task_type stringclasses 4
values | problem stringlengths 14 5.23k | solution stringlengths 1 8.29k | problem_tokens int64 9 1.02k | solution_tokens int64 1 1.98k |
|---|---|---|---|---|
coding | 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"]} | 204 | 150 |
coding | Solve the programming task below in a Python markdown code block.
Santa Claus decided to disassemble his keyboard to clean it. After he returned all the keys back, he suddenly realized that some pairs of keys took each other's place! That is, Santa suspects that each key is either on its place, or on the place of anoth... | {"inputs": ["a\nz\n", "y\ny\n", "z\nz\n", "a\nz\n", "z\na\n", "z\nz\n", "y\ny\n", "z\na\n"], "outputs": ["1\na z\n", "0\n", "0\n", "1\na z\n", "1\nz a\n", "0\n", "0\n", "1\nz a\n"]} | 422 | 98 |
coding | Solve the programming task below in a Python markdown code block.
Chloe is fascinated by prime numbers. She came across the number $283002$ on a sign and, though the number is not prime, found some primes hiding in it by using the following rules:
Every three consecutive digits sum to a prime:
$\underbrace{283}002\q... | {"inputs": ["1\n6\n"], "outputs": ["95\n"]} | 469 | 17 |
coding | Solve the programming task below in a Python markdown code block.
You are given two positive integers ```a``` and ```b```.
You can perform the following operations on ```a``` so as to obtain ```b``` :
```
(a-1)/2 (if (a-1) is divisible by 2)
a/2 (if a is divisible by 2)
a*2
```
```b``` will always be a power o... | {"functional": "_inputs = [[1, 1], [2, 4], [3, 8], [4, 16], [4, 1], [1, 4]]\n_outputs = [[0], [1], [4], [2], [2], [2]]\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 ... | 223 | 202 |
coding | Solve the programming task below in a Python markdown code block.
Codex is about to start and Ram has not done dinner yet. So, he quickly goes to hostel mess and finds a long queue in front of food counter. But somehow he manages to take the food plate and reaches in front of the queue. The plates are divided into sec... | {"inputs": ["19\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n12\n13\n14\n15\n16\n17\n18\n19"], "outputs": ["4\n9\n25\n64\n169\n441\n1156\n3025\n7921\n20736\n54289\n142129\n372100\n974169\n2550409\n6677056\n17480761\n45765225\n119814916"]} | 367 | 169 |
coding | Solve the programming task below in a Python markdown code block.
After learning a lot about space exploration, a little girl named Ana wants to change the subject.
Ana is a girl who loves palindromes (string that can be read the same backwards as forward). She has learned how to check for a given string whether it's ... | {"inputs": ["3\nab\nbb\ncd\n", "3\nbc\ncb\ndb\n", "3\nab\nbb\nbd\n", "3\nab\ncb\nbd\n", "3\nba\ncb\nbd\n", "3\nab\ncb\ndb\n", "3\nbb\ncb\nbd\n", "3\nbb\nbc\nbd\n"], "outputs": ["0\n", "1\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]} | 536 | 126 |
coding | 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. An island is a group of 1's (representing land) connected 4-directionally (horizontal or vertical.) You may assume all four edges of the grid are surrounded by water.
The are... | {"functional": "def check(candidate):\n assert candidate(grid = [[0,0,1,0,0,0,0,1,0,0,0,0,0],[0,0,0,0,0,0,0,1,1,1,0,0,0],[0,1,1,0,1,0,0,0,0,0,0,0,0],[0,1,0,0,1,1,0,0,1,0,1,0,0],[0,1,0,0,1,1,0,0,1,1,1,0,0],[0,0,0,0,0,0,0,0,0,0,1,0,0],[0,0,0,0,0,0,0,1,1,1,0,0,0],[0,0,0,0,0,0,0,1,1,0,0,0,0]]) == 6\n assert candidate... | 140 | 266 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given the root of a binary tree and an integer targetSum, return true if the tree has a root-to-leaf path such that adding up all the values along the path equals targetSum.
A leaf is a node with no children.
Please... | {"functional": "def check(candidate):\n assert candidate(root = tree_node([5,4,8,11,None,13,4,7,2,None,None,None,1]), targetSum = 22) == True\n assert candidate(root = tree_node([1,2,3]), targetSum = 5) == False\n assert candidate(root = tree_node([]), targetSum = 0) == False\n\n\ncheck(Solution().hasPathSum)"... | 154 | 103 |
coding | Solve the programming task below in a Python markdown code block.
Given an array (or list or vector) of arrays (or, guess what, lists or vectors) of integers, your goal is to return the sum of a specific set of numbers, starting with elements whose position is equal to the main array length and going down by one at eac... | {"functional": "_inputs = [[[[3, 2, 1, 0], [4, 6, 5, 3, 2], [9, 8, 7, 4]]], [[[3], [4, 6, 5, 3, 2], [9, 8, 7, 4]]], [[[3, 2, 1, 0], [4, 6, 5, 3, 2], []]], [[[3, 2, 1, 0], [4, 6, 5, 3, 2], []], 5], [[[3, 2], [4], []]]]\n_outputs = [[16], [15], [7], [12], [0]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstanc... | 297 | 310 |
coding | Solve the programming task below in a Python markdown code block.
Little Vasya has received a young builder’s kit. The kit consists of several wooden bars, the lengths of all of them are known. The bars can be put one on the top of the other if their lengths are the same.
Vasya wants to construct the minimal number of... | {"inputs": ["1\n1\n", "1\n2\n", "1\n1000\n", "3\n1 2 2\n", "3\n1 2 1\n", "3\n1 2 3\n", "3\n2 1 16\n", "3\n3 1 16\n"], "outputs": ["1 1\n", "1 1\n", "1 1\n", "2 2\n", "2 2\n", "1 3\n", "1 3\n", "1 3\n"]} | 218 | 127 |
coding | Solve the programming task below in a Python markdown code block.
Chef wants to make a purchase. For this, he needs X gold coins, but he has none at the moment.
Chef has N fixed deposits, the i^{th} of which is worth A_{i} coins. He wants to open the minimum number of these deposits so that he has at least X coins.
Y... | {"inputs": ["4\n4 6\n4 3 5 1\n3 15\n1 5 3\n2 5\n10 3\n4 7\n1 2 3 4"], "outputs": ["2\n-1\n1\n2"]} | 609 | 63 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given an integer array arr of length n that represents a permutation of the integers in the range [0, n - 1].
We split arr into some number of chunks (i.e., partitions), and individually sort each chunk. After... | {"functional": "def check(candidate):\n assert candidate(arr = [4,3,2,1,0]) == 1\n assert candidate(arr = [1,0,2,3,4]) == 4\n\n\ncheck(Solution().maxChunksToSorted)"} | 125 | 61 |
coding | Solve the programming task below in a Python markdown code block.
After a lot of hard work, Goyal has finally completed his app. But before he launches it, he needs to test it. His friends are helping him on this. Whenever a friend uses the app, his name is recorded in the logs. At the end of the day, Goyal makes a "Ha... | {"inputs": ["7\nArjun Mohit Karan Mohit Mohit Ajay Karan"], "outputs": ["Mohit 3\nKaran 2\nArjun 1\nAjay 1"]} | 290 | 45 |
coding | Solve the programming task below in a Python markdown code block.
Read problems statements [Bengali] , [Mandarin chinese] , [Russian] and [Vietnamese] as well.
There is an ATM machine. Initially, it contains a total of $K$ units of money. $N$ people (numbered $1$ through $N$) want to withdraw money; for each valid $i$... | {"inputs": ["2\n5 10\n3 5 3 2 1\n4 6\n10 8 6 4"], "outputs": ["11010\n0010"]} | 652 | 49 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given two 0-indexed strings str1 and str2.
In an operation, you select a set of indices in str1, and for each index i in the set, increment str1[i] to the next character cyclically. That is 'a' becomes 'b', 'b... | {"functional": "def check(candidate):\n assert candidate(str1 = \"abc\", str2 = \"ad\") == True\n assert candidate(str1 = \"zc\", str2 = \"ad\") == True\n assert candidate(str1 = \"ab\", str2 = \"d\") == False\n\n\ncheck(Solution().canMakeSubsequence)"} | 200 | 75 |
coding | 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 nodes in a perfect binary tree consisting of nodes numbered from 1 to n. The root of the tree is node 1 and each node i in the tree has two children where the left... | {"functional": "def check(candidate):\n assert candidate(n = 7, cost = [1,5,2,2,3,3,1]) == 6\n assert candidate(n = 3, cost = [5,3,3]) == 0\n\n\ncheck(Solution().minIncrements)"} | 240 | 70 |
coding | Solve the programming task below in a Python markdown code block.
In the 2-D world of Flatland, the Circles were having their sports day and wanted to end it with a nice formation. So, they called upon Mr. Sphere from Spaceland for help. Mr Sphere decides to arrange the Circles in square formations. He starts with $N$ ... | {"inputs": ["2\n85\n114"], "outputs": ["2\n4"]} | 289 | 21 |
coding | Solve the programming task below in a Python markdown code block.
Chef has two strings A and B of lengths N and M respectively.
Chef can rearrange both strings in any way he wants. Let the rearranged string of A be A' and the rearranged string of B be B'.
Determine whether we can construct rearrangements A' and B' s... | {"inputs": ["4\n5 2\nabcdd\nac\n3 3\nabc\nxyz\n2 4\naa\naaaa\n1 3\na\naax\n"], "outputs": ["YES\nNO\nYES\nNO\n"]} | 569 | 54 |
coding | Solve the programming task below in a Python markdown code block.
You are a given a tree of N vertices. The i-th vertex has two things assigned to it — a value A_{i} and a range [L_{i}, R_{i}]. It is guaranteed that L_{i} ≤ A_{i} ≤ R_{i}.
You perform the following operation exactly once:
Pick a (possibly empty) subset... | {"inputs": ["2\n3\n1 1 1\n2 3 3\n3 3 3\n1 2\n1 3\n4\n3 3 4\n1 3 5\n2 2 2\n2 2 2\n1 2\n2 3\n2 4\n"], "outputs": ["3\n1"]} | 717 | 81 |
coding | Solve the programming task below in a Python markdown code block.
# Letterss of Natac
In a game I just made up that doesn’t have anything to do with any other game that you may or may not have played, you collect resources on each turn and then use those resources to build settlements, roads, and cities or buy a develo... | {"functional": "_inputs = [['bwoo'], [''], ['ogogoogogo'], ['bwbwwwbb']]\n_outputs = [[['road']], [[]], [['city']], [['road']]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tupl... | 505 | 180 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a 0-indexed 2D integer array nums representing the coordinates of the cars parking on a number line. For any index i, nums[i] = [starti, endi] where starti is the starting point of the ith car and endi i... | {"functional": "def check(candidate):\n assert candidate(nums = [[3,6],[1,5],[4,7]]) == 7\n assert candidate(nums = [[1,3],[5,8]]) == 7\n\n\ncheck(Solution().numberOfPoints)"} | 133 | 59 |
coding | Solve the programming task below in a Python markdown code block.
Alice and Borys are playing tennis.
A tennis match consists of games. In each game, one of the players is serving and the other one is receiving.
Players serve in turns: after a game where Alice is serving follows a game where Borys is serving, and vic... | {"inputs": ["3\n2 1\n1 1\n0 5\n", "2\n99999 0\n0 99999\n", "2\n99999 1\n1 99999\n", "2\n99998 1\n1 99998\n", "2\n0 100000\n100000 0\n"], "outputs": ["4\n0 1 2 3\n2\n0 2\n2\n2 3\n", "2\n49999 50000\n2\n49999 50000\n", "2\n49999 50001\n2\n49999 50001\n", "4\n49998 49999 50000 50001\n4\n49998 49999 50000 50001\n", "1\n500... | 706 | 260 |
coding | Solve the programming task below in a Python markdown code block.
Given is a sequence of N digits a_1a_2\ldots a_N, where each element is 1, 2, or 3. Let x_{i,j} defined as follows:
* x_{1,j} := a_j \quad (1 \leq j \leq N)
* x_{i,j} := | x_{i-1,j} - x_{i-1,j+1} | \quad (2 \leq i \leq N and 1 \leq j \leq N+1-i)
Find... | {"inputs": ["4\n21", "4\n32", "4\n13", "4\n21", "4\n44", "4\n12", "4\n11", "4\n22"], "outputs": ["1\n", "1\n", "2\n", "1\n", "0\n", "1\n", "0\n", "0\n"]} | 249 | 86 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an array of integers nums and an integer limit, return the size of the longest non-empty subarray such that the absolute difference between any two elements of this subarray is less than or equal to limit.
Ple... | {"functional": "def check(candidate):\n assert candidate(nums = [8,2,4,7], limit = 4) == 2 \n assert candidate(nums = [10,1,2,4,7,2], limit = 5) == 4 \n assert candidate(nums = [4,2,2,2,4,4,2,2], limit = 0) == 3\n\n\ncheck(Solution().longestSubarray)"} | 95 | 105 |
coding | Solve the programming task below in a Python markdown code block.
Reverse Polish Notation (RPN) is a mathematical notation where every operator follows all of its operands. For instance, to add three and four, one would write "3 4 +" rather than "3 + 4". If there are multiple operations, the operator is given immediate... | {"inputs": ["3\n(a+(b*c))\n((a+b)*(z+x))\n((a+t)*((b+(a+c))^(c+d)))\n"], "outputs": ["abc*+\nab+zx+*\nat+bac++cd+^*\n"]} | 224 | 62 |
coding | Solve the programming task below in a Python markdown code block.
problem
I want to put as many rectangular tiles as possible on a rectangular wall with a size of $ h $ in height and $ w $ in width, and a size of $ a $ in height and $ b $ in width.
The following conditions must be met when attaching tiles.
* Do not... | {"inputs": ["5 8\n3 2", "5 8\n6 2", "6 8\n6 3", "5 8\n1 3", "1 7\n2 6", "5 8\n2 2", "12 8\n6 3", "12 8\n9 3"], "outputs": ["16\n", "40\n", "12\n", "10\n", "7\n", "8", "24\n", "42\n"]} | 189 | 117 |
coding | Solve the programming task below in a Python markdown code block.
You have A 500-yen coins, B 100-yen coins and C 50-yen coins (yen is the currency of Japan).
In how many ways can we select some of these coins so that they are X yen in total?
Coins of the same kind cannot be distinguished. Two ways to select coins are ... | {"inputs": ["5\n0\n0\n0", "5\n0\n1\n0", "5\n1\n1\n0", "5\n2\n1\n0", "5\n0\n0\n1", "5\n0\n0\n2", "5\n0\n1\n2", "5\n1\n1\n2"], "outputs": ["1\n", "1\n", "1\n", "1\n", "0\n", "0\n", "0\n", "0\n"]} | 290 | 110 |
coding | Solve the programming task below in a Python markdown code block.
Ripul was skilled in the art of lapidary. He used to collect stones and convert it into decorative items for sale. There were n stone shops. Each shop was having one exclusive stone of value s[i] , where 1<=i<=n. If number of stones collected are more ... | {"inputs": ["1\n3\n1 2 3"], "outputs": ["6 1 2"]} | 483 | 24 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a string s of length n where s[i] is either:
'D' means decreasing, or
'I' means increasing.
A permutation perm of n + 1 integers of all the integers in the range [0, n] is called a valid permutation if... | {"functional": "def check(candidate):\n assert candidate(s = \"DID\") == 5\n\n\ncheck(Solution().numPermsDISequence)"} | 176 | 35 |
coding | Solve the programming task below in a Python markdown code block.
Vedant has a hidden array of N elements. Given the [bitwise AND] of all elements of the array, determine whether the total sum of the elements is odd, even or cannot be determined.
------ Input Format ------
- The first line of each input contains T -... | {"inputs": ["3\n1 11\n1 2\n74120341 829182732"], "outputs": ["Odd\nEven\nImpossible"]} | 293 | 44 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given an array of strings nums and an integer k. Each string in nums represents an integer without leading zeros.
Return the string that represents the kth largest integer in nums.
Note: Duplicate numbers shou... | {"functional": "def check(candidate):\n assert candidate(nums = [\"3\",\"6\",\"7\",\"10\"], k = 4) == \"3\"\n assert candidate(nums = [\"2\",\"21\",\"12\",\"1\"], k = 3) == \"2\"\n assert candidate(nums = [\"0\",\"0\"], k = 2) == \"0\"\n\n\ncheck(Solution().kthLargestNumber)"} | 142 | 99 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given two strings s1 and s2, both of length n, consisting of lowercase English letters.
You can apply the following operation on any of the two strings any number of times:
Choose any two indices i and j such... | {"functional": "def check(candidate):\n assert candidate(s1 = \"abcdba\", s2 = \"cabdab\") == True\n assert candidate(s1 = \"abe\", s2 = \"bea\") == False\n\n\ncheck(Solution().checkStrings)"} | 145 | 59 |
coding | Solve the programming task below in a Python markdown code block.
Little boy Gerald studies at school which is quite far from his house. That's why he has to go there by bus every day. The way from home to school is represented by a segment of a straight line; the segment contains exactly n + 1 bus stops. All of them a... | {"inputs": ["1 0\n", "2 0\n", "6 1\n0 6\n", "3 2\n0 1\n1 2\n", "2 2\n0 1\n1 2\n", "1000000000 0\n", "3 2\n-1 1\n1 2\n", "3 3\n1 2\n2 3\n1 3\n"], "outputs": ["0\n", "0\n", "1\n", "0\n", "1\n", "0\n", "0\n", "0\n"]} | 615 | 136 |
coding | Solve the programming task below in a Python markdown code block.
Alice and Bob are playing the game of Nim with $n$ piles of stones with sizes $p_0,p_1,\ldots,p_{n-1}$. If Alice plays first, she loses if and only if the 'xor sum' (or 'Nim sum') of the piles is zero, i.e., $p_0\oplus p_1\oplus...\oplus p_{n-1}=0$.
Sin... | {"inputs": ["3\n1 2 3\n", "10\n10 10 1 1 1 1 1 10 10 10\n"], "outputs": ["4\n", "321616\n"]} | 467 | 59 |
coding | Solve the programming task below in a Python markdown code block.
You are given a binary string S. You are allowed to perform the following operation at most once:
Pick some [substring] of S
Flip all the values in this substring, i.e, convert 0 to 1 and vice versa
For example, if S = 1\underline{00101}011, you can pic... | {"inputs": ["3\n111\n000\n00100"], "outputs": ["10\n10\n26"]} | 640 | 33 |
coding | Solve the programming task below in a Python markdown code block.
We all know how to calculate $a^{b}$ using $\boldsymbol{b}$ operations by multiplying $1$ by $\boldsymbol{a}$ a total of $\boldsymbol{b}$ times. The drawback to this method is that $\boldsymbol{b}$ can be large, which makes exponentiation very slow.
The... | {"inputs": ["3\n2 0 9 1000\n0 1 5 10\n8 2 10 1000000000\n"], "outputs": ["512 0\n0 1\n880332800 927506432\n"]} | 554 | 80 |
coding | Solve the programming task below in a Python markdown code block.
Bobby has decided to hunt some Parrots. There are n horizontal branch of trees aligned parallel to each other. Branches are numbered 1 to n from top to bottom. On each branch there are some parrots sitting next to each other. Supposed there are a[i]$a[i]... | {"inputs": ["5\n10 10 10 10 10\n5\n2 5\n3 13\n2 12\n1 13\n4 6\n3\n2 4 1\n1\n2 2"], "outputs": ["0\n12\n5\n0\n16\n3\n0\n3"]} | 617 | 82 |
coding | Solve the programming task below in a Python markdown code block.
A and B are preparing themselves for programming contests.
After several years of doing sports programming and solving many problems that require calculating all sorts of abstract objects, A and B also developed rather peculiar tastes.
A likes lowercas... | {"inputs": ["1 1 -1 1 1 1 1 1 1 1 1 1 1 1 1 7 1 1 1 8 1 1 1 1 1 1\na\n", "1 1 -1 1 1 1 1 1 1 1 1 1 1 1 1 7 1 1 1 8 1 1 1 1 1 1\na\n", "1 1 -1 1 1 1 1 1 1 1 1 1 1 1 1 7 1 1 1 8 1 1 1 0 1 1\na\n", "1 1 -1 1 1 1 1 1 1 1 2 1 1 1 1 7 1 1 1 8 1 1 1 0 1 1\na\n", "1 1 -1 1 1 1 1 1 1 1 1 1 1 1 1 7 1 1 1 8 1 1 1 1 1 1\nbb\n", "1... | 490 | 486 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given two positive integers n and target.
An integer is considered beautiful if the sum of its digits is less than or equal to target.
Return the minimum non-negative integer x such that n + x is beautiful. Th... | {"functional": "def check(candidate):\n assert candidate(n = 16, target = 6) == 4\n assert candidate(n = 467, target = 6) == 33\n assert candidate(n = 1, target = 1) == 0\n\n\ncheck(Solution().makeIntegerBeautiful)"} | 112 | 75 |
coding | Solve the programming task below in a Python markdown code block.
For a positive integer M, MoEngage defines \texttt{digitSum(M)} as the sum of digits of the number M (when written in decimal).
For example, \texttt{digitSum(1023)} = 1 + 0 + 2 + 3 = 6.
Given a positive integer N, find the smallest integer X strictly ... | {"inputs": ["3\n123\n19\n509"], "outputs": ["124\n21\n511"]} | 533 | 32 |
coding | Solve the programming task below in a Python markdown code block.
Efim just received his grade for the last test. He studies in a special school and his grade can be equal to any positive decimal fraction. First he got disappointed, as he expected a way more pleasant result. Then, he developed a tricky plan. Each secon... | {"inputs": ["3 1\n0.1\n", "3 1\n9.9\n", "3 1\n0.9\n", "3 1\n9.5\n", "3 3\n9.9\n", "3 3\n9.9\n", "3 1\n0.1\n", "3 1\n9.9\n"], "outputs": ["0.1\n", "10\n", "1\n", "10\n", "10\n", "10\n", "0.1\n", "10\n"]} | 628 | 127 |
coding | Solve the programming task below in a Python markdown code block.
There are N cities numbered 1 through N, and M bidirectional roads numbered 1 through M. Road i connects City A_i and City B_i.
Snuke can perform the following operation zero or more times:
* Choose two distinct cities that are not directly connected b... | {"inputs": ["3 1\n1 1", "5 1\n1 1", "6 1\n1 1", "3 1\n3 2", "5 1\n3 2", "2 1\n1 2", "9 1\n1 2", "8 1\n2 4"], "outputs": ["2\n", "4\n", "5\n", "1\n", "3\n", "0\n", "7\n", "6\n"]} | 249 | 110 |
coding | Solve the programming task below in a Python markdown code block.
problem
There are $ N $ propositions, named $ 1, 2, \ cdots, N $, respectively. Also, $ M $ information about the propositions is given. The $ i $ th information is "$ a_i $$". Given in the form "b_i $", which means that $ a_i $ is $ b_i $. ("If" is a l... | {"inputs": ["5 2\n1 2\n2 2", "3 2\n1 2\n2 1", "3 2\n1 2\n3 1", "6 2\n1 2\n2 1", "9 2\n1 2\n2 4", "6 2\n1 1\n2 1", "4 2\n2 2\n3 1", "1 0\n2 2\n1 1"], "outputs": ["1\n2\n3\n4\n5\n", "1 2\n1 2\n3\n", "1\n2\n3\n", "1 2\n1 2\n3\n4\n5\n6\n", "1\n2\n3\n4\n5\n6\n7\n8\n9\n", "1\n2\n3\n4\n5\n6\n", "1\n2\n3\n4\n", "1\n"]} | 245 | 208 |
coding | 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"]} | 481 | 44 |
coding | Solve the programming task below in a Python markdown code block.
While most devs know about [big/little-endianness](https://en.wikipedia.org/wiki/Endianness), only a selected few know the secret of real hard core coolness with mid-endians.
Your task is to take a number and return it in its mid-endian format, putting ... | {"functional": "_inputs = [[9999999], [0], [658188], [168496141], [43135012110]]\n_outputs = [['96987F'], ['00'], ['0B0A0C'], ['0D0B0A0C'], ['0D0B0A0C0E']]\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 ... | 217 | 234 |
coding | Solve the programming task below in a Python markdown code block.
Deoxyribonucleic acid, DNA is the primary information storage molecule in biological systems. It is composed of four nucleic acid bases Guanine ('G'), Cytosine ('C'), Adenine ('A'), and Thymine ('T').
Ribonucleic acid, RNA, is the primary messenger mol... | {"functional": "_inputs = [['TTTT'], ['GCAT'], ['GACCGCCGCC'], ['GATTCCACCGACTTCCCAAGTACCGGAAGCGCGACCAACTCGCACAGC'], ['CACGACATACGGAGCAGCGCACGGTTAGTACAGCTGTCGGTGAACTCCATGACA'], ['AACCCTGTCCACCAGTAACGTAGGCCGACGGGAAAAATAAACGATCTGTCAATG'], ['GAAGCTTATCCGTTCCTGAAGGCTGTGGCATCCTCTAAATCAGACTTGGCTACGCCGTTAGCCGAGGGCTTAGCGTTGAGT... | 227 | 696 |
coding | Solve the programming task below in a Python markdown code block.
Snuke is interested in strings that satisfy the following conditions:
* The length of the string is at least N.
* The first N characters equal to the string s.
* The last N characters equal to the string t.
Find the length of the shortest string that... | {"inputs": ["1\na\n{", "1\n`\nz", "1\n`\n{", "1\n`\n|", "1\n`\n}", "1\n`\n~", "1\n_\n~", "1\n_\n\u007f"], "outputs": ["2\n", "2\n", "2\n", "2\n", "2\n", "2\n", "2\n", "2\n"]} | 176 | 96 |
coding | Solve the programming task below in a Python markdown code block.
Read problems statements in Mandarin chinese, Russian and Vietnamese as well.
The *greatest common divisor* (GCD) of a sequence is the greatest positive integer which divides each element of this sequence.
You are given a sequence $A$ of positive inte... | {"inputs": ["2\n2\n2 3\n2\n2 4"], "outputs": ["0\n-1"]} | 445 | 27 |
coding | Solve the programming task below in a Python markdown code block.
Little penguin Polo adores strings. But most of all he adores strings of length n.
One day he wanted to find a string that meets the following conditions:
1. The string consists of n lowercase English letters (that is, the string's length equals n), ... | {"inputs": ["3 3\n", "1 1\n", "1 2\n", "2 2\n", "7 7\n", "9 4\n", "4 4\n", "1 4\n"], "outputs": ["abc\n", "a\n", "-1\n", "ab\n", "abcdefg\n", "abababacd\n", "abcd\n", "-1\n"]} | 370 | 90 |
coding | Solve the programming task below in a Python markdown code block.
You are given three integers $a$, $b$ and $x$. Your task is to construct a binary string $s$ of length $n = a + b$ such that there are exactly $a$ zeroes, exactly $b$ ones and exactly $x$ indices $i$ (where $1 \le i < n$) such that $s_i \ne s_{i + 1}$. I... | {"inputs": ["2 2 1\n", "3 3 3\n", "5 3 6\n", "7 8 7\n", "2 3 3\n", "2 2 2\n", "3 4 6\n", "1 1 1\n"], "outputs": ["1100\n", "101100\n", "01010100\n", "101010111110000\n", "10110\n", "1001\n", "1010101\n", "10\n"]} | 457 | 145 |
coding | Solve the programming task below in a Python markdown code block.
Say hello!
Write a function to greet a person. Function will take name as input and greet the person by saying hello.
Return null/nil/None if input is empty string or null/nil/None.
Example:
```python
greet("Niks") --> "hello Niks!"
greet("") --> ... | {"functional": "_inputs = [['Niks'], ['Nick'], [''], [None]]\n_outputs = [['hello Niks!'], ['hello Nick!'], [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 isinstance(a, (list, tuple)):... | 126 | 177 |
coding | Solve the programming task below in a Python markdown code block.
An elephant decided to visit his friend. It turned out that the elephant's house is located at point 0 and his friend's house is located at point x(x > 0) of the coordinate line. In one step the elephant can move 1, 2, 3, 4 or 5 positions forward. Determ... | {"inputs": ["5\n", "1\n", "2\n", "3\n", "4\n", "3\n", "1\n", "4\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n"]} | 254 | 70 |
coding | Solve the programming task below in a Python markdown code block.
Gottfried learned about binary number representation. He then came up with this task and presented it to you.
You are given a collection of $n$ non-negative integers $a_1, \ldots, a_n$. You are allowed to perform the following operation: choose two dist... | {"inputs": ["1\n0\n", "1\n0\n", "1\n1\n", "1\n42\n", "1\n17\n", "1\n123\n", "1\n167\n", "1\n123\n"], "outputs": ["0\n", "0\n", "1\n", "1764\n", "289\n", "15129\n", "27889\n", "15129\n"]} | 649 | 111 |
coding | Solve the programming task below in a Python markdown code block.
Find the edit distance between given two words s1 and s2.
The disntace is the minimum number of single-character edits required to change one word into the other. The edits including the following operations:
* insertion: Insert a character at a partic... | {"inputs": ["`cac\nacm", "`cad\nacm", "`cac\nbcm", "`cac\nmcb", "`cab\nmcb", "`cab\nbcm", "_cac\nmcb", "_cca\nmcb"], "outputs": ["3\n", "3\n", "3\n", "3\n", "2\n", "3\n", "3\n", "3\n"]} | 195 | 85 |
coding | Solve the programming task below in a Python markdown code block.
Pig Latin is an English language game where the goal is to hide the meaning of a word from people not aware of the rules.
So, the goal of this kata is to wite a function that encodes a single word string to pig latin.
The rules themselves are rather ea... | {"functional": "_inputs = [['Hello'], ['CCCC'], ['tes3t5'], ['ay'], [''], ['YA'], ['123'], ['ya1'], ['yaYAya'], ['YayayA']]\n_outputs = [['ellohay'], ['ccccay'], [None], ['ayway'], [None], ['ayay'], [None], [None], ['ayayayay'], ['ayayayay']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or i... | 272 | 230 |
coding | Solve the programming task below in a Python markdown code block.
INTERCAL is the oldest of esoteric programming languages. One of its many weird features is the method of character-based output, known as Turing Tape method. It converts an array of unsigned 8-bit integers into a sequence of characters to print, using t... | {"inputs": ["N\n", "M\n", "o2^\"t\n", "p2^\"t\n", "\\Pk|a\\'\n", "aPk|\\\\'\n", "s3=MS8%X\n", "r3=MS8%X\n"], "outputs": ["142\n", "78\n", "10\n170\n210\n54\n22\n", "242\n194\n210\n54\n22\n", "198\n48\n52\n152\n184\n76\n86\n", "122\n124\n52\n152\n4\n0\n86\n", "50\n2\n16\n10\n232\n174\n120\n138\n", "178\n130\n16\n10\n232... | 475 | 225 |
coding | Solve the programming task below in a Python markdown code block.
Everything was going well in Wasseypur until Ramadhir Singh found out that Sahid Khan plans to kill him someday and takeover his mine. To protect himself, he decided to take preemptive measures and kill Sahid Khan first. However, Sahid Khan also learnt o... | {"inputs": ["2\n4\n0000\n4\n0011"], "outputs": ["SAHID\nRAMADHIR"]} | 683 | 32 |
coding | Solve the programming task below in a Python markdown code block.
Consider the following game:
There are two players, First and Second, sitting in front of a pile of $n$ stones. First always plays first.
There is a set, $\mbox{S}$, of $m$ distinct integers defined as $S=\{s_0,s_1,\ldots,s_{m-1}\}$.
The players move in... | {"inputs": ["15 3\n5 2 3\n"], "outputs": ["Second\n"]} | 471 | 23 |
coding | Solve the programming task below in a Python markdown code block.
The life goes up and down, just like nice sequences. Sequence t_1, t_2, ..., t_{n} is called nice if the following two conditions are satisfied: t_{i} < t_{i} + 1 for each odd i < n; t_{i} > t_{i} + 1 for each even i < n.
For example, sequences (2, ... | {"inputs": ["2\n5 1\n", "2\n5 1\n", "2\n5 2\n", "2\n5 4\n", "2\n10 10\n", "2\n10 10\n", "5\n2 8 4 7 7\n", "5\n1 1 1 4 3\n"], "outputs": ["1\n", "1", "1\n", "1\n", "0\n", "0", "2\n", "1\n"]} | 559 | 116 |
coding | Solve the programming task below in a Python markdown code block.
Chef's new friend hErd gave him two functions f and g.
The function f is defined over x (x≥ 1) as:
f(x) = \begin{cases}
0, & \text{if } x = 1 \\
f( \frac{x}{2} ) + 1, & \text{if } x \text{ is even} \\
f( \lfloor \frac{x}{2} \rfloor ), & \text{if } x ... | {"inputs": ["3\n1 1\n1 2\n1 20"], "outputs": ["1\n4\n35"]} | 573 | 30 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given a 2D integer array circles where circles[i] = [xi, yi, ri] represents the center (xi, yi) and radius ri of the ith circle drawn on a grid, return the number of lattice points that are present inside at least one... | {"functional": "def check(candidate):\n assert candidate(circles = [[2,2,1]]) == 5\n assert candidate(circles = [[2,2,2],[3,4,1]]) == 16\n\n\ncheck(Solution().countLatticePoints)"} | 135 | 62 |
coding | Solve the programming task below in a Python markdown code block.
Easy and hard versions are actually different problems, so we advise you to read both statements carefully.
You are given a weighted rooted tree, vertex 1 is the root of this tree. Also, each edge has its own cost.
A tree is a connected graph without c... | {"inputs": ["4\n4 7\n2 1 4 2\n3 2 4 1\n4 1 2 2\n3 20\n2 1 8 1\n3 1 0 2\n5 50\n1 3 100 1\n1 5 6 2\n2 4 123 2\n5 4 55 1\n2 100\n1 2 954 1\n", "4\n4 2\n2 1 4 2\n3 2 4 1\n4 1 2 2\n3 20\n2 1 8 1\n3 1 0 2\n5 50\n1 3 100 1\n1 5 6 2\n2 4 123 2\n5 4 55 1\n2 100\n1 2 954 1\n", "4\n4 7\n2 1 4 2\n3 2 4 1\n4 1 1 2\n3 20\n2 1 8 1\n3... | 734 | 986 |
coding | Solve the programming task below in a Python markdown code block.
Mishka is trying really hard to avoid being kicked out of the university. In particular, he was doing absolutely nothing for the whole semester, miraculously passed some exams so that just one is left.
There were $n$ classes of that subject during the s... | {"inputs": ["2\n7\n", "2\n0\n", "2\n0\n", "2\n7\n", "2\n5\n", "2\n4\n", "2\n1\n", "2\n2\n"], "outputs": ["0 7 \n", "0 0 \n", "0 0\n", "0 7\n", "0 5\n", "0 4\n", "0 1\n", "0 2\n"]} | 582 | 104 |
coding | Solve the programming task below in a Python markdown code block.
After a successful field test, Heidi is considering deploying a trap along some Corridor, possibly not the first one. She wants to avoid meeting the Daleks inside the Time Vortex, so for abundance of caution she considers placing the traps only along tho... | {"inputs": ["3 3\n1 2 8\n2 3 3\n3 1 7\n", "3 3\n1 2 8\n2 3 3\n3 1 0\n", "3 3\n1 2 8\n2 3 1\n3 1 0\n", "3 3\n1 2 8\n2 3 6\n3 1 4\n", "3 3\n1 2 8\n2 3 3\n3 1 4\n", "10 9\n5 10 606854707\n3 8 737506631\n2 4 429066157\n8 9 947792932\n6 4 56831480\n2 5 541638168\n10 7 20498997\n7 9 250445792\n6 1 9522145\n", "10 10\n4 8 149... | 396 | 596 |
coding | Solve the programming task below in a Python markdown code block.
JJ loves playing with averages. He has an array A of length N. He wants to divide the array A into two non-empty subsets P and Q such that the value of mean(P) + mean(Q) is as large as possible. (Note that each A_{i} must belong to either subset P or sub... | {"inputs": ["2\n2\n4 5\n5\n2 2 2 2 2\n"], "outputs": ["9.000000\n4.000000\n"]} | 540 | 48 |
coding | Solve the programming task below in a Python markdown code block.
Bessie and the cows are playing with sequences and need your help. They start with a sequence, initially containing just the number 0, and perform n operations. Each operation is one of the following: Add the integer x_{i} to the first a_{i} elements of... | {"inputs": ["1\n2 1\n", "1\n2 0\n", "1\n2 1\n", "1\n2 0\n", "1\n2 -1\n", "1\n1 1 1\n", "1\n1 1 0\n", "1\n1 1 0\n"], "outputs": ["0.500000\n", "0.000000\n", "0.500000\n", "0.000000\n", "-0.500000\n", "1.000000\n", "0.000000\n", "0.000000\n"]} | 649 | 164 |
coding | Solve the programming task below in a Python markdown code block.
A group of $n$ friends living in an $m$-dimensional hyperspace want to meet up at some central location. The hyperspace is in the form of an $m$-dimensional grid, and each person can only move along grid lines. For example, to go from $(0,0)\rightarrow(1... | {"inputs": ["3 2\n1 1\n2 2\n3 3\n"], "outputs": ["2 2\n"]} | 630 | 30 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You have an undirected, connected graph of n nodes labeled from 0 to n - 1. You are given an array graph where graph[i] is a list of all the nodes connected with node i by an edge.
Return the length of the shortest pa... | {"functional": "def check(candidate):\n assert candidate(graph = [[1,2,3],[0],[0],[0]]) == 4\n assert candidate(graph = [[1],[0,2,4],[1,3,4],[2],[1,2]]) == 4\n\n\ncheck(Solution().shortestPathLength)"} | 130 | 73 |
coding | Solve the programming task below in a Python markdown code block.
Long long ago, there was a thief. Looking for treasures, he was running about all over the world. One day, he heard a rumor that there were islands that had large amount of treasures, so he decided to head for there.
Finally he found n islands that had ... | {"inputs": ["3\n2 3\n3 6\n1 2\n3\n2 3\n3 5\n2 2\n0", "3\n2 3\n3 6\n2 2\n3\n3 3\n3 6\n2 2\n0", "3\n2 1\n3 6\n1 2\n3\n2 3\n3 5\n0 2\n0", "3\n4 5\n3 8\n1 2\n0\n7 3\n3 5\n2 1\n0", "3\n2 3\n3 6\n1 2\n3\n0 3\n3 5\n1 2\n0", "3\n2 3\n3 6\n1 2\n3\n3 3\n3 5\n2 2\n0", "3\n2 3\n3 6\n1 2\n3\n3 3\n3 6\n2 2\n0", "3\n2 3\n3 8\n2 2\n3\... | 377 | 300 |
coding | Solve the programming task below in a Python markdown code block.
Read problem statements in [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
In Olympics, the countries are ranked by the total number of medals won. You are given six integers G_{1}, S_{1}, B_{1}, and G_{2}, S_{2}, B_{2}, the number o... | {"inputs": ["3\n10 20 30 0 29 30\n0 0 0 0 0 1\n1 1 1 0 0 0\n"], "outputs": ["1\n2\n1"]} | 484 | 58 |
coding | Solve the programming task below in a Python markdown code block.
Implement function which will return sum of roots of a quadratic equation rounded to 2 decimal places, if there are any possible roots, else return **None/null/nil/nothing**. If you use discriminant,when discriminant = 0, x1 = x2 = root => return sum of ... | {"functional": "_inputs = [[1, -35, -23], [6, 0, -24], [-5, 21, 0], [6, 4, 8], [1, 5, -24], [3, 11, 6], [2, 2, 9], [1, -1.6666666666666667, -26], [1, 6, 10], [7, -2, -5], [1, 8, 20], [2, 3, -2], [1, 4, 12], [3, -2, -5], [3, 4, 9], [5, 4, 0], [4, -5, 0], [1, 4, 9], [1, 0, -49], [2, 8, 8], [1, 0, -0.16], [1, 6, 12], [1, ... | 123 | 786 |
coding | 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 $1$ and $m$ inclusive. Segments may intersect, overlap or even coincide with each other. Each segment is characterized by two integers $l_i$ and $r_i$ ($1 \l... | {"inputs": ["1 7\n1 7\n", "1 7\n5 5\n", "1 2\n1 1\n", "1 7\n5 5\n", "1 2\n1 1\n", "1 9\n5 5\n", "1 3\n1 1\n", "1 7\n1 7\n"], "outputs": ["0\n\n", "6\n1 2 3 4 6 7 \n", "1\n2 \n", "6\n1 2 3 4 6 7\n", "1\n2\n", "8\n1 2 3 4 6 7 8 9\n", "2\n2 3\n", "0\n\n"]} | 505 | 170 |
coding | Solve the programming task below in a Python markdown code block.
Mishka received a gift of multicolored pencils for his birthday! Unfortunately he lives in a monochrome world, where everything is of the same color and only saturation differs. This pack can be represented as a sequence a_1, a_2, ..., a_{n} of n integer... | {"inputs": ["1 1 1\n1\n", "1 1 1\n1\n", "1 1 0\n1\n", "3 2 2\n6 7 7\n", "3 2 2\n6 7 7\n", "3 2 3\n6 7 7\n", "4 2 3\n1 2 3 6\n", "4 2 1\n1 1 2 3\n"], "outputs": ["YES\n", "YES\n", "YES\n", "YES\n", "YES\n", "YES\n", "YES\n", "YES\n"]} | 562 | 142 |
coding | Solve the programming task below in a Python markdown code block.
Some days ago, I learned the concept of LCM (least common multiple). I've played with it for several times and I want to make a big number with it.
But I also don't want to use many numbers, so I'll choose three positive integers (they don't have to be ... | {"inputs": ["1\n", "8\n", "6\n", "3\n", "4\n", "5\n", "2\n", "9\n"], "outputs": ["1\n", "280\n", "60\n", "6\n", "12\n", "60\n", "2\n", "504\n"]} | 269 | 77 |
coding | 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"]} | 357 | 158 |
coding | Solve the programming task below in a Python markdown code block.
We have N strings of lowercase English letters: S_1, S_2, \cdots, S_N.
Takahashi wants to make a string that is a palindrome by choosing one or more of these strings - the same string can be chosen more than once - and concatenating them in some order of... | {"inputs": ["1\nx 1\n", "2\nabc 1\nab 0", "2\nabc 1\nba 0", "2\nabc 2\nab 0", "2\nabc 2\nba 0", "2\nbac 2\nba 0", "2\nbac 2\nab 0", "2\ncab 2\nab 0"], "outputs": ["1\n", "-1\n", "1\n", "-1\n", "2\n", "-1\n", "2\n", "-1\n"]} | 399 | 124 |
coding | Solve the programming task below in a Python markdown code block.
Bear Limak prepares problems for a programming competition. Of course, it would be unprofessional to mention the sponsor name in the statement. Limak takes it seriously and he is going to change some words. To make it still possible to read, he will try ... | {"inputs": ["1\nZ\n", "1\nV\n", "1\nK\n", "1\nY\n", "1\nU\n", "2\nKV\n", "2\nVK\n", "2\nKU\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "1\n", "0\n"]} | 499 | 87 |
coding | Solve the programming task below in a Python markdown code block.
Kostya likes Codeforces contests very much. However, he is very disappointed that his solutions are frequently hacked. That's why he decided to obfuscate (intentionally make less readable) his code before upcoming contest.
To obfuscate the code, Kostya ... | {"inputs": ["a\n", "z\n", "b\n", "x\n", "c\n", "z\n", "c\n", "b\n"], "outputs": ["YES\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n"]} | 408 | 70 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
A sentence is a string of single-space separated words where each word consists only of lowercase letters.
A word is uncommon if it appears exactly once in one of the sentences, and does not appear in the other senten... | {"functional": "def check(candidate):\n assert candidate(s1 = \"this apple is sweet\", s2 = \"this apple is sour\") == [\"sweet\",\"sour\"]\n assert candidate(s1 = \"apple apple\", s2 = \"banana\") == [\"banana\"]\n\n\ncheck(Solution().uncommonFromSentences)"} | 126 | 76 |
coding | Solve the programming task below in a Python markdown code block.
Chef is playing a game with two of his friends. In this game, each player chooses an integer between $1$ and $P$ inclusive. Let's denote the integers chosen by Chef, friend 1 and friend 2 by $i$, $j$ and $k$ respectively; then, Chef's score is
(((Nmodi)... | {"inputs": ["2\n4 4\n3 4"], "outputs": ["9\n13"]} | 515 | 23 |
coding | Solve the programming task below in a Python markdown code block.
Tom is interested in power consumption of his favourite laptop. His laptop has three modes. In normal mode laptop consumes P1 watt per minute. T1 minutes after Tom moved the mouse or touched the keyboard for the last time, a screensaver starts and power ... | {"inputs": ["1 5 2 1 6 3\n2 4\n", "1 0 2 1 6 9\n1 4\n", "1 5 0 1 6 3\n3 4\n", "1 2 0 1 6 3\n3 4\n", "1 5 2 1 6 3\n1 4\n", "1 3 2 1 5 9\n1 4\n", "1 3 2 1 6 9\n1 4\n", "1 5 0 1 6 3\n2 4\n"], "outputs": ["10\n", "0\n", "5\n", "2\n", "15\n", "9\n", "9\n", "10\n"]} | 413 | 185 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given an integer array arr.
We split arr into some number of chunks (i.e., partitions), and individually sort each chunk. After concatenating them, the result should equal the sorted array.
Return the largest ... | {"functional": "def check(candidate):\n assert candidate(arr = [5,4,3,2,1]) == 1\n assert candidate(arr = [2,1,3,4,4]) == 4\n\n\ncheck(Solution().maxChunksToSorted)"} | 105 | 61 |
coding | Solve the programming task below in a Python markdown code block.
Each evening after the dinner the SIS's students gather together to play the game of Sport Mafia.
For the tournament, Alya puts candies into the box, which will serve as a prize for a winner. To do that, she performs $n$ actions. The first action perfo... | {"inputs": ["1 1\n", "5 0\n", "3 2\n", "4 1\n", "7 7\n", "9 0\n", "4 1\n", "7 7\n"], "outputs": ["0", "3", "1", "2", "3", "6", "2\n", "3\n"]} | 743 | 80 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an integer n, return a string array answer (1-indexed) where:
answer[i] == "FizzBuzz" if i is divisible by 3 and 5.
answer[i] == "Fizz" if i is divisible by 3.
answer[i] == "Buzz" if i is divisible by 5.
answer... | {"functional": "def check(candidate):\n assert candidate(n = 3) == [\"1\",\"2\",\"Fizz\"]\n assert candidate(n = 5) == [\"1\",\"2\",\"Fizz\",\"4\",\"Buzz\"]\n assert candidate(n = 15) == [\"1\",\"2\",\"Fizz\",\"4\",\"Buzz\",\"Fizz\",\"7\",\"8\",\"Fizz\",\"Buzz\",\"11\",\"Fizz\",\"13\",\"14\",\"FizzBuzz\"]\n\n\... | 133 | 110 |
coding | Solve the programming task below in a Python markdown code block.
Petr likes to come up with problems about randomly generated data. This time problem is about random permutation. He decided to generate a random permutation this way: he takes identity permutation of numbers from 1 to n and then 3n times takes a random ... | {"inputs": ["5\n2 4 5 1 3\n"], "outputs": ["Petr\n"]} | 376 | 25 |
coding | Solve the programming task below in a Python markdown code block.
The only difference between the easy and the hard versions is constraints.
A subsequence is a string that can be derived from another string by deleting some or no symbols without changing the order of the remaining symbols. Characters to be deleted are... | {"inputs": ["1 2\nu\n", "1 5\nw\n", "1 5\nw\n", "1 2\nu\n", "1 0\ns\n", "1 10\ns\n", "1 25\no\n", "1 50\ns\n"], "outputs": ["1\n", "-1\n", "-1\n", "1\n", "0\n", "-1\n", "-1\n", "-1\n"]} | 496 | 105 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given an integer n. We reorder the digits in any order (including the original order) such that the leading digit is not zero.
Return true if and only if we can do this so that the resulting number is a power ... | {"functional": "def check(candidate):\n assert candidate(n = 1) == True\n assert candidate(n = 10) == False\n\n\ncheck(Solution().reorderedPowerOf2)"} | 99 | 45 |
coding | Solve the programming task below in a Python markdown code block.
Petya and Gena love playing table tennis. A single match is played according to the following rules: a match consists of multiple sets, each set consists of multiple serves. Each serve is won by one of the players, this player scores one point. As soon a... | {"inputs": ["1\n1\n", "1\n2\n", "1\n2\n", "1\n1\n", "4\n1 1 1 1\n", "4\n1 2 1 2\n", "4\n1 1 2 1\n", "4\n2 2 1 2\n"], "outputs": ["1\n1 1\n", "1\n1 1\n", "1\n1 1\n", "1\n1 1\n", "3\n1 4\n2 2\n4 1\n", "0\n", "2\n1 3\n3 1\n", "2\n1 3\n3 1\n"]} | 581 | 154 |
coding | Solve the programming task below in a Python markdown code block.
Roy lives in a city that is circular in shape on a $2{D}$ plane that has radius ${r}$. The city center is located at origin $(0,0)$ and it has suburbs lying on the lattice points (points with integer coordinates). The city Police Department Headquarters ... | {"inputs": ["5\n1 3\n1 4\n4 4\n25 11\n25 12\n"], "outputs": ["impossible\npossible\npossible\nimpossible\npossible\n"]} | 666 | 48 |
coding | Solve the programming task below in a Python markdown code block.
You are given the current time in 24-hour format hh:mm. Find and print the time after a minutes.
Note that you should find only the time after a minutes, see the examples to clarify the problem statement.
You can read more about 24-hour format here htt... | {"inputs": ["10:10\n0\n", "10:01\n0\n", "04:05\n0\n", "02:59\n1\n", "09:11\n0\n", "19:00\n0\n", "23:59\n1\n", "11:59\n1\n"], "outputs": ["10:10\n", "10:01\n", "04:05\n", "03:00\n", "09:11\n", "19:00\n", "00:00\n", "12:00\n"]} | 281 | 150 |
coding | Solve the programming task below in a Python markdown code block.
Your task is to convert a given number into a string with commas added for easier readability. The number should be rounded to 3 decimal places and the commas should be added at intervals of three digits before the decimal point. There does not need to ... | {"functional": "_inputs = [[1], [1000], [100.2346], [1000000000.23], [9123.212], [-1], [-1000000.123], [-2000.0], [-999.9999], [-1234567.0001236]]\n_outputs = [['1'], ['1,000'], ['100.235'], ['1,000,000,000.23'], ['9,123.212'], ['-1'], ['-1,000,000.123'], ['-2,000'], ['-1,000'], ['-1,234,567']]\nimport math\ndef _deep_... | 233 | 334 |
coding | 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.
We say that an integer x is expressible from nums if there exist some integers 0 <= index1 < index2 < ... < indexk < nums.length for which nums[index1] | nums[index2] | ..... | {"functional": "def check(candidate):\n assert candidate(nums = [2,1]) == 4\n assert candidate(nums = [5,3,2]) == 1\n\n\ncheck(Solution().minImpossibleOR)"} | 156 | 50 |
coding | Solve the programming task below in a Python markdown code block.
One of the first chain emails I ever received was about a supposed Cambridge University study that suggests your brain can read words no matter what order the letters are in, as long as the first and last letters of each word are correct.
Your task is ... | {"functional": "_inputs = [['Hi'], ['Hi!'], ['Hey'], ['Hey?']]\n_outputs = [['Hi'], ['Hi!'], ['Hey'], ['Hey?']]\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... | 354 | 177 |
coding | Solve the programming task below in a Python markdown code block.
Raccoon is fighting with a monster.
The health of the monster is H.
Raccoon can use N kinds of special moves. Using the i-th move decreases the monster's health by A_i.
There is no other way to decrease the monster's health.
Raccoon wins when the monster... | {"inputs": ["8 3\n3 0 6", "8 3\n3 1 6", "8 4\n3 1 6", "8 4\n4 1 6", "10 3\n4 4 6", "20 3\n3 5 6", "10 3\n4 0 6", "20 3\n3 3 6"], "outputs": ["Yes\n", "Yes\n", "Yes\n", "Yes\n", "Yes\n", "No\n", "Yes\n", "No\n"]} | 261 | 130 |
coding | Solve the programming task below in a Python markdown code block.
Create a program that inputs the test result data of the visual acuity test and outputs the number of people who apply to each judgment based on the following visual acuity judgment table for each of the left and right eyesight.
Judgment | Sight
--- | -... | {"inputs": ["1.0 1.2\n0.8 1.5\n1.2 0.7\n2.0 2.0", "1.0 1.2\n0.8 1.5\n1.2 0.7\n2.0 2.1903643288076555", "1.0 1.2\n0.8 1.5\n1.2 0.7\n2.751284804693524 2.1903643288076555", "1.0 1.2\n0.8 1.5471720124202895\n1.2 0.7\n2.751284804693524 2.1903643288076555", "1.0 1.6960573379527397\n0.8 1.5471720124202895\n1.2 0.7\n2.75128480... | 390 | 782 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an integer array nums, return the value of the bitwise OR of the sum of all possible subsequences in the array.
A subsequence is a sequence that can be derived from another sequence by removing zero or more elem... | {"functional": "def check(candidate):\n assert candidate(nums = [2,1,0,3]) == 7\n assert candidate(nums = [0,0,0]) == 0\n\n\ncheck(Solution().subsequenceSumOr)"} | 103 | 55 |
coding | Solve the programming task below in a Python markdown code block.
You are both a shop keeper and a shop assistant at a small nearby shop. You have $n$ goods, the $i$-th good costs $a_i$ coins.
You got tired of remembering the price of each product when customers ask for it, thus you decided to simplify your life. More... | {"inputs": ["1\n2\n75 2\n", "1\n2\n65 0\n", "1\n2\n777 1\n", "1\n2\n777 1\n", "1\n2\n386 1\n", "1\n2\n665 1\n", "1\n2\n449 1\n", "1\n2\n327 1\n"], "outputs": ["39\n", "33\n", "389\n", "389\n", "194\n", "333\n", "225\n", "164\n"]} | 490 | 146 |
coding | 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... | 131 | 221 |
coding | Solve the programming task below in a Python markdown code block.
In a building where Polycarp lives there are equal number of flats on each floor. Unfortunately, Polycarp don't remember how many flats are on each floor, but he remembers that the flats are numbered from 1 from lower to upper floors. That is, the first ... | {"inputs": ["1 0\n", "2 0\n", "3 0\n", "3 0\n", "6 0\n", "9 0\n", "2 0\n", "2 0\n"], "outputs": ["1\n", "-1\n", "-1\n", "-1\n", "-1\n", "-1\n", "-1\n", "-1\n"]} | 571 | 86 |
coding | Solve the programming task below in a Python markdown code block.
Consider a table G of size n × m such that G(i, j) = GCD(i, j) for all 1 ≤ i ≤ n, 1 ≤ j ≤ m. GCD(a, b) is the greatest common divisor of numbers a and b.
You have a sequence of positive integer numbers a_1, a_2, ..., a_{k}. We say that this sequence occ... | {"inputs": ["11 4 1\n11\n", "11 10 1\n11\n", "11 10 1\n11\n", "5 5 5\n1 1 1 1 1\n", "5 5 5\n1 1 1 1 1\n", "5 5 5\n1 1 2 1 1\n", "5 2 5\n1 1 2 1 1\n", "5 2 5\n2 1 2 1 1\n"], "outputs": ["NO\n", "NO\n", "NO\n", "YES\n", "YES\n", "NO\n", "NO\n", "NO\n"]} | 446 | 166 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.