Author:  FarEastern Subregional  
Input file:  input.txt  Time limit:  1 sec  
Output file:  output.txt  Memory limit:  8 Mb 
No.  Input file (input.txt ) 
Output file (output.txt ) 

1 


Author:  unknown  
Input file:  input.txt  Time limit:  15 sec  
Output file:  output.txt  Memory limit:  200 Mb 
No.  Input file (input.txt ) 
Output file (output.txt ) 

1 


Author:  FarEastern Subregional  
Input file:  input.txt  Time limit:  1 sec  
Output file:  output.txt  Memory limit:  8 Mb 
A market has a line of N trading posts selling sunflower seeds. Prospective buyers walk along the line, then at some moment stop and buy the seeds to nibble. Quality of the seeds does not differ substantially among the posts, so the only difference is in price and location of posts. Before trying to enter this market as another seed seller, you have conducted a market research to find out how is the number of buyers influenced by these two factors. The research shows that most buyers follow the same pattern. They walk past some posts noticing and remembering the prices, then after passing K posts return to the one with the lowest price encountered, and make a purchase there, then leave the market. If there are several posts with the equal price, they choose the nearest one in the line. For example, let us assume there are five posts with prices 37, 34, 34, 35, 33. If the buyer with K = 4 walks from the left to right, he sees seeds priced at 37, 34, 34, 35. At this moment, he decides he has seen enough, and goes back to the third post and buys seeds there. Although the second post has the same price as the third, it is a longer walk for the buyer to return there. If the same buyer would enter the line from the right end, he would see prices 33, 35, 34, 34, then stop and return to the fifth post. The number of posts passed before the decision (K) is a function of buyer's greed and patience, and is obviously different for different buyers. The research yielded the average percentage B_{K} of buyers for all values of K.
You are to determine the optimal market strategy (i. e. the price and location of the new post which maximizes anticipated average income) under the assumptions that half of the clients walk in the direction from the first post to the Nth and another half  from the Nth post, to the first, and that they behave according to the pattern above.
No.  Input file (input.txt ) 
Output file (output.txt ) 

1 


Author:  FarEastern Subregional  
Input file:  input.txt  Time limit:  1 sec  
Output file:  output.txt  Memory limit:  8 Mb 
No.  Input file (input.txt ) 
Output file (output.txt ) 

1 


Author:  FarEastern Subregional  
Input file:  input.txt  Time limit:  1 sec  
Output file:  output.txt  Memory limit:  8 Mb 
The multiplication puzzle is played with a row of cards, each containing a single positive integer. During the move player takes one card out of the row and scores the number of points equal to the product of the number on the card taken and the numbers on the cards on the left and on the right of it. It is not allowed to take out the first and the last card in the row. After the final move, only two cards are left in the row.
The goal is to take cards in such order as to minimize the total number of scored points.
For example, if cards in the row contain numbers 10 1 50 20 5, player might take a card with 1, then 20 and 50, scoring 10*1*50 + 50*20*5 + 10*50*5 = 500+5000+2500 = 8000
If he would take the cards in the opposite order, i.e. 50, then 20, then 1, the score would be 1*50*20 + 1*20*5 + 10*1*5 = 1000+100+50 = 1150.
No.  Input file (input.txt ) 
Output file (output.txt ) 

1 


Author:  FarEastern Subregional  
Input file:  input.txt  Time limit:  1 sec  
Output file:  output.txt  Memory limit:  8 Mb 
Several pieces of cloth are laid out on the table without overlapping each other. These pieces contain many holes, some so big that entire other piece of cloth may fit into them. Digital blackandwhite image of the tabletop was taken, on which areas covered by cloth are represented with '*'s and not covered areas with '.'s. A single piece of cloth is thus represented with 4connected area of '*'s  i.e., a group of '.'s located next to each other horizontally or vertically, but not diagonally. For example, on the following image there are three pieces  one without holes, and two with one hole each  first has area of 8, and the second  area of 12.
.***..*** .*.*.**.* .***.*.** *...**.*.
Your goal is to find the piece with the most holes in it. The hole is a 4 connected area of '.'s completely surrounded with '*'s. If several pieces have the same number of holes, you must select the one with the smallest area.
No.  Input file (input.txt ) 
Output file (output.txt ) 

1 


Author:  FarEastern Subregional  
Input file:  input.txt  Time limit:  1 sec  
Output file:  output.txt  Memory limit:  8 Mb 
The text on a sticker consists of words formed from small and capital Latin letters. Words are separated by spaces, line breaks, and/or the following punctuation marks: ",", ".", "!", "?".
There may be any number of spaces and empty lines before and after the words, but there is no more than one punctuation mark after each word. Sticker is printed with monospace font, so every character occupies on the paper a rectangular area of fixed size. Sticker itself is a minimal rectangle enclosing the text plus a margin of one character in width.
Many copies of the sticker are to be printed, and to minimize paper consumption the sticker should be made as small in area as possible. Consider, for example, the sticker with the following text:
Our pink elephants have great size and a small price. Buy our elephants!
Printed in one line, this sticker will have an area of (72 + 2) * (1 + 2) = 222 characters. On the other hand, if printed in four lines, like this:
···················· ·Our·pink·elephants· ·have·great·size···· ·and·a·small·price.· ·Buy·our·elephants!· ···················· 
the sticker will only require (18 + 2) * (4 + 2) = 120 characters.
You objective is, given the text of a sticker, to break it into lines so as to achieve the smallest possible area for it. Line break may be inserted after any word or punctuation mark, but not before a punctuation mark. One space must separate each word from the preceding word or punctuation on the same line. You do not have to preserve other spaces or line breaks in the input file.
No.  Input file (input.txt ) 
Output file (output.txt ) 

1 


Author:  FarEastern Subregional  
Input file:  input.txt  Time limit:  1 sec  
Output file:  output.txt  Memory limit:  8 Mb 
The game of Tetris is played with fourconnected 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.
No.  Input file (input.txt ) 
Output file (output.txt ) 

1 


Author:  FarEastern Subregional  
Input file:  input.txt  Time limit:  3 sec  
Output file:  output.txt  Memory limit:  8 Mb 
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 C_{ij} is the amount of data sent between ith and jth nodes (C_{ij} = C_{ji}, C_{ii} = 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 C_{ij}, where i belongs to A, and j belongs to B.
No.  Input file (input.txt ) 
Output file (output.txt ) 

1 


Author:  FarEastern Subregional  
Input file:  input.txt  Time limit:  1 sec  
Output file:  output.txt  Memory limit:  8 Mb 
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.
No.  Input file (input.txt ) 
Output file (output.txt ) 

1 


2 


Author:  FarEastern Subregional  
Input file:  input.txt  Time limit:  1 sec  
Output file:  output.txt  Memory limit:  8 Mb 
A numeric sequence of a_{i} is ordered if a_{1} < a_{2} < ... < a_{N}. Let the subsequence of the given numeric sequence (a_{1}, a_{2}, ., a_{N}) be any sequence (a_{i1}, a_{i2}, ., a_{iK}), where 1 ≤ i_{1} < i_{2} < ... < i_{K} ≤ 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.
No.  Input file (input.txt ) 
Output file (output.txt ) 

1 


Author:  FarEastern Subregional  
Input file:  input.txt  Time limit:  1 sec  
Output file:  output.txt  Memory limit:  8 Mb 
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 topdown view of that desk with cards upon it can be represented with the set of line segments with coordinates (x_{i}, y_{i}) to (v_{i}, w_{i}). 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 (x_{1}, y_{1})(v_{1}, w_{1}) and the falling direction of the first card is equal to 90 degrees (measured counterclockwise). 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.
No.  Input file (input.txt ) 
Output file (output.txt ) 

1 


Author:  FarEastern Subregional  
Input file:  input.txt  Time limit:  1 sec  
Output file:  output.txt  Memory limit:  8 Mb 
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.
No.  Input file (input.txt ) 
Output file (output.txt ) 

1 

