messages
listlengths
1
1
ground_truth
stringlengths
156
726k
dataset
stringclasses
1 value
[ { "content": "Mr. Matsudaira is always careful about eco-friendliness in his life. Last month's water charge was 4280 yen, which exceeded the usual target of 4000 yen, so we have been trying to save water this month. How much have you saved on your water bill compared to last month?\n\nEnter this month's water ...
[{"input": "29\n104\n0\n-1", "output": "620\n-11360\n3130\n"}, {"input": "29\n112\n0\n-1", "output": "620\n-12640\n3130\n"}, {"input": "29\n130\n1\n-1", "output": "620\n-15520\n3130\n"}, {"input": "29\n97\n0\n-1", "output": "620\n-10240\n3130\n"}, {"input": "29\n96\n1\n-1", "output": "620\n-10080\n3130\n"}, {"input": "...
code_stdio
[ { "content": "You are given n k-digit integers. You have to rearrange the digits in the integers so that the difference between the largest and the smallest number was minimum. Digits should be rearranged by the same rule in all integers.\n\nInput\n\nThe first line contains integers n and k — the number and dig...
[{"input": "8 8\n83239439\n62184887\n58968944\n39808261\n68740623\n38480328\n81965504\n52600488\n", "output": "44481119\n"}, {"input": "8 8\n96805230\n73119021\n06552907\n86283347\n88650846\n19155689\n37032451\n19310120\n", "output": "53604668\n"}, {"input": "8 8\n68785928\n11981277\n32480720\n72495162\n69969623\n42118...
code_stdio
[ { "content": "Let's consider all integers in the range from $1$ to $n$ (inclusive).\n\nAmong all pairs of distinct integers in this range, find the maximum possible greatest common divisor of integers in pair. Formally, find the maximum value of $\\mathrm{gcd}(a, b)$, where $1 \\leq a < b \\leq n$.\n\nThe great...
[{"input": "100\n2\n3\n4\n6\n6\n9\n8\n9\n10\n11\n12\n23\n14\n15\n5\n17\n18\n19\n20\n21\n22\n23\n24\n25\n26\n27\n28\n29\n30\n31\n32\n11\n20\n35\n36\n37\n38\n65\n40\n41\n42\n43\n44\n70\n46\n47\n48\n49\n50\n51\n52\n53\n54\n55\n56\n57\n58\n59\n60\n61\n62\n63\n64\n65\n66\n67\n68\n69\n70\n71\n72\n73\n39\n49\n76\n77\n78\n79\n...
code_stdio
[ { "content": "Bamboo Blossoms\n\nThe bamboos live for decades, and at the end of their lives, they flower to make their seeds. Dr. ACM, a biologist, was fascinated by the bamboos in blossom in his travel to Tsukuba. He liked the flower so much that he was tempted to make a garden where the bamboos bloom annuall...
[{"input": "3 2\n2 6\n10 10\n110 181\n2 371896\n0 0", "output": "5\n17\n21\n379\n5361757\n"}, {"input": "12 1\n3 1\n10 20\n100 50\n3 202868\n0 0", "output": "13\n4\n47\n150\n2792771\n"}, {"input": "2 4\n3 1\n13 35\n100 47\n4 346519\n0 0", "output": "11\n4\n101\n147\n4969351\n"}, {"input": "3 2\n3 4\n10 20\n100 50\n2 50...
code_stdio
[ { "content": "There is a knight - the chess piece - at the origin (0, 0) of a two-dimensional grid.\nWhen the knight is at the square (i, j), it can be moved to either (i+1,j+2) or (i+2, j+1).\nIn how many ways can the knight reach the square (X, Y)?\nFind the number of ways modulo 10^9 + 7.\n\n-----Constraints...
[{"input": "999999 999999\n", "output": "151840682\n"}, {"input": "803622 615354\n", "output": "984439211\n"}, {"input": "691947 979659\n", "output": "966489110\n"}, {"input": "411938 406831\n", "output": "625271651\n"}, {"input": "329039 389257\n", "output": "766659580\n"}, {"input": "544850 859069\n", "output": "7052...
code_stdio
[ { "content": "Alas, finding one's true love is not easy. Masha has been unsuccessful in that yet. Her friend Dasha told Masha about a way to determine the phone number of one's Prince Charming through arithmancy. \n\nThe phone number is divined like that. First one needs to write down one's own phone numbers. F...
[{"input": "17601120900014764776764048700928872725171605903217\n", "output": "10428170619\n"}, {"input": "78767765544454334445445555455676565433343455432332\n", "output": "11031574582\n"}, {"input": "67676566654565654332111011212211111223433222110012\n", "output": "5882859948\n"}, {"input": "107644873278096903327544821...
code_stdio
[ { "content": "I am a craftsman specialized in interior works. A customer asked me to perform wiring work on a wall whose entire rectangular surface is tightly pasted with pieces of panels. The panels are all of the same size (2 m in width, 1 m in height) and the wall is filled with an x (horizontal) by y (verti...
[{"input": "1 -11", "output": "-10\n"}, {"input": "171 2", "output": "173\n"}, {"input": "120 3", "output": "121\n"}, {"input": "109 1", "output": "110\n"}, {"input": "119 1", "output": "120\n"}, {"input": "150 2", "output": "151\n"}, {"input": "148 1", "output": "149\n"}, {"input": "169 2", "output": "171\n"}, {"input...
code_stdio
[ { "content": "A rabbit who came to the fair found that the prize for a game at a store was a carrot cake. The rules for this game are as follows.\n\nThere is a grid-like field of vertical h squares x horizontal w squares, and each block has at most one block. Each block is a color represented by one of the uppe...
[{"input": "4 6 1\n......\n...Y..\n/..Z..\nYRRRYY", "output": "YES\n"}, {"input": "4 6 1\n......\n...Y..\n..Z../\nYRRRYY", "output": "YES\n"}, {"input": "4 6 1\n......\n...Y./\n/..Z..\nYRRRYY", "output": "YES\n"}, {"input": "0 10 3\n......\n/.Y...\n/..Y..\nRRYRYY", "output": "NO\n"}, {"input": "4 6 1\n......\n...Y..\n....
code_stdio
[ { "content": "Mr. Infinity has a string S consisting of digits from 1 to 9. Each time the date changes, this string changes as follows:\n - Each occurrence of 2 in S is replaced with 22. Similarly, each 3 becomes 333, 4 becomes 4444, 5 becomes 55555, 6 becomes 666666, 7 becomes 7777777, 8 becomes 88888888 and 9...
[{"input": "3822434535651488671388118263222567477765652247558781154667867787813244635482224781486555517652377271\n150250350450550650\n", "output": "3\n"}, {"input": "111111111111111111117322118756841484815524346474882856582285635434521523587354424471731255584\n975864753642531420\n", "output": "7\n"}, {"input": "1111111...
code_stdio
[ { "content": "Summer is coming! It's time for Iahub and Iahubina to work out, as they both want to look hot at the beach. The gym where they go is a matrix a with n lines and m columns. Let number a[i][j] represents the calories burned by performing workout at the cell of gym in the i-th line and the j-th colum...
[{"input": "4 5\n87882 40786 3691 85313 46694\n28884 16067 3242 97367 78518\n4250 35501 9780 14435 19004\n64673 65438 56977 64495 27280\n", "output": "747898\n"}, {"input": "4 5\n2274 40786 3691 98933 46694\n28884 16067 3242 97367 73338\n8377 57682 9780 14435 19004\n64673 65438 103768 64495 27280\n", "output": "717521\...
code_stdio
[ { "content": "Formula 1 officials decided to introduce new competition. Cars are replaced by space ships and number of points awarded can differ per race.\n\nGiven the current ranking in the competition and points distribution for the next race, your task is to calculate the best possible ranking for a given as...
[{"input": "4 2\n29 16 13 10\n20 10 10 -1\n", "output": "1\n"}, {"input": "4 3\n50 30 20 10\n15 10 7 10\n", "output": "3\n"}, {"input": "4 4\n29 16 13 10\n20 10 8 -1\n", "output": "1\n"}, {"input": "4 3\n51 30 20 10\n15 10 7 10\n", "output": "3\n"}, {"input": "4 2\n29 16 13 10\n20 10 8 -1\n", "output": "1\n"}, {"input"...
code_stdio
[ { "content": "Oranges on Cans\n\nsquare1001 You put a $ N $ can of aluminum on the table.\n\nE869120 You put $ M $ of oranges on each aluminum can on the table.\n\nHow many oranges are on the aluminum can?\n\ninput\n\nInput is given from standard input in the following format.\n\n\n$ N $ $ M $\n\n\noutput\n\nOu...
[{"input": "-17 16", "output": "-272\n"}, {"input": "-17 30", "output": "-510\n"}, {"input": "-17 44", "output": "-748\n"}, {"input": "-2 125", "output": "-250\n"}, {"input": "-1 111", "output": "-111\n"}, {"input": "-2 110", "output": "-220\n"}, {"input": "-2 100", "output": "-200\n"}, {"input": "13 100", "output": "1...
code_stdio
[ { "content": "There are N stones, numbered 1, 2, \\ldots, N. For each i (1 \\leq i \\leq N), the height of Stone i is h_i. Here, h_1 < h_2 < \\cdots < h_N holds.\n\nThere is a frog who is initially on Stone 1. He will repeat the following action some number of times to reach Stone N:\n\n* If the frog is current...
[{"input": "2 1000000100100\n1174717 1001000", "output": "1030177696189\n"}, {"input": "2 1000000000100\n1174717 1001000", "output": "1030177596189\n"}, {"input": "2 1000000000000\n1807061 1100100", "output": "1499793855521\n"}, {"input": "2 1000000000000\n1249354 1100100", "output": "1022276756516\n"}, {"input": "2 10...
code_stdio
[ { "content": "Limak is a little polar bear. He loves connecting with other bears via social networks. He has n friends and his relation with the i-th of them is described by a unique integer ti. The bigger this value is, the better the friendship is. No two friends have the same value ti.\n\nSpring is starting ...
[{"input": "20 2 15\n12698951 55128070 116962690 156763505 188535242 332511771 269939893 428710623 802222241 483000923 516768937 552903993 633087286 656092270 671535141 714291344 1397620094 1268000284 879748146 937368929\n2 7\n1 2\n2 4\n2 19\n1 12\n1 5\n2 18\n2 11\n1 16\n2 1\n2 3\n2 19\n1 17\n2 4\n2 11\n", "output": "N...
code_stdio
[ { "content": "Happy new year! The year 2020 is also known as Year Gyeongja (경자년, gyeongja-nyeon) in Korea. Where did the name come from? Let's briefly look at the Gapja system, which is traditionally used in Korea to name the years.\n\nThere are two sequences of $n$ strings $s_1, s_2, s_3, \\ldots, s_{n}$ and $...
[{"input": "10 12\nsin im gye gap eul bynoeg jeong mu gj gyeong\nyu sul hae jb chuk in myo jin as o li sin\n14\n1\n1\n3\n4\n17\n17\n12\n13\n73\n2016\n32\n2018\n2019\n2020\n", "output": "sinyu\nsinyu\ngyehae\ngapjb\njeongchuk\njeongchuk\nimsin\ngyeyu\ngyeyu\nbynoegsin\nimjin\nmusul\ngjhae\ngyeongjb\n"}, {"input": "10 12...
code_stdio
[ { "content": "Recently personal training sessions have finished in the Berland State University Olympiad Programmer Training Centre. By the results of these training sessions teams are composed for the oncoming team contest season. Each team consists of three people. All the students of the Centre possess numbe...
[{"input": "7\n4 19 14 8 21 16 2 18 1 15 3 17 13 5 6 10 9 7 12 11 20\n4 19 10\n14 8 3\n21 17 9\n16 6 12\n2 13 20\n18 1 7\n15 5 11\n21\n", "output": "3 4 8 9 10 14 17 1 2 5 6 7 11 12 13 15 16 18 19 20\n"}, {"input": "6\n6 4 10 16 14 11 13 1 7 17 18 15 5 3 9 12 2 8\n6 10 1\n4 3 9\n16 11 13\n14 15 2\n7 18 5\n17 12 8\n7\n"...
code_stdio
[ { "content": "You are given an array $a_1, a_2, \\dots, a_n$ where all $a_i$ are integers and greater than $0$.\n\n In one operation, you can choose two different indices $i$ and $j$ ($1 \\le i, j \\le n$). If $gcd(a_i, a_j)$ is equal to the minimum element of the whole array $a$, you can swap $a_i$ and $a_j$. ...
[{"input": "4\n1\n8\n6\n4 4 6 6 2 9\n4\n4 5 6 10\n5\n10 10 2 2 4\n", "output": "YES\nYES\nYES\nYES\n"}, {"input": "4\n1\n8\n6\n4 4 6 6 2 9\n4\n4 5 6 7\n5\n10 10 2 2 4\n", "output": "YES\nYES\nYES\nYES\n"}, {"input": "4\n1\n8\n6\n4 4 6 6 2 15\n4\n4 5 6 7\n5\n7 10 2 2 3\n", "output": "YES\nYES\nYES\nNO\n"}, {"input": "4\...
code_stdio
[ { "content": "The circle line of the Berland subway has n stations. We know the distances between all pairs of neighboring stations:\n\n\n\n d_1 is the distance between the 1-st and the 2-nd station;\n\n d_2 is the distance between the 2-nd and the 3-rd station;\n\n...\n\n d_{n} - 1 is the distance between the ...
[{"input": "100\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100...
code_stdio
[ { "content": "You are given a sequence of $n$ integers $a_1, \\, a_2, \\, \\dots, \\, a_n$.\n\nDoes there exist a sequence of $n$ integers $b_1, \\, b_2, \\, \\dots, \\, b_n$ such that the following property holds?\n\nFor each $1 \\le i \\le n$, there exist two (not necessarily distinct) indices $j$ and $k$ ($1...
[{"input": "20\n5\n6711 19885 -3098 -16272 -10076\n4\n86522 29647 -12464 -9627\n4\n-82555 -5215 -15221 -63129\n4\n-18147 4 5 -5\n5\n-17427 -19079 17427 15043 19079\n5\n15148 5942 361 9206 21087\n3\n-1 -55 1\n5\n47214 53109 39369 11561 -22908\n4\n-74790 54187 -2 30242\n2\n-68120 94070\n3\n-27228 46215 -33546\n2\n75489 9...
code_stdio
[ { "content": "In this problem you have to simulate the workflow of one-thread server. There are n queries to process, the i-th will be received at moment t_{i} and needs to be processed for d_{i} units of time. All t_{i} are guaranteed to be distinct.\n\nWhen a query appears server may react in three possible w...
[{"input": "4 3\n999999996 1000000000\n999999997 1000000000\n999999998 1000000000\n999999999 1000000000\n", "output": "1999999996 2999999996 3999999996 4999999996 \n"}, {"input": "4 3\n999999996 1000000000\n999999997 1000000000\n999999998 1000000000\n999999999 1000000000\n", "output": "1999999996 2999999996 3999999996 ...
code_stdio
[ { "content": "You play a strategic video game (yeah, we ran out of good problem legends). In this game you control a large army, and your goal is to conquer $n$ castles of your opponent.\n\nLet's describe the game process in detail. Initially you control an army of $k$ warriors. Your enemy controls $n$ castles;...
[{"input": "10 10 2\n2 1 1615\n2 1 1326\n0 0 3880\n2 0 1596\n1 2 4118\n0 0 4795\n0 1 814\n0 0 4555\n0 1 3284\n2 2 1910\n10 6\n2 1\n8 3\n8 7\n6 3\n4 1\n7 4\n6 4\n7 2\n10 9\n", "output": "27079\n"}, {"input": "10 10 0\n0 2 1413\n0 0 4466\n0 0 2681\n0 0 2959\n0 2 1182\n0 0 468\n0 1 3347\n0 0 3978\n0 2 2831\n0 3 3138\n5 2\...
code_stdio
[ { "content": "We have three boxes A, B, and C, each of which contains an integer.\n\nCurrently, the boxes A, B, and C contain the integers X, Y, and Z, respectively.\n\nWe will now do the operations below in order. Find the content of each box afterward. \n - Swap the contents of the boxes A and B\n - Swap the...
[{"input": "100 100 100\n", "output": "100 100 100\n"}, {"input": "111 110 110", "output": "110 111 110\n"}, {"input": "110 110 110", "output": "110 110 110\n"}, {"input": "110 110 111", "output": "111 110 110\n"}, {"input": "010 100 100", "output": "100 10 100\n"}, {"input": "011 101 100", "output": "100 11 101\n"}, {...
code_stdio
[ { "content": "You drew lottery N times. In the i-th draw, you got an item of the kind represented by a string S_i.\nHow many kinds of items did you get?\n\n-----Constraints-----\n - 1 \\leq N \\leq 2\\times 10^5\n - S_i consists of lowercase English letters and has a length between 1 and 10 (inclusive).\n\n----...
[{"input": "5\ngrape\ngrape\ngrape\ngrape\ngrape\n", "output": "1\n"}, {"input": "5\ngrape\ngrape\ngraoe\ngrape\ngrape", "output": "2\n"}, {"input": "5\negapr\ngrape\ngraoe\ngr`pe\nepaqg", "output": "5\n"}, {"input": "5\ngrape\ngrape\ngraoe\ngrape\neparg", "output": "3\n"}, {"input": "5\ngrape\ngrape\ngraoe\ngrape\nepa...
code_stdio
[ { "content": "Today, Wet Shark is given n integers. Using any of these integers no more than once, Wet Shark wants to get maximum possible even (divisible by 2) sum. Please, calculate this value for Wet Shark. \n\nNote, that if Wet Shark uses no integers from the n integers, the sum is an even integer 0.\n\n\n-...
[{"input": "5\n999999999 503514429 850382710 999999999 1620498919\n", "output": "4974396056\n"}, {"input": "5\n999999999 503514429 850382710 999999999 1246839866\n", "output": "4097222574\n"}, {"input": "5\n999999999 999999999 850382710 999999999 999999999\n", "output": "4850382706\n"}, {"input": "5\n999999999 50351442...
code_stdio
[ { "content": "Once when Gerald studied in the first year at school, his teacher gave the class the following homework. She offered the students a string consisting of n small Latin letters; the task was to learn the way the letters that the string contains are written. However, as Gerald is too lazy, he has no ...
[{"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n99\n", "output": "1\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n"}, {"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...
code_stdio
[ { "content": "Recently, Petya learned about a new game \"Slay the Dragon\". As the name suggests, the player will have to fight with dragons. To defeat a dragon, you have to kill it and defend your castle. To do this, the player has a squad of $n$ heroes, the strength of the $i$-th hero is equal to $a_i$.\n\nAc...
[{"input": "4\n3 0 2 3\n5\n6 12\n2 22\n2 14\n1 7\n14 17\n", "output": "10\n16\n8\n1\n23\n"}, {"input": "4\n3 5 2 3\n5\n6 12\n2 22\n2 14\n1 7\n14 17\n", "output": "5\n11\n3\n0\n18\n"}, {"input": "4\n3 5 2 3\n5\n6 4\n2 22\n2 14\n2 14\n14 17\n", "output": "1\n11\n3\n3\n18\n"}, {"input": "4\n3 5 2 3\n5\n3 12\n2 15\n1 14\n1...
code_stdio
[ { "content": "You are given a special jigsaw puzzle consisting of $n\\cdot m$ identical pieces. Every piece has three tabs and one blank, as pictured below. $\\{3$ \n\nThe jigsaw puzzle is considered solved if the following conditions hold: The pieces are arranged into a grid with $n$ rows and $m$ columns. Fo...
[{"input": "3\n1 10\n001000 100000\n10 2\n", "output": "YES\nNO\nNO\n"}, {"input": "3\n1 10\n001000 100000\n16 2\n", "output": "YES\nNO\nNO\n"}, {"input": "3\n1 12\n110000 101110\n1 2\n", "output": "YES\nNO\nYES\n"}, {"input": "3\n1 15\n001000 100000\n16 2\n", "output": "YES\nNO\nNO\n"}, {"input": "3\n1 12\n110000 1011...
code_stdio
[ { "content": "You have a given picture with size $w \\times h$. Determine if the given picture has a single \"+\" shape or not. A \"+\" shape is described below:\n\n A \"+\" shape has one center nonempty cell. There should be some (at least one) consecutive non-empty cells in each direction (left, right, up, ...
[{"input": "10 10\n..........\n..........\n....*.....\n....*.....\n.*******..\n....*.....\n....*.....\n..........\n....*.....\n..........\n", "output": "NO\n"}, {"input": "10 10\n..........\n..........\n....*.....\n....*.....\n.*******..\n....*.....\n....*.....\n..........\n....**....\n..........\n", "output": "NO\n"},...
code_stdio
[ { "content": "You are given three strings A, B and C. Each of these is a string of length N consisting of lowercase English letters.\n\nOur objective is to make all these three strings equal. For that, you can repeatedly perform the following operation:\n\n* Operation: Choose one of the strings A, B and C, and ...
[{"input": "9\ncjfferent\ndifferent\ntnereffid", "output": "10\n"}, {"input": "9\ntneredfic\nciffeernt\ndifferent", "output": "11\n"}, {"input": "9\ntnedergia\ncifreefnt\ndifsnfeet", "output": "14\n"}, {"input": "9\ntnedergib\nbifrfegnt\ntcdfmtfhe", "output": "16\n"}, {"input": "9\ntnedeqgib\nbifrfegnt\ngcdfmtfte", "ou...
code_stdio
[ { "content": "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...
[{"input": "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\n66 7\n67 56\n70 28\n73 12\n74 81\n78 77\n95 99\n", "output": "2 3 4 6 7 8 11 12 14 15 17 18 19\n"}, {"input": "20 8\n2 37\n9 28\n13 63\n14 85\n27 27\n29 90\n34 96\n36 60\n41 14\n45 25\n46 95\n48 59\n53 12\n55 69\n61 11\n76...
code_stdio
[ { "content": "It is a simplified version of problem F2. The difference between them is the constraints (F1: $k \\le 2$, F2: $k \\le 10$).\n\nYou are given an integer $n$. Find the minimum integer $x$ such that $x \\ge n$ and the number $x$ is $k$-beautiful.\n\nA number is called $k$-beautiful if its decimal rep...
[{"input": "4\n1 1\n221 2\n177890 2\n998244353 1\n", "output": "1\n221\n181111\n999999999\n"}, {"input": "4\n1 1\n221 2\n177890 1\n998244353 1\n", "output": "1\n221\n222222\n999999999\n"}, {"input": "4\n1 1\n221 2\n108810 1\n998244353 1\n", "output": "1\n221\n111111\n999999999\n"}, {"input": "4\n2 1\n221 2\n177890 2\n9...
code_stdio
[ { "content": "You are given an undirected graph with N vertices and 0 edges. Process Q queries of the following types.\n\n* `0 u v`: Add an edge (u, v).\n* `1 u v`: Print 1 if u and v are in the same connected component, 0 otherwise.\n\nConstraints\n\n* 1 \\leq N \\leq 200,000\n* 1 \\leq Q \\leq 200,000\n* 0 \\...
[{"input": "4 7\n0 0 1\n-1 1 1\n-1 2 3\n1 0 1\n1 2 2\n-1 0 3\n-1 1 1", "output": "1\n0\n1\n1\n0\n1\n"}, {"input": "4 7\n0 0 1\n-1 2 1\n-1 2 3\n1 0 1\n1 2 2\n-1 0 3\n-1 1 1", "output": "0\n0\n1\n1\n0\n1\n"}, {"input": "9 7\n1 1 1\n-1 0 1\n-1 2 3\n1 0 2\n0 0 4\n-1 0 1\n2 1 3", "output": "1\n0\n0\n0\n0\n0\n"}, {"input": "...
code_stdio
[ { "content": "There are n heaps of stone. The i-th heap has h_i stones. You want to change the number of stones in the heap by performing the following process once: \n\n * You go through the heaps from the 3-rd heap to the n-th heap, in this order. \n * Let i be the number of the current heap. \n * You can ...
[{"input": "4\n4\n1 0 18 100\n4\n100 000 100 1\n5\n10 2 1 1 3\n6\n1 4 4 3 5 24\n", "output": "13\n1\n1\n3\n"}, {"input": "4\n4\n1 0 18 100\n4\n100 000 100 1\n5\n10 2 1 1 2\n6\n2 4 4 3 5 24\n", "output": "13\n1\n1\n4\n"}, {"input": "4\n4\n0 0 18 100\n4\n100 000 100 1\n5\n10 2 1 1 2\n6\n2 4 4 3 5 24\n", "output": "12\n1\...
code_stdio
[ { "content": "Example\n\nInput\n\n3 2\nR1\n\n\nOutput\n\n3 1 2\n4 5 6\n7 8 9\n\nWrite Python code to solve this problem. Your program should read the input from stdin and write the output to stdout. Enclose your complete solution in a single ```python code block.", "role": "user" } ]
[{"input": "73 2\nR2", "output": "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73\n146 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97...
code_stdio
[ { "content": "There are N islands and M bridges.\nThe i-th bridge connects the A_i-th and B_i-th islands bidirectionally.\nInitially, we can travel between any two islands using some of these bridges.\nHowever, the results of a survey show that these bridges will all collapse because of aging, in the order from...
[{"input": "29 45\n1 3\n2 3\n2 14\n2 19\n2 29\n3 26\n4 5\n4 6\n4 13\n4 17\n5 10\n5 19\n5 24\n6 18\n6 19\n6 24\n6 25\n6 28\n6 29\n8 9\n9 18\n9 25\n10 29\n11 16\n11 22\n12 14\n12 15\n12 26\n12 29\n13 14\n14 20\n14 27\n14 29\n15 16\n15 22\n15 25\n15 29\n16 29\n17 27\n19 26\n20 29\n24 26\n15 23\n1 21\n7 28\n", "output": "5...
code_stdio
[ { "content": "Niwango-kun is an employee of Dwango Co., Ltd.\nOne day, he is asked to generate a thumbnail from a video a user submitted.\nTo generate a thumbnail, he needs to select a frame of the video according to the following procedure:\n\n* Get an integer N and N integers a_0, a_1, ..., a_{N-1} as inputs....
[{"input": "4\n-1 13 12 2", "output": "3\n"}, {"input": "4\n-1 19 12 6", "output": "2\n"}, {"input": "4\n0 10 12 2", "output": "1\n"}, {"input": "4\n0 20 12 2", "output": "2\n"}, {"input": "4\n0 20 12 1", "output": "2\n"}, {"input": "4\n0 13 12 2", "output": "3\n"}, {"input": "4\n0 19 12 2", "output": "2\n"}, {"input":...
code_stdio
[ { "content": "Mike decided to teach programming to children in an elementary school. He knows that it is not an easy task to interest children in that age to code. That is why he decided to give each child two sweets.\n\nMike has $n$ sweets with sizes $a_1, a_2, \\ldots, a_n$. All his sweets have different size...
[{"input": "20\n43 48 38 34 23 18 8 22 12 7 47 1 13 20 3 15 49 6 10 26\n", "output": "5\n"}, {"input": "20\n43 48 38 34 23 18 8 22 12 7 47 1 13 20 3 15 49 6 10 26\n", "output": "5\n"}, {"input": "20\n43 48 38 34 41 18 8 22 12 7 47 1 13 20 3 15 49 6 10 26\n", "output": "6\n"}, {"input": "20\n43 48 38 34 23 18 8 22 12 7 ...
code_stdio
[ { "content": "The hero of the Cut the Rope game is a little monster named Om Nom. He loves candies. And what a coincidence! He also is the hero of today's problem. [Image] \n\nOne day, Om Nom visited his friend Evan. Evan has n candies of two types (fruit drops and caramel drops), the i-th candy hangs at the he...
[{"input": "10 2\n0 2 3\n1 5 2\n0 7 3\n1 15 2\n0 14 3\n1 19 1\n1 5 3\n0 2 2\n0 10 2\n0 10 3\n", "output": "9\n"}, {"input": "10 2\n0 2 3\n1 5 2\n0 7 3\n1 15 2\n0 14 3\n1 19 1\n1 5 3\n0 2 2\n0 10 2\n0 10 3\n", "output": "9"}, {"input": "10 2\n0 2 3\n1 5 2\n0 7 3\n1 15 2\n0 3 3\n1 19 1\n1 5 3\n0 2 2\n0 10 2\n0 10 3\n", "...
code_stdio
[ { "content": "Example\n\nInput\n\n2\n1 2\n\n\nOutput\n\n2\n\nWrite Python code to solve this problem. Your program should read the input from stdin and write the output to stdout. Enclose your complete solution in a single ```python code block.", "role": "user" } ]
[{"input": "2\n-1 -12", "output": "12\n"}, {"input": "2\n-1 12", "output": "-1\n"}, {"input": "2\n-1 24", "output": "-1\n"}, {"input": "2\n-2 24", "output": "-1\n"}, {"input": "2\n-2 22", "output": "-1\n"}, {"input": "2\n-2 -5", "output": "-1\n"}, {"input": "2\n10 16", "output": "-1\n"}, {"input": "2\n2 17", "output": ...
code_stdio
[ { "content": "A chessboard n × m in size is given. During the zero minute we repaint all the black squares to the 0 color. During the i-th minute we repaint to the i color the initially black squares that have exactly four corner-adjacent squares painted i - 1 (all such squares are repainted simultaneously). Th...
[{"input": "5000 5000\n1000000000\n", "output": "0\n"}, {"input": "2085 5000\n1000000000\n", "output": "0\n"}, {"input": "3762 3914\n1073\n", "output": "3386\n"}, {"input": "4583 2774\n1206\n", "output": "2535\n"}, {"input": "3432 4788\n1203\n", "output": "3410\n"}, {"input": "4643 3755\n1381\n", "output": "2876\n"}, {...
code_stdio
[ { "content": "Takahashi has a tower which is divided into N layers. Initially, all the layers are uncolored. Takahashi is going to paint some of the layers in red, green or blue to make a beautiful tower. He defines the beauty of the tower as follows:\n\n* The beauty of the tower is the sum of the scores of the...
[{"input": "121980 33447 90629 11295524182", "output": "643972230\n"}, {"input": "111605 33447 77758 2284871002", "output": "762328834\n"}, {"input": "111605 33447 14069 2284871002", "output": "815838636\n"}, {"input": "42470 60074 125620 6171829514", "output": "334199188\n"}, {"input": "111605 33447 27166 2284871002",...
code_stdio
[ { "content": "Polycarp likes numbers that are divisible by 3.\n\nHe has a huge number $s$. Polycarp wants to cut from it the maximum number of numbers that are divisible by $3$. To do this, he makes an arbitrary number of vertical cuts between pairs of adjacent digits. As a result, after $m$ such cuts, there wi...
[{"input": "1000000000000000000000000000000000\n", "output": "33\n"}, {"input": "1000010000000000000000000000000000\n", "output": "32\n"}, {"input": "1000010000000001000000000000000000\n", "output": "31\n"}, {"input": "1000000001000001000010000000000000\n", "output": "30\n"}, {"input": "10000000010000001000100000000010...
code_stdio
[ { "content": "Vasya the Great Magician and Conjurer loves all kinds of miracles and wizardry. In one wave of a magic wand he can turn an object into something else. But, as you all know, there is no better magic in the Universe than the magic of numbers. That's why Vasya adores math and spends a lot of time tur...
[{"input": "100 -4900 100\n", "output": "1 100 1 100 1 100 1 100 1 100 1 100 1 100 1 100 1 100 1 100 1 100 1 100 1 100 1 100 1 100 1 100 1 100 1 100 1 100 1 100 1 100 1 100 1 100 1 100 1 100 1 100 1 100 1 100 1 100 1 100 1 100 1 100 1 100 1 100 1 100 1 100 1 100 1 100 1 100 1 100 1 100 1 100 1 100 1 100 1 100 1 100 1 1...
code_stdio
[ { "content": "A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7.\n\nWrite a program which reads a list of N integers and prints the number of prime numbers in the list.\n\nConstraints\n\n1 ≤ N ≤ 1...
[{"input": "11\n13\n20\n9\n10\n11\n13\n33\n14\n16\n12\n17", "output": "4\n"}, {"input": "11\n25\n20\n9\n10\n11\n13\n33\n14\n16\n12\n17", "output": "3\n"}, {"input": "11\n7\n10\n9\n10\n11\n13\n17\n14\n15\n16\n17", "output": "5\n"}, {"input": "11\n13\n20\n9\n10\n11\n13\n17\n14\n15\n8\n17", "output": "5\n"}, {"input": "11...
code_stdio
[ { "content": "Polycarp likes arithmetic progressions. A sequence $[a_1, a_2, \\dots, a_n]$ is called an arithmetic progression if for each $i$ ($1 \\le i < n$) the value $a_{i+1} - a_i$ is the same. For example, the sequences $[42]$, $[5, 5, 5]$, $[2, 11, 20, 29]$ and $[3, 2, 1, 0]$ are arithmetic progressions,...
[{"input": "4\n1 1000000000 1000000000 1000000000\n", "output": "-1\n"}, {"input": "4\n1 1000000000 1000000000 1000000000\n", "output": "-1\n"}, {"input": "4\n1 1000000000 1010000000 1000000000\n", "output": "-1\n"}, {"input": "4\n0 1000000000 1010000000 1000000000\n", "output": "-1\n"}, {"input": "4\n0 1000000010 1010...
code_stdio
[ { "content": "Gennady owns a small hotel in the countryside where he lives a peaceful life. He loves to take long walks, watch sunsets and play cards with tourists staying in his hotel. His favorite game is called \"Mau-Mau\".\n\nTo play Mau-Mau, you need a pack of $52$ cards. Each card has a suit (Diamonds — D...
[{"input": "AS\n2H 4C TH JH AD\n", "output": "YES\n"}, {"input": "4D\nAS AC AD AH 5H\n", "output": "YES\n"}, {"input": "KH\n3C QD 9S KS 8D\n", "output": "YES\n"}, {"input": "4H\nJH QC 5H 9H KD\n", "output": "YES\n"}, {"input": "QC\nQD KS AH 7S 2S\n", "output": "YES\n"}, {"input": "7H\n4H 6D AC KH 8H\n", "output": "YES\...
code_stdio
[ { "content": "You have an integer variable x.\nInitially, x=0.\nSome person gave you a string S of length N, and using the string you performed the following operation N times.\nIn the i-th operation, you incremented the value of x by 1 if S_i=I, and decremented the value of x by 1 if S_i=D.\nFind the maximum v...
[{"input": "7\nDDIDDII\n", "output": "0\n"}, {"input": "7\nIIDDIDD", "output": "2\n"}, {"input": "7\nDIDDIID", "output": "0\n"}, {"input": "7\nIIIDDDD", "output": "3\n"}, {"input": "7\nDIIDDID", "output": "1\n"}, {"input": "7\nDIIDIDD", "output": "1\n"}, {"input": "7\nDDDIDII", "output": "0\n"}, {"input": "7\nIIDDDID",...
code_stdio
[ { "content": "Alice and Bob play 5-in-a-row game. They have a playing field of size 10 × 10. In turns they put either crosses or noughts, one at a time. Alice puts crosses and Bob puts noughts.\n\nIn current match they have made some turns and now it's Alice's turn. She wonders if she can put cross in such empt...
[{"input": "XX.XX.....\n.....OOOO.\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n", "output": "YES\n"}, {"input": "XO........\n.XO.......\n..XO......\n....O.....\n....X.....\n..........\n..........\n..........\n..........\n..........\n", "output": "YES\n"}, {"input": "...
code_stdio
[ { "content": "prison\n\nThere are an infinite number of prisoners. Initially, the prisoners are numbered 0, 1, 2, ....\n\nDo the following N times:\n\n* Release the 0th prisoner and execute the k, 2k, 3k, ... th prisoners.\n* Then renumber the remaining prisoners. At this time, the prisoners with the smallest o...
[{"input": "41 2", "output": "1099511627775\n"}, {"input": "35 2", "output": "17179869183\n"}, {"input": "34 2", "output": "8589934591\n"}, {"input": "56 3", "output": "7854933626\n"}, {"input": "29 2", "output": "268435455\n"}, {"input": "26 2", "output": "33554431\n"}, {"input": "25 2", "output": "16777215\n"}, {"inp...
code_stdio
[ { "content": "You might have remembered Theatre square from the problem 1A. Now it's finally getting repaved.\n\nThe square still has a rectangular shape of $n \\times m$ meters. However, the picture is about to get more complicated now. Let $a_{i,j}$ be the $j$-th square in the $i$-th row of the pavement.\n\nY...
[{"input": "1\n9 9 9 9\n.........\n.........\n.........\n.........\n.........\n.........\n.........\n.........\n.........\n", "output": "405\n"}, {"input": "1\n9 9 9 9\n.........\n.........\n.........\n.........\n.........\n.........\n.........\n.........\n.........\n", "output": "405\n"}, {"input": "4\n1 1 10 1\n.\n1 ...
code_stdio
[ { "content": "You are given an integer $n$. In one move, you can either multiply $n$ by two or divide $n$ by $6$ (if it is divisible by $6$ without the remainder).\n\nYour task is to find the minimum number of moves needed to obtain $1$ from $n$ or determine if it's impossible to do that.\n\nYou have to answer ...
[{"input": "7\n2\n2\n2\n12\n45568\n15116544\n387420489\n", "output": "-1\n-1\n-1\n-1\n-1\n12\n36\n"}, {"input": "7\n2\n2\n2\n17\n45568\n15116544\n387420489\n", "output": "-1\n-1\n-1\n-1\n-1\n12\n36\n"}, {"input": "7\n5\n2\n4\n17\n60902\n15116544\n387420489\n", "output": "-1\n-1\n-1\n-1\n-1\n12\n36\n"}, {"input": "7\n1\...
code_stdio
[ { "content": "There are two buttons, one of size A and one of size B.\nWhen you press a button of size X, you get X coins and the size of that button decreases by 1.\nYou will press a button twice. Here, you can press the same button twice, or press both buttons once.\nAt most how many coins can you get?\n\n---...
[{"input": "-134 -12", "output": "-25\n"}, {"input": "-134 -8", "output": "-17\n"}, {"input": "-13 -10", "output": "-21\n"}, {"input": "100 100", "output": "200\n"}, {"input": "111 111", "output": "222\n"}, {"input": "101 101", "output": "202\n"}, {"input": "-10 -10", "output": "-20\n"}, {"input": "110 110", "output": ...
code_stdio
[ { "content": "There is a cube which consists of n × n × n small cubes. Small cubes have marks on their surfaces. An example where n = 4 is shown in the following figure.\n\n\n<image>\n\n\nThen, as shown in the figure above (right), make a hole that penetrates horizontally or vertically from the marked surface t...
[{"input": "12 3\nxy 4 3\nxz 1 2\nyz 2 3\n7 5\nxy 1 1\nxy 3 3\nxz 3 2\nyz 2 1\nyz 3 3\n0 0", "output": "1692\n310\n"}, {"input": "12 3\nxy 4 3\nxz 1 2\nyz 2 3\n7 5\nxy 1 1\nyx 3 3\nxz 3 2\nyz 2 1\nyz 3 3\n0 0", "output": "1692\n315\n"}, {"input": "14 3\nxy 4 3\nxz 1 2\nyz 2 3\n4 5\nxy 1 1\nxy 3 3\nxz 3 2\nyz 2 1\nyz 3 ...
code_stdio
[ { "content": "Constraints\n\n* 1 ≤ |V| ≤ 1000\n* 0 ≤ |E| ≤ 2000\n* -10000 ≤ di ≤ 10000\n* There are no parallel edges\n* There are no self-loops\n\nInput\n\nAn edge-weighted graph G (V, E) and the source r.\n\n\n|V| |E| r\ns0 t0 d0\ns1 t1 d1\n:\ns|E|-1 t|E|-1 d|E|-1\n\n\n|V| is the number of vertices and |E| is...
[{"input": "42 0 1\n2 -1 3\n0 5 55\n1 0 -2\n-2 0 1\n2 4 -1", "output": "INF\n0\nINF\nINF\nINF\nINF\nINF\nINF\nINF\nINF\nINF\nINF\nINF\nINF\nINF\nINF\nINF\nINF\nINF\nINF\nINF\nINF\nINF\nINF\nINF\nINF\nINF\nINF\nINF\nINF\nINF\nINF\nINF\nINF\nINF\nINF\nINF\nINF\nINF\nINF\nINF\nINF\n"}, {"input": "38 0 1\n2 -2 3\n0 6 55\n1...
code_stdio
[ { "content": "As Valeric and Valerko were watching one of the last Euro Championship games in a sports bar, they broke a mug. Of course, the guys paid for it but the barman said that he will let them watch football in his bar only if they help his son complete a programming task. The task goes like that.\n\nLet...
[{"input": "5\n1000000000 1000000000\n1000000000 1000000000\n1000000000 1000000000\n1000000000 1000000000\n294967296 294967296\n", "output": "1\n"}, {"input": "5\n1000000000 1000000000\n1000000000 1000000000\n1000100000 1000000000\n1000000000 1000000000\n294967296 294967296\n", "output": "2\n"}, {"input": "5\n100000000...
code_stdio
[ { "content": "You are given a sequence $a$, initially consisting of $n$ integers.\n\nYou want to transform this sequence so that all elements in it are equal (i. e. it contains several occurrences of the same element).\n\nTo achieve this, you choose some integer $x$ that occurs at least once in $a$, and then pe...
[{"input": "5\n3\n1 1 1\n5\n1 2 3 4 5\n5\n1 2 3 2 1\n7\n1 2 3 1 2 3 1\n11\n2 2 1 2 3 2 1 2 3 1 2\n", "output": "\n0\n1\n1\n2\n3\n"}, {"input": "5\n3\n1 1 1\n5\n1 2 3 4 5\n5\n1 2 3 2 1\n7\n1 2 3 1 2 3 1\n11\n2 2 1 2 3 2 1 2 3 1 2\n", "output": "0\n1\n1\n2\n3\n"}, {"input": "5\n3\n1 1 1\n5\n1 2 3 4 5\n5\n1 2 3 2 1\n7\n1 ...
code_stdio
[ { "content": "B: Hokkaido University Hard\n\nNote\n\nPlease note that the question settings are the same as question A, except for the constraints.\n\nstory\n\nHomura-chan, who passed Hokkaido University and is excited about the beginning of a new life. But in front of her, a huge campus awaits ...\n\n\"Eh ... ...
[{"input": "3 3\nB.B\nB..\n.BB", "output": "4\n"}, {"input": "2 3\nB.B\nB..\n.BB", "output": "3\n"}, {"input": "1 3\nB-B\n..B\n.BA", "output": "2\n"}, {"input": "1 1\nB-B\n..B\n.BA", "output": "0\n"}, {"input": "1 3\nBB.\nB..\n.AA", "output": "1\n"}, {"input": "3 3\nB.B\nB..\nBB.", "output": "4\n"}, {"input": "3 3\nB.B...
code_stdio
[ { "content": "Takahashi is solving quizzes. He has easily solved all but the last one.\nThe last quiz has three choices: 1, 2, and 3.\nWith his supernatural power, Takahashi has found out that the choices A and B are both wrong.\nPrint the correct choice for this problem.\n\n-----Constraints-----\n - Each of th...
[{"input": "3\n001", "output": "2\n"}, {"input": "3\n001", "output": "2\n"}, {"input": "3\n1\n", "output": "2\n"}, {"input": "1\n2\n", "output": "3\n"}, {"input": "1\n3\n", "output": "2\n"}, {"input": "3\n2\n", "output": "1\n"}, {"input": "2\n1\n", "output": "3\n"}, {"input": "2\n3\n", "output": "1\n"}, {"input": "3\n2...
code_stdio
[ { "content": "You are given an array $a[0 \\ldots n-1]$ of length $n$ which consists of non-negative integers. Note that array indices start from zero.\n\nAn array is called good if the parity of each index matches the parity of the element at that index. More formally, an array is good if for all $i$ ($0 \\le ...
[{"input": "4\n4\n6 4 7 6\n3\n3 2 6\n1\n7\n3\n4 14 2 1 18 3 0\n", "output": "-1\n1\n-1\n-1\n"}, {"input": "4\n4\n3 2 0 6\n3\n6 4 4\n1\n7\n7\n7 7 2 1 18 1 2\n", "output": "-1\n-1\n-1\n-1\n"}, {"input": "4\n4\n3 2 7 8\n3\n6 2 8\n1\n7\n7\n6 13 2 1 19 1 1\n", "output": "2\n-1\n-1\n-1\n"}, {"input": "4\n4\n3 2 7 6\n3\n6 2 6...
code_stdio
[ { "content": "The postal code in Atcoder Kingdom is A+B+1 characters long, its (A+1)-th character is a hyphen -, and the other characters are digits from 0 through 9.\nYou are given a string S. Determine whether it follows the postal code format in Atcoder Kingdom.\n\n-----Constraints-----\n - 1≤A,B≤5\n - |S|=A...
[{"input": "3 4\n269-6650\n", "output": "Yes\n"}, {"input": "6 4\n269-6650", "output": "No\n"}, {"input": "6 8\n269-6650", "output": "No\n"}, {"input": "6 1\n269-6650", "output": "No\n"}, {"input": "6 2\n269-6650", "output": "No\n"}, {"input": "6 2\n0566-962", "output": "No\n"}, {"input": "6 3\n0566-962", "output": "No...
code_stdio
[ { "content": "CQXYM found a rectangle A of size n × m. There are n rows and m columns of blocks. Each block of the rectangle is an obsidian block or empty. CQXYM can change an obsidian block to an empty block or an empty block to an obsidian block in one operation.\n\nA rectangle M size of a × b is called a por...
[{"input": "1\n9 9\n001010001\n101110100\n000010011\n100000001\n101010101\n110001111\n000001111\n110100000\n000110000\n", "output": "5\n"}, {"input": "1\n8 9\n101110001\n101110100\n000010001\n001000001\n001011101\n110001111\n000001111\n110100010\n010110000\n", "output": "4\n"}, {"input": "1\n8 9\n101110001\n101110100\n...
code_stdio
[ { "content": "Note that girls in Arpa’s land are really attractive.\n\nArpa loves overnight parties. In the middle of one of these parties Mehrdad suddenly appeared. He saw n pairs of friends sitting around a table. i-th pair consisted of a boy, sitting on the a_{i}-th chair, and his girlfriend, sitting on the ...
[{"input": "26\n8 10\n52 21\n2 33\n18 34\n30 51\n5 19\n22 32\n36 28\n42 16\n13 49\n11 17\n31 39\n43 37\n50 15\n29 20\n35 46\n47 23\n3 1\n44 7\n9 27\n6 48\n40 24\n26 14\n45 4\n12 25\n41 38\n", "output": "2 1\n1 2\n2 1\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n2 1\n1 2\n1 2\n1 2\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n1 2\n2 1\n2 ...
code_stdio
[ { "content": "Polycarp wrote on the board a string $s$ containing only lowercase Latin letters ('a'-'z'). This string is known for you and given in the input.\n\nAfter that, he erased some letters from the string $s$, and he rewrote the remaining letters in any order. As a result, he got some new string $t$. Yo...
[{"input": "10\nvzsxyuyy\n3\n1 0 3\nwwvutuxsuxywut\n2\n0 0\nsuzvsvutvvstuz\n3\n3 1 0\nstyuwsutv\n4\n6 3 0 1\nzsustytvzsyw\n6\n0 9 5 7 7 5\nsvwxwwwyxuvszx\n1\n0\nxuyyvuztxwuuvsxwz\n5\n5 7 0 0 7\nuxuztuwsxz\n5\n4 2 2 0 10\nxystzstwtzwsz\n2\n1 0\nuuzss\n1\n0\n", "output": "yzx\nxx\nuvz\nuvyw\nztwtvy\nz\nywzzx\nuxuzt\nyz\n...
code_stdio
[ { "content": "Just to remind, girls in Arpa's land are really nice.\n\nMehrdad wants to invite some Hoses to the palace for a dancing party. Each Hos has some weight wi and some beauty bi. Also each Hos may have some friends. Hoses are divided in some friendship groups. Two Hoses x and y are in the same friends...
[{"input": "10 5 100\n64 109 3 94 96 97 52 54 82 26\n796554 444893 214351 43810 684158 1060686 686198 339093 383018 699152\n6 8\n8 3\n3 9\n2 3\n10 3\n", "output": "1495706\n"}, {"input": "10 5 100\n48 73 57 46 95 19 171 73 94 24\n501216 675859 843572 565104 879875 828759 80776 766980 213551 492652\n1 2\n6 5\n7 6\n10 5\...
code_stdio
[ { "content": "You are a rebel leader and you are planning to start a revolution in your country. But the evil Government found out about your plans and set your punishment in the form of correctional labor.\n\nYou must paint a fence which consists of $10^{100}$ planks in two colors in the following way (suppose...
[{"input": "5\n1 1000000000 999999998\n1 1000000000 999999999\n1 1000000000 1000000000\n1000000000 1000000000 2\n1000000000 1000000000 1000000000\n", "output": "REBEL\nREBEL\nOBEY\nOBEY\nOBEY\n"}, {"input": "5\n1 1000000000 999999998\n1 1000000000 999999999\n1 1000000000 1000000000\n1000000000 1000000000 2\n1000000000 ...
code_stdio
[ { "content": "Write a program which reads an directed graph $G = (V, E)$, and finds the shortest distance from vertex $1$ to each vertex (the number of edges in the shortest path). Vertices are identified by IDs $1, 2, ... n$.\n\nConstraints\n\n* $1 \\leq n \\leq 100$\n\nInput\n\nIn the first line, an integer $...
[{"input": "4\n1 2 1 4\n2 -1 4\n0 -1\n4 1 0", "output": "1 0\n2 -1\n3 -1\n4 1\n"}, {"input": "4\n1 2 1 4\n2 0 4\n0 -1\n4 -1 0", "output": "1 0\n2 -1\n3 -1\n4 1\n"}, {"input": "4\n1 2 1 4\n3 0 4\n0 -1\n4 -1 0", "output": "1 0\n2 -1\n3 -1\n4 1\n"}, {"input": "4\n1 2 4 4\n2 0 4\n0 -1\n-1 0 1", "output": "1 0\n2 -1\n3 -1\n...
code_stdio
[ { "content": "The only difference between easy and hard versions is the length of the string. You can hack this problem only if you solve both problems.\n\nKirk has a binary string $s$ (a string which consists of zeroes and ones) of length $n$ and he is asking you to find a binary string $t$ of the same length ...
[{"input": "0111001100111011101000\n", "output": "0011001100001011101000\n"}, {"input": "0111001110111011101000\n", "output": "0011000010001011101000\n"}, {"input": "0111001110101011101000\n", "output": "0011000010101011101000\n"}, {"input": "0111011110101011101000\n", "output": "0001000010101011101000\n"}, {"input": "...
code_stdio
[ { "content": "A university student, Takahashi, has to take N examinations and pass all of them. Currently, his readiness for the i-th examination is A_{i}, and according to his investigation, it is known that he needs readiness of at least B_{i} in order to pass the i-th examination.\n\nTakahashi thinks that he...
[{"input": "12\n757232153 372327760 440075441 195848680 354974235 458054863 463477172 740174259 615762794 632963102 529866931 64991604\n102338863 98239366 465611891 362739947 147060907 118867039 63189252 78303147 501410831 110823640 122948912 572905212", "output": "5\n"}, {"input": "12\n757232153 372327760 440075441 15...
code_stdio
[ { "content": "Snuke has an integer sequence A of length N.\n\nHe will freely choose an integer b. Here, he will get sad if A_i and b+i are far from each other. More specifically, the sadness of Snuke is calculated as follows:\n\n* abs(A_1 - (b+1)) + abs(A_2 - (b+2)) + ... + abs(A_N - (b+N))\n\n\n\nHere, abs(x) ...
[{"input": "9\n1 -4 4 -6 -16 1 1 24 -1", "output": "59\n"}, {"input": "9\n0 -1 -7 2 -1 0 -1 6 -3", "output": "28\n"}, {"input": "9\n0 -1 -7 2 -1 0 -1 6 -2", "output": "27\n"}, {"input": "9\n2 0 5 -2 -2 1 -2 10 -7", "output": "41\n"}, {"input": "9\n1 -4 4 -4 -4 1 0 18 -1", "output": "40\n"}, {"input": "9\n1 -4 4 -4 -8 1...
code_stdio
[ { "content": "Stephen Queen wants to write a story. He is a very unusual writer, he uses only letters 'a', 'b', 'c', 'd' and 'e'!\n\nTo compose a story, Stephen wrote out $n$ words consisting of the first $5$ lowercase letters of the Latin alphabet. He wants to select the maximum number of words to make an inte...
[{"input": "6\n3\nbac\naaada\ne\n3\naba\nabcde\naba\n2\nbaba\nbaba\n4\nab\nab\nc\nbc\n5\ncbdca\nd\na\nd\ne\n3\nb\nc\nca\n", "output": "3\n2\n0\n2\n3\n2\n"}, {"input": "6\n3\nbac\naaada\ne\n3\naba\nabcde\naba\n2\nbaba\nbaba\n4\nba\nab\nc\nbc\n5\ncbdca\nd\na\nd\ne\n3\nb\nc\nca\n", "output": "3\n2\n0\n2\n3\n2\n"}, {"input...
code_stdio
[ { "content": "Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise...
[{"input": "93\n010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010\n", "output": "93\n"}, {"input": "93\n010101010101010101010101010101010101010101010101010101010101010101010101011101010101010101010\n", "output": "93\n"}, {"input": "93\n0101010101010101010101010101010101010101...
code_stdio
[ { "content": "You are given a connected undirected weighted graph consisting of $n$ vertices and $m$ edges.\n\nYou need to print the $k$-th smallest shortest path in this graph (paths from the vertex to itself are not counted, paths from $i$ to $j$ and from $j$ to $i$ are counted as one).\n\nMore formally, if $...
[{"input": "28 27 378\n1 2 1000000000\n2 3 1000000000\n3 4 1000000000\n4 5 1000000000\n5 6 1000000000\n6 7 1000000000\n7 8 1000000000\n8 9 1000000000\n9 10 1000000000\n10 11 1000000000\n11 12 1000000000\n12 13 1000000000\n13 14 1000000000\n14 15 1000000000\n15 16 1000000000\n16 17 1000000000\n17 18 1000000000\n18 19 10...
code_stdio
[ { "content": "Karen has just arrived at school, and she has a math test today!\n\n<image>\n\nThe test is about basic addition and subtraction. Unfortunately, the teachers were too busy writing tasks for Codeforces rounds, and had no time to make an actual test. So, they just put one question in the test that is...
[{"input": "19\n716981305 764655030 1148561420 914539062 853464027 317088317 653721289 239862203 605157354 943428394 261437390 821695238 312192823 432992892 547139308 121208111 1614663126 223751525 1084180198\n", "output": "399181927\n"}, {"input": "19\n469776209 764655030 1148561420 914539062 853464027 317088317 65372...
code_stdio
[ { "content": "Little Artem has invented a time machine! He could go anywhere in time, but all his thoughts of course are with computer science. He wants to apply this time machine to a well-known data structure: multiset.\n\nArtem wants to create a basic multiset of integers. He wants these structure to support...
[{"input": "10\n1 1 1000000000\n1 4 1000000000\n2 2 1000000000\n1 5 1000000000\n1 8 1000000000\n2 15 1000000000\n3 3 1000000000\n3 10 1000000000\n3 6 1000000000\n3 7 1000000000\n", "output": "0\n3\n2\n2\n"}, {"input": "10\n1 1 1000000000\n1 4 1000000000\n2 2 1000000000\n1 5 1000000000\n1 8 1000000000\n2 15 1000000000\n...
code_stdio
[ { "content": "Moscow is hosting a major international conference, which is attended by n scientists from different countries. Each of the scientists knows exactly one language. For convenience, we enumerate all languages of the world with integers from 1 to 10^9.\n\nIn the evening after the conference, all n sc...
[{"input": "20\n2 2 1 6 6 5 10 3 5 4 4 8 6 8 8 10 2 1 5 6\n20\n1 9 1 1 5 1 9 10 1 10 9 9 8 7 5 1 1 10 2 7\n5 5 9 2 10 8 2 16 6 7 8 8 6 5 3 4 6 3 7 4\n", "output": "13\n"}, {"input": "20\n2 2 1 6 6 5 10 3 5 4 4 8 6 8 8 10 2 1 5 6\n20\n1 9 1 1 5 1 9 10 1 10 9 9 8 7 5 1 1 10 2 7\n5 5 9 2 10 8 2 16 5 7 8 8 6 5 3 4 6 3 7 4\...
code_stdio
[ { "content": "Problem\n\nAlice and Bob are competing in the 50m dash.\nHowever, in this world, the higher the AOJ rate is, the better, so the higher the AOJ rate wins.\nIf there is no AOJ rate on either side, there is no comparison, so there is no choice but to compete in the 50m sprint time. In this case, the ...
[{"input": "2 11 1010 1000", "output": "Alice\n"}, {"input": "2 11 1011 1000", "output": "Alice\n"}, {"input": "3 11 1011 1000", "output": "Alice\n"}, {"input": "3 11 1011 1001", "output": "Alice\n"}, {"input": "3 16 1001 0110", "output": "Alice\n"}, {"input": "3 11 1011 1011", "output": "Draw\n"}, {"input": "4 9 1001 ...
code_stdio
[ { "content": "Takahashi has two positive integers A and B.\n\nIt is known that A plus B equals N. Find the minimum possible value of \"the sum of the digits of A\" plus \"the sum of the digits of B\" (in base 10).\n\nConstraints\n\n* 2 ≤ N ≤ 10^5\n* N is an integer.\n\nInput\n\nInput is given from Standard Inpu...
[{"input": "100000", "output": "10"}, {"input": "1697", "output": "23\n"}, {"input": "199", "output": "19\n"}, {"input": "178", "output": "16\n"}, {"input": "389", "output": "20\n"}, {"input": "499", "output": "22\n"}, {"input": "789", "output": "24\n"}, {"input": "795", "output": "21\n"}, {"input": "989", "output": "2...
code_stdio
[ { "content": "Read problems statements in Mandarin Chinese and Russian as well. \n\n\tA version control system(VCS) is a repository of files, often the files for the source code of computer programs, with monitored access. Every change made to the source is tracked, along with who made the change, why they made...
[{"input": "2\n19 4 6\n1 4 6 7\n1 2 3 4 6 8\n12 2 2\n1 4\n1 4", "output": "3 12\n2 10\n"}, {"input": "2\n19 4 6\n1 4 6 7\n1 2 3 4 6 7\n12 2 2\n1 4\n1 4", "output": "4 13\n2 10\n"}, {"input": "2\n17 4 6\n1 3 6 11\n1 2 3 5 6 7\n5 2 2\n2 4\n3 4", "output": "3 10\n1 2\n"}, {"input": "2\n21 4 6\n2 3 6 14\n1 2 3 4 6 9\n4 2 2...
code_stdio
[ { "content": "You are given a huge decimal number consisting of $n$ digits. It is guaranteed that this number has no leading zeros. Each digit of this number is either 0 or 1.\n\nYou may perform several (possibly zero) operations with this number. During each operation you are allowed to change any digit of you...
[{"input": "213 5 3\n111001111110111001101011111100010010011001000001111010110110011000100000101010111110010001111110001010011001101000000011111110101001101100100100110100000111111100010100011010010001011100111011000001110000111000101\n", "output": "3\n"}, {"input": "213 5 3\n1110011111101110011010111111000100100110010...
code_stdio
[ { "content": "If you draw a few infinitely long straight lines on an infinitely wide plane, this plane will be divided into several areas. For example, if you draw a straight line, the plane will be divided into two areas. Even if you draw the same number of straight lines, the number of areas obtained will dif...
[{"input": "1\n705", "output": "2\n248866\n"}, {"input": "1\n506", "output": "2\n128272\n"}, {"input": "1\n154", "output": "2\n11936\n"}, {"input": "1\n238", "output": "2\n28442\n"}, {"input": "1\n373", "output": "2\n69752\n"}, {"input": "1\n155", "output": "2\n12091\n"}, {"input": "1\n159", "output": "2\n12721\n"}, {"...
code_stdio
[ { "content": "At 17:00, special agent Jack starts to escape from the enemy camp. There is a cliff in between the camp and the nearest safety zone. Jack has to climb the almost vertical cliff by stepping his feet on the blocks that cover the cliff. The cliff has slippery blocks where Jack has to spend time to ta...
[{"input": "6 6\n4 4 X X T T\n4 7 8 2 X 7\n1 X X X 1 8\n1 2 X X X 6\n1 1 2 4 4 7\nS S 2 3 X X\n2 10\nT 1\n1 X\n1 X\n1 X\n1 1\n1 X\n1 X\n1 1\n1 X\nS S\n2 10\nT X\n1 X\n1 X\n1 X\n1 1\n1 X\n1 X\n1 1\n1 X\nS S\n10 10\nT T T T T T T T T T\nX 2 X X X X X 3 4 X\n9 8 9 X X X 2 9 X 9\n7 7 X 7 3 X X 8 9 X\n8 9 9 9 6 3 X 5 X 5\n8...
code_stdio
[ { "content": "There are n positive integers a_1, a_2, ..., a_n. For the one move you can choose any even value c and divide by two all elements that equal c.\n\nFor example, if a=[6,8,12,6,3,12] and you choose c=6, and a is transformed into a=[3,8,12,3,3,12] after the move.\n\nYou need to find the minimal numbe...
[{"input": "4\n6\n37 6 40 3 20 1\n1\n1024\n4\n2 6 10 16\n3\n3 1 7\n", "output": "4\n10\n6\n0\n"}, {"input": "4\n6\n40 6 40 2 20 1\n1\n1024\n4\n2 4 8 16\n3\n3 1 14\n", "output": "5\n10\n4\n1\n"}, {"input": "4\n6\n37 6 79 3 20 1\n1\n1024\n4\n2 6 10 16\n1\n3 1 7\n", "output": "3\n10\n6\n0\n"}, {"input": "4\n6\n40 6 40 3 2...
code_stdio
[ { "content": "We have an H \\times W grid whose squares are painted black or white. The square at the i-th row from the top and the j-th column from the left is denoted as (i, j).\nSnuke would like to play the following game on this grid. At the beginning of the game, there is a character called Kenus at square...
[{"input": "10 37\n.....................................\n...#...####...####..###...###...###..\n..#.#..#...#.##....#...#.#...#.#...#.\n..#.#..#...#.#.....#...#.#...#.#...#.\n.#...#.#..##.#.....#...#.#.###.#.###.\n.#####.####..#.....#...#..##....##...\n.#...#.#...#.#.....#...#.#...#.#...#.\n.#...#.#...#.##....#...#.#.....
code_stdio
[ { "content": "The official capital and the cultural capital of Berland are connected by a single road running through n regions. Each region has a unique climate, so the i-th (1 ≤ i ≤ n) region has a stable temperature of ti degrees in summer.\n\nThis summer a group of m schoolchildren wants to get from the off...
[{"input": "20 102\n73 79 75 27\n13 15 62 47\n74 75 85 86\n49 81 23 69\n43 17 45 27\n35 14 90 35\n51 74 35 33\n54 66 46 24\n33 76 49 3\n34 53 25 76\n69 72 76 31\n41 31 8 48\n49 48 85 24\n19 2 59 83\n19 31 51 86\n31 10 45 76\n56 47 79 86\n49 33 15 1\n77 89 26 64\n7 52 76 77\n", "output": "59201\n"}, {"input": "20 102\n7...
code_stdio
[ { "content": "Nezzar has $n$ balls, numbered with integers $1, 2, \\ldots, n$. Numbers $a_1, a_2, \\ldots, a_n$ are written on them, respectively. Numbers on those balls form a non-decreasing sequence, which means that $a_i \\leq a_{i+1}$ for all $1 \\leq i < n$.\n\nNezzar wants to color the balls using the min...
[{"input": "5\n6\n1 1 1 2 3 4\n5\n1 1 2 2 3\n4\n2 2 2 2\n3\n1 2 3\n1\n1\n", "output": "\n3\n2\n4\n1\n1\n"}, {"input": "5\n6\n1 1 1 2 3 4\n5\n1 1 2 2 3\n4\n2 2 2 2\n3\n1 2 3\n1\n1\n", "output": "3\n2\n4\n1\n1\n"}, {"input": "5\n6\n1 1 1 2 3 4\n5\n1 1 2 2 3\n4\n2 2 2 2\n3\n2 2 3\n1\n1\n", "output": "3\n2\n4\n2\n1\n"}, {"...
code_stdio
[ { "content": "We, the researchers who discovered and investigated the ancient nation Iwashiro, finally discovered the temple in the center of Iwashiro. A lithograph dedicated to the god of Iwashiro was stored in the temple. On the lithograph, two strings were written, one for each sentence and one for the spell...
[{"input": "aaaabaaaabaaaabaaaab\naabaa", "output": "1576\n"}, {"input": "aaaabaaaabaa`abaaaab\naabaa", "output": "1248\n"}, {"input": "aaaabaaaabaa`ababaaa\naabaa", "output": "1446\n"}, {"input": "aaaabaaaabaaaabaaaab\nbaaaa", "output": "566\n"}, {"input": "aa`abbbaaaaa``bababa\na`bab", "output": "180\n"}, {"input": "...
code_stdio
[ { "content": "Boolean Expression Compressor\n\nYou are asked to build a compressor for Boolean expressions that transforms expressions to the shortest form keeping their meaning.\n\nThe grammar of the Boolean expressions has terminals `0` `1` `a` `b` `c` `d` `-` `^` `*` `(` `)`, start symbol <E> and the followi...
[{"input": "0\n(a*(0*b))\n(1^a)\n(-(-a*-b)*a)\n(a^(b^(c^d)))\n.", "output": "1\n1\n2\n1\n13\n"}, {"input": "0\n(a*(1*b))\n(1^b)\n(-(-a*-b)*a)\n(a^(b^(c^d)))\n.", "output": "1\n5\n2\n1\n13\n"}, {"input": "0\n(a*(1*b))\n(0^a)\n(-(-b*-c)*a)\nca^(b^((^e)))\n.", "output": "1\n5\n1\n12\n1\n"}, {"input": "0\n(a*(1*c))\n(1^a)\...
code_stdio
[ { "content": "Snuke is visiting a shop in Tokyo called 109 to buy some logs.\nHe wants n logs: one of length 1, one of length 2, ..., and one of length n.\nThe shop has n+1 logs in stock: one of length 1, one of length 2, \\dots, and one of length n+1. Each of these logs is sold for 1 yen (the currency of Japan...
[{"input": "1000000000000000000\n", "output": "999999998585786440\n"}, {"input": "109109109109109109\n", "output": "109109108641970782\n"}, {"input": "252509054433933446\n", "output": "252509053723287187\n"}, {"input": "335408917861648771\n", "output": "335408917042614075\n"}, {"input": "522842184971407774\n", "output"...
code_stdio
[ { "content": "You are given a string $s$ consisting of $n$ lowercase Latin letters.\n\nYou have to remove at most one (i.e. zero or one) character of this string in such a way that the string you obtain will be lexicographically smallest among all strings that can be obtained using this operation.\n\nString $s ...
[{"input": "26\nlolthisiscoolfreehackforya\n", "output": "llthisiscoolfreehackforya\n"}, {"input": "26\nlolthisiscoolfreehackforya\n", "output": "llthisiscoolfreehackforya\n"}, {"input": "26\nlolthisiscoolfrfehackforya\n", "output": "llthisiscoolfrfehackforya\n"}, {"input": "26\nayrofkcahefrfloocsisihtlol\n", "output":...
code_stdio
[ { "content": "Some positive integers can be represented by a sum of one or more consecutive prime numbers. How many such representations does a given positive integer have? For example, the integer 53 has two representations 5 + 7 + 11 + 13 + 17 and 53. The integer 41 has three representations 2 + 3 + 5 + 7 + 1...
[{"input": "2\n6\n17\n34\n20\n1266\n24\n20\n0", "output": "1\n0\n2\n0\n0\n1\n1\n0\n"}, {"input": "2\n3\n17\n41\n20\n666\n24\n53\n0", "output": "1\n1\n2\n3\n0\n0\n1\n2\n"}, {"input": "2\n3\n17\n41\n20\n666\n24\n56\n0", "output": "1\n1\n2\n3\n0\n0\n1\n1\n"}, {"input": "2\n3\n17\n41\n20\n666\n24\n20\n0", "output": "1\n1\n...
code_stdio
[ { "content": "Omkar is playing his favorite pixelated video game, Bed Wars! In Bed Wars, there are $n$ players arranged in a circle, so that for all $j$ such that $2 \\leq j \\leq n$, player $j - 1$ is to the left of the player $j$, and player $j$ is to the right of player $j - 1$. Additionally, player $n$ is t...
[{"input": "5\n4\nRLRL\n6\nLRRRRL\n8\nRLLRRRLL\n12\nLLLLRRLRRRLL\n5\nRRRRR\n", "output": "0\n1\n1\n3\n2\n"}, {"input": "5\n4\nRLRL\n6\nLRRRRL\n8\nRLLRRRLL\n12\nLLRRRLRRLLLL\n5\nRRRRR\n", "output": "0\n1\n1\n3\n2\n"}, {"input": "5\n4\nRLRL\n6\nRRRLRL\n8\nRLLRRRLL\n12\nLLLLRRLRLRRL\n5\nRRRRR\n", "output": "0\n1\n1\n1\n2\...
code_stdio
[ { "content": "Notice that the memory limit is non-standard.\n\nRecently Arthur and Sasha have studied correct bracket sequences. Arthur understood this topic perfectly and become so amazed about correct bracket sequences, so he even got himself a favorite correct bracket sequence of length 2n. Unlike Arthur, Sa...
[{"input": "50\n97 97\n61 61\n59 59\n29 29\n13 13\n7 7\n5 5\n3 3\n1 1\n3 3\n1 1\n13 13\n11 11\n9 9\n3 3\n1 1\n1 1\n1 1\n27 27\n25 25\n1 1\n21 21\n19 19\n17 17\n15 15\n5 5\n1 1\n1 1\n7 7\n1 1\n3 3\n1 1\n15 15\n13 13\n1 1\n9 9\n7 7\n5 5\n3 3\n1 1\n15 15\n5 5\n1 1\n1 1\n3 3\n1 1\n1 1\n1 1\n1 1\n1 1\n", "output": "((((((((...
code_stdio
[ { "content": "Wherever the destination is, whoever we meet, let's render this song together.\n\nOn a Cartesian coordinate plane lies a rectangular stage of size w × h, represented by a rectangle with corners (0, 0), (w, 0), (w, h) and (0, h). It can be seen that no collisions will happen before one enters the s...
[{"input": "20 50000 50000\n2 45955 55488\n1 19804 29337\n2 3767 90811\n2 24025 33558\n1 46985 56518\n2 21094 30627\n2 5787 15320\n1 4262 91306\n2 37231 46764\n1 18125 27658\n1 36532 12317\n1 31330 40863\n1 18992 28525\n1 29387 38920\n1 44654 54187\n2 45485 55018\n2 36850 46383\n1 44649 54182\n1 40922 50455\n2 12781 99...
code_stdio
[ { "content": "We ask you to select some number of positive integers, and calculate the sum of them.\nIt is allowed to select as many integers as you like, and as large integers as you wish.\nYou have to follow these, however: each selected integer needs to be a multiple of A, and you need to select at least one...
[{"input": "103 135 85", "output": "YES\n"}, {"input": "1 100 97\n", "output": "YES\n"}, {"input": "40 98 58\n", "output": "YES\n"}, {"input": "103 98 58", "output": "YES\n"}, {"input": "103 98 87", "output": "YES\n"}, {"input": "103 77 58", "output": "YES\n"}, {"input": "103 98 85", "output": "YES\n"}, {"input": "117 ...
code_stdio
[ { "content": "Given an integer N, let us consider a triangle of numbers of N lines in which a number a_{11} appears in the first line, two numbers a_{21} and a_{22} appear in the second line, three numbers a_{31}, a_{32} and a_{33} appear in the third line, etc. In general, i numbers a_{i1}, a_{i2} \\dots a_{ii...
[{"input": "2\n3\n1\n8 1\n41 4 3\n4 \n5 \n-1 0 \n2 -4 0\n3 0 12 -1", "output": "50\n17\n"}, {"input": "2\n3\n1\n4 2\n28 4 1\n4 \n4 \n1 0 \n5 -1 -1\n3 0 2 -1", "output": "33\n13\n"}, {"input": "2\n3\n1\n4 2\n28 4 2\n4 \n4 \n1 0 \n2 -1 -1\n3 0 4 -1", "output": "33\n10\n"}, {"input": "2\n3\n1\n8 1\n41 4 3\n4 \n14 \n0 0 \n...
code_stdio
[ { "content": "Students Vasya and Petya are studying at the BSU (Byteland State University). At one of the breaks they decided to order a pizza. In this problem pizza is a circle of some radius. The pizza was delivered already cut into n pieces. The i-th piece is a sector of angle equal to a_{i}. Vasya and Petya...
[{"input": "222\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1...
code_stdio
[ { "content": "One day, the teacher came up with the following game.\nThe game uses n cards with one number from 1 to 10 and proceeds as follows.\n\n\n1. The teacher pastes n cards on the blackboard in a horizontal row so that the numbers can be seen, and declares an integer k (k ≥ 1) to the students. For n card...
[{"input": "4 3\n15\n3\n16\n5\n0 0", "output": "480\n"}, {"input": "4 3\n12\n3\n16\n5\n0 0", "output": "384\n"}, {"input": "4 3\n8\n3\n16\n5\n0 0", "output": "256\n"}, {"input": "4 2\n8\n3\n10\n5\n0 0", "output": "30\n"}, {"input": "4 2\n4\n1\n14\n3\n0 0", "output": "14\n"}, {"input": "4 2\n8\n3\n16\n5\n0 0", "output":...
code_stdio
[ { "content": "You are visiting a large electronics store to buy a refrigerator and a microwave.\n\nThe store sells A kinds of refrigerators and B kinds of microwaves. The i-th refrigerator ( 1 \\le i \\le A ) is sold at a_i yen (the currency of Japan), and the j-th microwave ( 1 \\le j \\le B ) is sold at b_j y...
[{"input": "5 5 0\n-10 0\n12 10 -2\n-1 2 1", "output": "-12\n"}, {"input": "2 10 0\n-5 -1\n13 10 -1\n0 2 7", "output": "-6\n"}, {"input": "3 10 -1\n-5 0\n11 10 -2\n0 2 1", "output": "-7\n"}, {"input": "5 10 0\n-6 0\n12 10 -2\n-1 2 1", "output": "-8\n"}, {"input": "5 5 0\n-8 0\n12 10 -2\n-1 2 1", "output": "-10\n"}, {"i...
code_stdio
[ { "content": "Hands that shed innocent blood!\n\nThere are n guilty people in a line, the i-th of them holds a claw with length L_{i}. The bell rings and every person kills some of people in front of him. All people kill others at the same time. Namely, the i-th person kills the j-th person if and only if j < i...
[{"input": "11\n1 0 0 1 1 3 2 0 0 2 3\n", "output": "4\n"}, {"input": "11\n1 0 0 1 1 3 2 0 0 2 3\n", "output": "4\n"}, {"input": "11\n1 0 0 1 0 3 2 0 0 2 3\n", "output": "4\n"}, {"input": "11\n1 0 0 1 0 3 2 0 0 2 2\n", "output": "4\n"}, {"input": "2\n1000000000 1000000000\n", "output": "1\n"}, {"input": "2\n1000000000 ...
code_stdio
[ { "content": "Snuke and Raccoon have a heap of N cards. The i-th card from the top has the integer a_i written on it.\nThey will share these cards.\nFirst, Snuke will take some number of cards from the top of the heap, then Raccoon will take all the remaining cards.\nHere, both Snuke and Raccoon have to take at...
[{"input": "6\n1 30 1 10 -1 6", "output": "15\n"}, {"input": "6\n1 36 1 10 -1 6", "output": "21\n"}, {"input": "6\n1 36 1 10 -1 1", "output": "26\n"}, {"input": "6\n0 3 3 7 1 24", "output": "10\n"}, {"input": "6\n-1 10 3 3 1 8", "output": "0\n"}, {"input": "6\n-1 10 3 3 1 4", "output": "2\n"}, {"input": "6\n-1 15 3 3 1...
code_stdio