Input file: | Standard input | Time limit: | 1 sec | |
Output file: | Standard output | Memory limit: | 512 Mb |
A pawn is located on a chess board at coordinates x, y (x is a column number, y is a row number).
You must write a program to determine maximum number of rooks which can be placed on this board so that not a one of them will attack another.
Input contains integers x and y.
Output must contain a single integer — maximum number of rooks.
1 ≤ x, y ≤ 8
No. | Standard input | Standard output |
---|---|---|
1 |
|
|
Author: | A. Karabanov | Time limit: | 1 sec | |
Input file: | Standard input | Memory limit: | 256 Mb | |
Output file: | Standard output |
Kolya Gerasimov was born on January 1st, 1970. After visiting his strange neighbor's apartment on April 11th, 1982, he found a time machine and travels exactly 100 years into the future (that is, he goes to April 11th, 2082).
After living in the future for exactly a years, Kolya uses the same machine to go back to the past, where he lives normally, collecting precious archive data for future historians. After exactly b more years after his return, Kolya makes the final travel for exactly 100 years into the future. Then he lives in the future without aging due to amazing achievements of future medicine.
How many full years did Kolya Gerasimov live at January 1st of year n?
Input data contain three natural numbers: a, b and n.
Output data must contain a single integer — full years lived by Kolya on January 1st of the given year. If at the given date Kolya was not present in that moment of time, output − 1.
2 ≤ a + b ≤ 99
1971 ≤ n ≤ 3000
In both samples Kolya lived in the future for 12 years, got back, and after 27 years went to the beautiful faraway again. Time line for the life of Kolya is given on a picture. For January 1st, 2088 he lived 18 full years. However, on January 1st 1988 he was in the future.
No. | Standard input | Standard output |
---|---|---|
1 |
|
|
2 |
|
|
Author: | A. Karabanov | Time limit: | 1 sec | |
Input file: | Standard input | Memory limit: | 256 Mb | |
Output file: | Standard output |
During a woodwork lesson at school, Timofey got his hands onto the try-square with wooden handle and metallic blade. Since Timofey has already finished his assignment (producing a stool), he started to roll the try-square along the coordinate axis. Starting position and movement direction are shown on the picture.
Your program must, given the coordinate of the point on the axis, determine which part of the try-square touched it.
Input contains three integers a, b and n — lengths of the wooden and metallic internal sides of the try-square and the coordinate of point. It is guaranteed that a and b are catheti of Pythagorean triangle (that is, hypotenuse is a whole integer).
Output must contain a single word:
wood
, if point is touched by the wooden handle,metal
, if point is touched by the metal blade,empty
, if point is not touched by the try-square.3 ≤ a < b ≤ 1000
1 ≤ n ≤ 109
No. | Standard input | Standard output |
---|---|---|
1 |
|
|
Author: | A. Baranov | Time limit: | 1 sec | |
Input file: | Standard input | Memory limit: | 256 Mb | |
Output file: | Standard output |
Vasya has heard that the discount season has started in a shop nearby.
For a single visit to the shop buyer tries to purchase as many items as possible with total weight not greater than Wmax, to be able to carry them out with him. There is just one item of every type in the shop. According to discount rules, one client is allowed no more than 3 visits.
You must write a program to calculate optimal sequence of purchases allowing to buy maximum number of items. Total cost of all items must not exceed Pmax — the amount of money Vasya has. If several variants with maximum number of items exist, choose one with minimal number of visits.
Input starts with total number of items n, followed by n pairs of integers: Pi — price of i-th item, Wi — its weight.
Next in the input data are maximum allowed amount of money Pmax (total for all visits) and Wmax — maximum weight Vasya is able to carry in each visit.
Output must contain optimal sequence of purchases, described as follows.
First, a total number of visits Vasya has no make. Then for each visit: count of items purchased, followed by item numbers in any order. Items are numbered starting from zero.
If there are several optimal solutions, output any of them.
0 < n ≤ 100, 0 < Pi ≤ Pmax ≤ 100, 0 < Wi ≤ Wmax ≤ 10
No. | Standard input | Standard output |
---|---|---|
1 |
|
|
2 |
|
|
Author: | М. Спорышев | Time limit: | 4 sec | |
Input file: | Standard input | Memory limit: | 512 Mb | |
Output file: | Standard output |
There is an array of integers ai. You can choose any single element and replace any single decimal digit of it with any other one. Cost of such replacement is equal to absolute value of the difference between digits.
Your program must find such a replacement of single digit in a single element that the decimal representation of the sum of all elements will contain at least one digit 9, or determine that it does not exist. The cost of chosen replacement must be minimal possible.
Leading zeroes are not eligible for replacement.
Input contains integer N — array size, followed by N integers ai.
Output three integers: element number, number of digit to be replaced and the digit to replace with.
Elements and digits are numbered starting with 0. Digits are numbered right to left.
It is guaranteed that sum of elements of the input array does not contain digit 9.
If required replacement does not exist, output − 1. If there are several solutions, output any of them.
1 ≤ N ≤ 100000
|ai| ≤ 109
ai ≠ 0
No. | Standard input | Standard output |
---|---|---|
1 |
|
|
2 |
|
|
3 |
|
|
Author: | A. Baranov | Time limit: | 1 sec | |
Input file: | Standard input | Memory limit: | 256 Mb | |
Output file: | Standard output |
There is a set of N rational fractions, each is represented by corresponding numerator Ai and denominator Bi.
You must write a program that outputs:
Input contains integer N, followed by N pairs of integers (Ai, Bi).
Output must contain a single integer — answer to the problem.
1 ≤ N ≤ 200, 1 ≤ (Ai, Bi) < 232
No. | Standard input | Standard output |
---|---|---|
1 |
|
|
2 |
|
|
3 |
|
|
Author: | A. Baranov | Time limit: | 1 sec | |
Input file: | Standard input | Memory limit: | 256 Mb | |
Output file: | Standard output |
There are two simple (without self-intersections) polygons, each represented by a sequence of vertices in either clockwise or counter-clockwise order.
Your program must determine whether the polygons are similar, that is, whether one of them can be transformed into another by applying zero or more of the following operations:
Input contains integer n, followed by 2 ⋅ n vertices (first one polygon, then another), represented by pairs of integers: (xi, yi).
Output must contain a single integer: 1, if polygons are similar, 0 otherwise.
It is guaranteed that both polygons are non-degenerate, i.e. have an area strictly greater than zero.
All edges also have non-zero length.
− 104 ≤ (xi, yi) ≤ 104, 3 ≤ n ≤ 105
No. | Standard input | Standard output |
---|---|---|
1 |
|
|
2 |
|
|
Author: | A. Baranov | Time limit: | 1 sec | |
Input file: | Standard input | Memory limit: | 256 Mb | |
Output file: | Standard output |
Vasya got a text string S as an inheritance from his grandmother. Vasya decided to play with this string.
On each step, Vasya picks a symbol and replaces every occurrence of this symbol with a space. Conversely, if this symbol is already replaced by space, Vasya replaces each of corresponding spaces back with the original symbol in the same position.
Your program must, after each step, determine the number of words (substrings of consequential non-spaces) currently present in the string.
First line of input contains string S. Following line contains string T, representing a sequence of symbols chosen by Vasya.
Strings consist of digits, small and capital Latin letters.
Output must contain a sequence of integers Ni — number of words in string S after step i.
Symbol case does matter, i.e. small and capital letters are considered different.
1 ≤ |S| ≤ 107, 1 ≤ |T| ≤ 104
No. | Standard input | Standard output |
---|---|---|
1 |
|
|
2 |
|
|
Author: | A. Baranov | Time limit: | 1 sec | |
Input file: | Standard input | Memory limit: | 256 Mb | |
Output file: | Standard output |
Young programmer Vasya develops a data storage with a programming interface of multi-dimensional array. Elements of this array are accessed by composite index: (i1, i2, …, iN). Array dimensions are defined by values A1, A2, …, AN (i.e. 0 ≤ ik < Ak, k = 1… N).
Index ranges are non-decreasing (Ak ≤ Ak + 1). A special feature of Vasya's array is index-permutation symmetry. It means that elements with composite indices coinciding up to their permutation are considered equal.
To compactly represent array in memory Vasya decided on the following layout. Elements are stored sequentially row-by-row (aka row-major order) in one-dimensional array, which corresponds to lexicographically increasing composite indices. Those elements for which some permutation of their composite index was already encountered before are skipped.
Your program must execute queries of two kinds.
Input data starts with an integer N — number of array dimensions.
Followed by N integers Aj — array sizes in each dimension. Next are integer M and M query descriptions, one per line. Queries are of two kinds:
Output must contain a sequence of integers — result of execution for each query in the order of input. Elements of composite indices must be sorted in ascending order.
Indexing of both one-dimensional and multi-dimensional arrays starts with zero.
0 ≤ ij < Aj ≤ 100, Aj ≤ Aj + 1, 1 ≤ N ≤ 10, 1 ≤ M ≤ 105
No. | Standard input | Standard output |
---|---|---|
1 |
|
|
2 |
|
|
Author: | A. Baranov | Time limit: | 1 sec | |
Input file: | Standard input | Memory limit: | 256 Mb | |
Output file: | Standard output |
All you need to do is to output all possible variations of the phrase Just do it!
,
differing only by the case of some letters (for example jUst DO it!
).
Output must contain all possible variations of the phrase, one per line. Order of lines is not important.
Author: | А. Щуров | Time limit: | 2 sec | |
Input file: | Standard input | Memory limit: | 512 Mb | |
Output file: | Standard output |
You are to make a circuit using ∑ni = 1ki given parts, so that circuit has the maximum possible number of free outputs.
There are n different types of parts: each type is characterized by the number of inputs (a) and outputs (b). Any input can be connected to any output. Unused outputs are called free outputs. When connecting a part to the circuit it is mandatory to use all inputs of this part.
The final circuit must have exactly one input so that you can connect the circuit to a single output source.
The first line contains an integer n — the number of part types.
The next n lines contain three integers ki ai bi — the number of parts of i-th type and a description of these parts.
Output must contain a single integer: the maximum possible number of free outputs after assembly and connection of the circuit to the source. The final circuit may not contain any parts, then only the source output is free.
0 ≤ n ≤ 106
1 ≤ k, a, b ≤ 106
No. | Standard input | Standard output |
---|---|---|
1 |
|
|
2 |
|
|
Author: | A. Baranov | Time limit: | 1 sec | |
Input file: | Standard input | Memory limit: | 256 Mb | |
Output file: | Standard output |
There are two integer arrays A and B, of length N each.
Your program must generate lexicographically minimal permutation of A, satisfying conditions:
Ai ≤ Bi, i = 1, 2, …, N
Input contains integer N, followed by 2 ⋅ N integers: array A, then array B.
Output must contain N integers — resulting permutation.
If the solution does not exist, output a single number − 1.
0 ≤ Ai, Bi ≤ 109, 1 ≤ N ≤ 2 ⋅ 105
No. | Standard input | Standard output |
---|---|---|
1 |
|
|
2 |
|
|