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. 10^{10^{10}} participants, including Takahashi, competed in two programming contests. In each contest, all participants had distinct ranks from first through 10^{10^{10}}-th. The score of a participant is the product of his/her ranks in the two contests...
{"inputs": ["8\n2 4\n1 5\n3 6\n6 11\n8 9\n9 3\n7 36\n314159265 541984339", "8\n1 4\n10 8\n4 3\n4 8\n8 7\n22 6\n7 36\n314159265 96636036", "8\n2 4\n6 9\n3 1\n5 11\n4 9\n16 1\n6 57\n314159265 75457060", "8\n1 4\n10 5\n3 3\n4 11\n8 9\n1 3\n8 36\n314159265 358979323", "8\n1 4\n10 5\n3 3\n4 11\n8 9\n22 3\n7 36\n314159265 96...
336
671
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. A ramp in an integer array nums is a pair (i, j) for which i < j and nums[i] <= nums[j]. The width of such a ramp is j - i. Given an integer array nums, return the maximum width of a ramp in nums. If there is no ramp ...
{"functional": "def check(candidate):\n assert candidate([6,0,8,2,1,5]) == 4\n assert candidate([9,8,1,0,1,9,4,0,4,1]) == 7\n\n\ncheck(Solution().maxWidthRamp)"}
116
69
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. Chef recently visited ShareChat Cafe and was highly impressed by the food. Being a food enthusiast, he decided to enquire about the ingredients of ea...
{"inputs": ["2\n3\nabcaa\nbcbd\nbgc\n3\nquick\nbrown\nfox"], "outputs": ["2\n0"]}
515
33
coding
Solve the programming task below in a Python markdown code block. It is known that fleas in Berland can jump only vertically and horizontally, and the length of the jump is always equal to s centimeters. A flea has found herself at the center of some cell of the checked board of the size n × m centimeters (each cell is...
{"inputs": ["1 2 3\n", "9 8 7\n", "4 5 6\n", "1 1 1\n", "1 1 2\n", "8 5 6\n", "1 8 7\n", "8 1 6\n"], "outputs": ["2", "8", "20", "1", "1", "20\n", "2\n", "4\n"]}
266
99
coding
Solve the programming task below in a Python markdown code block. Ayush is a cashier at the shopping center. Recently his department has started a ''click and collect" service which allows users to shop online. The store contains k items. n customers have already used the above service. Each user paid for m items. Le...
{"inputs": ["1 1 1\n1\n1\n", "1 1 1\n1\n1\n", "2 2 5\n3 4 1 2 5\n1 5\n3 1\n", "3 2 3\n3 1 2\n1 2\n2 1\n2 3\n", "3 2 3\n3 1 2\n1 2\n2 1\n2 3\n", "3 2 3\n3 1 2\n1 2\n3 1\n2 3\n", "2 2 5\n3 4 1 0 5\n1 5\n3 1\n", "2 2 5\n3 4 1 0 5\n1 5\n4 1\n"], "outputs": ["1\n", "1\n", "14\n", "13\n", "13\n", "17\n", "14\n", "15\n"]}
644
224
coding
Solve the programming task below in a Python markdown code block. ## Debugging sayHello function The starship Enterprise has run into some problem when creating a program to greet everyone as they come aboard. It is your job to fix the code and get the program working again! Example output: ``` Hello, Mr. Spock ``` ...
{"functional": "_inputs = [['Mr. Spock'], ['Captain Kirk'], ['Liutenant Uhura'], ['Dr. McCoy'], ['Mr. Scott']]\n_outputs = [['Hello, Mr. Spock'], ['Hello, Captain Kirk'], ['Hello, Liutenant Uhura'], ['Hello, Dr. McCoy'], ['Hello, Mr. Scott']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or i...
92
211
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Alice and Bob have an undirected graph of n nodes and three types of edges: Type 1: Can be traversed by Alice only. Type 2: Can be traversed by Bob only. Type 3: Can be traversed by both Alice and Bob. Given an arra...
{"functional": "def check(candidate):\n assert candidate(n = 4, edges = [[3,1,2],[3,2,3],[1,1,3],[1,2,4],[1,1,2],[2,3,4]]) == 2\n assert candidate(n = 4, edges = [[3,1,2],[3,2,3],[1,1,4],[2,1,4]]) == 0\n assert candidate(n = 4, edges = [[3,2,3],[1,1,2],[2,3,4]]) == -1\n\n\ncheck(Solution().maxNumEdgesToRemove)...
219
144
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an integer array nums, return true if you can partition the array into two subsets such that the sum of the elements in both subsets is equal or false otherwise.   Please complete the following python code preci...
{"functional": "def check(candidate):\n assert candidate(nums = [1,5,11,5]) == True\n assert candidate(nums = [1,2,3,5]) == False\n\n\ncheck(Solution().canPartition)"}
81
54
coding
Solve the programming task below in a Python markdown code block. ###Lucky number Write a function to find if a number is lucky or not. If the sum of all digits is 0 or multiple of 9 then the number is lucky. `1892376 => 1+8+9+2+3+7+6 = 36`. 36 is divisble by 9, hence number is lucky. Function will return `true` fo...
{"functional": "_inputs = [[1892376], [189237], [18922314324324234423437], [189223141324324234423437], [1892231413243242344321432142343423437], [0]]\n_outputs = [[True], [False], [False], [True], [True], [True]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n r...
132
277
coding
Solve the programming task below in a Python markdown code block. Since I got tired to write long problem statements, I decided to make this problem statement short. For given positive integer L, how many pairs of positive integers a, b (a ≤ b) such that LCM(a, b) = L are there? Here, LCM(a, b) stands for the least com...
{"inputs": ["12\n9\n3\n0", "12\n8\n2\n0", "12\n9\n0\n0", "12\n0\n3\n0", "12\n9\n1\n0", "12\n8\n1\n0", "12\n9\n4\n0", "12\n8\n0\n0"], "outputs": ["8\n3\n2\n", "8\n4\n2\n", "8\n3\n", "8\n", "8\n3\n1\n", "8\n4\n1\n", "8\n3\n3\n", "8\n4\n"]}
157
142
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an integer array heights representing the heights of buildings, some bricks, and some ladders. You start your journey from building 0 and move to the next building by possibly using bricks or ladders. Wh...
{"functional": "def check(candidate):\n assert candidate(heights = [4,2,7,6,9,14,12], bricks = 5, ladders = 1) == 4\n assert candidate(heights = [4,12,2,7,3,18,20,3,19], bricks = 10, ladders = 2) == 7\n assert candidate(heights = [14,3,19,3], bricks = 17, ladders = 0) == 3\n\n\ncheck(Solution().furthestBuildin...
203
136
coding
Solve the programming task below in a Python markdown code block. You are given an integer $N$. Consider set $S=\{0,\:1,\ldots,\:2^N-1\}$. How many subsets $A\subset S$ with $\bigoplus_{x\in A}x=0$ ($\theta$ denotes xor operation) are there? Print your answer modulo $(10^9+7)$. Note that the xorsum of an empty set...
{"inputs": ["2\n1\n2\n"], "outputs": ["2\n4\n"]}
302
20
coding
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin Chinese and Russian as well. A version control system(VCS) is a repository of files, often the files for the source code of computer programs, with monitored access. Every change made to the source is tracked, alon...
{"inputs": ["2\n7 4 6\n1 4 6 7\n1 2 3 4 6 7\n4 2 2\n1 4\n3 4", "2\n7 4 6\n1 4 6 7\n1 2 3 5 6 7\n4 2 2\n1 4\n3 4", "2\n7 4 6\n1 4 6 7\n1 2 3 4 6 7\n4 2 2\n2 4\n3 4", "2\n7 4 6\n1 4 6 7\n1 2 3 4 6 7\n5 2 2\n2 4\n3 4", "2\n7 4 6\n1 4 6 7\n1 2 3 4 6 7\n4 2 2\n1 4\n1 4", "2\n7 4 6\n1 4 6 7\n1 2 3 5 6 7\n5 2 2\n2 4\n3 4", "2...
747
429
coding
Solve the programming task below in a Python markdown code block. If you finish this kata, you can try [Insane Coloured Triangles](http://www.codewars.com/kata/insane-coloured-triangles) by Bubbler, which is a ***much*** harder version of this one. A coloured triangle is created from a row of colours, each of which is...
{"functional": "_inputs = [['GB'], ['RRR'], ['RGBG'], ['RBRGBRB'], ['RBRGBRBGGRRRBGBBBGG'], ['B']]\n_outputs = [['R'], ['R'], ['B'], ['G'], ['G'], ['B']]\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...
406
198
coding
Solve the programming task below in a Python markdown code block. Create a function that checks if a number `n` is divisible by two numbers `x` **AND** `y`. All inputs are positive, non-zero digits. ```JS Examples: 1) n = 3, x = 1, y = 3 => true because 3 is divisible by 1 and 3 2) n = 12, x = 2, y = 6 => true ...
{"functional": "_inputs = [[3, 2, 2], [3, 3, 4], [12, 3, 4], [8, 3, 4], [48, 3, 4], [100, 5, 10], [100, 5, 3], [4, 4, 2], [5, 2, 3], [17, 17, 17], [17, 1, 17]]\n_outputs = [[False], [False], [True], [False], [True], [True], [False], [True], [False], [True], [True]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if is...
213
293
coding
Solve the programming task below in a Python markdown code block. The whole world got obsessed with robots,and to keep pace with the progress, great Berland's programmer Draude decided to build his own robot. He was working hard at the robot. He taught it to walk the shortest path from one point to another, to record a...
{"inputs": ["L\n", "R\n", "RR\n", "DL\n", "LD\n", "UL\n", "DDR\n", "ULD\n"], "outputs": ["OK\n", "OK\n", "OK\n", "OK\n", "OK\n", "OK\n", "OK\n", "BUG\n"]}
463
70
coding
Solve the programming task below in a Python markdown code block. prison There are an infinite number of prisoners. Initially, the prisoners are numbered 0, 1, 2, .... Do the following N times: * Release the 0th prisoner and execute the k, 2k, 3k, ... th prisoners. * Then renumber the remaining prisoners. At this ti...
{"inputs": ["5 2", "7 2", "2 2", "1 2", "4 3", "8 2", "6 2", "7 4"], "outputs": ["15\n", "63\n", "1\n", "0\n", "4\n", "127\n", "31\n", "10\n"]}
263
84
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an integer n. A 0-indexed integer array nums of length n + 1 is generated in the following way: nums[0] = 0 nums[1] = 1 nums[2 * i] = nums[i] when 2 <= 2 * i <= n nums[2 * i + 1] = nums[i] + nums[i + 1]...
{"functional": "def check(candidate):\n assert candidate(n = 7) == 3\n assert candidate(n = 2) == 1\n assert candidate(n = 3) == 2\n\n\ncheck(Solution().getMaximumGenerated)"}
158
56
coding
Solve the programming task below in a Python markdown code block. Petya has equal wooden bars of length n. He wants to make a frame for two equal doors. Each frame has two vertical (left and right) sides of length a and one top side of length b. A solid (i.e. continuous without breaks) piece of bar is needed for each s...
{"inputs": ["8\n1\n2\n", "5\n3\n4\n", "6\n4\n2\n", "1\n1\n1\n", "3\n1\n2\n", "3\n2\n1\n", "8\n3\n5\n", "5\n4\n2\n"], "outputs": ["1\n", "6\n", "4\n", "6\n", "3\n", "4\n", "3\n", "5\n"]}
351
102
coding
Solve the programming task below in a Python markdown code block. Write a program which reads a rectangle and a circle, and determines whether the circle is arranged inside the rectangle. As shown in the following figures, the upper right coordinate $(W, H)$ of the rectangle and the central coordinate $(x, y)$ and radi...
{"inputs": ["2 4 2 2 1", "2 8 2 0 0", "5 4 2 0 1", "2 4 2 2 2", "5 8 2 0 1", "2 6 2 2 2", "2 8 2 0 1", "3 6 2 2 2"], "outputs": ["No\n", "Yes\n", "No\n", "No\n", "No\n", "No\n", "No\n", "No\n"]}
206
126
coding
Solve the programming task below in a Python markdown code block. Alisha has a string of length n. Each character is either 'a', 'b' or 'c'. She has to select two characters s[i] and s[j] such that s[i] != s[j] and i,j are valid indexes. She has to find the maximum value of the absolute difference between i and j i.e a...
{"inputs": ["aba", "aabcaaa"], "outputs": ["1", "4"]}
287
20
coding
Solve the programming task below in a Python markdown code block. JJ has an array A of length N. He can perform the following operation on A: Select any L, R (1 ≤ L ≤ R ≤ N) and for each i such that L ≤ i ≤ R, set A_{i} := A_{i} + 1. JJ wants to make A palindromic. Find the minimum number of moves to do so. Note: An ...
{"inputs": ["3\n6\n2 6 4 3 4 1\n2\n1 10\n3\n1 10 1\n"], "outputs": ["2\n9\n0\n"]}
544
48
coding
Solve the programming task below in a Python markdown code block. Create a function `close_compare` that accepts 3 parameters: `a`, `b`, and an optional `margin`. The function should return whether `a` is lower than, close to, or higher than `b`. `a` is "close to" `b` if `margin` is higher than or equal to the differen...
{"functional": "_inputs = [[4, 5], [5, 5], [6, 5], [2, 5, 3], [5, 5, 3], [8, 5, 3], [8.1, 5, 3], [1.99, 5, 3]]\n_outputs = [[-1], [0], [1], [0], [0], [0], [1], [-1]]\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=...
270
241
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a weighted tree consisting of n nodes numbered from 0 to n - 1. The tree is rooted at node 0 and represented with a 2D array edges of size n where edges[i] = [pari, weighti] indicates that node pari is t...
{"functional": "def check(candidate):\n assert candidate(edges = [[-1,-1],[0,5],[0,10],[2,6],[2,4]]) == 11\n assert candidate(edges = [[-1,-1],[0,5],[0,-6],[0,7]]) == 7\n\n\ncheck(Solution().maxScore)"}
254
79
coding
Solve the programming task below in a Python markdown code block. You are given an array A = [A_{1}, A_{2}, \ldots, A_{N}] of length N. You can right rotate it any number of times (possibly, zero). What is the maximum value of A_{1} + A_{N} you can get? Note: Right rotating the array [A_{1}, A_{2}, \ldots, A_{N}] onc...
{"inputs": ["3\n2\n5 8\n3\n5 10 15\n4\n4 4 4 4\n"], "outputs": ["13\n25\n8\n"]}
527
46
coding
Solve the programming task below in a Python markdown code block. Let's start from some definitions. Strings A and B are called anagrams if it's possible to rearrange the letters of string A using all the original letters exactly once and achieve string B; in other words A and B are permutations of each other. For exa...
{"inputs": ["2\nwall\nstep", "2\nllaw\nstep", "2\namlu\nutfq", "2\nwmck\nmhqt", "2\nllwa\nstep", "2\nllwa\nstfp", "2\nmlwa\nstfp", "2\nawlm\nstfp"], "outputs": ["no such string", "no such string\n", "u\n", "m\n", "no such string\n", "no such string\n", "no such string\n", "no such string\n"]}
632
117
coding
Solve the programming task below in a Python markdown code block. You have initially a string of N characters, denoted by A1,A2...AN. You have to print the size of the largest subsequence of string A such that all the characters in that subsequence are distinct ie. no two characters in that subsequence should be same. ...
{"inputs": ["2\nabc\naba", "2\nabd\naba", "2\nabc\naaa", "2\ncca\naaa", "2\nccb\naab", "2\nccb\ncba", "2\nbbb\nbaa", "2\nbbb\naaa"], "outputs": ["3\n2", "3\n2\n", "3\n1\n", "2\n1\n", "2\n2\n", "2\n3\n", "1\n2\n", "1\n1\n"]}
268
111
coding
Solve the programming task below in a Python markdown code block. You are given three numbers $a$, $b$, $c$ . Write a program to determine the largest number that is less than or equal to $c$ and leaves a remainder $b$ when divided by $a$. -----Input:----- - First line will contain $T$, number of testcases. Then the t...
{"inputs": ["1\n7 2 10"], "outputs": ["9"]}
198
19
coding
Solve the programming task below in a Python markdown code block. problem There are fine icicles under the eaves of JOI's house in Canada. Because of this, JOI decided to investigate the icicles. There are N (2 ≤ N ≤ 100000 = 105) icicles under the eaves of JOI's house. These icicles are aligned and i cm (1 ≤ i ≤ N) ...
{"inputs": ["4 6\n7\n2\n3\n5", "4 6\n4\n1\n3\n5", "1 6\n4\n2\n3\n1", "4 5\n4\n2\n3\n1", "1 6\n3\n2\n3\n1", "1 6\n2\n2\n3\n1", "4 9\n7\n2\n3\n5", "1 6\n1\n0\n1\n1"], "outputs": ["8\n", "9\n", "2\n", "6\n", "3\n", "4\n", "17\n", "5\n"]}
687
143
coding
Solve the programming task below in a Python markdown code block. The store sells $n$ items, the price of the $i$-th item is $p_i$. The store's management is going to hold a promotion: if a customer purchases at least $x$ items, $y$ cheapest of them are free. The management has not yet decided on the exact values of $...
{"inputs": ["2 1\n100 200\n1 1\n", "1 1\n1000000\n1 1\n", "3 1\n100 200 100\n2 1\n", "2 2\n100 200\n2 2\n2 1\n", "5 3\n5 3 1 5 2\n3 2\n1 1\n5 3\n", "5 2\n100 200 300 400 500\n1 1\n3 2\n", "5 3\n100 200 300 400 500\n2 1\n1 1\n3 2\n", "5 3\n100 200 300 400 500\n1 1\n3 2\n2 2\n"], "outputs": ["200\n", "1000000\n", "100\n"...
477
302
coding
Solve the programming task below in a Python markdown code block. Chef develops his own computer program for playing chess. He is at the very beginning. At first he needs to write the module that will receive moves written by the players and analyze it. The module will receive a string and it should report at first whe...
{"inputs": ["4\na1-b3\nd2-h8\na3 c4\nErrorError"], "outputs": ["Yes\nNo\nError\nError"]}
398
36
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You may recall that an array arr is a mountain array if and only if: arr.length >= 3 There exists some index i (0-indexed) with 0 < i < arr.length - 1 such that: arr[0] < arr[1] < ... < arr[i - 1] < arr[i] arr[i] >...
{"functional": "def check(candidate):\n assert candidate(nums = [1,3,1]) == 0\n assert candidate(nums = [2,1,1,5,6,2,3,1]) == 3\n\n\ncheck(Solution().minimumMountainRemovals)"}
165
64
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given two strings s and t, return true if they are equal when both are typed into empty text editors. '#' means a backspace character. Note that after backspacing an empty text, the text will continue empty.   Please ...
{"functional": "def check(candidate):\n assert candidate(s = \"ab#c\", t = \"ad#c\") == True\n assert candidate(s = \"ab##\", t = \"c#d#\") == True\n assert candidate(s = \"a#c\", t = \"b\") == False\n\n\ncheck(Solution().backspaceCompare)"}
96
75
coding
Solve the programming task below in a Python markdown code block. Jou and Yae are a good couple. Jou is collecting prizes for capsule toy vending machines (Gachapon), and even when they go out together, when they find Gachapon, they seem to get so hot that they try it several times. Yae was just looking at Jou, who loo...
{"inputs": ["2\n3 0\n3\n0 1 1\n1\n1000\n0", "2\n3 2\n3\n0 1 1\n1\n0000\n0", "2\n1 0\n3\n0 1 1\n1\n1000\n0", "2\n2 0\n3\n0 1 1\n0\n1100\n0", "2\n1 0\n3\n0 1 1\n0\n1100\n0", "2\n3 2\n3\n0 0 1\n1\n1000\n0", "2\n6 4\n3\n0 1 2\n1\n0000\n0", "2\n0 4\n3\n0 1 2\n1\n0000\n0"], "outputs": ["2\nNA\n2\n", "3\nNA\nNA\n", "NA\nNA\n2...
397
258
coding
Solve the programming task below in a Python markdown code block. Today on a lecture about strings Gerald learned a new definition of string equivalency. Two strings a and b of equal length are called equivalent in one of the two cases: They are equal. If we split string a into two halves of the same size a_1 and a_...
{"inputs": ["a\na\n", "a\nb\n", "a\na\n", "a\nb\n", "a\nc\n", "a\nd\n", "`\nc\n", "`\nd\n"], "outputs": ["YES\n", "NO\n", "YES\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n"]}
409
84
coding
Solve the programming task below in a Python markdown code block. # Task You are given two strings s and t of the same length, consisting of uppercase English letters. Your task is to find the minimum number of "replacement operations" needed to get some `anagram` of the string t from the string s. A replacement opera...
{"functional": "_inputs = [['AABAA', 'BBAAA'], ['OVGHK', 'RPGUC'], ['AAAAAAAAAAAAAAAAAAAAAAAAAAAAAB', 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAC']]\n_outputs = [[1], [4], [1]]\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=t...
309
191
coding
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin Chinese and Russian. Cascading Style Sheets, or CSS is a style sheet language, most popularly known for styling web pages. Each object on a web page (like a picture, a paragraph, a table) can have various propertie...
{"inputs": ["3 1\n22 1 200 2\n22 1 300 2\n22 1 100 1\n22 1"], "outputs": ["300"]}
540
54
coding
Solve the programming task below in a Python markdown code block. Your class recently got a maths assignment with 5 questions. There are N (≤ 20) students in the class and at most 2 people can collaborate. For each student, you know which problems they solved. Find out if there exists a team of two students who can to...
{"inputs": ["4\n3\n1 3\n1 1\n4 1 3 4 5\n2\n4 2 3 4 5\n3 1 2 4\n3\n1 1\n1 2\n1 3\n2\n2 1 5\n3 2 3 4\n"], "outputs": ["NO\nYES\nNO\nYES"]}
558
89
coding
Solve the programming task below in a Python markdown code block. Consider an array $a$ of $n$ positive integers. You may perform the following operation: select two indices $l$ and $r$ ($1 \leq l \leq r \leq n$), then decrease all elements $a_l, a_{l + 1}, \dots, a_r$ by $1$. Let's call $f(a)$ the minimum number o...
{"inputs": ["3\n4\n2 3 5 4\n3\n1 2 3\n4\n3 1 3 2\n", "1\n5\n1000000000 1 1000000000 1 1000000000\n"], "outputs": ["YES\nYES\nNO\n", "NO\n"]}
610
93
coding
Solve the programming task below in a Python markdown code block. Programmer Deepak has created a program which calculates magical number as 2^n * 3^n * 5^n where "n" is an integer. Now he wants to find the magical number which is just greater than the input. Help him in finding it. NOTE : a^b denotes a raised to po...
{"inputs": ["456"], "outputs": ["900"]}
139
16
coding
Solve the programming task below in a Python markdown code block. Read problem statements in [Russian], [Mandarin Chinese], [Bengali], and [Vietnamese] as well. In a season, each player has three statistics: runs, wickets, and catches. Given the season stats of two players A and B, denoted by R, W, and C respectively,...
{"inputs": ["3\n0 1 2\n2 3 4\n10 10 10\n8 8 8\n10 0 10\n0 10 0"], "outputs": ["B\nA\nA"]}
535
58
coding
Solve the programming task below in a Python markdown code block. Our master carpenter is designing a condominium called Bange Hills Mansion. The condominium is constructed by stacking up floors of the same height. The height of each floor is designed so that the total height of the stacked floors coincides with the pr...
{"inputs": ["101 2 5", "100 2 5", "111 2 5", "000 2 5", "010 2 8", "000 2 8", "101 2 8", "100 2 8"], "outputs": ["0\n", "3\n", "1\n", "4\n", "2\n", "7\n", "0\n", "3\n"]}
283
110
coding
Solve the programming task below in a Python markdown code block. You are given circular array a0, a1, ..., an - 1. There are two types of operations with it: * inc(lf, rg, v) — this operation increases each element on the segment [lf, rg] (inclusively) by v; * rmq(lf, rg) — this operation returns minimal value ...
{"inputs": ["1\n1\n1\n0 0 0\n", "4\n1 2 3 4\n4\n3 0\n3 0 -1\n0 1\n2 1\n", "1\n-1\n10\n0 0 -1\n0 0\n0 0 1\n0 0\n0 0 1\n0 0\n0 0 0\n0 0\n0 0 -1\n0 0 1\n", "2\n-1 -1\n10\n0 0\n0 0\n0 0 1\n0 0\n1 1\n0 0 -1\n0 0 0\n0 0 1\n1 1 0\n0 0 -1\n"], "outputs": ["", "1\n0\n0\n", "-2\n-1\n0\n0\n", "-1\n-1\n0\n-1\n"]}
406
211
coding
Solve the programming task below in a Python markdown code block. A tennis tournament with n participants is running. The participants are playing by an olympic system, so the winners move on and the losers drop out. The tournament takes place in the following way (below, m is the number of the participants of the cur...
{"inputs": ["5 2 3\n", "8 2 4\n", "1 2 3\n", "1 3 4\n", "1 1 1\n", "1 2 5\n", "1 3 8\n", "1 3 5\n"], "outputs": ["20 15\n", "35 32\n", "0 3\n", "0 4\n", "0 1\n", "0 5\n", "0 8\n", "0 5\n"]}
410
122
coding
Solve the programming task below in a Python markdown code block. We have a sequence of N integers: x=(x_0,x_1,\cdots,x_{N-1}). Initially, x_i=0 for each i (0 \leq i \leq N-1). Snuke will perform the following operation exactly M times: * Choose two distinct indices i, j (0 \leq i,j \leq N-1,\ i \neq j). Then, replac...
{"inputs": ["0 2", "5 7", "6 7", "3 7", "3 3", "3 6", "2 5", "5 6"], "outputs": ["0\n", "11600\n", "63008\n", "169\n", "37\n", "127\n", "6\n", "6685\n"]}
309
94
coding
Solve the programming task below in a Python markdown code block. A remote island chain contains n islands, labeled 1 through n. Bidirectional bridges connect the islands to form a simple cycle — a bridge connects islands 1 and 2, islands 2 and 3, and so on, and additionally a bridge connects islands n and 1. The cente...
{"inputs": ["2\n1 0\n0 1\n", "2\n0 1\n0 1\n", "2\n1 0\n1 0\n", "2\n1 0\n1 0\n", "2\n0 1\n0 1\n", "2\n1 0\n0 1\n", "3\n1 0 2\n2 0 1\n", "3\n0 2 1\n1 2 0\n"], "outputs": ["YES\n", "YES\n", "YES\n", "YES", "YES", "YES", "YES\n", "YES\n"]}
539
139
coding
Solve the programming task below in a Python markdown code block. JJ has an array A of size N. He can perform the following operations on the array at most K times: Set A_{i} := A_{i + 1} where 1 ≤ i ≤ N - 1 Set A_{i} := A_{i - 1} where 2 ≤ i ≤ N He wants to maximize the value of the minimum element of the array A. F...
{"inputs": ["4\n5 4\n5 4 3 2 1\n6 1\n8 2 3 9 6 10\n5 2\n4 3 4 3 5\n5 1000\n4 3 4 3 5\n"], "outputs": ["5\n3\n4\n5\n"]}
746
82
coding
Solve the programming task below in a Python markdown code block. Solve the Mystery. Input : First line contains T - No. of Test cases. Each Test case consists of 2 lines. First line contains K. Second line contains 3 space separated Integers A1 ,A2 ,A3. Output : Print required answers in separate lines. Constrai...
{"inputs": ["10\n1\n1 1 1\n2\n1 2 3\n3\n2 3 5\n4\n5 4 6\n5\n1 7 6\n1\n4 4 4\n2\n10 10 10\n3\n9 8 7\n4\n1 5 7\n5\n9 7 9", "100\n5\n3 10 3\n8\n0 0 0\n2\n7 0 8\n5\n1 9 0\n10\n10 10 10\n3\n0 4 8\n7\n10 9 10\n9\n0 7 5\n4\n7 6 7\n10\n8 3 4\n6\n1 10 9\n4\n6 10 3\n4\n5 4 7\n1\n8 4 7\n5\n0 4 0\n1\n0 4 3\n6\n8 8 9\n8\n0 0 8\n8\n...
131
1,747
coding
Solve the programming task below in a Python markdown code block. Now that Kuroni has reached 10 years old, he is a big boy and doesn't like arrays of integers as presents anymore. This year he wants a Bracket sequence as a Birthday present. More specifically, he wants a bracket sequence so complex that no matter how h...
{"inputs": [")(\n", "()\n", "()\n", "((\n", "))\n", ")(\n", "(()((\n", "())((\n"], "outputs": ["0\n", "1\n2\n1 2 \n", "1\n2\n1 2 ", "0\n", "0\n", "0", "1\n2\n1 3 \n", "1\n2\n1 3\n"]}
719
101
coding
Solve the programming task below in a Python markdown code block. Hamed has recently found a string t and suddenly became quite fond of it. He spent several days trying to find all occurrences of t in other strings he had. Finally he became tired and started thinking about the following problem. Given a string s how ma...
{"inputs": ["a\na\n", "a\nb\n", "a\na\n", "a\nb\n", "c\nc\n", "a\nc\n", "b\nc\n", "c\nb\n"], "outputs": ["1\n", "0\n", "1", "0", "1\n", "0\n", "0\n", "0\n"]}
407
84
coding
Solve the programming task below in a Python markdown code block. Caracal is fighting with a monster. The health of the monster is H. Caracal can attack by choosing one monster. When a monster is attacked, depending on that monster's health, the following happens: - If the monster's health is 1, it drops to 0. - If t...
{"inputs": ["8", "3", "7", "1", "5", "6", "9", "4"], "outputs": ["15\n", "3\n", "7\n", "1\n", "7\n", "7\n", "15\n", "7"]}
283
63
coding
Solve the programming task below in a Python markdown code block. Polycarp remembered the $2020$-th year, and he is happy with the arrival of the new $2021$-th year. To remember such a wonderful moment, Polycarp wants to represent the number $n$ as the sum of a certain number of $2020$ and a certain number of $2021$. ...
{"inputs": ["1\n7\n", "1\n9\n", "1\n8\n", "1\n2\n", "1\n3\n", "1\n6\n", "1\n4\n", "1\n1\n"], "outputs": ["NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n"]}
518
86
coding
Solve the programming task below in a Python markdown code block. Let a_1, …, a_n be an array of n positive integers. In one operation, you can choose an index i such that a_i = i, and remove a_i from the array (after the removal, the remaining parts are concatenated). The weight of a is defined as the maximum number ...
{"inputs": ["1 1\n1\n0 0\n", "1 1\n0\n0 0\n", "2 1\n1 1\n0 0\n", "2 1\n1 0\n0 0\n", "2 1\n2 0\n0 0\n", "2 1\n0 0\n0 0\n", "2 1\n0 1\n0 0\n", "2 1\n2 1\n0 0\n"], "outputs": ["1\n", "0\n", "2\n", "1\n", "0\n", "0\n", "0\n", "0\n"]}
676
146
coding
Solve the programming task below in a Python markdown code block. The [Chinese zodiac](https://en.wikipedia.org/wiki/Chinese_zodiac) is a repeating cycle of 12 years, with each year being represented by an animal and its reputed attributes. The lunar calendar is divided into cycles of 60 years each, and each year has a...
{"functional": "_inputs = [[1965], [1938], [1998], [2016], [1924], [1968], [2162], [6479], [3050], [6673], [6594], [9911], [2323], [3448], [1972]]\n_outputs = [['Wood Snake'], ['Earth Tiger'], ['Earth Tiger'], ['Fire Monkey'], ['Wood Rat'], ['Earth Monkey'], ['Water Dog'], ['Earth Goat'], ['Metal Dog'], ['Water Rooster...
365
301
coding
Solve the programming task below in a Python markdown code block. You are given an array A = [A_{1}, A_{2}, \ldots, A_{N}]. Is it possible to partition A into two non-empty [subsequences] S_{1} and S_{2} such that sum(S_{1}) \times sum(S_{2}) is odd? Here, sum(S_{1}) denotes the sum of elements in S_{1}, and sum(S_{2...
{"inputs": ["4\n4\n1 1 2 2\n6\n1 2 4 6 8 10\n2\n3 5\n3\n1 3 5"], "outputs": ["YES\nNO\nYES\nNO"]}
635
57
coding
Solve the programming task below in a Python markdown code block. JavaScript provides a built-in parseInt method. It can be used like this: - `parseInt("10")` returns `10` - `parseInt("10 apples")` also returns `10` We would like it to return `"NaN"` (as a string) for the second case because the input string is not ...
{"functional": "_inputs = [['9'], ['09'], ['009'], [' 9'], [' 9 '], ['\\t9\\n'], ['5 friends'], ['5friends'], ['I <3 u'], ['17.42'], ['0x10'], ['123~~'], ['1 1'], ['1 2 3'], ['1.0']]\n_outputs = [[9], [9], [9], [9], [9], [9], ['NaN'], ['NaN'], ['NaN'], ['NaN'], ['NaN'], ['NaN'], ['NaN'], ['NaN'], ['NaN']]\nimport ma...
191
275
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a 2D grid of size m x n and an integer k. You need to shift the grid k times. In one shift operation: Element at grid[i][j] moves to grid[i][j + 1]. Element at grid[i][n - 1] moves to grid[i + 1][0]. Element at...
{"functional": "def check(candidate):\n assert candidate(grid = [[1,2,3],[4,5,6],[7,8,9]], k = 1) == [[9,1,2],[3,4,5],[6,7,8]]\n assert candidate(grid = [[3,8,1,9],[19,7,2,5],[4,6,11,10],[12,0,21,13]], k = 4) == [[12,0,21,13],[3,8,1,9],[19,7,2,5],[4,6,11,10]]\n assert candidate(grid = [[1,2,3],[4,5,6],[7,8,9]]...
159
212
coding
Solve the programming task below in a Python markdown code block. Chef bought a huge (effectively infinite) planar island and built $N$ restaurants (numbered $1$ through $N$) on it. For each valid $i$, the Cartesian coordinates of restaurant $i$ are $(X_i, Y_i)$. Now, Chef wants to build $N-1$ straight narrow roads (li...
{"inputs": ["2\n3\n0 0\n0 1\n0 -1\n3\n0 1\n1 0\n-1 0"], "outputs": ["0.5\n0"]}
678
45
coding
Solve the programming task below in a Python markdown code block. While walking down the street Vanya saw a label "Hide&Seek". Because he is a programmer, he used & as a bitwise AND for these two words represented as a integers in base 64 and got new word. Now Vanya thinks of some string s and wants to know the number ...
{"inputs": ["z\n", "_\n", "6\n", "6\n", "_\n", "8\n", "y\n", "7\n"], "outputs": ["3\n", "1\n", "81\n", "81", "1", "243\n", "9\n", "27\n"]}
427
73
coding
Solve the programming task below in a Python markdown code block. Write a function that takes as its parameters *one or more numbers which are the diameters of circles.* The function should return the *total area of all the circles*, rounded to the nearest integer in a string that says "We have this much circle: xyz"...
{"functional": "_inputs = [[48, 7, 8, 9, 10], [1], [1, 1, 1, 2, 3, 4, 5], [894, 5778, 4839, 476], [4.5456, 746.5, 98.34, 344.543], [1, 1, 1], [13.58, 14.9, 56.99, 107.321], [56894.04839, 843975.4839, 4.08437403489], [5, 6, 7, 8, 9, 10, 105083, 48839, 4853, 28, 483]]\n_outputs = [['We have this much circle: 2040'], ['We...
173
502
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an array of CPU tasks, each labeled with a letter from A to Z, and a number n. Each CPU interval can be idle or allow the completion of one task. Tasks can be completed in any order, but there's a constr...
{"functional": "def check(candidate):\n assert candidate(tasks = [\"A\",\"A\",\"A\",\"B\",\"B\",\"B\"], n = 2) == 8\n assert candidate(tasks = [\"A\",\"A\",\"A\",\"B\",\"B\",\"B\"], n = 0) == 6\n assert candidate(tasks = [\"A\",\"A\",\"A\",\"A\",\"A\",\"A\",\"B\",\"C\",\"D\",\"E\",\"F\",\"G\"], n = 2) == 16\n\...
136
119
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an integer n, return the nth digit of the infinite integer sequence [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, ...].   Please complete the following python code precisely: ```python class Solution: def findNthDigit...
{"functional": "def check(candidate):\n assert candidate(n = 3) == 3\n assert candidate(n = 11) == 0\n\n\ncheck(Solution().findNthDigit)"}
100
46
coding
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. Chef and his little brother are playing with sticks. They have total N sticks. Length of i-th stick is A_{i}. Chef asks his brother to choose any four sticks and to make a r...
{"inputs": ["2\n5\n1 2 3 1 2\n4\n1 2 2 3", "2\n5\n1 2 3 1 1\n4\n1 2 2 3", "2\n5\n1 2 3 1 2\n4\n1 3 2 3", "2\n5\n1 2 3 1 1\n4\n2 2 4 4", "2\n5\n1 3 3 1 1\n4\n0 2 0 3", "2\n5\n1 2 3 1 2\n4\n1 3 1 3", "2\n5\n2 2 3 1 2\n4\n1 3 1 3", "2\n5\n2 2 3 2 2\n1\n2 5 4 3"], "outputs": ["2\n-1", "-1\n-1\n", "2\n-1\n", "-1\n8\n", "3\n...
466
258
coding
Solve the programming task below in a Python markdown code block. You are given a string S of length 2N consisting of lowercase English letters. There are 2^{2N} ways to color each character in S red or blue. Among these ways, how many satisfy the following condition? * The string obtained by reading the characters p...
{"inputs": ["4\ncacaabba", "4\nacbaacab", "4\nhgfedcba", "4\nabbaacac", "4\nhgfbdcea", "4\nacbaacac", "4\nhgfbccea", "4\ncacaabca"], "outputs": ["0\n", "4\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]}
228
102
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. There are $N$ cars (numbered $1$ through $N$) on a circular track with length $N$. For each $i$ ($2 ≤ i ≤ N$), the $i$-th of them is at a distance $i...
{"inputs": ["3\n3\n1 1 1\n1 1 1\n3\n3 0 0\n10 0 0\n3\n3 3 3\n3 2 1"], "outputs": ["3\n30\n3"]}
654
60
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. There are some stones in different positions on the X-axis. You are given an integer array stones, the positions of the stones. Call a stone an endpoint stone if it has the smallest or largest position. In one move, y...
{"functional": "def check(candidate):\n assert candidate([7,4,9]) == [1,2]\n assert candidate([6,5,4,3,10]) == [2,3]\n assert candidate([100,101,104,102,103]) == [0,0]\n\n\ncheck(Solution().numMovesStonesII)"}
240
92
coding
Solve the programming task below in a Python markdown code block. Kalila and Dimna are two jackals living in a huge jungle. One day they decided to join a logging factory in order to make money. The manager of logging factory wants them to go to the jungle and cut n trees with heights a_1, a_2, ..., a_{n}. They bough...
{"inputs": ["5\n1 2 3 4 5\n5 4 3 2 0\n", "5\n1 4 3 4 5\n5 4 3 2 0\n", "5\n1 2 3 4 5\n9 4 3 2 0\n", "5\n1 2 3 4 5\n6 4 3 2 0\n", "5\n1 2 3 4 5\n7 4 3 2 0\n", "5\n0 2 5 4 5\n8 4 3 2 0\n", "5\n1 2 5 4 5\n5 4 3 2 0\n", "5\n0 2 5 4 5\n5 4 3 2 0\n"], "outputs": ["25\n", "25\n", "38\n", "30\n", "34\n", "36\n", "25\n", "25\n"]...
569
238
coding
Solve the programming task below in a Python markdown code block. Dreamoon has a string s and a pattern string p. He first removes exactly x characters from s obtaining string s' as a result. Then he calculates $\operatorname{occ}(s^{\prime}, p)$ that is defined as the maximal number of non-overlapping substrings equal...
{"inputs": ["a\na\n", "a\nb\n", "a\na\n", "a\nb\n", "a\naa\n", "a\nab\n", "a\nab\n", "a\naa\n"], "outputs": ["1 0\n", "0 0\n", "1 0 \n", "0 0 \n", "0 0\n", "0 0\n", "0 0 \n", "0 0 \n"]}
413
106
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an m x n matrix board where each cell is a battleship 'X' or empty '.', return the number of the battleships on board. Battleships can only be placed horizontally or vertically on board. In other words, they can...
{"functional": "def check(candidate):\n assert candidate(board = [[\"X\",\".\",\".\",\"X\"],[\".\",\".\",\".\",\"X\"],[\".\",\".\",\".\",\"X\"]]) == 2\n assert candidate(board = [[\".\"]]) == 0\n\n\ncheck(Solution().countBattleships)"}
161
83
coding
Solve the programming task below in a Python markdown code block. Everybody seems to think that the Martians are green, but it turns out they are metallic pink and fat. Ajs has two bags of distinct nonnegative integers. The bags are disjoint, and the union of the sets of numbers in the bags is \{0,1,…,M-1\}, for some p...
{"inputs": ["1 2\n1\n", "1 2\n0\n", "2 5\n3 4\n", "2 4\n1 3\n", "4 20\n5 6 7 16\n", "4 20\n5 2 7 16\n", "9 10\n1 2 3 4 5 6 7 8 9\n", "4 1000000000\n5 25 125 625\n"], "outputs": ["1\n0\n", "1\n0\n", "1\n2\n", "2\n0 2\n", "1\n12 \n", "0\n", "1\n0\n", "0\n\n"]}
568
176
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an integer array cost where cost[i] is the cost of ith step on a staircase. Once you pay the cost, you can either climb one or two steps. You can either start from the step with index 0, or the step with...
{"functional": "def check(candidate):\n assert candidate(cost = [10,15,20]) == 15\n assert candidate(cost = [1,100,1,1,1,100,1,1,100,1]) == 6\n\n\ncheck(Solution().minCostClimbingStairs)"}
121
80
coding
Solve the programming task below in a Python markdown code block. # Task You are given a regular array `arr`. Let's call a `step` the difference between two adjacent elements. Your task is to sum the elements which belong to the sequence of consecutive elements of length `at least 3 (but as long as possible)`, suc...
{"functional": "_inputs = [[[54, 70, 86, 1, -2, -5, 0, 5, 78, 145, 212, 15]], [[59, 58, 57, 55, 53, 51]], [[7, 2, -3, 3, 9, 15]], [[-17, -9, 1, 9, 17, 4, -9]], [[7, 2, 3, 2, -2, 400, 802]], [[-1, 7000, 1, -6998, -13997]]]\n_outputs = [[639], [390], [30], [39], [1200], [-13994]]\nimport math\ndef _deep_eq(a, b, tol=1e-5...
579
344
coding
Solve the programming task below in a Python markdown code block. The only difference between easy and hard versions is the maximum value of $n$. You are given a positive integer number $n$. You really love good numbers so you want to find the smallest good number greater than or equal to $n$. The positive integer is...
{"inputs": ["1\n387420490\n", "1\n506859788\n", "1\n132370398\n", "1\n230139648\n", "1\n152260256\n", "1\n586187597\n", "1\n100214312\n", "1\n218113389\n"], "outputs": ["387420490\n", "516560652\n", "133923132\n", "387420489\n", "172186884\n", "1162261467\n", "129140163\n", "387420489\n"]}
578
215
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. There is an undirected connected tree with n nodes labeled from 0 to n - 1 and n - 1 edges. You are given the integer n and the array edges where edges[i] = [ai, bi] indicates that there is an edge between nodes ai an...
{"functional": "def check(candidate):\n assert candidate(n = 6, edges = [[0,1],[0,2],[2,3],[2,4],[2,5]]) == [8,12,6,10,10,10]\n assert candidate(n = 1, edges = []) == [0]\n assert candidate(n = 2, edges = [[1,0]]) == [1,1]\n\n\ncheck(Solution().sumOfDistancesInTree)"}
148
111
coding
Solve the programming task below in a Python markdown code block. You are given n points on a plane. All the points are distinct and no three of them lie on the same line. Find the number of parallelograms with the vertices at the given points. -----Input----- The first line of the input contains integer n (1 ≤ n ≤ ...
{"inputs": ["1\n0 0\n", "1\n6 6\n", "1\n0 0\n", "1\n6 6\n", "1\n9 6\n", "1\n-1 0\n", "1\n18 6\n", "1\n0 -1\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]}
176
104
coding
Solve the programming task below in a Python markdown code block. There are N cities numbered 1 through N, and M bidirectional roads numbered 1 through M. Road i connects City A_i and City B_i. Snuke can perform the following operation zero or more times: * Choose two distinct cities that are not directly connected b...
{"inputs": ["3 1\n1 1", "5 1\n1 1", "6 1\n1 1", "3 1\n3 2", "5 1\n3 2", "2 1\n1 2", "9 1\n1 2", "8 1\n2 4"], "outputs": ["2\n", "4\n", "5\n", "1\n", "3\n", "0\n", "7\n", "6\n"]}
249
110
coding
Solve the programming task below in a Python markdown code block. # Description "It's the end of trick-or-treating and we have a list/array representing how much candy each child in our group has made out with. We don't want the kids to start arguing, and using our parental intuition we know trouble is brewing as many ...
{"functional": "_inputs = [[[5, 8, 6, 4]], [[1, 2, 4, 6]], [[1, 2]], [[4, 2]], [[1, 3, 3, 7]], [[7, 7, 7, 7]], [[17, 20, 50, 61, 42, 44]], [[0]], [[]], [[4]], [[None]]]\n_outputs = [[9], [11], [1], [2], [14], [0], [132], [-1], [-1], [-1], [-1]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or...
582
281
coding
Solve the programming task below in a Python markdown code block. Vasiliy spent his vacation in a sanatorium, came back and found that he completely forgot details of his vacation! Every day there was a breakfast, a dinner and a supper in a dining room of the sanatorium (of course, in this order). The only thing that...
{"inputs": ["3 2 1\n", "1 0 0\n", "1 1 1\n", "0 1 0\n", "0 0 1\n", "1 1 0\n", "0 1 1\n", "4 3 5\n"], "outputs": ["1\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "1\n"]}
618
102
coding
Solve the programming task below in a Python markdown code block. It is the final day of La Liga. Chef has a certain criteria for assessing football matches. In particular, he only likes a match if: The match ends in a draw, and, At least one goal has been scored by either team. Given the goals scored by both the ...
{"inputs": ["4\n1 1\n0 1\n0 0\n2 2\n"], "outputs": ["YES\nNO\nNO\nYES"]}
395
35
coding
Solve the programming task below in a Python markdown code block. Square1001 has seen an electric bulletin board displaying the integer 1. He can perform the following operations A and B to change this value: - Operation A: The displayed value is doubled. - Operation B: The displayed value increases by K. Square1001 ...
{"inputs": ["4\n4", "4\n7", "4\n2", "4\n0", "4\n1", "4\n6", "4\n5", "4\n3"], "outputs": ["12\n", "15\n", "8\n", "1\n", "5\n", "14\n", "13\n", "10"]}
218
82
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an m x n integer matrix heightMap representing the height of each unit cell in a 2D elevation map, return the volume of water it can trap after raining.   Please complete the following python code precisely: ```...
{"functional": "def check(candidate):\n assert candidate(heightMap = [[1,4,3,1,3,2],[3,2,1,3,2,4],[2,3,3,2,3,1]]) == 4\n assert candidate(heightMap = [[3,3,3,3,3],[3,2,2,2,3],[3,2,1,2,3],[3,2,2,2,3],[3,3,3,3,3]]) == 10\n\n\ncheck(Solution().trapRainWater)"}
86
129
coding
Solve the programming task below in a Python markdown code block. Given a string (`str`) containing a base-10 integer between `0` and `10000`, convert the integer to its binary representation. At that point, obtain a count of the maximum amount of consecutive 0s. From there, return the count in written form with a capi...
{"functional": "_inputs = [['7'], ['33'], ['77'], ['100'], ['105'], ['113'], ['160'], ['180'], ['223'], ['256'], ['777'], ['992'], ['1024'], ['1037'], ['1088'], ['2017'], ['2048'], ['3050'], ['4096'], ['6144'], ['6656'], ['7188'], ['8192'], ['9999'], ['10000']]\n_outputs = [['Zero'], ['Four'], ['Two'], ['Two'], ['Two']...
419
364
coding
Solve the programming task below in a Python markdown code block. I have started studying electronics recently, and I came up with a circuit made up of 2 LEDs and 3 buttons. Here 's how it works: 2 buttons (`red` and `blue`) are connected to the LEDs (`red` and `blue` respectively). Buttons pressing pattern will be re...
{"functional": "_inputs = [['10011010', '10110111'], ['01001000', '01011100'], ['00010100', '01011100'], ['10101010', '01010101'], ['11011011', '11111011']]\n_outputs = [['RBRB'], ['RB'], ['BRB'], ['RBRBRBRB'], ['RBR']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n ...
370
271
coding
Solve the programming task below in a Python markdown code block. You are given two arrays of integers $a_1, a_2, \ldots, a_n$ and $b_1, b_2, \ldots, b_n$. Let's define a transformation of the array $a$: Choose any non-negative integer $k$ such that $0 \le k \le n$. Choose $k$ distinct array indices $1 \le i_1 < i_2...
{"inputs": ["1\n1\n2\n1\n", "1\n1\n3\n2\n", "1\n1\n1\n2\n", "1\n1\n3\n1\n", "1\n1\n5\n4\n", "1\n1\n4\n3\n", "1\n1\n1\n0\n", "1\n1\n2\n3\n"], "outputs": ["NO\n", "NO\n", "YES\n", "NO\n", "NO\n", "NO\n", "NO\n", "YES\n"]}
606
118
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an n x n grid representing a field of cherries, each cell is one of three possible integers. 0 means the cell is empty, so you can pass through, 1 means the cell contains a cherry that you can pick up a...
{"functional": "def check(candidate):\n assert candidate(grid = [[0,1,-1],[1,0,-1],[1,1,1]]) == 5\n assert candidate(grid = [[1,1,-1],[1,-1,1],[-1,1,1]]) == 0\n\n\ncheck(Solution().cherryPickup)"}
266
77
coding
Solve the programming task below in a Python markdown code block. A palindrome is a string that reads the same backward as forward. For example, the strings ${z}$, ${aaa}$, ${aba}$, and ${abccba}$ are palindromes, but ${codeforces}$ and ${ab}$ are not. The double of a string $s$ is obtained by writing each character t...
{"inputs": ["4\na\nsururu\nerrorgorn\nanutforajaroftuna\n"], "outputs": ["aa\nsururuururus\nerrorgornnrogrorre\nanutforajaroftunaanutforajaroftuna\n"]}
447
53
coding
Solve the programming task below in a Python markdown code block. Given an integer $x$, find two non-negative integers $a$ and $b$ such that $(a \wedge b) + (a \vee b) = x$, where $\wedge$ is the bitwise AND operation and $\vee$ is the bitwise OR operation. -----Input----- - The first line of the input contains a sing...
{"inputs": ["2\n1\n8"], "outputs": ["0 1\n5 3"]}
289
22
coding
Solve the programming task below in a Python markdown code block. Kurt reaches nirvana when he finds the product of all the digits of some positive integer. Greater value of the product makes the nirvana deeper. Help Kurt find the maximum possible product of digits among all integers from $1$ to $n$. -----Input-----...
{"inputs": ["7\n", "1\n", "9\n", "2\n", "3\n", "4\n", "1\n", "9\n"], "outputs": ["7\n", "1\n", "9\n", "2\n", "3\n", "4\n", "1", "9"]}
267
68
coding
Solve the programming task below in a Python markdown code block. Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. One day Petya encountered a tree w...
{"inputs": ["2\n1 2 7\n", "2\n1 2 4\n", "2\n1 2 2\n", "2\n1 2 12\n", "2\n2 1 1000000000\n", "2\n2 1 1000010000\n", "2\n2 1 1001010000\n", "4\n1 2 4\n3 1 1\n1 4 7\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "16\n"]}
638
159
coding
Solve the programming task below in a Python markdown code block. You are given string $\boldsymbol{\mathrm{~s~}}$ and number $\boldsymbol{\mbox{k}}$. Consider a substring $\boldsymbol{p}$ of string $\boldsymbol{\mathrm{~S~}}$. For each position of string $\boldsymbol{\mathrm{~S~}}$ mark it if there is an occurence o...
{"inputs": ["abaab\n2\n"], "outputs": ["3\n"]}
432
17
coding
Solve the programming task below in a Python markdown code block. You are given three bags. Each bag contains a non-empty multiset of numbers. You can perform a number of operations on these bags. In one operation, you can choose any two non-empty bags, and choose one number from each of the bags. Let's say that you ch...
{"inputs": ["2 4 1\n1 2\n6 3 4 5\n5\n", "3 2 2\n7 5 4\n2 9\n7 1\n", "3 3 1\n2 3 4\n4 5 6\n5\n", "3 3 1\n2 3 4\n4 5 6\n5\n", "3 3 1\n2 3 4\n4 7 6\n5\n", "3 2 2\n1 5 4\n2 9\n7 1\n", "2 4 1\n1 4\n6 3 4 5\n5\n", "3 3 1\n3 3 4\n4 7 6\n5\n"], "outputs": ["20", "29", "19", "19", "21\n", "25\n", "20\n", "22\n"]}
671
218
coding
Solve the programming task below in a Python markdown code block. There are N points on the 2D plane, i-th of which is located on (x_i, y_i). There can be multiple points that share the same coordinate. What is the maximum possible Manhattan distance between two distinct points? Here, the Manhattan distance between two...
{"inputs": ["2\n0 1\n1 1", "2\n0 0\n1 1", "2\n0 0\n1 2", "2\n1 1\n1 1", "2\n1 1\n1 1\n", "2\n0 -1\n1 2", "2\n9 9\n0 -1", "2\n0 2\n39 0"], "outputs": ["1\n", "2\n", "3\n", "0", "0\n", "4\n", "19\n", "41\n"]}
248
129
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 grid. Each cell of grid represents a street. The street of grid[i][j] can be: 1 which means a street connecting the left cell and the right cell. 2 which means a street connecting the upper cel...
{"functional": "def check(candidate):\n assert candidate(grid = [[2,4,3],[6,5,2]]) == True\n assert candidate(grid = [[1,2,1],[1,2,1]]) == False\n assert candidate(grid = [[1,1,2]]) == False\n assert candidate(grid = [[1,1,1,1,1,1,3]]) == True\n assert candidate(grid = [[2],[2],[2],[2],[2],[2],[6]]) == T...
254
123
coding
Solve the programming task below in a Python markdown code block. Sereja showed an interesting game to his friends. The game goes like that. Initially, there is a table with an empty cup and n water mugs on it. Then all players take turns to move. During a move, a player takes a non-empty mug of water and pours all wat...
{"inputs": ["2 4\n4 4\n", "2 1\n1 1\n", "2 1\n2 2\n", "2 1\n1 1\n", "2 4\n4 4\n", "2 1\n2 2\n", "2 1\n3 2\n", "2 1\n3 4\n"], "outputs": ["YES\n", "YES\n", "NO\n", "YES\n", "YES\n", "NO\n", "NO\n", "NO\n"]}
366
118
coding
Solve the programming task below in a Python markdown code block. Takahashi has two integers X and Y. He computed X + Y and X - Y, and the results were A and B, respectively. Now he cannot remember what X and Y were. Find X and Y for him. -----Constraints----- - -100 \leq A, B \leq 100 - For the given integers A and...
{"inputs": ["3 1\n", "2 -2\n", "-98 4\n", "64 10\n", "-23 71\n", "62 -28\n", "17 -95\n", "-39 -69\n"], "outputs": ["2 1\n", "0 2\n", "-47 -51\n", "37 27\n", "24 -47\n", "17 45\n", "-39 56\n", "-54 15\n"]}
195
125
coding
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. Watson gives an array A of N integers A_{1}, A_{2}, ..., A_{N} to Sherlock. He wants Sherlock to reorganize the array in a way such that no two adjacent numbers differ by mor...
{"inputs": ["2\n4\n3 2 2 3 \n2\n1 5"], "outputs": ["YES\nNO"]}
359
31
coding
Solve the programming task below in a Python markdown code block. Statistics claims that students sleep no more than three hours a day. But even in the world of their dreams, while they are snoring peacefully, the sense of impending doom is still upon them. A poor student is dreaming that he is sitting the mathematica...
{"inputs": ["2 2\n1 1\n", "1 1\n1 1\n", "2 4\n6 6\n", "3 3\n1 1\n", "4 4\n1 1\n", "2 2\n1 2\n", "0 1\n1 1\n", "2 4\n6 8\n"], "outputs": ["YES\n", "YES\n", "YES\n", "NO\n", "NO\n", "YES\n", "YES\n", "YES\n"]}
502
118
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You have n packages that you are trying to place in boxes, one package in each box. There are m suppliers that each produce boxes of different sizes (with infinite supply). A package can be placed in a box if the size...
{"functional": "def check(candidate):\n assert candidate(packages = [2,3,5], boxes = [[4,8],[2,8]]) == 6\n assert candidate(packages = [2,3,5], boxes = [[1,4],[2,3],[3,4]]) == -1\n assert candidate(packages = [3,5,8,10,11,12], boxes = [[12],[11,9],[10,5,14]]) == 9\n\n\ncheck(Solution().minWastedSpace)"}
371
126
coding
Solve the programming task below in a Python markdown code block. Sevenkplus has a regular polygon. Each vertex of the polygon has a color, either white or black. Sevenkplus wants to count the number of isosceles triangles whose vertices are vertices of the regular polygon and have the same color. Input Format The...
{"inputs": ["5\n001\n0001\n10001\n111010\n1101010\n"], "outputs": ["Case 1: 0\nCase 2: 1\nCase 3: 1\nCase 4: 2\nCase 5: 3\n"]}
336
77
coding
Solve the programming task below in a Python markdown code block. Gift Exchange Party A gift exchange party will be held at a school in TKB City. For every pair of students who are close friends, one gift must be given from one to the other at this party, but not the other way around. It is decided in advance the gif...
{"inputs": ["3 3\n1 2\n2 3\n1 3\n4 3\n1 2\n1 3\n1 4\n4 6\n1 2\n1 3\n1 2\n2 3\n3 4\n2 4\n0 0", "3 3\n2 2\n2 3\n2 3\n4 3\n1 2\n1 3\n1 4\n4 6\n1 4\n1 3\n1 4\n2 3\n3 4\n2 4\n0 0", "3 3\n2 2\n2 3\n2 3\n4 3\n1 2\n1 3\n1 4\n6 6\n1 4\n1 3\n1 4\n2 3\n3 4\n2 4\n0 0", "4 3\n1 2\n2 3\n2 3\n4 3\n1 2\n1 3\n1 4\n4 6\n1 4\n1 3\n1 4\n2...
532
638