problem stringlengths 14 4.09k | solution stringlengths 1 802k | task_type stringclasses 3
values | problem_tokens int64 5 895 |
|---|---|---|---|
Solve the programming task below in a Python markdown code block.
You are given a set of `n` segments on the axis `Ox`, each segment has integer endpoints between `0` and `m` inclusive.
Segments may intersect, overlap or even coincide with each other. Each segment is characterized by two integers li and ri — coordinat... | {"functional": "_inputs = [[7, [[0, 7]]], [2, []], [0, []], [0, [[0, 0]]]]\n_outputs = [[[]], [[0, 1, 2]], [[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 ... | coding | 284 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an m x n grid of characters board and a string word, return true if word exists in the grid.
The word can be constructed from letters of sequentially adjacent cells, where adjacent cells are horizontally or vert... | {"functional": "def check(candidate):\n assert candidate(board = [[\"A\",\"B\",\"C\",\"E\"],[\"S\",\"F\",\"C\",\"S\"],[\"A\",\"D\",\"E\",\"E\"]], word = \"ABCCED\") == True\n assert candidate(board = [[\"A\",\"B\",\"C\",\"E\"],[\"S\",\"F\",\"C\",\"S\"],[\"A\",\"D\",\"E\",\"E\"]], word = \"SEE\") == True\n asse... | coding | 108 |
Solve the programming task below in a Python markdown code block.
The new "Avengers" movie has just been released! There are a lot of people at the cinema box office standing in a huge line. Each of them has a single `100`, `50` or `25` dollar bill. An "Avengers" ticket costs `25 dollars`.
Vasya is currently working a... | {"functional": "_inputs = [[[25, 25, 50]], [[25, 25, 50, 100]], [[25, 100]], [[25, 25, 25, 25, 25, 25, 25, 25, 25, 25]], [[50, 50, 50, 50, 50, 50, 50, 50, 50, 50]], [[100, 100, 100, 100, 100, 100, 100, 100, 100, 100]], [[25, 25, 25, 25, 50, 100, 50]], [[50, 100, 100]], [[25, 25, 100]], [[25, 25, 25, 25, 25, 25, 25, 50,... | coding | 551 |
Solve the programming task below in a Python markdown code block.
JJ found a balanced parenthesis sequence. He does not like balanced parentheses so he will make the parenthesis sequence unbalanced by swapping adjacent characters in the sequence.
JJ is lazy and wants to know minimum number of adjacent swaps required ... | {"inputs": ["4\n()\n(())\n()()\n((()))(())\n"], "outputs": ["1\n2\n1\n2\n"]} | coding | 343 |
Solve the programming task below in a Python markdown code block.
The Earth has been invaded by aliens. They demand our beer and threaten to destroy the Earth if we do not supply the exact number of beers demanded.
Unfortunately, the aliens only speak Morse code. Write a program to convert morse code into numbers usin... | {"functional": "_inputs = [['.----.----.----.----.----'], ['..----------...-....----------'], ['---------------'], ['..---.--------....--'], ['.----..---...--....-.....-....--...---..----.-----']]\n_outputs = [[11111], [207600], [0], [2193], [1234567890]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a... | coding | 118 |
Solve the programming task below in a Python markdown code block.
Polycarpus just has been out of luck lately! As soon as he found a job in the "Binary Cat" cafe, the club got burgled. All ice-cream was stolen.
On the burglary night Polycarpus kept a careful record of all club visitors. Each time a visitor entered the... | {"inputs": ["-\n", "+\n", "-\n", "+\n", "--\n", "+-\n", "++\n", "--\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "2\n", "1\n", "2\n", "2\n"]} | coding | 301 |
Solve the programming task below in a Python markdown code block.
Problem statement
There is an unsigned $ 2 $ decimal integer $ X $ with $ N $ in digits including Leading-zeros. Output the largest non-negative integer that can be expressed in $ 2 $ base in $ N $ digits where the Hamming distance from $ X $ is $ D $.
... | {"inputs": ["5\n00001\n4", "5\n00000\n3", "5\n00001\n1", "5\n10001\n1", "5\n10001\n2", "5\n10001\n4", "5\n10000\n1", "5\n00010\n1"], "outputs": ["11111\n", "11100\n", "10001\n", "11001\n", "11101\n", "11110\n", "11000\n", "10010\n"]} | coding | 357 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given an integer n indicating the number of people in a network. Each person is labeled from 0 to n - 1.
You are also given a 0-indexed 2D integer array restrictions, where restrictions[i] = [xi, yi] means tha... | {"functional": "def check(candidate):\n assert candidate(n = 3, restrictions = [[0,1]], requests = [[0,2],[2,1]]) == [True,False]\n assert candidate(n = 3, restrictions = [[0,1]], requests = [[1,2],[0,2]]) == [True,False]\n assert candidate(n = 5, restrictions = [[0,1],[1,2],[2,3]], requests = [[0,4],[1,2],[3,... | coding | 295 |
Solve the programming task below in a Python markdown code block.
Let N be a positive integer.
There is a numerical sequence of length 3N, a = (a_1, a_2, ..., a_{3N}).
Snuke is constructing a new sequence of length 2N, a', by removing exactly N elements from a without changing the order of the remaining elements.
Here,... | {"inputs": ["1\n1 0 5", "1\n0 0 5", "1\n1 3 5", "1\n1 2 5", "1\n0 0 8", "1\n0 0 0", "1\n0 1 0", "1\n1 2 3"], "outputs": ["1\n", "0\n", "-2\n", "-1\n", "0\n", "0\n", "1\n", "-1"]} | coding | 299 |
Solve the programming task below in a Python markdown code block.
Chef has invented 1-minute Instant Noodles. As the name suggests, each packet takes exactly 1 minute to cook.
Chef's restaurant has X stoves and only 1 packet can be cooked in a single pan.
How many customers can Chef serve in Y minutes if each custom... | {"inputs": ["3 7", "7 8"], "outputs": ["21", "56"]} | coding | 367 |
Solve the programming task below in a Python markdown code block.
Create a program that takes two dates as input and outputs the number of days between the two dates.
Date 1 (y1, m1, d1) is the same as or earlier than date 2 (y2, m2, d2). Date 1 is included in the number of days, not date 2. Also, take the leap year i... | {"inputs": ["2006 3 2 522 6 3\n2006 8 1 89 11 11\n2004 1 2 362 1 2\n3334 2 1 2180 1 1\n2000 2 1 2101 1 1\n-1 -1 -1 -1 -1 -1", "2006 9 2 522 9 2\n2006 9 1 19 11 11\n2004 1 2 2005 1 1\n1153 1 1 2006 1 1\n2000 1 1 2101 1 1\n-1 -1 -1 -1 -1 -1", "2006 9 2 522 9 3\n2006 9 1 2006 11 11\n2004 1 2 2005 1 1\n218 1 1 2006 1 1\n20... | coding | 356 |
Solve the programming task below in a Python markdown code block.
There are N people standing in a row from west to east.
Each person is facing east or west.
The directions of the people is given as a string S of length N.
The i-th person from the west is facing east if S_i = E, and west if S_i = W.
You will appoint on... | {"inputs": ["5\nWEEWW\n", "8\nWWWWWEEE\n", "12\nWEWEWEEEWWWE\n"], "outputs": ["1\n", "3\n", "4\n"]} | coding | 333 |
Solve the programming task below in a Python markdown code block.
Valera is a lazy student. He has m clean bowls and k clean plates.
Valera has made an eating plan for the next n days. As Valera is lazy, he will eat exactly one dish per day. At that, in order to eat a dish, he needs exactly one clean plate or bowl. W... | {"inputs": ["1 1 1\n2\n", "1 2 1\n2\n", "1 1 2\n2\n", "1 2 2\n2\n", "1 0 1\n2\n", "1 0 0\n2\n", "1 1 0\n2\n", "1 4 1\n2\n"], "outputs": ["0", "0", "0", "0", "0\n", "1\n", "0\n", "0\n"]} | coding | 501 |
Solve the programming task below in a Python markdown code block.
Vasya has got two number: a and b. However, Vasya finds number a too short. So he decided to repeat the operation of lengthening number a n times.
One operation of lengthening a number means adding exactly one digit to the number (in the decimal notatio... | {"inputs": ["3 4 1\n", "3 7 2\n", "5 4 7\n", "3 1 1\n", "5 4 9\n", "3 1 2\n", "7 4 9\n", "1 1 2\n"], "outputs": ["32\n", "350\n", "52000000\n", "30\n", "5200000000\n", "300\n", "7200000000\n", "100\n"]} | coding | 276 |
Solve the programming task below in a Python markdown code block.
Alice is playing Air Hockey with Bob. The first person to earn seven points wins the match. Currently, Alice's score is A and Bob's score is B.
Charlie is eagerly waiting for his turn. Help Charlie by calculating the minimum number of points that will b... | {"inputs": ["4\n0 0\n2 5\n5 2\n4 3"], "outputs": ["7\n2\n2\n3\n"]} | coding | 490 |
Solve the programming task below in a Python markdown code block.
You are given a string S of numbers. Dr. Dragoon has eaten up some numbers of the string. You decide to fix the string by putting the numbers 0 and 1 in the empty spaces.
The base cost for putting the ‘0’ is x and putting ‘1’ is y . The cost of putt... | {"inputs": ["501?1?\n6 5", "1001?11?\n5 23"], "outputs": ["6", "8"]} | coding | 443 |
Solve the programming task below in a Python markdown code block.
In Russia regular bus tickets usually consist of 6 digits. The ticket is called lucky when the sum of the first three digits equals to the sum of the last three digits. Write a function to find out whether the ticket is lucky or not. Return true if so, o... | {"functional": "_inputs = [['123321'], ['12341234'], ['100001'], ['100200'], ['912435'], ['12a12a'], ['999999'], ['1111'], ['000000'], ['']]\n_outputs = [[True], [False], [True], [False], [True], [False], [True], [False], [True], [False]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isins... | coding | 105 |
Solve the programming task below in a Python markdown code block.
The Gray code (see wikipedia for more details) is a well-known concept.
One of its important properties is that every two adjacent numbers have exactly one different digit in their binary representation.
In this problem, we will give you n non-negative ... | {"inputs": ["5\n1 0 2 3 7", "5\n1 0 2 3 7"], "outputs": ["Yes", "Yes"]} | coding | 332 |
Solve the programming task below in a Python markdown code block.
Chef's computer has N GB of free space. He wants to save X files, each of size 1 GB and Y files, each of size 2 GB on his computer. Will he be able to do so?
Chef can save all the files on his computer only if the total size of the files is less than o... | {"inputs": ["4\n6 3 1\n2 2 2\n4 3 2\n5 1 2\n"], "outputs": ["YES\nNO\nNO\nYES\n"]} | coding | 481 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given an integer mass, which represents the original mass of a planet. You are further given an integer array asteroids, where asteroids[i] is the mass of the ith asteroid.
You can arrange for the planet to co... | {"functional": "def check(candidate):\n assert candidate(mass = 10, asteroids = [3,9,19,5,21]) == True\n assert candidate(mass = 5, asteroids = [4,9,23,4]) == False\n\n\ncheck(Solution().asteroidsDestroyed)"} | coding | 158 |
Solve the programming task below in a Python markdown code block.
For the given integer $n$ ($n > 2$) let's write down all the strings of length $n$ which contain $n-2$ letters 'a' and two letters 'b' in lexicographical (alphabetical) order.
Recall that the string $s$ of length $n$ is lexicographically less than strin... | {"inputs": ["1\n100000 1\n", "1\n100010 1\n", "1\n100110 1\n", "1\n100000 2\n", "1\n100010 2\n", "1\n101010 1\n", "1\n100010 4\n", "1\n101000 1\n"], "outputs": ["aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa... | coding | 539 |
Solve the programming task below in a Python markdown code block.
One day n friends met at a party, they hadn't seen each other for a long time and so they decided to make a group photo together.
Simply speaking, the process of taking photos can be described as follows. On the photo, each photographed friend occupies... | {"inputs": ["2\n1 5\n2 3\n", "2\n2 3\n1 1\n", "2\n1 1\n1 2\n", "2\n1 1\n1 2\n", "2\n2 3\n1 1\n", "2\n1 5\n2 3\n", "2\n2 6\n1 1\n", "2\n2 5\n2 3\n"], "outputs": ["6 5 ", "1 6 ", "2 1 ", "2 1 ", "1 6 ", "6 5 ", "1 12\n", "6 10\n"]} | coding | 395 |
Solve the programming task below in a Python markdown code block.
A binary matrix is called good if every even length square sub-matrix has an odd number of ones.
Given a binary matrix $a$ consisting of $n$ rows and $m$ columns, determine the minimum number of cells you need to change to make it good, or report that ... | {"inputs": ["1 1\n0\n", "1 1\n1\n", "1 1\n0\n", "1 1\n1\n", "3 3\n101\n001\n110\n", "3 3\n101\n001\n100\n", "3 3\n101\n001\n111\n", "3 3\n111\n001\n100\n"], "outputs": ["0", "0", "0\n", "0\n", "2", "1\n", "2\n", "1\n"]} | coding | 697 |
Solve the programming task below in a Python markdown code block.
Vanya loves playing. He even has a special set of cards to play with. Each card has a single integer. The number on the card can be positive, negative and can even be equal to zero. The only limit is, the number on each card doesn't exceed x in the absol... | {"inputs": ["1 1\n0\n", "1 1\n1\n", "1 1\n1\n", "1 1\n0\n", "1 4\n-3\n", "1 1\n-1\n", "1 4\n-3\n", "1 1\n-1\n"], "outputs": ["0\n", "1\n", "1\n", "0\n", "1\n", "1\n", "1\n", "1\n"]} | coding | 395 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given an integer array banned and two integers n and maxSum. You are choosing some number of integers following the below rules:
The chosen integers have to be in the range [1, n].
Each integer can be chosen ... | {"functional": "def check(candidate):\n assert candidate(banned = [1,6,5], n = 5, maxSum = 6) == 2\n assert candidate(banned = [1,2,3,4,5,6,7], n = 8, maxSum = 1) == 0\n assert candidate(banned = [11], n = 7, maxSum = 50) == 7\n\n\ncheck(Solution().maxCount)"} | coding | 144 |
Solve the programming task below in a Python markdown code block.
Moamen and Ezzat are playing a game. They create an array $a$ of $n$ non-negative integers where every element is less than $2^k$.
Moamen wins if $a_1 \,\&\, a_2 \,\&\, a_3 \,\&\, \ldots \,\&\, a_n \ge a_1 \oplus a_2 \oplus a_3 \oplus \ldots \oplus a_n$... | {"inputs": ["1\n1 0\n", "1\n1 0\n", "3\n3 1\n2 1\n4 0\n", "3\n6 1\n2 1\n4 0\n", "3\n6 1\n2 0\n4 0\n", "3\n3 1\n2 1\n4 0\n", "3\n11 1\n2 0\n4 0\n", "5\n22 59\n26 60\n72 72\n47 3\n97 16\n"], "outputs": ["1\n", "1\n", "5\n2\n1\n", "32\n2\n1\n", "32\n1\n1\n", "5\n2\n1\n", "1025\n1\n1\n", "719147166\n712743436\n592556526\n3... | coding | 510 |
Solve the programming task below in a Python markdown code block.
Today s kilometer long auto race takes place in Berland. The track is represented by a straight line as long as s kilometers. There are n cars taking part in the race, all of them start simultaneously at the very beginning of the track. For every car is ... | {"inputs": ["2 33\n2 5 1 2 14\n1 3 11\n", "2 33\n2 1 3 10 3\n1 11 3\n", "2 6\n3 1 2 2 1 1 2\n3 2 1 1 2 2 1\n", "2 5\n3 2 1 1 1 2 1\n3 1 1 2 1 1 2\n", "2 5\n3 2 1 1 1 2 1\n3 1 2 2 1 1 1\n", "2 166755\n2 733 187 362 82\n3 813 147 565 57 557 27\n", "5 33\n2 1 3 3 10\n1 11 3\n2 5 3 3 6\n2 3 1 10 3\n2 6 3 3 5\n", "3 228385\... | coding | 575 |
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 stones sorted in strictly increasing order representing the positions of stones in a river.
A frog, initially on the first stone, wants to travel to the last stone and then retu... | {"functional": "def check(candidate):\n assert candidate(stones = [0,2,5,6,7]) == 5\n assert candidate(stones = [0,3,9]) == 9\n\n\ncheck(Solution().maxJump)"} | coding | 204 |
Solve the programming task below in a Python markdown code block.
Chef will not be able to attend the birthday of his best friend Rock. He promised Rock that this will not be the case on his half birthday. To keep his promise Chef must know Rock’s next half birthday accurately. Being busy, he is assigning this work to ... | {"inputs": ["3\n15 january\n31 august\n10 october"], "outputs": ["16 july\n1 march\n10 april"]} | coding | 334 |
Solve the programming task below in a Python markdown code block.
Read problem statements in [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
Given an array $A$ of size $N$. Find the maximum value of the expression $a * b + a - b$ where $a$ and $b$ are $2$ distinct elements of the array.
------ Inp... | {"inputs": ["2\n2 \n2 2\n3\n5 3 2"], "outputs": ["4\n17"]} | coding | 461 |
Solve the programming task below in a Python markdown code block.
You are given a string S consisting of uppercase English letters. Find the length of the longest ACGT string that is a substring (see Notes) of S.
Here, a ACGT string is a string that contains no characters other than A, C, G and T.
-----Notes-----
A su... | {"inputs": ["A\n", "Z\n", "CG\n", "ABC\n", "ATCPDER", "ATCPCER", "ATCPBER", "REBPCTA"], "outputs": ["1\n", "0\n", "2\n", "1\n", "3\n", "3\n", "3\n", "3\n"]} | coding | 234 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an array nums sorted in non-decreasing order, return the maximum between the number of positive integers and the number of negative integers.
In other words, if the number of positive integers in nums is pos an... | {"functional": "def check(candidate):\n assert candidate(nums = [-2,-1,-1,1,2,3]) == 3\n assert candidate(nums = [-3,-2,-1,0,0,1,2]) == 3\n assert candidate(nums = [5,20,66,1314]) == 4\n\n\ncheck(Solution().maximumCount)"} | coding | 117 |
Solve the programming task below in a Python markdown code block.
As a New Year's gift, Dolphin received a string s of length 19.
The string s has the following format: `[five lowercase English letters],[seven lowercase English letters],[five lowercase English letters]`.
Dolphin wants to convert the comma-separated str... | {"inputs": ["gaiku,atcoder,tasks", "abgde,fchihgf,edcba", "ha,pypnewyear,enjoy", "gaiku,atcoeer,tasks", "abcde,fghihcf,edgba", "ha,pypnewzear,enjoy", "gaiku,atcoeer-tasks", "abgde,fchihgf+edcba"], "outputs": ["gaiku atcoder tasks\n", "abgde fchihgf edcba\n", "ha pypnewyear enjoy\n", "gaiku atcoeer tasks\n", "abcde fghi... | coding | 200 |
Solve the programming task below in a Python markdown code block.
Mole is hungry again. He found one ant colony, consisting of n ants, ordered in a row. Each ant i (1 ≤ i ≤ n) has a strength si.
In order to make his dinner more interesting, Mole organizes a version of «Hunger Games» for the ants. He chooses two number... | {"inputs": ["5\n1 5 2 4 2\n4\n1 5\n2 5\n3 5\n4 5\n", "5\n1 3 4 4 2\n4\n1 5\n2 5\n3 5\n4 5\n", "5\n1 3 4 4 2\n4\n1 5\n2 5\n3 5\n2 5\n", "5\n1 3 4 4 2\n4\n1 5\n2 5\n1 5\n4 5\n", "5\n1 3 4 4 2\n4\n1 5\n2 5\n1 5\n3 5\n", "5\n1 3 4 4 2\n4\n1 3\n2 5\n1 5\n3 5\n", "5\n1 3 4 2 2\n4\n1 5\n2 5\n3 5\n2 5\n", "5\n1 3 4 4 2\n4\n1 5... | coding | 602 |
Solve the programming task below in a Python markdown code block.
# Covfefe
Your are given a string. You must replace the word(s) `coverage` by `covfefe`, however, if you don't find the word `coverage` in the string, you must add `covfefe` at the end of the string with a leading space.
For the languages where the st... | {"functional": "_inputs = [['coverage'], ['coverage coverage'], ['nothing'], ['double space '], ['covfefe']]\n_outputs = [['covfefe'], ['covfefe covfefe'], ['nothing covfefe'], ['double space covfefe'], ['covfefe covfefe']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float... | coding | 126 |
Solve the programming task below in a Python markdown code block.
There are N cards placed face down in a row. On each card, an integer 1 or 2 is written.
Let A_i be the integer written on the i-th card.
Your objective is to guess A_1, A_2, ..., A_N correctly.
You know the following facts:
- For each i = 1, 2, ..., M,... | {"inputs": ["3 1\n2 2 1", "3 1\n3 2 1", "6 1\n3 2 1", "4 1\n2 2 1", "8 1\n1 2 1", "6 1\n1 1 1", "8 1\n2 2 2", "3 1\n3 3 1"], "outputs": ["3\n", "2\n", "5\n", "4\n", "7\n", "6\n", "8\n", "3\n"]} | coding | 423 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an infinite number of quarters (25 cents), dimes (10 cents), nickels (5 cents), and pennies (1 cent), write code to calculate the number of ways of representing n cents. (The result may be large, so you should r... | {"functional": "def check(candidate):\n assert candidate(n = 5) == 2\n assert candidate(n = 10) == 4\n\n\ncheck(Solution().waysToChange)"} | coding | 116 |
Solve the programming task below in a Python markdown code block.
An Ironman Triathlon is one of a series of long-distance triathlon races organized by the World Triathlon Corporaion (WTC).
It consists of a 2.4-mile swim, a 112-mile bicycle ride and a marathon (26.2-mile) (run, raced in that order and without a break. ... | {"functional": "_inputs = [[36], [103], [0], [2], [151]]\n_outputs = [[{'Bike': '104.60 to go!'}], [{'Bike': '37.60 to go!'}], ['Starting Line... Good Luck!'], [{'Swim': '138.60 to go!'}], [\"You're done! Stop running!\"]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):... | coding | 312 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given an array of equal-length strings words. Assume that the length of each string is n.
Each string words[i] can be converted into a difference integer array difference[i] of length n - 1 where difference[i]... | {"functional": "def check(candidate):\n assert candidate(words = [\"adc\",\"wzy\",\"abc\"]) == \"abc\"\n assert candidate(words = [\"aaa\",\"bob\",\"ccc\",\"ddd\"]) == \"bob\"\n\n\ncheck(Solution().oddString)"} | coding | 234 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given an integer array jobs, where jobs[i] is the amount of time it takes to complete the ith job.
There are k workers that you can assign jobs to. Each job should be assigned to exactly one worker. The workin... | {"functional": "def check(candidate):\n assert candidate(jobs = [3,2,3], k = 3) == 3\n assert candidate(jobs = [1,2,4,7,8], k = 2) == 11\n\n\ncheck(Solution().minimumTimeRequired)"} | coding | 153 |
Solve the programming task below in a Python markdown code block.
Eugeny has array a = a_1, a_2, ..., a_{n}, consisting of n integers. Each integer a_{i} equals to -1, or to 1. Also, he has m queries: Query number i is given as a pair of integers l_{i}, r_{i} (1 ≤ l_{i} ≤ r_{i} ≤ n). The response to the query will be... | {"inputs": ["1 1\n1\n1 1\n", "1 1\n1\n1 1\n", "1 1\n-1\n1 1\n", "1 1\n-1\n1 1\n", "1 1\n-1\n0 1\n", "1 1\n-1\n1 2\n", "1 1\n-1\n1 3\n", "1 1\n-1\n-1 1\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]} | coding | 369 |
Solve the programming task below in a Python markdown code block.
If you have completed the Tribonacci sequence kata, you would know by now that mister Fibonacci has at least a bigger brother. If not, give it a quick look to get how things work.
Well, time to expand the family a little more: think of a Quadribonacci s... | {"functional": "_inputs = [[[0, 1], 10], [[1, 1], 10], [[0, 0, 0, 0, 1], 10], [[1, 0, 0, 0, 0, 0, 1], 10], [[1, 0, 0, 0, 0, 0, 0, 0, 0, 0], 20], [[0.5, 0, 0, 0, 0, 0, 0, 0, 0, 0], 10], [[0.5, 0, 0, 0, 0, 0, 0, 0, 0, 0], 20], [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0], 20], [[1, 2, 3, 4, 5, 6, 7, 8, 9, 0], 9], [[1, 2, 3, 4, 5, 6, ... | coding | 361 |
Solve the programming task below in a Python markdown code block.
You are given an integer sequence $a_1, a_2, \dots, a_n$.
Find the number of pairs of indices $(l, r)$ ($1 \le l \le r \le n$) such that the value of median of $a_l, a_{l+1}, \dots, a_r$ is exactly the given number $m$.
The median of a sequence is the ... | {"inputs": ["1 1\n1\n", "1 1\n2\n", "1 1\n2\n", "1 1\n1\n", "1 1\n0\n", "2 1\n1 2\n", "2 1\n2 1\n", "2 2\n1 2\n"], "outputs": ["1\n", "0\n", "0\n", "1\n", "0\n", "2\n", "2\n", "1\n"]} | coding | 550 |
Solve the programming task below in a Python markdown code block.
There are $n$ bulbs in a straight line, numbered from $\mbox{0}$ to $n-1$.
Each bulb $\boldsymbol{i}$ has a button associated with it, and there is a cost, $c_i$, for pressing this button. When some button $\boldsymbol{i}$ is pressed, all the bulbs at a... | {"inputs": ["3 1\n1 1 1\n"], "outputs": ["1\n"]} | coding | 365 |
Solve the programming task below in a Python markdown code block.
Mark is asked to take a group photo of $2n$ people. The $i$-th person has height $h_i$ units.
To do so, he ordered these people into two rows, the front row and the back row, each consisting of $n$ people. However, to ensure that everyone is seen proper... | {"inputs": ["3\n3 6\n1 3 9 10 12 16\n3 1\n2 5 2 2 2 5\n1 2\n8 6\n"], "outputs": ["YES\nNO\nYES\n"]} | coding | 625 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an array of positive integers nums, remove the smallest subarray (possibly empty) such that the sum of the remaining elements is divisible by p. It is not allowed to remove the whole array.
Return the length of ... | {"functional": "def check(candidate):\n assert candidate(nums = [3,1,4,2], p = 6) == 1\n assert candidate(nums = [6,3,5,2], p = 9) == 2\n assert candidate(nums = [1,2,3], p = 3) == 0\n assert candidate(nums = [1,2,3], p = 7) == -1\n assert candidate(nums = [1000000000,1000000000,1000000000], p = 3) == 0\... | coding | 130 |
Solve the programming task below in a Python markdown code block.
Imagine if there were no order of operations. Instead, you would do the problem from left to right. For example, the equation `$a +b *c /d$` would become `$(((a+b)*c)//d)$` (`Math.floor(((a+b)*c)/d)` in JS). Return `None`/`null` (depending on your langu... | {"functional": "_inputs = [['2 + 3- 4*1 ^ 3'], ['7 * 3 - 3/ 10 0'], ['1 20% 0 + 9'], ['6 9* 2+6 / 0']]\n_outputs = [[1], [0], [None], [None]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isin... | coding | 449 |
Solve the programming task below in a Python markdown code block.
You're fed up about changing the version of your software manually. Instead, you will create a little script that will make it for you.
# Exercice
Create a function `nextVersion`, that will take a string in parameter, and will return a string containin... | {"functional": "_inputs = [['1.2.3'], ['0.9.9'], ['1'], ['1.2.3.4.5.6.7.8'], ['9.9']]\n_outputs = [['1.2.4'], ['1.0.0'], ['2'], ['1.2.3.4.5.6.7.9'], ['10.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 ... | coding | 145 |
Solve the programming task below in a Python markdown code block.
Fukushima Prefecture is also famous for producing fruits, and among them, peaches and apples boast one of the highest production volumes in Japan. By the way, when I made a print manuscript of an English pamphlet for sale, I mistakenly wrote the descript... | {"inputs": ["the cost of one peach is higher than th`t of one apple.", "the cost of ooe peach is higher than th`t of one apple.", "the cost of ooe peach is higher than th`t of eno apple.", "the cpst of ooe peach is higher than th`t of eno apple.", "the cpst of ooe peach is higher than t`ht of eno apple.", "eht cpst of ... | coding | 217 |
Solve the programming task below in a Python markdown code block.
We have a board with a 2 \times N grid.
Snuke covered the board with N dominoes without overlaps.
Here, a domino can cover a 1 \times 2 or 2 \times 1 square.
Then, Snuke decided to paint these dominoes using three colors: red, cyan and green.
Two dominoe... | {"inputs": ["1\nZ\nZ\n", "1\nX\nX\n", "2\nrT\nrT\n", "2\nxj\nxj\n", "2\nEE\nCC\n", "3\naab\nccb\n", "3\nGxx\nGYY\n", "3\nYLm\nYLm\n"], "outputs": ["3\n", "3\n", "6\n", "6\n", "6\n", "6\n", "6\n", "12\n"]} | coding | 357 |
Solve the programming task below in a Python markdown code block.
There are $N$ cells numbered 1,2,….., N, and every cell has some positive value. you will be given an array $A_1$,$A_2$,…,$A_N$ where $A_i$ is the value of $ith$ cell and an integer $K$.
There is a monkey who wants to reach the $right$ side of the last (... | {"inputs": ["1\n2 2\n3 4"], "outputs": ["2"]} | coding | 543 |
Solve the programming task below in a Python markdown code block.
Your task is to write an update for a lottery machine. Its current version produces a sequence of random letters and integers (passed as a string to the function). Your code must filter out all letters and return **unique** integers as a string, in their... | {"functional": "_inputs = [['wQ8Hy0y5m5oshQPeRCkG'], ['ffaQtaRFKeGIIBIcSJtg'], ['555'], ['HappyNewYear2020'], ['20191224isXmas'], ['']]\n_outputs = [['805'], ['One more run!'], ['5'], ['20'], ['20194'], ['One more run!']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\... | coding | 168 |
Solve the programming task below in a Python markdown code block.
Read problems statements in Mandarin Chinese , Russian and Vietnamese
A number is called palindromic if its decimal representation is a palindrome. You are given a range, described by a pair of integers L and R. Find the sum of all palindromic numbers... | {"inputs": ["2\n1 1\n001 5", "2\n1 1\n001 3", "2\n3 0\n001 3", "2\n3 0\n001 1", "2\n0 1\n001 1", "2\n1 3\n101 0", "2\n2 3\n101 0", "2\n3 4\n111 1"], "outputs": ["1\n15\n", "1\n6\n", "0\n6\n", "0\n1\n", "1\n1\n", "6\n0\n", "5\n0\n", "7\n0\n"]} | coding | 362 |
Solve the programming task below in a Python markdown code block.
group()
A group() expression returns one or more subgroups of the match.
Code
>>> import re
>>> m = re.match(r'(\w+)@(\w+)\.(\w+)','username@hackerrank.com')
>>> m.group(0) # The entire match
'username@hackerrank.com'
>>> m.group(1) # Th... | {"inputs": ["..12345678910111213141516171820212223\n"], "outputs": ["1\n"]} | coding | 510 |
Solve the programming task below in a Python markdown code block.
Burger Town is a city that consists of $N$ special junctions and $N-1$ pathways. There is exactly one shortest path between each pair of junctions. Junction $\boldsymbol{i}$ is located at $(x_i,y_i)$ and the distance between two junctions $i,j$ is define... | {"inputs": ["3 2 1\n0 0\n1 1\n2 0\n1 2\n2 3\n"], "outputs": ["1\n"]} | coding | 630 |
Solve the programming task below in a Python markdown code block.
# Making Change
Complete the method that will determine the minimum number of coins needed to make change for a given amount in American currency.
Coins used will be half-dollars, quarters, dimes, nickels, and pennies, worth 50¢, 25¢, 10¢, 5¢ and 1¢, r... | {"functional": "_inputs = [[0], [1], [5], [43], [91], [101], [239]]\n_outputs = [[{}], [{'P': 1}], [{'N': 1}], [{'Q': 1, 'D': 1, 'N': 1, 'P': 3}], [{'H': 1, 'Q': 1, 'D': 1, 'N': 1, 'P': 1}], [{'H': 2, 'P': 1}], [{'H': 4, 'Q': 1, 'D': 1, 'P': 4}]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) ... | coding | 342 |
Solve the programming task below in a Python markdown code block.
problem
JOI decided to make a signboard for the store.
There are N old signboards with letters written at equal intervals. JOI makes a sign by erasing some letters from the old sign. I want the remaining characters to be the name of the store, and the ... | {"inputs": ["4\nbar\nabracadabra\nbear\nbar\nbbraxbara", "4\nrab\nabracadabra\nbear\nbar\nbbraxbara", "4\nrab\nabracadabra\nbear\nbar\narabxarbb", "4\nqab\nabracadabra\nbear\nbar\narabxarbb", "4\nqab\nabracadabra\nbear\nbra\narabxarbb", "4\nqab\nabrbcadaara\nbear\nbra\narabxarbb", "4\nqab\nabrbcadaara\nbear\nbra\narbbx... | coding | 586 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given a 0-indexed integer array nums, return the number of distinct quadruplets (a, b, c, d) such that:
nums[a] + nums[b] + nums[c] == nums[d], and
a < b < c < d
Please complete the following python code precisely... | {"functional": "def check(candidate):\n assert candidate(nums = [1,2,3,6]) == 1\n assert candidate(nums = [3,3,6,4,5]) == 0\n assert candidate(nums = [1,1,1,3,5]) == 4\n\n\ncheck(Solution().countQuadruplets)"} | coding | 106 |
Solve the programming task below in a Python markdown code block.
According to the new tax scheme, a new tax called the binary string tax was introduced! JJ has a binary string S of length N. According to the tax scheme, for every occurrence of 01 in S, a tax of X rupees will be charged, while for every occurrence of 1... | {"inputs": ["2\n4 7 3\n1101\n5 3 4\n00000\n"], "outputs": ["3\n0\n"]} | coding | 462 |
Solve the programming task below in a Python markdown code block.
Mishka is a little polar bear. As known, little bears loves spending their free time playing dice for chocolates. Once in a wonderful sunny morning, walking around blocks of ice, Mishka met her friend Chris, and they started playing the game.
Rules of t... | {"inputs": ["1\n1 1\n", "1\n1 1\n", "1\n1 0\n", "1\n2 1\n", "2\n6 1\n1 6\n", "2\n6 1\n1 8\n", "2\n6 1\n1 6\n", "3\n3 5\n2 1\n4 2\n"], "outputs": ["Friendship is magic!^^", "Friendship is magic!^^\n", "Mishka\n", "Mishka\n", "Friendship is magic!^^", "Friendship is magic!^^\n", "Friendship is magic!^^\n", "Mishka"]} | coding | 539 |
Solve the programming task below in a Python markdown code block.
Vietnamese and Bengali as well.
An $N$-bonacci sequence is an infinite sequence $F_1, F_2, \ldots$ such that for each integer $i > N$, $F_i$ is calculated as $f(F_{i-1}, F_{i-2}, \ldots, F_{i-N})$, where $f$ is some function. A XOR $N$-bonacci sequence i... | {"inputs": ["3 4\n0 1 2\n7\n2\n5\n1000000000"], "outputs": ["3\n1\n0\n0"]} | coding | 541 |
Solve the programming task below in a Python markdown code block.
The numbers 12, 63 and 119 have something in common related with their divisors and their prime factors, let's see it.
```
Numbers PrimeFactorsSum(pfs) DivisorsSum(ds) Is ds divisible by pfs
12 2 + 2 + 3 = 7 1 + 2 + 3 ... | {"functional": "_inputs = [[10, 100], [20, 120], [50, 140]]\n_outputs = [[[12, 15, 35, 42, 60, 63, 66, 68, 84, 90, 95]], [[35, 42, 60, 63, 66, 68, 84, 90, 95, 110, 114, 119]], [[60, 63, 66, 68, 84, 90, 95, 110, 114, 119, 140]]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, fl... | coding | 534 |
Solve the programming task below in a Python markdown code block.
As we know, Danny has a huge army and each time she wins a battle the size of her army is increased. Missandei, her advisor and Handmaiden, keeps the log of each battle and the amount and strength of soldiers won in a battle.
Now, Danny has some questi... | {"inputs": ["5 3\n2 3 1 6 5\n1 2 3 4 5\n2 3\n1 1\n1 5"], "outputs": ["9\n2\n60"]} | coding | 481 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You have n bags numbered from 0 to n - 1. You are given two 0-indexed integer arrays capacity and rocks. The ith bag can hold a maximum of capacity[i] rocks and currently contains rocks[i] rocks. You are also given an... | {"functional": "def check(candidate):\n assert candidate(capacity = [2,3,4,5], rocks = [1,2,4,4], additionalRocks = 2) == 3\n assert candidate(capacity = [10,2,2], rocks = [2,2,0], additionalRocks = 100) == 3\n\n\ncheck(Solution().maximumBags)"} | coding | 152 |
Solve the programming task below in a Python markdown code block.
You have decided to write a book introducing good restaurants.
There are N restaurants that you want to introduce: Restaurant 1, Restaurant 2, ..., Restaurant N. Restaurant i is in city S_i, and your assessment score of that restaurant on a 100-point sca... | {"inputs": ["1\nv 81\n", "6\nrgkkavbtoa 3\nqooqye -1\n`nz^k 4\njabyp 0\nowdnsk 0\njb`qnvtajl 1", "6\nrgkkavbtoa 3\nqooqye -1\n`mz]k 3\npybaj 0\nowdnsk 0\njb`qnvtajl 1", "6\nqgkkavbtoa 3\nqooqye -1\n`mz]k 3\npybaj 0\nowdnsk 0\njb`qnvtajl 1", "6\naotbvakkgq 3\nqooqye -1\n`mz]k 3\npybaj 0\nowdnsk 0\njb`qnvtajl 1", "6\nrgk... | coding | 409 |
Solve the programming task below in a Python markdown code block.
There is a circle with a circumference of L. Each point on the circumference has a coordinate value, which represents the arc length from a certain reference point clockwise to the point. On this circumference, there are N ants. These ants are numbered 1... | {"inputs": ["3 8 3\n0 2\n3 2\n6 1", "2 8 3\n0 1\n3 2\n6 1", "3 8 3\n1 2\n3 2\n6 1", "1 8 3\n1 2\n3 2\n6 1", "1 8 0\n1 2\n3 4\n6 1", "1 8 1\n1 2\n3 4\n6 1", "2 8 3\n1 1\n3 2\n6 1", "1 5 3\n1 2\n6 2\n6 1"], "outputs": ["0\n1\n5\n", "0\n3\n", "0\n1\n6\n", "6\n", "1\n", "0\n", "0\n4\n", "3\n"]} | coding | 416 |
Solve the programming task below in a Python markdown code block.
You will be given an array of strings. The words in the array should mesh together where one or more letters at the end of one word will have the same letters (in the same order) as the next word in the array. But, there are times when all the words won'... | {"functional": "_inputs = [[['beacon', 'condominium', 'umbilical', 'california']], [['allow', 'lowering', 'ringmaster', 'terror']], [['abandon', 'donation', 'onion', 'ongoing']], [['jamestown', 'ownership', 'hippocampus', 'pushcart', 'cartographer', 'pheromone']], [['marker', 'kerchief', 'effortless', 'lesson', 'sonnet... | coding | 424 |
Solve the programming task below in a Python markdown code block.
You are given a sequence of positive integers a_1, a_2, ..., a_{n}.
While possible, you perform the following operation: find a pair of equal consecutive elements. If there are more than one such pair, find the leftmost (with the smallest indices of el... | {"inputs": ["2\n1 1\n", "2\n1 1\n", "3\n2 1 1\n", "3\n2 1 1\n", "4\n3 2 1 1\n", "4\n3 2 1 1\n", "6\n5 2 1 1 2 2\n", "6\n5 3 1 1 2 2\n"], "outputs": ["1\n2 ", "1\n2\n", "1\n3 ", "1\n3\n", "1\n4 ", "1\n4\n", "2\n5 4 ", "3\n5 4 2\n"]} | coding | 683 |
Solve the programming task below in a Python markdown code block.
Carl is a beginner magician. He has a blue, b violet and c orange magic spheres. In one move he can transform two spheres of the same color into one sphere of any other color. To make a spell that has never been seen before, he needs at least x blue, y v... | {"inputs": ["4 4 0\n2 1 2\n", "5 6 1\n2 7 2\n", "3 3 3\n2 2 2\n", "0 0 0\n0 0 0\n", "0 0 0\n0 0 1\n", "0 1 0\n0 0 0\n", "1 0 0\n1 0 0\n", "2 2 1\n1 1 2\n"], "outputs": ["Yes\n", "No\n", "Yes\n", "Yes\n", "No\n", "Yes\n", "Yes\n", "No\n"]} | coding | 366 |
Solve the programming task below in a Python markdown code block.
Nukes has an integer that can be represented as the bitwise OR of one or more integers between A and B (inclusive). How many possible candidates of the value of Nukes's integer there are?
Constraints
* 1 ≤ A ≤ B < 2^{60}
* A and B are integers.
Input
... | {"inputs": ["7\n8", "7\n7", "7\n9", "7\n15", "7\n20", "7\n33", "7\n10", "7\n32"], "outputs": ["3\n", "1\n", "4", "9\n", "25\n", "52\n", "6\n", "51\n"]} | coding | 195 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given a (0-indexed) integer array nums and two integers low and high, return the number of nice pairs.
A nice pair is a pair (i, j) where 0 <= i < j < nums.length and low <= (nums[i] XOR nums[j]) <= high.
Please com... | {"functional": "def check(candidate):\n assert candidate(nums = [1,4,2,7], low = 2, high = 6) == 6\n assert candidate(nums = [9,8,4,2,1], low = 5, high = 14) == 8\n\n\ncheck(Solution().countPairs)"} | coding | 115 |
Solve the programming task below in a Python markdown code block.
A spoonerism is a spoken phrase in which the first letters of two of the words are swapped around, often with amusing results.
In its most basic form a spoonerism is a two word phrase in which only the first letters of each word are swapped:
```"not pi... | {"functional": "_inputs = [['not picking'], ['wedding bells'], ['jelly beans'], ['pop corn']]\n_outputs = [['pot nicking'], ['bedding wells'], ['belly jeans'], ['cop porn']]\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, ... | coding | 290 |
Solve the programming task below in a Python markdown code block.
The number n is Evil if it has an even number of 1's in its binary representation.
The first few Evil numbers: 3, 5, 6, 9, 10, 12, 15, 17, 18, 20
The number n is Odious if it has an odd number of 1's in its binary representation.
The first few Odious num... | {"functional": "_inputs = [[1], [2], [3]]\n_outputs = [[\"It's Odious!\"], [\"It's Odious!\"], [\"It's Evil!\"]]\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 i... | coding | 205 |
Solve the programming task below in a Python markdown code block.
In programming languages like C/C++, a goto statement provides an unconditional jump from the "goto" to a labeled statement. For example, a statement "goto CHECK_NUM;" is executed, control of the program jumps to CHECK_NUM. Using these constructs, you ca... | {"inputs": ["9", "7", "4", "53", "17", "28", "13", "25"], "outputs": [" 3 6 9\n", " 3 6\n", " 3\n", " 3 6 9 12 13 15 18 21 23 24 27 30 31 32 33 34 35 36 37 38 39 42 43 45 48 51 53\n", " 3 6 9 12 13 15\n", " 3 6 9 12 13 15 18 21 23 24 27\n", " 3 6 9 12 13\n", " 3 6 9 12 13 15 18 21 23 24\n"]} | coding | 318 |
Solve the programming task below in a Python markdown code block.
# Task
You're given a substring s of some cyclic string. What's the length of the smallest possible string that can be concatenated to itself many times to obtain this cyclic string?
# Example
For` s = "cabca"`, the output should be `3`
`"cabca"` i... | {"functional": "_inputs = [['cabca'], ['aba'], ['ccccccccccc'], ['abaca']]\n_outputs = [[3], [2], [1], [4]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len... | coding | 165 |
Solve the programming task below in a Python markdown code block.
Chef loves games! But he likes to invent his own. Now he plays game "Digit Jump". Chef has a sequence of digits $S_{1}, S_{2}, \ldots , S_{N}$. He is staying in the first digit $S_{1}$ and wants to reach the last digit $S_{N}$ in the minimal number of ju... | {"inputs": ["6", "0", "94", "60", "49", "50", "75", "18"], "outputs": ["0\n", "0\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n"]} | coding | 367 |
Solve the programming task below in a Python markdown code block.
Shaun was given $N$ pairs of parenthesis ( ) by his teacher who gave him a difficult task.The task consists of two steps. First,Shaun should colour all $N$ pairs of parenthesis each with different color but opening and closing bracket of a particular pa... | {"inputs": ["3\n1\n2\n3"], "outputs": ["1\n6\n90"]} | coding | 472 |
Solve the programming task below in a Python markdown code block.
We have N switches with "on" and "off" state, and M bulbs. The switches are numbered 1 to N, and the bulbs are numbered 1 to M.
Bulb i is connected to k_i switches: Switch s_{i1}, s_{i2}, ..., and s_{ik_i}. It is lighted when the number of switches that ... | {"inputs": ["10 1\n3 7 3 6\n0\n", "10 1\n4 3 5 2 4\n1\n", "2 2\n2 1 2\n1 2\n0 0", "4 2\n2 1 2\n1 2\n0 1", "4 0\n1 1 2\n1 2\n0 1", "7 2\n2 1 2\n1 1\n0 1", "4 2\n1 1 2\n1 2\n0 1", "4 2\n2 1 2\n1 1\n0 1"], "outputs": ["512\n", "512\n", "1\n", "4\n", "16\n", "32\n", "4\n", "4\n"]} | coding | 452 |
Solve the programming task below in a Python markdown code block.
Monk visits the land of Islands. There are a total of N islands numbered from 1 to N. Some pairs of islands are connected to each other by Bidirectional bridges running over water.
Monk hates to cross these bridges as they require a lot of efforts. He ... | {"inputs": ["2\n3 2\n1 2\n2 3\n4 5\n1 2\n2 3\n3 4\n4 2\n1 3"], "outputs": ["2\n2"]} | coding | 259 |
Solve the programming task below in a Python markdown code block.
Takahashi has N days of summer vacation.
His teacher gave him M summer assignments. It will take A_i days for him to do the i-th assignment.
He cannot do multiple assignments on the same day, or hang out on a day he does an assignment.
What is the maximu... | {"inputs": ["1 2\n0 1", "4 6\n2 0", "3 2\n7 4", "3 2\n7 8", "1 2\n7 8", "2 2\n7 8", "2 2\n6 8", "0 2\n6 8"], "outputs": ["0\n", "2\n", "-1\n", "-1\n", "-1\n", "-1\n", "-1\n", "-1\n"]} | coding | 286 |
Solve the programming task below in a Python markdown code block.
Alice and Bob play a game. There is a paper strip which is divided into n + 1 cells numbered from left to right starting from 0. There is a chip placed in the n-th cell (the last one).
Players take turns, Alice is first. Each player during his or her tu... | {"inputs": ["1\n9 3\n", "1\n8 2\n", "1\n3 7\n", "1\n2 7\n", "1\n0 4\n", "1\n25 6\n", "1\n24 6\n", "1\n25 6\n"], "outputs": ["Alice\n", "Alice\n", "Bob\n", "Alice\n", "Bob\n", "Alice\n", "Bob\n", "Alice\n"]} | coding | 344 |
Solve the programming task below in a Python markdown code block.
There is a given sequence of integers a1, a2, ..., an, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other.
Input
The first line contains... | {"inputs": ["1\n1\n", "1\n3\n", "1\n2\n", "2\n3 2\n", "2\n2 1\n", "2\n3 1\n", "2\n1 2\n", "2\n2 3\n"], "outputs": ["0\n", "0\n", "0\n", "1\n", "1\n", "1\n", "1\n", "1\n"]} | coding | 182 |
Solve the programming task below in a Python markdown code block.
You are given an integer sequence $A_1, A_2, \ldots, A_N$. For any pair of integers $(l, r)$ such that $1 \le l \le r \le N$, let's define $\mathrm{OR}(l, r)$ as $A_l \lor A_{l+1} \lor \ldots \lor A_r$. Here, $\lor$ is the bitwise OR operator.
In total, ... | {"inputs": ["4\n3\n1 2 7\n2\n1 2\n3\n6 5 8\n5\n12 32 45 23 47"], "outputs": ["NO\nYES\nYES\nNO"]} | coding | 564 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
There is a broken calculator that has the integer startValue on its display initially. In one operation, you can:
multiply the number on display by 2, or
subtract 1 from the number on display.
Given two integers sta... | {"functional": "def check(candidate):\n assert candidate(startValue = 2, target = 3) == 2\n assert candidate(startValue = 5, target = 8) == 2\n assert candidate(startValue = 3, target = 10) == 3\n\n\ncheck(Solution().brokenCalc)"} | coding | 117 |
Solve the programming task below in a Python markdown code block.
Read problems statements [Hindi] , [Vietnamese] , [Mandarin Chinese] , [Russian] and [Bengali] as well.
"Every beginning has an end... and an editorial." - taran_{1407}
What the hell are all these interactive problems? What does flushing output mean? S... | {"inputs": ["2 1500\n1499\n1501"], "outputs": ["Bad boi\nGood boi"]} | coding | 366 |
Solve the programming task below in a Python markdown code block.
Chef has $N$ small boxes arranged on a line from $1$ to $N$. For each valid $i$, the weight of the $i$-th box is $W_i$. Chef wants to bring them to his home, which is at the position $0$. He can hold any number of boxes at the same time; however, the tot... | {"inputs": ["4\n1 1\n2\n2 4\n1 1\n3 6\n3 4 2\n3 6\n3 4 3"], "outputs": ["-1\n1\n2\n3"]} | coding | 529 |
Solve the programming task below in a Python markdown code block.
Alice and Bob are playing a game. They have an array of positive integers $a$ of size $n$.
Before starting the game, Alice chooses an integer $k \ge 0$. The game lasts for $k$ stages, the stages are numbered from $1$ to $k$. During the $i$-th stage, Ali... | {"inputs": ["7\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n", "4\n3\n1 1 2\n4\n4 4 4 4\n1\n1\n5\n1 3 2 1 1\n", "13\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n", "13\n2\n1 1\n2\n1 1\n2\n1 1\n2\n1 1\n2\n1 1\n2\n1 1\n2\n1 1\n2\n1 1\n2\n1 1\n2\n1 1\n2\n1 1\n2\n1 1\n2\n1 1\n"], "outputs": ... | coding | 423 |
Solve the programming task below in a Python markdown code block.
An array is sorted if it has no inversions
A Young Boy
You are given an array of $n$ positive integers $a_1,a_2,\ldots,a_n$.
In one operation you do the following:
Choose any integer $x$.
For all $i$ such that $a_i = x$, do $a_i := 0$ (assign $0$ to... | {"inputs": ["5\n3\n3 3 2\n4\n1 3 1 3\n5\n4 1 5 3 2\n4\n2 4 1 2\n1\n1\n"], "outputs": ["1\n2\n4\n3\n0\n"]} | coding | 425 |
Solve the programming task below in a Python markdown code block.
Timur likes his name. As a spelling of his name, he allows any permutation of the letters of the name. For example, the following strings are valid spellings of his name: Timur, miurT, Trumi, mriTu. Note that the correct spelling must have uppercased T a... | {"inputs": ["1\n6\nTimura\n", "10\n5\nTimur\n5\nmiurT\n5\nTrumi\n5\nmriTu\n5\ntimur\n4\nTimr\n6\nTimuur\n10\ncodeforces\n10\nTimurTimur\n5\nTIMUR\n"], "outputs": ["NO\n", "YES\nYES\nYES\nYES\nNO\nNO\nNO\nNO\nNO\nNO\n"]} | coding | 374 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
There are n rooms you need to visit, labeled from 0 to n - 1. Each day is labeled, starting from 0. You will go in and visit one room a day.
Initially on day 0, you visit room 0. The order you visit the rooms for the ... | {"functional": "def check(candidate):\n assert candidate(nextVisit = [0,0]) == 2\n assert candidate(nextVisit = [0,0,2]) == 6\n assert candidate(nextVisit = [0,1,2,0]) == 6\n\n\ncheck(Solution().firstDayBeenInAllRooms)"} | coding | 278 |
Solve the programming task below in a Python markdown code block.
A histogram is made of a number of contiguous bars, which have same width.
For a given histogram with $N$ bars which have a width of 1 and a height of $h_i$ = $h_1, h_2, ... , h_N$ respectively, find the area of the largest rectangular area.
Constraint... | {"inputs": ["3\n3 0 1", "3\n5 0 0", "3\n0 0 0", "3\n0 0 1", "3\n2 0 2", "3\n6 1 0", "3\n4 1 2", "3\n7 2 1"], "outputs": ["3\n", "5\n", "0\n", "1\n", "2\n", "6\n", "4\n", "7\n"]} | coding | 192 |
Solve the programming task below in a Python markdown code block.
You are given an integer $x$ and an array of integers $a_1, a_2, \ldots, a_n$. You have to determine if the number $a_1! + a_2! + \ldots + a_n!$ is divisible by $x!$.
Here $k!$ is a factorial of $k$ — the product of all positive integers less than or eq... | {"inputs": ["1 1\n1\n", "1 2\n2\n", "1 5\n3\n", "2 3\n2 1\n", "2 10\n1 1\n", "1 500000\n1\n", "5 2\n2 1 1 1 1\n", "6 4\n3 2 2 2 3 3\n"], "outputs": ["Yes\n", "Yes\n", "No\n", "No\n", "No\n", "No\n", "Yes\n", "Yes\n"]} | coding | 606 |
Solve the programming task below in a Python markdown code block.
Create a function that takes a string and returns that
string with the first half lowercased and the last half uppercased.
eg: foobar == fooBAR
If it is an odd number then 'round' it up to find which letters to uppercase. See example below.
sillyc... | {"functional": "_inputs = [['foobar'], ['codewars'], ['jAvASCript'], ['brian'], ['jabberwock'], ['SCOTland'], ['WeLlDoNe']]\n_outputs = [['fooBAR'], ['codeWARS'], ['javasCRIPT'], ['briAN'], ['jabbeRWOCK'], ['scotLAND'], ['wellDONE']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance... | coding | 131 |
Solve the programming task below in a Python markdown code block.
Roman and Denis are on the trip to the programming competition. Since the trip was long, they soon got bored, and hence decided to came up with something. Roman invented a pizza's recipe, while Denis invented a string multiplication. According to Denis, ... | {"inputs": ["3\na\nb\na\n", "2\nbnn\na\n", "2\nnbn\na\n", "2\nbnn\na\n", "3\na\nb\na\n", "6\nw\ng\nc\nj\ny\nf\n", "6\nw\ng\nc\nj\ny\nf\n", "6\nw\nh\nc\nj\ny\nf\n"], "outputs": ["3\n", "1\n", "1\n", "1", "3", "1\n", "1", "1\n"]} | coding | 680 |
Solve the programming task below in a Python markdown code block.
Mike is trying rock climbing but he is awful at it.
There are n holds on the wall, i-th hold is at height a_{i} off the ground. Besides, let the sequence a_{i} increase, that is, a_{i} < a_{i} + 1 for all i from 1 to n - 1; we will call such sequence a... | {"inputs": ["3\n1 4 6\n", "3\n2 4 6\n", "3\n1 4 6\n", "3\n2 7 1000\n", "5\n1 2 3 4 5\n", "5\n1 2 3 7 8\n", "3\n30 61 381\n", "3\n30 55 539\n"], "outputs": ["5\n", "4\n", "5\n", "998\n", "2\n", "4\n", "351\n", "509\n"]} | coding | 621 |
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 representing the score of students in an exam. The teacher would like to form one non-empty group of students with maximal strength, where the strength of a group of studen... | {"functional": "def check(candidate):\n assert candidate(nums = [3,-1,-5,2,5,-9]) == 1350\n assert candidate(nums = [-4,-5,-4]) == 20\n\n\ncheck(Solution().maxStrength)"} | coding | 143 |
Solve the programming task below in a Python markdown code block.
Mohit(Ex GenSec ) is the most active member of the roasting club who loves giving tasks to other members. One day he observed that none of the members were paying attention to the online classes, so he decided to have some fun and overcome the boring lec... | {"inputs": ["5 4\n7\n12\n10\n1"], "outputs": ["17\n22\n20\n20"]} | coding | 346 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
A value-equal string is a string where all characters are the same.
For example, "1111" and "33" are value-equal strings.
In contrast, "123" is not a value-equal string.
Given a digit string s, decompose the string ... | {"functional": "def check(candidate):\n assert candidate(s = \"000111000\") == False\n assert candidate(s = \"00011111222\") == True\n assert candidate(s = \"01110002223300\") == False\n\n\ncheck(Solution().isDecomposable)"} | coding | 173 |
Solve the programming task below in a Python markdown code block.
Ravi is very good student in mathematics and he also like Even numbers very much .
On the other hand his friend Jhon like Odd numbers . Both of them are preparing for IIT JEE Advance .One day they are solving a question together the question was Find t... | {"inputs": ["2\n3"], "outputs": ["Jhon\nRavi"]} | coding | 367 |
Solve the programming task below in a Python markdown code block.
I need to save some money to buy a gift. I think I can do something like that:
First week (W0) I save nothing on Sunday, 1 on Monday, 2 on Tuesday... 6 on Saturday,
second week (W1) 2 on Monday... 7 on Saturday and so on according to the table below whe... | {"functional": "_inputs = [[5], [6], [8], [15], [100], [365], [730], [999], [2000], [4000], [5000]]\n_outputs = [[105], [168], [360], [2040], [515100], [24513765], [195308580], [499999500], [4006002000], [32024004000], [62537505000]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance... | coding | 469 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.