#P7677. [COCI 2013/2014 #5] LADICE

[COCI 2013/2014 #5] LADICE

Description

There are NN items and LL drawers. Each drawer can hold only 11 item. Each item can be placed into drawer AiA_i or BiB_i.

The rules for placing an item are as follows (performed in order: once condition 11 is satisfied, execute it immediately and do not execute condition 22; only if condition 11 is not satisfied do you check condition 22, and so on):

  • 1.1. If drawer AiA_i is empty, put this item into drawer AiA_i.

  • 2.2. If drawer BiB_i is empty, put this item into drawer BiB_i.

  • 3.3. Move the item currently in drawer AiA_i to its other drawer. If that drawer is also full, move the item in that drawer to its other drawer, and so on, until you succeed or return to a drawer you have encountered before. If you succeed, put this item into that drawer.

  • 4.4. Move the item currently in drawer BiB_i to its other drawer. If that drawer is also full, move the item in that drawer to its other drawer, and so on, until you succeed or return to a drawer you have encountered before. If you succeed, put this item into that drawer.

  • 5.5. Throw away this item.

For each given item, determine which items will be kept and which will be thrown away.

Input Format

The first line contains two integers NN and LL, representing the number of items and the number of drawers.

The next NN lines each contain two integers AiA_i and BiB_i, meaning that item ii can be stored in these two drawers.

Output Format

Output NN lines, each containing one string.

If the item is successfully stored, output LADICA.

If the item is thrown away, output SMECE.

5 3
1 2
1 3
1 2
1 3
1 2 
LADICA
LADICA
LADICA
SMECE
SMECE 
9 10
1 2
3 4
5 6
7 8
9 10
2 3
1 5
8 2
7 9 
LADICA
LADICA
LADICA
LADICA
LADICA
LADICA
LADICA
LADICA
LADICA

Hint

[Sample Explanation #1]

Item 11 is placed into drawer 11, item 22 into drawer 33, item 33 into drawer 22, and items 44 and 55 have nowhere to go.

[Sample Explanation #2]

Item 11 is placed into drawer 11, item 22 into drawer 33, item 33 into drawer 55, item 44 into drawer 77, item 55 into drawer 99, item 66 into drawer 22, and item 88 into drawer 88.

Both drawers for item 77 are full. Move item 11 in drawer 11 to drawer 22, move item 66 in drawer 22 to drawer 33, move item 22 in drawer 33 to drawer 44. Drawer 44 is empty, so the insertion succeeds.

Both drawers for item 99 are full. Move item 44 in drawer 77 to drawer 88, move item 88 in drawer 88 to drawer 22, move item 11 in drawer 22 to drawer 11, move item 77 in drawer 11 to drawer 55, move item 33 in drawer 55 to drawer 66. Drawer 66 is empty, so the insertion succeeds.

[Constraints]

For 50%50\% of the testdata, 1N,L20001\le N,L\le 2000.

For 100%100\% of the testdata, 1N,L3×1051\le N,L\le 3\times 10^5, 1Ai,BiL1\le A_i,B_i\le L.

[Notes]

The score of this problem follows the original COCI setting, with a full score of 160160.

Translated from COCI2013_2014 CONTEST #5 T6 LADICE.

Translated by ChatGPT 5