messages listlengths 1 1 | ground_truth stringlengths 156 726k | dataset stringclasses 1
value |
|---|---|---|
[
{
"content": "There are N towns located in a line, conveniently numbered 1 through N. Takahashi the merchant is going on a travel from town 1 to town N, buying and selling apples.\nTakahashi will begin the travel at town 1, with no apple in his possession. The actions that can be performed during the travel are... | [{"input": "10 100\n7 10 4 5 9 3 6 8 2 1\n", "output": "2\n"}, {"input": "10 100\n7 10 4 5 9 3 6 8 1 1", "output": "2\n"}, {"input": "10 100\n7 10 4 5 9 3 6 8 2 1", "output": "2"}, {"input": "5 8\n50 30 40 10 20\n", "output": "2\n"}, {"input": "5 10\n21 30 40 10 20", "output": "1\n"}, {"input": "5 10\n21 30 40 10 31", ... | code_stdio |
[
{
"content": "Haruna is a high school student. She must remember the seating arrangements in her class because she is a class president. It is too difficult task to remember if there are so many students.\n\nThat is the reason why seating rearrangement is depress task for her. But students have a complaint if s... | [{"input": "1 2\n11 0\n0 0", "output": "yes\nyes\n"}, {"input": "2 1\n10 0\n0 0", "output": "yes\nyes\n"}, {"input": "1 4\n11 0\n0 0", "output": "yes\nyes\n"}, {"input": "2 -1\n8 0\n0 0", "output": "yes\nyes\n"}, {"input": "3 0\n4 -1\n0 0", "output": "yes\nyes\n"}, {"input": "2 2\n4 -1\n0 0", "output": "yes\nyes\n"}, {... | code_stdio |
[
{
"content": "Not long ago Billy came across such a problem, where there were given three natural numbers A, B and C from the range [1, N], and it was asked to check whether the equation AB = C is correct. Recently Billy studied the concept of a digital root of a number. We should remind you that a digital root... | [{"input": "1000000\n", "output": "111111074060178115\n"}, {"input": "987572\n", "output": "107019643962508968\n"}, {"input": "983242\n", "output": "105618162572849728\n"}, {"input": "600000\n", "output": "23999973325791164\n"}, {"input": "783472\n", "output": "53435215015075583\n"}, {"input": "729761\n", "output": "43... | code_stdio |
[
{
"content": "Fox Ciel starts to learn programming. The first task is drawing a fox! However, that turns out to be too hard for a beginner, so she decides to draw a snake instead.\n\nA snake is a pattern on a n by m table. Denote c-th cell of r-th row as (r, c). The tail of the snake is located at (1, 1), then ... | [{"input": "49 50\n", "output": "##################################################\n.................................................#\n##################################################\n#.................................................\n##################################################\n.............................. | code_stdio |
[
{
"content": "You can perfectly predict the price of a certain stock for the next N days. You would like to profit on this knowledge, but only want to transact one share of stock per day. That is, each day you will either buy one share, sell one share, or do nothing. Initially you own zero shares, and you canno... | [{"input": "100\n411 642 560 340 276 440 515 519 182 314 35 227 390 136 97 5 502 584 567 79 543 444 413 463 455 316 545 329 437 443 9 435 291 384 328 501 603 234 285 297 453 587 550 72 130 163 282 298 605 349 270 198 24 179 243 92 115 56 83 26 3 456 622 325 366 360 299 153 140 552 216 117 61 307 278 189 496 562 38 527 ... | code_stdio |
[
{
"content": "A monster is attacking the Cyberland!\n\nMaster Yang, a braver, is going to beat the monster. Yang and the monster each have 3 attributes: hitpoints (HP), offensive power (ATK) and defensive power (DEF).\n\nDuring the battle, every second the monster's HP decrease by max(0, ATK_{Y} - DEF_{M}), whi... | [{"input": "100 100 100\n100 100 100\n100 100 100\n", "output": "100\n"}, {"input": "100 100 100\n100 100 100\n100 100 100\n", "output": "100\n"}, {"input": "50 100 51\n100 100 100\n1 100 100\n", "output": "1384\n"}, {"input": "100 100 1\n100 100 100\n1 100 100\n", "output": "1891\n"}, {"input": "100 100 1\n100 100 100... | code_stdio |
[
{
"content": "Petya's friends made him a birthday present — a bracket sequence. Petya was quite disappointed with his gift, because he dreamed of correct bracket sequence, yet he told his friends nothing about his dreams and decided to fix present himself. \n\nTo make everything right, Petya is going to move at... | [{"input": "500\n())()())((()(()((())())(())())()((()(()()))())())))()())())())()())))(()))))((((())(((()(())))()()(()))())(((((()()(((())()((()((())()))()())()))))()))()(((()(())((()()((()())()))((((())(())))()(()(())((((((()()()())))((()())(((((()()(((()))((()((()))())(((())((((()))))))))()()()))(())(())()())((((((((... | code_stdio |
[
{
"content": "We will define the median of a sequence b of length M, as follows:\n - Let b' be the sequence obtained by sorting b in non-decreasing order. Then, the value of the (M / 2 + 1)-th element of b' is the median of b. Here, / is integer division, rounding down.\nFor example, the median of (10, 30, 20) ... | [{"input": "10\n15 -1 6 0 -1 7 -1 19 1 3", "output": "3\n"}, {"input": "10\n15 -1 6 0 -1 7 -1 11 1 3", "output": "3\n"}, {"input": "10\n15 -1 6 1 -1 7 -1 11 1 3", "output": "3\n"}, {"input": "10\n15 -1 6 2 -1 7 -1 11 1 3", "output": "3\n"}, {"input": "10\n15 -1 6 4 -1 7 -1 11 1 3", "output": "4\n"}, {"input": "10\n15 -... | code_stdio |
[
{
"content": "Dawid has four bags of candies. The $i$-th of them contains $a_i$ candies. Also, Dawid has two friends. He wants to give each bag to one of his two friends. Is it possible to distribute the bags in such a way that each friend receives the same amount of candies in total?\n\nNote, that you can't ke... | [{"input": "100 100 100 100\n", "output": "YES\n"}, {"input": "100 100 100 100\n", "output": "YES\n"}, {"input": "100 100 000 100\n", "output": "NO\n"}, {"input": "100 100 99 100\n", "output": "NO\n"}, {"input": "100 100 99 100\n", "output": "NO\n"}, {"input": "100 000 99 100\n", "output": "NO\n"}, {"input": "100 98 99... | code_stdio |
[
{
"content": "An array of integers $p_1, p_2, \\dots, p_n$ is called a permutation if it contains each number from $1$ to $n$ exactly once. For example, the following arrays are permutations: $[3, 1, 2]$, $[1]$, $[1, 2, 3, 4, 5]$ and $[4, 3, 1, 2]$. The following arrays are not permutations: $[2]$, $[1, 1]$, $[... | [{"input": "5\n-1 2 -3 -1\n", "output": "4 3 5 2 1 "}, {"input": "5\n-1 2 -3 -1\n", "output": "4 3 5 2 1 "}, {"input": "5\n3 -2 1 -3\n", "output": "2 5 3 4 1 "}, {"input": "5\n-4 1 2 -1\n", "output": "5 1 2 4 3 "}, {"input": "5\n-4 1 2 -1\n", "output": "5 1 2 4 3 "}, {"input": "5\n3 -2 1 -3\n", "output": "2 5 3 4 1 "},... | code_stdio |
[
{
"content": "You are playing some computer game. One of its levels puts you in a maze consisting of n lines, each of which contains m cells. Each cell either is free or is occupied by an obstacle. The starting cell is in the row r and column c. In one step you can move one square up, left, down or right, if th... | [{"input": "21 7\n3 6\n5 2\n......*\n.****.*\n.****.*\n....*.*\n**.**.*\n**.**.*\n**.**.*\n**.**.*\n**.**.*\n**.**.*\n**.**.*\n**.**.*\n**.**.*\n**.**.*\n**.**.*\n**.**.*\n**.**.*\n**.**.*\n**....*\n**....*\n*******\n", "output": "51\n"}, {"input": "21 7\n3 6\n5 2\n......*\n.****.*\n.****.*\n....*.*\n**.**.*\n**.**.*\n... | code_stdio |
[
{
"content": "User ainta has a permutation p_1, p_2, ..., p_{n}. As the New Year is coming, he wants to make his permutation as pretty as possible.\n\nPermutation a_1, a_2, ..., a_{n} is prettier than permutation b_1, b_2, ..., b_{n}, if and only if there exists an integer k (1 ≤ k ≤ n) where a_1 = b_1, a_2 = b... | [{"input": "15\n6 1 2 7 9 13 14 8 4 5 3 12 10 15 11\n000100100100100\n000010010010010\n000001001001001\n100000100100100\n010000010010010\n001000001001001\n100100000100100\n010010000010010\n001001000001001\n100100100000100\n010010010000010\n001001001000001\n100100100100000\n010010010010000\n001001001001000\n", "output":... | code_stdio |
[
{
"content": "You are given a string $s$ consisting of $n$ lowercase Latin letters. $n$ is even.\n\nFor each position $i$ ($1 \\le i \\le n$) in string $s$ you are required to change the letter on this position either to the previous letter in alphabetic order or to the next one (letters 'a' and 'z' have only o... | [{"input": "50\n6\nbxyxcz\n4\nzzcy\n2\nzb\n2\nyb\n6\nzzbxyx\n4\nbxzb\n4\naaca\n4\nbzyx\n4\nxaac\n2\nbb\n2\nzb\n6\ncabcbb\n6\nyxzbbb\n2\nxz\n2\ncc\n6\nazcaza\n4\nyyaa\n2\nxb\n2\nyb\n6\nzaxxxz\n4\nbyab\n4\naxxz\n2\nay\n2\nyb\n2\ncx\n4\nzyab\n6\nybcyya\n6\nxayzaz\n4\nzacx\n6\nzzyxbz\n2\ncc\n4\nbycx\n2\nza\n4\naaxz\n6\nczy... | code_stdio |
[
{
"content": "For the multiset of positive integers s=\\\\{s_1,s_2,...,s_k\\}, define the Greatest Common Divisor (GCD) and Least Common Multiple (LCM) of s as follow:\n\n * \\gcd(s) is the maximum positive integer x, such that all integers in s are divisible on x.\n * lcm(s) is the minimum positive integer x... | [{"input": "10\n972 972 324 972 324 648 1944 243 324 474\n", "output": "162\n"}, {"input": "10\n61 1677 535 769 324 1309 1589 243 324 184\n", "output": "1\n"}, {"input": "10\n61 1677 535 769 627 1309 1589 243 324 184\n", "output": "1\n"}, {"input": "10\n54 972 224 392 324 809 1589 243 324 1357\n", "output": "1\n"}, {"i... | code_stdio |
[
{
"content": "Natasha is going to fly to Mars. She needs to build a rocket, which consists of several stages in some order. Each of the stages is defined by a lowercase Latin letter. This way, the rocket can be described by the string — concatenation of letters, which correspond to the stages.\n\nThere are $n$ ... | [{"input": "50 13\nqwertyuiopasdfghjklzxcvbnmaaaaaaaaaaaaaaaaaaaaaaaa\n", "output": "169\n"}, {"input": "50 13\nqwertyuiopasdfghjklzxcvbnmaaaaaaaaaaaaaaaaaaaaaaaa\n", "output": "169"}, {"input": "50 31\nahbyyoxltryqdmvenemaqnbakglgqolxnaifnqtoclnnqiabpz\n", "output": "-1\n"}, {"input": "50 14\nqwertyuiopasdfghjklzxcvbn... | code_stdio |
[
{
"content": "We have a tree with N vertices and N-1 edges, respectively numbered 1, 2,\\cdots, N and 1, 2, \\cdots, N-1. Edge i connects Vertex u_i and v_i.\nFor integers L, R (1 \\leq L \\leq R \\leq N), let us define a function f(L, R) as follows:\n - Let S be the set of the vertices numbered L through R. f(... | [{"input": "10\n5 4\n5 7\n-1 13\n0 9\n12 10\n4 11\n7 4\n11 10\n7 4", "output": "152\n"}, {"input": "10\n5 16\n5 6\n-1 24\n1 10\n13 10\n4 6\n13 4\n6 3\n7 3", "output": "187\n"}, {"input": "10\n5 16\n5 6\n-1 24\n1 10\n13 10\n4 6\n13 4\n6 5\n7 3", "output": "177\n"}, {"input": "10\n1 16\n5 6\n-1 24\n1 10\n13 10\n4 6\n13 4... | code_stdio |
[
{
"content": "You've probably heard about the twelve labors of Heracles, but do you have any idea about the thirteenth? It is commonly assumed it took him a dozen years to complete the twelve feats, so on average, a year to accomplish every one of them. As time flows faster these days, you have minutes rather t... | [{"input": "4\n4\n3 5 4 5\n2 1\n3 1\n4 3\n2\n21 32\n2 1\n6\n13 13 17 13 13 22\n2 1\n3 1\n4 2\n5 1\n6 1\n4\n10 11 3 11\n1 2\n2 3\n4 1\n", "output": "17 21 24\n53\n91 104 117 130 143\n35 46 56\n"}, {"input": "4\n4\n3 5 4 12\n2 1\n3 1\n4 3\n2\n21 32\n2 1\n6\n13 13 17 13 13 22\n2 1\n3 1\n4 1\n5 1\n6 1\n4\n10 6 3 11\n1 2\n2... | code_stdio |
[
{
"content": "Takahashi has N sticks that are distinguishable from each other. The length of the i-th stick is L_i.\nHe is going to form a triangle using three of these sticks. Let a, b, and c be the lengths of the three sticks used. Here, all of the following conditions must be satisfied:\n - a < b + c\n - b <... | [{"input": "2000\n1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 10... | code_stdio |
[
{
"content": "A country decides to build a palace.\nIn this country, the average temperature of a point at an elevation of x meters is T-x \\times 0.006 degrees Celsius.\nThere are N places proposed for the place. The elevation of Place i is H_i meters.\nAmong them, Princess Joisino orders you to select the pla... | [{"input": "1000\n20 -20\n51765 34765 54644 24887 70030 45034 46376 88410 33772 52941 79750 44783 70874 36236 36651 16147 23251 11281 36605 69084 74679 18310 88655 92253 0 76064 82769 20419 60361 61197 51619 35110 6063 82815 99426 22379 61759 34008 31814 22642 80907 10203 11864 18291 34343 35250 99120 14402 54252 92425... | code_stdio |
[
{
"content": "One day n friends met at a party, they hadn't seen each other for a long time and so they decided to make a group photo together. \n\nSimply speaking, the process of taking photos can be described as follows. On the photo, each photographed friend occupies a rectangle of pixels: the i-th of them o... | [{"input": "10\n10 1000\n10 1000\n10 1000\n10 1000\n10 1000\n10 1000\n10 1000\n10 1000\n10 1000\n10 1000\n", "output": "90000 90000 90000 90000 90000 90000 90000 90000 90000 90000 "}, {"input": "10\n10 1000\n10 1000\n10 1000\n10 1000\n10 1000\n10 1000\n10 1000\n10 1000\n10 1000\n10 1000\n", "output": "90000 90000 90000... | code_stdio |
[
{
"content": "Kattapa, as you all know was one of the greatest warriors of his time. The kingdom of Maahishmati had never lost a battle under him (as army-chief), and the reason for that was their really powerful army, also called as Mahasena.\n\nKattapa was known to be a very superstitious person. He believed ... | [{"input": "5\n12 -1 -2 -2 -2", "output": "READY FOR BATTLE\n"}, {"input": "5\n2 -1 -2 -2 -2", "output": "READY FOR BATTLE\n"}, {"input": "5\n2 -1 -1 -2 -2", "output": "READY FOR BATTLE\n"}, {"input": "5\n4 -1 -1 -2 -2", "output": "READY FOR BATTLE\n"}, {"input": "5\n4 -1 -2 -2 -2", "output": "READY FOR BATTLE\n"}, {"i... | code_stdio |
[
{
"content": "You have r red, g green and b blue balloons. To decorate a single table for the banquet you need exactly three balloons. Three balloons attached to some table shouldn't have the same color. What maximum number t of tables can be decorated if we know number of balloons of each color?\n\nYour task i... | [{"input": "1000000000 1000000000 1000000000\n", "output": "1000000000\n"}, {"input": "1000000000 2000000000 1000000000\n", "output": "1333333333\n"}, {"input": "2000000000 2000000000 2000000000\n", "output": "2000000000\n"}, {"input": "1585222789 1889821127 2000000000\n", "output": "1825014638\n"}, {"input": "20000000... | code_stdio |
[
{
"content": "There is a board with a grid consisting of n rows and m columns, the rows are numbered from 1 from top to bottom and the columns are numbered from 1 from left to right. In this grid we will denote the cell that lies on row number i and column number j as (i, j).\n\nA group of six numbers (a, b, c,... | [{"input": "500 500 249995\n", "output": " 0\n"}, {"input": "500 500 249999\n", "output": " 0\n"}, {"input": "500 500 249993\n", "output": " ... | code_stdio |
[
{
"content": "You are given two strings A and B representing essays of two students who are suspected cheaters. For any two strings C, D we define their similarity score S(C,D) as 4⋅ LCS(C,D) - |C| - |D|, where LCS(C,D) denotes the length of the Longest Common Subsequence of strings C and D. \n\nYou believe tha... | [{"input": "175 190\nqnnnnnnnnnnrnnnnrnrnnnnnrnnnnrqnnnnnnannnnnnnrnrrnrnnnnnrnnrnnnnnnrnrnnnnnrnnnannnrrnnnnrnnnnnnnnnnnrnannnnnrnnnnrnnnnrnnnnnnrnarnnnnnnnnanrnnnnnnnrnnrrnrnrrnnnnnrnnnnnrnnnnnn\nnnnnnrnnnnrnnnnnrnnnnnnrnnqnnnnnnrnnnnnnnrnnrnnnnrnqnannnnnnnannnnnnnrnrnnnrnnnnrnnnnnnnrrnqnnnnnnnnnnnrnrnnrannnnrnnnnrnr... | code_stdio |
[
{
"content": "In a long narrow forest stretching east-west, there are N beasts. Below, we will call the point that is p meters from the west end Point p. The i-th beast from the west (1 ≤ i ≤ N) is at Point x_i, and can be sold for s_i yen (the currency of Japan) if captured.\n\nYou will choose two integers L a... | [{"input": "4\n1 101\n10 152\n812494145527274 53\n1000000000110000 151", "output": "244\n"}, {"input": "4\n2 101\n10 152\n812494145527274 53\n1000000010110000 151", "output": "245\n"}, {"input": "4\n0 101\n10 152\n812494145527274 53\n1000000010110000 151", "output": "243\n"}, {"input": "4\n0 101\n10 242\n48251700863794... | code_stdio |
[
{
"content": "Neko is playing with his toys on the backyard of Aki's house. Aki decided to play a prank on him, by secretly putting catnip into Neko's toys. Unfortunately, he went overboard and put an entire bag of catnip into the toys...\n\nIt took Neko an entire day to turn back to normal. Neko reported to Ak... | [{"input": "1000\n", "output": "143886430\n"}, {"input": "450\n", "output": "690479399\n"}, {"input": "999\n", "output": "742390865\n"}, {"input": "900\n", "output": "454329300\n"}, {"input": "500\n", "output": "660474384\n"}, {"input": "996\n", "output": "666557857\n"}, {"input": "998\n", "output": "311781222\n"}, {"i... | code_stdio |
[
{
"content": "Simon has a prime number x and an array of non-negative integers a_1, a_2, ..., a_{n}.\n\nSimon loves fractions very much. Today he wrote out number $\\frac{1}{x^{a} 1} + \\frac{1}{x^{a_{2}}} + \\ldots + \\frac{1}{x^{a_{n}}}$ on a piece of paper. After Simon led all fractions to a common denominat... | [{"input": "26 7\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 2\n", "output": "49\n"}, {"input": "26 7\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 2\n", "output": "49\n"}, {"input": "26 2\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 2\n", "output": "8\n"}, {"input": "26 2\n0 0 0 0 0 0 0 0 0 0 0 0 0 0... | code_stdio |
[
{
"content": "Like any unknown mathematician, Yuri has favourite numbers: $A$, $B$, $C$, and $D$, where $A \\leq B \\leq C \\leq D$. Yuri also likes triangles and once he thought: how many non-degenerate triangles with integer sides $x$, $y$, and $z$ exist, such that $A \\leq x \\leq B \\leq y \\leq C \\leq z \... | [{"input": "86565 229134 356183 486713\n", "output": "1559833368660730\n"}, {"input": "90528 225462 336895 417903\n", "output": "1043176084391535\n"}, {"input": "178561 294901 405737 476436\n", "output": "911664147520700\n"}, {"input": "145490 215252 362118 413147\n", "output": "498858571439550\n"}, {"input": "108250 2... | code_stdio |
[
{
"content": "You are playing a variation of game 2048. Initially you have a multiset $s$ of $n$ integers. Every integer in this multiset is a power of two. \n\nYou may perform any number (possibly, zero) operations with this multiset.\n\nDuring each operation you choose two equal integers from $s$, remove them... | [{"input": "6\n4\n1024 512 64 512\n1\n2048\n3\n128 512 2\n2\n4096 8\n1\n2048 2 2048 2048 2048 2048 2048\n2\n2048 4898\n", "output": "YES\nYES\nNO\nNO\nYES\nYES\n"}, {"input": "6\n4\n1024 512 64 512\n1\n2048\n3\n64 512 2\n2\n4096 4\n7\n2048 2 2048 2048 2048 2048 2048\n2\n2048 4096\n", "output": "YES\nYES\nNO\nNO\nYES\nY... | code_stdio |
[
{
"content": "Write a program which calculates the area and perimeter of a given rectangle.\n\nConstraints\n\n* 1 ≤ a, b ≤ 100\n\nInput\n\nThe length a and breadth b of the rectangle are given in a line separated by a single space.\n\nOutput\n\nPrint the area and perimeter of the rectangle in a line. The two in... | [{"input": "-10 2", "output": "-20 -16\n"}, {"input": "-16 -2", "output": "32 -36\n"}, {"input": "-16 -1", "output": "16 -34\n"}, {"input": "-16 1", "output": "-16 -30\n"}, {"input": "4 122", "output": "488 252\n"}, {"input": "1 122", "output": "122 246\n"}, {"input": "1 -10", "output": "-10 -18\n"}, {"input": "-8 2", ... | code_stdio |
[
{
"content": "You are given two positive integers $a$ and $b$.\n\nIn one move, you can change $a$ in the following way:\n\n Choose any positive odd integer $x$ ($x > 0$) and replace $a$ with $a+x$; choose any positive even integer $y$ ($y > 0$) and replace $a$ with $a-y$. \n\nYou can perform as many such oper... | [{"input": "5\n2 3\n10 10\n2 4\n7 4\n9 3\n", "output": "1\n0\n2\n2\n1\n"}, {"input": "5\n2 3\n10 10\n2 4\n4 4\n9 3\n", "output": "1\n0\n2\n0\n1\n"}, {"input": "5\n2 3\n10 10\n2 7\n4 4\n9 3\n", "output": "1\n0\n1\n0\n1\n"}, {"input": "5\n2 3\n10 10\n2 2\n4 4\n9 3\n", "output": "1\n0\n0\n0\n1\n"}, {"input": "5\n2 2\n10 1... | code_stdio |
[
{
"content": "Vlad went into his appartment house entrance, now he is on the $1$-th floor. He was going to call the elevator to go up to his apartment.\n\nThere are only two elevators in his house. Vlad knows for sure that:\n\nthe first elevator is currently on the floor $a$ (it is currently motionless),\n\nthe... | [{"input": "69\n1 2 3\n3 1 2\n3 2 1\n1 2 3\n3 1 2\n3 2 1\n1 2 3\n3 1 2\n3 2 1\n1 2 3\n3 1 2\n3 2 1\n1 2 3\n3 1 2\n3 2 1\n1 2 3\n3 1 2\n3 2 1\n1 2 3\n3 1 2\n3 2 1\n1 2 3\n3 1 2\n3 2 1\n1 2 3\n3 1 2\n3 2 1\n1 2 3\n3 1 2\n3 2 1\n1 2 3\n3 1 2\n3 2 1\n1 2 3\n3 1 2\n3 2 1\n1 2 3\n3 1 2\n3 2 1\n1 2 3\n3 1 2\n3 2 1\n1 2 3\n3 1... | code_stdio |
[
{
"content": "We have a grid with 3 rows and N columns. The cell at the i-th row and j-th column is denoted (i, j). Initially, each cell (i, j) contains the integer i+3j-3.\n\n<image>\n\nA grid with N=5 columns\n\nSnuke can perform the following operation any number of times:\n\n* Choose a 3×3 subrectangle of t... | [{"input": "7\n21 12 1 16 14 6 10\n20 11 0 27 14 7 8\n19 10 3 18 7 4 12", "output": "No\n"}, {"input": "7\n21 12 1 16 14 6 10\n20 12 0 27 14 7 8\n19 10 3 18 7 4 12", "output": "No\n"}, {"input": "7\n21 12 1 16 12 6 10\n20 12 0 27 14 7 8\n19 10 3 18 7 4 12", "output": "No\n"}, {"input": "7\n21 12 1 16 13 6 7\n20 11 2 20... | code_stdio |
[
{
"content": "The letters shop showcase is a string s, consisting of n lowercase Latin letters. As the name tells, letters are sold in the shop.\n\nLetters are sold one by one from the leftmost to the rightmost. Any customer can only buy some prefix of letters from the string s.\n\nThere are m friends, the i-th... | [{"input": "100\nwjtwxtttttxjjwxtjtttwxjwjjwjxtwwxxwwwtwttwxjxxjxwxwjtjjwxxxxwwtwtxjxwtwtjjjxwjxjtwwwwtjtttjjtxtwtxjw\n10\nxwjxjwxtwwj\nwxjxxjxjx\nwtjxxxjxjxtwt\njwwxj\njtwjtxjxttxwtw\nwtwxjjjttjx\nwwwjtxw\ntjxjwtjwtw\ntjwtjjxtxjwt\nwxwtxtjw\n", "output": "21\n29\n29\n12\n15\n17\n21\n14\n17\n14\n"}, {"input": "100\nwjt... | code_stdio |
[
{
"content": "Let a_1, …, a_n be an array of n positive integers. In one operation, you can choose an index i such that a_i = i, and remove a_i from the array (after the removal, the remaining parts are concatenated).\n\nThe weight of a is defined as the maximum number of elements you can remove.\n\nYou must an... | [{"input": "30 10\n1 1 3 3 5 2 1 8 2 6 11 5 2 6 12 11 8 5 11 3 14 8 16 13 14 25 16 2 8 17\n6 3\n0 15\n1 0\n9 2\n12 16\n1 0\n17 3\n14 13\n0 22\n3 10\n", "output": "3\n15\n16\n2\n0\n16\n0\n0\n8\n4\n"}, {"input": "30 10\n1 1 3 3 5 2 1 8 2 6 11 5 2 6 12 11 8 5 11 3 14 3 16 13 14 25 16 2 8 17\n6 3\n0 15\n1 0\n9 2\n12 16\n1 ... | code_stdio |
[
{
"content": "Iahub and Iahubina went to a picnic in a forest full of trees. Less than 5 minutes passed before Iahub remembered of trees from programming. Moreover, he invented a new problem and Iahubina has to solve it, otherwise Iahub won't give her the food. \n\nIahub asks Iahubina: can you build a rooted tr... | [{"input": "24\n1 2 3 4 5 10 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24\n", "output": "NO\n"}, {"input": "24\n5 3 3 4 2 6 7 14 9 10 11 12 13 14 29 16 17 18 19 25 31 22 23 24\n", "output": "NO\n"}, {"input": "24\n5 3 3 4 2 6 7 14 9 10 11 12 13 14 29 16 17 18 19 25 31 22 23 37\n", "output": "NO\n"}, {"input": "24... | code_stdio |
[
{
"content": "Vitya is studying in the third grade. During the last math lesson all the pupils wrote on arithmetic quiz. Vitya is a clever boy, so he managed to finish all the tasks pretty fast and Oksana Fillipovna gave him a new one, that is much harder.\n\nLet's denote a flip operation of an integer as follo... | [{"input": "1000000000000000000000001\n", "output": "1000000000000000000000000\n"}, {"input": "2442173122931392213712431\n", "output": "1776586566965695556855660"}, {"input": "9009900990099009900990098\n", "output": "4555455545554454445444544"}, {"input": "1000000177157517600000001\n", "output": "1000000088578758800000... | code_stdio |
[
{
"content": "Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. \n\nChef is playing a game with his friend Misha. They have a pile containg N coins. Players take alternate turns, removing some coins from the pile. On each turn, a player can remove either one coin or coins equal to so... | [{"input": "2\n-12\n-6", "output": "Misha\nMisha\n"}, {"input": "2\n-12\n-1", "output": "Misha\nChef\n"}, {"input": "2\n-11\n-6", "output": "Chef\nMisha\n"}, {"input": "2\n-15\n-6", "output": "Chef\nMisha\n"}, {"input": "2\n-6\n-10", "output": "Misha\nChef\n"}, {"input": "2\n-6\n-11", "output": "Misha\nChef\n"}, {"inpu... | code_stdio |
[
{
"content": "Polycarp is reading a book consisting of $n$ pages numbered from $1$ to $n$. Every time he finishes the page with the number divisible by $m$, he writes down the last digit of this page number. For example, if $n=15$ and $m=5$, pages divisible by $m$ are $5, 10, 15$. Their last digits are $5, 0, 5... | [{"input": "7\n1 1\n10 1\n100 3\n1024 14\n998244353 1337\n123 144\n1234312817382646 13\n", "output": "1\n45\n153\n294\n3359835\n0\n427262129093995\n"}, {"input": "7\n1 1\n10 2\n100 3\n1024 14\n998244353 1337\n123 144\n1234312817382646 13\n", "output": "1\n20\n153\n294\n3359835\n0\n427262129093995\n"}, {"input": "7\n1 1... | code_stdio |
[
{
"content": "Two semifinals have just been in the running tournament. Each semifinal had n participants. There are n participants advancing to the finals, they are chosen as follows: from each semifinal, we choose k people (0 ≤ 2k ≤ n) who showed the best result in their semifinals and all other places in the ... | [{"input": "8\n100 101\n200 201\n300 301\n310 400\n320 500\n330 600\n340 700\n350 800\n", "output": "11111000\n11110000\n"}, {"input": "8\n100 101\n200 201\n300 301\n310 400\n320 500\n330 600\n340 700\n350 800\n", "output": "11111000\n11110000\n"}, {"input": "8\n100 101\n200 201\n300 157\n310 400\n320 500\n330 600\n340... | code_stdio |
[
{
"content": "Bob has a rectangular chocolate bar of the size W × H. He introduced a cartesian coordinate system so that the point (0, 0) corresponds to the lower-left corner of the bar, and the point (W, H) corresponds to the upper-right corner. Bob decided to split the bar into pieces by breaking it. Each bre... | [{"input": "9 8 5\n4 3 4 4\n0 4 9 4\n5 4 5 8\n0 3 9 3\n1 4 1 8\n", "output": "4 4 5 16 16 27 \n"}, {"input": "10 10 4\n9 0 9 10\n4 0 4 10\n1 0 1 10\n1 4 4 4\n", "output": "10 10 12 18 50 \n"}, {"input": "14 10 4\n9 0 9 10\n4 0 4 10\n1 0 1 10\n1 4 4 4\n", "output": "10 12 18 50 50\n"}, {"input": "16 10 4\n9 0 9 10\n4 0 ... | code_stdio |
[
{
"content": "If the girl doesn't go to Denis, then Denis will go to the girl. Using this rule, the young man left home, bought flowers and went to Nastya. \n\nOn the way from Denis's house to the girl's house is a road of n lines. This road can't be always crossed in one green light. Foreseeing this, the good ... | [{"input": "30 8\n0 1 13 12 23 24 26 30\n40 7\n", "output": "30\n"}, {"input": "30 8\n0 1 9 12 23 24 26 30\n40 7\n", "output": "30\n"}, {"input": "30 8\n0 1 9 12 23 24 26 30\n27 7\n", "output": "41\n"}, {"input": "30 8\n0 1 9 10 23 24 26 30\n71 7\n", "output": "30\n"}, {"input": "30 8\n0 1 9 10 23 24 26 30\n71 2\n", "o... | code_stdio |
[
{
"content": "Bob is an active user of the social network Faithbug. On this network, people are able to engage in a mutual friendship. That is, if $a$ is a friend of $b$, then $b$ is also a friend of $a$. Each user thus has a non-negative amount of friends.\n\nThis morning, somebody anonymously sent Bob the fol... | [{"input": "35\n21 26 18 7 28 2 16 13 16 25 6 32 11 5 31 17 18 3 24 33 14 27 29 1 20 4 12 9 10 30 34 8 19 23 22\n", "output": "0 2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 \n"}, {"input": "35\n21 26 18 4 28 3 15 13 16 25 6 25 11 5 31 17 9 3 24 33 14 27 29 1 20 4 12 7 10 30 34 8 19 23 22\n", "output": "5 7 9 11 13 1... | code_stdio |
[
{
"content": "You are given a rectangle grid. That grid's size is n × m. Let's denote the coordinate system on the grid. So, each point on the grid will have coordinates — a pair of integers (x, y) (0 ≤ x ≤ n, 0 ≤ y ≤ m).\n\nYour task is to find a maximum sub-rectangle on the grid (x_1, y_1, x_2, y_2) so that i... | [{"input": "1000000000 1000000000 286536427 579261823 230782719 575570138\n", "output": "171145067 291476754 401927786 867046892\n"}, {"input": "1000000000 1000000000 623214043 753726318 970868535 929707704\n", "output": "29131465 70292296 1000000000 1000000000\n"}, {"input": "1000000000 1000000000 500000000 500000000 ... | code_stdio |
[
{
"content": "[THE SxPLAY & KIVΛ - 漂流](https://soundcloud.com/kivawu/hyouryu)\n\n[KIVΛ & Nikki Simmons - Perspectives](https://soundcloud.com/kivawu/perspectives)\n\nWith a new body, our idol Aroma White (or should we call her Kaori Minamiya?) begins to uncover her lost past through the OS space.\n\nThe space c... | [{"input": "10000000000000000 10000000000000000 100 100 10000000000000000 10000000000000000\n10000000000000000 10000000000000000 10000000000000000\n", "output": "1\n"}, {"input": "10000000000000000 10000000000000000 100 100 10000000000000000 10000000000000000\n10000000000000000 10000000000000000 10000000100000000\n", "... | code_stdio |
[
{
"content": "La Confiserie d'ABC sells cakes at 4 dollars each and doughnuts at 7 dollars each.\nDetermine if there is a way to buy some of them for exactly N dollars. You can buy two or more doughnuts and two or more cakes, and you can also choose to buy zero doughnuts or zero cakes.\n\n-----Constraints-----\... | [{"input": "100\n", "output": "Yes\n"}, {"input": "11\n", "output": "Yes\n"}, {"input": "40\n", "output": "Yes\n"}, {"input": "12\n", "output": "Yes\n"}, {"input": "15\n", "output": "Yes\n"}, {"input": "16\n", "output": "Yes\n"}, {"input": "19\n", "output": "Yes\n"}, {"input": "20\n", "output": "Yes\n"}, {"input": "56\... | code_stdio |
[
{
"content": "Innovation technologies are on a victorious march around the planet. They integrate into all spheres of human activity!\n\nA restaurant called \"Dijkstra's Place\" has started thinking about optimizing the booking system. \n\nThere are n booking requests received by now. Each request is characteri... | [{"input": "10\n739 307\n523 658\n700 143\n373 577\n120 433\n353 833\n665 516\n988 101\n817 604\n800 551\n10\n431 425 227 147 153 170 954 757 222 759\n", "output": "6 3621\n6 2\n2 8\n9 7\n4 1\n7 10\n5 4\n"}, {"input": "10\n739 307\n523 658\n700 143\n373 577\n120 433\n353 833\n665 516\n988 101\n817 604\n800 551\n10\n431... | code_stdio |
[
{
"content": "You are given a tree with $n$ vertices. You are allowed to modify the structure of the tree through the following multi-step operation: Choose three vertices $a$, $b$, and $c$ such that $b$ is adjacent to both $a$ and $c$. For every vertex $d$ other than $b$ that is adjacent to $a$, remove the e... | [{"input": "15\n4 6\n8 4\n12 11\n7 6\n9 8\n5 1\n14 13\n6 13\n1 4\n1 2\n6 11\n10 8\n15 14\n3 1\n", "output": "4\n"}, {"input": "15\n4 6\n8 4\n12 11\n7 6\n9 8\n5 1\n14 13\n6 13\n1 4\n1 2\n6 11\n10 8\n15 14\n3 1\n", "output": "4\n"}, {"input": "15\n9 11\n8 15\n6 5\n12 10\n1 2\n5 11\n10 7\n3 2\n6 7\n4 8\n3 5\n9 13\n13 14\n... | code_stdio |
[
{
"content": "Chef is playing a game on a sequence of N positive integers, say A_{1}, A_{2}, ... A_{N}. The game is played as follows.\nIf all the numbers are equal, the game ends.\nOtherwise\nSelect two numbers which are unequal\nSubtract the smaller number from the larger number\nReplace the larger number wit... | [{"input": "3\n2\n10 30\n2\n7 14\n3\n12 10 24", "output": "10\n7\n2\n"}, {"input": "3\n2\n10 21\n2\n20 10\n3\n11 10 9", "output": "1\n10\n1\n"}, {"input": "3\n2\n10 10\n2\n10 14\n3\n8 14 22", "output": "10\n2\n2\n"}, {"input": "3\n2\n19 19\n2\n10 14\n3\n8 10 24", "output": "19\n2\n2\n"}, {"input": "3\n2\n16 19\n2\n10 2... | code_stdio |
[
{
"content": "One day n friends gathered together to play \"Mafia\". During each round of the game some player must be the supervisor and other n - 1 people take part in the game. For each person we know in how many rounds he wants to be a player, not the supervisor: the i-th person wants to play a_{i} rounds. ... | [{"input": "100\n1 555 876 444 262 234 231 598 416 261 206 165 181 988 469 123 602 592 533 97 864 716 831 156 962 341 207 377 892 51 866 96 757 317 832 476 549 472 770 1000 887 145 956 515 992 653 972 677 973 527 984 559 280 346 580 30 372 547 209 929 492 520 446 726 47 170 699 560 814 206 688 955 308 287 26 102 77 430... | code_stdio |
[
{
"content": "Read problems statements in Mandarin Chinese and Russian \n\nChef is going to participate in a new quiz show: \"Who dares to be a millionaire?\"\nAccording to the rules of the game, contestants must answer N questions. The quiz being famous for its difficulty, each question has 26 candidate answ... | [{"input": "3\n5\nABCDE\nEBCDA\n1 10 34 18 78 225\n4\nCHEE\nQUIZ\n15 3 3 1 0\n8\nABBABAAB\nABABABAB\n100 100 100 100 001 001 000 000 000", "output": "34\n15\n100\n"}, {"input": "3\n5\nABCDE\nEBCDA\n1 10 34 18 63 225\n4\nCHEE\nQUIZ\n15 3 3 1 0\n8\nABBABAAB\nABABABAB\n100 101 100 100 001 001 000 000 001", "output": "34\n... | code_stdio |
[
{
"content": "Unary is a minimalistic Brainfuck dialect in which programs are written using only one token. \n\nBrainfuck programs use 8 commands: \"+\", \"-\", \"[\", \"]\", \"<\", \">\", \".\" and \",\" (their meaning is not important for the purposes of this problem). Unary programs are created from Brainfuc... | [{"input": ",]+>.],,+->+>-[]][><,-]><]++<.,-[.>.<+.[.<,[-,,[<]+>]->>]>]-+-+<][].,.]+][[<,-.+][+<<-+.],,,<,.]-].-\n", "output": "859903\n"}, {"input": ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n", "output": "208877\n"}, {"input": "[][][][][][][][][][][][][][][]... | code_stdio |
[
{
"content": "ZS the Coder and Chris the Baboon has explored Udayland for quite some time. They realize that it consists of n towns numbered from 1 to n. \n\nThere are n directed roads in the Udayland. i-th of them goes from town i to some other town a_{i} (a_{i} ≠ i). ZS the Coder can flip the direction of any... | [{"input": "84\n2 50 67 79 71 45 43 40 57 20 25 8 60 47 52 10 37 23 1 28 22 26 3 42 11 63 61 68 49 32 55 18 5 24 31 70 66 27 38 41 54 12 65 51 15 34 30 35 77 74 21 62 33 16 81 14 19 48 80 73 69 78 39 6 76 46 75 72 84 29 58 59 13 17 82 9 83 4 36 56 53 7 64 44\n", "output": "428380105\n"}, {"input": "84\n2 50 67 79 71 45... | code_stdio |
[
{
"content": "Bizon the Champion isn't just attentive, he also is very hardworking.\n\nBizon the Champion decided to paint his old fence his favorite color, orange. The fence is represented as n vertical planks, put in a row. Adjacent planks have no gap between them. The planks are numbered from the left to the... | [{"input": "30\n1 4 5 3 9 7 8 4 5 9 2 3 4 2 3 4 5 5 6 8 1 2 9 4 3 7 2 6 5 4\n", "output": "26\n"}, {"input": "30\n1 4 5 3 9 7 8 4 5 9 2 3 4 2 3 4 5 5 6 8 1 2 9 4 3 7 2 6 5 4\n", "output": "26\n"}, {"input": "30\n1 4 5 3 9 7 8 4 5 1 2 3 4 2 3 4 5 5 6 8 1 2 9 4 3 7 2 6 5 4\n", "output": "25\n"}, {"input": "30\n1 4 5 3 9 ... | code_stdio |
[
{
"content": "The Chef likes to stay in touch with his staff. So, the Chef, the head server, and the sous-chef all carry two-way transceivers so they can stay in constant contact. Of course, these transceivers have a limited range so if two are too far apart, they cannot communicate directly.\n\nThe Chef invest... | [{"input": "3\n2\n0 -1\n-1 -1\n1 0\n2\n0 0\n0 -1\n1 -1\n2\n1 0\n1 2\n1 1", "output": "yes\nyes\nyes\n"}, {"input": "3\n2\n0 -1\n-1 -1\n1 0\n2\n1 0\n0 -1\n1 -1\n2\n1 0\n1 2\n1 1", "output": "yes\nyes\nyes\n"}, {"input": "3\n2\n0 -1\n-1 -1\n1 0\n2\n0 1\n0 -1\n1 -1\n2\n1 0\n1 2\n1 1", "output": "yes\nyes\nyes\n"}, {"input... | code_stdio |
[
{
"content": "Example\n\nInput\n\n3\n1 3 3\n2\n1 2\n1 3\n\n\nOutput\n\n5\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": "3\n0 2 0\n-1\n1 2\n0 2", "output": "3\n"}, {"input": "3\n0 2 0\n-1\n1 2\n0 1", "output": "3\n"}, {"input": "3\n1 1 0\n0\n1 2\n-1 1", "output": "3\n"}, {"input": "3\n0 1 1\n0\n2 1\n-1 1", "output": "3\n"}, {"input": "3\n0 0 0\n0\n0 1\n-1 1", "output": "3\n"}, {"input": "3\n1 0 0\n0\n1 2\n-1 1", "output": "3\... | code_stdio |
[
{
"content": "Vasilisa the Wise from the Kingdom of Far Far Away got a magic box with a secret as a present from her friend Hellawisa the Wise from the Kingdom of A Little Closer. However, Vasilisa the Wise does not know what the box's secret is, since she cannot open it again. She hopes that you will help her ... | [{"input": "16 14\n15 15\n17 13\n", "output": "9 7\n6 8\n"}, {"input": "12 14\n11 15\n9 17\n", "output": "3 9\n8 6\n"}, {"input": "12 12\n14 10\n16 8\n", "output": "9 3\n5 7\n"}, {"input": "11 11\n17 5\n12 10\n", "output": "9 2\n8 3\n"}, {"input": "14 11\n16 9\n13 12\n", "output": "9 5\n7 4\n"}, {"input": "15 11\n16 10... | code_stdio |
[
{
"content": "You have to organize a wedding party. The program of the party will include a concentration game played by the bride and groom. The arrangement of the concentration game should be easy since this game will be played to make the party fun.\n\nWe have a 4x4 board and 8 pairs of cards (denoted by `A'... | [{"input": "-2 1 -3 1 1 0 0 1\n1 -1 2 1 2 2 -1 3\n8", "output": "145\n0\n"}, {"input": "-2 1 0 1 1 0 1 3\n2 0 2 0 3 2 0 4\n10", "output": "173\n256\n"}, {"input": "-2 1 -2 1 1 0 1 2\n1 0 2 1 2 2 0 3\n5", "output": "145\n29\n"}, {"input": "-2 1 -2 1 1 0 1 3\n1 0 2 1 2 2 0 3\n5", "output": "125\n29\n"}, {"input": "-2 1 -... | code_stdio |
[
{
"content": "Dima's got a staircase that consists of n stairs. The first stair is at height a1, the second one is at a2, the last one is at an (1 ≤ a1 ≤ a2 ≤ ... ≤ an). \n\nDima decided to play with the staircase, so he is throwing rectangular boxes at the staircase from above. The i-th box has width wi and he... | [{"input": "5\n1 2 3 6 6\n25\n1 1000000000\n1 1000000000\n1 1000000000\n1 1000000000\n1 1000000000\n1 1000000000\n1 1000000000\n1 1000000000\n1 1000000000\n1 1000000000\n1 1000000000\n1 1000000000\n1 1000000000\n1 1000000000\n1 1000000000\n1 1000000000\n1 1000000000\n1 1000000000\n1 1000000000\n1 1000000000\n1 10000000... | code_stdio |
[
{
"content": "A sequence $a = [a_1, a_2, \\ldots, a_l]$ of length $l$ has an ascent if there exists a pair of indices $(i, j)$ such that $1 \\le i < j \\le l$ and $a_i < a_j$. For example, the sequence $[0, 2, 0, 2, 0]$ has an ascent because of the pair $(1, 4)$, but the sequence $[4, 3, 3, 3, 1]$ doesn't have ... | [{"input": "10\n3 62 24 39\n1 17\n1 99\n1 60\n1 64\n1 30\n2 79 29\n2 20 73\n2 85 37\n1 100\n", "output": "72\n"}, {"input": "10\n3 62 24 39\n1 17\n1 99\n1 60\n1 64\n1 30\n2 79 29\n2 20 73\n2 85 37\n1 100\n", "output": "72\n"}, {"input": "5\n5 1 2 2 4 5\n4 -1 2 3 6\n3 3 2 1\n2 3 1\n1 0\n", "output": "22\n"}, {"input": "... | code_stdio |
[
{
"content": "Student Valera is an undergraduate student at the University. His end of term exams are approaching and he is to pass exactly n exams. Valera is a smart guy, so he will be able to pass any exam he takes on his first try. Besides, he can take several exams on one day, and in any order.\n\nAccording... | [{"input": "1\n1000000000 999999999\n", "output": "999999999\n"}, {"input": "1\n1000000000 999999999\n", "output": "999999999\n"}, {"input": "1\n1010000000 999999999\n", "output": "999999999\n"}, {"input": "1\n1010000000 498441652\n", "output": "498441652\n"}, {"input": "1\n1000000000 115308630\n", "output": "115308630... | code_stdio |
[
{
"content": "Alice and Johnny are playing a simple guessing game. Johnny picks an arbitrary positive integer n (1<=n<=109) and gives Alice exactly k hints about the value of n. It is Alice's task to guess n, based on the received hints. \n\nAlice often has a serious problem guessing the value of n, and she's b... | [{"input": "3\n2\n< 100 No\n> 100 No\n3\n< 2 Yes\n> 4 Yes\n= 3 No\n6\n< 2 Yes\n> 1 Yes\n= 1 Yes\n= 1 Yes\n= 1 Yes\n= 1 Yes", "output": "0\n1\n1\n"}, {"input": "3\n2\n< 100 No\n? 100 No\n3\n< 2 Yes\n> 4 Yes\n= 3 No\n6\n< 2 Yes\n> 1 Yes\n= 1 Yes\n= 1 Yes\n> 1 Yes\n= 1 Yes", "output": "0\n1\n2\n"}, {"input": "3\n2\n< 100 ... | code_stdio |
[
{
"content": "Lavrenty, a baker, is going to make several buns with stuffings and sell them.\n\nLavrenty has n grams of dough as well as m different stuffing types. The stuffing types are numerated from 1 to m. Lavrenty knows that he has ai grams left of the i-th stuffing. It takes exactly bi grams of stuffing ... | [{"input": "1000 10 100 75\n100 97 100 95\n100 64 100 78\n110 82 100 35\n100 51 100 64\n100 67 100 25\n100 79 100 33\n100 65 100 85\n100 99 100 78\n100 53 100 74\n100 87 100 73\n", "output": "786\n"}, {"input": "1000 10 100 75\n100 97 100 95\n100 64 100 78\n100 82 100 35\n100 51 100 64\n100 67 100 25\n100 79 100 33\n10... | code_stdio |
[
{
"content": "Sereja owns a restaurant for n people. The restaurant hall has a coat rack with n hooks. Each restaurant visitor can use a hook to hang his clothes on it. Using the i-th hook costs a_{i} rubles. Only one person can hang clothes on one hook.\n\nTonight Sereja expects m guests in the restaurant. Nat... | [{"input": "100 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... | code_stdio |
[
{
"content": "Polycarpus has n friends in Tarasov city. Polycarpus knows phone numbers of all his friends: they are strings s1, s2, ..., sn. All these strings consist only of digits and have the same length. \n\nOnce Polycarpus needed to figure out Tarasov city phone code. He assumed that the phone code of the ... | [{"input": "10\n17254072509168593435\n17254072509168593433\n17254072509168593430\n17254072509168593432\n17254072509168593439\n17254072509168593436\n17254072509168593438\n17254072509168593437\n17254072509168593431\n17254072509168593434\n", "output": "19\n"}, {"input": "10\n17254072509168593435\n17475068102414404607\n172... | code_stdio |
[
{
"content": "Madeline has an array $a$ of $n$ integers. A pair $(u, v)$ of integers forms an inversion in $a$ if:\n\n $1 \\le u < v \\le n$. $a_u > a_v$. \n\nMadeline recently found a magical paper, which allows her to write two indices $u$ and $v$ and swap the values $a_u$ and $a_v$. Being bored, she decide... | [{"input": "100\n32 85 33 27 35 48 64 40 45 120 68 58 108 115 99 71 47 82 42 34 63 49 102 30 88 70 73 52 51 95 104 41 38 59 91 21 43 107 44 113 109 25 55 118 112 90 37 106 103 100 114 78 31 26 92 79 89 105 62 54 72 69 101 36 98 77 93 97 75 96 22 76 86 57 46 110 65 61 23 50 83 87 39 74 111 67 29 84 24 28 56 116 80 117 1... | code_stdio |
[
{
"content": "There is a frequency operation in the conversion operation of a finite number sequence. The conversion result of the sequence $ S = \\\\ {s_1, s_2, ... s_n \\\\} $ is a sequence of the same length. If the result is $ C = \\\\ {c_1, c_2, ..., c_n \\\\} $, then $ c_i $ represents the number of $ s_i... | [{"input": "10\n2 5 1 -1 3 4 27 0 -2 6\n0", "output": "2\n10 10 10 10 10 10 10 10 10 10\n"}, {"input": "10\n2 1 0 0 3 5 0 0 0 12\n0", "output": "3\n10 10 10 10 10 10 10 10 10 10\n"}, {"input": "10\n2 5 1 0 3 4 27 0 -2 10\n0", "output": "2\n8 8 8 2 8 8 8 2 8 8\n"}, {"input": "10\n2 5 1 -1 3 4 27 0 -2 5\n0", "output": "2... | code_stdio |
[
{
"content": "Arseniy is already grown-up and independent. His mother decided to leave him alone for m days and left on a vacation. She have prepared a lot of food, left some money and washed all Arseniy's clothes. \n\nTen minutes before her leave she realized that it would be also useful to prepare instruction... | [{"input": "10 3 3\n2 2 1 3 1 2 1 2 2 2\n10 8\n9 6\n8 10\n", "output": "0\n"}, {"input": "10 1 3\n2 2 1 3 1 2 1 2 2 2\n10 8\n9 6\n8 10\n", "output": "0\n"}, {"input": "10 1 3\n2 2 1 3 1 2 1 2 2 2\n10 8\n9 6\n3 10\n", "output": "0\n"}, {"input": "10 1 3\n2 2 1 3 1 2 1 2 3 2\n10 8\n9 6\n3 10\n", "output": "0\n"}, {"input... | code_stdio |
[
{
"content": "Read problems statements in English, Mandarin Chinese and Russian as well. \n\nSherlock is stuck. There is a N X N grid in which some cells are empty (denoted by ‘.’), while some cells have rocks in them (denoted by ‘#’). Sherlock is on the South of the grid. He has to watch what is happening on t... | [{"input": "2\n3\n#..\n..#\n#..\n3\n#.#\n#.#\n#.#", "output": "3\n0\n"}, {"input": "2\n3\n#..\n\"..\n#..\n3\n#.#\n#.#\n#.#", "output": "6\n0\n"}, {"input": "2\n3\n$..\n..#\n#..\n3\n\"-#\n#.#\n\"#.", "output": "3\n1\n"}, {"input": "2\n3\n$..\n.#.\n#..\n3\n\"-#\n#.#\n\".#", "output": "4\n0\n"}, {"input": "2\n3\n#..\n..#\... | code_stdio |
[
{
"content": "There are $n$ students in a school class, the rating of the $i$-th student on Codehorses is $a_i$. You have to form a team consisting of $k$ students ($1 \\le k \\le n$) such that the ratings of all team members are distinct.\n\nIf it is impossible to form a suitable team, print \"NO\" (without qu... | [{"input": "100 100\n63 100 75 32 53 24 73 98 76 15 70 48 8 81 88 58 95 78 27 92 14 16 72 43 46 39 66 38 64 42 59 9 22 51 4 6 10 94 28 99 68 80 35 50 45 20 47 7 30 26 49 91 77 19 96 57 65 1 11 13 31 12 82 87 93 34 62 3 21 79 56 41 89 18 44 23 74 86 2 33 69 36 61 67 25 83 5 84 90 37 40 29 97 60 52 55 54 71 17 85\n", "ou... | code_stdio |
[
{
"content": "You are given an integer n. You have to apply m operations to it.\n\nIn a single operation, you must replace every digit d of the number with the decimal representation of integer d + 1. For example, 1912 becomes 21023 after applying the operation once.\n\nYou have to find the length of n after ap... | [{"input": "5\n178 170\n26 25\n64 84\n19 12\n20 136\n", "output": "764520\n12\n1015\n6\n32483\n"}, {"input": "5\n178 170\n26 25\n64 84\n19 12\n38 136\n", "output": "764520\n12\n1015\n6\n46148\n"}, {"input": "5\n178 170\n26 25\n64 84\n19 6\n20 136\n", "output": "764520\n12\n1015\n3\n32483\n"}, {"input": "5\n176 143\n16 ... | code_stdio |
[
{
"content": "There are three houses on a number line: House 1, 2 and 3, with coordinates A, B and C, respectively. Print `Yes` if we pass the coordinate of House 3 on the straight way from House 1 to House 2 without making a detour, and print `No` otherwise.\n\nConstraints\n\n* 0\\leq A,B,C\\leq 100\n* A, B an... | [{"input": "31 61 59", "output": "Yes\n"}, {"input": "31 61 51", "output": "Yes\n"}, {"input": "31 86 59", "output": "Yes\n"}, {"input": "39 69 59", "output": "Yes\n"}, {"input": "31 49 59", "output": "No\n"}, {"input": "39 49 59", "output": "No\n"}, {"input": "39 49 10", "output": "No\n"}, {"input": "51 49 10", "outpu... | code_stdio |
[
{
"content": "A bracket sequence is a string containing only characters \"(\" and \")\".\n\nA regular bracket sequence is a bracket sequence that can be transformed into a correct arithmetic expression by inserting characters \"1\" and \"+\" between the original characters of the sequence. For example, bracket ... | [{"input": "10\n()()(\n)((\n)()(((()(\n(((()(\n)(()((\n))\n()()()()\n))()))((\n)\n))())(\n", "output": "2\n"}, {"input": "10\n()()(\n)((\n)()(((()(\n(((()(\n)(()((\n))\n()()()()\n))()))((\n)\n))())(\n", "output": "2\n"}, {"input": "10\n()()(\n)((\n)()((((((\n(((()(\n)(()((\n))\n()()()()\n))()))((\n)\n))())(\n", "output... | code_stdio |
[
{
"content": "Your company was appointed to lay new asphalt on the highway of length $n$. You know that every day you can either repair one unit of the highway (lay new asphalt over one unit of the highway) or skip repairing.\n\nSkipping the repair is necessary because of the climate. The climate in your region... | [{"input": "3\n10 1 1\n11 4 10\n1000000 1 1000100\n", "output": "10\n16\n500049499900\n"}, {"input": "3\n10 1 1\n16 4 10\n1000000 1 1000100\n", "output": "10\n18\n500049499900\n"}, {"input": "3\n10 1 1\n16 4 10\n1000001 1 1000100\n", "output": "10\n18\n500050500001\n"}, {"input": "3\n10 1 1\n16 8 10\n1000001 1 1000100\... | code_stdio |
[
{
"content": "Monocarp wants to draw four line segments on a sheet of paper. He wants the $i$-th segment to have its length equal to $a_i$ ($1 \\le i \\le 4$). These segments can intersect with each other, and each segment should be either horizontal or vertical.\n\nMonocarp wants to draw the segments in such a... | [{"input": "4\n1 1 5 4\n4 16 10 4\n2 1 4 1\n100 21 54 111\n", "output": "4\n40\n2\n2100\n"}, {"input": "4\n0 5 2 4\n6 14 10 3\n2 0 5 1\n101 40 47 111\n", "output": "0\n30\n0\n4040\n"}, {"input": "4\n1 1 5 8\n4 16 10 4\n2 1 4 1\n100 21 54 111\n", "output": "5\n40\n2\n2100\n"}, {"input": "4\n1 1 3 4\n4 16 5 4\n2 0 4 1\n1... | code_stdio |
[
{
"content": "There is a grid of squares with H+1 horizontal rows and W vertical columns.\n\nYou will start at one of the squares in the top row and repeat moving one square right or down. However, for each integer i from 1 through H, you cannot move down from the A_i-th, (A_i + 1)-th, \\ldots, B_i-th squares f... | [{"input": "4 4\n1 4\n1 1\n2 0\n3 4", "output": "-1\n-1\n-1\n-1\n"}, {"input": "4 5\n0 4\n0 1\n4 5\n3 4", "output": "1\n2\n-1\n-1\n"}, {"input": "4 34\n2 3\n1 2\n2 2\n2 14", "output": "1\n2\n3\n4\n"}, {"input": "4 34\n2 3\n2 2\n2 2\n2 14", "output": "1\n2\n3\n4\n"}, {"input": "4 12\n2 4\n-1 1\n4 3\n2 4", "output": "1\n... | code_stdio |
[
{
"content": "Takahashi is meeting up with Aoki.\nThey have planned to meet at a place that is D meters away from Takahashi's house in T minutes from now.\nTakahashi will leave his house now and go straight to the place at a speed of S meters per minute.\nWill he arrive in time?\n\n-----Constraints-----\n - 1 \... | [{"input": "7202 7775 4325\n", "output": "Yes\n"}, {"input": "3982 4784 8417\n", "output": "Yes\n"}, {"input": "2156 1932 5902\n", "output": "Yes\n"}, {"input": "1 10000 10000\n", "output": "Yes\n"}, {"input": "522 4575 6426\n", "output": "Yes\n"}, {"input": "3447 629 3497\n", "output": "Yes\n"}, {"input": "9445 8772 8... | code_stdio |
[
{
"content": "Ilya is a very clever lion, he lives in an unusual city ZooVille. In this city all the animals have their rights and obligations. Moreover, they even have their own bank accounts. The state of a bank account is an integer. The state of a bank account can be a negative number. This means that the o... | [{"input": "-1000000000\n", "output": "-100000000\n"}, {"input": "-1000000000\n", "output": "-100000000\n"}, {"input": "-1015555150\n", "output": "-101555510\n"}, {"input": "-1620057635\n", "output": "-162005763\n"}, {"input": "-1246147339\n", "output": "-124614733\n"}, {"input": "-1005651079\n", "output": "-100565107\... | code_stdio |
[
{
"content": "Addition is easy to calculate by hand, but if some numbers are missing, is it easy to fill in the missing numbers? For example, in the following long division, if there is a condition that the numbers 1 to 9 appear only once, how many numbers will fit in the C and E squares? In this case, 8 is cor... | [{"input": "-1 -1 -1 -1 -1 -1 -1 -1 -1", "output": "168"}, {"input": "-1 -1 -1 -1 -1 -1 3 4 6", "output": "0\n"}, {"input": "-1 -1 -1 -1 -1 -1 3 2 6", "output": "0\n"}, {"input": "-1 -1 -1 -1 -1 -2 3 2 6", "output": "0\n"}, {"input": "-1 -1 -1 -1 -1 -1 8 4 6", "output": "12"}, {"input": "-1 -1 -1 0 -1 -2 3 2 6", "outpu... | code_stdio |
[
{
"content": "One popular blog site edits the uploaded photos like this. It cuts a rectangular area out of them so that the ratio of height to width (i.e. the height / width quotient) can vary from 0.8 to 1.25 inclusively. Besides, at least one side of the cut area should have a size, equal to some power of num... | [{"input": "1010000000 1000000000\n", "output": "671088640 536870912\n"}, {"input": "1010000000 1000000010\n", "output": "671088640 536870912\n"}, {"input": "1010000000 1000000001\n", "output": "671088640 536870912\n"}, {"input": "1011000000 1000000010\n", "output": "671088640 536870912\n"}, {"input": "1000000010 10000... | code_stdio |
[
{
"content": "Example\n\nInput\n\n3 3 1 2 4\n1 2\n2 3\n3 1\n\n\nOutput\n\nIMPOSSIBLE\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": "4 1 2 1 2\n1 2\n2 3\n11 0", "output": "IMPOSSIBLE\n"}, {"input": "8 1 2 1 2\n1 2\n2 3\n11 0", "output": "IMPOSSIBLE\n"}, {"input": "3 3 2 2 4\n1 2\n2 3\n3 1", "output": "IMPOSSIBLE\n"}, {"input": "3 3 2 1 4\n1 2\n2 3\n3 1", "output": "IMPOSSIBLE\n"}, {"input": "4 3 2 1 4\n1 2\n2 3\n3 1", "output": "IMPOSSIB... | code_stdio |
[
{
"content": "Let's play Hit and Blow game. A imagines four numbers and B guesses the numbers. After B picks out four numbers, A answers:\n\n* The number of numbers which have the same place with numbers A imagined (Hit)\n* The number of numbers included (but different place) in the numbers A imagined (Blow)\n\... | [{"input": "9 1 8 3\n6 1 4 3\n8 6 -1 -1\n2 7 3 1", "output": "2 0\n0 0\n"}, {"input": "4 1 8 2\n6 1 2 3\n8 6 -1 -1\n2 7 3 1", "output": "1 1\n0 0\n"}, {"input": "5 0 8 2\n6 1 2 3\n7 6 -1 -1\n2 7 3 1", "output": "0 1\n0 1\n"}, {"input": "9 0 8 2\n6 1 5 9\n7 22 13 2\n2 6 7 1", "output": "0 1\n0 2\n"}, {"input": "11 1 8 3... | code_stdio |
[
{
"content": "Oleg the bank client and Igor the analyst are arguing again. This time, they want to pick a gift as a present for their friend, ZS the coder. After a long thought, they decided that their friend loves to eat carrots the most and thus they want to pick the best carrot as their present.\n\nThere are... | [{"input": "40\n2 2 88 105 2 2 2 2 2 2 2 2 2 2 4 2 2 2 2 2 2 2 2 2 2 2 2 7 7 2 2 2 2 0 2 2 2 2 2 2\n", "output": "2 2 2 2 2 2 2 2 2 2 4 2 4 2 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 105 88 105 88 105 88 105 105\n"}, {"input": "40\n2 2 88 105 2 2 2 2 2 1 2 2 2 2 4 2 2 2 2 2 2 2 2 2 2 2 2 7 7 2 2 2 2 0 2 2 2 2 2 2\n", "outpu... | code_stdio |
[
{
"content": "There are $n$ computers in a row, all originally off, and Phoenix wants to turn all of them on. He will manually turn on computers one at a time. At any point, if computer $i-1$ and computer $i+1$ are both on, computer $i$ $(2 \\le i \\le n-1)$ will turn on automatically if it is not already on. N... | [{"input": "100 999999733\n", "output": "499246611\n"}, {"input": "350 999999733\n", "output": "255248393\n"}, {"input": "397 999999733\n", "output": "239189389\n"}, {"input": "398 999999733\n", "output": "875462745\n"}, {"input": "399 999999733\n", "output": "530105147\n"}, {"input": "400 999999733\n", "output": "5640... | code_stdio |
[
{
"content": "You are given a tree with N vertices.\n\nHere, a tree is a kind of graph, and more specifically, a connected undirected graph with N-1 edges, where N is the number of its vertices.\n\nThe i-th edge (1≤i≤N-1) connects Vertices a_i and b_i, and has a length of c_i.\nYou are also given Q queries and ... | [{"input": "30\n20 2 885820291\n9 3 833676138\n21 8 969316096\n13 10 732239064\n14 12 568976928\n4 14 362005859\n4 17 46938898\n4 21 706609800\n13 4 114271135\n18 13 475446302\n20 22 582315387\n7 23 941896909\n18 7 546231774\n30 24 698675648\n30 25 13971027\n11 26 760254873\n30 27 731457744\n1 28 242926757\n15 1 704423... | code_stdio |
[
{
"content": "Japan achieved the second straight victory in the national baseball competition WBC !! A baseball tournament was held at Aizu Gakuen High School as baseball became more popular. In this tournament, a round-robin league match will be held and the ranking will be decided in the following ways.\n\n1.... | [{"input": "6\nA 1 0 0 2 -1\nB 0 0 1 2 -1\nC 2 1 1 1 1\nD 2 0 -1 0 2\nE 2 0 0 0 0\nF 1 1 1 2 2\n4\nh 1 1 1\ng 0 2 2\nx -1 0 0\n` 0 2 2\n0", "output": "E\nD\nA\nB\nF\nC\nx\ng\n`\nh\n"}, {"input": "6\nA 1 0 0 2 -1\nB 0 0 1 1 0\nC 1 1 1 1 1\nD 1 1 0 0 2\nE 2 0 -1 0 0\nF 1 2 0 2 1\n4\ng 1 1 1\nh 0 1 2\nx 0 -1 0\na 0 2 2\n0... | code_stdio |
[
{
"content": "Johnny drives a truck and must deliver a package from his hometown to the district center. His hometown is located at point 0 on a number line, and the district center is located at the point d.\n\nJohnny's truck has a gas tank that holds exactly n liters, and his tank is initially full. As he dri... | [{"input": "281 12 23\n178 650197\n129 288456\n34 1664910\n43 683515\n305 957083\n103 724815\n105 308008\n252 1280706\n74 87088\n229 146026\n85 241042\n35 39127\n62 47524\n217 760274\n156 562141\n10 209057\n50 714473\n201 164128\n97 624021\n120 102709\n147 388268\n317 1546753\n190 1448117\n", "output": "-1\n"}, {"input... | code_stdio |
[
{
"content": "Fast Forwarding\n\nMr. Anderson frequently rents video tapes of his favorite classic films. Watching the films so many times, he has learned the precise start times of his favorite scenes in all such films. He now wants to find how to wind the tape to watch his favorite scene as quickly as possibl... | [{"input": "2139", "output": "21\n"}, {"input": "1374", "output": "22\n"}, {"input": "3723", "output": "23\n"}, {"input": "138", "output": "12\n"}, {"input": "149", "output": "13\n"}, {"input": "132", "output": "14\n"}, {"input": "374", "output": "16\n"}, {"input": "315", "output": "15\n"}, {"input": "933", "output": "... | code_stdio |
[
{
"content": "When Serezha was three years old, he was given a set of cards with letters for his birthday. They were arranged into words in the way which formed the boy's mother favorite number in binary notation. Serezha started playing with them immediately and shuffled them because he wasn't yet able to read... | [{"input": "400\nzzzerrzrzzrozrezooreroeoeezerrzeerooereezeeererrezrororoorrzezoeerrorzrezzrzoerrzorrooerzrzeozrrorzzzzeoeereeroeozezeozoozooereoeorrzoroeoezooeerorreeorezeozeroerezoerooooeerozrrorzozeroereerozeozeoerroroereeeerzzrzeeozrezzozeoooeerzzzorozrzezrrorozezoorzzerzroeeeerorreeoezoeroeeezerrzeorzoeorzoeeororz... | code_stdio |
[
{
"content": "You are given a sequence (P_1,P_2,...,P_N) which is a permutation of the integers from 1 through N. You would like to sort this sequence in ascending order by repeating the following operation:\n\n* Choose an element in the sequence and move it to the beginning or the end of the sequence.\n\n\n\nF... | [{"input": "8\n6\n3\n2\n1\n7\n4\n8\n5", "output": "5\n"}, {"input": "8\n6\n3\n1\n2\n5\n4\n8\n7", "output": "6\n"}, {"input": "8\n6\n3\n2\n1\n4\n7\n8\n5", "output": "5\n"}, {"input": "8\n6\n3\n2\n1\n7\n4\n5\n8", "output": "5\n"}, {"input": "8\n6\n3\n2\n1\n7\n4\n8\n5", "output": "5\n"}, {"input": "8\n6\n3\n2\n1\n5\n4\n8\... | code_stdio |
[
{
"content": "Max wants to buy a new skateboard. He has calculated the amount of money that is needed to buy a new skateboard. He left a calculator on the floor and went to ask some money from his parents. Meanwhile his little brother Yusuf came and started to press the keys randomly. Unfortunately Max has forg... | [{"input": "80124649014054971081213608137817466046254652492627741860478258558206397113198232823859870363821007188476405951611069347299689170240023979048198711745011542774268179055311013054073075176122755643483380248999657649211459997766221072399103579977409770898200358240970169892326442892826731631357561876251276209119... | code_stdio |
[
{
"content": "Knights' tournaments were quite popular in the Middle Ages. A lot of boys were dreaming of becoming a knight, while a lot of girls were dreaming of marrying a knight on a white horse.\n\nIn this problem we consider one of these tournaments. \n\nLet's us call a tournament binary, if it runs accordi... | [{"input": "14", "output": "0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0... | code_stdio |
[
{
"content": "A motorcade of n trucks, driving from city «Z» to city «З», has approached a tunnel, known as Tunnel of Horror. Among truck drivers there were rumours about monster DravDe, who hunts for drivers in that tunnel. Some drivers fear to go first, others - to be the last, but let's consider the general ... | [{"input": "20\n7892 2 0 24\n4201 1 2 23\n3667 1 3 22\n6388 1 4 21\n2406 1 5 20\n1148 1 6 19\n3958 1 7 18\n7363 1 8 17\n9025 2 9 15\n1909 1 11 14\n73 1 12 13\n5477 2 13 11\n1869 1 15 10\n107 1 16 9\n523 1 17 8\n6589 2 18 6\n6277 2 20 4\n3881 1 22 3\n5771 1 23 2\n622 2 24 0\n", "output": "20\n1 2 3 4 5 6 7 8 9 10 11 12 ... | code_stdio |
[
{
"content": "Snuke Festival 2017 will be held in a tree with N vertices numbered 1,2, ...,N. The i-th edge connects Vertex a_i and b_i, and has joyfulness c_i.\n\nThe staff is Snuke and N-1 black cats. Snuke will set up the headquarters in some vertex, and from there he will deploy a cat to each of the other N... | [{"input": "19\n19 14 48\n11 19 23\n17 14 30\n7 11 15\n2 19 15\n2 18 21\n19 10 43\n12 11 25\n3 11 4\n5 19 50\n4 11 19\n9 12 29\n14 13 3\n14 6 12\n14 15 17\n5 1 6\n8 18 13\n7 16 14", "output": "103\n238\n71\n266\n373\n193\n232\n207\n302\n361\n298\n302\n54\n371\n250\n220\n322\n238\n373\n"}, {"input": "19\n19 14 48\n11 19... | code_stdio |
[
{
"content": "There are K pieces of cakes. Mr. Takahashi would like to eat one cake per day, taking K days to eat them all.\n\nThere are T types of cake, and the number of the cakes of type i (1 ≤ i ≤ T) is a_i.\n\nEating the same type of cake two days in a row would be no fun, so Mr. Takahashi would like to de... | [{"input": "110 2\n110", "output": "109\n"}, {"input": "12 3\n2 2 -1", "output": "0\n"}, {"input": "13 8\n-1 1 1", "output": "0\n"}, {"input": "100 2\n100", "output": "99\n"}, {"input": "7 3\n-1 1 1", "output": "0\n"}, {"input": "7 5\n-1 1 1", "output": "0\n"}, {"input": "12 3\n2 1 2", "output": "0\n"}, {"input": "7 8\... | code_stdio |
[
{
"content": "Write a program which reads a $ n \\times m$ matrix $A$ and a $m \\times 1$ vector $b$, and prints their product $Ab$.\n\nA column vector with m elements is represented by the following equation.\n\n\\\\[ b = \\left( \\begin{array}{c} b_1 \\\\\\ b_2 \\\\\\ : \\\\\\ b_m \\\\\\ \\end{array} \\right)... | [{"input": "3 4\n1 4 -2 1\n0 3 0 -1\n4 1 0 0\n0\n-2\n3\n0", "output": "-14\n-6\n-2\n"}, {"input": "3 4\n0 7 -13 0\n0 0 0 1\n4 2 2 0\n1\n1\n3\n-1", "output": "-32\n-1\n12\n"}, {"input": "3 4\n0 7 -13 0\n0 0 0 1\n4 2 2 0\n1\n2\n3\n-1", "output": "-25\n-1\n14\n"}, {"input": "3 4\n0 7 -13 0\n0 0 0 1\n4 2 4 0\n1\n2\n3\n-1",... | code_stdio |
[
{
"content": "We have N gemstones labeled 1 through N.\nYou can perform the following operation any number of times (possibly zero).\n - Select a positive integer x, and smash all the gems labeled with multiples of x.\nThen, for each i, if the gem labeled i remains without getting smashed, you will receive a_i ... | [{"input": "99\n122741031 -204980087 525357399 -35985856 -416421742 611495756 -929791499 -703341024 312660354 -8716403 -885125673 332761853 -601694152 -453492700 658205998 -888173729 58182557 620328675 -664005151 -864927032 645923185 675352889 -954440570 -792010737 -826546996 -44381354 332330747 -64136214 -790678352 -2... | code_stdio |
[
{
"content": "Bitwise exclusive OR (or bitwise addition modulo two) is a binary operation which is equivalent to applying logical exclusive OR to every pair of bits located on the same positions in binary notation of operands. In other words, a binary digit of the result is equal to 1 if and only if bits on the... | [{"input": "9992164445234764941\n8162963574901971597\n", "output": "914600435166396672 9077564010068368269"}, {"input": "1367480970723947\n584615739735395\n", "output": "391432615494276 976048355229671"}, {"input": "339671107814\n208405902980\n", "output": "65632602417 274038505397"}, {"input": "1870807699\n259801747\n... | code_stdio |
[
{
"content": "Let's suppose you have an array a, a stack s (initially empty) and an array b (also initially empty).\n\nYou may perform the following operations until both a and s are empty:\n\n Take the first element of a, push it into s and remove it from a (if a is not empty); Take the top element from s, a... | [{"input": "40 39\n25 4 26 34 35 11 22 23 21 2 1 28 20 8 36 5 27 15 39 7 24 14 17 19 33 6 38 16 18 3 32 10 30 13 37 31 29 9 12\n", "output": "-1\n"}, {"input": "40 39\n25 4 26 34 35 11 22 23 21 2 1 28 20 8 36 5 27 15 39 7 24 14 17 19 33 6 38 16 18 3 32 10 30 13 37 31 29 9 12\n", "output": "-1"}, {"input": "40 38\n32 35... | code_stdio |
[
{
"content": "Recall that string $a$ is a subsequence of a string $b$ if $a$ can be obtained from $b$ by deletion of several (possibly zero or all) characters. For example, for the string $a$=\"wowwo\", the following strings are subsequences: \"wowwo\", \"wowo\", \"oo\", \"wow\", \"\", and others, but the follo... | [{"input": "ovvvvovovvvvovoovovovovvvvvvvoovoovvovvoooooovo\n", "output": "463\n"}, {"input": "ovvvvovovvvvovoovovovovvvvvvvoovoovvovvoooooovo\n", "output": "463\n"}, {"input": "vvovooovovvovoovoovvvvovovvvov\n", "output": "100\n"}, {"input": "vovvvovovvvvoovoovovvovooovovv\n", "output": "100\n"}, {"input": "vovvvvvovo... | code_stdio |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.