info
stringlengths
120
50k
question
stringlengths
504
10.4k
avg@8_qwen3_4b_instruct_2507
float64
0
0.88
{"tests": "{\"inputs\": [\"4\\n4 2\\n4 1\\n2 3\\n2 1\\n3 1\\n\", \"4\\n3 1\\n4 1\\n4 2\\n3 2\\n3 4\\n\", \"5\\n3 5\\n2 5\\n1 5\\n1 4\\n4 3\\n1 3\\n2 3\\n4 5\\n4 2\\n\", \"6\\n3 1\\n5 4\\n2 1\\n6 2\\n5 2\\n3 6\\n6 4\\n3 2\\n3 4\\n6 1\\n6 5\\n5 1\\n2 4\\n3 5\\n\", \"5\\n4 5\\n1 5\\n4 3\\n2 5\\n2 1\\n2 4\\n3 5\\n2 3\\n1 3...
The tournament «Sleepyhead-2010» in the rapid falling asleep has just finished in Berland. n best participants from the country have participated in it. The tournament consists of games, each of them is a match between two participants. n·(n - 1) / 2 games were played during the tournament, and each participant had a m...
0
{"tests": "{\"inputs\": [\"5 5\\n-1 1 1 1 -1\\n1 1\\n2 3\\n3 5\\n2 5\\n1 5\\n\", \"2 3\\n1 -1\\n1 1\\n1 2\\n2 2\\n\", \"5 5\\n-1 -1 -1 -1 -1\\n1 1\\n1 1\\n3 4\\n1 1\\n1 4\\n\", \"7 7\\n-1 -1 -1 1 -1 -1 -1\\n1 1\\n2 7\\n1 3\\n1 5\\n4 7\\n1 7\\n6 7\\n\", \"9 9\\n-1 1 1 1 1 1 1 1 1\\n1 7\\n5 6\\n1 4\\n1 1\\n1 1\\n6 8\\n1 ...
Eugeny has array a = a1, a2, ..., an, consisting of n integers. Each integer ai equals to -1, or to 1. Also, he has m queries: * Query number i is given as a pair of integers li, ri (1 ≤ li ≤ ri ≤ n). * The response to the query will be integer 1, if the elements of array a can be rearranged so as the sum ali + a...
0.25
{"tests": "{\"inputs\": [\"1 4\\nSE23\\n\", \"5 7\\n000E0T3\\nT0TT0T0\\n010T0T0\\n2T0T0T0\\n0T0S000\\n\", \"1 10\\n9T9TSET9T9\\n\", \"3 3\\n920\\n752\\nE8S\\n\", \"1 5\\n78S6E\\n\", \"2 2\\nE9\\nS4\\n\", \"3 3\\n000\\nS0E\\n000\\n\", \"5 1\\n9\\nT\\nE\\n6\\nS\\n\", \"3 5\\n00000\\nS0E01\\n00000\\n\", \"5 5\\nS9999\\nTT...
You're a mikemon breeder currently in the middle of your journey to become a mikemon master. Your current obstacle is go through the infamous Biridian Forest. The forest The Biridian Forest is a two-dimensional grid consisting of r rows and c columns. Each cell in Biridian Forest may contain a tree, or may be vacant....
0
{"tests": "{\"inputs\": [\"2 9\\n3 4 5\\n0 7 8\\n\", \"3 10\\n1 2 3\\n4 -5 6\\n7 -8 9\\n\", \"10 100\\n0 100 1\\n1 -100 1\\n2 100 1\\n3 -100 1\\n4 100 1\\n5 -100 1\\n6 100 1\\n7 -100 1\\n8 100 1\\n9 -100 1\\n\", \"10 48\\n99 87 97\\n95 94 100\\n92 100 93\\n98 98 92\\n100 99 96\\n69 76 97\\n96 97 100\\n94 100 96\\n89 99...
On a number line there are n balls. At time moment 0 for each ball the following data is known: its coordinate xi, speed vi (possibly, negative) and weight mi. The radius of the balls can be ignored. The balls collide elastically, i.e. if two balls weighing m1 and m2 and with speeds v1 and v2 collide, their new speeds...
0
{"tests": "{\"inputs\": [\"5 5 2 3 1 1\\n\", \"5 7 1 3 2 2\\n\", \"2 6 1 2 2 2\\n\", \"100 100 50 50 500 500\\n\", \"1000000 2 2 2 2 1\\n\", \"33999 99333 33000 99000 3 9\\n\", \"5 1 3 1 1 1\\n\", \"6 1 5 1 2 2\\n\", \"100 100 70 5 1 1\\n\", \"1 100 1 50 1 50\\n\", \"11 11 3 3 4 4\\n\", \"5 8 4 2 1 2\\n\", \"1000000 10...
Dima and Inna are doing so great! At the moment, Inna is sitting on the magic lawn playing with a pink pony. Dima wanted to play too. He brought an n × m chessboard, a very tasty candy and two numbers a and b. Dima put the chessboard in front of Inna and placed the candy in position (i, j) on the board. The boy said h...
0
{"tests": "{\"inputs\": [\"3 2\\n1 2\\n2 3\\n\", \"2 1\\n1 2\\n\", \"1 0\\n\", \"26 17\\n1 2\\n2 3\\n1 6\\n6 7\\n7 8\\n2 9\\n4 10\\n3 11\\n11 12\\n9 13\\n6 14\\n2 16\\n5 18\\n6 19\\n11 22\\n15 24\\n6 26\\n\", \"8 5\\n1 2\\n1 3\\n1 4\\n5 6\\n7 8\\n\", \"10 10\\n1 8\\n4 10\\n4 6\\n5 10\\n2 3\\n1 7\\n3 4\\n3 6\\n6 9\\n3 7...
DZY loves chemistry, and he enjoys mixing chemicals. DZY has n chemicals, and m pairs of them will react. He wants to pour these chemicals into a test tube, and he needs to pour them in one by one, in any order. Let's consider the danger of a test tube. Danger of an empty test tube is 1. And every time when DZY pour...
0.75
{"tests": "{\"inputs\": [\"5 2 1\\n1 2 3 4 5\\n\", \"7 1 3\\n2 10 7 18 5 33 0\\n\", \"10 1 10\\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000\\n\", \"23 2 4\\n965481468 524609549 327408602 598336282 745920261 141281382 661619186 475657944 798069657 1991861...
The new ITone 6 has been released recently and George got really keen to buy it. Unfortunately, he didn't have enough money, so George was going to work as a programmer. Now he faced the following problem at the work. Given a sequence of n integers p1, p2, ..., pn. You are to choose k pairs of integers: [l1, r1], [l2...
0.5
{"tests": "{\"inputs\": [\"3 1\\n1 2 3\\n\", \"3 4\\n1 3 2\\n\", \"29 121\\n1 25 15 18 29 26 3 9 16 8 7 5 12 11 24 28 10 13 27 14 21 17 22 20 6 23 19 4 2\\n\", \"1 1\\n1\\n\", \"29 124\\n25 17 19 13 18 10 4 15 27 26 23 12 3 7 29 9 22 6 5 20 24 28 11 14 8 16 2 1 21\\n\", \"30 187\\n4 18 2 8 5 9 15 14 25 16 30 12 7 24 13...
You are given a permutation of n numbers p1, p2, ..., pn. We perform k operations of the following type: choose uniformly at random two indices l and r (l ≤ r) and reverse the order of the elements pl, pl + 1, ..., pr. Your task is to find the expected value of the number of inversions in the resulting permutation. In...
0
{"tests": "{\"inputs\": [\"3 0\\n\", \"4 1\\n3 = 6\\n\", \"3 1\\n2 &gt; 3\\n\", \"1 1\\n1 <= 2\\n\", \"8 5\\n2 <= 4\\n5 > 10\\n3 < 9\\n4 = 8\\n12 >= 16\\n\", \"10 5\\n17 <= 10\\n16 >= 18\\n9 > 18\\n8 = 8\\n6 >= 13\\n\", \"1 1\\n1 > 2\\n\", \"5 8\\n8 = 9\\n7 >= 7\\n3 <= 9\\n4 > 10\\n5 >= 1\\n7 = 7\\n2 < 6\\n4 <= 7\\n\",...
King of Berland Berl IV has recently died. Hail Berl V! As a sign of the highest achievements of the deceased king the new king decided to build a mausoleum with Berl IV's body on the main square of the capital. The mausoleum will be constructed from 2n blocks, each of them has the shape of a cuboid. Each block has th...
0
{"tests": "{\"inputs\": [\"8 8 0 2 8 3 4 5\\n\", \"10 10 -7 0 5 8 2 11\\n\", \"870 396 187 223 444 202 222 732\\n\", \"10 10 -7 -7 5 8 2 11\\n\", \"254 578 251 809 412 966 92 984\\n\", \"767 238 263 303 155 351 21 686\\n\", \"10 10 7 7 5 8 2 11\\n\", \"10 10 7 -7 5 8 2 11\\n\", \"403 24 708 984 850 765 344 865\\n\", \"...
Petya has recently started working as a programmer in the IT city company that develops computer games. Besides game mechanics implementation to create a game it is necessary to create tool programs that can be used by game designers to create game levels. Petya's first assignment is to create a tool that allows to pa...
0
{"tests": "{\"inputs\": [\"3\\n3 4 2\\n\", \"2\\n1 1\\n\", \"10\\n529280935 122195401 684409084 743180136 724768643 211207376 167236398 696535490 425348743 1\\n\", \"5\\n483078839 692549116 1 458438081 1\\n\", \"15\\n2 72 77 69 62 73 58 9 4 95 97 14 41 79 34\\n\", \"50\\n1 3083990 976356336 922018335 1 170272482 1 5472...
Long ago, Vasily built a good fence at his country house. Vasily calls a fence good, if it is a series of n consecutively fastened vertical boards of centimeter width, the height of each in centimeters is a positive integer. The house owner remembers that the height of the i-th board to the left is hi. Today Vasily de...
0
{"tests": "{\"inputs\": [\"9 12 4\\nbbaaababb\\nabbbabbaaaba\\n\", \"3 2 2\\nabc\\nab\\n\", \"120 362 6\\ncaaccbbbabbbcbaacbaccacaaccacaaababccaccaabaccacccbbaaaaababbccbbacccaacabacbaaacabbacbabcccbccbcbbcaabaaabaabcccaabacbb\\nabcbbaaccbbcabbcbbcacbabaacbaaacabcbabcabbabccbcaaacaccaaabbcbaacccccbcabacaacabbbcabaabcbb...
After returned from forest, Alyona started reading a book. She noticed strings s and t, lengths of which are n and m respectively. As usual, reading bored Alyona and she decided to pay her attention to strings s and t, which she considered very similar. Alyona has her favourite positive integer k and because she is to...
0.25
{"tests": "{\"inputs\": [\"3\\n0 0 1\\n0 0 1\\n1 1 0\\n\", \"4\\n0 1 1 1\\n1 0 1 1\\n1 1 0 1\\n1 1 1 0\\n\", \"3\\n0 0 0\\n0 0 1\\n0 1 0\\n\", \"4\\n0 0 1 0\\n0 0 0 1\\n1 0 0 0\\n0 1 0 0\\n\", \"4\\n0 0 0 1\\n0 0 0 0\\n0 0 0 1\\n1 0 1 0\\n\", \"10\\n0 0 0 0 0 0 1 0 0 0\\n0 0 0 0 0 0 0 0 0 0\\n0 0 0 1 0 0 0 0 0 0\\n0 0 ...
There are n points marked on the plane. The points are situated in such a way that they form a regular polygon (marked points are its vertices, and they are numbered in counter-clockwise order). You can draw n - 1 segments, each connecting any two marked points, in such a way that all points have to be connected with e...
0.125
{"tests": "{\"inputs\": [\"2\\n1 1\\n2 1\\n\\nSAMPLE\", \"10\\n29 7\\n58 29\\n32 24\\n31 3\\n15 15\\n31 14\\n79 14\\n93 89\\n80 76\\n85 19\", \"10\\n19 80\\n94 80\\n18 1\\n26 90\\n39 48\\n22 16\\n78 7\\n94 39\\n87 99\\n21 52\", \"10\\n29 7\\n58 29\\n32 24\\n31 3\\n15 15\\n31 14\\n79 26\\n93 89\\n80 76\\n85 19\", \"2\\n...
You have just purchased a new mobile phone and you want to call all of your relatives to brag about your new phone. You have N relatives. You will talk to i^th relative for exactly Ti minutes. Each minute costs you 1 dollar . However, your relatives are generous. Hence after the conversation, they will add a recharge o...
0
{"tests": "{\"inputs\": [\"4\\n1 1 2\\n1 -1 0\\n3 -1 -2\\n1 -3 4\", \"3\\n1 1 1\\n2 -1 2\\n-1 2 2\", \"7\\n1 7 8\\n-2 4 9\\n3 -8 -5\\n9 2 -14\\n6 7 5\\n-8 -9 3\\n3 8 10\", \"4\\n1 1 2\\n1 -1 0\\n3 -1 -2\\n1 -3 5\", \"3\\n1 1 1\\n2 -1 2\\n-1 2 4\", \"3\\n1 1 1\\n2 -1 2\\n-1 2 1\", \"7\\n1 7 8\\n-2 4 9\\n3 -8 -5\\n9 2 -1...
There are N lines in the xy-plane. The i-th line is represented by A_ix+B_iy=C_i. Any two lines among the N+2 lines, the above N lines plus the x-axis and y-axis, cross each other at exactly one point. For each pair 1 \leq i < j \leq N, there is a car at the cross point of the i-th and j-th lines. Even where three or ...
0.625
{"tests": "{\"inputs\": [\"8\\n3\\n2\\n3\\n1\\n4\\n6\\n20\\n4\\n4\\n12\\n8\\n16\\n7\\n7\\n11\\n8\\n0\", \"8\\n3\\n2\\n3\\n1\\n4\\n6\\n20\\n4\\n4\\n10\\n8\\n16\\n7\\n7\\n11\\n8\\n0\", \"8\\n3\\n2\\n3\\n1\\n4\\n6\\n20\\n4\\n4\\n12\\n8\\n16\\n7\\n7\\n4\\n8\\n0\", \"8\\n3\\n2\\n3\\n1\\n4\\n6\\n20\\n4\\n4\\n14\\n8\\n16\\n7\...
problem JOI Pizza sells pizza home delivery along the d-meter-long ring road that runs through the city center. JOI Pizza has n stores S1, ..., Sn on the loop line. The head office is S1. The distance from S1 to Si when moving the loop line clockwise is set to di meters. D2 , ..., dn is an integer greater than or equ...
0
{"tests": "{\"inputs\": [\"100000 1 1\\n-1\", \"65 60 3\\n-2 3 -4\", \"60 59 1\\n-123\", \"65 60 3\\n-2 10 -3\", \"65 1 3\\n-2 3 -4\", \"60 59 1\\n-68\", \"120 60 3\\n-2 10 -3\", \"48 1 3\\n-2 3 -4\", \"48 1 5\\n-2 3 -4\", \"48 1 5\\n-2 3 -3\", \"48 1 10\\n-2 0 -3\", \"48 1 14\\n-2 0 -3\", \"48 1 14\\n-2 0 -5\", \"48 1...
Chokudai loves eating so much. However, his doctor Akensho told him that he was overweight, so he finally decided to lose his weight. Chokudai made a slimming plan of a $D$-day cycle. It is represented by $D$ integers $w_0, ..., w_{D-1}$. His weight is $S$ on the 0-th day of the plan and he aims to reduce it to $T$ ($...
0
{"tests": "{\"inputs\": [\"6\\n<span class=\\\"tex-span\\\"></span>\\n1\\n<span class=\\\"tex-span\\\"></span>\\n2\\n<span class=\\\"tex-span\\\"></span>\\n3 \\n<span class=\\\"tex-span\\\"></span>\\n2\\n<span class=\\\"tex-span\\\"></span>\\n1\\n<span class=\\\"tex-span\\\"></span>\\n0\", \"8\\n<span class=\\\"tex-spa...
This is an interactive problem. Imur Ishakov decided to organize a club for people who love to play the famous game «The hat». The club was visited by n students, where n is even. Imur arranged them all in a circle and held a draw to break the students in pairs, but something went wrong. The participants are numbered ...
0
{"tests": "{\"inputs\": [\"6\\n4 0\\n5 8\\n0 1000000\\n0 0\\n1 0\\n1000000 1000000\\n\", \"1\\n5 0\\n\", \"1\\n7 0\\n\", \"1\\n15 0\\n\", \"1\\n1000000 0\\n\", \"1\\n3 0\\n\", \"1\\n7 1\\n\", \"6\\n6 0\\n5 8\\n0 1000000\\n0 0\\n1 0\\n1000000 1000000\\n\", \"1\\n8 1\\n\", \"6\\n6 0\\n5 8\\n0 1000000\\n1 0\\n1 0\\n100000...
We have a point A with coordinate x = n on OX-axis. We'd like to find an integer point B (also on OX-axis), such that the absolute difference between the distance from O to B and the distance from A to B is equal to k. <image> The description of the first test case. Since sometimes it's impossible to find such point ...
0.125
{"tests": "{\"inputs\": [\"13\\n\", \"377\\n\", \"53824509026\\n\", \"6138242440179\\n\", \"10\\n\", \"9999999999945\\n\", \"3153355924376\\n\", \"9999999999998\\n\", \"9999999999999\\n\", \"9137820308201\\n\", \"4917874132879\\n\", \"2755560887426\\n\", \"9\\n\", \"1\\n\", \"113\\n\", \"112\\n\", \"5\\n\", \"997290039...
John Doe has a list of all Fibonacci numbers modulo 1013. This list is infinite, it starts with numbers 0 and 1. Each number in the list, apart from the first two, is a sum of previous two modulo 1013. That is, John's list is made from the Fibonacci numbers' list by replacing each number there by the remainder when div...
0
{"tests": "{\"inputs\": [\"3\\n3 1\\n1 3\\n\", \"2\\n1 2\\n\", \"3\\n2 1\\n3 2\\n\", \"15\\n5 12\\n4 5\\n1 2\\n1 5\\n12 11\\n11 14\\n15 3\\n7 2\\n10 6\\n3 10\\n1 4\\n9 9\\n8 13\\n11 5\\n\", \"4\\n2 1\\n1 4\\n1 1\\n\", \"50\\n4 24\\n7 26\\n39 28\\n3 37\\n29 38\\n16 17\\n48 49\\n27 34\\n28 22\\n48 47\\n34 11\\n11 43\\n46...
You are given a square matrix consisting of n rows and n columns. We assume that the rows are numbered from 1 to n from top to bottom and the columns are numbered from 1 to n from left to right. Some cells (n - 1 cells in total) of the the matrix are filled with ones, the remaining cells are filled with zeros. We can a...
0
{"tests": "{\"inputs\": [\"5 0\\n5 3 4 1 2\\n\", \"10 -10\\n5 5 1 7 5 1 2 4 9 2\\n\", \"5 0\\n5 5 4 1 2\\n\", \"10 -10\\n5 5 1 7 4 1 2 4 9 2\\n\", \"10 0\\n5 5 1 7 4 1 2 4 9 2\\n\", \"10 -10\\n5 5 1 0 5 1 2 4 9 2\\n\", \"5 0\\n5 5 4 0 2\\n\", \"10 -10\\n5 5 1 7 4 1 0 4 9 2\\n\", \"10 -12\\n5 5 1 0 5 1 2 4 9 2\\n\", \"1...
During the last Sereja's Codesecrof round the server crashed many times, so the round was decided to be made unrated for some participants. Let's assume that n people took part in the contest. Let's assume that the participant who got the first place has rating a1, the second place participant has rating a2, ..., the...
0
{"tests": "{\"inputs\": [\"?01???\\n\", \"1\\n\", \"**12\\n\", \"?\\n\", \"0\\n\", \"01\\n\", \"1?\\n\", \"*\\n\", \"?01*??****\\n\", \"0?\\n\", \"21?20*0000?2?22??0001*?1??12?20020200?**0*12?*221*0*1200*?0*11?022*110*2*2022120*2*2100*0?0*02?012?1\\n\", \"1*\\n\", \"2\\n\", \"2?\\n\", \"2*\\n\", \"0*\\n\", \"?2?\\n\", ...
Game "Minesweeper 1D" is played on a line of squares, the line's height is 1 square, the line's width is n squares. Some of the squares contain bombs. If a square doesn't contain a bomb, then it contains a number from 0 to 2 — the total number of bombs in adjacent squares. For example, the correct field to play looks ...
0
{"tests": "{\"inputs\": [\"2 3\\n1 1\\n2\\n1 -2\\n\", \"4 2\\n2\\n1 3\\n\", \"6 3\\n1 2\\n2\\n1 2\\n\", \"24 8\\n1 17\\n2\\n1 -10\\n2\\n2\\n2\\n2\\n1 19\\n\", \"6 9\\n2\\n1 -2\\n2\\n1 -6\\n1 -6\\n1 4\\n2\\n1 -1\\n2\\n\", \"10 10\\n1 2\\n1 -10\\n1 -5\\n2\\n2\\n1 -4\\n2\\n2\\n1 -10\\n1 -9\\n\", \"364 57\\n1 -101\\n1 110\...
Little Artem is fond of dancing. Most of all dances Artem likes rueda — Cuban dance that is danced by pairs of boys and girls forming a circle and dancing together. More detailed, there are n pairs of boys and girls standing in a circle. Initially, boy number 1 dances with a girl number 1, boy number 2 dances with a g...
0.75
{"tests": "{\"inputs\": [\"4 3 0\\n\", \"4 3 7\\n\", \"4 3 11\\n\", \"9213788 21936127 8761236\\n\", \"2182 23967 52288026\\n\", \"4 5 4\\n\", \"4 5 17\\n\", \"6 9 43\\n\", \"4 4 6\\n\", \"1000000000 1000000000 999999999\\n\", \"636553724 546535019 115079316355948443\\n\", \"6 8 15\\n\", \"4 5 13\\n\", \"6 6 6\\n\", \"...
You might have heard about the next game in Lara Croft series coming out this year. You also might have watched its trailer. Though you definitely missed the main idea about its plot, so let me lift the veil of secrecy. Lara is going to explore yet another dangerous dungeon. Game designers decided to use good old 2D e...
0
{"tests": "{\"inputs\": [\"2\\nwww.google.com\\nwww.hackerearth.com\\n\\nSAMPLE\", \"100\\nwww.oazqupphakywpbqyfajsmgwcfcxuaaarpxhsyiljjzehrmifcxaldbffnkbdtfvzdrjnlnixdaobbfrppdrbmyducp.com\\nwww.wwbikcjsdqqnzrywdmibxbhfiqsmwuvhbsewgjswat.com\\nwww.cm.com\\nwww.knbwiewnxvdashnytchqsklwzlelczdkhamhlfbpduhefwori.com\\nww...
In the race for the best Internet browser, there's now a new contender for it, this browser is called the: "The Semantic Mind-Reader!" After its promo on the world wide web, everyone's been desperately waiting for the browser to be released. And why shouldn't they be curious about it, after all, it's the new project of...
0.5
{"tests": "{\"inputs\": [\"91\", \"314159265358979323846264338327950288419716939937551058209749445923078164062862089986280348253421170\", \"36\", \"30\", \"476640020082194381531155118436783393866726953614433851622190777875571135215042541028243752681838573\", \"22\", \"41\", \"4024190595003667858693588822821631596741656...
In the Kingdom of AtCoder, only banknotes are used as currency. There are 10^{100}+1 kinds of banknotes, with the values of 1, 10, 10^2, 10^3, \dots, 10^{(10^{100})}. You have come shopping at a mall and are now buying a takoyaki machine with a value of N. (Takoyaki is the name of a Japanese snack.) To make the paymen...
0
{"tests": "{\"inputs\": [\"RUDLUDR\", \"DULL\", \"RDULULDURURLRDULRLR\", \"UUUUUUUUUUUUUUU\", \"ULURU\", \"RDULDUR\", \"LLUD\", \"RDULULDURURLLDULRRR\", \"ULURV\", \"EULL\", \"RCULULDURURLLDULRRR\", \"UKURU\", \"EULM\", \"RCVLULDURURLLDULRRR\", \"UJURU\", \"RCVLULDURURKLDULRRR\", \"URUJU\", \"RCVLUUDURLRKLDULRRR\", \"R...
Takahashi will do a tap dance. The dance is described by a string S where each character is `L`, `R`, `U`, or `D`. These characters indicate the positions on which Takahashi should step. He will follow these instructions one by one in order, starting with the first character. S is said to be easily playable if and onl...
0.875
{"tests": "{\"inputs\": [\"314159265 7\\n21662711\\n77271666\\n89022761\\n156626166\\n160332356\\n166902656\\n298992265\", \"10 6\\n1\\n2\\n3\\n6\\n7\\n9\", \"10 3\\n2\\n7\\n9\", \"314159265 7\\n21662711\\n77271666\\n89022761\\n156626166\\n160332356\\n166902656\\n453863319\", \"6 6\\n1\\n2\\n3\\n6\\n7\\n9\", \"10 3\\n2...
Takahashi Lake has a perimeter of L. On the circumference of the lake, there is a residence of the lake's owner, Takahashi. Each point on the circumference of the lake has a coordinate between 0 and L (including 0 but not L), which is the distance from the Takahashi's residence, measured counter-clockwise. There are N...
0
{"tests": "{\"inputs\": [\"5\\n1 2 3 4 5\", \"4\\n2 3 4 6\", \"5\\n1 2 3 1 5\", \"4\\n2 0 4 6\", \"5\\n1 2 3 0 5\", \"4\\n1 0 4 6\", \"5\\n1 2 4 0 5\", \"4\\n1 0 2 6\", \"5\\n1 2 6 0 5\", \"4\\n1 0 2 2\", \"5\\n1 4 6 0 5\", \"4\\n2 0 2 2\", \"4\\n2 0 3 2\", \"4\\n2 0 6 2\", \"5\\n1 4 3 4 5\", \"4\\n2 3 4 1\", \"5\\n2 2...
There are N integers written on a blackboard. The i-th integer is A_i. Takahashi and Aoki will arrange these integers in a row, as follows: * First, Takahashi will arrange the integers as he wishes. * Then, Aoki will repeatedly swap two adjacent integers that are coprime, as many times as he wishes. We will assume...
0
{"tests": "{\"inputs\": [\"4\\n1.0,0.0\\n0.0,1.0\\n2.0,1.0\\n1.0,2.0\\n9\\n-509.94,892.63\\n567.62,639.99\\n-859.32,-64.84\\n-445.99,383.69\\n667.54,430.49\\n551.12,828.21\\n-940.2,-877.2\\n-361.62,-970\\n-125.42,-178.48\\n0\", \"4\\n1.0,0.0\\n0.0,1.0\\n2.0,1.0\\n1.0,2.0\\n9\\n-509.94,892.63\\n567.62,639.99\\n-859.32,-...
Hit n nails one by one at the coordinates P1 (x1, y1), P2 (x2, y2), P3 (x3, y3), ..., Pn (xn, yn) on the flat plate, and put them on the rubber band ring. Surround it with a single rubber band so that all the nails fit inside. At this time, the rubber bands must not intersect. Create a program that reads the coordinat...
0
{"tests": "{\"inputs\": [\"6 5\\n1 2 200 10\\n1 4 400 15\\n1 3 250 25\\n2 4 100 10\\n4 5 150 20\\n3 5 300 20\\n2\\n1 5 0\\n1 5 1\\n0 0\", \"6 5\\n1 2 200 10\\n1 4 400 15\\n1 3 250 25\\n2 4 100 10\\n4 5 150 20\\n3 5 300 30\\n2\\n1 5 0\\n1 5 1\\n0 0\", \"6 5\\n1 2 200 10\\n1 4 400 22\\n1 3 250 25\\n2 4 100 10\\n4 5 150 2...
Taro is planning a long trip by train during the summer vacation. However, in order for Taro, who is a high school student, to travel as far as possible during the summer vacation, which has only one month, he cannot make a good plan unless he finds the cheapest and the fastest way. Let's create a program to help Taro'...
0
{"tests": "{\"inputs\": [\"3 7\\n3\\n7 10\\n1 4\\n4 5\", \"5 7\\n3\\n1 4\\n4 5\\n7 10\", \"3 7\\n3\\n7 10\\n1 4\\n7 5\", \"5 11\\n3\\n1 4\\n4 5\\n1 2\", \"5 7\\n3\\n1 4\\n4 5\\n1 10\", \"3 7\\n3\\n7 10\\n1 4\\n8 5\", \"5 11\\n3\\n1 4\\n4 5\\n1 10\", \"3 7\\n3\\n13 10\\n1 4\\n8 5\", \"3 7\\n3\\n13 16\\n1 4\\n8 5\", \"3 ...
The supercomputer system L in the PCK Research Institute performs a variety of calculations upon request from external institutes, companies, universities and other entities. To use the L system, you have to reserve operation time by specifying the start and end time. No two reservation periods are allowed to overlap e...
0
{"tests": "{\"inputs\": [\"2\\n5\\n15 40\\n35 20\\n50 45\\n70 30\\n80 10\\n3\\n20 3\\n60 2\\n65 2\\n6\\n40 4100\\n25 7500\\n10 18000\\n90 7000\\n25 15000\\n25 22000\\n5\\n15 40\\n35 20\\n50 45\\n70 30\\n80 10\\n2\\n60 4\\n75 1\\n3\\n60 6000\\n75 6000\\n85 6000\", \"2\\n5\\n15 40\\n35 20\\n50 45\\n70 30\\n80 8\\n3\\n20 ...
Mr. Denjiro is a science teacher. Today he has just received a specially ordered water tank that will certainly be useful for his innovative experiments on water flow. <image> --- Figure 1: The water tank The size of the tank is 100cm (Width) * 50cm (Height) * 30cm (Depth) (see Figure 1). For the experiments, he fits...
0
{"tests": "{\"inputs\": [\"3 3\\nABC\\nD.D\\nCBA\", \"5 10\\n..A.......\\n.......B..\\n..........\\n..B.......\\n..A.CC....\", \"5 7\\nNUTUBOR\\nQT.SZRQ\\nSANAGIP\\nLMDGZBM\\nKLKIODP\", \"5 7\\nNBTUUOR\\nQT.SZRQ\\nSANAGIP\\nLMDGZBM\\nKLKIODP\", \"5 0\\nNBTUUOR\\nQT.SZRQ\\nPIGANAS\\nLMDGZBM\\nPDOIKKL\", \"5 7\\nOUTUBOR\...
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 quickly solve popular puzzles and train your instantaneous power. Today's challenge is a puzzle of colorful tiles lined up and erasing them well. In the initial st...
0
{"tests": "{\"inputs\": [\"7 4\\nconnected\\ndisconnected\\ngraph\\ndirected\\ndiameter\\ndistance\\nminor\\nc ed\\ndi ed\\ndis ed\\ndis e\", \"6 7\\nappreciate\\nappropriate\\nacceptance\\nace\\nacm\\nacetylene\\nappr iate\\na e\\na a\\nac ce\\nace e\\nacceptance acceptance\\nno match\", \"5 5\\nd\\ndd\\nddd\\ndddd\\n...
As an English learner, sometimes you cannot remember the entire spelling of English words perfectly, but you can only remember their prefixes and suffixes. For example, you may want to use a word which begins with 'appr' and ends with 'iate', but forget the middle part of the word. It may be 'appreciate', 'appropriate'...
0.125
{"tests": "{\"inputs\": [\"10\\n1236547896\", \"11\\n31415926535\", \"10\\n1598114589\", \"11\\n18396312558\", \"10\\n2555486547\", \"10\\n2722382398\", \"10\\n2713182985\", \"10\\n4333783596\", \"11\\n24764186449\", \"10\\n1859787539\", \"10\\n1888971773\", \"10\\n6843843631\", \"10\\n3639938767\", \"10\\n3398916166\"...
Problem Den, the phone number of Ukunikia Co., Ltd., enters a very long phone number into the phone every day. One day, too tired, Den came up with a surprising idea. "Isn't it even a little easier if you rearrange the arrangement of the buttons on the phone ?!" The phone has squares evenly spaced at $ 3 \ times 3 $,...
0
{"tests": "{\"inputs\": [\"4\\n54\\n50\\n2\\n178\\n\", \"1\\n179\\n\", \"69\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\...
You are given an angle ang. The Jury asks You to find such regular n-gon (regular polygon with n vertices) that it has three vertices a, b and c (they can be non-consecutive) with \angle{abc} = ang or report that there is no such n-gon. <image> If there are several answers, print the minimal one. It is guarantied t...
0.375
{"tests": "{\"inputs\": [\"3 2\\n\", \"4 2\\n\", \"1000000000000000000 42\\n\", \"6 2\\n\", \"288230376151711743 100\\n\", \"1000000000000000000 99\\n\", \"25 2\\n\", \"2 5\\n\", \"6 4\\n\", \"1 5\\n\", \"6 5\\n\", \"1000000000000000000 3\\n\", \"1000000000000000000 69\\n\", \"7 4\\n\", \"69 30\\n\", \"1441151880758558...
Reziba has many magic gems. Each magic gem can be split into M normal gems. The amount of space each magic (and normal) gem takes is 1 unit. A normal gem cannot be split. Reziba wants to choose a set of magic gems and split some of them, so the total space occupied by the resulting set of gems is N units. If a magic g...
0
{"tests": "{\"inputs\": [\"3\\n-1 0\\n0 2\\n1 0\\n\", \"5\\n1 0\\n1 -1\\n0 -1\\n-1 0\\n-1 -1\\n\", \"1\\n-751115 -925948\\n\", \"1\\n-751115 -1566406\\n\", \"3\\n-1 -1\\n0 2\\n1 0\\n\", \"3\\n0 -1\\n0 2\\n2 0\\n\", \"1\\n-751115 -2469241\\n\", \"3\\n-1 -1\\n0 2\\n2 0\\n\", \"1\\n-751115 -4760337\\n\", \"1\\n-751115 -43...
Recently Vasya learned that, given two points with different x coordinates, you can draw through them exactly one parabola with equation of type y = x^2 + bx + c, where b and c are reals. Let's call such a parabola an U-shaped one. Vasya drew several distinct points with integer coordinates on a plane and then drew an...
0.125
{"tests": "{\"inputs\": [\"5\\n10\\n0001111111\\n4\\n0101\\n8\\n11001101\\n10\\n1110000000\\n1\\n1\\n\", \"5\\n10\\n0001111111\\n4\\n0101\\n8\\n11001101\\n10\\n1010000000\\n1\\n1\\n\", \"5\\n10\\n0011111111\\n4\\n0101\\n8\\n11001101\\n10\\n1010000000\\n1\\n1\\n\", \"5\\n10\\n0001111110\\n4\\n0101\\n8\\n11001101\\n10\\n...
Lee was cleaning his house for the party when he found a messy string under the carpets. Now he'd like to make it clean accurately and in a stylish way... The string s he found is a binary string of length n (i. e. string consists only of 0-s and 1-s). In one move he can choose two consecutive characters s_i and s_{i...
0
{"tests": "{\"inputs\": [\"1\\n- 1\\n+\\n\", \"3\\n+\\n+\\n+\\n- 2\\n- 1\\n- 3\\n\", \"4\\n+\\n+\\n- 2\\n+\\n- 3\\n+\\n- 1\\n- 4\\n\", \"4\\n+\\n- 1\\n+\\n+\\n- 4\\n+\\n- 2\\n- 3\\n\", \"5\\n+\\n- 5\\n+\\n+\\n+\\n- 4\\n+\\n- 1\\n- 2\\n- 3\\n\", \"10\\n+\\n- 3\\n+\\n+\\n+\\n+\\n- 1\\n- 7\\n- 9\\n- 10\\n+\\n+\\n+\\n- 4\\...
Tenten runs a weapon shop for ninjas. Today she is willing to sell n shurikens which cost 1, 2, ..., n ryo (local currency). During a day, Tenten will place the shurikens onto the showcase, which is empty at the beginning of the day. Her job is fairly simple: sometimes Tenten places another shuriken (from the available...
0
{"tests": "{\"inputs\": [\"6\\n4 1\\n2 3 5 4\\n5 6\\n1 1 3 4 4\\n1 10\\n2\\n2 10\\n11 9\\n2 10\\n12 11\\n5 18\\n81 324 218 413 324\\n\", \"3\\n5 15\\n5 15 8 10 10\\n6 5\\n2 3 15 4 15 7\\n8 7\\n12 14 9 7 15 14 8 3\\n\", \"3\\n5 15\\n5 15 8 10 10\\n6 3\\n2 3 15 4 15 7\\n8 7\\n12 14 9 7 15 14 8 3\\n\", \"6\\n4 1\\n2 3 5 4...
You are given a sequence a consisting of n integers a_1, a_2, ..., a_n, and an integer x. Your task is to make the sequence a sorted (it is considered sorted if the condition a_1 ≤ a_2 ≤ a_3 ≤ ... ≤ a_n holds). To make the sequence sorted, you may perform the following operation any number of times you want (possibly ...
0.125
{"tests": "{\"inputs\": [\"3 2\\n01\\n10\\n00\\n2 3\\n001\\n111\\n\", \"3 3\\n000\\n010\\n000\\n1 1\\n1\\n\", \"1 14\\n11110101110010\\n50 3\\n101\\n011\\n010\\n100\\n011\\n011\\n100\\n100\\n110\\n101\\n000\\n111\\n100\\n010\\n000\\n001\\n101\\n111\\n110\\n111\\n100\\n011\\n110\\n110\\n100\\n001\\n011\\n100\\n100\\n010...
You've got two rectangular tables with sizes na × ma and nb × mb cells. The tables consist of zeroes and ones. We will consider the rows and columns of both tables indexed starting from 1. Then we will define the element of the first table, located at the intersection of the i-th row and the j-th column, as ai, j; we w...
0.875
{"tests": "{\"inputs\": [\"2\\n1 100\\n100 2\\n\", \"3\\n3 1\\n100 2\\n3 2\\n\", \"6\\n264896923 2497658\\n57071588 447086061\\n2497658 483723090\\n57071588 264896923\\n158310110 483723090\\n158310110 72866107\\n\", \"1\\n2105127 227379126\\n\", \"3\\n458744979 589655889\\n248228386 824699605\\n458744979 824699605\\n\"...
One day Bob got a letter in an envelope. Bob knows that when Berland's post officers send a letter directly from city «A» to city «B», they stamp it with «A B», or «B A». Unfortunately, often it is impossible to send a letter directly from the city of the sender to the city of the receiver, that's why the letter is sen...
0
{"tests": "{\"inputs\": [\"AA\\nA\\nA\\n\", \"AJKEQSLOBSROFGZ\\nOVGURWZLWVLUXTH\\nOZ\\n\", \"ABBBABABABABABBABAABAAABABAABABABABBABAAAABABABBABAABABAAABAABBAAABAABABBABBABABBABAABABABAAAAABABAB\\nB\\nBABBABAABABABABABABABABABBAABABBABABBAAABAAABABBAABAABBABABBABABAABBABAABABBAABAABAABABABABABBABABAB\\n\", \"KOROXDDWEUV...
In mathematics, a subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements. For example, the sequence BDF is a subsequence of ABCDEF. A substring of a string is a continuous subsequence of the string. For example, BCD is a substri...
0
{"tests": "{\"inputs\": [\"0 2 1\\n1 0 100\\n1 2 0\\n5\\n\", \"0 2 2\\n1 0 100\\n1 2 0\\n3\\n\", \"0 1 1\\n1 0 1\\n1 1 0\\n3\\n\", \"0 9628 4599\\n6755 0 5302\\n5753 1995 0\\n39\\n\", \"0 4449 3122\\n6816 0 8986\\n1048 1468 0\\n4\\n\", \"0 2986 6350\\n59 0 9863\\n8674 1704 0\\n40\\n\", \"0 2653 5614\\n9654 0 8668\\n642...
The Tower of Hanoi is a well-known mathematical puzzle. It consists of three rods, and a number of disks of different sizes which can slide onto any rod. The puzzle starts with the disks in a neat stack in ascending order of size on one rod, the smallest at the top, thus making a conical shape. The objective of the pu...
0
{"tests": "{\"inputs\": [\"1 5 2\\n1 5 10\\n2 7 4\\n\", \"2 1 4\\n1 5 3\\n3 3 10\\n7 10 2\\n6 4 8\\n\", \"1 5000 1\\n1 1000000 1000000\\n\", \"999999 1000000 1\\n1 1000000 1000000\\n\", \"447 74474 4\\n47 777474 747\\n74 744744 74477\\n477 477447 777\\n7 477777 444444\\n\", \"1 1 4\\n1 1000000 1000000\\n1 1 1000000\\n1...
Karafs is some kind of vegetable in shape of an 1 × h rectangle. Tavaspolis people love Karafs and they use Karafs in almost any kind of food. Tavas, himself, is crazy about Karafs. <image> Each Karafs has a positive integer height. Tavas has an infinite 1-based sequence of Karafses. The height of the i-th Karafs is ...
0
{"tests": "{\"inputs\": [\"3 2\\n1 3\\n2 1\\n\", \"5 5\\n3 3\\n3 3\\n\", \"4 2\\n2 3\\n1 2\\n\", \"62 70\\n48 12\\n75 51\\n\", \"90 75\\n38 2\\n100 61\\n\", \"965 1000\\n606 895\\n533 394\\n\", \"958 1000\\n326 461\\n836 674\\n\", \"903 694\\n104 488\\n567 898\\n\", \"28 65\\n66 27\\n5 72\\n\", \"10 10\\n9 10\\n6 1\\n\...
Gerald bought two very rare paintings at the Sotheby's auction and he now wants to hang them on the wall. For that he bought a special board to attach it to the wall and place the paintings on the board. The board has shape of an a1 × b1 rectangle, the paintings have shape of a a2 × b2 and a3 × b3 rectangles. Since th...
0
{"tests": "{\"inputs\": [\"2\\n16 4\\n...AAAAA........\\ns.BBB......CCCCC\\n........DDDDD...\\n16 4\\n...AAAAA........\\ns.BBB....CCCCC..\\n.......DDDDD....\\n\", \"2\\n10 4\\ns.ZZ......\\n.....AAABB\\n.YYYYYY...\\n10 4\\ns.ZZ......\\n....AAAABB\\n.YYYYYY...\\n\", \"1\\n100 26\\ns................PPPP.CCCCC..UUUUUU........
The mobile application store has a new game called "Subway Roller". The protagonist of the game Philip is located in one end of the tunnel and wants to get out of the other one. The tunnel is a rectangular field consisting of three rows and n columns. At the beginning of the game the hero is in some cell of the leftmo...
0
{"tests": "{\"inputs\": [\"3\\nNN\\nSS\\n\", \"7\\nNNESWW\\nSWSWSW\\n\", \"200\\nNESENEESEESWWWNWWSWSWNWNNWNNESWSWNNWNWNENESENNESSWSESWWSSSEEEESSENNNESSWWSSSSESWSWWNNEESSWWNNWSWSSWWNWNNEENNENWWNESSSENWNESWNESWNESEESSWNESSSSSESESSWNNENENESSWWNNWWSWWNESEENWWWWNWWNWWNENESESSWWSWWSES\\nNWNESESSENNNESWNWWSWWWNWSESSSWWNWWNNW...
In the spirit of the holidays, Saitama has given Genos two grid paths of length n (a weird gift even by Saitama's standards). A grid path is an ordered sequence of neighbouring squares in an infinite grid. Two squares are neighbouring if they share a side. One example of a grid path is (0, 0) → (0, 1) → (0, 2) → (1, 2...
0
{"tests": "{\"inputs\": [\"APRIL.1st\\n\", \"Codeforces\\n\", \"K3n5JwuWoJdFUVq8H5QldFqDD2B9yCUDFY1TTMN10\\n\", \"F646Pj3RlX5iZ9ei8oCh.IDjGCcvPQofAPCpNRwkBa6uido8w\\n\", \"uVVcZsrSe\\n\", \"rXoypUjrOofxvzuSUrNfhxn490ZBwQZ0mMHYFlY4DCNQW\\n\", \"F7\\n\", \"B9O9WWF\\n\", \"oZndfd2PbCT85u6081\\n\", \"A\\n\", \"D5LkqCdKJsy\...
<image> You can preview the image in better quality by the link: [http://assets.codeforces.com/files/656/without-text.png](//assets.codeforces.com/files/656/without-text.png) Input The only line of the input is a string (between 1 and 50 characters long, inclusive). Each character will be an alphanumeric character o...
0
{"tests": "{\"inputs\": [\"3\\ncbabc\\n\", \"3\\nbcabcbaccba\\n\", \"2\\nabcab\\n\", \"5\\nwjjdqawypvtgrncmqvcsergermprauyevcegjtcrrblkwiugrcjfpjyxngyryxntauxlouvwgjzpsuxyxvhavgezwtuzknetdibv\\n\", \"50\\ntyhjolxuexoffdkdwimsjujorgeksyiyvvqecvhpjsuayqnibijtipuqhkulxpysotlmtrsgygpkdhkrtntwqzrpfckiscaphyhv\\n\", \"10\\nb...
You are given a string s, consisting of lowercase English letters, and the integer m. One should choose some symbols from the given string so that any contiguous subsegment of length m has at least one selected symbol. Note that here we choose positions of symbols, not the symbols themselves. Then one uses the chosen...
0
{"tests": "{\"inputs\": [\"7 4\\n4\\n1 6 2\\n6 2 2\\n2 4 2\\n2 7 1\\n\", \"4 3\\n4\\n2 1 2\\n1 3 2\\n3 4 2\\n4 1 1\\n\", \"5 5\\n10\\n2 4 420\\n4 5 974\\n5 1 910\\n1 3 726\\n1 2 471\\n5 2 94\\n3 2 307\\n2 5 982\\n5 4 848\\n3 5 404\\n\", \"5 4\\n4\\n5 4 614\\n4 1 177\\n1 3 66\\n5 2 43\\n\", \"3 2\\n10\\n2 3 290\\n3 1 85...
Bankopolis is an incredible city in which all the n crossroads are located on a straight line and numbered from 1 to n along it. On each crossroad there is a bank office. The crossroads are connected with m oriented bicycle lanes (the i-th lane goes from crossroad ui to crossroad vi), the difficulty of each of the lan...
0.125
{"tests": "{\"inputs\": [\"4 2\\n11 0 0 14\\n5 4\\n\", \"6 1\\n2 3 0 8 9 10\\n5\\n\", \"7 7\\n0 0 0 0 0 0 0\\n1 2 3 4 5 6 7\\n\", \"4 1\\n8 94 0 4\\n89\\n\", \"6 2\\n1 2 3 0 5 0\\n6 4\\n\", \"4 2\\n1 0 4 0\\n5 2\\n\", \"100 1\\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...
A few years ago, Hitagi encountered a giant crab, who stole the whole of her body weight. Ever since, she tried to avoid contact with others, for fear that this secret might be noticed. To get rid of the oddity and recover her weight, a special integer sequence is needed. Hitagi's sequence has been broken for a long t...
0
{"tests": "{\"inputs\": [\"3\\n\", \"2\\n\", \"4\\n\", \"31\\n\", \"68\\n\", \"75\\n\", \"18\\n\", \"22\\n\", \"73\\n\", \"15\\n\", \"21\\n\", \"25\\n\", \"70\\n\", \"28\\n\", \"93\\n\", \"48\\n\", \"92\\n\", \"83\\n\", \"39\\n\", \"59\\n\", \"80\\n\", \"60\\n\", \"91\\n\", \"81\\n\", \"64\\n\", \"20\\n\", \"88\\n\", \...
You are given an integer N. Consider all possible segments on the coordinate axis with endpoints at integer points with coordinates between 0 and N, inclusive; there will be <image> of them. You want to draw these segments in several layers so that in each layer the segments don't overlap (they might touch at the endp...
0.25
{"tests": "{\"inputs\": [\"6 9\\n5 7 1 4 4 1\\n\\nSAMPLE\", \"17 13\\n27 32 24 30 94 1 89 22 18 84 68 34 21 47 96 27 7\", \"13 79\\n36 75 63 68 48 39 30 26 29 2 92 11 61\", \"20 1000\\n10 20 30 40 50 60 70 80 90 100 200 300 400 500 600 700 110 120 130 400\", \"6 11\\n8 75 71 70 8 100\", \"10 82\\n78 64 85 30 93 18 23 2...
Little Bob comes to you for candies as you are his favorite coder! He wants X candies. You have N bags and the i^th bag contains A[i] candies. You can give him a set of one or more bags such that the sum of candies in those bags is EXACTLY equal to X. Bob wants to find smallest such set of bags. If there are multiple ...
0.625
{"tests": "{\"inputs\": [\"8\\n90\\n90\\n270\\n90\\n90\\n90\\n270\\n90\", \"3\\n90\\n90\\n90\", \"3\\n90\\n9\\n90\", \"3\\n90\\n9\\n160\", \"3\\n90\\n3\\n160\", \"3\\n42\\n3\\n160\", \"3\\n42\\n5\\n160\", \"3\\n28\\n5\\n160\", \"3\\n28\\n4\\n160\", \"3\\n12\\n4\\n160\", \"3\\n12\\n0\\n160\", \"3\\n12\\n1\\n160\", \"3\\...
Construct an N-gon that satisfies the following conditions: * The polygon is simple (see notes for the definition). * Each edge of the polygon is parallel to one of the coordinate axes. * Each coordinate is an integer between 0 and 10^9, inclusive. * The vertices are numbered 1 through N in counter-clockwise order. * ...
0.875
{"tests": "{\"inputs\": [\"2\\n1 1\\n3 3\\n4\\n1.0 0.5\\n1.0 2.5\\n3.0 1.5\\n3.0 3.5\\n1\\n2.0 2.0\\n0\", \"2\\n1 1\\n3 3\\n4\\n1.0 0.5\\n1.0 2.5\\n3.0 1.5\\n3.0 3.589169796022375\\n1\\n2.0 2.0\\n0\", \"2\\n1 1\\n3 3\\n4\\n1.1278569475953018 0.5\\n1.0 2.5\\n3.0 1.5\\n3.0 3.5\\n1\\n2.0 2.0\\n0\", \"2\\n1 1\\n5 3\\n4\\n1...
Brave Ponta has finally arrived at the final dungeon. This is a dark wilderness in front of the fort of the evil emperor Boromos, with fairly strong monsters guarding their territories. <image> Figure 1: Wilderness As shown in Fig. 1, the wilderness is represented by a 4 × 4 square region with the southwest as the ...
0
{"tests": "{\"inputs\": [\"4 5\\nBYYGG\\nRRRRR\\nRRBRR\\nYYGGB\\n2\\n3 1\\n3 1\", \"3 3\\nRGR\\nRBP\\nYEB\\n1\\n1 1\", \"4 4\\nBEEP\\nERYY\\nBBRP\\nRBYP\\n1\\n1 2\", \"4 4\\nBEEP\\nYYRE\\nBBRP\\nRBYP\\n1\\n1 2\", \"3 3\\nRGR\\nRBP\\nYEB\\n1\\n1 2\", \"3 3\\nGRR\\nRBP\\nYEB\\n1\\n1 1\", \"4 4\\nBEEP\\nERYY\\nBBRP\\nRBYP...
Backgorund The super popular game "Puzzle & Hexagons" has finally been released. This game is so funny that many people are addicted to it. There were a number of people who were certified as addicted by doctors because of their excessive enthusiasm. Volunteers from around the world have created a "Puzzle & Hexagons" ...
0
{"tests": "{\"inputs\": [\"4 6\\n0 1 1\\n0 2 -5\\n1 2 2\\n1 3 4\\n2 3 1\\n3 2 7\", \"4 6\\n0 1 1\\n0 2 5\\n1 2 2\\n1 3 4\\n2 3 1\\n3 2 -7\", \"4 6\\n0 1 1\\n0 2 5\\n1 2 2\\n1 3 4\\n2 3 1\\n3 2 7\", \"4 6\\n0 1 1\\n0 2 5\\n1 2 2\\n1 3 8\\n2 3 1\\n3 2 -7\", \"4 6\\n0 1 1\\n0 3 -5\\n1 2 2\\n1 3 4\\n2 3 1\\n3 2 7\", \"4 6\...
Constraints * 1 ≤ |V| ≤ 100 * 0 ≤ |E| ≤ 9900 * -2 × 107 ≤ di ≤ 2 × 107 * There are no parallel edges * There are no self-loops Input An edge-weighted graph G (V, E). |V| |E| s0 t0 d0 s1 t1 d1 : s|E|-1 t|E|-1 d|E|-1 |V| is the number of vertices and |E| is the number of edges in G. The graph vertices are named wi...
0.25
{"tests": "{\"inputs\": [\"2\\n9 77 69\\n98 99 69\", \"2\\n9 77 69\\n98 73 69\", \"2\\n9 72 69\\n98 3 69\", \"2\\n11 72 69\\n98 3 69\", \"2\\n11 72 69\\n98 2 69\", \"2\\n11 72 69\\n78 2 91\", \"2\\n11 72 69\\n78 2 28\", \"2\\n9 77 69\\n98 99 104\", \"2\\n9 77 69\\n98 116 69\", \"2\\n9 72 53\\n98 73 69\", \"2\\n3 72 69\...
You are standing near a very strange machine. If you put C cents in the machine, the remaining money in your purse will transform in an unusual way. If you have A dollars and B cents remaining in your purse after depositing the C cents, then after the transformation you will have B dollars and A cents. You can repeat t...
0
{"tests": "{\"inputs\": [\"5 3\\n1\\n2 motarack\\n2 mike\\n1\\n2 light\\n\", \"4 3\\n1\\n2 alice\\n2 bob\\n2 tanyaromanova\\n\", \"21 6\\n1\\n2 d\\n2 c\\n1\\n2 d\\n2 e\\n1\\n2 a\\n2 b\\n1\\n2 a\\n2 f\\n1\\n2 b\\n2 c\\n1\\n2 b\\n2 f\\n1\\n2 f\\n2 e\\n\", \"18 6\\n1\\n2 a\\n2 b\\n1\\n2 d\\n2 c\\n1\\n2 d\\n2 e\\n1\\n2 e\\...
Hiasat registered a new account in NeckoForces and when his friends found out about that, each one of them asked to use his name as Hiasat's handle. Luckily for Hiasat, he can change his handle in some points in time. Also he knows the exact moments friends will visit his profile page. Formally, you are given a sequen...
0.125
{"tests": "{\"inputs\": [\"6\\n1 0 1 1 0 1\\n1 2 2 2 2\\n\", \"9\\n1 1 0 0 1 0 1 0 1\\n1 1 2 2 3 3 4 4\\n\", \"5\\n1 0 1 0 1\\n1 1 1 1\\n\", \"8\\n1 0 0 1 0 1 1 0\\n1 1 2 2 3 3 3\\n\", \"2\\n1 0\\n1\\n\", \"100\\n0 1 0 0 1 0 1 0 0 0 0 0 1 0 0 1 1 1 1 0 0 1 0 1 1 0 1 0 0 0 0 1 0 1 1 1 1 0 0 1 0 1 0 0 1 0 0 1 0 0 0 0 0 0...
Now Serval is a junior high school student in Japari Middle School, and he is still thrilled on math as before. As a talented boy in mathematics, he likes to play with numbers. This time, he wants to play with numbers on a rooted tree. A tree is a connected graph without cycles. A rooted tree has a special vertex ca...
0
{"tests": "{\"inputs\": [\"9\\n5 5\\n..*..\\n..*..\\n*****\\n..*..\\n..*..\\n3 4\\n****\\n.*..\\n.*..\\n4 3\\n***\\n*..\\n*..\\n*..\\n5 5\\n*****\\n*.*.*\\n*****\\n..*.*\\n..***\\n1 4\\n****\\n5 5\\n.....\\n..*..\\n.***.\\n..*..\\n.....\\n5 3\\n...\\n.*.\\n.*.\\n***\\n.*.\\n3 3\\n.*.\\n*.*\\n.*.\\n4 4\\n*.**\\n....\\n*...
You are given a picture consisting of n rows and m columns. Rows are numbered from 1 to n from the top to the bottom, columns are numbered from 1 to m from the left to the right. Each cell is painted either black or white. You think that this picture is not interesting enough. You consider a picture to be interesting...
0.375
{"tests": "{\"inputs\": [\"3\\n9\\niredppipe\\npiedpiper\\n4\\nestt\\ntest\\n4\\ntste\\ntest\\n\", \"4\\n1\\na\\nz\\n5\\nadhas\\ndasha\\n5\\naashd\\ndasha\\n5\\naahsd\\ndasha\\n\", \"5\\n2\\nab\\naa\\n2\\naa\\naa\\n2\\nab\\nba\\n2\\nbb\\nba\\n3\\naab\\nabb\\n\", \"6\\n7\\ncontest\\nntecost\\n7\\ncontest\\nnstteco\\n7\\...
The problem was inspired by Pied Piper story. After a challenge from Hooli's compression competitor Nucleus, Richard pulled an all-nighter to invent a new approach to compression: middle-out. You are given two strings s and t of the same length n. Their characters are numbered from 1 to n from left to right (i.e. from...
0
{"tests": "{\"inputs\": [\"10\\nonetwonetwooneooonetwooo\\ntwo\\none\\ntwooooo\\nttttwo\\nttwwoo\\nooone\\nonnne\\noneeeee\\noneeeeeeetwooooo\\n\", \"4\\nonetwone\\ntestme\\noneoneone\\ntwotwo\\n\", \"10\\nonetwonetwooneooonetwooo\\ntwo\\none\\ntwooooo\\nttttwo\\nttwwoo\\nooone\\nonnne\\noneeeee\\noneeeeeeetwooooo\\n\"...
You are given a non-empty string s=s_1s_2... s_n, which consists only of lowercase Latin letters. Polycarp does not like a string if it contains at least one string "one" or at least one string "two" (or both at the same time) as a substring. In other words, Polycarp does not like the string s if there is an integer j ...
0
{"tests": "{\"inputs\": [\"6\\n1 3\\n2 3\\n3 4\\n4 5\\n4 6\\n\", \"4\\n1 2\\n2 3\\n3 4\\n\", \"28\\n2 24\\n2 4\\n2 3\\n1 2\\n1 17\\n1 21\\n1 22\\n10 22\\n22 23\\n22 26\\n25 26\\n16 25\\n7 26\\n5 7\\n5 8\\n5 15\\n5 14\\n5 12\\n5 20\\n11 25\\n9 25\\n6 9\\n9 19\\n9 28\\n13 28\\n18 28\\n27 28\\n\", \"3\\n1 3\\n2 3\\n\", \"...
You have a tree of n vertices. You are going to convert this tree into n rubber bands on infinitely large plane. Conversion rule follows: * For every pair of vertices a and b, rubber bands a and b should intersect if and only if there is an edge exists between a and b in the tree. * Shape of rubber bands must be ...
0
{"tests": "{\"inputs\": [\"5 2\\n5 2 3\\n3 1 4 5 2\\n3 5\\n\", \"4 4\\n2 1 11\\n1 3 2 4\\n1 3 2 4\\n\", \"4 4\\n5 1 4\\n4 3 1 2\\n2 4 3 1\\n\", \"4 4\\n10 1 5\\n1 2 3 4\\n1 3 2 4\\n\", \"1 1\\n2 1 2\\n1\\n1\\n\", \"5 2\\n5 2 3\\n3 1 4 2 5\\n3 2\\n\", \"23 5\\n10 3 4\\n2 1 4 11 8 10 5 6 7 9 12 3 14 13 16 18 21 15 17 19 ...
There are n warriors in a row. The power of the i-th warrior is a_i. All powers are pairwise distinct. You have two types of spells which you may cast: 1. Fireball: you spend x mana and destroy exactly k consecutive warriors; 2. Berserk: you spend y mana, choose two consecutive warriors, and the warrior with gr...
0
{"tests": "{\"inputs\": [\"3 5\\n4 3 4\\n\", \"1 2\\n3\\n\", \"2 10\\n5 7\\n\", \"3 3\\n4 3 3\\n\", \"1 2\\n200000\\n\", \"1 3\\n3\\n\", \"1 199999\\n200000\\n\", \"100 5000\\n101 168 189 84 24 14 195 139 200 76 73 177 95 9 39 117 32 82 166 37 68 70 123 110 119 129 37 35 200 44 149 46 164 6 71 81 159 160 103 184 139 75...
// We decided to drop the legend about the power sockets but feel free to come up with your own :^) Define a chain: * a chain of length 1 is a single vertex; * a chain of length x is a chain of length x-1 with a new vertex connected to the end of it with a single edge. You are given n chains of lengths l_1,...
0
{"tests": "{\"inputs\": [\"5\\n1 2 5 4 3\\n\", \"7\\n1 2 4 6 5 3 7\\n\", \"7\\n2 5 7 3 1 4 6\\n\", \"9\\n1 2 3 5 4 8 9 7 6\\n\", \"5\\n5 3 4 2 1\\n\", \"11\\n9 10 11 6 3 5 4 7 8 2 1\\n\", \"7\\n7 3 5 6 4 2 1\\n\", \"9\\n3 4 5 6 7 8 9 2 1\\n\", \"2\\n1 2\\n\", \"9\\n9 8 2 5 7 3 1 4 6\\n\", \"7\\n1 2 7 6 5 4 3\\n\", \"9\...
On a weekend, Qingshan suggests that she and her friend Daniel go hiking. Unfortunately, they are busy high school students, so they can only go hiking on scratch paper. A permutation p is written from left to right on the paper. First Qingshan chooses an integer index x (1≤ x≤ n) and tells it to Daniel. After that, D...
0
{"tests": "{\"inputs\": [\"2 0\\n0 0\\n\", \"3 2\\n1 2\\n2 3\\n1 1 1\\n\", \"5 7\\n1 2\\n1 3\\n1 4\\n1 5\\n3 4\\n3 5\\n4 5\\n0 1 0 1 0\\n\", \"2 0\\n1 0\\n\", \"3 1\\n2 3\\n0 1 1\\n\", \"4 2\\n1 3\\n2 4\\n0 1 0 1\\n\", \"10 10\\n2 1\\n3 1\\n4 1\\n3 5\\n6 2\\n5 7\\n1 8\\n5 9\\n10 5\\n7 2\\n1 0 0 0 1 1 1 0 0 1\\n\", \"10...
Twilight Sparkle learnt that the evil Nightmare Moon would return during the upcoming Summer Sun Celebration after one thousand years of imprisonment on the moon. She tried to warn her mentor Princess Celestia, but the princess ignored her and sent her to Ponyville to check on the preparations for the celebration. <im...
0
{"tests": "{\"inputs\": [\"2 4\\nABDC\\nABDC\\n\", \"2 6\\nABCCBA\\nABCCBA\\n\", \"12 18\\nCBBCAACABACCACABBC\\nABCAACABAABCBCBCCC\\nBCAACCCBBBABBACBBA\\nACCBCBBBAABACCACCC\\nCAABCCCACACCBACACC\\nBBBCBCACCABCCBCBBB\\nBAABBCACAAAAACCBCB\\nBAABAABACBCABACBCA\\nAABCBCCBCCABACCCAC\\nCCBBBAACCCBCACCCBB\\nCBABACBBBABCBACCCB\...
The Hedgehog recently remembered one of his favorite childhood activities, — solving puzzles, and got into it with new vigor. He would sit day in, day out with his friend buried into thousands of tiny pieces of the picture, looking for the required items one by one. Soon the Hedgehog came up with a brilliant idea: ins...
0.125
{"tests": "{\"inputs\": [\"10 20 30\\n\", \"1 1 5\\n\", \"318476 318476 318476\\n\", \"1 100000000 1\\n\", \"12 34 56\\n\", \"9889 1221 2442\\n\", \"100500 200600 300700\\n\", \"12059 259855 5874875\\n\", \"2 5 2\\n\", \"46981 105809 585858\\n\", \"23985 3353 75633\\n\", \"777 777 777\\n\", \"100000000 100000000 100000...
Today Patrick waits for a visit from his friend Spongebob. To prepare for the visit, Patrick needs to buy some goodies in two stores located near his house. There is a d1 meter long road between his house and the first shop and a d2 meter long road between his house and the second shop. Also, there is a road of length ...
0
{"tests": "{\"inputs\": [\"2\\n4 3 1\\n4 2 2\\n\", \"1\\n4 2 2\\n\", \"1\\n1000 999 1\\n\", \"1\\n7 2 1\\n\", \"1\\n1000 1 1\\n\", \"1\\n2 1 1\\n\", \"1\\n1000 1 1000\\n\", \"1\\n8 7 2\\n\", \"1\\n1000 998 1000\\n\", \"1\\n1000 500 123\\n\", \"1\\n1000 1 2\\n\", \"1\\n1000 999 2\\n\", \"1\\n7 2 2\\n\", \"1\\n1100 999 1...
Have you ever tasted Martian food? Well, you should. Their signature dish is served on a completely black plate with the radius of R, flat as a pancake. First, they put a perfectly circular portion of the Golden Honduras on the plate. It has the radius of r and is located as close to the edge of the plate as possible...
0
{"tests": "{\"inputs\": [\"4\\nEdu-ca-tion-al Ro-unds are so fun\\n\", \"4\\ngarage for sa-le\\n\", \"4\\nasd asd asd asdf\\n\", \"1\\nrHPBSGKzxoSLerxkDVxJG PfUqVrdSdOgJBySsRHYryfLKOvIcU\\n\", \"1\\nqUOYCytbKgoGRgaqhjrohVRxKTKjjOUPPnEjiXJWlvpCyqiRzbnpyNqDylWverSTrcgZpEoDKhJCrOOvsuXHzkPtbXeKCKMwUTVk\\n\", \"2\\nZeqxDLfP...
The main city magazine offers its readers an opportunity to publish their ads. The format of the ad should be like this: There are space-separated non-empty words of lowercase and uppercase Latin letters. There are hyphen characters '-' in some words, their positions set word wrapping points. Word can include more th...
0
{"tests": "{\"inputs\": [\"4\\n89\\n88\\n1000\\n28923845\\n\", \"1\\n1010\\n\", \"6\\n12\\n10000000000000000000000000000000000000000000\\n3030\\n3112\\n99771122997711229977112299778700000006\\n99771122997711229977112299778699999996\\n\", \"1\\n100001\\n\", \"4\\n12\\n1000\\n1001\\n1002\\n\", \"3\\n100001\\n100000\\n100...
Yes, that's another problem with definition of "beautiful" numbers. Let's call a positive integer x beautiful if its decimal representation without leading zeroes contains even number of digits, and there exists a permutation of this representation which is palindromic. For example, 4242 is a beautiful number, since i...
0
{"tests": "{\"inputs\": [\"4 4 3\\n0 1 0\\n1 2 1\\n2 3 0\", \"10 9 9\\n7 6 0\\n4 5 1\\n9 7 0\\n2 9 0\\n2 3 0\\n4 1 0\\n8 0 0\\n9 1 0\\n3 0 0\", \"5 5 3\\n0 1 0\\n1 2 1\\n2 3 0\", \"4 4 3\\n0 1 0\\n1 2 1\\n1 3 0\", \"5 5 3\\n0 1 0\\n1 4 1\\n2 3 0\", \"10 9 9\\n7 6 0\\n4 5 1\\n9 7 0\\n2 9 0\\n2 3 0\\n4 1 0\\n10 0 0\\n9 1...
Snuke's mother gave Snuke an undirected graph consisting of N vertices numbered 0 to N-1 and M edges. This graph was connected and contained no parallel edges or self-loops. One day, Snuke broke this graph. Fortunately, he remembered Q clues about the graph. The i-th clue (0 \leq i \leq Q-1) is represented as integers...
0
{"tests": "{\"inputs\": [\"6\\nA 1 0 0 2 0\\nB 0 0 1 1 0\\nC 1 1 1 1 1\\nD 1 0 0 1 2\\nE 2 0 0 0 0\\nF 1 1 0 2 1\\n4\\ng 1 1 1\\nh 0 1 2\\nw 0 0 0\\nb 0 2 1\\n0\", \"6\\nA 1 0 0 2 0\\nB 0 0 1 1 0\\nC 1 1 1 1 1\\nD 1 0 0 1 2\\nE 2 0 0 0 0\\nF 1 1 0 2 1\\n4\\ng 1 1 1\\nh 0 1 2\\nx 0 0 0\\nb 0 2 1\\n0\", \"6\\nA 1 0 0 2 -...
Japan achieved the second straight victory in the national baseball competition WBC !! A baseball tournament was held at Aizu Gakuen High School as baseball became more popular. In this tournament, a round-robin league match will be held and the ranking will be decided in the following ways. 1. The team with the most ...
0
{"tests": "{\"inputs\": [\"5 2\\n3 1\\n3 1\\n10 3\\n1 10\\n10 1\\n8 3\\n0 0\", \"5 2\\n3 1\\n3 1\\n10 3\\n1 10\\n10 1\\n8 0\\n0 0\", \"5 0\\n3 1\\n3 1\\n10 3\\n1 10\\n10 1\\n8 0\\n0 0\", \"5 0\\n3 1\\n3 1\\n10 2\\n1 10\\n10 1\\n11 0\\n0 0\", \"5 2\\n3 1\\n3 1\\n10 3\\n1 11\\n10 1\\n8 3\\n0 0\", \"6 2\\n3 1\\n3 1\\n10 3...
There are a number of ways to shuffle a deck of cards. Hanafuda shuffling for Japanese card game 'Hanafuda' is one such example. The following is how to perform Hanafuda shuffling. There is a deck of n cards. Starting from the p-th card from the top of the deck, c cards are pulled out and put on the top of the deck, a...
0.875
{"tests": "{\"inputs\": [\"3\\n0\\n0\\n1000000000\", \"4\\n7\\n5\\n10\\n6\", \"3\\n0\\n0\\n1000000010\", \"4\\n11\\n5\\n10\\n6\", \"4\\n6\\n5\\n10\\n6\", \"4\\n6\\n5\\n20\\n6\", \"4\\n2\\n5\\n20\\n6\", \"4\\n2\\n5\\n10\\n6\", \"4\\n2\\n5\\n10\\n5\", \"4\\n0\\n5\\n10\\n5\", \"4\\n0\\n7\\n10\\n5\", \"4\\n0\\n7\\n10\\n1\"...
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 perform a very large number of calculations to improve the calculation power and raise awareness. Exponentiation is an operation that easily produces large numbers....
0
{"tests": "{\"inputs\": [\"5 5\\n.....\\n.#.#.\\n.###.\\n.#.#.\\n.....\", \"3 5\\n.....\\n.#.#.\\n.###.\\n.#.#.\\n.....\", \"3 1\\n.....\\n.#.#.\\n.###.\\n.#.#.\\n.....\", \"2 5\\n.....\\n.#.#.\\n.###.\\n.#.#.\\n.....\", \"4 2\\n.....\\n.#.#/\\n.###.\\n.#.#.\\n.....\", \"0 1\\n.....\\n.#.#.\\n.###.\\n.#.#.\\n.....\", \...
problem Given the squares of $ R * C $. Each square is either an empty square or a square with a hole. The given square meets the following conditions. * The cells with holes are connected. (You can move a square with a hole in the cross direction to any square with a hole) * Empty cells are connected. You can gen...
0.625
{"tests": "{\"inputs\": [\"3 9\\n0 0 1\\n0 0 2\\n0 0 3\\n0 2 4\\n0 2 5\\n1 0\\n1 2\\n2 0\\n1 0\", \"3 9\\n0 0 0\\n0 0 2\\n0 0 3\\n0 2 4\\n0 2 5\\n1 0\\n1 2\\n2 0\\n1 0\", \"3 9\\n0 0 0\\n0 0 2\\n0 0 3\\n0 2 4\\n0 0 5\\n1 0\\n1 2\\n2 0\\n1 0\", \"3 9\\n0 0 0\\n0 0 2\\n0 0 3\\n0 2 4\\n0 2 5\\n1 1\\n1 2\\n2 0\\n1 0\", \"6...
Stack is a container of elements that are inserted and deleted according to LIFO (Last In First Out). For $n$ stack $S_i$ ($i = 0, 1, ..., n-1$), perform a sequence of the following operations. * push($t$, $x$): Insert an integer $x$ to $S_t$. * top($t$): Report the value which should be deleted next from $S_t$. If $...
0
{"tests": "{\"inputs\": [\"5\\n1 2 3 4 5\\n\", \"7\\n24 10 8 26 25 5 16\\n\", \"7\\n18 29 23 23 1 14 5\\n\", \"9\\n23 1 2 26 9 11 23 10 26\\n\", \"7\\n4 13 8 20 31 17 3\\n\", \"6\\n12 12 29 10 30 32\\n\", \"8\\n9 24 29 4 20 14 8 31\\n\", \"7\\n2 6 7 1 3 4 5\\n\", \"5\\n14 27 8 7 28\\n\", \"6\\n32 9 29 17 24 20\\n\", \"...
From "ftying rats" to urban saniwation workers - can synthetic biology tronsform how we think of pigeons? The upiquitous pigeon has long been viewed as vermin - spleading disease, scavenging through trush, and defecating in populous urban spases. Yet they are product of selextive breeding for purposes as diverse as r...
0
{"tests": "{\"inputs\": [\"2\\n3 6\\n\", \"3\\n2 5 -3\\n\", \"3\\n0 1000000000 -1000000000\\n\", \"10\\n9 1 2 3 5 7 4 10 6 8\\n\", \"20\\n55 -14 -28 13 -67 -23 58 2 -87 92 -80 62 -44 86 18 97 -47 63 32 94\\n\", \"50\\n-482 -431 -457 -473 -428 -427 -406 -422 -426 -472 -407 -441 -408 -475 -463 -443 -447 -450 -412 -436 -4...
The legend of the foundation of Vectorland talks of two integers x and y. Centuries ago, the array king placed two markers at points |x| and |y| on the number line and conquered all the land in between (including the endpoints), which he declared to be Arrayland. Many years later, the vector king placed markers at poin...
0.25
{"tests": "{\"inputs\": [\"6\\n1 1 1 4 4 4\\n\", \"4\\n3 2 4 1\\n\", \"10\\n8 9 4 9 6 10 8 2 7 1\\n\", \"125\\n8 85 125 177 140 158 2 152 67 102 9 61 29 188 102 193 112 194 15 7 133 134 145 7 89 193 130 149 134 51 13 194 191 149 73 106 151 85 42 53 163 134 127 7 51 61 178 105 117 197 35 21 122 164 133 165 135 12 192 60...
There are n boxers, the weight of the i-th boxer is a_i. Each of them can change the weight by no more than 1 before the competition (the weight cannot become equal to zero, that is, it must remain positive). Weight is always an integer number. It is necessary to choose the largest boxing team in terms of the number o...
0.375
{"tests": "{\"inputs\": [\"0 0 0 0 0 0 0 0 0 0\\n0 0 0 0 0 0 0 0 0 0\\n0 0 0 0 0 0 0 0 0 0\\n0 0 0 0 0 0 0 0 0 0\\n0 0 0 0 0 0 0 0 0 0\\n0 0 0 0 0 0 0 0 0 0\\n0 6 6 6 6 6 6 0 0 0\\n1 0 0 0 0 0 0 0 0 0\\n0 0 0 0 0 0 0 0 0 0\\n0 0 0 0 0 0 0 0 0 0\\n\", \"0 0 0 0 0 0 0 0 0 0\\n0 0 0 0 0 0 0 0 0 0\\n0 0 0 0 0 0 0 0 0 0\\n0...
Hyakugoku has just retired from being the resident deity of the South Black Snail Temple in order to pursue her dream of becoming a cartoonist. She spent six months in that temple just playing "Cat's Cradle" so now she wants to try a different game — "Snakes and Ladders". Unfortunately, she already killed all the snake...
0
{"tests": "{\"inputs\": [\"5\\n\", \"1\\n\", \"999998\\n\", \"4\\n\", \"123455\\n\", \"10000\\n\", \"998756\\n\", \"1000000\\n\", \"999879\\n\", \"345612\\n\", \"6\\n\", \"999997\\n\", \"990001\\n\", \"8\\n\", \"623423\\n\", \"2\\n\", \"345634\\n\", \"777777\\n\", \"9009\\n\", \"100000\\n\", \"2009\\n\", \"976438\\n\",...
Let's assume that we have a pair of numbers (a, b). We can get a new pair (a + b, b) or (a, a + b) from the given pair in a single step. Let the initial pair of numbers be (1,1). Your task is to find number k, that is, the least number of steps needed to transform (1,1) into the pair where at least one number equals n...
0
{"tests": "{\"inputs\": [\"1 4 100 10 30 5\\n6\\n101 104 105 110 130 200\\n\", \"1 1 2 2 3 3\\n7\\n13 4 11 12 11 13 12\\n\", \"5 4 7 6 4 1\\n10\\n19 16 18 12 16 15 16 20 16 14\\n\", \"158260522 877914575 602436426 24979445 861648772 623690081\\n1\\n896194147\\n\", \"58260522 77914575 2436426 24979445 61648772 23690081\...
After battling Shikamaru, Tayuya decided that her flute is too predictable, and replaced it with a guitar. The guitar has 6 strings and an infinite number of frets numbered from 1. Fretting the fret number j on the i-th string produces the note a_{i} + j. Tayuya wants to play a melody of n notes. Each note can be play...
0.625
{"tests": "{\"inputs\": [\"3\\n3\\n777\\n111\\n3\\n314\\n159\\n5\\n09281\\n09281\\n\", \"3\\n3\\n777\\n111\\n3\\n314\\n159\\n5\\n14195\\n09281\\n\", \"3\\n3\\n777\\n111\\n3\\n314\\n159\\n5\\n14195\\n18546\\n\", \"3\\n3\\n777\\n111\\n3\\n196\\n159\\n5\\n14195\\n11156\\n\", \"3\\n3\\n777\\n111\\n3\\n314\\n159\\n5\\n14195...
There are n cards numbered 1, …, n. The card i has a red digit r_i and a blue digit b_i written on it. We arrange all n cards in random order from left to right, with all permutations of 1, …, n having the same probability. We then read all red digits on the cards from left to right, and obtain an integer R. In the sa...
0.25
{"tests": "{\"inputs\": [\"5\\n3\\nTMT\\n3\\nMTT\\n6\\nTMTMTT\\n6\\nTMTTTT\\n6\\nTTMMTT\\n\", \"5\\n3\\nTMT\\n3\\nMTT\\n6\\nTMTMTT\\n6\\nMTTTTT\\n6\\nTTMMTT\\n\", \"5\\n3\\nTMT\\n3\\nMTT\\n6\\nTMTMTT\\n6\\nMTTTTT\\n6\\nTTMTTM\\n\", \"5\\n3\\nTMT\\n3\\nMTT\\n6\\nTTTMMT\\n6\\nTMTTTT\\n6\\nTTMMTT\\n\", \"5\\n3\\nTTM\\n3\\...
The student council has a shared document file. Every day, some members of the student council write the sequence TMT (short for Towa Maji Tenshi) in it. However, one day, the members somehow entered the sequence into the document at the same time, creating a jumbled mess. Therefore, it is Suguru Doujima's task to fig...
0
{"tests": "{\"inputs\": [\"4 1\\n11\\n10\\n01\\n00\\n\", \"2 3\\n01 11 00\\n00 01 11\\n\", \"1 1\\n11\\n\", \"2 3\\n00 10 01\\n01 01 00\\n\", \"9 9\\n10 10 10 01 10 11 11 01 10\\n11 00 10 10 11 10 01 00 00\\n10 00 11 01 00 01 01 11 10\\n10 11 10 00 01 11 11 10 11\\n01 11 11 01 11 00 10 00 01\\n01 00 00 10 01 01 10 00 0...
During the break, we decided to relax and play dominoes. Our box with Domino was empty, so we decided to borrow the teacher's dominoes. The teacher responded instantly at our request. He put nm dominoes on the table as an n × 2m rectangle so that each of the n rows contained m dominoes arranged horizontally. Each half...
0
{"tests": "{\"inputs\": [\"2\\n4 1\\n\", \"4\\n0 1 -1 0\\n\", \"5\\n1 2 3 0 3\\n\", \"5\\n1 1 1 1 1\\n\", \"4\\n0 2 -1 2\\n\", \"9\\n0 0 0 0 0 0 0 0 0\\n\", \"100\\n1 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...
You've got array a[1], a[2], ..., a[n], consisting of n integers. Count the number of ways to split all the elements of the array into three contiguous parts so that the sum of elements in each part is the same. More formally, you need to find the number of such pairs of indices i, j (2 ≤ i ≤ j ≤ n - 1), that <image>...
0.875
{"tests": "{\"inputs\": [\"2 1 0 657276545\\n1 2\\n\", \"4 5 0 10000\\n1 2 3 4\\n\", \"2 1 1 888450282\\n1 2\\n\", \"8 4 9 371687114\\n1 7 22 31 35 38 62 84\\n\", \"2 1000000000 1000000000000 10000\\n1 2\\n\", \"1 1 1 2\\n0\\n\", \"4 0 8 414790855\\n1 88 97 99\\n\", \"1 1 1 2\\n1000000000\\n\", \"1 1 1 2\\n2\\n\", \"1 ...
Once upon a time in the thicket of the mushroom forest lived mushroom gnomes. They were famous among their neighbors for their magic mushrooms. Their magic nature made it possible that between every two neighboring mushrooms every minute grew another mushroom with the weight equal to the sum of weights of two neighbori...
0
{"tests": "{\"inputs\": [\"5 2\\nIvanov 1 763\\nAndreev 2 800\\nPetrov 1 595\\nSidorov 1 790\\nSemenov 2 503\\n\", \"5 2\\nIvanov 1 800\\nAndreev 2 763\\nPetrov 1 800\\nSidorov 1 800\\nSemenov 2 503\\n\", \"2 1\\na 1 10\\nb 1 10\\n\", \"2 1\\nOAELh 1 733\\nbFGs 1 270\\n\", \"2 1\\nA 1 5\\nB 1 5\\n\", \"3 1\\nA 1 5\\nB ...
Very soon Berland will hold a School Team Programming Olympiad. From each of the m Berland regions a team of two people is invited to participate in the olympiad. The qualifying contest to form teams was held and it was attended by n Berland students. There were at least two schoolboys participating from each of the m ...
0.125
{"tests": "{\"inputs\": [\"3 2\\n1 2\\n2 3\\n1 2 1\\n\", \"4 2\\n1 2\\n3 4\\n1 2 3 3\\n\", \"1 0\\n1\\n\", \"4 3\\n4 3\\n3 2\\n2 1\\n3 4 4 4\\n\", \"4 3\\n1 2\\n2 3\\n3 4\\n1 1 1 2\\n\", \"4 3\\n1 2\\n2 3\\n3 4\\n1 1 3 2\\n\", \"2 1\\n2 1\\n1 2\\n\", \"2 1\\n2 1\\n2 2\\n\", \"4 3\\n1 2\\n2 3\\n3 4\\n1 1 1 4\\n\", \"4 3...
Sasha lives in a big happy family. At the Man's Day all the men of the family gather to celebrate it following their own traditions. There are n men in Sasha's family, so let's number them with integers from 1 to n. Each man has at most one father but may have arbitrary number of sons. Man number A is considered to b...
0
{"tests": "{\"inputs\": [\"helloworld\\nehoolwlroz\\n\", \"hastalavistababy\\nhastalavistababy\\n\", \"merrychristmas\\nchristmasmerry\\n\", \"acbacacbbb\\nacbacacbbb\\n\", \"dacbdbbbdd\\nadbdadddaa\\n\", \"ijpanyhovzwjjxsvaiyhchfaulcsdgfszjnwtoqbtaqygfmxuwvynvlhqhvmkjbooklxfhmqlqvfoxlnoclfxtbhvnkmhjcmrsdc\\nijpanyhovz...
Santa Claus decided to disassemble his keyboard to clean it. After he returned all the keys back, he suddenly realized that some pairs of keys took each other's place! That is, Santa suspects that each key is either on its place, or on the place of another key, which is located exactly where the first key should be. ...
0.125
{"tests": "{\"inputs\": [\"10 4\\n4 3\\n5 10\\n8 9\\n1 2\\n\", \"4 4\\n3 1\\n2 3\\n3 4\\n1 2\\n\", \"3 2\\n1 2\\n2 3\\n\", \"4 3\\n1 3\\n3 4\\n1 4\\n\", \"4 5\\n1 2\\n1 3\\n1 4\\n2 3\\n2 4\\n\", \"6 6\\n1 2\\n2 3\\n3 4\\n4 5\\n5 6\\n1 6\\n\", \"4 3\\n1 2\\n1 3\\n1 4\\n\", \"4 4\\n1 2\\n2 3\\n3 4\\n4 1\\n\", \"5 5\\n1 2...
Bear Limak examines a social network. Its main functionality is that two members can become friends (then they can talk with each other and share funny pictures). There are n members, numbered 1 through n. m pairs of members are friends. Of course, a member can't be a friend with themselves. Let A-B denote that membe...
0.875
{"tests": "{\"inputs\": [\"3 2 4\\n91 94\\n92 97\\n97 99\\n92 94\\n93 97\\n95 96\\n90 100\\n\", \"2 1 1\\n1 1\\n200000 200000\\n90 100\\n\", \"1 1 1\\n1 1\\n1 1\\n\", \"1 1 1\\n200000 200000\\n200000 200000\\n\", \"1 1 1\\n186195 200000\\n200000 200000\\n\", \"3 2 4\\n91 94\\n92 97\\n97 186\\n92 94\\n93 97\\n95 96\\n90...
To stay woke and attentive during classes, Karen needs some coffee! <image> Karen, a coffee aficionado, wants to know the optimal temperature for brewing the perfect cup of coffee. Indeed, she has spent some time reading several recipe books, including the universally acclaimed "The Art of the Covfefe". She knows n ...
0.875
{"tests": "{\"inputs\": [\"4\\n\", \"2\\n\", \"7\\n\", \"536870913\\n\", \"1048576\\n\", \"1024\\n\", \"999999999999\\n\", \"123456789\\n\", \"3\\n\", \"10\\n\", \"12000\\n\", \"1000\\n\", \"549755813889\\n\", \"549755813888\\n\", \"100000\\n\", \"536870911\\n\", \"1000000000000\\n\", \"65536\\n\", \"536870912\\n\", \"...
Ehab is interested in the bitwise-xor operation and the special graphs. Mahmoud gave him a problem that combines both. He has a complete graph consisting of n vertices numbered from 0 to n - 1. For all 0 ≤ u < v < n, vertex u and vertex v are connected with an undirected edge that has weight <image> (where <image> is t...
0.125