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. You are standing on the $\mathit{OX}$-axis at point $0$ and you want to move to an integer point $x > 0$. You can make several jumps. Suppose you're currently at point $y$ ($y$ may be negative) and jump for the $k$-th time. You can: either jump to the ...
{"inputs": ["1\n8\n", "1\n6\n", "1\n3\n", "1\n1\n", "1\n4\n", "1\n7\n", "1\n10\n", "1\n10\n"], "outputs": ["4\n", "3\n", "2\n", "1\n", "3\n", "4\n", "4\n", "4\n"]}
coding
672
Solve the programming task below in a Python markdown code block. This time the Berland Team Olympiad in Informatics is held in a remote city that can only be reached by one small bus. Bus has n passenger seats, seat i can be occupied only by a participant from the city a_{i}. Today the bus has completed m trips, each...
{"inputs": ["1 5 8\n1\n", "1 9 10\n1\n", "1 9 13\n1\n", "1 2 13\n1\n", "1 5 13\n1\n", "1 3 13\n1\n", "1 8 10\n1\n", "1 9 10\n2\n"], "outputs": ["3\n", "1\n", "4\n", "1\n", "3\n", "1\n", "2\n", "1\n"]}
coding
440
Solve the programming task below in a Python markdown code block. Create an OR function, without use of the 'or' keyword, that takes an list of boolean values and runs OR against all of them. Assume there will be between 1 and 6 variables, and return None for an empty list. Also feel free to reuse/extend the following...
{"functional": "_inputs = [[[]], [[False, False, False, False, False, False]], [[False, False, False, False, False, True]], [[False, False, False, False, True, False]], [[False, False, False, False, True, True]], [[False, False, False, True, False, False]], [[False, False, False, True, False, True]], [[False, False, Fa...
coding
84
Solve the programming task below in a Python markdown code block. Alice gave Bob two integers $a$ and $b$ ($a > 0$ and $b \ge 0$). Being a curious boy, Bob wrote down an array of non-negative integers with $\operatorname{MEX}$ value of all elements equal to $a$ and $\operatorname{XOR}$ value of all elements equal to $b...
{"inputs": ["1\n0001 0\n", "1\n1001 1\n", "1\n1010 1\n", "1\n1000 0\n", "1\n1100 0\n", "1\n1100 1\n", "1\n0010 1\n", "1\n0010 0\n"], "outputs": ["1\n", "1003\n", "1010\n", "1000\n", "1100\n", "1101\n", "10\n", "11\n"]}
coding
501
Solve the programming task below in a Python markdown code block. Given a triangle of numbers where each number is equal to the sum of the three numbers on top of it, find the first even number in a row. Explanatory Note: The vertex of the triangle (at the top) is 1. The structure of the triangle is shown below. Eac...
{"inputs": ["2\n3\n4\n"], "outputs": ["2\n3\n"]}
coding
345
Solve the programming task below in a Python markdown code block. Perhaps many have heard that the World Biathlon Championship has finished. Although our hero Valera was not present at this spectacular event himself and only watched it on TV, it excited him so much that he decided to enroll in a biathlon section. Of c...
{"inputs": ["2\n0 5\n10 5\n2\n7 2\n6 1\n", "2\n0 5\n10 5\n2\n7 2\n0 1\n", "2\n0 5\n10 5\n2\n9 2\n0 1\n", "2\n0 5\n10 7\n2\n9 2\n0 1\n", "3\n1 1\n3 1\n-4 2\n1\n-4 -3\n", "3\n3 2\n7 1\n11 1\n4\n2 1\n6 0\n6 4\n11 2\n", "3\n3 2\n0 1\n11 1\n4\n2 1\n6 0\n6 4\n11 2\n", "3\n3 2\n0 1\n11 1\n4\n2 1\n6 0\n1 4\n11 2\n"], "outputs"...
coding
725
Solve the programming task below in a Python markdown code block. Program the function distance(p1, p2) which returns the distance between the points p1 and p2 in n-dimensional space. p1 and p2 will be given as arrays. Your program should work for all lengths of arrays, and should return -1 if the arrays aren't of the...
{"functional": "_inputs = [[[], []], [[1], [1, 1, 1, 1, 1, 1, 1, 1, 1]]]\n_outputs = [[-1], [-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)):\n if len(a) != len...
coding
136
Solve the programming task below in a Python markdown code block. You are given an integer sequence of length N. The i-th term in the sequence is a_i. In one operation, you can select a term and either increment or decrement it by one. At least how many operations are necessary to satisfy the following conditions? - F...
{"inputs": ["4\n1 -3 1 0\n", "5\n3 -6 4 -5 7\n", "6\n-1 4 3 2 -5 4\n"], "outputs": ["4\n", "0\n", "8\n"]}
coding
300
Solve the programming task below in a Python markdown code block. Chef considers a permutation P of \{1, 2, 3, \dots, N\} End Sorted if and only if P_{1} = 1 and P_{N} = N. Chef is given a permutation P. In one operation Chef can choose any index i \ (1 ≀ i ≀ N-1) and swap P_{i} and P_{i+1}. Determine the minimum num...
{"inputs": ["4\n4\n1 3 2 4\n3\n3 2 1\n2\n2 1\n3\n2 1 3\n"], "outputs": ["0\n3\n1\n1\n"]}
coding
587
Solve the programming task below in a Python markdown code block. The door of Snuke's laboratory is locked with a security code. The security code is a 4-digit number. We say the security code is hard to enter when it contains two consecutive digits that are the same. You are given the current security code S. If S is ...
{"inputs": ["44", "333", "446", "199", "110", "100", "000", "377"], "outputs": ["Bad\n", "Bad\n", "Bad\n", "Bad\n", "Bad\n", "Bad\n", "Bad\n", "Bad\n"]}
coding
166
Solve the programming task below in a Python markdown code block. Snuke has decided to play a game, where the player runs a railway company. There are M+1 stations on Snuke Line, numbered 0 through M. A train on Snuke Line stops at station 0 and every d-th station thereafter, where d is a predetermined constant for eac...
{"inputs": ["3 3\n1 2\n1 3\n3 3", "3 3\n1 1\n1 3\n3 3", "3 3\n1 2\n2 3\n3 3", "3 3\n1 2\n2 3\n3 3\n", "7 9\n1 9\n5 9\n5 7\n5 9\n1 1\n6 8\n3 4", "7 9\n1 9\n9 9\n5 7\n5 9\n1 1\n6 8\n3 4", "7 9\n1 9\n9 9\n5 7\n5 9\n1 1\n8 8\n3 4", "7 9\n1 9\n9 9\n5 5\n5 9\n1 1\n8 8\n3 4"], "outputs": ["3\n2\n2\n", "3\n1\n2\n", "3\n2\n2", ...
coding
486
Solve the programming task below in a Python markdown code block. City X consists of n vertical and n horizontal infinite roads, forming n Γ— n intersections. Roads (both vertical and horizontal) are numbered from 1 to n, and the intersections are indicated by the numbers of the roads that form them. Sand roads have lo...
{"inputs": ["1\n1 1\n", "1\n1 1\n", "2\n1 1\n1 2\n2 1\n2 2\n", "2\n1 1\n2 2\n1 2\n2 1\n", "2\n1 2\n2 2\n2 1\n1 1\n", "2\n1 2\n2 2\n2 1\n1 1\n", "2\n1 1\n2 2\n1 2\n2 1\n", "2\n1 1\n2 2\n1 2\n1 1\n"], "outputs": ["1 \n", "1\n", "1 4 \n", "1 2 \n", "1 3 \n", "1 3\n", "1 2\n", "1 2 "]}
coding
644
Solve the programming task below in a Python markdown code block. You can't possibly imagine how cold our friends are this winter in Nvodsk! Two of them play the following game to warm up: initially a piece of paper has an integer q. During a move a player should write any integer number that is a non-trivial divisor o...
{"inputs": ["9\n", "5\n", "2\n", "8\n", "3\n", "4\n", "7\n", "1\n"], "outputs": ["2\n", "1\n0\n", "1\n0\n", "1\n4\n", "1\n0\n", "2\n", "1\n0\n", "1\n0\n"]}
coding
418
Solve the programming task below in a Python markdown code block. Chef recently realized that he needs a haircut, and went to his favorite hair salon. At the salon, he found N customers waiting for their haircuts. From his past experience, Chef knows that the salon takes M minutes per customer. Only one person can get ...
{"inputs": ["2\n2 15\n0 15\n"], "outputs": ["30\n0\n"]}
coding
349
Solve the programming task below in a Python markdown code block. Two little greedy bears have found two pieces of cheese in the forest of weight a and b grams, correspondingly. The bears are so greedy that they are ready to fight for the larger piece. That's where the fox comes in and starts the dialog: "Little bears,...
{"inputs": ["6 6\n", "1 1\n", "1 1\n", "1 2\n", "9 6\n", "6 6\n", "14 8\n", "1 22\n"], "outputs": ["0\n", "0\n", "0\n", "1\n", "2\n", "0\n", "-1\n", "-1\n"]}
coding
371
Solve the programming task below in a Python markdown code block. Alice and Bob play a game. They have a binary string $s$ (a string such that each character in it is either $0$ or $1$). Alice moves first, then Bob, then Alice again, and so on. During their move, the player can choose any number (not less than one) of...
{"inputs": ["5\n01111001\n0000\n111111\n101010101\n011011110111\n", "5\n01111101\n0000\n111111\n101010101\n011011110111\n", "5\n01111101\n0000\n111111\n101010101\n011001110111\n", "5\n01111101\n0000\n111111\n101010101\n011001111111\n", "5\n11111101\n0000\n111111\n101010101\n011001111111\n", "5\n11111101\n0000\n111111\n...
coding
512
Solve the programming task below in a Python markdown code block. Levko loves tables that consist of n rows and n columns very much. He especially loves beautiful tables. A table is beautiful to Levko if the sum of elements in each row and column of the table equals k. Unfortunately, he doesn't know any such table. Yo...
{"inputs": ["2 4\n", "4 7\n", "1 8\n", "9 3\n", "2 7\n", "4 3\n", "3 2\n", "3 2\n"], "outputs": ["4 0 \n0 4 \n", "7 0 0 0 \n0 7 0 0 \n0 0 7 0 \n0 0 0 7 \n", "8 \n", "3 0 0 0 0 0 0 0 0 \n0 3 0 0 0 0 0 0 0 \n0 0 3 0 0 0 0 0 0 \n0 0 0 3 0 0 0 0 0 \n0 0 0 0 3 0 0 0 0 \n0 0 0 0 0 3 0 0 0 \n0 0 0 0 0 0 3 0 0 \n0 0 0 0 0 0 0 ...
coding
333
Solve the programming task below in a Python markdown code block. In this Kata, you will be given a mathematical string and your task will be to remove all braces as follows: ```Haskell solve("x-(y+z)") = "x-y-z" solve("x-(y-z)") = "x-y+z" solve("u-(v-w-(x+y))-z") = "u-v+w+x+y-z" solve("x-(-y-z)") = "x+y+z" ``` There...
{"functional": "_inputs = [['a-(b)'], ['a-(-b)'], ['a+(b)'], ['a+(-b)'], ['(((((((((-((-(((n))))))))))))))'], ['(((a-((((-(-(f)))))))))'], ['((((-(-(-(-(m-g))))))))'], ['(((((((m-(-(((((t)))))))))))))'], ['-x'], ['-(-(x))'], ['-((-x))'], ['-(-(-x))'], ['-(-(x-y))'], ['-(x-y)'], ['x-(y+z)'], ['x-(y-z)'], ['x-(-y-z)'], [...
coding
153
Solve the programming task below in a Python markdown code block. Old timers of Summer Informatics School can remember previous camps in which each student was given a drink of his choice on the vechorka (late-evening meal). Or may be the story was more complicated? There are $n$ students living in a building, and for...
{"inputs": ["1 1\n1\n", "1 1\n1\n", "1 2\n1\n", "1 1000\n19\n", "1 1000\n548\n", "1 1000\n548\n", "1 1000\n892\n", "1 1000\n406\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n"]}
coding
717
Solve the programming task below in a Python markdown code block. Chef likes to play with array elements. His teacher has given him an array problem. But now he is busy as Christmas is coming. So, he needs your help. Can you help him to solve this problem. You are given an array $(A1,A2,A3……AN)$ of length $N$. You have...
{"inputs": ["2\n5\n2 4 5 7 9\n4\n5 4 2 3"], "outputs": ["6 11 14 4 2\n4 7 6 5"]}
coding
508
Please solve the programming task below using a self-contained code snippet in a markdown code block. A wiggle sequence is a sequence where the differences between successive numbers strictly alternate between positive and negative. The first difference (if one exists) may be either positive or negative. A sequence wi...
{"functional": "def check(candidate):\n assert candidate(nums = [1,7,4,9,2,5]) == 6\n assert candidate(nums = [1,17,5,10,13,15,10,5,16,8]) == 7\n assert candidate(nums = [1,2,3,4,5,6,7,8,9]) == 2\n\n\ncheck(Solution().wiggleMaxLength)"}
coding
265
Solve the programming task below in a Python markdown code block. The queen can be moved any number of unoccupied squares in a straight line vertically, horizontally, or diagonally, thus combining the moves of the rook and bishop. The queen captures by occupying the square on which an enemy piece sits. (wikipedia: http...
{"functional": "_inputs = [[7]]\n_outputs = [[[]]]\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 return all(_deep_eq(...
coding
685
Solve the programming task below in a Python markdown code block. ## Story John runs a shop, bought some goods, and then sells them. He used a special accounting method, like this: ``` [[60,20],[60,-20]] ``` Each sub array records the commodity price and profit/loss to sell (percentage). Positive mean profit and negat...
{"functional": "_inputs = [[[[60, 20], [60, -20]]], [[[60, 100], [60, -50]]], [[[60, 0], [60, 0]]]]\n_outputs = [[-5], [-30], [0]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, t...
coding
203
Solve the programming task below in a Python markdown code block. Vasya has got an array consisting of $n$ integers, and two integers $k$ and $len$ in addition. All numbers in the array are either between $1$ and $k$ (inclusive), or equal to $-1$. The array is good if there is no segment of $len$ consecutive equal numb...
{"inputs": ["1 100 1\n-1\n", "1 100 1\n-1\n", "1 100 2\n-1\n", "1 010 4\n-1\n", "1 100 4\n-1\n", "1 000 2\n-1\n", "1 000 4\n-1\n", "1 010 2\n-1\n"], "outputs": ["0\n", "0\n", "100", "10", "100", "0", "0", "10"]}
coding
474
Solve the programming task below in a Python markdown code block. In Berland recently a new collection of toys went on sale. This collection consists of 10^9 types of toys, numbered with integers from 1 to 10^9. A toy from the new collection of the i-th type costs i bourles. Tania has managed to collect n different ty...
{"inputs": ["2 1\n1 2\n", "2 1\n1 2\n", "2 1\n1 3\n", "2 1\n2 3\n", "2 0\n2 3\n", "2 0\n2 6\n", "2 0\n2 12\n", "3 7\n1 3 4\n"], "outputs": ["0\n\n", "0\n\n", "0\n\n", "1\n1\n", "0\n\n", "0\n\n", "0\n\n", "2\n2 5 \n"]}
coding
570
Please solve the programming task below using a self-contained code snippet in a markdown code block. There is a row of n houses, where each house can be painted one of three colors: red, blue, or green. The cost of painting each house with a certain color is different. You have to paint all the houses such that no tw...
{"functional": "def check(candidate):\n assert candidate(costs = [[17,2,17],[16,16,5],[14,3,19]]) == 10\n assert candidate(costs = [[7,6,2]]) == 2\n\n\ncheck(Solution().minCost)"}
coding
181
Solve the programming task below in a Python markdown code block. Madison is a little girl who is fond of toys. Her friend Mason works in a toy manufacturing factory . Mason has a 2D board $\mbox{A}$ of size $H\times W$ with $\mbox{H}$ rows and $\mbox{W}$ columns. The board is divided into cells of size $1\times1$ with...
{"inputs": ["1 1\n1\n", "3 3\n1 3 4\n2 2 3\n1 2 4\n"], "outputs": ["6\n", "60\n"]}
coding
506
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 piles, where piles[i] represents the number of stones in the ith pile, and an integer k. You should apply the following operation exactly k times: Choose any piles[i] and remov...
{"functional": "def check(candidate):\n assert candidate(piles = [5,4,9], k = 2) == 12\n assert candidate(piles = [4,3,6,7], k = 3) == 12\n\n\ncheck(Solution().minStoneSum)"}
coding
167
Solve the programming task below in a Python markdown code block. The snakes want to build a temple for Lord Cobra. There are multiple strips of land that they are looking at, but not all of them are suitable. They need the strip of land to resemble a coiled Cobra. You need to find out which strips do so. Formally, eve...
{"inputs": ["7\n5\n1 2 3 2 1\n7\n2 3 4 5 4 3 2\n5\n1 2 3 4 3\n5\n1 3 5 3 1\n7\n1 2 3 4 3 2 1\n4\n1 2 3 2\n4\n1 2 2 1"], "outputs": ["yes\nno\nno\nno\nyes\nno\nno"]}
coding
710
Solve the programming task below in a Python markdown code block. Alice and Bob are playing a game. There are $n$ cells in a row. Initially each cell is either red or blue. Alice goes first. On each turn, Alice chooses two neighbouring cells which contain at least one red cell, and paints that two cells white. Then, B...
{"inputs": ["8\n3\nBRB\n5\nRRBBB\n6\nRBRBRB\n8\nBBRRBRRB\n6\nBRRBRB\n12\nRBRBRBRBRRBB\n12\nRBRBRBRBBBRR\n4\nRBBR\n"], "outputs": ["Bob\nBob\nAlice\nAlice\nAlice\nAlice\nBob\nBob\n"]}
coding
676
Solve the programming task below in a Python markdown code block. Your task is to get Zodiac Sign using input ```day``` and ```month```. For exapmle: ```python get_zodiac_sign(1,5) => 'Taurus' get_zodiac_sign(10,10) => 'Libra' ``` Correct answers are (preloaded): ```python SIGNS = ['Capricorn', 'Aquarius', 'Pisces...
{"functional": "_inputs = [[10, 10], [1, 5], [6, 9], [25, 11]]\n_outputs = [['Libra'], ['Taurus'], ['Virgo'], ['Sagittarius']]\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
351
Solve the programming task below in a Python markdown code block. In this Kata you are to implement a function that parses a string which is composed from tokens of the form 'n1-n2,n3,n4-n5:n6' where 'nX' is a positive integer. Each token represent a different range: 'n1-n2' represents the range n1 to n2 (inclusive in...
{"functional": "_inputs = [['1-10,14, 20-25:2'], ['5-10'], ['2'], ['1-10,3'], ['1-10:5']]\n_outputs = [[[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 14, 20, 22, 24]], [[5, 6, 7, 8, 9, 10]], [[2]], [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 3]], [[1, 6]]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b...
coding
302
Solve the programming task below in a Python markdown code block. In the official contest this problem has a different statement, for which jury's solution was working incorrectly, and for this reason it was excluded from the contest. This mistake have been fixed and the current given problem statement and model soluti...
{"inputs": ["2\n0 1\n", "2\n8 37\n", "2\n6 37\n", "2\n6 43\n", "2\n1 43\n", "2\n0 32\n", "2\n1 32\n", "2\n73 37\n"], "outputs": ["1", "29\n", "31\n", "37\n", "42\n", "32\n", "31\n", "36"]}
coding
679
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are playing the Bulls and Cows game with your friend. You write down a secret number and ask your friend to guess what the number is. When your friend makes a guess, you provide a hint with the following info: Th...
{"functional": "def check(candidate):\n assert candidate(secret = \"1807\", guess = \"7810\") == \"1A3B\"\n assert candidate(secret = \"1123\", guess = \"0111\") == \"1A1B\"\n\n\ncheck(Solution().getHint)"}
coding
223
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an n x n grid where we place some 1 x 1 x 1 cubes that are axis-aligned with the x, y, and z axes. Each value v = grid[i][j] represents a tower of v cubes placed on top of the cell (i, j). We view the pr...
{"functional": "def check(candidate):\n assert candidate([[1,2],[3,4]]) == 17\n assert candidate(grid = [[2]]) == 5\n assert candidate([[1,0],[0,2]]) == 8\n\n\ncheck(Solution().projectionArea)"}
coding
181
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a 0-indexed string s. You are also given a 0-indexed string queryCharacters of length k and a 0-indexed array of integer indices queryIndices of length k, both of which are used to describe k queries. Th...
{"functional": "def check(candidate):\n assert candidate(s = \"babacc\", queryCharacters = \"bcb\", queryIndices = [1,3,3]) == [3,3,4]\n assert candidate(s = \"abyzz\", queryCharacters = \"aa\", queryIndices = [2,1]) == [2,3]\n\n\ncheck(Solution().longestRepeating)"}
coding
166
Solve the programming task below in a Python markdown code block. Snuke has a grid consisting of three squares numbered 1, 2 and 3. In each square, either 0 or 1 is written. The number written in Square i is s_i. Snuke will place a marble on each square that says 1. Find the number of squares on which Snuke will place ...
{"inputs": ["101\n", "000\n"], "outputs": ["2\n", "0\n"]}
coding
170
Please solve the programming task below using a self-contained code snippet in a markdown code block. In a gold mine grid of size m x n, each cell in this mine has an integer representing the amount of gold in that cell, 0 if it is empty. Return the maximum amount of gold you can collect under the conditions: Every t...
{"functional": "def check(candidate):\n assert candidate(grid = [[0,6,0],[5,8,7],[0,9,0]]) == 24\n assert candidate(grid = [[1,0,7],[2,0,6],[3,4,5],[0,3,0],[9,0,20]]) == 28\n\n\ncheck(Solution().getMaximumGold)"}
coding
174
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. Chef is playing a game with his friend Misha. They have a pile containg N coins. Players take alternate turns, removing some coins from the pile. On each turn, a player can r...
{"inputs": ["2\n1\n8", "2\n0\n8", "2\n0\n6", "2\n0\n1", "2\n0\n0", "2\n1\n0", "2\n1\n1", "2\n0\n2"], "outputs": ["Chef\nChef", "Misha\nChef\n", "Misha\nMisha\n", "Misha\nChef\n", "Misha\nMisha\n", "Chef\nMisha\n", "Chef\nChef\n", "Misha\nChef\n"]}
coding
417
Solve the programming task below in a Python markdown code block. Chef Watson uses a social network called ChefBook, which has a new feed consisting of posts by his friends. Each post can be characterized by f - the identifier of the friend who created the post, p - the popularity of the post(which is pre-calculated by...
{"inputs": ["2 4\n1 2\n1 1 WhoDoesntLoveChefBook\n2 2 WinterIsComing\n3 10 TheseViolentDelightsHaveViolentEnds\n4 3 ComeAtTheKingBestNotMiss"], "outputs": ["WinterIsComing\nWhoDoesntLoveChefBook\nTheseViolentDelightsHaveViolentEnds\nComeAtTheKingBestNotMiss"]}
coding
525
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a positive integer n which is the number of nodes of a 0-indexed undirected weighted connected graph and a 0-indexed 2D array edges where edges[i] = [ui, vi, wi] indicates that there is an edge between n...
{"functional": "def check(candidate):\n assert candidate(n = 4, edges = [[0,1,4],[0,2,2],[2,3,6]], s = 1, d = 3, k = 2) == 2\n assert candidate(n = 7, edges = [[3,1,9],[3,2,4],[4,0,9],[0,5,6],[3,6,2],[6,0,4],[1,2,4]], s = 4, d = 1, k = 2) == 6\n assert candidate(n = 5, edges = [[0,4,2],[0,1,3],[0,2,1],[2,1,4],...
coding
212
Solve the programming task below in a Python markdown code block. Write a program which judges wheather given length of three side form a right triangle. Print "YES" if the given sides (integers) form a right triangle, "NO" if not so. Constraints * 1 ≀ length of the side ≀ 1,000 * N ≀ 1,000 Input Input consists of ...
{"inputs": ["3\n4 3 5\n0 3 6\n8 8 8", "3\n4 5 5\n0 8 6\n3 8 0", "3\n4 5 5\n0 8 6\n4 8 0", "3\n4 5 5\n1 8 6\n4 8 0", "3\n4 5 5\n2 8 6\n4 8 0", "3\n4 5 5\n2 8 2\n4 8 0", "3\n4 3 5\n4 3 6\n8 8 8", "3\n4 5 5\n-2 3 6\n8 8 8"], "outputs": ["YES\nNO\nNO\n", "NO\nNO\nNO\n", "NO\nNO\nNO\n", "NO\nNO\nNO\n", "NO\nNO\nNO\n", "NO\n...
coding
179
Solve the programming task below in a Python markdown code block. You are given a set $S$ and $Q$ queries. Initially, $S$ is empty. In each query: - You are given a positive integer $X$. - You should insert $X$ into $S$. - For each $y \in S$ before this query such that $y \neq X$, you should also insert $y \oplus X$ in...
{"inputs": ["1\n3\n4\n2\n7"], "outputs": ["0 1\n1 2\n3 4"]}
coding
552
Solve the programming task below in a Python markdown code block. You are given a sequence D_1, D_2, ..., D_N of length N. The values of D_i are all distinct. Does a tree with N vertices that satisfies the following conditions exist? - The vertices are numbered 1,2,..., N. - The edges are numbered 1,2,..., N-1, and E...
{"inputs": ["2\n0\n2", "2\n0\n5", "2\n0\n3", "2\n0\n4", "2\n1\n4", "2\n1\n2", "2\n1\n2\n", "2\n-1\n2"], "outputs": ["-1\n", "-1\n", "-1\n", "-1\n", "-1\n", "-1", "-1\n", "-1\n"]}
coding
347
Solve the programming task below in a Python markdown code block. Fizza is a cute girl and she wants to be more beautiful. So she approached a magician to increase her beauty magically. But the magician's glasses accidently got locked inside the locker and he forgot the password. Without glasses he can't help her. The...
{"inputs": ["3\n8\n6 3 6 4 5 4 3 6\n9\n5 5 4 5 2 1 3 4 2\n6\n1 2 3 4 5 6"], "outputs": ["1\n2\n0"]}
coding
526
Solve the programming task below in a Python markdown code block. Heidi's friend Jenny is asking Heidi to deliver an important letter to one of their common friends. Since Jenny is Irish, Heidi thinks that this might be a prank. More precisely, she suspects that the message she is asked to deliver states: "Send the foo...
{"inputs": ["4\n0 1 4\n0 2 2\n2 3 3\n", "3\n1 0 5987\n2 0 8891\n", "3\n1 0 5987\n2 0 8891\n", "3\n1 0 5987\n2 1 8891\n", "4\n0 1 4\n0 2 2\n1 3 3\n", "4\n0 1 4\n0 2 4\n2 3 4\n", "4\n0 1 6\n0 2 4\n1 3 4\n", "3\n1 0 1844\n2 0 8891\n"], "outputs": ["5\n", "8891\n", "8891\n", "14878\n", "7\n", "8\n", "10\n", "8891\n"]}
coding
639
Please solve the programming task below using a self-contained code snippet in a markdown code block. There is a strange printer with the following two special properties: The printer can only print a sequence of the same character each time. At each turn, the printer can print new characters starting from and ending...
{"functional": "def check(candidate):\n assert candidate(s = \"aaabbb\") == 2\n assert candidate(s = \"aba\") == 2\n\n\ncheck(Solution().strangePrinter)"}
coding
116
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 books of length n where books[i] denotes the number of books on the ith shelf of a bookshelf. You are going to take books from a contiguous section of the bookshelf spanning fro...
{"functional": "def check(candidate):\n assert candidate(books = [8,5,2,7,9]) == 19\n assert candidate(books = [7,0,3,4,5]) == 12\n assert candidate(books = [8,2,3,7,3,4,0,1,4,3]) == 13\n\n\ncheck(Solution().maximumBooks)"}
coding
152
Solve the programming task below in a Python markdown code block. Challenge: Given a two-dimensional array, return a new array which carries over only those arrays from the original, which were not empty and whose items are all of the same type (i.e. homogenous). For simplicity, the arrays inside the array will only c...
{"functional": "_inputs = [[[[1, 5, 4], ['a', 3, 5], ['b'], [], ['1', 2, 3]]], [[[123, 234, 432], ['', 'abc'], [''], ['', 1], ['', '1'], []]], [[[1, 2, 3], ['1', '2', '3'], ['1', 2, 3]]]]\n_outputs = [[[[1, 5, 4], ['b']]], [[[123, 234, 432], ['', 'abc'], [''], ['', '1']]], [[[1, 2, 3], ['1', '2', '3']]]]\nimport math\n...
coding
212
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given four integers sx, sy, tx, and ty, return true if it is possible to convert the point (sx, sy) to the point (tx, ty) through some operations, or false otherwise. The allowed operation on some point (x, y) is to c...
{"functional": "def check(candidate):\n assert candidate(sx = 1, sy = 1, tx = 3, ty = 5) == True\n assert candidate(sx = 1, sy = 1, tx = 2, ty = 2) == False\n assert candidate(sx = 1, sy = 1, tx = 1, ty = 1) == True\n\n\ncheck(Solution().reachingPoints)"}
coding
134
Solve the programming task below in a Python markdown code block. In this simple exercise, you will build a program that takes a value, `integer `, and returns a list of its multiples up to another value, `limit `. If `limit` is a multiple of ```integer```, it should be included as well. There will only ever be positiv...
{"functional": "_inputs = [[5, 25], [1, 2], [5, 7], [4, 27], [11, 54]]\n_outputs = [[[5, 10, 15, 20, 25]], [[1, 2]], [[5]], [[4, 8, 12, 16, 20, 24]], [[11, 22, 33, 44]]]\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
181
Solve the programming task below in a Python markdown code block. Little Dima has two sequences of points with integer coordinates: sequence (a_1, 1), (a_2, 2), ..., (a_{n}, n) and sequence (b_1, 1), (b_2, 2), ..., (b_{n}, n). Now Dima wants to count the number of distinct sequences of points of length 2Β·n that can be...
{"inputs": ["1\n1\n2\n7\n", "1\n1\n2\n7\n", "2\n1 2\n1 2\n4\n", "2\n1 2\n2 2\n4\n", "2\n1 2\n2 2\n4\n", "2\n1 2\n1 2\n4\n", "2\n1 2\n2 3\n11\n", "2\n1 2\n2 6\n11\n"], "outputs": ["1\n", "1\n", "1\n", "3\n", "3\n", "1\n", "2\n", "2\n"]}
coding
541
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an integer array nums of size n, return the minimum number of moves required to make all array elements equal. In one move, you can increment or decrement an element of the array by 1. Test cases are designed so...
{"functional": "def check(candidate):\n assert candidate(nums = [1,2,3]) == 2\n assert candidate(nums = [1,10,2,9]) == 16\n\n\ncheck(Solution().minMoves2)"}
coding
108
Solve the programming task below in a Python markdown code block. Write a program which reads $n$ dices constructed in the same way as Dice I, and determines whether they are all different. For the determination, use the same way as Dice III. Constraints * $2 \leq n \leq 100$ * $0 \leq $ the integer assigned to a fac...
{"inputs": ["3\n1 2 3 4 5 6\n6 5 4 3 2 1\n5 4 0 2 1 6", "3\n1 2 3 4 5 6\n6 2 5 3 5 1\n6 5 4 3 2 1", "3\n1 2 3 4 5 6\n5 5 4 3 2 1\n5 4 0 2 1 6", "3\n1 2 3 4 5 6\n6 2 5 3 0 1\n6 5 4 3 2 1", "3\n1 2 3 3 5 6\n5 5 4 3 2 1\n5 4 0 2 1 6", "3\n1 4 3 4 5 6\n6 2 5 3 0 1\n6 5 4 3 2 1", "3\n1 2 3 3 5 6\n5 2 4 3 2 1\n5 4 0 2 1 6", ...
coding
246
Solve the programming task below in a Python markdown code block. Vasya the programmer lives in the middle of the Programming subway branch. He has two girlfriends: Dasha and Masha, who live at the different ends of the branch, each one is unaware of the other one's existence. When Vasya has some free time, he goes to...
{"inputs": ["1 2\n", "2 1\n", "4 6\n", "6 7\n", "4 9\n", "7 3\n", "2 7\n", "7 4\n"], "outputs": ["Equal\n", "Equal\n", "Equal\n", "Equal\n", "Dasha\n", "Masha\n", "Dasha\n", "Masha\n"]}
coding
615
Solve the programming task below in a Python markdown code block. ## Description You are a *Fruit Ninja*, your skill is cutting fruit. All the fruit will be cut in half by your knife. For example: ``` [ "apple", "pear", "banana" ] --> ["app", "le", "pe", "ar", "ban", "ana"] ``` As you see, all fruits are cu...
{"functional": "_inputs = [[['apple', 'pear', 'banana']], [['apple', 'pear', 'banana', 'bomb']], [[]]]\n_outputs = [[['app', 'le', 'pe', 'ar', 'ban', 'ana']], [['app', 'le', 'pe', 'ar', 'ban', 'ana', 'bomb']], [[]]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n ...
coding
449
Solve the programming task below in a Python markdown code block. You have a statistic of price changes for one product represented as an array of $n$ positive integers $p_0, p_1, \dots, p_{n - 1}$, where $p_0$ is the initial price of the product and $p_i$ is how the price was increased during the $i$-th month. Using ...
{"inputs": ["1\n3 3\n7 2 3\n", "1\n3 3\n7 2 6\n", "1\n3 3\n97 2 2\n", "1\n3 3\n97 2 2\n", "1\n3 3\n17 2 2\n", "1\n3 2\n25 2 2\n", "1\n3 1\n94 2 2\n", "1\n3 2\n25 2 4\n"], "outputs": ["91\n", "191\n", "0\n", "0\n", "50\n", "75\n", "106\n", "173\n"]}
coding
690
Solve the programming task below in a Python markdown code block. An Arithmetic Progression is defined as one in which there is a constant difference between the consecutive terms of a given series of numbers. You are provided with consecutive elements of an Arithmetic Progression. There is however one hitch: exactly o...
{"functional": "_inputs = [[[1, 2, 3, 4, 6, 7, 8, 9]]]\n_outputs = [[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 len(a) != len(b): return False\n ...
coding
221
Solve the programming task below in a Python markdown code block. We will say that two integer sequences of length N, x_1, x_2, ..., x_N and y_1, y_2, ..., y_N, are similar when |x_i - y_i| \leq 1 holds for all i (1 \leq i \leq N). In particular, any integer sequence is similar to itself. You are given an integer N a...
{"inputs": ["2\n2 4", "1\n000", "2\n3 6", "1\n011", "2\n2 6", "1\n010", "2\n3 4", "1\n111"], "outputs": ["5\n", "1\n", "7\n", "2\n", "5\n", "1\n", "7\n", "2\n"]}
coding
321
Solve the programming task below in a Python markdown code block. Find the number with the most digits. If two numbers in the argument array have the same number of digits, return the first one in the array. Also feel free to reuse/extend the following starter code: ```python def find_longest(arr): ```
{"functional": "_inputs = [[[1, 10, 100]], [[9000, 8, 800]], [[8, 900, 500]], [[3, 40000, 100]], [[1, 200, 100000]]]\n_outputs = [[100], [9000], [900], [40000], [100000]]\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
65
Solve the programming task below in a Python markdown code block. One day, Twilight Sparkle is interested in how to sort a sequence of integers a_1, a_2, ..., a_{n} in non-decreasing order. Being a young unicorn, the only operation she can perform is a unit shift. That is, she can move the last element of the sequence ...
{"inputs": ["2\n2 1\n", "2\n1 2\n", "2\n1 1\n", "2\n1 1\n", "2\n1 0\n", "2\n2 2\n", "2\n2 0\n", "2\n0 0\n"], "outputs": ["1\n", "0\n", "0\n", "0\n", "1\n", "0\n", "1\n", "0\n"]}
coding
263
Solve the programming task below in a Python markdown code block. Chef Palin, as his name suggests, is always very interested in palindromic strings. Recently, he made a pretty interesting discovery on palindromes and that made him feel really Lucky. He came across something known as Lucky Palindromes. He defines a str...
{"inputs": ["3\nlaubcdkey\nluckycodechef\naaaaaaaa", "3\nlaubcdkey\nlubkycodechef\naaaaaaaa", "3\nlaubcdkey\nyubklcodechef\naaaaaaaa", "3\nlatbcdkfy\nfeicedocljbux\naaaaaaba", "3\nytkdadfbl\ntobjlcedechwf\naabaaaba", "3\nytkdadfbl\ntobjlcfdechwf\naabaaaba", "3\nytkdadlbf\ntobjlcfdechwf\naabaaaca", "3\nytjdadlbf\nfwmcee...
coding
351
Solve the programming task below in a Python markdown code block. There is no single treatment that works for every phobia, but some people cure it by being gradually exposed to the phobic situation or object. In this kata we will try curing arachnophobia by drawing primitive spiders. Our spiders will have legs, body...
{"functional": "_inputs = [[1, 1, 'W', 'o'], [2, 2, 'w', 'O'], [3, 3, 'w', '0']]\n_outputs = [['^(oWo)^'], ['/\\\\((OOwOO))/\\\\'], ['/\u2572(((0000w0000)))\u2571\\\\']]\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
300
Solve the programming task below in a Python markdown code block. Have you heard about the myth that [if you fold a paper enough times, you can reach the moon with it](http://scienceblogs.com/startswithabang/2009/08/31/paper-folding-to-the-moon/)? Sure you have, but exactly how many? Maybe it's time to write a program ...
{"functional": "_inputs = [[384000000], [5e-05], [1e-07], [0], [-1]]\n_outputs = [[42], [0], [0], [0], [None]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if ...
coding
242
Solve the programming task below in a Python markdown code block. Chef is watching TV. The current volume of the TV is X. Pressing the volume up button of the TV remote increases the volume by 1 while pressing the volume down button decreases the volume by 1. Chef wants to change the volume from X to Y. Find the minimu...
{"inputs": ["2\n50 54\n12 10\n"], "outputs": ["4\n2\n"]}
coding
290
Solve the programming task below in a Python markdown code block. Read problems statements [Hindi] ,[Bengali] , [Mandarin chinese] , [Russian] and [Vietnamese] as well. Consider the following algorithm, which generates a (not necessarily uniformly) random permutation of numbers $1$ through $N$: P := [1, 2, ..., N] fo...
{"inputs": ["2"], "outputs": ["1 2\n2 1"]}
coding
400
Solve the programming task below in a Python markdown code block. This is yet another problem dealing with regular bracket sequences. We should remind you that a bracket sequence is called regular, if by inserting Β«+Β» and Β«1Β» into it we can get a correct mathematical expression. For example, sequences Β«(())()Β», Β«()Β» a...
{"inputs": [")((\n", "()(\n", "())\n", "(((\n", "(()\n", "))(\n", "()(())()\n", "(()())()\n"], "outputs": ["0 1\n", "2 1\n", "2 1\n", "0 1\n", "2 1\n", "0 1\n", "8 1\n", "8 1\n"]}
coding
237
Solve the programming task below in a Python markdown code block. n people came to a party. Then those, who had no friends among people at the party, left. Then those, who had exactly 1 friend among those who stayed, left as well. Then those, who had exactly 2, 3, ..., n - 1 friends among those who stayed by the moment...
{"inputs": ["1\n4\n", "1\n2\n", "1\n7\n", "1\n5\n", "1\n6\n", "1\n9\n", "1\n8\n", "1\n1\n"], "outputs": ["2\n", "0\n", "5\n", "3\n", "4\n", "7\n", "6\n", "0\n"]}
coding
185
Solve the programming task below in a Python markdown code block. Alice has a grid with $2$ rows and $n$ columns. She fully covers the grid using $n$ dominoes of size $1 \times 2$ β€” Alice may place them vertically or horizontally, and each cell should be covered by exactly one domino. Now, she decided to show one row ...
{"inputs": ["4\n1\nU\n2\nLR\n5\nLRDLR\n6\nUUUUUU\n"], "outputs": ["D\nLR\nLRULR\nDDDDDD\n"]}
coding
432
Solve the programming task below in a Python markdown code block. Find the number of k-divisible numbers on the segment [a, b]. In other words you need to find the number of such integer values x that a ≀ x ≀ b and x is divisible by k. -----Input----- The only line contains three space-separated integers k, a and b ...
{"inputs": ["1 1 1\n", "1 0 0\n", "1 0 1\n", "2 0 0\n", "2 0 1\n", "2 1 2\n", "2 2 3\n", "2 0 1\n"], "outputs": ["1\n", "1\n", "2\n", "1\n", "1\n", "1\n", "1\n", "1\n"]}
coding
139
Solve the programming task below in a Python markdown code block. Given a string of length n s = s1, s2,…, sn and m queries. Each query qk (1 ≀ k ≀ m) is one of four types, "L ++", "L-", "R ++", "R-", and l [for the kth query qk. k] and r [k] are defined below. * L ++: l [k] = l [k-1] + 1, r [k] = r [k-1] * L-: l [k]...
{"inputs": ["6 4\nabcde\nR++\nR++\nL++\nL--", "6 2\nabdde\nR++\nR++\nL++\nL--", "5 0\nabcde\nR++\nR++\nL++\nL--", "6 1\nabcde\nR++\nR++\nL++\nL--", "6 4\nabdde\nR++\nR++\nL++\nL--", "2 4\nabcde\nR++\nR++\nL++\nL--", "6 2\neddba\nR++\nR++\nL++\nL--", "6 3\neddba\nR++\nR++\nL++\nL--"], "outputs": ["3\n", "2\n", "0\n", "1...
coding
498
Solve the programming task below in a Python markdown code block. YouKn0wWho has an integer sequence $a_1, a_2, \ldots, a_n$. He will perform the following operation until the sequence becomes empty: select an index $i$ such that $1 \le i \le |a|$ and $a_i$ is not divisible by $(i + 1)$, and erase this element from the...
{"inputs": ["5\n3\n1 2 3\n1\n2\n2\n7 7\n10\n384836991 191890310 576823355 782177068 404011431 818008580 954291757 160449218 155374934 840594328\n8\n6 69 696 69696 696969 6969696 69696969 696969696\n"], "outputs": ["YES\nNO\nYES\nYES\nNO\n"]}
coding
704
Solve the programming task below in a Python markdown code block. In the mysterious country of Byteland, everything is quite different from what you'd normally expect. In most places, if you were approached by two mobsters in a dark alley, they would probably tell you to give them all the money that you have. If yo...
{"inputs": ["5\n3 3\n1\n1\n1\n5 11\n1\n2\n4\n8\n16\n5 23\n1\n2\n4\n8\n16\n5 13\n1\n5\n5\n10\n10\n20 132\n17\n6\n4\n998\n254\n137\n259\n153\n154\n3\n28\n19\n123\n542\n857\n23\n687\n35\n99\n999"], "outputs": ["Yes\nYes\nYes\nNo\nYes"]}
coding
619
Solve the programming task below in a Python markdown code block. You are working at a lower league football stadium and you've been tasked with automating the scoreboard. The referee will shout out the score, you have already set up the voice recognition module which turns the ref's voice into a string, but the spoke...
{"functional": "_inputs = [['The score is four nil'], ['new score: two three'], ['two two'], ['Arsenal just conceded another goal, two nil']]\n_outputs = [[[4, 0]], [[2, 3]], [[2, 2]], [[2, 0]]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclos...
coding
186
Solve the programming task below in a Python markdown code block. For a dynamic array $A = \\{a_0, a_1, ...\\}$ of integers, perform a sequence of the following operations: * push($d$, $x$): Add element $x$ at the begining of $A$, if $d = 0$. Add element $x$ at the end of $A$, if $d = 1$. * randomAccess($p$): Print el...
{"inputs": ["11\n0 0 1\n0 0 2\n0 1 3\n1 0\n1 1\n1 0\n2 0\n2 1\n0 0 4\n1 0\n1 1", "11\n0 0 1\n0 0 2\n0 1 3\n1 0\n1 1\n1 0\n2 0\n2 1\n0 0 4\n1 0\n2 1", "11\n0 0 1\n0 0 3\n0 1 3\n1 0\n1 1\n1 0\n2 0\n2 1\n0 0 4\n1 0\n2 1", "11\n0 0 1\n0 0 3\n0 1 3\n1 0\n1 1\n1 0\n2 0\n2 1\n0 0 4\n2 0\n2 1", "11\n0 0 1\n0 0 2\n0 1 3\n1 0\n1...
coding
416
Solve the programming task below in a Python markdown code block. ## Description Given an array X of positive integers, its elements are to be transformed by running the following operation on them as many times as required: ```if X[i] > X[j] then X[i] = X[i] - X[j]``` When no more transformations are possible, retu...
{"functional": "_inputs = [[[6, 9, 21]], [[9]], [[30, 12]], [[11, 22]], [[1, 21, 55]], [[4, 16, 24]], [[3, 13, 23, 7, 83]], [[60, 12, 96, 48, 60, 24, 72, 36, 72, 72, 48]], [[71, 71, 71, 71, 71, 71, 71, 71, 71, 71, 71, 71, 71]]]\n_outputs = [[9], [9], [12], [22], [3], [12], [5], [132], [923]]\nimport math\ndef _deep_eq(...
coding
403
Solve the programming task below in a Python markdown code block. A string with length $L$ is called rich if $L \ge 3$ and there is a character which occurs in this string strictly more than $L/2$ times. You are given a string $S$ and you should answer $Q$ queries on this string. In each query, you are given a substrin...
{"inputs": ["1\n10 2\nhelloworld\n1 3\n1 10"], "outputs": ["NO\nYES"]}
coding
338
Solve the programming task below in a Python markdown code block. You are given a grid with 2 rows and 3 columns of squares. The color of the square at the i-th row and j-th column is represented by the character C_{ij}. Write a program that prints YES if this grid remains the same when rotated 180 degrees, and prints ...
{"inputs": ["tbb\nbet", "spp\npps", "eye\nele", "pos\ntop", "btb\nbet", "eey\nele", "pos\npot", "btb\nteb"], "outputs": ["NO\n", "YES\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n"]}
coding
209
Solve the programming task below in a Python markdown code block. # A wolf in sheep's clothing Wolves have been reintroduced to Great Britain. You are a sheep farmer, and are now plagued by wolves which pretend to be sheep. Fortunately, you are good at spotting them. Warn the sheep in front of the wolf that it is ab...
{"functional": "_inputs = [[['sheep', 'sheep', 'sheep', 'sheep', 'sheep', 'wolf', 'sheep', 'sheep']], [['sheep', 'wolf', 'sheep', 'sheep', 'sheep', 'sheep', 'sheep']], [['wolf', 'sheep', 'sheep', 'sheep', 'sheep', 'sheep', 'sheep']], [['sheep', 'wolf', 'sheep']], [['sheep', 'sheep', 'wolf']]]\n_outputs = [['Oi! Sheep n...
coding
328
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin Chinese and Russian as well. There are N cards placed in a row, where every card has two numbers written on it, one on the top and one on the bottom. The numbers are between 1 and N (both inclusive). Every number i...
{"inputs": ["2\n3\n1 3 2\n2 1 3\n8\n3 8 4 2 6 1 5 7\n5 2 4 3 8 7 6 1"], "outputs": ["2\n4"]}
coding
732
Solve the programming task below in a Python markdown code block. You are given three integers $x, y$ and $n$. Your task is to find the maximum integer $k$ such that $0 \le k \le n$ that $k \bmod x = y$, where $\bmod$ is modulo operation. Many programming languages use percent operator % to implement it. In other word...
{"inputs": ["1\n13 2 61\n", "1\n13 0 61\n", "1\n13 0 39\n", "1\n31 2 104\n", "1\n33 6 100\n", "1\n31 2 104\n", "1\n33 6 100\n", "1\n23 2 104\n"], "outputs": ["54\n", "52\n", "39\n", "95\n", "72\n", "95\n", "72\n", "94\n"]}
coding
531
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a positive integer num consisting only of digits 6 and 9. Return the maximum number you can get by changing at most one digit (6 becomes 9, and 9 becomes 6). Β  Please complete the following python code p...
{"functional": "def check(candidate):\n assert candidate(num = 9669) == 9969\n assert candidate(num = 9996) == 9999\n assert candidate(num = 9999) == 9999\n\n\ncheck(Solution().maximum69Number)"}
coding
93
Solve the programming task below in a Python markdown code block. Johnny has a younger sister Anne, who is very clever and smart. As she came home from the kindergarten, she told his brother about the task that her kindergartener asked her to solve. The task was just to construct a triangle out of four sticks of differ...
{"inputs": ["4 4 4 5\n", "3 1 2 1\n", "1 5 1 3\n", "3 5 1 1\n", "1 5 5 5\n", "8 4 3 1\n", "3 3 3 1\n", "1 1 2 1\n"], "outputs": ["TRIANGLE\n", "SEGMENT\n", "IMPOSSIBLE\n", "IMPOSSIBLE\n", "TRIANGLE\n", "SEGMENT\n", "TRIANGLE\n", "TRIANGLE\n"]}
coding
359
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an m x n binary grid grid where each 1 marks the home of one friend, return the minimal total travel distance. The total travel distance is the sum of the distances between the houses of the friends and the meet...
{"functional": "def check(candidate):\n assert candidate(grid = [[1,0,0,0,1],[0,0,0,0,0],[0,0,1,0,0]]) == 6\n assert candidate(grid = [[1,1]]) == 1\n\n\ncheck(Solution().minTotalDistance)"}
coding
133
Solve the programming task below in a Python markdown code block. Chef has an array A having N elements. Chef wants to make all the elements of the array equal by repeating the following move. Choose any integer K between 1 and N (inclusive). Then choose K distinct indices i_{1} , i_{2}, \dots, i_{K}, and increase the...
{"inputs": ["2\n3\n1 3 1\n3\n2 2 2"], "outputs": ["2\n0"]}
coding
494
Solve the programming task below in a Python markdown code block. Given is a sequence of N digits a_1a_2\ldots a_N, where each element is 1, 2, or 3. Let x_{i,j} defined as follows: * x_{1,j} := a_j \quad (1 \leq j \leq N) * x_{i,j} := | x_{i-1,j} - x_{i-1,j+1} | \quad (2 \leq i \leq N and 1 \leq j \leq N+1-i) Find...
{"inputs": ["4\n21", "4\n32", "4\n13", "4\n21", "4\n44", "4\n12", "4\n11", "4\n22"], "outputs": ["1\n", "1\n", "2\n", "1\n", "0\n", "1\n", "0\n", "0\n"]}
coding
249
Solve the programming task below in a Python markdown code block. There is a set A = \\{ a_1, a_2, \ldots, a_N \\} consisting of N positive integers. Taro and Jiro will play the following game against each other. Initially, we have a pile consisting of K stones. The two players perform the following operation alternat...
{"inputs": ["2 3\n2 3", "2 7\n1 3", "2 4\n2 5", "2 1\n1 3", "2 4\n3 5", "2 2\n1 3", "2 2\n2 3", "2 5\n2 5"], "outputs": ["First\n", "First\n", "Second\n", "First\n", "First\n", "Second\n", "First\n", "First\n"]}
coding
332
Solve the programming task below in a Python markdown code block. Generate and return **all** possible increasing arithmetic progressions of six primes `[a, b, c, d, e, f]` between the given limits. Note: the upper and lower limits are inclusive. An arithmetic progression is a sequence where the difference between con...
{"functional": "_inputs = [[0, 200], [90, 600], [770, 1000], [30, 305], [1000, 4000]]\n_outputs = [[[[7, 37, 67, 97, 127, 157]]], [[[107, 137, 167, 197, 227, 257], [359, 389, 419, 449, 479, 509]]], [[]], [[[107, 137, 167, 197, 227, 257]]], [[[1013, 1193, 1373, 1553, 1733, 1913], [1039, 1249, 1459, 1669, 1879, 2089], [1...
coding
243
Solve the programming task below in a Python markdown code block. Section numbers are strings of dot-separated integers. The highest level sections (chapters) are numbered 1, 2, 3, etc. Second level sections are numbered 1.1, 1.2, 1.3, 2.1, 2.2, 2.3, etc. Next level sections are numbered 1.1.1, 1.1.2, 1.1.2, 1.2.1, 1.2...
{"functional": "_inputs = [['1', '2'], ['1.1', '1.2'], ['1.1', '1'], ['1.2.3.4', '1.2.3.4'], ['3', '3.0'], ['3', '3.0.0.0'], ['1.2.1', '1.2.0'], ['3.0.0', '3.1.1'], ['3.0.1', '3.1'], ['1.2.3', '1.02.003'], ['1.20', '1.5']]\n_outputs = [[-1], [-1], [1], [0], [0], [0], [1], [-1], [-1], [0], [1]]\nimport math\ndef _deep_e...
coding
446
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a string time in the form of hh:mm, where some of the digits in the string are hidden (represented by ?). The valid times are those inclusively between 00:00 and 23:59. Return the latest valid time you ...
{"functional": "def check(candidate):\n assert candidate(time = \"2?:?0\") == \"23:50\"\n assert candidate(time = \"0?:3?\") == \"09:39\"\n assert candidate(time = \"1?:22\") == \"19:22\"\n\n\ncheck(Solution().maximumTime)"}
coding
114
Solve the programming task below in a Python markdown code block. The time is 2020. There is data that saves the qualifying results of PC Koshien 2020. This data stores the reference number and the number of correct answers assigned to each team. Here, the ranking is determined by the number of correct answers, and the...
{"inputs": ["1,20\n2,20\n3,30\n4,10\n5,10\n6,20\n0,0\n1\n2\n4\n1", "1,20\n2,20\n3,30\n4,10\n5,10\n0,26\n0,0\n1\n2\n4\n1", "1,20\n2,20\n3,30\n4,10\n5,10\n0,26\n0,0\n0\n2\n4\n1", "1,20\n2,20\n3,30\n4,10\n5,10\n0,26\n0,0\n1\n2\n4\n0", "1,20\n2,20\n3,30\n4,10\n5,10\n0,26\n0,0\n1\n3\n4\n0", "1,20\n2,20\n3,30\n4,10\n5,10\n0,...
coding
537
Solve the programming task below in a Python markdown code block. Call a number stepping if adjacent digits, as well as the first and last digits, differ by one. How many n-digit base 11 stepping numbers are there? Give your answer modulo 4294967143. For example, 8789A9 is a 6-digit base 11 stepping number. 9A0A and 2...
{"inputs": ["4\n2\n4\n6\n10"], "outputs": ["19\n54\n171\n1958"]}
coding
188
Solve the programming task below in a Python markdown code block. Chef is given 3 integers A, B, and C such that A < B < C. Chef needs to find the value of max(A, B, C) - min(A, B, C). Here max(A, B, C) denotes the maximum value among A, B, C while min(A, B, C) denotes the minimum value among A, B, C. ------ Input F...
{"inputs": ["4\n1 3 10\n5 6 7\n3 8 9\n2 5 6\n"], "outputs": ["9\n2\n6\n4\n"]}
coding
433
Please solve the programming task below using a self-contained code snippet in a markdown code block. There are n people and 40 types of hats labeled from 1 to 40. Given a 2D integer array hats, where hats[i] is a list of all hats preferred by the ith person. Return the number of ways that the n people wear different ...
{"functional": "def check(candidate):\n assert candidate(hats = [[3,4],[4,5],[5]]) == 1\n assert candidate(hats = [[3,5,1],[3,5]]) == 4\n assert candidate(hats = [[1,2,3,4],[1,2,3,4],[1,2,3,4],[1,2,3,4]]) == 24\n assert candidate(hats = [[1,2,3],[2,3,5,6],[1,3,7,9],[1,8,9],[2,5,7]]) == 111\n\n\ncheck(Soluti...
coding
130
Solve the programming task below in a Python markdown code block. Priyanka works for an international toy company that ships by container. Her task is to the determine the lowest cost way to combine her orders for shipping. She has a list of item weights. The shipping company has a requirement that all items loaded ...
{"inputs": ["8\n1 2 3 21 7 12 14 21\n"], "outputs": ["4\n"]}
coding
554
Solve the programming task below in a Python markdown code block. Some natural number was written on the board. Its sum of digits was not less than k. But you were distracted a bit, and someone changed this number to n, replacing some digits with others. It's known that the length of the number didn't change. You have...
{"inputs": ["2\n2\n", "1\n1\n", "9\n9\n", "5\n5\n", "5\n5\n", "1\n1\n", "9\n9\n", "2\n2\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]}
coding
229
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a positive integer n which is the number of nodes of a 0-indexed directed weighted graph and a 0-indexed 2D array edges where edges[i] = [ui, vi, wi] indicates that there is an edge from node ui to node ...
{"functional": "def check(candidate):\n assert candidate(n = 4, edges = [[0,1,1],[1,2,3],[2,3,2],[0,3,4]], s = 0, marked = [2,3]) == 4\n assert candidate(n = 5, edges = [[0,1,2],[0,2,4],[1,3,1],[2,3,3],[3,4,2]], s = 1, marked = [0,4]) == 3\n assert candidate(n = 4, edges = [[0,1,1],[1,2,3],[2,3,2]], s = 3, mar...
coding
186
Solve the programming task below in a Python markdown code block. # Personalized greeting Create a function that gives a personalized greeting. This function takes two parameters: `name` and `owner`. Use conditionals to return the proper message: case | return --- | --- name equals owner | 'Hello boss' otherwise ...
{"functional": "_inputs = [['Daniel', 'Daniel'], ['Greg', 'Daniel']]\n_outputs = [['Hello boss'], ['Hello guest']]\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
93
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are playing the following Nim Game with your friend: Initially, there is a heap of stones on the table. You and your friend will alternate taking turns, and you go first. On each turn, the person whose turn it is...
{"functional": "def check(candidate):\n assert candidate(n = 4) == False \n assert candidate(n = 1) == True\n assert candidate(n = 2) == True\n\n\ncheck(Solution().canWinNim)"}
coding
152
Solve the programming task below in a Python markdown code block. The chef is having one array of natural numbers. Cheffina challenges chef that find the sum of weights all the natural numbers present in the array, but the main problem is that all numbers have not original weights. After every 6 natural numbers weight ...
{"inputs": ["1\n6\n6 7 9 11 4 16"], "outputs": ["23"]}
coding
302