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. The Chessboard Distance for any two points (X_{1}, Y_{1}) and (X_{2}, Y_{2}) on a Cartesian plane is defined as max(|X_{1} - X_{2}|, |Y_{1} - Y_{2}|). You are given two points (X_{1}, Y_{1}) and (X_{2}, Y_{2}). Output their Chessboard Distance. Note ...
{"inputs": ["3\n2 4 5 1\n5 5 5 3\n1 4 3 3\n"], "outputs": ["3\n2\n2\n"]}
coding
513
Solve the programming task below in a Python markdown code block. You are given an integer, $N$. Your task is to print an alphabet rangoli of size $N$. (Rangoli is a form of Indian folk art based on creation of patterns.) Different sizes of alphabet rangoli are shown below: #size 3 ----c---- --c-b-c-- c-b-a-b-c --c-...
{"inputs": ["5\n"], "outputs": ["--------e--------\n------e-d-e------\n----e-d-c-d-e----\n--e-d-c-b-c-d-e--\ne-d-c-b-a-b-c-d-e\n--e-d-c-b-c-d-e--\n----e-d-c-d-e----\n------e-d-e------\n--------e--------\n"]}
coding
567
Solve the programming task below in a Python markdown code block. You are a coach of a group consisting of $n$ students. The $i$-th student has programming skill $a_i$. All students have distinct programming skills. You want to divide them into teams in such a way that: No two students $i$ and $j$ such that $|a_i - a_...
{"inputs": ["1\n1\n100\n", "1\n1\n100\n", "1\n2\n1 5\n", "1\n1\n101\n", "1\n1\n111\n", "1\n2\n1 8\n", "1\n1\n011\n", "1\n1\n010\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n"]}
coding
578
Solve the programming task below in a Python markdown code block. A pair of nodes, $(a,b)$, is a similar pair if the following conditions are true: node $a$ is the ancestor of node $b$ $abs(a-b)\leq k$ Given a tree where each node is labeled from $1$ to $n$, find the number of similar pairs in the tree. For example,...
{"inputs": ["5 2\n3 2\n3 1\n1 4\n1 5\n"], "outputs": ["4\n"]}
coding
514
Solve the programming task below in a Python markdown code block. It's almost summertime, so Big Cat and Little Cat are getting in shape. They decide the core of their fitness plan is to start jogging every day. Their city consists of $N$ intersections connected by $\mbox{M}$ bidirectional roads. The cats decide that ...
{"inputs": ["4 6\n1 2\n2 3\n3 4\n4 1\n1 3\n2 4\n"], "outputs": ["3\n"]}
coding
513
Solve the programming task below in a Python markdown code block. A squarer is a simple and convenient device. You give it some positive integer X and it calculates its square. Leha is implementing a module of this device which is responsible for squaring the numbers consisting of multiple repetitions of one digit. But...
{"inputs": ["3\n1 4\n3 6\n3 5"], "outputs": ["139\n40079781\n32745632"]}
coding
442
Solve the programming task below in a Python markdown code block. Your task is to write a program which reads a sequence of integers and prints mode values of the sequence. The mode value is the element which occurs most frequently. Input A sequence of integers ai (1 ≤ ai ≤ 100). The number of integers is less than...
{"inputs": ["5\n6\n3\n5\n8\n7\n6\n3\n9\n7\n3\n4", "5\n5\n3\n5\n8\n7\n6\n3\n9\n7\n3\n4", "5\n5\n3\n5\n8\n5\n6\n3\n9\n7\n3\n4", "5\n9\n3\n5\n8\n7\n6\n3\n9\n7\n0\n4", "5\n6\n6\n9\n8\n7\n5\n3\n9\n7\n0\n4", "5\n6\n6\n9\n8\n7\n8\n3\n9\n7\n0\n4", "5\n6\n6\n5\n8\n7\n7\n3\n9\n7\n3\n4", "5\n6\n3\n5\n8\n5\n6\n6\n9\n1\n3\n4"], "ou...
coding
130
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given two 0-indexed arrays nums and cost consisting each of n positive integers. You can do the following operation any number of times: Increase or decrease any element of the array nums by 1. The cost of d...
{"functional": "def check(candidate):\n assert candidate(nums = [1,3,5,2], cost = [2,3,1,14]) == 8\n assert candidate(nums = [2,2,2,2,2], cost = [4,2,8,1,3]) == 0\n\n\ncheck(Solution().minCost)"}
coding
127
Solve the programming task below in a Python markdown code block. The only difference between easy and hard versions is the constraints. Vova likes pictures with kittens. The news feed in the social network he uses can be represented as an array of $n$ consecutive pictures (with kittens, of course). Vova likes all the...
{"inputs": ["1 1 1\n7082632\n", "1 1 1\n1027282\n", "1 1 1\n1469884\n", "1 1 1\n99996055\n", "1 1 1\n41731973\n", "1 1 1\n74257449\n", "1 1 1\n69799202\n", "4 3 1\n1 100 1 1\n"], "outputs": ["7082632", "1027282\n", "1469884\n", "99996055", "41731973\n", "74257449\n", "69799202\n", "100\n"]}
coding
499
Solve the programming task below in a Python markdown code block. Hey CodeWarrior, we've got a lot to code today! I hope you know the basic string manipulation methods, because this kata will be all about them. Here we go... ## Background We've got a very long string, containing a bunch of User IDs. This string is...
{"functional": "_inputs = [['uid12345'], [' uidabc '], ['#uidswagger'], ['uidone, uidtwo'], ['uidCAPSLOCK'], ['uid##doublehashtag'], [' uidin name whitespace'], ['uidMultipleuid'], ['uid12 ab, uid#, uidMiXeDcHaRs'], [' uidT#e#S#t# ']]\n_outputs = [[['12345']], [['abc']], [['swagger']], [['one', 'two']], [['capslock...
coding
497
Solve the programming task below in a Python markdown code block. Ekiden competitions are held every year in Aizukuni. The country of Aiz is dotted with N towns, each numbered from 1 to N. Several towns are connected by roads that allow them to come and go directly to each other. You can also follow several roads betwe...
{"inputs": ["4 5\n1 2 2\n1 3 2\n2 3 1\n2 4 2\n3 4 1", "7 9\n2 1 2\n1 3 1\n2 3 2\n2 4 4\n2 6 1\n6 4 1\n3 5 1\n3 5 1\n4 7 3\n5 7 2\n6 7 1", "7 9\n2 1 2\n1 3 1\n2 3 2\n2 4 4\n2 6 1\n6 1 1\n3 5 1\n3 5 1\n4 7 3\n5 7 2\n6 7 1", "7 9\n2 1 2\n1 3 1\n2 3 2\n2 4 4\n2 6 1\n6 4 1\n3 5 1\n3 6 1\n4 7 3\n5 7 2\n6 7 1", "7 9\n2 1 2\n1...
coding
588
Solve the programming task below in a Python markdown code block. You are given an integer N. You have to count the number of distinct tuples (A, B, C, D) with 1 ≤ A, B, C, D ≤ N such that A \cdot B = C \cdot D. Two tuples, say (A, B, C, D) and (E, F, G, H) are considered to be different if at least one of the follow...
{"inputs": ["3\n3\n50\n35"], "outputs": ["15\n10950\n4831"]}
coding
495
Solve the programming task below in a Python markdown code block. Watson asks Sherlock: Given a string S of N 0's and M 1's, how many unique permutations of this string start with 1? Help Sherlock by printing the answer modulo (10^{9}+7). Input Format First line contains T, the number of test cases. Each ...
{"inputs": ["2\n1 1\n2 3\n"], "outputs": ["1\n6\n"]}
coding
305
Solve the programming task below in a Python markdown code block. Let f(X) denote the number of set bits in X. Given integers N and K, construct an array A of length N such that: 0 ≤ A_{i} ≤ K for all (1 ≤ i ≤ N); \sum_{i=1}^{N} A_{i} = K Over all such possible arrays, find the maximum value of \sum_{i=1}^{N} f(A_{i}...
{"inputs": ["2\n1 7\n3 6\n"], "outputs": ["3\n4\n"]}
coding
443
Solve the programming task below in a Python markdown code block. The *beauty* value of an array is defined as the difference between the largest and second largest elements of the array. Note that the largest and second largest elements can have the same value in case of duplicates. For example, *beauty* value of [2,...
{"inputs": ["4\n2\n1 1\n3\n4 2 1\n4\n8 1 7 2\n5\n6 9 4 2 1\n"], "outputs": ["1\n2\n4\n4\n"]}
coding
580
Solve the programming task below in a Python markdown code block. A valid parentheses sequence is a non-empty string where each character is either '(' or ')', which satisfies the following constraint: You can find a way to repeat erasing adjacent pairs of parentheses '()' until it becomes empty. For example, '(())'...
{"inputs": ["1\n()(())()()", "1\n((((()()))", "1\n(()(()()))", "1\n()((()(())", "1\n()()()()()", "1\n((((((()))", "1\n((((()(())", "1\n(((((((())"], "outputs": ["(())\n", "((((()))))\n", "((()))\n", "(((())))\n", "()\n", "((((((()))))))\n", "(((((())))))\n", "(((((((())))))))\n"]}
coding
527
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given two integers representing the numerator and denominator of a fraction, return the fraction in string format. If the fractional part is repeating, enclose the repeating part in parentheses. If multiple answers ar...
{"functional": "def check(candidate):\n assert candidate(numerator = 1, denominator = 2) == \"0.5\"\n assert candidate(numerator = 2, denominator = 1) == \"2\"\n assert candidate(numerator = 4, denominator = 333) == \"0.(012)\"\n\n\ncheck(Solution().fractionToDecimal)"}
coding
120
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a m x n binary matrix mat, find the 0-indexed position of the row that contains the maximum count of ones, and the number of ones in that row. In case there are multiple rows that have the maximum count of ones,...
{"functional": "def check(candidate):\n assert candidate(mat = [[0,1],[1,0]]) == [0,1]\n assert candidate(mat = [[0,0,0],[0,1,1]]) == [1,2]\n assert candidate(mat = [[0,0],[1,1],[0,0]]) == [1,2]\n\n\ncheck(Solution().rowAndMaximumOnes)"}
coding
132
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a 0-indexed array nums consisting of n positive integers. The array nums is called alternating if: nums[i - 2] == nums[i], where 2 <= i <= n - 1. nums[i - 1] != nums[i], where 1 <= i <= n - 1. In one o...
{"functional": "def check(candidate):\n assert candidate(nums = [3,1,3,2,4,3]) == 3\n assert candidate(nums = [1,2,2,2,2]) == 2\n\n\ncheck(Solution().minimumOperations)"}
coding
147
Solve the programming task below in a Python markdown code block. Julius Caesar protected his confidential information by encrypting it using a cipher. Caesar's cipher shifts each letter by a number of letters. If the shift takes you past the end of the alphabet, just rotate back to the front of the alphabet. In the ...
{"inputs": ["11\nmiddle-Outz\n2\n"], "outputs": ["okffng-Qwvb\n"]}
coding
464
Solve the programming task below in a Python markdown code block. The Chef has been hunting for a machine developed to change numbers in a rather peculiar manner. This machine has a fixed number c associated with it and a changing number X. In a single step, the Chef can do the following: First, choose any positive i...
{"inputs": ["3\n1 5\n10 1\n20 4"], "outputs": ["1\n1\n20"]}
coding
442
Solve the programming task below in a Python markdown code block. Airports are being built on a straight road according to a new construction plan. For convenience, imagine a number line on which at different points airports can be positioned. Because a plane can't take off and start landing immediately, there will be ...
{"inputs": ["1\n3 1\n0 0 0\n", "1\n5 4\n1 -1 2 -1 1\n"], "outputs": ["0 1 1\n", "0 2 2 3 3\n"]}
coding
679
Solve the programming task below in a Python markdown code block. Read problems statements in mandarin chinese, russian and vietnamese as well. On the occasion of the birthday, Chef bought a large circular cake and decorated it with k candles placed equally spaced around the circumference of the cake, i.e. the leng...
{"inputs": ["3\n6 1 3\n6 1 4\n10 1 5"], "outputs": ["1\n0\n3"]}
coding
407
Solve the programming task below in a Python markdown code block. # Task The game starts with `n` people standing in a circle. The presenter counts `m` people starting with the first one, and gives `1` coin to each of them. The rest of the players receive `2` coins each. After that, the last person who received `1` co...
{"functional": "_inputs = [[5, 1], [8, 3], [75, 34], [82, 49], [73, 38], [86, 71], [61, 17], [42, 38], [29, 5], [64, 49], [61, 20], [88, 52]]\n_outputs = [[[5, 24]], [[7, 51]], [[35, 4238]], [[48, 5091]], [[61, 3996]], [[10, 6275]], [[26, 3000]], [[12, 1578]], [[28, 740]], [[43, 3327]], [[32, 2922]], [[59, 5856]]]\nimp...
coding
653
Solve the programming task below in a Python markdown code block. Most of the time when rounding a given number, it is customary to round to some multiple of a power of 10. However, there is no reason why we cannot use another multiple to do our rounding to. For example, you could round to the nearest multiple of 7, or...
{"inputs": ["26\n5 10\n4 10\n100 3\n123456 7\n49 7\n158854 50\n822992 101\n691238 345\n682373 49\n643378 53\n328697 62\n446656 228\n368684 130\n530193 371\n864163 325\n708578 207\n915093 485\n711860 28\n234554 366\n309089 25\n595700 393\n10 6\n9 19\n4 10\n11 2\n11 3"], "outputs": ["10\n0\n99\n123459\n49\n158850\n822948...
coding
201
Solve the programming task below in a Python markdown code block. People in the Tomskaya region like magic formulas very much. You can see some of them below. Imagine you are given a sequence of positive integer numbers p_1, p_2, ..., p_{n}. Lets write down some magic formulas:$q_{i} = p_{i} \oplus(i \operatorname{mod...
{"inputs": ["1\n0\n", "1\n0\n", "1\n1\n", "1\n3\n", "1\n5\n", "1\n6\n", "1\n8\n", "1\n2\n"], "outputs": ["0\n", "0", "1\n", "3\n", "5\n", "6\n", "8\n", "2\n"]}
coding
350
Solve the programming task below in a Python markdown code block. Winter is here at the North and the White Walkers are close. John Snow has an army consisting of n soldiers. While the rest of the world is fighting for the Iron Throne, he is going to get ready for the attack of the White Walkers. He has created a meth...
{"inputs": ["3\n3 3 1\n", "3\n3 4 1\n", "3\n6 4 1\n", "3\n6 6 1\n", "3\n2 4 1\n", "3\n4 3 2\n", "3\n2 6 1\n", "3\n6 9 1\n"], "outputs": ["12\n", "7\n", "14\n", "24\n", "10\n", "13\n", "12\n", "21\n"]}
coding
467
Please solve the programming task below using a self-contained code snippet in a markdown code block. A 3 x 3 magic square is a 3 x 3 grid filled with distinct numbers from 1 to 9 such that each row, column, and both diagonals all have the same sum. Given a row x col grid of integers, how many 3 x 3 magic square subgr...
{"functional": "def check(candidate):\n assert candidate(grid = [[4,3,8,4],[9,5,1,9],[2,7,6,2]]) == 1\n assert candidate(grid = [[8]]) == 0\n\n\ncheck(Solution().numMagicSquaresInside)"}
coding
146
Solve the programming task below in a Python markdown code block. Три брата договорились о встрече. Пронумеруем братьев следующим образом: пусть старший брат имеет номер 1, средний брат имеет номер 2, а младший брат — номер 3. Когда пришло время встречи, один из братьев опоздал. По заданным номерам двух братьев, кото...
{"inputs": ["3 1\n", "2 1\n", "2 3\n", "1 2\n", "1 3\n", "3 2\n"], "outputs": ["2\n", "3\n", "1\n", "3\n", "2\n", "1\n"]}
coding
246
Solve the programming task below in a Python markdown code block. We have a sequence of N integers: x=(x_0,x_1,\cdots,x_{N-1}). Initially, x_i=0 for each i (0 \leq i \leq N-1). Snuke will perform the following operation exactly M times: * Choose two distinct indices i, j (0 \leq i,j \leq N-1,\ i \neq j). Then, replac...
{"inputs": ["0 2", "5 7", "6 7", "3 7", "3 3", "3 6", "2 5", "5 6"], "outputs": ["0\n", "11600\n", "63008\n", "169\n", "37\n", "127\n", "6\n", "6685\n"]}
coding
309
Solve the programming task below in a Python markdown code block. Given the values at the leaf nodes of a complete binary tree. The total number of nodes in the binary tree, is also given. Sum of the values at both the children of a node is equal to the value of the node itself. You can add any value or subtract any va...
{"inputs": ["1:\nInput:\n1\n50"], "outputs": ["0"]}
coding
411
Solve the programming task below in a Python markdown code block. This is the easy version of the problem. The only difference is that in this version $n \leq 2000$. You can make hacks only if both versions of the problem are solved. There are $n$ potions in a line, with potion $1$ on the far left and potion $n$ on th...
{"inputs": ["1\n0\n", "6\n4 -4 1 -3 1 -3\n", "12\n-3 -3 -7 -7 -1 -7 3 3 -2 -1 0 -7\n"], "outputs": ["1", "5", "5"]}
coding
362
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an integer n. You have an n x n binary grid grid with all values initially 1's except for some indices given in the array mines. The ith element of the array mines is defined as mines[i] = [xi, yi] where...
{"functional": "def check(candidate):\n assert candidate(n = 5, mines = [[4,2]]) == 2\n assert candidate(n = 1, mines = [[0,0]]) == 0\n\n\ncheck(Solution().orderOfLargestPlusSign)"}
coding
232
Solve the programming task below in a Python markdown code block. In the year 4242, the language Haskell has evolved so much that it has become an AI. It can solve very challenging problems, in very little time. Humanity is worried that Haskell will take over the world. All hopes remain tied to the Competitive Programm...
{"inputs": ["1\n1 1"], "outputs": ["1"]}
coding
303
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\"], ...
coding
188
Solve the programming task below in a Python markdown code block. Alice thinks of a non-decreasing sequence of non-negative integers and wants Bob to guess it by providing him the set of all its K-sums with repetitions. What is this? Let the sequence be {A[1], A[2], ..., A[N]} and K be some positive integer that both...
{"inputs": ["3\n1 3\n3\n2 2\n12 34 56\n3 2\n2 3 4 4 5 6\n"], "outputs": ["1\n6 28\n1 2 3\n"]}
coding
747
Solve the programming task below in a Python markdown code block. Little Petya loves inequations. Help him find n positive integers a1, a2, ..., an, such that the following two conditions are satisfied: * a12 + a22 + ... + an2 ≥ x * a1 + a2 + ... + an ≤ y Input The first line contains three space-separated integ...
{"inputs": ["1 1 1\n", "5 1 4\n", "2 1 1\n", "2 3 2\n", "10 3 8\n", "1 5 10\n", "5 37 10\n", "100 1 1\n"], "outputs": ["1\n", "-1", "-1", "-1\n", "-1", "10\n", "1\n1\n1\n1\n6\n", "-1"]}
coding
255
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an array points where points[i] = [xi, yi] is the coordinates of the ith point on a 2D plane. Multiple points can have the same coordinates. You are also given an array queries where queries[j] = [xj, yj...
{"functional": "def check(candidate):\n assert candidate(points = [[1,3],[3,3],[5,3],[2,2]], queries = [[2,3,1],[4,3,1],[1,1,2]]) == [3,2,2]\n assert candidate(points = [[1,1],[2,2],[3,3],[4,4],[5,5]], queries = [[1,2,2],[2,2,2],[4,3,2],[4,3,3]]) == [2,3,2,4]\n\n\ncheck(Solution().countPoints)"}
coding
181
Solve the programming task below in a Python markdown code block. Write a function that accepts a string, and returns true if it is in the form of a phone number. Assume that any integer from 0-9 in any of the spots will produce a valid phone number. Only worry about the following format: (123) 456-7890 (don't forge...
{"functional": "_inputs = [['(123) 456-7890'], ['(1111)555 2345'], ['(098) 123 4567'], ['(123)456-7890'], ['abc(123)456-7890'], ['(123)456-7890abc'], ['abc(123)456-7890abc'], ['abc(123) 456-7890'], ['(123) 456-7890abc'], ['abc(123) 456-7890abc']]\n_outputs = [[True], [False], [False], [False], [False], [False], [False]...
coding
185
Solve the programming task below in a Python markdown code block. Snuke has a blackboard and a set S consisting of N integers. The i-th element in S is S_i. He wrote an integer X on the blackboard, then performed the following operation N times: * Choose one element from S and remove it. * Let x be the number written...
{"inputs": ["2 17\n3 7", "2 20\n6 3", "2 19\n3 7", "2 19\n3 11", "2 12\n6 11", "5 193\n5 13 7 5 4", "5 82\n22 11 6 7 13", "5 82\n27 11 6 7 13"], "outputs": ["2\n", "4\n", "3", "3\n", "1\n", "198\n", "516\n", "456\n"]}
coding
373
Solve the programming task below in a Python markdown code block. It's your birthday today! So, you ask your dad to buy a brand new bicycle. But your dad knows you are weak in math. Hence he gives you the following task. If you solve it, he will purchase the bicycle you want! The task is: You are given a binary strin...
{"inputs": ["2\n3 1\n7 2"], "outputs": ["2\n7"]}
coding
478
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an integer array ribbons, where ribbons[i] represents the length of the ith ribbon, and an integer k. You may cut any of the ribbons into any number of segments of positive integer lengths, or perform no...
{"functional": "def check(candidate):\n assert candidate(ribbons = [9,7,5], k = 3) == 5\n assert candidate(ribbons = [7,5,9], k = 4) == 4\n assert candidate(ribbons = [5,7,9], k = 22) == 0\n\n\ncheck(Solution().maxLength)"}
coding
250
Solve the programming task below in a Python markdown code block. Complete the solution so that it strips all text that follows any of a set of comment markers passed in. Any whitespace at the end of the line should also be stripped out. **Example:** Given an input string of: ``` apples, pears # and bananas grapes b...
{"functional": "_inputs = [['apples, pears # and bananas\\ngrapes\\nbananas !apples', ['#', '!']], ['a #b\\nc\\nd $e f g', ['#', '$']], ['apples, pears # and bananas\\ngrapes\\nbananas !#apples', ['#', '!']], ['apples, pears # and bananas\\ngrapes\\nbananas #!apples', ['#', '!']], ['apples, pears # and bananas\\ngrapes...
coding
181
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin Chinese and Russian. Grapes of Coderpur are very famous. Devu went to the market and saw that there were N people selling grapes. He didn’t like it because things were not very structured. So, he gave a task to Dhi...
{"inputs": ["2\n2 1\n8 1\n3 7\n2 4 7", "2\n2 2\n3 8\n3 7\n8 16 7", "2\n2 1\n5 8\n3 7\n8 16 7", "2\n2 2\n5 8\n2 7\n7 16 7", "2\n2 2\n5 8\n3 7\n8 11 7", "2\n2 2\n5 1\n2 7\n8 16 7", "2\n2 2\n5 8\n2 7\n8 21 7", "2\n2 3\n5 8\n3 7\n8 11 7"], "outputs": ["0\n8\n", "1\n3\n", "0\n3\n", "1\n2\n", "1\n4\n", "2\n3\n", "1\n1\n", "2...
coding
537
Solve the programming task below in a Python markdown code block. My little sister came back home from school with the following task: given a squared sheet of paper she has to cut it in pieces which, when assembled, give squares the sides of which form an increasing sequence of numbers. At the beginning it was lot of ...
{"functional": "_inputs = [[12], [6], [50], [44], [625], [5], [7100], [123456], [1234567], [7654321], [4], [7654322]]\n_outputs = [[[1, 2, 3, 7, 9]], [None], [[1, 3, 5, 8, 49]], [[2, 3, 5, 7, 43]], [[2, 5, 8, 34, 624]], [[3, 4]], [[2, 3, 5, 119, 7099]], [[1, 2, 7, 29, 496, 123455]], [[2, 8, 32, 1571, 1234566]], [[6, 10...
coding
580
Solve the programming task below in a Python markdown code block. Given a tree T with n nodes, how many subtrees (T') of T have at most K edges connected to (T - T')? Input Format The first line contains two integers n and K followed by n-1 lines each containing two integers a & b denoting that there's an edge betwe...
{"inputs": ["3 1\n2 1\n2 3\n"], "outputs": ["6\n"]}
coding
272
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a date, return the corresponding day of the week for that date. The input is given as three integers representing the day, month and year respectively. Return the answer as one of the following values {"Sunday",...
{"functional": "def check(candidate):\n assert candidate(day = 31, month = 8, year = 2019) == \"Saturday\"\n assert candidate(day = 18, month = 7, year = 1999) == \"Sunday\"\n assert candidate(day = 15, month = 8, year = 1993) == \"Sunday\"\n\n\ncheck(Solution().dayOfTheWeek)"}
coding
120
Solve the programming task below in a Python markdown code block. The average miner Vaganych took refresher courses. As soon as a miner completes the courses, he should take exams. The hardest one is a computer test called "Testing Pants for Sadness". The test consists of n questions; the questions are to be answered ...
{"inputs": ["1\n18\n", "1\n24\n", "1\n29\n", "1\n46\n", "1\n27\n", "1\n10\n", "2\n2 1\n", "2\n2 2\n"], "outputs": ["18\n", "24\n", "29\n", "46\n", "27\n", "10", "3\n", "5"]}
coding
545
Solve the programming task below in a Python markdown code block. Given a sequence of $n$ integers, $p(1),p(2),...,p(n)$ where each element is distinct and satisfies $1\leq p(x)\leq n$. For each $\boldsymbol{x}$ where $1\leq x\leq n$, that is $\boldsymbol{x}$ increments from $\mbox{1}$ to $n$, find any integer $y$ such...
{"inputs": ["3\n2 3 1\n", "5\n4 3 5 1 2\n"], "outputs": ["2\n3\n1\n", "1\n3\n5\n4\n2\n"]}
coding
693
Solve the programming task below in a Python markdown code block. A sequence of $n$ numbers is called a permutation if it contains all integers from $1$ to $n$ exactly once. For example, the sequences [$3, 1, 4, 2$], [$1$] and [$2,1$] are permutations, but [$1,2,1$], [$0,1$] and [$1,3,4$] — are not. Polycarp lost his ...
{"inputs": ["1\n1 2\n4\n", "1\n2 4\n5 1\n", "1\n3 13\n4 1 3\n", "1\n7 489\n5 29 12 16 25 36 18\n", "2\n1 9\n2\n9 9\n11 6 5 13 7 10 2 3 12\n", "5\n3 13\n3 1 4\n1 1\n1\n3 3\n1 4 2\n2 1\n4 3\n5 6\n1 2 3 4 5\n", "1\n50 870\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 3...
coding
695
Solve the programming task below in a Python markdown code block. Let's arrange a deck of cards. Your task is to sort totally n cards. A card consists of a part of a suit (S, H, C or D) and an number. Write a program which sorts such cards based on the following pseudocode: Partition(A, p, r) 1 x = A[r] 2 i = p-1 3 f...
{"inputs": ["2\nS 1\nH 2", "2\nS 0\nH 1", "2\nS 2\nH 2", "2\nS 1\nH 1", "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 1", "6\nD 3\nH 2\nD 1\nS 3\nC 2\nC 2", "6\nD 3\nH 2\nC 1\nS 3\nC 2\nC 2", "6\nD 5\nH 2\nC 1\nS 3\nC 2\nC 2"], "outputs": ["Stable\nS 1\nH 2\n", "Stable\nS 0\nH 1\n", "Stable\nS 2\nH 2\n", "Stable\nS 1\nH 1", "Not stab...
coding
485
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a sorted integer array nums and an integer n, add/patch elements to the array such that any number in the range [1, n] inclusive can be formed by the sum of some elements in the array. Return the minimum number ...
{"functional": "def check(candidate):\n assert candidate(nums = [1,3], n = 6) == 1\n assert candidate(nums = [1,5,10], n = 20) == 2\n assert candidate(nums = [1,2,2], n = 5) == 0\n\n\ncheck(Solution().minPatches)"}
coding
105
Solve the programming task below in a Python markdown code block. Vasya tries to break in a safe. He knows that a code consists of n numbers, and every number is a 0 or a 1. Vasya has made m attempts to enter the code. After each attempt the system told him in how many position stand the right numbers. It is not said i...
{"inputs": ["6 1\n101011 2\n", "6 2\n000000 2\n010100 4\n", "7 2\n1011111 2\n1001111 1\n", "6 3\n000100 2\n010100 4\n111100 0\n", "6 3\n000000 2\n010100 4\n111100 2\n", "6 3\n000000 2\n010100 4\n111100 0\n", "8 3\n00111100 5\n10100111 2\n10110101 2\n", "6 4\n000110 2\n010001 2\n001111 2\n001100 2\n"], "outputs": ["15",...
coding
387
Solve the programming task below in a Python markdown code block. Animesh and Mohit are playing a game. They have $N$ balls in front of them. All the balls are numbered, not necessarily in any order. Animesh picks a set of ${K}$ balls from the lot each time, checks this set, puts it back into the lot, and repeats this ...
{"inputs": ["4 2\n10 20 30 40\n"], "outputs": ["100\n"]}
coding
406
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, both of length n. You can choose two integers left and right where 0 <= left <= right < n and swap the subarray nums1[left...right] with the subarray nums2[l...
{"functional": "def check(candidate):\n assert candidate(nums1 = [60,60,60], nums2 = [10,90,10]) == 210\n assert candidate(nums1 = [20,40,20,70,30], nums2 = [50,20,50,40,20]) == 220\n assert candidate(nums1 = [7,11,13], nums2 = [1,1,1]) == 31\n\n\ncheck(Solution().maximumsSplicedArray)"}
coding
292
Solve the programming task below in a Python markdown code block. Nickname Generator Write a function, `nicknameGenerator` that takes a string name as an argument and returns the first 3 or 4 letters as a nickname. If the 3rd letter is a consonant, return the first 3 letters. If the 3rd letter is a vowel, return the...
{"functional": "_inputs = [['Jimmy'], ['Samantha'], ['Sam'], ['Kayne'], ['Melissa'], ['James'], ['Gregory'], ['Jeannie'], ['Kimberly'], ['Timothy'], ['Dani'], ['Saamy'], ['Saemy'], ['Saimy'], ['Saomy'], ['Saumy'], ['Boyna'], ['Kiyna'], ['Sayma'], ['Ni'], ['Jam'], ['Suv']]\n_outputs = [['Jim'], ['Sam'], ['Error: Name to...
coding
176
Solve the programming task below in a Python markdown code block. Two words rhyme if their last 3 letters are a match. Given N words, print the test case number (of the format Case : num) followed by the rhyming words in separate line adjacent to each other. The output can be in anyorder. -----Input----- First line c...
{"inputs": ["3\n3\nnope qwerty hope\n5\nbrain drain request grain nest\n4\nthese words dont rhyme"], "outputs": ["Case : 1\nhope nope\nqwerty\nCase : 2\nbrain drain grain\nnest request\nCase : 3\nthese\ndont\nwords\nrhyme"]}
coding
326
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin Chinese , Russian and Vietnamese as well. Tic-Tac-Toe used to be Chef's favourite game during his childhood. Reminiscing in his childhood memories, he decided to create his own "Tic-Tac-Toe", with rules being simila...
{"inputs": ["1\n4 4\nXOXO\nOX..\nXO..\nOXOX", "1\n4 4\nXOXO\nOX..\nXO..\nOXOX", "3\n3 3\nXOX\nO.O\nXOX\n3 1\n...\n...\n...\n3 2\n...\n...\n...", "3\n3 3\nXOX\nO.O\nXOX\n3 1\n...\n...\n...\n3 2\n...\n...\n..."], "outputs": ["YES", "YES", "YES\nYES\nNO", "YES\nYES\nNO"]}
coding
681
Solve the programming task below in a Python markdown code block. Assume that you started to store items in progressively expanding square location, like this for the first 9 numbers: ``` 05 04 03 06 01 02 07 08 09 ``` And like this for the expanding to include up to the first 25 numbers: ``` 17 16 15 14 13 18 05 04...
{"functional": "_inputs = [[1], [5], [25], [30], [50]]\n_outputs = [[1], [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): ...
coding
430
Solve the programming task below in a Python markdown code block. Tattah's youngest brother, Tuftuf, is new to programming. Since his older brother is such a good programmer, his biggest dream is to outshine him. Tuftuf is a student at the German University in Cairo (GUC) where he learns to write programs in Gava. To...
{"inputs": ["2\n1 2\n", "2\n1 1\n", "2\n2 1\n", "2\n1 3\n", "2\n0 1\n", "2\n0 2\n", "2\n0 4\n", "2\n0 7\n"], "outputs": ["NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n"]}
coding
390
Solve the programming task below in a Python markdown code block. Kundu is true tree lover. Tree is a connected graph having N vertices and N-1 edges. Today when he got a tree, he colored each edge with one of either red(r) or black(b) color. He is interested in knowing how many triplets(a,b,c) of vertices are there ,...
{"inputs": ["5\n1 2 b\n2 3 r\n3 4 r\n4 5 b\n"], "outputs": ["4\n"]}
coding
432
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an integer num, return a string of its base 7 representation.   Please complete the following python code precisely: ```python class Solution: def convertToBase7(self, num: int) -> str: ```
{"functional": "def check(candidate):\n assert candidate(num = 100) == \"202\"\n assert candidate(num = -7) == \"-10\"\n\n\ncheck(Solution().convertToBase7)"}
coding
64
Solve the programming task below in a Python markdown code block. In one of the games Arkady is fond of the game process happens on a rectangular field. In the game process Arkady can buy extensions for his field, each extension enlarges one of the field sizes in a particular number of times. Formally, there are n exte...
{"inputs": ["5 5 1 2 3\n2 2 3\n", "3 4 1 1 3\n2 3 2\n", "5 5 1 2 3\n2 2 2\n", "5 5 1 2 3\n2 2 3\n", "3 4 1 1 3\n2 3 2\n", "1 1 1 1 1\n100000\n", "1 1 1 1 1\n100000\n", "3 3 2 4 4\n2 5 4 10\n"], "outputs": ["-1\n", "3\n", "-1\n", "-1", "3", "0\n", "0", "1\n"]}
coding
502
Solve the programming task below in a Python markdown code block. You are given a string S consisting of lowercase English letters. Determine whether all the characters in S are different. -----Constraints----- - 2 ≤ |S| ≤ 26, where |S| denotes the length of S. - S consists of lowercase English letters. -----Input-...
{"inputs": ["np", "mp", "pm", "pl", "ol", "lo", "nl", "ml"], "outputs": ["yes\n", "yes\n", "yes\n", "yes\n", "yes\n", "yes\n", "yes\n", "yes\n"]}
coding
120
Solve the programming task below in a Python markdown code block. # Task Write a function that accepts `msg` string and returns local tops of string from the highest to the lowest. The string's tops are from displaying the string in the below way: ``` 7891012 ...
{"functional": "_inputs = [[''], ['abcde'], ['123456789abcdefghijklmnopqrstuwyxvzABCDEFGHIJKLMNOPQRSTU'], ['123456789abcdefghijklmnopqrstuwyxvzABCDEFGHIJKLMNOPQRSTUWvXYZ123456789012345678910123']]\n_outputs = [[''], ['cd'], ['TUABCDElmnoabc34'], ['7891012TUWvXYABCDElmnoabc34']]\nimport math\ndef _deep_eq(a, b, tol=1e-5...
coding
433
Solve the programming task below in a Python markdown code block. I, Fischl, Prinzessin der Verurteilung, descend upon this land by the call of fate an — Oh, you are also a traveler from another world? Very well, I grant you permission to travel with me. It is no surprise Fischl speaks with a strange choice of words. ...
{"inputs": ["1\n25\nabcdefghijklmnopqrstuvwxy\n", "1\n25\nyxwvutsrqponmlkjihgfedcba\n", "1\n25\nabcdefghijklmnooqrstuvwxy\n", "1\n25\nyxwvutrrqponmlkjihgfedcba\n", "1\n25\nyxwvutsrlponmqkjihgfedcba\n", "1\n41\nsugimotomikasaackermannelectromasterjsoap\n", "1\n41\nsugimotomikasaacjermannelectromasterjsoap\n", "1\n21\nsu...
coding
498
Solve the programming task below in a Python markdown code block. There are N strings of lowercase alphabet only. The i-th string is S_i. Every string is unique. Provide answers for the Q queries below. The i-th query has the following format: Query: An integer k_i and a string p_{i,1}p_{i,2}...p_{i,26} that results ...
{"inputs": ["5\naa\nabbaa\nabbba\naaab\naaaaaba\n5\n1 abcdefghijklmnopqrstuvwxyz\n2 bacdefghijklmnopqrstuvwxyz\n3 abcdefghijklmnopqrstuvwxyz\n4 bacdefghijklmnopqrsttvwxyz\n5 abcdefghijklmnopqrstuvwxyz", "5\naa\nabbaa\nabbba\naaab\naaaaaba\n5\n1 abcdefghijklmnopqrstuvwxyz\n2 bacdefghijklmnopqrstuvwxyz\n3 abcdefghijklmno...
coding
607
Solve the programming task below in a Python markdown code block. IT City company developing computer games decided to upgrade its way to reward its employees. Now it looks the following way. After a new game release users start buying it actively, and the company tracks the number of sales with precision to each trans...
{"inputs": ["1\n", "1\n", "0\n", "9\n", "12\n", "18\n", "15\n", "27\n"], "outputs": ["1", "1\n", "0\n", "1\n", "2", "4\n", "3\n", "6\n"]}
coding
238
Solve the programming task below in a Python markdown code block. A string is called *boring* if all the characters of the string are same. You are given a string S of length N, consisting of lowercase english alphabets. Find the length of the longest *boring* substring of S which occurs more than once. Note that if ...
{"inputs": ["4\n3\naaa\n3\nabc\n5\nbcaca\n6\ncaabaa\n"], "outputs": ["2\n0\n1\n2\n"]}
coding
498
Solve the programming task below in a Python markdown code block. A Sumo wrestling championship is scheduled to be held this winter in the HackerCity where N wrestlers from different parts of the world are going to participate. The rules state that two wrestlers can fight against each other if and only if the differenc...
{"inputs": ["5 2\n1 3 4 3 0\n3\n0 1\n1 3\n0 4\n"], "outputs": ["1\n3\n6\n"]}
coding
539
Solve the programming task below in a Python markdown code block. Takahashi has N cards. The i-th of these cards has an integer A_i written on it. Takahashi will choose an integer K, and then repeat the following operation some number of times: - Choose exactly K cards such that the integers written on them are all di...
{"inputs": ["3\n2 2 2", "3\n2 2 1", "3\n2 1 2", "3\n2 1 2\n", "4\n1 3 1 3", "4\n1 3 3 2", "4\n2 3 2 2", "4\n2 3 4 1"], "outputs": ["3\n0\n0\n", "3\n1\n0\n", "3\n1\n0", "3\n1\n0\n", "4\n2\n0\n0\n", "4\n2\n1\n0\n", "4\n1\n0\n0\n", "4\n2\n1\n1\n"]}
coding
325
Solve the programming task below in a Python markdown code block. To write a research paper, you should definitely follow the structured format. This format, in many cases, is strictly defined, and students who try to write their papers have a hard time with it. One of such formats is related to citations. If you refe...
{"inputs": ["5\n1 1 3 5 6\n3\n7 8 9\n0", "5\n1 1 6 5 6\n3\n7 8 9\n0", "5\n1 1 6 4 6\n3\n7 8 9\n0", "5\n1 1 6 4 9\n3\n7 8 9\n0", "5\n1 1 2 4 9\n3\n7 8 9\n0", "5\n1 2 2 4 9\n3\n7 8 9\n0", "5\n1 2 3 5 6\n3\n3 8 9\n0", "5\n1 1 3 5 6\n3\n8 8 9\n0"], "outputs": ["1 1 3 5-6\n7-9\n", "1 1 6 5-6\n7-9\n", "1 1 6 4 6\n7-9\n", "1 ...
coding
432
Solve the programming task below in a Python markdown code block. problem JOI City will hold a large-scale exposition. There are two themes for this exposition, and each of the N exhibition facilities in JOI City will exhibit on one of the two themes. The location of the facility is represented by plane coordinates ...
{"inputs": ["5\n0 0\n0 0\n5 0\n0 0\n0 1", "5\n0 0\n0 0\n5 1\n0 0\n0 0", "5\n-2 0\n1 0\n0 0\n0 2\n-1 1", "5\n-2 0\n1 0\n0 -2\n0 2\n-1 1", "5\n0 0\n2 0\n0 -1\n-2 6\n-4 2", "5\n0 1\n2 1\n0 -1\n-2 4\n-4 1", "5\n-2 0\n1 0\n0 -1\n0 2\n-1 1", "5\n-2 0\n2 0\n0 -1\n0 2\n-1 1"], "outputs": ["1\n", "0\n", "3\n", "4\n", "6\n", "5\...
coding
614
Solve the programming task below in a Python markdown code block. Move the first letter of each word to the end of it, then add "ay" to the end of the word. Leave punctuation marks untouched. ## Examples ```python pig_it('Pig latin is cool') # igPay atinlay siay oolcay pig_it('Hello world !') # elloHay orldway ! ...
{"functional": "_inputs = [['Pig latin is cool'], ['This is my string']]\n_outputs = [['igPay atinlay siay oolcay'], ['hisTay siay ymay tringsay']]\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 isins...
coding
202
Solve the programming task below in a Python markdown code block. A Smith number is a composite number, the sum of whose digits is the sum of the digits of its prime factors obtained as a result of prime factorization (excluding ${1}$). The first few such numbers are ${4}$, $22$, $27$, $58$, $85$, ${94}$, and ${121}$. ...
{"inputs": ["378\n"], "outputs": ["1\n"]}
coding
450
Solve the programming task below in a Python markdown code block. Check Tutorial tab to know how to to solve. You are given a string $\boldsymbol{s}$ consisting only of digits 0-9, commas ,, and dots . Your task is to complete the regex_pattern defined below, which will be used to re.split() all of the , and . symb...
{"inputs": ["100,000,000.000\n"], "outputs": ["100\n000\n000\n000\n"]}
coding
146
Solve the programming task below in a Python markdown code block. .task { background: #fff; color: #333; padding: 25px; box-sizing: border-box; font-family: Comfortaa, sans-serif !important; position: relative; } .task code, .task_code { display: inline-block; padding: 0; border-radius: 2px; margin:...
{"functional": "_inputs = [[10]]\n_outputs = [[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 return all(_deep_eq(...
coding
606
Solve the programming task below in a Python markdown code block. Given a sequence of N elements, Chef defines a function F(i) (1 ≤ i ≤ N) as the median of the first i elements of the sequence. Chef wants to get a *permutation* P of length N such that P_{i} = F(i) \forall 1 ≤ i ≤ N. Can you help Chef in achieving this...
{"inputs": ["3\n1\n2\n3\n"], "outputs": ["1\n2 1 \n3 1 2"]}
coding
595
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a non-negative integer x, return the square root of x rounded down to the nearest integer. The returned integer should be non-negative as well. You must not use any built-in exponent function or operator. For e...
{"functional": "def check(candidate):\n assert candidate(x = 4) == 2\n assert candidate(x = 8) == 2\n\n\ncheck(Solution().mySqrt)"}
coding
117
Solve the programming task below in a Python markdown code block. Failed Filter - Bug Fixing #3 Oh no, Timmy's filter doesn't seem to be working? Your task is to fix the FilterNumber function to remove all the numbers from the string. Also feel free to reuse/extend the following starter code: ```python def filter_numbe...
{"functional": "_inputs = [['test123'], ['a1b2c3'], ['aa1bb2cc3dd'], ['CodeWars'], ['99234']]\n_outputs = [['test'], ['abc'], ['aabbccdd'], ['CodeWars'], ['']]\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...
coding
75
Solve the programming task below in a Python markdown code block. Pasha has many hamsters and he makes them work out. Today, n hamsters (n is even) came to work out. The hamsters lined up and each hamster either sat down or stood up. For another exercise, Pasha needs exactly $\frac{n}{2}$ hamsters to stand up and the ...
{"inputs": ["2\nXX\n", "2\nXx\n", "2\nxx\n", "2\nXx\n", "2\nxX\n", "2\nxX\n", "2\nXx\n", "2\nxx\n"], "outputs": ["1\nxX\n", "0\nXx\n", "1\nXx\n", "0\nXx\n", "0\nxX\n", "0\nxX\n", "0\nXx\n", "1\nXx\n"]}
coding
298
Solve the programming task below in a Python markdown code block. A piece of paper contains an array of n integers a1, a2, ..., an. Your task is to find a number that occurs the maximum number of times in this array. However, before looking for such number, you are allowed to perform not more than k following operatio...
{"inputs": ["1 0\n0\n", "1 1\n0\n", "1 1\n1\n", "1 2\n0\n", "1 2\n1\n", "1 3\n0\n", "1 0\n1\n", "3 4\n5 5 5\n"], "outputs": ["1 0\n", "1 0\n\n", "1 1\n\n", "1 0\n\n", "1 1\n\n", "1 0\n\n", "1 1\n\n", "3 5\n"]}
coding
556
Solve the programming task below in a Python markdown code block. Polycarp analyzes the prices of the new berPhone. At his disposal are the prices for $n$ last days: $a_1, a_2, \dots, a_n$, where $a_i$ is the price of berPhone on the day $i$. Polycarp considers the price on the day $i$ to be bad if later (that is, a d...
{"inputs": ["5\n6\n3 9 2 6 7 5\n1\n1000000\n2\n2 1\n10\n31 5 59 26 53 58 97 93 23 84\n7\n3 2 1 2 3 4 5\n", "5\n6\n3 5 4 6 7 4\n1\n1000000\n2\n2 0\n10\n2 41 59 26 53 58 97 93 23 84\n7\n3 2 1 2 3 4 5\n", "5\n6\n3 9 2 6 7 5\n1\n1000000\n2\n2 1\n10\n31 5 59 26 53 58 97 93 23 84\n7\n3 2 1 2 4 4 5\n", "5\n6\n3 9 4 6 7 5\n1\n...
coding
523
Solve the programming task below in a Python markdown code block. Imagine you have an infinite 2D plane with Cartesian coordinate system. Some of the integral points are blocked, and others are not. Two integral points A and B on the plane are 4-connected if and only if: * the Euclidean distance between A and B is o...
{"inputs": ["0\n", "9\n", "8\n", "4\n", "7\n", "6\n", "5\n", "2\n"], "outputs": ["1\n", "48\n", "44\n", "20\n", "36\n", "32\n", "28\n", "8\n"]}
coding
267
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a binary tree, determine if it is height-balanced.   Please complete the following python code precisely: ```python # Definition for a binary tree node. # class TreeNode: # def __init__(self, val=0, left=Non...
{"functional": "def check(candidate):\n assert candidate(root = tree_node([3,9,20,None,None,15,7])) == True\n assert candidate(root = tree_node([1,2,2,3,3,None,None,4,4])) == False\n assert candidate(root = tree_node([])) == True\n\n\ncheck(Solution().isBalanced)"}
coding
114
Solve the programming task below in a Python markdown code block. At the annual meeting of Board of Directors of Acme Inc. If everyone attending shakes hands exactly one time with every other attendee, how many handshakes are there? Example $n=3$ There are $3$ attendees, ${p1}$, $p2$ and $p3$. ${p1}$ shakes han...
{"inputs": ["2\n1\n2\n"], "outputs": ["0\n1\n"]}
coding
280
Solve the programming task below in a Python markdown code block. Given n and m, calculate 1^{1} + 2^{2} + 3^{3} + ... + n^{n} modulo m. ------ Input ------ The first line contains 1 ≤ t ≤ 10, the number of test cases. Then the test case definitions follow. Each test case is of the form: 1 ≤ n 10^{18}, 1 ≤ m ≤ 2000...
{"inputs": ["6\n1 100000\n2 100000\n3 100000\n4 100000\n5 100000\n6 100000"], "outputs": ["1\n5\n32\n288\n3413\n50069"]}
coding
220
Solve the programming task below in a Python markdown code block. You are given a bracket sequence consisting of $n$ characters '(' and/or )'. You perform several operations with it. During one operation, you choose the shortest prefix of this string (some amount of first characters of the string) that is good and rem...
{"inputs": ["1\n14\n()(((())((()))\n", "1\n15\n((((()))))(((((\n", "1\n16\n((((()))))((((((\n", "1\n18\n()()())(())(())(()\n", "5\n2\n()\n3\n())\n4\n((((\n5\n)((()\n6\n)((()(\n", "5\n3\n)()\n8\n)()()(((\n4\n(()(\n5\n(())(\n6\n))((()\n", "8\n3\n)()\n8\n)()()(((\n4\n(()(\n5\n(())(\n6\n))((()\n5\n))())\n1\n)\n2\n)(\n"], "...
coding
508
Solve the programming task below in a Python markdown code block. In this Kata, you will be given a number and your task will be to return the nearest prime number. ```Haskell solve(4) = 3. The nearest primes are 3 and 5. If difference is equal, pick the lower one. solve(125) = 127 ``` We'll be testing for numbers ...
{"functional": "_inputs = [[3], [11], [4], [110], [1110], [3000], [35000], [350000], [3500000], [10000000000]]\n_outputs = [[3], [11], [3], [109], [1109], [2999], [34981], [350003], [3499999], [10000000019]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n retur...
coding
186
Solve the programming task below in a Python markdown code block. There are n lights aligned in a row. These lights are numbered 1 to n from left to right. Initially some of the lights are switched on. Shaass wants to switch all the lights on. At each step he can switch a light on (this light should be switched off at ...
{"inputs": ["3 1\n1\n", "1 1\n1\n", "1 1\n1\n", "5 1\n1\n", "4 1\n1\n", "3 1\n1\n", "4 2\n1 4\n", "4 2\n1 3\n"], "outputs": ["1\n", "1\n", "1", "1\n", "1\n", "1", "2\n", "2\n"]}
coding
317
Solve the programming task below in a Python markdown code block. Twilight Sparkle once got a crystal from the Crystal Mine. A crystal of size n (n is odd; n > 1) is an n × n matrix with a diamond inscribed into it. You are given an odd integer n. You need to draw a crystal of size n. The diamond cells of the matrix s...
{"inputs": ["3\n", "5\n", "7\n", "9\n", "5\n", "7\n", "3\n", "11\n"], "outputs": ["*D*\nDDD\n*D*\n", "**D**\n*DDD*\nDDDDD\n*DDD*\n**D**\n", "***D***\n**DDD**\n*DDDDD*\nDDDDDDD\n*DDDDD*\n**DDD**\n***D***\n", "****D****\n***DDD***\n**DDDDD**\n*DDDDDDD*\nDDDDDDDDD\n*DDDDDDD*\n**DDDDD**\n***DDD***\n****D****\n", "**D**\n*D...
coding
213
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a 0-indexed string word of length n consisting of digits, and a positive integer m. The divisibility array div of word is an integer array of length n such that: div[i] = 1 if the numeric value of word[...
{"functional": "def check(candidate):\n assert candidate(word = \"998244353\", m = 3) == [1,1,0,0,0,1,1,0,0]\n assert candidate(word = \"1010\", m = 10) == [0,1,0,1]\n\n\ncheck(Solution().divisibilityArray)"}
coding
140
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...
coding
110
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an integer array nums and an integer k, you are asked to construct the array ans of size n-k+1 where ans[i] is the number of distinct numbers in the subarray nums[i:i+k-1] = [nums[i], nums[i+1], ..., nums[i+k-1]...
{"functional": "def check(candidate):\n assert candidate(nums = [1,2,3,2,2,1,3], k = 3) == [3,2,2,2,3]\n assert candidate(nums = [1,1,1,1,2,3,4], k = 4) == [1,2,3,4]\n\n\ncheck(Solution().distinctNumbers)"}
coding
121
Solve the programming task below in a Python markdown code block. In this challenge, the task is to debug the existing code to successfully execute all provided test files. A number is called a smart number if it has an odd number of factors. Given some numbers, find whether they are smart numbers or not. Debug the g...
{"inputs": ["4\n1\n2\n7\n169\n"], "outputs": ["YES\nNO\nNO\nYES\n"]}
coding
395
Solve the programming task below in a Python markdown code block. Write a function that takes one or more arrays and returns a new array of unique values in the order of the original provided arrays. In other words, all values present from all arrays should be included in their original order, but with no duplicates i...
{"functional": "_inputs = [[[1, 2], [3, 4]], [[1, 3, 2], [5, 2, 1, 4], [2, 1]], [[4, 3, 2, 2]], [[4, 'a', 2], []], [[], [4, 'a', 2]], [[], [4, 'a', 2], []], [[]], [[], []], [[], [1, 2]], [[], [1, 2, 1, 2], [2, 1, 1, 2, 1]]]\n_outputs = [[[1, 2, 3, 4]], [[1, 3, 2, 5, 4]], [[4, 3, 2]], [[4, 'a', 2]], [[4, 'a', 2]], [[4, ...
coding
173
Solve the programming task below in a Python markdown code block. After you had helped Fedor to find friends in the «Call of Soldiers 3» game, he stopped studying completely. Today, the English teacher told him to prepare an essay. Fedor didn't want to prepare the essay, so he asked Alex for help. Alex came to help and...
{"inputs": ["1\nR\n0\n", "1\nr\n0\n", "1\nR\n0\n", "1\nr\n0\n", "1\nQ\n0\n", "1\ns\n0\n", "1\nffff\n1\nffff r\n", "1\nffff\n1\nffff r\n"], "outputs": ["1 1\n", "1 1\n", "1 1\n", "1 1\n", "0 1\n", "0 1\n", "0 4\n", "0 4\n"]}
coding
565
Solve the programming task below in a Python markdown code block. There is a grid with N rows and N columns of squares. Let (i, j) be the square at the i-th row from the top and the j-th column from the left. Each of the central (N-2) \times (N-2) squares in the grid has a black stone on it. Each of the 2N - 1 squares ...
{"inputs": ["39 0", "630 0", "279 0", "328 0", "272 0", "173 0", "218 0", "674 0"], "outputs": ["1369", "394384", "76729", "106276", "72900", "29241", "46656", "451584"]}
coding
419
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an m x n 0-indexed 2D array of positive integers heights where heights[i][j] is the height of the person standing at position (i, j). A person standing at position (row1, col1) can see a person standing ...
{"functional": "def check(candidate):\n assert candidate(heights = [[3,1,4,2,5]]) == [[2,1,2,1,0]]\n assert candidate(heights = [[5,1],[3,1],[4,1]]) == [[3,1],[2,1],[1,0]]\n\n\ncheck(Solution().seePeople)"}
coding
222
Solve the programming task below in a Python markdown code block. The Little Elephant loves chess very much. One day the Little Elephant and his friend decided to play chess. They've got the chess pieces but the board is a problem. They've got an 8 × 8 checkered board, each square is painted either black or white. Th...
{"inputs": ["WBWBWBWB\nBWBWBWBW\nBWBWBWBW\nBWBWBWBW\nWBWBWBWB\nWBWBWBWB\nBWBWBWBW\nWBWBWBWB\n", "WBWBWBWB\nWBWBWBWB\nBBWBWWWB\nBWBWBWBW\nBWBWBWBW\nBWBWBWWW\nBWBWBWBW\nBWBWBWBW\n", "BWBWBWBW\nWBWBWBWB\nBWBWBWBW\nBWBWBWBW\nWBWBWBWB\nWBWBWBWB\nWBWBWBWB\nWBWBWBWB\n", "BWBWBWBW\nWBWBWBWB\nBWBWBWBW\nWBWBWBWB\nBWBWBWBW\nWBWBW...
coding
591