task_type
stringclasses
1 value
problem
stringlengths
209
3.39k
answer
stringlengths
35
6.15k
problem_tokens
int64
60
774
answer_tokens
int64
12
2.04k
coding
Solve the programming task below in a Python markdown code block. B: Twice as own problem You will be given Q queries. Since one positive integer N is given for each query, find the number of positive integers M that satisfy the following two conditions. * 2 Satisfy \ leq M \ leq N * Of the divisors of M, excluding ...
{"inputs": ["3\n73\n8\n9", "3\n7\n24\n1", "3\n7\n45\n2", "3\n7\n59\n2", "3\n7\n33\n1", "3\n7\n80\n2", "3\n7\n52\n2", "3\n7\n94\n1"], "outputs": ["25\n0\n0\n", "0\n5\n0\n", "0\n13\n0\n", "0\n18\n0\n", "0\n8\n0\n", "0\n29\n0\n", "0\n16\n0\n", "0\n34\n0\n"]}
305
156
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. An undirected graph of n nodes is defined by edgeList, where edgeList[i] = [ui, vi, disi] denotes an edge between nodes ui and vi with distance disi. Note that there may be multiple edges between two nodes. Given an a...
{"functional": "def check(candidate):\n assert candidate(n = 3, edgeList = [[0,1,2],[1,2,4],[2,0,8],[1,0,16]], queries = [[0,1,2],[0,2,5]]) == [False,True]\n assert candidate(n = 5, edgeList = [[0,1,10],[1,2,5],[2,3,9],[3,4,13]], queries = [[0,4,14],[1,4,13]]) == [True,False]\n\n\ncheck(Solution().distanceLimited...
207
140
coding
Solve the programming task below in a Python markdown code block. Every year the professor selects the top two students from his class and takes them on a fun filled field trip, this year Ali and Zafar were selected. The professor took them to a place where there was a never-ending queue of solid metal cubes. The profe...
{"inputs": ["4\n3 3 8 8", "4\n2 8 7 3"], "outputs": ["3", "4"]}
489
34
coding
Solve the programming task below in a Python markdown code block. New Year is coming and you are excited to know how many minutes remain before the New Year. You know that currently the clock shows $h$ hours and $m$ minutes, where $0 \le hh < 24$ and $0 \le mm < 60$. We use 24-hour time format! Your task is to find th...
{"inputs": ["1\n1 2\n", "1\n1 2\n", "1\n1 3\n", "1\n2 3\n", "1\n0 3\n", "1\n0 2\n", "1\n1 0\n", "1\n0 6\n"], "outputs": ["1378\n", "1378\n", "1377\n", "1317\n", "1437\n", "1438\n", "1380\n", "1434\n"]}
342
126
coding
Solve the programming task below in a Python markdown code block. The local transport authority is organizing an online picture contest. Participants must take pictures of transport means in an original way, and then post the picture on Instagram using a specific ```hashtag```. The local transport authority needs your...
{"functional": "_inputs = [['Sunny day! #lta #vvv', '#lta'], ['#lta #picture_contest', '#lta'], ['#lta #picture_contest #lta', '#lta']]\n_outputs = [['Sunny day! #vvv'], [' #picture_contest'], [' #picture_contest #lta']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\...
263
218
coding
Solve the programming task below in a Python markdown code block. Vasily has a number a, which he wants to turn into a number b. For this purpose, he can do two types of operations: multiply the current number by 2 (that is, replace the number x by 2·x); append the digit 1 to the right of current number (that is, rep...
{"inputs": ["1 2\n", "1 3\n", "1 2\n", "1 3\n", "2 4\n", "1 5\n", "4 42\n", "2 11\n"], "outputs": ["YES\n2\n1 2 \n", "NO\n", "YES\n2\n1 2 \n", "NO\n", "YES\n2\n2 4\n", "NO\n", "NO\n", "NO\n"]}
419
108
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given two 0-indexed integer arrays nums1 and nums2, return a list answer of size 2 where: answer[0] is a list of all distinct integers in nums1 which are not present in nums2. answer[1] is a list of all distinct inte...
{"functional": "def check(candidate):\n assert candidate(nums1 = [1,2,3], nums2 = [2,4,6]) == [[1,3],[4,6]]\n assert candidate(nums1 = [1,2,3,3], nums2 = [1,1,2,2]) == [[3],[]]\n\n\ncheck(Solution().findDifference)"}
139
88
coding
Solve the programming task below in a Python markdown code block. In this kata, you will write a function that returns the positions and the values of the "peaks" (or local maxima) of a numeric array. For example, the array `arr = [0, 1, 2, 5, 1, 0]` has a peak at position `3` with a value of `5` (since `arr[3]` equal...
{"functional": "_inputs = [[[1, 2, 3, 6, 4, 1, 2, 3, 2, 1]], [[3, 2, 3, 6, 4, 1, 2, 3, 2, 1, 2, 3]], [[3, 2, 3, 6, 4, 1, 2, 3, 2, 1, 2, 2, 2, 1]], [[2, 1, 3, 1, 2, 2, 2, 2, 1]], [[2, 1, 3, 1, 2, 2, 2, 2]], [[2, 1, 3, 2, 2, 2, 2, 5, 6]], [[2, 1, 3, 2, 2, 2, 2, 1]], [[1, 2, 5, 4, 3, 2, 3, 6, 4, 1, 2, 3, 3, 4, 5, 3, 2, 1,...
736
631
coding
Solve the programming task below in a Python markdown code block. Implement a modified Fibonacci sequence using the following definition: Given terms $t\left[i\right]$ and $t[i+1]$ where $i\in(1,\infty)$, term $t[i+2]$ is computed as: $t_{i+2}=t_{i}+(t_{i+1})^{2}$ Given three integers, $\mbox{t1}$, $\mbox{t2}...
{"inputs": ["0 1 5\n"], "outputs": ["5\n"]}
504
18
coding
Solve the programming task below in a Python markdown code block. The All-Berland Team Programming Contest will take place very soon. This year, teams of four are allowed to participate. There are $a$ programmers and $b$ mathematicians at Berland State University. How many maximum teams can be made if: each team must...
{"inputs": ["1\n841409 1\n", "6\n5 5\n10 1\n2 3\n0 0\n17 2\n1000000000 1000000000\n"], "outputs": ["1\n", "2\n1\n1\n0\n2\n500000000\n"]}
393
93
coding
Solve the programming task below in a Python markdown code block. The new ITone 6 has been released recently and George got really keen to buy it. Unfortunately, he didn't have enough money, so George was going to work as a programmer. Now he faced the following problem at the work. Given a sequence of n integers p_1,...
{"inputs": ["1 1 1\n1\n", "1 1 1\n1\n", "2 2 1\n1 0\n", "2 1 1\n0 0\n", "2 1 1\n0 0\n", "2 2 1\n1 0\n", "2 1 1\n0 1\n", "2 1 1\n10 11\n"], "outputs": ["1\n", "1", "1\n", "0\n", "0", "1", "1\n", "11\n"]}
354
130
coding
Solve the programming task below in a Python markdown code block. You are given two arrays A and B, each of size n. The error, E, between these two arrays is defined $E = \sum_{i = 1}^{n}(a_{i} - b_{i})^{2}$. You have to perform exactly k_1 operations on array A and exactly k_2 operations on array B. In one operation, ...
{"inputs": ["1 5 7\n1\n2\n", "1 0 6\n0\n0\n", "1 1 2\n0\n8\n", "1 5 7\n1\n2\n", "1 1 2\n0\n8\n", "1 0 6\n0\n0\n", "1 5 7\n0\n2\n", "1 5 7\n0\n1\n"], "outputs": ["1", "0", "25", "1\n", "25\n", "0\n", "0\n", "1\n"]}
695
133
coding
Solve the programming task below in a Python markdown code block. Caisa solved the problem with the sugar and now he is on the way back to home. Caisa is playing a mobile game during his path. There are (n + 1) pylons numbered from 0 to n in this game. The pylon with number 0 has zero height, the pylon with number i ...
{"inputs": ["1\n1\n", "1\n0\n", "1\n4\n", "1\n2\n", "1\n3\n", "1\n5\n", "1\n69\n", "1\n69\n"], "outputs": ["1\n", "0\n", "4\n", "2\n", "3\n", "5\n", "69\n", "69\n"]}
438
90
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. During the NBA playoffs, we always set the rather strong team to play with the rather weak team, like making the rank 1 team play with the rank nth team, which is a good strategy to make the contest more interesting. ...
{"functional": "def check(candidate):\n assert candidate(n = 4) == \"((1,4),(2,3))\"\n assert candidate(n = 8) == \"(((1,8),(4,5)),((2,7),(3,6)))\"\n\n\ncheck(Solution().findContestMatch)"}
205
72
coding
Solve the programming task below in a Python markdown code block. Boboniu likes bit operations. He wants to play a game with you. Boboniu gives you two sequences of non-negative integers $a_1,a_2,\ldots,a_n$ and $b_1,b_2,\ldots,b_m$. For each $i$ ($1\le i\le n$), you're asked to choose a $j$ ($1\le j\le m$) and let $...
{"inputs": ["1 1\n119\n395\n", "1 1\n511\n511\n", "1 1\n119\n395\n", "1 1\n511\n511\n", "4 2\n2 6 4 0\n2 4\n", "4 2\n2 6 4 0\n2 4\n", "3 2\n5 7 99\n23 162\n", "3 2\n3 7 227\n23 137\n"], "outputs": ["3", "511", "3", "511", "2", "2", "3\n", "3\n"]}
518
169
coding
Solve the programming task below in a Python markdown code block. Min Element Given the sequence a_1, a_2, .., a_N. Find the minimum number in this sequence. If the minimum value is in more than one place, answer the one with the lowest number. input N a_1 a_2 ... a_N output Output the smallest i such that a_i...
{"inputs": ["6\n8 6 9 0 2 1", "6\n8 6 9 1 2 0", "6\n6 0 9 1 2 1", "6\n1 6 9 1 2 0", "6\n1 6 9 0 2 0", "6\n8 3 9 1 2 1", "6\n6 6 9 0 2 1", "6\n8 6 9 2 2 0"], "outputs": ["4\n", "6\n", "2\n", "6\n", "4\n", "4\n", "4\n", "6\n"]}
171
158
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. A distinct string is a string that is present only once in an array. Given an array of strings arr, and an integer k, return the kth distinct string present in arr. If there are fewer than k distinct strings, return a...
{"functional": "def check(candidate):\n assert candidate(arr = [\"d\",\"b\",\"c\",\"b\",\"c\",\"a\"], k = 2) == \"a\"\n assert candidate(arr = [\"aaa\",\"aa\",\"a\"], k = 1) == \"aaa\"\n assert candidate(arr = [\"a\",\"b\",\"a\"], k = 3) == \"\"\n\n\ncheck(Solution().kthDistinct)"}
122
97
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. There is a test that has n types of questions. You are given an integer target and a 0-indexed 2D integer array types where types[i] = [counti, marksi] indicates that there are counti questions of the ith type, and ea...
{"functional": "def check(candidate):\n assert candidate(target = 6, types = [[6,1],[3,2],[2,3]]) == 7\n assert candidate(target = 5, types = [[50,1],[50,2],[50,5]]) == 4\n assert candidate(target = 18, types = [[6,1],[3,2],[2,3]]) == 1\n\n\ncheck(Solution().waysToReachTarget)"}
216
106
coding
Solve the programming task below in a Python markdown code block. There are a number of ways to shuffle a deck of cards. Riffle shuffle is one such example. The following is how to perform riffle shuffle. There is a deck of n cards. First, we divide it into two decks; deck A which consists of the top half of it and de...
{"inputs": ["9 1\n3\n9 4\n1 2 6 4", "9 1\n3\n9 4\n1 1 6 6", "9 1\n4\n5 4\n1 2 6 4", "2 1\n4\n5 4\n1 2 6 4", "9 1\n3\n9 4\n1 2 2 4", "5 1\n3\n9 4\n1 2 3 4", "9 1\n4\n5 4\n2 2 6 4", "5 1\n1\n9 4\n1 2 3 4"], "outputs": ["3\n0\n", "3\n1\n", "8\n0\n", "0\n0\n", "3\n8\n", "1\n0\n", "8\n3\n", "4\n0\n"]}
662
206
coding
Solve the programming task below in a Python markdown code block. Let's call left cyclic shift of some string $t_1 t_2 t_3 \dots t_{n - 1} t_n$ as string $t_2 t_3 \dots t_{n - 1} t_n t_1$. Analogically, let's call right cyclic shift of string $t$ as string $t_n t_1 t_2 t_3 \dots t_{n - 1}$. Let's say string $t$ is go...
{"inputs": ["1\n1111\n", "1\n1111\n", "1\n0111\n", "1\n0011\n", "1\n0101\n", "1\n0001\n", "1\n1101\n", "1\n1001\n"], "outputs": ["0\n", "0\n", "1\n", "2\n", "0\n", "1\n", "1\n", "2\n"]}
455
110
coding
Solve the programming task below in a Python markdown code block. Frog Gorf is traveling through Swamp kingdom. Unfortunately, after a poor jump, he fell into a well of $n$ meters depth. Now Gorf is on the bottom of the well and has a long way up. The surface of the well's walls vary in quality: somewhere they are sli...
{"inputs": ["1\n1\n0\n", "1\n1\n0\n", "2\n1 1\n1 0\n", "2\n1 1\n0 0\n", "2\n1 2\n1 0\n", "2\n0 2\n1 0\n", "2\n1 1\n1 0\n", "3\n0 2 2\n1 1 0\n"], "outputs": ["1\n0 \n", "1\n0 ", "-1\n", "2\n1 0\n", "1\n0\n", "1\n0\n", "-1\n", "2\n1 0 \n"]}
736
147
coding
Solve the programming task below in a Python markdown code block. You are given an integer $n$. You have to change the minimum number of digits in it in such a way that the resulting number does not have any leading zeroes and is divisible by $7$. If there are multiple ways to do it, print any of them. If the given nu...
{"inputs": ["3\n42\n23\n377\n"], "outputs": ["42\n28\n378\n"]}
362
32
coding
Solve the programming task below in a Python markdown code block. Monocarp wrote down two numbers on a whiteboard. Both numbers follow a specific format: a positive integer $x$ with $p$ zeros appended to its end. Now Monocarp asks you to compare these two numbers. Can you help him? -----Input----- The first line co...
{"inputs": ["1\n7 0\n1 1\n", "1\n7 0\n1 2\n", "1\n7 0\n2 2\n", "1\n15 0\n1 1\n", "1\n1 5\n101 3\n", "1\n105 0\n1 2\n", "1\n402 2\n4 4\n", "1\n4 4\n402 2\n"], "outputs": ["<\n", "<\n", "<\n", ">\n", "<\n", ">\n", ">\n", "<\n"]}
391
144
coding
Solve the programming task below in a Python markdown code block. As you must know, the maximum clique problem in an arbitrary graph is NP-hard. Nevertheless, for some graphs of specific kinds it can be solved effectively. Just in case, let us remind you that a clique in a non-directed graph is a subset of the vertice...
{"inputs": ["1\n1\n", "1\n8\n", "1\n1\n", "1\n8\n", "1\n2\n", "1\n3\n", "1\n4\n", "1\n5\n"], "outputs": ["1\n", "1\n", "1", "1", "1\n", "1\n", "1\n", "1\n"]}
409
84
coding
Solve the programming task below in a Python markdown code block. Mr. Takahashi has a string s consisting of lowercase English letters. He repeats the following operation on s exactly K times. * Choose an arbitrary letter on s and change that letter to the next alphabet. Note that the next letter of `z` is `a`. For...
{"inputs": ["b\n25", "b\n11", "b\n16", "a\n16", "a\n25", "xyz\n1", "zyx\n1", "zyx\n2"], "outputs": ["a\n", "m\n", "r\n", "q\n", "z", "xya\n", "ayx\n", "ayy\n"]}
256
87
coding
Solve the programming task below in a Python markdown code block. From a hidden array A of length N, Stack constructs an array B of length N such that: For all i (1 ≤ i ≤ N), B_{i}=\max(A_{1},A_{2},\ldots,A_{i}) or B_{i}=\min(A_{1},A_{2},\ldots,A_{i}). For the given array B of length N, Stack wants you to check whethe...
{"inputs": ["3\n1\n343\n4\n1 1 2 3\n3\n1 3 2\n", "2\n5\n1 1 1 1 1 \n5\n1 2 1 2 1\n"], "outputs": ["YES\nYES\nNO\n", "YES\nYES\n"]}
681
77
coding
Solve the programming task below in a Python markdown code block. The sequence of integers $a_1, a_2, \dots, a_k$ is called a good array if $a_1 = k - 1$ and $a_1 > 0$. For example, the sequences $[3, -1, 44, 0], [1, -99]$ are good arrays, and the sequences $[3, 7, 8], [2, 5, 4, 1], [0]$ — are not. A sequence of integ...
{"inputs": ["1\n0\n", "1\n1\n", "1\n1\n", "1\n0\n", "1\n2\n", "1\n3\n", "1\n4\n", "1\n6\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]}
562
86
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given two positive integers n and k. A factor of an integer n is defined as an integer i where n % i == 0. Consider a list of all factors of n sorted in ascending order, return the kth factor in this list or r...
{"functional": "def check(candidate):\n assert candidate(n = 12, k = 3) == 3\n assert candidate(n = 7, k = 2) == 7\n assert candidate(n = 4, k = 4) == -1\n\n\ncheck(Solution().kthFactor)"}
115
72
coding
Solve the programming task below in a Python markdown code block. This is an easy version of the problem. The actual problems are different, but the easy version is almost a subtask of the hard version. Note that the constraints and the output format are different. You are given a string $s$ consisting of $n$ lowercas...
{"inputs": ["1\na\n", "1\nr\n", "1\na\n", "1\ns\n", "1\nb\n", "1\nt\n", "2\ntj\n", "2\njt\n"], "outputs": ["YES\n0\n", "YES\n0\n", "YES\n0\n", "YES\n0\n", "YES\n0\n", "YES\n0\n", "YES\n01\n", "YES\n00\n"]}
452
105
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Alice and Bob are opponents in an archery competition. The competition has set the following rules: Alice first shoots numArrows arrows and then Bob shoots numArrows arrows. The points are then calculated as follows:...
{"functional": "def check(candidate):\n assert candidate(numArrows = 9, aliceArrows = [1,1,0,1,0,0,2,1,0,1,2,0]) == [0,0,0,0,1,1,0,0,1,2,3,1]\n assert candidate(numArrows = 3, aliceArrows = [0,0,1,0,0,0,0,0,0,0,0,2]) == [0,0,0,0,0,0,0,0,1,1,1,0]\n\n\ncheck(Solution().maximumBobPoints)"}
374
152
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an integer array nums of length n, return true if there is a triplet (i, j, k) which satisfies the following conditions: 0 < i, i + 1 < j, j + 1 < k < n - 1 The sum of subarrays (0, i - 1), (i + 1, j - 1), (j +...
{"functional": "def check(candidate):\n assert candidate(nums = [1,2,1,2,1,2,1]) == True\n assert candidate(nums = [1,2,1,2,1,2,1,2]) == False\n\n\ncheck(Solution().splitArray)"}
177
67
coding
Solve the programming task below in a Python markdown code block. Base on the fairy tale [Diamonds and Toads](https://en.wikipedia.org/wiki/Diamonds_and_Toads) from Charles Perrault. In this kata you will have to complete a function that take 2 arguments: - A string, that correspond to what the daugther says. - A str...
{"functional": "_inputs = [['Ruby and Crystal', 'good'], ['This string contain some Ruby and some Crystal in it', 'good'], ['Python and Squirrel', 'evil'], ['This string contain some Python and some Squirrel in it', 'evil']]\n_outputs = [[{'ruby': 3, 'crystal': 2}], [{'ruby': 4, 'crystal': 3}], [{'python': 2, 'squirrel...
318
254
coding
Solve the programming task below in a Python markdown code block. Write a program which judges wheather given length of three side form a right triangle. Print "YES" if the given sides (integers) form a right triangle, "NO" if not so. Constraints * 1 ≤ length of the side ≤ 1,000 * N ≤ 1,000 Input Input consists of ...
{"inputs": ["3\n4 3 5\n0 3 6\n8 8 8", "3\n4 5 5\n0 8 6\n3 8 0", "3\n4 5 5\n0 8 6\n4 8 0", "3\n4 5 5\n1 8 6\n4 8 0", "3\n4 5 5\n2 8 6\n4 8 0", "3\n4 5 5\n2 8 2\n4 8 0", "3\n4 3 5\n4 3 6\n8 8 8", "3\n4 5 5\n-2 3 6\n8 8 8"], "outputs": ["YES\nNO\nNO\n", "NO\nNO\nNO\n", "NO\nNO\nNO\n", "NO\nNO\nNO\n", "NO\nNO\nNO\n", "NO\n...
179
238
coding
Solve the programming task below in a Python markdown code block. Write a function that replaces 'two', 'too' and 'to' with the number '2'. Even if the sound is found mid word (like in octopus) or not in lowercase grandma still thinks that should be replaced with a 2. Bless her. ```text 'I love to text' becomes 'I lov...
{"functional": "_inputs = [['I love to text'], ['see you tomorrow'], ['look at that octopus'], ['BECAUSE I WANT TO']]\n_outputs = [['I love 2 text'], ['see you 2morrow'], ['look at that oc2pus'], ['BECAUSE I WANT 2']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n ...
151
206
coding
Solve the programming task below in a Python markdown code block. You are given an integer sequence A of length N. Find the maximum absolute difference of two elements (with different indices) in A. -----Constraints----- - 2 \leq N \leq 100 - 1 \leq A_i \leq 10^9 - All values in input are integers. -----Input-----...
{"inputs": ["4\n1 4 6 3\n", "5\n1 1 1 1 1\n", "2\n1000000000 1\n", "2\n877914575 602436426\n", "2\n861648772 861648772\n", "16\n433933447 476190629 262703497 211047202 971407775 628894325 731963982 822804784 450968417 430302156 982631932 161735902 880895728 923078537 707723857 189330739\n", "63\n992120464 989248231 989...
169
1,687
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 2 arrays W = (W_{1}, W_{2}, .., W_{N}) and C = (C_{1}, C_{2}, .., C_{N}) with N elements each. A range [l, r] is unique if all the elements C_{l}, C_{l+1}, .....
{"inputs": ["1\n5\n0 1 2 0 2\n5 6 7 8 2"], "outputs": ["21"]}
508
35
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a string text. You can swap two of the characters in the text. Return the length of the longest substring with repeated characters.   Please complete the following python code precisely: ```python class ...
{"functional": "def check(candidate):\n assert candidate(text = \"ababa\") == 3\n assert candidate(text = \"aaabaaa\") == 6\n assert candidate(text = \"aaabbaaa\") == 4\n assert candidate(text = \"aaaaa\") == 5\n assert candidate(text = \"abcdef\") == 1\n\n\ncheck(Solution().maxRepOpt1)"}
78
88
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. A sequence of numbers is called arithmetic if it consists of at least two elements, and the difference between every two consecutive elements is the same. More formally, a sequence s is arithmetic if and only if s[i+1...
{"functional": "def check(candidate):\n assert candidate(nums = [4,6,5,9,3,7], l = [0,0,2], r = [2,3,5]) == [True,False,True]\n assert candidate(nums = [-12,-9,-3,-12,-6,15,20,-25,-20,-15,-10], l = [0,1,6,4,8,7], r = [4,4,9,7,9,10]) == [False,True,False,False,True,True]\n\n\ncheck(Solution().checkArithmeticSubarr...
292
142
coding
Solve the programming task below in a Python markdown code block. Mr. Suzuki has opened a new mobile sales shop for freshly squeezed milk in the Aizu area. It is assumed that all the customers who come to buy that day are already in the store with bottles to take home and will not increase any more. Customers only orde...
{"inputs": ["5\n2\n6\n4\n6\n9\n0", "5\n2\n6\n4\n7\n9\n0", "5\n1\n2\n6\n9\n0\n0", "5\n1\n2\n6\n9\n1\n0", "5\n1\n2\n6\n1\n1\n0", "5\n1\n2\n6\n1\n3\n0", "5\n1\n2\n4\n2\n4\n0", "5\n2\n2\n4\n2\n4\n0"], "outputs": ["38\n", "39\n", "13\n", "17\n", "11\n", "14\n", "18\n", "22\n"]}
610
166
coding
Solve the programming task below in a Python markdown code block. Implement a function, `multiples(m, n)`, which returns an array of the first `m` multiples of the real number `n`. Assume that `m` is a positive integer. Ex. ``` multiples(3, 5.0) ``` should return ``` [5.0, 10.0, 15.0] ``` Also feel free to reuse/exten...
{"functional": "_inputs = [[3, 5], [1, 3.14], [5, -1]]\n_outputs = [[[5, 10, 15]], [[3.14]], [[-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 ...
115
203
coding
Solve the programming task below in a Python markdown code block. problem JOI decided to play a game with his friends. N players participate in this game. The rules for a single game are as follows: Each player writes a favorite integer from 1 to 100 on the card and submits it. Each player gets the same score as he w...
{"inputs": ["5\n100 2 98\n100 97 5\n18 4 65\n68 1 77\n57 81 58", "5\n100 2 98\n100 97 5\n18 4 12\n68 1 77\n57 81 58", "5\n100 2 98\n100 97 5\n18 4 47\n68 1 77\n57 81 58", "5\n100 2 98\n100 97 5\n18 4 65\n68 91 77\n57 81 58", "5\n100 1 98\n100 97 68\n2 21 9\n68 99 77\n89 97 43", "5\n100 1 98\n100 97 5\n18 4 65\n68 91 77...
624
543
coding
Solve the programming task below in a Python markdown code block. Given an integer $n$, find the maximum value of integer $k$ such that the following condition holds: $n$ & ($n-1$) & ($n-2$) & ($n-3$) & ... ($k$) = $0$ where & denotes the bitwise AND operation. -----Input----- The first line contains a single integ...
{"inputs": ["1\n6\n", "1\n2\n", "1\n7\n", "1\n90\n", "1\n16\n", "1\n52\n", "1\n70\n", "1\n82\n"], "outputs": ["3\n", "1\n", "3\n", "63\n", "15\n", "31\n", "63\n", "63\n"]}
306
96
coding
Solve the programming task below in a Python markdown code block. Your task is to write a program which reads an expression and evaluates it. * The expression consists of numerical values, operators and parentheses, and the ends with '='. * The operators includes +, - , *, / where respectively represents, addition, su...
{"inputs": ["2\n4-2*3=\n8*(4+4+3)=", "2\n4-2*3=\n8*(4+4+2)=", "2\n4-3*3=\n4*(8+4+3)=", "2\n4-1*3=\n4*(8+4+3)=", "2\n4-1+3=\n4*(8+4+3)=", "2\n4-2+3=\n4*(8+4+3)=", "2\n5-1+3=\n4*(8+4+3)=", "2\n3-1*3=\n4*(8+4+3)="], "outputs": ["-2\n88\n", "-2\n80\n", "-5\n60\n", "1\n60\n", "6\n60\n", "5\n60\n", "7\n60\n", "0\n60\n"]}
250
215
coding
Solve the programming task below in a Python markdown code block. Each New Year Timofey and his friends cut down a tree of n vertices and bring it home. After that they paint all the n its vertices, so that the i-th vertex gets color ci. Now it's time for Timofey birthday, and his mother asked him to remove the tree. ...
{"inputs": ["2\n1 2\n1 1\n", "2\n1 2\n1 2\n", "2\n1 2\n1 0\n", "2\n1 2\n2 2\n", "3\n2 1\n2 3\n4 4 4\n", "3\n1 2\n1 3\n1 2 2\n", "3\n2 1\n2 3\n1 2 3\n", "3\n2 1\n2 3\n4 4 5\n"], "outputs": ["YES\n1", "YES\n1\n", "YES\n1\n", "YES\n1\n", "YES\n1", "YES\n1", "YES\n2", "YES\n2"]}
504
169
coding
Solve the programming task below in a Python markdown code block. It started as a discussion with a friend, who didn't fully grasp some way of setting defaults, but I thought the idea was cool enough for a beginner kata: binary `OR` each matching element of two given arrays (or lists, if you do it in Python; vectors in...
{"functional": "_inputs = [[[1, 2, 3], [1, 2, 3]], [[1, 2, 3], [4, 5, 6]], [[1, 2, 3], [1, 2]], [[1, 0], [1, 2, 3]], [[1, 0, 3], [1, 2, 3], 3]]\n_outputs = [[[1, 2, 3]], [[5, 7, 7]], [[1, 2, 3]], [[1, 2, 3]], [[1, 2, 3]]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\...
275
280
coding
Solve the programming task below in a Python markdown code block. It's well known that the best way to distract from something is to do one's favourite thing. Job is such a thing for Leha. So the hacker began to work hard in order to get rid of boredom. It means that Leha began to hack computers all over the world. Fo...
{"inputs": ["2 4\n1 2 1\n2 3 2\n", "2 2\n1 1 1\n1 1 1\n", "2 2\n2 2 1\n3 3 2\n", "2 4\n1 2 5\n1 3 5\n", "2 4\n1 2 5\n1 3 5\n", "2 2\n1 1 1\n1 1 1\n", "2 2\n2 2 1\n3 3 2\n", "2 4\n1 2 1\n2 3 2\n"], "outputs": ["-1\n", "-1\n", "3\n", "-1\n", "-1", "-1", "3", "-1"]}
617
179
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an m x n 2D binary grid grid which represents a map of '1's (land) and '0's (water), return the number of islands. An island is surrounded by water and is formed by connecting adjacent lands horizontally or vert...
{"functional": "def check(candidate):\n assert candidate(grid = [\n [\"1\",\"1\",\"1\",\"1\",\"0\"],\n [\"1\",\"1\",\"0\",\"1\",\"0\"],\n [\"1\",\"1\",\"0\",\"0\",\"0\"],\n [\"0\",\"0\",\"0\",\"0\",\"0\"]\n]) == 1\n assert candidate(grid = [\n [\"1\",\"1\",\"0\",\"0\",\"0\"],\n [\"1\",\"1\",\"0\",\"0\",\"0\...
118
170
coding
Solve the programming task below in a Python markdown code block. Takahashi and Aoki will play a game on a tree. The tree has N vertices numbered 1 to N, and the i-th of the N-1 edges connects Vertex a_i and Vertex b_i. At the beginning of the game, each vertex contains a coin. Starting from Takahashi, he and Aoki wil...
{"inputs": ["3\n2 2\n2 3", "3\n2 1\n2 3", "3\n1 2\n2 3", "6\n1 2\n2 1\n2 4\n4 6\n5 6", "6\n1 2\n2 3\n2 4\n6 6\n5 6", "6\n1 2\n2 1\n2 4\n4 6\n4 6", "6\n1 3\n2 3\n2 4\n6 6\n5 6", "6\n2 2\n2 3\n2 4\n6 6\n5 6"], "outputs": ["First\n", "First\n", "First", "Second\n", "First\n", "First\n", "First\n", "First\n"]}
385
185
coding
Solve the programming task below in a Python markdown code block. Given an array of numbers (in string format), you must return a string. The numbers correspond to the letters of the alphabet in reverse order: a=26, z=1 etc. You should also account for `'!'`, `'?'` and `' '` that are represented by '27', '28' and '29' ...
{"functional": "_inputs = [[['24', '12', '23', '22', '4', '26', '9', '8']], [['25', '7', '8', '4', '14', '23', '8', '25', '23', '29', '16', '16', '4']], [['4', '24']], [['12']], [['12', '28', '25', '21', '25', '7', '11', '22', '15']]]\n_outputs = [['codewars'], ['btswmdsbd kkw'], ['wc'], ['o'], ['o?bfbtpel']]\nimport m...
112
301
coding
Solve the programming task below in a Python markdown code block. Today Hayato came home from school with homework. In the assignment, Hayato was given an array $a$ of length $n$. The task was to find $3$ numbers in this array whose sum is odd. At school, he claimed that there are such $3$ numbers, but Hayato was not ...
{"inputs": ["6\n3\n1 1 1\n4\n1 1 2 2\n3\n1 2 3\n5\n1 4 5 1 2\n4\n2 6 2 4\n5\n5 6 3 2 1\n"], "outputs": ["YES\n1 2 3\nYES\n3 4 1\nNO\nYES\n1 3 4\nNO\nYES\n1 3 5\n"]}
638
108
coding
Solve the programming task below in a Python markdown code block. The Little Elephant very much loves sums on intervals. This time he has a pair of integers l and r (l ≤ r). The Little Elephant has to find the number of such integers x (l ≤ x ≤ r), that the first digit of integer x equals the last one (in decimal nota...
{"inputs": ["2 2\n", "1 2\n", "4 7\n", "7 8\n", "1 1\n", "2 3\n", "1 10\n", "5 45\n"], "outputs": ["1\n", "2\n", "4\n", "2\n", "1\n", "2\n", "9\n", "9\n"]}
305
88
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 and an integer targetSum, return true if the tree has a root-to-leaf path such that adding up all the values along the path equals targetSum. A leaf is a node with no children.   Please...
{"functional": "def check(candidate):\n assert candidate(root = tree_node([5,4,8,11,None,13,4,7,2,None,None,None,1]), targetSum = 22) == True\n assert candidate(root = tree_node([1,2,3]), targetSum = 5) == False\n assert candidate(root = tree_node([]), targetSum = 0) == False\n\n\ncheck(Solution().hasPathSum)"...
154
103
coding
Solve the programming task below in a Python markdown code block. Taxis of Kharagpur are famous for making sharp turns. You are given the coordinates where a particular taxi was on a 2-D planes at N different moments: (x1, y1), (x2, y2), ..., (xN, yN). In between these coordinates, the taxi moves on a straight line. A ...
{"inputs": ["5\n3\n0 0\n1 1\n2 1\n3\n0 0\n1 0\n6 1\n3\n0 0\n1 0\n1 1\n4\n0 0\n1 0\n1 1\n6 1\n6\n0 0\n1 0\n1 1\n2 1\n2 2\n3 2"], "outputs": ["yes yes\nyes yes\nno yes\nno yes\nno no"]}
737
111
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an array of distinct integers nums and a target integer target, return the number of possible combinations that add up to target. The test cases are generated so that the answer can fit in a 32-bit integer.   Pl...
{"functional": "def check(candidate):\n assert candidate(nums = [1,2,3], target = 4) == 7\n assert candidate(nums = [9], target = 3) == 0\n\n\ncheck(Solution().combinationSum4)"}
98
58
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. There is a country of n cities numbered from 0 to n - 1. In this country, there is a road connecting every pair of cities. There are m friends numbered from 0 to m - 1 who are traveling through the country. Each one o...
{"functional": "def check(candidate):\n assert candidate(n = 5, paths = [[0,1,2,3,4],\n [2,3,4],\n [4,0,1,2,3]]) == 2\n assert candidate(n = 3, paths = [[0],[1],[2]]) == 0\n assert candidate(n = 5, paths = [[0,1,2,3,4],\n [4,3,2,1,0]]) == 1\n\n\ncheck...
232
131
coding
Solve the programming task below in a Python markdown code block. Find places where a string P is found within a text T. Print all indices of T where P found. The indices of T start with 0. Constraints * 1 ≤ length of T ≤ 1000000 * 1 ≤ length of P ≤ 10000 * The input consists of alphabetical characters and digits In...
{"inputs": ["yzyz\nyz", "xzyz\nyz", "zyzy\nyz", "xyzz\nyz", "aaabaa\naa", "aabbaa\naa", "aabaab\naa", "aababb\naa"], "outputs": ["0\n2\n", "2\n", "1\n", "1", "0\n1\n4\n", "0\n4\n", "0\n3\n", "0\n"]}
168
100
coding
Solve the programming task below in a Python markdown code block. Highway 201 is the most busy street in Rockport. Traffic cars cause a lot of hindrances to races, especially when there are a lot of them. The track which passes through this highway can be divided into $n$ sub-tracks. You are given an array $a$ where $a...
{"inputs": ["3\n3\n1 2 6\n4\n2 1 1 0\n10\n0 2 5 23 4 2 4 5 7 8\n", "3\n3\n1 2 8\n4\n2 1 1 0\n10\n0 2 5 23 4 2 4 5 7 8\n", "3\n3\n1 2 8\n4\n2 1 1 0\n10\n0 2 5 23 4 2 4 5 1 8\n", "3\n3\n1 2 8\n4\n2 1 1 0\n10\n0 2 5 23 4 4 5 5 2 8\n", "3\n3\n1 2 8\n4\n3 1 1 0\n10\n0 2 5 28 4 4 5 5 2 8\n", "3\n3\n1 2 8\n4\n3 1 1 1\n10\n0 2...
492
444
coding
Solve the programming task below in a Python markdown code block. Create a function that returns the sum of the two lowest positive numbers given an array of minimum 4 positive integers. No floats or non-positive integers will be passed. For example, when an array is passed like `[19, 5, 42, 2, 77]`, the output should...
{"functional": "_inputs = [[[5, 8, 12, 18, 22]], [[7, 15, 12, 18, 22]], [[25, 42, 12, 18, 22]], [[1, 8, 12, 18, 5]], [[13, 12, 5, 61, 22]]]\n_outputs = [[13], [19], [30], [6], [17]]\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_t...
157
263
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an integer n. Each number from 1 to n is grouped according to the sum of its digits. Return the number of groups that have the largest size.   Please complete the following python code precisely: ```pyth...
{"functional": "def check(candidate):\n assert candidate(n = 13) == 4\n assert candidate(n = 2) == 2\n assert candidate(n = 15) == 6\n assert candidate(n = 24) == 5\n\n\ncheck(Solution().countLargestGroup)"}
84
72
coding
Solve the programming task below in a Python markdown code block. Let's consider one interesting word game. In this game you should transform one word into another through special operations. Let's say we have word w, let's split this word into two non-empty parts x and y so, that w = xy. A split operation is transfo...
{"inputs": ["aa\naa\n1\n", "ab\nba\n0\n", "hi\nhi\n1\n", "ab\nba\n9\n", "aa\naa\n0\n", "ab\nab\n9\n", "ab\nca\n2\n", "ab\nbb\n2\n"], "outputs": ["1\n", "0\n", "0\n", "1\n", "1\n", "0\n", "0\n", "0\n"]}
453
102
coding
Solve the programming task below in a Python markdown code block. Snuke lives in another world, where slimes are real creatures and kept by some people. Slimes come in N colors. Those colors are conveniently numbered 1 through N. Snuke currently has no slime. His objective is to have slimes of all the colors together. ...
{"inputs": ["2 6\n1 101", "2 3\n1 101", "2 2\n1 100", "2 0\n1 100", "2 10\n1 101", "2 10\n1 100", "4 4\n2 1 3 4", "4 10\n1 1 3 4"], "outputs": ["8\n", "5\n", "4\n", "2\n", "12\n", "12", "10\n", "9\n"]}
362
135
coding
Solve the programming task below in a Python markdown code block. Chef has a string $S$ consisting of lowercase English characters. Chef defined functions left shift $L(X)$ and right shift $R(X)$ as follows. $L(X)$ is defined as shifting all characters of string $X$ one step towards left and moving the first character...
{"inputs": ["4\na\nab\nabcd\naaaaa"], "outputs": ["YES\nYES\nNO\nYES"]}
408
27
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an integer array nums of size n, return the minimum number of moves required to make all array elements equal. In one move, you can increment or decrement an element of the array by 1. Test cases are designed so...
{"functional": "def check(candidate):\n assert candidate(nums = [1,2,3]) == 2\n assert candidate(nums = [1,10,2,9]) == 16\n\n\ncheck(Solution().minMoves2)"}
108
56
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an array of keywords words and a string s, make all appearances of all keywords words[i] in s bold. Any letters between <b> and </b> tags become bold. Return s after adding the bold tags. The returned string sho...
{"functional": "def check(candidate):\n assert candidate(words = [\"ab\",\"bc\"], s = \"aabcd\") == \"a<b>abc</b>d\"\n assert candidate(words = [\"ab\",\"cb\"], s = \"aabcd\") == \"a<b>ab</b>cd\"\n\n\ncheck(Solution().boldWords)"}
119
78
coding
Solve the programming task below in a Python markdown code block. Petya and Vasya are playing a game. Petya's got n non-transparent glasses, standing in a row. The glasses' positions are indexed with integers from 1 to n from left to right. Note that the positions are indexed but the glasses are not. First Petya puts ...
{"inputs": ["1 1 1\n1\n", "1 1 1\n1\n", "2 1 2\n1 2\n", "2 1 2\n2 1\n", "2 2 2\n1 2\n", "2 2 2\n2 1\n", "2 1 1\n2 1\n", "2 1 2\n2 1\n"], "outputs": ["0\n", "0\n", "-1\n", "1\n", "0\n", "0\n", "0\n", "1\n"]}
494
130
coding
Solve the programming task below in a Python markdown code block. A pangram is a string that contains every letter of the alphabet. Given a sentence determine whether it is a pangram in the English alphabet. Ignore case. Return either pangram or not pangram as appropriate. Example $s=\text{'The quick brown fox ju...
{"inputs": ["We promptly judged antique ivory buckles for the prize", "We promptly judged antique ivory buckles for the next prize"], "outputs": ["not pangram", "pangram"]}
299
41
coding
Solve the programming task below in a Python markdown code block. Creatnx has $n$ mirrors, numbered from $1$ to $n$. Every day, Creatnx asks exactly one mirror "Am I beautiful?". The $i$-th mirror will tell Creatnx that he is beautiful with probability $\frac{p_i}{100}$ for all $1 \le i \le n$. Creatnx asks the mirror...
{"inputs": ["1\n50\n", "1\n69\n", "1\n96\n", "1\n68\n", "1\n50\n", "2\n4 73\n", "2\n7 73\n", "2\n7 85\n"], "outputs": ["2\n", "578692380\n", "291154604\n", "528482306\n", "2\n", "259817059\n", "443447121\n", "16777234\n"]}
539
147
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. You are given a tree $G$ with $N$ vertices numbered $1$ through $N$. It is guaranteed that $N$ is even. For a positive integer $k$, let's define a g...
{"inputs": ["2\n2\n1 2\n6\n1 2\n1 3\n3 4\n3 5\n3 6"], "outputs": ["1\n1\n2\n2\n1 3 5\n2 4 6"]}
661
58
coding
Solve the programming task below in a Python markdown code block. We have N points in the two-dimensional plane. The coordinates of the i-th point are (X_i,Y_i). Among them, we are looking for the points such that the distance from the origin is at most D. How many such points are there? We remind you that the distan...
{"inputs": ["4 5\n0 5\n-2 4\n3 4\n4 -2", "4 5\n1 5\n-2 4\n3 1\n4 -1", "3 5\n0 5\n-2 4\n5 1\n4 -2", "1 5\n0 5\n-2 4\n3 1\n4 -2", "4 5\n0 5\n-2 4\n3 1\n4 -2", "4 5\n0 5\n-2 4\n3 1\n4 -1", "3 5\n0 5\n-2 4\n3 1\n4 -2", "4 5\n0 5\n-2 4\n3 4\n4 -5"], "outputs": ["4\n", "3\n", "2\n", "1\n", "4\n", "4\n", "3\n", "3\n"]}
591
214
coding
Solve the programming task below in a Python markdown code block. Vova is again playing some computer game, now an RPG. In the game Vova's character received a quest: to slay the fearsome monster called Modcrab. After two hours of playing the game Vova has tracked the monster and analyzed its tactics. The Modcrab has ...
{"inputs": ["1 1 2\n3 1\n", "1 1 2\n3 1\n", "1 1 3\n3 1\n", "4 1 2\n2 1\n", "4 1 4\n2 1\n", "4 1 2\n10 1\n", "20 1 5\n8 4\n", "20 1 5\n8 4\n"], "outputs": ["5\nHEAL\nSTRIKE\nHEAL\nSTRIKE\nSTRIKE\n", "5\nHEAL\nSTRIKE\nHEAL\nSTRIKE\nSTRIKE\n", "4\nHEAL\nSTRIKE\nSTRIKE\nSTRIKE\n", "2\nSTRIKE\nSTRIKE\n", "2\nSTRIKE\nSTRIKE...
737
383
coding
Solve the programming task below in a Python markdown code block. Determine if we can choose K different integers between 1 and N (inclusive) so that no two of them differ by 1. Constraints * 1\leq N,K\leq 100 * N and K are integers. Input Input is given from Standard Input in the following format: N K Output ...
{"inputs": ["5 2", "5 8", "2 2", "5 1", "6 2", "9 2", "9 4", "9 1"], "outputs": ["YES\n", "NO\n", "NO\n", "YES\n", "YES\n", "YES\n", "YES\n", "YES\n"]}
148
78
coding
Solve the programming task below in a Python markdown code block. Every summer Vitya comes to visit his grandmother in the countryside. This summer, he got a huge wart. Every grandma knows that one should treat warts when the moon goes down. Thus, Vitya has to catch the moment when the moon is down. Moon cycle lasts 3...
{"inputs": ["1\n8\n", "1\n1\n", "1\n2\n", "1\n3\n", "1\n4\n", "1\n5\n", "1\n6\n", "1\n7\n"], "outputs": ["-1\n", "-1\n", "-1\n", "-1\n", "-1\n", "-1\n", "-1\n", "-1\n"]}
610
87
coding
Solve the programming task below in a Python markdown code block. The Fair Nut lives in $n$ story house. $a_i$ people live on the $i$-th floor of the house. Every person uses elevator twice a day: to get from the floor where he/she lives to the ground (first) floor and to get from the first floor to the floor where he/...
{"inputs": ["1\n1\n", "1\n1\n", "1\n0\n", "1\n2\n", "1\n4\n", "1\n6\n", "1\n5\n", "2\n1 1\n"], "outputs": ["0", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "4"]}
653
86
coding
Solve the programming task below in a Python markdown code block. Finally, after purchasing a water cooler during the April long challenge, Chef noticed that his water cooler requires 2 liters of water to cool for one hour. How much water (in liters) would be required by the cooler to cool for N hours? ------ Input F...
{"inputs": ["2\n1\n2"], "outputs": ["2\n4\n"]}
260
19
coding
Solve the programming task below in a Python markdown code block. Write a program which reads a word W and a text T, and prints the number of word W which appears in text T T consists of string Ti separated by space characters and newlines. Count the number of Ti which equals to W. The word and text are case insensiti...
{"inputs": ["computer\nNurtures computer scientists and highly-skilled computer engineers\nwho will create and exploit \"knowledge\" for the enw era.\nProvides an outstanding computer environment.\nEND_OF_TEXT", "comquter\nNurtures computer scientists and highly-skilled computer engineers\nwho will create and tiolpxe \...
203
414
coding
Solve the programming task below in a Python markdown code block. I have the `par` value for each hole on a golf course and my stroke `score` on each hole. I have them stored as strings, because I wrote them down on a sheet of paper. Right now, I'm using those strings to calculate my golf score by hand: take the diffe...
{"functional": "_inputs = [['443454444344544443', '353445334534445344'], ['123456123456123456', '123456123456123456']]\n_outputs = [[-1], [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...
258
238
coding
Solve the programming task below in a Python markdown code block. One of the first chain emails I ever received was about a supposed Cambridge University study that suggests your brain can read words no matter what order the letters are in, as long as the first and last letters of each word are correct. Your task is ...
{"functional": "_inputs = [['Hi'], ['Hi!'], ['Hey'], ['Hey?']]\n_outputs = [['Hi'], ['Hi!'], ['Hey'], ['Hey?']]\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...
354
177
coding
Solve the programming task below in a Python markdown code block. # Task You are given a binary string (a string consisting of only '1' and '0'). The only operation that can be performed on it is a Flip operation. It flips any binary character ( '0' to '1' and vice versa) and all characters to the `right` of it. ...
{"functional": "_inputs = [['0101'], ['10000'], ['0000000000'], ['1111111111'], ['10101010101010'], ['11111000011111'], ['000001111100000'], ['111000000000'], ['00000000111111111'], ['1010101011111111111111000000000']]\n_outputs = [[3], [2], [0], [1], [14], [3], [2], [2], [1], [10]]\nimport math\ndef _deep_eq(a, b, tol...
295
332
coding
Solve the programming task below in a Python markdown code block. Furik loves math lessons very much, so he doesn't attend them, unlike Rubik. But now Furik wants to get a good mark for math. For that Ms. Ivanova, his math teacher, gave him a new task. Furik solved the task immediately. Can you? You are given a set of...
{"inputs": ["1\n0\n", "2\n0 0\n", "2\n0 1\n", "2\n9 0\n", "3\n0 0 1\n", "3\n1 0 0\n", "3\n1 4 0\n", "3\n0 0 4\n"], "outputs": ["0\n", "0\n", "0\n", "90\n", "0\n", "0\n", "0\n", "0\n"]}
360
109
coding
Solve the programming task below in a Python markdown code block. You are given a rooted tree with root in vertex 1. Each vertex is coloured in some colour. Let's call colour c dominating in the subtree of vertex v if there are no other colours that appear in the subtree of vertex v more times than colour c. So it's p...
{"inputs": ["4\n1 2 3 4\n1 2\n2 3\n2 4\n", "4\n1 2 3 4\n1 2\n2 3\n1 4\n", "4\n2 2 3 4\n1 2\n2 3\n2 4\n", "4\n1 2 3 4\n1 2\n1 3\n1 4\n", "4\n3 2 3 4\n1 2\n2 3\n2 4\n", "4\n1 2 3 4\n1 2\n1 3\n2 4\n", "4\n1 2 1 4\n1 2\n1 3\n2 4\n", "4\n1 2 1 4\n1 2\n1 3\n1 4\n"], "outputs": ["10 9 3 4\n", "10 5 3 4\n", "2 9 3 4\n", "10 2 ...
422
282
coding
Solve the programming task below in a Python markdown code block. Alice has an array A consisting of N distinct integers. Bob takes exactly N - 1 elements from this array and adds a positive integer X (i.e. X > 0) to each of these numbers and then shuffles them to form a new array B of length N - 1. You are given bot...
{"inputs": ["3\n4\n1 4 3 8\n15 8 11\n2\n4 8\n10\n2\n2 4\n3"], "outputs": ["7\n2\n1"]}
623
51
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, the depth of each node is the shortest distance to the root. Return the smallest subtree such that it contains all the deepest nodes in the original tree. A node is called the deepest ...
{"functional": "def check(candidate):\n assert is_same_tree(candidate(root = tree_node([3,5,1,6,2,0,8,None,None,7,4])), tree_node([2,7,4]))\n assert is_same_tree(candidate(root = tree_node([1])), tree_node([1]))\n assert is_same_tree(candidate(root = tree_node([0,1,3,None,2])), tree_node([2]))\n\n\ncheck(Solut...
185
113
coding
Solve the programming task below in a Python markdown code block. Let's call a sequence of integers $x_1, x_2, \dots, x_k$ MEX-correct if for all $i$ ($1 \le i \le k$) $|x_i - \operatorname{MEX}(x_1, x_2, \dots, x_i)| \le 1$ holds. Where $\operatorname{MEX}(x_1, \dots, x_k)$ is the minimum non-negative integer that doe...
{"inputs": ["4\n3\n0 2 1\n2\n1 0\n5\n0 0 0 0 0\n4\n0 1 2 3\n", "4\n3\n0 2 0\n2\n1 0\n5\n0 0 0 0 0\n4\n0 1 2 3\n", "4\n3\n0 2 1\n2\n1 0\n5\n0 0 0 0 0\n4\n0 1 1 3\n", "4\n3\n0 2 0\n2\n1 0\n5\n0 0 1 0 0\n4\n0 1 2 3\n", "4\n3\n0 2 1\n2\n1 1\n5\n0 0 0 0 0\n4\n0 1 1 3\n", "4\n3\n1 2 0\n2\n1 0\n5\n0 0 1 0 0\n4\n0 1 2 3\n", "4...
664
444
coding
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)"}
222
85
coding
Solve the programming task below in a Python markdown code block. Find the number of integers between 1 and K (inclusive) satisfying the following condition, modulo 10^9 + 7: * The sum of the digits in base ten is a multiple of D. Constraints * All values in input are integers. * 1 \leq K < 10^{10000} * 1 \leq D \le...
{"inputs": ["30\n1", "30\n2", "30\n8", "30\n4", "1000000009\n2", "1000000009\n4", "1000000009\n5", "1000000009\n9"], "outputs": ["30\n", "14\n", "3\n", "6", "500000004\n", "250000009\n", "200000001\n", "111111112\n"]}
206
151
coding
Solve the programming task below in a Python markdown code block. On the way to Rio de Janeiro Ostap kills time playing with a grasshopper he took with him in a special box. Ostap builds a line of length n such that some cells of this line are empty and some contain obstacles. Then, he places his grasshopper to one of ...
{"inputs": ["2 1\nGT\n", "2 1\nTG\n", "2 1\nTG\n", "2 1\nGT\n", "3 1\nTG#\n", "3 1\nGT#\n", "3 2\nG.T\n", "3 1\nTG#\n"], "outputs": ["YES\n", "YES\n", "YES\n", "YES\n", "YES\n", "YES\n", "YES\n", "YES\n"]}
615
106
coding
Solve the programming task below in a Python markdown code block. You are given Name of chef's friend and using chef's new method of calculating value of string , chef have to find the value of all the names. Since chef is busy , he asked you to do the work from him . The method is a function $f(x)$ as follows - - $f...
{"inputs": ["1\ncodechef"], "outputs": ["173"]}
324
18
coding
Solve the programming task below in a Python markdown code block. Chef has provided with a sequence of integers of length $N$ arranged in an unsorted fashion. The elements of the sequence are ordered as ${A1,A2,A3.....A'N}$ The task of the chef is to identify the highest and lowest value among the given sequence. It is...
{"inputs": ["5\n3 2 7 9 4"], "outputs": ["9 2"]}
260
24
coding
Solve the programming task below in a Python markdown code block. We have found a new chess character — pook. It has the qualities of both a rook and a pawn. Specifically, treating the chessboard to be an N\times N grid where (i, j) denotes the intersection of the i-th row and the j-th column, a pook placed at square (...
{"inputs": ["3\n1\n2\n3"], "outputs": ["1\n1\n2"]}
438
22
coding
Solve the programming task below in a Python markdown code block. Chef and Chefina are residing in a hotel. There are 10 floors in the hotel and each floor consists of 10 rooms. Floor 1 consists of room numbers 1 to 10. Floor 2 consists of room numbers 11 to 20. \ldots Floor i consists of room numbers 10 \cdot (i-1...
{"inputs": ["4\n1 100\n42 50\n53 30\n81 80\n"], "outputs": ["9\n0\n3\n1\n"]}
504
44
coding
Solve the programming task below in a Python markdown code block. There are N piles of candies on the table. The piles are numbered 1 through N. At first, pile i contains a_i candies. Snuke and Ciel are playing a game. They take alternating turns. Snuke goes first. In each turn, the current player must perform one of ...
{"inputs": ["2\n0 3", "2\n1 4", "2\n1 0", "2\n1 5", "2\n1 9", "2\n0 5", "2\n1 6", "2\n2 4"], "outputs": ["Second\n", "First\n", "Second\n", "First\n", "First\n", "Second\n", "First\n", "Second\n"]}
261
94
coding
Solve the programming task below in a Python markdown code block. A permutation p of size n is an array such that every integer from 1 to n occurs exactly once in this array. Let's call a permutation an almost identity permutation iff there exist at least n - k indices i (1 ≤ i ≤ n) such that p_{i} = i. Your task is ...
{"inputs": ["4 1\n", "4 2\n", "5 3\n", "5 4\n", "4 4\n", "4 4\n", "5 2\n", "8 3\n"], "outputs": ["1\n", "7\n", "31\n", "76\n", "24\n", "24\n", "11\n", "141\n"]}
182
93
coding
Solve the programming task below in a Python markdown code block. Sebi lives in Chefland where the government is extremely corrupt that usually makes fool out of public by announcing eye catching but non-sustainable schemes. Recently there was a move to increase tourism in the country that was highly lauded. Sebi wants...
{"inputs": ["3\n1 2 3\n1 3 2"], "outputs": ["2.333333"]}
715
31
coding
Solve the programming task below in a Python markdown code block. The fearless Ikta has finally hunted down the infamous Count Big Bridge! Count Bigbridge is now trapped in a rectangular room w meters wide and h meters deep, waiting for his end. If you select a corner of the room and take the coordinate system so that...
{"inputs": ["16 10 0 7 3 3 2 8", "7 18 1 20 6 3 1 7", "7 28 1 20 1 3 1 3", "7 28 1 40 6 3 1 3", "7 19 2 19 0 3 1 0", "17 9 3 19 3 3 1 0", "7 19 2 19 0 3 0 0", "17 9 3 19 3 2 1 0"], "outputs": ["0\n", "9\n", "12\n", "24\n", "28\n", "64\n", "32\n", "68\n"]}
479
196
coding
Solve the programming task below in a Python markdown code block. You are given a permutation of the numbers 1, 2, ..., n and m pairs of positions (a_{j}, b_{j}). At each step you can choose a pair from the given positions and swap the numbers in that positions. What is the lexicographically maximal permutation one ca...
{"inputs": ["1 1\n1\n1 1\n", "1 1\n1\n1 1\n", "3 1\n1 3 2\n1 2\n", "3 1\n3 2 1\n1 2\n", "3 1\n2 3 1\n1 1\n", "3 1\n3 2 1\n1 2\n", "3 1\n1 3 2\n1 2\n", "3 1\n2 3 1\n1 1\n"], "outputs": ["1\n", "1 \n", "3 1 2\n", "3 2 1\n", "2 3 1\n", "3 2 1 \n", "3 1 2 \n", "2 3 1 \n"]}
374
186
coding
Solve the programming task below in a Python markdown code block. Vova had a pretty weird sleeping schedule. There are $h$ hours in a day. Vova will sleep exactly $n$ times. The $i$-th time he will sleep exactly after $a_i$ hours from the time he woke up. You can assume that Vova woke up exactly at the beginning of thi...
{"inputs": ["1 10 0 9\n5\n", "1 10 0 9\n5\n", "2 24 21 22\n23 1\n", "2 24 14 16\n17 2\n", "4 3 0 0\n1 1 1 1\n", "2 24 22 23\n22 2\n", "4 3 0 0\n1 1 1 1\n", "2 24 22 23\n22 2\n"], "outputs": ["1\n", "1\n", "2\n", "1\n", "4\n", "2\n", "4\n", "2\n"]}
690
172
coding
Solve the programming task below in a Python markdown code block. ### Task: You have to write a function `pattern` which creates the following pattern (See Examples) upto desired number of rows. If the Argument is `0` or a Negative Integer then it should return `""` i.e. empty string. ### Examples: `pattern(9)`: ...
{"functional": "_inputs = [[7], [1], [4], [0], [-25]]\n_outputs = [['1234567\\n2345671\\n3456712\\n4567123\\n5671234\\n6712345\\n7123456'], ['1'], ['1234\\n2341\\n3412\\n4123'], [''], ['']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, ...
271
257
coding
Solve the programming task below in a Python markdown code block. There are N cities. There are also K roads and L railways, extending between the cities. The i-th road bidirectionally connects the p_i-th and q_i-th cities, and the i-th railway bidirectionally connects the r_i-th and s_i-th cities. No two roads connect...
{"inputs": ["4 3 0\n1 2\n2 3\n3 4\n2 3", "4 2 2\n2 2\n2 3\n1 4\n2 3", "4 2 2\n1 2\n2 3\n1 4\n1 3", "4 3 1\n1 3\n2 3\n3 4\n2 1", "4 3 0\n0 2\n2 3\n3 4\n2 3", "4 2 2\n2 2\n2 3\n1 4\n3 3", "6 3 0\n0 2\n4 3\n3 4\n5 3", "6 3 0\n0 0\n4 3\n3 4\n5 3"], "outputs": ["1 1 1 1\n", "1 2 2 1\n", "2 1 2 1\n", "2 2 1 1\n", "1 1 1 1\n"...
469
278
coding
Solve the programming task below in a Python markdown code block. Bob has a rectangular chocolate bar of the size W × H. He introduced a cartesian coordinate system so that the point (0, 0) corresponds to the lower-left corner of the bar, and the point (W, H) corresponds to the upper-right corner. Bob decided to split ...
{"inputs": ["100 100 1\n0 14 100 14\n", "2 7 2\n0 1 2 1\n0 3 2 3\n", "2 8 2\n0 1 2 1\n0 3 2 3\n", "2 2 2\n1 0 1 2\n1 1 2 1\n", "2 5 2\n0 1 2 1\n0 3 2 3\n", "2 9 2\n0 1 2 1\n0 3 2 3\n", "2 6 2\n0 1 2 1\n0 3 2 3\n", "2 4 2\n0 1 2 1\n0 3 2 3\n"], "outputs": ["1400 8600 \n", "2 4 8\n", "2 4 10\n", "1 1 2\n", "2 4 4\n", "2 ...
523
270
coding
Solve the programming task below in a Python markdown code block. There is an array with n elements a_1, a_2, ..., a_{n} and the number x. In one operation you can select some i (1 ≤ i ≤ n) and replace element a_{i} with a_{i} & x, where & denotes the bitwise and operation. You want the array to have at least two equ...
{"inputs": ["2 1\n3 5\n", "2 4\n1 2\n", "2 1\n2 4\n", "2 2\n4 5\n", "2 8\n2 3\n", "2 4\n2 3\n", "2 5\n1 3\n", "2 4\n1 2\n"], "outputs": ["2\n", "2\n", "2\n", "2\n", "2\n", "2\n", "1\n", "2\n"]}
383
118