problem
stringlengths
14
4.09k
solution
stringlengths
1
802k
task_type
stringclasses
3 values
problem_tokens
int64
5
895
Solve the programming task below in a Python markdown code block. .intersection() The .intersection() operator returns the intersection of a set and the set of elements in an iterable. Sometimes, the & operator is used in place of the .intersection() operator, but it only operates on the set of elements in set. Th...
{"inputs": ["9\n1 2 3 4 5 6 7 8 9\n9\n10 1 2 3 11 21 55 6 8\n"], "outputs": ["5\n"]}
coding
489
Solve the programming task below in a Python markdown code block. You will be given two ASCII strings, `a` and `b`. Your task is write a function to determine which one of these strings is "worth" more, and return it. A string's worth is determined by the sum of its ASCII codepoint indexes. So, for example, the string...
{"functional": "_inputs = [['AaBbCcXxYyZz0189', 'KkLlMmNnOoPp4567'], ['ABcd', '0123'], ['!\"?$%^&*()', \"{}[]@~'#:;\"], ['ABCD', 'DCBA']]\n_outputs = [['KkLlMmNnOoPp4567'], ['ABcd'], [\"{}[]@~'#:;\"], ['ABCD']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n re...
coding
166
Solve the programming task below in a Python markdown code block. Your task is to sort a given string. Each word in the string will contain a single number. This number is the position the word should have in the result. Note: Numbers can be from 1 to 9. So 1 will be the first word (not 0). If the input string is emp...
{"functional": "_inputs = [['is2 Thi1s T4est 3a'], ['4of Fo1r pe6ople g3ood th5e the2'], ['d4o dru7nken sh2all w5ith s8ailor wha1t 3we a6'], [''], ['3 6 4 2 8 7 5 1 9']]\n_outputs = [['Thi1s is2 3a T4est'], ['Fo1r the2 g3ood 4of th5e pe6ople'], ['wha1t sh2all 3we d4o w5ith a6 dru7nken s8ailor'], [''], ['1 2 3 4 5 6 7 8...
coding
197
Solve the programming task below in a Python markdown code block. We have N points in a two-dimensional plane. The coordinates of the i-th point (1 \leq i \leq N) are (x_i,y_i). Let us consider a rectangle whose sides are parallel to the coordinate axes that contains K or more of the N points in its interior. Here, ...
{"inputs": ["4 4\n1 4\n2 3\n6 2\n8 1", "4 4\n1 4\n2 3\n6 2\n8 0", "4 4\n0 4\n2 3\n6 2\n8 1", "4 4\n2 4\n3 3\n6 2\n8 1", "4 4\n1 4\n2 6\n6 2\n8 1", "4 2\n0 0\n1 1\n2 2\n3 3", "4 4\n1 4\n3 3\n6 2\n8 1", "4 4\n1 4\n3 3\n6 2\n8 1\n"], "outputs": ["21\n", "28\n", "24\n", "18\n", "35\n", "1", "21", "21\n"]}
coding
353
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a string word, return the sum of the number of vowels ('a', 'e', 'i', 'o', and 'u') in every substring of word. A substring is a contiguous (non-empty) sequence of characters within a string. Note: Due to the la...
{"functional": "def check(candidate):\n assert candidate(word = \"aba\") == 6\n assert candidate(word = \"abc\") == 3\n assert candidate(word = \"ltcd\") == 0\n assert candidate(word = \"noosabasboosa\") == 237\n\n\ncheck(Solution().countVowels)"}
coding
129
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are keeping the scores for a baseball game with strange rules. At the beginning of the game, you start with an empty record. You are given a list of strings operations, where operations[i] is the ith operation you...
{"functional": "def check(candidate):\n assert candidate(ops = [\"5\",\"2\",\"C\",\"D\",\"+\"]) == 30\n assert candidate(ops = [\"5\",\"-2\",\"4\",\"C\",\"D\",\"9\",\"+\",\"+\"]) == 27\n assert candidate(ops = [\"1\"]) == 1\n\n\ncheck(Solution().calPoints)"}
coding
210
Solve the programming task below in a Python markdown code block. Polycarp was presented with some sequence of integers $a$ of length $n$ ($1 \le a_i \le n$). A sequence can make Polycarp happy only if it consists of different numbers (i.e. distinct numbers). In order to make his sequence like this, Polycarp is going ...
{"inputs": ["1\n6\n1 1 4 5 1 4\n", "1\n7\n1 6 5 4 3 2 1\n", "5\n4\n3 1 4 3\n5\n1 1 1 1 1\n1\n1\n6\n6 5 4 3 2 1\n7\n1 2 1 7 1 2 1\n"], "outputs": ["3\n", "1\n", "1\n4\n0\n0\n5\n"]}
coding
565
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a year year and a month month, return the number of days of that month.   Please complete the following python code precisely: ```python class Solution: def numberOfDays(self, year: int, month: int) -> int: ...
{"functional": "def check(candidate):\n assert candidate(year = 1992, month = 7) == 31\n assert candidate(year = 2000, month = 2) == 29\n assert candidate(year = 1900, month = 2) == 28\n\n\ncheck(Solution().numberOfDays)"}
coding
69
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given the head of a linked list and a value x, partition it such that all nodes less than x come before nodes greater than or equal to x. You should preserve the original relative order of the nodes in each of the two...
{"functional": "def check(candidate):\n assert is_same_list(candidate(head = list_node([1,4,3,2,5,2]), x = 3), list_node([1,2,2,4,3,5]))\n assert is_same_list(candidate(head = list_node([2,1]), x = 2), list_node([1,2]))\n\n\ncheck(Solution().partition)"}
coding
142
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a triangle array, return the minimum path sum from top to bottom. For each step, you may move to an adjacent number of the row below. More formally, if you are on index i on the current row, you may move to eith...
{"functional": "def check(candidate):\n assert candidate(triangle = [[2],[3,4],[6,5,7],[4,1,8,3]]) == 11\n assert candidate(triangle = [[-10]]) == -10\n\n\ncheck(Solution().minimumTotal)"}
coding
112
Solve the programming task below in a Python markdown code block. Chef just got a box of chocolates as his birthday gift. The box contains $N$ chocolates in a row (numbered $1$ through $N$), where $N$ is even. For each valid $i$, the $i$-th chocolate has a sweetness value $W_i$. Chef wants to eat all the chocolates in ...
{"inputs": ["2\n6\n1 1 2 1 1 1\n6\n1 1 2 1 1 2"], "outputs": ["3\n0"]}
coding
588
Solve the programming task below in a Python markdown code block. During a daily walk Alina noticed a long number written on the ground. Now Alina wants to find some positive number of same length without leading zeroes, such that the sum of these two numbers is a palindrome. Recall that a number is called a palindrom...
{"inputs": ["1\n3\n100\n", "1\n3\n109\n", "3\n2\n99\n4\n1023\n3\n385\n"], "outputs": ["899\n", "890\n", "12\n8976\n614\n"]}
coding
490
Solve the programming task below in a Python markdown code block. Gematria is an Assyro-Babylonian-Greek system of code and numerology later adopted into Jewish culture. The system assigns numerical value to a word or a phrase in the belief that words or phrases with identical numerical values bear some relation to eac...
{"functional": "_inputs = [['love'], ['jaels'], ['JAELS'], ['Devil'], ['Coding is fun']]\n_outputs = [[775], [716], [716], [738], [458]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (l...
coding
334
Solve the programming task below in a Python markdown code block. Makes solves problems on Decoforces and lots of other different online judges. Each problem is denoted by its difficulty — a positive integer number. Difficulties are measured the same across all the judges (the problem with difficulty d on Decoforces is...
{"inputs": ["1 1\n3\n", "1 1\n2\n", "1 1\n4\n", "1 4\n9\n", "1 2\n9\n", "1 2\n9\n", "1 1\n4\n", "1 1\n3\n"], "outputs": ["1\n", "0\n", "1\n", "1\n", "2\n", "2", "1", "1"]}
coding
539
Solve the programming task below in a Python markdown code block. You are given a function $f$ written in some basic language. The function accepts an integer value, which is immediately written into some variable $x$. $x$ is an integer variable and can be assigned values from $0$ to $2^{32}-1$. The function contains t...
{"inputs": ["1\nadd\n", "1\nadd\n", "2\nfor 4\nend\n", "2\nfor 62\nend\n", "2\nfor 15\nend\n", "2\nfor 14\nend\n", "2\nfor 16\nend\n", "2\nfor 24\nend\n"], "outputs": ["1\n", "1\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]}
coding
640
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. You can apply the following operation any number of times: Pick any element from nums and put it at the end of nums. The prefix sum array of nums is an array prefix of t...
{"functional": "def check(candidate):\n assert candidate(nums = [2,3,-5,4]) == 0\n assert candidate(nums = [3,-5,-2,6]) == 1\n\n\ncheck(Solution().makePrefSumNonNegative)"}
coding
169
Solve the programming task below in a Python markdown code block. Write a program that takes in a letterclass ID of a ship and display the equivalent string class description of the given ID. Use the table below. Class ID Ship ClassB or bBattleShipC or cCruiserD or dDestroyerF or fFrigate -----Input----- The first l...
{"inputs": ["3\nB\nc\nD", "3 \nC\nc\nD", "3 \nB\nc\nC", "3 \nB\nc\nB", "3 \nC\nc\nB", "3 \nC\nb\nB", "3 \nB\nd\nD", "3 \nC\nd\nD"], "outputs": ["BattleShip\nCruiser\nDestroyer", "Cruiser\nCruiser\nDestroyer\n", "BattleShip\nCruiser\nCruiser\n", "BattleShip\nCruiser\nBattleShip\n", "Cruiser\nCruiser\nBattleShip\n", "Cru...
coding
160
Solve the programming task below in a Python markdown code block. There are N islands and M bridges. The i-th bridge connects the A_i-th and B_i-th islands bidirectionally. Initially, we can travel between any two islands using some of these bridges. However, the results of a survey show that these bridges will all col...
{"inputs": ["2 1\n2 2", "2 1\n1 2", "2 1\n1 2\n", "6 5\n3 3\n1 2\n5 6\n3 4\n4 5", "4 5\n1 2\n3 4\n1 3\n3 3\n1 4", "6 5\n3 3\n1 2\n5 6\n3 4\n2 5", "4 5\n1 2\n3 4\n1 3\n3 3\n1 1", "6 5\n2 3\n1 2\n5 6\n3 4\n4 3"], "outputs": ["1\n", "1", "1\n", "8\n9\n12\n14\n15\n", "3\n3\n5\n5\n6\n", "8\n11\n13\n14\n15\n", "3\n5\n6\n6\n6...
coding
411
Solve the programming task below in a Python markdown code block. You are given a string $s$. Each character is either 0 or 1. You want all 1's in the string to form a contiguous subsegment. For example, if the string is 0, 1, 00111 or 01111100, then all 1's form a contiguous subsegment, and if the string is 0101, 100...
{"inputs": ["2\n01010\n0\n", "2\n01010\n0\n", "2\n01110\n0\n", "2\n01011\n1\n", "2\n10011\n1\n", "2\n01110\n1\n", "2\n01111\n1\n", "2\n11011\n1\n"], "outputs": ["1\n0\n", "1\n0\n", "0\n0\n", "1\n0\n", "2\n0\n", "0\n0\n", "0\n0\n", "1\n0\n"]}
coding
356
Solve the programming task below in a Python markdown code block. Chef gives an array A with N elements to Babla. Babla's task is to find the maximum non-negative integer X such that: No element in the array belongs to the range [-X, X]. In other words, for all (1≤ i ≤ N), either A_{i} < -X or A_{i} > X. Help Babla t...
{"inputs": ["3\n5\n8 4 2 5 2\n6\n7 9 -10 8 12 17\n4\n0 -3 -1 -10\n"], "outputs": ["1\n6\n-1\n"]}
coding
509
Solve the programming task below in a Python markdown code block. Little Johnny Bubbles enjoys spending hours in front of his computer playing video games. His favorite game is Bubble Strike, fast-paced bubble shooting online game for two players. Each game is set in one of the N maps, each having different terrain co...
{"inputs": ["7 1.0000\n", "3 0.0000\n", "3 1.0000\n", "3 1.0000\n", "3 0.0000\n", "3 0.5879\n", "4 0.0000\n", "8 0.0000\n"], "outputs": ["6\n", "0\n", "2\n", "2\n", "0\n", "2\n", "0\n", "0\n"]}
coding
373
Solve the programming task below in a Python markdown code block. Read problem statements in [Mandarin], [Bengali], [Russian], and [Vietnamese] as well. You are given an undirected graph with N nodes (numbered 1 through N). For each valid i, the i-th node has a weight W_{i}. Also, for each pair of nodes i and j, there...
{"inputs": ["2\n2\n1 2\n2\n2 1\n"], "outputs": ["2\n1"]}
coding
484
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given the root of a binary tree with unique values and the values of two different nodes of the tree x and y, return true if the nodes corresponding to the values x and y in the tree are cousins, or false otherwise. T...
{"functional": "def check(candidate):\n assert candidate(root = tree_node([1,2,3,4]), x = 4, y = 3) == False\n assert candidate(root = tree_node([1,2,3,None,4,None,5]), x = 5, y = 4) == True\n assert candidate(root = tree_node([1,2,3,None,4]), x = 2, y = 3) == False\n\n\ncheck(Solution().isCousins)"}
coding
207
Solve the programming task below in a Python markdown code block. Phoenix has $n$ coins with weights $2^1, 2^2, \dots, 2^n$. He knows that $n$ is even. He wants to split the coins into two piles such that each pile has exactly $\frac{n}{2}$ coins and the difference of weights between the two piles is minimized. Formal...
{"inputs": ["1\n2\n", "1\n2\n", "1\n4\n", "1\n6\n", "2\n2\n4\n", "2\n4\n4\n", "2\n4\n6\n", "2\n6\n4\n"], "outputs": ["2\n", "2\n", "6\n", "14\n", "2\n6\n", "6\n6\n", "6\n14\n", "14\n6\n"]}
coding
374
Solve the programming task below in a Python markdown code block. Kulyash is given an integer N. His task is to break N into some number of (integer) powers of 2. TO achieve this, he can perform the following operation several times (possibly, zero): Choose an integer X which he already has, and break X into 2 intege...
{"inputs": ["2\n3\n4\n"], "outputs": ["1\n0\n"]}
coding
318
Solve the programming task below in a Python markdown code block. If you have not ever heard the term **Arithmetic Progrossion**, refer to: http://www.codewars.com/kata/find-the-missing-term-in-an-arithmetic-progression/python And here is an unordered version. Try if you can survive lists of **MASSIVE** numbers (whic...
{"functional": "_inputs = [[[3, 9, 1, 11, 13, 5]], [[5, -1, 0, 3, 4, -3, 2, -2]], [[2, -2, 8, -8, 4, -4, 6, -6]]]\n_outputs = [[7], [1], [0]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(...
coding
193
Solve the programming task below in a Python markdown code block. Little kids, Jack and Evan like playing their favorite game Glass-and-Stone. Today they want to play something new and came across Twitter on their father's laptop. They saw it for the first time but were already getting bored to see a bunch of sentence...
{"inputs": ["3 6\nCLICK 1\nCLICK 2\nCLICK 3\nCLICK 2\nCLOSEALL\nCLICK 1"], "outputs": ["1\n2\n3\n2\n0\n1"]}
coding
509
Solve the programming task below in a Python markdown code block. A disease is spreading through ChefLand! The disease spreads as follows: At the end of day 0, a single person is infected with the disease. During the next 10 days, the number of infected people doubles each day, until the disease has spread to all peop...
{"inputs": ["4\n100 3\n2000 10\n6000 11\n10 11"], "outputs": ["8\n1024\n3072\n10"]}
coding
631
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an integer n representing an array colors of length n where all elements are set to 0's meaning uncolored. You are also given a 2D integer array queries where queries[i] = [indexi, colori]. For the ith q...
{"functional": "def check(candidate):\n assert candidate(n = 4, queries = [[0,2],[1,2],[3,1],[1,1],[2,1]]) == [0,1,1,0,2]\n assert candidate(n = 1, queries = [[0,100000]]) == [0]\n\n\ncheck(Solution().colorTheArray)"}
coding
158
Solve the programming task below in a Python markdown code block. You are going out for a walk, when you suddenly encounter a monster. Fortunately, you have N katana (swords), Katana 1, Katana 2, …, Katana N, and can perform the following two kinds of attacks in any order: - Wield one of the katana you have. When you ...
{"inputs": ["1 10\n4 5", "1 10\n3 5", "1 10\n3 5\n", "2 10\n2 5\n2 6", "2 19\n2 5\n2 6", "2 19\n4 5\n2 6", "2 19\n4 5\n2 4", "2 2\n1 5\n2 10"], "outputs": ["3\n", "3", "3\n", "2\n", "6\n", "4\n", "5\n", "1\n"]}
coding
383
Please solve the programming task below using a self-contained code snippet in a markdown code block. The school cafeteria offers circular and square sandwiches at lunch break, referred to by numbers 0 and 1 respectively. All students stand in a queue. Each student either prefers square or circular sandwiches. The num...
{"functional": "def check(candidate):\n assert candidate(students = [1,1,0,0], sandwiches = [0,1,0,1]) == 0 \n assert candidate(students = [1,1,1,0,0,1], sandwiches = [1,0,0,0,1,1]) == 3\n\n\ncheck(Solution().countStudents)"}
coding
263
Solve the programming task below in a Python markdown code block. You are given an integer N. Among the divisors of N! (= 1 \times 2 \times ... \times N), how many Shichi-Go numbers (literally "Seven-Five numbers") are there? Here, a Shichi-Go number is a positive integer that has exactly 75 divisors. -----Note----- W...
{"inputs": ["4", "3", "2", "6", "1", "8", "0", "5"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]}
coding
237
Please solve the programming task below using a self-contained code snippet in a markdown code block. You have a bomb to defuse, and your time is running out! Your informer will provide you with a circular array code of length of n and a key k. To decrypt the code, you must replace every number. All the numbers are re...
{"functional": "def check(candidate):\n assert candidate(code = [5,7,1,4], k = 3) == [12,10,16,13]\n assert candidate(code = [1,2,3,4], k = 0) == [0,0,0,0]\n assert candidate(code = [2,4,9,3], k = -2) == [12,5,6,13]\n\n\ncheck(Solution().decrypt)"}
coding
214
Please solve the programming task below using a self-contained code snippet in a markdown code block. There are several squares being dropped onto the X-axis of a 2D plane. You are given a 2D integer array positions where positions[i] = [lefti, sideLengthi] represents the ith square with a side length of sideLengthi t...
{"functional": "def check(candidate):\n assert candidate(positions = [[1,2],[2,3],[6,1]]) == [2,5,5]\n assert candidate(positions = [[100,100],[200,100]]) == [100,100]\n\n\ncheck(Solution().fallingSquares)"}
coding
229
Solve the programming task below in a Python markdown code block. Tim buy a string of length N from his friend which consist of ‘d’ and ‘u’ letters only ,but now Tim wants to sell the string at maximum cost. The maximum cost of string is defined as the maximum length of a Substring (consecutive subsequence) consist...
{"inputs": ["4 2\nduud", "10 1\ndduddudddu"], "outputs": ["4", "6"]}
coding
289
Solve the programming task below in a Python markdown code block. Read problems statements in [Mandarin Chinese], [Russian], and [Bengali] as well. Recently, Chef's College Examination has concluded. He was enrolled in $3$ courses and he scored $A, B, C$ in them, respectively. To pass the semester, he must score at le...
{"inputs": ["5\n1 1 1 300 2 2 2\n3 2 2 6 2 2 2\n2 3 2 6 2 2 2\n2 2 3 6 2 2 2\n100 100 100 300 100 100 100"], "outputs": ["NO\nNO\nNO\nNO\nYES"]}
coding
644
Solve the programming task below in a Python markdown code block. This is the hard version of Problem F. The only difference between the easy version and the hard version is the constraints. We will call a non-empty string balanced if it contains the same number of plus and minus signs. For example: strings "+--+" and...
{"inputs": ["5\n3\n+-+\n5\n-+---\n4\n----\n7\n--+---+\n6\n+++---\n"], "outputs": ["2\n4\n2\n7\n4\n"]}
coding
640
Solve the programming task below in a Python markdown code block. Timothy (age: 16) really likes to smoke. Unfortunately, he is too young to buy his own cigarettes and that's why he has to be extremely efficient in smoking. It's now your task to create a function that calculates how many cigarettes Timothy can smoke o...
{"functional": "_inputs = [[0, 1], [1, 0], [1, 1]]\n_outputs = [[22], [224], [247]]\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 Fa...
coding
196
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a 0-indexed array nums of size n consisting of non-negative integers. You need to apply n - 1 operations to this array where, in the ith operation (0-indexed), you will apply the following on the ith ele...
{"functional": "def check(candidate):\n assert candidate(nums = [1,2,2,1,1,0]) == [1,4,2,0,0,0]\n assert candidate(nums = [0,1]) == [1,0]\n\n\ncheck(Solution().applyOperations)"}
coding
221
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given the head of a singly linked list, reverse the list, and return the reversed list.   Please complete the following python code precisely: ```python # Definition for singly-linked list. # class ListNode: # def...
{"functional": "def check(candidate):\n assert is_same_list(candidate(head = list_node([1,2,3,4,5])), list_node([5,4,3,2,1]))\n assert is_same_list(candidate(head = list_node([1,2])), list_node([2,1]))\n assert is_same_list(candidate(head = list_node([])), list_node([]))\n\n\ncheck(Solution().reverseList)"}
coding
110
Solve the programming task below in a Python markdown code block. One day little Vasya found mom's pocket book. The book had n names of her friends and unusually enough, each name was exactly m letters long. Let's number the names from 1 to n in the order in which they are written. As mom wasn't home, Vasya decided to...
{"inputs": ["1 1\nE\n", "1 1\nD\n", "1 1\nF\n", "2 2\nAA\nBB\n", "2 2\nNS\nPD\n", "2 2\nNS\nDP\n", "2 2\nSN\nDP\n", "2 2\nSN\nCP\n"], "outputs": ["1\n", "1\n", "1\n", "4\n", "4\n", "4\n", "4\n", "4\n"]}
coding
453
Solve the programming task below in a Python markdown code block. Consider a table G of size n × m such that G(i, j) = GCD(i, j) for all 1 ≤ i ≤ n, 1 ≤ j ≤ m. GCD(a, b) is the greatest common divisor of numbers a and b. You have a sequence of positive integer numbers a_1, a_2, ..., a_{k}. We say that this sequence occ...
{"inputs": ["11 4 1\n11\n", "11 10 1\n11\n", "11 10 1\n11\n", "5 5 5\n1 1 1 1 1\n", "5 5 5\n1 1 1 1 1\n", "5 5 5\n1 1 2 1 1\n", "5 2 5\n1 1 2 1 1\n", "5 2 5\n2 1 2 1 1\n"], "outputs": ["NO\n", "NO\n", "NO\n", "YES\n", "YES\n", "NO\n", "NO\n", "NO\n"]}
coding
446
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a 0-indexed string s of even length n. The string consists of exactly n / 2 opening brackets '[' and n / 2 closing brackets ']'. A string is called balanced if and only if: It is the empty string, or It...
{"functional": "def check(candidate):\n assert candidate(s = \"][][\") == 1\n assert candidate(s = \"]]][[[\") == 2\n assert candidate(s = \"[]\") == 0\n\n\ncheck(Solution().minSwaps)"}
coding
160
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an integer array prices representing the daily price history of a stock, where prices[i] is the stock price on the ith day. A smooth descent period of a stock consists of one or more contiguous days such...
{"functional": "def check(candidate):\n assert candidate(prices = [3,2,1,4]) == 7\n assert candidate(prices = [8,6,7,7]) == 4\n assert candidate(prices = [1]) == 1\n\n\ncheck(Solution().getDescentPeriods)"}
coding
136
Solve the programming task below in a Python markdown code block. You have an n × m rectangle table, its cells are not initially painted. Your task is to paint all cells of the table. The resulting picture should be a tiling of the table with squares. More formally: each cell must be painted some color (the colors are...
{"inputs": ["1 3\n", "2 2\n", "3 4\n", "4 3\n", "1 1\n", "2 3\n", "3 2\n", "1 2\n"], "outputs": ["ABA\n", "AA\nAA\n", "AAAB\nAAAC\nAAAB\n", "AAA\nAAA\nAAA\nBCB\n", "A\n", "AAB\nAAC\n", "AA\nAA\nBC\n", "AB\n"]}
coding
331
Solve the programming task below in a Python markdown code block. Chef took an examination two times. In the first attempt, he scored X marks while in the second attempt he scored Y marks. According to the rules of the examination, the best score out of the two attempts will be considered as the final score. Determin...
{"inputs": ["4\n40 60\n67 55\n50 50\n1 100\n"], "outputs": ["60\n67\n50\n100\n"]}
coding
290
Solve the programming task below in a Python markdown code block. Tejas has invited the Clash Team for a Dinner Party. He places V empty plates (numbered from 1 to V inclusive) in a straight line on a table. He has prepared 2 kinds of Delicious Dishes named dish A and dish B. He has exactly V servings of Dish A and W ...
{"inputs": ["1\n3 3"], "outputs": ["4"]}
coding
280
Solve the programming task below in a Python markdown code block. Read problem statements in [Russian], [Mandarin] and [Vietnamese] as well. You are given a permutation P of integers from 1 to N, and an integer K such that \lceil \frac{2N}{3}\rceil ≤ K ≤ N. In one operation, you can do the following: Choose any conse...
{"inputs": ["4\n6 4\n1 2 3 4 5 6\n6 4\n1 2 4 3 5 6\n6 4\n6 5 2 1 4 3\n6 4\n2 6 4 3 1 5\n"], "outputs": ["0\n1\n2\n3\n"]}
coding
613
Solve the programming task below in a Python markdown code block. In computing, the collection of four bits is called a nibble. Chef defines a program as: Good, if it takes exactly X nibbles of memory, where X is a positive integer. Not Good, otherwise. Given a program which takes N bits of memory, determine whether ...
{"inputs": ["4\n8\n17\n52\n3"], "outputs": ["Good\nNot Good\nGood\nNot Good"]}
coding
498
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a positive integer n representing n cities numbered from 1 to n. You are also given a 2D array roads, where roads[i] = [ai, bi, costi] indicates that there is a bidirectional road between cities ai and b...
{"functional": "def check(candidate):\n assert candidate(n = 4, roads = [[1,2,4],[2,3,2],[2,4,5],[3,4,1],[1,3,4]], appleCost = [56,42,102,301], k = 2) == [54,42,48,51]\n assert candidate(n = 3, roads = [[1,2,5],[2,3,1],[3,1,2]], appleCost = [2,3,1], k = 3) == [2,3,1]\n\n\ncheck(Solution().minCost)"}
coding
265
Solve the programming task below in a Python markdown code block. Given an array A having N elements, Chef wonders how many pairs (i, j) exists such that 1 ≤ i < j ≤ N, and A_{i} \cdot A_{j} is divisible by i \cdot j. Can you help Chef in finding the number of such pairs? ------ Input Format ------ - The first lin...
{"inputs": ["3\n3\n1 2 3\n4\n2 3 5 6\n5\n3 9 14 6 10\n"], "outputs": ["3\n2\n6\n"]}
coding
390
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. Chef is a big fan of soccer! He loves soccer so much, that he even invented soccer for his pet dogs! Here are the rules of the game: There are N dogs numerated from 1 to N s...
{"inputs": ["3\n3 2 2\n1 2 \n3 3 3\n1 1 1\n3 1 1\n3"], "outputs": ["1 0 1\n0 2 0\n0 0 0"]}
coding
716
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"]}
coding
671
Solve the programming task below in a Python markdown code block. John is new to Mathematics and does not know how to calculate GCD of numbers. So he wants you to help him in a few GCD calculations. John has a list A of numbers, indexed 1 to N. He wants to create another list B having N+1 numbers, indexed from 1 to N+1...
{"inputs": ["2\n3\n1 2 3\n3\n5 10 5\n"], "outputs": ["1 2 6 3\n5 10 10 5\n"]}
coding
470
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"]}
coding
610
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an integer array data representing the data, return whether it is a valid UTF-8 encoding (i.e. it translates to a sequence of valid UTF-8 encoded characters). A character in UTF8 can be from 1 to 4 bytes long, s...
{"functional": "def check(candidate):\n assert candidate(data = [197,130,1]) == True\n assert candidate(data = [235,140,4]) == False\n\n\ncheck(Solution().validUtf8)"}
coding
350
Solve the programming task below in a Python markdown code block. Complete the function/method (depending on the language) to return `true`/`True` when its argument is an array that has the same nesting structures and same corresponding length of nested arrays as the first array. For example: ```python # should retur...
{"functional": "_inputs = [[[1, [1, 1]], [[2, 2], 2]], [[1, [1, 1]], [2, [2]]], [[[[], []]], [[[], []]]], [[[[], []]], [[1, 1]]], [[1, [[[1]]]], [2, [[[2]]]]], [[], 1], [[], {}], [[1, '[', ']'], ['[', ']', 1]]]\n_outputs = [[False], [False], [True], [False], [True], [False], [False], [True]]\nimport math\ndef _deep_eq(...
coding
312
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...
coding
579
Solve the programming task below in a Python markdown code block. You're a programmer in a SEO company. The SEO specialist of your company gets the list of all project keywords everyday, then he looks for the longest keys to analyze them. You will get the list with keywords and must write a simple function that return...
{"functional": "_inputs = [['key1', 'key22', 'key333'], ['coding', 'sorting', 'tryruby'], ['small keyword', 'how to coding?', 'very nice kata', 'a lot of keys', 'I like Ruby!!!'], ['pippi']]\n_outputs = [[\"'key333'\"], [\"'sorting', 'tryruby'\"], [\"'I like Ruby!!!', 'how to coding?', 'very nice kata'\"], [\"'pippi'\"...
coding
169
Solve the programming task below in a Python markdown code block. Imagine you have a rooted tree consisting of $n$ vertices. Consider the following function: int order[n]; // initially consists of -1 int pointer = 0; void dfs(int vertex, int depth) { order[pointer] = depth; pointer++; for each child of vertex ...
{"inputs": ["2\n1 ?\n", "4\n0 ? 1 ?\n", "3\n? ? ? \n"], "outputs": ["0\n", "2\n", "2\n"]}
coding
427
Please solve the programming task below using a self-contained code snippet in a markdown code block. An array is squareful if the sum of every pair of adjacent elements is a perfect square. Given an integer array nums, return the number of permutations of nums that are squareful. Two permutations perm1 and perm2 are ...
{"functional": "def check(candidate):\n assert candidate([1,17,8]) == 2\n assert candidate([2,2,2]) == 1\n\n\ncheck(Solution().numSquarefulPerms)"}
coding
114
Solve the programming task below in a Python markdown code block. After solving some Graph Theory related problems KBG challenged Sameer to solve the following problem. There is an undirected graph consisting of N vertices numbered from 1 to N. For every pair of vertices u and v (u \neq v) in the graph, there is a un...
{"inputs": ["1\n6 2\n3 6\n2 3\n"], "outputs": ["2\n5\n"]}
coding
524
Solve the programming task below in a Python markdown code block. Complete the square sum function so that it squares each number passed into it and then sums the results together. For example, for `[1, 2, 2]` it should return `9` because `1^2 + 2^2 + 2^2 = 9`. ```if:racket In Racket, use a list instead of an array, ...
{"functional": "_inputs = [[[1, 2]], [[0, 3, 4, 5]], [[]], [[-1, -2]], [[-1, 0, 1]]]\n_outputs = [[5], [50], [0], [5], [2]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):...
coding
126
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a 0-indexed string word, consisting of lowercase English letters. You need to select one index and remove the letter at that index from word so that the frequency of every letter present in word is equal...
{"functional": "def check(candidate):\n assert candidate(word = \"abcc\") == True\n assert candidate(word = \"aazz\") == False\n\n\ncheck(Solution().equalFrequency)"}
coding
150
Solve the programming task below in a Python markdown code block. Two circles A, B are given on a two-dimensional plane. The coordinate of the center and radius of circle A is (x_A, y_A) and r_A respectively. The coordinate of the center and radius of circle B is (x_B, y_B) and r_B respectively. These two circles have ...
{"inputs": ["4\n0 -3 2 0 3 2\n0 0 9 8 8 2\n0 0 9 10 10 5\n0 0 707 1000 1000 245", "4\n0 -3 2 0 3 2\n0 0 9 8 8 2\n0 0 9 10 10 5\n0 0 707 1000 1010 707", "4\n0 -3 2 0 3 2\n0 0 6 8 8 2\n0 0 9 10 10 5\n0 0 707 1000 1010 707", "4\n1 -6 2 0 3 2\n0 0 9 8 8 2\n0 0 9 10 10 5\n0 0 707 1000 1000 245", "4\n0 -3 2 0 3 3\n0 0 6 8 8 ...
coding
522
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. For each index i (1 <= i <= nums.length - 2) the beauty of nums[i] equals: 2, if nums[j] < nums[i] < nums[k], for all 0 <= j < i and for all i < k <= nums.length - 1. 1, ...
{"functional": "def check(candidate):\n assert candidate(nums = [1,2,3]) == 2\n assert candidate(nums = [2,4,6,4]) == 1\n assert candidate(nums = [3,2,1]) == 0\n\n\ncheck(Solution().sumOfBeauties)"}
coding
181
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an integer n, return a string array answer (1-indexed) where: answer[i] == "FizzBuzz" if i is divisible by 3 and 5. answer[i] == "Fizz" if i is divisible by 3. answer[i] == "Buzz" if i is divisible by 5. answer...
{"functional": "def check(candidate):\n assert candidate(n = 3) == [\"1\",\"2\",\"Fizz\"]\n assert candidate(n = 5) == [\"1\",\"2\",\"Fizz\",\"4\",\"Buzz\"]\n assert candidate(n = 15) == [\"1\",\"2\",\"Fizz\",\"4\",\"Buzz\",\"Fizz\",\"7\",\"8\",\"Fizz\",\"Buzz\",\"11\",\"Fizz\",\"13\",\"14\",\"FizzBuzz\"]\n\n\...
coding
133
Solve the programming task below in a Python markdown code block. Takahashi is solving quizzes. He has easily solved all but the last one. The last quiz has three choices: 1, 2, and 3. With his supernatural power, Takahashi has found out that the choices A and B are both wrong. Print the correct choice for this problem...
{"inputs": ["3\n2", "1\n3", "3\n2", "1\n3", "1\n2", "3\n1", "3\n1\n", "1\n2\n"], "outputs": ["1\n", "2\n", "1\n", "2\n", "3", "2", "2\n", "3\n"]}
coding
164
Solve the programming task below in a Python markdown code block. How many days are we represented in a foreign country? My colleagues make business trips to a foreign country. We must find the number of days our company is represented in a country. Every day that one or more colleagues are present in the country is a...
{"functional": "_inputs = [[[[10, 15], [25, 35]]], [[[2, 8], [220, 229], [10, 16]]]]\n_outputs = [[17], [24]]\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 l...
coding
244
Solve the programming task below in a Python markdown code block. # Write Number in Expanded Form You will be given a number and you will need to return it as a string in [Expanded Form](https://www.mathplacementreview.com/arithmetic/whole-numbers.php#expanded-form). For example: ```python expanded_form(12) # Should ...
{"functional": "_inputs = [[2], [12], [42], [70304], [4982342]]\n_outputs = [['2'], ['10 + 2'], ['40 + 2'], ['70000 + 300 + 4'], ['4000000 + 900000 + 80000 + 2000 + 300 + 40 + 2']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_to...
coding
192
Solve the programming task below in a Python markdown code block. You have an integer variable x. Initially, x=0. Some person gave you a string S of length N, and using the string you performed the following operation N times. In the i-th operation, you incremented the value of x by 1 if S_i=I, and decremented the valu...
{"inputs": ["5\nDIDII", "5\nDIIID", "5\nIDIID", "5\nIIDDI", "5\nDIIDI", "5\nIIIDD", "5\nDDIII", "5\nIDDII"], "outputs": ["1\n", "2\n", "2\n", "2\n", "1\n", "3\n", "1\n", "1\n"]}
coding
225
Solve the programming task below in a Python markdown code block. You are playing one famous sandbox game with the three-dimensional world. The map of the world can be represented as a matrix of size n × m, where the height of the cell (i, j) is a_{i, j}. You are in the cell (1, 1) right now and want to get in the cel...
{"inputs": ["1\n8 6\n2 -1 3 4 1 6\n7 2 16 14 7 12\n1 14 15 10 1 27\n19 20 35 5 6 39\n7 27 54 60 30 31\n33 4 35 36 34 35\n47 38 75 40 41 42\n44 45 49 47 48 49\n", "1\n8 6\n2 -1 3 4 1 6\n7 2 16 14 7 12\n1 14 15 14 1 27\n19 20 35 5 6 39\n7 27 54 60 30 31\n33 4 35 36 34 35\n47 38 75 40 41 42\n44 45 49 47 48 49\n", "1\n8 6\...
coding
717
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given the root of a binary tree with n nodes. Each node is uniquely assigned a value from 1 to n. You are also given an integer startValue representing the value of the start node s, and a different integer de...
{"functional": "def check(candidate):\n assert candidate(root = tree_node([5,1,2,3,None,6,4]), startValue = 3, destValue = 6) == \"UURL\"\n assert candidate(root = tree_node([2,1]), startValue = 2, destValue = 1) == \"L\"\n\n\ncheck(Solution().getDirections)"}
coding
275
Solve the programming task below in a Python markdown code block. Give me Chocolate Anushka wants to buy chocolates.there are many chocolates in front of her, tagged with their prices. Anushka has only a certain amount to spend, and she wants to maximize the number of chocolates she buys with this money. Given a lis...
{"inputs": ["7 50\n1 12 5 111 200 1000 10"], "outputs": ["4"]}
coding
326
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an array of integers citations where citations[i] is the number of citations a researcher received for their ith paper and citations is sorted in ascending order, return the researcher's h-index. According to th...
{"functional": "def check(candidate):\n assert candidate(citations = [0,1,3,5,6]) == 3\n assert candidate(citations = [1,2,100]) == 2\n\n\ncheck(Solution().hIndex)"}
coding
139
Solve the programming task below in a Python markdown code block. You have written N problems to hold programming contests. The i-th problem will have a score of P_i points if used in a contest. With these problems, you would like to hold as many contests as possible under the following condition: * A contest has thr...
{"inputs": ["3\n6 9\n5 6 3", "3\n6 0\n5 6 3", "3\n6 0\n5 9 3", "3\n6 0\n5 3 3", "3\n6 0\n5 3 2", "3\n6 0\n5 1 2", "3\n8 0\n5 1 2", "3\n8 0\n1 1 2"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]}
coding
312
Solve the programming task below in a Python markdown code block. You are given an array $a$ of $n$ integers. You are allowed to perform the following operation on it as many times as you want (0 or more times): Choose $2$ indices $i$,$j$ where $1 \le i < j \le n$ and replace $a_k$ for all $i \leq k \leq j$ with $|a_i...
{"inputs": ["3\n3\n1 1 1\n2\n9 1\n3\n4 9 5\n"], "outputs": ["3\n16\n18\n"]}
coding
468
Please solve the programming task below using a self-contained code snippet in a markdown code block. Alice and Bob take turns playing a game, with Alice starting first. You are given a string num of even length consisting of digits and '?' characters. On each turn, a player will do the following if there is still at ...
{"functional": "def check(candidate):\n assert candidate(num = \"5023\") == False\n assert candidate(num = \"25??\") == True\n assert candidate(num = \"?3295???\") == False\n\n\ncheck(Solution().sumGame)"}
coding
275
Solve the programming task below in a Python markdown code block. # Feynman's squares Richard Phillips Feynman was a well-known American physicist and a recipient of the Nobel Prize in Physics. He worked in theoretical physics and pioneered the field of quantum computing. Recently, an old farmer found some papers and ...
{"functional": "_inputs = [[1], [2], [3], [5], [8], [15]]\n_outputs = [[1], [5], [14], [55], [204], [1240]]\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...
coding
273
Solve the programming task below in a Python markdown code block. You are given a table consisting of n rows and m columns. Each cell of the table contains a number, 0 or 1. In one move we can choose some row of the table and cyclically shift its values either one cell to the left, or one cell to the right. To cyclica...
{"inputs": ["1 1\n0\n", "1 1\n1\n", "3 1\n1\n1\n0\n", "3 1\n0\n0\n0\n", "3 1\n1\n2\n0\n", "2 3\n111\n010\n", "2 3\n110\n010\n", "2 3\n111\n000\n"], "outputs": ["-1", "0", "-1", "-1", "-1\n", "0\n", "0\n", "-1"]}
coding
508
Solve the programming task below in a Python markdown code block. You are given two integers $N$ and ${L}}$. Compute the number of unrooted labelled trees with exactly $N$ nodes and exactly ${L}$ leafs. This number can be huge, so please output it's modulo $10^9+7$. Input Format The first line of input consists of tw...
{"inputs": ["5 2"], "outputs": ["60"]}
coding
138
Solve the programming task below in a Python markdown code block. You are given $n$ integers $a_1, a_2, \ldots, a_n$. Find the maximum value of $max(a_l, a_{l + 1}, \ldots, a_r) \cdot min(a_l, a_{l + 1}, \ldots, a_r)$ over all pairs $(l, r)$ of integers for which $1 \le l < r \le n$. -----Input----- The first line c...
{"inputs": ["1\n2\n44841 417\n", "1\n2\n44841 2653\n", "1\n2\n44841 66241\n", "1\n2\n44841 83433\n", "1\n2\n29981 18424\n", "1\n2\n23338 18424\n", "1\n2\n23338 34273\n", "1\n2\n11672 34273\n"], "outputs": ["18698697\n", "118963173\n", "2970312681\n", "3741219153\n", "552369944\n", "429979312\n", "799863274\n", "4000344...
coding
663
Solve the programming task below in a Python markdown code block. Petya has k matches, placed in n matchboxes lying in a line from left to right. We know that k is divisible by n. Petya wants all boxes to have the same number of matches inside. For that, he can move a match from its box to the adjacent one in one move....
{"inputs": ["1\n0\n", "1\n0\n", "1\n1\n", "1\n2\n", "1\n4\n", "1\n8\n", "1\n6\n", "1\n3\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]}
coding
194
Solve the programming task below in a Python markdown code block. Your favorite music streaming platform has formed a perfectly balanced playlist exclusively for you. The playlist consists of $n$ tracks numbered from $1$ to $n$. The playlist is automatic and cyclic: whenever track $i$ finishes playing, track $i+1$ star...
{"inputs": ["2\n1 1\n", "2\n1 1\n", "3\n4 3 6\n", "3\n2 5 3\n", "3\n2 5 3\n", "3\n3 5 3\n", "3\n3 9 5\n", "3\n4 1 2\n"], "outputs": ["-1 -1\n", "-1 -1 ", "-1 -1 -1\n", "3 2 4\n", "3 2 4 \n", "-1 -1 -1\n", "3 2 4\n", "1 3 2\n"]}
coding
744
Solve the programming task below in a Python markdown code block. You're given two arrays $a[1 \dots n]$ and $b[1 \dots n]$, both of the same length $n$. In order to perform a push operation, you have to choose three integers $l, r, k$ satisfying $1 \le l \le r \le n$ and $k > 0$. Then, you will add $k$ to elements $a...
{"inputs": ["2\n1\n2\n1\n1\n1\n1\n", "2\n1\n2\n1\n1\n1\n1\n", "2\n1\n1\n1\n1\n1\n1\n", "2\n1\n2\n2\n1\n1\n1\n", "2\n1\n1\n1\n1\n0\n1\n", "2\n1\n2\n2\n1\n0\n1\n", "1\n3\n1 1 1\n1 1 3\n", "1\n3\n2 5 2\n2 3 2\n"], "outputs": ["NO\nYES\n", "NO\nYES\n", "YES\nYES\n", "YES\nYES\n", "YES\nYES\n", "YES\nYES\n", "YES\n", "NO\n"...
coding
692
Solve the programming task below in a Python markdown code block. The R2 company has n employees working for it. The work involves constant exchange of ideas, sharing the stories of success and upcoming challenging. For that, R2 uses a famous instant messaging program Spyke. R2 has m Spyke chats just to discuss all so...
{"inputs": ["2 1 1\n1\n1\n1 1\n", "2 1 1\n1\n1\n1 1\n", "2 1 1\n1\n1\n2 1\n", "2 1 1\n1\n1\n1 1\n", "2 1 1\n1\n1\n2 1\n", "2 1 1\n1\n0\n1 1\n", "3 1 2\n1\n1\n0\n1 1\n2 1\n", "3 1 2\n1\n0\n1\n1 1\n3 1\n"], "outputs": ["0 1 ", "0 1 ", "1 0 ", "0 1 \n", "1 0 \n", "0 0", "1 1 0 ", "1 0 1 "]}
coding
624
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an integer array nums, return the third distinct maximum number in this array. If the third maximum does not exist, return the maximum number.   Please complete the following python code precisely: ```python cla...
{"functional": "def check(candidate):\n assert candidate([3, 2, 1]) == 1\n assert candidate([1, 2]) == 2\n assert candidate([2, 2, 3, 1]) == 1\n\n\ncheck(Solution().thirdMax)"}
coding
77
Solve the programming task below in a Python markdown code block. There are N integers written on a blackboard. The i-th integer is A_i. Takahashi will repeatedly perform the following operation on these numbers: * Select a pair of integers, A_i and A_j, that have the same parity (that is, both are even or both are o...
{"inputs": ["3\n2 2 3", "3\n2 2 6", "3\n2 2 7", "3\n1 2 7", "3\n1 0 7", "3\n1 2 3", "3\n1 0 13", "3\n1 0 19"], "outputs": ["NO\n", "YES\n", "NO\n", "YES\n", "YES\n", "YES", "YES\n", "YES\n"]}
coding
243
Solve the programming task below in a Python markdown code block. G: Working Kou decided to do the same number of jobs every day for the next $ N $. $ A_i $ jobs are added on the $ i $ day of the $ N $ day. Mr. Kou has no work to do now, and he doesn't have to finish all the work by the $ N $ day. How many jobs can...
{"inputs": ["5\n4 2 5 3 0", "5\n4 2 3 3 0", "5\n6 2 3 3 0", "5\n6 3 0 3 0", "5\n6 3 0 2 0", "5\n8 3 0 2 0", "5\n9 3 0 2 0", "5\n9 3 0 4 0"], "outputs": ["2\n", "2\n", "2\n", "2\n", "2\n", "2\n", "2\n", "3\n"]}
coding
339
Solve the programming task below in a Python markdown code block. Have you ever played Hanabi? If not, then you've got to try it out! This problem deals with a simplified version of the game. Overall, the game has 25 types of cards (5 distinct colors and 5 distinct values). Borya is holding n cards. The game is somewh...
{"inputs": ["2\nG3 G3\n", "2\nW3 Y5\n", "2\nW5 Y5\n", "2\nW5 Y5\n", "2\nW3 Y5\n", "2\nW4 Y5\n", "2\nW3 Y4\n", "2\nG3 G3\n"], "outputs": ["0\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "0\n"]}
coding
503
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an m x n 2D binary grid grid which represents a map of '1's (land) and '0's (water), return the number of islands. An island is surrounded by water and is formed by connecting adjacent lands horizontally or vert...
{"functional": "def check(candidate):\n assert candidate(grid = [\n [\"1\",\"1\",\"1\",\"1\",\"0\"],\n [\"1\",\"1\",\"0\",\"1\",\"0\"],\n [\"1\",\"1\",\"0\",\"0\",\"0\"],\n [\"0\",\"0\",\"0\",\"0\",\"0\"]\n]) == 1\n assert candidate(grid = [\n [\"1\",\"1\",\"0\",\"0\",\"0\"],\n [\"1\",\"1\",\"0\",\"0\",\"0\...
coding
118
Solve the programming task below in a Python markdown code block. You are given a text consisting of n lines. Each line contains some space-separated words, consisting of lowercase English letters. We define a syllable as a string that contains exactly one vowel and any arbitrary number (possibly none) of consonants. ...
{"inputs": ["1\n1\naa\n", "1\n1\naa\n", "1\n2\naa\n", "1\n0\naa\n", "1\n0\na`\n", "1\n0\n`a\n", "1\n1\naaa\n", "1\n1\naaa\n"], "outputs": ["NO\n", "NO\n", "YES\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n"]}
coding
626
Solve the programming task below in a Python markdown code block. You are the judge at a competitive eating competition and you need to choose a winner! There are three foods at the competition and each type of food is worth a different amount of points. Points are as follows: - Chickenwings: 5 points - Hamburgers...
{"functional": "_inputs = [[[{'name': 'Billy The Beast', 'chickenwings': 17, 'hamburgers': 7, 'hotdogs': 8}, {'name': 'Habanero Hillary', 'chickenwings': 5, 'hamburgers': 17, 'hotdogs': 11}, {'name': 'Joey Jaws', 'chickenwings': 8, 'hamburgers': 8, 'hotdogs': 15}, {'name': 'Big Bob', 'chickenwings': 20, 'hamburgers': 4...
coding
265
Solve the programming task below in a Python markdown code block. Alice and Bob invented the following silly game: The game starts with an integer, $n$, that's used to build a $\boldsymbol{set}$ of $n$ distinct integers in the inclusive range from $1$ to $n$ (i.e., $set=\{1,2,3,\ldots,n-1,n\}$). Alice always plays fir...
{"inputs": ["3\n1\n2\n5\n"], "outputs": ["Bob\nAlice\nAlice\n"]}
coding
679
Solve the programming task below in a Python markdown code block. Last year Bob earned by selling memory sticks. During each of n days of his work one of the two following events took place: * A customer came to Bob and asked to sell him a 2x MB memory stick. If Bob had such a stick, he sold it and got 2x berllars....
{"inputs": ["1\nsell 17\n", "1\nsell 31\n", "1\nwin 2000\n", "1\nsell 104\n", "1\nsell 2000\n", "2\nwin 2000\nsell 238\n", "2\nwin 2000\nsell 315\n", "2\nwin 2000\nsell 350\n"], "outputs": ["0\n", "0\n", "0", "0\n", "0", "0\n", "0\n", "0\n"]}
coding
440
Solve the programming task below in a Python markdown code block. A left rotation operation on an array of size $n$ shifts each of the array's elements $1$ unit to the left. Given an integer, $\boldsymbol{d}$, rotate the array that many steps left and return the result. Example $\boldsymbol{d}=2$ $arr=[1,2,3,4,5...
{"inputs": ["5 4\n1 2 3 4 5\n"], "outputs": ["5 1 2 3 4\n"]}
coding
379
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a 0-indexed 2D integer array nums representing the coordinates of the cars parking on a number line. For any index i, nums[i] = [starti, endi] where starti is the starting point of the ith car and endi i...
{"functional": "def check(candidate):\n assert candidate(nums = [[3,6],[1,5],[4,7]]) == 7\n assert candidate(nums = [[1,3],[5,8]]) == 7\n\n\ncheck(Solution().numberOfPoints)"}
coding
133
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)"}
coding
120
Solve the programming task below in a Python markdown code block. Let A, B, C, D, E be sets of integers and let U is a universal set that includes all sets under consideration. All elements in any set are different (no repetitions). u - union of two sets, AuB = {x ∈ U : x ∈ A or x ∈ B} is the set of all elements which...
{"inputs": ["A 3\n1 3 -1\nB 4\n3 1 5 7\nD 1\n5\nR 0\ncAiBdD\nC 3\n1 2 3\nA 4\n2 9 8 3\nB 3\n2 4 8\nR 0\n(As(AiB))uC", "A 3\n1 2 -1\nB 4\n3 1 5 7\nD 1\n5\nR 0\ncAiBdD\nC 3\n1 2 3\nA 4\n2 9 8 3\nB 3\n2 4 8\nR 0\n(As(AiB))uC", "A 3\n2 3 -1\nB 4\n3 1 5 7\nD 1\n5\nR 0\ncAiBdD\nC 3\n1 2 3\nA 4\n2 9 8 3\nB 3\n2 4 8\nR 0\n(As(...
coding
594
Solve the programming task below in a Python markdown code block. Chef is looking to buy a TV and has shortlisted two models. The first one costs A rupees, while the second one costs B rupees. Since there is a huge sale coming up on Chefzon, Chef can get a flat discount of C rupees on the first TV, and a flat discount...
{"inputs": ["3\n85 75 35 20\n100 99 0 0\n30 40 0 10\n"], "outputs": ["First\nSecond\nAny\n"]}
coding
576