info
stringlengths
120
50k
question
stringlengths
504
10.4k
avg@8_qwen3_4b_instruct_2507
float64
0
0.88
{"tests": "{\"inputs\": [\"2\\n0000\", \"5\\n11110101011100110010111100010001\", \"3\\n01100110\", \"2\\n0110\", \"N\\nbit_line\", \"2\\n0001\", \"5\\n11110101011100110010111100010011\", \"3\\n00100110\", \"N\\nbit_ljne\", \"2\\n0011\", \"3\\n00101110\", \"5\\n11110101011100110010111100000010\", \"3\\n00101010\", \"5\\...
Problem Statement Do you know the data structure called BDD (Binary Decision Diagram)? In recent years, ZDD, which has become a hot topic in the video related to Combinatorial Explosion Sister, is a data structure derived from BDD. This problem is a basic implementation of BDD. BDD is a cycleless graph (DAG) that rep...
0
{"tests": "{\"inputs\": [\"3 2\\n1 3 2\", \"3 1\\n1 3 2\", \"3 0\\n1 3 2\", \"3 3\\n1 3 2\", \"2 0\\n1 2 2\", \"2 0\\n1 2 3\", \"2 0\\n1 2 4\", \"2 1\\n1 2 4\", \"2 1\\n1 2 8\", \"2 0\\n1 2 8\", \"2 1\\n1 2 5\", \"2 0\\n1 2 7\", \"2 1\\n1 2 3\", \"2 0\\n1 2 0\", \"2 2\\n1 2 5\", \"3 0\\n1 2 3\", \"2 0\\n1 2 11\", \"2 0...
D: Two Colors Sort problem During the walk, umg found a sequence of length N, P_1, P_2, ..., P_N, which can be made by rearranging 1,2, ..., N. umg can use mysterious powers to exchange places by choosing two different numbers painted in the same color. umg wanted to be able to sort the sequence in ascending order ...
0.5
{"tests": "{\"inputs\": [\"4 3\\n1 1 4\\n0 1 4 1\\n1 1 4\", \"3 5\\n0 1 2 1\\n0 2 3 2\\n0 3 3 3\\n1 1 2\\n1 2 3\", \"4 3\\n1 1 4\\n1 1 4 1\\n1 1 4\", \"4 3\\n1 1 2\\n0 1 4 1\\n1 1 4\", \"3 5\\n0 1 2 1\\n0 2 3 2\\n0 2 3 3\\n1 1 2\\n1 2 3\", \"4 2\\n1 1 4\\n1 1 4 1\\n1 1 0\", \"3 5\\n0 1 1 1\\n0 2 3 2\\n0 2 3 3\\n1 1 2\\...
Write a program which manipulates a sequence A = {a1, a2, . . . , an} with the following operations: * add(s, t, x): add x to as, as+1, ..., at. * getSum(s, t): report the sum of as, as+1, ..., at. Note that the initial values of ai (i = 1, 2, . . . , n) are 0. Constraints * 1 ≤ n ≤ 100000 * 1 ≤ q ≤ 100000 * 1 ≤ ...
0
{"tests": "{\"inputs\": [\"4\\n6 9 15 30\\n\", \"3\\n1 1 1\\n\", \"3\\n1 2 4\\n\", \"10\\n10 8 9 5 4 8 8 10 8 1\\n\", \"2\\n2 4\\n\", \"2\\n3 9\\n\", \"2\\n1 7\\n\", \"3\\n1 100003 100003\\n\", \"3\\n1 14999981 14999981\\n\", \"3\\n2 4 8\\n\", \"100\\n95 94 31 65 35 95 70 78 81 36 69 97 39 28 89 62 36 23 35 21 36 11 65...
Mr. F has n positive integers, a_1, a_2, …, a_n. He thinks the greatest common divisor of these integers is too small. So he wants to enlarge it by removing some of the integers. But this problem is too simple for him, so he does not want to do it by himself. If you help him, he will give you some scores in reward. ...
0
{"tests": "{\"inputs\": [\"2\\n4\\n1.000 31.000\\n12 3\\n20 6\\n30 1\\n5 1\\n3\\n1.000 30.000\\n1 10\\n10 10\\n20 8\\n\", \"2\\n4\\n1.000 31.000\\n12 3\\n20 6\\n30 1\\n5 1\\n3\\n1.000 30.000\\n1 10\\n10 8\\n20 8\\n\", \"2\\n4\\n1.000 31.000\\n12 0\\n20 6\\n31 0\\n5 0\\n3\\n1.000 30.000\\n1 10\\n10 8\\n20 5\\n\", \"2\\n...
Polycarp, Arkady's friend, prepares to the programming competition and decides to write a contest. The contest consists of n problems and lasts for T minutes. Each of the problems is defined by two positive integers a_i and p_i — its difficulty and the score awarded by its solution. Polycarp's experience suggests that...
0
{"tests": "{\"inputs\": [\"7 3 2 2\\n1 2 3 3 2 1 2\\n2 2\\n\", \"13 4 1 3\\n3 2 6 4 1 4 4 7 1 3 3 2 4\\n4 3 4\\n\", \"13 4 3 3\\n3 2 6 4 1 4 4 7 1 3 3 2 4\\n4 3 4\\n\", \"2 2 1 2\\n1 2\\n2 1\\n\", \"2 1 1 1\\n1 2\\n3\\n\", \"10 4 2 4\\n3 2 3 3 3 1 3 3 2 3\\n2 2 2 3\\n\", \"10 3 3 2\\n2 2 3 2 1 3 1 3 2 3\\n2 3\\n\", \"4...
At the first holiday in spring, the town Shortriver traditionally conducts a flower festival. Townsfolk wear traditional wreaths during these festivals. Each wreath contains exactly k flowers. The work material for the wreaths for all n citizens of Shortriver is cut from the longest flowered liana that grew in the tow...
0
{"tests": "{\"inputs\": [\"6\\n3 2 2 2\\n0 0 -2 -2 2 2\\n3 1 4 1\\n0 0 -1 -1 1 1\\n1 1 1 1\\n1 1 1 1 1 1\\n0 0 0 1\\n0 0 0 0 0 1\\n5 1 1 1\\n0 0 -100 -100 0 100\\n1 1 5 1\\n0 0 -100 -100 100 0\\n\", \"1\\n83 75 18 67\\n-4233924 24412104 -4233956 24412104 -4233832 24412181\\n\", \"1\\n0 0 1 1\\n0 0 0 0 0 0\\n\", \"1\\n8...
Alice has a cute cat. To keep her cat fit, Alice wants to design an exercising walk for her cat! Initially, Alice's cat is located in a cell (x,y) of an infinite grid. According to Alice's theory, cat needs to move: * exactly a steps left: from (u,v) to (u-1,v); * exactly b steps right: from (u,v) to (u+1,v); ...
0
{"tests": "{\"inputs\": [\"5 6 1\\n\", \"80 500000000000000000 3200\\n\", \"15 1033532424 1\\n\", \"37 1877886816 1\\n\", \"17 65579254 1\\n\", \"8 703528038 1\\n\", \"83 253746842 3200\\n\", \"5 37 24\\n\", \"19 1146762197 1\\n\", \"100 1000000000000000000 1221\\n\", \"32 504681835 1\\n\", \"9 402260913 1\\n\", \"1 10...
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...
0
{"tests": "{\"inputs\": [\"2\\n\", \"3\\n\", \"1\\n\", \"4\\n\", \"5\\n\", \"4000\\n\", \"3000\\n\", \"42\\n\", \"3555\\n\", \"2999\\n\", \"999\\n\", \"3789\\n\", \"6\\n\", \"133\\n\", \"2000\\n\", \"8\\n\", \"345\\n\", \"3333\\n\", \"2345\\n\", \"1730\\n\", \"3999\\n\", \"555\\n\", \"2500\\n\", \"20\\n\", \"666\\n\", ...
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 ...
0.25
{"tests": "{\"inputs\": [\"0 0 0 1000\\n100 1000\\n-50 0\\n50 0\\n\", \"0 0 5 5\\n3 2\\n-1 -1\\n-1 0\\n\", \"-9680 -440 9680 440\\n969 1000\\n-968 -44\\n-968 -44\\n\", \"-10000 10000 10000 -10000\\n1000 10\\n-890 455\\n-891 454\\n\", \"0 0 0 750\\n25 30\\n0 -1\\n0 24\\n\", \"0 -1000 0 0\\n11 10\\n-10 0\\n10 0\\n\", \"-...
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...
0
{"tests": "{\"inputs\": [\"5 4 2\\n1 2 5\\n1 2 3\\n2 3 4\\n1 4 10\\n1 5\\n\", \"3 1 1\\n1 2 3\\n3\\n\", \"350 10 39\\n2 13 693\\n6 31 482\\n72 312 617\\n183 275 782\\n81 123 887\\n26 120 1205\\n135 185 822\\n64 219 820\\n74 203 874\\n19 167 1422\\n252 332 204 334 100 350 26 14 134 213 32 84 331 215 181 158 99 190 206 2...
Masha wants to open her own bakery and bake muffins in one of the n cities numbered from 1 to n. There are m bidirectional roads, each of whose connects some pair of cities. To bake muffins in her bakery, Masha needs to establish flour supply from some storage. There are only k storages, located in different cities nu...
0.875
{"tests": "{\"inputs\": [\"4\\n3 2 2 3\\n\", \"6\\n4 5 6 3 2 1\\n\", \"10\\n6 8 4 6 7 1 6 3 4 5\\n\", \"50\\n48 37 47 50 46 43 42 46 36 40 45 41 40 50 35 49 37 42 44 45 49 44 31 47 45 49 48 41 45 45 48 20 34 43 43 41 47 50 41 48 38 48 43 48 46 48 32 37 47 45\\n\", \"50\\n1 1 2 1 1 1 1 1 1 1 1 1 2 1 2 1 1 2 1 1 1 1 1 1 ...
Ivan has an array consisting of n elements. Each of the elements is an integer from 1 to n. Recently Ivan learned about permutations and their lexicographical order. Now he wants to change (replace) minimum number of elements in his array in such a way that his array becomes a permutation (i.e. each of the integers fr...
0
{"tests": "{\"inputs\": [\"3\\n1 2\\n1 3\", \"2\\n1 2\", \"5\\n1 2\\n2 3\\n3 4\\n3 5\", \"8\\n1 2\\n2 3\\n3 4\\n3 5\\n3 6\\n6 7\\n6 8\", \"5\\n1 2\\n1 3\\n3 4\\n3 5\", \"5\\n1 2\\n1 4\\n3 4\\n3 5\", \"5\\n1 2\\n1 4\\n5 4\\n3 5\", \"3\\n2 3\\n1 3\", \"5\\n1 2\\n2 3\\n2 4\\n3 5\", \"5\\n1 2\\n1 5\\n3 4\\n3 5\", \"5\\n1 2...
We have a tree with N vertices numbered 1 to N. The i-th edge in this tree connects Vertex a_i and b_i. For each k=1, ..., N, solve the problem below: * Consider writing a number on each vertex in the tree in the following manner: * First, write 1 on Vertex k. * Then, for each of the numbers 2, ..., N in this order, w...
0
{"tests": "{\"inputs\": [\"5 5\\n3949 3774 3598 3469 3424\", \"5 5\\n5960 3774 3598 3469 3424\", \"5 5\\n3949 3774 4045 3469 3424\", \"5 5\\n5960 3774 3598 2384 3424\", \"5 5\\n5960 3774 3598 610 3424\", \"5 5\\n5960 3170 3598 610 3424\", \"5 1\\n5960 3170 3598 610 3424\", \"5 5\\n3949 359 3598 3469 3424\", \"5 5\\n596...
Input Format N K a_1 a_2 a_3 ... a_N Output Format Print the minimum cost in one line. In the end put a line break. Constraints * 1 ≤ K ≤ N ≤ 15 * 1 ≤ a_i ≤ 10^9 Scoring Subtask 1 [120 points] * N = K Subtask 2 [90 points] * N ≤ 5 * a_i ≤ 7 Subtask 3 [140 points] * There are no additional constraint...
0
{"tests": "{\"inputs\": [\"(B&B&f)|(~d&~i&i)|(~v&i&~V)|(~g&~e&o)|(~f&d&~v)|(d&~i&o)|(g&i&~B)|(~i&f&d)|(e&~i&~V)|(~v&f&~d)\\n(S&X&~X)\\n#\", \"(B&B&f)|(~d&~i&i)|(~v&i&~V)|(~g&~e&o)|(~f&d&~v)|(d&~i&o)|(g&i&~B)|(~i&f&d)|(e&~i&~V)|(~v&f&~d)\\n(S&X&~X)\", \"(B&B&f)|(~d&~i&i)|(~v&i&~V)|(&g&~e&o)|(~f&d&~v)|(d&~i&o)|(g&i&~B)|(...
She was worried. The grades are not good. Although she forced her parents to enroll in a dormitory school, her talent never blossomed. Or maybe he didn't have the talent in the first place, but it was possible that he didn't want to think about it as much as possible. So she relied on the dubious brain training materi...
0.25
{"tests": "{\"inputs\": [\"10 10\\n.o....o...\\no.oo......\\n..oo..oo..\\n..o.......\\n..oo..oo..\\n..o...o.o.\\no..U.o....\\noo......oo\\noo........\\noo..oo....\", \"10 1\\nD\\n.\\n.\\n.\\n.\\n.\\n.\\n.\\n.\\no\", \"2 3\\nUo.\\n.oo\", \"2 3\\nUo.\\noo.\", \"2 3\\n.oU\\noo.\", \"10 10\\n.o....o...\\no.oo......\\n..oo....
There is a frog living in a big pond. He loves jumping between lotus leaves floating on the pond. Interestingly, these leaves have strange habits. First, a leaf will sink into the water after the frog jumps from it. Second, they are aligned regularly as if they are placed on the grid points as in the example below. <i...
0.125
{"tests": "{\"inputs\": [\"[[m-y]-[a-o]]\\no 0\\na 1\\ny 2\\nm 0\", \"[[r-i]-[m-e]]\\ne 0\\nr 1\\ni 1\\nm 2\", \"[[r-i]-[m-e]]\\ne 0\\nr 1\\ni 1\\nn 2\", \"[[m-y]-[a-o]]\\nn 0\\na 1\\ny 2\\nm 0\", \"[[r-i]-[m-e]]\\nd 0\\nr 1\\ni 1\\nn 2\", \"[[r-i]-[m-e]]\\nd 0\\nr 1\\ni 1\\nn 3\", \"[[r-i]-[m-e]]\\nd 0\\nr 1\\nh 1\\nn...
In 21XX, an annual programming contest, Japan Algorithmist GrandPrix (JAG) has become one of the most popular mind sports events. JAG is conducted as a knockout tournament. This year, $N$ contestants will compete in JAG. A tournament chart is represented as a string. '[[a-b]-[c-d]]' is an easy example. In this case, t...
0.25
{"tests": "{\"inputs\": [\"3 1\\n1 2 3 4 5 6\\n2 6\\n1\\n\\n2\\n\\n4\\n\\n1\\n\", \"3 1\\n1 2 3 4 5 6\\n1 5\\n2\\n6\\n\\n1\\n\\n3\\n\", \"6 0\\n73 766 748 111 544 978 381 864 195 952 558 970\\n1\\n12 2 8 9 3 10 4 6 7 11 5 1\\n\", \"6 0\\n73 766 748 111 544 978 381 864 195 952 558 970\\n1\\n6 12 10 8 2 3 11 5 7 9 4 1\\n...
Don't you tell me what you think that I can be If you say that Arkady is a bit old-fashioned playing checkers, you won't be right. There is also a modern computer game Arkady and his friends are keen on. We won't discuss its rules, the only feature important to this problem is that each player has to pick a distinct h...
0
{"tests": "{\"inputs\": [\"12\\n)(()(()())()\\n\", \"10\\n()()())(()\\n\", \"6\\n)))(()\\n\", \"100\\n)()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()()(\\n\", \"498\\n)())()(()()))())())()((()())((((()))()((()())()))())())))((()(()())))())())(()()(())())(((()))()))))(((...
This is an easier version of the problem. In this version, n ≤ 500. Vasya is an experienced developer of programming competitions' problems. As all great minds at some time, Vasya faced a creative crisis. To improve the situation, Petya gifted him a string consisting of opening and closing brackets only. Petya believe...
0
{"tests": "{\"inputs\": [\"DOCTOR\\n\", \"SMARTPHONE\\n\", \"REVOLVER\\n\", \"GENIUS\\n\", \"HOLMES\\n\", \"IRENE\\n\", \"MARY\\n\", \"WATSON\\n\", \"AID\\n\", \"TEASE\\n\", \"SUM\\n\", \"KHAKI\\n\", \"WURM\\n\", \"MUG\\n\", \"WEEVIL\\n\", \"WORD\\n\", \"PRODUCT\\n\", \"BRIGHT\\n\", \"SOURPUSS\\n\", \"AI\\n\", \"CUP\\n...
Input The input consists of a single string of uppercase letters A-Z. The length of the string is between 1 and 10 characters, inclusive. Output Output "YES" or "NO". Examples Input GENIUS Output YES Input DOCTOR Output NO Input IRENE Output YES Input MARY Output NO Input SMARTP...
0
{"tests": "{\"inputs\": [\"9 1 10 9 2 9\\n\", \"8 1 10 2 6 5\\n\", \"8 1 10 2 6 4\\n\", \"20 15 25 3 5 7\\n\", \"39438548848582980 11012410395558518 55950951412984721 44 535353 28994364452506991\\n\", \"512151145295769976 499588189546311526 513794826978301613 1000000000000000000 504656 89379401\\n\", \"5005139223211195...
In recent years John has very successfully settled at his new job at the office. But John doesn't like to idly sit around while his code is compiling, so he immediately found himself an interesting distraction. The point of his distraction was to maintain a water level in the water cooler used by other zebras. <image>...
0
{"tests": "{\"inputs\": [\"5\\n4\\n4 5 2 5\\n2\\n0 4\\n5\\n10 8 5 1 4\\n1\\n10000\\n7\\n1 1 1 1 1 1 1\\n\", \"1\\n52\\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\\n\", \"1\\n2\\n1 691\\n\", \"1\\n3\\n1 1 67\\n\", \"1\\n52\\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1...
Polycarp has n friends, the i-th of his friends has a_i candies. Polycarp's friends do not like when they have different numbers of candies. In other words they want all a_i to be the same. To solve this, Polycarp performs the following set of actions exactly once: * Polycarp chooses k (0 ≤ k ≤ n) arbitrary friends...
0.875
{"tests": "{\"inputs\": [\"2 2 2\\n1 1 1\\n1 2 3 4 5 6\\n\", \"0 0 10\\n3 2 3\\n1 2 3 4 5 6\\n\", \"5 5 0\\n3 1 3\\n832224 636838 995053 211585 505442 341920\\n\", \"34271 -17508 -6147\\n456 567 112\\n804178 307516 306399 18981 989216 228388\\n\", \"967 -1346 2551\\n769 331 28\\n458319 885170 877010 533360 723416 24823...
One day Vasya was going home when he saw a box lying on the road. The box can be represented as a rectangular parallelepiped. Vasya needed no time to realize that the box is special, as all its edges are parallel to the coordinate axes, one of its vertices is at point (0, 0, 0), and the opposite one is at point (x1, y1...
0.5
{"tests": "{\"inputs\": [\"100 100 52 50 46 56\\n\", \"9 9 5 5 2 1\\n\", \"71265727 62692710 12444778 3479306 21442685 5463351\\n\", \"81460 7041354 53032 1297536 41496 5748697\\n\", \"99373741 10548319 82293354 9865357 58059929 5328757\\n\", \"1000000000 1000000000 839898171 196274842 131921537 865789406\\n\", \"65618...
You are given a rectangle grid. That grid's size is n × m. Let's denote the coordinate system on the grid. So, each point on the grid will have coordinates — a pair of integers (x, y) (0 ≤ x ≤ n, 0 ≤ y ≤ m). Your task is to find a maximum sub-rectangle on the grid (x1, y1, x2, y2) so that it contains the given point (...
0
{"tests": "{\"inputs\": [\"2\\n2\\n3\\n\", \"5\\n72\\n72\\n30\\n75\\n11\\n\", \"5\\n79\\n149\\n136\\n194\\n124\\n\", \"6\\n885\\n419\\n821\\n635\\n63\\n480\\n\", \"1\\n1000000000\\n\", \"5\\n3\\n6\\n9\\n10\\n5\\n\", \"5\\n5\\n8\\n18\\n17\\n17\\n\", \"1\\n649580447\\n\", \"5\\n7\\n40\\n37\\n25\\n4\\n\", \"5\\n80\\n72\\n...
Let's assume that * v(n) is the largest prime number, that does not exceed n; * u(n) is the smallest prime number strictly greater than n. Find <image>. Input The first line contains integer t (1 ≤ t ≤ 500) — the number of testscases. Each of the following t lines of the input contains integer n (2 ≤ n ≤ ...
0
{"tests": "{\"inputs\": [\"36 5\\n10 16\\n\", \"3 5\\n2 1\\n\", \"2 6\\n2 3\\n\", \"261578849 307610920\\n636335376 399859678\\n\", \"199999978 2\\n599999934 3\\n\", \"894 197\\n325 232\\n\", \"60 1080\\n60 45\\n\", \"720005688 725594112\\n816293376 960007584\\n\", \"1 1\\n918330048 918330048\\n\", \"22295873 586964387...
Polycarpus likes giving presents to Paraskevi. He has bought two chocolate bars, each of them has the shape of a segmented rectangle. The first bar is a1 × b1 segments large and the second one is a2 × b2 segments large. Polycarpus wants to give Paraskevi one of the bars at the lunch break and eat the other one himself...
0
{"tests": "{\"inputs\": [\"3\\n1 6\\n3 4\\n2 5\\n\", \"2\\n4 2\\n1 4\\n\", \"5\\n2 5\\n6 3\\n4 6\\n5 4\\n2 5\\n\", \"30\\n1 200000\\n2 199999\\n3 199998\\n4 199997\\n5 199996\\n200001 399996\\n200002 399997\\n200003 399998\\n200004 399999\\n200005 400000\\n400001 599998\\n400002 599999\\n400003 600000\\n400004 599996\\...
There is an infinite sequence consisting of all positive integers in the increasing order: p = {1, 2, 3, ...}. We performed n swap operations with this sequence. A swap(a, b) is an operation of swapping the elements of the sequence on positions a and b. Your task is to find the number of inversions in the resulting seq...
0
{"tests": "{\"inputs\": [\"4\\nb\\naa\\nhg\\nc\\n.\\n\", \"2\\naa\\na\\n!\\n\", \"2\\naa\\na\\n|\\n\", \"4\\nqhcivbxotj\\nirgxzzxvw\\npxdmcyszvk\\nyyaevcdal\\n~\\n\", \"34\\nobseknnnqk\\ncvyvvbcgb\\nxvmhfzfl\\ngrtp\\nhbcbhj\\nknnnqk\\ncyud\\nkuaeui\\naeui\\nlhpdobsekn\\ncxmigej\\ncvyvvbcgbs\\nuwuu\\nnnqk\\npzcftfrrqp\\...
BerOilGasDiamondBank has branches in n cities, at that n is an even number. The bank management wants to publish a calendar with the names of all those cities written in two columns: the calendar should consist of exactly n / 2 lines of strictly equal length, each of which contains exactly two names and exactly one sep...
0
{"tests": "{\"inputs\": [\"3 1\\n1 2 3\\n2 2\\n\", \"4 2\\n1 2 4 3\\n2 3\\n1 2\\n\", \"6 2\\n3 1 2 6 4 5\\n1 6\\n2 3\\n\", \"100 30\\n65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 65 74 57 115 16 55 88 79 97 21 80 41 56...
Each month Blake gets the report containing main economic indicators of the company "Blake Technologies". There are n commodities produced by the company. For each of them there is exactly one integer in the final report, that denotes corresponding revenue. Before the report gets to Blake, it passes through the hands o...
0.875
{"tests": "{\"inputs\": [\"5 3 2\\nto head\\n0001001\\n\", \"3 2 1\\nto tail\\n0001\\n\", \"50 4 12\\nto tail\\n00000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000001000100000000000000000000000000000000000000010000000010000000000000000000000000000000000000000001\\n\", \...
A stowaway and a controller play the following game. The train is represented by n wagons which are numbered with positive integers from 1 to n from the head to the tail. The stowaway and the controller are initially in some two different wagons. Every minute the train can be in one of two conditions — moving or idle...
0
{"tests": "{\"inputs\": [\"4\\n1 2 1 2\\n\", \"10\\n1 1 2 2 2 1 1 2 2 1\\n\", \"6\\n2 2 2 1 1 1\\n\", \"2\\n1 2\\n\", \"200\\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...
A dragon symbolizes wisdom, power and wealth. On Lunar New Year's Day, people model a dragon with bamboo strips and clothes, raise them with rods, and hold the rods high and low to resemble a flying dragon. A performer holding the rod low is represented by a 1, while one holding it high is represented by a 2. Thus, th...
0
{"tests": "{\"inputs\": [\"8\\n1 2 -2 -3 5 -7 -8 10\\n\\nSAMPLE\", \"8\\n1 2 -2 -3 5 -7 -8 19\\n\\nSAMPLE\", \"8\\n1 2 -2 -6 1 -7 -8 19\\n\\nSAMPLE\", \"8\\n2 2 -1 -12 2 -4 -8 19\\n\\nSAMPLE\", \"8\\n0 2 0 -10 2 -14 -8 8\\n\\nELPMBS\", \"8\\n1 2 -2 -6 5 -7 -8 19\\n\\nSAMPLE\", \"8\\n2 2 -2 -6 1 -7 -8 19\\n\\nSAMPLE\", ...
Given an array a of N integers a1, a2, a3, ... aN you have to find the longest alternating sub-sequence of this array . An alternating sequence b1, b2 ... bk, k ≥ 1 is a sequence that has the 2 following properties: 1.|b1|<|b2|<|b3|<.....<|bk| 2. The signs alternate between adjacent elements, i.e, if b1 > 0 then b2<...
0.75
{"tests": "{\"inputs\": [\"3\\n1 1\\n0 8\\n7 1\", \"2\\n2 2\\n9 1\", \"3\\n1 0\\n0 8\\n7 1\", \"3\\n1 0\\n0 8\\n7 2\", \"3\\n1 0\\n0 10\\n7 2\", \"3\\n1 0\\n0 17\\n7 2\", \"3\\n1 1\\n0 17\\n7 2\", \"3\\n1 1\\n0 4\\n7 2\", \"3\\n1 0\\n0 4\\n7 2\", \"3\\n1 0\\n0 4\\n7 1\", \"3\\n1 0\\n0 3\\n7 1\", \"3\\n1 1\\n0 8\\n7 2\"...
N programmers are going to participate in the preliminary stage of DDCC 20XX. Due to the size of the venue, however, at most 9 contestants can participate in the finals. The preliminary stage consists of several rounds, which will take place as follows: * All the N contestants will participate in the first round. * W...
0
{"tests": "{\"inputs\": [\"1000000000 0\", \"10 9\\n1 2 3 4 5 6 7 8 9\", \"5 2\\n2 3\", \"3 1\\n2\", \"5 0\\n2 3\", \"3 1\\n1\", \"1 0\\n2 3\", \"3 0\\n1\", \"1000100000 0\", \"2 0\\n3 3\", \"0000100000 0\", \"1000101000 0\", \"10 0\\n2 11\", \"6 0\\n9 3\", \"4 1\\n2\", \"10 1\\n2 11\", \"11 0\\n9 3\", \"4 0\\n2\", \"1...
Joisino has a bar of length N, which has M marks on it. The distance from the left end of the bar to the i-th mark is X_i. She will place several squares on this bar. Here, the following conditions must be met: * Only squares with integral length sides can be placed. * Each square must be placed so that its bottom si...
0
{"tests": "{\"inputs\": [\"5\\n6\\n7\\n8\", \"5\\n12\\n7\\n8\", \"5\\n12\\n12\\n8\", \"5\\n12\\n12\\n13\", \"5\\n24\\n12\\n13\", \"5\\n24\\n18\\n13\", \"5\\n24\\n34\\n13\", \"5\\n25\\n34\\n13\", \"5\\n25\\n23\\n13\", \"5\\n25\\n27\\n13\", \"5\\n24\\n27\\n13\", \"5\\n24\\n27\\n2\", \"5\\n24\\n37\\n2\", \"5\\n16\\n37\\n2...
"Fukusekiken" is a popular ramen shop where you can line up. But recently, I've heard some customers say, "I can't afford to have vacant seats when I enter the store, even though I have a long waiting time." I'd like to find out why such dissatisfaction occurs, but I'm too busy to check the actual procession while the ...
0
{"tests": "{\"inputs\": [\"3\\n150 120\\n100 50\\n80 100\", \"3\\n156 120\\n100 50\\n80 100\", \"3\\n52 5\\n100 85\\n37 000\", \"3\\n19 5\\n000 49\\n43 010\", \"3\\n156 120\\n100 50\\n80 000\", \"3\\n156 159\\n100 50\\n80 000\", \"3\\n156 11\\n100 50\\n80 000\", \"3\\n156 22\\n100 50\\n80 000\", \"3\\n156 22\\n100 50\\...
There was a powerful school where powerful people gathered. At the athletic meet of the powerful school, powerful people march in a formation. While the powerhouses always want to show off their power, most of them don't want to walk on their own. So I thought that some of them would be at the bottom, and a lot of peo...
0
{"tests": "{\"inputs\": [\"6\\n5\\n1 2\\n1 3\\n3 4\\n2 3\\n4 5\\n6\\n5\\n2 3\\n3 4\\n4 5\\n5 6\\n2 5\\n0\\n0\", \"6\\n5\\n1 2\\n1 3\\n3 4\\n2 3\\n4 5\\n6\\n5\\n2 3\\n3 4\\n4 5\\n5 6\\n2 6\\n0\\n0\", \"6\\n5\\n1 2\\n1 3\\n3 4\\n2 3\\n4 5\\n6\\n5\\n2 3\\n3 4\\n1 5\\n5 6\\n2 6\\n0\\n0\", \"6\\n5\\n1 2\\n1 3\\n3 5\\n2 3\\n...
problem You decide to invite your friends of the school and your friends of a friend to the Christmas party. The number of students in your school is n, and each student is assigned a number from 1 to n. Your number is 1. You have a list of who and who are your friends. Based on this list, create a program that asks f...
0
{"tests": "{\"inputs\": [\"2 2 1\\n1 2 1\\n1\\n2\\n4 3 2\\n1 2 1\\n1 3 2\\n1 4 3\\n2\\n3\\n4\\n0 0 0\", \"2 2 0\\n1 2 1\\n1\\n2\\n4 3 2\\n1 2 1\\n1 3 2\\n1 4 3\\n2\\n3\\n4\\n0 0 0\", \"2 2 1\\n1 2 1\\n1\\n2\\n4 3 2\\n1 2 1\\n1 3 2\\n1 4 2\\n2\\n3\\n4\\n0 0 0\", \"2 2 1\\n1 2 1\\n1\\n2\\n4 3 2\\n1 2 1\\n1 3 4\\n1 4 3\\n...
There is a tree that has n nodes and n-1 edges. There are military bases on t out of the n nodes. We want to disconnect the bases as much as possible by destroying k edges. The tree will be split into k+1 regions when we destroy k edges. Given the purpose to disconnect the bases, we only consider to split in a way that...
0
{"tests": "{\"inputs\": [\"5 5\\n1 1\\n1 2\\n1 2\\n1 3\\n1 3\", \"3 10\\n1 6\\n5 10\\n0 5\", \"6 5\\n1 1\\n1 2\\n1 2\\n1 3\\n1 3\", \"3 10\\n1 9\\n5 10\\n0 5\", \"3 7\\n1 9\\n5 10\\n0 5\", \"6 5\\n0 1\\n1 2\\n1 2\\n2 3\\n1 3\", \"3 18\\n1 6\\n5 5\\n0 5\", \"0 8\\n1 2\\n5 20\\n0 5\", \"6 6\\n0 0\\n1 2\\n2 0\\n0 3\\n2 2\...
Problem Gaccho loses motivation as the final exam approaches and often misses school. There are N days left until the final exam. Gaccho's motivation on day i is Xi, and the motivation needed to go to school on day i is Yi. Gaccho goes to school only on days when Xi ≥ Yi. Haji, who was worried about Gaccho, decided to...
0
{"tests": "{\"inputs\": [\"1 2 3 4 5 6\\n6 5 4 3 2 1\", \"1 2 3 4 5 6\\n6 2 4 3 5 1\", \"1 2 3 2 5 6\\n6 5 4 3 2 1\", \"1 2 3 2 5 6\\n6 1 4 3 2 1\", \"1 2 3 2 5 6\\n6 0 4 3 2 1\", \"1 2 3 2 5 6\\n6 0 4 3 4 1\", \"1 2 3 2 7 6\\n6 0 4 3 4 1\", \"1 2 3 2 7 3\\n6 0 4 3 4 1\", \"1 2 2 2 7 6\\n6 0 4 3 4 1\", \"1 2 2 2 7 9\\n...
Write a program which reads the two dices constructed in the same way as Dice I, and determines whether these two dices are identical. You can roll a dice in the same way as Dice I, and if all integers observed from the six directions are the same as that of another dice, these dices can be considered as identical. Co...
0.375
{"tests": "{\"inputs\": [\"bwwwbwwbw\\n\", \"bwwbwwb\\n\", \"bwbw\\n\", \"www\\n\", \"wbwbwbwbwb\\n\", \"bwbwbbbbwb\\n\", \"bww\\n\", \"bwb\\n\", \"bwbwwwwwwwwbwb\\n\", \"wbwbwb\\n\", \"wbwb\\n\", \"bwwwwwbbbbbw\\n\", \"bwbwbw\\n\", \"wbbwbw\\n\", \"bbbbwbwwbbwwwwwbbbwb\\n\", \"wwwwb\\n\", \"bw\\n\", \"bwbwbwbwbwbw\\n\...
Is there anything better than going to the zoo after a tiresome week at work? No wonder Grisha feels the same while spending the entire weekend accompanied by pretty striped zebras. Inspired by this adventure and an accidentally found plasticine pack (represented as a sequence of black and white stripes), Grisha now ...
0.125
{"tests": "{\"inputs\": [\"3 1\\n1 3\\n2 3\\n\", \"14 2\\n1 4\\n2 4\\n3 4\\n4 13\\n10 5\\n11 5\\n12 5\\n14 5\\n5 13\\n6 7\\n8 6\\n13 6\\n9 6\\n\", \"2 1\\n1 2\\n\", \"8 1\\n8 2\\n2 5\\n5 1\\n7 2\\n2 4\\n3 5\\n5 6\\n\", \"5 1\\n4 1\\n3 1\\n5 1\\n1 2\\n\", \"25 2\\n1 2\\n1 3\\n1 4\\n2 5\\n2 6\\n2 7\\n3 8\\n3 9\\n3 10\\n4...
Someone give a strange birthday present to Ivan. It is hedgehog — connected undirected graph in which one vertex has degree at least 3 (we will call it center) and all other vertices has degree 1. Ivan thought that hedgehog is too boring and decided to make himself k-multihedgehog. Let us define k-multihedgehog as fol...
0.125
{"tests": "{\"inputs\": [\"4\\n\", \"2\\n\", \"1\\n\", \"677\\n\", \"9\\n\", \"30238\\n\", \"7635\\n\", \"47539\\n\", \"14\\n\", \"2048\\n\", \"5714\\n\", \"20\\n\", \"78088\\n\", \"93378\\n\", \"11\\n\", \"8\\n\", \"91402\\n\", \"86632\\n\", \"64444\\n\", \"80555\\n\", \"91568\\n\", \"75232\\n\", \"2864\\n\", \"64\\n\...
Vivek initially has an empty array a and some integer constant m. He performs the following algorithm: 1. Select a random integer x uniformly in range from 1 to m and append it to the end of a. 2. Compute the greatest common divisor of integers in a. 3. In case it equals to 1, break 4. Otherwise, return to...
0
{"tests": "{\"inputs\": [\"5 5\\n1 5 4\\n1 3 1\\n1 3 4\\n3 1 5\\n4 2 5\\n\", \"7 4\\n2 4 3\\n1 2 0\\n2 2 0\\n1 2 1\\n4 3 5\\n1 2 2\\n4 2 0\\n\", \"3 4\\n2 4 7\\n3 3 1\\n2 2 9\\n\", \"8 5\\n2 2 91\\n5 1 97\\n5 1 36\\n5 4 19\\n2 5 50\\n4 2 1\\n1 4 9\\n3 2 32\\n\", \"2 100000000\\n2 1 3\\n99999999 100000000 100000000\\n\"...
And now the numerous qualifying tournaments for one of the most prestigious Russian contests Russian Codec Cup are over. All n participants who have made it to the finals found themselves in a huge m-floored 108-star hotel. Of course the first thought to come in a place like this is "How about checking out the elevator...
0.125
{"tests": "{\"inputs\": [\"4\\n3 2\\n3 1\\n8 6\\n8 7 6 5 3 2\\n9 6\\n9 8 5 4 3 1\\n1 1\\n1\\n\", \"1\\n3 2\\n3 2\\n\", \"28\\n8 4\\n8 7 6 3\\n8 5\\n8 7 6 3 1\\n8 5\\n8 7 6 3 2\\n8 6\\n8 7 6 3 2 1\\n8 4\\n8 7 6 4\\n8 5\\n8 7 6 4 1\\n8 5\\n8 7 6 4 2\\n8 6\\n8 7 6 4 2 1\\n8 5\\n8 7 6 4 3\\n8 6\\n8 7 6 4 3 1\\n8 6\\n8 7 6 ...
You are playing a game where your character should overcome different obstacles. The current problem is to come down from a cliff. The cliff has height h, and there is a moving platform on each height x from 1 to h. Each platform is either hidden inside the cliff or moved out. At first, there are n moved out platforms...
0
{"tests": "{\"inputs\": [\"3\\n2 4\\n1 1\\n1 1\\n1 2\\n2 1\\n2 2\\n\\n3 4\\n1 1 1\\n1 1\\n1 2\\n2 2\\n2 3\\n\\n4 7\\n36 31 96 29\\n1 2\\n1 3\\n1 4\\n2 2\\n2 4\\n3 1\\n4 3\\n\", \"1\\n100 27\\n10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10...
Wu got hungry after an intense training session, and came to a nearby store to buy his favourite instant noodles. After Wu paid for his purchase, the cashier gave him an interesting task. You are given a bipartite graph with positive integers in all vertices of the right half. For a subset S of vertices of the left ha...
0
{"tests": "{\"inputs\": [\"500 10\\n69 477 122\\n73 186 235\\n341 101 145\\n372 77 497\\n390 117 440\\n494 471 37\\n522 300 498\\n682 149 379\\n821 486 359\\n855 157 386\\n\", \"10 4\\n1 2 1\\n5 10 9\\n13 8 8\\n15 9 9\\n\", \"6 9\\n1 2 6\\n7 5 1\\n8 5 5\\n10 3 1\\n12 4 4\\n13 6 2\\n17 6 6\\n20 1 4\\n21 5 4\\n\", \"10 1...
You are a paparazzi working in Manhattan. Manhattan has r south-to-north streets, denoted by numbers 1, 2,…, r in order from west to east, and r west-to-east streets, denoted by numbers 1,2,…,r in order from south to north. Each of the r south-to-north streets intersects each of the r west-to-east streets; the interse...
0.5
{"tests": "{\"inputs\": [\"3\\n3\\n.X.\\nXXX\\n.X.\\n6\\nXX.XXX\\nXXXXXX\\nXXX.XX\\nXXXXXX\\nXX.X.X\\nXXXXXX\\n5\\nXXX.X\\n.X..X\\nXXX.X\\n..X..\\n..X..\\n\", \"1\\n6\\nXXXXXX\\nXXXXXX\\nXX..XX\\nXX..XX\\nXXXXXX\\nXXXXXX\\n\", \"3\\n3\\n.X.\\nXXX\\n.X.\\n6\\nXX.XXX\\nXXXXXX\\nXXX.XX\\nXXXXXX\\nXX.X.X\\nXXXXXX\\n5\\nXXX...
The only difference between the easy and hard versions is that tokens of type O do not appear in the input of the easy version. Errichto gave Monogon the following challenge in order to intimidate him from taking his top contributor spot on Codeforces. In a Tic-Tac-Toe grid, there are n rows and n columns. Each cell ...
0
{"tests": "{\"inputs\": [\"5\\n2 3 3 1 1\\n\", \"3\\n1 2 1\\n\", \"100\\n85 50 17 89 65 89 5 20 86 26 16 21 85 14 44 31 87 31 6 2 48 67 8 80 79 1 48 36 97 1 5 30 79 50 78 12 2 55 76 100 54 40 26 81 97 96 68 56 87 14 51 17 54 37 52 33 69 62 38 63 74 15 62 78 9 19 67 2 60 58 93 60 18 96 55 48 34 7 79 82 32 58 90 67 20 50...
Petya loves football very much, especially when his parents aren't home. Each morning he comes to the yard, gathers his friends and they play all day. From time to time they have a break to have some food or do some chores (for example, water the flowers). The key in football is to divide into teams fairly before the ...
0
{"tests": "{\"inputs\": [\"2\\n4\\n1\\n1\\n2\\n3\\n9\\n1\\n1\\n1\\n2\\n2\\n1\\n2\\n1\\n2\\n\", \"2\\n4\\n1\\n1\\n2\\n3\\n9\\n1\\n1\\n1\\n2\\n2\\n1\\n2\\n1\\n2\\n\", \"7\\n1\\n1\\n2\\n1\\n1\\n2\\n1\\n2\\n3\\n1\\n1\\n1\\n3\\n1\\n1\\n2\\n3\\n1\\n2\\n1\\n3\\n1\\n2\\n3\\n\", \"10\\n4\\n1\\n1\\n1\\n1\\n4\\n1\\n1\\n1\\n2\\n4\...
<image> William is a huge fan of planning ahead. That is why he starts his morning routine by creating a nested list of upcoming errands. A valid nested list is any list which can be created from a list with one item "1" by applying some operations. Each operation inserts a new item into the list, on a new line, just...
0
{"tests": "{\"inputs\": [\"2 10 1\\n1 9\\n5 5\\n1 2\\n\", \"2 10 0\\n5 2\\n4 2\\n\", \"2 10 0\\n4 2\\n4 2\\n\", \"2 1000000000 2\\n1000000000 999999999\\n999999999 1000000000\\n1 2\\n2 1\\n\", \"1 1000000000 0\\n999999999\\n1000000000\\n\", \"1 1000000000 0\\n1000000000\\n1000000000\\n\", \"10 1 3\\n0 1 0 1 0 1 0 1 0 1...
A system of n vessels with water is given. Several pairs of vessels are connected by tubes with transfusion mechanisms. One may transfer an integer amount of liters of water between two vessels connected by such tube (tube works in both directions). There might be multiple tubes between two vessels. Total number of tub...
0
{"tests": "{\"inputs\": [\"2\\n\", \"4\\n\", \"1\\n\", \"3\\n\", \"102513046\\n\", \"685146646\\n\", \"11\\n\", \"10\\n\", \"752887969\\n\", \"341796022\\n\", \"585325539\\n\", \"930971393\\n\", \"802030518\\n\", \"18\\n\", \"702209411\\n\", \"7\\n\", \"0\\n\", \"536870912\\n\", \"335521569\\n\", \"13\\n\", \"985629174...
Fox Ciel studies number theory. She thinks a non-empty set S contains non-negative integers is perfect if and only if for any <image> (a can be equal to b), <image>. Where operation xor means exclusive or operation (http://en.wikipedia.org/wiki/Exclusive_or). Please calculate the number of perfect sets consisting of ...
0
{"tests": "{\"inputs\": [\"1\\n\", \"2\\n\", \"0\\n\", \"-1\\n\", \"-2\\n\", \"-3\\n\", \"-6\\n\", \"-8\\n\", \"-14\\n\", \"-17\\n\", \"-30\\n\", \"4\\n\", \"8\\n\", \"11\\n\", \"19\\n\", \"6\\n\", \"3\\n\", \"5\\n\", \"10\\n\", \"17\\n\", \"-4\\n\", \"-5\\n\", \"-9\\n\", \"-10\\n\", \"9\\n\", \"18\\n\", \"34\\n\", \"4...
You are given a mysterious language (codenamed "Secret") available in "Custom Invocation" tab. Figure out what this language is and write a program which prints its name. Note that the program must be written in this language. Input This program has only one test (your program doesn't have to read anything). Output ...
0
{"tests": "{\"inputs\": [\"5 2 4 1\\n\", \"5 2 4 2\\n\", \"5 3 4 1\\n\", \"5000 2314 1234 5000\\n\", \"3 2 3 1\\n\", \"4988 3629 4106 4488\\n\", \"300 1 300 300\\n\", \"2 1 2 1\\n\", \"4999 1 2 4999\\n\", \"3999 2 10 5000\\n\", \"10 1 4 4999\\n\", \"22 9 18 3\\n\", \"10 1 10 2\\n\", \"5 3 2 2\\n\", \"50 5 2 50\\n\", \"...
Imagine that you are in a building that has exactly n floors. You can move between the floors in a lift. Let's number the floors from bottom to top with integers from 1 to n. Now you're on the floor number a. You are very bored, so you want to take the lift. Floor number b has a secret lab, the entry is forbidden. Howe...
0
{"tests": "{\"inputs\": [\"3\\n10 1\\n20 2\\n30 3\\n\", \"1\\n5 10\\n\", \"3\\n3 1\\n2 2\\n4 3\\n\", \"4\\n573 7\\n169 9\\n447 7\\n947 3\\n\", \"10\\n489 685\\n857 870\\n736 221\\n687 697\\n166 360\\n265 200\\n738 519\\n393 760\\n66 176\\n798 160\\n\", \"3\\n203 145\\n780 692\\n992 713\\n\", \"3\\n627 286\\n37 65\\n53 ...
Many years have passed, and n friends met at a party again. Technologies have leaped forward since the last meeting, cameras with timer appeared and now it is not obligatory for one of the friends to stand with a camera, and, thus, being absent on the photo. Simply speaking, the process of photographing can be describ...
0
{"tests": "{\"inputs\": [\"10 1\\n\", \"4 3\\n\", \"31 1899100\\n\", \"16 747\\n\", \"44 863791309\\n\", \"25 121393\\n\", \"15 463\\n\", \"36 7074882\\n\", \"50 20365011074\\n\", \"34 2412850\\n\", \"39 68773650\\n\", \"24 47430\\n\", \"18 1809\\n\", \"19 859\\n\", \"10 89\\n\", \"6 10\\n\", \"32 1314567\\n\", \"2 2\\...
Let's define the permutation of length n as an array p = [p1, p2, ..., pn] consisting of n distinct integers from range from 1 to n. We say that this permutation maps value 1 into the value p1, value 2 into the value p2 and so on. Kyota Ootori has just learned about cyclic representation of a permutation. A cycle is a...
0
{"tests": "{\"inputs\": [\"7 1\\n1 0 1 1 0 0 0\\n1 2\\n1 3\\n2 4\\n2 5\\n3 6\\n3 7\\n\", \"4 1\\n1 1 0 0\\n1 2\\n1 3\\n1 4\\n\", \"5 2\\n1 1 0 1 1\\n1 2\\n2 3\\n3 4\\n4 5\\n\", \"6 1\\n1 0 1 1 0 0\\n1 2\\n1 3\\n1 4\\n1 5\\n1 6\\n\", \"2 1\\n1 1\\n2 1\\n\", \"3 2\\n1 1 1\\n1 2\\n2 3\\n\", \"12 3\\n1 0 1 0 1 1 1 1 0 0 0 ...
Kefa decided to celebrate his first big salary by going to the restaurant. He lives by an unusual park. The park is a rooted tree consisting of n vertices with the root at vertex 1. Vertex 1 also contains Kefa's house. Unfortunaely for our hero, the park also contains cats. Kefa has already found out what are the ver...
0
{"tests": "{\"inputs\": [\"6 2\\n10.245\\n\", \"3 100\\n9.2\\n\", \"6 1\\n10.245\\n\", \"13 1\\n761.044449428\\n\", \"35 8\\n984227318.2031144444444444494637612\\n\", \"31 15\\n2707786.24030444444444444724166\\n\", \"3 1\\n0.1\\n\", \"9 2\\n23999.448\\n\", \"12 5\\n872.04488525\\n\", \"320 142\\n2704701300865535.432223...
Efim just received his grade for the last test. He studies in a special school and his grade can be equal to any positive decimal fraction. First he got disappointed, as he expected a way more pleasant result. Then, he developed a tricky plan. Each second, he can ask his teacher to round the grade at any place after th...
0
{"tests": "{\"inputs\": [\"5 2\\n5 3 -2 1 -1 5\\n3 -5 2 5\\n\", \"4 2\\n1 -3\\n4 -2 3 2 -3\\n\", \"7 2\\n3 -1 6 7\\n7 -5 4 2 4 7 -3 4\\n\", \"10 1\\n2 4 4\\n\", \"5 1\\n2 -1 -1\\n\", \"3 1\\n3 1 1 2\\n\", \"10000 1\\n1 2550\\n\", \"1 1\\n1 1\\n\", \"2 1\\n2 2 2\\n\", \"4 1\\n3 1 1 -1\\n\", \"4 2\\n2 1 -1\\n1 1\\n\", \"...
Since the giant heads have appeared in the sky all humanity is in danger, so all Ricks and Mortys from all parallel universes are gathering in groups to find a solution to get rid of them. There are n parallel universes participating in this event (n Ricks and n Mortys). I. e. each of n universes has one Rick and one...
0.625
{"tests": "{\"inputs\": [\"0.0\\n\", \"1.50\\n\", \"12345678901234567890.1\\n\", \"2.71828182845904523536\\n\", \"1.49\\n\", \"3.14159265358979323846\\n\", \"123456789123456789.999\\n\", \"7.6\\n\", \"1950583094879039694852660558765931995628486712128191844305265555887022812284005463780616067.500000000000000000000000000...
In a far away kingdom lived the King, the Prince, the Shoemaker, the Dressmaker and many other citizens. They lived happily until great trouble came into the Kingdom. The ACMers settled there. Most damage those strange creatures inflicted upon the kingdom was that they loved high precision numbers. As a result, the Ki...
0.75
{"tests": "{\"inputs\": [\"3\\n4 2\\n6 6\\n3 4\\n\\nSAMPLE\", \"12\\n1 3\\n4 6\\n7 9\\n2 3\\n5 6\\n8 9\\n5 5\\n46 46\\n89 89\\n96 96\\n94 94\\n79 97\", \"3\\n4 2\\n11 6\\n3 4\\n\\nSAMPLE\", \"3\\n4 4\\n7 8\\n3 10\\n\\nSAMPLE\", \"3\\n4 6\\n7 8\\n3 0\\n\\nSAMPLF\", \"3\\n4 6\\n7 8\\n2 0\\n\\nSAMPLF\", \"3\\n1 6\\n4 2\\n...
Rahul likes to play with mathematics and geometry and when it comes for 2D geometry, he just can’t stop himself doing experiments. While working with 2D geometry, he came up with an interesting pattern of numbers as shown below. He started at the point (0, 0) and wrote all non-negative integers. They are- (0, 0) – 0 ...
0.125
{"tests": "{\"inputs\": [\"2\\n2 1\\n3 2\\n\\nSAMPLE\", \"2\\n2 1\\n3 2\", \"2\\n2 1\\n3 1\\n\\nSAMPLE\", \"2\\n2 1\\n4 2\", \"2\\n2 1\\n7 2\", \"2\\n4 1\\n3 1\\n\\nS@MPLE\", \"2\\n4 1\\n5 1\\n\\nFLPS@M\", \"2\\n2 1\\n4 3\", \"2\\n4 1\\n7 2\", \"2\\n4 2\\n3 2\\n\\nSANPLE\", \"2\\n4 1\\n7 1\", \"2\\n4 2\\n6 2\\n\\nSANPL...
Everyone has got to know that HELL and Printf{} use cheats while playing Counter-Strike 1.6. Everyone decides to give them a punishment. They are going to be made to paint all the rooms of the ground floor of the hostel. There are a total of N rooms on the ground floor arranged in a single row side by side numbered f...
0.875
{"tests": "{\"inputs\": [\"8 5\\n3 6 2\\n1 4 7\\n3 8 3\\n2 2 2\\n4 5 1\", \"200000 1\\n123 456 7\", \"149688 1\\n123 456 7\", \"8 5\\n3 6 2\\n1 4 7\\n3 8 4\\n2 2 2\\n4 5 1\", \"200000 1\\n123 348 7\", \"70116 1\\n123 456 7\", \"8 5\\n3 6 2\\n1 4 7\\n3 8 4\\n2 2 1\\n4 5 1\", \"70116 1\\n134 456 7\", \"8 5\\n5 6 2\\n1 4 ...
You have a string S of length N. Initially, all characters in S are `1`s. You will perform queries Q times. In the i-th query, you are given two integers L_i, R_i and a character D_i (which is a digit). Then, you must replace all characters from the L_i-th to the R_i-th (inclusive) with D_i. After each query, read th...
0.375
{"tests": "{\"inputs\": [\"5\\n11 1 2 4 8\\n11 1 2 2 8\\n32 10 8 5 4\\n29384293847243 454353412 332423423 934923490 1\\n900000000000000000 332423423 454353412 934923490 987654321\", \"5\\n11 1 4 4 8\\n11 1 2 2 8\\n32 10 8 5 4\\n29384293847243 454353412 332423423 934923490 1\\n900000000000000000 332423423 454353412 9349...
You start with the number 0 and you want to reach the number N. You can change the number, paying a certain amount of coins, with the following operations: * Multiply the number by 2, paying A coins. * Multiply the number by 3, paying B coins. * Multiply the number by 5, paying C coins. * Increase or decrease the num...
0
{"tests": "{\"inputs\": [\"4\\n1 2\\n2 3\\n3 4\\n8 6 6 8\", \"15\\n9 10\\n9 15\\n15 4\\n4 13\\n13 2\\n13 11\\n2 14\\n13 6\\n11 1\\n1 12\\n12 3\\n12 7\\n2 5\\n14 8\\n1154 890 2240 883 2047 2076 1590 1104 1726 1791 1091 1226 841 1000 901\", \"5\\n1 2\\n1 3\\n1 4\\n1 5\\n10 13 16 19 22\", \"15\\n9 10\\n9 15\\n15 4\\n4 13\...
Snuke found a record of a tree with N vertices in ancient ruins. The findings are as follows: * The vertices of the tree were numbered 1,2,...,N, and the edges were numbered 1,2,...,N-1. * Edge i connected Vertex a_i and b_i. * The length of each edge was an integer between 1 and 10^{18} (inclusive). * The sum of the ...
0.25
{"tests": "{\"inputs\": [\"4 2 3\\n0 1 3 1\\n1 1 4 1\\n2 0 2 2\", \"5 5 7\\n0 0 2 4\\n2 3 4 5\\n3 5 5 2\\n5 5 5 4\\n0 3 5 1\\n2 2 4 4\\n0 5 4 1\", \"2 2 4\\n0 0 2 2\\n2 0 0 1\\n0 2 1 2\\n1 1 2 1\", \"1 1 2\\n0 0 1 1\\n1 0 0 1\", \"4 3 3\\n0 1 3 1\\n1 1 4 1\\n2 0 2 2\", \"2 2 4\\n0 0 2 2\\n2 0 0 1\\n0 2 1 2\\n1 1 2 0\",...
Snuke is playing a puzzle game. In this game, you are given a rectangular board of dimensions R × C, filled with numbers. Each integer i from 1 through N is written twice, at the coordinates (x_{i,1},y_{i,1}) and (x_{i,2},y_{i,2}). The objective is to draw a curve connecting the pair of points where the same integer i...
0
{"tests": "{\"inputs\": [\"6 6\\n2 4\\n6 2\\n0 0 0 0 1 0\\n0 1 0 0 0 0\\n0 1 0 0 0 0\\n0 0 0 1 0 0\\n0 0 0 0 0 1\\n0 0 0 0 0 0\\n3 3\\n1 1\\n3 3\\n0 0 0\\n0 1 0\\n0 0 0\\n0 0\", \"6 6\\n2 4\\n6 2\\n0 0 0 0 1 0\\n0 1 1 0 0 0\\n0 1 0 0 0 0\\n0 0 0 1 0 0\\n0 0 0 0 0 1\\n0 0 0 0 0 0\\n3 3\\n1 1\\n3 3\\n0 0 0\\n0 1 0\\n0 0 ...
Takayuki and Kazuyuki are good twins, but their behavior is exactly the opposite. For example, if Takayuki goes west, Kazuyuki goes east, and if Kazuyuki goes north, Takayuki goes south. Currently the two are in a department store and are in different locations. How can two people who move in the opposite direction mee...
0
{"tests": "{\"inputs\": [\"8 3\\n0 0 0 0 0 0 0 1\\n2 3 0 1 4 0 0 1\\n3 3 0 0 0 0 0 4\\n9 9 1 9\\n4 4\\n3 3 4 0\\n1 2 4 4\\n1 1 1 0\\n0 2 4 4\\n8 7 2 1\\n2 8\\n2 2\\n4 1\\n0 4\\n1 3\\n1 0\\n2 1\\n0 3\\n1 4\\n1 9 3 1\\n0 0\", \"8 3\\n0 0 0 0 0 0 0 1\\n2 3 0 1 4 0 0 1\\n3 3 0 0 0 0 0 4\\n9 9 1 9\\n4 4\\n3 3 4 0\\n1 2 4 4\...
Let's play a game using a robot on a rectangular board covered with a square mesh (Figure D-1). The robot is initially set at the start square in the northwest corner facing the east direction. The goal of this game is to lead the robot to the goal square in the southeast corner. <image> Figure D-1: Example of a boar...
0
{"tests": "{\"inputs\": [\"11\\n0\\n0\\n-2\\n0\\n-4\\n1\\n-1\\n2\\n0\\n0\\n0\", \"12\\n0\\n0\\n7\\n0\\n2\\n0\\n0\\n3\\n-6\\n-2\\n1\\n0\", \"8\\n0\\n4\\n-1\\n1\\n-2\\n-2\\n0\\n0\", \"11\\n0\\n1\\n-2\\n0\\n-4\\n1\\n-1\\n2\\n0\\n0\\n0\", \"12\\n0\\n0\\n7\\n0\\n2\\n0\\n0\\n3\\n-5\\n-2\\n1\\n0\", \"8\\n0\\n4\\n-1\\n1\\n0\\n...
All space-time unified dimension sugoroku tournament. You are representing the Earth in the 21st century in the tournament, which decides only one Sugoroku absolute champion out of more than 500 trillion participants. The challenge you are currently challenging is one-dimensional sugoroku with yourself as a frame. Sta...
0.375
{"tests": "{\"inputs\": [\"5 7\\n\\n.#g..#\\n.###.#\\ns....#\\n\\n{T{~C^}>}\", \"5 3\\n###\\n#g#\\n#.#\\n#s#\\n###\\n^<^<vv\", \"5 7\\n\\n.#g..#\\n.###.#\\ns....#\\n\\n{T{~C^}<}\", \"5 3\\n\\ng#\\n.#\\ns#\\n\\n^<^<vv\", \"5 11\\n\\n.#g..#\\n.###.#\\ns....#\\n\\n{T{~C^}>}\", \"5 3\\n#$#\\n#g#\\n#.#\\n#s#\\n###\\n^<^<vv\...
A robot, a wall, and a goal are installed on the board, and a program that describes the behavior pattern of the robot is given. The given program is represented by the following EBNF. Program: = {statement}; Statement: = if statement | while statement | action statement; if statement: = "[", condition, program, "]"...
0
{"tests": "{\"inputs\": [\"1\\n3 2 2\", \"1\\n3 2 3\", \"1\\n3 3 3\", \"1\\n6 3 3\", \"1\\n6 4 3\", \"1\\n6 4 6\", \"1\\n3 1 3\", \"1\\n9 3 3\", \"1\\n6 5 3\", \"1\\n8 4 6\", \"1\\n12 3 3\", \"1\\n8 2 6\", \"1\\n3 1 2\", \"1\\n12 3 0\", \"1\\n8 2 8\", \"1\\n8 3 8\", \"1\\n12 4 1\", \"1\\n8 1 8\", \"1\\n12 7 1\", \"1\\n...
Chef has a special affection for sets of binary strings of equal length which have same numbers of 1's. Given three integers n, k and m, your task is to find the the lexicographically m^th smallest string among strings which have length n and have k 1's. If no such string exists output -1. Tips: To see what lexic...
0
{"tests": "{\"inputs\": [\"4\\n1 1000\\n1024 1024\\n65536 65536\\n999999 1000001\\n\", \"4\\n1 1010\\n1024 1024\\n65536 65536\\n999999 1000001\\n\", \"4\\n1 1010\\n1024 1024\\n65536 65536\\n967877 1000001\\n\", \"4\\n1 1010\\n217 1024\\n65536 65536\\n967877 1000001\\n\", \"4\\n1 1010\\n217 1024\\n65536 65536\\n967877 1...
Let's call some positive integer classy if its decimal representation contains no more than 3 non-zero digits. For example, numbers 4, 200000, 10203 are classy and numbers 4231, 102306, 7277420000 are not. You are given a segment [L; R]. Count the number of classy integers x such that L ≤ x ≤ R. Each testcase contain...
0
{"tests": "{\"inputs\": [\"4 3\\n###\\n###\\n###\\n###\\n\", \"5 7\\n.......\\n.#####.\\n.#.#.#.\\n.#####.\\n.......\\n\", \"3 3\\n###\\n###\\n###\\n\", \"3 3\\n###\\n#.#\\n###\\n\", \"3 4\\n####\\n#.##\\n####\\n\", \"5 8\\n........\\n.######.\\n.######.\\n.######.\\n........\\n\", \"5 7\\n.......\\n.######\\n.#.#.##\\...
Student Andrey has been skipping physical education lessons for the whole term, and now he must somehow get a passing grade on this subject. Obviously, it is impossible to do this by legal means, but Andrey doesn't give up. Having obtained an empty certificate from a local hospital, he is going to use his knowledge of ...
0
{"tests": "{\"inputs\": [\"3\\n1 1\\n2 2\\n2 12\\n\", \"1\\n3 10\\n\", \"1\\n30 660981744053648874\\n\", \"19\\n1 2\\n2 1\\n2 2\\n2 3\\n2 4\\n2 5\\n2 6\\n1 1000000000000000000\\n1000000000 1000000000000000000\\n64 64\\n64 3\\n4 4\\n2 100\\n3 6\\n3 7\\n4 10000\\n4 100000\\n4 71\\n4 70\\n\", \"1\\n3 12\\n\", \"1\\n30 410...
Recently, Olya received a magical square with the size of 2^n× 2^n. It seems to her sister that one square is boring. Therefore, she asked Olya to perform exactly k splitting operations. A Splitting operation is an operation during which Olya takes a square with side a and cuts it into 4 equal squares with side a/2. ...
0
{"tests": "{\"inputs\": [\"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\", \"1\\n2\\n1 ...
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...
0
{"tests": "{\"inputs\": [\"10 2 3\\n\", \"5 0 0\\n\", \"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...
«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...
0
{"tests": "{\"inputs\": [\"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\", \"3\\n-1000000000 1000000000\\n1000000000 0\\n1000 -1000000000\\n3...
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...
0.625
{"tests": "{\"inputs\": [\"9 4\\n3\\n1 2 4\\n\", \"9 4\\n3\\n2 3 1\\n\", \"9 4\\n2\\n2 4\\n\", \"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...
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...
0.125
{"tests": "{\"inputs\": [\"3 2\\n1 2\\n1 1\\n\", \"3 3\\n1 3\\n2 3\\n1 3\\n\", \"2 1\\n2 1\\n\", \"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\\...
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...
0
{"tests": "{\"inputs\": [\"2\\n2 2\\n\", \"1\\n5\\n\", \"5\\n2 2 1 2 1\\n\", \"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...
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...
0
{"tests": "{\"inputs\": [\"5 2\\n1 2 3 4 5\\n\", \"4 2\\n2 3 2 3\\n\", \"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\\n...
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 ...
0.375
{"tests": "{\"inputs\": [\"1\\n14\\n\\nSAMPLE\", \"2\\n1\\n2\", \"5\\n15\\n2\\n15\\n3\\n5\", \"13\\n1\\n5\\n5\\n2\\n6\\n6\\n13\\n6\\n13\\n6\\n8\\n4\\n7\", \"5\\n15\\n2\\n15\\n3\\n2\", \"13\\n1\\n5\\n5\\n2\\n6\\n6\\n8\\n6\\n13\\n6\\n8\\n4\\n7\", \"1\\n12\\n\\nSAMPLE\", \"2\\n1\\n4\", \"5\\n15\\n2\\n15\\n2\\n2\", \"13\\n...
Vivek and Sita are in a relationship. Both of them love playing with numbers and treat each other with puzzles every now and then. When Sita visits her class she comes to see that there is a gift packed in a wooden box which has a lock in it which can only be unlocked by solving the puzzle written on the paper note w...
0.75
{"tests": "{\"inputs\": [\"8\\n2 2 286017\\n3 1 262355\\n2 -2 213815\\n1 -3 224435\\n-2 -2 136860\\n-3 -1 239338\\n-2 2 217647\\n-1 3 141903\", \"5\\n3 5 400\\n5 3 700\\n5 5 1000\\n5 7 700\\n7 5 400\", \"6\\n2 5 1000\\n5 2 1100\\n5 5 1700\\n-2 -5 900\\n-5 -2 600\\n-5 -5 2200\", \"3\\n1 2 300\\n3 3 600\\n1 4 800\", \"8\...
New AtCoder City has an infinite grid of streets, as follows: * At the center of the city stands a clock tower. Let (0, 0) be the coordinates of this point. * A straight street, which we will call East-West Main Street, runs east-west and passes the clock tower. It corresponds to the x-axis in the two-dimensional coor...
0.125
{"tests": "{\"inputs\": [\"2 2\\n.\\n.#\", \"4 4\\n..##\\n...\\n.\\n.\", \"5 5\\n.#.#.\\n.#.#\\n.#.#.\\n.#.#\\n.#.#.\", \"3 3\\n.##\\n.#.\\n##.\", \"3 3\\n.##\\n.#.\\n.\", \"2 2\\n.\\n#.\", \"4 4\\n##..\\n...\\n.\\n.\", \"1 7\\n#.#/\\n-..\\n0\\n,\", \"3 3\\n.##\\n.#-\\n.\", \"2 2\\n.\\n$.\", \"4 4\\n##..\\n...\\n-\\n.\...
Consider a grid with H rows and W columns of squares. Let (r, c) denote the square at the r-th row from the top and the c-th column from the left. Each square is painted black or white. The grid is said to be good if and only if the following condition is satisfied: * From (1, 1), we can reach (H, W) by moving one sq...
0
{"tests": "{\"inputs\": [\"5\\n0 1 2 3\\n2 4 0 1 3\", \"5\\n0 1 2 2\\n4 3 1 2 0\", \"5\\n0 1 0 3\\n2 4 0 1 3\", \"5\\n0 1 2 2\\n2 4 0 1 3\", \"5\\n0 1 1 3\\n2 4 0 1 3\", \"5\\n0 0 2 2\\n4 3 1 2 0\", \"5\\n0 1 0 2\\n4 3 1 2 0\", \"5\\n0 0 1 3\\n2 4 0 1 3\", \"5\\n0 0 2 3\\n4 3 1 2 0\", \"5\\n0 0 1 2\\n2 4 0 1 3\", \"5\\...
You are given a rooted tree with N vertices. The vertices are numbered 0, 1, ..., N-1. The root is Vertex 0, and the parent of Vertex i (i = 1, 2, ..., N-1) is Vertex p_i. Initially, an integer a_i is written in Vertex i. Here, (a_0, a_1, ..., a_{N-1}) is a permutation of (0, 1, ..., N-1). You can execute the followi...
0
{"tests": "{\"inputs\": [\"AAAAABBBBAAABBBBAAAA\\nBBBBAAABBBBBBAAAAABB\\n10\\n2 15 2 13\\n2 13 6 16\\n1 13 2 20\\n4 20 3 20\\n1 18 9 19\\n2 14 1 11\\n3 20 3 15\\n6 16 1 17\\n4 18 8 20\\n7 20 3 14\", \"BBBAAAABA\\nBBBBA\\n4\\n7 9 2 5\\n7 9 1 4\\n1 7 2 5\\n1 7 2 4\", \"AAAAABBBBAAABBBBAAAA\\nBBBBAAABBBBBBAAAAABB\\n10\\n2...
Let us consider the following operations on a string consisting of `A` and `B`: 1. Select a character in a string. If it is `A`, replace it with `BB`. If it is `B`, replace with `AA`. 2. Select a substring that is equal to either `AAA` or `BBB`, and delete it from the string. For example, if the first operation is ...
0.25
{"tests": "{\"inputs\": [\"2,5,3\\n3,6,1\\n3,4,2\\n4,5,2\\n3,6,3\\n2,4,1\", \"2,5,3\\n3,6,1\\n3,4,2\\n4,5,2\\n3,6,3\\n1,4,1\", \"2,5,3\\n1,6,3\\n3,4,2\\n4,5,2\\n3,6,3\\n2,4,1\", \"2,5,3\\n3,6,1\\n2,4,2\\n4,5,2\\n3,6,3\\n1,4,1\", \"2,5,3\\n3,6,1\\n3,4,2\\n5,5,2\\n3,6,3\\n1,4,1\", \"2,5,3\\n3,6,1\\n2,4,2\\n4,6,2\\n3,6,3\...
As shown in the following figure, there is a paper consisting of a grid structure where each cell is indicated by (x, y) coordinate system. We are going to put drops of ink on the paper. A drop comes in three different sizes: Large, Medium, and Small. From the point of fall, the ink sinks into surrounding cells as sho...
0.125
{"tests": "{\"inputs\": [\"6\\n1 1\\n4 3\\n6 5\\n8 6\\n10 10\\n14 14\\n5\\n2 2\\n5 4\\n6 6\\n9 8\\n15 10\\n4\\n1 1\\n4 3\\n6 5\\n8 6\\n3\\n2 2\\n5 4\\n6 6\\n4\\n1 1\\n4 3\\n6 5\\n8 6\\n4\\n10 10\\n12 11\\n18 15\\n24 20\\n0\", \"6\\n1 1\\n4 3\\n6 5\\n8 6\\n10 10\\n14 14\\n5\\n2 1\\n5 4\\n6 6\\n9 8\\n15 10\\n4\\n1 1\\n4 ...
<image> Matryoshka is a wooden doll in the shape of a female figure and is a typical Russian folk craft. Matryoshka has a nested structure in which smaller dolls are contained inside a large doll, and is composed of multiple dolls of different sizes. In order to have such a nested structure, the body of each doll has ...
0.25
{"tests": "{\"inputs\": [\"5\\n1 1 0 1 1\\n\", \"3\\n0 1 0\\n\", \"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...
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...
0
{"tests": "{\"inputs\": [\"9\\n5\\n4 7 2 2 9\\n5\\n3 5 8 1 7\\n5\\n1 2 2 4 5\\n2\\n0 1\\n3\\n0 1 0\\n4\\n0 1 0 0\\n4\\n0 1 0 1\\n4\\n0 1 0 2\\n20\\n16 15 1 10 0 14 0 10 3 9 2 5 4 5 17 9 10 20 0 9\\n\", \"9\\n5\\n4 7 2 2 9\\n5\\n3 5 8 1 7\\n5\\n1 2 2 4 0\\n2\\n0 1\\n3\\n0 1 0\\n4\\n0 1 0 0\\n4\\n0 1 0 1\\n4\\n0 1 0 2\\n...
This is a hard version of the problem. In this version, the given array can contain equal elements and the constraints on n are greater than in the easy version of the problem. You are given an array a of n integers (the given array can contain equal elements). You can perform the following operations on array element...
0
{"tests": "{\"inputs\": [\"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\", \"2\\n5 4 1\\n1 5 4 3 2\\n5 4 1\\n1 5 4 3 2\\n\", \"2\\n5 4 1\\n1 5 2 3 2\\n5 4 1\\n1 5 4 3 2\\n\", \"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 3 3\\n4 6 8 2 ...
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...
0
{"tests": "{\"inputs\": [\"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\", \"4\\n1 1000000000\\n1\\n123456\\n1 1000000000\\n21345\\n987654321\\n1 1000000000\\n1000000000\\n1000000000\...
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...
0.125
{"tests": "{\"inputs\": [\"3\\n3\\n1 2\\n1 3\\n4\\n1 2\\n2 3\\n3 4\\n8\\n1 2\\n2 3\\n3 4\\n1 5\\n5 6\\n6 7\\n5 8\\n\", \"3\\n3\\n1 2\\n2 3\\n4\\n1 2\\n2 3\\n3 4\\n8\\n1 2\\n2 3\\n3 4\\n1 5\\n5 6\\n6 7\\n5 8\\n\", \"3\\n3\\n1 2\\n2 3\\n4\\n1 2\\n2 3\\n3 4\\n8\\n1 2\\n2 3\\n3 4\\n1 7\\n5 6\\n6 7\\n5 8\\n\", \"3\\n3\\n1 2...
Gildong is playing with his dog, Badugi. They're at a park that has n intersections and n-1 bidirectional roads, each 1 meter in length and connecting two intersections with each other. The intersections are numbered from 1 to n, and for every a and b (1 ≤ a, b ≤ n), it is possible to get to the b-th intersection from ...
0
{"tests": "{\"inputs\": [\"6\\ncbabc\\nab\\nzza\\nba\\na\\nnutforajaroftuna\\n\", \"6\\ncbabc\\nab\\nzza\\nba\\na\\nnutforajaroftuna\\n\", \"6\\ncbabc\\n`b\\nzza\\nba\\na\\nnutforajaroftuna\\n\", \"6\\ncbabc\\nba\\nzza\\nba\\na\\nnutforajaroftuna\\n\", \"6\\ncbabc\\n`b\\nzza\\nab\\na\\nnutforajaroftuna\\n\", \"6\\ncbab...
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...
0
{"tests": "{\"inputs\": [\"10 14\\n5 14\\n\", \"10 10\\n10 4\\n\", \"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...
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...
0
{"tests": "{\"inputs\": [\"10 5 3 3 6\\nNENSWESNEE\\n\", \"5 0 0 1 1\\nSESNW\\n\", \"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 -46868011...
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). ...
0.625
{"tests": "{\"inputs\": [\"BYOB\\n\", \"YISVOWEL\\n\", \"IEAIAIO\\n\", \"EZYYOIYUZXEVRTOUYXIQ\\n\", \"KZTNJQLPZVHZKZWIB\\n\", \"Z\\n\", \"MTOESEPRFEIWAIWLAFJMGBIQB\\n\", \"A\\n\", \"POKKJNWMNCSXBJLDWVG\\n\", \"ZUBQNDCHHKWNWRVSDSRRRTGZDDPNTVJFKTCNGWND\\n\", \"QIXYUOTRVEXZUYIOYYZE\\n\", \"BIWZKZHVZPLQJNTZK\\n\", \"[\\n\"...
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...
0.5
{"tests": "{\"inputs\": [\"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\", \"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...
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...
0
{"tests": "{\"inputs\": [\"8\\n1 2 7 3 4 8 5 6\\n\", \"6\\n25 1 2 3 14 36\\n\", \"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...
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...
0.25
{"tests": "{\"inputs\": [\"3 5\\n9 0 3 2 4\\n0 2 8 6 2\\n5 3 4 1 3\\n5 1 7 9 5\\n2 4 1 2 4\\n9 1 2 2 0\\n9 1 8 9 7\\n2 7 3 2 9\\n9 1 9 8 2\\n\\nSAMPLE\", \"2 1\\n20\\n24293\\n173\\n1180\\n51947\\n76994\", \"6 6\\n71859 43509 78307 37710 68651 11715\\n91820 39108 37781 14649 95399 38262\\n254 16744 35985 32112 22885 701...
You have an n by m grid. Each grid square has a certain value associated with it. This is given by the numbers vi,j. You can capture grid squares in two different ways. You can directly capture a grid square. This costs ci,j. You can indirectly capture a grid square. You can only do this if we have already captured a...
0