ГлавнаяСборникиТурнирыРазделыФорумыУчастникиПечатьПомощьО системе

Сборники > Problems from everywhere > задача:


TopCoder-3. 50245 - Santa Gifts

Гость
• Обсуждение задачи (1)

Задачи сборника

• TopCoder-7. 50244 - Chessboard P...
• VologdaInterCity-A. 50614 - Игра в...
• VologdaInterCity-C. 50646 - Чем бо...
• VologdaInterCity-D. 50605 - За реш...
• 50580 - Sa dite kane kaluar?
• 50623 - Прямоугольники
• 50645 - Строки
• Редкое имя
• TopCoder-3. 50245 - Santa Gifts
• TopCoder-4. 50701 - Cell Removal
• TopCoder-8. 50641 - Strong Prime ...
• VologdaInterCity-B. 50632 - Снова ...
• VologdaInterCity-E. 50624 - Проста...
• VologdaInterUni-B. 2 ->10
• VologdaInterUni-C. 50629 - Минусы
• 50602 - День рождения Иванова
• 50603 - Ездец

Обратная связь

Если у вас есть предложения или пожелания по работе Contester, посетите форум сайта www.contester.ru.

Лимит времени 2000/4000/4000/4000 мс. Лимит памяти 65000/65000/65000/65000 Кб. Сложность Бета

Santa Claus has come with a bag full of presents this year. A group of N kids stand in line, anxious to get their gifts. Santa Claus takes a present from his bag and gives it to the kid who is currently first in line. That kid then goes to the end of the line, unless he already has 4 gifts, in which case, he goes home. This process continues as long as there are presents in the bag and kids in the line.

You are given M gifts containing the presents in Santa's bag, in the order they are given away. Output the gifts each kid received.

Input
The first line will contain two numbers N and M (1 ≤ N ≤ 50, 1 ≤ M ≤ 50). Next M lines will contain gifts in the order they are given away. Each gift will contain between 1 and 10 lowercase letters ('a'-'z'), inclusive.
Output
Output should contain N lines exactly. i-th line should contain gifts description for i-th kid. i-th line starts with ki - number of gifts the i-th kid received (0, if no gifts). Next ki gifts follow in the order the kid received them, separated by spaces.

Input 1 Input 2 Input 3
3 4
ball
plane
robot
puzzle
5 3
ball
plane
robot
2 4
ball
ball
plane
plane
Output 1 Output 2 Output 3
2 ball puzzle
1 plane
1 robot
1 ball
1 plane
1 robot
0
0
2 ball plane
2 ball plane

Для отправки решений необходимо выполнить вход.

www.contester.ru