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.
Create a program that will take in a string as input and, if there are duplicates of more than two alphabetical characters in the string, returns the string with all the extra characters in a bracket.
For example, the input "aaaabbcdefffffffg" should re... | {"functional": "_inputs = [['aaaabbcdefffffffg'], [3], ['boopdedoop'], ['helloookat'], [True], [''], ['aAAabbcdeffFfFffg'], ['aAAabbcdeFFFffffg'], [{}], [[5.3]]]\n_outputs = [['aa[aa]bbcdeff[fffff]g'], ['Please enter a valid string'], ['boopdedoop'], ['helloo[o]kat'], ['Please enter a valid string'], [''], ['aAAabbcdef... | 128 | 291 |
coding | Solve the programming task below in a Python markdown code block.
Inspired by the development team at Vooza, write the function `howManyLightsabersDoYouOwn`/`how_many_light_sabers_do_you_own` that
* accepts the name of a programmer, and
* returns the number of lightsabers owned by that person.
The only person who ow... | {"functional": "_inputs = [['Zach'], ['zach']]\n_outputs = [[18], [0]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) != len(b): return False\n ... | 266 | 171 |
coding | Solve the programming task below in a Python markdown code block.
Given an array of integer $a_1, a_2, \ldots, a_n$. In one operation you can make $a_i := a_i + 1$ if $i < n$ and $a_i \leq a_{i + 1}$, or $i = n$ and $a_i \leq a_1$.
You need to check whether the array $a_1, a_2, \ldots, a_n$ can become equal to the arr... | {"inputs": ["1\n5\n4 4 4 4 4\n3 3 3 3 3\n", "1\n2\n10 10\n1000000 1000000\n", "1\n2\n1 1\n1000000000 1000000000\n", "1\n4\n1 1 1 1\n40000000 40000000 40000000 40000000\n", "5\n3\n1 2 5\n1 2 5\n2\n2 2\n1 3\n4\n3 4 1 2\n6 4 2 5\n3\n2 4 1\n4 5 3\n5\n1 2 3 4 5\n6 5 6 7 6\n"], "outputs": ["NO\n", "YES\n", "YES\n", "YES\n", ... | 711 | 252 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given two arrays of integers nums1 and nums2, possibly of different lengths. The values in the arrays are between 1 and 6, inclusive.
In one operation, you can change any integer's value in any of the arrays t... | {"functional": "def check(candidate):\n assert candidate(nums1 = [1,2,3,4,5,6], nums2 = [1,1,2,2,2,2]) == 3\n assert candidate(nums1 = [1,1,1,1,1,1,1], nums2 = [6]) == -1\n assert candidate(nums1 = [6,6], nums2 = [1]) == 3\n\n\ncheck(Solution().minOperations)"} | 163 | 110 |
coding | Solve the programming task below in a Python markdown code block.
A little bear Limak plays a game. He has five cards. There is one number written on each card. Each number is a positive integer.
Limak can discard (throw out) some cards. His goal is to minimize the sum of numbers written on remaining (not discarded) c... | {"inputs": ["7 9 3 1 8\n", "8 7 1 8 7\n", "7 7 7 8 8\n", "8 8 8 2 2\n", "8 8 2 2 2\n", "1 1 1 1 1\n", "8 1 8 8 8\n", "1 1 1 8 1\n"], "outputs": ["28\n", "15\n", "16\n", "4\n", "6\n", "2\n", "9\n", "9\n"]} | 487 | 137 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a 0-indexed string blocks of length n, where blocks[i] is either 'W' or 'B', representing the color of the ith block. The characters 'W' and 'B' denote the colors white and black, respectively.
You are a... | {"functional": "def check(candidate):\n assert candidate(blocks = \"WBBWWBBWBW\", k = 7) == 3\n assert candidate(blocks = \"WBWBBBW\", k = 2) == 0\n\n\ncheck(Solution().minimumRecolors)"} | 163 | 62 |
coding | Solve the programming task below in a Python markdown code block.
Inna loves digit 9 very much. That's why she asked Dima to write a small number consisting of nines. But Dima must have misunderstood her and he wrote a very large number a, consisting of digits from 1 to 9.
Inna wants to slightly alter the number Dima ... | {"inputs": ["1\n", "2\n", "3\n", "0\n", "4\n", "7\n", "1\n", "70\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n"]} | 573 | 71 |
coding | Solve the programming task below in a Python markdown code block.
It seems like the year of 2013 came only yesterday. Do you know a curious fact? The year of 2013 is the first year after the old 1987 with only distinct digits.
Now you are suggested to solve the following problem: given a year number, find the minimum ... | {"inputs": ["1987\n", "2013\n", "1000\n", "1001\n", "1234\n", "5555\n", "9000\n", "1111\n"], "outputs": ["2013\n", "2014\n", "1023\n", "1023\n", "1235\n", "5601\n", "9012\n", "1203\n"]} | 186 | 118 |
coding | Solve the programming task below in a Python markdown code block.
Sherlock considers a string to be valid if all characters of the string appear the same number of times. It is also valid if he can remove just $1$ character at $1$ index in the string, and the remaining characters will occur the same number of times. ... | {"inputs": ["aabbcd\n", "aabbccddeefghi\n", "abcdefghhgfedecba\n"], "outputs": ["NO\n", "NO\n", "YES\n"]} | 556 | 42 |
coding | Solve the programming task below in a Python markdown code block.
Consider the following arithmetic progression with n terms:
* x, x + d, x + 2d, \ldots, x + (n-1)d
What is the product of all terms in this sequence? Compute the answer modulo 1\ 000\ 003.
You are given Q queries of this form. In the i-th query, com... | {"inputs": ["2\n7 3 4\n12345 30036 63", "2\n7 3 4\n12345 57737 63", "2\n7 1 1\n9796 9219 1485", "2\n7 2 4\n12345 57737 63", "2\n7 1 1\n9796 9219 2637", "2\n3 2 4\n12345 57737 63", "2\n3 1 4\n12345 57737 63", "2\n3 1 0\n12345 57737 63"], "outputs": ["14560\n487009\n", "14560\n462686\n", "7\n37900\n", "9009\n462686\n", "... | 276 | 300 |
coding | Solve the programming task below in a Python markdown code block.
Read problems statements in [Russian].
Chef has an array A of size N. Chef wants to choose any subsequence of size exactly \lceil \frac{N}{2} \rceil from the array such that GCD of all the elements in that sequence must be 2. Chef names such a kind of ... | {"inputs": ["3\n5\n1 2 3 4 5\n4\n1 2 3 4\n3\n30 42 70"], "outputs": ["NO\nYES\nNO"]} | 624 | 49 |
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 tokens that represents an arithmetic expression in a Reverse Polish Notation.
Evaluate the expression. Return an integer that represents the value of the expression.
Note that:
The v... | {"functional": "def check(candidate):\n assert candidate(tokens = [\"2\",\"1\",\"+\",\"3\",\"*\"]) == 9\n assert candidate(tokens = [\"4\",\"13\",\"5\",\"/\",\"+\"]) == 6\n assert candidate(tokens = [\"10\",\"6\",\"9\",\"3\",\"+\",\"-11\",\"*\",\"/\",\"*\",\"17\",\"+\",\"5\",\"+\"]) == 22\n\n\ncheck(Solution()... | 159 | 105 |
coding | Solve the programming task below in a Python markdown code block.
The season for Snuke Festival has come again this year. First of all, Ringo will perform a ritual to summon Snuke. For the ritual, he needs an altar, which consists of three parts, one in each of the three categories: upper, middle and lower.
He has N p... | {"inputs": ["2\n1 5\n2 4\n2 6", "2\n2 5\n2 4\n2 6", "2\n0 5\n2 4\n2 6", "2\n0 5\n2 4\n2 5", "2\n0 5\n2 4\n2 3", "2\n1 5\n2 4\n3 6", "2\n0 10\n2 4\n2 3", "2\n0 12\n2 4\n2 3"], "outputs": ["2\n", "1\n", "2\n", "2\n", "1\n", "3", "1\n", "1\n"]} | 477 | 159 |
coding | Solve the programming task below in a Python markdown code block.
There is a train going from Station A to Station B that costs X yen (the currency of Japan).
Also, there is a bus going from Station B to Station C that costs Y yen.
Joisino got a special ticket. With this ticket, she can take the bus for half the fare i... | {"inputs": ["5 0", "1 2", "1 2\n", "3 54", "3 34", "5 34", "5 -1", "51 1"], "outputs": ["5\n", "2\n", "2\n", "30\n", "20\n", "22\n", "4\n", "51\n"]} | 256 | 87 |
coding | Solve the programming task below in a Python markdown code block.
«Bersoft» company is working on a new version of its most popular text editor — Bord 2010. Bord, like many other text editors, should be able to print out multipage documents. A user keys a sequence of the document page numbers that he wants to print out... | {"inputs": ["2\n", "1\n", "3\n", "5\n", "7\n", "37\n", "19\n", "30\n"], "outputs": ["2", "1", "3\n", "5\n", "7\n", "37", "19\n", "30\n"]} | 455 | 73 |
coding | Solve the programming task below in a Python markdown code block.
Read problems statements in Mandarin Chinese here
Read problems statements in Russian here
------ Problem Statement ------
One day Chef is waiting his girlfriend on the bus station. The girlfriend said that she will be at time_{1}. Chef went to the ... | {"inputs": ["3\n10:00\n09:00\n6\n10:00\n09:00\n48\n10:00\n09:00\n60", "3\n10:00\n09:00\n6\n10:00\n09:00\n56\n10:00\n09:00\n60", "3\n10:00\n09:00\n6\n10:00\n09:00\n56\n10:00\n09:00\n54", "3\n10:01\n09:00\n7\n10:00\n09:00\n48\n10:00\n09:00\n60", "3\n10:00\n09:00\n8\n10:00\n08:00\n48\n10:00\n09:00\n60", "3\n10:01\n09:00\n... | 564 | 655 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given an integer array nums sorted in non-decreasing order.
Build and return an integer array result with the same length as nums such that result[i] is equal to the summation of absolute differences between n... | {"functional": "def check(candidate):\n assert candidate(nums = [2,3,5]) == [4,3,5]\n assert candidate(nums = [1,4,6,8,10]) == [24,15,13,15,21]\n\n\ncheck(Solution().getSumAbsoluteDifferences)"} | 142 | 78 |
coding | Solve the programming task below in a Python markdown code block.
A permutation is a sequence of integers from 1 to n of length n containing each number exactly once. For example, (1), (4, 3, 5, 1, 2), (3, 2, 1) are permutations, and (1, 1), (4, 3, 1), (2, 3, 4) are not.
There are many tasks on permutations. Today yo... | {"inputs": ["1\n1\n", "1\n2\n", "1\n3\n", "1\n5\n", "1\n4\n", "1\n6\n", "3\n2 1 1\n", "3\n4 1 1\n"], "outputs": ["1\n1 ", "-1", "-1\n", "-1\n", "-1\n", "-1\n", "2\n1 1 2 ", "-1\n"]} | 527 | 99 |
coding | Solve the programming task below in a Python markdown code block.
Fennec is fighting with N monsters.
The health of the i-th monster is H_i.
Fennec can do the following two actions:
- Attack: Fennec chooses one monster. That monster's health will decrease by 1.
- Special Move: Fennec chooses one monster. That monster... | {"inputs": ["3 1\n0 1 5", "3 0\n0 1 5", "3 1\n4 1 6", "3 1\n4 1 5", "3 1\n4 1 5\n", "8 8\n7 9 3 2 3 8 4 6", "8 0\n4 9 5 2 3 6 5 6", "8 1\n4 9 5 2 3 6 5 6"], "outputs": ["1\n", "6\n", "5\n", "5", "5\n", "0\n", "40\n", "31\n"]} | 320 | 158 |
coding | Solve the programming task below in a Python markdown code block.
You are given an integer N. You have to count the number of distinct tuples (A, B, C, D) with 1 ≤ A, B, C, D ≤ N such that A \cdot B = C \cdot D.
Two tuples, say (A, B, C, D) and (E, F, G, H) are considered to be different if at least one of the follow... | {"inputs": ["3\n3\n50\n35"], "outputs": ["15\n10950\n4831"]} | 495 | 32 |
coding | Solve the programming task below in a Python markdown code block.
Makes solves problems on Decoforces and lots of other different online judges. Each problem is denoted by its difficulty — a positive integer number. Difficulties are measured the same across all the judges (the problem with difficulty d on Decoforces is... | {"inputs": ["1 1\n3\n", "1 1\n2\n", "1 1\n4\n", "1 4\n9\n", "1 2\n9\n", "1 2\n9\n", "1 1\n4\n", "1 1\n3\n"], "outputs": ["1\n", "0\n", "1\n", "1\n", "2\n", "2", "1", "1"]} | 539 | 99 |
coding | Solve the programming task below in a Python markdown code block.
Manasa was sulking her way through a boring class when suddenly her teacher singled her out and asked her a question. He gave her a number n and Manasa has to come up with the smallest number m which contains atleast n number of zeros at the end of m!. H... | {"inputs": ["3\n1\n2\n3\n"], "outputs": ["5\n10\n15\n"]} | 282 | 26 |
coding | Solve the programming task below in a Python markdown code block.
A TV program called "Saizo" is popular in a certain country. In this program, participants challenge field athletics and get a prize if they successfully capture it.
Field athletics are made by arranging blocks of different heights in a row, and how to ... | {"inputs": ["5\n5\n5 101 5 98 117\n2\n3 100\n2\n101 26\n3\n22 86 50\n7\n123 17 959 901 2 971 1573", "5\n5\n10 101 5 50 59\n2\n20 100\n2\n100 30\n3\n5 86 50\n7\n123 82 959 319 41 971 275", "5\n5\n5 101 5 98 117\n2\n15 100\n2\n100 30\n3\n22 86 50\n7\n123 82 959 901 2 971 1573", "5\n5\n5 101 5 98 117\n2\n15 100\n2\n101 30... | 446 | 875 |
coding | Solve the programming task below in a Python markdown code block.
The number ```1331``` is the first positive perfect cube, higher than ```1```, having all its digits odd (its cubic root is ```11```).
The next one is ```3375```.
In the interval [-5000, 5000] there are six pure odd digit perfect cubic numbers and are... | {"functional": "_inputs = [[-5000, 5000], [0, 5000], [-1, 5000], [-5000, -2]]\n_outputs = [[[-3375, -1331, -1, 1, 1331, 3375]], [[1, 1331, 3375]], [[-1, 1, 1331, 3375]], [[-3375, -1331]]]\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,... | 403 | 270 |
coding | Solve the programming task below in a Python markdown code block.
Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
There is a secret sequence $A_{1}, A_{2}, \ldots, A_{N}$. We do not know the elements of this sequence, but we know another sequence $B_{1}, B_{2}, \... | {"inputs": ["1\n5 3\n4 5 6 7\n1 2\n1 3\n4 1"], "outputs": ["4\nUNKNOWN\n5"]} | 587 | 40 |
coding | Solve the programming task below in a Python markdown code block.
There are N towns on a line running east-west. The towns are numbered 1 through N, in order from west to east. Each point on the line has a one-dimensional coordinate, and a point that is farther east has a greater coordinate value. The coordinate of tow... | {"inputs": ["4 2 5\n1 2 8 7", "4 2 5\n1 1 5 7", "4 2 5\n1 2 5 7", "7 2 101\n18 8 32 1 146 3 37", "7 2 101\n13 8 32 1 146 3 37", "7 2 101\n13 8 32 1 182 3 37", "7 2 101\n20 14 32 1 72 3 37", "7 2 100\n13 8 32 1 182 3 37"], "outputs": ["5\n", "9\n", "11", "-151\n", "-141\n", "-213\n", "-7\n", "-214\n"]} | 387 | 231 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given two strings s and sub. You are also given a 2D character array mappings where mappings[i] = [oldi, newi] indicates that you may perform the following operation any number of times:
Replace a character o... | {"functional": "def check(candidate):\n assert candidate(s = \"fool3e7bar\", sub = \"leet\", mappings = [[\"e\",\"3\"],[\"t\",\"7\"],[\"t\",\"8\"]]) == True\n assert candidate(s = \"fooleetbar\", sub = \"f00l\", mappings = [[\"o\",\"0\"]]) == False\n assert candidate(s = \"Fool33tbaR\", sub = \"leetd\", mappin... | 166 | 148 |
coding | Solve the programming task below in a Python markdown code block.
Johnny has a younger sister Anne, who is very clever and smart. As she came home from the kindergarten, she told his brother about the task that her kindergartener asked her to solve. The task was just to construct a triangle out of four sticks of differ... | {"inputs": ["4 4 4 5\n", "3 1 2 1\n", "1 5 1 3\n", "3 5 1 1\n", "1 5 5 5\n", "8 4 3 1\n", "3 3 3 1\n", "1 1 2 1\n"], "outputs": ["TRIANGLE\n", "SEGMENT\n", "IMPOSSIBLE\n", "IMPOSSIBLE\n", "TRIANGLE\n", "SEGMENT\n", "TRIANGLE\n", "TRIANGLE\n"]} | 359 | 134 |
coding | Solve the programming task below in a Python markdown code block.
Given a set of integers (it can contain equal elements).
You have to split it into two subsets $A$ and $B$ (both of them can contain equal elements or be empty). You have to maximize the value of $mex(A)+mex(B)$.
Here $mex$ of a set denotes the smalles... | {"inputs": ["4\n6\n0 2 1 5 0 1\n3\n0 1 2\n4\n0 2 0 1\n6\n1 2 3 4 5 6\n", "4\n6\n0 2 1 5 0 1\n3\n0 1 2\n4\n0 2 1 1\n6\n1 2 3 4 5 6\n", "4\n6\n0 2 1 5 0 1\n3\n0 1 2\n4\n0 2 1 1\n6\n1 2 0 4 5 7\n", "4\n6\n0 2 1 5 0 1\n3\n0 1 2\n4\n0 2 0 1\n6\n0 2 3 4 5 6\n", "4\n6\n0 2 1 5 0 1\n3\n0 1 2\n4\n1 2 0 1\n6\n0 2 3 5 5 8\n", "4\... | 591 | 486 |
coding | Solve the programming task below in a Python markdown code block.
As most of you might know already, a prime number is an integer `n` with the following properties:
* it must be greater than 1
* it must be divisible only by itself and 1
And that's it: -15 or 8 are not primes, 5 or 97 are; pretty easy, isn't it?
Well... | {"functional": "_inputs = [[1], [2], [5], [143], [-1], [29], [53], [529]]\n_outputs = [[False], [True], [True], [False], [False], [True], [True], [False]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n i... | 631 | 202 |
coding | Solve the programming task below in a Python markdown code block.
Little Petya very much likes playing with little Masha. Recently he has received a game called "Zero-One" as a gift from his mother. Petya immediately offered Masha to play the game with him.
Before the very beginning of the game several cards are lain ... | {"inputs": ["00\n", "11\n", "??\n", "10?\n", "1?0\n", "?10\n", "?01\n", "1?1\n"], "outputs": ["00\n", "11\n", "00\n01\n10\n11\n", "00\n01\n", "00\n10\n", "00\n10\n", "00\n01\n", "01\n11\n"]} | 735 | 113 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given two integer arrays of the same length nums1 and nums2. In one operation, you are allowed to swap nums1[i] with nums2[i].
For example, if nums1 = [1,2,3,8], and nums2 = [5,6,7,4], you can swap the elemen... | {"functional": "def check(candidate):\n assert candidate(nums1 = [1,3,5,4], nums2 = [1,2,3,7]) == 1\n assert candidate(nums1 = [0,3,5,8,9], nums2 = [2,1,4,6,9]) == 1\n\n\ncheck(Solution().minSwap)"} | 221 | 85 |
coding | Solve the programming task below in a Python markdown code block.
A robot is standing at the origin of the infinite two-dimensional plane. Each second the robot moves exactly $1$ meter in one of the four cardinal directions: north, south, west, and east. For the first step the robot can choose any of the four direction... | {"inputs": ["1\n", "2\n", "3\n", "8\n", "4\n", "5\n", "6\n", "7\n"], "outputs": ["4\n", "4\n", "12\n", "25\n", "9\n", "24\n", "16\n", "40\n"]} | 317 | 75 |
coding | Solve the programming task below in a Python markdown code block.
# A History Lesson
The Pony Express was a mail service operating in the US in 1859-60.
It reduced the time for messages to travel between the Atlantic and Pacific coasts to about 10 days, before it was made obsolete by the [transcontinental telegrap... | {"functional": "_inputs = [[[18, 15]], [[43, 23, 40, 13]], [[33, 8, 16, 47, 30, 30, 46]], [[6, 24, 6, 8, 28, 8, 23, 47, 17, 29, 37, 18, 40, 49]], [[50, 50]], [[50, 50, 25, 50, 24]], [[50, 50, 25, 50, 25]], [[50, 50, 25, 50, 26]], [[90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, ... | 251 | 749 |
coding | Solve the programming task below in a Python markdown code block.
Takahashi is hosting an sports meet. There are N people who will participate. These people are conveniently numbered 1 through N. Also, there are M options of sports for this event. These sports are numbered 1 through M. Among these options, Takahashi wi... | {"inputs": ["2 3\n2 1 3\n2 1 3\n2 1 3", "1 3\n2 1 3\n2 1 3\n2 1 3", "1 3\n2 1 3\n2 1 4\n2 1 3", "3 3\n2 1 3\n2 1 3\n2 1 3", "2 5\n5 1 3 4 2\n2 5 3 1 4\n2 3 1 4 5\n2 5 4 3 1", "2 5\n5 1 3 4 2\n2 5 3 1 4\n2 3 1 6 5\n2 5 4 3 1", "2 5\n5 1 3 4 2\n2 5 3 1 4\n2 3 1 6 7\n2 5 4 3 1", "2 5\n5 1 3 4 2\n2 5 3 1 4\n2 0 1 4 5\n2 5 ... | 426 | 309 |
coding | Solve the programming task below in a Python markdown code block.
Chef is not feeling well today. He measured his body temperature using a thermometer and it came out to be X °F.
A person is said to have fever if his body temperature is strictly greater than 98 °F.
Determine if Chef has fever or not.
------ Input F... | {"inputs": ["3\n98\n100\n96\n"], "outputs": ["NO\nYES\nNO\n"]} | 309 | 28 |
coding | Solve the programming task below in a Python markdown code block.
Pak Chanek has a prime number$^\dagger$ $n$. Find a prime number $m$ such that $n + m$ is not prime.
$^\dagger$ A prime number is a number with exactly $2$ factors. The first few prime numbers are $2,3,5,7,11,13,\ldots$. In particular, $1$ is not a prim... | {"inputs": ["1\n65777\n", "3\n7\n2\n75619\n", "55\n7\n7\n7\n7\n7\n7\n7\n7\n7\n7\n7\n7\n7\n7\n7\n7\n7\n7\n7\n7\n7\n7\n7\n7\n7\n7\n7\n7\n7\n7\n7\n7\n7\n7\n7\n7\n7\n7\n7\n7\n7\n7\n7\n7\n7\n7\n7\n7\n7\n7\n7\n7\n7\n7\n7\n"], "outputs": ["65777\n", "7\n2\n75619\n", "7\n7\n7\n7\n7\n7\n7\n7\n7\n7\n7\n7\n7\n7\n7\n7\n7\n7\n7\n7\... | 418 | 277 |
coding | Solve the programming task below in a Python markdown code block.
One day n friends gathered together to play "Mafia". During each round of the game some player must be the supervisor and other n - 1 people take part in the game. For each person we know in how many rounds he wants to be a player, not the supervisor: th... | {"inputs": ["3\n1 1 1\n", "3\n2 1 1\n", "3\n1 2 1\n", "3\n1 1 2\n", "3\n1 1 0\n", "3\n3 4 2\n", "3\n4 5 5\n", "3\n3 4 1\n"], "outputs": ["2\n", "2\n", "2\n", "2\n", "1\n", "5\n", "7\n", "4\n"]} | 329 | 118 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given two binary search trees root1 and root2, return a list containing all the integers from both trees sorted in ascending order.
Please complete the following python code precisely:
```python
# Definition for a b... | {"functional": "def check(candidate):\n assert candidate(root1 = tree_node([2,1,4]), root2 = tree_node([1,0,3])) == [0,1,1,2,3,4]\n assert candidate(root1 = tree_node([1,None,8]), root2 = tree_node([8,1])) == [1,1,8,8]\n\n\ncheck(Solution().getAllElements)"} | 132 | 96 |
coding | Solve the programming task below in a Python markdown code block.
Given two arrays, the purpose of this Kata is to check if these two arrays are the same. "The same" in this Kata means the two arrays contains arrays of 2 numbers which are same and not necessarily sorted the same way. i.e. [[2,5], [3,6]] is same as [[5,... | {"functional": "_inputs = [[[[2, 5], [3, 6]], [[5, 2], [3, 6]]], [[[2, 5], [3, 6]], [[6, 3], [5, 2]]], [[[2, 5], [3, 6]], [[6, 3], [2, 5]]], [[[2, 5], [3, 5], [6, 2]], [[2, 6], [5, 3], [2, 5]]], [[[2, 5], [3, 5], [6, 2]], [[3, 5], [6, 2], [5, 2]]], [[], []], [[[2, 3], [3, 4]], [[4, 3], [2, 4]]], [[[2, 3], [3, 2]], [[2,... | 334 | 370 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
A peak element in a 2D grid is an element that is strictly greater than all of its adjacent neighbors to the left, right, top, and bottom.
Given a 0-indexed m x n matrix mat where no two adjacent cells are equal, find... | {"functional": "def check(candidate):\n assert candidate(mat = [[1,4],[3,2]]) == [0,1]\n assert candidate(mat = [[10,20,15],[21,30,14],[7,16,32]]) == [1,1]\n\n\ncheck(Solution().findPeakGrid)"} | 166 | 80 |
coding | Solve the programming task below in a Python markdown code block.
Read problems statements in Mandarin Chinese and Russian as well.
You had an array of integer numbers. You also had a beautiful operations called "Copy-Paste" which allowed you to copy any contiguous subsequence of your array and paste it in any positi... | {"inputs": ["2\n5\n1 1 1 1 1\n5\n1 2 3 1 2", "2\n5\n1 1 1 1 1\n5\n1 2 6 1 2", "2\n5\n1 0 1 1 1\n5\n1 3 3 1 2", "2\n5\n1 0 1 2 1\n5\n1 3 3 1 2", "2\n5\n1 1 1 1 1\n5\n1 2 6 0 2", "2\n5\n1 0 1 1 1\n5\n0 3 3 1 2", "2\n5\n1 0 1 2 1\n5\n1 3 3 1 3", "2\n5\n1 1 1 1 1\n5\n1 2 1 1 2"], "outputs": ["1\n3", "1\n3\n", "2\n3\n", "3\... | 502 | 269 |
coding | Solve the programming task below in a Python markdown code block.
Given are two strings S and T.
Let us change some of the characters in S so that T will be a substring of S.
At least how many characters do we need to change?
Here, a substring is a consecutive subsequence. For example, xxx is a substring of yxxxy, but ... | {"inputs": ["cabacc\nabb", "ccbaac\naac", "caacbc\nbba", "ccabac\nabb", "ccabac\nbba", "ccabac\ncba", "ccabac\ncaa", "ccbaac\ncaa"], "outputs": ["1\n", "0\n", "2\n", "1\n", "1\n", "1\n", "1\n", "1\n"]} | 226 | 96 |
coding | Solve the programming task below in a Python markdown code block.
Snuke prepared 6 problems for a upcoming programming contest. For each of those problems, Rng judged whether it can be used in the contest or not.
You are given a string S of length 6. If the i-th character of s is `1`, it means that the i-th problem pr... | {"inputs": ["001011", "100000", "011011", "100100", "111011", "111111", "101100", "110100"], "outputs": ["3\n", "1\n", "4\n", "2\n", "5\n", "6\n", "3\n", "3\n"]} | 213 | 102 |
coding | Solve the programming task below in a Python markdown code block.
Polycarp and Vasiliy love simple logical games. Today they play a game with infinite chessboard and one pawn for each player. Polycarp and Vasiliy move in turns, Polycarp starts. In each turn Polycarp can move his pawn from cell (x, y) to (x - 1, y) or (... | {"inputs": ["2 1 2 2\n", "4 7 7 4\n", "0 1 0 2\n", "0 1 1 0\n", "0 1 1 1\n", "0 1 1 2\n", "0 1 2 0\n", "0 1 2 1\n"], "outputs": ["Polycarp\n", "Vasiliy\n", "Polycarp\n", "Polycarp\n", "Polycarp\n", "Polycarp\n", "Polycarp\n", "Polycarp\n"]} | 444 | 135 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given an integer array cost where cost[i] is the cost of ith step on a staircase. Once you pay the cost, you can either climb one or two steps.
You can either start from the step with index 0, or the step with... | {"functional": "def check(candidate):\n assert candidate(cost = [10,15,20]) == 15\n assert candidate(cost = [1,100,1,1,1,100,1,1,100,1]) == 6\n\n\ncheck(Solution().minCostClimbingStairs)"} | 121 | 80 |
coding | Solve the programming task below in a Python markdown code block.
Kenkoooo found a simple connected graph. The vertices are numbered 1 through n. The i-th edge connects Vertex u_i and v_i, and has a fixed integer s_i.
Kenkoooo is trying to write a positive integer in each vertex so that the following condition is sati... | {"inputs": ["4 3\n1 2 6\n2 3 7\n3 4 7", "3 3\n1 2 3\n2 3 0\n1 3 4", "4 3\n1 2 6\n2 3 7\n3 4 3", "4 3\n1 2 4\n2 3 7\n3 4 7", "4 3\n1 2 6\n2 3 7\n3 4 6", "4 3\n1 2 4\n2 3 1\n3 4 7", "4 3\n1 2 6\n2 3 7\n3 4 2", "4 3\n1 2 2\n2 3 7\n3 4 7"], "outputs": ["5\n", "0\n", "1\n", "3\n", "4\n", "0\n", "0\n", "1\n"]} | 419 | 222 |
coding | Solve the programming task below in a Python markdown code block.
You were strolling outside the restaurant at the end of the universe. On a metaspiral path you stumble upon a weird device which takes a three-digit number as input and processes it. The Hitchhiker's guide to the galaxy explains that it processes the inp... | {"inputs": ["1\n123 5"], "outputs": ["27"]} | 376 | 19 |
coding | Solve the programming task below in a Python markdown code block.
###Instructions
Write a function that takes a negative or positive integer, which represents the number of minutes before (-) or after (+) Sunday midnight, and returns the current day of the week and the current time in 24hr format ('hh:mm') as a string... | {"functional": "_inputs = [[0], [-3], [45], [759], [1236], [1447], [7832], [18876], [259180], [-349000]]\n_outputs = [['Sunday 00:00'], ['Saturday 23:57'], ['Sunday 00:45'], ['Sunday 12:39'], ['Sunday 20:36'], ['Monday 00:07'], ['Friday 10:32'], ['Saturday 02:36'], ['Thursday 23:40'], ['Tuesday 15:20']]\nimport math\nd... | 304 | 295 |
coding | Solve the programming task below in a Python markdown code block.
Create a function that returns an array containing the first `l` digits from the `n`th diagonal of [Pascal's triangle](https://en.wikipedia.org/wiki/Pascal's_triangle).
`n = 0` should generate the first diagonal of the triangle (the 'ones'). The first n... | {"functional": "_inputs = [[0, 10], [1, 10], [2, 10], [3, 10], [4, 10], [10, 0], [100, 6]]\n_outputs = [[[1, 1, 1, 1, 1, 1, 1, 1, 1, 1]], [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]], [[1, 3, 6, 10, 15, 21, 28, 36, 45, 55]], [[1, 4, 10, 20, 35, 56, 84, 120, 165, 220]], [[1, 5, 15, 35, 70, 126, 210, 330, 495, 715]], [[]], [[1, 101... | 138 | 425 |
coding | Solve the programming task below in a Python markdown code block.
You are given N points on a plane. Write a program which will find the sum of squares of distances between all pairs of points.
Input
The first line of input contains one integer number N (1 ≤ N ≤ 100 000) — the number of points. Each of the following ... | {"inputs": ["1\n6 3\n", "1\n7 3\n", "1\n9 3\n", "1\n9 4\n", "1\n6 4\n", "1\n6 2\n", "1\n6 0\n", "1\n8 1\n"], "outputs": ["0", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]} | 170 | 101 |
coding | Solve the programming task below in a Python markdown code block.
Sonya was unable to think of a story for this problem, so here comes the formal description.
You are given the array containing n positive integers. At one turn you can pick any element and increase or decrease it by 1. The goal is the make the array st... | {"inputs": ["1\n1\n", "1\n0\n", "1\n2\n", "1\n4\n", "1\n5\n", "1\n1000\n", "1\n1001\n", "1\n0001\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]} | 346 | 95 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an array of integers arr, you are initially positioned at the first index of the array.
In one step you can jump from index i to index:
i + 1 where: i + 1 < arr.length.
i - 1 where: i - 1 >= 0.
j where: arr[i] ... | {"functional": "def check(candidate):\n assert candidate(arr = [100,-23,-23,404,100,23,23,23,3,404]) == 3\n assert candidate(arr = [7]) == 0\n assert candidate(arr = [7,6,9,6,9,6,9,7]) == 1\n\n\ncheck(Solution().minJumps)"} | 156 | 101 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given a string s of zeros and ones, return the maximum score after splitting the string into two non-empty substrings (i.e. left substring and right substring).
The score after splitting a string is the number of zero... | {"functional": "def check(candidate):\n assert candidate(s = \"011101\") == 5 \n assert candidate(s = \"00111\") == 5\n assert candidate(s = \"1111\") == 3\n\n\ncheck(Solution().maxScore)"} | 107 | 68 |
coding | Solve the programming task below in a Python markdown code block.
A country has coins with denominations
```python
coins_list = d1 < d2 < · · · < dn.
```
You want to make change for n cents, using the smallest number of coins.
```python
# Example 1: U.S. coins
d1 = 1 d2 = 5 d3 = 10 d4 = 25
## Optimal change for 37 ce... | {"functional": "_inputs = [[[1, 5, 10, 25], 37], [[1, 3, 4], 6], [[25, 5, 10, 1, 21], 63], [[1, 4, 5, 10], 8], [[1, 2, 5, 10, 20, 50, 100, 200], 93]]\n_outputs = [[4], [2], [3], [2], [5]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b,... | 215 | 267 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given an integer n. There is a complete binary tree with 2n - 1 nodes. The root of that tree is the node with the value 1, and every node with a value val in the range [1, 2n - 1 - 1] has two children where:
... | {"functional": "def check(candidate):\n assert candidate(n = 3, queries = [[5,3],[4,7],[2,3]]) == [4,5,3]\n assert candidate(n = 2, queries = [[1,2]]) == [2]\n\n\ncheck(Solution().cycleLengthQueries)"} | 295 | 72 |
coding | Solve the programming task below in a Python markdown code block.
This problem was part of the CodeChef April Challenge. All user submissions for this contest problem are publicly available here.
In the game of "BattleShip V", you control a cannon which is attacking a large enemy battleship, armed with many guns. You... | {"inputs": ["1\n2 -2 1"], "outputs": ["2"]} | 384 | 18 |
coding | Solve the programming task below in a Python markdown code block.
There are N items, numbered 1, 2, \ldots, N. For each i (1 \leq i \leq N), Item i has a weight of w_i and a value of v_i.
Taro has decided to choose some of the N items and carry them home in a knapsack. The capacity of the knapsack is W, which means th... | {"inputs": ["2 1\n3 6\n0 97\n8 96", "2 31\n2 4\n1 28\n1 5", "2 1\n1 6\n0 50\n4 96", "3 8\n3 30\n4 35\n5 60", "3 8\n3 30\n4 35\n5 78", "3 8\n3 30\n0 35\n5 78", "2 8\n3 30\n4 50\n5 60", "3 10\n3 30\n0 6\n5 78"], "outputs": ["97\n", "32\n", "56\n", "90\n", "108\n", "143\n", "80\n", "114\n"]} | 346 | 206 |
coding | Solve the programming task below in a Python markdown code block.
There is a new mobile game that starts with consecutively numbered clouds. Some of the clouds are thunderheads and others are cumulus. The player can jump on any cumulus cloud having a number that is equal to the number of the current cloud plus $\mbox... | {"inputs": ["6\n0 0 0 0 1 0\n", "7\n0 0 1 0 0 1 0\n"], "outputs": ["3\n", "4\n"]} | 572 | 48 |
coding | Solve the programming task below in a Python markdown code block.
You are given two integers N and K. Find number of ordered triplets (A, B, C) that satisfy the following conditions:
0 ≤ A, B, C < 2^{N}
A, B and C are distinct
A \oplus B \oplus C = K
Here, \oplus denotes the [bitwise XOR operation].
------ Input Form... | {"inputs": ["3\n2 1\n3 0\n9 100\n"], "outputs": ["6\n42\n260610\n"]} | 393 | 38 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a 0-indexed string s and a dictionary of words dictionary. You have to break s into one or more non-overlapping substrings such that each substring is present in dictionary. There may be some extra chara... | {"functional": "def check(candidate):\n assert candidate(s = \"leetscode\", dictionary = [\"leet\",\"code\",\"leetcode\"]) == 1\n assert candidate(s = \"sayhelloworld\", dictionary = [\"hello\",\"world\"]) == 3\n\n\ncheck(Solution().minExtraChar)"} | 129 | 68 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
There exists an infinitely large two-dimensional grid of uncolored unit cells. You are given a positive integer n, indicating that you must do the following routine for n minutes:
At the first minute, color any arbit... | {"functional": "def check(candidate):\n assert candidate(n = 1) == 1\n assert candidate(n = 2) == 5\n\n\ncheck(Solution().coloredCells)"} | 148 | 44 |
coding | Solve the programming task below in a Python markdown code block.
The sequence is called ordered if it is non-decreasing or non-increasing. For example, sequnces [3, 1, 1, 0] and [1, 2, 3, 100] are ordered, but the sequence [1, 3, 3, 1] is not. You are given a sequence of numbers. You are to find it's shortest subseque... | {"inputs": ["2\n7 8\n", "2\n0 8\n", "2\n0 2\n", "2\n0 3\n", "2\n0 6\n", "2\n-1 6\n", "3\n3 1 2\n", "3\n3 1 1\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "3\n1 2 3\n", "0\n"]} | 315 | 113 |
coding | Solve the programming task below in a Python markdown code block.
In a regular table tennis match, the player who serves changes every time after 2 points are scored, regardless of which players scored them.
Chef and Cook are playing a different match — they decided that the player who serves would change every time af... | {"inputs": ["3\n1 3 2\n0 3 2\n34 55 2"], "outputs": ["CHEF\nCOOK\nCHEF"]} | 370 | 39 |
coding | Solve the programming task below in a Python markdown code block.
We all love the future president (or Führer or duce or sōtō as he could find them more fitting) donald trump, but we might fear that some of his many fans like John Miller or John Barron are not making him justice, sounding too much like their (and our a... | {"functional": "_inputs = [['I will build a huge wall'], ['HUUUUUGEEEE WAAAAAALL'], ['MEXICAAAAAAAANS GOOOO HOOOMEEEE'], ['America NUUUUUKEEEE Oooobaaaamaaaaa'], ['listen migrants: IIII KIIIDD YOOOUUU NOOOOOOTTT']]\n_outputs = [[0], [4], [2.5], [1.89], [1.56]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinsta... | 438 | 239 |
coding | Solve the programming task below in a Python markdown code block.
Think of New York as a rectangular grid consisting of N vertical avenues numerated from 1 to N and M horizontal streets numerated 1 to M. C friends are staying at C hotels located at some street-avenue crossings. They are going to celebrate birthday of o... | {"inputs": ["1 1\n1\n1 1\n1\n1 1\n", "1 1\n1\n1 1\n1\n1 1\n", "1 1\n1\n1 1\n1\n2 1\n", "100 100\n1\n1 100\n1\n1 100\n", "100 100\n1\n1 100\n1\n1 100\n", "101 100\n1\n1 100\n1\n1 100\n", "111 100\n1\n1 100\n1\n1 100\n", "100 101\n1\n1 100\n1\n1 100\n"], "outputs": ["0\n1\n", "0\n1\n", "1\n1\n", "0\n1\n", "0\n1\n", "0\n1... | 354 | 238 |
coding | Solve the programming task below in a Python markdown code block.
Given a set of N integer points on the Cartesian plane. Your task is to find an integer point satisfying its sum of distances to N given points (S) is minimum.
------ Input ------
There are several test cases (fifteen at most), each formed as follows:... | {"inputs": ["3\n1 1\n2 2\n3 3\n5\n1 4\n2 3\n5 2\n3 5\n4 1\n0\n"], "outputs": ["2.828427\n9.640986"]} | 232 | 65 |
coding | Solve the programming task below in a Python markdown code block.
Victor tries to write his own text editor, with word correction included. However, the rules of word correction are really strange.
Victor thinks that if a word contains two consecutive vowels, then it's kinda weird and it needs to be replaced. So the w... | {"inputs": ["1\na\n", "1\nb\n", "1\ne\n", "1\ne\n", "1\na\n", "1\nb\n", "1\nf\n", "1\n`\n"], "outputs": ["a\n", "b\n", "e\n", "e\n", "a\n", "b\n", "f\n", "`\n"]} | 316 | 86 |
coding | Solve the programming task below in a Python markdown code block.
A long time ago in some far country lived king Copa. After the recent king's reform, he got so large powers that started to keep the books by himself.
The total income A of his kingdom during 0-th year is known, as well as the total income B during n-th... | {"inputs": ["1 1 4\n", "0 3 6\n", "3 0 4\n", "1 1 5\n", "0 1 2\n", "0 1 4\n", "3 0 6\n", "1 1 9\n"], "outputs": ["-1\n", "No solution\n", "0\n", "1\n", "No solution\n", "No solution\n", "0\n", "1\n"]} | 329 | 106 |
coding | Solve the programming task below in a Python markdown code block.
A wise man told Kerem "Different is good" once, so Kerem wants all things in his life to be different.
Kerem recently got a string s consisting of lowercase English letters. Since Kerem likes it when things are different, he wants all substrings of his... | {"inputs": ["1\nq\n", "1\na\n", "1\na\n", "1\nq\n", "1\nb\n", "1\np\n", "1\no\n", "1\nn\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]} | 375 | 86 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given n balloons, indexed from 0 to n - 1. Each balloon is painted with a number on it represented by an array nums. You are asked to burst all the balloons.
If you burst the ith balloon, you will get nums[i -... | {"functional": "def check(candidate):\n assert candidate(nums = [3,1,5,8]) == 167\n assert candidate(nums = [1,5]) == 10\n\n\ncheck(Solution().maxCoins)"} | 165 | 54 |
coding | Solve the programming task below in a Python markdown code block.
Write a program which identifies the number of combinations of three integers which satisfy the following conditions:
* You should select three distinct integers from 1 to n.
* A total sum of the three integers is x.
For example, there are two combin... | {"inputs": ["5 7\n0 0", "2 7\n0 0", "7 9\n0 0", "5 6\n0 0", "7 6\n0 0", "2 2\n0 0", "7 2\n0 0", "6 9\n0 0"], "outputs": ["1\n", "0\n", "3\n", "1\n", "1\n", "0\n", "0\n", "3\n"]} | 205 | 110 |
coding | Solve the programming task below in a Python markdown code block.
Read problems statements in Mandarin Chinese and Russian as well.
Let's consider a set of points S. Initially, S is an empty set. Your task is to implement a data structure that can process the following queries efficiently:
"+ X Y" - add a new po... | {"inputs": ["10\n+ 8 1\n- 1\n+ 3 9\n? 8 4\n? 8 8\n? 12 0\n+ 6 5\n? 7 8\n? 4 5\n- 9"], "outputs": ["10\n8\n2\n4\n11"]} | 676 | 80 |
coding | Solve the programming task below in a Python markdown code block.
Given a positive integer n, find k integers (not necessary distinct) such that all these integers are strictly greater than 1, and their product is equal to n.
Input
The first line contains two integers n and k (2 ≤ n ≤ 100000, 1 ≤ k ≤ 20).
Output
If... | {"inputs": ["4 5\n", "9 6\n", "5 6\n", "5 4\n", "8 2\n", "6 2\n", "2 5\n", "5 3\n"], "outputs": ["-1\n", "-1\n", "-1\n", "-1\n", "2 4\n", "2 3\n", "-1\n", "-1\n"]} | 192 | 91 |
coding | Solve the programming task below in a Python markdown code block.
Polycarp is going to participate in the contest. It starts at $h_1:m_1$ and ends at $h_2:m_2$. It is guaranteed that the contest lasts an even number of minutes (i.e. $m_1 \% 2 = m_2 \% 2$, where $x \% y$ is $x$ modulo $y$). It is also guaranteed that th... | {"inputs": ["10:00\n11:00\n", "11:10\n11:12\n", "01:02\n03:02\n", "00:00\n23:58\n", "00:01\n23:59\n", "00:00\n00:02\n", "23:57\n23:59\n", "11:40\n12:22\n"], "outputs": ["10:30\n", "11:11\n", "02:02\n", "11:59\n", "12:00\n", "00:01\n", "23:58\n", "12:01\n"]} | 521 | 182 |
coding | Solve the programming task below in a Python markdown code block.
A string is made of only lowercase latin letters (a,b,c,d,.....,z). Can you find the length of the lexicographically smallest string such that it has exactly ${K}$ sub-strings, each of which are palindromes?
Input Format
The first line of input contai... | {"inputs": ["2\n10\n17\n"], "outputs": ["4\n7\n"]} | 242 | 22 |
coding | Solve the programming task below in a Python markdown code block.
A palindrome is a string that reads the same backward as forward. For example, the strings ${z}$, ${aaa}$, ${aba}$, and ${abccba}$ are palindromes, but ${codeforces}$ and ${ab}$ are not.
The double of a string $s$ is obtained by writing each character t... | {"inputs": ["4\na\nsururu\nerrorgorn\nanutforajaroftuna\n"], "outputs": ["aa\nsururuururus\nerrorgornnrogrorre\nanutforajaroftunaanutforajaroftuna\n"]} | 447 | 53 |
coding | Solve the programming task below in a Python markdown code block.
You know combinations: for example,
if you take 5 cards from a 52 cards deck you have 2,598,960 different combinations.
In mathematics the number of x combinations you can take from a set of n elements
is called the binomial coefficient of n and x, or ... | {"functional": "_inputs = [[1, 6], [6, 4], [4, 4], [4, 2], [35, 7], [36, 7], [184756, 20], [184756, 10], [3268760, 25], [155117520, 30], [155117530, 30]]\n_outputs = [[0], [2], [1], [-1], [3], [-1], [10], [-1], [10], [15], [-1]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, f... | 658 | 289 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given a string s, reverse the string according to the following rules:
All the characters that are not English letters remain in the same position.
All the English letters (lowercase or uppercase) should be reversed.... | {"functional": "def check(candidate):\n assert candidate(s = \"ab-cd\") == \"dc-ba\"\n assert candidate(s = \"a-bC-dEf-ghIj\") == \"j-Ih-gfE-dCba\"\n assert candidate(s = \"Test1ng-Leet=code-Q!\") == \"Qedo1ct-eeLg=ntse-T!\"\n\n\ncheck(Solution().reverseOnlyLetters)"} | 96 | 99 |
coding | Solve the programming task below in a Python markdown code block.
Twin adventurers Rin and Len are searching for treasure in the Mirror Cave. The cave has two pairs of rooms, the Hall of Mirrors, and an expensive treasure lies behind the door of the room.
For convenience, each of the two rooms is considered to have W ... | {"inputs": ["5 5\n%#... ...#%\n.#.#. .#.#.\n.#.#. .#.#.\n.#.#. .#.#.\n...#L R#...\n3 2\n.L. .R#\n%.. .&.\n4 1\nL.%. %..R\n0 0", "5 5\n%#... .%.#.\n.#.#. .#.#.\n.#.#. .#.#.\n.#.#. .#.#.\n...#L R#...\n3 2\n.L. .R#\n%.. .&.\n4 1\nL.%. %..R\n0 0", "5 5\n%#... ...#%\n.#.#. .#.#.\n.#.#. .#.#.\n.#.#. .#.#.\n...#L R#...\n3 2\n... | 729 | 659 |
coding | Solve the programming task below in a Python markdown code block.
Constanze is the smartest girl in her village but she has bad eyesight.
One day, she was able to invent an incredible machine! When you pronounce letters, the machine will inscribe them onto a piece of paper. For example, if you pronounce 'c', 'o', 'd',... | {"inputs": ["a\n", "a\n", "w\n", "`\n", "x\n", "b\n", "y\n", "c\n"], "outputs": ["1\n", "1\n", "0\n", "1\n", "1\n", "1\n", "1\n", "1\n"]} | 639 | 70 |
coding | Solve the programming task below in a Python markdown code block.
Bob has ladder. He wants to climb this ladder, but being a precocious child, he wonders about exactly how many ways he could to climb this `n` size ladder using jumps of up to distance `k`.
Consider this example...
n = 5\
k = 3
Here, Bob has ladder of... | {"functional": "_inputs = [[1, 3], [3, 3], [2, 3], [5, 3], [4, 3], [10, 6], [14, 7]]\n_outputs = [[1], [4], [2], [13], [7], [492], [7936]]\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, ... | 287 | 220 |
coding | Solve the programming task below in a Python markdown code block.
Create a function that accepts 3 inputs, a string, a starting location, and a length. The function needs to simulate the string endlessly repeating in both directions and return a substring beginning at the starting location and continues for length.
E... | {"functional": "_inputs = [['xyz', -23, 6], ['xyz', 0, 4], ['xyz', 19, 2], ['xyz', -4, -4], ['abcdefghijklmnopqrstuvwxyz', 29, 1], ['Hello! How are you?', -14, 27], ['1x2x3x4x', 1532, 100], ['1x2x3x4x', -1532, -100], ['112233', 0, 0], ['112233', -1, 0], ['112233', 15824, 0]]\n_outputs = [['yzxyzx'], ['xyzx'], ['yz'], [... | 329 | 540 |
coding | Solve the programming task below in a Python markdown code block.
There are 32 letters in the Polish alphabet: 9 vowels and 23 consonants.
Your task is to change the letters with diacritics:
```
ą -> a,
ć -> c,
ę -> e,
ł -> l,
ń -> n,
ó -> o,
ś -> s,
ź -> z,
ż -> z
```
and print out the string without the use of th... | {"functional": "_inputs = [['J\u0119drzej B\u0142\u0105dzi\u0144ski'], ['Lech Wa\u0142\u0119sa'], ['Maria Sk\u0142odowska-Curie'], ['W\u0142adys\u0142aw Reymont'], ['Miko\u0142aj Kopernik'], ['J\u00f3zef Pi\u0142sudski'], ['Czes\u0142aw Mi\u0142osz'], ['Agnieszka Radwa\u0144ska'], ['Wojciech Szcz\u0119sny'], ['Za\u017c... | 154 | 539 |
coding | Solve the programming task below in a Python markdown code block.
You're laying out a rad pixel art mural to paint on your living room wall in homage to [Paul Robertson](http://68.media.tumblr.com/0f55f7f3789a354cfcda7c2a64f501d1/tumblr_o7eq3biK9s1qhccbco1_500.png), your favorite pixel artist.
You want your work to be... | {"functional": "_inputs = [[4050, 27], [4066, 27], [10000, 20], [10005, 20]]\n_outputs = [[True], [False], [True], [False]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):... | 524 | 203 |
coding | Solve the programming task below in a Python markdown code block.
A prime number is an integer greater than $1$ that has no positive divisors other than $1$ and itself.
We call a number megaprime if it is prime and all of its individual digits are prime. For example, $53$ is megaprime because it is prime and all its d... | {"inputs": ["1 100\n"], "outputs": ["8\n"]} | 352 | 18 |
coding | Solve the programming task below in a Python markdown code block.
Julius Caesar protected his confidential information by encrypting it using a cipher. Caesar's cipher shifts each letter by a number of letters. If the shift takes you past the end of the alphabet, just rotate back to the front of the alphabet. In the ... | {"inputs": ["11\nmiddle-Outz\n2\n"], "outputs": ["okffng-Qwvb\n"]} | 464 | 26 |
coding | Solve the programming task below in a Python markdown code block.
You are given two strings A and B representing essays of two students who are suspected cheaters. For any two strings C, D we define their similarity score S(C,D) as 4⋅ LCS(C,D) - |C| - |D|, where LCS(C,D) denotes the length of the Longest Common Subsequ... | {"inputs": ["1 1\na\nb\n", "4 5\nabca\nbaaab\n", "4 5\nabca\nbabab\n", "4 5\nabca\naabab\n", "4 5\nabba\nbabab\n", "6 6\nooojjj\nooookj\n", "7 7\nuiibwws\nqhtkxcn\n", "6 9\nvvvkvv\nvgkkvvvgg\n"], "outputs": ["0\n", "4\n", "5\n", "5\n", "5\n", "7\n", "0\n", "6\n"]} | 538 | 143 |
coding | Solve the programming task below in a Python markdown code block.
Create a function that takes a number as an argument and returns a grade based on that number.
Score | Grade
-----------------------------------------|-----
Anything greater than 1 or less than 0.6 | "F"
0.9 or greater... | {"functional": "_inputs = [[1], [1.01], [0.2], [0.7], [0.8], [0.9], [0.6], [0.5], [0]]\n_outputs = [['A'], ['F'], ['F'], ['C'], ['B'], ['A'], ['D'], ['F'], ['F']]\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... | 195 | 217 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an array nums of integers, return the length of the longest arithmetic subsequence in nums.
Note that:
A subsequence is an array that can be derived from another array by deleting some or no elements without ch... | {"functional": "def check(candidate):\n assert candidate(nums = [3,6,9,12]) == 4\n assert candidate(nums = [9,4,7,2,10]) == 3\n assert candidate(nums = [20,1,15,3,10,5,8]) == 4\n\n\ncheck(Solution().longestArithSeqLength)"} | 135 | 90 |
coding | Solve the programming task below in a Python markdown code block.
The positive odd numbers are sorted in ascending order as $1,3,5,7,9,11,13,15,17,19\ldots$, and grouped as $(1),(3,5),(7,9,11),(13,15,17,19),...$ and so on.
Thus, the first group is $\left(1\right)$, the second group is $(3,5)$, the third group is $(7,9... | {"inputs": ["3\n"], "outputs": ["27\n"]} | 342 | 15 |
coding | Solve the programming task below in a Python markdown code block.
The wide mouth frog is particularly interested in the eating habits of other creatures.
He just can't stop asking the creatures he encounters what they like to eat. But then he meet the alligator who just LOVES to eat wide-mouthed frogs!
When he meets ... | {"functional": "_inputs = [['toucan'], ['ant bear'], ['alligator']]\n_outputs = [['wide'], ['wide'], ['small']]\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... | 152 | 171 |
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, return an array of the largest value in each row of the tree (0-indexed).
Please complete the following python code precisely:
```python
# Definition for a binary tree node.
# class ... | {"functional": "def check(candidate):\n assert candidate(root = tree_node([1,3,2,5,3,None,9])) == [1,3,9]\n assert candidate(root = tree_node([1,2,3])) == [1,3]\n\n\ncheck(Solution().largestValues)"} | 127 | 71 |
coding | Solve the programming task below in a Python markdown code block.
The game of billiards involves two players knocking 3 balls around
on a green baize table. Well, there is more to it, but for our
purposes this is sufficient.
The game consists of several rounds and in each round both players
obtain a score, based on how... | {"inputs": ["5\n41 9\n41 115\n43 110\n21 4\n88 1", "5\n41 64\n41 115\n43 110\n21 4\n88 1", "5\n140 82\n89 16\n64 010\n62 58\n2 90", "5\n140 82\n89 15\n90 110\n289 50\n2 90", "5\n140 82\n89 15\n90 110\n289 63\n2 90", "5\n140 82\n89 15\n90 010\n289 63\n2 90", "5\n140 82\n89 16\n64 010\n62 107\n2 90", "5\n140 64\n41 103\n... | 661 | 343 |
coding | Solve the programming task below in a Python markdown code block.
You are given several queries. Each query consists of three integers $p$, $q$ and $b$. You need to answer whether the result of $p/q$ in notation with base $b$ is a finite fraction.
A fraction in notation with base $b$ is finite if it contains finite nu... | {"inputs": ["2\n6 12 10\n4 3 10\n", "2\n8 12 10\n4 3 10\n", "2\n8 12 10\n4 6 10\n", "2\n6 12 10\n4 3 10\n", "2\n14 12 10\n4 6 10\n", "2\n19 12 10\n4 6 10\n", "1\n1 5244319080000 30030\n", "1\n1 5942671135120 30030\n"], "outputs": ["Finite\nInfinite\n", "Infinite\nInfinite\n", "Infinite\nInfinite\n", "Finite\nInfinite\n... | 407 | 229 |
coding | Solve the programming task below in a Python markdown code block.
It is known that fleas in Berland can jump only vertically and horizontally, and the length of the jump is always equal to s centimeters. A flea has found herself at the center of some cell of the checked board of the size n × m centimeters (each cell is... | {"inputs": ["1 2 3\n", "9 8 7\n", "4 5 6\n", "1 1 1\n", "1 1 2\n", "8 5 6\n", "1 8 7\n", "8 1 6\n"], "outputs": ["2", "8", "20", "1", "1", "20\n", "2\n", "4\n"]} | 266 | 99 |
coding | Solve the programming task below in a Python markdown code block.
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for ... | {"inputs": ["1\n0\n", "1\n1\n", "2\n00\n", "2\n10\n", "2\n11\n", "2\n01\n", "3\n101\n", "3\n001\n"], "outputs": ["1\n", "1\n", "2\n", "2\n", "2\n", "2\n", "3\n", "3\n"]} | 506 | 94 |
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. An index i is part of a hill in nums if the closest non-equal neighbors of i are smaller than nums[i]. Similarly, an index i is part of a valley in nums if the closest non... | {"functional": "def check(candidate):\n assert candidate(nums = [2,4,1,1,6,5]) == 3\n assert candidate(nums = [6,6,5,5,4,1]) == 0\n\n\ncheck(Solution().countHillValley)"} | 179 | 66 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an array nums of n integers where nums[i] is in the range [1, n], return an array of all the integers in the range [1, n] that do not appear in nums.
Please complete the following python code precisely:
```pyt... | {"functional": "def check(candidate):\n assert candidate(nums = [4,3,2,7,8,2,3,1]) == [5,6]\n assert candidate(nums = [1,1]) == [2]\n\n\ncheck(Solution().findDisappearedNumbers)"} | 93 | 65 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
There is an integer array nums sorted in ascending order (with distinct values).
Prior to being passed to your function, nums is possibly rotated at an unknown pivot index k (1 <= k < nums.length) such that the result... | {"functional": "def check(candidate):\n assert candidate(nums = [4,5,6,7,0,1,2], target = 0) == 4\n assert candidate(nums = [4,5,6,7,0,1,2], target = 3) == -1\n assert candidate(nums = [1], target = 0) == -1\n\n\ncheck(Solution().search)"} | 222 | 93 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.