info
stringlengths
120
50k
question
stringlengths
504
10.4k
avg@8_qwen3_4b_instruct_2507
float64
0
0.88
{"tests": "{\"inputs\": [\"2 3\\n1 0\\n1 1\\n\", \"2 3\\n0\\n1 0\\n\", \"2 4\\n1 0\\n1 2\\n\", \"99999 100000\\n2 514 415\\n2 50216 61205\\n\", \"3 5\\n0\\n5 4 3 2 1 0\\n\", \"5 12\\n0\\n3 0 8 4\\n\", \"98 49\\n33 0 51 52 6 57 10 12 63 15 16 19 20 21 72 73 74 76 77 78 30 31 81 33 83 37 38 39 40 92 44 45 95 97\\n15 4 5 ...
Drazil has many friends. Some of them are happy and some of them are unhappy. Drazil wants to make all his friends become happy. So he invented the following plan. There are n boys and m girls among his friends. Let's number them from 0 to n - 1 and 0 to m - 1 separately. In i-th day, Drazil invites <image>-th boy and...
0
{"tests": "{\"inputs\": [\"3 1\\n\", \"4 3\\n\", \"692501734 346250868\\n\", \"616075979 207073797\\n\", \"296647497 148323750\\n\", \"401241775 170032078\\n\", \"4 2\\n\", \"541904957 459371829\\n\", \"5 3\\n\", \"3 2\\n\", \"971573366 216791157\\n\", \"5 1\\n\", \"12412523 125123\\n\", \"619189108 309594555\\n\", \"7...
One day Misha and Andrew were playing a very simple game. First, each player chooses an integer in the range from 1 to n. Let's assume that Misha chose number m, and Andrew chose number a. Then, by using a random generator they choose a random integer c in the range between 1 and n (any integer from 1 to n is chosen w...
0.25
{"tests": "{\"inputs\": [\"12\\niherehtolleh\\n5\\nHI\\nHo\\nthere\\nHeLLo\\nhello\\n\", \"30\\nariksihsidlihcdnaehsetahgnisol\\n10\\nKira\\nhates\\nis\\nhe\\nlosing\\ndeath\\nchildish\\nL\\nand\\nNote\\n\", \"5\\ncbaed\\n6\\nbc\\nea\\nab\\ncd\\nabc\\nde\\n\", \"11\\naaaaaaaaaaa\\n3\\naaaa\\naaaaa\\naaaaaa\\n\", \"3\\n...
After observing the results of Spy Syndrome, Yash realised the errors of his ways. He now believes that a super spy such as Siddhant can't use a cipher as basic and ancient as Caesar cipher. After many weeks of observation of Siddhant’s sentences, Yash determined a new cipher technique. For a given sentence, the ciphe...
0
{"tests": "{\"inputs\": [\"2\\n2\\n \\n&gt;\\n \\n3\\n \\n=\\n \\n=\\n \", \"1\\n1\\n1000000000\\n\", \"1\\n1\\n1\\n\", \"1\\n10\\n1 2 1 2 1 3 1 3 1 2\\n\", \"1\\n4\\n1 1 2 2\\n\", \"2\\n2\\n1 2\\n2\\n2 1\\n\", \"6\\n3\\n1 2 3\\n3\\n1 3 2\\n3\\n2 1 3\\n3\\n2 3 1\\n3\\n3 1 2\\n3\\n3 2 1\\n\", \"2\\n2\\n2 1\\n3\\n1 1 1\\...
This is an interactive problem. You have to use flush operation right after printing each line. For example, in C++ you should use function fflush(stdout), in Java — System.out.flush(), in Pascal — flush(output) and in Python — sys.stdout.flush(). In this problem, you need to find maximal and minimal elements of an ar...
0
{"tests": "{\"inputs\": [\"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\", \"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...
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...
0
{"tests": "{\"inputs\": [\"6\\nabacbb\\nbabcba\\n\", \"3\\naba\\nbba\\n\", \"49\\nssizfrtawiuefcgtrrapgoivdxmmipwvdtqggsczdipnkzppi\\npqzrmpifgttneasigivkrouigpdivczigcxdsmtwpzpwfsadr\\n\", \"50\\nzyzxzyzwzyzxzyzvzyzxzyzwzyzxzyzuzyzxzyzwzyzxzyzvzy\\nwxzyzzzyzyvzzvyzxxzyxwzuzzzzzyzyzzxyyzzzywzxzzyzyy\\n\", \"50\\nabbaba...
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...
0
{"tests": "{\"inputs\": [\"8\\n168 224 U\\n130 175 R\\n111 198 D\\n121 188 L\\n201 116 U\\n112 121 R\\n145 239 D\\n185 107 L\", \"4\\n20 30 U\\n30 20 R\\n20 10 D\\n10 20 L\", \"2\\n11 1 U\\n11 47 D\", \"8\\n285 224 U\\n130 175 R\\n111 198 D\\n121 188 L\\n201 116 U\\n112 121 R\\n145 239 D\\n185 107 L\", \"4\\n20 30 U\\n...
M-kun is a brilliant air traffic controller. On the display of his radar, there are N airplanes numbered 1, 2, ..., N, all flying at the same altitude. Each of the airplanes flies at a constant speed of 0.1 per second in a constant direction. The current coordinates of the airplane numbered i are (X_i, Y_i), and the d...
0
{"tests": "{\"inputs\": [\"654321\", \"2\", \"53707\", \"3\", \"42179\", \"1\", \"69890\", \"4\", \"68941\", \"126548\", \"138065\", \"132361\", \"219101\", \"412635\", \"147547\", \"226036\", \"401978\", \"462799\", \"563821\", \"507124\", \"417069\", \"235764\", \"221196\", \"335918\", \"316839\", \"186455\", \"47732...
How many infinite sequences a_1, a_2, ... consisting of {{1, ... ,n}} satisfy the following conditions? * The n-th and subsequent elements are all equal. That is, if n \leq i,j, a_i = a_j. * For every integer i, the a_i elements immediately following the i-th element are all equal. That is, if i < j < k\leq i+a_i, a_j...
0
{"tests": "{\"inputs\": [\"1 6\\n000000\\n000000\\n010010\\n010010\\n000000\\n000000\", \"7 8\\n00100000\\n00011000\\n10111101\\n01100110\\n01000110\\n10111101\\n00011000\\n00100100\\n2\\n5 3\\n1 6\\n1\\n6 8\\n3\\n6 8\\n3 3\\n3 6\\n2\\n6 3\\n6 6\\n0\\n2\\n3 8\\n6 8\", \"2 2\\n00\\n00\\n4\\n1 1\\n1 2\\n2 1\\n2 2\", \"1 ...
The cloth coasters produced and sold by Aizu Takada City are known for their symmetrical design and great beauty. As part of quality control, Aizu Takada City has installed cameras on the production line to automatically verify that the images obtained by shooting each coaster are symmetrical. Each coaster is represent...
0
{"tests": "{\"inputs\": [\"3 3 1\\n1 2 1\\n2 3 1\\n3 1 1\\n1\", \"4 3 1\\n1 2 1\\n2 3 1\\n3 1 1\\n1\", \"4 3 1\\n1 2 1\\n2 3 2\\n1 1 1\\n1\", \"4 3 1\\n1 2 1\\n2 3 1\\n1 2 1\\n2\", \"4 3 1\\n1 2 1\\n2 3 4\\n1 1 1\\n1\", \"8 3 1\\n1 1 2\\n2 3 4\\n3 1 0\\n1\", \"4 3 1\\n1 2 2\\n2 4 4\\n1 1 1\\n1\", \"4 3 1\\n1 1 0\\n1 3 ...
There are N towns in JOI, which are connected by M bidirectional roads. There are shopping malls in K towns, and the people go to one of those towns through the road to shop. Depending on the location of your home, you may have to travel long distances to go shopping, which is very inconvenient. To understand this sit...
0
{"tests": "{\"inputs\": [\"5 5 10 2\\n1 1 0 1 1\\n0 9 1 0 1\\n1 1 1 9 1\\n1 1 9 0 1\\n1 1 1 1 0\\n1 1 0 1 1\\n0 9 1 0 1\\n1 1 1 9 1\\n1 1 1 0 1\\n1 1 1 1 0\\n1 1 10 0\\n3\\n7\\n1 1 5 0\\n3\\n6\\n1 2 10 1\\n6 7\\n5 6\\n2 1 10 1\\n4\\n8\\n3\\n7\\n2 1 10 0\\n4\\n8\\n3\\n7\\n2 1 5 0\\n4\\n8\\n3\\n6\\n0 0 0 0\", \"5 5 10 2\...
YOKARI TAMURA is a nationally famous artist. This month YOKARI will be touring live for D days. Divide this country into C different regions when deciding on a tour schedule. YOKARI benefits from performing live in an area, which is represented by a positive integer. As a general rule, YOKARI will perform up to one liv...
0
{"tests": "{\"inputs\": [\"100000 3\", \"20 3\", \"7 3\", \"5 2\", \"100000 2\", \"36 3\", \"36 2\", \"100010 4\", \"000010 4\", \"001010 4\", \"100100 3\", \"33 3\", \"101000 2\", \"36 4\", \"001010 2\", \"001000 4\", \"110000 3\", \"6 3\", \"101000 3\", \"36 8\", \"001011 4\", \"001000 6\", \"36 15\", \"010010 3\", \...
Problem Find the area of ​​a regular N / K polygon inscribed in a circle with a radius of 1. However, a regular N / K polygon is defined as "the outermost figure that takes N points on the circumference at equal intervals and connects each point every K-1". For example, a 5/2 polygon can be drawn as follows. First, ...
0
{"tests": "{\"inputs\": [\"1\\n1 1 359 1\", \"2\\n2 4 25 306\\n1 9 7 321\", \"8\\n2 9 297 297\\n8 6 359 211\\n8 16 28 288\\n7 9 113 143\\n3 18 315 190\\n10 18 277 300\\n9 5 276 88\\n3 5 322 40\", \"1\\n1 1 1 1\", \"2\\n2 4 25 104\\n1 9 7 321\", \"2\\n2 4 25 28\\n1 9 13 321\", \"2\\n2 4 4 51\\n1 4 13 252\", \"2\\n3 4 4 ...
Problem Neat lives on the world line for a total of 360 days until the 30th of every month for 1 year and 12 months. In that world, N consecutive holidays with the same schedule were applied to people all over the world every year. Consecutive holidays i are consecutive Vi days starting from Mi month Di day. NEET is ...
0
{"tests": "{\"inputs\": [\"15 50\\n\", \"61 2\\n\", \"13 50\\n\", \"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\", ...
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...
0
{"tests": "{\"inputs\": [\"3\\n2\\n3\\n5\\n\", \"1\\n228\\n\", \"9\\n15\\n7\\n12\\n122\\n127\\n99\\n1999999\\n255\\n8388607\\n\", \"1\\n88\\n\", \"9\\n15\\n7\\n12\\n122\\n127\\n99\\n1984716\\n255\\n8388607\\n\", \"1\\n11\\n\", \"9\\n30\\n7\\n12\\n122\\n127\\n99\\n1984716\\n255\\n8388607\\n\", \"1\\n19\\n\", \"9\\n30\\n...
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...
0
{"tests": "{\"inputs\": [\"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\", \"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\...
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},...
0
{"tests": "{\"inputs\": [\"2\\n4 3 2 3 4\\n1 2 3\\n1 2\\n1 3\\n1 4\\n7 9 1 5 7\\n2 10 4 8 5 6 7 3 3\\n1 2\\n1 3\\n1 4\\n3 2\\n3 5\\n4 2\\n5 6\\n1 7\\n6 7\\n\", \"2\\n4 3 2 3 4\\n1 2 3\\n1 2\\n1 3\\n1 4\\n7 9 1 5 7\\n2 10 4 8 5 6 7 3 3\\n1 2\\n1 3\\n1 4\\n3 2\\n3 5\\n4 2\\n5 6\\n1 4\\n6 7\\n\", \"2\\n4 3 2 3 4\\n2 2 3\\...
You are given an undirected unweighted graph consisting of n vertices and m edges (which represents the map of Bertown) and the array of prices p of length m. It is guaranteed that there is a path between each pair of vertices (districts). Mike has planned a trip from the vertex (district) a to the vertex (district) b...
0.25
{"tests": "{\"inputs\": [\"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\", \"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 ...
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 ...
0.25
{"tests": "{\"inputs\": [\"4\\n8 3\\n1 2\\n1 5\\n7 6\\n6 8\\n3 1\\n6 4\\n6 1\\n10 3\\n1 2\\n1 10\\n2 3\\n1 5\\n1 6\\n2 4\\n7 10\\n10 9\\n8 10\\n7 2\\n3 1\\n4 5\\n3 6\\n7 4\\n1 2\\n1 4\\n5 1\\n1 2\\n2 3\\n4 3\\n5 3\\n\", \"4\\n8 3\\n1 2\\n1 5\\n7 6\\n6 8\\n3 1\\n6 4\\n6 1\\n10 3\\n1 2\\n1 10\\n2 3\\n1 5\\n1 6\\n2 4\\n7 ...
You are given a tree (connected graph without cycles) consisting of n vertices. The tree is unrooted — it is just a connected undirected graph without cycles. In one move, you can choose exactly k leaves (leaf is such a vertex that is connected to only one another vertex) connected to the same vertex and remove them w...
0
{"tests": "{\"inputs\": [\"5\\n1 3 1 4 5\\n\", \"5\\n100 1 100 1 100\\n\", \"4\\n4 2 2 4\\n\", \"2\\n1 1\\n\", \"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\", \"4\\n1 3 4 2\\n\", \"4\\n2 1 5 3\\n\", \"8\\n7 2 5 5 1 2 5 2\\n\", \"5\\n1 3 1 4 7\\n\", \"8\\n7 2 5 5 1 2 2 2\\n\", \...
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 ...
0.25
{"tests": "{\"inputs\": [\"4\\n4\\n-&gt;&lt;-\\n5\\n&gt;&gt;&gt;&gt;&gt;\\n3\\n&lt;--\\n2\\n&lt;&gt;\\n\", \"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-->>-...
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...
0
{"tests": "{\"inputs\": [\"2\\n6 3\\n001000\\n2 4\\n1 3\\n3 5\\n4 2\\n1111\\n1 4\\n2 3\\n\", \"2\\n6 3\\n001000\\n2 4\\n1 3\\n3 5\\n4 2\\n1111\\n1 4\\n1 3\\n\", \"2\\n6 3\\n001000\\n2 5\\n1 3\\n3 5\\n4 2\\n1111\\n1 4\\n1 3\\n\", \"2\\n6 3\\n001000\\n2 5\\n1 3\\n3 5\\n4 2\\n1011\\n1 4\\n1 3\\n\", \"2\\n6 3\\n001000\\n2 ...
Hr0d1y has q queries on a binary string s of length n. A binary string is a string containing only characters '0' and '1'. A query is described by a pair of integers l_i, r_i (1 ≤ l_i < r_i ≤ n). For each query, he has to determine whether there exists a good subsequence in s that is equal to the substring s[l_i… r_...
0
{"tests": "{\"inputs\": [\"3\\n4\\n1 3 2 4\\n3\\n1 2 3\\n5\\n2 1 4 5 3\\n\", \"1\\n8\\n6 2 3 1 8 4 5 7\\n\", \"1\\n8\\n6 0 3 1 8 4 5 7\\n\", \"3\\n4\\n1 3 2 7\\n3\\n1 2 3\\n5\\n2 1 4 5 3\\n\", \"1\\n8\\n5 2 2 1 0 0 2 8\\n\", \"1\\n6\\n6 0 3 1 8 4 5 7\\n\", \"1\\n8\\n6 2 6 1 8 4 5 7\\n\", \"1\\n8\\n6 0 3 1 8 6 5 7\\n\",...
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...
0.75
{"tests": "{\"inputs\": [\"1 6\\n2\\n\", \"2 10\\n13 7\\n\", \"1 6\\n7\\n\", \"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 ...
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...
0
{"tests": "{\"inputs\": [\"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\", \"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 5...
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...
0.25
{"tests": "{\"inputs\": [\"add\\n2\\n\", \"revive\\n1\\n\", \"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\",...
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...
0
{"tests": "{\"inputs\": [\"4\\n1100\\n\", \"8\\n11101111\\n\", \"5\\n01010\\n\", \"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\\n1...
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 ...
0.875
{"tests": "{\"inputs\": [\"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\", \"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 22...
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...
0
{"tests": "{\"inputs\": [\"4 1\\n1 2 2 1\\n\", \"7 2\\n1 3 3 1 4 4 4\\n\", \"8 3\\n7 7 8 7 7 8 1 7\\n\", \"50 5\\n2 39 16 20 32 36 29 42 14 23 9 4 28 17 45 16 46 1 39 33 47 15 34 43 6 6 12 15 46 11 32 16 31 12 41 33 47 35 22 3 10 4 9 36 22 22 17 33 15 46\\n\", \"50 7\\n34 49 9 4 29 13 17 46 12 12 14 20 11 36 33 19 46 5...
<image> Some time ago Slastyona the Sweetmaid decided to open her own bakery! She bought required ingredients and a wonder-oven which can bake several types of cakes, and opened the bakery. Soon the expenses started to overcome the income, so Slastyona decided to study the sweets market. She learned it's profitable t...
0.875
{"tests": "{\"inputs\": [\"5 2\\n0 2 1 255 254\\n\", \"4 3\\n2 14 3 4\\n\", \"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\", \"10...
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 ...
0
{"tests": "{\"inputs\": [\"8\\n0 0 0 2 2 2 0 0\\n1 1 1 1 0 0 0 0\\n4\\n1 1 2 2\\n0 0 2 2\\n0\", \"8\\n0 0 0 2 2 2 0 0\\n1 1 1 1 1 0 0 0\\n4\\n1 1 2 2\\n0 0 2 2\\n0\", \"8\\n0 0 0 2 2 2 0 0\\n1 1 1 1 1 0 0 0\\n2\\n1 1 2 2\\n0 0 2 2\\n0\", \"8\\n0 0 0 2 2 2 0 0\\n0 1 1 1 1 0 0 0\\n2\\n1 1 2 2\\n0 0 2 2\\n0\", \"8\\n0 0 0...
Ninja Atsushi guards the town from the roof of the Ninja Building from early morning to late night every day. This Ninja Building is two adjacent buildings of the same floor, and Atsushi's daily routine is to jump between buildings and head to the rooftop for security. Because these two buildings are cleaned frequentl...
0
{"tests": "{\"inputs\": [\"5\\n6 4 2 3 7\", \"7\\n2 9 6 5 6 7 3\", \"5\\n6 2 2 3 7\", \"5\\n6 1 2 2 14\", \"5\\n6 2 2 2 7\", \"5\\n6 2 2 2 14\", \"5\\n6 1 2 2 18\", \"5\\n5 1 2 2 18\", \"5\\n6 4 2 3 11\", \"7\\n2 9 6 5 6 7 5\", \"5\\n10 4 2 3 7\", \"5\\n10 2 2 2 7\", \"5\\n6 2 2 2 1\", \"5\\n3 1 2 2 14\", \"5\\n6 1 4 2...
You are now examining a unique method to sort a sequence of numbers in increasing order. The method only allows swapping of two numbers that have a common prime factor. For example, a sequence [6, 4, 2, 3, 7] can be sorted using the following steps. Step 0: 6 4 2 3 7 (given sequence) Step 1: 2 4 6 3 7 (elements 6 and 2...
0.75
{"tests": "{\"inputs\": [\"3\\n1 1 8 8\\n2 4 3 8\\n8 8 8 8\", \"3\\n1 1 8 8\\n2 4 3 8\\n8 3 8 8\", \"3\\n1 1 8 8\\n2 3 3 8\\n8 3 8 8\", \"3\\n1 1 8 7\\n2 3 3 8\\n8 3 8 8\", \"3\\n1 1 8 7\\n2 3 3 4\\n8 3 8 8\", \"3\\n1 1 8 7\\n2 3 3 4\\n8 3 8 2\", \"3\\n1 1 1 8\\n2 3 3 8\\n8 3 8 8\", \"3\\n1 1 8 7\\n2 3 3 8\\n8 3 8 3\",...
problem Prepare the Othello board. The upper left is $ (1,1) $ and the lower right is $ (8,8) $. The board to be prepared here is $ (5,4) as follows. ) There is no $ black stone. ........ ........ ........ ... ox ... .... o ... ........ ........ ........ Kuroishi: x Shiraishi: o 8x8 board From this state, Black st...
0
{"tests": "{\"inputs\": [\"3\\n0 0\\n1 1\\n2 0\", \"5\\n0 0\\n1 2\\n2 1\\n3 2\\n4 0\", \"4\\n0 1\\n1 2\\n2 0\\n3 1\", \"3\\n0 -1\\n1 1\\n2 0\", \"5\\n-1 0\\n1 2\\n2 1\\n3 2\\n4 0\", \"4\\n0 1\\n1 2\\n3 0\\n3 1\", \"3\\n0 -1\\n1 2\\n2 0\", \"4\\n0 1\\n1 4\\n3 0\\n3 1\", \"3\\n0 -1\\n1 0\\n2 0\", \"4\\n0 0\\n1 4\\n3 0\\n...
For given $N$ points in the 2D Euclidean plane, find the distance of the shortest tour that meets the following criteria: * Visit the points according to the following steps: 1. It starts from the leftmost point (starting point), goes strictly from left to right, and then visits the rightmost point (turn-around point)...
0
{"tests": "{\"inputs\": [\"3 1\\n1 5 6\\n1 3\\n3\\n\", \"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 10...
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...
0
{"tests": "{\"inputs\": [\"8\\n2 4 1 3 4 2 1 2\\n\", \"5\\n1 1 2 1 2\\n\", \"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 8...
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...
0.75
{"tests": "{\"inputs\": [\"2\\n1 2\\n\", \"8\\n10 4 3 6 5 10 7 5\\n\", \"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\", \"5...
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 ...
0
{"tests": "{\"inputs\": [\"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\", \"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 ...
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...
0
{"tests": "{\"inputs\": [\"5 1\\nBGGBG\\n\", \"5 2\\nBGGBG\\n\", \"4 1\\nGGGB\\n\", \"30 50\\nBGGBBGGGGGGGGBBGGGBBGGBBBGBBGG\\n\", \"10 3\\nBBGBBBBBBG\\n\", \"1 1\\nG\\n\", \"46 3\\nGGBBGGGGBBGBGBBBBBGGGBGGGBBGGGBBBGGBGGBBBGBGBB\\n\", \"50 6\\nBGGBBBBGGBBBBBBGGBGBGBBBBGBBBBBBGBBBBBBBBBBBBBBBBB\\n\", \"1 50\\nG\\n\", \"...
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...
0.375
{"tests": "{\"inputs\": [\"3 2\\n0 1 1\\n\", \"3 1\\n0 0 0\\n\", \"4 2\\n2 0 1 3\\n\", \"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...
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...
0.25
{"tests": "{\"inputs\": [\"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\", \"caaijqulvbesqytzrjqujqhsqtzqulbvhsquqsqcmzlqswbvug\\nyinccmmtvchfctzlqcsqwqlpktbjidmusqmqbfjsqwuclwfugq\\n50\\n...
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...
0
{"tests": "{\"inputs\": [\"5 13\\n\", \"10 5\\n\", \"6 12\\n\", \"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\...
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...
0.625
{"tests": "{\"inputs\": [\"5\\n1 2 3 4 1\\n\", \"7\\n1 2 1 3 1 2 1\\n\", \"5\\n1 2 3 4 5\\n\", \"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 544...
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 ...
0
{"tests": "{\"inputs\": [\"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\", \"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\\n2...
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. ...
0
{"tests": "{\"inputs\": [\"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\", \"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...
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...
0
{"tests": "{\"inputs\": [\"4\\n1001\\n\", \"1\\n1\\n\", \"5\\n11100\\n\", \"2\\n11\\n\", \"100\\n1110111100001111011111111010110011111111011110000111101101011100110110001011000000101010110101011100\\n\", \"100\\n1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\\n\", \...
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>...
0.625
{"tests": "{\"inputs\": [\"5 4 2 1\\n1 2 1 5 4\\n\\nSAMPLE\", \"328 292351550 594024 614178\\n111198 247099 874897 789938 217603 184758 550844 786670 926237 148681 166078 312493 797943 48188 761455 612740 236243 719660 121651 128546 37287 500578 18681 428938 866782 174809 839632 31111 718241 136707 358494 290903 482093...
Cat Noku recently picked up construction working as a hobby. He's currently working with a row of buildings and would like to make it beautiful. There are n buildings in a row. The height of the i-th building is xi. Cat Noku can modify the buildings by adding or removing floors to change the heights. It costs him P d...
0.375
{"tests": "{\"inputs\": [\"1\\n4 2\\nAlice\\nBob\\nDaniel\\nMike\\nBob\\n97\\n1\\nAlice\\nMike\\n24\\n2\\nAlice\\nBob\\n\\nSAMPLE\", \"10\\n5 5\\nprtei\\nfyidw\\nnshrv\\nvflws\\noefcc\\nfyidw\\n703\\n1\\noefcc\\nfyidw\\n35\\n3\\nnshrv\\noefcc\\nvflws\\noefcc\\n117\\n2\\nfyidw\\nprtei\\nfyidw\\n149\\n3\\nnshrv\\noefcc\\...
WizKid went on a trip to Wonderland with his classmates. Now, as you know, going on trips incurs costs including hotel costs, fooding, shopping, etc. And when many people go together, usually one person pays and it is expected that the others will pay back their share. But, after a few days people lost track of who owe...
0.125
{"tests": "{\"inputs\": [\"2\\n3\\n8\\n\\nSAMPLE\", \"1\\n2\", \"1\\n4\", \"2\\n2\\n8\\n\\nSAMPLE\", \"1\\n0\", \"2\\n2\\n6\\n\\nSAMPLE\", \"2\\n2\\n5\\n\\nSAMPLE\", \"2\\n2\\n12\\n\\nSBMOLE\", \"2\\n2\\n10\\n\\nLDTMBO\", \"2\\n2\\n14\\n\\nLDTMBO\", \"2\\n2\\n16\\n\\nKDTMBO\", \"2\\n1\\n15\\n\\nKDTMBO\", \"2\\n0\\n0\\n...
Today, teacher taught Xenny the chapter 'Prime numbers and Composite numbers'. Xenny liked it and being a studious boy, wanted some homework. So teacher gave him a simple task. The task is to find the smallest composite number greater than given no. Xenny was happy to get the simple task. But Xenny didn't get the time ...
0
{"tests": "{\"inputs\": [\"3\\n1 2\\n2 3\", \"6\\n1 2\\n1 3\\n1 4\\n2 5\\n2 6\", \"7\\n1 2\\n6 3\\n4 5\\n1 7\\n1 5\\n2 3\", \"4\\n1 2\\n1 3\\n1 4\", \"3\\n1 2\\n1 3\", \"6\\n1 2\\n1 3\\n1 4\\n2 5\\n2 10\", \"6\\n1 2\\n1 3\\n1 4\\n1 5\\n2 6\", \"7\\n1 2\\n6 3\\n4 5\\n1 7\\n1 5\\n2 6\", \"7\\n1 3\\n6 3\\n4 5\\n1 7\\n1 5\...
There is a tree with N vertices. The vertices are numbered 1 through N. The i-th edge (1 \leq i \leq N - 1) connects Vertex x_i and y_i. For vertices v and w (1 \leq v, w \leq N), we will define the distance between v and w d(v, w) as "the number of edges contained in the path v-w". A squirrel lives in each vertex of ...
0
{"tests": "{\"inputs\": [\"8\\n2 8 8\\n1 5 1\\n4 8 2\\n2 5 4\\n3 8 6\\n6 8 9\\n2 7 12\", \"5\\n1 2 5\\n3 4 7\\n2 3 3\\n2 5 2\", \"8\\n2 8 8\\n1 5 1\\n4 8 2\\n2 5 4\\n3 8 5\\n6 8 9\\n2 7 12\", \"5\\n1 2 5\\n3 4 10\\n2 3 3\\n2 5 2\", \"5\\n1 3 5\\n3 4 10\\n2 3 3\\n2 5 2\", \"5\\n1 3 5\\n2 4 20\\n2 3 3\\n2 5 2\", \"8\\n2 ...
There is a tree with N vertices, numbered 1 through N. The i-th edge in this tree connects Vertices A_i and B_i and has a length of C_i. Joisino created a complete graph with N vertices. The length of the edge connecting Vertices u and v in this graph, is equal to the shortest distance between Vertices u and v in the ...
0
{"tests": "{\"inputs\": [\"5 4\\nA\\nB\\nC\\nD\\n5 4\\nD\\nC\\nB\\nA\\n0 0\", \"5 4\\nA\\nC\\nC\\nD\\n5 4\\nD\\nC\\nB\\nA\\n0 0\", \"5 4\\nA\\nC\\nC\\nD\\n5 4\\nD\\nD\\nB\\nA\\n0 0\", \"5 4\\nA\\nC\\nC\\nD\\n4 4\\nD\\nC\\nB\\nA\\n0 0\", \"5 4\\nA\\nD\\nC\\nD\\n5 4\\nD\\nD\\nB\\nA\\n0 0\", \"5 4\\nA\\nC\\nC\\nD\\n4 4\\n...
The neutral city of Eyes City, in the heart of the four countries, is home to the transcontinental train Bandai. The platform has a row of chairs for passengers waiting for the Bandai, and people who enter the platform can use the chairs freely. The Bandai is cheap, fast and comfortable, so there are a constant number...
0
{"tests": "{\"inputs\": [\"10 3 5\\n10 3 5\\n30\\n1\\n6\\n10\", \"10 3 5\\n10 3 3\\n30\\n1\\n6\\n10\", \"10 3 1\\n10 3 3\\n30\\n1\\n6\\n10\", \"10 3 5\\n10 3 3\\n32\\n1\\n6\\n10\", \"10 3 1\\n10 3 3\\n30\\n1\\n8\\n10\", \"10 3 1\\n10 3 0\\n51\\n0\\n6\\n10\", \"10 3 5\\n10 3 6\\n32\\n2\\n6\\n10\", \"10 3 10\\n10 3 6\\n8...
The JOI Railways is the only railway company in the Kingdom of JOI. There are $N$ stations numbered from $1$ to $N$ along a railway. Currently, two kinds of trains are operated; one is express and the other one is local. A local train stops at every station. For each $i$ ($1 \leq i < N$), by a local train, it takes $A...
0
{"tests": "{\"inputs\": [\"1 1 1 2 3 100\\n50\", \"3 1 1 2 3 100\\n49\\n50\\n51\", \"0 1 1 2 3 100\\n50\", \"1 1 1 2 3 110\\n50\", \"3 1 1 2 3 100\\n49\\n50\\n74\", \"2 1 1 2 3 100\\n49\\n72\\n74\", \"2 1 1 2 4 100\\n49\\n72\\n40\", \"1 1 1 3 3 110\\n50\", \"3 1 1 2 3 110\\n49\\n50\\n51\", \"0 1 1 2 3 000\\n50\", \"0 1...
Training is indispensable for achieving good results at ICPC. Rabbit wants to win at ICPC, so he decided to practice today as well. Today's training is to develop physical strength and judgment by running on a straight road. The rabbit is now standing at the starting line and looking out over a long, long road. There...
0
{"tests": "{\"inputs\": [\"316250877917604 316250877917599 681260158257385\", \"3 1 5\", \"82 69 64\", \"3 2 5\", \"82 69 103\", \"3 2 1\", \"82 69 114\", \"3 2 0\", \"98 69 114\", \"560118409912468 316250877917599 681260158257385\", \"5 1 5\", \"82 69 30\", \"82 69 73\", \"82 78 114\", \"98 69 148\", \"560118409912468...
Problem If you bring an empty bottle of $ a $ milk, you can exchange it for a new bottle of $ b $ milk. How many bottles of milk can Mr. Kawabayashi, who initially has a bottle of $ x $ milk, drink? Output the remainder after dividing by $ 1000000007 $. Constraints The input satisfies the following conditions. * $ ...
0
{"tests": "{\"inputs\": [\"3 10\\n0 0 1\\n0 0 2\\n0 0 3\\n0 1 4\\n0 1 5\\n2 1 0\\n0 2 6\\n1 0\\n1 1\\n1 2\", \"3 10\\n0 0 1\\n0 0 2\\n0 0 3\\n0 1 4\\n0 1 5\\n2 1 0\\n0 2 9\\n1 0\\n1 1\\n1 2\", \"3 10\\n0 0 1\\n0 0 2\\n0 0 3\\n0 1 4\\n0 1 5\\n2 2 0\\n0 2 6\\n1 0\\n1 1\\n1 2\", \"3 10\\n0 0 1\\n0 0 2\\n0 0 3\\n0 1 4\\n0 ...
For $n$ lists $L_i$ $(i = 0, 1, ..., n-1)$, perform a sequence of the following operations. * insert($t$, $x$): Insert an integer $x$ at the end of $L_t$. * dump($t$): Print all elements in $L_t$. * splice($s$, $t$): Transfer elements of $L_s$ to the end of $L_t$. $L_s$ becomes empty. In the initial state, $L_i$ $(...
0
{"tests": "{\"inputs\": [\"3\\n4\\n1 2 2 3\\n2\\n1 2\\n7\\n1 2 3 4 5 6 7\", \"3\\n4\\n1 2 2 3\\n2\\n1 2\\n7\\n1 0 3 4 5 6 7\", \"3\\n4\\n1 4 2 3\\n2\\n1 2\\n7\\n1 0 3 4 5 6 7\", \"3\\n4\\n0 2 2 3\\n2\\n1 2\\n7\\n1 2 3 4 5 6 7\", \"3\\n4\\n1 4 2 3\\n2\\n1 1\\n20\\n2 0 3 4 1 6 7\", \"3\\n4\\n1 4 0 3\\n2\\n1 1\\n20\\n2 0 ...
Did you know that Chwee kueh, a cuisine of Singapore, means water rice cake ? Its a variety of the most popular South Indian savory cake, only that we call it here idli :). The tastiest idlis are made in Chennai, by none other than our famous chef, Dexter Murugan. Being very popular, he is flown from Marina to Miami, t...
0.75
{"tests": "{\"inputs\": [\"4 1\\n\", \"1 2\\n\", \"3 4\\n\", \"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\", \"1000 1100\\n\", \"27 3\\n\", \"2 1\\n\", \"10 10\\n\", \"653 87\\n\", \"212 234\\n\",...
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...
0
{"tests": "{\"inputs\": [\"4\\n5\\nsouse\\nhouhe\\n3\\ncat\\ndog\\n2\\naa\\naz\\n3\\nabc\\nbca\\n\", \"4\\n5\\nsouse\\nhouhe\\n3\\ncat\\ndog\\n2\\naa\\naz\\n3\\nabc\\nbca\\n\", \"4\\n5\\nsouse\\nhouhe\\n3\\ncat\\ndog\\n2\\naa\\nza\\n3\\nabc\\nbca\\n\", \"4\\n5\\nsouse\\nhouhf\\n3\\ncat\\ndog\\n2\\naa\\naz\\n3\\nabc\\nb...
This problem is different from the easy version. In this version Ujan makes at most 2n swaps. In addition, k ≤ 1000, n ≤ 50 and it is necessary to print swaps themselves. You can hack this problem if you solve it. But you can hack the previous problem only if you solve both problems. After struggling and failing many ...
0
{"tests": "{\"inputs\": [\"3\\n1 3 2 4\\n4 5 6 7\\n3 4 5 5\\n\", \"6\\n1 5 2 9\\n2 4 5 8\\n3 6 7 11\\n7 10 12 16\\n8 11 13 17\\n9 12 14 18\\n\", \"2\\n1 2 3 6\\n3 4 7 8\\n\", \"4\\n1 5 1 3\\n2 6 2 4\\n3 7 3 5\\n4 8 4 6\\n\", \"4\\n1 5 1 5\\n2 3 2 3\\n4 6 6 8\\n100 200 100 200\\n\", \"4\\n1 2 5 6\\n2 3 1 2\\n5 6 2 3\\n6...
Filled with optimism, Hyunuk will host a conference about how great this new year will be! The conference will have n lectures. Hyunuk has two candidate venues a and b. For each of the n lectures, the speaker specified two time intervals [sa_i, ea_i] (sa_i ≤ ea_i) and [sb_i, eb_i] (sb_i ≤ eb_i). If the conference is s...
0.875
{"tests": "{\"inputs\": [\"5\\n3\\n2\\n1\\n4\\n5\\n\", \"31\\n2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 1 22 23 24 25 26 27 28 29 30 31\\n\", \"26\\n12 8 5 1 3 4 6 7 9 10 13 14 15 16 18 19 20 2 11 17 21 22 23 24 25 26\\n\", \"73\\n14 61 69 73 59 26 8 2 65 51 68 3 22 31 30 36 5 64 60 62 9 24 48 46 12 19 18 52 ...
This is an interactive problem. Homer likes arrays a lot and he wants to play a game with you. Homer has hidden from you a permutation a_1, a_2, ..., a_n of integers 1 to n. You are asked to find any index k (1 ≤ k ≤ n) which is a local minimum. For an array a_1, a_2, ..., a_n, an index i (1 ≤ i ≤ n) is said to be...
0
{"tests": "{\"inputs\": [\"1\\n1 0 0 1 0\\n\", \"10\\n2 0 0 1 1\\n1 1 1 2 1\\n2 1 0 1 2\\n1 1 0 1 1\\n2 1 0 2 1\\n1 1 1 2 1\\n1 2 1 3 1\\n2 0 0 1 1\\n1 1 0 1 1\\n1 1 2 2 2\\n\", \"1\\n1 0 0 1 0\\n\", \"1\\n2 0 0 1 1\\n\", \"1\\n2 0 1 2 1\\n\", \"1\\n1 1 0 1 1\\n\", \"1\\n1 0 1 2 0\\n\", \"1\\n1 1 0 2 0\\n\", \"1\\n1 1 ...
Input The first line of the input contains a single integer N (1 ≤ N ≤ 24). The next N lines contain 5 space-separated integers each. The first three integers will be between 0 and 2, inclusive. The last two integers will be between 0 and 3, inclusive. The sum of the first three integers will be equal to the sum of ...
0
{"tests": "{\"inputs\": [\"2 3\\n3 4 5\\n3 9 1\\n\", \"3 4\\n1 0 0 0\\n0 0 3 0\\n0 0 5 5\\n\", \"7 4\\n0 0 0 0\\n0 1 0 3\\n0 1 0 0\\n0 0 3 0\\n0 0 0 2\\n0 3 0 1\\n0 0 2 6\\n\", \"1 1\\n0\\n\", \"4 7\\n91811 50656 97940 70982 88108 31856 80371\\n94488 4672 15935 10209 22935 55803 57593\\n79510 213 92494 7670 49727 97141...
A widely known among some people Belarusian sport programmer Yura possesses lots of information about cars. That is why he has been invited to participate in a game show called "Guess That Car!". The game show takes place on a giant parking lot, which is 4n meters long from north to south and 4m meters wide from west ...
0.25
{"tests": "{\"inputs\": [\"1 10\\n\", \"3 8\\n\", \"8 100\\n\", \"514853447 9\\n\", \"7 63\\n\", \"9 95\\n\", \"333734901 647005907\\n\", \"602799218 494169337\\n\", \"6 29\\n\", \"1 3\\n\", \"3 1\\n\", \"2 3\\n\", \"6 5\\n\", \"523061914 144515354\\n\", \"2 81\\n\", \"3 27\\n\", \"357780112 9\\n\", \"528551307 729\\n\...
An expedition group flew from planet ACM-1 to Earth in order to study the bipedal species (its representatives don't even have antennas on their heads!). The flying saucer, on which the brave pioneers set off, consists of three sections. These sections are connected by a chain: the 1-st section is adjacent only to the...
0
{"tests": "{\"inputs\": [\"3 6 9\\n\", \"4 4 4\\n\", \"0 0 0\\n\", \"0 1 0\\n\", \"2 2 0\\n\", \"7 8 9\\n\", \"666806767 385540591 357848286\\n\", \"3 3 5\\n\", \"494914467 356982656 757942689\\n\", \"242854896 442432924 180395753\\n\", \"32 62 92\\n\", \"8 8 9\\n\", \"139978911 5123031 935395222\\n\", \"937984449 1844...
Fox Ciel has some flowers: r red flowers, g green flowers and b blue flowers. She wants to use these flowers to make several bouquets. There are 4 types of bouquets: * To make a "red bouquet", it needs 3 red flowers. * To make a "green bouquet", it needs 3 green flowers. * To make a "blue bouquet", it needs 3 ...
0.25
{"tests": "{\"inputs\": [\"5 5 5 6\\n\", \"4 3 1 6\\n\", \"1 4 6 2\\n\", \"8 1 1 8\\n\", \"1 3 1 6\\n\", \"6 7 4 1\\n\", \"1 7 5 4\\n\", \"1 5 2 7\\n\", \"4 2 6 4\\n\", \"1 2 3 2\\n\", \"3 3 1 5\\n\", \"1 1 8 1\\n\", \"1 3 3 7\\n\", \"3 8 7 2\\n\", \"1 1 8 8\\n\", \"8 1 1 1\\n\", \"6 5 1 4\\n\", \"8 1 8 8\\n\", \"1 8 8...
Little Petya is learning to play chess. He has already learned how to move a king, a rook and a bishop. Let us remind you the rules of moving chess pieces. A chessboard is 64 square fields organized into an 8 × 8 table. A field is represented by a pair of integers (r, c) — the number of the row and the number of the co...
0.25
{"tests": "{\"inputs\": [\"10 2\\n2\\n7\\n3\\n9\\n8\\n7\\n9\\n7\\n1\\n9\\n\", \"10 5\\n2\\n7\\n3\\n9\\n8\\n7\\n9\\n7\\n1\\n9\\n\", \"2 1\\n2\\n1\\n\", \"10 2\\n2\\n7\\n3\\n9\\n8\\n7\\n9\\n4\\n1\\n9\\n\", \"10 5\\n2\\n7\\n3\\n9\\n8\\n7\\n9\\n7\\n1\\n18\\n\", \"10 5\\n2\\n7\\n3\\n9\\n8\\n7\\n9\\n7\\n1\\n13\\n\", \"2 2\\n...
This problem consists of three subproblems: for solving subproblem F1 you will receive 8 points, for solving subproblem F2 you will receive 15 points, and for solving subproblem F3 you will receive 10 points. Manao has developed a model to predict the stock price of a company over the next n days and wants to design a...
0.125
{"tests": "{\"inputs\": [\"4\\n\", \"77\\n\", \"7\\n\", \"7747\\n\", \"447\\n\", \"7474747\\n\", \"77474\\n\", \"774477\\n\", \"774\\n\", \"477477447\\n\", \"777774\\n\", \"777744747\\n\", \"47\\n\", \"747777\\n\", \"7774477\\n\", \"444\\n\", \"7747474\\n\", \"444444444\\n\", \"7444\\n\", \"4447\\n\", \"4447744\\n\", \...
Once again Tavas started eating coffee mix without water! Keione told him that it smells awful, but he didn't stop doing that. That's why Keione told his smart friend, SaDDas to punish him! SaDDas took Tavas' headphones and told him: "If you solve the following problem, I'll return it to you." <image> The problem is:...
0.25
{"tests": "{\"inputs\": [\"100 50 2\\n50 25\\n50 25\\n\", \"3 4 0\\n\", \"2 2 1\\n1 2\\n\", \"20 20 5\\n10 6\\n6 8\\n16 11\\n11 11\\n7 15\\n\", \"66 94 26\\n11 75\\n46 72\\n55 74\\n34 10\\n33 84\\n25 11\\n13 23\\n27 73\\n45 22\\n54 34\\n53 63\\n28 8\\n57 46\\n26 78\\n52 46\\n32 38\\n22 55\\n17 71\\n56 18\\n9 60\\n31 54...
Volodya and Vlad play the following game. There are k pies at the cells of n × m board. Each turn Volodya moves one pie to the neighbouring (by side) cell. If the pie lies at the border of the board then Volodya can move it outside the board, get the pie and win. After Volodya's move, Vlad bans some edge at the border ...
0
{"tests": "{\"inputs\": [\"7 2\\n1 5 6 2\\n1 3\\n3 2\\n4 5\\n3 7\\n4 3\\n4 6\\n\", \"9 3\\n3 2 1 6 5 9\\n8 9\\n3 2\\n2 7\\n3 4\\n7 6\\n4 5\\n2 1\\n2 8\\n\", \"6 1\\n4 5\\n1 2\\n1 3\\n1 4\\n1 5\\n1 6\\n\", \"3 1\\n2 1\\n1 2\\n2 3\\n\", \"5 1\\n1 2\\n1 2\\n2 3\\n3 4\\n4 5\\n\", \"41 3\\n11 10 15 35 34 6\\n28 2\\n25 3\\n9...
Treeland is a country in which there are n towns connected by n - 1 two-way road such that it's possible to get from any town to any other town. In Treeland there are 2k universities which are located in different towns. Recently, the president signed the decree to connect universities by high-speed network.The Min...
0.125
{"tests": "{\"inputs\": [\"4 3\\n1 2\\n2 3\\n2 4\\n\", \"5 2\\n1 2\\n2 3\\n3 4\\n2 5\\n\", \"3 3\\n1 2\\n3 2\\n\", \"8 3\\n2 1\\n3 1\\n4 3\\n5 1\\n6 1\\n7 1\\n8 6\\n\", \"10 4\\n5 4\\n8 3\\n4 6\\n5 3\\n7 9\\n1 3\\n5 10\\n2 9\\n9 8\\n\", \"2 2\\n2 1\\n\", \"3 3\\n2 1\\n3 1\\n\", \"34 33\\n2 1\\n3 2\\n4 3\\n5 2\\n6 3\\n7...
Alice got tired of playing the tag game by the usual rules so she offered Bob a little modification to it. Now the game should be played on an undirected rooted tree of n vertices. Vertex 1 is the root of the tree. Alice starts at vertex 1 and Bob starts at vertex x (x ≠ 1). The moves are made in turns, Bob goes first...
0.25
{"tests": "{\"inputs\": [\"2 2\\n5 8\\n\", \"1 2\\n7 1\\n\", \"1 4\\n2 2 1 2\\n\", \"1 2\\n4 4\\n\", \"1 4\\n1 2 2 2\\n\", \"8459 91\\n778 338 725 1297 115 540 1452 2708 193 1806 1496 1326 2648 176 199 93 342 3901 2393 2718 800 3434 657 4037 291 690 1957 3280 73 6011 2791 1987 440 455 444 155 261 234 829 1309 1164 616 ...
Daenerys Targaryen has an army consisting of k groups of soldiers, the i-th group contains ai soldiers. She wants to bring her army to the other side of the sea to get the Iron Throne. She has recently bought an airplane to carry her army through the sea. The airplane has n rows, each of them has 8 seats. We call two s...
0
{"tests": "{\"inputs\": [\"4\\n1 5\\n5 2\\n3 7\\n7 3\\n\", \"5\\n1 10\\n2 10\\n3 10\\n4 10\\n5 5\\n\", \"1\\n1 2\\n\", \"30\\n22 37\\n12 37\\n37 58\\n29 57\\n43 57\\n57 58\\n58 53\\n45 4\\n1 4\\n4 51\\n35 31\\n21 31\\n31 51\\n51 53\\n53 48\\n60 55\\n52 55\\n55 33\\n36 9\\n10 9\\n9 33\\n33 19\\n5 23\\n47 23\\n23 32\\n50...
A new set of desks just arrived, and it's about time! Things were getting quite cramped in the office. You've been put in charge of creating a new seating chart for the engineers. The desks are numbered, and you sent out a survey to the engineering team asking each engineer the number of the desk they currently sit at,...
0
{"tests": "{\"inputs\": [\"2\\n2 2 2 2 10\\n2 3 5 7 1000\\n\\nSAMPLE\", \"2\\n2 2 2 2 10\\n2 3 1 7 1000\\n\\nSAMPLE\", \"2\\n2 2 2 2 16\\n1 3 1 7 1000\\n\\nSAMPKE\", \"2\\n2 2 2 2 19\\n2 7 1 7 1010\\n\\nSAMPLE\", \"2\\n2 2 2 1 16\\n1 4 2 7 1000\\n\\nSAMPKE\", \"2\\n2 2 2 0 32\\n2 8 1 0 1010\\n\\nSAMPLE\", \"2\\n2 2 2 2...
Foo was not amongst the most brilliant students of his class. So, he has some pending exams to clear. As the exams are approaching, this time he vowed to pass in all of them. This will only happen if he is not under stress. Foo's stress can be calculated using a simple function called Foo_function which depends upon th...
0.5
{"tests": "{\"inputs\": [\"3\\n10\\n20\\n30\\n\\nSAMPLE\", \"100\\n10\\n10\\n10\\n9\\n10\\n8\\n10\\n9\\n10\\n10\\n8\\n10\\n10\\n10\\n10\\n10\\n10\\n9\\n10\\n10\\n8\\n10\\n10\\n9\\n7\\n10\\n10\\n10\\n10\\n10\\n9\\n10\\n10\\n10\\n9\\n9\\n10\\n10\\n9\\n10\\n10\\n10\\n10\\n10\\n7\\n10\\n10\\n10\\n9\\n10\\n10\\n10\\n10\\n10...
Rahul has set upon the quest for a new logo of his company. He has created the following continuous logo: /\ / \ / /\ \ / / \ \ / / /\ \ \ \ \ \/ / / \ \ / / \ \/ / \ / \/ However, his sister, Rashi, likes the following discontinuous design more /\ / \ / /\ \ / / \ \ \...
0
{"tests": "{\"inputs\": [\"5 7\\n1 2 3 4 5\\n1 0 5\\n0 2 4 100 101\\n1 0 3\\n0 1 3 102 103\\n1 2 5\\n0 2 5 104 105\\n1 0 5\", \"5 7\\n1 2 3 4 5\\n1 0 5\\n0 2 4 100 101\\n1 0 3\\n0 1 5 102 103\\n1 2 5\\n0 2 5 104 105\\n1 0 5\", \"5 7\\n1 2 3 4 5\\n1 0 5\\n0 2 4 100 101\\n1 0 3\\n0 2 5 102 103\\n1 2 5\\n0 2 5 104 105\\n1...
You are given an array a_0, a_1, ..., a_{N-1} of length N. Process Q queries of the following types. * `0 l r b c`: For each i = l, l+1, \dots, {r - 1}, set a_i \gets b \times a_i + c. * `1 l r`: Print \sum_{i = l}^{r - 1} a_i \bmod 998244353. Constraints * 1 \leq N, Q \leq 500000 * 0 \leq a_i, c < 998244353 * 1 \le...
0
{"tests": "{\"inputs\": [\"3 2\", \"100000 50000\", \"10 10\", \"2 2\", \"100001 50000\", \"5 10\", \"0 2\", \"100001 27098\", \"5 7\", \"101001 27098\", \"6 7\", \"101000 27098\", \"3 7\", \"101000 9586\", \"3 10\", \"101000 14296\", \"2 10\", \"101000 4853\", \"101000 3325\", \"101001 3325\", \"101001 365\", \"101011...
We have a sequence of N integers: x=(x_0,x_1,\cdots,x_{N-1}). Initially, x_i=0 for each i (0 \leq i \leq N-1). Snuke will perform the following operation exactly M times: * Choose two distinct indices i, j (0 \leq i,j \leq N-1,\ i \neq j). Then, replace x_i with x_i+2 and x_j with x_j+1. Find the number of differe...
0
{"tests": "{\"inputs\": [\"2 3 1 1\", \"100000 100000 99999 99999\", \"100000 100000 44444 55555\", \"10 7 3 4\", \"10 7 6 4\", \"10 8 6 4\", \"17 8 6 4\", \"17 8 6 6\", \"2 4 1 1\", \"100000 100000 99999 72298\", \"100000 100000 43938 55555\", \"10 13 6 4\", \"17 8 5 6\", \"3 4 1 1\", \"100000 100000 99999 39553\", \"...
We have a large square grid with H rows and W columns. Iroha is now standing in the top-left cell. She will repeat going right or down to the adjacent cell, until she reaches the bottom-right cell. However, she cannot enter the cells in the intersection of the bottom A rows and the leftmost B columns. (That is, there ...
0.125
{"tests": "{\"inputs\": [\"2 3\\n-2 -1 3\\n0 1 3\\n2 3 3\\n2 2\\n-2 0 4\\n0 2 3\\n2 6\\n-3 3 1\\n-2 3 2\\n-1 3 3\\n0 3 4\\n1 3 5\\n2 3 6\\n2 6\\n-3 3 1\\n-3 2 2\\n-3 1 3\\n-3 0 4\\n-3 -1 5\\n-3 -2 6\\n0 0\", \"2 3\\n-3 -1 3\\n0 1 3\\n2 3 3\\n2 2\\n-2 0 4\\n0 2 3\\n2 6\\n-3 3 1\\n-2 3 2\\n-1 3 3\\n0 3 4\\n1 3 5\\n2 3 6\...
Vampire Mr. C is a vampire. If he is exposed to the sunlight directly, he turns into ash. Nevertheless, last night, he attended to the meeting of Immortal and Corpse Programmers Circle, and he has to go home in the near dawn. Fortunately, there are many tall buildings around Mr. C's home, and while the sunlight is blo...
0
{"tests": "{\"inputs\": [\"2015 3 13 2015 3 13\", \"2015 2 14 2015 3 15\", \"1234 5 6 789012345678901234 5 6\", \"2015 3 2 2015 3 13\", \"1045 2 14 2015 3 15\", \"1234 5 4 789012345678901234 5 6\", \"2015 3 3 2015 2 13\", \"2015 3 6 3448 2 13\", \"2015 2 6 3448 3 13\", \"2015 2 6 3516 3 13\", \"3203 2 2 3516 3 13\", \"...
Problem "Ritsumeikan University Competitive Programming Camp" will be held this year as well. I am very much looking forward to this annual training camp. However, I couldn't stand my desires and splurged before the training camp, so I couldn't afford it. So I decided to use the cheapest Seishun 18 Ticket to get to Mi...
0
{"tests": "{\"inputs\": [\"3 2\\n5 2 1 3\\n8 2 2 3\\n2 3\\n8 2 1 2\\n3 1 1\\n5 1 2\\n2 5\\n100 1 1\\n100 1 1\\n100 1 1\\n100 1 1\\n100 1 1\\n3 4\\n5 1 1\\n5 1 2\\n100 2 1 3\\n100 2 2 3\\n0 0\", \"3 2\\n5 2 1 3\\n8 2 2 3\\n2 3\\n8 2 1 2\\n3 1 1\\n5 1 2\\n2 5\\n100 1 1\\n000 1 1\\n100 1 1\\n100 1 1\\n100 1 1\\n3 4\\n5 1 ...
quiz You are the director of a quiz show. N people will appear in the quiz show as answerers, each numbered from 1 to N. Questions will be M + 1 questions, and each question is numbered from 1 to M + 1. Questions are given in numerical order, and points are given only to the person who answers correctly first by pres...
0
{"tests": "{\"inputs\": [\"4 6\", \"2 6\", \"6 7\", \"5 7\", \"10 11\", \"4 5\", \"9 64\", \"8 11\", \"7 9\", \"7 16\", \"10 31\", \"14 61\", \"23 64\", \"17 31\", \"23 70\", \"12 49\", \"24 78\", \"45 78\", \"68 78\", \"16 75\", \"3 4\", \"16 102\", \"5 11\", \"8 17\", \"9 37\", \"10 45\", \"17 60\", \"25 70\", \"19 4...
D: Is greed the best? story In Japan, where there are 1, 5, 10, 50, 100, 500 yen coins, it is known that the number of coins can be minimized by using as many coins as possible when paying a certain amount. .. If the amount of coins is different from that of Japan, it is not always possible to minimize it by paying ...
0
{"tests": "{\"inputs\": [\"3\\na\\naa\\naa\\na\\n\", \"5\\nba\\na\\nabab\\na\\naba\\nbaba\\nab\\naba\\n\", \"2\\na\\nc\\n\", \"5\\na\\na\\nab\\nba\\naba\\naba\\nbaba\\nabab\\n\", \"4\\nab\\na\\nb\\nbab\\nab\\naba\\n\", \"5\\na\\naa\\naaa\\naaaa\\nb\\nba\\nbaa\\nbaaa\\n\", \"4\\na\\nba\\naba\\nb\\nba\\nbab\\n\", \"4\\na...
Ivan wants to play a game with you. He picked some string s of length n consisting only of lowercase Latin letters. You don't know this string. Ivan has informed you about all its improper prefixes and suffixes (i.e. prefixes and suffixes of lengths from 1 to n-1), but he didn't tell you which strings are prefixes an...
0.125
{"tests": "{\"inputs\": [\"4 5 4\\n4 4 5 1\\n15\\n9\\n13\\n6\\n\", \"6 4 10\\n3 1 1 1 2 2\\n7\\n8\\n9\\n10\\n11\\n12\\n13\\n14\\n15\\n16\\n\", \"100 21 20\\n11 17 21 14 7 15 18 6 17 11 21 3 17 21 21 7 21 17 14 21 14 14 3 6 18 21 17 17 18 14 14 21 15 13 3 15 11 11 16 11 6 10 15 17 11 15 13 13 21 16 21 13 11 14 21 21 13 ...
Misha was interested in water delivery from childhood. That's why his mother sent him to the annual Innovative Olympiad in Irrigation (IOI). Pupils from all Berland compete there demonstrating their skills in watering. It is extremely expensive to host such an olympiad, so after the first n olympiads the organizers int...
0
{"tests": "{\"inputs\": [\"4 5 2\\n1 10 1\\n1 10 2\\n1 10 3\\n1 20 4\\n1 100 5\\n\", \"3 4 3\\n1 3 1\\n2 4 4\\n2 3 3\\n2 2 2\\n\", \"50 50 1\\n1 1 1\\n1 1 2\\n1 1 3\\n1 1 4\\n1 1 5\\n1 1 6\\n1 1 7\\n1 1 8\\n1 1 9\\n1 1 10\\n1 1 11\\n1 1 12\\n1 1 13\\n1 1 14\\n1 1 15\\n1 1 16\\n1 1 17\\n1 1 18\\n1 1 19\\n1 1 20\\n1 1 21...
Yet another education system reform has been carried out in Berland recently. The innovations are as follows: An academic year now consists of n days. Each day pupils study exactly one of m subjects, besides, each subject is studied for no more than one day. After the lessons of the i-th subject pupils get the home ta...
0
{"tests": "{\"inputs\": [\"4\\n1 2\\n2 3\\n3 4\\n\", \"7\\n4 2\\n5 7\\n3 4\\n6 3\\n1 3\\n4 5\\n\", \"10\\n9 8\\n1 3\\n7 5\\n8 6\\n8 10\\n6 4\\n1 6\\n10 2\\n6 5\\n\", \"10\\n5 7\\n4 1\\n10 5\\n9 3\\n7 9\\n8 2\\n6 1\\n8 6\\n2 7\\n\", \"2\\n1 2\\n\", \"10\\n10 2\\n4 10\\n1 10\\n5 10\\n10 7\\n9 10\\n3 10\\n1 6\\n8 1\\n\", ...
This problem is split into two tasks. In this task, you are required to find the minimum possible answer. In the task Village (Maximum) you are required to find the maximum possible answer. Each task is worth 50 points. There are N houses in a certain village. A single villager lives in each of the houses. The houses ...
0
{"tests": "{\"inputs\": [\"7 8\\n3 6 7 9 10 7 239\\n8 1 9 7 10 2 6 239\\n3 2 1 3\\n2 4 1\\n3 1 3 7\\n2 4 3\\n5 3 4 5 6 7\\n2 5 7\\n1 8\\n\", \"3 2\\n1 2 3\\n4 5\\n2 1 2\\n2 1 2\\n2 1 2\\n\", \"2 2\\n1 1\\n1 1\\n2 1 2\\n2 1 2\\n\", \"2 2\\n1 2\\n1 1\\n2 1 2\\n2 1 2\\n\", \"7 8\\n3 6 7 9 10 7 239\\n8 1 9 7 10 2 6 92\\n3 ...
You are given m sets of integers A_1, A_2, …, A_m; elements of these sets are integers between 1 and n, inclusive. There are two arrays of positive integers a_1, a_2, …, a_m and b_1, b_2, …, b_n. In one operation you can delete an element j from the set A_i and pay a_i + b_j coins for that. You can make several (ma...
0
{"tests": "{\"inputs\": [\"4\\n01\\n01\\n10\\n10\\n\", \"6\\n10\\n10\\n10\\n01\\n10\\n10\\n\", \"1\\n10\\n\", \"3\\n10\\n01\\n10\\n\", \"3\\n10\\n10\\n01\\n\", \"115\\n10\\n10\\n10\\n10\\n01\\n01\\n10\\n10\\n10\\n01\\n01\\n10\\n01\\n01\\n10\\n10\\n10\\n01\\n10\\n01\\n10\\n10\\n01\\n01\\n10\\n10\\n10\\n10\\n01\\n10\\n01...
Mad scientist Mike entertains himself by arranging rows of dominoes. He doesn't need dominoes, though: he uses rectangular magnets instead. Each magnet has two poles, positive (a "plus") and negative (a "minus"). If two magnets are put together at a close distance, then the like poles will repel each other and the oppo...
0
{"tests": "{\"inputs\": [\"100 3\\n1 2\\n2 1\\n3 1\\n\", \"1 2\\n1 1\\n2 100\\n\", \"5 2\\n1 2\\n2 3\\n\", \"58 38\\n6384 48910\\n97759 90589\\n28947 5031\\n45169 32592\\n85656 26360\\n88538 42484\\n44042 88351\\n42837 79021\\n96022 59200\\n485 96735\\n98000 3939\\n3789 64468\\n10894 58484\\n26422 26618\\n25515 95617\\...
Let's call an array consisting of n integer numbers a1, a2, ..., an, beautiful if it has the following property: * consider all pairs of numbers x, y (x ≠ y), such that number x occurs in the array a and number y occurs in the array a; * for each pair x, y must exist some position j (1 ≤ j < n), such that at leas...
0
{"tests": "{\"inputs\": [\"3\\n1 2\\n2 4\\n1 10\\n\", \"18\\n1 10\\n1 100\\n1 1000\\n1 10000\\n1 100000\\n1 1000000\\n1 10000000\\n1 100000000\\n1 1000000000\\n1 10000000000\\n1 100000000000\\n1 1000000000000\\n1 10000000000000\\n1 100000000000000\\n1 1000000000000000\\n1 10000000000000000\\n1 100000000000000000\\n1 10...
Let's denote as <image> the number of bits set ('1' bits) in the binary representation of the non-negative integer x. You are given multiple queries consisting of pairs of integers l and r. For each query, find the x, such that l ≤ x ≤ r, and <image> is maximum possible. If there are multiple such numbers find the sma...
0
{"tests": "{\"inputs\": [\"1 5\\n2 3\\n\", \"2 4\\n1 1 1 1\\n\", \"3 18\\n4 4 4 2 2 2\\n\", \"4 1000000000\\n1 1 1 1 2 2 2 2\\n\", \"4 30\\n3 3 3 3 4 5 6 7\\n\", \"2 19\\n3 3 5 5\\n\", \"4 1000000000\\n1 1 1 1 1 1 1 1\\n\", \"4 1\\n3 3 3 3 4 4 4 4\\n\", \"1 100\\n1 200\\n\", \"1 1\\n1 1\\n\", \"2 100\\n1 1 1 10\\n\", \...
Pasha decided to invite his friends to a tea party. For that occasion, he has a large teapot with the capacity of w milliliters and 2n tea cups, each cup is for one of Pasha's friends. The i-th cup can hold at most ai milliliters of water. It turned out that among Pasha's friends there are exactly n boys and exactly n...
0
{"tests": "{\"inputs\": [\"4 4\\n\", \"3 5\\n\", \"1 4\\n\", \"7 2\\n\", \"100 25\\n\", \"29 1\\n\", \"3 73\\n\", \"14 15\\n\", \"1 1\\n\", \"24 57\\n\", \"1 2\\n\", \"3 2\\n\", \"24 15\\n\", \"2 97\\n\", \"15 31\\n\", \"15 25\\n\", \"2 3\\n\", \"8 8\\n\", \"2 99\\n\", \"59 45\\n\", \"23 12\\n\", \"3 1\\n\", \"74 25\\n...
Friends are going to play console. They have two joysticks and only one charger for them. Initially first joystick is charged at a1 percent and second one is charged at a2 percent. You can connect charger to a joystick only at the beginning of each minute. In one minute joystick either discharges by 2 percent (if not c...
0
{"tests": "{\"inputs\": [\"0 0 2 4\\n1 1\\n1 2\\n\", \"0 0 2 3\\n1 1\\n1 2\\n\", \"3 -1 20 200\\n19 12\\n24 121\\n25 32\\n28 19\\n28 87\\n29 49\\n32 88\\n33 70\\n37 77\\n54 33\\n56 27\\n61 59\\n67 42\\n73 15\\n76 40\\n80 73\\n83 39\\n91 34\\n91 112\\n95 95\\n\", \"0 0 5 100\\n17 3\\n42 24\\n72 22\\n72 25\\n120 25\\n\",...
Anton and Dasha like to play different games during breaks on checkered paper. By the 11th grade they managed to play all the games of this type and asked Vova the programmer to come up with a new game. Vova suggested to them to play a game under the code name "dot" with the following rules: * On the checkered pape...
0.25
{"tests": "{\"inputs\": [\"4 2 11\\n2 4 6 6\\n6 4 2 1\\n1 2\\n2 3\\n\", \"3 1 5\\n3 2 5\\n2 4 2\\n1 2\\n\", \"10 5 100\\n64 90 3 94 96 97 52 54 82 31\\n796554 444893 214351 43810 684158 555762 686198 339093 383018 699152\\n6 8\\n8 3\\n3 9\\n2 3\\n10 3\\n\", \"10 5 100\\n48 73 30 46 95 19 98 73 94 24\\n501216 675859 843...
Just to remind, girls in Arpa's land are really nice. Mehrdad wants to invite some Hoses to the palace for a dancing party. Each Hos has some weight wi and some beauty bi. Also each Hos may have some friends. Hoses are divided in some friendship groups. Two Hoses x and y are in the same friendship group if and only if...
0.375
{"tests": "{\"inputs\": [\"50 2\\n100 25\\n\", \"400 4\\n100 300 450 500\\n\", \"852 10\\n668 1000 1000 1000 1000 1000 1000 639 213 1000\\n\", \"314 15\\n160 769 201 691 358 724 248 47 420 432 667 601 596 370 469\\n\", \"834 10\\n921 995 1000 285 1000 166 1000 999 991 983\\n\", \"971 108\\n706 706 991 706 988 997 996 9...
Sasha and Kolya decided to get drunk with Coke, again. This time they have k types of Coke. i-th type is characterised by its carbon dioxide concentration <image>. Today, on the party in honour of Sergiy of Vancouver they decided to prepare a glass of Coke with carbon dioxide concentration <image>. The drink should als...
0
{"tests": "{\"inputs\": [\"8\\n! hello\\n! codeforces\\n? c\\n. o\\n? d\\n? h\\n. l\\n? e\\n\", \"7\\n! ababahalamaha\\n? a\\n? b\\n? a\\n? b\\n? a\\n? h\\n\", \"5\\n! abc\\n. ad\\n. b\\n! cd\\n? c\\n\", \"3\\n. abcdefghijklmnopqrstuvwxy\\n? a\\n? z\\n\", \"3\\n. abcdefghijklmnopqrstuvwxy\\n! z\\n? z\\n\", \"1\\n? q\\n...
Valentin participates in a show called "Shockers". The rules are quite easy: jury selects one letter which Valentin doesn't know. He should make a small speech, but every time he pronounces a word that contains the selected letter, he receives an electric shock. He can make guesses which letter is selected, but for eac...
0
{"tests": "{\"inputs\": [\"19 00\\n255 1 100 1\\n\", \"17 41\\n1000 6 15 11\\n\", \"00 10\\n33077 21 40 22\\n\", \"17 31\\n9603 53 73 74\\n\", \"01 38\\n70542 27 74 26\\n\", \"14 53\\n76530 92 4 22\\n\", \"18 06\\n88580 22 35 59\\n\", \"10 44\\n66449 67 90 83\\n\", \"00 00\\n100000 100 100 100\\n\", \"20 58\\n93398 43 ...
After waking up at hh:mm, Andrew realised that he had forgotten to feed his only cat for yet another time (guess why there's only one cat). The cat's current hunger level is H points, moreover each minute without food increases his hunger by D points. At any time Andrew can visit the store where tasty buns are sold (y...
0.625
{"tests": "{\"inputs\": [\"6\\n1 2\\n2 3\\n3 4\\n2 5\\n3 6\\n\", \"4\\n1 2\\n2 3\\n3 4\\n\", \"5\\n1 2\\n1 3\\n1 4\\n1 5\\n\", \"9\\n1 2\\n1 3\\n1 4\\n1 5\\n1 6\\n6 7\\n7 8\\n7 9\\n\", \"8\\n1 2\\n1 3\\n1 4\\n1 8\\n7 8\\n6 8\\n5 8\\n\", \"3\\n2 3\\n1 2\\n\", \"2\\n1 2\\n\", \"9\\n1 2\\n2 3\\n1 4\\n1 5\\n1 6\\n6 7\\n7 8...
Ramesses knows a lot about problems involving trees (undirected connected graphs without cycles)! He created a new useful tree decomposition, but he does not know how to construct it, so he asked you for help! The decomposition is the splitting the edges of the tree in some simple paths in such a way that each two pa...
0
{"tests": "{\"inputs\": [\"2\\n5\\n2 3 2 4 6\\n3\\n2 99 101\\n\\nSAMPLE\", \"2\\n5\\n2 3 2 4 6\\n3\\n3 99 101\\n\\nSAMPLE\", \"2\\n5\\n2 3 2 4 6\\n3\\n3 42 101\\n\\nSAMPLE\", \"2\\n5\\n2 5 2 4 6\\n3\\n3 83 111\\n\\nSAMOLE\", \"2\\n5\\n2 3 2 8 6\\n3\\n3 83 101\\n\\nSAMOLE\", \"2\\n5\\n2 3 2 6 6\\n3\\n3 83 111\\n\\nSAMOL...
You are given N sticks, the length of the i^th stick being ai . As your professor is very interested in triangles he gives you a problem: From the N given sticks, choose 3 sticks that form a triangle. If there are many such triangles , choose the sticks in such a way such that the perimeter of the triangle formed is ma...
0
{"tests": "{\"inputs\": [\"3\\n5\\n5\\n1\", \"6\\n3\\n1\\n4\\n1\\n5\\n9\", \"5\\n6\\n8\\n1\\n2\\n3\", \"3\\n5\\n6\\n1\", \"6\\n6\\n1\\n4\\n1\\n5\\n9\", \"5\\n6\\n8\\n1\\n1\\n3\", \"3\\n5\\n3\\n1\", \"6\\n6\\n1\\n4\\n1\\n1\\n9\", \"5\\n6\\n4\\n1\\n1\\n3\", \"3\\n0\\n3\\n1\", \"6\\n6\\n1\\n7\\n1\\n1\\n9\", \"5\\n6\\n4\\n...
You are given N integers; the i-th of them is A_i. Find the maximum possible sum of the absolute differences between the adjacent elements after arranging these integers in a row in any order you like. Constraints * 2 \leq N \leq 10^5 * 1 \leq A_i \leq 10^9 * All values in input are integers. Input Input is given f...
0