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. Snuke has a large collection of cards. Each card has an integer between 1 and N, inclusive, written on it. He has A_i cards with an integer i. Two cards can form a pair if the absolute value of the difference of the integers written on them is at most 1...
{"inputs": ["4\n4\n0\n3\n1", "4\n3\n0\n3\n1", "4\n0\n0\n3\n1", "4\n0\n0\n0\n1", "4\n0\n0\n1\n1", "4\n0\n0\n6\n1", "4\n0\n1\n6\n1", "4\n0\n1\n6\n0"], "outputs": ["4\n", "3\n", "2\n", "0\n", "1\n", "3\n", "4\n", "3\n"]}
240
126
coding
Solve the programming task below in a Python markdown code block. Kirito is stuck on a level of the MMORPG he is playing now. To move on in the game, he's got to defeat all n dragons that live on this level. Kirito and the dragons have strength, which is represented by an integer. In the duel between two opponents the ...
{"inputs": ["5 1\n6 7\n", "10 1\n1 1\n", "10 1\n1 2\n", "11 1\n1 2\n", "11 1\n2 2\n", "10 1\n10 0\n", "10 1\n14 0\n", "10 1\n10 10\n"], "outputs": ["NO\n", "YES\n", "YES\n", "YES\n", "YES\n", "NO\n", "NO\n", "NO\n"]}
454
129
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a string s containing only lowercase English letters and the '?' character, convert all the '?' characters into lowercase letters such that the final string does not contain any consecutive repeating characters....
{"functional": "def check(candidate):\n assert candidate(s = \"?zs\") == \"azs\"\n assert candidate(s = \"ubv?w\") == \"ubvaw\"\n\n\ncheck(Solution().modifyString)"}
152
52
coding
Solve the programming task below in a Python markdown code block. Bob is a lazy man. He needs you to create a method that can determine how many ```letters``` and ```digits``` are in a given string. Example: "hel2!lo" --> 6 "wicked .. !" --> 6 "!?..A" --> 1 Also feel free to reuse/extend the following starter c...
{"functional": "_inputs = [['n!!ice!!123'], ['de?=?=tttes!!t'], [''], ['!@#$%^&`~.'], ['u_n_d_e_r__S_C_O_R_E']]\n_outputs = [[7], [8], [0], [0], [10]]\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 is...
97
210
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. A triplet is an array of three integers. You are given a 2D integer array triplets, where triplets[i] = [ai, bi, ci] describes the ith triplet. You are also given an integer array target = [x, y, z] that describes the...
{"functional": "def check(candidate):\n assert candidate(triplets = [[2,5,3],[1,8,4],[1,7,5]], target = [2,7,5]) == True\n assert candidate(triplets = [[1,3,4],[2,5,8]], target = [2,5,8]) == True\n assert candidate(triplets = [[2,5,3],[2,3,4],[1,2,5],[5,2,3]], target = [5,5,5]) == True\n assert candidate(tr...
287
166
coding
Solve the programming task below in a Python markdown code block. Little boy Valera studies an algorithm of sorting an integer array. After studying the theory, he went on to the practical tasks. As a result, he wrote a program that sorts an array of n integers a_1, a_2, ..., a_{n} in the non-decreasing order. The pseu...
{"inputs": ["1\n", "2\n", "3\n", "4\n", "5\n", "6\n", "7\n", "8\n"], "outputs": ["-1\n", "-1\n", "3 2 1 ", "4 3 2 1 ", "5 4 3 2 1 ", "6 5 4 3 2 1 ", "7 6 5 4 3 2 1 ", "8 7 6 5 4 3 2 1 "]}
374
120
coding
Solve the programming task below in a Python markdown code block. There is a country with n citizens. The i-th of them initially has a_{i} money. The government strictly controls the wealth of its citizens. Whenever a citizen makes a purchase or earns some money, they must send a receipt to the social services mentioni...
{"inputs": ["4\n1 2 3 4\n2\n2 3\n2 2\n", "4\n1 2 3 4\n2\n2 3\n2 1\n", "4\n1 2 3 8\n2\n2 3\n2 1\n", "4\n2 4 3 8\n2\n2 3\n2 1\n", "4\n1 2 3 4\n2\n2 3\n2 4\n", "4\n1 2 3 0\n2\n2 3\n2 1\n", "4\n0 2 5 4\n2\n2 3\n2 1\n", "4\n1 2 4 0\n2\n2 3\n2 1\n"], "outputs": ["3 3 3 4\n", "3 3 3 4\n", "3 3 3 8\n", "3 4 3 8\n", "4 4 4 4\n"...
553
262
coding
Solve the programming task below in a Python markdown code block. Read problem statements in [Russian] and [Mandarin Chinese]. You are given two integers A, B. You have to choose an integer X in the range [minimum(A, B), maximum(A, B)] such that: \Big \lceil \frac{B - X}{2} \Big \rceil + \Big \lceil \frac{X - A}{2} ...
{"inputs": ["3\n2 2\n1 11\n13 6\n"], "outputs": ["0\n6\n-3"]}
601
32
coding
Solve the programming task below in a Python markdown code block. A card pyramid of height $1$ is constructed by resting two cards against each other. For $h>1$, a card pyramid of height $h$ is constructed by placing a card pyramid of height $h-1$ onto a base. A base consists of $h$ pyramids of height $1$, and $h-1$ ca...
{"inputs": ["1\n1000000000\n", "1\n1000000000\n", "1\n1000001000\n", "1\n1000011000\n", "1\n0001011001\n", "1\n0001001000\n", "1\n1000011001\n", "1\n0000011001\n"], "outputs": ["6\n", "6\n", "6\n", "5\n", "4\n", "3\n", "6\n", "6\n"]}
494
158
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a string s, return the length of the longest substring that contains at most two distinct characters.   Please complete the following python code precisely: ```python class Solution: def lengthOfLongestSubst...
{"functional": "def check(candidate):\n assert candidate(s = \"eceba\") == 3\n assert candidate(s = \"ccaabbb\") == 5\n\n\ncheck(Solution().lengthOfLongestSubstringTwoDistinct)"}
72
51
coding
Solve the programming task below in a Python markdown code block. Teddy and Tracy like to play a game based on strings. The game is as follows. Initially, Tracy writes a long random string on a whiteboard. Then, each player starting with Teddy makes turn alternately. Each turn, the player must erase a contiguous substr...
{"inputs": ["3\ncodechef\n2\ncode\nchef\nfoo\n1\nbar\nmississippi\n4\nssissi\nmippi\nmi\nppi\n\n"], "outputs": ["Tracy\nTracy\nTeddy"]}
367
55
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an integer array nums, return the maximum difference between two successive elements in its sorted form. If the array contains less than two elements, return 0. You must write an algorithm that runs in linear ti...
{"functional": "def check(candidate):\n assert candidate(nums = [3,6,9,1]) == 3\n assert candidate(nums = [10]) == 0\n\n\ncheck(Solution().maximumGap)"}
96
50
coding
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"]}
120
62
coding
Solve the programming task below in a Python markdown code block. There is a grass field that stretches infinitely. In this field, there is a negligibly small cow. Let (x, y) denote the point that is x\ \mathrm{cm} south and y\ \mathrm{cm} east of the point where the cow stands now. The cow itself is standing at (0, 0)...
{"inputs": ["3 1\n-3 -1 0\n-3 0 1\n-2 0 2\n1 4 -2\n1 6 -1\n1 4 1\n3 1 0", "3 1\n-3 -1 0\n-6 0 1\n-2 0 2\n1 4 -2\n1 6 -1\n1 4 1\n3 1 0", "3 1\n-3 -1 0\n-6 1 1\n-2 0 2\n1 4 -2\n1 6 -1\n1 4 1\n3 1 0", "3 1\n-3 -1 0\n-6 1 1\n-2 0 2\n1 4 -2\n1 2 -1\n1 4 1\n3 1 0", "3 0\n-3 -1 0\n-3 0 1\n-2 0 2\n1 4 -2\n1 6 -1\n1 4 1\n3 1 0"...
514
438
coding
Solve the programming task below in a Python markdown code block. Ashish has an array $a$ of size $n$. A subsequence of $a$ is defined as a sequence that can be obtained from $a$ by deleting some elements (possibly none), without changing the order of the remaining elements. Consider a subsequence $s$ of $a$. He defi...
{"inputs": ["2 2\n5 10\n", "2 2\n5 10\n", "4 2\n1 2 3 4\n", "4 3\n1 2 3 4\n", "4 2\n1 3 3 4\n", "4 2\n1 2 3 4\n", "4 3\n1 2 3 4\n", "5 3\n5 3 4 2 6\n"], "outputs": ["5", "5\n", "1", "2", "1\n", "1\n", "2\n", "2"]}
624
142
coding
Solve the programming task below in a Python markdown code block. Diameter of a Tree Given a tree T with non-negative weight, find the diameter of the tree. The diameter of a tree is the maximum distance between two nodes in a tree. Constraints * 1 ≤ n ≤ 100,000 * 0 ≤ wi ≤ 1,000 Input n s1 t1 w1 s2 t2 w2 : sn...
{"inputs": ["4\n0 1 1\n1 3 2\n2 3 4", "4\n0 1 1\n1 2 1\n1 3 3", "4\n0 1 2\n1 3 2\n2 3 4", "4\n0 1 1\n1 3 1\n2 3 4", "4\n0 1 1\n1 3 0\n2 3 4", "4\n0 1 1\n1 3 1\n2 3 0", "4\n0 1 0\n2 2 2\n2 3 4", "4\n0 1 2\n1 3 1\n2 3 0"], "outputs": ["7\n", "4\n", "8\n", "6\n", "5\n", "2\n", "0\n", "3\n"]}
252
206
coding
Solve the programming task below in a Python markdown code block. Snuke loves working out. He is now exercising N times. Before he starts exercising, his power is 1. After he exercises for the i-th time, his power gets multiplied by i. Find Snuke's power after he exercises N times. Since the answer can be extremely lar...
{"inputs": ["1", "6", "4", "7", "2", "8", "5", "9"], "outputs": ["1\n", "720\n", "24\n", "5040\n", "2\n", "40320\n", "120\n", "362880\n"]}
216
79
coding
Solve the programming task below in a Python markdown code block. Define the score of some binary string $T$ as the absolute difference between the number of zeroes and ones in it. (for example, $T=$ 010001 contains $4$ zeroes and $2$ ones, so the score of $T$ is $|4-2| = 2$). Define the creepiness of some binary stri...
{"inputs": ["5\n1 1\n1 2\n5 2\n4 5\n3 7\n"], "outputs": ["01\n011\n0101000\n010101011\n0101011111\n"]}
487
68
coding
Solve the programming task below in a Python markdown code block. We have an undirected graph G with N vertices numbered 1 to N and N edges as follows: - For each i=1,2,...,N-1, there is an edge between Vertex i and Vertex i+1. - There is an edge between Vertex X and Vertex Y. For each k=1,2,...,N-1, solve the proble...
{"inputs": ["4 1 3", "7 3 4", "9 2 4", "3 2 3", "5 1 4", "4 1 2", "8 4 5", "6 1 3"], "outputs": ["4\n2\n0\n", "6\n5\n4\n3\n2\n1\n", "9\n8\n6\n5\n4\n3\n1\n0\n", "2\n1\n", "5\n4\n1\n0\n", "3\n2\n1\n", "7\n6\n5\n4\n3\n2\n1\n", "6\n4\n3\n2\n0\n"]}
463
154
coding
Solve the programming task below in a Python markdown code block. Chef appeared for an exam consisting of 3 sections. Each section is worth 100 marks. Chef scored A marks in Section 1, B marks in section 2, and C marks in section 3. Chef passes the exam if both of the following conditions satisfy: Total score of Che...
{"inputs": ["5\n9 100 100\n30 40 50\n30 20 40\n0 98 8\n90 80 80\n"], "outputs": ["FAIL\nPASS\nFAIL\nFAIL\nPASS\n"]}
481
66
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an integer n indicating there are n people numbered from 0 to n - 1. You are also given a 0-indexed 2D integer array meetings where meetings[i] = [xi, yi, timei] indicates that person xi and person yi ha...
{"functional": "def check(candidate):\n assert candidate(n = 6, meetings = [[1,2,5],[2,3,8],[1,5,10]], firstPerson = 1) == [0,1,2,3,5]\n assert candidate(n = 4, meetings = [[3,1,3],[1,2,2],[0,3,3]], firstPerson = 3) == [0,1,3]\n assert candidate(n = 5, meetings = [[3,4,2],[1,2,1],[2,3,1]], firstPerson = 1) == ...
273
160
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a string s that contains digits 0-9, addition symbols '+', and multiplication symbols '*' only, representing a valid math expression of single digit numbers (e.g., 3+5*2). This expression was given to n ...
{"functional": "def check(candidate):\n assert candidate(s = \"7+3*1*2\", answers = [20,13,42]) == 7\n assert candidate(s = \"3+5*2\", answers = [13,0,10,13,13,16,16]) == 19\n assert candidate(s = \"6+0*1\", answers = [12,9,6,4,8,6]) == 10\n\n\ncheck(Solution().scoreOfStudents)"}
256
123
coding
Solve the programming task below in a Python markdown code block. In Chefland, a tax of rupees 10 is deducted if the total income is strictly greater than rupees 100. Given that total income is X rupees, find out how much money you get. ------ Input Format ------ - The first line of input will contain a single int...
{"inputs": ["4\n5\n105\n101\n100\n"], "outputs": ["5\n95\n91\n100"]}
411
37
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a 0-indexed integer array nums. The concatenation of two numbers is the number formed by concatenating their numerals. For example, the concatenation of 15, 49 is 1549. The concatenation value of nums ...
{"functional": "def check(candidate):\n assert candidate(nums = [7,52,2,4]) == 596\n assert candidate(nums = [5,14,13,8,12]) == 673\n\n\ncheck(Solution().findTheArrayConcVal)"}
198
69
coding
Solve the programming task below in a Python markdown code block. The ancient Berlanders believed that the longer the name, the more important its bearer is. Thus, Berland kings were famous for their long names. But long names are somewhat inconvenient, so the Berlanders started to abbreviate the names of their kings. ...
{"inputs": ["3\naa\nc\ndef\n", "3\nba\nb\nfde\n", "3\naa\nc\nedf\n", "3\naa\nb\nedf\n", "3\naa\nb\nfde\n", "3\nba\nc\nfde\n", "3\nab\nc\ndef\n", "3\nab\nacb\nba\n"], "outputs": ["2\n", "1\n", "2\n", "2\n", "2\n", "1\n", "1\n", "5\n"]}
673
123
coding
Solve the programming task below in a Python markdown code block. The "BerCorp" company has got n employees. These employees can use m approved official languages for the formal correspondence. The languages are numbered with integers from 1 to m. For each employee we have the list of languages, which he knows. This li...
{"inputs": ["2 2\n0\n0\n", "3 3\n0\n0\n0\n", "2 2\n1 2\n0\n", "2 2\n1 2\n1 1\n", "3 100\n0\n0\n0\n", "2 3\n1 2\n1 1\n", "3 101\n0\n0\n0\n", "3 001\n0\n0\n0\n"], "outputs": ["2\n", "3\n", "1\n", "1\n", "3\n", "1\n", "3\n", "3\n"]}
476
142
coding
Solve the programming task below in a Python markdown code block. The Utopian Tree goes through 2 cycles of growth every year. Each spring, it doubles in height. Each summer, its height increases by 1 meter. A Utopian Tree sapling with a height of 1 meter is planted at the onset of spring. How tall will the tree be af...
{"inputs": ["3\n0\n1\n4\n"], "outputs": ["1\n2\n7\n"]}
451
24
coding
Solve the programming task below in a Python markdown code block. You want to make change for $ n $ cents. Assuming that you have infinite supply of coins of 1, 5, 10 and / or 25 cents coins respectively, find the minimum number of coins you need. Constraints * $ 1 \ le n \ le 10 ^ 9 $ Input $ n $ The integer $ ...
{"inputs": ["40", "41", "000", "010", "110", "111", "011", "581"], "outputs": ["3\n", "4\n", "0\n", "1\n", "5\n", "6\n", "2\n", "25\n"]}
136
77
coding
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin Chinese and Russian. You are given two positive integers – A and B. You have to check whether A is divisible by all the prime divisors of B. ------ Input ------ The first line of the input contains an integer T ...
{"inputs": ["3\n215 16\n12 4\n4 4", "3\n153 7\n20 16\n3 5", "3\n120 16\n128 4\n4 4", "3\n215 16\n128 4\n4 4", "3\n215 16\n128 8\n4 4", "3\n153 75\n20 16\n3 3", "3\n215 16\n128 8\n6 4", "3\n153 29\n20 16\n3 3"], "outputs": ["No\nYes\nYes\n", "No\nYes\nNo\n", "Yes\nYes\nYes\n", "No\nYes\nYes\n", "No\nYes\nYes\n", "No\nYe...
386
228
coding
Solve the programming task below in a Python markdown code block. Galya is playing one-dimensional Sea Battle on a 1 × n grid. In this game a ships are placed on the grid. Each of the ships consists of b consecutive cells. No cell can be part of two ships, however, the ships can touch each other. Galya doesn't know th...
{"inputs": ["1 1 1 0\n0\n", "1 1 1 0\n0\n", "2 2 1 0\n00\n", "2 2 1 0\n00\n", "5 1 2 1\n00100\n", "5 4 1 0\n00000\n", "5 1 2 1\n00100\n", "5 4 1 0\n00000\n"], "outputs": ["1\n1 \n", "1\n1 ", "1\n1 \n", "1\n1 \n", "2\n2 5 \n", "2\n1 2 \n", "2\n2 5\n", "2\n1 2 \n"]}
530
181
coding
Solve the programming task below in a Python markdown code block. Polycarp has just invented a new binary protocol for data transmission. He is encoding positive integer decimal number to binary string using following algorithm: Each digit is represented with number of '1' characters equal to the value of that digit...
{"inputs": ["1\n1\n", "1\n1\n", "2\n10\n", "2\n10\n", "3\n111\n", "3\n100\n", "3\n100\n", "3\n110\n"], "outputs": ["1\n", "1\n", "10\n", "10\n", "3\n", "100\n", "100\n", "20\n"]}
245
103
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a string num, representing a large integer, and an integer k. We call some integer wonderful if it is a permutation of the digits in num and is greater in value than num. There can be many wonderful inte...
{"functional": "def check(candidate):\n assert candidate(num = \"5489355142\", k = 4) == 2\n assert candidate(num = \"11112\", k = 4) == 4\n assert candidate(num = \"00123\", k = 1) == 1\n\n\ncheck(Solution().getMinSwaps)"}
253
89
coding
Solve the programming task below in a Python markdown code block. Consider sequences \{A_1,...,A_N\} of length N consisting of integers between 1 and K (inclusive). There are K^N such sequences. Find the sum of \gcd(A_1, ..., A_N) over all of them. Since this sum can be enormous, print the value modulo (10^9+7). Here \...
{"inputs": ["5 2", "5 1", "7 2", "5 0", "8 5", "3 3", "1 2", "6 5"], "outputs": ["33\n", "1\n", "129\n", "0\n", "390889\n", "30\n", "3\n", "15697\n"]}
316
91
coding
Solve the programming task below in a Python markdown code block. There are N piles where the i^{th} pile consists of A_{i} stones. Chef and Chefina are playing a game taking alternate turns with Chef starting first. In his/her turn, a player can choose any non-empty pile and remove exactly 1 stone from it. The ga...
{"inputs": ["2\n2\n5 10\n3\n1 1 3\n"], "outputs": ["CHEF\nCHEFINA\n"]}
409
34
coding
Solve the programming task below in a Python markdown code block. Chef loves saving money and he trusts none other bank than State Bank of Chefland. Unsurprisingly, the employees like giving a hard time to their customers. But instead of asking them to stand them in long queues, they have weird way of accepting money. ...
{"inputs": ["4\n1\n2\n3\n4"], "outputs": ["1\n1\n1 2\n3\n1 2 4\n7\n1 2 4 8\n15"]}
632
47
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an array of integers temperatures represents the daily temperatures, return an array answer such that answer[i] is the number of days you have to wait after the ith day to get a warmer temperature. If there is n...
{"functional": "def check(candidate):\n assert candidate(temperatures = [73,74,75,71,69,72,76,73]) == [1,1,4,2,1,1,0,0]\n assert candidate(temperatures = [30,40,50,60]) == [1,1,1,0]\n assert candidate(temperatures = [30,60,90]) == [1,1,0]\n\n\ncheck(Solution().dailyTemperatures)"}
111
132
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 upto n number of rows. * If the Argument is 0 or a Negative Integer then it should return "" i.e. empty string. * If any odd number is passed as argument then the pa...
{"functional": "_inputs = [[2], [1], [5], [6], [0], [-25]]\n_outputs = [['22'], [''], ['22\\n4444'], ['22\\n4444\\n666666'], [''], ['']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (l...
204
204
coding
Solve the programming task below in a Python markdown code block. You are given integers N and K. Find the number of triples (a,b,c) of positive integers not greater than N such that a+b,b+c and c+a are all multiples of K. The order of a,b,c does matter, and some of them can be the same. -----Constraints----- - 1 \le...
{"inputs": ["3 2\n", "5 3\n", "1 1\n", "10003 8\n", "200000 1\n", "200000 2\n", "200000 3\n", "1 200000\n"], "outputs": ["9\n", "1\n", "1\n", "3906250000\n", "8000000000000000\n", "2000000000000000\n", "296287407496296\n", "0\n"]}
229
163
coding
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin and Russian. Translations in Vietnamese to be uploaded soon. You have a matrix of size N * N with rows numbered through 1 to N from top to bottom and columns through 1 to N from left to right. It contains all values...
{"inputs": ["2\n2\n1 3\n2 4\n3\n1 7 9\n2 4 8\n3 6 5", "2\n2\n1 3\n2 4\n3\n2 7 9\n1 4 8\n3 6 5", "2\n2\n1 3\n2 4\n3\n1 7 9\n3 4 8\n2 6 5", "2\n2\n1 3\n2 4\n3\n1 7 9\n2 4 8\n6 3 5", "2\n2\n1 3\n2 4\n3\n1 7 5\n2 4 8\n6 3 9", "2\n2\n2 3\n1 4\n3\n2 7 9\n1 4 8\n3 6 5", "2\n2\n1 3\n2 4\n3\n2 7 9\n1 3 8\n4 6 5", "2\n2\n1 3\n2 ...
625
325
coding
Solve the programming task below in a Python markdown code block. You will be given an array of numbers. For each number in the array you will need to create an object. The object key will be the number, as a string. The value will be the corresponding character code, as a string. Return an array of the resulting o...
{"functional": "_inputs = [[[118, 117, 120]], [[101, 121, 110, 113, 113, 103]], [[118, 103, 110, 109, 104, 106]], [[107, 99, 110, 107, 118, 106, 112, 102]], [[100, 100, 116, 105, 117, 121]]]\n_outputs = [[[{'118': 'v'}, {'117': 'u'}, {'120': 'x'}]], [[{'101': 'e'}, {'121': 'y'}, {'110': 'n'}, {'113': 'q'}, {'113': 'q'}...
116
533
coding
Solve the programming task below in a Python markdown code block. Chef is buying sweet things to prepare for Halloween! The shop sells both chocolate and candy. Each bar of chocolate has a tastiness of X. Each piece of candy has a tastiness of Y. One packet of chocolate contains 2 bars, while one packet of candy cont...
{"inputs": ["4\n5 1\n5 2\n5 3\n3 10\n"], "outputs": ["Chocolate\nEither\nCandy\nCandy\n"]}
569
39
coding
Solve the programming task below in a Python markdown code block. A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≤ pi ≤ n). A lucky permutation is such permutation p, that any integer i (1 ≤ i ≤ n) meets this condition ppi = n - i + 1. You ...
{"inputs": ["7\n", "9\n", "8\n", "3\n", "6\n", "1\n", "5\n", "4\n"], "outputs": ["-1", "2 9 4 7 5 3 6 1 8 ", "2 8 4 6 3 5 1 7 ", "-1", "-1", "1 ", "2 5 3 1 4 ", "2 4 1 3 "]}
236
108
coding
Solve the programming task below in a Python markdown code block. There is a long plate s containing n digits. Iahub wants to delete some digits (possibly none, but he is not allowed to delete all the digits) to form his "magic number" on the plate, a number that is divisible by 5. Note that, the resulting number may c...
{"inputs": ["14\n2\n", "14\n3\n", "555\n2\n", "555\n4\n", "555\n6\n", "555\n9\n", "14\n66\n", "14\n95\n"], "outputs": ["0\n", "0\n", "63\n", "4095\n", "262143\n", "134217727\n", "0\n", "0\n"]}
405
117
coding
Solve the programming task below in a Python markdown code block. Vasya has recently developed a new algorithm to optimize the reception of customer flow and he considered the following problem. Let the queue to the cashier contain n people, at that each of them is characterized by a positive integer ai — that is the ...
{"inputs": ["1\n10\n", "1\n20\n", "1\n25\n", "2\n3 5\n", "2\n3 7\n", "3\n1 10 1\n", "3\n1 10 0\n", "3\n2 10 0\n"], "outputs": ["10\n1\n", "20\n1\n", "25\n1\n", "5\n1 2\n", "7\n1 2\n", "11\n1 2\n3\n", "10\n1 2\n3\n", "10\n1 2\n3\n"]}
550
146
coding
Solve the programming task below in a Python markdown code block. Asmany strings are strings of '0's and '1's that have as many 00 as 11. A string such as 00110001 consists of 3 "00" and 1 "11". Of course this is not an Asmany string. 0011, 1100, 000111000111 are Asmany strings. An L'th Asmany number is the number of A...
{"inputs": ["2\n3\n4", "2\n1\n4", "2\n2\n4", "2\n2\n1", "2\n1\n1", "2\n4\n4", "2\n5\n4", "2\n1\n6"], "outputs": ["NO\nYES", "NO\nYES\n", "YES\nYES\n", "YES\nNO\n", "NO\nNO\n", "YES\nYES\n", "NO\nYES\n", "NO\nYES\n"]}
384
109
coding
Solve the programming task below in a Python markdown code block. Eugene has to do his homework. But today, he is feeling very lazy and wants to you do his homework. His homework has the following given maths problem. You are given three integers: A, N, M. You write the number A appended to itself N times in a row. Let...
{"inputs": ["2\n12 2 17\n523 3 11\n\n"], "outputs": ["5\n6"]}
432
33
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an integer columnNumber, return its corresponding column title as it appears in an Excel sheet. For example: A -> 1 B -> 2 C -> 3 ... Z -> 26 AA -> 27 AB -> 28 ...   Please complete the following python code ...
{"functional": "def check(candidate):\n assert candidate(columnNumber = 1) == \"A\"\n assert candidate(columnNumber = 28) == \"AB\"\n assert candidate(columnNumber = 701) == \"ZY\"\n assert candidate(columnNumber = 2147483647) == \"FXSHRXW\"\n\n\ncheck(Solution().convertToTitle)"}
106
91
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a string s and an integer k, reverse the first k characters for every 2k characters counting from the start of the string. If there are fewer than k characters left, reverse all of them. If there are less than 2...
{"functional": "def check(candidate):\n assert candidate(s = \"abcdefg\", k = 2) == \"bacdfeg\"\n assert candidate(s = \"abcd\", k = 2) == \"bacd\"\n\n\ncheck(Solution().reverseStr)"}
123
59
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. In this problem, a rooted tree is a directed graph such that, there is exactly one node (the root) for which all other nodes are descendants of this node, plus every node has exactly one parent, except for the root no...
{"functional": "def check(candidate):\n assert candidate(edges = [[1,2],[1,3],[2,3]]) == [2,3]\n assert candidate(edges = [[1,2],[2,3],[3,4],[4,1],[1,5]]) == [4,1]\n\n\ncheck(Solution().findRedundantDirectedConnection)"}
248
81
coding
Solve the programming task below in a Python markdown code block. In the new world, we also have a new system called Cybalphabit system. The system assigns points to each Latin lowercase alphabet as follows:- 'a' is assigned $2^{0}$ , 'b' is assigned $2^{1}$, 'c' $2^{2}$ and so on. Thus, finally 'z' is assigned $2^{25}...
{"inputs": ["4\n2 2\n2 5\n4 5\n3 2"], "outputs": ["aa\nac\nbaaa\n-1"]}
557
36
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an absolute path for a Unix-style file system, which always begins with a slash '/'. Your task is to transform this absolute path into its simplified canonical path. The rules of a Unix-style file system...
{"functional": "def check(candidate):\n assert candidate(path = \"/home/\") == \"/home\"\n assert candidate(path = \"/../\") == \"/\"\n assert candidate(path = \"/home//foo/\") == \"/home/foo\"\n assert candidate(path = \"/a/./b/../../c/\") == \"/c\"\n\n\ncheck(Solution().simplifyPath)"}
249
91
coding
Solve the programming task below in a Python markdown code block. Example Input 4 Durett 7 Gayles 3 Facenda 6 Daughtery 0 1 + Mccourtney 2 Output Mccourtney is not working now. Durett is working hard now.
{"inputs": ["4\nDurett 7\nGayles 3\nFacenda 6\nyrethguaD 0\n1\n+ Mccourtney 2", "4\nDurett 7\nGayles 3\nFacenda 6\nDaughtery 0\n1\n+ yentruoccM 3", "4\nDurett 7\nGaylds 3\nFbccnda 2\nyrethguaD 0\n1\n+ yeotruoccM 2", "4\nDurett 7\nGaylds 3\nFbccnda 2\nyrdthguaD 0\n1\n+ yeMtruocco 2", "4\nDurett 7\nGaylds 3\nFbccnda 2\ny...
70
474
coding
Solve the programming task below in a Python markdown code block. Read problem statements in [Russian] and [Mandarin Chinese]. Find the minimum integer K such that sum of bits present on odd positions in binary representation of all integers from 1 to K is greater than or equal to N. The bits are enumerated from left...
{"inputs": ["3\n2\n6\n100"], "outputs": ["2\n5\n57"]}
450
25
coding
Solve the programming task below in a Python markdown code block. You have to write two methods to *encrypt* and *decrypt* strings. Both methods have two parameters: ``` 1. The string to encrypt/decrypt 2. The Qwerty-Encryption-Key (000-999) ``` The rules are very easy: ``` The crypting-regions are these 3 lines from...
{"functional": "_inputs = [['A', 111], ['Abc', 212], ['Ball', 134], ['Ball', 444], ['This is a test.', 348], ['Do the kata Kobayashi Maru Test. Endless fun and excitement when finding a solution.', 583]]\n_outputs = [['S'], ['Smb'], ['>fdd'], ['>gff'], ['Iaqh qh g iyhi,'], ['Sr pgi jlpl Jr,lqlage Zlow Piapc I.skiaa dw....
635
286
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Suppose we have a file system that stores both files and directories. An example of one system is represented in the following picture: Here, we have dir as the only directory in the root. dir contains two subdirecto...
{"functional": "def check(candidate):\n assert candidate(input = \"dir\\n\\tsubdir1\\n\\tsubdir2\\n\\t\\tfile.ext\") == 20\n assert candidate(input = \"dir\\n\\tsubdir1\\n\\t\\tfile1.ext\\n\\t\\tsubsubdir1\\n\\tsubdir2\\n\\t\\tsubsubdir2\\n\\t\\t\\tfile2.ext\") == 32\n assert candidate(input = \"a\") == 0\n ...
438
160
coding
Solve the programming task below in a Python markdown code block. Mitya has a rooted tree with n vertices indexed from 1 to n, where the root has index 1. Each vertex v initially had an integer number a_v ≥ 0 written on it. For every vertex v Mitya has computed s_v: the sum of all values written on the vertices on the ...
{"inputs": ["2\n1\n1 -1\n", "2\n1\n0 -1\n", "2\n1\n6 -1\n", "2\n1\n2 -1\n", "2\n1\n4 -1\n", "2\n1\n7 -1\n", "2\n1\n3 -1\n", "2\n1\n12 -1\n"], "outputs": ["1\n", "0\n", "6\n", "2\n", "4\n", "7\n", "3\n", "12\n"]}
426
120
coding
Solve the programming task below in a Python markdown code block. Bob is a competitive programmer. He wants to become red, and for that he needs a strict training regime. He went to the annual meeting of grandmasters and asked $n$ of them how much effort they needed to reach red. "Oh, I just spent $x_i$ hours solving ...
{"inputs": ["1\n8\n", "1\n2\n", "1\n13\n", "1\n15\n", "1\n26\n", "1\n76\n", "1\n900\n", "1\n300\n"], "outputs": ["cyan\n", "cyan\n", "cyan\n", "cyan\n", "cyan\n", "cyan\n", "red\n", "red\n"]}
702
94
coding
Solve the programming task below in a Python markdown code block. Chef and Chefina are playing with dice. In one turn, both of them roll their dice at once. They consider a turn to be *good* if the sum of the numbers on their dice is greater than 6. Given that in a particular turn Chef and Chefina got X and Y on the...
{"inputs": ["4\n1 4\n3 4\n4 2\n2 6\n"], "outputs": ["NO\nYES\nNO\nYES\n"]}
410
36
coding
Solve the programming task below in a Python markdown code block. Iahub helps his grandfather at the farm. Today he must milk the cows. There are n cows sitting in a row, numbered from 1 to n from left to right. Each cow is either facing to the left or facing to the right. When Iahub milks a cow, all the cows that see ...
{"inputs": ["1\n0\n", "1\n1\n", "1\n2\n", "1\n3\n", "1\n5\n", "1\n4\n", "1\n8\n", "1\n9\n"], "outputs": ["0", "0", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]}
445
84
coding
Solve the programming task below in a Python markdown code block. A post on facebook is said to be more *popular* if the number of likes on the post is strictly greater than the number of likes on some other post. In case the number of likes is same, the post having more comments is more *popular*. Given arrays A and ...
{"inputs": ["4\n3\n5 4 4\n1 2 3\n3\n10 10 9\n2 5 4\n3\n3 3 9\n9 1 3\n4\n2 8 1 5\n2 8 1 9\n"], "outputs": ["1\n2\n3\n2\n"]}
642
82
coding
Solve the programming task below in a Python markdown code block. Every college has a stud−max$stud-max$ buoy. JGEC$JGEC$ has its own Atul$Atul$ who loves to impress everyone with his smile. A presentation is going on at the auditorium where there are N$N$ rows of M$M$ chairs with people sitting on it. Everyone votes f...
{"inputs": ["1\n4 4 3\n1 4 5 7\n2 3 8 6\n1 4 8 9\n5 1 5 6"], "outputs": ["22"]}
441
51
coding
Solve the programming task below in a Python markdown code block. Once upon a time in the thicket of the mushroom forest lived mushroom gnomes. They were famous among their neighbors for their magic mushrooms. Their magic nature made it possible that between every two neighboring mushrooms every minute grew another mus...
{"inputs": ["1 1 1 2\n0\n", "1 1 1 2\n2\n", "1 1 0 2\n1\n", "1 1 2 2\n0\n", "1 1 2 2\n1\n", "1 1 0 2\n2\n", "1 1 1 2\n1\n", "1 0 1 2\n1\n"], "outputs": ["0", "0", "1", "0\n", "1\n", "0\n", "1\n", "1\n"]}
471
131
coding
Solve the programming task below in a Python markdown code block. Create a function which checks a number for three different properties. - is the number prime? - is the number even? - is the number a multiple of 10? Each should return either true or false, which should be given as an array. Remark: The Haskell varia...
{"functional": "_inputs = [[0], [2], [5], [25], [131], [1], [100], [179424691], [179424693]]\n_outputs = [[[False, True, True]], [[True, True, False]], [[True, False, False]], [[False, False, False]], [[True, False, False]], [[False, False, False]], [[False, True, True]], [[True, False, False]], [[False, False, False]]...
206
259
coding
Solve the programming task below in a Python markdown code block. The chef is trying to decode some pattern problems, Chef wants your help to code it. Chef has one number K to form a new pattern. Help the chef to code this pattern problem. -----Input:----- - First-line will contain $T$, the number of test cases. Then ...
{"inputs": ["4\n1\n2\n3\n4"], "outputs": ["0\n01\n10\n010\n101\n010\n0101\n1010\n0101\n1010"]}
216
58
coding
Solve the programming task below in a Python markdown code block. A new entertainment has appeared in Buryatia — a mathematical circus! The magician shows two numbers to the audience — $n$ and $k$, where $n$ is even. Next, he takes all the integers from $1$ to $n$, and splits them all into pairs $(a, b)$ (each integer ...
{"inputs": ["1\n200000 618391804\n", "4\n4 1\n2 0\n12 10\n14 11\n"], "outputs": ["NO\n", "YES\n1 2\n3 4\nNO\nYES\n3 4\n7 8\n11 12\n2 1\n6 5\n10 9\nYES\n1 2\n3 4\n5 6\n7 8\n9 10\n11 12\n13 14\n"]}
641
133
coding
Solve the programming task below in a Python markdown code block. There are $X$ people participating in a quiz competition and their IDs have been numbered from $1$ to $X$ (both inclusive). Beth needs to form a team among these $X$ participants. She has been given an integer $Y$. She can choose participants whose ID nu...
{"inputs": ["2\n10 3\n15 5"], "outputs": ["18\n10"]}
302
26
coding
Solve the programming task below in a Python markdown code block. You are given a string $s$. And you have a function $f(x)$ defined as: f(x) = 1, if $x$ is a vowel f(x) = 0, if $x$ is a constant Your task is to apply the above function on all the characters in the string s and convert the obtained binary string in d...
{"inputs": ["1\nhello"], "outputs": ["9"]}
262
14
coding
Solve the programming task below in a Python markdown code block. Challenge: Given a two-dimensional array, return a new array which carries over only those arrays from the original, which were not empty and whose items are all of the same type (i.e. homogenous). For simplicity, the arrays inside the array will only c...
{"functional": "_inputs = [[[[1, 5, 4], ['a', 3, 5], ['b'], [], ['1', 2, 3]]], [[[123, 234, 432], ['', 'abc'], [''], ['', 1], ['', '1'], []]], [[[1, 2, 3], ['1', '2', '3'], ['1', 2, 3]]]]\n_outputs = [[[[1, 5, 4], ['b']]], [[[123, 234, 432], ['', 'abc'], [''], ['', '1']]], [[[1, 2, 3], ['1', '2', '3']]]]\nimport math\n...
212
300
coding
Solve the programming task below in a Python markdown code block. Chef Dengklek will open a new restaurant in the city. The restaurant will be open for N days. He can cook M different types of dish. He would like to cook a single dish every day, such that for the entire N days, he only cook at most K distinct types of ...
{"inputs": ["4\n1 1 1\n2 2 2\n4 3 2\n5 7 3"], "outputs": ["1\n4\n45\n5887"]}
267
46
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. There is a family tree rooted at 0 consisting of n nodes numbered 0 to n - 1. You are given a 0-indexed integer array parents, where parents[i] is the parent for node i. Since node 0 is the root, parents[0] == -1. The...
{"functional": "def check(candidate):\n assert candidate(parents = [-1,0,0,2], nums = [1,2,3,4]) == [5,1,1,1]\n assert candidate(parents = [-1,0,1,0,3,3], nums = [5,4,6,2,1,3]) == [7,1,1,4,2,1]\n assert candidate(parents = [-1,2,3,0,2,4,1], nums = [2,3,4,5,6,7,8]) == [1,1,1,1,1,1,1]\n\n\ncheck(Solution().small...
213
164
coding
Solve the programming task below in a Python markdown code block. Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well. You are given an odd integer $N$ and two integer sequences $A_{1}, A_{2}, \ldots, A_{N}$ and $B_{1}, B_{2}, \ldots, B_{N}$. Your task is to reorder...
{"inputs": ["1\n5\n3 1 2 4 5\n2 4 5 1 3"], "outputs": ["3 1 2 4 5"]}
557
42
coding
Solve the programming task below in a Python markdown code block. Filled with optimism, Hyunuk will host a conference about how great this new year will be! The conference will have $n$ lectures. Hyunuk has two candidate venues $a$ and $b$. For each of the $n$ lectures, the speaker specified two time intervals $[sa_i,...
{"inputs": ["2\n1 2 3 6\n3 4 7 8\n", "2\n4 4 4 5\n4 5 1 2\n", "2\n4 4 4 5\n4 5 1 2\n", "2\n1 2 3 6\n3 4 7 8\n", "3\n1 3 2 4\n4 5 6 7\n3 4 5 5\n", "3\n1 4 1 2\n2 5 2 3\n3 6 3 4\n", "3\n1 3 1 4\n3 5 2 5\n5 7 3 6\n", "3\n1 4 1 2\n2 5 2 3\n3 6 3 4\n"], "outputs": ["YES\n", "NO\n", "NO\n", "YES\n", "NO\n", "NO\n", "NO\n", "...
719
230
coding
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin Chinese and Russian. Chef has a box full of infinite number of identical coins. One day while playing, he made N piles each containing equal number of coins. Chef suddenly remembered an important task and left the ...
{"inputs": ["1\n4\n1 2 3 4", "1\n4\n1 2 2 4", "1\n4\n1 2 2 2", "1\n4\n1 2 0 4", "1\n4\n1 1 1 1", "1\n4\n1 2 1 4", "1\n4\n1 0 2 2", "1\n4\n1 1 2 2"], "outputs": ["3", "2\n", "1\n", "3\n", "0\n", "2\n", "2\n", "2\n"]}
518
141
coding
Solve the programming task below in a Python markdown code block. Reverse Polish Notation (RPN) is a mathematical notation where every operator follows all of its operands. For instance, to add three and four, one would write "3 4 +" rather than "3 + 4". If there are multiple operations, the operator is given immediate...
{"inputs": ["3\n(a+(b*c))\n((a+b)*(z+x))\n((a+t)*((b+(a+c))^(c+d)))\n"], "outputs": ["abc*+\nab+zx+*\nat+bac++cd+^*\n"]}
224
62
coding
Solve the programming task below in a Python markdown code block. You will be given an array which lists the current inventory of stock in your store and another array which lists the new inventory being delivered to your store today. Your task is to write a function that returns the updated list of your current inven...
{"functional": "_inputs = [[[], []]]\n_outputs = [[[]]]\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(_dee...
242
155
coding
Solve the programming task below in a Python markdown code block. Robbers, who attacked the Gerda's cab, are very successful in covering from the kingdom police. To make the goal of catching them even harder, they use their own watches. First, as they know that kingdom police is bad at math, robbers use the positional...
{"inputs": ["1 9\n", "8 7\n", "2 1\n", "1 1\n", "8 8\n", "1 2\n", "1 7\n", "2 2\n"], "outputs": ["0\n", "35\n", "1\n", "0\n", "0\n", "1\n", "6\n", "2\n"]}
434
87
coding
Solve the programming task below in a Python markdown code block. Create a program of the square picking method, which is one of the classical random number generation methods. The square harvesting method was proposed by von Neumann in the mid-1940s. In the square picking method, when the number of digits of the gene...
{"inputs": ["2\n-2\n1", "2\n12\n0", "2\n20\n0", "2\n94\n0", "2\n88\n0", "2\n0\n36", "2\n1\n43", "2\n1\n39"], "outputs": ["Case 1:\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\nCase 2:\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n", "Case 1:\n1\n0\n0\n0\n0\n0\n0\n0\n0\n0\nCase 2:\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n", "Case 1:\n4\n0\n0\n0\n0\n0\n0\n0\n0...
541
498
coding
Solve the programming task below in a Python markdown code block. You are given a grid with $R$ rows (numbered $1$ through $R$) and $C$ columns (numbered $1$ through $C$). A cell in row $r$ and column $c$ is denoted by $(r, c)$. Two cells in the grid are adjacent if they have a common side. For each valid $i$ and $j$, ...
{"inputs": ["2\n3 3\n1 2 1\n2 3 2\n1 2 1\n3 4\n0 0 0 0\n0 0 0 0\n0 0 4 0"], "outputs": ["Stable\nUnstable"]}
506
66
coding
Solve the programming task below in a Python markdown code block. Vasya plays a computer game with ninjas. At this stage Vasya's ninja should get out of a deep canyon. The canyon consists of two vertical parallel walls, their height is n meters. Let's imagine that we split these walls into 1 meter-long areas and numbe...
{"inputs": ["1 1\n-\nX\n", "1 20\n-\n-\n", "2 1\n-X\nX-\n", "2 1\n-X\n-X\n", "2 0\n-X\n-X\n", "2 0\n-X\nX-\n", "2 2\n-X\nX-\n", "1 100000\n-\n-\n"], "outputs": ["YES\n", "YES\n", "YES\n", "NO\n", "NO\n", "NO\n", "YES\n", "YES\n"]}
630
127
coding
Solve the programming task below in a Python markdown code block. While Vasya finished eating his piece of pizza, the lesson has already started. For being late for the lesson, the teacher suggested Vasya to solve one interesting problem. Vasya has an array a and integer x. He should find the number of different ordere...
{"inputs": ["1 1 1\n1\n", "1 1 1\n1\n", "1 1 1\n2\n", "1 1 1\n3\n", "1 1 1\n4\n", "1 1 2\n3\n", "2 5 0\n3 4\n", "1 13 1\n13\n"], "outputs": ["1\n", "1", "1\n", "1\n", "1\n", "0\n", "3\n", "1\n"]}
438
121
coding
Solve the programming task below in a Python markdown code block. As we all know, Chef is cooking string for long days, his new discovery on string is the longest common pattern length. The longest common pattern length between two strings is the maximum number of characters that both strings have in common. Characters...
{"inputs": ["4\nabcd\nxyz\nabcd\nbcda\nacba\nacaa\nCodechef\nelfedcc", "4\nbdca\nxyz\nabcd\nbcda\nabca\nacaa\nCodechff\nelfedcc", "4\nbdca\nyyz\nabdd\nbcda\nabca\nacaa\nCodechff\nelfedcc", "4\nabcd\nxyz\nabcd\nbcda\nacba\nacba\nCodechef\nelfedcc", "4\nbdca\nxyz\nabcd\nbcea\nabca\nacaa\nCodechef\nelfedcc", "4\nbdca\nyyz...
426
303
coding
Solve the programming task below in a Python markdown code block. The Little Elephant loves playing with arrays. He has array a, consisting of n positive integers, indexed from 1 to n. Let's denote the number with index i as ai. Additionally the Little Elephant has m queries to the array, each query is characterised ...
{"inputs": ["1 2\n1\n1 1\n1 1\n", "1 1\n1000000000\n1 1\n", "1 1\n1010000000\n1 1\n", "1 1\n1010000010\n1 1\n", "1 1\n1010010000\n1 1\n", "1 1\n1010100010\n1 1\n", "7 2\n3 1 2 2 6 3 7\n1 7\n3 4\n", "7 2\n3 1 2 2 3 3 4\n1 7\n3 4\n"], "outputs": ["1\n1\n", "0\n", "0\n", "0\n", "0\n", "0\n", "2\n1\n", "3\n1\n"]}
316
221
coding
Solve the programming task below in a Python markdown code block. Given an array A of size N. You can do the following operation on the array: Pick any 2 distinct indices i and j such that A_{i}=A_{j}; Change all the elements between the indices i and j to A_{i}, i.e, for all k (i ≤ k ≤ j), set A_{k}=A_{i}. Find the...
{"inputs": ["2\n6\n1 2 1 3 4 3\n3\n3 1 2"], "outputs": ["2\n-1"]}
497
37
coding
Solve the programming task below in a Python markdown code block. Captain Fint is involved in another treasure hunt, but have found only one strange problem. The problem may be connected to the treasure's location or may not. That's why captain Flint decided to leave the solving the problem to his crew and offered an a...
{"inputs": ["2\n-1 100\n2 -1\n", "2\n-1 000\n2 -1\n", "2\n-1 101\n2 -1\n", "2\n-1 001\n2 -1\n", "2\n-2 101\n2 -1\n", "2\n-2 100\n2 -1\n", "2\n-2 000\n2 -1\n", "2\n-4 100\n2 -1\n"], "outputs": ["99\n2 1 \n", "-1\n2 1 ", "100\n2 1 ", "0\n2 1 ", "99\n2 1 ", "98\n2 1 ", "-2\n2 1 ", "96\n2 1 "]}
641
191
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given two integers n and k, construct a list answer that contains n different positive integers ranging from 1 to n and obeys the following requirement: Suppose this list is answer = [a1, a2, a3, ... , an], then the ...
{"functional": "def check(candidate):\n assert candidate(n = 3, k = 1) == [1, 2, 3]\n assert candidate(n = 3, k = 2) == [1, 3, 2]\n\n\ncheck(Solution().constructArray)"}
162
67
coding
Solve the programming task below in a Python markdown code block. Manao is trying to open a rather challenging lock. The lock has n buttons on it and to open it, you should press the buttons in a certain order to open the lock. When you push some button, it either stays pressed into the lock (that means that you've gue...
{"inputs": ["2\n", "3\n", "4\n", "1\n", "4\n", "1\n", "5\n", "8\n"], "outputs": ["3\n", "7\n", "14\n", "1\n", "14\n", "1\n", "25\n", "92\n"]}
404
74
coding
Solve the programming task below in a Python markdown code block. It is the hard version of the problem. The difference is that in this version, there are nodes with already chosen colors. Theofanis is starving, and he wants to eat his favorite food, sheftalia. However, he should first finish his homework. Can you hel...
{"inputs": ["1\n1\n1 white\n", "1\n1\n1 white\n", "3\n1\n7 yellow\n", "1\n1\n1 yellow\n", "3\n1\n7 yellow\n", "1\n1\n1 yellow\n", "2\n2\n1 green\n3 red\n", "2\n2\n1 green\n3 red\n"], "outputs": ["1\n", "1\n", "4096\n", "1\n", "4096\n", "1\n", "4\n", "4\n"]}
663
122
coding
Solve the programming task below in a Python markdown code block. An NBA game runs 48 minutes (Four 12 minute quarters). Players do not typically play the full game, subbing in and out as necessary. Your job is to extrapolate a player's points per game if they played the full 48 minutes. Write a function that takes tw...
{"functional": "_inputs = [[2, 5], [3, 9], [16, 27], [11, 19], [14, 33], [1, 7.5], [6, 13]]\n_outputs = [[19.2], [16.0], [28.4], [27.8], [20.4], [6.4], [22.2]]\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...
235
242
coding
Solve the programming task below in a Python markdown code block. There are N strings arranged in a row. It is known that, for any two adjacent strings, the string to the left is lexicographically smaller than the string to the right. That is, S_1<S_2<...<S_N holds lexicographically, where S_i is the i-th string from t...
{"inputs": ["3\n3 4 1", "3\n1 3 4", "3\n3 5 1", "3\n3 5 2", "3\n3 5 3", "3\n3 7 3", "3\n3 1 3", "3\n3 3 1"], "outputs": ["2", "1", "2", "2", "2", "2", "2", "2"]}
233
102
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 matrix board, representing the current state of a crossword puzzle. The crossword contains lowercase English letters (from solved words), ' ' to represent any empty cells, and '#' to represent a...
{"functional": "def check(candidate):\n assert candidate(board = [[\"#\", \" \", \"#\"], [\" \", \" \", \"#\"], [\"#\", \"c\", \" \"]], word = \"abc\") == True\n assert candidate(board = [[\" \", \"#\", \"a\"], [\" \", \"#\", \"c\"], [\" \", \"#\", \"a\"]], word = \"ac\") == False\n assert candidate(board = [[...
240
160
coding
Solve the programming task below in a Python markdown code block. Do you know Professor Saeed? He is the algorithms professor at Damascus University. Yesterday, he gave his students hard homework (he is known for being so evil) - for a given binary string $S$, they should compute the sum of $F(S, L, R)$ over all pairs ...
{"inputs": ["1\n001"], "outputs": ["6"]}
630
16
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an integer array nums of length n where nums is a permutation of the numbers in the range [0, n - 1]. You should build a set s[k] = {nums[k], nums[nums[k]], nums[nums[nums[k]]], ... } subjected to the fo...
{"functional": "def check(candidate):\n assert candidate(nums = [5,4,0,3,1,6,2]) == 4\n assert candidate(nums = [0,1,2]) == 1\n\n\ncheck(Solution().arrayNesting)"}
185
60
coding
Solve the programming task below in a Python markdown code block. Takahashi had a pair of two positive integers not exceeding N, (a,b), which he has forgotten. He remembers that the remainder of a divided by b was greater than or equal to K. Find the number of possible pairs that he may have had. Constraints * 1 \leq...
{"inputs": ["6 2", "8 2", "8 4", "8 5", "8 7", "8 0", "4 2", "7 2"], "outputs": ["12\n", "28\n", "10\n", "6\n", "1\n", "64\n", "3\n", "19\n"]}
184
83
coding
Solve the programming task below in a Python markdown code block. Print the K-th element of the following sequence of length 32: 1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51 Constraints * 1 \leq K \leq 32 * All values in input are integers. Input Input is given...
{"inputs": ["8", "1", "5", "8", "1", "5", "6", "16"], "outputs": ["5\n", "1\n", "1\n", "5\n", "1\n", "1\n", "2", "14\n"]}
191
63
coding
Solve the programming task below in a Python markdown code block. Create a program that reads poker hand data and outputs the role for each. However, this issue follows the rules below. * Poker is a competition with 5 playing cards. * No more than 5 cards with the same number. * There is no joker. * Suppose you only c...
{"inputs": ["1,2,3,4,1\n2,3,1,3,12\n12,13,11,12,12\n7,6,7,6,7\n3,3,2,3,3\n6,7,8,9,10\n11,12,10,1,13\n11,12,13,1,2", "1,2,3,4,1\n2,3,1,3,12\n12,13,11,12,12\n7,6,7,6,7\n3,3,2,3,3\n6,7,8,9,10\n11,13,10,1,13\n11,12,13,1,2", "1,2,3,4,1\n2,3,1,3,12\n13,13,11,12,12\n7,6,7,6,7\n3,3,2,3,3\n6,7,8,9,10\n11,13,10,1,13\n11,12,13,1,...
530
961
coding
Solve the programming task below in a Python markdown code block. Create a program that will return whether an input value is a str, int, float, or bool. Return the name of the value. ### Examples - Input = 23 --> Output = int - Input = 2.3 --> Output = float - Input = "Hello" --> Output = str - Input = True --> Outpu...
{"functional": "_inputs = [[10], [9.7], ['Hello World!'], [[1, 2, 3, 4]], [1023], [True], ['True'], [{'name': 'John', 'age': 32}], [None], [3.141], [False], ['8.6'], ['*&^'], [4.5]]\n_outputs = [['int'], ['float'], ['str'], ['list'], ['int'], ['bool'], ['str'], ['dict'], ['NoneType'], ['float'], ['bool'], ['str'], ['st...
107
268
coding
Solve the programming task below in a Python markdown code block. Vasya wants to turn on Christmas lights consisting of m bulbs. Initially, all bulbs are turned off. There are n buttons, each of them is connected to some set of bulbs. Vasya can press any of these buttons. When the button is pressed, it turns on all the...
{"inputs": ["1 1\n0\n", "1 1\n0\n", "0 1\n0\n", "0 1\n1\n", "0 2\n1\n", "0 2\n0\n", "0 4\n0\n", "0 1\n-1\n"], "outputs": ["NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n"]}
341
103
coding
Solve the programming task below in a Python markdown code block. This is related to my other Kata about cats and dogs. # Kata Task I have a cat and a dog which I got as kitten / puppy. I forget when that was, but I do know their current ages as `catYears` and `dogYears`. Find how long I have owned each of my pets ...
{"functional": "_inputs = [[9, 7], [15, 15], [18, 21], [19, 17], [24, 24], [25, 25], [26, 26], [27, 27], [56, 64]]\n_outputs = [[[0, 0]], [[1, 1]], [[1, 1]], [[1, 1]], [[2, 2]], [[2, 2]], [[2, 2]], [[2, 2]], [[10, 10]]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n ...
265
278
coding
Solve the programming task below in a Python markdown code block. Chef gives you a sequence A of length N. Let X denote the MEX of the sequence A. Chef is interested in the count of positive values k, such that, if every element A_{i} of A is replaced by \texttt{max}(A_{i}-k,0), the MEX of the sequence still remains ...
{"inputs": ["3\n4\n1 2 3 5\n1\n0\n7\n5 10 2 4 0 6 1"], "outputs": ["0\n-1\n1"]}
578
48
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Implement a function signFunc(x) that returns: 1 if x is positive. -1 if x is negative. 0 if x is equal to 0. You are given an integer array nums. Let product be the product of all values in the array nums. Return s...
{"functional": "def check(candidate):\n assert candidate(nums = [-1,-2,-3,-4,3,2,1]) == 1\n assert candidate(nums = [1,5,0,2,-3]) == 0\n assert candidate(nums = [-1,1,-1,1,-1]) == -1\n\n\ncheck(Solution().arraySign)"}
106
83