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. Let's call an integer array $a_1, a_2, \dots, a_n$ good if $a_i \neq i$ for each $i$. Let $F(a)$ be the number of pairs $(i, j)$ ($1 \le i < j \le n$) such that $a_i + a_j = i + j$. Let's say that an array $a_1, a_2, \dots, a_n$ is excellent if: $a$ i...
{"inputs": ["1\n122520 -643096130 7376743\n", "1\n27154 -643096130 65152507\n", "1\n200000 -926527577 99824348\n", "1\n167208 -356488738 91840074\n", "1\n45288 -643096130 139364119\n", "1\n167208 -356488738 34429628\n", "1\n122520 -643096130 24457044\n", "1\n27154 -643096130 139364119\n"], "outputs": ["862272722\n", "7...
481
339
coding
Solve the programming task below in a Python markdown code block. You have $n$ stacks of blocks. The $i$-th stack contains $h_i$ blocks and it's height is the number of blocks in it. In one move you can take a block from the $i$-th stack (if there is at least one block) and put it to the $i + 1$-th stack. Can you make ...
{"inputs": ["1\n5\n1000000000 1000000000 1000000000 1000000000 0\n", "1\n5\n1000000000 1000000000 1000000000 1000000000 0\n", "1\n5\n1000000000 1000000000 1000000000 1000000000 1\n", "1\n5\n1000000000 1000000010 1000000000 1000000000 1\n", "1\n5\n1000000000 1000000010 1000001000 1000000000 1\n", "1\n5\n1000000000 10000...
581
454
coding
Solve the programming task below in a Python markdown code block. Theatre Square in the capital city of Berland has a rectangular shape with the size n × m meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size a × a. Wha...
{"inputs": ["1 1 3\n", "2 1 2\n", "2 2 1\n", "2 3 4\n", "2 1 1\n", "1 1 1\n", "1 2 1\n", "1 1 2\n"], "outputs": ["1\n", "1\n", "4\n", "1\n", "2\n", "1\n", "2\n", "1\n"]}
185
102
coding
Solve the programming task below in a Python markdown code block. You can print your name on a billboard ad. Find out how much it will cost you. Each letter has a default price of £30, but that can be different if you are given 2 parameters instead of 1. You can not use multiplier "*" operator. If your name would be ...
{"functional": "_inputs = [['Jeong-Ho Aristotelis'], ['Abishai Charalampos'], ['Idwal Augustin'], ['Hadufuns John', 20], ['Zoroaster Donnchadh'], ['Claude Miljenko'], ['Werner Vigi', 15], ['Anani Fridumar'], ['Paolo Oli'], ['Hjalmar Liupold', 40], ['Simon Eadwulf']]\n_outputs = [[600], [570], [420], [260], [570], [450]...
134
294
coding
Solve the programming task below in a Python markdown code block. A string is a palindrome if it reads the same from the left to the right and from the right to the left. For example, the strings "kek", "abacaba", "r" and "papicipap" are palindromes, while the strings "abb" and "iq" are not. A substring $s[l \ldots r]...
{"inputs": ["a\n", "l\n", "v\n", "l\n", "a\n", "v\n", "k\n", "b\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]}
501
70
coding
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin Chinese , Russian and Vietnamese as well. Sergey recently learned about country codes - two letter strings, denoting countries. For example, BY stands for Belarus and IN stands for India. Mesmerized by this new disc...
{"inputs": ["2\nINBY\nBYBY"], "outputs": ["3\n2"]}
320
20
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an array nums​​​ and an integer k​​​​​. The XOR of a segment [left, right] where left <= right is the XOR of all the elements with indices between left and right, inclusive: nums[left] XOR nums[left+1] X...
{"functional": "def check(candidate):\n assert candidate(nums = [1,2,0,3,0], k = 1) == 3\n assert candidate(nums = [3,4,5,2,1,7,3,4,7], k = 3) == 3\n assert candidate(nums = [1,2,4,1,2,5,1,2,6], k = 3) == 3\n\n\ncheck(Solution().minChanges)"}
142
110
coding
Solve the programming task below in a Python markdown code block. We have a sequence of N integers: A_1, A_2, \cdots, A_N. You can perform the following operation between 0 and K times (inclusive): - Choose two integers i and j such that i \neq j, each between 1 and N (inclusive). Add 1 to A_i and -1 to A_j, possibly ...
{"inputs": ["2 1\n3 5", "2 3\n2 1", "2 2\n3 5", "2 2\n3 1", "2 2\n6 1", "2 3\n6 1", "2 4\n6 1", "2 6\n2 1"], "outputs": ["4\n", "3\n", "4\n", "4\n", "7\n", "7\n", "7\n", "3\n"]}
324
110
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an integer total indicating the amount of money you have. You are also given two integers cost1 and cost2 indicating the price of a pen and pencil respectively. You can spend part or all of your money to...
{"functional": "def check(candidate):\n assert candidate(total = 20, cost1 = 10, cost2 = 5) == 9\n assert candidate(total = 5, cost1 = 10, cost2 = 10) == 1\n\n\ncheck(Solution().waysToBuyPensPencils)"}
139
77
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 players, where players[i] represents the ability of the ith player. You are also given a 0-indexed integer array trainers, where trainers[j] represents the training capacity of ...
{"functional": "def check(candidate):\n assert candidate(players = [4,7,9], trainers = [8,2,5,8]) == 2\n assert candidate(players = [1,1,1], trainers = [10]) == 1\n\n\ncheck(Solution().matchPlayersAndTrainers)"}
178
71
coding
Solve the programming task below in a Python markdown code block. There are N empty boxes arranged in a row from left to right. The integer i is written on the i-th box from the left (1 \leq i \leq N). For each of these boxes, Snuke can choose either to put a ball in it or to put nothing in it. We say a set of choices ...
{"inputs": ["1\n0\n", "1\n1\n", "3\n1 0 1", "3\n1 1 0", "3\n0 0 0", "3\n0 0 0", "3\n1 1 0", "3\n1 0 1"], "outputs": ["0\n", "1\n1\n", "1\n3\n", "1\n2\n", "0\n\n", "0\n\n", "1\n2\n", "1\n3\n"]}
474
116
coding
Solve the programming task below in a Python markdown code block. You have been recruited by an unknown organization for your cipher encrypting/decrypting skills. Being new to the organization they decide to test your skills. Your first test is to write an algorithm that encrypts the given string in the following s...
{"functional": "_inputs = [['amz'], ['welcome to the organization'], ['hello'], ['my name is'], ['goodbye']]\n_outputs = [['man'], ['qibkyai ty tfi yvgmzenmteyz'], ['fibby'], ['ao zmai eu'], ['gyyjloi']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return ma...
259
206
coding
Solve the programming task below in a Python markdown code block. Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for ...
{"inputs": ["1\n0\n", "1\n1\n", "1\n1\n", "1\n0\n", "2\n01\n", "2\n10\n", "2\n11\n", "2\n00\n"], "outputs": ["1\n", "1\n", "1", "1", "2\n", "2\n", "2\n", "2\n"]}
510
88
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an integer n (in base 10) and a base k, return the sum of the digits of n after converting n from base 10 to base k. After converting, each digit should be interpreted as a base 10 number, and the sum should be ...
{"functional": "def check(candidate):\n assert candidate(n = 34, k = 6) == 9\n assert candidate(n = 10, k = 10) == 1\n\n\ncheck(Solution().sumBase)"}
115
56
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an integer array nums. You should move each element of nums into one of the two arrays A and B such that A and B are non-empty, and average(A) == average(B). Return true if it is possible to achieve that...
{"functional": "def check(candidate):\n assert candidate(nums = [1,2,3,4,5,6,7,8]) == True\n assert candidate(nums = [3,1]) == False\n\n\ncheck(Solution().splitArraySameAverage)"}
129
59
coding
Solve the programming task below in a Python markdown code block. Given two arrays of integers, find which elements in the second array are missing from the first array. Example $arr=[7,2,5,3,5,3]$ $brr=[7,2,5,4,6,3,5,3]$ The $brr$ array is the orginal list. The numbers missing are $[4,6]$. Notes If a numb...
{"inputs": ["10\n203 204 205 206 207 208 203 204 205 206\n13\n203 204 204 205 206 207 205 208 203 206 205 206 204\n"], "outputs": ["204 205 206\n"]}
594
120
coding
Solve the programming task below in a Python markdown code block. Roma works in a company that sells TVs. Now he has to prepare a report for the last year. Roma has got a list of the company's incomes. The list is a sequence that consists of n integers. The total income of the company is the sum of all integers in seq...
{"inputs": ["1 1\n0\n", "1 2\n1\n", "1 1\n0\n", "1 2\n1\n", "1 2\n0\n", "1 0\n1\n", "1 2\n-1\n", "1 2\n-1\n"], "outputs": ["0\n", "1\n", "0\n", "1\n", "0\n", "1\n", "-1\n", "-1\n"]}
380
104
coding
Solve the programming task below in a Python markdown code block. There are $n$ robbers at coordinates $(a_1, b_1)$, $(a_2, b_2)$, ..., $(a_n, b_n)$ and $m$ searchlight at coordinates $(c_1, d_1)$, $(c_2, d_2)$, ..., $(c_m, d_m)$. In one move you can move each robber to the right (increase $a_i$ of each robber by one...
{"inputs": ["1 1\n0 0\n2 3\n", "1 1\n0 0\n0 0\n", "1 1\n0 0\n0 0\n", "1 1\n0 0\n2 3\n", "1 2\n0 0\n0 0\n0 0\n", "2 1\n0 0\n0 0\n0 0\n", "2 1\n0 0\n0 0\n0 0\n", "1 2\n1 0\n0 0\n0 0\n"], "outputs": ["3\n", "1\n", "1\n", "3\n", "1\n", "1\n", "1\n", "0\n"]}
700
166
coding
Solve the programming task below in a Python markdown code block. You are given a string s consisting of |s| small english letters. In one move you can replace any character of this string to the next character in alphabetical order (a will be replaced with b, s will be replaced with t, etc.). You cannot replace lette...
{"inputs": ["a\n", "a\n", "b\n", "thereisnoanswer\n", "thereisnoansweq\n", "thereisnoanswer\n", "aacceeggiikkmmooqqssuuwwyy\n", "abcdefghijklmnopqrstuvwxxx\n"], "outputs": ["-1\n", "-1\n", "-1\n", "-1\n", "-1\n", "-1\n", "abcdefghijklmnopqrstuvwxyz\n", "abcdefghijklmnopqrstuvwxyz\n"]}
264
96
coding
Solve the programming task below in a Python markdown code block. The kingdom of Lazyland is the home to $n$ idlers. These idlers are incredibly lazy and create many problems to their ruler, the mighty King of Lazyland. Today $k$ important jobs for the kingdom ($k \le n$) should be performed. Every job should be done...
{"inputs": ["2 1\n1 1\n7 13\n", "2 2\n2 2\n7 13\n", "2 1\n1 1\n7 13\n", "2 2\n2 2\n7 13\n", "2 1\n1 1\n6 13\n", "2 2\n2 2\n7 12\n", "2 2\n1 2\n7 12\n", "2 1\n1 1\n6 11\n"], "outputs": ["0\n", "7\n", "0", "7", "0\n", "7\n", "0\n", "0\n"]}
523
156
coding
Solve the programming task below in a Python markdown code block. You are given a string $s$ of 0's and 1's. You are allowed to perform the following operation: choose a non-empty contiguous substring of $s$ that contains an equal number of 0's and 1's; flip all characters in the substring, that is, replace all 0's w...
{"inputs": ["2\n0\n1\n", "2\n0\n1\n", "4\n1\n10\n1\n11\n", "4\n1\n10\n01\n11\n", "4\n00\n10\n01\n11\n", "4\n00\n10\n01\n11\n", "3\n100101\n1100011\n10101010\n", "3\n100101\n1100011\n10001010\n"], "outputs": ["0\n1\n", "0\n1\n", "1\n10\n1\n11\n", "1\n10\n01\n11\n", "00\n10\n01\n11\n", "00\n10\n01\n11\n", "010110\n011011...
477
256
coding
Solve the programming task below in a Python markdown code block. Consider a rooted binary tree with $n$ vertices containing numbers. Each vertex of the tree either has two sons (left son and right son), or no sons. We will call such a tree heap, if and only if for all vertices (except the root), the number assigned th...
{"inputs": ["5\n2 1 1 1 1\n"], "outputs": ["2\n"]}
646
24
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a string s that consists of the digits '1' to '9' and two integers k and minLength. A partition of s is called beautiful if: s is partitioned into k non-intersecting substrings. Each substring has a len...
{"functional": "def check(candidate):\n assert candidate(s = \"23542185131\", k = 3, minLength = 2) == 3\n assert candidate(s = \"23542185131\", k = 3, minLength = 3) == 1\n assert candidate(s = \"3312958\", k = 3, minLength = 1) == 1\n\n\ncheck(Solution().beautifulPartitions)"}
196
112
coding
Solve the programming task below in a Python markdown code block. In AtCoder, a person who has participated in a contest receives a color, which corresponds to the person's rating as follows: - Rating 1-399 : gray - Rating 400-799 : brown - Rating 800-1199 : green - Rating 1200-1599 : cyan - Rating 1600-1999 : b...
{"inputs": ["4\n2100 3230 248 21", "4\n2100 3230 248 26", "4\n2100 3992 248 26", "4\n2100 4691 248 409", "4\n2100 3230 248 409", "4\n2100 2500 248 2612", "4\n2100 2500 248 2218", "4\n2100 4691 248 2218"], "outputs": ["2 3\n", "2 3\n", "2 3\n", "3 4\n", "3 4\n", "3 3\n", "3 3\n", "2 3\n"]}
383
222
coding
Solve the programming task below in a Python markdown code block. Mary wrote a recipe book and is about to publish it, but because of a new European law, she needs to update and include all measures in grams. Given all the measures in tablespoon (`tbsp`) and in teaspoon (`tsp`), considering `1 tbsp = 15g` and `1 tsp =...
{"functional": "_inputs = [['2 tbsp of butter'], ['Add to the mixing bowl and coat well with 1 tbsp of olive oil & 1/2 tbsp of dried dill'], ['1/2 tsp of baking powder'], ['In another bowl, add 2 tsp of vanilla extract, 3 tsp of baking soda and 1/2 tsp of salt'], ['10 tbsp of cocoa powder'], ['1/8 tbsp of baking soda']...
258
402
coding
Solve the programming task below in a Python markdown code block. The 9-th grade student Gabriel noticed a caterpillar on a tree when walking around in a forest after the classes. The caterpillar was on the height h_1 cm from the ground. On the height h_2 cm (h_2 > h_1) on the same tree hung an apple and the caterpilla...
{"inputs": ["1 9\n1 1\n", "1 2\n4 3\n", "1 9\n1 2\n", "1 2\n4 3\n", "1 9\n1 1\n", "1 9\n1 2\n", "1 5\n1 1\n", "1 2\n2 2\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]}
507
118
coding
Solve the programming task below in a Python markdown code block. ```if:python Create a function `args_count`, that returns the count of passed arguments ``` ```if:kotlin Create a function `argsCount`, that returns the count of passed arguments ``` ```if:ruby Create a method `args_count`, that returns the count of pass...
{"functional": "_inputs = [[100], [100, 2, 3]]\n_outputs = [[1], [3]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) != len(b): return False\n r...
165
170
coding
Solve the programming task below in a Python markdown code block. Find the number with the most digits. If two numbers in the argument array have the same number of digits, return the first one in the array. Also feel free to reuse/extend the following starter code: ```python def find_longest(arr): ```
{"functional": "_inputs = [[[1, 10, 100]], [[9000, 8, 800]], [[8, 900, 500]], [[3, 40000, 100]], [[1, 200, 100000]]]\n_outputs = [[100], [9000], [900], [40000], [100000]]\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...
65
250
coding
Solve the programming task below in a Python markdown code block. Let A, B, C, D, E be sets of integers and let U is a universal set that includes all sets under consideration. All elements in any set are different (no repetitions). u - union of two sets, AuB = {x ∈ U : x ∈ A or x ∈ B} is the set of all elements which...
{"inputs": ["A 3\n1 3 -1\nB 4\n3 1 5 7\nD 1\n5\nR 0\ncAiBdD\nC 3\n1 2 3\nA 4\n2 9 8 3\nB 3\n2 4 8\nR 0\n(As(AiB))uC", "A 3\n1 2 -1\nB 4\n3 1 5 7\nD 1\n5\nR 0\ncAiBdD\nC 3\n1 2 3\nA 4\n2 9 8 3\nB 3\n2 4 8\nR 0\n(As(AiB))uC", "A 3\n2 3 -1\nB 4\n3 1 5 7\nD 1\n5\nR 0\ncAiBdD\nC 3\n1 2 3\nA 4\n2 9 8 3\nB 3\n2 4 8\nR 0\n(As(...
594
789
coding
Solve the programming task below in a Python markdown code block. [0, 0] [0, 1] [1, 1] [0, 2] [1, 2] [2, 2] [0, 3] [1, 3] [2, 3] [3, 3] [0, 4] [1, 4] [2, 4] [3, 4] [4, 4] [0, 5] [1, 5] [2, 5] [3, 5] [4, 5] [5, 5] [0, 6] [1, 6] [2, 6] [3, 6] [4, 6] [5, 6] [6, 6] Consider the standard set of 28 wes...
{"inputs": ["6\n13 23 20 24 15 25\n10\n00 01 11 02 12 22 03 13 23 33", "6\n13 23 20 24 11 25\n10\n00 01 11 02 12 22 03 13 23 33", "6\n13 23 20 24 11 25\n10\n00 01 11 02 12 22 03 13 16 33", "6\n16 23 16 16 15 25\n10\n00 01 11 02 12 22 03 13 13 33", "6\n13 23 14 24 15 25\n10\n00 01 11 02 12 22 03 13 36 33", "6\n12 23 14 ...
580
486
coding
Solve the programming task below in a Python markdown code block. In this Kata, you will be given a ```number```, two indexes (```index1``` and ```index2```) and a ```digit``` to look for. Your task will be to check if the ```digit``` exists in the ```number```, within the ```indexes``` given. Be careful, the ```index...
{"functional": "_inputs = [[1234567, 1, 0, 1], [1234567, 0, 1, 2], [67845123654, 4, 2, 4], [6668844536485, 0, 0, 6], [9999999999, 2, 5, 1]]\n_outputs = [[True], [True], [True], [True], [False]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose...
432
266
coding
Solve the programming task below in a Python markdown code block. Two tortoises named ***A*** and ***B*** must run a race. ***A*** starts with an average speed of ```720 feet per hour```. Young ***B*** knows she runs faster than ***A***, and furthermore has not finished her cabbage. When she starts, at last, she can s...
{"functional": "_inputs = [[720, 850, 70], [80, 91, 37], [80, 100, 40], [720, 850, 37], [720, 850, 370], [120, 850, 37], [820, 850, 550], [820, 81, 550]]\n_outputs = [[[0, 32, 18]], [[3, 21, 49]], [[2, 0, 0]], [[0, 17, 4]], [[2, 50, 46]], [[0, 3, 2]], [[18, 20, 0]], [None]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n...
509
334
coding
Solve the programming task below in a Python markdown code block. Tavak and Seyyed are good friends. Seyyed is very funny and he told Tavak to solve the following problem instead of longest-path. You are given l and r. For all integers from l to r, inclusive, we wrote down all of their integer divisors except 1. Find ...
{"inputs": ["3 6\n", "6 8\n", "5 5\n", "3 3\n", "2 2\n", "7 7\n", "3 8\n", "4 8\n"], "outputs": ["2\n", "2\n", "5\n", "3\n", "2\n", "7\n", "2\n", "2\n"]}
276
86
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You have n boxes labeled from 0 to n - 1. You are given four arrays: status, candies, keys, and containedBoxes where: status[i] is 1 if the ith box is open and 0 if the ith box is closed, candies[i] is the number of ...
{"functional": "def check(candidate):\n assert candidate(status = [1,0,1,0], candies = [7,5,4,100], keys = [[],[],[1],[]], containedBoxes = [[1,2],[3],[],[]], initialBoxes = [0]) == 16\n assert candidate(status = [1,0,0,0,0,0], candies = [1,1,1,1,1,1], keys = [[1,2,3,4,5],[],[],[],[],[]], containedBoxes = [[1,2,3...
247
299
coding
Solve the programming task below in a Python markdown code block. In the pet store on sale there are: $a$ packs of dog food; $b$ packs of cat food; $c$ packs of universal food (such food is suitable for both dogs and cats). Polycarp has $x$ dogs and $y$ cats. Is it possible that he will be able to buy food for all ...
{"inputs": ["1\n0 0 0 0 1\n", "1\n114514 1 1 1 1\n", "1\n114515 1 1 114515 2\n", "1\n114515 0 0 114514 0\n", "2\n2 3 5 4 4\n2 3 5 4 4\n", "2\n2 3 4 4 4\n2 3 4 4 4\n", "1\n55555 55555 55555 55555 55555\n", "1\n114514 114514 114514 114514 114514\n"], "outputs": ["NO\n", "YES\n", "YES\n", "YES\n", "YES\nYES\n", "YES\nYES\...
419
244
coding
Solve the programming task below in a Python markdown code block. Reverse and invert all integer values in a given list. Python: reverse_invert([1,12,'a',3.4,87,99.9,-42,50,5.6]) = [-1,-21,-78,24,-5] Ignore all other types than integer. Also feel free to reuse/extend the following starter code: ```python de...
{"functional": "_inputs = [[[1, 2, 3, 4, 5]], [[-10]], [[-9, -18, 99]], [[1, 12, 'a', 3.4, 87, 99.9, -42, 50, 5.6]], [[]]]\n_outputs = [[[-1, -2, -3, -4, -5]], [[1]], [[9, 81, -99]], [[-1, -21, -78, 24, -5]], [[]]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n ...
106
272
coding
Solve the programming task below in a Python markdown code block. Xenia lives in a city that has n houses built along the main ringroad. The ringroad houses are numbered 1 through n in the clockwise order. The ringroad traffic is one way and also is clockwise. Xenia has recently moved into the ringroad house number 1....
{"inputs": ["2 1\n1\n", "2 1\n1\n", "2 2\n1 1\n", "2 2\n1 2\n", "2 2\n1 2\n", "2 2\n1 2\n", "2 2\n1 1\n", "2 2\n2 2\n"], "outputs": ["0\n", "0\n", "0\n", "1\n", "1\n", "1\n", "0\n", "1\n"]}
383
114
coding
Solve the programming task below in a Python markdown code block. New Year is coming! Vasya has prepared a New Year's verse and wants to recite it in front of Santa Claus. Vasya's verse contains $n$ parts. It takes $a_i$ seconds to recite the $i$-th part. Vasya can't change the order of parts in the verse: firstly he ...
{"inputs": ["1\n1 9\n2\n", "1\n1 9\n1\n", "1\n1 9\n0\n", "1\n1 10\n4\n", "1\n1 10\n4\n", "1\n1 10\n5\n", "1\n1 10\n2\n", "1\n5 9\n1 8 10 1 10\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "3\n"]}
645
132
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. For each index i (1 <= i <= nums.length - 2) the beauty of nums[i] equals: 2, if nums[j] < nums[i] < nums[k], for all 0 <= j < i and for all i < k <= nums.length - 1. 1, ...
{"functional": "def check(candidate):\n assert candidate(nums = [1,2,3]) == 2\n assert candidate(nums = [2,4,6,4]) == 1\n assert candidate(nums = [3,2,1]) == 0\n\n\ncheck(Solution().sumOfBeauties)"}
181
72
coding
Solve the programming task below in a Python markdown code block. >When no more interesting kata can be resolved, I just choose to create the new kata, to solve their own, to enjoy the process --myjinxin2015 said # Description: John learns to play poker with his uncle. His uncle told him: Poker to be in accordance...
{"functional": "_inputs = [['D6H2S3D5SJCQSKC7D2C5H5H10SA', 'S2S3S5HJHQHKC8C9C10D4D5D6D7'], ['D6H2S3D5SJCQSKC7D2C5H5H10SA', 'C8C9C10D4D5D6D7S2S3S5HJHQHK']]\n_outputs = [['S3SJSKSAH2H5H10C5C7CQD2D5D6'], ['C5C7CQD2D5D6S3SJSKSAH2H5H10']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance...
382
309
coding
Solve the programming task below in a Python markdown code block. # Task In the Land Of Chess, bishops don't really like each other. In fact, when two bishops happen to stand on the same diagonal, they immediately rush towards the opposite ends of that same diagonal. Given the initial positions (in chess notation) o...
{"functional": "_inputs = [['d7', 'f5'], ['d8', 'b5'], ['a1', 'h8'], ['g3', 'e1'], ['b4', 'e7']]\n_outputs = [[['c8', 'h3']], [['b5', 'd8']], [['a1', 'h8']], [['e1', 'h4']], [['a3', 'f8']]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, ...
368
232
coding
Solve the programming task below in a Python markdown code block. The Jones Trucking Company tracks the location of each of its trucks on a grid similar to an (x, y) plane. The home office is at the location (0, 0). Read the coordinates of truck A and the coordinates of truck B and determine which is closer to the offi...
{"inputs": ["4\n3 -2 -5 -3\n0 6 1 2\n-7 8 4 -1\n3 3 -2 2"], "outputs": ["A IS CLOSER\nB IS CLOSER\nB IS CLOSER\nB IS CLOSER"]}
298
67
coding
Solve the programming task below in a Python markdown code block. You are given an array $a_1, a_2, \ldots, a_n$ of positive integers. A good pair is a pair of indices $(i, j)$ with $1 \leq i, j \leq n$ such that, for all $1 \leq k \leq n$, the following equality holds: $$ |a_i - a_k| + |a_k - a_j| = |a_i - a_j|, $$ w...
{"inputs": ["3\n3\n5 2 7\n5\n1 4 2 2 3\n1\n2\n"], "outputs": ["2 3\n1 2\n1 1\n"]}
636
48
coding
Solve the programming task below in a Python markdown code block. You are given a permutation $p_1, p_2, \ldots, p_n$. In one move you can swap two adjacent values. You want to perform a minimum number of moves, such that in the end there will exist a subsegment $1,2,\ldots, k$, in other words in the end there should...
{"inputs": ["1\n1\n", "1\n1\n", "3\n1 2 3\n", "3\n2 1 3\n", "3\n2 3 1\n", "3\n3 1 2\n", "3\n3 2 1\n", "3\n1 3 2\n"], "outputs": ["0 \n", "0 ", "0 0 0 \n", "0 1 1\n", "0 2 2\n", "0 0 2\n", "0 1 3\n", "0 1 1\n"]}
377
135
coding
Solve the programming task below in a Python markdown code block. # Challenge : Write a function that takes a single argument `n` that is a string representation of a simple mathematical expression and evaluates it as a floating point value. # Commands : - positive or negative decimal numbers - `+, -, *, /, ( / )....
{"functional": "_inputs = [['2*3*4*5+99']]\n_outputs = [[219]]\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 a...
415
164
coding
Solve the programming task below in a Python markdown code block. In a building where Polycarp lives there are equal number of flats on each floor. Unfortunately, Polycarp don't remember how many flats are on each floor, but he remembers that the flats are numbered from 1 from lower to upper floors. That is, the first ...
{"inputs": ["1 0\n", "2 0\n", "3 0\n", "3 0\n", "6 0\n", "9 0\n", "2 0\n", "2 0\n"], "outputs": ["1\n", "-1\n", "-1\n", "-1\n", "-1\n", "-1\n", "-1\n", "-1\n"]}
571
86
coding
Solve the programming task below in a Python markdown code block. You are given a sequence $A_1, A_2, \ldots, A_N$. Calculate the number of ways to remove a non-empty contiguous subsequence from it such that the resulting sequence is non-empty and strictly increasing. -----Input----- - The first line of the input cont...
{"inputs": ["2\n3\n1 1 2\n4\n2 4 3 5"], "outputs": ["4\n7"]}
277
32
coding
Solve the programming task below in a Python markdown code block. Given a string of words and numbers. Extract the expression including: 1. the operator: either addition or subtraction 2. the two numbers that we are operating on Return the result of the calculation. Example: "Panda has 48 apples and loses 4" return...
{"functional": "_inputs = [['Panda has 48 apples and loses 4'], ['Jerry has 34 apples and gains 6'], ['Tom has 20 apples and gains 15'], ['Fred has 110 bananas and loses 50'], ['Pippi has 20 tunas and gains 0']]\n_outputs = [[44], [40], [35], [60], [20]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a,...
153
234
coding
Solve the programming task below in a Python markdown code block. Read problems statements in Russian here The Head Chef is studying the motivation and satisfaction level of his chefs . The motivation and satisfaction of a Chef can be represented as an integer . The Head Chef wants to know the N th smallest sum of o...
{"inputs": ["1\n3 1\n1 2 3\n4 5 6\n4", "1\n3 1\n1 4 3\n4 5 6\n4", "1\n6 1\n1 4 3\n4 5 6\n1", "1\n6 1\n0 4 3\n4 5 6\n1", "1\n3 1\n1 2 1\n4 5 6\n4", "1\n6 1\n0 8 6\n2 5 6\n1", "1\n8 1\n1 1 3\n4 6 2\n0", "1\n1 1\n2 8 2\n4 2 4\n0"], "outputs": ["7", "7\n", "5\n", "4\n", "6\n", "2\n", "9\n", "12\n"]}
640
206
coding
Solve the programming task below in a Python markdown code block. Nitin and Sobhagya were playing a game with coins. If Sobhagya has more coins then he is *winning*, otherwise Nitin is winning. Note that this means if both Nitin and Sobhagya have the same number of coins, then Nitin is winning. Initially Nitin has A c...
{"inputs": ["3\n2 3 4 5\n3 3 3 3\n2 3 1 2\n"], "outputs": ["S\nN\nS\n"]}
563
42
coding
Solve the programming task below in a Python markdown code block. The year 2015 is almost over. Limak is a little polar bear. He has recently learnt about the binary system. He noticed that the passing year has exactly one zero in its representation in the binary system — 2015_10 = 11111011111_2. Note that he doesn't ...
{"inputs": ["1 1\n", "1 2\n", "1 3\n", "1 4\n", "1 5\n", "1 6\n", "1 7\n", "2 2\n"], "outputs": ["0\n", "1\n", "1\n", "1\n", "2\n", "3\n", "3\n", "1\n"]}
417
86
coding
Solve the programming task below in a Python markdown code block. Well met with Fibonacci bigger brother, AKA Tribonacci. As the name may already reveal, it works basically like a Fibonacci, but summing the last 3 (instead of 2) numbers of the sequence to generate the next. And, worse part of it, regrettably I won't g...
{"functional": "_inputs = [[[1, 1, 1], 10], [[0, 0, 1], 10], [[0, 1, 1], 10], [[1, 0, 0], 10], [[0, 0, 0], 10], [[1, 2, 3], 10], [[3, 2, 1], 10], [[1, 1, 1], 1], [[300, 200, 100], 0], [[0.5, 0.5, 0.5], 30]]\n_outputs = [[[1, 1, 1, 3, 5, 9, 17, 31, 57, 105]], [[0, 0, 1, 1, 2, 4, 7, 13, 24, 44]], [[0, 1, 1, 2, 4, 7, 13, ...
451
766
coding
Solve the programming task below in a Python markdown code block. Toastman came up with a very easy task. He gives it to Appleman, but Appleman doesn't know how to solve it. Can you help him? Given a n × n checkerboard. Each cell of the board has either character 'x', or character 'o'. Is it true that each cell of the...
{"inputs": ["1\no\n", "1\no\n", "1\nn\n", "1\np\n", "1\nm\n", "1\nl\n", "1\nk\n", "1\nq\n"], "outputs": ["YES\n", "YES\n", "YES\n", "YES\n", "YES\n", "YES\n", "YES\n", "YES\n"]}
215
86
coding
Solve the programming task below in a Python markdown code block. This is the hard version of this problem. The difference between easy and hard versions is only the constraints on $a_i$ and on $n$. You can make hacks only if both versions of the problem are solved. Burenka is the crown princess of Buryatia, and soon ...
{"inputs": ["7\n4\n5 5 5 5\n3\n1 3 2\n2\n0 0\n3\n2 5 7\n6\n1 2 3 3 2 1\n10\n27 27 34 32 2 31 23 56 52 4\n5\n1822 1799 57 23 55\n", "1\n30\n1 2 4 8 16 32 64 128 256 512 1024 2048 4096 8192 16384 32768 65536 131072 262144 524288 1048576 2097152 4194304 8388608 16777216 33554432 67108864 134217728 268435456 268435456\n"],...
734
313
coding
Solve the programming task below in a Python markdown code block. Little Susie listens to fairy tales before bed every day. Today's fairy tale was about wood cutters and the little girl immediately started imagining the choppers cutting wood. She imagined the situation that is described below. There are n trees locate...
{"inputs": ["4\n10 4\n15 1\n19 3\n20 1\n", "4\n10 4\n15 1\n19 3\n20 1\n", "1\n1000000000 1000000000\n", "1\n1000000000 1000000000\n", "1\n1010000000 1000000000\n", "1\n1010000000 1000010000\n", "1\n1110000000 1000010000\n", "1\n1110000000 1000000000\n"], "outputs": ["4\n", "4\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n...
540
242
coding
Solve the programming task below in a Python markdown code block. Everyone loves a freebie. Especially students. It is well-known that if in the night before exam a student opens window, opens the student's record-book and shouts loudly three times "Fly, freebie, fly!" — then flown freebie helps him to pass the upcomi...
{"inputs": ["1\n1\n1\n", "1\n1\n1\n", "1\n2\n1\n", "1\n2\n2\n", "1\n3\n2\n", "1\n1\n2\n", "2\n1 1\n1\n", "2\n1 1\n2\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "2\n", "2\n"]}
354
106
coding
Solve the programming task below in a Python markdown code block. Read problems statements in [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well. No play and eating all day makes your belly fat. This happened to Chef during the lockdown. His weight before the lockdown was $w_{1}$ kg (measured on the mo...
{"inputs": ["5\n1 2 1 2 2\n2 4 1 2 2\n4 8 1 2 2\n5 8 1 2 2\n1 100 1 2 2"], "outputs": ["0\n1\n1\n1\n0"]}
713
72
coding
Solve the programming task below in a Python markdown code block. Little Petya has a birthday soon. Due this wonderful event, Petya's friends decided to give him sweets. The total number of Petya's friends equals to n. Let us remind you the definition of the greatest common divisor: GCD(a1, ..., ak) = d, where d repre...
{"inputs": ["8\n", "2\n", "3\n", "7\n", "9\n", "5\n", "4\n", "6\n"], "outputs": ["4849845\n3233230\n1939938\n1385670\n881790\n746130\n570570\n510510\n", "-1\n", "15\n10\n6\n", "255255\n170170\n102102\n72930\n46410\n39270\n30030\n", "111546435\n74364290\n44618574\n31870410\n20281170\n17160990\n13123110\n11741730\n969969...
504
316
coding
Solve the programming task below in a Python markdown code block. Given a number, return a string with dash``` '-' ```marks before and after each odd integer, but do not begin or end the string with a dash mark. Ex: Also feel free to reuse/extend the following starter code: ```python def dashatize(num): ```
{"functional": "_inputs = [[274], [5311], [86320], [974302]]\n_outputs = [['2-7-4'], ['5-3-1-1'], ['86-3-20'], ['9-7-4-3-02']]\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...
71
213
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. A string s is called good if there are no two different characters in s that have the same frequency. Given a string s, return the minimum number of characters you need to delete to make s good. The frequency of a cha...
{"functional": "def check(candidate):\n assert candidate(s = \"aab\") == 0\n assert candidate(s = \"aaabbbcc\") == 2\n assert candidate(s = \"ceabaacb\") == 2\n\n\ncheck(Solution().minDeletions)"}
139
62
coding
Solve the programming task below in a Python markdown code block. For a given weighted undirected graph G(V, E), find the distance of the shortest route that meets the following criteria: * It is a closed cycle where it ends at the same point it starts. * The route must go through every edge at least once. Constraint...
{"inputs": ["2 3\n0 1 1\n0 1 2\n0 1 3", "4 4\n0 1 1\n1 2 2\n1 3 3\n2 3 4", "6 4\n0 1 0\n1 2 2\n1 3 3\n2 3 4", "6 4\n0 1 0\n1 2 2\n1 3 6\n2 3 4", "6 4\n0 2 0\n1 2 3\n1 3 6\n2 3 4", "6 4\n0 2 0\n1 0 3\n1 4 6\n2 3 4", "6 4\n0 2 0\n1 0 3\n1 1 6\n2 5 4", "6 3\n0 2 0\n1 0 2\n1 1 6\n2 5 4"], "outputs": ["7", "11\n", "9\n", "1...
363
269
coding
Solve the programming task below in a Python markdown code block. Starting with a 1-indexed array of zeros and a list of operations, for each operation add a value to each the array element between two given indices, inclusive. Once all operations have been performed, return the maximum value in the array. Example ...
{"inputs": ["5 3\n1 2 100\n2 5 100\n3 4 100\n"], "outputs": ["200\n"]}
670
42
coding
Solve the programming task below in a Python markdown code block. You are given a binary string S of length N. You have to perform the following operation exactly once: Select an index i (1 ≤ i ≤ N) and delete S_{i} from S. The remaining parts of S are concatenated in the same order. How many distinct binary strings...
{"inputs": ["3\n3\n100\n4\n1111\n5\n10110"], "outputs": ["2\n1\n4\n"]}
397
38
coding
Solve the programming task below in a Python markdown code block. Bizon the Champion isn't just attentive, he also is very hardworking. Bizon the Champion decided to paint his old fence his favorite color, orange. The fence is represented as n vertical planks, put in a row. Adjacent planks have no gap between them. Th...
{"inputs": ["1\n5\n", "1\n1\n", "1\n1\n", "1\n2\n", "1\n8\n", "1\n3\n", "1\n4\n", "1\n5\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n"]}
431
86
coding
Solve the programming task below in a Python markdown code block. Read problems statements in [Russian], [Vietnamese], [Hindi], [Mandarin chinese] and [Bengali] as well. Chef is interested in the history of SnackDown contests. He needs a program to verify if SnackDown was hosted in a given year. SnackDown was hosted ...
{"inputs": ["2\n2019\n2018"], "outputs": ["HOSTED\nNOT HOSTED"]}
242
27
coding
Solve the programming task below in a Python markdown code block. Chef has a circular plot of land of radius $R$ on which he wants to construct a swimming pool. He wants the swimming pool to be square in shape with maximum possible area,so that he along with his friends can enjoy themselves during their summer vacation...
{"inputs": ["2\n5\n10"], "outputs": ["50\n200"]}
219
22
coding
Solve the programming task below in a Python markdown code block. N people are waiting in a single line in front of the Takahashi Store. The cash on hand of the i-th person from the front of the line is a positive integer A_i. Mr. Takahashi, the shop owner, has decided on the following scheme: He picks a product, sets...
{"inputs": ["3\n3\n6\n5", "3\n4\n1\n2", "3\n3\n1\n1", "3\n5\n1\n1", "3\n2\n1\n1", "3\n1\n2\n1", "3\n3\n3\n5", "3\n5\n1\n4"], "outputs": ["6\n", "3\n", "2\n", "4\n", "1\n", "0\n", "5\n", "5\n"]}
457
110
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. In a row of dominoes, tops[i] and bottoms[i] represent the top and bottom halves of the ith domino. (A domino is a tile with two numbers from 1 to 6 - one on each half of the tile.) We may rotate the ith domino, so th...
{"functional": "def check(candidate):\n assert candidate(tops = [2,1,2,4,2,2], bottoms = [5,2,6,2,3,2]) == 2\n assert candidate(tops = [3,5,1,2,3], bottoms = [3,6,3,3,4]) == -1\n\n\ncheck(Solution().minDominoRotations)"}
165
94
coding
Solve the programming task below in a Python markdown code block. # Introduction The Condi (Consecutive Digraphs) cipher was introduced by G4EGG (Wilfred Higginson) in 2011. The cipher preserves word divisions, and is simple to describe and encode, but it's surprisingly difficult to crack. # Encoding Algorithm The ...
{"functional": "_inputs = [['on', 'cryptogram', 10]]\n_outputs = [['jx']]\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 ...
690
163
coding
Solve the programming task below in a Python markdown code block. Consider X as the aleatory variable that count the number of letters in a word. Write a function that, give in input an array of words (strings), calculate the variance of X. Max decimal of the variance : 4. Some wiki: Variance , Aleatory variable ...
{"functional": "_inputs = [[['Hello', 'world']], [['Hi', 'world']], [['Variance', 'is', 'not', 'a', 'good', 'stimator']]]\n_outputs = [[0], [2.25], [7.5556]]\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 ...
383
199
coding
Solve the programming task below in a Python markdown code block. The ancient Berlanders believed that the longer the name, the more important its bearer is. Thus, Berland kings were famous for their long names. But long names are somewhat inconvenient, so the Berlanders started to abbreviate the names of their kings. ...
{"inputs": ["3\nab\nb\ndef\n", "3\nab\na\ndef\n", "3\nab\na\ndeg\n", "3\nba\na\ndeg\n", "3\nba\na\ndef\n", "3\nab\nc\ndef\n", "3\nac\nabc\nca\n", "3\nab\nacb\nba\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "5\n", "5\n"]}
673
120
coding
Solve the programming task below in a Python markdown code block. There are two persons, numbered 0 and 1, and a variable x whose initial value is 0. The two persons now play a game. The game is played in N rounds. The following should be done in the i-th round (1 \leq i \leq N): * Person S_i does one of the following...
{"inputs": ["3\n2\n1 2\n14\n0\n0 0\n9\n6\n2 6 9 3 7 7\n011000", "3\n2\n1 2\n10\n2\n1 1\n10\n6\n2 3 4 9 6 7\n111000", "3\n2\n0 2\n10\n2\n1 1\n10\n6\n2 3 4 9 6 7\n111000", "3\n2\n1 2\n10\n2\n1 2\n10\n6\n2 3 1 9 6 7\n111000", "3\n2\n1 2\n14\n0\n2 0\n10\n6\n2 3 5 9 7 7\n111000", "3\n2\n0 2\n10\n2\n1 2\n10\n6\n2 3 1 9 2 7\n...
387
405
coding
Solve the programming task below in a Python markdown code block. DZY has a hash table with p buckets, numbered from 0 to p - 1. He wants to insert n numbers, in the order they are given, into the hash table. For the i-th number x_{i}, DZY will put it into the bucket numbered h(x_{i}), where h(x) is the hash function. ...
{"inputs": ["2 2\n2\n2\n", "2 2\n0\n0\n", "2 2\n0\n0\n", "2 2\n2\n2\n", "2 2\n1\n0\n", "2 2\n0\n2\n", "2 0\n1\n0\n", "2 2\n0\n3\n"], "outputs": ["2\n", "2\n", "2", "2", "-1\n", "2\n", "-1\n", "-1\n"]}
300
116
coding
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin chinese, Russian and Vietnamese as well. Chef has obtained the results of a past Cook-Off. He wants to estimate the skill level of each contestant. The contestants can be classified with high probability (w.h.p.) ba...
{"inputs": ["7\n0 0 0 0 0\n0 1 0 1 0\n0 0 1 0 0\n1 1 1 1 1\n0 1 1 1 0\n0 1 1 1 1\n1 1 1 1 0"], "outputs": ["Beginner\nMiddle Developer\nJunior Developer\nJeff Dean\nSenior Developer\nHacker\nHacker"]}
571
101
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an array of network towers towers, where towers[i] = [xi, yi, qi] denotes the ith network tower with location (xi, yi) and quality factor qi. All the coordinates are integral coordinates on the X-Y plane...
{"functional": "def check(candidate):\n assert candidate(towers = [[1,2,5],[2,1,7],[3,1,9]], radius = 2) == [2,1]\n assert candidate(towers = [[23,11,21]], radius = 9) == [23,11]\n assert candidate(towers = [[1,2,13],[2,1,7],[0,1,9]], radius = 2) == [1,2]\n\n\ncheck(Solution().bestCoordinate)"}
332
124
coding
Solve the programming task below in a Python markdown code block. Blob is a computer science student. He recently got an internship from Chef's enterprise. Along with the programming he has various other skills too like graphic designing, digital marketing and social media management. Looking at his skills Chef has pro...
{"inputs": ["6\n3 9 10 1 30 40"], "outputs": ["46"]}
221
28
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 n integers differences, which describes the differences between each pair of consecutive integers of a hidden sequence of length (n + 1). More formally, call the hidden sequence hidd...
{"functional": "def check(candidate):\n assert candidate(differences = [1,-3,4], lower = 1, upper = 6) == 2\n assert candidate(differences = [3,-4,5,1,-2], lower = -4, upper = 5) == 4\n assert candidate(differences = [4,-7,2], lower = 3, upper = 6) == 0\n\n\ncheck(Solution().numberOfArrays)"}
294
104
coding
Solve the programming task below in a Python markdown code block. Read problems statements in mandarin chinese, russian and vietnamese as well. Chef's dog Snuffles has so many things to play with! This time around, Snuffles has an array A containing N integers: A_{1}, A_{2}, ..., A_{N}. Bad news: Snuffles only love...
{"inputs": ["3\n5 2\n1 4 5 2 3\n3 1\n1 4 1\n4 2\n3 4 3 5"], "outputs": ["3\n2\n-1"]}
701
53
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a string s consisting of only the characters 'a' and 'b', return true if every 'a' appears before every 'b' in the string. Otherwise, return false.   Please complete the following python code precisely: ```pytho...
{"functional": "def check(candidate):\n assert candidate(s = \"aaabbb\") == True\n assert candidate(s = \"abab\") == False\n assert candidate(s = \"bbb\") == True\n\n\ncheck(Solution().checkString)"}
85
55
coding
Solve the programming task below in a Python markdown code block. # Task `EvilCode` is a game similar to `Codewars`. You have to solve programming tasks as quickly as possible. However, unlike `Codewars`, `EvilCode` awards you with a medal, depending on the time you took to solve the task. To get a medal, your time mu...
{"functional": "_inputs = [['00:30:00', '00:15:00', '00:45:00', '01:15:00'], ['01:15:00', '00:15:00', '00:45:00', '01:15:00'], ['00:00:01', '00:00:10', '00:01:40', '01:00:00'], ['00:10:01', '00:00:10', '00:01:40', '01:00:00'], ['00:00:01', '00:00:02', '00:00:03', '00:00:04'], ['90:00:01', '60:00:02', '70:00:03', '80:00...
481
583
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 taken his first dose of vaccine D days ago. He may take the second dose no less than L days and no more than R days since his first dose. Determine if Chef ...
{"inputs": ["4\n10 8 12 \n14 2 10\n4444 5555 6666 \n8 8 12\n"], "outputs": ["Take second dose now\nToo Late\nToo Early\nTake second dose now"]}
479
67
coding
Solve the programming task below in a Python markdown code block. We have a permutation of the integers from 1 through N, p_1, p_2, .., p_N. We also have M pairs of two integers between 1 and N (inclusive), represented as (x_1,y_1), (x_2,y_2), .., (x_M,y_M). AtCoDeer the deer is going to perform the following operation...
{"inputs": ["3 2\n3 2 1\n1 2\n1 3", "3 2\n3 2 1\n1 2\n2 2", "3 2\n3 2 1\n1 1\n1 3", "5 1\n1 2 3 4 5\n1 5", "3 2\n3 2 1\n1 2\n2 3", "5 2\n5 3 1 4 3\n1 3\n5 4", "5 2\n5 3 1 4 2\n1 2\n5 4", "5 2\n5 3 1 4 2\n1 2\n5 3"], "outputs": ["3\n", "1\n", "3\n", "5", "3", "2\n", "1\n", "1\n"]}
459
200
coding
Solve the programming task below in a Python markdown code block. In this problem at each moment you have a set of intervals. You can move from interval (a, b) from our set to interval (c, d) from our set if and only if c < a < d or c < b < d. Also there is a path from interval I1 from our set to interval I2 from our s...
{"inputs": ["5\n1 1 5\n1 8 11\n2 1 2\n1 2 9\n2 1 2\n", "5\n1 1 4\n1 8 11\n1 1 2\n1 3 9\n2 1 2\n", "5\n1 1 4\n1 8 11\n2 1 2\n1 2 9\n2 1 2\n", "5\n1 1 4\n1 8 11\n2 1 2\n1 3 9\n2 1 2\n", "5\n1 1 5\n1 5 13\n2 1 2\n1 2 9\n2 1 2\n", "5\n1 0 5\n1 8 11\n2 1 2\n1 2 9\n2 1 2\n", "5\n1 1 2\n1 8 11\n2 1 2\n1 2 9\n2 1 2\n", "5\n1 1...
361
332
coding
Solve the programming task below in a Python markdown code block. There is a queue for the self-checkout tills at the supermarket. Your task is write a function to calculate the total time required for all the customers to check out! ### input ```if-not:c * customers: an array of positive integers representing the que...
{"functional": "_inputs = [[[], 1], [[5], 1], [[2], 5], [[1, 2, 3, 4, 5], 1], [[1, 2, 3, 4, 5], 100], [[2, 2, 3, 3, 4, 4], 2]]\n_outputs = [[0], [5], [2], [15], [5], [9]]\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...
487
243
coding
Solve the programming task below in a Python markdown code block. Snuke is playing a puzzle game. In this game, you are given a rectangular board of dimensions R × C, filled with numbers. Each integer i from 1 through N is written twice, at the coordinates (x_{i,1},y_{i,1}) and (x_{i,2},y_{i,2}). The objective is to dr...
{"inputs": ["1 1 2\n0 0 1 1\n1 0 0 1", "1 1 2\n0 0 1 1\n1 0 0 1\n", "4 3 3\n0 1 3 1\n1 1 4 1\n2 0 2 2", "4 3 3\n0 1 3 1\n1 1 4 1\n0 0 2 2", "4 2 3\n0 1 3 1\n1 1 4 1\n2 0 4 2", "4 3 3\n0 1 1 1\n1 1 4 1\n0 0 2 2", "4 2 3\n0 1 3 1\n1 1 4 1\n2 0 4 1", "4 3 3\n0 1 1 1\n1 1 4 1\n0 0 2 1"], "outputs": ["NO", "NO\n", "YES\n", ...
357
270
coding
Solve the programming task below in a Python markdown code block. Chef has a sequence of positive integers $A_1, A_2, \ldots, A_N$. He wants to split this sequence into two non-empty (not necessarily contiguous) subsequences $B$ and $C$ such that $\mathrm{GCD}\,(B) + \mathrm{GCD}\,(C)$ is maximum possible. Help him fin...
{"inputs": ["1 \n4 \n4 4 7 6 \n"], "outputs": ["9"]}
412
29
coding
Solve the programming task below in a Python markdown code block. # Task A ciphertext alphabet is obtained from the plaintext alphabet by means of rearranging some characters. For example "bacdef...xyz" will be a simple ciphertext alphabet where a and b are rearranged. A substitution cipher is a method of encoding w...
{"functional": "_inputs = [['aacb', 'aabc'], ['aa', 'bc'], ['aaxxaaz', 'aazzaay'], ['aaxyaa', 'aazzaa'], ['aazzaa', 'aaxyaa'], ['jpeuizmi', 'mxxcwriq']]\n_outputs = [[True], [False], [True], [False], [False], [False]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n ...
294
230
coding
Solve the programming task below in a Python markdown code block. Given is a positive even number N. Find the number of strings s of length N consisting of `A`, `B`, and `C` that satisfy the following condition: * s can be converted to the empty string by repeating the following operation: * Choose two consecutive ch...
{"inputs": ["4", "8", "6", "0", "2", "14", "12", "16"], "outputs": ["63\n", "5407\n", "583\n", "1\n", "7", "4231815\n", "460815\n", "38745279\n"]}
266
88
coding
Solve the programming task below in a Python markdown code block. Two sisters, A and B, play the piano every day. During the day, they can play in any order. That is, A might play first and then B, or it could be B first and then A. But each one of them plays the piano exactly once per day. They maintain a common log, ...
{"inputs": ["4\nAB\nABBA\nABAABB\nAA"], "outputs": ["yes\nyes\nno\nno"]}
394
28
coding
Solve the programming task below in a Python markdown code block. You have N apples, called Apple 1, Apple 2, Apple 3, ..., Apple N. The flavor of Apple i is L+i-1, which can be negative. You can make an apple pie using one or more of the apples. The flavor of the apple pie will be the sum of the flavors of the apples ...
{"inputs": ["5 4", "5 7", "5 9", "8 9", "8 7", "3 8", "4 0", "2 2"], "outputs": ["26\n", "38\n", "46\n", "91\n", "77\n", "19\n", "6\n", "3\n"]}
390
84
coding
Solve the programming task below in a Python markdown code block. You have a playlist consisting of $n$ songs. The $i$-th song is characterized by two numbers $t_i$ and $b_i$ — its length and beauty respectively. The pleasure of listening to set of songs is equal to the total length of the songs in the set multiplied b...
{"inputs": ["2 1\n1 2\n2 1\n", "2 1\n1 2\n2 1\n", "2 2\n1 2\n2 1\n", "2 1\n1 2\n0 1\n", "2 1\n2 2\n2 1\n", "2 2\n100 100\n100 100\n", "2 2\n100 100\n100 100\n", "2 2\n100 100\n000 100\n"], "outputs": ["2\n", "2", "3\n", "2\n", "4\n", "20000\n", "20000", "10000\n"]}
456
184
coding
Solve the programming task below in a Python markdown code block. Write a function `insertDash(num)`/`InsertDash(int num)` that will insert dashes ('-') between each two odd numbers in num. For example: if num is 454793 the output should be 4547-9-3. Don't count zero as an odd number. Note that the number will always ...
{"functional": "_inputs = [[454793], [123456], [1003567], [24680], [13579]]\n_outputs = [['4547-9-3'], ['123456'], ['1003-567'], ['24680'], ['1-3-5-7-9']]\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 i...
114
233
coding
Solve the programming task below in a Python markdown code block. Create a program that converts the date expressed in the Christian era to the Japanese calendar using the era name and outputs the date. The input is three integers, as shown in the example, in the order year, month, and day. Convert this as shown in the...
{"inputs": ["2005 6 3\n53 5 1\n581 9 2", "2447 6 3\n53 5 1\n581 9 2", "2297 5 3\n411 5 1\n581 9 2", "2005 9 3\n1868 9 3\n359 9 7", "2965 9 3\n1868 9 3\n359 9 7", "4983 9 3\n1868 9 3\n359 9 7", "2005 4 3\n1868 9 3\n359 9 7", "3378 9 3\n373 10 3\n329 9 7"], "outputs": ["heisei 17 6 3\npre-meiji\npre-meiji\n", "heisei 459...
344
392
coding
Solve the programming task below in a Python markdown code block. # Task Given array of integers, for each position i, search among the previous positions for the last (from the left) position that contains a smaller value. Store this value at position i in the answer. If no such value can be found, store `-1` instead...
{"functional": "_inputs = [[[3, 5, 2, 4, 5]], [[2, 2, 1, 3, 4, 5, 5, 3]], [[3, 2, 1]]]\n_outputs = [[[-1, 3, -1, 2, 4]], [[-1, -1, -1, 1, 3, 4, 4, 1]], [[-1, -1, -1]]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_to...
207
248
coding
Solve the programming task below in a Python markdown code block. A new set of desks just arrived, and it's about time! Things were getting quite cramped in the office. You've been put in charge of creating a new seating chart for the engineers. The desks are numbered, and you sent out a survey to the engineering team ...
{"inputs": ["1\n1 2\n", "1\n1 2\n", "1\n2 2\n", "4\n1 5\n5 2\n3 7\n7 3\n", "4\n5 6\n6 7\n7 8\n8 5\n", "4\n5 6\n6 7\n7 8\n8 5\n", "4\n5 8\n6 7\n7 8\n8 5\n", "4\n5 8\n6 7\n7 3\n8 5\n"], "outputs": ["2\n", "2\n", "1\n", "6\n", "2\n", "2\n", "2\n", "6\n"]}
450
162
coding
Solve the programming task below in a Python markdown code block. You are given a tree with N nodes with every node being colored. A color is represented by an integer ranging from 1 to 10^{9}. Can you find the number of distinct colors available in a subtree rooted at the node s? Input Format The first line contai...
{"inputs": ["4 2 1\n1 2\n2 4\n2 3\n10\n20\n20\n30\n1\n2\n"], "outputs": ["3\n2\n"]}
372
48
coding
Solve the programming task below in a Python markdown code block. There are N cities numbered 1 to N, connected by M railroads. You are now at City 1, with 10^{100} gold coins and S silver coins in your pocket. The i-th railroad connects City U_i and City V_i bidirectionally, and a one-way trip costs A_i silver coins a...
{"inputs": ["2 1 1\n1 2 1 1\n1 1000000000\n1 1", "2 1 0\n1 2 1 1\n1 1000000100\n1 1", "2 1 0\n1 2 1 1\n1 1000000000\n1 1", "2 1 0\n1 2 1 1\n1 1000000000\n1 1\n", "2 1 1\n1 2 2 1\n1 1000000000\n-1 0", "2 1 1\n1 2 -1 2\n0 1000000000\n0 2", "2 1 0\n1 2 2 1\n1 1000000000\n-1 0", "2 1 0\n1 2 2 1\n1 1000010000\n-1 0"], "outp...
730
351
coding
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. Chef has n × n array A of non-negative integers. He wants to divide this array by p-1 horizontal dividers and p-1 vertical dividers into p^{2} blocks such that maximum sum of...
{"inputs": ["4 3\n1 1 2 2\n2 1 2 2\n3 1 4 2\n4 4 2 2"], "outputs": ["2 3\n1 3"]}
719
52
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an array nums that consists of positive integers. The GCD of a sequence of numbers is defined as the greatest integer that divides all the numbers in the sequence evenly. For example, the GCD of the seq...
{"functional": "def check(candidate):\n assert candidate(nums = [6,10,3]) == 5\n assert candidate(nums = [5,15,40,5,6]) == 7\n\n\ncheck(Solution().countDifferentSubsequenceGCDs)"}
186
63
coding
Solve the programming task below in a Python markdown code block. Johnny drives a truck and must deliver a package from his hometown to the district center. His hometown is located at point 0 on a number line, and the district center is located at the point d. Johnny's truck has a gas tank that holds exactly n liters,...
{"inputs": ["16 5 2\n8 2\n5 1\n", "153 105 1\n96 83995\n", "10 4 4\n3 5\n5 8\n6 3\n8 4\n", "229 79 2\n27 270968\n76 284309\n", "229 79 2\n27 349050\n76 284309\n", "229 79 2\n27 349050\n16 284309\n", "229 79 2\n53 349050\n16 284309\n", "229 123 2\n6 270968\n76 284309\n"], "outputs": ["-1\n", "4031760\n", "22\n", "-1\n",...
497
264