messages
listlengths
1
1
ground_truth
stringlengths
156
726k
dataset
stringclasses
1 value
[ { "content": "Your search for Heidi is over – you finally found her at a library, dressed up as a human. In fact, she has spent so much time there that she now runs the place! Her job is to buy books and keep them at the library so that people can borrow and read them. There are n different books, numbered 1 th...
[{"input": "80 4\n71 49 41 21 72 71 37 14 51 59 73 11 70 15 36 46 32 57 58 15 72 67 16 75 70 11 67 3 40 36 2 9 63 68 32 22 63 52 67 55 35 19 72 59 22 19 44 55 59 74 4 34 53 3 22 57 32 27 78 12 71 4 26 15 43 21 79 10 67 39 34 74 38 26 31 78 2 78 69 42\n", "output": "62\n"}, {"input": "80 4\n71 49 41 21 72 71 37 14 51 59...
code_stdio
[ { "content": "The robot is placed in the top left corner of a grid, consisting of $n$ rows and $m$ columns, in a cell $(1, 1)$.\n\nIn one step, it can move into a cell, adjacent by a side to the current one:\n\n$(x, y) \\rightarrow (x, y + 1)$;\n\n$(x, y) \\rightarrow (x + 1, y)$;\n\n$(x, y) \\rightarrow (x, y ...
[{"input": "3\n2 3 1 3 0\n2 3 1 3 1\n5 5 3 4 1\n", "output": "3\n-1\n8\n"}, {"input": "2\n3 5 2 3 1\n5 3 3 2 1\n", "output": "-1\n-1\n"}, {"input": "2\n2 3 1 3 0\n2 3 1 3 1\n", "output": "3\n-1\n"}, {"input": "2\n3 3 2 2 1\n5 5 3 3 1\n", "output": "-1\n8\n"}, {"input": "1\n972 439 242 299 296\n", "output": "1409\n"}, {...
code_stdio
[ { "content": "Harry Water, Ronaldo, Her-my-oh-knee and their friends have started a new school year at their MDCS School of Speechcraft and Misery. At the time, they are very happy to have seen each other after a long time. The sun is shining, birds are singing, flowers are blooming, and their Potions class tea...
[{"input": "2\n10\n10\n", "output": "200\n"}, {"input": "2\n19\n10\n", "output": "380\n"}, {"input": "2\n4\n18\n", "output": "144\n"}, {"input": "2\n6\n18\n", "output": "216\n"}, {"input": "2\n6\n23\n", "output": "276\n"}, {"input": "2\n6\n30\n", "output": "360\n"}, {"input": "2\n6\n39\n", "output": "468\n"}, {"input":...
code_stdio
[ { "content": "It is nighttime and Joe the Elusive got into the country's main bank's safe. The safe has n cells positioned in a row, each of them contains some amount of diamonds. Let's make the problem more comfortable to work with and mark the cells with positive numbers from 1 to n from the left to the right...
[{"input": "95 97575868 5\n4612 1644 3613 5413 5649 2419 5416 3926 4610 4419 2796 5062 2112 1071 3790 4220 3955 2142 4638 2832 2702 2115 2045 4085 3599 2452 5495 4767 1368 2344 4625 4132 5755 5815 2581 6259 1330 4938 815 5430 1628 3108 4342 3692 2928 1941 3714 4498 4471 4842 1822 867 3395 2587 3372 6394 6423 3728 3720 ...
code_stdio
[ { "content": "There are three airports A, B and C, and flights between each pair of airports in both directions.\nA one-way flight between airports A and B takes P hours, a one-way flight between airports B and C takes Q hours, and a one-way flight between airports C and A takes R hours.\nConsider a route where...
[{"input": "001 -13 -101", "output": "-114\n"}, {"input": "100 100 100\n", "output": "200\n"}, {"input": "111 -117 -5", "output": "-122\n"}, {"input": "011 -5 -101", "output": "-106\n"}, {"input": "000 -93 -7", "output": "-100\n"}, {"input": "010 -10 -10", "output": "-20\n"}, {"input": "010 -10 -18", "output": "-28\n"}...
code_stdio
[ { "content": "The Metropolis computer network consists of n servers, each has an encryption key in the range from 0 to 2^k - 1 assigned to it. Let c_i be the encryption key assigned to the i-th server. Additionally, m pairs of servers are directly connected via a data communication channel. Because of the encry...
[{"input": "10 40 10\n838 215 738 782 183 422 127 283 103 129\n1 2\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n2 9\n2 10\n3 3\n3 5\n3 6\n3 7\n3 8\n3 9\n3 10\n4 5\n4 6\n4 7\n4 9\n4 10\n5 7\n5 8\n5 9\n5 10\n6 7\n6 8\n6 9\n6 10\n7 9\n7 10\n8 10\n9 10\n", "output": "1028608\n"}, {"input": "10 40 10\n...
code_stdio
[ { "content": "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.\n\nHowever, one day, the members somehow entered the sequence into the document at the same time, creating a jumbled mess. Therefore, it is Sugu...
[{"input": "5\n3\nTMT\n3\nTMT\n6\nTMTMTT\n6\nTMTTTT\n6\nTTMMTT\n", "output": "YES\nYES\nYES\nNO\nYES\n"}, {"input": "5\n3\nTMT\n3\nMTT\n6\nTMTMTT\n6\nTMTTTT\n6\nTTMMTT\n", "output": "\nYES\nNO\nYES\nNO\nYES\n"}, {"input": "5\n3\nTMT\n3\nMTT\n6\nTMTMTT\n6\nTMTTTT\n6\nTTMMTT\n", "output": "YES\nNO\nYES\nNO\nYES\n"}, {"in...
code_stdio
[ { "content": "Yaroslav has an array, consisting of (2·n - 1) integers. In a single operation Yaroslav can change the sign of exactly n elements in the array. In other words, in one operation Yaroslav can select exactly n array elements, and multiply each of them by -1.\n\nYaroslav is now wondering: what maximum...
[{"input": "56\n-157 136 457 598 -138 -586 -338 752 -566 -718 -333 -965 309 -125 -938 -188 -390 17 -75 -902 -320 163 820 -970 -525 -329 81 488 -412 978 138 344 305 -358 -273 -967 253 -665 -245 187 602 252 -825 -511 828 764 -402 278 995 541 542 549 612 -536 527 -884 225 800 160 -409 -926 -795 -321 -791 981 812 599 381 7...
code_stdio
[ { "content": "There are $n$ people who want to participate in a boat competition. The weight of the $i$-th participant is $w_i$. Only teams consisting of two people can participate in this competition. As an organizer, you think that it's fair to allow only teams with the same total weight.\n\nSo, if there are ...
[{"input": "4\n14\n2 6 5 9 5 8 13 14 12 5 6 14 5 2\n36\n15 22 27 14 23 36 10 17 33 21 18 22 3 4 32 24 8 19 36 22 17 11 24 10 33 4 30 6 2 17 11 16 18 1 2 20\n2\n2 2\n12\n4 9 10 6 1 9 5 8 12 9 9 12\n", "output": "3\n11\n1\n4\n"}, {"input": "4\n14\n2 6 5 9 5 8 13 14 12 5 6 14 5 2\n36\n15 22 27 14 23 36 10 17 33 21 18 22 3...
code_stdio
[ { "content": "Alice has a string $s$. She really likes the letter \"a\". She calls a string good if strictly more than half of the characters in that string are \"a\"s. For example \"aaabb\", \"axaa\" are good strings, and \"baca\", \"awwwa\", \"\" (empty string) are not.\n\nAlice can erase some characters from...
[{"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n", "output": "50\n"}, {"input": "ababababababababababababababababababababababababav\n", "output": "49\n"}, {"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n", "output": "50\n"}, {"input": "ababababababababababababababababababababababababav\n"...
code_stdio
[ { "content": "You are given a multiset of n integers. You should select exactly k of them in a such way that the difference between any two of them is divisible by m, or tell that it is impossible.\n\nNumbers can be repeated in the original multiset and in the multiset of selected numbers, but number of occurre...
[{"input": "108 29 72\n738 192 711 235 288 288 679 36 785 233 706 71 216 144 216 1419 338 583 495 648 144 432 72 720 541 288 158 328 154 393 10 533 867 176 707 216 314 397 440 142 326 458 568 701 745 144 61 634 520 720 744 144 409 127 526 476 101 469 72 432 738 432 235 641 695 276 144 144 231 555 630 9 109 319 437 288 ...
code_stdio
[ { "content": "There is a plane like Figure 1 with 8 vertical and 8 horizontal squares. There are several bombs on that plane. Figure 2 shows an example (● = bomb).\n\n| □ | □ | □ | □ | □ | □ | □ | □\n--- | --- | --- | --- | --- | --- | --- | ---\n□ | □ | □ | □ | □ | □ | □ | □\n□ | □ | □ | □ | □ | □ | □ | □\n□ |...
[{"input": "2\n\n00010010\n00000100\n10001001\n00100010\n01000000\n00001000\n10100010\n01010010\n2\n5\n\n00010010\n00000100\n10001001\n00100010\n01000000\n00001000\n10100000\n01010010\n2\n5", "output": "Data 1:\n00000000\n00000100\n10001001\n00100000\n00000000\n00001000\n10100000\n00000000\nData 2:\n00010010\n00000100\...
code_stdio
[ { "content": "I decided to play rock-paper-scissors with a group of five good friends. Rock-paper-scissors has three hands: goo, choki, and par. If the game between goo and choki is a match between goo and choki, goo is \"winning\" and choki is \"losing\". , Par and Goo have the rule that Par is \"winning\" and...
[{"input": "1\n3\n3\n2\n1\n1\n2\n2\n2\n1\n0", "output": "3\n3\n3\n3\n3\n1\n2\n2\n2\n1\n"}, {"input": "1\n1\n1\n2\n1\n1\n2\n2\n2\n1\n0", "output": "1\n1\n1\n2\n1\n1\n2\n2\n2\n1\n"}, {"input": "1\n2\n3\n2\n1\n1\n1\n2\n2\n1\n0", "output": "3\n3\n3\n3\n3\n1\n1\n2\n2\n1\n"}, {"input": "1\n2\n2\n2\n1\n1\n1\n2\n2\n1\n0", "out...
code_stdio
[ { "content": "You want to go on a trip with a friend. However, friends who have a habit of spending money cannot easily save travel expenses. I don't know when my friends will go on a trip if they continue their current lives. So, if you want to travel early, you decide to create a program to help your friends ...
[{"input": "10000\n1225 3150\n861 12737\n0 -1\n5000 1050\n5000 4211\n5000 412\n5000 5000\n5000 5000\n-1 -1\n5075 1951\n9143 2494\n5000 2100\n29170\n100000 000000\n100010 110000\n100000 100000\n100000 100000\n100100 100100\n100000 111000\n100000 100000\n101000 100000\n100000 100010\n100000 100000\n100000 000000\n100000 ...
code_stdio
[ { "content": "Recently, Norge found a string $s = s_1 s_2 \\ldots s_n$ consisting of $n$ lowercase Latin letters. As an exercise to improve his typing speed, he decided to type all substrings of the string $s$. Yes, all $\\frac{n (n + 1)}{2}$ of them!\n\nA substring of $s$ is a non-empty string $x = s[a \\ldots...
[{"input": "200 13\nvgfjhgkgwkftaeqejmbgildembgxdbskxfndwmcckjfkbeekxkgakmcjhclqsecpnkaigcxxhfghgegfadjktckftdhtifriemfifakygoesjfginnddjjklwiwlbjsgftwhtjdxmcadpvhaeddxwnmguwhetwbmffbmvdvuhecgjckddrbikgwkrfwfhdhqolidgkfm\na b c d e f g h i j k l m\n", "output": "578\n"}, {"input": "200 13\nvgfjhgkgwkftaeqejmbgildembgxd...
code_stdio
[ { "content": "For his computer science class, Jacob builds a model tree with sticks and balls containing n nodes in the shape of a tree. Jacob has spent ai minutes building the i-th ball in the tree.\n\nJacob's teacher will evaluate his model and grade Jacob based on the effort he has put in. However, she does ...
[{"input": "10 3\n703660 186846 317819 628672 131569 58472 247014 480113 252764 860936\n10 6\n7 4\n10 9\n9 5\n6 3\n6 2\n10 1\n10 7\n10 8\n", "output": "480113\n"}, {"input": "10 3\n703660 186846 317819 1004549 74457 58472 247014 480113 252764 1263340\n10 6\n7 4\n10 9\n9 5\n9 3\n6 2\n7 1\n10 7\n10 8\n", "output": "25276...
code_stdio
[ { "content": "Lord Omkar has permitted you to enter the Holy Church of Omkar! To test your worthiness, Omkar gives you a password which you must interpret!\n\nA password is an array $a$ of $n$ positive integers. You apply the following operation to the array: pick any two adjacent numbers that are not equal to ...
[{"input": "80\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\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...
code_stdio
[ { "content": "As Famil Door’s birthday is coming, some of his friends (like Gabi) decided to buy a present for him. His friends are going to buy a string consisted of round brackets since Famil Door loves string of brackets of length n more than any other strings!\n\nThe sequence of round brackets is called val...
[{"input": "1980 464\n))(()()))(((((((((()))))))(()(((()((()))()()())()))()))(()))))))(())((())))()())()((())())()())))(())()(()))(()())()((((()))())()(())))))(()()(()(((((()(()()))(((()))(())))))()())(())))))())()()((())))))))((()(())))))()()(()((()((()()))(()))(())(()))()((((())()()))))))()(())))()(()())()())(((((())...
code_stdio
[ { "content": "The \"BerCorp\" company has got n employees. These employees can use m approved official languages for the formal correspondence. The languages are numbered with integers from 1 to m. For each employee we have the list of languages, which he knows. This list could be empty, i. e. an employee may k...
[{"input": "100 100\n1 33\n0\n2 35 4\n2 40 78\n1 69\n0\n1 2\n0\n0\n2 81 34\n1 45\n0\n1 87\n1 50\n1 97\n0\n2 100 59\n0\n0\n0\n1 45\n0\n0\n0\n1 6\n1 54\n0\n0\n0\n4 79 96 52 84\n1 86\n0\n0\n0\n0\n0\n0\n0\n0\n3 90 2 80\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n1 2\n0\n1 64\n0\n1 78\n1 82\n0\n0\n0\n0\n0\n1 6\n0\n0\n2 47 57\n1 95\n0\n2...
code_stdio
[ { "content": "The classic programming language of Bitland is Bit++. This language is so peculiar and complicated.\n\nThe language is that peculiar as it has exactly one variable, called x. Also, there are two operations:\n\n Operation ++ increases the value of variable x by 1. Operation -- decreases the value...
[{"input": "101\nX++\nX++\nX++\n++X\n--X\nX--\nX++\nX--\nX--\n--X\n--X\n++X\nX++\n++X\n++X\nX--\n--X\n++X\nX++\nX--\n++X\n--X\n--X\n--X\n++X\n--X\n++X\nX++\nX++\n++X\n--X\nX++\nX--\nX++\n++X\n++X\nX--\nX--\nX--\nX++\nX++\nX--\nX--\nX++\n++X\n++X\n++X\n--X\n--X\n++X\nX--\nX--\n--X\n++X\nX--\n++X\nX++\n++X\nX--\nX--\n--X...
code_stdio
[ { "content": "This is the story of 20XX. The number of air passengers increased as a result of the stable energy supply by the renewable power network and the invention of liquefied synthetic fuel. However, the threat of terrorism by aircraft still exists, and the importance of fast and highly reliable automati...
[{"input": "6\n1 1\n.\n3 3\n...\n.W.\n...\n10 10\n..........\n.DDDDCCC..\n.DDDDCCC..\n.DDDDCCC..\nADDDDCCC..\nAAA..CCC..\n..CBBBBAAA\nAAABBBB...\n..BBBBB...\n..........\n10 10\n..........\n.DDDDDD...\n.DDDDCCC..\n.DDDDCCC..\nADDDDCCC..\nAAA.-CCC..\nAAABBBBC..\nAAABBBB...\n..BBBBB...\n..........\n10 10\nR..E..C.T.\nR.EE...
code_stdio
[ { "content": "Problem F Pizza Delivery\n\nAlyssa is a college student, living in New Tsukuba City. All the streets in the city are one-way. A new social experiment starting tomorrow is on alternative traffic regulation reversing the one-way directions of street sections. Reversals will be on one single street s...
[{"input": "4 5\n1 3 7\n4 2 6\n4 3 0\n2 1 34\n3 3 12", "output": "SOSO\nSOSO\nHAPPY\nHAPPY\nSOSO\n"}, {"input": "4 5\n1 1 5\n3 4 6\n4 2 13\n2 1 6\n2 3 17", "output": "SOSO\nSOSO\nSOSO\nHAPPY\nSOSO\n"}, {"input": "4 5\n1 3 5\n3 4 6\n2 2 7\n2 1 1\n2 3 17", "output": "SOSO\nSOSO\nSOSO\nHAPPY\nHAPPY\n"}, {"input": "4 5\n1 ...
code_stdio
[ { "content": "Billy investigates the question of applying greedy algorithm to different spheres of life. At the moment he is studying the application of greedy algorithm to the problem about change. There is an amount of n coins of different face values, and the coins of each value are not limited in number. Th...
[{"input": "91\n4000000 3000000 2900000 2511334 2511333 2102003 1901011 1700000 1200000 999999 800000 750000 600000 508111 202000 101000 35000 20000 9000 5000 2000 899 630 629 628 627 626 625 624 623 622 621 620 619 618 617 616 615 614 613 612 611 610 609 608 607 606 605 604 603 602 601 504 405 404 403 402 401 305 304 ...
code_stdio
[ { "content": "The new camp by widely-known over the country Spring Programming Camp is going to start soon. Hence, all the team of friendly curators and teachers started composing the camp's schedule. After some continuous discussion, they came up with a schedule s, which can be represented as a binary string, ...
[{"input": "01010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101...
code_stdio
[ { "content": "This problem is a simplified version of D2, but it has significant differences, so read the whole statement.\n\nPolycarp has an array of $n$ ($n$ is even) integers $a_1, a_2, \\dots, a_n$. Polycarp conceived of a positive integer $k$. After that, Polycarp began performing the following operations ...
[{"input": "10\n10\n25 25 7 61 97 -47 43 7 -11 -29\n10\n44 -10 -10 -64 -64 98 -64 62 -10 -64\n10\n20 50 65 35 65 -40 50 20 -55 -10\n10\n7 -91 -77 -91 -21 7 77 35 21 -7\n10\n56 -76 78 12 -54 -43 23 1 -65 45\n10\n-68 12 -88 -48 52 -8 -28 -8 92 -88\n10\n55 -2 -2 74 36 -59 -59 55 36 -78\n10\n70 -66 -76 71 3 44 96 -78 50 -5...
code_stdio
[ { "content": "Bob is playing a game of Spaceship Solitaire. The goal of this game is to build a spaceship. In order to do this, he first needs to accumulate enough resources for the construction. There are $n$ types of resources, numbered $1$ through $n$. Bob needs at least $a_i$ pieces of the $i$-th resource t...
[{"input": "2\n4 4\n9\n1 1 1\n1 2 1\n1 3 1\n2 1 2\n2 2 2\n2 3 2\n2 3 1\n2 2 1\n2 1 1\n", "output": "7\n6\n5\n4\n3\n2\n2\n3\n4\n"}, {"input": "2\n4 4\n9\n1 1 1\n1 2 1\n1 3 1\n2 1 2\n2 2 2\n2 3 2\n2 3 1\n2 2 1\n2 1 1\n", "output": "7\n6\n5\n4\n3\n2\n2\n3\n4\n"}, {"input": "2\n4 4\n9\n1 1 1\n2 2 1\n1 3 1\n2 1 2\n2 2 2\n2 ...
code_stdio
[ { "content": "There are several colored cubes. All of them are of the same size but they may be colored differently. Each face of these cubes has a single color. Colors of distinct faces of a cube may or may not be the same.\n\nTwo cubes are said to be identically colored if some suitable rotations of one of th...
[{"input": "3\nscarlet green blue yellow magenta cyan\nblue pink green magenta cyan lemon\npurple red blue yellow cyan green\n2\nred green blue yellow magenta cyan\ncyan green blue yellow magenta red\n2\nred green gray gray magenta cyan\ncyan green gray fray magenta red\n2\nred green blue yellow magenta cyan\nmagenta r...
code_stdio
[ { "content": "John Smith knows that his son, Thomas Smith, is among the best students in his class and even in his school. After the students of the school took the exams in English, German, Math, and History, a table of results was formed.\n\nThere are $n$ students, each of them has a unique id (from $1$ to $n...
[{"input": "18\n68 32 84 6\n44 53 11 21\n61 34 77 82\n19 36 47 58\n47 73 31 96\n17 50 82 16\n57 90 64 8\n14 37 45 69\n48 1 18 58\n42 34 96 14\n56 82 33 77\n40 66 30 53\n33 31 44 95\n0 90 24 8\n7 85 39 1\n76 77 93 35\n98 9 62 13\n24 84 60 51\n", "output": "8\n"}, {"input": "18\n68 32 84 6\n44 53 11 21\n61 34 77 82\n19 3...
code_stdio
[ { "content": "There are $n$ shovels in the nearby shop. The $i$-th shovel costs $a_i$ bourles.\n\nMisha has to buy exactly $k$ shovels. Each shovel can be bought no more than once.\n\nMisha can buy shovels by several purchases. During one purchase he can choose any subset of remaining (non-bought) shovels and b...
[{"input": "9 4 8\n12 13 5 1 12 1 2 2 2\n9 4\n8 4\n5 3\n9 7\n", "output": "28\n"}, {"input": "9 4 8\n6 13 5 1 10 1 1 2 1\n9 4\n8 4\n5 3\n9 7\n", "output": "19\n"}, {"input": "9 4 8\n6 13 5 1 12 1 1 2 2\n9 4\n8 4\n5 3\n9 5\n", "output": "21\n"}, {"input": "9 4 8\n6 13 5 1 12 1 2 2 2\n9 4\n8 4\n5 3\n9 5\n", "output": "22...
code_stdio
[ { "content": "You are given a matrix with $n$ rows (numbered from $1$ to $n$) and $m$ columns (numbered from $1$ to $m$). A number $a_{i, j}$ is written in the cell belonging to the $i$-th row and the $j$-th column, each number is either $0$ or $1$.\n\nA chip is initially in the cell $(1, 1)$, and it will be mo...
[{"input": "4\n2 2\n1 1\n0 1\n2 3\n1 1 0\n1 0 0\n3 7\n1 0 1 1 1 1 1\n0 0 0 0 0 0 0\n1 0 1 1 1 0 1\n2 5\n1 0 1 0 0\n1 1 1 1 0\n-1 1 1 0 0\n", "output": "0\n3\n5\n4\n"}, {"input": "4\n2 2\n1 1\n0 1\n2 3\n1 1 1\n1 0 0\n3 7\n1 0 1 1 1 1 1\n0 0 1 0 0 1 0\n1 0 1 0 1 0 1\n2 5\n1 0 1 0 0\n1 1 1 1 0\n-1 1 2 0 0\n", "output": "0...
code_stdio
[ { "content": "Salem gave you $n$ sticks with integer positive lengths $a_1, a_2, \\ldots, a_n$.\n\nFor every stick, you can change its length to any other positive integer length (that is, either shrink or stretch it). The cost of changing the stick's length from $a$ to $b$ is $|a - b|$, where $|x|$ means the a...
[{"input": "113\n86 67 31 33 72 100 88 63 16 12 79 80 76 45 31 96 44 10 24 33 53 11 56 100 23 57 9 48 28 73 18 48 12 89 73 9 51 11 82 94 90 92 34 99 54 58 33 67 35 87 58 90 94 64 57 80 87 99 84 99 20 1 63 12 16 40 50 95 33 58 7 23 71 89 53 15 95 29 71 16 65 21 66 89 82 30 6 45 6 66 58 32 27 78 28 42 8 61 10 26 7 55 76 ...
code_stdio
[ { "content": "Emergency Evacuation\n\nThe Japanese government plans to increase the number of inbound tourists to forty million in the year 2020, and sixty million in 2030. Not only increasing touristic appeal but also developing tourism infrastructure further is indispensable to accomplish such numbers.\n\nOne...
[{"input": "0 1 3\n1 1\n-2 18\n0 4\n3 -1\n1 3\n0 1\n2 0", "output": "20\n"}, {"input": "0 1 3\n0 1\n-2 35\n0 3\n5 -1\n1 2\n0 1\n5 0", "output": "37\n"}, {"input": "0 3 3\n1 1\n-2 18\n0 3\n5 -1\n1 2\n0 1\n5 0", "output": "18\n"}, {"input": "0 3 3\n1 1\n-2 18\n0 3\n5 -1\n1 3\n0 1\n5 0", "output": "18\n"}, {"input": "0 3 ...
code_stdio
[ { "content": "Polycarpus likes studying at school a lot and he is always diligent about his homework. Polycarpus has never had any problems with natural sciences as his great-great-grandfather was the great physicist Seinstein. On the other hand though, Polycarpus has never had an easy time with history.\n\nEve...
[{"input": "10\n58 22116\n112840 772160\n127432 399484\n182031 255417\n459340 548097\n603984 739189\n606173 663033\n280170 366159\n779239 906234\n874623 155443\n", "output": "7\n"}, {"input": "10\n58 22116\n112840 772160\n122094 399484\n182031 255417\n459340 548097\n603984 739189\n606173 663033\n280170 366159\n779239 9...
code_stdio
[ { "content": "From beginning till end, this message has been waiting to be conveyed.\n\nFor a given unordered multiset of n lowercase English letters (\"multi\" means that a letter may appear more than once), we treat all letters as strings of length 1, and repeat the following operation n - 1 times:\n\n * Rem...
[{"input": "100110\n", "output": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...
code_stdio
[ { "content": "You are given three bags. Each bag contains a non-empty multiset of numbers. You can perform a number of operations on these bags. In one operation, you can choose any two non-empty bags, and choose one number from each of the bags. Let's say that you choose number $a$ from the first bag and numbe...
[{"input": "3 3 3\n1000 1000 1000\n1000 1000 1000\n1 1 -1\n", "output": "5999\n"}, {"input": "3 3 3\n1010 1000 1000\n1000 1000 1000\n1 1 -1\n", "output": "6009\n"}, {"input": "3 3 3\n1010 1000 1000\n1000 1100 1000\n1 1 -1\n", "output": "6109\n"}, {"input": "3 3 3\n1010 1000 1010\n1000 1100 1000\n1 1 -1\n", "output": "6...
code_stdio
[ { "content": "You are given set of n points in 5-dimensional space. The points are labeled from 1 to n. No two points coincide.\n\nWe will call point a bad if there are different points b and c, not equal to a, from the given set such that angle between vectors <image> and <image> is acute (i.e. strictly less t...
[{"input": "11\n358 -724 -232 53 -520\n486 -554 -328 53 -220\n358 -554 -232 -372 -520\n358 -554 -232 308 -520\n868 -554 448 53 -520\n478 -554 -322 53 -600\n358 296 -232 53 -520\n256 -554 -368 53 -520\n230 -554 -136 53 -820\n-182 -554 173 53 -160\n358 -554 -232 53 -520\n", "output": "1\n11\n"}, {"input": "11\n358 -724 -...
code_stdio
[ { "content": "Innokentiy decides to change the password in the social net \"Contact!\", but he is too lazy to invent a new password by himself. That is why he needs your help. \n\nInnokentiy decides that new password should satisfy the following conditions: the length of the password must be equal to n, the p...
[{"input": "114 14\n", "output": "abcdefghijklmnabcdefghijklmnabcdefghijklmnabcdefghijklmnabcdefghijklmnabcdefghijklmnabcdefghijklmnabcdefghijklmnab"}, {"input": "113 3\n", "output": "abcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcab"}, {"input": "113 5\n"...
code_stdio
[ { "content": "A Pythagorean triple is a triple of integer numbers $(a, b, c)$ such that it is possible to form a right triangle with the lengths of the first cathetus, the second cathetus and the hypotenuse equal to $a$, $b$ and $c$, respectively. An example of the Pythagorean triple is $(3, 4, 5)$.\n\nVasya st...
[{"input": "3\n2131\n21165\n6666\n", "output": "32\n102\n57\n"}, {"input": "3\n2131\n21165\n6666\n", "output": "32\n102\n57\n"}, {"input": "3\n2131\n38301\n6666\n", "output": "32\n137\n57\n"}, {"input": "3\n1625\n38301\n6666\n", "output": "28\n137\n57\n"}, {"input": "3\n2570\n38301\n6666\n", "output": "35\n137\n57\n"},...
code_stdio
[ { "content": "A thief sneaked into a museum with a lot of treasures with only one large furoshiki. There are many things I want to steal, but the weight that the furoshiki can withstand is limited, and if it exceeds this, the furoshiki will tear. Therefore, the thief must consider a combination of treasures tha...
[{"input": "50\n5\n60,10\n100,10\n03,022\n210,45\n10,4\n162\n5\n60,10\n100,20\n120,30\n210,45\n10,4\n0", "output": "Case 1:\n220\n49\nCase 2:\n500\n109\n"}, {"input": "50\n5\n60,20\n100,20\n03,021\n210,45\n10,4\n143\n5\n60,10\n100,20\n120,30\n200,45\n10,4\n0", "output": "Case 1:\n220\n49\nCase 2:\n490\n109\n"}, {"input...
code_stdio
[ { "content": "Kaavi, the mysterious fortune teller, deeply believes that one's fate is inevitable and unavoidable. Of course, she makes her living by predicting others' future. While doing divination, Kaavi believes that magic spells can provide great power for her to see the future. \n\n<image>\n\nKaavi has a ...
[{"input": "babbaaababbbbabbaaaababbbaabababbaabbaababbaaabaabbabaabbaababababbaabaaabaaaaababbaabaaaaabaabbabaaababbbb\nbbaabbbbabbbbaaaaaababbbabaaabbbbabababbbaabbbbbabaababbaabaaabaabbababababaaaaabaabbabaaabaaaaaaaaaaaaabbb\n", "output": "284471294"}, {"input": "bbbbabaaababbaabaaaaabaabbabaaaaabaaabaabbabababaabb...
code_stdio
[ { "content": "Kolya is going to make fresh orange juice. He has n oranges of sizes a_1, a_2, ..., a_{n}. Kolya will put them in the juicer in the fixed order, starting with orange of size a_1, then orange of size a_2 and so on. To be put in the juicer the orange must have size not exceeding b, so if Kolya sees ...
[{"input": "100 1000 1083\n992 616 818 359 609 783 263 989 501 929 362 394 919 1081 870 830 1097 975 62 346 531 367 323 457 707 360 949 334 867 116 478 417 961 963 1029 114 867 1008 988 916 983 1077 959 1322 572 961 579 318 721 337 488 717 111 70 416 685 987 130 353 107 61 191 827 849 106 815 211 953 111 398 889 860 80...
code_stdio
[ { "content": "Vasya studies divisibility rules at school. Here are some of them:\n\n * Divisibility by 2. A number is divisible by 2 if and only if its last digit is divisible by 2 or in other words, is even.\n * Divisibility by 3. A number is divisible by 3 if and only if the sum of its digits is divisible b...
[{"input": "30 100\n", "output": "2-type\n2\n"}, {"input": "10 100\n", "output": "2-type\n2\n"}, {"input": "10 25\n", "output": "2-type\n2\n"}, {"input": "70 14\n", "output": "2-type\n1\n"}, {"input": "10 16\n", "output": "2-type\n4\n"}, {"input": "91 49\n", "output": "2-type\n2\n"}, {"input": "10 40\n", "output": "2-t...
code_stdio
[ { "content": "You are standing on the $\\mathit{OX}$-axis at point $0$ and you want to move to an integer point $x > 0$.\n\nYou can make several jumps. Suppose you're currently at point $y$ ($y$ may be negative) and jump for the $k$-th time. You can:\n\neither jump to the point $y + k$\n\nor jump to the point $...
[{"input": "12\n1\n2\n3\n4\n5\n1\n2\n3\n4\n5\n1\n2\n", "output": "1\n3\n2\n3\n4\n1\n3\n2\n3\n4\n1\n3\n"}, {"input": "12\n1\n2\n3\n4\n5\n1\n2\n3\n4\n5\n1\n2\n", "output": "1\n3\n2\n3\n4\n1\n3\n2\n3\n4\n1\n3\n"}, {"input": "12\n1\n2\n3\n4\n5\n2\n2\n3\n4\n5\n1\n2\n", "output": "1\n3\n2\n3\n4\n3\n3\n2\n3\n4\n1\n3\n"}, {"in...
code_stdio
[ { "content": "Two famous competing companies ChemForces and TopChemist decided to show their sets of recently discovered chemical elements on an exhibition. However they know that no element should be present in the sets of both companies.\n\nIn order to avoid this representatives of both companies decided to m...
[{"input": "10\n598654597 975579682\n117777072 31932499\n223851456 1477480177\n988262691 654502493\n967529230 543358150\n835120075 101574205\n809901567 613170206\n152157661 479980560\n859252956 158469817\n614959273 735298093\n10\n1156316033 361325206\n341655282 740807372\n239996693 809030434\n813199219 765838311\n12755...
code_stdio
[ { "content": "Given is an undirected graph G consisting of N vertices numbered 1 through N and M edges numbered 1 through M.\nEdge i connects Vertex a_i and Vertex b_i bidirectionally.\nG is said to be a good graph when both of the conditions below are satisfied. It is guaranteed that G is initially a good grap...
[{"input": "3\n3 0\n6 2\n1 2\n2 3\n15 10\n12 14\n8 3\n10 1\n14 6\n12 6\n1 9\n13 1\n2 5\n3 9\n7 2\n", "output": "First\nSecond\nFirst\n"}, {"input": "1\n100000 0\n", "output": "First\n"}]
code_stdio
[ { "content": "Ivan has a robot which is situated on an infinite grid. Initially the robot is standing in the starting cell (0, 0). The robot can process commands. There are four types of commands it can perform: U — move from the cell (x, y) to (x, y + 1); D — move from (x, y) to (x, y - 1); L — move from (x...
[{"input": "100\nUDRLRRLLRRLRRRDDLLDDDLULLDDLURUURUULUDDDRDDLLRDLLUURLRDRLRRLRLLLULDUDDUURRLRDULDRDURRRRRRULDRRDLDRRL\n", "output": "88\n"}, {"input": "100\nUDRLRRLLRRLRRRDDLLDDDLULLDDLURUURUULUDDDRDDLLRDLLUURLRDRLRRLRLLLULDUDDUURRLRDULDRDURRRRRRULDRRDLDRRL\n", "output": "88\n"}, {"input": "100\nLRRDLDRRDLURRRRRRUDRDLU...
code_stdio
[ { "content": "In this problem, a $n \\times m$ rectangular matrix $a$ is called increasing if, for each row of $i$, when go from left to right, the values strictly increase (that is, $a_{i,1}<a_{i,2}<\\dots<a_{i,m}$) and for each column $j$, when go from top to bottom, the values strictly increase (that is, $a_...
[{"input": "10 4\n4 9 11 12\n8 11 13 18\n13 16 18 21\n15 21 0 24\n17 0 21 29\n21 26 0 33\n26 31 33 35\n30 32 35 37\n33 37 40 43\n34 41 46 51\n", "output": "-1\n"}, {"input": "10 4\n4 9 11 12\n8 11 13 18\n13 16 18 21\n15 21 0 24\n17 0 21 29\n21 26 0 33\n26 31 33 35\n30 32 35 37\n33 37 40 43\n34 41 46 51\n", "output": "-...
code_stdio
[ { "content": "Iahub is a big fan of tourists. He wants to become a tourist himself, so he planned a trip. There are n destinations on a straight road that Iahub wants to visit. Iahub starts the excursion from kilometer 0. The n destinations are described by a non-negative integers sequence a_1, a_2, ..., a_{n}....
[{"input": "50\n3987477 8934938 4067156 6712855 7269334 5039822 9533601 9335400 5992073 2619268 438734 8620973 4347619 4307947 2249161 815221 7615258 8244100 8341666 5908546 6646952 4812769 6215114 7479369 6290438 5623785 6466133 9953199 3525873 4326034 3510072 8117068 2342953 1717542 9766539 651627 9541804 4518782 704...
code_stdio
[ { "content": "Farmer Feb has three fields with potatoes planted in them. He harvested x potatoes from the first field, y potatoes from the second field and is yet to harvest potatoes from the third field. Feb is very superstitious and believes that if the sum of potatoes he harvests from the three fields is a p...
[{"input": "2\n3 20\n27 15", "output": "6\n1\n"}, {"input": "2\n3 20\n63 22", "output": "6\n4\n"}, {"input": "2\n3 20\n58 22", "output": "6\n3\n"}, {"input": "2\n5 19\n58 22", "output": "5\n3\n"}, {"input": "2\n2 1\n11 12", "output": "2\n6\n"}, {"input": "2\n2 6\n14 10", "output": "3\n5\n"}, {"input": "2\n24 7\n3 18", ...
code_stdio
[ { "content": "Pupils decided to go to amusement park. Some of them were with parents. In total, n people came to the park and they all want to get to the most extreme attraction and roll on it exactly once.\n\nTickets for group of x people are sold on the attraction, there should be at least one adult in each g...
[{"input": "100 1000 1000\n0000010100101100110100101111001111111111100101111100111011110001011110110111111010000000101000111000\n", "output": "100000\n"}, {"input": "100 1000 1000\n0000010100101100110100101111001111111111100101111100111011110001011110110111111010000000101000111000\n", "output": "100000\n"}, {"input": "...
code_stdio
[ { "content": "You have array a that contains all integers from 1 to n twice. You can arbitrary permute any numbers in a.\n\nLet number i be in positions x_{i}, y_{i} (x_{i} < y_{i}) in the permuted array a. Let's define the value d_{i} = y_{i} - x_{i} — the distance between the positions of the number i. Permut...
[{"input": "1376\n", "output": "1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45 47 49 51 53 55 57 59 61 63 65 67 69 71 73 75 77 79 81 83 85 87 89 91 93 95 97 99 101 103 105 107 109 111 113 115 117 119 121 123 125 127 129 131 133 135 137 139 141 143 145 147 149 151 153 155 157 159 161 163 165 167 169 171...
code_stdio
[ { "content": "Chilly Willy loves playing with numbers. He only knows prime numbers that are digits yet. These numbers are 2, 3, 5 and 7. But Willy grew rather bored of such numbers, so he came up with a few games that were connected with them.\n\nChilly Willy wants to find the minimum number of length n, such t...
[{"input": "99993\n", "output": "10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...
code_stdio
[ { "content": "You are given two integers a and b. Determine if a+b=15 or a\\times b=15 or neither holds.\n\nNote that a+b=15 and a\\times b=15 do not hold at the same time.\n\nConstraints\n\n* 1 \\leq a,b \\leq 15\n* All values in input are integers.\n\nInput\n\nInput is given from Standard Input in the followi...
[{"input": "-3 -5", "output": "*\n"}, {"input": "11 -1", "output": "x\n"}, {"input": "15 -1", "output": "x\n"}, {"input": "29 -1", "output": "x\n"}, {"input": "13 -1", "output": "x\n"}, {"input": "17 -1", "output": "x\n"}, {"input": "16 -1", "output": "+\n"}, {"input": "16 -2", "output": "x\n"}, {"input": "-1 -3", "out...
code_stdio
[ { "content": "Three people, A, B and C, are trying to communicate using transceivers.\nThey are standing along a number line, and the coordinates of A, B and C are a, b and c (in meters), respectively.\nTwo people can directly communicate when the distance between them is at most d meters.\nDetermine if A and C...
[{"input": "-1 000 -1 15", "output": "Yes\n"}, {"input": "-1 100 -1 15", "output": "Yes\n"}, {"input": "-1 100 -1 12", "output": "Yes\n"}, {"input": "-1 100 -1 13", "output": "Yes\n"}, {"input": "-1 100 -1 24", "output": "Yes\n"}, {"input": "-1 100 -2 24", "output": "Yes\n"}, {"input": "-2 011 -1 24", "output": "Yes\n"...
code_stdio
[ { "content": "Petya is the most responsible worker in the Research Institute. So he was asked to make a very important experiment: to melt the chocolate bar with a new laser device. The device consists of a rectangular field of n × m cells and a robotic arm. Each cell of the field is a 1 × 1 square. The robotic...
[{"input": "20\n100 200 100 1 100 100\n100 200 1 100 100 100\n2 2 1 1 2 2\n100 100 50 50 1 1\n10 10 5 5 1 1\n100 100 99 1 1 99\n100 100 1 99 99 1\n100 100 1 10 10 1\n100 100 1 1 10 10\n9 6 1 3 3 1\n1000000000 1000000000 1 1 1000000000 1000000000\n9 4 1 4 4 1\n6 4 1 1 5 4\n6 2 1 1 5 2\n8 2 1 1 5 2\n10 2 1 1 5 2\n10 2 1 ...
code_stdio
[ { "content": "Valera the Horse is going to the party with friends. He has been following the fashion trends for a while, and he knows that it is very popular to wear all horseshoes of different color. Valera has got four horseshoes left from the last year, but maybe some of them have the same color. In this cas...
[{"input": "133315691 1002877005 1237779669 265159773\n", "output": "0\n"}, {"input": "133315691 1002877005 1237779669 207655879\n", "output": "0\n"}, {"input": "111229995 1002877005 1237779669 207655879\n", "output": "0\n"}, {"input": "133315691 265159773 1237779669 265159773\n", "output": "1\n"}, {"input": "391958720...
code_stdio
[ { "content": "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.\nS is said to be easily playa...
[{"input": "UUULRUUDRURLDDRLRLRURLUDRLUURDDUULRUULRDRDULUUDLRLRUDLUDRLULULRUDURURDRLUURLULRUULDURDUUUDULRDRLRLDL\n", "output": "Yes\n"}, {"input": "UDUDRDDLRDDDRUDURUULULDUUURLDLDLRURLDDRDDDRUUDRUUDDDDUUURLDLULUDRUDDDUULDDLURDRDRUUURLUDUUDLRUUDULRD\n", "output": "No\n"}, {"input": "UUULRULUUDDLDDULRDRDDDRLDLULRDDLDLRUR...
code_stdio
[ { "content": "Example\n\nInput\n\n8\n-10 0\n-10 5\n-5 5\n-5 0\n10 0\n10 -5\n5 -5\n5 0\n\n\nOutput\n\n50\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": "8\n-18 1\n-10 2\n-10 8\n-27 -1\n11 0\n22 -5\n4 -8\n5 0", "output": "137\n"}, {"input": "8\n-18 1\n-10 2\n-10 8\n-27 -1\n11 0\n22 -7\n4 -8\n5 0", "output": "144\n"}, {"input": "8\n-18 1\n-10 2\n-10 8\n-7 -1\n11 0\n22 -14\n4 -8\n5 0", "output": "155\n"}, {"input": "8\n-1 0\n-10 10\n-4 8\n-5 -1\n19 0\n10 -5\n7...
code_stdio
[ { "content": "problem\n\nThere are n cards with one integer from 1 to n and one blank card. Of these n + 1 cards, k cards are given, but 1 ≤ k ≤ n. You can write one integer from 1 to n on a blank card. I want to make a continuous sequence of integers as long as possible with just a given card.\n\nWrite a progr...
[{"input": "14 5\n6\n2\n4\n10\n1\n15 5\n5\n2\n0\n4\n7\n0 0", "output": "2\n4\n"}, {"input": "33 5\n5\n0\n4\n7\n0\n20 5\n10\n3\n2\n4\n7\n0 0", "output": "4\n3\n"}, {"input": "14 5\n6\n0\n4\n14\n1\n8 5\n5\n2\n0\n0\n7\n0 0", "output": "3\n3\n"}, {"input": "33 5\n5\n3\n4\n7\n0\n10 5\n5\n2\n1\n4\n7\n0 0", "output": "5\n2\n"...
code_stdio
[ { "content": "$N$ sages are sitting around a round table with $N$ seats. Each sage holds chopsticks with his dominant hand to eat his dinner. The following happens in this situation.\n\n* If sage $i$ is right-handed and a left-handed sage sits on his right, a level of frustration $w_i$ occurs to him. A right-ha...
[{"input": "5\n1 1 0 1 0\n1 3 1 -2 4", "output": "-1\n"}, {"input": "5\n1 1 0 1 0\n1 3 1 -1 4", "output": "0\n"}, {"input": "5\n1 1 0 0 2\n1 3 0 2 13", "output": "1\n"}, {"input": "5\n1 0 0 1 0\n2 3 6 1 2", "output": "3\n"}, {"input": "5\n1 1 0 1 0\n4 3 5 1 4", "output": "5\n"}, {"input": "5\n1 1 0 1 0\n4 3 0 1 4", "ou...
code_stdio
[ { "content": "It's New Year's Eve soon, so Ivan decided it's high time he started setting the table. Ivan has bought two cakes and cut them into pieces: the first cake has been cut into a pieces, and the second one — into b pieces.\n\nIvan knows that there will be n people at the celebration (including himself)...
[{"input": "100 100 100\n", "output": "2\n"}, {"input": "100 100 100\n", "output": "2\n"}, {"input": "100 100 10\n", "output": "1\n"}, {"input": "17 100 79\n", "output": "10\n"}, {"input": "17 100 79\n", "output": "10\n"}, {"input": "100 100 10\n", "output": "1\n"}, {"input": "5 122 100\n", "output": "40\n"}, {"input":...
code_stdio
[ { "content": "Sereja has got an array, consisting of n integers, a_1, a_2, ..., a_{n}. Sereja is an active boy, so he is now going to complete m operations. Each operation will have one of the three forms: Make v_{i}-th array element equal to x_{i}. In other words, perform the assignment a_{v}_{i} = x_{i}. In...
[{"input": "6 6\n202714501 613423725 367325359 862808465 196327629 745008828\n2 492\n2 1943\n1 3 173984392\n1 5 17007494\n3 4\n1 5 472683539\n", "output": "862810900\n\n"}, {"input": "6 6\n202714501 613423725 367325359 862808465 196327629 745008828\n2 492\n2 1943\n1 3 173984392\n1 5 17007494\n3 4\n1 5 650027606\n", "ou...
code_stdio
[ { "content": "You are given a permutation of the numbers 1, 2, ..., n and m pairs of positions (a_{j}, b_{j}).\n\nAt each step you can choose a pair from the given positions and swap the numbers in that positions. What is the lexicographically maximal permutation one can get?\n\nLet p and q be two permutations ...
[{"input": "83 8\n54 3 52 12 61 36 65 62 69 49 47 77 31 15 21 14 73 29 6 26 37 17 81 75 43 30 58 76 16 8 11 5 27 35 7 66 50 67 2 39 45 28 60 71 38 82 53 1 42 13 44 72 22 4 9 25 19 57 10 70 18 68 32 34 20 80 23 79 24 63 64 51 59 41 74 48 40 33 46 83 55 56 78\n48 80\n1 8\n71 54\n15 59\n72 46\n36 9\n64 29\n55 58\n", "outp...
code_stdio
[ { "content": "Stepan is a very experienced olympiad participant. He has n cups for Physics olympiads and m cups for Informatics olympiads. Each cup is characterized by two parameters — its significance c_{i} and width w_{i}.\n\nStepan decided to expose some of his cups on a shelf with width d in such a way, tha...
[{"input": "20 10 761\n66 41\n47 7\n35 6\n22 40\n15 2\n47 28\n46 47\n3 45\n12 19\n44 41\n46 2\n49 23\n9 8\n7 41\n5 3\n16 42\n12 50\n17 22\n25 9\n45 12\n56 44\n34 47\n33 35\n32 47\n119 6\n27 18\n43 36\n23 6\n39 22\n38 45\n", "output": "1009\n"}, {"input": "20 10 761\n66 41\n47 7\n35 6\n22 40\n15 2\n47 28\n46 47\n3 45\n1...
code_stdio
[ { "content": "There are N strings arranged in a row. It is known that, for any two adjacent strings, the string to the left is lexicographically smaller than the string to the right. That is, S_1<S_2<...<S_N holds lexicographically, where S_i is the i-th string from the left.\n\nAt least how many different char...
[{"input": "5\n11 1 2 2 2", "output": "3"}, {"input": "5\n14 1 2 2 2", "output": "3"}, {"input": "5\n28 1 2 2 2", "output": "3"}, {"input": "5\n3 1 2 1 13", "output": "3"}, {"input": "5\n11 1 2 2 1", "output": "3"}, {"input": "5\n14 1 2 2 3", "output": "2"}, {"input": "5\n23 1 2 2 2", "output": "3"}, {"input": "5\n2 1 ...
code_stdio
[ { "content": "An accordion is a string (yes, in the real world accordions are musical instruments, but let's forget about it for a while) which can be represented as a concatenation of: an opening bracket (ASCII code $091$), a colon (ASCII code $058$), some (possibly zero) vertical line characters (ASCII code $...
[{"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa[\n", "output": "-1\n"}, {"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...
code_stdio
[ { "content": "Someone give a strange birthday present to Ivan. It is hedgehog — connected undirected graph in which one vertex has degree at least 3 (we will call it center) and all other vertices has degree 1. Ivan thought that hedgehog is too boring and decided to make himself k-multihedgehog.\n\nLet us defin...
[{"input": "33 2\n3 13\n17 3\n2 6\n5 33\n4 18\n1 2\n31 5\n4 19\n3 16\n1 3\n9 2\n10 3\n5 1\n5 28\n21 4\n7 2\n1 4\n5 24\n30 5\n14 3\n3 11\n27 5\n8 2\n22 4\n12 3\n20 4\n26 5\n4 23\n32 5\n25 5\n15 3\n29 5\n", "output": "Yes\n"}, {"input": "25 2\n1 2\n1 3\n1 4\n2 5\n2 6\n2 7\n3 8\n3 9\n3 10\n4 11\n4 12\n4 13\n4 14\n14 15\n1...
code_stdio
[ { "content": "Santa Claus has Robot which lives on the infinite grid and can move along its lines. He can also, having a sequence of m points p_1, p_2, ..., p_{m} with integer coordinates, do the following: denote its initial location by p_0. First, the robot will move from p_0 to p_1 along one of the shortest ...
[{"input": "26\nRURULRRURUDLULDLDLDURLRDDL\n", "output": "10\n"}, {"input": "26\nRURULRRLRUDUULLLDLDURDRDLD\n", "output": "11\n"}, {"input": "26\nLDDRLRUDLDLDLULDURURRLURUR\n", "output": "10\n"}, {"input": "26\nLDDRLRLDLDLDLUUDURURRLURUR\n", "output": "10\n"}, {"input": "26\nRURULRRURUDUULDLDLDLRLRDDL\n", "output": "10...
code_stdio
[ { "content": "The only difference between easy and hard versions is the maximum value of $n$.\n\nYou are given a positive integer number $n$. You really love good numbers so you want to find the smallest good number greater than or equal to $n$.\n\nThe positive integer is called good if it can be represented as...
[{"input": "100\n1\n2\n3\n4\n5\n6\n7\n8\n14\n10\n11\n12\n13\n14\n15\n16\n17\n18\n19\n20\n21\n22\n23\n24\n25\n26\n27\n28\n29\n30\n31\n32\n33\n34\n35\n36\n37\n38\n39\n40\n41\n42\n43\n44\n45\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\n74\n75\n76\n77\n78\...
code_stdio
[ { "content": "Given a matrix (H × W) which contains only 1 and 0, find the area of the largest rectangle which only contains 0s.\n\nConstraints\n\n* 1 ≤ H, W ≤ 1,400\n\nInput\n\n\nH W\nc1,1 c1,2 ... c1,W\nc2,1 c2,2 ... c2,W\n:\ncH,1 cH,2 ... cH,W\n\n\nIn the first line, two integers H and W separated by a space...
[{"input": "1 5\n1 0 1 0 0\n2 0 -1 -1 0\n0 -1 0 -1 0\n0 0 0 1 0", "output": "2\n"}, {"input": "1 3\n1 1 1 0 0\n2 0 -1 0 1\n1 -1 0 0 0\n-1 0 1 2 -1", "output": "0\n"}, {"input": "1 5\n0 0 0 0 0\n2 0 -1 -1 0\n0 0 0 0 0\n0 2 1 1 -1", "output": "5\n"}, {"input": "1 5\n1 0 1 0 0\n2 0 -1 -1 0\n0 -1 0 0 0\n0 0 0 1 0", "output...
code_stdio
[ { "content": "Little Elephant from the Zoo of Lviv likes cards. He has N cards, each of which has one of 1000 colors. The colors are numbered from 1 to 1000.\nLittle Elephant and Big Hippo are playing the following game. At first Little Elephant takes some subset of cards, and Big Hippo takes the rest of them. ...
[{"input": "2\n15\n-1 1 7\n35\n-1 -3 8 8", "output": "16384\n179869065\n"}, {"input": "2\n15\n-1 1 7\n38\n-1 -3 8 8", "output": "16384\n766320739\n"}, {"input": "2\n15\n-1 1 7\n47\n-1 -3 8 8", "output": "16384\n743685088\n"}, {"input": "2\n25\n0 -1 1\n15\n2 -1 -1 3", "output": "16777216\n16384\n"}, {"input": "2\n12\n-1...
code_stdio
[ { "content": "An expedition group flew from planet ACM-1 to Earth in order to study the bipedal species (its representatives don't even have antennas on their heads!).\n\nThe flying saucer, on which the brave pioneers set off, consists of three sections. These sections are connected by a chain: the 1-st section...
[{"input": "602799218 494169337\n", "output": "105935725\n"}, {"input": "523061914 144515354\n", "output": "127493116\n"}, {"input": "622152471 448257864\n", "output": "210299666\n"}, {"input": "549662082 945236243\n", "output": "239869294\n"}, {"input": "868095112 994962872\n", "output": "606909752\n"}, {"input": "296...
code_stdio
[ { "content": "A telephone number is a sequence of exactly 11 digits, where the first digit is 8. For example, the sequence 80011223388 is a telephone number, but the sequences 70011223388 and 80000011223388 are not.\n\nYou are given a string $s$ of length $n$, consisting of digits.\n\nIn one operation you can d...
[{"input": "2\n13\n7818005553535\n11\n31415926535\n", "output": "YES\nNO\n"}, {"input": "2\n13\n14222439333841\n11\n31415926535\n", "output": "NO\nNO\n"}, {"input": "2\n13\n3872943379171\n11\n45489461254\n", "output": "YES\nNO\n"}, {"input": "2\n13\n14222439333841\n11\n45489461254\n", "output": "NO\nNO\n"}, {"input": "...
code_stdio
[ { "content": "You are an upcoming movie director, and you have just released your first movie. You have also launched a simple review site with two buttons to press — upvote and downvote.\n\nHowever, the site is not so simple on the inside. There are two servers, each with its separate counts for the upvotes an...
[{"input": "9\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n", "output": "1\n1\n1\n1\n1\n1\n1\n1\n1\n"}, {"input": "9\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n", "output": "1\n1\n1\n1\n1\n1\n1\n1\n1\n"}, {"input": "9\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n2\n1\n1\n1\n1\n", "output": "1\n1\n1\n1\...
code_stdio
[ { "content": "Vasya plays the Need For Brake. He plays because he was presented with a new computer wheel for birthday! Now he is sure that he will win the first place in the championship in his favourite racing computer game! \n\nn racers take part in the championship, which consists of a number of races. Afte...
[{"input": "20\ng 1000000\nibb 1000000\nidj 1000000\nkccg 1000000\nbbe 1000000\nhjf 1000000\na 1000000\nf 1000000\niij 1000000\nakgf 1000000\nkdkhj 1000000\ne 1000000\nh 1000000\nhb 1000000\nfaie 1000000\nj 1000000\ni 1000000\nhgg 1000000\nfi 1000000\nicf 1000000\n12\n1000000 1000000 1000000 1000000 1000000 1000000 100...
code_stdio
[ { "content": "A positive integer is called a 2-3-integer, if it is equal to 2^{x}·3^{y} for some non-negative integers x and y. In other words, these integers are such integers that only have 2 and 3 among their prime divisors. For example, integers 1, 6, 9, 16 and 108 — are 2-3 integers, while 5, 10, 21 and 12...
[{"input": "1088391168 1934917632\n", "output": "17\n"}, {"input": "1088391167 1934917632\n", "output": "17\n"}, {"input": "1088391169 1934917632\n", "output": "16\n"}, {"input": "1088391168 1934917631\n", "output": "16\n"}, {"input": "1088391168 1934917633\n", "output": "17\n"}, {"input": "1088391167 1934917632\n", "o...
code_stdio
[ { "content": "You are given a permutation $p$ of $n$ integers $1$, $2$, ..., $n$ (a permutation is an array where each element from $1$ to $n$ occurs exactly once).\n\nLet's call some subsegment $p[l, r]$ of this permutation special if $p_l + p_r = \\max \\limits_{i = l}^{r} p_i$. Please calculate the number of...
[{"input": "5\n3 4 1 5 2\n", "output": "2\n"}, {"input": "5\n4 5 1 3 2\n", "output": "2\n"}, {"input": "5\n5 4 1 3 2\n", "output": "1\n"}, {"input": "5\n3 4 2 5 1\n", "output": "1\n"}, {"input": "5\n3 4 1 5 2\n", "output": "2"}, {"input": "3\n1 3 2\n", "output": "1\n"}, {"input": "3\n2 3 1\n", "output": "1\n"}, {"input...
code_stdio
[ { "content": "There is a tree with N vertices, numbered 1, 2, \\ldots, N. For each i (1 \\leq i \\leq N - 1), the i-th edge connects Vertex x_i and y_i.\n\nTaro has decided to paint each vertex in white or black, so that any black vertex can be reached from any other black vertex by passing through only black v...
[{"input": "10 2\n8 5\n10 8\n6 5\n1 5\n4 8\n2 10\n3 6\n9 4\n1 7", "output": "0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n"}, {"input": "10 2\n8 5\n10 8\n6 5\n1 5\n4 8\n2 10\n3 6\n9 2\n1 7", "output": "0\n0\n1\n1\n1\n0\n1\n0\n1\n1"}, {"input": "4 101\n1 2\n1 3\n1 4", "output": "8\n5\n5\n5\n"}, {"input": "4 101\n1 2\n1 3\n2 4", "outpu...
code_stdio
[ { "content": "Taro came to a square to look for treasure. There are many treasures buried in this square, but Taro has the latest machines, so he knows everything about where the treasures are buried. Since the square is very wide Taro decided to look for the treasure to decide the area, but the treasure is wha...
[{"input": "5 5\n10 7\n-3 -8\n2 11\n6 0\n-1 3\n-3 1 3 13\n-1 -1 9 5\n-3 -16 10 11\n-1 0 5 4\n-1 -13 15 10", "output": "2\n2\n5\n1\n3\n"}, {"input": "5 5\n10 7\n-3 -8\n2 11\n10 0\n-1 3\n-3 1 3 13\n-1 -1 9 5\n-3 -16 12 11\n0 0 5 4\n-1 -13 15 10", "output": "2\n1\n5\n0\n3\n"}, {"input": "5 5\n10 7\n-3 -8\n2 11\n0 0\n-1 3\...
code_stdio
[ { "content": "In Berland recently a new collection of toys went on sale. This collection consists of 10^9 types of toys, numbered with integers from 1 to 10^9. A toy from the new collection of the i-th type costs i bourles.\n\nTania has managed to collect n different types of toys a_1, a_2, ..., a_{n} from the ...
[{"input": "5 100000000\n100000000 999999999 1 2 3\n", "output": "14138\n4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 8...
code_stdio
[ { "content": "Decimal numbers are a common notation system currently in use and use ten symbols 0, 1, 2, 3, 4, 5, 6, 7, 8, and 9 to represent all numbers.\n\nBinary numbers are a popular notation in the computer world and use two symbols, 0 and 1, to represent all numbers.\n\nOnly the four numbers 0, 1, 2, and ...
[{"input": "7\n4\n0\n24\n10\n10010\n-1", "output": "13\n10\n0\n120\n22\n2130122\n"}, {"input": "7\n4\n1\n24\n10\n10010\n-1", "output": "13\n10\n1\n120\n22\n2130122\n"}, {"input": "7\n4\n0\n12\n16\n10000\n-1", "output": "13\n10\n0\n30\n100\n2130100\n"}, {"input": "7\n4\n0\n24\n10\n11010\n-1", "output": "13\n10\n0\n120\n...
code_stdio
[ { "content": "There is an infinitely long street that runs west to east, which we consider as a number line.\nThere are N roadworks scheduled on this street.\nThe i-th roadwork blocks the point at coordinate X_i from time S_i - 0.5 to time T_i - 0.5.\nQ people are standing at coordinate 0. The i-th person will ...
[{"input": "4 6\n1 3 2\n2 13 10\n18 20 22\n4 4 2\n1\n1\n2\n3\n5\n8", "output": "10\n10\n10\n-1\n-1\n-1\n"}, {"input": "4 6\n2 1 0\n2 13 10\n18 20 22\n7 4 1\n1\n1\n4\n3\n5\n8", "output": "10\n10\n-1\n-1\n-1\n-1\n"}, {"input": "4 6\n1 3 2\n7 13 10\n18 20 13\n3 4 2\n0\n1\n2\n3\n5\n8\n", "output": "2\n2\n10\n-1\n13\n-1\n"}...
code_stdio
[ { "content": "Find places where a string P is found within a text T. Print all indices of T where P found. The indices of T start with 0.\n\nConstraints\n\n* 1 ≤ length of T ≤ 1000000\n* 1 ≤ length of P ≤ 10000\n* The input consists of alphabetical characters and digits\n\nInput\n\nIn the first line, a text T i...
[{"input": "aaaaab\naa", "output": "0\n1\n2\n3\n"}, {"input": "baaaaa\naa", "output": "1\n2\n3\n4\n"}, {"input": "aaabaa\naa", "output": "0\n1\n4\n"}, {"input": "baaaab\naa", "output": "1\n2\n3\n"}, {"input": "aaaabb\naa", "output": "0\n1\n2\n"}, {"input": "b`aaaa\naa", "output": "2\n3\n4\n"}, {"input": "``a```\n``", "...
code_stdio
[ { "content": "The Smart Beaver from ABBYY began to develop a new educational game for children. The rules of the game are fairly simple and are described below.\n\nThe playing field is a sequence of n non-negative integers ai numbered from 1 to n. The goal of the game is to make numbers a1, a2, ..., ak (i.e. so...
[{"input": "120\n242 524 420 973 816 432 247 666 134 849 145 366 608 930 613 315 863 628 97 109 65 704 741 314 736 17 872 971 559 648 223 771 171 327 782 837 303 393 292 339 730 834 794 868 540 251 789 893 23 305 116 220 699 863 580 992 861 393 98 253 544 171 336 207 348 496 316 285 286 727 613 616 304 811 592 916 91 5...
code_stdio
[ { "content": "Sakuzyo - Imprinting\n\nA.R.C. Markland-N is a tall building with $n$ floors numbered from $1$ to $n$. Between each two adjacent floors in the building, there is a staircase connecting them.\n\nIt's lunchtime for our sensei Colin \"ConneR\" Neumann Jr, and he's planning for a location to enjoy his...
[{"input": "1\n100 52 99\n51 69 42 32 34 62 12 75 88 18 57 47 40 91 100 81 72 15 26 14 93 68 6 50 5 24 97 52 10 20 54 9 56 39 21 55 7 98 59 87 77 17 29 13 30 46 37 76 71 78 96 82 49 64 84 60 67 19 2 25 85 89 38 41 11 90 35 48 27 28 70 65 66 16 79 3 80 44 36 43 61 99 22 33 86 4 83 94 74 31 73 95 58 53 8 63 92 45 23\n", ...
code_stdio
[ { "content": "We have a tree with N vertices. The i-th edge connects Vertex A_i and B_i bidirectionally.\nTakahashi is standing at Vertex u, and Aoki is standing at Vertex v.\nNow, they will play a game of tag as follows:\n - 1. If Takahashi and Aoki are standing at the same vertex, the game ends. Otherwise, Ta...
[{"input": "9626 1978 3170\n4041 8502\n9589 1770\n3880 9265\n3674 287\n5843 6458\n4211 4202\n1543 3712\n2171 8104\n6298 1286\n702 6013\n5943 5185\n570 8388\n328 3661\n4012 7110\n5999 5207\n4151 4634\n1287 1773\n8991 1892\n6828 7699\n6330 2869\n8268 6633\n3292 1018\n7016 6679\n8643 7852\n7834 6467\n4894 2098\n2936 460\n...
code_stdio
[ { "content": "Jon Snow is on the lookout for some orbs required to defeat the white walkers. There are k different types of orbs and he needs at least one of each. One orb spawns daily at the base of a Weirwood tree north of the wall. The probability of this orb being of any kind is equal. As the north of wall ...
[{"input": "8 10\n100\n200\n300\n400\n500\n600\n700\n800\n900\n1000\n", "output": "11\n13\n14\n15\n16\n16\n17\n18\n19\n20\n"}, {"input": "8 10\n100\n200\n300\n400\n500\n600\n700\n862\n900\n1000\n", "output": "11\n13\n14\n15\n16\n16\n17\n19\n19\n20\n"}, {"input": "7 10\n100\n200\n300\n400\n500\n600\n700\n800\n900\n1000\...
code_stdio
[ { "content": "Piegirl has found a monster and a book about monsters and pies. When she is reading the book, she found out that there are n types of monsters, each with an ID between 1 and n. If you feed a pie to a monster, the monster will split into some number of monsters (possibly zero), and at least one col...
[{"input": "11 10\n1 9 -1 -1 -1 -1 -1 -1 -1 -1 -1\n1 10 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1\n2 11 1 1 1 1 1 1 1 1 1 1 -1\n3 11 2 2 2 2 2 2 2 2 2 2 -1\n4 11 3 3 3 3 3 3 3 3 3 3 -1\n5 11 4 4 4 4 4 4 4 4 4 4 -1\n6 11 5 5 5 5 5 5 5 5 5 5 -1\n7 11 6 6 6 6 6 6 6 6 6 6 -1\n8 11 7 7 7 7 7 7 7 7 7 7 -1\n9 11 8 8 8 8 8 8 8 8 8 8 -1\n1...
code_stdio
[ { "content": "Takahashi has an empty string S and a variable x whose initial value is 0.\n\nAlso, we have a string T consisting of `0` and `1`.\n\nNow, Takahashi will do the operation with the following two steps |T| times.\n\n* Insert a `0` or a `1` at any position of S of his choice.\n* Then, increment x by t...
[{"input": "0111101111", "output": "28\n"}, {"input": "0111001111", "output": "27\n"}, {"input": "1010011111", "output": "29\n"}, {"input": "0010001111", "output": "23\n"}, {"input": "0010001011", "output": "21\n"}, {"input": "0010001001", "output": "18\n"}, {"input": "0110001001", "output": "19\n"}, {"input": "0010001...
code_stdio
[ { "content": "Problem\n\nGiven the integer n, output the smallest m such that nCm (the number of combinations that choose m out of n different ones) is even.\n\nConstraints\n\nThe input satisfies the following conditions.\n\n* 1 ≤ n ≤ 1018\n\nInput\n\nThe input is given in the following format.\n\n\nn\n\n\nOutp...
[{"input": "127", "output": "128\n"}, {"input": "255", "output": "256\n"}, {"input": "175", "output": "16\n"}, {"input": "101", "output": "2\n"}, {"input": "15", "output": "16\n"}, {"input": "31", "output": "32\n"}, {"input": "63", "output": "64\n"}, {"input": "110", "output": "1\n"}, {"input": "010", "output": "1\n"},...
code_stdio
[ { "content": "There are N balls in the xy-plane. The coordinates of the i-th of them is (x_i, i).\nThus, we have one ball on each of the N lines y = 1, y = 2, ..., y = N.\nIn order to collect these balls, Snuke prepared 2N robots, N of type A and N of type B.\nThen, he placed the i-th type-A robot at coordinate...
[{"input": "5\n20\n11 12 9 17 12\n", "output": "74\n"}, {"input": "5\n20\n14 12 16 17 15", "output": "52\n"}, {"input": "5\n20\n14 10 16 17 15", "output": "56\n"}, {"input": "5\n20\n14 10 20 17 15", "output": "48\n"}, {"input": "5\n20\n14 18 20 17 15", "output": "32\n"}, {"input": "5\n20\n14 18 20 17 19", "output": "24...
code_stdio
[ { "content": "There are n phone numbers in Polycarp's contacts on his phone. Each number is a 9-digit integer, starting with a digit different from 0. All the numbers are distinct.\n\nThere is the latest version of Berdroid OS installed on Polycarp's phone. If some number is entered, is shows up all the numbers...
[{"input": "9\n111111111\n111111110\n111111100\n111111000\n111110000\n111100000\n111000000\n110000000\n100000000\n", "output": "111111111\n111111110\n111111100\n111111000\n111110000\n111100000\n111000000\n110000000\n00000000\n"}, {"input": "10\n302417715\n621211824\n474451896\n961495400\n633841010\n839982537\n797812119...
code_stdio
[ { "content": "Read problems statements in Mandarin Chinese and Russian. \n\nYou are given an array A of integers of size N. You will be given Q queries where each query is represented by two integers L, R. You have to find the gcd(Greatest Common Divisor) of the array after excluding the part from range L to R...
[{"input": "1\n3 3\n3 5 17\n1 2\n0 1\n-1 0", "output": "17\n1\n1\n"}, {"input": "1\n3 3\n3 9 23\n3 0\n1 2\n-1 0", "output": "1\n23\n1\n"}, {"input": "1\n3 3\n5 10 10\n4 0\n0 0\n4 0", "output": "5\n5\n5\n"}, {"input": "1\n3 3\n3 6 19\n1 2\n0 0\n4 0", "output": "19\n1\n1\n"}, {"input": "1\n3 3\n2 2 16\n1 1\n1 2\n2 3", "o...
code_stdio
[ { "content": "As you must know, the maximum clique problem in an arbitrary graph is NP-hard. Nevertheless, for some graphs of specific kinds it can be solved effectively.\n\nJust in case, let us remind you that a clique in a non-directed graph is a subset of the vertices of a graph, such that any two vertices o...
[{"input": "50\n1 2 5 7 9 14 19 24 25 29 31 34 37 40 43 44 46 53 54 57 58 59 60 61 62 64 66 68 69 70 72 75 78 79 80 81 82 84 85 86 87 88 89 90 91 92 93 94 96 98\n", "output": "4\n"}, {"input": "50\n1 2 5 7 9 14 19 24 25 29 31 34 37 40 43 44 46 53 54 57 58 59 60 61 62 64 66 68 69 70 72 75 78 79 80 81 82 84 85 86 87 88 8...
code_stdio
[ { "content": "We're giving away nice huge bags containing number tiles! A bag we want to present to you contains n tiles. Each of them has a single number written on it — either 1 or 2.\n\nHowever, there is one condition you must fulfill in order to receive the prize. You will need to put all the tiles from the...
[{"input": "214\n1 2 2 1 1 1 2 2 2 2 1 1 1 2 2 2 2 2 2 1 2 1 1 2 2 1 1 2 2 2 2 1 2 2 2 1 1 2 2 2 1 1 2 2 1 2 2 2 1 1 2 1 1 2 1 1 1 2 2 2 2 1 2 2 2 1 2 1 2 1 1 2 2 1 1 2 1 2 2 2 2 2 2 2 1 2 1 2 2 1 2 2 2 1 2 2 1 2 2 1 2 2 2 2 1 2 2 2 1 1 2 2 2 2 2 2 1 2 2 2 2 1 1 1 2 2 2 1 2 1 2 1 1 2 1 1 1 2 2 2 1 2 2 2 2 2 2 2 1 2 2 1...
code_stdio
[ { "content": "Multiple polygonal lines are given on the xy-plane. Given a list of polygonal lines and a template, you must find out polygonal lines which have the same shape as the template.\n\nA polygonal line consists of several line segments parallel to x-axis or y-axis. It is defined by a list of xy-coordin...
[{"input": "5\n5\n0 0\n2 0\n2 1\n4 1\n4 0\n5\n0 0\n0 2\n-1 2\n-1 4\n0 4\n5\n0 0\n0 1\n-2 1\n-2 2\n0 2\n5\n0 0\n0 -1\n2 -1\n2 0\n4 0\n5\n0 0\n2 0\n2 -1\n4 -1\n4 0\n5\n0 0\n2 0\n2 1\n4 1\n4 0\n4\n4\n-60 -75\n-60 -78\n-42 -78\n-42 -6\n4\n10 3\n10 7\n-4 7\n-4 40\n4\n-74 66\n-74 63\n-92 63\n-92 135\n4\n-12 22\n-12 25\n-30 2...
code_stdio
[ { "content": "You are given $n$ numbers $a_1, a_2, \\dots, a_n$. With a cost of one coin you can perform the following operation:\n\nChoose one of these numbers and add or subtract $1$ from it.\n\nIn particular, we can apply this operation to the same number several times.\n\nWe want to make the product of all ...
[{"input": "22\n99039804 -580368436 -694542422 231508622 -490965348 958087037 -570157955 560902976 -840005981 -1381720926 -708462966 639575552 119982241 -631099451 -154223559 102960509 -225552439 507250810 -712228569 989896753 1574991855 1\n", "output": "12773524192\n"}, {"input": "22\n99039804 -580368436 -694542422 23...
code_stdio
[ { "content": "There are times you recall a good old friend and everything you've come through together. Luckily there are social networks — they store all your message history making it easy to know what you argued over 10 years ago.\n\nMore formal, your message history is a sequence of messages ordered by time...
[{"input": "100 7\n0 1 1 1 0 5 6 6 8 8 9 11 12 11 8 0 0 14 6 16 7 21 15 23 15 24 0 0 0 28 0 29 26 27 19 1 0 21 37 32 40 30 37 34 39 38 34 38 0 0 41 24 45 47 0 33 46 26 31 0 21 57 57 18 63 63 20 59 65 56 68 0 30 55 55 0 70 43 59 49 59 79 66 74 0 11 65 0 80 63 0 84 73 49 73 81 0 86 76 20\n", "output": "8 9 10 11 12 13 14...
code_stdio
[ { "content": "Vanya has a table consisting of 100 rows, each row contains 100 cells. The rows are numbered by integers from 1 to 100 from bottom to top, the columns are numbered from 1 to 100 from left to right. \n\nIn this table, Vanya chose n rectangles with sides that go along borders of squares (some rectan...
[{"input": "5\n4 11 20 20\n6 11 20 16\n5 1 33 15\n11 3 18 21\n3 2 14 21\n", "output": "1087\n"}, {"input": "5\n4 11 20 22\n6 11 20 16\n5 1 34 15\n11 3 18 21\n3 1 14 11\n", "output": "1028\n"}, {"input": "5\n4 11 20 38\n6 11 20 16\n5 2 19 15\n11 3 18 15\n3 2 14 11\n", "output": "1000\n"}, {"input": "5\n4 11 20 20\n6 11 ...
code_stdio
[ { "content": "For a given polygon g, print \"1\" if g is a convex polygon, \"0\" otherwise. Here, in a convex polygon, all interior angles are less than or equal to 180 degrees.\n\ng is represented by a sequence of points p1, p2,..., pn where line segments connecting pi and pi+1 (1 ≤ i ≤ n-1) are sides of the p...
[{"input": "4\n-1 1\n25 -3\n1 0\n-1 -1", "output": "0\n"}, {"input": "4\n-1 1\n25 -3\n1 -1\n-1 0", "output": "0\n"}, {"input": "4\n-1 1\n25 -3\n1 -1\n-1 1", "output": "0\n"}, {"input": "4\n-1 2\n25 -3\n1 -1\n-1 1", "output": "0\n"}, {"input": "4\n-1 2\n25 -3\n0 -1\n-1 1", "output": "0\n"}, {"input": "4\n-1 4\n25 -3\n0 ...
code_stdio