HomeVolumesContestsSectionsForumsUsersPrintHelpAbout

Sections > Unsorted > problem:


50245 - Santa Gifts

Guest
• Discussion of problem (1)

Section problems

• 50614 - Numbers game
• 50625 - Permutations
• 50626 - The route
• 50642 - Draft board
• 50646 - The more the better
• 51153 - A+B.
• Problem 1
• 50252 - Birthday
• 50245 - Santa Gifts
• 50239 - Eating cheese
• 50276 - Nice Floor
• 50476 - Meditation
• 50551 - Camelot
• 50608 - Gangsters
• 50623 - Rectangles
• 50624 - Simple problem
• 50627 - Area of a polygon

Feedback

If you notice incorrect translations in Contester, please let author know.

Time limit 2000/4000/4000/4000 ms. Memory limit 65000/65000/65000/65000 Kb. Difficulty Beta

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