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. You have a rooted tree with $n$ vertices numbered from $\mbox{1}$ through $n$ where the root is vertex $\mbox{1}$. You are given $m$ triplets, the $j^{th}$ triplet is denoted by three integers $u_j,v_j,c_j$. The $j^{th}$ triplet represents a simple pat...
{"inputs": ["1\n8 8\n1 2 3\n1 3 1\n2 4 5\n2 5 1\n2 6 1\n3 7 2\n4 8 1\n1 2 3\n2 8 5\n1 8 7\n1 5 8\n1 6 10\n3 7 5\n1 7 6\n1 7 6\n"], "outputs": ["37\n"]}
coding
670
Solve the programming task below in a Python markdown code block. Ho ho! So you think you know integers, do you? Well then, young wizard, tell us what the Nth digit of the [Champernowne constant](https://en.wikipedia.org/wiki/Champernowne_constant) is! The constant proceeds like this: `0.12345678910111213141516...` I...
{"functional": "_inputs = [[1], [2], [3], [4], [5], [6], [7], [8], [9], [10], [11], [12], [20], [35], [36], [37], [100], [101], [102], [103], [104], [105], [190], [2890], [38890], [488890], [5888890], [3678608], [3678609], [3678610], [3678611], [3678612], [3678613], [3678614], [3897249], [3897189], [3897309], [3897369]...
coding
338
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 an integer $n$ and a string $s$ consisting only of characters 'a' and 'b'. Consider a string $t = \underbrace{s + s + \dots + s}_{n\text{ times}}$, i.e. the str...
{"inputs": ["3\naba 2\nbaa 3\nbba 3"], "outputs": ["5\n6\n0"]}
coding
497
Solve the programming task below in a Python markdown code block. Zenyk and Marichka are playing a game taking turns alternatively. They have N piles of stones. In the i^{th} pile, there are A_{i} stones initially. Marichka goes first, and removes any non-zero number of stones from any pile. After that, in one move...
{"inputs": ["3\n3\n1 2 3\n2\n1 1\n1\n10\n"], "outputs": ["Marichka\nZenyk\nMarichka\n"]}
coding
514
Solve the programming task below in a Python markdown code block. Today, hedgehog Filya went to school for the very first time! Teacher gave him a homework which Filya was unable to complete without your help. Filya is given an array of non-negative integers a_1, a_2, ..., a_{n}. First, he pick an integer x and then h...
{"inputs": ["1\n0\n", "1\n0\n", "1\n1\n", "2\n1 2\n", "2\n4 2\n", "2\n2 3\n", "2\n4 2\n", "2\n2 3\n"], "outputs": ["YES\n", "YES\n", "YES\n", "YES\n", "YES\n", "YES\n", "YES\n", "YES\n"]}
coding
366
Solve the programming task below in a Python markdown code block. Reve has two integers $n$ and $k$. Let $p$ be a permutation$^\dagger$ of length $n$. Let $c$ be an array of length $n - k + 1$ such that $$c_i = \max(p_i, \dots, p_{i+k-1}) + \min(p_i, \dots, p_{i+k-1}).$$ Let the cost of the permutation $p$ be the maxi...
{"inputs": ["3\n5 3\n5 1\n6 6\n"], "outputs": ["5 4 1 3 2\n1 2 3 4 5\n6 5 4 3 2 1\n"]}
coding
615
Solve the programming task below in a Python markdown code block. Your city has n junctions. There are m one-way roads between the junctions. As a mayor of the city, you have to ensure the security of all the junctions. To ensure the security, you have to build some police checkposts. Checkposts can only be built in a...
{"inputs": ["1\n0\n0\n", "1\n0\n0\n", "1\n1000000000\n0\n", "1\n1000000000\n0\n", "2\n7 91\n2\n1 2\n2 1\n", "2\n6 91\n2\n1 2\n2 1\n", "2\n7 91\n2\n1 2\n2 1\n", "3\n1 2 3\n3\n1 2\n2 3\n3 2\n"], "outputs": ["0 1\n", "0 1\n", "1000000000 1\n", "1000000000 1\n", "7 1\n", "6 1\n", "7 1\n", "3 1\n"]}
coding
656
Solve the programming task below in a Python markdown code block. You are given array $a_1, a_2, \dots, a_n$. Find the subsegment $a_l, a_{l+1}, \dots, a_r$ ($1 \le l \le r \le n$) with maximum arithmetic mean $\frac{1}{r - l + 1}\sum\limits_{i=l}^{r}{a_i}$ (in floating-point numbers, i.e. without any rounding). If th...
{"inputs": ["1\n1\n", "1\n0\n", "1\n0\n", "1\n1\n", "1\n2\n", "1\n3\n", "1\n4\n", "2\n1 2\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n"]}
coding
266
Solve the programming task below in a Python markdown code block. The [half-life](https://en.wikipedia.org/wiki/Half-life) of a radioactive substance is the time it takes (on average) for one-half of its atoms to undergo radioactive decay. # Task Overview Given the initial quantity of a radioactive substance, the quan...
{"functional": "_inputs = [[10, 5, 1], [8, 4, 2], [12, 3, 2]]\n_outputs = [[1], [2], [1]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) != len(b): ret...
coding
264
Solve the programming task below in a Python markdown code block. [Langton's ant](https://en.wikipedia.org/wiki/Langton%27s_ant) is a two-dimensional Turing machine invented in the late 1980s. The ant starts out on a grid of black and white cells and follows a simple set of rules that has complex emergent behavior. ##...
{"functional": "_inputs = [[[[1]], 0, 0, 1, 0], [[[0]], 0, 0, 1, 0], [[[1]], 0, 0, 3, 0], [[[1]], 0, 0, 1]]\n_outputs = [[[[0, 0]]], [[[0, 1]]], [[[0, 1], [0, 1]]], [[[0, 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=to...
coding
464
Solve the programming task below in a Python markdown code block. Aayush has recently started teaching Latin Dance. Today, he will be teaching Salsa. For this, he needs to divide the people attending his dance class into pairs. Usually in Salsa, the dance pairs consist of one girl and one boy. But Aayush doesn't find t...
{"inputs": ["2\n5 8\n7 10"], "outputs": ["5\n6\n"]}
coding
412
Solve the programming task below in a Python markdown code block. Kolya got an integer array $a_1, a_2, \dots, a_n$. The array can contain both positive and negative integers, but Kolya doesn't like $0$, so the array doesn't contain any zeros. Kolya doesn't like that the sum of some subsegments of his array can be $0$...
{"inputs": ["2\n-1 1\n", "2\n-1 1\n", "3\n1 2 -3\n", "3\n1 2 -3\n", "4\n1 -5 3 2\n", "4\n1 -5 2 2\n", "4\n2 -5 2 2\n", "4\n1 -5 4 2\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "0\n", "1\n"]}
coding
566
Please solve the programming task below using a self-contained code snippet in a markdown code block. There are n students in a class numbered from 0 to n - 1. The teacher will give each student a problem starting with the student number 0, then the student number 1, and so on until the teacher reaches the student num...
{"functional": "def check(candidate):\n assert candidate(chalk = [5,1,5], k = 22) == 0\n assert candidate(chalk = [3,4,1,2], k = 25) == 1\n\n\ncheck(Solution().chalkReplacer)"}
coding
219
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a 2D matrix of size m x n, consisting of non-negative integers. You are also given an integer k. The value of coordinate (a, b) of the matrix is the XOR of all matrix[i][j] where 0 <= i <= a < m and 0 <=...
{"functional": "def check(candidate):\n assert candidate(matrix = [[5,2],[1,6]], k = 1) == 7\n assert candidate(matrix = [[5,2],[1,6]], k = 2) == 5\n assert candidate(matrix = [[5,2],[1,6]], k = 3) == 4\n assert candidate(matrix = [[5,2],[1,6]], k = 4) == 0\n\n\ncheck(Solution().kthLargestValue)"}
coding
147
Solve the programming task below in a Python markdown code block. You are a rebel leader and you are planning to start a revolution in your country. But the evil Government found out about your plans and set your punishment in the form of correctional labor. You must paint a fence which consists of $10^{100}$ planks i...
{"inputs": ["1\n99999 100001 2\n", "1\n99999 100001 2\n", "1\n99999 100001 1\n", "1\n99999 100000 2\n", "1\n99999 100000 0\n", "1\n99999 100000 1\n", "1\n12 73 200000000\n", "1\n12 73 200000000\n"], "outputs": ["REBEL\n", "REBEL\n", "REBEL\n", "OBEY\n", "REBEL\n", "REBEL\n", "OBEY\n", "OBEY\n"]}
coding
520
Solve the programming task below in a Python markdown code block. Emuskald is an avid horticulturist and owns the world's longest greenhouse — it is effectively infinite in length. Over the years Emuskald has cultivated n plants in his greenhouse, of m different plant species numbered from 1 to m. His greenhouse is ve...
{"inputs": ["1 1\n1 0\n", "1 2\n1 0\n", "3 3\n3 0\n1 1\n2 2\n", "3 3\n2 0\n1 1\n3 2\n", "3 3\n3 0\n1 1\n2 4\n", "3 3\n2 0\n1 2\n3 2\n", "3 3\n2 0\n1 4\n3 2\n", "3 2\n2 1\n2 2.0\n1 3.100\n"], "outputs": ["0\n", "0\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n"]}
coding
638
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin Chinese and Russian as well. Given a sequence of n distinct numbers a[1..n], we want to sort them in an ascending order. An interesting property of some sequences is that all numbers are almost at their correct pos...
{"inputs": ["2\n3\n1 2 3\n5\n2 4 1 3 5"], "outputs": ["YES\nNO"]}
coding
294
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an n x n binary matrix image, flip the image horizontally, then invert it, and return the resulting image. To flip an image horizontally means that each row of the image is reversed. For example, flipping [1,1,...
{"functional": "def check(candidate):\n assert candidate(image = [[1,1,0],[1,0,1],[0,0,0]]) == [[1,0,0],[0,1,0],[1,1,1]]\n assert candidate(image = [[1,1,0,0],[1,0,0,1],[0,1,1,1],[1,0,1,0]]) == [[1,1,0,0],[0,1,1,0],[0,0,0,1],[1,0,1,0]]\n\n\ncheck(Solution().flipAndInvertImage)"}
coding
160
Solve the programming task below in a Python markdown code block. Due to another of his misbehaved, the primary school's teacher of the young Gauß, Herr J.G. Büttner, to keep the bored and unruly young schoolboy Karl Friedrich Gauss busy for a good long time, while he teaching arithmetic to his mates, assigned him th...
{"functional": "_inputs = [[100], [300], [303], [50000], ['n'], [3.14], [0], [-10]]\n_outputs = [[5050], [45150], [46056], [1250025000], [None], [None], [None], [None]]\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_t...
coding
303
Solve the programming task below in a Python markdown code block. This is a simple game you must have played around with during your school days, calculating FLAMES of you and your crush! Given the names of two people, cancel out the common letters (repeated occurrence of a letter is treated separately, so 2A's in one ...
{"inputs": ["2\nSHILPA\nAAMIR\nMATT\nDENISE\n\n\n"], "outputs": ["ENEMIES\nLOVE"]}
coding
376
Solve the programming task below in a Python markdown code block. You are given two positive integer numbers x and y. An array F is called an y-factorization of x iff the following conditions are met: There are y elements in F, and all of them are integer numbers; $\prod_{i = 1}^{y} F_{i} = x$. You have to count th...
{"inputs": ["1\n4 4683\n", "1\n8 4683\n", "1\n8 8343\n", "1\n8 7803\n", "1\n8 2147\n", "1\n8 2163\n", "1\n8 3647\n", "1\n16 654\n"], "outputs": ["303279594\n", "621629319\n", "553137688\n", "366213165\n", "273611487\n", "177004929\n", "754511490\n", "220226534\n"]}
coding
356
Solve the programming task below in a Python markdown code block. The chef is trying to solve some pattern problems, Chef wants your help to code it. Chef has one number K to form a new pattern. Help the chef to code this pattern problem. -----Input:----- - First-line will contain $T$, the number of test cases. Then t...
{"inputs": ["2\n2\n4"], "outputs": ["2\n21\n210\n21\n2\n4\n43\n432\n4321\n43210\n4321\n432\n43\n4"]}
coding
220
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a 0-indexed array usageLimits of length n. Your task is to create groups using numbers from 0 to n - 1, ensuring that each number, i, is used no more than usageLimits[i] times in total across all groups....
{"functional": "def check(candidate):\n assert candidate(usageLimits = [1,2,5]) == 3\n assert candidate(usageLimits = [2,1,2]) == 2\n assert candidate(usageLimits = [1,1]) == 1\n\n\ncheck(Solution().maxIncreasingGroups)"}
coding
170
Solve the programming task below in a Python markdown code block. Consider an array A of length N. You know that for all 1 ≤ i ≤ N, 0 ≤ A_{i} ≤ 10^{5}. We construct an array B of length N-1 such that, for all 1 ≤ i ≤ N - 1, B_{i} = min(A_{i}, A_{i + 1}). You are given the array B, you need to find out the total number...
{"inputs": ["3\n2\n100\n5\n3 9 8 4\n3\n10 12"], "outputs": ["199801\n199983\n199977"]}
coding
532
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a 0-indexed integer array nums of size n containing all numbers from 1 to n, return the number of increasing quadruplets. A quadruplet (i, j, k, l) is increasing if: 0 <= i < j < k < l < n, and nums[i] < nums[k...
{"functional": "def check(candidate):\n assert candidate(nums = [1,3,2,4,5]) == 2\n assert candidate(nums = [1,2,3,4]) == 0\n\n\ncheck(Solution().countQuadruplets)"}
coding
127
Solve the programming task below in a Python markdown code block. *SCHEDULE YOUR DA(RRA)Y* The best way to have a productive day is to plan out your work schedule. Given the following three inputs, please create an an array of time alloted to work, broken up with time alloted with breaks: Input 1: Hou...
{"functional": "_inputs = [[8, 5, 30], [3, 5, 60], [2, 2, 60], [2, 1, 60], [2, 0, 60]]\n_outputs = [[[30, 82, 30, 82, 30, 82, 30, 82, 30]], [\"You're not sleeping tonight!\"], [[60, 0, 60]], [[60]], [[]]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return m...
coding
283
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a list of words, list of  single letters (might be repeating) and score of every character. Return the maximum score of any valid set of words formed by using the given letters (words[i] cannot be used two or mo...
{"functional": "def check(candidate):\n assert candidate(words = [\"dog\",\"cat\",\"dad\",\"good\"], letters = [\"a\",\"a\",\"c\",\"d\",\"d\",\"d\",\"g\",\"o\",\"o\"], score = [1,0,9,5,0,0,3,0,0,0,0,0,0,0,2,0,0,0,0,0,0,0,0,0,0,0]) == 23\n assert candidate(words = [\"xxxz\",\"ax\",\"bx\",\"cx\"], letters = [\"z\",...
coding
169
Solve the programming task below in a Python markdown code block. You are given a sequence of N$N$ powers of an integer k$k$; let's denote the i$i$-th of these powers by kAi$k^{A_i}$. You should partition this sequence into two non-empty contiguous subsequences; each element of the original sequence should appear in ex...
{"inputs": ["1\n5 2\n1 1 3 3 5"], "outputs": ["4"]}
coding
627
Solve the programming task below in a Python markdown code block. Snuke has a rooted tree with N+1 vertices. The vertices are numbered 0 through N, and Vertex 0 is the root of the tree. The parent of Vertex i (1 \leq i \leq N) is Vertex p_i. Besides this tree, Snuke also has an box which is initially empty and many mar...
{"inputs": ["2\n0 1", "2\n0 0", "2\n0 0\n", "5\n0 1 1 0 3", "5\n0 1 1 1 4", "5\n0 1 0 0 4", "5\n0 1 4 0 4", "5\n0 1 1 0 4"], "outputs": ["12\n", "8", "8\n", "128\n", "120\n", "88\n", "96\n", "96"]}
coding
412
Please solve the programming task below using a self-contained code snippet in a markdown code block. You have n computers. You are given the integer n and a 0-indexed integer array batteries where the ith battery can run a computer for batteries[i] minutes. You are interested in running all n computers simultaneously...
{"functional": "def check(candidate):\n assert candidate(n = 2, batteries = [3,3,3]) == 4\n assert candidate(n = 2, batteries = [1,1,1,1]) == 2\n\n\ncheck(Solution().maxRunTime)"}
coding
193
Solve the programming task below in a Python markdown code block. In this Kata, we are going to see how a Hash (or Map or dict) can be used to keep track of characters in a string. Consider two strings `"aabcdefg"` and `"fbd"`. How many characters do we have to remove from the first string to get the second string? ...
{"functional": "_inputs = [['xyz', 'yxz'], ['abcxyz', 'ayxz'], ['abcdexyz', 'yxz'], ['xyz', 'yxxz'], ['abdegfg', 'ffdb'], ['aabcdefg', 'fbd']]\n_outputs = [[0], [2], [5], [0], [0], [5]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, r...
coding
202
Solve the programming task below in a Python markdown code block. Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. For positive integers $a$ and $b$, we say that a fraction $\frac{a}{b}$ is *good* if it is equal to $\frac{m}{m+1}$ for some positive integer $m$. Y...
{"inputs": ["5"], "outputs": ["8"]}
coding
392
Solve the programming task below in a Python markdown code block. In this kata, you've to count lowercase letters in a given string and return the letter count in a hash with 'letter' as key and count as 'value'. The key must be 'symbol' instead of string in Ruby and 'char' instead of string in Crystal. Example: ```...
{"functional": "_inputs = [['codewars'], ['activity'], ['arithmetics'], ['traveller'], ['daydreamer']]\n_outputs = [[{'a': 1, 'c': 1, 'd': 1, 'e': 1, 'o': 1, 'r': 1, 's': 1, 'w': 1}], [{'a': 1, 'c': 1, 'i': 2, 't': 2, 'v': 1, 'y': 1}], [{'a': 1, 'c': 1, 'e': 1, 'h': 1, 'i': 2, 'm': 1, 'r': 1, 's': 1, 't': 2}], [{'a': 1...
coding
159
Please solve the programming task below using a self-contained code snippet in a markdown code block. A swap is defined as taking two distinct positions in an array and swapping the values in them. A circular array is defined as an array where we consider the first element and the last element to be adjacent. Given a ...
{"functional": "def check(candidate):\n assert candidate(nums = [0,1,0,1,1,0,0]) == 1\n assert candidate(nums = [0,1,1,1,0,0,1,1,0]) == 2\n assert candidate(nums = [1,1,0,0,1]) == 0\n\n\ncheck(Solution().minSwaps)"}
coding
119
Solve the programming task below in a Python markdown code block. Ganesh lives in Gopalmath. He is looking for Jojo. So he decides to collect Aadhar Card Information of all the citizens of India from UIDAI. Someone told Ganesh that the sum of all the digits of Jojo’s Aadhar number is divisible by 10 and it is greater t...
{"inputs": ["1\n3"], "outputs": ["37"]}
coding
332
Solve the programming task below in a Python markdown code block. Grandma Capa has decided to knit a scarf and asked Grandpa Sher to make a pattern for it, a pattern is a string consisting of lowercase English letters. Grandpa Sher wrote a string $s$ of length $n$. Grandma Capa wants to knit a beautiful scarf, and in ...
{"inputs": ["5\n8\nabcaacab\n6\nxyzxyz\n4\nabba\n8\nrprarlap\n10\nkhyyhhyhky\n", "5\n8\nabcaacab\n6\nxyzxyz\n4\nabba\n8\nrpqarlap\n10\nkhyyhhyhky\n", "5\n8\nabcaacab\n6\nxyzxyy\n4\nabba\n8\nrpqarlap\n10\nkhyyhhyhky\n", "5\n8\nabcaacab\n6\nxyzxyz\n4\nabab\n8\nrpqarlap\n10\nkhyyhhyhky\n", "5\n8\nabcaacab\n6\nxyzxyy\n4\na...
coding
622
Solve the programming task below in a Python markdown code block. Sarthak and Anuradha are very good friends and are eager to participate in an event called *Equinox*. It is a game of words. In this game, $N$ strings $S_{1},\ldots, S_{N}$ are given. For each string $S_{i}$, if it starts with one of the letters of the w...
{"inputs": ["2\n4 1 3\nABBBCDDE\nEARTH\nINDIA\nUUUFFFDDD\n2 5 7\nSDHHD\nXOXOXOXO"], "outputs": ["DRAW\nANURADHA"]}
coding
662
Solve the programming task below in a Python markdown code block. Mobile phones are equipped with a function that displays input candidates in order to efficiently input texts such as emails. This records frequently used words and presents words that have the entered letters as initial letters as input candidates. For ...
{"inputs": ["1\nben likes bananas the best among many fruits because bananas are sweet and cheap\nb\n1\nwinners get to visit aizu and the university of aizu and make many friends as well\na\n3\nask alex about\nthe answer for the\nassignment on android apps\na\n2\nprogramming is both\na spprt and an intellectual puzzle\...
coding
439
Solve the programming task below in a Python markdown code block. The busses in Berland are equipped with a video surveillance system. The system records information about changes in the number of passengers in a bus after stops. If $x$ is the number of passengers in a bus just before the current bus stop and $y$ is t...
{"inputs": ["2 4\n0 1\n", "2 2\n0 1\n", "2 4\n0 0\n", "2 1\n0 0\n", "2 2\n0 0\n", "2 4\n1 0\n", "2 4\n-1 1\n", "2 4\n-1 0\n"], "outputs": ["4\n", "2\n", "5\n", "2\n", "3\n", "4\n", "4\n", "4\n"]}
coding
545
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a binary string s ​​​​​without leading zeros, return true​​​ if s contains at most one contiguous segment of ones. Otherwise, return false.   Please complete the following python code precisely: ```python class ...
{"functional": "def check(candidate):\n assert candidate(s = \"1001\") == False\n assert candidate(s = \"110\") == True\n\n\ncheck(Solution().checkOnesSegment)"}
coding
81
Solve the programming task below in a Python markdown code block. A flea is sitting at one of the n hassocks, arranged in a circle, at the moment. After minute number k the flea jumps through k - 1 hassoсks (clockwise). For example, after the first minute the flea jumps to the neighboring hassock. You should answer: wi...
{"inputs": ["7\n", "5\n", "9\n", "8\n", "8\n", "2\n", "6\n", "4\n"], "outputs": ["NO\n", "NO\n", "NO\n", "YES\n", "YES\n", "YES\n", "NO\n", "YES\n"]}
coding
159
Solve the programming task below in a Python markdown code block. You are given a sequence $s$ consisting of $n$ digits from $1$ to $9$. You have to divide it into at least two segments (segment — is a consecutive sequence of elements) (in other words, you have to place separators between some digits of the sequence) ...
{"inputs": ["1\n3\n333\n", "1\n3\n333\n", "1\n3\n343\n", "1\n3\n218\n", "1\n3\n242\n", "1\n4\n3333\n", "1\n4\n5234\n", "1\n4\n9999\n"], "outputs": ["YES\n2\n3 33\n", "YES\n2\n3 33\n", "YES\n2\n3 43\n", "YES\n2\n2 18\n", "YES\n2\n2 42\n", "YES\n2\n3 333\n", "YES\n2\n5 234\n", "YES\n2\n9 999\n"]}
coding
691
Solve the programming task below in a Python markdown code block. One day, Niwango-kun, an employee of Dwango Co., Ltd., found an integer sequence (a_1, ..., a_N) of length N. He is interested in properties of the sequence a. For a nonempty contiguous subsequence a_l, ..., a_r (1 \leq l \leq r \leq N) of the sequence ...
{"inputs": ["4 4\n2 5 2 5", "4 2\n2 5 3 5", "4 4\n2 5 2 1", "4 2\n4 5 2 5", "4 2\n2 8 2 5", "4 2\n2 5 2 5", "8 4\n9 1 8 2 7 5 6 6", "8 4\n9 1 8 2 7 8 6 6"], "outputs": ["6\n", "13\n", "2\n", "9\n", "12\n", "12", "32\n", "33\n"]}
coding
300
Solve the programming task below in a Python markdown code block. Your are given a string $S$ containing only lowercase letter and a array of character $arr$. Find whether the given string only contains characters from the given character array. Print $1$ if the string contains characters from the given array only els...
{"inputs": ["3\nabcd\n4\na b c d\naabbbcccdddd\n4\na b c d\nacd\n3\na b d"], "outputs": ["1\n1\n0"]}
coding
250
Solve the programming task below in a Python markdown code block. A map of some object is a rectangular field consisting of n rows and n columns. Each cell is initially occupied by the sea but you can cover some some cells of the map with sand so that exactly k islands appear on the map. We will call a set of sand cell...
{"inputs": ["2 3\n", "6 5\n", "2 1\n", "1 0\n", "2 4\n", "2 0\n", "1 1\n", "2 2\n"], "outputs": ["NO", "YES\nLSLSLS\nSLSLSS\nSSSSSS\nSSSSSS\nSSSSSS\nSSSSSS\n", "YES\nLS\nSS\n", "YES\nS\n", "NO", "YES\nSS\nSS\n", "YES\nL\n", "YES\nLS\nSL\n"]}
coding
384
Solve the programming task below in a Python markdown code block. Taro and Hanako are playing card games. They have n cards each, and they compete n turns. At each turn Taro and Hanako respectively puts out a card. The name of the animal consisting of alphabetical letters is written on each card, and the bigger one in ...
{"inputs": ["3\nact dog\nfish fish\nlion tiger", "3\nact god\nfish fith\nlion tiger", "3\nuea goe\ndirh giuh\nnojk tiger", "3\nvea hpg\njrie giug\nnpjk rhget", "3\nv`f ggn\njrhd jgug\njnok ehrug", "3\nact god\nfish fish\nlion tiger", "3\nact god\nfish gith\nlion tiger", "3\nact goe\nfish gith\nlion tiger"], "outputs": ...
coding
243
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an array nums of distinct positive integers, return the number of tuples (a, b, c, d) such that a * b = c * d where a, b, c, and d are elements of nums, and a != b != c != d.   Please complete the following pyth...
{"functional": "def check(candidate):\n assert candidate(nums = [2,3,4,6]) == 8\n assert candidate(nums = [1,2,4,5,10]) == 16\n\n\ncheck(Solution().tupleSameProduct)"}
coding
104
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given two string arrays, queries and dictionary. All words in each array comprise of lowercase English letters and have the same length. In one edit you can take a word from queries, and change any letter in i...
{"functional": "def check(candidate):\n assert candidate(queries = [\"word\",\"note\",\"ants\",\"wood\"], dictionary = [\"wood\",\"joke\",\"moat\"]) == [\"word\",\"note\",\"wood\"]\n assert candidate(queries = [\"yes\"], dictionary = [\"not\"]) == []\n\n\ncheck(Solution().twoEditWords)"}
coding
159
Solve the programming task below in a Python markdown code block. If `a = 1, b = 2, c = 3 ... z = 26` Then `l + o + v + e = 54` and `f + r + i + e + n + d + s + h + i + p = 108` So `friendship` is twice stronger than `love` :-) The input will always be in lowercase and never be empty. Also feel free to reuse/extend...
{"functional": "_inputs = [['attitude'], ['friends'], ['family'], ['selfness'], ['knowledge']]\n_outputs = [[100], [75], [66], [99], [96]]\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, ...
coding
126
Solve the programming task below in a Python markdown code block. Monk has magical powers, by which he can compare any part of the strings and figure out if they're equal. His magical powers are faster than a super computer even. So, to prove his worth, he's given a string and he has to answer multiple queries based on...
{"inputs": ["qrstqrstqrstqrstqrstqrstqrstqrstqrstqrstqrstqrstqrstqrstqrstqrstqrstqrstqrstqrstqrstqrstqrstqrstqrstqrstqrstqrstqrstqrstqrstqrstqrstqrstqrstqrstqrstqrstqrstqrstqrstqrstqrstqrstqrstqrstqrstqrstqrstqrstqrstqrstqrstqrstqrstqrstqrstqrstqrstqrstqrstqrstqrstqrstqrstqrstqrstqrstqrstqrstqrstqrstqrstqrstqrstqrstqrs...
coding
463
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given two strings s and t of lengths m and n respectively, return the minimum window substring of s such that every character in t (including duplicates) is included in the window. If there is no such substring, retur...
{"functional": "def check(candidate):\n assert candidate(s = \"ADOBECODEBANC\", t = \"ABC\") == \"BANC\"\n assert candidate(s = \"a\", t = \"a\") == \"a\"\n\n\ncheck(Solution().minWindow)"}
coding
113
Solve the programming task below in a Python markdown code block. Two friends Chef and Chefina are currently on floors A and B respectively. They hear an announcement that prizes are being distributed on the ground floor and so decide to reach the ground floor as soon as possible. Chef can climb down X floors per min...
{"inputs": ["4\n2 2 2 2\n4 2 1 5\n3 2 4 1\n3 2 2 1\n"], "outputs": ["Both\nChefina\nChef\nChef"]}
coding
694
Please solve the programming task below using a self-contained code snippet in a markdown code block. A string is good if there are no repeated characters. Given a string s​​​​​, return the number of good substrings of length three in s​​​​​​. Note that if there are multiple occurrences of the same substring, every oc...
{"functional": "def check(candidate):\n assert candidate(s = \"xyzzaz\") == 1\n assert candidate(s = \"aababcabc\") == 4\n\n\ncheck(Solution().countGoodSubstrings)"}
coding
114
Solve the programming task below in a Python markdown code block. Chef is currently standing at stair 0 and he wants to reach stair numbered X. Chef can climb either Y steps or 1 step in one move. Find the minimum number of moves required by him to reach exactly the stair numbered X. ------ Input Format ------ - ...
{"inputs": ["4\n4 2\n8 3\n3 4\n2 1\n"], "outputs": ["2\n4\n3\n2\n"]}
coding
364
Solve the programming task below in a Python markdown code block. Imagine a triangle of numbers which follows this pattern: * Starting with the number "1", "1" is positioned at the top of the triangle. As this is the 1st row, it can only support a single number. * The 2nd row can support the next 2 numbers: "2" and ...
{"functional": "_inputs = [[1], [2], [3], [4], [15], [150], [100], [500], [1000], [10000]]\n_outputs = [[1], [5], [15], [34], [1695], [1687575], [500050], [62500250], [500000500], [500000005000]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclo...
coding
198
Solve the programming task below in a Python markdown code block. Vasya is currently at a car rental service, and he wants to reach cinema. The film he has bought a ticket for starts in t minutes. There is a straight road of length s from the service to the cinema. Let's introduce a coordinate system so that the car re...
{"inputs": ["1 1 2 1\n1 10\n1\n", "1 1 2 1\n1 10\n0\n", "1 1 2 1\n2 10\n1\n", "1 1 10 18\n5 6\n5\n", "1 1 10 18\n3 6\n5\n", "1 1 10 24\n5 6\n5\n", "2 2 10 18\n10 4\n20 6\n5 3\n", "3 1 8 10\n10 8\n5 7\n11 9\n3\n"], "outputs": ["-1\n", "-1\n", "-1\n", "5\n", "3\n", "5\n", "20\n", "10\n"]}
coding
750
Solve the programming task below in a Python markdown code block. Read problems statements in [Mandarin Chinese], [Russian], [Vietnamese] and [Bengali] as well. Ash is trying to get visa to Chefland. For the visa to be approved, he needs to satisfy the following three criteria: Solve at least $x_{1}$ problems on Codec...
{"inputs": ["4\n20 50 2100 1900 6 6\n50 20 1900 1900 5 5\n20 20 1900 1900 1 6\n27 27 1920 1920 3 3"], "outputs": ["NO\nNO\nNO\nYES"]}
coding
562
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a string s containing an out-of-order English representation of digits 0-9, return the digits in ascending order.   Please complete the following python code precisely: ```python class Solution: def original...
{"functional": "def check(candidate):\n assert candidate(s = \"owoztneoer\") == \"012\"\n assert candidate(s = \"fviefuro\") == \"45\"\n\n\ncheck(Solution().originalDigits)"}
coding
72
Solve the programming task below in a Python markdown code block. You are visiting a large electronics store to buy a refrigerator and a microwave. The store sells A kinds of refrigerators and B kinds of microwaves. The i-th refrigerator ( 1 \le i \le A ) is sold at a_i yen (the currency of Japan), and the j-th microw...
{"inputs": ["2 2 1\n3 1\n3 5\n2 2 2", "2 2 1\n3 2\n3 8\n2 2 2", "2 4 0\n2 1\n1 5\n1 2 2", "2 4 0\n2 1\n0 5\n1 2 2", "2 2 1\n2 1\n3 5\n2 2 2", "2 2 1\n2 1\n3 8\n2 2 2", "2 2 1\n3 1\n3 8\n2 2 2", "2 4 1\n2 1\n3 5\n2 2 2"], "outputs": ["4\n", "5\n", "2\n", "1\n", "4\n", "4\n", "4\n", "4\n"]}
coding
432
Solve the programming task below in a Python markdown code block. After lessons Nastya decided to read a book. The book contains $n$ chapters, going one after another, so that one page of the book belongs to exactly one chapter and each chapter contains at least one page. Yesterday evening Nastya did not manage to fin...
{"inputs": ["1\n1 7\n4\n", "1\n1 2\n1\n", "1\n1 7\n7\n", "1\n1 1\n1\n", "1\n1 7\n1\n", "1\n1 5\n1\n", "1\n1 5\n1\n", "1\n1 2\n1\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n"]}
coding
602
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an array nums of size n, return the majority element. The majority element is the element that appears more than ⌊n / 2⌋ times. You may assume that the majority element always exists in the array.   Please compl...
{"functional": "def check(candidate):\n assert candidate(nums = [3,2,3]) == 3\n assert candidate(nums = [2,2,1,1,1,2,2]) == 2\n\n\ncheck(Solution().majorityElement)"}
coding
94
Solve the programming task below in a Python markdown code block. Create a function that returns an array containing the first `l` digits from the `n`th diagonal of [Pascal's triangle](https://en.wikipedia.org/wiki/Pascal's_triangle). `n = 0` should generate the first diagonal of the triangle (the 'ones'). The first n...
{"functional": "_inputs = [[0, 10], [1, 10], [2, 10], [3, 10], [4, 10], [10, 0], [100, 6]]\n_outputs = [[[1, 1, 1, 1, 1, 1, 1, 1, 1, 1]], [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]], [[1, 3, 6, 10, 15, 21, 28, 36, 45, 55]], [[1, 4, 10, 20, 35, 56, 84, 120, 165, 220]], [[1, 5, 15, 35, 70, 126, 210, 330, 495, 715]], [[]], [[1, 101...
coding
138
Solve the programming task below in a Python markdown code block. Integers in Python can be as big as the bytes in your machine's memory. There is no limit in size as there is: $2^{31}-1$ (c++ int) or $2^{63}-1$ (C++ long long int). As we know, the result of $a^{b}$ grows really fast with increasing $\boldsymbol{b...
{"inputs": ["9\n29\n7\n27\n"], "outputs": ["4710194409608608369201743232 \n"]}
coding
361
Solve the programming task below in a Python markdown code block. Andrewid the Android is a galaxy-famous detective. He is now investigating a case of frauds who make fake copies of the famous Stolp's gears, puzzles that are as famous as the Rubik's cube once was. Its most important components are a button and a line ...
{"inputs": ["1\n0\n", "1\n0\n", "2\n1 0\n", "2\n0 0\n", "2\n0 1\n", "2\n1 0\n", "2\n1 1\n", "2\n1 1\n"], "outputs": ["Yes\n", "Yes\n", "Yes\n", "No\n", "Yes\n", "Yes\n", "No\n", "No\n"]}
coding
503
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 whose length is a power of 2. Apply the following algorithm on nums: Let n be the length of nums. If n == 1, end the process. Otherwise, create a new 0-indexed integer arr...
{"functional": "def check(candidate):\n assert candidate(nums = [1,3,5,2,4,8,2,2]) == 1\n assert candidate(nums = [3]) == 3\n\n\ncheck(Solution().minMaxGame)"}
coding
231
Solve the programming task below in a Python markdown code block. Little Walter likes playing with his toy scales. He has $N$ types of weights. The $i^{\mbox{th}}$ weight type has weight $a_i$. There are infinitely many weights of each type. Recently, Walter defined a function, $F(X)$, denoting the number of different...
{"inputs": ["3\n1 2 3\n1 6\n"], "outputs": ["22\n"]}
coding
567
Solve the programming task below in a Python markdown code block. Dreamoon likes sequences very much. So he created a problem about the sequence that you can't find in OEIS: You are given two integers d, m, find the number of arrays a, satisfying the following constraints: * The length of a is n, n ≥ 1 * 1 ≤ a_...
{"inputs": ["10\n1 1000000000\n2 146085669\n9 805629\n4 9999997\n5 999996\n6 99995\n9 18320\n8 993\n9 157\n7 2\n", "10\n1 1000000000\n2 999999999\n3 99999998\n4 9999997\n5 56682\n9 99995\n5 18320\n8 993\n9 92\n7 1\n", "10\n1 1000000000\n2 146085669\n6 805629\n4 9999997\n5 999996\n6 99995\n9 18320\n8 993\n9 157\n7 2\n",...
coding
404
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given two 0-indexed arrays, nums1 and nums2, consisting of non-negative integers. There exists another array, nums3, which contains the bitwise XOR of all pairings of integers between nums1 and nums2 (every in...
{"functional": "def check(candidate):\n assert candidate(nums1 = [2,1,3], nums2 = [10,2,5,0]) == 13\n assert candidate(nums1 = [1,2], nums2 = [3,4]) == 0\n\n\ncheck(Solution().xorAllNums)"}
coding
132
Solve the programming task below in a Python markdown code block. Given a sequence of $n$ numbers, $D=(d_1,d_2,\ldots,d_n)$, what's the maximum size of a subsequence of $\mbox{D}$ in which every pair is a nice pair? The pair $(a,b)$ is a nice pair iff at least one of the following condition holds. The parity of the...
{"inputs": ["4\n2 3 6 8\n"], "outputs": ["3\n"]}
coding
491
Solve the programming task below in a Python markdown code block. You have a tree consisting of n vertices. You want to color each vertex of the tree in one of the k colors such that for any pair of vertices having same color, all the vertices belonging to the path joining them should also have same color. In other wor...
{"inputs": ["3\n3 2\n1 2\n2 3\n3 1\n1 2\n2 3\n4 3\n1 2\n2 3\n2 4"], "outputs": ["6\n1\n39"]}
coding
532
Solve the programming task below in a Python markdown code block. When new students come to the Specialized Educational and Scientific Centre (SESC) they need to start many things from the beginning. Sometimes the teachers say (not always unfairly) that we cannot even count. So our teachers decided to teach us arithmet...
{"inputs": ["|+|=|\n", "|+|=|\n", "||+|=|\n", "|+||=|\n", "|+|=||\n", "|+||=|\n", "||+|=|\n", "|+||=|\n"], "outputs": ["Impossible\n", "Impossible\n", "|+|=||\n", "|+|=||\n", "|+|=||\n", "|+|=||\n", "|+|=||\n", "|+|=||\n"]}
coding
534
Solve the programming task below in a Python markdown code block. The Holmes children are fighting over who amongst them is the cleverest. Mycroft asked Sherlock and Eurus to find value of f(n), where f(1) = 1 and for n ≥ 2, f(n) is the number of distinct ordered positive integer pairs (x, y) that satisfy x + y = n an...
{"inputs": ["7 1\n", "7 1\n", "10 2\n", "10 2\n", "961 2\n", "1 100\n", "961 2\n", "1 100\n"], "outputs": ["6", "6", "4", "4", "930", "1", "930", "1"]}
coding
602
Solve the programming task below in a Python markdown code block. Today Hayato came home from school with homework. In the assignment, Hayato was given an array $a$ of length $n$. The task was to find $3$ numbers in this array whose sum is odd. At school, he claimed that there are such $3$ numbers, but Hayato was not ...
{"inputs": ["6\n3\n1 1 1\n4\n1 1 2 2\n3\n1 2 3\n5\n1 4 5 1 2\n4\n2 6 2 4\n5\n5 6 3 2 1\n"], "outputs": ["YES\n1 2 3\nYES\n3 4 1\nNO\nYES\n1 3 4\nNO\nYES\n1 3 5\n"]}
coding
638
Solve the programming task below in a Python markdown code block. Alex is attending a Halloween party with his girlfriend, Silvia. At the party, Silvia spots the corner of an infinite chocolate bar (two dimensional, infinitely long in width and length). If the chocolate can be served only as 1 x 1 sized pieces and A...
{"inputs": ["4\n5\n6\n7\n8\n"], "outputs": ["6\n9\n12\n16\n"]}
coding
329
Solve the programming task below in a Python markdown code block. Chef loves to play with arrays by himself. Today, he has an array A consisting of N distinct integers. He wants to perform the following operation on his array A. - Select a pair of adjacent integers and remove the larger one of these two. This decrease...
{"inputs": ["2\n2\n3 4\n3\n4 2 5", "2\n2\n3 4\n3\n4 2 9", "2\n2\n3 4\n3\n0 2 5", "2\n2\n0 4\n3\n4 0 9", "2\n2\n0 4\n3\n7 2 9", "2\n2\n0 4\n3\n4 1 9", "2\n2\n1 4\n3\n4 2 9", "2\n2\n1 4\n3\n3 0 4"], "outputs": ["3\n4", "3\n4\n", "3\n0\n", "0\n0\n", "0\n4\n", "0\n2\n", "1\n4\n", "1\n0\n"]}
coding
361
Please solve the programming task below using a self-contained code snippet in a markdown code block. There are n people, each person has a unique id between 0 and n-1. Given the arrays watchedVideos and friends, where watchedVideos[i] and friends[i] contain the list of watched videos and the list of friends respectiv...
{"functional": "def check(candidate):\n assert candidate(watchedVideos = [[\"A\",\"B\"],[\"C\"],[\"B\",\"C\"],[\"D\"]], friends = [[1,2],[0,3],[0,3],[1,2]], id = 0, level = 1) == [\"B\",\"C\"] \n assert candidate(watchedVideos = [[\"A\",\"B\"],[\"C\"],[\"B\",\"C\"],[\"D\"]], friends = [[1,2],[0,3],[0,3],[1,2]], i...
coding
226
Solve the programming task below in a Python markdown code block. One day, at the "Russian Code Cup" event it was decided to play football as an out of competition event. All participants was divided into n teams and played several matches, two teams could not play against each other more than once. The appointed Judg...
{"inputs": ["3 1\n", "7 3\n", "4 1\n", "5 2\n", "5 2\n", "1 1\n", "2 1\n", "3 1\n"], "outputs": ["3\n1 2\n2 3\n3 1\n", "21\n1 2\n1 3\n1 4\n2 3\n2 4\n2 5\n3 4\n3 5\n3 6\n4 5\n4 6\n4 7\n5 6\n5 7\n5 1\n6 7\n6 1\n6 2\n7 1\n7 2\n7 3\n", "4\n1 2\n2 3\n3 4\n4 1\n", "10\n1 2\n1 3\n2 3\n2 4\n3 4\n3 5\n4 5\n4 1\n5 1\n5 2\n", "10...
coding
406
Solve the programming task below in a Python markdown code block. Mr. Bill is shopping at the store. There are some coins in his wallet (10-yen coins, 50-yen coins, 100-yen coins, 500-yen coins), but he is now trying to consume as much of this coin as possible. In other words, by paying for the goods with an appropriat...
{"inputs": ["160\n1 0 1 2\n4\n1 0 9 0\n0", "160\n2 0 4 1\n83\n1 0 4 5\n0", "160\n1 1 4 0\n46\n2 0 7 9\n0", "160\n2 2 6 1\n86\n1 0 4 5\n0", "160\n0 1 2 0\n5\n0 1 1 18\n0", "160\n0 0 0 2\n4\n1 0 14 0\n0", "160\n0 0 0 1\n8\n0 0 14 0\n0", "160\n0 0 0 1\n8\n0 0 17 0\n0"], "outputs": ["10 1\n500 1\n\n10 1\n100 5\n", "10 1\n1...
coding
620
Solve the programming task below in a Python markdown code block. Two children are playing tag on a number line. (In the game of tag, the child called "it" tries to catch the other child.) The child who is "it" is now at coordinate A, and he can travel the distance of V per second. The other child is now at coordinate ...
{"inputs": ["1 0\n3 3\n3", "1 3\n3 2\n3", "1 2\n3 0\n3", "1 0\n3 6\n3", "0 3\n3 2\n3", "1 2\n5 0\n3", "1 0\n3 8\n3", "0 2\n5 0\n3"], "outputs": ["NO\n", "YES\n", "YES\n", "NO\n", "YES\n", "YES\n", "NO\n", "YES\n"]}
coding
287
Solve the programming task below in a Python markdown code block. The weather in Takahashi's town changes day by day, in the following cycle: Sunny, Cloudy, Rainy, Sunny, Cloudy, Rainy, ... Given is a string S representing the weather in the town today. Predict the weather tomorrow. Constraints * S is `Sunny`, `Clou...
{"inputs": ["Rainy", "Sunny"], "outputs": ["Sunny", "Cloudy"]}
coding
141
Solve the programming task below in a Python markdown code block. There are N pieces of sushi. Each piece has two parameters: "kind of topping" t_i and "deliciousness" d_i. You are choosing K among these N pieces to eat. Your "satisfaction" here will be calculated as follows: - The satisfaction is the sum of the "base...
{"inputs": ["1 1\n1 11\n", "4 3\n3 4\n2 8\n2 9\n3 1\n", "5 3\n1 9\n1 0\n2 6\n2 5\n3 1", "5 3\n1 9\n1 0\n2 6\n2 5\n3 2", "5 4\n1 9\n1 7\n2 6\n2 5\n3 1", "5 3\n1 3\n1 7\n2 6\n2 5\n3 1", "5 2\n1 9\n1 0\n2 6\n2 5\n3 2", "5 4\n2 9\n1 7\n2 3\n2 5\n3 1"], "outputs": ["12\n", "25\n", "25\n", "26\n", "32\n", "23\n", "19\n", "31...
coding
348
Solve the programming task below in a Python markdown code block. You're given Q queries of the form (L, R). For each query you have to find the number of such x that L ≤ x ≤ R and there exist integer numbers a > 0, p > 1 such that x = a^{p}. -----Input----- The first line contains the number of queries Q (1 ≤ Q ≤...
{"inputs": ["6\n1 4\n9 9\n5 7\n12 29\n83 591\n1 1000000\n", "6\n1 2\n9 9\n5 7\n12 29\n83 591\n1 1000000\n", "6\n2 2\n9 9\n5 7\n12 29\n83 591\n1 1000000\n", "6\n2 2\n9 9\n3 7\n12 29\n83 591\n1 1000000\n", "6\n2 2\n9 9\n1 7\n12 29\n83 591\n1 1000000\n", "6\n4 2\n9 9\n2 7\n12 29\n83 301\n1 1000000\n", "6\n1 4\n9 9\n5 7\n1...
coding
206
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given n balloons, indexed from 0 to n - 1. Each balloon is painted with a number on it represented by an array nums. You are asked to burst all the balloons. If you burst the ith balloon, you will get nums[i -...
{"functional": "def check(candidate):\n assert candidate(nums = [3,1,5,8]) == 167\n assert candidate(nums = [1,5]) == 10\n\n\ncheck(Solution().maxCoins)"}
coding
165
Solve the programming task below in a Python markdown code block. There are a total of A + B cats and dogs. Among them, A are known to be cats, but the remaining B are not known to be either cats or dogs. Determine if it is possible that there are exactly X cats among these A + B animals. -----Constraints----- - 1 \l...
{"inputs": ["2 0 6", "2 5 4", "5 3 3", "4 5 4", "2 3 3", "2 0 0", "5 5 4", "2 3 5"], "outputs": ["NO\n", "YES\n", "NO\n", "YES\n", "YES\n", "NO\n", "NO\n", "YES\n"]}
coding
209
Solve the programming task below in a Python markdown code block. You are running through a rectangular field. This field can be represented as a matrix with 3 rows and m columns. (i, j) denotes a cell belonging to i-th row and j-th column. You start in (2, 1) and have to end your path in (2, m). From the cell (i, j) ...
{"inputs": ["2 5\n1 2 4\n2 2 3\n", "2 5\n1 3 4\n2 2 3\n", "50 100\n1 71 96\n2 34 52\n2 16 95\n1 54 55\n1 65 85\n1 76 92\n2 19 91\n1 26 43\n2 83 95\n2 70 88\n2 67 88\n1 9 75\n2 4 50\n2 9 11\n1 77 92\n1 28 58\n1 23 72\n1 24 75\n2 12 5\n1 54 55\n2 45 93\n1 88 93\n2 98 99\n1 40 58\n3 40 42\n1 16 61\n2 94 94\n1 82 86\n2 81 ...
coding
417
Solve the programming task below in a Python markdown code block. You are given integers N and K. Find the number of triples (a,b,c) of positive integers not greater than N such that a+b,b+c and c+a are all multiples of K. The order of a,b,c does matter, and some of them can be the same. -----Constraints----- - 1 \le...
{"inputs": ["3 2\n", "5 3\n", "1 1\n", "10003 8\n", "200000 1\n", "200000 2\n", "200000 3\n", "1 200000\n"], "outputs": ["9\n", "1\n", "1\n", "3906250000\n", "8000000000000000\n", "2000000000000000\n", "296287407496296\n", "0\n"]}
coding
229
Solve the programming task below in a Python markdown code block. Is every value in the array an array? This should only test the second array dimension of the array. The values of the nested arrays don't have to be arrays. Examples: ```python [[1],[2]] => true ['1','2'] => false [{1:1},{2:2}] => false ``` Also fee...
{"functional": "_inputs = [[[]], [[['string']]], [[[], {}]], [[[1], [2], [3]]], [['A', 'R', 'R', 'A', 'Y']]]\n_outputs = [[True], [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=to...
coding
104
Solve the programming task below in a Python markdown code block. Billy investigates the question of applying greedy algorithm to different spheres of life. At the moment he is studying the application of greedy algorithm to the problem about change. There is an amount of n coins of different face values, and the coins...
{"inputs": ["1\n1\n", "2\n2 1\n", "2\n4 1\n", "3\n3 2 1\n", "3\n4 2 1\n", "3\n4 3 1\n", "4\n5 4 3 1\n", "3\n25 15 1\n"], "outputs": ["-1\n", "-1\n", "-1\n", "-1\n", "-1\n", "6\n", "7\n", "30\n"]}
coding
400
Solve the programming task below in a Python markdown code block. Unlucky year in Berland is such a year that its number n can be represented as n = x^{a} + y^{b}, where a and b are non-negative integer numbers. For example, if x = 2 and y = 3 then the years 4 and 17 are unlucky (4 = 2^0 + 3^1, 17 = 2^3 + 3^2 = 2^4 +...
{"inputs": ["2 3 3 5\n", "3 2 6 7\n", "3 3 1 1\n", "4 4 1 1\n", "2 2 1 1\n", "2 3 1 1\n", "3 2 6 7\n", "4 4 1 1\n"], "outputs": ["0\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1", "1"]}
coding
415
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given two strings firstString and secondString that are 0-indexed and consist only of lowercase English letters. Count the number of index quadruples (i,j,a,b) that satisfy the following conditions: 0 <= i <=...
{"functional": "def check(candidate):\n assert candidate(firstString = \"abcd\", secondString = \"bccda\") == 1\n assert candidate(firstString = \"ab\", secondString = \"cd\") == 0\n\n\ncheck(Solution().countQuadruples)"}
coding
189
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin Chinese here ------ Problem Statement ------ Lira is a little girl form Bytenicut, a small and cozy village located in the country of Byteland.  As the village is located on a somewhat hidden and isolated area, li...
{"inputs": ["2\n0 0 0 100 100 0\n1 1 1 5 5 1", "2\n0 0 0 100 100 0\n1 2 1 5 5 1", "2\n0 0 0 111 000 1\n1 2 0 3 2 1", "2\n0 0 0 100 100 0\n1 2 1 5 5 2", "2\n0 0 0 100 100 0\n1 2 1 5 9 2", "2\n0 0 0 100 100 0\n1 2 1 5 9 1", "2\n0 0 0 100 100 0\n1 2 1 7 9 1", "2\n0 0 0 100 100 0\n1 1 0 5 5 1"], "outputs": ["2 1", "2 1\n",...
coding
474
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a 0-indexed array of n integers differences, which describes the differences between each pair of consecutive integers of a hidden sequence of length (n + 1). More formally, call the hidden sequence hidd...
{"functional": "def check(candidate):\n assert candidate(differences = [1,-3,4], lower = 1, upper = 6) == 2\n assert candidate(differences = [3,-4,5,1,-2], lower = -4, upper = 5) == 4\n assert candidate(differences = [4,-7,2], lower = 3, upper = 6) == 0\n\n\ncheck(Solution().numberOfArrays)"}
coding
294
Solve the programming task below in a Python markdown code block. # Background My pet bridge-maker ants are marching across a terrain from left to right. If they encounter a gap, the first one stops and then next one climbs over him, then the next, and the next, until a bridge is formed across the gap. What clever ...
{"functional": "_inputs = [['GFEDCBA', '-----------------------'], ['GFEDCBA', '------------...-----------'], ['GFEDCBA', '------------.....---------'], ['GFEDCBA', '------.....------.....---------'], ['GFEDCBA', '------------...-----..----'], ['CBA', '--.--.---'], ['GFEDCBA', '------....-.---'], ['EDCBA', '--..---...-...
coding
480
Solve the programming task below in a Python markdown code block. Jack is working on his jumping skills recently. Currently he's located at point zero of the number line. He would like to get to the point x. In order to train, he has decided that he'll first jump by only one unit, and each subsequent jump will be exact...
{"inputs": ["3\n", "1\n", "2\n", "0\n", "6\n", "-2\n", "-5\n", "-8\n"], "outputs": ["2\n", "1\n", "3\n", "0\n", "3\n", "3\n", "5\n", "4\n"]}
coding
163
Solve the programming task below in a Python markdown code block. You are given a string $s$ consisting of $n$ lowercase Latin letters. Polycarp wants to remove exactly $k$ characters ($k \le n$) from the string $s$. Polycarp uses the following algorithm $k$ times: if there is at least one letter 'a', remove the lef...
{"inputs": ["1 1\nu\n", "1 1\nu\n", "2 1\nzz\n", "2 1\nzz\n", "4 3\nhack\n", "4 3\nzzzz\n", "4 3\nhack\n", "4 3\nzzzz\n"], "outputs": ["\n", "\n", "z\n", "z\n", "k\n", "z\n", "k\n", "z\n"]}
coding
365
Solve the programming task below in a Python markdown code block. # Task Given an array of roots of a polynomial equation, you should reconstruct this equation. ___ ## Output details: * If the power equals `1`, omit it: `x = 0` instead of `x^1 = 0` * If the power equals `0`, omit the `x`: `x - 2 = 0` instead of `x ...
{"functional": "_inputs = [[[0]], [[0, 0]], [[-1]], [[1]], [[1, -1]], [[0, -2, -3]], [[0, 2, 3]], [[1, 2, 3, 4, 5]]]\n_outputs = [['x = 0'], ['x^2 = 0'], ['x + 1 = 0'], ['x - 1 = 0'], ['x^2 - 1 = 0'], ['x^3 + 5x^2 + 6x = 0'], ['x^3 - 5x^2 + 6x = 0'], ['x^5 - 15x^4 + 85x^3 - 225x^2 + 274x - 120 = 0']]\nimport math\ndef ...
coding
472
Solve the programming task below in a Python markdown code block. This problem takes its name by arguably the most important event in the life of the ancient historian Josephus: according to his tale, he and his 40 soldiers were trapped in a cave by the Romans during a siege. Refusing to surrender to the enemy, they i...
{"functional": "_inputs = [[[1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 1], [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 2], [['C', 'o', 'd', 'e', 'W', 'a', 'r', 's'], 4], [['C', 0, 'd', 3, 'W', 4, 'r', 5], 4], [[1, 2, 3, 4, 5, 6, 7], 3], [[], 3], [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 2...
coding
607
Solve the programming task below in a Python markdown code block. Chef has a binary string S of length N. In one operation, Chef can: Select two indices i and j (1 ≤ i, j ≤ N, i \ne j) and flip S_{i} and S_{j}. (i.e. change 0 to 1 and 1 to 0) For example, if S = 10010 and chef applys operation on i = 1 and j = 3 the...
{"inputs": ["3\n6\n101011\n2\n01\n7\n1110000\n"], "outputs": ["YES\nNO\nYES\n"]}
coding
637
Solve the programming task below in a Python markdown code block. You have two strings, $a$ and $\boldsymbol{b}$. Find a string, $\boldsymbol{\mathrm{~S~}}$, such that: $\boldsymbol{\mathrm{~S~}}$ can be expressed as $s=s_{a}+s_{b}$ where $\boldsymbol{s_{a}}$ is a non-empty substring of $a$ and $s_{b}$ is a non-empty ...
{"inputs": ["3\nbac\nbac\nabc\ndef\njdfh\nfds\n"], "outputs": ["aba\n-1\ndfhfd\n"]}
coding
625
Please solve the programming task below using a self-contained code snippet in a markdown code block. There is an undirected connected tree with n nodes labeled from 1 to n and n - 1 edges. You are given the integer n. The parent node of a node with a label v is the node with the label floor (v / 2). The root of the t...
{"functional": "def check(candidate):\n assert candidate(n = 5 , queries = [1,2,5]) == 3\n assert candidate(n = 3, queries = [2,3,3]) == 1\n\n\ncheck(Solution().numberOfNodes)"}
coding
285