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

Сборники > Задачи с TopCoder > задача:


Santa Gifts

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

• Santa Gifts
• Text Statistics
• Chessboard Pattern
• Cell Removal
• Strong Prime Power
• Magic Words
• Making Potions
• Hexatridecimal Sum

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

Если у вас есть предложения или пожелания по работе 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