source
int64
2
2
difficulty
int64
7
25
name
stringlengths
9
60
description
stringlengths
164
7.12k
public_tests
dict
private_tests
dict
cf_rating
int64
0
3.5k
cf_points
float64
0
4k
2
12
774_F. Pens And Days Of Week
Stepan has n pens. Every day he uses them, and on the i-th day he uses the pen number i. On the (n + 1)-th day again he uses the pen number 1, on the (n + 2)-th — he uses the pen number 2 and so on. On every working day (from Monday to Saturday, inclusive) Stepan spends exactly 1 milliliter of ink of the pen he uses t...
{ "input": [ "5\n5 4 5 4 4\n", "3\n3 3 3\n" ], "output": [ "5\n", "2\n" ] }
{ "input": [ "2\n1000000000 1000000000\n", "3\n999999999 1000000000 1000000000\n", "4\n1000000000 1000000000 1000000000 1000000000\n", "8\n1000000000 999999999 1000000000 999999999 1000000000 999999999 999999999 999999999\n", "7\n10 10 10 10 10 10 10\n", "2\n999999999 999999999\n", "21\n99...
2,700
0
2
7
81_A. Plug-in
Polycarp thinks about the meaning of life very often. He does this constantly, even when typing in the editor. Every time he starts brooding he can no longer fully concentrate and repeatedly presses the keys that need to be pressed only once. For example, instead of the phrase "how are you" he can type "hhoow aaaare yy...
{ "input": [ "hhoowaaaareyyoouu\n", "reallazy\n", "abacabaabacabaa\n" ], "output": [ "wre\n", "rezy\n", "a\n" ] }
{ "input": [ "xraccabccbry\n", "abb\n", "a\n", "aab\n", "babbbbabbabbbababbabbbbbbabaabaababaaabbbbbabbbbaaaaabbaaabbaabaabbbbabbbababbabaaabbababaaababbbaaa\n", "ab\n", "babbbbbababa\n", "gfj\n", "b\n", "aba\n", "il\n" ], "output": [ "xy\n", "a\n", "a\n", ...
1,400
500
2
10
845_D. Driving Test
Polycarp has just attempted to pass the driving test. He ran over the straight road with the signs of four types. * speed limit: this sign comes with a positive integer number — maximal speed of the car after the sign (cancel the action of the previous sign of this type); * overtake is allowed: this sign means th...
{ "input": [ "7\n1 20\n2\n6\n4\n6\n6\n2\n", "11\n1 100\n3 70\n4\n2\n3 120\n5\n3 120\n6\n1 150\n4\n3 300\n", "5\n1 100\n3 200\n2\n4\n5\n" ], "output": [ "2\n", "2\n", "0\n" ] }
{ "input": [ "10\n1 37\n6\n5\n2\n5\n6\n5\n2\n4\n2\n", "10\n1 5\n4\n5\n4\n1 21\n6\n1 10\n1 1\n2\n3 1\n", "1\n1 100\n", "2\n1 100\n2\n" ], "output": [ "2\n", "1\n", "0\n", "0\n" ] }
1,800
0
2
7
892_A. Greed
Jafar has n cans of cola. Each can is described by two integers: remaining volume of cola ai and can's capacity bi (ai ≤ bi). Jafar has decided to pour all remaining cola into just 2 cans, determine if he can do this or not! Input The first line of the input contains one integer n (2 ≤ n ≤ 100 000) — number of cola...
{ "input": [ "4\n4 1 0 3\n5 2 2 3\n", "3\n6 8 9\n6 10 12\n", "5\n0 0 5 0 0\n1 1 8 10 5\n", "2\n3 5\n3 6\n" ], "output": [ "yes\n", "no\n", "yes\n", "yes\n" ] }
{ "input": [ "4\n1 0 0 0\n2 0 0 0\n", "2\n2 5\n2 5\n", "2\n0 0\n1 2\n", "5\n32 4 22 40 26\n39 20 36 98 44\n", "6\n18 25 3 10 13 37\n38 73 19 35 24 37\n", "2\n1000 1008\n10000 2352\n", "4\n25 35 7 31\n70 37 43 35\n", "5\n1 1 2 3 1\n1 1 2 3 4\n", "5\n22 5 19 16 32\n26 10 43 38 37\n",...
900
500
2
7
914_A. Perfect Squares
Given an array a1, a2, ..., an of n integers, find the largest number in the array that is not a perfect square. A number x is said to be a perfect square if there exists an integer y such that x = y2. Input The first line contains a single integer n (1 ≤ n ≤ 1000) — the number of elements in the array. The second ...
{ "input": [ "2\n4 2\n", "8\n1 2 4 8 16 32 64 576\n" ], "output": [ "2\n", "32\n" ] }
{ "input": [ "2\n370881 659345\n", "5\n804610 765625 2916 381050 93025\n", "1\n-1000000\n", "2\n-1 0\n", "2\n99999 3\n", "53\n280988 756430 -515570 -248578 170649 -21608 642677 216770 827291 589500 940901 216097 -118956 -919104 -319264 -761585 289479 499613 588276 883036 480518 -323196 -274570...
900
500
2
9
936_C. Lock Puzzle
Welcome to another task about breaking the code lock! Explorers Whitfield and Martin came across an unusual safe, inside of which, according to rumors, there are untold riches, among which one can find the solution of the problem of discrete logarithm! Of course, there is a code lock is installed on the safe. The lock...
{ "input": [ "6\nabacbb\nbabcba\n", "3\naba\nbba\n" ], "output": [ "18\n4 1 6 5 1 6 3 1 6 5 1 6 4 1 6 5 1 6 ", "-1" ] }
{ "input": [ "49\nssizfrtawiuefcgtrrapgoivdxmmipwvdtqggsczdipnkzppi\npqzrmpifgttneasigivkrouigpdivczigcxdsmtwpzpwfsadr\n", "50\nzyzxzyzwzyzxzyzvzyzxzyzwzyzxzyzuzyzxzyzwzyzxzyzvzy\nwxzyzzzyzyvzzvyzxxzyxwzuzzzzzyzyzzxyyzzzywzxzzyzyy\n", "50\nabbabaabbaababbabaababbaabbabaabbaababbaabbabaabab\nbaababbaabbaba...
2,300
1,500
2
7
962_A. Equator
Polycarp has created his own training plan to prepare for the programming contests. He will train for n days, all days are numbered from 1 to n, beginning from the first. On the i-th day Polycarp will necessarily solve a_i problems. One evening Polycarp plans to celebrate the equator. He will celebrate it on the first...
{ "input": [ "6\n2 2 2 2 2 2\n", "4\n1 3 2 1\n" ], "output": [ "3\n", "2\n" ] }
{ "input": [ "6\n1 1 1 1 1 2\n", "2\n1 3\n", "6\n3 3 3 2 4 4\n", "2\n2 3\n", "6\n7 3 10 7 3 11\n", "5\n1 1 1 1 1\n", "3\n2 1 2\n", "4\n1 8 7 3\n", "4\n3 2 3 3\n", "2\n5 6\n", "5\n1 1 1 1 3\n", "2\n9 10\n", "5\n2 2 2 4 3\n", "5\n1 2 1 2 1\n", "3\n3 2 2\n", ...
1,300
0
2
8
98_B. Help King
This is the modification of the problem used during the official round. Unfortunately, author's solution of the original problem appeared wrong, so the problem was changed specially for the archive. Once upon a time in a far away kingdom lived the King. The King had a beautiful daughter, Victoria. They lived happily, ...
{ "input": [ "2\n", "3\n", "4\n" ], "output": [ "1/1\n", "8/3\n", "2/1\n" ] }
{ "input": [ "9556\n", "9859\n", "721\n", "9949\n", "659\n", "9992\n", "1108\n", "5\n", "9941\n", "6212\n", "64\n", "46\n", "563\n", "9993\n", "915\n", "43\n", "96\n", "8947\n", "9991\n", "1649\n", "408\n", "9556\n", "16\n", ...
2,200
1,000
2
8
1003_B. Binary String Constructing
You are given three integers a, b and x. Your task is to construct a binary string s of length n = a + b such that there are exactly a zeroes, exactly b ones and exactly x indices i (where 1 ≤ i < n) such that s_i ≠ s_{i + 1}. It is guaranteed that the answer always exists. For example, for the string "01010" there ar...
{ "input": [ "5 3 6\n", "2 2 1\n", "3 3 3\n" ], "output": [ "01010100\n", "1100\n", "101100\n" ] }
{ "input": [ "3 2 1\n", "2 1 2\n", "2 3 3\n", "10 40 1\n", "91 87 11\n", "7 99 14\n", "67 81 40\n", "30 34 44\n", "7 8 7\n", "55 56 110\n", "83 83 83\n", "100 1 2\n", "6 84 12\n", "50 47 18\n", "15 26 24\n", "100 100 100\n", "1 1 1\n", "99 41 17\...
1,300
0
2
9
1027_C. Minimum Value Rectangle
You have n sticks of the given lengths. Your task is to choose exactly four of them in such a way that they can form a rectangle. No sticks can be cut to pieces, each side of the rectangle must be formed by a single stick. No stick can be chosen multiple times. It is guaranteed that it is always possible to choose suc...
{ "input": [ "3\n4\n7 2 2 7\n8\n2 8 1 4 8 2 1 5\n5\n5 5 5 5 5\n" ], "output": [ "2 2 7 7\n1 1 2 2\n5 5 5 5\n" ] }
{ "input": [ "3\n4\n7 2 2 7\n8\n2 8 1 4 8 2 1 5\n5\n5 5 5 5 5\n", "1\n4\n1 1 10000 10000\n", "10\n9\n10 11 11 2 10 2 18 10 18\n6\n14 14 14 14 6 6\n11\n9 7 9 20 7 7 9 9 20 7 12\n7\n15 16 15 15 15 16 15\n17\n7 18 7 15 15 2 18 7 20 19 19 19 20 2 7 19 19\n5\n3 1 6 1 3\n8\n19 12 18 12 12 18 19 12\n13\n11 19 15...
1,600
0
2
7
1070_A. Find a Number
You are given two positive integers d and s. Find minimal positive integer n which is divisible by d and has sum of digits equal to s. Input The first line contains two positive integers d and s (1 ≤ d ≤ 500, 1 ≤ s ≤ 5000) separated by space. Output Print the required number or -1 if it doesn't exist. Examples In...
{ "input": [ "15 50\n", "61 2\n", "13 50\n" ], "output": [ "-1", "1000000000000000000000000000001", "699998" ] }
{ "input": [ "2 5000\n", "3 5000\n", "182 6\n", "364 4\n", "1 5000\n", "72 72\n", "5 1\n", "500 5000\n", "75 16\n", "212 14\n", "277 5\n", "4 5\n", "321 24\n", "4 3\n", "500 1\n", "481 11\n", "76 2\n", "496 4\n", "74 9\n", "100 5000\n", ...
2,200
0
2
11
1091_E. New Year and the Acquaintance Estimation
Bob is an active user of the social network Faithbug. On this network, people are able to engage in a mutual friendship. That is, if a is a friend of b, then b is also a friend of a. Each user thus has a non-negative amount of friends. This morning, somebody anonymously sent Bob the following link: [graph realization ...
{ "input": [ "2\n0 2\n", "4\n1 1 1 1\n", "35\n21 26 18 4 28 2 15 13 16 25 6 32 11 5 31 17 9 3 24 33 14 27 29 1 20 4 12 7 10 30 34 8 19 23 22\n", "3\n3 3 3\n" ], "output": [ "-1\n", "0 2 4 \n", "13 15 17 19 21 \n", "3 \n" ] }
{ "input": [ "8\n3 8 8 4 8 3 4 3\n", "4\n2 2 3 4\n", "4\n1 2 4 3\n", "5\n5 4 3 2 1\n", "1\n0\n", "3\n3 2 1\n", "4\n4 4 3 3\n", "10\n3 7 1 2 6 5 4 10 9 8\n", "1\n1\n", "19\n2 3 2 2 2 2 2 2 2 2 19 3 2 2 2 2 2 2 19\n", "19\n2 2 2 2 2 2 2 2 19 19 2 2 2 2 2 2 2 2 2\n", "10\n...
2,400
3,000
2
9
1110_C. Meaningless Operations
Can the greatest common divisor and bitwise operations have anything in common? It is time to answer this question. Suppose you are given a positive integer a. You want to choose some integer b from 1 to a - 1 inclusive in such a way that the [greatest common divisor (GCD)](https://en.wikipedia.org/wiki/Greatest_commo...
{ "input": [ "3\n2\n3\n5\n" ], "output": [ "3\n1\n7\n" ] }
{ "input": [ "1\n228\n", "9\n15\n7\n12\n122\n127\n99\n1999999\n255\n8388607\n" ], "output": [ "255\n", "5\n1\n15\n127\n1\n127\n2097151\n85\n178481\n" ] }
1,500
1,500
2
9
1180_C. Valeriy and Deque
Recently, on the course of algorithms and data structures, Valeriy learned how to use a deque. He built a deque filled with n elements. The i-th element is a_i (i = 1, 2, …, n). He gradually takes the first two leftmost elements from the deque (let's call them A and B, respectively), and then does the following: if A >...
{ "input": [ "5 3\n1 2 3 4 5\n1\n2\n10\n", "2 0\n0 0\n" ], "output": [ "1 2\n2 3\n5 2\n", "\n" ] }
{ "input": [ "71 57\n9 26 80 10 65 60 63 1 15 85 71 1 58 27 41 97 42 15 42 56 87 22 10 28 34 90 13 70 71 56 65 21 0 78 47 96 56 77 32 83 28 16 10 41 0 18 78 12 27 58 4 67 21 41 99 20 21 52 74 10 83 45 43 65 2 15 1 63 46 97 72\n81\n21\n81\n81\n5\n9\n41\n76\n81\n92\n95\n94\n78\n93\n47\n30\n92\n3\n45\n81\n42\n88\n17...
1,500
500
2
9
1199_C. MP3
One common way of digitalizing sound is to record sound intensity at particular time moments. For each time moment intensity is recorded as a non-negative integer. Thus we can represent a sound file as an array of n non-negative integers. If there are exactly K distinct values in the array, then we need k = ⌈ log_{2} ...
{ "input": [ "6 2\n2 1 2 3 4 3\n", "6 1\n1 1 2 2 3 3\n", "6 1\n2 1 2 3 4 3\n" ], "output": [ "0", "2", "2\n" ] }
{ "input": [ "4 2\n2 2 2 1\n", "40 1\n296861916 110348711 213599874 304979682 902720247 958794999 445626005 29685036 968749742 772121742 50110079 72399009 347194050 322418543 594963355 407238845 847251668 210179965 293944170 300817194 842872332 82882809 446438478 304657690 343250734 567326942 47727237 6627113...
1,600
500
2
8
1216_B. Shooting
Recently Vasya decided to improve his pistol shooting skills. Today his coach offered him the following exercise. He placed n cans in a row on a table. Cans are numbered from left to right from 1 to n. Vasya has to knock down each can exactly once to finish the exercise. He is allowed to choose the order in which he wi...
{ "input": [ "3\n20 10 20\n", "2\n1 4\n", "4\n10 10 10 10\n", "6\n5 4 5 4 4 5\n" ], "output": [ "43\n1 3 2\n", "3\n2 1\n", "64\n1 2 3 4\n", "69\n1 3 6 2 4 5\n" ] }
{ "input": [ "5\n13 16 20 18 11\n" ], "output": [ "138\n3 4 2 1 5\n" ] }
900
0
2
9
1239_C. Queue in the Train
There are n seats in the train's car and there is exactly one passenger occupying every seat. The seats are numbered from 1 to n from left to right. The trip is long, so each passenger will become hungry at some moment of time and will go to take boiled water for his noodles. The person at seat i (1 ≤ i ≤ n) will decid...
{ "input": [ "5 314\n0 310 942 628 0\n" ], "output": [ "314 628 1256 942 1570 \n" ] }
{ "input": [ "100 1000000000\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 1 1 1\n", "1 1\n1\n", "100 1000000000\n12 803 439 918 435 300 497 520 718 573 782 ...
2,300
1,250
2
11
1257_E. The Contest
A team of three programmers is going to play a contest. The contest consists of n problems, numbered from 1 to n. Each problem is printed on a separate sheet of paper. The participants have decided to divide the problem statements into three parts: the first programmer took some prefix of the statements (some number of...
{ "input": [ "2 1 2\n3 1\n4\n2 5\n", "1 5 1\n6\n5 1 2 4 7\n3\n", "3 2 1\n3 2 1\n5 4\n6\n", "2 1 3\n5 6\n4\n1 2 3\n" ], "output": [ "1", "2", "0", "3" ] }
{ "input": [ "5 10 6\n14 3 6 12 21\n7 1 5 8 10 11 13 17 18 20\n9 2 4 15 16 19\n", "11 7 9\n4 8 9 12 14 16 19 21 22 23 27\n1 2 3 11 17 18 26\n5 6 7 10 13 15 20 24 25\n", "1 1 1\n3\n1\n2\n" ], "output": [ "11", "15", "1" ] }
2,000
0
2
12
1280_F. Intergalactic Sliding Puzzle
You are an intergalactic surgeon and you have an alien patient. For the purposes of this problem, we can and we will model this patient's body using a 2 × (2k + 1) rectangular grid. The alien has 4k + 1 distinct organs, numbered 1 to 4k + 1. In healthy such aliens, the organs are arranged in a particular way. For exam...
{ "input": [ "2\n3\n1 2 3 5 6 E 7\n8 9 10 4 11 12 13\n11\n34 45 6 22 16 43 38 44 5 4 41 14 7 29 28 19 9 18 42 8 17 33 1\nE 15 40 36 31 24 10 2 21 11 32 23 30 27 35 25 13 12 39 37 26 20 3\n" ], "output": [ "\nSURGERY COMPLETE\nIR\nR SrS\nS rr\nI lldll\nDONE\nSURGERY FAILED\n" ] }
{ "input": [ "2\n3\n1 2 3 5 6 E 7\n8 9 10 4 11 12 13\n11\n34 45 6 22 16 43 38 44 5 4 41 14 7 29 28 19 9 18 42 8 17 33 1\nE 15 40 36 31 24 10 2 21 11 32 23 30 27 35 25 13 12 39 37 26 20 3\n", "4\n3\n1 5 3 4 13 7 6\nE 2 12 11 10 9 8\n2\n1 7 E 3 4\n9 8 2 6 5\n2\n1 7 6 4 9\nE 5 8 2 3\n3\n1 8 10 E 4 5 6\n13 12 11 ...
3,400
3,000
2
11
1300_E. Water Balance
There are n water tanks in a row, i-th of them contains a_i liters of water. The tanks are numbered from 1 to n from left to right. You can perform the following operation: choose some subsegment [l, r] (1≤ l ≤ r ≤ n), and redistribute water in tanks l, l+1, ..., r evenly. In other words, replace each of a_l, a_{l+1},...
{ "input": [ "5\n7 8 8 10 12\n", "10\n3 9 5 5 1 7 5 3 8 7\n", "4\n7 5 5 7\n" ], "output": [ "7.000000000\n8.000000000\n8.000000000\n10.000000000\n12.000000000\n", "3.000000000\n5.000000000\n5.000000000\n5.000000000\n5.000000000\n5.000000000\n5.000000000\n5.000000000\n7.500000000\n7.500000000\n...
{ "input": [ "3\n20 90 100\n", "13\n987069 989619 960831 976342 972924 961800 954209 956033 998067 984513 977987 963504 985482\n", "3\n20 100 50\n", "2\n100 20\n", "5\n742710 834126 850058 703320 972844\n", "7\n765898 894083 551320 290139 300748 299067 592728\n", "12\n8 10 4 6 6 4 1 2 2 6 ...
2,100
1,250
2
12
1324_F. Maximum White Subtree
You are given a tree consisting of n vertices. A tree is a connected undirected graph with n-1 edges. Each vertex v of this tree has a color assigned to it (a_v = 1 if the vertex v is white and 0 if the vertex v is black). You have to solve the following problem for each vertex v: what is the maximum difference betwee...
{ "input": [ "9\n0 1 1 1 0 0 0 0 1\n1 2\n1 3\n3 4\n3 5\n2 6\n4 7\n6 8\n5 9\n", "4\n0 0 1 0\n1 2\n1 3\n1 4\n" ], "output": [ "2 2 2 2 2 1 1 0 2 ", "0 -1 1 -1 " ] }
{ "input": [ "8\n9 4 1 7 10 1 6 5\n1 2\n2 3\n1 4\n1 5\n5 6\n5 7\n5 8\n", "1\n1337\n", "2\n12345 65432\n2 1\n" ], "output": [ "121\n", "0\n", "65432\n" ] }
1,800
0
2
12
1365_F. Swaps Again
Ayush, Ashish and Vivek are busy preparing a new problem for the next Codeforces round and need help checking if their test cases are valid. Each test case consists of an integer n and two arrays a and b, of size n. If after some (possibly zero) operations described below, array a can be transformed into array b, the ...
{ "input": [ "5\n2\n1 2\n2 1\n3\n1 2 3\n1 2 3\n3\n1 2 4\n1 3 4\n4\n1 2 3 2\n3 1 2 2\n3\n1 2 3\n1 3 2\n" ], "output": [ "Yes\nYes\nNo\nYes\nNo\n" ] }
{ "input": [ "24\n4\n1 2 3 4\n1 2 3 4\n4\n1 2 3 4\n1 2 4 3\n4\n1 2 3 4\n1 3 2 4\n4\n1 2 3 4\n1 3 4 2\n4\n1 2 3 4\n1 4 2 3\n4\n1 2 3 4\n1 4 3 2\n4\n1 2 3 4\n2 1 3 4\n4\n1 2 3 4\n2 1 4 3\n4\n1 2 3 4\n2 3 1 4\n4\n1 2 3 4\n2 3 4 1\n4\n1 2 3 4\n2 4 1 3\n4\n1 2 3 4\n2 4 3 1\n4\n1 2 3 4\n3 1 2 4\n4\n1 2 3 4\n3 1 4 2\n4\...
2,100
2,500
2
10
1407_D. Discrete Centrifugal Jumps
There are n beautiful skyscrapers in New York, the height of the i-th one is h_i. Today some villains have set on fire first n - 1 of them, and now the only safety building is n-th skyscraper. Let's call a jump from i-th skyscraper to j-th (i < j) discrete, if all skyscrapers between are strictly lower or higher than ...
{ "input": [ "5\n1 3 1 4 5\n", "5\n100 1 100 1 100\n", "4\n4 2 2 4\n", "2\n1 1\n" ], "output": [ "3", "2", "1", "1" ] }
{ "input": [ "4\n2 3 4 2\n", "4\n2 1 3 3\n", "8\n4 2 5 5 1 2 5 2\n", "5\n1 5 5 1 4\n" ], "output": [ "1", "2", "4", "2" ] }
2,200
2,000
2
8
1428_B. Belted Rooms
In the snake exhibition, there are n rooms (numbered 0 to n - 1) arranged in a circle, with a snake in each room. The rooms are connected by n conveyor belts, and the i-th conveyor belt connects the rooms i and (i+1) mod n. In the other words, rooms 0 and 1, 1 and 2, …, n-2 and n-1, n-1 and 0 are connected with conveyo...
{ "input": [ "4\n4\n-&gt;&lt;-\n5\n&gt;&gt;&gt;&gt;&gt;\n3\n&lt;--\n2\n&lt;&gt;\n" ], "output": [ "4\n5\n3\n2\n" ] }
{ "input": [ "1\n6\n->>-<-\n", "1\n7\n->>-<<-\n", "1\n15\n--->>>---<<<---\n", "1\n5\n>-<<-\n", "1\n4\n--<>\n", "1\n6\n-<<<->\n", "1\n12\n--->>>---<<<\n", "1\n5\n<<->-\n", "1\n7\n-->>-<-\n", "1\n5\n<<->>\n", "1\n8\n>>>-<---\n", "1\n6\n<<->>-\n", "4\n5\n->>-<\n4\n-><-...
1,200
1,000
2
8
1475_B. New Year's Number
Polycarp remembered the 2020-th year, and he is happy with the arrival of the new 2021-th year. To remember such a wonderful moment, Polycarp wants to represent the number n as the sum of a certain number of 2020 and a certain number of 2021. For example, if: * n=4041, then the number n can be represented as the s...
{ "input": [ "5\n1\n4041\n4042\n8081\n8079\n" ], "output": [ "\nNO\nYES\nYES\nYES\nNO\n" ] }
{ "input": [ "1\n2021\n", "1\n2020\n", "3\n2020\n2021\n4040\n", "1\n4040\n" ], "output": [ "YES\n", "YES\n", "YES\nYES\nYES\n", "YES\n" ] }
900
0
2
11
14_E. Camels
Bob likes to draw camels: with a single hump, two humps, three humps, etc. He draws a camel by connecting points on a coordinate plane. Now he's drawing camels with t humps, representing them as polylines in the plane. Each polyline consists of n vertices with coordinates (x1, y1), (x2, y2), ..., (xn, yn). The first ve...
{ "input": [ "6 1\n", "4 2\n" ], "output": [ "6\n", "0\n" ] }
{ "input": [ "19 10\n", "19 4\n", "20 9\n", "19 7\n", "4 9\n", "19 9\n", "4 1\n", "20 1\n", "19 1\n", "20 10\n", "3 2\n", "5 5\n", "5 10\n", "19 6\n", "6 10\n", "3 3\n", "4 3\n", "5 3\n", "20 4\n", "20 8\n", "19 2\n", "6 2\n", ...
1,900
0
2
8
1525_B. Permutation Sort
You are given a permutation a consisting of n numbers 1, 2, ..., n (a permutation is an array in which each element from 1 to n occurs exactly once). You can perform the following operation: choose some subarray (contiguous subsegment) of a and rearrange the elements in it in any way you want. But this operation canno...
{ "input": [ "3\n4\n1 3 2 4\n3\n1 2 3\n5\n2 1 4 5 3\n" ], "output": [ "\n1\n0\n2\n" ] }
{ "input": [ "1\n8\n6 2 3 1 8 4 5 7\n" ], "output": [ "2\n" ] }
900
0
2
10
156_D. Clues
As Sherlock Holmes was investigating another crime, he found a certain number of clues. Also, he has already found direct links between some of those clues. The direct links between the clues are mutual. That is, the direct link between clues A and B and the direct link between clues B and A is the same thing. No more ...
{ "input": [ "4 1 1000000000\n1 4\n", "3 0 100\n", "2 0 1000000000\n" ], "output": [ "8\n", "3\n", "1\n" ] }
{ "input": [ "100000 0 1\n", "2 1 100000\n1 2\n", "2 1 819865995\n2 1\n", "83 33 367711297\n14 74\n26 22\n55 19\n8 70\n6 42\n53 49\n54 56\n52 17\n62 44\n78 61\n76 4\n78 30\n51 2\n31 42\n33 67\n45 41\n64 62\n15 25\n33 35\n37 20\n38 65\n65 83\n61 14\n20 67\n62 47\n7 34\n78 41\n38 83\n26 69\n54 58\n11 62...
2,500
2,500
2
13
177_G1. Fibonacci Strings
Fibonacci strings are defined as follows: * f1 = «a» * f2 = «b» * fn = fn - 1 fn - 2, n > 2 Thus, the first five Fibonacci strings are: "a", "b", "ba", "bab", "babba". You are given a Fibonacci string and m strings si. For each string si, find the number of times it occurs in the given Fibonacci string as...
{ "input": [ "6 5\na\nb\nab\nba\naba\n" ], "output": [ "3\n5\n3\n3\n1\n" ] }
{ "input": [ "50 100\nbb\naa\nb\nbaa\nbbba\naa\nba\na\nabba\nbaa\naa\naab\nab\nbabb\naabb\nbaa\nbaaa\nbaa\naab\nbba\nbb\naba\naaba\nbab\naaba\naa\naaaa\nbabb\nbbb\naaba\naaa\nab\nbab\nb\nb\naa\naaab\naa\nbba\nbaa\nbabb\nbaba\nba\naaba\nbba\nba\nab\nabb\nb\nba\nbbb\nba\naaa\nbbb\nbaa\nbb\na\naaa\naaba\nab\nbba\nba...
2,400
30
2
7
223_A. Bracket Sequence
A bracket sequence is a string, containing only characters "(", ")", "[" and "]". A correct bracket sequence is a bracket sequence that can be transformed into a correct arithmetic expression by inserting characters "1" and "+" between the original characters of the sequence. For example, bracket sequences "()[]", "([...
{ "input": [ "(((\n", "([])\n" ], "output": [ "0\n\n", "1\n([])\n" ] }
{ "input": [ "(][)\n", "[(()[])]()[()[]]\n", "[[]\n", "(()[))()[]\n", "([]\n", ")[)][)))((([[)]((]][)[)((]([)[)(([)[)]][([\n", "][([))][[))[[((]][([(([[)]]])([)][([([[[[([))]])][[[[[([)]]([[(((]([(](([([[)[(]])(][(((][)[[)][)(][[)[[)])))[)]))]])[([[))(([(]][))([(]]][(])]))))))[[[[[([[([)[[...
1,700
500
2
10
246_D. Colorful Graph
You've got an undirected graph, consisting of n vertices and m edges. We will consider the graph's vertices numbered with integers from 1 to n. Each vertex of the graph has a color. The color of the i-th vertex is an integer ci. Let's consider all vertices of the graph, that are painted some color k. Let's denote a se...
{ "input": [ "5 6\n4 2 5 2 4\n1 2\n2 3\n3 1\n5 3\n5 4\n3 4\n", "6 6\n1 1 2 3 5 8\n1 2\n3 2\n1 4\n4 3\n4 5\n4 6\n" ], "output": [ "2", "3" ] }
{ "input": [ "10 15\n1 1 1 1 2 2 2 2 1 2\n8 5\n9 1\n8 6\n3 5\n2 7\n2 9\n10 3\n3 2\n3 6\n4 2\n5 9\n7 3\n6 7\n5 10\n4 7\n", "10 9\n1 1 1 1 1 1 1 1 1 1\n5 8\n8 6\n1 8\n8 4\n3 7\n1 10\n1 9\n2 5\n6 9\n", "3 1\n13 13 4\n1 2\n", "10 27\n1 1 3 2 4 1 3 2 4 1\n9 3\n7 8\n9 7\n6 5\n7 6\n7 4\n6 9\n3 8\n6 10\n8 5\n...
1,600
2,000
2
11
271_E. Three Horses
There are three horses living in a horse land: one gray, one white and one gray-and-white. The horses are really amusing animals, which is why they adore special cards. Each of those cards must contain two integers, the first one on top, the second one in the bottom of the card. Let's denote a card with a on the top an...
{ "input": [ "1 6\n2\n", "2 10\n13 7\n", "1 6\n7\n" ], "output": [ " 11\n", " 36\n", " 14\n" ] }
{ "input": [ "5 1000000000\n812747000 266266300 444091950 694572960 414735290\n", "10 10\n4 8 4 10 2 10 8 10 4 6\n", "5 22\n14 7 14 21 14\n", "1 1000000000\n12\n", "1 1000000000\n1000000000\n", "5 20\n11 11 11 11 11\n", "6 23\n16 16 16 8 8 8\n", "1 922296375\n922296375\n", "1 24\n1...
2,200
3,000
2
8
295_B. Greg and Graph
Greg has a weighed directed graph, consisting of n vertices. In this graph any pair of distinct vertices has an edge between them in both directions. Greg loves playing with the graph and now he has invented a new game: * The game consists of n steps. * On the i-th step Greg removes vertex number xi from the grap...
{ "input": [ "4\n0 3 1 1\n6 0 400 1\n2 4 0 1\n1 1 1 0\n4 1 2 3\n", "2\n0 5\n4 0\n1 2\n", "1\n0\n1\n" ], "output": [ "17 23 404 0 \n", "9 0 \n", "0 \n" ] }
{ "input": [ "6\n0 72137 71041 29217 96749 46417\n40199 0 55907 57677 68590 78796\n83463 50721 0 30963 31779 28646\n94529 47831 98222 0 61665 73941\n24397 66286 2971 81613 0 52501\n26285 3381 51438 45360 20160 0\n6 3 2 4 5 1\n", "5\n0 27799 15529 16434 44291\n47134 0 90227 26873 52252\n41605 21269 0 9135 5578...
1,700
1,000
2
8
366_B. Dima and To-do List
You helped Dima to have a great weekend, but it's time to work. Naturally, Dima, as all other men who have girlfriends, does everything wrong. Inna and Dima are now in one room. Inna tells Dima off for everything he does in her presence. After Inna tells him off for something, she goes to another room, walks there in ...
{ "input": [ "10 5\n1 3 5 7 9 9 4 1 8 5\n", "6 2\n3 2 1 6 5 4\n" ], "output": [ "3", "1" ] }
{ "input": [ "20 4\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n", "4 2\n2 1 1 3\n", "50 10\n1 2 3 4 5 6 7 8 9 10 10 1 1 1 1 1 1 1 1 1 10 1 1 1 1 1 1 1 1 1 10 1 1 1 1 1 1 1 1 1 10 1 1 1 1 1 1 1 1 1\n", "10 10\n8 4 5 7 6 9 2 2 3 5\n", "2 1\n1 1\n", "1 1\n1\n", "15 5\n5 5 5 5 5 1 2 3 4 5 1 2 3 ...
1,200
1,000
2
7
38_A. Army
The Berland Armed Forces System consists of n ranks that are numbered using natural numbers from 1 to n, where 1 is the lowest rank and n is the highest rank. One needs exactly di years to rise from rank i to rank i + 1. Reaching a certain rank i having not reached all the previous i - 1 ranks is impossible. Vasya ha...
{ "input": [ "3\n5 6\n1 2\n", "3\n5 6\n1 3\n" ], "output": [ "5\n", "11\n" ] }
{ "input": [ "80\n65 15 43 6 43 98 100 16 69 98 4 54 25 40 2 35 12 23 38 29 10 89 30 6 4 8 7 96 64 43 11 49 89 38 20 59 54 85 46 16 16 89 60 54 28 37 32 34 67 9 78 30 50 87 58 53 99 48 77 3 5 6 19 99 16 20 31 10 80 76 82 56 56 83 72 81 84 60 28\n18 24\n", "51\n85 38 22 38 42 36 55 24 36 80 49 15 66 91 88 61 4...
800
0
2
15
409_I. Feed the Golorp
Golorps are mysterious creatures who feed on variables. Golorp's name is a program in some programming language. Some scientists believe that this language is Befunge; golorps are tantalizingly silent. Variables consumed by golorps can take values from 0 to 9, inclusive. For each golorp its daily diet is defined by it...
{ "input": [ "?(__-_+_/_____):-__&gt;__,_____&lt;__.\n", "?(______________________/____+_______*__-_____*______-___):-__&lt;___,___&lt;____,____&lt;_____,_____&lt;______,______&lt;_______.\n", "?(__+___+__-___):-___&gt;__.\n", "?(_-_/___*__):-___&gt;__.\n" ], "output": [ "false", "false", ...
{ "input": [ "?(____________*___________*__________*_________*________*_______*______*_____*____*___*__*_):-__<___,___<____,____<_____,_____<______,______<_______,_______<________,________<_________,_________<__________,__________<___________.\n", "?(__+__+___):-___<__.\n", "?(__*___+_-____):-___>__,____<...
2,400
0
2
10
437_D. The Child and Zoo
Of course our child likes walking in a zoo. The zoo has n areas, that are numbered from 1 to n. The i-th area contains ai animals in it. Also there are m roads in the zoo, and each road connects two distinct areas. Naturally the zoo is connected, so you can reach any area of the zoo from any other area using the roads....
{ "input": [ "4 3\n10 20 30 40\n1 3\n2 3\n4 3\n", "7 8\n40 20 10 30 20 50 40\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n1 4\n5 7\n", "3 3\n10 20 30\n1 2\n2 3\n3 1\n" ], "output": [ "16.6666666667\n", "18.5714285714\n", "13.3333333333\n" ] }
{ "input": [ "10 19\n15704 19758 26631 25050 22778 15041 8487 26418 5136 4199\n1 2\n1 3\n1 4\n2 5\n1 6\n2 7\n2 8\n7 9\n6 10\n7 3\n4 7\n6 4\n6 8\n5 8\n6 9\n5 4\n1 8\n1 9\n5 3\n", "10 14\n594 965 90 327 549 206 514 993 803 635\n1 2\n1 3\n3 4\n2 5\n5 6\n5 7\n4 8\n4 9\n5 10\n10 4\n7 8\n2 6\n6 4\n5 4\n", "10 1...
1,900
2,000
2
11
506_E. Mr. Kitayuta's Gift
Mr. Kitayuta has kindly given you a string s consisting of lowercase English letters. You are asked to insert exactly n lowercase English letters into s to make it a palindrome. (A palindrome is a string that reads the same forward and backward. For example, "noon", "testset" and "a" are all palindromes, while "test" a...
{ "input": [ "add\n2\n", "revive\n1\n" ], "output": [ "adda\n", "reviver\n" ] }
{ "input": [ "noon\n5\n", "lsdijfjisl\n1\n", "lsdijfjisl\n209\n", "nsngnnnnnnnnnnvnnnnnbe\n948\n", "squirrel\n32\n", "cnonnpbnpptppgntggtggtngpptppnbpnnonc\n294295\n", "k\n46277432\n", "nevceypryxidffdixyrpyecven\n2916\n", "yosupo\n2\n", "irrjoktogwxektwrfihfjtertgdhttktrgiwtgt...
3,000
2,500
2
7
556_A. Case of the Zeros and Ones
Andrewid the Android is a galaxy-famous detective. In his free time he likes to think about strings containing zeros and ones. Once he thought about a string of length n consisting of zeroes and ones. Consider the following operation: we choose any two adjacent positions in the string, and if one them contains 0, and ...
{ "input": [ "4\n1100\n", "8\n11101111\n", "5\n01010\n" ], "output": [ "0", "6", "1" ] }
{ "input": [ "7\n1110000\n", "1\n0\n", "6\n110110\n", "2\n11\n", "8\n01011100\n", "2\n00\n", "6\n110100\n", "6\n010111\n", "3\n001\n", "6\n110010\n", "1\n1\n", "6\n001011\n", "9\n011111101\n", "2\n10\n", "2\n01\n", "7\n0000011\n", "3\n100\n" ], "...
900
250
2
11
581_E. Kojiro and Furrari
Motorist Kojiro spent 10 years saving up for his favorite car brand, Furrari. Finally Kojiro's dream came true! Kojiro now wants to get to his girlfriend Johanna to show off his car to her. Kojiro wants to get to his girlfriend, so he will go to her along a coordinate line. For simplicity, we can assume that Kojiro is...
{ "input": [ "9 3 2 3\n2 3\n1 6\n-1 0 1\n", "20 9 2 4\n1 5\n2 10\n-1 0 1 2\n", "8 4 1 1\n2 4\n0\n" ], "output": [ "-1 -1\n3 3\n3 2\n", "-1 -1\n-1 -1\n-1 -1\n-1 -1\n", "0 4\n" ] }
{ "input": [ "386 20 29 30\n1 349\n2 482\n1 112\n1 93\n2 189\n1 207\n2 35\n2 -5\n1 422\n1 442\n1 402\n2 238\n3 258\n3 54\n2 369\n2 290\n2 329\n3 74\n3 -62\n2 170\n1 462\n2 15\n2 222\n1 309\n3 150\n1 -25\n3 130\n1 271\n1 -43\n351 250 91 102 0 286 123 93 100 205 328 269 188 83 73 35 188 223 73 215 199 64 47 379 61 ...
2,800
3,000
2
8
626_B. Cards
Catherine has a deck of n cards, each of which is either red, green, or blue. As long as there are at least two cards left, she can do one of two actions: * take any two (not necessarily adjacent) cards with different colors and exchange them for a new card of the third color; * take any two (not necessarily adj...
{ "input": [ "2\nRB\n", "5\nBBBBB\n", "3\nGRG\n" ], "output": [ "G", "B", "BR" ] }
{ "input": [ "2\nRG\n", "6\nGRRGBB\n", "1\nB\n", "4\nRBGB\n", "7\nBBBGBRG\n", "3\nGGR\n", "102\nGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGRGGGGGGGGBGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG\n", "3\nGGB\n", "1\nR\n", "5\nGRRGR\n", "2\nBG\n", "200\nRGRGRRRRRGRRGR...
1,300
750
2
9
675_C. Money Transfers
There are n banks in the city where Vasya lives, they are located in a circle, such that any two banks are neighbouring if their indices differ by no more than 1. Also, bank 1 and bank n are neighbours if n > 1. No bank is a neighbour of itself. Vasya has an account in each bank. Its balance may be negative, meaning V...
{ "input": [ "3\n5 0 -5\n", "4\n-1 0 1 0\n", "4\n1 2 3 -6\n" ], "output": [ "1", "2", "3" ] }
{ "input": [ "6\n1 -1 1 -1 1 -1\n", "50\n108431864 128274949 -554057370 -384620666 -202862975 -803855410 -482167063 -55139054 -215901009 0 0 0 0 0 94325701 730397219 358214459 -673647271 -131397668 -377892440 0 0 0 0 0 -487994257 -360271553 639988328 489338210 -281060728 250208758 0 993242346 -213071841 -5975...
2,100
1,500
2
10
699_D. Fix a Tree
A tree is an undirected connected graph without cycles. Let's consider a rooted undirected tree with n vertices, numbered 1 through n. There are many ways to represent such a tree. One way is to create an array with n integers p1, p2, ..., pn, where pi denotes a parent of vertex i (here, for convenience a root is cons...
{ "input": [ "5\n3 2 2 5 3\n", "4\n2 3 3 4\n", "8\n2 3 5 4 1 6 6 7\n" ], "output": [ "0 \n3 2 2 5 3 ", "1\n2 3 3 3 \n", "2\n2 3 5 4 4 4 6 7 \n" ] }
{ "input": [ "7\n1 2 3 4 5 6 7\n", "7\n4 3 2 6 3 5 2\n", "6\n6 2 6 2 4 2\n", "8\n2 1 2 2 6 5 6 6\n", "7\n7 5 3 1 2 1 5\n", "3\n2 1 1\n", "7\n1 6 4 4 5 6 7\n", "18\n2 3 4 5 2 7 8 9 10 7 11 12 14 15 13 17 18 18\n", "2\n1 2\n" ], "output": [ "6\n1 1 1 1 1 1 1 \n", "1 \n4 3...
1,700
1,000
2
9
741_C. Arpa’s overnight party and Mehrdad’s silent entering
Note that girls in Arpa’s land are really attractive. Arpa loves overnight parties. In the middle of one of these parties Mehrdad suddenly appeared. He saw n pairs of friends sitting around a table. i-th pair consisted of a boy, sitting on the ai-th chair, and his girlfriend, sitting on the bi-th chair. The chairs wer...
{ "input": [ "3\n1 4\n2 5\n3 6\n" ], "output": [ "1 2\n2 1\n1 2\n" ] }
{ "input": [ "6\n2 11\n7 1\n12 8\n4 10\n3 9\n5 6\n", "26\n8 10\n52 21\n2 33\n18 34\n30 51\n5 19\n22 32\n36 28\n42 16\n13 49\n11 17\n31 39\n43 37\n50 15\n29 20\n35 46\n47 23\n3 1\n44 7\n9 27\n6 48\n40 24\n26 14\n45 4\n12 25\n41 38\n", "7\n3 14\n7 4\n13 10\n11 8\n6 1\n5 9\n2 12\n", "8\n14 2\n7 9\n15 6\n...
2,600
1,250
2
8
765_B. Code obfuscation
Kostya likes Codeforces contests very much. However, he is very disappointed that his solutions are frequently hacked. That's why he decided to obfuscate (intentionally make less readable) his code before upcoming contest. To obfuscate the code, Kostya first looks at the first variable name used in his program and rep...
{ "input": [ "jinotega\n", "abacaba\n" ], "output": [ "NO\n", "YES\n" ] }
{ "input": [ "ac\n", "za\n", "bab\n", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...
1,100
1,000
2
7
80_A. Panoramix's Prediction
A prime number is a number which has exactly two distinct divisors: one and itself. For example, numbers 2, 7, 3 are prime, and 1, 6, 4 are not. The next prime number after x is the smallest prime number greater than x. For example, the next prime number after 2 is 3, and the next prime number after 3 is 5. Note that ...
{ "input": [ "7 9\n", "3 5\n", "7 11\n" ], "output": [ "NO\n", "YES\n", "YES\n" ] }
{ "input": [ "2 6\n", "31 33\n", "2 11\n", "41 49\n", "13 17\n", "23 29\n", "7 8\n", "5 13\n", "47 50\n", "43 47\n", "17 19\n", "5 9\n", "2 50\n", "2 3\n", "3 7\n", "13 20\n", "11 13\n", "19 23\n", "5 11\n", "3 9\n", "5 6\n", "23 ...
800
500
2
8
855_B. Marvolo Gaunt's Ring
Professor Dumbledore is helping Harry destroy the Horcruxes. He went to Gaunt Shack as he suspected a Horcrux to be present there. He saw Marvolo Gaunt's Ring and identified it as a Horcrux. Although he destroyed it, he is still affected by its curse. Professor Snape is helping Dumbledore remove the curse. For this, he...
{ "input": [ "5 1 2 -3\n-1 -2 -3 -4 -5\n", "5 1 2 3\n1 2 3 4 5\n" ], "output": [ "12", "30" ] }
{ "input": [ "1 1000000000 1000000000 1000000000\n1000000000\n", "1 -1000000000 -1000000000 -1000000000\n1000000000\n", "1 999999999 999999999 999999999\n-999999999\n", "1 1000000000 1000000000 1000000000\n-1000000000\n", "3 -2 3 -2\n1 2 1\n", "1 1 1 1\n-1\n", "1 -1000000000 -1000000000 10...
1,500
1,000
2
8
903_B. The Modcrab
Vova is again playing some computer game, now an RPG. In the game Vova's character received a quest: to slay the fearsome monster called Modcrab. After two hours of playing the game Vova has tracked the monster and analyzed its tactics. The Modcrab has h2 health points and an attack power of a2. Knowing that, Vova has...
{ "input": [ "10 6 100\n17 5\n", "11 6 100\n12 5\n" ], "output": [ "4\nSTRIKE\nHEAL\nSTRIKE\nSTRIKE\n", "2\nSTRIKE\nSTRIKE\n" ] }
{ "input": [ "6 6 100\n12 5\n", "79 4 68\n9 65\n", "50 1 2\n70 1\n", "1 1 100\n100 99\n", "12 12 19\n83 8\n", "5 12 11\n4 2\n", "25 27 91\n10 87\n", "9 76 78\n86 69\n", "1 1 2\n3 1\n", "9 1 20\n4 19\n", "14 5 2\n99 1\n", "62 21 10\n47 2\n", "20 1 5\n8 4\n", "34 ...
1,200
0
2
9
925_C. Big Secret
Vitya has learned that the answer for The Ultimate Question of Life, the Universe, and Everything is not the integer 54 42, but an increasing integer sequence a_1, …, a_n. In order to not reveal the secret earlier than needed, Vitya encrypted the answer and obtained the sequence b_1, …, b_n using the following rules: ...
{ "input": [ "3\n1 2 3\n", "6\n4 7 7 12 31 61\n" ], "output": [ "No\n", "Yes\n4 12 7 31 7 61 " ] }
{ "input": [ "1\n4\n", "5\n3 1 1 7 1\n", "2\n531 108\n", "10\n10 1 1 1 1 1 3 6 7 3\n", "31\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 3 3 3 3 3 3 3 7 7 7 7 15 15 31\n" ], "output": [ "Yes\n4 ", "Yes\n1 3 1 7 1 ", "Yes\n108 531 ", "No\n", "Yes\n1 3 1 7 1 3 1 15 1 3 1 7 1 3 1 31 1 3 ...
2,200
1,500
2
10
954_D. Fight Against Traffic
Little town Nsk consists of n junctions connected by m bidirectional roads. Each road connects two distinct junctions and no two roads connect the same pair of junctions. It is possible to get from any junction to any other junction by these roads. The distance between two junctions is equal to the minimum possible num...
{ "input": [ "5 4 3 5\n1 2\n2 3\n3 4\n4 5\n", "5 6 1 5\n1 2\n1 3\n1 4\n4 5\n3 5\n2 5\n", "5 4 1 5\n1 2\n2 3\n3 4\n4 5\n" ], "output": [ "5\n", "3\n", "0\n" ] }
{ "input": [ "3 3 2 3\n1 2\n2 3\n1 3\n", "2 1 2 1\n1 2\n", "3 2 2 3\n1 2\n2 3\n", "3 2 1 3\n1 2\n2 3\n" ], "output": [ "0\n", "0\n", "1\n", "0\n" ] }
1,600
0
2
9
980_C. Posterized
Professor Ibrahim has prepared the final homework for his algorithm’s class. He asked his students to implement the Posterization Image Filter. Their algorithm will be tested on an array of integers, where the i-th integer represents the color of the i-th pixel in the image. The image is in black and white, therefore ...
{ "input": [ "5 2\n0 2 1 255 254\n", "4 3\n2 14 3 4\n" ], "output": [ "0 1 1 254 254 \n", "0 12 3 3 \n" ] }
{ "input": [ "10 3\n112 184 161 156 118 231 191 128 91 229\n", "9 3\n174 149 118 124 166 146 219 233 107\n", "1 4\n51\n", "8 4\n180 195 13 195 61 24 132 160\n", "4 2\n122 108 224 154\n", "3 3\n212 167 3\n", "2 4\n218 213\n", "100 7\n39 242 238 155 95 30 129 132 72 59 22 61 133 113 99 8...
1,700
1,500
2
9
9_C. Hexadecimal's Numbers
One beautiful July morning a terrible thing happened in Mainframe: a mean virus Megabyte somehow got access to the memory of his not less mean sister Hexadecimal. He loaded there a huge amount of n different natural numbers from 1 to n to obtain total control over her energy. But his plan failed. The reason for this w...
{ "input": [ "10\n" ], "output": [ "2\n" ] }
{ "input": [ "100\n", "1010011\n", "1\n", "999999999\n", "112\n", "101\n", "121212121\n", "99\n", "101010101\n", "901556123\n", "2\n", "312410141\n", "1000000000\n", "100100\n", "111111111\n", "100111001\n", "745\n", "7\n", "832513432\n", ...
1,200
0
2
7
1019_A. Elections
As you know, majority of students and teachers of Summer Informatics School live in Berland for the most part of the year. Since corruption there is quite widespread, the following story is not uncommon. Elections are coming. You know the number of voters and the number of parties — n and m respectively. For each vote...
{ "input": [ "1 2\n1 100\n", "5 5\n2 100\n3 200\n4 300\n5 800\n5 900\n", "5 5\n2 100\n3 200\n4 300\n5 400\n5 900\n" ], "output": [ "0\n", "600\n", "500\n" ] }
{ "input": [ "5 5\n2 5\n2 4\n2 1\n3 6\n3 7\n", "1 3000\n918 548706881\n", "1 3000\n2006 226621946\n", "10 2\n1 1\n1 1\n1 1\n1 1\n1 1\n2 1\n2 1\n2 1\n2 1\n2 1\n", "5 5\n1 3\n1 6\n5 4\n3 7\n2 10\n", "10 10\n1 73\n2 8\n3 88\n1 5\n2 100\n1 29\n1 57\n3 37\n7 46\n3 21\n", "5 5\n1 7\n3 3\n2 7\n2 ...
1,700
500
2
12
1041_F. Ray in the tube
You are given a tube which is reflective inside represented as two non-coinciding, but parallel to Ox lines. Each line has some special integer points — positions of sensors on sides of the tube. You are going to emit a laser ray in the tube. To do so, you have to choose two integer points A and B on the first and the...
{ "input": [ "3 1\n1 5 6\n1 3\n3\n" ], "output": [ "3\n" ] }
{ "input": [ "6 94192\n0 134217728 268435456 402653184 536870912 671088640\n6 435192\n67108864 201326592 335544320 469762048 603979776 738197504\n", "8 896753688\n106089702 120543561 161218905 447312211 764275096 764710792 813135974 841008065\n8 933908609\n20162935 104158090 483658135 499325847 728277205 7350...
2,500
3,000
2
9
1106_C. Lunar New Year and Number Division
Lunar New Year is approaching, and Bob is struggling with his homework – a number division problem. There are n positive integers a_1, a_2, …, a_n on Bob's homework paper, where n is always an even number. Bob is asked to divide those numbers into groups, where each group must contain at least 2 numbers. Suppose the n...
{ "input": [ "6\n1 1 1 2 2 2\n", "4\n8 5 2 3\n" ], "output": [ "27\n", "164\n" ] }
{ "input": [ "100\n28 27 23 6 23 11 25 20 28 15 29 23 20 2 8 24 8 9 30 8 8 1 11 7 6 17 17 27 26 30 12 22 17 22 9 25 4 26 9 26 10 30 13 4 16 12 23 19 10 22 12 20 3 16 10 4 29 11 15 4 5 7 29 16 3 1 7 16 26 14 28 1 15 19 30 28 5 22 14 28 13 12 11 30 3 4 7 10 22 8 4 10 22 12 17 27 23 11 18 7\n", "4\n10000 10000 1...
900
1,250
2
10
1133_D. Zero Quantity Maximization
You are given two arrays a and b, each contains n integers. You want to create a new array c as follows: choose some real (i.e. not necessarily integer) number d, and then for every i ∈ [1, n] let c_i := d ⋅ a_i + b_i. Your goal is to maximize the number of zeroes in array c. What is the largest possible answer, if y...
{ "input": [ "4\n0 0 0 0\n1 2 3 4\n", "5\n1 2 3 4 5\n2 4 7 11 3\n", "3\n13 37 39\n1 2 3\n", "3\n1 2 -1\n-6 -12 6\n" ], "output": [ "0\n", "2\n", "2\n", "3\n" ] }
{ "input": [ "5\n-2 2 1 0 2\n0 0 2 -1 -2\n", "4\n0 1 2 3\n0 0 0 3\n", "2\n0 1000000000\n0 0\n", "3\n999999999 999999998 999999999\n999999998 999999997 999999998\n", "2\n0 0\n0 0\n", "2\n999999999 1000000000\n999999998 999999999\n", "3\n0 5 7\n0 10 13\n", "14\n1 1 1 1 1 1 1 1 1 1 1 1 1 ...
1,500
0
2
7
1154_A. Restoring Three Numbers
Polycarp has guessed three positive integers a, b and c. He keeps these numbers in secret, but he writes down four numbers on a board in arbitrary order — their pairwise sums (three numbers) and sum of all three numbers (one number). So, there are four numbers on a board in random order: a+b, a+c, b+c and a+b+c. You h...
{ "input": [ "40 40 40 60\n", "201 101 101 200\n", "3 6 5 4\n" ], "output": [ "20 20 20\n", "100 100 1 ", "3 1 2\n" ] }
{ "input": [ "500000000 500000001 999999999 1000000000\n", "3 999999990 999999991 999999992\n", "600000000 900000000 500000000 1000000000\n", "1000000000 666666667 666666667 666666666\n", "10101000 101000 10001000 10100000\n", "2 2 3 2\n", "3 6 5 4\n" ], "output": [ "500000000 4999...
800
0
2
12
1175_F. The Number of Subpermutations
You have an array a_1, a_2, ..., a_n. Let's call some subarray a_l, a_{l + 1}, ... , a_r of this array a subpermutation if it contains all integers from 1 to r-l+1 exactly once. For example, array a = [2, 2, 1, 3, 2, 3, 1] contains 6 subarrays which are subpermutations: [a_2 ... a_3], [a_2 ... a_4], [a_3 ... a_3], [a...
{ "input": [ "8\n2 4 1 3 4 2 1 2\n", "5\n1 1 2 1 2\n" ], "output": [ "7\n", "6\n" ] }
{ "input": [ "98\n1 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 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98\n", "99...
2,500
0
2
7
1234_A. Equalize Prices Again
You are both a shop keeper and a shop assistant at a small nearby shop. You have n goods, the i-th good costs a_i coins. You got tired of remembering the price of each product when customers ask for it, thus you decided to simplify your life. More precisely you decided to set the same price for all n goods you have. ...
{ "input": [ "3\n5\n1 2 3 4 5\n3\n1 2 2\n4\n1 1 1 1\n" ], "output": [ "3\n2\n1\n" ] }
{ "input": [ "3\n5\n1 2 3 4 5\n3\n1 2 3\n2\n777 778\n", "1\n2\n777 778\n", "1\n2\n777 1\n", "1\n1\n2441139\n" ], "output": [ "3\n2\n778\n", "778\n", "389\n", "2441139\n" ] }
800
0
2
11
1296_E1. String Coloring (easy version)
This is an easy version of the problem. The actual problems are different, but the easy version is almost a subtask of the hard version. Note that the constraints and the output format are different. You are given a string s consisting of n lowercase Latin letters. You have to color all its characters one of the two ...
{ "input": [ "7\nabcdedc\n", "9\nabacbecfd\n", "5\nabcde\n", "8\naaabbcbb\n" ], "output": [ "NO\n", "YES\n001010101\n", "YES\n00000\n", "YES\n00000011\n" ] }
{ "input": [ "6\nqdlrhw\n", "500\nxwxpgalijfbdbdmluuaubobxztpkfnuparzxczfzchinxdtaevbepdxlouzfzaizkinuaufhckjvydmgnkuaneqohcqocfrsbmmohgpoacnqlgspppfogdkkbrkrhdpdlnknjyeccbqssqtaqmyamtkedlhpbjmchfnmwhxepzfrfmlrxrirbvvlryzmulxqjlthclocmiudxbtqpihlnielggjxjmvqjbeozjpskenampuszybcorplicekprqbsdkidwpgwkrpvbpcsdcn...
1,800
0
2
11
131_E. Yet Another Task with Queens
A queen is the strongest chess piece. In modern chess the queen can move any number of squares in any horizontal, vertical or diagonal direction (considering that there're no other pieces on its way). The queen combines the options given to the rook and the bishop. There are m queens on a square n × n chessboard. You ...
{ "input": [ "10 3\n1 1\n1 2\n1 3\n", "8 4\n4 3\n4 8\n6 5\n1 6\n" ], "output": [ "0 2 1 0 0 0 0 0 0\n", "0 3 0 1 0 0 0 0 0\n" ] }
{ "input": [ "10 10\n6 5\n3 5\n3 4\n6 10\n3 10\n4 6\n6 2\n7 5\n1 8\n2 2\n", "10 20\n6 10\n3 10\n10 4\n5 3\n9 4\n10 1\n10 3\n10 7\n8 5\n7 2\n4 7\n5 1\n2 9\n5 5\n6 6\n9 8\n2 10\n9 10\n1 4\n7 4\n", "2 1\n1 1\n", "10 4\n5 6\n4 8\n8 4\n7 4\n", "10 5\n2 3\n1 3\n3 3\n2 1\n2 5\n", "2 2\n1 1\n1 2\n", ...
1,700
2,500
2
8
1339_B. Sorted Adjacent Differences
You have array of n numbers a_{1}, a_{2}, …, a_{n}. Rearrange these numbers to satisfy |a_{1} - a_{2}| ≤ |a_{2} - a_{3}| ≤ … ≤ |a_{n-1} - a_{n}|, where |x| denotes absolute value of x. It's always possible to find such rearrangement. Note that all numbers in a are not necessarily different. In other words, some numb...
{ "input": [ "2\n6\n5 -2 4 8 6 5\n4\n8 1 4 2\n" ], "output": [ "5 5 4 6 -2 8\n2 4 1 8\n" ] }
{ "input": [ "1\n29\n31 16383 15 127 255 3 4095 536870911 7 63 262143 2097151 1 16777215 134217727 524287 511 8388607 67108863 1023 8191 2047 32767 33554431 268435455 65535 131071 1048575 4194303\n" ], "output": [ "32767 65535 16383 131071 8191 262143 4095 524287 2047 1048575 1023 2097151 511 4194303 255 ...
1,200
750
2
12
1360_F. Spy-string
You are given n strings a_1, a_2, …, a_n: all of them have the same length m. The strings consist of lowercase English letters. Find any string s of length m such that each of the given n strings differs from s in at most one position. Formally, for each given string a_i, there is no more than one position j such that...
{ "input": [ "5\n2 4\nabac\nzbab\n2 4\naaaa\nbbbb\n3 3\nbaa\naaa\naab\n2 2\nab\nbb\n3 1\na\nb\nc\n" ], "output": [ "zbac\n-1\naaa\nab\na\n" ] }
{ "input": [ "5\n2 4\nabac\nzbab\n2 4\naaaa\nbbbb\n3 3\nbaa\naaa\naab\n2 2\nab\nbb\n3 1\na\nb\nc\n" ], "output": [ "zbac\n-1\naaa\nab\na\n" ] }
1,700
0
2
13
1380_G. Circular Dungeon
You are creating a level for a video game. The level consists of n rooms placed in a circle. The rooms are numbered 1 through n. Each room contains exactly one exit: completing the j-th room allows you to go the (j+1)-th room (and completing the n-th room allows you to go the 1-st room). You are given the description ...
{ "input": [ "2\n1 2\n", "8\n10 4 3 6 5 10 7 5\n" ], "output": [ "499122177 0 ", "499122193 249561095 249561092 873463811 499122178 124780545 623902721 0 " ] }
{ "input": [ "50\n499 780 837 984 481 526 944 482 862 136 265 605 5 631 974 967 574 293 969 467 573 845 102 224 17 873 648 120 694 996 244 313 404 129 899 583 541 314 525 496 443 857 297 78 575 2 430 137 387 319\n", "10\n20 1 15 17 11 2 15 3 16 3\n" ], "output": [ "559025033 419266602 618914066 938351...
2,600
0
2
13
1424_G. Years
During one of the space missions, humans have found an evidence of previous life at one of the planets. They were lucky enough to find a book with birth and death years of each individual that had been living at this planet. What's interesting is that these years are in the range (1, 10^9)! Therefore, the planet was na...
{ "input": [ "3\n1 5\n2 4\n5 6\n", "4\n3 4\n4 5\n4 6\n8 10\n" ], "output": [ "2 2\n", "4 2\n" ] }
{ "input": [ "1\n1 2\n", "1\n1 1000000000\n", "1\n125 126\n", "3\n1 2\n2 4\n2 4\n" ], "output": [ "1 1\n", "1 1\n", "125 1\n", "2 2\n" ] }
1,300
0
2
9
1445_C. Division
Oleg's favorite subjects are History and Math, and his favorite branch of mathematics is division. To improve his division skills, Oleg came up with t pairs of integers p_i and q_i and for each pair decided to find the greatest integer x_i, such that: * p_i is divisible by x_i; * x_i is not divisible by q_i. ...
{ "input": [ "3\n10 4\n12 6\n179 822\n" ], "output": [ "10\n4\n179\n" ] }
{ "input": [ "1\n42034266112 80174\n", "10\n246857872446986130 713202678\n857754240051582063 933416507\n873935277189052612 530795521\n557307185726829409 746530097\n173788420792057536 769449696\n101626841876448103 132345797\n598448092106640578 746411314\n733629261048200000 361714100\n981271355542147402 38\n559...
1,500
500
2
9
146_C. Lucky Conversion
Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya has two strings a and b of the same length n. The strings consist only of lucky digits. Pety...
{ "input": [ "47\n74\n", "774\n744\n", "777\n444\n" ], "output": [ "1\n", "1\n", "3\n" ] }
{ "input": [ "44447777447744444777777747477444777444447744444\n47444747774774744474747744447744477747777777447\n", "74747474\n77777777\n", "77747\n47474\n", "474777477774444\n774747777774477\n", "47744447444\n74477447744\n", "4447744774744774744747744774474474444447477477444747477444\n74774774...
1,200
500
2
8
1519_B. The Cake Is a Lie
There is a n × m grid. You are standing at cell (1, 1) and your goal is to finish at cell (n, m). You can move to the neighboring cells to the right or down. In other words, suppose you are standing at cell (x, y). You can: * move right to the cell (x, y + 1) — it costs x burles; * move down to the cell (x + 1,...
{ "input": [ "6\n1 1 0\n2 2 2\n2 2 3\n2 2 4\n1 4 3\n100 100 10000\n" ], "output": [ "\nYES\nNO\nYES\nNO\nYES\nNO\n" ] }
{ "input": [ "9\n1 1 0\n2 2 2\n2 2 3\n2 2 4\n1 4 3\n100 100 10000\n3 3 7\n3 3 9\n2 4 8\n" ], "output": [ "YES\nNO\nYES\nNO\nYES\nNO\nNO\nNO\nNO\n" ] }
800
0
2
8
1546_B. AquaMoon and Stolen String
AquaMoon had n strings of length m each. n is an odd number. When AquaMoon was gone, Cirno tried to pair these n strings together. After making (n-1)/(2) pairs, she found out that there was exactly one string without the pair! In her rage, she disrupted each pair of strings. For each pair, she selected some positions...
{ "input": [ "3\n3 5\naaaaa\nbbbbb\nccccc\naaaaa\nbbbbb\n3 4\naaaa\nbbbb\ncccc\naabb\nbbaa\n5 6\nabcdef\nuuuuuu\nkekeke\nekekek\nxyzklm\nxbcklf\neueueu\nayzdem\nukukuk\n" ], "output": [ "ccccc\ncccc\nkekeke\n" ] }
{ "input": [ "3\n3 5\naaaaa\nbbbbb\nccccc\n1 2 5 1 2 3 4 5\n2 1 3\n3 4\naaaa\nbbbb\ncccc\n1 2 2 1 2\n2 1 3\n5 6\nabcdef\nuuuuuu\nkekeke\nekekek\nxyzklm\n1 5 3 2 3 6\n2 4 3 2 4 6\n5 4 1 2 3\n" ], "output": [ "abcabcabcabcabc\n\n\n" ] }
1,200
1,000
2
8
266_B. Queue at the School
During the break the schoolchildren, boys and girls, formed a queue of n people in the canteen. Initially the children stood in the order they entered the canteen. However, after a while the boys started feeling awkward for standing in front of the girls in the queue and they started letting the girls move forward each...
{ "input": [ "5 1\nBGGBG\n", "5 2\nBGGBG\n", "4 1\nGGGB\n" ], "output": [ "GBGGB\n", "GGBGB\n", "GGGB\n" ] }
{ "input": [ "30 50\nBGGBBGGGGGGGGBBGGGBBGGBBBGBBGG\n", "10 3\nBBGBBBBBBG\n", "1 1\nG\n", "46 3\nGGBBGGGGBBGBGBBBBBGGGBGGGBBGGGBBBGGBGGBBBGBGBB\n", "50 6\nBGGBBBBGGBBBBBBGGBGBGBBBBGBBBBBBGBBBBBBBBBBBBBBBBB\n", "1 50\nG\n", "2 2\nBG\n", "27 6\nGBGBGBGGGGGGBGGBGGBBGBBBGBB\n", "50 8\n...
800
500
2
8
28_B. pSort
One day n cells of some array decided to play the following game. Initially each cell contains a number which is equal to it's ordinal number (starting from 1). Also each cell determined it's favourite number. On it's move i-th cell can exchange it's value with the value of some other j-th cell, if |i - j| = di, where ...
{ "input": [ "7\n4 3 5 1 2 7 6\n4 6 6 1 6 6 1\n", "5\n5 4 3 2 1\n1 1 1 1 1\n", "7\n4 2 5 1 3 7 6\n4 6 6 1 6 6 1\n" ], "output": [ "NO\n", "YES\n", "YES\n" ] }
{ "input": [ "80\n39 2 33 16 36 27 65 62 40 17 44 6 13 10 43 31 66 64 63 20 59 72 9 24 12 29 77 47 71 79 50 32 55 4 35 60 7 69 14 54 3 42 15 11 75 22 28 30 49 18 46 56 51 68 5 38 25 58 73 26 61 21 37 80 19 45 53 1 70 67 23 52 41 74 34 76 57 8 48 78\n6 23 42 42 13 72 14 45 66 76 74 44 49 10 14 64 17 15 4 68 14 34 ...
1,600
1,000
2
8
315_B. Sereja and Array
Sereja has got an array, consisting of n integers, a1, a2, ..., an. Sereja is an active boy, so he is now going to complete m operations. Each operation will have one of the three forms: 1. Make vi-th array element equal to xi. In other words, perform the assignment avi = xi. 2. Increase each array element by yi....
{ "input": [ "10 11\n1 2 3 4 5 6 7 8 9 10\n3 2\n3 9\n2 10\n3 1\n3 10\n1 1 10\n2 10\n2 10\n3 1\n3 10\n3 9\n" ], "output": [ "2\n9\n11\n20\n30\n40\n39\n" ] }
{ "input": [ "5 5\n286163265 724763447 761775891 215352371 491215007\n1 4 780579549\n1 2 638546757\n3 4\n1 3 38072627\n2 6119\n", "5 4\n293170637 715384768 756975575 129004053 875201151\n1 3 695181967\n3 3\n2 2288\n1 5 332270946\n", "1 3\n1\n1 1 2\n2 1\n3 1\n", "1 1\n1\n3 1\n", "4 4\n529316834 995...
1,200
1,000
2
10
337_D. Book of Evil
Paladin Manao caught the trail of the ancient Book of Evil in a swampy area. This area contains n settlements numbered from 1 to n. Moving through the swamp is very difficult, so people tramped exactly n - 1 paths. Each of these paths connects some pair of settlements and is bidirectional. Moreover, it is possible to r...
{ "input": [ "6 2 3\n1 2\n1 5\n2 3\n3 4\n4 5\n5 6\n" ], "output": [ "3" ] }
{ "input": [ "50 2 5\n9 14\n46 34\n40 35\n44 30\n32 16\n1 38\n48 2\n17 14\n50 25\n6 1\n45 19\n21 15\n22 11\n15 33\n8 28\n2 32\n10 22\n37 3\n43 39\n25 16\n9 19\n16 3\n28 32\n20 45\n24 32\n4 18\n49 39\n13 45\n26 4\n11 33\n14 37\n42 19\n31 45\n38 3\n34 8\n18 29\n35 34\n29 16\n7 46\n19 28\n27 33\n30 9\n33 16\n36 45\n...
2,000
2,000
2
7
360_A. Levko and Array Recovery
Levko loves array a1, a2, ... , an, consisting of integers, very much. That is why Levko is playing with array a, performing all sorts of operations with it. Each operation Levko performs is of one of two types: 1. Increase all elements from li to ri by di. In other words, perform assignments aj = aj + di for all j ...
{ "input": [ "4 5\n1 2 3 1\n2 1 2 8\n2 3 4 7\n1 1 3 3\n2 3 4 8\n", "4 5\n1 2 3 1\n2 1 2 8\n2 3 4 7\n1 1 3 3\n2 3 4 13\n" ], "output": [ "YES\n8 7 4 7 \n", "NO\n" ] }
{ "input": [ "1 1\n2 1 1 40000000\n", "1 4\n1 1 1 2\n2 1 1 6\n1 1 1 1\n2 1 1 7\n", "97 29\n2 78 82 356152\n2 14 29 430177\n1 59 84 3680\n1 49 89 -2247\n1 92 96 3701\n2 54 89 377271\n1 62 70 -507\n2 94 97 431563\n1 46 55 -9257\n1 51 83 1627\n1 10 20 6633\n1 17 34 -9263\n2 66 92 383251\n1 12 82 3884\n1 78 9...
1,700
500
2
10
383_D. Antimatter
Iahub accidentally discovered a secret lab. He found there n devices ordered in a line, numbered from 1 to n from left to right. Each device i (1 ≤ i ≤ n) can create either ai units of matter or ai units of antimatter. Iahub wants to choose some contiguous subarray of devices in the lab, specify the production mode f...
{ "input": [ "4\n1 1 1 1\n" ], "output": [ "12\n" ] }
{ "input": [ "50\n2 1 5 2 1 3 1 2 3 2 1 1 5 2 2 2 3 2 1 2 2 2 3 3 1 3 1 1 2 2 2 2 1 2 3 1 2 4 1 1 1 3 2 1 1 1 3 2 1 3\n", "250\n2 2 2 2 3 2 4 2 3 2 5 1 2 3 4 4 5 3 5 1 2 5 2 3 5 3 2 3 3 3 5 1 5 5 5 4 1 3 2 5 1 2 3 5 3 3 5 2 1 1 3 3 5 1 4 2 3 3 2 2 3 5 5 4 1 4 1 5 1 3 3 4 1 5 2 5 5 3 2 4 4 4 4 3 5 1 3 4 3 4 2 ...
2,300
2,000
2
9
404_C. Restore Graph
Valera had an undirected connected graph without self-loops and multiple edges consisting of n vertices. The graph had an interesting property: there were at most k edges adjacent to each of its vertices. For convenience, we will assume that the graph vertices were indexed by integers from 1 to n. One day Valera count...
{ "input": [ "3 2\n0 1 1\n", "3 1\n0 0 0\n", "4 2\n2 0 1 3\n" ], "output": [ "2\n1 2\n1 3\n", "-1\n", "3\n2 3\n3 1\n1 4\n" ] }
{ "input": [ "3 1\n0 1 2\n", "5 3\n0 2 1 2 1\n", "4 3\n1 1 1 2\n", "2 1\n1 0\n", "2 1\n1 1\n", "3 2\n0 1 1\n", "9 4\n2 1 1 3 1 2 2 1 0\n", "4 2\n0 1 0 1\n", "7 3\n2 2 0 1 3 2 1\n", "2 1\n0 0\n", "5 4\n1 2 2 2 3\n", "7 6\n1 1 2 2 3 3 3\n", "4 3\n1 2 2 3\n", "10 5...
1,800
1,500
2
10
431_D. Random Task
One day, after a difficult lecture a diligent student Sasha saw a graffitied desk in the classroom. She came closer and read: "Find such positive integer n, that among numbers n + 1, n + 2, ..., 2·n there are exactly m numbers which binary representation contains exactly k digits one". The girl got interested in the t...
{ "input": [ "1 1\n", "3 2\n" ], "output": [ "1", "5\n" ] }
{ "input": [ "286 11\n", "5004844 6\n", "55 55\n", "820882585293 13\n", "427 4\n", "6 16\n", "4 20\n", "15619605006173 15\n", "3 3\n", "2518095982 9\n", "14065439 11\n", "135647 6\n", "3600 4\n", "330 8\n", "10 10\n", "20074910 16\n", "10919740326483...
2,100
2,000
2
7
454_A. Little Pony and Crystal Mine
Twilight Sparkle once got a crystal from the Crystal Mine. A crystal of size n (n is odd; n > 1) is an n × n matrix with a diamond inscribed into it. You are given an odd integer n. You need to draw a crystal of size n. The diamond cells of the matrix should be represented by character "D". All other cells of the matr...
{ "input": [ "5\n", "7\n", "3\n" ], "output": [ "**D**\n*DDD*\nDDDDD\n*DDD*\n**D**\n", "***D***\n**DDD**\n*DDDDD*\nDDDDDDD\n*DDDDD*\n**DDD**\n***D***\n", "*D*\nDDD\n*D*\n" ] }
{ "input": [ "101\n", "11\n", "81\n", "21\n", "15\n", "57\n", "33\n", "69\n", "91\n" ], "output": [ "**************************************************D**************************************************\n*************************************************DDD******************...
800
500
2
10
476_D. Dreamoon and Sets
Dreamoon likes to play with sets, integers and <image>. <image> is defined as the largest positive integer that divides both a and b. Let S be a set of exactly four distinct integers greater than 0. Define S to be of rank k if and only if for all pairs of distinct elements si, sj from S, <image>. Given k and n, Dream...
{ "input": [ "1 1\n", "2 2\n" ], "output": [ "5\n1 2 3 5 \n", "22\n2 4 6 10 \n14 16 18 22 \n" ] }
{ "input": [ "3081 11\n", "4237 87\n", "113 97\n", "2 2\n", "7 7\n", "19 21\n", "13 7\n", "3844 46\n", "1 1\n", "1 10\n", "1563 15\n", "15 27\n", "770 59\n", "1171 46\n", "5422 87\n", "407 39\n", "1 100\n", "6518 18\n", "6155 94\n" ], "ou...
1,900
2,000
2
11
49_E. Common ancestor
The DNA sequence for every living creature in Berland can be represented as a non-empty line consisting of lowercase Latin letters. Berland scientists found out that all the creatures evolve by stages. During one stage exactly one symbol of the DNA line is replaced by exactly two other ones. At that overall there are n...
{ "input": [ "ababa\naba\n2\nc-&gt;ba\nc-&gt;cc\n", "ababa\naba\n1\nc-&gt;ba\n", "ababa\naba\n7\nc-&gt;ba\nc-&gt;cc\ne-&gt;ab\nz-&gt;ea\nb-&gt;ba\nd-&gt;dd\nd-&gt;ab\n" ], "output": [ "-1\n", "-1\n", "-1\n" ] }
{ "input": [ "caaijqulvbesqytzrjqujqhsqtzqulbvhsquqsqcmzlqswbvug\nyinccmmtvchfctzlqcsqwqlpktbjidmusqmqbfjsqwuclwfugq\n50\nw->ep\nc->ya\nj->dc\nf->ot\nc->xm\nb->ce\nt->vl\ni->qu\nk->rv\ns->hs\nh->cu\nl->fn\nl->ai\ng->di\nb->bn\nc->ej\ng->kx\ns->uw\nh->hp\nv->ji\nw->sh\nn->cm\nj->ed\ny->lf\nk->lr\nf->bv\ne->hf\ng->...
2,300
2,500
2
7
577_A. Multiplication Table
Let's consider a table consisting of n rows and n columns. The cell located at the intersection of i-th row and j-th column contains number i × j. The rows and columns are numbered starting from 1. You are given a positive integer x. Your task is to count the number of cells in a table that contain number x. Input T...
{ "input": [ "5 13\n", "10 5\n", "6 12\n" ], "output": [ "0\n", "2\n", "4\n" ] }
{ "input": [ "100000 997920\n", "100000 989460910\n", "22740 989460910\n", "1 1000000000\n", "19999 399960001\n", "100000 1000000000\n", "100000 1\n", "100000 479001600\n", "4 4\n", "100000 25\n", "58942 936593001\n", "100000 98280\n", "2 4\n", "100000 720720\n"...
1,000
500
2
10
599_D. Spongebob and Squares
Spongebob is already tired trying to reason his weird actions and calculations, so he simply asked you to find all pairs of n and m, such that there are exactly x distinct squares in the table consisting of n rows and m columns. For example, in a 3 × 5 table there are 15 squares with side one, 8 squares with side two a...
{ "input": [ "8\n", "26\n", "2\n" ], "output": [ "4\n 1 8\n 2 ...
{ "input": [ "10152342200\n", "6466460\n", "334344854787443885\n", "5050505060\n", "649708734844\n", "380060000009189500\n", "5000004100\n", "800800\n", "147456000000000\n", "20202582400\n", "914669606669700001\n", "600201602000\n", "14\n", "18270000000000\n", ...
1,900
2,000
2
9
620_C. Pearls in a Row
There are n pearls in a row. Let's enumerate them with integers from 1 to n from the left to the right. The pearl number i has the type ai. Let's call a sequence of consecutive pearls a segment. Let's call a segment good if it contains two pearls of the same type. Split the row of the pearls to the maximal number of ...
{ "input": [ "5\n1 2 3 4 1\n", "7\n1 2 1 3 1 2 1\n", "5\n1 2 3 4 5\n" ], "output": [ "1\n1 5\n", "2\n1 3\n4 7\n", "-1\n" ] }
{ "input": [ "7\n13 9 19 13 3 13 12\n", "4\n1 2 1 2\n", "5\n1 2 2 2 3\n", "13\n1 1 1 1 1 1 1 1 1 1 1 1 1\n", "3\n1 1 1\n", "11\n1 1 2 1 2 1 2 1 2 1 1\n", "1\n576560149\n", "10\n522312461 21923894 21923894 544064902 488228616 329635457 522312461 488228616 654502493 598654597\n", "10...
1,500
0
2
8
641_B. Little Artem and Matrix
Little Artem likes electronics. He can spend lots of time making different schemas and looking for novelties in the nearest electronics store. The new control element was delivered to the store recently and Artem immediately bought it. That element can store information about the matrix of integers size n × m. There a...
{ "input": [ "2 2 6\n2 1\n2 2\n3 1 1 1\n3 2 2 2\n3 1 2 8\n3 2 1 8\n", "3 3 2\n1 2\n3 2 2 5\n" ], "output": [ "8 2 \n1 8 \n", "0 0 0 \n0 0 5 \n0 0 0 \n" ] }
{ "input": [ "4 2 5\n2 1\n3 1 1 5\n3 2 1 6\n3 3 1 7\n3 4 1 9\n", "1 1 3\n1 1\n2 1\n3 1 1 -1000000000\n", "1 4 5\n1 1\n3 1 1 1\n3 1 2 2\n3 1 3 3\n3 1 4 4\n", "5 5 1\n1 5\n", "1 2 2\n1 1\n3 1 2 15\n", "3 10 2\n1 2\n3 2 7 5\n", "2 2 6\n2 1\n2 2\n3 1 1 -1\n3 2 2 -1\n3 1 2 -1\n3 2 1 -1\n", ...
1,400
750
2
11
669_E. Little Artem and Time Machine
Little Artem has invented a time machine! He could go anywhere in time, but all his thoughts of course are with computer science. He wants to apply this time machine to a well-known data structure: multiset. Artem wants to create a basic multiset of integers. He wants these structure to support operations of three typ...
{ "input": [ "3\n1 1 1\n2 2 1\n3 3 1\n", "6\n1 1 5\n3 5 5\n1 2 5\n3 6 5\n2 3 5\n3 7 5\n" ], "output": [ "0\n", "1\n2\n1\n" ] }
{ "input": [ "10\n1 1 1000000000\n1 4 1000000000\n2 2 1000000000\n1 5 1000000000\n1 8 1000000000\n2 15 1000000000\n3 3 1000000000\n3 10 1000000000\n3 6 1000000000\n3 7 1000000000\n", "20\n1 1 1\n1 2 2\n1 3 3\n1 4 4\n1 5 5\n2 11 5\n2 12 4\n2 13 3\n2 14 2\n2 15 1\n3 6 1\n3 7 2\n3 8 3\n3 9 4\n3 10 5\n3 16 1\n3 1...
2,000
2,000
2
8
715_B. Complete The Graph
ZS the Coder has drawn an undirected graph of n vertices numbered from 0 to n - 1 and m edges between them. Each edge of the graph is weighted, each weight is a positive integer. The next day, ZS the Coder realized that some of the weights were erased! So he wants to reassign positive integer weight to each of the edg...
{ "input": [ "5 5 13 0 4\n0 1 5\n2 1 2\n3 2 3\n1 4 0\n4 3 4\n", "2 1 999999999 1 0\n0 1 1000000000\n", "2 1 123456789 0 1\n0 1 0\n" ], "output": [ "YES\n0 1 5\n2 1 2\n3 2 3\n1 4 8\n4 3 4\n", "NO", "YES\n0 1 123456789\n" ] }
{ "input": [ "8 9 10 1 0\n1 2 1\n2 4 1\n1 3 0\n3 4 0\n4 5 0\n5 6 1\n6 0 1\n5 7 0\n7 0 0\n", "7 9 320 0 3\n0 1 0\n1 2 0\n2 3 0\n0 4 1\n4 1 1\n1 5 100\n5 2 100\n2 6 59\n6 3 61\n", "1000 1 5 999 0\n0 999 0\n", "4 5 7 0 3\n0 1 0\n1 2 3\n2 3 0\n0 2 5\n1 3 5\n", "5 5 3 0 2\n0 1 1\n1 2 1\n0 4 0\n4 3 0\n3...
2,300
1,000
2
10
735_D. Taxes
Mr. Funt now lives in a country with a very specific tax laws. The total income of mr. Funt during this year is equal to n (n ≥ 2) burles and the amount of tax he has to pay is calculated as the maximum divisor of n (not equal to n, of course). For example, if n = 6 then Funt has to pay 3 burles, while for n = 25 he ne...
{ "input": [ "4\n", "27\n" ], "output": [ "2", "3" ] }
{ "input": [ "101\n", "998321704\n", "200743933\n", "99990001\n", "16\n", "1999999999\n", "14\n", "10759922\n", "192483501\n", "344472101\n", "1999999927\n", "21\n", "2\n", "200000015\n", "26\n", "1000000007\n", "1908903481\n", "18\n", "24\n"...
1,600
1,750
2
10
75_D. Big Maximum Sum
Ahmed and Mostafa used to compete together in many programming contests for several years. Their coach Fegla asked them to solve one challenging problem, of course Ahmed was able to solve it but Mostafa couldn't. This problem is similar to a standard problem but it has a different format and constraints. In the stand...
{ "input": [ "6 1\n4 0 8 -3 -10\n8 3 -2 -5 10 8 -9 -5 -4\n1 0\n1 -3\n3 -8 5 6\n2 9 6\n1\n", "3 4\n3 1 6 -2\n2 3 3\n2 -5 1\n2 3 1 3\n" ], "output": [ "8", "9" ] }
{ "input": [ "4 8\n8 0 3 -9 -10 0 -1 6 -4\n3 -10 -7 2\n10 6 -2 -9 0 -7 -4 -7 7 -1 2\n3 -5 1 -4\n1 1 1 1 4 4 3 3\n", "2 2\n6 -1 -1 -1 1 1 1\n6 -1 -1 -1 -1 -1 -1\n1 2\n", "2 2\n6 -1 -1 -1 1 1 1\n6 1 1 1 -1 -1 -1\n1 2\n", "2 2\n6 0 0 0 0 0 0\n6 0 0 0 0 0 0\n1 2\n", "2 2\n11 -1 -1 -1 -1 10 -1 -1 -1 -1...
2,000
2,000
2
9
780_C. Andryusha and Colored Balloons
Andryusha goes through a park each day. The squares and paths between them look boring to Andryusha, so he decided to decorate them. The park consists of n squares connected with (n - 1) bidirectional paths in such a way that any square is reachable from any other using these paths. Andryusha decided to hang a colored...
{ "input": [ "5\n2 3\n5 3\n4 3\n1 3\n", "5\n2 1\n3 2\n4 3\n5 4\n", "3\n2 3\n1 3\n" ], "output": [ "5\n1 3 2 5 4", "3\n1 2 3 1 2", "3\n1 3 2" ] }
{ "input": [ "10\n5 3\n9 2\n7 1\n3 8\n4 1\n1 9\n10 1\n8 9\n6 2\n", "5\n4 2\n3 1\n3 4\n3 5\n", "3\n2 1\n3 2\n", "7\n3 6\n3 1\n3 2\n3 5\n3 4\n3 7\n", "50\n45 2\n4 48\n16 4\n17 29\n29 33\n31 2\n47 41\n41 33\n22 6\n44 40\n32 24\n12 40\n28 16\n18 30\n20 41\n25 45\n35 29\n10 32\n1 48\n15 50\n6 9\n43 2\n...
1,600
1,250
2
7
850_A. Five Dimensional Points
You are given set of n points in 5-dimensional space. The points are labeled from 1 to n. No two points coincide. We will call point a bad if there are different points b and c, not equal to a, from the given set such that angle between vectors <image> and <image> is acute (i.e. strictly less than <image>). Otherwise,...
{ "input": [ "3\n0 0 1 2 0\n0 0 9 2 0\n0 0 5 9 0\n", "6\n0 0 0 0 0\n1 0 0 0 0\n0 1 0 0 0\n0 0 1 0 0\n0 0 0 1 0\n0 0 0 0 1\n" ], "output": [ "0\n", "1\n1\n" ] }
{ "input": [ "10\n0 -110 68 -51 -155\n-85 -110 68 -51 -155\n85 -70 51 68 -230\n0 -40 51 68 75\n0 5 -51 -68 -190\n85 0 0 0 0\n85 -115 -68 51 35\n85 -75 -187 34 -40\n-85 -110 -136 102 -155\n85 -110 -17 119 -155\n", "11\n1 0 0 0 0\n-1 0 0 0 0\n0 1 0 0 0\n0 -1 0 0 0\n0 0 1 0 0\n0 0 -1 0 0\n0 0 0 1 0\n0 0 0 -1 0\n...
1,700
500
2
9
873_C. Strange Game On Matrix
Ivan is playing a strange game. He has a matrix a with n rows and m columns. Each element of the matrix is equal to either 0 or 1. Rows and columns are 1-indexed. Ivan can replace any number of ones in this matrix with zeroes. After that, his score in the game will be calculated as follows: 1. Initially Ivan's scor...
{ "input": [ "3 2 1\n1 0\n0 1\n0 0\n", "4 3 2\n0 1 0\n1 0 1\n0 1 0\n1 1 1\n" ], "output": [ "2 0", "4 1" ] }
{ "input": [ "3 57 3\n1 0 0 1 1 0 1 1 0 0 0 0 1 0 1 0 0 0 0 0 0 1 0 0 0 0 1 0 0 1 1 0 1 1 1 1 0 1 1 1 0 0 0 1 1 0 0 1 0 0 0 1 1 0 0 1 0\n1 1 0 0 0 1 1 1 0 1 1 0 0 0 0 1 1 0 0 1 0 0 1 1 1 0 1 0 0 0 0 1 1 1 0 0 0 1 0 1 0 0 0 1 1 0 0 0 1 1 0 0 1 1 0 0 0\n1 0 1 0 0 1 1 0 1 0 0 0 1 0 1 0 1 0 1 1 1 1 0 1 0 0 0 1 1 1 1 ...
1,600
0
2
8
899_B. Months and Years
Everybody in Russia uses Gregorian calendar. In this calendar there are 31 days in January, 28 or 29 days in February (depending on whether the year is leap or not), 31 days in March, 30 days in April, 31 days in May, 30 in June, 31 in July, 31 in August, 30 in September, 31 in October, 30 in November, 31 in December. ...
{ "input": [ "4\n31 31 30 31\n", "3\n31 31 28\n", "5\n29 31 30 31 30\n", "2\n30 30\n", "3\n31 28 30\n" ], "output": [ "Yes\n", "Yes\n", "Yes\n", "No\n", "No\n" ] }
{ "input": [ "17\n28 30 31 30 31 31 28 31 30 31 30 31 31 30 31 30 31\n", "12\n31 29 31 30 31 30 31 30 30 31 30 31\n", "4\n31 29 29 30\n", "9\n29 31 29 31 30 31 30 31 31\n", "24\n29 31 30 31 30 31 31 30 31 30 31 31 28 31 30 31 30 31 31 30 31 30 31 31\n", "12\n31 29 31 30 31 30 31 31 30 31 30 31...
1,200
1,000
2
9
91_C. Ski Base
A ski base is planned to be built in Walrusland. Recently, however, the project is still in the constructing phase. A large land lot was chosen for the construction. It contains n ski junctions, numbered from 1 to n. Initially the junctions aren't connected in any way. In the constructing process m bidirectional ski r...
{ "input": [ "3 4\n1 3\n2 3\n1 2\n1 2\n" ], "output": [ "0\n0\n1\n3\n" ] }
{ "input": [ "15 29\n6 11\n14 3\n10 4\n14 7\n6 14\n7 15\n13 8\n10 13\n4 14\n15 8\n12 7\n3 5\n6 7\n8 1\n4 5\n11 5\n10 6\n11 3\n13 14\n7 10\n3 12\n7 14\n8 11\n7 15\n15 8\n12 7\n4 3\n9 4\n8 10\n", "2 40\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\...
2,300
1,500
2
7
948_A. Protect Sheep
Bob is a farmer. He has a large pasture with many sheep. Recently, he has lost some of them due to wolf attacks. He thus decided to place some shepherd dogs in such a way that all his sheep are protected. The pasture is a rectangle consisting of R × C cells. Each cell is either empty, contains a sheep, a wolf or a dog...
{ "input": [ "1 2\nSW\n", "6 6\n..S...\n..S.W.\n.S....\n..W...\n...W..\n......\n", "5 5\n.S...\n...S.\nS....\n...S.\n.S...\n" ], "output": [ "No\n", "Yes\nDDSDDD\nDDSDWD\nDSDDDD\nDDWDDD\nDDDWDD\nDDDDDD\n", "Yes\nDSDDD\nDDDSD\nSDDDD\nDDDSD\nDSDDD\n" ] }
{ "input": [ "4 4\nW..S\nW..S\nW..S\nW..S\n", "10 10\n....W.W.W.\n.........S\n.S.S...S..\nW.......SS\n.W..W.....\n.W...W....\nS..S...S.S\n....W...S.\n..S..S.S.S\nSS.......S\n", "4 2\n..\n..\n.W\n.S\n", "2 4\n...W\n...S\n", "10 10\n....W.W.W.\n...W.....S\n.S.S...S..\nW......WSS\n.W..W.....\n.W...W....
900
500
2
7
976_A. Minimum Binary Number
String can be called correct if it consists of characters "0" and "1" and there are no redundant leading zeroes. Here are some examples: "0", "10", "1001". You are given a correct string s. You can perform two different operations on this string: 1. swap any pair of adjacent characters (for example, "101" <image>...
{ "input": [ "4\n1001\n", "1\n1\n" ], "output": [ "100\n", "1\n" ] }
{ "input": [ "5\n11100\n", "2\n11\n", "100\n1110111100001111011111111010110011111111011110000111101101011100110110001011000000101010110101011100\n", "100\n1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n", "50\n100100100000000000000000000000000...
800
0
2
11
1006_E. Military Problem
In this problem you will have to help Berland army with organizing their command delivery system. There are n officers in Berland army. The first officer is the commander of the army, and he does not have any superiors. Every other officer has exactly one direct superior. If officer a is the direct superior of officer...
{ "input": [ "9 6\n1 1 1 3 5 3 5 7\n3 1\n1 5\n3 4\n7 3\n1 8\n1 9\n" ], "output": [ "3\n6\n8\n-1\n9\n4\n" ] }
{ "input": [ "2 1\n1\n1 1\n", "13 12\n1 1 1 1 1 1 1 1 1 1 1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n" ], "output": [ "1\n", "1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n" ] }
1,600
0
2
10
102_D. Buses
Little boy Gerald studies at school which is quite far from his house. That's why he has to go there by bus every day. The way from home to school is represented by a segment of a straight line; the segment contains exactly n + 1 bus stops. All of them are numbered with integers from 0 to n in the order in which they f...
{ "input": [ "2 2\n0 1\n1 2\n", "5 5\n0 1\n0 2\n0 3\n0 4\n0 5\n", "3 2\n0 1\n1 2\n" ], "output": [ "1\n", "16\n", "0\n" ] }
{ "input": [ "68 74\n51 54\n3 22\n12 24\n3 27\n32 42\n36 55\n60 64\n1 4\n4 23\n11 64\n54 62\n50 56\n21 34\n27 63\n15 54\n28 61\n13 57\n39 53\n12 32\n32 40\n33 67\n55 61\n33 67\n30 37\n15 49\n27 45\n21 41\n8 42\n24 63\n40 48\n28 41\n30 67\n0 4\n7 15\n27 59\n60 62\n25 65\n30 31\n38 67\n24 43\n14 64\n26 46\n8 12\n34...
1,700
1,000
2
10
1051_D. Bicolorings
You are given a grid, consisting of 2 rows and n columns. Each cell of this grid should be colored either black or white. Two cells are considered neighbours if they have a common border and share the same color. Two cells A and B belong to the same component if they are neighbours, or if there is a neighbour of A tha...
{ "input": [ "4 1\n", "1 2\n", "3 4\n" ], "output": [ "2", "2", "12" ] }
{ "input": [ "1000 1000\n", "1000 1999\n", "23 3\n", "1000 2000\n", "1000 1\n", "1 1\n", "10 15\n", "653 1305\n", "718 234\n", "1000 500\n", "816 2\n" ], "output": [ "987824894", "0", "312158", "2", "2", "2", "872", "0", "178750139", ...
1,700
0
2
11
1073_E. Segment Sum
You are given two integers l and r (l ≤ r). Your task is to calculate the sum of numbers from l to r (including l and r) such that each number contains at most k different digits, and print this sum modulo 998244353. For example, if k = 1 then you have to calculate all numbers from l to r such that each number is form...
{ "input": [ "10 50 2\n", "1 2345 10\n", "101 154 2\n" ], "output": [ "1230", "2750685", "2189" ] }
{ "input": [ "99999999999999999 999999999999999999 6\n", "94010733142571570 227078148960766697 9\n", "1 999999999999999999 7\n", "772 1991 8\n", "2115 5821 2\n", "2001 3111 10\n", "267367244641009867 267367244641757963 2\n", "688313103572144934 736106804844576469 10\n", "4098010349...
2,300
0
2
11
1095_E. Almost Regular Bracket Sequence
You are given a bracket sequence s consisting of n opening '(' and closing ')' brackets. A regular bracket sequence is a bracket sequence that can be transformed into a correct arithmetic expression by inserting characters '1' and '+' between the original characters of the sequence. For example, bracket sequences "()(...
{ "input": [ "6\n()()()\n", "1\n)\n", "6\n(((())\n", "8\n)))(((((\n" ], "output": [ "0", "0", "3", "0" ] }
{ "input": [ "2\n)(\n", "4\n)(((\n", "6\n())(((\n", "2\n((\n", "3\n)))\n", "20\n(())(()((((()())()((\n", "10\n(()(())(((\n", "4\n))))\n", "10\n)(()()(()(\n", "12\n)())(())((((\n", "3\n(((\n", "4\n())(\n", "9\n(((()((()\n", "15\n(((((()(()(()()\n", "2\n))\n",...
1,900
0