Problem A. Appropriate names ≡

 Author: G.Korneev, A. Klenin Input file: input.txt Time limit: 1 sec Output file: output.txt Memory limit: 256 Mb

Statement

A company wants to name a new product. Marketing department determined, that a name for a product is appropriate, if:

1. it consist of exactly N small English letters;
2. it has alternating vowels and consonants;
3. it does not contain any of given M offensive substrings.

Your program must calculate the number of possible appropriate names. Note that English vowels are: 'a', 'e', 'i', 'o', 'u', 'y'.

Input file format

First line of input file contains two integers N M — name length and number of offensive substrings.

Following M lines contain offensive substrings si, one per line.

Output file format

Output file must contain a single integer — number of appropriate names modulo 109 + 7.

Constraints

1 ≤ N ≤ 50, 0 ≤ M ≤ 50, 1 ≤ length(si) ≤ N.

Sample tests

No. Input file (input.txt) Output file (output.txt)
1
2 3
b
ca
b

227

2
5 0

374400


Problem B. Binary king ≡

 Author: M. Sporyshev Input file: input.txt Time limit: 1 sec Output file: output.txt Memory limit: 256 Mb

Statement

Young game developer Alice has created a new game and sent it to friends for beta-testing.

Young gamer Vasya wants to impress Alice by finishing the game completely.

At the final level Vasya fights the main boss — Binary King. At the beginning of the fight, Binary King generates a sequence K of N binary digits. After that, Vasya must present his own binary sequence V of the same length.

Vasya's sequence is scored as follows. For each position i, if Vi = 1 and Ki = 0, Vasya gains 1 point; if Vi = 0 and Ki = 1, Vasya loses 2 points.

Since Vasya plays at the hardest difficulty, each prefix of his sequence must contain at least as many zeroes as ones.

To win, Vasya must get maximum possible number of points.

Input file format

Input file contains N characters 0 and 1 — King's sequence.

Output file format

Output file must contain N characters 0 and 1 — Vasya's sequence scoring maximum number of points. If there are several optimal solutions, output any of them.

1 ≤ N ≤ 105

Sample tests

No. Input file (input.txt) Output file (output.txt)
1
111111111111
000000111111
2
111011001000
001011001011

Problem C. Covering the ring ≡

 Author: A. Baranov Input file: input.txt Time limit: 1 sec Output file: output.txt Memory limit: 256 Mb

Statement

Let us consider a rectangular domain D = {(x, y): Ax ≤ x ≤ Bx, Ay ≤ y ≤ By} covered by the uniform grid (two-dimensional array of cells):

Ωi j = {(x, y): xi < x < xi+1, yj < y < yj+1}, where xi = Ax + (i − 1) ⋅ Sx, yj = Ay + (j − 1) ⋅ Sy, i = 1, 2, …, Nx, j = 1, 2, …, Ny,

Sx = (Bx − Ax) / Nx, Sy = (By − Ay) / Ny — grid steps for x and y respectively.

The grid is defined by four real parameters (Ax, Ay, Sx, Sy) and two integer parameters (Nx, Ny).

Note that cells are open rectangles not including their boundaries.

Your program must count grid cells that have common points with the ring defined by its center (x0, y0), internal and external radius (r1, r2).

Input file format

Input file contains parameters of the grid: Ax, Ay, Sx, Sy, Nx, Ny, followed by parameters of the ring: x0, y0, r1, r2.

Output file format

Output file must contain a single integer — number of cells intersecting the ring.

Constraints

All input values have no more than 5 digits after the decimal point.

− 10 < (Ax, Ay) < 10, 1 ≤ (Bx − Ax) < 10, 1 ≤ (By − Ay) < 10, 0 < (Nx, Ny) ≤ 106,

10 < (x0, y0) < 10, 0 ≤ r1 ≤ r2 < 10

Sample tests

No. Input file (input.txt) Output file (output.txt)
1
-1.00000 -1.00000 0.12500 0.12500 16 16
0.00000  0.00000 0.50000 0.90000
160
2
 0.00000  0.00000 0.05000 0.07143 20 14
0.00000  0.00000 0.20000 0.74000
128

Problem D. Document signing ≡

 Author: A. Baranov Input file: input.txt Time limit: 1 sec Output file: output.txt Memory limit: 256 Mb

Statement

You have a document that needs to be signed by university president. It's hard to get president's time, but luckily you know his current location in the university campus. You also know that he is heading to his office now, so you can try to intercept him on the way and ask for a signature. Even more, everyone at university knows that president always takes fastest path wherever he goes. However, if there are several fastest paths, the president chooses any of them.

You need to write a program that determines whether you can guarantee meeting the president no matter which of the fastest path he picks, if you start moving from your room at the same time as the president.

More formally, university campus map is given as an undirected graph. i-th edge is given by its vertices (ai, bi) and traversal time ti (this is a traversal time for any human, either you or the president). Initially, the president is located at vertex p1 and is taking one of the fastest paths to his office located at vertex f. You are initially located at vertex p2. You can get the signature if you meet the president at vertex v such that:

• The president is guaranteed to go through v on his way to the office.
• You can get to v not later than he.

Input file format

Input file starts with two integers: n — the number of vertices and m — the number of edges.

Then m edges are given by integers ai, bi, ti. Vertices are numbered starting from 0.

Finally, there are three integers f, p1, and p2.

Output file format

Output file must contain the number of vertices where it is possible to get the signature, followed by the list of vertex numbers in ascending order.

Constraints

It is guaranteed that the graph is connected, i.e. it's possible to get from any vertex to any other vertex.

There is no more than one edge between each pair of vertices (ai, bi).

2 ≤ n ≤ 1000, 1 ≤ m ≤ n(n − 1) / 2

0 ≤ ai, bi, p1, p2, f < n

ai ≠ bi, p1 ≠ p2

0 < ti ≤ 1000

Sample tests

No. Input file (input.txt) Output file (output.txt)
1
8 9

0 1 1
5 1 1
5 6 2
6 4 3
5 4 7
1 2 2
2 4 4
3 7 5
7 4 6

3
0
5
4
1 3 4 7

2
8 9

5 6 1
6 4 4
0 1 2
1 7 1
7 2 2
1 4 4
1 2 4
4 2 1
2 3 7

3
0
5
0


Problem E. Emitting light ≡

 Author: A. Klenin Input file: input.txt Time limit: 1 sec Output file: output.txt Memory limit: 256 Mb

Statement

Young physicist Masha studies lasers. Masha wants to create a simplest 2-dimensional waveguide, consisting of two very long parallel mirrors, one coinciding with the Ox axis, and another located h millimeters above the first.

Masha's laser is located at coordinates (0, y) and emits light in direction (1, −1). Masha wants to hit a target located at coordinates (xt, yt) by choosing a good value for h. All coordinates are in millimeters.

Note that laser itself must fit into the waveguide, so h ≥ y. Both mirrors and laser are perfect, so light is always fully reflected at 45 degrees angle.

Input file format

Input file contains three integers y xt yt — coordinates of laser and target.

Output file format

Output file must contain a single integer — value of h. If there are several solutions, output the smallest one. If there are no solutions, output 1.

Constraints

1 ≤ y, xt, yt ≤ 109

Sample tests

No. Input file (input.txt) Output file (output.txt)
1
5 2 2
-1

2
5 6 1
5

3
2 16 2

2


Problem F. Fixing lottery ≡

 Author: A. Klenin Input file: input.txt Time limit: 1 sec Output file: output.txt Memory limit: 256 Mb

Statement

Well-known store chain "Three cats" decided to create a marketing lottery. Customers were given tickets with sequential integer numbers, and each month a single ticket number was selected as a winner.

To promote company image, it was decided that winning number must be divisible by 3.

For the first month of the lottery, company selected a ticket and printed it on a large banner to hang inside the store. Unfortunately, a person from marketing who selected a ticket did not know math, and selected ticket number which is not divisible by 3.

To quickly fix the banner, your program must change exactly one digit in the number so that:

1. Result is divisible by 3.
2. Result is less than original number.
3. Result has no leading zeroes.

Input file format

Input file contains a string of N decimal digits. First digit is non-zero.

Output file format

Output file must contain a string of N decimal digits — fixed ticket number. If there is more than one solution, output numerically smallest of them. If there is no solution, output string IMPOSSIBLE.

2 ≤ N ≤ 100

Sample tests

No. Input file (input.txt) Output file (output.txt)
1
13
12
2
200
IMPOSSIBLE
3
55
15

Problem G. Gathering ants ≡

 Author: A. Baranov Input file: input.txt Time limit: 1 sec Output file: output.txt Memory limit: 256 Mb

Statement

Let us consider 3-dimensional area that is split by uniform rectangular grid. Some cells contain ants. Each second every ant can either stay put or move to the neighboring cell in any of the six directions: up, down, right, left, forward and backward.

Your program must, given coordinates of starting cell for each ant, find minimum possible number of seconds (starting from zero) until any two ants meet in the same cell.

Input file format

Input file contains integer N followed by N triples of integer indices Xi, Yi, Zi — coordinates of starting cells for each ant.

Output file format

Output file must contain a single integer — minimal number of seconds until two ants meet.

Constraints

106 ≤ (Xi, Yi, Zi) ≤ 106, 2 ≤ N ≤ 5 ⋅ 104

Sample tests

No. Input file (input.txt) Output file (output.txt)
1
5
1 19 37
-9 5 10
4 3 6
9 8 7
17 20 5
6
2
5
6 49 58
-9 -1 3
2 8 9
-1 2 0
2 8 9
0

Problem H. Horticulture ≡

 Author: M. Sporyshev Input file: input.txt Time limit: 1 sec Output file: output.txt Memory limit: 256 Mb

Statement

Young programmer James decided to practice horticulture and brought home N plants.

Plant number i has starting height of ai centimeters and grows by vi centimeters per day. Vasya has a girlfriend Alice, who is currently traveling away from home. Alice does not like tall plants, so Vasya decided to cut his plants shorter from time to time.

Vasya can reduce height of any plant by exactly X centimeters (but not make it negative) in one cut. Vasya's endurance in not very good, so he can make no more than M cuts per day. Every day, plants grow after all cutting is finished.

Alice will return in T days. Vasya would like to cut plants in such a way as to make on the day of her arrival the height of the highest plant as small as possible.

Input file format

First line of input file contains integers N, T, M, X.

Second line contains N integers ai — initial plant heights.

Third line contains N integers vi — plant growth speeds.

Output file format

Output file must contain a single integer — minimal height of the tallest plant after T days.

Constraints

1 ≤ N ≤ 105

1 ≤ T ⋅ M ≤ 105

1 ≤ X, ai, vi ≤ 105

Sample tests

No. Input file (input.txt) Output file (output.txt)
1
4 1 2 4
8 9 10 11
8 8 3 2

13
2
1 100000 1 100000
100000
100000

100000

Problem I. Implicit array ≡

 Author: М. Спорышев Input file: input.txt Time limit: 1 sec Output file: output.txt Memory limit: 256 Mb

Statement

Sorted array of integers is represented implicitly. Instead of each element, a set of that element and its neighbors on the right and on the left is known. First and last array elements have no more than one neighbor. Note that the set does not represent neither the order of elements nor duplicate values.

Your program must output explicit representation of the array (all elements in order).

Input file format

First line of input file contains integer N — number of elements in array.

Following N lines contain implicit representation of array elements: set size si and si different integers aij — a set of i-th array element and its neighbors.

Output file format

Output file must contain N integers — elements of original sorted array.

1 ≤ N ≤ 105

109 ≤ aij ≤ 109

Sample tests

No. Input file (input.txt) Output file (output.txt)
1
7
1 1
1 1
2 1 2
2 1 2
2 2 3
2 2 3
1 3
1 1 1 2 2 3 3
2
1
1 7
7

Problem J. Jubilees ≡

 Author: A. Klenin Input file: input.txt Time limit: 1 sec Output file: output.txt Memory limit: 256 Mb

Statement

Let's define that a positive integer is a jubilee if it is divisible by 5 and is no less than 10. (i.e. 10, 15, 20, …).

Your program must, given a sequence of N decimal digits, find maximum number of jubilees which can be made by splitting this sequence into disjoint subsequences. In other words, every digit of sequence must be used no more than once and original order of digits must be preserved.

In the first sample, sequence 2535 can be split into 25 and 35.

In the second sample, sequence 1115005000 can be split into 10, 10, 10, 50 and 50.

Input file format

Input file contains a string of N decimal digits. First digit is non-zero.

Output file format

Output file must contain a single integer — number of jubilees.

1 ≤ N ≤ 100

Sample tests

No. Input file (input.txt) Output file (output.txt)
1
2535
2
2
1115005000
5

Problem K. K ≡

 Author: A. Klenin Input file: input.txt Time limit: 1 sec Output file: output.txt Memory limit: 256 Mb

Statement

Your program must output large letter 'K'.

Letter is drawn using '#' (ASCII 35) characters and is composed of vertical line of V characters, upper diagonal of H characters, and lower diagonal of L characters.

Diagonals must connect in the middle of the vertical line. If vertical line has even length, diagonals must connect on the character above the middle.

Letter image must be the smallest possible rectangle including the letter. Parts of rectangle not occupied by the letter must be filled with '.' (ASCII 46) character.

Input file format

Input file contains three integers V H L.

Output file format

Output file must contain letter image.

3 ≤ V ≤ 20

1 ≤ H, L ≤ 20

Sample tests

No. Input file (input.txt) Output file (output.txt)
1
6 3 2
...#
#.#.
##..
#...
##..
#.#.
#...

2
7 1 2
#..
#..
##.
#..
##.
#.#
#..


0.114s 0.007s 29