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.
Alice and Bob play 5-in-a-row game. They have a playing field of size 10 × 10. In turns they put either crosses or noughts, one at a time. Alice puts crosses and Bob puts noughts.
In current match they have made some turns and now it's Alice's turn. She... | {"inputs": ["XX.XX.....\n.....OOOO.\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n", "XXOXX.....\nOO.O......\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n", "XO........\n.XO.......\n..XO......\n....O.....\n....X.....\... | coding | 320 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
There is an integer array nums that consists of n unique elements, but you have forgotten it. However, you do remember every pair of adjacent elements in nums.
You are given a 2D integer array adjacentPairs of size n ... | {"functional": "def check(candidate):\n assert candidate(adjacentPairs = [[2,1],[3,4],[3,2]]) == [1,2,3,4]\n assert candidate(adjacentPairs = [[4,-2],[1,4],[-3,1]]) == [-2,4,1,-3]\n assert candidate(adjacentPairs = [[100000,-100000]]) == [100000,-100000]\n\n\ncheck(Solution().restoreArray)"} | coding | 194 |
Solve the programming task below in a Python markdown code block.
You have recently fallen through a hole and, after several hours of unconsciousness, have realized you are in an underground city. On one of your regular, daily walks through the unknown, you have encountered two unusually looking skeletons called Sanz a... | {"inputs": ["6\nabacba\n2\naba 6\nba 3\n1\n", "6\nabacba\n2\naba 6\nba 3\n2\n", "6\nabacba\n2\naba 6\nba 4\n2\n", "6\nabacba\n2\naba 5\nba 4\n2\n", "6\nabacba\n2\naba 5\nba 0\n2\n", "6\nabacba\n2\nbaa 5\nab 0\n2\n", "6\nabacba\n2\nbaa 5\nba 1\n2\n", "6\nabacba\n2\nbaa 5\nba 2\n2\n"], "outputs": ["9\n", "12\n", "14\n", ... | coding | 568 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an m x n binary matrix mat, return the length of the longest line of consecutive one in the matrix.
The line could be horizontal, vertical, diagonal, or anti-diagonal.
Please complete the following python code... | {"functional": "def check(candidate):\n assert candidate(mat = [[0,1,1,0],[0,1,1,0],[0,0,0,1]]) == 3\n assert candidate(mat = [[1,1,1,1],[0,1,1,0],[0,0,0,1]]) == 4\n\n\ncheck(Solution().longestLine)"} | coding | 87 |
Solve the programming task below in a Python markdown code block.
Quickly after finishing the tutorial of the online game ATChat, you have decided to visit a particular place with N-1 players who happen to be there. These N players, including you, are numbered 1 through N, and the friendliness of Player i is A_i.
The N... | {"inputs": ["4\n1 2 1 3", "4\n1 3 1 3", "4\n1 5 1 3", "4\n1 4 1 3", "4\n2 4 1 2", "4\n1 7 1 8", "4\n0 0 0 0", "4\n0 1 0 0"], "outputs": ["7\n", "9\n", "11\n", "10\n", "8\n", "22\n", "0\n", "1\n"]} | coding | 379 |
Solve the programming task below in a Python markdown code block.
Sophia has discovered several alien languages. Suprisingly, all of these languages have an alphabet, and each of them may contain thousands of characters! Also, all the words in a language have the same number of characters in it.
However, the aliens li... | {"inputs": ["3\n1 3\n2 3\n3 2\n"], "outputs": ["1\n3\n6\n"]} | coding | 675 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an integer array nums, return all the triplets [nums[i], nums[j], nums[k]] such that i != j, i != k, and j != k, and nums[i] + nums[j] + nums[k] == 0.
Notice that the solution set must not contain duplicate trip... | {"functional": "def check(candidate):\n assert candidate(nums = [-1,0,1,2,-1,-4]) == [[-1,-1,2],[-1,0,1]]\n assert candidate(nums = [0,1,1]) == []\n assert candidate(nums = [0,0,0]) == [[0,0,0]]\n\n\ncheck(Solution().threeSum)"} | coding | 114 |
Solve the programming task below in a Python markdown code block.
Chef Tobby asked Bhuvan to brush up his knowledge of statistics for a test. While studying some distributions, Bhuvan learns the fact that for symmetric distributions, the mean and the median are always the same.
Chef Tobby asks Bhuvan out for a game and... | {"inputs": ["3\n1\n2\n3"], "outputs": ["1\n1 2\n1 2 3"]} | coding | 473 |
Solve the programming task below in a Python markdown code block.
Palindrome
Problem Statement
Find the number of palindromes closest to the integer n.
Note that the non-negative integer x is the number of palindromes, which means that the character string in which x is expressed in decimal notation and the characte... | {"inputs": ["4", "8", "7", "6", "5", "1", "2", "3"], "outputs": ["4\n", "8\n", "7\n", "6\n", "5\n", "1\n", "2\n", "3\n"]} | coding | 215 |
Solve the programming task below in a Python markdown code block.
An even sequence has the following property: each maximal contiguous subsequence which contains only equal integers (i.e. the same integer repeated a number of times) has an even length. In particular, the empty sequence is even. A subsequence is maximal... | {"inputs": ["2\n4\n1 1 2 1\n11\n2 2 2 10 2 10 1 1 5 3 5"], "outputs": ["2\n3"]} | coding | 611 |
Solve the programming task below in a Python markdown code block.
Recently a top secret mission to Mars has taken place. As a result, scientists managed to obtain some information about the Martian DNA. Now we know that any Martian DNA contains at most m different nucleotides, numbered from 1 to m. Special characterist... | {"inputs": ["3 3 0\n", "5000 3 0\n", "6984 3 0\n", "6984 4 0\n", "2 1 1\naa\n", "100000 52 0\n", "100000 34 0\n", "3 4 2\nab\nba\n"], "outputs": ["27\n", "22443616\n", "170353494", "63989708", "0\n", "378241178\n", "486606280", "50"]} | coding | 634 |
Solve the programming task below in a Python markdown code block.
There is an infinitely long street that runs west to east, which we consider as a number line.
There are N roadworks scheduled on this street.
The i-th roadwork blocks the point at coordinate X_i from time S_i - 0.5 to time T_i - 0.5.
Q people are standi... | {"inputs": ["4 5\n0 4 1\n8 13 1\n2 48 9\n3 4 2\n1\n0\n2\n3\n5\n8", "4 5\n0 4 1\n8 13 1\n2 48 9\n3 4 2\n1\n0\n2\n0\n5\n8", "4 5\n0 4 1\n8 13 1\n2 48 4\n3 4 2\n1\n0\n2\n0\n5\n8", "4 2\n0 4 1\n8 21 1\n2 48 4\n3 5 2\n1\n0\n2\n0\n5\n8", "4 5\n2 4 2\n8 13 1\n17 6 6\n5 7 2\n1\n1\n2\n3\n8\n8", "4 5\n2 4 2\n8 13 1\n17 6 6\n5 7 ... | coding | 509 |
Solve the programming task below in a Python markdown code block.
Given are integer sequences A and B of length 3N. Each of these two sequences contains three copies of each of 1, 2, \dots, N. In other words, A and B are both arrangements of (1, 1, 1, 2, 2, 2, \dots, N, N, N).
Tak can perform the following operation t... | {"inputs": ["3\n2 3 3 1 2 1 2 1 3\n3 2 2 1 1 1 3 3 2", "3\n1 1 1 2 2 2 3 3 3\n2 1 1 1 2 2 3 3 3", "3\n1 1 1 2 2 2 3 3 3\n1 1 1 2 3 2 3 3 2", "3\n2 3 3 1 2 1 2 1 3\n3 2 1 2 1 1 3 3 2", "3\n2 3 1 1 3 2 2 1 3\n1 2 1 3 1 2 3 2 3", "3\n3 3 1 1 3 2 2 1 2\n1 1 2 3 2 2 3 1 3", "3\n2 3 3 1 1 1 3 2 2\n3 2 2 1 1 1 3 3 2", "3\n1 1... | coding | 538 |
Solve the programming task below in a Python markdown code block.
Read problems statements in [Hindi], [Mandarin Chinese], [Vietnamese], and [Bengali] as well.
You are given a grid with $N$ rows and $M$ columns, where each cell contains either '0' or '1'.
Find out whether all the cells containing '1'-s form a rectan... | {"inputs": ["3\n3 3\n010\n111\n010\n4 4\n0000\n0110\n1110\n1100\n3 3\n011\n011\n000"], "outputs": ["NO\nNO\nYES"]} | coding | 534 |
Solve the programming task below in a Python markdown code block.
Ishank lives in a country in which there are N$N$ cities and N−1$N-1$ roads. All the cities are connected via these roads. Each city has been assigned a unique number from 1 to N$N$. The country can be assumed as a tree, with nodes representing the citie... | {"inputs": ["9 5\n1 2 8\n1 3 -9\n2 4 1\n2 5 -6\n3 6 7\n3 7 6\n6 8 3\n6 9 4\n1 2\n2 7\n4 3\n3 2\n8 9"], "outputs": ["10\n5\n0\n-1\n21"]} | coding | 707 |
Solve the programming task below in a Python markdown code block.
Write a program which reads an integer $S$ [second] and converts it to $h:m:s$ where $h$, $m$, $s$ denote hours, minutes (less than 60) and seconds (less than 60) respectively.
Constraints
* $0 \leq S \leq 86400$
Input
An integer $S$ is given in a li... | {"inputs": ["8", "6", "4", "2", "1", "3", "9", "0"], "outputs": ["0:0:8\n", "0:0:6\n", "0:0:4\n", "0:0:2\n", "0:0:1\n", "0:0:3\n", "0:0:9\n", "0:0:0\n"]} | coding | 154 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
A truck has two fuel tanks. You are given two integers, mainTank representing the fuel present in the main tank in liters and additionalTank representing the fuel present in the additional tank in liters.
The truck ha... | {"functional": "def check(candidate):\n assert candidate(mainTank = 5, additionalTank = 10) == 60\n assert candidate(mainTank = 1, additionalTank = 2) == 10\n\n\ncheck(Solution().distanceTraveled)"} | coding | 184 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given an integer array nums. The value of this array is defined as the sum of |nums[i] - nums[i + 1]| for all 0 <= i < nums.length - 1.
You are allowed to select any subarray of the given array and reverse it.... | {"functional": "def check(candidate):\n assert candidate(nums = [2,3,1,5,4]) == 10\n assert candidate(nums = [2,4,9,24,2,1,10]) == 68\n\n\ncheck(Solution().maxValueAfterReverse)"} | coding | 125 |
Solve the programming task below in a Python markdown code block.
Chuck has lost count of how many asses he has kicked...
Chuck stopped counting at 100,000 because he prefers to kick things in the face instead of counting. That's just who he is.
To stop having to count like a mere mortal chuck developed his own speci... | {"functional": "_inputs = [['A6C2E5Z9A4.-F%8.08.'], ['PP P6A6T5F5S3.-Z%1.11.hgr'], ['A6A1E3A8M2.-Q%8.88.'], ['d G8H1E2O9N3.-W%8.56. f'], ['B4A1D1I8B4.-E%8.76.'], ['ffr65A C8K4D9U7V5.-Y%8.00.'], [' 76 B2L4D0A8C6.-T%8.90. lkd'], ['B2L4D0A8C6.-T%8.90'], ['B2L4D0AFC6.-T%8.90.'], ['B4A1D1I8B4'], ['B4A6666...'], ['... | coding | 437 |
Solve the programming task below in a Python markdown code block.
Today is Wednesday, the third day of the week. What's more interesting is that tomorrow is the last day of the year 2015.
Limak is a little polar bear. He enjoyed this year a lot. Now, he is so eager to the coming year 2016.
Limak wants to prove how re... | {"inputs": ["4 of week\n", "6 of week\n", "1 of week\n", "2 of week\n", "3 of week\n", "5 of week\n", "7 of week\n", "6 of week\n"], "outputs": ["52\n", "53\n", "52\n", "52\n", "52\n", "53\n", "52\n", "53"]} | coding | 470 |
Solve the programming task below in a Python markdown code block.
Those days, many boys use beautiful girls' photos as avatars in forums. So it is pretty hard to tell the gender of a user at the first glance. Last year, our hero went to a forum and had a nice chat with a beauty (he thought so). After that they talked v... | {"inputs": ["oh\n", "oh\n", "nh\n", "rhh\n", "rhh\n", "hhr\n", "pezu\n", "kmsk\n"], "outputs": ["CHAT WITH HER!\n", "CHAT WITH HER!\n", "CHAT WITH HER!\n", "CHAT WITH HER!\n", "CHAT WITH HER!\n", "CHAT WITH HER!\n", "CHAT WITH HER!\n", "IGNORE HIM!\n"]} | coding | 371 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a non-negative floating point number rounded to two decimal places celsius, that denotes the temperature in Celsius.
You should convert Celsius into Kelvin and Fahrenheit and return it as an array ans = ... | {"functional": "def check(candidate):\n assert candidate(celsius = 36.50) == [309.65000,97.70000]\n assert candidate(celsius = 122.11) == [395.26000,251.79800]\n\n\ncheck(Solution().convertTemperature)"} | coding | 150 |
Solve the programming task below in a Python markdown code block.
Given is a string S. Each character in S is either a digit (0, ..., 9) or ?.
Among the integers obtained by replacing each occurrence of ? with a digit, how many have a remainder of 5 when divided by 13? An integer may begin with 0.
Since the answer can ... | {"inputs": ["?\n", "5\n", "3\n", "??\n", "74?", "54?", "64?", "?46"], "outputs": ["1\n", "1\n", "0\n", "8\n", "1\n", "0\n", "1\n", "1\n"]} | coding | 217 |
Solve the programming task below in a Python markdown code block.
Jon Snow is on the lookout for some orbs required to defeat the white walkers. There are k different types of orbs and he needs at least one of each. One orb spawns daily at the base of a Weirwood tree north of the wall. The probability of this orb being... | {"inputs": ["1 1\n1\n", "1 1\n1\n", "2 2\n1\n2\n", "2 2\n1\n4\n", "1 2\n1\n4\n", "2 2\n1\n2\n", "1 1\n1000\n", "1 1\n1000\n"], "outputs": ["1\n", "1\n", "2\n2\n", "2\n2\n", "1\n1\n", "2\n2\n", "1\n", "1\n"]} | coding | 315 |
Solve the programming task below in a Python markdown code block.
Ito joined the Kyudo club after entering high school. At first, I had a hard time because the arrow didn't reach the target, but in the fall of my first year of high school, I managed to improve to the point where the arrow reached the target.
One day, ... | {"inputs": ["20\n4\n6\n2\n1\n3\n8\n2\n0\n0", "20\n4\n6\n2\n1\n0\n8\n2\n0\n0", "20\n4\n6\n2\n1\n1\n8\n2\n0\n0", "20\n4\n3\n4\n1\n3\n8\n2\n0\n0", "20\n4\n6\n2\n2\n3\n8\n2\n0\n0", "20\n4\n6\n2\n1\n0\n8\n2\n1\n0", "20\n4\n3\n0\n1\n3\n8\n2\n0\n0", "20\n8\n6\n2\n2\n3\n8\n2\n0\n0"], "outputs": ["16\n2\n", "13\n2\n", "14\n2\n"... | coding | 362 |
Solve the programming task below in a Python markdown code block.
Ma5termind is going through the Euler's book of knowledge when he finds the following function:
def function(L,R):
sum=0
for i in range(L,R+1): #[L,R]
for j in range(1,i+1): #[1,i]
cnt=0
if ... | {"inputs": ["2\n1 10\n2 5\n"], "outputs": ["9\n2\n"]} | coding | 495 |
Solve the programming task below in a Python markdown code block.
# Task
Christmas is coming, and your task is to build a custom Christmas tree with the specified characters and the specified height.
# Inputs:
- `chars`: the specified characters.
- `n`: the specified height. A positive integer greater than 2.
# Out... | {"functional": "_inputs = [['*@o', 3], ['*@o', 6], ['1234', 6], ['123456789', 3]]\n_outputs = [[' *\\n @ o\\n* @ o\\n |'], [' *\\n @ o\\n * @ o\\n * @ o *\\n @ o * @ o\\n* @ o * @ o\\n |\\n |'], [' 1\\n 2 3\\n 4 1 2\\n 3 4 1 2\\n 3 4 1 2 3\\n4 1 2 3 4 1\\n |\\n |'], [' 1\\n 2 3\\n... | coding | 534 |
Solve the programming task below in a Python markdown code block.
In this Kata we are passing a number (n) into a function.
Your code will determine if the number passed is even (or not).
The function needs to return either a true or false.
Numbers may be positive or negative, integers or floats.
Floats are cons... | {"functional": "_inputs = [[0], [0.5], [1], [2], [-4], [15], [20], [220], [222222221], [500000000]]\n_outputs = [[True], [False], [False], [True], [True], [False], [True], [True], [False], [True]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.iscl... | coding | 98 |
Solve the programming task below in a Python markdown code block.
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
Chefina is playing with ranges. There are $N$ ranges $[l_{1}, r_{1}], [l_{2}, r_{2}], \ldots, [l_{N}, r_{N}]$. Chefina wants to divide the ranges int... | {"inputs": ["3\n3\n1 4\n2 6\n5 7\n2\n1 4\n4 6\n2\n3 7\n8 9"], "outputs": ["1\n-1\n0"]} | coding | 623 |
Solve the programming task below in a Python markdown code block.
Dolphin is planning to generate a small amount of a certain chemical substance C.
In order to generate the substance C, he must prepare a solution which is a mixture of two substances A and B in the ratio of M_a:M_b.
He does not have any stock of chemi... | {"inputs": ["0 4 6\n10 2 5", "1 -1 4\n10 3 5", "1 0 20\n8 9 10", "1 -1 4\n10 3 6", "0 1 25\n5 0 10", "0 1 25\n5 0 16", "0 2 25\n5 0 10", "0 4 10\n10 2 5"], "outputs": ["-1\n", "-1\n", "-1\n", "-1\n", "-1\n", "-1\n", "-1\n", "-1\n"]} | coding | 477 |
Solve the programming task below in a Python markdown code block.
You have unlimited number of coins with values $1, 2, \ldots, n$. You want to select some set of coins having the total value of $S$.
It is allowed to have multiple coins with the same value in the set. What is the minimum number of coins required to g... | {"inputs": ["1 2\n", "6 2\n", "5 2\n", "5 11\n", "6 16\n", "5 29\n", "1 30\n", "5 29\n"], "outputs": ["2\n", "1\n", "1\n", "3", "3", "6", "30", "6\n"]} | coding | 328 |
Solve the programming task below in a Python markdown code block.
One day shooshuns found a sequence of n integers, written on a blackboard. The shooshuns can perform one operation with it, the operation consists of two steps:
1. Find the number that goes k-th in the current sequence and add the same number to the e... | {"inputs": ["1 1\n1\n", "2 1\n1 1\n", "2 1\n2 1\n", "2 1\n1 2\n", "3 2\n3 1 0\n", "3 2\n2 1 0\n", "3 2\n3 1 1\n", "3 1\n3 1 1\n"], "outputs": ["0\n", "0\n", "-1\n", "-1\n", "-1\n", "-1\n", "1\n", "-1\n"]} | coding | 333 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an integer array nums, in which exactly two elements appear only once and all the other elements appear exactly twice. Find the two elements that appear only once. You can return the answer in any order.
You mus... | {"functional": "def check(candidate):\n assert candidate(nums = [1,2,1,3,2,5]) == [3,5]\n assert candidate(nums = [-1,0]) == [-1,0]\n assert candidate(nums = [0,1]) == [1,0]\n\n\ncheck(Solution().singleNumber)"} | coding | 110 |
Solve the programming task below in a Python markdown code block.
MKnez wants to construct an array $s_1,s_2, \ldots , s_n$ satisfying the following conditions:
Each element is an integer number different from $0$;
For each pair of adjacent elements their sum is equal to the sum of the whole array.
More formally, $s... | {"inputs": ["2\n2\n3\n", "100\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3\n3... | coding | 676 |
Solve the programming task below in a Python markdown code block.
A ball will bounce along a number line, making N + 1 bounces. It will make the first bounce at coordinate D_1 = 0, and the i-th bounce (2 \leq i \leq N+1) at coordinate D_i = D_{i-1} + L_{i-1}.
How many times will the ball make a bounce where the coordin... | {"inputs": ["3 6\n3 1 5", "2 6\n3 4 5", "3 6\n6 1 5", "1 6\n3 4 5", "3 6\n7 1 5", "3 6\n3 4 5", "3 6\n3 4 5\n", "4 9\n3 6 3 3"], "outputs": ["3\n", "2\n", "2\n", "2\n", "1\n", "2", "2\n", "3\n"]} | coding | 266 |
Solve the programming task below in a Python markdown code block.
Takahashi has N balls. Initially, an integer A_i is written on the i-th ball.
He would like to rewrite the integer on some balls so that there are at most K different integers written on the N balls.
Find the minimum number of balls that Takahashi needs ... | {"inputs": ["4 4\n1 1 2 2\n", "5 2\n1 1 2 2 5\n", "10 3\n5 1 3 2 4 1 1 2 3 4\n"], "outputs": ["0\n", "1\n", "3\n"]} | coding | 263 |
Solve the programming task below in a Python markdown code block.
Implement a function which takes a string, and returns its hash value.
Algorithm steps:
* `a` := sum of the ascii values of the input characters
* `b` := sum of every difference between the consecutive characters of the input (second char minus first c... | {"functional": "_inputs = [['int main(int argc, char *argv[]) { return 0; }'], [\" Yo - What's Good?! \"], [' df af asd '], ['global hash'], ['section .text'], ['hash:'], [' xor eax, eax'], [' ret'], ['; -----> end of hash <-----'], ['int hash(const char *str);'], [''], [' '], [' '], [' '], [' ']]\n_outputs... | coding | 226 |
Solve the programming task below in a Python markdown code block.
There are N towns in the State of Atcoder, connected by M bidirectional roads.
The i-th road connects Town A_i and B_i and has a length of C_i.
Joisino is visiting R towns in the state, r_1,r_2,..,r_R (not necessarily in this order).
She will fly to the ... | {"inputs": ["5 3 2\n1 3\n2 3 2\n1 3 6\n1 2 2", "5 3 2\n1 3\n2 3 2\n1 3 6\n1 1 2", "3 3 2\n1 3\n2 3 0\n0 3 6\n1 2 2", "6 3 2\n1 3\n2 3 2\n1 3 9\n0 1 2", "6 3 2\n1 4\n4 3 2\n1 3 9\n0 1 2", "5 3 2\n2 2\n2 3 0\n1 5 8\n1 2 2", "6 3 2\n1 3\n2 3 2\n1 3 6\n1 1 2", "6 3 2\n1 3\n2 3 2\n1 3 7\n1 1 2"], "outputs": ["4\n", "6\n", "... | coding | 425 |
Solve the programming task below in a Python markdown code block.
You wrote down all integers from $0$ to $10^n - 1$, padding them with leading zeroes so their lengths are exactly $n$. For example, if $n = 3$ then you wrote out 000, 001, ..., 998, 999.
A block in an integer $x$ is a consecutive segment of equal digits... | {"inputs": ["1\n", "2\n", "3\n", "4\n", "5\n", "6\n", "7\n", "8\n"], "outputs": ["10\n", "180 10\n", "2610 180 10\n", "34200 2610 180 10\n", "423000 34200 2610 180 10\n", "5040000 423000 34200 2610 180 10\n", "58500000 5040000 423000 34200 2610 180 10\n", "666000000 58500000 5040000 423000 34200 2610 180 10\n"]} | coding | 313 |
Solve the programming task below in a Python markdown code block.
Given a sequence of items and a specific item in that sequence, return the item immediately following the item specified. If the item occurs more than once in a sequence, return the item after the first occurence. This should work for a sequence of any t... | {"functional": "_inputs = [[[1, 2, 3, 4, 5, 6, 7, 8], 3], [['a', 'b', 'c'], 'd'], [['a', 'b', 'c'], 'c'], ['testing', 't'], ['Hello!', 'o'], ['Hello!', '!'], ['Hello!', 'x']]\n_outputs = [[4], [None], [None], ['e'], ['!'], [None], [None]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isins... | coding | 180 |
Solve the programming task below in a Python markdown code block.
Given an integer $n$, find the maximum value of integer $k$ such that the following condition holds:
$n$ & ($n-1$) & ($n-2$) & ($n-3$) & ... ($k$) = $0$
where & denotes the bitwise AND operation.
-----Input-----
The first line contains a single integ... | {"inputs": ["1\n6\n", "1\n2\n", "1\n7\n", "1\n90\n", "1\n16\n", "1\n52\n", "1\n70\n", "1\n82\n"], "outputs": ["3\n", "1\n", "3\n", "63\n", "15\n", "31\n", "63\n", "63\n"]} | coding | 306 |
Solve the programming task below in a Python markdown code block.
Given an array of integer $a_1, a_2, \ldots, a_n$. In one operation you can make $a_i := a_i + 1$ if $i < n$ and $a_i \leq a_{i + 1}$, or $i = n$ and $a_i \leq a_1$.
You need to check whether the array $a_1, a_2, \ldots, a_n$ can become equal to the arr... | {"inputs": ["1\n5\n4 4 4 4 4\n3 3 3 3 3\n", "1\n2\n10 10\n1000000 1000000\n", "1\n2\n1 1\n1000000000 1000000000\n", "1\n4\n1 1 1 1\n40000000 40000000 40000000 40000000\n", "5\n3\n1 2 5\n1 2 5\n2\n2 2\n1 3\n4\n3 4 1 2\n6 4 2 5\n3\n2 4 1\n4 5 3\n5\n1 2 3 4 5\n6 5 6 7 6\n"], "outputs": ["NO\n", "YES\n", "YES\n", "YES\n", ... | coding | 711 |
Solve the programming task below in a Python markdown code block.
You managed to send your friend to queue for tickets in your stead, but there is a catch: he will get there only if you tell him how much that is going to take. And everybody can only take one ticket at a time, then they go back in the last position of t... | {"functional": "_inputs = [[[2, 5, 3, 6, 4], 0], [[2, 5, 3, 6, 4], 1], [[2, 5, 3, 6, 4], 2], [[2, 5, 3, 6, 4], 3], [[2, 5, 3, 6, 4], 4]]\n_outputs = [[6], [18], [12], [20], [17]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=... | coding | 393 |
Solve the programming task below in a Python markdown code block.
Krishnakant is standing at $(0,0)$ in the Cartesian plane. He wants to go to the point $(x,y)$ in the same plane using only horizontal and vertical moves of $1$ unit. There are many ways of doing this, and he is writing down all such ways. Each way compr... | {"inputs": ["2\n2 2 2\n2 2 3\n"], "outputs": ["HVVH\nVHHV\n"]} | coding | 393 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
On day 1, one person discovers a secret.
You are given an integer delay, which means that each person will share the secret with a new person every day, starting from delay days after discovering the secret. You are a... | {"functional": "def check(candidate):\n assert candidate(n = 6, delay = 2, forget = 4) == 5\n assert candidate(n = 4, delay = 1, forget = 3) == 6\n\n\ncheck(Solution().peopleAwareOfSecret)"} | coding | 183 |
Solve the programming task below in a Python markdown code block.
Petya and Vasya are playing a game. Petya's got n non-transparent glasses, standing in a row. The glasses' positions are indexed with integers from 1 to n from left to right. Note that the positions are indexed but the glasses are not.
First Petya puts ... | {"inputs": ["1 1 1\n1\n", "1 1 1\n1\n", "2 1 2\n1 2\n", "2 1 2\n2 1\n", "2 2 2\n1 2\n", "2 2 2\n2 1\n", "2 1 1\n2 1\n", "2 1 2\n2 1\n"], "outputs": ["0\n", "0\n", "-1\n", "1\n", "0\n", "0\n", "0\n", "1\n"]} | coding | 494 |
Solve the programming task below in a Python markdown code block.
Thor is getting used to the Earth. As a gift Loki gave him a smartphone. There are n applications on this phone. Thor is fascinated by this phone. He has only one minor issue: he can't count the number of unread notifications generated by those applicati... | {"inputs": ["300000 1\n1 86053\n", "300000 1\n2 86053\n", "300000 1\n1 300000\n", "300000 1\n1 300000\n", "3 4\n1 3\n1 1\n1 2\n2 3\n", "4 4\n1 3\n1 1\n1 2\n2 3\n", "4 4\n1 3\n2 1\n1 2\n2 3\n", "4 4\n1 1\n2 1\n1 2\n2 3\n"], "outputs": ["1\n", "0\n", "1\n", "1\n\n", "1\n2\n3\n2\n", "1\n2\n3\n2\n", "1\n1\n2\n1\n", "1\n0\n... | coding | 648 |
Solve the programming task below in a Python markdown code block.
Theater stage is a rectangular field of size n × m. The director gave you the stage's plan which actors will follow. For each cell it is stated in the plan if there would be an actor in this cell or not.
You are to place a spotlight on the stage in some... | {"inputs": ["1 1\n1\n", "1 1\n1\n", "1 1\n0\n", "1 2\n0 1\n", "1 2\n1 0\n", "1 2\n1 1\n", "2 1\n1\n0\n", "2 1\n0\n1\n"], "outputs": ["0\n", "0", "0\n", "1\n", "1\n", "0\n", "1\n", "1\n"]} | coding | 525 |
Solve the programming task below in a Python markdown code block.
This morning, Roman woke up and opened the browser with $n$ opened tabs numbered from $1$ to $n$. There are two kinds of tabs: those with the information required for the test and those with social network sites. Roman decided that there are too many tab... | {"inputs": ["3 2\n1 1 1\n", "3 2\n1 1 1\n", "3 3\n1 1 1\n", "3 2\n1 1 -1\n", "3 2\n1 1 -1\n", "3 3\n1 1 -1\n", "4 2\n1 1 -1 1\n", "4 2\n1 1 1 -1\n"], "outputs": ["2\n", "2\n", "2\n", "1\n", "1\n", "2\n", "2\n", "2\n"]} | coding | 628 |
Solve the programming task below in a Python markdown code block.
How many ways are there to choose two distinct positive integers totaling N, disregarding the order?
Constraints
* 1 \leq N \leq 10^6
* N is an integer.
Input
Input is given from Standard Input in the following format:
N
Output
Print the answer.... | {"inputs": ["3", "5", "0", "1", "8", "9", "4", "-2"], "outputs": ["1\n", "2\n", "-1\n", "0\n", "3\n", "4\n", "1", "-2\n"]} | coding | 104 |
Solve the programming task below in a Python markdown code block.
In this kata you will have to change every letter in a given string to the next letter in the alphabet. You will write a function `nextLetter` to do this. The function will take a single parameter `s` (string).
Examples:
```
"Hello" --> "Ifmmp"
"What ... | {"functional": "_inputs = [['Hello'], ['What is your name?'], ['zOo']]\n_outputs = [['Ifmmp'], ['Xibu jt zpvs obnf?'], ['aPp']]\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, tupl... | coding | 157 |
Solve the programming task below in a Python markdown code block.
Chef recorded a video explaining his favorite recipe. However, the size of the video is too large to upload on the internet. He wants to compress the video so that it has the minimum size possible.
Chef's video has N frames initially. The value of the ... | {"inputs": ["4\n1\n5\n2\n1 1\n3\n1 2 3\n4\n2 1 2 2\n"], "outputs": ["1\n1\n3\n3"]} | coding | 559 |
Solve the programming task below in a Python markdown code block.
Spoonerize... with numbers... numberize?... numboonerize?... noonerize? ...anyway! If you don't yet know what a spoonerism is and haven't yet tried my spoonerism kata, please do [check it out](http://www.codewars.com/kata/spoonerize-me) first.
You will... | {"functional": "_inputs = [[[12, 34]], [[55, 63]], [[357, 579]], [[1000000, 9999999]], [[1000000, 'hello']], [['pippi', 9999999]], [['pippi', 'hello']], [[1, 1]], [[1, 0]], [[0, 1]]]\n_outputs = [[18], [12], [178], [7000001], ['invalid array'], ['invalid array'], ['invalid array'], [0], [1], [1]]\nimport math\ndef _dee... | coding | 259 |
Solve the programming task below in a Python markdown code block.
Write a comparator for a list of phonetic words for the letters of the [greek alphabet](https://en.wikipedia.org/wiki/Greek_alphabet).
A comparator is:
> *a custom comparison function of two arguments (iterable elements) which should return a negative, ... | {"functional": "_inputs = [['chi', 'chi']]\n_outputs = [[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, tuple)):\n if len(a) != len(b): return False\n return all... | coding | 303 |
Solve the programming task below in a Python markdown code block.
Read problem statements in [Bengali], [Russian], [Mandarin] and [Vietnamese] as well.
You are given a binary string S. You can perform the following operations on S:
Flip: Pick an index i (1 ≤ i ≤ |S|) and flip the i-th character (i.e change 1 to 0 or ... | {"inputs": ["3\n100011\n1110011\n000101110\n"], "outputs": ["2\n2\n3\n"]} | coding | 758 |
Solve the programming task below in a Python markdown code block.
We have a tree with N vertices numbered 1 to N. The i-th edge in this tree connects Vertex a_i and b_i.
For each k=1, ..., N, solve the problem below:
- Consider writing a number on each vertex in the tree in the following manner:
- First, write 1 on V... | {"inputs": ["2\n2 1", "2\n1 2", "2\n1 2\n", "3\n2 3\n1 3", "3\n1 2\n2 3", "3\n1 2\n1 3", "3\n1 2\n1 3\n", "5\n1 2\n1 3\n3 4\n3 5"], "outputs": ["1\n1\n", "1\n1", "1\n1\n", "1\n1\n2\n", "1\n2\n1\n", "2\n1\n1", "2\n1\n1\n", "8\n2\n12\n3\n3\n"]} | coding | 387 |
Solve the programming task below in a Python markdown code block.
Let $length(A)$ denote the count of digits of a number $\mbox{A}$ in its decimal representation.
John is looking for new methods of determining which numbers are strange all day long.
All non-negative numbers of length 1 are strange. Further, a numbe... | {"inputs": ["5\n7 25\n45 50\n1 100\n99 103\n0 1000000\n"], "outputs": ["10\n1\n26\n0\n96\n"]} | coding | 387 |
Solve the programming task below in a Python markdown code block.
Given N and M Dexter wants to know how many pairs a,b(1 ≤ a < b ≤N) are there such that (a+b) is divisible by M.
For example when N=4 and M=3, there are 2 possible pairs the sum of which is divisible by M and they are (1,2) and (2,4).
------ Input ----... | {"inputs": ["3\n2 3\n4 3\n1 6"], "outputs": ["1\n2\n0"]} | coding | 205 |
Solve the programming task below in a Python markdown code block.
Read problems statements in Mandarin Chinese and Russian.
Devu is learning Combinatorics in his college. He find it very interesting to calculate number of ways of going to point (c,d) from point (a,b) in co-ordinate plane. We can take horizontal and ... | {"inputs": ["2\n2 2\n4 5"], "outputs": ["8\n236"]} | coding | 520 |
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 maximum sum of a non-empty subsequence of that array such that for every two consecutive integers in the subsequence, nums[i] and nums[j], where i < j, the cond... | {"functional": "def check(candidate):\n assert candidate(nums = [10,2,-10,5,20], k = 2) == 37\n assert candidate(nums = [-1,-2,-3], k = 1) == -1\n assert candidate(nums = [10,-2,-10,-5,20], k = 2) == 23\n\n\ncheck(Solution().constrainedSubsetSum)"} | coding | 142 |
Solve the programming task below in a Python markdown code block.
There is BMI (Body Mass Index) as an index showing the degree of obesity. The BMI value is calculated using the following formula.
BMI = weight (kg) / (height (m)) 2
The closer the BMI value is to the standard value, the more "ideal body shape" is cons... | {"inputs": ["6\n4 179 10\n0 657 0\n4 24 36\n11 2 75\n1 13 111\n10 336 74\n3\n2 15 4\n-1 76 6\n2 139 34\n0", "6\n4 216 10\n0 657 0\n4 24 36\n11 2 68\n1 13 011\n10 336 74\n3\n2 15 4\n0 76 12\n1 139 34\n0", "6\n2 58 11\n1 178 30\n3 78 72\n4 42 65\n7 101 62\n6 47 50\n3\n-1 147 129\n1 3 14\n0 80 24\n0", "6\n2 32 66\n1 178 1... | coding | 441 |
Solve the programming task below in a Python markdown code block.
A string is called bracket sequence if it does not contain any characters other than "(" and ")". A bracket sequence is called regular if it it is possible to obtain correct arithmetic expression by inserting characters "+" and "1" into this sequence. Fo... | {"inputs": ["3\n1\n4\n3\n", "0\n0\n0\n0\n", "1\n2\n3\n4\n", "0\n0\n1\n0\n", "4\n3\n2\n1\n", "1\n2\n2\n1\n", "2\n0\n2\n0\n", "1\n0\n1\n1\n"], "outputs": ["1\n", "1\n", "0\n", "0\n", "0\n", "1\n", "0\n", "1\n"]} | coding | 422 |
Solve the programming task below in a Python markdown code block.
A strange grid has been recovered from an old book. It has $5$ columns and infinite number of rows. The bottom row is considered as the first row. First few rows of the grid are like this:
..............
..............
20 22 24 26 28
11 13 15 17 19
... | {"inputs": ["6 3\n"], "outputs": ["25\n"]} | coding | 286 |
Solve the programming task below in a Python markdown code block.
Do you know Just Odd Inventions? The business of this company is to "just odd inventions". Here, it is abbreviated as JOI.
JOI is conducting research to confine many microorganisms in one petri dish alive. There are N microorganisms to be investigated, ... | {"inputs": ["6\n2 8\n1 9\n1 4\n6 2\n6 2\n6 9", "6\n2 8\n1 9\n1 5\n6 2\n6 2\n6 9", "6\n2 0\n0 9\n2 4\n8 0\n6 2\n6 9", "6\n2 8\n2 9\n1 5\n6 2\n6 2\n6 9", "6\n2 0\n0 9\n2 4\n0 0\n6 2\n6 9", "6\n2 8\n5 9\n2 4\n10 4\n6 1\n6 5", "6\n2 8\n5 9\n2 4\n10 4\n6 2\n6 5", "6\n2 8\n5 9\n2 4\n10 4\n6 2\n6 9"], "outputs": ["4\n", "4\n"... | coding | 529 |
Solve the programming task below in a Python markdown code block.
We make a tower by stacking up blocks. The tower consists of several stages and each stage is constructed by connecting blocks horizontally. Each block is of the same weight and is tough enough to withstand the weight equivalent to up to $K$ blocks witho... | {"inputs": ["5 4", "4 8", "6 8", "3 7", "5 7", "5 8", "5 3", "7 4"], "outputs": ["5\n", "4\n", "6\n", "3\n", "5\n", "5\n", "4\n", "6\n"]} | coding | 273 |
Solve the programming task below in a Python markdown code block.
There are n squirrel(s) waiting below the feet of m chestnut tree(s). The first chestnut of the i-th tree will fall right after T_{i} second(s), and one more every P_{i} second(s) after that. The “big mama” of squirrels wants them to bring their nest no ... | {"inputs": ["2\n3 2 5\n5 1 2\n1 2 1\n3 2 5\n5 1 2\n1 1 1"], "outputs": ["4\n3"]} | coding | 642 |
Solve the programming task below in a Python markdown code block.
The [Sharkovsky's Theorem](https://en.wikipedia.org/wiki/Sharkovskii%27s_theorem) involves the following ordering of the natural numbers:
```math
3≺5≺7≺9≺ ...\\
≺2·3≺2·5≺2·7≺2·9≺...\\
≺2^n·3≺2^n·5≺2^n·7≺2^n·9≺...\\
≺2^{(n+1)}·3≺2^{(n+1)}·5≺2^{(n+1)}·7≺2^... | {"functional": "_inputs = [[18, 12], [3, 9], [10, 16], [1, 22], [32, 1024], [17, 17]]\n_outputs = [[True], [True], [True], [False], [False], [False]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isi... | coding | 250 |
Solve the programming task below in a Python markdown code block.
Auction
square1001 You were watching a certain auction.
An auction is a transaction in which when there are a large number of buyers and the number of items is limited, the one with the highest price is given the right to buy. (From the 7th edition of ... | {"inputs": ["5\n8 6 9 1 0", "5\n0 6 9 1 0", "5\n1 1 1 1 0", "5\n0 1 1 2 4", "5\n0 6 6 1 0", "5\n0 5 6 1 0", "5\n0 5 6 2 0", "5\n0 5 6 3 0"], "outputs": ["4\n5\n", "3\n5\n", "5\n5\n", "2\n5\n", "4\n5\n", "3\n5\n", "3\n5\n", "3\n5\n"]} | coding | 577 |
Solve the programming task below in a Python markdown code block.
Takahashi has come to an integer shop to buy an integer.
The shop sells the integers from 1 through 10^9. The integer N is sold for A \times N + B \times d(N) yen (the currency of Japan), where d(N) is the number of digits in the decimal notation of N.
F... | {"inputs": ["10 7 100\n", "2 1 100000000000\n", "1234 56789 314159265\n", "5 826766933 11100722310\n", "18 395432867 10840610026\n", "1000000000 1000000000 100\n", "384836991 191890310 91047313\n", "782177068 404011431 1793399970\n"], "outputs": ["9\n", "1000000000\n", "254309\n", "731963982\n", "404539679\n", "0\n", "... | coding | 373 |
Solve the programming task below in a Python markdown code block.
You are given $n$ integers $w_i (i = 0, 1, ..., n-1)$ to be sorted in ascending order. You can swap two integers $w_i$ and $w_j$. Each swap operation has a cost, which is the sum of the two integers $w_i + w_j$. You can perform the operations any number ... | {"inputs": ["4\n8 3 2 1", "4\n3 5 2 1", "4\n4 0 2 1", "4\n0 3 2 1", "4\n4 5 2 1", "4\n6 5 2 1", "4\n4 3 1 2", "4\n6 7 2 1"], "outputs": ["14\n", "13\n", "5\n", "4\n", "14\n", "14\n", "12\n", "18\n"]} | coding | 247 |
Solve the programming task below in a Python markdown code block.
Create a program that will take in a string as input and, if there are duplicates of more than two alphabetical characters in the string, returns the string with all the extra characters in a bracket.
For example, the input "aaaabbcdefffffffg" should re... | {"functional": "_inputs = [['aaaabbcdefffffffg'], [3], ['boopdedoop'], ['helloookat'], [True], [''], ['aAAabbcdeffFfFffg'], ['aAAabbcdeFFFffffg'], [{}], [[5.3]]]\n_outputs = [['aa[aa]bbcdeff[fffff]g'], ['Please enter a valid string'], ['boopdedoop'], ['helloo[o]kat'], ['Please enter a valid string'], [''], ['aAAabbcdef... | coding | 128 |
Solve the programming task below in a Python markdown code block.
There is a card game called "Durak", which means "Fool" in Russian. The game is quite popular in the countries that used to form USSR. The problem does not state all the game's rules explicitly — you can find them later yourselves if you want.
To play d... | {"inputs": ["H\nQD KD\n", "D\n9S 8S\n", "H\nTH 8H\n", "D\nAC KS\n", "H\nAH KH\n", "H\nAD KD\n", "D\n8S 6C\n", "H\nAC QC\n"], "outputs": ["NO\n", "YES\n", "YES\n", "NO\n", "YES\n", "YES\n", "NO\n", "YES\n"]} | coding | 443 |
Solve the programming task below in a Python markdown code block.
There are 3 hidden numbers A, B, C.
You somehow found out the values of \min(A, B), \min(B, C), and \min(C, A).
Determine whether there exists any tuple (A, B, C) that satisfies the given values of \min(A, B), \min(B, C), \min(C, A).
------ Input Form... | {"inputs": ["3\n5 5 5\n2 3 4\n2 2 4\n"], "outputs": ["YES\nNO\nYES\n"]} | coding | 369 |
Solve the programming task below in a Python markdown code block.
Write a program that extracts n different numbers from the numbers 0 to 9 and outputs the number of combinations that add up to s. Each n number is from 0 to 9, and the same number cannot be used in one combination. For example, if n is 3 and s is 6, the... | {"inputs": ["3 5\n3 1\n0 0", "3 0\n5 1\n0 0", "1 0\n5 1\n0 0", "3 6\n3 0\n0 0", "2 5\n1 1\n0 0", "2 0\n1 1\n0 0", "3 2\n0 0\n0 0", "2 2\n0 0\n0 0"], "outputs": ["2\n0\n", "0\n0\n", "1\n0\n", "3\n0\n", "3\n1\n", "0\n1\n", "0\n", "1\n"]} | coding | 253 |
Solve the programming task below in a Python markdown code block.
You are given an integer $n$.
Your task is to find two positive (greater than $0$) integers $a$ and $b$ such that $a+b=n$ and the least common multiple (LCM) of $a$ and $b$ is the minimum among all possible values of $a$ and $b$. If there are multiple a... | {"inputs": ["4\n2\n9\n5\n10\n"], "outputs": ["1 1\n3 6\n1 4\n5 5\n"]} | coding | 578 |
Solve the programming task below in a Python markdown code block.
Homer has two friends Alice and Bob. Both of them are string fans.
One day, Alice and Bob decide to play a game on a string $s = s_1 s_2 \dots s_n$ of length $n$ consisting of lowercase English letters. They move in turns alternatively and Alice makes t... | {"inputs": ["1\na\n", "1\na\n", "1\nb\n", "3\na\nbbbb\naz\n", "3\na\nbbbb\nza\n", "3\na\nabbb\nza\n", "3\na\nbbbb\nay\n", "3\na\nabbb\naz\n"], "outputs": ["b\n", "b\n", "a\n", "b\nazaz\nby\n", "b\nazaz\naz\n", "b\nbzaz\naz\n", "b\nazaz\nbz\n", "b\nbzaz\nby\n"]} | coding | 522 |
Solve the programming task below in a Python markdown code block.
For this exercise you will create a global flatten method. The method takes in any number of arguments and flattens them into a single array. If any of the arguments passed in are an array then the individual objects within the array will be flattened so... | {"functional": "_inputs = [[1, 2, 3], [1, 2], [5, 'string'], [-4.5, -3, 1, 4], [[3, 4, 5], [1, 2, 3]], [[1], [], 2, [4, 5, 6]], [[4, 'string', 9, 3, 1], [], [], [], [], ['string']], [1, 2, ['9', [], []], None], [[1, 2], [3, 4, 5], [6, [7], [[8]]]], [['hello', 2, ['text', [4, 5]]], [[]], '[list]']]\n_outputs = [[[1, 2, ... | coding | 226 |
Solve the programming task below in a Python markdown code block.
You are given a sequence of N integer numbers A. Calculate the sum of A_{i} AND A_{j} for all the pairs (i, j) where i < j.
The AND operation is the Bitwise AND operation, defined as in here.
------ Input ------
The first line of input consists of t... | {"inputs": ["5\n1 2 3 4 5", "5\n2 2 3 4 5", "5\n2 2 6 4 5", "5\n0 2 6 4 5", "5\n1 2 5 4 6", "5\n0 2 3 4 5", "5\n2 2 6 6 5", "5\n1 2 8 4 6"], "outputs": ["9", "11\n", "18\n", "14\n", "15\n", "7\n", "24\n", "6\n"]} | coding | 256 |
Solve the programming task below in a Python markdown code block.
Takahashi Lake has a perimeter of L. On the circumference of the lake, there is a residence of the lake's owner, Takahashi. Each point on the circumference of the lake has a coordinate between 0 and L (including 0 but not L), which is the distance from t... | {"inputs": ["5 3\n1\n7\n8", "3 3\n1\n2\n3", "10 3\n1\n7\n8", "0 3\n2\n7\n32", "4 3\n1\n7\n10", "3 3\n2\n6\n63", "3 3\n2\n6\n50", "3 3\n1\n1\n22"], "outputs": ["11\n", "4\n", "16\n", "32\n", "10\n", "63\n", "50\n", "22\n"]} | coding | 470 |
Solve the programming task below in a Python markdown code block.
Codex is about to start and Ram has not done dinner yet. So, he quickly goes to hostel mess and finds a long queue in front of food counter. But somehow he manages to take the food plate and reaches in front of the queue. The plates are divided into sec... | {"inputs": ["19\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n12\n13\n14\n15\n16\n17\n18\n19"], "outputs": ["4\n9\n25\n64\n169\n441\n1156\n3025\n7921\n20736\n54289\n142129\n372100\n974169\n2550409\n6677056\n17480761\n45765225\n119814916"]} | coding | 367 |
Solve the programming task below in a Python markdown code block.
Lena is the most economical girl in Moscow. So, when her dad asks her to buy some food for a trip to the country, she goes to the best store — "PriceFixed". Here are some rules of that store:
The store has an infinite number of items of every product.
... | {"inputs": ["1\n8 2\n", "1\n8 2\n", "1\n8 4\n", "1\n8 1\n", "1\n6 1\n", "1\n4 1\n", "1\n16 1\n", "2\n7 7\n1 4\n"], "outputs": ["10\n", "10\n", "12\n", "9\n", "7\n", "5\n", "17\n", "14\n"]} | coding | 710 |
Solve the programming task below in a Python markdown code block.
After a hard quarter in the office you decide to get some rest on a vacation. So you will book a flight for you and your girlfriend and try to leave all the mess behind you.
You will need a rental car in order for you to get around in your vacation. The... | {"functional": "_inputs = [[1], [2], [3], [4], [5], [6], [7], [8], [9], [10]]\n_outputs = [[40], [80], [100], [140], [180], [220], [230], [270], [310], [350]]\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 ... | coding | 171 |
Solve the programming task below in a Python markdown code block.
There are initially X people in a room.
You are given an array A of length N which describes the following events:
If A_{i} ≥ 0, then A_{i} people enter the room at i-th minute. For e.g. if A_{2} = 3, then 3 people enter the room at the 2-nd minute.
If... | {"inputs": ["3\n5 8\n0 3 3 -13 5\n4 5\n0 -2 2 3\n3 5\n-2 5 -2\n"], "outputs": ["14\n8\n8\n"]} | coding | 572 |
Solve the programming task below in a Python markdown code block.
There is a long plate s containing n digits. Iahub wants to delete some digits (possibly none, but he is not allowed to delete all the digits) to form his "magic number" on the plate, a number that is divisible by 5. Note that, the resulting number may c... | {"inputs": ["14\n2\n", "14\n3\n", "555\n2\n", "555\n4\n", "555\n6\n", "555\n9\n", "14\n66\n", "14\n95\n"], "outputs": ["0\n", "0\n", "63\n", "4095\n", "262143\n", "134217727\n", "0\n", "0\n"]} | coding | 405 |
Solve the programming task below in a Python markdown code block.
Mary loves binary strings.
Given a binary string S, she defines the *beauty* of the string as the [bitwise XOR] of decimal representations of all substrings of S.
Find the *beauty* of string S. Since the answer can be huge, print it modulo 998244353.
... | {"inputs": ["3\n2\n10\n3\n101\n4\n1111"], "outputs": ["3\n6\n12\n"]} | coding | 765 |
Solve the programming task below in a Python markdown code block.
For two positive integers a and b, let g(a, b) = [gcd]
(a, b) + [lcm](a, b).
For a positive integer N, let f(N) denote the minimum value of g(a, b) over all the pairs of positive integers (a, b) such that a+b = N.
Find out the number of ordered pairs ... | {"inputs": ["2\n4\n105"], "outputs": ["3\n14\n"]} | coding | 422 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given the root of a binary search tree and the lowest and highest boundaries as low and high, trim the tree so that all its elements lies in [low, high]. Trimming the tree should not change the relative structure of t... | {"functional": "def check(candidate):\n assert is_same_tree(candidate(root = tree_node([1,0,2]), low = 1, high = 2), tree_node([1,None,2]))\n assert is_same_tree(candidate(root = tree_node([3,0,4,None,2,None,None,1]), low = 1, high = 3), tree_node([3,2,None,1]))\n\n\ncheck(Solution().trimBST)"} | coding | 209 |
Solve the programming task below in a Python markdown code block.
# Do you ever wish you could talk like Siegfried of KAOS ?
## YES, of course you do!
https://en.wikipedia.org/wiki/Get_Smart
# Task
Write the function ```siegfried``` to replace the letters of a given sentence.
Apply the rules using the course not... | {"functional": "_inputs = [[1, 'City civilians'], [1, 'Centre receiver'], [1, 'Chatanooga choo choo crashed'], [1, 'Capital city cats chew cheese'], [2, 'Photo of 5 pheasants with graphs'], [3, 'Meet me at the same place at noon'], [3, 'The time is now'], [3, 'Be quite quiet'], [3, 'Aardvarks are nice most of the time'... | coding | 389 |
Solve the programming task below in a Python markdown code block.
We have N logs of lengths A_1,A_2,\cdots A_N.
We can cut these logs at most K times in total. When a log of length L is cut at a point whose distance from an end of the log is t (0<t<L), it becomes two logs of lengths t and L-t.
Find the shortest possibl... | {"inputs": ["2 6\n7 9", "2 6\n1 9", "2 6\n1 6", "4 1\n7 9", "2 0\n4 9", "2 0\n1 8", "2 3\n7 9", "2 3\n7 9\n"], "outputs": ["3\n", "2\n", "1\n", "7\n", "9\n", "8\n", "4", "4\n"]} | coding | 389 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
We are playing the Guessing Game. The game will work as follows:
I pick a number between 1 and n.
You guess a number.
If you guess the right number, you win the game.
If you guess the wrong number, then I will tell y... | {"functional": "def check(candidate):\n assert candidate(n = 10) == 16\n assert candidate(n = 1) == 0\n assert candidate(n = 2) == 1\n\n\ncheck(Solution().getMoneyAmount)"} | coding | 180 |
Solve the programming task below in a Python markdown code block.
A football league of N teams is taking place, where each team plays other teams once in [single round robin] fashion. A team gets 3 points for winning a game and 0 for losing (assume that no games end in a draw/tie). What is the maximum possible differen... | {"inputs": ["4\n2\n3\n4\n9"], "outputs": ["3\n3\n6\n12"]} | coding | 435 |
Solve the programming task below in a Python markdown code block.
This is the easy version of the problem. The difference between the versions is in the constraints on the array elements. You can make hacks only if all versions of the problem are solved.
You are given an array [a_1, a_2, ..., a_n].
Your goal is to f... | {"inputs": ["1\n1\n", "7\n1 2 3 3 3 2 1\n", "7\n2 2 3 3 3 2 1\n", "7\n2 4 3 3 3 2 1\n", "7\n1 1 4 4 3 4 3\n", "7\n1 1 2 2 3 4 3\n", "7\n1 1 4 2 3 4 3\n", "7\n2 4 6 3 3 2 1\n"], "outputs": ["0\n", "3\n", "7\n", "3\n", "5\n", "7\n", "7\n", "7\n"]} | coding | 431 |
Solve the programming task below in a Python markdown code block.
Valera is a little boy. Yesterday he got a huge Math hometask at school, so Valera didn't have enough time to properly learn the English alphabet for his English lesson. Unfortunately, the English teacher decided to have a test on alphabet today. At the ... | {"inputs": ["3\nwsw\nsws\nwsw\n", "3\nxpx\npxp\nxpe\n", "3\naaa\naaa\naaa\n", "3\naca\noec\nzba\n", "3\nxxx\naxa\nxax\n", "3\nxax\naxx\nxax\n", "3\nxax\naxa\nxxx\n", "3\nxax\nxxa\nxax\n"], "outputs": ["YES\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n"]} | coding | 347 |
Solve the programming task below in a Python markdown code block.
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well.
In Chefland, each person has their own non-empty personal string. When two people with personal strings $T_{1}$ and $T_{2}$ (possibly identical) bec... | {"inputs": ["3\nabcd\naaaa\nababcdccdc"], "outputs": ["0\n1\n1"]} | coding | 501 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given an array of points in the X-Y plane points where points[i] = [xi, yi].
Return the minimum area of a rectangle formed from these points, with sides parallel to the X and Y axes. If there is not any such r... | {"functional": "def check(candidate):\n assert candidate([[1,1],[1,3],[3,1],[3,3],[2,2]]) == 4\n assert candidate([[1,1],[1,3],[3,1],[3,3],[4,1],[4,3]]) == 2\n\n\ncheck(Solution().minAreaRect)"} | coding | 107 |
Solve the programming task below in a Python markdown code block.
Today, Marin is at a cosplay exhibition and is preparing for a group photoshoot!
For the group picture, the cosplayers form a horizontal line. A group picture is considered beautiful if for every contiguous segment of at least $2$ cosplayers, the number... | {"inputs": ["9\n3\n000\n3\n001\n3\n010\n3\n011\n3\n100\n3\n101\n3\n110\n3\n111\n19\n1010110000100000101\n"], "outputs": ["4\n2\n1\n0\n2\n0\n0\n0\n17\n"]} | coding | 568 |
Solve the programming task below in a Python markdown code block.
Given an array of integers.
Return an array, where the first element is the count of positives numbers and the second element is sum of negative numbers.
If the input array is empty or null, return an empty array.
# Example
For input `[1, 2, 3, 4, 5,... | {"functional": "_inputs = [[[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, -11, -12, -13, -14, -15]], [[0, 2, 3, 0, 5, 6, 7, 8, 9, 10, -11, -12, -13, -14]], [[1]], [[-1]], [[0, 0, 0, 0, 0, 0, 0, 0, 0]], [[]]]\n_outputs = [[[10, -65]], [[8, -50]], [[1, 0]], [[0, -1]], [[0, 0]], [[]]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if... | coding | 151 |
Solve the programming task below in a Python markdown code block.
Given an array (or list or vector) of arrays (or, guess what, lists or vectors) of integers, your goal is to return the sum of a specific set of numbers, starting with elements whose position is equal to the main array length and going down by one at eac... | {"functional": "_inputs = [[[[3, 2, 1, 0], [4, 6, 5, 3, 2], [9, 8, 7, 4]]], [[[3], [4, 6, 5, 3, 2], [9, 8, 7, 4]]], [[[3, 2, 1, 0], [4, 6, 5, 3, 2], []]], [[[3, 2, 1, 0], [4, 6, 5, 3, 2], []], 5], [[[3, 2], [4], []]]]\n_outputs = [[16], [15], [7], [12], [0]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstanc... | coding | 297 |
Solve the programming task below in a Python markdown code block.
Write a function that will check whether the permutation of an input string is a palindrome. Bonus points for a solution that is efficient and/or that uses _only_ built-in language functions. Deem yourself **brilliant** if you can come up with a version ... | {"functional": "_inputs = [['a'], ['aa'], ['baa'], ['aab'], ['baabcd'], ['racecars'], ['abcdefghba'], ['']]\n_outputs = [[True], [True], [True], [True], [False], [False], [False], [True]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b,... | coding | 172 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
A company is planning to interview 2n people. Given the array costs where costs[i] = [aCosti, bCosti], the cost of flying the ith person to city a is aCosti, and the cost of flying the ith person to city b is bCosti.
... | {"functional": "def check(candidate):\n assert candidate(costs = [[10,20],[30,200],[400,50],[30,20]]) == 110\n assert candidate(costs = [[259,770],[448,54],[926,667],[184,139],[840,118],[577,469]]) == 1859\n assert candidate(costs = [[515,563],[451,713],[537,709],[343,819],[855,779],[457,60],[650,359],[631,42]... | coding | 134 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.