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. Taro has decided to move. Taro has a lot of luggage, so I decided to ask a moving company to carry the luggage. Since there are various weights of luggage, I asked them to arrange them in order from the lightest one for easy understanding, but the mover ...
{"inputs": ["4\n2 4 2 2", "4\n1 4 3 2", "4\n3 4 1 2", "4\n2 4 1 3", "4\n2 4 3 1", "4\n2 1 4 3", "4\n2 4 1 3", "4\n1 2 4 3"], "outputs": ["4\n", "5\n", "3\n", "4\n", "4\n", "4\n", "4\n", "3\n"]}
coding
420
Solve the programming task below in a Python markdown code block. Chef belongs to a very rich family which owns many gold mines. Today, he brought N gold coins and decided to form a triangle using these coins. Isn't it strange? Chef has a unusual way of forming a triangle using gold coins, which is described as follows...
{"inputs": ["3\n3\n5\n7"], "outputs": ["2\n2\n3"]}
coding
391
Solve the programming task below in a Python markdown code block. Let's call a positive integer extremely round if it has only one non-zero digit. For example, $5000$, $4$, $1$, $10$, $200$ are extremely round integers; $42$, $13$, $666$, $77$, $101$ are not. You are given an integer $n$. You have to calculate the num...
{"inputs": ["1\n1\n", "1\n69\n", "1\n912\n", "2\n1\n1\n", "1\n9123\n", "1\n9999\n", "1\n9998\n", "1\n9997\n"], "outputs": ["1\n", "15\n", "27\n", "1\n1\n", "36\n", "36\n", "36\n", "36\n"]}
coding
277
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an array nums of n integers, return an array of all the unique quadruplets [nums[a], nums[b], nums[c], nums[d]] such that: 0 <= a, b, c, d < n a, b, c, and d are distinct. nums[a] + nums[b] + nums[c] + nums[d] ...
{"functional": "def check(candidate):\n assert candidate(nums = [1,0,-1,0,-2,2], target = 0) == [[-2,-1,1,2],[-2,0,0,2],[-1,0,0,1]]\n assert candidate(nums = [2,2,2,2,2], target = 8) == [[2,2,2,2]]\n\n\ncheck(Solution().fourSum)"}
coding
139
Solve the programming task below in a Python markdown code block. Mr.X, who the handle name is T, looked at the list which written N handle names, S_1, S_2, ..., S_N. But he couldn't see some parts of the list. Invisible part is denoted `?`. Please calculate all possible index of the handle name of Mr.X when you sort ...
{"inputs": ["2\ntourist\neptr\ne", "2\nssvuhnr\nerrs\nf", "2\nhupouvt\netor\ni", "2\nsourist\neptr\ne", "2\nsourist\neqtr\ne", "2\nsourist\netqr\ne", "2\nsourisu\netqr\ne", "2\nsourisu\netqr\nd"], "outputs": ["1\n", "2\n", "3\n", "1\n", "1\n", "1\n", "1\n", "1\n"]}
coding
487
Solve the programming task below in a Python markdown code block. Polycarpus analyzes a string called abracadabra. This string is constructed using the following algorithm: * On the first step the string consists of a single character "a". * On the k-th step Polycarpus concatenates two copies of the string obtai...
{"inputs": ["1 4 4 7\n", "1 2 3 3\n", "3 3 1 2\n", "1 2 3 6\n", "2 2 6 6\n", "4 7 1 4\n", "1 3 5 7\n", "5 7 1 3\n"], "outputs": ["3\n", "1\n", "1\n", "2\n", "1\n", "3\n", "3\n", "3\n"]}
coding
705
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a string s containing only three types of characters: '(', ')' and '*', return true if s is valid. The following rules define a valid string: Any left parenthesis '(' must have a corresponding right parenthesis...
{"functional": "def check(candidate):\n assert candidate(s = \"()\") == True\n assert candidate(s = \"(*)\") == True\n assert candidate(s = \"(*))\") == True\n\n\ncheck(Solution().checkValidString)"}
coding
138
Solve the programming task below in a Python markdown code block. Little penguin Polo loves his home village. The village has n houses, indexed by integers from 1 to n. Each house has a plaque containing an integer, the i-th house has a plaque containing integer p_{i} (1 ≤ p_{i} ≤ n). Little penguin Polo loves walking...
{"inputs": ["5 2\n", "7 4\n", "8 5\n", "8 1\n", "8 8\n", "9 8\n", "1 1\n", "2 1\n"], "outputs": ["54\n", "1728\n", "16875\n", "823543\n", "2097152\n", "2097152\n", "1\n", "1\n"]}
coding
426
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an integer array bloomDay, an integer m and an integer k. You want to make m bouquets. To make a bouquet, you need to use k adjacent flowers from the garden. The garden consists of n flowers, the ith flo...
{"functional": "def check(candidate):\n assert candidate(bloomDay = [1,10,3,10,2], m = 3, k = 1) == 3\n assert candidate(bloomDay = [1,10,3,10,2], m = 3, k = 2) == -1\n assert candidate(bloomDay = [7,7,7,7,12,7,7], m = 2, k = 3) == 12\n assert candidate(bloomDay = [1000000000,1000000000], m = 1, k = 1) == 1...
coding
161
Please solve the programming task below using a self-contained code snippet in a markdown code block. HTML entity parser is the parser that takes HTML code as input and replace all the entities of the special characters by the characters itself. The special characters and their entities for HTML are: Quotation Mark: ...
{"functional": "def check(candidate):\n assert candidate(text = \"&amp; is an HTML entity but &ambassador; is not.\") == \"& is an HTML entity but &ambassador; is not.\"\n assert candidate(text = \"and I quote: &quot;...&quot;\") == \"and I quote: \\\"...\\\"\"\n assert candidate(text = \"Stay home! Practice o...
coding
208
Solve the programming task below in a Python markdown code block. Laura Bassi was the first female professor at a European university. Despite her immense intellect, she was not always allowed to lecture publicly. One day a professor with very strong beliefs against women in academia sent some `agents` to find Bassi...
{"functional": "_inputs = [[[[1, 1]], 2], [[[1, 1]], 0], [[[9, 9]], 1], [[[0, 0]], 10]]\n_outputs = [[[[0, 0]]], [[]], [[[0, 0]]], [[[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...
coding
579
Solve the programming task below in a Python markdown code block. JJ has an array A of length N. He can perform the following operation on A: Select any L, R (1 ≤ L ≤ R ≤ N) and for each i such that L ≤ i ≤ R, set A_{i} := A_{i} + 1. JJ wants to make A palindromic. Find the minimum number of moves to do so. Note: An ...
{"inputs": ["3\n6\n2 6 4 3 4 1\n2\n1 10\n3\n1 10 1\n"], "outputs": ["2\n9\n0\n"]}
coding
544
Solve the programming task below in a Python markdown code block. You are at a water bowling training. There are l people who play with their left hand, r people, who play with their right hand, and a ambidexters, who can play with left or right hand. The coach decided to form a team of even number of players, exactly...
{"inputs": ["1 4 2\n", "5 5 5\n", "0 2 0\n", "0 0 0\n", "1 1 1\n", "1 2 1\n", "1 2 2\n", "2 2 2\n"], "outputs": ["6\n", "14\n", "0\n", "0\n", "2\n", "4\n", "4\n", "6\n"]}
coding
409
Solve the programming task below in a Python markdown code block. Ask a small girl - "How old are you?". She always says strange things... Lets help her! For correct answer program should return int from 0 to 9. Assume test input string always valid and may look like "1 year old" or "5 years old", etc.. The first c...
{"functional": "_inputs = [['1 year old'], ['2 years old'], ['3 years old'], ['4 years old'], ['5 years old'], ['6 years old'], ['7 years old'], ['8 years old'], ['9 years old']]\n_outputs = [[1], [2], [3], [4], [5], [6], [7], [8], [9]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinsta...
coding
102
Solve the programming task below in a Python markdown code block. A sorting algorithm A is said to have more time complexity than a sorting algorithm B if it uses more number of comparisons for sorting the same array than algorithm B. Given that algorithm A uses X comparisons to sort an array and algorithm B uses Y co...
{"inputs": ["4\n9 9\n15 7\n10 19\n21 20\n"], "outputs": ["NO\nYES\nNO\nYES"]}
coding
530
Solve the programming task below in a Python markdown code block. You have a grid with `$m$` rows and `$n$` columns. Return the number of unique ways that start from the top-left corner and go to the bottom-right corner. You are only allowed to move right and down. For example, in the below grid of `$2$` rows and `$3$...
{"functional": "_inputs = [[1, 1], [5, 1], [3, 4], [5, 6], [10, 10], [100, 3], [123, 456]]\n_outputs = [[2], [6], [35], [462], [184756], [176851], [448843261729071620474858205566477025894357385375655014634306680560209909590802545266425906052279365647506075241055256064119806400]]\nimport math\ndef _deep_eq(a, b, tol=1e-...
coding
201
Solve the programming task below in a Python markdown code block. Finally, a COVID vaccine is out on the market and the Chefland government has asked you to form a plan to distribute it to the public as soon as possible. There are a total of $N$ people with ages $a_1, a_2, \ldots, a_N$. There is only one hospital where...
{"inputs": ["2\n10 1\n10 20 30 40 50 60 90 80 100 1\n5 2\n9 80 27 72 79"], "outputs": ["10\n3"]}
coding
508
Solve the programming task below in a Python markdown code block. Write a function that outputs the transpose of a matrix - a new matrix where the columns and rows of the original are swapped. For example, the transpose of: | 1 2 3 | | 4 5 6 | is | 1 4 | | 2 5 | | 3 6 | The input to your func...
{"functional": "_inputs = [[[[1]]], [[[1, 2, 3]]], [[[1, 2, 3], [4, 5, 6], [7, 8, 9]]], [[[1, 0, 0], [0, 1, 0], [0, 0, 1], [0, 1, 0], [1, 0, 0]]]]\n_outputs = [[[[1]]], [[[1], [2], [3]]], [[[1, 4, 7], [2, 5, 8], [3, 6, 9]]], [[[1, 0, 0, 0, 1], [0, 1, 0, 1, 0], [0, 0, 1, 0, 0]]]]\nimport math\ndef _deep_eq(a, b, tol=1e-...
coding
147
Solve the programming task below in a Python markdown code block. We have a string S of length N consisting of R, G, and B. Find the number of triples (i,~j,~k)~(1 \leq i < j < k \leq N) that satisfy both of the following conditions: - S_i \neq S_j, S_i \neq S_k, and S_j \neq S_k. - j - i \neq k - j. -----Constraint...
{"inputs": ["3\nRGB\n", "4\nBGRR", "4\nGRRB", "4\nRGBR", "4\nRRBG", "4\nGBRR", "4\nRGRB", "4\nBRGR"], "outputs": ["0\n", "1\n", "2\n", "0\n", "1\n", "1\n", "1\n", "1\n"]}
coding
228
Solve the programming task below in a Python markdown code block. This is Fibonacci madness. Given a number n. Print the first n Fibonacci numbers in reverse order. Input: First line is number T denoting number of test cases. T lines follow. Each line has number N. Output: Print the first n Fibonacci numbers in rev...
{"inputs": ["5\n56\n61\n63\n67\n70", "7\n3\n12\n15\n24\n36\n41\n42"], "outputs": ["139583862445 86267571272 53316291173 32951280099 20365011074 12586269025 7778742049 4807526976 2971215073 1836311903 1134903170 701408733 433494437 267914296 165580141 102334155 63245986 39088169 24157817 14930352 9227465 5702887 3524578...
coding
167
Solve the programming task below in a Python markdown code block. 3R2 as DJ Mashiro - Happiness Breeze Ice - DJ Mashiro is dead or alive NEKO#ΦωΦ has just got a new maze game on her PC! The game's main puzzle is a maze, in the forms of a $2 \times n$ rectangle grid. NEKO's task is to lead a Nekomimi girl from cell $(...
{"inputs": ["4 1\n1 4\n", "4 1\n1 4\n", "2 2\n2 1\n1 2\n", "2 2\n2 1\n1 2\n", "2 4\n2 1\n1 2\n1 2\n1 2\n", "2 4\n2 1\n1 2\n1 2\n1 2\n", "5 5\n2 3\n1 4\n2 4\n2 3\n1 4\n", "6 5\n2 3\n1 4\n2 4\n2 3\n1 4\n"], "outputs": ["Yes\n", "Yes\n", "Yes\nNo\n", "Yes\nNo\n", "Yes\nNo\nYes\nNo\n", "Yes\nNo\nYes\nNo\n", "Yes\nNo\nNo\nN...
coding
707
Solve the programming task below in a Python markdown code block. Ridbit starts with an integer $n$. In one move, he can perform one of the following operations: divide $n$ by one of its proper divisors, or subtract $1$ from $n$ if $n$ is greater than $1$. A proper divisor is a divisor of a number, excluding itself...
{"inputs": ["6\n1\n2\n3\n4\n6\n9\n", "6\n1\n2\n3\n4\n1\n9\n", "6\n1\n2\n3\n7\n1\n1\n", "6\n1\n3\n3\n4\n1\n9\n", "6\n1\n3\n3\n3\n6\n7\n", "6\n1\n4\n3\n7\n1\n1\n", "6\n1\n3\n3\n4\n1\n3\n", "6\n1\n4\n3\n7\n1\n2\n"], "outputs": ["0\n1\n2\n2\n2\n3\n", "0\n1\n2\n2\n0\n3\n", "0\n1\n2\n3\n0\n0\n", "0\n2\n2\n2\n0\n3\n", "0\n2\n...
coding
373
Solve the programming task below in a Python markdown code block. You get any card as an argument. Your task is to return a suit of this card. Our deck (is preloaded): ```python DECK = ['2S','3S','4S','5S','6S','7S','8S','9S','10S','JS','QS','KS','AS', '2D','3D','4D','5D','6D','7D','8D','9D','10D','JD','QD','K...
{"functional": "_inputs = [['3C'], ['QS'], ['9D'], ['JH']]\n_outputs = [['clubs'], ['spades'], ['diamonds'], ['hearts']]\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
267
Solve the programming task below in a Python markdown code block. A string $s$ of length $n$, consisting of lowercase letters of the English alphabet, is given. You must choose some number $k$ between $0$ and $n$. Then, you select $k$ characters of $s$ and permute them however you want. In this process, the positions ...
{"inputs": ["1\n20\naaaaaaaaaaaaaaaaaqwq\n", "1\n20\naaaaaaaaaaaaaaaaaqwq\n", "1\n20\naaaaaaabaaaaaaaaaqwq\n", "1\n20\nabaaaaabaaaaaaaaaqwq\n", "1\n20\nqwqaaaaaaaaabaaaaaba\n", "1\n20\nqwqaaaaabaaabaaaaaba\n", "1\n20\nabaaaaabaaabaaaaaqwq\n", "1\n20\nqwqaaaaaaaaabaaaabba\n"], "outputs": ["2\n", "2\n", "4\n", "6\n", "9\...
coding
569
Please solve the programming task below using a self-contained code snippet in a markdown code block. There are n pieces arranged in a line, and each piece is colored either by 'A' or by 'B'. You are given a string colors of length n where colors[i] is the color of the ith piece. Alice and Bob are playing a game where...
{"functional": "def check(candidate):\n assert candidate(colors = \"AAABABB\") == True\n assert candidate(colors = \"AA\") == False\n assert candidate(colors = \"ABBBBBBBAAA\") == False\n\n\ncheck(Solution().winnerOfGame)"}
coding
244
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an integer array values where values[i] represents the value of the ith sightseeing spot. Two sightseeing spots i and j have a distance j - i between them. The score of a pair (i < j) of sightseeing spot...
{"functional": "def check(candidate):\n assert candidate(values = [8,1,5,2,6]) == 11\n assert candidate(values = [1,2]) == 2\n\n\ncheck(Solution().maxScoreSightseeingPair)"}
coding
145
Solve the programming task below in a Python markdown code block. You will be given an array of non-negative integers and positive integer bin width. Your task is to create the Histogram method that will return histogram data corresponding to the input array. The histogram data is an array that stores under index i t...
{"functional": "_inputs = [[[1, 1, 0, 1, 3, 2, 6], 1], [[1, 1, 0, 1, 3, 2, 6], 2], [[], 1], [[8], 1]]\n_outputs = [[[1, 3, 1, 1, 0, 0, 1]], [[4, 2, 0, 1]], [[]], [[0, 0, 0, 0, 0, 0, 0, 0, 1]]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(...
coding
248
Solve the programming task below in a Python markdown code block. Given is a string S consisting of lowercase English letters. Find the maximum positive integer K that satisfies the following condition: * There exists a partition of S into K non-empty strings S=S_1S_2...S_K such that S_i \neq S_{i+1} (1 \leq i \leq K-...
{"inputs": ["a`bbaa", "b`aba`", "b``aaa", "a`bcaa", "a`acaa", "c`aaaa", "b`aaaa", "b`abaa"], "outputs": ["5\n", "6\n", "4\n", "5\n", "5\n", "5\n", "5\n", "5\n"]}
coding
198
Solve the programming task below in a Python markdown code block. In Japan, temperature is usually expressed using the Celsius (℃) scale. In America, they used the Fahrenheit (℉) scale instead. $20$ degrees Celsius is roughly equal to $68$ degrees Fahrenheit. A phrase such as "Today’s temperature is $68$ degrees" is co...
{"inputs": ["6", "82", "60", "85", "51", "96", "65", "57"], "outputs": ["-12\n", "26\n", "15\n", "27\n", "10\n", "33\n", "17\n", "13\n"]}
coding
285
Solve the programming task below in a Python markdown code block. You are given a certain integer, ```n, n > 0```. You have to search the partition or partitions, of n, with maximum product value. Let'see the case for ```n = 8```. ``` Partition Product [8] 8 [7, 1] ...
{"functional": "_inputs = [[8], [10]]\n_outputs = [[[[3, 3, 2], 18]], [[[4, 3, 3], [3, 3, 2, 2], 36]]]\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
630
Solve the programming task below in a Python markdown code block. Little Masha loves arranging her toys into piles on the floor. And she also hates it when somebody touches her toys. One day Masha arranged all her n toys into several piles and then her elder brother Sasha came and gathered all the piles into one. Havin...
{"inputs": ["8\n", "7\n", "6\n", "2\n", "1\n", "8\n", "6\n", "5\n"], "outputs": ["4140\n{1,2,3,4,5,6,7,8}\n{1,2,3,4,5,6,7},{8}\n{1,2,3,4,5,6},{7},{8}\n{1,2,3,4,5,6},{7,8}\n{1,2,3,4,5,6,8},{7}\n{1,2,3,4,5,8},{6},{7}\n{1,2,3,4,5},{6,8},{7}\n{1,2,3,4,5},{6},{7,8}\n{1,2,3,4,5},{6},{7},{8}\n{1,2,3,4,5},{6,7},{8}\n{1,2,3,4,5...
coding
545
Solve the programming task below in a Python markdown code block. You have a two-dimensional list in the following format: ```python data = [[2, 5], [3, 4], [8, 7]] ``` Each sub-list contains two items, and each item in the sub-lists is an integer. Write a function `process_data()` that processes each sub-list like ...
{"functional": "_inputs = [[[[2, 5], [3, 4], [8, 7]]], [[[2, 9], [2, 4], [7, 5]]], [[[5, 4], [6, 4]]], [[[2, 1], [5, 3], [7, 4], [10, 6]]]]\n_outputs = [[3], [28], [2], [24]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol,...
coding
207
Solve the programming task below in a Python markdown code block. Chef usually likes to play cricket, but now, he is bored of playing it too much, so he is trying new games with strings. Chef's friend Dustin gave him binary strings $S$ and $R$, each with length $N$, and told him to make them identical. However, unlike ...
{"inputs": ["2\n5\n11000\n01001\n3\n110\n001"], "outputs": ["YES\nNO"]}
coding
478
Solve the programming task below in a Python markdown code block. Sam is playing with an array, $\mbox{A}$, of $N$ positive integers. Sam writes a list, $\mbox{S}$, containing all $\mbox{A}$'s contiguous subarrays, and then replaces each subarray with its respective maximum element. For example, consider the following...
{"inputs": ["2\n3 2\n1 2 3 \n3 1 \n1 2 3 \n"], "outputs": ["3\n5\n"]}
coding
613
Solve the programming task below in a Python markdown code block. Given a square table sized NxN (3 ≤ N ≤ 5,000; rows and columns are indexed from 1) with a robot on it. The robot has a mission of moving from cell (1, 1) to cell (N, N) using only the directions "right" or "down". You are requested to find the number of...
{"inputs": ["4 2\n4 3\n5 3\n0 0", "2 2\n4 3\n5 3\n0 0", "2 2\n5 3\n5 3\n0 0", "2 1\n4 3\n5 3\n0 0", "2 1\n4 2\n5 3\n0 0", "2 2\n5 5\n5 2\n0 0", "2 1\n3 2\n5 3\n0 0", "2 2\n5 0\n5 3\n0 0"], "outputs": ["4\n8\n18", "774058230\n8\n18\n", "774058230\n18\n18\n", "2\n8\n18\n", "2\n4\n18\n", "774058230\n18\n6\n", "2\n2\n18\n"...
coding
318
Solve the programming task below in a Python markdown code block. One day Nikita found the string containing letters "a" and "b" only. Nikita thinks that string is beautiful if it can be cut into 3 strings (possibly empty) without changing the order of the letters, where the 1-st and the 3-rd one contain only letters...
{"inputs": ["a\n", "b\n", "a\n", "b\n", "ab\n", "ba\n", "bb\n", "aa\n"], "outputs": ["1", "1", "1\n", "1\n", "2", "2", "2", "2"]}
coding
236
Solve the programming task below in a Python markdown code block. In this Kata, you will be given a list of strings and your task will be to find the strings that have the same characters and return the sum of their positions as follows: ```Haskell solve(["abc","abbc", "ab", "xyz", "xy", "zzyx"]) = [1,8] -- we see th...
{"functional": "_inputs = [[['abc', 'abbc', 'ab', 'xyz', 'xy', 'zzyx']], [['wkskkkkkk', 'fokoo', 'wkskk', 'uizzzz', 'fokooff', 'wkskkkk', 'uizzzzzzz']], [['xhuhhh', 'dghgg', 'dghgghh', 'mrerrrrrr', 'xhuhhhhhh', 'mrerrr']], [['uczcccccc', 'idffffiii', 'pnjjjjjjj', 'pnjjjj', 'idffff', 'uczcccc', 'uczcc']], [['rvjvvvv', '...
coding
342
Solve the programming task below in a Python markdown code block. Learning to code around your full time job is taking over your life. You realise that in order to make significant steps quickly, it would help to go to a coding bootcamp in London. Problem is, many of them cost a fortune, and those that don't still inv...
{"functional": "_inputs = [['Can I have a sabbatical?', 5, 5], ['Why are you shouting?', 7, 2], ['What do you mean I cant learn to code??', 8, 9], ['Please calm down', 9, 1], ['I can?! Nice. FaC..Im coming :D', 9, 9]]\n_outputs = [['Sabbatical! Boom!'], ['Back to your desk, boy.'], ['Sabbatical! Boom!'], ['Back to your...
coding
297
Solve the programming task below in a Python markdown code block. And where the are the phone numbers? You are given a string s consisting of lowercase English letters and an integer k. Find the lexicographically smallest string t of length k, such that its set of letters is a subset of the set of letters of s and s i...
{"inputs": ["1 3\nf\n", "1 3\nf\n", "1 3\ne\n", "1 6\ne\n", "2 3\nba\n", "2 3\ngi\n", "2 3\ngi\n", "2 3\nhi\n"], "outputs": ["fff\n", "fff\n", "eee\n", "eeeeee\n", "baa\n", "gig\n", "gig\n", "hih\n"]}
coding
447
Solve the programming task below in a Python markdown code block. Chef goes to the supermarket to buy some items. Luckily there's a sale going on under which Chef gets the following offer: If Chef buys 3 items then he gets the item (out of those 3 items) having the lowest price as free. For e.g. if Chef bought 3 it...
{"inputs": ["3\n6 2 4\n3 3 3\n8 4 4\n"], "outputs": ["10\n6\n12\n"]}
coding
402
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin chinese, Russian and Vietnamese as well. Chef has a sequence A containing N integers A_{1}, A_{2}, ..., A_{N}. Chef is playing a game with this sequence. In this game, he may perform the following operation any num...
{"inputs": ["2\n2\n1 2\n5\n7 4 3 2 6"], "outputs": ["2\n1"]}
coding
337
Solve the programming task below in a Python markdown code block. There is a sequence of colorful stones. The color of each stone is one of red, green, or blue. You are given a string s. The i-th (1-based) character of s represents the color of the i-th stone. If the character is "R", "G", or "B", the color of the corr...
{"inputs": ["R\nB\n", "R\nB\n", "S\nB\n", "S\nC\n", "S\nD\n", "T\nD\n", "U\nD\n", "R\nD\n"], "outputs": ["1\n", "1", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n"]}
coding
437
Solve the programming task below in a Python markdown code block. Chef has two numbers A and B. In one operation, Chef can choose either A or B and multiply it by 2. Determine whether he can make both A and B equal after any number (possibly, zero) of moves. ------ Input Format ------ - The first line of input wil...
{"inputs": ["4\n5 20\n6 6\n12 2\n50 20\n"], "outputs": ["YES\nYES\nNO\nNO\n"]}
coding
311
Solve the programming task below in a Python markdown code block. You are given a permutation P of length N. You can perform the following operation on P: Choose any i and j such that i < j and P_{i} < P_{j}, and remove exactly one of them from the array. After removing, the remaining parts of the array are concatenate...
{"inputs": ["3\n4\n3 1 2 4\n3\n2 3 1\n6\n5 2 3 6 1 4\n"], "outputs": ["YES\nNO\nYES\n"]}
coding
675
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an array intervals where intervals[i] = [li, ri] represent the interval [li, ri), remove all intervals that are covered by another interval in the list. The interval [a, b) is covered by the interval [c, d) if a...
{"functional": "def check(candidate):\n assert candidate(intervals = [[1,4],[3,6],[2,8]]) == 2\n\n\ncheck(Solution().removeCoveredIntervals)"}
coding
123
Solve the programming task below in a Python markdown code block. We have N integers. The i-th number is A_i. \{A_i\} is said to be pairwise coprime when GCD(A_i,A_j)=1 holds for every pair (i, j) such that 1\leq i < j \leq N. \{A_i\} is said to be setwise coprime when \{A_i\} is not pairwise coprime but GCD(A_1,\ldots...
{"inputs": ["3\n4 4 2", "3\n4 3 1", "3\n4 4 5", "3\n4 8 2", "3\n8 8 2", "3\n4 4 1", "3\n4 4 4", "3\n6 8 2"], "outputs": ["not coprime\n", "pairwise coprime\n", "setwise coprime\n", "not coprime\n", "not coprime\n", "setwise coprime\n", "not coprime\n", "not coprime\n"]}
coding
318
Solve the programming task below in a Python markdown code block. A bracket is considered to be any one of the following characters: (, ), {, }, [, or ]. Two brackets are considered to be a matched pair if the an opening bracket (i.e., (, [, or {) occurs to the left of a closing bracket (i.e., ), ], or }) of the exac...
{"inputs": ["3\n{[()]}\n{[(])}\n{{[[(())]]}}\n"], "outputs": ["YES\nNO\nYES\n"]}
coding
540
Solve the programming task below in a Python markdown code block. Chef is playing a game on the non-negative x-axis. It takes him $1$ second to reach from $i^{th}$ position to $(i-1)^{th}$ position or $(i+1)^{th}$ position. The chef never goes to the negative x-axis. Also, Chef doesn't stop at any moment of time. The ...
{"inputs": ["5\n0 1\n1 1\n2 1\n1 3\n4 6"], "outputs": ["0\n1\n4\n5\n46"]}
coding
748
Solve the programming task below in a Python markdown code block. Given an array A of length N, your task is to find the element which repeats in A maximum number of times as well as the corresponding count. In case of ties, choose the smaller element first. ------ Input ------ First line of input contains an intege...
{"inputs": ["2\n5\n1 2 3 2 5\n6\n1 2 2 1 1 2"], "outputs": ["2 2\n1 3"]}
coding
282
Solve the programming task below in a Python markdown code block. Due to the COVID pandemic, maintaining social distancing is of utmost importance. In this problem, you'd calculate how many days would it take to reach an apocalypse from an initial case if nobody maintains social distancing. The Earth is flat (for this ...
{"inputs": ["2\n4 5\n2 1\n3 4\n1 1"], "outputs": ["5\n3"]}
coding
614
Solve the programming task below in a Python markdown code block. You have a sequence $a$ with length $N$ created by removing some elements (possibly zero) from a permutation of numbers $(1, 2, \dots, N)$. When an element is removed, the length of the sequence doesn't change, but there is an empty spot left where the r...
{"inputs": ["1\n3 1\n2 0 0"], "outputs": ["2"]}
coding
424
Solve the programming task below in a Python markdown code block. problem Chairman K is a regular customer of the JOI pizza shop in the center of JOI city. For some reason, he decided to start a life-saving life this month. So he wanted to order the pizza with the highest calories per dollar among the pizzas he could ...
{"inputs": ["3\n2 3\n7\n0\n37\n110", "3\n2 1\n7\n0\n37\n110", "3\n2 1\n7\n0\n37\n010", "3\n2 1\n2\n0\n35\n010", "3\n2 2\n2\n0\n35\n000", "3\n5 2\n1\n0\n45\n101", "3\n1 2\n1\n0\n45\n101", "3\n2 1\n8\n0\n37\n010"], "outputs": ["23\n", "39\n", "14\n", "12\n", "9\n", "16\n", "34\n", "15\n"]}
coding
737
Please solve the programming task below using a self-contained code snippet in a markdown code block. There is an undirected graph consisting of n nodes numbered from 1 to n. You are given the integer n and a 2D array edges where edges[i] = [ai, bi] indicates that there is an edge between nodes ai and bi. The graph ca...
{"functional": "def check(candidate):\n assert candidate(n = 5, edges = [[1,2],[2,3],[3,4],[4,2],[1,4],[2,5]]) == True\n assert candidate(n = 4, edges = [[1,2],[3,4]]) == True\n assert candidate(n = 4, edges = [[1,2],[1,3],[1,4]]) == False\n\n\ncheck(Solution().isPossible)"}
coding
175
Solve the programming task below in a Python markdown code block. In a tournament, $n$ players play against each other exactly once. Each game results in exactly one player winning. There are no ties. You have been given a scorecard containing the scores of each player at the end of the tournament. The score of a playe...
{"inputs": ["5\n3\n-1 -1 2\n3\n-1 -1 -1\n4\n0 1 2 3\n2\n1 1\n4\n-1 -1 -1 2\n"], "outputs": ["2\n7\n1\n0\n12\n"]}
coding
550
Solve the programming task below in a Python markdown code block. There are n problems prepared for the next Codeforces round. They are arranged in ascending order by their difficulty, and no two problems have the same difficulty. Moreover, there are m pairs of similar problems. Authors want to split problems between t...
{"inputs": ["2 0\n", "3 0\n", "4 0\n", "2 0\n", "4 0\n", "3 0\n", "7 0\n", "5 0\n"], "outputs": ["1\n", "2\n", "3\n", "1\n", "3\n", "2\n", "6\n", "4\n"]}
coding
556
Solve the programming task below in a Python markdown code block. You are given a number $k$ and a string $s$ of length $n$, consisting of the characters '.' and '*'. You want to replace some of the '*' characters with 'x' characters so that the following conditions are met: The first character '*' in the original str...
{"inputs": ["5\n7 3\n.**.***\n5 1\n..*..\n5 2\n*.*.*\n3 2\n*.*\n1 1\n*\n", "5\n7 3\n.**.***\n5 2\n..*..\n5 2\n*.*.*\n3 2\n*.*\n1 1\n*\n", "5\n7 5\n.**.***\n5 1\n..*..\n5 2\n*.*.*\n3 2\n*.*\n1 1\n*\n", "5\n7 3\n***..**\n5 1\n*....\n5 2\n*.*.*\n3 2\n*.*\n1 1\n*\n", "5\n7 4\n.****.*\n5 2\n..*..\n5 4\n*.*.*\n3 2\n*.*\n1 2\...
coding
531
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"]}
coding
337
Solve the programming task below in a Python markdown code block. Iahub is so happy about inventing bubble sort graphs that he's staying all day long at the office and writing permutations. Iahubina is angry that she is no more important for Iahub. When Iahub goes away, Iahubina comes to his office and sabotage his res...
{"inputs": ["2\n-1 -1\n", "2\n-1 -1\n", "5\n-1 -1 4 5 1\n", "5\n-1 -1 4 2 1\n", "5\n-1 -1 4 3 -1\n", "5\n-1 -1 4 1 -1\n", "5\n-1 -1 4 5 -1\n", "5\n-1 -1 4 2 -1\n"], "outputs": ["1\n", "1\n", "1\n", "2\n", "2\n", "3\n", "3\n", "3\n"]}
coding
472
Solve the programming task below in a Python markdown code block. In the world of birding there are four-letter codes for the common names of birds. These codes are created by some simple rules: * If the bird's name has only one word, the code takes the first four letters of that word. * If the name is made up of two...
{"functional": "_inputs = [[['American Redstart', 'Northern Cardinal', 'Pine Grosbeak', 'Barred Owl', 'Starling', \"Cooper's Hawk\", 'Pigeon']], [['Great Crested Flycatcher', 'Bobolink', 'American White Pelican', 'Red-Tailed Hawk', 'Eastern Screech Owl', 'Blue Jay']], [['Black-Crowned Night Heron', 'Northern Mockingbir...
coding
316
Solve the programming task below in a Python markdown code block. You will have a list of rationals in the form ``` lst = [ [numer_1, denom_1] , ... , [numer_n, denom_n] ] ``` or ``` lst = [ (numer_1, denom_1) , ... , (numer_n, denom_n) ] ``` where all numbers are positive integers. You have to produce their sum `N /...
{"functional": "_inputs = [[[[1, 2], [1, 3], [1, 4]]], [[[1, 3], [5, 3]]], [[[12, 3], [15, 3]]], [[[2, 7], [1, 3], [1, 12]]], [[[69, 130], [87, 1310], [3, 4]]], [[[77, 130], [84, 131], [60, 80]]], [[[6, 13], [187, 1310], [31, 41]]], [[[8, 15], [7, 111], [4, 25]]], [[]], [[[81345, 15786], [87546, 11111111], [43216, 2556...
coding
587
Solve the programming task below in a Python markdown code block. Permutation p is an ordered set of integers p_1, p_2, ..., p_{n}, consisting of n distinct positive integers, each of them doesn't exceed n. We'll denote the i-th element of permutation p as p_{i}. We'll call number n the size or the length of permuta...
{"inputs": ["1 0\n", "2 1\n", "3 2\n", "4 1\n", "7 4\n", "7 7\n", "8 4\n", "8 5\n"], "outputs": ["1\n", "0\n", "4\n", "6\n", "328\n", "0\n", "2658\n", "688\n"]}
coding
425
Solve the programming task below in a Python markdown code block. You are stacking some boxes containing gold weights on top of each other. If a box contains more weight than the box below it, it will crash downwards and combine their weights. e.g. If we stack [2] on top of [1], it will crash downwards and become a sin...
{"functional": "_inputs = [[[[1]]], [[[1, 2]]], [[[2], [1]]]]\n_outputs = [[[1]], [[1, 2]], [[3]]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) != le...
coding
411
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an array of integers nums and an integer k. A continuous subarray is called nice if there are k odd numbers on it. Return the number of nice sub-arrays.   Please complete the following python code precisely: ```...
{"functional": "def check(candidate):\n assert candidate(nums = [1,1,2,1,1], k = 3) == 2\n assert candidate(nums = [2,4,6], k = 1) == 0\n assert candidate(nums = [2,2,2,1,2,2,1,2,2,2], k = 2) == 16\n\n\ncheck(Solution().numberOfSubarrays)"}
coding
89
Solve the programming task below in a Python markdown code block. The story of Harry Potter begins when Lord Voldemort arrives at his house at Privet Drive. Harry's house has N rooms placed in one line. Each room has its own energy level and no two rooms have exactly same energy. Lord Voldemort arrives at the room whic...
{"inputs": ["3\n4 2 1"], "outputs": ["10"]}
coding
310
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"]}
coding
358
Solve the programming task below in a Python markdown code block. G: Palindromic Subsequences problem Given a string S consisting only of lowercase letters, find out how many subsequences of this string S are not necessarily continuous and are palindromes. Here, a subsequence that is not necessarily continuous with ...
{"inputs": ["ccpa", "cnbc", "emec", "ccoa", "aocc", "pcca", "ccao", "pcda"], "outputs": ["4\n", "6\n", "5\n", "4\n", "4\n", "4\n", "4\n", "4\n"]}
coding
474
Solve the programming task below in a Python markdown code block. Each number should be formatted that it is rounded to two decimal places. You don't need to check whether the input is a valid number because only valid numbers are used in the tests. ``` Example: 5.5589 is rounded 5.56 3.3424 is rounded 3.34 ``` ...
{"functional": "_inputs = [[4.659725356], [173735326.37837327], [4.653725356]]\n_outputs = [[4.66], [173735326.38], [4.65]]\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
107
Solve the programming task below in a Python markdown code block. E869120 found a chest which is likely to contain treasure. However, the chest is locked. In order to open it, he needs to enter a string S consisting of lowercase English letters. He also found a string S', which turns out to be the string S with some ...
{"inputs": [">q???d?>\n_ba", "d>>>???q\na`a", "d>>>???q\naaa", "??p??d??\nabb", "??p??d??\n`bb", "??p??d??\n`ab", "??p??d??\nba`", "??p??d??\nb``"], "outputs": [">q_bada>\n", "d>>>a`aq\n", "d>>>aaaq\n", "UNRESTORABLE\n", "UNRESTORABLE\n", "UNRESTORABLE\n", "UNRESTORABLE\n", "UNRESTORABLE\n"]}
coding
313
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a 2D integer array coordinates and an integer k, where coordinates[i] = [xi, yi] are the coordinates of the ith point in a 2D plane. We define the distance between two points (x1, y1) and (x2, y2) as (x1...
{"functional": "def check(candidate):\n assert candidate(coordinates = [[1,2],[4,2],[1,3],[5,2]], k = 5) == 2\n assert candidate(coordinates = [[1,3],[1,3],[1,3],[1,3],[1,3]], k = 0) == 10\n\n\ncheck(Solution().countPairs)"}
coding
166
Solve the programming task below in a Python markdown code block. We have three boxes A, B, and C, each of which contains an integer. Currently, the boxes A, B, and C contain the integers X, Y, and Z, respectively. We will now do the operations below in order. Find the content of each box afterward. - Swap the con...
{"inputs": ["2 2 3", "2 2 5", "2 2 7", "3 2 7", "4 1 9", "3 1 9", "3 2 9", "1 2 3"], "outputs": ["3 2 2\n", "5 2 2\n", "7 2 2\n", "7 3 2\n", "9 4 1\n", "9 3 1\n", "9 3 2\n", "3 1 2"]}
coding
248
Solve the programming task below in a Python markdown code block. Along a road running in an east-west direction, there are A shrines and B temples. The i-th shrine from the west is located at a distance of s_i meters from the west end of the road, and the i-th temple from the west is located at a distance of t_i meter...
{"inputs": ["1 1 1\n1\n2\n3\n", "2 3 4\n110\n677\n400\n900\n1000\n1\n2000\n324\n756", "2 3 4\n110\n677\n769\n900\n1000\n1\n2000\n324\n756", "2 3 4\n110\n677\n769\n900\n1000\n2\n2000\n324\n756", "2 3 4\n000\n600\n400\n900\n1000\n150\n798\n899\n799", "2 3 3\n110\n608\n400\n900\n1000\n21\n1894\n899\n799", "2 3 3\n110\n608...
coding
763
Solve the programming task below in a Python markdown code block. You are beta testing the new secret Terraria update. This update will add quests to the game! Simply, the world map can be represented as an array of length $n$, where the $i$-th column of the world has height $a_i$. There are $m$ quests you have to te...
{"inputs": ["10 1\n5 5 5 3 5 5 5 5 5 1\n10 7\n", "7 6\n10 8 9 6 8 12 7\n1 2\n1 7\n4 6\n7 1\n3 5\n4 2\n", "8 6\n1 2 3 4 5 6 7 8\n1 8\n7 1\n1 2\n2 3\n4 5\n4 5\n", "10 4\n1 1 1 1 1 1 1 1 1 1\n1 10\n10 1\n10 9\n1 2\n", "38 1\n2 999999999 2 999999999 2 999999999 2 999999999 2 999999999 2 999999999 2 999999999 2 999999999 2 ...
coding
630
Solve the programming task below in a Python markdown code block. You are given a permutation P_1 ... P_N of the set {1, 2, ..., N}. You can apply the following operation to this permutation, any number of times (possibly zero): * Choose two indices i,j (1 ≦ i < j ≦ N), such that j - i ≧ K and |P_i - P_j| = 1. Then, ...
{"inputs": ["4 4\n4 2 3 1", "4 1\n4 2 3 1", "4 2\n4 3 2 1", "4 3\n4 1 3 2", "4 2\n4 1 3 2", "4 3\n3 2 4 1", "4 3\n4 2 3 1", "4 5\n4 2 3 1"], "outputs": ["4\n2\n3\n1\n", "1\n2\n3\n4\n", "4\n3\n2\n1\n", "4\n1\n3\n2\n", "2\n1\n4\n3\n", "3\n2\n4\n1\n", "4\n2\n3\n1\n", "4\n2\n3\n1\n"]}
coding
306
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a 2D integer array intervals where intervals[i] = [lefti, righti] represents the inclusive interval [lefti, righti]. You have to divide the intervals into one or more groups such that each interval is in...
{"functional": "def check(candidate):\n assert candidate(intervals = [[5,10],[6,8],[1,5],[2,3],[1,10]]) == 3\n assert candidate(intervals = [[1,3],[5,6],[8,10],[11,13]]) == 1\n\n\ncheck(Solution().minGroups)"}
coding
162
Solve the programming task below in a Python markdown code block. As you probably know, Fibonacci sequence are the numbers in the following integer sequence: 1, 1, 2, 3, 5, 8, 13... Write a method that takes the index as an argument and returns last digit from fibonacci number. Example: getLastDigit(15) - 610. Your m...
{"functional": "_inputs = [[193150], [300], [20001], [800], [1001], [100], [260], [1111], [1234], [99999], [10], [234], [193241], [79], [270]]\n_outputs = [[5], [0], [6], [5], [1], [5], [5], [9], [7], [6], [5], [2], [1], [1], [0]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b,...
coding
192
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an integer array arr and an integer difference, return the length of the longest subsequence in arr which is an arithmetic sequence such that the difference between adjacent elements in the subsequence equals di...
{"functional": "def check(candidate):\n assert candidate(arr = [1,2,3,4], difference = 1) == 4\n assert candidate(arr = [1,3,5,7], difference = 1) == 1\n assert candidate(arr = [1,5,7,8,5,3,4,2,1], difference = -2) == 4\n\n\ncheck(Solution().longestSubsequence)"}
coding
119
Solve the programming task below in a Python markdown code block. Chef's son wants to go on a roller coaster ride. The height of Chef's son is X inches while the minimum height required to go on the ride is H inches. Determine whether he can go on the ride or not. ------ Input Format ------ - The first line contains...
{"inputs": ["4\n15 20\n50 48\n32 32\n38 39\n"], "outputs": ["NO\nYES\nYES\nNO"]}
coding
357
Please solve the programming task below using a self-contained code snippet in a markdown code block. The appeal of a string is the number of distinct characters found in the string. For example, the appeal of "abbca" is 3 because it has 3 distinct characters: 'a', 'b', and 'c'. Given a string s, return the total ap...
{"functional": "def check(candidate):\n assert candidate(s = \"abbca\") == 28\n assert candidate(s = \"code\") == 20\n\n\ncheck(Solution().appealSum)"}
coding
122
Solve the programming task below in a Python markdown code block. The purpose of this kata is to work out just how many bottles of duty free whiskey you would have to buy such that the saving over the normal high street price would effectively cover the cost of your holiday. You will be given the high street price (n...
{"functional": "_inputs = [[12, 50, 1000], [17, 10, 500], [24, 35, 3000], [1400, 35, 10000], [700, 26, 7000]]\n_outputs = [[166], [294], [357], [20], [38]]\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
173
Solve the programming task below in a Python markdown code block. One day Greg and his friends were walking in the forest. Overall there were n people walking, including Greg. Soon he found himself in front of a river. The guys immediately decided to get across the river. Luckily, there was a boat by the river bank, ju...
{"inputs": ["1 50\n50\n", "1 204\n50\n", "1 2994\n100\n", "2 93\n50 50\n", "2 24\n50 50\n", "2 24\n96 50\n", "2 50\n50 50\n", "2 153\n100 50\n"], "outputs": ["1\n1", "1\n1", "1\n1", "-1\n0\n", "-1\n0\n", "-1\n0\n", "-1\n0", "1\n1"]}
coding
624
Solve the programming task below in a Python markdown code block. Bessie and the cows are playing with sequences and need your help. They start with a sequence, initially containing just the number 0, and perform n operations. Each operation is one of the following: Add the integer x_{i} to the first a_{i} elements of...
{"inputs": ["1\n2 1\n", "1\n2 0\n", "1\n2 1\n", "1\n2 0\n", "1\n2 -1\n", "1\n1 1 1\n", "1\n1 1 0\n", "1\n1 1 0\n"], "outputs": ["0.500000\n", "0.000000\n", "0.500000\n", "0.000000\n", "-0.500000\n", "1.000000\n", "0.000000\n", "0.000000\n"]}
coding
649
Solve the programming task below in a Python markdown code block. "We've tried solitary confinement, waterboarding and listening to Just In Beaver, to no avail. We need something extreme." "Little Alena got an array as a birthday present..." The array b of length n is obtained from the array a of length n and two int...
{"inputs": ["5\n1 2 3 4 5\n00001\n", "5\n1 2 3 4 5\n00001\n", "5\n0 2 3 4 5\n00001\n", "5\n2 0 4 0 2\n00001\n", "5\n1 2 3 0 5\n00001\n", "5\n2 2 3 0 5\n00001\n", "5\n2 0 3 0 5\n00001\n", "5\n2 0 4 0 5\n00001\n"], "outputs": ["6 1000000000\n", "6 1000000000\n", "6 1000000000\n", "5 1000000000\n", "6 1000000000\n", "6 10...
coding
631
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a 0-indexed 2D integer array peaks where peaks[i] = [xi, yi] states that mountain i has a peak at coordinates (xi, yi). A mountain can be described as a right-angled isosceles triangle, with its base alo...
{"functional": "def check(candidate):\n assert candidate(peaks = [[2,2],[6,3],[5,4]]) == 2\n assert candidate(peaks = [[1,3],[1,3]]) == 0\n\n\ncheck(Solution().visibleMountains)"}
coding
167
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a positive integer num, return the number of positive integers less than or equal to num whose digit sums are even. The digit sum of a positive integer is the sum of all its digits.   Please complete the followi...
{"functional": "def check(candidate):\n assert candidate(num = 4) == 2\n assert candidate(num = 30) == 14\n\n\ncheck(Solution().countEven)"}
coding
86
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given two strings s and t, determine if they are isomorphic. Two strings s and t are isomorphic if the characters in s can be replaced to get t. All occurrences of a character must be replaced with another character w...
{"functional": "def check(candidate):\n assert candidate(s = \"egg\", t = \"add\") == True\n assert candidate(s = \"foo\", t = \"bar\") == False\n assert candidate(s = \"paper\", t = \"title\") == True\n\n\ncheck(Solution().isIsomorphic)"}
coding
122
Please solve the programming task below using a self-contained code snippet in a markdown code block. Return the number of permutations of 1 to n so that prime numbers are at prime indices (1-indexed.) (Recall that an integer is prime if and only if it is greater than 1, and cannot be written as a product of two posit...
{"functional": "def check(candidate):\n assert candidate(n = 5) == 12\n assert candidate(n = 100) == 682289015\n\n\ncheck(Solution().numPrimeArrangements)"}
coding
130
Solve the programming task below in a Python markdown code block. problem There is a mysterious device $ M $, and if you put Tanuki and Fox in this device, one animal will come out from the device (hereinafter, Tanuki will be $ T $ and Fox will be $ F $). $ M (x, y) $ represents an animal that came out by putting ani...
{"inputs": ["3\nF S T", "3\nF R T", "3\nG S T", "3\nG R T", "3\nH R T", "3\nF U T", "3\nE S T", "3\nE T T"], "outputs": ["T\n", "T\n", "T\n", "T\n", "T\n", "T\n", "T\n", "T\n"]}
coding
245
Solve the programming task below in a Python markdown code block. ## Story Before we dive into the exercise, I would like to show you why these numbers are so important in computer programming today. It all goes back to the time of 19th century. Where computers we know today were non-existing. The first ever **comput...
{"functional": "_inputs = [[0], [3], [1337]]\n_outputs = [[1], [0], [0]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) != len(b): return False\n ...
coding
731
Solve the programming task below in a Python markdown code block. The task is very simple. You must to return pyramids. Given a number ```n``` you print a pyramid with ```n``` floors For example , given a ```n=4``` you must to print this pyramid: ``` /\ / \ / \ /______\ ``` Other example, given a ``...
{"functional": "_inputs = [[4], [6], [10]]\n_outputs = [[' /\\\\\\n / \\\\\\n / \\\\\\n/______\\\\\\n'], [' /\\\\\\n / \\\\\\n / \\\\\\n / \\\\\\n / \\\\\\n/__________\\\\\\n'], [' /\\\\\\n / \\\\\\n / \\\\\\n / \\\\\\n / \\\\\\n / ...
coding
236
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...
coding
551
Solve the programming task below in a Python markdown code block. n children are standing in a circle and playing the counting-out game. Children are numbered clockwise from 1 to n. In the beginning, the first child is considered the leader. The game is played in k steps. In the i-th step the leader counts out a_{i} pe...
{"inputs": ["2 1\n1\n", "2 1\n2\n", "2 1\n3\n", "2 1\n1\n", "2 1\n3\n", "2 1\n2\n", "3 1\n2\n", "3 1\n1\n"], "outputs": ["2 \n", "1 \n", "2 \n", "2\n", "2\n", "1\n", "3\n", "2\n"]}
coding
438
Solve the programming task below in a Python markdown code block. This problem was part of the CodeChef April Challenge. All user submissions for this contest problem are publicly available here. In the game of "BattleShip V", you control a cannon which is attacking a large enemy battleship, armed with many guns. You...
{"inputs": ["1\n2 -2 1"], "outputs": ["2"]}
coding
384
Solve the programming task below in a Python markdown code block. ButCoder Inc. runs a programming competition site called ButCoder. In this site, a user is given an integer value called rating that represents his/her skill, which changes each time he/she participates in a contest. The initial value of a new user's rat...
{"inputs": ["31 144 600", "1131 7 0000", "1131 8 0000", "1152 8 0000", "5856 883 583", "6439 987 572", "5856 500 2000", "4000 2000 312"], "outputs": ["1\n", "323\n", "283\n", "287\n", "35\n", "29\n", "-1\n", "5\n"]}
coding
360
Solve the programming task below in a Python markdown code block. The sequence is called ordered if it is non-decreasing or non-increasing. For example, sequnces [3, 1, 1, 0] and [1, 2, 3, 100] are ordered, but the sequence [1, 3, 3, 1] is not. You are given a sequence of numbers. You are to find it's shortest subseque...
{"inputs": ["2\n7 8\n", "2\n0 8\n", "2\n0 2\n", "2\n0 3\n", "2\n0 6\n", "2\n-1 6\n", "3\n3 1 2\n", "3\n3 1 1\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "3\n1 2 3\n", "0\n"]}
coding
315
Solve the programming task below in a Python markdown code block. You are given ${D}$ datasets where each dataset is in the form of two integers, $m$ and ${a}$, such that: $n=\prod\limits_{i=1}^m p_i^{a+i},\text{where}~p_i~\text{is the}~i^{th}~\text{prime}.$ For each dataset, find and print the following on a new line...
{"inputs": ["3\n2 0\n3 0\n2 4\n"], "outputs": ["18\n180\n588\n"]}
coding
511
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a rectangle of size n x m, return the minimum number of integer-sided squares that tile the rectangle.   Please complete the following python code precisely: ```python class Solution: def tilingRectangle(sel...
{"functional": "def check(candidate):\n assert candidate(n = 2, m = 3) == 3\n assert candidate(n = 5, m = 8) == 5\n assert candidate(n = 11, m = 13) == 6\n\n\ncheck(Solution().tilingRectangle)"}
coding
74
Solve the programming task below in a Python markdown code block. We all know how to calculate $a^{b}$ using $\boldsymbol{b}$ operations by multiplying $1$ by $\boldsymbol{a}$ a total of $\boldsymbol{b}$ times. The drawback to this method is that $\boldsymbol{b}$ can be large, which makes exponentiation very slow. The...
{"inputs": ["3\n2 0 9 1000\n0 1 5 10\n8 2 10 1000000000\n"], "outputs": ["512 0\n0 1\n880332800 927506432\n"]}
coding
554
Solve the programming task below in a Python markdown code block. Description Lets imagine a yoga classroom as a Square 2D Array of Integers ```classroom```, with each integer representing a person, and the value representing their skill level. ``` classroom = [ [3,2,1,3], [1,3,2,1], ...
{"functional": "_inputs = [[[[0, 0], [0, 0]], [1, 1, 0, 1, 2, 3, 0, 1, 5]], [[], [1, 3, 4]], [[[0, 0], [0, 0]], []], [[], []]]\n_outputs = [[8], [0], [0], [0]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n...
coding
365
Solve the programming task below in a Python markdown code block. Modern text editors usually show some information regarding the document being edited. For example, the number of words, the number of pages, or the number of characters. In this problem you should implement the similar functionality. You are given a s...
{"inputs": ["1\n_\n", "1\na\n", "1\n_\n", "1\na\n", "1\nb\n", "1\nc\n", "1\nd\n", "1\ne\n"], "outputs": ["0 0\n", "1 0\n", "0 0\n", "1 0\n", "1 0\n", "1 0\n", "1 0\n", "1 0\n"]}
coding
596
Solve the programming task below in a Python markdown code block. In Summer Informatics School, if a student doesn't behave well, teachers make a hole in his badge. And today one of the teachers caught a group of $n$ students doing yet another trick. Let's assume that all these students are numbered from $1$ to $n$. ...
{"inputs": ["1\n1\n", "1\n1\n", "2\n2 1\n", "2\n2 1\n", "3\n2 3 2\n", "3\n1 2 3\n", "3\n2 3 1\n", "3\n2 3 1\n"], "outputs": ["1 \n", "1\n", "1 2 \n", "1 2\n", "2 2 3 \n", "1 2 3 \n", "1 2 3 \n", "1 2 3\n"]}
coding
603