task_type
stringclasses
4 values
problem
stringlengths
14
5.23k
solution
stringlengths
1
8.29k
problem_tokens
int64
9
1.02k
solution_tokens
int64
1
1.98k
coding
Solve the programming task below in a Python markdown code block. Takahashi is distributing N balls to K persons. If each person has to receive at least one ball, what is the maximum possible difference in the number of balls received between the person with the most balls and the person with the fewest balls? Constr...
{"inputs": ["9 5", "4 2", "2 2", "2 3", "0 3", "1 3", "0 9", "0 6"], "outputs": ["4\n", "2\n", "0\n", "-1\n", "-3\n", "-2\n", "-9\n", "-6\n"]}
153
78
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an integer array nums and an integer k. In one operation, you can pick two numbers from the array whose sum equals k and remove them from the array. Return the maximum number of operations you can perfor...
{"functional": "def check(candidate):\n assert candidate(nums = [1,2,3,4], k = 5) == 2\n assert candidate(nums = [3,1,3,4,3], k = 6) == 1\n\n\ncheck(Solution().maxOperations)"}
100
67
coding
Solve the programming task below in a Python markdown code block. # Task You are given a car odometer which displays the miles traveled as an integer. The odometer has a defect, however: it proceeds from digit `3` to digit `5` always skipping the digit `4`. This defect shows up in all positions (ones, tens, hundre...
{"functional": "_inputs = [[13], [15], [55], [2005], [1500], [999999], [165826622]]\n_outputs = [[12], [13], [40], [1462], [1053], [531440], [69517865]]\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 ...
285
236
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You have n tasks and m workers. Each task has a strength requirement stored in a 0-indexed integer array tasks, with the ith task requiring tasks[i] strength to complete. The strength of each worker is stored in a 0-i...
{"functional": "def check(candidate):\n assert candidate(tasks = [3,2,1], workers = [0,3,3], pills = 1, strength = 1) == 3\n assert candidate(tasks = [5,4], workers = [0,0,0], pills = 1, strength = 5) == 1\n assert candidate(tasks = [10,15,30], workers = [0,10,10,10,10], pills = 3, strength = 10) == 2\n ass...
233
178
coding
Solve the programming task below in a Python markdown code block. You are given two integers $x$ and $y$. You can perform two types of operations: Pay $a$ dollars and increase or decrease any of these integers by $1$. For example, if $x = 0$ and $y = 7$ there are four possible outcomes after this operation: $x = 0$...
{"inputs": ["1\n62 7\n2 4\n", "1\n62 7\n3 4\n", "1\n62 3\n3 4\n", "1\n62 3\n6 4\n", "1\n62 2\n6 4\n", "1\n62 2\n4 4\n", "1\n62 2\n7 4\n", "1\n35 2\n7 4\n"], "outputs": ["138\n", "193\n", "189\n", "366\n", "368\n", "248\n", "428\n", "239\n"]}
501
158
coding
Solve the programming task below in a Python markdown code block. Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. You are given a matrix $A$ with $N$ rows (numbered $1$ through $N$) and $M$ columns (numbered $1$ through $M$). You need to fill the matrix with can...
{"inputs": ["2\n4 4 4 6\n3 4 4 5"], "outputs": ["48\n30"]}
360
32
coding
Solve the programming task below in a Python markdown code block. Your friend is developing a computer game. He has already decided how the game world should look like — it should consist of n locations connected by m two-way passages. The passages are designed in such a way that it should be possible to get from any l...
{"inputs": ["4 3\n1 2\n4 2\n3 2\n", "4 3\n1 2\n4 3\n3 2\n", "5 5\n1 2\n2 3\n3 1\n4 1\n5 4\n", "5 5\n1 2\n2 3\n3 1\n4 1\n5 3\n", "5 5\n1 2\n2 3\n3 1\n4 1\n5 2\n", "5 6\n1 5\n2 3\n3 5\n2 1\n2 5\n2 4\n", "5 6\n1 5\n2 3\n3 5\n2 1\n2 5\n1 4\n", "5 6\n1 5\n3 3\n3 5\n2 2\n2 5\n2 4\n"], "outputs": ["2\n", "3\n", "2\n", "2\n", ...
444
242
coding
Solve the programming task below in a Python markdown code block. Read problems statements [Hindi] ,[Bengali] , [Mandarin chinese] , [Russian] and [Vietnamese] as well. Chef is stuck at the following problem. Help him solve it! Chef has a sequence of integers $A_{1}, A_{2}, \dots, A_{N}$. He should find the number of...
{"inputs": ["1\n5\n2 4 8 1 3"], "outputs": ["3"]}
433
24
coding
Solve the programming task below in a Python markdown code block. This version of the problem differs from the next one only in the constraint on n. Note that the memory limit in this problem is lower than in others. You have a vertical strip with n cells, numbered consecutively from 1 to n from top to bottom. You a...
{"inputs": ["29 2839\n", "29 3120\n", "54 3120\n", "54 2819\n", "54 3493\n", "54 3635\n", "54 3180\n", "84 3180\n"], "outputs": ["2780\n", "1565\n", "371\n", "1134\n", "224\n", "1941\n", "911\n", "2568\n"]}
513
139
coding
Solve the programming task below in a Python markdown code block. Chef has an array A of length N. He defines the *alternating sum* of the array as: S = |A_{1}| - |A_{2}| + |A_{3}| - |A_{4}| + \ldots (-1)^{N-1}\cdot |A_{N}| Chef is allowed to perform the following operation on the array at most once: Choose two indice...
{"inputs": ["2\n2\n10 -10\n7\n-3 -2 -1 0 1 2 3\n"], "outputs": ["0\n6\n"]}
527
41
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an m x n integer matrix grid where each cell is either 0 (empty) or 1 (obstacle). You can move up, down, left, or right from and to an empty cell in one step. Return the minimum number of steps to walk f...
{"functional": "def check(candidate):\n assert candidate( grid = [[0,0,0],[1,1,0],[0,0,0],[0,1,1],[0,0,0]], k = 1) == 6\n assert candidate(grid = [[0,1,1],[1,1,1],[1,0,0]], k = 1) == -1\n\n\ncheck(Solution().shortestPath)"}
159
99
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a string s of lowercase English letters and an array widths denoting how many pixels wide each lowercase English letter is. Specifically, widths[0] is the width of 'a', widths[1] is the width of 'b', and...
{"functional": "def check(candidate):\n assert candidate(widths = [10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10], s = \"abcdefghijklmnopqrstuvwxyz\") == [3,60]\n assert candidate(widths = [4,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10], s = \"bbbcccd...
227
217
coding
Solve the programming task below in a Python markdown code block. Berland Football Cup starts really soon! Commentators from all over the world come to the event. Organizers have already built $n$ commentary boxes. $m$ regional delegations will come to the Cup. Every delegation should get the same number of the commen...
{"inputs": ["9 7 3 8\n", "2 7 3 7\n", "7 2 3 7\n", "1 2 1 1\n", "9 2 1 1\n", "1 2 5 1\n", "7 2 1 2\n", "5 2 2 2\n"], "outputs": ["15\n", "14\n", "3\n", "1\n", "1\n", "1\n", "1\n", "2\n"]}
515
120
coding
Solve the programming task below in a Python markdown code block. Snuke has decided to play with N cards and a deque (that is, a double-ended queue). Each card shows an integer from 1 through N, and the deque is initially empty. Snuke will insert the cards at the beginning or the end of the deque one at a time, in orde...
{"inputs": ["4 2", "4 1", "1 1", "3 1", "5 2", "5 1", "9 2", "9 1"], "outputs": ["6", "4", "1", "2", "16", "8", "512", "128"]}
303
75
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. On a campus represented on the X-Y plane, there are n workers and m bikes, with n <= m. You are given an array workers of length n where workers[i] = [xi, yi] is the position of the ith worker. You are also given an a...
{"functional": "def check(candidate):\n assert candidate(workers = [[0,0],[2,1]], bikes = [[1,2],[3,3]]) == [1,0]\n assert candidate(workers = [[0,0],[1,1],[2,0]], bikes = [[1,0],[2,2],[2,1]]) == [0,2,1]\n\n\ncheck(Solution().assignBikes)"}
314
96
coding
Solve the programming task below in a Python markdown code block. The end of the school year is near and Ms. Manana, the teacher, will soon have to say goodbye to a yet another class. She decided to prepare a goodbye present for her n students and give each of them a jigsaw puzzle (which, as wikipedia states, is a tili...
{"inputs": ["2 2\n4 4\n", "2 2\n4 4\n", "2 2\n5 4\n", "2 2\n1000 4\n", "2 2\n1000 4\n", "2 2\n0000 4\n", "3 3\n4 1000 4\n", "3 3\n4 1000 4\n"], "outputs": ["0\n", "0\n", "1\n", "996\n", "996\n", "4\n", "996\n", "996\n"]}
459
145
coding
Solve the programming task below in a Python markdown code block. Sometimes it is hard to prepare tests for programming problems. Now Bob is preparing tests to new problem about strings — input data to his problem is one string. Bob has 3 wrong solutions to this problem. The first gives the wrong answer if the input da...
{"inputs": ["ab\ncc\ncd\n", "ab\ncc\ndd\n", "ab\ncc\ndc\n", "ba\ncc\ndd\n", "aa\ncc\ndd\n", "aa\ndc\ndd\n", "aa\ndc\ncd\n", "aa\ndc\nbd\n"], "outputs": ["5\n", "6\n", "5\n", "6\n", "6\n", "5\n", "5\n", "5\n"]}
235
112
coding
Solve the programming task below in a Python markdown code block. JavaScript provides a built-in parseInt method. It can be used like this: - `parseInt("10")` returns `10` - `parseInt("10 apples")` also returns `10` We would like it to return `"NaN"` (as a string) for the second case because the input string is not ...
{"functional": "_inputs = [['9'], ['09'], ['009'], [' 9'], [' 9 '], ['\\t9\\n'], ['5 friends'], ['5friends'], ['I <3 u'], ['17.42'], ['0x10'], ['123~~'], ['1 1'], ['1 2 3'], ['1.0']]\n_outputs = [[9], [9], [9], [9], [9], [9], ['NaN'], ['NaN'], ['NaN'], ['NaN'], ['NaN'], ['NaN'], ['NaN'], ['NaN'], ['NaN']]\nimport ma...
191
275
coding
Solve the programming task below in a Python markdown code block. Ichigo is on his way to save Rukia. Unfortunately, when Ichigo was busy fighting Renji, Kenpachi Zaraki had gone to the Dangai(the same place where Ichigo got his final Getsuga Tenshou) to train. Now, he has a Bankai called Tensa Quantum Computer and he ...
{"inputs": ["4\n1 1\n4 1\n4 -3\n1729 -786\n"], "outputs": ["0\n2\n6\n3170\n"]}
732
44
coding
Solve the programming task below in a Python markdown code block. Shaka and his brother have created a boring game which is played like this: They take a word composed of lowercase English letters and try to get the maximum possible score by building exactly 2 palindromic subsequences. The score obtained is the prod...
{"inputs": ["eeegeeksforskeeggeeks\n"], "outputs": ["50\n"]}
425
23
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a 0-indexed integer array nums. Initially, all of the indices are unmarked. You are allowed to make this operation any number of times: Pick two different unmarked indices i and j such that 2 * nums[i] ...
{"functional": "def check(candidate):\n assert candidate(nums = [3,5,2,4]) == 2\n assert candidate(nums = [9,2,5,4]) == 4\n assert candidate(nums = [7,6,8]) == 0\n\n\ncheck(Solution().maxNumOfMarkedIndices)"}
132
75
coding
Solve the programming task below in a Python markdown code block. Coolguy gives you a simple problem. Given a $1$-indexed array, $\mbox{A}$, containing $N$ elements, what will $\textit{and}$ be after this pseudocode is implemented and executed? Print $and\%(10^9+7)$. //f(a, b) is a function that returns the minimum el...
{"inputs": ["3\n3 2 1\n"], "outputs": ["6\n"]}
459
20
coding
Solve the programming task below in a Python markdown code block. Finally, College has started calling students back to campus. There are so many students and thus due to some safety measures the college can’t call back all the students on the same day. It currently has the capacity of screening K students on a single ...
{"inputs": ["3\n3 3\n3 2\n4 3\n"], "outputs": ["1\n2\n2\n"]}
475
30
coding
Solve the programming task below in a Python markdown code block. Polycarp likes numbers that are divisible by 3. He has a huge number $s$. Polycarp wants to cut from it the maximum number of numbers that are divisible by $3$. To do this, he makes an arbitrary number of vertical cuts between pairs of adjacent digits. ...
{"inputs": ["6\n", "4\n", "4\n", "5\n", "8\n", "1\n", "2\n", "7\n"], "outputs": ["1\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]}
621
70
coding
Solve the programming task below in a Python markdown code block. You get a new job working for Eggman Movers. Your first task is to write a method that will allow the admin staff to enter a person’s name and return what that person's role is in the company. You will be given an array of object literals holding the c...
{"functional": "_inputs = [['Dipper Pines'], ['Morty Smith'], ['Anna Bell'], ['Anna'], ['Bell Anna'], ['Jewel Bell'], ['Bell Jewel']]\n_outputs = [['Does not work here!'], ['Truck Driver'], ['Admin'], ['Does not work here!'], ['Does not work here!'], ['Receptionist'], ['Does not work here!']]\nimport math\ndef _deep_eq...
524
225
coding
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 grid of size m x n which represents a field. Each cell has one of three values: 0 represents grass, 1 represents fire, 2 represents a wall that you and fire cannot pass thro...
{"functional": "def check(candidate):\n assert candidate(grid = [[0,2,0,0,0,0,0],[0,0,0,2,2,1,0],[0,2,0,0,1,2,0],[0,0,2,2,2,0,2],[0,0,0,0,0,0,0]]) == 3\n assert candidate(grid = [[0,0,0,0],[0,1,2,0],[0,2,0,0]]) == -1\n assert candidate(grid = [[0,0,0],[2,2,0],[1,2,0]]) == 1000000000\n\n\ncheck(Solution().maxim...
286
170
coding
Solve the programming task below in a Python markdown code block. Chef has a calculator which has two screens and two buttons. Initially, each screen shows the number zero. Pressing the first button increments the number on the first screen by 1, and each click of the first button consumes 1 unit of energy. Pressing th...
{"inputs": ["3\n10 2\n8 5\n6 1"], "outputs": ["12\n3\n9"]}
489
30
coding
Solve the programming task below in a Python markdown code block. Ayrat has number n, represented as it's prime factorization p_{i} of size m, i.e. n = p_1·p_2·...·p_{m}. Ayrat got secret information that that the product of all divisors of n taken modulo 10^9 + 7 is the password to the secret data base. Now he wants t...
{"inputs": ["2\n2 3\n", "2\n2 5\n", "2\n2 2\n", "2\n3 2\n", "2\n3 3\n", "2\n3 5\n", "2\n5 5\n", "2\n5 3\n"], "outputs": ["36\n", "100\n", "8\n", "36\n", "27\n", "225\n", "125\n", "225\n"]}
341
113
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. A decimal number can be converted to its Hexspeak representation by first converting it to an uppercase hexadecimal string, then replacing all occurrences of the digit '0' with the letter 'O', and the digit '1' with t...
{"functional": "def check(candidate):\n assert candidate(num = \"257\") == \"IOI\"\n assert candidate(num = \"3\") == \"ERROR\"\n\n\ncheck(Solution().toHexspeak)"}
170
50
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an array of integers arr, a lucky integer is an integer that has a frequency in the array equal to its value. Return the largest lucky integer in the array. If there is no lucky integer return -1.   Please compl...
{"functional": "def check(candidate):\n assert candidate(arr = [2,2,3,4]) == 2\n assert candidate(arr = [1,2,2,3,3,3]) == 3\n assert candidate(arr = [2,2,2,3,3]) == -1\n assert candidate(arr = [5]) == -1\n assert candidate(arr = [7,7,7,7,7,7,7]) == 7\n\n\ncheck(Solution().findLucky)"}
93
116
coding
Solve the programming task below in a Python markdown code block. There is an event in DUCS where boys get a chance to show off their skills to impress girls. The boy who impresses the maximum number of girls will be honoured with the title “Charming Boy of the year”. There are $N$ girls in the department. Each girl gi...
{"inputs": ["2\n10\njohn berry berry thomas thomas john john berry thomas john\n4\nramesh suresh suresh ramesh"], "outputs": ["john\nramesh"]}
468
44
coding
Solve the programming task below in a Python markdown code block. Given two arrays A and B each of length N. Find the value \sum_{i=1}^N\sum_{j=1}^N \max(A_{i}\oplus B_{j},A_{i}\& B_{j}). Here \oplus and \& denote the [bitwise XOR operation] and [bitwise AND operation] respectively. ------ Input Format ------ ...
{"inputs": ["3\n2\n3 4\n1 2\n1\n0\n0\n3\n2 4 3\n1 2 1"], "outputs": ["15\n0\n30"]}
729
48
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an array of integers, write a method to find indices m and n such that if you sorted elements m through n, the entire array would be sorted. Minimize n - m (that is, find the smallest such sequence). Return [m,n...
{"functional": "def check(candidate):\n assert candidate([1,2,4,7,10,11,7,12,6,7,16,18,19]) == [3,9]\n\n\ncheck(Solution().subSort)"}
126
62
coding
Solve the programming task below in a Python markdown code block. Sophia has discovered several alien languages. Suprisingly, all of these languages have an alphabet, and each of them may contain thousands of characters! Also, all the words in a language have the same number of characters in it. However, the aliens li...
{"inputs": ["3\n1 3\n2 3\n3 2\n"], "outputs": ["1\n3\n6\n"]}
675
30
coding
Solve the programming task below in a Python markdown code block. ```if-not:swift Create a method that takes an array/list as an input, and outputs the index at which the sole odd number is located. This method should work with arrays with negative numbers. If there are no odd numbers in the array, then the method sho...
{"functional": "_inputs = [[[2, 4, 6, 7, 10]], [[2, 16, 98, 10, 13, 78]], [[4, -8, 98, -12, -7, 90, 100]], [[2, 4, 6, 8]]]\n_outputs = [[3], [4], [4], [-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 ...
253
238
coding
Solve the programming task below in a Python markdown code block. Watto, the owner of a spare parts store, has recently got an order for the mechanism that can process strings in a certain way. Initially the memory of the mechanism is filled with n strings. Then the mechanism should be able to process queries of the fo...
{"inputs": ["0 0\n", "0 0\n", "2 3\naaaaa\nacacaca\naabaa\nccacacc\ncaaac\n", "2 3\naaaaa\nacacaca\naabaa\nccbcacc\ncaaac\n", "1 3\naaaaa\nacacaca\naabaa\nccbcacc\ncaaac\n", "1 3\nabaaa\nacacaca\naabaa\nccbcacc\ncaaac\n", "2 3\naaaaa\nacacaca\naabaa\ndcacacc\ncaaac\n", "2 3\naaaaa\nacacaca\naabaa\nccacacc\ncaaac\n"], "...
338
209
coding
Solve the programming task below in a Python markdown code block. Holidays are coming up really soon. Rick realized that it's time to think about buying a traditional spruce tree. But Rick doesn't want real trees to get hurt so he decided to find some in an $n \times m$ matrix consisting of "*" and ".". To find every ...
{"inputs": ["4\n2 3\n.*.\n***\n2 3\n.*.\n**.\n4 5\n.***.\n*****\n*****\n*.*.*\n5 7\n..*.*..\n.*****.\n*******\n.*****.\n..*.*..\n", "4\n2 3\n..*\n***\n2 3\n.*.\n**.\n4 5\n.***.\n*****\n*****\n*.*.*\n5 7\n..*.*..\n.*****.\n*******\n.*****.\n..*.*..\n", "4\n2 3\n..*\n***\n2 3\n.*.\n**.\n4 5\n.***.\n*****\n*****\n*.*.*\n1...
643
643
coding
Solve the programming task below in a Python markdown code block. Mike has n strings s1, s2, ..., sn each consisting of lowercase English letters. In one move he can choose a string si, erase the first character and append it to the end of the string. For example, if he has the string "coolmike", in one move he can tra...
{"inputs": ["1\na\n", "1\nb\n", "1\n`\n", "2\na\nb\n", "2\nb\nb\n", "2\nb\na\n", "2\nc\na\n", "2\naa\naa\n"], "outputs": ["0\n", "0\n", "0\n", "-1\n", "0\n", "-1\n", "-1\n", "0\n"]}
306
96
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given n points on a 2D plane, find if there is such a line parallel to the y-axis that reflects the given points symmetrically. In other words, answer whether or not if there exists a line that after reflecting all po...
{"functional": "def check(candidate):\n assert candidate(points = [[1,1],[-1,1]]) == True\n assert candidate(points = [[1,1],[-1,-1]]) == False\n\n\ncheck(Solution().isReflected)"}
124
54
coding
Solve the programming task below in a Python markdown code block. A new innovative ticketing systems for public transport is introduced in Bytesburg. Now there is a single travel card for all transport. To make a trip a passenger scan his card and then he is charged according to the fare. The fare is constructed in th...
{"inputs": ["1\n0\n", "1\n1\n", "1\n2\n", "1\n3\n", "1\n4\n", "1\n7\n", "1\n9\n", "1\n5\n"], "outputs": ["20\n", "20\n", "20\n", "20\n", "20\n", "20\n", "20\n", "20\n"]}
608
94
coding
Solve the programming task below in a Python markdown code block. Since most contestants do not read this part, I have to repeat that Bitlandians are quite weird. They have their own jobs, their own working method, their own lives, their own sausages and their own games! Since you are so curious about Bitland, I'll gi...
{"inputs": ["1\n6\n", "1\n0\n", "1\n2\n", "1\n1\n", "1\n1\n", "1\n6\n", "1\n2\n", "1\n0\n"], "outputs": ["BitLGM\n", "BitAryo\n", "BitLGM\n", "BitLGM\n", "BitLGM\n", "BitLGM\n", "BitLGM\n", "BitAryo\n"]}
465
102
coding
Solve the programming task below in a Python markdown code block. Let's call the set of positive integers $S$ correct if the following two conditions are met: $S \subseteq \{1, 2, \dots, n\}$; if $a \in S$ and $b \in S$, then $|a-b| \neq x$ and $|a-b| \neq y$. For the given values $n$, $x$, and $y$, you have to find...
{"inputs": ["3 6 8\n", "3 8 5\n", "9 8 3\n", "10 2 5\n", "21 4 6\n", "21 7 9\n", "3 4 14\n", "5 20 3\n"], "outputs": ["3\n", "3\n", "5\n", "5\n", "9\n", "12\n", "3\n", "3\n"]}
256
108
coding
Solve the programming task below in a Python markdown code block. You are given two integers $l$ and $r$, $l\le r$. Find the largest possible value of $a mod b$ over all pairs $(a, b)$ of integers for which $r\ge a \ge b \ge l$. As a reminder, $a mod b$ is a remainder we get when dividing $a$ by $b$. For example, $26 ...
{"inputs": ["4\n1 1\n9312924 1000001000\n6 51\n1 481905067\n", "4\n1 1\n7655209 1000001000\n6 85\n1 481905067\n", "4\n1 1\n9312924 1000001000\n6 70\n1 481905067\n", "4\n1 1\n7655209 1000001000\n6 56\n1 481905067\n", "4\n1 1\n2508889 1010100000\n9 26\n1 999999999\n", "4\n1 1\n2508889 1010100000\n9 42\n1 999999999\n", "4...
393
574
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a 0-indexed, strictly increasing integer array nums and a positive integer diff. A triplet (i, j, k) is an arithmetic triplet if the following conditions are met: i < j < k, nums[j] - nums[i] == diff, a...
{"functional": "def check(candidate):\n assert candidate(nums = [0,1,4,6,7,10], diff = 3) == 2\n assert candidate(nums = [4,5,6,7,8,9], diff = 2) == 2\n\n\ncheck(Solution().arithmeticTriplets)"}
130
76
coding
Solve the programming task below in a Python markdown code block. You are given two positive integers $A$ and $B$. Find the number of pairs of positive integers $(X, Y)$ such that $1 \le X \le A$, $1 \le Y \le B$ and $X + Y$ is even. -----Input----- - The first line of the input contains a single integer $T$ denoting ...
{"inputs": ["4\n1 1\n2 3\n4 6\n8 9"], "outputs": ["1\n3\n12\n36"]}
274
36
coding
Solve the programming task below in a Python markdown code block. In Republic of Atcoder, there are N prefectures, and a total of M cities that belong to those prefectures. City i is established in year Y_i and belongs to Prefecture P_i. You can assume that there are no multiple cities that are established in the same ...
{"inputs": ["1 1\n1 852958660\n", "2 3\n1 32\n2 63\n1 6", "4 3\n2 5\n2 49\n2 12", "4 3\n2 5\n4 49\n1 12", "2 3\n2 4\n1 7\n2 528", "5 2\n1 63\n4 63\n0 9", "2 3\n1 32\n2 63\n1 4", "2 3\n2 39\n2 0\n1 12"], "outputs": ["000001000001\n", "000001000002\n000002000001\n000001000001\n", "000002000001\n000002000003\n000002000002...
504
446
coding
Solve the programming task below in a Python markdown code block. Two friends Chef and Chefina are currently on floors A and B respectively. They hear an announcement that prizes are being distributed on the ground floor and so decide to reach the ground floor as soon as possible. Chef can climb down X floors per min...
{"inputs": ["4\n2 2 2 2\n4 2 1 5\n3 2 4 1\n3 2 2 1\n"], "outputs": ["Both\nChefina\nChef\nChef"]}
694
52
coding
Solve the programming task below in a Python markdown code block. Consider an array A of length N. You know that for all 1 ≤ i ≤ N, 0 ≤ A_{i} ≤ 10^{5}. We construct an array B of length N-1 such that, for all 1 ≤ i ≤ N - 1, B_{i} = min(A_{i}, A_{i + 1}). You are given the array B, you need to find out the total number...
{"inputs": ["3\n2\n100\n5\n3 9 8 4\n3\n10 12"], "outputs": ["199801\n199983\n199977"]}
532
55
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given two integer arrays nums and divisors. The divisibility score of divisors[i] is the number of indices j such that nums[j] is divisible by divisors[i]. Return the integer divisors[i] with the maximum divis...
{"functional": "def check(candidate):\n assert candidate(nums = [4,7,9,3,9], divisors = [5,2,3]) == 3\n assert candidate(nums = [20,14,21,10], divisors = [5,7,5]) == 5\n assert candidate(nums = [12], divisors = [10,16]) == 10\n\n\ncheck(Solution().maxDivScore)"}
120
106
coding
Solve the programming task below in a Python markdown code block. Toad Ivan has $m$ pairs of integers, each integer is between $1$ and $n$, inclusive. The pairs are $(a_1, b_1), (a_2, b_2), \ldots, (a_m, b_m)$. He asks you to check if there exist two integers $x$ and $y$ ($1 \leq x < y \leq n$) such that in each give...
{"inputs": ["2 1\n1 2\n", "4 1\n1 2\n", "4 1\n1 2\n", "2 1\n1 2\n", "8 1\n1 2\n", "4 2\n1 2\n3 4\n", "4 2\n1 2\n2 3\n", "4 2\n1 2\n2 3\n"], "outputs": ["YES\n", "YES\n", "YES", "YES", "YES\n", "YES\n", "YES\n", "YES"]}
519
127
coding
Solve the programming task below in a Python markdown code block. Jack loved his house very much, because his lovely cats take a nap on the wall of his house almost every day. Jack loved cats very much. Jack decided to keep an observation diary of the cats as a free study during the summer vacation. After observing fo...
{"inputs": ["4 6\ns 0 2\ns 1 2\ns 2 1\nw 0\ns 3 3\ns 4 2\n3 3\ns 0 1\ns 1 1\ns 2 1\n0 0", "4 6\ns 0 2\ns 1 3\ns 2 1\nw 0\ns 3 3\ns 4 2\n3 3\ns 0 1\ns 0 1\ns 2 1\n0 0", "4 6\ns 0 2\ns 1 2\ns 2 1\nw 0\ns 3 3\ns 4 2\n4 3\ns 0 1\ns 1 2\ns 2 1\n0 0", "4 6\ns 0 3\ns 1 3\ns 2 1\nw 0\ns 3 3\ns 4 2\n3 3\ns 0 1\ns 1 1\ns 2 1\n0 ...
653
722
coding
Solve the programming task below in a Python markdown code block. You are given a string S of length 3 consisting of a, b and c. Determine if S can be obtained by permuting abc. -----Constraints----- - |S|=3 - S consists of a, b and c. -----Input----- Input is given from Standard Input in the following format: S -...
{"inputs": ["bba", "cab", "abb", "aab", "aac", "bbb", "baa", "caa"], "outputs": ["No\n", "Yes\n", "No\n", "No\n", "No\n", "No\n", "No\n", "No\n"]}
125
64
coding
Solve the programming task below in a Python markdown code block. There are N stones arranged in a row. The i-th stone from the left is painted in the color C_i. Snuke will perform the following operation zero or more times: * Choose two stones painted in the same color. Repaint all the stones between them, with the ...
{"inputs": ["5\n1\n4\n1\n2\n2", "5\n1\n2\n1\n2\n3", "5\n1\n2\n1\n2\n1", "5\n1\n2\n1\n3\n2", "5\n1\n2\n1\n5\n2", "5\n1\n2\n1\n1\n2", "5\n1\n3\n1\n1\n2", "5\n2\n3\n1\n1\n2"], "outputs": ["2\n", "3\n", "5\n", "3\n", "3\n", "3\n", "2\n", "2\n"]}
267
142
coding
Solve the programming task below in a Python markdown code block. Unlucky year in Berland is such a year that its number n can be represented as n = x^{a} + y^{b}, where a and b are non-negative integer numbers. For example, if x = 2 and y = 3 then the years 4 and 17 are unlucky (4 = 2^0 + 3^1, 17 = 2^3 + 3^2 = 2^4 +...
{"inputs": ["2 3 3 5\n", "3 2 6 7\n", "3 3 1 1\n", "4 4 1 1\n", "2 2 1 1\n", "2 3 1 1\n", "3 2 6 7\n", "4 4 1 1\n"], "outputs": ["0\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1", "1"]}
415
116
coding
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin Chinese and Russian as well. Euler's phi function for a positive integer N is usually denoted as φ(N) and defined as the number of positive integers less than or equal to N that are coprime with N. Let's call a po...
{"inputs": ["3\n4 3\n1 57\n8 23", "3\n4 3\n90 95\n1 21", "3\n4 3\n90 95\n4 21", "3\n4 5\n90 89\n8 21", "3\n1 3\n86 95\n12 8", "3\n4 5\n90 89\n8 11", "3\n2 3\n90 95\n6 21", "3\n4 5\n90 95\n1 21"], "outputs": ["0\n13\n4\n", "0\n0\n8\n", "0\n0\n6\n", "1\n0\n4\n", "2\n0\n0\n", "1\n0\n1\n", "1\n0\n5\n", "1\n0\n8\n"]}
351
214
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a positive integer 0-indexed array nums. A subset of the array nums is square-free if the product of its elements is a square-free integer. A square-free integer is an integer that is divisible by no squ...
{"functional": "def check(candidate):\n assert candidate(nums = [3,4,4,5]) == 3\n assert candidate(nums = [1]) == 1\n\n\ncheck(Solution().squareFreeSubsets)"}
181
51
coding
Solve the programming task below in a Python markdown code block. Koa the Koala and her best friend want to play a game. The game starts with an array a of length n consisting of non-negative integers. Koa and her best friend move in turns and each have initially a score equal to 0. Koa starts. Let's describe a move ...
{"inputs": ["3\n3\n2 2 2\n3\n2 2 3\n5\n0 0 0 2 2\n", "3\n3\n2 2 0\n3\n2 2 3\n5\n0 0 0 2 2\n", "3\n3\n4 2 0\n3\n2 2 3\n5\n0 0 0 2 2\n", "3\n3\n4 2 0\n3\n2 2 4\n5\n0 0 0 2 2\n", "3\n3\n1 2 2\n3\n2 2 3\n5\n0 1 0 2 2\n", "3\n3\n2 2 2\n3\n2 2 1\n5\n0 0 0 2 2\n", "3\n3\n4 4 0\n3\n2 2 4\n5\n0 0 0 2 2\n", "3\n3\n4 2 0\n3\n0 2 ...
568
326
coding
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)"}
244
58
coding
Solve the programming task below in a Python markdown code block. You are given two positive integers $a$ and $b$. In one move you can increase $a$ by $1$ (replace $a$ with $a+1$). Your task is to find the minimum number of moves you need to do in order to make $a$ divisible by $b$. It is possible, that you have to mak...
{"inputs": ["1\n9 3\n", "1\n8 4\n", "1\n3 4\n", "1\n3 6\n", "1\n3 3\n", "1\n29 4\n", "1\n9 75\n", "1\n9 95\n"], "outputs": ["0\n", "0\n", "1\n", "3\n", "0\n", "3\n", "66\n", "86\n"]}
274
107
coding
Solve the programming task below in a Python markdown code block. Description In English we often use "neutral vowel sounds" such as "umm", "err", "ahh" as fillers in conversations to help them run smoothly. Bob always finds himself saying "err". Infact he adds an "err" to every single word he says that ends in a con...
{"functional": "_inputs = [['r r r r r r r r'], ['THIS, is crazy!'], ['hI, hi. hI hi skY! sky? skY sky'], ['Hello, I am Mr Bob.'], ['This, is. another! test? case to check your beautiful code.'], ['Hello from the other siiiiideeee'], ['Punctuation? is, important! double space also']]\n_outputs = [['rerr rerr rerr rerr...
255
350
coding
Solve the programming task below in a Python markdown code block. The time has finally come, MKnez and Baltic are to host The Game of the Century. For that purpose, they built a village to lodge its participants. The village has the shape of an equilateral triangle delimited by three roads of length $n$. It is cut int...
{"inputs": ["3\n3\n001\n001\n010\n1\n0\n0\n0\n3\n111\n011\n100\n"], "outputs": ["2\n0\n3\n"]}
723
54
coding
Solve the programming task below in a Python markdown code block. Like any good boss, the Chef has delegated all cooking jobs to his employees so he can take care of other tasks. Occasionally, one of the cooks needs a tool that is out of reach. In some of these cases, the cook cannot leave their workstation to get the ...
{"inputs": ["3\n2\n1 0 0 1\n0 0 1 1\n3\n0 3 0 1\n0 4 0 2\n0 5 0 3\n3\n0 1 0 2\n0 1 0 2\n0 1 0 2"], "outputs": ["4\n10\n6"]}
683
87
coding
Solve the programming task below in a Python markdown code block. Chef has just finished the construction of his new garden. He has sown the garden with patches of the most beautiful carpet grass he could find. He has filled it with patches of different color and now he wants to evaluate how elegant his garden is. Chef...
{"inputs": ["3\n2 2\naa\naA\n3 0\naba\nbab\naba\n4 4\naabb\naabb\nbbaa\nbbaa", "3\n2 2\naa\naA\n3 3\naba\nbab\naba\n4 4\naabb\naabb\nbbaa\nbaaa", "3\n2 2\naa\naA\n3 3\naba\nb`b\naba\n4 4\naabb\naabb\nbba`\nbaaa", "3\n2 2\nab\naA\n3 3\naba\nbab\naba\n4 4\naabb\naabb\nbbaa\nbbaa", "3\n2 2\nab\naA\n3 3\naba\nc`b\naba\n4 0...
445
395
coding
Solve the programming task below in a Python markdown code block. Sam has been teaching Jon the Game of Stones to sharpen his mind and help him devise a strategy to fight the white walkers. The rules of this game are quite simple: The game starts with n piles of stones indexed from 1 to n. The i-th pile contains s_{i}...
{"inputs": ["1\n5\n", "1\n9\n", "1\n5\n", "1\n16\n", "1\n24\n", "1\n27\n", "1\n25\n", "1\n37\n"], "outputs": ["NO", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n"]}
495
90
coding
Solve the programming task below in a Python markdown code block. Let's call an array consisting of n integer numbers a_1, a_2, ..., a_{n}, beautiful if it has the following property: consider all pairs of numbers x, y (x ≠ y), such that number x occurs in the array a and number y occurs in the array a; for each pa...
{"inputs": ["1 1\n1 1\n", "1 1\n1 1\n", "5 2\n1 2\n2 3\n", "2 2\n1 1\n2 1\n", "2 2\n1 1\n2 1\n", "5 2\n1 2\n2 1\n", "5 2\n1 2\n2 3\n", "1 2\n1 1\n2 100\n"], "outputs": ["1\n", "1\n", "5\n", "2\n", "2\n", "3\n", "5\n", "100\n"]}
628
146
coding
Solve the programming task below in a Python markdown code block. There is a vampire family of N members. Vampires are also known as extreme gourmets. Of course vampires' foods are human blood. However, not all kinds of blood is acceptable for them. Vampires drink blood that K blood types of ones are mixed, and each va...
{"inputs": ["2 3\n9 3 6\n1 1 3\n3 2 0\n3 5\n0 2 2 6 5\n0 1 0 1 2\n1 0 1 2 4\n1 0 3 0 1\n0 0", "2 3\n9 2 6\n1 1 3\n3 2 0\n3 5\n0 2 2 6 5\n0 1 0 1 2\n1 0 1 2 4\n1 0 3 0 1\n0 0", "2 3\n9 2 6\n0 1 3\n3 2 0\n3 5\n0 2 2 6 5\n0 1 0 1 2\n1 0 1 2 4\n1 0 3 0 1\n0 0", "2 3\n9 2 6\n0 1 3\n3 2 0\n3 5\n0 2 2 6 5\n0 1 0 1 2\n1 0 2 2 ...
448
622
coding
Solve the programming task below in a Python markdown code block. It's now the season of TAKOYAKI FESTIVAL! This year, N takoyaki (a ball-shaped food with a piece of octopus inside) will be served. The deliciousness of the i-th takoyaki is d_i. As is commonly known, when you eat two takoyaki of deliciousness x and y to...
{"inputs": ["3\n3 1 3", "3\n3 1 5", "3\n1 1 5", "3\n1 1 8", "3\n0 1 8", "3\n0 1 2", "3\n0 1 1", "3\n1 1 1"], "outputs": ["15\n", "23\n", "11\n", "17\n", "8\n", "2\n", "1\n", "3\n"]}
360
114
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a 0-indexed integer array nums. The array nums is beautiful if: nums.length is even. nums[i] != nums[i + 1] for all i % 2 == 0. Note that an empty array is considered beautiful. You can delete any numb...
{"functional": "def check(candidate):\n assert candidate(nums = [1,1,2,3,5]) == 1\n assert candidate(nums = [1,1,2,2,3,3]) == 2\n\n\ncheck(Solution().minDeletion)"}
171
62
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a real number between 0 and 1 (e.g., 0.72) that is passed in as a double, print the binary representation. If the number cannot be represented accurately in binary with at most 32 characters, print "ERROR". Plea...
{"functional": "def check(candidate):\n assert candidate(0.625) == \"0.101\"\n assert candidate(0.1) == \"ERROR\"\n\n\ncheck(Solution().printBin)"}
100
51
coding
Solve the programming task below in a Python markdown code block. Failed Sort - Bug Fixing #4 Oh no, Timmy's Sort doesn't seem to be working? Your task is to fix the sortArray function to sort all numbers in ascending order Also feel free to reuse/extend the following starter code: ```python def sort_array(value): ```
{"functional": "_inputs = [['12345'], ['54321'], ['34251'], ['11111'], ['10101']]\n_outputs = [['12345'], ['12345'], ['12345'], ['11111'], ['00111']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isi...
74
218
coding
Solve the programming task below in a Python markdown code block. Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya has two strings a and b of...
{"inputs": ["7\n4\n", "7\n7\n", "4\n7\n", "4\n4\n", "47\n77\n", "47\n47\n", "47\n74\n", "444\n444\n"], "outputs": ["1\n", "0\n", "1\n", "0\n", "1\n", "0\n", "1\n", "0\n"]}
342
96
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given two groups of points where the first group has size1 points, the second group has size2 points, and size1 >= size2. The cost of the connection between any two points are given in an size1 x size2 matrix ...
{"functional": "def check(candidate):\n assert candidate(cost = [[15, 96], [36, 2]]) == 17\n assert candidate(cost = [[1, 3, 5], [4, 1, 1], [1, 5, 3]]) == 4\n assert candidate(cost = [[2, 5, 1], [3, 4, 7], [8, 1, 2], [6, 2, 4], [3, 8, 8]]) == 10\n\n\ncheck(Solution().connectTwoGroups)"}
202
136
coding
Solve the programming task below in a Python markdown code block. You are given an array A of size N. In one operation, you can: Choose an index i (1≤ i ≤ N) and increase A_{i} by 1. Find the minimum number of operations required to convert the array A into a *permutation* of size N. If it is impossible to do so, prin...
{"inputs": ["4\n4\n3 1 1 2\n3\n0 3 3\n3\n3 2 1\n3\n2 0 1\n"], "outputs": ["3\n-1\n0\n3"]}
718
54
coding
Solve the programming task below in a Python markdown code block. There is a horizontal row of $n$ cubes. The length of each cube is given. You need to create a new vertical pile of cubes. The new pile should follow these directions: if $cube[i]$ is on top of $cube[j]$ then $side Length[j]\geq side Length[i]$. When s...
{"inputs": ["2\n6\n4 3 2 1 3 4\n3\n1 3 2\n"], "outputs": ["Yes\nNo\n"]}
562
38
coding
Solve the programming task below in a Python markdown code block. You are a person who is always fond of eating candies. Your friend gave you a candy of length N, to eat during the break period of your school. You start eating this candy from one of the ends. But as it is not your candy, your friend told you to eat ex...
{"inputs": ["3\n3 1\n3 2\n0 3\n"], "outputs": ["3\n-1\n0\n"]}
436
31
coding
Solve the programming task below in a Python markdown code block. There is a popular apps named “Exbook” like “Facebook”. To sign up in this app , You have to make a strong password with more than 3 digits and less than 10 digits . But I am a pro hacker and so I make a Exbook hacking site . You need to login in this si...
{"inputs": ["2\n3527\n47269"], "outputs": ["1305\n25047"]}
280
32
coding
Solve the programming task below in a Python markdown code block. A has a string consisting of some number of lowercase English letters 'a'. He gives it to his friend B who appends some number of letters 'b' to the end of this string. Since both A and B like the characters 'a' and 'b', they have made sure that at this ...
{"inputs": ["c\n", "a\n", "b\n", "c\n", "b\n", "a\n", "cc\n", "bc\n"], "outputs": ["NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n"]}
421
70
coding
Solve the programming task below in a Python markdown code block. n children are standing in a circle and playing a game. Children's numbers in clockwise order form a permutation a_1, a_2, ..., a_{n} of length n. It is an integer sequence such that each integer from 1 to n appears exactly once in it. The game consists...
{"inputs": ["100 1\n6\n", "2 2\n2 2\n", "2 2\n2 2\n", "100 1\n6\n", "3 3\n3 1 2\n", "3 3\n2 2 3\n", "2 3\n1 1 2\n", "3 3\n1 1 3\n"], "outputs": ["1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 ...
506
710
coding
Solve the programming task below in a Python markdown code block. Chef is very fond of horses. He enjoys watching them race. As expected, he has a stable full of horses. He, along with his friends, goes to his stable during the weekends to watch a few of these horses race. Chef wants his friends to enjoy the race and s...
{"inputs": ["1\n5\n4 9 1 32 13"], "outputs": ["3"]}
343
26
coding
Solve the programming task below in a Python markdown code block. Jim is doing his discrete maths homework which requires him to repeatedly calculate ^{n}C_{r}(n choose r) for different values of n. Knowing that this is time consuming, he goes to his sister June for help. June, being a computer science student knows h...
{"inputs": ["3\n2\n4\n5\n"], "outputs": ["1 2 1\n1 4 6 4 1\n1 5 10 10 5 1\n"]}
378
48
coding
Solve the programming task below in a Python markdown code block. It's been a tough week at work and you are stuggling to get out of bed in the morning. While waiting at the bus stop you realise that if you could time your arrival to the nearest minute you could get valuable extra minutes in bed. There is a bus that ...
{"functional": "_inputs = [['10:00'], ['10:45'], ['15:05'], ['06:10'], ['05:10'], ['04:50'], ['05:55'], ['23:57'], ['00:00'], ['23:55']]\n_outputs = [[10], [10], [5], [0], [45], [65], [0], [358], [355], [0]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n retur...
291
256
coding
Solve the programming task below in a Python markdown code block. Snuke stands on a number line. He has L ears, and he will walk along the line continuously under the following conditions: * He never visits a point with coordinate less than 0, or a point with coordinate greater than L. * He starts walking at a point w...
{"inputs": ["4\n1\n0\n4\n3", "4\n0\n0\n4\n3", "4\n0\n1\n4\n3", "4\n0\n0\n8\n3", "4\n0\n0\n8\n1", "4\n1\n0\n8\n1", "4\n1\n0\n0\n1", "4\n1\n0\n3\n3"], "outputs": ["1\n", "0\n", "1\n", "0\n", "0\n", "1\n", "1\n", "1\n"]}
422
126
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a 0-indexed integer array nums and an integer x. Find the minimum absolute difference between two elements in the array that are at least x indices apart. In other words, find two indices i and j such th...
{"functional": "def check(candidate):\n assert candidate(nums = [4,3,2,4], x = 2) == 0\n assert candidate(nums = [5,3,2,10,15], x = 1) == 1\n assert candidate(nums = [1,2,3,4], x = 3) == 3\n\n\ncheck(Solution().minAbsoluteDifference)"}
139
93
coding
Solve the programming task below in a Python markdown code block. Chef recently printed directions from his home to a hot new restaurant across the town, but forgot to print the directions to get back home. Help Chef to transform the directions to get home from the restaurant. A set of directions consists of several in...
{"inputs": ["2\n4\nBegin on Road A\nRight on Road B\nRight on Road C\nLeft on Road D\n6\nBegin on Old Madras Road\nLeft on Domlur Flyover\nLeft on 100 Feet Road\nRight on Sarjapur Road\nRight on Hosur Road\nRight on Ganapathi Temple Road\n"], "outputs": ["Begin on Road D\nRight on Road C\nLeft on Road B\nLeft on Road A...
503
146
coding
Solve the programming task below in a Python markdown code block. The little girl loves the problems on array queries very much. One day she came across a rather well-known problem: you've got an array of n elements (the elements of the array are indexed starting from 1); also, there are q queries, each one is defined...
{"inputs": ["3 2\n1 2 3\n2 3\n1 2\n", "3 2\n1 2 3\n2 3\n1 2\n", "3 2\n1 4 3\n2 3\n1 2\n", "3 2\n1 2 5\n2 3\n1 2\n", "3 2\n1 7 3\n2 3\n1 2\n", "3 3\n5 3 2\n1 2\n2 3\n1 3\n", "3 3\n5 3 3\n1 2\n2 3\n1 3\n", "3 3\n5 3 2\n1 2\n2 3\n1 2\n"], "outputs": ["9\n", "9\n", "12\n", "13\n", "18\n", "25\n", "27\n", "23\n"]}
431
216
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an array of strings words, find the longest string in words such that every prefix of it is also in words. For example, let words = ["a", "app", "ap"]. The string "app" has prefixes "ap" and "a", all of which a...
{"functional": "def check(candidate):\n assert candidate(words = [\"k\",\"ki\",\"kir\",\"kira\", \"kiran\"]) == \"kiran\"\n assert candidate(words = [\"a\", \"banana\", \"app\", \"appl\", \"ap\", \"apply\", \"apple\"]) == \"apple\"\n assert candidate(words = [\"abc\", \"bc\", \"ab\", \"qwe\"]) == \"\"\n\n\nche...
143
104
coding
Solve the programming task below in a Python markdown code block. Gag Segtree has $ N $ of "gags", each with a value of $ V_i $. Segtree decided to publish all the gags in any order. Here, the "joy" you get when you publish the $ i $ th gag to the $ j $ th is expressed as $ V_i --j $. Find the maximum sum of the "j...
{"inputs": ["1\n2", "1\n1", "1\n4", "1\n6", "1\n7", "1\n9", "1\n3", "1\n8"], "outputs": ["1\n", "0\n", "3\n", "5\n", "6\n", "8\n", "2\n", "7\n"]}
282
78
coding
Solve the programming task below in a Python markdown code block. In an attempt to escape the Mischievous Mess Makers' antics, Farmer John has abandoned his farm and is traveling to the other side of Bovinia. During the journey, he and his k cows have decided to stay at the luxurious Grand Moo-dapest Hotel. The hotel c...
{"inputs": ["2 1\n00\n", "2 1\n00\n", "3 2\n000\n", "3 1\n010\n", "3 1\n010\n", "3 1\n000\n", "3 1\n001\n", "2 1\n001\n"], "outputs": ["1\n", "1\n", "1\n", "2\n", "2\n", "1\n", "1\n", "1\n"]}
509
116
coding
Solve the programming task below in a Python markdown code block. We have one slime. You can set the health of this slime to any integer value of your choice. A slime reproduces every second by spawning another slime that has strictly less health. You can freely choose the health of each new slime. The first reproducti...
{"inputs": ["1\n1 1\n", "2\n4 2 3 1\n", "2\n1 2 3 1\n", "5\n4 3 5 3 1 2 7 8 7 4 6 3 7 2 3 6 2 7 3 2 6 7 3 4 6 7 3 4 2 5 2 3\n"], "outputs": ["No\n", "Yes\n", "Yes\n", "No\n"]}
449
122
coding
Solve the programming task below in a Python markdown code block. You've arrived at a carnival and head straight for the duck shooting tent. Why wouldn't you? You will be given a set amount of ammo, and an aim rating of between 1 and 0. No your aim is not always perfect - hey maybe someone fiddled with the sights on t...
{"functional": "_inputs = [[4, 0.64, '|~~2~~~22~2~~22~2~~~~2~~~|'], [9, 0.22, '|~~~~~~~2~2~~~|'], [6, 0.41, '|~~~~~22~2~~~~~|'], [8, 0.05, '|2~~~~|'], [8, 0.92, '|~~~~2~2~~~~~22~~2~~~~2~~~2|']]\n_outputs = [['|~~X~~~X2~2~~22~2~~~~2~~~|'], ['|~~~~~~~X~2~~~|'], ['|~~~~~XX~2~~~~~|'], ['|2~~~~|'], ['|~~~~X~X~~~~~XX~~X~~~~X...
214
328
coding
Solve the programming task below in a Python markdown code block. Prof. Twotwo as the name suggests is very fond powers of 2. Moreover he also has special affinity to number 800. He is known for carrying quirky experiments on powers of 2. One day he played a game in his class. He brought some number plates on each of ...
{"inputs": ["5\n2222222\n24256\n65536\n023223\n33579\n"], "outputs": ["7\n4\n1\n4\n0\n"]}
647
55
coding
Solve the programming task below in a Python markdown code block. Alice and Bob play a game. The game consists of several sets, and each set consists of several rounds. Each round is won either by Alice or by Bob, and the set ends when one of the players has won $x$ rounds in a row. For example, if Bob won five rounds ...
{"inputs": ["1\n0\n", "1\n1\n", "1\n?\n", "1\n0\n", "1\n1\n", "1\n?\n", "5\n01?01\n", "5\n10?10\n"], "outputs": ["1 \n", "1 \n", "1 \n", "1\n", "1\n", "1\n", "5 1 0 0 0 \n", "5 1 0 0 0\n"]}
597
114
coding
Solve the programming task below in a Python markdown code block. We have held a popularity poll for N items on sale. Item i received A_i votes. From these N items, we will select M as popular items. However, we cannot select an item with less than \dfrac{1}{4M} of the total number of votes. If M popular items can be s...
{"inputs": ["3 3\n39 4 1", "4 1\n5 4 0 1", "3 1\n5 4 0 1", "3 2\n39 19 1", "3 2\n39 14 1", "3 2\n39 18 1", "3 1\n39 18 1", "3 1\n39 16 1"], "outputs": ["No\n", "Yes\n", "Yes\n", "Yes\n", "Yes\n", "Yes\n", "Yes\n", "Yes\n"]}
229
141
coding
Solve the programming task below in a Python markdown code block. You are given two arrays $a$ and $b$, both consisting of $n$ integers. In one move, you can choose two indices $i$ and $j$ ($1 \le i, j \le n$; $i \neq j$) and swap $a_i$ with $a_j$ and $b_i$ with $b_j$. You have to perform the swap in both arrays. You...
{"inputs": ["3\n2\n1 2\n1 2\n2\n2 1\n1 2\n4\n2 3 1 2\n2 3 2 3\n"], "outputs": ["0\n-1\n3\n3 1\n3 2\n4 3\n"]}
488
69
coding
Solve the programming task below in a Python markdown code block. Chef's dog *binary* hears frequencies starting from 67 Hertz to 45000 Hertz (both inclusive). If Chef's commands have a frequency of X Hertz, find whether *binary* can hear them or not. ------ Input Format ------ - The first line of input will conta...
{"inputs": ["5\n42\n67\n402\n45000\n45005\n"], "outputs": ["NO\nYES\nYES\nYES\nNO\n"]}
478
44
coding
Solve the programming task below in a Python markdown code block. # Task A newspaper is published in Walrusland. Its heading is `s1` , it consists of lowercase Latin letters. Fangy the little walrus wants to buy several such newspapers, cut out their headings, glue them one to another in order to get one big string. ...
{"functional": "_inputs = [['abc', 'bcac'], ['abc', 'xyz'], ['abc', 'abcabc'], ['abc', 'abccba'], ['abc', 'aaaaaa']]\n_outputs = [[2], [-1], [2], [4], [6]]\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 ...
352
201
coding
Solve the programming task below in a Python markdown code block. These days, many boys use beautiful girls' photos as dps in Social Networking Profiles. So it is pretty hard to guess whether it is a fake profile or not.Last year, Yogesh went to a forum and had a nice chat with a beauty (he thought so). After that they...
{"inputs": ["rahul", "palak", "payal", "anisha"], "outputs": ["IGNORE HIM!", "CHAT WITH HER!", "CHAT WITH HER!", "IGNORE HIM!"]}
281
41
coding
Solve the programming task below in a Python markdown code block. Everyone knows what a square looks like. Mathematically, a square is a regular quadrilateral. This means that it has four equal sides and four equal angles (90 degree angles). One beautiful day, Johnny eagerly examined the interesting properties of squar...
{"inputs": ["1\n7\n0 0\n0 1\n1 0\n1 1\n1 2\n2 1\n2 2"], "outputs": ["3"]}
362
42
coding
Solve the programming task below in a Python markdown code block. Luntik came out for a morning stroll and found an array $a$ of length $n$. He calculated the sum $s$ of the elements of the array ($s= \sum_{i=1}^{n} a_i$). Luntik calls a subsequence of the array $a$ nearly full if the sum of the numbers in that subsequ...
{"inputs": ["5\n5\n1 2 3 4 5\n2\n1000 1000\n2\n1 0\n5\n3 0 2 1 1\n5\n2 1 0 3 0\n", "5\n5\n1 2 3 4 5\n2\n1000 1000\n2\n1 0\n5\n3 0 2 1 0\n5\n2 1 0 3 0\n", "5\n5\n1 4 3 4 5\n2\n1000 1000\n2\n1 0\n5\n3 0 4 1 0\n5\n0 1 0 3 0\n", "5\n5\n1 2 3 4 1\n2\n1000 1000\n2\n1 0\n5\n3 0 2 1 1\n5\n2 1 0 3 0\n", "5\n5\n1 2 3 4 5\n2\n100...
532
566
coding
Solve the programming task below in a Python markdown code block. Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese] and [Bengali] as well. As everybody knows, Reza Shiri is the favourite Iranian artist. Since we love Reza Shiri and his songs, we never download them for free. Reza Shiri’s...
{"inputs": ["5 2 24\n1 7 2\n1 5 2\n1 4 1\n2 9 1\n2 13 2\n10 15"], "outputs": ["7"]}
550
54