info
stringlengths
120
50k
question
stringlengths
504
10.4k
avg@8_qwen3_4b_instruct_2507
float64
0
0.88
{"tests": "{\"inputs\": [\"3 3\\n#..\\n..#\\n...\", \"3 3\\n..\\n..#\\n...\", \"4 3\\n#..\\n..#\\n...\", \"3 5\\n..\\n..#\\n...\", \"4 3\\n#..\\n.#.\\n...\", \"4 3\\n#..\\n.#.\\n../\", \"3 1\\n#..\\n..#\\n...\", \"3 1\\n..#\\n..#\\n...\", \"3 1\\n..$\\n..#\\n...\", \"6 13\\n..\\n..#\\n...\", \"6 13\\n..\\n..#\\n../\", ...
You are given a grid of N rows and M columns. The square at the i-th row and j-th column will be denoted as (i,j). Some of the squares contain an object. All the remaining squares are empty. The state of the grid is represented by strings S_1,S_2,\cdots,S_N. The square (i,j) contains an object if S_{i,j}= `#` and is em...
0
{"tests": "{\"inputs\": [\"2 1 3 0\\nAB\\nAC\", \"1 0 9 0\\nAC\", \"8 6 9 1\\nAC\\nBC\\nAB\\nBC\\nAC\\nBC\\nAB\\nAB\", \"3 1 0 0\\nAB\\nBC\\nAB\", \"2 1 3 1\\nAB\\nAC\", \"8 6 9 1\\nBC\\nBC\\nAB\\nBC\\nAC\\nBC\\nAB\\nAB\", \"3 1 0 -1\\nAB\\nBC\\nAB\", \"8 6 16 1\\nAC\\nBC\\nAB\\nBC\\nAC\\nBC\\nAB\\nAB\", \"2 0 3 2\\nAB...
There is a game that involves three variables, denoted A, B, and C. As the game progresses, there will be N events where you are asked to make a choice. Each of these choices is represented by a string s_i. If s_i is `AB`, you must add 1 to A or B then subtract 1 from the other; if s_i is `AC`, you must add 1 to A or ...
0
{"tests": "{\"inputs\": [\"5 3\\n10 14 19 34 33\", \"9 14\\n1 3 5 110 24 21 34 5 3\", \"9 73\\n67597 52981 5828 66249 75177 64141 40773 79105 16076\", \"5 3\\n10 4 19 34 33\", \"9 14\\n1 3 5 110 24 21 34 2 3\", \"9 73\\n67597 52981 5828 18 75177 64141 40773 79105 16076\", \"5 1\\n10 4 19 34 33\", \"9 14\\n1 3 5 111 24 ...
Takahashi has come to a party as a special guest. There are N ordinary guests at the party. The i-th ordinary guest has a power of A_i. Takahashi has decided to perform M handshakes to increase the happiness of the party (let the current happiness be 0). A handshake will be performed as follows: * Takahashi chooses o...
0
{"tests": "{\"inputs\": [\"10\\n1 1\\n2 2\\n5 1000000000000000000\\n7 3\\n1 334334334334334334\\n23847657 23458792534\\n111111111 111111111\\n7 7\\n4 19\\n9 10\", \"3\\n4 4\\n6 10\\n12 11\", \"10\\n1 1\\n2 2\\n5 1000000000000000000\\n7 3\\n1 334334334334334334\\n23847657 23458792534\\n111111111 011111111\\n7 7\\n4 19\\...
Kenus, the organizer of International Euclidean Olympiad, is seeking a pair of two integers that requires many steps to find its greatest common divisor using the Euclidean algorithm. You are given Q queries. The i-th query is represented as a pair of two integers X_i and Y_i, and asks you the following: among all pai...
0
{"tests": "{\"inputs\": [\"-2 0 2 0\\n2\\n-1 0 2\\n1 0 2\", \"4 -2 -2 4\\n3\\n0 0 2\\n4 0 1\\n0 4 1\", \"-2 -2 2 2\\n1\\n0 0 1\", \"-2 0 2 0\\n2\\n-1 0 0\\n1 0 2\", \"4 -2 -2 4\\n3\\n0 0 2\\n4 -1 1\\n0 4 1\", \"-2 -2 2 4\\n1\\n0 0 1\", \"-2 1 2 0\\n2\\n-1 0 0\\n1 0 2\", \"-2 -2 2 4\\n0\\n0 0 1\", \"-2 1 2 0\\n1\\n-1 0 ...
On the xy-plane, Snuke is going to travel from the point (x_s, y_s) to the point (x_t, y_t). He can move in arbitrary directions with speed 1. Here, we will consider him as a point without size. There are N circular barriers deployed on the plane. The center and the radius of the i-th barrier are (x_i, y_i) and r_i, r...
0
{"tests": "{\"inputs\": [\"5 5\\n.X.S.\\n.X#..\\n.XX##\\n.#XG.\\n..X..\\n7 3\\nSXX.XXG\\nX.#.#X.\\nXXX.XX#\\n4 4\\nS...\\nX.X.\\nGX..\\n...X\\n10 10\\n..XXXXX.XX\\n.X.#.#X.XX\\nSX.#X.X..X\\n#X.##.X.XX\\n..XXXX#.XX\\n##.##.##XX\\n....X.XX#X\\n.##X..#X#X\\n....XX#..X\\n...#XXG..X\\n0 0\", \"5 5\\n.X.S.\\n.X#..\\n.XX##\\n...
There is a rectangular maze with square squares lined up vertically and horizontally. In this maze, while moving to the adjacent squares in the north, south, east and west, the starting square S departs and the goal square G is aimed at. There are three types of trout: plain, mountain, and ice. S and G are located in t...
0.375
{"tests": "{\"inputs\": [\"300 10 8 5\\n50 5 2 1\\n70 5 2 0\\n75 1 1 0\\n100 3 1 0\\n150 3 2 0\\n240 5 5 7\\n50 1 1 0\\n60 2 2 0\\n70 2 3 0\\n90 1 3 0\\n120 3 5 0\\n140 4 1 0\\n150 2 4 1\\n180 3 5 4\\n15 2 2 1\\n20 2 2 1\\n25 2 2 0\\n60 1 1 0\\n120 5 5 4\\n15 5 4 1\\n20 5 4 0\\n40 1 1 0\\n40 2 2 0\\n120 2 3 4\\n30 1 1 ...
ICPC Ranking Your mission in this problem is to write a program which, given the submission log of an ICPC (International Collegiate Programming Contest), determines team rankings. The log is a sequence of records of program submission in the order of submission. A record has four fields: elapsed time, team number, p...
0.125
{"tests": "{\"inputs\": [\"3\\nFUKUOKA\\nOKAYAMA\\nYAMAGUCHI\\n3\\nFUKUOKA\\nFUKUYAMA\\nOKAYAMA\\n2\\nABCDE\\nEDCBA\\n4\\nGA\\nDEFG\\nCDDE\\nABCD\\n2\\nABCDE\\nC\\n14\\nAAAAA\\nBBBBB\\nCCCCC\\nDDDDD\\nEEEEE\\nFFFFF\\nGGGGG\\nHHHHH\\nIIIII\\nJJJJJ\\nKKKKK\\nLLLLL\\nMMMMM\\nNNNNN\\n0\", \"3\", \"3\\nFUKUOKA\\nOKAYAMA\\nY...
Recent improvements in information and communication technology have made it possible to provide municipal service to a wider area more quickly and with less costs. Stimulated by this, and probably for saving their not sufficient funds, mayors of many cities started to discuss on mergers of their cities. There are, of...
0
{"tests": "{\"inputs\": [\"1 1\\n3 1\", \"2 1\\n-1 -3\\n3 10\", \"2 3\\n3 3\\n1 2\", \"0 1\\n3 1\", \"2 2\\n-1 -3\\n3 10\", \"2 3\\n4 3\\n1 2\", \"2 3\\n4 2\\n1 2\", \"2 3\\n1 2\\n1 2\", \"2 3\\n1 2\\n2 3\", \"1 3\\n1 2\\n2 3\", \"1 31\\n0 8\\n1 6\", \"1 1\\n3 2\", \"2 1\\n-1 0\\n3 10\", \"1 0\\n-1 1\\n3 8\", \"1 31\\n...
Problem statement Real variables $ x_1, x_2, ..., x_N $ satisfy the following conditions. 1. $ 0 \ leq x_i \ leq 1 $ ($ 1 \ leq i \ leq N $) 2. $ w_1x_1 + w_2x_2 + ... + w_Nx_N \ leq W $ At this time, find the maximum value that $ v_1x_1 + v_2x_2 + ... + v_Nx_N $ can take. It is known that such a maximum actually ...
0
{"tests": "{\"inputs\": [\"6\\nAIZU 10\\nLINER 6\\nLINE 4\\nALL 2\\nAS 1\\nCIEL 10\\nASLA\\nCILI\\nIRZN\\nELEU\\n21\", \"6\\nAIZU 10\\nLINER 6\\nLINE 4\\nALL 2\\nAS 1\\nCIEL 10\\nASLA\\nCILI\\nIRZN\\nUELE\\n21\", \"6\\nAIZU 10\\nLINER 6\\nLHNE 4\\nALL 2\\nAS 1\\nCIEL 10\\nASLA\\nCILI\\nIRZN\\nUELE\\n21\", \"6\\nAIZU 10...
Problem Statement Mr. Takatsuki, who is planning to participate in the Aizu training camp, is enthusiastic about studying and has been studying English recently. She tries to learn as many English words as possible by playing the following games on her mobile phone. The mobile phone she has is a touch panel type that ...
0
{"tests": "{\"inputs\": [\"6 7\\n0 1 3 1\\n0 2 4 -2\\n1 0 5\\n1 0 1\\n0 3 5 3\\n1 3 4\\n1 0 5\", \"6 7\\n0 1 3 1\\n0 2 4 -2\\n1 0 5\\n1 0 1\\n0 1 5 3\\n1 3 4\\n1 0 5\", \"6 7\\n0 0 3 1\\n0 2 4 -2\\n1 0 5\\n1 0 1\\n0 3 5 3\\n1 3 4\\n1 0 5\", \"6 7\\n0 1 3 1\\n0 2 4 0\\n1 0 5\\n1 0 1\\n0 3 5 3\\n1 3 4\\n1 0 5\", \"6 7\\n...
Write a program which manipulates a sequence $A$ = {$a_0, a_1, ..., a_{n-1}$} with the following operations: * $add(s, t, x)$ : add $x$ to $a_s, a_{s+1}, ..., a_t$. * $find(s, t)$ : report the minimum value in $a_s, a_{s+1}, ..., a_t$. Note that the initial values of $a_i ( i = 0, 1, ..., n-1 )$ are 0. Constraints...
0
{"tests": "{\"inputs\": [\"2\\n1\\n1 2\\n3\\n1 3\\n1 1\\n1 0\", \"2\\n1\\n1 2\\n3\\n1 3\\n1 1\\n2 0\", \"2\\n1\\n1 4\\n3\\n1 3\\n1 1\\n2 0\", \"2\\n1\\n1 4\\n1\\n1 3\\n1 1\\n3 0\", \"2\\n1\\n1 2\\n3\\n1 6\\n1 1\\n2 0\", \"2\\n1\\n1 4\\n3\\n1 3\\n1 1\\n2 1\", \"2\\n1\\n1 4\\n3\\n1 3\\n1 2\\n3 0\", \"2\\n1\\n1 4\\n1\\n1 ...
In this problem, you will be given a polynomial, you have to print what it becomes after differentiation. Following are the rules for differentiation: For a polynomial f(x), its differentiation is defined as f'(x). If a is a constant, then differentiation of af(x) is af'(x). If f(x) = h(x) + g(x) , then f'(x) = h'(x...
0
{"tests": "{\"inputs\": [\"8\\n4 4\\n2 3\\n1 6\\n\", \"8\\n3 5\\n1 2\\n6 1\\n\", \"8\\n4 4\\n1 3\\n3 1\\n\", \"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 ...
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...
0.375
{"tests": "{\"inputs\": [\"1000000000 1 2019\\n\", \"7 5 3\\n\", \"6 4 5\\n\", \"100 100000 1\\n\", \"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\", ...
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 ...
0
{"tests": "{\"inputs\": [\"110\\n\", \"0001111\\n\", \"010\\n\", \"0111001100111011101000\\n\", \"1111111111111111\\n\", \"1111111111111010\\n\", \"0100000001000001\\n\", \"0000100010001110\\n\", \"1001101000001101\\n\", \"1\\n\", \"1111101000110110\\n\", \"0010000110000100\\n\", \"0\\n\", \"0000000000000000\\n\", \"11...
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...
0
{"tests": "{\"inputs\": [\"5\\n3 4\\n3 2\\n3 1\\n13 7\\n1010000 9999999\\n\", \"1\\n632934461 955818012\\n\", \"1\\n1 1\\n\", \"1\\n632934461 286939621\\n\", \"1\\n1 2\\n\", \"5\\n3 4\\n3 2\\n3 1\\n13 7\\n1010000 14106652\\n\", \"1\\n632934461 107730378\\n\", \"1\\n2 2\\n\", \"1\\n3 2\\n\", \"5\\n3 4\\n3 2\\n5 1\\n13 9...
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...
0
{"tests": "{\"inputs\": [\"5 8\\n5 1 2 4 3\\n0 1\\n0 2\\n0 3\\n0 4\\n0 5\\n1 1000000000\\n1 1\\n1 500000000\\n\", \"5 6\\n1 2 6 8 10\\n1 4\\n1 9\\n0 6\\n0 10\\n1 100\\n1 50\\n\", \"5 6\\n1 2 6 8 10\\n1 4\\n1 9\\n0 6\\n0 10\\n1 100\\n1 5\\n\", \"5 6\\n1 2 6 5 10\\n1 4\\n1 9\\n0 6\\n0 10\\n1 100\\n1 50\\n\", \"5 4\\n5 1 ...
Vova decided to clean his room. The room can be represented as the coordinate axis OX. There are n piles of trash in the room, coordinate of the i-th pile is the integer p_i. All piles have different coordinates. Let's define a total cleanup as the following process. The goal of this process is to collect all the pile...
0
{"tests": "{\"inputs\": [\"4 1 2\\n\", \"123 42 24\\n\", \"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\",...
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...
0
{"tests": "{\"inputs\": [\"4 2\\n1 3\\n2 4\\n\", \"6 3\\n1 3\\n3 5\\n5 1\\n\", \"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\"...
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...
0.625
{"tests": "{\"inputs\": [\"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\", \"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...
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...
0
{"tests": "{\"inputs\": [\"5 5\\nDIMAD\\nDIMAI\\nDIMAM\\nDDMAA\\nAAMID\\n\", \"1 2\\nDI\\n\", \"2 2\\nMA\\nID\\n\", \"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\",...
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...
0
{"tests": "{\"inputs\": [\"2 5 3\\n\", \"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\", \"2 999 1000\\n\", \"1 2 234\\n\", \"1204 328 709\\n\", \"3 4 2\\n\", \"1000 1000 0000\\n\", \"1587 948 879\\n\", \"9...
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...
0.25
{"tests": "{\"inputs\": [\"5\\nDDRRR\\n\", \"6\\nDDRRRR\\n\", \"1\\nR\\n\", \"7\\nDDRRRRD\\n\", \"6\\nRDDRDR\\n\", \"21\\nDDDDRRRRRDRDRDRDRDRDR\\n\", \"7\\nRRRDDDD\\n\", \"7\\nDDRRRDR\\n\", \"100\\nRRDRRDDDDDDDRDRRRDRDRDDDRDDDRDDRDRRDRRRDRRDRRRRRRRDRRRRRRDDDRRDDRRRDRRRDDRRDRRDDDDDRRDRDDRDDRRRDRRDD\\n\", \"8\\nRDDRDRRD\...
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...
0
{"tests": "{\"inputs\": [\"2\\nabcde\\nabc\\n\\nSAMPLE\", \"2\\nabcde\\nabc\\n\\nSAMPEL\", \"2\\nabcdf\\nacc\\n\\nASMPEL\", \"2\\nfdcca\\n`dc\\n\\nASLPLD\", \"2\\nfdcca\\n`dd\\n\\nASLQLD\", \"2\\ncafcc\\ngaf\\n\\nUKJ@BQ\", \"2\\nea_ea\\ngee\\n\\n@UEKJU\", \"2\\nabcde\\nabc\\n\\nASMPEL\", \"2\\nabcdf\\nabc\\n\\nASMPEL\"...
As we all know that power sets of any set are formed by taking i elements (where i is from 1 to n) and then random shuffling them like this power set of {1,2,3} are {EMPTY SET},{1},{2},{3},{1,2}{1,3}{2,3}{1,2,3} . Now we have a MODIfied POWER SET which contains only those subsets which have consecutive elements from s...
0
{"tests": "{\"inputs\": [\"4 5 5 3\", \"3 4 4 2\", \"7 9 20 20\", \"8 5 5 3\", \"3 5 4 2\", \"7 9 20 32\", \"15 5 5 3\", \"3 9 4 2\", \"15 5 5 5\", \"3 9 4 3\", \"15 5 8 5\", \"5 9 4 3\", \"15 5 8 3\", \"5 9 7 3\", \"15 6 8 3\", \"10 9 7 3\", \"15 11 8 3\", \"10 6 7 3\", \"15 3 8 3\", \"13 6 7 3\", \"12 3 12 6\", \"13 ...
Takahashi has an N \times M grid, with N horizontal rows and M vertical columns. Determine if we can place A 1 \times 2 tiles (1 vertical, 2 horizontal) and B 2 \times 1 tiles (2 vertical, 1 horizontal) satisfying the following conditions, and construct one arrangement of the tiles if it is possible: * All the tiles m...
0
{"tests": "{\"inputs\": [\"3 4 3\\n1 0 1 1\\n0 1 0 0\\n1 0 1 0\\n0 0 0\", \"3 4 3\\n1 0 1 1\\n0 1 0 0\\n1 0 1 1\\n0 0 0\", \"3 4 6\\n1 0 1 1\\n0 1 0 0\\n1 0 1 1\\n0 0 0\", \"3 4 8\\n1 0 1 1\\n0 1 0 0\\n1 0 1 1\\n0 0 0\", \"3 4 8\\n1 0 1 1\\n0 0 0 0\\n1 0 1 1\\n0 0 0\", \"3 4 4\\n1 0 1 1\\n0 1 0 0\\n1 0 1 1\\n0 0 0\", \...
problem One day, Taro, who lives in JOI town, decided to take a walk as a daily routine to improve his health. In JOI town, where Taro lives, he runs in the east-west direction as shown in the figure (H + 1). The road and the north-south direction (W + 1) run through the road in a grid pattern. Taro's house is at the ...
0
{"tests": "{\"inputs\": [\"1-(2+3-4+5)\", \"0-(2+3-4+5)\", \"0-(2+3-3+5)\", \"2-(2+3-4+5)\", \"1-(3+2-4+5)\", \"2-(2-3+4+5)\", \"0-(3+4-4+5)\", \"3+(2-4-4+5)\", \"2-(2+2-4+5)\", \"2+(2-4-4+5)\", \"2-(2+2-5+5)\", \"2-(2-3+4+6)\", \"3+(2-4-4+6)\", \"4-(2+5-0+2)\", \"2-(2-3+4+7)\", \"0-(4+5-1+6)\", \"0-(4+5-1+5)\", \"0-(2...
Tunnel formula One day while exploring an abandoned mine, you found a long formula S written in the mine. If you like large numbers, you decide to take out the choke and add `(` or `)` so that the result of the formula calculation is as large as possible. If it has to be a mathematical formula even after adding it, ho...
0
{"tests": "{\"inputs\": [\"3 9\\n\", \"4 4\\n\", \"506 2708\\n\", \"3 6\\n\", \"9 3\\n\", \"97821761637600 97821761637600\\n\", \"99999999999962 99999999999973\\n\", \"1 1\\n\", \"11 49\\n\", \"2 2\\n\", \"1 6\\n\", \"99999999999973 99999999999971\\n\", \"11003163441270 11003163441270\\n\", \"87897897895 29835496161\\n...
There is an infinite board of square tiles. Initially all tiles are white. Vova has a red marker and a blue marker. Red marker can color a tiles. Blue marker can color b tiles. If some tile isn't white then you can't use marker of any color on it. Each marker must be drained completely, so at the end there should be e...
0
{"tests": "{\"inputs\": [\"5\\naaaaa\\n\", \"10\\ncodeforces\\n\", \"4\\ncbba\\n\", \"6\\naabbcc\\n\", \"6\\naabbab\\n\", \"2\\nss\\n\", \"2\\nab\\n\", \"3\\nbaa\\n\", \"3\\nabb\\n\", \"4\\naaba\\n\", \"1\\ng\\n\", \"6\\nsssssa\\n\", \"2\\naa\\n\", \"5\\naabaa\\n\", \"4\\naabb\\n\", \"3\\naba\\n\", \"9\\naabbccaab\\n\"...
You are given a string s, consisting of n lowercase Latin letters. A substring of string s is a continuous segment of letters from s. For example, "defor" is a substring of "codeforces" and "fors" is not. The length of the substring is the number of letters in it. Let's call some string of length n diverse if and o...
0.375
{"tests": "{\"inputs\": [\"5 4 3\\n3 4\\n3 1\\n3 3\\n5 3\\n1 3\\n1 4\\n\", \"3 3 2\\n1 2\\n2 1\\n3 3\\n3 2\\n\", \"3 3 2\\n1 2\\n2 1\\n3 3\\n3 2\\n\", \"2 2 1\\n1 1\\n1 1\\n\", \"2 2 2\\n2 1\\n2 1\\n1 2\\n1 1\\n\", \"10 10 20\\n7 5\\n4 5\\n5 4\\n7 4\\n1 5\\n6 7\\n9 5\\n8 4\\n1 4\\n2 10\\n3 10\\n4 10\\n3 6\\n5 7\\n6 2\\...
Petya has a rectangular Board of size n × m. Initially, k chips are placed on the board, i-th chip is located in the cell at the intersection of sx_i-th row and sy_i-th column. In one action, Petya can move all the chips to the left, right, down or up by 1 cell. If the chip was in the (x, y) cell, then after the oper...
0
{"tests": "{\"inputs\": [\"5\\n6 7 4\\n10 7 12\\n12 30 7\\n1 1 1\\n3247834 10298779 625324\\n\", \"5\\n6 7 4\\n10 7 12\\n12 30 6\\n1 1 1\\n3247834 10298779 625324\\n\", \"5\\n6 7 4\\n10 7 12\\n12 30 7\\n1 1 1\\n3247834 18794097 625324\\n\", \"5\\n6 7 1\\n10 7 12\\n12 30 6\\n1 1 1\\n3247834 10298779 625324\\n\", \"5\\n6...
Berland year consists of m months with d days each. Months are numbered from 1 to m. Berland week consists of w days. The first day of the year is also the first day of the week. Note that the last week of the year might be shorter than w days. A pair (x, y) such that x < y is ambiguous if day x of month y is the same...
0
{"tests": "{\"inputs\": [\"4\\n1 2 3 4\\n4 1 3 2\\n4 3 1 2\\n3 4 2 1\\n3 1 2 4\\n\", \"10\\n5 1 6 2 8 3 4 10 9 7\\n3 1 10 6 8 5 2 7 9 4\\n2 9 1 4 10 6 8 7 3 5\\n10 1 7 8 3 2 4 6 5 9\\n3 2 10 4 7 8 5 6 1 9\\n5 6 3 10 8 7 2 9 4 1\\n6 5 1 3 2 7 9 10 8 4\\n1 10 9 3 7 8 4 2 6 5\\n6 8 4 5 9 1 2 10 7 3\\n9 6 8 5 10 3 1 7 2 4\...
As meticulous Gerald sets the table, Alexander finished another post on Codeforces and begins to respond to New Year greetings from friends. Alexander has n friends, and each of them sends to Alexander exactly one e-card. Let us number his friends by numbers from 1 to n in the order in which they send the cards. Let's ...
0
{"tests": "{\"inputs\": [\"2 3\\n2 3 6\\n3 4 3\\n\", \"2 5\\n3 7 11\\n10 12 15\\n\", \"5 42\\n42 42 42\\n42 43 42\\n43 44 42\\n44 45 42\\n45 45 1\\n\", \"1 10\\n100 111 1\\n\", \"4 10\\n1 3 1\\n3 3 10\\n5 6 15\\n7 8 1\\n\", \"10 76\\n1 2 82\\n4 6 43\\n9 10 13\\n12 12 8\\n14 15 16\\n15 15 9\\n16 16 92\\n16 18 77\\n18 19...
Recently you've discovered a new shooter. They say it has realistic game mechanics. Your character has a gun with magazine size equal to k and should exterminate n waves of monsters. The i-th wave consists of a_i monsters and happens from the l_i-th moment of time up to the r_i-th moments of time. All a_i monsters spa...
0
{"tests": "{\"inputs\": [\"4\\n4\\n1 2 3\\n1 2 3\\n5\\n1 2 3 4\\n1 1 1 1\\n6\\n1 1 1 1 2\\n1 2 1 2 2\\n7\\n1 1 3 4 4 5\\n1 2 1 4 2 5\\n\", \"4\\n4\\n1 2 3\\n1 2 3\\n5\\n1 2 3 4\\n1 1 1 1\\n6\\n1 2 1 1 2\\n1 2 1 2 2\\n7\\n1 1 3 4 4 5\\n1 2 1 4 2 5\\n\", \"4\\n4\\n1 2 3\\n1 2 3\\n5\\n1 2 3 4\\n1 1 1 1\\n6\\n1 2 1 1 2\\n1...
Soroush and Keshi each have a labeled and rooted tree on n vertices. Both of their trees are rooted from vertex 1. Soroush and Keshi used to be at war. After endless decades of fighting, they finally became allies to prepare a Codeforces round. To celebrate this fortunate event, they decided to make a memorial graph o...
0
{"tests": "{\"inputs\": [\"5\\n4 1\\n4 2\\n7 3\\n1 1\\n42 7\\n\", \"12\\n11 4\\n9 2\\n10000 100\\n1000000000 2345\\n123456 1234567\\n123456 65536\\n5 55\\n5 3\\n2323 10\\n999111000 232323\\n999888777 777888999\\n999888777 777\\n\", \"17\\n1 1000000000\\n1000000000 1\\n1000000000 1000000000\\n1000000000 999999999\\n9999...
Once n people simultaneously signed in to the reception at the recently opened, but already thoroughly bureaucratic organization (abbreviated TBO). As the organization is thoroughly bureaucratic, it can accept and cater for exactly one person per day. As a consequence, each of n people made an appointment on one of the...
0
{"tests": "{\"inputs\": [\"6\\n12 5 8 3 11 9\\n\", \"101\\n38 47 46 44 77 39 62 29 24 21 9 64 98 56 86 79 30 71 12 20 50 70 22 5 13 23 51 35 78 18 59 43 34 63 75 82 10 2 97 83 53 32 33 69 6 99 11 14 100 8 84 19 68 49 89 65 42 92 1 40 88 73 81 80 16 96 15 93 60 54 31 57 37 85 74 95 66 26 17 27 25 3 48 72 7 41 87 45 28 9...
Polar bears like unique arrays — that is, arrays without repeated elements. You have got a unique array s with length n containing non-negative integers. Since you are good friends with Alice and Bob, you decide to split the array in two. Precisely, you need to construct two arrays a and b that are also of length n, w...
0
{"tests": "{\"inputs\": [\"10 3\\nX...X..X..\\n..X...X..X\\n11 7\\n7 18\\n18 10\\n\", \"4 7\\n.X..\\n...X\\n5 1\\n1 3\\n7 7\\n1 4\\n6 1\\n4 7\\n5 7\\n\", \"1 1\\n.\\n.\\n1 2\\n\", \"2 1\\nX.\\n..\\n2 3\\n\", \"2 1\\n..\\n.X\\n1 2\\n\", \"2 1\\n..\\nX.\\n1 4\\n\", \"2 1\\n.X\\n..\\n1 4\\n\", \"2 1\\n..\\nX.\\n1 2\\n\", ...
The last product of the R2 company in the 2D games' field is a new revolutionary algorithm of searching for the shortest path in a 2 × n maze. Imagine a maze that looks like a 2 × n rectangle, divided into unit squares. Each unit square is either an empty cell or an obstacle. In one unit of time, a person can move fro...
0.25
{"tests": "{\"inputs\": [\"8 3\\naeabcaez\\n\", \"5 5\\npjfjb\\n\", \"10 5\\nabcdeedcba\\n\", \"1 1\\nd\\n\", \"2 2\\nat\\n\", \"4 4\\nrkoa\\n\", \"10 4\\nabcddddcef\\n\", \"46 29\\nxxzkzsxlyhotmfjpptrilatgtqpyshraiycmyzzlrcllvu\\n\", \"198 3\\ntuxqalctjyegbvouezfiqoeoazizhmjhpcmvyvjkyrgxkeupwcmvzcosdrrfgtdmxwfttxjxsba...
Nam is playing with a string on his computer. The string consists of n lowercase English letters. It is meaningless, so Nam decided to make the string more beautiful, that is to make it be a palindrome by using 4 arrow keys: left, right, up, down. There is a cursor pointing at some symbol of the string. Suppose that c...
0
{"tests": "{\"inputs\": [\"9\\n0 2 3 4 1 1 0 2 2\\n\", \"5\\n2 1 3 0 1\\n\", \"4\\n0 2 1 1\\n\", \"54\\n4 17 18 15 6 0 12 19 20 21 19 14 23 20 7 19 0 2 13 18 2 1 0 1 0 5 11 10 1 16 8 21 20 1 16 1 1 0 15 2 22 2 2 2 18 0 3 9 1 20 19 14 0 2\\n\", \"6\\n0 1 2 1 2 0\\n\", \"7\\n3 0 0 4 2 2 1\\n\", \"123\\n114 105 49 11 115 ...
On February, 30th n students came in the Center for Training Olympiad Programmers (CTOP) of the Berland State University. They came one by one, one after another. Each of them went in, and before sitting down at his desk, greeted with those who were present in the room by shaking hands. Each of the students who came in...
0
{"tests": "{\"inputs\": [\"4\\nCC..\\nC..C\\n.CC.\\n.CC.\\n\", \"3\\n.CC\\nC..\\nC.C\\n\", \"7\\n.CC..CC\\nCC.C..C\\nC.C..C.\\nC...C.C\\nCCC.CCC\\n.CC...C\\n.C.CCC.\\n\", \"3\\nC..\\nC..\\nC..\\n\", \"20\\nC.C.CCC.C....C.CCCCC\\nC.CC.C..CCC....CCCC.\\n.CCC.CC...CC.CCCCCC.\\n.C...CCCC..C....CCC.\\n.C..CCCCCCC.C.C.....\\...
Door's family is going celebrate Famil Doors's birthday party. They love Famil Door so they are planning to make his birthday cake weird! The cake is a n × n square consisting of equal squares with side length 1. Each square is either empty or consists of a single chocolate. They bought the cake and randomly started t...
0.875
{"tests": "{\"inputs\": [\"6 2\\nbb a\\nba a\\n\", \"2 8\\naf e\\ndc d\\ncc f\\nbc b\\nda b\\neb a\\nbb b\\nff c\\n\", \"3 5\\nab a\\ncc c\\nca a\\nee c\\nff d\\n\", \"6 36\\nac a\\naf a\\ndb a\\nab a\\ncb a\\nef a\\nad a\\nbd a\\nfe a\\nde a\\nbe a\\nbb a\\naa a\\nae a\\ndf a\\nbc a\\nbf a\\nce a\\nba a\\nfd a\\ndc a\...
Limak is a little polar bear. Polar bears hate long strings and thus they like to compress them. You should also know that Limak is so young that he knows only first six letters of the English alphabet: 'a', 'b', 'c', 'd', 'e' and 'f'. You are given a set of q possible operations. Limak can perform them in any order, ...
0.625
{"tests": "{\"inputs\": [\"2 100000 569\\n605 986\\n\", \"5 1 2\\n9 7 11 15 5\\n\", \"11 1003 9\\n12 5 10 8 0 6 8 10 12 14 4\\n\", \"5 4 6\\n0 2 2 2 3\\n\", \"31 3 4\\n7 18 16 14 16 7 13 10 2 3 8 11 20 4 7 1 7 13 17 12 9 8 10 3 11 3 4 8 16 10 3\\n\", \"10 3 5\\n1 2 3 4 5 6 7 8 9 10\\n\", \"1 1 100\\n923\\n\", \"10 2219...
Jon Snow now has to fight with White Walkers. He has n rangers, each of which has his own strength. Also Jon Snow has his favourite number x. Each ranger can fight with a white walker only if the strength of the white walker equals his strength. He however thinks that his rangers are weak and need to improve. Jon now t...
0.25
{"tests": "{\"inputs\": [\"5 4 7 2\\n1 1\\n2 2\\n2 1\\n5 1\\n3 3\\n4 4\\n4 1\\n5 3\\n5 4\\n\", \"3 3 5 1\\n1 1\\n2 2\\n3 3\\n1 2\\n2 3\\n3 1\\n\", \"13 18 27 13\\n1 1\\n1 2\\n1 3\\n1 4\\n1 17\\n2 5\\n2 1\\n3 6\\n3 2\\n5 14\\n5 3\\n4 4\\n6 9\\n6 3\\n7 8\\n7 3\\n8 7\\n8 9\\n10 11\\n10 18\\n11 10\\n11 15\\n11 11\\n9 12\\n...
Sagheer is working at a kindergarten. There are n children and m different toys. These children use well-defined protocols for playing with the toys: * Each child has a lovely set of toys that he loves to play with. He requests the toys one after another at distinct moments of time. A child starts playing if and onl...
0
{"tests": "{\"inputs\": [\"3 3\\n\", \"175236 173750\\n\", \"646205 361804\\n\", \"284114 73851\\n\", \"261457 212062\\n\", \"3745 1612\\n\", \"519169 430233\\n\", \"976535 433238\\n\", \"896437 604720\\n\", \"784160 282537\\n\", \"942045 878421\\n\", \"43657 852\\n\", \"921643 744360\\n\", \"361284 5729\\n\", \"234247...
There is an airplane which has n rows from front to back. There will be m people boarding this airplane. This airplane has an entrance at the very front and very back of the plane. Each person has some assigned seat. It is possible for multiple people to have the same assigned seat. The people will then board the pla...
0
{"tests": "{\"inputs\": [\"0 1\\n0 0\\n\", \"1 5\\n5 2\\n\", \"24 41\\n24 42\\n\", \"41 -82\\n-33 -15\\n\", \"1 1\\n0 1\\n\", \"-90 -54\\n9 -9\\n\", \"-100 100\\n-100 -100\\n\", \"100 -100\\n-100 100\\n\", \"-68 26\\n-2 6\\n\", \"25 76\\n24 76\\n\", \"-20 34\\n-9 55\\n\", \"-53 63\\n-53 62\\n\", \"-30 94\\n31 -58\\n\",...
Polycarp takes part in a quadcopter competition. According to the rules a flying robot should: * start the race from some point of a field, * go around the flag, * close cycle returning back to the starting point. Polycarp knows the coordinates of the starting point (x1, y1) and the coordinates of the poin...
0
{"tests": "{\"inputs\": [\"6 7\\n1 4\\n5 2\\n3 0\\n5 5\\n4 1\\n0 3\\n4 2\", \"6 7\\n0 4\\n5 2\\n3 0\\n5 5\\n4 1\\n0 3\\n4 2\", \"6 7\\n1 4\\n5 2\\n5 0\\n5 5\\n4 1\\n0 3\\n4 2\", \"6 7\\n0 4\\n5 2\\n3 0\\n5 5\\n0 1\\n0 3\\n4 2\", \"6 5\\n0 4\\n5 2\\n3 0\\n5 5\\n0 1\\n0 3\\n4 2\", \"6 7\\n1 5\\n5 2\\n3 0\\n5 5\\n4 1\\n0 ...
You are given a directed graph with N vertices and M edges, not necessarily simple. The i-th edge is oriented from the vertex a_i to the vertex b_i. Divide this graph into strongly connected components and print them in their topological order. Constraints * 1 \leq N \leq 500,000 * 1 \leq M \leq 500,000 * 0 \leq a_i,...
0
{"tests": "{\"inputs\": [\"6\\n4\\n2\\n5\\n4\\n2\\n4\", \"5\\n1\\n2\\n1\\n2\\n2\", \"7\\n1\\n3\\n1\\n2\\n3\\n3\\n2\", \"6\\n4\\n2\\n2\\n4\\n2\\n4\", \"5\\n1\\n4\\n1\\n2\\n2\", \"6\\n4\\n2\\n2\\n1\\n2\\n4\", \"6\\n4\\n1\\n2\\n1\\n2\\n4\", \"7\\n1\\n2\\n1\\n2\\n3\\n3\\n2\", \"6\\n3\\n2\\n2\\n2\\n2\\n4\", \"7\\n1\\n3\\n1\...
There are N stones arranged in a row. The i-th stone from the left is painted in the color C_i. Snuke will perform the following operation zero or more times: * Choose two stones painted in the same color. Repaint all the stones between them, with the color of the chosen stones. Find the number of possible final s...
0
{"tests": "{\"inputs\": [\"3 5\", \"100000 100000\", \"100000 2\", \"5 5\", \"4 5\", \"100100 100000\", \"000000 2\", \"5 1\", \"100100 110000\", \"100111 100001\", \"100111 000101\", \"000011 001100\", \"000010 011000\", \"010010 011110\", \"011000 110111\", \"001000 110101\", \"001010 110101\", \"100100 100010\", \"1...
There is a bar of chocolate with a height of H blocks and a width of W blocks. Snuke is dividing this bar into exactly three pieces. He can only cut the bar along borders of blocks, and the shape of each piece must be a rectangle. Snuke is trying to divide the bar as evenly as possible. More specifically, he is trying...
0
{"tests": "{\"inputs\": [\"3 50\\n30 20 10\", \"5 50\\n10 20 30 40 50\", \"2 21\\n10 10\", \"3 50\\n30 17 10\", \"5 50\\n10 20 30 40 88\", \"2 21\\n10 20\", \"3 50\\n55 17 10\", \"5 80\\n10 20 30 40 50\", \"5 50\\n10 20 29 51 104\", \"5 30\\n10 20 29 51 104\", \"3 23\\n0 17 18\", \"2 21\\n10 13\", \"3 50\\n34 17 10\", ...
We have N pieces of ropes, numbered 1 through N. The length of piece i is a_i. At first, for each i (1≤i≤N-1), piece i and piece i+1 are tied at the ends, forming one long rope with N-1 knots. Snuke will try to untie all of the knots by performing the following operation repeatedly: * Choose a (connected) rope with a...
0
{"tests": "{\"inputs\": [\"6\\n8\\n1,2,2,2\\n1,3,4,3\\n1,4,4,2\\n2,5,3,2\\n3,4,4,2\\n3,6,1,2\\n4,6,1,1\\n5,6,1,2\\n2,4,50,30\", \"6\\n8\\n1,2,2,2\\n1,3,4,3\\n1,4,4,2\\n2,5,3,2\\n3,4,4,2\\n3,6,1,2\\n4,6,1,1\\n5,6,2,2\\n2,4,50,30\", \"6\\n8\\n1,2,2,2\\n1,3,4,3\\n1,4,4,2\\n2,5,3,2\\n3,4,4,2\\n3,6,1,2\\n4,6,1,1\\n2,1,6,5\\...
One day, the lord ordered a carpenter to "build a sturdy and large building where the townspeople could evacuate in the event of a typhoon or earthquake." However, large thick pillars are needed to complete the sturdy and large building. There is no such big pillar in the town. So the carpenter decided to go to a dista...
0
{"tests": "{\"inputs\": [\"7\\n1 3\\n3 4\\n1 4\\n2 7\\n5 7\\n6 7\\n1 7\\n6\\n1 2\\n2 3\\n3 4\\n4 5\\n1 5\\n2 6\\n7\\n1 3\\n2 4\\n3 5\\n4 6\\n6 7\\n2 6\\n4 7\\n0\", \"7\\n1 3\\n3 4\\n1 4\\n2 7\\n5 7\\n6 7\\n1 7\\n6\\n1 2\\n2 3\\n3 4\\n4 4\\n1 5\\n2 6\\n7\\n1 3\\n2 4\\n3 5\\n4 6\\n6 7\\n2 6\\n4 7\\n0\", \"7\\n1 3\\n3 4\\...
Consider a string with rings on both ends. Rings have positive integers to distinguish them. Rings on both ends of the string have different numbers a and b. Describe this as [a, b]. If there are multiple strings and the number attached to the ring of one string and the other string is the same, these strings can be co...
0
{"tests": "{\"inputs\": [\"010\\n\", \"1\\n\", \"010\\n\", \"011110\\n\", \"0\\n\", \"01\\n\", \"110\\n\", \"011111\\n\", \"000\\n\", \"111\\n\", \"001111\\n\", \"100\\n\", \"101\\n\", \"101111\\n\", \"011\\n\", \"001\\n\", \"001101\\n\", \"011010\\n\", \"011011\\n\", \"111111\\n\", \"101011\\n\", \"011101\\n\", \"0101...
You are given a 4x4 grid. You play a game — there is a sequence of tiles, each of them is either 2x1 or 1x2. Your task is to consequently place all tiles from the given sequence in the grid. When tile is placed, each cell which is located in fully occupied row or column is deleted (cells are deleted at the same time in...
0
{"tests": "{\"inputs\": [\"2\\n\", \"1\\n\", \"3\\n\", \"12\\n\", \"19\\n\", \"17\\n\", \"11\\n\", \"25\\n\", \"24\\n\", \"22\\n\", \"996\\n\", \"8\\n\", \"1000\\n\", \"9\\n\", \"6\\n\", \"10\\n\", \"20\\n\", \"998\\n\", \"13\\n\", \"26\\n\", \"21\\n\", \"30\\n\", \"18\\n\", \"16\\n\", \"28\\n\", \"5\\n\", \"4\\n\", \"...
Neko is playing with his toys on the backyard of Aki's house. Aki decided to play a prank on him, by secretly putting catnip into Neko's toys. Unfortunately, he went overboard and put an entire bag of catnip into the toys... It took Neko an entire day to turn back to normal. Neko reported to Aki that he saw a lot of w...
0
{"tests": "{\"inputs\": [\"3\\n1 2 3\\n1 2 3\\n\", \"1\\n0\\n1\\n\", \"4\\n3 2 3 6\\n2 8 5 10\\n\", \"10\\n206158430208 206162624513 68719476737 137506062337 206162624513 4194305 68719476737 206225539072 137443147777 68719476736\\n202243898 470292528 170057449 290025540 127995253 514454151 607963029 768676450 611202521...
Marcin is a coach in his university. There are n students who want to attend a training camp. Marcin is a smart coach, so he wants to send only the students that can work calmly with each other. Let's focus on the students. They are indexed with integers from 1 to n. Each of them can be described with two integers a_i...
0
{"tests": "{\"inputs\": [\"8 5\\n7 5\\n1 7\\n6 1\\n3 7\\n8 3\\n2 1\\n4 5\\n\", \"7 4\\n1 2\\n1 3\\n1 4\\n3 5\\n3 6\\n4 7\\n\", \"4 1\\n1 2\\n1 3\\n2 4\\n\", \"3 2\\n1 2\\n1 3\\n\", \"3 1\\n1 2\\n2 3\\n\", \"20 7\\n9 7\\n3 7\\n15 9\\n1 3\\n11 9\\n18 7\\n17 18\\n20 1\\n4 11\\n2 11\\n12 18\\n8 18\\n13 2\\n19 2\\n10 9\\n6 ...
Writing light novels is the most important thing in Linova's life. Last night, Linova dreamed about a fantastic kingdom. She began to write a light novel for the kingdom as soon as she woke up, and of course, she is the queen of it. <image> There are n cities and n-1 two-way roads connecting pairs of cities in the ki...
0
{"tests": "{\"inputs\": [\"5 10\\n0 1 0 2 1\\n\", \"3 2\\n1 2 3\\n\", \"10 6\\n4 2 2 3 4 0 3 2 2 2\\n\", \"7 4\\n0 10 10 11 11 12 13\\n\", \"12 3\\n7878607 7878605 7878605 7878613 7878612 7878609 7878609 7878608 7878609 7878611 7878609 7878613\\n\", \"2 0\\n8 9\\n\", \"2 5\\n8 9\\n\", \"9 6\\n10225066 10225069 10225069...
This problem is the most boring one you've ever seen. Given a sequence of integers a1, a2, ..., an and a non-negative integer h, our goal is to partition the sequence into two subsequences (not necessarily consist of continuous elements). Each element of the original sequence should be contained in exactly one of the...
0
{"tests": "{\"inputs\": [\"3\\n\", \"17\\n\", \"11\\n\", \"18\\n\", \"4\\n\", \"13\\n\", \"15\\n\", \"14\\n\", \"19\\n\", \"14\\n\", \"10\\n\", \"5\\n\", \"12\\n\", \"13\\n\", \"12\\n\", \"7\\n\", \"18\\n\", \"15\\n\", \"17\\n\", \"10\\n\", \"19\\n\", \"16\\n\", \"20\\n\", \"20\\n\", \"6\\n\", \"9\\n\", \"8\\n\", \"11\...
Volodya has recently visited a very odd town. There are N tourist attractions in the town and every two of them are connected by a bidirectional road. Each road has some travel price (natural number) assigned to it and all prices are distinct. But the most striking thing about this town is that each city sightseeing to...
0
{"tests": "{\"inputs\": [\"3 1\\n1 2 1\\n\", \"6 3\\n5 20 12 7 14 101\\n\", \"3 1\\n2 2 1\\n\", \"2 2\\n67427 727097\\n\", \"3 3\\n767153 643472 154791\\n\", \"3 3\\n814664 27142 437959\\n\", \"1 1\\n107540\\n\", \"6 3\\n346 118 330 1403 5244 480\\n\", \"7 4\\n11 3532 99 3512 12 8 22\\n\", \"3 3\\n349371 489962 45420\\...
There are n cities in Westeros. The i-th city is inhabited by ai people. Daenerys and Stannis play the following game: in one single move, a player chooses a certain town and burns it to the ground. Thus all its residents, sadly, die. Stannis starts the game. The game ends when Westeros has exactly k cities left. The ...
0
{"tests": "{\"inputs\": [\"5 4\\n1 1 3\\n2 3 90\\n2 5 48\\n1 4 1\\n\", \"1 1\\n2 1 302\\n\", \"50 50\\n1 41 261\\n2 47 324\\n1 41 256\\n1 31 339\\n2 23 116\\n2 44 184\\n2 32 115\\n1 40 301\\n2 40 303\\n1 29 309\\n2 49 348\\n2 47 356\\n1 41 263\\n2 42 276\\n1 45 135\\n1 33 226\\n2 31 166\\n1 50 171\\n2 47 166\\n2 50 284...
Roger is a robot. He has an arm that is a series of n segments connected to each other. The endpoints of the i-th segment are initially located at points (i - 1, 0) and (i, 0). The endpoint at (i - 1, 0) is colored red and the endpoint at (i, 0) is colored blue for all segments. Thus, the blue endpoint of the i-th segm...
0
{"tests": "{\"inputs\": [\"6\\n000000\\n000000\\n012100\\n024200\\n012100\\n000000\\n\", \"8\\n00000000\\n00001210\\n00002420\\n00002020\\n00001210\\n00000000\\n00000000\\n00000000\\n\", \"7\\n0000000\\n0000000\\n0000000\\n1122210\\n0244420\\n0122210\\n0000000\\n\", \"7\\n0000000\\n0012210\\n0024420\\n0012210\\n0000000...
The zombies are gathering in their secret lair! Heidi will strike hard to destroy them once and for all. But there is a little problem... Before she can strike, she needs to know where the lair is. And the intel she has is not very good. Heidi knows that the lair can be represented as a rectangle on a lattice, with si...
0.625
{"tests": "{\"inputs\": [\"bbbabb\\nbb\\n1 6 3 4 2 5\\n\", \"ababcba\\nabb\\n5 3 4 1 7 6 2\\n\", \"aaaaaaaadbaaabbbbbddaaabdadbbbbbdbbabbbabaabdbbdababbbddddbdaabbddbbbbabbbbbabadaadabaaaadbbabbbaddb\\naaaaaaaaaaaaaa\\n61 52 5 43 53 81 7 96 6 9 34 78 79 12 8 63 22 76 18 46 41 56 3 20 57 21 75 73 100 94 35 69 32 4 70 95...
Little Nastya has a hobby, she likes to remove some letters from word, to obtain another word. But it turns out to be pretty hard for her, because she is too young. Therefore, her brother Sergey always helps her. Sergey gives Nastya the word t and wants to get the word p out of it. Nastya removes letters in a certain ...
0.875
{"tests": "{\"inputs\": [\"4\\n2\\n3\\n2\\n0\\n2\\n3\\n2\\n0\", \"3\\n0\\n0\\n3\\n2\\n3\\n2\", \"10\\n0 1 2 3 4 5 6 7 8 9\\n\", \"6\\n0 1 2 4 3 5\\n\", \"2\\n0 1\\n\", \"4\\n3 1 2 0\\n\", \"64\\n0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 ...
This is an interactive problem. Jury has hidden a permutation p of integers from 0 to n - 1. You know only the length n. Remind that in permutation all integers are distinct. Let b be the inverse permutation for p, i.e. pbi = i for all i. The only thing you can do is to ask xor of elements pi and bj, printing two ind...
0
{"tests": "{\"inputs\": [\"10\\n4 1825\\n3 75\\n3 530\\n4 1829\\n4 1651\\n3 187\\n4 584\\n4 255\\n4 774\\n2 474\\n\", \"3\\n1 1\\n1 2\\n1 111111111111\\n\", \"5\\n0 69\\n1 194\\n1 139\\n0 47\\n1 66\\n\", \"10\\n96759 970434747560290241\\n95684 985325796232084031\\n99418 855577012478917561\\n98767 992053283401739711\\n9...
What are you doing at the end of the world? Are you busy? Will you save us? <image> Nephren is playing a game with little leprechauns. She gives them an infinite array of strings, f0... ∞. f0 is "What are you doing at the end of the world? Are you busy? Will you save us?". She wants to let more people know about i...
0
{"tests": "{\"inputs\": [\"5\\n1 2 3 4 5\\n00001\\n\", \"10\\n-10 -9 -8 -7 -6 6 7 8 9 10\\n0000111110\\n\", \"99\\n-94 -97 -95 -99 94 98 91 95 90 -98 -92 -93 -91 -100 84 81 80 89 89 70 76 79 69 74 -80 -90 -83 -81 -80 64 60 60 60 68 56 50 55 50 57 39 47 47 48 49 37 31 34 38 34 -76 -71 -70 -76 -70 23 21 24 29 22 -62 -65 ...
"We've tried solitary confinement, waterboarding and listening to Just In Beaver, to no avail. We need something extreme." "Little Alena got an array as a birthday present..." The array b of length n is obtained from the array a of length n and two integers l and r (l ≤ r) using the following procedure: b1 = b2 = b3...
0.25
{"tests": "{\"inputs\": [\"6\\n0 10 -7 -4 -13 0\", \"5\\n0 2 5 1 0\", \"11\\n0 -4 0 -99 31 14 -15 -39 43 18 0\", \"6\\n0 10 -7 -4 -5 0\", \"5\\n0 2 5 0 0\", \"11\\n0 -4 0 -99 31 14 -15 -39 43 24 0\", \"6\\n0 2 -7 -1 -5 0\", \"11\\n0 -4 0 -99 31 13 -15 -39 64 24 0\", \"6\\n0 4 -7 -1 -3 0\", \"6\\n0 4 -7 -1 -1 0\", \"6\\...
There is an infinitely large pond, which we consider as a number line. In this pond, there are N lotuses floating at coordinates 0, 1, 2, ..., N-2 and N-1. On the lotus at coordinate i, an integer s_i is written. You are standing on the lotus at coordinate 0. You will play a game that proceeds as follows: * 1. Choose...
0
{"tests": "{\"inputs\": [\"6\\n0 1 2 3\\n0 4 6 1\\n1 6 7 2\\n2 7 5 3\\n6 4 5 7\\n4 0 3 5\", \"6\\n0 0 0 0\\n0 0 0 0\\n0 0 0 0\\n0 0 0 0\\n0 0 0 0\\n0 0 0 0\", \"8\\n0 0 0 0\\n0 0 1 1\\n0 1 0 1\\n0 1 1 0\\n1 0 0 1\\n1 0 1 0\\n1 1 0 0\\n1 1 1 1\", \"6\\n0 1 2 3\\n0 4 6 1\\n1 6 9 2\\n2 7 5 3\\n6 4 5 7\\n4 0 3 5\", \"8\\n0...
AtCoDeer the deer has N square tiles. The tiles are numbered 1 through N, and the number given to each tile is written on one side of the tile. Also, each corner of each tile is painted in one of the 1000 colors, which are represented by the integers 0 between 999. The top-left, top-right, bottom-right and bottom-left ...
0
{"tests": "{\"inputs\": [\"5\\n1 2 3 4 5 6\\n1 3 5 6 8 4\\n1 2 3 4 5 8\\n1 2 4 5 10 11\\n1 2 3 6 9 11\", \"5\\n1 2 3 4 5 6\\n1 3 5 6 8 4\\n1 2 3 4 5 8\\n1 2 4 5 10 11\\n1 3 3 6 9 11\", \"5\\n1 2 3 4 5 6\\n1 3 5 6 8 4\\n1 2 3 4 5 8\\n1 2 3 5 10 5\\n1 3 3 6 9 11\", \"5\\n1 2 3 4 5 6\\n1 3 5 6 8 4\\n1 2 3 4 6 8\\n1 2 3 5 ...
There is "7 rows" in the game using playing cards. Here we consider a game that simplifies it. Arrange 7 using 13 cards with numbers 1 to 13 written on each. In the match, the game progresses as follows with only two players. 1. Place 7 cards in the "field". 2. Six remaining cards will be randomly distributed to the t...
0
{"tests": "{\"inputs\": [\"5 5 2\\n2 3 1\\n3 1 2\\n2 4 3\\n1 2 4\\n2 5 5\", \"5 5 2\\n2 3 1\\n3 1 2\\n1 4 3\\n1 2 4\\n2 5 5\", \"5 5 2\\n2 3 1\\n3 1 4\\n1 4 3\\n1 2 4\\n2 5 5\", \"5 0 2\\n2 3 1\\n3 1 4\\n1 2 2\\n1 2 4\\n2 5 5\", \"5 5 2\\n2 3 1\\n3 1 4\\n1 4 3\\n1 2 4\\n1 5 5\", \"5 5 2\\n2 3 1\\n3 1 2\\n2 4 3\\n1 2 4\...
JOI Park In preparation for the Olympic Games in IOI in 20XX, the JOI Park in IOI will be developed. There are N squares in JOI Park, and the squares are numbered from 1 to N. There are M roads connecting the squares, and the roads are numbered from 1 to M. The road i (1 ≤ i ≤ M) connects the square Ai and the square ...
0.125
{"tests": "{\"inputs\": [\"3\\n1 3\\n2 0\\n0 0\\n4\\n4 1\\n3 1\\n1 2\\n0 0\\n5\\n2 1\\n3 1\\n4 1\\n3 2\\n1 1\\n0 0\\n0\", \"3\\n1 3\\n2 0\\n0 0\\n4\\n4 1\\n3 1\\n1 0\\n0 0\\n5\\n2 1\\n3 1\\n4 1\\n3 2\\n1 1\\n0 0\\n0\", \"3\\n1 3\\n2 0\\n0 0\\n4\\n4 1\\n3 1\\n1 2\\n0 0\\n5\\n2 2\\n3 1\\n4 1\\n3 2\\n1 1\\n0 0\\n0\", \"3\...
There are cubes of the same size and a simple robot named Masato. Initially, all cubes are on the floor. Masato can be instructed to pick up a cube and put it on another cube, to make piles of cubes. Each instruction is of the form `pick up cube A and put it on cube B (or on the floor).' When he is to pick up a cube, ...
0
{"tests": "{\"inputs\": [\"4\\n 0 2 2 2\\n 2 0 2 2\\n 2 2 0 2\\n 2 2 2 0\\n4\\n 0 2 4 4\\n 2 0 4 4\\n 4 4 0 2\\n 4 4 2 0\\n2\\n 0 12\\n 12 0\\n0\", \"4\\n0 2 2 2\\n2 0 2 2\\n2 2 0 2\\n2 2 2 0\\n4\\n0 2 4 4\\n2 0 4 4\\n4 4 0 2\\n4 4 2 0\\n2\\n0 12\\n12 ...
Gilbert is the network admin of Ginkgo company. His boss is mad about the messy network cables on the floor. He finally walked up to Gilbert and asked the lazy network admin to illustrate how computers and switches are connected. Since he is a programmer, he is very reluctant to move throughout the office and examine c...
0.125
{"tests": "{\"inputs\": [\"3 3 2\\n12 578 2214\\n59 471605241352156968 431565444592236940\\n0 0 0\", \"3 3 2\\n12 578 1435\\n59 471605241352156968 431565444592236940\\n0 0 0\", \"3 3 2\\n12 578 1954\\n59 471605241352156968 431565444592236940\\n0 0 0\", \"3 3 2\\n12 785 2214\\n59 471605241352156968 431565444592236940\\n...
Folding a Ribbon Think of repetitively folding a very long and thin ribbon. First, the ribbon is spread out from left to right, then it is creased at its center, and one half of the ribbon is laid over the other. You can either fold it from the left to the right, picking up the left end of the ribbon and laying it ove...
0
{"tests": "{\"inputs\": [\"2 3 1000 1000 1 1 1 2\", \"10 10 1 11 3 3 7 7\", \"10 10 1 10 3 3 7 7\", \"2 3 1001 1000 1 1 1 2\", \"16 10 1 10 3 3 7 7\", \"2 3 1001 1000 1 2 1 2\", \"16 10 1 10 3 3 2 7\", \"2 3 1000 1000 1 2 1 2\", \"2 3 1000 1000 1 2 0 2\", \"2 3 1000 1010 1 2 0 2\", \"16 10 0 7 3 3 2 8\", \"2 2 1000 100...
The fearless Ikta has finally hunted down the infamous Count Big Bridge! Count Bigbridge is now trapped in a rectangular room w meters wide and h meters deep, waiting for his end. If you select a corner of the room and take the coordinate system so that the width direction is the x-axis and the depth direction is the ...
0
{"tests": "{\"inputs\": [\"3 2\\n2 2\", \"3 2\\n2 3\", \"5 1\\n2 3\", \"3 2\\n1 2\", \"3 2\\n1 3\", \"4 2\\n1 3\", \"2 2\\n2 2\", \"5 2\\n2 3\", \"3 1\\n1 2\", \"3 3\\n1 3\", \"4 3\\n1 3\", \"2 2\\n4 2\", \"3 1\\n1 0\", \"3 2\\n1 5\", \"2 2\\n4 1\", \"2 1\\n2 3\", \"3 2\\n2 5\", \"0 2\\n4 2\", \"2 0\\n2 3\", \"3 2\\n3 ...
B: Nakajima, let's do that! --Match Peas War - problem Nakajima "Uhh ..." Isono "Nakajima, are you okay?" Nakajima "... I feel like I was having an unpleasant dream." Isono "What kind of dream do you have?" Nakajima "Dream to play infinitely" Isono "I don't know what it means. Well, Nakajima, let's do that!" Na...
0
{"tests": "{\"inputs\": [\"5 5 0 0 4 4\", \"1 1 0 0 0 0\", \"1 10 0 0 0 9\", \"2 2 0 0 1 1\", \"421 435 196 169 388 9\", \"2 2 0 0 0 1\", \"421 435 196 169 388 5\", \"1 2 0 0 0 0\", \"421 435 196 91 388 9\", \"5 6 0 0 4 4\", \"1 10 0 1 0 9\", \"421 435 196 169 388 12\", \"421 435 196 169 388 10\", \"421 435 196 118 388...
Problem There is a grid of $ R \ times C $ squares with $ (0, 0) $ in the upper left and $ (R-1, C-1) $ in the lower right. When you are in a square ($ e $, $ f $), from there $ (e + 1, f) $, $ (e-1, f) $, $ (e, f + 1) $, $ (e) , f-1) $, $ (e, 0) $, $ (e, C-1) $, $ (0, f) $, $ (R-1, f) $ can be moved at a cost of $ 1 ...
0.75
{"tests": "{\"inputs\": [\"1\\nhello\\n3\", \"1\\nhlelo\\n3\", \"1\\nhlelo\\n2\", \"1\\nolelh\\n2\", \"1\\nolelh\\n1\", \"1\\nokelh\\n1\", \"1\\nhleko\\n1\", \"1\\nhloke\\n1\", \"1\\ngloke\\n1\", \"1\\nekolg\\n1\", \"1\\nfkolg\\n1\", \"1\\nfknlg\\n1\", \"1\\nfknlg\\n2\", \"1\\nfknlg\\n0\", \"1\\nfknlg\\n-1\", \"1\\ngln...
In this problem, you are given a string of N characters(1-indexed), and an integer D. You perform multiple operations on this string. In the first operation you select the first D characters of the string, ie. the substring S[1...D] and reverse it. The other characters remain unchanged. Thus, after the first operation ...
0
{"tests": "{\"inputs\": [\"4\\n2 3\\n\", \"5\\n3 5\\n\", \"2\\n2 2\\n\", \"878602530892252875\\n583753601575252768 851813862933314387\\n\", \"982837494536444311\\n471939396014493192 262488194864680421\\n\", \"778753534913338583\\n547836868672081726 265708022656451521\\n\", \"100000000000000000\\n50000000000000001 50000...
On a chessboard with a width of n and a height of n, rows are numbered from bottom to top from 1 to n, columns are numbered from left to right from 1 to n. Therefore, for each cell of the chessboard, you can assign the coordinates (r,c), where r is the number of the row, and c is the number of the column. The white ki...
0
{"tests": "{\"inputs\": [\"0 3\\n0 0\\n3\\nUDD\\n\", \"0 0\\n4 6\\n3\\nUUU\\n\", \"0 0\\n0 1\\n1\\nL\\n\", \"0 1\\n2 1\\n1\\nR\\n\", \"0 0\\n0 1\\n2\\nLU\\n\", \"0 0\\n1000000000 1000000000\\n2\\nDR\\n\", \"1 0\\n0 0\\n2\\nLU\\n\", \"0 0\\n1000000010 1000000000\\n2\\nDR\\n\", \"0 -1\\n0 1\\n1\\nL\\n\", \"0 0\\n1 1\\n2\...
You a captain of a ship. Initially you are standing in a point (x_1, y_1) (obviously, all positions in the sea can be described by cartesian plane) and you want to travel to a point (x_2, y_2). You know the weather forecast — the string s of length n, consisting only of letters U, D, L and R. The letter corresponds t...
0
{"tests": "{\"inputs\": [\"2 4 3\\n2 1\\n1 1 2 2\\n1 2\\n2 3\\n3 4\\n\", \"3 6 3\\n2 1 3\\n1 2 3 1 2 3\\n1 5\\n2 6\\n3 5\\n\", \"1 1 1\\n1\\n1\\n1 1\\n\", \"2 4 3\\n2 1\\n1 1 2 2\\n1 2\\n2 2\\n3 4\\n\", \"3 6 3\\n2 1 3\\n1 2 3 1 2 3\\n1 6\\n2 6\\n3 5\\n\", \"2 4 3\\n2 1\\n1 1 2 2\\n1 2\\n2 4\\n3 4\\n\", \"2 4 3\\n2 1\\...
Recently Lynyrd and Skynyrd went to a shop where Lynyrd bought a permutation p of length n, and Skynyrd bought an array a of length m, consisting of integers from 1 to n. Lynyrd and Skynyrd became bored, so they asked you q queries, each of which has the following form: "does the subsegment of a from the l-th to the ...
0.25
{"tests": "{\"inputs\": [\"2\\n2 -10 10\\n2 0 -20\\n\", \"2\\n2 3 -2\\n2 -1 5\\n\", \"4\\n3 1 7 4\\n2 3 2\\n2 8 5\\n1 10\\n\", \"1\\n1 0\\n\", \"2\\n2 1 2\\n10 0 1000000000 999999999 999999998 999999997 999999996 999999995 999999994 999999993 589934621\\n\", \"3\\n1 20\\n2 30 40\\n3 50 60 80\\n\", \"5\\n10 -251 650 475...
Ujan has a lot of numbers in his boxes. He likes order and balance, so he decided to reorder the numbers. There are k boxes numbered from 1 to k. The i-th box contains n_i integer numbers. The integers can be negative. All of the integers are distinct. Ujan is lazy, so he will do the following reordering of the numbe...
0
{"tests": "{\"inputs\": [\"6\\n4 2\\nbaba\\n5 2\\nbaacb\\n5 3\\nbaacb\\n5 3\\naaaaa\\n6 4\\naaxxzz\\n7 1\\nphoenix\\n\", \"9\\n8 2\\nchefspam\\n11 7\\nmonkeyeight\\n8 2\\nvcubingx\\n6 1\\namazed\\n4 4\\nhebs\\n8 1\\narolakiv\\n9 7\\nhidavidhu\\n33 33\\ngosubtovcubingxheneedssubscribers\\n7 4\\nhiimbad\\n\", \"9\\n8 2\\...
Phoenix has a string s consisting of lowercase Latin letters. He wants to distribute all the letters of his string into k non-empty strings a_1, a_2, ..., a_k such that every letter of s goes to exactly one of the strings a_i. The strings a_i do not need to be substrings of s. Phoenix can distribute letters of s and re...
0
{"tests": "{\"inputs\": [\"4\\n3\\n4\\n12\\n1000000000\\n\", \"4\\n3\\n4\\n12\\n1010000000\\n\", \"4\\n3\\n4\\n12\\n1010000001\\n\", \"4\\n3\\n4\\n11\\n1110000000\\n\", \"4\\n3\\n7\\n12\\n1010000001\\n\", \"4\\n3\\n1\\n11\\n1110000000\\n\", \"4\\n4\\n7\\n12\\n1010000001\\n\", \"4\\n2\\n4\\n19\\n1010000110\\n\", \"4\\n2...
Lee is going to fashionably decorate his house for a party, using some regular convex polygons... Lee thinks a regular n-sided (convex) polygon is beautiful if and only if he can rotate it in such a way that at least one of its edges is parallel to the OX-axis and at least one of its edges is parallel to the OY-axis a...
0.875
{"tests": "{\"inputs\": [\"3\\n1 1\\n2 1\\n1 7\\n\", \"3\\n1 1\\n2 1\\n96342 7\\n\", \"1\\n99899 99899\\n\", \"1\\n99899 100000\\n\", \"1\\n1000000 1\\n\", \"1\\n99999 100000\\n\", \"12\\n1 1\\n2 1\\n1 7\\n1 1\\n2 1\\n1 7\\n1 1\\n2 1\\n1 7\\n1 1\\n2 1\\n1 7\\n\", \"1\\n1000000 1000000\\n\", \"2\\n1000000 1\\n1 1000000\...
Alice and Bob play ping-pong with simplified rules. During the game, the player serving the ball commences a play. The server strikes the ball then the receiver makes a return by hitting the ball back. Thereafter, the server and receiver must alternately make a return until one of them doesn't make a return. The one ...
0
{"tests": "{\"inputs\": [\"7 2\\n2 1 3\\n3 2 4 5\\n\", \"7 2\\n2 1 2\\n3 3 4 5\\n\", \"7 3\\n1 7\\n2 6 5\\n3 4 3 2\\n\", \"100 30\\n8 62 50 93 34 82 24 87 65\\n2 64 86\\n3 91 42 88\\n2 76 7\\n2 35 63\\n3 78 84 15\\n4 90 46 73 9\\n4 74 13 95 58\\n3 71 59 55\\n2 4 31\\n1 19\\n1 10\\n2 45 23\\n2 27 69\\n4 12 66 44 22\\n1 ...
In this problem you have to implement an algorithm to defragment your hard disk. The hard disk consists of a sequence of clusters, numbered by integers from 1 to n. The disk has m recorded files, the i-th file occupies clusters with numbers ai, 1, ai, 2, ..., ai, ni. These clusters are not necessarily located consecuti...
0
{"tests": "{\"inputs\": [\"3\\n1000000000000 1000000000000 1000000000000\\n\", \"8\\n1 1 2 2 3 3 4 4\\n\", \"6\\n1 2 3 4 5 6\\n\", \"10\\n1 2 1 0 0 1 100 1 3 1\\n\", \"2\\n1024 2048\\n\", \"5\\n0 0 1 3 128\\n\", \"2\\n123456789123456789 123456789123456789\\n\", \"17\\n1 2 3 4 5 6 7 8 9 10 11 12 13 13 13 17 16\\n\", \"3...
Little Petya likes numbers a lot. Recently his mother has presented him a collection of n non-negative integers. There's only one thing Petya likes more than numbers: playing with little Masha. He immediately decided to give a part of his new collection to her. To make the game even more interesting, Petya decided to g...
0
{"tests": "{\"inputs\": [\"4 8\\n..w..w..\\n........\\n........\\n..w..w..\\n\", \"5 6\\n......\\n.w....\\n......\\n..w...\\n......\\n\", \"2 4\\n....\\n.w..\\n\", \"2 6\\nw..w.w\\n...w..\\n\", \"1 3\\n.w.\\n\", \"8 10\\n..........\\n..........\\n.....w....\\n.w........\\n..........\\n....w.....\\n..........\\n...........
Innocentius has a problem — his computer monitor has broken. Now some of the pixels are "dead", that is, they are always black. As consequence, Innocentius can't play the usual computer games. He is recently playing the following game with his younger brother Polycarpus. Innocentius is touch-typing a program that pain...
0.25
{"tests": "{\"inputs\": [\"1 1 1\\n1\\n\", \"3 1 2\\n1 2 3\\n\", \"5 1 4\\n12 6 11 9 1\\n\", \"1 1 1000000000\\n1000000000\\n\", \"1 1 1000000000\\n999999999\\n\", \"10 1 100000000\\n999999999 999999999 999999999 999999999 999999999 999999999 999999999 999999999 999999999 999999999\\n\", \"1 2 1000000000\\n1000000000\\...
Bimokh is Mashmokh's boss. For the following n days he decided to pay to his workers in a new way. At the beginning of each day he will give each worker a certain amount of tokens. Then at the end of each day each worker can give some of his tokens back to get a certain amount of money. The worker can save the rest of ...
0.5
{"tests": "{\"inputs\": [\"2\\n2 3\\n1 0\\n\", \"1\\n2\\n0\\n\", \"1\\n15\\n1\\n\", \"1\\n7\\n5\\n\", \"1\\n6\\n3\\n\", \"2\\n10 14\\n2 5\\n\", \"16\\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16\\n0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15\\n\", \"1\\n16\\n15\\n\", \"3\\n6 14 7\\n4 2 0\\n\", \"2\\n13 3\\n6 0\\n\", \"12\\n8 5 5 1...
Btoh yuo adn yuor roomatme lhoate wianshg disehs, btu stlil sdmoeboy msut peorrfm tihs cohre dialy. Oen dya yuo decdie to idourtcne smoe syestm. Yuor rmmotaoe sstgegus teh fooniwllg dael. Yuo argee on tow arayrs of ientgres M adn R, nmebur upmicnog dyas (induiclng teh cunrret oen) wtih sicsescuve irnegets (teh ceurrnt ...
0.875
{"tests": "{\"inputs\": [\"3 3 4\\n1 1\\n1 2\\n2 1\\n2 2\\n\", \"3 4 6\\n1 1\\n2 1\\n1 2\\n2 2\\n1 3\\n2 3\\n\", \"7 4 5\\n1 3\\n2 2\\n5 1\\n5 3\\n4 3\\n\", \"10 10 10\\n3 8\\n1 7\\n2 3\\n4 2\\n4 8\\n3 3\\n2 8\\n5 5\\n6 3\\n3 1\\n\", \"3 3 4\\n1 1\\n1 0\\n2 1\\n2 2\\n\", \"10 10 10\\n3 8\\n1 7\\n2 3\\n4 2\\n4 8\\n3 3\\...
There are k sensors located in the rectangular room of size n × m meters. The i-th sensor is located at point (xi, yi). All sensors are located at distinct points strictly inside the rectangle. Opposite corners of the room are located at points (0, 0) and (n, m). Walls of the room are parallel to coordinate axes. At...
0.125
{"tests": "{\"inputs\": [\"4 2 4\\n3 4\\n1 1\\n\", \"5 4 0\\n1 2\\n3 1\\n\", \"50 10 30\\n1 50\\n10 1\\n\", \"1000 913 474\\n34 162\\n566 -1\\n\", \"1000 394 798\\n155 673\\n954 -1\\n\", \"10 4 8\\n1 5\\n4 -1\\n\", \"40 31 14\\n628 1000\\n36 1\\n\", \"5 4 1\\n1 100\\n4 -1\\n\", \"4 2 4\\n3 4\\n2 1\\n\", \"20 5 19\\n163...
The tram in Berland goes along a straight line from the point 0 to the point s and back, passing 1 meter per t1 seconds in both directions. It means that the tram is always in the state of uniform rectilinear motion, instantly turning around at points x = 0 and x = s. Igor is at the point x1. He should reach the point...
0.125
{"tests": "{\"inputs\": [\"4\\n7 7 9 8\\n0 3 -5 4\\n5 0 5 4\\n9 9 -1 -6\\n10 5 -7 -10\\n\", \"4\\n7 7 9 8\\n3 5 7 5\\n7 5 2 4\\n3 3 7 8\\n6 6 3 2\\n\", \"1\\n0 0 10 10\\n5 5 5 5\\n\", \"1\\n0 0 5 5\\n2 5 0 0\\n\", \"4\\n0 49998 2 50002\\n1 50000 0 0\\n1 50000 0 0\\n1 0 0 1\\n1 100000 0 -1\\n\", \"1\\n0 0 100000 100000\...
Igor the analyst fell asleep on the work and had a strange dream. In the dream his desk was crowded with computer mice, so he bought a mousetrap to catch them. The desk can be considered as an infinite plane, then the mousetrap is a rectangle which sides are parallel to the axes, and which opposite sides are located i...
0.5
{"tests": "{\"inputs\": [\"4\\n\", \"25\\n\", \"27\\n\", \"1\\n\", \"97\\n\", \"98\\n\", \"94\\n\", \"21\\n\", \"97\\n\", \"19\\n\", \"3\\n\", \"28\\n\", \"2\\n\", \"8\\n\", \"12\\n\", \"15\\n\", \"91\\n\", \"4\\n\", \"9\\n\", \"23\\n\", \"29\\n\", \"22\\n\", \"96\\n\", \"30\\n\", \"7\\n\", \"100\\n\", \"16\\n\", \"100...
We all know the problem about the number of ways one can tile a 2 × n field by 1 × 2 dominoes. You probably remember that it goes down to Fibonacci numbers. We will talk about some other problem below, there you also are going to deal with tiling a rectangular field with dominoes. You are given a 4 × n rectangular fie...
0
{"tests": "{\"inputs\": [\"2 4\\n1 2\\n3 4\\n\", \"4 6\\n1 3\\n2 3\\n4 6\\n5 6\\n\", \"11 3\\n1 1\\n1 1\\n1 1\\n1 1\\n2 2\\n2 2\\n2 2\\n3 3\\n3 3\\n3 3\\n3 3\\n\", \"43 1319\\n750 1030\\n857 946\\n941 1203\\n407 1034\\n947 1290\\n546 585\\n630 1201\\n72 342\\n693 1315\\n34 719\\n176 1097\\n36 931\\n198 973\\n5 1025\\n8...
Young Teodor enjoys drawing. His favourite hobby is drawing segments with integer borders inside his huge [1;m] segment. One day Teodor noticed that picture he just drawn has one interesting feature: there doesn't exist an integer point, that belongs each of segments in the picture. Having discovered this fact, Teodor ...
0
{"tests": "{\"inputs\": [\"4\\n(99+98)/97\\n(26+4)/10\\n(12+33)/15\\n(5+1)/7\\n\", \"30\\n(89+76)/87\\n(81+78)/18\\n(60+97)/32\\n(41+14)/48\\n(55+65)/27\\n(29+15)/95\\n(64+13)/96\\n(78+30)/75\\n(43+6)/60\\n(69+34)/48\\n(62+2)/97\\n(85+42)/3\\n(4+97)/42\\n(1+18)/39\\n(46+55)/76\\n(22+59)/24\\n(62+81)/98\\n(64+8)/51\\n(9...
The Rebel fleet is on the run. It consists of m ships currently gathered around a single planet. Just a few seconds ago, the vastly more powerful Empire fleet has appeared in the same solar system, and the Rebels will need to escape into hyperspace. In order to spread the fleet, the captain of each ship has independent...
0.125
{"tests": "{\"inputs\": [\"3\\n4\\n2 4 3 5\\n3\\n1 2 3\\n3\\n2 3 1\\n\\nSAMPLE\", \"3\\n4\\n2 4 3 6\\n3\\n1 2 3\\n3\\n2 3 1\\n\\nSAMPLE\", \"3\\n4\\n2 4 5 7\\n1\\n1 2 4\\n3\\n4 6 0\\n\\nSAMPLE\", \"3\\n4\\n1 4 3 2\\n3\\n1 2 0\\n3\\n1 6 0\\n\\nSAMPLE\", \"3\\n4\\n2 4 1 7\\n3\\n1 2 6\\n3\\n4 3 1\\n\\nELPMAS\", \"3\\n4\\n...
Milly and her classmates are standing in a queue to attend the morning assembly of her school. According to the rule any student should stand in his/her proper place in order to make the queue completely visible till the end. Milly being the class monitor is required to make this queue such that students should be stan...
0
{"tests": "{\"inputs\": [\"3\\naabbccdd\\naabcc\\nhackerearthSAMPLE\", \"7\\ninmobi\\nnirvana\\nfoodpanda\\nsoftwareengineer\\nbackenddevloper\\nuideveloper\\ninmobinirvanafoodpandasoftwareengineerbackenddevloperuideveloper\", \"7\\naaaaaabbbbbbfgggggdddjjjdjddaaabdggzzzzyyy\\nzzzzzzzzzaaaaaaaaaaaabbbbbbbbbbccddppqqrrs...
Little Ashish got a lot of strings as his birthday gift. He does not mind getting so many strings for free; in fact, he loves them. But, on noticing all the strings he received as a gift, Little Ashish, who's also a snob and a bit OCD kind of a guy, realizes that he does not like the way in which the strings are arrang...
0
{"tests": "{\"inputs\": [\"3\\n3\\n-2\\n1\\n0\\n2\\n4\\n2\\n0\\n-1\\n-2\\n2\\n2\\n-2\\n-2\\n0\", \"3\\n3\\n-2\\n1\\n0\\n2\\n4\\n2\\n1\\n-1\\n-2\\n2\\n2\\n-2\\n-2\\n0\", \"3\\n3\\n-2\\n1\\n0\\n2\\n4\\n2\\n1\\n-1\\n-3\\n2\\n2\\n-2\\n-2\\n0\", \"3\\n3\\n-2\\n1\\n0\\n2\\n4\\n2\\n1\\n-1\\n-3\\n4\\n2\\n-2\\n-2\\n0\", \"3\\n3...
Taro made a sugoroku so that everyone can play at the children's association event. In order to make the game interesting, I wrote instructions such as "advance 6" and "back 5" in some of the sugoroku squares other than "Furidashi" and "Agari". Turn the roulette wheel to advance as many times as you can, and if an inst...
0
{"tests": "{\"inputs\": [\"380\\n1\\n0\", \"380\\n0\\n0\", \"380\\n2\\n0\", \"380\\n-1\\n0\", \"380\\n-2\\n0\", \"380\\n3\\n0\", \"380\\n4\\n0\", \"380\\n-4\\n0\", \"380\\n5\\n0\", \"380\\n-7\\n0\", \"380\\n10\\n0\", \"380\\n-9\\n0\", \"380\\n43\\n0\", \"380\\n48\\n0\", \"380\\n0\\n-1\", \"380\\n0\\n1\", \"380\\n0\\n-2...
problem Taro often shop at JOI general stores. At JOI general stores, there are enough coins of 500 yen, 100 yen, 50 yen, 10 yen, 5 yen, and 1 yen, and we always pay the change so that the number of coins is the smallest. Create a program to find the number of coins included in the change you receive when Taro goes sh...
0.875
{"tests": "{\"inputs\": [\"2 2\\n! 1 2 1\\n? 1 2\\n2 2\\n! 1 2 1\\n? 2 1\\n4 7\\n! 1 2 100\\n? 2 3\\n! 2 3 100\\n? 2 3\\n? 1 3\\n! 4 3 150\\n? 4 1\\n0 0\", \"2 2\\n! 1 2 1\\n? 1 2\\n2 2\\n! 2 2 1\\n? 2 1\\n4 7\\n! 1 2 100\\n? 2 3\\n! 2 3 100\\n? 2 3\\n? 1 3\\n! 4 3 150\\n? 4 1\\n0 0\", \"2 2\\n! 2 2 1\\n? 1 2\\n2 2\\n!...
In a laboratory, an assistant, Nathan Wada, is measuring weight differences between sample pieces pair by pair. He is using a balance because it can more precisely measure the weight difference between two samples than a spring scale when the samples have nearly the same weight. He is occasionally asked the weight dif...
0.375
{"tests": "{\"inputs\": [\"2\\n1 2 3\\n4 2 3\\n3\\n2 5 2\\n3 3 4\\n5 5 5\\n5\\n1 1 1\\n2 2 2\\n3 3 3\\n4 4 4\\n5 5 5\\n5\\n1 1 1\\n2 1 1\\n3 1 1\\n4 1 1\\n5 1 1\\n10\\n3 1 4\\n1 5 9\\n2 6 5\\n3 5 8\\n9 7 9\\n3 2 3\\n8 4 6\\n2 6 4\\n3 3 8\\n3 2 7\\n0\", \"2\\n1 4 3\\n4 2 3\\n3\\n2 5 2\\n3 3 4\\n5 5 5\\n5\\n1 1 1\\n2 2 2...
Matryoshka Matryoshka is a famous Russian folk craft doll. Matryoshka can be divided into upper and lower parts, and when opened, there is another smaller doll inside. The nesting structure is such that when the small doll that appears is opened, a smaller doll is contained. <image> You found an unusually shaped ma...
0
{"tests": "{\"inputs\": [\"1 1 1 1 1 1 1\\n1 1\\n1 1\", \"2 1 1 1 1 1 1\\n1 1\\n1 1\", \"2 1 1 1 1 1 1\\n1 0\\n1 1\", \"1 1 1 1 2 1 1\\n1 1\\n1 1\", \"2 0 1 1 1 1 1\\n1 1\\n1 1\", \"0 1 1 1 1 1 1\\n1 1\\n1 1\", \"1 1 1 1 1 1 1\\n1 1\\n2 1\", \"1 1 1 1 1 1 1\\n2 1\\n2 1\", \"2 1 1 1 1 1 1\\n2 0\\n1 1\", \"1 2 1 1 1 1 1\...
Cutlet Sandwich In some worlds, there are $ X $ types of "sandwiches", $ Y $ types of "cutlets", and $ Z $ types of "curry" foods. There is a $ N $ type of "cutlet sandwich" in this world, and the $ i $ type of cutlet sandwich is made from the $ A_i $ type of sand and the $ B_i $ type of cutlet. There is also a $ M ...
0.375