messages
listlengths
1
1
ground_truth
stringlengths
872
161M
id
stringlengths
32
32
dataset
stringclasses
1 value
[ { "content": "Solve the following coding problem using the programming language python:\n\nAfter a wonderful evening in the restaurant the time to go home came. Leha as a true gentlemen suggested Noora to give her a lift. Certainly the girl agreed with pleasure. Suddenly one problem appeared: Leha cannot find h...
[{"input": "4\n1 1 1 1 1\n3 2 5 4 5\n1 1 5 5 10000\n1 4 2 5 2\n", "output": "1\n13\n93\n0\n", "type": "code"}, {"input": "10\n3 7 4 10 7\n6 1 7 10 18\n9 6 10 8 3\n1 8 3 10 3\n10 4 10 5 19\n8 9 9 10 10\n10 1 10 5 4\n8 1 9 4 18\n6 3 9 5 1\n6 6 9 6 16\n", "output": "22\n130\n0\n0\n25\n3\n0\n68\n0\n22\n", "type": "code"}, ...
811b158b35eac12103a102b12f10da7c
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nThere is a beautiful garden of stones in Innopolis.\n\nIts most beautiful place is the $n$ piles with stones numbered from $1$ to $n$.\n\nEJOI participants have visited this place twice. \n\nWhen they first visited it, th...
[{"input": "5\n1 2 3 4 5\n2 1 4 3 5\n", "output": "Yes\n", "type": "code"}, {"input": "5\n1 1 1 1 1\n1 0 1 0 1\n", "output": "Yes\n", "type": "code"}, {"input": "3\n2 3 9\n1 7 9\n", "output": "No\n", "type": "code"}, {"input": "40\n361 372 139 808 561 460 421 961 727 719 130 235 320 470 432 759 317 886 624 666 917 133 ...
934bd3611c16f47df53dbfa21be2637c
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nAndrey thinks he is truly a successful developer, but in reality he didn't know about the binary search algorithm until recently. After reading some literature Andrey understood that this algorithm allows to quickly find ...
[{"input": "4 1 2\n", "output": "6\n", "type": "code"}, {"input": "123 42 24\n", "output": "824071958\n", "type": "code"}, {"input": "1 1 0\n", "output": "1\n", "type": "code"}, {"input": "1000 501 501\n", "output": "646597996\n", "type": "code"}, {"input": "1000 999 799\n", "output": "0\n", "type": "code"}, {"input": ...
d7a794d4b0390b4696e11f43bdc610eb
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nBajtek, known for his unusual gifts, recently got an integer array $x_0, x_1, \\ldots, x_{k-1}$.\n\nUnfortunately, after a huge array-party with his extraordinary friends, he realized that he'd lost it. After hours spent ...
[{"input": "5\n1 2 3 4 5\n", "output": "5\n1 2 3 4 5 ", "type": "code"}, {"input": "5\n1 3 5 6 8\n", "output": "2\n3 5 ", "type": "code"}, {"input": "3\n1 5 3\n", "output": "1\n3 ", "type": "code"}, {"input": "1\n5\n", "output": "1\n1 ", "type": "code"}, {"input": "10\n500000 500000 500000 500000 500000 500000 500000 1...
c0907e1ac4d1f713f34e41ce4190b14a
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nThere are $n$ slimes in a row. Each slime has an integer value (possibly negative or zero) associated with it.\n\nAny slime can eat its adjacent slime (the closest slime to its left or to its right, assuming that this sli...
[{"input": "4\n2 1 2 1\n", "output": "4", "type": "code"}, {"input": "5\n0 -1 -1 -1 -1\n", "output": "4", "type": "code"}, {"input": "2\n10 8\n", "output": "2", "type": "code"}, {"input": "5\n-14 -2 0 -19 -12\n", "output": "47", "type": "code"}, {"input": "6\n-15 2 -19 20 0 9\n", "output": "65", "type": "code"}, {"inpu...
2b7bc0ce0fd388c83595c160e5300d93
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nSome natural number was written on the board. Its sum of digits was not less than k. But you were distracted a bit, and someone changed this number to n, replacing some digits with others. It's known that the length of th...
[{"input": "3\n11\n", "output": "1\n", "type": "code"}, {"input": "3\n99\n", "output": "0\n", "type": "code"}, {"input": "10\n5205602270\n", "output": "0\n", "type": "code"}, {"input": "70\n3326631213\n", "output": "6\n", "type": "code"}, {"input": "200\n10000000100000000000000000000100000000000000010000010000000000000...
2e4043fa95fcbed5bdc168967f8f9628
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nXenia the beginner mathematician is a third year student at elementary school. She is now learning the addition operation.\n\nThe teacher has written down the sum of multiple numbers. Pupils should calculate the sum. To m...
[{"input": "3+2+1\n", "output": "1+2+3\n", "type": "code"}, {"input": "1+1+3+1+3\n", "output": "1+1+1+3+3\n", "type": "code"}, {"input": "2\n", "output": "2\n", "type": "code"}, {"input": "2+2+1+1+3\n", "output": "1+1+2+2+3\n", "type": "code"}, {"input": "2+1+2+2+2+3+1+3+1+2\n", "output": "1+1+1+2+2+2+2+2+3+3\n", "type...
2b127a6c62af05e03e48ac4e7112c6ce
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nThere are $n$ students and $m$ clubs in a college. The clubs are numbered from $1$ to $m$. Each student has a potential $p_i$ and is a member of the club with index $c_i$. Initially, each student is a member of exactly on...
[{"input": "5 3\n0 1 2 2 0\n1 2 2 3 2\n5\n3\n2\n4\n5\n1\n", "output": "3\n1\n1\n1\n0\n", "type": "code"}, {"input": "5 3\n0 1 2 2 1\n1 3 2 3 2\n5\n4\n2\n3\n5\n1\n", "output": "3\n2\n2\n1\n0\n", "type": "code"}, {"input": "5 5\n0 1 2 4 5\n1 2 3 4 5\n4\n2\n3\n5\n4\n", "output": "1\n1\n1\n1\n", "type": "code"}, {"input": ...
f72f6c50394787652ffbb964db61256a
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nOstap already settled down in Rio de Janiero suburb and started to grow a tree in his garden. Recall that a tree is a connected undirected acyclic graph. \n\nOstap's tree now has n vertices. He wants to paint some vertice...
[{"input": "2 0\n1 2\n", "output": "1\n", "type": "code"}, {"input": "2 1\n1 2\n", "output": "3\n", "type": "code"}, {"input": "4 1\n1 2\n2 3\n3 4\n", "output": "9\n", "type": "code"}, {"input": "7 2\n1 2\n2 3\n1 4\n4 5\n1 6\n6 7\n", "output": "91\n", "type": "code"}, {"input": "1 0\n", "output": "1\n", "type": "code"}...
b8217840dea518ac49b3940ac9183ac5
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nThe first algorithm for detecting a face on the image working in realtime was developed by Paul Viola and Michael Jones in 2001. A part of the algorithm is a procedure that computes Haar features. As part of this task, we...
[{"input": "6 8\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW\n", "output": "2\n", "type": "code"}, {"input": "3 3\nWBW\nBWW\nWWW\n", "output": "4\n", "type": "code"}, {"input": "3 6\nWWBBWW\nWWBBWW\nWWBBWW\n", "output": "3\n", "type": "code"}, {"input": "4 4\nBBBB\nBBBB\nBBBB\nBBBW\n", "output": "4\n", "...
f547e94d09cd6987ab96a77e995cd3d6
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nIn 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 colum...
[{"input": "4 5\n1 3 5 6 7\n3 0 7 0 9\n5 0 0 0 10\n8 9 10 11 12\n", "output": "144\n", "type": "code"}, {"input": "3 3\n1 2 3\n2 0 4\n4 5 6\n", "output": "30\n", "type": "code"}, {"input": "3 3\n1 2 3\n3 0 4\n4 5 6\n", "output": "-1\n", "type": "code"}, {"input": "3 3\n1 2 3\n2 3 4\n3 4 2\n", "output": "-1\n", "type": ...
0cab7c559cc44ed5b98cea104536ee69
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nFor integers b (b \\geq 2) and n (n \\geq 1), let the function f(b,n) be defined as follows:\n - f(b,n) = n, when n < b\n - f(b,n) = f(b,\\,{\\rm floor}(n / b)) + (n \\ {\\rm mod} \\ b), when n \\geq b\nHere, {\\rm floor}...
[{"input": "87654\n30\n", "output": "10\n", "type": "code"}, {"input": "87654\n138\n", "output": "100\n", "type": "code"}, {"input": "87654\n45678\n", "output": "-1\n", "type": "code"}, {"input": "31415926535\n1\n", "output": "31415926535\n", "type": "code"}, {"input": "1\n31415926535\n", "output": "-1\n", "type": "cod...
9af28efda47122106d3d3cbfb6c56b1f
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nRikhail Mubinchik believes that the current definition of prime numbers is obsolete as they are too complex and unpredictable. A palindromic number is another matter. It is aesthetically pleasing, and it has a number of r...
[{"input": "1 1\n", "output": "40\n", "type": "code"}, {"input": "1 42\n", "output": "1\n", "type": "code"}, {"input": "6 4\n", "output": "172\n", "type": "code"}, {"input": "3 1\n", "output": "2530\n", "type": "code"}, {"input": "42 1\n", "output": "1179858\n", "type": "code"}, {"input": "10000 239\n", "output": "1168...
c390e12d92e3f803fe81d289c99dcdb2
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nRecently you have received two positive integer numbers $x$ and $y$. You forgot them, but you remembered a shuffled list containing all divisors of $x$ (including $1$ and $x$) and all divisors of $y$ (including $1$ and $y...
[{"input": "10\n10 2 8 1 2 4 1 20 4 5\n", "output": "20 8\n", "type": "code"}, {"input": "4\n9973 9973 1 1\n", "output": "9973 9973\n", "type": "code"}, {"input": "66\n35 90 36 7560 189 14 360 180 168 12 1 252 21 8 630 15 40 1512 18 9973 108 7 540 3 210 270 2520 504 1890 6 378 70 1080 30 20 84 1260 420 105 9 135 28 60 ...
7ebbe2e7a034c6c858d9044dbb6a699c
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nYou are given a problemset consisting of $n$ problems. The difficulty of the $i$-th problem is $a_i$. It is guaranteed that all difficulties are distinct and are given in the increasing order.\n\nYou have to assemble the ...
[{"input": "10\n1 2 5 6 7 10 21 23 24 49\n", "output": "4\n", "type": "code"}, {"input": "5\n2 10 50 110 250\n", "output": "1\n", "type": "code"}, {"input": "6\n4 7 12 100 150 199\n", "output": "3\n", "type": "code"}, {"input": "1\n1000000000\n", "output": "1\n", "type": "code"}, {"input": "2\n1 2\n", "output": "2\n", ...
0fb99dd4ba0acceaa7431d7e18dfba09
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nYou are given an integer sequence $a_1, a_2, \\dots, a_n$.\n\nFind the number of pairs of indices $(l, r)$ ($1 \\le l \\le r \\le n$) such that the value of median of $a_l, a_{l+1}, \\dots, a_r$ is exactly the given numbe...
[{"input": "5 4\n1 4 5 60 4\n", "output": "8\n", "type": "code"}, {"input": "3 1\n1 1 1\n", "output": "6\n", "type": "code"}, {"input": "15 2\n1 2 3 1 2 3 1 2 3 1 2 3 1 2 3\n", "output": "97\n", "type": "code"}, {"input": "1 1\n1\n", "output": "1\n", "type": "code"}, {"input": "2 1\n1 2\n", "output": "2\n", "type": "co...
ca3d9bba40ea3b2c17a4cfd70e37dc5a
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nYou are given a permutation $p_1, p_2, \\dots, p_n$. A permutation of length $n$ is a sequence such that each integer between $1$ and $n$ occurs exactly once in the sequence.\n\nFind the number of pairs of indices $(l, r)...
[{"input": "5 4\n2 4 5 3 1\n", "output": "4\n", "type": "code"}, {"input": "5 5\n1 2 3 4 5\n", "output": "1\n", "type": "code"}, {"input": "15 8\n1 15 2 14 3 13 4 8 12 5 11 6 10 7 9\n", "output": "48\n", "type": "code"}, {"input": "1 1\n1\n", "output": "1\n", "type": "code"}, {"input": "2 1\n1 2\n", "output": "2\n", "t...
d5d753fc449988807bedee39b05ca89f
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nThere are two sisters Alice and Betty. You have $n$ candies. You want to distribute these $n$ candies between two sisters in such a way that: Alice will get $a$ ($a > 0$) candies; Betty will get $b$ ($b > 0$) candies; ...
[{"input": "6\n7\n1\n2\n3\n2000000000\n763243547\n", "output": "3\n0\n0\n1\n999999999\n381621773\n", "type": "code"}, {"input": "2\n1\n2\n", "output": "0\n0\n", "type": "code"}, {"input": "1\n108139\n", "output": "54069\n", "type": "code"}, {"input": "5\n1\n1\n1\n1\n1\n", "output": "0\n0\n0\n0\n0\n", "type": "code"}, {...
6030a2a7ba30edca9b0aac86ee36da0f
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nThere are n persons who initially don't know each other. On each morning, two of them, who were not friends before, become friends.\n\nWe want to plan a trip for every evening of m days. On each trip, you have to select a...
[{"input": "4 4 2\n2 3\n1 2\n1 3\n1 4\n", "output": "0\n0\n3\n3\n", "type": "code"}, {"input": "5 8 2\n2 1\n4 2\n5 4\n5 2\n4 3\n5 1\n4 1\n3 2\n", "output": "0\n0\n0\n3\n3\n4\n4\n5\n", "type": "code"}, {"input": "5 7 2\n1 5\n3 2\n2 5\n3 4\n1 2\n5 3\n1 3\n", "output": "0\n0\n0\n0\n3\n4\n4\n", "type": "code"}, {"input": "...
550450240449db4654469cafa0a52b16
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nXenia the beginner mathematician is a third year student at elementary school. She is now learning the addition operation.\n\nThe teacher has written down the sum of multiple numbers. Pupils should calculate the sum. To m...
[{"input": "2\n", "output": "2\n", "type": "code"}, {"input": "3+2+1\n", "output": "1+2+3\n", "type": "code"}, {"input": "1+1+3+1+3\n", "output": "1+1+1+3+3\n", "type": "code"}, {"input": "2+2+1+1+3\n", "output": "1+1+2+2+3\n", "type": "code"}, {"input": "3+1\n", "output": "1+3\n", "type": "code"}, {"input": "1+3\n", "...
4ed91a995e908a6994e25bbcef2a2cfa
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nJoisino is planning to open a shop in a shopping street.\n\nEach of the five weekdays is divided into two periods, the morning and the evening. For each of those ten periods, a shop must be either open during the whole pe...
[{"input": "1\n1 1 0 1 0 0 0 1 0 1\n3 4 5 6 7 8 9 -2 -3 4 -2", "output": "8", "type": "code"}, {"input": "3\n1 1 1 1 1 1 0 0 1 1\n0 1 0 1 1 1 1 0 1 0\n1 0 1 1 0 1 0 1 0 1\n-8 6 -2 -8 -8 4 8 7 -6 2 2\n-9 2 0 1 7 -5 0 -2 -6 5 5\n6 -6 7 -9 6 -5 8 0 -9 -7 -7", "output": "23", "type": "code"}, {"input": "2\n1 1 1 1 1 0 0 0 ...
3e20c8a46e3cb6bdee90bff720dbbf55
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nYou are given an array a of n integers and an integer s. It is guaranteed that n is odd.\n\nIn one operation you can either increase or decrease any single element by one. Calculate the minimum number of operations requir...
[{"input": "3 8\n6 5 8\n", "output": "2\n", "type": "code"}, {"input": "7 20\n21 15 12 11 20 19 12\n", "output": "6\n", "type": "code"}, {"input": "3 1\n1 2 5\n", "output": "1\n", "type": "code"}, {"input": "1 1\n100000\n", "output": "99999\n", "type": "code"}, {"input": "5 1\n2 2 4 6 1\n", "output": "2\n", "type": "co...
6101a6a802fdc5169bac768c463528f4
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nBackground\n\nThe kindergarten attached to the University of Aizu is a kindergarten where children who love programming gather. Yu, one of the kindergarten children, loves rectangles as much as programming. Yu-kun decided...
[{"input": "4 4\n10 2 -1 6\n8 1 -100 41\n22 47 32 11\n-41 99 12 -8\n1 0 0 1\n0 0 1 0\n0 1 0 1\n0 0 1 0\n2 3\n1 0 1\n0 1 0", "output": "193", "type": "code"}, {"input": "3 4\n4 1 9 1\n9 1 -1 3\n2 -4 1 10\n1 1 0 1\n0 1 1 1\n1 1 0 0\n1 4\n1 1 1 1", "output": "NA", "type": "code"}, {"input": "3 3\n5 1 3\n2 5 9\n0 1 5\n1 0 ...
84115426b85dd697b0e8f2d1bf84a79c
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nA Garden with Ponds\n\nMr. Gardiner is a modern garden designer who is excellent at utilizing the terrain features. His design method is unique: he first decides the location of ponds and design them with the terrain feat...
[{"input": "3 3\n2 3 2\n2 1 2\n2 3 1\n3 5\n3 3 4 3 3\n3 1 0 2 3\n3 3 4 3 2\n7 7\n1 1 1 1 1 0 0\n1 0 0 0 1 0 0\n1 0 1 1 1 1 1\n1 0 1 0 1 0 1\n1 1 1 1 1 0 1\n0 0 1 0 0 0 1\n0 0 1 1 1 1 1\n6 6\n1 1 1 1 2 2\n1 0 0 2 0 2\n1 0 0 2 0 2\n3 3 3 9 9 9\n3 0 0 9 0 9\n3 3 3 9 9 9\n0 0", "output": "0\n3\n1\n9", "type": "code"}, {"in...
a4c0d687fe63af5d95e8ad0197fb7e01
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nThere are n piranhas with sizes a_1, a_2, …, a_n in the aquarium. Piranhas are numbered from left to right in order they live in the aquarium.\n\nScientists of the Berland State University want to find if there is dominan...
[{"input": "6\n5\n5 3 4 4 5\n3\n1 1 1\n5\n4 4 3 4 4\n5\n5 5 4 3 2\n3\n1 1 2\n5\n5 4 3 5 5\n", "output": "1\n-1\n2\n2\n3\n1\n", "type": "code"}, {"input": "1\n3\n5 3 4\n", "output": "1\n", "type": "code"}, {"input": "6\n5\n5 3 4 4 5\n3\n1 1 1\n5\n4 4 3 4 4\n5\n5 5 4 3 2\n3\n1 1 2\n5\n5 4 3 5 5\n", "output": "1\n-1\n2\n2...
7513ed37b2a1fba399dd8aac3f565139
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nThere are n students and m clubs in a college. The clubs are numbered from 1 to m. Each student has a potential p_i and is a member of the club with index c_i. Initially, each student is a member of exactly one club. A te...
[{"input": "5 5\n0 1 2 4 5\n1 2 3 4 5\n4\n2\n3\n5\n4\n", "output": "1\n1\n1\n1\n", "type": "code"}, {"input": "5 3\n0 1 2 2 0\n1 2 2 3 2\n5\n3\n2\n4\n5\n1\n", "output": "3\n1\n1\n1\n0\n", "type": "code"}, {"input": "5 3\n0 1 2 2 1\n1 3 2 3 2\n5\n4\n2\n3\n5\n1\n", "output": "3\n2\n2\n1\n0\n", "type": "code"}, {"input": ...
126370b161576e7b03e29eec1c759265
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nKoa the Koala and her best friend want to play a game.\n\nThe game starts with an array a of length n consisting of non-negative integers. Koa and her best friend move in turns and each have initially a score equal to 0. ...
[{"input": "4\n5\n4 1 5 1 3\n4\n1 0 1 6\n1\n0\n2\n5 4\n", "output": "WIN\nWIN\nDRAW\nWIN\n", "type": "code"}, {"input": "3\n3\n1 2 2\n3\n2 2 3\n5\n0 0 0 2 2\n", "output": "WIN\nLOSE\nDRAW\n", "type": "code"}, {"input": "3\n3\n2 2 2\n3\n2 2 3\n5\n0 0 0 2 2\n", "output": "LOSE\nLOSE\nDRAW\n", "type": "code"}, {"input": "...
6107f809660786e5043bbfcbeb70d871
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nDima loves Inna very much. He decided to write a song for her. Dima has a magic guitar with n strings and m frets. Dima makes the guitar produce sounds like that: to play a note, he needs to hold one of the strings on one...
[{"input": "4 6 5 7\n3 1 2 2 3 1\n3 2 2 2 5 5\n4 2 2 2 5 3\n3 2 2 1 4 3\n2 3 1 4 1 5 1\n", "output": "8\n", "type": "code"}, {"input": "4 4 9 5\n4 7 9 5\n1 2 1 7\n8 3 4 9\n5 7 7 2\n7 1 9 2 5\n", "output": "4\n", "type": "code"}, {"input": "10 1 9 5\n1\n2\n3\n4\n5\n6\n7\n8\n9\n1\n1 1 9 2 3\n", "output": "9\n", "type": "...
937003991d6ef2cc9157860fbe7344b9
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nSome natural number was written on the board. Its sum of digits was not less than k. But you were distracted a bit, and someone changed this number to n, replacing some digits with others. It's known that the length of th...
[{"input": "3\n11\n", "output": "1\n", "type": "code"}, {"input": "3\n99\n", "output": "0\n", "type": "code"}, {"input": "3\n21\n", "output": "0\n", "type": "code"}, {"input": "3\n111\n", "output": "0\n", "type": "code"}, {"input": "6\n33\n", "output": "0\n", "type": "code"}, {"input": "6\n222\n", "output": "0\n", "typ...
9e18f043e2e67cc3104198fdec62a00a
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nBob loves sorting very much. He is always thinking of new ways to sort an array.His friend Ram gives him a challenging task.He gives Bob an array and an integer K .The challenge is to produce the lexicographical minimal a...
[{"input": "2\n3 2\n5 3 1\n5 3\n8 9 11 2 1\n\nSAMPLE", "output": "1 5 3\n2 8 9 11 1\n", "type": "code"}, {"input": "7\n929 320\n25908 624 13924 20094 9600 20729 20932 18348 14154 1502 19845 31067 22191 8352 20405 17322 11359 3061 10689 15785 4412 8975 22688 1214 12324 7201 21838 6984 31242 31776 18812 6787 8268 30663 3...
faba6209220656e38492deb72092f305
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nLet's call an array t dominated by value v in the next situation.\n\nAt first, array t should have at least 2 elements. Now, let's calculate number of occurrences of each number num in t and define it as occ(num). Then t ...
[{"input": "4\n1\n1\n6\n1 2 3 4 5 1\n9\n4 1 2 4 5 4 3 2 1\n4\n3 3 3 3\n", "output": "-1\n6\n3\n2\n", "type": "code"}, {"input": "1\n11\n1 1 1 1 1 1 1 1 1 1 1\n", "output": "2\n", "type": "code"}, {"input": "1\n12\n1 1 1 1 1 1 1 1 1 1 1 1\n", "output": "2\n", "type": "code"}, {"input": "1\n2\n2 2\n", "output": "2\n", "t...
bef725ec9aff13e9ed5a103cd4f54337
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nFor integers b (b \\geq 2) and n (n \\geq 1), let the function f(b,n) be defined as follows:\n\n* f(b,n) = n, when n < b\n* f(b,n) = f(b,\\,{\\rm floor}(n / b)) + (n \\ {\\rm mod} \\ b), when n \\geq b\n\n\n\nHere, {\\rm ...
[{"input": "87654\n30", "output": "10", "type": "code"}, {"input": "87654\n138", "output": "100", "type": "code"}, {"input": "87654\n45678", "output": "-1", "type": "code"}, {"input": "31415926535\n1", "output": "31415926535", "type": "code"}, {"input": "1\n31415926535", "output": "-1", "type": "code"}, {"input": "8765...
b4e261f6f1745a35f44229365d61dfba
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nLet \\mathrm{popcount}(n) be the number of `1`s in the binary representation of n. For example, \\mathrm{popcount}(3) = 2, \\mathrm{popcount}(7) = 3, and \\mathrm{popcount}(0) = 0.\n\nLet f(n) be the number of times the f...
[{"input": "23\n00110111001011011001110", "output": "2\n1\n2\n2\n1\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n2\n1\n3", "type": "code"}, {"input": "3\n011", "output": "2\n1\n1", "type": "code"}, {"input": "23\n00110111001011011001111", "output": "3\n3\n2\n2\n3\n3\n2\n3\n3\n3\n2\n2\n3\n2\n2\n2\n2\n3\n2\n3\n3\n3\n2\n"...
96fef62df8440b3b5488fe47fc592927
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nYou are given an array a of length n consisting of integers. You can apply the following operation, consisting of several steps, on the array a zero or more times: \n\n * you select two different numbers in the array a_i...
[{"input": "5\n6\n1 6 1 1 4 4\n2\n1 2\n2\n1 1\n5\n4 5 4 5 4\n6\n2 3 2 1 3 1\n", "output": "\n0\n0\n2\n1\n0\n", "type": "code"}, {"input": "1\n12\n2 2 2 2 4 4 4 4 6 6 6 6\n", "output": "0\n", "type": "code"}, {"input": "1\n12\n1 2 2 2 4 4 4 4 6 6 6 6\n", "output": "0\n", "type": "code"}, {"input": "5\n6\n2 6 1 1 4 4\n2\...
97aa37750b0b6ce13fbe0958d45c8804
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nThe \"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...
[{"input": "8 7\n0\n3 1 2 3\n1 1\n2 5 4\n2 6 7\n1 3\n2 7 4\n1 1\n", "output": "2", "type": "code"}, {"input": "2 2\n1 2\n0\n", "output": "1", "type": "code"}, {"input": "5 5\n1 2\n2 2 3\n2 3 4\n2 4 5\n1 5\n", "output": "0", "type": "code"}, {"input": "3 3\n0\n0\n0\n", "output": "3", "type": "code"}, {"input": "8 4\n0\n...
80fbac80d207735c0d2b450dfbd174d8
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nA binary heap which satisfies max-heap property is called max-heap. In a max-heap, for every node $i$ other than the root, $A[i] \\leq A[parent(i)]$, that is, the value of a node is at most the value of its parent. The la...
[{"input": "10\n4 1 3 2 16 9 10 14 8 7", "output": "16 14 10 8 7 9 3 2 4 1", "type": "code"}, {"input": "10\n4 1 3 2 16 9 10 2 8 7", "output": " 16 8 10 4 7 9 3 2 2 1\n", "type": "code"}, {"input": "10\n4 1 3 2 23 9 10 2 8 7", "output": " 23 8 10 4 7 9 3 2 2 1\n", "type": "code"}, {"input": "10\n7 1 3 2 23 9 10 2 8 7",...
144e2c11338316bc4a9286cd5bbd528f
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nYou are given a weighted undirected connected graph consisting of n vertices and m edges. It is guaranteed that there are no self-loops or multiple edges in the given graph.\n\nLet's define the weight of the path consisti...
[{"input": "7 10\n7 5 5\n2 3 3\n4 7 1\n5 3 6\n2 7 6\n6 2 6\n3 7 6\n4 2 1\n3 1 4\n1 7 4\n", "output": "\n3 4 2 7 7 3 \n", "type": "code"}, {"input": "5 4\n5 3 4\n2 1 1\n3 2 2\n2 4 2\n", "output": "\n1 2 2 4 \n", "type": "code"}, {"input": "6 8\n3 1 1\n3 6 2\n5 4 2\n4 2 2\n6 1 1\n5 2 1\n3 2 3\n1 5 4\n", "output": "\n2 1 ...
1e48c184cde0d68bdb5ca3446bb02e27
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nInternational Center for Picassonian Cubism is a Spanish national museum of cubist artworks, dedicated to Pablo Picasso. The center held a competition for an artwork that will be displayed in front of the facade of the mu...
[{"input": "5 5\n1 2 3 4 5\n1 2 3 4 5\n5 5\n2 5 4 1 3\n4 1 5 3 2\n5 5\n1 2 3 4 5\n3 3 3 4 5\n3 3\n7 7 7\n7 7 7\n3 3\n4 4 4\n4 3 4\n4 3\n4 2 2 4\n4 2 1\n4 4\n2 8 8 8\n2 3 8 3\n10 10\n9 9 9 9 9 9 9 9 9 9\n9 9 9 9 9 9 9 9 9 9\n10 9\n20 1 20 20 20 20 20 18 20 20\n20 20 20 20 7 20 20 20 20\n0 0", "output": "15\n15\n21\n21\n...
30a7bc2f131b3c2e2cbdca23b709c3f3
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nThere are n slimes in a row. Each slime has an integer value (possibly negative or zero) associated with it.\n\nAny slime can eat its adjacent slime (the closest slime to its left or to its right, assuming that this slime...
[{"input": "5\n0 -1 -1 -1 -1\n", "output": "4\n", "type": "code"}, {"input": "4\n2 1 2 1\n", "output": "4\n", "type": "code"}, {"input": "2\n-4 -5\n", "output": "1\n", "type": "code"}, {"input": "10\n-20 0 3 -5 -18 15 -3 -9 -7 9\n", "output": "89\n", "type": "code"}, {"input": "2\n-2 -2\n", "output": "0\n", "type": "co...
b71f96f4afe9918047f9696909dc9e6b
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nRikhail Mubinchik believes that the current definition of prime numbers is obsolete as they are too complex and unpredictable. A palindromic number is another matter. It is aesthetically pleasing, and it has a number of r...
[{"input": "1 1\n", "output": "40", "type": "code"}, {"input": "1 42\n", "output": "1", "type": "code"}, {"input": "6 4\n", "output": "172", "type": "code"}, {"input": "10000 10000\n", "output": "40", "type": "code"}, {"input": "5858 674\n", "output": "71118", "type": "code"}, {"input": "214 210\n", "output": "40", "ty...
c0eade2e0b5a4bbd66d516e7b5733094
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nThe map of Bertown can be represented as a set of n intersections, numbered from 1 to n and connected by m one-way roads. It is possible to move along the roads from any intersection to any other intersection. The length ...
[{"input": "7 7\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 1\n7\n1 2 3 4 5 6 7\n", "output": "0 0\n", "type": "code"}, {"input": "8 13\n8 7\n8 6\n7 5\n7 4\n6 5\n6 4\n5 3\n5 2\n4 3\n4 2\n3 1\n2 1\n1 8\n5\n8 7 5 2 1\n", "output": "0 3\n", "type": "code"}, {"input": "6 9\n1 5\n5 4\n1 2\n2 3\n3 4\n4 1\n2 6\n6 4\n4 2\n4\n1 2 3 4\n", ...
e2a8d425502703793981b83e1238c6af
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nPolycarp is a frequent user of the very popular messenger. He's chatting with his friends all the time. He has n friends, numbered from 1 to n.\n\nRecall that a permutation of size n is an array of size n such that each i...
[{"input": "5 4\n3 5 1 4\n", "output": "1 3\n2 5\n1 4\n1 5\n1 5\n", "type": "code"}, {"input": "4 3\n1 2 4\n", "output": "1 3\n1 2\n3 4\n1 4\n", "type": "code"}, {"input": "2 1\n2\n", "output": "1 2\n1 2\n", "type": "code"}, {"input": "5 5\n1 1 4 2 2\n", "output": "1 3\n1 3\n3 4\n1 4\n5 5\n", "type": "code"}, {"input":...
9ff801f530c39be15df0323414ffdbf9
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nChef Monocarp has just put n dishes into an oven. He knows that the i-th dish has its optimal cooking time equal to t_i minutes.\n\nAt any positive integer minute T Monocarp can put no more than one dish out of the oven. ...
[{"input": "6\n6\n4 2 4 4 5 2\n7\n7 7 7 7 7 7 7\n1\n1\n5\n5 1 2 4 3\n4\n1 4 4 4\n21\n21 8 1 4 1 5 21 1 8 21 11 21 11 3 12 8 19 15 9 11 13\n", "output": "4\n12\n0\n0\n2\n21\n", "type": "code"}, {"input": "1\n200\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...
5be1cc00d890339b3c92e953a0e299cb
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nRikhail Mubinchik believes that the current definition of prime numbers is obsolete as they are too complex and unpredictable. A palindromic number is another matter. It is aesthetically pleasing, and it has a number of r...
[{"input": "6 4\n", "output": "172\n", "type": "code"}, {"input": "1 1\n", "output": "40\n", "type": "code"}, {"input": "1 42\n", "output": "1\n", "type": "code"}, {"input": "238 9996\n", "output": "1\n", "type": "code"}, {"input": "9999 9999\n", "output": "40\n", "type": "code"}, {"input": "620 35\n", "output": "25126...
c0eade2e0b5a4bbd66d516e7b5733094
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nYou are given a tree (connected graph without cycles) consisting of n vertices. The tree is unrooted — it is just a connected undirected graph without cycles.\n\nIn one move, you can choose exactly k leaves (leaf is such ...
[{"input": "4\n8 3\n1 2\n1 5\n7 6\n6 8\n3 1\n6 4\n6 1\n10 3\n1 2\n1 10\n2 3\n1 5\n1 6\n2 4\n7 10\n10 9\n8 10\n7 2\n3 1\n4 5\n3 6\n7 4\n1 2\n1 4\n5 1\n1 2\n2 3\n4 3\n5 3\n", "output": "2\n3\n3\n4\n", "type": "code"}, {"input": "4\n8 3\n1 2\n1 5\n7 6\n6 8\n3 1\n6 4\n6 1\n10 3\n1 2\n1 10\n2 3\n1 5\n1 6\n2 4\n7 10\n10 9\n8...
21ff97575b6f5c04780669aea1c23172
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nJust to remind, girls in Arpa's land are really nice.\n\nMehrdad wants to invite some Hoses to the palace for a dancing party. Each Hos has some weight wi and some beauty bi. Also each Hos may have some friends. Hoses are...
[{"input": "4 2 11\n2 4 6 6\n6 4 2 1\n1 2\n2 3\n", "output": "7\n", "type": "code"}, {"input": "3 1 5\n3 2 5\n2 4 2\n1 2\n", "output": "6\n", "type": "code"}, {"input": "10 5 100\n64 90 3 94 96 97 52 54 82 31\n796554 444893 214351 43810 684158 555762 686198 339093 383018 699152\n6 8\n8 3\n3 9\n2 3\n10 3\n", "output": "...
4c92be9f3db01e87f8ac3dd503a1224c
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nRecently you have received two positive integer numbers x and y. You forgot them, but you remembered a shuffled list containing all divisors of x (including 1 and x) and all divisors of y (including 1 and y). If d is a di...
[{"input": "10\n10 2 8 1 2 4 1 20 4 5\n", "output": "20 8\n", "type": "code"}, {"input": "4\n1 2 53 1\n", "output": "53 2\n", "type": "code"}, {"input": "6\n1 58 29 1 2 2\n", "output": "58 2\n", "type": "code"}, {"input": "6\n29 29 1 1 58 2\n", "output": "58 29\n", "type": "code"}, {"input": "9\n7 49 1 1 98 14 49 7 2\n...
4fb02de11a21613420f12b1dfbce3d1e
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nConnected undirected graph without cycles is called a tree. Trees is a class of graphs which is interesting not only for people, but for ants too.\n\nAn ant stands at the root of some tree. He sees that there are n vertex...
[{"input": "6\n1 2\n1 3\n2 4\n4 5\n4 6\n5 6 3\n", "output": "1 2 4 5 4 6 4 2 1 3 1 ", "type": "code"}, {"input": "3\n1 2\n2 3\n3\n", "output": "1 2 3 2 1 ", "type": "code"}, {"input": "6\n1 2\n1 3\n2 4\n4 5\n4 6\n5 3 6\n", "output": "-1", "type": "code"}, {"input": "20\n4 13\n17 7\n19 10\n18 1\n5 15\n2 6\n11 7\n3 6\n5 ...
60d6d14a3f70983f9341258ab17a4d93
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nThere are two sisters Alice and Betty. You have n candies. You want to distribute these n candies between two sisters in such a way that:\n\n * Alice will get a (a > 0) candies; \n * Betty will get b (b > 0) candies; \n...
[{"input": "6\n7\n1\n2\n3\n2000000000\n763243547\n", "output": "3\n0\n0\n1\n999999999\n381621773\n", "type": "code"}, {"input": "39\n2\n3\n5\n7\n9\n8\n6\n5\n4\n4\n9\n4\n5\n6\n8\n1\n5\n4\n3\n10\n7\n1\n1\n4\n3\n5\n6\n2\n5\n9\n9\n6\n6\n4\n5\n3\n10\n10\n1\n", "output": "0\n1\n2\n3\n4\n3\n2\n2\n1\n1\n4\n1\n2\n2\n3\n0\n2\n1\...
2dc70aa937c012accb83483830771a5d
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nOn the Internet, data is divided into packets, and each packet is transferred to a destination via a relay device called a router. Each router determines the next router to forward from the destination described in the pa...
[{"input": "7\n1 4 2 5 4 3\n2 1 5\n3 1 6\n4 1 7\n5 2 7 6\n6 1 1\n7 0\n6\n1 2 2\n1 5 3\n1 2 1\n5 1 3\n6 3 3\n1 7 4", "output": "2\n2\nNA\n3\n3\n3", "type": "code"}, {"input": "7\n1 4 2 5 4 3\n2 1 5\n3 1 6\n4 1 7\n5 2 7 6\n6 1 1\n7 0\n6\n1 2 2\n1 5 3\n1 2 0\n5 1 3\n6 3 3\n1 7 4", "output": "2\n2\nNA\n3\n3\n3\n", "type": ...
f597641cd55083eea25befa88f60e201
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nproblem\n\nDo you know Just Odd Inventions? The business of this company is to \"just odd inventions\". Here we call it JOI for short.\n\nJOI has two offices, each of which has square rooms of the same size arranged in a ...
[{"input": "5\n2 2 1 2\n9 5\n1 17\n3 2 2 1\n6 1 20\n8 18 3\n8\n5 4 1 3\n5 5 4 5 5\n8 2 1 9 7\n1 1 3 5 1\n7 2 7 1 3\n6 5 6 2\n2 3 5 8 2 7\n1 6 9 4 5 1\n2 4 5 4 2 2\n5 4 2 5 3 3\n7 1 5 1 5 6\n6\n3 3 2 2\n2 9 2\n9 1 9\n2 9 2\n2 2 1 1\n1 3\n5 7\n0", "output": "15\n4\n9", "type": "code"}, {"input": "5\n2 2 1 2\n9 5\n1 17\n3...
fc41fab0bacfb6d8b71b76637a460a89
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nYou have a list of numbers from 1 to n written from left to right on the blackboard.\n\nYou perform an algorithm consisting of several steps (steps are 1-indexed). On the i-th step you wipe the i-th number (considering on...
[{"input": "3\n3 1\n4 2\n69 6\n", "output": "2\n4\n12\n", "type": "code"}, {"input": "1\n241139 1\n", "output": "2\n", "type": "code"}, {"input": "1\n2441139 10\n", "output": "20\n", "type": "code"}, {"input": "1\n2452199 2\n", "output": "4\n", "type": "code"}, {"input": "1\n244139 1\n", "output": "2\n", "type": "code"...
10ccba5e52e871f359c1d46ddb534871
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nKoa the Koala and her best friend want to play a game.\n\nThe game starts with an array a of length n consisting of non-negative integers. Koa and her best friend move in turns and each have initially a score equal to 0. ...
[{"input": "3\n3\n1 2 2\n3\n2 2 3\n5\n0 0 0 2 2\n", "output": "WIN\nLOSE\nDRAW\n", "type": "code"}, {"input": "4\n5\n4 1 5 1 3\n4\n1 0 1 6\n1\n0\n2\n5 4\n", "output": "WIN\nWIN\nDRAW\nWIN\n", "type": "code"}, {"input": "3\n3\n1 2 2\n3\n2 2 3\n5\n0 0 1 2 2\n", "output": "WIN\nLOSE\nWIN\n", "type": "code"}, {"input": "3\...
6107f809660786e5043bbfcbeb70d871
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nSilver Fox is fighting with N monsters.\n\nThe monsters are standing in a row, and we can assume them to be standing on a number line. The i-th monster, standing at the coordinate X_i, has the health of H_i.\n\nSilver Fox...
[{"input": "9 4 1\n1 5\n2 4\n3 3\n4 2\n5 1\n6 2\n7 3\n8 4\n9 5", "output": "5", "type": "code"}, {"input": "3 3 2\n1 2\n5 4\n9 2", "output": "2", "type": "code"}, {"input": "3 0 1\n300000000 1000000000\n100000000 1000000000\n200000000 1000000000", "output": "3000000000", "type": "code"}, {"input": "9 4 1\n1 5\n2 4\n3 3...
177f66a3f9aa79c91514ef440ae0db16
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nYou are given a problemset consisting of n problems. The difficulty of the i-th problem is a_i. It is guaranteed that all difficulties are distinct and are given in the increasing order.\n\nYou have to assemble the contes...
[{"input": "5\n2 10 50 110 250\n", "output": "1\n", "type": "code"}, {"input": "10\n1 2 5 6 7 10 21 23 24 49\n", "output": "4\n", "type": "code"}, {"input": "6\n4 7 12 100 150 199\n", "output": "3\n", "type": "code"}, {"input": "2\n2 3\n", "output": "2\n", "type": "code"}, {"input": "2\n10 20\n", "output": "2\n", "type...
a5c97ddf3b1a36fb99207f290662578e
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nConsider some square matrix A with side n consisting of zeros and ones. There are n rows numbered from 1 to n from top to bottom and n columns numbered from 1 to n from left to right in this matrix. We'll denote the eleme...
[{"input": "9\n", "output": "5\n", "type": "code"}, {"input": "4\n", "output": "3\n", "type": "code"}, {"input": "6\n", "output": "5\n", "type": "code"}, {"input": "89\n", "output": "15\n", "type": "code"}, {"input": "15\n", "output": "7\n", "type": "code"}, {"input": "91\n", "output": "15\n", "type": "code"}, {"input"...
77c3ad0158530161e5f846a9f0967eb3
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nByteburg Senate elections are coming. Usually \"United Byteland\", the ruling Byteland party, takes all the seats in the Senate to ensure stability and sustainable development. But this year there is one opposition candid...
[{"input": "2 1\n1 1\n", "output": "0\n", "type": "code"}, {"input": "3 3\n2 3 8\n4 2 9\n3 1 7\n", "output": "3\n1 2 3", "type": "code"}, {"input": "5 3\n6 3 4 2 8\n3 7 5 6 7\n5 2 4 7 9\n", "output": "2\n3 1", "type": "code"}, {"input": "2 1\n1000 1000\n", "output": "0\n", "type": "code"}, {"input": "2 1\n0 0\n", "outp...
cfa2c96747b877b97b49c7efb75ad516
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nPolycarp came up with a new programming language. There are only two types of statements in it: \n\n * \"x := s\": assign the variable named x the value s (where s is a string). For example, the statement var := hello as...
[{"input": "4\n6\na := h\nb := aha\nc = a + b\nc = c + c\ne = c + c\nd = a + c\n15\nx := haha\nx = x + x\nx = x + x\nx = x + x\nx = x + x\nx = x + x\nx = x + x\nx = x + x\nx = x + x\nx = x + x\nx = x + x\nx = x + x\nx = x + x\nx = x + x\nx = x + x\n1\nhaha := hah\n5\nhaahh := aaaha\nahhhh = haahh + haahh\nhaahh = haahh...
bbee6cdf10ae0e7410c7336356b2ab14
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nYou are given a set of n elements indexed from 1 to n. The weight of i-th element is wi. The weight of some subset of a given set is denoted as <image>. The weight of some partition R of a given set into k subsets is <ima...
[{"input": "5 2\n1 2 3 4 5\n", "output": "645\n", "type": "code"}, {"input": "4 2\n2 3 2 3\n", "output": "160\n", "type": "code"}, {"input": "5 2\n3113 612 440 2761 6970\n", "output": "597528\n", "type": "code"}, {"input": "1 1\n1\n", "output": "1\n", "type": "code"}, {"input": "4 2\n4049 2220 6447 3695\n", "output": "...
0a7d120312afa142045850e634dc4a09
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nConsider a string with rings on both ends. Rings have positive integers to distinguish them. Rings on both ends of the string have different numbers a and b. Describe this as [a, b]. If there are multiple strings and the ...
[{"input": "7\n1 3\n3 4\n1 4\n2 7\n5 7\n6 7\n1 7\n6\n1 2\n2 3\n3 4\n4 5\n1 5\n2 6\n7\n1 3\n2 4\n3 5\n4 6\n6 7\n2 6\n4 7\n0", "output": "5\n6\n4", "type": "code"}, {"input": "7\n1 3\n3 4\n1 4\n2 7\n5 7\n6 7\n1 7\n6\n1 2\n2 3\n3 4\n4 4\n1 5\n2 6\n7\n1 3\n2 4\n3 5\n4 6\n6 7\n2 6\n4 7\n0", "output": "5\n5\n4\n", "type": "c...
190176961bd7075fddd2aae5fa9cbe12
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nGiven is a positive integer N.\nFind the number of pairs (A, B) of positive integers not greater than N that satisfy the following condition:\n\n* When A and B are written in base ten without leading zeros, the last digit...
[{"input": "2020", "output": "40812", "type": "code"}, {"input": "200000", "output": "400000008", "type": "code"}, {"input": "25", "output": "17", "type": "code"}, {"input": "100", "output": "108", "type": "code"}, {"input": "1", "output": "1", "type": "code"}, {"input": "73", "output": "63\n", "type": "code"}, {"input...
ffc372311e0a9aed1d6c82707a4e81ad
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nBajtek, known for his unusual gifts, recently got an integer array x_0, x_1, …, x_{k-1}.\n\nUnfortunately, after a huge array-party with his extraordinary friends, he realized that he'd lost it. After hours spent on searc...
[{"input": "5\n1 2 3 4 5\n", "output": "5\n1 2 3 4 5 ", "type": "code"}, {"input": "5\n1 3 5 6 8\n", "output": "2\n3 5 ", "type": "code"}, {"input": "3\n1 5 3\n", "output": "1\n3 ", "type": "code"}, {"input": "4\n5 4 9 11\n", "output": "1\n4 ", "type": "code"}, {"input": "5\n5 7 12 14 19\n", "output": "3\n2 4 5 ", "typ...
199e5d34e294a23a6d73988073471a9e
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nLittle Chris is a huge fan of linear algebra. This time he has been given a homework about the unusual square of a square matrix.\n\nThe dot product of two integer number vectors x and y of size n is the sum of the produc...
[{"input": "3\n1 1 1\n0 1 1\n1 0 0\n12\n3\n2 3\n3\n2 2\n2 2\n1 3\n3\n3\n1 2\n2 1\n1 1\n3\n", "output": "01001", "type": "code"}, {"input": "2\n0 0\n0 0\n9\n3\n1 2\n2 2\n1 1\n2 1\n3\n1 2\n1 1\n3\n", "output": "000", "type": "code"}, {"input": "1\n0\n5\n1 1\n3\n1 1\n1 1\n3\n", "output": "11", "type": "code"}, {"input": "...
7ea809c83aaa200bde6f17bc687af2a3
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nICPC Calculator\n\nIn mathematics, we usually specify the order of operations by using parentheses. For example, 7 × (3 + 2) always means multiplying 7 by the result of 3 + 2 and never means adding 2 to the result of 7 × ...
[{"input": "1\n9\n4\n+\n.1\n.2\n.3\n9\n+\n.0\n.+\n..*\n...1\n...*\n....1\n....2\n..0\n10\n+\n.+\n..6\n..2\n.+\n..1\n..*\n...7\n...6\n.3\n0", "output": "9\n6\n2\n54", "type": "code"}, {"input": "1\n9\n4\n+\n.1\n.2\n.3\n9\n+\n.0\n.+\n..*\n...1\n...+\n....1\n....2\n..0\n10\n+\n.+\n..6\n..2\n.+\n..1\n..*\n...7\n...6\n.3\n0...
95102b8e650a596daed1434c43f031fb
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nYou are given a tree, which consists of n vertices. Recall that a tree is a connected undirected graph without cycles. \n\n<image> Example of a tree.\n\nVertices are numbered from 1 to n. All vertices have weights, the we...
[{"input": "7 2\n2 1 2 1 2 1 1\n6 4\n1 5\n3 1\n2 3\n7 5\n7 4\n", "output": "4\n", "type": "code"}, {"input": "5 1\n1 2 3 4 5\n1 2\n2 3\n3 4\n3 5\n", "output": "11\n", "type": "code"}, {"input": "14 2\n3 2 3 1 2 3 4 2 3 1 4 2 1 3\n12 10\n2 7\n13 12\n14 11\n10 5\n1 2\n11 4\n4 9\n14 8\n12 4\n7 9\n13 6\n10 3\n", "output": ...
fd3c6657044ba7d111b29d50db345100
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nAt the end of last year, Santa Claus forgot to give Christmas presents to the children in JOI village. Therefore, I decided to deliver the chocolate cake to the children as an apology. The day to deliver is approaching to...
[{"input": "5 4\n3\n1 1\n3 4\n5 3", "output": "10\n3 3", "type": "code"}, {"input": "5 4\n3\n1 1\n3 4\n5 6", "output": "13\n3 4\n", "type": "code"}, {"input": "6 4\n3\n1 1\n1 4\n5 6", "output": "12\n1 4\n", "type": "code"}, {"input": "6 4\n3\n1 1\n1 4\n5 12", "output": "18\n1 4\n", "type": "code"}, {"input": "6 4\n3\n0...
7d940bd9c44814ff5e65854c2d0df5d2
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nThere are $ n $ acitivities with start times $ \\\\ {s_i \\\\} $ and finish times $ \\\\ {t_i \\\\} $. Assuming that a person can only work on a single activity at a time, find the maximum number of activities that can be...
[{"input": "5\n1 2\n3 9\n3 5\n5 9\n6 8", "output": "3", "type": "code"}, {"input": "3\n1 2\n2 3\n3 4", "output": "2", "type": "code"}, {"input": "3\n1 5\n3 4\n2 5", "output": "1", "type": "code"}, {"input": "5\n2 2\n3 9\n3 5\n5 9\n6 8", "output": "3\n", "type": "code"}, {"input": "3\n1 1\n2 3\n3 4", "output": "2\n", "t...
bbfc05f7476fb32cee9b823aa280a316
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nYou are given a permutation p_1, p_2, …, p_n of integers from 1 to n and an integer k, such that 1 ≤ k ≤ n. A permutation means that every number from 1 to n is contained in p exactly once.\n\nLet's consider all partition...
[{"input": "5 5\n2 1 5 3 4\n", "output": "15 1\n", "type": "code"}, {"input": "3 2\n2 1 3\n", "output": "5 2\n", "type": "code"}, {"input": "7 3\n2 7 3 1 5 4 6\n", "output": "18 6\n", "type": "code"}, {"input": "1 1\n1\n", "output": "1 1\n", "type": "code"}, {"input": "10 3\n4 6 7 8 9 1 10 3 5 2\n", "output": "27 2\n",...
14fd6053a1b8b1c3146ae148e027e241
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nDr. Jimbo, an applied mathematician, needs to calculate matrices all day for solving his own problems. In his laboratory, he uses an excellent application program for manipulating matrix expressions, however, he cannot us...
[{"input": "1\nA=[1 2 3;4 5 6].\n1\nA=[[1 2 3;4 5 6] [7 8;9 10] [11;12];13 14 15 16 17 18].\n3\nB=[3 -2 1;-9 8 7].\nC=([1 2 3;4 5 6]+B)(2,3).\nD=([1 2 3;4 5 6]+B)([1 2],[2 3]).\n5\nA=2*[1 2;-3 4]'.\nB=A([2 1 2],[2 1]).\nA=[1 2;3 4]*3.\nA=[2]*[1 2;3 4].\nA=[1 2;3 4]*[3].\n2\nA=[11 12 13;0 22 23;0 0 33].\nA=[A A';--A''' ...
40b34ede6c75e8a227c6946aa45efaf0
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nIn this problem, a n × 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}<...<a_{i,m}) and for each column j, when go from...
[{"input": "3 3\n1 2 3\n2 0 4\n4 5 6\n", "output": "30\n", "type": "code"}, {"input": "3 3\n1 2 3\n2 3 4\n3 4 2\n", "output": "-1\n", "type": "code"}, {"input": "4 5\n1 3 5 6 7\n3 0 7 0 9\n5 0 0 0 10\n8 9 10 11 12\n", "output": "144\n", "type": "code"}, {"input": "3 3\n1 2 3\n3 0 4\n4 5 6\n", "output": "-1\n", "type": ...
f016adcfef861c3351264fcf7ea06463
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nConsider creating the following number pattern.\n\n\n4 8 2 3 1 0 8 3 7 6\n2 0 5 4 1 8 1 0 3\n2 5 9 5 9 9 1 3\n7 4 4 4 8 0 4\n1 8 8 2 8 4\n9 6 0 0 2\n5 6 0 2\n1 6 2\n7 8\nFive\n\n\nThis pattern follows the rules below.\n\n...
[{"input": "4823108376\n1234567890\n0123456789", "output": "5\n6\n4", "type": "code"}, {"input": "4823108376\n2273064329\n0123456789", "output": "5\n1\n4\n", "type": "code"}, {"input": "4823108376\n2314825047\n0123456789", "output": "5\n4\n4\n", "type": "code"}, {"input": "4823108376\n1842094049\n0123456789", "output":...
35d081a47dbf1cda2e4ae640e3a55169
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nJAG mock qualifying practice session\n\nThe ACM-ICPC OB / OG Association (Japanese Alumni Group; JAG) has N questions in stock of questions to be asked in the mock contest, and each question is numbered with an integer fr...
[{"input": "5 3\n1 1\n2 3\n3 2\n3 5\n2 1\n4 2\n1 7\n2 1\n1 3\n1 5\n6 1\n1 3\n1 2\n1 8\n1 2\n1 7\n1 6\n20 9\n4 10\n2 4\n5 3\n6 6\n6 3\n7 4\n8 10\n4 6\n7 5\n1 8\n5 7\n1 5\n6 6\n9 9\n5 8\n6 7\n1 4\n6 4\n7 10\n3 5\n19 6\n4 1\n6 5\n5 10\n1 10\n3 10\n4 6\n2 3\n5 4\n2 10\n1 8\n3 4\n3 1\n5 4\n1 10\n1 3\n5 6\n5 2\n1 10\n2 3\n0 ...
09d576391517f24aa980ce798b0921e2
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nYou are given a tree consisting exactly of n vertices. Tree is a connected undirected graph with n-1 edges. Each vertex v of this tree has a value a_v assigned to it.\n\nLet dist(x, y) be the distance between the vertices...
[{"input": "1\n1337\n", "output": "0\n", "type": "code"}, {"input": "8\n9 4 1 7 10 1 6 5\n1 2\n2 3\n1 4\n1 5\n5 6\n5 7\n5 8\n", "output": "121\n", "type": "code"}, {"input": "2\n12345 65432\n2 1\n", "output": "65432\n", "type": "code"}, {"input": "1\n617\n", "output": "0\n", "type": "code"}, {"input": "8\n9 4 1 7 10 1 ...
e8ea3d460112d7587e312f7f5ec5e667
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nOne Big Software Company has n employees numbered from 1 to n. The director is assigned number 1. Every employee of the company except the director has exactly one immediate superior. The director, of course, doesn't have...
[{"input": "7\n-1 3\n1 2\n1 1\n1 4\n4 5\n4 3\n5 2\n", "output": "17\n", "type": "code"}, {"input": "20\n-1 100\n1 35\n1 22\n1 28\n1 2\n1 8\n1 17\n1 50\n5 37\n1 25\n1 29\n5 21\n4 16\n2 39\n1 41\n3 28\n3 30\n2 36\n2 26\n14 17\n", "output": "548\n", "type": "code"}, {"input": "2\n-1 1\n1 2\n", "output": "2\n", "type": "co...
d956f5443248931b6fb8c70a3b4530e1
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nLittle Chris is a huge fan of linear algebra. This time he has been given a homework about the unusual square of a square matrix.\n\nThe dot product of two integer number vectors x and y of size n is the sum of the produc...
[{"input": "3\n1 1 1\n0 1 1\n1 0 0\n12\n3\n2 3\n3\n2 2\n2 2\n1 3\n3\n3\n1 2\n2 1\n1 1\n3\n", "output": "01001\n", "type": "code"}, {"input": "1\n0\n5\n1 1\n3\n1 1\n1 1\n3\n", "output": "11\n", "type": "code"}, {"input": "2\n1 0\n1 1\n6\n1 2\n3\n2 1\n3\n1 1\n3\n", "output": "101\n", "type": "code"}, {"input": "3\n0 0 0\...
7ea809c83aaa200bde6f17bc687af2a3
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nYou are given n rectangles, each of height 1. Each rectangle's width is a power of 2 (i. e. it can be represented as 2^x for some non-negative integer x). \n\nYou are also given a two-dimensional box of width W. Note that...
[{"input": "2\n5 16\n1 2 8 4 8\n6 10\n2 8 8 2 2 8\n", "output": "\n2\n3\n", "type": "code"}, {"input": "2\n5 13\n1 2 8 4 8\n6 10\n2 8 8 2 2 8\n", "output": "2\n3\n", "type": "code"}, {"input": "2\n5 13\n1 2 8 2 8\n6 10\n4 8 8 2 2 8\n", "output": "2\n4\n", "type": "code"}, {"input": "2\n5 12\n1 4 8 4 8\n6 10\n2 8 8 2 2 ...
a1eaf4a1204872c0b9b6496f64ddb985
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nXenia the beginner programmer has a sequence a, consisting of 2n non-negative integers: a1, a2, ..., a2n. Xenia is currently studying bit operations. To better understand how they work, Xenia decided to calculate some val...
[{"input": "2 4\n1 6 3 5\n1 4\n3 4\n1 2\n1 2\n", "output": "1\n3\n3\n3\n", "type": "code"}, {"input": "1 10\n6 26\n1 11\n1 9\n1 31\n1 10\n2 12\n1 8\n2 10\n2 4\n2 18\n1 31\n", "output": "27\n27\n31\n26\n14\n12\n10\n12\n26\n31\n", "type": "code"}, {"input": "1 10\n22 17\n2 15\n2 12\n1 6\n1 16\n2 24\n1 21\n2 19\n2 25\n2 1...
5a39f6bbc70c0fd2ea9d5250b0d6a1ea
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nKirill plays a new computer game. He came to the potion store where he can buy any potion. Each potion is characterized by two integers — amount of experience and cost. The efficiency of a potion is the ratio of the amoun...
[{"input": "1 10 1 10 1\n", "output": "YES\n", "type": "code"}, {"input": "1 5 6 10 1\n", "output": "NO\n", "type": "code"}, {"input": "71841 96625 73295 77648 8\n", "output": "NO\n", "type": "code"}, {"input": "17 19 2 3 8\n", "output": "NO\n", "type": "code"}, {"input": "1 100000 1 100000 100001\n", "output": "NO\n",...
dd7c1cf7e2e0482d09cdc5f17738739e
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nMonocarp and Polycarp are working as waiters in Berpizza, a pizzeria located near the center of Bertown. Since they are waiters, their job is to serve the customers, but they choose whom they serve first differently.\n\nA...
[{"input": "8\n1 8\n1 10\n1 6\n3\n2\n1 9\n2\n3\n", "output": "\n2 1 3 4 ", "type": "code"}, {"input": "8\n1 103913\n3\n1 103913\n1 103913\n3\n1 103913\n1 103913\n2\n", "output": "\n1 2 3 ", "type": "code"}, {"input": "6\n1 8\n1 10\n1 8\n3\n3\n3\n", "output": "\n2 1 3 ", "type": "code"}, {"input": "2\n1 500000\n3\n", "o...
3e2734c7820fc8b265b08790f23aac46
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nThe map of Bertown can be represented as a set of n intersections, numbered from 1 to n and connected by m one-way roads. It is possible to move along the roads from any intersection to any other intersection. The length ...
[{"input": "8 13\n8 7\n8 6\n7 5\n7 4\n6 5\n6 4\n5 3\n5 2\n4 3\n4 2\n3 1\n2 1\n1 8\n5\n8 7 5 2 1\n", "output": "0 3", "type": "code"}, {"input": "6 9\n1 5\n5 4\n1 2\n2 3\n3 4\n4 1\n2 6\n6 4\n4 2\n4\n1 2 3 4\n", "output": "1 2", "type": "code"}, {"input": "7 7\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 1\n7\n1 2 3 4 5 6 7\n", "out...
e2a8d425502703793981b83e1238c6af
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nJust to remind, girls in Arpa's land are really nice.\n\nMehrdad wants to invite some Hoses to the palace for a dancing party. Each Hos has some weight wi and some beauty bi. Also each Hos may have some friends. Hoses are...
[{"input": "3 1 5\n3 2 5\n2 4 2\n1 2\n", "output": "6\n", "type": "code"}, {"input": "4 2 11\n2 4 6 6\n6 4 2 1\n1 2\n2 3\n", "output": "7\n", "type": "code"}, {"input": "10 5 100\n78 89 3 2 95 96 87 11 13 60\n694709 921 799687 428614 221900 536251 117674 36488 219932 771513\n4 5\n3 4\n6 2\n2 3\n8 3\n", "output": "17911...
4c92be9f3db01e87f8ac3dd503a1224c
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nEmail address in Berland is a string of the form A@B, where A and B are arbitrary strings consisting of small Latin letters. \n\nBob is a system administrator in «Bersoft» company. He keeps a list of email addresses of th...
[{"input": "@aa@a\n", "output": "No solution\n", "type": "code"}, {"input": "a@aa@a\n", "output": "a@a,a@a\n", "type": "code"}, {"input": "a@a@a\n", "output": "No solution\n", "type": "code"}, {"input": "a@mc@ks@gu@rl@gq@zq@iz@da@uq@mi@nf@zs@hi@we@ej@ke@vb@az@yz@yl@rr@gh@um@nv@qe@qq@de@dy@op@gt@vx@ak@q\n", "output": "a...
8db98093fcb7bf01e455b2aa04f133e7
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nMaxim wants to buy some games at the local game shop. There are n games in the shop, the i-th game costs c_i.\n\nMaxim has a wallet which can be represented as an array of integers. His wallet contains m bills, the j-th b...
[{"input": "5 4\n2 4 5 2 4\n5 3 4 6\n", "output": "3\n", "type": "code"}, {"input": "5 2\n20 40 50 20 40\n19 20\n", "output": "0\n", "type": "code"}, {"input": "6 4\n4 8 15 16 23 42\n1000 1000 1000 1000\n", "output": "4\n", "type": "code"}, {"input": "5 1\n1 1 1 1 1\n5\n", "output": "1\n", "type": "code"}, {"input": "1...
847e34c2daf84912f0e799c82879d108
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nA permutation is a sequence of integers from 1 to n of length n containing each number exactly once. For example, [1], [4, 3, 5, 1, 2], [3, 2, 1] — are permutations, and [1, 1], [4, 3, 1], [2, 3, 4] — no.\n\nPermutation a...
[{"input": "4 4\n1 2 4\n2 3\n1 1 2\n1 3 4\n", "output": "9\n4\n6\n", "type": "code"}, {"input": "2 3\n1 1 2\n2 1\n1 2 2\n", "output": "3\n1\n", "type": "code"}, {"input": "2 3\n1 2 2\n2 1\n1 2 2\n", "output": "2\n1\n", "type": "code"}, {"input": "2 3\n1 2 2\n2 1\n1 2 1\n", "output": "2\n0\n", "type": "code"}, {"input":...
30333ca64f743b7b48b5d769c3af184f
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nThe first algorithm for detecting a face on the image working in realtime was developed by Paul Viola and Michael Jones in 2001. A part of the algorithm is a procedure that computes Haar features. As part of this task, we...
[{"input": "3 3\nWBW\nBWW\nWWW\n", "output": "4\n", "type": "code"}, {"input": "3 6\nWWBBWW\nWWBBWW\nWWBBWW\n", "output": "3\n", "type": "code"}, {"input": "6 8\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW\n", "output": "2\n", "type": "code"}, {"input": "4 4\nBBBB\nBBBB\nBBBB\nBBBW\n", "output": "4\n", "...
0043fb1eda8923ae5dae10cf7b3bbcdd
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nYou are given a rooted tree with root in vertex 1. Each vertex is coloured in some colour.\n\nLet's call colour c dominating in the subtree of vertex v if there are no other colours that appear in the subtree of vertex v ...
[{"input": "4\n1 2 3 4\n1 2\n2 3\n2 4\n", "output": "10 9 3 4 \n", "type": "code"}, {"input": "15\n1 2 3 1 2 3 3 1 1 3 2 2 1 2 3\n1 2\n1 3\n1 4\n1 14\n1 15\n2 5\n2 6\n2 7\n3 8\n3 9\n3 10\n4 11\n4 12\n4 13\n", "output": "6 5 4 3 2 3 3 1 1 3 2 2 1 2 3 \n", "type": "code"}, {"input": "4\n1 2 3 4\n1 2\n2 3\n1 4\n", "output...
2f9129e4cda1abb7591d0e6d2a8b93a7
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nIn BerSoft n programmers work, the programmer i is characterized by a skill r_i.\n\nA programmer a can be a mentor of a programmer b if and only if the skill of the programmer a is strictly greater than the skill of the p...
[{"input": "10 4\n5 4 1 5 4 3 7 1 2 5\n4 6\n2 1\n10 8\n3 5\n", "output": "5 4 0 5 3 3 9 0 2 5 ", "type": "code"}, {"input": "4 2\n10 4 10 15\n1 2\n4 3\n", "output": "0 0 1 2 ", "type": "code"}, {"input": "2 0\n3 1\n", "output": "1 0 ", "type": "code"}, {"input": "10 35\n322022227 751269818 629795150 369443545 344607287...
e8215e61c6bd490dfd704efb39abfd99
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nYou are given an integer sequence a_1, a_2, ..., a_n.\n\nFind the number of pairs of indices (l, r) (1 ≤ l ≤ r ≤ n) such that the value of median of a_l, a_{l+1}, ..., a_r is exactly the given number m.\n\nThe median of a...
[{"input": "15 2\n1 2 3 1 2 3 1 2 3 1 2 3 1 2 3\n", "output": "97\n", "type": "code"}, {"input": "5 4\n1 4 5 60 4\n", "output": "8\n", "type": "code"}, {"input": "3 1\n1 1 1\n", "output": "6\n", "type": "code"}, {"input": "1 200000\n1\n", "output": "0\n", "type": "code"}, {"input": "2 2\n1 1\n", "output": "0\n", "type"...
6bbaf2b2587ac52d656673934dd0ecb1
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nParsa has a humongous tree on n vertices.\n\nOn each vertex v he has written two integers l_v and r_v.\n\nTo make Parsa's tree look even more majestic, Nima wants to assign a number a_v (l_v ≤ a_v ≤ r_v) to each vertex v ...
[{"input": "3\n2\n1 6\n3 8\n1 2\n3\n1 3\n4 6\n7 9\n1 2\n2 3\n6\n3 14\n12 20\n12 19\n2 12\n10 17\n3 17\n3 2\n6 5\n1 5\n2 6\n4 6\n", "output": "\n7\n8\n62\n", "type": "code"}, {"input": "3\n2\n1 6\n3 8\n1 2\n3\n1 3\n4 6\n7 9\n1 2\n2 3\n6\n4 14\n12 20\n12 19\n2 12\n10 17\n3 17\n3 2\n6 5\n1 5\n2 6\n4 6\n", "output": "7\n8\...
b6ebc7ac3de8bde7c30214505bb9570c
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nYou are given an undirected graph consisting of n vertices and n edges. It is guaranteed that the given graph is connected (i. e. it is possible to reach any vertex from any other vertex) and there are no self-loops and m...
[{"input": "3\n3\n1 2\n2 3\n1 3\n4\n1 2\n2 3\n3 4\n4 2\n5\n1 2\n2 3\n1 3\n2 5\n4 3\n", "output": "\n6\n11\n18\n", "type": "code"}, {"input": "3\n3\n1 2\n2 3\n1 3\n4\n1 4\n2 3\n3 4\n4 2\n5\n1 2\n2 3\n1 3\n2 5\n4 3\n", "output": "6\n11\n18\n", "type": "code"}, {"input": "3\n3\n1 2\n2 3\n1 3\n4\n1 2\n1 3\n3 4\n4 2\n5\n1 2...
05d74d13ff5eb30ab4d4762f2a864bfc
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nConsider some square matrix A with side n consisting of zeros and ones. There are n rows numbered from 1 to n from top to bottom and n columns numbered from 1 to n from left to right in this matrix. We'll denote the eleme...
[{"input": "4\n", "output": "3", "type": "code"}, {"input": "9\n", "output": "5", "type": "code"}, {"input": "61\n", "output": "11", "type": "code"}, {"input": "13\n", "output": "5", "type": "code"}, {"input": "38\n", "output": "9", "type": "code"}, {"input": "98\n", "output": "15", "type": "code"}, {"input": "84\n", "...
77c3ad0158530161e5f846a9f0967eb3
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nThe construction of subway in Bertown is almost finished! The President of Berland will visit this city soon to look at the new subway himself.\n\nThere are n stations in the subway. It was built according to the Bertown ...
[{"input": "3\n2 1 3\n", "output": "9", "type": "code"}, {"input": "5\n1 5 4 3 2\n", "output": "17", "type": "code"}, {"input": "10\n5 1 6 2 8 3 4 10 9 7\n", "output": "82", "type": "code"}, {"input": "3\n1 2 3\n", "output": "5", "type": "code"}, {"input": "20\n1 6 15 9 18 17 7 8 3 19 2 13 11 12 14 4 5 20 16 10\n", "ou...
00a73f99096e4cd6f0e0caece8843bed
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nYour friend recently came up with a card game called UT-Rummy.\n\nThe cards used in this game are numbered red, green, or blue and any number from 1 to 9. Each player in this game has 9 cards in his or her hand, chooses o...
[{"input": "5\n1 2 3 3 4 5 7 7 7\nR R R R R R G G G\n1 2 2 3 4 4 4 4 5\nR R R R R R R R R\n1 2 3 4 4 4 5 5 5\nR R B R R R R R R\n1 1 1 3 4 5 6 6 6\nR R B G G G R R R\n2 2 2 3 3 3 1 1 1\nR G B R G B R G B", "output": "1\n0\n0\n0\n1", "type": "code"}, {"input": "5\n1 2 3 3 4 5 7 7 7\nR R R R R R G G G\n1 2 2 3 4 4 4 4 5\...
c67111d5ed33855ef85b5f463c7cb19e
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nAfter a wonderful evening in the restaurant the time to go home came. Leha as a true gentlemen suggested Noora to give her a lift. Certainly the girl agreed with pleasure. Suddenly one problem appeared: Leha cannot find h...
[{"input": "4\n1 1 1 1 1\n3 2 5 4 5\n1 1 5 5 10000\n1 4 2 5 2\n", "output": "1\n13\n93\n0\n", "type": "code"}, {"input": "10\n1 1 1000000000 1000000000 1477070720\n1 1 1000000000 1000000000 1378704784\n1 1 1000000000 1000000000 782520772\n1 1 1000000000 1000000000 1377211731\n1 1 1000000000 1000000000 623332716\n1 1 10...
ae76e18b5a98f545a71254ac699ae060
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nThe \"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...
[{"input": "5 5\n1 2\n2 2 3\n2 3 4\n2 4 5\n1 5\n", "output": "0\n", "type": "code"}, {"input": "2 2\n1 2\n0\n", "output": "1\n", "type": "code"}, {"input": "8 7\n0\n3 1 2 3\n1 1\n2 5 4\n2 6 7\n1 3\n2 7 4\n1 1\n", "output": "2\n", "type": "code"}, {"input": "10 10\n5 7 5 2 8 1\n7 10 6 9 5 8 2 4\n2 2 7\n5 8 6 9 10 1\n2 9...
80fbac80d207735c0d2b450dfbd174d8
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nVladik had started reading a complicated book about algorithms containing n pages. To improve understanding of what is written, his friends advised him to read pages in some order given by permutation P = [p1, p2, ..., pn...
[{"input": "6 5\n1 4 3 2 5 6\n2 4 3\n1 6 2\n4 5 4\n1 3 3\n2 6 3\n", "output": "Yes\nNo\nYes\nNo\nYes\n", "type": "code"}, {"input": "5 5\n5 4 3 2 1\n1 5 3\n1 3 1\n2 4 3\n4 4 4\n2 5 3\n", "output": "Yes\nNo\nYes\nYes\nNo\n", "type": "code"}, {"input": "10 10\n10 1 6 7 9 8 4 3 5 2\n1 1 1\n4 4 4\n7 7 7\n3 3 3\n1 6 5\n2 6 ...
89dbefb3756689056e78725f219a9f15
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nOne day Jeff got hold of an integer sequence a1, a2, ..., an of length n. The boy immediately decided to analyze the sequence. For that, he needs to find all values of x, for which these conditions hold:\n\n * x occurs i...
[{"input": "8\n1 2 1 3 1 2 1 5\n", "output": "4\n1 2\n2 4\n3 0\n5 0\n", "type": "code"}, {"input": "1\n2\n", "output": "1\n2 0\n", "type": "code"}, {"input": "9\n2 3 3 3 2 1 2 3 2\n", "output": "1\n1 0\n", "type": "code"}, {"input": "10\n3 1 1 1 1 3 1 2 2 1\n", "output": "2\n2 1\n3 5\n", "type": "code"}, {"input": "4\n...
a0328b2762c0705ed8442d15743f0a51
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nOmkar is standing at the foot of Celeste mountain. The summit is n meters away from him, and he can see all of the mountains up to the summit, so for all 1 ≤ j ≤ n he knows that the height of the mountain at the point j m...
[{"input": "4\n2 6 7 8\n", "output": "5 5 6 7 ", "type": "code"}, {"input": "1\n0\n", "output": "0 ", "type": "code"}, {"input": "100\n75 78 155 169 264 333 369 416 439 486 503 541 557 635 726 745 814 845 899 914 943 1016 1090 1132 1191 1199 1258 1323 1423 1491 1557 1562 1583 1663 1707 1711 1729 1767 1819 1894 1916 192...
97e51c2256dde4a6741f9a09907eec7e
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nSince I got tired to write long problem statements, I decided to make this problem statement short. For given positive integer L, how many pairs of positive integers a, b (a ≤ b) such that LCM(a, b) = L are there? Here, L...
[{"input": "12\n9\n2\n0", "output": "8\n3\n2", "type": "code"}, {"input": "12\n11\n2\n0", "output": "8\n2\n2\n", "type": "code"}, {"input": "12\n9\n3\n0", "output": "8\n3\n2\n", "type": "code"}, {"input": "12\n8\n2\n0", "output": "8\n4\n2\n", "type": "code"}, {"input": "12\n9\n0\n0", "output": "8\n3\n", "type": "code"}...
a1d986ba4863dfb46f7f173a4a764715
code_stdio
[ { "content": "Solve the following coding problem using the programming language python:\n\nLittle girl Margarita is a big fan of competitive programming. She especially loves problems about arrays and queries on them.\n\nRecently, she was presented with an array a of the size of 10^9 elements that is filled as ...
[{"input": "5\n1 3\n2 5\n5 5\n4 4\n2 3\n", "output": "-2\n-2\n-5\n4\n-1\n", "type": "code"}, {"input": "1\n200000000 1000000000\n", "output": "600000000\n", "type": "code"}, {"input": "6\n617758920 825919887\n775957146 950878973\n404173573 553845184\n25837072 795166931\n756434592 838258528\n590139756 977664562\n", "out...
5c0aa31e4aa58e5ec2e5789b0550ab99
code_stdio