eolymp
bolt
Try our new interface for solving problems
Problems

Shehrzad

Shehrzad

\textit{...Here Shehrzad perceived the day and was silent...} \textit{"One Thousand and One Nights"} And when King Shehriyar knew about his wife's unfaithfulness, then went up to his palace, and drew his sword and decapitated his wife, and black slaves, and concubines. Then he took an oath that every night he would marry chaste girl and in the morning put her to death. And so it happened and had been continuing during three years, till the land was stripped of marriageable girls, and all the women and mothers and fathers wept and cried out against the King, cursing him and complaining to the Creator of heaven and earth and calling for succour upon Him who heard prayer and answered those that cry to Him; and those that had daughters left fled with them, till at last there remained not a single girl in the city apt for marriage. One day the King ordered the Vizier to bring him a maid as of wont; so the Vizier went out and made search for a girl, but found not one and returned home troubled and careful for fear of the king's anger. Now this Vizier had two daughters, the elder called Shehrzad and the younger Dunyazad, and the former had read many books and histories and chronicles of ancient kings and stories of people of old time. When the Vizier heard his daughter's words, he told her his case, and she said, "By Allah, O my father, marry me to this king, for either I will be the means of the deliverance of the daughters of the Muslims from slaughter or I will die and perish as others have perished.'' And the Vizier was not able to dissuade Shehrzad. Then he went up to King Shehriyar and kissing the earth before him, told him about his daughter and how she would have him give her to him that next night. But Shehrzad said to her sister Dunyazad, "O my sister, note well what I shall enjoin thee. When I go up to the Sultan, I will send after thee, and when thou come to me, ask me to tell some stories''. And so it happened, and the King being wakeful, was pleased to hear a story and allowed Shehrzad to start her story. But when the morning came, Shehrzad had been silent at most interest moment. And Shehriyar said to himself, "What a charming and delightful story! By Allah, I will not kill her, till I hear the rest of the story!''. So it had been continued during many nights: Shehrzad continued undertold story of previous night from that moment, where she stopped in morning, and as soon as this story was finished, she immediately started other one, fascinating the King at new subject. But Shehrzad had to follow that stories was not repeated, and (perhaps, except the last) was not finished in the morning. Then the King either kill Shehrzad, or fall in love with her by that time so that the hand does not arise. Naturally, the more stories she tells, the more Shehriyar's love, and the more chance of staying alive. \InputFile In the first line of the input line it is given integer number \textbf{N} (\textbf{1} ≤ \textbf{N} ≤ \textbf{10000}), which define the number of stories known by Shehrzad. The second line consists of \textbf{N} natural number not exceeded \textbf{100}, which define stories durations in hours. It is considered that each night lasts \textbf{8} hours. \OutputFile On the first line output maximal number of stories, which can told by Shehrzad, and on the second line write durations of these stories in order, that she must tell her stories.
Time limit 2 seconds
Memory limit 64 MiB
Input example #1
6
1 2 3 4 5 6
Output example #1
6
1 2 3 4 5 6
Author В.Неспирный