Legend explains that one day, during his quest for the Holy Chawan all along the island of Honshu, Shogun Aasaa’s caravan was stopped on his way to meet Professor Ooku by two fearful samurais who were blocking their way. When his squire asked them to move aside to let the Shogun continue his march, the men replied with fearful words that made the warrior realize that his life was at risk.
SAMURAI: Ni! Ni! Ni!
AASAA: Who are you?
SAMURAI: We are the Samurais Who Say... Ni!
AASAA: No! Not the Samurais Who Say Ni!
SAMURAI: The same!
SQUIRE: Who are they?
SAMURAI: We are the first among the infinite series of keepers of sacred
words: Ni, San, Yon, Go, Roku,…
AASAA: Those who hear them seldom live long enough to tell the tale!
SAMURAI: The Samurais Who Say Ni demand a sacrifice!
AASAA: Samurais Who Say Ni, we are but simple travellers who seek the
professor who lives beyond these woods.
SAMURAI: Ni! Ni! Ni! Ni!
AASAA: Oh, ow!
SAMURAI: We shall say Ni again if you do not appease us.
AASAA: Well, what is it you want?
SAMURAI: Looking at your ordered caravan, you are first carrying
forty-nine coconuts…Nah! There are two of us, so we would not be able
to split them evenly. Same for your nine Asian swallows that follow. But oh!
You then have six shrubberies which we can split. They look nice, and not
too expensive…Yes! We will keep them, you may go!
Shogun Aasaa then hurried his entourage past the Samurais Who Say Ni, but after one hour of progressing through the forest, they encountered a set of three samurais looming over them, pronouncing equally ominous words.
SAMURAI: San! San! San!
AASAA: Who are you?
SAMURAI: We are the Samurais Who Say... San!
AASAA: No! Not the Samurais Who Say San!
SAMURAI: The same!
SQUIRE: Who are they?
SAMURAI: We are the second among the infinite series of keepers of sacred
words: Ni, San, Yon, Go, Roku,…
AASAA: Those who hear them seldom live long enough to tell the tale!
SAMURAI: The Samurais Who Say San demand a sacrifice!
AASAA: Samurais Who Say San, we are but simple travellers who seek the
professor who lives beyond these woods, and we have already made a sacrifice
of six shrubberies, which looked nice, and not too expensive, to the
Samurais Who Say Ni.
SAMURAI: San! San! San! San!
AASAA: Oh, ow!
SAMURAI: We shall say San again if you do not appease us.
AASAA: Well, what is it you want?
SAMURAI: Looking at your ordered caravan, we do not care about your first
forty-nine coconuts, since there are three of us and we would not be able to
split them evenly. But you have the nine Asian swallows that follow, which
we can split. They are bigger than European ones…Yes! We will keep
them, you may go!
Shogun Aasaa then hurried his entourage past the Samurais Who Say San, but after fifteen minutes of progressing through the forest, they encountered a set of four samurais looming over them, pronouncing equally ominous words.
SAMURAI: Yon! Yon! Yon!
AASAA: Who are you?
SAMURAI: We are the Samurais Who Say... Yon!
AASAA: No! Not the Samurais Who Say Yon!
SAMURAI: The same!
SQUIRE: Who are they?
SAMURAI: We are the third among the infinite series of keepers of sacred
words: Ni, San, Yon, Go, Roku,…
AASAA: Those who hear them seldom live long enough to tell the tale!
Squire: Yes, I have gotten that part by now…
SAMURAI: The Samurais Who Say Yon demand a sacrifice!
AASAA: Samurais Who Say Yon, we are but simple travellers who seek the
professor who lives beyond these woods, and we have already made a sacrifice
of six shrubberies, which looked nice, and not too expensive, to the
Samurais Who Say Ni; and another sacrifice of nine Asian swallows, which
were bigger than European ones, to the Samurais who say San.
SAMURAI: Yon! Yon! Yon! Yon!
AASAA: Oh, ow!
SAMURAI: We shall say Yon again if you do not appease us.
AASAA: Well, what is it you want?
SAMURAI: Looking at your ordered caravan, we cannot take your first
forty-nine coconuts, since there are four of us and we would not be able to
split them evenly…The same applies to your second three Holy Hand
Grenades of Kyoto, and to the two tree-cutting herrings that follow, and to
the one sword distributed by a strange women lying in a pond, which clearly
is no basis for a system of government…Yon! You do not have anything
for a proper sacrifice to the Samurais Who Say Yon! You may go, but do not
ever dare to pass through here again.
Shogun Aasaa then hurried his entourage past the Samurais Who Say Yon, but after six minutes and forty seconds of progressing through the forest, they encountered a set of five samurais looming over them, pronouncing equally ominous words, Go!, and they could pass without a sacrifice from their perfectly sorted caravan.
Shogun Aasaa then hurried his entourage past the Samurais Who Say Go, but after three minutes and forty-five seconds of progressing through the forest, they encountered a set of six samurais looming over them, pronouncing equally ominous words, Roku!, and they could pass without a sacrifice from their perfectly sorted caravan.
Shogun Aasaa then hurried his entourage past the Samurais Who Say Roku, but after two minutes and twenty-four seconds of progressing through the forest, they encountered a set of seven samurais looming over them, pronouncing equally ominous words, Nana!, and they took their forty-nine coconuts as a sacrifice.
And thus, after one hour, thirty-eight minutes, and roughly forty-one seconds of traversal through the forest, Shogun Aasaa was able to leave behind the infinite series of keepers of sacred words, while still carrying their three Holy Hand Grenades of Kyoto, their two tree-cutting herrings, and their one sword distributed by a strange women lying in a pond, which clearly is no basis for a system of government but which Aasaa continued using as such. A total of six objects.
They eventually reached the hut of Professor Ooku. He listened attentively to the account of their ordeal, nodding while he wondered how he could use that unlikely story in the future…
Input
Input consists of several cases. Each case starts with the number n of object types the caravan is carrying before meeting the Samurais Who Say Ni. Follow n values m1 … mn with the number of objects of each type, in the order in which they will be inspected by the samurais. Assume 1 ≤ n ≤ 100 and 1 ≤ mi ≤ 1000.
Output
For each case, print the number of objects that remain after going through all the groups of samurais.
Input
6 49 9 6 3 2 1 1 42 2 3 3
Output
6 0 3