problem
stringlengths
14
4.09k
solution
stringlengths
1
802k
task_type
stringclasses
3 values
problem_tokens
int64
5
895
Solve the programming task below in a Python markdown code block. Chef is an advocate for Go Green Initiative. Today he had n trees planted in a row outside his his restaurant. Today, the height of i-th tree is hi feet. The trees grow at a rate of mi feet per day. Chef knows that trees will look beautiful if they form ...
{"inputs": ["3\n3\n0 1\n2 2\n0 3\n2\n2 1\n1 2\n3\n1 1\n2 2\n3 3"], "outputs": ["1\n0 1\n2\n0 0\n2 Inf\n0"]}
coding
574
Solve the programming task below in a Python markdown code block. 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. Alice often has a serious pr...
{"inputs": ["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", "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", "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...
coding
502
Solve the programming task below in a Python markdown code block. Mr. Chef is the manager of the Code cinemas and after a long break, the theatres are now open to the public again. To compensate for the loss in revenue due to Covid-19, Mr. Chef wants to maximize the profits for every show from now on and at the same ti...
{"inputs": ["3\n1 5\n3 3\n4 4"], "outputs": ["3\n4\n4"]}
coding
484
Solve the programming task below in a Python markdown code block. There are n cities in Berland and some pairs of them are connected by two-way roads. It is guaranteed that you can pass from any city to any other, moving along the roads. Cities are numerated from 1 to n. Two fairs are currently taking place in Berland...
{"inputs": ["3\n7 7 3 5\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 5\n4 5 2 4\n1 2\n2 3\n3 4\n4 1\n4 2\n4 3 2 1\n1 2\n2 3\n4 1\n", "3\n7 7 3 5\n1 2\n2 3\n3 4\n2 5\n5 6\n6 7\n7 5\n4 5 2 4\n1 2\n2 3\n3 4\n4 1\n4 2\n4 3 2 1\n1 2\n2 3\n4 1\n", "3\n7 7 3 5\n1 2\n2 3\n1 4\n2 5\n5 6\n6 7\n7 5\n4 5 2 4\n1 2\n2 3\n3 4\n4 1\n4 2\n4 3 2 1\...
coding
611
Solve the programming task below in a Python markdown code block. Find sum of all the numbers that are multiples of 10 and are less than or equal to a given number "N". (quotes for clarity and be careful of integer overflow) -----Input----- Input will start with an integer T the count of test cases, each case will hav...
{"inputs": ["1\n10"], "outputs": ["10"]}
coding
160
Solve the programming task below in a Python markdown code block. You are given three strings A, B and C. Each of these is a string of length N consisting of lowercase English letters. Our objective is to make all these three strings equal. For that, you can repeatedly perform the following operation: * Operation: Ch...
{"inputs": ["4\nwest\neast\nw`it", "4\nwesu\neast\nw`it", "4\nwetu\neast\nw`it", "4\nwetv\n`est\ntiaw", "4\ntewv\n`ftt\nsaiw", "4\nwetu\ne`st\nw`it", "4\nwetu\n`est\nw`it", "4\nwetu\n`est\nwait"], "outputs": ["4\n", "5\n", "6\n", "7\n", "8\n", "5\n", "5\n", "5\n"]}
coding
252
Solve the programming task below in a Python markdown code block. You are given N points on a plane. Write a program which will find the sum of squares of distances between all pairs of points. Input The first line of input contains one integer number N (1 ≤ N ≤ 100 000) — the number of points. Each of the following ...
{"inputs": ["1\n6 3\n", "1\n7 3\n", "1\n9 3\n", "1\n9 4\n", "1\n6 4\n", "1\n6 2\n", "1\n6 0\n", "1\n8 1\n"], "outputs": ["0", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]}
coding
170
Solve the programming task below in a Python markdown code block. The new operating system BerOS has a nice feature. It is possible to use any number of characters '/' as a delimiter in path instead of one traditional '/'. For example, strings //usr///local//nginx/sbin// and /usr/local/nginx///sbin are equivalent. The ...
{"inputs": ["/\n", "////\n", "/a/b/c\n", "/b/b/c\n", "/c/b/c\n", "/aa//b/aa\n", "/a//aa/a//\n", "////a//b/////g\n"], "outputs": ["/\n", "/\n", "/a/b/c\n", "/b/b/c\n", "/c/b/c\n", "/aa/b/aa\n", "/a/aa/a\n", "/a/b/g\n"]}
coding
214
Solve the programming task below in a Python markdown code block. Once, a genius guy Cristo visited NASA where he met many scientists. A young intern Mark at NASA asked Cristo to observe the strange behaviour of two independent particles (say Alpha and Beta) moving in the free space.Cristo was astonished to see the mo...
{"inputs": ["2\n1\n2"], "outputs": ["0 1\n2 1"]}
coding
379
Solve the programming task below in a Python markdown code block. 10^{10^{10}} participants, including Takahashi, competed in two programming contests. In each contest, all participants had distinct ranks from first through 10^{10^{10}}-th. The score of a participant is the product of his/her ranks in the two contests...
{"inputs": ["8\n2 4\n1 5\n3 6\n6 11\n8 9\n9 3\n7 36\n314159265 541984339", "8\n1 4\n10 8\n4 3\n4 8\n8 7\n22 6\n7 36\n314159265 96636036", "8\n2 4\n6 9\n3 1\n5 11\n4 9\n16 1\n6 57\n314159265 75457060", "8\n1 4\n10 5\n3 3\n4 11\n8 9\n1 3\n8 36\n314159265 358979323", "8\n1 4\n10 5\n3 3\n4 11\n8 9\n22 3\n7 36\n314159265 96...
coding
336
Solve the programming task below in a Python markdown code block. Short Phrase A Short Phrase (aka. Tanku) is a fixed verse, inspired by Japanese poetry Tanka and Haiku. It is a sequence of words, each consisting of lowercase letters 'a' to 'z', and must satisfy the following condition: > (The Condition for a Short P...
{"inputs": ["9\ndo\nhet\nbest\n`nd\nenjoy\ntoday\nat\nacm\nicpc\n0\noh\nyes\nby\nfar\nit\nis\nwow\nso\nbda\nto\nmd\nyou\nknow\nhey\n15\nedcba\nfghijkl\nmnopq\nrstuvwx\nyzz\nabcde\nlkkihgf\nmnopq\nxwvutsr\nyz\nabcde\nfghijkl\nmnopq\nrstuvwx\nyz\n0", "9\ndo\nhet\nbest\n`nd\nenjoy\ntoday\nat\nacm\nicpc\n0\noh\nyes\nby\nfa...
coding
729
Please solve the programming task below using a self-contained code snippet in a markdown code block. There are n buildings in a line. You are given an integer array heights of size n that represents the heights of the buildings in the line. The ocean is to the right of the buildings. A building has an ocean view if t...
{"functional": "def check(candidate):\n assert candidate(heights = [4,2,3,1]) == [0,2,3]\n assert candidate(heights = [4,3,2,1]) == [0,1,2,3]\n assert candidate(heights = [1,3,2,4]) == [3]\n assert candidate(heights = [2,2,2,2]) == [3]\n\n\ncheck(Solution().findBuildings)"}
coding
150
Solve the programming task below in a Python markdown code block. You are given an integer $n$. A set, $\mbox{S}$, of triples $(x_i,y_i,z_i)$ is beautiful if and only if: $0\leq x_i,y_i,z_i$ $x_i+y_i+z_i=n,\forall i:1\leq i\leq|S|$ Let $\mbox{X}$ be the set of different $x_i$'s in $\mbox{S}$, $\mathbf{Y}$ be the set o...
{"inputs": ["3\n"], "outputs": ["3\n0 1 2\n2 0 1\n1 2 0\n"]}
coding
600
Solve the programming task below in a Python markdown code block. Read problems statements [Mandarin] , [Bengali] , [Hindi] , [Russian] and [Vietnamese] as well. Chef's brother Chefu is a competitive programmer. Every day, he practices for ICPC (International Chefs' Programming Contest) by solving problems. Today, Che...
{"inputs": ["2\n8 3\n1 2 2 1 3 3 2 1\n5 3\n1 1 2 2 3"], "outputs": ["3\n-1"]}
coding
541
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a 0-indexed integer array nums and a positive integer x. You are initially at position 0 in the array and you can visit other positions according to the following rules: If you are currently in position...
{"functional": "def check(candidate):\n assert candidate(nums = [2,3,6,1,9,2], x = 5) == 13\n assert candidate(nums = [2,4,6,8], x = 3) == 20\n\n\ncheck(Solution().maxScore)"}
coding
182
Solve the programming task below in a Python markdown code block. Bob wants to put a new bargaining table in his office. To do so he measured the office room thoroughly and drew its plan: Bob's office room is a rectangular room n × m meters. Each square meter of the room is either occupied by some furniture, or free. A...
{"inputs": ["1 1\n0\n", "3 3\n000\n110\n000\n", "4 2\n00\n10\n11\n00\n", "3 3\n000\n010\n010\n", "3 3\n000\n010\n011\n", "3 3\n100\n010\n011\n", "3 3\n101\n010\n011\n", "3 3\n000\n010\n000\n"], "outputs": ["4", "8", "6", "8\n", "8\n", "6\n", "6\n", "8"]}
coding
317
Solve the programming task below in a Python markdown code block. There was a power value associated with each soldier of Ram’s troop. It was a known belief that if two soldiers could be paired such that their total power can be divided by 3 perfectly, the pairing becomes ultra-powerful. Ram was curious as to see how m...
{"inputs": ["5\n3\n1 2 3\n9\n2 3 4 5 11 3 5 6 4\n1\n2\n2 \n7 2\n3 \n9 9 9"], "outputs": ["1\n11\n0\n1\n3"]}
coding
313
Solve the programming task below in a Python markdown code block. You are standing at point $(0,0)$ on an infinite plane. In one step, you can move from some point $(x_f,y_f)$ to any point $(x_t,y_t)$ as long as the Euclidean distance, $\sqrt{(x_f-x_t)^2+(y_f-y_t)^2}$, between the two points is either $\boldsymbol{a}$ ...
{"inputs": ["3\n2 3 1\n1 2 0\n3 4 11\n"], "outputs": ["2\n0\n3\n"]}
coding
602
Solve the programming task below in a Python markdown code block. A `bouncy number` is a positive integer whose digits neither increase nor decrease. For example, 1235 is an increasing number, 5321 is a decreasing number, and 2351 is a bouncy number. By definition, all numbers under 100 are non-bouncy, and 101 is the f...
{"functional": "_inputs = [[0], [1], [2], [3], [4], [5], [6], [10], [20], [50]]\n_outputs = [[0], [0], [0], [525], [8325], [95046], [987048], [9999722967], [99999999999959940181], [99999999999999999999999999999999999999912040301674]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance...
coding
284
Solve the programming task below in a Python markdown code block. There are $n$ districts in the town, the $i$-th district belongs to the $a_i$-th bandit gang. Initially, no districts are connected to each other. You are the mayor of the city and want to build $n-1$ two-way roads to connect all districts (two district...
{"inputs": ["1\n2\n7 7\n", "1\n2\n7 7\n", "1\n2\n3 7\n", "1\n2\n0 7\n", "1\n2\n11 7\n", "1\n2\n0 13\n", "1\n2\n1 13\n", "1\n2\n1 21\n"], "outputs": ["NO\n", "NO\n", "YES\n1 2\n", "YES\n1 2\n", "YES\n1 2\n", "YES\n1 2\n", "YES\n1 2\n", "YES\n1 2\n"]}
coding
621
Solve the programming task below in a Python markdown code block. The Cybermen solved that first test much quicker than the Daleks. Luckily for us, the Daleks were angry (shocking!) and they destroyed some of the Cybermen. After the fighting stopped, Heidi gave them another task to waste their time on. There are $n$ ...
{"inputs": ["5 1\n1 1\n1 -2\n0 1\n0 0\n2 0\n", "5 1\n1 1\n1 -2\n0 1\n0 1\n2 0\n", "5 1\n1 1\n1 -2\n0 1\n1 1\n2 0\n", "5 1\n0 1\n1 -2\n0 1\n1 1\n2 0\n", "5 1\n0 2\n1 -2\n0 1\n1 1\n2 0\n", "5 1\n1 1\n1 -2\n0 1\n-1 0\n2 0\n", "1 1000000\n1000000 -419484\n", "5 1\n1 1\n2 -2\n0 1\n-1 0\n2 0\n"], "outputs": ["3\n", "3\n", "3...
coding
513
Solve the programming task below in a Python markdown code block. The only difference between easy and hard versions is the number of elements in the array. You are given an array $a$ consisting of $n$ integers. In one move you can choose any $a_i$ and divide it by $2$ rounding down (in other words, in one move you ca...
{"inputs": ["1 1\n1337\n", "1 1\n1337\n", "5 3\n1 2 2 4 5\n", "5 3\n1 2 3 4 5\n", "5 3\n1 2 3 3 3\n", "5 3\n1 2 4 4 5\n", "5 3\n1 2 1 4 5\n", "5 3\n1 3 3 3 3\n"], "outputs": ["0\n", "0\n", "1\n", "2\n", "0\n", "2\n", "1\n", "0\n"]}
coding
376
Solve the programming task below in a Python markdown code block. A boy Valera registered on site Codeforces as Valera, and wrote his first Codeforces Round #300. He boasted to a friend Arkady about winning as much as x points for his first contest. But Arkady did not believe his friend's words and decided to check whe...
{"inputs": ["1 2 1 2 1 2\n", "0 3 5 6 1 2\n", "7 2 27 4 9 1\n", "7 2 27 5 9 1\n", "46 7 18 6 3 1\n", "0 7 30 50 3 4\n", "6 2 11 1 11 1\n", "2 5 29 36 5 6\n"], "outputs": ["YES\n", "YES\n", "NO\n", "NO\n", "NO\n", "YES\n", "NO\n", "NO\n"]}
coding
601
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a 0-indexed string blocks of length n, where blocks[i] is either 'W' or 'B', representing the color of the ith block. The characters 'W' and 'B' denote the colors white and black, respectively. You are a...
{"functional": "def check(candidate):\n assert candidate(blocks = \"WBBWWBBWBW\", k = 7) == 3\n assert candidate(blocks = \"WBWBBBW\", k = 2) == 0\n\n\ncheck(Solution().minimumRecolors)"}
coding
163
Solve the programming task below in a Python markdown code block. After seeing the "ALL YOUR BASE ARE BELONG TO US" meme for the first time, numbers X and Y realised that they have different bases, which complicated their relations. You're given a number X represented in base b_{x} and a number Y represented in base b...
{"inputs": ["1 3\n1\n1 2\n1\n", "1 3\n1\n1 2\n1\n", "1 2\n1\n1 40\n1\n", "1 9\n2\n1 10\n2\n", "1 2\n1\n1 40\n1\n", "1 9\n2\n1 10\n2\n", "1 8\n2\n1 10\n2\n", "2 2\n1 0\n1 3\n1\n"], "outputs": ["=\n", "=", "=\n", "=\n", "=", "=", "=\n", ">\n"]}
coding
602
Solve the programming task below in a Python markdown code block. A and B are preparing themselves for programming contests. After several years of doing sports programming and solving many problems that require calculating all sorts of abstract objects, A and B also developed rather peculiar tastes. A likes lowercas...
{"inputs": ["1 1 -1 1 1 1 1 1 1 1 1 1 1 1 1 7 1 1 1 8 1 1 1 1 1 1\na\n", "1 1 -1 1 1 1 1 1 1 1 1 1 1 1 1 7 1 1 1 8 1 1 1 1 1 1\na\n", "1 1 -1 1 1 1 1 1 1 1 1 1 1 1 1 7 1 1 1 8 1 1 1 0 1 1\na\n", "1 1 -1 1 1 1 1 1 1 1 2 1 1 1 1 7 1 1 1 8 1 1 1 0 1 1\na\n", "1 1 -1 1 1 1 1 1 1 1 1 1 1 1 1 7 1 1 1 8 1 1 1 1 1 1\nbb\n", "1...
coding
490
Solve the programming task below in a Python markdown code block. An `non decreasing` number is one containing no two consecutive digits (left to right), whose the first is higer than the second. For example, 1235 is an non decreasing number, 1229 is too, but 123429 isn't. Write a function that finds the number of non...
{"functional": "_inputs = [[0], [1], [2], [3], [4], [5], [6], [10], [20], [50]]\n_outputs = [[1], [10], [55], [220], [715], [2002], [5005], [92378], [10015005], [12565671261]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol...
coding
167
Solve the programming task below in a Python markdown code block. ```if:python Create a function `args_count`, that returns the count of passed arguments ``` ```if:kotlin Create a function `argsCount`, that returns the count of passed arguments ``` ```if:ruby Create a method `args_count`, that returns the count of pass...
{"functional": "_inputs = [[100], [100, 2, 3]]\n_outputs = [[1], [3]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) != len(b): return False\n r...
coding
165
Solve the programming task below in a Python markdown code block. A string $s$ of length $n$ can be encrypted by the following algorithm: iterate over all divisors of $n$ in decreasing order (i.e. from $n$ to $1$), for each divisor $d$, reverse the substring $s[1 \dots d]$ (i.e. the substring which starts at position...
{"inputs": ["1\nz\n", "1\ny\n", "1\nx\n", "1\n{\n", "1\n|\n", "1\nz\n", "2\nir\n", "2\nir\n"], "outputs": ["z\n", "y\n", "x\n", "{\n", "|\n", "z\n", "ri\n", "ri\n"]}
coding
384
Solve the programming task below in a Python markdown code block. The itertools module standardizes a core set of fast, memory efficient tools that are useful by themselves or in combination. Together, they form an iterator algebra making it possible to construct specialized tools succinctly and efficiently in pure Pyt...
{"inputs": ["4 \na a c d\n2\n"], "outputs": ["0.8333\n"]}
coding
477
Solve the programming task below in a Python markdown code block. Given a string, turn each letter into its ASCII character code and join them together to create a number - let's call this number `total1`: ``` 'ABC' --> 'A' = 65, 'B' = 66, 'C' = 67 --> 656667 ``` Then replace any incidence of the number `7` with the ...
{"functional": "_inputs = [['abcdef'], ['ifkhchlhfd'], ['aaaaaddddr'], ['jfmgklf8hglbe'], ['jaam'], ['abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ']]\n_outputs = [[6], [6], [30], [6], [12], [96]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return ma...
coding
227
Solve the programming task below in a Python markdown code block. You are given <var>Q</var> tuples of integers <var>(L_i, A_i, B_i, M_i)</var>. For each tuple, answer the following question. There is an arithmetic progression with L terms: s_0, s_1, s_2, ... , s_{L-1}. The initial term is A, and the common difference...
{"inputs": ["5 5 4 10007", "2 5 4 10007", "2 1 4 10007", "5 3 4 10007", "5 3 4 10007\n", "6 8 1 1000000", "4 8 1 1001000", "3 8 1 1001000"], "outputs": ["358\n", "59\n", "15\n", "5563", "5563\n", "111213\n", "891011\n", "8910\n"]}
coding
354
Solve the programming task below in a Python markdown code block. Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. Chef has a tree with $N$ nodes (numbered $1$ through $N$) and a non-negative integer $x$. The nodes of the tree have non-negative integer weights; le...
{"inputs": ["7 1\n1 0 1 0 1 0 1 \n1 2\n1 3\n2 4\n2 5\n3 6\n3 7"], "outputs": ["5"]}
coding
694
Solve the programming task below in a Python markdown code block. You have an array A of size N containing only positive numbers. You have to output the maximum possible value of A[i]%A[j] where 1<=i,j<=N. -----Input----- The first line of each test case contains a single integer N denoting the size of the array. The...
{"inputs": ["2\n1\n2"], "outputs": ["1"]}
coding
272
Solve the programming task below in a Python markdown code block. The Bubble Cup hypothesis stood unsolved for $130$ years. Who ever proves the hypothesis will be regarded as one of the greatest mathematicians of our time! A famous mathematician Jerry Mao managed to reduce the hypothesis to this problem: Given a numbe...
{"inputs": ["1\n9\n", "1\n9\n", "1\n3\n", "1\n17\n", "1\n29\n", "1\n50\n", "1\n15\n", "1\n21\n"], "outputs": ["9\n", "9\n", "2\n", "25\n", "64\n", "182\n", "20\n", "36\n"]}
coding
337
Solve the programming task below in a Python markdown code block. Truncate the given string (first argument) if it is longer than the given maximum length (second argument). Return the truncated string with a `"..."` ending. Note that inserting the three dots to the end will add to the string length. However, if the ...
{"functional": "_inputs = [['pippi', 3], ['Peter Piper picked a peck of pickled peppers', 14], ['A-tisket a-tasket A green and yellow basket', 43], ['A-tisket a-tasket A green and yellow basket', 45], ['A-', 1], ['Chingel loves his Angel so much!!!', 27], ['I like ice-cream.Do you?', 19], ['Seems like you have passed t...
coding
193
Solve the programming task below in a Python markdown code block. You are given $n$ lengths of segments that need to be placed on an infinite axis with coordinates. The first segment is placed on the axis so that one of its endpoints lies at the point with coordinate $0$. Let's call this endpoint the "start" of the fi...
{"inputs": ["6\n2\n1 3\n3\n1 2 3\n4\n6 2 3 9\n4\n6 8 4 5\n7\n1 2 4 6 7 7 3\n8\n8 6 5 1 2 2 3 6\n", "6\n2\n1 3\n3\n1 2 3\n4\n2 2 3 9\n4\n6 8 4 5\n7\n1 2 4 6 7 7 3\n8\n8 6 5 1 2 2 3 6\n", "6\n2\n1 3\n3\n1 2 6\n4\n6 2 3 9\n4\n6 8 4 5\n7\n1 2 4 6 7 7 3\n8\n8 6 5 1 2 2 3 6\n", "6\n2\n1 3\n3\n1 2 3\n4\n2 2 3 9\n4\n6 8 4 5\n7...
coding
702
Solve the programming task below in a Python markdown code block. A [Mersenne prime](https://en.wikipedia.org/wiki/Mersenne_prime) is a prime number that can be represented as: Mn = 2^(n) - 1. Therefore, every Mersenne prime is one less than a power of two. Write a function that will return whether the given integer ...
{"functional": "_inputs = [[2], [3], [5], [7], [11], [13], [17], [19], [21], [23], [31], [49], [61], [89], [107], [127], [221], [521], [607], [1279]]\n_outputs = [[True], [True], [True], [True], [False], [True], [True], [True], [False], [False], [True], [False], [True], [True], [True], [True], [False], [True], [True], ...
coding
130
Solve the programming task below in a Python markdown code block. You are given three sticks with positive integer lengths of a, b, and c centimeters. You can increase length of some of them by some positive integer number of centimeters (different sticks can be increased by a different length), but in total by at most...
{"inputs": ["1 2 1 5\n", "2 7 8 4\n", "2 5 8 4\n", "2 2 3 1\n", "1 1 1 2\n", "1 2 3 1\n", "4 2 5 28\n", "3 1 29 1\n"], "outputs": ["20\n", "25\n", "16\n", "3\n", "4\n", "2\n", "1893\n", "0\n"]}
coding
338
Solve the programming task below in a Python markdown code block. Two integers A and B are the inputs. Write a program to find GCD and LCM of A and B. -----Input----- The first line contains an integer T, total number of testcases. Then follow T lines, each line contains an integer A and B. -----Output----- Display...
{"inputs": ["3\n120 140\n10213 312\n10 30"], "outputs": ["20 840\n1 3186456\n10 30"]}
coding
188
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an array of n integers nums and an integer target, find the number of index triplets i, j, k with 0 <= i < j < k < n that satisfy the condition nums[i] + nums[j] + nums[k] < target.   Please complete the followi...
{"functional": "def check(candidate):\n assert candidate(nums = [-2,0,1,3], target = 2) == 2\n assert candidate(nums = [], target = 0) == 0\n assert candidate(nums = [0], target = 0) == 0\n\n\ncheck(Solution().threeSumSmaller)"}
coding
108
Solve the programming task below in a Python markdown code block. A key feature of the Siruseri railway network is that it has exactly one route between any pair of stations. The government has chosen three contractors to run the canteens at the stations on the railway network. To ensure that there are no disputes betw...
{"inputs": ["6\n10\n20\n25\n40\n30\n30\n4 5\n1 3\n3 4\n2 3\n6 4"], "outputs": ["70"]}
coding
688
Solve the programming task below in a Python markdown code block. With the college fest approaching soon, Manasa is following a strict dieting regime . Today, she just cannot resist her temptation for having a pizza. An inner conflict ensues, and she decides that she will have a pizza, only if she comes up with a solut...
{"inputs": ["3\n1 2 3\n"], "outputs": ["40392\n"]}
coding
496
Solve the programming task below in a Python markdown code block. We will define the median of a sequence b of length M, as follows: - 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...
{"inputs": ["1\n4", "1\n2", "1\n7", "1\n3", "1\n6", "1\n1", "1\n5", "1\n8"], "outputs": ["4\n", "2\n", "7\n", "3\n", "6\n", "1\n", "5\n", "8\n"]}
coding
508
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an integer array nums. You must perform exactly one operation where you can replace one element nums[i] with nums[i] * nums[i].  Return the maximum possible subarray sum after exactly one operation. The ...
{"functional": "def check(candidate):\n assert candidate(nums = [2,-1,-4,-3]) == 17\n assert candidate(nums = [1,-1,1,1,-1,-1,1]) == 4\n\n\ncheck(Solution().maxSumAfterOperation)"}
coding
105
Solve the programming task below in a Python markdown code block. There is an empty grid (all cells are colored white) of N rows and M columns. Chef can fill each cell with either RED or GREEN color. Chef defines a *valid* path as a path of cells starting from (1,1) and ending at (N,M), where, Chef moves either righ...
{"inputs": ["3\n1 1\n1 2\n2 3\n"], "outputs": ["0\n2\n72\n"]}
coding
498
Solve the programming task below in a Python markdown code block. We have a string s consisting of lowercase English letters. Snuke is partitioning s into some number of non-empty substrings. Let the subtrings obtained be s_1, s_2, ..., s_N from left to right. (Here, s = s_1 + s_2 + ... + s_N holds.) Snuke wants to sat...
{"inputs": ["byeybe", "eybcxb", "ebyeyb", "eybeyb", "eybdyb", "eybcyb", "byecxb", "cyebxb"], "outputs": ["1\n", "6\n", "1\n", "1\n", "2\n", "2\n", "6\n", "4\n"]}
coding
242
Solve the programming task below in a Python markdown code block. Mr. Square is going on a holiday. He wants to bring 2 of his favorite squares with him, so he put them in his rectangle suitcase. Write a function that, given the size of the squares and the suitcase, return whether the squares can fit inside the suitca...
{"functional": "_inputs = [[1, 2, 3, 2], [1, 2, 2, 1], [3, 2, 3, 2], [1, 2, 1, 2], [6, 5, 8, 7], [6, 6, 12, 6], [7, 1, 7, 8], [10, 10, 11, 11], [7, 2, 9, 7], [7, 2, 8, 7], [4, 1, 5, 3], [1, 2, 3, 4], [1, 2, 4, 3], [1, 3, 2, 4], [1, 3, 4, 2], [1, 4, 2, 3], [1, 4, 3, 2], [2, 1, 3, 4], [2, 1, 4, 3], [2, 3, 1, 4], [2, 3, 4...
coding
193
Solve the programming task below in a Python markdown code block. Today Sonya learned about long integers and invited all her friends to share the fun. Sonya has an initially empty multiset with integers. Friends give her t queries, each of one of the following type: 1. + ai — add non-negative integer ai to the mul...
{"inputs": ["4\n+ 200\n+ 15\n- 200\n? 0\n", "4\n+ 200\n+ 200\n- 200\n? 0\n", "10\n+ 2\n- 2\n+ 778\n+ 3\n+ 4\n- 4\n+ 1\n+ 617\n? 011\n? 011\n", "10\n+ 2\n- 2\n+ 778\n+ 2\n+ 4\n- 4\n+ 1\n+ 617\n? 011\n? 011\n", "10\n+ 2\n- 2\n+ 778\n+ 0\n+ 4\n- 4\n+ 0\n+ 617\n? 001\n? 011\n", "10\n+ 2\n- 2\n+ 778\n+ 1\n+ 4\n- 4\n+ 1\n+ 6...
coding
756
Solve the programming task below in a Python markdown code block. Note that the memory limit is unusual. You are given an integer n and two sequences a_1, a_2, ..., a_n and b_1, b_2, ..., b_n. Let's call a set of integers S such that S ⊆ \{1, 2, 3, ..., n\} strange, if, for every element i of S, the following conditi...
{"inputs": ["1\n6\n3\n", "1\n1\n8\n", "1\n1\n9\n", "1\n2\n9\n", "1\n5\n42\n", "1\n5\n-8\n", "1\n5\n45\n", "1\n5\n70\n"], "outputs": ["3\n", "8\n", "9\n", "9\n", "42\n", "0\n", "45\n", "70\n"]}
coding
394
Solve the programming task below in a Python markdown code block. You have decided to give an allowance to your child depending on the outcome of the game that he will play now. The game is played as follows: - There are three "integer panels", each with a digit between 1 and 9 (inclusive) printed on it, and one "oper...
{"inputs": ["9 9 8", "1 8 2", "6 6 5", "0 9 8", "1 1 2", "6 7 5", "1 2 2", "6 9 5"], "outputs": ["107\n", "83\n", "71\n", "98\n", "22\n", "81\n", "23\n", "101\n"]}
coding
271
Solve the programming task below in a Python markdown code block. Write a function that merges two sorted arrays into a single one. The arrays only contain integers. Also, the final outcome must be sorted and not have any duplicate. Also feel free to reuse/extend the following starter code: ```python def merge_arrays(f...
{"functional": "_inputs = [[[1, 3, 5], [2, 4, 6]], [[2, 4, 8], [2, 4, 6]], [[1, 2, 3], []], [[], []]]\n_outputs = [[[1, 2, 3, 4, 5, 6]], [[2, 4, 6, 8]], [[1, 2, 3]], [[]]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, ab...
coding
69
Solve the programming task below in a Python markdown code block. There are three positive integers A, B and C written on a blackboard. E869120 performs the following operation K times: - Choose one integer written on the blackboard and let the chosen integer be n. Replace the chosen integer with 2n. What is the large...
{"inputs": ["3 3 4\n4", "3 3 4\n0", "4 3 4\n0", "4 3 1\n0", "4 1 1\n0", "3 1 1\n0", "4 2 1\n0", "3 2 4\n2"], "outputs": ["70\n", "10\n", "11\n", "8\n", "6\n", "5\n", "7\n", "21\n"]}
coding
352
Solve the programming task below in a Python markdown code block. Create a function `sierpinski` to generate an ASCII representation of a Sierpinski triangle of order **N**. Seperate each line with `\n`. You don't have to check the input value. The output should look like this: sierpinski(4) ...
{"functional": "_inputs = [[1], [2], [3]]\n_outputs = [[' * \\n* *'], [' * \\n * * \\n * * \\n* * * *'], [' * \\n * * \\n * * \\n * * * * \\n * * \\n * * * * \\n * * * * \\n* * * * * * * *']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstan...
coding
235
Solve the programming task below in a Python markdown code block. You are taking a computer-based examination. The examination consists of N questions, and the score allocated to the i-th question is s_i. Your answer to each question will be judged as either "correct" or "incorrect", and your grade will be the sum of t...
{"inputs": ["3\n2\n0\n2", "3\n2\n1\n2", "3\n0\n0\n3", "3\n1\n8\n1", "3\n2\n8\n0", "3\n2\n3\n1", "3\n2\n3\n2", "3\n2\n8\n2"], "outputs": ["4\n", "5\n", "3\n", "9\n", "8\n", "6\n", "7\n", "12\n"]}
coding
321
Solve the programming task below in a Python markdown code block. You are given a string s consisting of n lowercase Latin letters. You have to type this string using your keyboard. Initially, you have an empty string. Until you type the whole string, you may perform the following operation: add a character to the en...
{"inputs": ["1\na\n", "1\ns\n", "1\ns\n", "1\na\n", "1\nt\n", "1\n`\n", "2\naa\n", "2\naa\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "2\n", "2\n"]}
coding
322
Solve the programming task below in a Python markdown code block. For a set $S$ of integers, perform a sequence of the following operations. Note that each value in $S$ must be unique. * insert($x$): Insert $x$ to $S$ and report the number of elements in $S$ after the operation. * find($x$): Report the number of $x$ i...
{"inputs": ["8\n0 1\n0 2\n0 2\n2 2\n1 1\n1 2\n1 3\n0 2", "8\n0 1\n0 4\n0 2\n2 2\n1 1\n1 2\n1 3\n0 2", "8\n0 1\n0 4\n0 2\n2 2\n1 1\n1 4\n1 3\n0 2", "8\n0 1\n0 4\n0 1\n2 2\n1 1\n1 4\n1 3\n0 2", "8\n0 2\n0 3\n0 1\n2 2\n1 1\n1 4\n1 3\n0 2", "8\n0 2\n0 3\n0 2\n2 2\n1 1\n1 4\n1 3\n0 2", "8\n1 1\n0 2\n0 3\n2 2\n1 1\n1 2\n1 3\...
coding
316
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a linked list, swap every two adjacent nodes and return its head. You must solve the problem without modifying the values in the list's nodes (i.e., only nodes themselves may be changed.)   Please complete the f...
{"functional": "def check(candidate):\n assert is_same_list(candidate(head = list_node([1,2,3,4])), list_node([2,1,4,3]))\n assert is_same_list(candidate(head = list_node([])), list_node([]))\n assert is_same_list(candidate(head = list_node([1])), list_node([1]))\n\n\ncheck(Solution().swapPairs)"}
coding
134
Solve the programming task below in a Python markdown code block. How many non decreasing sequences are there of length ${K}$, with the condition that numbers in sequence can take values only from $1,2,3,\cdots N$ and gcd of all numbers in the sequence must be ${1}$. Input Format The first line contains an integer $...
{"inputs": ["4\n2 4 \n3 4\n5 2\n1 10\n"], "outputs": ["4\n13\n10\n1\n"]}
coding
501
Solve the programming task below in a Python markdown code block. You are given two integers $n$ and $m$. Find the $\operatorname{MEX}$ of the sequence $n \oplus 0, n \oplus 1, \ldots, n \oplus m$. Here, $\oplus$ is the bitwise XOR operator . $\operatorname{MEX}$ of the sequence of non-negative integers is the smalles...
{"inputs": ["5\n4 8\n2 0\n5 2\n25 331\n5594 361646\n", "5\n3 5\n4 6\n3 4\n69 696\n51217 654321\n", "5\n3 5\n2 0\n1 2\n69 696\n87131 654321\n", "5\n6 5\n2 0\n6 2\n39 696\n185099 29706\n", "5\n3 5\n2 0\n1 2\n36 696\n87131 654321\n", "5\n3 8\n2 0\n1 2\n36 696\n87131 654321\n", "5\n6 5\n2 0\n6 1\n39 974\n185099 29706\n", "...
coding
602
Solve the programming task below in a Python markdown code block. After Fox Ciel got off a bus, she found that the bus she was on was a wrong bus and she lost her way in a strange town. However, she fortunately met her friend Beaver Taro and asked which way to go to her castle. Taro's response to her was a string s, an...
{"inputs": ["Z\n1\na\n", "9\n1\n9\n", "9\n1\n13\n", "hb\n1\nAa\n", "abc\n1\nb\n", "hb\n1\nBa\n", "cba\n1\nb\n", "abcde\n1\nf\n"], "outputs": ["1 0", "0 0", "1 0\n", "2 0", "1 0", "2 0\n", "1 0\n", "5 0"]}
coding
517
Solve the programming task below in a Python markdown code block. Snuke is playing a puzzle game. In this game, you are given a rectangular board of dimensions R × C, filled with numbers. Each integer i from 1 through N is written twice, at the coordinates (x_{i,1},y_{i,1}) and (x_{i,2},y_{i,2}). The objective is to dr...
{"inputs": ["1 1 2\n0 0 1 1\n1 0 0 1", "1 1 2\n0 0 1 1\n1 0 0 1\n", "4 3 3\n0 1 3 1\n1 1 4 1\n2 0 2 2", "4 3 3\n0 1 3 1\n1 1 4 1\n0 0 2 2", "4 2 3\n0 1 3 1\n1 1 4 1\n2 0 4 2", "4 3 3\n0 1 1 1\n1 1 4 1\n0 0 2 2", "4 2 3\n0 1 3 1\n1 1 4 1\n2 0 4 1", "4 3 3\n0 1 1 1\n1 1 4 1\n0 0 2 1"], "outputs": ["NO", "NO\n", "YES\n", ...
coding
357
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a 0-indexed integer array nums of length n and an integer k. In an operation, you can choose an element and multiply it by 2. Return the maximum possible value of nums[0] | nums[1] | ... | nums[n - 1] th...
{"functional": "def check(candidate):\n assert candidate(nums = [12,9], k = 1) == 30\n assert candidate(nums = [8,1,2], k = 2) == 35\n\n\ncheck(Solution().maximumOr)"}
coding
142
Solve the programming task below in a Python markdown code block. Let's call a string good if and only if it consists of only two types of letters — 'a' and 'b' and every two consecutive letters are distinct. For example "baba" and "aba" are good strings and "abb" is a bad string. You have $a$ strings "a", $b$ strings...
{"inputs": ["1 1 1\n", "2 1 2\n", "3 5 2\n", "2 2 1\n", "3 1 3\n", "2 2 3\n", "1 1 4\n", "1 1 2\n"], "outputs": ["4\n", "7\n", "11\n", "6\n", "9\n", "10\n", "10\n", "6\n"]}
coding
360
Solve the programming task below in a Python markdown code block. You are given a string s, consisting of small Latin letters. Let's denote the length of the string as |s|. The characters in the string are numbered starting from 1. Your task is to find out if it is possible to rearrange characters in string s so that...
{"inputs": ["z\n", "abc\n", "abcc\n", "abcd\n", "xxxyyxx\n", "xxxyxxx\n", "hfihihhfh\n", "hgihihhfh\n"], "outputs": ["YES\nz", "YES\nabc", "YES\nacbc\n", "NO\n", "YES\nxxxxyxy\n", "YES\nxxxxxxy\n", "NO\n", "NO\n"]}
coding
341
Solve the programming task below in a Python markdown code block. You are given an array A of length N. Determine the count of subarrays of A which contain their length as an element. Formally, count the number of pairs (L, R) (1≤ L≤ R≤ N) such that: (R-L+1) \in \{A_{L}, A_{L+1}, \ldots, A_{R}\}. ------ Input Format...
{"inputs": ["3\n3\n1 2 1\n5\n2 3 1 3 5\n10\n10 7 4 4 2 9 2 1 9 3\n"], "outputs": ["4\n6\n15\n"]}
coding
430
Solve the programming task below in a Python markdown code block. The start of the new academic year brought about the problem of accommodation students into dormitories. One of such dormitories has a a × b square meter wonder room. The caretaker wants to accommodate exactly n students there. But the law says that ther...
{"inputs": ["3 3 5\n", "2 4 4\n", "1 1 1\n", "8 7 5\n", "8 7 5\n", "1 1 1\n", "3 4 5\n", "3 4 3\n"], "outputs": ["18\n3 6\n", "16\n4 4\n", "6\n1 6\n", "48\n8 6\n", "48\n8 6\n", "6\n1 6\n", "20\n4 5\n", "18\n6 3\n"]}
coding
278
Solve the programming task below in a Python markdown code block. Create a function that finds the [integral](https://en.wikipedia.org/wiki/Integral) of the expression passed. In order to find the integral all you need to do is add one to the `exponent` (the second argument), and divide the `coefficient` (the first ar...
{"functional": "_inputs = [[3, 2], [12, 5], [20, 1], [40, 3], [90, 2]]\n_outputs = [['1x^3'], ['2x^6'], ['10x^2'], ['10x^4'], ['30x^3']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (l...
coding
238
Solve the programming task below in a Python markdown code block. You have $r$ red and $b$ blue beans. You'd like to distribute them among several (maybe, one) packets in such a way that each packet: has at least one red bean (or the number of red beans $r_i \ge 1$); has at least one blue bean (or the number of blue ...
{"inputs": ["1\n1 1 1\n", "1\n2 1 1\n", "1\n2 1 1\n", "1\n1 1 1\n", "1\n2 1 0\n", "1\n1 1 2\n", "1\n2 2 0\n", "1\n2 2 1\n"], "outputs": ["YES\n", "YES\n", "YES\n", "YES\n", "NO\n", "YES\n", "YES\n", "YES\n"]}
coding
498
Solve the programming task below in a Python markdown code block. Chef likes all arrays equally. But he likes some arrays more equally than others. In particular, he loves Rainbow Arrays. An array is Rainbow if it has the following structure: - First a1 elements equal 1. - Next a2 elements equal 2. - Next a3 element...
{"inputs": ["3\n19\n1 2 3 4 4 5 6 6 6 7 6 6 6 5 4 4 3 2 1\n14\n1 2 3 4 5 6 7 6 5 4 3 2 1 1\n13\n1 2 3 4 5 6 8 6 5 4 3 2 1"], "outputs": ["yes\nno\nno"]}
coding
552
Solve the programming task below in a Python markdown code block. Did you know that Chwee kueh, a cuisine of Singapore, means water rice cake ? Its a variety of the most popular South Indian savory cake, only that we call it here idli :). The tastiest idlis are made in Chennai, by none other than our famous chef, Dexte...
{"inputs": ["3\n4\n1 2 2 3\n2\n1 2\n7\n1 2 3 4 5 6 7", "3\n4\n1 2 2 3\n2\n1 2\n7\n1 0 3 4 5 6 7", "3\n4\n1 4 2 3\n2\n1 2\n7\n1 0 3 4 5 6 7", "3\n4\n0 2 2 3\n2\n1 2\n7\n1 2 3 4 5 6 7", "3\n4\n1 1 1 1\n2\n1 2\n7\n1 4 0 1 6 6 7", "3\n4\n1 4 2 3\n2\n1 2\n7\n1 0 4 4 6 6 7", "3\n4\n1 2 2 3\n2\n1 2\n7\n1 4 3 2 5 6 7", "3\n4\n...
coding
774
Solve the programming task below in a Python markdown code block. Starting with a 1-indexed array of zeros and a list of operations, for each operation add a value to each the array element between two given indices, inclusive. Once all operations have been performed, return the maximum value in the array. Example ...
{"inputs": ["5 3\n1 2 100\n2 5 100\n3 4 100\n"], "outputs": ["200\n"]}
coding
670
Solve the programming task below in a Python markdown code block. Vova's family is building the Great Vova Wall (named by Vova himself). Vova's parents, grandparents, grand-grandparents contributed to it. Now it's totally up to Vova to put the finishing touches. The current state of the wall can be respresented by a s...
{"inputs": ["1\n1\n", "1\n2\n", "1\n1\n", "1\n2\n", "1\n0\n", "2\n1 2\n", "2\n1 2\n", "2\n3 2\n"], "outputs": ["YES\n", "YES\n", "YES\n", "YES\n", "YES\n", "NO\n", "NO\n", "NO\n"]}
coding
676
Please solve the programming task below using a self-contained code snippet in a markdown code block. There is a class with m students and n exams. You are given a 0-indexed m x n integer matrix score, where each row represents one student and score[i][j] denotes the score the ith student got in the jth exam. The matr...
{"functional": "def check(candidate):\n assert candidate(score = [[10,6,9,1],[7,5,11,2],[4,8,3,15]], k = 2) == [[7,5,11,2],[10,6,9,1],[4,8,3,15]]\n assert candidate(score = [[3,4],[5,6]], k = 0) == [[5,6],[3,4]]\n\n\ncheck(Solution().sortTheStudents)"}
coding
164
Solve the programming task below in a Python markdown code block. On each of the following $N$ days (numbered $1$ through $N$), Chef is planning to cook either pizza or broccoli. He wrote down a string $A$ with length $N$, where for each valid $i$, if the character $A_i$ is '1', then he will cook pizza on the $i$-th da...
{"inputs": ["2\n13 2\n0101110000101\n6 3\n100001"], "outputs": ["5\n4"]}
coding
552
Solve the programming task below in a Python markdown code block. Vasya has a pile, that consists of some number of stones. $n$ times he either took one stone from the pile or added one stone to the pile. The pile was non-empty before each operation of taking one stone from the pile. You are given $n$ operations which...
{"inputs": ["1\n+\n", "1\n-\n", "1\n-\n", "1\n+\n", "2\n-+\n", "2\n++\n", "2\n+-\n", "2\n--\n"], "outputs": ["1", "0", "0\n", "1\n", "1", "2", "0", "0"]}
coding
545
Solve the programming task below in a Python markdown code block. Chef loves bitwise operations. So, he creates the following problem but needs your help to solve it. Chef calls a sequence of integers A_{1}, A_{2}, \ldots, A_{N} tasty if it satisfies the following condition: parity(A_{i} \& A_{i+1}) \neq parity(A_{i} ...
{"inputs": ["2\n2\n0 0\n3\n6 16 69"], "outputs": ["-1\n1\n1 3"]}
coding
692
Solve the programming task below in a Python markdown code block. You are given three integers $a$, $b$ and $x$. Your task is to construct a binary string $s$ of length $n = a + b$ such that there are exactly $a$ zeroes, exactly $b$ ones and exactly $x$ indices $i$ (where $1 \le i < n$) such that $s_i \ne s_{i + 1}$. I...
{"inputs": ["2 2 1\n", "3 3 3\n", "5 3 6\n", "7 8 7\n", "2 3 3\n", "2 2 2\n", "3 4 6\n", "1 1 1\n"], "outputs": ["1100\n", "101100\n", "01010100\n", "101010111110000\n", "10110\n", "1001\n", "1010101\n", "10\n"]}
coding
457
Solve the programming task below in a Python markdown code block. Andy got a box of candies for Christmas. In fact, he discovered that the box contained several identical smaller boxes, and they could contain even smaller boxes, and so on. Formally, we say that candies are boxes of level 0, and for 1 ≤ i ≤ n, a level i...
{"inputs": ["5 1\n1 1 1 1 1\n1", "3 3\n3 3 3\n2 8 13"], "outputs": ["5", "3\n5\n8"]}
coding
554
Solve the programming task below in a Python markdown code block. Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. Chef has a sequence $A_{1}, A_{2}, \ldots, A_{N}$. The sequence is circular, i.e. for each valid $i$, elements $A_{i}$ and $A_{i+1}$ are considered a...
{"inputs": ["3\n3\n0 0 0\n4\n1 0 1 0\n5\n1 1 0 1 0"], "outputs": ["0\n2\n3"]}
coding
726
Solve the programming task below in a Python markdown code block. The chef is trying to decode some pattern problems, Chef wants your help to code it. Chef has one number K(odd) to form a new pattern. Help the chef to code this pattern problem. -----Input:----- - First-line will contain $T$, the number of test cases. ...
{"inputs": ["4\n1\n3\n5\n7"], "outputs": ["1\n111\n111\n111\n11111\n11 11\n1 1 1\n11 11\n11111\n1111111\n11 11\n1 1 1 1\n1 1 1\n1 1 1 1\n11 11\n1111111"]}
coding
277
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an array nums that consists of non-negative integers. Let us define rev(x) as the reverse of the non-negative integer x. For example, rev(123) = 321, and rev(120) = 21. A pair of indices (i, j) is nice i...
{"functional": "def check(candidate):\n assert candidate(nums = [42,11,1,97]) == 2\n assert candidate(nums = [13,10,35,24,76]) == 4\n\n\ncheck(Solution().countNicePairs)"}
coding
179
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given three integers, k, digit1, and digit2, you want to find the smallest integer that is: Larger than k, A multiple of k, and Comprised of only the digits digit1 and/or digit2. Return the smallest such integer. If...
{"functional": "def check(candidate):\n assert candidate(k = 2, digit1 = 0, digit2 = 2) == 20\n assert candidate(k = 3, digit1 = 4, digit2 = 2) == 24\n assert candidate(k = 2, digit1 = 0, digit2 = 0) == -1\n\n\ncheck(Solution().findInteger)"}
coding
143
Solve the programming task below in a Python markdown code block. How many integer sequences A_1,A_2,\ldots,A_N of length N satisfy all of the following conditions? - 0 \leq A_i \leq 9 - There exists some i such that A_i=0 holds. - There exists some i such that A_i=9 holds. The answer can be very large, so output it...
{"inputs": ["0", "3", "5", "7", "4", "6", "9", "8"], "outputs": ["0\n", "54\n", "14670\n", "2531214\n", "974\n", "199262\n", "359376750\n", "30683774\n"]}
coding
188
Solve the programming task below in a Python markdown code block. Let's assume that we are given a matrix b of size x × y, let's determine the operation of mirroring matrix b. The mirroring of matrix b is a 2x × y matrix c which has the following properties: the upper half of matrix c (rows with numbers from 1 to x)...
{"inputs": ["1 1\n0\n", "1 1\n1\n", "1 1\n0\n", "1 1\n1\n", "1 2\n0 1\n", "1 2\n0 1\n", "1 2\n1 1\n", "1 2\n2 1\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n"]}
coding
457
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a string text, you want to use the characters of text to form as many instances of the word "balloon" as possible. You can use each character in text at most once. Return the maximum number of instances that can...
{"functional": "def check(candidate):\n assert candidate(text = \"nlaebolko\") == 1\n assert candidate(text = \"loonbalxballpoon\") == 2\n assert candidate(text = \"leetcode\") == 0\n\n\ncheck(Solution().maxNumberOfBalloons)"}
coding
100
Solve the programming task below in a Python markdown code block. Galya is playing one-dimensional Sea Battle on a 1 × n grid. In this game a ships are placed on the grid. Each of the ships consists of b consecutive cells. No cell can be part of two ships, however, the ships can touch each other. Galya doesn't know th...
{"inputs": ["1 1 1 0\n0\n", "2 2 1 0\n00\n", "1 1 1 -1\n0\n", "1 1 1 -2\n0\n", "1 1 1 -3\n0\n", "2 2 1 -1\n00\n", "5 4 1 0\n00000\n", "5 1 2 1\n00100\n"], "outputs": ["1\n1 ", "1\n1 ", "1\n1\n", "1\n1\n", "1\n1\n", "1\n1\n", "2\n1 2 ", "2\n2 5 "]}
coding
524
Solve the programming task below in a Python markdown code block. You are given two positive integers A and B. You need to construct two different binary strings (i.e, they are strings which consist of only 0s and 1s), which satisfy these two conditions: Both the strings should be palindromes. Each string should have ...
{"inputs": ["3\n2 2\n2 3\n3 3\n"], "outputs": ["Yes\nYes\nNo\n"]}
coding
488
Solve the programming task below in a Python markdown code block. Read problems statements [Hindi] , [Vietnamese] , [Mandarin Chinese] , [Russian] and [Bengali] as well. Raja only participates in contests and does not upsolve, but he claims that he has been upsolving. Chef wants to test if he is really improving, so h...
{"inputs": ["1\n3\n2 3 2"], "outputs": ["5"]}
coding
637
Solve the programming task below in a Python markdown code block. Two sisters, A and B, play the piano every day. During the day, they can play in any order. That is, A might play first and then B, or it could be B first and then A. But each one of them plays the piano exactly once per day. They maintain a common log, ...
{"inputs": ["4\nAB\nABBA\nABAABB\nAA"], "outputs": ["yes\nyes\nno\nno"]}
coding
394
Solve the programming task below in a Python markdown code block. $n$ heroes fight against each other in the Arena. Initially, the $i$-th hero has level $a_i$. Each minute, a fight between two different heroes occurs. These heroes can be chosen arbitrarily (it's even possible that it is the same two heroes that were f...
{"inputs": ["1\n3\n90 91 92\n", "1\n3\n90 91 92\n", "1\n3\n90 56 92\n", "1\n3\n90 75 92\n", "1\n3\n49 75 92\n", "1\n3\n90 43 92\n", "1\n3\n90 57 92\n", "1\n3\n49 75 180\n"], "outputs": ["2\n", "2\n", "2\n", "2\n", "2\n", "2\n", "2\n", "2\n"]}
coding
440
Solve the programming task below in a Python markdown code block. Your task is to Combine two Strings. But consider the rule... By the way you don't have to check errors or incorrect input values, everything is ok without bad tricks, only two input strings and as result one output string;-)... And here's the rule: ...
{"functional": "_inputs = [['abc', 'cde'], ['abcdeFgtrzw', 'defgGgfhjkwqe'], ['abcdeFg', 'defgG'], ['abab', 'bababa']]\n_outputs = [['abCCde'], ['abcDeFGtrzWDEFGgGFhjkWqE'], ['abcDEfgDEFGg'], ['ABABbababa']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n retur...
coding
553
Solve the programming task below in a Python markdown code block. Polycarp is a big lover of killing time in social networks. A page with a chatlist in his favourite network is made so that when a message is sent to some friend, his friend's chat rises to the very top of the page. The relative order of the other chats ...
{"inputs": ["1\nwdi\n", "1\nwdi\n", "1\nwci\n", "1\nwcj\n", "1\nwjc\n", "1\ncjw\n", "2\naa\na\n", "2\naa\na\n"], "outputs": ["wdi\n", "wdi\n", "wci\n", "wcj\n", "wjc\n", "cjw\n", "a\naa\n", "a\naa\n"]}
coding
440
Solve the programming task below in a Python markdown code block. ## Fixed xor Write a function that takes two hex strings as input and XORs them against each other. If the strings are different lengths the output should be the length of the shortest string. Hint: The strings would first need to be converted to binar...
{"functional": "_inputs = [['1c0111001f010100061a024b53535009181c', '686974207468652062756c6c277320657965'], ['aadf', 'bce2'], ['ab3f', 'ac'], ['', ''], ['c611d9bdd9de38b9eb', '23a0745505d4d25494'], ['7d1e875da9d5e89b54c7eaf', '3541599be591709795cebd5'], ['785a6677b3e52f0e7', 'a8d97da7441'], ['6cbd75511e7f750c6827', '1...
coding
385
Solve the programming task below in a Python markdown code block. Hello everyone. I have a simple challenge for you today. In mathematics, the formula for finding the sum to infinity of a geometric sequence is: **ONLY IF** `-1 < r < 1` where: * `a` is the first term of the sequence * `r` is the common ratio of t...
{"functional": "_inputs = [[[1, 0.5, 0.25, 0.125]], [[250, 100, 40, 16]], [[21, 4.2, 0.84, 0.168]], [[5, -2.5, 1.25, -0.625]]]\n_outputs = [[2], [416.667], [26.25], [3.333]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, ...
coding
210
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an array of distinct integers arr, where arr is sorted in ascending order, return the smallest index i that satisfies arr[i] == i. If there is no such index, return -1.   Please complete the following python cod...
{"functional": "def check(candidate):\n assert candidate(arr = [-10,-5,0,3,7]) == 3\n assert candidate(arr = [0,2,5,8,17]) == 0\n assert candidate(arr = [-10,-5,3,4,7,9]) == -1\n\n\ncheck(Solution().fixedPoint)"}
coding
88
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. Little Egor is a huge movie fan. He likes watching different kinds of movies: from drama movies to comedy movies, from teen movies to horror movies. He is planning to visit c...
{"inputs": ["2\n2\n1 2\n2 1\n4\n2 1 4 1\n2 4 1 4", "2\n2\n1 2\n2 1\n4\n2 1 4 1\n2 5 1 4", "2\n2\n2 2\n2 1\n4\n2 1 4 1\n4 4 1 4", "2\n2\n1 2\n2 1\n4\n1 1 4 1\n2 5 1 4", "2\n2\n2 2\n2 1\n4\n2 1 4 1\n2 4 1 4", "2\n2\n2 2\n2 1\n4\n2 1 4 1\n1 4 1 4", "2\n2\n1 2\n2 1\n4\n1 1 1 1\n2 5 1 4", "2\n2\n2 2\n2 1\n3\n2 1 4 1\n1 4 1 ...
coding
459
Solve the programming task below in a Python markdown code block. There is data of up to 100 characters per line, consisting of half-width alphabetic character strings. Some lines are symmetric (same whether read from the left edge or the right edge). Create a program that reads this data and outputs the number of symm...
{"inputs": ["abcba\nsx\nabcddcba\nrstrd", "abcca\nsw\nabcddcba\nrstrd", "abcca\nxt\nadcbdcba\nrdsrt", "abcba\nsw\nabcddcba\nrstrd", "accba\nsw\nabcddcba\nrstrd", "accba\nsx\nabcddcba\nrstrd", "accba\ntx\nabcddcba\nrstrd", "accba\ntx\nabcddcba\nrsdrt"], "outputs": ["2\n", "1\n", "0\n", "2\n", "1\n", "1\n", "1\n", "1\n"]...
coding
143
Solve the programming task below in a Python markdown code block. A and B are preparing themselves for programming contests. To train their logical thinking and solve problems better, A and B decided to play chess. During the game A wondered whose position is now stronger. For each chess piece we know its weight: t...
{"inputs": ["...QK...\n........\n........\n........\n........\n........\n........\n...rk...\n", "rnbqkbnr\npppppppp\n........\n........\n........\n........\nPPPPPPPP\nRNBQKBNR\n", "rppppppr\n...k....\n........\n........\n........\n........\nK...Q...\n........\n", "....bQ.K\n.B......\n.....P..\n........\n........\n........
coding
596
Solve the programming task below in a Python markdown code block. Note that the memory limit is unusual. You are given a multiset consisting of n integers. You have to process queries of two types: * add integer k into the multiset; * find the k-th order statistics in the multiset and remove it. k-th order s...
{"inputs": ["2 2\n1 2\n1 -1\n", "6 2\n1 1 1 2 3 4\n5 6\n", "6 2\n1 1 1 1 3 4\n5 6\n", "6 2\n1 1 1 2 3 4\n5 2\n", "6 2\n1 1 2 1 3 4\n5 6\n", "6 2\n1 1 2 2 3 4\n5 6\n", "6 2\n1 1 2 1 3 4\n5 5\n", "6 2\n1 1 2 1 3 4\n5 8\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n"]}
coding
580