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. We define a function f on a binary string S of length N as follows: f(S) = \sum_{i = 1}^{N - 1} |S_{i+1} - S_{i}|. JJ and Uttu have a binary string S of length N and they decide to play a game using it. The rules of the game are as follows: JJ starts ...
{"inputs": ["3\n5\n10011\n2\n00\n5\n10101"], "outputs": ["JJ\nJJ\nUttu"]}
502
39
coding
Solve the programming task below in a Python markdown code block. The purpose of this problem is to verify whether the method you are using to read input data is sufficiently fast to handle problems branded with the enormous Input/Output warning. You are expected to be able to process at least 2.5MB of input data per s...
{"inputs": ["6 3\n1\n6\n201449\n16\n7\n60700\n7", "6 3\n1\n6\n201449\n18\n7\n60700\n7", "7 3\n1\n34\n966369\n7\n9\n40177\n11", "7 3\n1\n62\n334284\n16\n7\n60700\n7", "6 3\n1\n62\n201449\n16\n7\n60700\n7", "6 1\n1\n62\n190402\n16\n6\n60700\n7", "6 3\n1\n62\n334284\n16\n7\n60700\n7", "6 3\n1\n62\n201449\n16\n6\n60700\n7"...
171
276
coding
Solve the programming task below in a Python markdown code block. A magic island Geraldion, where Gerald lives, has its own currency system. It uses banknotes of several values. But the problem is, the system is not perfect and sometimes it happens that Geraldionians cannot express a certain sum of money with any set o...
{"inputs": ["1\n2\n", "1\n1\n", "1\n1\n", "1\n2\n", "1\n3\n", "1\n4\n", "1\n5\n", "1\n7\n"], "outputs": ["1\n", "-1\n", "-1\n", "1\n", "1\n", "1\n", "1\n", "1\n"]}
227
86
coding
Solve the programming task below in a Python markdown code block. Edward Leven loves multiples of eleven very much. When he sees a number, he always tries to find consecutive subsequences (or substrings) forming multiples of eleven. He calls such subsequences as 11-sequences. For example, he can find an 11-sequence 781...
{"inputs": ["17819\n1010\n10011\n7865275925328748785018788\n0", "17819\n0110\n10011\n7865275925328748785018788\n0", "17819\n0110\n10011\n4852349612300523475741654\n0", "17819\n0110\n00011\n4852349612300523475741654\n0", "17819\n0110\n01011\n6299136610007038575852406\n0", "17819\n0110\n01011\n8858159281710306483280973\n...
353
465
coding
Solve the programming task below in a Python markdown code block. Write a function ```python vowel_2_index``` that takes in a string and replaces all the vowels [a,e,i,o,u] with their respective positions within that string. E.g: ```python vowel_2_index('this is my string') == 'th3s 6s my str15ng' vowel_2_index('...
{"functional": "_inputs = [['this is my string'], ['Codewars is the best site in the world'], ['Tomorrow is going to be raining'], [''], [\"90's cornhole Austin, pickled butcher yr messenger bag gastropub next level leggings listicle meditation try-hard Vice. Taxidermy gastropub gentrify, meh fap organic ennui fingerst...
185
1,196
coding
Solve the programming task below in a Python markdown code block. Professor Sahil is a master artist, he always finds creative ways to teach lessons to his students. Today in Painting class he took all the students of the class to a wall. Professor Sahil asked every student to paint the wall upto a certain integral hei...
{"inputs": ["3\n5 4\n1 2 3 4 5\n3 3 3 3 3\n5 4\n3 5 1 2 3\n1 2 3 4 3\n5 5 \n5 4 3 2 3\n1 2 3 4 5"], "outputs": ["1\n2\n3"]}
657
89
coding
Solve the programming task below in a Python markdown code block. Chef likes problems related to learning new languages. He only knows first N letters of English alphabet. Also he explores all M-letter words formed by the characters he knows. Define cost for a given M-letter word S, cost(S) = P1, S1+P2, S2+...+PM, SM, ...
{"inputs": ["2 5 17\n7 9\n13 18\n10 12\n4 18\n3 9"], "outputs": ["aaaba"]}
318
43
coding
Solve the programming task below in a Python markdown code block. You have received data from a Bubble bot. You know your task is to make factory facilities, but before you even start, you need to know how big the factory is and how many rooms it has. When you look at the data you see that you have the dimensions of th...
{"inputs": ["6 1\n13\n5\n7\n15\n13\n7\n", "4 5\n9 14 9 12 13\n5 15 11 6 7\n5 9 14 9 14\n3 2 14 3 6\n", "4 5\n9 14 9 12 13\n5 15 11 6 7\n5 9 14 9 14\n3 2 14 3 14\n", "4 5\n9 14 11 12 13\n5 15 3 6 7\n5 9 14 9 14\n3 2 14 3 14\n", "4 5\n9 14 9 12 13\n5 15 11 6 7\n5 8 14 9 14\n3 2 14 3 14\n", "4 5\n9 14 11 12 13\n5 15 11 6 ...
397
510
coding
Solve the programming task below in a Python markdown code block. Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. Chef has always been fond of girls, but he could not make any girl his friend. In order to finally make one, he was asked to solve the following prob...
{"inputs": ["1\n4\nanxa"], "outputs": ["1"]}
534
17
coding
Solve the programming task below in a Python markdown code block. Imagine a triangle of numbers which follows this pattern: * Starting with the number "1", "1" is positioned at the top of the triangle. As this is the 1st row, it can only support a single number. * The 2nd row can support the next 2 numbers: "2" and ...
{"functional": "_inputs = [[1], [2], [3], [4], [15], [150], [100], [500], [1000], [10000]]\n_outputs = [[1], [5], [15], [34], [1695], [1687575], [500050], [62500250], [500000500], [500000005000]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclo...
198
266
coding
Solve the programming task below in a Python markdown code block. An abundant number or excessive number is a number for which the sum of its proper divisors is greater than the number itself. The integer 12 is the first abundant number. Its proper divisors are 1, 2, 3, 4 and 6 for a total of 16 (> 12). Derive funct...
{"functional": "_inputs = [[12], [18], [37], [120], [77], [118], [5830], [11410], [14771], [11690]]\n_outputs = [[True], [True], [False], [True], [False], [False], [True], [True], [False], [True]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.iscl...
144
233
coding
Solve the programming task below in a Python markdown code block. You are given $n$ rectangles, each of height $1$. Each rectangle's width is a power of $2$ (i. e. it can be represented as $2^x$ for some non-negative integer $x$). You are also given a two-dimensional box of width $W$. Note that $W$ may or may not be a...
{"inputs": ["2\n5 8\n1 2 8 2 8\n6 11\n4 8 8 2 2 8\n", "2\n5 9\n1 2 8 8 8\n6 10\n2 8 8 2 2 8\n", "2\n5 8\n1 2 8 2 8\n6 11\n4 2 8 2 2 8\n", "2\n5 8\n1 2 8 2 8\n6 11\n4 1 8 2 2 8\n", "2\n5 13\n2 2 8 2 8\n6 9\n2 8 8 2 2 1\n", "2\n5 8\n2 2 8 2 8\n6 11\n4 8 8 2 2 8\n", "2\n5 8\n4 2 8 2 8\n6 15\n2 8 8 2 2 1\n", "2\n5 13\n1 2 ...
611
334
coding
Solve the programming task below in a Python markdown code block. Shik loves sorted intervals. But currently he does not have enough time to sort all the numbers. So he decided to use Almost sorted intervals. An Almost sorted interval is a consecutive subsequence in a sequence which satisfies the following property: T...
{"inputs": ["5\n3 1 2 5 4\n"], "outputs": ["8\n"]}
220
24
coding
Solve the programming task below in a Python markdown code block. We define the sequence ```SF``` in the following way in terms of four previous sequences: ```S1```, ```S2```, ```S3``` and ```ST``` We are interested in collecting the terms of SF that are multiple of ten. The first term multiple of ten of this seque...
{"functional": "_inputs = [[1], [2], [3]]\n_outputs = [[60], [70080], [90700800]]\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 Fals...
297
181
coding
Solve the programming task below in a Python markdown code block. There are n coins labeled from 1 to n. Initially, coin c_i is on position i and is facing upwards ((c_1, c_2, ..., c_n) is a permutation of numbers from 1 to n). You can do some operations on these coins. In one operation, you can do the following: ...
{"inputs": ["3\n2 3 1\n", "3\n1 3 2\n", "3\n3 1 2\n", "3\n1 2 3\n", "3\n3 2 1\n", "3\n2 1 3\n", "4\n2 1 4 3\n", "4\n2 3 4 1\n"], "outputs": ["4\n1 2\n2 3\n1 3\n1 2\n", "3\n2 1\n1 3\n1 2\n", "4\n1 3\n3 2\n1 2\n1 3\n", "0\n", "3\n1 2\n2 3\n2 1\n", "\n3\n1 3\n3 2\n3 1\n", "4\n1 3\n1 4\n3 2\n3 1\n", "5\n1 2\n2 3\n2 4\n1 3\...
473
227
coding
Solve the programming task below in a Python markdown code block. Given an array A consisting of N non-negative integers. You need to perform the following operation (N - 1) times: Sort the array A in ascending order. Let M be the current size of the array A. Replace the array A by [(A_{2} - A_{1}), (A_{3} - A_{2}), ...
{"inputs": ["2\n4\n29 19 0 3\n1\n777"], "outputs": ["1\n777"]}
578
34
coding
Solve the programming task below in a Python markdown code block. You are making your very own boardgame. The game is played by two opposing players, featuring a 6 x 6 tile system, with the players taking turns to move their pieces (similar to chess). The design is finished, now it's time to actually write and implemen...
{"functional": "_inputs = [['K', 'A'], ['S', 'A'], ['k', 's'], ['a', 'a'], ['k', 'A'], ['K', 'a']]\n_outputs = [[-1], [-1], [-1], [-1], ['k'], ['K']]\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 isi...
681
204
coding
Solve the programming task below in a Python markdown code block. # The die is cast! Your task in this kata is to write a "dice roller" that interprets a subset of [dice notation](http://en.wikipedia.org/wiki/Dice_notation). # Description In most role-playing games, die rolls required by the system are given in the ...
{"functional": "_inputs = [[''], [{}], ['abc'], ['2d6+3 abc'], ['abc 2d6+3'], ['2d6++4']]\n_outputs = [[False], [False], [False], [False], [False], [False]]\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 ...
370
198
coding
Solve the programming task below in a Python markdown code block. Two people are playing a game with a string $s$, consisting of lowercase latin letters. On a player's turn, he should choose two consecutive equal letters in the string and delete them. For example, if the string is equal to "xaax" than there is only...
{"inputs": ["a\n", "a\n", "`\n", "_\n", "aa\n", "aa\n", "`a\n", "a`\n"], "outputs": ["No\n", "No\n", "No\n", "No\n", "Yes\n", "Yes\n", "No\n", "No\n"]}
266
71
coding
Solve the programming task below in a Python markdown code block. Paul hates palindromes. He assumes that string s is tolerable if each its character is one of the first p letters of the English alphabet and s doesn't contain any palindrome contiguous substring of length 2 or more. Paul has found a tolerable string s ...
{"inputs": ["1 2\na\n", "1 2\nb\n", "1 1\na\n", "1 2\nb\n", "1 2\na\n", "1 2\nb\n", "1 1\na\n", "1 4\na\n"], "outputs": ["b\n", "NO\n", "NO\n", "NO\n", "b\n", "NO\n", "NO\n", "b\n"]}
336
102
coding
Solve the programming task below in a Python markdown code block. The chef has one array of N natural numbers (might be in sorted order). Cheffina challenges chef to find the total number of inversions in the array. -----Input:----- - First-line will contain $T$, the number of test cases. Then the test cases follow. ...
{"inputs": ["1\n5\n5 4 1 3 2"], "outputs": ["8"]}
192
24
coding
Solve the programming task below in a Python markdown code block. Our Chef who was a renouned mathematician has recently got into diamonds' business. She has accidentally misplaced $Q$ diamonds into a jar which already had $N$ chocolates. She then started wondering about an interesting question as following. If we pi...
{"inputs": ["1\n2 2"], "outputs": ["3.3333333333"]}
396
27
coding
Solve the programming task below in a Python markdown code block. I'm traveling to a country with a rabbit. There are n cities in this country numbered from 1 to n, and the rabbit is now in city 1. City i is a point on the coordinate plane (xi, yi) ). Rabbits travel to meet the following conditions. * The travel path...
{"inputs": ["5\n100.1 90.1\n0 0\n0 10\n5 5\n10 0\n10 4", "5\n100.1 90.1\n0 0\n0 10\n7 5\n10 0\n10 10", "5\n100.1 90.1\n0 0\n0 10\n5 5\n10 0\n10 10", "5\n100.2380070184939 90.1\n0 0\n0 10\n5 9\n10 0\n9 4", "5\n100.2380070184939 90.1\n0 0\n0 10\n4 9\n7 0\n17 0", "5\n101.055831370051 90.1\n0 0\n1 10\n4 9\n7 0\n17 -1", "5\...
400
394
coding
Solve the programming task below in a Python markdown code block. Chef Leonardo has a decimal integer $N$ and a non-zero decimal digit $d$. $N$ does not contain the digit zero; specifically, $N$ should always be treated as a decimal integer without leading zeroes. Chef likes $d$ and does not like any other digit, so he...
{"inputs": ["3\n35 4\n42 4\n24 9"], "outputs": ["34\n24\n24"]}
496
34
coding
Solve the programming task below in a Python markdown code block. This kata focuses on the Numpy python package and you can read up on the Numpy array manipulation functions here: https://docs.scipy.org/doc/numpy-1.13.0/reference/routines.array-manipulation.html You will get two integers `N` and `M`. You must return a...
{"functional": "_inputs = [[10, 1], [10, 3], [10, 97]]\n_outputs = [[[[4, 0, 1, 2, 3], [9, 5, 6, 7, 8]]], [[[2, 3, 4, 0, 1], [7, 8, 9, 5, 6]]], [[[3, 4, 0, 1, 2], [8, 9, 5, 6, 7]]]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_t...
269
264
coding
Solve the programming task below in a Python markdown code block. # Task You are given n rectangular boxes, the ith box has the length lengthi, the width widthi and the height heighti. Your task is to check if it is possible to pack all boxes into one so that inside each box there is no more than one another box (...
{"functional": "_inputs = [[[1, 3, 2], [1, 3, 2], [1, 3, 2]], [[1, 1], [1, 1], [1, 1]], [[3, 1, 2], [3, 1, 2], [3, 2, 1]], [[2], [3], [4]], [[5, 7, 4, 1, 2], [4, 10, 3, 1, 4], [6, 5, 5, 1, 2]], [[6, 4], [5, 3], [4, 5]], [[6, 3], [5, 4], [4, 5]], [[6, 3], [5, 5], [4, 4]], [[883, 807], [772, 887], [950, 957]], [[6, 5], [...
513
507
coding
Solve the programming task below in a Python markdown code block. George woke up and saw the current time s on the digital clock. Besides, George knows that he has slept for time t. Help George! Write a program that will, given time s and t, determine the time p when George went to bed. Note that George could have go...
{"inputs": ["05:50\n05:44\n", "00:00\n01:00\n", "00:01\n00:00\n", "23:59\n23:59\n", "23:44\n23:55\n", "00:00\n13:12\n", "12:00\n23:59\n", "12:44\n12:44\n"], "outputs": ["00:06\n", "23:00\n", "00:01\n", "00:00\n", "23:49\n", "10:48\n", "12:01\n", "00:00\n"]}
355
182
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. A transformation sequence from word beginWord to word endWord using a dictionary wordList is a sequence of words beginWord -> s1 -> s2 -> ... -> sk such that: Every adjacent pair of words differs by a single letter. ...
{"functional": "def check(candidate):\n assert candidate(beginWord = \"hit\", endWord = \"cog\", wordList = [\"hot\",\"dot\",\"dog\",\"lot\",\"log\",\"cog\"]) == [[\"hit\",\"hot\",\"dot\",\"dog\",\"cog\"],[\"hit\",\"hot\",\"lot\",\"log\",\"cog\"]]\n assert candidate(beginWord = \"hit\", endWord = \"cog\", wordLis...
204
120
coding
Solve the programming task below in a Python markdown code block. You are given a permutation of natural integers from 1 to N, inclusive. Initially, the permutation is 1, 2, 3, ..., N. You are also given M pairs of integers, where the i-th is (Li Ri). In a single turn you can choose any of these pairs (let's say with t...
{"inputs": ["2\n7 4\n3 1 2 4 5 7 6\n1 2\n4 4\n6 7\n2 3\n4 2\n2 1 3 4\n2 4\n2 3", "2\n7 4\n6 1 2 4 5 7 6\n1 2\n4 4\n6 7\n2 3\n4 2\n2 1 3 4\n2 4\n2 3", "2\n7 4\n3 1 2 4 5 7 6\n1 2\n4 4\n6 7\n2 3\n4 2\n2 1 3 6\n2 4\n2 3", "2\n7 4\n6 1 2 4 5 7 6\n1 2\n4 0\n6 7\n2 3\n4 2\n2 1 3 4\n2 4\n2 3", "2\n8 4\n6 1 2 4 5 7 6\n1 2\n4 4...
375
509
coding
Solve the programming task below in a Python markdown code block. Polycarp wants to train before another programming competition. During the first day of his training he should solve exactly $1$ problem, during the second day — exactly $2$ problems, during the third day — exactly $3$ problems, and so on. During the $k$...
{"inputs": ["1\n2\n", "1\n2\n", "1\n3\n", "1\n1\n", "1\n4\n", "1\n7\n", "2\n2 3\n", "2\n2 3\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "2\n", "2\n"]}
377
90
coding
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin Chinese and Russian as well. Special Sum of 4 numbers (a, b, c, d) is defined as: |a+b-c-d| + |a+c-b-d| + |a+d-b-c| + |c+d-a-b| + |b+d-a-c| + |b+c-a-d| where |x| denotes absolute value of x. Read problems statements...
{"inputs": ["3\n4\n1 2 3 3\n5\n1 2 3 4 5\n6\n9 18 28 23 12 9"], "outputs": ["10\n76\n1176"]}
391
61
coding
Solve the programming task below in a Python markdown code block. A and B are preparing themselves for programming contests. To train their logical thinking and solve problems better, A and B decided to play chess. During the game A wondered whose position is now stronger. For each chess piece we know its weight: t...
{"inputs": ["...QK...\n........\n........\n........\n........\n........\n........\n...rk...\n", "rnbqkbnr\npppppppp\n........\n........\n........\n........\nPPPPPPPP\nRNBQKBNR\n", "rppppppr\n...k....\n........\n........\n........\n........\nK...Q...\n........\n", "....bQ.K\n.B......\n.....P..\n........\n........\n........
596
315
coding
Solve the programming task below in a Python markdown code block. An array is defined to be `odd-heavy` if it contains at least one odd element and every element whose value is `odd` is greater than every even-valued element. eg. ``` Array [11,4,9,2,8] is odd-heavy because:- its odd elements [11,9] are greater than...
{"functional": "_inputs = [[[0, 2, 19, 4, 4]], [[1, -2, -1, 2]], [[-3, 2, 1, 3, -1, -2]], [[3, 4, -2, -3, -2]], [[-1, 1, -2, 2, -2, -2, -4, 4]], [[-1, -2, 21]], [[0, 0, 0, 0]], [[0, -1, 1]], [[0, 2, 3]], [[0]], [[]], [[1]], [[0, 1, 2, 3, 4, 0, -2, -1, -4, -3]], [[1, -1, 3, -1]], [[1, -1, 2, -2, 3, -3, 0]], [[3]], [[2, ...
225
432
coding
Solve the programming task below in a Python markdown code block. Let us calculate the sum of k-th powers of natural numbers from 1 to n. As the result can be quite large, output the result modulo some integer p. ------ Input ------ First t≤10 - the number of test cases. Each test case consist of numbers: 1≤n≤100000...
{"inputs": ["4\n10 1 1000000\n10 2 1000000\n10 3 1000000\n10 4 1000000"], "outputs": ["55\n385\n3025\n25333"]}
229
80
coding
Solve the programming task below in a Python markdown code block. Read problem statements in [Mandarin], [Bengali], [Russian], and [Vietnamese] as well. Chef has three spells. Their powers are A, B, and C respectively. Initially, Chef has 0 hit points, and if he uses a spell with power P, then his number of hit points...
{"inputs": ["2\n4 2 8\n10 14 18"], "outputs": ["12\n32"]}
413
31
coding
Solve the programming task below in a Python markdown code block. Given the participants' score sheet for your University Sports Day, you are required to find the runner-up score. You are given $n$ scores. Store them in a list and find the score of the runner-up. Input Format The first line contains $n$. The second ...
{"inputs": ["5\n2 3 6 6 5\n"], "outputs": ["5\n"]}
213
24
coding
Solve the programming task below in a Python markdown code block. We have caught N sardines. The deliciousness and fragrantness of the i-th sardine is A_i and B_i, respectively. We will choose one or more of these sardines and put them into a cooler. However, two sardines on bad terms cannot be chosen at the same time....
{"inputs": ["3\n0 2\n4 0\n0 0", "3\n0 0\n-2 0\n2 0", "3\n1 0\n-2 0\n2 0", "3\n1 0\n-2 0\n2 1", "3\n1 0\n-2 0\n0 1", "3\n1 0\n-2 0\n0 2", "3\n1 0\n-1 0\n0 1", "3\n1 4\n-1 1\n2 -1"], "outputs": ["3\n", "4\n", "7\n", "7\n", "4\n", "4\n", "4\n", "7\n"]}
349
165
coding
Solve the programming task below in a Python markdown code block. How many days are we represented in a foreign country? My colleagues make business trips to a foreign country. We must find the number of days our company is represented in a country. Every day that one or more colleagues are present in the country is a...
{"functional": "_inputs = [[[[10, 15], [25, 35]]], [[[2, 8], [220, 229], [10, 16]]]]\n_outputs = [[17], [24]]\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 l...
244
201
coding
Solve the programming task below in a Python markdown code block. You are given an array A of N elements. For any ordered triplet (i, j, k) such that i, j, and k are pairwise distinct and 1 ≤ i, j, k ≤ N, the value of this triplet is (A_{i}-A_{j})\cdot A_{k}. You need to find the maximum value among all possible ordere...
{"inputs": ["3\n3\n1 1 3\n5\n3 4 4 1 2\n5\n23 17 21 18 19"], "outputs": ["2\n12\n126"]}
608
56
coding
Solve the programming task below in a Python markdown code block. Giant chess is quite common in Geraldion. We will not delve into the rules of the game, we'll just say that the game takes place on an h × w field, and it is painted in two colors, but not like in chess. Almost all cells of the field are white and only s...
{"inputs": ["2 2 2\n2 1\n1 2\n", "3 4 2\n2 2\n2 4\n", "3 4 2\n3 2\n2 4\n", "3 7 2\n3 2\n2 4\n", "2 4 2\n2 2\n2 3\n", "3 4 2\n2 2\n2 3\n", "100000 100000 2\n1 2\n2 1\n", "100 100 3\n15 7\n16 15\n15 88\n"], "outputs": ["0\n", "2", "3", "9", "1", "2\n", "0\n", "950251154"]}
461
192
coding
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. Chef is a well-known chef, and everyone wishes to taste his dishes. As you might know, cooking is not an easy job at all and cooking everyday makes the chef very tired. So, ...
{"inputs": ["2\n9 2\n110001111\n4 1\n1001"], "outputs": ["2\n2"]}
637
37
coding
Solve the programming task below in a Python markdown code block. Create a function that takes a number as an argument and returns a grade based on that number. Score | Grade -----------------------------------------|----- Anything greater than 1 or less than 0.6 | "F" 0.9 or greater...
{"functional": "_inputs = [[1], [1.01], [0.2], [0.7], [0.8], [0.9], [0.6], [0.5], [0]]\n_outputs = [['A'], ['F'], ['F'], ['C'], ['B'], ['A'], ['D'], ['F'], ['F']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol...
195
217
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given n points on a 1-D plane, where the ith point (from 0 to n-1) is at x = i, find the number of ways we can draw exactly k non-overlapping line segments such that each segment covers two or more points. The endpoin...
{"functional": "def check(candidate):\n assert candidate(n = 4, k = 2) == 5\n assert candidate(n = 3, k = 1) == 3\n assert candidate(n = 30, k = 7) == 796297179\n assert candidate(n = 5, k = 3) == 7\n assert candidate(n = 3, k = 2) == 1\n\n\ncheck(Solution().numberOfSets)"}
169
113
coding
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"]}
413
110
coding
Solve the programming task below in a Python markdown code block. A substring of some string is called the most frequent, if the number of its occurrences is not less than number of occurrences of any other substring. You are given a set of strings. A string (not necessarily from this set) is called good if all elemen...
{"inputs": ["1\nz\n", "1\nz\n", "1\ny\n", "1\nx\n", "1\nlol\n", "1\nlol\n", "1\nlnl\n", "1\nlln\n"], "outputs": ["z\n", "z\n", "y\n", "x\n", "NO\n", "NO\n", "NO\n", "NO\n"]}
422
88
coding
Solve the programming task below in a Python markdown code block. Sereja has an array A of N positive integers : A[1], A[2], A[3], ... , A[N]. In a single operation on the array, he performs the following two steps : - Pick two indices i, j s.t. A[i] > A[j] - A[i] -= A[j] Sereja can apply these operations any num...
{"inputs": ["2\n1\n1\n3\n2 4 6"], "outputs": ["1\n6"]}
421
26
coding
Solve the programming task below in a Python markdown code block. Alice is a kindergarten teacher. She wants to give some candies to the children in her class.  All the children sit in a line and each of them has a rating score according to his or her performance in the class.  Alice wants to give at least 1 candy to e...
{"inputs": ["3\n1\n2\n2\n", "8\n2\n4\n3\n5\n2\n6\n4\n5\n", "10\n2\n4\n2\n6\n1\n7\n8\n9\n2\n1\n"], "outputs": ["4\n", "12\n", "19\n"]}
500
75
coding
Solve the programming task below in a Python markdown code block. You are given a string $s$. You have to reverse it — that is, the first letter should become equal to the last letter before the reversal, the second letter should become equal to the second-to-last letter before the reversal — and so on. For example, if...
{"inputs": ["2\ngg\n", "2\nzg\n", "2\ngg\n", "2\nzg\n", "2\nfg\n", "2\ngz\n", "2\nfh\n", "2\nhf\n"], "outputs": ["0\n", "1\n", "0\n", "1\n", "1\n", "1\n", "1\n", "1\n"]}
327
91
coding
Solve the programming task below in a Python markdown code block. Currently, people's entertainment is limited to programming contests. The activity of the entertainment club of a junior high school to which she belongs is to plan and run a programming contest. Her job is not to create problems. It's a behind-the-scene...
{"inputs": ["1 1 1 1 1 1\n1 1 1 0 0 0\n1 0 0 0 1 0\n3 0 0 3 0 0\n3 1 0 1 3 1\n1 2 0 2 0 1\n0 0 1 1 0 3\n1 0 0 1 1 0\n0 0 0 0 0 0", "1 1 1 1 1 1\n1 1 1 0 0 0\n1 0 0 0 1 0\n3 0 0 0 0 0\n3 1 0 1 3 1\n1 2 0 2 0 1\n0 0 1 1 0 3\n1 0 0 1 1 0\n0 0 0 0 0 0", "1 1 1 1 1 1\n1 1 1 0 0 0\n1 0 0 0 1 1\n2 0 0 3 0 0\n3 1 0 1 3 1\n1 2 ...
625
1,022
coding
Solve the programming task below in a Python markdown code block. The time has finally come, MKnez and Baltic are to host The Game of the Century. For that purpose, they built a village to lodge its participants. The village has the shape of an equilateral triangle delimited by three roads of length $n$. It is cut int...
{"inputs": ["3\n3\n001\n001\n010\n1\n0\n0\n0\n3\n111\n011\n100\n"], "outputs": ["2\n0\n3\n"]}
723
54
coding
Solve the programming task below in a Python markdown code block. This morning, Roman woke up and opened the browser with $n$ opened tabs numbered from $1$ to $n$. There are two kinds of tabs: those with the information required for the test and those with social network sites. Roman decided that there are too many tab...
{"inputs": ["3 2\n1 1 1\n", "3 2\n1 1 1\n", "3 3\n1 1 1\n", "3 2\n1 1 -1\n", "3 2\n1 1 -1\n", "3 3\n1 1 -1\n", "4 2\n1 1 -1 1\n", "4 2\n1 1 1 -1\n"], "outputs": ["2\n", "2\n", "2\n", "1\n", "1\n", "2\n", "2\n", "2\n"]}
628
138
coding
Solve the programming task below in a Python markdown code block. City X consists of n vertical and n horizontal infinite roads, forming n × n intersections. Roads (both vertical and horizontal) are numbered from 1 to n, and the intersections are indicated by the numbers of the roads that form them. Sand roads have lo...
{"inputs": ["1\n1 1\n", "1\n1 1\n", "2\n1 1\n1 2\n2 1\n2 2\n", "2\n1 1\n2 2\n1 2\n2 1\n", "2\n1 2\n2 2\n2 1\n1 1\n", "2\n1 2\n2 2\n2 1\n1 1\n", "2\n1 1\n2 2\n1 2\n2 1\n", "2\n1 1\n2 2\n1 2\n1 1\n"], "outputs": ["1 \n", "1\n", "1 4 \n", "1 2 \n", "1 3 \n", "1 3\n", "1 2\n", "1 2 "]}
644
190
coding
Solve the programming task below in a Python markdown code block. Given a random string consisting of numbers, letters, symbols, you need to sum up the numbers in the string. Note: - Consecutive integers should be treated as a single number. eg, `2015` should be treated as a single number `2015`, NOT four numbers - ...
{"functional": "_inputs = [['In 2015, I want to know how much does iPhone 6+ cost?'], ['1+1=2'], ['e=mc^2'], ['aHR0cDovL3d3dy5jb2Rld2Fycy5jb20va2F0YS9uZXcvamF2YXNjcmlwdA=='], ['a30561ff4fb19170aa598b1431b52edad1fcc3e0'], ['x1KT CmZ__\\rYouOY8Uqu-ETtz'], ['x1KT-8&*@\"CmZ__\\rYouO __Y8Uq\\\\u-ETtz'], [''], ['Hello Wor...
222
357
coding
Solve the programming task below in a Python markdown code block. You are given two strings $s$ and $t$, both of length $n$. Each character in both string is 'a', 'b' or 'c'. In one move, you can perform one of the following actions: choose an occurrence of "ab" in $s$ and replace it with "ba"; choose an occurrence ...
{"inputs": ["5\n3\ncab\ncab\n1\na\nb\n6\nabbabc\nbbaacb\n10\nbcaabababc\ncbbababaac\n2\nba\nab\n"], "outputs": ["YES\nNO\nYES\nYES\nNO\n"]}
386
66
coding
Solve the programming task below in a Python markdown code block. Iroha is very particular about numbers. There are K digits that she dislikes: D_1, D_2, ..., D_K. She is shopping, and now paying at the cashier. Her total is N yen (the currency of Japan), thus she has to hand at least N yen to the cashier (and possibl...
{"inputs": ["3 1\n0", "6 1\n0", "5 1\n0", "4 1\n1", "8 1\n0", "2 1\n0", "7 1\n1", "1 1\n0"], "outputs": ["3\n", "6\n", "5\n", "4\n", "8\n", "2\n", "7\n", "1\n"]}
324
94
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an array of integers nums which is sorted in ascending order, and an integer target, write a function to search target in nums. If target exists, then return its index. Otherwise, return -1. You must write an al...
{"functional": "def check(candidate):\n assert candidate(nums = [-1,0,3,5,9,12], target = 9) == 4\n assert candidate(nums = [-1,0,3,5,9,12], target = 2) == -1\n\n\ncheck(Solution().search)"}
106
74
coding
Solve the programming task below in a Python markdown code block. According to rules of the Berland fashion, a jacket should be fastened by all the buttons except only one, but not necessarily it should be the last one. Also if the jacket has only one button, it should be fastened, so the jacket will not swinging open....
{"inputs": ["1\n1\n", "1\n0\n", "1\n0\n", "1\n1\n", "2\n0 1\n", "2\n1 0\n", "2\n0 0\n", "2\n1 1\n"], "outputs": ["YES\n", "NO\n", "NO\n", "YES\n", "YES\n", "YES\n", "NO\n", "NO\n"]}
229
94
coding
Solve the programming task below in a Python markdown code block. Joisino the magical girl has decided to turn every single digit that exists on this world into 1. Rewriting a digit i with j (0≤i,j≤9) costs c_{i,j} MP (Magic Points). She is now standing before a wall. The wall is divided into HW squares in H rows and W...
{"inputs": ["2 4\n0 9 9 9 9 9 9 9 9 9\n9 0 9 9 9 9 9 9 9 9\n9 9 0 9 9 9 9 9 9 9\n9 9 9 0 2 9 9 9 9 9\n9 9 9 9 0 9 9 9 9 2\n9 9 9 9 9 0 9 9 9 9\n9 9 9 9 9 9 0 9 9 9\n9 9 9 9 9 9 9 0 9 9\n9 9 9 9 2 9 9 9 0 9\n9 2 9 9 9 9 9 9 9 0\n-1 -1 -1 -1\n8 1 1 8", "2 4\n0 9 9 9 9 9 9 9 9 9\n9 0 9 9 9 9 9 9 9 9\n9 9 0 9 9 9 9 9 9 9\n...
659
1,825
coding
Solve the programming task below in a Python markdown code block. Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well. In Chefland, there are $N$ cities (numbered $1$ through $N$). Initially, there are no roads between them. The Mayor of Chefland has ordered engineer...
{"inputs": ["2\n3\n5"], "outputs": ["3\n8"]}
388
18
coding
Solve the programming task below in a Python markdown code block. Given a set of distinct integers, print the size of a maximal subset of $S$ where the sum of any $2$ numbers in $\text{S'}$ is not evenly divisible by $k$. Example $S=[19,10,12,10,24,25,22]$ $k=4$ One of the arrays that can be created is $S'[0]=[10,1...
{"inputs": ["4 3 \n1 7 2 4 \n"], "outputs": ["3\n"]}
475
27
coding
Solve the programming task below in a Python markdown code block. Polycarpus loves hamburgers very much. He especially adores the hamburgers he makes with his own hands. Polycarpus thinks that there are only three decent ingredients to make hamburgers from: a bread, sausage and cheese. He writes down the recipe of his ...
{"inputs": ["B\n1 1 1\n1 1 1\n381\n", "B\n1 1 1\n1 1 1\n381\n", "B\n1 2 1\n1 1 1\n381\n", "BSC\n3 5 6\n7 3 9\n100\n", "BSC\n3 5 6\n7 3 9\n100\n", "BSC\n3 5 9\n7 3 9\n100\n", "BSC\n3 5 9\n7 3 5\n100\n", "BSC\n3 5 9\n7 3 5\n101\n"], "outputs": ["382\n", "382\n", "382\n", "10\n", "10\n", "11\n", "12\n", "12\n"]}
675
214
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Consider a function that implements an algorithm similar to Binary Search. The function has two input parameters: sequence is a sequence of integers, and target is an integer value. The purpose of the function is to f...
{"functional": "def check(candidate):\n assert candidate(nums = [7]) == 1\n assert candidate(nums = [-1,5,2]) == 1\n\n\ncheck(Solution().binarySearchableNumbers)"}
264
49
coding
Solve the programming task below in a Python markdown code block. You are playing a new computer game in which you have to fight monsters. In a dungeon you are trying to clear, you met three monsters; the first of them has $a$ health points, the second has $b$ health points, and the third has $c$. To kill the monsters...
{"inputs": ["1\n3 1 5\n", "1\n1 2 6\n", "1\n4 4 1\n", "1\n7 1 1\n", "1\n1 1 7\n", "1\n4 1 4\n", "1\n9 2 7\n", "1\n1 3 5\n"], "outputs": ["YES\n", "YES\n", "YES\n", "YES\n", "YES\n", "YES\n", "YES\n", "YES\n"]}
557
118
coding
Solve the programming task below in a Python markdown code block. Snuke has an integer sequence A of length N. He will freely choose an integer b. Here, he will get sad if A_i and b+i are far from each other. More specifically, the sadness of Snuke is calculated as follows: * abs(A_1 - (b+1)) + abs(A_2 - (b+2)) + ......
{"inputs": ["5\n2 0 1 8 7", "5\n2 2 3 5 5", "5\n2 2 3 5 10", "5\n2 0 1 8 10", "5\n2 2 2 5 10", "5\n2 2 2 8 10", "5\n2 0 2 8 10", "6\n6 0 4 3 2 1"], "outputs": ["10\n", "2", "6\n", "13\n", "7\n", "10\n", "12\n", "15\n"]}
297
153
coding
Solve the programming task below in a Python markdown code block. Pankaj likes to eat Ice cream when he is working late into the night. Today has been yet another long day for Pankaj. So, he wants to eat ice cream now. He opens the fridge and sees that he has 2 types of containers holding the ice cream. The first conta...
{"inputs": ["2\n1.00 1.00 1.00 1.00\n3.02 7.23 5.20 6.00\n\n"], "outputs": ["3.141592654 3.141592654\n126.739919445 509.691992118"]}
401
104
coding
Solve the programming task below in a Python markdown code block. Training is indispensable for achieving good results at ICPC. Rabbit wants to win at ICPC, so he decided to practice today as well. Today's training is to perform a very large number of calculations to improve the calculation power and raise awareness. ...
{"inputs": ["4\n2\n5\n0\n5", "4\n0\n5\n4\n5", "4\n2\n9\n0\n5", "4\n0\n5\n4\n4", "4\n0\n3\n8\n1", "4\n7\n8\n0\n0", "4\n0\n5\n6\n4", "4\n1\n3\n8\n1"], "outputs": ["5\n5\n2\n0\n", "5\n5\n4\n0\n", "5\n9\n2\n0\n", "4\n5\n4\n0\n", "3\n8\n1\n0\n", "7\n8\n0\n0\n", "5\n6\n4\n0\n", "3\n8\n1\n1\n"]}
305
174
coding
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]],...
359
357
coding
Solve the programming task below in a Python markdown code block. A special type of prime is generated by the formula `p = 2^m * 3^n + 1` where `m` and `n` can be any non-negative integer. The first `5` of these primes are `2, 3, 5, 7, 13`, and are generated as follows: ```Haskell 2 = 2^0 * 3^0 + 1 3 = 2^1 * 3^0 + 1 ...
{"functional": "_inputs = [[0, 10], [0, 15], [0, 100], [100, 1000], [340, 500], [3400, 5000], [20000, 60000], [750000, 1000000], [300000, 900000], [100, 1000000], [500000, 1000000], [1000000, 1500000], [0, 1500000]]\n_outputs = [[4], [5], [10], [8], [2], [2], [2], [3], [6], [32], [5], [2], [44]]\nimport math\ndef _deep...
346
353
coding
Solve the programming task below in a Python markdown code block. #Bubbleing around Since everybody hates chaos and loves sorted lists we should implement some more sorting algorithms. Your task is to implement a Bubble sort (for some help look at https://en.wikipedia.org/wiki/Bubble_sort) and return a list of snapsho...
{"functional": "_inputs = [[[]], [[1, 2, 3, 4, 5, 6, 7, 8, 9]], [[1, 3, 3, 7, 4, 2]]]\n_outputs = [[[]], [[]], [[[1, 3, 3, 4, 7, 2], [1, 3, 3, 4, 2, 7], [1, 3, 3, 2, 4, 7], [1, 3, 2, 3, 4, 7], [1, 2, 3, 3, 4, 7]]]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n ...
220
292
coding
Solve the programming task below in a Python markdown code block. In the Bus of Characters there are $n$ rows of seat, each having $2$ seats. The width of both seats in the $i$-th row is $w_i$ centimeters. All integers $w_i$ are distinct. Initially the bus is empty. On each of $2n$ stops one passenger enters the bus. ...
{"inputs": ["1\n1\n01\n", "1\n1\n01\n", "1\n0\n01\n", "1\n-1\n01\n", "2\n3 1\n0011\n", "2\n0 1\n0011\n", "2\n3 1\n0011\n", "2\n-1 1\n0011\n"], "outputs": ["1 1 \n", "1 1 ", "1 1\n", "1 1\n", "2 1 1 2 \n", "1 2 2 1\n", "2 1 1 2 ", "1 2 2 1\n"]}
668
160
coding
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. We call a subarray of nums nice if the bitwise AND of every pair of elements that are in different positions in the subarray is equal to 0. Return the lengt...
{"functional": "def check(candidate):\n assert candidate(nums = [1,3,8,48,10]) == 3\n assert candidate(nums = [3,1,5,11,13]) == 1\n\n\ncheck(Solution().longestNiceSubarray)"}
127
66
coding
Solve the programming task below in a Python markdown code block. In music, if you double (or halve) the pitch of any note you will get to the same note again. "Concert A" is fixed at 440 Hz, and every other note is defined based on that. 880 Hz is also an A, as is 1760 Hz, as is 220 Hz. There are 12 notes in Western...
{"functional": "_inputs = [[440], [220], [880], [523.25], [261.625], [1046.5]]\n_outputs = [['A'], ['A'], ['A'], ['C'], ['C'], ['C']]\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...
396
206
coding
Solve the programming task below in a Python markdown code block. You are given a sequence of positive integers of length N, A=a_1,a_2,…,a_{N}, and an integer K. How many contiguous subsequences of A satisfy the following condition? - (Condition) The sum of the elements in the contiguous subsequence is at least K. We ...
{"inputs": ["1 4\n3\n", "1 64\n64\n", "1 33\n34\n", "2 2\n3 5\n", "3 5\n3 3 3\n", "4 10\n6 1 2 7\n", "8 29\n6 10 9 7 5 3 2 6\n", "6 231759\n58478 68246 31455 68061 22344 58784\n"], "outputs": ["0\n", "1\n", "1\n", "3\n", "3\n", "2\n", "10\n", "3\n"]}
297
175
coding
Solve the programming task below in a Python markdown code block. A grid is a perfect starting point for many games (Chess, battleships, Candy Crush!). Making a digital chessboard I think is an interesting way of visualising how loops can work together. Your task is to write a function that takes two integers `rows` ...
{"functional": "_inputs = [[1, 1], [1, 2], [2, 1], [2, 2], [6, 6]]\n_outputs = [[[['O']]], [[['O', 'X']]], [[['O'], ['X']]], [[['O', 'X'], ['X', 'O']]], [[['O', 'X', 'O', 'X', 'O', 'X'], ['X', 'O', 'X', 'O', 'X', 'O'], ['O', 'X', 'O', 'X', 'O', 'X'], ['X', 'O', 'X', 'O', 'X', 'O'], ['O', 'X', 'O', 'X', 'O', 'X'], ['X',...
288
324
coding
Solve the programming task below in a Python markdown code block. N Snukes called Snuke 1, Snuke 2, ..., Snuke N live in a town. There are K kinds of snacks sold in this town, called Snack 1, Snack 2, ..., Snack K. The following d_i Snukes have Snack i: Snuke A_{i, 1}, A_{i, 2}, \cdots, A_{i, {d_i}}. Takahashi will wal...
{"inputs": ["1 1\n1\n1\n", "3 1\n2\n1 3\n1\n3", "5 1\n2\n1 3\n1\n3", "9 0\n2\n4 0\n2\n0", "3 0\n2\n1 3\n1\n3", "5 1\n2\n1 4\n1\n3", "3 0\n1\n1 3\n1\n3", "5 1\n2\n1 4\n2\n3"], "outputs": ["0\n", "1\n", "3\n", "9\n", "3\n", "3\n", "3\n", "3\n"]}
370
153
coding
Solve the programming task below in a Python markdown code block. You are given an array $a$ consisting of $n$ integers. Your task is to say the number of such positive integers $x$ such that $x$ divides each number from the array. In other words, you have to find the number of common divisors of all elements in the a...
{"inputs": ["1\n1\n", "1\n1\n", "1\n4\n", "1\n2\n", "1\n3\n", "1\n5\n", "1\n15\n", "1\n15\n"], "outputs": ["1\n", "1\n", "3\n", "2\n", "2\n", "2\n", "4\n", "4\n"]}
327
88
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a binary string s ​​​​​without leading zeros, return true​​​ if s contains at most one contiguous segment of ones. Otherwise, return false.   Please complete the following python code precisely: ```python class ...
{"functional": "def check(candidate):\n assert candidate(s = \"1001\") == False\n assert candidate(s = \"110\") == True\n\n\ncheck(Solution().checkOnesSegment)"}
81
48
coding
Solve the programming task below in a Python markdown code block. Compute A \times B. -----Constraints----- - 1 \leq A \leq 100 - 1 \leq B \leq 100 - All values in input are integers. -----Input----- Input is given from Standard Input in the following format: A B -----Output----- Print the value A \times B as an ...
{"inputs": ["4 5", "1 1", "1 2", "1 3", "4 2", "6 2", "2 5", "2 5\n"], "outputs": ["20\n", "1\n", "2\n", "3\n", "8\n", "12\n", "10", "10\n"]}
119
82
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a string s, return the string after replacing every uppercase letter with the same lowercase letter.   Please complete the following python code precisely: ```python class Solution: def toLowerCase(self, s: ...
{"functional": "def check(candidate):\n assert candidate(s = \"Hello\") == \"hello\"\n assert candidate(s = \"here\") == \"here\"\n assert candidate(s = \"LOVELY\") == \"lovely\"\n\n\ncheck(Solution().toLowerCase)"}
66
60
coding
Solve the programming task below in a Python markdown code block. Daniel is organizing a football tournament. He has come up with the following tournament format: In the first several (possibly zero) stages, while the number of teams is even, they split in pairs and play one game for each pair. At each stage the lose...
{"inputs": ["3\n", "2\n", "1\n", "4\n", "5\n", "6\n", "7\n", "8\n"], "outputs": ["3\n4\n", "-1\n", "2\n", "-1\n", "-1\n", "6\n", "8\n", "-1\n"]}
442
72
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given the coordinates of two rectilinear rectangles in a 2D plane, return the total area covered by the two rectangles. The first rectangle is defined by its bottom-left corner (ax1, ay1) and its top-right corner (ax2...
{"functional": "def check(candidate):\n assert candidate(ax1 = -3, ay1 = 0, ax2 = 3, ay2 = 4, bx1 = 0, by1 = -1, bx2 = 9, by2 = 2) == 45\n assert candidate(ax1 = -2, ay1 = -2, ax2 = 2, ay2 = 2, bx1 = -2, by1 = -2, bx2 = 2, by2 = 2) == 16\n\n\ncheck(Solution().computeArea)"}
166
131
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given two strings s and t, return true if they are both one edit distance apart, otherwise return false. A string s is said to be one distance apart from a string t if you can: Insert exactly one character into s to ...
{"functional": "def check(candidate):\n assert candidate(s = \"ab\", t = \"acb\") == True\n assert candidate(s = \"cab\", t = \"ad\") == False\n\n\ncheck(Solution().isOneEditDistance)"}
127
53
coding
Solve the programming task below in a Python markdown code block. Fibonacci numbers are generated by setting F0 = 0, F1 = 1, and then using the formula: # Fn = Fn-1 + Fn-2 Your task is to efficiently calculate the **n**th element in the Fibonacci sequence and then count the occurrence of each digit in the number. Ret...
{"functional": "_inputs = [[10]]\n_outputs = [[[[2, 5]]]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) != len(b): return False\n return all(_d...
334
161
coding
Solve the programming task below in a Python markdown code block. You are given a permutation p of length n. Also you are given m foe pairs (a_{i}, b_{i}) (1 ≤ a_{i}, b_{i} ≤ n, a_{i} ≠ b_{i}). Your task is to count the number of different intervals (x, y) (1 ≤ x ≤ y ≤ n) that do not contain any foe pairs. So you sho...
{"inputs": ["2 1\n1 2\n1 2\n", "2 1\n1 2\n1 2\n", "4 2\n1 3 2 4\n3 2\n2 4\n", "4 2\n1 3 2 4\n3 2\n2 1\n", "4 2\n1 3 2 4\n1 2\n2 1\n", "4 2\n1 3 2 4\n3 2\n4 1\n", "4 2\n1 3 2 4\n3 2\n2 4\n", "3 4\n1 2 3\n1 3\n1 2\n1 3\n2 3\n"], "outputs": ["2\n", "2", "5\n", "6\n", "8\n", "6\n", "5", "3\n"]}
561
202
coding
Solve the programming task below in a Python markdown code block. Takahashi is distributing N balls to K persons. If each person has to receive at least one ball, what is the maximum possible difference in the number of balls received between the person with the most balls and the person with the fewest balls? Constr...
{"inputs": ["9 5", "4 2", "2 2", "2 3", "0 3", "1 3", "0 9", "0 6"], "outputs": ["4\n", "2\n", "0\n", "-1\n", "-3\n", "-2\n", "-9\n", "-6\n"]}
153
78
coding
Solve the programming task below in a Python markdown code block. At first, let's define function $f(x)$ as follows: $$ \begin{matrix} f(x) & = & \left\{ \begin{matrix} \frac{x}{2} & \mbox{if } x \text{ is even} \\ x - 1 & \mbox{otherwise } \end{matrix} \right. \end{matrix} $$ We can see that if we choose some value $...
{"inputs": ["1 1\n", "2 1\n", "1 1\n", "2 1\n", "8 5\n", "11 3\n", "11 6\n", "14 5\n"], "outputs": ["1\n", "2\n", "1\n", "2\n", "2\n", "5\n", "4\n", "6\n"]}
599
89
coding
Solve the programming task below in a Python markdown code block. Your task in order to complete this Kata is to write a function which formats a duration, given as a number of seconds, in a human-friendly way. The function must accept a non-negative integer. If it is zero, it just returns `"now"`. Otherwise, the dur...
{"functional": "_inputs = [[0], [1], [62], [120], [3600], [3662], [15731080], [132030240], [205851834], [253374061], [242062374], [101956166], [33243586]]\n_outputs = [['now'], ['1 second'], ['1 minute and 2 seconds'], ['2 minutes'], ['1 hour'], ['1 hour, 1 minute and 2 seconds'], ['182 days, 1 hour, 44 minutes and 40 ...
508
440
coding
Solve the programming task below in a Python markdown code block. You need count how many valleys you will pass. Start is always from zero level. Every time you go down below 0 level counts as an entry of a valley, and as you go up to 0 level from valley counts as an exit of a valley. One passed valley is equal one ...
{"functional": "_inputs = [['UFFFD'], ['DFFFD'], ['UFFFU'], ['DFFFU'], ['UFFDDFDUDFUFU'], ['UFFDDFDUDFUFUUFFDDFDUDFUFU'], ['UFFDDFDUDFUFUUFFDDUFFDDUFFDDUDUDUDUDUDUUUUUUUUU'], ['UFFDDFDUDFUFUUFFDDFDUDFUFUUFFDDFDUDFUFUUFFDDFDUDFUFU'], ['UFFDDFDUDFUFUUFFDDFDUDFUFUUFFDDFDUDFUFUUFFDDFDUDFUFUUFFDDFDUDFUFUUFFDDFDUDFUFU']]\n_o...
190
319
coding
Solve the programming task below in a Python markdown code block. There is a data which provides heights (in meter) of mountains. The data is only for ten mountains. Write a program which prints heights of the top three mountains in descending order. Constraints 0 ≤ height of mountain (integer) ≤ 10,000 Input Hei...
{"inputs": ["100\n0\n0\n3561\n000\n98\n9\n15\n1\n297", "100\n-3\n-4\n629\n010\n48\n2\n1\n4\n112", "100\n-4\n-2\n629\n110\n71\n1\n1\n3\n112", "100\n-8\n0\n651\n010\n104\n1\n1\n3\n112", "100\n-8\n0\n552\n011\n104\n1\n1\n3\n112", "100\n-8\n0\n901\n011\n104\n1\n1\n3\n112", "100\n-8\n0\n901\n011\n193\n1\n1\n3\n112", "100\n-...
248
375
coding
Solve the programming task below in a Python markdown code block. The only difference between easy and hard versions is constraints. The BerTV channel every day broadcasts one episode of one of the $k$ TV shows. You know the schedule for the next $n$ days: a sequence of integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le ...
{"inputs": ["4\n5 2 2\n1 2 1 2 1\n9 3 3\n3 3 3 2 2 2 1 1 1\n4 10 4\n10 8 6 4\n16 9 8\n3 1 4 1 5 9 2 6 5 3 5 8 9 7 9 3\n", "4\n5 2 2\n1 2 1 2 1\n9 3 3\n3 3 3 3 2 2 1 1 1\n4 10 4\n10 8 6 4\n16 9 8\n3 1 4 1 5 9 2 6 5 3 5 8 9 7 9 3\n", "4\n5 2 2\n1 2 1 2 1\n9 3 3\n3 3 3 2 2 2 1 1 1\n4 10 4\n10 8 6 4\n16 9 8\n3 1 4 1 5 9 2 ...
744
1,324
coding
Solve the programming task below in a Python markdown code block. Not considering number 1, the integer 153 is the first integer having this property: the sum of the third-power of each of its digits is equal to 153. Take a look: 153 = 1^3 + 5^3 + 3^3 = 1 + 125 + 27 = 153 The next number that experiments this particu...
{"functional": "_inputs = [[100, 2], [1000, 2], [2000, 2], [200, 3], [370, 3], [400, 3], [500, 3], [1000, 3], [1500, 3]]\n_outputs = [[[]], [[]], [[]], [[153]], [[153, 370]], [[153, 370, 371]], [[153, 370, 371, 407]], [[153, 370, 371, 407]], [[153, 370, 371, 407]]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if is...
291
323
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. You are also given an integer key, which is present in nums. For every unique integer target in nums, count the number of times target immediately follows an occurrence of...
{"functional": "def check(candidate):\n assert candidate(nums = [1,100,200,1,100], key = 1) == 100\n assert candidate(nums = [2,2,2,2,3], key = 2) == 2\n\n\ncheck(Solution().mostFrequent)"}
165
78
coding
Solve the programming task below in a Python markdown code block. The north country is conquered by the great shogun-sama (which means king). Recently many beautiful dice which were made by order of the great shogun-sama were given to all citizens of the country. All citizens received the beautiful dice with a tear of ...
{"inputs": ["1 2\n8 8\n0 0\n0 1\n3 3\n1 2 5\n2 8 3\n0 1 2\n0 0\n2 2\n3 3\n1 2 5\n2 8 6\n0 1 2\n0 0\n1 2\n2 2\n1 2\n3 4\n0 0\n0 1\n2 3\n1 2 3\n4 5 6\n0 0\n1 2\n0 0", "1 2\n8 8\n0 0\n0 1\n3 3\n1 2 5\n2 8 3\n0 1 2\n0 0\n2 2\n3 3\n1 2 5\n2 8 3\n0 1 2\n0 0\n1 2\n2 2\n2 2\n3 4\n0 0\n0 1\n2 3\n1 2 3\n4 5 6\n0 0\n1 2\n0 0", "1...
631
1,134
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. There is an undirected connected tree with n nodes labeled from 1 to n and n - 1 edges. You are given the integer n. The parent node of a node with a label v is the node with the label floor (v / 2). The root of the t...
{"functional": "def check(candidate):\n assert candidate(n = 5 , queries = [1,2,5]) == 3\n assert candidate(n = 3, queries = [2,3,3]) == 1\n\n\ncheck(Solution().numberOfNodes)"}
285
61
coding
Solve the programming task below in a Python markdown code block. **Step 1:** Create a function called `encode()` to replace all the lowercase vowels in a given string with numbers according to the following pattern: ``` a -> 1 e -> 2 i -> 3 o -> 4 u -> 5 ``` For example, `encode("hello")` would return `"h2ll4"`. Ther...
{"functional": "_inputs = [['hello'], ['How are you today?'], ['This is an encoding test.']]\n_outputs = [['h2ll4'], ['H4w 1r2 y45 t4d1y?'], ['Th3s 3s 1n 2nc4d3ng t2st.']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, ab...
193
210
coding
Solve the programming task below in a Python markdown code block. You are given an integer $x$ and an array of integers $a_1, a_2, \ldots, a_n$. You have to determine if the number $a_1! + a_2! + \ldots + a_n!$ is divisible by $x!$. Here $k!$ is a factorial of $k$ — the product of all positive integers less than or eq...
{"inputs": ["1 1\n1\n", "1 2\n2\n", "1 5\n3\n", "2 3\n2 1\n", "2 10\n1 1\n", "1 500000\n1\n", "5 2\n2 1 1 1 1\n", "6 4\n3 2 2 2 3 3\n"], "outputs": ["Yes\n", "Yes\n", "No\n", "No\n", "No\n", "No\n", "Yes\n", "Yes\n"]}
606
130
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You have a long flowerbed in which some of the plots are planted, and some are not. However, flowers cannot be planted in adjacent plots. Given an integer array flowerbed containing 0's and 1's, where 0 means empty an...
{"functional": "def check(candidate):\n assert candidate(flowerbed = [1,0,0,0,1], n = 1) == True\n assert candidate(flowerbed = [1,0,0,0,1], n = 2) == False\n\n\ncheck(Solution().canPlaceFlowers)"}
145
73
coding
Solve the programming task below in a Python markdown code block. Vasya plays a computer game with ninjas. At this stage Vasya's ninja should get out of a deep canyon. The canyon consists of two vertical parallel walls, their height is n meters. Let's imagine that we split these walls into 1 meter-long areas and numbe...
{"inputs": ["1 1\n-\nX\n", "1 1\n-\nY\n", "1 20\n-\n-\n", "1 27\n-\n-\n", "2 1\n-X\nX-\n", "2 1\n-X\n-X\n", "2 2\n-X\nX-\n", "1 100000\n-\n-\n"], "outputs": ["YES\n", "YES\n", "YES\n", "YES\n", "YES\n", "NO\n", "YES\n", "YES\n"]}
630
127
coding
Solve the programming task below in a Python markdown code block. Arkady decided to buy roses for his girlfriend. A flower shop has white, orange and red roses, and the total amount of them is n. Arkady thinks that red roses are not good together with white roses, so he won't buy a bouquet containing both red and whit...
{"inputs": ["1 1\n100\nO\n", "1 1\n780\nO\n", "1 1\n100\nO\n", "1 1\n780\nO\n", "1 1\n486\nO\n", "1 1\n107\nO\n", "1 1\n1059\nO\n", "1 1\n6750\nW\n"], "outputs": ["-1\n", "-1\n", "-1\n", "-1\n", "-1\n", "-1\n", "-1\n", "-1\n"]}
574
137
coding
Solve the programming task below in a Python markdown code block. For god's sake, you're boxes with legs! It is literally your only purpose! Walking onto buttons! How can you not do the one thing you were designed for? Oh, that's funny, is it? Oh it's funny? Because we've been at this for twelve hours and you haven't ...
{"inputs": ["1\n3\n2 2 1\n", "1\n3\n2 2 0\n", "1\n3\n4 2 0\n", "1\n3\n3 2 0\n", "1\n3\n4 3 0\n", "1\n3\n0 2 0\n", "1\n3\n0 2 1\n", "1\n3\n2 2 2\n"], "outputs": ["YES\n", "YES\n", "NO\n", "NO\n", "NO\n", "YES\n", "YES\n", "YES\n"]}
598
134