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

Разделы > Unsorted > задача:


50245 - Santa Gifts

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

Задачи раздела

• 51112 - Even Numbers
• 51105 - Currency System
• 51103 - Is it a triangle?
• 51114 - The traveling vehicle
• 50251 - Symmetric matrix
• 50252 - Birthday
• 50239 - Eating cheese
• 50244 - Chessboard Pattern
• 50245 - Santa Gifts
• 50256 - Sequence
• 50257 - Galls village
• 50280 - Division
• 50266 - Kovrov
• 50254 - Lawyers Council
• 50260 - What about judges?
• 50259 - Many-coloured roads
• 50276 - Nice Floor

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

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