Author: | Andrew Stankevich | |||
Input file: | ancient.in | Time limit: | 2 sec | |
Output file: | ancient.out | Memory limit: | 64 Mb |
Ancient Roman empire had a strong government system with various departments, including a secret service department. Important documents were sent between provinces and the capital in encrypted form to prevent eavesdropping. The most popular ciphers in those times were so called substitution cipher and permutation cipher.
Substitution cipher changes all occurrences of each letter to some other letter. Substitutes for all letters must be different. For some letters substitute letter may coincide with the original letter. For example, applying substitution cipher that changes all letters from `A' to `Y' to the next ones in the alphabet, and changes `Z' to `A', to the message `VICTORIOUS' one gets the message `WJDUPSJPVT'.
Permutation cipher applies some permutation to the letters of the message. For example, applying the permutation <2, 1, 5, 4, 3, 7, 6, 10, 9, 8> to the message `VICTORIOUS' one gets the message `IVOTCIRSUO'.
It was quickly noticed that being applied separately, both substitution cipher and permutation cipher were rather weak. But when being combined, they were strong enough for those times. Thus, the most important messages were first encrypted using substitution cipher, and then the result was encrypted using permutation cipher. Encrypting the message `VICTORIOUS' with the combination of the ciphers described above one gets the message `JWPUDJSTVP'.
Archeologists have recently found the message engraved on a stone plate. At the first glance it seemed completely meaningless, so it was suggested that the message was encrypted with some substitution and permutation ciphers. They have conjectured the possible text of the original message that was encrypted, and now they want to check their conjecture. They need a computer program to do it, so you have to write one.
No. | Input file (ancient.in ) |
Output file (ancient.out ) |
---|---|---|
1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
Author: | Michail Mirzayanov | |||
Input file: | box.in | Time limit: | 2 sec | |
Output file: | box.out | Memory limit: | 64 Mb |
Ivan works at a factory that produces heavy machinery. He has a simple job — he knocks up wooden boxes of different sizes to pack machinery for delivery to the customers. Each box is a rectangular parallelepiped. Ivan uses six rectangular wooden pallets to make a box. Each pallet is used for one side of the box.
Joe delivers pallets for Ivan. Joe is not very smart and often makes mistakes — he brings Ivan pallets that do not fit together to make a box. But Joe does not trust Ivan. It always takes a lot of time to explain Joe that he has made a mistake.
Fortunately, Joe adores everything related to computers and sincerely believes that computers never make mistakes. Ivan has decided to use this for his own advantage. Ivan asks you to write a program that given sizes of six rectangular pallets tells whether it is possible to make a box out of them.
No. | Input file (box.in ) |
Output file (box.out ) |
---|---|---|
1 |
|
|
2 |
|
|
Author: | Andrew Stankevich | |||
Input file: | document.in | Time limit: | 2 sec | |
Output file: | document.out | Memory limit: | 64 Mb |
Andy is fond of old computers. He loves everything about them and he uses emulators of old operating systems on his modern computer. Andy also likes writing programs for them. Recently he has decided to write a text editor for his favorite text-mode operating system.
The most difficult task he has got stuck with is document indexing. An index of the document is the lexicographically ordered list of all words occurring in the document with the numbers of pages they occur at. Andy feels that he is not able to write the component of the editor that performs indexing, so he asks you to help.
A document is a sequence of paragraphs. Each paragraph consists of one or more lines. Paragraphs are separated from each other with exactly one blank line.
First, the document is paginated — divided into pages. Each page consists of up to n lines. Lines are placed on the page one after another, until n lines are placed. The following correction rules are then applied:
After applying the correction rules the next page is formed, and so on until the whole document is paginated.
A word is a continuous sequence of letters of the English alphabet. Case is not important.
The index of the document contains each word from the document and the list of the pages it occurs at. The numbers of pages a word occurs at must be listed in the ascending order. Numbers must be separated by commas. If a word occurs on three or more consecutive pages, only the first and the last page numbers of this range must be listed, separated by a dash, for example 3-5,7-10,12,13,15.
The first line of the input file contains n . The rest of the input file contains the document to be indexed.
The line is considered blank if it is completely empty. No line contains leading or trailing spaces. The document does not contain two consecutive blank lines. The first line of the document is not blank.
No. | Input file (document.in ) |
Output file (document.out ) |
---|---|---|
1 |
|
|
Author: | Roman Elizarov | |||
Input file: | lattice.in | Time limit: | 2 sec | |
Output file: | lattice.out | Memory limit: | 64 Mb |
No. | Input file (lattice.in ) |
Output file (lattice.out ) |
---|---|---|
1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|