info
stringlengths
120
50k
question
stringlengths
504
10.4k
avg@8_qwen3_4b_instruct_2507
float64
0
0.88
{"tests": "{\"inputs\": [\"50 30 10 10\\n\", \"100 50 10 21\\n\", \"3 2 1 1\\n\", \"50 30 10 5\\n\", \"50 49 5 10\\n\", \"50 20 4 8\\n\", \"100 50 3 1\\n\", \"60 30 10 1\\n\", \"99 22 13 14\\n\", \"99 50 25 49\\n\", \"100 40 30 40\\n\", \"99 32 13 5\\n\", \"40 30 20 10\\n\", \"100 50 19 30\\n\", \"5 4 3 1\\n\", \"100 9...
A family consisting of father bear, mother bear and son bear owns three cars. Father bear can climb into the largest car and he likes it. Also, mother bear can climb into the middle car and she likes it. Moreover, son bear can climb into the smallest car and he likes it. It's known that the largest car is strictly larg...
0
{"tests": "{\"inputs\": [\"1\\n3 3 5\\n1 1\\n2 2\\n3 3\\n1 0\\n0 0\\n2 0\\n\\nSAMPLE\", \"1\\n3 3 5\\n1 1\\n2 2\\n3 3\\n1 0\\n0 0\\n2 0\\n\\nSAMPLF\", \"1\\n3 2 0\\n1 0\\n2 -1\\n5 3\\n1 1\\n2 1\\n2 1\\n\\nSPMALE\", \"1\\n3 3 5\\n1 1\\n2 2\\n3 3\\n1 0\\n0 0\\n4 0\\n\\nSAMPLF\", \"1\\n3 3 5\\n1 1\\n2 4\\n3 3\\n1 0\\n0 0\...
Navi is a counter strike pro. He always say how good he is at counter strike. After being tired of Navi, his friends decided to test his skills at shooting. They put M targets on a X-Y plane, each target is denoted by (X, Y) where X is x-coordinate and Y is y-coordinate. His friends also gave him N locations on X-Y pl...
0.75
{"tests": "{\"inputs\": [\"2 0\", \"20 10\\n10 18\\n11 17\\n14 7\\n4 6\\n30 28\\n19 24\\n29 22\\n25 32\\n38 34\\n36 39\", \"4 2\\n5 2\\n6 1\", \"20 10\\n10 18\\n11 17\\n14 7\\n4 5\\n30 28\\n19 24\\n29 22\\n25 32\\n38 34\\n36 39\", \"4 0\\n5 2\\n6 1\", \"20 10\\n10 18\\n21 17\\n14 7\\n4 5\\n30 28\\n19 24\\n29 22\\n25 32...
There are 2N points evenly spaced on the circumference of a circle. These points are numbered 1 to 2N in clockwise order, starting from some of them. Snuke will divide these points into N pairs, then for each pair, he will draw a line segment connecting the two points. After the line segments are drawn, two points are...
0
{"tests": "{\"inputs\": [\"bab\", \"abc\", \"aaa\", \"bac\", \"bba\", \"cab\", \"abb\", \"aab\", \"aac\", \"bbb\", \"baa\", \"caa\", \"bb`\", \"`bb\", \"aba\", \"acb\", \"_bb\", \"bcb\", \"aca\", \"b`b\", \"cba\", \"aa`\", \"b_b\", \"bbc\", \"cbb\", \"`aa\", \"cca\", \"cbc\", \"``b\", \"acc\", \"bca\", \"a`a\", \"ccb\"...
You are given a string S of length 3 consisting of `a`, `b` and `c`. Determine if S can be obtained by permuting `abc`. Constraints * |S|=3 * S consists of `a`, `b` and `c`. Input Input is given from Standard Input in the following format: S Output If S can be obtained by permuting `abc`, print `Yes`; otherwis...
0.625
{"tests": "{\"inputs\": [\"needed\", \"atcoder\", \"deened\", \"aoctder\", \"aocteer\", \"aectepp\", \"defnfd\", \"ndeedd\", \"defned\", \"fedned\", \"aocueer\", \"efdned\", \"aocueeq\", \"efnded\", \"aocueep\", \"dendfe\", \"peeucoa\", \"peetcoa\", \"aocteep\", \"aecteop\", \"aecsepp\", \"neeedd\", \"actoder\", \"deen...
Given a string t, we will call it unbalanced if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both `voodoo` and `melee` are unbalanced, while neither `noon` nor `a` is. You are given a string s consisting of lowercase letters. Determine if there exists a (...
0
{"tests": "{\"inputs\": [\"3 3\\nR G B\\nG G G\\nG B B\\n2 4\\nR G\\nG G\\nR B\\nB R\\n4 3\\nG G B R\\nG R R G\\nB G G R\\n0 0\", \"3 3\\nR G B\\nG G G\\nG B B\\n2 4\\nR G\\nG G\\nR B\\nB R\\n4 3\\nF G B R\\nG R R G\\nB G G R\\n0 0\", \"3 3\\nR G B\\nG G G\\nG B B\\n2 4\\nS G\\nG G\\nR B\\nB R\\n4 3\\nG G B R\\nG R R G...
The tablet interface technology, which can be operated by touching the screen with a finger, has also been applied in the field of games, and various types of games with new operability have been created. The game currently being developed by AZ is one of them. The requirements for this software (game) are as follows....
0.125
{"tests": "{\"inputs\": [\"4 4 2 1 4\\n1 2 2 1\\n2 3 2 1\\n3 4 5 1\\n2 4 4 2\\n3 1\\n3 6\\n10 5 3\\n\\n10\\n2 0 1 1 2\\n1\\n\\n1\\n4 5 2 4 1\\n4 3 10 1\\n3 2 2 1\\n3 2 1 2\\n3 2 5 2\\n2 1 10 1\\n3 3\\n20 30\\n3 2 1\\n5 10\\n3 2 1\\n5 5 2 1 5\\n1 2 10 2\\n1 3 20 2\\n2 4 20 1\\n3 4 10 1\\n4 5 20 1\\n2 2\\n20\\n4 1\\n20\\...
Tokyo has a very complex railway system. For example, there exists a partial map of lines and stations as shown in Figure D-1. <image> Figure D-1: A sample railway network Suppose you are going to station D from station A. Obviously, the path with the shortest distance is A->B->D. However, the path with the shortes...
0
{"tests": "{\"inputs\": [\"5 7\\nRRCABXT\\nAABMFAB\\nRROMJAC\\nAPTADAB\\nYABADAO\\n3 13\\nABCDEFGHIJKLM\\nXMADAMIMADAMY\\nACEGIKMOQSUWY\\n3 4\\nDEFG\\nACAB\\nHIJK\\n3 6\\nABCDEF\\nGHIAKL\\nMNOPQR\\n10 19\\nJFZODYDXMZZPEYTRNCW\\nXVGHPOKEYNZTQFZJKOD\\nEYEHHQKHFZOVNRGOOLP\\nQFZOIHRQMGHPNISHXOC\\nDRGILJHSQEHHQLYTILL\\nNCSH...
Your master went to the town for a day. You could have a relaxed day without hearing his scolding. But he ordered you to make donuts dough by the evening. Loving donuts so much, he can't live without eating tens of donuts everyday. What a chore for such a beautiful day. But last week, you overheard a magic spell that ...
0
{"tests": "{\"inputs\": [\"1 100\\n0 86400 1\\n1 100\\n43200 86400 1\\n0 0\", \"1 100\\n0 86400 1\\n1 110\\n43200 86400 1\\n0 0\", \"1 101\\n0 86400 1\\n1 100\\n43200 86400 1\\n0 0\", \"1 101\\n0 86400 1\\n1 000\\n43200 86400 1\\n0 0\", \"1 101\\n0 73100 1\\n1 000\\n43200 86400 1\\n0 0\", \"1 101\\n0 73100 1\\n1 000\\n...
You built an apartment. The apartment has a water tank with a capacity of L in order to store water for the residents. The tank works as a buffer between the water company and the residents. It is required to keep the tank "not empty" at least during use of water. A pump is used to provide water into the tank. From th...
0
{"tests": "{\"inputs\": [\"8 24\\n05:30 Kyoto 06:37 Maibara\\n06:50 Maibara 07:36 Tsuruga\\n07:42 Tsuruga 10:03 Kanazawa\\n10:58 Kanazawa 12:07 Toyama\\n12:15 Toyama 14:12 Naoetsu\\n14:29 Naoetsu 15:57 Nagaoka\\n16:11 Nagaoka 17:14 Niitsu\\n17:38 Niitsu 20:06 AizuWakamatsu\", \"N T\\nst_time1 st_name1 ar_time1 ar_name1...
Problem Statement Mr. Takatsuki, who is planning to participate in the Aizu training camp, has a poor house and does not have much money. Therefore, he is trying to save money by using the Seishun 18 Ticket. With only one 18 ticket, you can ride a local train all day long, and you can enter and exit the ticket gates f...
0
{"tests": "{\"inputs\": [\"3 3\\nB.B\\n..B\\n.BB\", \"3 3\\nA.B\\n..B\\n.BB\", \"3 3\\nB.B\\n..B\\n-BB\", \"1 3\\nAB.\\n.B.\\n.BB\", \"3 3\\nA.B\\nA..\\n.CB\", \"3 3\\nA.B\\n..B\\n.AA\", \"3 3\\nA.B\\nB..\\n.BB\", \"3 3\\nB.B\\nB..\\n.BB\", \"3 3\\nA.B\\n.B.\\n.BB\", \"3 3\\nA.B\\nA..\\n.BB\", \"3 3\\nB.B\\nA..\\n.BB\"...
A: Hokkaido University Easy Note Please note that the problem settings are the same as problem B, except for the constraints. story Homura-chan, who passed Hokkaido University and is excited about the beginning of a new life. But in front of her, a huge campus awaits ... "Eh ... I'm not in time for the next class ...
0
{"tests": "{\"inputs\": [\"3 5\\n0 0 1 1\\n0 1 2 3\\n0 2 2 2\\n1 0\\n1 1\", \"1 3\\n1 0\\n0 0 0 5\\n1 0\", \"3 5\\n0 0 1 1\\n0 1 2 3\\n0 0 2 2\\n1 0\\n1 1\", \"2 3\\n1 0\\n0 0 0 5\\n1 0\", \"3 5\\n0 0 1 1\\n0 1 2 3\\n0 0 2 2\\n1 0\\n0 1\", \"2 3\\n1 0\\n0 0 0 5\\n1 1\", \"3 5\\n1 0 1 1\\n0 1 2 3\\n0 0 2 2\\n1 0\\n1 1\"...
Write a program which manipulates a sequence A = {a0, a1, . . . , an−1} with the following operations: * update(s, t, x): change as, as+1, ..., at to x. * find(i): output the value of ai. Note that the initial values of ai (i = 0, 1, . . . , n−1) are 231-1. Constraints * 1 ≤ n ≤ 100000 * 1 ≤ q ≤ 100000 * 0 ≤ s ≤ ...
0.875
{"tests": "{\"inputs\": [\"2\\n2\\n5\", \"2\\n2\\n3\", \"2\\n2\\n10\", \"2\\n1\\n3\", \"2\\n1\\n10\", \"2\\n1\\n15\", \"2\\n2\\n15\", \"2\\n1\\n13\", \"2\\n2\\n13\", \"2\\n2\\n26\", \"2\\n2\\n44\", \"2\\n2\\n77\", \"2\\n2\\n79\", \"2\\n2\\n14\", \"2\\n4\\n14\", \"2\\n3\\n14\", \"2\\n3\\n7\", \"2\\n3\\n11\", \"2\\n2\\n1...
The Head Chef is receiving a lot of orders for cooking the best of the problems lately. For this, he organized an hiring event to hire some talented Chefs. He gave the following problem to test the skills of the participating Chefs. Can you solve this problem and be eligible for getting hired by Head Chef. A non-nega...
0.5
{"tests": "{\"inputs\": [\"7 3 10\\n2 -4 15 -3 4 8 3\\n\", \"5 2 1000\\n-13 -4 -9 -20 -11\\n\", \"8 3 10\\n1 9 -1 9 9 4 17 7\\n\", \"52 6 669\\n642 20 568 -469 -266 744 -486 639 813 632 -539 -818 464 438 -349 -950 280 -93 -529 -920 -831 462 559 961 -837 -349 -653 849 820 -21 -120 -144 -269 605 -99 -276 -844 54 -276 837...
You are given an array a_1, a_2, ... , a_n and two integers m and k. You can choose some subarray a_l, a_{l+1}, ..., a_{r-1}, a_r. The cost of subarray a_l, a_{l+1}, ..., a_{r-1}, a_r is equal to ∑_{i=l}^{r} a_i - k ⌈ (r - l + 1)/(m) ⌉, where ⌈ x ⌉ is the least integer greater than or equal to x. The cost of empty...
0.875
{"tests": "{\"inputs\": [\"3\\n0 0 3\\n3 0 0\\n\", \"2\\n0 1 1\\n1 1 0\\n\", \"686\\n479 178 29\\n11 145 530\\n\", \"319\\n10 53 256\\n182 103 34\\n\", \"15\\n5 5 5\\n5 5 5\\n\", \"29912\\n24063 5489 360\\n10100 9805 10007\\n\", \"961732220\\n361581771 179093036 421057413\\n184611622 34898801 742221797\\n\", \"10000000...
Alice and Bob have decided to play the game "Rock, Paper, Scissors". The game consists of several rounds, each round is independent of each other. In each round, both players show one of the following things at the same time: rock, paper or scissors. If both players showed the same things then the round outcome is a ...
0.375
{"tests": "{\"inputs\": [\"4 6 1\\n1 2 1\\n1 3 3\\n2 3 1\\n2 4 1\\n3 4 1\\n1 4 2\\n2\\n\", \"5 6 3\\n3 1 1\\n3 2 1\\n3 4 1\\n3 5 1\\n1 2 6\\n4 5 8\\n4\\n\", \"10 45 9\\n2 1 428\\n3 1 610\\n3 2 357\\n4 1 855\\n4 2 528\\n4 3 508\\n5 1 425\\n5 2 185\\n5 3 349\\n5 4 845\\n6 1 206\\n6 2 969\\n6 3 153\\n6 4 854\\n6 5 640\\n7...
A country called Berland consists of n cities, numbered with integer numbers from 1 to n. Some of them are connected by bidirectional roads. Each road has some length. There is a path from each city to any other one by these roads. According to some Super Duper Documents, Berland is protected by the Super Duper Missile...
0
{"tests": "{\"inputs\": [\"2 0\\n1 2\\n\", \"6 3\\n1 2\\n1 5\\n2 3\\n3 4\\n5 6\\n\", \"6 2\\n1 6\\n2 4\\n2 6\\n3 6\\n5 6\\n\", \"4 3\\n1 2\\n1 3\\n1 4\\n\", \"20 3\\n10 6\\n2 6\\n19 4\\n15 6\\n20 13\\n9 11\\n8 1\\n12 4\\n7 8\\n16 3\\n18 17\\n8 16\\n12 5\\n13 7\\n9 4\\n14 16\\n8 9\\n10 18\\n9 17\\n\", \"10 0\\n10 6\\n6 ...
You are given an integer k and an undirected tree, consisting of n vertices. The length of a simple path (a path in which each vertex appears at most once) between some pair of vertices is the number of edges in this path. A diameter of a tree is the maximum length of a simple path between all pairs of vertices of thi...
0.125
{"tests": "{\"inputs\": [\"4\\n3 0 3\\n4 -3 5\\n42 -33 55\\n69 -42 146\\n\", \"1\\n167208 -643096130 843266036\\n\", \"1\\n200000 -926527577 520580266\\n\", \"2\\n100000 -441248421 284504519\\n100000 -26375717 863206865\\n\", \"10\\n20000 -431912570 597469643\\n20000 -13928452 414987414\\n20000 -472808872 367983694\\n2...
Let's call an integer array a_1, a_2, ..., a_n good if a_i ≠ i for each i. Let F(a) be the number of pairs (i, j) (1 ≤ i < j ≤ n) such that a_i + a_j = i + j. Let's say that an array a_1, a_2, ..., a_n is excellent if: * a is good; * l ≤ a_i ≤ r for each i; * F(a) is the maximum possible among all good arra...
0
{"tests": "{\"inputs\": [\"3 1\\n1 3 2\\n\", \"5 2\\n1 3 2 1 7\\n\", \"2 0\\n2 1\\n\", \"74 9\\n23 15 38 22 47 8 2 38 17 3 39 10 33 26 19 27 11 15 42 18 44 22 47 44 18 29 25 6 4 44 12 44 30 26 5 41 18 6 17 15 40 28 44 37 27 32 31 13 1 13 3 19 39 3 27 23 25 27 30 31 14 42 31 3 1 26 40 42 26 33 43 11 33 15\\n\", \"5 0\\n...
The Little Elephant has array a, consisting of n positive integers, indexed from 1 to n. Let's denote the number with index i as ai. The Little Elephant wants to count, how many pairs of integers l and r are there, such that 1 ≤ l < r ≤ n and sequence b = a1a2... alarar + 1... an has no more than k inversions. An in...
0.375
{"tests": "{\"inputs\": [\"5 3 1\\n\", \"0 1 0\\n\", \"0 5 5\\n\", \"100000 90000 0\\n\", \"100000 100000 10\\n\", \"44133 52876 8\\n\", \"25902 30390 2\\n\", \"0 0 0\\n\", \"90000 100000 0\\n\", \"91756 73882 2\\n\", \"84273 98526 10\\n\", \"49672 75296 0\\n\", \"1 0 0\\n\", \"18874 21756 8\\n\", \"0 0 10\\n\", \"6794...
As a big fan of Formula One, Charlie is really happy with the fact that he has to organize ticket sells for the next Grand Prix race in his own city. Unfortunately, the finacial crisis is striking everywhere and all the banknotes left in his country are valued either 10 euros or 20 euros. The price of all tickets for t...
0.25
{"tests": "{\"inputs\": [\"2 6 2 2\\n\", \"1 9 1 2\\n\", \"2255 7902 8891 429\\n\", \"9999 10000 10000 10000\\n\", \"9999 10000 10000 10000\\n\", \"4400 8021 6895 2089\\n\", \"3274 4728 888 4578\\n\", \"5726 9082 7448 3054\\n\", \"5726 9082 7448 3054\\n\", \"1196 4082 4071 9971\\n\", \"123 1242 12 312\\n\", \"1 9 1 2\\...
Luke Skywalker got locked up in a rubbish shredder between two presses. R2D2 is already working on his rescue, but Luke needs to stay alive as long as possible. For simplicity we will assume that everything happens on a straight line, the presses are initially at coordinates 0 and L, and they move towards each other wi...
0.75
{"tests": "{\"inputs\": [\"8 2\\n1 2 4 100000 123 456 789 1\\n\", \"3 2\\n3 4 7\\n\", \"1 1\\n10\\n\", \"3 1\\n1 2 3\\n\", \"10 5\\n1384 1129 1780 1960 1567 1928 12 1523 1165 344\\n\", \"10 6\\n19 3 20 16 14 10 1 13 7 3\\n\", \"10 4\\n127 1459 718 1183 880 1044 1857 1340 725 1496\\n\", \"1 1\\n100000\\n\", \"1 1\\n1\\n...
It's been almost a week since Polycarp couldn't get rid of insomnia. And as you may already know, one week in Berland lasts k days! When Polycarp went to a doctor with his problem, the doctor asked him about his sleeping schedule (more specifically, the average amount of hours of sleep per week). Luckily, Polycarp kep...
0.875
{"tests": "{\"inputs\": [\"2 999\\n400000 1 2\\n500000 1 1\\n\", \"2 1000\\n400000 500 1\\n600000 500 2\\n\", \"10 100\\n945740 58 2\\n424642 85 2\\n310528 91 2\\n688743 93 1\\n355046 85 1\\n663649 84 2\\n720124 56 1\\n941616 59 2\\n412011 46 2\\n891591 30 2\\n\", \"3 96475\\n187875 5 2\\n813727 8 1\\n645383 7 2\\n\", ...
n people are standing on a coordinate axis in points with positive integer coordinates strictly less than 106. For each person we know in which direction (left or right) he is facing, and his maximum speed. You can put a bomb in some point with non-negative integer coordinate, and blow it up. At this moment all people...
0
{"tests": "{\"inputs\": [\"4\\n1 1 1\\n1 0 0 1\\n9\\nget 1\\nget 2\\nget 3\\nget 4\\npow 1\\nget 1\\nget 2\\nget 3\\nget 4\\n\", \"10\\n1 2 3 3 5 5 7 7 9\\n1 1 0 1 0 0 1 0 0 0\\n10\\nget 2\\nget 6\\nget 4\\nget 2\\nget 1\\nget 2\\nget 6\\nget 9\\nget 10\\nget 7\\n\", \"10\\n1 2 3 3 5 5 7 7 8\\n0 0 0 0 1 1 1 1 0 0\\n10\...
Danil decided to earn some money, so he had found a part-time job. The interview have went well, so now he is a light switcher. Danil works in a rooted tree (undirected connected acyclic graph) with n vertices, vertex 1 is the root of the tree. There is a room in each vertex, light can be switched on or off in each ro...
0.375
{"tests": "{\"inputs\": [\"AABCCBAAB\\nABCB\\n5\\n1 3 1 2\\n2 2 2 4\\n7 9 1 1\\n3 4 2 3\\n4 5 1 3\\n\", \"A\\nCB\\n1\\n1 1 1 2\\n\", \"A\\nBB\\n1\\n1 1 1 2\\n\", \"BBAACCBACACBCCCBBAAC\\nCACCAAABAACBBBBACABC\\n1\\n3 10 6 13\\n\", \"BCBBC\\nABBCB\\n5\\n2 2 2 4\\n3 4 2 4\\n1 2 2 2\\n2 3 4 5\\n5 5 2 4\\n\", \"AAAAAA\\nAAA...
Alice has a string consisting of characters 'A', 'B' and 'C'. Bob can use the following transitions on any substring of our string in any order any number of times: * A <image> BC * B <image> AC * C <image> AB * AAA <image> empty string Note that a substring is one or more consecutive characters. For give...
0
{"tests": "{\"inputs\": [\"1\\nabcabc\\ncbabac\\nababca\\n\", \"15\\nfoPaErcvJ\\nmZaxowpbt\\nmkuOlaHRE\\n\", \"3\\nKuroo\\nShiro\\nKatie\\n\", \"7\\ntreasurehunt\\nthreefriends\\nhiCodeforces\\n\", \"3\\naaaabb\\naaaabb\\naaabbb\\n\", \"3\\naaaaaa\\naabbcc\\naabbcc\\n\", \"9174\\nbzbbbzzzbbzzccczzccczzbzbzcbzbbzccbzccc...
After the big birthday party, Katie still wanted Shiro to have some more fun. Later, she came up with a game called treasure hunt. Of course, she invited her best friends Kuro and Shiro to play with her. The three friends are very smart so they passed all the challenges very quickly and finally reached the destination...
0.625
{"tests": "{\"inputs\": [\"4\\n1 2 2\\n1\\n6 10 4\\n5 4 7 8 4 1 \\n1 4 3\\n2 \\n1 6 2\\n5 \\n\\nSAMPLE\", \"4\\n1 2 2\\n1\\n6 10 4\\n5 4 0 8 4 1 \\n1 4 3\\n2 \\n1 6 2\\n5 \\n\\nSAMPLE\", \"4\\n1 2 2\\n1\\n6 10 4\\n5 4 0 8 4 1 \\n1 4 3\\n2 \\n1 6 2\\n1 \\n\\nSAMPLE\", \"4\\n1 2 2\\n1\\n6 10 7\\n5 4 0 8 4 1 \\n1 4 3\\n2 ...
Benny is a little pig. She usually goes to school, but the summer is coming which is also the time of getting the grade card report of all the N + 1 subjects. Benny has a M grade point system. Hence, all the scores for any subject are not less than 1 and not greater than M. During this year of education, Benny got N ...
0.625
{"tests": "{\"inputs\": [\"5 100\\n101\\n\\nSAMPLE\", \"5 100\\n101\\n\\nASMPLE\", \"5 100\\n001\\n\\nASMPLE\", \"5 110\\n001\\n\\nASMPLE\", \"8 110\\n001\\n\\nASMLPE\", \"8 100\\n001\\n\\nASMLPE\", \"11 100\\n001\\n\\nASMLQE\", \"11 110\\n001\\n\\nMSALQE\", \"11 110\\n101\\n\\nMSALQE\", \"0 110\\n100\\n\\nEQL@SM\", \"...
There is a magical shop owned by The Monk, which consists of magical potions. On the first day there are A number of potions. Let, potions[I] denote the number of potions present in the shop on the I^th day. potions[I] = potions[I-1] * potions[I-1] You, Monk's favorite student love to play around with various type...
0.75
{"tests": "{\"inputs\": [\"4\\n0 0 1 0 2\", \"3\\n0 1 1 2\", \"10\\n0 0 1 1 2 3 5 8 13 21 34\", \"2\\n0 3 1\", \"1\\n1 1\", \"4\\n0 0 0 0 2\", \"3\\n0 1 1 1\", \"10\\n0 0 1 0 2 3 5 8 13 21 34\", \"2\\n0 3 2\", \"10\\n0 0 1 0 2 3 5 8 13 23 34\", \"10\\n0 0 1 0 3 3 5 8 13 23 34\", \"2\\n-1 3 2\", \"10\\n0 0 1 1 3 3 5 8 1...
Given is an integer sequence of length N+1: A_0, A_1, A_2, \ldots, A_N. Is there a binary tree of depth N such that, for each d = 0, 1, \ldots, N, there are exactly A_d leaves at depth d? If such a tree exists, print the maximum possible number of vertices in such a tree; otherwise, print -1. Constraints * 0 \leq N \...
0
{"tests": "{\"inputs\": [\"3 3\", \"8 6\", \"9 13\", \"10 1\", \"314 159\", \"5 3\", \"1 6\", \"13 13\", \"15 1\", \"56 159\", \"5 1\", \"19 13\", \"15 2\", \"43 159\", \"1 1\", \"27 2\", \"61 159\", \"0 2\", \"2 13\", \"16 2\", \"39 159\", \"11 2\", \"89 205\", \"102 205\", \"169 205\", \"3 6\", \"16 6\", \"5 13\", \"...
Find the number, modulo 998244353, of sequences of length N consisting of 0, 1 and 2 such that none of their contiguous subsequences totals to X. Constraints * 1 \leq N \leq 3000 * 1 \leq X \leq 2N * N and X are integers. Input Input is given from Standard Input in the following format: N X Output Print the nu...
0
{"tests": "{\"inputs\": [\"1\\n4\", \"1\\n6\", \"1\\n8\", \"1\\n12\", \"1\\n16\", \"1\\n1\", \"1\\n13\", \"1\\n25\", \"1\\n5\", \"1\\n2\", \"1\\n3\", \"1\\n10\", \"1\\n19\", \"1\\n23\", \"1\\n9\", \"1\\n17\", \"1\\n7\", \"1\\n18\", \"1\\n20\", \"1\\n21\", \"1\\n11\", \"1\\n29\", \"1\\n15\", \"1\\n14\", \"1\\n26\", \"1\...
An bydrocarbon is an organic compound which contains only carbons and hydrogens. An isomer is a compound that has the same number of carbons but different structures. Heptane, for example, is a hydrocarbon with 7 carbons. It has nine isomers. The structural formula of three are shown in Figure 1. Carbons are represente...
0
{"tests": "{\"inputs\": [\"4\\n1357 4680\\n6\\n777777 003330\\n0\", \"4\\n1433 4680\\n6\\n777777 003330\\n0\", \"4\\n1357 4680\\n6\\n509138 003330\\n0\", \"4\\n1357 4680\\n6\\n297443 003330\\n0\", \"4\\n1357 5363\\n6\\n777777 003330\\n0\", \"4\\n1357 1908\\n6\\n509138 003330\\n0\", \"4\\n2443 5385\\n6\\n568742 003330\\...
A dial lock is a kind of lock which has some dials with printed numbers. It has a special sequence of numbers, namely an unlocking sequence, to be opened. You are working at a manufacturer of dial locks. Your job is to verify that every manufactured lock is unlocked by its unlocking sequence. In other words, you have ...
0.125
{"tests": "{\"inputs\": [\"5 3 6 9\\n9 7 5 3 1\", \"5 3 6 9\\n9 1 5 3 1\", \"21 10 0 4\\n5 2 13 -1 0\", \"21 7 1 4\\n0 2 23 -1 2\", \"9 3 1 9\\n22 2 6 2 0\", \"21 14 1 4\\n2 2 0 -1 2\", \"5 3 6 9\\n9 1 6 3 1\", \"8 3 6 9\\n9 1 6 3 1\", \"8 3 6 9\\n15 1 6 3 1\", \"8 3 6 9\\n15 0 6 3 1\", \"8 3 6 9\\n22 0 6 3 1\", \"11 3...
Problem statement AOR Ika got a cabbage with $ N $ leaves. The leaves of this cabbage are numbered $ 1, \ ldots, N $ in order from the outside, and the dirtiness of the $ i $ th leaf is $ D_i $. The larger this value is, the worse the degree of dirt is. AOR Ika-chan decided to use the cabbage leaves for cooking, so sh...
0
{"tests": "{\"inputs\": [\"2 2\\n1 5\\n1 5\", \"2 2\\n0 5\\n1 5\", \"2 2\\n0 2\\n1 5\", \"2 2\\n0 4\\n1 5\", \"2 2\\n-1 2\\n1 5\", \"2 2\\n0 3\\n1 5\", \"2 2\\n0 5\\n2 5\", \"2 2\\n0 5\\n3 5\", \"2 2\\n0 1\\n1 5\", \"2 2\\n-1 0\\n1 5\", \"2 2\\n2 5\\n1 5\", \"2 2\\n0 0\\n3 8\", \"2 2\\n2 5\\n2 5\", \"2 2\\n1 5\\n3 5\",...
N: Mail order Mr. Komozawa bought building blocks toys from Makai mail order. The building blocks are in the shape of a cube with a side length of 1, and are stacked on squares divided into $ H $ pieces vertically and $ W $ pieces horizontally. Seen from the side, $ A_1, A_2, A_3, \ dots, A_H $ blocks were stacked i...
0.25
{"tests": "{\"inputs\": [\"1 1 50\", \"6 10 99\", \"2 2 10\", \"6 13 99\", \"2 2 15\", \"6 13 187\", \"2 1 15\", \"6 18 187\", \"6 23 187\", \"6 23 338\", \"9 23 338\", \"9 43 338\", \"9 43 467\", \"9 43 58\", \"2 43 58\", \"3 43 58\", \"6 43 58\", \"6 26 58\", \"6 42 58\", \"0 42 58\", \"1 4 56\", \"1 4 85\", \"1 4 14...
Problem There are coins with front and back sides and dice with rolls from $ 1 $ to $ N $. Gacho decided to play the following games using these. The game starts with a score of $ 0 $ and proceeds as follows. 1. Roll the dice $ 1 $ and add the number of rolls to the score. 2. If the current score is $ K $ or more, ...
0.375
{"tests": "{\"inputs\": [\"1 2 1\\n4 2 2\", \"1 2 1\\n3 2 2\", \"0 0 1\\n1 0 2\", \"1 1 1\\n6 2 2\", \"0 2 1\\n4 2 2\", \"1 2 2\\n3 2 2\", \"0 0 2\\n1 0 2\", \"1 1 2\\n6 2 2\", \"0 2 1\\n1 2 2\", \"0 -1 2\\n1 0 2\", \"1 1 2\\n6 4 2\", \"0 -2 2\\n1 0 2\", \"1 1 2\\n6 6 2\", \"0 -4 2\\n1 0 2\", \"0 1 2\\n6 6 2\", \"0 -4 ...
Find common tangent lines of two circles $c1$ and $c2$. Constraints * $-1,000 \leq c1x, c1y, c2x, c2y \leq 1,000$ * $1 \leq c1r, c2r \leq 1,000$ * $c1$ and $c2$ are different Input Center coordinates ($cix$, $ciy$) and radii $cir$ of two circles $c1$ are $c2$ are given in the following format. $c1x \; c1y \; c1r$ ...
0
{"tests": "{\"inputs\": [\"7\\n0 blue 4\\n0 red 1\\n0 white 5\\n1 red\\n1 blue\\n0 black 8\\n1 black\", \"7\\n0 blue 4\\n0 red 1\\n0 white 5\\n1 red\\n1 blue\\n0 black 16\\n1 black\", \"7\\n0 blue 4\\n0 red 1\\n0 white 3\\n1 red\\n1 blue\\n0 black 8\\n1 black\", \"7\\n0 blue 5\\n0 red 1\\n0 white 5\\n1 red\\n1 blue\\n0...
For a dictionary $M$ that stores elements formed by a pair of a string key and an integer value, perform a sequence of the following operations. Note that each key in $M$ must be unique. * insert($key$, $x$): Insert an element formed by a pair of $key$ and $x$ to $M$. If there is an element with $key$, replace the cor...
0
{"tests": "{\"inputs\": [\"7\\n1 2\\n2 3\\n3 4\\n3 5\\n3 6\\n3 7\\n\", \"7\\n1 2\\n2 3\\n2 4\\n4 5\\n4 6\\n5 7\\n\", \"7\\n1 2\\n1 3\\n2 4\\n2 5\\n3 6\\n1 7\\n\", \"7\\n1 2\\n2 3\\n2 4\\n2 5\\n3 6\\n1 7\\n\", \"7\\n1 2\\n2 3\\n2 4\\n2 5\\n2 6\\n1 7\\n\", \"7\\n1 2\\n4 6\\n2 4\\n3 5\\n3 2\\n3 7\\n\", \"7\\n1 2\\n2 3\\n2...
You are given an undirected tree consisting of n vertices. An undirected tree is a connected undirected graph with n - 1 edges. Your task is to add the minimum number of edges in such a way that the length of the shortest path from the vertex 1 to any other vertex is at most 2. Note that you are not allowed to add loo...
0
{"tests": "{\"inputs\": [\"4\\n1 2 4 4\\n\", \"9\\n1 1 8 8 8 4 4 4 4\\n\", \"7\\n4 3 7 1 4 3 3\\n\", \"2\\n1 2\\n\", \"10\\n8 8 1 1 1 2 7 7 8 4\\n\", \"2\\n1 1\\n\", \"10\\n10 7 10 10 7 10 7 7 10 10\\n\", \"9\\n9 5 7 9 6 4 6 4 8\\n\", \"10\\n6 6 6 6 6 6 6 6 6 6\\n\", \"10\\n6 8 9 6 5 9 4 8 8 6\\n\", \"10\\n1 2 3 4 5 6 ...
Oh, New Year. The time to gather all your friends and reflect on the heartwarming events of the past year... n friends live in a city which can be represented as a number line. The i-th friend lives in a house with an integer coordinate x_i. The i-th friend can come celebrate the New Year to the house with coordinate ...
0.125
{"tests": "{\"inputs\": [\"1\\n\", \"3\\n\", \"5\\n\", \"10000000001\\n\", \"31\\n\", \"666666\\n\", \"1537\\n\", \"256\\n\", \"6131066257802\\n\", \"9728000000001\\n\", \"600\\n\", \"6131066257801\\n\", \"7\\n\", \"512\\n\", \"128\\n\", \"10000000000\\n\", \"6\\n\", \"421654016\\n\", \"16\\n\", \"8\\n\", \"59049\\n\",...
Karl likes Codeforces and subsequences. He wants to find a string of lowercase English letters that contains at least k subsequences codeforces. Out of all possible strings, Karl wants to find a shortest one. Formally, a codeforces subsequence of a string s is a subset of ten characters of s that read codeforces from ...
0.125
{"tests": "{\"inputs\": [\"3\\n3 5\\n1 2\\n3 4\\n2 1000000000\\n1 1\\n999999999 999999999\\n10 3\\n5 10\\n7 8\\n\", \"1\\n10 10\\n1 1\\n1 1\\n\", \"1\\n1 1\\n3 3\\n1 1\\n\", \"1\\n2 10\\n1 1\\n1 1\\n\", \"1\\n4 52\\n3 5\\n3 5\\n\", \"1\\n3 100\\n1 1\\n1 1\\n\", \"2\\n3 5\\n1 2\\n1 2\\n3 5\\n1 1\\n1 1\\n\", \"1\\n1 1\\n...
You are given two lists of segments [al_1, ar_1], [al_2, ar_2], ..., [al_n, ar_n] and [bl_1, br_1], [bl_2, br_2], ..., [bl_n, br_n]. Initially, all segments [al_i, ar_i] are equal to [l_1, r_1] and all segments [bl_i, br_i] are equal to [l_2, r_2]. In one step, you can choose one segment (either from the first or fro...
0
{"tests": "{\"inputs\": [\"1 10 10\\n\", \"4 10 4\\n\", \"5 10 4\\n\", \"2 100 50\\n\", \"100 821 25\\n\", \"2 10 10\\n\", \"10 72 17\\n\", \"100 100 5\\n\", \"10 1000 237\\n\", \"2 2 1\\n\", \"59 486 43\\n\", \"7 997 332\\n\", \"1 100 45\\n\", \"13 927 179\\n\", \"85 449 16\\n\", \"93 857 28\\n\", \"2 1000 500\\n\", \...
Gerald is setting the New Year table. The table has the form of a circle; its radius equals R. Gerald invited many guests and is concerned whether the table has enough space for plates for all those guests. Consider all plates to be round and have the same radii that equal r. Each plate must be completely inside the ta...
0.875
{"tests": "{\"inputs\": [\"3\\n\", \"1\\n\", \"2\\n\", \"100\\n\", \"333625\\n\", \"693549\\n\", \"757606\\n\", \"1000000\\n\", \"999228\\n\", \"443013\\n\", \"825195\\n\", \"160945\\n\", \"489857\\n\", \"563368\\n\", \"372544\\n\", \"315936\\n\", \"446167\\n\", \"797112\\n\", \"75417\\n\", \"119444\\n\", \"916542\\n\"...
Kavi has 2n points lying on the OX axis, i-th of which is located at x = i. Kavi considers all ways to split these 2n points into n pairs. Among those, he is interested in good pairings, which are defined as follows: Consider n segments with ends at the points in correspondent pairs. The pairing is called good, if fo...
0
{"tests": "{\"inputs\": [\"4\\nfind the next palindrome\\n1\\n10 find the previous palindrome or print better luck next time\\n\", \"3\\nadd two decimals\\n5\\n4 please two decimals add\\n5 decimals want to be added\\n4 two add decimals add\\n4 add one two three\\n7 one plus two plus three equals six\\n\", \"3\\nadd tw...
A widely known among some people Belarusian sport programmer Lesha decided to make some money to buy a one square meter larger flat. To do this, he wants to make and carry out a Super Rated Match (SRM) on the site Torcoder.com. But there's a problem — a severe torcoder coordinator Ivan does not accept any Lesha's probl...
0
{"tests": "{\"inputs\": [\"10 1 8 2\\n\", \"10 1 8 3\\n\", \"905420490 57 588 288\\n\", \"342603251 513651 575872 16399\\n\", \"39 934112975734 999999999956 3045192662\\n\", \"72 831006353527 999999999987 71879885253\\n\", \"232100782 7 9 2\\n\", \"10 1 20 2\\n\", \"829051283 1088391361 820651073160 7\\n\", \"100 7 12 ...
There are less than 60 years left till the 900-th birthday anniversary of a famous Italian mathematician Leonardo Fibonacci. Of course, such important anniversary needs much preparations. Dima is sure that it'll be great to learn to solve the following problem by the Big Day: You're given a set A, consisting of number...
0
{"tests": "{\"inputs\": [\"2 3\\nATK 2000\\nDEF 1700\\n2500\\n2500\\n2500\\n\", \"3 4\\nATK 10\\nATK 100\\nATK 1000\\n1\\n11\\n101\\n1001\\n\", \"2 4\\nDEF 0\\nATK 0\\n0\\n0\\n1\\n1\\n\", \"34 9\\nDEF 7295\\nDEF 7017\\nDEF 7483\\nDEF 7509\\nDEF 7458\\nDEF 7434\\nDEF 6981\\nDEF 7090\\nDEF 7298\\nDEF 7134\\nATK 737\\nDEF...
Fox Ciel is playing a card game with her friend Jiro. Jiro has n cards, each one has two attributes: position (Attack or Defense) and strength. Fox Ciel has m cards, each one has these two attributes too. It's known that position of all Ciel's cards is Attack. Now is Ciel's battle phase, Ciel can do the following ope...
0
{"tests": "{\"inputs\": [\"2 3\\n1 1 1\\n1 1 1\\n\", \"2 2\\n1 0\\n0 0\\n\", \"2 3\\n0 1 0\\n1 1 1\\n\", \"7 10\\n1 0 1 0 0 0 1 0 1 0\\n1 0 1 0 0 0 1 0 1 0\\n1 1 1 1 1 1 1 1 1 1\\n1 0 1 0 0 0 1 0 1 0\\n1 1 1 1 1 1 1 1 1 1\\n1 1 1 1 1 1 1 1 1 1\\n1 1 1 1 1 1 1 1 1 1\\n\", \"5 5\\n1 1 1 0 1\\n1 1 0 0 1\\n0 0 1 1 1\\n1 1 ...
Let's define logical OR as an operation on two logical values (i. e. values that belong to the set {0, 1}) that is equal to 1 if either or both of the logical values is set to 1, otherwise it is 0. We can define logical OR of three or more logical values in the same manner: <image> where <image> is equal to 1 if some ...
0.375
{"tests": "{\"inputs\": [\"3\\n0.0 0.5 0.8\\n0.5 0.0 0.4\\n0.2 0.6 0.0\\n\", \"4\\n0.0 1.0 1.0 1.0\\n0.0 0.0 0.0 0.0\\n0.0 1.0 0.0 0.0\\n0.0 1.0 1.0 0.0\\n\", \"6\\n0.000000 0.433864 0.631347 0.597596 0.794426 0.713555\\n0.566136 0.000000 0.231193 0.396458 0.723050 0.146212\\n0.368653 0.768807 0.000000 0.465978 0.54622...
The rules of Sith Tournament are well known to everyone. n Sith take part in the Tournament. The Tournament starts with the random choice of two Sith who will fight in the first battle. As one of them loses, his place is taken by the next randomly chosen Sith who didn't fight before. Does it need to be said that each b...
0
{"tests": "{\"inputs\": [\"7 2 5\\n\", \"10 3 10\\n\", \"11586121 15337246 15397874\\n\", \"950099012 175922161 176000556\\n\", \"9056 336 896\\n\", \"903316762502 354723010040 354723105411\\n\", \"95173251245550 106288351347530 106288351372022\\n\", \"281474976710656 17179869184 17179869186\\n\", \"542 321 956\\n\", \...
Jon fought bravely to rescue the wildlings who were attacked by the white-walkers at Hardhome. On his arrival, Sam tells him that he wants to go to Oldtown to train at the Citadel to become a maester, so he can return and take the deceased Aemon's place as maester of Castle Black. Jon agrees to Sam's proposal and Sam s...
0.125
{"tests": "{\"inputs\": [\"'co-co-co, codeforces?!'\\n\", \"snow affects sports such as skiing, snowboarding, and snowmachine travel.\\nsnowboarding is a recreational activity and olympic and paralympic sport.\\n\", \"thun-thun-thunder, thunder, thunder\\nthunder, thun-, thunder\\nthun-thun-thunder, thunder\\nthunder, ...
Arcady is a copywriter. His today's task is to type up an already well-designed story using his favorite text editor. Arcady types words, punctuation signs and spaces one after another. Each letter and each sign (including line feed) requires one keyboard click in order to be printed. Moreover, when Arcady has a non-e...
0
{"tests": "{\"inputs\": [\"1333333333\", \"103\", \"1000000000000000000\", \"1925339908\", \"121\", \"1000010000000000000\", \"2918372355\", \"1100010000000000000\", \"1759180116\", \"314793131\", \"385473767\", \"693073999\", \"463707925\", \"620557412\", \"55916268\", \"29927702\", \"12264538\", \"23000309\", \"11100...
Takahashi has a deposit of 100 yen (the currency of Japan) in AtCoder Bank. The bank pays an annual interest rate of 1 % compounded annually. (A fraction of less than one yen is discarded.) Assuming that nothing other than the interest affects Takahashi's balance, in how many years does the balance reach X yen or abo...
0.875
{"tests": "{\"inputs\": [\"41\", \"6\", \"79992\", \"40\", \"37450\", \"70620\", \"9\", \"14\", \"11849\", \"48730\", \"198\", \"478\", \"10989\", \"10\", \"78\", \"8\", \"155\", \"45794\", \"100\", \"101\", \"25\", \"31\", \"47\", \"20\", \"17\", \"21\", \"4\", \"24\", \"15\", \"65\", \"34375\", \"72\", \"3\", \"31041...
Find the smallest possible sum of the digits in the decimal notation of a positive multiple of K. Constraints * 2 \leq K \leq 10^5 * K is an integer. Input Input is given from Standard Input in the following format: K Output Print the smallest possible sum of the digits in the decimal notation of a positive mu...
0.25
{"tests": "{\"inputs\": [\"5\\n8 6 9 1 20\", \"5\\n8 0 9 1 20\", \"5\\n10 -2 3 1 0\", \"5\\n3 -2 1 2 4\", \"5\\n1 1 0 0 0\", \"5\\n8 0 11 1 20\", \"5\\n12 0 11 1 20\", \"5\\n15 0 11 1 20\", \"5\\n15 0 21 1 20\", \"5\\n15 0 21 0 20\", \"5\\n15 -1 21 0 20\", \"5\\n15 -1 21 0 22\", \"5\\n15 -1 3 0 22\", \"5\\n15 -1 3 1 22...
Today's Random Number E869120 You ran a campaign called "Today's Random Numbers" for N days. This is a project to generate a random number once a day and post the value on Twitter. The "random numbers of the day" on day $ 1, 2, 3, \ dots, N $ were $ A_1, A_2, A_3, \ dots, A_N $, respectively. E869120 You would be ha...
0.75
{"tests": "{\"inputs\": [\"3\\n4 2 1\\n\", \"7\\n77 66 55 44 33 22 11\\n\", \"2\\n4 7\\n\", \"10\\n8 4 7 5 9 5 8 5 10 1000\\n\", \"50\\n6 2 5 6 5 5 1 5 7 2 3 7 3 1 9 1 6 6 8 1 4 7 1 7 6 2 6 2 6 4 2 9 8 2 3 2 4 3 2 4 6 4 4 9 8 2 8 8 1 5\\n\", \"5\\n4 7 47 744 1\\n\", \"100\\n3 2 4 2 2 2 3 1 2 3 1 4 1 4 1 2 3 3 3 2 3 1 2...
Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya got an array consisting of n numbers, it is the gift for his birthday. Now he wants to sort it...
0
{"tests": "{\"inputs\": [\"4 5\\n2\\n1 2\\n3 5\\n2\\n1 3\\n4 5\\n3\\n1 1\\n2 4\\n5 5\\n3\\n1 1\\n2 2\\n3 5\\n\", \"7 8\\n1\\n1 8\\n2\\n1 5\\n6 8\\n4\\n1 1\\n2 2\\n3 4\\n5 8\\n4\\n1 3\\n4 4\\n5 5\\n6 8\\n2\\n1 7\\n8 8\\n2\\n1 6\\n7 8\\n3\\n1 1\\n2 2\\n3 8\\n\", \"3 3\\n3\\n1 1\\n2 2\\n3 3\\n3\\n1 1\\n2 2\\n3 3\\n3\\n1 1...
Omkar is building a house. He wants to decide how to make the floor plan for the last floor. Omkar's floor starts out as n rows of m zeros (1 ≤ n,m ≤ 100). Every row is divided into intervals such that every 0 in the row is in exactly 1 interval. For every interval for every row, Omkar can change exactly one of the 0s...
0
{"tests": "{\"inputs\": [\"7\\n0 2\\n1 0\\n-3 0\\n0 -2\\n-1 -1\\n-1 -3\\n-2 -3\\n\", \"5\\n0 0\\n2 0\\n0 -1\\n-2 0\\n-2 1\\n\", \"4\\n100 0\\n0 100\\n-100 0\\n0 -100\\n\", \"5\\n0 0\\n0 -1\\n3 0\\n-2 0\\n-2 1\\n\", \"5\\n1626381 1696233\\n1626265 1696001\\n1626381 1696117\\n1626497 1696001\\n1626381 1695885\\n\", \"6\\...
There are n detachments on the surface, numbered from 1 to n, the i-th detachment is placed in a point with coordinates (x_i, y_i). All detachments are placed in different points. Brimstone should visit each detachment at least once. You can choose the detachment where Brimstone starts. To move from one detachment to...
0
{"tests": "{\"inputs\": [\"24\\n\", \"102\\n\", \"1\\n\", \"25011428282808773575\\n\", \"7361918244654780790014643\\n\", \"412686535537807118767857480321109460298267404\\n\", \"1538780506138269474552303704695154678\\n\", \"61728395061728395061728395061728395061345382132589\\n\", \"80460506176325884697749506233871685211...
You are given a positive (greater than zero) integer n. You have to represent n as the sum of integers (possibly negative) consisting only of ones (digits '1'). For example, 24 = 11 + 11 + 1 + 1 and 102 = 111 - 11 + 1 + 1. Among all possible representations, you have to find the one that uses the minimum number of o...
0
{"tests": "{\"inputs\": [\"7 5\\n2 1 1 4 3 3 1\\n3 2 1 1 4\\n\", \"5 2\\n6 4 3 2 1\\n1 6\\n\", \"5 1\\n1 2 3 4 5\\n1\\n\", \"7 5\\n20 10 10 40 30 30 10\\n30 20 10 10 40\\n\", \"5 15\\n1 2 3 4 5\\n5 5 5 5 5 5 5 5 5 5 5 5 5 5 5\\n\", \"5 4\\n3 15 50 50 3\\n50 15 3 50\\n\", \"7 5\\n20 10 20 40 30 30 10\\n30 20 10 10 40\\n...
You have a card deck of n cards, numbered from top to bottom, i. e. the top card has index 1 and bottom card — index n. Each card has its color: the i-th card has color a_i. You should process q queries. The j-th query is described by integer t_j. For each query you should: * find the highest card in the deck with...
0.125
{"tests": "{\"inputs\": [\"4 3\\n1 3 2 4\\n1 2\\n2 3\\n1 4\\n\", \"2 1\\n1 2\\n1 2\\n\", \"125 8\\n111 69 3 82 24 38 4 39 42 22 92 6 16 10 8 45 17 91 84 53 5 46 124 47 18 57 43 73 114 102 121 105 118 95 104 98 72 20 56 60 123 80 103 70 65 107 67 112 101 108 99 49 12 94 2 68 119 109 59 40 86 116 88 63 110 14 13 120 41 6...
The Little Elephant loves permutations of integers from 1 to n very much. But most of all he loves sorting them. To sort a permutation, the Little Elephant repeatedly swaps some elements. As a result, he must receive a permutation 1, 2, 3, ..., n. This time the Little Elephant has permutation p1, p2, ..., pn. Its sort...
0
{"tests": "{\"inputs\": [\"25\\n\", \"1\\n\", \"219\\n\", \"6560\\n\", \"19\\n\", \"9999\\n\", \"9880\\n\", \"7769\\n\", \"9894\\n\", \"7590\\n\", \"10000\\n\", \"20\\n\", \"2925\\n\", \"220\\n\", \"3\\n\", \"4115\\n\", \"9879\\n\", \"4\\n\", \"7142\\n\", \"5\\n\", \"1014\\n\", \"2\\n\", \"7770\\n\", \"3046\\n\", \"796...
Vanya got n cubes. He decided to build a pyramid from them. Vanya wants to build the pyramid as follows: the top level of the pyramid must consist of 1 cube, the second level must consist of 1 + 2 = 3 cubes, the third level must have 1 + 2 + 3 = 6 cubes, and so on. Thus, the i-th level of the pyramid must have 1 + 2 + ...
0.75
{"tests": "{\"inputs\": [\"8\\n1 6 5 4 3 2 7 8\\n\", \"4\\n2 3 4 1\\n\", \"4\\n1 2 3 4\\n\", \"8\\n1 3 2 4 6 5 7 8\\n\", \"1\\n1\\n\", \"8\\n1 3 4 2 6 5 7 8\\n\", \"2\\n1 2\\n\", \"2\\n2 1\\n\", \"4\\n1 2 4 3\\n\", \"35\\n7 33 34 15 16 24 5 27 1 19 17 22 29 3 4 23 31 11 21 35 32 2 12 20 8 9 6 28 18 26 30 14 13 10 25\\n...
Vasya collects coins: he has exactly one coin for every year from 1 to n. Naturally, Vasya keeps all the coins in his collection in the order in which they were released. Once Vasya's younger brother made a change — he took all the coins whose release year dated from l to r inclusively and put them in the reverse order...
0.5
{"tests": "{\"inputs\": [\"3 2\\n0 5\\n-3 2\\n3 8\\n\", \"3 2\\n0 5\\n-3 3\\n3 8\\n\", \"1 1\\n-990637865 387517231\\n\", \"10 10\\n-92 87\\n-100 -67\\n-88 80\\n-82 -59\\n-72 81\\n-50 30\\n30 77\\n65 92\\n-76 -60\\n-29 -15\\n\", \"10 8\\n-749560329 759073394\\n-186423470 816422576\\n-674251064 742056817\\n-342947007 95...
You are given n segments on the coordinate axis Ox and the number k. The point is satisfied if it belongs to at least k segments. Find the smallest (by the number of segments) set of segments on the coordinate axis Ox which contains all satisfied points and no others. Input The first line contains two integers n and ...
0
{"tests": "{\"inputs\": [\"2 100\\n1 787\\n2 788\\n\", \"5 300\\n3 100\\n4 150\\n4 80\\n2 90\\n2 300\\n\", \"2 100\\n2 42\\n2 58\\n\", \"5 100\\n1 10\\n1 10\\n1 10\\n1 10\\n1 10\\n\", \"5 66\\n2 64\\n4 91\\n5 91\\n1 79\\n3 85\\n\", \"10 481\\n4 25\\n3 85\\n6 96\\n6 13\\n1 9\\n4 27\\n2 7\\n3 42\\n9 66\\n9 70\\n\", \"5 3...
You are preparing for an exam on scheduling theory. The exam will last for exactly T milliseconds and will consist of n problems. You can either solve problem i in exactly ti milliseconds or ignore it and spend no time. You don't need time to rest after solving a problem, either. Unfortunately, your teacher considers ...
0.875
{"tests": "{\"inputs\": [\"7 26\\n0 15 12 9 13 0 14\\n11 1 0 13 15 12 0\\n\", \"1 2\\n0\\n1\\n\", \"1 2\\n1\\n0\\n\", \"6 26\\n14 5 19 18 9 14\\n0 0 0 0 0 0\\n\", \"10 90086\\n41910 22500 6101 0 0 0 34790 9614 0 83351\\n11155 21861 0 19394 81349 53888 33712 3834 17500 48357\\n\", \"5 1\\n1 1 1 1 1\\n0 0 0 0 0\\n\", \"4...
Ancient Egyptians are known to have used a large set of symbols <image> to write on the walls of the temples. Fafa and Fifa went to one of the temples and found two non-empty words S1 and S2 of equal lengths on the wall of temple written one below the other. Since this temple is very ancient, some symbols from the word...
0.125
{"tests": "{\"inputs\": [\"10 7\\n1.0.1.0.1.\\n\", \"10 9\\n1........1\\n\", \"10 6\\n1.0.1.1000\\n\", \"128 108\\n01100.110...000.0001.1.11.11.010010.01100.0.1.01.0.0011.11001.000101...1.0.0..100.0110.0110.0.0101.0.0.0001.01100.110...100.0001\\n\", \"3 3\\n1..\\n\", \"3 1\\n01.\\n\", \"4 1\\n111.\\n\", \"10 7\\n000......
Walking along a riverside, Mino silently takes a note of something. "Time," Mino thinks aloud. "What?" "Time and tide wait for no man," explains Mino. "My name, taken from the river, always reminds me of this." "And what are you recording?" "You see it, tide. Everything has its own period, and I think I've figured...
0
{"tests": "{\"inputs\": [\"3\\n1 1\\n1 3\\n100 500\\n\\nSAMPLE\", \"3\\n1 2\\n1 3\\n100 500\\n\\nSAMPLE\", \"3\\n1 1\\n1 1\\n100 500\\n\\nSAMPLE\", \"3\\n2 2\\n1 3\\n100 500\\n\\nSAMPME\", \"3\\n1 2\\n1 1\\n100 818\\n\\nEAPMLS\", \"3\\n1 2\\n1 6\\n100 100\\n\\nSAMPLE\", \"3\\n1 2\\n1 3\\n100 500\\n\\nSAMPME\", \"3\\n1 ...
Anton and Artur are old friends. Today they practice in writing strings. Anton must write each string with the lengths exactly N , based on the alphabet of size M . And Arthur, on the contrary, should write each string with the lengths exactly M , based on the alphabet of size N . Guys spend 1 second to write a sin...
0.625
{"tests": "{\"inputs\": [\"999\", \"3\", \"5\", \"8\", \"0\", \"1\", \"2\", \"4\", \"7\", \"13\", \"6\", \"11\", \"-1\", \"-2\", \"-3\", \"-4\", \"-5\", \"-8\", \"-6\", \"-7\", \"-11\", \"-16\", \"-17\", \"14\", \"17\", \"26\", \"9\", \"12\", \"21\", \"24\", \"19\", \"35\", \"32\", \"31\", \"34\", \"48\", \"18\", \"27\...
Given is a positive integer L. Find the maximum possible volume of a rectangular cuboid whose sum of the dimensions (not necessarily integers) is L. Constraints * 1 ≤ L ≤ 1000 * L is an integer. Input Input is given from Standard Input in the following format: L Output Print the maximum possible volume of a re...
0.875
{"tests": "{\"inputs\": [\"2 5 6\", \"3 2 1\", \"2 4 6\", \"2 8 6\", \"2 2 2\", \"2 2 1\", \"2 0 6\", \"1 8 6\", \"2 0 2\", \"1 8 1\", \"2 4 2\", \"2 0 3\", \"1 10 1\", \"2 4 1\", \"0 0 3\", \"1 1 1\", \"2 1 1\", \"-1 0 3\", \"1 1 0\", \"2 1 0\", \"0 -1 3\", \"1 2 0\", \"2 0 1\", \"0 -1 1\", \"0 2 0\", \"2 0 0\", \"1 -...
Three poles stand evenly spaced along a line. Their heights are a, b and c meters, from left to right. We will call the arrangement of the poles beautiful if the tops of the poles lie on the same line, that is, b-a = c-b. Determine whether the arrangement of the poles is beautiful. Constraints * 1 \leq a,b,c \leq 10...
0.875
{"tests": "{\"inputs\": [\"1 1\\n3 1\\n3 3\\n3 2\\n3\\n3 12\\n9 3\\n11 12\\n8 7\\n5\\n15 3\\n17 7\\n22 5\\n7 6\\n4\\n6 11\\n8 2\\n16 9\\n10 8\\n2\\n0 0\", \"1 1\\n3 1\\n3 3\\n3 2\\n3\\n3 12\\n9 3\\n11 12\\n8 7\\n5\\n15 3\\n17 7\\n22 5\\n7 6\\n5\\n6 11\\n8 2\\n16 9\\n10 8\\n2\\n0 0\", \"2 1\\n3 1\\n3 3\\n3 2\\n3\\n3 12\...
Create a program to determine the positional relationship between a triangle and a circle on a plane. All target figures shall include boundaries. The triangle is given the position of three vertices, and the circle is given the position of the center and the radius. The position is given by a set of two integers in a ...
0.125
{"tests": "{\"inputs\": [\"4 6\\n4\\n2\\n3\\n5\", \"4 6\\n7\\n2\\n3\\n5\", \"4 6\\n4\\n1\\n3\\n5\", \"1 6\\n4\\n2\\n3\\n1\", \"4 10\\n7\\n1\\n3\\n5\", \"4 11\\n5\\n2\\n3\\n5\", \"4 5\\n4\\n2\\n3\\n1\", \"1 6\\n3\\n2\\n3\\n1\", \"1 6\\n2\\n2\\n3\\n1\", \"4 9\\n7\\n2\\n3\\n5\", \"1 6\\n1\\n0\\n1\\n1\", \"4 11\\n5\\n2\\n1...
problem There are fine icicles under the eaves of JOI's house in Canada. Because of this, JOI decided to investigate the icicles. There are N (2 ≤ N ≤ 100000 = 105) icicles under the eaves of JOI's house. These icicles are aligned and i cm (1 ≤ i ≤ N) from the left edge of the eaves. There are i-th icicles at the pos...
0
{"tests": "{\"inputs\": [\"5 100 3\\n2 3 4 5 6\\n50 40 20 10 5\", \"5 100 3\\n2 3 4 5 100\\n50 40 20 10 1\", \"5 100 3\\n2 3 4 5 4\\n50 40 20 10 5\", \"5 100 3\\n2 2 4 5 100\\n50 40 20 10 1\", \"5 100 3\\n2 2 4 5 110\\n50 40 20 10 1\", \"5 110 3\\n2 2 4 5 110\\n50 40 20 10 1\", \"5 110 3\\n2 3 4 5 110\\n50 40 20 10 1\"...
Problem Gaccho owns an N-sided field and M potatoes. Each field is numbered from 1 to N. Gaccho wants to increase the number of potatoes by planting and harvesting potatoes in the field. Gaccho lives alone and can only manage fields up to the K side. In addition, the soil condition and area of ​​each field vary, and ...
0
{"tests": "{\"inputs\": [\"2 4 1\\n2 1\\n2 2 1\\n2 2\\n0 0 0\", \"2 4 1\\n2 1\\n4 2 1\\n2 2\\n0 0 0\", \"2 4 1\\n2 1\\n2 2 1\\n2 1\\n0 0 0\", \"2 6 1\\n2 1\\n4 2 1\\n2 2\\n0 0 0\", \"2 6 1\\n2 1\\n4 2 0\\n2 2\\n0 0 0\", \"3 4 1\\n2 1\\n4 2 1\\n2 2\\n0 0 0\", \"2 2 1\\n2 1\\n2 2 1\\n2 1\\n0 0 0\", \"2 4 1\\n2 2\\n2 2 1\...
There is a grid that consists of W \times H cells. The upper-left-most cell is (1, 1). You are standing on the cell of (1,1) and you are going to move to cell of (W, H). You can only move to adjacent lower-left, lower or lower-right cells. There are obstructions on several cells. You can not move to it. You cannot mov...
0
{"tests": "{\"inputs\": [\"3 2\\n1 2\\n2 3\", \"12 2\\n1 2\\n2 3\\n3 4\\n4 5\\n3 6\\n6 7\\n7 8\\n8 9\\n6 10\\n10 11\\n11 12\", \"9 3\\n1 2\\n1 3\\n1 4\\n4 5\\n4 6\\n4 7\\n7 8\\n7 9\", \"2 1\\n1 2\", \"7 3\\n1 2\\n2 3\\n3 4\\n4 5\\n5 6\\n6 7\", \"3 1\\n1 2\\n2 3\", \"1 2\\n1 2\\n2 3\", \"4 1\\n1 2\\n2 3\", \"12 2\\n1 2\...
You are given a tree $T$ and an integer $K$. You can choose arbitrary distinct two vertices $u$ and $v$ on $T$. Let $P$ be the simple path between $u$ and $v$. Then, remove vertices in $P$, and edges such that one or both of its end vertices is in $P$ from $T$. Your task is to choose $u$ and $v$ to maximize the number ...
0
{"tests": "{\"inputs\": [\"2 2\\n00 10\\n01 11\\n10 01\\n10 01\\n\", \"2 3\\n0 0 0\\n011 1 0\\n0 0 1\\n011 0 0\\n\", \"2 2\\n0 1\\n0 1\\n0 1\\n0 1\\n\", \"2 3\\n0 0 0\\n011 1 0\\n0 0 1\\n011 0 0\\n\", \"2 2\\n1 1\\n0 0\\n0 1\\n1 0\\n\", \"2 2\\n1 0\\n1 1\\n1 1\\n1 0\\n\", \"2 2\\n0 1\\n1 0\\n0 1\\n1 0\\n\", \"2 2\\n00 ...
Egor came up with a new chips puzzle and suggests you to play. The puzzle has the form of a table with n rows and m columns, each cell can contain several black or white chips placed in a row. Thus, the state of the cell can be described by a string consisting of characters '0' (a white chip) and '1' (a black chip), p...
0
{"tests": "{\"inputs\": [\"4\\nezor\\n\", \"10\\nnznooeeoer\\n\", \"32\\noeonznzneeononnerooooooeeeneenre\\n\", \"4\\neorz\\n\", \"35\\nozrorrooeoeeeozonoenzoeoreenzrzenen\\n\", \"40\\noeerzzozozzrezeezzzoroozrrreorrreereooeo\\n\", \"300\\noeeeneoenooonnoeeoonenoeeeooeeneoeneeeenoeooooenneneeneoneonnnonnonnnnennoneoone...
When Serezha was three years old, he was given a set of cards with letters for his birthday. They were arranged into words in the way which formed the boy's mother favorite number in binary notation. Serezha started playing with them immediately and shuffled them because he wasn't yet able to read. His father decided t...
0.875
{"tests": "{\"inputs\": [\"3 5\\n3 0\\n0 1\\n2 2\\n0 0\\n1 1\\n2 2\\n3 3\\n5 4\\n\", \"4 1\\n2 5\\n4 0\\n5 1\\n5 6\\n4 4\\n\", \"4 1\\n2 9\\n4 0\\n5 1\\n5 6\\n4 4\\n\", \"4 1\\n2 4\\n4 0\\n5 1\\n1 6\\n2 4\\n\", \"3 5\\n3 0\\n0 1\\n2 2\\n0 0\\n1 1\\n2 2\\n3 3\\n10 4\\n\", \"3 2\\n2 1\\n3 2\\n9 0\\n5 7\\n3 5\\n\", \"3 5\...
After your debut mobile game "Nim" blew up, you decided to make a sequel called "Nim 2". This game will expand on the trusted Nim game formula, adding the much awaited second heap! In the game, there are two heaps, each containing a non-negative number of stones. Two players make moves in turn. On their turn, a playe...
0
{"tests": "{\"inputs\": [\"5\\n1 2 2 1 3\\n\", \"5\\n1 2 2 1 1\\n\", \"100\\n7 4 5 5 10 10 5 8 5 7 4 5 4 6 8 8 2 6 3 3 10 7 10 8 6 2 7 3 9 7 7 2 4 5 2 4 9 5 10 1 10 5 10 4 1 3 4 2 6 9 9 9 10 6 2 5 6 1 8 10 4 10 3 4 10 5 5 4 10 4 5 3 7 10 2 7 3 6 9 6 1 6 5 5 4 6 6 4 4 1 5 1 6 6 6 8 8 6 2 6\\n\", \"100\\n82 51 81 14 37 1...
One day you wanted to read something, so you went to your bookshelf to grab some book. But when you saw how messy the bookshelf was you decided to clean it up first. <image> There are n books standing in a row on the shelf, the i-th book has color a_i. You'd like to rearrange the books to make the shelf look beautif...
0
{"tests": "{\"inputs\": [\"3\\n20 30 10 30 20 10\\n\", \"1\\n1 2\\n\", \"5\\n3 3 1 1 1 3 2 3 1 2\\n\", \"100\\n6 3 6 8 8 4 3 7 10 3 1 3 9 5 10 10 6 7 6 6 2 3 8 8 7 6 4 9 6 7 4 4 10 4 7 3 2 7 10 8 6 7 9 1 3 5 3 7 9 1 1 7 1 1 7 7 8 3 2 7 4 8 7 8 10 3 1 7 2 7 9 8 8 8 5 2 8 1 2 7 8 7 8 8 5 10 10 4 9 10 8 7 8 8 7 7 3 6 4 3 ...
Petya has got 2n cards, each card contains some integer. The numbers on the cards can be the same. Let's index all cards by consecutive integers from 1 to 2n. We'll denote the number that is written on a card with number i, as ai. In order to play one entertaining game with his friends, Petya needs to split the cards i...
0
{"tests": "{\"inputs\": [\"|+|=||||||\\n\", \"|||||+||=||\\n\", \"||+|=|||||\\n\", \"||||+||=||||||\\n\", \"|+||||||=|||||\\n\", \"|||||||||||||||||||||||||||||||||||||||||+|||||||||||||||||||||||||||||||||||||||||=|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||\\n\", \"|+|=||||\\n\", ...
When new students come to the Specialized Educational and Scientific Centre (SESC) they need to start many things from the beginning. Sometimes the teachers say (not always unfairly) that we cannot even count. So our teachers decided to teach us arithmetics from the start. And what is the best way to teach students add...
0
{"tests": "{\"inputs\": [\"5 9\\n10 10\\n20 10\\n30 1\\n31 5\\n40 10\\n\", \"13 6\\n7 75\\n8 84\\n16 95\\n29 21\\n49 33\\n54 56\\n55 80\\n65 63\\n67 50\\n73 47\\n80 26\\n82 74\\n86 77\\n\", \"3 2\\n2 6\\n3 9\\n6 8\\n\", \"19 2\\n1 73\\n2 96\\n3 24\\n5 96\\n11 13\\n14 96\\n16 31\\n17 60\\n34 69\\n39 41\\n60 40\\n61 96\\...
A traveler is planning a water hike along the river. He noted the suitable rest points for the night and wrote out their distances from the starting point. Each of these locations is further characterized by its picturesqueness, so for the i-th rest point the distance from the start equals xi, and its picturesqueness e...
0
{"tests": "{\"inputs\": [\"5\\n1 2\\n1 3\\n2 4\\n2 5\\n\", \"6\\n1 2\\n1 3\\n3 4\\n1 5\\n5 6\\n\", \"3\\n1 2\\n1 3\\n\", \"10\\n1 2\\n1 3\\n3 4\\n3 5\\n4 6\\n1 7\\n3 8\\n2 9\\n6 10\\n\", \"2\\n1 2\\n\", \"1\\n\", \"50\\n1 2\\n2 3\\n3 4\\n4 5\\n5 6\\n6 7\\n7 8\\n8 9\\n9 10\\n10 11\\n11 12\\n12 13\\n13 14\\n14 15\\n15 16...
Demiurges Shambambukli and Mazukta love to watch the games of ordinary people. Today, they noticed two men who play the following game. There is a rooted tree on n nodes, m of which are leaves (a leaf is a nodes that does not have any children), edges of the tree are directed from parent to children. In the leaves of ...
0
{"tests": "{\"inputs\": [\"3\\n1 3\\n2 1\\n3 2\\n\", \"3\\n1 3\\n2 2\\n3 1\\n\", \"12\\n70 11\\n74 27\\n32 11\\n26 83\\n57 18\\n97 28\\n75 43\\n75 21\\n84 29\\n16 2\\n89 63\\n21 88\\n\", \"5\\n39 21\\n95 89\\n73 90\\n9 55\\n85 32\\n\", \"1\\n39 52\\n\", \"2\\n25 56\\n94 17\\n\", \"2\\n100 68\\n38 80\\n\", \"12\\n70 11\...
Duff is addicted to meat! Malek wants to keep her happy for n days. In order to be happy in i-th day, she needs to eat exactly ai kilograms of meat. <image> There is a big shop uptown and Malek wants to buy meat for her from there. In i-th day, they sell meat for pi dollars per kilogram. Malek knows all numbers a1, ....
0
{"tests": "{\"inputs\": [\"1\\n0 10 0 10\\n\", \"2\\n12 3 4 7\\n1 15 9 1\\n\", \"2\\n5 4 8 8\\n4 12 14 0\\n\", \"10\\n31181 6 72281 7\\n65255 10 17867 2\\n96212 8 32852 10\\n69668 6 37236 1\\n6031 7 61541 0\\n12286 4 40227 2\\n30573 9 36317 3\\n97429 6 35399 9\\n20907 5 19251 8\\n86446 8 56301 10\\n\", \"10\\n100000000...
Alice and Bonnie are sisters, but they don't like each other very much. So when some old family photos were found in the attic, they started to argue about who should receive which photos. In the end, they decided that they would take turns picking photos. Alice goes first. There are n stacks of photos. Each stack con...
0
{"tests": "{\"inputs\": [\"3\\n2 qwopwasp\\nwdw\\nabco\\n5 eeeessaa\\nvalentina\\nesta\\njugando\\ncon\\nmarcia\\n5 ahi\\nvalentina\\nesta\\njugando\\ncon\\nsusamigas\\n\\nSAMPLE\", \"3\\n2 qwopwasp\\nwdw\\nabco\\n5 eeeessaa\\nvalentina\\nesta\\njugando\\ncon\\niarcma\\n5 ahi\\nvalentina\\nesta\\njugando\\ncon\\nsusami...
Valentina is looking for a new game to play with her friends. She asks her mom Marcia for an idea. After a moment Marcia described to girls the following simple game. Girls are divided into n teams, indexed 1 through n. Each girl chooses a lowercase letter, one of 'a' - 'z'. Of course, some girls can choose the same l...
0.75
{"tests": "{\"inputs\": [\"5\\nX--X-\", \"20\\n-X--X--X-X--X--X-X-X\", \"100\\nX-X-X-X-X-X-X-X-X-X--X-X-X-X-X-X-X-X-X-X-X-X-X-X-X--X--X-X-X-X--X--X-X-X--X-X-X--X-X--X--X-X--X-X-X-\", \"5\\nX-X-X\", \"3\\n---\", \"1\\nX\", \"5\\n-X--X\", \"20\\nX-X-X--X--X-X--X--X-\", \"5\\n-X-X-\", \"20\\n-X--X--X-X-----XXX-X\", \"100\...
There is a very long bench. The bench is divided into M sections, where M is a very large integer. Initially, the bench is vacant. Then, M people come to the bench one by one, and perform the following action: * We call a section comfortable if the section is currently unoccupied and is not adjacent to any occupied s...
0
{"tests": "{\"inputs\": [\"1 7\", \"2 2\", \"314 1592\", \"1 2\", \"582 1592\", \"0 0\", \"582 932\", \"0 -1\", \"1018 932\", \"1018 374\", \"527 374\", \"358 374\", \"592 374\", \"592 345\", \"592 673\", \"207 673\", \"128 673\", \"128 131\", \"128 260\", \"246 260\", \"373 260\", \"54 260\", \"54 36\", \"54 54\", \"5...
There is a grid with infinitely many rows and columns. In this grid, there is a rectangular region with consecutive N rows and M columns, and a card is placed in each square in this region. The front and back sides of these cards can be distinguished, and initially every card faces up. We will perform the following op...
0.75
{"tests": "{\"inputs\": [\"10\\n4 9 1 9 5 9 2 3 2 1\\n8 7 6 5 10 5 5 4 7 6\\n5\\n4 3 2 5 1\\n4 4 4 4 4\\n4\\n4 1 3 2\\n4 3 2 1\\n0\", \"10\\n4 9 1 9 5 9 2 3 2 1\\n8 7 6 5 10 5 4 4 7 6\\n5\\n4 3 2 5 1\\n4 4 4 4 4\\n4\\n4 1 3 2\\n4 3 2 1\\n0\", \"10\\n4 9 1 9 5 9 2 3 2 1\\n8 7 6 5 10 5 4 4 7 6\\n0\\n4 3 2 5 1\\n4 4 4 4 4...
There is a game called Packet Monster. A game that catches, raises, fights and exchanges monsters, and is very popular all over Japan. Of course, in my class. That's why I also raise monsters so that I can play with everyone in this game, but sadly there is no opponent to play against. I'm not the type who is good at t...
0
{"tests": "{\"inputs\": [\"15 6\\n10\\n1 4 5 6\\n2 1 4 5\\n1 0 5 1\\n6 1 7 5\\n7 5 9 6\\n7 0 9 2\\n9 1 10 5\\n11 0 14 1\\n12 1 13 5\\n11 5 14 6\\n0 0\", \"15 6\\n10\\n1 4 5 6\\n2 1 4 5\\n1 0 5 1\\n6 1 7 5\\n7 5 3 6\\n7 0 9 2\\n9 1 10 5\\n11 0 14 1\\n12 1 13 5\\n11 5 14 6\\n0 0\", \"15 6\\n10\\n1 4 5 6\\n2 1 0 5\\n1 0 5...
problem Information I want to paint a rectangular veneer board to make a signboard for the promotion of the Olympic Games. Some rectangular masking tapes are pre-attached to the veneer board where I do not want to paint. We decided to paint each area with a different color. For example, in the case of Figure 5-1 we us...
0.375
{"tests": "{\"inputs\": [\"5 16\\n70 66 40\\n38 52 20\\n40 35 10\\n70 30 10\\n20 60 10\\n1 100\\n54 75 200\\n1 10\\n90 10 1\\n1 11\\n54 75 200\\n3 10\\n53 60 1\\n61 38 1\\n45 48 1\\n4 10\\n20 20 10\\n20 80 10\\n80 20 10\\n80 80 10\\n0 0\", \"5 16\\n70 66 40\\n38 52 20\\n40 35 10\\n70 30 10\\n20 60 10\\n1 100\\n54 75 20...
An open-top box having a square bottom is placed on the floor. You see a number of needles vertically planted on its bottom. You want to place a largest possible spheric balloon touching the box bottom, interfering with none of the side walls nor the needles. Java Specific: Submitted Java programs may not use "java.a...
0
{"tests": "{\"inputs\": [\"3\\n......\\n......\\n......\\n......\\n......\\n......\\n......\\n......\\n.RGB..\\nRGOP..\\nRGBPB.\\nRGBPP.\\nGBRGYP\\nGBRRYP\\nBGGRBB\\nBPRGYY\\nGGPRRY\\nBYPPRB\\nYGGGPB\\nGYYYPR\\nYRBRBR\\nYBRBRB\\nBRBRBR\\nBRBRBR\\n......\\n......\\n......\\n......\\n......\\n......\\n......\\n......\\n....
Masa Kita, who entered the University of Tokyo, joined a circle called TSG (University of Tokyo Super Gamers). This circle exhibits games at the Komaba Festival every year, and Masa Kita decided to create and display the games as well. The game created by Kitamasa is a common falling block puzzle game such as the fol...
0
{"tests": "{\"inputs\": [\"3 2 2 3 1\\n1 2 1\\n1 3 2\\n4 3 1 4 2\\n2 1 3\\n2 3 x\\n4 3 x\\n0 0 0 0 0\", \"3 2 2 3 1\\n1 2 1\\n1 3 2\\n4 3 1 4 2\\n2 1 4\\n2 3 x\\n4 3 x\\n0 0 0 0 0\", \"3 2 2 3 1\\n1 2 1\\n1 3 2\\n4 3 1 4 2\\n2 1 5\\n2 3 x\\n4 3 x\\n0 0 0 0 0\", \"3 2 2 3 1\\n1 2 1\\n1 3 1\\n4 3 1 4 2\\n2 1 3\\n2 3 x\\n...
Problem Statement A magician lives in a country which consists of N islands and M bridges. Some of the bridges are magical bridges, which are created by the magician. Her magic can change all the lengths of the magical bridges to the same non-negative integer simultaneously. This country has a famous 2-player race ga...
0.125
{"tests": "{\"inputs\": [\"1\\n0\\n\", \"3\\n0 0 1\\n\", \"3\\n0 0 0\\n\", \"2\\n0 0\\n\", \"100\\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\\n\", \"100\\n0 0 0 0...
When preparing a tournament, Codeforces coordinators try treir best to make the first problem as easy as possible. This time the coordinator had chosen some problem and asked n people about their opinions. Each person answered whether this problem is easy or hard. If at least one of these n people has answered that th...
0.875
{"tests": "{\"inputs\": [\"4\\n0 0\\n1 1\\n0 3\\n1 2\\n\", \"3\\n-1 -1\\n1 0\\n3 1\\n\", \"4\\n0 0\\n0 2\\n0 4\\n2 0\\n\", \"4\\n-10000 -10000\\n-10000 -9999\\n10000 10000\\n9999 10000\\n\", \"16\\n0 0\\n0 2\\n0 4\\n0 6\\n2 0\\n2 2\\n2 4\\n2 6\\n4 0\\n4 2\\n4 4\\n4 6\\n6 0\\n6 2\\n6 4\\n6 6\\n\", \"4\\n-10000 -10000\\n...
This problem is same as the previous one, but has larger constraints. It was a Sunday morning when the three friends Selena, Shiro and Katie decided to have a trip to the nearby power station (do not try this at home). After arriving at the power station, the cats got impressed with a large power transmission system c...
0.125
{"tests": "{\"inputs\": [\"5\\n0 10 2 3\\n0 10 3 3\\n900000000 1000000000 1 9999999\\n1 2 1 1\\n1 3 1 1\\n\", \"5\\n0 10 0 3\\n0 10 3 3\\n900000000 1000000000 1 9999999\\n1 2 1 1\\n1 3 1 1\\n\", \"5\\n0 10 -1 3\\n1 10 3 3\\n900000000 1000000000 1 9999999\\n1 2 1 1\\n1 3 1 1\\n\", \"5\\n0 10 -2 3\\n1 10 3 3\\n900000000 ...
Being tired of participating in too many Codeforces rounds, Gildong decided to take some rest in a park. He sat down on a bench, and soon he found two rabbits hopping around. One of the rabbits was taller than the other. He noticed that the two rabbits were hopping towards each other. The positions of the two rabbits ...
0.625
{"tests": "{\"inputs\": [\"8 16\\n\", \"1 2\\n\", \"1 1\\n\", \"28591024119784617 732203343197854927\\n\", \"23811264031960242 520940113721281721\\n\", \"8589934592 8989934592\\n\", \"658472316271074503 728242833853270665\\n\", \"25785331761502790 119852560236585580\\n\", \"190620774979376809 899159649449168622\\n\", \...
A little girl loves problems on bitwise operations very much. Here's one of them. You are given two integers l and r. Let's consider the values of <image> for all pairs of integers a and b (l ≤ a ≤ b ≤ r). Your task is to find the maximum value among all considered ones. Expression <image> means applying bitwise excl...
0.75
{"tests": "{\"inputs\": [\"2\\n1\\n1\\n1 1\\n\", \"3\\n1 2\\n3 3\\n2 1 3\\n\", \"4\\n1 2 3\\n3 2 1\\n3 2 2 3\\n\", \"48\\n3 42 46 11 44 25 1 42 38 49 14 42 44 10 4 12 2 20 27 44 14 50 33 10 42 27 41 48 26 42 40 18 9 42 1 2 47 8 20 39 45 42 47 8 19 41 32\\n36 32 45 48 26 26 38 38 10 7 31 50 23 23 15 17 18 25 24 44 29 12...
A little boy Laurenty has been playing his favourite game Nota for quite a while and is now very hungry. The boy wants to make sausage and cheese sandwiches, but first, he needs to buy a sausage and some cheese. The town where Laurenty lives in is not large. The houses in it are located in two rows, n houses in each r...
0.25
{"tests": "{\"inputs\": [\"5 5\\n..S..\\n****.\\nT....\\n****.\\n.....\\n\", \"5 5\\nS....\\n****.\\n.....\\n.****\\n..T..\\n\", \"1 2\\nST\\n\", \"3 3\\n**T\\n*S*\\n***\\n\", \"2 2\\nTS\\n.*\\n\", \"2 2\\nS.\\n.T\\n\", \"3 3\\nT.*\\n*.*\\n*S*\\n\", \"3 3\\n*..\\n...\\nTS.\\n\", \"2 2\\n.T\\nS*\\n\", \"2 2\\nST\\n*.\\n...
Woken up by the alarm clock Igor the financial analyst hurried up to the work. He ate his breakfast and sat in his car. Sadly, when he opened his GPS navigator, he found that some of the roads in Bankopolis, the city where he lives, are closed due to road works. Moreover, Igor has some problems with the steering wheel,...
0.875
{"tests": "{\"inputs\": [\"6\\n314159\\n\", \"30\\n000100000100000110000000001100\\n\", \"54\\n668822125317092836839407462257441103728473858428026440\\n\", \"33\\n459847811604598478116045984781160\\n\", \"9\\n975975975\\n\", \"300\\n518499551238825328417663140237955446550596254299485115465325550413577584420893115025535...
n evenly spaced points have been marked around the edge of a circle. There is a number written at each point. You choose a positive real number k. Then you may repeatedly select a set of 2 or more points which are evenly spaced, and either increase all numbers at points in the set by k or decrease all numbers at points...
0.125
{"tests": "{\"inputs\": [\"8\\nabaccaba\\n1 2 3 4 5 6 7 8\\n\", \"8\\nabacabac\\n1 1 1 1 1 1 1 1\\n\", \"8\\nabacabca\\n1 2 3 4 4 3 2 1\\n\", \"100\\novkihhgldgfmibpnlptjcgrtgbcrleflheanrmvteivsrvenrvrugggfvhfbnnachgddvlojtsjtmnmgpfbugvltfjhbngotjagd\\n34 71 77 50 21 88 24 60 79 84 59 33 15 65 89 2 81 69 91 47 23 7 55 ...
A string a of length m is called antipalindromic iff m is even, and for each i (1 ≤ i ≤ m) ai ≠ am - i + 1. Ivan has a string s consisting of n lowercase Latin letters; n is even. He wants to form some string t that will be an antipalindromic permutation of s. Also Ivan has denoted the beauty of index i as bi, and the...
0
{"tests": "{\"inputs\": [\"2\\n10 4\\n7 3\\n\\nSAMPLE\", \"2\\n16 4\\n7 3\\n\\nSAMPLE\", \"2\\n16 1\\n7 3\\n\\nSAMPLE\", \"2\\n16 1\\n7 2\\n\\nSAMPLE\", \"2\\n7 1\\n7 2\\n\\nSAMPLE\", \"2\\n7 1\\n12 2\\n\\nSAMPLE\", \"2\\n7 1\\n12 1\\n\\nRAMPLE\", \"2\\n7 1\\n19 2\\n\\nRAMLPE\", \"2\\n14 1\\n19 2\\n\\nRAMLPE\", \"2\\n1...
You are given two numbers N and K and a set X. X = { x : x is a natural number ≤ N } You have to find the total number of pairs of elements X[i] and X[j] belonging to the given set, such that, i < j and their sum is divisible by K. Input Format: An integer T followed by T lines, each containing a pair of space se...
0