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.
Write a program which prints $n$-th fibonacci number for a given integer $n$. The $n$-th fibonacci number is defined by the following recursive formula:
\begin{equation*} fib(n)= \left \\{ \begin{array}{ll} 1 & (n = 0) \\\ 1 & (n = 1) \\\ fib(n - 1) + f... | {"inputs": ["1", "2", "4", "8", "6", "7", "5", "9"], "outputs": ["1\n", "2\n", "5\n", "34\n", "13\n", "21\n", "8\n", "55\n"]} | coding | 157 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given two images, img1 and img2, represented as binary, square matrices of size n x n. A binary matrix has only 0s and 1s as values.
We translate one image however we choose by sliding all the 1 bits left, rig... | {"functional": "def check(candidate):\n assert candidate(img1 = [[1,1,0],[0,1,0],[0,1,0]], img2 = [[0,0,0],[0,1,1],[0,0,1]]) == 3\n assert candidate(img1 = [[1]], img2 = [[1]]) == 1\n assert candidate(img1 = [[0]], img2 = [[0]]) == 0\n\n\ncheck(Solution().largestOverlap)"} | coding | 190 |
Solve the programming task below in a Python markdown code block.
We have a tree with N vertices. Vertex 1 is the root of the tree, and the parent of Vertex i (2 \leq i \leq N) is Vertex P_i.
To each vertex in the tree, Snuke will allocate a color, either black or white, and a non-negative integer weight.
Snuke has a f... | {"inputs": ["1\n\n1", "1\n\n2", "1\n\n3", "1\n\n6", "1\n\n9", "1\n\n4", "1\n\n5", "1\n\n8"], "outputs": ["POSSIBLE\n", "POSSIBLE\n", "POSSIBLE\n", "POSSIBLE\n", "POSSIBLE\n", "POSSIBLE\n", "POSSIBLE\n", "POSSIBLE\n"]} | coding | 401 |
Solve the programming task below in a Python markdown code block.
Karan likes the number 4 very much.
Impressed by the power of this number, Karan has begun to look for occurrences of four anywhere. He has a list of T integers, for each of them he wants to calculate the number of occurrences of the digit 4 in the deci... | {"inputs": ["5\n447474\n228\n6664\n40\n81\n"], "outputs": ["4\n0\n1\n1\n0\n"]} | coding | 273 |
Solve the programming task below in a Python markdown code block.
Chef is playing a videogame, and is getting close to the end. He decides to finish the rest of the game in a single session.
There are X levels remaining in the game, and each level takes Chef Y minutes to complete. To protect against eye strain, Chef a... | {"inputs": ["4\n2 12 10\n3 12 10\n7 20 8\n24 45 15\n"], "outputs": ["24\n36\n156\n1185"]} | coding | 300 |
Solve the programming task below in a Python markdown code block.
Mathison recently inherited an ancient papyrus that contained some text. Unfortunately, the text was not a
pangram. Now, Mathison has a particular liking for holoalphabetic strings and the text bothers him. The good news is that Mathison can buy letters ... | {"inputs": ["2\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26\nabcdefghijklmopqrstuvwz\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26\nthequickbrownfoxjumpsoverthelazydog"], "outputs": ["63\n0"]} | coding | 581 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given two strings s and t. In one step, you can append any character to either s or t.
Return the minimum number of steps to make s and t anagrams of each other.
An anagram of a string is a string that contain... | {"functional": "def check(candidate):\n assert candidate(s = \"leetcode\", t = \"coats\") == 7\n assert candidate(s = \"night\", t = \"thing\") == 0\n\n\ncheck(Solution().minSteps)"} | coding | 116 |
Solve the programming task below in a Python markdown code block.
You have an award-winning garden and everyday the plants need exactly 40mm of water. You created a great piece of JavaScript to calculate the amount of water your plants will need when you have taken into consideration the amount of rain water that is fo... | {"functional": "_inputs = [[100], [40], [39], [5], [0]]\n_outputs = [['Your plant has had more than enough water for today!'], ['Your plant has had more than enough water for today!'], ['You need to give your plant 1mm of water'], ['You need to give your plant 35mm of water'], ['You need to give your plant 40mm of wate... | coding | 114 |
Solve the programming task below in a Python markdown code block.
In a coding contest, there are two types of problems:
Easy problems, which are worth 1 point each
Hard problems, which are worth 2 points each
To qualify for the next round, a contestant must score at least X points. Chef solved A Easy problems and B H... | {"inputs": ["3\n15 9 3\n5 3 0\n6 2 8\n"], "outputs": ["Qualify\nNotQualify\nQualify\n"]} | coding | 489 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
A perfect number is a positive integer that is equal to the sum of its positive divisors, excluding the number itself. A divisor of an integer x is an integer that can divide x evenly.
Given an integer n, return true ... | {"functional": "def check(candidate):\n assert candidate(num = 28) == True\n assert candidate(num = 7) == False\n\n\ncheck(Solution().checkPerfectNumber)"} | coding | 105 |
Solve the programming task below in a Python markdown code block.
For given two sequences $X$ and $Y$, a sequence $Z$ is a common subsequence of $X$ and $Y$ if $Z$ is a subsequence of both $X$ and $Y$. For example, if $X = \\{a,b,c,b,d,a,b\\}$ and $Y = \\{b,d,c,a,b,a\\}$, the sequence $\\{b,c,a\\}$ is a common subseque... | {"inputs": ["3\nabcbdab\nbdcaba\nabc\nabc\nacb\nbc", "3\nabcbdab\nbdcaba\nabc\nabc\nbcb\nbc", "3\nabcbdab\nbdcaba\n`bc\nabc\nbcb\nbc", "3\nbadbcba\nbdcaba\n`bc\nabc\nbcb\nbc", "3\nbadbdba\nbdcaba\n`bc\nabc\nbcb\ncc", "3\nbadbdba\nbdcaba\n`bc\nabd\nbcb\ncc", "3\nbadbdba\nabacdb\n_cb\ndba\nbbb\ncc", "3\n`bdbdab\nabacdb\n... | coding | 428 |
Solve the programming task below in a Python markdown code block.
There are N candles placed on a number line.
The i-th candle from the left is placed on coordinate x_i.
Here, x_1 < x_2 < ... < x_N holds.
Initially, no candles are burning.
Snuke decides to light K of the N candles.
Now, he is at coordinate 0.
He can mo... | {"inputs": ["1 1\n0", "1 1\n0\n", "3 2\n10 18 30", "3 2\n10 20 43", "3 2\n10 22 30", "3 2\n10 11 30", "3 3\n12 20 60", "3 3\n5 26 149"], "outputs": ["0", "0\n", "18\n", "20\n", "22\n", "11\n", "60\n", "149\n"]} | coding | 334 |
Solve the programming task below in a Python markdown code block.
A teacher asks the class to open their books to a page number. A student can either start turning pages from the front of the book or from the back of the book. They always turn pages one at a time. When they open the book, page $1$ is always on the rig... | {"inputs": ["6\n2\n", "5\n4\n"], "outputs": ["1\n", "0\n"]} | coding | 559 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given a string s, return the number of substrings that have only one distinct letter.
Please complete the following python code precisely:
```python
class Solution:
def countLetters(self, s: str) -> int:
``` | {"functional": "def check(candidate):\n assert candidate(s = \"aaaba\") == 8\n assert candidate(s = \"aaaaaaaaaa\") == 55\n\n\ncheck(Solution().countLetters)"} | coding | 65 |
Solve the programming task below in a Python markdown code block.
You are given an unweighted tree with N$N$ nodes (numbered 1$1$ through N$N$). Let's denote the distance between any two nodes p$p$ and q$q$ by d(p,q)$d(p, q)$.
You should answer Q$Q$ queries. In each query, you are given parameters a$a$, da$d_a$, b$b$, ... | {"inputs": ["1\n5 3\n1 2\n2 3\n3 4\n3 5\n2 1 4 1\n2 2 4 2\n1 1 2 1"], "outputs": ["3\n5\n-1"]} | coding | 676 |
Solve the programming task below in a Python markdown code block.
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well.
Chef is a well known programmer. He owns a brand new Android phone of screen size of dimension n × m (n denotes the height of the phone and m denotes the width). Chef wants t... | {"inputs": ["2\n4 6 12\n3 3 10"], "outputs": ["3\n0"]} | coding | 498 |
Solve the programming task below in a Python markdown code block.
Roma is playing a new expansion for his favorite game World of Darkraft. He made a new character and is going for his first grind.
Roma has a choice to buy exactly one of n different weapons and exactly one of m different armor sets. Weapon i has attack... | {"inputs": ["1 2 1\n2 2\n2 1\n2 2\n1 1 1\n", "1 1 1\n1 100\n1 100\n2 2 1\n", "1 2 1\n2 2\n2 1\n2 3\n1 1 1\n", "1 1 1\n1 100\n1 100\n2 4 1\n", "1 2 1\n2 2\n1 1\n2 3\n1 1 1\n", "1 2 1\n2 2\n2 1\n1 3\n1 1 1\n", "1 1 1\n1 100\n1 100\n2 0 1\n", "1 2 1\n2 2\n2 1\n1 2\n1 1 1\n"], "outputs": ["-2\n", "-200\n", "-2", "-200", "-... | coding | 631 |
Solve the programming task below in a Python markdown code block.
After their adventure with the magic mirror Kay and Gerda have returned home and sometimes give free ice cream to kids in the summer.
At the start of the day they have x ice cream packs. Since the ice cream is free, people start standing in the queue be... | {"inputs": ["1 0\n+ 1\n", "1 0\n- 1\n", "1 3\n- 5\n", "1 0\n- 5\n", "1 0\n+ 5\n", "1 0\n+ 1\n", "1 0\n- 5\n", "1 3\n- 5\n"], "outputs": ["1 0\n", "0 1\n", "3 1\n", "0 1\n", "5 0\n", "1 0\n", "0 1\n", "3 1\n"]} | coding | 592 |
Solve the programming task below in a Python markdown code block.
The academic year has just begun, but lessons and olympiads have already occupied all the free time. It is not a surprise that today Olga fell asleep on the Literature. She had a dream in which she was on a stairs.
The stairs consists of n steps. The s... | {"inputs": ["1\nD\n", "1\nD\n", "1\nU\n", "1\nD\n", "1\nU\n", "2\nDU\n", "2\nDU\n", "2\nUD\n"], "outputs": ["1 ", "1 ", "1 ", "1\n", "1\n", "1 1 ", "1 1\n", "3 3 "]} | coding | 555 |
Solve the programming task below in a Python markdown code block.
Happy traveller [Part 1]
There is a play grid NxN; Always square!
0 1 2 3
0 [o, o, o, X]
1 [o, o, o, o]
2 [o, o, o, o]
3 [o, o, o, o]
You start from a random point. I mean, you are given the coordinates of your start position in format (row, c... | {"functional": "_inputs = [[1, [0, 0]], [2, [1, 0]], [2, [1, 1]], [3, [1, 0]], [5, [4, 0]], [6, [5, 0]], [7, [6, 0]]]\n_outputs = [[0], [2], [1], [3], [70], [252], [924]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs... | coding | 521 |
Solve the programming task below in a Python markdown code block.
Tracy loves Donuts. She purchased a lots of Donuts for her birthday party. She learnt to calculate the area of the circle a few days back and she is fascinated to know the area of the donuts as well !! Help her finding the area of the Donuts…..
-----Inp... | {"inputs": ["2\n5\n12"], "outputs": ["78.5\n452.16"]} | coding | 179 |
Solve the programming task below in a Python markdown code block.
Yaroslav thinks that two strings s and w, consisting of digits and having length n are non-comparable if there are two numbers, i and j (1 ≤ i, j ≤ n), such that s_{i} > w_{i} and s_{j} < w_{j}. Here sign s_{i} represents the i-th digit of string s, simi... | {"inputs": ["1\n?\n?\n", "1\n?\n?\n", "2\n90\n09\n", "2\n11\n55\n", "2\n12\n?9\n", "2\n12\n?9\n", "2\n39\n09\n", "2\n11\n61\n"], "outputs": ["0\n", "0", "1\n", "0\n", "1\n", "1", "0\n", "0\n"]} | coding | 432 |
Solve the programming task below in a Python markdown code block.
Petya's friends made him a birthday present — a bracket sequence. Petya was quite disappointed with his gift, because he dreamed of correct bracket sequence, yet he told his friends nothing about his dreams and decided to fix present himself.
To make e... | {"inputs": ["1\n)\n", "1\n(\n", "1\n(\n", "1\n)\n", "2\n)(\n", "2\n()\n", "2\n((\n", "2\n((\n"], "outputs": ["No\n", "No\n", "No\n", "No\n", "Yes\n", "Yes\n", "No\n", "No\n"]} | coding | 466 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an array points where points[i] = [xi, yi] represents a point on the X-Y plane, return true if these points are a boomerang.
A boomerang is a set of three points that are all distinct and not in a straight line.... | {"functional": "def check(candidate):\n assert candidate(points = [[1,1],[2,3],[3,2]]) == True\n assert candidate(points = [[1,1],[2,2],[3,3]]) == False\n\n\ncheck(Solution().isBoomerang)"} | coding | 106 |
Solve the programming task below in a Python markdown code block.
Once Vasya played bricks. All the bricks in the set had regular cubical shape. Vasya vas a talented architect, however the tower he built kept falling apart.
Let us consider the building process. Vasya takes a brick and puts it on top of the already bui... | {"inputs": ["1\n0 0 1 1\n", "1\n0 0 2 1\n", "1\n0 0 4 1\n", "1\n-50 -50 50 50\n", "1\n-50 -93 50 50\n", "2\n0 0 4 3\n1 0 4 3\n", "2\n0 0 3 3\n1 0 4 3\n", "2\n0 0 3 3\n2 0 5 3\n"], "outputs": ["1", "1", "1", "1", "1", "2", "2", "1"]} | coding | 634 |
Solve the programming task below in a Python markdown code block.
The Little Elephant loves Ukraine very much. Most of all he loves town Rozdol (ukr. "Rozdil").
However, Rozdil is dangerous to settle, so the Little Elephant wants to go to some other town. The Little Elephant doesn't like to spend much time on travelli... | {"inputs": ["1\n47\n", "1\n76\n", "1\n71\n", "1\n22\n", "1\n31\n", "1\n16\n", "1\n15\n", "1\n127\n"], "outputs": ["1", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n"]} | coding | 433 |
Solve the programming task below in a Python markdown code block.
You are given $n$ elements numbered from $1$ to $n$, the element $i$ has value $a_i$ and color $c_i$, initially, $c_i = 0$ for all $i$.
The following operation can be applied:
Select three elements $i$, $j$ and $k$ ($1 \leq i < j < k \leq n$), such tha... | {"inputs": ["3\n1 1 2\n", "3\n1 1 1\n", "3\n1 2 1\n", "3\n1 2 2\n", "3\n1 2 3\n", "7\n1 2 1 2 7 4 7\n", "13\n1 2 3 2 1 3 3 4 5 5 5 4 7\n"], "outputs": ["0\n", "1\n", "1\n", "0\n", "0\n", "2\n", "7\n"]} | coding | 386 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are a hiker preparing for an upcoming hike. You are given heights, a 2D array of size rows x columns, where heights[row][col] represents the height of cell (row, col). You are situated in the top-left cell, (0, 0)... | {"functional": "def check(candidate):\n assert candidate(heights = [[1,2,2],[3,8,2],[5,3,5]]) == 2\n assert candidate(heights = [[1,2,3],[3,8,4],[5,3,5]]) == 1\n assert candidate(heights = [[1,2,1,1,1],[1,2,1,2,1],[1,2,1,2,1],[1,2,1,2,1],[1,1,1,2,1]]) == 0\n\n\ncheck(Solution().minimumEffortPath)"} | coding | 200 |
Solve the programming task below in a Python markdown code block.
The only difference between easy and hard versions is constraints.
The BerTV channel every day broadcasts one episode of one of the $k$ TV shows. You know the schedule for the next $n$ days: a sequence of integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le ... | {"inputs": ["4\n5 2 2\n1 2 1 2 1\n9 3 3\n3 3 3 2 2 2 1 1 1\n4 10 4\n10 8 6 4\n16 9 8\n3 1 4 1 5 9 2 6 5 3 5 8 9 7 9 3\n", "4\n5 2 2\n1 2 1 2 1\n9 3 3\n3 3 3 3 2 2 1 1 1\n4 10 4\n10 8 6 4\n16 9 8\n3 1 4 1 5 9 2 6 5 3 5 8 9 7 9 3\n", "4\n5 2 2\n1 2 1 2 1\n9 3 3\n3 3 3 2 2 2 1 1 1\n4 10 4\n10 8 6 4\n16 9 8\n3 1 4 1 5 9 2 ... | coding | 744 |
Solve the programming task below in a Python markdown code block.
>
**Note**: This kata is a translation of this (Java) one: http://www.codewars.com/kata/rotate-array. I have not translated this first one as usual because I did not solved it, and I fear not being able to solve it (Java is **not** my cup of... tea). @c... | {"functional": "_inputs = [[['a', 'b', 'c'], 1], [[1.0, 2.0, 3.0], 1], [[True, True, False], 1]]\n_outputs = [[['c', 'a', 'b']], [[3.0, 1.0, 2.0]], [[False, True, True]]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs... | coding | 703 |
Solve the programming task below in a Python markdown code block.
There are $b$ boys and $g$ girls participating in Olympiad of Metropolises. There will be a board games tournament in the evening and $n$ participants have accepted the invitation. The organizers do not know how many boys and girls are among them.
Organ... | {"inputs": ["5\n6\n3\n", "5\n3\n5\n", "1\n1\n1\n", "1\n1\n2\n", "3\n3\n4\n", "4\n4\n5\n", "4\n4\n7\n", "3\n3\n5\n"], "outputs": ["4\n", "4\n", "2\n", "1\n", "3\n", "4\n", "2\n", "2\n"]} | coding | 445 |
Solve the programming task below in a Python markdown code block.
You are given a string S as input. This represents a valid date in the year 2019 in the yyyy/mm/dd format. (For example, April 30, 2019 is represented as 2019/04/30.)
Write a program that prints Heisei if the date represented by S is not later than April... | {"inputs": ["2019/03/30", "2019/11/00", "2019/04/20", "2019/12/01", "2019/14/20", "2119/12/01", "2019/24/10", "1019/04/30"], "outputs": ["Heisei\n", "TBD \n", "Heisei\n", "TBD \n", "TBD \n", "TBD \n", "TBD \n", "Heisei\n"]} | coding | 204 |
Solve the programming task below in a Python markdown code block.
Snuke Festival 2017 will be held in a tree with N vertices numbered 1,2, ...,N. The i-th edge connects Vertex a_i and b_i, and has joyfulness c_i.
The staff is Snuke and N-1 black cats. Snuke will set up the headquarters in some vertex, and from there h... | {"inputs": ["3\n1 3 6\n2 3 4", "3\n1 3 3\n2 3 20", "3\n1 3 6\n2 3 20", "3\n1 3 4\n2 3 20", "3\n1 3 4\n2 3 21", "3\n1 3 8\n2 3 20", "3\n1 3 4\n2 1 20", "3\n1 3 10\n2 3 20"], "outputs": ["10\n8\n10\n", "6\n23\n23\n", "12\n26\n26\n", "8\n24\n24\n", "8\n25\n25\n", "16\n28\n28\n", "24\n24\n8\n", "20\n30\n30\n"]} | coding | 738 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given an m x n binary matrix grid.
In one operation, you can choose any row or column and flip each value in that row or column (i.e., changing all 0's to 1's, and all 1's to 0's).
Return true if it is possibl... | {"functional": "def check(candidate):\n assert candidate(grid = [[0,1,0],[1,0,1],[0,1,0]]) == True\n assert candidate(grid = [[1,1,0],[0,0,0],[0,0,0]]) == False\n assert candidate(grid = [[0]]) == True\n\n\ncheck(Solution().removeOnes)"} | coding | 128 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an integer array arr, return the number of distinct bitwise ORs of all the non-empty subarrays of arr.
The bitwise OR of a subarray is the bitwise OR of each integer in the subarray. The bitwise OR of a subarray... | {"functional": "def check(candidate):\n assert candidate(arr = [0]) == 1\n assert candidate(arr = [1,1,2]) == 3\n assert candidate(arr = [1,2,4]) == 6\n\n\ncheck(Solution().subarrayBitwiseORs)"} | coding | 124 |
Solve the programming task below in a Python markdown code block.
There are N people numbered from 1 to N such that:
Exactly one of these people is a thief and always lies;
All the others are honest and always tell the truth.
If the i^{th} person claims that the thief is one person out of L_{i}, L_{i}+1, L_{i}+2, \cd... | {"inputs": ["1\n4\n2 2\n1 1\n1 3\n1 3"], "outputs": ["2\n1\n2"]} | coding | 593 |
Solve the programming task below in a Python markdown code block.
There are $n$ robbers at coordinates $(a_1, b_1)$, $(a_2, b_2)$, ..., $(a_n, b_n)$ and $m$ searchlight at coordinates $(c_1, d_1)$, $(c_2, d_2)$, ..., $(c_m, d_m)$.
In one move you can move each robber to the right (increase $a_i$ of each robber by one... | {"inputs": ["1 1\n0 0\n2 3\n", "1 1\n0 0\n0 0\n", "1 1\n0 0\n0 0\n", "1 1\n0 0\n2 3\n", "1 2\n0 0\n0 0\n0 0\n", "2 1\n0 0\n0 0\n0 0\n", "2 1\n0 0\n0 0\n0 0\n", "1 2\n1 0\n0 0\n0 0\n"], "outputs": ["3\n", "1\n", "1\n", "3\n", "1\n", "1\n", "1\n", "0\n"]} | coding | 700 |
Solve the programming task below in a Python markdown code block.
Henry and Derek are waiting on a room, eager to join the Snackdown 2016 Qualifier Round. They decide to pass the time by playing a game.
In this game's setup, they write N positive integers on a blackboard. Then the players take turns, starting with He... | {"inputs": ["2\n2\n3 4\n3\n1 3 5"], "outputs": ["Henry\nDerek"]} | coding | 682 |
Solve the programming task below in a Python markdown code block.
DestinyLand is a really fun place for kids. It is composed of N islands, numbered from 1 to N. The company is planning to divide these N islands into exactly M area, such that, each island will belong to one of the M areas, and each area will contain at ... | {"inputs": ["3\n3 2 1 1000003\n3 1 2 1234567891\n3 1 1 314159\n"], "outputs": ["6\n9\n6\n"]} | coding | 388 |
Solve the programming task below in a Python markdown code block.
Your search for Heidi is over – you finally found her at a library, dressed up as a human. In fact, she has spent so much time there that she now runs the place! Her job is to buy books and keep them at the library so that people can borrow and read them... | {"inputs": ["1 1\n1\n", "1 1\n1\n", "4 1\n1 2 2 1\n", "4 2\n1 2 3 1\n", "4 2\n1 2 3 2\n", "4 2\n1 2 3 2\n", "4 2\n1 2 3 1\n", "4 1\n1 2 2 1\n"], "outputs": ["1\n", "1\n", "3\n", "3\n", "3\n", "3\n", "3\n", "3\n"]} | coding | 667 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right, which minimizes the sum of all numbers along its path.
Note: You can only move either down or right at any point in time.... | {"functional": "def check(candidate):\n assert candidate(grid = [[1,3,1],[1,5,1],[4,2,1]]) == 7\n assert candidate(grid = [[1,2,3],[4,5,6]]) == 12\n\n\ncheck(Solution().minPathSum)"} | coding | 100 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You want to schedule a list of jobs in d days. Jobs are dependent (i.e To work on the ith job, you have to finish all the jobs j where 0 <= j < i).
You have to finish at least one task every day. The difficulty of a j... | {"functional": "def check(candidate):\n assert candidate(jobDifficulty = [6,5,4,3,2,1], d = 2) == 7\n assert candidate(jobDifficulty = [9,9,9], d = 4) == -1\n assert candidate(jobDifficulty = [1,1,1], d = 3) == 3\n assert candidate(jobDifficulty = [7,1,7,1,7,1], d = 3) == 15\n assert candidate(jobDifficu... | coding | 187 |
Solve the programming task below in a Python markdown code block.
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
Dr.D got so famous thanks to his first problem that he decided to commemorate it by making yet another problem with an almost identical statement — he only cha... | {"inputs": ["4\n1 3\n4 5\n1031 93714\n1000000000123 1000000123456"], "outputs": ["3\n5\n131071\n1000000192511"]} | coding | 306 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
A fancy string is a string where no three consecutive characters are equal.
Given a string s, delete the minimum possible number of characters from s to make it fancy.
Return the final string after the deletion. It ca... | {"functional": "def check(candidate):\n assert candidate(s = \"leeetcode\") == \"leetcode\"\n assert candidate(s = \"aaabaaaa\") == \"aabaa\"\n assert candidate(s = \"aab\") == \"aab\"\n\n\ncheck(Solution().makeFancyString)"} | coding | 102 |
Solve the programming task below in a Python markdown code block.
A bracketed sequence is called correct (regular) if by inserting "+" and "1" you can get a well-formed mathematical expression from it. For example, sequences "(())()", "()" and "(()(()))" are correct, while ")(", "(()" and "(()))(" are not.
The teacher... | {"inputs": ["1\n(\n", "1\n)\n", "2\n((\n", "2\n)(\n", "2\n()\n", "2\n))\n", "3\n(()\n", "4\n))))\n"], "outputs": ["-1\n", "-1\n", "-1\n", "2\n", "0\n", "-1\n", "-1\n", "-1\n"]} | coding | 521 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given an integer n representing the number of houses on a number line, numbered from 0 to n - 1.
Additionally, you are given a 2D integer array offers where offers[i] = [starti, endi, goldi], indicating that i... | {"functional": "def check(candidate):\n assert candidate(n = 5, offers = [[0,0,1],[0,2,2],[1,3,2]]) == 3\n assert candidate(n = 5, offers = [[0,0,1],[0,2,10],[1,3,2]]) == 10\n\n\ncheck(Solution().maximizeTheProfit)"} | coding | 179 |
Solve the programming task below in a Python markdown code block.
Nicholas, a painter is going to paint several new canvases. Nicholas is sure that the canvases will turn out so great that each one will need framing and being hung on the wall. Frames are what Nicholas decided to begin with.
Nicholas has n sticks whos... | {"inputs": ["1\n1\n", "1\n10\n", "1\n20\n", "1\n37\n", "2\n1 1\n", "2\n3 5\n", "2\n5 5\n", "2\n5 6\n"], "outputs": ["0", "0", "0\n", "0\n", "0", "0", "0\n", "0\n"]} | coding | 341 |
Solve the programming task below in a Python markdown code block.
There are N balls in the xy-plane. The coordinates of the i-th of them is (x_i, i).
Thus, we have one ball on each of the N lines y = 1, y = 2, ..., y = N.
In order to collect these balls, Snuke prepared 2N robots, N of type A and N of type B.
Then, he p... | {"inputs": ["1\n18\n2", "1\n23\n1", "1\n23\n0", "1\n10\n3", "1\n15\n8", "1\n17\n9", "1\n0\n-8", "1\n0\n-7"], "outputs": ["4\n", "2\n", "0\n", "6\n", "14\n", "16\n", "-16\n", "-14\n"]} | coding | 546 |
Solve the programming task below in a Python markdown code block.
The chef is very expert in coding, so to keep his password safe from the hackers. He always enters a decoded code of his password. You are a hacker and your work is to find the maximum number of possible ways to unlock his password in encoded form.
The ... | {"inputs": ["2\n12\n223"], "outputs": ["YES\nNO"]} | coding | 296 |
Solve the programming task below in a Python markdown code block.
Read problems statements in Mandarin Chinese and Russian.
Given a string S consisting of only 1s and 0s, find the number of substrings which start and end both in 1.
In this problem, a substring is defined as a sequence of continuous characters S_{i}... | {"inputs": ["2\n4\n1111\n5\n10001", "2\n4\n1111\n5\n10000", "2\n4\n1111\n5\n10100", "2\n4\n1011\n5\n10000", "2\n4\n1110\n5\n10100", "2\n4\n1001\n5\n10000", "2\n4\n1111\n5\n10011", "2\n4\n0001\n2\n10000"], "outputs": ["10\n3", "10\n1\n", "10\n3\n", "6\n1\n", "6\n3\n", "3\n1\n", "10\n6\n", "1\n1\n"]} | coding | 346 |
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.*
##Examples:
pattern(4):
1234
234
34
... | {"functional": "_inputs = [[1], [2], [5], [0], [-25]]\n_outputs = [['1'], ['12\\n2'], ['12345\\n2345\\n345\\n45\\n5'], [''], ['']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, t... | coding | 177 |
Solve the programming task below in a Python markdown code block.
Chef's college is conducting online exams. Chef has a test tomorrow and he being irresponsible failed to prepare for it on time (just as always). However, fortunately, he now realises the gravity of the situation and decides to prepare as much as possibl... | {"inputs": ["3\n2 2\n1 1\n2 1\n3 3\n1 1\n2 2\n3 3\n5 6\n5 1\n4 2\n3 3\n2 4\n1 5"], "outputs": ["2\n2\n9"]} | coding | 609 |
Solve the programming task below in a Python markdown code block.
One day a well-known sponsor of a well-known contest decided to give every participant of the contest a T-shirt as a present. A natural problem occurred: on the one hand, it is not clear how many T-shirts of what sizes should be ordered, and on the other... | {"inputs": ["0 0 0 0 1\n1\nS\n", "1 0 1 0 1\n1\nS\n", "0 0 0 0 2\n1\nS\n", "0 1 0 0 1\n1\nS\n", "1 0 0 0 2\n1\nS\n", "1 0 1 0 2\n1\nS\n", "1 0 1 1 2\n1\nS\n", "2 0 1 1 2\n1\nS\n"], "outputs": ["XXL\n", "S\n", "XXL\n", "M\n", "S\n", "S\n", "S\n", "S\n"]} | coding | 537 |
Solve the programming task below in a Python markdown code block.
As we all know, F.C. Barcelona is the best soccer team of our era! Their entangling and mesmerizing game style usually translates into very high ball possession, consecutive counter-attack plays and goals. Lots of goals, thanks to the natural talent of t... | {"inputs": ["2\n2 4\n4 2", "2\n3 4\n4 2", "2\n3 4\n4 3", "2\n3 1\n4 2", "2\n3 1\n4 3", "2\n6 1\n4 3", "2\n6 2\n4 3", "2\n6 2\n4 1"], "outputs": ["4\n6", "12\n6\n", "12\n21\n", "0\n6\n", "0\n21\n", "1\n21\n", "22\n21\n", "22\n1\n"]} | coding | 738 |
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 contents of a pile, where nums[0] is the topmost element of the pile.
In one move, you can perform either of the following:
If the pile is not empty, remo... | {"functional": "def check(candidate):\n assert candidate(nums = [5,2,2,4,0,6], k = 4) == 5\n assert candidate(nums = [2], k = 1) == -1\n\n\ncheck(Solution().maximumTop)"} | coding | 197 |
Solve the programming task below in a Python markdown code block.
Given a side length `n`, traveling only right and down how many ways are there to get from the top left corner to the bottom right corner of an `n by n` grid?
Your mission is to write a program to do just that!
Add code to `route(n)` that returns the n... | {"functional": "_inputs = [[156], [106], [108], [126], [165], [125], [103]]\n_outputs = [[376594020312425061595746241557406711201605603899894320577733841460621358204120168599683135056], [360262512886894560870925723424985925545493469115736766525399280], [5710703280600670271749409312650477833283445281465962347881848400],... | coding | 198 |
Solve the programming task below in a Python markdown code block.
You are given $n$ distinct points on a plane. The coordinates of the $i$-th point are $(x_i, y_i)$.
For each point $i$, find the nearest (in terms of Manhattan distance) point with integer coordinates that is not among the given $n$ points. If there are... | {"inputs": ["1\n1 1\n", "1\n200000 200000\n", "6\n2 2\n1 2\n2 1\n3 2\n2 3\n5 5\n", "8\n4 4\n2 4\n2 2\n2 3\n1 4\n4 2\n1 3\n3 3\n"], "outputs": ["1 0\n", "200000 199999\n", "1 1\n1 1\n2 0\n3 1\n2 4\n5 4\n", "4 3\n2 5\n2 1\n2 5\n1 5\n4 1\n1 2\n3 2\n"]} | coding | 485 |
Solve the programming task below in a Python markdown code block.
Chef has recently started playing chess, and wants to play as many games as possible.
He calculated that playing one game of chess takes at least 20 minutes of his time.
Chef has N hours of free time. What is the maximum number of complete chess games... | {"inputs": ["4\n1\n10\n7\n3\n"], "outputs": ["3\n30\n21\n9\n"]} | coding | 329 |
Solve the programming task below in a Python markdown code block.
Kiyora has $n$ whiteboards numbered from $1$ to $n$. Initially, the $i$-th whiteboard has the integer $a_i$ written on it.
Koxia performs $m$ operations. The $j$-th operation is to choose one of the whiteboards and change the integer written on it to $b... | {"inputs": ["4\n3 2\n1 2 3\n4 5\n2 3\n1 2\n3 4 5\n1 1\n100\n1\n5 3\n1 1 1 1 1\n1000000000 1000000000 1000000000\n"], "outputs": ["12\n9\n1\n3000000002\n"]} | coding | 631 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an integer n, return true if and only if it is an Armstrong number.
The k-digit number n is an Armstrong number if and only if the kth power of each digit sums to n.
Please complete the following python code p... | {"functional": "def check(candidate):\n assert candidate(n = 153) == True\n assert candidate(n = 123) == False\n\n\ncheck(Solution().isArmstrong)"} | coding | 89 |
Solve the programming task below in a Python markdown code block.
At a geometry lesson Bob learnt that a triangle is called right-angled if it is nondegenerate and one of its angles is right. Bob decided to draw such a triangle immediately: on a sheet of paper he drew three points with integer coordinates, and joined t... | {"inputs": ["0 0 1 0 4 1\n", "0 0 1 0 2 1\n", "0 0 0 1 1 0\n", "0 0 1 0 3 1\n", "0 0 1 0 2 2\n", "0 0 1 0 0 1\n", "2 3 4 5 3 6\n", "0 0 4 0 0 1\n"], "outputs": ["NEITHER\n", "ALMOST\n", "RIGHT\n", "ALMOST\n", "ALMOST\n", "RIGHT\n", "RIGHT\n", "RIGHT\n"]} | coding | 353 |
Solve the programming task below in a Python markdown code block.
There are N towns on a plane. The i-th town is located at the coordinates (x_i,y_i). There may be more than one town at the same coordinates.
You can build a road between two towns at coordinates (a,b) and (c,d) for a cost of min(|a-c|,|b-d|) yen (the c... | {"inputs": ["3\n0 5\n3 9\n7 8", "3\n0 8\n3 9\n7 8", "3\n0 8\n3 9\n9 8", "3\n1 5\n3 9\n7 8", "3\n0 8\n3 9\n16 8", "3\n0 4\n3 9\n16 8", "3\n0 4\n3 9\n3 10", "3\n0 0\n22 26\n6 0"], "outputs": ["4\n", "1\n", "1\n", "3", "1\n", "4\n", "3\n", "16\n"]} | coding | 295 |
Solve the programming task below in a Python markdown code block.
Little Artem has invented a time machine! He could go anywhere in time, but all his thoughts of course are with computer science. He wants to apply this time machine to a well-known data structure: multiset.
Artem wants to create a basic multiset of int... | {"inputs": ["3\n1 1 1\n2 2 1\n3 3 1\n", "3\n1 1 1\n2 2 1\n3 3 1\n", "6\n1 1 5\n3 5 5\n1 2 5\n3 6 5\n2 3 5\n3 7 5\n", "6\n1 1 5\n3 5 5\n1 2 0\n3 6 5\n2 3 5\n3 7 5\n", "6\n1 1 5\n3 5 5\n1 2 0\n3 6 2\n2 3 5\n3 7 5\n", "6\n1 1 5\n3 5 5\n1 2 0\n2 6 2\n2 3 5\n3 7 5\n", "6\n1 1 5\n3 4 5\n1 2 0\n2 6 2\n2 3 6\n3 7 5\n", "6\n1 1... | coding | 706 |
Solve the programming task below in a Python markdown code block.
The Indian bank issues coins in 4 denominations, ₹1, ₹2, ₹5 and ₹10.
Given a limited supply of each of the above denominations, in how many ways can you sum them up to a total of ₹N?
Input Format
The first line contains an integer T (number of testc... | {"inputs": ["2\n15\n2 3 1 1\n12\n2 2 1 1\n"], "outputs": ["2\n2\n"]} | coding | 290 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
There is a special typewriter with lowercase English letters 'a' to 'z' arranged in a circle with a pointer. A character can only be typed if the pointer is pointing to that character. The pointer is initially pointin... | {"functional": "def check(candidate):\n assert candidate(word = \"abc\") == 5\n assert candidate(word = \"bza\") == 7\n assert candidate(word = \"zjpc\") == 34\n\n\ncheck(Solution().minTimeToType)"} | coding | 152 |
Solve the programming task below in a Python markdown code block.
The numbers 1 to n x n are contained in the n x n square squares one by one, and the sum of the squares in any vertical column and the sum of the squares in any horizontal column are diagonal squares. Those with the same sum of eyes are called magic squa... | {"inputs": ["3\n0\n0", "3\n7\n0", "3\n3\n0", "3\n9\n0", "3\n0\n1", "3\n0\n2", "3\n0\n3", "3\n0\n4"], "outputs": [" 4 9 2\n 3 5 7\n 8 1 6\n", " 4 9 2\n 3 5 7\n 8 1 6\n 22 47 16 41 10 35 4\n 5 23 48 17 42 11 29\n 30 6 24 49 18 36 12\n 13 31 7 25 43 19 37... | coding | 500 |
Solve the programming task below in a Python markdown code block.
Write a function that takes as its parameters *one or more numbers which are the diameters of circles.*
The function should return the *total area of all the circles*, rounded to the nearest integer in a string that says "We have this much circle: xyz"... | {"functional": "_inputs = [[48, 7, 8, 9, 10], [1], [1, 1, 1, 2, 3, 4, 5], [894, 5778, 4839, 476], [4.5456, 746.5, 98.34, 344.543], [1, 1, 1], [13.58, 14.9, 56.99, 107.321], [56894.04839, 843975.4839, 4.08437403489], [5, 6, 7, 8, 9, 10, 105083, 48839, 4853, 28, 483]]\n_outputs = [['We have this much circle: 2040'], ['We... | coding | 173 |
Solve the programming task below in a Python markdown code block.
-----Problem Statement-----
A classroom has several students, half of whom are boys and half of whom are girls. You need to arrange all of them in a line for the morning assembly such that the following conditions are satisfied:
- The students must be in... | {"inputs": ["1\n2\n1 3\n2 4"], "outputs": ["YES"]} | coding | 605 |
Solve the programming task below in a Python markdown code block.
Vasya has a multiset s consisting of n integer numbers. Vasya calls some number x nice if it appears in the multiset exactly once. For example, multiset \{1, 1, 2, 3, 3, 3, 4\} contains nice numbers 2 and 4.
Vasya wants to split multiset s into two mult... | {"inputs": ["2\n1 1\n", "2\n1 2\n", "2\n1 4\n", "2\n1 100\n", "3\n2 1 2\n", "3\n1 1 1\n", "3\n2 2 2\n", "3\n2 1 4\n"], "outputs": ["YES\nAA\n", "YES\nAB", "YES\nAB\n", "YES\nAB", "NO\n", "YES\nAAA\n", "YES\nAAA\n", "NO\n"]} | coding | 373 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a string s. You can convert s to a palindrome by adding characters in front of it.
Return the shortest palindrome you can find by performing this transformation.
Please complete the following python co... | {"functional": "def check(candidate):\n assert candidate(s = \"aacecaaa\") == \"aaacecaaa\"\n assert candidate(s = \"abcd\") == \"dcbabcd\"\n\n\ncheck(Solution().shortestPalindrome)"} | coding | 81 |
Solve the programming task below in a Python markdown code block.
Devu is a dumb guy, his learning curve is very slow. You are supposed to teach him n subjects, the i^{th} subject has c_{i} chapters. When you teach him, you are supposed to teach all the chapters of a subject continuously.
Let us say that his initial p... | {"inputs": ["1 1\n1\n", "1 2\n1\n", "1 2\n2\n", "1 1\n1\n", "1 2\n2\n", "1 2\n1\n", "1 3\n1\n", "1 2\n0\n"], "outputs": ["1\n", "2\n", "4\n", "1\n", "4\n", "2\n", "3\n", "0\n"]} | coding | 662 |
Solve the programming task below in a Python markdown code block.
Chef has an exam which will start exactly M minutes from now. However, instead of preparing for his exam, Chef started watching Season-1 of Superchef. Season-1 has N episodes, and the duration of each episode is K minutes.
Will Chef be able to finish w... | {"inputs": ["3\n10 1 10\n25 2 10\n15 2 10"], "outputs": ["NO\nYES\nNO"]} | coding | 520 |
Solve the programming task below in a Python markdown code block.
AtCoDeer the deer is seeing a quick report of election results on TV.
Two candidates are standing for the election: Takahashi and Aoki.
The report shows the ratio of the current numbers of votes the two candidates have obtained, but not the actual number... | {"inputs": ["3\n3 3\n1 1\n3 2", "3\n4 3\n1 1\n3 1", "3\n4 3\n1 2\n3 1", "3\n2 3\n1 1\n1 2", "3\n4 3\n1 1\n1 2", "3\n2 1\n1 1\n3 2", "3\n3 3\n1 2\n3 2", "3\n4 3\n1 2\n2 1"], "outputs": ["10\n", "16\n", "32\n", "9\n", "12\n", "5\n", "15\n", "24\n"]} | coding | 381 |
Solve the programming task below in a Python markdown code block.
[0, 0]
[0, 1] [1, 1]
[0, 2] [1, 2] [2, 2]
[0, 3] [1, 3] [2, 3] [3, 3]
[0, 4] [1, 4] [2, 4] [3, 4] [4, 4]
[0, 5] [1, 5] [2, 5] [3, 5] [4, 5] [5, 5]
[0, 6] [1, 6] [2, 6] [3, 6] [4, 6] [5, 6] [6, 6]
Consider the standard set of 28 wes... | {"inputs": ["6\n13 23 20 24 15 25\n10\n00 01 11 02 12 22 03 13 23 33", "6\n13 23 20 24 11 25\n10\n00 01 11 02 12 22 03 13 23 33", "6\n13 23 20 24 11 25\n10\n00 01 11 02 12 22 03 13 16 33", "6\n16 23 16 16 15 25\n10\n00 01 11 02 12 22 03 13 13 33", "6\n13 23 14 24 15 25\n10\n00 01 11 02 12 22 03 13 36 33", "6\n12 23 14 ... | coding | 580 |
Solve the programming task below in a Python markdown code block.
In some other world, today is Christmas Eve.
There are N trees planted in Mr. Takaha's garden. The height of the i-th tree (1 \leq i \leq N) is h_i meters.
He decides to choose K trees from these trees and decorate them with electric lights. To make the ... | {"inputs": ["3 3\n5\n7\n0\n1\n7", "3 3\n5\n7\n5\n7\n7", "3 3\n5\n7\n5\n1\n7", "3 3\n5\n7\n5\n1\n5", "5 3\n5\n7\n5\n9\n7", "3 3\n5\n7\n5\n7\n6", "5 3\n5\n7\n2\n0\n6", "5 3\n5\n7\n5\n1\n5"], "outputs": ["7\n", "2\n", "2\n", "2\n", "2\n", "2\n", "2\n", "0\n"]} | coding | 334 |
Solve the programming task below in a Python markdown code block.
Dr. Moriarty is about to send a message to Sherlock Holmes. He has a string s.
String p is called a substring of string s if you can read it starting from some position in the string s. For example, string "aba" has six substrings: "a", "b", "a", "ab",... | {"inputs": ["a\na\n", "c\nh\n", "h\nb\n", "r\ni\n", "t\nv\n", "o\nu\n", "c\np\n", "a\nz\n"], "outputs": ["0\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n"]} | coding | 508 |
Solve the programming task below in a Python markdown code block.
The chef is trying to decode some pattern problems, Chef wants your help to code it. Chef has one number K to form a new pattern. Help the chef to code this pattern problem.
-----Input:-----
- First-line will contain $T$, the number of test cases. Then ... | {"inputs": ["4\n1\n2\n3\n4"], "outputs": ["1\n12\n3\n123\n45\n6\n1234\n567\n89\n10"]} | coding | 207 |
Solve the programming task below in a Python markdown code block.
There is a grid with R rows and C columns. We call the cell in the r-th row and c-th column (r,c).
Mr. Takahashi wrote non-negative integers into N of the cells, that is, he wrote a non-negative integer a_i into (r_i,c_i) for each i (1≤i≤N). After that ... | {"inputs": ["2 2\n3\n1 1 0\n1 2 10\n2 1 22", "2 2\n3\n2 1 20\n1 2 10\n2 1 0", "2 2\n3\n1 1 0\n1 2 10\n2 1 14", "2 4\n3\n1 1 0\n1 2 10\n2 1 22", "2 2\n3\n1 1 0\n1 2 10\n1 1 14", "2 4\n3\n1 1 1\n1 2 10\n2 1 22", "2 2\n3\n1 1 0\n2 2 10\n2 1 22", "2 2\n3\n1 2 20\n1 2 10\n2 1 0"], "outputs": ["Yes\n", "No\n", "Yes\n", "Yes\... | coding | 557 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
A sequence is special if it consists of a positive number of 0s, followed by a positive number of 1s, then a positive number of 2s.
For example, [0,1,2] and [0,0,1,1,1,2] are special.
In contrast, [2,1,0], [1], and [... | {"functional": "def check(candidate):\n assert candidate(nums = [0,1,2,2]) == 3\n assert candidate(nums = [2,2,0,0]) == 0\n assert candidate(nums = [0,1,2,0,1,2]) == 7\n\n\ncheck(Solution().countSpecialSubsequences)"} | coding | 234 |
Solve the programming task below in a Python markdown code block.
Iahub and his friend Floyd have started painting a wall. Iahub is painting the wall red and Floyd is painting it pink. You can consider the wall being made of a very large number of bricks, numbered 1, 2, 3 and so on.
Iahub has the following scheme of ... | {"inputs": ["3 2 5 5\n", "1 1 1 1\n", "2 3 7 7\n", "3 3 3 7\n", "3 2 5 5\n", "3 3 3 7\n", "2 3 7 7\n", "1 1 1 1\n"], "outputs": ["0", "1", "0", "2", "0\n", "2\n", "0\n", "1\n"]} | coding | 444 |
Solve the programming task below in a Python markdown code block.
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
You are given a rooted tree with $N$ nodes (numbered $1$ through $N$); node $1$ is the root. Each node has a value; let's denote the value of node $i... | {"inputs": ["1\n3 5\n1 -5 -10\n1 2\n2 3"], "outputs": ["-4"]} | coding | 475 |
Solve the programming task below in a Python markdown code block.
Основой любой социальной сети является отношение дружбы между двумя пользователями в том или ином смысле. В одной известной социальной сети дружба симметрична, то есть если a является другом b, то b также является другом a.
В этой же сети есть функция,... | {"inputs": ["1 0\n42 23\n", "1 1\n42 23\n", "1 50\n42 23\n", "1 99\n42 23\n", "1 100\n42 23\n", "2 49\n42 23\n23 14\n", "2 50\n42 23\n23 19\n", "2 51\n42 23\n23 19\n"], "outputs": ["23: 0\n42: 0\n", "23: 0\n42: 0\n", "23: 0\n42: 0\n", "23: 0\n42: 0\n", "23: 0\n42: 0\n", "14: 1 42\n23: 0\n42: 1 14\n", "19: 1 42\n23: 0\n... | coding | 685 |
Solve the programming task below in a Python markdown code block.
In Aramic language words can only represent objects.
Words in Aramic have special properties: A word is a root if it does not contain the same letter more than once. A root and all its permutations represent the same object. The root $x$ of a word $... | {"inputs": ["3\namer arem mrea\n", "3\namer mera mrea\n", "3\nrema mera mrea\n", "3\nrema mera erma\n", "3\nrema arem erma\n", "3\nrema aerm erma\n", "3\namer arem mrea\n", "5\na aa aaa ab abb\n"], "outputs": ["1", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "2"]} | coding | 373 |
Solve the programming task below in a Python markdown code block.
The Smart Beaver from ABBYY came up with another splendid problem for the ABBYY Cup participants! This time the Beaver invites the contest participants to check out a problem on sorting documents by their subjects. Let's describe the problem:
You've got... | {"inputs": ["21000\nSWISS TO LAUNCH NEW SERIES OF MONEY MARKET PAPER\nZURICH, April 9 - The Swiss Federal Government will launch\na new series of three month money market certificates totalling\naround 150 mln Swiss francs, the National Bank said.\nSubscriptions close April 14 and payment date is April 16.\nThe last se... | coding | 497 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given an m x n binary matrix grid where each cell is either 0 (empty) or 1 (occupied).
You are then given stamps of size stampHeight x stampWidth. We want to fit the stamps such that they follow the given rest... | {"functional": "def check(candidate):\n assert candidate(grid = [[1,0,0,0],[1,0,0,0],[1,0,0,0],[1,0,0,0],[1,0,0,0]], stampHeight = 4, stampWidth = 3) == True\n assert candidate(grid = [[1,0,0,0],[0,1,0,0],[0,0,1,0],[0,0,0,1]], stampHeight = 2, stampWidth = 2 ) == False \n\n\ncheck(Solution().possibleToStamp)"} | coding | 189 |
Solve the programming task below in a Python markdown code block.
There are N positive integers written on a blackboard: A_1, ..., A_N.
Snuke can perform the following operation when all integers on the blackboard are even:
- Replace each integer X on the blackboard by X divided by 2.
Find the maximum possible number ... | {"inputs": ["3\n4 7 31", "3\n4 7 52", "3\n7 7 52", "3\n7 7 25", "3\n7 13 5", "3\n7 13 8", "3\n6 12 31", "3\n4 12 31"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]} | coding | 311 |
Solve the programming task below in a Python markdown code block.
A problem setter is called an *expert* if at least 50 \% of their problems are approved by Chef.
Munchy submitted X problems for approval. If Y problems out of those were approved, find whether Munchy is an *expert* or not.
------ Input Format ------
... | {"inputs": ["4\n5 3\n1 1\n4 1\n2 1\n"], "outputs": ["YES\nYES\nNO\nYES"]} | coding | 487 |
Solve the programming task below in a Python markdown code block.
Polycarpus likes studying at school a lot and he is always diligent about his homework. Polycarpus has never had any problems with natural sciences as his great-great-grandfather was the great physicist Seinstein. On the other hand though, Polycarpus has... | {"inputs": ["2\n2 3\n1 4\n", "2\n2 0\n1 6\n", "2\n2 1\n1 6\n", "2\n2 1\n0 6\n", "2\n5 6\n1 10\n", "2\n5 9\n1 10\n", "2\n3 9\n1 10\n", "2\n3 9\n1 12\n"], "outputs": ["1", "1\n", "1\n", "1\n", "1", "1\n", "1\n", "1\n"]} | coding | 516 |
Solve the programming task below in a Python markdown code block.
problem
Given the sequence $ A $ of length $ N $. The $ i $ item in $ A $ is $ A_i $. You can do the following for this sequence:
* $ 1 \ leq i \ leq N --Choose the integer i that is 1 $. Swap the value of $ A_i $ with the value of $ A_ {i + 1} $.
F... | {"inputs": ["5\n0 2 3 4 5", "5\n1 2 1 4 5", "5\n0 2 3 4 8", "5\n0 1 3 4 5", "5\n0 2 3 4 2", "5\n0 2 3 8 2", "5\n0 4 3 9 4", "5\n1 5 3 1 8"], "outputs": ["2\n", "1\n", "2\n", "2\n", "1\n", "1\n", "0\n", "1\n"]} | coding | 308 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Write an algorithm to determine if a number n is happy.
A happy number is a number defined by the following process:
Starting with any positive integer, replace the number by the sum of the squares of its digits.
Rep... | {"functional": "def check(candidate):\n assert candidate(n = 19) == True\n assert candidate(n = 2) == False\n\n\ncheck(Solution().isHappy)"} | coding | 146 |
Solve the programming task below in a Python markdown code block.
You are given N positive integers a_1, a_2, ..., a_N.
For a non-negative integer m, let f(m) = (m\ mod\ a_1) + (m\ mod\ a_2) + ... + (m\ mod\ a_N).
Here, X\ mod\ Y denotes the remainder of the division of X by Y.
Find the maximum value of f.
-----Constr... | {"inputs": ["2\n8 5\n", "2\n3 10\n", "3\n3 1 6", "3\n3 2 6", "3\n3 3 6", "3\n2 1 6", "3\n7 0 6", "3\n2 0 6"], "outputs": ["11\n", "11\n", "7\n", "8\n", "9\n", "6\n", "10\n", "5\n"]} | coding | 243 |
Solve the programming task below in a Python markdown code block.
You've been collecting change all day, and it's starting to pile up in your pocket, but you're too lazy to see how much you've found.
Good thing you can code!
Create ```change_count()``` to return a dollar amount of how much change you have!
Valid typ... | {"functional": "_inputs = [['dime penny dollar'], ['dime penny nickel'], ['quarter quarter'], ['dollar penny dollar'], ['dollar dollar dollar dollar dollar dollar dollar dollar dollar dollar penny']]\n_outputs = [['$1.11'], ['$0.16'], ['$0.50'], ['$2.01'], ['$10.01']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if... | coding | 350 |
Solve the programming task below in a Python markdown code block.
I’m planning to have a party on my birthday. Many of my friends will come to the party. Some of them will come with one or more pieces of cakes, but it is not certain if the number of the cakes is a multiple of the number of people coming.
I wish to enj... | {"inputs": ["5 2\n5 5 6 5", "100 3\n1 3 3", "5 2\n3 5 6 5", "000 3\n1 3 3", "5 2\n3 7 6 5", "010 3\n1 3 3", "010 3\n1 3 5", "5 4\n5 5 6 5"], "outputs": ["2\n", "1\n", "2\n", "7\n", "2\n", "1\n", "1\n", "4"]} | coding | 390 |
Solve the programming task below in a Python markdown code block.
A student of z-school found a kind of sorting called z-sort. The array a with n elements are z-sorted if two conditions hold:
a_{i} ≥ a_{i} - 1 for all even i, a_{i} ≤ a_{i} - 1 for all odd i > 1.
For example the arrays [1,2,1,2] and [1,1,1,1] are ... | {"inputs": ["1\n1\n", "1\n1\n", "1\n2\n", "1\n0\n", "1\n4\n", "3\n1 2 6\n", "3\n1 2 3\n", "3\n1 2 3\n"], "outputs": ["1\n", "1 ", "2 ", "0 ", "4 ", "1 6 2\n", "1 3 2\n", "1 3 2 "]} | coding | 290 |
Solve the programming task below in a Python markdown code block.
Snuke loves "paper cutting": he cuts out characters from a newspaper headline and rearranges them to form another string.
He will receive a headline which contains one of the strings S_1,...,S_n tomorrow.
He is excited and already thinking of what string... | {"inputs": ["3\na\naa\na", "3\na\naa\nb", "3\na\naa\nb\n", "3\ncaaa\ndaacc\nacacac", "3\ncaaa\nd`acc\nacacac", "3\naaca\nbdb`c\nacacac", "3\ncaca\ncca`d\nacacac", "3\nacba\nda`cb\nacacbc"], "outputs": ["a\n", "", "\n", "aac\n", "ac\n", "c\n", "acc\n", "abc\n"]} | coding | 348 |
Solve the programming task below in a Python markdown code block.
Allen is hosting a formal dinner party. $2n$ people come to the event in $n$ pairs (couples). After a night of fun, Allen wants to line everyone up for a final picture. The $2n$ people line up, but Allen doesn't like the ordering. Allen prefers if each p... | {"inputs": ["1\n1 1\n", "1\n1 1\n", "1\n0 0\n", "2\n1 2 1 2\n", "2\n2 1 1 2\n", "2\n2 1 1 2\n", "2\n1 2 1 2\n", "2\n1 1 2 2\n"], "outputs": ["0\n", "0\n", "0\n", "1\n", "2\n", "2\n", "1\n", "0\n"]} | coding | 484 |
Solve the programming task below in a Python markdown code block.
Your program fails again. This time it gets "Wrong answer on test 233"
.
This is the easier version of the problem. In this version 1 ≤ n ≤ 2000. You can hack this problem only if you solve and lock both problems.
The problem is about a test containin... | {"inputs": ["1 1\n1\n", "1 0\n1\n", "3 3\n1 3 1\n", "5 5\n1 2 4 2 2\n", "5 5\n1 1 4 2 2\n", "6 2\n1 1 2 2 1 1\n", "6 2\n0 1 2 2 1 1\n", "6 2\n0 0 2 2 1 1\n"], "outputs": ["0\n", "0\n", "9\n", "1075\n", "1000\n", "16\n", "20\n", "32\n"]} | coding | 690 |
Solve the programming task below in a Python markdown code block.
I assume most of you are familiar with the ancient legend of the rice (but I see wikipedia suggests [wheat](https://en.wikipedia.org/wiki/Wheat_and_chessboard_problem), for some reason) problem, but a quick recap for you: a young man asks as a compensati... | {"functional": "_inputs = [[0], [1], [2], [3], [4]]\n_outputs = [[0], [1], [2], [2], [3]]\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 | 311 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a 0-indexed 2D array grid of size 2 x n, where grid[r][c] represents the number of points at position (r, c) on the matrix. Two robots are playing a game on this matrix.
Both robots initially start at (0... | {"functional": "def check(candidate):\n assert candidate(grid = [[2,5,4],[1,5,1]]) == 4\n assert candidate(grid = [[3,3,1],[8,5,2]]) == 4\n assert candidate(grid = [[1,3,1,15],[1,3,3,1]]) == 7\n\n\ncheck(Solution().gridGame)"} | coding | 311 |
Solve the programming task below in a Python markdown code block.
Everyone knows passphrases. One can choose passphrases from poems, songs, movies names and so on but frequently
they can be guessed due to common cultural references.
You can get your passphrases stronger by different means. One is the following:
choos... | {"functional": "_inputs = [['I LOVE YOU!!!', 1], ['I LOVE YOU!!!', 0], ['AAABBCCY', 1], ['MY GRANMA CAME FROM NY ON THE 23RD OF APRIL 2015', 2], [\"TO BE HONEST WITH YOU I DON'T USE THIS TEXT TOOL TOO OFTEN BUT HEY... MAYBE YOUR NEEDS ARE DIFFERENT.\", 5], ['IN 2012 TWO CAMBRIDGE UNIVERSITY RESEARCHERS ANALYSED PASSPHR... | coding | 286 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.