problem
stringlengths
14
4.09k
solution
stringlengths
1
802k
task_type
stringclasses
3 values
problem_tokens
int64
5
895
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an integer array of even length arr, return true if it is possible to reorder arr such that arr[2 * i + 1] = 2 * arr[2 * i] for every 0 <= i < len(arr) / 2, or false otherwise.   Please complete the following py...
{"functional": "def check(candidate):\n assert candidate(arr = [3,1,3,6]) == False\n assert candidate(arr = [2,1,2,6]) == False\n assert candidate(arr = [4,-2,2,-4]) == True\n\n\ncheck(Solution().canReorderDoubled)"}
coding
109
Solve the programming task below in a Python markdown code block. One day, Yuhao came across a problem about checking if some bracket sequences are correct bracket sequences. A bracket sequence is any non-empty sequence of opening and closing parentheses. A bracket sequence is called a correct bracket sequence if it's...
{"inputs": ["3\n)\n(\n)\n", "3\n)\n(\n)\n", "3\n(\n(\n)\n", "2\n(())\n()\n", "2\n(((\n)))\n", "2\n(((\n)))\n", "2\n((()\n()\n", "2\n)(()\n()\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "0\n", "0\n"]}
coding
447
Solve the programming task below in a Python markdown code block. # How many ways can you make the sum of a number? From wikipedia: https://en.wikipedia.org/wiki/Partition_(number_theory)# >In number theory and combinatorics, a partition of a positive integer *n*, also called an *integer partition*, is a way of writi...
{"functional": "_inputs = [[1], [2], [3], [4], [5], [20], [30], [40], [43], [60], [70], [90], [200], [275]]\n_outputs = [[1], [2], [3], [5], [7], [627], [5604], [37338], [63261], [966467], [4087968], [56634173], [3972999029388], [1520980492851175]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float...
coding
426
Solve the programming task below in a Python markdown code block. Initially, you have the array $a$ consisting of one element $1$ ($a = [1]$). In one move, you can do one of the following things: Increase some (single) element of $a$ by $1$ (choose some $i$ from $1$ to the current length of $a$ and increase $a_i$ b...
{"inputs": ["5\n2\n2\n18\n2\n1000001010\n", "5\n1\n4\n9\n129\n1000001000\n", "5\n2\n2\n16\n13\n1000000000\n", "5\n2\n13\n78\n7\n1000001100\n", "5\n2\n2\n18\n13\n1000001000\n", "5\n2\n7\n9\n284\n1000001000\n", "5\n1\n2\n9\n129\n1000001000\n", "5\n1\n4\n9\n110\n1000001010\n"], "outputs": ["1\n1\n7\n1\n63244\n", "0\n2\n4\...
coding
518
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. There exists an array arr of length nums.length, where arr[i] is the sum of |i - j| over all j such that nums[j] == nums[i] and j != i. If there is no such j, set arr[i] t...
{"functional": "def check(candidate):\n assert candidate(nums = [1,3,1,1,2]) == [5,0,3,4,0]\n assert candidate(nums = [0,5,3]) == [0,0,0]\n\n\ncheck(Solution().distance)"}
coding
121
Solve the programming task below in a Python markdown code block. Now I have a card with n numbers on it. Consider arranging some or all of these appropriately to make numbers. Find the number obtained by adding all the numbers created at this time. For example, if you have 1 and 2, you will get 4 numbers 1, 2, 12, 21...
{"inputs": ["2\n2\n2", "2\n2\n0", "2\n1\n0", "2\n2\n9", "2\n1\n9", "2\n0\n9", "2\n3\n9", "2\n2\n1"], "outputs": ["48\n", "22\n", "11\n", "132\n", "120\n", "99\n", "144\n", "36\n"]}
coding
366
Solve the programming task below in a Python markdown code block. The idea for this Kata came from 9gag today.[here](http://9gag.com/gag/amrb4r9) [screen]:("http://img-9gag-fun.9cache.com/photo/amrb4r9_700b.jpg") You'll have to translate a string to Pilot's alphabet (NATO phonetic alphabet) [wiki](https://en.wikipedi...
{"functional": "_inputs = [['If you can read'], ['Did not see that coming']]\n_outputs = [['India Foxtrot Yankee Oscar Uniform Charlie Alfa November Romeo Echo Alfa Delta'], ['Delta India Delta November Oscar Tango Sierra Echo Echo Tango Hotel Alfa Tango Charlie Oscar Mike India November Golf']]\nimport math\ndef _deep...
coding
263
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an integer array nums, find the subarray with the largest sum, and return its sum.   Please complete the following python code precisely: ```python class Solution: def maxSubArray(self, nums: List[int]) -> i...
{"functional": "def check(candidate):\n assert candidate(nums = [-2,1,-3,4,-1,2,1,-5,4]) == 6\n assert candidate(nums = [1]) == 1\n assert candidate(nums = [5,4,-1,7,8]) == 23\n\n\ncheck(Solution().maxSubArray)"}
coding
69
Solve the programming task below in a Python markdown code block. Let's introduce some definitions that will be needed later. Let $prime(x)$ be the set of prime divisors of $x$. For example, $prime(140) = \{ 2, 5, 7 \}$, $prime(169) = \{ 13 \}$. Let $g(x, p)$ be the maximum possible integer $p^k$ where $k$ is an inte...
{"inputs": ["2 1\n", "2 1\n", "10 2\n", "16 2\n", "15 2\n", "10 2\n", "9 188\n", "9 188\n"], "outputs": ["1\n", "1\n", "2\n", "2\n", "1\n", "2\n", "954137859\n", "954137859\n"]}
coding
677
Solve the programming task below in a Python markdown code block. Write a function that returns the index of the first occurence of the word "Wally". "Wally" must not be part of another word, but it can be directly followed by a punctuation mark. If no such "Wally" exists, return -1. Examples: "Wally" => 0 "Where...
{"functional": "_inputs = [[''], ['WAlly'], ['wAlly'], ['DWally'], ['.Wally'], ['Wallyd'], [\"wally mollyWally Wallybrolly 'Wally\"], ['Walley ,Wally -Wally ;Wally +Wally :Wally'], ['Walley Wally, Wally- Wally: Wally+ Wally:'], ['12Wally Wally01 W.ally'], [\"Where's Waldo\"], ['Wally'], ['Wally Wally'], ['W ally Wally'...
coding
174
Solve the programming task below in a Python markdown code block. Petya organized a strange birthday party. He invited $n$ friends and assigned an integer $k_i$ to the $i$-th of them. Now Petya would like to give a present to each of them. In the nearby shop there are $m$ unique presents available, the $j$-th present c...
{"inputs": ["1\n1 1\n1\n1\n", "1\n1 1\n1\n0\n", "1\n1 1\n1\n1\n", "2\n5 4\n2 3 4 3 2\n3 5 6 20\n5 5\n5 5 3 2 1\n7 40 90 160 250\n", "2\n5 4\n2 2 4 3 2\n3 5 6 20\n5 5\n5 5 3 2 1\n7 40 90 160 423\n", "2\n5 4\n2 4 4 1 2\n4 5 12 20\n5 5\n5 4 1 3 1\n7 40 90 91 160\n", "2\n5 4\n2 3 4 3 2\n3 5 9 20\n5 5\n5 5 3 2 1\n7 40 90 16...
coding
738
Solve the programming task below in a Python markdown code block. You are given sequence a_1, a_2, ..., a_{n} and m queries l_{j}, r_{j} (1 ≤ l_{j} ≤ r_{j} ≤ n). For each query you need to print the minimum distance between such pair of elements a_{x} and a_{y} (x ≠ y), that: both indexes of the elements lie within ra...
{"inputs": ["1 1\n1\n1 1\n", "1 1\n1\n1 1\n", "2 1\n1 1\n1 2\n", "2 1\n1 1\n1 1\n", "2 1\n1 1\n1 1\n", "2 1\n1 1\n1 2\n", "2 1\n1 2\n1 1\n", "2 1\n0 0\n1 2\n"], "outputs": ["-1\n", "-1\n", "1\n", "-1\n", "-1\n", "1\n", "-1\n", "1\n"]}
coding
419
Solve the programming task below in a Python markdown code block. Chef's brother likes to put words in Chef's mouth. Chef hates it about him of course. He has decided to become extremely careful about what he speaks. Fortunately, he knows how his brother transforms the words, that Chef uses. He has decided to use only ...
{"inputs": ["3\n1\n14\n45"], "outputs": ["26\n456976\n827063120"]}
coding
378
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given two groups of points where the first group has size1 points, the second group has size2 points, and size1 >= size2. The cost of the connection between any two points are given in an size1 x size2 matrix ...
{"functional": "def check(candidate):\n assert candidate(cost = [[15, 96], [36, 2]]) == 17\n assert candidate(cost = [[1, 3, 5], [4, 1, 1], [1, 5, 3]]) == 4\n assert candidate(cost = [[2, 5, 1], [3, 4, 7], [8, 1, 2], [6, 2, 4], [3, 8, 8]]) == 10\n\n\ncheck(Solution().connectTwoGroups)"}
coding
202
Solve the programming task below in a Python markdown code block. # Task Your task is to find the similarity of given sorted arrays `a` and `b`, which is defined as follows: you take the number of elements which are present in both arrays and divide it by the number of elements which are present in at least one ar...
{"functional": "_inputs = [[[1, 2, 3], [1, 2, 3]], [[1, 2, 3], [4, 5, 6]], [[1, 2, 4, 6, 7], [2, 3, 4, 7]], [[1, 2, 6, 8, 9], [0, 1, 4, 5, 6, 8, 9]], [[0, 1, 3, 4, 5, 6, 9, 14, 15, 16, 17, 18, 19], [1, 4, 10, 12, 13, 14, 15, 16]]]\n_outputs = [[1], [0], [0.5], [0.5], [0.3125]]\nimport math\ndef _deep_eq(a, b, tol=1e-5)...
coding
397
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin Chinese and Russian as well. Andrii is a great programmer. He recently managed to enter Ukrainian IOI team. His parents wanted to appreciate him and present him a DAG(Directed Acyclic Graph). His favourite TV show i...
{"inputs": ["3\n010\n000\n000"], "outputs": ["2\n1 3\n2 3"]}
coding
420
Solve the programming task below in a Python markdown code block. You are given an integer $k$. Find the largest integer $x$, where $1 \le x < k$, such that $x! + (x - 1)!^\dagger$ is a multiple of $^\ddagger$ $k$, or determine that no such $x$ exists. $^\dagger$ $y!$ denotes the factorial of $y$, which is defined rec...
{"inputs": ["4\n3\n6\n8\n10\n", "10\n595\n358\n784\n542\n361\n368\n108\n860\n116\n391\n", "100\n44\n71\n96\n94\n37\n44\n79\n61\n60\n35\n75\n51\n97\n90\n31\n30\n98\n15\n16\n11\n53\n17\n71\n75\n99\n57\n95\n12\n84\n74\n98\n73\n80\n47\n72\n36\n30\n63\n90\n78\n68\n35\n89\n44\n33\n81\n45\n56\n19\n93\n26\n94\n50\n43\n28\n92\n...
coding
447
Solve the programming task below in a Python markdown code block. Monocarp is playing a MMORPG. There are two commonly used types of currency in this MMORPG — gold coins and silver coins. Monocarp wants to buy a new weapon for his character, and that weapon costs $n$ silver coins. Unfortunately, right now, Monocarp has...
{"inputs": ["4\n100 25 30\n9999997 25 50\n52 50 48\n49 50 1\n"], "outputs": ["4\n400000\n1\n1\n"]}
coding
612
Solve the programming task below in a Python markdown code block. Polycarp calls an array dense if the greater of any two adjacent elements is not more than twice bigger than the smaller. More formally, for any $i$ ($1 \le i \le n-1$), this condition must be satisfied: $$\frac{\max(a[i], a[i+1])}{\min(a[i], a[i+1])} \l...
{"inputs": ["6\n4\n4 2 10 1\n2\n1 3\n2\n6 1\n3\n1 4 2\n5\n1 2 3 4 3\n12\n4 27 9 1 30 20 34 46 42 16 3 16\n", "6\n4\n4 2 10 1\n2\n1 3\n2\n6 1\n3\n2 4 2\n5\n1 2 3 4 3\n12\n4 27 9 1 30 20 34 46 42 16 3 16\n", "6\n4\n4 2 10 1\n2\n1 3\n2\n6 1\n3\n2 4 2\n5\n1 2 3 4 3\n12\n4 27 9 1 30 20 54 46 42 16 3 16\n", "6\n4\n4 3 10 1\n...
coding
688
Solve the programming task below in a Python markdown code block. Little Vasya had n boxes with balls in the room. The boxes stood in a row and were numbered with numbers from 1 to n from left to right. Once Vasya chose one of the boxes, let's assume that its number is i, took all balls out from it (it is guaranteed t...
{"inputs": ["3 3\n2 3 1\n", "3 3\n4 3 1\n", "3 3\n2 3 1\n", "4 4\n4 3 1 6\n", "4 4\n4 3 1 6\n", "5 2\n3 2 0 2 7\n", "5 4\n3 1 3 1 3\n", "5 4\n3 1 3 1 3\n"], "outputs": ["1 2 3 ", "3 2 3\n", "1 2 3\n", "3 2 5 4 ", "3 2 5 4\n", "2 1 4 1 6 ", "2 0 2 5 2 ", "2 0 2 5 2\n"]}
coding
737
Solve the programming task below in a Python markdown code block. A tennis tournament with n participants is running. The participants are playing by an olympic system, so the winners move on and the losers drop out. The tournament takes place in the following way (below, m is the number of the participants of the cur...
{"inputs": ["5 2 3\n", "8 2 4\n", "1 2 3\n", "1 3 4\n", "1 1 1\n", "1 2 5\n", "1 3 8\n", "1 3 5\n"], "outputs": ["20 15\n", "35 32\n", "0 3\n", "0 4\n", "0 1\n", "0 5\n", "0 8\n", "0 5\n"]}
coding
410
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an array rectangles where rectangles[i] = [li, wi] represents the ith rectangle of length li and width wi. You can cut the ith rectangle to form a square with a side length of k if both k <= li and k <= ...
{"functional": "def check(candidate):\n assert candidate(rectangles = [[5,8],[3,9],[5,12],[16,5]]) == 3\n assert candidate(rectangles = [[2,3],[3,7],[4,3],[3,7]]) == 3\n\n\ncheck(Solution().countGoodRectangles)"}
coding
174
Solve the programming task below in a Python markdown code block. There are one cat, $k$ mice, and one hole on a coordinate line. The cat is located at the point $0$, the hole is located at the point $n$. All mice are located between the cat and the hole: the $i$-th mouse is located at the point $x_i$ ($0 < x_i < n$). ...
{"inputs": ["3\n10 6\n8 7 5 4 9 4\n2 8\n1 1 1 1 1 1 1 1\n12 11\n1 2 3 4 5 6 7 8 9 10 11\n"], "outputs": ["3\n1\n4\n"]}
coding
591
Solve the programming task below in a Python markdown code block. Olga came to visit the twins Anna and Maria and saw that they have many cookies. The cookies are distributed into bags. As there are many cookies, Olga decided that it's no big deal if she steals a bag. However, she doesn't want the sisters to quarrel be...
{"inputs": ["1\n2\n", "1\n4\n", "1\n8\n", "1\n1\n", "2\n1 2\n", "2\n2 2\n", "2\n1 1\n", "2\n0 1\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "1\n", "2\n", "0\n", "1\n"]}
coding
436
Solve the programming task below in a Python markdown code block. Some country is populated by wizards. They want to organize a demonstration. There are n people living in the city, x of them are the wizards who will surely go to the demonstration. Other city people (n - x people) do not support the wizards and aren't...
{"inputs": ["1 1 1\n", "1 0 1\n", "3 1 69\n", "67 1 3\n", "2 1 69\n", "67 2 6\n", "67 2 9\n", "67 2 3\n"], "outputs": ["0\n", "1\n", "2\n", "2\n", "1\n", "3\n", "5\n", "1\n"]}
coding
505
Solve the programming task below in a Python markdown code block. Luke is daydreaming in Math class. He has a sheet of graph paper with $n$ rows and $m$ columns, and he imagines that there is an army base in each cell for a total of $n\cdot m$ bases. He wants to drop supplies at strategic points on the sheet, marking e...
{"inputs": ["2 2\n"], "outputs": ["1\n"]}
coding
402
Solve the programming task below in a Python markdown code block. Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. Consider the following function, where + denotes string concatenation. function BinaryConcatenation(integer X, integer Y): string binX = binary repr...
{"inputs": ["2\n2\n5 9\n7\n1 2 4 8 16 64 128"], "outputs": ["12\n127"]}
coding
624
Solve the programming task below in a Python markdown code block. Chef had an array A of length N such that 1 ≤ A_{i} ≤ N for all 1 ≤ i ≤ N. Chef constructed another binary array B of length N in the following manner: B_{i} = 1 if the frequency of element i in A is *odd*. B_{i} = 0 if the frequency of element i in A is...
{"inputs": ["3\n4\n0 1 0 1\n5\n1 1 1 1 0\n6\n1 1 1 1 1 1\n"], "outputs": ["YES\nNO\nYES\n"]}
coding
569
Solve the programming task below in a Python markdown code block. Takahashi will do a tap dance. The dance is described by a string S where each character is L, R, U, or D. These characters indicate the positions on which Takahashi should step. He will follow these instructions one by one in order, starting with the fi...
{"inputs": ["U\n", "L\n", "R\n", "D\n", "LLUD", "EULL", "EULM", "DULL"], "outputs": ["Yes\n", "No\n", "Yes\n", "Yes\n", "No\n", "No\n", "No\n", "No"]}
coding
320
Solve the programming task below in a Python markdown code block. Christy is interning at HackerRank. One day she has to distribute some chocolates to her colleagues. She is biased towards her friends and plans to give them more than the others. One of the program managers hears of this and tells her to make sure every...
{"inputs": ["1\n4\n2 2 3 7\n", "1\n3\n10 7 12\n"], "outputs": ["2\n", "3\n"]}
coding
687
Solve the programming task below in a Python markdown code block. After a very long time, the Chef has a vacation. Chef has planned for two trips during this vacation - one with his family and the other with his friends. The family trip will take X days and the trip with friends will take Y days. Currently, the dates a...
{"inputs": ["2\n1 2 4\n2 2 3"], "outputs": ["YES\nNO"]}
coding
399
Solve the programming task below in a Python markdown code block. The only difference between easy and hard versions is the length of the string. You are given a string $s$ and a string $t$, both consisting only of lowercase Latin letters. It is guaranteed that $t$ can be obtained from $s$ by removing some (possibly, ...
{"inputs": ["m\nm\n", "m\nm\n", "td\nt\n", "aa\na\n", "td\nt\n", "aa\na\n", "dt\nt\n", "ct\nt\n"], "outputs": ["0\n", "0\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n"]}
coding
481
Solve the programming task below in a Python markdown code block. There are two rival donut shops. The first shop sells donuts at retail: each donut costs a dollars. The second shop sells donuts only in bulk: box of b donuts costs c dollars. So if you want to buy x donuts from this shop, then you have to buy the smal...
{"inputs": ["1\n8042 1 2\n", "1\n9353 1 2\n", "1\n12313 2 2\n", "1\n12313 1 2\n", "1\n13806 1 2\n", "1\n165 82 165\n", "1\n165 82 173\n", "1\n165 165 165\n"], "outputs": ["-1 1\n", "-1 1\n", "-1 2\n", "-1 1\n", "-1 1\n", "-1 82\n", "1 82\n", "-1 165\n"]}
coding
762
Solve the programming task below in a Python markdown code block. You have a long stick, consisting of $m$ segments enumerated from $1$ to $m$. Each segment is $1$ centimeter long. Sadly, some segments are broken and need to be repaired. You have an infinitely long repair tape. You want to cut some pieces from the tap...
{"inputs": ["1 1 1\n1\n", "1 1 1\n1\n", "3 8 1\n2 6 7\n", "3 8 2\n4 6 8\n", "3 8 3\n1 2 6\n", "3 8 3\n1 2 6\n", "3 8 2\n4 6 8\n", "3 8 1\n2 6 7\n"], "outputs": ["1\n", "1", "6\n", "4\n", "3\n", "3", "4", "6"]}
coding
512
Solve the programming task below in a Python markdown code block. Given an array of numbers, return an array, with each member of input array rounded to a nearest number, divisible by 5. For example: ``` roundToFive([34.5, 56.2, 11, 13]); ``` should return ``` [35, 55, 10, 15] ``` ```if:python Roundings have to be do...
{"functional": "_inputs = [[[1, 5, 87, 45, 8, 8]], [[3, 56.2, 11, 13]], [[22.5, 544.9, 77.5]]]\n_outputs = [[[0, 5, 85, 45, 10, 10]], [[5, 55, 10, 15]], [[25, 545, 80]]]\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_...
coding
144
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an n x n integer matrix grid where each value grid[i][j] represents the elevation at that point (i, j). The rain starts to fall. At time t, the depth of the water everywhere is t. You can swim from a squ...
{"functional": "def check(candidate):\n assert candidate(grid = [[0,2],[1,3]]) == 3\n assert candidate(grid = [[0,1,2,3,4],[24,23,22,21,5],[12,13,14,15,16],[11,17,18,19,20],[10,9,8,7,6]]) == 16\n\n\ncheck(Solution().swimInWater)"}
coding
189
Solve the programming task below in a Python markdown code block. Read problem statements in [Russian] and [Mandarin Chinese]. Value of an array A of length L is defined as the sum of (A_{i} \oplus i) for all 0 ≤ i < L, where \oplus denotes [bitwise xor operation]. Note that array indices start from zero. You are gi...
{"inputs": ["3\n2 0\n2 1\n10 100"], "outputs": ["0\n6\n204600"]}
coding
658
Solve the programming task below in a Python markdown code block. One of the most important products of the R1 company is a popular @r1.com mail service. The R1 mailboxes receive and send millions of emails every day. Today, the online news thundered with terrible information. The R1 database crashed and almost no dat...
{"inputs": ["@\n", "a\n", ".\n", "0\n", "A\n", "`\n", "-\n", "?\n"], "outputs": [" 0", " 0", " 0", " ...
coding
556
Solve the programming task below in a Python markdown code block. The Little Elephant loves numbers. He has a positive integer x. The Little Elephant wants to find the number of positive integers d, such that d is the divisor of x, and x and d have at least one common (the same) digit in their decimal representations...
{"inputs": ["2\n", "3\n", "9\n", "4\n", "5\n", "6\n", "7\n", "8\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n"]}
coding
133
Solve the programming task below in a Python markdown code block. Given are positive integers A and B. Let us choose some number of positive common divisors of A and B. Here, any two of the chosen divisors must be coprime. At most, how many divisors can we choose?Definition of common divisor An integer d is said to be ...
{"inputs": ["1 1\n", "19 9", "31 9", "40 9", "66 9", "3 19", "3 38", "28 5"], "outputs": ["1\n", "1\n", "1\n", "1\n", "2\n", "1\n", "1\n", "1\n"]}
coding
312
Solve the programming task below in a Python markdown code block. It can be shown that any positive integer x can be uniquely represented as x = 1 + 2 + 4 + ... + 2^{k} - 1 + r, where k and r are integers, k ≥ 0, 0 < r ≤ 2^{k}. Let's call that representation prairie partition of x. For example, the prairie partitions ...
{"inputs": ["1\n1\n", "1\n2\n", "1\n2\n", "1\n1\n", "1\n3\n", "1\n6\n", "1\n4\n", "1\n5\n"], "outputs": ["1 \n", "-1\n", "-1\n", "1 \n", "-1\n", "-1\n", "-1\n", "-1\n"]}
coding
524
Solve the programming task below in a Python markdown code block. Chef has a sequence $A_{1}, A_{2}, \ldots, A_{N}$. For a positive integer $M$, sequence $B$ is defined as $B = A*M$ that is, appending $A$ exactly $M$ times. For example, If $A = [1, 2]$ and $M = 3$, then $B = A*M = [1, 2, 1, 2, 1, 2]$ You have to help ...
{"inputs": ["3\n2\n2 1\n2\n1 2\n5\n1 3 2 1 2"], "outputs": ["2\n1\n2"]}
coding
463
Solve the programming task below in a Python markdown code block. # Base reduction ## Input A positive integer: ``` 0 < n < 1000000000 ``` ## Output The end result of the base reduction. If it cannot be fully reduced (reduced down to a single-digit number), return -1. Assume that if 150 conversions from base 11 t...
{"functional": "_inputs = [[10], [5], [7], [7], [15]]\n_outputs = [[2], [5], [7], [7], [3]]\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): r...
coding
493
Solve the programming task below in a Python markdown code block. itertools.combinations_with_replacement(iterable, r) This tool returns $\textbf{r}$ length subsequences of elements from the input iterable allowing individual elements to be repeated more than once. Combinations are emitted in lexicographic sorted or...
{"inputs": ["HACK 2\n"], "outputs": ["AA\nAC\nAH\nAK\nCC\nCH\nCK\nHH\nHK\nKK\n"]}
coding
440
Solve the programming task below in a Python markdown code block. Mihai plans to watch a movie. He only likes palindromic movies, so he wants to skip some (possibly zero) scenes to make the remaining parts of the movie palindromic. You are given a list $s$ of $n$ non-empty strings of length at most $3$, representing t...
{"inputs": ["6\n5\nzx\nab\ncc\nzx\nba\n2\nab\nbad\n4\nco\ndef\norc\nes\n3\na\nb\nc\n3\nab\ncd\ncba\n2\nab\nab\n"], "outputs": ["YES\nNO\nNO\nYES\nYES\nNO\n"]}
coding
509
Solve the programming task below in a Python markdown code block. Sherlock is given $2$ square tiles, initially both of whose sides have length $\boldsymbol{l}$ placed in an $x-y$ plane. Initially, the bottom left corners of each square are at the origin and their sides are parallel to the axes. At $t=0$, both squa...
{"inputs": ["10 1 2\n2\n50\n100\n"], "outputs": ["4.1421\n0.0000\n"]}
coding
514
Solve the programming task below in a Python markdown code block. You are given two integers N \ ( N ≥ 2) and S. You have to construct an array A containing N integers such that: 0 ≤ A_{i} ≤ S for each 1 ≤ i ≤ N A_{1} + A_{2} + \ldots + A_{N} = S A_{1} \mathbin{\&} A_{2} \mathbin{\&} \ldots \mathbin{\&} A_{N} = 0, wher...
{"inputs": ["4\n2 7\n3 6\n5 21\n100 256455\n"], "outputs": ["4\n3\n5\n2570\n"]}
coding
497
Solve the programming task below in a Python markdown code block. Read problem statements in [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. It’s Chef's birthday. He and his twin have received $N$ gifts in total. The $i$-th gift has a price of $A_{i}$. Each twin wants to keep the most expensive gif...
{"inputs": ["3\n3 1\n1 3 2\n3 1\n3 1 3\n5 2\n5 1 3 2 4"], "outputs": ["3\n4\n8"]}
coding
592
Solve the programming task below in a Python markdown code block. A direced graph is strongly connected if every two nodes are reachable from each other. In a strongly connected component of a directed graph, every two nodes of the component are mutually reachable. Constraints * 1 ≤ |V| ≤ 10,000 * 0 ≤ |E| ≤ 30,000 * ...
{"inputs": ["5 6\n0 1\n1 0\n0 2\n2 4\n4 3\n3 2\n4\n0 1\n0 3\n2 3\n3 4", "5 6\n0 1\n1 0\n1 2\n2 4\n4 3\n3 2\n4\n0 1\n0 3\n2 0\n3 4", "5 6\n0 1\n1 0\n1 2\n2 4\n4 0\n3 2\n4\n0 1\n0 3\n2 0\n3 4", "5 6\n0 1\n1 0\n1 2\n2 4\n1 1\n3 2\n4\n0 1\n0 3\n2 0\n3 4", "7 6\n0 1\n1 0\n1 2\n2 4\n4 3\n3 2\n4\n1 2\n0 3\n2 3\n3 4", "5 6\n0 ...
coding
336
Solve the programming task below in a Python markdown code block. In a recent [breakthrough] in mathematics, the proof utilized a concept called Height. Consider a fraction \frac{a}{b}. Its Height is defined as the maximum of its numerator and denominator. So, for example, the Height of \frac{3}{19} would be 19, and t...
{"inputs": ["3 19\n", "27 4\n"], "outputs": ["19\n", "27\n"]}
coding
306
Solve the programming task below in a Python markdown code block. Berland shop sells $n$ kinds of juices. Each juice has its price $c_i$. Each juice includes some set of vitamins in it. There are three types of vitamins: vitamin "A", vitamin "B" and vitamin "C". Each juice can contain one, two or all three types of vit...
{"inputs": ["2\n9 C\n3 B\n", "1\n100 ABC\n", "2\n9 C\n3 B\n", "1\n100 ABC\n", "2\n9 AB\n4 BC\n", "2\n9 AB\n4 BC\n", "2\n2 AB\n4 BC\n", "2\n6 AB\n5 BA\n"], "outputs": ["-1\n", "100\n", "-1", "100", "13\n", "13", "6\n", "-1\n"]}
coding
543
Solve the programming task below in a Python markdown code block. Twin adventurers Rin and Len are searching for treasure in the Mirror Cave. The cave has two pairs of rooms, the Hall of Mirrors, and an expensive treasure lies behind the door of the room. For convenience, each of the two rooms is considered to have W ...
{"inputs": ["5 5\n%#... ...#%\n.#.#. .#.#.\n.#.#. .#.#.\n.#.#. .#.#.\n...#L R#...\n3 2\n.L. .R#\n%.. .&.\n4 1\nL.%. %..R\n0 0", "5 5\n%#... .%.#.\n.#.#. .#.#.\n.#.#. .#.#.\n.#.#. .#.#.\n...#L R#...\n3 2\n.L. .R#\n%.. .&.\n4 1\nL.%. %..R\n0 0", "5 5\n%#... ...#%\n.#.#. .#.#.\n.#.#. .#.#.\n.#.#. .#.#.\n...#L R#...\n3 2\n...
coding
729
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given the root node of a binary search tree (BST) and a value to insert into the tree. Return the root node of the BST after the insertion. It is guaranteed that the new value does not exist in the original BS...
{"functional": "def check(candidate):\n assert is_same_tree(candidate(root = tree_node([4,2,7,1,3]), val = 5), tree_node([4,2,7,1,3,5]))\n assert is_same_tree(candidate(root = tree_node([40,20,60,10,30,50,70]), val = 25), tree_node([40,20,60,10,30,50,70,None,None,25]))\n assert is_same_tree(candidate(root = tr...
coding
190
Solve the programming task below in a Python markdown code block. Alex is transitioning from website design to coding and wants to sharpen his skills with CodeWars. He can do ten kata in an hour, but when he makes a mistake, he must do pushups. These pushups really tire poor Alex out, so every time he does them they ...
{"functional": "_inputs = [[10, 120], [11, 120], [3, 45], [8, 120], [6, 60], [9, 180], [20, 120], [20, 125], [20, 130], [20, 135]]\n_outputs = [[3], [3], [2], [3], [2], [4], [0], [1], [1], [2]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose...
coding
164
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 a sequence of positive integers $A_{1}, A_{2}, \ldots, A_{K}$, let's define the number of inversions in it as the number of pairs of integers $(i...
{"inputs": ["4\n1\n1\n3\n3 2 1\n4\n4 3 2 1\n5 \n1 4 3 2 5"], "outputs": ["YES\nNO\nYES\nNO"]}
coding
603
Solve the programming task below in a Python markdown code block. Burenka came to kindergarden. This kindergarten is quite strange, so each kid there receives two fractions ($\frac{a}{b}$ and $\frac{c}{d}$) with integer numerators and denominators. Then children are commanded to play with their fractions. Burenka is a...
{"inputs": ["1\n1 2 3 4\n", "1\n2 1 4 3\n", "1\n1 2 3 1\n", "1\n5 8 1 2\n", "1\n3 1 5 1\n", "1\n2 3 3 5\n", "1\n5 3 4 3\n", "1\n3 5 1 7\n"], "outputs": ["2\n", "2\n", "1\n", "2\n", "2\n", "2\n", "2\n", "2\n"]}
coding
522
Solve the programming task below in a Python markdown code block. Since due to COVID 19, India has undergone a complete 21 day lockdown. So Amol was attending an online lecture where his professor asked him to solve a question. Amol was unable to solve the question so he asked you to solve the question and give him the...
{"inputs": ["2\n4\n16\n2 4 6 10\n4\n20\n2 8 12 10"], "outputs": ["2\n2"]}
coding
365
Solve the programming task below in a Python markdown code block. For any positive integer, we define a digit rotation as either moving the first digit to the end of the number (left digit rotation), or the last digit to the front of the number (right digit rotation). For example, the number 12345 could be left digit r...
{"inputs": ["6\n2528\n18211\n575\n268\n1\n257", "6\n4360\n18211\n575\n268\n1\n257", "6\n4360\n18211\n575\n268\n1\n443", "6\n4360\n18211\n575\n268\n1\n145", "6\n5788\n18211\n575\n268\n1\n145", "6\n5788\n32221\n575\n268\n1\n145", "6\n1689\n7692\n14761\n5838\n3\n68", "6\n1689\n7692\n14761\n8668\n3\n68"], "outputs": ["8252...
coding
321
Solve the programming task below in a Python markdown code block. Inna likes sweets and a game called the "Candy Matrix". Today, she came up with the new game "Candy Matrix 2: Reload". The field for the new game is a rectangle table of size n × m. Each line of the table contains one cell with a dwarf figurine, one cel...
{"inputs": ["1 2\nSG\n", "1 2\nGS\n", "1 2\nSG\n", "1 2\nGS\n", "1 3\nS*G\n", "1 3\nG*S\n", "1 3\nS*G\n", "1 4\nSG**\n"], "outputs": ["-1\n", "1\n", "-1\n", "1\n", "-1\n", "1\n", "-1\n", "-1\n"]}
coding
485
Solve the programming task below in a Python markdown code block. Here we have a function that help us spam our hearty laughter. But is not working! I need you to find out why... Expected results: ```python spam(1) ==> "hue" spam(6) ==> "huehuehuehuehuehue" spam(14) ==> "huehuehuehuehuehuehuehuehuehuehuehuehuehue" ...
{"functional": "_inputs = [[1], [6], [14]]\n_outputs = [['hue'], ['huehuehuehuehuehue'], ['huehuehuehuehuehuehuehuehuehuehuehuehuehue']]\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
112
Solve the programming task below in a Python markdown code block. The spring is coming and it means that a lot of fruits appear on the counters. One sunny day little boy Valera decided to go shopping. He made a list of m fruits he wanted to buy. If Valera want to buy more than one fruit of some kind, he includes it int...
{"inputs": ["1 4\n1\nu\nu\nu\nu\n", "1 4\n2\nu\nu\nu\nu\n", "3 1\n6 26 22\naga\n", "3 1\n6 26 42\naga\n", "3 1\n6 26 39\naga\n", "3 1\n14 26 22\naag\n", "3 1\n25 26 22\naag\n", "3 1\n25 26 22\naga\n"], "outputs": ["4 4\n", "8 8\n", "6 26\n", "6 42\n", "6 39\n", "14 26\n", "22 26\n", "22 26\n"]}
coding
468
Solve the programming task below in a Python markdown code block. You are given a set of $n$ ($n$ is always a power of $2$) elements containing all integers $0, 1, 2, \ldots, n-1$ exactly once. Find $\frac{n}{2}$ pairs of elements such that: Each element in the set is in exactly one pair. The sum over all pairs of t...
{"inputs": ["4\n4 0\n4 1\n4 2\n4 3\n"], "outputs": ["0 3\n1 2\n0 2\n1 3\n0 1\n2 3\n-1\n"]}
coding
550
Solve the programming task below in a Python markdown code block. Consider a pyramid made up of blocks. Each layer of the pyramid is a rectangle of blocks, and the dimensions of these rectangles increment as you descend the pyramid. So, if a layer is a `3x6` rectangle of blocks, then the next layer will be a `4x7` rect...
{"functional": "_inputs = [[1, 1, 2], [2, 4, 3], [1, 10, 10], [20, 30, 40]]\n_outputs = [[5], [47], [880], [83540]]\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 ...
coding
385
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a strictly increasing integer array rungs that represents the height of rungs on a ladder. You are currently on the floor at height 0, and you want to reach the last rung. You are also given an integer d...
{"functional": "def check(candidate):\n assert candidate(rungs = [1,3,5,10], dist = 2) == 2\n assert candidate(rungs = [3,6,8,10], dist = 3) == 0\n assert candidate(rungs = [3,4,6,7], dist = 2) == 1\n assert candidate(rungs = [5], dist = 10) == 0\n\n\ncheck(Solution().addRungs)"}
coding
189
Solve the programming task below in a Python markdown code block. There are n incoming messages for Vasya. The i-th message is going to be received after t_{i} minutes. Each message has a cost, which equals to A initially. After being received, the cost of a message decreases by B each minute (it can become negative). ...
{"inputs": ["1 6 4 3 9\n2\n", "1 6 4 3 9\n2\n", "4 5 5 3 5\n1 5 5 4\n", "4 5 5 3 5\n2 5 5 4\n", "4 5 5 3 5\n1 5 5 4\n", "5 3 1 1 3\n2 2 2 1 1\n", "5 5 3 4 5\n1 2 3 4 5\n", "5 6 1 1 3\n2 2 2 1 1\n"], "outputs": ["6\n", "6\n", "20\n", "20\n", "20\n", "15\n", "35\n", "30\n"]}
coding
502
Solve the programming task below in a Python markdown code block. Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. $N$ integers $A_{1}, A_{2}, \ldots, A_{N}$ are placed in a circle in such a way that for each valid $i$, $A_{i}$ and $A_{i+1}$ are adjacent, and $A_{...
{"inputs": ["1\n3\n10 10 1"], "outputs": ["32"]}
coding
563
Solve the programming task below in a Python markdown code block. Princess'Gamble Princess gambling English text is not available in this practice contest. One day, a brave princess in a poor country's tomboy broke the walls of her room, escaped from the castle, and entered the gambling hall where horse racing and o...
{"inputs": ["3 3 0\n1\n4\n3\n4 4 65\n1\n2\n3\n0\n3 1 3\n8\n2\n1\n0 0 0", "3 2 6\n2\n2\n3\n4 4 65\n1\n2\n6\n0\n3 1 2\n8\n1\n1\n0 0 0", "3 2 6\n3\n2\n3\n4 4 65\n1\n2\n6\n0\n3 1 2\n8\n1\n1\n0 0 0", "3 2 1\n1\n2\n3\n4 4 4\n1\n2\n1\n1\n3 1 16\n6\n0\n3\n0 0 0", "3 2 1\n1\n2\n3\n4 4 4\n1\n2\n1\n1\n3 1 16\n6\n0\n4\n0 0 0", "3 ...
coding
614
Solve the programming task below in a Python markdown code block. Today you are going to lead a group of elven archers to defend the castle that is attacked by an army of angry orcs. Three sides of the castle are protected by impassable mountains and the remaining side is occupied by a long wall that is split into n se...
{"inputs": ["1 0 0\n1\n", "1 0 0\n0\n", "1 1 0\n0\n", "1 1 10\n23\n", "2 0 1\n1 1\n", "1 1 10\n20\n", "2 0 1\n1 0\n", "2 0 100\n98 2\n"], "outputs": ["1\n", "0\n", "0", "33\n", "1\n", "30", "1", "100\n"]}
coding
470
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a 0-indexed string text and another 0-indexed string pattern of length 2, both of which consist of only lowercase English letters. You can add either pattern[0] or pattern[1] anywhere in text exactly onc...
{"functional": "def check(candidate):\n assert candidate(text = \"abdcdbc\", pattern = \"ac\") == 4\n assert candidate(text = \"aabb\", pattern = \"ab\") == 6\n\n\ncheck(Solution().maximumSubsequenceCount)"}
coding
169
Solve the programming task below in a Python markdown code block. Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. One day Petya was delivered a stri...
{"inputs": ["7\n", "4\n", "5\n", "9\n", "8\n", "2\n", "3\n", "0\n"], "outputs": ["7\n", "4\n", "-1\n", "-1\n", "-1\n", "-1\n", "-1\n", "-1\n"]}
coding
417
Solve the programming task below in a Python markdown code block. Chef likes toys. His favourite toy is an array of length N. This array contains only integers. He plays with this array every day. His favourite game with this array is Segment Multiplication. In this game, the second player tells the left and right side...
{"inputs": ["5\n1 2 3 4 5\n4\n1 2 3\n2 3 4\n1 1 1\n1 5 1000000000"], "outputs": ["2\n2\n0\n120"]}
coding
387
Please solve the programming task below using a self-contained code snippet in a markdown code block. The pair sum of a pair (a,b) is equal to a + b. The maximum pair sum is the largest pair sum in a list of pairs. For example, if we have pairs (1,5), (2,3), and (4,4), the maximum pair sum would be max(1+5, 2+3, 4+4)...
{"functional": "def check(candidate):\n assert candidate(nums = [3,5,2,3]) == 7\n assert candidate(nums = [3,5,4,2,4,6]) == 8\n\n\ncheck(Solution().minPairSum)"}
coding
198
Solve the programming task below in a Python markdown code block. The look and say sequence is a sequence in which each number is the result of a "look and say" operation on the previous element. Considering for example the classical version startin with `"1"`: `["1", "11", "21, "1211", "111221", ...]`. You can see th...
{"functional": "_inputs = [['1', 1], ['1', 3], ['1', 5], ['22', 10], ['14', 2]]\n_outputs = [['1'], ['21'], ['111221'], ['22'], ['1114']]\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
318
Solve the programming task below in a Python markdown code block. # It's too hot, and they can't even… One hot summer day Pete and his friend Billy decided to buy watermelons. They chose the biggest crate. They rushed home, dying of thirst, and decided to divide their loot, however they faced a hard problem. Pete and...
{"functional": "_inputs = [[4], [2], [5], [88], [100], [67], [90], [10], [99], [32]]\n_outputs = [[True], [False], [False], [True], [True], [False], [True], [True], [False], [True]]\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_t...
coding
295
Solve the programming task below in a Python markdown code block. The chef is trying to decode some pattern problems, Chef wants your help to code it. Chef has one number K to form a new pattern. Help the chef to code this pattern problem. -----Input:----- - First-line will contain $T$, the number of test cases. Then ...
{"inputs": ["4\n1\n2\n3\n4"], "outputs": ["0\n01\n10\n012\n101\n210\n0123\n1012\n2101\n3210"]}
coding
216
Solve the programming task below in a Python markdown code block. There are n schoolchildren, boys and girls, lined up in the school canteen in front of the bun stall. The buns aren't ready yet and the line is undergoing some changes. Each second all boys that stand right in front of girls, simultaneously swap places ...
{"inputs": ["F\n", "M\n", "F\n", "M\n", "FF\n", "FM\n", "MF\n", "MM\n"], "outputs": ["0\n", "0\n", "0", "0", "0\n", "0\n", "1\n", "0\n"]}
coding
522
Solve the programming task below in a Python markdown code block. There is a tree with N vertices, numbered 1, 2, \ldots, N. For each i (1 \leq i \leq N - 1), the i-th edge connects Vertex x_i and y_i. Taro has decided to paint each vertex in white or black. Here, it is not allowed to paint two adjacent vertices both ...
{"inputs": ["1", "3\n1 2\n2 0", "3\n1 2\n2 3", "4\n1 2\n1 3\n2 4", "4\n1 2\n2 3\n2 4", "4\n1 2\n1 3\n3 4", "4\n1 2\n2 3\n3 4", "4\n1 4\n1 3\n2 4"], "outputs": ["2", "5\n", "5", "8\n", "9\n", "8\n", "8\n", "8\n"]}
coding
327
Solve the programming task below in a Python markdown code block. Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well. Chef is planning to setup a secure password for his Codechef account. For a password to be secure the following conditions should be satisfied: 1) ...
{"inputs": ["3\n#cookOff#P1\nU@code4CHEFINA\ngR3@tPWD"], "outputs": ["NO\nYES\nNO"]}
coding
485
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a 0-indexed m x n integer matrix grid. Your initial position is at the top-left cell (0, 0). Starting from the cell (i, j), you can move to one of the following cells: Cells (i, k) with j < k <= grid[i]...
{"functional": "def check(candidate):\n assert candidate(grid = [[3,4,2,1],[4,2,3,1],[2,1,0,0],[2,4,0,0]]) == 4\n assert candidate(grid = [[3,4,2,1],[4,2,1,1],[2,1,1,0],[3,4,1,0]]) == 3\n assert candidate(grid = [[2,1,0],[1,0,0]]) == -1\n\n\ncheck(Solution().minimumVisitedCells)"}
coding
185
Please solve the programming task below using a self-contained code snippet in a markdown code block. A sequence of numbers is called arithmetic if it consists of at least two elements, and the difference between every two consecutive elements is the same. More formally, a sequence s is arithmetic if and only if s[i+1...
{"functional": "def check(candidate):\n assert candidate(nums = [4,6,5,9,3,7], l = [0,0,2], r = [2,3,5]) == [True,False,True]\n assert candidate(nums = [-12,-9,-3,-12,-6,15,20,-25,-20,-15,-10], l = [0,1,6,4,8,7], r = [4,4,9,7,9,10]) == [False,True,False,False,True,True]\n\n\ncheck(Solution().checkArithmeticSubarr...
coding
292
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given two integers n and k and two integer arrays speed and efficiency both of length n. There are n engineers numbered from 1 to n. speed[i] and efficiency[i] represent the speed and efficiency of the ith eng...
{"functional": "def check(candidate):\n assert candidate(n = 6, speed = [2,10,3,1,5,8], efficiency = [5,4,3,9,7,2], k = 2) == 60\n assert candidate(n = 6, speed = [2,10,3,1,5,8], efficiency = [5,4,3,9,7,2], k = 3) == 68\n assert candidate(n = 6, speed = [2,10,3,1,5,8], efficiency = [5,4,3,9,7,2], k = 4) == 72\...
coding
180
Solve the programming task below in a Python markdown code block. Read problem statements in [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. You are given a tree with $N$ nodes numbered from $1$ to $N$. A set $S$ of nodes is called valid if there exist two vertices $u$ and $v$ (possibly, $u=v$) suc...
{"inputs": ["2\n4\n1 2\n3 1\n2 4\n4\n1 2\n2 3\n2 4"], "outputs": ["15\n13"]}
coding
596
Solve the programming task below in a Python markdown code block. Hackerland is a one-dimensional city with houses aligned at integral locations along a road. The Mayor wants to install radio transmitters on the roofs of the city's houses. Each transmitter has a fixed range meaning it can transmit a signal to all house...
{"inputs": ["5 1 \n1 2 3 4 5\n", "8 2\n7 2 4 6 5 9 12 11 \n"], "outputs": ["2\n", "3\n"]}
coding
645
Solve the programming task below in a Python markdown code block. Read problems statements in [Mandarin Chinese], [Russian], [Vietnamese] and [Bengali] as well. Chef is participating in an ICPC regional contest, in which there is a total of $N$ problems (numbered $1$ through $N$) with varying difficulties. For each va...
{"inputs": ["3\n7\n1 2 3 4 5 7 6\n8\n8 7 6 5 4 3 2 1\n9\n7 4 3 5 6 1 8 2 9"], "outputs": ["7\n8\n8"]}
coding
548
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": ["4\n1\n2\n3\n4"], "outputs": ["1\n1 10\n11 100\n1 10 11\n100 101 110\n111 1000 1001\n1 10 11 100\n101 110 111 1000\n1001 1010 1011 1100\n1101 1110 1111 10000"]}
coding
294
Solve the programming task below in a Python markdown code block. Your wizard cousin works at a Quidditch stadium and wants you to write a function that calculates the points for the Quidditch scoreboard! # Story Quidditch is a sport with two teams. The teams score goals by throwing the Quaffle through a hoop, each ...
{"functional": "_inputs = [['Appleby Arrows vs Montrose Magpies', 'Montrose Magpies: Quaffle goal, Montrose Magpies: Quaffle goal, Appleby Arrows: Quaffle goal, Appleby Arrows: Quaffle goal, Montrose Magpies: Haverstacking foul, Appleby Arrows: Quaffle goal, Appleby Arrows: Quaffle goal, Appleby Arrows: Quaffle goal, A...
coding
382
Please solve the programming task below using a self-contained code snippet in a markdown code block. There is a street with n * 2 plots, where there are n plots on each side of the street. The plots on each side are numbered from 1 to n. On each plot, a house can be placed. Return the number of ways houses can be pla...
{"functional": "def check(candidate):\n assert candidate(n = 1) == 4\n assert candidate(n = 2) == 9\n\n\ncheck(Solution().countHousePlacements)"}
coding
177
Solve the programming task below in a Python markdown code block. Read problem statements in [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. For a given $N$, find the number of ways to choose an integer $x$ from the range $[0, 2^{N} - 1]$ such that $x \oplus (x+1) = (x+2) \oplus (x+3)$, where $\opl...
{"inputs": ["2\n1\n2"], "outputs": ["1\n2"]}
coding
326
Solve the programming task below in a Python markdown code block. You have N items and a bag of strength W. The i-th item has a weight of w_i and a value of v_i. You will select some of the items and put them in the bag. Here, the total weight of the selected items needs to be at most W. Your objective is to maximize...
{"inputs": ["4 6\n2 1\n3 6\n4 8\n3 4", "4 6\n2 1\n3 6\n2 8\n3 4", "4 6\n2 1\n3 8\n2 8\n2 8", "4 2\n2 1\n3 8\n2 8\n2 8", "4 6\n2 1\n3 6\n4 8\n3 6", "4 6\n2 1\n3 1\n2 8\n3 1", "4 6\n2 1\n3 2\n2 2\n3 1", "4 6\n2 1\n3 2\n2 4\n3 1"], "outputs": ["10\n", "14\n", "17\n", "8\n", "12\n", "9\n", "4\n", "6\n"]}
coding
355
Please solve the programming task below using a self-contained code snippet in a markdown code block. There are some spherical balloons taped onto a flat wall that represents the XY-plane. The balloons are represented as a 2D integer array points where points[i] = [xstart, xend] denotes a balloon whose horizontal diam...
{"functional": "def check(candidate):\n assert candidate(points = [[10,16],[2,8],[1,6],[7,12]]) == 2\n assert candidate(points = [[1,2],[3,4],[5,6],[7,8]]) == 4\n assert candidate(points = [[1,2],[2,3],[3,4],[4,5]]) == 2\n\n\ncheck(Solution().findMinArrowShots)"}
coding
216
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given 3 positives numbers a, b and c. Return the minimum flips required in some bits of a and b to make ( a OR b == c ). (bitwise OR operation). Flip operation consists of change any single bit 1 to 0 or change the b...
{"functional": "def check(candidate):\n assert candidate(a = 2, b = 6, c = 5) == 3\n assert candidate(a = 4, b = 2, c = 7) == 1\n assert candidate(a = 1, b = 2, c = 3) == 0\n\n\ncheck(Solution().minFlips)"}
coding
128
Solve the programming task below in a Python markdown code block. You are given an array A of N integers. You can do the following two types of operations any (possibly zero) number of times: Pick two indices i and j (1 ≤ i,j ≤ |A|, i \neq j). Change A_{j} := A_{j} + A_{i} and remove the i^{th} element from the array....
{"inputs": ["2\n3\n1 2 4\n4\n1 1 3 4"], "outputs": ["3\n3"]}
coding
762
Solve the programming task below in a Python markdown code block. There are n beacons located at distinct positions on a number line. The i-th beacon has position a_{i} and power level b_{i}. When the i-th beacon is activated, it destroys all beacons to its left (direction of decreasing coordinates) within distance b_{...
{"inputs": ["1\n0 1\n", "1\n0 1\n", "1\n1 1\n", "1\n0 2\n", "1\n1 2\n", "1\n0 4\n", "1\n1 3\n", "1\n0 3\n"], "outputs": ["0\n", "0", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]}
coding
486
Solve the programming task below in a Python markdown code block. The fearless Ikta has finally hunted down the infamous Count Big Bridge! Count Bigbridge is now trapped in a rectangular room w meters wide and h meters deep, waiting for his end. If you select a corner of the room and take the coordinate system so that...
{"inputs": ["16 10 0 7 3 3 2 8", "7 18 1 20 6 3 1 7", "7 28 1 20 1 3 1 3", "7 28 1 40 6 3 1 3", "7 19 2 19 0 3 1 0", "17 9 3 19 3 3 1 0", "7 19 2 19 0 3 0 0", "17 9 3 19 3 2 1 0"], "outputs": ["0\n", "9\n", "12\n", "24\n", "28\n", "64\n", "32\n", "68\n"]}
coding
479
Solve the programming task below in a Python markdown code block. There is an automatic door at the entrance of a factory. The door works in the following way: when one or several people come to the door and it is closed, the door immediately opens automatically and all people immediately come inside, when one or sev...
{"inputs": ["1 1 3 4\n7\n", "2 1 3 4\n7\n", "2 1 3 8\n7\n", "1 1 3 4\n7\n", "4 3 4 2\n7 9 11\n", "4 3 4 2\n3 9 11\n", "5 3 4 2\n7 9 11\n", "5 3 4 4\n7 9 11\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "4\n", "4\n", "5\n", "3\n"]}
coding
554
Solve the programming task below in a Python markdown code block. Chef has two distinct positive integers A and B. Chef wonders how many distinct values are possible for the expression \mathrm{gcd}(A+X,B+X), where X can take any non-negative integer value. Help Chef find this value. Here, \mathrm{gcd} stands for [G...
{"inputs": ["2\n1 2\n12 8\n"], "outputs": ["1\n3\n"]}
coding
374
Solve the programming task below in a Python markdown code block. You are given a program that consists of $n$ instructions. Initially a single variable $x$ is assigned to $0$. Afterwards, the instructions are of two types: increase $x$ by $1$; decrease $x$ by $1$. You are given $m$ queries of the following format: ...
{"inputs": ["2\n8 4\n-+--+--+\n1 8\n2 8\n2 5\n1 1\n4 10\n+-++\n1 1\n1 2\n2 2\n1 3\n2 3\n3 3\n1 4\n2 4\n3 4\n4 4\n", "2\n8 4\n-+--+--+\n2 8\n2 8\n2 5\n1 1\n4 10\n+-++\n1 1\n1 2\n2 2\n1 3\n2 3\n3 3\n1 4\n2 4\n3 4\n4 4\n", "2\n8 4\n-+--+--+\n1 8\n2 8\n2 5\n2 1\n4 10\n+-++\n1 1\n1 2\n2 2\n1 3\n2 3\n3 3\n1 4\n2 4\n3 4\n4 4\...
coding
628
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an integer array nums which is sorted in ascending order and all of its elements are unique and given also an integer k, return the kth missing number starting from the leftmost number of the array.   Please com...
{"functional": "def check(candidate):\n assert candidate(nums = [4,7,9,10], k = 1) == 5\n assert candidate(nums = [4,7,9,10], k = 3) == 8\n assert candidate(nums = [1,2,4], k = 3) == 6\n\n\ncheck(Solution().missingElement)"}
coding
93
Solve the programming task below in a Python markdown code block. Jenny is 9 years old. She is the youngest detective in North America. Jenny is a 3rd grader student, so when a new mission comes up, she gets a code to decipher in a form of a sticker (with numbers) in her math notebook and a comment (a sentence) in her ...
{"functional": "_inputs = [[[0, 3, 5], 'I love you'], [[7, 10, 1], 'see you later'], [[29, 31, 8], 'The quick brown fox jumps over the lazy dog'], [[12, 4, 6], 'Good Morning'], [[1, 16, 21], 'A purple pig and a green donkey flew a kite in the middle of the night'], [[35, 8, 20], 'A song can make or ruin your day if you...
coding
304
Solve the programming task below in a Python markdown code block. Little penguin Polo adores strings. But most of all he adores strings of length n. One day he wanted to find a string that meets the following conditions: The string consists of n lowercase English letters (that is, the string's length equals n), exact...
{"inputs": ["7 4\n", "4 7\n", "1 1\n", "2 2\n", "1 2\n", "3 3\n", "2 2\n", "3 3\n"], "outputs": ["ababacd\n", "-1\n", "a\n", "ab\n", "-1\n", "abc\n", "ab", "abc"]}
coding
406