problem
stringlengths
14
4.09k
solution
stringlengths
1
802k
task_type
stringclasses
3 values
problem_tokens
int64
5
895
Please solve the programming task below using a self-contained code snippet in a markdown code block. The alternating sum of a 0-indexed array is defined as the sum of the elements at even indices minus the sum of the elements at odd indices. For example, the alternating sum of [4,2,5,3] is (4 + 5) - (2 + 3) = 4. Gi...
{"functional": "def check(candidate):\n assert candidate(nums = [4,2,5,3]) == 7\n assert candidate(nums = [5,6,7,8]) == 8\n assert candidate(nums = [6,2,1,2,4,5]) == 10\n\n\ncheck(Solution().maxAlternatingSum)"}
coding
222
Solve the programming task below in a Python markdown code block. Read problem statements in [Mandarin Chinese] and [Bengali]. You are given N identical squares, each with side length A. All the squares have their sides parallel to the x-axis and y-axis. That is, the squares are not tilted. You have to take several (p...
{"inputs": ["5\n3 2\n5 3\n16 18\n11 8\n8 6\n"], "outputs": ["2\n6\n72\n24\n12\n"]}
coding
364
Solve the programming task below in a Python markdown code block. You are given N integers \{A_{1}, A_{2}, \ldots, A_{N}\}. Determine whether they can be reordered such that each pair of consecutive differences differ by a factor of 2. Formally, determine whether there exists a rearrangement of the given integers into...
{"inputs": ["4\n3\n5 2 4\n5\n2 1 16 8 4\n5\n97 98 100 96 88\n6\n16 19 18 21 24 22"], "outputs": ["Yes\nYes\nNo\nYes\n"]}
coding
729
Solve the programming task below in a Python markdown code block. Chef wants to cross a hallway of N doors. These N doors are represented as a string. Each door is initially either open or close, represented by 1 or 0 respectively. Chef is required to go through all the doors one by one in the order that they appear, s...
{"inputs": ["3\n111\n010\n10011"], "outputs": ["0\n3\n2"]}
coding
522
Solve the programming task below in a Python markdown code block. Read problem statements in [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. Chef has $N$ [6-sided standard dice]. Each die has dimensions $1 \times 1 \times 1$. Since Chef is bored during the quarantine, he decides to stack dice for f...
{"inputs": ["1\n1"], "outputs": ["20"]}
coding
509
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an integer array nums and an integer k, return the kth largest element in the array. Note that it is the kth largest element in the sorted order, not the kth distinct element. Can you solve it without sorting?  ...
{"functional": "def check(candidate):\n assert candidate(nums = [3,2,1,5,6,4], k = 2) == 5\n assert candidate(nums = [3,2,3,1,2,4,5,5,6], k = 4) == 4\n\n\ncheck(Solution().findKthLargest)"}
coding
103
Solve the programming task below in a Python markdown code block. Chef is playing a video game, and is now fighting the final boss. The boss has H health points. Each attack of Chef reduces the health of the boss by X. Chef also has a special attack that can be used at most once, and will decrease the health of the ...
{"inputs": ["4\n100 25 40\n100 29 45\n46 1 2\n78 15 78\n"], "outputs": ["4\n3\n45\n1\n"]}
coding
487
Solve the programming task below in a Python markdown code block. A plot of land can be described by $M x N$ dots such that horizontal and vertical distance between any two dots is 10m. Mr. Wolf would like to build a house in the land such that all four sides of the house are equal. Help Mr. Wolf to find the total numb...
{"inputs": ["4\n2 4\n3 4\n4 4\n1000 500"], "outputs": ["3\n10\n20\n624937395"]}
coding
298
Solve the programming task below in a Python markdown code block. In this Kata, you will implement the [Luhn Algorithm](http://en.wikipedia.org/wiki/Luhn_algorithm), which is used to help validate credit card numbers. Given a positive integer of up to 16 digits, return ```true``` if it is a valid credit card number, a...
{"functional": "_inputs = [[123], [1], [2121], [1230], [8675309], [4111111111111111], [26], [2626262626262626], [91], [92], [912030], [922030]]\n_outputs = [[False], [False], [True], [True], [False], [True], [True], [True], [True], [False], [True], [False]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance...
coding
534
Solve the programming task below in a Python markdown code block. # Task An `amazon` (also known as a queen+knight compound) is an imaginary chess piece that can move like a `queen` or a `knight` (or, equivalently, like a `rook`, `bishop`, or `knight`). The diagram below shows all squares which the amazon attacks from...
{"functional": "_inputs = [['a1', 'g5'], ['a3', 'e4'], ['f3', 'f2'], ['b7', 'a8'], ['f7', 'd3'], ['g2', 'c3'], ['f3', 'c1'], ['d4', 'h8'], ['h6', 'a7'], ['a6', 'g3'], ['e1', 'b4'], ['f4', 'c4'], ['c3', 'e8'], ['b5', 'e5'], ['c8', 'g8'], ['a6', 'b5'], ['b3', 'e2'], ['b7', 'c3'], ['b5', 'b3'], ['a4', 'a6'], ['h2', 'a5'],...
coding
702
Solve the programming task below in a Python markdown code block. There are N squares lining up in a row, numbered 1 through N from left to right. Initially, all squares are white. We also have N-1 painting machines, numbered 1 through N-1. When operated, Machine i paints Square i and i+1 black. Snuke will operate the...
{"inputs": ["3", "6", "9", "8", "7", "2", "4", "5"], "outputs": ["4\n", "516\n", "275040\n", "30096\n", "3696\n", "1", "16", "84"]}
coding
321
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given two strings word1 and word2. Merge the strings by adding letters in alternating order, starting with word1. If a string is longer than the other, append the additional letters onto the end of the merged ...
{"functional": "def check(candidate):\n assert candidate(word1 = \"abc\", word2 = \"pqr\") == \"apbqcr\"\n assert candidate(word1 = \"ab\", word2 = \"pqrs\") == \"apbqrs\"\n assert candidate(word1 = \"abcd\", word2 = \"pq\") == \"apbqcd\"\n\n\ncheck(Solution().mergeAlternately)"}
coding
106
Please solve the programming task below using a self-contained code snippet in a markdown code block. There is a tree (i.e., a connected, undirected graph that has no cycles) consisting of n nodes numbered from 0 to n - 1 and exactly n - 1 edges. Each node has a value associated with it, and the root of the tree is no...
{"functional": "def check(candidate):\n assert candidate(nums = [2,3,3,2], edges = [[0,1],[1,2],[1,3]]) == [-1,0,0,1]\n assert candidate(nums = [5,6,10,2,3,6,15], edges = [[0,1],[0,2],[1,3],[1,4],[2,5],[2,6]]) == [-1,0,-1,0,0,0,-1]\n\n\ncheck(Solution().getCoprimes)"}
coding
284
Solve the programming task below in a Python markdown code block. To make Yalalovichik even more satisfied and happy, Jafar decided to invent Yalalovichik strings. A string is called a Yalalovichik string if the set of all of its distinct non-empty substrings is equal to the set of all of its distinct non-empty subsequ...
{"inputs": ["1\n3\nxxx"], "outputs": ["3"]}
coding
456
Solve the programming task below in a Python markdown code block. Sean is trying to save a large file to a USB flash drive. He has n USB flash drives with capacities equal to a_1, a_2, ..., a_{n} megabytes. The file size is equal to m megabytes. Find the minimum number of USB flash drives needed to write Sean's file,...
{"inputs": ["1\n1\n1\n", "1\n1\n1\n", "2\n5\n5\n10\n", "2\n5\n5\n10\n", "3\n5\n2\n1\n3\n", "3\n6\n2\n3\n2\n", "3\n5\n2\n1\n5\n", "2\n5\n10\n10\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "2\n", "3\n", "1\n", "1\n"]}
coding
342
Solve the programming task below in a Python markdown code block. The Monty Hall problem is a probability puzzle base on the American TV show "Let's Make A Deal". In this show, you would be presented with 3 doors: One with a prize behind it, and two without (represented with goats). After choosing a door, the host wo...
{"functional": "_inputs = [[1, [1, 2, 2, 2, 3, 2, 1, 3, 1, 3]], [2, [2, 1, 2, 1, 2, 3, 1, 1, 2, 2, 3]], [3, [1, 1, 1, 2, 2, 3, 2, 2, 1, 3, 3, 2, 3, 1, 1, 2]]]\n_outputs = [[70], [55], [75]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, ...
coding
267
Solve the programming task below in a Python markdown code block. Chef likes to play with big numbers. Today, he has a big positive integer N. He can select any two digits from this number (the digits can be same but their positions should be different) and orders them in any one of the two possible ways. For each of t...
{"inputs": ["4\n65\n566\n11\n1623455078"], "outputs": ["A\nAB\nACDFGHIJKLNPQRSTUVW"]}
coding
467
Solve the programming task below in a Python markdown code block. Two tortoises named ***A*** and ***B*** must run a race. ***A*** starts with an average speed of ```720 feet per hour```. Young ***B*** knows she runs faster than ***A***, and furthermore has not finished her cabbage. When she starts, at last, she can s...
{"functional": "_inputs = [[720, 850, 70], [80, 91, 37], [80, 100, 40], [720, 850, 37], [720, 850, 370], [120, 850, 37], [820, 850, 550], [820, 81, 550]]\n_outputs = [[[0, 32, 18]], [[3, 21, 49]], [[2, 0, 0]], [[0, 17, 4]], [[2, 50, 46]], [[0, 3, 2]], [[18, 20, 0]], [None]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n...
coding
509
Solve the programming task below in a Python markdown code block. There is a long-established secondhand bookstore called JOI secondhand bookstore in your town, and you often use the JOI secondhand bookstore. Each book has a standard price, and you can buy it at that price if you go to the JOI secondhand bookstore. At...
{"inputs": ["7 2\n4 1\n0 1\n9 2\n10 3\n8 2\n4 8\n8 2", "7 2\n4 1\n9 1\n9 2\n3 5\n2 2\n4 3\n11 2", "7 2\n4 1\n0 1\n4 2\n10 3\n8 2\n4 8\n8 2", "7 4\n4 1\n13 1\n9 2\n3 5\n3 2\n4 3\n11 2", "7 5\n4 1\n13 2\n9 2\n10 3\n8 2\n4 8\n11 2", "7 1\n4 1\n13 2\n9 2\n10 3\n8 2\n4 8\n11 2", "7 4\n7 2\n0 1\n20 6\n15 2\n0 7\n5 5\n12 4", ...
coding
467
Solve the programming task below in a Python markdown code block. Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well. Chef has a machine which he uses to rotate sequences. If he puts a sequence $S_{1}, S_{2}, \ldots, S_{N}$ into the machine, it produces the sequence...
{"inputs": ["1\n4\n-5 4 1 2"], "outputs": ["7 7 4 5"]}
coding
703
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an integer array nums and a positive integer k. You can choose any subsequence of the array and sum all of its elements together. We define the K-Sum of the array as the kth largest subsequence sum that ...
{"functional": "def check(candidate):\n assert candidate(nums = [2,4,-2], k = 5) == 2\n assert candidate(nums = [1,-2,3,4,-10,12], k = 16) == 10\n\n\ncheck(Solution().kSum)"}
coding
161
Solve the programming task below in a Python markdown code block. Mutual Recursion allows us to take the fun of regular recursion (where a function calls itself until a terminating condition) and apply it to multiple functions calling each other! Let's use the Hofstadter Female and Male sequences to demonstrate this ...
{"functional": "_inputs = [[0], [5], [10], [15], [25]]\n_outputs = [[1], [3], [6], [9], [16]]\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):...
coding
262
Solve the programming task below in a Python markdown code block. The growth of Computer Science has forced the scientific community to award Nobel Prize in CS starting from this year. Chef knows that the Nobel community is going to award the prize to that person whose research is different from others (ie. no other r...
{"inputs": ["3\n4 4\n1 2 3 4\n5 4\n4 2 1 1 1\n4 4\n4 4 4 4"], "outputs": ["No\nYes\nYes"]}
coding
630
Solve the programming task below in a Python markdown code block. You are given two integers $n$ and $k$. Your task is to find if $n$ can be represented as a sum of $k$ distinct positive odd (not divisible by $2$) integers or not. You have to answer $t$ independent test cases. -----Input----- The first line of the ...
{"inputs": ["1\n707 44\n", "1\n2 65536\n", "1\n2 65536\n", "1\n2 15317\n", "1\n3 15317\n", "1\n1 15317\n", "1\n0 15317\n", "1\n0 26405\n"], "outputs": ["NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n"]}
coding
382
Solve the programming task below in a Python markdown code block. A prime number is an integer that is greater than 1 and can only be divided by itself or 1. For example, 2 is a prime number because it is divisible only by 2 and 1, but 12 is not a prime number because it is divisible by 2, 3, 4, 6 in addition to 12 and...
{"inputs": ["19\n9", "19\n52", "19\n74", "19\n38", "19\n13", "19\n24", "19\n30", "19\n58"], "outputs": ["17 23\n7 11\n", "17 23\n47 53\n", "17 23\n73 79\n", "17 23\n37 41\n", "17 23\n11 17\n", "17 23\n23 29\n", "17 23\n29 31\n", "17 23\n53 59\n"]}
coding
219
Solve the programming task below in a Python markdown code block. There are N towns in JOI, which are connected by M bidirectional roads. There are shopping malls in K towns, and the people go to one of those towns through the road to shop. Depending on the location of your home, you may have to travel long distances ...
{"inputs": ["4 3 1\n1 2 1\n2 3 1\n3 1 1\n1", "4 3 1\n1 2 1\n2 3 2\n1 1 1\n1", "4 3 1\n1 2 1\n2 3 1\n1 2 1\n2", "4 3 1\n1 2 1\n2 3 4\n1 1 1\n1", "8 3 1\n1 1 2\n2 3 4\n3 1 0\n1", "4 3 1\n1 2 2\n2 4 4\n1 1 1\n1", "4 3 1\n1 1 0\n1 3 0\n3 2 0\n1", "4 3 1\n1 2 1\n2 3 1\n1 1 1\n1"], "outputs": ["2\n", "3\n", "1\n", "5\n", "4\...
coding
490
Solve the programming task below in a Python markdown code block. Nowadays it is becoming increasingly difficult to park a car in cities successfully. Let's imagine a segment of a street as long as L meters along which a parking lot is located. Drivers should park their cars strictly parallel to the pavement on the rig...
{"inputs": ["8 1 0\n1\n1 8\n", "1 1 0\n1\n1 8\n", "1 2 0\n1\n1 8\n", "1 3 0\n1\n1 8\n", "10 1 1\n1\n1 9\n", "4 1 2\n1\n1 10\n", "10 1 1\n1\n1 8\n", "10 1 0\n1\n1 8\n"], "outputs": ["0\n", "-1\n", "-1\n", "-1\n", "0\n", "-1\n", "0\n", "0\n"]}
coding
730
Solve the programming task below in a Python markdown code block. Alice and Bob are playing a game of table tennis where irrespective of the point scored, every player makes 2 consecutive serves before the service changes. Alice makes the first serve of the match. Therefore the first 2 serves will be made by Alice, the...
{"inputs": ["4\n0 0\n0 2\n2 2\n4 7\n"], "outputs": ["Alice\nBob\nAlice\nBob\n"]}
coding
589
Solve the programming task below in a Python markdown code block. A number is simply made up of digits. The number 1256 is made up of the digits 1, 2, 5, and 6. For 1256 there are 24 distinct permutations of the digits: 1256, 1265, 1625, 1652, 1562, 1526, 2156, 2165, 2615, 2651, 2561, 2516, 5126, 5162, 5216, 5...
{"functional": "_inputs = [[2], [25], [737]]\n_outputs = [[2], [38], [629]]\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
522
Solve the programming task below in a Python markdown code block. Everyone knows that 2010 FIFA World Cup is being held in South Africa now. By the decision of BFA (Berland's Football Association) next World Cup will be held in Berland. BFA took the decision to change some World Cup regulations: * the final tourname...
{"inputs": ["2\na\nA\nA-a 2:1\n", "2\na\nA\nA-a 1:2\n", "2\na\nA\na-A 1:2\n", "2\na\nA\na-A 2:1\n", "4\nA\nB\nC\nD\nA-B 1:1\nA-C 2:2\nA-D 1:0\nB-C 0:1\nB-D 0:3\nC-D 0:3\n", "4\nA\nB\nC\nD\nA-B 1:1\nA-C 2:2\nA-D 1:0\nB-C 0:1\nB-D 0:3\nD-C 0:3\n", "4\nA\nB\nC\nD\nA-B 1:1\nA-D 2:2\nD-A 1:0\nB-C 1:0\nB-D 0:3\nC-D 0:3\n", "...
coding
583
Solve the programming task below in a Python markdown code block. You were dreaming that you are traveling to a planet named Planetforces on your personal spaceship. Unfortunately, its piloting system was corrupted and now you need to fix it in order to reach Planetforces. Space can be represented as the $XY$ plane. Y...
{"inputs": ["6\n1 5\nUURRURRRURRURRR\n1 0\nUDDDRLLL\n0 -5\nLDLDLDDDR\n0 4\nLLLLUU\n6 -1\nRDULRLLDR\n1 6\nRUDURUUUUR\n", "6\n10 1\nRRRRRRRRRRUUUUU\n1 1\nRDDDULLL\n0 -2\nLDLDLDDDR\n1 4\nULLLUL\n1 -1\nRDLURLLDR\n0 6\nRUUUURUDUR\n", "6\n1 5\nUURRURRRURRURRR\n1 0\nUDDDRLLL\n-6 -5\nLDLDLDDDR\n0 4\nLLLLUU\n6 -1\nRDULRLLDR\n1 ...
coding
744
Solve the programming task below in a Python markdown code block. The chef is trying to solve some series problems, Chef wants your help to code it. Chef has one number N. Help the chef to find N'th number in the series. 0, 1, 5, 14, 30, 55 ….. -----Input:----- - First-line will contain $T$, the number of test cases. ...
{"inputs": ["3\n1\n7\n8"], "outputs": ["0\n91\n140"]}
coding
188
Solve the programming task below in a Python markdown code block. Numbers $1, 2, 3, \dots n$ (each integer from $1$ to $n$ once) are written on a board. In one operation you can erase any two numbers $a$ and $b$ from the board and write one integer $\frac{a + b}{2}$ rounded up instead. You should perform the given ope...
{"inputs": ["1\n4\n", "1\n4\n", "1\n8\n", "1\n5\n", "1\n6\n", "1\n9\n", "1\n3\n", "1\n7\n"], "outputs": ["2\n4 3\n4 2\n3 1\n", "2\n4 3\n4 2\n3 1\n", "2\n8 7\n8 6\n7 5\n6 4\n5 3\n4 2\n3 1\n", "2\n5 4\n5 3\n4 2\n3 1\n", "2\n6 5\n6 4\n5 3\n4 2\n3 1\n", "2\n9 8\n9 7\n8 6\n7 5\n6 4\n5 3\n4 2\n3 1\n", "2\n3 2\n3 1\n", "2\n7 ...
coding
462
Solve the programming task below in a Python markdown code block. Chef likes prime numbers. However, there is one thing he loves even more. Of course, it's semi-primes! A semi-prime number is an integer which can be expressed as a product of two distinct primes. For example, $15 = 3 \cdot 5$ is a semi-prime number, but...
{"inputs": ["3\n30\n45\n62\n"], "outputs": ["YES\nYES\nNO"]}
coding
381
Solve the programming task below in a Python markdown code block. Alice has an array A of length N which is initially a *permutation*. She dislikes K numbers which are B_{1}, B_{2}, \ldots, B_{K} all of which are distinct. Therefore, she removes all the occurrences of these numbers from A. The order of the remaining el...
{"inputs": ["3\n4\n4 1 3 2\n2\n3 1\n9\n5 2 9 1 8 6 4 3 7\n3\n5 8 9\n5\n3 4 5 1 2\n2\n2 3\n"], "outputs": ["4 2\n2 1 6 4 3 7\n4 5 1\n"]}
coding
740
Solve the programming task below in a Python markdown code block. The chef is having one array of N natural numbers(numbers may be repeated). i.e. All natural numbers must be less than N. Chef wants to rearrange the array and try to place a natural number on its index of the array, i.e array[i]=i. If multiple natural n...
{"inputs": ["2\n2\n1 1\n4\n1 1 2 1"], "outputs": ["0 1\n0 1 2 0"]}
coding
393
Solve the programming task below in a Python markdown code block. Help a fruit packer sort out the bad apples. There are 7 varieties of apples, all packaged as pairs and stacked in a fruit box. Some of the apples are spoiled. The fruit packer will have to make sure the spoiled apples are either removed from the fruit...
{"functional": "_inputs = [[[]], [[[0, 0], [0, 0]]], [[[0, 0], [0, 0], [0, 1], [0, 0], [0, 0]]], [[[0, 0], [3, 7], [0, 5]]], [[[1, 3], [7, 6], [7, 2], [1, 3], [2, 3], [4, 5], [7, 6]]], [[[1, 2], [6, 1], [5, 2], [6, 3], [1, 4], [2, 5], [7, 6], [0, 1]]], [[[0, 0], [1, 0], [0, 2], [3, 0], [4, 0], [0, 5], [0, 6], [7, 0]]],...
coding
496
Solve the programming task below in a Python markdown code block. Takahashi is participating in a programming contest, AXC001. He has just submitted his code to Problem A. The problem has N test cases, all of which must be passed to get an AC verdict. Takahashi's submission has passed M cases out of the N test cases....
{"inputs": ["4 3", "0 0", "1 0", "3 4", "4 1", "2 0", "3 7", "4 0"], "outputs": ["No\n", "Yes\n", "No\n", "No\n", "No\n", "No\n", "No\n", "No\n"]}
coding
191
Solve the programming task below in a Python markdown code block. Iahub got bored, so he invented a game to be played on paper.  He writes n integers a1, a2, ..., an. Each of those integers can be either 0 or 1. He's allowed to do exactly one move: he chooses two indices i and j (1 ≤ i ≤ j ≤ n) and flips all values ak ...
{"functional": "_inputs = [[[1, 0, 0, 1, 0, 0]], [[1, 0, 0, 1]], [[1]], [[0]], [[1, 0, 0, 0, 1, 0, 0, 0]], [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]], [[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]], [[0, 1, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0, 1, 1, 1, 0, 0, 1, 1, 0, 1]]]\n_o...
coding
492
Solve the programming task below in a Python markdown code block. A car number in Berland consists of exactly n digits. A number is called beautiful if it has at least k equal digits. Vasya wants to change the digits in his car's number so that the number became beautiful. To replace one of n digits Vasya has to pay th...
{"inputs": ["2 2\n11\n", "2 2\n80\n", "2 2\n09\n", "2 2\n10\n", "2 2\n85\n", "2 2\n15\n", "2 2\n24\n", "2 1\n24\n"], "outputs": ["0\n11\n", "8\n00\n", "9\n00\n", "1\n00\n", "3\n55\n", "4\n11\n", "2\n22\n", "0\n24\n"]}
coding
510
Solve the programming task below in a Python markdown code block. Phoenix is playing with a new puzzle, which consists of $n$ identical puzzle pieces. Each puzzle piece is a right isosceles triangle as shown below. A puzzle piece The goal of the puzzle is to create a square using the $n$ pieces. He is allowed to rota...
{"inputs": ["1\n2\n", "1\n82\n", "1\n24\n", "1\n31\n", "1\n56\n", "1\n93\n", "1\n21\n", "1\n883\n"], "outputs": ["YES\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n"]}
coding
285
Solve the programming task below in a Python markdown code block. # Task John is new to spreadsheets. He is well aware of rows and columns, but he is not comfortable with spreadsheets numbering system. ``` Spreadsheet Row Column A1 R1C1 D5 R5C4 AA48 ...
{"functional": "_inputs = [['A1'], ['R1C1'], ['R5C4'], ['AA48'], ['BK12'], ['R12C63'], ['R85C26'], ['R31C78'], ['BZ31']]\n_outputs = [['R1C1'], ['A1'], ['D5'], ['R48C27'], ['R12C63'], ['BK12'], ['Z85'], ['BZ31'], ['R31C78']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float...
coding
295
Please solve the programming task below using a self-contained code snippet in a markdown code block. Write a method that finds the maximum of two numbers. You should not use if-else or any other comparison operator. Please complete the following python code precisely: ```python class Solution: def maximum(self, a...
{"functional": "def check(candidate):\n assert candidate(a = 1, b = 2) == 2\n\n\ncheck(Solution().maximum)"}
coding
73
Solve the programming task below in a Python markdown code block. You are given a straight line, $a\cdot x+b\cdot y=c$. Find the point closest to the origin that also satisfies the following properties: $\boldsymbol{x}$ and $y$ are integers. $\boldsymbol{x}$ is greater than zero. If more than one solution exist...
{"inputs": ["1\n2 3 1\n"], "outputs": ["2 -1\n"]}
coding
439
Solve the programming task below in a Python markdown code block. Mr. A wants to get to the destination on the Yamanote line. After getting on the train, Mr. A gets up for a minute and sleeps for b minutes repeatedly. It is c minutes after boarding to the destination, and you can get off if you are awake at this time,...
{"inputs": ["2 5 4", "2 5 5", "2 5 9", "1 0 8", "1 0 1", "1 2 3", "0 2 2", "2 5 0"], "outputs": ["64\n", "65\n", "9\n", "8\n", "1\n", "3\n", "2\n", "0\n"]}
coding
380
Solve the programming task below in a Python markdown code block. ------Read problems statements in Hindi, Mandarin chinese , Russian and Vietnamese as well. ------ Sheokand is good at mathematics. One day, to test his math skills, Kaali gave him an integer $N$. To impress Kaali, Sheokand has to convert $N$ into an i...
{"inputs": ["3\n10\n22\n4"], "outputs": ["0\n2\n1"]}
coding
508
Solve the programming task below in a Python markdown code block. An adult game master and N children are playing a game on an ice rink. The game consists of K rounds. In the i-th round, the game master announces: * Form groups consisting of A_i children each! Then the children who are still in the game form as man...
{"inputs": ["4\n3 3 2 2", "4\n4 3 2 2", "4\n3 5 3 2", "4\n1 1 2 2", "4\n3 4 2 2", "4\n3 6 2 2", "4\n3 6 4 2", "4\n3 4 3 2"], "outputs": ["3 5\n", "4 7\n", "6 11\n", "2 3\n", "-1\n", "-1\n", "-1\n", "6 8"]}
coding
372
Solve the programming task below in a Python markdown code block. Implement a function, `multiples(m, n)`, which returns an array of the first `m` multiples of the real number `n`. Assume that `m` is a positive integer. Ex. ``` multiples(3, 5.0) ``` should return ``` [5.0, 10.0, 15.0] ``` Also feel free to reuse/exten...
{"functional": "_inputs = [[3, 5], [1, 3.14], [5, -1]]\n_outputs = [[[5, 10, 15]], [[3.14]], [[-1, -2, -3, -4, -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 ...
coding
115
Solve the programming task below in a Python markdown code block. Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. You are given a sequence $A_{1}, A_{2}, \ldots, A_{N}$. Find the maximum value of the expression $|A_{x}-A_{y}| + |A_{y}-A_{z}| + |A_{z}-A_{x}|$ over...
{"inputs": ["3\n3\n2 7 5\n3\n3 3 3\n5\n2 2 2 2 5"], "outputs": ["10\n0\n6"]}
coding
556
Solve the programming task below in a Python markdown code block. We have a grid of squares with N rows and M columns. Let (i, j) denote the square at the i-th row from the top and j-th column from the left. We will choose K of the squares and put a piece on each of them. If we place the K pieces on squares (x_1, y_1),...
{"inputs": ["4 2 2", "4 5 7", "2 3 2", "4 6 7", "2 3 3", "2 4 3", "1 4 3", "1 4 4"], "outputs": ["56\n", "4883760\n", "25\n", "24227280\n", "100\n", "336\n", "20\n", "10\n"]}
coding
510
Solve the programming task below in a Python markdown code block. Companies always have a lot of equipment, furniture and other things. All of them should be tracked. To do this, there is an inventory number assigned with each item. It is much easier to create a database by using those numbers and keep the track of eve...
{"inputs": ["1\n2\n", "1\n3\n", "1\n6\n", "1\n1\n", "1\n5\n", "1\n7\n", "1\n2\n", "2\n1 4\n"], "outputs": ["1 \n", "1\n", "1\n", "1\n", "1\n", "1\n", "1 \n", "1 2 \n"]}
coding
452
Solve the programming task below in a Python markdown code block. The most basic encryption method is to map a char to another char by a certain math rule. Because every char has an ASCII value, we can manipulate this value with a simple math expression. For example 'a' + 1 would give us 'b', because 'a' value is 97 a...
{"functional": "_inputs = [['', 1], ['a', 1], ['please encrypt me', 2]]\n_outputs = [[''], ['b'], ['rngcug\"gpet{rv\"og']]\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
185
Solve the programming task below in a Python markdown code block. ## The Riddle The King of a small country invites 1000 senators to his annual party. As a tradition, each senator brings the King a bottle of wine. Soon after, the Queen discovers that one of the senators is trying to assassinate the King by giving him ...
{"functional": "_inputs = [[[0]], [[1]], [[2]], [[3]], [[4]], [[5]], [[6]], [[7]], [[8]], [[9]], [[3, 5, 6, 7, 8, 9]], [[0, 3, 5, 4, 9, 8]], [[0, 1, 9, 3, 5]], [[0, 1, 2, 3, 4, 6]], [[0, 1, 3, 4]]]\n_outputs = [[1], [2], [4], [8], [16], [32], [64], [128], [256], [512], [1000], [825], [555], [95], [27]]\nimport math\nde...
coding
304
Solve the programming task below in a Python markdown code block. You are parking at a parking lot. You can choose from the following two fee plans: - Plan 1: The fee will be A×T yen (the currency of Japan) when you park for T hours. - Plan 2: The fee will be B yen, regardless of the duration. Find the minimum fee wh...
{"inputs": ["7 17 120\n", "5 20 100\n", "6 18 100\n"], "outputs": ["119\n", "100\n", "100\n"]}
coding
234
Solve the programming task below in a Python markdown code block. During the Steam Summer Sale, Jim's $N-1$ friends have purchased $\mbox{M}$ games, which are numbered from $\mbox{1}$ to $\mbox{M}$. The games are multiplayer. Jim has invited his friends to his basement where they will play by making a LAN-Party. Each...
{"inputs": ["5 2 4\n1 2 2 2 1\n1 2 \n2 3\n1 5\n4 5 \n"], "outputs": ["3\n4\n"]}
coding
669
Solve the programming task below in a Python markdown code block. It is raining heavily. But this is the first day for Serval, who just became 3 years old, to go to the kindergarten. Unfortunately, he lives far from kindergarten, and his father is too busy to drive him there. The only choice for this poor little boy is...
{"inputs": ["1 4\n2 2\n", "1 4\n2 2\n", "1 4\n0 2\n", "1 4\n-1 2\n", "2 2\n6 4\n9 5\n", "2 5\n4 3\n3 3\n", "2 7\n4 3\n3 3\n", "2 7\n4 4\n3 3\n"], "outputs": ["1\n", "1", "1\n", "1\n", "1\n", "2\n", "1\n", "1\n"]}
coding
604
Solve the programming task below in a Python markdown code block. Serval is fighting with a monster. The health of the monster is H. In one attack, Serval can decrease the monster's health by A. There is no other way to decrease the monster's health. Serval wins when the monster's health becomes 0 or below. Find the nu...
{"inputs": ["4 3", "1 1\n", "14 4", "14 3", "11 2", "14 5", "26 4", "20 2"], "outputs": ["2\n", "1\n", "4\n", "5\n", "6\n", "3\n", "7\n", "10\n"]}
coding
228
Solve the programming task below in a Python markdown code block. One not particularly beautiful evening Valera got very bored. To amuse himself a little bit, he found the following game. He took a checkered white square piece of paper, consisting of n × n cells. After that, he started to paint the white cells black o...
{"inputs": ["1 1\n1 1\n", "2 1\n1 1\n", "3 1\n1 3\n", "2 1\n1 2\n", "1000 1\n542 374\n", "1000 1\n542 737\n", "1000 1\n542 1000\n", "2 4\n2 1\n1 2\n1 1\n2 2\n"], "outputs": ["-1", "-1", "-1", "-1\n", "-1", "-1\n", "-1\n", "-1"]}
coding
541
Solve the programming task below in a Python markdown code block. Let's define the value of the permutation $p$ of $n$ integers $1$, $2$, ..., $n$ (a permutation is an array where each element from $1$ to $n$ occurs exactly once) as follows: initially, an integer variable $x$ is equal to $0$; if $x < p_1$, then add $...
{"inputs": ["1\n5\n", "3\n4\n5\n6\n"], "outputs": ["1 3 2 4 5 \n", "2 1 3 4 \n1 3 2 4 5 \n2 1 4 3 5 6 \n"]}
coding
476
Solve the programming task below in a Python markdown code block. The Jones Trucking Company tracks the location of each of its trucks on a grid similar to an (x, y) plane. The home office is at the location (0, 0). Read the coordinates of truck A and the coordinates of truck B and determine which is closer to the offi...
{"inputs": ["4\n3 -2 -5 -3\n0 6 1 2\n-7 8 4 -1\n3 3 -2 2"], "outputs": ["A IS CLOSER\nB IS CLOSER\nB IS CLOSER\nB IS CLOSER"]}
coding
298
Solve the programming task below in a Python markdown code block. Example Input 4 Durett 7 Gayles 3 Facenda 6 Daughtery 0 1 + Mccourtney 2 Output Mccourtney is not working now. Durett is working hard now.
{"inputs": ["4\nDurett 7\nGayles 3\nFacenda 6\nyrethguaD 0\n1\n+ Mccourtney 2", "4\nDurett 7\nGayles 3\nFacenda 6\nDaughtery 0\n1\n+ yentruoccM 3", "4\nDurett 7\nGaylds 3\nFbccnda 2\nyrethguaD 0\n1\n+ yeotruoccM 2", "4\nDurett 7\nGaylds 3\nFbccnda 2\nyrdthguaD 0\n1\n+ yeMtruocco 2", "4\nDurett 7\nGaylds 3\nFbccnda 2\ny...
coding
70
Solve the programming task below in a Python markdown code block. Devendra just had a million-dollar idea and he needs funds to startup. He was recently invited to Sasta Shark Tank (A TV show where entrepreneurs pitch their ideas to investors hoping to get investment in return). He was offered deals from two investors...
{"inputs": ["3\n100 200\n200 100\n200 500\n"], "outputs": ["ANY\nFIRST\nSECOND"]}
coding
738
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a binary tree, find its minimum depth. The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node. Note: A leaf is a node with no children.   Please complet...
{"functional": "def check(candidate):\n assert candidate(root = tree_node([3,9,20,None,None,15,7])) == 2\n assert candidate(root = tree_node([2,None,3,None,4,None,5,None,6])) == 5\n\n\ncheck(Solution().minDepth)"}
coding
145
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an array of integers arr of even length n and an integer k. We want to divide the array into exactly n / 2 pairs such that the sum of each pair is divisible by k. Return true If you can find a way to do that or ...
{"functional": "def check(candidate):\n assert candidate(arr = [1,2,3,4,5,10,6,7,8,9], k = 5) == True\n assert candidate(arr = [1,2,3,4,5,6], k = 7) == True\n assert candidate(arr = [1,2,3,4,5,6], k = 10) == False\n\n\ncheck(Solution().canArrange)"}
coding
107
Solve the programming task below in a Python markdown code block. A famous Berland's painter Kalevitch likes to shock the public. One of his last obsessions is chess. For more than a thousand years people have been playing this old game on uninteresting, monotonous boards. Kalevitch decided to put an end to this tradit...
{"inputs": ["BBBBBBBB\nWBWWBBBW\nBBBBBBBB\nWBWWBBBW\nWBWWBBBW\nWBWWBBBW\nWBWWBBBW\nBBBBBBBB\n", "BBBBBBBB\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nBWBBWBWB\n", "BBBBBBBB\nWWWBBBBB\nWWWBBBBB\nBBBBBBBB\nWWWBBBBB\nWWWBBBBB\nBBBBBBBB\nBBBBBBBB\n", "BBBBBBBB\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nBBBBBBBB\nBBBBB...
coding
542
Solve the programming task below in a Python markdown code block. A k-multiple free set is a set of integers where there is no pair of integers where one is equal to another integer multiplied by k. That is, there are no two integers x and y (x < y) from the set, such that y = x·k. You're given a set of n distinct pos...
{"inputs": ["1 1\n1\n", "1 1\n1\n", "1 1\n2\n", "1 1\n3\n", "1 2\n3\n", "1 4\n3\n", "1 2\n5\n", "1 4\n5\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n"]}
coding
276
Solve the programming task below in a Python markdown code block. Your job is to change the given string `s` using a non-negative integer `n`. Each bit in `n` will specify whether or not to swap the case for each alphabetic character in `s`: if the bit is `1`, swap the case; if its `0`, leave it as is. When you finish...
{"functional": "_inputs = [['Hello world!', 11], ['the quick broWn fox leapt over the fence', 9], ['eVerybody likes ice cReam', 85], ['gOOd MOrniNg', 7864], ['how are you today?', 12345], ['the lord of the rings', 0], ['', 11345]]\n_outputs = [['heLLO wORLd!'], ['The QUicK BrowN foX LeaPT ovER thE FenCE'], ['EVErYbODy ...
coding
337
Solve the programming task below in a Python markdown code block. Given an array, find the duplicates in that array, and return a new array of those duplicates. The elements of the returned array should appear in the order when they first appeared as duplicates. __*Note*__: numbers and their corresponding string repre...
{"functional": "_inputs = [[[1, 2, 4, 4, 3, 3, 1, 5, 3, '5']], [[0, 1, 2, 3, 4, 5]], [[1, 1, 2, 3, 4, 5, 4]]]\n_outputs = [[[4, 3, 1]], [[]], [[1, 4]]]\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 i...
coding
171
Solve the programming task below in a Python markdown code block. Chef is deriving weird ways to sort his array. Currently he is trying to sort his arrays in increasing order by reversing some of his subarrays. To make it more challenging for himself, Chef decides that he can reverse only those subarrays that have sum...
{"inputs": ["3\n4 1\n1 2 3 4\n4 1\n2 1 3 4\n5 7\n3 2 2 3 3\n"], "outputs": ["YES\nNO\nYES\n"]}
coding
624
Solve the programming task below in a Python markdown code block. Little Vitaly loves different algorithms. Today he has invented a new algorithm just for you. Vitaly's algorithm works with string s, consisting of characters "x" and "y", and uses two following operations at runtime: Find two consecutive characters in ...
{"inputs": ["x\n", "y\n", "x\n", "xxx\n", "xxx\n", "yxx\n", "yxyxy\n", "xxyxx\n"], "outputs": ["x\n", "y\n", "x", "xxx\n", "xxx", "x\n", "y\n", "xxx\n"]}
coding
587
Solve the programming task below in a Python markdown code block. In this kata, your task is to create a function that takes a single list as an argument and returns a flattened list. The input list will have a maximum of one level of nesting (list(s) inside of a list). ```python # no nesting [1, 2, 3] # one level of...
{"functional": "_inputs = [[[1, [2, 3], 4]], [[['a', 'b'], 'c', ['d']]], [['!', '?']]]\n_outputs = [[[1, 2, 3, 4]], [['a', 'b', 'c', 'd']], [['!', '?']]]\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...
coding
228
Solve the programming task below in a Python markdown code block. What joy! Petya's parents went on a business trip for the whole year and the playful kid is left all by himself. Petya got absolutely happy. He jumped on the bed and threw pillows all day long, until... Today Petya opened the cupboard and found a scary...
{"inputs": ["0\n0 0 0 0 0 0 0 0 0 0 0 0\n", "1\n0 0 0 0 0 0 0 0 0 0 0 0\n", "1\n0 0 0 0 0 0 0 0 0 0 1 0\n", "0\n0 0 0 1 0 0 0 1 1 2 3 0\n", "5\n1 1 1 1 2 2 6 2 2 1 1 1\n", "0\n0 0 0 1 0 0 1 1 1 2 3 0\n", "5\n1 1 1 1 0 2 6 2 2 1 1 1\n", "0\n0 0 0 0 0 0 0 1 1 2 3 0\n"], "outputs": ["0\n", "-1\n", "1\n", "0\n", "1\n", "0\...
coding
539
Solve the programming task below in a Python markdown code block. In this Kata, you will be given a lower case string and your task will be to remove `k` characters from that string using the following rule: ```Python - first remove all letter 'a', followed by letter 'b', then 'c', etc... - remove the leftmost characte...
{"functional": "_inputs = [['abracadabra', 0], ['abracadabra', 1], ['abracadabra', 2], ['abracadabra', 6], ['abracadabra', 8], ['abracadabra', 50], ['hxehmvkybeklnj', 5], ['cccaabababaccbc', 3], ['cccaabababaccbc', 9], ['u', 1], ['back', 3]]\n_outputs = [['abracadabra'], ['bracadabra'], ['brcadabra'], ['rcdbr'], ['rdr'...
coding
308
Solve the programming task below in a Python markdown code block. Sereja has an array a, consisting of n integers a_1, a_2, ..., a_{n}. The boy cannot sit and do nothing, he decided to study an array. Sereja took a piece of paper and wrote out m integers l_1, l_2, ..., l_{m} (1 ≤ l_{i} ≤ n). For each number l_{i} he wa...
{"inputs": ["1 1\n1\n1\n", "1 1\n1\n1\n", "1 1\n2\n1\n", "1 1\n0\n1\n", "2 2\n8 4\n1\n1\n", "2 2\n8 4\n1\n1\n", "2 2\n8 4\n2\n1\n", "2 2\n2 4\n1\n1\n"], "outputs": ["1\n", "1", "1\n", "1\n", "2\n2\n", "2\n2", "1\n2\n", "2\n2\n"]}
coding
406
Solve the programming task below in a Python markdown code block. A new TV streaming service was recently started in Chefland called the Chef-TV. A group of N friends in Chefland want to buy Chef-TV subscriptions. We know that 6 people can share one Chef-TV subscription. Also, the cost of one Chef-TV subscription is X...
{"inputs": ["3\n1 100\n12 250\n16 135\n"], "outputs": ["100\n500\n405\n"]}
coding
398
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given the roots of two binary trees p and q, write a function to check if they are the same or not. Two binary trees are considered the same if they are structurally identical, and the nodes have the same value.   Ple...
{"functional": "def check(candidate):\n assert candidate(p = tree_node([1,2,3]), q = tree_node([1,2,3])) == True\n assert candidate(p = tree_node([1,2]), q = tree_node([1,None,2])) == False\n assert candidate(p = tree_node([1,2,1]), q = tree_node([1,1,2])) == False\n\n\ncheck(Solution().isSameTree)"}
coding
153
Solve the programming task below in a Python markdown code block. Peter is a person with erratic sleep habits. He goes to sleep at twelve o'lock every midnight. He gets up just after one hour of sleep on some days; he may even sleep for twenty-three hours on other days. His sleeping duration changes in a cycle, where h...
{"inputs": ["2\n0 5\n3\n1 1\n2 1\n3 1\n0", "2\n0 5\n3\n1 1\n2 2\n3 1\n0", "2\n0 1\n3\n1 1\n2 2\n3 1\n0", "2\n0 1\n3\n2 1\n2 2\n3 1\n0", "2\n1 5\n3\n1 1\n2 1\n3 1\n0", "2\n0 5\n3\n1 2\n2 2\n3 1\n0", "2\n0 1\n3\n1 1\n2 0\n3 1\n0", "2\n0 2\n3\n1 1\n2 2\n3 1\n0"], "outputs": ["2\n", "2\n", "0\n", "0\n", "2\n", "2\n", "1\n"...
coding
508
Solve the programming task below in a Python markdown code block. You want to type the string $s$, consisting of $n$ lowercase Latin letters, using your favorite text editor Notepad#. Notepad# supports two kinds of operations: append any letter to the end of the string; copy a continuous substring of an already type...
{"inputs": ["1\n3\nyes\n", "6\n10\ncodeforces\n8\nlabacaba\n5\nuohhh\n16\nisthissuffixtree\n1\nx\n4\nmomo\n"], "outputs": ["NO\n", "NO\nYES\nNO\nYES\nNO\nYES\n"]}
coding
438
Solve the programming task below in a Python markdown code block. Your task is to ___Reverse and Combine Words___. It's not too difficult, but there are some things you have to consider... ### So what to do? Input: String containing different "words" separated by spaces ``` 1. More than one word? Reverse each word ...
{"functional": "_inputs = [['abc def'], ['abc def ghi jkl'], ['dfghrtcbafed'], ['234hh54 53455 sdfqwzrt rtteetrt hjhjh lllll12 44'], ['sdfsdf wee sdffg 342234 ftt']]\n_outputs = [['cbafed'], ['defabcjklghi'], ['dfghrtcbafed'], ['trzwqfdstrteettr45hh4325543544hjhjh21lllll'], ['gffds432243fdsfdseewttf']]\nimport math\nd...
coding
272
Solve the programming task below in a Python markdown code block. Before the Battle of Kamino the Confederacy of Independent Systems developed the a way to communicate with the far systems. This way is very unique as every word consists of exactly L lowercase letters. Also, there are exactly D words in this. Jedi orde...
{"inputs": ["10 25 10\nnwlrbbmqbh\ncdarzowkky\nhiddqscdxr\njmowfrxsjy\nbldbefsarc\nbynecdyggx\nxpklorelln\nmpapqfwkho\npkmcoqhnwn\nkuewhsqmgb\nbuqcljjivs\nwmdkqtbxix\nmvtrrbljpt\nnsnfwzqfjm\nafadrrwsof\nsbcnuvqhff\nbsaqxwpqca\ncehchzvfrk\nmlnozjkpqp\nxrjxkitzyx\nacbhhkicqc\noendtomfgd\nwdwfcgpxiq\nvkuytdlcgd\newhtacioh...
coding
432
Please solve the programming task below using a self-contained code snippet in a markdown code block. A magic index in an array A[0...n-1] is defined to be an index such that A[i] = i. Given a sorted array of integers, write a method to find a magic index, if one exists, in array A. If not, return -1. If there are mor...
{"functional": "def check(candidate):\n assert candidate(nums = [0, 2, 3, 4, 5]) == 0\n assert candidate(nums = [1, 1, 1]) == 1\n\n\ncheck(Solution().findMagicIndex)"}
coding
123
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a 0-indexed m x n integer matrix grid consisting of distinct integers from 0 to m * n - 1. You can move in this matrix from a cell to any other cell in the next row. That is, if you are in cell (x, y) su...
{"functional": "def check(candidate):\n assert candidate(grid = [[5,3],[4,0],[2,1]], moveCost = [[9,8],[1,5],[10,12],[18,6],[2,4],[14,3]]) == 17\n assert candidate(grid = [[5,1,2],[4,0,3]], moveCost = [[12,10,15],[20,23,8],[21,7,1],[8,1,13],[9,10,25],[5,3,2]]) == 6\n\n\ncheck(Solution().minPathCost)"}
coding
306
Solve the programming task below in a Python markdown code block. A TV program called "Saizo" is popular in a certain country. In this program, participants challenge field athletics and get a prize if they successfully capture it. Field athletics are made by arranging blocks of different heights in a row, and how to ...
{"inputs": ["5\n5\n5 101 5 98 117\n2\n3 100\n2\n101 26\n3\n22 86 50\n7\n123 17 959 901 2 971 1573", "5\n5\n10 101 5 50 59\n2\n20 100\n2\n100 30\n3\n5 86 50\n7\n123 82 959 319 41 971 275", "5\n5\n5 101 5 98 117\n2\n15 100\n2\n100 30\n3\n22 86 50\n7\n123 82 959 901 2 971 1573", "5\n5\n5 101 5 98 117\n2\n15 100\n2\n101 30...
coding
446
Solve the programming task below in a Python markdown code block. The stardate is 1983, and Princess Heidi is getting better at detecting the Death Stars. This time, two Rebel spies have yet again given Heidi two maps with the possible locations of the Death Star. Since she got rid of all double agents last time, she k...
{"inputs": ["1 1\ng\ng\n", "1 1\ng\ng\n", "10 5\nsomer\nandom\nnoise\nmayth\neforc\nebewi\nthyou\nhctwo\nagain\nnoise\nsomermayth\nandomeforc\nnoiseebewi\nagainthyou\nnoisehctwo\n", "10 5\nsomer\nandom\nnoise\nmayth\neforc\nebewi\nthyou\nhctwo\nagain\nooise\nsomermayth\nandomeforc\nnoiseebewi\nagainthyou\nnoisehctwo\n"...
coding
499
Solve the programming task below in a Python markdown code block. You are given a board of size $2 \times n$ ($2$ rows, $n$ columns). Some cells of the board contain chips. The chip is represented as '*', and an empty space is represented as '.'. It is guaranteed that there is at least one chip on the board. In one mo...
{"inputs": ["5\n1\n*\n.\n2\n.*\n**\n3\n*.*\n.*.\n4\n**.*\n**..\n5\n**...\n...**\n"], "outputs": ["0\n2\n3\n5\n5\n"]}
coding
502
Solve the programming task below in a Python markdown code block. Kawashiro Nitori is a girl who loves competitive programming. One day she found a string and an integer. As an advanced problem setter, she quickly thought of a problem. Given a string $s$ and a parameter $k$, you need to check if there exist $k+1$ non...
{"inputs": ["7\n5 1\nqwqwq\n2 1\nc`\n3 1\nioi\n4 2\niqcc\n22 0\ndokidokiliteratureclub\n9 8\nimteamshanghaialice\n6 3\naaaaaa\n", "7\n5 1\nqwqwq\n2 1\nab\n3 1\nioi\n4 2\nicpc\n22 0\ndokidokiliteratureclub\n19 8\nimteamshanghaialice\n6 3\naaaaaa\n", "7\n5 1\nqwqwq\n2 1\nab\n3 1\nioi\n4 2\nipcc\n22 0\ndokidokiliteraturec...
coding
553
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. Last week Penguin Charlie had a birthday. Chef presented him a string S. Unfortunately, Charlie doesn't like string S, he likes string F. Charlie wants to create a few strin...
{"inputs": ["3\nchefandcharliethebest\ncharliethebest\nheknowsimeanityeahyouknowimeanityouknow\nimeanit\naaaaa\naa"], "outputs": ["1\n3\n7"]}
coding
601
Solve the programming task below in a Python markdown code block. Striver$Striver$ wants to strive hard in order to reach his goals, hence asks his mentor to give him a question for which he has to strive hard. The mentor gives Striver$Striver$ a N$N$ X N$N$ matrix consisting of lowercase characters (′a′$'a'$ to ′z′$'...
{"inputs": ["1\n3 2\na b a\na c d\nb a b\n1 3\n3 3"], "outputs": ["1\n2"]}
coding
582
Solve the programming task below in a Python markdown code block. Let's call beauty of an array $b_1, b_2, \ldots, b_n$ ($n > 1$)  — $\min\limits_{1 \leq i < j \leq n} |b_i - b_j|$. You're given an array $a_1, a_2, \ldots a_n$ and a number $k$. Calculate the sum of beauty over all subsequences of the array of length e...
{"inputs": ["3 2\n4 4 4\n", "3 2\n4 4 4\n", "3 3\n1 4 0\n", "3 2\n8 4 4\n", "3 3\n4 4 4\n", "3 3\n4 4 7\n", "3 3\n4 4 0\n", "3 5\n1 4 0\n"], "outputs": ["0", "0\n", "1\n", "8\n", "0\n", "0\n", "0\n", "0\n"]}
coding
465
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given the array of integers nums, you will choose two different indices i and j of that array. Return the maximum value of (nums[i]-1)*(nums[j]-1).   Please complete the following python code precisely: ```python clas...
{"functional": "def check(candidate):\n assert candidate(nums = [3,4,5,2]) == 12 \n assert candidate(nums = [1,5,4,5]) == 16\n assert candidate(nums = [3,7]) == 12\n\n\ncheck(Solution().maxProduct)"}
coding
84
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given two strings s and t, return true if t is an anagram of s, and false otherwise.   Please complete the following python code precisely: ```python class Solution: def isAnagram(self, s: str, t: str) -> bool: ``...
{"functional": "def check(candidate):\n assert candidate(s = \"anagram\", t = \"nagaram\") == True\n assert candidate(s = \"rat\", t = \"car\") == False\n\n\ncheck(Solution().isAnagram)"}
coding
74
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given two string arrays words1 and words2. A string b is a subset of string a if every letter in b occurs in a including multiplicity. For example, "wrr" is a subset of "warrior" but is not a subset of "world...
{"functional": "def check(candidate):\n assert candidate(words1 = [\"amazon\",\"apple\",\"facebook\",\"google\",\"leetcode\"], words2 = [\"e\",\"o\"]) == [\"facebook\",\"google\",\"leetcode\"]\n assert candidate(words1 = [\"amazon\",\"apple\",\"facebook\",\"google\",\"leetcode\"], words2 = [\"l\",\"e\"]) == [\"ap...
coding
159
Solve the programming task below in a Python markdown code block. This is related to my other Kata about cats and dogs. # Kata Task I have a cat and a dog which I got as kitten / puppy. I forget when that was, but I do know their current ages as `catYears` and `dogYears`. Find how long I have owned each of my pets ...
{"functional": "_inputs = [[9, 7], [15, 15], [18, 21], [19, 17], [24, 24], [25, 25], [26, 26], [27, 27], [56, 64]]\n_outputs = [[[0, 0]], [[1, 1]], [[1, 1]], [[1, 1]], [[2, 2]], [[2, 2]], [[2, 2]], [[2, 2]], [[10, 10]]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n ...
coding
265
Solve the programming task below in a Python markdown code block. Winnie-the-Pooh likes honey very much! That is why he decided to visit his friends. Winnie has got three best friends: Rabbit, Owl and Eeyore, each of them lives in his own house. There are winding paths between each pair of houses. The length of a path ...
{"inputs": ["3\n2\n3\n1\n", "1\n2\n3\n5\n", "9\n9\n7\n5\n", "1\n2\n2\n1\n", "1\n1\n1\n1\n", "2\n1\n1\n3\n", "1\n3\n2\n1\n", "1\n5\n6\n1\n"], "outputs": ["3\n", "0\n", "42\n", "0\n", "0\n", "1\n", "0\n", "0\n"]}
coding
555
Solve the programming task below in a Python markdown code block. In mathematics, a **pandigital number** is a number that in a given base has among its significant digits each digit used in the base at least once. For example, 1234567890 is a pandigital number in base 10. For simplification, in this kata, we will con...
{"functional": "_inputs = [[0, 5], [5432160879, 3], [9876543000, 5], [9999999999, 1], [-123456789, 1], [-9999999999, 25]]\n_outputs = [[[1023456789, 1023456798, 1023456879, 1023456897, 1023456978]], [[5432160879, 5432160897, 5432160978]], [[9876543012, 9876543021, 9876543102, 9876543120, 9876543201]], [[]], [[102345678...
coding
347
Solve the programming task below in a Python markdown code block. Chandrima likes the XOR operation very much and keeps finding and solving related problems. One day she comes across a problem and gets stuck on it, which makes her sad. You being her friend decide to help her out by writing a code for the same. Consid...
{"inputs": ["3\n1 2 3\n", "3\n1 3 4\n"], "outputs": ["7\n", "0\n"]}
coding
388
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin and Russian. Translations in Vietnamese to be uploaded soon. You have a matrix of size N * N with rows numbered through 1 to N from top to bottom and columns through 1 to N from left to right. It contains all values...
{"inputs": ["2\n2\n1 3\n2 4\n3\n1 7 9\n2 4 8\n3 6 5", "2\n2\n1 3\n2 4\n3\n2 7 9\n1 4 8\n3 6 5", "2\n2\n1 3\n2 4\n3\n1 7 9\n3 4 8\n2 6 5", "2\n2\n1 3\n2 4\n3\n1 7 9\n2 4 8\n6 3 5", "2\n2\n1 3\n2 4\n3\n1 7 5\n2 4 8\n6 3 9", "2\n2\n2 3\n1 4\n3\n2 7 9\n1 4 8\n3 6 5", "2\n2\n1 3\n2 4\n3\n2 7 9\n1 3 8\n4 6 5", "2\n2\n1 3\n2 ...
coding
625
Solve the programming task below in a Python markdown code block. Create a program that inputs the test result data of the visual acuity test and outputs the number of people who apply to each judgment based on the following visual acuity judgment table for each of the left and right eyesight. Judgment | Sight --- | -...
{"inputs": ["1.0 1.2\n0.8 1.5\n1.2 0.7\n2.0 2.0", "1.0 1.2\n0.8 1.5\n1.2 0.7\n2.0 2.1903643288076555", "1.0 1.2\n0.8 1.5\n1.2 0.7\n2.751284804693524 2.1903643288076555", "1.0 1.2\n0.8 1.5471720124202895\n1.2 0.7\n2.751284804693524 2.1903643288076555", "1.0 1.6960573379527397\n0.8 1.5471720124202895\n1.2 0.7\n2.75128480...
coding
390
Solve the programming task below in a Python markdown code block. Monocarp has got an array $a$ consisting of $n$ integers. Let's denote $k$ as the mathematic mean of these elements (note that it's possible that $k$ is not an integer). The mathematic mean of an array of $n$ elements is the sum of elements divided by t...
{"inputs": ["1\n1\n228 1337 3\n", "1\n1\n228 1512 3\n", "1\n1\n228 2063 3\n", "1\n1\n228 2063 2\n", "1\n1\n342 1512 3\n", "1\n1\n228 2063 0\n", "1\n1\n228 4021 2\n", "1\n3\n40 270 228\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]}
coding
577
Solve the programming task below in a Python markdown code block. The last contest held on Johnny's favorite competitive programming platform has been received rather positively. However, Johnny's rating has dropped again! He thinks that the presented tasks are lovely, but don't show the truth about competitors' skills...
{"inputs": ["1\n1\n", "1\n1\n", "1\n399462040\n", "1\n338186953\n", "1\n158575687\n", "1\n313577823\n", "1\n247528392\n", "1\n452215226\n"], "outputs": ["1\n", "1\n", "798924063\n", "676373895\n", "317151359\n", "627155631\n", "495056769\n", "904430437\n"]}
coding
610