problem
stringlengths
14
4.09k
solution
stringlengths
1
802k
task_type
stringclasses
3 values
problem_tokens
int64
5
895
Solve the programming task below in a Python markdown code block. Gildong has bought a famous painting software cfpaint. The working screen of cfpaint is square-shaped consisting of $n$ rows and $n$ columns of square cells. The rows are numbered from $1$ to $n$, from top to bottom, and the columns are numbered from $1$...
{"inputs": ["1 1\nB\n", "1 1\nW\n", "1 1\nW\n", "1 1\nB\n", "2 2\nBW\nWB\n", "2 1\nWW\nWW\n", "2 1\nBB\nWW\n", "2 1\nBB\nBB\n"], "outputs": ["2\n", "2\n", "2\n", "2\n", "4\n", "4\n", "2\n", "0\n"]}
coding
721
Solve the programming task below in a Python markdown code block. Kulyash stays in room that has a single bulb and N buttons. The bulb is initially on. The initial states of the buttons are stored in a binary string S of length N — if S_{i} is 0, the i-th button is off, and if S_{i} is 1, the i-th button is on. If Kul...
{"inputs": ["2\n3\n000\n001\n2\n00\n11\n"], "outputs": ["0\n1\n"]}
coding
450
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin Chinese and Russian. Tanu has got interested in signs and gestures that we use for communication. One such gesture is the head-bob. When we want to signal "Yes" to someone, we move the head up-and-down. For "No", t...
{"inputs": ["3\n5\nNNNYY\n6\nNNINNI\n4\nNNNN"], "outputs": ["NOT INDIAN\nINDIAN\nNOT SURE"]}
coding
407
Solve the programming task below in a Python markdown code block. Problem N idols, numbered from 1 to n in order, are lined up in a row. Idle i can transmit information to idle i-1 and idle i + 1 in a unit time. However, idol 1 can transmit information only to idol 2, and idol n can transmit information only to idol n...
{"inputs": ["6 2\n1 3", "3 2\n1 3", "8 1\n2 2 7", "8 3\n2 2 7", "2 1\n2 2 8", "2 1\n2 2 3", "2 2\n2 2 3", "0 1\n1 3 3"], "outputs": ["3\n", "1", "6\n", "2\n", "1\n", "1\n", "1\n", "0\n"]}
coding
313
Solve the programming task below in a Python markdown code block. Igor has fallen in love with Tanya. Now Igor wants to show his feelings and write a number on the fence opposite to Tanya's house. Igor thinks that the larger the number is, the more chance to win Tanya's heart he has. Unfortunately, Igor could only ge...
{"inputs": ["5\n5 4 3 2 1 2 3 4 5\n", "0\n1 1 1 1 1 1 1 1 1\n", "5\n5 4 3 2 1 4 3 4 5\n", "0\n1 1 1 1 1 1 1 1 1\n", "5\n5 4 3 2 1 2 3 4 5\n", "50\n5 3 10 2 2 4 3 6 5\n", "50\n5 3 10 2 2 4 3 6 5\n", "50\n5 3 10 2 2 5 3 6 5\n"], "outputs": ["55555\n", "-1\n", "55555\n", "-1\n", "55555\n", "5555555555555555555555555\n", "...
coding
311
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"]}
coding
457
Solve the programming task below in a Python markdown code block. Polycarp had an array $a$ of $3$ positive integers. He wrote out the sums of all non-empty subsequences of this array, sorted them in non-decreasing order, and got an array $b$ of $7$ integers. For example, if $a = \{1, 4, 3\}$, then Polycarp wrote out ...
{"inputs": ["1\n1 2 3 69696875 69696876 69696877 69696878\n", "1\n1 1 2 69696880 69696881 69696881 69696882\n", "1\n1 2 3 69696887 69696888 69696889 69696890\n", "1\n1 1 2 69696883 69696884 69696884 69696885\n", "1\n1 1 2 69696884 69696885 69696885 69696886\n", "1\n1 1 2 69696880 69696881 69696881 69696882\n", "1\n1 2 ...
coding
681
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin Chinese and Russian. Lira loves Linear Algebra and she is especially keen about matrix :). Today, she learnt some properties about matrices, namely, she learnt about what the trace of a matrix is, as her teacher ga...
{"inputs": ["1\n3"], "outputs": ["2"]}
coding
374
Solve the programming task below in a Python markdown code block. While dad was at work, a little girl Tanya decided to play with dad's password to his secret database. Dad's password is a string consisting of n + 2 characters. She has written all the possible n three-letter continuous substrings of the password on pie...
{"inputs": ["1\nabc\n", "1\nacc\n", "1\nbac\n", "1\naac\n", "1\ncaa\n", "2\nbba\nabb\n", "2\nabc\nbga\n", "2\naba\naba\n"], "outputs": ["YES\nabc\n", "YES\nacc\n", "YES\nbac\n", "YES\naac\n", "YES\ncaa\n", "YES\nabba\n", "NO\n", "NO\n"]}
coding
384
Solve the programming task below in a Python markdown code block. While purchasing certain items, a discount of 10% is offered if the quantity purchased is more than 1000. If the quantity and price per item are input, write a program to calculate the total expenses. ------ Input Format ------ The first line contain...
{"inputs": ["3 \n100 4\n31 36\n390 40", "3 \n100 4\n31 36\n441 40", "3 \n001 215\n10 20\n25 19", "3 \n001 215\n10 22\n25 19", "3 \n001 215\n10 29\n25 19", "3 \n100 17\n16 36\n390 40", "3 \n011 15\n10 20\n128 42", "3 \n001 215\n10 41\n25 19"], "outputs": ["400.000000\n1116.000000\n15600.000000\n", "400.000000\n1116.0000...
coding
218
Solve the programming task below in a Python markdown code block. Petya started to attend programming lessons. On the first lesson his task was to write a simple program. The program was supposed to do the following: in the given string, consisting if uppercase and lowercase Latin letters, it: * deletes all the vow...
{"inputs": ["g\n", "D\n", "h\n", "Ba\n", "ab\n", "aB\n", "bA\n", "Ab\n"], "outputs": [".g\n", ".d\n", ".h\n", ".b\n", ".b\n", ".b\n", ".b\n", ".b\n"]}
coding
257
Solve the programming task below in a Python markdown code block. Daisy loves playing games with words. Recently, she has been playing the following Deletive Editing word game with Daniel. Daisy picks a word, for example, "DETERMINED". On each game turn, Daniel calls out a letter, for example, 'E', and Daisy removes t...
{"inputs": ["10\nGK GK\nF F\nH D\nZQ QZ\nC C\nFN NF\nS S\nC C\nEM C\nXO C\n", "6\nDETERMINED TRME\nDETERMINED TERM\nPSEUDOPSEUDOHYPOPARATHYROIDISM PEPA\nDEINSTITUTIONALIZATION DONATION\nCONTEST CODE\nSOLUTION SOLUTION\n"], "outputs": ["YES\nYES\nNO\nNO\nYES\nNO\nYES\nYES\nNO\nNO\n", "YES\nNO\nNO\nYES\nNO\nYES\n"]}
coding
485
Solve the programming task below in a Python markdown code block. Gru has a string $S$ of length $N$, consisting of only characters $a$ and $b$ for banana and $P$ points to spend. Now Gru wants to replace and/or re-arrange characters of this given string to get the lexicographically smallest string possible. For this, ...
{"inputs": ["1\n3 3\nbba"], "outputs": ["aab"]}
coding
389
Solve the programming task below in a Python markdown code block. Let's denote a function $d(x, y) = \left\{\begin{array}{ll}{y - x,} & {\text{if}|x - y|> 1} \\{0,} & {\text{if}|x - y|\leq 1} \end{array} \right.$ You are given an array a consisting of n integers. You have to calculate the sum of d(a_{i}, a_{j}) over...
{"inputs": ["1\n1\n", "1\n1\n", "1\n0\n", "1\n2\n", "1\n4\n", "1\n5\n", "1\n-1\n", "1\n-2\n"], "outputs": ["0\n", "0", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]}
coding
442
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given the root of a binary tree, return the maximum width of the given tree. The maximum width of a tree is the maximum width among all levels. The width of one level is defined as the length between the end-nodes (th...
{"functional": "def check(candidate):\n assert candidate(root = tree_node([1,3,2,5,3,None,9])) == 4\n assert candidate(root = tree_node([1,3,2,5,None,None,9,6,None,7])) == 7\n assert candidate(root = tree_node([1,3,2,5])) == 2\n\n\ncheck(Solution().widthOfBinaryTree)"}
coding
209
Solve the programming task below in a Python markdown code block. A Train started its journey at x=-infinity is travelling on the x-Coordinate Axis. Given n passengers and the coordinates $b_i$ and $d_i$ for each of the $ith$ passenger at which they board and leave from the train respectively. Due to current COVID-19 c...
{"inputs": ["3\n0 2\n1 3\n-1 4"], "outputs": ["12"]}
coding
446
Solve the programming task below in a Python markdown code block. Jamie loves sleeping. One day, he decides that he needs to wake up at exactly hh: mm. However, he hates waking up, so he wants to make waking up less painful by setting the alarm at a lucky time. He will then press the snooze button every x minutes until...
{"inputs": ["1\n2 00\n", "2\n1 23\n", "3\n11 23\n", "5\n01 07\n", "2\n14 37\n", "3\n12 15\n", "9\n16 53\n", "5\n13 10\n"], "outputs": ["3\n", "3\n", "2\n", "0\n", "0\n", "6\n", "4\n", "63\n"]}
coding
449
Solve the programming task below in a Python markdown code block. Write a function that takes an arbitrary number of strings and interlaces them (combines them by alternating characters from each string). For example `combineStrings('abc', '123')` should return `'a1b2c3'`. If the strings are different lengths the fun...
{"functional": "_inputs = [['abc'], ['abc', '123'], ['abcd', '123'], ['abc', '1234'], ['abc', '123', '$%'], ['abcd', '123', '$%'], ['abcd', '123', '$%^&'], ['abcd', '123', '$%^&', 'qwertyuiop'], ['abcd', '123', '$%^&', 'qwertyuiop', 'X']]\n_outputs = [['abc'], ['a1b2c3'], ['a1b2c3d'], ['a1b2c34'], ['a1$b2%c3'], ['a1$b2...
coding
206
Solve the programming task below in a Python markdown code block. Shell Sort Shell Sort is a generalization of Insertion Sort to arrange a list of $n$ elements $A$. 1 insertionSort(A, n, g) 2 for i = g to n-1 3 v = A[i] 4 j = i - g 5 while j >= 0 && A[j] > v 6 A[j+g] = A...
{"inputs": ["3\n6\n2\n1", "3\n0\n2\n1", "3\n0\n2\n0", "3\n0\n1\n0", "3\n1\n1\n0", "3\n1\n8\n0", "3\n1\n8\n1", "3\n1\n1\n1"], "outputs": ["1\n1\n3\n1\n2\n6\n", "1\n1\n1\n0\n1\n2\n", "1\n1\n1\n0\n0\n2\n", "1\n1\n1\n0\n0\n1\n", "1\n1\n2\n0\n1\n1\n", "1\n1\n2\n0\n1\n8\n", "1\n1\n1\n1\n1\n8\n", "1\n1\n0\n1\n1\n1\n"]}
coding
595
Solve the programming task below in a Python markdown code block. Sort array by last character Complete the function to sort a given array or list by last character of elements. ```if-not:haskell Element can be an integer or a string. ``` ### Example: ``` ['acvd', 'bcc'] --> ['bcc', 'acvd'] ``` The last characte...
{"functional": "_inputs = [[['acvd', 'bcc']], [['14', '13']], [['asdf', 'asdf', '14', '13']], [['bsde', 'asdf', 14, '13']], [['asdf', 14, '13', 'asdf']]]\n_outputs = [[['bcc', 'acvd']], [['13', '14']], [['13', '14', 'asdf', 'asdf']], [['13', 14, 'bsde', 'asdf']], [['13', 14, 'asdf', 'asdf']]]\nimport math\ndef _deep_eq...
coding
179
Solve the programming task below in a Python markdown code block. Rahul is assigned a task by his fellow mates.He has to take a string from somewhere and first of all he has to calculate the weight of that string.The weight of string is calculated by adding the ASCII values of each characters in that string and then di...
{"inputs": ["Hello", "Worldd", "Hello World"], "outputs": ["olleH", "d", "l"]}
coding
237
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a 0-indexed integer array nums of length n and an integer k, return the number of pairs (i, j) where 0 <= i < j < n, such that nums[i] == nums[j] and (i * j) is divisible by k.   Please complete the following py...
{"functional": "def check(candidate):\n assert candidate(nums = [3,1,2,2,2,1,3], k = 2) == 4\n assert candidate(nums = [1,2,3,4], k = 1) == 0\n\n\ncheck(Solution().countPairs)"}
coding
109
Solve the programming task below in a Python markdown code block. We have a square grid with N rows and M columns. Takahashi will write an integer in each of the squares, as follows: * First, write 0 in every square. * For each i=1,2,...,N, choose an integer k_i (0\leq k_i\leq M), and add 1 to each of the leftmost k_i...
{"inputs": ["4 3", "2 2", "1 3", "2 4", "0 3", "2 8", "1 8", "1 6"], "outputs": ["15584\n", "47\n", "20\n", "1053\n", "1\n", "257337\n", "1280\n", "256\n"]}
coding
345
Solve the programming task below in a Python markdown code block. Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well. [Flappy Bird] is on a screen with height $H$ pixels (a 2D plane where the $y$-axis corresponds to the vertical direction). There are $N$ vertical ob...
{"inputs": ["1\n10 4\n0 2 5\n1 5 6\n1 8 8\n0 11 2"], "outputs": ["2 3 2 3"]}
coding
635
Solve the programming task below in a Python markdown code block. In input string ```word```(1 word): * replace the vowel with the nearest left consonant. * replace the consonant with the nearest right vowel. P.S. To complete this task imagine the alphabet is a circle (connect the first and last element of the array i...
{"functional": "_inputs = [['cat'], ['codewars'], ['abcdtuvwxyz']]\n_outputs = [['ezu'], ['enedazuu'], ['zeeeutaaaaa']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n ...
coding
292
Solve the programming task below in a Python markdown code block. CODE FESTIVAL 2016 is going to be held. For the occasion, Mr. Takahashi decided to make a signboard. He intended to write `CODEFESTIVAL2016` on it, but he mistakenly wrote a different string S. Fortunately, the string he wrote was the correct length. S...
{"inputs": ["C0DEFESTIVAL2O61", "EDOC6102LAVITSEF", "C0DEFERTIVAL2O61", "C0DEGERTIVAL2O61", "CTDEGER0IVAL2O61", "CT/EGERDIVAL2O61", "CT0EGERDIVAK2O61", "1DO2LAVI6REGE0TC"], "outputs": ["4\n", "16\n", "5\n", "6\n", "7\n", "8\n", "9\n", "15\n"]}
coding
220
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an array of integers arr, return true if the number of occurrences of each value in the array is unique or false otherwise.   Please complete the following python code precisely: ```python class Solution: de...
{"functional": "def check(candidate):\n assert candidate(arr = [1,2,2,1,1,3]) == True\n assert candidate(arr = [1,2]) == False\n assert candidate(arr = [-3,0,1,-3,1,1,1,-3,10,0]) == True\n\n\ncheck(Solution().uniqueOccurrences)"}
coding
74
Solve the programming task below in a Python markdown code block. Chef is given a number in form of its binary representation S, having length N. Determine if the number can be represented as a sum of exactly three non-negative powers of 2. Please refer to samples for further explanation. Note that S will NOT contain...
{"inputs": ["4\n1\n1\n4\n1001\n5\n11001\n7\n1101101\n"], "outputs": ["NO\nYES\nYES\nNO\n"]}
coding
507
Solve the programming task below in a Python markdown code block. re.findall() The expression re.findall() returns all the non-overlapping matches of patterns in a string as a list of strings. Code >>> import re >>> re.findall(r'\w','http://www.hackerrank.com/') ['h', 't', 't', 'p', 'w', 'w', 'w', 'h', 'a', 'c', 'k...
{"inputs": ["rabcdeefgyYhFjkIoomnpOeorteeeeet\n"], "outputs": ["ee\nIoo\nOeo\neeeee\n"]}
coding
587
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given two strings s and t, return true if they are both one edit distance apart, otherwise return false. A string s is said to be one distance apart from a string t if you can: Insert exactly one character into s to ...
{"functional": "def check(candidate):\n assert candidate(s = \"ab\", t = \"acb\") == True\n assert candidate(s = \"cab\", t = \"ad\") == False\n\n\ncheck(Solution().isOneEditDistance)"}
coding
127
Solve the programming task below in a Python markdown code block. A Little Elephant from the Zoo of Lviv likes lucky strings, i.e., the strings that consist only of the lucky digits 4 and 7. The Little Elephant calls some string T of the length M balanced if there exists at least one integer X (1 ≤ X ≤ M) such that the...
{"inputs": ["4\n47\n74\n477\n4747477\n\n"], "outputs": ["2\n2\n3\n23"]}
coding
606
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a string s and array queries where queries[i] = [lefti, righti, ki]. We may rearrange the substring s[lefti...righti] for each query and then choose up to ki of them to replace with any lowercase English...
{"functional": "def check(candidate):\n assert candidate(s = \"abcda\", queries = [[3,3,0],[1,2,0],[0,3,1],[0,3,2],[0,4,1]]) == [True,False,False,True,True]\n\n\ncheck(Solution().canMakePaliQueries)"}
coding
215
Solve the programming task below in a Python markdown code block. Sumit and Dhiraj are roommates in a hostel of NIT Jamshedpur,One day after completing there boring assignments of Artificial Intelligence, they decided to play a game as it was dhiraj,s idea to play a game so he started explaining the rules of the game t...
{"inputs": ["2\n4\n5"], "outputs": ["YES\nNO"]}
coding
360
Solve the programming task below in a Python markdown code block. You've just recently been hired to calculate scores for a Dart Board game! Scoring specifications: * 0 points - radius above 10 * 5 points - radius between 5 and 10 inclusive * 10 points - radius less than 5 **If all radii are less than 5, award 100 ...
{"functional": "_inputs = [[[1, 5, 11]], [[15, 20, 30, 31, 32, 44, 100]], [[1, 2, 3, 4]], [[]], [[1, 2, 3, 4, 5, 6, 7, 8, 9]], [[0, 5, 10, 10.5, 4.5]], [[1]], [[21, 10, 10]], [[5, 5, 5, 5]], [[4.9, 5.1]]]\n_outputs = [[15], [0], [140], [0], [65], [30], [110], [10], [20], [15]]\nimport math\ndef _deep_eq(a, b, tol=1e-5)...
coding
156
Solve the programming task below in a Python markdown code block. Given an array of ints, return the index such that the sum of the elements to the right of that index equals the sum of the elements to the left of that index. If there is no such index, return `-1`. If there is more than one such index, return the left-...
{"functional": "_inputs = [[[1, 2, 3, 5, 3, 2, 1]], [[1, 12, 3, 3, 6, 3, 1]], [[10, 20, 30, 40]]]\n_outputs = [[3], [2], [-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_tol=tol)\n if isinstance(a, (list, tuple...
coding
274
Solve the programming task below in a Python markdown code block. We conducted a survey on newspaper subscriptions. More specifically, we asked each of the N respondents the following two questions: * Question 1: Are you subscribing to Newspaper X? * Question 2: Are you subscribing to Newspaper Y? As the result, A ...
{"inputs": ["0 2 1", "0 3 1", "0 3 2", "1 3 2", "2 3 1", "1 5 0", "1 3 0", "10 2 5"], "outputs": ["1 3\n", "1 4\n", "2 5\n", "2 4\n", "1 2\n", "0 4\n", "0 2\n", "2 0\n"]}
coding
266
Solve the programming task below in a Python markdown code block. Given the list of numbers, you are to sort them in non decreasing order. -----Input----- t – the number of numbers in list, then t lines follow [t <= 10^6]. Each line contains one integer: N [0 <= N <= 10^6] -----Output----- Output given numbers in n...
{"inputs": ["5\n5\n3\n6\n7\n1", "5\n5\n3\n3\n7\n1", "5\n0\n3\n3\n7\n1", "5\n1\n3\n3\n7\n1", "5\n1\n3\n3\n7\n2", "5\n1\n1\n3\n7\n2", "5\n1\n2\n4\n1\n1", "5\n1\n2\n4\n1\n0"], "outputs": ["1\n3\n5\n6\n7", "1\n3\n3\n5\n7\n", "0\n1\n3\n3\n7\n", "1\n1\n3\n3\n7\n", "1\n2\n3\n3\n7\n", "1\n1\n2\n3\n7\n", "1\n1\n1\n2\n4\n", "0\n...
coding
112
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given two integers, n and k. An array of distinct positive integers is called a k-avoiding array if there does not exist any pair of distinct elements that sum to k. Return the minimum possible sum of a k-avoi...
{"functional": "def check(candidate):\n assert candidate(n = 5, k = 4) == 18\n assert candidate(n = 2, k = 6) == 3\n\n\ncheck(Solution().minimumSum)"}
coding
107
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin Chinese and Russian. Rupsa recently started to intern under Chef. He gave her N type of ingredients of varying quantity A_{1}, A_{2}, ..., A_{N} respectively to store it. But as she is lazy to arrange them she put...
{"inputs": ["2\n2\n2 2\n1\n6", "2\n2\n2 1\n1\n6", "2\n2\n2 2\n1\n8", "2\n2\n4 2\n1\n6", "2\n1\n2 1\n1\n1", "2\n3\n3 2\n1\n8", "2\n3\n4 2\n0\n1", "2\n3\n4 7\n0\n6"], "outputs": ["4\n2", "-1\n2\n", "4\n2\n", "6\n2\n", "-1\n-1\n", "5\n2\n", "6\n-1\n", "9\n2\n"]}
coding
469
Solve the programming task below in a Python markdown code block. In africa jungle , there were zebra's who liked to spit. There owner watched them for whole day and noted in his sheet where each zebra spitted. Now he's in a confusion and wants to know if in the jungle there are two zebra's which spitted at each other....
{"inputs": ["2\n0 1\n1 -1"], "outputs": ["YES"]}
coding
292
Solve the programming task below in a Python markdown code block. Ivan decided to prepare for the test on solving integer equations. He noticed that all tasks in the test have the following form: You are given two positive integers $u$ and $v$, find any pair of integers (not necessarily positive) $x$, $y$, such that: ...
{"inputs": ["4\n1 1\n2 3\n3 5\n6 9\n", "1\n144266828 777818251\n"], "outputs": ["-1 1\n-4 9\n-9 25\n-36 81\n", "-20812917661181584 605001231588699001\n"]}
coding
540
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a string containing digits from 2-9 inclusive, return all possible letter combinations that the number could represent. Return the answer in any order. A mapping of digits to letters (just like on the telephone ...
{"functional": "def check(candidate):\n assert candidate(digits = \"23\") == [\"ad\",\"ae\",\"af\",\"bd\",\"be\",\"bf\",\"cd\",\"ce\",\"cf\"]\n assert candidate(digits = \"\") == []\n assert candidate(digits = \"2\") == [\"a\",\"b\",\"c\"]\n\n\ncheck(Solution().letterCombinations)"}
coding
108
Solve the programming task below in a Python markdown code block. Given are integers L and R. Find the number, modulo 10^9 + 7, of pairs of integers (x, y) (L \leq x \leq y \leq R) such that the remainder when y is divided by x is equal to y \mbox{ XOR } x.What is \mbox{ XOR }? The XOR of integers A and B, A \mbox{ XO...
{"inputs": ["3 3", "3 0", "2 5", "3 4", "4 5", "2 3", "2 3\n", "1 1\n"], "outputs": ["1\n", "0\n", "6\n", "2\n", "3\n", "3", "3\n", "1\n"]}
coding
341
Solve the programming task below in a Python markdown code block. You are given three piles of casino chips: white, green and black chips: * the first pile contains only white chips * the second pile contains only green chips * the third pile contains only black chips Each day you take exactly two chips of different ...
{"functional": "_inputs = [[[1, 1, 1]], [[1, 2, 1]], [[4, 1, 1]], [[8, 2, 8]], [[8, 1, 4]], [[7, 4, 10]], [[12, 12, 12]], [[1, 23, 2]]]\n_outputs = [[1], [2], [2], [9], [5], [10], [18], [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,...
coding
482
Solve the programming task below in a Python markdown code block. [3R2 as DJ Mashiro - Happiness Breeze](https://open.spotify.com/track/2qGqK8GRS65Wlf20qUBEak) [Ice - DJ Mashiro is dead or alive](https://soundcloud.com/iceloki/dj-mashiro-is-dead-or-alive) NEKO#ΦωΦ has just got a new maze game on her PC! The game's m...
{"inputs": ["4 1\n1 4\n", "5 1\n1 4\n", "2 2\n2 1\n1 2\n", "2 4\n2 1\n1 2\n1 2\n1 2\n", "4 4\n2 1\n1 2\n1 2\n1 2\n", "4 4\n2 1\n1 2\n1 2\n2 2\n", "5 5\n2 3\n2 4\n2 4\n2 3\n1 4\n", "5 5\n2 3\n1 4\n2 4\n2 3\n1 4\n"], "outputs": ["Yes\n", "Yes\n", "Yes\nNo\n", "Yes\nNo\nYes\nNo\n", "Yes\nNo\nYes\nNo\n", "Yes\nNo\nYes\nYes...
coding
714
Solve the programming task below in a Python markdown code block. On her way to ChefLand, Marichka noticed $10^K$ road signs (numbered $0$ through $10^K - 1$). For each valid $i$, the sign with number $i$ had the integer $i$ written on one side and $10^K-i-1$ written on the other side. Now, Marichka is wondering — how ...
{"inputs": ["1\n1\n"], "outputs": ["10"]}
coding
432
Solve the programming task below in a Python markdown code block. N hotels are located on a straight line. The coordinate of the i-th hotel (1 \leq i \leq N) is x_i. Tak the traveler has the following two personal principles: - He never travels a distance of more than L in a single day. - He never sleeps in the open....
{"inputs": ["9\n1 6 6 24 7 15 19 29 31\n10\n3\n2 8\n8 3\n1 2\n5 5", "9\n1 3 6 6 15 15 19 29 31\n10\n2\n1 8\n7 3\n1 2\n8 5", "9\n1 3 6 13 15 18 19 29 31\n10\n2\n1 8\n7 3\n6 7\n8 5", "9\n1 3 6 13 23 18 19 29 31\n10\n2\n1 8\n7 5\n6 7\n8 5", "9\n1 3 6 13 23 18 19 29 31\n12\n2\n1 8\n1 3\n9 7\n8 7", "9\n1 3 6 13 23 18 19 29 ...
coding
661
Solve the programming task below in a Python markdown code block. Given a lowercase string that has alphabetic characters only and no spaces, return the highest value of consonant substrings. Consonants are any letters of the alphabet except `"aeiou"`. We shall assign the following values: `a = 1, b = 2, c = 3, .... ...
{"functional": "_inputs = [['zodiac'], ['chruschtschov'], ['khrushchev'], ['strength'], ['catchphrase'], ['twelfthstreet'], ['mischtschenkoana']]\n_outputs = [[26], [80], [38], [57], [73], [103], [80]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math...
coding
240
Solve the programming task below in a Python markdown code block. I conducted an exit poll of the shopping amount at a department store. Create a program that takes the shopping amount data as input, calculates the average shopping amount per person, and outputs it. The number of people surveyed shall be 100,000 or les...
{"inputs": ["6\n1110\n9\n65\n6\n63\n7", "6\n1656\n7\n892\n2\n63\n6", "6\n1100\n7\n892\n2\n63\n6", "6\n1100\n7\n360\n2\n63\n6", "6\n1100\n7\n346\n2\n63\n7", "6\n1110\n17\n65\n6\n63\n7", "6\n1042\n8\n892\n2\n311\n9", "6\n1042\n8\n892\n2\n361\n9"], "outputs": ["210\n", "437\n", "345\n", "256\n", "254\n", "211\n", "377\n",...
coding
201
Solve the programming task below in a Python markdown code block. You are given an integer sequence $1, 2, \dots, n$. You have to divide it into two sets $A$ and $B$ in such a way that each element belongs to exactly one set and $|sum(A) - sum(B)|$ is minimum possible. The value $|x|$ is the absolute value of $x$ and ...
{"inputs": ["3\n", "5\n", "6\n", "1\n", "2\n", "4\n", "4\n", "2\n"], "outputs": ["0\n", "1\n", "1\n", "1\n", "1\n", "0\n", "0\n", "1\n"]}
coding
360
Solve the programming task below in a Python markdown code block. Vasya owns three big integers — $a, l, r$. Let's define a partition of $x$ such a sequence of strings $s_1, s_2, \dots, s_k$ that $s_1 + s_2 + \dots + s_k = x$, where $+$ is a concatanation of strings. $s_i$ is the $i$-th element of the partition. For ex...
{"inputs": ["123\n0\n0\n", "123\n0\n0\n", "123\n0\n1\n", "135\n2\n4\n", "135\n4\n4\n", "135\n6\n4\n", "135\n6\n2\n", "135\n6\n5\n"], "outputs": ["0\n", "0", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]}
coding
531
Solve the programming task below in a Python markdown code block. There are $n$ models in the shop numbered from $1$ to $n$, with sizes $s_1, s_2, \ldots, s_n$. Orac will buy some of the models and will arrange them in the order of increasing numbers (i.e. indices, but not sizes). Orac thinks that the obtained arrang...
{"inputs": ["4\n4\n5 3 4 6\n7\n1 4 2 3 6 4 9\n5\n5 4 3 2 1\n1\n9\n", "4\n4\n5 3 4 6\n7\n1 4 2 3 6 4 9\n5\n5 4 6 2 1\n1\n9\n", "4\n4\n5 3 4 6\n7\n1 4 2 3 6 4 9\n5\n5 5 6 2 1\n1\n9\n", "4\n4\n5 3 4 6\n7\n1 4 2 1 6 4 9\n5\n5 4 6 2 1\n1\n9\n", "4\n4\n5 3 4 6\n7\n1 4 2 3 6 4 9\n5\n5 4 3 2 1\n1\n9\n", "4\n4\n6 6 3 6\n7\n1 4 ...
coding
618
Solve the programming task below in a Python markdown code block. *Words that contain many consecutive consonants, like "schtschurowskia", are generally considered somewhat hard to pronounce.* We say that a word is *hard to pronounce* if it contains 4 or more consonants in a row; otherwise it is *easy to pronounce*. F...
{"inputs": ["5\n5\napple\n15\nschtschurowskia\n6\npolish\n5\ntryst\n3\ncry"], "outputs": ["YES\nNO\nYES\nNO\nYES\n"]}
coding
592
Solve the programming task below in a Python markdown code block. Chef has provided with a sequence of integers of length $N$ arranged in an unsorted fashion. The elements of the sequence are ordered as ${A1,A2,A3.....A'N}$ The task of the chef is to identify the highest and lowest value among the given sequence. It is...
{"inputs": ["5\n3 2 7 9 4"], "outputs": ["9 2"]}
coding
260
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. Perform the following steps: Find any two adjacent numbers in nums that are non-coprime. If no such numbers are found, stop the process. Otherwise, delete the two numbers and ...
{"functional": "def check(candidate):\n assert candidate(nums = [6,4,3,2,7,6,2]) == [12,7,6]\n assert candidate(nums = [2,2,1,1,3,3,3]) == [2,1,1,3]\n\n\ncheck(Solution().replaceNonCoprimes)"}
coding
217
Solve the programming task below in a Python markdown code block. A palindrome is a word, phrase, number, or other sequence of characters which reads the same backward as forward. Examples of numerical palindromes are: 2332 110011 54322345 For a given number `num`, write a function to test if it's a numerical p...
{"functional": "_inputs = [[1221], [110011], [1456009006541], [123322], [1], [152], [9999], ['ACCDDCCA'], ['@14AbC'], ['1221'], [-450]]\n_outputs = [[True], [True], [True], [False], [True], [False], [True], ['Not valid'], ['Not valid'], ['Not valid'], ['Not valid']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if i...
coding
237
Solve the programming task below in a Python markdown code block. There are 2 trains A and B and N stations in a line from 1 to N in order. There is also an array P of length N-1 such that P_{i} (1≤ i < N) denotes the amount of time any train takes to go from the i-th station to the (i+1)-th station. Initially, both ...
{"inputs": ["3\n2\n4\n3\n3 5\n4\n5 2 6\n"], "outputs": ["8\n13\n19\n"]}
coding
567
Solve the programming task below in a Python markdown code block. Find the number of integers between 1 and K (inclusive) satisfying the following condition, modulo 10^9 + 7: * The sum of the digits in base ten is a multiple of D. Constraints * All values in input are integers. * 1 \leq K < 10^{10000} * 1 \leq D \le...
{"inputs": ["30\n1", "30\n2", "30\n8", "30\n4", "1000000009\n2", "1000000009\n4", "1000000009\n5", "1000000009\n9"], "outputs": ["30\n", "14\n", "3\n", "6", "500000004\n", "250000009\n", "200000001\n", "111111112\n"]}
coding
206
Solve the programming task below in a Python markdown code block. Vasily has a deck of cards consisting of n cards. There is an integer on each of the cards, this integer is between 1 and 100 000, inclusive. It is possible that some cards have the same integers on them. Vasily decided to sort the cards. To do this, he...
{"inputs": ["1\n1000\n", "1\n1001\n", "1\n1011\n", "1\n1111\n", "1\n0111\n", "1\n1010\n", "1\n1110\n", "1\n1100\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n"]}
coding
553
Solve the programming task below in a Python markdown code block. Description Since the cubic equation: ax ^ 3 + bx ^ 2 + cx + d = 0 is given, please check the number of positive real roots and the number of negative real roots, respectively. The number of roots shall be counted including the multiple roots. Input...
{"inputs": ["2\n1 4 3 0\n-1 0 1 1", "2\n1 4 3 0\n-1 0 0 0", "2\n1 4 3 0\n-1 0 1 0", "2\n2 4 3 0\n-1 0 1 0", "2\n1 3 3 1\n-8 0 0 0", "2\n1 4 5 0\n-1 0 0 1", "2\n1 4 5 0\n-1 0 0 0", "2\n1 4 3 1\n-3 0 0 1"], "outputs": ["0 2\n1 0\n", "0 2\n0 0\n", "0 2\n1 1\n", "0 0\n1 1\n", "0 3\n0 0\n", "0 0\n1 0\n", "0 0\n0 0\n", "0 1\...
coding
196
Solve the programming task below in a Python markdown code block. Pak Chanek has a grid that has $N$ rows and $M$ columns. Each row is numbered from $1$ to $N$ from top to bottom. Each column is numbered from $1$ to $M$ from left to right. Each tile in the grid contains a number. The numbers are arranged as follows: ...
{"inputs": ["3 4\n", "2 1\n", "1 1\n", "1 2\n", "2 2\n", "1 999999997\n", "1 589284012\n", "999999999 1\n"], "outputs": ["9\n", "1\n", "0\n", "1\n", "2\n", "999999996\n", "589284011\n", "999999998\n"]}
coding
371
Solve the programming task below in a Python markdown code block. Problem A graph is given in which N vertices, each numbered from 1 to N, are connected by N-1 undirected edges. For each vertex, output the shortest number of steps to start from that vertex and visit all vertices. However, one step is to follow one si...
{"inputs": ["2\n1 2", "6\n1 2\n2 3\n3 4\n3 5\n5 6", "6\n1 2\n2 3\n6 4\n3 5\n5 6", "6\n1 2\n2 3\n6 4\n3 4\n5 6", "6\n1 2\n2 3\n3 4\n3 5\n1 6", "6\n1 2\n1 3\n3 4\n3 5\n3 6", "6\n1 2\n2 3\n3 4\n3 5\n2 6", "6\n1 2\n2 5\n6 4\n3 4\n5 6"], "outputs": ["1\n1", "6\n7\n8\n7\n7\n6\n", "5\n6\n7\n5\n7\n6\n", "5\n6\n7\n7\n5\n6\n", "...
coding
281
Solve the programming task below in a Python markdown code block. Seisu-ya, a store specializing in non-negative integers, sells N non-negative integers. The i-th integer is A_i and has a utility of B_i. There may be multiple equal integers with different utilities. Takahashi will buy some integers in this store. He c...
{"inputs": ["3 6\n3 1\n4 4\n2 5", "3 1\n3 3\n4 4\n2 5", "3 6\n4 1\n4 4\n2 5", "3 6\n2 3\n4 4\n2 5", "3 6\n0 0\n4 2\n3 5", "3 1\n3 3\n4 4\n4 5", "3 6\n0 1\n4 4\n2 5", "3 6\n0 1\n3 4\n2 5"], "outputs": ["9\n", "0\n", "10\n", "12\n", "5\n", "0\n", "10\n", "10\n"]}
coding
333
Solve the programming task below in a Python markdown code block. #Detail [Countdown](https://en.wikipedia.org/wiki/Countdown_(game_show) is a British game show with number and word puzzles. The letters round consists of the contestant picking 9 shuffled letters - either picking from the vowel pile or the consonant pi...
{"functional": "_inputs = [[''], ['MKMKMKMKM'], ['IIIWUGEZI']]\n_outputs = [[None], [None], [None]]\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) != l...
coding
309
Solve the programming task below in a Python markdown code block. You are now in a bookshop with your friend Alice to buy a book, "The Winning Strategy for the Programming Koshien Contest,” just released today. As you definitely want to buy it, you are planning to borrow some money from Alice in case the amount you hav...
{"inputs": ["1 1110 3", "0 1100 3", "1 1100 2", "350 7 354", "0 1110 13", "0 1110 20", "0 1110 10", "1 1110 10"], "outputs": ["2\n", "3\n", "1\n", "4\n", "13\n", "20\n", "10\n", "9\n"]}
coding
330
Solve the programming task below in a Python markdown code block. Chef has an array A of length N. He calls an index i (1 ≤ i ≤ N) *good* if there exists some j \neq i such that A_{i} = A_{j}. Chef can perform the following operation at most once: Choose any [subsequence] of the array A and add any positive integer ...
{"inputs": ["3\n6\n1 3 5 2 4 8\n4\n2 3 4 5\n7\n1 1 2 2 3 4 4\n"], "outputs": ["4\n4\n7\n"]}
coding
329
Solve the programming task below in a Python markdown code block. Given an integer N. Integers A and B are chosen randomly in the range [1..N]. Calculate the probability that the Greatest Common Divisor(GCD) of A and B equals to B. -----Input----- The first line of the input contains an integer T denoting the number o...
{"inputs": ["3\n1\n2\n3", "3\n1\n2\n3"], "outputs": ["1/1\n3/4\n5/9", "1/1\n3/4\n5/9"]}
coding
163
Solve the programming task below in a Python markdown code block. Given is a sequence of integers A_1, A_2, ..., A_N. If its elements are pairwise distinct, print YES; otherwise, print NO. -----Constraints----- - 2 ≤ N ≤ 200000 - 1 ≤ A_i ≤ 10^9 - All values in input are integers. -----Input----- Input is given fro...
{"inputs": ["5\n2 9 1 4 5", "5\n2 9 1 3 5", "5\n2 9 0 3 5", "5\n2 4 0 3 5", "5\n2 4 1 3 5", "5\n2 4 1 3 2", "5\n1 4 1 3 2", "5\n1 4 1 1 2"], "outputs": ["YES\n", "YES\n", "YES\n", "YES\n", "YES\n", "NO\n", "NO\n", "NO\n"]}
coding
156
Solve the programming task below in a Python markdown code block. Congratulations! That Special Someone has given you their phone number. But WAIT, is it a valid number? Your task is to write a function that verifies whether a given string contains a valid British mobile (cell) phone number or not. If valid, retur...
{"functional": "_inputs = [['07454876120'], ['0754876120'], ['0745--487-61-20'], ['+447535514555'], ['-07599-51-4555'], ['075335440555'], ['+337535512555'], ['00535514555'], ['+447+4435512555'], ['+44']]\n_outputs = [['In with a chance'], ['Plenty more fish in the sea'], ['In with a chance'], ['In with a chance'], ['In...
coding
279
Solve the programming task below in a Python markdown code block. Bozo is shifting his house. He has some balls and boxes which he has to shift. He now wonders how large a ball he can fit in a given box. Given the dimensions of a box, help Bozo determine the radius of the largest ball that he can fit in the box. Assume...
{"inputs": ["28\n754474126400970 101 196613378898208859\n380621045618581 267501121282332999 950586\n793855488118611572 865408 211106328880\n373419125 487966671162 240278042032\n366316 973 365\n592904340231516 734 44193919246935149\n76 752 536\n343780751470180549 907 976026998834190\n868 755369598881618 9491478654517796...
coding
257
Solve the programming task below in a Python markdown code block. Nezzar has a binary string s of length n that he wants to share with his best friend, Nanako. Nanako will spend q days inspecting the binary string. At the same time, Nezzar wants to change the string s into string f during these q days, because it looks...
{"inputs": ["1\n4 1\n0011\n0011\n1 4\n", "1\n4 1\n0011\n0111\n1 4\n", "1\n4 1\n0011\n0011\n4 4\n", "1\n4 1\n0011\n0110\n1 4\n", "1\n4 1\n0011\n0011\n2 4\n", "1\n4 1\n0011\n0100\n1 4\n", "1\n4 1\n0011\n0100\n2 4\n", "1\n4 1\n0011\n0001\n4 4\n"], "outputs": ["NO\n", "NO\n", "YES\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n"...
coding
676
Solve the programming task below in a Python markdown code block. Chang's new maths teacher is very enthusiastic about making sure that students understand the concept rather than remembering it. On her first day at teaching, she gives an assignment to all the students to test their potential. Chang wants to demonstrat...
{"inputs": ["4 4"], "outputs": ["1"]}
coding
284
Solve the programming task below in a Python markdown code block. As you know, majority of students and teachers of Summer Informatics School live in Berland for the most part of the year. Since corruption there is quite widespread, the following story is not uncommon. Elections are coming. You know the number of vote...
{"inputs": ["1 1\n1 100\n", "1 1\n1 110\n", "1 2\n1 100\n", "1 259\n55 226621946\n", "1 654\n408 226621946\n", "1 3000\n61 226621946\n", "1 3000\n55 226621946\n", "1 522\n408 226621946\n"], "outputs": ["0\n", "0\n", "0\n", "226621946\n", "226621946\n", "226621946\n", "226621946\n", "226621946\n"]}
coding
521
Solve the programming task below in a Python markdown code block. "I'm a fan of anything that tries to replace actual human contact." - Sheldon. After years of hard work, Sheldon was finally able to develop a formula which would diminish the real human contact. He found k$k$ integers n1,n2...nk$n_1,n_2...n_k$ . Also ...
{"inputs": ["1\n1\n5"], "outputs": ["2"]}
coding
497
Solve the programming task below in a Python markdown code block. Chef is given two strings A and B of length N containing lowercase English letters. Chef can rearrange both the strings in any way he wants. He wants to minimize the length of LCS ([Longest Common Subsequence] of both the strings. Find the minimum leng...
{"inputs": ["3\n4\naaaa\naaab\n1\nc\nz\n5\nabcde\ncdefg\n"], "outputs": ["3\n0\n1\n"]}
coding
413
Solve the programming task below in a Python markdown code block. You are given an array A of length N containing the elements -1 and 1 only. Determine if it is possible to rearrange the array A in such a way that A_{i} is not the geometric mean of A_{i-1} and A_{i+1}, for all i such that 2 ≤ i ≤ N-1. Y is said to be ...
{"inputs": ["3\n5\n1 1 1 -1 -1\n3\n1 1 1\n6\n1 -1 -1 -1 -1 1\n"], "outputs": ["Yes\nNo\nYes\n"]}
coding
478
Solve the programming task below in a Python markdown code block. Vasya has n days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this n days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the i-th d...
{"inputs": ["1\n0\n", "1\n1\n", "1\n2\n", "1\n3\n", "1\n2\n", "1\n1\n", "1\n3\n", "1\n0\n"], "outputs": ["1\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "1\n"]}
coding
685
Solve the programming task below in a Python markdown code block. A correct expression of the form a+b=c was written; a, b and c are non-negative integers without leading zeros. In this expression, the plus and equally signs were lost. The task is to restore the expression. In other words, one character '+' and one cha...
{"inputs": ["099\n", "112\n", "101\n", "011\n", "178\n", "000\n", "178\n", "101\n"], "outputs": ["0+9=9\n", "1+1=2\n", "1+0=1\n", "0+1=1\n", "1+7=8\n", "0+0=0\n", "1+7=8", "1+0=1"]}
coding
421
Solve the programming task below in a Python markdown code block. Alex just got a new hula hoop, he loves it but feels discouraged because his little brother is better than him Write a program where Alex can input (n) how many times the hoop goes round and it will return him an encouraging message :) -If Alex gets 1...
{"functional": "_inputs = [[6], [10], [22]]\n_outputs = [['Keep at it until you get it'], ['Great, now move on to tricks'], ['Great, now move on to tricks']]\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 ...
coding
131
Solve the programming task below in a Python markdown code block. Problem statement A programming contest will be held in the Russian Federation. The contest has N questions and has M participants. Question i has a score a_i, and it is known that participant j's ability is b_j. For problem i and participant j, partici...
{"inputs": ["6\n1 2 1 3 4 5\n7\n1 3 4 5 3 1 0\n2 8 5 3 4 5 3", "6\n1 2 1 5 4 5\n7\n1 3 4 7 3 1 0\n2 8 5 3 7 5 3", "6\n1 2 2 5 4 5\n7\n1 3 4 7 3 1 0\n2 8 5 3 7 5 3", "6\n1 2 1 6 3 1\n7\n1 3 4 7 3 1 0\n2 8 5 3 3 0 3", "6\n1 2 2 8 6 1\n7\n2 3 4 2 3 1 0\n1 8 1 3 3 1 1", "6\n1 2 1 5 4 5\n7\n1 3 3 7 3 1 0\n2 8 5 3 7 5 3", "6...
coding
701
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an integer array score of size n, where score[i] is the score of the ith athlete in a competition. All the scores are guaranteed to be unique. The athletes are placed based on their scores, where the 1st...
{"functional": "def check(candidate):\n assert candidate(score = [5,4,3,2,1]) == [\"Gold Medal\",\"Silver Medal\",\"Bronze Medal\",\"4\",\"5\"]\n assert candidate(score = [10,3,8,9,4]) == [\"Gold Medal\",\"5\",\"Bronze Medal\",\"Silver Medal\",\"4\"]\n\n\ncheck(Solution().findRelativeRanks)"}
coding
226
Solve the programming task below in a Python markdown code block. JJ has an array A of length N and an integer X. JJ can perform the following operation at most once: Select a [subsequence] of A and add X to all the elements of that subsequence. For example, if A = [2, 1, 6, 3, 5] and X = 7, we can select the subseque...
{"inputs": ["3\n2 1\n1 2\n4 1\n2 2 3 3\n5 2\n5 3 6 2 8\n"], "outputs": ["3\n15\n43\n"]}
coding
629
Solve the programming task below in a Python markdown code block. Scheduling is how the processor decides which jobs(processes) get to use the processor and for how long. This can cause a lot of problems. Like a really long process taking the entire CPU and freezing all the other processes. One solution is Shortest Job...
{"functional": "_inputs = [[[100], 0], [[3, 10, 20, 1, 2], 0], [[3, 10, 20, 1, 2], 1], [[3, 10, 10, 20, 1, 2], 1], [[3, 10, 10, 20, 1, 2], 2], [[3, 10, 20, 1, 2, 3], 5], [[3, 10, 20, 1, 2, 10, 10], 5]]\n_outputs = [[100], [6], [16], [16], [26], [9], [26]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a...
coding
437
Solve the programming task below in a Python markdown code block. Valery is very interested in magic. Magic attracts him so much that he sees it everywhere. He explains any strange and weird phenomenon through intervention of supernatural forces. But who would have thought that even in a regular array of numbers Valera...
{"inputs": ["1\n8\n", "1\n9\n", "1\n1\n", "1\n0\n", "1\n10\n", "1\n11\n", "2\n5 6\n", "2\n1 6\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "1", "1\n", "2", "2\n"]}
coding
473
Solve the programming task below in a Python markdown code block. Timmy & Sarah think they are in love, but around where they live, they will only know once they pick a flower each. If one of the flowers has an even number of petals and the other has an odd number of petals it means they are in love. Write a function...
{"functional": "_inputs = [[1, 4], [2, 2], [0, 1], [0, 0]]\n_outputs = [[True], [False], [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(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a...
coding
122
Solve the programming task below in a Python markdown code block. There is a house with 4 levels. In that house there is an elevator. You can program this elevator to go up or down, depending on what button the user touches inside the elevator. Valid levels must be only these numbers: `0,1,2,3` Valid buttons must be ...
{"functional": "_inputs = [[0, '0'], [0, '1'], [0, '2'], [0, '3'], [1, '0'], [1, '1'], [1, '2'], [1, '3'], [2, '0'], [2, '1'], [2, '2'], [2, '3'], [3, '0'], [3, '1'], [3, '2'], [3, '3'], [0, '4'], [0, None], [1, '4'], [1, None], [2, '4'], [2, None], [3, '4'], [3, None], [4, '2'], [None, '2'], [[], '2'], [3, {}], ['2', ...
coding
400
Solve the programming task below in a Python markdown code block. Chef bought N items from a shop. Although it is hard to carry all these items in hand, so Chef has to buy some polybags to store these items. 1 polybag can contain at most 10 items. What is the minimum number of polybags needed by Chef? ------ Input Fo...
{"inputs": ["3\n20\n24\n99\n"], "outputs": ["2\n3\n10\n"]}
coding
279
Solve the programming task below in a Python markdown code block. When registering in a social network, users are allowed to create their own convenient login to make it easier to share contacts, print it on business cards, etc. Login is an arbitrary sequence of lower and uppercase latin letters, digits and underline ...
{"inputs": ["Z\n1\nz\n", "0\n1\no\n", "0\n1\nO\n", "o\n1\n0\n", "o\n1\nO\n", "o\n1\no\n", "O\n1\no\n", "O\n1\n0\n"], "outputs": ["No\n", "No\n", "No\n", "No\n", "No\n", "No\n", "No\n", "No\n"]}
coding
650
Solve the programming task below in a Python markdown code block. Problem Alice and Bob are competing in the 50m dash. However, in this world, the higher the AOJ rate is, the better, so the higher the AOJ rate wins. If there is no AOJ rate on either side, there is no comparison, so there is no choice but to compete in...
{"inputs": ["18 9 0 1", "18 9 0 0", "30 9 0 0", "45 9 0 0", "63 9 0 0", "63 2 0 0", "63 4 0 0", "82 4 0 0"], "outputs": ["Bob\n", "Draw\n", "Draw\n", "Draw\n", "Draw\n", "Draw\n", "Draw\n", "Draw\n"]}
coding
410
Solve the programming task below in a Python markdown code block. You should write a simple function that takes string as input and checks if it is a valid Russian postal code, returning `true` or `false`. A valid postcode should be 6 digits with no white spaces, letters or other symbols. Empty string should also retu...
{"functional": "_inputs = [['142784'], ['642784'], ['111'], ['1111111'], ['AA5590'], [''], ['\\n245980'], ['245980\\n'], ['245980a'], ['24598a'], [' 310587 '], ['555555'], ['775255'], ['875555'], ['012345'], ['968345'], ['@68345']]\n_outputs = [[True], [True], [False], [False], [False], [False], [False], [False], [Fals...
coding
191
Solve the programming task below in a Python markdown code block. Vasya is choosing a laptop. The shop has n laptops to all tastes. Vasya is interested in the following properties: processor speed, ram and hdd. Vasya is a programmer and not a gamer which is why he is not interested in all other properties. If all thr...
{"inputs": ["1\n1000 256 1 100\n", "1\n1000 477 1 100\n", "1\n1000 477 1 101\n", "1\n1000 784 1 101\n", "1\n1200 512 300 700\n", "1\n1619 512 300 700\n", "1\n1619 579 300 700\n", "1\n1619 375 300 700\n"], "outputs": ["1", "1\n", "1\n", "1\n", "1", "1\n", "1\n", "1\n"]}
coding
494
Solve the programming task below in a Python markdown code block. You are given 3 numbers a, b and x. You need to output the multiple of x which is closest to a^{b}. If more than one answer exists , display the smallest one. Input Format The first line contains T, the number of testcases. T lines follow, each line...
{"inputs": ["3\n349 1 4\n395 1 7\n4 -2 2\n"], "outputs": ["348\n392\n0\n"]}
coding
277
Solve the programming task below in a Python markdown code block. Read problems statements [Mandarin] , [Bengali] , [Hindi] , [Russian] and [Vietnamese] as well. You are given an integer sequence $A_{1}, A_{2}, \dots, A_{N}$. Let's define the *useful number* of a subsequence of $A$ as the number of distinct primes $p$...
{"inputs": ["1\n5\n2 2 4 17 8"], "outputs": ["4"]}
coding
448
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an integer array matchsticks where matchsticks[i] is the length of the ith matchstick. You want to use all the matchsticks to make one square. You should not break any stick, but you can link them up, an...
{"functional": "def check(candidate):\n assert candidate(matchsticks = [1,1,2,2,2]) == True\n assert candidate(matchsticks = [3,3,3,3,4]) == False\n\n\ncheck(Solution().makesquare)"}
coding
121
Solve the programming task below in a Python markdown code block. You will be given an integer a and a string s consisting of lowercase English letters as input. Write a program that prints s if a is not less than 3200 and prints red if a is less than 3200. -----Constraints----- - 2800 \leq a < 5000 - s is a string ...
{"inputs": ["2800\na\n", "4049\nrdd", "4049\nqdd", "4049\nqcd", "4049\nqdc", "4049\nddq", "4049\nddr", "4049\ndrd"], "outputs": ["red\n", "rdd\n", "qdd\n", "qcd\n", "qdc\n", "ddq\n", "ddr\n", "drd\n"]}
coding
202
Solve the programming task below in a Python markdown code block. As most of you might know already, a prime number is an integer `n` with the following properties: * it must be greater than 1 * it must be divisible only by itself and 1 And that's it: -15 or 8 are not primes, 5 or 97 are; pretty easy, isn't it? Well...
{"functional": "_inputs = [[1], [2], [5], [143], [-1], [29], [53], [529]]\n_outputs = [[False], [True], [True], [False], [False], [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(a, b, rel_tol=tol, abs_tol=tol)\n i...
coding
631
Solve the programming task below in a Python markdown code block. Given a word w, rearrange the letters of w to construct another word s in such a way that s is lexicographic-ally greater than w. In case of multiple possible answers, find the lexicographic-ally smallest one. Input Format The first line of input conta...
{"inputs": ["5\nab\nbb\nhefg\ndhck\ndkhc"], "outputs": ["ba\nno answer\nhegf\ndhkc\nhcdk"]}
coding
339
Solve the programming task below in a Python markdown code block. Kabir wants to impress Tara by showing her his problem solving skills. He has decided to give the correct answer to the next question which will be asked by his Algorithms teacher. The question asked is: Find the sum of alternate consecutive d$d$ odd num...
{"inputs": ["1\n3\n10 33"], "outputs": ["114"]}
coding
499
Solve the programming task below in a Python markdown code block. Rng has a connected undirected graph with N vertices. Currently, there are M edges in the graph, and the i-th edge connects Vertices A_i and B_i. Rng will add new edges to the graph by repeating the following operation: * Operation: Choose u and v (u \...
{"inputs": ["6 5\n1 2\n2 3\n3 4\n4 5\n4 6", "5 5\n1 2\n2 3\n3 1\n5 3\n5 1", "6 5\n1 2\n2 2\n3 4\n4 5\n5 6", "5 5\n1 2\n2 3\n3 2\n5 4\n5 1", "6 5\n1 2\n2 3\n3 4\n4 5\n3 6", "9 5\n1 2\n2 3\n3 3\n0 5\n4 6", "8 5\n1 1\n2 3\n3 1\n5 3\n5 1", "7 5\n1 1\n2 3\n3 1\n5 3\n5 1"], "outputs": ["3\n", "5\n", "10\n", "1\n", "4\n", "31...
coding
317
Solve the programming task below in a Python markdown code block. Zonal Computing Olympiad 2012, 26 Nov 2011 A sequence of opening and closing brackets is well-bracketed if we can pair up each opening bracket with a matching closing bracket in the usual sense. For instance, the sequences (), (()) and ()(()) are well-...
{"inputs": ["20\n1 2 1 1 2 2 1 2 1 1 2 1 2 2 1 1 2 1 2 2"], "outputs": ["2 4 6 9"]}
coding
666