Mirko has items (labeled with numbers from
to
) and
drawers (labeled with numbers from
to
). All items are currently scattered throughout his room, so he decided to clean them up. Each drawer can contain one item, and in order to make it easier for Mirko to find them later, he has determined in advance exactly two drawers (
and
) for each item
.
Mirko stores the items in order from to
using the first rule he can apply:
If the drawer
is empty, he stores the item
in that drawer.
If the drawer
is empty, he stores the item
in that drawer.
Try to move the item from
to its other drawer; if that one's filled too, try moving that item to its other drawer, and so on until you either succeed or get back to a previously seen drawer. In case of success, store the item
in the drawer
. In case of failure, continue to next rule.
Try moving the item from
to its other drawer; if that one's filled too, try moving that item to its other drawer, and so on until you either succeed or get back to a previously seen drawer. In case of success, store the item
in the drawer
. In case of failure, continue to next rule.
Give up and throw away the item
.
For given pairs of drawers for each item, determine which items will be stored and which will be thrown away.
Input Specification
The first line of input consists of two integers, and
, the number of items and the number of drawers.
Each of the following lines contains two integers:
and
, pair of drawers corresponding to the item
. The numbers
and
will be different.
Output Specification
For each item, respectively, output where it ends up.
In case the item is stored successfully, output LADICA
(Croatian word for drawer).
In case the item is thrown away, output SMECE
(Croatian word for trash).
Scoring
In test cases worth of total points, both
and
will be less than
.
Sample Input 1
5 3
1 2
1 3
1 2
1 3
1 2
Sample Output 1
LADICA
LADICA
LADICA
SMECE
SMECE
Explanation for Sample Output 1
The first item goes to drawer by rule
). The second item goes to drawer
by rule
). The third item goes to drawer
by rule
). For the fourth and fifth item, both drawers are already taken and cannot be emptied.
Sample Input 2
9 10
1 2
3 4
5 6
7 8
9 10
2 3
1 5
8 2
7 9
Sample Output 2
LADICA
LADICA
LADICA
LADICA
LADICA
LADICA
LADICA
LADICA
LADICA
Explanation for Sample Output 2
The first six items go into drawers (respectively), by rule
). For the seventh item, applying the rule
), we try to move the item in drawer
to drawer
, the item in drawer
to drawer
, the item in drawer
to drawer
, which we succeed because the drawer is empty.
The eighth item goes to drawer which was empty from the beginning. For the ninth item, applying the rule
), we try to move the item in drawer
to drawer
, the item in drawer
to drawer
, the item in drawer
to drawer
, the item in drawer
to drawer
, the item in drawer
to drawer
, which we succeed because the drawer is empty.
Comments