task_type
stringclasses
1 value
problem
stringlengths
209
3.39k
answer
stringlengths
35
6.15k
problem_tokens
int64
60
774
answer_tokens
int64
12
2.04k
coding
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"]}
507
70
coding
Solve the programming task below in a Python markdown code block. # Task You are a lifelong fan of your local football club, and proud to say you rarely miss a game. Even though you're a superfan, you still hate boring games. Luckily, boring games often end in a draw, at which point the winner is determined by a penalt...
{"functional": "_inputs = [[2, [1, 2]], [10, [10, 10]], [5, [5, 5]], [0, [0, 0]], [1, [0, 0]], [1, [0, 1]], [1, [1, 1]], [3, [3, 3]], [3, [1, 3]], [100, [100, 100]]]\n_outputs = [[3], [2], [2], [6], [5], [4], [5], [3], [1], [2]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, f...
536
280
coding
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)"}
93
69
coding
Solve the programming task below in a Python markdown code block. Chef has $K$ chocolates and he wants to distribute them to $N$ people (numbered $1$ through $N$). These people are standing in a line in such a way that for each $i$ ($1 \le i \le N-1$), person $i$ and person $i+1$ are adjacent. First, consider some way ...
{"inputs": ["1\n3\n2"], "outputs": ["2"]}
754
16
coding
Solve the programming task below in a Python markdown code block. The snakes want to build a temple for Lord Cobra. There are multiple strips of land that they are looking at, but not all of them are suitable. They need the strip of land to resemble a coiled Cobra. You need to find out which strips do so. Formally, eve...
{"inputs": ["7\n5\n1 2 3 2 1\n7\n2 3 4 5 4 3 2\n5\n1 2 3 4 3\n5\n1 3 5 3 1\n7\n1 2 3 4 3 2 1\n4\n1 2 3 2\n4\n1 2 2 1"], "outputs": ["yes\nno\nno\nno\nyes\nno\nno"]}
710
112
coding
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...
71
315
coding
Solve the programming task below in a Python markdown code block. International Abbreviation Olympiad takes place annually starting from 1989. Each year the competition receives an abbreviation of form IAO'y, where y stands for some number of consequent last digits of the current year. Organizers always pick an abbrevi...
{"inputs": ["1\nIAO'001\n", "1\nIAO'089\n", "1\nIAO'089\n", "1\nIAO'001\n", "1\nIAO'088\n", "1\nIAO'002\n", "1\nIAO'102\n", "1\nIAO'079\n"], "outputs": ["3001\n", "3089\n", "3089\n", "3001\n", "3088\n", "3002\n", "2102\n", "3079\n"]}
399
150
coding
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"]}
576
44
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an integer x, return true if x is a palindrome, and false otherwise. Β  Please complete the following python code precisely: ```python class Solution: def isPalindrome(self, x: int) -> bool: ```
{"functional": "def check(candidate):\n assert candidate(x = 121) == True\n assert candidate(x = -121) == False\n assert candidate(x = 10) == False\n\n\ncheck(Solution().isPalindrome)"}
64
57
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. A pangram is a sentence where every letter of the English alphabet appears at least once. Given a string sentence containing only lowercase English letters, return true if sentence is a pangram, or false otherwise. Β  ...
{"functional": "def check(candidate):\n assert candidate(sentence = \"thequickbrownfoxjumpsoverthelazydog\") == True\n assert candidate(sentence = \"leetcode\") == False\n\n\ncheck(Solution().checkIfPangram)"}
91
54
coding
Solve the programming task below in a Python markdown code block. collections.OrderedDict An OrderedDict is a dictionary that remembers the order of the keys that were inserted first. If a new entry overwrites an existing entry, the original insertion position is left unchanged. Example Code >>> from collections i...
{"inputs": ["9\nBANANA FRIES 12\nPOTATO CHIPS 30\nAPPLE JUICE 10\nCANDY 5\nAPPLE JUICE 10\nCANDY 5\nCANDY 5\nCANDY 5\nPOTATO CHIPS 30\n"], "outputs": ["BANANA FRIES 12\nPOTATO CHIPS 60\nAPPLE JUICE 20\nCANDY 20\n"]}
632
112
coding
Solve the programming task below in a Python markdown code block. Let be `n` an integer prime with `10` e.g. `7`. `1/7 = 0.142857 142857 142857 ...`. We see that the decimal part has a cycle: `142857`. The length of this cycle is `6`. In the same way: `1/11 = 0.09 09 09 ...`. Cycle length is `2`. # Task Given an ...
{"functional": "_inputs = [[3], [33], [18118], [69], [197], [65], [97], [19], [111], [53], [59], [93], [51], [159], [183], [167], [94], [133], [218713], [38127], [431541], [221193], [1234567]]\n_outputs = [[1], [2], [-1], [22], [98], [-1], [96], [18], [3], [13], [58], [15], [16], [13], [60], [166], [-1], [18], [9744], ...
402
365
coding
Solve the programming task below in a Python markdown code block. A line on the plane is described by an equation Ax + By + C = 0. You are to find any point on this line, whose coordinates are integer numbers from  - 5Β·1018 to 5Β·1018 inclusive, or to find out that such points do not exist. Input The first line contain...
{"inputs": ["2 5 3"], "outputs": ["6 -3"]}
201
18
coding
Solve the programming task below in a Python markdown code block. There is a circular pond with a perimeter of K meters, and N houses around them. The i-th house is built at a distance of A_i meters from the northmost point of the pond, measured clockwise around the pond. When traveling between these houses, you can on...
{"inputs": ["7 3\n0 5 17", "7 3\n0 4 17", "7 3\n0 4 28", "7 3\n0 8 28", "7 3\n1 8 31", "9 3\n0 5 17", "7 3\n0 8 17", "7 3\n0 2 28"], "outputs": ["-5\n", "-6\n", "-17\n", "-13\n", "-16\n", "-3\n", "-2\n", "-19\n"]}
276
139
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an m x n matrix mat that has its rows sorted in non-decreasing order and an integer k. You are allowed to choose exactly one element from each row to form an array. Return the kth smallest array sum amon...
{"functional": "def check(candidate):\n assert candidate(mat = [[1,3,11],[2,4,6]], k = 5) == 7\n assert candidate(mat = [[1,3,11],[2,4,6]], k = 9) == 17\n assert candidate(mat = [[1,10,10],[1,4,5],[2,3,6]], k = 7) == 9\n assert candidate(mat = [[1,1,10],[2,2,9]], k = 7) == 12\n\n\ncheck(Solution().kthSmalle...
107
142
coding
Solve the programming task below in a Python markdown code block. The only difference between problems C1 and C2 is that all values in input of problem C1 are distinct (this condition may be false for problem C2). You are given a sequence $a$ consisting of $n$ integers. You are making a sequence of moves. During each...
{"inputs": ["1\n1\n", "1\n1\n", "2\n1 1\n", "2\n2 1\n", "2\n1 2\n", "2\n1 1\n", "2\n1 2\n", "2\n2 1\n"], "outputs": ["1\nR\n", "1\nR\n", "1\nR\n", "2\nRR\n", "2\nLR\n", "1\nR", "2\nLR\n", "2\nRR\n"]}
568
113
coding
Solve the programming task below in a Python markdown code block. Imagine there's a big cube consisting of n^3 small cubes. Calculate, how many small cubes are not visible from outside. For example, if we have a cube which has 4 cubes in a row, then the function should return 8, because there are 8 cubes inside our cu...
{"functional": "_inputs = [[0], [1], [2], [3], [4], [5], [7], [12], [18], [10002]]\n_outputs = [[0], [0], [0], [1], [8], [27], [125], [1000], [4096], [1000000000000]]\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...
103
237
coding
Solve the programming task below in a Python markdown code block. You are given a directed graph with $n$ vertices and $m$ directed edges without self-loops or multiple edges. Let's denote the $k$-coloring of a digraph as following: you color each edge in one of $k$ colors. The $k$-coloring is good if and only if ther...
{"inputs": ["2 1\n2 1\n", "2 1\n2 1\n", "2 2\n2 1\n1 2\n", "2 2\n2 1\n1 2\n", "10 2\n8 7\n4 5\n", "10 2\n8 7\n10 5\n", "10 2\n8 7\n10 5\n", "10 2\n4 7\n10 5\n"], "outputs": ["1\n1 \n", "1\n1\n", "2\n2 1 \n", "2\n2 1\n", "1\n1 1\n", "1\n1 1 \n", "1\n1 1\n", "1\n1 1\n"]}
435
180
coding
Solve the programming task below in a Python markdown code block. The summer is at its peak in Chefland. Chef is planning to purchase a water cooler to keep his room cool. He has two options available: Rent a cooler at the cost of X coins per month. Purchase a cooler for Y coins. Chef wonders what is the maximum numb...
{"inputs": ["2\n5 12\n5 5"], "outputs": ["2\n0"]}
406
23
coding
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"]}
737
102
coding
Solve the programming task below in a Python markdown code block. In the Kingdom of AtCoder, people use a language called Taknese, which uses lowercase English letters. In Taknese, the plural form of a noun is spelled based on the following rules: - If a noun's singular form does not end with s, append s to the end of...
{"inputs": ["a\n", "s\n", "aox", "bsu", "xoa", "bsv", "xo`", "csv"], "outputs": ["as\n", "ses\n", "aoxs\n", "bsus\n", "xoas\n", "bsvs\n", "xo`s\n", "csvs\n"]}
202
75
coding
Solve the programming task below in a Python markdown code block. Read problem statements in [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. You are given an integer $C$. Let $d$ be the smallest integer such that $2^{d}$ is strictly greater than $C$. Consider all pairs of non-negative integers $(A...
{"inputs": ["2\n13\n10"], "outputs": ["70\n91"]}
452
22
coding
Solve the programming task below in a Python markdown code block. *** No Loops Allowed *** You will be given an array (a) and a value (x). All you need to do is check whether the provided array contains the value, without using a loop. Array can contain numbers or strings. X can be either. Return true if the array co...
{"functional": "_inputs = [[[66, 101], 66], [[80, 117, 115, 104, 45, 85, 112, 115], 45], [['t', 'e', 's', 't'], 'e'], [['what', 'a', 'great', 'kata'], 'kat'], [[66, 'codewars', 11, 'alex loves pushups'], 'alex loves pushups'], [['come', 'on', 110, '2500', 10, '!', 7, 15], 'Come'], [[\"when's\", 'the', 'next', 'Katathon...
166
395
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a 0-indexed array of positive integers tasks, representing tasks that need to be completed in order, where tasks[i] represents the type of the ith task. You are also given a positive integer space, which...
{"functional": "def check(candidate):\n assert candidate(tasks = [1,2,1,2,3,1], space = 3) == 9\n assert candidate(tasks = [5,8,8,5], space = 2) == 6\n\n\ncheck(Solution().taskSchedulerII)"}
164
70
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a string s and an integer array indices of the same length. The string s will be shuffled such that the character at the ith position moves to indices[i] in the shuffled string. Return the shuffled strin...
{"functional": "def check(candidate):\n assert candidate(s = \"codeleet\", indices = [4,5,6,7,0,2,1,3]) == \"leetcode\"\n assert candidate(s = \"abc\", indices = [0,1,2]) == \"abc\"\n\n\ncheck(Solution().restoreString)"}
97
74
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a positive integer array nums. The element sum is the sum of all the elements in nums. The digit sum is the sum of all the digits (not necessarily distinct) that appear in nums. Return the absolute dif...
{"functional": "def check(candidate):\n assert candidate(nums = [1,15,6,3]) == 9\n assert candidate(nums = [1,2,3,4]) == 0\n\n\ncheck(Solution().differenceOfSum)"}
124
57
coding
Solve the programming task below in a Python markdown code block. Your friend won't stop texting his girlfriend. It's all he does. All day. Seriously. The texts are so mushy too! The whole situation just makes you feel ill. Being the wonderful friend that you are, you hatch an evil plot. While he's sleeping, you tak...
{"functional": "_inputs = [['I miss you!'], ['u want to go to the movies?'], [\"Can't wait to see youuuuu\"], ['I want to film the bayou with you and put it on youtube'], ['You should come over Friday night'], ['You u youville utube you youyouyou uuu raiyou united youuuu u you']]\n_outputs = [['I miss your sister!'], [...
261
307
coding
Solve the programming task below in a Python markdown code block. MoEngage noticed that some users are not aware of the practice page on CodeChef, and some others are not aware of the rated contests on CodeChef. So, MoEngage wants to send an email to the users depending on which of the following groups they fall into: ...
{"inputs": ["0 1", "1 0"], "outputs": ["https://www.codechef.com/practice", "https://www.codechef.com/contests"]}
465
37
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an array points where points[i] = [xi, yi] represents a point on the X-Y plane, return true if these points are a boomerang. A boomerang is a set of three points that are all distinct and not in a straight line....
{"functional": "def check(candidate):\n assert candidate(points = [[1,1],[2,3],[3,2]]) == True\n assert candidate(points = [[1,1],[2,2],[3,3]]) == False\n\n\ncheck(Solution().isBoomerang)"}
106
63
coding
Solve the programming task below in a Python markdown code block. You are given an array $a$ of $n$ non-negative integers. In one operation you can change any number in the array to any other non-negative integer. Let's define the cost of the array as $\operatorname{DIFF}(a) - \operatorname{MEX}(a)$, where $\operatorn...
{"inputs": ["1\n5 1\n5 4 3 1 2\n", "1\n5 1\n1 2 3 4 5\n", "1\n10 5\n0 1 2 3 100 101 102 102 102 102\n", "5\n5 1\n1 2 3 4 5\n5 1\n1 2 3 4 5\n5 1\n1 2 3 4 5\n5 1\n1 2 3 4 5\n5 1\n1 2 3 4 5\n", "4\n4 1\n3 0 1 2\n4 1\n0 2 4 5\n7 2\n4 13 0 0 13 1337 1000000000\n6 2\n1 2 8 0 0 0\n"], "outputs": ["0\n", "0\n", "1\n", "0\n0\n0...
733
267
coding
Solve the programming task below in a Python markdown code block. You are given a string $\mbox{S}$. $\mbox{S}$ contains alphanumeric characters only. Your task is to sort the string $\mbox{S}$ in the following manner: All sorted lowercase letters are ahead of uppercase letters. All sorted uppercase letters are a...
{"inputs": ["Sorting1234\n"], "outputs": ["ginortS1324\n"]}
150
24
coding
Solve the programming task below in a Python markdown code block. Fox Ciel is playing a game. In this game there is an infinite long tape with cells indexed by integers (positive, negative and zero). At the beginning she is standing at the cell 0. There are also n cards, each card has 2 attributes: length l_{i} and co...
{"inputs": ["1\n1\n1\n", "1\n2\n2\n", "1\n1\n1\n", "1\n2\n2\n", "1\n1\n2\n", "1\n4\n2\n", "1\n6\n2\n", "1\n5\n2\n"], "outputs": ["1\n", "-1\n", "1\n", "-1\n", "2\n", "-1\n", "-1\n", "-1\n"]}
628
102
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a string s containing lowercase letters and an integer k. You need to : First, change some characters of s to other lowercase English letters. Then divide s into k non-empty disjoint substrings such tha...
{"functional": "def check(candidate):\n assert candidate(s = \"abc\", k = 2) == 1\n assert candidate(s = \"aabbc\", k = 3) == 0\n assert candidate(s = \"leetcode\", k = 8) == 0\n\n\ncheck(Solution().palindromePartition)"}
116
72
coding
Solve the programming task below in a Python markdown code block. A permutation of length n is an array containing each integer from 1 to n exactly once. For example, q = [4, 5, 1, 2, 3] is a permutation. For the permutation q the square of permutation is the permutation p that p[i] = q[q[i]] for each i = 1... n. For e...
{"inputs": ["1\n1\n", "1\n1\n", "1\n1\n", "4\n2 1 4 3\n", "4\n2 1 3 4\n", "4\n1 2 4 3\n", "4\n1 4 2 3\n", "4\n3 1 2 4\n"], "outputs": ["1\n", "1\n", "1\n", "3 4 2 1\n", "-1\n", "-1\n", "1 3 4 2\n", "2 3 1 4\n"]}
371
134
coding
Solve the programming task below in a Python markdown code block. You are given a straight line, $a\cdot x+b\cdot y=c$. Find the point closest to the origin that also satisfies the following properties: $\boldsymbol{x}$ and $y$ are integers. $\boldsymbol{x}$ is greater than zero. If more than one solution exist...
{"inputs": ["1\n2 3 1\n"], "outputs": ["2 -1\n"]}
439
22
coding
Solve the programming task below in a Python markdown code block. A burglar got into a matches warehouse and wants to steal as many matches as possible. In the warehouse there are m containers, in the i-th container there are ai matchboxes, and each matchbox contains bi matches. All the matchboxes are of the same size....
{"inputs": ["1 1\n1 2\n", "2 1\n2 1\n", "4 1\n2 2\n", "3 1\n2 1\n", "4 1\n4 2\n", "4 1\n4 4\n", "2 1\n4 4\n", "5 1\n10 5\n"], "outputs": ["2\n", "2\n", "4\n", "2\n", "8\n", "16\n", "8\n", "25\n"]}
273
121
coding
Solve the programming task below in a Python markdown code block. If there is an integer not less than 0 satisfying the following conditions, print the smallest such integer; otherwise, print -1. - The integer has exactly N digits in base ten. (We assume 0 to be a 1-digit integer. For other integers, leading zeros are...
{"inputs": ["3 0\n", "1 0\n", "3 1\n2 0", "3 1\n0 0", "3 0\n1 0", "3 0\n2 0", "3 0\n2 1", "3 0\n3 1"], "outputs": ["100\n", "0\n", "100\n", "100\n", "100\n", "100\n", "100\n", "100\n"]}
277
118
coding
Solve the programming task below in a Python markdown code block. Jim is doing his discrete maths homework which requires him to repeatedly calculate ^{n}C_{r}(n choose r) for different values of n. Knowing that this is time consuming, he goes to his sister June for help. June, being a computer science student knows h...
{"inputs": ["3\n2\n4\n5\n"], "outputs": ["1 2 1\n1 4 6 4 1\n1 5 10 10 5 1\n"]}
378
48
coding
Solve the programming task below in a Python markdown code block. Complete the function `power_of_two`/`powerOfTwo` (or equivalent, depending on your language) that determines if a given non-negative integer is a [power of two](https://en.wikipedia.org/wiki/Power_of_two). From the corresponding Wikipedia entry: > *a ...
{"functional": "_inputs = [[0], [1], [536870912]]\n_outputs = [[False], [True], [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 if len(a) != len(b): retur...
344
175
coding
Solve the programming task below in a Python markdown code block. There are X+Y+Z people, conveniently numbered 1 through X+Y+Z. Person i has A_i gold coins, B_i silver coins and C_i bronze coins. Snuke is thinking of getting gold coins from X of those people, silver coins from Y of the people and bronze coins from Z ...
{"inputs": ["1 2 1\n2 4 4\n0 2 1\n7 6 7\n5 2 3", "1 2 1\n2 4 4\n1 2 1\n7 6 2\n5 3 3", "1 2 1\n2 4 6\n0 2 1\n7 6 7\n5 2 3", "1 2 1\n2 4 4\n1 2 1\n7 0 2\n5 3 3", "1 2 1\n2 4 6\n0 2 1\n7 6 7\n9 2 3", "1 2 1\n2 4 7\n3 2 2\n7 6 7\n5 4 3", "1 2 1\n2 4 4\n3 2 1\n7 6 7\n5 2 3", "1 2 1\n2 4 4\n1 2 1\n7 6 11\n5 3 3"], "outputs":...
712
294
coding
Solve the programming task below in a Python markdown code block. Takahashi loves the number 7 and multiples of K. Where is the first occurrence of a multiple of K in the sequence 7,77,777,\ldots? (Also see Output and Sample Input/Output below.) If the sequence contains no multiples of K, print -1 instead. -----Constr...
{"inputs": ["3", "1", "9", "2", "2\n", "1\n", "3\n", "7\n"], "outputs": ["3\n", "1\n", "9\n", "-1", "-1\n", "1\n", "3\n", "1\n"]}
202
65
coding
Solve the programming task below in a Python markdown code block. Given a string, capitalize the letters that occupy even indexes and odd indexes separately, and return as shown below. Index `0` will be considered even. For example, `capitalize("abcdef") = ['AbCdEf', 'aBcDeF']`. See test cases for more examples. The ...
{"functional": "_inputs = [['abcdef'], ['codewars'], ['abracadabra'], ['codewarriors'], ['indexinglessons'], ['codingisafunactivity']]\n_outputs = [[['AbCdEf', 'aBcDeF']], [['CoDeWaRs', 'cOdEwArS']], [['AbRaCaDaBrA', 'aBrAcAdAbRa']], [['CoDeWaRrIoRs', 'cOdEwArRiOrS']], [['InDeXiNgLeSsOnS', 'iNdExInGlEsSoNs']], [['CoDiN...
192
291
coding
Solve the programming task below in a Python markdown code block. Recently, Norge found a string $s = s_1 s_2 \ldots s_n$ consisting of $n$ lowercase Latin letters. As an exercise to improve his typing speed, he decided to type all substrings of the string $s$. Yes, all $\frac{n (n + 1)}{2}$ of them! A substring of $s...
{"inputs": ["7 1\naaaaaaa\nb\n", "7 1\naaaaaba\nb\n", "7 1\naaaaaba\na\n", "7 1\naaaaaba\nc\n", "7 1\naaaaaaa\nb\n", "7 2\nabacaba\na b\n", "7 2\nabacaba\na c\n", "7 2\nabacaba\na d\n"], "outputs": ["0\n", "1\n", "16\n", "0\n", "0\n", "12\n", "8\n", "4\n"]}
604
134
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a list ofΒ preferencesΒ forΒ nΒ friends, where n is always even. For each person i,Β preferences[i]Β containsΒ a list of friendsΒ sorted in the order of preference. In other words, a friend earlier in the list i...
{"functional": "def check(candidate):\n assert candidate(n = 4, preferences = [[1, 2, 3], [3, 2, 0], [3, 1, 0], [1, 2, 0]], pairs = [[0, 1], [2, 3]]) == 2\n assert candidate(n = 2, preferences = [[1], [0]], pairs = [[1, 0]]) == 0\n assert candidate(n = 4, preferences = [[1, 3, 2], [2, 3, 0], [1, 3, 0], [0, 2, ...
264
176
coding
Solve the programming task below in a Python markdown code block. On his trip to Luxor and Aswan, Sagheer went to a Nubian market to buy some souvenirs for his friends and relatives. The market has some strange rules. It contains n different items numbered from 1 to n. The i-th item has base cost a_{i} Egyptian pounds....
{"inputs": ["1 7\n7\n", "1 7\n5\n", "1 1\n1\n", "1 1\n1\n", "1 7\n5\n", "1 7\n9\n", "1 3\n9\n", "1 7\n7\n"], "outputs": ["0 0\n", "1 6\n", "0 0\n", "0 0", "1 6", "0 0\n", "0 0\n", "0 0"]}
550
115
coding
Solve the programming task below in a Python markdown code block. You are given an expression of the form $a{+}b$, where $a$ and $b$ are integers from $0$ to $9$. You have to evaluate it and print the result. -----Input----- The first line contains one integer $t$ ($1 \le t \le 100$) β€” the number of test cases. Eac...
{"inputs": ["1\n5+5\n", "1\n1+1\n", "1\n2+2\n", "1\n5+6\n", "1\n1+4\n", "1\n0+0\n", "1\n2+3\n", "1\n3+1\n"], "outputs": ["10\n", "2\n", "4\n", "11\n", "5\n", "0\n", "5\n", "4\n"]}
199
104
coding
Solve the programming task below in a Python markdown code block. The mysterious pathogen of ACM Nation multiplies mysteriously each day. Maria was able to decipher the pattern but unable to completely solve the problem. The study of this equation will help in combating their growth. The summation is - S = a + a...
{"inputs": ["1\n5", "2\n6"], "outputs": ["5", "126"]}
157
24
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an array words of size n consisting of non-empty strings. We define the score of a string term as the number of strings words[i] such that term is a prefix of words[i]. For example, if words = ["a", "ab...
{"functional": "def check(candidate):\n assert candidate(words = [\"abc\",\"ab\",\"bc\",\"b\"]) == [5,4,3,2]\n assert candidate(words = [\"abcd\"]) == [4]\n\n\ncheck(Solution().sumPrefixScores)"}
173
62
coding
Solve the programming task below in a Python markdown code block. Chef likes arrays a lot. Today, he found an array A consisting of N positive integers. Let L denote the sorted (in non-increasing order) list of size N*(N+1)/2 containing the sums of all possible contiguous subarrays of A. Chef is interested in finding t...
{"inputs": ["3 4\n1 3 4", "3 3\n10 2 7"], "outputs": ["8 7 4 4", "19 12 10"]}
383
48
coding
Solve the programming task below in a Python markdown code block. Let N be a positive even number. We have a permutation of (1, 2, ..., N), p = (p_1, p_2, ..., p_N). Snuke is constructing another permutation of (1, 2, ..., N), q, following the procedure below. First, let q be an empty sequence. Then, perform the follow...
{"inputs": ["2\n0 2", "2\n0 1", "2\n0 0", "2\n2 2", "2\n1 0", "2\n1 1", "2\n1 2", "2\n1 2\n"], "outputs": ["0 2 ", "0 1 ", "0 0 ", "2 2 ", "1 0 ", "1 1 ", "1 2", "1 2\n"]}
337
104
coding
Solve the programming task below in a Python markdown code block. Billy investigates the question of applying greedy algorithm to different spheres of life. At the moment he is studying the application of greedy algorithm to the problem about change. There is an amount of n coins of different face values, and the coins...
{"inputs": ["1\n1\n", "2\n2 1\n", "2\n4 1\n", "3\n3 2 1\n", "3\n4 2 1\n", "3\n4 3 1\n", "4\n5 4 3 1\n", "3\n25 15 1\n"], "outputs": ["-1\n", "-1\n", "-1\n", "-1\n", "-1\n", "6\n", "7\n", "30\n"]}
400
116
coding
Solve the programming task below in a Python markdown code block. C: Divisor Game problem tsutaj is trying to play about a few games. In a divisor game, a natural number N of 2 or more is given first, and then the game progresses according to the following procedure. * Declare one integer from the divisors of N oth...
{"inputs": ["2", "8", "7", "4", "5", "3", "6", "9"], "outputs": ["1 1\n", "1 3\n", "1 1\n", "1 2\n", "1 1\n", "1 1\n", "2 3\n", "1 2\n"]}
398
78
coding
Solve the programming task below in a Python markdown code block. Write function describeList which returns "empty" if the list is empty or "singleton" if it contains only one element or "longer"" if more. Also feel free to reuse/extend the following starter code: ```python def describeList(list): ```
{"functional": "_inputs = [[[]], [[1]], [[1, 2, 5, 4]], [['one']], [['one', 'two']], [[[1, 2]]]]\n_outputs = [['empty'], ['singleton'], ['longer'], ['singleton'], ['longer'], ['singleton']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, ...
66
203
coding
Solve the programming task below in a Python markdown code block. The integer ```64``` is the first integer that has all of its digits even and furthermore, is a perfect square. The second one is ```400``` and the third one ```484```. Give the numbers of this sequence that are in the range ```[a,b] ```(both values in...
{"functional": "_inputs = [[100, 1000], [1000, 4000], [10000, 40000]]\n_outputs = [[[400, 484]], [[]], [[26244, 28224, 40000]]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tupl...
243
221
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an array of positive integers nums, return an array answer that consists of the digits of each integer in nums after separating them in the same order they appear in nums. To separate the digits of an integer is...
{"functional": "def check(candidate):\n assert candidate(nums = [13,25,83,77]) == [1,3,2,5,8,3,7,7]\n assert candidate(nums = [7,1,3,9]) == [7,1,3,9]\n\n\ncheck(Solution().separateDigits)"}
133
82
coding
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...
547
1,460
coding
Solve the programming task below in a Python markdown code block. Isaac has to buy a new HackerPhone for his girlfriend Amy. He is exploring the shops in the town to compare the prices whereupon he finds a shop located on the first floor of a building, that has a unique pricing policy. There are N steps leading to the ...
{"inputs": ["3\n1 \n1\n2\n", "4\n1 \n2\n2\n2\n"], "outputs": ["2.0\n", "3.5\n"]}
416
42
coding
Solve the programming task below in a Python markdown code block. Recently, Vladimir got bad mark in algebra again. To avoid such unpleasant events in future he decided to train his arithmetic skills. He wrote four integer numbers a, b, c, d on the blackboard. During each of the next three minutes he took two numbers f...
{"inputs": ["3 2 2 2\n* * +\n", "1 2 3 4\n* + *\n", "2 2 2 2\n* * +\n", "1 1 1 1\n+ + *\n", "1 2 3 4\n* + +\n", "15 1 3 1\n* * +\n", "8 1 7 14\n+ + +\n", "7 0 8 15\n+ + *\n"], "outputs": ["10\n", "10\n", "8\n", "3\n", "9\n", "18\n", "30\n", "0\n"]}
329
162
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a network of n nodes, labeled from 1 to n. You are also given times, a list of travel times as directed edges times[i] = (ui, vi, wi), where ui is the source node, vi is the target node, and wi is the ti...
{"functional": "def check(candidate):\n assert candidate(times = [[2,1,1],[2,3,1],[3,4,1]], n = 4, k = 2) == 2\n assert candidate(times = [[1,2,1]], n = 2, k = 1) == 1\n assert candidate(times = [[1,2,1]], n = 2, k = 2) == -1\n\n\ncheck(Solution().networkDelayTime)"}
174
110
coding
Solve the programming task below in a Python markdown code block. An accordion is a string (yes, in the real world accordions are musical instruments, but let's forget about it for a while) which can be represented as a concatenation of: an opening bracket (ASCII code $091$), a colon (ASCII code $058$), some (possibly ...
{"inputs": ["[\n", "|\n", "]\n", ":\n", "b\n", "c\n", "s\n", "z\n"], "outputs": ["-1\n", "-1\n", "-1\n", "-1\n", "-1\n", "-1\n", "-1\n", "-1\n"]}
342
71
coding
Solve the programming task below in a Python markdown code block. You are given a string S of numbers. Dr. Dragoon has eaten up some numbers of the string. You decide to fix the string by putting the numbers 0 and 1 in the empty spaces. The base cost for putting the β€˜0’ is x and putting β€˜1’ is y . The cost of putt...
{"inputs": ["501?1?\n6 5", "1001?11?\n5 23"], "outputs": ["6", "8"]}
443
40
coding
Solve the programming task below in a Python markdown code block. Look for the Winner! The citizens of TKB City are famous for their deep love in elections and vote counting. Today they hold an election for the next chairperson of the electoral commission. Now the voting has just been closed and the counting is going ...
{"inputs": ["1\nA\n4\nA A B C\n5\nL M N L O\n1\nJ K K K J K\n0\nX Y Y Y Z X\n8\nB B A B A C A D C B\n1\nV V U U U W V W V V\n0", "1\nA\n4\nA A B B\n5\nL M N L N\n6\nK K K K K K\n6\nX X X Y Z X\n10\nA A A B A C A C C B\n1\nV U U U U V V W V W\n0", "1\nA\n4\nA A B B\n5\nL M N L N\n6\nK K K K K K\n6\nX X X Y Z X\n10\nA A ...
699
702
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. A 3 x 3 magic square is a 3 x 3 grid filled with distinct numbers from 1 to 9 such that each row, column, and both diagonals all have the same sum. Given a row x col grid of integers, how many 3 x 3 magic square subgr...
{"functional": "def check(candidate):\n assert candidate(grid = [[4,3,8,4],[9,5,1,9],[2,7,6,2]]) == 1\n assert candidate(grid = [[8]]) == 0\n\n\ncheck(Solution().numMagicSquaresInside)"}
146
68
coding
Solve the programming task below in a Python markdown code block. Chef is interested to solve series problems. Chef wants to solve a series problem but he can't solve it till now.Can you help Chef to solve the series problem? - In series problem, the series goes as follows 1,9,31,73,141 . . . . . . . . Your task is t...
{"inputs": ["2\n8\n10"], "outputs": ["561\n1081"]}
271
24
coding
Solve the programming task below in a Python markdown code block. You are the head of a large enterprise. $n$ people work at you, and $n$ is odd (i. e. $n$ is not divisible by $2$). You have to distribute salaries to your employees. Initially, you have $s$ dollars for it, and the $i$-th employee should get a salary fr...
{"inputs": ["1\n1 1000000000\n1000000000 1000000000\n", "1\n1 1000000000\n1000000000 1000000000\n", "3\n3 26\n10 12\n1 4\n10 11\n1 945\n1 1000010000\n5 26\n4 4\n0 2\n6 8\n9 6\n2 7\n", "3\n3 26\n6 12\n1 4\n10 11\n1 1337\n1 1000000000\n5 26\n4 4\n0 4\n3 8\n2 6\n2 7\n", "3\n3 26\n7 12\n1 2\n10 14\n1 1337\n1 1000000000\n5 ...
740
595
coding
Solve the programming task below in a Python markdown code block. Andi and Budi were given an assignment to tidy up their bookshelf of $n$ books. Each book is represented by the book title β€” a string $s_i$ numbered from $1$ to $n$, each with length $m$. Andi really wants to sort the book lexicographically ascending, wh...
{"inputs": ["5 2\nAA\nAB\nBB\nBA\nAZ\n", "5 2\nAA\nAB\nBB\nBA\nZA\n", "5 2\nAA\nAB\nCB\nBA\nAZ\n", "2 2\nAA\nAB\nCB\nBA\nAZ\n", "2 2\nAA\nBC\nCB\nAB\nAZ\n", "1 2\nAA\nAC\nBC\nBA\nZA\n", "5 2\nAA\nAB\nBC\nBA\nAZ\n", "3 2\nAA\nAB\nCB\nAB\nAZ\n"], "outputs": ["5 2 1 3 4\n", "2 1 3 4 5\n", "5 2 1 4 3\n", "2 1\n", "1 2\n", ...
370
206
coding
Solve the programming task below in a Python markdown code block. Valerian was captured by Shapur. The victory was such a great one that Shapur decided to carve a scene of Valerian's defeat on a mountain. So he had to find the best place to make his victory eternal! He decided to visit all n cities of Persia to find t...
{"inputs": ["1\n", "2\n2 1 5\n", "2\n2 1 89\n", "2\n2 1 17\n", "2\n2 1 140\n", "3\n1 2 0\n2 3 0\n", "3\n1 2 3\n2 3 5\n", "3\n1 2 3\n2 3 3\n"], "outputs": ["0", "5", "89", "17\n", "140\n", "0", "8\n", "6\n"]}
377
134
coding
Solve the programming task below in a Python markdown code block. ### Preface You are currently working together with a local community to build a school teaching children how to code. First plans have been made and the community wants to decide on the best location for the coding school. In order to make this decision...
{"functional": "_inputs = [[[[3, 7], [2, 2], [14, 1]], [{'id': 1, 'x': 3, 'y': 4}, {'id': 2, 'x': 8, 'y': 2}]], [[[54, 7], [1, 211], [14, 44], [12, 5], [14, 7]], [{'id': 1, 'x': 44, 'y': 55}, {'id': 2, 'x': 12, 'y': 57}, {'id': 3, 'x': 23, 'y': 66}]], [[[152, 7], [1, 211], [14, 56], [12, 4], [142, 7]], [{'id': 1, 'x': ...
345
954
coding
Solve the programming task below in a Python markdown code block. Emuskald needs a fence around his farm, but he is too lazy to build it himself. So he purchased a fence-building robot. He wants the fence to be a regular polygon. The robot builds the fence along a single path, but it can only make fence corners at a s...
{"inputs": ["3\n4\n11\n6\n", "3\n6\n5\n46\n", "3\n6\n11\n6\n", "3\n28\n1\n62\n", "3\n6\n17\n46\n", "3\n9\n24\n21\n", "3\n7\n24\n21\n", "3\n30\n11\n6\n"], "outputs": ["NO\nNO\nNO\n", "NO\nNO\nNO\n", "NO\nNO\nNO\n", "NO\nNO\nNO\n", "NO\nNO\nNO\n", "NO\nNO\nNO\n", "NO\nNO\nNO\n", "NO\nNO\nNO\n"]}
290
163
coding
Solve the programming task below in a Python markdown code block. Chef likes inequalities. Please help him to solve next one. Given four integers a, b, c, d. Find number of solutions x < y, where a ≀ x ≀ b and c ≀ y ≀ d and x, y integers. -----Input----- The first line contains an integer T denoting number of tests. F...
{"inputs": ["1\n2 3 3 4", "1\n2 999999 1 1000000"], "outputs": ["3", "499998500001"]}
258
56
coding
Solve the programming task below in a Python markdown code block. Gordon Ramsay shouts. He shouts and swears. There may be something wrong with him. Anyway, you will be given a string of four words. Your job is to turn them in to Gordon language. Rules: Obviously the words should be Caps, Every word should end with...
{"functional": "_inputs = [['What feck damn cake'], ['are you stu pid'], ['i am a chef'], ['dont you talk tome'], ['how dare you feck']]\n_outputs = [['WH@T!!!! F*CK!!!! D@MN!!!! C@K*!!!!'], ['@R*!!!! Y**!!!! ST*!!!! P*D!!!!'], ['*!!!! @M!!!! @!!!! CH*F!!!!'], ['D*NT!!!! Y**!!!! T@LK!!!! T*M*!!!!'], ['H*W!!!! D@R*!!!! ...
115
262
coding
Solve the programming task below in a Python markdown code block. Igor is a post-graduate student of chemistry faculty in Berland State University (BerSU). He needs to conduct a complicated experiment to write his thesis, but laboratory of BerSU doesn't contain all the materials required for this experiment. Fortunate...
{"inputs": ["3\n1 2 3\n3 2 1\n1 1\n1 1\n", "3\n3 2 1\n1 2 3\n1 1\n1 2\n", "3\n3 2 1\n1 2 3\n1 1\n1 4\n", "3\n1 2 3\n3 2 0\n1 1\n1 1\n", "3\n3 2 1\n1 2 3\n1 1\n2 4\n", "3\n3 0 1\n1 2 3\n1 1\n2 4\n", "3\n3 2 1\n1 2 3\n1 1\n1 2\n", "3\n1 2 3\n3 2 1\n1 1\n1 1\n"], "outputs": ["YES\n", "NO\n", "NO\n", "YES\n", "NO\n", "NO\n...
541
230
coding
Solve the programming task below in a Python markdown code block. Soroush and Keshi each have a labeled and rooted tree on n vertices. Both of their trees are rooted from vertex 1. Soroush and Keshi used to be at war. After endless decades of fighting, they finally became allies to prepare a Codeforces round. To celeb...
{"inputs": ["4\n4\n1 2 3\n1 2 3\n5\n1 2 3 4\n1 1 1 1\n6\n1 2 1 1 2\n1 2 1 2 2\n7\n1 1 3 4 4 5\n1 2 1 4 2 5\n", "4\n4\n1 2 3\n1 2 3\n5\n1 2 3 4\n1 1 1 1\n6\n1 2 1 1 2\n1 2 1 2 2\n7\n1 1 3 4 4 5\n1 2 1 4 4 5\n", "4\n4\n1 2 3\n1 2 3\n5\n1 4 3 4\n1 1 1 1\n6\n1 1 1 1 2\n1 2 1 2 2\n7\n1 1 3 4 4 5\n1 2 1 4 2 5\n", "4\n4\n1 2 ...
631
758
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given two integers tomatoSlices and cheeseSlices. The ingredients of different burgers are as follows: Jumbo Burger: 4 tomato slices and 1 cheese slice. Small Burger: 2 Tomato slices and 1 cheese slice. Return [tota...
{"functional": "def check(candidate):\n assert candidate(tomatoSlices = 16, cheeseSlices = 7) == [1,6]\n assert candidate(tomatoSlices = 17, cheeseSlices = 4) == []\n assert candidate(tomatoSlices = 4, cheeseSlices = 17) == []\n assert candidate(tomatoSlices = 0, cheeseSlices = 0) == [0,0]\n assert candi...
163
149
coding
Solve the programming task below in a Python markdown code block. You are given a string S of length 3 consisting of a, b and c. Determine if S can be obtained by permuting abc. -----Constraints----- - |S|=3 - S consists of a, b and c. -----Input----- Input is given from Standard Input in the following format: S -...
{"inputs": ["bba", "cab", "abb", "aab", "aac", "bbb", "baa", "caa"], "outputs": ["No\n", "Yes\n", "No\n", "No\n", "No\n", "No\n", "No\n", "No\n"]}
125
64
coding
Solve the programming task below in a Python markdown code block. Pair of gloves ============= Winter is coming, you must prepare your ski holidays. The objective of this kata is to determine the number of pair of gloves you can constitute from the gloves you have in your drawer. A pair of gloves is constituted of tw...
{"functional": "_inputs = [[['red', 'red']], [['red', 'green', 'blue']], [['gray', 'black', 'purple', 'purple', 'gray', 'black']], [[]], [['red', 'green', 'blue', 'blue', 'red', 'green', 'red', 'red', 'red']]]\n_outputs = [[1], [0], [3], [0], [4]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float)...
200
228
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a 0-indexed array nums consisting of positive integers, representing targets on a number line. You are also given an integer space. You have a machine which can destroy targets. Seeding the machine with ...
{"functional": "def check(candidate):\n assert candidate(nums = [3,7,8,1,1,5], space = 2) == 1\n assert candidate(nums = [1,3,5,2,4,6], space = 2) == 1\n assert candidate(nums = [6,2,5], space = 100) == 2\n\n\ncheck(Solution().destroyTargets)"}
163
96
coding
Solve the programming task below in a Python markdown code block. A certain type of steel is graded according to the following conditions. 1. Hardness of the steel must be greater than 50 2. Carbon content of the steel must be less than 0.7 3. Tensile strength must be greater than 5600 The grades awarded are as follo...
{"inputs": ["3 \n67 0.6 5602\n45 0 4500\n0 0 0", "3 \n67 0.6 5602\n78 0 4500\n0 0 0", "3 \n53 0.6 5602\n45 0 4500\n0 0 0", "3 \n103 0.6 5602\n78 0 4500\n0 0 0", "3 \n103 0.6 5602\n78 0 4466\n0 0 0", "3 \n103 0.6 7770\n78 0 4466\n0 0 0", "3 \n53 0.6 5602\n45 0 4500\n0 0 0 \n", "3 \n103 0.6 7770\n78 -1 4466\n0 0 0"], "ou...
349
340
coding
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. Eugene loves sequences, especially arithmetic progressions. One day he was asked to solve a difficult problem. If a sequence of numbers A_{1}, A_{2}, ... , A_{N} form an ari...
{"inputs": ["2\n1 1 0 4\n4 7 2 4", "2\n1 1 0 4\n2 7 2 4", "2\n1 1 1 3\n14 7 2 4", "2\n1 1 1 2\n14 7 2 4", "2\n1 1 1 4\n14 7 2 4", "2\n1 1 0 4\n14 7 2 4", "2\n1 1 1 4\n2 10 2 0", "2\n1 1 1 4\n3 29 2 0"], "outputs": ["19\n18\n", "19\n21\n", "6\n12", "3\n12\n", "10\n12\n", "19\n12\n", "10\n-2\n", "10\n-3\n"]}
703
225
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an integer array nums, return true if nums is consecutive, otherwise return false. An array is consecutive if it contains every number in the range [x, x + n - 1] (inclusive), where x is the minimum number in th...
{"functional": "def check(candidate):\n assert candidate(nums = [1,3,4,2]) == True\n assert candidate(nums = [1,3]) == False\n assert candidate(nums = [3,5,4]) == True\n\n\ncheck(Solution().isConsecutive)"}
109
65
coding
Solve the programming task below in a Python markdown code block. Santa has $n$ candies and he wants to gift them to $k$ kids. He wants to divide as many candies as possible between all $k$ kids. Santa can't divide one candy into parts but he is allowed to not use some candies at all. Suppose the kid who recieves the ...
{"inputs": ["1\n49845 2\n", "1\n96290 2\n", "1\n51548 1\n", "1\n25702 1\n", "1\n25113 1\n", "1\n49777 3\n", "1\n38068 2\n", "1\n49845 1\n"], "outputs": ["49845\n", "96290\n", "51548\n", "25702\n", "25113\n", "49777\n", "38068\n", "49845\n"]}
700
166
coding
Solve the programming task below in a Python markdown code block. You are given array of integers, your task will be to count all pairs in that array and return their count. **Notes:** * Array can be empty or contain only one value; in this case return `0` * If there are more pairs of a certain number, count each...
{"functional": "_inputs = [[[1, 2, 2, 20, 6, 20, 2, 6, 2]], [[1000, 1000]], [[]], [[54]]]\n_outputs = [[4], [1], [0], [0]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\...
271
207
coding
Solve the programming task below in a Python markdown code block. You are given two integer arrays a and b of length n. You can reverse at most one subarray (continuous subsegment) of the array a. Your task is to reverse such a subarray that the sum βˆ‘_{i=1}^n a_i β‹… b_i is maximized. Input The first line contains o...
{"inputs": ["1\n1\n1\n", "1\n2\n1\n", "1\n2\n0\n", "2\n13 37\n0 4\n", "2\n13 71\n0 4\n", "2\n13 37\n2 4\n", "3\n0 2 5\n5 45 22\n", "3\n0 2 5\n5 69 22\n"], "outputs": ["1\n", "2\n", "0\n", "148\n", "284\n", "\n174\n", "269\n", "389\n"]}
476
151
coding
Solve the programming task below in a Python markdown code block. It is the World Cup Finals. Chef only finds a match interesting if the skill difference of the competing teams is *less than or equal to* D. Given that the skills of the teams competing in the final are X and Y respectively, determine whether Chef will ...
{"inputs": ["3\n5 3 4\n5 3 1\n5 5 0\n"], "outputs": ["YES\nNO\nYES\n"]}
335
36
coding
Solve the programming task below in a Python markdown code block. It is nighttime and Joe the Elusive got into the country's main bank's safe. The safe has n cells positioned in a row, each of them contains some amount of diamonds. Let's make the problem more comfortable to work with and mark the cells with positive nu...
{"inputs": ["1 1 1\n0\n", "2 1 1\n0\n", "3 1 1\n0\n", "2 0 1\n2 3\n", "2 0 1\n0 3\n", "2 3 1\n2 3\n", "3 2 2\n4 1 3\n", "1 6 19\n110000\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "2\n", "114\n"]}
677
136
coding
Solve the programming task below in a Python markdown code block. Create a program to determine the positional relationship between a triangle and a circle on a plane. All target figures shall include boundaries. The triangle is given the position of three vertices, and the circle is given the position of the center an...
{"inputs": ["4 0\n3 1\n3 3\n3 3\n1\n4 3\n8 2\n4 12\n8 9\n5\n0 0\n52 2\n8 5\n2 2\n5\n3 7\n23 2\n4 9\n37 1\n0\n0 0", "2 0\n3 1\n3 3\n3 3\n1\n4 3\n16 2\n4 12\n8 9\n5\n5 0\n10 2\n8 5\n7 2\n5\n3 7\n23 2\n16 9\n37 1\n0\n0 0", "2 0\n3 1\n3 3\n3 3\n1\n4 3\n16 2\n4 12\n8 9\n5\n5 0\n10 2\n8 5\n7 2\n0\n3 7\n23 2\n16 9\n37 1\n0\n0...
393
754
coding
Solve the programming task below in a Python markdown code block. All cities of Lineland are located on the Ox coordinate axis. Thus, each city is associated with its position x_{i} β€” a coordinate on the Ox axis. No two cities are located at a single point. Lineland residents love to send letters to each other. A pers...
{"inputs": ["2\n0 0\n", "2\n0 1\n", "2\n0 2\n", "2\n0 3\n", "2\n-1 1\n", "2\n-2 1\n", "2\n-4 1\n", "2\n-6 1\n"], "outputs": ["0 0\n0 0\n", "1 1\n1 1\n", "2 2\n2 2\n", "3 3\n3 3\n", "2 2\n2 2\n", "3 3\n3 3\n", "5 5\n5 5\n", "7 7\n7 7\n"]}
414
154
coding
Solve the programming task below in a Python markdown code block. Christmas is coming, and Santa has a long list to go through, to find who deserves presents for the big day. Go through a list of children, and return a list containing every child who appeared on Santa's list. Do not add any child more than once. Output...
{"functional": "_inputs = [[['Jason', 'Jackson', 'Jordan', 'Johnny'], ['Jason', 'Jordan', 'Jennifer']], [['Jason', 'Jackson', 'Johnson', 'JJ'], ['Jason', 'James', 'JJ']], [['jASon', 'JAsoN', 'JaSON', 'jasON'], ['JasoN', 'jASOn', 'JAsoN', 'jASon', 'JASON']]]\n_outputs = [[['Jason', 'Jordan']], [['JJ', 'Jason']], [['JAso...
152
258
coding
Solve the programming task below in a Python markdown code block. You are playing one RPG from the 2010s. You are planning to raise your smithing skill, so you need as many resources as possible. So how to get resources? By stealing, of course. You decided to rob a town's blacksmith and you take a follower with you. Y...
{"inputs": ["1\n8 7\n2 4\n7 3\n", "1\n8 7\n2 4\n7 3\n", "1\n8 7\n2 4\n2 3\n", "1\n8 7\n3 4\n2 3\n", "1\n15 10\n200000 4\n15 1000000000\n", "1\n15 10\n200000 4\n15 1000000000\n", "1\n13 10\n200000 4\n15 1000000000\n", "1\n13 10\n200000 4\n15 1000001000\n"], "outputs": ["4\n", "4\n", "5\n", "6\n", "1\n", "1\n", "0\n", "0...
668
234
coding
Solve the programming task below in a Python markdown code block. Toad Rash has a binary string $s$. A binary string consists only of zeros and ones. Let $n$ be the length of $s$. Rash needs to find the number of such pairs of integers $l$, $r$ that $1 \leq l \leq r \leq n$ and there is at least one pair of integers ...
{"inputs": ["0\n", "0\n", "1\n", "00\n", "01\n", "00\n", "01\n", "000\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "1\n"]}
398
76
coding
Solve the programming task below in a Python markdown code block. In the beginning, Takahashi has A cookies, and Aoki has B cookies. They will perform the following operation alternately, starting from Takahashi: * If the number of cookies in his hand is odd, eat one of those cookies; if the number is even, do nothing...
{"inputs": ["3 2 3", "5 4 1", "0 2 3", "8 4 1", "0 0 3", "8 4 2", "3 3 3", "5 4 2"], "outputs": ["1 2\n", "2 6\n", "0 1\n", "4 8\n", "0 0\n", "8 4\n", "1 3", "5 3"]}
276
108
coding
Solve the programming task below in a Python markdown code block. What's in a name? ..Or rather, what's a name in? For us, a particular string is where we are looking for a name. Task Test whether or not the string contains all of the letters which spell a given name, in order. The format A function passing two stri...
{"functional": "_inputs = [['Across the rivers', 'chris'], ['Next to a lake', 'chris'], ['Under a sea', 'chris'], ['A crew that boards the ship', 'chris'], ['A live son', 'Allison'], ['Just enough nice friends', 'Jennifer'], ['thomas', 'Thomas'], ['pippippi', 'Pippi'], ['pipipp', 'Pippi'], ['ppipip', 'Pippi']]\n_output...
385
270
coding
Solve the programming task below in a Python markdown code block. Ostap already settled down in Rio de Janiero suburb and started to grow a tree in his garden. Recall that a tree is a connected undirected acyclic graph. Ostap's tree now has n vertices. He wants to paint some vertices of the tree black such that from ...
{"inputs": ["1 0\n", "2 2\n1 2\n", "2 1\n1 2\n", "2 0\n1 2\n", "4 1\n1 2\n2 3\n3 4\n", "5 1\n1 2\n4 3\n5 3\n2 3\n", "7 2\n1 2\n2 3\n1 4\n4 5\n1 6\n6 7\n", "10 5\n6 4\n4 1\n7 5\n8 7\n2 6\n3 6\n8 6\n10 3\n4 9\n"], "outputs": ["1", "3\n", "3", "1", "9", "15", "91", "1023"]}
559
186
coding
Solve the programming task below in a Python markdown code block. Haiku is a short form of Japanese poetry. A Haiku consists of three phrases with 5, 7 and 5 syllables, in this order. Iroha is looking for X,Y,Z-Haiku (defined below) in integer sequences. Consider all integer sequences of length N whose elements are bet...
{"inputs": ["5 4 3 3", "5 4 2 3", "0 4 2 3", "8 5 7 5", "3 3 7 5", "7 4 2 3", "5 8 3 3", "8 4 2 3"], "outputs": ["460\n", "435\n", "0\n", "1761124\n", "1\n", "78735\n", "574\n", "962894\n"]}
404
131
coding
Solve the programming task below in a Python markdown code block. Taro is an elementary school student who has just learned multiplication. Somehow, he likes multiplication, so when he sees numbers, he wants to multiply. He seems to like to do the following for integers greater than or equal to 0. (Processing flow) * ...
{"inputs": ["3\n2\n2\n4", "3\n0\n42\n4", "3\n0\n37\n4", "3\n16\n2\n7", "3\n29\n2\n7", "3\n9\n99\n39", "3\n3\n127\n5", "3\n1\n169\n6"], "outputs": ["0\n0\n0\n", "0\n1\n0\n", "0\n2\n0\n", "1\n0\n0\n", "2\n0\n0\n", "0\n2\n3\n", "0\n3\n0\n", "0\n4\n0\n"]}
618
152
coding
Solve the programming task below in a Python markdown code block. Sheldon, Leonard, Penny, Rajesh and Howard are in the queue for a "Double Cola" drink vending machine; there are no other people in the queue. The first one in the queue (Sheldon) buys a can, drinks it and doubles! The resulting two Sheldons go to the en...
{"inputs": ["841", "38614"], "outputs": ["Leonard", "Howard"]}
355
25
coding
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. A pair of indices i, j where 0 <=Β i < j < nums.length is called beautiful if the first digit of nums[i] and the last digit of nums[j] are coprime. Return the total number ...
{"functional": "def check(candidate):\n assert candidate(nums = [2,5,1,4]) == 5\n assert candidate(nums = [11,21,12]) == 2\n\n\ncheck(Solution().countBeautifulPairs)"}
174
57
coding
Solve the programming task below in a Python markdown code block. In this Kata, you will be given a mathematical string and your task will be to remove all braces as follows: ```Haskell solve("x-(y+z)") = "x-y-z" solve("x-(y-z)") = "x-y+z" solve("u-(v-w-(x+y))-z") = "u-v+w+x+y-z" solve("x-(-y-z)") = "x+y+z" ``` There...
{"functional": "_inputs = [['a-(b)'], ['a-(-b)'], ['a+(b)'], ['a+(-b)'], ['(((((((((-((-(((n))))))))))))))'], ['(((a-((((-(-(f)))))))))'], ['((((-(-(-(-(m-g))))))))'], ['(((((((m-(-(((((t)))))))))))))'], ['-x'], ['-(-(x))'], ['-((-x))'], ['-(-(-x))'], ['-(-(x-y))'], ['-(x-y)'], ['x-(y+z)'], ['x-(y-z)'], ['x-(-y-z)'], [...
153
493
coding
Solve the programming task below in a Python markdown code block. A newly opened multinational brand has decided to base their company logo on the three most common characters in the company name. They are now trying out various combinations of company names and logos based on this condition. Given a string $\boldsymbo...
{"inputs": ["aabbbccde\n"], "outputs": ["b 3\na 2\nc 2\n"]}
380
27
coding
Solve the programming task below in a Python markdown code block. Raj is suffering from shot term memory loss so he is unable to remember his laptop password but he has a list of some string and the only thing that he remember about his password is alphanumeric and also that all the characters are unique. Given a lis...
{"inputs": ["absdbads\nasdjenfef\ntyerbet\nabc564"], "outputs": ["Invalid\nInvalid\nInvalid\nValid"]}
168
33