task_type
stringclasses
4 values
problem
stringlengths
14
5.23k
solution
stringlengths
1
8.29k
problem_tokens
int64
9
1.02k
solution_tokens
int64
1
1.98k
coding
Solve the programming task below in a Python markdown code block. Takahashi, Aoki and Snuke love cookies. They have A, B and C cookies, respectively. Now, they will exchange those cookies by repeating the action below: * Each person simultaneously divides his cookies in half and gives one half to each of the other two...
{"inputs": ["0 0 0", "4 0 13", "3 0 13", "6 0 13", "6 0 24", "1 25 5", "1 25 0", "2 25 0"], "outputs": ["-1\n", "0\n", "0\n", "0\n", "1\n", "0\n", "0\n", "0\n"]}
223
102
coding
Solve the programming task below in a Python markdown code block. We have a grid with A horizontal rows and B vertical columns, with the squares painted white. On this grid, we will repeatedly apply the following operation: * Assume that the grid currently has a horizontal rows and b vertical columns. Choose "vertical...
{"inputs": ["2 0 3 4", "1 0 2 2", "2 0 3 0", "1 0 2 3", "2 0 3 1", "2 0 3 2", "1 0 2 1", "2 0 6 2"], "outputs": ["130\n", "3\n", "0\n", "7\n", "2\n", "10\n", "1\n", "94\n"]}
346
114
coding
Solve the programming task below in a Python markdown code block. Recently a dog was bought for Polycarp. The dog's name is Cormen. Now Polycarp has a lot of troubles. For example, Cormen likes going for a walk. Empirically Polycarp learned that the dog needs at least k walks for any two consecutive days in order to ...
{"inputs": ["1 1\n1\n", "1 4\n2\n", "1 5\n1\n", "1 2\n1\n", "1 5\n2\n", "1 3\n0\n", "1 3\n1\n", "1 5\n0\n"], "outputs": ["0\n1\n", "0\n2\n", "0\n1\n", "0\n1\n", "0\n2\n", "0\n0\n", "0\n1\n", "0\n0\n"]}
616
118
coding
Solve the programming task below in a Python markdown code block. INTERCAL is the oldest of esoteric programming languages. One of its many weird features is the method of character-based output, known as Turing Tape method. It converts an array of unsigned 8-bit integers into a sequence of characters to print, using t...
{"inputs": ["N\n", "M\n", "o2^\"t\n", "t\"^2o\n", "\\Pk|a\\'\n", "'\\a|kP\\\n", "s3=MS8%X\n", "X%8SM=3s\n"], "outputs": ["142\n", "78\n", "10\n170\n210\n54\n22\n", "210\n234\n202\n46\n86\n", "198\n48\n52\n152\n184\n76\n86\n", "28\n170\n180\n72\n104\n204\n208\n", "50\n2\n16\n10\n232\n174\n120\n138\n", "230\n118\n136\n82...
475
231
coding
Solve the programming task below in a Python markdown code block. Congratulations !!! You have successfully completed the heist by looting all the gifts in Santa's locker. Now it's time to decide who gets to take all the gifts, you or the Grinch, there will be no splitting. So you and Grinch decide to play a game. To s...
{"inputs": ["7\n1\n2\n3\n4\n5\n6\n12"], "outputs": ["Grinch\nMe\nMe\nGrinch\nMe\nGrinch\nMe"]}
303
42
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a 0-indexed array nums of length n, consisting of non-negative integers. For each index i from 0 to n - 1, you must determine the size of the minimum sized non-empty subarray of nums starting at i (inclu...
{"functional": "def check(candidate):\n assert candidate(nums = [1,0,2,1,3]) == [3,3,2,2,1]\n assert candidate(nums = [1,2]) == [2,1]\n\n\ncheck(Solution().smallestSubarrays)"}
229
67
coding
Solve the programming task below in a Python markdown code block. You are given an array of $n$ integers $a_1, a_2, \ldots, a_n$. The integers are either $1$ or $-1$. You have to perform the following operation exactly once on the array $a$: Choose an index $i$ ($1 \leq i < n$) and flip the signs of $a_i$ and $a_{i+1}...
{"inputs": ["4\n5\n-1 1 1 -1 -1\n5\n1 1 -1 -1 -1\n2\n1 1\n4\n1 -1 -1 1\n"], "outputs": ["3\n3\n-2\n4\n"]}
460
62
coding
Solve the programming task below in a Python markdown code block. Bizon the Champion isn't just attentive, he also is very hardworking. Bizon the Champion decided to paint his old fence his favorite color, orange. The fence is represented as n vertical planks, put in a row. Adjacent planks have no gap between them. Th...
{"inputs": ["1\n5\n", "1\n1\n", "1\n1\n", "1\n2\n", "1\n8\n", "1\n3\n", "1\n4\n", "1\n5\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n"]}
431
86
coding
Solve the programming task below in a Python markdown code block. Take a string and return a hash with all the ascii values of the characters in the string. Returns nil if the string is empty. The key is the character, and the value is the ascii value of the character. Repeated characters are to be ignored and non-alph...
{"functional": "_inputs = [[''], ['a'], ['aaa'], ['hello world'], ['ABaa ^']]\n_outputs = [[None], [{'a': 97}], [{'a': 97}], [{'h': 104, 'e': 101, 'l': 108, 'o': 111, 'w': 119, 'r': 114, 'd': 100}], [{'A': 65, 'B': 66, 'a': 97}]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, ...
95
261
coding
Solve the programming task below in a Python markdown code block. Time to win the lottery! Given a lottery ticket (ticket), represented by an array of 2-value arrays, you must find out if you've won the jackpot. Example ticket: To do this, you must first count the 'mini-wins' on your ticket. Each sub array has both...
{"functional": "_inputs = [[[['ABC', 65], ['HGR', 74], ['BYHT', 74]], 2], [[['ABC', 65], ['HGR', 74], ['BYHT', 74]], 1], [[['HGTYRE', 74], ['BE', 66], ['JKTY', 74]], 3]]\n_outputs = [['Loser!'], ['Winner!'], ['Loser!']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n ...
203
244
coding
Solve the programming task below in a Python markdown code block. As bad weather continues and vegetable prices soar, Seven-Eleven is offering customers bulk purchase sales of vegetables. The store is very busy, as you can get vegetables that are hard to find in stores at reasonable prices. One day, a group of three g...
{"inputs": ["4 1\n50 77 110 80\n7 3\n3 300 110 194 77 600 75\n0 0", "4 1\n50 77 110 80\n7 6\n3 300 110 194 77 600 75\n0 0", "4 3\n50 59 100 80\n7 3\n400 290 000 700 4 600 57\n0 0", "4 4\n50 59 100 80\n7 3\n400 290 000 700 4 600 57\n0 0", "4 2\n50 40 101 80\n7 4\n400 45 000 700 87 650 57\n0 0", "4 1\n27 77 100 80\n7 3\n...
522
494
coding
Solve the programming task below in a Python markdown code block. Levian works as an accountant in a large company. Levian knows how much the company has earned in each of the n consecutive months — in the i-th month the company had income equal to a_i (positive income means profit, negative income means loss, zero inc...
{"inputs": ["2\n0\n0\n", "2\n2\n2\n", "2\n4\n2\n", "2\n2\n0\n", "2\n1\n2\n", "2\n1\n0\n", "2\n0\n1\n", "2\n2\n1\n"], "outputs": ["-1", "2", "2\n", "2\n", "2\n", "2\n", "2\n", "2\n"]}
602
101
coding
Solve the programming task below in a Python markdown code block. Artem has an array of n positive integers. Artem decided to play with it. The game consists of n moves. Each move goes like this. Artem chooses some element of the array and removes it. For that, he gets min(a, b) points, where a and b are numbers that w...
{"inputs": ["1\n4\n", "1\n7\n", "1\n9\n", "1\n87\n", "1\n17\n", "1\n10\n", "1\n64\n", "2\n3 1\n"], "outputs": [" 0\n", "0\n", "0\n", " 0\n", "0\n", "0\n", "0\n", " ...
287
98
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You have intercepted a secret message encoded as a string of numbers. The message is decoded via the following mapping: "1" -> 'A' "2" -> 'B' ... "25" -> 'Y' "26" -> 'Z' However, while decoding the message, you realiz...
{"functional": "def check(candidate):\n assert candidate(s = \"12\") == 2\n assert candidate(s = \"226\") == 3\n assert candidate(s = \"06\") == 0\n\n\ncheck(Solution().numDecodings)"}
292
60
coding
Solve the programming task below in a Python markdown code block. Let $f(x)$ be the sum of digits of a decimal number $x$. Find the smallest non-negative integer $x$ such that $f(x) + f(x + 1) + \dots + f(x + k) = n$. -----Input----- The first line contains one integer $t$ ($1 \le t \le 150$) — the number of test c...
{"inputs": ["2\n6 9\n5 0\n", "2\n9 9\n53 9\n", "2\n4 9\n51 5\n", "2\n6 9\n10 0\n", "2\n4 6\n47 7\n", "2\n9 9\n27 9\n", "2\n9 9\n17 4\n", "2\n9 8\n53 9\n"], "outputs": ["-1\n5\n", "-1\n8\n", "-1\n24\n", "-1\n19\n", "-1\n17\n", "-1\n-1\n", "-1\n-1\n", "-1\n8\n"]}
278
163
coding
Solve the programming task below in a Python markdown code block. An array $b$ of length $k$ is called good if its arithmetic mean is equal to $1$. More formally, if $$\frac{b_1 + \cdots + b_k}{k}=1.$$ Note that the value $\frac{b_1+\cdots+b_k}{k}$ is not rounded up or down. For example, the array $[1,1,1,2]$ has an a...
{"inputs": ["1\n1\n1\n", "4\n3\n1 1 1\n2\n1 2\n4\n8 4 6 2\n1\n-2\n"], "outputs": ["0\n", "0\n1\n16\n1\n"]}
557
62
coding
Solve the programming task below in a Python markdown code block. Alice and Bob love playing one-dimensional battle ships. They play on the field in the form of a line consisting of n square cells (that is, on a 1 × n table). At the beginning of the game Alice puts k ships on the field without telling their positions ...
{"inputs": ["5 1 3\n1\n3\n", "1 1 1\n1\n1\n", "1 1 1\n1\n1\n", "2 1 1\n1\n1\n", "2 1 2\n1\n1\n", "3 1 2\n1\n1\n", "5 1 3\n1\n2\n", "5 1 2\n1\n1\n"], "outputs": ["1\n", "1\n", "1\n", "-1\n", "1\n", "-1\n", "-1\n", "-1\n"]}
484
134
coding
Solve the programming task below in a Python markdown code block. Takahashi and Aoki will play a game on a tree. The tree has N vertices numbered 1 to N, and the i-th of the N-1 edges connects Vertex a_i and Vertex b_i. At the beginning of the game, each vertex contains a coin. Starting from Takahashi, he and Aoki wil...
{"inputs": ["3\n2 2\n2 3", "3\n2 1\n2 3", "3\n1 2\n2 3", "6\n1 2\n2 1\n2 4\n4 6\n5 6", "6\n1 2\n2 3\n2 4\n6 6\n5 6", "6\n1 2\n2 1\n2 4\n4 6\n4 6", "6\n1 3\n2 3\n2 4\n6 6\n5 6", "6\n2 2\n2 3\n2 4\n6 6\n5 6"], "outputs": ["First\n", "First\n", "First", "Second\n", "First\n", "First\n", "First\n", "First\n"]}
385
185
coding
Solve the programming task below in a Python markdown code block. Kuriyama Mirai has killed many monsters and got many (namely n) stones. She numbers the stones from 1 to n. The cost of the i-th stone is v_{i}. Kuriyama Mirai wants to know something about these stones so she will ask you two kinds of questions: She wi...
{"inputs": ["1\n1\n2\n1 1 1\n2 1 1\n", "1\n1\n2\n1 1 1\n2 1 1\n", "6\n6 4 2 7 2 7\n3\n2 3 6\n1 3 4\n1 1 6\n", "6\n6 6 3 8 5 4\n3\n2 2 3\n2 1 5\n1 1 5\n", "6\n6 6 3 8 5 4\n3\n2 2 3\n2 1 5\n1 1 5\n", "6\n6 6 3 8 5 6\n3\n2 2 3\n2 1 5\n1 1 5\n", "6\n1 6 3 8 5 6\n3\n2 2 3\n2 1 5\n1 1 5\n", "6\n1 1 3 8 5 6\n3\n2 2 3\n2 1 5\n...
603
335
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a non-empty array of non-negative integers nums, the degree of this array is defined as the maximum frequency of any one of its elements. Your task is to find the smallest possible length of a (contiguous) subar...
{"functional": "def check(candidate):\n assert candidate(nums = [1,2,2,3,1]) == 2\n assert candidate(nums = [1,2,2,3,1,4,2]) == 6\n\n\ncheck(Solution().findShortestSubArray)"}
108
66
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a 0-indexed 2D matrix grid of size m x n, where (r, c) represents: A land cell if grid[r][c] = 0, or A water cell containing grid[r][c] fish, if grid[r][c] > 0. A fisher can start at any water cell (r,...
{"functional": "def check(candidate):\n assert candidate(grid = [[0,2,1,0],[4,0,0,3],[1,0,0,4],[0,3,2,0]]) == 7\n assert candidate(grid = [[1,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,1]]) == 1\n\n\ncheck(Solution().findMaxFish)"}
240
104
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an m x n matrix, return true if the matrix is Toeplitz. Otherwise, return false. A matrix is Toeplitz if every diagonal from top-left to bottom-right has the same elements.   Please complete the following python...
{"functional": "def check(candidate):\n assert candidate(matrix = [[1,2,3,4],[5,1,2,3],[9,5,1,2]]) == True\n assert candidate(matrix = [[1,2],[2,2]]) == False\n\n\ncheck(Solution().isToeplitzMatrix)"}
96
72
coding
Solve the programming task below in a Python markdown code block. problem Given a sequence of n integers a1, a2, ..., an and a positive integer k (1 ≤ k ≤ n), then the sum of k consecutive integers Si = ai + ai + Create a program that outputs the maximum value of 1 + ... + ai + k-1 (1 ≤ i ≤ n --k + 1). input The i...
{"inputs": ["5 3\n2\n5\n0\n5\n3\n0 0", "5 1\n0\n0\n0\n3\n1\n0 0", "5 3\n2\n5\n0\n8\n0\n0 0", "5 3\n2\n5\n1\n8\n0\n0 0", "5 3\n4\n5\n1\n8\n0\n0 0", "5 3\n4\n5\n2\n8\n0\n0 0", "5 3\n2\n5\n-4\n8\n3\n0 0", "5 3\n1\n9\n-4\n2\n1\n0 0"], "outputs": ["10\n", "3\n", "13\n", "14\n", "14\n", "15\n", "9\n", "7\n"]}
294
197
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Tic-tac-toe is played by two players A and B on a 3 x 3 grid. The rules of Tic-Tac-Toe are: Players take turns placing characters into empty squares ' '. The first player A always places 'X' characters, while the sec...
{"functional": "def check(candidate):\n assert candidate(moves = [[0,0],[2,0],[1,1],[2,1],[2,2]]) == \"A\"\n assert candidate(moves = [[0,0],[1,1],[0,1],[0,2],[1,0],[2,0]]) == \"B\"\n assert candidate(moves = [[0,0],[1,1],[2,0],[1,0],[1,2],[2,1],[0,1],[0,2],[2,2]]) == \"Draw\"\n assert candidate(moves = [[0...
290
157
coding
Solve the programming task below in a Python markdown code block. Given two positive integers N and M, let S denote the set of all the arrays of size N such that each element of the array lies in the range [1, M]. Since there are M^{N} such arrays, the size of S is M^{N}. Let X_{i} denote the [bitwise AND] of all elem...
{"inputs": ["2\n2 2\n2 3\n"], "outputs": ["3\n12"]}
611
24
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a string s, return the maximum number of unique substrings that the given string can be split into. You can split string s into any list of non-empty substrings, where the concatenation of the substrings forms t...
{"functional": "def check(candidate):\n assert candidate(s = \"ababccc\") == 5\n assert candidate(s = \"aba\") == 2\n assert candidate(s = \"aa\") == 1\n\n\ncheck(Solution().maxUniqueSplit)"}
131
58
coding
Solve the programming task below in a Python markdown code block. Chef is deriving weird ways to sort his array. Currently he is trying to sort his arrays in increasing order by reversing some of his subarrays. To make it more challenging for himself, Chef decides that he can reverse only those subarrays that have sum...
{"inputs": ["3\n4 1\n1 2 3 4\n4 1\n2 1 3 4\n5 7\n3 2 2 3 3\n"], "outputs": ["YES\nNO\nYES\n"]}
624
56
coding
Solve the programming task below in a Python markdown code block. Given a string $s$. You can perform the following operation on given string any number of time. Delete two successive elements of the string if they are same. After performing the above operation you have to return the least possible length of the string...
{"inputs": ["3\nabccd\nabbac\naaaa"], "outputs": ["3\n1\n0"]}
230
24
coding
Solve the programming task below in a Python markdown code block. The average miner Vaganych took refresher courses. As soon as a miner completes the courses, he should take exams. The hardest one is a computer test called "Testing Pants for Sadness". The test consists of n questions; the questions are to be answered ...
{"inputs": ["1\n2\n", "1\n3\n", "1\n10\n", "2\n2 1\n", "2\n2 3\n", "2\n1 2\n", "2\n1 1\n", "2\n2 2\n"], "outputs": ["2\n", "3\n", "10\n", "3\n", "7\n", "4\n", "2\n", "5\n"]}
545
98
coding
Solve the programming task below in a Python markdown code block. Read problem statements in [Mandarin], [Bengali], [Russian], and [Vietnamese] as well. Two drunken players Alice and Bob are playing a modified version of Tic-Tac-Toe. Initially, there is a $N \times M$ empty grid. Alice and Bob take alternate turns s...
{"inputs": ["1\n3 4 2\n1 1\n3 1\n1 2\n2 3\n2 1\n2 4\n3 2\n3 4\n1 3\n3 3\n2 2\n1 4\n"], "outputs": ["Bob\n"]}
649
68
coding
Solve the programming task below in a Python markdown code block. You are given a string $s$ consisting only of characters + and -. You perform some process with this string. This process can be described by the following pseudocode: res = 0 for init = 0 to inf cur = init ok = true for i = 1 to |s| ...
{"inputs": ["3\n--+-\n---\n++--+-\n", "3\n-+--\n---\n++--+-\n", "3\n--+-\n---\n+--++-\n", "3\n-+--\n---\n+--++-\n", "3\n--+-\n---\n-+-++-\n", "3\n---+\n---\n++--+-\n", "3\n-+--\n---\n---+++\n", "3\n--+-\n---\n-+--++\n"], "outputs": ["7\n9\n6\n", "9\n9\n6\n", "7\n9\n9\n", "9\n9\n9\n", "7\n9\n7\n", "10\n9\n6\n", "9\n9\n1...
316
203
coding
Solve the programming task below in a Python markdown code block. Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well. You are a warrior and you have to fight $N$ enemy warriors (numbered $1$ through $N$) one by one, in any order you choose. You have to win as many o...
{"inputs": ["1\n3 4\n1 2 1\n10\n2\n3\n1"], "outputs": ["3\n2\n3\n0"]}
462
37
coding
Solve the programming task below in a Python markdown code block. Chef has $N$ doggo (dogs) , Lets number them $1$ to $N$. Chef decided to build houses for each, but he soon realizes that keeping so many dogs at one place may be messy. So he decided to divide them into several groups called doggo communities. Let the...
{"inputs": ["1\n4"], "outputs": ["2"]}
406
14
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. An array A is larger than some array B if for the first index i where A[i] != B[i], A[i] > B[i]. For example, consider 0-indexing: [1,3,2,4] > [1,2,2,4], since at index 1, 3 > 2. [1,4,4,4] < [2,1,1,1], since at index...
{"functional": "def check(candidate):\n assert candidate(nums = [1,4,5,2,3], k = 3) == [5,2,3]\n assert candidate(nums = [1,4,5,2,3], k = 4) == [4,5,2,3]\n assert candidate(nums = [1,4,5,2,3], k = 1) == [5]\n\n\ncheck(Solution().largestSubarray)"}
187
109
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given two 0-indexed binary arrays nums1 and nums2. Find the widest pair of indices (i, j) such that i <= j and nums1[i] + nums1[i+1] + ... + nums1[j] == nums2[i] + nums2[i+1] + ... + nums2[j]. The widest pair ...
{"functional": "def check(candidate):\n assert candidate(nums1 = [1,1,0,1], nums2 = [0,1,1,0]) == 3\n assert candidate(nums1 = [0,1], nums2 = [1,1]) == 1\n assert candidate(nums1 = [0], nums2 = [1]) == 0\n\n\ncheck(Solution().widestPairOfIndices)"}
184
95
coding
Solve the programming task below in a Python markdown code block. Mole is hungry again. He found one ant colony, consisting of n ants, ordered in a row. Each ant i (1 ≤ i ≤ n) has a strength si. In order to make his dinner more interesting, Mole organizes a version of «Hunger Games» for the ants. He chooses two number...
{"inputs": ["5\n1 5 2 4 2\n4\n1 5\n2 5\n3 5\n4 5\n", "5\n1 3 4 4 2\n4\n1 5\n2 5\n3 5\n4 5\n", "5\n1 3 4 4 2\n4\n1 5\n2 5\n3 5\n2 5\n", "5\n1 3 4 4 2\n4\n1 5\n2 5\n1 5\n4 5\n", "5\n1 3 4 4 2\n4\n1 5\n2 5\n1 5\n3 5\n", "5\n1 3 4 4 2\n4\n1 3\n2 5\n1 5\n3 5\n", "5\n1 3 4 2 2\n4\n1 5\n2 5\n3 5\n2 5\n", "5\n1 3 4 4 2\n4\n1 5...
602
342
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. There are n cities numbered from 0 to n - 1 and n - 1 roads such that there is only one way to travel between two different cities (this network form a tree). Last year, The ministry of transport decided to orient the...
{"functional": "def check(candidate):\n assert candidate(n = 6, connections = [[0,1],[1,3],[2,3],[4,0],[4,5]]) == 3\n assert candidate(n = 5, connections = [[1,0],[1,2],[3,2],[3,4]]) == 2\n assert candidate(n = 3, connections = [[1,0],[2,0]]) == 0\n\n\ncheck(Solution().minReorder)"}
209
109
coding
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\...
518
338
coding
Solve the programming task below in a Python markdown code block. There are N towns in Snuke Kingdom, conveniently numbered 1 through N. Town 1 is the capital. Each town in the kingdom has a Teleporter, a facility that instantly transports a person to another place. The destination of the Teleporter of town i is town ...
{"inputs": ["3 1\n3 3 1", "3 1\n2 1 1", "3 2\n3 3 1", "3 4\n3 3 1", "3 4\n1 3 1", "3 7\n1 3 1", "3 2\n3 3 2", "3 2\n1 3 1"], "outputs": ["2\n", "1\n", "1\n", "1\n", "0\n", "0\n", "1\n", "0\n"]}
349
126
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an integer array nums, find three numbers whose product is maximum and return the maximum product.   Please complete the following python code precisely: ```python class Solution: def maximumProduct(self, nu...
{"functional": "def check(candidate):\n assert candidate(nums = [1,2,3]) == 6\n assert candidate(nums = [1,2,3,4]) == 24\n assert candidate(nums = [-1,-2,-3]) == -6\n\n\ncheck(Solution().maximumProduct)"}
67
70
coding
Solve the programming task below in a Python markdown code block. # Task Given an array `arr`, find the rank of the element at the ith position. The `rank` of the arr[i] is a value equal to the number of elements `less than or equal to` arr[i] standing before arr[i], plus the number of elements `less than` arr[i] st...
{"functional": "_inputs = [[[2, 1, 2, 1, 2], 2], [[2, 1, 2, 2, 2], 2], [[3, 2, 3, 4, 1], 0], [[3, 2, 3, 4, 1], 1], [[3, 2, 3, 4, 1], 2]]\n_outputs = [[3], [2], [2], [1], [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,...
304
254
coding
Solve the programming task below in a Python markdown code block. C: Skewering problem One day, when Homura was playing with blocks, Tempura came. Homura decided to play with blocks with Tempura. There is a rectangular parallelepiped of A \ times B \ times C, which is made by stacking A \ times B \ times C blocks of...
{"inputs": ["2 1 1", "2 1 2", "4 1 2", "2 1 0", "4 1 3", "2 2 0", "0 1 2", "7 1 3"], "outputs": ["Hom\n", "Tem\n", "Tem\n", "Tem\n", "Hom\n", "Tem\n", "Tem\n", "Hom\n"]}
476
94
coding
Solve the programming task below in a Python markdown code block. You are an upcoming movie director, and you have just released your first movie. You have also launched a simple review site with two buttons to press — upvote and downvote. However, the site is not so simple on the inside. There are two servers, each w...
{"inputs": ["1\n1\n2\n", "1\n1\n2\n", "1\n1\n3\n", "1\n1\n1\n", "4\n1\n2\n3\n1 2 3\n5\n1 1 1 1 1\n3\n3 3 2\n", "4\n1\n2\n3\n1 3 3\n5\n1 1 1 1 1\n3\n3 3 2\n", "4\n1\n1\n3\n1 3 3\n5\n1 1 1 1 1\n3\n3 3 2\n", "4\n1\n1\n3\n1 3 3\n5\n1 1 1 1 1\n3\n3 3 3\n"], "outputs": ["0\n", "0\n", "1\n", "1\n", "0\n2\n5\n2\n", "0\n3\n5\n2...
674
238
coding
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", "ba\na\n", "ba\nb\n", "bb\nb\n"], "outputs": ["0\n", "0", "1\n", "1", "1", "1\n", "1\n", "1\n"]}
471
83
coding
Solve the programming task below in a Python markdown code block. # Task Your task is to sort the characters in a string according to the following rules: ``` - Rule1: English alphabets are arranged from A to Z, case insensitive. ie. "Type" --> "epTy" - Rule2: If the uppercase and lowercase of an English alphabet ex...
{"functional": "_inputs = [['a'], ['cba'], ['Cba'], ['cCBbAa'], ['!'], ['c b a'], ['-c--b--a-'], ['cbaCcC'], ['Codewars'], [' MkWD{RB=//k-^ J@,xH Vfi uAz+$ kV _[ }a!}%pSBwn !kKB (b q PQF +}wS .kfU r wFNEs#NsR UVMdG']]\n_outputs = [['a'], ['abc'], ['abC'], ['AaBbcC'], ['!'], ['a b c'], ['-a--b--c-'], ['abcCcC'], ['aCd...
338
359
coding
Solve the programming task below in a Python markdown code block. Chef has a grid of size N \times M. In one move, Chef can move from his current cell to an adjacent cell. If the Chef is currently at (i, j) then, in one move, Chef can move to (i + 1, j), (i - 1, j), (i, j + 1) or (i, j - 1). There are also K *specia...
{"inputs": ["2\n3 3 0\n3 3 2\n2 2\n2 3\n"], "outputs": ["4\n3\n"]}
691
36
coding
Solve the programming task below in a Python markdown code block. With a friend we used to play the following game on a chessboard (8, rows, 8 columns). On the first row at the *bottom* we put numbers: `1/2, 2/3, 3/4, 4/5, 5/6, 6/7, 7/8, 8/9` On row 2 (2nd row from the bottom) we have: `1/3, 2/4, 3/5, 4/6, 5/7, 6/8,...
{"functional": "_inputs = [[0], [1], [8], [40], [101], [204], [807], [1808], [5014], [120000], [750000], [750001], [3000000], [3000001]]\n_outputs = [[[0]], [[1, 2]], [[32]], [[800]], [[10201, 2]], [[20808]], [[651249, 2]], [[1634432]], [[12570098]], [[7200000000]], [[281250000000]], [[562501500001, 2]], [[450000000000...
627
370
coding
Solve the programming task below in a Python markdown code block. You are given an array A of length N. An element X is said to be *dominant* if the frequency of X in A is strictly greater than the frequency of any other element in the A. For example, if A = [2, 1, 4, 4, 4] then 4 is a dominant element since its frequ...
{"inputs": ["4\n5\n2 2 2 2 2\n4\n1 2 3 4\n4\n3 3 2 1\n6\n1 1 2 2 3 4\n"], "outputs": ["YES\nNO\nYES\nNO\n"]}
394
66
coding
Solve the programming task below in a Python markdown code block. There are b blocks of digits. Each one consisting of the same n digits, which are given to you in the input. Wet Shark must choose exactly one digit from each block and concatenate all of those digits together to form one large integer. For example, if h...
{"inputs": ["3 2 1 2\n6 2 2\n", "3 2 1 2\n3 1 2\n", "3 2 1 2\n6 3 2\n", "3 2 1 2\n3 6 3\n", "3 2 0 2\n3 3 9\n", "3 2 0 2\n4 5 1\n", "3 2 0 2\n1 3 2\n", "3 2 1 2\n5 9 3\n"], "outputs": ["0\n", "6\n", "3\n", "6\n", "0\n", "3\n", "3\n", "9\n"]}
535
166
coding
Solve the programming task below in a Python markdown code block. Amicable numbers are two different numbers so related that the sum of the proper divisors of each is equal to the other number. (A proper divisor of a number is a positive factor of that number other than the number itself. For example, the proper diviso...
{"functional": "_inputs = [[220, 284], [220, 280], [1184, 1210], [220221, 282224], [10744, 10856], [299920, 9284], [999220, 2849], [122265, 139815]]\n_outputs = [[True], [False], [True], [False], [True], [False], [False], [True]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, ...
283
280
coding
Solve the programming task below in a Python markdown code block. Consider a sequence generation that follows the following steps. We will store removed values in variable `res`. Assume `n = 25`: ```Haskell -> [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] Let's remove the first number => res = [1]...
{"functional": "_inputs = [[7], [25], [50], [100], [1000], [10000]]\n_outputs = [[18], [107], [304], [993], [63589], [4721110]]\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, tupl...
730
212
coding
Solve the programming task below in a Python markdown code block. Fafa owns a company that works on huge projects. There are n employees in Fafa's company. Whenever the company has a new project to start working on, Fafa has to divide the tasks of this project among all the employees. Fafa finds doing this every time ...
{"inputs": ["2\n", "3\n", "4\n", "6\n", "9\n", "4\n", "3\n", "6\n"], "outputs": ["1\n", "1\n", "2\n", "3\n", "2\n", "2", "1", "3"]}
368
67
coding
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin Chinese and Russian. Mike likes to invent new functions. The latest one he has invented is called SuperFunction. Let's consider how it can be calculated: You are given two integers N and K. SuperFunction of N and K...
{"inputs": ["5 2 100"], "outputs": ["30"]}
509
19
coding
Solve the programming task below in a Python markdown code block. Madison is a little girl who is fond of toys. Her friend Mason works in a toy manufacturing factory . Mason has a 2D board $\mbox{A}$ of size $H\times W$ with $\mbox{H}$ rows and $\mbox{W}$ columns. The board is divided into cells of size $1\times1$ with...
{"inputs": ["1 1\n1\n", "3 3\n1 3 4\n2 2 3\n1 2 4\n"], "outputs": ["6\n", "60\n"]}
506
47
coding
Solve the programming task below in a Python markdown code block. We have an array of length $n$. Initially, each element is equal to $0$ and there is a pointer located on the first element. We can do the following two kinds of operations any number of times (possibly zero) in any order: If the pointer is not on the ...
{"inputs": ["1\n1\n1\n", "1\n2\n2 2\n", "1\n2\n-800372697 800372697\n", "7\n2\n1 0\n4\n2 -1 -1 0\n4\n1 -4 3 0\n4\n1 -1 1 -1\n5\n1 2 3 4 -10\n7\n2 -1 1 -2 0 0 0\n1\n0\n"], "outputs": ["No\n", "No\n", "No\n", "No\nYes\nNo\nNo\nYes\nYes\nYes\n"]}
677
152
coding
Solve the programming task below in a Python markdown code block. VK news recommendation system daily selects interesting publications of one of $n$ disjoint categories for each user. Each publication belongs to exactly one category. For each category $i$ batch algorithm selects $a_i$ publications. The latest A/B test...
{"inputs": ["1\n1\n7\n", "1\n2\n7\n", "1\n2\n4\n", "1\n1\n72\n", "1\n5\n16\n", "1\n3\n31\n", "1\n1\n72\n", "1\n3\n31\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]}
409
107
coding
Solve the programming task below in a Python markdown code block. A string $s$ of length $n$, consisting of lowercase letters of the English alphabet, is given. You must choose some number $k$ between $0$ and $n$. Then, you select $k$ characters of $s$ and permute them however you want. In this process, the positions ...
{"inputs": ["1\n20\naaaaaaaaaaaaaaaaaqwq\n", "1\n20\naaaaaaaaaaaaaaaaaqwq\n", "1\n20\naaaaaaabaaaaaaaaaqwq\n", "1\n20\nabaaaaabaaaaaaaaaqwq\n", "1\n20\nqwqaaaaaaaaabaaaaaba\n", "1\n20\nqwqaaaaabaaabaaaaaba\n", "1\n20\nabaaaaabaaabaaaaaqwq\n", "1\n20\nqwqaaaaaaaaabaaaabba\n"], "outputs": ["2\n", "2\n", "4\n", "6\n", "9\...
569
158
coding
Solve the programming task below in a Python markdown code block. You are given an integer sequence of length N, a = {a_1, a_2, …, a_N}, and an integer K. a has N(N+1)/2 non-empty contiguous subsequences, {a_l, a_{l+1}, …, a_r} (1 ≤ l ≤ r ≤ N). Among them, how many have an arithmetic mean that is greater than or equal...
{"inputs": ["1 4\n1", "1 2\n0", "1 6\n1", "1 2\n1", "3 5\n7\n5\n7", "3 6\n7\n5\n7", "3 6\n7\n5\n10", "3 6\n7\n5\n12"], "outputs": ["0\n", "0\n", "0\n", "0", "6\n", "5", "5\n", "5\n"]}
265
110
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a string s. You can convert s to a palindrome by adding characters in front of it. Return the shortest palindrome you can find by performing this transformation.   Please complete the following python co...
{"functional": "def check(candidate):\n assert candidate(s = \"aacecaaa\") == \"aaacecaaa\"\n assert candidate(s = \"abcd\") == \"dcbabcd\"\n\n\ncheck(Solution().shortestPalindrome)"}
81
54
coding
Solve the programming task below in a Python markdown code block. It's one more school day now. Sasha doesn't like classes and is always bored at them. So, each day he invents some game and plays in it alone or with friends. Today he invented one simple game to play with Lena, with whom he shares a desk. The rules are...
{"inputs": ["1 1\n", "6 2\n", "6 3\n", "6 4\n", "6 5\n", "6 6\n", "2 2\n", "6 1\n"], "outputs": ["YES\n", "YES\n", "NO\n", "YES\n", "YES\n", "YES\n", "YES\n", "NO\n"]}
363
86
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. In LeetCode Store, there are n items to sell. Each item has a price. However, there are some special offers, and a special offer consists of one or more different kinds of items with a sale price. You are given an int...
{"functional": "def check(candidate):\n assert candidate(price = [2,5], special = [[3,0,5],[1,2,10]], needs = [3,2]) == 14\n assert candidate(price = [2,3,4], special = [[1,1,0,4],[2,2,1,9]], needs = [1,2,1]) == 11\n\n\ncheck(Solution().shoppingOffers)"}
270
102
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given n rectangles represented by a 0-indexed 2D integer array rectangles, where rectangles[i] = [widthi, heighti] denotes the width and height of the ith rectangle. Two rectangles i and j (i < j) are consider...
{"functional": "def check(candidate):\n assert candidate(rectangles = [[4,8],[3,6],[10,20],[15,30]]) == 6\n assert candidate(rectangles = [[4,5],[7,8]]) == 0\n\n\ncheck(Solution().interchangeableRectangles)"}
153
72
coding
Solve the programming task below in a Python markdown code block. For years, the Day of city N was held in the most rainy day of summer. New mayor decided to break this tradition and select a not-so-rainy day for the celebration. The mayor knows the weather forecast for the $n$ days of summer. On the $i$-th day, $a_i$ ...
{"inputs": ["1 0 0\n7\n", "1 0 1\n7\n", "1 0 0\n10\n", "1 0 0\n10\n", "1 0 1\n10\n", "2 1 0\n2 1\n", "2 0 1\n2 1\n", "2 2 2\n1 2\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "2\n", "1\n"]}
628
127
coding
Solve the programming task below in a Python markdown code block. An array of integers is called *good* if all its elements are perfect squares. You are given an array A of N integers. In one move, you can do the following: Pick a subset of indices of the array, say \{i_{1}, i_{2}, \ldots, i_{k}\} where 1 ≤ i_{1} < i...
{"inputs": ["5\n3\n15 2 4\n4\n15 14 4 9\n3\n10 3 6\n2\n4 9\n2\n2 8\n"], "outputs": ["2\n2\n3\n0\n1\n"]}
649
64
coding
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin Chinese here ------ Problem Statement ------ Maxim likes dividers of the numbers. Also Maxim is fond of lucky numbers of small elephant from Lviv city.   If you remember, lucky numbers are positive integers whose ...
{"inputs": ["10\n2\n4\n2\n7\n5\n6\n7\n8\n9\n2", "10\n2\n2\n2\n4\n5\n8\n1\n2\n9\n5", "10\n2\n2\n1\n4\n5\n6\n3\n8\n9\n4", "10\n2\n3\n2\n5\n5\n4\n1\n2\n9\n5", "10\n2\n2\n1\n6\n5\n6\n3\n8\n9\n4", "10\n2\n4\n2\n7\n4\n6\n7\n8\n9\n2", "10\n2\n5\n4\n5\n5\n4\n1\n2\n9\n2", "10\n3\n4\n2\n9\n4\n6\n7\n8\n9\n2"], "outputs": ["0\n1\n...
370
374
coding
Solve the programming task below in a Python markdown code block. B: Periodic Sequence- problem Dr. Period, a professor at H University, is studying a property called the cycle that is supposed to be hidden in all things. As a generally known basic cycle, a cycle hidden in a sequence may be considered. That is, if th...
{"inputs": ["6\n1 2 3 1 1 3", "6\n1 2 3 1 0 3", "6\n2 2 3 1 0 3", "6\n2 2 3 2 0 3", "6\n4 2 3 2 0 3", "6\n4 2 3 2 0 4", "6\n4 4 3 2 0 4", "6\n7 4 3 2 0 4"], "outputs": ["1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n"]}
530
158
coding
Solve the programming task below in a Python markdown code block. Vasya has recently finished writing a book. Now he faces the problem of giving it the title. Vasya wants the title to be vague and mysterious for his book to be noticeable among others. That's why the title should be represented by a single word containi...
{"inputs": ["2\n?\n", "1\na\n", "1\n?\n", "1\n?a\n", "3\nb?c\n", "3\na?c\n", "2\n????\n", "3\n????\n"], "outputs": ["IMPOSSIBLE\n", "a\n", "a\n", "aa\n", "IMPOSSIBLE\n", "IMPOSSIBLE\n", "abba\n", "IMPOSSIBLE\n"]}
499
105
coding
Solve the programming task below in a Python markdown code block. You are given an integer N. You have to find a [permutation] P of the integers \{1, 2, \ldots, N\} that satisfies M conditions of the following form: (X_{i}, Y_{i}), denoting that the element X_{i}\;(1≤ X_{i} ≤ N) must appear in the prefix of length Y_{i...
{"inputs": ["4\n3 2\n2 1\n1 2\n4 3\n1 2\n4 1\n3 2\n4 1\n2 3\n5 2\n5 4\n3 2\n"], "outputs": ["2 1 3\n-1\n1 2 3 4\n1 3 2 5 4\n"]}
751
87
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given two strings a and b that consist of lowercase letters. In one operation, you can change any character in a or b to any lowercase letter. Your goal is to satisfy one of the following three conditions: Ev...
{"functional": "def check(candidate):\n assert candidate(a = \"aba\", b = \"caa\") == 2\n assert candidate(a = \"dabadd\", b = \"cda\") == 3\n\n\ncheck(Solution().minCharacters)"}
150
56
coding
Solve the programming task below in a Python markdown code block. Reading books is one of Sasha's passions. Once while he was reading one book, he became acquainted with an unusual character. The character told about himself like that: "Many are my names in many countries. Mithrandir among the Elves, Tharkûn to the Dwa...
{"inputs": ["a\n", "f\n", "a\n", "f\n", "`\n", "e\n", "b\n", "d\n"], "outputs": ["Impossible\n", "Impossible\n", "Impossible", "Impossible", "Impossible\n", "Impossible\n", "Impossible\n", "Impossible\n"]}
676
68
coding
Solve the programming task below in a Python markdown code block. Takahashi's house has only one socket. Takahashi wants to extend it with some number of power strips, each with A sockets, into B or more empty sockets. One power strip with A sockets can extend one empty socket into A empty sockets. Find the minimum num...
{"inputs": ["8 4", "4 9", "2 5", "7 9", "2 9", "4 1", "2 8", "2 7"], "outputs": ["1\n", "3\n", "4\n", "2\n", "8\n", "0\n", "7\n", "6\n"]}
177
78
coding
Solve the programming task below in a Python markdown code block. Chef has scored A, B, and C marks in 3 different subjects respectively. Chef will fail if the average score of any two subjects is less than 35. Determine whether Chef will pass or fail. ------ Input Format ------ - First line will contain T, number...
{"inputs": ["4\n23 47 52\n28 36 80\n0 100 0\n35 35 35\n"], "outputs": ["Pass\nFail\nFail\nPass"]}
418
54
coding
Solve the programming task below in a Python markdown code block. Bizon the Champion isn't just a bison. He also is a favorite of the "Bizons" team. At a competition the "Bizons" got the following problem: "You are given two distinct words (strings of English letters), s and t. You need to transform word s into word t...
{"inputs": ["y\nu\n", "y\nu\n", "z\nu\n", "y\nt\n", "z\nt\n", "z\nzz\n", "z\nzz\n", "ba\naa\n"], "outputs": ["need tree\n", "need tree\n", "need tree\n", "need tree\n", "need tree\n", "need tree\n", "need tree\n", "need tree\n"]}
557
94
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are assigned to put some amount of boxes onto one truck. You are given a 2D array boxTypes, where boxTypes[i] = [numberOfBoxesi, numberOfUnitsPerBoxi]: numberOfBoxesi is the number of boxes of type i. numberOfUni...
{"functional": "def check(candidate):\n assert candidate(boxTypes = [[1,3],[2,2],[3,1]], truckSize = 4) == 8\n assert candidate(boxTypes = [[5,10],[2,5],[4,7],[3,9]], truckSize = 10) == 91\n\n\ncheck(Solution().maximumUnits)"}
189
84
coding
Solve the programming task below in a Python markdown code block. William has array of $n$ numbers $a_1, a_2, \dots, a_n$. He can perform the following sequence of operations any number of times: Pick any two items from array $a_i$ and $a_j$, where $a_i$ must be a multiple of $2$ $a_i = \frac{a_i}{2}$ $a_j = a_j \cd...
{"inputs": ["5\n3\n6 4 2\n5\n1 2 3 4 5\n1\n10\n3\n2 3 4\n15\n8 8 8 8 8 8 8 8 8 8 8 8 8 8 8\n"], "outputs": ["50\n46\n10\n26\n35184372088846\n"]}
632
105
coding
Solve the programming task below in a Python markdown code block. ##Task: You have to write a function **pattern** which creates the following pattern upto n number of rows. *If the Argument is 0 or a Negative Integer then it should return "" i.e. empty string.* ##Examples: pattern(4): 1234 234 34 ...
{"functional": "_inputs = [[1], [2], [5], [0], [-25]]\n_outputs = [['1'], ['12\\n2'], ['12345\\n2345\\n345\\n45\\n5'], [''], ['']]\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, t...
177
202
coding
Solve the programming task below in a Python markdown code block. Arcady is a copywriter. His today's task is to type up an already well-designed story using his favorite text editor. Arcady types words, punctuation signs and spaces one after another. Each letter and each sign (including line feed) requires one keyboa...
{"inputs": ["aaa aaaaaa\n", "aaa aaaaaa\n", "aaa aabaaa\n", "aaa aaabaa\n", "aaa aaabab\n", "aaa baaaab\n", "'co-co-co, codeforces?!'\n", "'co-co-co, '!?secrofedoc\n"], "outputs": ["10\n", "10\n", "11\n", "10\n", "10\n", "11\n", "25\n", "25\n"]}
610
112
coding
Solve the programming task below in a Python markdown code block. Read problem statements in [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. Only $x$ hours are left for the March Long Challenge and Chef is only left with the last problem unsolved. However, he is sure that he cannot solve the proble...
{"inputs": ["2 5 3\n1 2", "2 6 3\n1 2"], "outputs": ["YES", "NO"]}
602
34
coding
Solve the programming task below in a Python markdown code block. You are given an input string. For each symbol in the string if it's the first character occurrence, replace it with a '1', else replace it with the amount of times you've already seen it... But will your code be **performant enough**? ___ ## E...
{"functional": "_inputs = [['Hello, World!'], [\"Hello, World! It's me, JomoPipi!\"], ['hello hello'], ['Hello'], ['11111'], ['hope you 123456789 expected numbers in the string'], [\"In this string, I'll make sure the amounts of a character go over 9\"]]\n_outputs = [['1112111121311'], ['1112111121311211113122413241112...
210
425
coding
Solve the programming task below in a Python markdown code block. You are given a string $t$ and a set $S$ of $N$ different strings. You need to separate $t$ such that each part is included in $S$. For example, the following 4 separation methods satisfy the condition when $t = abab$ and $S = \\{a, ab, b\\}$. * $a,b,a...
{"inputs": ["3\na\nb\nc\nxy{", "3\nb\nb\nc\nxy{", "3\nb\nb\nc\nyx{", "3\nb\nb\nc\nxx{", "3\nb\nb\nd\nxx{", "3\nb\nb\nd\nx{x", "3\nb\na\nd\nx{x", "3\na\nb\nc\nzyx"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]}
517
134
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an integer array bloomDay, an integer m and an integer k. You want to make m bouquets. To make a bouquet, you need to use k adjacent flowers from the garden. The garden consists of n flowers, the ith flo...
{"functional": "def check(candidate):\n assert candidate(bloomDay = [1,10,3,10,2], m = 3, k = 1) == 3\n assert candidate(bloomDay = [1,10,3,10,2], m = 3, k = 2) == -1\n assert candidate(bloomDay = [7,7,7,7,12,7,7], m = 2, k = 3) == 12\n assert candidate(bloomDay = [1000000000,1000000000], m = 1, k = 1) == 1...
161
221
coding
Solve the programming task below in a Python markdown code block. # Task You are given a positive integer `n`. We intend to make some ascending sequences according to the following rules: 1. Make a sequence of length 1: [ n ] 2. Or, insert a number to the left side of the sequence. But this number can not exceed h...
{"functional": "_inputs = [[6], [10], [1000]]\n_outputs = [[6], [14], [1981471878]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) != len(b): return Fa...
534
180
coding
Solve the programming task below in a Python markdown code block. Internet search engines, such as Google, automatically sort and categorize web pages around the world to create a huge database. It also parses the search keywords entered by the user and creates an inquiry statement for database search. In each case, c...
{"inputs": ["Rain, rain, go ot Spain.", "Rain, iarn, og ot Spain.", "Rain, arin, go to Spain.", "Rain, raio, go ot Spain.", "Rain, rain, og ot .niapS", "Rajn, rain, og ot .niapS", "Rain, rain, go to Spain.", "Win today's preliminary contest and be qualified to visit University fo Aizu."], "outputs": ["Rain rain Spain\n...
266
155
coding
Solve the programming task below in a Python markdown code block. An array $a_1, a_2, \ldots, a_n$ is good if and only if for every subsegment $1 \leq l \leq r \leq n$, the following holds: $a_l + a_{l + 1} + \ldots + a_r = \frac{1}{2}(a_l + a_r) \cdot (r - l + 1)$. You are given an array of integers $a_1, a_2, \ldots...
{"inputs": ["5\n4\n1 2 3 4\n4\n1 1 2 2\n2\n0 -1\n6\n3 -2 4 -1 -4 0\n1\n-100\n"], "outputs": ["0\n2\n0\n3\n0\n"]}
496
69
coding
Solve the programming task below in a Python markdown code block. We call a 4-digit integer with three or more consecutive same digits, such as 1118, good. You are given a 4-digit integer N. Answer the question: Is N good? -----Constraints----- - 1000 ≤ N ≤ 9999 - N is an integer. -----Input----- Input is given fro...
{"inputs": ["860", "374", "425", "647", "317", "943", "308", "164"], "outputs": ["No\n", "No\n", "No\n", "No\n", "No\n", "No\n", "No\n", "No\n"]}
139
78
coding
Solve the programming task below in a Python markdown code block. Timur initially had a binary string$^{\dagger}$ $s$ (possibly of length $0$). He performed the following operation several (possibly zero) times: Add ${0}$ to one end of the string and ${1}$ to the other end of the string. For example, starting from the...
{"inputs": ["1\n1\n1\n", "9\n3\n100\n4\n0111\n5\n10101\n6\n101010\n7\n1010110\n1\n1\n2\n10\n2\n11\n10\n1011011010\n"], "outputs": ["1\n", "1\n2\n5\n0\n3\n1\n0\n2\n4\n"]}
687
110
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. There is an undirected connected tree with n nodes labeled from 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)"}
285
61
coding
Solve the programming task below in a Python markdown code block. Let's start from some definitions. Strings A and B are called anagrams if it's possible to rearrange the letters of string A using all the original letters exactly once and achieve string B; in other words A and B are permutations of each other. For exa...
{"inputs": ["2\nwall\nstep", "2\nllaw\nstep", "2\namlu\nutfq", "2\nwmck\nmhqt", "2\nllwa\nstep", "2\nllwa\nstfp", "2\nmlwa\nstfp", "2\nawlm\nstfp"], "outputs": ["no such string", "no such string\n", "u\n", "m\n", "no such string\n", "no such string\n", "no such string\n", "no such string\n"]}
632
117
coding
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)"}
159
83
coding
Solve the programming task below in a Python markdown code block. This is the hard version of this problem. The only difference between the easy and hard versions is the constraints on $k$ and $m$. In this version of the problem, you need to output the answer by modulo $10^9+7$. You are given a sequence $a$ of length ...
{"inputs": ["3\n1 1 1\n1\n1 1 1\n1\n1 1 1\n1\n", "4\n4 3 2\n1 2 4 3\n4 2 1\n1 1 1 1\n1 1 1\n1\n10 4 3\n5 6 1 3 2 9 8 1 2 4\n", "4\n4 3 2\n1 2 4 3\n4 3 2\n1 1 1 1\n1 3 1\n1\n10 3 2\n5 6 1 3 2 9 8 1 2 4\n"], "outputs": ["1\n1\n1\n", "2\n6\n1\n20\n", "2\n4\n0\n15\n"]}
702
198
coding
Solve the programming task below in a Python markdown code block. 'Jeopardy!' is an intellectual game where players answer questions and earn points. Company Q conducts a simplified 'Jeopardy!' tournament among the best IT companies. By a lucky coincidence, the old rivals made it to the finals: company R1 and company R...
{"inputs": ["1 1\n1\n1\n", "1 1\n1\n1\n", "1 1\n2\n1\n", "2 1\n1 2\n1\n", "2 1\n1 2\n2\n", "2 1\n1 2\n2\n", "2 1\n1 2\n1\n", "2 1\n1 0\n1\n"], "outputs": ["1\n", " 1", "2\n", "4\n", "3\n", " 3", "...
593
131
coding
Solve the programming task below in a Python markdown code block. You are in a grid of dimensions N \times M. You are allowed to perform two types of operations: Go down, left, up, or right each for a cost of X. Formally, if you are at the cell (i,j) of the grid, you can go to either of the cells (i + 1, j), (i, j - 1...
{"inputs": ["3\n5 6 2 5\n4 7 5 6\n7 8 6 5"], "outputs": ["18\n33\n36"]}
625
43
coding
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 dreamt of a lexicogr...
{"inputs": ["3 7\n", "2 3\n", "1 2\n", "1 1\n", "7 1\n", "2 4\n", "2 1\n", "2 2\n"], "outputs": ["-1\n", "-1\n", "-1\n", "0\n", "2\n", "-1\n", "0\n", "0\n"]}
425
87
coding
Solve the programming task below in a Python markdown code block. Chandrima likes the XOR operation very much and keeps finding and solving related problems. One day she comes across a problem and gets stuck on it, which makes her sad. You being her friend decide to help her out by writing a code for the same. Consid...
{"inputs": ["3\n1 2 3\n", "3\n1 3 4\n"], "outputs": ["7\n", "0\n"]}
388
34
coding
Solve the programming task below in a Python markdown code block. You're a statistics professor and the deadline for submitting your students' grades is tonight at midnight. Each student's grade is determined by their mean score across all of the tests they took this semester. You've decided to automate grade calculat...
{"functional": "_inputs = [[[92, 94, 99]], [[50, 60, 70, 80, 90]], [[50, 55]]]\n_outputs = [['A'], ['C'], ['F']]\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 i...
284
198
coding
Solve the programming task below in a Python markdown code block. Jeff got 2n real numbers a1, a2, ..., a2n as a birthday present. The boy hates non-integer numbers, so he decided to slightly "adjust" the numbers he's got. Namely, Jeff consecutively executes n operations, each of them goes as follows: * choose index...
{"inputs": ["1\n1.100 1.200\n", "1\n0.061 0.330\n", "1\n0.900 0.900\n", "1\n0.001 0.001\n", "1\n6418.669 157.986\n", "1\n6418.000 157.986\n", "1\n6418.000 157.000\n", "2\n0.001 0.001 0.001 0.001\n"], "outputs": ["0.700\n", "0.609\n", "0.800\n", "0.998\n", "0.655\n", "0.014\n", "0.000\n", "1.996\n"]}
539
225
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. For an integer array nums, an inverse pair is a pair of integers [i, j] where 0 <= i < j < nums.length and nums[i] > nums[j]. Given two integers n and k, return the number of different arrays consisting of numbers fro...
{"functional": "def check(candidate):\n assert candidate(n = 3, k = 0) == 1\n assert candidate(n = 3, k = 1) == 2\n\n\ncheck(Solution().kInversePairs)"}
137
54
coding
Solve the programming task below in a Python markdown code block. *CodeChef recently revamped its [practice page] to make it easier for users to identify the next problems they should solve by introducing some new features:* *Recent Contest Problems - Contains only problems from the last 2 contests* *Separate Un-Attemp...
{"inputs": ["4\n3\nSTART38 LTIME108 START38\n4\nLTIME108 LTIME108 LTIME108 START38\n2\nLTIME108 LTIME108\n6\nSTART38 LTIME108 LTIME108 LTIME108 START38 LTIME108\n"], "outputs": ["2 1\n1 3\n0 2\n2 4\n"]}
666
105
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. A path in a binary tree is a sequence of nodes where each pair of adjacent nodes in the sequence has an edge connecting them. A node can only appear in the sequence at most once. Note that the path does not need to pa...
{"functional": "def check(candidate):\n assert candidate(root = tree_node([1,2,3])) == 6\n assert candidate(root = tree_node([-10,9,20,None,None,15,7])) == 42\n\n\ncheck(Solution().maxPathSum)"}
189
66
coding
Solve the programming task below in a Python markdown code block. Chef Watson uses a social network called ChefBook, which has a new feed consisting of posts by his friends. Each post can be characterized by f - the identifier of the friend who created the post, p - the popularity of the post(which is pre-calculated by...
{"inputs": ["2 4\n1 2\n1 1 WhoDoesntLoveChefBook\n2 2 WinterIsComing\n3 10 TheseViolentDelightsHaveViolentEnds\n4 3 ComeAtTheKingBestNotMiss"], "outputs": ["WinterIsComing\nWhoDoesntLoveChefBook\nTheseViolentDelightsHaveViolentEnds\nComeAtTheKingBestNotMiss"]}
525
89