source
int64
2
2
difficulty
int64
7
25
name
stringlengths
9
60
description
stringlengths
164
7.12k
public_tests
dict
private_tests
dict
cf_rating
int64
0
3.5k
cf_points
float64
0
4k
2
7
1268_A. Long Beautiful Integer
You are given an integer x of n digits a_1, a_2, …, a_n, which make up its decimal notation in order from left to right. Also, you are given a positive integer k < n. Let's call integer b_1, b_2, …, b_m beautiful if b_i = b_{i+k} for each i, such that 1 ≤ i ≤ m - k. You need to find the smallest beautiful integer y,...
{ "input": [ "4 2\n1234\n", "3 2\n353\n" ], "output": [ "4\n1313\n", "3\n353\n" ] }
{ "input": [ "6 4\n819999\n", "5 3\n91471\n", "4 2\n6972\n", "6 3\n129130\n", "6 3\n288298\n", "9 3\n179179234\n", "6 2\n222228\n", "4 2\n2829\n", "6 2\n252611\n", "9 3\n129129222\n", "5 1\n26550\n", "4 2\n9192\n", "5 2\n55546\n", "4 2\n1921\n", "6 3\n129987...
1,700
500
2
8
1290_B. Irreducible Anagrams
Let's call two strings s and t anagrams of each other if it is possible to rearrange symbols in the string s to get a string, equal to t. Let's consider two strings s and t which are anagrams of each other. We say that t is a reducible anagram of s if there exists an integer k ≥ 2 and 2k non-empty strings s_1, t_1, s_...
{ "input": [ "aabbbbbbc\n6\n1 2\n2 4\n2 2\n1 9\n5 7\n3 5\n", "aaaaa\n3\n1 1\n2 4\n5 5\n" ], "output": [ "NO\nYES\nYES\nYES\nNO\nNO\n", "YES\nNO\nYES\n" ] }
{ "input": [ "f\n1\n1 1\n", "abca\n1\n1 4\n" ], "output": [ "YES\n", "YES\n" ] }
1,800
1,000
2
7
1333_A. Little Artem
Young boy Artem tries to paint a picture, and he asks his mother Medina to help him. Medina is very busy, that's why she asked for your help. Artem wants to paint an n × m board. Each cell of the board should be colored in white or black. Lets B be the number of black cells that have at least one white neighbor adja...
{ "input": [ "2\n3 2\n3 3\n" ], "output": [ "WB\nBB\nBB\nWBB\nBBB\nBBB\n" ] }
{ "input": [ "2\n3 2\n3 3\n", "16\n2 2\n2 3\n4 2\n2 5\n2 3\n3 3\n3 4\n3 5\n4 2\n3 4\n4 4\n4 5\n2 5\n3 5\n5 4\n5 5\n", "20\n73 69\n18 60\n60 59\n61 50\n82 85\n71 16\n43 8\n17 63\n24 95\n7 34\n69 72\n27 92\n33 49\n50 11\n45 71\n42 43\n84 14\n52 69\n22 87\n94 73\n", "19\n15 65\n44 92\n16 67\n48 53\n44 94...
1,000
500
2
9
1373_C. Pluses and Minuses
You are given a string s consisting only of characters + and -. You perform some process with this string. This process can be described by the following pseudocode: res = 0 for init = 0 to inf cur = init ok = true for i = 1 to |s| res = res + 1 ...
{ "input": [ "3\n--+-\n---\n++--+-\n" ], "output": [ "7\n9\n6\n" ] }
{ "input": [ "15\n-\n--\n+\n+-\n-\n+\n-\n+\n-\n-+\n-+\n-+\n-+\n-+\n-+\n" ], "output": [ "2\n5\n1\n2\n2\n1\n2\n1\n2\n3\n3\n3\n3\n3\n3\n" ] }
1,300
0
2
8
1396_B. Stoned Game
T is playing a game with his friend, HL. There are n piles of stones, the i-th pile initially has a_i stones. T and HL will take alternating turns, with T going first. In each turn, a player chooses a non-empty pile and then removes a single stone from it. However, one cannot choose a pile that has been chosen in th...
{ "input": [ "2\n1\n2\n2\n1 1\n" ], "output": [ "T\nHL\n" ] }
{ "input": [ "1\n2\n1 13\n", "1\n4\n2 3 1 2\n", "1\n7\n10 3 1 1 1 1 1\n", "1\n4\n3 1 1 1\n", "4\n5\n1 3 1 3 4\n1\n4\n1\n5\n2\n3 3\n", "2\n2\n1 4\n3\n3 1 3\n", "1\n3\n2 1 1\n", "3\n2\n4 3\n4\n2 2 2 3\n3\n1 4 1\n" ], "output": [ "T\n", "HL\n", "T\n", "HL\n", "HL\n...
1,800
1,000
2
10
141_D. Take-off Ramps
Vasya participates in a ski race along the X axis. The start is at point 0, and the finish is at L, that is, at a distance L meters from the start in the positive direction of the axis. Vasya has been training so hard that he can run one meter in exactly one second. Besides, there are n take-off ramps on the track, ea...
{ "input": [ "2 20\n9 8 12 6\n15 5 1 1\n", "2 20\n5 10 5 5\n4 16 1 7\n" ], "output": [ "16\n1\n2 ", "15\n1\n1 " ] }
{ "input": [ "0 100\n", "5 100\n84 5 19 103\n45 39 105 63\n16 67 59 24\n6 89 104 8\n94 5 3 19\n", "5 100\n85 5 4 6\n46 5 6 10\n15 5 4 9\n25 3 6 3\n26 2 2 8\n", "1 20\n7 1 5 1\n", "3 50\n28 1 1 3\n21 1 1 1\n34 1 1 1\n", "10 10\n3 2 2 91\n3 4 1 75\n7 3 6 47\n5 5 5 83\n1 2 2 18\n0 2 2 28\n5 5 3 8...
2,300
2,000
2
10
1438_D. Powerful Ksenia
Ksenia has an array a consisting of n positive integers a_1, a_2, …, a_n. In one operation she can do the following: * choose three distinct indices i, j, k, and then * change all of a_i, a_j, a_k to a_i ⊕ a_j ⊕ a_k simultaneously, where ⊕ denotes the [bitwise XOR operation](https://en.wikipedia.org/wiki/Bitwi...
{ "input": [ "5\n4 2 1 7 2\n", "4\n10 4 49 22\n" ], "output": [ "YES\n4\n1 2 3\n3 4 5\n1 2 5\n3 4 5\n", "NO\n" ] }
{ "input": [ "4\n1 1 1 1\n", "5\n4 2 1 7 2\n", "4\n4 4 4 4\n", "4\n1 3 2 2\n" ], "output": [ "YES\n1\n1 2 3\n", "YES\n4\n1 2 3\n3 4 5\n1 2 5\n3 4 5\n", "YES\n1\n1 2 3\n", "NO\n" ] }
2,200
1,750
2
9
1463_C. Busy Robot
You have a robot that can move along a number line. At time moment 0 it stands at point 0. You give n commands to the robot: at time t_i seconds you command the robot to go to point x_i. Whenever the robot receives a command, it starts moving towards the point x_i with the speed of 1 unit per second, and he stops when...
{ "input": [ "8\n3\n1 5\n3 0\n6 4\n3\n1 5\n2 4\n10 -5\n5\n2 -5\n3 1\n4 1\n5 1\n6 1\n4\n3 3\n5 -3\n9 2\n12 0\n8\n1 1\n2 -6\n7 2\n8 3\n12 -9\n14 2\n18 -1\n23 9\n5\n1 -4\n4 -7\n6 -1\n7 -3\n8 -7\n2\n1 2\n2 -2\n6\n3 10\n5 5\n8 0\n12 -4\n14 -7\n19 -5\n" ], "output": [ "\n1\n2\n0\n2\n1\n1\n0\n2\n" ] }
{ "input": [ "1\n2\n1 999999995\n1000000000 -1000000000\n", "1\n2\n1 999999998\n999999999 -999999999\n", "1\n3\n1 999999998\n999999999 -1000000000\n1000000000 -1000000000\n", "1\n2\n1 -999999997\n1000000000 100000000\n", "1\n2\n1 -999999995\n1000000000 1000000000\n", "1\n2\n1 999999998\n100000...
1,800
0
2
9
148_C. Terse princess
«Next please», — the princess called and cast an estimating glance at the next groom. The princess intends to choose the most worthy groom, this is, the richest one. Whenever she sees a groom who is more rich than each of the previous ones, she says a measured «Oh...». Whenever the groom is richer than all previous on...
{ "input": [ "10 2 3\n", "5 0 0\n" ], "output": [ "1 2 4 8 9 10 1 1 1 1 ", "1 1 1 1 1 " ] }
{ "input": [ "100 11 13\n", "100 2 0\n", "100 1 0\n", "100 3 0\n", "4 1 2\n", "10 7 0\n", "4 1 0\n", "4 3 0\n", "4 2 0\n", "7 4 0\n", "15 10 0\n", "2 1 0\n", "2 0 0\n", "5 2 2\n", "16 0 15\n", "4 2 1\n", "10 5 0\n", "100 0 2\n", "100 9 0\n", ...
1,700
1,000
2
7
1512_A. Spy Detected!
You are given an array a consisting of n (n ≥ 3) positive integers. It is known that in this array, all the numbers except one are the same (for example, in the array [4, 11, 4, 4] all numbers except one are equal to 4). Print the index of the element that does not equal others. The numbers in the array are numbered f...
{ "input": [ "4\n4\n11 13 11 11\n5\n1 4 4 4 4\n10\n3 3 3 3 10 3 3 3 3 3\n3\n20 20 10\n" ], "output": [ "\n2\n1\n5\n3\n" ] }
{ "input": [ "2\n3\n5 6 6\n3\n7 7 6\n" ], "output": [ "1\n3\n" ] }
800
0
2
11
1539_E. Game with Cards
The Alice's computer is broken, so she can't play her favorite card game now. To help Alice, Bob wants to answer n her questions. Initially, Bob holds one card with number 0 in the left hand and one in the right hand. In the i-th question, Alice asks Bob to replace a card in the left or right hand with a card with nu...
{ "input": [ "5 10\n3\n0 3\n0 3\n7\n4 7\n1 3\n2\n2 3\n3 7\n8\n1 8\n1 8\n6\n1 6\n7 10\n", "2 10\n3\n0 3\n0 2\n2\n3 4\n0 1\n", "2 10\n3\n0 3\n0 2\n2\n0 4\n0 2\n" ], "output": [ "Yes\n1 0 0 1 0 ", "No\n", "Yes\n0 0 \n" ] }
{ "input": [ "15 100\n84\n0 84\n0 84\n92\n92 92\n84 84\n87\n99 99\n6 78\n83\n92 92\n83 83\n81\n81 92\n81 83\n17\n17 92\n17 83\n25\n25 25\n17 83\n100\n100 100\n17 17\n16\n16 100\n16 17\n96\n100 100\n96 96\n28\n28 100\n28 96\n49\n28 100\n28 96\n22\n28 100\n22 22\n29\n28 49\n22 29\n64\n29 29\n64 64\n", "15 40\n2...
2,500
2,000
2
8
166_B. Polygons
You've got another geometrical task. You are given two non-degenerate polygons A and B as vertex coordinates. Polygon A is strictly convex. Polygon B is an arbitrary polygon without any self-intersections and self-touches. The vertices of both polygons are given in the clockwise order. For each polygon no three consecu...
{ "input": [ "5\n1 2\n4 2\n3 -3\n-2 -2\n-2 1\n4\n0 1\n1 2\n4 1\n2 -1\n", "5\n-1 2\n2 3\n4 1\n3 -2\n0 -3\n5\n1 0\n1 1\n3 1\n5 -1\n2 -1\n", "6\n-2 1\n0 3\n3 3\n4 1\n3 -2\n2 -2\n4\n0 1\n2 2\n3 1\n1 0\n" ], "output": [ "NO\n", "NO\n", "YES\n" ] }
{ "input": [ "3\n-1000000000 1000000000\n1000000000 0\n1000 -1000000000\n3\n1000 -999999999\n1000 0\n1001 0\n", "4\n0 3\n3 0\n0 -3\n-3 0\n4\n2 2\n2 -2\n-2 -2\n-2 2\n", "4\n0 0\n9 4\n12 -5\n5 -5\n4\n2 0\n2 3\n5 3\n5 0\n", "6\n3 3\n3 -3\n0 -4\n-4 -1\n-4 2\n1 5\n9\n0 0\n2 1\n2 -3\n0 -1\n0 -3\n-2 -2\n-1 -...
2,100
3,000
2
7
208_A. Dubstep
Vasya works as a DJ in the best Berland nightclub, and he often uses dubstep music in his performance. Recently, he has decided to take a couple of old songs and make dubstep remixes from them. Let's assume that a song consists of some number of words. To make the dubstep remix of this song, Vasya inserts a certain nu...
{ "input": [ "WUBWUBABCWUB\n", "WUBWEWUBAREWUBWUBTHEWUBCHAMPIONSWUBMYWUBFRIENDWUB\n" ], "output": [ "ABC\n", "WE ARE THE CHAMPIONS MY FRIEND\n" ] }
{ "input": [ "UB\n", "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\n", "AWUBBWUBCWUBD\n", "WUBZVMJWUBWUBWUBFOIMJQWKNZUBOFOFYCCWUBWUBWUBAUWWUBRDRAD...
900
500
2
10
233_D. Table
John Doe has an n × m table. John Doe can paint points in some table cells, not more than one point in one table cell. John Doe wants to use such operations to make each square subtable of size n × n have exactly k points. John Doe wondered, how many distinct ways to fill the table with points are there, provided that...
{ "input": [ "5 6 1\n" ], "output": [ "45\n" ] }
{ "input": [ "8 703528038 1\n", "94 1634867304 3200\n", "5 559703685 1\n", "80 500000000000000000 3200\n", "1 1000000000000000000 0\n", "4 1484499480 1\n", "87 434070509 3200\n", "38 1150965180 1\n", "5 37 24\n", "5 37 4\n", "92 548977630 3200\n", "36 290905083 1\n", ...
1,900
1,000
2
9
259_C. Little Elephant and Bits
The Little Elephant has an integer a, written in the binary notation. He wants to write this number on a piece of paper. To make sure that the number a fits on the piece of paper, the Little Elephant ought to delete exactly one any digit from number a in the binary record. At that a new number appears. It consists of ...
{ "input": [ "101\n", "110010\n" ], "output": [ "11\n", "11010\n" ] }
{ "input": [ "1111111110\n", "11\n", "111\n", "11111111111111111111111110110111001101100111010010101101101001011100011011000111010011110010101100010001011101011010010100001000011100001101101001100010100001001010010100100001111110100110011000101100001111111011010111001011111110111101000100101001001011\...
1,100
500
2
9
282_C. XOR and OR
The Bitlandians are quite weird people. They do everything differently. They have a different alphabet so they have a different definition for a string. A Bitlandish string is a string made only of characters "0" and "1". BitHaval (the mayor of Bitland) loves to play with Bitlandish strings. He takes some Bitlandish ...
{ "input": [ "1\n01\n", "11\n10\n", "000\n101\n" ], "output": [ "NO\n", "YES\n", "NO\n" ] }
{ "input": [ "0\n1\n", "1\n1\n", "11\n00\n", "0\n0\n", "01\n10\n", "100\n11111\n", "1101\n1111\n", "11000001\n00000001\n", "1000000000000000000000000000000000000011111111000000000000\n0111111111100000000000111111111000000000000000111111110001\n", "10\n00\n", "010101\n101010...
1,500
1,500
2
8
305_B. Continued Fractions
A continued fraction of height n is a fraction of form <image>. You are given two rational numbers, one is represented as <image> and the other one is represented as a finite fraction of height n. Check if they are equal. Input The first line contains two space-separated integers p, q (1 ≤ q ≤ p ≤ 1018) — the numerat...
{ "input": [ "9 4\n3\n1 2 4\n", "9 4\n3\n2 3 1\n", "9 4\n2\n2 4\n" ], "output": [ "NO", "YES", "YES" ] }
{ "input": [ "823443107025550834 331822464812968648\n42\n2 2 13 14 4 4 1 1 1 1 2 1 1 1 1 113 1 1 8 1 1 1 1 2 2 1 15 1 5 1 1 2 1 1 1 14 4 3 1 5 1 1\n", "2 1\n2\n1 2\n", "1000000000000000000 3\n3\n3 4 5\n", "9 4\n2\n2 3\n", "790637895857383456 679586240913926415\n40\n1 6 8 2 1 2 1 7 2 4 1 1 1 10 1 1...
1,700
1,000
2
7
353_A. Domino
Valera has got n domino pieces in a row. Each piece consists of two halves — the upper one and the lower one. Each of the halves contains a number from 1 to 6. Valera loves even integers very much, so he wants the sum of the numbers on the upper halves and the sum of the numbers on the lower halves to be even. To do t...
{ "input": [ "3\n1 4\n2 3\n4 4\n", "2\n4 2\n6 4\n", "1\n2 3\n" ], "output": [ "1\n", "0\n", "-1\n" ] }
{ "input": [ "10\n4 1\n3 2\n1 2\n2 6\n3 5\n2 1\n5 2\n4 6\n5 6\n3 1\n", "90\n5 2\n5 5\n5 1\n4 6\n4 3\n5 3\n5 6\n5 1\n3 4\n1 3\n4 2\n1 6\n6 4\n1 2\n6 1\n4 1\n6 2\n6 5\n6 2\n5 4\n3 6\n1 1\n5 5\n2 2\n1 6\n3 5\n6 5\n1 6\n1 5\n2 3\n2 6\n2 3\n3 3\n1 3\n5 1\n2 5\n3 6\n1 2\n4 4\n1 6\n2 3\n1 5\n2 5\n1 3\n2 2\n4 6\n3 6\...
1,200
500
2
8
377_B. Preparing for the Contest
Soon there will be held the world's largest programming contest, but the testing system still has m bugs. The contest organizer, a well-known university, has no choice but to attract university students to fix all the bugs. The university has n students able to perform such work. The students realize that they are the ...
{ "input": [ "3 4 10\n2 3 1 2\n2 1 3\n4 3 6\n", "3 4 9\n2 3 1 2\n2 1 3\n4 3 6\n", "3 4 5\n1 3 1 2\n2 1 3\n5 3 6\n", "3 4 9\n1 3 1 2\n2 1 3\n4 3 6\n" ], "output": [ "YES\n1 3 1 3\n", "YES\n3 3 2 3 \n", "NO\n", "YES\n2 3 2 3 \n" ] }
{ "input": [ "8 4 3\n1 1 3 8\n1 2 3 1 2 3 1 8\n2 4 3 2 1 3 4 2\n", "1 1 9\n1\n1\n10\n", "5 15 10\n2 5 3 2 4 4 4 3 2 3 1 6 3 1 5\n4 4 4 2 1\n11 13 13 12 15\n", "5 6 9\n2 4 6 5 4 3\n4 2 5 3 6\n3 2 5 3 7\n", "2 2 10\n1 2\n1 2\n5 5\n", "5 6 13\n2 4 6 5 4 3\n4 2 5 3 6\n3 2 5 3 7\n", "2 2 10\n1 ...
1,900
1,000
2
11
421_E. Cup Trick
The employees of the F company have lots of ways to entertain themselves. Today they invited a famous magician who shows a trick with plastic cups and a marble. The point is to trick the spectator's attention. Initially, the spectator stands in front of a line of n plastic cups. Then the magician places a small marble...
{ "input": [ "3 2\n1 2\n1 1\n", "3 3\n1 3\n2 3\n1 3\n", "2 1\n2 1\n" ], "output": [ "2 1 3 ", "-1\n", "2 1 " ] }
{ "input": [ "7 3\n4 4\n5 4\n2 4\n", "10 3\n7 10\n8 7\n5 5\n", "2 2\n1 2\n2 2\n", "2 1\n2 2\n", "100 50\n11 28\n11 1\n98 58\n38 27\n24 27\n67 37\n90 48\n91 14\n43 29\n3 64\n24 6\n53 19\n97 65\n13 27\n75 53\n37 82\n69 75\n94 99\n1 26\n95 60\n45 27\n100 82\n71 49\n86 99\n74 58\n88 68\n39 63\n38 23\n...
2,200
1,500
2
9
448_C. Painting Fence
Bizon the Champion isn't just attentive, he also is very hardworking. Bizon the Champion decided to paint his old fence his favorite color, orange. The fence is represented as n vertical planks, put in a row. Adjacent planks have no gap between them. The planks are numbered from the left to the right starting from one...
{ "input": [ "2\n2 2\n", "1\n5\n", "5\n2 2 1 2 1\n" ], "output": [ "2\n", "1\n", "3\n" ] }
{ "input": [ "14\n1 1 3 1 1 4 4 4 4 4 4 4 4 4\n", "12\n10 10 1 1 1 3 3 3 3 3 3 3\n", "2\n999635584 999595693\n", "8\n5000 5000 5 5000 5000 5000 5000 5000\n", "30\n1 4 5 3 9 7 8 4 5 9 2 3 4 2 3 4 5 5 6 8 1 2 9 4 3 7 2 6 5 4\n", "9\n4 4 4 4 20 4 4 4 4\n", "6\n3 3 3 3 1 3\n", "1\n10000000...
1,900
2,500
2
10
46_D. Parking Lot
Nowadays it is becoming increasingly difficult to park a car in cities successfully. Let's imagine a segment of a street as long as L meters along which a parking lot is located. Drivers should park their cars strictly parallel to the pavement on the right side of the street (remember that in the country the authors of...
{ "input": [ "10 1 1\n1\n1 12\n", "30 1 2\n6\n1 5\n1 4\n1 5\n2 2\n1 5\n1 4\n", "30 1 1\n6\n1 5\n1 4\n1 5\n2 2\n1 5\n1 4\n" ], "output": [ "-1\n", "0\n6\n11\n17\n23\n", "0\n6\n11\n17\n6\n" ] }
{ "input": [ "10 1 1\n2\n1 3\n1 7\n", "30 2 1\n10\n1 4\n2 1\n1 1\n1 3\n1 1\n1 1\n1 2\n1 5\n2 4\n2 7\n", "10 1 1\n5\n1 1\n1 2\n1 3\n2 2\n1 4\n", "10 1 1\n2\n1 3\n1 6\n", "50 2 3\n15\n1 7\n1 6\n1 1\n2 3\n2 1\n2 2\n1 1\n1 4\n1 6\n1 2\n1 8\n1 6\n2 7\n1 8\n2 9\n", "50 3 1\n30\n1 9\n2 1\n1 6\n1 5\n1...
1,800
0
2
11
492_E. Vanya and Field
Vanya decided to walk in the field of size n × n cells. The field contains m apple trees, the i-th apple tree is at the cell with coordinates (xi, yi). Vanya moves towards vector (dx, dy). That means that if Vanya is now at the cell (x, y), then in a second he will be at cell <image>. The following condition is satisfi...
{ "input": [ "5 5 2 3\n0 0\n1 2\n1 3\n2 4\n3 1\n", "2 3 1 1\n0 0\n0 1\n1 1\n" ], "output": [ "0 4\n", "0 0\n" ] }
{ "input": [ "6 6 1 1\n0 0\n1 1\n2 1\n0 1\n1 2\n3 4\n", "4 1 1 3\n0 3\n", "2 15 1 1\n0 0\n0 1\n0 0\n0 1\n0 0\n0 1\n0 0\n0 1\n0 0\n0 1\n0 0\n0 1\n0 0\n0 1\n0 0\n", "2 15 1 1\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n", "10 10 7 3\n9 0\n0 0\n7 6\n6 5\n4 8\n0 3\n2 1\...
2,000
2,500
2
10
543_D. Road Improvement
The country has n cities and n - 1 bidirectional roads, it is possible to get from every city to any other one if you move only along the roads. The cities are numbered with integers from 1 to n inclusive. All the roads are initially bad, but the government wants to improve the state of some roads. We will assume that...
{ "input": [ "3\n1 1\n", "5\n1 2 3 4\n" ], "output": [ "4 3 3 ", "5 8 9 8 5 " ] }
{ "input": [ "137\n1 1 3 3 5 5 7 8 8 10 10 12 12 14 14 16 16 18 18 20 21 21 23 23 25 26 26 28 28 30 30 32 33 33 35 36 36 38 38 40 41 41 43 43 45 46 46 48 49 49 51 51 53 53 55 56 56 58 59 59 61 62 62 64 64 66 67 67 1 1 71 71 73 73 75 76 76 78 78 80 80 82 82 84 84 86 86 88 89 89 91 91 93 94 94 96 96 98 98 100 101 1...
2,300
1,750
2
7
570_A. Elections
The country of Byalechinsk is running elections involving n candidates. The country consists of m cities. We know how many people in each city voted for each candidate. The electoral system in the country is pretty unusual. At the first stage of elections the votes are counted for each city: it is assumed that in each...
{ "input": [ "3 4\n10 10 3\n5 1 6\n2 2 2\n1 5 7\n", "3 3\n1 2 3\n2 3 1\n1 2 1\n" ], "output": [ "1\n", "2\n" ] }
{ "input": [ "2 2\n1 2\n0 0\n", "2 2\n2 1\n2 1\n", "2 3\n0 0\n0 0\n0 1\n", "2 3\n1 2\n0 0\n2 1\n", "1 1\n1000000000\n", "3 3\n0 0 0\n1 2 3\n1 3 2\n", "4 4\n1 4 1 3\n3 1 2 1\n1 0 0 2\n0 1 10 0\n", "1 100\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1...
1,100
500
2
10
591_D. Chip 'n Dale Rescue Rangers
A team of furry rescue rangers was sitting idle in their hollow tree when suddenly they received a signal of distress. In a few moments they were ready, and the dirigible of the rescue chipmunks hit the road. We assume that the action takes place on a Cartesian plane. The headquarters of the rescuers is located at poi...
{ "input": [ "0 0 5 5\n3 2\n-1 -1\n-1 0\n", "0 0 0 1000\n100 1000\n-50 0\n50 0\n" ], "output": [ "3.7299356163\n", "11.5470054150\n" ] }
{ "input": [ "-999 -999 -999 -999\n1000 1000\n999 0\n0 999\n", "0 0 4540 8910\n1000 1000\n-454 -891\n-454 -891\n", "0 0 0 1000\n100 5\n0 -50\n0 50\n", "10000 10000 -10000 -10000\n2 999\n-1 0\n0 0\n", "-753 8916 -754 8915\n1000 1000\n999 44\n999 44\n", "0 -10000 -10000 0\n1 777\n0 0\n0 0\n", ...
2,100
1,000
2
8
613_B. Skills
Lesha plays the recently published new version of the legendary game hacknet. In this version character skill mechanism was introduced. Now, each player character has exactly n skills. Each skill is represented by a non-negative integer ai — the current skill level. All skills have the same maximum level A. Along with...
{ "input": [ "3 5 10 1 339\n1 3 1\n", "3 5 10 1 5\n1 3 1\n" ], "output": [ " 35\n 5 5 ...
{ "input": [ "2 6 0 1 4\n5 1\n", "1 1000000000 1000 1000 1000000000000000\n1000000000\n", "1 100 1 2 30\n71\n", "4 5 3 7 15\n4 3 3 1\n", "5 5 10 20 50\n0 0 0 0 0\n", "1 1000000000 1000 1000 1000000000000000\n0\n", "1 100 1 2 30\n1\n", "5 5 10 20 50\n3 3 3 3 3\n", "3 6 4 6 8\n6 4 5\...
1,900
1,250
2
8
633_B. A Trivial Problem
Mr. Santa asks all the great programmers of the world to solve a trivial problem. He gives them an integer m and asks for the number of positive integers n, such that the factorial of n ends with exactly m zeroes. Are you among those great programmers who can solve this problem? Input The only line of input contains ...
{ "input": [ "1\n", "5\n" ], "output": [ "5\n5 6 7 8 9 ", "0\n" ] }
{ "input": [ "798\n", "12\n", "9353\n", "2083\n", "93346\n", "11024\n", "52032\n", "9282\n", "70\n", "41\n", "89\n", "8158\n", "729\n", "394\n", "815\n", "63218\n", "4604\n", "7657\n", "26151\n", "6641\n", "31\n", "2528\n", "1...
1,300
500
2
7
730_A. Toda 2
A group of n friends enjoys playing popular video game Toda 2. There is a rating system describing skill level of each player, initially the rating of the i-th friend is ri. The friends decided to take part in the championship as a team. But they should have equal ratings to be allowed to compose a single team consist...
{ "input": [ "5\n4 5 1 7 4\n", "3\n1 1 1\n", "2\n1 2\n" ], "output": [ "1\n8\n01010\n00011\n01010\n10010\n00011\n11000\n00011\n11000\n", "1\n0\n", "0\n2\n11\n11\n" ] }
{ "input": [ "100\n4 2 4 1 1 4 1 1 2 4 1 1 4 4 1 1 1 3 2 4 2 3 2 4 3 4 3 4 3 2 1 4 4 4 3 2 4 3 3 2 2 3 1 4 3 4 1 1 4 3 3 1 1 3 2 4 1 4 2 2 2 2 2 2 1 4 3 1 4 4 100 4 4 3 1 2 4 3 3 2 1 2 1 2 2 3 3 2 2 1 2 4 2 4 4 1 4 1 4 3\n", "10\n67 46 46 67 46 46 67 67 46 67\n", "100\n2 1 2 2 1 1 1 2 1 1 1 1 2 1 1 2 2 2 ...
1,800
0
2
11
774_E. Big Number and Remainder
Stepan has a very big positive integer. Let's consider all cyclic shifts of Stepan's integer (if we look at his integer like at a string) which are also integers (i.e. they do not have leading zeros). Let's call such shifts as good shifts. For example, for the integer 10203 the good shifts are the integer itself 10203...
{ "input": [ "521\n3\n", "5678901234567890123456789\n10000\n", "1001\n5\n" ], "output": [ "2", "123", "0" ] }
{ "input": [ "79\n60847671\n", "260597722\n10577910\n", "8460711003592660299377170851036141857177105821455679225940496548902563144980707248030407967017317182\n13315371\n", "1908\n86567928\n", "552352155\n13\n", "23457\n23456\n", "12345\n12344\n", "11533077525260\n193983\n", "486518...
2,300
0
2
11
819_E. Mister B and Flight to the Moon
In order to fly to the Moon Mister B just needs to solve the following problem. There is a complete indirected graph with n vertices. You need to cover it with several simple cycles of length 3 and 4 so that each edge is in exactly 2 cycles. We are sure that Mister B will solve the problem soon and will fly to the Mo...
{ "input": [ "5\n", "3\n" ], "output": [ "6\n3 1 2 3\n3 1 2 3\n3 1 4 5\n3 1 4 5\n4 4 2 5 3\n4 4 2 5 3\n", "2\n3 1 2 3\n3 1 2 3\n" ] }
{ "input": [ "112\n", "210\n", "35\n", "168\n", "4\n", "6\n", "49\n", "84\n", "5\n", "189\n", "140\n", "42\n", "63\n", "119\n", "10\n", "56\n", "9\n", "147\n", "126\n", "7\n", "154\n", "28\n", "70\n", "175\n", "105\n",...
2,800
2,500
2
9
845_C. Two TVs
Polycarp is a great fan of television. He wrote down all the TV programs he is interested in for today. His list contains n shows, i-th of them starts at moment li and ends at moment ri. Polycarp owns two TVs. He can watch two different shows simultaneously with two TVs but he can only watch one show at any given mom...
{ "input": [ "4\n1 2\n2 3\n2 3\n1 2\n", "3\n1 2\n2 3\n4 5\n" ], "output": [ "NO\n", "YES\n" ] }
{ "input": [ "5\n0 3\n14 16\n6 8\n5 9\n9 15\n", "1\n0 1000000000\n", "3\n1 8\n5 6\n6 9\n", "4\n2 3\n5 9\n8 10\n9 10\n", "3\n6 9\n0 1\n0 2\n", "3\n1 2\n2 3\n2 4\n", "3\n1 2\n1 2\n2 3\n", "4\n1 7\n2 3\n4 5\n6 7\n", "2\n0 2\n0 6\n", "5\n8 10\n4 10\n3 4\n14 15\n17 19\n", "3\n2 ...
1,500
0
2
8
936_B. Sleepy Game
Petya and Vasya arranged a game. The game runs by the following rules. Players have a directed graph consisting of n vertices and m edges. One of the vertices contains a chip. Initially the chip is located at vertex s. Players take turns moving the chip along some edge of the graph. Petya goes first. Player who can't m...
{ "input": [ "5 6\n2 2 3\n2 4 5\n1 4\n1 5\n0\n1\n", "3 2\n1 3\n1 1\n0\n2\n", "2 2\n1 2\n1 1\n1\n" ], "output": [ "Win\n1 2 4 5 \n", "Lose\n", "Draw\n" ] }
{ "input": [ "5 5\n2 2 3\n2 4 5\n1 5\n0\n0\n1\n", "5 5\n1 2\n2 3 4\n0\n1 5\n1 3\n1\n", "5 5\n2 2 3\n1 4\n0\n1 5\n1 4\n2\n", "11 20\n1 2\n2 7 6\n1 7\n4 10 9 3 2\n2 9 2\n1 3\n0\n0\n3 1 6 7\n4 11 7 5 6\n2 2 8\n4\n", "3 3\n1 2\n2 1 3\n0\n1\n", "5 5\n1 2\n1 3\n2 2 4\n1 5\n0\n1\n", "11 20\n1 2\n...
2,100
1,000
2
13
961_G. Partitions
You are given a set of n elements indexed from 1 to n. The weight of i-th element is wi. The weight of some subset of a given set is denoted as <image>. The weight of some partition R of a given set into k subsets is <image> (recall that a partition of a given set is a set of its subsets such that every element of the ...
{ "input": [ "5 2\n1 2 3 4 5\n", "4 2\n2 3 2 3\n" ], "output": [ "645\n", "160\n" ] }
{ "input": [ "5 2\n3113 612 440 2761 6970\n", "1 1\n1\n", "4 2\n4049 2220 6447 3695\n", "5 3\n9887 7162 3409 8937 3662\n", "5 5\n1546 1477 962 7095 8934\n", "6 5\n7906 9870 6443 6162 477 4656\n", "4 4\n9900 6535 5489 1853\n", "3 1\n2403 4573 3678\n", "2 2\n8224 8138\n", "1 1\n1...
2,700
0
2
7
98_A. Help Victoria the Wise
Vasilisa the Wise from a far away kingdom got a present from her friend Helga the Wise from a farther away kingdom. The present is a surprise box, yet Vasilisa the Wise doesn't know yet what the surprise actually is because she cannot open the box. She hopes that you can help her in that. The box's lock is constructed...
{ "input": [ "YYYYYY\n", "ROYGBV\n", "BOOOOB\n" ], "output": [ "1\n", "30\n", "2\n" ] }
{ "input": [ "RRYYOO\n", "YYBBOO\n", "RRBYRR\n", "YYYYRB\n", "BYOVRR\n", "GVGBVO\n", "OVBRYG\n", "BRRBRB\n", "YYYRRY\n", "BBBBBY\n", "RRYOGB\n", "VOBYGO\n", "BVRYBV\n", "GRBYVO\n", "RRRGGB\n", "OGGOOG\n", "RRRRRR\n", "ROYYGG\n", "VOBVYB\n", ...
1,700
500
2
11
1005_E1. Median on Segments (Permutations Edition)
You are given a permutation p_1, p_2, ..., p_n. A permutation of length n is a sequence such that each integer between 1 and n occurs exactly once in the sequence. Find the number of pairs of indices (l, r) (1 ≤ l ≤ r ≤ n) such that the value of the median of p_l, p_{l+1}, ..., p_r is exactly the given number m. The ...
{ "input": [ "5 4\n2 4 5 3 1\n", "15 8\n1 15 2 14 3 13 4 8 12 5 11 6 10 7 9\n", "5 5\n1 2 3 4 5\n" ], "output": [ "4", "48", "1" ] }
{ "input": [ "2 1\n1 2\n", "5 4\n1 4 5 60 4\n", "3 3\n5 5 3\n", "5 2\n2 1 3 4 5\n", "3 1\n2 1 3\n", "8 7\n2 3 6 8 7 5 4 1\n", "11 2\n9 4 7 5 11 1 3 8 10 2 6\n", "2 2\n1 2\n", "1 1\n1\n", "1 200000\n1\n", "3 1\n1 2 3\n", "2 1\n2 1\n", "1 1\n2\n", "9 9\n6 4 8 5 1 ...
1,800
0
2
9
1029_C. Maximal Intersection
You are given n segments on a number line; each endpoint of every segment has integer coordinates. Some segments can degenerate to points. Segments can intersect with each other, be nested in each other or even coincide. The intersection of a sequence of segments is such a maximal set of points (not necesserily having...
{ "input": [ "2\n3 10\n1 5\n", "5\n2 6\n1 3\n0 4\n1 20\n0 4\n", "4\n1 3\n2 6\n0 4\n3 3\n", "3\n4 5\n1 2\n9 20\n" ], "output": [ "7\n", "2\n", "1\n", "0\n" ] }
{ "input": [ "3\n1 6\n2 5\n3 4\n", "2\n1 3\n2 2\n", "3\n6 10\n4 8\n5 9\n", "2\n2 2\n1 3\n", "6\n2 4\n3 6\n2 6\n2 5\n1 4\n1 4\n", "2\n4 4\n1 3\n", "3\n2 5\n1 4\n1 6\n", "3\n3 5\n2 5\n2 6\n", "3\n0 10\n5 10\n0 9\n", "6\n2 4\n3 5\n2 5\n1 6\n2 4\n3 6\n", "3\n6 10\n6 10\n1 5\n",...
1,600
0
2
8
104_B. Testing Pants for Sadness
The average miner Vaganych took refresher courses. As soon as a miner completes the courses, he should take exams. The hardest one is a computer test called "Testing Pants for Sadness". The test consists of n questions; the questions are to be answered strictly in the order in which they are given, from question 1 to ...
{ "input": [ "2\n1 1\n", "1\n10\n", "2\n2 2\n" ], "output": [ "2\n", "10\n", "5\n" ] }
{ "input": [ "100\n6659 5574 5804 7566 7431 1431 3871 6703 200 300 3523 3580 8500 2312 4812 3149 3324 5846 8965 5758 5831 1341 7733 4477 355 3024 2941 9938 1494 16 1038 8262 9938 9230 5192 8113 7575 7696 5566 2884 8659 1951 1253 6480 3877 3707 5482 3825 5359 44 3219 3258 1785 5478 4525 5950 2417 1991 8885 4264 87...
1,100
500
2
9
1071_C. Triple Flips
You are given an array a of length n that consists of zeros and ones. You can perform the following operation multiple times. The operation consists of two steps: 1. Choose three integers 1 ≤ x < y < z ≤ n, that form an arithmetic progression (y - x = z - y). 2. Flip the values a_x, a_y, a_z (i.e. change 1 to 0...
{ "input": [ "5\n1 1 0 1 1\n", "3\n0 1 0\n" ], "output": [ "YES\n2\n3 4 5\n1 2 3\n", "NO\n" ] }
{ "input": [ "7\n0 0 1 0 0 0 0\n", "6\n0 0 1 0 0 0\n", "6\n0 0 0 1 0 0\n", "5\n0 1 0 0 0\n", "8\n0 0 0 1 1 1 1 1\n", "6\n1 0 0 0 0 0\n", "7\n0 0 0 0 1 0 0\n", "10\n0 0 1 1 1 1 1 0 1 1\n", "8\n0 0 0 1 1 0 0 0\n", "11\n1 1 0 0 0 0 0 0 0 1 1\n", "7\n0 0 0 0 0 0 1\n", "14\n...
2,600
2,500
2
13
1141_G. Privatization of Roads in Treeland
Treeland consists of n cities and n-1 roads. Each road is bidirectional and connects two distinct cities. From any city you can get to any other city by roads. Yes, you are right — the country's topology is an undirected tree. There are some private road companies in Treeland. The government decided to sell roads to t...
{ "input": [ "4 2\n3 1\n1 4\n1 2\n", "10 2\n10 3\n1 2\n1 3\n1 4\n2 5\n2 6\n2 7\n3 8\n3 9\n", "6 2\n1 4\n4 3\n3 5\n3 6\n5 2\n" ], "output": [ "1\n1 1 1 ", "3\n3 1 2 3 2 3 1 1 2 ", "2\n1 2 1 1 2 " ] }
{ "input": [ "3 0\n1 2\n1 3\n", "3 2\n2 1\n1 3\n", "2 1\n1 2\n", "4 0\n2 3\n2 4\n3 1\n", "4 1\n4 2\n2 1\n3 2\n", "4 2\n1 2\n1 4\n4 3\n", "4 3\n4 1\n3 1\n1 2\n", "2 0\n2 1\n", "3 1\n3 2\n2 1\n" ], "output": [ "2\n1 2 ", "1\n1 1 ", "1\n1 ", "2\n2 1 1 ", "1\n1 ...
1,900
0
2
8
1162_B. Double Matrix
You are given two n × m matrices containing integers. A sequence of integers is strictly increasing if each next number is greater than the previous one. A row is strictly increasing if all numbers from left to right are strictly increasing. A column is strictly increasing if all numbers from top to bottom are strictly...
{ "input": [ "2 2\n2 10\n11 5\n9 4\n3 12\n", "3 2\n1 3\n2 4\n5 10\n3 1\n3 6\n4 8\n", "2 3\n2 4 5\n4 5 6\n3 6 7\n8 10 11\n" ], "output": [ "Possible\n", "Impossible", "Possible\n" ] }
{ "input": [ "3 3\n1 2 3\n4 5 6\n7 80 90\n2 3 4\n5 6 7\n8 92 91\n", "2 2\n6 7\n5 8\n6 7\n4 10\n", "2 2\n2 2\n2 4\n1 2\n2 5\n", "2 2\n2 3\n4 5\n5 5\n5 5\n", "2 2\n1 1\n2 3\n10 11\n12 13\n", "2 2\n3 4\n1 2\n5 6\n3 4\n", "1 3\n3 6 6\n1 2 3\n", "2 3\n5 6 7\n1 2 3\n5 6 7\n1 2 3\n", "2 2...
1,400
1,000
2
7
1183_A. Nearest Interesting Number
Polycarp knows that if the sum of the digits of a number is divisible by 3, then the number itself is divisible by 3. He assumes that the numbers, the sum of the digits of which is divisible by 4, are also somewhat interesting. Thus, he considers a positive integer n interesting if its sum of digits is divisible by 4. ...
{ "input": [ "99\n", "432\n", "237\n", "42\n" ], "output": [ "103\n", "435\n", "237\n", "44\n" ] }
{ "input": [ "398\n", "909\n", "120\n", "399\n", "1\n", "997\n", "400\n", "6\n", "518\n", "799\n", "3\n", "999\n", "36\n", "9\n", "970\n", "1000\n", "8\n", "12\n", "4\n", "2\n", "898\n", "188\n", "38\n", "7\n" ], "outp...
800
0
2
8
1200_B. Block Adventure
Gildong is playing a video game called Block Adventure. In Block Adventure, there are n columns of blocks in a row, and the columns are numbered from 1 to n. All blocks have equal heights. The height of the i-th column is represented as h_i, which is the number of blocks stacked in the i-th column. Gildong plays the g...
{ "input": [ "5\n3 0 1\n4 3 5\n3 1 2\n1 4 7\n4 10 0\n10 20 10 20\n2 5 5\n0 11\n1 9 9\n99\n" ], "output": [ "YES\nNO\nYES\nNO\nYES\n" ] }
{ "input": [ "1\n97 0 0\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n" ], "output": [ "YES\n" ] }
1,200
1,000
2
7
1242_A. Tile Painting
Ujan has been lazy lately, but now has decided to bring his yard to good shape. First, he decided to paint the path from his house to the gate. The path consists of n consecutive tiles, numbered from 1 to n. Ujan will paint each tile in some color. He will consider the path aesthetic if for any two different tiles wit...
{ "input": [ "5\n", "4\n" ], "output": [ "5\n", "2\n" ] }
{ "input": [ "812990017201\n", "1\n", "977592945289\n", "322687697779\n", "442654694329\n", "6469693230\n", "847288609443\n", "10460353203\n", "42\n", "3\n", "200560490130\n", "19463908527\n", "918797935650\n", "916517107801\n", "2000006\n", "6\n", "...
1,500
500
2
8
1261_B1. Optimal Subsequences (Easy Version)
This is the easier version of the problem. In this version 1 ≤ n, m ≤ 100. You can hack this problem only if you solve and lock both problems. You are given a sequence of integers a=[a_1,a_2,...,a_n] of length n. Its subsequence is obtained by removing zero or more elements from the sequence a (they do not necessarily...
{ "input": [ "7\n1 2 1 3 1 2 1\n9\n2 1\n2 2\n3 1\n3 2\n3 3\n1 1\n7 1\n7 7\n7 4\n", "3\n10 20 10\n6\n1 1\n2 1\n2 2\n3 1\n3 2\n3 3\n" ], "output": [ "2\n3\n2\n3\n2\n3\n1\n1\n3\n", "20\n10\n20\n10\n20\n10\n" ] }
{ "input": [ "5\n3 1 4 1 2\n15\n5 5\n5 4\n5 3\n5 2\n5 1\n4 4\n4 3\n4 2\n4 1\n3 3\n3 2\n3 1\n2 2\n2 1\n1 1\n", "2\n3922 3922\n3\n2 2\n2 1\n1 1\n", "2\n1 10\n3\n2 2\n2 1\n1 1\n", "2\n392222 322\n3\n2 2\n2 1\n1 1\n", "1\n1000000000\n1\n1 1\n", "1\n1\n3\n1 1\n1 1\n1 1\n" ], "output": [ "2\...
1,600
500
2
9
1283_C. Friends and Gifts
There are n friends who want to give gifts for the New Year to each other. Each friend should give exactly one gift and receive exactly one gift. The friend cannot give the gift to himself. For each friend the value f_i is known: it is either f_i = 0 if the i-th friend doesn't know whom he wants to give the gift to or...
{ "input": [ "7\n7 4 0 3 0 5 1\n", "5\n5 0 0 2 4\n", "5\n2 1 0 0 0\n", "7\n7 0 0 1 4 0 6\n" ], "output": [ "7 4 2 3 6 5 1 ", "5 3 1 2 4 \n", "2 1 4 5 3 ", "7 3 2 1 4 5 6 " ] }
{ "input": [ "104\n24 0 77 92 89 16 0 81 46 0 12 0 0 0 0 0 74 0 0 88 0 21 20 55 6 0 33 5 0 76 8 68 17 0 0 7 0 0 0 35 0 87 32 14 102 59 49 0 0 11 0 0 0 23 57 31 22 99 63 38 0 0 0 90 0 25 0 0 19 0 50 0 0 0 60 48 0 0 0 0 0 0 0 0 42 0 0 0 98 97 10 65 86 95 0 4 0 45 0 0 75 82 0 78\n", "3\n2 0 0\n", "5\n2 1 0 0...
1,500
0
2
8
1389_B. Array Walk
You are given an array a_1, a_2, ..., a_n, consisting of n positive integers. Initially you are standing at index 1 and have a score equal to a_1. You can perform two kinds of moves: 1. move right — go from your current index x to x+1 and add a_{x+1} to your score. This move can only be performed if x<n. 2. mo...
{ "input": [ "4\n5 4 0\n1 5 4 3 2\n5 4 1\n1 5 4 3 2\n5 4 4\n10 20 30 40 50\n10 7 3\n4 6 8 2 9 9 7 4 10 9\n" ], "output": [ "15\n19\n150\n56\n" ] }
{ "input": [ "2\n5 4 1\n1 5 4 3 2\n5 4 1\n1 5 4 3 2\n" ], "output": [ "19\n19\n" ] }
1,600
0
2
11
1409_E. Two Platforms
There are n points on a plane. The i-th point has coordinates (x_i, y_i). You have two horizontal platforms, both of length k. Each platform can be placed anywhere on a plane but it should be placed horizontally (on the same y-coordinate) and have integer borders. If the left border of the platform is (x, y) then the r...
{ "input": [ "4\n7 1\n1 5 2 3 1 5 4\n1 3 6 7 2 5 4\n1 1\n1000000000\n1000000000\n5 10\n10 7 5 15 8\n20 199 192 219 1904\n10 10\n15 19 8 17 20 10 9 2 10 19\n12 13 6 17 1 14 7 9 19 3\n" ], "output": [ "6\n1\n5\n10\n" ] }
{ "input": [ "4\n1 1000000000\n1\n123456\n1 1000000000\n21345\n987654321\n1 1000000000\n1000000000\n1000000000\n1 1000000000\n1000000000\n1\n" ], "output": [ "1\n1\n1\n1\n" ] }
1,800
0
2
9
1430_C. Numbers on Whiteboard
Numbers 1, 2, 3, ... n (each integer from 1 to n once) are written on a board. In one operation you can erase any two numbers a and b from the board and write one integer (a + b)/(2) rounded up instead. You should perform the given operation n - 1 times and make the resulting number that will be left on the board as s...
{ "input": [ "1\n4\n" ], "output": [ "2\n4 3\n4 2\n3 1\n" ] }
{ "input": [ "1\n4\n" ], "output": [ "2\n4 3\n4 2\n3 1\n" ] }
1,000
0
2
9
1477_C. Nezzar and Nice Beatmap
Nezzar loves the game osu!. osu! is played on beatmaps, which can be seen as an array consisting of distinct points on a plane. A beatmap is called nice if for any three consecutive points A,B,C listed in order, the angle between these three points, centered at B, is strictly less than 90 degrees. <image> Points A,B,...
{ "input": [ "5\n0 0\n5 0\n4 2\n2 1\n3 0\n" ], "output": [ "\n1 2 5 3 4\n" ] }
{ "input": [ "20\n1000000000 0\n500000000 0\n809016994 587785252\n404508497 293892626\n309016994 951056516\n154508497 475528258\n-309016994 951056516\n-154508497 475528258\n-809016994 587785252\n-404508497 293892626\n-1000000000 0\n-500000000 0\n-809016994 -587785252\n-404508497 -293892626\n-309016994 -951056516\...
2,200
1,500
2
7
1504_A. Déjà Vu
A palindrome is a string that reads the same backward as forward. For example, the strings "z", "aaa", "aba", and "abccba" are palindromes, but "codeforces" and "ab" are not. You hate palindromes because they give you déjà vu. There is a string s. You must insert exactly one character 'a' somewhere in s. If it is poss...
{ "input": [ "6\ncbabc\nab\nzza\nba\na\nnutforajaroftuna\n" ], "output": [ "\nYES\ncbabac\nYES\naab\nYES\nzaza\nYES\nbaa\nNO\nYES\nnutforajarofatuna\n" ] }
{ "input": [ "6\ncbabc\nab\nzza\nba\na\nnutforajaroftuna\n" ], "output": [ "YES\ncbabca\nYES\naab\nYES\nzzaa\nYES\nbaa\nNO\nYES\nnutforajaroftunaa\n" ] }
800
500
2
10
159_D. Palindrome pairs
You are given a non-empty string s consisting of lowercase letters. Find the number of pairs of non-overlapping palindromic substrings of this string. In a more formal way, you have to find the quantity of tuples (a, b, x, y) such that 1 ≤ a ≤ b < x ≤ y ≤ |s| and substrings s[a... b], s[x... y] are palindromes. A pal...
{ "input": [ "aa\n", "aaa\n", "abacaba\n" ], "output": [ "1\n", "5\n", "36\n" ] }
{ "input": [ "abacabadabacabaeabacabadabacabafabacabadabacabaeabacabadabacabagabacabadabacabaeabacabadabacabafabacabadabacabaeabacabadabacabahabacabadabpcabaeabacabadabacabafabacabadabacabaeabacabadabacabagabacabadabacabaeabacabadabacabafabacabadabacabaeabacabadabacabaeeegbahbcahagefafcedggigbhdaeebfbagfafhdfcddd...
1,500
2,000
2
8
201_B. Guess That Car!
A widely known among some people Belarusian sport programmer Yura possesses lots of information about cars. That is why he has been invited to participate in a game show called "Guess That Car!". The game show takes place on a giant parking lot, which is 4n meters long from north to south and 4m meters wide from west ...
{ "input": [ "2 3\n3 4 5\n3 9 1\n", "3 4\n1 0 0 0\n0 0 3 0\n0 0 5 5\n" ], "output": [ " 392\n1 1\n", " 240\n2 3\n" ] }
{ "input": [ "6 5\n0 0 0 0 0\n0 0 0 0 0\n0 3 3 3 0\n0 3 3 3 0\n0 3 3 3 0\n0 0 0 0 0\n", "2 3\n0 0 0\n0 0 0\n", "10 10\n0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0\n0 0 1585 1564 3603 1095 1364 1029 3189 1331\n0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 1749\n0 3495 1540 6...
1,800
1,000
2
7
226_A. Flying Saucer Segments
An expedition group flew from planet ACM-1 to Earth in order to study the bipedal species (its representatives don't even have antennas on their heads!). The flying saucer, on which the brave pioneers set off, consists of three sections. These sections are connected by a chain: the 1-st section is adjacent only to the...
{ "input": [ "3 8\n", "1 10\n" ], "output": [ "2\n", "2\n" ] }
{ "input": [ "2 81\n", "2 3\n", "4 27\n", "7 90\n", "331358794 820674098\n", "234899623 6561\n", "422262807 3\n", "528551307 729\n", "108260816 609551797\n", "969271595 9\n", "296519935 960061928\n", "596386879 356583466\n", "3 3\n", "3 60\n", "4 81\n", ...
1,400
500
2
10
24_D. Broken robot
You received as a gift a very clever robot walking on a rectangular board. Unfortunately, you understood that it is broken and behaves rather strangely (randomly). The board consists of N rows and M columns of cells. The robot is initially at some cell on the i-th row and the j-th column. Then at every step the robot c...
{ "input": [ "10 14\n5 14\n", "10 10\n10 4\n" ], "output": [ "18.0038068653", "0.0000000000" ] }
{ "input": [ "1000 1\n777 1\n", "126 125\n115 22\n", "1000 1000\n1 1\n", "1000 2\n987 2\n", "1000 1\n1 1\n", "1 2\n1 1\n", "663 904\n192 518\n", "2 1\n1 1\n", "1000 2\n1 1\n", "293 183\n279 21\n", "1000 1\n1000 1\n", "812 240\n561 19\n", "552 36\n199 35\n", "892...
2,400
0
2
8
298_B. Sail
The polar bears are going fishing. They plan to sail from (sx, sy) to (ex, ey). However, the boat can only sail by wind. At each second, the wind blows in one of these directions: east, south, west or north. Assume the boat is currently at (x, y). * If the wind blows to the east, the boat will move to (x + 1, y). ...
{ "input": [ "10 5 3 3 6\nNENSWESNEE\n", "5 0 0 1 1\nSESNW\n" ], "output": [ "-1\n", "4\n" ] }
{ "input": [ "15 1 1 1 2\nNNNNNNNNNNNNNNN\n", "11 1 1 1 2\nNNNNNNNNNNN\n", "1 0 0 0 -1\nS\n", "41 -264908123 -86993764 -264908123 -86993723\nNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN\n", "19 -172106364 -468680119 -172106365 -468680119\nSSEEESSSESESWSEESSS\n", "1 5 5 5 6\nE\n", "34 -1000000...
1,200
500
2
8
369_B. Valera and Contest
Valera loves to participate in competitions. Especially in programming contests. Today he has participated in the contest with his team, consisting of n students (including Valera). This contest was an individual competition, so each student in the team solved problems individually. After the contest was over, Valera ...
{ "input": [ "5 3 1 3 15 9\n", "5 3 1 3 13 9\n" ], "output": [ "3 3 3 3 3 \n", "3 3 3 2 2 \n" ] }
{ "input": [ "300 100 1 3 900 300\n", "1 1 1 1000 656 656\n", "999 999 13 333 169609 169609\n", "432 32 13 123 28942 3824\n", "3 2 1 1000 1816 1652\n", "5 3 1 1000 2732 2055\n", "1000 1000 111 111 111000 111000\n", "1000 567 996 1000 997986 566445\n", "1000 500 500 1000 750000 3750...
1,400
1,000
2
9
391_C1. The Tournament
This problem consists of three subproblems: for solving subproblem C1 you will receive 4 points, for solving subproblem C2 you will receive 4 points, and for solving subproblem C3 you will receive 8 points. Manao decided to pursue a fighter's career. He decided to begin with an ongoing tournament. Before Manao joined,...
{ "input": [ "5 2\n2 10\n2 10\n1 1\n3 1\n3 1\n", "2 1\n3 2\n4 0\n", "3 2\n1 1\n1 4\n2 2\n" ], "output": [ "12\n", "-1\n", "3\n" ] }
{ "input": [ "1 1\n1 200000\n", "9 4\n3 10\n4 11\n4 2\n1 3\n1 7\n2 5\n2 6\n3 4\n1 7\n", "15 3\n2 39237\n6 42209\n8 99074\n2 140949\n3 33788\n15 7090\n13 29599\n1 183967\n6 20161\n7 157097\n10 173220\n9 167385\n15 123904\n12 30799\n5 47324\n", "15 1\n15 200000\n15 200000\n15 200000\n15 200000\n15 20000...
0
4
2
8
413_B. Spyke Chatting
The R2 company has n employees working for it. The work involves constant exchange of ideas, sharing the stories of success and upcoming challenging. For that, R2 uses a famous instant messaging program Spyke. R2 has m Spyke chats just to discuss all sorts of issues. In each chat, some group of employees exchanges mes...
{ "input": [ "4 3 4\n0 1 1\n1 0 1\n1 1 1\n0 0 0\n1 2\n2 1\n3 1\n1 3\n", "3 4 5\n1 1 1 1\n1 0 1 1\n1 1 0 0\n1 1\n3 1\n1 3\n2 4\n3 2\n" ], "output": [ "0 2 3 0 \n", "3 3 1 \n" ] }
{ "input": [ "3 3 1\n1 1 1\n1 1 1\n1 1 1\n3 1\n", "3 2 1\n0 1\n1 0\n1 1\n1 2\n", "2 1 1\n1\n1\n1 1\n", "3 3 4\n1 1 1\n0 0 0\n1 1 1\n1 1\n3 1\n3 2\n3 3\n", "10 1 10\n0\n0\n0\n0\n0\n0\n1\n0\n1\n0\n7 1\n9 1\n9 1\n7 1\n9 1\n9 1\n9 1\n7 1\n9 1\n9 1\n", "5 5 5\n0 1 1 1 0\n1 1 0 1 1\n1 1 1 1 1\n0 1 1...
1,300
1,000
2
10
43_D. Journey
The territory of Berland is represented by a rectangular field n × m in size. The king of Berland lives in the capital, located on the upper left square (1, 1). The lower right square has coordinates (n, m). One day the king decided to travel through the whole country and return back to the capital, having visited ever...
{ "input": [ "2 2\n", "3 3\n" ], "output": [ "0\n1 1\n1 2\n2 2\n2 1\n1 1\n", "1\n3 3 1 1\n1 1\n1 2\n1 3\n2 3\n2 2\n2 1\n3 1\n3 2\n3 3\n1 1\n" ] }
{ "input": [ "2 100\n", "4 38\n", "1 3\n", "1 2\n", "99 2\n", "99 2\n", "3 2\n", "2 100\n", "2 99\n", "3 1\n", "1 100\n", "6 3\n", "99 1\n", "1 100\n", "10 13\n", "100 2\n", "100 2\n", "2 3\n", "4 38\n", "11 17\n", "2 99\n", "3 4\...
2,000
2,000
2
7
462_A. Appleman and Easy Task
Toastman came up with a very easy task. He gives it to Appleman, but Appleman doesn't know how to solve it. Can you help him? Given a n × n checkerboard. Each cell of the board has either character 'x', or character 'o'. Is it true that each cell of the board has even number of adjacent cells with 'o'? Two cells of th...
{ "input": [ "3\nxxo\nxox\noxx\n", "4\nxxxo\nxoxo\noxox\nxxxx\n" ], "output": [ "YES\n", "NO\n" ] }
{ "input": [ "3\nooo\noxo\nxoo\n", "12\nxxooxxoxxxoo\nxxoooxoxoxoo\nooxoxoxxooxx\nooxxooooxoxo\nxxxxxxxxoxxx\noxooooxxxooo\noxxoxoxoooxx\nxxxxxxxooxox\noxoooooxoxxx\nxxooxxoxxoxx\noxxxxxxxooxx\nooxoxooxxooo\n", "1\no\n", "4\noooo\noxxo\nxoxo\noooo\n", "10\nxxxxxxxoox\nxooxxooooo\noxoooxxooo\nxoxxx...
1,000
500
2
11
509_E. Pretty Song
When Sasha was studying in the seventh grade, he started listening to music a lot. In order to evaluate which songs he likes more, he introduced the notion of the song's prettiness. The title of the song is a word consisting of uppercase Latin letters. The prettiness of the song is the prettiness of its title. Let's d...
{ "input": [ "BYOB\n", "YISVOWEL\n", "IEAIAIO\n" ], "output": [ "5.83333333\n", "17.05000000\n", "28.00000000\n" ] }
{ "input": [ "EZYYOIYUZXEVRTOUYXIQ\n", "KZTNJQLPZVHZKZWIB\n", "Z\n", "MTOESEPRFEIWAIWLAFJMGBIQB\n", "A\n", "POKKJNWMNCSXBJLDWVG\n", "ZUBQNDCHHKWNWRVSDSRRRTGZDDPNTVJFKTCNGWND\n" ], "output": [ "124.01681635\n", "5.82028152\n", "0.00000000\n", "127.22036847\n", "1.000...
2,000
0
2
7
534_A. Exam
An exam for n students will take place in a long and narrow room, so the students will sit in a line in some order. The teacher suspects that students with adjacent numbers (i and i + 1) always studied side by side and became friends and if they take an exam sitting next to each other, they will help each other for sur...
{ "input": [ "3\n", "6" ], "output": [ "2\n1 3\n", "6\n1 3 5 2 4 6\n" ] }
{ "input": [ "13\n", "16\n", "25\n", "729\n", "4993\n", "10\n", "4992\n", "5\n", "120\n", "4181\n", "1777\n", "2999\n", "4998\n", "29\n", "4997\n", "4999\n", "1597\n", "9\n", "7\n", "2\n", "4991\n", "1\n", "216\n", "5000\n...
1,100
500
2
7
559_A. Gerald's Hexagon
Gerald got a very curious hexagon for his birthday. The boy found out that all the angles of the hexagon are equal to <image>. Then he measured the length of its sides, and found that each of them is equal to an integer number of centimeters. There the properties of the hexagon ended and Gerald decided to draw on it. ...
{ "input": [ "1 1 1 1 1 1\n", "1 2 1 2 1 2\n" ], "output": [ "6\n", "13\n" ] }
{ "input": [ "718 466 729 470 714 481\n", "7 1 7 3 5 3\n", "4 60 4 60 4 60\n", "41 64 48 61 44 68\n", "30 36 36 32 34 38\n", "125 7 128 8 124 11\n", "1000 1000 1000 1000 1000 1000\n", "9 2 9 3 8 3\n", "888 888 888 887 889 887\n", "7 5 4 8 4 5\n", "131 425 143 461 95 473\n",...
1,600
500
2
10
584_D. Dima and Lisa
Dima loves representing an odd number as the sum of multiple primes, and Lisa loves it when there are at most three primes. Help them to represent the given number as the sum of at most than three primes. More formally, you are given an odd numer n. Find a set of numbers pi (1 ≤ i ≤ k), such that 1. 1 ≤ k ≤ 3 2. ...
{ "input": [ "27\n" ], "output": [ "3\n23 2 2\n" ] }
{ "input": [ "7147\n", "8909\n", "1357329\n", "7077\n", "199999581\n", "370359\n", "784533\n", "838347\n", "999991791\n", "501148647\n", "999995085\n", "826815517\n", "19\n", "499966179\n", "999995529\n", "1388581\n", "462409937\n", "1357323\n", ...
1,800
2,000
2
10
606_D. Lazy Student
Student Vladislav came to his programming exam completely unprepared as usual. He got a question about some strange algorithm on a graph — something that will definitely never be useful in real life. He asked a girl sitting next to him to lend him some cheat papers for this questions and found there the following defin...
{ "input": [ "4 5\n2 1\n3 1\n4 0\n1 1\n5 0\n", "3 3\n1 0\n2 1\n3 1\n" ], "output": [ "1 3\n1 4\n2 3\n1 2\n2 4\n", "-1\n" ] }
{ "input": [ "5 9\n1 1\n2 1\n3 0\n4 1\n5 0\n6 0\n7 0\n8 1\n9 0\n", "4 6\n1 1\n3 1\n2 0\n2 1\n3 0\n3 0\n", "4 6\n2 1\n4 0\n3 0\n1 1\n4 1\n5 0\n", "4 5\n7 0\n3 0\n1 1\n5 1\n7 1\n", "4 6\n2 1\n7 1\n3 0\n1 1\n7 0\n6 0\n", "10 15\n752087443 1\n537185872 1\n439895449 1\n494086747 1\n718088132 1\n934...
1,700
1,000
2
10
628_D. Magic Numbers
Consider the decimal presentation of an integer. Let's call a number d-magic if digit d appears in decimal presentation of the number on even positions and nowhere else. For example, the numbers 1727374, 17, 1 are 7-magic but 77, 7, 123, 34, 71 are not 7-magic. On the other hand the number 7 is 0-magic, 123 is 2-magic...
{ "input": [ "2 6\n10\n99\n", "2 0\n1\n9\n", "19 7\n1000\n9999\n" ], "output": [ "8\n", "4\n", "6\n" ] }
{ "input": [ "6 2\n22\n95\n", "2 2\n12\n14\n", "2 0\n1000\n9999\n", "2 2\n2934\n4323\n", "43 3\n587\n850\n", "3 9\n10\n99\n", "1 0\n10\n20\n", "2 6\n46\n46\n", "3 9\n10\n69\n", "2 4\n1\n9\n", "1 0\n1\n1\n", "3 9\n39\n39\n", "477 9\n3062053\n6465858\n", "2 5\n176...
2,200
0
2
9
678_C. Joty and Chocolate
Little Joty has got a task to do. She has a line of n tiles indexed from 1 to n. She has to paint them in a strange pattern. An unpainted tile should be painted Red if it's index is divisible by a and an unpainted tile should be painted Blue if it's index is divisible by b. So the tile with the number divisible by a a...
{ "input": [ "5 2 3 12 15\n", "20 2 3 3 5\n" ], "output": [ "39\n", "51\n" ] }
{ "input": [ "1000000000 9 15 10 10\n", "20 4 6 2 3\n", "1000000000 1 1 1000000000 999999999\n", "134312 3 6 33333 1\n", "100000 3 9 1 2\n", "100000 4 6 12 14\n", "100 12 6 1 10\n", "7 2 4 2 1\n", "20 2 4 10 20\n", "1000 4 6 7 3\n", "1000000000 1 2 1 1\n", "24 4 6 10 10...
1,600
0
2
10
791_D. Bear and Tree Jumps
A tree is an undirected connected graph without cycles. The distance between two vertices is the number of edges in a simple path between them. Limak is a little polar bear. He lives in a tree that consists of n vertices, numbered 1 through n. Limak recently learned how to jump. He can jump from a vertex to any verte...
{ "input": [ "13 3\n1 2\n3 2\n4 2\n5 2\n3 6\n10 6\n6 7\n6 13\n5 8\n5 9\n9 11\n11 12\n", "6 2\n1 2\n1 3\n2 4\n2 5\n4 6\n", "3 5\n2 1\n3 1\n" ], "output": [ "114\n", "20\n", "3\n" ] }
{ "input": [ "2 1\n1 2\n", "2 5\n2 1\n", "15 1\n12 9\n13 7\n1 3\n10 4\n9 2\n2 15\n11 4\n2 14\n10 8\n6 7\n12 5\n8 7\n3 10\n10 2\n", "12 3\n5 11\n10 11\n6 4\n8 9\n4 12\n10 7\n4 1\n3 1\n2 12\n9 4\n9 10\n", "4 2\n3 4\n2 4\n3 1\n" ], "output": [ "1\n", "1\n", "346\n", "88\n", "7...
2,100
1,000
2
7
812_A. Sagheer and Crossroads
Sagheer is walking in the street when he comes to an intersection of two roads. Each road can be represented as two parts where each part has 3 lanes getting into the intersection (one for each direction) and 3 lanes getting out of the intersection, so we have 4 parts in total. Each part has 4 lights, one for each lane...
{ "input": [ "1 0 0 1\n0 1 0 0\n0 0 1 0\n0 0 0 1\n", "1 0 0 0\n0 0 0 1\n0 0 0 0\n1 0 1 0\n", "0 1 1 0\n1 0 1 0\n1 1 0 0\n0 0 0 1\n" ], "output": [ "YES\n", "NO\n", "NO\n" ] }
{ "input": [ "0 0 0 0\n0 0 1 0\n0 0 0 1\n0 0 0 0\n", "0 1 0 0\n1 1 0 1\n1 0 0 1\n1 1 0 1\n", "0 0 0 1\n0 1 0 1\n0 0 0 0\n0 0 0 0\n", "0 1 0 0\n0 0 0 1\n0 1 0 0\n0 0 0 1\n", "0 1 0 0\n0 0 0 0\n0 0 0 1\n0 0 0 0\n", "0 0 0 0\n0 1 0 1\n1 0 1 1\n0 0 0 1\n", "0 0 0 0\n0 0 0 0\n1 0 0 1\n0 0 0 0\n...
1,200
500
2
10
858_D. Polycarp's phone book
There are n phone numbers in Polycarp's contacts on his phone. Each number is a 9-digit integer, starting with a digit different from 0. All the numbers are distinct. There is the latest version of Berdroid OS installed on Polycarp's phone. If some number is entered, is shows up all the numbers in the contacts for whi...
{ "input": [ "3\n123456789\n100000000\n100123456\n", "4\n123456789\n193456789\n134567819\n934567891\n" ], "output": [ "7\n000\n01\n", "2\n193\n13\n91\n" ] }
{ "input": [ "3\n638631659\n929648227\n848163730\n", "5\n567323818\n353474649\n468171032\n989223926\n685081078\n", "5\n774610315\n325796798\n989859836\n707706423\n310546337\n", "10\n181033039\n210698534\n971006898\n391227170\n323096464\n560766866\n377374442\n654389922\n544146403\n779261493\n", "10...
1,600
2,000
2
8
928_B. Chat
There are times you recall a good old friend and everything you've come through together. Luckily there are social networks — they store all your message history making it easy to know what you argued over 10 years ago. More formal, your message history is a sequence of messages ordered by time sent numbered from 1 to...
{ "input": [ "6 0\n0 1 1 2 3 2\n", "2 2\n0 1\n", "10 1\n0 1 0 3 4 5 2 3 7 0\n" ], "output": [ "1 2 2 3 3 3 \n", "2 2 \n", "2 3 3 4 5 6 6 6 8 2 \n" ] }
{ "input": [ "100 5\n0 1 1 1 0 5 6 6 8 8 9 11 12 11 8 0 0 14 6 16 7 21 15 23 15 24 0 0 0 28 0 29 26 27 19 0 0 21 37 32 40 30 37 34 39 38 34 38 0 0 41 24 45 47 0 33 46 26 31 0 21 57 57 31 63 63 25 59 65 56 68 0 30 55 55 0 70 43 59 49 59 79 66 74 0 11 65 0 80 63 0 84 73 49 73 81 0 86 76 98\n", "5 2\n0 1 2 3 1\n...
1,400
1,250
2
10
957_D. Riverside Curio
Arkady decides to observe a river for n consecutive days. The river's water level on each day is equal to some real value. Arkady goes to the riverside each day and makes a mark on the side of the channel at the height of the water level, but if it coincides with a mark made before, no new mark is created. The water d...
{ "input": [ "5\n0 1 1 2 2\n", "5\n0 1 2 1 2\n", "6\n0 1 0 3 0 2\n" ], "output": [ "0\n", "1\n", "6\n" ] }
{ "input": [ "3\n0 1 1\n", "4\n0 0 1 2\n", "2\n0 0\n", "4\n0 1 1 0\n", "3\n0 1 0\n", "2\n0 1\n", "8\n0 0 2 0 3 0 3 2\n", "3\n0 1 2\n", "10\n0 0 2 2 3 2 3 3 1 3\n", "6\n0 0 0 2 0 1\n", "10\n0 1 2 0 4 5 3 6 0 5\n", "4\n0 0 1 1\n", "3\n0 0 0\n", "9\n0 1 0 1 1 4 0 4...
1,700
1,250
2
10
982_D. Shark
For long time scientists study the behavior of sharks. Sharks, as many other species, alternate short movements in a certain location and long movements between locations. Max is a young biologist. For n days he watched a specific shark, and now he knows the distance the shark traveled in each of the days. All the dis...
{ "input": [ "8\n1 2 7 3 4 8 5 6\n", "6\n25 1 2 3 14 36\n" ], "output": [ "7\n", "2\n" ] }
{ "input": [ "2\n2 1\n", "127\n64 96 63 112 62 95 61 120 60 94 59 111 58 93 57 124 56 92 55 110 54 91 53 119 52 90 51 109 50 89 49 126 48 88 47 108 46 87 45 118 44 86 43 107 42 85 41 123 40 84 39 106 38 83 37 117 36 82 35 105 34 81 33 127 32 80 31 104 30 79 29 116 28 78 27 103 26 77 25 122 24 76 23 102 22 75 ...
1,900
2,000
2
7
1033_A. King Escape
Alice and Bob are playing chess on a huge chessboard with dimensions n × n. Alice has a single piece left — a queen, located at (a_x, a_y), while Bob has only the king standing at (b_x, b_y). Alice thinks that as her queen is dominating the chessboard, victory is hers. But Bob has made a devious plan to seize the vic...
{ "input": [ "8\n4 4\n2 3\n1 6\n", "8\n3 5\n1 2\n6 1\n", "8\n4 4\n1 3\n3 1\n" ], "output": [ "NO\n", "NO\n", "YES\n" ] }
{ "input": [ "4\n1 2\n4 3\n4 4\n", "1000\n114 372\n112 350\n113 352\n", "4\n2 3\n3 1\n4 2\n", "100\n12 47\n24 26\n3 4\n", "20\n11 10\n12 18\n18 11\n", "5\n3 3\n4 1\n5 2\n", "50\n2 3\n1 1\n50 50\n", "20\n5 10\n7 7\n8 8\n", "100\n2 6\n1 3\n3 4\n", "5\n1 2\n2 4\n2 5\n", "1000\...
1,000
500
2
12
1077_F2. Pictures with Kittens (hard version)
The only difference between easy and hard versions is the constraints. Vova likes pictures with kittens. The news feed in the social network he uses can be represented as an array of n consecutive pictures (with kittens, of course). Vova likes all these pictures, but some are more beautiful than the others: the i-th p...
{ "input": [ "4 3 1\n1 100 1 1\n", "5 2 3\n5 1 3 10 1\n", "6 1 5\n10 30 30 70 10 10\n" ], "output": [ "100\n", "18\n", "-1\n" ] }
{ "input": [ "1 1 1\n558472458\n", "15 5 2\n529585109 776474925 944162404 531331019 502148487 753160855 314701391 764106954 382377182 490189975 434952522 988199603 440453830 51256343 532602115\n", "1 1 1\n465559034\n", "1 1 1\n99996055\n", "14 5 2\n956036265 182694371 213500222 846949061 812445518...
2,100
0
2
10
1146_D. Frog Jumping
A frog is initially at position 0 on the number line. The frog has two positive integers a and b. From a position k, it can either jump to position k+a or k-b. Let f(x) be the number of distinct integers the frog can reach if it never jumps on an integer outside the interval [0, x]. The frog doesn't need to visit all ...
{ "input": [ "1000000000 1 2019\n", "7 5 3\n", "6 4 5\n", "100 100000 1\n" ], "output": [ "500000001500000001\n", "19\n", "10\n", "101\n" ] }
{ "input": [ "7526 35 7525\n", "936989 17028 92708\n", "26 92701 7\n", "42651129 26190 16875\n", "172165 93846 84\n", "95544 17793 8856\n", "983 97020 105\n", "236009692 89900 300\n", "14332 13672 1976\n", "16145755 64220 70642\n", "9331043 5355 81159\n", "57986 4760 56...
2,100
2,250
2
10
1167_D. Bicolored RBS
A string is called bracket sequence if it does not contain any characters other than "(" and ")". A bracket sequence is called regular (shortly, RBS) if it is possible to obtain correct arithmetic expression by inserting characters "+" and "1" into this sequence. For example, "", "(())" and "()()" are RBS and ")(" and ...
{ "input": [ "2\n()\n", "4\n(())\n", "10\n((()())())\n" ], "output": [ "00\n", "0110\n", "0100001110\n" ] }
{ "input": [ "10\n((()())())\n", "8\n((()))()\n", "20\n(()()()())(()())()()\n", "4\n(())\n", "20\n(()(((())(()))(())))\n", "20\n(())(()()())(())()()\n", "20\n(())(())(())()(())()\n", "20\n()((())((()))())(())\n", "2\n()\n", "12\n(()())((()))\n", "14\n((()(()()())))\n", ...
1,500
0
2
13
1185_G1. Playlist for Polycarp (easy version)
The only difference between easy and hard versions is constraints. Polycarp loves to listen to music, so he never leaves the player, even on the way home from the university. Polycarp overcomes the distance from the university to the house in exactly T minutes. In the player, Polycarp stores n songs, each of which is...
{ "input": [ "4 10\n5 3\n2 1\n3 2\n5 1\n", "3 3\n1 1\n1 1\n1 3\n", "3 3\n1 1\n1 2\n1 3\n" ], "output": [ "10", "2", "6" ] }
{ "input": [ "4 2\n1 3\n1 2\n1 3\n1 2\n", "15 49\n3 1\n14 3\n9 1\n8 1\n14 2\n5 1\n14 3\n10 3\n9 3\n9 1\n8 3\n2 1\n10 2\n4 3\n6 1\n", "3 1\n1 3\n1 3\n1 1\n", "15 12\n1 1\n1 1\n1 1\n1 1\n1 1\n1 2\n1 2\n1 2\n1 2\n1 2\n1 3\n1 3\n1 3\n1 3\n1 3\n", "15 10\n1 1\n1 2\n1 1\n1 2\n1 1\n1 2\n1 1\n1 2\n1 1\n1 ...
2,100
2,750
2
10
1204_D2. Kirk and a Binary String (hard version)
The only difference between easy and hard versions is the length of the string. You can hack this problem if you solve it. But you can hack the previous problem only if you solve both problems. Kirk has a binary string s (a string which consists of zeroes and ones) of length n and he is asking you to find a binary str...
{ "input": [ "110\n", "0001111\n", "010\n", "0111001100111011101000\n" ], "output": [ "010", "0000000", "010", "0011001100001011101000" ] }
{ "input": [ "1111111111111111\n", "1111111111111010\n", "0100000001000001\n", "0000100010001110\n", "1001101000001101\n", "1\n", "1111101000110110\n", "0010000110000100\n", "0\n", "0000000000000000\n" ], "output": [ "0000000000000000", "0000000000001010", "0100...
2,100
750
2
10
1266_D. Decreasing Debts
There are n people in this world, conveniently numbered 1 through n. They are using burles to buy goods and services. Occasionally, a person might not have enough currency to buy what he wants or needs, so he borrows money from someone else, with the idea that he will repay the loan later with interest. Let d(a,b) deno...
{ "input": [ "3 2\n1 2 10\n2 3 5\n", "3 3\n1 2 10\n2 3 15\n3 1 10\n", "3 4\n2 3 1\n2 3 2\n2 3 4\n2 3 8\n", "4 2\n1 2 12\n3 4 8\n" ], "output": [ "2\n1 2 5\n1 3 5\n", "1\n2 3 5\n", "1\n2 3 15\n", "2\n1 2 12\n3 4 8\n" ] }
{ "input": [ "50 0\n", "12 20\n1 3 1000000000\n3 2 1000000000\n1 4 1000000000\n4 2 1000000000\n1 5 1000000000\n5 2 1000000000\n1 6 1000000000\n6 2 1000000000\n1 7 1000000000\n7 2 1000000000\n1 8 1000000000\n8 2 1000000000\n1 9 1000000000\n9 2 1000000000\n1 10 1000000000\n10 2 1000000000\n1 11 1000000000\n11 2...
2,000
1,750
2
8
1371_B. Magical Calendar
A competitive eater, Alice is scheduling some practices for an eating contest on a magical calendar. The calendar is unusual because a week contains not necessarily 7 days! In detail, she can choose any integer k which satisfies 1 ≤ k ≤ r, and set k days as the number of days in a week. Alice is going to paint some n...
{ "input": [ "5\n3 4\n3 2\n3 1\n13 7\n1010000 9999999\n" ], "output": [ "4\n3\n1\n28\n510049495001\n" ] }
{ "input": [ "1\n632934461 955818012\n", "1\n1 1\n" ], "output": [ "200303015644213031\n", "1\n" ] }
1,200
1,000
2
9
1436_C. Binary Search
Andrey thinks he is truly a successful developer, but in reality he didn't know about the binary search algorithm until recently. After reading some literature Andrey understood that this algorithm allows to quickly find a certain number x in an array. For an array a indexed from zero, and an integer x the pseudocode o...
{ "input": [ "4 1 2\n", "123 42 24\n" ], "output": [ "6", "824071958" ] }
{ "input": [ "10 7 7\n", "1000 1 1\n", "74 16 54\n", "2 1 1\n", "1 1 0\n", "535 101 250\n", "61 29 15\n", "999 490 499\n", "1000 2 2\n", "9 4 4\n", "6 4 3\n", "7 3 3\n", "697 390 118\n", "69 67 68\n", "91 60 48\n", "63 15 45\n", "1000 501 50\n", ...
1,500
1,500
2
7
1461_A. String Generation
One fall day Joe got bored because he couldn't find himself something interesting to do. Marty suggested Joe to generate a string of length n to entertain him somehow. It didn't seem particularly difficult, but Joe's generated string had to follow these rules: * the string may only contain characters 'a', 'b', or 'c...
{ "input": [ "2\n3 2\n4 1\n" ], "output": [ "\naab\nacba\n" ] }
{ "input": [ "10\n11 1\n12 1\n13 1\n14 1\n15 1\n16 1\n17 1\n18 1\n19 1\n20 1\n", "10\n567 1\n234 2\n543 1\n888 1\n864 2\n123 3\n543 1\n333 1\n999 1\n674 123\n", "10\n101 1\n102 1\n103 1\n104 1\n105 1\n106 1\n107 1\n108 1\n109 1\n110 1\n", "10\n1 1\n2 1\n3 1\n4 1\n5 1\n6 1\n7 1\n8 1\n9 1\n10 1\n", ...
800
500
2
8
1486_B. Eastern Exhibition
You and your friends live in n houses. Each house is located on a 2D plane, in a point with integer coordinates. There might be different houses located in the same point. The mayor of the city is asking you for places for the building of the Eastern exhibition. You have to find the number of places (points with intege...
{ "input": [ "6\n3\n0 0\n2 0\n1 2\n4\n1 0\n0 2\n2 3\n3 1\n4\n0 0\n0 1\n1 0\n1 1\n2\n0 0\n1 1\n2\n0 0\n2 0\n2\n0 0\n0 0\n" ], "output": [ "\n1\n4\n4\n4\n3\n1\n" ] }
{ "input": [ "2\n2\n0 0\n1000000000 1000000000\n4\n0 1000000000\n0 0\n1000000000 1000000000\n1000000000 0\n" ], "output": [ "1000000002000000001\n1000000002000000001\n" ] }
1,500
1,000
2
10
27_D. Ring Road 2
It is well known that Berland has n cities, which form the Silver ring — cities i and i + 1 (1 ≤ i < n) are connected by a road, as well as the cities n and 1. The goverment have decided to build m new roads. The list of the roads to build was prepared. Each road will connect two cities. Each road should be a curve whi...
{ "input": [ "4 2\n1 3\n2 4\n", "6 3\n1 3\n3 5\n5 1\n" ], "output": [ "io\n", "iii\n" ] }
{ "input": [ "6 4\n6 3\n1 3\n6 4\n5 3\n", "10 7\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n", "6 6\n1 4\n4 6\n2 6\n2 4\n5 3\n6 3\n", "7 9\n4 7\n3 5\n7 2\n2 4\n4 6\n1 5\n1 3\n7 5\n2 5\n", "10 4\n6 9\n10 2\n4 8\n2 9\n", "5 1\n3 5\n", "100 50\n79 24\n65 69\n44 6\n49 53\n26 22\n24 76\n10 2\n19 44\n44...
2,200
2,000
2
9
302_C. Yaroslav and Sequence
Yaroslav has an array, consisting of (2·n - 1) integers. In a single operation Yaroslav can change the sign of exactly n elements in the array. In other words, in one operation Yaroslav can select exactly n array elements, and multiply each of them by -1. Yaroslav is now wondering: what maximum sum of array elements c...
{ "input": [ "2\n50 50 50\n", "2\n-1 -100 -1\n" ], "output": [ "150\n", "100\n" ] }
{ "input": [ "22\n697 556 -538 879 -623 73 -293 -401 -491 -7 -144 853 -319 395 785 248 -585 0 -420 -830 -720 75 411 -397 746 828 -83 -833 -847 709 181 967 314 -633 -322 415 -450 433 -459 438 508 -870 -949\n", "27\n-401 -840 -583 -612 -298 -384 798 366 -922 -443 -972 -271 127 -201 992 -748 -351 925 -177 -528 3...
1,800
500
2
10
329_D. The Evil Temple and the Moving Rocks
Important: All possible tests are in the pretest, so you shouldn't hack on this problem. So, if you passed pretests, you will also pass the system test. You are an adventurer currently journeying inside an evil temple. After defeating a couple of weak monsters, you arrived at a square room consisting of tiles forming ...
{ "input": [ "3 2\n", "5 5\n" ], "output": [ ">vv\n^<.\n^.<\n1 3\n", ">...v\nv.<..\n..^..\n>....\n..^.<\n1 1\n" ] }
{ "input": [ "100 100000\n", "5 5\n", "3 2\n" ], "output": [ ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.v\n^.<.<.<.<.<.<.<.<.<.<.<.<.<.<.<.<.<.<.<.<.<.<.<.<.<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>...
2,500
1,500
2
8
350_B. Resort
Valera's finally decided to go on holiday! He packed up and headed for a ski resort. Valera's fancied a ski trip but he soon realized that he could get lost in this new place. Somebody gave him a useful hint: the resort has n objects (we will consider the objects indexed in some way by integers from 1 to n), each obje...
{ "input": [ "5\n0 0 1 0 1\n0 1 2 2 4\n", "5\n0 0 0 0 1\n0 1 2 3 4\n", "4\n1 0 0 0\n2 3 4 2\n" ], "output": [ "2\n4 5\n", "5\n1 2 3 4 5\n", "1\n1\n" ] }
{ "input": [ "10\n0 0 0 0 0 0 0 0 0 1\n4 0 8 4 7 8 5 5 7 2\n", "50\n0 0 0 0 0 0 0 0 0 0 1 0 1 0 0 1 1 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 0 0 1 1 0 0 0 1 0\n28 4 33 22 4 35 36 31 42 25 50 33 25 36 18 23 23 28 43 3 18 31 1 2 15 22 40 43 29 32 28 35 18 27 48 40 14 36 27 50 40 5 48 14 36 24 32 33 26 ...
1,500
1,000
2
9
374_C. Inna and Dima
Inna and Dima bought a table of size n × m in the shop. Each cell of the table contains a single letter: "D", "I", "M", "A". Inna loves Dima, so she wants to go through his name as many times as possible as she moves through the table. For that, Inna acts as follows: 1. initially, Inna chooses some cell of the tabl...
{ "input": [ "5 5\nDIMAD\nDIMAI\nDIMAM\nDDMAA\nAAMID\n", "1 2\nDI\n", "2 2\nMA\nID\n" ], "output": [ "4", "Poor Dima!\n", "Poor Inna!\n" ] }
{ "input": [ "1 1\nD\n", "5 5\nAAAAA\nAAAAA\nAAAAA\nAAAAA\nAAAAA\n", "4 1\nD\nI\nM\nA\n", "5 5\nDIADD\nDMADD\nDDDID\nAMMMD\nMIDAD\n", "1 1\nM\n", "1 4\nDIMA\n", "2 2\nDI\nMA\n", "5 5\nDIMAD\nADDDI\nMDDDM\nIDDDA\nDAMID\n", "9 6\nDIMADD\nIDDDDD\nMDDDDD\nADDDDD\nDIMADD\nIDDDDD\nMDDDDD...
1,900
1,500
2
7
41_A. Translation
The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pronounced) reversely. For example, a Berlandish word code corresponds to a Birlandish word edoc....
{ "input": [ "code\nedoc\n", "abb\naba\n", "code\ncode\n" ], "output": [ "YES\n", "NO\n", "NO\n" ] }
{ "input": [ "kudl\nldku\n", "abcdef\nfecdba\n", "incenvizhqpcenhjhehvjvgbsnfixbatrrjstxjzhlmdmxijztphxbrldlqwdfimweepkggzcxsrwelodpnryntepioqpvk\ndhjbjjftlvnxibkklxquwmzhjfvnmwpapdrslioxisbyhhfymyiaqhlgecpxamqnocizwxniubrmpyubvpenoukhcobkdojlybxd\n", "dgxmzbqofstzcdgthbaewbwocowvhqpinehpjatnnbrijcolv...
800
500
2
13
513_G3. Inversions problem
You are given a permutation of n numbers p1, p2, ..., pn. We perform k operations of the following type: choose uniformly at random two indices l and r (l ≤ r) and reverse the order of the elements pl, pl + 1, ..., pr. Your task is to find the expected value of the number of inversions in the resulting permutation. In...
{ "input": [ "3 4\n1 3 2\n", "3 1\n1 2 3\n" ], "output": [ "1.458333333333\n", "0.833333333333\n" ] }
{ "input": [ "96 999999657\n75 37 8 51 69 71 19 41 1 36 2 54 21 53 88 26 96 46 64 83 15 63 68 93 86 72 9 91 80 55 87 67 65 39 78 74 28 11 17 61 73 85 94 3 59 45 60 24 66 90 48 79 43 81 89 58 70 49 5 56 12 42 92 40 20 29 52 47 95 7 84 22 13 44 50 77 30 57 4 6 34 62 76 38 10 14 27 31 32 82 35 16 33 25 23 18\n", ...
3,100
16
2
7
540_A. Combination Lock
Scrooge McDuck keeps his most treasured savings in a home safe with a combination lock. Each time he wants to put there the treasures that he's earned fair and square, he has to open the lock. <image> The combination lock is represented by n rotating disks with digits from 0 to 9 written on them. Scrooge McDuck has t...
{ "input": [ "5\n82195\n64723\n" ], "output": [ "13\n" ] }
{ "input": [ "1\n9\n2\n", "1\n7\n9\n", "125\n23269567683904664184142384849516523616863461607751021071772615078579713054027902974007001544768640273491193035874486891541257\n47635110303703399505805044019026243695451609639556649012447370081552870340011971572363458960190590266459684717415349529509024\n", ...
800
500
2
8
568_B. Symmetric and Transitive
Little Johnny has recently learned about set theory. Now he is studying binary relations. You've probably heard the term "equivalence relation". These relations are very important in many areas of mathematics. For example, the equality of the two numbers is an equivalence relation. A set ρ of pairs (a, b) of elements ...
{ "input": [ "2\n", "3\n", "1\n" ], "output": [ "3\n", "10\n", "1\n" ] }
{ "input": [ "76\n", "3000\n", "3789\n", "5\n", "2999\n", "1234\n", "3999\n", "777\n", "555\n", "1730\n", "2500\n", "999\n", "3555\n", "666\n", "133\n", "2780\n", "2000\n", "345\n", "4000\n", "3333\n", "9\n", "7\n", "4\n", ...
1,900
1,000
2
8
611_B. New Year and Old Property
The year 2015 is almost over. Limak is a little polar bear. He has recently learnt about the binary system. He noticed that the passing year has exactly one zero in its representation in the binary system — 201510 = 111110111112. Note that he doesn't care about the number of zeros in the decimal representation. Limak...
{ "input": [ "72057594000000000 72057595000000000\n", "100 105\n", "5 10\n", "2015 2015\n" ], "output": [ "26\n", "0\n", "2\n", "1\n" ] }
{ "input": [ "10000000000 70000000000000000\n", "511 1023\n", "1124800395214848 36011204832919551\n", "2 7\n", "4 4\n", "1 1023\n", "1099444518911 1099444518912\n", "999999999999999999 1000000000000000000\n", "500000000000000000 1000000000000000000\n", "1 1000000000000000000\n"...
1,300
750
2
24
630_Q. Pyramids
IT City administration has no rest because of the fame of the Pyramids in Egypt. There is a project of construction of pyramid complex near the city in the place called Emerald Walley. The distinction of the complex is that its pyramids will be not only quadrangular as in Egypt but also triangular and pentagonal. Of co...
{ "input": [ "2 5 3\n" ], "output": [ "38.546168065708805\n" ] }
{ "input": [ "1 999 1000\n", "1 2 998\n", "709 328 709\n", "3 4 5\n", "1000 1000 1000\n", "982 948 879\n", "99 23 530\n", "999 997 998\n", "1 1 1\n" ], "output": [ "536498692.9990839\n", "299697433.026885\n", "157775455.6830121\n", "55.95477923013054\n", "65...
1,700
0
2
8
65_B. Harry Potter and the History of Magic
The History of Magic is perhaps the most boring subject in the Hogwarts school of Witchcraft and Wizardry. Harry Potter is usually asleep during history lessons, and his magical quill writes the lectures for him. Professor Binns, the history of magic teacher, lectures in such a boring and monotonous voice, that he has ...
{ "input": [ "3\n1999\n5055\n2000\n", "4\n9999\n2000\n3000\n3011\n", "3\n1875\n1936\n1721\n" ], "output": [ "No solution", "1999\n2000\n2000\n2011\n", "1075\n1136\n1221\n" ] }
{ "input": [ "5\n1901\n1166\n1308\n1037\n1808\n", "3\n1095\n1094\n1095\n", "10\n1075\n1133\n1393\n1350\n1369\n1403\n2643\n1653\n1756\n7811\n", "10\n1501\n1617\n1368\n1737\n1800\n1272\n1019\n1545\n1035\n1302\n", "5\n1612\n7835\n8183\n3368\n1685\n", "10\n1110\n1278\n1283\n7758\n1183\n1214\n2970\...
1,700
1,000
2
8
729_B. Spotlights
Theater stage is a rectangular field of size n × m. The director gave you the stage's plan which actors will follow. For each cell it is stated in the plan if there would be an actor in this cell or not. You are to place a spotlight on the stage in some good position. The spotlight will project light in one of the fou...
{ "input": [ "2 4\n0 1 0 0\n1 0 1 0\n", "4 4\n0 0 0 0\n1 0 0 1\n0 1 1 0\n0 1 0 0\n" ], "output": [ "9", "20" ] }
{ "input": [ "1 1\n1\n", "1 2\n0 1\n", "1 2\n1 0\n", "4 4\n1 1 1 1\n1 0 0 1\n1 0 0 1\n1 1 1 1\n", "2 1\n1\n1\n", "1 2\n1 1\n", "10 20\n0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
1,200
1,000
2
9
749_C. Voting
There are n employees in Alternative Cake Manufacturing (ACM). They are now voting on some very important question and the leading world media are trying to predict the outcome of the vote. Each of the employees belongs to one of two fractions: depublicans or remocrats, and these two fractions have opposite opinions o...
{ "input": [ "5\nDDRRR\n", "6\nDDRRRR\n" ], "output": [ "D\n", "R\n" ] }
{ "input": [ "1\nR\n", "7\nDDRRRRD\n", "6\nRDDRDR\n", "21\nDDDDRRRRRDRDRDRDRDRDR\n", "7\nRRRDDDD\n", "7\nDDRRRDR\n", "100\nRRDRRDDDDDDDRDRRRDRDRDDDRDDDRDDRDRRDRRRDRRDRRRRRRRDRRRRRRDDDRRDDRRRDRRRDDRRDRRDDDDDRRDRDDRDDRRRDRRDD\n", "8\nRDDRDRRD\n", "6\nDRRDRD\n", "3\nDRD\n", "1...
1,500
1,500
2
8
772_B. Volatile Kite
You are given a convex polygon P with n distinct vertices p1, p2, ..., pn. Vertex pi has coordinates (xi, yi) in the 2D plane. These vertices are listed in clockwise order. You can choose a real number D and move each vertex of the polygon a distance of at most D from their original positions. Find the maximum value ...
{ "input": [ "4\n0 0\n0 1\n1 1\n1 0\n", "6\n5 0\n10 0\n12 -4\n10 -8\n5 -8\n3 -4\n" ], "output": [ "0.353553391", "1.000000000" ] }
{ "input": [ "5\n0 0\n0 10\n10 10\n20 0\n10 -1\n", "4\n-1000000000 -1000000000\n-1000000000 1000000000\n1000000000 1000000000\n1000000000 -1000000000\n", "19\n449447997 711296339\n530233434 692216537\n535464528 613140435\n535533467 100893188\n530498867 -265063956\n519107979 -271820709\n482156929 -28779233...
1,800
1,000