task_type
stringclasses
4 values
problem
stringlengths
14
5.23k
solution
stringlengths
1
8.29k
problem_tokens
int64
9
1.02k
solution_tokens
int64
1
1.98k
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. There is a bi-directional graph with n vertices, where each vertex is labeled from 0 to n - 1 (inclusive). The edges in the graph are represented as a 2D integer array edges, where each edges[i] = [ui, vi] denotes a b...
{"functional": "def check(candidate):\n assert candidate(n = 3, edges = [[0,1],[1,2],[2,0]], source = 0, destination = 2) == True\n assert candidate(n = 6, edges = [[0,1],[0,2],[3,5],[5,4],[4,3]], source = 0, destination = 5) == False\n\n\ncheck(Solution().validPath)"}
196
99
coding
Solve the programming task below in a Python markdown code block. Write a function with the signature shown below: ```python def is_int_array(arr): return True ``` * returns `true / True` if every element in an array is an integer or a float with no decimals. * returns `true / True` if array is empty. * returns...
{"functional": "_inputs = [[[]], [[1, 2, 3, 4]], [[-11, -12, -13, -14]], [[1.0, 2.0, 3.0]], [[1, 2, None]], [None], [''], [[None]], [[1.0, 2.0, 3.0001]], [['-1']]]\n_outputs = [[True], [True], [True], [True], [False], [False], [False], [False], [False], [False]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isins...
110
265
coding
Solve the programming task below in a Python markdown code block. There are $n$ block towers in a row, where tower $i$ has a height of $a_i$. You're part of a building crew, and you want to make the buildings look as nice as possible. In a single day, you can perform the following operation: Choose two indices $i$ and...
{"inputs": ["3\n3\n9 7 4\n4\n3 3 1 3\n5\n0 3 6 1 5\n", "3\n3\n9 7 4\n4\n3 3 1 6\n5\n0 3 6 1 5\n", "3\n3\n3 7 4\n4\n6 3 1 6\n5\n0 3 2 1 5\n", "3\n3\n9 7 7\n4\n3 3 1 6\n5\n0 3 6 1 5\n", "3\n3\n4 7 4\n4\n6 3 1 6\n5\n0 3 2 1 5\n", "3\n3\n6 5 0\n4\n6 1 2 2\n5\n1 4 3 1 4\n", "3\n3\n16 5 5\n4\n3 3 0 3\n5\n0 3 6 1 5\n", "3\n3\...
612
344
coding
Solve the programming task below in a Python markdown code block. We have a string of letters 'a' and 'b'. We want to perform some operations on it. On each step we choose one of substrings "ab" in the string and replace it with the string "bba". If we have no "ab" as a substring, our job is done. Print the minimum num...
{"inputs": ["ba\n", "ca\n", "ab\n", "aab\n", "abbaa\n", "bbbaa\n", "aabbb\n", "aabaa\n"], "outputs": ["0\n", "0\n", "1", "3", "2", "0\n", "9\n", "3\n"]}
239
73
coding
Solve the programming task below in a Python markdown code block. Chef likes to play with array elements. His teacher has given him an array problem. But now he is busy as Christmas is coming. So, he needs your help. Can you help him to solve this problem. You are given an array $(A1,A2,A3……AN)$ of length $N$. You have...
{"inputs": ["2\n5\n2 4 5 7 9\n4\n5 4 2 3"], "outputs": ["6 11 14 4 2\n4 7 6 5"]}
508
52
coding
Solve the programming task below in a Python markdown code block. A notice on the notice board read: “Is there an end to it? While the number remains greater than one, if 2 divides the number completely, divide the number by 2; while the number remains greater than 1, if the number is not divisible by 2 , multiply th...
{"inputs": ["0", "1", "16"], "outputs": ["No", "Yes", "Yes"]}
152
25
coding
Solve the programming task below in a Python markdown code block. Your favorite music streaming platform has formed a perfectly balanced playlist exclusively for you. The playlist consists of $n$ tracks numbered from $1$ to $n$. The playlist is automatic and cyclic: whenever track $i$ finishes playing, track $i+1$ star...
{"inputs": ["2\n1 1\n", "2\n1 1\n", "3\n4 3 6\n", "3\n2 5 3\n", "3\n2 5 3\n", "3\n3 5 3\n", "3\n3 9 5\n", "3\n4 1 2\n"], "outputs": ["-1 -1\n", "-1 -1 ", "-1 -1 -1\n", "3 2 4\n", "3 2 4 \n", "-1 -1 -1\n", "3 2 4\n", "1 3 2\n"]}
744
143
coding
Solve the programming task below in a Python markdown code block. Once when Gerald studied in the first year at school, his teacher gave the class the following homework. She offered the students a string consisting of n small Latin letters; the task was to learn the way the letters that the string contains are written...
{"inputs": ["a\n1\n", "a\n0\n", "a\n2\n", "aa\n2\n", "aa\n3\n", "cky\n79\n", "aaaa\n4\n", "aaaa\n1\n"], "outputs": ["0\n", "1\na", "0\n", "0\n", "0\n", "0\n", "0\n", "1\naaaa"]}
524
90
coding
Solve the programming task below in a Python markdown code block. We say that a binary string (a string containing only characters '0' and '1') is pure if it does not contain either of the strings "0101" or "1010" as a subsequence. Recall that string T is a subsequence of string S if we can delete some of the letters o...
{"inputs": ["4\n010111101\n1011100001011101\n0110\n111111"], "outputs": ["2\n3\n0\n0"]}
382
57
coding
Solve the programming task below in a Python markdown code block. Takahashi has a maze, which is a grid of H \times W squares with H horizontal rows and W vertical columns. The square at the i-th row from the top and the j-th column is a "wall" square if S_{ij} is #, and a "road" square if S_{ij} is .. From a road squa...
{"inputs": ["1 2\n..\n", "3 3\n...\n../\n...", "3 3\n...\n...\n...", "3 3\n...\n...\n...\n", "0 5\n...#.\n.#.#.\n.#...", "0 5\n.#...\n.#.#.\n.#...", "0 5\n.#...\n.#.#.\n.$...", "0 5\n.#..-\n.#.#.\n.$..."], "outputs": ["1\n", "4\n", "4", "4\n", "0\n", "0\n", "0\n", "0\n"]}
341
137
coding
Solve the programming task below in a Python markdown code block. ## Task Write a function that accepts two arguments and generates a sequence containing the integers from the first argument to the second inclusive. ## Input Pair of integers greater than or equal to `0`. The second argument will always be greater t...
{"functional": "_inputs = [[2, 5]]\n_outputs = [[[2, 3, 4, 5]]]\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 return ...
124
168
coding
Solve the programming task below in a Python markdown code block. Polycarpus loves hamburgers very much. He especially adores the hamburgers he makes with his own hands. Polycarpus thinks that there are only three decent ingredients to make hamburgers from: a bread, sausage and cheese. He writes down the recipe of his ...
{"inputs": ["B\n1 1 1\n1 1 1\n381\n", "B\n1 1 1\n1 1 1\n381\n", "B\n1 2 1\n1 1 1\n381\n", "BSC\n3 5 6\n7 3 9\n100\n", "BSC\n3 5 6\n7 3 9\n100\n", "BSC\n3 5 9\n7 3 9\n100\n", "BSC\n3 5 9\n7 3 5\n100\n", "BSC\n3 5 9\n7 3 5\n101\n"], "outputs": ["382\n", "382\n", "382\n", "10\n", "10\n", "11\n", "12\n", "12\n"]}
675
214
coding
Solve the programming task below in a Python markdown code block. According to ISO 8601, the first calendar week (1) starts with the week containing the first thursday in january. Every year contains of 52 (53 for leap years) calendar weeks. **Your task is** to calculate the calendar week (1-53) from a given date. For...
{"functional": "_inputs = [['2017-01-01'], ['2018-12-24'], ['2018-12-31'], ['2019-01-01'], ['2016-02-29'], ['2015-12-29'], ['2024-12-31'], ['2025-01-05'], ['2025-01-06'], ['1995-12-31'], ['1996-01-01'], ['1999-12-31'], ['2000-01-02'], ['2000-01-03'], ['2016-12-25'], ['2016-12-26'], ['2017-01-02'], ['2017-01-09'], ['201...
246
458
coding
Solve the programming task below in a Python markdown code block. It is the easy version of the problem. The difference is that in this version, there are no nodes with already chosen colors. Theofanis is starving, and he wants to eat his favorite food, sheftalia. However, he should first finish his homework. Can you ...
{"inputs": ["3\n", "1\n", "2\n", "4\n", "2\n", "1\n", "4\n", "5\n"], "outputs": ["24576\n", "6\n", "96\n", "610612729\n", "96\n", "6\n", "610612729\n", "218379003\n"]}
482
100
coding
Solve the programming task below in a Python markdown code block. problem AOR Ika made a set $ S = \\ {a_1, ..., a_N \\} $ and a map $ f: S → S $. $ f (a_i) = b_i $. For any element $ x $ in the set $ S $, all maps $ g, h: S → S $ satisfying $ g (f (x)) = h (f (x)) $ are $ g (x). ) = Determine if h (x) $ is satisfied,...
{"inputs": ["5\n2 1 3 4 5\n3 4 2 5 1", "5\n1 2 3 4 5\n2 4 3 5 1", "5\n1 3 2 4 5\n3 4 2 5 1", "5\n2 1 3 4 5\n2 4 3 5 1", "5\n1 4 3 2 5\n3 4 2 5 1", "5\n2 1 3 4 5\n3 4 2 5 1", "5\n1 2 3 4 5\n2 4 3 5 1", "5\n2 1 3 4 5\n3 4 1 5 2"], "outputs": ["Yes\n", "Yes\n", "Yes\n", "Yes\n", "Yes\n", "Yes\n", "Yes\n", "Yes\n"]}
153
222
coding
Solve the programming task below in a Python markdown code block. Mike wants to prepare for IMO but he doesn't know geometry, so his teacher gave him an interesting geometry problem. Let's define f([l, r]) = r - l + 1 to be the number of integer points in the segment [l, r] with l ≤ r (say that $f(\varnothing) = 0$). Y...
{"inputs": ["1 1\n45 70\n", "1 1\n45 70\n", "1 1\n-35 -8\n", "1 1\n-35 -8\n", "1 1\n45 113\n", "1 1\n-40 -8\n", "1 1\n-79 -51\n", "1 1\n-79 -51\n"], "outputs": ["26\n", " 26\n", "28\n", " 28\n", "69...
592
151
coding
Solve the programming task below in a Python markdown code block. collections.namedtuple() Basically, namedtuples are easy to create, lightweight object types. They turn tuples into convenient containers for simple tasks. With namedtuples, you don’t have to use integer indices for accessing members of a tuple. Ex...
{"inputs": ["5\nMARKS CLASS NAME ID \n92 2 Calum 1 \n82 5 Scott 2 \n94 2 Jason 3 \n55 8 Glenn 4 \n82 2 Fergus 5\n", "5\nID MARKS NAME CLA...
693
182
coding
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"]}
688
51
coding
Solve the programming task below in a Python markdown code block. Hacker Zhorik wants to decipher two secret messages he intercepted yesterday. Yeah message is a sequence of encrypted blocks, each of them consists of several bytes of information. Zhorik knows that each of the messages is an archive containing one or m...
{"inputs": ["1 1\n1\n1\n", "1 1\n1\n1\n", "1 1\n2\n2\n", "1 2\n2\n1 1\n", "1 2\n2\n1 1\n", "2 2\n1 1\n1 1\n", "2 2\n2 3\n4 1\n", "2 2\n2 3\n3 2\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "1\n", "2\n", "1\n", "1\n"]}
742
134
coding
Solve the programming task below in a Python markdown code block. Pupils Alice and Ibragim are best friends. It's Ibragim's birthday soon, so Alice decided to gift him a new puzzle. The puzzle can be represented as a matrix with $2$ rows and $n$ columns, every element of which is either $0$ or $1$. In one move you can ...
{"inputs": ["1\n0\n1\n1\n0\n", "3\n1 0 0\n0 0 0\n0 0 0\n0 0 0\n", "5\n0 1 0 1 0\n1 1 0 0 1\n1 0 1 0 1\n0 0 1 1 0\n", "7\n1 0 0 1 1 0 1\n1 0 0 0 1 1 1\n1 1 1 0 0 1 0\n0 1 1 1 0 0 0\n", "7\n0 0 1 0 1 0 1\n0 0 0 0 0 0 1\n0 1 0 1 0 1 0\n1 0 0 0 0 0 0\n", "7\n0 0 0 0 0 0 0\n1 0 0 0 0 0 0\n0 0 0 0 0 1 0\n0 0 0 0 0 0 0\n", "7...
602
422
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an n x n binary matrix image, flip the image horizontally, then invert it, and return the resulting image. To flip an image horizontally means that each row of the image is reversed. For example, flipping [1,1,...
{"functional": "def check(candidate):\n assert candidate(image = [[1,1,0],[1,0,1],[0,0,0]]) == [[1,0,0],[0,1,0],[1,1,1]]\n assert candidate(image = [[1,1,0,0],[1,0,0,1],[0,1,1,1],[1,0,1,0]]) == [[1,1,0,0],[0,1,1,0],[0,0,0,1],[1,0,1,0]]\n\n\ncheck(Solution().flipAndInvertImage)"}
160
142
coding
Solve the programming task below in a Python markdown code block. Sereja has a string A consisting of n lower case English letters. Sereja calls two strings X and Y each of length n similar if they can be made equal by applying the following operation at most once in each of them. - Chose any two position i, j in th...
{"inputs": ["2\nz\nabcd\n\n"], "outputs": ["0\n144"]}
504
22
coding
Solve the programming task below in a Python markdown code block. Valentine's Day is approaching and thus Chef wants to buy some chocolates for someone special. Chef has a total of X rupees and one chocolate costs Y rupees. What is the maximum number of chocolates Chef can buy? ------ Input Format ------ - First l...
{"inputs": ["4\n5 10\n16 5\n35 7\n100 1\n"], "outputs": ["0\n3\n5\n100\n"]}
388
43
coding
Solve the programming task below in a Python markdown code block. Snuke has decided to play a game, where the player runs a railway company. There are M+1 stations on Snuke Line, numbered 0 through M. A train on Snuke Line stops at station 0 and every d-th station thereafter, where d is a predetermined constant for eac...
{"inputs": ["3 3\n1 2\n1 3\n3 3", "3 3\n1 1\n1 3\n3 3", "3 3\n1 2\n2 3\n3 3", "3 3\n1 2\n2 3\n3 3\n", "7 9\n1 9\n5 9\n5 7\n5 9\n1 1\n6 8\n3 4", "7 9\n1 9\n9 9\n5 7\n5 9\n1 1\n6 8\n3 4", "7 9\n1 9\n9 9\n5 7\n5 9\n1 1\n8 8\n3 4", "7 9\n1 9\n9 9\n5 5\n5 9\n1 1\n8 8\n3 4"], "outputs": ["3\n2\n2\n", "3\n1\n2\n", "3\n2\n2", ...
486
318
coding
Solve the programming task below in a Python markdown code block. Thanos wants to destroy the avengers base, but he needs to destroy the avengers along with their base. Let we represent their base with an array, where each position can be occupied by many avengers, but one avenger can occupy only one position. Length ...
{"inputs": ["1 1 5 6\n1\n", "1 1 5 6\n1\n", "1 1 7 6\n1\n", "1 1 5 2\n1\n", "1 1 7 0\n1\n", "2 1 5 2\n1\n", "1 1 7 -1\n1\n", "1 1 7 -2\n2\n"], "outputs": ["11\n", "11", "12\n", "4\n", "0\n", "8\n", "-2\n", "-4\n"]}
650
136
coding
Solve the programming task below in a Python markdown code block. Sort array by last character Complete the function to sort a given array or list by last character of elements. ```if-not:haskell Element can be an integer or a string. ``` ### Example: ``` ['acvd', 'bcc'] --> ['bcc', 'acvd'] ``` The last characte...
{"functional": "_inputs = [[['acvd', 'bcc']], [['14', '13']], [['asdf', 'asdf', '14', '13']], [['bsde', 'asdf', 14, '13']], [['asdf', 14, '13', 'asdf']]]\n_outputs = [[['bcc', 'acvd']], [['13', '14']], [['13', '14', 'asdf', 'asdf']], [['13', 14, 'bsde', 'asdf']], [['13', 14, 'asdf', 'asdf']]]\nimport math\ndef _deep_eq...
179
268
coding
Solve the programming task below in a Python markdown code block. Joisino is planning to record N TV programs with recorders. The TV can receive C channels numbered 1 through C. The i-th program that she wants to record will be broadcast from time s_i to time t_i (including time s_i but not t_i) on Channel c_i. Here, t...
{"inputs": ["3 4\n1 3 2\n2 4 4\n1 4 3", "3 4\n1 3 2\n2 4 4\n1 5 3", "3 4\n1 3 2\n3 4 4\n1 4 3", "3 4\n1 3 2\n3 4 4\n1 4 3\n", "3 2\n1 7 2\n7 8 1\n8 12 1", "3 2\n1 7 2\n7 8 1\n8 12 1\n", "3 2\n1 7 2\n7 12 1\n8 12 1", "3 2\n2 7 2\n7 12 1\n8 12 1"], "outputs": ["3\n", "3\n", "3", "3\n", "2", "2\n", "2\n", "2\n"]}
446
228
coding
Solve the programming task below in a Python markdown code block. Sitting in a station waiting room, Joisino is gazing at her train ticket. The ticket is numbered with four digits A, B, C and D in this order, each between 0 and 9 (inclusive). In the formula A op1 B op2 C op3 D = 7, replace each of the symbols op1, op2 ...
{"inputs": ["2364", "1114", "2005", "1455", "1152", "3246", "6120", "2768"], "outputs": ["2+3+6-4=7\n", "1+1+1+4=7\n", "2+0+0+5=7\n", "1-4+5+5=7\n", "1-1+5+2=7\n", "3+2-4+6=7\n", "6-1+2+0=7\n", "2+7+6-8=7\n"]}
235
150
coding
Solve the programming task below in a Python markdown code block. International Carpenters Professionals Company (ICPC) is a top construction company with a lot of expert carpenters. What makes ICPC a top company is their original language. The syntax of the language is simply given in CFG as follows: S -> SS | (S) ...
{"inputs": ["3\n0 ) 0\n7 * 0\n1 ( 0", "3\n0 ( 8\n10 ) 2\n0 ( 3", "3\n0 ( 8\n10 ) 4\n0 ( 3", "3\n0 ( 8\n10 ) 4\n0 ' 3", "3\n0 ( 3\n10 ) 4\n0 ' 3", "3\n-1 ) 0\n8 ( 19\n4 ' 2", "3\n-2 ) 0\n7 ) 0\n4 ( 11", "3\n0 ( 8\n10 ) 5\n10 ( 5"], "outputs": ["Yes\nYes\nYes\n", "No\nNo\nNo\n", "No\nNo\nNo\n", "No\nNo\nNo\n", "No\nNo\nN...
555
224
coding
Solve the programming task below in a Python markdown code block. problem Given the sequence $ A $ of length $ N $. The $ i $ item in $ A $ is $ A_i $. You can do the following for this sequence: * $ 1 \ leq i \ leq N --Choose the integer i that is 1 $. Swap the value of $ A_i $ with the value of $ A_ {i + 1} $. F...
{"inputs": ["5\n0 2 3 4 5", "5\n1 2 1 4 5", "5\n0 2 3 4 8", "5\n0 1 3 4 5", "5\n0 2 3 4 2", "5\n0 2 3 8 2", "5\n0 4 3 9 4", "5\n1 5 3 1 8"], "outputs": ["2\n", "1\n", "2\n", "2\n", "1\n", "1\n", "0\n", "1\n"]}
308
142
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are playing a simplified PAC-MAN game on an infinite 2-D grid. You start at the point [0, 0], and you are given a destination point target = [xtarget, ytarget] that you are trying to get to. There are several ghos...
{"functional": "def check(candidate):\n assert candidate(ghosts = [[1,0],[0,3]], target = [0,1]) == True\n assert candidate(ghosts = [[1,0]], target = [2,0]) == False\n assert candidate(ghosts = [[2,0]], target = [1,0]) == False\n\n\ncheck(Solution().escapeGhosts)"}
257
90
coding
Solve the programming task below in a Python markdown code block. Prime numbers are widely applied for cryptographic and communication technology. A twin prime is a prime number that differs from another prime number by 2. For example, (5, 7) and (11, 13) are twin prime pairs. In this problem, we call the greater numb...
{"inputs": ["12\n010\n27\n68\n0", "12\n010\n44\n68\n0", "12\n010\n8\n118\n0", "12\n100\n88\n50\n0", "12\n100\n71\n28\n0", "12\n100\n24\n28\n0", "12\n100\n24\n34\n0", "12\n100\n24\n52\n0"], "outputs": ["5 7\n5 7\n17 19\n59 61\n", "5 7\n5 7\n41 43\n59 61\n", "5 7\n5 7\n5 7\n107 109\n", "5 7\n71 73\n71 73\n41 43\n", "5 7\...
244
320
coding
Solve the programming task below in a Python markdown code block. Being a programmer, you like arrays a lot. For your birthday, your friends have given you an array a consisting of n distinct integers. Unfortunately, the size of a is too small. You want a bigger array! Your friends agree to give you a bigger array, bu...
{"inputs": ["1\n1\n", "1\n1\n", "1\n2\n", "1\n3\n", "1\n5\n", "1\n0\n", "1\n10\n", "2\n1 2\n"], "outputs": ["yes\n1 1\n", "yes\n1 1\n", "yes\n1 1\n", "yes\n1 1\n", "yes\n1 1\n", "yes\n1 1\n", "yes\n1 1\n", "yes\n1 1\n"]}
480
121
coding
Solve the programming task below in a Python markdown code block. The MarkiT online virtual market startup wants to organize its grand opening in NIT Patna. but they want maximum crowd for their inauguration. So the manager told this to Praveen a student in NITP who suggested them: The first-year students come to cam...
{"inputs": ["1\n10\n8 10 6"], "outputs": ["2"]}
351
22
coding
Solve the programming task below in a Python markdown code block. Given an alphanumeric string made up of digits and lower case Latin characters only, find the sum of all the digit characters in the string. -----Input----- - The first line of the input contains an integer T denoting the number of test cases. Then T te...
{"inputs": ["1\nab1231da"], "outputs": ["7"]}
204
19
coding
Solve the programming task below in a Python markdown code block. $Neha$ is given a number $N$. She always looks for special thing , this time she is looking for $Special$ $Number$ and $Partial$ $Special$ $Number$. A $Special$ $Number$ is a number whose product of its digits is equal to number itself i.e. $N $, and in...
{"inputs": ["3"], "outputs": ["1 20"]}
439
15
coding
Solve the programming task below in a Python markdown code block. Baby Badawy's first words were "AND 0 SUM BIG", so he decided to solve the following problem. Given two integers $n$ and $k$, count the number of arrays of length $n$ such that: all its elements are integers between $0$ and $2^k-1$ (inclusive); the bit...
{"inputs": ["1\n2 3\n", "1\n2 3\n", "1\n2 2\n", "1\n0 2\n", "1\n1 3\n", "1\n2 4\n", "1\n5 20\n", "1\n9 20\n"], "outputs": ["8\n", "8\n", "4\n", "0\n", "1\n", "16\n", "430973056\n", "953271190\n"]}
321
121
coding
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin chinese, Russian and Vietnamese as well. Chef has a clock, but it got broken today — the minute hand on Chef's clock doesn't rotate by the angle 2π/3600 each second, but by a different fixed angle x. The coordinates...
{"inputs": ["3\n4 2 1\n4 2 2\n4 2 3"], "outputs": ["2\n1000000005\n1000000003"]}
612
52
coding
Solve the programming task below in a Python markdown code block. Given two integers A and B. Let P denote a sequence of N [prime numbers] such that the sum of the sequence is A. Let Q denote a sequence of M prime numbers such that the sum of the sequence is B. Let X denote the maximum absolute difference between P_{...
{"inputs": ["2\n3 6\n3 2"], "outputs": ["0\n1"]}
483
22
coding
Solve the programming task below in a Python markdown code block. You would like to get the 'weight' of a name by getting the sum of the ascii values. However you believe that capital letters should be worth more than mere lowercase letters. Spaces, numbers, or any other character are worth 0. Normally in ascii a...
{"functional": "_inputs = [['Joe'], ['CJ'], ['cj'], ['George Washington'], ['Billy Bob Joe'], ['King George II'], ['r2d2'], ['R2D2'], ['C3PO']]\n_outputs = [[254], [205], [141], [1275], [909], [1012], [150], [214], [322]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\...
206
236
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an m x n grid of characters board and a string word, return true if word exists in the grid. The word can be constructed from letters of sequentially adjacent cells, where adjacent cells are horizontally or vert...
{"functional": "def check(candidate):\n assert candidate(board = [[\"A\",\"B\",\"C\",\"E\"],[\"S\",\"F\",\"C\",\"S\"],[\"A\",\"D\",\"E\",\"E\"]], word = \"ABCCED\") == True\n assert candidate(board = [[\"A\",\"B\",\"C\",\"E\"],[\"S\",\"F\",\"C\",\"S\"],[\"A\",\"D\",\"E\",\"E\"]], word = \"SEE\") == True\n asse...
108
153
coding
Solve the programming task below in a Python markdown code block. Complete the method/function so that it converts dash/underscore delimited words into camel casing. The first word within the output should be capitalized **only** if the original word was capitalized (known as Upper Camel Case, also often referred to as...
{"functional": "_inputs = [[''], ['the_stealth_warrior'], ['The-Stealth-Warrior'], ['A-B-C']]\n_outputs = [[''], ['theStealthWarrior'], ['TheStealthWarrior'], ['ABC']]\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_to...
137
192
coding
Solve the programming task below in a Python markdown code block. Sehr Sus is an infinite hexagonal grid as pictured below, controlled by MennaFadali, ZerooCool and Hosssam. They love equilateral triangles and want to create $n$ equilateral triangles on the grid by adding some straight lines. The triangles must all be...
{"inputs": ["1\n1\n", "2\n10\n9\n", "2\n76\n15\n", "2\n2922\n2251\n", "4\n1\n2\n3\n4567\n", "1\n1000000000\n", "3\n390\n398\n285\n", "5\n66\n6666\n666666\n66666666\n666666666\n"], "outputs": ["2\n", "4\n4\n", "11\n5\n", "67\n59\n", "2\n2\n3\n83\n", "38730\n", "25\n25\n21\n", "10\n100\n1000\n10000\n31623\n"]}
353
210
coding
Solve the programming task below in a Python markdown code block. Mutual Recursion allows us to take the fun of regular recursion (where a function calls itself until a terminating condition) and apply it to multiple functions calling each other! Let's use the Hofstadter Female and Male sequences to demonstrate this ...
{"functional": "_inputs = [[0], [5], [10], [15], [25]]\n_outputs = [[1], [3], [6], [9], [16]]\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):...
262
181
coding
Solve the programming task below in a Python markdown code block. Create the function ```consecutive(arr)``` that takes an array of integers and return the minimum number of integers needed to make the contents of ```arr``` consecutive from the lowest number to the highest number. For example: If ```arr``` contains [4...
{"functional": "_inputs = [[[4, 8, 6]], [[1, 2, 3, 4]], [[]], [[1]], [[-10]], [[1, -1]], [[-10, -9]], [[0]], [[10, -10]], [[-10, 10]]]\n_outputs = [[2], [0], [0], [0], [0], [1], [0], [0], [19], [19]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.i...
139
245
coding
Solve the programming task below in a Python markdown code block. Perhaps many have heard that the World Biathlon Championship has finished. Although our hero Valera was not present at this spectacular event himself and only watched it on TV, it excited him so much that he decided to enroll in a biathlon section. Of c...
{"inputs": ["2\n0 5\n10 5\n2\n7 2\n6 1\n", "2\n0 5\n10 5\n2\n7 2\n0 1\n", "2\n0 5\n10 5\n2\n9 2\n0 1\n", "2\n0 5\n10 7\n2\n9 2\n0 1\n", "3\n1 1\n3 1\n-4 2\n1\n-4 -3\n", "3\n3 2\n7 1\n11 1\n4\n2 1\n6 0\n6 4\n11 2\n", "3\n3 2\n0 1\n11 1\n4\n2 1\n6 0\n6 4\n11 2\n", "3\n3 2\n0 1\n11 1\n4\n2 1\n6 0\n1 4\n11 2\n"], "outputs"...
725
312
coding
Solve the programming task below in a Python markdown code block. You are given n segments on the Ox-axis. You can drive a nail in any integer point on the Ox-axis line nail so, that all segments containing this point, are considered nailed down. If the nail passes through endpoint of some segment, this segment is cons...
{"inputs": ["1\n0 0\n", "1\n1 0\n", "1\n2 0\n", "1\n1 1\n", "1\n1 2\n", "1\n-1 0\n", "1\n1 -1\n", "2\n0 2\n2 9\n"], "outputs": ["1\n0\n", "1\n1\n", "1\n2\n", "1\n1\n", "1\n2\n", "1\n0\n", "1\n1\n", "1\n2\n"]}
267
123
coding
Solve the programming task below in a Python markdown code block. *Gormint aunty is very upset with the government and Imran wants to prove that his government is not sold out. Gormint aunty gives an ethical problem which only an honest person could solve. Help Imran solve this question.* You are given two integers N ...
{"inputs": ["3\n5 4\n3 1\n6 3\n"], "outputs": ["5\n1 2 3 4 5\n1\n1 1 1\n3\n1 2 3 1 2 3"]}
574
57
coding
Solve the programming task below in a Python markdown code block. You already know that Valery's favorite sport is biathlon. Due to your help, he learned to shoot without missing, and his skills are unmatched at the shooting range. But now a smaller task is to be performed, he should learn to complete the path fastest....
{"inputs": ["1 2 4\nST\n", "1 2 1\nST\n", "1 3 3\nSaT\n", "2 1 4\nS\nT\n", "2 1 1\nS\nT\n", "1 3 2\nTyS\n", "1 3 2\nTzS\n", "1 3 3\nTyS\n"], "outputs": ["\n", "\n", "a\n", "\n", "\n", "y\n", "z\n", "y\n"]}
592
124
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a string array words and a string s, where words[i] and s comprise only of lowercase English letters. Return the number of strings in words that are a prefix of s. A prefix of a string is a substring tha...
{"functional": "def check(candidate):\n assert candidate(words = [\"a\",\"b\",\"c\",\"ab\",\"bc\",\"abc\"], s = \"abc\") == 3\n assert candidate(words = [\"a\",\"a\"], s = \"aa\") == 2\n\n\ncheck(Solution().countPrefixes)"}
121
70
coding
Solve the programming task below in a Python markdown code block. YouKn0wWho has two even integers x and y. Help him to find an integer n such that 1 ≤ n ≤ 2 ⋅ 10^{18} and n mod x = y mod n. Here, a mod b denotes the remainder of a after division by b. If there are multiple such integers, output any. It can be shown th...
{"inputs": ["1\n1000000000 1000000000\n", "1\n1000010000 1000000000\n", "1\n1001010000 1000000000\n", "1\n1001010010 1000000000\n", "1\n1001010010 1000100000\n", "1\n1000010010 1000000000\n", "1\n1000010011 1000000000\n", "1\n1001000000 1000000000\n"], "outputs": ["1000000000 \n", "2000010000\n", "2001010000\n", "20010...
352
319
coding
Solve the programming task below in a Python markdown code block. ZS the Coder and Chris the Baboon are travelling to Udayland! To get there, they have to get on the special IOI bus. The IOI bus has n rows of seats. There are 4 seats in each row, and the seats are separated into pairs by a walkway. When ZS and Chris ca...
{"inputs": ["1\nXO|OX\n", "1\nOO|OO\n", "1\nOO|XX\n", "1\nXO|OX\n", "1\nOO|OO\n", "1\nOO|XX\n", "1\nXX|OO\n", "1\nXO|NX\n"], "outputs": ["NO\n", "YES\n++|OO\n", "YES\n++|XX\n", "NO\n", "YES\n++|OO\n", "YES\n++|XX\n", "YES\nXX|++\n", "NO\n"]}
613
126
coding
Solve the programming task below in a Python markdown code block. Tim likes Math. He likes it so much that he always brings his tablets with him and reads math e-books everywhere, even during parties. Tim found an interesting exercise in one of the e-books he is reading. But you want him to join the party, so you deci...
{"inputs": ["3\n1 2\n0 4\n-1 1\n"], "outputs": ["4\n2\n0\n"]}
402
31
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a 0-indexed circular string array words and a string target. A circular array means that the array's end connects to the array's beginning. Formally, the next element of words[i] is words[(i + 1) % n] a...
{"functional": "def check(candidate):\n assert candidate(words = [\"hello\",\"i\",\"am\",\"leetcode\",\"hello\"], target = \"hello\", startIndex = 1) == 1\n assert candidate(words = [\"a\",\"b\",\"leetcode\"], target = \"leetcode\", startIndex = 0) == 1\n assert candidate(words = [\"i\",\"eat\",\"leetcode\"], ...
188
108
coding
Solve the programming task below in a Python markdown code block. ## Story Before we dive into the exercise, I would like to show you why these numbers are so important in computer programming today. It all goes back to the time of 19th century. Where computers we know today were non-existing. The first ever **comput...
{"functional": "_inputs = [[0], [3], [1337]]\n_outputs = [[1], [0], [0]]\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 ...
731
172
coding
Solve the programming task below in a Python markdown code block. Two people are playing Nimble! The rules of the game are: The game is played on a line of $n$ squares, indexed from $\mbox{0}$ to $n-1$. Each square $\boldsymbol{i}$ (where $0\leq i<n$) contains $c_i$ coins. For example: The players move in alternatin...
{"inputs": ["2\n5\n0 2 3 0 6\n4\n0 0 0 0\n"], "outputs": ["First\nSecond\n"]}
573
38
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given two 0-indexed integer arrays nums1 and nums2 of the same length. A pair of indices (i,j) is called beautiful if|nums1[i] - nums1[j]| + |nums2[i] - nums2[j]| is the smallest amongst all possible indices p...
{"functional": "def check(candidate):\n assert candidate(nums1 = [1,2,3,2,4], nums2 = [2,3,1,2,3]) == [0,3]\n assert candidate(nums1 = [1,2,4,3,2,5], nums2 = [1,4,2,3,5,1]) == [1,4]\n\n\ncheck(Solution().beautifulPair)"}
200
99
coding
Solve the programming task below in a Python markdown code block. You are playing a very popular game called Cubecraft. Initially, you have one stick and want to craft $k$ torches. One torch can be crafted using one stick and one coal. Hopefully, you've met a very handsome wandering trader who has two trade offers: e...
{"inputs": ["5\n2 2 5\n76 3 24\n7 15 9\n1000000000 1001000000 1000100001\n2 1000000001 1000000000\n", "5\n2 2 5\n76 19 24\n7 15 9\n1000000000 1001000000 1000000000\n2 1000000000 1000000000\n", "5\n2 2 5\n76 19 24\n7 15 9\n1000000000 1001000000 1000100000\n2 1000000000 1000000000\n", "5\n2 2 5\n76 19 24\n7 15 9\n1000000...
492
1,003
coding
Solve the programming task below in a Python markdown code block. In graph theory, a graph is a collection of nodes with connections between them. Any node can be connected to any other node exactly once, and can be connected to no nodes, to some nodes, or to every other node. Nodes cannot be connected to themselves A ...
{"functional": "_inputs = [[[[], []]], [[[1], [0]]], [[[1, 2], [0, 2], [0, 1]]], [[[1, 2, 3], [0, 2], [1, 2], [0]]], [[[1, 2, 3], [0], [0], [0, 4], [3]]], [[[1, 2, 3], [0], [0], [0, 4], [3], []]], [[[1], [0, 2], [1, 3, 5], [2, 4], [3, 5], [4, 2]]], [[[1], [0, 2, 3, 4], [1], [1], [1]]], [[[1], [0, 2, 3], [1], [1], [5], ...
392
465
coding
Solve the programming task below in a Python markdown code block. Let $f_{x} = c^{2x-6} \cdot f_{x-1} \cdot f_{x-2} \cdot f_{x-3}$ for $x \ge 4$. You have given integers $n$, $f_{1}$, $f_{2}$, $f_{3}$, and $c$. Find $f_{n} \bmod (10^{9}+7)$. -----Input----- The only line contains five integers $n$, $f_{1}$, $f_{2}$...
{"inputs": ["5 1 2 5 3\n", "4 1 1 1 1\n", "4 1 1 1 1\n", "5 2 2 5 3\n", "5 1 2 5 3\n", "17 97 41 37 11\n", "24 97 41 37 11\n", "17 97 41 37 11\n"], "outputs": ["72900\n", "1\n", "1", "145800\n", "72900", "317451037\n", "303925722\n", "317451037"]}
327
183
coding
Solve the programming task below in a Python markdown code block. Madoka's father just reached $1$ million subscribers on Mathub! So the website decided to send him a personalized award — The Mathhub's Bit Button! The Bit Button is a rectangular table with $n$ rows and $m$ columns with $0$ or $1$ in each cell. After e...
{"inputs": ["5\n3 3\n100\n011\n011\n3 3\n110\n111\n110\n1 5\n01111\n4 5\n11111\n01010\n01000\n01000\n3 2\n11\n00\n11\n"], "outputs": ["YES\nNO\nYES\nNO\nYES\n"]}
585
105
coding
Solve the programming task below in a Python markdown code block. During the lesson small girl Alyona works with one famous spreadsheet computer program and learns how to edit tables. Now she has a table filled with integers. The table consists of n rows and m columns. By a_{i}, j we will denote the integer located at...
{"inputs": ["1 1\n1\n1\n1 1\n", "1 1\n1\n1\n1 1\n", "1 1\n2\n1\n1 1\n", "5 4\n1 2 3 5\n3 1 3 2\n4 5 2 3\n5 5 3 2\n4 4 3 4\n6\n1 1\n2 5\n4 5\n3 5\n1 3\n1 5\n", "5 4\n1 2 3 5\n3 1 3 2\n4 5 2 3\n5 5 3 2\n4 4 4 4\n6\n1 1\n2 5\n4 5\n3 5\n1 3\n1 5\n", "5 4\n1 2 3 5\n3 1 3 2\n4 5 2 3\n4 5 4 2\n4 4 4 5\n6\n1 1\n2 5\n4 5\n5 5\n...
607
490
coding
Solve the programming task below in a Python markdown code block. Nearly each project of the F company has a whole team of developers working on it. They often are in different rooms of the office in different cities and even countries. To keep in touch and track the results of the project, the F company conducts share...
{"inputs": ["1 1\n+ 1\n", "2 1\n- 2\n", "2 1\n- 2\n", "1 1\n+ 1\n", "3 1\n- 2\n", "3 1\n- 3\n", "20 1\n- 16\n", "20 1\n- 16\n"], "outputs": ["1\n1 ", "2\n1 2 ", "2\n1 2 \n", "1\n1 \n", "3\n1 2 3\n", "3\n1 2 3\n", "20\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 ", "20\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 1...
614
250
coding
Solve the programming task below in a Python markdown code block. We've got no test cases. A big olympiad is coming up. But the problemsetters' number one priority should be adding another problem to the round. The diameter of a multiset of points on the line is the largest distance between two points from this set. ...
{"inputs": ["1 5\n6\n", "1 5\n6\n", "1 3\n6\n", "1 0\n6\n", "1 0\n22\n", "1 0\n22\n", "1 1\n22\n", "1 1\n42\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]}
424
106
coding
Solve the programming task below in a Python markdown code block. You are going to the beach with the idea to build the greatest sand castle ever in your head! The beach is not as three-dimensional as you could have imagined, it can be decribed as a line of spots to pile up sand pillars. Spots are numbered 1 through in...
{"inputs": ["5 2\n", "6 8\n", "1 1\n", "1 1\n", "3 4\n", "6 9\n", "1 2\n", "3 2\n"], "outputs": ["3\n", "3\n", "1\n", "1\n", "2\n", "3\n", "1\n", "2\n"]}
737
86
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a 0-indexed array of strings garbage where garbage[i] represents the assortment of garbage at the ith house. garbage[i] consists only of the characters 'M', 'P' and 'G' representing one unit of metal, pa...
{"functional": "def check(candidate):\n assert candidate(garbage = [\"G\",\"P\",\"GP\",\"GG\"], travel = [2,4,3]) == 21\n assert candidate(garbage = [\"MMM\",\"PGM\",\"GP\"], travel = [3,10]) == 37\n\n\ncheck(Solution().garbageCollection)"}
248
82
coding
Solve the programming task below in a Python markdown code block. Pasha has two hamsters: Arthur and Alexander. Pasha put n apples in front of them. Pasha knows which apples Arthur likes. Similarly, Pasha knows which apples Alexander likes. Pasha doesn't want any conflict between the hamsters (as they may like the same...
{"inputs": ["1 1 1\n1\n1\n", "2 1 1\n2\n1\n", "2 1 1\n1\n2\n", "2 1 1\n2\n1\n", "1 1 1\n1\n1\n", "2 1 1\n1\n2\n", "1 1 0\n1\n1\n", "1 1 0\n1\n0\n"], "outputs": ["1\n", "2 1\n", "1 2\n", "2 1 ", "1 ", "1 2 ", "1\n", "1\n"]}
406
139
coding
Solve the programming task below in a Python markdown code block. Integer sequence $\boldsymbol{a}$ having length $2n+2$ is defined as follows: $a_{0}=0$ $a_{1}=C$ $a_{i+2}=(a_{i+1}+a_i)\ \text{\% M}$, where $0\leq i<2n$ Write a function generator, $gen$, to generate the remaining values for $a_2$ through $a_{2n+1}$....
{"inputs": ["4 5 3\n"], "outputs": ["2\n"]}
720
18
coding
Solve the programming task below in a Python markdown code block. Ilya is an experienced player in tic-tac-toe on the 4 × 4 field. He always starts and plays with Xs. He played a lot of games today with his friend Arseny. The friends became tired and didn't finish the last game. It was Ilya's turn in the game when they...
{"inputs": ["xx..\n.oo.\nx...\noox.\n", "x.ox\nox..\nx.o.\noo.x\n", "x..x\n..oo\no...\nx.xo\n", "o.x.\no...\n.x..\nooxx\n", ".xox\no.x.\nx.o.\n..o.\n", "o.oo\n.x.o\nx.x.\n.x..\n", ".xx.\n.xoo\n.oox\n....\n", "xxox\no.x.\nx.oo\nxo.o\n"], "outputs": ["YES\n", "NO\n", "YES\n", "NO\n", "YES\n", "YES\n", "YES\n", "YES\n"]}
493
158
coding
Solve the programming task below in a Python markdown code block. Check Tutorial tab to know how to to solve. Here is a sample line of code that can be executed in Python: print("Hello, World!") You can just as easily store a string as a variable and then print it to stdout: my_string = "Hello, World!" print(...
{"inputs": [""], "outputs": ["Hello World!\n"]}
132
15
coding
Solve the programming task below in a Python markdown code block. Tokitsukaze has a sequence $a$ of length $n$. For each operation, she selects two numbers $a_i$ and $a_j$ ($i \ne j$; $1 \leq i,j \leq n$). If $a_i = a_j$, change one of them to $0$. Otherwise change both of them to $\min(a_i, a_j)$. Tokitsukaze wants...
{"inputs": ["3\n3\n1 2 3\n3\n1 2 2\n3\n1 2 0\n"], "outputs": ["4\n3\n2\n"]}
550
42
coding
Solve the programming task below in a Python markdown code block. There are $n$ piles of sand where the $i$-th pile has $a_i$ blocks of sand. The $i$-th pile is called too tall if $1 < i < n$ and $a_i > a_{i-1} + a_{i+1}$. That is, a pile is too tall if it has more sand than its two neighbours combined. (Note that pile...
{"inputs": ["3\n5 2\n2 9 2 4 1\n4 4\n1 3 2 1\n3 1\n1 3 1\n"], "outputs": ["2\n0\n1\n"]}
711
54
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an array of CPU tasks, each labeled with a letter from A to Z, and a number n. Each CPU interval can be idle or allow the completion of one task. Tasks can be completed in any order, but there's a constr...
{"functional": "def check(candidate):\n assert candidate(tasks = [\"A\",\"A\",\"A\",\"B\",\"B\",\"B\"], n = 2) == 8\n assert candidate(tasks = [\"A\",\"A\",\"A\",\"B\",\"B\",\"B\"], n = 0) == 6\n assert candidate(tasks = [\"A\",\"A\",\"A\",\"A\",\"A\",\"A\",\"B\",\"C\",\"D\",\"E\",\"F\",\"G\"], n = 2) == 16\n\...
136
119
coding
Solve the programming task below in a Python markdown code block. This is a story in a depopulated area. In this area, houses are sparsely built along a straight road called Country Road. Until now, there was no electricity in this area, but this time the government will give us some generators. You can install the gen...
{"inputs": ["6\n5 2\n10 30 69 70 110\n7 3\n3 7 10 2 21 26 28\n1 1\n100\n2 1\n0 1010000\n3 5\n30 70 37\n6 4\n0 0 20 7 40 50", "6\n5 2\n10 30 40 70 110\n7 3\n3 12 10 2 21 26 28\n1 1\n100\n2 1\n0 1010000\n3 8\n30 70 69\n6 4\n0 0 20 7 40 50", "6\n5 2\n10 30 69 70 110\n7 3\n3 7 10 2 21 26 28\n1 1\n100\n2 1\n-1 1010000\n3 5\...
590
997
coding
Solve the programming task below in a Python markdown code block. You have a large rectangular board which is divided into $n \times m$ cells (the board has $n$ rows and $m$ columns). Each cell is either white or black. You paint each white cell either red or blue. Obviously, the number of different ways to paint them...
{"inputs": ["1 4\noooo\n", "1 4\noooo\n", "2 2\noo\no*\n", "1 2\noo\no*\n", "2 2\noo\n*o\n", "1 2\noo\n*o\n", "1 2\noo\no)\n", "1 2\noo\n)o\n"], "outputs": ["9\n", "\n9\n", "4\n", "1\n", "4\n", "1\n", "1\n", "1\n"]}
494
120
coding
Solve the programming task below in a Python markdown code block. There are N positive integers A_1, A_2, ..., A_N. Takahashi can perform the following operation on these integers any number of times: * Choose 1 \leq i \leq N and multiply the value of A_i by -2. Notice that he multiplies it by minus two. He would ...
{"inputs": ["4\n2 1 4 1", "4\n3 1 4 4", "4\n2 1 5 1", "4\n2 1 4 2", "4\n3 1 4 2", "4\n3 1 4 8", "4\n2 1 4 8", "4\n2 1 1 2"], "outputs": ["3\n", "1\n", "5\n", "3\n", "3\n", "1\n", "1\n", "1\n"]}
312
126
coding
Solve the programming task below in a Python markdown code block. You throw a ball vertically upwards with an initial speed `v (in km per hour)`. The height `h` of the ball at each time `t` is given by `h = v*t - 0.5*g*t*t` where `g` is Earth's gravity `(g ~ 9.81 m/s**2)`. A device is recording at every **tenth of seco...
{"functional": "_inputs = [[37], [45], [99], [85], [136], [52], [16], [127], [137], [14]]\n_outputs = [[10], [13], [28], [24], [39], [15], [5], [36], [39], [4]]\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)\...
331
229
coding
Solve the programming task below in a Python markdown code block. Write ```python remove(text, what) ``` that takes in a string ```str```(```text``` in Python) and an object/hash/dict/Dictionary ```what``` and returns a string with the chars removed in ```what```. For example: ```python remove('this is a string',{'t':1...
{"functional": "_inputs = [['this is a string', {'t': 1, 'i': 2}], ['hello world', {'x': 5, 'i': 2}], ['apples and bananas', {'a': 50, 'n': 1}], ['a', {'a': 1, 'n': 1}], ['codewars', {'c': 5, 'o': 1, 'd': 1, 'e': 1, 'w': 1, 'z': 1, 'a': 1, 'r': 1, 's': 1}]]\n_outputs = [['hs s a string'], ['hello world'], ['pples d bnn...
222
296
coding
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin chinese, Russian and Vietnamese as well. You are given an integer $n$ and a string $s$ consisting only of characters 'a' and 'b'. Consider a string $t = \underbrace{s + s + \dots + s}_{n\text{ times}}$, i.e. the str...
{"inputs": ["3\naba 2\nbaa 3\nbba 3"], "outputs": ["5\n6\n0"]}
497
30
coding
Solve the programming task below in a Python markdown code block. City X consists of n vertical and n horizontal infinite roads, forming n × n intersections. Roads (both vertical and horizontal) are numbered from 1 to n, and the intersections are indicated by the numbers of the roads that form them. Sand roads have lo...
{"inputs": ["1\n1 1\n", "1\n1 1\n", "2\n1 1\n1 2\n2 1\n2 2\n", "2\n1 1\n2 2\n1 2\n2 1\n", "2\n1 2\n2 2\n2 1\n1 1\n", "2\n1 2\n2 2\n2 1\n1 1\n", "2\n1 1\n2 2\n1 2\n2 1\n", "2\n1 1\n2 2\n1 2\n1 1\n"], "outputs": ["1 \n", "1\n", "1 4 \n", "1 2 \n", "1 3 \n", "1 3\n", "1 2\n", "1 2 "]}
644
190
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given the root of a binary tree, return the preorder traversal of its nodes' values.   Please complete the following python code precisely: ```python # Definition for a binary tree node. # class TreeNode: # def __...
{"functional": "def check(candidate):\n assert candidate(root = tree_node([1,None,2,3])) == [1,2,3]\n assert candidate(root = tree_node([])) == []\n assert candidate(root = tree_node([1])) == [1]\n assert candidate(root = tree_node([1,2])) == [1,2]\n assert candidate(root = tree_node([1,None,2])) == [1,2...
119
111
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given two 0-indexed integer arrays player1 and player2, representing the number of pins that player 1 and player 2 hit in a bowling game, respectively. The bowling game consists of n turns, and the number of p...
{"functional": "def check(candidate):\n assert candidate(player1 = [4,10,7,9], player2 = [6,5,2,3]) == 1\n assert candidate(player1 = [3,5,7,6], player2 = [8,10,10,2]) == 2\n assert candidate(player1 = [2,3], player2 = [4,1]) == 0\n\n\ncheck(Solution().isWinner)"}
235
107
coding
Solve the programming task below in a Python markdown code block. Here you will create the classic [Pascal's triangle](https://en.wikipedia.org/wiki/Pascal%27s_triangle). Your function will be passed the depth of the triangle and you code has to return the corresponding pascal triangle up to that depth. The triangle s...
{"functional": "_inputs = [[1], [5], [10]]\n_outputs = [[[[1]]], [[[1], [1, 1], [1, 2, 1], [1, 3, 3, 1], [1, 4, 6, 4, 1]]], [[[1], [1, 1], [1, 2, 1], [1, 3, 3, 1], [1, 4, 6, 4, 1], [1, 5, 10, 10, 5, 1], [1, 6, 15, 20, 15, 6, 1], [1, 7, 21, 35, 35, 21, 7, 1], [1, 8, 28, 56, 70, 56, 28, 8, 1], [1, 9, 36, 84, 126, 126, 84...
236
397
coding
Solve the programming task below in a Python markdown code block. You are given an array that of arbitrary depth that needs to be nearly flattened into a 2 dimensional array. The given array's depth is also non-uniform, so some parts may be deeper than others. All of lowest level arrays (most deeply nested) will conta...
{"functional": "_inputs = [[[[1]]], [[[1, 2, 3], [4, 5, 6]]], [[[1, 2, 3], [[4, 5], [[6], [7, 8]]]]], [[[[1, 2, 3], [9, 10]], [[4, 5], [6, 7, 8]]]]]\n_outputs = [[[[1]]], [[[1, 2, 3], [4, 5, 6]]], [[[1, 2, 3], [4, 5], [6], [7, 8]]], [[[1, 2, 3], [4, 5], [6, 7, 8], [9, 10]]]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\...
231
314
coding
Solve the programming task below in a Python markdown code block. Alice became interested in periods of integer numbers. We say positive $X$ integer number is periodic with length $L$ if there exists positive integer number $P$ with $L$ digits such that $X$ can be written as $PPPP…P$. For example: $X = 123123123$ is p...
{"inputs": ["3\n991\n", "3\n901\n", "3\n643\n", "10\n86\n", "1\n6789\n", "1\n6789\n", "1\n3968\n", "3\n5248\n"], "outputs": ["992\n", "902\n", "644\n", "1000000000\n", "7777\n", "7777", "4444\n", "100100\n"]}
411
134
coding
Solve the programming task below in a Python markdown code block. A conglomerate consists of $n$ companies. To make managing easier, their owners have decided to merge all companies into one. By law, it is only possible to merge two companies, so the owners plan to select two companies, merge them into one, and continu...
{"inputs": ["1\n4 2 2 3 2\n", "1\n4 2 2 3 2\n", "1\n4 2 2 3 0\n", "1\n4 3 2 3 0\n", "1\n4 3 2 4 0\n", "1\n4 1 2 4 0\n", "1\n4 2 2 2 2\n", "1\n1 2 2 3 0\n"], "outputs": ["0\n", "0", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]}
508
149
coding
Solve the programming task below in a Python markdown code block. Bill Gates is on one of his philanthropic journeys to a village in Utopia. He has brought a box of packets of candies and would like to distribute one packet to each of the children. Each of the packets contains a number of candies. He wants to minimiz...
{"inputs": ["7\n3\n10\n100\n300\n200\n1000\n20\n30\n", "10\n4\n1\n2\n3\n4\n10\n20\n30\n40\n100\n200\n"], "outputs": ["40\n", "10\n"]}
681
83
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an m x n integer matrix heightMap representing the height of each unit cell in a 2D elevation map, return the volume of water it can trap after raining.   Please complete the following python code precisely: ```...
{"functional": "def check(candidate):\n assert candidate(heightMap = [[1,4,3,1,3,2],[3,2,1,3,2,4],[2,3,3,2,3,1]]) == 4\n assert candidate(heightMap = [[3,3,3,3,3],[3,2,2,2,3],[3,2,1,2,3],[3,2,2,2,3],[3,3,3,3,3]]) == 10\n\n\ncheck(Solution().trapRainWater)"}
86
129
coding
Solve the programming task below in a Python markdown code block. You have n distinct points on a plane, none of them lie on OY axis. Check that there is a point after removal of which the remaining points are located on one side of the OY axis. -----Input----- The first line contains a single positive integer n (2 ...
{"inputs": ["2\n8 0\n7 0\n", "2\n1 0\n2 0\n", "2\n8 0\n7 0\n", "2\n1 0\n2 0\n", "2\n1 0\n4 0\n", "2\n1 0\n-1 0\n", "2\n-1 0\n1 0\n", "2\n1 2\n-1 2\n"], "outputs": ["Yes", "Yes", "Yes\n", "Yes\n", "Yes\n", "Yes", "Yes", "Yes"]}
280
132
coding
Solve the programming task below in a Python markdown code block. An array is said to be `hollow` if it contains `3` or more `0`s in the middle that are preceded and followed by the same number of non-zero elements. Furthermore, all the zeroes in the array must be in the middle of the array. Write a function named `i...
{"functional": "_inputs = [[[-1, 0, 0, 0, 3]], [[1, 0, 0, 0, 0]]]\n_outputs = [[True], [False]]\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...
133
186
coding
Solve the programming task below in a Python markdown code block. You get an array of numbers, return the sum of all of the positives ones. Example `[1,-4,7,12]` => `1 + 7 + 12 = 20` Note: if there is nothing to sum, the sum is default to `0`. Also feel free to reuse/extend the following starter code: ```python def p...
{"functional": "_inputs = [[[1, 2, 3, 4, 5]], [[1, -2, 3, 4, 5]], [[-1, 2, 3, 4, -5]], [[]], [[-1, -2, -3, -4, -5]]]\n_outputs = [[15], [13], [9], [0], [0]]\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 ...
95
230
coding
Solve the programming task below in a Python markdown code block. Bear Limak wants to become the largest of bears, or at least to become larger than his brother Bob. Right now, Limak and Bob weigh a and b respectively. It's guaranteed that Limak's weight is smaller than or equal to his brother's weight. Limak eats a ...
{"inputs": ["4 7\n", "4 9\n", "1 1\n", "4 6\n", "1 1\n", "1 2\n", "1 3\n", "1 4\n"], "outputs": ["2\n", "3\n", "1\n", "2\n", "1\n", "2\n", "3\n", "4\n"]}
418
86
coding
Solve the programming task below in a Python markdown code block. Given an array of integers and a target sum, determine the sum nearest to but not exceeding the target that can be created. To create the sum, use any element of your array zero or more times. For example, if $arr=[2,3,4]$ and your target sum is $10$, ...
{"inputs": ["2\n3 12\n1 6 9\n5 9\n3 4 4 4 8\n"], "outputs": ["12\n9\n"]}
425
42
coding
Solve the programming task below in a Python markdown code block. After solving some Graph Theory related problems KBG challenged Sameer to solve the following problem. There is an undirected graph consisting of N vertices numbered from 1 to N. For every pair of vertices u and v (u \neq v) in the graph, there is a un...
{"inputs": ["1\n6 2\n3 6\n2 3\n"], "outputs": ["2\n5\n"]}
524
28
coding
Solve the programming task below in a Python markdown code block. Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. Consider the following function, where + denotes string concatenation. function BinaryConcatenation(integer X, integer Y): string binX = binary repr...
{"inputs": ["2\n2\n5 9\n7\n1 2 4 8 16 64 128"], "outputs": ["12\n127"]}
624
43
coding
Solve the programming task below in a Python markdown code block. in Chefland, there is a very famous street where $N$ types of street food (numbered $1$ through $N$) are offered. For each valid $i$, there are $S_i$ stores that offer food of the $i$-th type, the price of one piece of food of this type is $V_i$ (the sam...
{"inputs": ["2\n3\n4 6 8\n2 6 6\n1 4 3\n1\n7 7 4"], "outputs": ["12\n0"]}
581
43
coding
Solve the programming task below in a Python markdown code block. Door's family is going celebrate Famil Doors's birthday party. They love Famil Door so they are planning to make his birthday cake weird! The cake is a n × n square consisting of equal squares with side length 1. Each square is either empty or consists ...
{"inputs": ["1\n.\n", "1\n.\n", "1\n/\n", "1\n0\n", "1\n-\n", "1\n,\n", "1\n+\n", "1\n*\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]}
404
86
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given positive integers n and target. An array nums is beautiful if it meets the following conditions: nums.length == n. nums consists of pairwise distinct positive integers. There doesn't exist two distinct ...
{"functional": "def check(candidate):\n assert candidate(n = 2, target = 3) == 4\n assert candidate(n = 3, target = 3) == 8\n assert candidate(n = 1, target = 1) == 1\n\n\ncheck(Solution().minimumPossibleSum)"}
141
71
coding
Solve the programming task below in a Python markdown code block. Let's play Fairy Chess! You have an $n\times n$ chessboard. An $\boldsymbol{\mathrm{~S~}}$-leaper is a chess piece which can move from some square $(x_0,y_0)$ to some square $(x_{1},y_{1})$ if $abs(x_0-x_1)+abs(y_0-y_1)\leq s$; however, its movements ar...
{"inputs": ["3\n4 1 1\n....\n.L..\n.P..\n....\n3 2 1\n...\n...\n..L\n4 3 2\n....\n...L\n..P.\nP...\n"], "outputs": ["4\n11\n385\n"]}
714
70
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a binary string s and an integer k, return true if every binary code of length k is a substring of s. Otherwise, return false.   Please complete the following python code precisely: ```python class Solution: ...
{"functional": "def check(candidate):\n assert candidate(s = \"00110110\", k = 2) == True\n assert candidate(s = \"0110\", k = 1) == True\n assert candidate(s = \"0110\", k = 2) == False\n\n\ncheck(Solution().hasAllCodes)"}
82
81