problem
stringlengths
14
4.09k
solution
stringlengths
1
802k
task_type
stringclasses
3 values
problem_tokens
int64
5
895
Solve the programming task below in a Python markdown code block. Vasya plays a computer game with ninjas. At this stage Vasya's ninja should get out of a deep canyon. The canyon consists of two vertical parallel walls, their height is n meters. Let's imagine that we split these walls into 1 meter-long areas and numbe...
{"inputs": ["1 1\n-\nX\n", "1 20\n-\n-\n", "2 1\n-X\nX-\n", "2 1\n-X\n-X\n", "2 0\n-X\n-X\n", "2 0\n-X\nX-\n", "2 2\n-X\nX-\n", "1 100000\n-\n-\n"], "outputs": ["YES\n", "YES\n", "YES\n", "NO\n", "NO\n", "NO\n", "YES\n", "YES\n"]}
coding
630
Solve the programming task below in a Python markdown code block. Pirates have notorious difficulty with enunciating. They tend to blur all the letters together and scream at people. At long last, we need a way to unscramble what these pirates are saying. Write a function that will accept a jumble of letters as well ...
{"functional": "_inputs = [['trisf', ['first']], ['oob', ['bob', 'baobab']], ['ainstuomn', ['mountains', 'hills', 'mesa']], ['oolp', ['donkey', 'pool', 'horse', 'loop']], ['ortsp', ['sport', 'parrot', 'ports', 'matey']], ['ourf', ['one', 'two', 'three']]]\n_outputs = [[['first']], [[]], [['mountains']], [['pool', 'loop...
coding
174
Solve the programming task below in a Python markdown code block. You are given positive integers N and K. You have to construct an array A of length N such that : 1 ≤ A_{i} ≤ 10^{18} \sum_{i=1}^{N} \sum_{j=i}^{N} F(i,j) = K, where F(i,j) denotes the [gcd] of all elements of the subarray A[i, j]. If multiple such ar...
{"inputs": ["3\n1 5\n2 4\n3 1\n"], "outputs": ["5\n1 2\n-1\n"]}
coding
542
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an integer array nums. A subsequence of nums is called a square streak if: The length of the subsequence is at least 2, and after sorting the subsequence, each element (except the first element) is the ...
{"functional": "def check(candidate):\n assert candidate(nums = [4,3,6,16,8,2]) == 3\n assert candidate(nums = [2,3,5,6,7]) == -1\n\n\ncheck(Solution().longestSquareStreak)"}
coding
156
Solve the programming task below in a Python markdown code block. Vasilisa the Wise from a far away kingdom got a present from her friend Helga the Wise from a farther away kingdom. The present is a surprise box, yet Vasilisa the Wise doesn't know yet what the surprise actually is because she cannot open the box. She h...
{"inputs": ["VYYYVV\n", "OBRRYY\n", "RRYOGB\n", "RROOYY\n", "GOGGVG\n", "GVGBVO\n", "BOBGBB\n", "OOYYBY\n"], "outputs": ["2\n", "8\n", "15\n", "6\n", "2\n", "8\n", "2\n", "3\n"]}
coding
368
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given two integer arrays nums1 and nums2 of length n, count the pairs of indices (i, j) such that i < j and nums1[i] + nums1[j] > nums2[i] + nums2[j]. Return the number of pairs satisfying the condition.   Please comp...
{"functional": "def check(candidate):\n assert candidate(nums1 = [2,1,2,1], nums2 = [1,2,1,2]) == 1\n assert candidate(nums1 = [1,10,6,2], nums2 = [1,4,1,5]) == 5\n\n\ncheck(Solution().countPairs)"}
coding
112
Solve the programming task below in a Python markdown code block. # Task You are given a decimal number `n` as a **string**. Transform it into an array of numbers (given as **strings** again), such that each number has only one nonzero digit and their sum equals n. Each number in the output array should be written w...
{"functional": "_inputs = [['7970521.5544'], ['7496314'], ['0'], ['6'], ['1.0000000000'], ['0000000000.1'], ['1010101'], ['1234567890.1234567890']]\n_outputs = [[['7000000', '900000', '70000', '500', '20', '1', '.5', '.05', '.004', '.0004']], [['7000000', '400000', '90000', '6000', '300', '10', '4']], [[]], [['6']], [[...
coding
324
Solve the programming task below in a Python markdown code block. Determine whether a text T includes a pattern P. Your program should answer for given queries consisting of P_i. Constraints * 1 ≤ length of T ≤ 1000000 * 1 ≤ length of P_i ≤ 1000 * 1 ≤ Q ≤ 10000 * The input consists of alphabetical characters and digi...
{"inputs": ["aabaaa\n4\nab\nba\nbb\nxyz", "aabaaa\n4\nab\nba\nba\nxyz", "aabaaa\n4\nba\nbb\nac\nzyx", "aabaaa\n4\nca\nab\nba\nzyx", "aacaaa\n4\nba\nb`\nac\nzyx", "aacaaa\n4\nca\nb`\nac\nzyx", "aabaaa\n4\na`\nab\nca\nyzx", "aadaaa\n4\nca\nb`\nca\nzyx"], "outputs": ["1\n1\n0\n0\n", "1\n1\n1\n0\n", "1\n0\n0\n0\n", "0\n1\n...
coding
185
Solve the programming task below in a Python markdown code block. You are locked in a room with a door that has a keypad with 10 keys corresponding to digits from 0 to 9. To escape from the room, you need to enter a correct code. You also have a sequence of digits. Some keys on the keypad have fingerprints. You believ...
{"inputs": ["1 1\n4\n4\n", "1 1\n4\n4\n", "1 2\n1\n1 0\n", "1 2\n2\n1 2\n", "1 2\n2\n1 2\n", "1 2\n1\n1 0\n", "6 1\n4 2 7 3 1 8\n9\n", "1 6\n3\n6 8 2 4 5 3\n"], "outputs": ["4\n", "4\n", "1\n", "2\n", "2\n", "1\n", "\n", "3\n"]}
coding
484
Solve the programming task below in a Python markdown code block. Johnny is a boy who likes to open and close lockers. He loves it so much that one day, when school was out, he snuck in just to play with the lockers. Each locker can either be open or closed. If a locker is closed when Johnny gets to it, he opens it, a...
{"functional": "_inputs = [[1], [5], [10], [20]]\n_outputs = [[[1]], [[1, 4]], [[1, 4, 9]], [[1, 4, 9, 16]]]\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 le...
coding
357
Solve the programming task below in a Python markdown code block. Consider the infinite sequence s of positive integers, created by repeating the following steps: 1. Find the lexicographically smallest triple of positive integers (a, b, c) such that * a ⊕ b ⊕ c = 0, where ⊕ denotes the [bitwise XOR operation](h...
{"inputs": ["9\n2\n2\n3\n4\n5\n6\n7\n8\n9\n", "9\n2\n2\n3\n4\n9\n6\n7\n8\n9\n", "9\n1\n2\n3\n4\n5\n6\n7\n8\n9\n", "9\n2\n2\n3\n4\n5\n6\n7\n8\n17\n", "9\n3\n2\n3\n4\n5\n9\n15\n8\n7\n", "9\n1\n2\n3\n4\n5\n12\n7\n8\n9\n", "9\n3\n2\n3\n4\n9\n9\n15\n8\n7\n", "9\n2\n2\n3\n4\n5\n12\n7\n8\n9\n"], "outputs": ["2\n2\n3\n4\n8\n12...
coding
435
Solve the programming task below in a Python markdown code block. Chef has his lunch only between 1 pm and 4 pm (both inclusive). Given that the current time is X pm, find out whether it is *lunchtime* for Chef. ------ Input Format ------ - The first line of input will contain a single integer T, the number of tes...
{"inputs": ["3\n1\n7\n3"], "outputs": ["YES\nNO\nYES"]}
coding
373
Please solve the programming task below using a self-contained code snippet in a markdown code block. A train line going through a city has two routes, the regular route and the express route. Both routes go through the same n + 1 stops labeled from 0 to n. Initially, you start on the regular route at stop 0. You are ...
{"functional": "def check(candidate):\n assert candidate(regular = [1,6,9,5], express = [5,2,3,10], expressCost = 8) == [1,7,14,19]\n assert candidate(regular = [11,5,13], express = [7,10,6], expressCost = 3) == [10,15,24]\n\n\ncheck(Solution().minimumCosts)"}
coding
291
Solve the programming task below in a Python markdown code block. You are given $n$ integer numbers $a_1, a_2, \dots, a_n$. Consider graph on $n$ nodes, in which nodes $i$, $j$ ($i\neq j$) are connected if and only if, $a_i$ AND $a_j\neq 0$, where AND denotes the bitwise AND operation. Find the length of the shortest ...
{"inputs": ["3\n1 1 3\n", "3\n5 5 5\n", "3\n1 1 3\n", "3\n5 5 5\n", "3\n2 1 3\n", "3\n4 5 5\n", "3\n2 2 3\n", "4\n1 2 4 8\n"], "outputs": ["3", "3", "3", "3", "-1\n", "3\n", "3\n", "-1"]}
coding
322
Solve the programming task below in a Python markdown code block. Kuznecov likes art, poetry, and music. And strings consisting of lowercase English letters. Recently, Kuznecov has found two strings, $a$ and $b$, of lengths $n$ and $m$ respectively. They consist of lowercase English letters and no character is contain...
{"inputs": ["1\n5 1 5\naaaaa\nx\n", "3\n6 4 2\naaaaaa\nbbbb\n5 9 3\ncaaca\nbedededeb\n7 7 1\nnoskill\nwxhtzdy\n"], "outputs": ["aaaaa\n", "aabaabaa\naaabbcc\ndihktlwlxnyoz\n"]}
coding
681
Solve the programming task below in a Python markdown code block. Vova has taken his summer practice this year and now he should write a report on how it went. Vova has already drawn all the tables and wrote down all the formulas. Moreover, he has already decided that the report will consist of exactly $n$ pages and t...
{"inputs": ["1 1\n1\n1\n", "1 1\n2\n1\n", "1 1\n1\n2\n", "1 1\n3\n1\n", "1 1\n1\n3\n", "1 1\n2\n1\n", "1 1\n1\n2\n", "1 1\n3\n1\n"], "outputs": ["YES\n", "YES\n", "YES\n", "NO\n", "NO\n", "YES\n", "YES\n", "NO\n"]}
coding
680
Solve the programming task below in a Python markdown code block. You're playing a video game, in which you will get an achievement if you complete all of the levels consecutively without dying. You can play the levels in any order, and each time you play a level you'll either complete it or die. Each level has some pr...
{"inputs": ["1\n4\n1 1 1 1\n50 0 20 20", "3\n4\n1 1 1 1\n50 0 20 20\n3\n100 10 1\n0 50 0\n3\n100 80 50\n40 20 80"], "outputs": ["Case #1: 0 2 3 1", "Case #1: 0 2 3 1\nCase #2: 1 0 2\nCase #3: 2 0 1"]}
coding
509
Solve the programming task below in a Python markdown code block. The "Russian Peasant Method" is an old algorithm used by Russian peasants (and before them ancient Egyptians) to perform multiplication. Consider that X and Y are two numbers. X can be any number but Y must be a positive integer. To multiply X and Y: ...
{"functional": "_inputs = [[10, 5], [1.001, 2], [175, 18], [-2, 2], [2500, 123]]\n_outputs = [[50], [2.002], [3150], [-4], [307500]]\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,...
coding
230
Solve the programming task below in a Python markdown code block. You are given sequence a_1, a_2, ..., a_{n} of integer numbers of length n. Your task is to find such subsequence that its sum is odd and maximum among all such subsequences. It's guaranteed that given sequence contains subsequence with odd sum. Subsequ...
{"inputs": ["1\n1\n", "1\n1\n", "1\n1\n", "1\n1\n", "1\n1\n", "1\n1\n", "1\n-1\n", "1\n-1\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "-1\n", "-1\n"]}
coding
248
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 that consists of n distinct positive integers. Apply m operations to this array, where in the ith operation you replace the number operations[i][0] with operations[i][1]. It is gua...
{"functional": "def check(candidate):\n assert candidate(nums = [1,2,4,6], operations = [[1,3],[4,7],[6,1]]) == [3,2,7,1]\n assert candidate(nums = [1,2], operations = [[1,3],[2,1],[3,2]]) == [2,1]\n\n\ncheck(Solution().arrayChange)"}
coding
139
Solve the programming task below in a Python markdown code block. Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. You are given a matrix $A$ with $N$ rows (numbered $1$ through $N$) and $M$ columns (numbered $1$ through $M$). You need to fill the matrix with can...
{"inputs": ["2\n4 4 4 6\n3 4 4 5"], "outputs": ["48\n30"]}
coding
360
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given n cuboids where the dimensions of the ith cuboid is cuboids[i] = [widthi, lengthi, heighti] (0-indexed). Choose a subset of cuboids and place them on each other. You can place cuboid i on cuboid j if widthi <= w...
{"functional": "def check(candidate):\n assert candidate(cuboids = [[50,45,20],[95,37,53],[45,23,12]]) == 190\n assert candidate(cuboids = [[38,25,45],[76,35,3]]) == 76\n assert candidate(cuboids = [[7,11,17],[7,17,11],[11,7,17],[11,17,7],[17,7,11],[17,11,7]]) == 102\n\n\ncheck(Solution().maxHeight)"}
coding
154
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin chinese, Russian and Vietnamese as well. Chef is an intern at Zoozle. He has a co-intern named Ajar who's good at maths. Chef wants to impress Ajar with his zoozliness, so he decided to play the following game with ...
{"inputs": ["5\n5"], "outputs": ["187500002"]}
coding
566
Solve the programming task below in a Python markdown code block. Peter likes to travel by train. He likes it so much that on the train he falls asleep. Once in summer Peter was going by train from city A to city B, and as usual, was sleeping. Then he woke up, started to look through the window and noticed that every...
{"inputs": ["a\na\na\n", "a\na\n`\n", "ab\nb\na\n", "aab\nb\naa\n", "`ab\nb\naa\n", "atob\na\na\n", "`ab\nb\n`a\n", "atnb\na\na\n"], "outputs": ["fantasy\n", "fantasy\n", "backward\n", "backward\n", "fantasy\n", "fantasy\n", "fantasy\n", "fantasy\n"]}
coding
583
Please solve the programming task below using a self-contained code snippet in a markdown code block. Run-length encoding is a compression algorithm that allows for an integer array nums with many segments of consecutive repeated numbers to be represented by a (generally smaller) 2D array encoded. Each encoded[i] = [v...
{"functional": "def check(candidate):\n assert candidate(encoded1 = [[1,3],[2,3]], encoded2 = [[6,3],[3,3]]) == [[6,6]]\n assert candidate(encoded1 = [[1,3],[2,1],[3,2]], encoded2 = [[2,3],[3,3]]) == [[2,3],[6,1],[9,2]]\n\n\ncheck(Solution().findRLEArray)"}
coding
381
Solve the programming task below in a Python markdown code block. Your task is to find the first element of an array that is not consecutive. By not consecutive we mean not exactly 1 larger than the previous element of the array. E.g. If we have an array `[1,2,3,4,6,7,8]` then `1` then `2` then `3` then `4` are all c...
{"functional": "_inputs = [[[1, 2, 3, 4, 6, 7, 8]], [[1, 2, 3, 4, 5, 6, 7, 8]], [[4, 6, 7, 8, 9, 11]], [[4, 5, 6, 7, 8, 9, 11]], [[31, 32]], [[-3, -2, 0, 1]], [[-5, -4, -3, -1]]]\n_outputs = [[6], [None], [6], [11], [None], [0], [-1]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstanc...
coding
466
Solve the programming task below in a Python markdown code block. Polycarp has just invented a new binary protocol for data transmission. He is encoding positive integer decimal number to binary string using following algorithm: Each digit is represented with number of '1' characters equal to the value of that digit...
{"inputs": ["1\n1\n", "1\n1\n", "2\n10\n", "2\n10\n", "3\n111\n", "3\n100\n", "3\n100\n", "3\n110\n"], "outputs": ["1\n", "1\n", "10\n", "10\n", "3\n", "100\n", "100\n", "20\n"]}
coding
245
Please solve the programming task below using a self-contained code snippet in a markdown code block. You have a 1-indexed binary string of length n where all the bits are 0 initially. We will flip all the bits of this binary string (i.e., change them from 0 to 1) one by one. You are given a 1-indexed integer array fl...
{"functional": "def check(candidate):\n assert candidate(flips = [3,2,4,1,5]) == 2\n assert candidate(flips = [4,1,2,3]) == 1\n\n\ncheck(Solution().numTimesAllBlue)"}
coding
179
Solve the programming task below in a Python markdown code block. Given the integer $n$ — the number of available blocks. You must use all blocks to build a pedestal. The pedestal consists of $3$ platforms for $2$-nd, $1$-st and $3$-rd places respectively. The platform for the $1$-st place must be strictly higher than...
{"inputs": ["1\n3777\n", "1\n3234\n", "1\n5234\n", "1\n14377\n", "6\n11\n6\n10\n100000\n7\n8\n", "17\n58512\n46568\n77983\n60262\n48767\n75002\n79520\n52911\n42089\n38692\n71175\n51960\n33754\n36367\n67108\n79100\n78009\n"], "outputs": ["1259 1260 1258\n", "1078 1079 1077\n", "1745 1746 1743\n", "4793 4794 4790\n", "4 ...
coding
632
Solve the programming task below in a Python markdown code block. Yaroslav has an array that consists of n integers. In one second Yaroslav can swap two neighboring array elements. Now Yaroslav is wondering if he can obtain an array where any two neighboring elements would be distinct in a finite time. Help Yaroslav. ...
{"inputs": ["1\n1\n", "1\n0\n", "1\n1\n", "2\n1 1\n", "2\n1 1\n", "2\n1 0\n", "1\n1000\n", "1\n1000\n"], "outputs": ["YES\n", "YES\n", "YES\n", "NO\n", "NO\n", "YES\n", "YES\n", "YES\n"]}
coding
284
Solve the programming task below in a Python markdown code block. "This problem is rubbish! There is not statement, and there are only 5 test cases. The problemsetter took liberties with this problem!" — people complained in the comments to one round on Codeforces. And even more... No, wait, the checker for the problem...
{"inputs": ["5\n", "4\n", "2\n", "3\n", "1\n"], "outputs": ["1", "2", "3", "1", "2"]}
coding
156
Solve the programming task below in a Python markdown code block. Having read half of the book called "Storm and Calm" on the IT lesson, Innocentius was absolutely determined to finish the book on the maths lessons. All was fine until the math teacher Ms. Watkins saw Innocentius reading fiction books instead of solving...
{"inputs": ["a\n", "b\n", "c\n", "d\n", "e\n", "ab\n", "bb\n", "ba\n"], "outputs": ["No solution\n", "1 1\n", "1 1\n", "1 1\n", "No solution\n", "2 1\n", "2 1\n", "2 1\n"]}
coding
497
Solve the programming task below in a Python markdown code block. DevuLand is a very strange place. There are n villages in it. Some of the villages are occupied by dinosaurs while the remaining ones by villagers. You are given the information of DevuLand by an array D of size n. If D[i] is non-negative, it means th...
{"inputs": ["3\n2\n5 -5\n2\n-5 5\n3\n1 2 -3", "3\n1\n5 -5\n2\n-5 5\n3\n1 2 -3", "3\n2\n5 -5\n2\n-5 5\n3\n0 3 -3", "3\n1\n5 -5\n1\n-5 5\n2\n1 3 -4", "3\n1\n5 -5\n2\n-8 8\n2\n1 2 -3", "3\n1\n5 -5\n1\n-5 5\n3\n1 2 -3", "3\n2\n5 -5\n2\n-5 5\n2\n1 2 -3", "3\n2\n5 -5\n1\n-5 5\n3\n1 2 -3"], "outputs": ["5\n5\n4", "5\n5\n4\n",...
coding
734
Solve the programming task below in a Python markdown code block. *Shamelessly stolen from Here :)* Your server has sixteen memory banks; each memory bank can hold any number of blocks. You must write a routine to balance the blocks between the memory banks. The reallocation routine operates in cycles. In each cycle,...
{"functional": "_inputs = [[[5, 1, 10, 0, 1, 7, 13, 14, 3, 12, 8, 10, 7, 12, 0, 600]], [[53, 21, 10, 0, 1, 7, 13, 14, 3, 12, 8, 10, 7, 12, 0, 60]], [[14, 21, 10, 0, 1, 7, 0, 14, 3, 12, 8, 10, 17, 12, 0, 19]], [[5, 1, 10, 0, 1, 7, 13, 14, 3, 12, 8, 10, 7, 12, 0, 6]], [[17, 17, 3, 5, 1, 10, 6, 2, 0, 12, 8, 11, 16, 2, 1, ...
coding
668
Solve the programming task below in a Python markdown code block. The goal is to write a pair of functions the first of which will take a string of binary along with a specification of bits, which will return a numeric, signed complement in two's complement format. The second will do the reverse. It will take in an int...
{"functional": "_inputs = [['00000001', 8], ['00000010', 8], ['01111110', 8], ['01111111', 8], ['11111111', 8], ['11111110', 8], ['10000010', 8], ['1000 0000', 8], ['1010 1010 0010 0010 1110 1010 0010 1110', 32], ['1000 0000 1110 1111 0011 0100 1100 1010', 32], ['10110001000100000101100011111000', 32]]\n_outputs = [[1]...
coding
238
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an integer array nums containing n integers, find the beauty of each subarray of size k. The beauty of a subarray is the xth smallest integer in the subarray if it is negative, or 0 if there are fewer than x neg...
{"functional": "def check(candidate):\n assert candidate(nums = [1,-1,-3,-2,3], k = 3, x = 2) == [-1,-2,-2]\n assert candidate(nums = [-1,-2,-3,-4,-5], k = 2, x = 2) == [-1,-2,-3,-4]\n assert candidate(nums = [-3,1,2,-3,0,-3], k = 2, x = 1) == [-3,0,-3,-3,-3]\n\n\ncheck(Solution().getSubarrayBeauty)"}
coding
158
Solve the programming task below in a Python markdown code block. Alice and Bob like games. And now they are ready to start a new game. They have placed n chocolate bars in a line. Alice starts to eat chocolate bars one by one from left to right, and Bob — from right to left. For each chocololate bar the time, needed f...
{"inputs": ["1\n6\n", "1\n1\n", "1\n5\n", "1\n9\n", "1\n2\n", "1\n7\n", "1\n8\n", "1\n15\n"], "outputs": ["1 0\n", "1 0\n", "1 0\n", "1 0\n", "1 0\n", "1 0\n", "1 0\n", "1 0\n"]}
coding
289
Solve the programming task below in a Python markdown code block. Many years have passed, and n friends met at a party again. Technologies have leaped forward since the last meeting, cameras with timer appeared and now it is not obligatory for one of the friends to stand with a camera, and, thus, being absent on the ph...
{"inputs": ["1\n1 1\n", "1\n1 1\n", "1\n1 1\n", "1\n2 7\n", "1\n0 1\n", "1\n5 10\n", "1\n2 10\n", "1\n5 10\n"], "outputs": ["1\n", "1\n", "1\n", "14\n", "0\n", "50\n", "20\n", "50\n"]}
coding
418
Solve the programming task below in a Python markdown code block. **Step 1:** Create a function called `encode()` to replace all the lowercase vowels in a given string with numbers according to the following pattern: ``` a -> 1 e -> 2 i -> 3 o -> 4 u -> 5 ``` For example, `encode("hello")` would return `"h2ll4"`. Ther...
{"functional": "_inputs = [['hello'], ['How are you today?'], ['This is an encoding test.']]\n_outputs = [['h2ll4'], ['H4w 1r2 y45 t4d1y?'], ['Th3s 3s 1n 2nc4d3ng t2st.']]\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, ab...
coding
193
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed. All houses at this place are arranged in a circle. That means the first house is the neighbor of t...
{"functional": "def check(candidate):\n assert candidate(nums = [2,3,2]) == 3\n assert candidate(nums = [1,2,3,1]) == 4\n assert candidate(nums = [1,2,3]) == 3\n\n\ncheck(Solution().rob)"}
coding
155
Solve the programming task below in a Python markdown code block. Theofanis really likes sequences of positive integers, thus his teacher (Yeltsa Kcir) gave him a problem about a sequence that consists of only special numbers. Let's call a positive number special if it can be written as a sum of different non-negative...
{"inputs": ["3\n6 7\n2 6\n9 255\n", "3\n1 2\n2 6\n7 433\n", "3\n6 7\n2 6\n9 205\n", "3\n1 2\n2 6\n7 749\n", "3\n0 4\n2 6\n39 564\n", "3\n0 8\n0 6\n105 46\n", "3\n1 7\n0 6\n35 564\n", "3\n0 4\n0 6\n39 564\n"], "outputs": ["43\n6\n5380840\n", "1\n6\n6607553\n", "43\n6\n5315221\n", "1\n6\n41311999\n", "0\n6\n452236824\n",...
coding
347
Solve the programming task below in a Python markdown code block. Bear Limak has n colored balls, arranged in one long row. Balls are numbered 1 through n, from left to right. There are n possible colors, also numbered 1 through n. The i-th ball has color t_{i}. For a fixed interval (set of consecutive elements) of ba...
{"inputs": ["1\n1\n", "1\n1\n", "2\n2 1\n", "2\n2 1\n", "2\n2 2\n", "3\n1 1 1\n", "3\n2 1 1\n", "3\n1 1 1\n"], "outputs": ["1 \n", "1 ", "2 1 \n", "2 1 ", "0 3\n", "6 0 0 \n", "5 1 0\n", "6 0 0 "]}
coding
412
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an array prices where prices[i] is the price of a given stock on the ith day. Find the maximum profit you can achieve. You may complete at most two transactions. Note: You may not engage in multiple tran...
{"functional": "def check(candidate):\n assert candidate(prices = [3,3,5,0,0,3,1,4]) == 6\n assert candidate(prices = [1,2,3,4,5]) == 4\n assert candidate(prices = [7,6,4,3,1] ) == 0 \n assert candidate(prices = [1]) == 0\n\n\ncheck(Solution().maxProfit)"}
coding
110
Solve the programming task below in a Python markdown code block. There are some rabbits in Singapore Zoo. To feed them, Zookeeper bought $n$ carrots with lengths $a_1, a_2, a_3, \ldots, a_n$. However, rabbits are very fertile and multiply very quickly. Zookeeper now has $k$ rabbits and does not have enough carrots to ...
{"inputs": ["1 1\n1\n", "1 1\n1\n", "1 4\n6\n", "1 4\n19\n", "1 8\n19\n", "1 4\n19\n", "1 15\n19\n", "3 6\n5 3 1\n"], "outputs": ["1\n", "1\n", "10\n", "91\n", "47\n", "91\n", "27\n", "15\n"]}
coding
440
Please solve the programming task below using a self-contained code snippet in a markdown code block. Alice is texting Bob using her phone. The mapping of digits to letters is shown in the figure below. In order to add a letter, Alice has to press the key of the corresponding digit i times, where i is the position of...
{"functional": "def check(candidate):\n assert candidate(pressedKeys = \"22233\") == 8\n assert candidate(pressedKeys = \"222222222222222222222222222222222222\") == 82876089\n\n\ncheck(Solution().countTexts)"}
coding
259
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a parentheses string s containing only the characters '(' and ')'. A parentheses string is balanced if: Any left parenthesis '(' must have a corresponding two consecutive right parenthesis '))'. Left parenthesi...
{"functional": "def check(candidate):\n assert candidate(s = \"(()))\") == 1\n assert candidate(s = \"())\") == 0\n assert candidate(s = \"))())(\") == 3\n assert candidate(s = \"((((((\") == 12\n assert candidate(s = \")))))))\") == 5\n\n\ncheck(Solution().minInsertions)"}
coding
184
Solve the programming task below in a Python markdown code block. Ho, Ho, Ho! It's Christmas time and our friendly grandpa Santa Claus is busy distributing gifts to all the nice children. With the rising population, Santa's workload every year gets increased and he seeks your help to wrap the gifts with fancy wrapping ...
{"inputs": ["4"], "outputs": ["4 4 4 4 4 4 4\n4 3 3 3 3 3 4\n4 3 2 2 2 3 4\n4 3 2 1 2 3 4\n4 3 2 2 2 3 4\n4 3 3 3 3 3 4\n4 4 4 4 4 4 4"]}
coding
336
Solve the programming task below in a Python markdown code block. Dr .: Peter, I've finally done it. Peter: See you again? What kind of silly invention is this time? Dr .: I finally came up with a revolutionary way to process mathematical formulas on a computer. Look at this table. Ordinary notation | Dr.'s "breakth...
{"inputs": ["2 0 82 - /\n4 4 - 7 0 3 * + *\n0 0 1 + +", "1 0 82 - /\n4 4 - 7 0 3 * + *\n0 0 1 + +", "1 0 82 - /\n1 4 - 7 0 3 + + *\n0 0 1 + +", "1 0 82 - /\n1 4 - 7 0 3 * + *\n0 0 1 + +", "1 0 82 - /\n2 4 - 7 0 3 * + *\n0 0 1 + +", "1 0 82 - /\n2 4 - 7 0 3 * + *\n1 0 1 + +", "1 0 82 - /\n2 6 - 7 0 3 * + *\n1 0 1 + +", ...
coding
676
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an integer array nums and two integers k and p, return the number of distinct subarrays, which have at most k elements that are divisible by p. Two arrays nums1 and nums2 are said to be distinct if: They are of...
{"functional": "def check(candidate):\n assert candidate(nums = [2,3,3,2,2], k = 2, p = 2) == 11\n assert candidate(nums = [1,2,3,4], k = 4, p = 1) == 10\n\n\ncheck(Solution().countDistinct)"}
coding
144
Solve the programming task below in a Python markdown code block. You are given a string $t$ consisting of $n$ lowercase Latin letters and an integer number $k$. Let's define a substring of some string $s$ with indices from $l$ to $r$ as $s[l \dots r]$. Your task is to construct such string $s$ of minimum possible le...
{"inputs": ["1 1\na\n", "1 1\na\n", "1 50\nq\n", "2 4\naa\n", "2 2\noo\n", "2 2\naa\n", "2 1\naa\n", "2 2\nab\n"], "outputs": ["a\n", "a\n", "qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq\n", "aaaaa\n", "ooo\n", "aaa\n", "aa\n", "abab\n"]}
coding
299
Solve the programming task below in a Python markdown code block. The auditorium of Stanford University is made up of L*R matrix (assume each coordinate has a chair). On the occasion of an event Chef was called as a chief guest. The auditorium was filled with males (M) and females (F), occupying one chair each. Our Che...
{"inputs": ["4 3 3\nMMF\nMMM\nFFM\nFFM\n2 F\n3 M\n1 M"], "outputs": ["yes\nno\nyes"]}
coding
344
Solve the programming task below in a Python markdown code block. You are given an integer number $n$. The following algorithm is applied to it: if $n = 0$, then end algorithm; find the smallest prime divisor $d$ of $n$; subtract $d$ from $n$ and go to step $1$. Determine the number of subtrations the algorithm ...
{"inputs": ["5\n", "4\n", "2\n", "2\n", "6\n", "7\n", "8\n", "4\n"], "outputs": ["1\n", "2\n", "1\n", "1\n", "3\n", "1\n", "4\n", "2\n"]}
coding
198
Solve the programming task below in a Python markdown code block. Uh oh, Someone at the office has dropped all these sequences on the floor and forgotten to label them with their correct bases. We have to fix this before the boss gets back or we're all going to be fired! This is what your years of coding have been l...
{"functional": "_inputs = [[['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']], [['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']], [['1', '2', '3', '4', '5', '6', '10', '11', '12', '13']], [['301', '302', '303', '304', '305', '310', '311', '312', '313', '314']], [['50', '51', '61', '53', '54', '60', '52', '62', '5...
coding
357
Solve the programming task below in a Python markdown code block. # Definition A number is a **_Special Number_** *if it’s digits only consist 0, 1, 2, 3, 4 or 5* **_Given_** a number *determine if it special number or not* . # Warm-up (Highly recommended) # [Playing With Numbers Series](https://www.codewars.c...
{"functional": "_inputs = [[2], [3], [5], [9], [7], [23], [79], [32], [39], [55], [11350224]]\n_outputs = [['Special!!'], ['Special!!'], ['Special!!'], ['NOT!!'], ['NOT!!'], ['Special!!'], ['NOT!!'], ['Special!!'], ['NOT!!'], ['Special!!'], ['Special!!']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a...
coding
509
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 of even length. As long as nums is not empty, you must repetitively: Find the minimum number in nums and remove it. Find the maximum number in nums and remove it. Calculat...
{"functional": "def check(candidate):\n assert candidate(nums = [4,1,4,0,3,5]) == 2\n assert candidate(nums = [1,100]) == 1\n\n\ncheck(Solution().distinctAverages)"}
coding
183
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 ai and power level bi. When the i-th beacon is activated, it destroys all beacons to its left (direction of decreasing coordinates) within distance bi inclus...
{"inputs": ["1\n0 1\n", "1\n0 2\n", "1\n1 2\n", "1\n0 4\n", "1\n1 1\n", "1\n2 1\n", "1\n2 2\n", "1\n4 2\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]}
coding
454
Solve the programming task below in a Python markdown code block. Complete the solution. It should try to retrieve the value of the array at the index provided. If the index is out of the array's max bounds then it should return the default value instead. Example: ```Haskell solution [1..3] 1 1000 `shouldBe` 2 soluti...
{"functional": "_inputs = [[[None, None], 0, 'a']]\n_outputs = [[None]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) != len(b): return False\n ...
coding
338
Solve the programming task below in a Python markdown code block. Chef is throwing a party for his N friends. There is a pizza store nearby and he wants to buy pizza for his friends. Each pizza has exactly K slices. Chef's friends get sad if one gets more slices than the other. Also, Chef gets sad if there are some piz...
{"inputs": ["3\n2 2\n2 3\n4 2\n"], "outputs": ["1\n2\n2\n"]}
coding
552
Solve the programming task below in a Python markdown code block. There is a grid, consisting of $2$ rows and $m$ columns. The rows are numbered from $1$ to $2$ from top to bottom. The columns are numbered from $1$ to $m$ from left to right. The robot starts in a cell $(1, 1)$. In one second, it can perform either of ...
{"inputs": ["4\n3\n0 0 1\n4 3 2\n5\n0 4 8 12 16\n2 6 10 14 18\n4\n0 10 10 10\n10 10 10 10\n2\n0 0\n0 0\n"], "outputs": ["5\n19\n17\n3\n"]}
coding
574
Solve the programming task below in a Python markdown code block. We define the "unfairness" of a list/array as the *minimal* difference between max(x1,x2,...xk) and min(x1,x2,...xk), for all possible combinations of k elements you can take from the list/array; both minimum and maximum of an empty list/array are consid...
{"functional": "_inputs = [[[30, 100, 1000, 150, 60, 250, 10, 120, 20], 3], [[30, 100, 1000, 150, 60, 250, 10, 120, 20], 5], [[1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2], 10], [[1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2], 9], [[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], 10], [[1, 1, -1], 2], [[1, 1],...
coding
639
Solve the programming task below in a Python markdown code block. # Background: You're working in a number zoo, and it seems that one of the numbers has gone missing! Zoo workers have no idea what number is missing, and are too incompetent to figure it out, so they're hiring you to do it for them. In case the zoo lo...
{"functional": "_inputs = [[[2, 3, 4]], [[1, 3, 4]], [[1, 2, 4]], [[1, 2, 3]], [[]], [[1]], [[2]]]\n_outputs = [[1], [2], [3], [4], [1], [2], [1]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinst...
coding
216
Solve the programming task below in a Python markdown code block. It is a balmy spring afternoon, and Farmer John's n cows are ruminating about link-cut cacti in their stalls. The cows, labeled 1 through n, are arranged so that the i-th cow occupies the i-th stall from the left. However, Elsie, after realizing that she...
{"inputs": ["5 2\n", "1 1\n", "8 3\n", "7 1\n", "9 2\n", "1 2\n", "1 3\n", "1 4\n"], "outputs": ["10\n", "0\n", "27\n", "11\n", "26\n", "0\n", "0\n", "0\n"]}
coding
429
Solve the programming task below in a Python markdown code block. One of Chef's friends offered him a deal: during $D$ days, they are going to exchange money. For each $i$ ($1 \le i \le D$), on the $i$-th day, Chef's friend would give Chef $A$ rupees, while Chef would give his friend $2^{i-1}$ rupees ($1$ rupee on day ...
{"inputs": ["4\n5\n8\n9\n1000000000"], "outputs": ["4 3\n5 3\n5 4\n35 30"]}
coding
452
Solve the programming task below in a Python markdown code block. Given an array of integers and a target value, determine the number of pairs of array elements that have a difference equal to the target value. Example $k=1$ $arr=[1,2,3,4]$ There are three values that differ by $k=1$: $2-1=2$, $3-2=1$, and $...
{"inputs": ["5 2 \n1 5 3 4 2 \n"], "outputs": ["3\n"]}
coding
350
Solve the programming task below in a Python markdown code block. Kenkoooo found a simple connected graph. The vertices are numbered 1 through n. The i-th edge connects Vertex u_i and v_i, and has a fixed integer s_i. Kenkoooo is trying to write a positive integer in each vertex so that the following condition is sati...
{"inputs": ["4 3\n1 2 6\n2 3 7\n3 4 7", "3 3\n1 2 3\n2 3 0\n1 3 4", "4 3\n1 2 6\n2 3 7\n3 4 3", "4 3\n1 2 4\n2 3 7\n3 4 7", "4 3\n1 2 6\n2 3 7\n3 4 6", "4 3\n1 2 4\n2 3 1\n3 4 7", "4 3\n1 2 6\n2 3 7\n3 4 2", "4 3\n1 2 2\n2 3 7\n3 4 7"], "outputs": ["5\n", "0\n", "1\n", "3\n", "4\n", "0\n", "0\n", "1\n"]}
coding
419
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. Andrash study in Uzhland National University. Now is the time of exam results. Andrash similar to other students, hopes that this scores in the exam could fetch him a scholar...
{"inputs": ["2\n5\n3 5 4 4 3\n5\n3 4 4 4 5"], "outputs": ["No\nYes"]}
coding
552
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an array routes representing bus routes where routes[i] is a bus route that the ith bus repeats forever. For example, if routes[0] = [1, 5, 7], this means that the 0th bus travels in the sequence 1 -> 5...
{"functional": "def check(candidate):\n assert candidate(routes = [[1,2,7],[3,6,7]], source = 1, target = 6) == 2\n assert candidate(routes = [[7,12],[4,5,15],[6],[15,19],[9,12,13]], source = 15, target = 12) == -1\n\n\ncheck(Solution().numBusesToDestination)"}
coding
201
Solve the programming task below in a Python markdown code block. A string S of an odd length is said to be a strong palindrome if and only if all of the following conditions are satisfied: - S is a palindrome. - Let N be the length of S. The string formed by the 1-st through ((N-1)/2)-th characters of S is a palindr...
{"inputs": ["ddd\n", "gvg\n", "llvee", "elvle", "elvld", "elvdl", "eludl", "ldule"], "outputs": ["Yes\n", "Yes\n", "No\n", "No\n", "No\n", "No\n", "No\n", "No\n"]}
coding
248
Solve the programming task below in a Python markdown code block. You are given a permutation p_1, p_2, ... , p_n (an array where each integer from 1 to n appears exactly once). The weight of the i-th element of this permutation is a_i. At first, you separate your permutation into two non-empty sets — prefix and suffi...
{"inputs": ["2\n2 1\n9 5\n", "2\n1 2\n9 9\n", "2\n2 1\n14 5\n", "2\n2 1\n14 7\n", "2\n2 1\n14 3\n", "2\n2 1\n26 7\n", "2\n2 1\n28 7\n", "2\n1 2\n17 9\n"], "outputs": ["5\n", "0\n", "5\n", "7\n", "3\n", "7\n", "7\n", "0\n"]}
coding
599
Solve the programming task below in a Python markdown code block. Bob likes to draw camels: with a single hump, two humps, three humps, etc. He draws a camel by connecting points on a coordinate plane. Now he's drawing camels with t humps, representing them as polylines in the plane. Each polyline consists of n vertice...
{"inputs": ["4 9\n", "4 1\n", "3 2\n", "5 5\n", "3 3\n", "4 3\n", "5 3\n", "6 2\n"], "outputs": ["0\n", "22\n", "0\n", "0\n", "0\n", "0\n", "0\n", "232\n"]}
coding
448
Solve the programming task below in a Python markdown code block. $Gogi$, $Tapu$ and $Sonu$ are the elite members of $Tapu$ $Sena$. $Gogi$ is always stoned and asks absurd questions, But this time he asked a question which seems to be very serious and interesting. $Tapu$ wants to solve this question to impress $Sonu$. ...
{"inputs": ["1\n1\n2"], "outputs": ["2"]}
coding
355
Solve the programming task below in a Python markdown code block. You are a person who is always fond of eating candies. Your friend gave you a candy of length N, to eat during the break period of your school. You start eating this candy from one of the ends. But as it is not your candy, your friend told you to eat ex...
{"inputs": ["3\n3 1\n3 2\n0 3\n"], "outputs": ["3\n-1\n0\n"]}
coding
436
Solve the programming task below in a Python markdown code block. A jail has a number of prisoners and a number of treats to pass out to them. Their jailer decides the fairest way to divide the treats is to seat the prisoners around a circular table in sequentially numbered chairs. A chair number will be drawn from a...
{"inputs": ["2\n5 2 1\n5 2 2\n", "2\n7 19 2\n3 7 3\n"], "outputs": ["2\n3\n", "6\n3\n"]}
coding
722
Solve the programming task below in a Python markdown code block. Computation of the date either previous or forthcoming dates is quiet easy. But it is quiet difficult to calculate the day from a particular given date. You are required to find a day from a particular date given to you. -----Input----- It consists of ...
{"inputs": ["14 3 2012"], "outputs": ["Wednesday"]}
coding
162
Solve the programming task below in a Python markdown code block. Vasya wants to turn on Christmas lights consisting of m bulbs. Initially, all bulbs are turned off. There are n buttons, each of them is connected to some set of bulbs. Vasya can press any of these buttons. When the button is pressed, it turns on all the...
{"inputs": ["1 1\n0\n", "1 1\n0\n", "0 1\n0\n", "0 1\n1\n", "0 2\n1\n", "0 2\n0\n", "0 4\n0\n", "0 1\n-1\n"], "outputs": ["NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n"]}
coding
341
Solve the programming task below in a Python markdown code block. Bhallaladeva was an evil king who ruled the kingdom of Maahishmati. He wanted to erect a 100ft golden statue of himself and he looted gold from several places for this. He even looted his own people, by using the following unfair strategy: There are N ho...
{"inputs": ["4\n3 2 1 4\n2\n0\n2"], "outputs": ["10\n3"]}
coding
736
Solve the programming task below in a Python markdown code block. Jack decides to invite Emma out for a dinner. Jack is a modest student, he doesn't want to go to an expensive restaurant. Emma is a girl with high taste, she prefers elite places. Munhattan consists of n streets and m avenues. There is exactly one resta...
{"inputs": ["1 1\n1\n", "1 1\n1\n", "1 1\n1000000000\n", "1 1\n1000000000\n", "3 3\n1 2 3\n2 3 1\n3 1 2\n", "3 3\n0 2 3\n2 3 1\n3 1 2\n", "3 3\n0 2 3\n2 3 1\n5 1 2\n", "3 3\n0 2 3\n2 3 1\n5 1 1\n"], "outputs": ["1\n", "1\n", "1000000000\n", "1000000000\n", "1\n", "1\n", "1\n", "1\n"]}
coding
450
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an integer array nums. We call a subset of nums good if its product can be represented as a product of one or more distinct prime numbers. For example, if nums = [1, 2, 3, 4]: [2, 3], [1, 2, 3], and ...
{"functional": "def check(candidate):\n assert candidate(nums = [1,2,3,4]) == 6\n assert candidate(nums = [4,2,3,15]) == 5\n\n\ncheck(Solution().numberOfGoodSubsets)"}
coding
243
Solve the programming task below in a Python markdown code block. Sandy is a professor at a very reputed institute. The institute mandates that all the lectures be communicated in English. As Sandy is not very good at English(or anything actually) the presentations he displays in class have a lot of spelling mistakes i...
{"inputs": ["1\n5 2\nszhbdvrngk\nqzhxibnuec\njfsalpwfkospl\nlevjehdkjy\nwdfhzgatuh\nszhbdvcngk\nqzhxbnuec"], "outputs": ["szhbdvrngk\nqzhxibnuec"]}
coding
739
Solve the programming task below in a Python markdown code block. You have three piles of candies: red, green and blue candies: the first pile contains only red candies and there are $r$ candies in it, the second pile contains only green candies and there are $g$ candies in it, the third pile contains only blue cand...
{"inputs": ["6\n1 1 1\n2 4 1\n4 1 1\n7 4 7\n8 1 4\n8 2 8\n", "6\n1 1 1\n1 2 1\n4 1 1\n7 4 10\n8 1 4\n8 2 8\n", "6\n1 1 1\n1 2 1\n4 1 1\n7 7 10\n8 1 4\n8 2 8\n", "6\n1 1 1\n1 2 1\n4 1 1\n7 7 18\n8 1 4\n8 2 8\n", "6\n1 1 1\n2 2 1\n4 1 1\n7 4 10\n8 1 4\n8 2 8\n", "6\n1 1 1\n2 4 1\n4 1 1\n7 4 10\n8 1 4\n8 2 8\n", "6\n1 1 1...
coding
462
Solve the programming task below in a Python markdown code block. ## Task In this kata you'll be given a string of English digits "collapsed" together, like this: `zeronineoneoneeighttwoseventhreesixfourtwofive` Your task is to split the string back to digits: `zero nine one one eight two seven three six four two fi...
{"functional": "_inputs = [['three'], ['eightsix'], ['fivefourseven'], ['ninethreesixthree'], ['foursixeighttwofive'], ['fivethreefivesixthreenineonesevenoneeight'], ['threesevensevensixninenineninefiveeighttwofiveeightsixthreeeight'], ['zeroonetwothreefourfivesixseveneightnine']]\n_outputs = [['three'], ['eight six'],...
coding
164
Solve the programming task below in a Python markdown code block. As part of this Kata, you need to find the length of the sequence in an array, between the first and the second occurrence of a specified number. For example, for a given array `arr` [0, -3, 7, 4, 0, 3, 7, 9] Finding length between two `7`s li...
{"functional": "_inputs = [[[1], 0], [[1], 1], [[-7, 3, -7, -7, 2, 1], -7], [[-7, 3, -7, -7, 2, -7], -7]]\n_outputs = [[0], [0], [0], [0]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, ...
coding
196
Solve the programming task below in a Python markdown code block. Given $n$ strings, each of length $2$, consisting of lowercase Latin alphabet letters from 'a' to 'k', output the number of pairs of indices $(i, j)$ such that $i < j$ and the $i$-th string and the $j$-th string differ in exactly one position. In other ...
{"inputs": ["2\n1\nab\n1\ncf\n", "4\n6\nab\ncb\ndb\naa\ncc\nef\n7\naa\nbb\ncc\nac\nca\nbb\naa\n4\nkk\nkk\nab\nab\n5\njf\njf\njk\njk\njk\n"], "outputs": ["0\n0\n", "5\n6\n0\n6\n"]}
coding
650
Solve the programming task below in a Python markdown code block. Kate has a set $S$ of $n$ integers $\{1, \dots, n\} $. She thinks that imperfection of a subset $M \subseteq S$ is equal to the maximum of $gcd(a, b)$ over all pairs $(a, b)$ such that both $a$ and $b$ are in $M$ and $a \neq b$. Kate is a very neat g...
{"inputs": ["2\n", "3\n", "4\n", "5\n", "6\n", "6\n", "4\n", "5\n"], "outputs": ["1 ", "1 1 ", "1 1 2 ", "1 1 1 2 ", "1 1 1 2 3 ", "1 1 1 2 3", "1 1 2", "1 1 1 2"]}
coding
405
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. During the Indian Programming Camp (IPC), there are N trainers. The camp runs for D days. Each day, there can be at most one lecture. The i-th trainer arrives on day D_{i} an...
{"inputs": ["3\n2 3\n1 2 300\n2 2 100\n2 3\n1 1 100\n2 2 300\n2 3\n3 2 150\n1 1 200"], "outputs": ["100\n0\n150"]}
coding
731
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a 0-indexed 8 x 8 grid board, where board[r][c] represents the cell (r, c) on a game board. On the board, free cells are represented by '.', white cells are represented by 'W', and black cells are repres...
{"functional": "def check(candidate):\n assert candidate(board = [[\".\",\".\",\".\",\"B\",\".\",\".\",\".\",\".\"],[\".\",\".\",\".\",\"W\",\".\",\".\",\".\",\".\"],[\".\",\".\",\".\",\"W\",\".\",\".\",\".\",\".\"],[\".\",\".\",\".\",\"W\",\".\",\".\",\".\",\".\"],[\"W\",\"B\",\"B\",\".\",\"W\",\"W\",\"W\",\"B\"],[...
coding
292
Solve the programming task below in a Python markdown code block. With one die of 6 sides we will have six different possible results:``` 1, 2, 3, 4, 5, 6``` . With 2 dice of six sides, we will have 36 different possible results: ``` (1,1),(1,2),(2,1),(1,3),(3,1),(1,4),(4,1),(1,5), (5,1), (1,6),(6,1),(2,2),(2,3),(3,...
{"functional": "_inputs = [[[6, 6]], [[5, 6, 4]], [[3, 15, 8, 20]], [[6]], [[3, 3]], [[20]], [[3, 6]]]\n_outputs = [[3], [5], [44], [0], [0], [1], [0]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if i...
coding
695
Solve the programming task below in a Python markdown code block. -----Problem Statement----- Harry Potter has one biscuit and zero rupee in his pocket. He will perform the following operations exactly $K$ times in total, in the order he likes: - Hit his pocket, which magically increases the number of biscuits by one. ...
{"inputs": ["4 2 6"], "outputs": ["7"]}
coding
317
Please solve the programming task below using a self-contained code snippet in a markdown code block. Your country has an infinite number of lakes. Initially, all the lakes are empty, but when it rains over the nth lake, the nth lake becomes full of water. If it rains over a lake that is full of water, there will be a...
{"functional": "def check(candidate):\n assert candidate(rains = [1,2,3,4]) == [-1,-1,-1,-1]\n assert candidate(rains = [1,2,0,0,2,1]) == [-1,-1,2,1,-1,-1]\n assert candidate(rains = [1,2,0,1,2]) == []\n\n\ncheck(Solution().avoidFlood)"}
coding
263
Solve the programming task below in a Python markdown code block. Nuske has a grid with N rows and M columns of squares. The rows are numbered 1 through N from top to bottom, and the columns are numbered 1 through M from left to right. Each square in the grid is painted in either blue or white. If S_{i,j} is 1, the squ...
{"inputs": ["3 4 4\n1101\n0110\n1101\n1 1 3 4\n1 1 3 1\n2 2 3 4\n1 2 3 4", "3 4 4\n1101\n0110\n1101\n1 1 3 4\n2 1 3 1\n2 2 3 4\n1 2 2 4", "3 4 4\n1101\n0110\n1101\n1 1 3 4\n1 1 3 1\n2 2 3 4\n2 2 3 4", "3 4 4\n1101\n0110\n1101\n2 1 3 4\n2 1 3 1\n2 2 3 4\n1 2 2 4", "3 4 4\n1101\n1110\n1101\n1 1 3 4\n1 1 3 1\n2 2 3 4\n2 2...
coding
676
Solve the programming task below in a Python markdown code block. Given is a simple undirected graph with N vertices and M edges. Its vertices are numbered 1, 2, \ldots, N and its edges are numbered 1, 2, \ldots, M. On Vertex i (1 \leq i \leq N) two integers A_i and B_i are written. Edge i (1 \leq i \leq M) connects Ve...
{"inputs": ["4 2\n1 1 1 1\n1 1 -1 -1\n1 2\n3 4\n", "4 4\n4 1 2 3\n0 2 -3 1\n1 2\n2 3\n3 4\n4 2\n", "2 1\n273747 996499\n565109 -976650\n2 1\n", "4 6\n14121 332351 255931 165916\n198395 696843 64607 388580\n4 1\n4 2\n3 1\n4 3\n2 3\n2 1\n", "11 6\n826528 600459 788854 191285 93501 904786 49857 946608 481594 523737 115487...
coding
547
Solve the programming task below in a Python markdown code block. **This Kata is intended as a small challenge for my students** All Star Code Challenge #18 Create a function called that accepts 2 string arguments and returns an integer of the count of occurrences the 2nd argument is found in the first one. If no oc...
{"functional": "_inputs = [['hello', 'l'], ['hello', 'e'], ['codewars', 'c'], ['ggggg', 'g'], ['hello world', 'o']]\n_outputs = [[2], [1], [1], [5], [2]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if...
coding
130
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a large integer represented as an integer array digits, where each digits[i] is the ith digit of the integer. The digits are ordered from most significant to least significant in left-to-right order. The...
{"functional": "def check(candidate):\n assert candidate(digits = [1,2,3]) == [1,2,4]\n assert candidate(digits = [4,3,2,1]) == [4,3,2,2]\n assert candidate(digits = [0]) == [1]\n\n\ncheck(Solution().plusOne)"}
coding
117
Solve the programming task below in a Python markdown code block. Write a command line tool which takes a file path as input and prints the number of lines, number of words, number of characters in the file, userid of the owner of the file, groupid of owner of the file and last modification time of the file in UNIX tim...
{"inputs": ["/home/input\n"], "outputs": ["19\n402\n2612\n0\n0\n1358021928\n"]}
coding
193
Solve the programming task below in a Python markdown code block. Vasya and Petya are playing a simple game. Vasya thought of number x between 1 and n, and Petya tries to guess the number. Petya can ask questions like: "Is the unknown number divisible by number y?". The game is played by the following rules: first Pe...
{"inputs": ["1\n", "3\n", "2\n", "8\n", "5\n", "7\n", "9\n", "4\n"], "outputs": ["0\n", "2\n2 3\n", "1\n2\n", "6\n2 4 8 3 5 7\n", "4\n2 4 3 5\n", "5\n2 4 3 5 7\n", "7\n2 4 8 3 9 5 7\n", "3\n2 4 3 "]}
coding
400
Solve the programming task below in a Python markdown code block. For encrypting strings this region of chars is given (in this order!): * all letters (ascending, first all UpperCase, then all LowerCase) * all digits (ascending) * the following chars: `.,:;-?! '()$%&"` These are 77 chars! (This region is zero-based....
{"functional": "_inputs = [[\"$-Wy,dM79H'i'o$n0C&I.ZTcMJw5vPlZc Hn!krhlaa:khV mkL;gvtP-S7Rt1Vp2RV:wV9VuhO Iz3dqb.U0w\"], ['5MyQa9p0riYplZc'], [\"5MyQa79H'ijQaw!Ns6jVtpmnlZ.V6p\"], [''], [None]]\n_outputs = [['Do the kata \"Kobayashi-Maru-Test!\" Endless fun and excitement when finding a solution!'], ['This is a test!']...
coding
508
Solve the programming task below in a Python markdown code block. Implement `String#to_cents`, which should parse prices expressed as `$1.23` and return number of cents, or in case of bad format return `nil`. Also feel free to reuse/extend the following starter code: ```python def to_cents(amount): ```
{"functional": "_inputs = [[''], ['1'], ['1.23'], ['$1'], ['$1.23'], ['$99.99'], ['$12345678.90'], ['$9.69'], ['$9.70'], ['$9.71'], ['$1.23\\n'], ['\\n$1.23'], ['$0.69'], ['$9.69$4.3.7'], ['$9.692']]\n_outputs = [[None], [None], [None], [None], [123], [9999], [1234567890], [969], [970], [971], [None], [None], [69], [No...
coding
71
Solve the programming task below in a Python markdown code block. Our bear's forest has a checkered field. The checkered field is an n × n table, the rows are numbered from 1 to n from top to bottom, the columns are numbered from 1 to n from left to right. Let's denote a cell of the field on the intersection of row x a...
{"inputs": ["5 1 2 0 1 2\n", "1 1 1 1 1 0\n", "1 1 1 1 1 0\n", "5 1 1 0 1 2\n", "5 1 2 0 1 2\n", "1 1 1 -1 -1 2\n", "2 2 1 -2 -2 5\n", "2 2 1 -2 -2 5\n"], "outputs": ["3 1", "1 1", "1 1\n", "3 5\n", "3 1\n", "1 1", "1 2", "1 2\n"]}
coding
720
Solve the programming task below in a Python markdown code block. Joisino is planning to record N TV programs with recorders. The TV can receive C channels numbered 1 through C. The i-th program that she wants to record will be broadcast from time s_i to time t_i (including time s_i but not t_i) on Channel c_i. Here, t...
{"inputs": ["3 4\n1 3 2\n2 4 4\n1 4 3", "3 4\n1 3 2\n2 4 4\n1 5 3", "3 4\n1 3 2\n3 4 4\n1 4 3", "3 4\n1 3 2\n3 4 4\n1 4 3\n", "3 2\n1 7 2\n7 8 1\n8 12 1", "3 2\n1 7 2\n7 8 1\n8 12 1\n", "3 2\n1 7 2\n7 12 1\n8 12 1", "3 2\n2 7 2\n7 12 1\n8 12 1"], "outputs": ["3\n", "3\n", "3", "3\n", "2", "2\n", "2\n", "2\n"]}
coding
446
Solve the programming task below in a Python markdown code block. Brief ===== Sometimes we need information about the list/arrays we're dealing with. You'll have to write such a function in this kata. Your function must provide the following informations: * Length of the array * Number of integer items in the array ...
{"functional": "_inputs = [[[1, 2, 3.33, 4, 5.01, 'bass', 'kick', ' ']], [[0.001, 2, ' ']], [[]], [[' ']], [[' ', ' ']], [['jazz']], [[4]], [[3.1416]], [[11, 22, 33.33, 44.44, 'hasan', 'ahmad']], [['a', 'b', 'c', 'd', ' ']], [[1, 2, 3, 4, 5, 6, 7, 8, 9]], [[1, 2.23, 'string', ' ']]]\n_outputs = [[[[8], [3], [2], [2], [...
coding
398