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. Berland annual chess tournament is coming! Organizers have gathered 2·n chess players who should be divided into two teams with n people each. The first team is sponsored by BerOil and the second team is sponsored by BerMobile. Obviously, organizers sho...
{"inputs": ["1\n3 3\n", "1\n2 3\n", "1\n2 1\n", "1\n8 6\n", "1\n2 3\n", "1\n2 1\n", "1\n8 6\n", "1\n2 5\n"], "outputs": ["NO\n", "YES\n", "YES\n", "YES\n", "YES\n", "YES\n", "YES\n", "YES\n"]}
coding
378
Solve the programming task below in a Python markdown code block. Using his tip-top physique, Kim has now climbed up the mountain where the base is located. Kim has found the door to the (supposedly) super secret base. Well, it is super secret, but obviously no match for Kim's talents. The door is guarded by a row of ...
{"inputs": ["3\n4\n3 5 3 4\n2\n5 7\n1\n4"], "outputs": ["3\n0\n0"]}
coding
751
Solve the programming task below in a Python markdown code block. Based on the information of the time when study started and the time when study ended, check whether the total time studied in one day is t or more, and if not, create a program to find the shortage time. Time is one unit per hour, and minutes and second...
{"inputs": ["10\n3\n8 11\n12 19\n18 9\n8\n2\n6 6\n5 6\n0", "10\n3\n8 11\n12 19\n18 9\n8\n2\n4 6\n5 6\n0", "10\n3\n6 11\n12 19\n18 9\n8\n2\n4 6\n5 6\n0", "10\n3\n6 11\n12 19\n18 9\n8\n2\n3 6\n5 6\n0", "10\n3\n6 11\n12 19\n18 9\n8\n2\n3 6\n5 9\n0", "10\n3\n8 11\n12 19\n18 38\n8\n2\n6 6\n5 6\n0", "10\n3\n8 8\n12 19\n18 8\...
coding
530
Solve the programming task below in a Python markdown code block. # Task Write a function named `sumEvenNumbers`, taking a sequence of numbers as single parameter. Your function must return the sum of **the even values** of this sequence. Only numbers without decimals like `4` or `4.0` can be even. ## Input * seque...
{"functional": "_inputs = [[[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]], [[]], [[1337, 374, 849, 22.5, 19, 16, 0, 0, 16, 32]], [[-16, -32, 20, 21, 41, 42]], [[15397, 12422, 10495, 22729, 23921, 18326, 27955, 24073, 23690, 15002, 11615, 15682, 24346, 16725, 17252, 20467, 20493, 17807, 13041, 25861, 22471, 22747, 24082, 18979, 2854...
coding
172
Solve the programming task below in a Python markdown code block. If we write out the digits of "60" as English words we get "sixzero"; the number of letters in "sixzero" is seven. The number of letters in "seven" is five. The number of letters in "five" is four. The number of letters in "four" is four: we have reached...
{"functional": "_inputs = [[1], [2], [3], [4], [12], [37], [311], [999]]\n_outputs = [[['one', 'three', 'five', 'four']], [['two', 'three', 'five', 'four']], [['three', 'five', 'four']], [['four']], [['onetwo', 'six', 'three', 'five', 'four']], [['threeseven', 'onezero', 'seven', 'five', 'four']], [['threeoneone', 'one...
coding
203
Please solve the programming task below using a self-contained code snippet in a markdown code block. There exists an undirected and initially unrooted tree with n nodes indexed from 0 to n - 1. You are given the integer n and a 2D integer array edges of length n - 1, where edges[i] = [ai, bi] indicates that there is ...
{"functional": "def check(candidate):\n assert candidate(n = 6, edges = [[0,1],[1,2],[1,3],[3,4],[3,5]], price = [9,8,7,6,10,5]) == 24\n assert candidate(n = 3, edges = [[0,1],[1,2]], price = [1,1,1]) == 2\n\n\ncheck(Solution().maxOutput)"}
coding
223
Solve the programming task below in a Python markdown code block. International Women's Day is coming soon! Polycarp is preparing for the holiday. There are $n$ candy boxes in the shop for sale. The $i$-th box contains $d_i$ candies. Polycarp wants to prepare the maximum number of gifts for $k$ girls. Each gift will ...
{"inputs": ["1 2\n21\n", "1 2\n41\n", "0 2\n41\n", "0 2\n10\n", "1 2\n24\n", "1 2\n60\n", "0 2\n24\n", "0 2\n60\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]}
coding
596
Solve the programming task below in a Python markdown code block. Polycarp plays a well-known computer game (we won't mention its name). In this game, he can craft tools of two types — shovels and swords. To craft a shovel, Polycarp spends two sticks and one diamond; to craft a sword, Polycarp spends two diamonds and o...
{"inputs": ["1\n2 75\n", "1\n543 1\n", "1\n531 2\n", "1\n531 0\n", "1\n6 176\n", "1\n543 0\n", "1\n2 176\n", "1\n723 1\n"], "outputs": ["2\n", "1\n", "2\n", "0\n", "6\n", "0\n", "2\n", "1\n"]}
coding
307
Solve the programming task below in a Python markdown code block. There is a non-negative integer array A of length N. Chef and Cook will play a game on the array with Chef starting first. In one turn the player will perform the following operation: Choose two indices i,j such that 1 ≤ i < j ≤ N and A_{i} > 0. Set A_...
{"inputs": ["3\n4\n1 0 1 0\n4\n1 2 3 4\n1\n420\n"], "outputs": ["Chef\nChef\nCook\n"]}
coding
565
Please solve the programming task below using a self-contained code snippet in a markdown code block. Implement a method to perform basic string compression using the counts of repeated characters. For example, the string aabcccccaaa would become a2blc5a3. If the "compressed" string would not become smaller than the o...
{"functional": "def check(candidate):\n assert candidate(\"aabcccccaaa\") == \"a2b1c5a3\"\n assert candidate(\"abbccd\") == \"abbccd\"\n\n\ncheck(Solution().compressString)"}
coding
120
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an m x n picture consisting of black 'B' and white 'W' pixels, return the number of black lonely pixels. A black lonely pixel is a character 'B' that located at a specific position where the same row and same co...
{"functional": "def check(candidate):\n assert candidate(picture = [[\"W\",\"W\",\"B\"],[\"W\",\"B\",\"W\"],[\"B\",\"W\",\"W\"]]) == 3\n assert candidate(picture = [[\"B\",\"B\",\"B\"],[\"B\",\"B\",\"W\"],[\"B\",\"B\",\"B\"]]) == 0\n\n\ncheck(Solution().findLonelyPixel)"}
coding
109
Solve the programming task below in a Python markdown code block. You are given two binary strings A and B, each of length N. You can perform the following operation on string A any number of times: Select a [prime number] X. Choose any substring of string A having length X and reverse the substring. Determine whether...
{"inputs": ["4\n2\n00\n00\n4\n1001\n0111\n5\n11000\n10010\n5\n11000\n11010\n"], "outputs": ["YES\nNO\nYES\nNO\n"]}
coding
533
Solve the programming task below in a Python markdown code block. To address the situation of Water Scarcity in Chefland, Chef has started an awareness campaign to motivate people to use greywater for toilets, washing cars, gardening, and many other chores which don't require the use of freshwater. These activities pre...
{"inputs": ["3\n3 1 1 3\n1 1 1 2\n2 1 1 1"], "outputs": ["YES\nYES\nNO"]}
coding
586
Solve the programming task below in a Python markdown code block. Kolya is developing an economy simulator game. His most favourite part of the development process is in-game testing. Once he was entertained by the testing so much, that he found out his game-coin score become equal to 0. Kolya remembers that at the be...
{"inputs": ["6\n", "4\n", "2\n", "11\n", "11\n", "58\n", "30\n", "26\n"], "outputs": ["NO\n", "NO\n", "NO\n", "NO", "NO\n", "NO\n", "NO\n", "NO\n"]}
coding
415
Solve the programming task below in a Python markdown code block. You are given a sequence of non-negative integers $A_1, A_2, \ldots, A_N$. At most once, you may choose a non-negative integer $X$ and for each valid $i$, change $A_i$ to $A_i \oplus X$ ($\oplus$ denotes bitwise XOR). Find the minimum possible value of t...
{"inputs": ["3\n5\n2 3 4 5 6\n4\n7 7 7 7\n3\n1 1 3"], "outputs": ["14\n0\n2"]}
coding
473
Solve the programming task below in a Python markdown code block. Alice and Bob are playing a game with a rooted tree. The tree has $N$ vertices and the first node, $1$, is always the root. Here are the basic rules: They move in alternating turns, and both players always move optimally. During each move, a player remo...
{"inputs": ["1\n5\n1 2\n3 1\n3 4\n4 5\n"], "outputs": ["Alice\n"]}
coding
519
Solve the programming task below in a Python markdown code block. Create a function that takes a list of one or more non-negative integers, and arranges them such that they form the largest possible number. Examples: `largestArrangement([4, 50, 8, 145])` returns 8504145 (8-50-4-145) `largestArrangement([4, 40, 7])` ...
{"functional": "_inputs = [[[50, 2, 1, 9]], [[3655, 89]], [[8]], [[12, 13, 89, 155, 8, 26, 0]], [[76, 4, 3, 81, 514, 6, 716]], [[817, 6879, 163, 348, 8, 22, 47]], [[411, 742, 89, 691, 284]], [[587, 625, 638, 898, 122]], [[797, 535, 210, 87]], [[5, 2, 1, 9, 50, 56]], [[197, 853, 819]], [[23044, 2, 7626, 914, 7800]], [[4...
coding
262
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an n x n integer matrix board where the cells are labeled from 1 to n2 in a Boustrophedon style starting from the bottom left of the board (i.e. board[n - 1][0]) and alternating direction each row. You s...
{"functional": "def check(candidate):\n assert candidate(board = [[-1,-1,-1,-1,-1,-1],[-1,-1,-1,-1,-1,-1],[-1,-1,-1,-1,-1,-1],[-1,35,-1,-1,13,-1],[-1,-1,-1,-1,-1,-1],[-1,15,-1,-1,-1,-1]]) == 4\n assert candidate(board = [[-1,-1],[-1,3]]) == 1\n\n\ncheck(Solution().snakesAndLadders)"}
coding
406
Solve the programming task below in a Python markdown code block. So the Chef has become health conscious and is now lifting weights at the gym. But its his first time so the trainer gives him a simple job to do. He has been given a weight lifting rod and N heavy weights, each weighing 20, 21, .... , 2n-1. He has to ...
{"inputs": ["3\n2\n5\n18"], "outputs": ["3\n945\n221643095476699771875"]}
coding
276
Solve the programming task below in a Python markdown code block. Anfisa the monkey learns to type. She is yet unfamiliar with the "space" key and can only type in lower-case Latin letters. Having typed for a fairly long line, Anfisa understood that it would be great to divide what she has written into k lines not shor...
{"inputs": ["3 1 2\nfpos\n", "3 2 2\nfpos\n", "3 4 2\nfpos\n", "3 4 2\nsopf\n", "3 4 2\nfops\n", "3 1 2\nvgnfpo\n", "3 2 2\nvgnfpo\n", "3 2 2\nvgnopf\n"], "outputs": ["fp\no\ns\n", "No solution", "No solution", "No solution", "No solution", "vg\nnf\npo\n", "vg\nnf\npo\n", "vg\nno\npf\n"]}
coding
294
Solve the programming task below in a Python markdown code block. There are $n$ boxes with different quantities of candies in each of them. The $i$-th box has $a_i$ candies inside. You also have $n$ friends that you want to give the candies to, so you decided to give each friend a box of candies. But, you don't want a...
{"inputs": ["1\n1\n114514\n", "1\n1\n999999\n", "1\n3\n1000 1000 4567\n", "5\n5\n1 2 3 4 5\n6\n1000 1000 5 1000 1000 1000\n10\n1 2 3 5 1 2 7 9 13 5\n3\n8 8 8\n1\n10000000\n"], "outputs": ["0\n", "0\n", "3567\n", "10\n4975\n38\n0\n0\n"]}
coding
578
Solve the programming task below in a Python markdown code block. In telecomunications we use information coding to detect and prevent errors while sending data. A parity bit is a bit added to a string of binary code that indicates whether the number of 1-bits in the string is even or odd. Parity bits are used as the...
{"functional": "_inputs = [['01011001'], ['00110001'], ['11111111'], ['00000000'], ['11100111'], ['00111100 00111101'], ['00001111 11100001'], ['01011110 00011000'], ['11111111 11011100 11100011'], ['00111110 00110100 00111011'], ['01101110 01100000 01010110 10001111 01100011'], ['10100011 00111001 11001100 01010100 10...
coding
463
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 grid accounts where accounts[i][j] is the amount of money the i​​​​​​​​​​​th​​​​ customer has in the j​​​​​​​​​​​th​​​​ bank. Return the wealth that the richest customer has. A customer'...
{"functional": "def check(candidate):\n assert candidate(accounts = [[1,2,3],[3,2,1]]) == 6\n assert candidate(accounts = [[1,5],[7,3],[3,5]]) == 10\n assert candidate(accounts = [[2,8,7],[7,1,3],[1,9,5]]) == 17\n\n\ncheck(Solution().maximumWealth)"}
coding
136
Solve the programming task below in a Python markdown code block. Flash has invited his nemesis The Turtle (He actually was a real villain! ) to play his favourite card game, SNAP. In this game a 52 card deck is dealt out so both Flash and the Turtle get 26 random cards. Each players cards will be represented by an a...
{"functional": "_inputs = [[['3', 'K', '5', 'A', '5', '6', '7', 'J', '7', '9', '10', 'Q', 'Q', '6', '8', '7', '4', 'J', '8', '9', 'K', 'J', '10', '4', 'K', '4'], ['2', '8', '9', 'Q', 'A', 'K', '6', '3', 'J', '2', '4', '3', '3', '8', 'A', '2', '6', '7', '9', '10', 'A', '5', 'Q', '10', '2', '5']], [['9', '5', '4', '4', '...
coding
594
Solve the programming task below in a Python markdown code block. Polycarp is a beginner programmer. He is studying how to use a command line. Polycarp faced the following problem. There are n files in a directory and he needs to delete some of them. Polycarp wants to run a single delete command with filename pattern ...
{"inputs": ["2 1\na\nb\n1\n", "2 1\na\nb\n2\n", "2 1\na\nb\n1\n", "2 1\na\nb\n2\n", "2 1\na\nc\n1\n", "2 1\nb\nc\n1\n", "2 1\naa\nb\n1\n", "2 1\naa\nb\n2\n"], "outputs": ["Yes\na\n", "Yes\nb\n", "Yes\na\n", "Yes\nb\n", "Yes\na\n", "Yes\nb\n", "Yes\naa\n", "Yes\nb\n"]}
coding
580
Solve the programming task below in a Python markdown code block. Given an array $a$ of $n$ elements, print any value that appears at least three times or print -1 if there is no such value. -----Input----- The first line contains an integer $t$ ($1 \leq t \leq 10^4$) — the number of test cases. The first line of e...
{"inputs": ["7\n1\n1\n3\n2 2 2\n7\n2 2 3 3 4 2 2\n8\n1 4 3 4 3 2 4 1\n9\n1 1 1 2 2 2 3 3 3\n5\n1 5 2 4 3\n4\n4 4 4 4\n"], "outputs": ["-1\n2\n2\n4\n3\n-1\n4\n"]}
coding
499
Solve the programming task below in a Python markdown code block. Comprised of a team of five incredibly brilliant women, "The ladies of ENIAC" were the first “computors” working at the University of Pennsylvania’s Moore School of Engineering (1945). Through their contributions, we gained the first software application...
{"functional": "_inputs = [['k?%35a&&/y@@@5599 m93753&$$$c$n///79u??@@%l?975$t?%5y%&$3$1!'], ['9?9?9?m335%$@a791%&$r$$$l@53$&y&n%$5@ $5577w&7e931%s$c$o%%%f351f??%!%%'], ['%&$557f953//1/$@%r%935$$a@3111$@???%n???5 $%157b%///$i%55&31@l?%&$$a%@$s5757!$$%%%%53'], ['///$%&$553791r357%??@$%u?$%@7993111@$%t$h3% 3$l$311i3%@?&c...
coding
189
Solve the programming task below in a Python markdown code block. You are given an integer N. Determine if there exists a tree with 2N vertices numbered 1 to 2N satisfying the following condition, and show one such tree if the answer is yes. * Assume that, for each integer i between 1 and N (inclusive), Vertex i and N...
{"inputs": ["4", "8", "2", "2", "4", "8", "1", "3"], "outputs": ["No\n", "No\n", "No\n", "No\n", "No\n", "No\n", "No", "Yes\n1 2\n2 3\n3 4\n4 5\n5 6"]}
coding
311
Solve the programming task below in a Python markdown code block. You are solving the crossword problem K from IPSC 2014. You solved all the clues except for one: who does Eevee evolve into? You are not very into pokemons, but quick googling helped you find out, that Eevee can evolve into eight different pokemons: Vapo...
{"inputs": ["6\n.s..o.\n", "6\n......\n", "6\n..p...\n", "6\n......\n", "6\n.s..o.\n", "6\n..p...\n", "7\nj......\n", "7\n...feon\n"], "outputs": ["espeon\n", "espeon\n", "espeon\n", "espeon\n", "espeon\n", "espeon\n", "jolteon\n", "leafeon\n"]}
coding
423
Solve the programming task below in a Python markdown code block. Given are a sequence of N positive integers A_1, A_2, \ldots, A_N, and a positive integer K. Find the number of non-empty contiguous subsequences in A such that the remainder when dividing the sum of its elements by K is equal to the number of its elemen...
{"inputs": ["5 1\n1 4 2 3 5", "5 8\n1 4 2 3 5", "5 1\n1 4 2 4 5", "0 1\n1 4 2 4 5", "0 1\n1 4 2 6 5", "0 1\n1 0 2 6 5", "0 1\n0 0 2 6 5", "0 1\n0 0 2 6 3"], "outputs": ["0\n", "1\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]}
coding
252
Solve the programming task below in a Python markdown code block. # Task Vanya gets bored one day and decides to enumerate a large pile of rocks. He first counts the rocks and finds out that he has `n` rocks in the pile, then he goes to the store to buy labels for enumeration. Each of the labels is a digit from 0 ...
{"functional": "_inputs = [[1], [10], [13], [100], [36123011]]\n_outputs = [[1], [11], [17], [192], [277872985]]\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 i...
coding
319
Solve the programming task below in a Python markdown code block. You are given an n × m rectangular table consisting of lower case English letters. In one operation you can completely remove one column from the table. The remaining parts are combined forming a new table. For example, after removing the second column f...
{"inputs": ["2 1\nb\na\n", "2 1\nb\n`\n", "2 2\nfb\nye\n", "2 2\nfb\ney\n", "2 2\nfb\nez\n", "2 2\nfb\nze\n", "2 2\nfc\nez\n", "2 3\naxc\nbxa\n"], "outputs": ["1\n", "1\n", "0\n", "1\n", "1\n", "0\n", "1\n", "0\n"]}
coding
379
Solve the programming task below in a Python markdown code block. A game is played on a strip consisting of N cells consecutively numbered from 1 to N. Alice has her token on cell A. Borys has his token on a different cell B. Players take turns, Alice moves first. The moving player must shift his or her token from it...
{"inputs": ["8 2 4", "3 1 2", "3 2 2", "8 2 3", "0 2 2", "7 2 3", "0 2 1", "7 2 5"], "outputs": ["Alice\n", "Borys\n", "Alice\n", "Borys\n", "Alice\n", "Borys\n", "Borys\n", "Borys\n"]}
coding
297
Please solve the programming task below using a self-contained code snippet in a markdown code block. English description is not available for the problem. Please switch to Chinese.   Please complete the following python code precisely: ```python class Solution: def game(self, guess: List[int], answer: List[int]...
{"functional": "def check(candidate):\n assert candidate(guess = [1,2,3], answer = [1,2,3]) == 3\n assert candidate(guess = [2,2,3], answer = [3,2,1]) == 1\n\n\ncheck(Solution().game)"}
coding
67
Please solve the programming task below using a self-contained code snippet in a markdown code block. There exists an infinitely large grid. You are currently at point (1, 1), and you need to reach the point (targetX, targetY) using a finite number of steps. In one step, you can move from point (x, y) to any one of th...
{"functional": "def check(candidate):\n assert candidate(targetX = 6, targetY = 9) == False\n assert candidate(targetX = 4, targetY = 7) == True\n\n\ncheck(Solution().isReachable)"}
coding
186
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an array coordinates, coordinates[i] = [x, y], where [x, y] represents the coordinate of a point. Check if these points make a straight line in the XY plane.     Please complete the following python code...
{"functional": "def check(candidate):\n assert candidate(coordinates = [[1,2],[2,3],[3,4],[4,5],[5,6],[6,7]]) == True\n assert candidate(coordinates = [[1,1],[2,2],[3,4],[4,5],[5,6],[7,7]]) == False\n\n\ncheck(Solution().checkStraightLine)"}
coding
95
Solve the programming task below in a Python markdown code block. Chef has an old machine if the chef enters any natural number, the machine will display 1, 2, …n, n-1, n-2, n-3,…1 series and in next line prints sum of cubes of each number in the series. Chef wants to create a computer program which can replicate the f...
{"inputs": ["2\n1\n3"], "outputs": ["1\n45"]}
coding
246
Solve the programming task below in a Python markdown code block. You have a binary string S. You can perform the following operation on S: Select any substring S_{L \dots R} (1 ≤ L ≤ R ≤ |S|) which is sorted in non-decreasing order and remove it from S. (Both the left and right halves are concatenated after performing...
{"inputs": ["3\n3\n000\n5\n01110\n2\n10\n"], "outputs": ["0\n1\n1\n"]}
coding
499
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a 0-indexed array of strings words. Each string consists of lowercase English letters only. No letter occurs more than once in any string of words. Two strings s1 and s2 are said to be connected if the s...
{"functional": "def check(candidate):\n assert candidate(words = [\"a\",\"b\",\"ab\",\"cde\"]) == [2,3]\n assert candidate(words = [\"a\",\"ab\",\"abc\"]) == [1,3]\n\n\ncheck(Solution().groupStrings)"}
coding
308
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a series of video clips from a sporting event that lasted time seconds. These video clips can be overlapping with each other and have varying lengths. Each video clip is described by an array clips where...
{"functional": "def check(candidate):\n assert candidate(clips = [[0,2],[4,6],[8,10],[1,9],[1,5],[5,9]], time = 10) == 3\n assert candidate(clips = [[0,1],[1,2]], time = 5) == -1\n assert candidate(clips = [[0,1],[6,8],[0,2],[5,6],[0,4],[0,3],[6,7],[1,3],[4,7],[1,4],[2,5],[2,6],[3,4],[4,5],[5,7],[6,9]], time =...
coding
204
Solve the programming task below in a Python markdown code block. Let us define the oddness of a permutation p = {p_1,\ p_2,\ ...,\ p_n} of {1,\ 2,\ ...,\ n} as \sum_{i = 1}^n |i - p_i|. Find the number of permutations of {1,\ 2,\ ...,\ n} of oddness k, modulo 10^9+7. -----Constraints----- - All values in input are i...
{"inputs": ["3 0", "6 2", "5 2", "3 4", "4 4", "9 2", "7 6", "7 2"], "outputs": ["1\n", "5\n", "4\n", "3\n", "7\n", "8\n", "76\n", "6\n"]}
coding
244
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an integer array arr, count how many elements x there are, such that x + 1 is also in arr. If there are duplicates in arr, count them separately.   Please complete the following python code precisely: ```python ...
{"functional": "def check(candidate):\n assert candidate(arr = [1,2,3]) == 2\n assert candidate(arr = [1,1,3,3,5,5,7,7]) == 0\n\n\ncheck(Solution().countElements)"}
coding
84
Solve the programming task below in a Python markdown code block. Timur's grandfather gifted him a chessboard to practice his chess skills. This chessboard is a grid $a$ with $n$ rows and $m$ columns with each cell having a non-negative integer written on it. Timur's challenge is to place a bishop on the board such th...
{"inputs": ["1\n1 1\n114514\n", "4\n4 4\n1 2 2 1\n2 4 2 4\n2 2 3 1\n2 4 2 4\n2 1\n1\n0\n3 3\n1 1 1\n1 1 1\n1 1 1\n3 3\n0 1 1\n1 0 1\n1 1 0\n"], "outputs": ["114514\n", "20\n1\n5\n3\n"]}
coding
474
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a 2D integer array items where items[i] = [pricei, weighti] denotes the price and weight of the ith item, respectively. You are also given a positive integer capacity. Each item can be divided into two i...
{"functional": "def check(candidate):\n assert candidate(items = [[50,1],[10,8]], capacity = 5) == 55.00000\n assert candidate(items = [[100,30]], capacity = 50) == -1.00000\n\n\ncheck(Solution().maxPrice)"}
coding
220
Solve the programming task below in a Python markdown code block. You have an infinitely long digital panel. Using various combinations of 7 segments, we can represent each digit. The picture shows how all 10 decimal digits are displayed. Initially, all segments in the panel are off. You are given seven integers A, B...
{"inputs": ["3\n10 1 31 21 5 3 12 9\n69697 1 2 3 4 5 6 7\n3964083074239146524786 1 41 31 21 11 1 41\n"], "outputs": ["48\n5\n72\n"]}
coding
601
Solve the programming task below in a Python markdown code block. Squirrel Liss lived in a forest peacefully, but unexpected trouble happens. Stones fall from a mountain. Initially Squirrel Liss occupies an interval [0, 1]. Next, n stones will fall and Liss will escape from the stones. The stones are numbered from 1 to...
{"inputs": ["l\n", "r\n", "l\n", "r\n", "llrlr\n", "rrlll\n", "lrlrr\n", "rlrll\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "3\n5\n4\n2\n1\n", "1\n2\n5\n4\n3\n", "2\n4\n5\n3\n1\n", "1\n3\n5\n4\n2\n"]}
coding
440
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given two strings word1 and word2, return the minimum number of operations required to convert word1 to word2. You have the following three operations permitted on a word: Insert a character Delete a character Replac...
{"functional": "def check(candidate):\n assert candidate(word1 = \"horse\", word2 = \"ros\") == 3\n assert candidate(word1 = \"intention\", word2 = \"execution\") == 5\n\n\ncheck(Solution().minDistance)"}
coding
100
Solve the programming task below in a Python markdown code block. ```if:javascript `Array.prototype.length` will give you the number of top-level elements in an array. ``` ```if:ruby `Array#length` will give you the number of top-level elements in an array. ``` ```if:csharp The `Length` property of an array will give y...
{"functional": "_inputs = [[[]], [[1, 2, 3]], [['x', 'y', ['z']]], [[1, 2, [3, 4, [5]]]], [[[[[[[[[[]]]]]]]]]], [['a']], [[['a']]], [[['a'], []]], [['[a]']], [[[[[[[[[['Everybody!']]]]]]]]]], [['cat', [['dog']], ['[bird]']]]]\n_outputs = [[0], [3], [4], [7], [8], [1], [2], [3], [1], [9], [6]]\nimport math\ndef _deep_eq...
coding
654
Solve the programming task below in a Python markdown code block. Given an array of 4 integers ```[a,b,c,d]``` representing two points ```(a, b)``` and ```(c, d)```, return a string representation of the slope of the line joining these two points. For an undefined slope (division by 0), return ```undefined``` . N...
{"functional": "_inputs = [[[12, -18, -15, -18]], [[3, -20, 5, 8]], [[17, -3, 17, 8]], [[1, -19, -2, -7]], [[19, 3, 20, 3]], [[6, -12, 15, -3]], [[15, -3, 15, -3]], [[9, 3, 19, -17]], [[3, 6, 4, 10]], [[2, 7, 4, -7]], [[1, 24, 2, 88]], [[4, 384, 8, 768]], [[4, 16, 4, 18]], [[7, 28, 9, 64]], [[18, -36, 12, 36]], [[36, 5...
coding
163
Solve the programming task below in a Python markdown code block. Petya has got an interesting flower. Petya is a busy person, so he sometimes forgets to water it. You are given $n$ days from Petya's live and you have to determine what happened with his flower in the end. The flower grows as follows: If the flower is...
{"inputs": ["1\n10\n1 1 1 1 1 1 1 1 1 1\n", "4\n3\n1 0 1\n3\n0 1 1\n4\n1 0 0 1\n1\n0\n"], "outputs": ["47\n", "3\n7\n-1\n1\n"]}
coding
441
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are currently designing a dynamic array. You are given a 0-indexed integer array nums, where nums[i] is the number of elements that will be in the array at time i. In addition, you are given an integer k, the maxi...
{"functional": "def check(candidate):\n assert candidate(nums = [10,20], k = 0) == 10\n assert candidate(nums = [10,20,30], k = 1) == 10\n assert candidate(nums = [10,20,15,30,20], k = 2) == 15\n\n\ncheck(Solution().minSpaceWastedKResizing)"}
coding
236
Solve the programming task below in a Python markdown code block. Chef is given two integers N, S. Consider an array A of size N such that A[i]=i for every 1 ≤ i ≤ N. You are required to find any position x(1≤ x ≤ N) such that : (A[1]+A[2]+...A[x-1]) + (A[x+1]+A[x+2]+...A[N]) = S If there are multiple such position...
{"inputs": ["3\n4 8\n5 10\n2 3\n"], "outputs": ["2\n5\n-1\n"]}
coding
313
Solve the programming task below in a Python markdown code block. As the first step in algebra, students learn quadratic formulas and their factorization. Often, the factorization is a severe burden for them. A large number of students cannot master the factorization; such students cannot be aware of the elegance of ad...
{"inputs": ["2 5 2\n1 1 1\n9 -7 0\n1 0 -3\n0 0 0", "2 7 2\n1 1 1\n9 -7 0\n1 0 -3\n0 0 0", "2 5 2\n1 1 1\n7 -7 1\n1 0 -3\n0 0 0", "3 5 3\n1 2 1\n4 -11 0\n1 1 1\n0 0 0", "3 5 3\n1 2 1\n4 -15 0\n2 0 1\n0 0 0", "3 4 6\n2 2 1\n4 -15 0\n2 0 1\n0 0 0", "3 5 3\n1 2 1\n4 -11 0\n1 1 0\n0 0 0", "2 5 3\n1 2 1\n4 -11 0\n2 0 1\n0 0 ...
coding
636
Solve the programming task below in a Python markdown code block. Ivan's classes at the university have just finished, and now he wants to go to the local CFK cafe and eat some fried chicken. CFK sells chicken chunks in small and large portions. A small portion contains 3 chunks; a large one — 7 chunks. Ivan wants to ...
{"inputs": ["2\n6\n5\n", "2\n6\n4\n", "2\n6\n6\n", "2\n2\n5\n", "2\n2\n1\n", "2\n6\n5\n", "2\n11\n6\n", "2\n10\n4\n"], "outputs": ["YES\nNO\n", "YES\nNO\n", "YES\nYES\n", "NO\nNO\n", "NO\nNO\n", "YES\nNO\n", "NO\nYES\n", "YES\nNO\n"]}
coding
294
Solve the programming task below in a Python markdown code block. You are given a digital clock with $n$ digits. Each digit shows an integer from $0$ to $9$, so the whole clock shows an integer from $0$ to $10^n-1$. The clock will show leading zeroes if the number is smaller than $10^{n-1}$. You want the clock to show...
{"inputs": ["7\n3\n007\n4\n1000\n5\n00000\n3\n103\n4\n2020\n9\n123456789\n30\n001678294039710047203946100020\n", "7\n3\n007\n4\n1000\n5\n00000\n3\n103\n4\n1247\n9\n123456789\n30\n001678294039710047203946100020\n", "7\n3\n007\n4\n1000\n5\n00000\n3\n153\n4\n1247\n9\n123456789\n30\n001678294039710047203946100020\n", "7\n3...
coding
516
Solve the programming task below in a Python markdown code block. Imagine two rings with numbers on them. The inner ring spins clockwise (decreasing by 1 each spin) and the outer ring spins counter clockwise (increasing by 1 each spin). We start with both rings aligned on 0 at the top, and on each move we spin each rin...
{"functional": "_inputs = [[2, 3], [3, 2], [1, 1], [2, 2], [3, 3]]\n_outputs = [[5], [2], [1], [3], [2]]\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
404
Solve the programming task below in a Python markdown code block. Nastya received one more array on her birthday, this array can be used to play a traditional Byteland game on it. However, to play the game the players should first select such a subsegment of the array that $\frac{p}{s} = k$, where p is the product of a...
{"inputs": ["1 1\n1\n", "1 1\n2\n", "1 1\n1\n", "4 2\n6 3 8 1\n", "4 2\n6 3 8 1\n", "4 2\n6 3 12 1\n", "5 21\n4 9 5 3 2\n", "5 15\n10 9 5 2 2\n"], "outputs": ["1\n", "1\n", "1\n", "2\n", "2\n", "1\n", "0\n", "0\n"]}
coding
431
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a string s consisting of lowercase English letters, return the first letter to appear twice. Note: A letter a appears twice before another letter b if the second occurrence of a is before the second occurrence ...
{"functional": "def check(candidate):\n assert candidate(s = \"abccbaacz\") == \"c\"\n assert candidate(s = \"abcdd\") == \"d\"\n\n\ncheck(Solution().repeatedCharacter)"}
coding
101
Solve the programming task below in a Python markdown code block. You're given a row with $n$ chairs. We call a seating of people "maximal" if the two following conditions hold: There are no neighbors adjacent to anyone seated. It's impossible to seat one more person without violating the first rule. The seating is...
{"inputs": ["1\n0\n", "1\n1\n", "1\n0\n", "1\n1\n", "2\n00\n", "2\n01\n", "2\n10\n", "2\n11\n"], "outputs": ["No\n", "Yes\n", "No\n", "Yes\n", "No\n", "Yes\n", "Yes\n", "No\n"]}
coding
319
Solve the programming task below in a Python markdown code block. A [Power Law](https://en.wikipedia.org/wiki/Power_law) distribution occurs whenever "a relative change in one quantity results in a proportional relative change in the other quantity." For example, if *y* = 120 when *x* = 1 and *y* = 60 when *x* = 2 (i.e...
{"functional": "_inputs = [[[1, 120], [2, 60], 4], [[1, 120], [2, 60], 8], [[1, 120], [4, 30], 8], [[1, 120], [3, 60], 9], [[1, 120], [3, 60], 27], [[1, 120], [9, 30], 27], [[1, 81], [2, 27], 4], [[1, 81], [2, 27], 8], [[1, 81], [4, 9], 8], [[1, 81], [5, 27], 25], [[1, 81], [5, 27], 125], [[1, 81], [25, 9], 125], [[4, ...
coding
415
Solve the programming task below in a Python markdown code block. We have a matrix of integers with m rows and n columns. We want to calculate the total sum for the matrix: As you can see, the name "alternating sum" of the title is due to the sign of the terms that changes from one term to its contiguous one and ...
{"functional": "_inputs = [[[[1, 2, 3], [-3, -2, 1], [3, -1, 2]]]]\n_outputs = [[8]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) != len(b): return F...
coding
232
Solve the programming task below in a Python markdown code block. Polycarp has an array $a$ consisting of $n$ integers. He wants to play a game with this array. The game consists of several moves. On the first move he chooses any element and deletes it (after the first move the array contains $n-1$ elements). For each...
{"inputs": ["5\n1 5 7 8 2\n", "5\n2 1 1 1 1\n", "5\n1 1 1 1 1\n", "5\n1 1 1 1 1\n", "5\n2 1 1 1 1\n", "5\n2 1 1 1 2\n", "5\n1 5 7 1 2\n", "5\n1 5 7 2 2\n"], "outputs": ["0\n", "2\n", "4\n", "4\n", "2\n", "0\n", "2\n", "0\n"]}
coding
480
Solve the programming task below in a Python markdown code block. Taro had his own personal computer and set a password for login. However, Taro inadvertently forgot the password. Then, remembering that there was a piece of paper with the password written down, Taro found the paper and was surprised to see it. The pape...
{"inputs": ["AI[U\n_A", "U[IA\n_A", "U[IA\n^A", "U[HA\n^A", "U[H@\n^A", "U[H@\n^B", "U[H@\nB^", "@H[U\nB^"], "outputs": ["No\n", "Yes\n", "No\n", "No\n", "No\n", "No\n", "No\n", "No\n"]}
coding
226
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a string s, return the number of palindromic substrings in it. A string is a palindrome when it reads the same backward as forward. A substring is a contiguous sequence of characters within the string.   Please ...
{"functional": "def check(candidate):\n assert candidate(s = \"abc\") == 3\n assert candidate(s = \"aaa\") == 6\n\n\ncheck(Solution().countSubstrings)"}
coding
92
Solve the programming task below in a Python markdown code block. Alice is playing a game with her good friend, Marisa. There are n boxes arranged in a line, numbered with integers from 1 to n from left to right. Marisa will hide a doll in one of the boxes. Then Alice will have m chances to guess where the doll is. If...
{"inputs": ["7 1\n3\n", "8 1\n8\n", "1 1\n1\n", "2 1\n2\n", "4 1\n1\n", "3 1\n2\n", "5 1\n1\n", "6 1\n5\n"], "outputs": ["27\n", "34\n", "0\n", "4\n", "14\n", "7\n", "19\n", "22\n"]}
coding
648
Solve the programming task below in a Python markdown code block. Let s(x) be sum of digits in decimal representation of positive integer x. Given two integers n and m, find some positive integers a and b such that * s(a) ≥ n, * s(b) ≥ n, * s(a + b) ≤ m. Input The only line of input contain two integers n ...
{"inputs": ["4 1\n", "1 1\n", "9 1\n", "4 3\n", "3 1\n", "2 1\n", "7 1\n", "4 2\n"], "outputs": ["1111\n8889", "1\n9", "111111111\n888888889", "1111\n8889", "111\n889", "11\n89", "1111111\n8888889", "1111\n8889"]}
coding
244
Solve the programming task below in a Python markdown code block. Slime and his $n$ friends are at a party. Slime has designed a game for his friends to play. At the beginning of the game, the $i$-th player has $a_i$ biscuits. At each second, Slime will choose a biscuit randomly uniformly among all $a_1 + a_2 + \ldots...
{"inputs": ["2\n1 1\n", "2\n1 2\n", "2\n0 1\n", "2\n0 1\n", "2\n2 1\n", "2\n1 0\n", "2\n2 2\n", "2\n2 3\n"], "outputs": ["1\n", "3\n", "0\n", "0\n", "3\n", "0\n", "8\n", "499122194\n"]}
coding
570
Solve the programming task below in a Python markdown code block. In this kata, you will make a function that converts between `camelCase`, `snake_case`, and `kebab-case`. You must write a function that changes to a given case. It must be able to handle all three case types: ```python py> change_case("snakeCase", "sn...
{"functional": "_inputs = [['snakeCase', 'snake'], ['some-lisp-name', 'camel'], ['map_to_all', 'kebab'], ['doHTMLRequest', 'kebab'], ['invalid-inPut_bad', 'kebab'], ['valid-input', 'huh???'], ['', 'camel'], ['snake-kebab_case', 'kebab'], ['snakeCamel_case', 'snake'], ['kebabCamel-case', 'snake'], ['case-Camel', 'kebab'...
coding
256
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given the root of a Binary Search Tree (BST), return the minimum absolute difference between the values of any two different nodes in the tree.   Please complete the following python code precisely: ```python # Defini...
{"functional": "def check(candidate):\n assert candidate(root = tree_node([4,2,6,1,3])) == 1\n assert candidate(root = tree_node([1,0,48,None,None,12,49])) == 1\n\n\ncheck(Solution().getMinimumDifference)"}
coding
129
Solve the programming task below in a Python markdown code block. Takahashi is now competing in a programming contest, but he received TLE in a problem where the answer is YES or NO. When he checked the detailed status of the submission, there were N test cases in the problem, and the code received TLE in M of those ca...
{"inputs": ["1 0", "0 0", "8 5", "7 5", "7 2", "2 2", "2 4", "2 0"], "outputs": ["100\n", "0\n", "313600\n", "310400\n", "17200\n", "15200\n", "118400\n", "200\n"]}
coding
460
Solve the programming task below in a Python markdown code block. A number is called powerful if it is a power of two or a factorial. In other words, the number $m$ is powerful if there exists a non-negative integer $d$ such that $m=2^d$ or $m=d!$, where $d!=1\cdot 2\cdot \ldots \cdot d$ (in particular, $0! = 1$). For ...
{"inputs": ["1\n488408742907\n", "4\n7\n11\n240\n17179869184\n", "22\n1\n3\n11\n43\n107\n235\n491\n3499\n12203\n28587\n98155\n229227\n1013995\n2062571\n15685995\n32463211\n234643051\n1509641835\n3657125483\n66233778651\n477441124711\n546451189359\n", "100\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n12\n13\n14\n15\n16\n17\n18\n...
coding
604
Solve the programming task below in a Python markdown code block. You are given a matrix consisting of digits zero and one, its size is n × m. You are allowed to rearrange its rows. What is the maximum area of the submatrix that only consists of ones and can be obtained in the given problem by the described operations?...
{"inputs": ["1 1\n0\n", "1 1\n1\n", "2 2\n10\n11\n", "4 3\n101\n011\n000\n101\n", "4 3\n101\n011\n101\n101\n", "4 3\n101\n011\n100\n101\n", "4 3\n100\n111\n000\n101\n", "4 3\n100\n011\n000\n101\n"], "outputs": ["0\n", "1\n", "2\n", "3\n", "4\n", "3\n", "3\n", "2\n"]}
coding
357
Solve the programming task below in a Python markdown code block. You're a buyer/seller and your buisness is at stake... You ___need___ to make profit... Or at least, you need to lose the least amount of money! Knowing a list of prices for buy/sell operations, you need to pick two of them. Buy/sell market is evolving...
{"functional": "_inputs = [[[10, 7, 5, 8, 11, 9]], [[3, 4]], [[9, 9]], [[10, 7, 5, 4, 1]]]\n_outputs = [[6], [1], [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(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple))...
coding
233
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given the root of a binary tree, return the number of nodes where the value of the node is equal to the average of the values in its subtree. Note: The average of n elements is the sum of the n elements divided by n ...
{"functional": "def check(candidate):\n assert candidate(root = tree_node([4,8,5,0,1,None,6])) == 5\n assert candidate(root = tree_node([1])) == 1\n\n\ncheck(Solution().averageOfSubtree)"}
coding
175
Solve the programming task below in a Python markdown code block. We define the sequence ```SF``` in the following way in terms of four previous sequences: ```S1```, ```S2```, ```S3``` and ```ST``` We are interested in collecting the terms of SF that are multiple of ten. The first term multiple of ten of this seque...
{"functional": "_inputs = [[1], [2], [3]]\n_outputs = [[60], [70080], [90700800]]\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 Fals...
coding
297
Solve the programming task below in a Python markdown code block. Read problems statements in [Mandarin Chinese], [Russian], and [Bengali] as well. You are given an array $A$ with $N$ integers. An array's score is defined as the bitwise AND of all its elements. You need to find the bitwise OR of the scores of all poss...
{"inputs": ["2\n3 2\n1 2 3\n1 4\n3 0\n4 1\n1 2 3 4\n4 0"], "outputs": ["3\n7\n6\n7\n3"]}
coding
658
Solve the programming task below in a Python markdown code block. Every college has a stud−max$stud-max$ buoy. JGEC$JGEC$ has its own Atul$Atul$ who loves to impress everyone with his smile. A presentation is going on at the auditorium where there are N$N$ rows of M$M$ chairs with people sitting on it. Everyone votes f...
{"inputs": ["1\n4 4 3\n1 4 5 7\n2 3 8 6\n1 4 8 9\n5 1 5 6"], "outputs": ["22"]}
coding
441
Solve the programming task below in a Python markdown code block. Consider a table of size $n \times m$, initially fully white. Rows are numbered $1$ through $n$ from top to bottom, columns $1$ through $m$ from left to right. Some square inside the table with odd side length was painted black. Find the center of this s...
{"inputs": ["1 1\nB\n", "1 1\nB\n", "1 1\nB\n", "1 4\nWWBW\n", "1 4\nWWBW\n", "1 4\nWWWB\n", "1 4\nBWWW\n", "1 4\nWBWW\n"], "outputs": ["1 1\n", "1 1\n", "1 1\n", "1 3\n", "1 3\n", "1 4\n", "1 1\n", "1 2\n"]}
coding
295
Solve the programming task below in a Python markdown code block. A palindrome is a string $t$ which reads the same backward as forward (formally, $t[i] = t[|t| + 1 - i]$ for all $i \in [1, |t|]$). Here $|t|$ denotes the length of a string $t$. For example, the strings 010, 1001 and 0 are palindromes. You have $n$ bin...
{"inputs": ["1\n4\n0\n1\n1\n0\n", "1\n4\n0\n1\n1\n0\n", "1\n4\n0\n1\n1\n1\n", "1\n1\n0\n1\n1\n1\n", "1\n3\n0\n0110\n1\n", "1\n3\n0\n0110\n1\n", "1\n3\n0\n1110\n1\n", "1\n1\n0\n1110\n1\n"], "outputs": ["4\n", "4\n", "4\n", "1\n", "3\n", "3\n", "3\n", "1\n"]}
coding
750
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. A pair of indices i, j where 0 <= i < j < nums.length is called beautiful if the first digit of nums[i] and the last digit of nums[j] are coprime. Return the total number ...
{"functional": "def check(candidate):\n assert candidate(nums = [2,5,1,4]) == 5\n assert candidate(nums = [11,21,12]) == 2\n\n\ncheck(Solution().countBeautifulPairs)"}
coding
174
Solve the programming task below in a Python markdown code block. In this kata you will create a function to check a non-negative input to see if it is a prime number. The function will take in a number and will return True if it is a prime number and False if it is not. A prime number is a natural number greater tha...
{"functional": "_inputs = [[0], [1], [2], [11], [12], [61], [571], [573], [25]]\n_outputs = [[False], [False], [True], [True], [False], [True], [True], [False], [False]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_...
coding
108
Solve the programming task below in a Python markdown code block. Anya loves to watch horror movies. In the best traditions of horror, she will be visited by m ghosts tonight. Anya has lots of candles prepared for the visits, each candle can produce light for exactly t seconds. It takes the girl one second to light one...
{"inputs": ["1 1 1\n4\n", "1 1 1\n4\n", "1 6 5\n9\n", "1 1 2\n4\n", "1 8 3\n10\n", "1 1 3\n10\n", "1 8 5\n10\n", "1 8 6\n10\n"], "outputs": ["1\n", "1\n", "5\n", "-1\n", "3\n", "-1\n", "5\n", "6\n"]}
coding
648
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a string s, remove duplicate letters so that every letter appears once and only once. You must make sure your result is the smallest in lexicographical order among all possible results.   Please complete the fol...
{"functional": "def check(candidate):\n assert candidate(s = \"bcabc\") == \"abc\"\n assert candidate(s = \"cbacdcbc\") == \"acdb\"\n\n\ncheck(Solution().removeDuplicateLetters)"}
coding
85
Solve the programming task below in a Python markdown code block. Chef and his friend Miron were getting bored and decided to play a game. Miron thinks of a sequence of N integers (A1, A2, …., AN) and gives Chef a matrix B, where Bi,j = |Ai - Aj|. He further tells Chef that A1 = 0. The game is for Chef to guess the ...
{"inputs": ["3 2\n0 1 2\n1 0 1\n2 1 0\n1\n0 4 3\n2\n4 0 7"], "outputs": ["0 -1 -2\n0 -4 -3\n0 -4 3"]}
coding
558
Solve the programming task below in a Python markdown code block. $n$ players are playing a game. There are two different maps in the game. For each player, we know his strength on each map. When two players fight on a specific map, the player with higher strength on that map always wins. No two players have the same ...
{"inputs": ["3\n4\n1 3 5 6\n1 2 3 4\n4\n17 11 20 21\n9 3 11 29\n1\n1000000000\n1000000000\n", "3\n4\n0 3 5 1\n1 2 3 4\n4\n1 12 20 21\n70 0 16 30\n1\n1000000000\n1000000000\n", "3\n4\n1 3 5 6\n1 2 3 4\n4\n1 12 20 21\n70 2 11 30\n1\n1000000000\n1000000000\n", "3\n4\n1 3 5 6\n1 2 3 4\n4\n1 12 20 21\n70 2 16 30\n1\n1000000...
coding
628
Solve the programming task below in a Python markdown code block. Given are a sequence of N integers A_1, A_2, \ldots, A_N and a positive integer S. For a pair of integers (L, R) such that 1\leq L \leq R \leq N, let us define f(L, R) as follows: - f(L, R) is the number of sequences of integers (x_1, x_2, \ldots , x_...
{"inputs": ["3 4\n2 2 6", "3 4\n2 2 2", "3 4\n1 2 1", "3 4\n1 3 1", "3 5\n2 2 3", "3 4\n2 2 4", "3 4\n2 2 4\n", "5 7\n2 6 1 9 5"], "outputs": ["2\n", "5\n", "1\n", "4\n", "3\n", "5", "5\n", "7\n"]}
coding
461
Solve the programming task below in a Python markdown code block. Calculate the trace of a square matrix. A square matrix has `n` rows and `n` columns, where `n` is any integer > 0. The entries of the matrix can contain any number of integers. The function should return the calculated trace of the matrix, or `nil/None`...
{"functional": "_inputs = [[[[1, 2, 3], [4, 5, 6], [7, 8, 9]]], [[[0, 0], [0, 0]]], [[[0, 0, 0], [0, 0, 0], [0, 0, 0]]], [[[1, 0, 0], [0, 1, 0], [0, 0, -2]]], [[[0]]], [[[1]]], [[[-300]]], [[]], [[[]]], [[[1, 2], [1, 2], [1, 2]]], [[[1, 2, 3], [1, 2, 3]]]]\n_outputs = [[15], [0], [0], [0], [0], [1], [-300], [None], [No...
coding
367
Solve the programming task below in a Python markdown code block. A category page displays a set number of products per page, with pagination at the bottom allowing the user to move from page to page. Given that you know the page you are on, how many products are in the category in total, and how many products are on ...
{"functional": "_inputs = [[1, 10, 30], [3, 10, 26], [1, 10, 8], [2, 30, 350], [1, 23, 30], [2, 23, 30], [43, 15, 3456]]\n_outputs = [['Showing 1 to 10 of 30 Products.'], ['Showing 21 to 26 of 26 Products.'], ['Showing 1 to 8 of 8 Products.'], ['Showing 31 to 60 of 350 Products.'], ['Showing 1 to 23 of 30 Products.'], ...
coding
229
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an integer array nums sorted in non-decreasing order, return an array of the squares of each number sorted in non-decreasing order.   Please complete the following python code precisely: ```python class Solution...
{"functional": "def check(candidate):\n assert candidate(nums = [-4,-1,0,3,10]) == [0,1,9,16,100]\n assert candidate(nums = [-7,-3,2,3,11]) == [4,9,9,49,121]\n\n\ncheck(Solution().sortedSquares)"}
coding
78
Solve the programming task below in a Python markdown code block. One day John had to take care of his little nephew Jim. He was very busy, so he gave Jim a big bag full of building bricks. The bricks are of various heights: at most 15 different heights. For each height, the bag contains infinitely many bricks. Now, ...
{"inputs": ["10\n1\n1\n", "5\n2\n2 3\n", "19\n2\n4 5\n"], "outputs": ["2\n", "4\n", "8\n"]}
coding
598
Solve the programming task below in a Python markdown code block. You are given an undirected connected weighted graph with N vertices and M edges that contains neither self-loops nor double edges. The i-th (1≤i≤M) edge connects vertex a_i and vertex b_i with a distance of c_i. Here, a self-loop is an edge where a_i = ...
{"inputs": ["3 2\n1 2 2\n2 3 1", "3 2\n1 3 2\n2 3 1", "3 2\n1 3 2\n2 0 1", "3 2\n1 2 2\n2 0 1", "3 2\n2 2 2\n2 0 1", "3 2\n1 1 1\n2 3 1", "3 2\n1 3 2\n2 1 1", "3 2\n1 3 3\n2 1 1"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]}
coding
366
Solve the programming task below in a Python markdown code block. There is a sequence of length N: A_1, A_2, ..., A_N. Initially, this sequence is a permutation of 1, 2, ..., N. On this sequence, Snuke can perform the following operation: * Choose K consecutive elements in the sequence. Then, replace the value of eac...
{"inputs": ["3 3\n2 2 3", "3 3\n2 2 2", "6 3\n2 2 2", "6 3\n0 2 2", "6 3\n0 3 2", "3 3\n1 2 4", "3 3\n2 2 0", "3 3\n2 2 1"], "outputs": ["1\n", "1\n", "3\n", "3\n", "3\n", "1\n", "1\n", "1\n"]}
coding
287
Solve the programming task below in a Python markdown code block. Reziba has many magic gems. Each magic gem can be split into $M$ normal gems. The amount of space each magic (and normal) gem takes is $1$ unit. A normal gem cannot be split. Reziba wants to choose a set of magic gems and split some of them, so the tota...
{"inputs": ["4 2\n", "3 2\n", "1 2\n", "1 3\n", "1 4\n", "1 5\n", "2 2\n", "2 3\n"], "outputs": ["5\n", "3\n", "1\n", "1\n", "1\n", "1\n", "2\n", "1\n"]}
coding
531
Solve the programming task below in a Python markdown code block. A connected undirected graph is called a vertex cactus, if each vertex of this graph belongs to at most one simple cycle. A simple cycle in a undirected graph is a sequence of distinct vertices v1, v2, ..., vt (t > 2), such that for any i (1 ≤ i < t) ex...
{"inputs": ["2 1\n1 2\n3\n1 2\n1 2\n2 1\n", "5 4\n1 3\n2 3\n4 3\n1 5\n3\n1 3\n2 4\n5 2\n", "6 6\n1 2\n2 3\n3 4\n4 5\n5 6\n6 1\n4\n1 2\n1 6\n6 5\n4 3\n", "5 5\n1 2\n2 3\n3 4\n4 2\n2 5\n5\n1 5\n5 1\n2 5\n4 2\n4 1\n", "5 5\n1 2\n2 3\n3 4\n4 2\n2 5\n5\n1 5\n3 1\n2 5\n4 2\n4 1\n", "5 5\n1 2\n2 3\n3 4\n4 2\n1 5\n5\n1 5\n3 1\...
coding
674
Solve the programming task below in a Python markdown code block. Tomya is a girl. She loves Chef Ciel very much. Tomya like a positive integer p, and now she wants to get a receipt of Ciel's restaurant whose total price is exactly p. The current menus of Ciel's restaurant are shown the following table. Name of Menupr...
{"inputs": ["4\n5\n23\n1\n1090", "4\n7\n23\n1\n1090", "4\n8\n73\n94\n2919", "4\n8\n73\n12\n2919", "4\n6\n73\n12\n2919", "4\n3\n73\n94\n2919", "4\n15\n18\n12\n689", "4\n5\n23\n12\n1090"], "outputs": ["2\n4\n1\n3\n", "3\n4\n1\n3\n", "1\n3\n5\n8\n", "1\n3\n2\n8\n", "2\n3\n2\n8\n", "2\n3\n5\n8\n", "4\n2\n2\n5\n", "2\n4\n2\...
coding
556
Solve the programming task below in a Python markdown code block. Maksim has $n$ objects and $m$ boxes, each box has size exactly $k$. Objects are numbered from $1$ to $n$ in order from left to right, the size of the $i$-th object is $a_i$. Maksim wants to pack his objects into the boxes and he will pack objects by th...
{"inputs": ["1 1 1\n1\n", "1 1 1\n1\n", "1 1 1\n0\n", "1 1 2\n0\n", "1 1 2\n1\n", "1 1 2\n2\n", "1 2 2\n1\n", "1 2 2\n2\n"], "outputs": ["1\n", "1", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n"]}
coding
722
Solve the programming task below in a Python markdown code block. N people are arranged in a row from left to right. You are given a string S of length N consisting of 0 and 1, and a positive integer K. The i-th person from the left is standing on feet if the i-th character of S is 0, and standing on hands if that char...
{"inputs": ["1 1\n0", "1 2\n0", "1 2\n1", "1 3\n1", "1 4\n1", "1 1\n1", "1 1\n1\n", "5 1\n00000"], "outputs": ["1\n", "1\n", "1\n", "1\n", "1\n", "1", "1\n", "5\n"]}
coding
379
Solve the programming task below in a Python markdown code block. As we all know, Dhoni loves drinking milk. Once he and Sir Jadeja were invited in the inauguration of a Dairy company in Ranchi. The company had arranged n jars of milk from various breeds of cows , jar number i containing a[i] litres of milk. Si...
{"inputs": ["1\n3 3 3\n15 8 10"], "outputs": ["9"]}
coding
481
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin chinese, Russian and Vietnamese as well. Chef Tobby is trying to run a code given to him by Bhuvan for an experiment they want to include in the manuscript to be submitted to a conference. The deadline to submit the...
{"inputs": ["1\n2 2\n3 1", "1\n7 3\n3 7 5 4 6 2 1"], "outputs": ["1", "0"]}
coding
628
Solve the programming task below in a Python markdown code block. A `Nice array` is defined to be an array where for every value `n` in the array, there is also an element `n-1` or `n+1` in the array. example: ``` [2,10,9,3] is Nice array because 2=3-1 10=9+1 3=2+1 9=10-1 ``` Write a function named `isNice`/`IsNice`...
{"functional": "_inputs = [[[2, 10, 9, 3]], [[3, 4, 5, 7]], [[0, 2, 19, 4, 4]], [[3, 2, 1, 0]], [[3, 2, 10, 4, 1, 6]], [[1, 1, 8, 3, 1, 1]], [[0, 1, 2, 3]], [[1, 2, 3, 4]], [[0, -1, 1]], [[0, 2, 3]], [[0]], [[]], [[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]], [[0, 1, 3, -2, 5, 4]], [[0, -1, -2, -3, -4]], [[1, -1, 3]], [[1, -1, 2, -...
coding
173