Problem A. Ancient Cipher

Author:Andrew Stankevich
Input file:ancient.in   Time limit:2 sec
Output file:ancient.out   Memory limit:64 Mb

Statement

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.

Input file format

Input file contains two lines. The first line contains the message engraved on the plate. Before encrypting, all spaces and punctuation marks were removed, so the encrypted message contains only capital letters of the English alphabet. The second line contains the original message that is conjectured to be encrypted in the message on the first line. It also contains only capital letters of the English alphabet.

Output file format

Output `YES' if the message on the first line of the input file could be the result of encrypting the message on the second line, or `NO' in the other case.

Constraints

The lengths of both lines of the input file are equal and do not exceed 100.

Sample tests

No. Input file (ancient.in) Output file (ancient.out)
1
JWPUDJSTVP
VICTORIOUS
YES
2
MAMA
ROME
NO
3
HAHA
HEHE
YES
4
AAA
AAA
YES
5
NEERCISTHEBEST
SECRETMESSAGES
NO

Problem B. Box

Author:Michail Mirzayanov
Input file:box.in   Time limit:2 sec
Output file:box.out   Memory limit:64 Mb

Statement

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.

Input file format

Input file consists of six lines. Each line describes one pallet and contains two integer numbers w and h — width and height of the pallet in millimeters respectively.

Output file format

Write a single word `POSSIBLE' to the output file if it is possible to make a box using six given pallets for its sides. Write a single word `IMPOSSIBLE' if it is not possible to do so.

Constraints

1 ≤ w, h ≤ 10000

Sample tests

No. Input file (box.in) Output file (box.out)
1
1345 2584
2584 683
2584 1345
683 1345
683 1345
2584 683
POSSIBLE
2
1234 4567
1234 4567
4567 4321
4322 4567
4321 1234
4321 1234
IMPOSSIBLE

Problem D. Document

Author:Andrew Stankevich
Input file:document.in   Time limit:2 sec
Output file:document.out   Memory limit:64 Mb

Statement

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.

Input file format

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.

Output file format

Print all words that occur in the given document. Words must be printed in the lexicographical order, one word on a line. After each word print one space followed by the list of pages it occurs at, formatted as described in problem statement. Use capital letters in output.

Constraints

4 ≤ n ≤ 100. The size of the input file does not exceed 20000 bytes. The length of each line of the document does not exceed 200 characters.

Sample tests

No. Input file (document.in) Output file (document.out)
1
6
From thousands of teams competing in regional 
contests held from September to December 2004 
world-wide, seventy-five teams will advance to 
the World Finals in Shanghai, April 3-7, 2005.  

Awards, prizes, scholarships, and bragging rights 
will be at stake for some of the world's finest 
university students of the computing science.

Join us for the challenge, camaraderie, 
and the fun! Become the best of the best
of the best in ACM ICPC!

ACM ICPC is the best contest!
ACM 3
ADVANCE 1
AND 2,3
APRIL 1
AT 2
AWARDS 2
BE 2
BECOME 3
BEST 3
BRAGGING 2
CAMARADERIE 3
CHALLENGE 3
COMPETING 1
COMPUTING 2
CONTEST 3
CONTESTS 1
DECEMBER 1
FINALS 1
FINEST 2
FIVE 1
FOR 2,3
FROM 1
FUN 3
HELD 1
ICPC 3
IN 1,3
IS 3
JOIN 3
OF 1-3
PRIZES 2
REGIONAL 1
RIGHTS 2
S 2
SCHOLARSHIPS 2
SCIENCE 2
SEPTEMBER 1
SEVENTY 1
SHANGHAI 1
SOME 2
STAKE 2
STUDENTS 2
TEAMS 1
THE 1-3
THOUSANDS 1
TO 1
UNIVERSITY 2
US 3
WIDE 1
WILL 1,2
WORLD 1,2

Problem L. Lattice Animals

Author:Roman Elizarov
Input file:lattice.in   Time limit:2 sec
Output file:lattice.out   Memory limit:64 Mb

Statement

Lattice animal is a set of connected sites on a lattice. Lattice animals on a square lattice are especially popular subject of study and are also known as polyominoes. Polyomino is usually represented as a set of sidewise connected squares. Polyomino with n squares is called n-polyomino. In this problem you are to find a number of distinct free n-polyominoes that fit into rectangle w x h. Free polyominoes can be rotated and flipped over, so that their rotations and mirror images are considered to be the same. For example, there are 5 different pentominoes (5-polyominoes) that fit into 2 x 4 rectangle and 3 different octominoes (8-polyominoes) that fit into 3 x 3 rectangle.

Input file format

The input file consists of a single line with 3 integer numbers n, w, and h

Output file format

Write to the output file a single integer number — the number of distinct free n-polyominoes that fit into rectangle w x h.

Constraints

1 ≤ n ≤ 10, 1 ≤ w, hn.

Sample tests

No. Input file (lattice.in) Output file (lattice.out)
1
5 1 4
0
2
5 2 4
5
3
5 3 4
11
4
5 5 5
12
5
8 3 3
3

0.034s 0.003s 13