task_type stringclasses 1
value | problem stringlengths 209 3.39k | answer stringlengths 35 6.15k | problem_tokens int64 60 774 | answer_tokens int64 12 2.04k |
|---|---|---|---|---|
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a string text. You should split it to k substrings (subtext1, subtext2, ..., subtextk) such that:
subtexti is a non-empty string.
The concatenation of all the substrings is equal to text (i.e., subtext1... | {"functional": "def check(candidate):\n assert candidate(text = \"ghiabcdefhelloadamhelloabcdefghi\") == 7\n assert candidate(text = \"merchant\") == 1\n assert candidate(text = \"antaprezatepzapreanta\") == 11\n\n\ncheck(Solution().longestDecomposition)"} | 159 | 73 |
coding | Solve the programming task below in a Python markdown code block.
Take an integer `n (n >= 0)` and a digit `d (0 <= d <= 9)` as an integer. Square all numbers `k (0 <= k <= n)` between 0 and n. Count the numbers of
digits `d` used in the writing of all the `k**2`. Call `nb_dig` (or nbDig or ...) the function taking `n... | {"functional": "_inputs = [[5750, 0], [11011, 2], [12224, 8], [11549, 1], [14550, 7], [8304, 7], [10576, 9], [12526, 1], [7856, 4], [14956, 1]]\n_outputs = [[4700], [9481], [7733], [11905], [8014], [3927], [7860], [13558], [7132], [17267]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isin... | 365 | 309 |
coding | Solve the programming task below in a Python markdown code block.
## Task
Given a positive integer as input, return the output as a string in the following format:
Each element, corresponding to a digit of the number, multiplied by a power of 10 in such a way that with the sum of these elements you can obtain the or... | {"functional": "_inputs = [[8964631], [56], [999], [11], [991], [47], [234], [196587], [660], [600], [9090], [10104], [80008], [90000], [0]]\n_outputs = [['8*1000000+9*100000+6*10000+4*1000+6*100+3*10+1'], ['5*10+6'], ['9*100+9*10+9'], ['1*10+1'], ['9*100+9*10+1'], ['4*10+7'], ['2*100+3*10+4'], ['1*100000+9*10000+6*100... | 178 | 455 |
coding | Solve the programming task below in a Python markdown code block.
Galileo's latest project involves determining the density of stars in certain regions of the sky. For this purpose he started looking for datasets online, and discovered a dataset on Newton's blog. Newton had decomposed the night sky into a Voronoi tesse... | {"inputs": ["3 3\n10 10 10\n10 10 10\n10 10 10\n4\n1 1 1 1\n1 1 3 3\n2 1 3 3\n3 1 3 3"], "outputs": ["10\n90\n60\n30"]} | 370 | 85 |
coding | Solve the programming task below in a Python markdown code block.
We want to find the numbers higher or equal than 1000 that the sum of every four consecutives digits cannot be higher than a certain given value.
If the number is ``` num = d1d2d3d4d5d6 ```, and the maximum sum of 4 contiguous digits is ```maxSum```, the... | {"functional": "_inputs = [[2000, 3], [2000, 4], [2000, 7], [3000, 7], [4000, 4], [5000, 2], [5000, 3], [5000, 4], [5000, 5], [5000, 6], [5000, 7], [5000, 8], [5000, 9]]\n_outputs = [[[11, 1110, 12555]], [[21, 1120, 23665]], [[85, 1200, 99986]], [[141, 1600, 220756]], [[35, 2000, 58331]], [[5, 1100, 6111]], [[15, 1200,... | 754 | 496 |
coding | Solve the programming task below in a Python markdown code block.
Polycarp is a great fan of television.
He wrote down all the TV programs he is interested in for today. His list contains n shows, i-th of them starts at moment l_{i} and ends at moment r_{i}.
Polycarp owns two TVs. He can watch two different shows sim... | {"inputs": ["2\n0 1\n0 1\n", "2\n0 4\n0 4\n", "2\n0 2\n0 6\n", "2\n2 5\n0 5\n", "2\n0 2\n0 6\n", "2\n0 1\n0 1\n", "2\n0 4\n0 4\n", "2\n2 5\n0 5\n"], "outputs": ["YES\n", "YES\n", "YES\n", "YES\n", "YES\n", "YES\n", "YES\n", "YES"]} | 298 | 133 |
coding | Solve the programming task below in a Python markdown code block.
Peter loves any kinds of cheating. A week before ICPC, he broke into Doctor's PC and sneaked a look at all the problems that would be given in ICPC. He solved the problems, printed programs out, and brought into ICPC. Since electronic preparation is stri... | {"inputs": ["3\n19 22 1\n7\n93 26 38 43 66 4 3", "3\n19 22 1\n7\n93 26 38 43 36 4 3", "3\n19 22 0\n7\n93 26 38 3 66 80 1", "3\n19 22 0\n7\n93 26 38 43 36 4 3", "3\n19 22 1\n7\n93 26 38 3 66 80 1", "3\n19 20 2\n7\n56 26 2 43 31 12 7", "3\n19 22 0\n7\n93 26 38 43 36 4 2", "3\n19 44 1\n7\n93 26 38 3 66 80 1"], "outputs": ... | 553 | 334 |
coding | Solve the programming task below in a Python markdown code block.
The number "zero" is called "love" (or "l'oeuf" to be precise, literally means "egg" in French), for example when denoting the zero score in a game of tennis.
Aki is fond of numbers, especially those with trailing zeros. For example, the number $9200$ ... | {"inputs": ["6 9\n", "5 2\n", "1 2\n", "2 2\n", "2 2\n", "1 2\n", "9 9\n", "9 2\n"], "outputs": ["1\n", "3\n", "0\n", "1\n", "1\n", "0\n", "2\n", "7\n"]} | 593 | 86 |
coding | Solve the programming task below in a Python markdown code block.
Valera the horse lives on a plane. The Cartesian coordinate system is defined on this plane. Also an infinite spiral is painted on the plane. The spiral consists of segments: [(0, 0), (1, 0)], [(1, 0), (1, 1)], [(1, 1), ( - 1, 1)], [( - 1, 1), ( - 1, - ... | {"inputs": ["0 0\n", "1 0\n", "0 1\n", "0 6\n", "1 1\n", "0 6\n", "1 1\n", "2 1\n"], "outputs": ["0\n", "0\n", "2\n", "22\n", "1\n", "22\n", "1\n", "5\n"]} | 318 | 88 |
coding | Solve the programming task below in a Python markdown code block.
Chef has $N$ points (numbered $1$ through $N$) in a 2D Cartesian coordinate system. For each valid $i$, the $i$-th point is $(x_i, y_i)$. He also has a fixed integer $c$ and he may perform operations of the following type: choose a point $(x_i, y_i)$ and... | {"inputs": ["1\n3 1\n1 1\n1 0\n3 2"], "outputs": ["2 2"]} | 589 | 30 |
coding | Solve the programming task below in a Python markdown code block.
After you had helped George and Alex to move in the dorm, they went to help their friend Fedor play a new computer game Β«Call of Soldiers 3Β».
The game has (m + 1) players and n types of soldiers in total. Players Β«Call of Soldiers 3Β» are numbered form 1... | {"inputs": ["1 1 1\n1\n1\n", "1 1 1\n1\n1\n", "1 1 2\n1\n1\n", "4 2 2\n5\n6\n7\n", "2 2 1\n2\n1\n1\n", "2 2 1\n2\n1\n1\n", "4 2 2\n5\n6\n7\n", "4 2 3\n5\n6\n7\n"], "outputs": ["1\n", "1\n", "1\n", "2\n", "1\n", "1\n", "2\n", "2\n"]} | 390 | 144 |
coding | Solve the programming task below in a Python markdown code block.
Let's denote the $f(x)$ function for a string $x$ as the number of distinct characters that the string contains. For example $f({abc}) = 3$, $f({bbbbb}) = 1$, and $f({babacaba}) = 3$.
Given a string $s$, split it into two non-empty strings $a$ and $b$ s... | {"inputs": ["5\n2\naa\n7\nabcabcd\n5\naaaaa\n10\npaiumoment\n4\naazz\n"], "outputs": ["2\n7\n2\n10\n3\n"]} | 505 | 49 |
coding | Solve the programming task below in a Python markdown code block.
# Task
Consider a string of lowercase Latin letters and space characters (" ").
First, rearrange the letters in each word `alphabetically`.
And then rearrange the words in ascending order of the sum of their characters' `ASCII` values.
If tw... | {"functional": "_inputs = [['batman is bruce wayne'], ['peter parker is spiderman'], ['codewars is great'], ['airplanes in the night sky']]\n_outputs = [['is bceru aenwy aabmnt'], ['is eeprt aekprr adeimnprs'], ['is aegrt acdeorsw'], ['in eht ksy ghint aaeilnprs']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if is... | 363 | 231 |
coding | Solve the programming task below in a Python markdown code block.
Read problems statements in [Mandarin Chinese], [Russian], [Vietnamese] and [Bengali] as well.
Given an array A of N non-negative integers, you can choose any non-negative integer X and replace every element A_{i} with (A_{i}\oplus X) Here, \oplus deno... | {"inputs": ["1\n2\n4 6"], "outputs": ["6 2"]} | 409 | 20 |
coding | Solve the programming task below in a Python markdown code block.
You are given an array of integers $a_1,a_2,\ldots,a_n$. Find the maximum possible value of $a_ia_ja_ka_la_t$ among all five indices $(i, j, k, l, t)$ ($i<j<k<l<t$).
-----Input-----
The input consists of multiple test cases. The first line contains an... | {"inputs": ["1\n5\n-3000 -777 -3000 810 831\n", "1\n5\n-3000 -777 -3123 810 831\n", "1\n5\n-3000 -777 -1726 810 831\n", "1\n5\n-3000 -777 -3123 810 176\n", "1\n5\n-3000 -777 -3000 810 3000\n", "1\n5\n-3000 -777 -3000 2024 3000\n", "1\n5\n-3000 -1535 -3000 3000 349\n", "1\n5\n-3000 -216 -3000 2024 3000\n"], "outputs": [... | 563 | 402 |
coding | Solve the programming task below in a Python markdown code block.
Write a program which reads a $n \times m$ matrix $A$ and a $m \times l$ matrix $B$, and prints their product, a $n \times l$ matrix $C$. An element of matrix $C$ is obtained by the following formula:
\\[ c_{ij} = \sum_{k=1}^m a_{ik}b_{kj} \\]
where $a... | {"inputs": ["3 2 3\n1 2\n0 3\n4 5\n1 2 1\n1 3 2", "3 2 3\n1 2\n1 3\n4 5\n1 2 1\n1 3 2", "3 2 3\n1 2\n2 3\n4 5\n1 2 1\n1 3 2", "3 2 3\n1 2\n2 3\n4 5\n1 2 2\n1 3 2", "3 2 3\n1 2\n3 3\n4 5\n1 2 2\n1 3 2", "3 2 3\n1 1\n3 3\n4 5\n1 2 2\n1 3 2", "3 2 3\n1 1\n3 3\n4 9\n1 2 2\n1 3 2", "3 2 3\n1 1\n3 2\n4 9\n1 2 2\n1 3 2"], "ou... | 324 | 444 |
coding | Solve the programming task below in a Python markdown code block.
Archith was a making noise in digital logic class.Sir was very frustrated by the behaviour of Archith. Sir asked archith to meet him in staff room. As archith reached staff room sir gave a smile and asked to complete this assignment in one day if not he ... | {"inputs": ["20\n212245523\n546843625\n456431356\n546463364\n584651321\n352145896\n53\n2\n32\n32\n32692\n32646\n41354\n4351\n312\n524\n54365\n58421\n54213\n23452"], "outputs": ["odd\nodd\nodd\nodd\nodd\neven\neven\nodd\nodd\nodd\nodd\neven\neven\nodd\neven\nodd\nodd\neven\nodd\nodd"]} | 213 | 183 |
coding | Solve the programming task below in a Python markdown code block.
You are given an array a consisting of n integers.
Let min(l, r) be the minimum value among a_l, a_{l + 1}, β¦, a_r and max(l, r) be the maximum value among a_l, a_{l + 1}, β¦, a_r.
Your task is to choose three positive (greater than 0) integers x, y and... | {"inputs": ["3\n3\n1 1 1\n3\n1 1 1\n3\n1 1 1\n", "3\n3\n2 1 1\n3\n1 1 1\n3\n1 1 1\n", "3\n3\n2 1 1\n3\n1 2 1\n3\n1 1 1\n", "3\n3\n1 1 1\n3\n1 1 2\n3\n1 1 1\n", "3\n3\n2 1 2\n3\n2 1 1\n3\n1 2 1\n", "3\n3\n1 1 1\n3\n1 1 2\n3\n2 1 1\n", "3\n3\n2 1 1\n3\n2 2 2\n3\n1 2 1\n", "3\n3\n1 1 1\n3\n1 1 1\n3\n1 1 2\n"], "outputs": ... | 602 | 366 |
coding | Solve the programming task below in a Python markdown code block.
Salmon has some hidden numbers that he wants you to find!
Given an integer $N$, find and output any two integers A and B such that:
* $1 β€ A, B β€ 10^{9}$, and
* $A*B = N$.
------ Input: ------
The first line of input consists of a single integer $T$ ($... | {"inputs": ["5\n1\n3\n5\n8\n10"], "outputs": ["1 1\n1 3\n1 5\n1 8\n2 5\n"]} | 228 | 42 |
coding | Solve the programming task below in a Python markdown code block.
You are given a rectangular grid with $n$ rows and $m$ columns. The cell located on the $i$-th row from the top and the $j$-th column from the left has a value $a_{ij}$ written in it.
You can perform the following operation any number of times (possibly... | {"inputs": ["1\n3 3\n-3 -2 -1\n0 -2 0\n-3 -2 -1\n", "1\n3 3\n0 -1 -2\n-8 -4 -3\n-3 0 -1\n", "1\n3 3\n0 -1 -4\n-8 -4 -3\n-3 0 -1\n", "1\n3 3\n0 -1 -4\n-8 -4 -3\n-1 0 -1\n", "1\n3 3\n-3 -2 -2\n0 -2 -1\n-3 -2 -1\n", "1\n3 3\n-1 -2 -2\n0 -2 -1\n-3 -2 -1\n", "1\n3 3\n-4 -4 -1\n-3 -4 -2\n-3 -2 0\n", "1\n3 3\n-6 -4 -1\n-3 -4 ... | 468 | 272 |
coding | Solve the programming task below in a Python markdown code block.
You are given a permutation $p$ of $n$ integers $1$, $2$, ..., $n$ (a permutation is an array where each element from $1$ to $n$ occurs exactly once).
Let's call some subsegment $p[l, r]$ of this permutation special if $p_l + p_r = \max \limits_{i = l}^... | {"inputs": ["3\n1 3 2\n", "3\n2 3 1\n", "3\n3 2 1\n", "3\n2 1 3\n", "3\n1 2 3\n", "3\n3 1 2\n", "3\n1 3 2\n", "5\n3 4 1 5 2\n"], "outputs": ["1\n", "1\n", "0\n", "0\n", "0\n", "0\n", "1", "2\n"]} | 271 | 121 |
coding | Solve the programming task below in a Python markdown code block.
Read problem statements in [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
Only $x$ hours are left for the March Long Challenge and Chef is only left with the last problem unsolved. However, he is sure that he cannot solve the proble... | {"inputs": ["2 5 3\n1 2", "2 6 3\n1 2"], "outputs": ["YES", "NO"]} | 602 | 34 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an m x n binary matrix mat, return the number of special positions in mat.
A position (i, j) is called special if mat[i][j] == 1 and all other elements in row i and column j are 0 (rows and columns are 0-indexed... | {"functional": "def check(candidate):\n assert candidate(mat = [[1,0,0],[0,0,1],[1,0,0]]) == 1\n assert candidate(mat = [[1,0,0],[0,1,0],[0,0,1]]) == 3\n\n\ncheck(Solution().numSpecial)"} | 109 | 75 |
coding | Solve the programming task below in a Python markdown code block.
Chef has opened up a new restaurant. Like every other restaurant, critics critique this place. The Chef wants to gather as much positive publicity as he can. Also, he is very aware of the fact that people generally do not tend to go through all the revie... | {"inputs": ["10\n1 1\n1 7\n2\n1 9\n1 21\n1 8\n1 5\n2\n1 9\n2"], "outputs": ["No reviews yet\n9\n9"]} | 759 | 54 |
coding | Solve the programming task below in a Python markdown code block.
-----Problem Statement-----
We have an integer sequence $A$, whose length is $N$.
Find the number of the non-empty contiguous subsequences of $A$ whose sum is $0$. Note that we are counting the ways to take out subsequences. That is, even if the contents... | {"inputs": ["6\n1 3 -4 2 2 -2"], "outputs": ["3"]} | 269 | 24 |
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": ["9\n", "7\n", "1\n", "5\n", "6\n", "2\n", "8\n", "3\n"], "outputs": ["504\n", "210\n", "1\n", "60\n", "60\n", "2\n", "280\n", "6\n"]} | 274 | 78 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an array of integers arr, return true if we can partition the array into three non-empty parts with equal sums.
Formally, we can partition the array if we can find indexes i + 1 < j with (arr[0] + arr[1] + ... +... | {"functional": "def check(candidate):\n assert candidate(arr = [0,2,1,-6,6,-7,9,1,2,0,1]) == True\n assert candidate(arr = [0,2,1,-6,6,7,9,-1,2,0,1]) == False\n assert candidate(arr = [3,3,6,5,-2,2,5,1,-9,4]) == True\n\n\ncheck(Solution().canThreePartsEqualSum)"} | 155 | 113 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a positive integer array nums.
Partition nums into two arrays,Β nums1 and nums2, such that:
Each element of the array nums belongs to either the array nums1 or the array nums2.
Both arrays are non-empty.... | {"functional": "def check(candidate):\n assert candidate(nums = [1,3,2,4]) == 1\n assert candidate(nums = [100,1,10]) == 9\n\n\ncheck(Solution().findValueOfPartition)"} | 167 | 58 |
coding | Solve the programming task below in a Python markdown code block.
Write a program which reads relations in a SNS (Social Network Service), and judges that given pairs of users are reachable each other through the network.
Constraints
* $2 \leq n \leq 100,000$
* $0 \leq m \leq 100,000$
* $1 \leq q \leq 10,000$
Input
... | {"inputs": ["10 9\n0 1\n0 2\n3 4\n5 7\n5 6\n3 7\n6 8\n7 8\n8 9\n3\n0 1\n5 9\n1 3", "10 9\n0 1\n0 2\n3 4\n5 7\n5 6\n3 7\n0 8\n7 8\n8 9\n3\n0 1\n5 9\n1 3", "10 9\n0 1\n0 2\n3 4\n5 7\n5 6\n3 7\n0 8\n7 8\n8 5\n3\n0 1\n5 9\n1 3", "16 9\n0 1\n0 2\n3 4\n5 7\n5 6\n3 7\n6 8\n7 8\n8 9\n3\n0 1\n5 9\n1 3", "10 9\n0 1\n0 2\n5 4\n5 ... | 358 | 518 |
coding | Solve the programming task below in a Python markdown code block.
Vasya thinks that lucky tickets are the tickets whose numbers are divisible by 3. He gathered quite a large collection of such tickets but one day his younger brother Leonid was having a sulk and decided to destroy the collection. First he tore every tic... | {"inputs": ["1\n1731005\n", "1\n2340786\n", "1\n4533183\n", "1\n3050700\n", "1\n1474114\n", "1\n1456697\n", "1\n19938466\n", "1\n26757320\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]} | 458 | 136 |
coding | Solve the programming task below in a Python markdown code block.
A particular month has 30 days, numbered from 1 to 30.
Day 1 is a Monday, and the usual 7-day week is followed (so day 2 is Tuesday, day 3 is Wednesday, and so on).
Every Saturday and Sunday is a holiday. There are N festival days, which are also holid... | {"inputs": ["3\n2\n5 7\n3\n23 1 6\n1\n13\n"], "outputs": ["9\n10\n8\n"]} | 668 | 39 |
coding | Solve the programming task below in a Python markdown code block.
Paul is at the orchestra. The string section is arranged in an r Γ c rectangular grid and is filled with violinists with the exception of n violists. Paul really likes violas, so he would like to take a picture including at least k of them. Paul can take... | {"inputs": ["2 2 1 1\n1 2\n", "1 1 1 1\n1 1\n", "1 1 1 1\n1 1\n", "2 2 1 1\n1 2\n", "5 9 2 2\n4 6\n1 5\n", "2 6 2 2\n1 2\n1 5\n", "2 6 2 2\n1 2\n1 5\n", "5 9 2 2\n4 6\n1 5\n"], "outputs": ["4\n", "1\n", "1\n", "4\n", "40\n", "8\n", "8\n", "40\n"]} | 464 | 168 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an n x n array of integers matrix, return the minimum sum of any falling path through matrix.
A falling path starts at any element in the first row and chooses the element in the next row that is either directly... | {"functional": "def check(candidate):\n assert candidate(matrix = [[2,1,3],[6,5,4],[7,8,9]]) == 13\n assert candidate(matrix = [[-19,57],[-40,-5]]) == -59\n\n\ncheck(Solution().minFallingPathSum)"} | 148 | 74 |
coding | Solve the programming task below in a Python markdown code block.
Yaroslav likes algorithms. We'll describe one of his favorite algorithms.
1. The algorithm receives a string as the input. We denote this input string as a.
2. The algorithm consists of some number of command. Π‘ommand number i looks either as si >>... | {"inputs": ["2\n8\n52\n", "2\n10\n79\n", "2\n10\n71\n", "2\n18\n79\n", "2\n15\n71\n", "2\n27\n79\n", "2\n15\n52\n", "2\n10\n79\n"], "outputs": ["0??<>1\n1??<>2\n2??<>3\n3??<>4\n4??<>5\n5??<>6\n6??<>7\n7??<>8\n8??<>9\n9??>>??0\n??<>1\n?0>>0?\n?1>>1?\n?2>>2?\n?3>>3?\n?4>>4?\n?5>>5?\n?6>>6?\n?7>>7?\n?8>>8?\n?9>>9?\n?>>??\... | 521 | 1,074 |
coding | Solve the programming task below in a Python markdown code block.
A word from the English dictionary is taken and arranged as a matrix. e.g. "MATHEMATICS"
MATHE
ATHEM
THEMA
HEMAT
EMATI
MATIC
ATICS
There are many ways to trace this matrix in a way that helps you construct this word. You start tracing the... | {"inputs": ["1\n2 3\n"], "outputs": ["3\n"]} | 379 | 18 |
coding | Solve the programming task below in a Python markdown code block.
You have a string $s$ consisting of digits from $0$ to $9$ inclusive. You can perform the following operation any (possibly zero) number of times:
You can choose a position $i$ and delete a digit $d$ on the $i$-th position. Then insert the digit $\min{(... | {"inputs": ["4\n04829\n9\n01\n314752277691991\n"], "outputs": ["02599\n9\n01\n111334567888999\n"]} | 478 | 66 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given the root of a binary search tree and an integer k, return true if there exist two elements in the BST such that their sum is equal to k, or false otherwise.
Β
Please complete the following python code precisely:... | {"functional": "def check(candidate):\n assert candidate(root = tree_node([5,3,6,2,4,None,7]), k = 9) == True\n assert candidate(root = tree_node([5,3,6,2,4,None,7]), k = 28) == False\n\n\ncheck(Solution().findTarget)"} | 140 | 78 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses.
Β
Please complete the following python code precisely:
```python
class Solution:
def generateParenthesis(self... | {"functional": "def check(candidate):\n assert candidate(n = 3) == [\"((()))\",\"(()())\",\"(())()\",\"()(())\",\"()()()\"]\n assert candidate(n = 1) == [\"()\"]\n\n\ncheck(Solution().generateParenthesis)"} | 67 | 65 |
coding | Solve the programming task below in a Python markdown code block.
For an integer n not less than 0, let us define f(n) as follows:
- f(n) = 1 (if n < 2)
- f(n) = n f(n-2) (if n \geq 2)
Given is an integer N. Find the number of trailing zeros in the decimal notation of f(N).
-----Constraints-----
- 0 \leq N \leq 10^... | {"inputs": ["7", "5", "5\n", "0\n", "1\n", "2\n", "10", "24"], "outputs": ["0\n", "0", "0\n", "0\n", "0\n", "0\n", "1\n", "2\n"]} | 191 | 67 |
coding | Solve the programming task below in a Python markdown code block.
Consider the infinite sequence of integers: 1, 1, 2, 1, 2, 3, 1, 2, 3, 4, 1, 2, 3, 4, 5.... The sequence is built in the following way: at first the number 1 is written out, then the numbers from 1 to 2, then the numbers from 1 to 3, then the numbers fro... | {"inputs": ["3\n", "5\n", "1\n", "2\n", "4\n", "6\n", "8\n", "6\n"], "outputs": ["2\n", "2\n", "1\n", "1\n", "1\n", "3\n", "2\n", "3\n"]} | 307 | 70 |
coding | Solve the programming task below in a Python markdown code block.
Let $f(x)$ be the sum of digits of a decimal number $x$.
Find the smallest non-negative integer $x$ such that $f(x) + f(x + 1) + \dots + f(x + k) = n$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 150$) β the number of test c... | {"inputs": ["2\n6 9\n5 0\n", "2\n9 9\n53 9\n", "2\n4 9\n51 5\n", "2\n6 9\n10 0\n", "2\n4 6\n47 7\n", "2\n9 9\n27 9\n", "2\n9 9\n17 4\n", "2\n9 8\n53 9\n"], "outputs": ["-1\n5\n", "-1\n8\n", "-1\n24\n", "-1\n19\n", "-1\n17\n", "-1\n-1\n", "-1\n-1\n", "-1\n8\n"]} | 278 | 163 |
coding | Solve the programming task below in a Python markdown code block.
A number $a_2$ is said to be the arithmetic mean of two numbers $a_1$ and $a_3$, if the following condition holds: $a_1 + a_3 = 2\cdot a_2$.
We define an arithmetic mean deviation of three numbers $a_1$, $a_2$ and $a_3$ as follows: $d(a_1, a_2, a_3) = |... | {"inputs": ["3\n3 4 5\n2 2 6\n1 6 5\n"], "outputs": ["0\n1\n0\n"]} | 746 | 36 |
coding | Solve the programming task below in a Python markdown code block.
There is an easy way to obtain a new task from an old one called "Inverse the problem": we give an output of the original task, and ask to generate an input, such that solution to the original problem will produce the output we provided. The hard task of... | {"inputs": ["1\n0\n", "1\n1\n", "1\n2\n", "1\n4\n", "1\n6\n", "1\n5\n", "1\n7\n", "1\n3\n"], "outputs": ["YES\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n"]} | 458 | 86 |
coding | Solve the programming task below in a Python markdown code block.
The academic year has just begun, but lessons and olympiads have already occupied all the free time. It is not a surprise that today Olga fell asleep on the Literature. She had a dream in which she was on a stairs.
The stairs consists of n steps. The s... | {"inputs": ["1\nD\n", "1\nD\n", "1\nU\n", "1\nD\n", "1\nU\n", "2\nDU\n", "2\nDU\n", "2\nUD\n"], "outputs": ["1 ", "1 ", "1 ", "1\n", "1\n", "1 1 ", "1 1\n", "3 3 "]} | 555 | 88 |
coding | Solve the programming task below in a Python markdown code block.
Read problems statements in Mandarin Chinese and Russian.
Lira loves Linear Algebra and she is especially keen about matrix :).
Today, she learnt some properties about matrices, namely, she learnt about what the trace of a matrix is, as her teacher ga... | {"inputs": ["1\n3"], "outputs": ["2"]} | 374 | 14 |
coding | Solve the programming task below in a Python markdown code block.
Takahashi, who works at DISCO, is standing before an iron bar. The bar has N-1 notches, which divide the bar into N sections. The i-th section from the left has a length of A_i millimeters.
Takahashi wanted to choose a notch and cut the bar at that poin... | {"inputs": ["3\n2 5 3", "3\n2 8 3", "3\n2 8 2", "3\n2 0 4", "3\n1 0 6", "3\n1 0 1", "3\n2 4 3", "12\n001 0 107 5 0 196 001 1 2 101 0 110"], "outputs": ["4\n", "7\n", "8\n", "2\n", "5\n", "0\n", "3", "94\n"]} | 372 | 141 |
coding | Solve the programming task below in a Python markdown code block.
Determine if an N-sided polygon (not necessarily convex) with sides of length L_1, L_2, ..., L_N can be drawn in a two-dimensional plane.
You can use the following theorem:
Theorem: an N-sided polygon satisfying the condition can be drawn if and only if ... | {"inputs": ["4\n3 5 5 1", "4\n3 3 4 1", "4\n3 5 6 1", "4\n4 3 4 1", "4\n3 5 0 1", "4\n4 1 4 1", "4\n3 5 0 0", "4\n2 1 4 1"], "outputs": ["Yes\n", "Yes\n", "Yes\n", "Yes\n", "No\n", "Yes\n", "No\n", "No\n"]} | 235 | 126 |
coding | Solve the programming task below in a Python markdown code block.
HDD hard drives group data by sectors. All files are split to fragments and each of them are written in some sector of hard drive. Note the fragments can be written in sectors in arbitrary order.
One of the problems of HDD hard drives is the following: ... | {"inputs": ["1\n1\n", "1\n1\n", "1\n1\n", "1\n1\n", "3\n3 1 2\n", "3\n3 2 1\n", "3\n2 3 1\n", "3\n1 2 3\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "3\n", "2\n", "3\n", "2\n"]} | 501 | 102 |
coding | Solve the programming task below in a Python markdown code block.
Petya is preparing for IQ test and he has noticed that there many problems like: you are given a sequence, find the next number. Now Petya can solve only problems with arithmetic or geometric progressions.
Arithmetic progression is a sequence a_1, a_1 +... | {"inputs": ["1 1 1 1\n", "9 8 7 5\n", "2 6 6 8\n", "2 4 8 8\n", "2 4 4 2\n", "1 2 4 8\n", "8 4 2 1\n", "2 3 4 6\n"], "outputs": ["1\n", "42\n", "42\n", "42\n", "42\n", "16\n", "42\n", "42\n"]} | 370 | 125 |
coding | Solve the programming task below in a Python markdown code block.
When Serezha was three years old, he was given a set of cards with letters for his birthday. They were arranged into words in the way which formed the boy's mother favorite number in binary notation. Serezha started playing with them immediately and shuf... | {"inputs": ["3\nnoe\n", "3\nnoe\n", "3\none\n", "3\neon\n", "3\nneo\n", "3\neno\n", "3\noen\n", "4\nezor\n"], "outputs": ["1 \n", "1\n", "1 ", "1 ", "1 ", "1 ", "1 ", "0 \n"]} | 312 | 87 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given a string s, return the number of homogenous substrings of s. Since the answer may be too large, return it modulo 109 + 7.
A string is homogenous if all the characters of the string are the same.
A substring is a... | {"functional": "def check(candidate):\n assert candidate(s = \"abbcccaa\") == 13\n assert candidate(s = \"xy\") == 2\n assert candidate(s = \"zzzzz\") == 15\n\n\ncheck(Solution().countHomogenous)"} | 111 | 62 |
coding | Solve the programming task below in a Python markdown code block.
You are given a string $s$. You need to find two non-empty strings $a$ and $b$ such that the following conditions are satisfied:
Strings $a$ and $b$ are both subsequences of $s$.
For each index $i$, character $s_i$ of string $s$ must belong to exactly ... | {"inputs": ["3\nfc\naaaa\nthebrightboiler\n", "5\nkbxiahaosfyclumgnaczggrnljumplxknibxmeedvnefh\ndkqosshpegwunnzsohmxxumnnhckwyczaowpoxezqlovukcuuqgrsbrtifngthlquuqdjvyltgjbrmwoefypvdyzqwlainjoqx\nwktnblvszfndrjodikurlytsayblhpdnrytxnhfejtjfzeeamtt\ngkffwelozvmyosbmoufjpjzbeohbulotcinspqmyurolxwlwloobkszpnddxhrkbxoytmd... | 559 | 361 |
coding | Solve the programming task below in a Python markdown code block.
There's a new security company in Paris, and they decided to give their employees an algorithm to make first name recognition faster. In the blink of an eye, they can now detect if a string is a first name, no matter if it is a one-word name or an hyphen... | {"functional": "_inputs = [['Francis'], ['Jean-Eluard'], ['Le Mec'], ['Bernard-Henry-Levy'], ['Meme Gertrude'], ['A-a-a-a----a-a'], ['Z-------------'], ['Jean-luc'], ['Jean--Luc'], ['JeanLucPicard'], ['-Jean-Luc'], ['Jean-Luc-Picard-']]\n_outputs = [[True], [True], [False], [True], [False], [False], [False], [False], [... | 321 | 258 |
coding | Solve the programming task below in a Python markdown code block.
Jim runs a big burger restaurant and, to entertain his customers, he always tell them jokes. He is running out of jokes and he needs you to help him find new ones.
An often heard programmer joke goes like this:
"Why do programmers always mix up Christm... | {"inputs": ["2\n2 25\n2 25\n", "2\n10 25\n8 31\n", "2\n11 10\n10 11\n"], "outputs": ["0\n", "1\n", "1\n"]} | 703 | 63 |
coding | Solve the programming task below in a Python markdown code block.
You are given an array $a$ of $n$ elements.
Your can perform the following operation no more than $n$ times: Select three indices $x,y,z$ $(1 \leq x < y < z \leq n)$ and replace $a_x$ with $a_y - a_z$. After the operation, $|a_x|$ need to be less than $... | {"inputs": ["3\n5\n5 -4 2 -1 2\n3\n4 3 2\n3\n-3 -2 -1\n"], "outputs": ["3\n1 4 5\n2 4 5\n3 4 5\n-1\n0\n"]} | 590 | 66 |
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.
Read problems statements in Mandarin Chinese and Russian.
Given three positive integers N, L and R, find the number of non-decreasing sequences of size at least 1 and at most N, such that each element of the sequence lies between L and R, both inclusi... | {"inputs": ["2\n1 4 5\n2 4 5", "2\n1 4 5\n2 4 5"], "outputs": ["2\n5", "2\n5"]} | 326 | 46 |
coding | Solve the programming task below in a Python markdown code block.
Simple interest on a loan is calculated by simply taking the initial amount (the principal, p) and multiplying it by a rate of interest (r) and the number of time periods (n).
Compound interest is calculated by adding the interest after each time perio... | {"functional": "_inputs = [[100, 0.1, 1], [100, 0.1, 2], [100, 0.1, 10], [100, 0, 10], [0, 0.1, 10], [100, 0.1, 0]]\n_outputs = [[[110, 110]], [[120, 121]], [[200, 259]], [[100, 100]], [[0, 0]], [[100, 100]]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n retu... | 309 | 281 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an array arr,Β replace every element in that array with the greatest element among the elements to itsΒ right, and replace the last element with -1.
After doing so, return the array.
Β
Please complete the followin... | {"functional": "def check(candidate):\n assert candidate(arr = [17,18,5,4,6,1]) == [18,6,6,6,1,-1]\n assert candidate(arr = [400]) == [-1]\n\n\ncheck(Solution().replaceElements)"} | 90 | 70 |
coding | Solve the programming task below in a Python markdown code block.
Read problems statements in [Hindi], [Mandarin Chinese], [Vietnamese], and [Bengali] as well.
You are given a grid with $N$ rows and $M$ columns, where each cell contains either '0' or '1'.
Find out whether all the cells containing '1'-s form a rectan... | {"inputs": ["3\n3 3\n010\n111\n010\n4 4\n0000\n0110\n1110\n1100\n3 3\n011\n011\n000"], "outputs": ["NO\nNO\nYES"]} | 534 | 72 |
coding | Solve the programming task below in a Python markdown code block.
Variation of this nice kata, the war has expanded and become dirtier and meaner; both even and odd numbers will fight with their pointy `1`s. And negative integers are coming into play as well, with, Γ§a va sans dire, a negative contribution (think of the... | {"functional": "_inputs = [[[1, 5, 12]], [[7, -3, 20]], [[7, -3, -2, 6]], [[-3, -5]], [[]]]\n_outputs = [['odds win'], ['evens win'], ['tie'], ['evens win'], ['tie']]\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... | 240 | 210 |
coding | Solve the programming task below in a Python markdown code block.
Calculate the value of the sum: n mod 1 + n mod 2 + n mod 3 + ... + n mod m. As the result can be very large, you should print the value modulo 10^9 + 7 (the remainder when divided by 10^9 + 7).
The modulo operator a mod b stands for the remainder after... | {"inputs": ["3 4\n", "4 4\n", "1 1\n", "3 3\n", "4 1\n", "3 4\n", "4 4\n", "1 1\n"], "outputs": ["4\n", "1\n", "0\n", "1", "0", "4\n", "1\n", "0\n"]} | 194 | 84 |
coding | Solve the programming task below in a Python markdown code block.
Given a string s, write a method (function) that will return true if its a valid single integer or floating number or false if its not.
Valid examples, should return true:
should return false:
Also feel free to reuse/extend the following starter code:
... | {"functional": "_inputs = [['s2324'], ['-234.4'], ['3 4'], ['3-4'], ['3 4 '], ['34.65'], ['-0'], ['0.0'], [''], [' ']]\n_outputs = [[False], [True], [False], [False], [False], [True], [True], [True], [False], [False]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n ... | 75 | 229 |
coding | Solve the programming task below in a Python markdown code block.
Problem Statement:
You are one of the organizers of Pragyan.Having worked so hard to ensure
success of the event, you are able to spot the word "pragyan" in any text.
You are given a stream of character strings and you need to output them
till you find ... | {"inputs": ["PRAGyAN", "The\nquick\nbrown\nfox\npragyan\njumped\nover\nthe\nlazy\ndog", "The\nquick\nbrown\nfox\njumped\nover\nthe\nlazy\ndog\npragya\npragy\npra\nragyan\noragyan\npragyam\npRaGYAN\nAny\ninput\nbeyond\nthis\nshould\nnot\nbe\nprocessed", "Far\nout\nin\nthe\nuncharted\nbackwaters\nof\nthe\nunfashionable\n... | 217 | 270 |
coding | Solve the programming task below in a Python markdown code block.
Stuart is obsessed to numbers. He like all type of numbers in fact he is having a great collection of numbers in his room. His collection includes N different large numbers. But today he is searching for a number which is having maximum frequency of digi... | {"inputs": ["2\n5\n345 1323 165 98 456\n3\n5\n335 876 98 1323 349\n3"], "outputs": ["1323\n335"]} | 369 | 67 |
coding | Solve the programming task below in a Python markdown code block.
The protection of a popular program developed by one of IT City companies is organized the following way. After installation it outputs a random five digit number which should be sent in SMS to a particular phone number. In response an SMS activation cod... | {"inputs": ["12345\n", "13542\n", "71232\n", "11111\n", "10000\n", "99999\n", "91537\n", "70809\n"], "outputs": ["71232", "84443", "10151", "36551", "00000", "99999", "27651", "00000"]} | 358 | 126 |
coding | Solve the programming task below in a Python markdown code block.
Snuke has a blackboard and a set S consisting of N integers. The i-th element in S is S_i.
He wrote an integer X on the blackboard, then performed the following operation N times:
* Choose one element from S and remove it.
* Let x be the number written... | {"inputs": ["2 17\n3 7", "2 20\n6 3", "2 19\n3 7", "2 19\n3 11", "2 12\n6 11", "5 193\n5 13 7 5 4", "5 82\n22 11 6 7 13", "5 82\n27 11 6 7 13"], "outputs": ["2\n", "4\n", "3", "3\n", "1\n", "198\n", "516\n", "456\n"]} | 373 | 151 |
coding | Solve the programming task below in a Python markdown code block.
Fox Ciel is playing a card game with her friend Fox Jiro. There are n piles of cards on the table. And there is a positive integer on each card.
The players take turns and Ciel takes the first turn. In Ciel's turn she takes a card from the top of any no... | {"inputs": ["1\n1 1\n", "2\n1 110\n2 1 10\n", "2\n1 100\n2 1 10\n", "2\n2 60 2\n3 1 000 4\n", "2\n2 60 2\n3 1 000 5\n", "2\n2 200 1\n3 1 100 2\n", "2\n2 200 2\n3 1 100 2\n", "2\n2 200 2\n3 1 000 2\n"], "outputs": ["1 0\n", "111 10\n", "101 10\n", "61 6\n", "61 7\n", "301 3\n", "301 4\n", "201 4\n"]} | 544 | 218 |
coding | Solve the programming task below in a Python markdown code block.
You are given a string $s$ of even length $n$. String $s$ is binary, in other words, consists only of 0's and 1's.
String $s$ has exactly $\frac{n}{2}$ zeroes and $\frac{n}{2}$ ones ($n$ is even).
In one operation you can reverse any substring of $s$. ... | {"inputs": ["3\n2\n10\n4\n0110\n8\n11101000\n", "3\n2\n10\n4\n0110\n8\n11100001\n", "3\n2\n10\n4\n1010\n8\n11101000\n", "3\n2\n10\n4\n0011\n8\n11101000\n", "3\n2\n10\n4\n0101\n8\n11100001\n", "3\n2\n10\n4\n0101\n8\n11101000\n", "3\n2\n10\n4\n0011\n8\n11100001\n", "3\n2\n10\n4\n1001\n8\n11101000\n"], "outputs": ["0\n1\n... | 507 | 286 |
coding | Solve the programming task below in a Python markdown code block.
Luba has a ticket consisting of 6 digits. In one move she can choose digit in any position and replace it with arbitrary digit. She wants to know the minimum number of digits she needs to replace in order to make the ticket lucky.
The ticket is consider... | {"inputs": ["000000\n", "123456\n", "111000\n", "120111\n", "999999\n", "199880\n", "899889\n", "899888\n"], "outputs": ["0\n", "2\n", "1\n", "0\n", "0\n", "1\n", "1\n", "1\n"]} | 276 | 110 |
coding | Solve the programming task below in a Python markdown code block.
Takahashi's house has only one socket.
Takahashi wants to extend it with some number of power strips, each with A sockets, into B or more empty sockets.
One power strip with A sockets can extend one empty socket into A empty sockets.
Find the minimum num... | {"inputs": ["8 4", "4 9", "2 5", "7 9", "2 9", "4 1", "2 8", "2 7"], "outputs": ["1\n", "3\n", "4\n", "2\n", "8\n", "0\n", "7\n", "6\n"]} | 177 | 78 |
coding | Solve the programming task below in a Python markdown code block.
Chef discovered that his secret recipe has been stolen. He immediately informs the police of the theft.
It is known that the policeman and thief move on the number line. You are given that:
The initial location of the policeman on the number line is X a... | {"inputs": ["3\n1 3\n2 1\n1 1"], "outputs": ["2\n1\n0"]} | 462 | 28 |
coding | Solve the programming task below in a Python markdown code block.
You are playing the following game with Joisino.
- Initially, you have a blank sheet of paper.
- Joisino announces a number. If that number is written on the sheet, erase the number from the sheet; if not, write the number on the sheet. This process is... | {"inputs": ["3\n6\n2\n7", "3\n6\n2\n8", "3\n3\n2\n8", "3\n0\n2\n8", "3\n0\n2\n7", "3\n0\n3\n7", "3\n0\n6\n7", "3\n0\n5\n7"], "outputs": ["3\n", "3\n", "3\n", "3\n", "3\n", "3\n", "3\n", "3\n"]} | 313 | 110 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
There are n gas stations along a circular route, where the amount of gas at the ith station is gas[i].
You have a car with an unlimited gas tank and it costs cost[i] of gas to travel from the ith station to its next (... | {"functional": "def check(candidate):\n assert candidate(gas = [1,2,3,4,5], cost = [3,4,5,1,2]) == 3\n assert candidate(gas = [2,3,4], cost = [3,4,3]) == -1\n\n\ncheck(Solution().canCompleteCircuit)"} | 174 | 81 |
coding | Solve the programming task below in a Python markdown code block.
You are given a huge integer $a$ consisting of $n$ digits ($n$ is between $1$ and $3 \cdot 10^5$, inclusive). It may contain leading zeros.
You can swap two digits on adjacent (neighboring) positions if the swapping digits are of different parity (that ... | {"inputs": ["1\n890\n", "1\n454\n", "1\n638\n", "1\n540\n", "1\n119\n", "1\n176\n", "1\n187\n", "1\n353\n"], "outputs": ["809\n", "445\n", "368\n", "405\n", "119\n", "167\n", "178\n", "353\n"]} | 605 | 118 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given a m x n binary matrix mat. In one step, you can choose one cell and flip it and all the four neighbors of it if they exist (Flip is changing 1 to 0 and 0 to 1). A pair of cells are called neighbors if they share... | {"functional": "def check(candidate):\n assert candidate(mat = [[0,0],[0,1]]) == 3\n assert candidate(mat = [[0]]) == 0\n assert candidate(mat = [[1,0,0],[1,0,0]]) == -1\n\n\ncheck(Solution().minFlips)"} | 163 | 72 |
coding | Solve the programming task below in a Python markdown code block.
You will have a list of rationals in the form
```
lst = [ [numer_1, denom_1] , ... , [numer_n, denom_n] ]
```
or
```
lst = [ (numer_1, denom_1) , ... , (numer_n, denom_n) ]
```
where all numbers are positive integers. You have to produce their sum `N /... | {"functional": "_inputs = [[[[1, 2], [1, 3], [1, 4]]], [[[1, 3], [5, 3]]], [[[12, 3], [15, 3]]], [[[2, 7], [1, 3], [1, 12]]], [[[69, 130], [87, 1310], [3, 4]]], [[[77, 130], [84, 131], [60, 80]]], [[[6, 13], [187, 1310], [31, 41]]], [[[8, 15], [7, 111], [4, 25]]], [[]], [[[81345, 15786], [87546, 11111111], [43216, 2556... | 587 | 528 |
coding | Solve the programming task below in a Python markdown code block.
We are interested in obtaining two scores from a given integer:
**First score**: The sum of all the integers obtained from the power set of the digits of the given integer that have the same order
E.g:
```
integer = 1234 ---> (1 + 2 + 3 + 4) + (12 + 1... | {"functional": "_inputs = [[100, 300], [100, 500], [300, 900]]\n_outputs = [[[7, 294]], [[7, 294, 468]], [[7, 468, 834]]]\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... | 634 | 214 |
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 integer grid accounts where accounts[i][j] is the amount of money the iβββββββββββthββββ customer has in the jβββββββββββthββββ bank. Return the wealth that the richest customer has.
A customer'... | {"functional": "def check(candidate):\n assert candidate(accounts = [[1,2,3],[3,2,1]]) == 6\n assert candidate(accounts = [[1,5],[7,3],[3,5]]) == 10\n assert candidate(accounts = [[2,8,7],[7,1,3],[1,9,5]]) == 17\n\n\ncheck(Solution().maximumWealth)"} | 136 | 94 |
coding | Solve the programming task below in a Python markdown code block.
Chef and his friend Miron were getting bored and decided to play a game.
Miron thinks of a sequence of N integers (A1, A2, β¦., AN) and gives Chef a matrix B, where Bi,j = |Ai - Aj|. He further tells Chef that A1 = 0. The game is for Chef to guess the ... | {"inputs": ["3 2\n0 1 2\n1 0 1\n2 1 0\n1\n0 4 3\n2\n4 0 7"], "outputs": ["0 -1 -2\n0 -4 -3\n0 -4 3"]} | 558 | 64 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
There is a broken calculator that has the integer startValue on its display initially. In one operation, you can:
multiply the number on display by 2, or
subtract 1 from the number on display.
Given two integers sta... | {"functional": "def check(candidate):\n assert candidate(startValue = 2, target = 3) == 2\n assert candidate(startValue = 5, target = 8) == 2\n assert candidate(startValue = 3, target = 10) == 3\n\n\ncheck(Solution().brokenCalc)"} | 117 | 74 |
coding | Solve the programming task below in a Python markdown code block.
Read problem statements in [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
Chefland has $7$ days in a week. Chef is very conscious about his work done during the week.
There are two ways he can spend his energy during the week. The ... | {"inputs": ["3\n1 2 3 1\n6 2 3 1\n1 2 8 1"], "outputs": ["14\n19\n14"]} | 535 | 43 |
coding | Solve the programming task below in a Python markdown code block.
There are N integers, A_1, A_2, ..., A_N, arranged in a row in this order.
You can perform the following operation on this integer sequence any number of times:
Operation: Choose an integer i satisfying 1 \leq i \leq N-1. Multiply both A_i and A_{i+1} by... | {"inputs": ["3\n0 1 1", "2\n-10 9\n", "3\n-1 5 1", "3\n-2 5 1", "3\n-1 1 1", "3\n-2 0 1", "3\n-10 5 0", "3\n-14 5 0"], "outputs": ["2\n", "1\n", "5\n", "6\n", "1\n", "3\n", "15\n", "19\n"]} | 355 | 121 |
coding | Solve the programming task below in a Python markdown code block.
Even if it's a really easy question, she won't be able to answer it
β Perfect Memento in Strict Sense
Cirno's perfect bitmasks classroom has just started!
Cirno gave her students a positive integer $x$. As an assignment, her students need to find the ... | {"inputs": ["1\n1073741824\n", "7\n1\n2\n5\n9\n16\n114514\n1000000\n"], "outputs": ["1073741825\n", "3\n3\n1\n1\n17\n2\n64\n"]} | 369 | 82 |
coding | Solve the programming task below in a Python markdown code block.
To protect people from evil,
a long and tall wall was constructed a few years ago.
But just a wall is not safe, there should also be soldiers on it,
always keeping vigil.
The wall is very long and connects the left and the right towers.
There are ex... | {"inputs": ["4\n3 8\n3 9\n2 4\n5 25"], "outputs": ["0\n0\n-1\n5"]} | 603 | 36 |
coding | Solve the programming task below in a Python markdown code block.
Sometimes one has to spell email addresses over the phone. Then one usually pronounces a dot as dot, an at sign as at. As a result, we get something like vasyaatgmaildotcom. Your task is to transform it into a proper email address (vasya@gmail.com).
It... | {"inputs": ["aatt\n", "atatat\n", "doatdt\n", "taatta\n", "eoatdt\n", "taatua\n", "epatdt\n", "tbatua\n"], "outputs": ["a@t\n", "at@at\n", "do@dt\n", "ta@ta\n", "eo@dt\n", "ta@ua\n", "ep@dt\n", "tb@ua\n"]} | 398 | 99 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
A digit string is good if the digits (0-indexed) at even indices are even and the digits at odd indices are prime (2, 3, 5, or 7).
For example, "2582" is good because the digits (2 and 8) at even positions are even a... | {"functional": "def check(candidate):\n assert candidate(n = 1) == 5\n assert candidate(n = 4) == 400\n assert candidate(n = 50) == 564908303\n\n\ncheck(Solution().countGoodNumbers)"} | 206 | 67 |
coding | Solve the programming task below in a Python markdown code block.
Lee just became Master in Codeforces, and so, he went out to buy some gifts for his friends. He bought $n$ integers, now it's time to distribute them between his friends rationally...
Lee has $n$ integers $a_1, a_2, \ldots, a_n$ in his backpack and he h... | {"inputs": ["3\n4 2\n1 13 7 0\n1 3\n6 2\n10 0 10 10 6 11\n3 3\n4 4\n1000000000 1000000000 1000000000 1000000000\n1 1 1 1\n", "3\n4 2\n1 13 7 1\n1 3\n6 2\n7 10 11 0 11 19\n3 3\n4 4\n1000000000 1000000000 1000000000 1000000000\n1 1 1 1\n", "3\n4 2\n0 18 12 1\n1 3\n6 2\n2 11 9 2 11 11\n3 3\n4 4\n1000000000 1000000000 1000... | 747 | 966 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an integer n represented as a string, return the smallest good base of n.
We call k >= 2 a good base of n, if all digits of n base k are 1's.
Β
Please complete the following python code precisely:
```python
clas... | {"functional": "def check(candidate):\n assert candidate(n = \"13\") == \"3\"\n assert candidate(n = \"4681\") == \"8\"\n assert candidate(n = \"1000000000000000000\") == \"999999999999999999\"\n\n\ncheck(Solution().smallestGoodBase)"} | 89 | 99 |
coding | Solve the programming task below in a Python markdown code block.
Simon has a prime number x and an array of non-negative integers a_1, a_2, ..., a_{n}.
Simon loves fractions very much. Today he wrote out number $\frac{1}{x^{a} 1} + \frac{1}{x^{a_{2}}} + \ldots + \frac{1}{x^{a_{n}}}$ on a piece of paper. After Simon l... | {"inputs": ["2 2\n2 2\n", "2 2\n2 4\n", "2 4\n2 4\n", "2 5\n2 7\n", "2 4\n2 7\n", "2 2\n2 2\n", "2 2\n5 29\n", "2 2\n7 29\n"], "outputs": ["8\n", "4\n", "16\n", "25\n", "16\n", "8\n", "32\n", "128\n"]} | 659 | 126 |
coding | Solve the programming task below in a Python markdown code block.
This problem's actual name, "Lexicographically Largest Palindromic Subsequence" is too long to fit into the page headline.
You are given string s consisting of lowercase English letters only. Find its lexicographically largest palindromic subsequence.
... | {"inputs": ["b\n", "a\n", "z\n", "y\n", "c\n", "x\n", "d\n", "aa\n"], "outputs": ["b\n", "a\n", "z\n", "y\n", "c\n", "x\n", "d\n", "aa\n"]} | 556 | 70 |
coding | Solve the programming task below in a Python markdown code block.
The Chef's latest idea is that some cooks might work better in pairs. So, he is going to experiment by pairing up some of his employees to see if the quality of the food prepared in his kitchen increases. However, only some pairs of employees are compati... | {"inputs": ["2\n4 5\n0 1\n1 2\n2 3\n1 3\n3 0\n4 3\n0 1\n2 3\n2 1", "2\n4 5\n0 1\n1 2\n2 3\n1 3\n3 0\n4 3\n0 1\n2 3\n2 0", "2\n4 5\n0 1\n1 2\n0 3\n1 3\n1 0\n4 3\n0 1\n2 3\n2 0", "2\n4 5\n0 1\n1 2\n1 3\n1 3\n2 0\n4 3\n0 1\n2 3\n2 0", "2\n4 5\n0 1\n1 2\n1 3\n0 3\n3 0\n4 1\n0 1\n2 3\n2 1", "2\n8 5\n0 1\n1 2\n1 3\n0 3\n4 0\... | 533 | 415 |
coding | Solve the programming task below in a Python markdown code block.
You are given an integer sequence $a_1, a_2, \dots, a_n$.
Find the number of pairs of indices $(l, r)$ ($1 \le l \le r \le n$) such that the value of median of $a_l, a_{l+1}, \dots, a_r$ is exactly the given number $m$.
The median of a sequence is the ... | {"inputs": ["1 1\n1\n", "1 1\n2\n", "1 1\n2\n", "1 1\n1\n", "1 1\n0\n", "2 1\n1 2\n", "2 1\n2 1\n", "2 2\n1 2\n"], "outputs": ["1\n", "0\n", "0\n", "1\n", "0\n", "2\n", "2\n", "1\n"]} | 550 | 108 |
coding | Solve the programming task below in a Python markdown code block.
Fox Ciel is playing a game. In this game there is an infinite long tape with cells indexed by integers (positive, negative and zero). At the beginning she is standing at the cell 0.
There are also n cards, each card has 2 attributes: length li and cost ... | {"inputs": ["1\n2\n2\n", "1\n1\n1\n", "1\n4\n2\n", "1\n2\n1\n", "1\n3\n1\n", "1\n5\n1\n", "1\n5\n2\n", "1\n5\n0\n"], "outputs": ["-1", "1\n", "-1\n", "-1\n", "-1\n", "-1\n", "-1\n", "-1\n"]} | 595 | 102 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
There is a hotel with n rooms. The rooms are represented by a 2D integer array rooms where rooms[i] = [roomIdi, sizei] denotes that there is a room with room number roomIdi and size equal to sizei. Each roomIdi is gua... | {"functional": "def check(candidate):\n assert candidate(rooms = [[2,2],[1,2],[3,2]], queries = [[3,1],[3,3],[5,2]]) == [3,-1,3]\n assert candidate(rooms = [[1,4],[2,3],[3,5],[4,1],[5,2]], queries = [[2,3],[2,4],[2,5]]) == [2,1,3]\n\n\ncheck(Solution().closestRoom)"} | 246 | 113 |
coding | Solve the programming task below in a Python markdown code block.
On every CodeChef user's profile page, the list of problems that they have set, tested, and written editorials for, is listed at the bottom.
Given the number of problems in each of these 3 categories as X, Y, and Z respectively (where all three integer... | {"inputs": ["4\n5 3 2\n1 2 4\n2 5 1\n9 4 5\n"], "outputs": ["Setter\nEditorialist\nTester\nSetter"]} | 495 | 45 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
There is a bi-directional graph with n vertices, where each vertex is labeled from 0 to n - 1. The edges in the graph are represented by a given 2D integer array edges, where edges[i] = [ui, vi] denotes an edge betwee... | {"functional": "def check(candidate):\n assert candidate(n = 7, edges = [[0,1],[1,2],[2,0],[3,4],[4,5],[5,6],[6,3]]) == 3\n assert candidate(n = 4, edges = [[0,1],[0,2]]) == -1\n\n\ncheck(Solution().findShortestCycle)"} | 182 | 87 |
coding | Solve the programming task below in a Python markdown code block.
Alice and Bob are playing a game with $n$ piles of stones. It is guaranteed that $n$ is an even number. The $i$-th pile has $a_i$ stones.
Alice and Bob will play a game alternating turns with Alice going first.
On a player's turn, they must choose exac... | {"inputs": ["2\n8 8\n", "2\n1 1\n", "2\n1 1\n", "2\n2 1\n", "2\n2 0\n", "2\n8 8\n", "2\n15 8\n", "4\n3 1 4 1\n"], "outputs": ["Bob\n", "Bob\n", "Bob\n", "Alice\n", "Alice\n", "Bob\n", "Alice\n", "Alice\n"]} | 391 | 107 |
coding | Solve the programming task below in a Python markdown code block.
You've got array A, consisting of n integers and a positive integer k. Array A is indexed by integers from 1 to n.
You need to permute the array elements so that value $\sum_{i = 1}^{n - k}|A [ i ] - A [ i + k ]|$ became minimal possible. In particular,... | {"inputs": ["3 2\n1 2 4\n", "2 1\n1 100\n", "2 1\n1 100\n", "3 2\n1 2 4\n", "4 3\n1 2 4 8\n", "4 3\n1 2 4 8\n", "4 1\n1 2 4 8\n", "5 3\n1 2 6 0 2\n"], "outputs": ["1\n", "99\n", "99\n", "1\n", "1\n", "1\n", "7\n", "1\n"]} | 317 | 146 |
coding | Solve the programming task below in a Python markdown code block.
Complete the solution so that it returns true if it contains any duplicate argument values. Any number of arguments may be passed into the function.
The array values passed in will only be strings or numbers. The only valid return values are `true` and ... | {"functional": "_inputs = [[1, 2, 3, 1, 2], [1, 1], [1, 0], ['a', 'b'], ['a', 'b', 'a'], [1, 2, 42, 3, 4, 5, 42], ['a', 'b', 'c', 'd'], ['a', 'b', 'c', 'c'], ['a', 'b', 'c', 'd', 'e', 'f', 'f', 'b']]\n_outputs = [[True], [True], [False], [False], [True], [True], [False], [True], [True]]\nimport math\ndef _deep_eq(a, b,... | 143 | 287 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.