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.
Mr. Wire Less is not that good at implementing circuit in a breadboard. In his Digital Logic Design course, he has to implement several boolean functions using the breadboard. In a breadboard, inputs are given through the switches and outputs are taken t... | {"inputs": ["2\n1\n2\n\n"], "outputs": ["Case 1: 1\nCase 2: 3"]} | coding | 537 |
Solve the programming task below in a Python markdown code block.
Rachel has some candies and she decided to distribute them among $N$ kids. The ith kid receives $A_i$ candies. The kids are happy iff the difference between the highest and lowest number of candies received is less than $X$.
Find out if the children are ... | {"inputs": ["2\n5 6\n3 5 6 8 1\n3 10\n5 2 9"], "outputs": ["NO\nYES"]} | coding | 295 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an integer array nums, return the greatest common divisor of the smallest number and largest number in nums.
The greatest common divisor of two numbers is the largest positive integer that evenly divides both nu... | {"functional": "def check(candidate):\n assert candidate(nums = [2,5,6,9,10]) == 2\n assert candidate(nums = [7,5,6,8,3]) == 1\n assert candidate(nums = [3,3]) == 3\n\n\ncheck(Solution().findGCD)"} | coding | 88 |
Solve the programming task below in a Python markdown code block.
Read problems statements in mandarin chinese, russian and vietnamese as well.
You are given 2 arrays W = (W_{1}, W_{2}, .., W_{N}) and C = (C_{1}, C_{2}, .., C_{N}) with N elements each. A range [l, r] is unique if all the elements C_{l}, C_{l+1}, ..... | {"inputs": ["1\n5\n0 1 2 0 2\n5 6 7 8 2"], "outputs": ["21"]} | coding | 508 |
Solve the programming task below in a Python markdown code block.
Very soon there will be a parade of victory over alien invaders in Berland. Unfortunately, all soldiers died in the war and now the army consists of entirely new recruits, many of whom do not even know from which leg they should begin to march. The civil... | {"inputs": ["1\n654 61\n", "2\n6 5\n5 6\n", "1\n139 252\n", "1\n139 252\n", "1\n139 361\n", "1\n220 361\n", "1\n340 361\n", "1\n654 361\n"], "outputs": ["0", "1\n", "0\n", "0\n", "0", "0", "0", "0"]} | coding | 744 |
Solve the programming task below in a Python markdown code block.
Your algorithm is so good at predicting the market that you now know what the share price of Mahindra & Mahindra. (M&M) will be for the next N days.
Each day, you can either buy one share of M&M, sell any number of shares of M&M that you own, or not mak... | {"inputs": ["3\n3\n5 3 2\n3\n1 2 100\n4\n1 3 1 2"], "outputs": ["0\n197\n3"]} | coding | 341 |
Solve the programming task below in a Python markdown code block.
Toad Ivan has $m$ pairs of integers, each integer is between $1$ and $n$, inclusive. The pairs are $(a_1, b_1), (a_2, b_2), \ldots, (a_m, b_m)$.
He asks you to check if there exist two integers $x$ and $y$ ($1 \leq x < y \leq n$) such that in each give... | {"inputs": ["2 1\n1 2\n", "4 1\n1 2\n", "4 1\n1 2\n", "2 1\n1 2\n", "8 1\n1 2\n", "4 2\n1 2\n3 4\n", "4 2\n1 2\n2 3\n", "4 2\n1 2\n2 3\n"], "outputs": ["YES\n", "YES\n", "YES", "YES", "YES\n", "YES\n", "YES\n", "YES"]} | coding | 519 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an integer n and an integer array rounds. We have a circular track which consists of n sectors labeled from 1 to n. A marathon will be held on this track, the marathon consists of m rounds. The ith round starts ... | {"functional": "def check(candidate):\n assert candidate(n = 4, rounds = [1,3,1,2]) == [1,2]\n assert candidate(n = 2, rounds = [2,1,2,1,2,1,2,1,2]) == [2]\n assert candidate(n = 7, rounds = [1,3,5,7]) == [1,2,3,4,5,6,7]\n\n\ncheck(Solution().mostVisited)"} | coding | 174 |
Solve the programming task below in a Python markdown code block.
There are an integer sequence A_1,...,A_N consisting of N terms, and N buttons. When the i-th (1 ≦ i ≦ N) button is pressed, the values of the i terms from the first through the i-th are all incremented by 1.
There is also another integer sequence B_1,.... | {"inputs": ["3\n3 5\n2 2\n9 4", "3\n3 4\n2 2\n9 4", "3\n2 4\n2 1\n9 4", "3\n2 1\n0 1\n8 4", "3\n3 4\n2 3\n9 4", "3\n3 4\n2 1\n9 4", "3\n3 5\n2 7\n9 2", "3\n3 4\n3 3\n9 4"], "outputs": ["7\n", "5\n", "6\n", "0\n", "5\n", "5\n", "7\n", "5\n"]} | coding | 301 |
Solve the programming task below in a Python markdown code block.
This kata requires you to convert minutes (`int`) to hours and minutes in the format `hh:mm` (`string`).
If the input is `0` or negative value, then you should return `"00:00"`
**Hint:** use the modulo operation to solve this challenge. The modulo oper... | {"functional": "_inputs = [[0], [-6], [8], [32], [75], [63], [134], [180], [970], [565757]]\n_outputs = [['00:00'], ['00:00'], ['00:08'], ['00:32'], ['01:15'], ['01:03'], ['02:14'], ['03:00'], ['16:10'], ['9429:17']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n ... | coding | 173 |
Solve the programming task below in a Python markdown code block.
You are given a string $\mbox{S}$.
$\mbox{S}$ contains alphanumeric characters only.
Your task is to sort the string $\mbox{S}$ in the following manner:
All sorted lowercase letters are ahead of uppercase letters.
All sorted uppercase letters are a... | {"inputs": ["Sorting1234\n"], "outputs": ["ginortS1324\n"]} | coding | 150 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a 1-indexed integer array nums of length n.
An element nums[i] of nums is called special if i divides n, i.e. n % i == 0.
Return the sum of the squares of all special elements of nums.
Please complete ... | {"functional": "def check(candidate):\n assert candidate(nums = [1,2,3,4]) == 21\n assert candidate(nums = [2,7,1,19,18,3]) == 63\n\n\ncheck(Solution().sumOfSquares)"} | coding | 103 |
Solve the programming task below in a Python markdown code block.
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well.
Rahul and Rashi are off to the wedding of a close relative. This time they have to travel without their guardians. Rahul got very interested in the arrangement of seats insid... | {"inputs": ["3\n1\n5\n3"], "outputs": ["4LB\n2MB\n6UB"]} | coding | 456 |
Solve the programming task below in a Python markdown code block.
Let's write all the positive integer numbers one after another from $1$ without any delimiters (i.e. as a single string). It will be the infinite sequence starting with 123456789101112131415161718192021222324252627282930313233343536...
Your task is to p... | {"inputs": ["7\n", "1\n", "2\n", "3\n", "4\n", "5\n", "6\n", "8\n"], "outputs": ["7\n", "1\n", "2\n", "3\n", "4\n", "5\n", "6\n", "8\n"]} | coding | 206 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given a string s of zeros and ones, return the maximum score after splitting the string into two non-empty substrings (i.e. left substring and right substring).
The score after splitting a string is the number of zero... | {"functional": "def check(candidate):\n assert candidate(s = \"011101\") == 5 \n assert candidate(s = \"00111\") == 5\n assert candidate(s = \"1111\") == 3\n\n\ncheck(Solution().maxScore)"} | coding | 107 |
Solve the programming task below in a Python markdown code block.
Manasa has a string having N number of A's and 2*N number of B's. She wants to arrange these characters in such a way that in each prefix and in each suffix of the string the number of B's is greater than or equal to the number of A's. Given the value of... | {"inputs": ["2\n1\n2\n"], "outputs": ["1\n4\n"]} | coding | 223 |
Solve the programming task below in a Python markdown code block.
According to rules of the Berland fashion, a jacket should be fastened by all the buttons except only one, but not necessarily it should be the last one. Also if the jacket has only one button, it should be fastened, so the jacket will not swinging open.... | {"inputs": ["1\n1\n", "1\n0\n", "1\n0\n", "1\n1\n", "2\n0 1\n", "2\n1 0\n", "2\n0 0\n", "2\n1 1\n"], "outputs": ["YES\n", "NO\n", "NO\n", "YES\n", "YES\n", "YES\n", "NO\n", "NO\n"]} | coding | 229 |
Solve the programming task below in a Python markdown code block.
**Getting Familiar:**
LEET: (sometimes written as "1337" or "l33t"), also known as eleet or leetspeak, is another alphabet for the English language that is used mostly on the internet. It uses various combinations of ASCII characters to replace Latinate ... | {"functional": "_inputs = [['codewars'], ['kata'], ['kumite'], ['greekleet'], [\"This Kata's Sensei is Divyansh\"], ['Any reviews about CS50'], ['Man is still the most extraordinary computer of all.'], ['I do not fear computers. I fear the lack of them.'], ['Do you also think these quotes are conflicting each other?']]... | coding | 522 |
Solve the programming task below in a Python markdown code block.
The Little Elephant loves sortings.
He has an array a consisting of n integers. Let's number the array elements from 1 to n, then the i-th element will be denoted as ai. The Little Elephant can make one move to choose an arbitrary pair of integers l and... | {"inputs": ["3\n3 1 1\n", "3\n3 0 1\n", "3\n0 2 3\n", "3\n1 0 3\n", "3\n3 0 2\n", "3\n0 0 3\n", "3\n1 0 2\n", "3\n3 2 1\n"], "outputs": ["2\n", "3\n", "0\n", "1\n", "3\n", "0\n", "1\n", "2\n"]} | coding | 491 |
Solve the programming task below in a Python markdown code block.
A hero is on his way to the castle to complete his mission. However, he's been told that the castle is surrounded with a couple of powerful dragons! each dragon takes 2 bullets to be defeated, our hero has no idea how many bullets he should carry.. Assum... | {"functional": "_inputs = [[10, 5], [7, 4], [4, 5], [100, 40], [1500, 751], [0, 1]]\n_outputs = [[True], [False], [False], [True], [False], [False]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isin... | coding | 125 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a 2D integer array intervals where intervals[i] = [starti, endi] represents all the integers from starti to endi inclusively.
A containing set is an array nums where each interval from intervals has at l... | {"functional": "def check(candidate):\n assert candidate(intervals = [[1,3],[3,7],[8,9]]) == 5\n assert candidate(intervals = [[1,3],[1,4],[2,5],[3,5]]) == 3\n assert candidate(intervals = [[1,2],[2,3],[2,4],[4,5]]) == 5\n\n\ncheck(Solution().intersectionSizeTwo)"} | coding | 166 |
Solve the programming task below in a Python markdown code block.
You are given positive integers A and B.
If A is a divisor of B, print A + B; otherwise, print B - A.
-----Constraints-----
- All values in input are integers.
- 1 \leq A \leq B \leq 20
-----Input-----
Input is given from Standard Input in the follow... | {"inputs": ["1 0", "1 2", "4 6", "3 6", "4 4", "5 1", "1 6", "1 1"], "outputs": ["1\n", "3\n", "2\n", "9\n", "8\n", "-4\n", "7\n", "2"]} | coding | 152 |
Solve the programming task below in a Python markdown code block.
A palindrome is a word, phrase, number, or other sequence of characters which reads the same backward as forward. Examples of numerical palindromes are:
2332
110011
54322345
You'll be given 2 numbers as arguments: ```(num,s)```. Write a function whi... | {"functional": "_inputs = [[6, 4], [75, 1], [19, 3], [101, 2], ['ACCDDCCA', 3], [773, '1551'], [-4505, 15]]\n_outputs = [[[11, 22, 33, 44]], [[77]], [[22, 33, 44]], [[101, 111]], ['Not valid'], ['Not valid'], ['Not valid']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float)... | coding | 370 |
Solve the programming task below in a Python markdown code block.
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
You are given $N$ sets of integers $A_{1}, A_{2}, \ldots, A_{N}$. For each valid $i$, let's denote the elements of the set $A_{i}$ by $\{c_{i,1}, c_{... | {"inputs": ["3\n3 1 2 3\n2 1 2\n2 2 3"], "outputs": ["3"]} | coding | 578 |
Solve the programming task below in a Python markdown code block.
Write a program which performs the following operations to a binary search tree $T$ by adding the find operation to A: Binary Search Tree I.
* insert $k$: Insert a node containing $k$ as key into $T$.
* find $k$: Report whether $T$ has a node containin... | {"inputs": ["10\ninsert 30\ninsert 88\ninsert 3\ninsert 2\ninsert 20\nfind 12\ninsert 1\ninsert 24\nfind 2\nprint", "10\ninsert 30\ninsert 88\ninsert 3\ninsert 2\ninsert 20\nfind 12\ninsert 1\ninsert 24\nfind 16\nprint", "10\ninsert 30\ninsert 88\ninsert 12\ninsert 2\ninsert 20\nfind 8\ninsert 1\ninsert 24\nfind 16\npr... | coding | 413 |
Solve the programming task below in a Python markdown code block.
You are given n integers a_1, a_2, ..., a_{n}. Find the number of pairs of indexes i, j (i < j) that a_{i} + a_{j} is a power of 2 (i. e. some integer x exists so that a_{i} + a_{j} = 2^{x}).
-----Input-----
The first line contains the single positive... | {"inputs": ["1\n2\n", "1\n2\n", "1\n4\n", "2\n1 1\n", "2\n1 1\n", "3\n1 1 1\n", "3\n1 1 1\n", "4\n7 3 2 1\n"], "outputs": ["0\n", "0\n", "0\n", "1\n", "1\n", "3\n", "3\n", "2\n"]} | coding | 272 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given the root of a binary tree containing digits from 0 to 9 only.
Each root-to-leaf path in the tree represents a number.
For example, the root-to-leaf path 1 -> 2 -> 3 represents the number 123.
Return th... | {"functional": "def check(candidate):\n assert candidate(root = tree_node([1,2,3])) == 25\n assert candidate(root = tree_node([4,9,0,5,1])) == 1026\n\n\ncheck(Solution().sumNumbers)"} | coding | 197 |
Solve the programming task below in a Python markdown code block.
FizzBuzz is a game in which integers of 1 or more are spoken in order according to the following rules.
* "Fizz" when divisible by 3
* "Buzz" when divisible by 5
* "FizzBuzz" when divisible by both 3 and 5
* At other times, that number
An example... | {"inputs": ["8", "2", "4", "3", "6", "5", "7", "9"], "outputs": ["BuzzFizz78FizzBuzz11\n", "2Fizz4BuzzFizz78Fizz\n", "izz4BuzzFizz78FizzBu\n", "Fizz4BuzzFizz78FizzB\n", "z4BuzzFizz78FizzBuzz\n", "zz4BuzzFizz78FizzBuz\n", "4BuzzFizz78FizzBuzz1\n", "uzzFizz78FizzBuzz11F\n"]} | coding | 336 |
Solve the programming task below in a Python markdown code block.
```if-not:sql
Create a function (or write a script in Shell) that takes an integer as an argument and returns "Even" for even numbers or "Odd" for odd numbers.
```
```if:sql
## SQL Notes:
You will be given a table, `numbers`, with one column `number`.
... | {"functional": "_inputs = [[2], [1], [0], [1545452], [7], [78], [17], [74156741], [100000], [-123], [-456]]\n_outputs = [['Even'], ['Odd'], ['Even'], ['Even'], ['Odd'], ['Even'], ['Odd'], ['Odd'], ['Even'], ['Odd'], ['Even']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, floa... | coding | 149 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a 0-indexed integer array stations of length n, where stations[i] represents the number of power stations in the ith city.
Each power station can provide power to every city in a fixed range. In other wo... | {"functional": "def check(candidate):\n assert candidate(stations = [1,2,4,5,0], r = 1, k = 2) == 5\n assert candidate(stations = [4,4,4,4], r = 0, k = 3) == 4\n\n\ncheck(Solution().maxPower)"} | coding | 273 |
Solve the programming task below in a Python markdown code block.
It's another Start[c]up finals, and that means there is pizza to order for the onsite contestants. There are only 2 types of pizza (obviously not, but let's just pretend for the sake of the problem), and all pizzas contain exactly S slices.
It is known ... | {"inputs": ["2 9\n6 1 7\n6 7 1\n", "2 9\n6 1 7\n6 7 1\n", "2 9\n5 1 7\n6 7 1\n", "2 9\n5 1 7\n6 9 1\n", "2 10\n7 2 1\n7 1 2\n", "2 10\n9 1 2\n9 2 1\n", "2 10\n9 1 2\n9 2 1\n", "2 10\n7 2 1\n7 1 2\n"], "outputs": ["84\n", "84\n", "77\n", "89\n", "28\n", "36\n", "36\n", "28\n"]} | coding | 517 |
Solve the programming task below in a Python markdown code block.
Alice has an array A consisting of N distinct integers. Bob takes exactly N - 1 elements from this array and adds a positive integer X (i.e. X > 0) to each of these numbers and then shuffles them to form a new array B of length N - 1.
You are given bot... | {"inputs": ["3\n4\n1 4 3 8\n15 8 11\n2\n4 8\n10\n2\n2 4\n3"], "outputs": ["7\n2\n1"]} | coding | 623 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
The count-and-say sequence is a sequence of digit strings defined by the recursive formula:
countAndSay(1) = "1"
countAndSay(n) is the run-length encoding of countAndSay(n - 1).
Run-length encoding (RLE) is a string... | {"functional": "def check(candidate):\n assert candidate(n = 4) == \"1211\"\n assert candidate(n = 1) == \"1\"\n\n\ncheck(Solution().countAndSay)"} | coding | 235 |
Solve the programming task below in a Python markdown code block.
You are given an infinite 2-d grid with the bottom left cell referenced as (1,1). All the cells contain a value of zero initially. Let's play a game?
The game consists of N steps wherein each step you are given two integers a and b. The value of each ... | {"inputs": ["3\n2 3\n3 7\n4 1\n"], "outputs": ["2\n"]} | coding | 559 |
Solve the programming task below in a Python markdown code block.
# Scenario
**_Several people_** are standing in *a row divided into two teams*.
The **_first person_** goes into **_team 1_**, **_the second_** goes into **_team 2_**, **_the third_** goes into **_team 1_**, and so on.
___
# Task
**_Given_** *an arra... | {"functional": "_inputs = [[[80]], [[100, 50]], [[50, 60, 70, 80]], [[13, 27, 49]], [[70, 58, 75, 34, 91]], [[29, 83, 67, 53, 19, 28, 96]], [[0]], [[100, 51, 50, 100]], [[39, 84, 74, 18, 59, 72, 35, 61]], [[0, 1, 0]]]\n_outputs = [[[80, 0]], [[100, 50]], [[120, 140]], [[62, 27]], [[236, 92]], [[211, 164]], [[0, 0]], [[... | coding | 573 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a 0-indexed integer array nums. In one step, remove all elements nums[i] where nums[i - 1] > nums[i] for all 0 < i < nums.length.
Return the number of steps performed until nums becomes a non-decreasing ... | {"functional": "def check(candidate):\n assert candidate(nums = [5,3,4,4,7,3,6,11,8,5,11]) == 3\n assert candidate(nums = [4,5,7,7,13]) == 0\n\n\ncheck(Solution().totalSteps)"} | coding | 106 |
Solve the programming task below in a Python markdown code block.
problem
AOR Ika is studying to pass the test.
AOR Ika-chan solved the $ N $ question. After that, round the solved problem according to the following procedure.
1. Check the correctness of the answer.
2. If the answer is correct, write a circle mark, ... | {"inputs": ["3\nnxx", "3\nnwx", "3\nxxo", "3\nxwn", "3\nowx", "3\npxx", "3\npyx", "3\npzx"], "outputs": ["2\n", "3\n", "1\n", "3\n", "3\n", "2\n", "3\n", "3\n"]} | coding | 306 |
Solve the programming task below in a Python markdown code block.
Little Dima has two sequences of points with integer coordinates: sequence (a1, 1), (a2, 2), ..., (an, n) and sequence (b1, 1), (b2, 2), ..., (bn, n).
Now Dima wants to count the number of distinct sequences of points of length 2·n that can be assembled... | {"inputs": ["1\n1\n2\n3\n", "1\n1\n3\n3\n", "1\n1\n5\n3\n", "1\n1\n5\n2\n", "1\n1\n2\n7\n", "2\n1 2\n1 2\n4\n", "2\n1 2\n2 2\n4\n", "2\n2 2\n1 2\n4\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "3\n", "3\n"]} | coding | 484 |
Solve the programming task below in a Python markdown code block.
Summer is coming! It's time for Iahub and Iahubina to work out, as they both want to look hot at the beach. The gym where they go is a matrix a with n lines and m columns. Let number a[i][j] represents the calories burned by performing workout at the cel... | {"inputs": ["3 3\n3 1 2\n3 2 0\n2 3 2\n", "3 3\n9 0 9\n0 9 9\n9 9 9\n", "3 3\n9 0 9\n0 2 9\n9 9 9\n", "3 3\n3 1 2\n3 2 0\n1 3 2\n", "3 3\n9 0 9\n0 2 9\n18 9 9\n", "3 3\n9 1 9\n0 2 9\n18 9 9\n", "3 3\n1 10 0\n1 3 1\n1 1 1\n", "3 3\n9 0 9\n0 9 9\n9 9 17\n"], "outputs": ["16\n", "54\n", "54\n", "15\n", "63\n", "64\n", "16... | coding | 553 |
Solve the programming task below in a Python markdown code block.
Mr. E Ven only likes even length words.
Please create a translator so that he doesn't have to hear those pesky odd length words.
For some reason he also hates punctuation, he likes his sentences to flow.
Your translator should take in a string and outpu... | {"functional": "_inputs = [['I got a hole in 1!'], ['tHiS sEnTeNcE iS eVeN.'], ['underscore is not considered a word..in this case,'], ['hi. how are you? Bye!!'], ['lorem is so ipsum. why bother?'], ['_under the seA!']]\n_outputs = [['II gott aa hole in 11'], ['tHiS sEnTeNcE iS eVeN'], ['underscore is nott considered a... | coding | 148 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given a string expression representing an expression of fraction addition and subtraction, return the calculation result in string format.
The final result should be an irreducible fraction. If your final result is an... | {"functional": "def check(candidate):\n assert candidate(expression = \"-1/2+1/2\") == \"0/1\"\n assert candidate(expression = \"-1/2+1/2+1/3\") == \"1/3\"\n assert candidate(expression = \"1/3-1/2\") == \"-1/6\"\n\n\ncheck(Solution().fractionAddition)"} | coding | 118 |
Solve the programming task below in a Python markdown code block.
Implication is a function of two logical arguments, its value is false if and only if the value of the first argument is true and the value of the second argument is false.
Implication is written by using character '$\rightarrow$', and the arguments an... | {"inputs": ["1\n0\n", "1\n1\n", "1\n1\n", "1\n0\n", "2\n1 1\n", "2\n0 0\n", "2\n0 1\n", "2\n1 0\n"], "outputs": ["YES\n0\n", "NO\n", "NO", "YES\n0", "NO\n", "NO\n", "NO\n", "YES\n1->0\n"]} | coding | 724 |
Solve the programming task below in a Python markdown code block.
Not so long ago, Vlad came up with an interesting function:
$f_a(x)=\left\lfloor\frac{x}{a}\right\rfloor + x mod a$, where $\left\lfloor\frac{x}{a}\right\rfloor$ is $\frac{x}{a}$, rounded down, $x mod a$ — the remainder of the integer division of $x$ by... | {"inputs": ["1\n1 100 55\n", "1\n6 999998 9\n", "1\n87 95 696969\n", "3\n1 100 54\n1 100 55\n1 100 56\n", "5\n1 4 3\n5 8 4\n6 10 6\n1 1000000000 1000000000\n10 12 8\n"], "outputs": ["54\n", "111118\n", "95\n", "53\n54\n55\n", "2\n4\n5\n999999999\n5\n"]} | coding | 631 |
Solve the programming task below in a Python markdown code block.
Unicode Transformation Format – 8-bit
As the name suggests UTF-8 was designed to encode data in a stream of bytes.
It works by splitting the bits up in multiples of eight. This is achieved by inserting headers to mark in how many bytes the bits were spl... | {"functional": "_inputs = [['\\x80'], ['\u07ff'], ['\u0800'], ['\\uffff']]\n_outputs = [['1100001010000000'], ['1101111110111111'], ['111000001010000010000000'], ['111011111011111110111111']]\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 | 632 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given the head of a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numbers from the original list. Return the linked list sorted as well.
Please complete the following python... | {"functional": "def check(candidate):\n assert is_same_list(candidate(head = list_node([1,2,3,3,4,4,5])), list_node([1,2,5]))\n assert is_same_list(candidate(head = list_node([1,1,1,2,3])), list_node([2,3]))\n\n\ncheck(Solution().deleteDuplicates)"} | coding | 125 |
Solve the programming task below in a Python markdown code block.
problem
I want to put as many rectangular tiles as possible on a rectangular wall with a size of $ h $ in height and $ w $ in width, and a size of $ a $ in height and $ b $ in width.
The following conditions must be met when attaching tiles.
* Do not... | {"inputs": ["5 8\n3 2", "5 8\n6 2", "6 8\n6 3", "5 8\n1 3", "1 7\n2 6", "5 8\n2 2", "12 8\n6 3", "12 8\n9 3"], "outputs": ["16\n", "40\n", "12\n", "10\n", "7\n", "8", "24\n", "42\n"]} | coding | 189 |
Solve the programming task below in a Python markdown code block.
##Task:
You have to write a function **pattern** which creates the following pattern upto n number of rows.
* If the Argument is 0 or a Negative Integer then it should return "" i.e. empty string.
* If any odd number is passed as argument then the pa... | {"functional": "_inputs = [[2], [1], [5], [6], [0], [-25]]\n_outputs = [['22'], [''], ['22\\n4444'], ['22\\n4444\\n666666'], [''], ['']]\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, (l... | coding | 204 |
Solve the programming task below in a Python markdown code block.
Pashmak has fallen in love with an attractive girl called Parmida since one year ago...
Today, Pashmak set up a meeting with his partner in a romantic garden. Unfortunately, Pashmak has forgotten where the garden is. But he remembers that the garden loo... | {"inputs": ["0 0 0 1\n", "0 0 1 1\n", "0 0 1 2\n", "0 1 2 3\n", "0 1 0 0\n", "1 1 0 0\n", "0 0 1 0\n", "1 0 0 1\n"], "outputs": ["1 0 1 1\n", "0 1 1 0\n", "-1\n", "0 3 2 1\n", "1 1 1 0\n", "1 0 0 1\n", "0 1 1 1\n", "1 1 0 0\n"]} | coding | 385 |
Solve the programming task below in a Python markdown code block.
Read problems statements in Mandarin chinese, Russian and Vietnamese as well.
Chef has two integers $A$ and $B$. He can perform the following operation on $A$ an arbitrary number of times (including zero):
write $A$ as a binary number with an arbitrary... | {"inputs": ["2\n2 4\n1 5"], "outputs": ["2\n1"]} | coding | 388 |
Solve the programming task below in a Python markdown code block.
Kevin and Nicky Sun have invented a new game called Lieges of Legendre. In this game, two players take turns modifying the game state with Kevin moving first. Initially, the game is set up so that there are n piles of cows, with the i-th pile containing ... | {"inputs": ["1 2\n3\n", "1 1\n1\n", "1 2\n1\n", "1 2\n1\n", "1 1\n1\n", "1 0\n1\n", "1 2\n2\n", "1 0\n2\n"], "outputs": ["Nicky\n", "Kevin\n", "Kevin\n", "Kevin\n", "Kevin\n", "Kevin\n", "Kevin\n", "Kevin\n"]} | coding | 414 |
Solve the programming task below in a Python markdown code block.
Alice and Bob are ready to play a new game. Both the players take alternate turns. Alice starts first.
There are N binary numbers written on a blackboard.
Alice, in her turn, erases any 2 numbers from the blackboard and writes the [bitwise OR] of th... | {"inputs": ["3\n5\n1 1 1 1 0\n3\n0 1 0\n4\n0 0 0 0\n"], "outputs": ["1\n0\n0\n"]} | coding | 737 |
Solve the programming task below in a Python markdown code block.
Fibonacci numbers are generated by setting F0 = 0, F1 = 1, and then using the formula:
# Fn = Fn-1 + Fn-2
Your task is to efficiently calculate the **n**th element in the Fibonacci sequence and then count the occurrence of each digit in the number. Ret... | {"functional": "_inputs = [[10]]\n_outputs = [[[[2, 5]]]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) != len(b): return False\n return all(_d... | coding | 334 |
Solve the programming task below in a Python markdown code block.
A and B are preparing themselves for programming contests.
B loves to debug his code. But before he runs the solution and starts debugging, he has to first compile the code.
Initially, the compiler displayed n compilation errors, each of them is repres... | {"inputs": ["3\n1 2 3\n3 2\n2\n", "3\n1 2 3\n3 2\n2\n", "3\n2 2 3\n3 2\n2\n", "3\n2 1 3\n3 2\n2\n", "3\n2 2 3\n3 2\n3\n", "3\n84 7 9\n9 84\n9\n", "3\n84 30 9\n9 84\n9\n", "3\n84 30 9\n9 84\n9\n"], "outputs": ["1\n3\n", "1\n3\n", "2\n3\n", "1\n3\n", "2\n2\n", "7\n84\n", "30\n84\n", "30\n84\n"]} | coding | 563 |
Solve the programming task below in a Python markdown code block.
Read problems statements in Mandarin chinese, Russian and Vietnamese as well.
When the final results for the employement competition were announced, Nour Eddin Ramadan was thrilled to find his name among the accepted co-Chefs.
However, after a while N... | {"inputs": ["4\n2\n3\n4\n10000000000"], "outputs": ["1\n2\n3\n69999300"]} | coding | 430 |
Solve the programming task below in a Python markdown code block.
You are given an array A consisting of N integers.
From array A, we create a new array B containing all pairwise bitwise ANDs of elements from A. That is, B consists of N\cdot(N-1)/2 elements, each of the form A_{i} \mathbin{\&} A_{j} for some 1 ≤ i < j... | {"inputs": ["3\n2\n1 3\n3\n2 7 1\n4\n4 6 7 2"], "outputs": ["1\n3\n6\n"]} | coding | 681 |
Solve the programming task below in a Python markdown code block.
There are n employees working in company "X" (let's number them from 1 to n for convenience). Initially the employees didn't have any relationships among each other. On each of m next days one of the following events took place: either employee y became... | {"inputs": ["1 2\n2 1\n3 1 1\n", "1 2\n2 1\n3 1 1\n", "2 3\n1 2 1\n2 1\n3 2 1\n", "2 3\n1 1 2\n2 1\n3 2 1\n", "2 3\n1 2 1\n2 1\n3 2 1\n", "2 3\n1 1 2\n2 1\n3 2 1\n", "10 5\n1 5 4\n2 5\n2 3\n3 7 2\n1 8 4\n", "10 5\n1 5 4\n2 5\n2 3\n3 7 2\n1 8 4\n"], "outputs": ["YES\n", "YES\n", "NO\n", "YES\n", "NO\n", "YES\n", "NO\n",... | coding | 535 |
Solve the programming task below in a Python markdown code block.
Chef has N dishes of different types arranged in a row: A_{1}, A_{2}, \ldots, A_{N}, where A_{i} denotes the type of the i^{th} dish. He wants to choose as many dishes as possible from the given list but while satisfying two conditions:
1. He can choo... | {"inputs": ["3\n5\n1 2 2 1 2\n6\n1 1 1 1 1 1\n8\n1 2 2 2 3 4 2 1"], "outputs": ["1\n1\n2"]} | coding | 626 |
Solve the programming task below in a Python markdown code block.
You are given an integer $n$.
Find any pair of integers $(x,y)$ ($1\leq x,y\leq n$) such that $x^y\cdot y+y^x\cdot x = n$.
-----Input-----
The first line contains a single integer $t$ ($1\leq t\leq 10^4$) — the number of test cases.
Each test case c... | {"inputs": ["5\n3\n7\n42\n31250\n20732790\n"], "outputs": ["-1\n-1\n1 21\n1 15625\n1 10366395\n"]} | coding | 317 |
Solve the programming task below in a Python markdown code block.
You are given two integers a and b. In one turn, you can do one of the following operations:
* Take an integer c (c > 1 and a should be divisible by c) and replace a with a/c;
* Take an integer c (c > 1 and b should be divisible by c) and replace ... | {"inputs": ["1\n8 5469 4\n", "1\n8 5469 1\n", "1\n7 5469 1\n", "1\n8 2465 4\n", "1\n8 5469 2\n", "1\n9 5469 1\n", "1\n8 2661 4\n", "1\n9 5469 2\n"], "outputs": ["YES\n", "NO\n", "NO\n", "YES\n", "YES\n", "NO\n", "YES\n", "YES\n"]} | coding | 445 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given an array of non-negative integers nums and an integer k. In one operation, you may choose any element from nums and increment it by 1.
Return the maximum product of nums after at most k operations. Since... | {"functional": "def check(candidate):\n assert candidate(nums = [0,4], k = 5) == 20\n assert candidate(nums = [6,3,3,2], k = 2) == 216\n\n\ncheck(Solution().maximumProduct)"} | coding | 129 |
Solve the programming task below in a Python markdown code block.
Animesh has $n$ empty candy jars, numbered from ${1}$ to $n$, with infinite capacity. He performs $m$ operations. Each operation is described by $3$ integers, ${a}$, ${b}$, and ${k}$. Here, ${a}$ and ${b}$ are indices of the jars, and ${k}$ is the number... | {"inputs": ["5 3\n1 2 100\n2 5 100\n3 4 100\n"], "outputs": ["160\n"]} | coding | 660 |
Solve the programming task below in a Python markdown code block.
There is a big staircase with $N$ steps (numbered $1$ through $N$) in ChefLand. Let's denote the height of the top of step $i$ by $h_i$. Chef Ada is currently under the staircase at height $0$ and she wants to reach the top of the staircase (the top of t... | {"inputs": ["1\n4 3\n2 4 8 16"], "outputs": ["3"]} | coding | 392 |
Solve the programming task below in a Python markdown code block.
We often have to copy large volumes of information. Such operation can take up many computer resources. Therefore, in this problem you are advised to come up with a way to copy some part of a number array into another one, quickly.
More formally, you've... | {"inputs": ["4 1\n-1 1 1 0\n2 -2 -1 2\n2 4\n", "4 1\n0 1 1 -1\n2 -2 -1 2\n2 4\n", "4 1\n0 1 0 -1\n2 -2 -1 2\n2 4\n", "4 1\n0 1 0 -1\n1 -2 -1 2\n2 4\n", "4 1\n-1 1 1 -1\n2 -2 -3 2\n2 4\n", "4 1\n-1 1 1 -1\n2 -2 -3 2\n2 4\n", "4 1\n-1 1 1 -1\n2 -2 -1 2\n2 4\n", "4 1\n-1 1 0 -1\n2 -2 -1 2\n2 4\n"], "outputs": ["2\n", "2\n... | coding | 663 |
Solve the programming task below in a Python markdown code block.
Due to the COVID pandemic, there has been an increase in the number of cases if a hospital. The management has decided to clear a large square area for the patients and arrange for beds. But the beds can't be too near to each other.
The area is of dimens... | {"inputs": ["2\n4\n1 0 1 0\n0 0 0 1\n0 1 0 0\n1 0 0 1\n4\n1 0 1 0\n0 0 0 0\n1 0 1 1\n0 1 0 0"], "outputs": ["SAFE\nUNSAFE"]} | coding | 505 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given two 0-indexed integer permutations A and B of length n.
A prefix common array of A and B is an array C such that C[i] is equal to the count of numbers that are present at or before the index i in both A ... | {"functional": "def check(candidate):\n assert candidate(A = [1,3,2,4], B = [3,1,2,4]) == [0,2,3,4]\n assert candidate(A = [2,3,1], B = [3,1,2]) == [0,1,3]\n\n\ncheck(Solution().findThePrefixCommonArray)"} | coding | 147 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a string s and an array of strings words. All the strings of words are of the same length.
A concatenated string is a string that exactly contains all the strings of any permutation of words concatenated... | {"functional": "def check(candidate):\n assert candidate(s = \"barfoothefoobarman\", words = [\"foo\",\"bar\"]) == [0,9]\n assert candidate(s = \"wordgoodgoodgoodbestword\", words = [\"word\",\"good\",\"best\",\"word\"]) == []\n assert candidate(s = \"barfoofoobarthefoobarman\", words = [\"bar\",\"foo\",\"the\... | coding | 191 |
Solve the programming task below in a Python markdown code block.
A string $a=a_1a_2\dots a_n$ is called even if it consists of a concatenation (joining) of strings of length $2$ consisting of the same characters. In other words, a string $a$ is even if two conditions are satisfied at the same time:
its length $n$ is ... | {"inputs": ["6\naabbdabdccc\nzyx\naaababbb\naabbcc\noaoaaaoo\nbmefbmuyw\n"], "outputs": ["3\n3\n2\n0\n2\n7\n"]} | coding | 542 |
Solve the programming task below in a Python markdown code block.
You are given two integers $a$ and $b$. Moreover, you are given a sequence $s_0, s_1, \dots, s_{n}$. All values in $s$ are integers $1$ or $-1$. It's known that sequence is $k$-periodic and $k$ divides $n+1$. In other words, for each $k \leq i \leq n$ it... | {"inputs": ["4 1 5 1\n-\n", "4 1 6 1\n-\n", "4 2 6 1\n-\n", "4 1 5 1\n-\n", "1 1 4 2\n-+\n", "1 1 4 2\n-+\n", "2 2 3 3\n+-+\n", "2 2 3 3\n+-+\n"], "outputs": ["999999228\n", "999998454\n", "999998073\n", "999999228\n", "3\n", "3\n", "7\n", "7\n"]} | coding | 584 |
Solve the programming task below in a Python markdown code block.
# Introduction and Warm-up (Highly recommended)
# [Playing With Lists/Arrays Series](https://www.codewars.com/collections/playing-with-lists-slash-arrays)
___
# Task
**_Given_** an **_array of integers_** , **_Find the minimum sum_** which is obtained... | {"functional": "_inputs = [[[5, 4, 2, 3]], [[12, 6, 10, 26, 3, 24]], [[9, 2, 8, 7, 5, 4, 0, 6]]]\n_outputs = [[22], [342], [74]]\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, tup... | coding | 492 |
Solve the programming task below in a Python markdown code block.
You found a mysterious function f. The function takes two strings s1 and s2. These strings must consist only of lowercase English letters, and must be the same length.
The output of the function f is another string of the same length. The i-th character... | {"inputs": ["d\ny\n", "r\nl\n", "s\nl\n", "s\nm\n", "s\nn\n", "d\nx\n", "d\nz\n", "ba\nba\n"], "outputs": ["-1\n", "l\n", "l\n", "m\n", "n\n", "-1\n", "-1\n", "ba\n"]} | coding | 377 |
Solve the programming task below in a Python markdown code block.
In Python, a string of text can be aligned left, right and center.
.ljust(width)
This method returns a left aligned string of length width.
>>> width = 20
>>> print 'HackerRank'.ljust(width,'-')
HackerRank----------
.center(width)
This method retu... | {"inputs": ["5\n"], "outputs": [" H \n HHH \n HHHHH \n HHHHHHH \nHHHHHHHHH\n HHHHH HHHHH \n HHHHH HHHHH \n HHHHH HHHHH \n HHHHH HHHHH \n HHHHH HHHHH \n HHHHH ... | coding | 436 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an integer array arr of distinct integers and an integer k.
A game will be played between the first two elements of the array (i.e. arr[0] and arr[1]). In each round of the game, we compare arr[0] with arr[1], t... | {"functional": "def check(candidate):\n assert candidate(arr = [2,1,3,5,4,6,7], k = 2) == 5\n assert candidate(arr = [3,2,1], k = 10) == 3\n assert candidate(arr = [1,9,8,2,3,7,6,4,5], k = 7) == 9\n assert candidate(arr = [1,11,22,33,44,55,66,77,88,99], k = 1000000000) == 99\n\n\ncheck(Solution().getWinner)... | coding | 165 |
Solve the programming task below in a Python markdown code block.
William has two numbers $a$ and $b$ initially both equal to zero. William mastered performing three different operations with them quickly. Before performing each operation some positive integer $k$ is picked, which is then used to perform one of the fol... | {"inputs": ["6\n1 2\n3 5\n5 3\n6 6\n8 0\n0 0\n", "6\n1 0\n3 5\n5 3\n6 6\n8 0\n0 0\n", "6\n2 0\n3 5\n5 3\n6 6\n8 0\n0 0\n", "6\n4 0\n3 5\n5 6\n6 6\n8 0\n0 0\n", "6\n4 0\n3 5\n5 6\n6 1\n8 0\n0 0\n", "6\n4 0\n3 5\n5 6\n5 1\n8 0\n0 0\n", "6\n4 0\n3 5\n5 6\n5 1\n8 1\n0 0\n", "6\n1 2\n4 5\n5 3\n6 6\n8 0\n0 0\n"], "outputs": ... | coding | 538 |
Solve the programming task below in a Python markdown code block.
Given two numbers (m and n) :
- convert all numbers from m to n to binary
- sum them as if they were in base 10
- convert the result to binary
- return as string
Eg: with the numbers 1 and 4
1 // 1 to binary is 1
+ 10 // 2 to binary is 10
+ 11 //... | {"functional": "_inputs = [[1, 4], [1, 6], [6, 20], [21, 60], [100, 100], [1, 1], [0, 1], [0, 0], [1, 100], [100, 1000]]\n_outputs = [['1111010'], ['101001101'], ['1110010110100011'], ['1100000100010001010100'], ['100001100100101000100'], ['1'], ['1'], ['0'], ['10011101010010110000101010'], ['11111100111111011001101100... | coding | 205 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
In this problem, a rooted tree is a directed graph such that, there is exactly one node (the root) for which all other nodes are descendants of this node, plus every node has exactly one parent, except for the root no... | {"functional": "def check(candidate):\n assert candidate(edges = [[1,2],[1,3],[2,3]]) == [2,3]\n assert candidate(edges = [[1,2],[2,3],[3,4],[4,1],[1,5]]) == [4,1]\n\n\ncheck(Solution().findRedundantDirectedConnection)"} | coding | 248 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an integer array nums of length n and an integer target, find three integers in nums such that the sum is closest to target.
Return the sum of the three integers.
You may assume that each input would have exactl... | {"functional": "def check(candidate):\n assert candidate(nums = [-1,2,1,-4], target = 1) == 2\n assert candidate(nums = [0,0,0], target = 1) == 0\n\n\ncheck(Solution().threeSumClosest)"} | coding | 101 |
Solve the programming task below in a Python markdown code block.
Petya and Gena love playing table tennis. A single match is played according to the following rules: a match consists of multiple sets, each set consists of multiple serves. Each serve is won by one of the players, this player scores one point. As soon a... | {"inputs": ["1\n1\n", "1\n2\n", "1\n2\n", "1\n1\n", "4\n1 1 1 1\n", "4\n1 2 1 2\n", "4\n1 1 2 1\n", "4\n2 2 1 2\n"], "outputs": ["1\n1 1\n", "1\n1 1\n", "1\n1 1\n", "1\n1 1\n", "3\n1 4\n2 2\n4 1\n", "0\n", "2\n1 3\n3 1\n", "2\n1 3\n3 1\n"]} | coding | 581 |
Solve the programming task below in a Python markdown code block.
Let's introduce a number system which is based on a roman digits. There are digits I, V, X, L which correspond to the numbers 1, 5, 10 and 50 respectively. The use of other roman digits is not allowed.
Numbers in this system are written as a sequence of... | {"inputs": ["6\n", "8\n", "4\n", "9\n", "3\n", "5\n", "7\n", "1\n"], "outputs": ["83\n", "155\n", "35\n", "198\n", "20\n", "56\n", "116\n", "4\n"]} | coding | 390 |
Solve the programming task below in a Python markdown code block.
There will be a launch of a new, powerful and unusual collider very soon, which located along a straight line. n particles will be launched inside it. All of them are located in a straight line and there can not be two or more particles located in the sa... | {"inputs": ["1\nR\n0\n", "1\nL\n0\n", "1\nL\n0\n", "1\nR\n0\n", "1\nL\n1\n", "1\nR\n1\n", "2\nRL\n0 2\n", "2\nLL\n2 4\n"], "outputs": ["-1\n", "-1\n", "-1", "-1", "-1\n", "-1\n", "1\n", "-1\n"]} | coding | 562 |
Solve the programming task below in a Python markdown code block.
Given an array of integers, find the one that appears an odd number of times.
There will always be only one integer that appears an odd number of times.
Also feel free to reuse/extend the following starter code:
```python
def find_it(seq):
``` | {"functional": "_inputs = [[[20, 1, -1, 2, -2, 3, 3, 5, 5, 1, 2, 4, 20, 4, -1, -2, 5]], [[1, 1, 2, -2, 5, 2, 4, 4, -1, -2, 5]], [[20, 1, 1, 2, 2, 3, 3, 5, 5, 4, 20, 4, 5]], [[10]], [[1, 1, 1, 1, 1, 1, 10, 1, 1, 1, 1]]]\n_outputs = [[5], [-1], [5], [10], [10]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstan... | coding | 66 |
Solve the programming task below in a Python markdown code block.
Consider the numbers `6969` and `9116`. When you rotate them `180 degrees` (upside down), these numbers remain the same. To clarify, if we write them down on a paper and turn the paper upside down, the numbers will be the same. Try it and see! Some numbe... | {"functional": "_inputs = [[0, 10], [10, 100], [100, 1000], [1000, 10000], [10000, 15000], [15000, 20000], [60000, 70000], [60000, 130000]]\n_outputs = [[3], [4], [12], [20], [6], [9], [15], [55]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.iscl... | coding | 329 |
Solve the programming task below in a Python markdown code block.
Read problems statements in [Mandarin Chinese],[Vietnamese], and [Bengali] as well.
Today is Chef's birthday and he is looking forward to his gift. As usual, the gift is hidden and Chef has to follow a sequence of $N$ instructions to reach it.
Initiall... | {"inputs": ["3\n5\nLLLUR\n7\nLLLRUUD\n8\nLRULLUDU"], "outputs": ["0 1\n-1 1\n-2 2"]} | coding | 531 |
Solve the programming task below in a Python markdown code block.
Is it rated?
Here it is. The Ultimate Question of Competitive Programming, Codeforces, and Everything. And you are here to answer it.
Another Codeforces round has been conducted. No two participants have the same number of points. For each participant,... | {"inputs": ["2\n1 1\n1 1\n", "2\n1 1\n2 2\n", "2\n2 2\n1 1\n", "2\n2 1\n1 2\n", "2\n3 2\n3 2\n", "2\n1 2\n2 1\n", "2\n3 1\n9 8\n", "2\n2 1\n1 1\n"], "outputs": ["maybe\n", "unrated\n", "maybe\n", "rated\n", "rated\n", "rated\n", "rated\n", "rated\n"]} | coding | 630 |
Solve the programming task below in a Python markdown code block.
Triangular number is the amount of points that can fill equilateral triangle.
Example: the number 6 is a triangular number because all sides of a triangle has the same amount of points.
```
Hint!
T(n) = n * (n + 1) / 2,
n - is the size of one side.
T(... | {"functional": "_inputs = [[1], [3], [6], [10], [15], [21], [28], [2], [7], [14], [27]]\n_outputs = [[True], [True], [True], [True], [True], [True], [True], [False], [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(... | coding | 146 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given three integers x, y, and bound, return a list of all the powerful integers that have a value less than or equal to bound.
An integer is powerful if it can be represented as xi + yj for some integers i >= 0 and j... | {"functional": "def check(candidate):\n assert candidate(x = 2, y = 3, bound = 10) == [2,3,4,5,7,9,10]\n assert candidate(x = 3, y = 5, bound = 15) == [2,4,6,8,10,14]\n\n\ncheck(Solution().powerfulIntegers)"} | coding | 134 |
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 memory machine. It has one layer for data storage and another layer for cache. Chef has stored an array with length $N$ in the first laye... | {"inputs": ["1\n5 3 3\n0 3 4"], "outputs": ["2"]} | coding | 731 |
Solve the programming task below in a Python markdown code block.
Vasya is writing an operating system shell, and it should have commands for working with directories. To begin with, he decided to go with just two commands: cd (change the current directory) and pwd (display the current directory).
Directories in Vasya... | {"inputs": ["1\npwd\n", "4\ncd /b/b\npwd\ncd ../a/b\npwd\n", "4\ncd /a/b\npwd\ncd ../a/b\npwd\n", "5\npwd\ncd ztb/kag\npwd\npwd\npwd\n", "5\npwd\ncd gak/btz\npwd\npwd\npwd\n", "6\ncd a/a/b/b\npwd\ncd ../..\npwd\ncd ..\npwd\n", "5\npwd\ncd /xgztbykka\npwd\ncd /gia/kxfls\npwd\n", "5\npwd\ncd /xgztbzkka\npwd\ncd /gia/kxfl... | coding | 631 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
A good meal is a meal that contains exactly two different food items with a sum of deliciousness equal to a power of two.
You can pick any two different foods to make a good meal.
Given an array of integers deliciousn... | {"functional": "def check(candidate):\n assert candidate(deliciousness = [1,3,5,7,9]) == 4\n assert candidate(deliciousness = [1,1,1,3,3,3,7]) == 15\n\n\ncheck(Solution().countPairs)"} | coding | 160 |
Solve the programming task below in a Python markdown code block.
The main city magazine offers its readers an opportunity to publish their ads. The format of the ad should be like this:
There are space-separated non-empty words of lowercase and uppercase Latin letters.
There are hyphen characters '-' in some words, ... | {"inputs": ["1\nj\n", "1\nj\n", "1\ni\n", "1\nh\n", "1\ng\n", "1\nf\n", "10\nb\n", "10\nb\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n"]} | coding | 403 |
Solve the programming task below in a Python markdown code block.
We have a sequence of N integers A~=~A_0,~A_1,~...,~A_{N - 1}.
Let B be a sequence of K \times N integers obtained by concatenating K copies of A. For example, if A~=~1,~3,~2 and K~=~2, B~=~1,~3,~2,~1,~3,~2.
Find the inversion number of B, modulo 10^9 ... | {"inputs": ["2 2\n2 2", "2 2\n0 2", "2 2\n2 0", "2 4\n2 0", "2 2\n2 1", "3 5\n1 1 0", "3 5\n1 2 0", "2 -4\n2 -1"], "outputs": ["0\n", "1\n", "3\n", "10\n", "3", "30\n", "40\n", "6\n"]} | coding | 357 |
Solve the programming task below in a Python markdown code block.
Compute A + B.
Constraints
* -1000 ≤ A, B ≤ 1000
Input
The input will consist of a series of pairs of integers A and B separated by a space, one pair of integers per line. The input will be terminated by EOF.
Output
For each pair of input integers ... | {"inputs": ["1 2\n0 6\n011 1", "2 2\n0 6\n011 1", "2 4\n0 6\n011 1", "2 4\n0 2\n011 1", "2 6\n0 2\n011 1", "3 6\n0 2\n011 1", "3 6\n0 2\n011 0", "3 6\n0 4\n011 0"], "outputs": ["3\n6\n12\n", "4\n6\n12\n", "6\n6\n12\n", "6\n2\n12\n", "8\n2\n12\n", "9\n2\n12\n", "9\n2\n11\n", "9\n4\n11\n"]} | coding | 128 |
Solve the programming task below in a Python markdown code block.
Every now and then people in the office moves teams or departments. Depending what people are doing with their time they can become more or less boring. Time to assess the current team.
```if-not:java
You will be provided with an object(staff) containin... | {"functional": "_inputs = [[{'tim': 'change', 'jim': 'accounts', 'randy': 'canteen', 'sandy': 'change', 'andy': 'change', 'katie': 'IS', 'laura': 'change', 'saajid': 'IS', 'alex': 'trading', 'john': 'accounts', 'mr': 'finance'}], [{'tim': 'IS', 'jim': 'finance', 'randy': 'pissing about', 'sandy': 'cleaning', 'andy': 'c... | coding | 330 |
Solve the programming task below in a Python markdown code block.
Gerald got a very curious hexagon for his birthday. The boy found out that all the angles of the hexagon are equal to $120^{\circ}$. Then he measured the length of its sides, and found that each of them is equal to an integer number of centimeters. There... | {"inputs": ["1 1 1 1 1 1\n", "1 2 1 2 1 2\n", "2 4 5 3 3 6\n", "7 5 4 8 4 5\n", "3 2 1 4 1 2\n", "7 1 7 3 5 3\n", "9 2 9 3 8 3\n", "1 6 1 5 2 5\n"], "outputs": ["6\n", "13\n", "83\n", "175\n", "25\n", "102\n", "174\n", "58\n"]} | coding | 352 |
Solve the programming task below in a Python markdown code block.
You are given two arrays $a$ and $b$ of $n$ elements, each element is either $0$ or $1$.
You can make operations of $2$ kinds.
Pick an index $i$ and change $a_i$ to $1-a_i$.
Rearrange the array $a$ however you want.
Find the minimum number of operati... | {"inputs": ["5\n3\n1 0 1\n0 0 1\n4\n1 1 0 0\n0 1 1 1\n2\n1 1\n1 1\n4\n1 0 0 1\n0 1 1 0\n1\n0\n1\n"], "outputs": ["1\n2\n0\n1\n1\n"]} | coding | 571 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
There are n children standing in a line. Each child is assigned a rating value given in the integer array ratings.
You are giving candies to these children subjected to the following requirements:
Each child must hav... | {"functional": "def check(candidate):\n assert candidate(ratings = [1,0,2]) == 5\n assert candidate(ratings = [1,2,2]) == 4\n\n\ncheck(Solution().candy)"} | coding | 122 |
Solve the programming task below in a Python markdown code block.
The football season has just ended in Berland. According to the rules of Berland football, each match is played between two teams. The result of each match is either a draw, or a victory of one of the playing teams. If a team wins the match, it gets w po... | {"inputs": ["10 2 5 3\n", "10 2 5 4\n", "100 1 5 4\n", "10 6 10 9\n", "27 60 3 1\n", "20 0 28 5\n", "101 1 5 4\n", "10 2 10 9\n"], "outputs": ["-1\n", "-1\n", "-1\n", "-1\n", "20 0 7\n", "0 0 20\n", "-1\n", "-1\n"]} | coding | 583 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
An integer has sequential digits if and only if each digit in the number is one more than the previous digit.
Return a sorted list of all the integers in the range [low, high] inclusive that have sequential digits.
... | {"functional": "def check(candidate):\n assert candidate(low = 100, high = 300) == [123,234]\n assert candidate(low = 1000, high = 13000) == [1234,2345,3456,4567,5678,6789,12345]\n\n\ncheck(Solution().sequentialDigits)"} | coding | 99 |
Solve the programming task below in a Python markdown code block.
Consider the number `1176` and its square (`1176 * 1176) = 1382976`. Notice that:
* the first two digits of `1176` form a prime.
* the first two digits of the square `1382976` also form a prime.
* the last two digits of `1176` and `1382976` are the same... | {"functional": "_inputs = [[2, 1200], [1176, 1200], [2, 100000], [2, 1000000], [100000, 1000000]]\n_outputs = [[1], [1], [247], [2549], [2302]]\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 isinstanc... | coding | 364 |
Solve the programming task below in a Python markdown code block.
There are n boys and m girls attending a theatre club. To set a play "The Big Bang Theory", they need to choose a group containing exactly t actors containing no less than 4 boys and no less than one girl. How many ways are there to choose a group? Of co... | {"inputs": ["4 2 6\n", "4 1 5\n", "7 3 6\n", "5 1 6\n", "6 1 5\n", "5 1 5\n", "4 4 5\n", "6 1 6\n"], "outputs": ["1", "1", "168", "1\n", "15\n", "5\n", "4\n", "6\n"]} | coding | 236 |
Solve the programming task below in a Python markdown code block.
The Story:
Aliens from Kepler 27b have immigrated to Earth! They have learned English and go to our stores, eat our food, dress like us, ride Ubers, use Google, etc. However, they speak English a little differently. Can you write a program that converts ... | {"functional": "_inputs = [['codewars'], ['hello']]\n_outputs = [['cudewors'], ['hellu']]\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): ret... | coding | 160 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.