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. Find the second-to-last element of a list. Example: ```python penultimate([1,2,3,4]) # => 3 penultimate(["Python is dynamic"]) # => 'i' (courtesy of [haskell.org](http://www.haskell.org/haskellwiki/99_questions/1_to_10)) ``` Also feel free to...
{"functional": "_inputs = [[[1, 2, 3, 4]], ['hello']]\n_outputs = [[3], ['l']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) != len(b): return False\n...
coding
109
Solve the programming task below in a Python markdown code block. You are given a string S of length N. Among its subsequences, count the ones such that all characters are different, modulo 10^9+7. Two subsequences are considered different if their characters come from different positions in the string, even if they ar...
{"inputs": ["3\naab", "3\nbac", "3\naaa", "3\nabb", "3\nbab", "3\ncac", "3\ndac", "3\naba"], "outputs": ["5\n", "7\n", "3\n", "5\n", "5\n", "5\n", "7\n", "5\n"]}
coding
209
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given the head of a linked list. Remove every node which has a node with a greater value anywhere to the right side of it. Return the head of the modified linked list.   Please complete the following python co...
{"functional": "def check(candidate):\n assert is_same_list(candidate(head = list_node([5,2,13,3,8])), list_node([13,8]))\n assert is_same_list(candidate(head = list_node([1,1,1,1])), list_node([1,1,1,1]))\n\n\ncheck(Solution().removeNodes)"}
coding
129
Solve the programming task below in a Python markdown code block. One day, Vogons wanted to build a new hyperspace highway through a distant system with $n$ planets. The $i$-th planet is on the orbit $a_i$, there could be multiple planets on the same orbit. It's a pity that all the planets are on the way and need to be...
{"inputs": ["1\n1 100\n1\n", "4\n10 1\n2 1 4 5 2 4 5 5 1 2\n5 2\n3 2 1 2 2\n2 2\n1 1\n2 2\n1 2\n", "1\n49 2\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n"], "outputs": ["1\n", "4\n4\n2\n2\n", "2\n"]}
coding
577
Solve the programming task below in a Python markdown code block. Given an array $a$ consisting of $n$ elements, find the maximum possible sum the array can have after performing the following operation any number of times: Choose $2$ adjacent elements and flip both of their signs. In other words choose an index $i$ s...
{"inputs": ["5\n3\n-1 -1 -1\n5\n1 5 -5 0 2\n3\n1 2 3\n6\n-1 10 9 8 7 6\n2\n-1 -1\n"], "outputs": ["1\n13\n6\n39\n2\n"]}
coding
602
Solve the programming task below in a Python markdown code block. Arseniy is already grown-up and independent. His mother decided to leave him alone for m days and left on a vacation. She have prepared a lot of food, left some money and washed all Arseniy's clothes. Ten minutes before her leave she realized that it w...
{"inputs": ["3 2 3\n1 2 3\n1 2\n2 3\n", "3 2 2\n1 1 2\n1 2\n2 1\n", "3 2 3\n1 2 3\n1 2\n2 3\n", "3 2 2\n1 1 2\n1 2\n2 1\n", "4 2 4\n1 2 3 4\n1 2\n3 4\n", "4 2 4\n1 2 3 4\n1 2\n3 4\n", "4 2 4\n1 2 3 4\n1 3\n3 4\n", "4 2 4\n1 2 1 4\n1 3\n3 4\n"], "outputs": ["2\n", "0\n", "2", "0", "2\n", "2", "2\n", "1\n"]}
coding
711
Solve the programming task below in a Python markdown code block. We say that a string contains the word hackerrank if a subsequence of its characters spell the word hackerrank. Remeber that a subsequence maintains the order of characters selected from a sequence. More formally, let $p[0],p[1],\cdots,p[9]$ be the ...
{"inputs": ["2\nhereiamstackerrank\nhackerworld\n", "2\nhhaacckkekraraannk\nrhbaasdndfsdskgbfefdbrsdfhuyatrjtcrtyytktjjt\n"], "outputs": ["YES\nNO\n", "YES\nNO\n"]}
coding
640
Solve the programming task below in a Python markdown code block. You are looking for a place to park your car on a wall street. You can park at any position that meets the following requirements: 1. It is not directly in front of a private driveway. 2. It is not directly in front of a bus stop. 3. It is not 5 meter...
{"inputs": ["46\n---B--S-D--S--\nDDBDDBDDBDD\n--S--S--S--S--\nSSD-B---BD-DDSB-----S-S--------S-B----BSB-S--B-S-D\n-SB---S----DD-D-DS---B--BD-S-SD---D----D-B---B-SDD\n------BB-----D--------S--D-BSSS-----B---S-S-SSS---\n----------S--S----D---------SD---DD--D---DSB-B----\n-S---------DDDB---BB----SSD---D-B---S-B-----DD---S...
coding
485
Solve the programming task below in a Python markdown code block. Vasya learned about integer subtraction in school. He is still not very good at it, so he is only able to subtract any single digit number from any other number (which is not necessarily single digit). For practice, Vasya chose a positive integer n$n$ an...
{"inputs": ["3\n2\n3\n100"], "outputs": ["9\n10\n170"]}
coding
566
Solve the programming task below in a Python markdown code block. Alice and Bob are playing a game using a string S of length N. They both have their individual strings which are initially empty. Both players take alternate turns. Alice starts first. In Alice's turn, she will: Choose a prefix of S; Remove the chosen...
{"inputs": ["3\n4\nabab\n6\nabccda\n4\naaaa\n"], "outputs": ["1\n2\n2\n"]}
coding
712
Solve the programming task below in a Python markdown code block. One day in the IT lesson Anna and Maria learned about the lexicographic order. String x is lexicographically less than string y, if either x is a prefix of y (and x ≠ y), or there exists such i (1 ≤ i ≤ min(|x|, |y|)), that xi < yi, and for any j (1 ≤ j...
{"inputs": ["ba\n2\n", "ab\n2\n", "aa\n2\n", "cba\n6\n", "cca\n6\n", "cca\n1\n", "acb\n5\n", "cba\n1\n"], "outputs": ["b\n", "ab\n", "a\n", "cba\n", "cca\n", "a\n", "c\n", "a\n"]}
coding
413
Solve the programming task below in a Python markdown code block. You were given a string of integer temperature values. Create a function `close_to_zero(t)` and return the closest value to 0 or `0` if the string is empty. If two numbers are equally close to zero, return the positive integer. Also feel free to reuse/ex...
{"functional": "_inputs = [[''], ['-1 50 -4 20 22 -7 0 10 -8'], ['28 35 -21 17 38 -17']]\n_outputs = [[0], [0], [17]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n ...
coding
86
Solve the programming task below in a Python markdown code block. Snuke found N strange creatures. Each creature has a fixed color and size. The color and size of the i-th creature are represented by i and A_i, respectively. Every creature can absorb another creature whose size is at most twice the size of itself. Whe...
{"inputs": ["3\n3 1 3", "3\n1 1 3", "3\n5 1 3", "3\n1 1 2", "3\n5 2 3", "3\n1 1 1", "3\n3 1 4", "5\n1 1 1 1 2"], "outputs": ["2\n", "3\n", "2\n", "3\n", "3\n", "3\n", "2", "5\n"]}
coding
312
Solve the programming task below in a Python markdown code block. The match is set and your team is ready to win! The team has $N$ players, each with the ability $A_{i}$. But you are not happy with the given playing order. You are wondering how to create a new order so that the player with lesser ability go earlier, ...
{"inputs": ["2\n2\n1 2\n3\n2 1 3"], "outputs": ["YES\n0\nNO"]}
coding
557
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 same tree where every subtree (of the given tree) not containing a 1 has been removed. A subtree of a node node is node plus every node that is a descendant of node.   Pleas...
{"functional": "def check(candidate):\n assert is_same_tree(candidate(root = tree_node([1,None,0,0,1])), tree_node([1,None,0,None,1]))\n assert is_same_tree(candidate(root = tree_node([1,0,1,0,0,0,1])), tree_node([1,None,1,None,1]))\n assert is_same_tree(candidate(root = tree_node([1,1,0,1,1,0,1,0])), tree_nod...
coding
150
Solve the programming task below in a Python markdown code block. There is a very secret base in Potatoland where potato mash is made according to a special recipe. The neighbours from Porridgia decided to seize this recipe and to sell it to Pilauland. For this mission they have been preparing special agent Pearlo for ...
{"inputs": ["...\nX.X\n...\n", "X..\nX..\nX..\n", "...\nXXX\nXXX\n", "...\nX.X\nX..\n", "..X\nX..\n..X\n", "...\n...\n..X\n", "X..\n...\n...\n", "...\nX..\n...\n"], "outputs": ["YES\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n"]}
coding
362
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. Nim is a well-known combinatorial game, based on removing stones from piles. In this problem, we'll deal with a similar game, which we'll call Dual Nim. The rules of this game...
{"inputs": ["3\n4\n1 2 4 8\n3\n2 3 3\n5\n3 3 3 3 3", "3\n4\n1 2 4 8\n3\n2 3 3\n5\n1 3 3 3 3", "3\n4\n1 2 4 2\n3\n3 3 3\n5\n1 3 2 3 3", "3\n4\n1 2 8 7\n3\n2 1 3\n5\n1 3 1 3 3", "3\n4\n1 2 4 8\n3\n3 3 3\n5\n1 3 3 3 3", "3\n4\n1 2 4 8\n3\n3 3 3\n5\n1 3 1 3 3", "3\n4\n1 2 4 2\n3\n3 3 3\n5\n1 3 1 3 3", "3\n4\n1 2 4 7\n3\n2 ...
coding
363
Solve the programming task below in a Python markdown code block. Tanish is the president of the chemistry club at his school. He considers everyone who doesn't like chemistry as his enemy. After years of research, he has invented a lethal poison, which he named success. Now Tanish plans to kill all his enemies with hi...
{"inputs": ["2\n2\n9 3\n3\n3 2 9"], "outputs": ["6.00000000\n4.00000000"]}
coding
574
Solve the programming task below in a Python markdown code block. Chef has recently learned about number bases and is becoming fascinated. Chef learned that for bases greater than ten, new digit symbols need to be introduced, and that the convention is to use the first few letters of the English alphabet. For example, ...
{"inputs": ["4\n6\n9\n11\n24"], "outputs": ["4\n7\n8\n14"]}
coding
501
Solve the programming task below in a Python markdown code block. We have an array of length $n$. Initially, each element is equal to $0$ and there is a pointer located on the first element. We can do the following two kinds of operations any number of times (possibly zero) in any order: If the pointer is not on the ...
{"inputs": ["1\n1\n1\n", "1\n2\n2 2\n", "1\n2\n-800372697 800372697\n", "7\n2\n1 0\n4\n2 -1 -1 0\n4\n1 -4 3 0\n4\n1 -1 1 -1\n5\n1 2 3 4 -10\n7\n2 -1 1 -2 0 0 0\n1\n0\n"], "outputs": ["No\n", "No\n", "No\n", "No\nYes\nNo\nNo\nYes\nYes\nYes\n"]}
coding
677
Solve the programming task below in a Python markdown code block. With your birthday coming up soon, your eccentric friend sent you a message to say "happy birthday": hhhappyyyy biirrrrrthddaaaayyyyyyy to youuuu hhapppyyyy biirtttthdaaay too youuu happy birrrthdayy to youuu happpyyyy birrtthdaaay toooo...
{"functional": "_inputs = [['happy birthday', 'appyh appy birth day'], ['happy birthday', 'hhaappyy bbiirrtthhddaayy'], ['happy birthday', 'happy holidays'], ['happy birthday', 'happy birthday'], ['happy', 'hhhappy'], ['happy birthday', 'hhhappyyyy biirrrrrthddaaaayyyyyyy to youuuu']]\n_outputs = [[1], [2048], [0], [1]...
coding
407
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an array of integers arr. We want to select three indices i, j and k where (0 <= i < j <= k < arr.length). Let's define a and b as follows: a = arr[i] ^ arr[i + 1] ^ ... ^ arr[j - 1] b = arr[j] ^ arr[j + 1] ^ ....
{"functional": "def check(candidate):\n assert candidate(arr = [2,3,1,6,7]) == 4\n assert candidate(arr = [1,1,1,1,1]) == 10\n assert candidate(arr = [2,3]) == 0\n assert candidate(arr = [1,3,5,7,9]) == 3\n assert candidate(arr = [7,11,12,9,5,2,7,17,22]) == 8\n\n\ncheck(Solution().countTriplets)"}
coding
156
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!"]}
coding
281
Solve the programming task below in a Python markdown code block. Looking at consecutive powers of `2`, starting with `2^1`: `2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, ...` Note that out of all the digits `0-9`, the last one ever to appear is `7`. It only shows up for the first time in...
{"functional": "_inputs = [[100], [2], [3], [8], [1111], [3000]]\n_outputs = [[None], [7], [0], [7], [9], [5]]\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 ...
coding
351
Solve the programming task below in a Python markdown code block. Each student eagerly awaits the day he would pass the exams successfully. Thus, Vasya was ready to celebrate, but, alas, he didn't pass it. However, many of Vasya's fellow students from the same group were more successful and celebrated after the exam. ...
{"inputs": ["2 2 0 4\n", "2 2 2 1\n", "6 7 5 8\n", "6 7 5 9\n", "6 7 5 7\n", "0 0 0 0\n", "1 1 0 4\n", "5 5 3 1\n"], "outputs": ["-1", "-1", "-1", "1", "-1", "-1", "2", "-1"]}
coding
620
Solve the programming task below in a Python markdown code block. Create a function that returns the sum of the two lowest positive numbers given an array of minimum 4 positive integers. No floats or non-positive integers will be passed. For example, when an array is passed like `[19, 5, 42, 2, 77]`, the output should...
{"functional": "_inputs = [[[5, 8, 12, 18, 22]], [[7, 15, 12, 18, 22]], [[25, 42, 12, 18, 22]], [[1, 8, 12, 18, 5]], [[13, 12, 5, 61, 22]]]\n_outputs = [[13], [19], [30], [6], [17]]\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_t...
coding
157
Solve the programming task below in a Python markdown code block. Heidi found out that the Daleks have created a network of bidirectional Time Corridors connecting different destinations (at different times!). She suspects that they are planning another invasion on the entire Space and Time. In order to counter the inv...
{"inputs": ["2 1\n1 2 944277353\n", "3 3\n1 2 8\n2 3 3\n3 1 2\n", "3 3\n1 2 8\n2 3 3\n3 1 4\n", "10 10\n9 1 0\n9 4 0\n5 2 0\n8 10 0\n8 3 0\n10 4 0\n1 2 0\n5 6 0\n7 3 0\n6 7 0\n", "10 10\n9 1 0\n9 4 0\n3 2 0\n8 10 0\n8 3 0\n10 4 0\n1 2 0\n5 6 0\n7 3 0\n6 7 0\n", "10 10\n9 1 0\n9 4 0\n3 2 0\n8 10 0\n8 3 0\n10 4 0\n1 2 0\...
coding
717
Solve the programming task below in a Python markdown code block. Read problem statements in [Mandarin], [Bengali], [Russian], and [Vietnamese] as well. You are given an integer N. Consider the sequence containing the integers 1, 2, \ldots, N in increasing order (each exactly once). Find the maximum length of its cont...
{"inputs": ["3\n3\n4\n5"], "outputs": ["3\n4\n4"]}
coding
318
Please solve the programming task below using a self-contained code snippet in a markdown code block. There are n dominoes in a line, and we place each domino vertically upright. In the beginning, we simultaneously push some of the dominoes either to the left or to the right. After each second, each domino that is fal...
{"functional": "def check(candidate):\n assert candidate(dominoes = \"RR.L\") == \"RR.L\"\n assert candidate(dominoes = \".L.R...LR..L..\") == \"LL.RR.LLRRLL..\"\n\n\ncheck(Solution().pushDominoes)"}
coding
274
Solve the programming task below in a Python markdown code block. Dazzler has a task for you. Given two positive integers A and B, find two positive integers i and j such that: [gcd](i,j) > 1; A ≤ i < j ≤ B; The value (i + j) is minimum possible. If there are multiple solutions, you may print any of them. If no such...
{"inputs": ["2\n2 3\n2 10\n"], "outputs": ["-1\n2 4\n"]}
coding
330
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a list of songs where the ith song has a duration of time[i] seconds. Return the number of pairs of songs for which their total duration in seconds is divisible by 60. Formally, we want the number of ind...
{"functional": "def check(candidate):\n assert candidate(time = [30,20,150,100,40]) == 3\n assert candidate(time = [60,60,60]) == 3\n\n\ncheck(Solution().numPairsDivisibleBy60)"}
coding
128
Solve the programming task below in a Python markdown code block. We have a grid with N rows and M columns of squares. Initially, all the squares are white. There is a button attached to each row and each column. When a button attached to a row is pressed, the colors of all the squares in that row are inverted; that i...
{"inputs": ["4 2 2", "4 2 1", "7 9 8", "2 5 8", "6 2 2", "1 5 8", "2 3 2", "2 1 8"], "outputs": ["Yes\n", "No\n", "No\n", "Yes\n", "Yes\n", "No\n", "Yes\n", "No\n"]}
coding
251
Solve the programming task below in a Python markdown code block. Stepan is a very experienced olympiad participant. He has n cups for Physics olympiads and m cups for Informatics olympiads. Each cup is characterized by two parameters — its significance c_{i} and width w_{i}. Stepan decided to expose some of his cups ...
{"inputs": ["1 1 1\n1 1\n1 1\n", "1 1 1\n1 1\n1 1\n", "1 1 1\n1 0\n1 1\n", "3 1 8\n4 2\n5 5\n4 2\n3 2\n", "2 2 2\n5 3\n6 3\n4 2\n8 1\n", "3 1 8\n0 2\n5 5\n4 2\n3 2\n", "2 2 2\n5 3\n6 3\n4 2\n8 2\n", "3 1 6\n0 2\n5 5\n4 2\n3 2\n"], "outputs": ["0\n", "0\n", "2\n", "8\n", "0\n", "8\n", "0\n", "0\n"]}
coding
672
Solve the programming task below in a Python markdown code block. Once Volodya was at the museum and saw a regular chessboard as a museum piece. And there were only four chess pieces on it: two white rooks, a white king and a black king. "Aha, blacks certainly didn't win!", — Volodya said and was right for sure. And yo...
{"inputs": ["e8 e7 d8 g8\n", "b3 a8 d3 a3\n", "b2 c2 b3 b1\n", "c6 b2 g6 b4\n", "a5 c5 c3 a1\n", "d4 e5 b7 a5\n", "e8 e7 f8 h8\n", "h7 h8 c7 a8\n"], "outputs": ["CHECKMATE\n", "OTHER\n", "OTHER\n", "OTHER\n", "OTHER\n", "CHECKMATE\n", "OTHER\n", "OTHER\n"]}
coding
405
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. Sereja has a string A consisting of n lower case English letters. Sereja calls two strings X and Y each of length n similar if they can be made equal by applying the follow...
{"inputs": ["2\nz\nabcd", "2\nz\nabcd"], "outputs": ["0\n144", "0\n144"]}
coding
519
Solve the programming task below in a Python markdown code block. You need to execute several tasks, each associated with number of processors it needs, and the compute power it will consume. You have sufficient number of analog computers, each with enough processors for any task. Each computer can execute up to one t...
{"inputs": ["1\n1\n100\n", "1\n100000000\n1\n", "5\n5 4 3 7 3\n7 7 14 57 94\n", "5\n5 4 3 7 3\n7 7 14 45 94\n", "5\n5 8 3 7 3\n7 7 14 45 94\n", "5\n99 65 5 94 25\n1 5 6 2 3\n", "5\n99 65 93 94 17\n1 5 6 2 3\n", "5\n99 65 93 94 25\n1 5 6 2 3\n"], "outputs": ["10\n", "100000000000\n", "89\n", "96\n", "124\n", "12934\n", ...
coding
586
Solve the programming task below in a Python markdown code block. Fox Ciel has a robot on a 2D plane. Initially it is located in (0, 0). Fox Ciel code a command to it. The command was represented by string s. Each character of s is one move operation. There are four move operations at all: * 'U': go up, (x, y) → (...
{"inputs": ["0 1\nD\n", "1 0\nD\n", "0 0\nD\n", "1 1\nLD\n", "0 -1\nU\n", "-1 0\nR\n", "-1 1\nR\n", "2 4\nRU\n"], "outputs": ["No\n", "No\n", "Yes\n", "No\n", "No\n", "No\n", "No\n", "No\n"]}
coding
466
Solve the programming task below in a Python markdown code block. Snuke has N sticks. The length of the i-th stick is l_i. Snuke is making a snake toy by joining K of the sticks together. The length of the toy is represented by the sum of the individual sticks that compose it. Find the maximum possible length of the to...
{"inputs": ["5 5\n1 2 3 4 5", "5 5\n2 2 3 4 5", "5 3\n2 2 3 4 5", "5 5\n1 2 2 4 5", "5 5\n3 2 3 4 5", "5 5\n1 4 2 4 0", "0 3\n1 1 4 8 0", "5 5\n3 2 3 4 7"], "outputs": ["15\n", "16\n", "12\n", "14\n", "17\n", "11\n", "13\n", "19\n"]}
coding
212
Solve the programming task below in a Python markdown code block. Hofstadter sequences are a family of related integer sequences, among which the first ones were described by an American professor Douglas Hofstadter in his book Gödel, Escher, Bach. ### Task Today we will be implementing the rather chaotic recursive s...
{"functional": "_inputs = [[1], [3], [7], [10], [100], [1000]]\n_outputs = [[1], [2], [5], [6], [56], [502]]\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 le...
coding
231
Solve the programming task below in a Python markdown code block. Arun has an integer N. His friend likes the number 1, so Arun wants to reduce N to 1. To do so, he can perform the following move several times (possibly, zero): Pick two integers X and Y such that X+Y is even and X^{Y} is a divisor of N. Then, replace ...
{"inputs": ["2\n25\n24\n"], "outputs": ["1\n-1"]}
coding
453
Solve the programming task below in a Python markdown code block. The only difference between easy and hard versions is the number of elements in the array. You are given an array $a$ consisting of $n$ integers. In one move you can choose any $a_i$ and divide it by $2$ rounding down (in other words, in one move you ca...
{"inputs": ["1 1\n1337\n", "1 1\n1337\n", "4 2\n9 9 9 9\n", "4 2\n3 3 3 3\n", "4 2\n2 2 2 2\n", "4 2\n3 3 3 3\n", "4 2\n9 9 9 9\n", "4 2\n2 2 2 2\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]}
coding
370
Solve the programming task below in a Python markdown code block. Make the 2D list by the sequential integers started by the ```head``` number. See the example test cases for the expected output. ``` Note: -10**20 < the head number <10**20 1 <= the number of rows <= 1000 0 <= the number of columms <= 1000 ``` Als...
{"functional": "_inputs = [[1, 2, 3], [2, 3, 4], [5, 6, 1], [7, 1, 1], [0, 1, 0], [-20, 2, 2], [10000000000, 2, 2]]\n_outputs = [[[[1, 2, 3], [4, 5, 6]]], [[[2, 3, 4, 5], [6, 7, 8, 9], [10, 11, 12, 13]]], [[[5], [6], [7], [8], [9], [10]]], [[[7]]], [[[]]], [[[-20, -19], [-18, -17]]], [[[10000000000, 10000000001], [1000...
coding
119
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given two strings a and b, return the length of the longest uncommon subsequence between a and b. If no such uncommon subsequence exists, return -1. An uncommon subsequence between two strings is a string that is a su...
{"functional": "def check(candidate):\n assert candidate(a = \"aaa\", b = \"bbb\") == 3\n assert candidate(a = \"aaa\", b = \"aaa\") == -1\n\n\ncheck(Solution().findLUSlength)"}
coding
107
Solve the programming task below in a Python markdown code block. A set of four prime numbers arranged like (a, a + 2, a + 6, a + 8) is called a quadruplet prime number. Of the four prime numbers that make up a quadruplet prime, the largest number is called the size of the quadruplet prime. For example, the smallest pr...
{"inputs": ["13\n23\n15\n0\n0\n76\n1\n0\n10000\n2", "13\n14\n19\n0\n6\n40\n1\n0\n10000\n1", "13\n0\n15\n16\n17\n27\n0\n3\n11000\n0", "13\n14\n15\n16\n0\n24\n0\n3\n11000\n0", "13\n14\n15\n0\n24\n27\n0\n0\n11100\n1", "13\n14\n0\n21\n17\n24\n0\n2\n11000\n0", "13\n19\n15\n16\n0\n18\n0\n20\n10001\n0", "13\n14\n15\n21\n17\n2...
coding
328
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given two strings s1 and s2, both of length n, consisting of lowercase English letters. You can apply the following operation on any of the two strings any number of times: Choose any two indices i and j such...
{"functional": "def check(candidate):\n assert candidate(s1 = \"abcdba\", s2 = \"cabdab\") == True\n assert candidate(s1 = \"abe\", s2 = \"bea\") == False\n\n\ncheck(Solution().checkStrings)"}
coding
145
Solve the programming task below in a Python markdown code block. *It seemed a good idea at the time...* # Why I did it? After a year on **Codewars** I really needed a holiday... But not wanting to drift backwards in the honour rankings while I was away, I hatched a cunning plan! # The Cunning Plan So I borrowed m...
{"functional": "_inputs = [[0], [1], [5], [10]]\n_outputs = [[[1, 0]], [[1, 1]], [[16, 57]], [[512, 2036]]]\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...
coding
513
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an integer mountain array arr of length n where the values increase to a peak element and then decrease. Return the index of the peak element. Your task is to solve it in O(log(n)) time complexity.   Ple...
{"functional": "def check(candidate):\n assert candidate(arr = [0,1,0]) == 1\n assert candidate(arr = [0,2,1,0]) == 1\n assert candidate(arr = [0,10,5,2]) == 1\n\n\ncheck(Solution().peakIndexInMountainArray)"}
coding
96
Solve the programming task below in a Python markdown code block. Chef has 3 numbers A, B and C. Chef wonders if it is possible to choose *exactly* two numbers out of the three numbers such that their sum is odd. ------ Input Format ------ - The first line of input will contain a single integer T, denoting the num...
{"inputs": ["4\n1 2 3\n8 4 6\n3 3 9\n7 8 6\n"], "outputs": ["YES\nNO\nNO\nYES\n"]}
coding
286
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin Chinese and Russian. ------ Sereja and Arrays ------ Sereja have an array that consist of n integers a1, a2, ..., an (0 ≤ ai ≤ 1). Sereja can make next operation: fix some integer i (1 ≤ i ≤ n - k + 1) subtra...
{"inputs": ["3\n3 3\n5 2\n5 1"], "outputs": ["2\n8\n32"]}
coding
370
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin Chinese and Russian as well. Given an array of N numbers, a pair of numbers is called good if difference between the two numbers is strictly less than D. Find out maximum possible sum of all good disjoint pairs that...
{"inputs": ["3\n3 3\n3 5 8\n3 3\n5 8 20 0\n5 3\n3 3 8 17 9", "3\n3 3\n3 5 8\n4 3\n5 1 0 20\n5 6\n3 1 8 14 15", "3\n3 3\n3 5 8\n4 3\n5 1 0 20\n5 6\n3 1 5 14 15", "3\n3 3\n0 2 8\n4 3\n5 8 36 8\n1 3\n3 2 8 17 15", "3\n3 3\n3 5 8\n4 3\n5 2 0 20\n5 6\n3 1 5 14 15", "3\n3 3\n3 5 8\n4 3\n3 8 10 5\n5 3\n3 2 3 15 15", "3\n2 1\n...
coding
361
Solve the programming task below in a Python markdown code block. The letters shop showcase is a string s, consisting of n lowercase Latin letters. As the name tells, letters are sold in the shop. Letters are sold one by one from the leftmost to the rightmost. Any customer can only buy some prefix of letters from the ...
{"inputs": ["4\nabcd\n3\na\nd\nac\n", "4\nacbd\n3\na\nd\nac\n", "4\ndbca\n3\na\nd\nca\n", "4\nacbd\n3\na\nc\nac\n", "4\nacbd\n3\nb\nd\nca\n", "4\ndcba\n3\na\nc\nac\n", "4\nacbd\n3\nb\nd\ncb\n", "4\ndbca\n3\na\nc\nac\n"], "outputs": ["1\n4\n3\n", "1\n4\n2\n", "4\n1\n4\n", "1\n2\n2\n", "3\n4\n2\n", "4\n2\n4\n", "3\n4\n3\...
coding
588
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a string s containing lowercase letters and an integer k. You need to : First, change some characters of s to other lowercase English letters. Then divide s into k non-empty disjoint substrings such tha...
{"functional": "def check(candidate):\n assert candidate(s = \"abc\", k = 2) == 1\n assert candidate(s = \"aabbc\", k = 3) == 0\n assert candidate(s = \"leetcode\", k = 8) == 0\n\n\ncheck(Solution().palindromePartition)"}
coding
116
Solve the programming task below in a Python markdown code block. Ripul was skilled in the art of lapidary. He used to collect stones and convert it into decorative items for sale. There were n stone shops. Each shop was having one exclusive stone of value s[i] , where 1<=i<=n. If number of stones collected are more ...
{"inputs": ["1\n3\n1 2 3"], "outputs": ["6 1 2"]}
coding
483
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"]}
coding
513
Solve the programming task below in a Python markdown code block. The year 2015 is almost over. Limak is a little polar bear. He has recently learnt about the binary system. He noticed that the passing year has exactly one zero in its representation in the binary system — 2015_10 = 11111011111_2. Note that he doesn't ...
{"inputs": ["1 1\n", "1 2\n", "1 3\n", "1 4\n", "1 5\n", "1 6\n", "1 7\n", "2 2\n"], "outputs": ["0\n", "1\n", "1\n", "1\n", "2\n", "3\n", "3\n", "1\n"]}
coding
417
Solve the programming task below in a Python markdown code block. In Chefland, a tennis game involves 4 referees. Each referee has to point out whether he considers the ball to be inside limits or outside limits. The ball is considered to be IN if and only if all the referees agree that it was inside limits. Given t...
{"inputs": ["4\n1 1 0 0\n0 0 0 0\n0 0 0 1\n1 1 1 1\n"], "outputs": ["OUT\nIN\nOUT\nOUT\n"]}
coding
440
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)"}
coding
159
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin Chinese and Russian. This is a very easy warm-up problem. You are given a string. Your task is to determine whether number of occurrences of some character in the string is equal to the sum of the numbers of occurr...
{"inputs": ["4\nacab\nzzqzqq\nabc\nkklkwwww", "4\nacab\nzzqzqq\ncba\nkklkwwww", "4\nacbb\nzzqzqq\ncba\nkkmkwvww", "4\ncbba\nqrzqyz\nbab\nkllkxwvw", "4\naccc\nqrzqyz\nbab\nkklkxwvw", "4\nabbb\nzzqzqq\ncba\nkkmkwwww", "4\ncbbb\nqqzqyz\nbab\nkllkxwvw", "4\nadac\nzzqypr\nabc\nkklkwwww"], "outputs": ["YES\nYES\nNO\nYES", "Y...
coding
245
Solve the programming task below in a Python markdown code block. Little penguin Polo adores strings. But most of all he adores strings of length n. One day he wanted to find a string that meets the following conditions: 1. The string consists of n lowercase English letters (that is, the string's length equals n), ...
{"inputs": ["3 3\n", "1 1\n", "1 2\n", "2 2\n", "7 7\n", "9 4\n", "4 4\n", "1 4\n"], "outputs": ["abc\n", "a\n", "-1\n", "ab\n", "abcdefg\n", "abababacd\n", "abcd\n", "-1\n"]}
coding
370
Solve the programming task below in a Python markdown code block. Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. Ari and Rich are playing a pretty confusing game. Here are the rules of the game: The game is played with two piles of matches. Initially, the first ...
{"inputs": ["5\n1 1\n2 2\n1 3\n155 47\n6 4"], "outputs": ["Ari\nAri\nAri\nAri\nRich"]}
coding
537
Solve the programming task below in a Python markdown code block. Moscow is hosting a major international conference, which is attended by n scientists from different countries. Each of the scientists knows exactly one language. For convenience, we enumerate all languages of the world with integers from 1 to 10^9. In ...
{"inputs": ["1\n8\n1\n10\n3\n", "1\n8\n1\n17\n3\n", "1\n10\n1\n10\n3\n", "2\n1 6\n1\n6\n1\n", "1\n10\n1\n10\n3\n", "2\n1 6\n1\n6\n1\n", "1\n19\n1\n10\n3\n", "2\n1 6\n1\n3\n1\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n"]}
coding
730
Solve the programming task below in a Python markdown code block. Write a function named setAlarm which receives two parameters. The first parameter, employed, is true whenever you are employed and the second parameter, vacation is true whenever you are on vacation. The function should return true if you are employed a...
{"functional": "_inputs = [[True, True], [False, True], [False, False], [True, False]]\n_outputs = [[False], [False], [False], [True]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (lis...
coding
156
Solve the programming task below in a Python markdown code block. You are given two strings. In a single move, you can choose any of them, and delete the first (i.e. leftmost) character. For Example: * By applying a move to the string `"where"`, the result is the string `"here"`. * By applying a move to the string `"...
{"functional": "_inputs = [['test', 'west'], ['test', 'yes'], ['b', 'ab'], ['abacabadabacaba', 'abacabadacaba'], ['aaabc', 'bc'], ['dark', 'd'], ['dadc', 'dddc'], ['nogkvcdldfpvlbkpedsecl', 'nogkvcdldfpvlbkpedsecl']]\n_outputs = [[2], [7], [1], [18], [3], [5], [4], [0]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n ...
coding
161
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an array of distinct integers nums and a target integer target, return the number of possible combinations that add up to target. The test cases are generated so that the answer can fit in a 32-bit integer.   Pl...
{"functional": "def check(candidate):\n assert candidate(nums = [1,2,3], target = 4) == 7\n assert candidate(nums = [9], target = 3) == 0\n\n\ncheck(Solution().combinationSum4)"}
coding
98
Solve the programming task below in a Python markdown code block. Monocarp is a little boy who lives in Byteland and he loves programming. Recently, he found a permutation of length $n$. He has to come up with a mystic permutation. It has to be a new permutation such that it differs from the old one in each position. ...
{"inputs": ["4\n3\n1 2 3\n5\n2 3 4 5 1\n4\n2 3 1 4\n1\n1\n"], "outputs": ["2 3 1\n1 2 3 4 5\n1 2 4 3\n-1\n"]}
coding
683
Solve the programming task below in a Python markdown code block. Emma is really fond of integers and loves playing with them. Her friends were jealous, and to test her, one of them gave her a problem. Emma is given a list ${A}$ of $N$ integers and is asked a set of ${Q}$ queries. Each query is denoted by an integer ...
{"inputs": ["3\n1 2 2\n1\n2\n", "3\n1 2 3\n2\n1\n2\n"], "outputs": ["8\n", "6\n11\n"]}
coding
566
Solve the programming task below in a Python markdown code block. Read problems statements in [Mandarin Chinese], [Russian], [Vietnamese] and [Bengali] as well. Suppose the population is divided into the age groups $[1, 10], [11, 20], [21, 30], \ldots, [91, \infty)$. The age groups are numbered from $1$ to $10$ and th...
{"inputs": ["3\n5 2 2 2 2 2 2 2 2 2 2 2\n5 2 2 2 2 2 2 3 2 2 2 2\n9 4 2 2 2 2 3 2 2 2 2 2"], "outputs": ["6 6\n6 7\n1 1"]}
coding
656
Solve the programming task below in a Python markdown code block. The Cybermen and the Daleks have long been the Doctor's main enemies. Everyone knows that both these species enjoy destroying everything they encounter. However, a little-known fact about them is that they both also love taking Turing tests! Heidi desig...
{"inputs": ["2\n0 0\n0 1\n0 2\n1 0\n1 1\n1 2\n2 0\n2 1\n2 2\n", "2\n0 0\n0 1\n0 2\n0 3\n1 0\n1 2\n2 0\n2 1\n2 2\n", "2\n0 0\n0 1\n0 2\n0 3\n1 0\n1 2\n2 0\n2 1\n2 2\n", "2\n0 0\n0 1\n0 2\n1 0\n1 1\n1 2\n2 0\n2 1\n2 2\n", "2\n1 2\n1 27\n1 45\n10 45\n28 48\n38 1\n44 1\n45 7\n45 26\n", "2\n1 2\n1 27\n1 45\n10 45\n28 48\n38...
coding
400
Solve the programming task below in a Python markdown code block. Consider the function p(x), where x is an array of m integers, which returns an array y consisting of m + 1 integers such that y_{i} is equal to the sum of first i elements of array x (0 ≤ i ≤ m). You have an infinite sequence of arrays A^0, A^1, A^2......
{"inputs": ["2 2\n1 1\n", "2 2\n1 1\n", "3 6\n1 1 1\n", "3 1\n1 0 1\n", "3 6\n1 1 1\n", "3 1\n1 0 1\n", "3 1\n1 -1 1\n", "3 1\n2 -1 1\n"], "outputs": ["1\n", "1\n", "2\n", "0\n", "2\n", "0\n", "0\n", "0\n"]}
coding
327
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an encoded string s. To decode the string to a tape, the encoded string is read one character at a time and the following steps are taken: If the character read is a letter, that letter is written onto ...
{"functional": "def check(candidate):\n assert candidate(s = \"leet2code3\", k = 10) == \"o\"\n assert candidate(s = \"ha22\", k = 5) == \"h\"\n assert candidate(s = \"a2345678999999999999999\", k = 1) == \"a\"\n\n\ncheck(Solution().decodeAtIndex)"}
coding
145
Solve the programming task below in a Python markdown code block. Stanley and Megan decided to shop in the "Crossmarket" grocery store, which can be represented as a matrix with $n$ rows and $m$ columns. Stanley and Megan can move to an adjacent cell using $1$ unit of power. Two cells are considered adjacent if they s...
{"inputs": ["1\n2 2\n", "4\n1 1\n1 2\n2 1\n2 2\n", "7\n7 5\n5 7\n1 1\n100000 100000\n57 228\n1 5\n5 1\n"], "outputs": ["4\n", "0\n2\n2\n4\n", "15\n15\n0\n299998\n340\n5\n5\n"]}
coding
575
Solve the programming task below in a Python markdown code block. Vasilisa the Wise from a far away kingdom got a present from her friend Helga the Wise from a farther away kingdom. The present is a surprise box, yet Vasilisa the Wise doesn't know yet what the surprise actually is because she cannot open the box. She h...
{"inputs": ["RRYYOO\n", "YYBBOO\n", "RRBYRR\n", "YYYYRB\n", "BYOVRR\n", "GVGBVO\n", "OVBRYG\n", "BRRBRB\n"], "outputs": ["6\n", "6\n", "2\n", "2\n", "15\n", "8\n", "30\n", "2\n"]}
coding
368
Please solve the programming task below using a self-contained code snippet in a markdown code block. We are given hours, a list of the number of hours worked per day for a given employee. A day is considered to be a tiring day if and only if the number of hours worked is (strictly) greater than 8. A well-performing i...
{"functional": "def check(candidate):\n assert candidate(hours = [9,9,6,0,6,6,9]) == 3\n assert candidate(hours = [6,6,6]) == 0\n\n\ncheck(Solution().longestWPI)"}
coding
139
Solve the programming task below in a Python markdown code block. A subsequence of length |x| of string s = s1s2... s|s| (where |s| is the length of string s) is a string x = sk1sk2... sk|x| (1 ≤ k1 < k2 < ... < k|x| ≤ |s|). You've got two strings — s and t. Let's consider all subsequences of string s, coinciding with...
{"inputs": ["aa\naaa\n", "abc\nba\n", "ab\nabcd\n", "abc\nbac\n", "ab\nadcb\n", "abc\nbad\n", "abab\nac\n", "ab\nbdcb\n"], "outputs": ["No\n", "No\n", "No\n", "No\n", "No\n", "No\n", "No\n", "No\n"]}
coding
387
Solve the programming task below in a Python markdown code block. Allen is hosting a formal dinner party. 2n people come to the event in n pairs (couples). After a night of fun, Allen wants to line everyone up for a final picture. The 2n people line up, but Allen doesn't like the ordering. Allen prefers if each pair oc...
{"inputs": ["1\n1 1\n", "2\n1 2 1 2\n", "2\n2 1 1 2\n", "2\n1 1 2 2\n", "2\n2 1 2 1\n", "2\n2 2 1 1\n", "2\n1 2 2 1\n", "3\n1 2 3 3 1 2\n"], "outputs": ["0", "1", "2", "0\n", "1\n", "0\n", "2\n", "5"]}
coding
446
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a string expression representing a Lisp-like expression to return the integer value of. The syntax for these expressions is given as follows. An expression is either an integer, let expression, add expr...
{"functional": "def check(candidate):\n assert candidate(expression = \"(let x 2 (mult x (let x 3 y 4 (add x y))))\") == 14\n assert candidate(expression = \"(let x 3 x 2 x)\") == 2\n assert candidate(expression = \"(let x 1 y 2 x (add x y) (add x y))\") == 5\n\n\ncheck(Solution().evaluate)"}
coding
445
Solve the programming task below in a Python markdown code block. One of the oddest traditions of the town of Gameston may be that even the town mayor of the next term is chosen according to the result of a game. When the expiration of the term of the mayor approaches, at least three candidates, including the mayor of ...
{"inputs": ["3 2\n3 3\n4 50\n5 29\n57 4\n50 2\n50 50\n0 0", "3 2\n6 3\n4 50\n5 29\n57 4\n50 2\n50 50\n0 0", "3 2\n1 2\n3 10\n10 4\n4 32\n39 2\n50 50\n0 0", "3 2\n3 3\n6 50\n10 4\n74 4\n17 1\n66 50\n0 0", "3 5\n3 2\n3 50\n17 6\n65 6\n50 2\n50 50\n0 0", "6 2\n1 2\n3 10\n1 4\n66 38\n39 2\n50 50\n0 0", "3 2\n3 3\n3 76\n10 ...
coding
677
Solve the programming task below in a Python markdown code block. ## Your story You've always loved both Fizz Buzz katas and cuckoo clocks, and when you walked by a garage sale and saw an ornate cuckoo clock with a missing pendulum, and a "Beyond-Ultimate Raspberry Pi Starter Kit" filled with all sorts of sensors and m...
{"functional": "_inputs = [['13:34'], ['21:00'], ['11:15'], ['03:03'], ['14:30'], ['08:55'], ['00:00'], ['12:00']]\n_outputs = [['tick'], ['Cuckoo Cuckoo Cuckoo Cuckoo Cuckoo Cuckoo Cuckoo Cuckoo Cuckoo'], ['Fizz Buzz'], ['Fizz'], ['Cuckoo'], ['Buzz'], ['Cuckoo Cuckoo Cuckoo Cuckoo Cuckoo Cuckoo Cuckoo Cuckoo Cuckoo Cu...
coding
720
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. Chef recently learned about ratios and proportions. He wrote some positive integers a, b, c, d o...
{"inputs": ["1 2 4 2"], "outputs": ["Possible"]}
coding
276
Solve the programming task below in a Python markdown code block. Playing with Stones Koshiro and Ukiko are playing a game with black and white stones. The rules of the game are as follows: 1. Before starting the game, they define some small areas and place "one or more black stones and one or more white stones" in e...
{"inputs": ["3\n1 2\n2 21\n3 0", "3\n1 1\n2 21\n3 0", "3\n1 1\n2 21\n5 0", "3\n0 5\n9 58\n46 1", "3\n0 5\n9 23\n46 1", "3\n0 5\n9 23\n66 1", "3\n0 5\n9 19\n66 1", "3\n0 5\n9 19\n17 1"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]}
coding
478
Solve the programming task below in a Python markdown code block. Vasya is an active Internet user. One day he came across an Internet resource he liked, so he wrote its address in the notebook. We know that the address of the written resource has format: <protocol>://<domain>.ru[/<context>] where: <protocol> can eq...
{"inputs": ["ftprru\n", "ftprru\n", "ftparua\n", "httpzru\n", "ftparua\n", "httpzru\n", "httprrur\n", "httprrur\n"], "outputs": ["ftp://r.ru\n", "ftp://r.ru", "ftp://a.ru/a\n", "http://z.ru\n", "ftp://a.ru/a\n", "http://z.ru", "http://r.ru/r\n", "http://r.ru/r\n"]}
coding
426
Solve the programming task below in a Python markdown code block. Read problem statements in [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. Chef is a very lazy person. Whatever work is supposed to be finished in x units of time, he finishes it in m * x units of time. But there is always a limit to...
{"inputs": ["3\n1 1 0\n1 3 1\n2 2 3"], "outputs": ["1\n2\n4"]}
coding
381
Solve the programming task below in a Python markdown code block. Alice, Bob, and Charlie have X, Y, and Z chocolates respectively. Find whether you can redistribute the chocolates such that: Each person has at least one chocolate; No two people have same number of chocolates; No chocolate is left after redistributio...
{"inputs": ["4\n1 2 3\n1 1 1\n2 2 2\n2 1 1\n"], "outputs": ["YES\nNO\nYES\nNO\n"]}
coding
412
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order, and each of their nodes contains a single digit. Add the two numbers and return the sum as a lin...
{"functional": "def check(candidate):\n assert is_same_list(candidate(l1 = list_node([2,4,3]), l2 = list_node([5,6,4])), list_node([7,0,8]))\n assert is_same_list(candidate(l1 = list_node([0]), l2 = list_node([0])), list_node([0]))\n assert is_same_list(candidate(l1 = list_node([9,9,9,9,9,9,9]), l2 = list_node...
coding
166
Solve the programming task below in a Python markdown code block. Anton likes to listen to fairy tales, especially when Danik, Anton's best friend, tells them. Right now Danik tells Anton a fairy tale: "Once upon a time, there lived an emperor. He was very rich and had much grain. One day he ordered to build a huge ba...
{"inputs": ["5 2\n", "8 1\n", "1 1\n", "2 1\n", "2 2\n", "3 1\n", "3 2\n", "3 3\n"], "outputs": ["4\n", "5\n", "1\n", "2\n", "2\n", "3\n", "3\n", "3\n"]}
coding
712
Solve the programming task below in a Python markdown code block. A queen is the strongest chess piece. In modern chess the queen can move any number of squares in any horizontal, vertical or diagonal direction (considering that there're no other pieces on its way). The queen combines the options given to the rook and ...
{"inputs": ["2 1\n1 1\n", "1 1\n1 1\n", "2 2\n1 1\n1 2\n", "20 3\n1 1\n1 2\n1 3\n", "38 3\n1 1\n1 2\n1 3\n", "10 3\n1 1\n1 2\n1 3\n", "2 4\n2 1\n1 2\n2 2\n1 1\n", "8 4\n4 3\n8 8\n6 5\n1 6\n"], "outputs": ["1 0 0 0 0 0 0 0 0\n", "1 0 0 0 0 0 0 0 0\n", "0 2 0 0 0 0 0 0 0\n", "0 2 1 0 0 0 0 0 0\n", "0 2 1 0 0 0 0 0 0\n", ...
coding
458
Solve the programming task below in a Python markdown code block. Six friends go on a trip and are looking for accommodation. After looking for hours, they find a hotel which offers two types of rooms — double rooms and triple rooms. A double room costs Rs. X, while a triple room costs Rs. Y. The friends can either ge...
{"inputs": ["3\n10 15\n6 8\n4 8\n"], "outputs": ["30\n16\n12\n"]}
coding
318
Solve the programming task below in a Python markdown code block. There are n pictures delivered for the new exhibition. The i-th painting has beauty a_{i}. We know that a visitor becomes happy every time he passes from a painting to a more beautiful one. We are allowed to arranged pictures in any order. What is the m...
{"inputs": ["1\n995\n", "1\n995\n", "1\n1000\n", "1\n1000\n", "2\n179 5\n", "2\n251 75\n", "2\n251 42\n", "2\n251 30\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "1\n", "1\n", "1\n", "1\n"]}
coding
362
Solve the programming task below in a Python markdown code block. There are N monsters, numbered 1, 2, ..., N. Initially, the health of Monster i is A_i. Below, a monster with at least 1 health is called alive. Until there is only one alive monster, the following is repeated: - A random alive monster attacks another r...
{"inputs": ["4\n1 1 1 2", "4\n1 1 1 3", "4\n1 1 1 6", "4\n1 1 2 6", "4\n1 1 4 6", "4\n1 1 0 6", "4\n2 1 0 6", "4\n2 1 0 1"], "outputs": ["1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n"]}
coding
247
Solve the programming task below in a Python markdown code block. The string $s$ is given, the string length is odd number. The string consists of lowercase letters of the Latin alphabet. As long as the string length is greater than $1$, the following operation can be performed on it: select any two adjacent letters i...
{"inputs": ["1\nwabalabadubdu\nw\n", "1\nasdfghjklqwertyuiop\ne\n", "1\nasdfghjklqwertyuiop\nf\n", "1\nadsfdxvxvsdfdgxcvsdfd\nc\n", "1\nhghjhgvdvkhbgtftfvgvp\nj\n", "1\nqwertyuioppoiuytrewqplkmnjiuhbs\nz\n", "5\nabcde\nc\nabcde\nb\nx\ny\nabobobussss\ns\ncontest\nt\n", "5\nabcde\nc\nabcde\nb\nx\ny\naaaaaaaaaaaaaaa\na\nc...
coding
603
Solve the programming task below in a Python markdown code block. You are given a weighted graph with $N$ nodes and $M$ edges. Some of the nodes are marked as special nodes. Your task is to find the shortest pairwise distance between any two different special nodes. -----Input----- - The first line of the input contai...
{"inputs": ["5 5 3\n1 3 5\n1 2 3\n2 3 4\n3 4 1\n4 5 8\n1 5 19"], "outputs": ["7"]}
coding
597
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...
coding
191
Solve the programming task below in a Python markdown code block. Sasha likes programming. Once, during a very long contest, Sasha decided that he was a bit tired and needed to relax. So he did. But since Sasha isn't an ordinary guy, he prefers to relax unusually. During leisure time Sasha likes to upsolve unsolved pro...
{"inputs": ["3\n3 4 2\n", "3\n3 4 3\n", "3\n2 4 3\n", "3\n2 4 6\n", "3\n2 2 6\n", "3\n2 2 7\n", "3\n2 4 7\n", "3\n0 4 8\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "1\n", "1\n", "0\n", "0\n"]}
coding
516
Solve the programming task below in a Python markdown code block. You are given an array $a$ of $n$ positive integers. You can use the following operation as many times as you like: select any integer $1 \le k \le n$ and do one of two things: decrement by one $k$ of the first elements of the array. decrement by one...
{"inputs": ["4\n3\n1 2 1\n5\n4 7 9 6 8\n5\n1 3 1 3 1\n4\n5 2 1 10\n", "4\n3\n1 2 1\n5\n4 7 9 6 8\n5\n2 3 1 3 1\n4\n5 2 1 10\n", "4\n3\n1 2 1\n5\n4 7 9 6 8\n5\n2 3 1 3 2\n4\n5 2 1 10\n", "4\n3\n1 2 1\n5\n4 7 9 6 8\n5\n2 3 1 3 2\n4\n5 2 0 10\n", "4\n3\n1 2 1\n5\n4 7 9 6 8\n5\n2 3 0 3 2\n4\n5 2 0 10\n", "4\n3\n1 2 2\n5\n1...
coding
518
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin Chinese and Russian as well. Mike and his friend Tom are playing a very interesting game right now. Here is the description of the game: Initially, there is a positive integer N written on the desk, which is stri...
{"inputs": ["4 \n5 \n3 \n2 \n4"], "outputs": ["Tom\nTom\nMike\nMike"]}
coding
386
Solve the programming task below in a Python markdown code block. There is unrest in the Galactic Senate. Several thousand solar systems have declared their intentions to leave the Republic. Master Heidi needs to select the Jedi Knights who will go on peacekeeping missions throughout the galaxy. It is well-known that t...
{"inputs": ["1 1\n1\n1\n", "1 1\n1\n1\n", "2 1\n1 1\n1\n", "2 1\n1 1\n2\n", "2 1\n1 1\n1\n", "2 1\n1 1\n2\n", "2 2\n1 2\n1 1\n", "2 2\n2 2\n0 2\n"], "outputs": ["YES\n", "YES\n", "YES\n", "YES\n", "YES\n", "YES\n", "YES\n", "YES\n"]}
coding
360
Solve the programming task below in a Python markdown code block. Create a function which answers the question "Are you playing banjo?". If your name starts with the letter "R" or lower case "r", you are playing banjo! The function takes a name as its only argument, and returns one of the following strings: ``` name...
{"functional": "_inputs = [['Adam'], ['Paul'], ['Ringo'], ['bravo'], ['rolf']]\n_outputs = [['Adam does not play banjo'], ['Paul does not play banjo'], ['Ringo plays banjo'], ['bravo does not play banjo'], ['rolf plays banjo']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, fl...
coding
121
Please solve the programming task below using a self-contained code snippet in a markdown code block. You start at the cell (rStart, cStart) of an rows x cols grid facing east. The northwest corner is at the first row and column in the grid, and the southeast corner is at the last row and column. You will walk in a cl...
{"functional": "def check(candidate):\n assert candidate(rows = 1, cols = 4, rStart = 0, cStart = 0) == [[0,0],[0,1],[0,2],[0,3]]\n assert candidate(rows = 5, cols = 6, rStart = 1, cStart = 4) == [[1,4],[1,5],[2,5],[2,4],[2,3],[1,3],[0,3],[0,4],[0,5],[3,5],[3,4],[3,3],[3,2],[2,2],[1,2],[0,2],[4,5],[4,4],[4,3],[4,...
coding
184
Solve the programming task below in a Python markdown code block. N of us are going on a trip, by train or taxi. The train will cost each of us A yen (the currency of Japan). The taxi will cost us a total of B yen. How much is our minimum total travel expense? -----Constraints----- - All values in input are integers....
{"inputs": ["6 2 7", "4 4 9", "3 2 8", "6 1 0", "6 4 1", "7 4 2", "5 2 5", "5 2 8"], "outputs": ["7\n", "9\n", "6\n", "0\n", "1\n", "2\n", "5\n", "8\n"]}
coding
199
Solve the programming task below in a Python markdown code block. There is a string S consisting of digits 1, 2, ..., 9. Lunlun, the Dachshund, will take out three consecutive digits from S, treat them as a single integer X and bring it to her master. (She cannot rearrange the digits.) The master's favorite number is 7...
{"inputs": ["820", "708", "792", "571", "2761", "5306", "1537", "1801"], "outputs": ["67\n", "45\n", "39\n", "182\n", "8\n", "223\n", "216\n", "48\n"]}
coding
335