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. You are given two sorted arrays that contain only integers. Your task is to find a way to merge them into a single one, sorted in **ascending order**. Complete the function `mergeArrays(arr1, arr2)`, where `arr1` and `arr2` are the original sorted arrays...
{"functional": "_inputs = [[[1, 2, 3, 4], [5, 6, 7, 8]], [[10, 8, 6, 4, 2], [9, 7, 5, 3, 1]], [[-20, 35, 36, 37, 39, 40], [-10, -5, 0, 6, 7, 8, 9, 10, 25, 38, 50, 62]], [[5, 6, 7, 8, 9, 10], [20, 18, 15, 14, 13, 12, 11, 4, 3, 2]], [[45, 30, 20, 15, 12, 5], [9, 10, 18, 25, 35, 50]], [[-8, -3, -2, 4, 5, 6, 7, 15, 42, 90,...
198
1,067
coding
Solve the programming task below in a Python markdown code block. Ania has a large integer $S$. Its decimal representation has length $n$ and doesn't contain any leading zeroes. Ania is allowed to change at most $k$ digits of $S$. She wants to do it in such a way that $S$ still won't contain any leading zeroes and it'l...
{"inputs": ["1 1\n1\n", "1 0\n1\n", "1 1\n0\n", "1 0\n0\n", "1 0\n7\n", "1 1\n9\n", "1 1\n5\n", "1 1\n2\n"], "outputs": ["0\n", "1\n", "0\n", "0\n", "7\n", "0\n", "0\n", "0\n"]}
344
102
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. There is a bag that consists of items, each item has a number 1, 0, or -1 written on it. You are given four non-negative integers numOnes, numZeros, numNegOnes, and k. The bag initially contains: numOnes items with 1...
{"functional": "def check(candidate):\n assert candidate(numOnes = 3, numZeros = 2, numNegOnes = 0, k = 2) == 2\n assert candidate(numOnes = 3, numZeros = 2, numNegOnes = 0, k = 4) == 3\n\n\ncheck(Solution().kItemsWithMaximumSum)"}
186
90
coding
Solve the programming task below in a Python markdown code block. Given are integers S and P. Is there a pair of positive integers (N,M) such that N + M = S and N \times M = P? -----Constraints----- - All values in input are integers. - 1 \leq S,P \leq 10^{12} -----Input----- Input is given from Standard Input in t...
{"inputs": ["3 2\n", "2 1\n", "1060 67456\n", "1000000000000 1\n", "7449088 3336990720\n", "6064022 70812167400\n", "2000000 1000000000000\n", "3059787769 226424289430\n"], "outputs": ["Yes\n", "Yes\n", "Yes\n", "No\n", "Yes\n", "Yes\n", "Yes\n", "Yes\n"]}
170
174
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given two strings s1 and s2, both of length n, consisting of lowercase English letters. You can apply the following operation on any of the two strings any number of times: Choose any two indices i and j such...
{"functional": "def check(candidate):\n assert candidate(s1 = \"abcdba\", s2 = \"cabdab\") == True\n assert candidate(s1 = \"abe\", s2 = \"bea\") == False\n\n\ncheck(Solution().checkStrings)"}
145
59
coding
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. You are given two integer arrays A and B each of size N. Let us define interaction of arrays A and B to be the sum of A[i] * B[i] for each i from 1 to N. You want to maximiz...
{"inputs": ["2\n2 2\n2 1\n0 6\n3 9\n1 2 -3\n0 -1 -4", "2\n2 2\n1 2\n-4 6\n3 9\n1 2 -3\n-2 0 0", "2\n2 1\n0 2\n-3 3\n3 2\n1 2 -3\n0 3 -5", "2\n2 2\n1 2\n-2 3\n3 5\n1 2 -3\n-2 3 -5", "2\n2 2\n1 2\n-2 3\n3 2\n1 2 -3\n-2 3 -5", "2\n2 2\n0 2\n-2 3\n3 2\n1 2 -3\n-2 3 -5", "2\n2 1\n0 2\n-2 3\n3 2\n1 2 -3\n-2 3 -5", "2\n2 2\n1...
517
328
coding
Solve the programming task below in a Python markdown code block. There are one cat, $k$ mice, and one hole on a coordinate line. The cat is located at the point $0$, the hole is located at the point $n$. All mice are located between the cat and the hole: the $i$-th mouse is located at the point $x_i$ ($0 < x_i < n$). ...
{"inputs": ["3\n10 6\n8 7 5 4 9 4\n2 8\n1 1 1 1 1 1 1 1\n12 11\n1 2 3 4 5 6 7 8 9 10 11\n"], "outputs": ["3\n1\n4\n"]}
591
85
coding
Solve the programming task below in a Python markdown code block. Mothers arranged a dance party for the children in school. At that party, there are only mothers and their children. All are having great fun on the dance floor when suddenly all the lights went out. It's a dark night and no one can see each other. But y...
{"functional": "_inputs = [['abBA'], ['AaaaaZazzz'], ['CbcBcbaA'], ['xXfuUuuF'], ['']]\n_outputs = [['AaBb'], ['AaaaaaZzzz'], ['AaBbbCcc'], ['FfUuuuXx'], ['']]\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...
191
209
coding
Solve the programming task below in a Python markdown code block. Vasya learned about integer subtraction in school. He is still not very good at it, so he is only able to subtract any single digit number from any other number (which is not necessarily single digit). For practice, Vasya chose a positive integer n$n$ an...
{"inputs": ["3\n2\n3\n100"], "outputs": ["9\n10\n170"]}
566
27
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an integer array nums, partition it into two (contiguous) subarrays left and right so that: Every element in left is less than or equal to every element in right. left and right are non-empty. left has the smal...
{"functional": "def check(candidate):\n assert candidate(nums = [5,0,3,8,6]) == 3\n assert candidate(nums = [1,1,1,0,6,12]) == 4\n\n\ncheck(Solution().partitionDisjoint)"}
121
63
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a non-negative integer c, decide whether there're two integers a and b such that a2 + b2 = c.   Please complete the following python code precisely: ```python class Solution: def judgeSquareSum(self, c: int)...
{"functional": "def check(candidate):\n assert candidate(c = 5) == True\n assert candidate(c = 3) == False\n\n\ncheck(Solution().judgeSquareSum)"}
74
42
coding
Solve the programming task below in a Python markdown code block. You are given two strings $s$ and $t$ both of length $2$ and both consisting only of characters 'a', 'b' and 'c'. Possible examples of strings $s$ and $t$: "ab", "ca", "bb". You have to find a string $res$ consisting of $3n$ characters, $n$ characters ...
{"inputs": ["2\nab\nbc\n", "3\naa\nbc\n", "1\ncb\nac\n", "1\nab\ncb\n", "3\nbb\ncb\n", "4\naa\nbb\n", "4\naa\nbc\n", "4\nbc\nca\n"], "outputs": ["YES\nacbacb\n", "YES\nacbacbacb\n", "YES\nabc\n", "YES\nbac\n", "YES\nabcabcabc\n", "YES\nabcabcabcabc\n", "YES\nacbacbacbacb\n", "YES\nacbacbacbacb\n"]}
478
139
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. We say that an integer x is expressible from nums if there exist some integers 0 <= index1 < index2 < ... < indexk < nums.length for which nums[index1] | nums[index2] | .....
{"functional": "def check(candidate):\n assert candidate(nums = [2,1]) == 4\n assert candidate(nums = [5,3,2]) == 1\n\n\ncheck(Solution().minImpossibleOR)"}
156
50
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a string of length 5 called time, representing the current time on a digital clock in the format "hh:mm". The earliest possible time is "00:00" and the latest possible time is "23:59". In the string time...
{"functional": "def check(candidate):\n assert candidate(time = \"?5:00\") == 2\n assert candidate(time = \"0?:0?\") == 100\n assert candidate(time = \"??:??\") == 1440\n\n\ncheck(Solution().countTime)"}
159
69
coding
Solve the programming task below in a Python markdown code block. You're on your way to the market when you hear beautiful music coming from a nearby street performer. The notes come together like you wouln't believe as the musician puts together patterns of tunes. As you wonder what kind of algorithm you could use to ...
{"functional": "_inputs = [['Your girlscout cookies are ready to ship. Your total comes to tree fiddy'], [\"Howdy Pardner. Name's Pete Lexington. I reckon you're the kinda stiff who carries about tree fiddy?\"], [\"I'm from Scottland. I moved here to be with my family sir. Please, $3.50 would go a long way to help me f...
301
439
coding
Solve the programming task below in a Python markdown code block. The Padovan sequence is the sequence of integers `P(n)` defined by the initial values `P(0)=P(1)=P(2)=1` and the recurrence relation `P(n)=P(n-2)+P(n-3)` The first few values of `P(n)` are `1, 1, 1, 2, 2, 3, 4, 5, 7, 9, 12, 16, 21, 28, 37, 49, 65, 8...
{"functional": "_inputs = [[100]]\n_outputs = [[1177482265857]]\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 ...
255
168
coding
Solve the programming task below in a Python markdown code block. [3R2 as DJ Mashiro - Happiness Breeze](https://open.spotify.com/track/2qGqK8GRS65Wlf20qUBEak) [Ice - DJ Mashiro is dead or alive](https://soundcloud.com/iceloki/dj-mashiro-is-dead-or-alive) NEKO#ΦωΦ has just got a new maze game on her PC! The game's m...
{"inputs": ["4 1\n1 4\n", "5 1\n1 4\n", "2 2\n2 1\n1 2\n", "2 4\n2 1\n1 2\n1 2\n1 2\n", "4 4\n2 1\n1 2\n1 2\n1 2\n", "4 4\n2 1\n1 2\n1 2\n2 2\n", "5 5\n2 3\n2 4\n2 4\n2 3\n1 4\n", "5 5\n2 3\n1 4\n2 4\n2 3\n1 4\n"], "outputs": ["Yes\n", "Yes\n", "Yes\nNo\n", "Yes\nNo\nYes\nNo\n", "Yes\nNo\nYes\nNo\n", "Yes\nNo\nYes\nYes...
714
226
coding
Solve the programming task below in a Python markdown code block. On Unix system type files can be identified with the ls -l command which displays the type of the file in the first alphabetic letter of the file system permissions field. You can find more information about file type on Unix system on the [wikipedia pag...
{"functional": "_inputs = [['-rwxrwxrwx'], ['Drwxr-xr-x'], ['lrwxrw-rw-'], ['srwxrwxrwx']]\n_outputs = [['file'], ['door'], ['symlink'], ['socket']]\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 isin...
289
195
coding
Solve the programming task below in a Python markdown code block. Your algorithms have become so good at predicting the market that you now know what the share price of Wooden Orange Toothpicks Inc. (WOT) will be for the next number of days. Each day, you can either buy one share of WOT, sell any number of shares of W...
{"inputs": ["3\n3\n5 3 2\n3\n1 2 100\n4\n1 3 1 2"], "outputs": ["0\n197\n3\n"]}
568
47
coding
Solve the programming task below in a Python markdown code block. Sardar Singh has many men fighting for him, and he would like to calculate the power of each of them to better plan for his fight against Ramadhir. The power of a string S of lowercase English alphabets is defined to be \sum_{i = 1}^{|S|} i\cdot ord(S...
{"inputs": ["1\nfaizal"], "outputs": ["273"]}
450
18
coding
Solve the programming task below in a Python markdown code block. Gildong is now developing a puzzle game. The puzzle consists of n platforms numbered from 1 to n. The player plays the game as a character that can stand on each platform and the goal of the game is to move the character from the 1-st platform to the n-t...
{"inputs": ["3\n4\n1 1 1 0\n5\n4 3 2 1 0\n9\n4 1 4 3 1 0 2 1 0\n", "3\n4\n1 1 1 0\n5\n4 3 2 1 0\n9\n4 1 4 2 1 0 2 0 0\n", "3\n4\n1 1 1 0\n5\n2 3 2 1 0\n9\n3 1 4 1 1 0 2 1 0\n", "3\n4\n1 1 1 0\n5\n4 3 2 1 0\n9\n4 2 4 3 1 0 2 1 0\n", "3\n4\n2 1 1 0\n5\n2 3 2 1 0\n9\n3 1 4 1 0 0 2 1 0\n", "3\n4\n1 1 1 0\n5\n4 2 2 1 0\n9\n...
647
438
coding
Solve the programming task below in a Python markdown code block. You are given a 4-character string S consisting of uppercase English letters. Determine if S consists of exactly two kinds of characters which both appear twice in S. -----Constraints----- - The length of S is 4. - S consists of uppercase English lett...
{"inputs": ["EEFF", "FQEE", "SPOT", "ASRA", "EEQF", "SPNT", "ARSA", "EEQG"], "outputs": ["Yes\n", "No\n", "No\n", "No\n", "No\n", "No\n", "No\n", "No\n"]}
135
73
coding
Solve the programming task below in a Python markdown code block. Coolguy gives you a simple problem. Given a $1$-indexed array, $\mbox{A}$, containing $N$ elements, what will $\textit{and}$ be after this pseudocode is implemented and executed? Print $and\%(10^9+7)$. //f(a, b) is a function that returns the minimum el...
{"inputs": ["3\n3 2 1\n"], "outputs": ["6\n"]}
459
20
coding
Solve the programming task below in a Python markdown code block. Consider an N \times M binary matrix A, i.e. a grid consisting of N rows numbered 1 to N from top to bottom and M columns numbered 1 to M from left to right, whose cells take the value 0 or 1. Let (i, j) denote the cell on the i-th row and j-th column. ...
{"inputs": ["2\n3 3\n4 5"], "outputs": ["5\n10"]}
439
23
coding
Solve the programming task below in a Python markdown code block. # Summary: Given a number, `num`, return the shortest amount of `steps` it would take from 1, to land exactly on that number. # Description: A `step` is defined as either: - Adding 1 to the number: `num += 1` - Doubling the number: `num *= 2` You will ...
{"functional": "_inputs = [[2], [3], [4], [5], [6], [7], [8], [9], [10], [20], [30], [40], [50], [11], [24], [37], [19], [48], [59], [65], [73], [83], [64], [99], [100], [10000], [1500], [1534], [1978], [2763], [9999], [2673], [4578], [9876], [2659], [7777], [9364], [7280], [4998], [9283], [8234], [7622], [800], [782],...
345
567
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given two integers m and n representing the dimensions of a 0-indexed m x n grid. You are also given a 0-indexed 2D integer matrix coordinates, where coordinates[i] = [x, y] indicates that the cell with coordi...
{"functional": "def check(candidate):\n assert candidate(m = 3, n = 3, coordinates = [[0,0]]) == [3,1,0,0,0]\n assert candidate(m = 3, n = 3, coordinates = [[0,0],[1,1],[0,2]]) == [0,2,2,0,0]\n\n\ncheck(Solution().countBlackBlocks)"}
257
94
coding
Solve the programming task below in a Python markdown code block. The city of Gridland is represented as an $n\times m$ matrix where the rows are numbered from $1$ to $n$ and the columns are numbered from $1$ to $m$. Gridland has a network of train tracks that always run in straight horizontal lines along a row. In ot...
{"inputs": ["4 4 3\n2 2 3\n3 1 4\n4 4 4\n"], "outputs": ["9\n"]}
702
36
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. A substring is a contiguous (non-empty) sequence of characters within a string. A vowel substring is a substring that only consists of vowels ('a', 'e', 'i', 'o', and 'u') and has all five vowels present in it. Given ...
{"functional": "def check(candidate):\n assert candidate(word = \"aeiouu\") == 2\n assert candidate(word = \"unicornarihan\") == 0\n assert candidate(word = \"cuaieuouac\") == 7\n assert candidate(word = \"bbaeixoubb\") == 0\n\n\ncheck(Solution().countVowelSubstrings)"}
117
83
coding
Solve the programming task below in a Python markdown code block. During the hypnosis session, Nicholas suddenly remembered a positive integer $n$, which doesn't contain zeros in decimal notation. Soon, when he returned home, he got curious: what is the maximum number of digits that can be removed from the number so t...
{"inputs": ["1\n1\n9\n", "1\n1\n1\n", "1\n1\n8\n", "1\n1\n4\n", "1\n1\n6\n", "1\n2\n77\n", "1\n2\n77\n", "1\n2\n83\n"], "outputs": ["1\n9\n", "1\n1\n", "1\n8\n", "1\n4\n", "1\n6\n", "2\n77\n", "2\n77\n", "1\n8\n"]}
630
123
coding
Solve the programming task below in a Python markdown code block. Exceptions Errors detected during execution are called exceptions. Examples: ZeroDivisionError This error is raised when the second argument of a division or modulo operation is zero. >>> a = '1' >>> b = '0' >>> print int(a) / int(b) >>> ZeroDivisi...
{"inputs": ["3\n1 0\n2 $\n3 1\n"], "outputs": ["Error Code: integer division or modulo by zero\nError Code: invalid literal for int() with base 10: '$'\n3\n"]}
402
52
coding
Solve the programming task below in a Python markdown code block. Based on the information of the time when study started and the time when study ended, check whether the total time studied in one day is t or more, and if not, create a program to find the shortage time. Time is one unit per hour, and minutes and second...
{"inputs": ["10\n3\n8 11\n12 19\n18 9\n8\n2\n6 6\n5 6\n0", "10\n3\n8 11\n12 19\n18 9\n8\n2\n4 6\n5 6\n0", "10\n3\n6 11\n12 19\n18 9\n8\n2\n4 6\n5 6\n0", "10\n3\n6 11\n12 19\n18 9\n8\n2\n3 6\n5 6\n0", "10\n3\n6 11\n12 19\n18 9\n8\n2\n3 6\n5 9\n0", "10\n3\n8 11\n12 19\n18 38\n8\n2\n6 6\n5 6\n0", "10\n3\n8 8\n12 19\n18 8\...
530
346
coding
Solve the programming task below in a Python markdown code block. An integer N is a multiple of 9 if and only if the sum of the digits in the decimal representation of N is a multiple of 9. Determine whether N is a multiple of 9. -----Constraints----- - 0 \leq N < 10^{200000} - N is an integer. -----Input----- Inpu...
{"inputs": ["1", "2", "3", "9", "6", "8", "4", "0"], "outputs": ["No\n", "No\n", "No\n", "Yes\n", "No\n", "No\n", "No\n", "Yes"]}
193
61
coding
Solve the programming task below in a Python markdown code block. The letters shop showcase is a string s, consisting of n lowercase Latin letters. As the name tells, letters are sold in the shop. Letters are sold one by one from the leftmost to the rightmost. Any customer can only buy some prefix of letters from the ...
{"inputs": ["4\nabcd\n3\na\nd\nac\n", "4\nacbd\n3\na\nd\nac\n", "4\ndbca\n3\na\nd\nca\n", "4\nacbd\n3\na\nc\nac\n", "4\nacbd\n3\nb\nd\nca\n", "4\ndcba\n3\na\nc\nac\n", "4\nacbd\n3\nb\nd\ncb\n", "4\ndbca\n3\na\nc\nac\n"], "outputs": ["1\n4\n3\n", "1\n4\n2\n", "4\n1\n4\n", "1\n2\n2\n", "3\n4\n2\n", "4\n2\n4\n", "3\n4\n3\...
588
192
coding
Solve the programming task below in a Python markdown code block. Let's write all the positive integer numbers one after another from $1$ without any delimiters (i.e. as a single string). It will be the infinite sequence starting with 123456789101112131415161718192021222324252627282930313233343536... Your task is to p...
{"inputs": ["7\n", "1\n", "2\n", "3\n", "4\n", "5\n", "6\n", "8\n"], "outputs": ["7\n", "1\n", "2\n", "3\n", "4\n", "5\n", "6\n", "8\n"]}
206
70
coding
Solve the programming task below in a Python markdown code block. Monica decides that she would like to get to know the neighbours in the apartment better. She makes a batch of wonderful chocolates and hangs them on the door in a basket hoping that her neighbors will take some and they can meet. The neighbours (includi...
{"inputs": ["3\n3\n2 1 1\n3\n0 5 0\n4\n3 0 2 1\n"], "outputs": ["4\n1\n3\n"]}
741
44
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an undirected graph. You are given an integer n which is the number of nodes in the graph and an array edges, where each edges[i] = [ui, vi] indicates that there is an undirected edge between ui and vi. ...
{"functional": "def check(candidate):\n assert candidate(n = 6, edges = [[1,2],[1,3],[3,2],[4,1],[5,2],[3,6]]) == 3\n assert candidate(n = 7, edges = [[1,3],[4,1],[4,3],[2,5],[5,6],[6,7],[7,5],[2,6]]) == 0\n\n\ncheck(Solution().minTrioDegree)"}
176
107
coding
Solve the programming task below in a Python markdown code block. A direced graph is strongly connected if every two nodes are reachable from each other. In a strongly connected component of a directed graph, every two nodes of the component are mutually reachable. Constraints * 1 ≤ |V| ≤ 10,000 * 0 ≤ |E| ≤ 30,000 * ...
{"inputs": ["5 6\n0 1\n1 0\n0 2\n2 4\n4 3\n3 2\n4\n0 1\n0 3\n2 3\n3 4", "5 6\n0 1\n1 0\n1 2\n2 4\n4 3\n3 2\n4\n0 1\n0 3\n2 0\n3 4", "5 6\n0 1\n1 0\n1 2\n2 4\n4 0\n3 2\n4\n0 1\n0 3\n2 0\n3 4", "5 6\n0 1\n1 0\n1 2\n2 4\n1 1\n3 2\n4\n0 1\n0 3\n2 0\n3 4", "7 6\n0 1\n1 0\n1 2\n2 4\n4 3\n3 2\n4\n1 2\n0 3\n2 3\n3 4", "5 6\n0 ...
336
460
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a string s and a character c that occurs in s, return an array of integers answer where answer.length == s.length and answer[i] is the distance from index i to the closest occurrence of character c in s. The dis...
{"functional": "def check(candidate):\n assert candidate(s = \"loveleetcode\", c = \"e\") == [3,2,1,0,1,0,0,1,2,2,1,0]\n assert candidate(s = \"aaab\", c = \"b\") == [3,2,1,0]\n\n\ncheck(Solution().shortestToChar)"}
120
87
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an integer n and a 0-indexed 2D array queries where queries[i] = [typei, indexi, vali]. Initially, there is a 0-indexed n x n matrix filled with 0's. For each query, you must apply one of the following c...
{"functional": "def check(candidate):\n assert candidate(n = 3, queries = [[0,0,1],[1,2,2],[0,2,3],[1,0,4]]) == 23\n assert candidate(n = 3, queries = [[0,0,4],[0,1,2],[1,0,1],[0,2,3],[1,2,1]]) == 17\n\n\ncheck(Solution().matrixSumQueries)"}
184
106
coding
Solve the programming task below in a Python markdown code block. The penultimate task involved the calculation of the typical Fibonacci sequence up to the nth term. Input – single integer n Output – Fibonacci sequence up to the nth term, all terms on a new line SAMPLE INPUT 5 SAMPLE OUTPUT 1 1 2 3 5
{"inputs": ["5"], "outputs": ["1\n1\n2\n3\n5"]}
71
20
coding
Solve the programming task below in a Python markdown code block. You need to handle two extraordinarily large integers. The good news is that you don't need to perform any arithmetic operation on them. You just need to compare them and see whether they are equal or one is greater than the other. Given two strings x a...
{"inputs": ["27\n0!!!\n0\n1\n1!!!\n2!!!\n2\n3!!!\n999999999\n0!\n0\n11!\n40000000\n3!!\n721\n3\n2!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n7!!!\n3!!!!\n0!\n2\n1\n2\n0\n0\n3!!!!\n4!!!!\n15!\n999999999\n999999999\n4!!\n7!!!\n5000!!\n40321\n8!\n3!\n5\n5!!\n3!!!\n7!\n3!!\n3!\n7\n6!\n719\n719!!\n6!!!\n6!\n721\n721!!!!\n6...
218
655
coding
Solve the programming task below in a Python markdown code block. Given a string of integers, return the number of odd-numbered substrings that can be formed. For example, in the case of `"1341"`, they are `1, 1, 3, 13, 41, 341, 1341`, a total of `7` numbers. `solve("1341") = 7`. See test cases for more examples. ...
{"functional": "_inputs = [['1341'], ['1357'], ['13471'], ['134721'], ['1347231'], ['13472315']]\n_outputs = [[7], [10], [12], [13], [20], [28]]\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 isinstan...
215
217
coding
Solve the programming task below in a Python markdown code block. Chef is the new king of the country Chefland. As first and most important responsibility he wants to reconstruct the road system of Chefland. There are N (1 to N) cities in the country and each city i has a population Pi. Chef wants to build some bi-dire...
{"inputs": ["2\n2\n9 3\n4\n29 0 4 2", "2\n2\n8 9\n4\n5 18 2 5", "2\n2\n8 9\n4\n5 36 2 5", "2\n2\n9 2\n4\n29 0 4 2", "2\n2\n8 9\n4\n4 18 2 5", "2\n2\n8 9\n4\n5 18 2 13", "2\n2\n3 5\n4\n8 10 7 13", "2\n2\n3 5\n4\n9 10 7 13"], "outputs": ["27\n0\n", "72\n56\n", "72\n92\n", "18\n0\n", "72\n54\n", "72\n72\n", "15\n217\n", "...
339
233
coding
Solve the programming task below in a Python markdown code block. Eighth-grader Vova is on duty today in the class. After classes, he went into the office to wash the board, and found on it the number n. He asked what is this number and the teacher of mathematics Inna Petrovna answered Vova that n is the answer to the ...
{"inputs": ["2\n", "9\n", "3\n", "1\n", "4\n", "5\n", "8\n", "6\n"], "outputs": ["1\n1 ", "0\n", "0\n", "0\n", "1\n2\n", "0\n\n", "1\n4\n", "1\n3\n"]}
294
78
coding
Solve the programming task below in a Python markdown code block. Vasya follows a basketball game and marks the distances from which each team makes a throw. He knows that each successful throw has value of either 2 or 3 points. A throw is worth 2 points if the distance it was made from doesn't exceed some value of d m...
{"inputs": ["1\n3\n1\n3\n", "1\n3\n1\n3\n", "1\n3\n1\n1\n", "1\n1\n2\n1 2\n", "1\n1\n2\n1 1\n", "1\n1\n2\n1 2\n", "1\n1\n2\n1 1\n", "2\n2 2\n2\n2 2\n"], "outputs": ["3:3\n", "3:3", "3:2\n", "2:4\n", "2:4\n", "2:4", "2:4", "6:6\n"]}
378
143
coding
Solve the programming task below in a Python markdown code block. The male gametes or sperm cells in humans and other mammals are heterogametic and contain one of two types of sex chromosomes. They are either X or Y. The female gametes or eggs however, contain only the X sex chromosome and are homogametic. The sperm c...
{"functional": "_inputs = [['XY'], ['XX']]\n_outputs = [[\"Congratulations! You're going to have a son.\"], [\"Congratulations! You're going to have a daughter.\"]]\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...
215
181
coding
Solve the programming task below in a Python markdown code block. Let S(n) denote the sum of the digits in the decimal notation of n. For example, S(123) = 1 + 2 + 3 = 6. We will call an integer n a Snuke number when, for all positive integers m such that m > n, \frac{n}{S(n)} \leq \frac{m}{S(m)} holds. Given an intege...
{"inputs": ["7", "5", "8", "2", "6", "4", "1", "3"], "outputs": ["1\n2\n3\n4\n5\n6\n7\n", "1\n2\n3\n4\n5\n", "1\n2\n3\n4\n5\n6\n7\n8\n", "1\n2\n", "1\n2\n3\n4\n5\n6\n", "1\n2\n3\n4\n", "1\n", "1\n2\n3\n"]}
211
118
coding
Solve the programming task below in a Python markdown code block. Rakesh has built a model rocket and wants to test how stable it is. He usually uses a magic box which runs some tests on the rocket and tells if it is stable or not, but his friend broke it by trying to find out how stable he is (very delicate magic inde...
{"inputs": ["1\n10 12 4 5 3"], "outputs": ["0"]}
585
24
coding
Solve the programming task below in a Python markdown code block. Oh, New Year. The time to gather all your friends and reflect on the heartwarming events of the past year... $n$ friends live in a city which can be represented as a number line. The $i$-th friend lives in a house with an integer coordinate $x_i$. The $...
{"inputs": ["1\n1\n", "1\n1\n", "2\n1 1\n", "2\n1 2\n", "2\n1 2\n", "2\n1 1\n", "2\n2 2\n", "2\n2 1\n"], "outputs": ["1 1\n", "1 1\n", "1 2\n", "1 2\n", "1 2\n", "1 2\n", "1 2\n", "1 2\n"]}
663
114
coding
Solve the programming task below in a Python markdown code block. In AtCoder city, there are five antennas standing in a straight line. They are called Antenna A, B, C, D and E from west to east, and their coordinates are a, b, c, d and e, respectively. Two antennas can communicate directly if the distance between the...
{"inputs": ["1\n0\n7\n1\n5\n3", "1\n0\n7\n0\n5\n3", "1\n0\n9\n0\n5\n3", "1\n0\n5\n8\n4\n1", "1\n0\n7\n2\n5\n3", "1\n1\n9\n0\n5\n3", "1\n0\n5\n8\n4\n0", "1\n0\n2\n8\n4\n1"], "outputs": [":(\n", ":(\n", ":(\n", ":(\n", ":(\n", ":(\n", ":(\n", ":(\n"]}
451
150
coding
Solve the programming task below in a Python markdown code block. Given an array $a$ of $n$ elements, print any value that appears at least three times or print -1 if there is no such value. -----Input----- The first line contains an integer $t$ ($1 \leq t \leq 10^4$) — the number of test cases. The first line of e...
{"inputs": ["7\n1\n1\n3\n2 2 2\n7\n2 2 3 3 4 2 2\n8\n1 4 3 4 3 2 4 1\n9\n1 1 1 2 2 2 3 3 3\n5\n1 5 2 4 3\n4\n4 4 4 4\n"], "outputs": ["-1\n2\n2\n4\n3\n-1\n4\n"]}
499
116
coding
Solve the programming task below in a Python markdown code block. Given a mathematical equation that has `*,+,-,/`, reverse it as follows: ```Haskell solve("100*b/y") = "y/b*100" solve("a+b-c/d*30") = "30*d/c-b+a" ``` More examples in test cases. Good luck! Please also try: [Simple time difference](https://www.co...
{"functional": "_inputs = [['100*b/y'], ['a+b-c/d*30'], ['a*b/c+50']]\n_outputs = [['y/b*100'], ['30*d/c-b+a'], ['50+c/b*a']]\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)...
181
195
coding
Solve the programming task below in a Python markdown code block. You are given a weighted undirected graph. The vertices are enumerated from 1 to n. Your task is to find the shortest path between the vertex 1 and the vertex n. Input The first line contains two integers n and m (2 ≤ n ≤ 105, 0 ≤ m ≤ 105), where n is ...
{"inputs": ["2 1\n1 2 1\n", "3 1\n1 2 1\n", "2 1\n1 2 0\n", "2 1\n1 1 1\n", "3 1\n2 2 1\n", "3 3\n1 2 1\n1 3 2\n2 3 1\n", "3 3\n1 2 1\n1 3 2\n2 3 0\n", "3 3\n1 2 1\n1 3 2\n1 3 1\n"], "outputs": ["1 2\n", "-1\n", "1 2\n", "-1\n", "-1\n", "1 3\n", "1 2 3\n", "1 3\n"]}
299
182
coding
Solve the programming task below in a Python markdown code block. We have N+1 integers: 10^{100}, 10^{100}+1, ..., 10^{100}+N. We will choose K or more of these integers. Find the number of possible values of the sum of the chosen numbers, modulo (10^9+7). -----Constraints----- - 1 \leq N \leq 2\times 10^5 - 1 \leq ...
{"inputs": ["3 1", "1 1", "3 4", "6 1", "2 1", "6 2", "4 3", "4 1"], "outputs": ["14\n", "3\n", "1\n", "63\n", "7\n", "56\n", "13\n", "25\n"]}
620
83
coding
Solve the programming task below in a Python markdown code block. Shortest Common Non-Subsequence A subsequence of a sequence $P$ is a sequence that can be derived from the original sequence $P$ by picking up some or no elements of $P$ preserving the order. For example, "ICPC" is a subsequence of "MICROPROCESSOR". A ...
{"inputs": ["0101\n1101001", "0101\n1100000", "0101\n1101000", "0101\n0001000", "0101\n0011001", "0101\n0110001", "0101\n1111001", "0101\n1001001"], "outputs": ["0000\n", "111\n", "0001\n", "110\n", "1000\n", "0010\n", "000\n", "0110\n"]}
448
171
coding
Solve the programming task below in a Python markdown code block. You are given a regular polygon with $n$ vertices labeled from $1$ to $n$ in counter-clockwise order. The triangulation of a given polygon is a set of triangles such that each vertex of each triangle is a vertex of the initial polygon, there is no pair o...
{"inputs": ["3\n", "4\n", "5\n", "6\n", "7\n", "8\n", "9\n", "5\n"], "outputs": ["6\n", "18\n", "38\n", "68\n", "110\n", "166\n", "238\n", "38\n"]}
383
80
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an integer n denoting the total number of servers and a 2D 0-indexed integer array logs, where logs[i] = [server_id, time] denotes that the server with id server_id received a request at time time. You a...
{"functional": "def check(candidate):\n assert candidate(n = 3, logs = [[1,3],[2,6],[1,5]], x = 5, queries = [10,11]) == [1,2]\n assert candidate(n = 3, logs = [[2,4],[2,1],[1,2],[3,1]], x = 2, queries = [3,4]) == [0,1]\n\n\ncheck(Solution().countServers)"}
183
109
coding
Solve the programming task below in a Python markdown code block. Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 1018 numbers in a single second. One day ...
{"inputs": ["0\n0\n", "0\n1\n", "10\n01\n", "000\n111\n", "1110\n1010\n", "01110\n01100\n", "011101\n000001\n", "011101\n000000\n"], "outputs": ["0\n", "1\n", "11\n", "111\n", "0100\n", "00010\n", "011100\n", "011101\n"]}
471
146
coding
Solve the programming task below in a Python markdown code block. Gregor is learning about RSA cryptography, and although he doesn't understand how RSA works, he is now fascinated with prime numbers and factoring them. Gregor's favorite prime number is $P$. Gregor wants to find two bases of $P$. Formally, Gregor is lo...
{"inputs": ["2\n7\n5\n", "1\n271\n", "1\n833\n", "1\n497\n", "1\n643\n", "1\n997\n", "1\n611\n", "1\n887\n"], "outputs": ["2 6\n2 4\n", "2 270\n", "2 832\n", "2 496\n", "2 642\n", "2 996\n", "2 610\n", "2 886\n"]}
367
136
coding
Solve the programming task below in a Python markdown code block. Chan has decided to make a list of all possible combinations of letters of a given string S. If there are two strings with the same set of characters, print the lexicographically smallest arrangement of the two strings. abc acb cab bac bca all the abo...
{"inputs": ["2\n2\nab\n3\nxyz\n"], "outputs": ["a\nab\nb\nx\nxy\nxyz\nxz\ny\nyz\nz\n"]}
300
40
coding
Solve the programming task below in a Python markdown code block. Stellar history 2005.11.5. You are about to engage an enemy spacecraft as the captain of the UAZ Advance spacecraft. Fortunately, the enemy spaceship is still unnoticed. In addition, the space coordinates of the enemy are already known, and the "feather ...
{"inputs": ["-19 0 0\n14 0 0\n0 2 1\n0 8 9\n0 0 8", "-19 0 0\n14 0 0\n1 2 1\n0 8 9\n0 0 8", "-2 0 0\n14 0 0\n1 1 1\n0 8 9\n-1 0 4", "-2 0 0\n14 0 0\n1 1 1\n0 8 9\n-2 0 4", "-2 0 1\n14 0 0\n1 1 1\n0 8 9\n-2 0 4", "-2 0 1\n14 0 0\n1 1 1\n0 8 9\n-1 0 4", "-4 0 1\n14 0 0\n1 1 2\n0 5 9\n-1 0 4", "-4 0 2\n14 0 0\n1 1 2\n0 5 ...
561
311
coding
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin Chinese and Russian. Mike is fond of collecting stamps. He has a lot of rare and unusual ones in his collection. Unfortunately, a few days ago he was fired from his well-paid job. But he doesn't complain about tha...
{"inputs": ["4 3\n2 1 2\n2 2 3\n2 3 4\n"], "outputs": ["2"]}
434
33
coding
Solve the programming task below in a Python markdown code block. Victor tries to write his own text editor, with word correction included. However, the rules of word correction are really strange. Victor thinks that if a word contains two consecutive vowels, then it's kinda weird and it needs to be replaced. So the w...
{"inputs": ["1\na\n", "1\nb\n", "1\ne\n", "1\ne\n", "1\na\n", "1\nb\n", "1\nf\n", "1\n`\n"], "outputs": ["a\n", "b\n", "e\n", "e\n", "a\n", "b\n", "f\n", "`\n"]}
316
86
coding
Solve the programming task below in a Python markdown code block. Read problems statements in [Mandarin Chinese], [Russian], [Vietnamese] and [Bengali] as well. You are given a tree of $N$ nodes rooted at node $1$. Each node $u$ initially has a positive value $a_{u}$ associated with it. You randomly choose one node i...
{"inputs": ["3\n1\n1\n4\n1 2\n2 3\n2 4\n1 1 1 2\n7\n1 2\n1 3\n2 4\n2 5\n3 6\n3 7\n1 2 3 4 1 2 1\n"], "outputs": ["1\n4\n14\n"]}
716
85
coding
Solve the programming task below in a Python markdown code block. Snuke has an integer sequence A of length N. He will make three cuts in A and divide it into four (non-empty) contiguous subsequences B, C, D and E. The positions of the cuts can be freely chosen. Let P,Q,R,S be the sums of the elements in B,C,D,E, res...
{"inputs": ["5\n3 2 4 2 2", "5\n5 2 4 2 1", "5\n4 3 4 2 1", "5\n2 1 6 0 2", "5\n2 3 6 2 1", "5\n2 1 7 0 2", "5\n2 1 7 0 0", "5\n8 0 2 2 0"], "outputs": ["2\n", "3\n", "1\n", "5\n", "4\n", "6\n", "7\n", "8\n"]}
311
142
coding
Solve the programming task below in a Python markdown code block. We need a function (for commercial purposes) that may perform integer partitions with some constraints. The function should select how many elements each partition should have. The function should discard some "forbidden" values in each partition. So, cr...
{"functional": "_inputs = [[10, 3, 2], [10, 3, 0], [10, 4, 1], [10, 5, 3], [15, 5, 3], [15, 5, 4], [15, 3, 3]]\n_outputs = [[4], [8], [2], [4], [15], [19], [13]]\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)...
491
242
coding
Solve the programming task below in a Python markdown code block. You are given 3 numbers a, b and x. You need to output the multiple of x which is closest to a^{b}. If more than one answer exists , display the smallest one. Input Format The first line contains T, the number of testcases. T lines follow, each line...
{"inputs": ["3\n349 1 4\n395 1 7\n4 -2 2\n"], "outputs": ["348\n392\n0\n"]}
277
44
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 the number of distinct subsequences of s which equals t. The test cases are generated so that the answer fits on a 32-bit signed integer.   Please complete the following python code p...
{"functional": "def check(candidate):\n assert candidate(s = \"rabbbit\", t = \"rabbit\") == 3\n assert candidate(s = \"babgbag\", t = \"bag\") == 5\n\n\ncheck(Solution().numDistinct)"}
90
57
coding
Solve the programming task below in a Python markdown code block. Make a function that will return a greeting statement that uses an input; your program should return, `"Hello, how are you doing today?"`. SQL: return results in a column named ```greeting``` *[Make sure you type the exact thing I wrote or the program...
{"functional": "_inputs = [['Ryan'], ['Shingles']]\n_outputs = [['Hello, Ryan how are you doing today?'], ['Hello, Shingles how are you doing today?']]\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 i...
95
178
coding
Solve the programming task below in a Python markdown code block. A number is called almost prime if it has exactly two distinct prime divisors. For example, numbers 6, 18, 24 are almost prime, while 4, 8, 9, 42 are not. Find the amount of almost prime numbers which are between 1 and n, inclusive. Input Input contain...
{"inputs": ["1\n", "3\n", "4\n", "8\n", "2\n", "6\n", "5\n", "9\n"], "outputs": ["0\n", "0\n", "0\n", "1\n", "0\n", "1\n", "0\n", "1\n"]}
135
70
coding
Solve the programming task below in a Python markdown code block. This program tests the life of an evaporator containing a gas. We know the content of the evaporator (content in ml), the percentage of foam or gas lost every day (evap_per_day) and the threshold (threshold) in percentage beyond which the evaporator is...
{"functional": "_inputs = [[10, 10, 10], [10, 10, 5], [100, 5, 5], [50, 12, 1], [47.5, 8, 8], [100, 1, 1], [10, 1, 1], [100, 1, 5]]\n_outputs = [[22], [29], [59], [37], [31], [459], [459], [299]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclo...
203
273
coding
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin Chinese and Russian as well. Let's consider a set of points S. Initially, S is an empty set. Your task is to implement a data structure that can process the following queries efficiently: "+ X Y" - add a new po...
{"inputs": ["10\n+ 8 1\n- 1\n+ 3 9\n? 8 4\n? 8 8\n? 12 0\n+ 6 5\n? 7 8\n? 4 5\n- 9"], "outputs": ["10\n8\n2\n4\n11"]}
676
80
coding
Solve the programming task below in a Python markdown code block. Let's consider one interesting word game. In this game you should transform one word into another through special operations. Let's say we have word w, let's split this word into two non-empty parts x and y so, that w = xy. A split operation is transfo...
{"inputs": ["ab\nba\n0\n", "hi\nhi\n1\n", "ab\nba\n9\n", "aa\naa\n1\n", "ab\nab\n0\n", "ba\naa\n1\n", "ab\nb`\n2\n", "bb\nab\n2\n"], "outputs": ["0\n", "0\n", "1\n", "1\n", "1\n", "0\n", "0\n", "0\n"]}
453
103
coding
Solve the programming task below in a Python markdown code block. You are given a binary string S of length N. Your task is to check if there exists a [substring] of S which is the binary representation of a [prime number]. Formally, check if there exist integers L and R such that 1 ≤ L ≤ R ≤ N, and the substring S_{L...
{"inputs": ["3\n1\n111\n101101"], "outputs": ["No\nYes\nYes"]}
521
29
coding
Solve the programming task below in a Python markdown code block. There are 101 citizens in Chefland. It is election time in Chefland and 3 parties, A, B, and C are contesting the elections. Party A receives X_{A} votes, party B receives X_{B} votes, and party C receives X_{C} votes. The constitution of Chefland requi...
{"inputs": ["3\n80 19 2\n20 55 26\n50 1 50\n"], "outputs": ["A\nB\nNOTA\n"]}
461
44
coding
Solve the programming task below in a Python markdown code block. Mr. Wire Less is not that good at implementing circuit in a breadboard. In his Digital Logic Design course, he has to implement several boolean functions using the breadboard. In a breadboard, inputs are given through the switches and outputs are taken t...
{"inputs": ["2\n1\n2\n\n"], "outputs": ["Case 1: 1\nCase 2: 3"]}
537
30
coding
Solve the programming task below in a Python markdown code block. Your algorithm is so good at predicting the market that you now know what the share price of Mahindra & Mahindra. (M&M) will be for the next N days. Each day, you can either buy one share of M&M, sell any number of shares of M&M that you own, or not mak...
{"inputs": ["3\n3\n5 3 2\n3\n1 2 100\n4\n1 3 1 2"], "outputs": ["0\n197\n3"]}
341
46
coding
Solve the programming task below in a Python markdown code block. Ichiro likes baseball and has decided to write a program which simulates baseball. The program reads events in an inning and prints score in that inning. There are only three events as follows: Single hit * put a runner on the first base. * the runner...
{"inputs": ["2\nHIT\nOUT\nHOMERUN\nHIT\nHIT\nHOMERUN\nHIT\nOUT\nHIT\nHIT\nHIT\nHIT\nOUT\nHIT\nHIT\nOUT\nHIT\nOUT\nOUT"], "outputs": ["7\n0"]}
357
69
coding
Solve the programming task below in a Python markdown code block. Problem N idols, numbered from 1 to n in order, are lined up in a row. Idle i can transmit information to idle i-1 and idle i + 1 in a unit time. However, idol 1 can transmit information only to idol 2, and idol n can transmit information only to idol n...
{"inputs": ["6 2\n1 3", "3 2\n1 3", "8 1\n2 2 7", "8 3\n2 2 7", "2 1\n2 2 8", "2 1\n2 2 3", "2 2\n2 2 3", "0 1\n1 3 3"], "outputs": ["3\n", "1", "6\n", "2\n", "1\n", "1\n", "1\n", "0\n"]}
313
121
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a 2D integer array circles where circles[i] = [xi, yi, ri] represents the center (xi, yi) and radius ri of the ith circle drawn on a grid, return the number of lattice points that are present inside at least one...
{"functional": "def check(candidate):\n assert candidate(circles = [[2,2,1]]) == 5\n assert candidate(circles = [[2,2,2],[3,4,1]]) == 16\n\n\ncheck(Solution().countLatticePoints)"}
135
62
coding
Solve the programming task below in a Python markdown code block. Now After eliminating the invalid registrations they are planning to form connections to the participants laptops. The connection can be direct or indirect form and there should be only one connection exists between them. After setting the connections ma...
{"inputs": ["10\n5\n1 2\n2 4 \n4 6\n6 5\n5 9\n5\n5 9\n1 8\n1 9\n2 5\n1 4"], "outputs": ["Direct Connection\nNo Connection\nIndirect Connection\nIndirect Connection\nIndirect Connection"]}
256
74
coding
Solve the programming task below in a Python markdown code block. Generalized leap year Normally, whether or not the year x is a leap year is defined as follows. 1. If x is a multiple of 400, it is a leap year. 2. Otherwise, if x is a multiple of 100, it is not a leap year. 3. Otherwise, if x is a multiple of 4, it i...
{"inputs": ["3 3 2014\n400\n101\n4\n1 1000 2949\n1\n2 1110 3333\n2\n4\n6 6 3370\n2\n5\n2\n9\n5\n13\n0 0 0", "3 3 2014\n400\n101\n4\n1 1000 2949\n1\n2 1110 3333\n2\n4\n6 6 3370\n2\n5\n21\n9\n3\n13\n0 0 0", "3 3 2014\n400\n101\n4\n1 1000 2949\n1\n2 1110 3333\n2\n4\n6 6 3370\n2\n5\n21\n9\n5\n13\n0 0 0", "3 3 2014\n400\n10...
618
810
coding
Solve the programming task below in a Python markdown code block. A new strain of flu has broken out. Fortunately, a vaccine was developed very quickly and is now being administered to the public. Your local health clinic is administering this vaccine, but the waiting line is very long. For safety reasons, people are ...
{"inputs": ["3\n2 4\n1\n2\n2 2\n1\n2\n4 1\n0\n0.5\n0.6\n2.75"], "outputs": ["2.0000\n0.5000\n1.4000"]}
769
66
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. A city is represented as a bi-directional connected graph with n vertices where each vertex is labeled from 1 to n (inclusive). The edges in the graph are represented as a 2D integer array edges, where each edges[i] =...
{"functional": "def check(candidate):\n assert candidate(n = 5, edges = [[1,2],[1,3],[1,4],[3,4],[4,5]], time = 3, change = 5) == 13\n assert candidate(n = 2, edges = [[1,2]], time = 3, change = 2) == 11\n\n\ncheck(Solution().secondMinimum)"}
341
95
coding
Solve the programming task below in a Python markdown code block. *“You won’t get caught if you hide behind someone.”* Sang-Woo advises Gi-Hun to hide behind someone to avoid getting shot. Gi-Hun follows Sang-Woo's advice and hides behind Ali, who saved his life earlier. Gi-Hun and Ali both have the same height, K. M...
{"inputs": ["3\n4 10\n2 13 4 16\n5 8\n9 3 8 8 4\n4 6\n1 2 3 4"], "outputs": ["2\n1\n0"]}
679
57
coding
Solve the programming task below in a Python markdown code block. A thief sneaked into a museum with a lot of treasures with only one large furoshiki. There are many things I want to steal, but the weight that the furoshiki can withstand is limited, and if it exceeds this, the furoshiki will tear. Therefore, the thief ...
{"inputs": ["50\n5\n60,10\n100,20\n120,30\n310,45\n10,4\n50\n5\n60,10\n100,20\n120,30\n210,45\n10,4\n0", "50\n5\n60,10\n100,20\n110,30\n310,45\n10,4\n50\n5\n60,10\n100,20\n120,30\n210,45\n00,4\n0", "50\n5\n60,10\n100,20\n100,32\n210,45\n10,4\n50\n5\n60,10\n100,20\n120,30\n210,45\n10,4\n0", "50\n5\n60,10\n100,20\n120,30...
479
830
coding
Solve the programming task below in a Python markdown code block. Snuke has decided to play a game using cards. He has a deck consisting of N cards. On the i-th card from the top, an integer A_i is written. He will perform the operation described below zero or more times, so that the values written on the remaining car...
{"inputs": ["5\n1 2 0 3 7", "5\n1 2 1 3 7", "5\n1 2 1 3 7\n", "5\n1 2 0 3 11", "5\n1 2 0 3 18", "5\n1 2 0 5 18", "5\n1 2 0 9 18", "5\n4 -2 0 3 1"], "outputs": ["5\n", "3", "3\n", "5\n", "5\n", "5\n", "5\n", "5\n"]}
326
146
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an array of integers nums and an integer k. A continuous subarray is called nice if there are k odd numbers on it. Return the number of nice sub-arrays.   Please complete the following python code precisely: ```...
{"functional": "def check(candidate):\n assert candidate(nums = [1,1,2,1,1], k = 3) == 2\n assert candidate(nums = [2,4,6], k = 1) == 0\n assert candidate(nums = [2,2,2,1,2,2,1,2,2,2], k = 2) == 16\n\n\ncheck(Solution().numberOfSubarrays)"}
89
102
coding
Solve the programming task below in a Python markdown code block. Write a program to obtain length (L) and breadth (B) of a rectangle and check whether its area is greater or perimeter is greater or both are equal. ------ Input Format ------ - First line will contain the length (L) of the rectangle. - Second line wi...
{"inputs": ["1\n2\n"], "outputs": ["Peri\n6\n"]}
243
19
coding
Solve the programming task below in a Python markdown code block. Wabbit is playing a game with $n$ bosses numbered from $1$ to $n$. The bosses can be fought in any order. Each boss needs to be defeated exactly once. There is a parameter called boss bonus which is initially $0$. When the $i$-th boss is defeated, the c...
{"inputs": ["3 0\n1 1 1\n", "1 0\n1000000\n", "1 500000\n-1\n", "5 1\n-1 -2 -3 -4 5\n", "5 5\n-1 -2 -3 -4 -5\n", "13 2\n3 1 4 1 5 -9 -2 -6 -5 -3 -5 -8 -9\n", "10 3\n950 882 856 786 677 480 302 258 147 98\n", "70 2\n1 1 1 1 1 -1 -1 -1 -1 -1 -3 -3 -3 -3 -3 -3 -3 -3 -3 -3 -3 -3 -3 -3 -3 -3 -3 -3 -3 -3 -3 -3 -3 -3 -3 -3 -3...
735
347
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. Ridbit is given an array $a_{1}, a_{2}, \ldots, a_{N}$. He needs to find the number of ways to divide the array into contiguous subarrays such that:...
{"inputs": ["2\n6\n1 0 0 1 0 1\n3\n1 2 3"], "outputs": ["5\n4"]}
482
36
coding
Solve the programming task below in a Python markdown code block. You have a total of 3N balls of colours Red, Blue and Green. There are exactly N balls of each colour. These 3N balls are now distributed to 3 boxes such that each box contains exactly N balls. You are given the contents of each box. You would like the...
{"inputs": ["2\n3\n3 0 0\n0 3 0\n0 0 3\n5\n2 1 2\n1 4 0\n2 0 3"], "outputs": ["0\n3"]}
750
54
coding
Solve the programming task below in a Python markdown code block. collections.namedtuple() Basically, namedtuples are easy to create, lightweight object types. They turn tuples into convenient containers for simple tasks. With namedtuples, you don’t have to use integer indices for accessing members of a tuple. Ex...
{"inputs": ["5\nMARKS CLASS NAME ID \n92 2 Calum 1 \n82 5 Scott 2 \n94 2 Jason 3 \n55 8 Glenn 4 \n82 2 Fergus 5\n", "5\nID MARKS NAME CLA...
693
182
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given the root of a binary tree, determine if it is a complete binary tree. In a complete binary tree, every level, except possibly the last, is completely filled, and all nodes in the last level are as far left as po...
{"functional": "def check(candidate):\n assert candidate(root = tree_node([1,2,3,4,5,6])) == True\n assert candidate(root = tree_node([1,2,3,4,5,None,7])) == False\n\n\ncheck(Solution().isCompleteTree)"}
168
67
coding
Solve the programming task below in a Python markdown code block. The Little Elephant has got a problem — somebody has been touching his sorted by non-decreasing array a of length n and possibly swapped some elements of the array. The Little Elephant doesn't want to call the police until he understands if he could hav...
{"inputs": ["2\n1 1\n", "2\n2 1\n", "2\n1 0\n", "2\n2 0\n", "2\n2 2\n", "2\n0 0\n", "2\n1 2\n", "3\n1 3 2\n"], "outputs": ["YES\n", "YES\n", "YES\n", "YES\n", "YES\n", "YES\n", "YES\n", "YES\n"]}
388
104
coding
Solve the programming task below in a Python markdown code block. There is a cricket match going on between two teams A and B. Team B is batting second and got a target of X runs. Currently, team B has scored Y runs. Determine how many more runs Team B should score to win the match. Note: The target score in cricket ...
{"inputs": ["4\n200 50\n100 99\n130 97\n53 51\n"], "outputs": ["150\n1\n33\n2\n"]}
469
50
coding
Solve the programming task below in a Python markdown code block. You've got an n × m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. Yo...
{"inputs": ["1 1\n14\n", "1 1\n14\n", "1 1\n32\n", "1 1\n19\n", "1 1\n36\n", "1 1\n99992\n", "1 1\n20000\n", "1 1\n99992\n"], "outputs": ["3\n", "3\n", "5\n", "0\n", "1\n", "11\n", "11\n", "11\n"]}
495
122
coding
Solve the programming task below in a Python markdown code block. # Palindrome strings A palindrome is a word, phrase, number, or other sequence of characters which reads the same backward or forward. This includes capital letters, punctuation, and word dividers. Implement a function that checks if something is a pal...
{"functional": "_inputs = [['anna'], ['walter'], [12321], [123456]]\n_outputs = [[True], [False], [True], [False]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n ...
138
183
coding
Solve the programming task below in a Python markdown code block. We have A balls with the string S written on each of them and B balls with the string T written on each of them. From these balls, Takahashi chooses one with the string U written on it and throws it away. Find the number of balls with the string S and ...
{"inputs": ["a b\n1 3\na\n", "abc arc\n3 6\nabc\n", "red blue\n3 2\nred", "red blte\n3 0\nred", "red blue\n5 0\nred", "red blue\n7 0\nred", "red blue\n5 1\nred", "red blue\n0 0\nred"], "outputs": ["0 3\n", "2 6\n", "2 2\n", "2 0\n", "4 0\n", "6 0\n", "4 1\n", "-1 0\n"]}
243
137
coding
Solve the programming task below in a Python markdown code block. There is a connected undirected graph with N vertices and M edges. The vertices are numbered 1 to N, and the edges are numbered 1 to M. Also, each of these vertices and edges has a specified weight. Vertex i has a weight of X_i; Edge i has a weight of Y_...
{"inputs": ["4 4\n2 3 5 7\n1 2 7\n1 3 9\n1 3 6\n3 4 18", "4 4\n2 3 5 7\n1 2 7\n1 3 9\n2 3 21\n3 4 18", "4 4\n2 3 1 7\n1 2 7\n1 3 9\n2 3 12\n3 4 18", "4 4\n2 3 5 7\n1 4 7\n1 2 9\n1 3 15\n3 4 18", "4 4\n2 3 5 7\n1 2 7\n1 3 9\n1 3 21\n3 4 18", "4 4\n2 3 1 7\n1 2 7\n2 3 9\n2 3 12\n3 4 18", "4 4\n2 3 5 7\n1 4 7\n1 3 9\n1 3 ...
588
349