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. For a positive integer n * If n is even, divide by 2. * If n is odd, multiply by 3 and add 1. If you repeat the above operation, the result will be 1. A problem called "Colatz conjecture" is that repeating this operation for any positive integer n wi...
{"inputs": ["3\n3\n0", "3\n2\n0", "3\n9\n0", "3\n6\n0", "3\n1\n0", "3\n0\n0", "3\n4\n0", "3\n5\n0"], "outputs": ["7\n7\n", "7\n1\n", "7\n19\n", "7\n8\n", "7\n0\n", "7\n", "7\n2\n", "7\n5\n"]}
coding
382
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 length n. nums contains a valid split at index i if the following are true: The sum of the first i + 1 elements is greater than or equal to the sum of the last n - i - ...
{"functional": "def check(candidate):\n assert candidate(nums = [10,4,-8,7]) == 2\n assert candidate(nums = [2,3,1,0]) == 2\n\n\ncheck(Solution().waysToSplitArray)"}
coding
142
Please solve the programming task below using a self-contained code snippet in a markdown code block. You have n dice, and each dice has k faces numbered from 1 to k. Given three integers n, k, and target, return the number of possible ways (out of the kn total ways) to roll the dice, so the sum of the face-up numbers...
{"functional": "def check(candidate):\n assert candidate(n = 1, k = 6, target = 3) == 1\n assert candidate(n = 2, k = 6, target = 7) == 6\n assert candidate(n = 30, k = 30, target = 500) == 222616187\n\n\ncheck(Solution().numRollsToTarget)"}
coding
135
Solve the programming task below in a Python markdown code block. Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well. Chef is taking a cooking exam. The exam consists of $N$ multiple-choice questions numbered $1$ through $N$. In each question, Chef may choose one ou...
{"inputs": ["3\n6\nABCDAB\nABCDAB\n8\nDDCABCCA\nDNCBBBBA\n3\nCDD\nNDC"], "outputs": ["6\n3\n1"]}
coding
701
Solve the programming task below in a Python markdown code block. One beautiful July morning a terrible thing happened in Mainframe: a mean virus Megabyte somehow got access to the memory of his not less mean sister Hexadecimal. He loaded there a huge amount of n different natural numbers from 1 to n to obtain total co...
{"inputs": ["1\n", "2\n", "7\n", "9\n", "3\n", "4\n", "6\n", "8\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n"]}
coding
201
Solve the programming task below in a Python markdown code block. An array is defined to be `inertial`if the following conditions hold: ``` a. it contains at least one odd value b. the maximum value in the array is even c. every odd value is greater than every even value that is not the maximum value. ``` eg:- ``` S...
{"functional": "_inputs = [[[]], [[581, -384, 140, -287]], [[11, 4, 20, 9, 2, 8]]]\n_outputs = [[False], [False], [True]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n...
coding
238
Solve the programming task below in a Python markdown code block. Problem statement When you heard that this year's KUPC can be joined as a team, you decided to talk to your friends and join as a team. Eventually, $ 4 $ people, including you, got together. Individual strength is expressed in ratings, and $ 4 $ perso...
{"inputs": ["2 1 3 6", "3 1 3 6", "3 0 3 6", "4 0 1 0", "6 0 1 0", "6 1 1 0", "3 0 3 2", "3 0 3 1"], "outputs": ["2\n", "1\n", "0\n", "3\n", "5\n", "4\n", "2\n", "1\n"]}
coding
413
Solve the programming task below in a Python markdown code block. Finally, after purchasing a water cooler during the April long challenge, Chef noticed that his water cooler requires 2 liters of water to cool for one hour. How much water (in liters) would be required by the cooler to cool for N hours? ------ Input F...
{"inputs": ["2\n1\n2"], "outputs": ["2\n4\n"]}
coding
260
Solve the programming task below in a Python markdown code block. You are given a mysterious language (codenamed "Secret") available in "Custom Test" tab. Find out what this language is and write a program which outputs its name. Note that the program must be written in this language. Input This program has only one ...
{"inputs": ["1\n"], "outputs": ["INTERCAL"]}
coding
95
Solve the programming task below in a Python markdown code block. Chef has some numbers. His girlfriend Chefina feels good when chef gives her a particular pattern number also called as Armstrong number. Armstrong number is a number whose sum of its all individual digit raise to the power of the number of digit in that...
{"inputs": ["3\n153\n11\n1634"], "outputs": ["FEELS GOOD\nFEELS BAD\nFEELS GOOD"]}
coding
343
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a string s that consists of lower case English letters and brackets. Reverse the strings in each pair of matching parentheses, starting from the innermost one. Your result should not contain any brackets...
{"functional": "def check(candidate):\n assert candidate(s = \"(abcd)\") == \"dcba\"\n assert candidate(s = \"(u(love)i)\") == \"iloveu\"\n assert candidate(s = \"(ed(et(oc))el)\") == \"leetcode\"\n assert candidate(s = \"a(bcdefghijkl(mno)p)q\") == \"apmnolkjihgfedcbq\"\n\n\ncheck(Solution().reverseParenth...
coding
89
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. In one operation, you can: Choose two different indices i and j such that 0 <= i, j < nums.length. Choose a non-negative integer k such that the kth bit (0-indexed) in th...
{"functional": "def check(candidate):\n assert candidate(nums = [4,3,1,2,4]) == 2\n assert candidate(nums = [1,10,4]) == 0\n\n\ncheck(Solution().beautifulSubarrays)"}
coding
189
Solve the programming task below in a Python markdown code block. You are given a positive integer $n$. You have to find $4$ positive integers $a, b, c, d$ such that $a + b + c + d = n$, and $\gcd(a, b) = \operatorname{lcm}(c, d)$. If there are several possible answers you can output any of them. It is possible to s...
{"inputs": ["5\n4\n7\n8\n9\n10\n"], "outputs": ["1 1 1 1\n4 1 1 1\n5 1 1 1\n6 1 1 1\n7 1 1 1\n"]}
coding
582
Solve the programming task below in a Python markdown code block. Chef has with him an array A of length N. In one move, he can delete any element from A. Find the minimum number of deletions Chef must make so that the following condition holds: Let B denote the resulting array, and M be the length of B. Then, B_{i} \...
{"inputs": ["4\n4\n2 2 2 2\n5\n3 4 3 4 4\n5\n1 2 3 4 0\n6\n5 5 5 6 6 6\n"], "outputs": ["0\n2\n3\n3\n"]}
coding
635
Solve the programming task below in a Python markdown code block. A palindrome is a string that reads the same backward as forward. For example, the strings ${z}$, ${aaa}$, ${aba}$, and ${abccba}$ are palindromes, but ${codeforces}$ and ${ab}$ are not. The double of a string $s$ is obtained by writing each character t...
{"inputs": ["4\na\nsururu\nerrorgorn\nanutforajaroftuna\n"], "outputs": ["aa\nsururuururus\nerrorgornnrogrorre\nanutforajaroftunaanutforajaroftuna\n"]}
coding
447
Solve the programming task below in a Python markdown code block. Let's denote the $f(x)$ function for a string $x$ as the number of distinct characters that the string contains. For example $f({abc}) = 3$, $f({bbbbb}) = 1$, and $f({babacaba}) = 3$. Given a string $s$, split it into two non-empty strings $a$ and $b$ s...
{"inputs": ["5\n2\naa\n7\nabcabcd\n5\naaaaa\n10\npaiumoment\n4\naazz\n"], "outputs": ["2\n7\n2\n10\n3\n"]}
coding
505
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an integer array nums, return the length of the longest strictly increasing subsequence.   Please complete the following python code precisely: ```python class Solution: def lengthOfLIS(self, nums: List[int]...
{"functional": "def check(candidate):\n assert candidate(nums = [10,9,2,5,3,7,101,18]) == 4\n assert candidate(nums = [0,1,0,3,2,3]) == 4\n assert candidate(nums = [7,7,7,7,7,7,7]) == 1\n\n\ncheck(Solution().lengthOfLIS)"}
coding
67
Solve the programming task below in a Python markdown code block. "The zombies are lurking outside. Waiting. Moaning. And when they come..." "When they come?" "I hope the Wall is high enough." Zombie attacks have hit the Wall, our line of defense in the North. Its protection is failing, and cracks are showing. In pl...
{"inputs": ["1 1\nB\n", "1 1\nB\n", "3 7\n.......\n.......\n.BB.B..\n", "4 5\n..B..\n..B..\nB.B.B\nBBB.B\n", "3 7\n.......\n..../..\n.BB.B..\n", "3 7\n.......\n....0..\n.BB.B..\n", "3 7\n.......\n..0....\n.BB.B..\n", "3 7\n.......\n..0....\n..B.BB.\n"], "outputs": ["1\n", "1\n", "2\n", "2\n", "2\n", "2\n", "2\n", "2\n"...
coding
492
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an array of strings words and a string pref. Return the number of strings in words that contain pref as a prefix. A prefix of a string s is any leading contiguous substring of s.   Please complete the fo...
{"functional": "def check(candidate):\n assert candidate(words = [\"pay\",\"attention\",\"practice\",\"attend\"], pref = \"at\") == 2\n assert candidate(words = [\"leetcode\",\"win\",\"loops\",\"success\"], pref = \"code\") == 0\n\n\ncheck(Solution().prefixCount)"}
coding
93
Solve the programming task below in a Python markdown code block. Chef has just found a recipe book, where every dish consists of exactly four ingredients. He is going to choose some two dishes and prepare them for dinner. Of course, he likes diversity and wants to know whether the two dishes are similar. Two dishes ar...
{"inputs": ["5\neggs sugar flour salt\nsugar eggs milk flour\naa ab ac ad\nac ad ae af\ncookies sugar grass lemon\nlemon meat chili wood\none two three four\none two three four\ngibberish jibberish lalalalala popopopopo\njibberisz gibberisz popopopopu lalalalalu"], "outputs": ["similar\nsimilar\ndissimilar\nsimilar\ndi...
coding
544
Please solve the programming task below using a self-contained code snippet in a markdown code block. A bit flip of a number x is choosing a bit in the binary representation of x and flipping it from either 0 to 1 or 1 to 0. For example, for x = 7, the binary representation is 111 and we may choose any bit (including...
{"functional": "def check(candidate):\n assert candidate(start = 10, goal = 7) == 3\n assert candidate(start = 3, goal = 4) == 3\n\n\ncheck(Solution().minBitFlips)"}
coding
195
Solve the programming task below in a Python markdown code block. Create a program that reads poker hand data and outputs the role for each. However, this issue follows the rules below. * Poker is a competition with 5 playing cards. * No more than 5 cards with the same number. * There is no joker. * Suppose you only c...
{"inputs": ["1,2,3,4,1\n2,3,1,3,12\n12,13,11,12,12\n7,6,7,6,7\n3,3,2,3,3\n6,7,8,9,10\n11,12,10,1,13\n11,12,13,1,2", "1,2,3,4,1\n2,3,1,3,12\n12,13,11,12,12\n7,6,7,6,7\n3,3,2,3,3\n6,7,8,9,10\n11,13,10,1,13\n11,12,13,1,2", "1,2,3,4,1\n2,3,1,3,12\n13,13,11,12,12\n7,6,7,6,7\n3,3,2,3,3\n6,7,8,9,10\n11,13,10,1,13\n11,12,13,1,...
coding
530
Solve the programming task below in a Python markdown code block. Let's call a sequence good if the sum of all its elements is $0$. You have a sequence of integers $A_1, A_2, \ldots, A_N$. You may perform any number of operations on this sequence (including zero). In one operation, you should choose a valid index $i$ a...
{"inputs": ["2\n1\n-1\n2\n1 2"], "outputs": ["NO\nYES"]}
coding
371
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an integer array nums and an integer k. Find the largest even sum of any subsequence of nums that has a length of k. Return this sum, or -1 if such a sum does not exist. A subsequence is an array that ca...
{"functional": "def check(candidate):\n assert candidate(nums = [4,1,5,3,1], k = 3) == 12\n assert candidate(nums = [4,6,2], k = 3) == 12\n assert candidate(nums = [1,3,5], k = 1) == -1\n\n\ncheck(Solution().largestEvenSum)"}
coding
126
Solve the programming task below in a Python markdown code block. You have a card deck of $n$ cards, numbered from top to bottom, i. e. the top card has index $1$ and bottom card — index $n$. Each card has its color: the $i$-th card has color $a_i$. You should process $q$ queries. The $j$-th query is described by inte...
{"inputs": ["5 1\n1 2 3 4 5\n1\n", "5 1\n1 2 3 4 5\n1\n", "5 1\n1 4 3 4 5\n1\n", "5 1\n1 2 3 4 5\n2\n", "5 1\n2 5 1 8 5\n1\n", "5 1\n1 4 3 4 6\n1\n", "5 1\n1 2 3 4 6\n1\n", "5 1\n1 4 3 5 5\n1\n"], "outputs": ["1 ", "1 ", "1 ", "2 ", "3 ", "1 ", "1 ", "1 "]}
coding
609
Solve the programming task below in a Python markdown code block. You are given an integer N. For two positive integers A and B, we will define F(A,B) as the larger of the following: the number of digits in the decimal notation of A, and the number of digits in the decimal notation of B. For example, F(3,11) = 2 sinc...
{"inputs": ["1\n", "56", "472", "010", "748", "395", "593", "101"], "outputs": ["1\n", "1\n", "2\n", "1\n", "2\n", "2\n", "3\n", "3\n"]}
coding
238
Solve the programming task below in a Python markdown code block. A palindrome is a word, phrase, number, or other sequence of characters which reads the same backward as forward. Examples of numerical palindromes are: `2332, 110011, 54322345` For a given number ```num```, write a function which returns an array of al...
{"functional": "_inputs = [[2], [34322122], [10015885], [4444], [1002001], [141221001], [1551], [13598], ['ACCDDCCA'], ['1551'], [-4505]]\n_outputs = [['No palindromes found'], [[22, 212, 343, 22122]], [[88, 1001, 5885]], [[44, 444, 4444]], [[1002001]], [[22, 141, 1001, 1221]], [[55, 1551]], ['No palindromes found'], [...
coding
407
Solve the programming task below in a Python markdown code block. Roger the Lion wants to help all his friends with passing exams. They need to solve the following problem to pass the IT exam. You've got string s = s1s2... sn (n is the length of the string), consisting only of characters "." and "#" and m queries. Eac...
{"inputs": ["#..###\n5\n1 3\n5 6\n1 5\n3 6\n3 4", "#.##.##.\n7\n1 8\n2 6\n2 6\n6 8\n3 5\n2 4\n2 5"], "outputs": ["1\n1\n2\n2\n0", "2\n1\n1\n1\n1\n1\n1"]}
coding
354
Solve the programming task below in a Python markdown code block. Implement a method that accepts 3 integer values a, b, c. The method should return true if a triangle can be built with the sides of given length and false in any other case. (In this case, all triangles must have surface greater than 0 to be accepted)....
{"functional": "_inputs = [[1, 2, 2], [7, 2, 2], [1, 2, 3], [1, 3, 2], [3, 1, 2], [5, 1, 2], [1, 2, 5], [2, 5, 1], [4, 2, 3], [5, 1, 5], [2, 2, 2], [-1, 2, 3], [1, -2, 3], [1, 2, -3], [0, 2, 3]]\n_outputs = [[True], [False], [False], [False], [False], [False], [False], [False], [True], [True], [True], [False], [False],...
coding
94
Solve the programming task below in a Python markdown code block. Luke, an intergalactic traveller went on a trip across the universe and got candies from the different planets he visited. He comes back with $N$ candies and decides to distribute them among his $M$ friends. However, Luke only wants a fair distribution o...
{"inputs": ["2 \n28 6 2 \n78 5 3"], "outputs": ["2\n1"]}
coding
382
Solve the programming task below in a Python markdown code block. You are given a binary string S of length N. You are allowed to perform the following types of operations on string S: Delete any one character from S, and concatenate the remaining parts of the string. For example, if we delete the third character of S ...
{"inputs": ["4\n2\n01\n3\n101\n3\n111\n4\n0000\n"], "outputs": ["1\n2\n1\n0\n"]}
coding
576
Solve the programming task below in a Python markdown code block. We like parsed SQL or PL/SQL blocks... You need to write function that return list of literals indices from source block, excluding "in" comments, OR return empty list if no literals found. input: some fragment of sql or pl/sql code output: list of li...
{"functional": "_inputs = [[\"select 'text' into row from table where a = 'value'\"], [\"if a>'data'and b<'nnn' then c:='test'; end if;\"], [\"select aaa, bbb, ccc, /*'ddd'?*/ into row from table;\"], [\"a:='data''s';\"]]\n_outputs = [[[[7, 13], [44, 51]]], [[[5, 11], [17, 22], [31, 37]]], [[]], [[[3, 12]]]]\nimport ma...
coding
354
Solve the programming task below in a Python markdown code block. You are given a grid with $n$ rows and $m$ columns, where each cell has a positive integer written on it. Let's call a grid good, if in each row the sequence of numbers is sorted in a non-decreasing order. It means, that for each $1 \le i \le n$ and $2 \...
{"inputs": ["1\n1 3\n2 1 1\n", "1\n1 5\n1 2 4 3 3\n", "1\n1 5\n1 3 2 2 4\n", "1\n1 7\n1 2 4 3 3 3 5\n", "1\n2 4\n2 1 1 1\n2 2 2 1\n", "5\n2 3\n1 2 3\n1 1 1\n2 2\n4 1\n2 3\n2 2\n2 1\n1 1\n2 3\n6 2 1\n5 4 3\n2 1\n1\n2\n", "4\n1 10\n1 2 3 2 2 2 2 2 3 3\n1 10\n1 2 3 3 3 3 3 2 3 3\n1 10\n1 2 3 3 3 3 2 2 3 3\n1 5\n1 4 3 2 5\...
coding
590
Solve the programming task below in a Python markdown code block. Aaron is struggling with trigonometric functions, so his teacher gave him extra homework. Given an integer, $n$, he must answer the following question: What is the maximum value of $sin(x)+sin(y)+sin(z)$, where $x}$, $y$, and $z$ are positive integers a...
{"inputs": ["3\n"], "outputs": ["2.524412954\n"]}
coding
256
Solve the programming task below in a Python markdown code block. Let us consider the following operations on a string consisting of A and B: - Select a character in a string. If it is A, replace it with BB. If it is B, replace with AA. - Select a substring that is equal to either AAA or BBB, and delete it from the s...
{"inputs": ["BBBAAAABA\nBBBBA\n4\n7 9 2 5\n7 9 1 4\n1 7 2 5\n1 6 2 4", "BBBAAAABA\nBBBBA\n4\n7 3 2 5\n7 9 1 4\n1 7 2 5\n1 6 2 4", "BBBAAAABA\nABBBB\n4\n7 9 2 5\n7 9 1 4\n1 7 2 5\n1 7 2 4", "BBBAAAABA\nABBBB\n4\n7 9 2 5\n7 9 1 4\n2 7 2 5\n1 7 2 4", "BBBAABABA\nBBBBA\n4\n7 3 2 5\n1 9 1 4\n1 7 2 5\n2 6 4 4", "BBBAABABA\nB...
coding
584
Solve the programming task below in a Python markdown code block. Read problems statements in mandarin chinese, russian and vietnamese as well. Chef's dog Snuffles has so many things to play with! This time around, Snuffles has an array A containing N integers: A_{1}, A_{2}, ..., A_{N}. Bad news: Snuffles only love...
{"inputs": ["3\n5 2\n1 4 5 2 3\n3 1\n1 4 1\n4 2\n3 4 3 5"], "outputs": ["3\n2\n-1"]}
coding
701
Solve the programming task below in a Python markdown code block. Maxim always goes to the supermarket on Sundays. Today the supermarket has a special offer of discount systems. There are m types of discounts. We assume that the discounts are indexed from 1 to m. To use the discount number i, the customer takes a spec...
{"inputs": ["1\n1\n1\n1\n", "1\n2\n1\n1\n", "1\n2\n1\n1\n", "1\n1\n1\n1\n", "1\n2\n1\n0\n", "1\n4\n1\n0\n", "1\n1\n3\n3 1 1\n", "1\n1\n3\n3 1 1\n"], "outputs": ["1\n", "1\n", "1", "1", "0\n", "0\n", "3\n", "3"]}
coding
573
Solve the programming task below in a Python markdown code block. Galya is playing one-dimensional Sea Battle on a 1 × n grid. In this game a ships are placed on the grid. Each of the ships consists of b consecutive cells. No cell can be part of two ships, however, the ships can touch each other. Galya doesn't know th...
{"inputs": ["1 1 1 0\n0\n", "1 1 1 0\n0\n", "2 2 1 0\n00\n", "2 2 1 0\n00\n", "5 1 2 1\n00100\n", "5 4 1 0\n00000\n", "5 1 2 1\n00100\n", "5 4 1 0\n00000\n"], "outputs": ["1\n1 \n", "1\n1 ", "1\n1 \n", "1\n1 \n", "2\n2 5 \n", "2\n1 2 \n", "2\n2 5\n", "2\n1 2 \n"]}
coding
530
Solve the programming task below in a Python markdown code block. Chef 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. Chef has a positive integer N. He c...
{"inputs": ["3\n4\n5\n0", "3\n0\n7\n61", "3\n0\n8\n24", "3\n0\n12\n5", "3\n3\n4\n70", "3\n32\n5\n7", "3\n1\n7\n44", "3\n1\n5\n44"], "outputs": ["0\n1\n1\n", "1\n0\n2\n", "1\n1\n1\n", "1\n2\n1\n", "1\n0\n1\n", "2\n1\n0\n", "1\n0\n0\n", "1\n1\n0\n"]}
coding
268
Solve the programming task below in a Python markdown code block. Chef wants to gift pairs to his friends this new year. But his friends like good pairs only. A pair (a , b) is called a good pair if 1 <= a < b <= N such that GCD(a*b , P) = 1. Since Chef is busy in preparation for the party, he wants your help to find a...
{"inputs": ["2\n2 3\n3 3\n\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014"], "outputs": ["1\n1"]}
coding
211
Solve the programming task below in a Python markdown code block. Not everyone probably knows that Chef has younder brother Jeff. Currently Jeff learns to read. He knows some subset of the letter of Latin alphabet. In order to help Jeff to study, Chef gave him a book with the text consisting of N words. Jeff can read a...
{"inputs": ["act\n2\ncat\ndog"], "outputs": ["Yes\nNo"]}
coding
373
Solve the programming task below in a Python markdown code block. Your task is to create a function called ```sum_arrays()``` in Python or ```addArrays``` in Javascript, which takes two arrays consisting of integers, and returns the sum of those two arrays. The twist is that (for example) ```[3,2,9]``` does not equal ...
{"functional": "_inputs = [[[3, 2, 9], [1, 2]], [[4, 7, 3], [1, 2, 3]], [[1], [5, 7, 6]], [[3, 2, 6, 6], [-7, 2, 2, 8]], [[-4, 5, 7, 3, 6], [5, 3, 4, 5]], [[], []], [[0], []], [[], [1, 2]], [[1, 4, 5], []], [[0], [0]]]\n_outputs = [[[3, 4, 1]], [[5, 9, 6]], [[5, 7, 7]], [[-3, 9, 6, 2]], [[-4, 0, 3, 9, 1]], [[]], [[0]],...
coding
359
Solve the programming task below in a Python markdown code block. We have weather records at AtCoder Town for some consecutive three days. A string of length 3, S, represents the records - if the i-th character is S, it means it was sunny on the i-th day; if that character is R, it means it was rainy on that day. Find ...
{"inputs": ["SRR", "RRR", "RSS", "SSR", "RST", "SRS", "TSR", "USR"], "outputs": ["2\n", "3\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n"]}
coding
189
Solve the programming task below in a Python markdown code block. Everybody knows the classic ["half your age plus seven"](https://en.wikipedia.org/wiki/Age_disparity_in_sexual_relationships#The_.22half-your-age-plus-seven.22_rule) dating rule that a lot of people follow (including myself). It's the 'recommended' age r...
{"functional": "_inputs = [[17], [40], [15], [35], [10], [53], [19], [12], [7], [33]]\n_outputs = [['15-20'], ['27-66'], ['14-16'], ['24-56'], ['9-11'], ['33-92'], ['16-24'], ['10-13'], ['6-7'], ['23-52']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return ...
coding
277
Solve the programming task below in a Python markdown code block. Tokitsukaze and CSL are playing a little game of stones. In the beginning, there are $n$ piles of stones, the $i$-th pile of which has $a_i$ stones. The two players take turns making moves. Tokitsukaze moves first. On each turn the player chooses a none...
{"inputs": ["1\n0\n", "1\n1\n", "1\n2\n", "1\n3\n", "1\n4\n", "1\n5\n", "1\n2\n", "1\n5\n"], "outputs": ["cslnb\n", "sjfnb\n", "cslnb\n", "sjfnb\n", "cslnb\n", "sjfnb\n", "cslnb\n", "sjfnb\n"]}
coding
737
Solve the programming task below in a Python markdown code block. You're on your way to the market when you hear beautiful music coming from a nearby street performer. The notes come together like you wouln't believe as the musician puts together patterns of tunes. As you wonder what kind of algorithm you could use to ...
{"functional": "_inputs = [['Your girlscout cookies are ready to ship. Your total comes to tree fiddy'], [\"Howdy Pardner. Name's Pete Lexington. I reckon you're the kinda stiff who carries about tree fiddy?\"], [\"I'm from Scottland. I moved here to be with my family sir. Please, $3.50 would go a long way to help me f...
coding
301
Solve the programming task below in a Python markdown code block. Every number may be factored in prime factors. For example, the number 18 may be factored by its prime factors ``` 2 ``` and ```3``` ``` 18 = 2 . 3 . 3 = 2 . 3² ``` The sum of the prime factors of 18 is ```2 + 3 + 3 = 8``` But some numbers like 70 are...
{"functional": "_inputs = [[10, 100], [80, 150], [90, 200]]\n_outputs = [[[16, 27, 30, 60, 70, 72, 84]], [[84, 105, 150]], [[105, 150, 180]]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(...
coding
399
Please solve the programming task below using a self-contained code snippet in a markdown code block. We know that 4 and 7 are lucky digits. Also, a number is called lucky if it contains only lucky digits. You are given an integer k, return the kth lucky number represented as a string.   Please complete the following ...
{"functional": "def check(candidate):\n assert candidate(k = 4) == \"47\"\n assert candidate(k = 10) == \"477\"\n assert candidate(k = 1000) == \"777747447\"\n\n\ncheck(Solution().kthLuckyNumber)"}
coding
97
Solve the programming task below in a Python markdown code block. Santa Claus decided to disassemble his keyboard to clean it. After he returned all the keys back, he suddenly realized that some pairs of keys took each other's place! That is, Santa suspects that each key is either on its place, or on the place of anoth...
{"inputs": ["a\nz\n", "y\ny\n", "z\nz\n", "a\nz\n", "z\na\n", "z\nz\n", "y\ny\n", "z\na\n"], "outputs": ["1\na z\n", "0\n", "0\n", "1\na z\n", "1\nz a\n", "0\n", "0\n", "1\nz a\n"]}
coding
422
Solve the programming task below in a Python markdown code block. Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well. Chef lives in a huge apartment building with $N$ floors, numbered $0$ (ground floor) through $N$ (terrace). Unfortunately, it has only one lift. We ...
{"inputs": ["1\n2 3\n1 2\n0 1\n1 0"], "outputs": ["6"]}
coding
621
Solve the programming task below in a Python markdown code block. You are given $q$ queries in the following form: Given three integers $l_i$, $r_i$ and $d_i$, find minimum positive integer $x_i$ such that it is divisible by $d_i$ and it does not belong to the segment $[l_i, r_i]$. Can you answer all the queries? Re...
{"inputs": ["1\n1 1 1\n", "1\n2 5 6\n", "1\n5 5 5\n", "1\n6 6 6\n", "1\n1 3 2\n", "1\n6 6 6\n", "1\n1 1 1\n", "1\n1 3 2\n"], "outputs": ["2\n", "6\n", "10\n", "12\n", "4\n", "12\n", "2\n", "4\n"]}
coding
285
Solve the programming task below in a Python markdown code block. Converting a normal (12-hour) time like "8:30 am" or "8:30 pm" to 24-hour time (like "0830" or "2030") sounds easy enough, right? Well, let's see if you can do it! You will have to define a function named "to24hourtime", and you will be given an hour (...
{"functional": "_inputs = [[12, 0, 'am'], [12, 1, 'am'], [12, 2, 'am'], [12, 3, 'am'], [12, 4, 'am'], [12, 5, 'am'], [12, 6, 'am'], [12, 7, 'am'], [12, 8, 'am'], [12, 9, 'am'], [12, 10, 'am'], [12, 11, 'am'], [12, 12, 'am'], [12, 13, 'am'], [12, 14, 'am'], [12, 15, 'am'], [12, 16, 'am'], [12, 17, 'am'], [12, 18, 'am'],...
coding
196
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an array of positive integers arr, find a pattern of length m that is repeated k or more times. A pattern is a subarray (consecutive sub-sequence) that consists of one or more values, repeated multiple times con...
{"functional": "def check(candidate):\n assert candidate(arr = [1,2,4,4,4,4], m = 1, k = 3) == True\n assert candidate(arr = [1,2,1,2,1,1,1,3], m = 2, k = 2) == True\n assert candidate(arr = [1,2,1,2,1,3], m = 2, k = 3) == False\n assert candidate(arr = [1,2,3,1,2], m = 2, k = 2) == False\n assert candid...
coding
143
Solve the programming task below in a Python markdown code block. Iahub got bored, so he invented a game to be played on paper. He writes n integers a_1, a_2, ..., a_{n}. Each of those integers can be either 0 or 1. He's allowed to do exactly one move: he chooses two indices i and j (1 ≤ i ≤ j ≤ n) and flips all valu...
{"inputs": ["1\n1\n", "1\n0\n", "1\n0\n", "1\n1\n", "2\n1 1\n", "2\n1 1\n", "2\n0 0\n", "4\n1 0 0 1\n"], "outputs": ["0\n", "1\n", "1", "0\n", "1\n", "1\n", "2\n", "4\n"]}
coding
398
Solve the programming task below in a Python markdown code block. $m$ chairs are arranged in a circle sequentially. The chairs are numbered from $0$ to $m-1$. $n$ people want to sit in these chairs. The $i$-th of them wants at least $a[i]$ empty chairs both on his right and left side. More formally, if the $i$-th pers...
{"inputs": ["6\n3 2\n1 1 1\n2 4\n1 1\n2 5\n2 1\n3 8\n1 2 1\n4 12\n1 2 1 3\n4 19\n1 2 1 3\n"], "outputs": ["NO\nYES\nNO\nYES\nNO\nYES\n"]}
coding
689
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin Chinese here ------ Problem Statement ------ As we know, Fibonacci Number is defined as F_{n}=n if n ≤ 1 F_{n}=F_{n-1}+F_{n-2}, otherwise Now this problem is quite simple: you are given one prime number P a...
{"inputs": ["4\n0 11\n16 19\n18 19\n4 19"], "outputs": ["0\n14\n16\n-1"]}
coding
436
Solve the programming task below in a Python markdown code block. # Task Yesterday you found some shoes in your room. Each shoe is described by two values: ``` type indicates if it's a left or a right shoe; size is the size of the shoe. ``` Your task is to check whether it is possible to pair the shoes you found in s...
{"functional": "_inputs = [[[[0, 21], [1, 23], [1, 21], [0, 23]]], [[[0, 21], [1, 23], [1, 21], [1, 23]]], [[[0, 23], [1, 21], [1, 23], [0, 21], [1, 22], [0, 22]]], [[[0, 23], [1, 21], [1, 23], [0, 21]]], [[[0, 23], [1, 21], [1, 22], [0, 21]]], [[[0, 23]]], [[[0, 23], [1, 23]]], [[[0, 23], [1, 23], [1, 23], [0, 23]]], ...
coding
333
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a string s, partition s such that every substring of the partition is a palindrome. Return the minimum cuts needed for a palindrome partitioning of s.   Please complete the following python code precisely: ```py...
{"functional": "def check(candidate):\n assert candidate(s = \"aab\") == 1\n assert candidate(s = \"a\") == 0\n assert candidate(s = \"ab\") == 1\n\n\ncheck(Solution().minCut)"}
coding
78
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given the root of a binary tree and an integer distance. A pair of two different leaf nodes of a binary tree is said to be good if the length of the shortest path between them is less than or equal to distance...
{"functional": "def check(candidate):\n assert candidate(root = tree_node([1,2,3,None,4]), distance = 3) == 1\n assert candidate(root = tree_node([1,2,3,4,5,6,7]), distance = 3) == 2\n assert candidate(root = tree_node([7,1,4,6,None,5,3,None,None,None,None,None,2]), distance = 3) == 1\n assert candidate(roo...
coding
162
Solve the programming task below in a Python markdown code block. Manao is taking part in a quiz. The quiz consists of n consecutive questions. A correct answer gives one point to the player. The game also has a counter of consecutive correct answers. When the player answers a question correctly, the number on this cou...
{"inputs": ["2 0 2\n", "2 2 2\n", "3 2 2\n", "2 1 2\n", "3 3 2\n", "2 2 3\n", "3 3 3\n", "6 3 2\n"], "outputs": [" 0", " 4", " 2", " ...
coding
543
Solve the programming task below in a Python markdown code block. Snuke lives on an infinite two-dimensional plane. He is going on an N-day trip. At the beginning of Day 1, he is at home. His plan is described in a string S of length N. On Day i(1 ≦ i ≦ N), he will travel a positive distance in the following direction:...
{"inputs": ["S", "W", "SEWN", "NNDW", "ESWN", "WNES", "NEWS", "ENWS"], "outputs": ["No\n", "No", "Yes\n", "No\n", "Yes\n", "Yes\n", "Yes\n", "Yes\n"]}
coding
300
Solve the programming task below in a Python markdown code block. A bracket sequence is a string containing only characters "(" and ")". A regular bracket sequence is a bracket sequence that can be transformed into a correct arithmetic expression by inserting characters "1" and "+" between the original characters of t...
{"inputs": ["1\n)(\n", "1\n()\n", "1\n)(\n", "1\n()\n", "1\n((\n", "1\n))\n", "2\n()\n()\n", "2\n((\n))\n"], "outputs": ["0\n", "1\n", "0\n", "1\n", "0\n", "0\n", "4\n", "1\n"]}
coding
475
Solve the programming task below in a Python markdown code block. # Description: Count the number of exclamation marks and question marks, return the product. # Examples ``` Product("") == 0 product("!") == 0 Product("!ab? ?") == 2 Product("!!") == 0 Product("!??") == 2 Product("!???") == 3 Product("!!!??") == 6 Pr...
{"functional": "_inputs = [[''], ['!'], ['!!??!!']]\n_outputs = [[0], [0], [8]]\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\...
coding
143
Solve the programming task below in a Python markdown code block. You are given a binary array$^{\dagger}$ of length $n$. You are allowed to perform one operation on it at most once. In an operation, you can choose any element and flip it: turn a $0$ into a $1$ or vice-versa. What is the maximum number of inversions$^...
{"inputs": ["5\n4\n1 0 1 0\n6\n0 1 0 0 1 0\n2\n0 0\n8\n1 0 1 1 0 0 0 1\n3\n1 1 1\n"], "outputs": ["3\n7\n1\n13\n2\n"]}
coding
635
Please solve the programming task below using a self-contained code snippet in a markdown code block. The letter value of a letter is its position in the alphabet starting from 0 (i.e. 'a' -> 0, 'b' -> 1, 'c' -> 2, etc.). The numerical value of some string of lowercase English letters s is the concatenation of the let...
{"functional": "def check(candidate):\n assert candidate(firstWord = \"acb\", secondWord = \"cba\", targetWord = \"cdb\") == True\n assert candidate(firstWord = \"aaa\", secondWord = \"a\", targetWord = \"aab\") == False\n assert candidate(firstWord = \"aaa\", secondWord = \"a\", targetWord = \"aaaa\") == True...
coding
228
Solve the programming task below in a Python markdown code block. A word from the English dictionary is taken and arranged as a matrix. e.g. "MATHEMATICS" MATHE ATHEM THEMA HEMAT EMATI MATIC ATICS There are many ways to trace this matrix in a way that helps you construct this word. You start tracing the...
{"inputs": ["1\n2 3\n"], "outputs": ["3\n"]}
coding
379
Solve the programming task below in a Python markdown code block. Given are integers N and K. How many quadruples of integers (a,b,c,d) satisfy both of the following conditions? - 1 \leq a,b,c,d \leq N - a+b-c-d=K -----Constraints----- - 1 \leq N \leq 10^5 - -2(N-1) \leq K \leq 2(N-1) - All numbers in input are i...
{"inputs": ["2 1\n", "1 0\n", "2525 -425\n", "23294 13184\n", "97692 12674\n", "24115 24178\n", "66977 75123\n", "13582 27162\n"], "outputs": ["4\n", "1\n", "10314607400\n", "5523272501050\n", "606889464360839\n", "2319008467426\n", "33936530568560\n", "1\n"]}
coding
215
Solve the programming task below in a Python markdown code block. The [Ones' Complement](https://en.wikipedia.org/wiki/Ones%27_complement) of a binary number is the number obtained by swapping all the 0s for 1s and all the 1s for 0s. For example: ``` onesComplement(1001) = 0110 onesComplement(1001) = 0110 ``` For any...
{"functional": "_inputs = [['0'], ['1'], ['01'], ['10'], ['1101']]\n_outputs = [['1'], ['0'], ['10'], ['01'], ['0010']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n ...
coding
149
Please solve the programming task below using a self-contained code snippet in a markdown code block. In English, we have a concept called root, which can be followed by some other word to form another longer word - let's call this word derivative. For example, when the root "help" is followed by the word "ful", we ca...
{"functional": "def check(candidate):\n assert candidate(dictionary = [\"cat\",\"bat\",\"rat\"], sentence = \"the cattle was rattled by the battery\") == \"the cat was rat by the bat\"\n assert candidate(dictionary = [\"a\",\"b\",\"c\"], sentence = \"aadsfasf absbs bbab cadsfafs\") == \"a a b c\"\n\n\ncheck(Solut...
coding
169
Solve the programming task below in a Python markdown code block. The aim of this kata is to split a given string into different strings of equal size (note size of strings is passed to the method) Example: Split the below string into other strings of size #3 'supercalifragilisticexpialidocious' Will re...
{"functional": "_inputs = [['supercalifragilisticexpialidocious', 3], ['HelloKata', 1], ['HelloKata', 9]]\n_outputs = [['sup erc ali fra gil ist ice xpi ali doc iou s'], ['H e l l o K a t a'], ['HelloKata']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n retur...
coding
147
Solve the programming task below in a Python markdown code block. You have three tasks, all of which need to be completed. First, you can complete any one task at cost 0. Then, just after completing the i-th task, you can complete the j-th task at cost |A_j - A_i|. Here, |x| denotes the absolute value of x. Find the mi...
{"inputs": ["3 5 2", "4 3 2", "4 3 0", "5 3 0", "0 1 6", "1 1 8", "0 1 8", "1 6 3"], "outputs": ["3\n", "2\n", "4\n", "5\n", "6\n", "7\n", "8\n", "5"]}
coding
233
Solve the programming task below in a Python markdown code block. The Smart Beaver from ABBYY began to develop a new educational game for children. The rules of the game are fairly simple and are described below. The playing field is a sequence of n non-negative integers ai numbered from 1 to n. The goal of the game i...
{"inputs": ["4\n1 0 0 2\n", "4\n0 0 0 1\n", "4\n1 0 0 1\n", "4\n1 0 1 2\n", "5\n4 1 4 7 6\n", "5\n2 1 4 7 6\n", "5\n2 1 4 4 6\n", "5\n2 1 4 1 6\n"], "outputs": ["1\n1\n2\n", "0\n0\n0\n", "1\n1\n2\n", "1\n1\n3\n", "4\n5\n9\n17\n", "2\n3\n7\n15\n", "2\n3\n7\n12\n", "2\n3\n7\n9\n"]}
coding
583
Please solve the programming task below using a self-contained code snippet in a markdown code block. We have n chips, where the position of the ith chip is position[i]. We need to move all the chips to the same position. In one step, we can change the position of the ith chip from position[i] to: position[i] + 2 or ...
{"functional": "def check(candidate):\n assert candidate(position = [1,2,3]) == 1\n assert candidate(position = [2,2,2,3,3]) == 2\n assert candidate(position = [1,1000000000]) == 1\n\n\ncheck(Solution().minCostToMoveChips)"}
coding
152
Solve the programming task below in a Python markdown code block. Hooray! Polycarp turned $n$ years old! The Technocup Team sincerely congratulates Polycarp! Polycarp celebrated all of his $n$ birthdays: from the $1$-th to the $n$-th. At the moment, he is wondering: how many times he turned beautiful number of years? ...
{"inputs": ["6\n18\n1\n9\n100500\n33\n1000000000\n"], "outputs": ["10\n1\n9\n45\n12\n81\n"]}
coding
456
Solve the programming task below in a Python markdown code block. # Number encrypting: cypher ## Part I of Number encrypting Katas *** ## Introduction Back then when the internet was coming up, most search functionalities simply looked for keywords in text to show relevant documents. Hackers weren't very keen on havin...
{"functional": "_inputs = [['Hello World'], ['I am your father'], ['I do not know what else I can test. Be cool. Good luck'], ['IlRzEeAaSsGbTtBgOo'], ['']]\n_outputs = [['H3110 W0r1d'], ['1 4m y0ur f47h3r'], ['1 d0 n07 kn0w wh47 3153 1 c4n 7357. 83 c001. 600d 1uck'], ['112233445566778900'], ['']]\nimport math\ndef _dee...
coding
678
Solve the programming task below in a Python markdown code block. Create a function `longer` that accepts a string and sorts the words in it based on their respective lengths in an ascending order. If there are two words of the same lengths, sort them alphabetically. Look at the examples below for more details. ```pyt...
{"functional": "_inputs = [['Another Green World'], ['Darkness on the edge of Town'], ['Have you ever Seen the Rain'], ['Like a Rolling Stone'], ['This will be our Year'], ['hello Hello']]\n_outputs = [['Green World Another'], ['of on the Town edge Darkness'], ['the you Have Rain Seen ever'], ['a Like Stone Rolling'], ...
coding
198
Solve the programming task below in a Python markdown code block. As we all know, a palindrome is a word that equals its reverse. Here are some examples of palindromes: malayalam, gag, appa, amma. We consider any sequence consisting of the letters of the English alphabet to be a word. So axxb,abbba and bbbccddx are wor...
{"inputs": ["5\nabbba", "12\nabcbcabbacba"], "outputs": ["5\nabbba", "8\nbcabbacb"]}
coding
440
Solve the programming task below in a Python markdown code block. William really likes the cellular automaton called "Game of Life" so he decided to make his own version. For simplicity, William decided to define his cellular automaton on an array containing $n$ cells, with each cell either being alive or dead. Evolut...
{"inputs": ["1\n5 3017\n10011\n", "1\n5 42069\n11011\n", "1\n5 42069\n11011\n", "1\n5 45215\n01101\n", "1\n5 35184\n11011\n", "1\n5 21557\n11011\n", "1\n5 21557\n10011\n", "1\n5 55375\n11011\n"], "outputs": ["11111\n", "11011\n", "11011\n", "11101\n", "11011\n", "11011\n", "11111\n", "11011\n"]}
coding
670
Solve the programming task below in a Python markdown code block. You're writing an excruciatingly detailed alternate history novel set in a world where [Daniel Gabriel Fahrenheit](https://en.wikipedia.org/wiki/Daniel_Gabriel_Fahrenheit) was never born. Since Fahrenheit never lived the world kept on using the [Rømer s...
{"functional": "_inputs = [[24], [8], [29]]\n_outputs = [[20.1], [11.7], [22.725]]\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 Fal...
coding
234
Solve the programming task below in a Python markdown code block. Given an array of integers your solution should find the smallest integer. For example: - Given `[34, 15, 88, 2]` your solution will return `2` - Given `[34, -345, -1, 100]` your solution will return `-345` You can assume, for the purpose of this kat...
{"functional": "_inputs = [[[78, 56, 232, 12, 11, 43]], [[78, 56, -2, 12, 8, -33]], [[0, -18446744073709551615, 18446744073709551616]], [[-133, -5666, -89, -12341, -321423, 18446744073709551616]], [[0, 18446744073709551616, -18446744073709551617, 18446744073709551616, 18446744073709551616]], [[1, 2, 3, 4, 5, 6, 7, 8, 9...
coding
127
Solve the programming task below in a Python markdown code block. A new Berland businessman Vitaly is going to open a household appliances' store. All he's got to do now is to hire the staff. The store will work seven days a week, but not around the clock. Every day at least k people must work in the store. Berland h...
{"inputs": ["5 1 1\n", "2 2 2\n", "4 1 2\n", "4 2 2\n", "4 4 2\n", "4 1 1\n", "3 3 2\n", "2 2 5\n"], "outputs": ["2\n1 5\n", "5\n1 1 2 3 4\n", "4\n1 1 4 5\n", "4\n1 1 4 5\n", "5\n1 1 4 5 8\n", "2\n1 4\n", "5\n1 1 3 4 6\n", "11\n1 1 1 1 1 2 3 3 3 3 4\n"]}
coding
595
Solve the programming task below in a Python markdown code block. Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. One day Petya encountered a tree w...
{"inputs": ["2\n1 2 7\n", "2\n1 2 4\n", "2\n1 2 2\n", "2\n1 2 12\n", "2\n2 1 1000000000\n", "2\n2 1 1000010000\n", "2\n2 1 1001010000\n", "4\n1 2 4\n3 1 1\n1 4 7\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "16\n"]}
coding
638
Solve the programming task below in a Python markdown code block. Today there is going to be an unusual performance at the circus — hamsters and tigers will perform together! All of them stand in circle along the arena edge and now the trainer faces a difficult task: he wants to swap the animals' positions so that all ...
{"inputs": ["2\nTH\n", "2\nHT\n", "3\nHHT\n", "3\nTHH\n", "3\nHTH\n", "4\nHTHT\n", "4\nHTTH\n", "4\nTTHH\n"], "outputs": ["0", "0\n", "0\n", "0\n", "0", "1", "0", "0\n"]}
coding
419
Solve the programming task below in a Python markdown code block. Remove the parentheses = In this kata you are given a string for example: ```python "example(unwanted thing)example" ``` Your task is to remove everything inside the parentheses as well as the parentheses themselves. The example above would return: `...
{"functional": "_inputs = [['example(unwanted thing)example'], ['example (unwanted thing) example'], ['a (bc d)e'], ['a(b(c))'], ['hello example (words(more words) here) something'], ['(first group) (second group) (third group)']]\n_outputs = [['exampleexample'], ['example example'], ['a e'], ['a'], ['hello example s...
coding
132
Solve the programming task below in a Python markdown code block. You are given n integer numbers a_1, a_2, ..., a_n. Consider graph on n nodes, in which nodes i, j (i≠ j) are connected if and only if, a_i AND a_j≠ 0, where AND denotes the [bitwise AND operation](https://en.wikipedia.org/wiki/Bitwise_operation#AND). F...
{"inputs": ["3\n5 5 5\n", "3\n1 1 3\n", "3\n2 5 5\n", "3\n1 1 2\n", "4\n1 2 4 8\n", "4\n3 6 28 9\n", "5\n25 3 44 6 48\n", "5\n49 3 6 44 24\n"], "outputs": ["3\n", "3\n", "-1\n", "-1\n", "-1\n", "4\n", "3\n", "3\n"]}
coding
299
Solve the programming task below in a Python markdown code block. A famous student of AESC MSU, as you know, comes from Kostomuksha. Kostomuksha has a popular game called Doka. The essence of Doka is as follows: You are given an array A and an integer X. You want to calculate how many subarrays of this array have a g...
{"inputs": ["3\n3 3\n3 3 3\n4 4\n1 2 3 4\n4 54\n36 81 54 54"], "outputs": ["6\n1\n6"]}
coding
666
Solve the programming task below in a Python markdown code block. You have an array of integers (initially empty). You have to perform $q$ queries. Each query is of one of two types: "$1$ $x$" — add the element $x$ to the end of the array; "$2$ $x$ $y$" — replace all occurrences of $x$ in the array with $y$. Find t...
{"inputs": ["1\n1 8\n", "1\n1 6\n", "1\n1 3\n", "1\n1 5\n", "1\n1 1\n", "1\n1 4\n", "1\n1 9\n", "1\n1 2\n"], "outputs": ["8", "6", "3", "5", "1", "4", "9", "2"]}
coding
674
Solve the programming task below in a Python markdown code block. Create a function that takes a number and finds the factors of it, listing them in **descending** order in an **array**. If the parameter is not an integer or less than 1, return `-1`. In C# return an empty array. For Example: `factors(54)` should retu...
{"functional": "_inputs = [[-4], [0], [-12], ['a'], [4.5], ['hello world'], [54], [49], [1]]\n_outputs = [[-1], [-1], [-1], [-1], [-1], [-1], [[54, 27, 18, 9, 6, 3, 2, 1]], [[49, 7, 1]], [[1]]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose...
coding
125
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given two integer arrays nums1 and nums2. We write the integers of nums1 and nums2 (in the order they are given) on two separate horizontal lines. We may draw connecting lines: a straight line connecting two n...
{"functional": "def check(candidate):\n assert candidate(nums1 = [1,4,2], nums2 = [1,2,4]) == 2\n assert candidate(nums1 = [2,5,1,2,5], nums2 = [10,5,2,1,5,2]) == 3\n assert candidate(nums1 = [1,3,7,1,7,5], nums2 = [1,9,2,5,1]) == 2\n\n\ncheck(Solution().maxUncrossedLines)"}
coding
184
Solve the programming task below in a Python markdown code block. It's that time of the year when the Russians flood their countryside summer cottages (dachas) and the bus stop has a lot of people. People rarely go to the dacha on their own, it's usually a group, so the people stand in queue by groups. The bus stop qu...
{"inputs": ["1 5\n4\n", "1 5\n4\n", "1 73\n24\n", "2 6\n1 4\n", "2 5\n5 5\n", "2 6\n1 4\n", "2 5\n5 5\n", "1 73\n24\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "2\n", "1\n", "2\n", "1\n"]}
coding
323
Solve the programming task below in a Python markdown code block. \textit {Life is change, change is stability.} Chef calls a sequence of integers A_{1}, A_{2}, \ldots, A_{N} stable if all the elements in the sequence are equal. Chef gives you a sequence A_{1}, A_{2}, \ldots, A_{N}. You may perform the following ope...
{"inputs": ["2\n3\n1 1 1\n2\n69 96"], "outputs": ["0\n1"]}
coding
568
Solve the programming task below in a Python markdown code block. You should write a function that takes a string and a positive integer `n`, splits the string into parts of length `n` and returns them in an array. It is ok for the last element to have less than `n` characters. If `n` is not a valid size (`> 0`) (or i...
{"functional": "_inputs = [['codewars', 2]]\n_outputs = [[['co', 'de', 'wa', 'rs']]]\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 F...
coding
226
Solve the programming task below in a Python markdown code block. Petya loves hockey very much. One day, as he was watching a hockey match, he fell asleep. Petya dreamt of being appointed to change a hockey team's name. Thus, Petya was given the original team name w and the collection of forbidden substrings s1, s2, .....
{"inputs": ["3\na\nA\na\nA\nb\n", "3\na\nA\na\nA\na\n", "3\na\nA\nb\nA\nb\n", "3\na\nA\nb\nB\na\n", "3\na\nA\na\nB\na\n", "3\nb\nA\nb\nA\nb\n", "3\nab\nBa\naB\nABBA\nl\n", "3\nab\nBa\naB\nABBA\na\n"], "outputs": ["B\n", "B\n", "B\n", "A\n", "B\n", "B\n", "LLLL\n", "BAAB\n"]}
coding
693
Solve the programming task below in a Python markdown code block. One rainy gloomy evening when all modules hid in the nearby cafes to drink hot energetic cocktails, the Hexadecimal virus decided to fly over the Mainframe to look for a Great Idea. And she has found one! Why not make her own Codeforces, with blackjack ...
{"inputs": ["6\n", "5\n", "9\n", "2\n", "1\n", "3\n", "4\n", "8\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]}
coding
507
Solve the programming task below in a Python markdown code block. Takahashi has a strong stomach. He never gets a stomachache from eating something whose "best-by" date is at most X days earlier. He gets a stomachache if the "best-by" date of the food is X+1 or more days earlier, though. Other than that, he finds the f...
{"inputs": ["0 3 6", "6 5 0", "4 2 6", "1 3 6", "1 0 6", "2 0 6", "4 0 6", "4 1 6"], "outputs": ["dangerous\n", "delicious\n", "safe\n", "dangerous\n", "dangerous\n", "dangerous\n", "dangerous\n", "dangerous\n"]}
coding
276
Solve the programming task below in a Python markdown code block. It's your Birthday. Your colleagues buy you a cake. The numbers of candles on the cake is provided (x). Please note this is not reality, and your age can be anywhere up to 1,000. Yes, you would look a mess. As a surprise, your colleagues have arranged f...
{"functional": "_inputs = [[900, 'abcdef'], [56, 'ifkhchlhfd'], [256, 'aaaaaddddr'], [333, 'jfmgklfhglbe'], [12, 'jaam'], [808, 'alfbpmmpz'], [660, 'zyxsqwh'], [651, 'hmgoltyy'], [349, 'nxls'], [958, 'hovzfsxbmwu'], [301, 'doda'], [383, 'zwwl'], [871, 'gnlyvknjga'], [583, 'slhacx'], [0, 'jpipe']]\n_outputs = [['That wa...
coding
296
Solve the programming task below in a Python markdown code block. For the given sequence with n different elements find the number of increasing subsequences with k + 1 elements. It is guaranteed that the answer is not greater than 8·1018. Input First line contain two integer values n and k (1 ≤ n ≤ 105, 0 ≤ k ≤ 10) ...
{"inputs": ["1 0\n1\n", "1 1\n1\n", "1 2\n1\n", "1 4\n1\n", "1 7\n1\n", "1 3\n1\n", "2 1\n1\n2\n", "2 1\n2\n1\n"], "outputs": ["1\n", "0\n", "0\n", "0\n", "0\n", "0\n", "1\n", "0\n"]}
coding
157
Solve the programming task below in a Python markdown code block. Every positive integer number, that is not prime, may be decomposed in prime factors. For example the prime factors of 20, are: ``` 2, 2, and 5, because: 20 = 2 . 2 . 5 ``` The first prime factor (the smallest one) of ```20``` is ```2``` and the last on...
{"functional": "_inputs = [[10, 100], [10, 200], [15, 150], [501, 1000], [501, 5000]]\n_outputs = [[[21, 25, 63]], [[21, 25, 63, 105, 125, 147, 189]], [[26, 52, 78, 104, 130]], [[998]], [[998, 1996, 2994, 3992, 4990]]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n ...
coding
604
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given two integer arrays pushed and popped each with distinct values, return true if this could have been the result of a sequence of push and pop operations on an initially empty stack, or false otherwise.   Please c...
{"functional": "def check(candidate):\n assert candidate(pushed = [1,2,3,4,5], popped = [4,5,3,2,1]) == True\n assert candidate(pushed = [1,2,3,4,5], popped = [4,3,5,1,2]) == False\n\n\ncheck(Solution().validateStackSequences)"}
coding
94
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an array nums consisting of positive integers and an integer k. Partition the array into two ordered groups such that each element is in exactly one group. A partition is called great if the sum of eleme...
{"functional": "def check(candidate):\n assert candidate(nums = [1,2,3,4], k = 4) == 6\n assert candidate(nums = [3,3,3], k = 4) == 0\n assert candidate(nums = [6,6], k = 2) == 2\n\n\ncheck(Solution().countPartitions)"}
coding
153