task_type
stringclasses
1 value
problem
stringlengths
261
3.34k
answer
stringlengths
35
6.15k
problem_tokens
int64
62
774
answer_tokens
int64
12
2.04k
coding
Solve the programming task below in a Python markdown code block. You are given N points on a plane. Write a program which will find the sum of squares of distances between all pairs of points. Input The first line of input contains one integer number N (1 ≀ N ≀ 100 000) β€” the number of points. Each of the following ...
{"inputs": ["1\n6 3\n", "1\n7 3\n", "1\n9 3\n", "1\n9 4\n", "1\n6 4\n", "1\n6 2\n", "1\n6 0\n", "1\n8 1\n"], "outputs": ["0", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]}
170
101
coding
Solve the programming task below in a Python markdown code block. Chef has a number N, Cheffina challenges the chef to check the divisibility of all the permutation of N by 2. If any of the permutations is divisible by 2 then print 1 else print 0. -----Input:----- - First-line will contain $T$, the number of test case...
{"inputs": ["2\n19\n385"], "outputs": ["0\n1"]}
177
21
coding
Solve the programming task below in a Python markdown code block. Problem Given a natural number N less than or equal to 12, find the smallest natural number such that the number of divisors is exactly N. Constraints * 1 ≀ N ≀ 12 Input One natural number N is given in one line. Output Output the smallest natural...
{"inputs": ["5", "4", "6", "8", "7", "9", "4", "6"], "outputs": ["16\n", "6\n", "12\n", "24\n", "64\n", "36\n", "6\n", "12\n"]}
115
68
coding
Solve the programming task below in a Python markdown code block. Little Vasya's uncle is a postman. The post offices are located on one circular road. Besides, each post office has its own gas station located next to it. Petya's uncle works as follows: in the morning he should leave the house and go to some post offic...
{"inputs": ["1\n1\n1\n", "1\n0\n0\n", "1\n2\n2\n", "1\n3\n3\n", "1\n4\n4\n", "3\n3 3 3\n3 2 4\n", "4\n0 7 2 3\n8 1 0 3\n", "4\n1 7 2 3\n9 1 0 3\n"], "outputs": ["1\n1 \n", "1\n1 ", "1\n1 ", "1\n1 ", "1\n1 ", "3\n1 2 3 \n", "2\n2 4 ", "2\n2 4 "]}
738
155
coding
Solve the programming task below in a Python markdown code block. You are going to be given a word. Your job will be to make sure that each character in that word has the exact same number of occurrences. You will return `true` if it is valid, or `false` if it is not. For example: `"abcabc"` is a valid word because `...
{"functional": "_inputs = [['abcabc'], ['Abcabc'], ['AbcabcC'], ['AbcCBa'], ['pippi'], ['?!?!?!'], ['abc123'], ['abcabcd'], ['abc!abc!'], ['abc:abc']]\n_outputs = [[True], [True], [False], [True], [False], [True], [True], [False], [True], [False]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float)...
278
229
coding
Solve the programming task below in a Python markdown code block. We have a board with a 2 \times N grid. Snuke covered the board with N dominoes without overlaps. Here, a domino can cover a 1 \times 2 or 2 \times 1 square. Then, Snuke decided to paint these dominoes using three colors: red, cyan and green. Two dominoe...
{"inputs": ["1\nZ\nZ\n", "1\nX\nX\n", "2\nrT\nrT\n", "2\nxj\nxj\n", "2\nEE\nCC\n", "3\naab\nccb\n", "3\nGxx\nGYY\n", "3\nYLm\nYLm\n"], "outputs": ["3\n", "3\n", "6\n", "6\n", "6\n", "6\n", "6\n", "12\n"]}
357
111
coding
Solve the programming task below in a Python markdown code block. A new delivery of clothing has arrived today to the clothing store. This delivery consists of $a$ ties, $b$ scarves, $c$ vests and $d$ jackets. The store does not sell single clothing items β€” instead, it sells suits of two types: a suit of the first ty...
{"inputs": ["4\n5\n6\n3\n1\n2\n", "1\n2\n3\n4\n1\n1\n", "6\n1\n2\n5\n1\n1\n", "1\n2\n2\n2\n2\n1\n", "1\n4\n5\n6\n8\n8\n", "1\n1\n1\n2\n1\n1\n", "1\n2\n3\n4\n1\n1\n", "1\n2\n2\n2\n2\n1\n"], "outputs": ["6\n", "3\n", "5\n", "3\n", "40\n", "2\n", "3\n", "3\n"]}
562
151
coding
Solve the programming task below in a Python markdown code block. You are given an array ${A}$ of size $N$. You are asked to answer ${Q}$ queries. Each query is of the form : ${ij x}$ You need to print Yes if ${x}$ divides the value returned from $find(i,j)$ function, otherwise print No. find(int i,int j) { ...
{"inputs": ["4\n2 3 4 5\n2\n1 2 4\n1 3 7\n"], "outputs": ["Yes\nNo\n"]}
326
38
coding
Solve the programming task below in a Python markdown code block. You are given an array $a_1, a_2, \dots , a_n$, which is sorted in non-decreasing order ($a_i \le a_{i + 1})$. Find three indices $i$, $j$, $k$ such that $1 \le i < j < k \le n$ and it is impossible to construct a non-degenerate triangle (a triangle wi...
{"inputs": ["1\n6\n1 1 1 2 2 3\n", "1\n6\n1 1 1 2 2 3\n", "1\n6\n1 1 1 2 3 3\n", "1\n3\n21 78868 80000\n", "1\n3\n21 78868 80000\n", "1\n3\n39 78868 80000\n", "1\n3\n41 78868 80000\n", "1\n3\n11 78868 80000\n"], "outputs": ["1 2 6\n", "1 2 6\n", "1 2 6\n", "1 2 3\n", "1 2 3\n", "1 2 3\n", "1 2 3\n", "1 2 3\n"]}
554
229
coding
Solve the programming task below in a Python markdown code block. It is raining heavily. But this is the first day for Serval, who just became 3 years old, to go to the kindergarten. Unfortunately, he lives far from kindergarten, and his father is too busy to drive him there. The only choice for this poor little boy is...
{"inputs": ["1 4\n2 2\n", "1 4\n2 2\n", "1 4\n0 2\n", "1 4\n-1 2\n", "2 2\n6 4\n9 5\n", "2 5\n4 3\n3 3\n", "2 7\n4 3\n3 3\n", "2 7\n4 4\n3 3\n"], "outputs": ["1\n", "1", "1\n", "1\n", "1\n", "2\n", "1\n", "1\n"]}
604
134
coding
Solve the programming task below in a Python markdown code block. Vasya goes to visit his classmate Petya. Vasya knows that Petya's apartment number is $n$. There is only one entrance in Petya's house and the distribution of apartments is the following: the first floor contains $2$ apartments, every other floor conta...
{"inputs": ["4\n8 3\n1 5\n22 5\n987 5\n", "4\n8 3\n1 5\n22 5\n859 5\n", "4\n8 3\n1 5\n29 5\n859 5\n", "4\n8 3\n1 5\n11 5\n859 5\n", "4\n8 3\n1 5\n29 5\n859 7\n", "4\n6 3\n1 5\n29 5\n859 6\n", "4\n8 3\n1 5\n37 5\n859 7\n", "4\n2 3\n1 5\n29 5\n859 6\n"], "outputs": ["3\n1\n5\n198\n", "3\n1\n5\n173\n", "3\n1\n7\n173\n", "...
471
286
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 an array A consisting of N integers. He also has an intger K. Chef wants you to find out number of different arrays he can obtain from array A by applying the follo...
{"inputs": ["3\n1 3\n100\n3 1\n1 2 1\n3 2\n1 2 1"], "outputs": ["1\n3\n4"]}
548
44
coding
Solve the programming task below in a Python markdown code block. Given is an integer N. Find the minimum possible positive integer k such that (1+2+\cdots+k) is a multiple of N. It can be proved that such a positive integer k always exists. Constraints * 1 \leq N \leq 10^{15} * All values in input are integers. Inp...
{"inputs": ["5", "2", "9", "1", "85", "19", "91", "11"], "outputs": ["4\n", "3\n", "8\n", "1\n", "34\n", "18\n", "13\n", "10"]}
139
69
coding
Solve the programming task below in a Python markdown code block. You are given n patterns p_1, p_2, ..., p_n and m strings s_1, s_2, ..., s_m. Each pattern p_i consists of k characters that are either lowercase Latin letters or wildcard characters (denoted by underscores). All patterns are pairwise distinct. Each stri...
{"inputs": ["2 1 1\ns\nb\nb 1\n", "2 1 1\ns\na\nb 1\n", "2 1 1\ns\nb\nc 1\n", "2 1 1\ns\na\nb 2\n", "2 1 1\nt\na\nb 1\n", "1 1 3\n__d\ncba 1\n", "1 1 3\n_c_\ncba 1\n", "1 1 3\n__c\ncba 1\n"], "outputs": ["NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "\nNO\n"]}
674
166
coding
Solve the programming task below in a Python markdown code block. Oh no! Ghosts have reportedly swarmed the city. It's your job to get rid of them and save the day! In this kata, strings represent buildings while whitespaces within those strings represent ghosts. So what are you waiting for? Return the building(strin...
{"functional": "_inputs = [['Factor y'], ['O f fi ce'], ['BusStation'], ['Suite '], ['YourHouse'], ['H o t e l ']]\n_outputs = [['Factory'], ['Office'], [\"You just wanted my autograph didn't you?\"], ['Suite'], [\"You just wanted my autograph didn't you?\"], ['Hotel']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n ...
114
220
coding
Solve the programming task below in a Python markdown code block. Valera the Horse is going to the party with friends. He has been following the fashion trends for a while, and he knows that it is very popular to wear all horseshoes of different color. Valera has got four horseshoes left from the last year, but maybe s...
{"inputs": ["2 2 2 1\n", "3 1 1 1\n", "1 1 2 5\n", "1 1 3 3\n", "1 1 3 5\n", "2 1 2 3\n", "1 2 2 2\n", "3 1 2 1\n"], "outputs": ["2\n", "2\n", "1\n", "2\n", "1\n", "1\n", "2\n", "1\n"]}
299
118
coding
Solve the programming task below in a Python markdown code block. Let's learn some new Python concepts! You have to generate a list of the first $N$ fibonacci numbers, $\mbox{o}$ being the first number. Then, apply the map function and a lambda expression to cube each fibonacci number and print the list. Concept The ...
{"inputs": ["5\n"], "outputs": ["[0, 1, 1, 8, 27]\n"]}
403
29
coding
Solve the programming task below in a Python markdown code block. Given an array of numbers, return the difference between the largest and smallest values. For example: `[23, 3, 19, 21, 16]` should return `20` (i.e., `23 - 3`). `[1, 434, 555, 34, 112]` should return `554` (i.e., `555 - 1`). The array will contain ...
{"functional": "_inputs = [[[1, 1]], [[-1, -1]], [[1, -1]], [[21, 34, 54, 43, 26, 12]], [[-1, -41, -77, -100]]]\n_outputs = [[0], [0], [2], [42], [99]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if i...
164
228
coding
Solve the programming task below in a Python markdown code block. The chef is having one array of N natural numbers(numbers may be repeated). i.e. All natural numbers must be less than N. Chef wants to rearrange the array and try to place a natural number on its index of the array, i.e array[i]=i. If multiple natural n...
{"inputs": ["2\n2\n1 1\n4\n1 1 2 1"], "outputs": ["0 1\n0 1 2 0"]}
393
38
coding
Solve the programming task below in a Python markdown code block. A sequence of integers is called a wonderful sequence if all the integers in it are positive and it is a strictly increasing sequence. Given a sequence of integers, you have to make it a wonderful sequence. For that you can change any element you want, ...
{"inputs": ["3\n2\n1 2\n3\n3 2 1\n5\n10 5 6 7 8", "4\n2\n1 2\n3\n3 2 1\n5\n10 5 6 7 8\n4\n2 2 2 2"], "outputs": ["0\n2\n1", "0\n2\n1\n3"]}
300
92
coding
Solve the programming task below in a Python markdown code block. As a strict big brother, I do limit my young brother Vasya on time he spends on computer games. I define a prime-time as a time period till which Vasya have a permission to play computer games. I specify start hour and end hour as pair of integers. I ne...
{"functional": "_inputs = [[9, 10, 11], [12, 12, 13], [13, 10, 15], [14, 9, 14], [15, 8, 12], [20, 21, 1], [21, 21, 6], [17, 15, 3], [0, 22, 1], [1, 22, 1], [3, 23, 2], [20, 0, 23], [14, 2, 9], [9, 20, 11], [23, 23, 0], [11, 2, 9], [0, 20, 23], [4, 0, 3], [6, 2, 10]]\n_outputs = [[False], [True], [True], [False], [Fals...
216
409
coding
Solve the programming task below in a Python markdown code block. Create a function that takes 2 positive integers in form of a string as an input, and outputs the sum (also as a string): If either input is an empty string, consider it as zero. Also feel free to reuse/extend the following starter code: ```python def s...
{"functional": "_inputs = [['4', '5'], ['34', '5'], ['9', ''], ['', '9']]\n_outputs = [['9'], ['39'], ['9'], ['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 if isinstance(a, (list, tuple)):\n ...
77
183
coding
Solve the programming task below in a Python markdown code block. Based on some criterion, Snuke divided the integers from 1 through 12 into three groups as shown in the figure below. Given two integers x and y (1 ≀ x < y ≀ 12), determine whether they belong to the same group. -----Constraints----- - x and y are inte...
{"inputs": ["2 8", "1 4", "2 3", "4 3", "7 3", "7 6", "7 4", "7 5"], "outputs": ["No\n", "No\n", "No\n", "No\n", "Yes\n", "No\n", "No\n", "Yes\n"]}
140
78
coding
Solve the programming task below in a Python markdown code block. You've got a positive integer sequence a_1, a_2, ..., a_{n}. All numbers in the sequence are distinct. Let's fix the set of variables b_1, b_2, ..., b_{m}. Initially each variable b_{i} (1 ≀ i ≀ m) contains the value of zero. Consider the following seque...
{"inputs": ["3\n3 6 5\n", "3\n2 4 8\n", "3\n2 4 8\n", "3\n3 6 5\n", "1\n83930578\n", "1\n83930578\n", "1\n26428407\n", "1\n34042729\n"], "outputs": ["-1\n", "1\n", "1\n", "-1", "1\n", "1", "1\n", "1\n"]}
489
129
coding
Solve the programming task below in a Python markdown code block. B: Ebi-chan and Integer Sequences- problem Ebi-chan likes sequences. I especially like arithmetic progressions. This time, I decided to create a sequence that meets the following conditions. * Arithmetic progression of length n * When the i-th element...
{"inputs": ["3 0", "3 4", "3 1", "6 4", "2 4", "2 3", "2 5", "1 2"], "outputs": ["1\n", "13\n", "2\n", "5\n", "25\n", "16\n", "36\n", "3\n"]}
322
82
coding
Solve the programming task below in a Python markdown code block. At Akabeko Elementary School, all the students participate in a slightly unusual jogging. Students run their own lap courses at their own pace. After going around each of your courses, you will be returned to elementary school. How many laps do they all ...
{"inputs": ["2\n4 6\n5 4\n5\n789 5\n166 22\n9 3\n617 252\n972 303\n2\n8 5\n6 20\n0", "2\n4 3\n7 8\n0\n480 10\n255 46\n9 1\n617 12\n219 303\n2\n0 1\n2 37\n0", "2\n4 3\n9 4\n5\n480 2\n48 46\n9 5\n617 252\n972 303\n2\n8 5\n61 20\n0", "2\n4 3\n11 8\n0\n480 5\n166 46\n9 1\n617 252\n262 1\n0\n2 5\n32 20\n0", "2\n4 3\n9 4\n5\...
448
850
coding
Solve the programming task below in a Python markdown code block. Problem Statement:Captain America and Iron Man are at WAR and the rage inside Iron Man is rising. But Iron Man faces a problem to identify the location of Captain America. There are N buildings situtaed adjacently to each other and Captain America can ...
{"inputs": ["3\n2 1\n3 0\n3 2"], "outputs": ["2 1\n1 2 3\nCAPTAIN AMERICA EVADES"]}
354
41
coding
Solve the programming task below in a Python markdown code block. You have a string $s$ consisting of $n$ characters. Each character is either 0 or 1. You can perform operations on the string. Each operation consists of two steps: select an integer $i$ from $1$ to the length of the string $s$, then delete the charact...
{"inputs": ["5\n6\n111010\n1\n0\n1\n1\n2\n11\n6\n101010\n", "5\n6\n111010\n1\n1\n1\n1\n2\n11\n6\n101010\n", "5\n6\n111000\n1\n1\n1\n1\n2\n11\n6\n101010\n", "5\n6\n011011\n1\n0\n1\n1\n2\n11\n6\n111000\n", "5\n6\n111111\n1\n0\n1\n1\n2\n11\n6\n101010\n", "5\n6\n111000\n1\n1\n1\n1\n2\n18\n6\n000010\n", "5\n6\n111011\n1\n1\...
701
382
coding
Solve the programming task below in a Python markdown code block. Problem One day, Kawabayashi is about to have lunch at the school cafeteria. There are three types of daily lunch menus for school cafeterias: A lunch, B lunch, and C lunch. Kawabayashi is a glutton, so I would like to eat all three types of daily lunch...
{"inputs": ["0011 2 329", "0011 1 329", "0011 0 329", "0010 0 329", "0010 0 256", "0010 0 413", "0011 0 413", "0001 0 413"], "outputs": ["C\n", "C\n", "C\n", "C\n", "C\n", "C\n", "C\n", "C\n"]}
337
134
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 possibly...
{"inputs": ["9999 1\n0\n", "1000 8\n1 3 4 5 6 7 8 9\n"], "outputs": ["9999\n", "2000\n"]}
358
56
coding
Solve the programming task below in a Python markdown code block. ----- HALLOWEEN EVE ----- In some other world, today is Halloween Eve.There are N trees planted in Mr. Smith’s garden. The height of the i-th tree (1≀i≀N) is h i meters. He decides to choose K trees from these trees and decorate them with electric light...
{"inputs": ["5 3\n10\n15\n11\n14\n12"], "outputs": ["2"]}
307
29
coding
Solve the programming task below in a Python markdown code block. At a geometry lesson Bob learnt that a triangle is called right-angled if it is nondegenerate and one of its angles is right. Bob decided to draw such a triangle immediately: on a sheet of paper he drew three points with integer coordinates, and joined t...
{"inputs": ["0 0 1 0 4 1\n", "0 0 1 0 2 1\n", "0 0 0 1 1 0\n", "0 0 1 0 3 1\n", "0 0 1 0 2 2\n", "0 0 1 0 0 1\n", "2 3 4 5 3 6\n", "0 0 4 0 0 1\n"], "outputs": ["NEITHER\n", "ALMOST\n", "RIGHT\n", "ALMOST\n", "ALMOST\n", "RIGHT\n", "RIGHT\n", "RIGHT\n"]}
353
154
coding
Solve the programming task below in a Python markdown code block. On a number axis directed from the left rightwards, n marbles with coordinates x1, x2, ..., xn are situated. Let's assume that the sizes of the marbles are infinitely small, that is in this task each of them is assumed to be a material point. You can sti...
{"inputs": ["1\n837757580 0\n", "1\n-59873019 0\n", "1\n-60730778 0\n", "3\n4 3\n3 4\n1 2\n", "1\n837757580 2\n", "3\n4 3\n3 4\n1 1\n", "1\n837757580 4\n", "1\n837757580 1\n"], "outputs": ["0", "0", "0\n", "7\n", "2\n", "6\n", "4\n", "1\n"]}
446
164
coding
Solve the programming task below in a Python markdown code block. This follows from Game of Thrones - I. Now that the king knows how to find out whether a given word has an anagram which is a palindrome or not, he encounters another challenge. He realizes that there can be more than one palindrome anagrams for a given...
{"inputs": ["aaabbbb\n", "cdcdcdcdeeeef\n"], "outputs": ["3 \n", "90\n"]}
287
31
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a list of dominoes, dominoes[i] = [a, b] is equivalent to dominoes[j] = [c, d] if and only if either (a == c and b == d), or (a == d and b == c) - that is, one domino can be rotated to be equal to another domino...
{"functional": "def check(candidate):\n assert candidate(dominoes = [[1,2],[2,1],[3,4],[5,6]]) == 1\n assert candidate(dominoes = [[1,2],[1,2],[1,1],[1,2],[2,2]]) == 3\n\n\ncheck(Solution().numEquivDominoPairs)"}
168
83
coding
Solve the programming task below in a Python markdown code block. Let's denote that some array $b$ is bad if it contains a subarray $b_l, b_{l+1}, \dots, b_{r}$ of odd length more than $1$ ($l < r$ and $r - l + 1$ is odd) such that $\forall i \in \{0, 1, \dots, r - l\}$ $b_{l + i} = b_{r - i}$. If an array is not bad,...
{"inputs": ["2 3\n3 3\n", "2 3\n3 3\n", "2 6\n3 3\n", "2 6\n5 3\n", "2 6\n2 3\n", "2 6\n3 5\n", "2 7\n3 5\n", "2 9\n3 5\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n"]}
442
118
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given the root of a binary tree, replace the value of each node in the tree with the sum of all its cousins' values. Two nodes of a binary tree are cousins if they have the same depth with different parents. Return th...
{"functional": "def check(candidate):\n assert is_same_tree(candidate(root = tree_node([5,4,9,1,10,None,7])), tree_node([0,0,0,7,7,None,11]))\n assert is_same_tree(candidate(root = tree_node([3,1,2])), tree_node([0,0,0]))\n\n\ncheck(Solution().replaceValueInTree)"}
179
93
coding
Solve the programming task below in a Python markdown code block. Polycarp is very careful. He even types numeric sequences carefully, unlike his classmates. If he sees a sequence without a space after the comma, with two spaces in a row, or when something else does not look neat, he rushes to correct it. For example, ...
{"inputs": ["1\n", ",\n", "0\n", ",,\n", "1,\n", ",1\n", "2,\n", ",2\n"], "outputs": ["1\n", ",\n", "0\n", ", ,\n", "1,\n", ", 1\n", "2,\n", ", 2\n"]}
498
77
coding
Solve the programming task below in a Python markdown code block. One day Alex was creating a contest about his friends, but accidentally deleted it. Fortunately, all the problems were saved, but now he needs to find them among other problems. But there are too many problems, to do it manually. Alex asks you to write ...
{"inputs": ["A\n", "A\n", "@\n", "aa\n", "aa\n", "ab\n", "ac\n", "Ann\n"], "outputs": ["NO", "NO\n", "NO\n", "NO", "NO\n", "NO\n", "NO\n", "YES"]}
232
67
coding
Solve the programming task below in a Python markdown code block. In genetic the reverse complement of a sequence is formed by **reversing** the sequence and then taking the complement of each symbol. The four nucleotides in DNA is Adenine (A), Cytosine (C), Guanine (G) and Thymine (Thymine). - A is the complement o...
{"functional": "_inputs = [['TTCCGGAA'], ['GACTGACTGTA'], [''], ['XYZ']]\n_outputs = [['TTCCGGAA'], ['TACAGTCAGTC'], [''], ['Invalid sequence']]\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 isinstan...
229
188
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an integer array nums, return the third distinct maximum number in this array. If the third maximum does not exist, return the maximum number. Β  Please complete the following python code precisely: ```python cla...
{"functional": "def check(candidate):\n assert candidate([3, 2, 1]) == 1\n assert candidate([1, 2]) == 2\n assert candidate([2, 2, 3, 1]) == 1\n\n\ncheck(Solution().thirdMax)"}
77
67
coding
Solve the programming task below in a Python markdown code block. Pavel made a photo of his favourite stars in the sky. His camera takes a photo of all points of the sky that belong to some rectangle with sides parallel to the coordinate axes. Strictly speaking, it makes a photo of all points with coordinates (x, y), ...
{"inputs": ["1\n1 1\n", "1\n1 0\n", "1\n3 0\n", "1\n0 0\n", "1\n1 -1\n", "1\n2 -1\n", "1\n3 -1\n", "1\n0 -1\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]}
520
102
coding
Solve the programming task below in a Python markdown code block. *** Nova polynomial multiply*** This kata is from a series on polynomial handling. ( [#1](http://www.codewars.com/kata/nova-polynomial-1-add-1) [#2](http://www.codewars.com/kata/570eb07e127ad107270005fe) [#3](http://www.codewars.com/kata/5714041e880...
{"functional": "_inputs = [[[], []], [[1, 2, 3, 4, 5, 6], []], [[], [1, 2, 3, 4, 5, 6]]]\n_outputs = [[[]], [[]], [[]]]\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 ...
363
199
coding
Solve the programming task below in a Python markdown code block. Read problem statements in [Mandarin], [Russian], and [Vietnamese] as well. An index of an array is called a fixed point if the value on the index of the array is equal to the index itself. Formally, an index i of an array A of length N is a fixed point...
{"inputs": ["3\n2\n1 2\n3\n2 3 2\n4\n1 3 4 2\n"], "outputs": ["3\n1\n5\n"]}
686
42
coding
Solve the programming task below in a Python markdown code block. Ekiden competitions are held every year in Aizukuni. The country of Aiz is dotted with N towns, each numbered from 1 to N. Several towns are connected by roads that allow them to come and go directly to each other. You can also follow several roads betwe...
{"inputs": ["4 5\n1 2 2\n1 3 2\n2 3 1\n2 4 2\n3 4 1", "7 9\n2 1 2\n1 3 1\n2 3 2\n2 4 4\n2 6 1\n6 4 1\n3 5 1\n3 5 1\n4 7 3\n5 7 2\n6 7 1", "7 9\n2 1 2\n1 3 1\n2 3 2\n2 4 4\n2 6 1\n6 1 1\n3 5 1\n3 5 1\n4 7 3\n5 7 2\n6 7 1", "7 9\n2 1 2\n1 3 1\n2 3 2\n2 4 4\n2 6 1\n6 4 1\n3 5 1\n3 6 1\n4 7 3\n5 7 2\n6 7 1", "7 9\n2 1 2\n1...
588
589
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a sorted integer array nums and an integer n, add/patch elements to the array such that any number in the range [1, n] inclusive can be formed by the sum of some elements in the array. Return the minimum number ...
{"functional": "def check(candidate):\n assert candidate(nums = [1,3], n = 6) == 1\n assert candidate(nums = [1,5,10], n = 20) == 2\n assert candidate(nums = [1,2,2], n = 5) == 0\n\n\ncheck(Solution().minPatches)"}
105
83
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a phone number as a string number. number consists of digits, spaces ' ', and/or dashes '-'. You would like to reformat the phone number in a certain manner. Firstly, remove all spaces and dashes. Then, ...
{"functional": "def check(candidate):\n assert candidate(number = \"1-23-45 6\") == \"123-456\"\n assert candidate(number = \"123 4-567\") == \"123-45-67\"\n assert candidate(number = \"123 4-5678\") == \"123-456-78\"\n assert candidate(number = \"12\") == \"12\"\n assert candidate(number = \"--17-5 229 ...
202
169
coding
Solve the programming task below in a Python markdown code block. Ahmed and Mostafa used to compete together in many programming contests for several years. Their coach Fegla asked them to solve one challenging problem, of course Ahmed was able to solve it but Mostafa couldn't. This problem is similar to a standard pr...
{"inputs": ["1 1\n1 0\n1\n", "1 1\n1 1\n1\n", "1 1\n1 -1\n1\n", "2 1\n2 -4 -6\n5 6 8 3 5 -2\n1\n", "2 1\n2 -4 -6\n5 6 8 3 5 -3\n1\n", "2 1\n2 -4 -10\n5 6 8 3 5 -3\n1\n", "3 4\n3 1 6 -2\n2 4 3\n2 -5 1\n2 3 1 3\n", "3 4\n3 1 6 -2\n2 3 3\n2 -5 1\n2 3 1 3\n"], "outputs": ["0", "1", "-1", "-4", "-4\n", "-4\n", "10\n", "9"]}
724
217
coding
Solve the programming task below in a Python markdown code block. Consider an undirected graph containing $N$ nodes and $\mbox{M}$ edges. Each edge $\textit{M}_i$ has an integer cost, $C_i$, associated with it. The penalty of a path is the bitwise OR of every edge cost in the path between a pair of nodes, $\mbox{A}$ a...
{"inputs": ["3 4\n1 2 1\n1 2 1000\n2 3 3\n1 3 100\n1 3\n"], "outputs": ["3\n"]}
626
49
coding
Solve the programming task below in a Python markdown code block. You are given a $sorted$ list $A$ of size $N$.You have to make a new list $B$ such that $B[i]$ is equal to the number of elements $strictly$ $greater$ than $A[i]$ in the list $A$. Print the $new$ $list$. ------ Input ------ The first line consists o...
{"inputs": ["2\n4\n1 2 4 4\n5\n1 2 2 2 2"], "outputs": ["3 2 0 0\n4 0 0 0 0"]}
535
50
coding
Solve the programming task below in a Python markdown code block. You are going out for a walk, when you suddenly encounter N monsters. Each monster has a parameter called health, and the health of the i-th monster is h_i at the moment of encounter. A monster will vanish immediately when its health drops to 0 or below....
{"inputs": ["2 35 7\n0\n26", "2 9 4\n20\n91", "2 10 4\n20\n37", "2 17 4\n20\n37", "2 11 7\n20\n37", "2 10 4\n39\n37", "2 10 4\n39\n64", "2 10 4\n20\n20"], "outputs": ["1\n", "11\n", "5\n", "3\n", "4\n", "6\n", "8\n", "4"]}
399
148
coding
Solve the programming task below in a Python markdown code block. On a certain train, Chef-the ticket collector, collects a fine of Rs. X if a passenger is travelling without a ticket. It is known that a passenger carries either a single ticket or no ticket. P passengers are travelling and they have a total of Q tick...
{"inputs": ["4\n4 1 1\n2 10 7\n8 5 4\n9 7 0"], "outputs": ["0\n6\n8\n63"]}
461
44
coding
Solve the programming task below in a Python markdown code block. The Indian bank issues coins in 4 denominations, β‚Ή1, β‚Ή2, β‚Ή5 and β‚Ή10. Given a limited supply of each of the above denominations, in how many ways can you sum them up to a total of β‚ΉN? Input Format The first line contains an integer T (number of testc...
{"inputs": ["2\n15\n2 3 1 1\n12\n2 2 1 1\n"], "outputs": ["2\n2\n"]}
290
38
coding
Solve the programming task below in a Python markdown code block. Tired of boring office work, Denis decided to open a fast food restaurant. On the first day he made $a$ portions of dumplings, $b$ portions of cranberry juice and $c$ pancakes with condensed milk. The peculiarity of Denis's restaurant is the procedure ...
{"inputs": ["2\n2 2 8\n3 2 2\n", "2\n2 2 8\n3 2 2\n", "2\n2 2 8\n3 3 2\n", "2\n2 2 7\n3 3 0\n", "2\n1 2 7\n3 3 0\n", "2\n1 3 7\n5 0 0\n", "2\n1 3 7\n5 0 1\n", "2\n2 2 8\n2 2 2\n"], "outputs": ["5\n5\n", "5\n5\n", "5\n5\n", "5\n3\n", "4\n3\n", "4\n1\n", "4\n2\n", "5\n4\n"]}
550
182
coding
Solve the programming task below in a Python markdown code block. Vasya's telephone contains n photos. Photo number 1 is currently opened on the phone. It is allowed to move left and right to the adjacent photo by swiping finger over the screen. If you swipe left from the first photo, you reach photo n. Similarly, by s...
{"inputs": ["1 2 3 3\nw\n", "1 2 3 3\nw\n", "1 3 3 3\nw\n", "1 0 3 3\nw\n", "1 4 3 3\nw\n", "1 2 5 3\nw\n", "4 2 3 10\nwwhw\n", "4 2 1 10\nwwhw\n"], "outputs": ["0\n", "0", "0\n", "0\n", "0\n", "0\n", "2\n", "3\n"]}
602
137
coding
Solve the programming task below in a Python markdown code block. The Little Elephant loves to play with color cards. He has n cards, each has exactly two colors (the color of the front side and the color of the back side). Initially, all the cards lay on the table with the front side up. In one move the Little Elepha...
{"inputs": ["1\n1 2\n", "1\n1 1\n", "1\n0 2\n", "1\n2 2\n", "1\n2 4\n", "2\n1 2\n2 1\n", "2\n1 2\n2 3\n", "2\n1 1\n1 1\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]}
421
114
coding
Solve the programming task below in a Python markdown code block. Let's call a number k-good if it contains all digits not exceeding k (0, ..., k). You've got a number k and an array a containing n numbers. Find out how many k-good numbers are in a (count each number every time it occurs in array a). -----Input----- ...
{"inputs": ["1 0\n1\n", "1 1\n1\n", "1 3\n1\n", "1 9\n1\n", "1 3\n1\n", "1 1\n1\n", "1 0\n1\n", "1 9\n1\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]}
256
102
coding
Solve the programming task below in a Python markdown code block. Alice likes to shop online. The main reason is that she gets a lot of discounts! There are M online shops from where she purchases her items. The prices of the same item vary in both the shops. She needs to buy N items in all. And each she can buy each i...
{"inputs": ["2\n2 2\n3 4\n1 2\n1 0\n0 1\n2 4\n1 2 3 4\n4 3 2 1\n2 3 2 1\n1 2 1 1"], "outputs": ["3\n2"]}
699
70
coding
Solve the programming task below in a Python markdown code block. This problem takes its name by arguably the most important event in the life of the ancient historian Josephus: according to his tale, he and his 40 soldiers were trapped in a cave by the Romans during a siege. Refusing to surrender to the enemy, they i...
{"functional": "_inputs = [[[1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 1], [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 2], [['C', 'o', 'd', 'e', 'W', 'a', 'r', 's'], 4], [['C', 0, 'd', 3, 'W', 4, 'r', 5], 4], [[1, 2, 3, 4, 5, 6, 7], 3], [[], 3], [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 2...
607
976
coding
Solve the programming task below in a Python markdown code block. You've got two numbers. As long as they are both larger than zero, they go through the same operation: subtract the lesser number from the larger one. If they equal substract one number from the another. For example, one operation transforms pair (4,17) ...
{"inputs": ["1\n920400783 7\n", "1\n718772242 7\n", "1\n718772242 8\n", "1\n718772242 3\n", "1\n718772242 5\n", "1\n589741341 5\n", "1\n589741341 9\n", "1\n459104377 9\n"], "outputs": ["131485833\n", "102681755\n", "89846534\n", "239590750\n", "143754452\n", "117948273\n", "65526818\n", "51011603\n"]}
242
227
coding
Solve the programming task below in a Python markdown code block. There are $n$ bulbs in a straight line, numbered from $\mbox{0}$ to $n-1$. Each bulb $\boldsymbol{i}$ has a button associated with it, and there is a cost, $c_i$, for pressing this button. When some button $\boldsymbol{i}$ is pressed, all the bulbs at a...
{"inputs": ["3 1\n1 1 1\n"], "outputs": ["1\n"]}
365
22
coding
Solve the programming task below in a Python markdown code block. Given an array $a$ of length $n$, you can do at most $k$ operations of the following type on it: choose $2$ different elements in the array, add $1$ to the first, and subtract $1$ from the second. However, all the elements of $a$ have to remain non-nega...
{"inputs": ["1\n3 1\n1 8 9\n", "1\n3 1\n3 1 9\n", "1\n3 1\n1 0 1\n", "2\n3 1\n3 1 4\n2 10\n1 0\n"], "outputs": ["0 8 10 \n", "2 1 10 \n", "0 0 2 \n", "2 1 5 \n0 1 \n"]}
438
114
coding
Solve the programming task below in a Python markdown code block. You are given two integers N and K. Find number of ordered triplets (A, B, C) that satisfy the following conditions: 0 ≀ A, B, C < 2^{N} A, B and C are distinct A \oplus B \oplus C = K Here, \oplus denotes the [bitwise XOR operation]. ------ Input Form...
{"inputs": ["3\n2 1\n3 0\n9 100\n"], "outputs": ["6\n42\n260610\n"]}
393
38
coding
Solve the programming task below in a Python markdown code block. Write a program which prints the central coordinate $(p_x, p_y)$ and the radius $r$ of a circumscribed circle of a triangle which is constructed by three points $(x_1, y_1)$, $(x_2, y_2)$ and $(x_3, y_3)$ on the plane surface. Constraints * $-100 \leq ...
{"inputs": ["1\n0.0 0.0 2.0 0.0 2.0 2.0", "1\n0.0 0.0 2.0 0.5127281311709682 2.0 2.0", "1\n0.0 0.0 2.4487612247110815 0.5127281311709682 2.0 2.0", "1\n0.0 0.0 2.4487612247110815 0.5127281311709682 2.0 2.033916337250816", "1\n0.0 0.8678187768154128 2.4487612247110815 0.5127281311709682 2.0 2.033916337250816", "1\n1.3652...
297
745
coding
Solve the programming task below in a Python markdown code block. For an integer N, we will choose a permutation \{P_1, P_2, ..., P_N\} of \{1, 2, ..., N\}. Then, for each i=1,2,...,N, let M_i be the remainder when i is divided by P_i. Find the maximum possible value of M_1 + M_2 + \cdots + M_N. -----Constraints----- ...
{"inputs": ["3", "4", "6", "0", "8", "9", "7", "2"], "outputs": ["3\n", "6\n", "15\n", "0\n", "28\n", "36\n", "21\n", "1"]}
217
65
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 of size n containing each element from 0 to n - 1 (inclusive). Each of the elements from 1 to n - 1 represents an item, and the element 0 represents an empty space. In one operation...
{"functional": "def check(candidate):\n assert candidate(nums = [4,2,0,3,1]) == 3\n assert candidate(nums = [1,2,3,4,0]) == 0\n assert candidate(nums = [1,0,2,4,3]) == 2\n\n\ncheck(Solution().sortArray)"}
204
79
coding
Solve the programming task below in a Python markdown code block. -----Problem Statement----- You all must have played the game candy crush. So here is a bomb which works much the fruit bomb in candy crush. A designer, Anton, designed a very powerful bomb. The bomb, when placed on a location $(x, y)$ in a $R \times C$ ...
{"inputs": ["2 3 3\n1 1\n0 0\n0 2"], "outputs": ["3"]}
421
28
coding
Solve the programming task below in a Python markdown code block. A balanced parenthesis string is defined as follows: - The empty string is balanced - If P is balanced, (P) is also - If P and Q are balanced, PQ is also balanced You are given two even integers n$n$ and k$k$. Find any balanced paranthesis string of len...
{"inputs": ["2\n4 2\n8 6"], "outputs": ["-1\n(())(())"]}
375
26
coding
Solve the programming task below in a Python markdown code block. In the advanced algorithm class, n2 students sit in n rows and n columns. One day, a professor who teaches this subject comes into the class, asks the shortest student in each row to lift up his left hand, and the tallest student in each column to lift u...
{"inputs": ["3\n1 2 3\n4 5 6\n7 5 9\n3\n1 2 3\n1 8 9\n4 5 6\n0", "3\n0 2 3\n4 5 7\n7 1 9\n3\n0 2 3\n7 8 6\n1 5 6\n0", "3\n1 1 3\n0 2 6\n7 9 9\n3\n1 4 3\n7 8 9\n4 8 6\n0", "3\n2 2 3\n4 4 6\n7 4 9\n3\n1 4 3\n7 8 9\n4 8 6\n0", "3\n1 2 3\n4 5 6\n7 8 9\n3\n1 2 3\n7 8 9\n4 5 6\n0", "3\n1 2 3\n4 5 6\n7 10 9\n3\n1 2 3\n7 8 9\n...
311
400
coding
Solve the programming task below in a Python markdown code block. # Description: Count the number of exclamation marks and question marks, return the product. # Examples ``` Product("") == 0 product("!") == 0 Product("!ab? ?") == 2 Product("!!") == 0 Product("!??") == 2 Product("!???") == 3 Product("!!!??") == 6 Pr...
{"functional": "_inputs = [[''], ['!'], ['!!??!!']]\n_outputs = [[0], [0], [8]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) != len(b): return False\...
143
166
coding
Solve the programming task below in a Python markdown code block. Kirill plays a new computer game. He came to the potion store where he can buy any potion. Each potion is characterized by two integersΒ β€” amount of experience and cost. The efficiency of a potion is the ratio of the amount of experience to the cost. Effi...
{"inputs": ["1 5 6 10 1", "4 5 1 2 3\n", "2 4 1 3 1\n", "4 5 1 2 2\n", "4 5 3 7 1\n", "1 1 1 1 1\n", "7 7 3 6 2\n", "5 5 1 6 2\n"], "outputs": ["NO", "NO\n", "YES\n", "YES\n", "YES\n", "YES\n", "NO\n", "NO\n"]}
287
133
coding
Solve the programming task below in a Python markdown code block. The Little Elephant from the Zoo of Lviv has an array A that consists of N positive integers. Let A[i] be the i-th number in this array (i = 1, 2, ..., N). Find the minimal number x > 1 such that x is a divisor of all integers from array A. More formall...
{"inputs": ["2\n2\n7 2 8\n3\n0 8 5", "2\n2\n2 0 8\n3\n0 0 9", "2\n2\n0 7 0\n3\n1 5 5", "2\n3\n6 0 3\n2\n1 4 2", "2\n2\n2 4 8\n3\n1 5 5", "2\n2\n2 4 4\n3\n1 5 5", "2\n2\n2 2 4\n3\n1 5 5", "2\n2\n2 2 8\n3\n1 5 5"], "outputs": ["-1\n-1\n", "2\n3\n", "7\n-1\n", "3\n-1\n", "2\n-1\n", "2\n-1\n", "2\n-1\n", "2\n-1\n"]}
508
214
coding
Solve the programming task below in a Python markdown code block. Give the summation of all even numbers in a Fibonacci sequence up to, but not including, the maximum value. The Fibonacci sequence is a series of numbers where the next value is the addition of the previous two values. The series starts with 0 and 1: 0...
{"functional": "_inputs = [[0], [10], [5], [100], [1000], [1000000], [100000000], [1000000000], [2147483647], [-1]]\n_outputs = [[0], [10], [2], [44], [798], [1089154], [82790070], [350704366], [1485607536], [0]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n ...
157
282
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You have a water dispenser that can dispense cold, warm, and hot water. Every second, you can either fill up 2 cups with different types of water, or 1 cup of any type of water. You are given a 0-indexed integer array...
{"functional": "def check(candidate):\n assert candidate(amount = [1,4,2]) == 4\n assert candidate(amount = [5,4,4]) == 7\n assert candidate(amount = [5,0,0]) == 5\n\n\ncheck(Solution().fillCups)"}
154
68
coding
Solve the programming task below in a Python markdown code block. You are both a shop keeper and a shop assistant at a small nearby shop. You have $n$ goods, the $i$-th good costs $a_i$ coins. You got tired of remembering the price of each product when customers ask for it, thus you decided to simplify your life. More...
{"inputs": ["1\n2\n75 2\n", "1\n2\n65 0\n", "1\n2\n777 1\n", "1\n2\n777 1\n", "1\n2\n386 1\n", "1\n2\n665 1\n", "1\n2\n449 1\n", "1\n2\n327 1\n"], "outputs": ["39\n", "33\n", "389\n", "389\n", "194\n", "333\n", "225\n", "164\n"]}
490
146
coding
Solve the programming task below in a Python markdown code block. $N$ persons visited a restaurant. The restaurant is open from 0 to $T$. The $i$-th person entered the restaurant at $l_i$ and left at $r_i$. Find the maximum number of persons during the business hours. Constraints * $ 1 \leq N \leq 10^5 $ * $ 1 \leq T...
{"inputs": ["2 4\n0 1\n1 2", "2 2\n0 0\n1 2", "2 4\n0 1\n1 3", "2 2\n1 1\n1 2", "2 4\n0 1\n1 1", "2 2\n0 0\n0 2", "2 4\n1 1\n1 3", "2 2\n1 1\n0 2"], "outputs": ["1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n"]}
229
142
coding
Solve the programming task below in a Python markdown code block. Word $s$ of length $n$ is called $k$-complete if $s$ is a palindrome, i.e. $s_i=s_{n+1-i}$ for all $1 \le i \le n$; $s$ has a period of $k$, i.e. $s_i=s_{k+i}$ for all $1 \le i \le n-k$. For example, "abaaba" is a $3$-complete word, while "abccba" i...
{"inputs": ["4\n6 2\nabaaba\n6 3\nabaaba\n36 9\nhippopotomonstrosesquippedaliophobia\n21 7\nwudixiaoxingxingheclp\n", "4\n6 2\nabaaba\n6 3\nabaaba\n36 9\nhippopotononstrosesquippedaliophobia\n21 7\nwudixiaoxingxingheclp\n", "4\n6 2\nabaaba\n6 3\nabaaba\n36 9\nhippopotomonstrosesquippedaliophobia\n21 3\nwudixiaoxingxing...
551
509
coding
Solve the programming task below in a Python markdown code block. Heiankyo is known as a town with a grid of roads. Hokusai, a cat who lives in Heiankyo, has to go from his home to a secret place on the outskirts of town every day for patrol. However, I get tired of following the same path every day, and there is a ri...
{"inputs": ["4\n2 2\n0\n1 2\n2\n0 0 0 1\n0 0 1 0\n4 3\n4\n1 0 0 0\n3 3 2 3\n4 0 4 0\n0 2 0 3\n1 3\n0", "4\n2 2\n0\n0 2\n2\n0 0 0 1\n0 0 2 0\n2 3\n4\n1 0 0 0\n3 1 4 3\n5 0 1 0\n0 2 0 3\n3 4\n0", "4\n3 2\n0\n0 2\n2\n0 0 0 1\n0 0 1 0\n2 3\n4\n1 0 0 0\n3 1 4 3\n7 0 1 0\n0 2 0 1\n5 3\n0", "4\n3 2\n0\n0 2\n2\n0 0 0 1\n0 0 1 ...
629
752
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. No-Zero integer is a positive integer that does not contain any 0 in its decimal representation. Given an integer n, return a list of two integers [a, b] where: a and b are No-Zero integers. a + b = n The test cases...
{"functional": "def check(candidate):\n assert candidate(n = 2) == [1,1]\n assert candidate(n = 11) == [2,9]\n assert candidate(n = 10000) == [1,9999]\n assert candidate(n = 69) == [1,68]\n assert candidate(n = 1010) == [11,999]\n\n\ncheck(Solution().getNoZeroIntegers)"}
133
113
coding
Solve the programming task below in a Python markdown code block. Chef has the binary representation S of a number X with him. He can modify the number by applying the following operation exactly once: Make X := X \oplus \lfloor \frac{X}{2^{Y}} \rfloor, where (1 ≀ Y ≀ |S|) and \oplus denotes the [bitwise XOR operation]...
{"inputs": ["4\n2\n10\n2\n11\n3\n101\n3\n110\n"], "outputs": ["1\n2\n1\n2\n"]}
683
42
coding
Solve the programming task below in a Python markdown code block. Chef is an advocate for Go Green Initiative. Today he had n trees planted in a row outside his his restaurant. Today, the height of i-th tree is hi feet. The trees grow at a rate of mi feet per day. Chef knows that trees will look beautiful if they form ...
{"inputs": ["3\n3\n0 1\n2 2\n0 3\n2\n2 1\n1 2\n3\n1 1\n2 2\n3 3"], "outputs": ["1\n0 1\n2\n0 0\n2 Inf\n0"]}
574
65
coding
Solve the programming task below in a Python markdown code block. *** No Loops Allowed *** You will be given an array (a) and a limit value (limit). You must check that all values in the array are below or equal to the limit value. If they are, return true. Else, return false. You can assume all values in the array a...
{"functional": "_inputs = [[[66, 101], 200], [[78, 117, 110, 99, 104, 117, 107, 115], 100], [[101, 45, 75, 105, 99, 107], 107], [[80, 117, 115, 104, 45, 85, 112, 115], 120]]\n_outputs = [[True], [False], [True], [True]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n ...
168
293
coding
Solve the programming task below in a Python markdown code block. You have two strings, $a$ and $\boldsymbol{b}$. Find a string, $\boldsymbol{\mathrm{~S~}}$, such that: $\boldsymbol{\mathrm{~S~}}$ can be expressed as $s=s_{a}+s_{b}$ where $\boldsymbol{s_{a}}$ is a non-empty substring of $a$ and $s_{b}$ is a non-empty ...
{"inputs": ["3\nbac\nbac\nabc\ndef\njdfh\nfds\n"], "outputs": ["aba\n-1\ndfhfd\n"]}
625
35
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. There are $N$ people on a street (numbered $1$ through $N$). For simplicity, we'll view them as points on a line. For each valid $i$, the position of...
{"inputs": ["3\n2\n3 6\n3\n1 3 5\n5\n1 2 5 6 7"], "outputs": ["1 1\n3 3\n2 3"]}
632
48
coding
Solve the programming task below in a Python markdown code block. You are given a spreadsheet that contains a list of $N$ athletes and their details (such as age, height, weight and so on). You are required to sort the data based on the $K^{th}$ attribute and print the final resulting table. Follow the example given be...
{"inputs": ["5 3\n10 2 5\n7 1 0\n9 9 9\n1 23 12\n6 5 9\n1\n"], "outputs": ["7 1 0\n10 2 5\n6 5 9\n9 9 9\n1 23 12\n"]}
375
82
coding
Solve the programming task below in a Python markdown code block. A queen is the strongest chess piece. In modern chess the queen can move any number of squares in any horizontal, vertical or diagonal direction (considering that there're no other pieces on its way). The queen combines the options given to the rook and ...
{"inputs": ["2 1\n1 1\n", "1 1\n1 1\n", "2 2\n1 1\n1 2\n", "20 3\n1 1\n1 2\n1 3\n", "38 3\n1 1\n1 2\n1 3\n", "10 3\n1 1\n1 2\n1 3\n", "2 4\n2 1\n1 2\n2 2\n1 1\n", "8 4\n4 3\n8 8\n6 5\n1 6\n"], "outputs": ["1 0 0 0 0 0 0 0 0\n", "1 0 0 0 0 0 0 0 0\n", "0 2 0 0 0 0 0 0 0\n", "0 2 1 0 0 0 0 0 0\n", "0 2 1 0 0 0 0 0 0\n", ...
458
301
coding
Solve the programming task below in a Python markdown code block. In a small restaurant there are a tables for one person and b tables for two persons. It it known that n groups of people come today, each consisting of one or two people. If a group consist of one person, it is seated at a vacant one-seater table. I...
{"inputs": ["1 1 1\n1\n", "1 1 1\n1\n", "1 1 1\n2\n", "1 1 1\n1\n", "1 1 1\n2\n", "1 0 1\n1\n", "1 0 1\n2\n", "2 1 2\n2 2\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]}
562
120
coding
Solve the programming task below in a Python markdown code block. The town sheriff dislikes odd numbers and wants all odd numbered families out of town! In town crowds can form and individuals are often mixed with other people and families. However you can distinguish the family they belong to by the number on the shir...
{"functional": "_inputs = [[[1, 2, 3, 1, 3, 3]], [[75, 68, 75, 47, 68]], [[42, 72, 32, 4, 94, 82, 67, 67]], [[100, 100, 5, 5, 100, 50, 68, 50, 68, 50, 68, 5, 100]], [[82, 86, 71, 58, 44, 79, 50, 44, 79, 67, 82, 82, 55, 50]]]\n_outputs = [[[1, 1]], [[75, 68, 75, 68]], [[67, 67]], [[100, 100, 100, 100]], [[44, 79, 50, 44...
430
403
coding
Solve the programming task below in a Python markdown code block. Adam Ivan is working as a system administrator at Soy Group, Inc. He is now facing at a big trouble: a number of computers under his management have been infected by a computer virus. Unfortunately, anti-virus system in his company failed to detect this ...
{"inputs": ["3 2\n1 1 3\n2 2 3\n3 2\n2 3 2\n1 2 1\n0 0", "3 2\n1 1 2\n2 2 3\n3 2\n2 3 2\n1 2 0\n0 0", "4 2\n1 0 3\n1 2 3\n3 2\n2 3 2\n2 2 1\n0 0", "3 2\n1 1 3\n1 2 3\n3 2\n2 1 2\n1 2 0\n0 0", "3 2\n1 0 3\n1 2 3\n3 2\n2 1 2\n1 2 0\n0 0", "3 2\n1 1 3\n1 2 3\n3 2\n2 3 2\n1 2 1\n0 0", "3 2\n1 1 3\n1 2 3\n3 2\n3 3 2\n1 2 1\...
464
350
coding
Solve the programming task below in a Python markdown code block. One day John had to take care of his little nephew Jim. He was very busy, so he gave Jim a big bag full of building bricks. The bricks are of various heights: at most 15 different heights. For each height, the bag contains infinitely many bricks. Now, ...
{"inputs": ["10\n1\n1\n", "5\n2\n2 3\n", "19\n2\n4 5\n"], "outputs": ["2\n", "4\n", "8\n"]}
598
48
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it can trap after raining. Β  Please complete the following python code precisely: ```python class So...
{"functional": "def check(candidate):\n assert candidate(height = [0,1,0,2,1,0,1,3,2,1,2,1]) == 6\n assert candidate(height = [4,2,0,3,2,5]) == 9\n\n\ncheck(Solution().trap)"}
76
74
coding
Solve the programming task below in a Python markdown code block. The string $s$ is given, the string length is odd number. The string consists of lowercase letters of the Latin alphabet. As long as the string length is greater than $1$, the following operation can be performed on it: select any two adjacent letters i...
{"inputs": ["1\nwabalabadubdu\nw\n", "1\nasdfghjklqwertyuiop\ne\n", "1\nasdfghjklqwertyuiop\nf\n", "1\nadsfdxvxvsdfdgxcvsdfd\nc\n", "1\nhghjhgvdvkhbgtftfvgvp\nj\n", "1\nqwertyuioppoiuytrewqplkmnjiuhbs\nz\n", "5\nabcde\nc\nabcde\nb\nx\ny\nabobobussss\ns\ncontest\nt\n", "5\nabcde\nc\nabcde\nb\nx\ny\naaaaaaaaaaaaaaa\na\nc...
603
213
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an array of integers nums represents the numbers written on a chalkboard. Alice and Bob take turns erasing exactly one number from the chalkboard, with Alice starting first. If erasing a number causes th...
{"functional": "def check(candidate):\n assert candidate(nums = [1,1,2]) == False\n assert candidate(nums = [0,1]) == True\n assert candidate(nums = [1,2,3]) == True\n\n\ncheck(Solution().xorGame)"}
182
62
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. There is an n x n 0-indexed grid with some artifacts buried in it. You are given the integer n and a 0-indexed 2D integer array artifacts describing the positions of the rectangular artifacts where artifacts[i] = [r1i...
{"functional": "def check(candidate):\n assert candidate(n = 2, artifacts = [[0,0,0,0],[0,1,1,1]], dig = [[0,0],[0,1]]) == 1\n assert candidate(n = 2, artifacts = [[0,0,0,0],[0,1,1,1]], dig = [[0,0],[0,1],[1,1]]) == 2\n\n\ncheck(Solution().digArtifacts)"}
305
108
coding
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin chinese, Russian and Vietnamese as well. You are given a string $S$ of lowercase English letters with length $N$. You are allowed to (but don't have to) choose one index in this string and change the letter at this ...
{"inputs": ["3\nabcd\ndbca\ndcba"], "outputs": ["6\n1\n0"]}
389
25
coding
Solve the programming task below in a Python markdown code block. Adding tip to a restaurant bill in a graceful way can be tricky, thats why you need make a function for it. The function will receive the restaurant bill (always a positive number) as an argument. You need to 1) **add at least 15%** in tip, 2) round tha...
{"functional": "_inputs = [[1], [7], [12], [86], [99], [1149], [983212]]\n_outputs = [[2], [9], [15], [100], [150], [1500], [1500000]]\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, (lis...
277
218
coding
Solve the programming task below in a Python markdown code block. You have to restore the wall. The wall consists of $N$ pillars of bricks, the height of the $i$-th pillar is initially equal to $h_{i}$, the height is measured in number of bricks. After the restoration all the $N$ pillars should have equal heights. You...
{"inputs": ["1 0 0 0\n0\n", "1 0 0 0\n1\n", "1 0 0 1\n1\n", "2 0 0 0\n1 1\n", "2 0 0 0\n2 1\n", "2 0 0 0\n0 1\n", "2 0 0 1\n0 1\n", "2 0 0 1\n-1 1\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]}
440
145
coding
Solve the programming task below in a Python markdown code block. A notice on the notice board read: β€œIs there an end to it? While the number remains greater than one, if 2 divides the number completely, divide the number by 2; while the number remains greater than 1, if the number is not divisible by 2 , multiply th...
{"inputs": ["0", "1", "16"], "outputs": ["No", "Yes", "Yes"]}
152
25
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You have a list arr of all integers in the range [1, n] sorted in a strictly increasing order. Apply the following algorithm on arr: Starting from left to right, remove the first number and every other number afterwa...
{"functional": "def check(candidate):\n assert candidate(n = 9) == 6\n assert candidate(n = 1) == 1\n\n\ncheck(Solution().lastRemaining)"}
164
43
coding
Solve the programming task below in a Python markdown code block. There is a strange game played in ChefLand. The game starts with N white balls, the i-th of which has a power of S_{i}. It is known that 0 ≀ S_{i} ≀ 9. On each level, a black ball with power K hits each of the white balls. After the collision, the powe...
{"inputs": ["3\n4 9 2\n5418\n5 63 3\n40514\n1 100000 100000\n0"], "outputs": ["14\n88\n1\n"]}
646
61