Problem A. Tetris alphabet

Author:Far-Eastern Subregional
Input file: input.txt   Time limit:1 sec
Output file: output.txt   Memory limit:8 Mb

Statement

The game of Tetris is played with four-connected blocks falling down the well having N rows and 20 columns. Each figure is marked with a unique English letter from 'A' to 'Z'.

Your program must, given the state of the well, determine the order in which the blocks fell down.

Input file format

The first line of input file contains integer N - number of rows. Following N lines contain 20 characters each, with characters that are either a letter from 'A' to 'Z' or the dot character (ASCII 46), representing an empty cell.

Output file format

Output file must contain a string of letters indicating the order in which figures fell down. If there is more than one order, lexicographically smallest one must be printed. Input data will guarantee that at least one nonempty order exists.

Constraints

0 ≤ N ≤ 50

Sample tests

No. Input file (input.txt) Output file (output.txt)
1
6
...........XX.......
..........MMMM......
..........K.........
........KKK.........
.....ZAAA.FFF.......
.....ZZZA..F.B......
BFZAKMX

Problem B. Network Saboteur

Author:Far-Eastern Subregional
Input file: input.txt   Time limit:3 sec
Output file: output.txt   Memory limit:8 Mb

Statement

A university network is composed of N computers. System administrators gathered information on the traffic between nodes, and carefully divided the network into two subnetworks in order to minimize traffic between parts.

A disgruntled computer science student Vasya, after being expelled from the university, decided to have his revenge. He hacked into the university network and decided to reassign computers to maximize the traffic between two subnetworks.

Unfortunately, he found that calculating such worst subdivision is one of those problems he, being a student, failed to solve. So he asks you, a more successful CS student, to help him.

The traffic data are given in the form of matrix C, where Cij is the amount of data sent between ith and jth nodes (Cij = Cji, Cii = 0). The goal is to divide the network nodes into the two disjointed subsets A and B so as to maximize the sum of all Cij, where i belongs to A, and j belongs to B.

Input file format

The first line of input file contains a number of nodes N. The following N lines, containing N space-separated integers each, represent the traffic matrix C.

Output file format

Output file must contain a single integer - the maximum traffic between the subnetworks.

Constraints

2 ≤ N ≤ 20; 0 ≤ Cij ≤ 10000.

Sample tests

No. Input file (input.txt) Output file (output.txt)
1
3
0 50 30
50 0 40
30 40 0
90

Problem C. Burned Calendar

Author:Far-Eastern Subregional
Input file: input.txt   Time limit:1 sec
Output file: output.txt   Memory limit:8 Mb

Statement

A year calendar is printed using the monospace font according to the following rules:

1) All spaces on the printed calendar are represented by the dot character (ASCII 46).

2) Every month occupies a rectangle of 17 by 8 characters, with the name of the month written in all capital letters starting from the 2nd character of the first line.

3) All days of the months are printed in 4, 5, or 6 columns 2 characters wide and 7 characters high, with one space between the columns. The first day of the week is Monday.

4) Months of the year are arranged in the three rows separated by horizontal and vertical lines of spaces. Each row contains four months. The calendar margins are of 1 space from all sides. Therefore, the whole calendar has size of 73 by 28 characters.

Note that January 1st, 1900 was Monday. Also note that a leap year number is divisible by 4 and not divisible by 100, or divisible by 400. For example, a part of the printed calendar from October to December 2002 may look like this:

.OCTOBER...........NOVEMBER..........DECEMBER.........

....7.14.21.28........4.11.18.25........2..9.16.23.30.

.1..8.15.22.29........5.12.19.26........3.10.17.24.31.

.2..9.16.23.30........6.13.20.27........4.11.18.25....

.3.10.17.24.31........7.14.21.28........5.12.19.26....

.4.11.18.25........1..8.15.22.29........6.13.20.27....

.5.12.19.26........2..9.16.23.30........7.14.21.28....

.6.13.20.27........3.10.17.24........1..8.15.22.29....

......................................................

A calendar was printed and then burned, with only a small rectangular piece left. Your program must determine to which of years from 1900 to 2100 this piece could belong.

Input file format

The first line of the input file contains integer numbers N and M, separated by spaces - the size of the piece. The following M lines contain N characters each - the piece of calendar.

Output file format

Output file must contain an ordered list of year numbers, one year per line. If given piece could not belong to any calendar, output must contain a single integer 0 (zero).

Constraints

2 ≤ N, M ≤ 10

Sample tests

No. Input file (input.txt) Output file (output.txt)
1
4 4
1..8
....
JUNE
1..8
1903
1914
1925
1931
1942
1953
1959
1970
1981
1987
1998
2009
2015
2026
2037
2043
2054
2065
2071
2082
2093
2099
2
3 2
1.7
...
0

Problem D. Longest Ordered Subsequence

Author:Far-Eastern Subregional
Input file: input.txt   Time limit:1 sec
Output file: output.txt   Memory limit:8 Mb

Statement

A numeric sequence of ai is ordered if a1 < a2 < ... < aN. Let the subsequence of the given numeric sequence (a1, a2, ., aN) be any sequence (ai1, ai2, ., aiK), where 1 ≤ i1 < i2 < ... < iK ≤ N. For example, the sequence (1, 7, 3, 5, 9, 4, 8) has ordered subsequences, e. g., (1, 7), (3, 4, 8) and many others. All longest ordered subsequences of this sequence are of length 4, e. g., (1, 3, 5, 8).

Your program, when given the numeric sequence, must find the length of its longest ordered subsequence.

Input file format

The first line of input file contains the length of sequence N. The second line contains the elements of sequence - N integers in the range from 0 to 10000 each, separated by spaces.

Output file format

Output file must contain a single integer - the length of the longest ordered subsequence of the given sequence.

Constraints

1 ≤ N ≤ 1000

Sample tests

No. Input file (input.txt) Output file (output.txt)
1
7
1 7 3 5 9 4 8
4

Problem E. Falling Cards

Author:Far-Eastern Subregional
Input file: input.txt   Time limit:1 sec
Output file: output.txt   Memory limit:8 Mb

Statement

It is hard to make the playing card stand on its edge, however, some patient person managed to put N of them upon the desk in such a way that each cards stands on its shorter edge. The top-down view of that desk with cards upon it can be represented with the set of line segments with coordinates (xi, yi) to (vi, wi). The segments do not intersect.

The first card falls flat on its side, causing any card it touches to fall down also. The angle between vector (x1, y1)-(v1, w1) and the falling direction of the first card is equal to 90 degrees (measured counter-clockwise). If card A touches card B, the direction of B's fall is chosen so that the continuation of the direction vector does not cross the line containing segment A. Input data are guaranteed to never contain:

1) a card falling exactly perpendicular to the other and

2) a falling card that touches more than one of still standing cards.

Your program must determine which cards will fall, and which shall remain standing.

Input file format

The first line of input file contains a numbers N H - the number of cards and the floating point height of a card. Each of the following N lines contains four floating-point numbers xi yi vi wi - coordinates of cards separated by spaces.

Output file format

The output file must contain the list of fallen cards' numbers, sorted in increasing order and separated by spaces.

Constraints

1 ≤ N ≤ 100

Sample tests

No. Input file (input.txt) Output file (output.txt)
1
3 100
10 10 50 40
10 0 50 30
20 90 20 20
1 3

Problem F. Very Simple Problem

Author:Far-Eastern Subregional
Input file: input.txt   Time limit:1 sec
Output file: output.txt   Memory limit:8 Mb

Statement

During a preparation of programming contest, its jury is usually faced with many difficult tasks. One of them is to select a problem simple enough to most, if not all, contestants to solve.

The difficulty here lies in diverse meanings of the term "simple" amongst the jury members. So, the jury uses the following procedure to reach a consensus: each member weights each proposed problem with a positive integer "complexity rating" (not necessarily different for different problems). The jury member calls "simplest" those problems that he gave the minimum complexity rating, and "hardest" those problems that he gave the maximum complexity rating.

The ratings received from all jury members are then compared, and a problem is declared as "very simple", if it was called as "simplest" by more than a half of the jury, and was called as "hardest" by nobody.

Input file format

The first line of input file contains integers N and P, the number of jury members and the number of problems. The following N lines contain P integers in range from 0 to 1000 each - the complexity ratings.

Output file format

Output file must contain an ordered list of "very simple" problem numbers, separated by spaces. If there are no such problems, output must contain a single integer 0 (zero).

Constraints

1 ≤ N, P ≤ 100

Sample tests

No. Input file (input.txt) Output file (output.txt)
1
4 4
1 1 1 2
5 900 21 40
10 10 9 10
3 4 3 5
3

0.051s 0.005s 17