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.
Mishka wants to buy some food in the nearby shop. Initially, he has $s$ burles on his card.
Mishka can perform the following operation any number of times (possibly, zero): choose some positive integer number $1 \le x \le s$, buy food that costs exactl... | {"inputs": ["6\n1\n1\n44\n3360\n3467\n1100000000\n", "6\n1\n1\n58\n3360\n3467\n1100000000\n", "6\n2\n3\n83\n1320\n7153\n1000000000\n", "6\n1\n1\n58\n3360\n6281\n1100000000\n", "6\n1\n1\n5\n3553\n12345\n1100000100\n", "6\n1\n1\n3\n6735\n12345\n1100000000\n", "6\n1\n1\n18\n3360\n6281\n1100000000\n", "6\n1\n1\n5\n1772\n12... | 497 | 502 |
coding | Solve the programming task below in a Python markdown code block.
There are N cities. There are also K roads and L railways, extending between the cities.
The i-th road bidirectionally connects the p_i-th and q_i-th cities, and the i-th railway bidirectionally connects the r_i-th and s_i-th cities.
No two roads connect... | {"inputs": ["4 3 1\n1 2\n2 3\n3 4\n2 3\n", "4 2 2\n1 2\n2 3\n1 4\n2 3\n", "7 4 4\n1 2\n2 3\n2 5\n6 7\n3 5\n4 5\n3 4\n6 7\n"], "outputs": ["1 2 2 1\n", "1 2 2 1\n", "1 1 2 1 2 2 2\n"]} | 431 | 130 |
coding | Solve the programming task below in a Python markdown code block.
An Introduction to the Longest Increasing Subsequence Problem
The task is to find the length of the longest subsequence in a given array of integers such that all elements of the subsequence are sorted in strictly ascending order. This is called the L... | {"inputs": ["5\n2\n7\n4\n3\n8\n", "6\n2\n4\n3\n7\n4\n5\n"], "outputs": ["3\n", "4\n"]} | 502 | 44 |
coding | Solve the programming task below in a Python markdown code block.
You are given a graph with N vertices (numbered 1 to N) and M bidirectional edges, which doesn't contain multiple edges or self-loops — that is, the given graph is a simple undirected graph.
For each pair of vertices a, b such that 1 ≤ a, b ≤ N, it is p... | {"inputs": ["3\n2 0\n5 4\n3 2\n1 4\n5 3\n4 2\n6 3\n1 2\n3 2\n1 3\n"], "outputs": ["1\n0\n3\n"]} | 490 | 58 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given two sorted arrays nums1 and nums2 of size m and n respectively, return the median of the two sorted arrays.
The overall run time complexity should be O(log (m+n)).
Please complete the following python code pre... | {"functional": "def check(candidate):\n assert candidate(nums1 = [1,3], nums2 = [2]) == 2.00000\n assert candidate(nums1 = [1,2], nums2 = [3,4]) == 2.50000\n\n\ncheck(Solution().findMedianSortedArrays)"} | 95 | 77 |
coding | Solve the programming task below in a Python markdown code block.
There are $5$ cities in the country.
The map of the country is given below.
The tour starts from the red city.
Each road is associated with a character.
Initially, there is an empty string.
Every time a road has been travelled the character associated g... | {"inputs": ["1\n100"], "outputs": ["NO"]} | 278 | 16 |
coding | Solve the programming task below in a Python markdown code block.
Chef Shifu and Chef Po are participating in the Greatest Dumpling Fight of 2012.
Of course, Masterchef Oogway has formed the rules of the fight.
There is a long horizontal rope of infinite length with a center point P.
Initially both Chef Shifu and Chef... | {"inputs": ["3\n2 5 0 6 0\n1 4 4 5 2\n10 12 3 1 8", "3\n2 5 0 6 0\n1 4 5 5 2\n10 12 3 1 8", "3\n2 4 0 32 0\n2 1 6 5 1\n1 2 0 5 16", "3\n2 5 0 6 0\n1 6 5 5 2\n5 12 3 1 12", "3\n2 4 0 32 0\n2 1 6 5 2\n1 2 0 5 16", "3\n2 5 0 6 0\n1 6 8 5 2\n5 12 3 1 12", "3\n2 4 3 6 7\n1 2 4 5 1\n10 12 3 9 16", "3\n2 4 0 10 0\n0 4 4 5 1\n... | 533 | 354 |
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 array grid where grid[i][j] could be:
1 representing the starting square. There is exactly one starting square.
2 representing the ending square. There is exactly one ending square.
0 r... | {"functional": "def check(candidate):\n assert candidate([[1,0,0,0],[0,0,0,0],[0,0,2,-1]]) == 2\n assert candidate([[1,0,0,0],[0,0,0,0],[0,0,0,2]]) == 4\n assert candidate([[0,1],[2,0]]) == 0\n\n\ncheck(Solution().uniquePathsIII)"} | 143 | 100 |
coding | Solve the programming task below in a Python markdown code block.
There are $n$ consecutive seat places in a railway carriage. Each place is either empty or occupied by a passenger.
The university team for the Olympiad consists of $a$ student-programmers and $b$ student-athletes. Determine the largest number of studen... | {"inputs": ["1 0 1\n.\n", "1 1 1\n.\n", "1 1 1\n.\n", "1 0 1\n.\n", "1 0 2\n.\n", "1 1 2\n.\n", "1 2 1\n.\n", "2 2 0\n..\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n"]} | 501 | 118 |
coding | Solve the programming task below in a Python markdown code block.
Write a program which prints the central coordinate $(p_x, p_y)$ and the radius $r$ of a circumscribed circle of a triangle which is constructed by three points $(x_1, y_1)$, $(x_2, y_2)$ and $(x_3, y_3)$ on the plane surface.
Constraints
* $-100 \leq ... | {"inputs": ["1\n0.0 0.0 2.0 0.0 2.0 2.0", "1\n0.0 0.0 2.0 0.5127281311709682 2.0 2.0", "1\n0.0 0.0 2.4487612247110815 0.5127281311709682 2.0 2.0", "1\n0.0 0.0 2.4487612247110815 0.5127281311709682 2.0 2.033916337250816", "1\n0.0 0.8678187768154128 2.4487612247110815 0.5127281311709682 2.0 2.033916337250816", "1\n1.3652... | 297 | 745 |
coding | Solve the programming task below in a Python markdown code block.
In this kata you need to build a function to return either `true/True` or `false/False` if a string can be seen as the repetition of a simpler/shorter subpattern or not.
For example:
```cpp,java
hasSubpattern("a") == false; //no repeated pattern
hasSub... | {"functional": "_inputs = [['a'], ['aaaa'], ['abcd'], ['abababab'], ['ababababa'], ['123a123a123a'], ['123A123a123a'], ['abbaabbaabba'], ['abbabbabba'], ['abcdabcabcd']]\n_outputs = [[False], [True], [False], [True], [False], [True], [False], [True], [False], [False]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if... | 321 | 247 |
coding | Solve the programming task below in a Python markdown code block.
Given the triangle of consecutive odd numbers:
```
1
3 5
7 9 11
13 15 17 19
21 23 25 27 29
...
```
Calculate the row sums of this triangle from the row index (starting at index 1) e.g.:
... | {"functional": "_inputs = [[1], [2], [13], [19], [41], [42], [74], [86], [93], [101]]\n_outputs = [[1], [8], [2197], [6859], [68921], [74088], [405224], [636056], [804357], [1030301]]\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... | 174 | 254 |
coding | Solve the programming task below in a Python markdown code block.
It is a simplified version of problem F2. The difference between them is the constraints (F1: $k \le 2$, F2: $k \le 10$).
You are given an integer $n$. Find the minimum integer $x$ such that $x \ge n$ and the number $x$ is $k$-beautiful.
A number is ca... | {"inputs": ["1\n4320 2\n", "1\n9319 2\n", "1\n5952 2\n", "1\n7778 2\n", "1\n5878 2\n", "1\n4025 2\n", "1\n89258 1\n", "1\n76353 2\n"], "outputs": ["4333\n", "9333\n", "5955\n", "7778\n", "5885\n", "4040\n", "99999\n", "76666\n"]} | 373 | 154 |
coding | Solve the programming task below in a Python markdown code block.
Read problems statements in Mandarin chinese, Russian and Vietnamese as well.
There are $N$ workers; each worker is of one of the following three types:
A *translator* translates some text from Chef's language to another langague.
An *author* writes so... | {"inputs": ["5\n1 3 4 6 8\n1 2 1 2 3"], "outputs": ["4"]} | 551 | 32 |
coding | Solve the programming task below in a Python markdown code block.
You are given array $a$ of length $n$. You can choose one segment $[l, r]$ ($1 \le l \le r \le n$) and integer value $k$ (positive, negative or even zero) and change $a_l, a_{l + 1}, \dots, a_r$ by $k$ each (i.e. $a_i := a_i + k$ for each $l \le i \le r$... | {"inputs": ["2 1\n1 2\n", "2 1\n1 2\n", "2 0\n1 2\n", "3 2\n6 2 6\n", "3 2\n6 2 0\n", "3 2\n6 2 6\n", "1 1\n500000\n", "1 1\n500000\n"], "outputs": ["2\n", "2\n", "1\n", "2\n", "2\n", "2\n", "1\n", "1\n"]} | 378 | 130 |
coding | Solve the programming task below in a Python markdown code block.
Ridhiman challenged Ashish to find the maximum valued subsequence of an array $a$ of size $n$ consisting of positive integers.
The value of a non-empty subsequence of $k$ elements of $a$ is defined as $\sum 2^i$ over all integers $i \ge 0$ such that at... | {"inputs": ["1\n1\n", "1\n1\n", "2\n3 4\n", "2\n3 4\n", "2\n4 4\n", "2\n4 7\n", "2\n0 7\n", "3\n2 1 3\n"], "outputs": ["1", "1\n", "7", "7\n", "4\n", "7\n", "7\n", "3"]} | 601 | 97 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given an array words of size n consisting of non-empty strings.
We define the score of a string term as the number of strings words[i] such that term is a prefix of words[i].
For example, if words = ["a", "ab... | {"functional": "def check(candidate):\n assert candidate(words = [\"abc\",\"ab\",\"bc\",\"b\"]) == [5,4,3,2]\n assert candidate(words = [\"abcd\"]) == [4]\n\n\ncheck(Solution().sumPrefixScores)"} | 173 | 62 |
coding | Solve the programming task below in a Python markdown code block.
Sereja has an array A of N positive integers : A[1], A[2], A[3], ... , A[N].
In a single operation on the array, he performs the following two steps :
- Pick two indices i, j s.t. A[i] > A[j]
- A[i] -= A[j]
Sereja can apply these operations any num... | {"inputs": ["2\n1\n1\n3\n2 4 6"], "outputs": ["1\n6"]} | 421 | 26 |
coding | Solve the programming task below in a Python markdown code block.
Grandma Capa has decided to knit a scarf and asked Grandpa Sher to make a pattern for it, a pattern is a string consisting of lowercase English letters. Grandpa Sher wrote a string $s$ of length $n$.
Grandma Capa wants to knit a beautiful scarf, and in ... | {"inputs": ["5\n8\nabcaacab\n6\nxyzxyz\n4\nabba\n8\nrprarlap\n10\nkhyyhhyhky\n", "5\n8\nabcaacab\n6\nxyzxyz\n4\nabba\n8\nrpqarlap\n10\nkhyyhhyhky\n", "5\n8\nabcaacab\n6\nxyzxyy\n4\nabba\n8\nrpqarlap\n10\nkhyyhhyhky\n", "5\n8\nabcaacab\n6\nxyzxyz\n4\nabab\n8\nrpqarlap\n10\nkhyyhhyhky\n", "5\n8\nabcaacab\n6\nxyzxyy\n4\na... | 622 | 415 |
coding | Solve the programming task below in a Python markdown code block.
Read problem statements in [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.
There is a grid of size 10^{5} \times 10^{5}, covered completely in railway tracks. Tom is riding in a train, currently in cell (a, b), and Jerry is tied up i... | {"inputs": ["3\n1 1 2 2 2\n1 1 2 3 4\n1 1 1 0 3"], "outputs": ["YES\nNO\nYES"]} | 548 | 46 |
coding | Solve the programming task below in a Python markdown code block.
Lauren has a chart of distinct projected prices for a house over the next several years. She must buy the house in one year and sell it in another, and she must do so at a loss. She wants to minimize her financial loss.
Example
$price=[20,15,8,2,1... | {"inputs": ["3\n5 10 3\n", "5\n20 7 8 2 5\n"], "outputs": ["2\n", "2\n"]} | 445 | 40 |
coding | Solve the programming task below in a Python markdown code block.
Nexus 4.O is going to be organized by ASME, GLA University. Shubhanshu, Head of Finance Team is working for it. He has $N$ number of bills of different values as $a$$1$,$ a$$2$, $a$$3$…$a$$n$.
He is interested in a game in which one has to do the additio... | {"inputs": ["1\n8 3\n1 2 3 4 5 6 7 8\n2 3\n1 6\n5 8"], "outputs": ["5\n21\n26"]} | 700 | 50 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given two version strings, version1 and version2, compare them. A version string consists of revisions separated by dots '.'. The value of the revision is its integer conversion ignoring leading zeros.
To compare vers... | {"functional": "def check(candidate):\n assert candidate(version1 = \"1.2\", version2 = \"1.10\") == -1\n assert candidate(version1 = \"1.01\", version2 = \"1.001\") == 0\n assert candidate(version1 = \"1.0\", version2 = \"1.0.0.0\") == 0\n\n\ncheck(Solution().compareVersion)"} | 157 | 96 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given two strings firstString and secondString that are 0-indexed and consist only of lowercase English letters. Count the number of index quadruples (i,j,a,b) that satisfy the following conditions:
0 <= i <=... | {"functional": "def check(candidate):\n assert candidate(firstString = \"abcd\", secondString = \"bccda\") == 1\n assert candidate(firstString = \"ab\", secondString = \"cd\") == 0\n\n\ncheck(Solution().countQuadruples)"} | 189 | 60 |
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.
Chef is teaching a cooking course. There are $N$ students attending the course, numbered $1$ through $N$.
Before each lesson, Chef has to take atten... | {"inputs": ["1\n4\nhasan jaddouh\nfarhod khakimiyon\nkerim kochekov\nhasan khateeb"], "outputs": ["hasan jaddouh\nfarhod\nkerim\nhasan khateeb"]} | 512 | 61 |
coding | Solve the programming task below in a Python markdown code block.
You are given a string S of length N.
Your task is to delete a [subsequence] of maximum length from the string, such that, after concatenating the remaining parts of the string, it becomes a [palindrome] of length greater than 1.
If this is possible, p... | {"inputs": ["3\n6\nbabkhj\n3 \nabc \n4 \nqtoo"], "outputs": ["4\n-1\n2 \n"]} | 469 | 37 |
coding | Solve the programming task below in a Python markdown code block.
Let's call a non-empty sequence of positive integers a_1, a_2... a_{k} coprime if the greatest common divisor of all elements of this sequence is equal to 1.
Given an array a consisting of n positive integers, find the number of its coprime subsequences... | {"inputs": ["1\n1\n", "1\n1\n", "3\n1 2 3\n", "3\n1 2 5\n", "3\n1 1 5\n", "3\n1 1 1\n", "3\n1 2 3\n", "1\n100000\n"], "outputs": ["1\n", "1", "5\n", "5\n", "6\n", "7\n", "5", "0\n"]} | 346 | 109 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an array of strings words, return the first palindromic string in the array. If there is no such string, return an empty string "".
A string is palindromic if it reads the same forward and backward.
Please com... | {"functional": "def check(candidate):\n assert candidate(words = [\"abc\",\"car\",\"ada\",\"racecar\",\"cool\"]) == \"ada\"\n assert candidate(words = [\"notapalindrome\",\"racecar\"]) == \"racecar\"\n assert candidate(words = [\"def\",\"ghi\"]) == \"\"\n\n\ncheck(Solution().firstPalindrome)"} | 96 | 81 |
coding | Solve the programming task below in a Python markdown code block.
We all know that Share market is place where drastic change occurs within moments. So we have one Stockholder, Isabella, who wants to maximize her profit by selling her shares. She has $N$ shares of a Doofenshmirtz Corporation which is represented by $N$... | {"inputs": ["1\n4\n1 2\n4 3\n3 5\n2 4"], "outputs": ["3"]} | 454 | 34 |
coding | Solve the programming task below in a Python markdown code block.
Write
```python
word_pattern(pattern, string)
```
that given a ```pattern``` and a string ```str```, find if ```str``` follows the same sequence as ```pattern```.
For example:
```python
word_pattern('abab', 'truck car truck car') == True
word_pattern('... | {"functional": "_inputs = [['abab', 'apple banana apple banana'], ['abba', 'car truck truck car'], ['abab', 'apple banana banana apple'], ['aaaa', 'cat cat cat cat'], ['aaaa', 'cat cat dog cat'], ['bbbabcb', 'c# c# c# javascript c# python c#'], ['abcdef', 'apple banana cat donkey elephant flower'], ['xyzzyx', 'apple ba... | 143 | 358 |
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.
"It's totally fun to play troublemakers ― totally." - Lee Pace
Sakshi had a matrix with $N$ rows (numbered $1$ through $N$) and $M$ columns (numbere... | {"inputs": ["1\n2 2 3\n1 1\n1 2\n2 1"], "outputs": ["2"]} | 749 | 30 |
coding | Solve the programming task below in a Python markdown code block.
For a given prime $\boldsymbol{p}$, define $\text{ord}_p(k)$ as the multiplicity of $\boldsymbol{p}$ in $\boldsymbol{\mbox{k}}$, i.e. the number of times $\boldsymbol{p}$ appears in the prime factorization of $\boldsymbol{k}$.
For a given $\boldsymbol{p... | {"inputs": ["2\n2 6\n3 6\n"], "outputs": ["2\n2\n"]} | 488 | 24 |
coding | Solve the programming task below in a Python markdown code block.
You are given an array B of length 2N . You have an unknown array A which is sorted and contains *distinct* elements. You need to find out the array A. B contains all the medians of each prefix and suffix of the array A.
A median is the middle element i... | {"inputs": ["2\n3\n6 5 5 7 6 6\n3\n1 2 1 4 2 4"], "outputs": ["5 6 7\n-1"]} | 528 | 47 |
coding | Solve the programming task below in a Python markdown code block.
You have to restore the wall. The wall consists of $N$ pillars of bricks, the height of the $i$-th pillar is initially equal to $h_{i}$, the height is measured in number of bricks. After the restoration all the $N$ pillars should have equal heights.
You... | {"inputs": ["1 0 0 0\n0\n", "1 0 0 0\n1\n", "1 0 0 1\n1\n", "2 0 0 0\n1 1\n", "2 0 0 0\n2 1\n", "2 0 0 0\n0 1\n", "2 0 0 1\n0 1\n", "2 0 0 1\n-1 1\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]} | 440 | 145 |
coding | Solve the programming task below in a Python markdown code block.
There is a long-established secondhand bookstore called JOI secondhand bookstore in your town, and you often use the JOI secondhand bookstore. Each book has a standard price, and you can buy it at that price if you go to the JOI secondhand bookstore.
At... | {"inputs": ["7 2\n4 1\n0 1\n9 2\n10 3\n8 2\n4 8\n8 2", "7 2\n4 1\n9 1\n9 2\n3 5\n2 2\n4 3\n11 2", "7 2\n4 1\n0 1\n4 2\n10 3\n8 2\n4 8\n8 2", "7 4\n4 1\n13 1\n9 2\n3 5\n3 2\n4 3\n11 2", "7 5\n4 1\n13 2\n9 2\n10 3\n8 2\n4 8\n11 2", "7 1\n4 1\n13 2\n9 2\n10 3\n8 2\n4 8\n11 2", "7 4\n7 2\n0 1\n20 6\n15 2\n0 7\n5 5\n12 4", ... | 467 | 327 |
coding | Solve the programming task below in a Python markdown code block.
"This problem is rubbish! There is not statement, and there are only 5 test cases. The problemsetter took liberties with this problem!" — people complained in the comments to one round on Codeforces. And even more... No, wait, the checker for the problem... | {"inputs": ["5\n", "4\n", "2\n", "3\n", "1\n"], "outputs": ["1", "2", "3", "1", "2"]} | 156 | 41 |
coding | Solve the programming task below in a Python markdown code block.
Serena is interested in only red and yellow roses. She is arranging flowers in some fashion to be presented at her friend's birthday. Her friend loves only red and yellow roses(but mostly red ones). The flowers can be arranged only in the following three... | {"inputs": ["47\nRRYRRY\nRRRR\nYYRWBR\nR\nRY\nRRY\nW\nYRY\nRGGGGGGGGG\nRYYRYYRYY\nRYYY\nRR\nRYRYRYRYR\nRRRRGRRR\nRRYRRYRYY\nYYY\nBBBB\nRRRYYY\nRRRRY\nYRRRR\nRRYYRYYYR\nRYYYRYYYR\nRYYBYYRYY\nRRRRRRRRR\nRYYYYYYYY\nYYYYYYYYY\nRYRYYRYYR\nYYR\nRP\nRYYYY\nRRYYY\nRYY\nRYRYYRY\nRYRYYY\nRYRYY\nY\nRRYY\nRYRRRRYYY\nRYYRYYRY\nRYRY... | 337 | 303 |
coding | Solve the programming task below in a Python markdown code block.
Tired of the overpopulated world, Miu - The introverted cat visits a new continent in search for a new house.
There are $N$ houses lying on the X-axis.
Their positions are given by $X$$i$ , where $i$ refers to the $i$th house. ( $1 <= i <= N$ )
Each ... | {"inputs": ["2\n6\n7 -1 2 13 -5 15\n4\n6 10 3 12"], "outputs": ["5\n3"]} | 460 | 42 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
A k x k magic square is a k x k grid filled with integers such that every row sum, every column sum, and both diagonal sums are all equal. The integers in the magic square do not have to be distinct. Every 1 x 1 grid ... | {"functional": "def check(candidate):\n assert candidate(grid = [[7,1,4,5,6],[2,5,1,6,4],[1,5,4,3,2],[1,2,7,3,4]]) == 3\n assert candidate(grid = [[5,1,3,1],[9,3,3,1],[1,3,3,8]]) == 2\n\n\ncheck(Solution().largestMagicSquare)"} | 143 | 105 |
coding | Solve the programming task below in a Python markdown code block.
Chef is currently standing at stair 0 and he wants to reach stair numbered X.
Chef can climb either Y steps or 1 step in one move.
Find the minimum number of moves required by him to reach exactly the stair numbered X.
------ Input Format ------
- ... | {"inputs": ["4\n4 2\n8 3\n3 4\n2 1\n"], "outputs": ["2\n4\n3\n2\n"]} | 364 | 36 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right, which minimizes the sum of all numbers along its path.
Note: You can only move either down or right at any point in time.... | {"functional": "def check(candidate):\n assert candidate(grid = [[1,3,1],[1,5,1],[4,2,1]]) == 7\n assert candidate(grid = [[1,2,3],[4,5,6]]) == 12\n\n\ncheck(Solution().minPathSum)"} | 100 | 71 |
coding | Solve the programming task below in a Python markdown code block.
You are given a permutation $p_1, p_2, \ldots, p_n$ of length $n$. You have to choose two integers $l,r$ ($1 \le l \le r \le n$) and reverse the subsegment $[l,r]$ of the permutation. The permutation will become $p_1,p_2, \dots, p_{l-1},p_r,p_{r-1}, \dot... | {"inputs": ["4\n1\n1\n3\n2 1 3\n4\n1 4 2 3\n5\n1 2 3 4 5\n"], "outputs": ["1 \n1 2 3 \n1 2 4 3 \n1 2 3 4 5 \n"]} | 658 | 76 |
coding | Solve the programming task below in a Python markdown code block.
Write a method named `getExponent(n,p)` that returns the largest integer exponent `x` such that p^(x) evenly divides `n`. if `p<=1` the method should return `null`/`None` (throw an `ArgumentOutOfRange` exception in C#).
Also feel free to reuse/extend the... | {"functional": "_inputs = [[27, 3]]\n_outputs = [[3]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) != len(b): return False\n return all(_deep_... | 97 | 159 |
coding | Solve the programming task below in a Python markdown code block.
Find the union of two sets $A = \\{a_0, a_1, ..., a_{n-1}\\}$ and $B = \\{b_0, b_1, ..., b_{m-1}\\}$.
Constraints
* $1 \leq n, m \leq 200,000$
* $0 \leq a_0 < a_1 < ... < a_{n-1} \leq 10^9$
* $0 \leq b_0 < b_1 < ... < b_{m-1} \leq 10^9$
Input
The inp... | {"inputs": ["3\n1 5 8\n2\n5 8", "3\n1 3 8\n2\n5 8", "3\n1 5 8\n2\n4 9", "3\n1 6 8\n2\n5 8", "3\n1 3 8\n2\n2 8", "3\n1 5 8\n2\n3 9", "3\n2 3 8\n2\n5 8", "3\n1 3 8\n2\n3 8"], "outputs": ["1\n5\n8\n", "1\n3\n5\n8\n", "1\n4\n5\n8\n9\n", "1\n5\n6\n8\n", "1\n2\n3\n8\n", "1\n3\n5\n8\n9\n", "2\n3\n5\n8\n", "1\n3\n8\n"]} | 273 | 206 |
coding | Solve the programming task below in a Python markdown code block.
Your work is to write a method that takes a value and an index, and returns the value with the bit at given index flipped.
The bits are numbered from the least significant bit (index 1).
Example:
```python
flip_bit(15, 4) == 7 # 15 in binary is 1111, a... | {"functional": "_inputs = [[0, 16], [2147483647, 31], [127, 8]]\n_outputs = [[32768], [1073741823], [255]]\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(... | 246 | 204 |
coding | Solve the programming task below in a Python markdown code block.
A palindrome is a word that reads the same forward and backward. Given a string s, you need to make it a palindrome by adding 0 or more characters to the end of s, and remember, we want the palindrome to be as short as possible.
INPUT
First line is T,... | {"inputs": ["6\nabdfhdyrbdbsdfghjkllkjhgfds\nzazazazazazazazazazazazazazazazazazazazazazazazaza\nbacba\na\nadwuaaxcnleegluqvsczaguujoppchwecusmevz\nkoikijiikmmkmonkiinnjlijmiimnniokikimikkkkjkmiinii"], "outputs": ["38\n51\n9\n1\n77\n95"]} | 219 | 120 |
coding | Solve the programming task below in a Python markdown code block.
In Russia, there is an army-purposed station named UVB-76 or "Buzzer" (see also https://en.wikipedia.org/wiki/UVB-76). Most of time specific "buzz" noise is being broadcasted, but on very rare occasions, the buzzer signal is interrupted and a voice trans... | {"functional": "_inputs = [['Is this a right message?'], ['MDZHB 85 596 KLASA 81 00 02 91'], ['MDZHB 12 733 EDINENIE 67 79 66 32'], ['MDZHV 60 130 VATRUKH 58 89 54 54'], ['MDZHB 85 596 BRAMIRKA 81 00 02 91'], ['MDZHB 12 733 INITIAL 67 79 66 32'], ['MDZHB 60 130 KROLI5T 58 89 54 54'], ['MDZHB 85 596 KAMASIT 81 00 02 91'... | 270 | 1,022 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an array nums of distinct positive integers, return the number of tuples (a, b, c, d) such that a * b = c * d where a, b, c, and d are elements of nums, and a != b != c != d.
Please complete the following pyth... | {"functional": "def check(candidate):\n assert candidate(nums = [2,3,4,6]) == 8\n assert candidate(nums = [1,2,4,5,10]) == 16\n\n\ncheck(Solution().tupleSameProduct)"} | 104 | 60 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given two strings str1 and str2, return the shortest string that has both str1 and str2 as subsequences. If there are multiple valid strings, return any of them.
A string s is a subsequence of string t if deleting som... | {"functional": "def check(candidate):\n assert candidate(str1 = \"abac\", str2 = \"cab\") == \"cabac\"\n assert candidate(str1 = \"aaaaaaaa\", str2 = \"aaaaaaaa\") == \"aaaaaaaa\"\n\n\ncheck(Solution().shortestCommonSupersequence)"} | 121 | 64 |
coding | Solve the programming task below in a Python markdown code block.
Harry is a bright student. To prepare thoroughly for exams, he completes all the exercises in his book! Now that the exams are approaching fast, he is doing book exercises day and night. He writes down and keeps updating the remaining number of exercises... | {"inputs": ["6\n9 english\n6 mathematics\n8 geography\n-1\n3 graphics\n-1"], "outputs": ["1 mathematics\n0 graphics"]} | 500 | 34 |
coding | Solve the programming task below in a Python markdown code block.
For a positive integer n, let us define f(n) as the number of digits in base 10.
You are given an integer S.
Count the number of the pairs of positive integers (l, r) (l \leq r) such that f(l) + f(l + 1) + ... + f(r) = S, and find the count modulo 10^9 +... | {"inputs": ["4", "3", "6", "8", "1", "2", "1\n", "2\n"], "outputs": ["9096\n", "908\n", "900993\n", "90009092\n", "9", "98", "9\n", "98\n"]} | 186 | 81 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
There is a long and thin painting that can be represented by a number line. The painting was painted with multiple overlapping segments where each segment was painted with a unique color. You are given a 2D integer ar... | {"functional": "def check(candidate):\n assert candidate(segments = [[1,4,5],[4,7,7],[1,7,9]]) == [[1,4,14],[4,7,16]]\n assert candidate(segments = [[1,7,9],[6,8,15],[8,10,7]]) == [[1,6,9],[6,7,24],[7,8,15],[8,10,7]]\n assert candidate(segments = [[1,4,5],[1,4,7],[4,7,1],[4,7,11]]) == [[1,4,12],[4,7,12]]\n\n\n... | 448 | 171 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a 0-indexed array nums consisting of positive integers.
You can do the following operation on the array any number of times:
Choose an integer i such that 0 <= i < nums.length - 1 and nums[i] <= nums[i ... | {"functional": "def check(candidate):\n assert candidate(nums = [2,3,7,9,3]) == 21\n assert candidate(nums = [5,3,3]) == 11\n\n\ncheck(Solution().maxArrayValue)"} | 153 | 58 |
coding | Solve the programming task below in a Python markdown code block.
There are n railway stations in Berland. They are connected to each other by n-1 railway sections. The railway network is connected, i.e. can be represented as an undirected tree.
You have a map of that network, so for each railway section you know whic... | {"inputs": ["2\n2 1\n1\n1 2 3\n", "2\n2 1\n1\n1 2 4\n", "3\n2 1\n3 1\n1\n3 2 3\n", "3\n2 1\n3 1\n1\n2 3 1\n", "2\n2 1\n2\n1 2 3\n1 2 3\n", "2\n2 1\n2\n1 2 1\n2 1 1\n", "4\n4 1\n2 3\n2 1\n1\n1 3 1\n", "3\n1 2\n1 3\n2\n3 2 2\n1 3 4\n"], "outputs": ["3 \n", "4 \n", "3 3 \n", "1 1 \n", "3 \n", "1 \n", "1 1 1 \n", "2 4 \n"]... | 701 | 222 |
coding | Solve the programming task below in a Python markdown code block.
In his publication Liber Abaci Leonardo Bonacci, aka Fibonacci, posed a problem involving a population of idealized rabbits. These rabbits bred at a fixed rate, matured over the course of one month, had unlimited resources, and were immortal.
Beginning ... | {"functional": "_inputs = [[0, 4], [1, 4], [4, 0], [6, 3], [8, 12], [7, 4], [9, 8], [10, 2], [11, 33], [100, 3], [40, 6], [4, 100]]\n_outputs = [[0], [1], [1], [40], [8425], [181], [10233], [341], [58212793], [465790837923166086127602033842234887], [2431532871909060205], [201]]\nimport math\ndef _deep_eq(a, b, tol=1e-5... | 233 | 342 |
coding | Solve the programming task below in a Python markdown code block.
Rakesh has built a model rocket and wants to test how stable it is. He usually uses a magic box which runs some tests on the rocket and tells if it is stable or not, but his friend broke it by trying to find out how stable he is (very delicate magic inde... | {"inputs": ["1\n10 12 4 5 3"], "outputs": ["0"]} | 585 | 24 |
coding | Solve the programming task below in a Python markdown code block.
In this kata, you will do addition and subtraction on a given string. The return value must be also a string.
**Note:** the input will not be empty.
## Examples
```
"1plus2plus3plus4" --> "10"
"1plus2plus3minus4" --> "2"
```
Also feel free to reuse/... | {"functional": "_inputs = [['1plus2plus3plus4'], ['1minus2minus3minus4'], ['1plus2plus3minus4'], ['1minus2plus3minus4'], ['1plus2minus3plus4minus5']]\n_outputs = [['10'], ['-8'], ['2'], ['-2'], ['-1']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math... | 103 | 211 |
coding | Solve the programming task below in a Python markdown code block.
Read problems statements in Mandarin Chinese , Russian and Vietnamese as well.
Chef belongs to a very rich family which owns many gold mines. Today, he brought N gold coins and decided to form a triangle using these coins. Isn't it strange?
Chef has a... | {"inputs": ["3\n3\n5\n7", "3\n5\n9\n2", "3\n5\n5\n2", "3\n2\n5\n2", "3\n5\n5\n7", "3\n5\n5\n3", "3\n5\n7\n7", "3\n5\n7\n5"], "outputs": ["2\n2\n3", "2\n3\n1\n", "2\n2\n1\n", "1\n2\n1\n", "2\n2\n3\n", "2\n2\n2\n", "2\n3\n3\n", "2\n3\n2\n"]} | 423 | 141 |
coding | Solve the programming task below in a Python markdown code block.
In distant future on Earth day lasts for n hours and that's why there are n timezones. Local times in adjacent timezones differ by one hour. For describing local time, hours numbers from 1 to n are used, i.e. there is no time "0 hours", instead of it "n ... | {"inputs": ["2\n5 1\n1 2\n", "2\n5 1\n1 2\n", "3\n1 2 3\n1 3\n", "3\n1 4 3\n1 3\n", "3\n1 2 3\n1 3\n", "2\n909 8422\n1 2\n", "5\n1 2 3 4 1\n1 3\n", "2\n5072 8422\n1 2\n"], "outputs": ["1\n", "1", "3\n", "3\n", "3", "2\n", "4\n", "2\n"]} | 533 | 155 |
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 (BST), return the minimum difference between the values of any two different nodes in the tree.
Please complete the following python code precisely:
```python
# Definition for ... | {"functional": "def check(candidate):\n assert candidate(root = tree_node([4,2,6,1,3])) == 1\n assert candidate(root = tree_node([1,0,48,None,None,12,49])) == 1\n\n\ncheck(Solution().minDiffInBST)"} | 129 | 70 |
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 of the same length words.
In one move, you can swap any two even indexed characters or any two odd indexed characters of a string words[i].
Two strings words[i] and words[j] are speci... | {"functional": "def check(candidate):\n assert candidate(words = [\"abcd\",\"cdab\",\"cbad\",\"xyzz\",\"zzxy\",\"zzyx\"]) == 3\n assert candidate(words = [\"abc\",\"acb\",\"bac\",\"bca\",\"cab\",\"cba\"]) == 3\n\n\ncheck(Solution().numSpecialEquivGroups)"} | 243 | 77 |
coding | Solve the programming task below in a Python markdown code block.
The Quark Codejam's number QC(n, m) represents the number of ways to partition a set of n things into m nonempty subsets. For example, there are seven ways to split a four-element set into two parts:
{1, 2, 3} ∪ {4}, {1, 2, 4} ∪ {3}, {1, 3, 4} ∪ {2}, {2... | {"inputs": ["1\n4 2"], "outputs": ["1"]} | 393 | 16 |
coding | Solve the programming task below in a Python markdown code block.
Young Teodor enjoys drawing. His favourite hobby is drawing segments with integer borders inside his huge [1;m] segment. One day Teodor noticed that picture he just drawn has one interesting feature: there doesn't exist an integer point, that belongs eac... | {"inputs": ["2 7\n1 2\n3 4\n", "2 4\n1 2\n3 4\n", "4 6\n1 3\n2 5\n4 6\n5 6\n", "4 6\n1 3\n2 3\n4 6\n5 6\n", "11 3\n1 1\n1 1\n1 1\n1 1\n2 2\n2 2\n2 2\n3 3\n3 3\n3 3\n3 3\n", "31 1600\n51 1483\n8 475\n14 472\n49 81\n300 1485\n627 682\n44 443\n1191 1541\n478 732\n1112 1202\n741 1341\n475 1187\n1218 1463\n523 1513\n274 477... | 655 | 993 |
coding | Solve the programming task below in a Python markdown code block.
D: Shiritori Compression
problem
Ebi-chan and Kana-chan did a shiritori. Ebi-chan is looking at the memo of the word that came out in Shiritori.
Ebi-chan wants to remove redundant continuous subsequences from this word sequence w_1, w_2, ..., w_N unti... | {"inputs": ["7\nbanana\nta\ntomb\nbus\nsound\ndoes\nsome", "7\nananab\nta\nsomb\nbus\nsound\ndoes\nsemo", "7\nbanaoa\nta\ntomb\nbus\nsound\ndoes\nsome", "7\nbanaoa\nta\nuomb\nbus\nsound\ndoes\nsome", "7\nbanaoa\nua\ntomb\nbus\nsound\ndoes\nsome", "7\nbanaoa\nua\ntomb\nbus\nspund\ndoes\nsome", "7\nbanaoa\nua\ntomb\nbus\... | 684 | 211 |
coding | Solve the programming task below in a Python markdown code block.
Are you fond of collecting some kind of stuff? Mike is crazy about collecting stamps. He is an active member of Stamp Collecting Сommunity(SCC).
SCC consists of N members which are fond of philately. A few days ago Mike argued with the others from SCC.... | {"inputs": ["5\n1 1 1 1 0", "5\n1 2 1 1 0", "5\n0 2 1 1 0", "5\n0 3 1 1 0", "5\n0 3 1 0 0", "5\n0 3 1 0 1", "5\n0 3 0 0 1", "5\n0 3 0 0 0"], "outputs": ["NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n"]} | 312 | 142 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
A gene string can be represented by an 8-character long string, with choices from 'A', 'C', 'G', and 'T'.
Suppose we need to investigate a mutation from a gene string startGene to a gene string endGene where one mutat... | {"functional": "def check(candidate):\n assert candidate(start = \"AACCGGTT\", end = \"AACCGGTA\", bank = [\"AACCGGTA\"]) == 1\n assert candidate(start = \"AACCGGTT\", end = \"AAACGGTA\", bank = [\"AACCGGTA\",\"AACCGCTA\",\"AAACGGTA\"]) == 2\n assert candidate(start = \"AAAAACCC\", end = \"AACCCCCC\", bank = [... | 237 | 133 |
coding | Solve the programming task below in a Python markdown code block.
You are given an integer N that has exactly four digits in base ten. How many times does `2` occur in the base-ten representation of N?
Constraints
* 1000 \leq N \leq 9999
Input
Input is given from Standard Input in the following format:
N
Output... | {"inputs": ["0", "1", "2", "3", "95", "79", "89", "36"], "outputs": ["0\n", "0\n", "1\n", "0\n", "0\n", "0\n", "0\n", "0\n"]} | 121 | 66 |
coding | Solve the programming task below in a Python markdown code block.
The Chessboard Distance for any two points (X_{1}, Y_{1}) and (X_{2}, Y_{2}) on a Cartesian plane is defined as max(|X_{1} - X_{2}|, |Y_{1} - Y_{2}|).
You are given two points (X_{1}, Y_{1}) and (X_{2}, Y_{2}). Output their Chessboard Distance.
Note ... | {"inputs": ["3\n2 4 5 1\n5 5 5 3\n1 4 3 3\n"], "outputs": ["3\n2\n2\n"]} | 513 | 42 |
coding | Solve the programming task below in a Python markdown code block.
You are given an array $a$, consisting of $n$ positive integers.
Let's call a concatenation of numbers $x$ and $y$ the number that is obtained by writing down numbers $x$ and $y$ one right after another without changing the order. For example, a concate... | {"inputs": ["4 2\n2 78 4 2\n", "4 2\n1 78 4 2\n", "4 2\n2 78 4 10\n", "4 4\n1 130 4 2\n", "4 2\n1 130 4 2\n", "4 2\n2 78 4 10\n", "5 2\n3 7 19 3 3\n", "1 2\n1000000000\n"], "outputs": ["12\n", "9\n", "12\n", "3\n", "9\n", "12", "0\n", "0\n"]} | 497 | 168 |
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 matrix grid, where m and n are both even integers, and an integer k.
The matrix is composed of several layers, which is shown in the below image, where each color is its own layer:
A... | {"functional": "def check(candidate):\n assert candidate(grid = [[40,10],[30,20]], k = 1) == [[10,20],[40,30]]\n assert candidate(grid = [[1,2,3,4],[5,6,7,8],[9,10,11,12],[13,14,15,16]], k = 2) == [[3,4,8,12],[2,11,10,16],[1,7,6,15],[5,9,13,14]]\n\n\ncheck(Solution().rotateGrid)"} | 170 | 151 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given an integer n and an integer p representing an array arr of length n where all elements are set to 0's, except position p which is set to 1. You are also given an integer array banned containing restricte... | {"functional": "def check(candidate):\n assert candidate(n = 4, p = 0, banned = [1,2], k = 4) == [0,-1,-1,1]\n assert candidate(n = 5, p = 0, banned = [2,4], k = 3) == [0,-1,-1,-1,-1]\n assert candidate(n = 4, p = 2, banned = [0,1,3], k = 1) == [-1,-1,0,-1]\n\n\ncheck(Solution().minReverseOperations)"} | 178 | 132 |
coding | Solve the programming task below in a Python markdown code block.
Devu and his brother love each other a lot. As they are super geeks, they only like to play with arrays. They are given two arrays a and b by their father. The array a is given to Devu and b to his brother.
As Devu is really a naughty kid, he wants the... | {"inputs": ["1 1\n1\n2\n", "1 1\n1\n1\n", "1 1\n2\n1\n", "1 1\n1\n2\n", "1 1\n1\n3\n", "1 1\n2\n1\n", "1 1\n1\n1\n", "1 1\n1\n2\n"], "outputs": ["1\n", "0\n", "0\n", "1\n", "2\n", "0\n", "0\n", "1\n"]} | 473 | 118 |
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 how many of them contain an even number of digits.
Please complete the following python code precisely:
```python
class Solution:
def findNumbers(self, nums: List[int]) ->... | {"functional": "def check(candidate):\n assert candidate(nums = [12,345,2,6,7896]) == 2\n assert candidate(nums = [555,901,482,1771]) == 1 \n\n\ncheck(Solution().findNumbers)"} | 67 | 73 |
coding | Solve the programming task below in a Python markdown code block.
# Task
Write a function named `sumEvenNumbers`, taking a sequence of numbers as single parameter. Your function must return the sum of **the even values** of this sequence.
Only numbers without decimals like `4` or `4.0` can be even.
## Input
* seque... | {"functional": "_inputs = [[[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]], [[]], [[1337, 374, 849, 22.5, 19, 16, 0, 0, 16, 32]], [[-16, -32, 20, 21, 41, 42]], [[15397, 12422, 10495, 22729, 23921, 18326, 27955, 24073, 23690, 15002, 11615, 15682, 24346, 16725, 17252, 20467, 20493, 17807, 13041, 25861, 22471, 22747, 24082, 18979, 2854... | 172 | 975 |
coding | Solve the programming task below in a Python markdown code block.
You are given an array a_0, a_1, ..., a_{N-1} of length N. Process Q queries of the following types.
* `0 p x`: a_p \gets a_p + x
* `1 l r`: Print \sum_{i = l}^{r - 1}{a_i}.
Constraints
* 1 \leq N, Q \leq 500,000
* 0 \leq a_i, x \leq 10^9
* 0 \leq p <... | {"inputs": ["5 5\n0 1 8 4 7\n0 0 5\n1 2 4\n0 3 4\n1 0 5\n1 0 3", "5 5\n0 1 8 4 7\n0 0 5\n1 2 4\n0 3 4\n1 0 5\n1 1 3", "5 5\n1 2 3 4 5\n4 1 5\n1 2 4\n0 3 6\n1 0 5\n1 0 3", "5 5\n1 2 3 4 5\n1 1 5\n1 2 4\n0 3 10\n1 0 5\n1 0 3", "5 5\n1 2 5 4 5\n1 1 5\n1 2 4\n0 3 10\n1 0 5\n1 0 3", "5 5\n1 2 5 4 5\n1 1 2\n1 2 4\n0 3 10\n1 ... | 292 | 463 |
coding | Solve the programming task below in a Python markdown code block.
A variation of determining leap years, assuming only integers are used and years can be negative and positive.
Write a function which will return the days in the year and the year entered in a string. For example 2000, entered as an integer, will retur... | {"functional": "_inputs = [[0], [-64], [2016], [1974], [-10], [666], [1857], [2000], [-300], [-1]]\n_outputs = [['0 has 366 days'], ['-64 has 366 days'], ['2016 has 366 days'], ['1974 has 365 days'], ['-10 has 365 days'], ['666 has 365 days'], ['1857 has 365 days'], ['2000 has 366 days'], ['-300 has 365 days'], ['-1 ha... | 226 | 304 |
coding | Solve the programming task below in a Python markdown code block.
Consider a game, wherein the player has to guess a target word. All the player knows is the length of the target word.
To help them in their goal, the game will accept guesses, and return the number of letters that are in the correct position.
Write a ... | {"functional": "_inputs = [['dog', 'car'], ['dog', 'god'], ['dog', 'cog'], ['dog', 'cod'], ['dog', 'bog'], ['dog', 'dog'], ['abcde', 'abcde'], ['same', 'same'], ['z', 'z']]\n_outputs = [[0], [1], [2], [1], [2], [3], [5], [4], [1]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b,... | 431 | 234 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given an integer array jobs, where jobs[i] is the amount of time it takes to complete the ith job.
There are k workers that you can assign jobs to. Each job should be assigned to exactly one worker. The workin... | {"functional": "def check(candidate):\n assert candidate(jobs = [3,2,3], k = 3) == 3\n assert candidate(jobs = [1,2,4,7,8], k = 2) == 11\n\n\ncheck(Solution().minimumTimeRequired)"} | 153 | 69 |
coding | Solve the programming task below in a Python markdown code block.
A squarer is a simple and convenient device. You give it some positive integer X and it calculates its square.
Leha is implementing a module of this device which is responsible for squaring the numbers consisting of multiple repetitions of one digit. But... | {"inputs": ["3\n1 4\n3 6\n3 5"], "outputs": ["139\n40079781\n32745632"]} | 442 | 44 |
coding | Solve the programming task below in a Python markdown code block.
Computation of the date either previous or forthcoming dates is quiet easy. But it is quiet difficult to calculate the day from a particular given date.
You are required to find a day from a particular date given to you.
-----Input-----
It consists of ... | {"inputs": ["14 3 2012"], "outputs": ["Wednesday"]} | 162 | 20 |
coding | Solve the programming task below in a Python markdown code block.
# Task
"AL-AHLY" and "Zamalek" are the best teams in Egypt, but "AL-AHLY" always wins the matches between them. "Zamalek" managers want to know what is the best match they've played so far.
The best match is the match they lost with the minimum goal ... | {"functional": "_inputs = [[[6, 4], [1, 2]], [[1], [0]], [[1, 2, 3, 4, 5], [0, 1, 2, 3, 4]], [[3, 4, 3], [1, 1, 2]], [[4, 3, 4], [1, 1, 1]]]\n_outputs = [[1], [0], [4], [2], [1]]\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=... | 405 | 247 |
coding | Solve the programming task below in a Python markdown code block.
Chef is interested to solve series problems. Chef wants to solve a series problem but he can't
solve it till now.Can you help Chef to solve the series problem?
- In series problem, the series goes as follows 1,9,31,73,141 . . . . . . . .
Your task is t... | {"inputs": ["2\n8\n10"], "outputs": ["561\n1081"]} | 271 | 24 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given two strings low and high that represent two integers low and high where low <= high, return the number of strobogrammatic numbers in the range [low, high].
A strobogrammatic number is a number that looks the sam... | {"functional": "def check(candidate):\n assert candidate(low = \"50\", high = \"100\") == 3\n assert candidate(low = \"0\", high = \"0\") == 1\n\n\ncheck(Solution().strobogrammaticInRange)"} | 116 | 59 |
coding | Solve the programming task below in a Python markdown code block.
Polycarpus has a sequence, consisting of n non-negative integers: a1, a2, ..., an.
Let's define function f(l, r) (l, r are integer, 1 ≤ l ≤ r ≤ n) for sequence a as an operation of bitwise OR of all the sequence elements with indexes from l to r. Formal... | {"inputs": ["1\n0\n", "1\n1\n", "1\n2\n", "1\n3\n", "1\n4\n", "1\n5\n", "1\n6\n", "1\n51\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n"]} | 517 | 87 |
coding | Solve the programming task below in a Python markdown code block.
There are some perfect squares with a particular property.
For example the number ```n = 256``` is a perfect square, its square root is ```16```. If we change the position of the digits of n, we may obtain another perfect square``` 625``` (square root = ... | {"functional": "_inputs = [[100, 2], [100, 3], [100, 4], [500, 2], [1000, 3], [100000, 4], [144, 2], [145, 2], [440, 2], [441, 2], [257, 2]]\n_outputs = [[441], [961], [81796], [625], [9216], [298116], [625], [625], [441], [625], [441]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinsta... | 409 | 304 |
coding | Solve the programming task below in a Python markdown code block.
On the Planet AtCoder, there are four types of bases: A, C, G and T. A bonds with T, and C bonds with G.
You are given a letter b as input, which is A, C, G or T. Write a program that prints the letter representing the base that bonds with the base b.
-... | {"inputs": ["C", "T", "C", "T", "G", "A", "A\n", "G\n"], "outputs": ["G\n", "A\n", "G\n", "A\n", "C", "T", "T\n", "C\n"]} | 142 | 62 |
coding | Solve the programming task below in a Python markdown code block.
You are given a tree with N nodes with every node being colored. A color is represented by an integer ranging from 1 to 10^{9}. Can you find the number of distinct colors available in a subtree rooted at the node s?
Input Format
The first line contai... | {"inputs": ["4 2 1\n1 2\n2 4\n2 3\n10\n20\n20\n30\n1\n2\n"], "outputs": ["3\n2\n"]} | 372 | 48 |
coding | Solve the programming task below in a Python markdown code block.
Watson gives Sherlock an array of integers. His challenge is to find an element of the array such that the sum of all elements to the left is equal to the sum of all elements to the right.
Example
$arr=[5,6,8,11]$
$8$ is between two subarrays t... | {"inputs": ["2\n3\n1 2 3\n4\n1 2 3 3\n", "3\n5\n1 1 4 1 1\n4\n2 0 0 0\n4\n0 0 2 0 \n"], "outputs": ["NO\nYES\n", "YES\nYES\nYES\n"]} | 536 | 79 |
coding | Solve the programming task below in a Python markdown code block.
The only difference between problems C1 and C2 is that all values in input of problem C1 are distinct (this condition may be false for problem C2).
You are given a sequence $a$ consisting of $n$ integers.
You are making a sequence of moves. During each... | {"inputs": ["1\n1\n", "1\n1\n", "2\n1 1\n", "2\n2 1\n", "2\n1 2\n", "2\n1 1\n", "2\n1 2\n", "2\n2 1\n"], "outputs": ["1\nR\n", "1\nR\n", "1\nR\n", "2\nRR\n", "2\nLR\n", "1\nR", "2\nLR\n", "2\nRR\n"]} | 568 | 113 |
coding | Solve the programming task below in a Python markdown code block.
Monocarp has arranged $n$ colored marbles in a row. The color of the $i$-th marble is $a_i$. Monocarp likes ordered things, so he wants to rearrange marbles in such a way that all marbles of the same color form a contiguos segment (and there is only one ... | {"inputs": ["2\n2 1\n", "2\n2 1\n", "2\n2 2\n", "2\n2 4\n", "2\n13 13\n", "2\n13 13\n", "6\n1 2 3 1 1 2\n", "6\n3 1 2 3 3 1\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "4\n", "4\n"]} | 598 | 122 |
coding | Solve the programming task below in a Python markdown code block.
For an array b of length m we define the function f as
f(b) = \begin{cases} b[1] & if m = 1 \\\ f(b[1] ⊕ b[2],b[2] ⊕ b[3],...,b[m-1] ⊕ b[m]) & otherwise, \end{cases}
where ⊕ is [bitwise exclusive OR](https://en.wikipedia.org/wiki/Bitwise_opera... | {"inputs": ["3\n5 4 1\n2\n2 3\n1 2\n", "3\n5 4 0\n2\n2 3\n1 2\n", "3\n2 4 0\n2\n2 3\n1 2\n", "3\n5 7 1\n2\n2 3\n1 2\n", "3\n2 4 1\n2\n2 3\n1 3\n", "3\n6 4 1\n2\n2 3\n1 3\n", "3\n8 8 1\n2\n2 3\n1 2\n", "3\n5 3 1\n2\n2 3\n1 2\n"], "outputs": ["5\n5\n", "4\n5\n", "4\n6\n", "7\n7\n", "5\n6\n", "5\n7\n", "9\n8\n", "3\n6\n"]... | 513 | 214 |
coding | Solve the programming task below in a Python markdown code block.
Iahub likes chess very much. He even invented a new chess piece named Coder. A Coder can move (and attack) one square horizontally or vertically. More precisely, if the Coder is located at position (x, y), he can move to (or attack) positions (x + 1, y),... | {"inputs": ["2\n", "3\n", "4\n", "1\n", "3\n", "4\n", "1\n", "6\n"], "outputs": ["2\nC.\n.C\n", "5\nC.C\n.C.\nC.C\n", "8\nC.C.\n.C.C\nC.C.\n.C.C\n", "1\nC\n", "5\nC.C\n.C.\nC.C\n", "8\nC.C.\n.C.C\nC.C.\n.C.C\n", "1\nC\n", "18\nC.C.C.\n.C.C.C\nC.C.C.\n.C.C.C\nC.C.C.\n.C.C.C\n"]} | 244 | 153 |
coding | Solve the programming task below in a Python markdown code block.
Read problems statements in Mandarin Chinese and Russian.
Chef wants to hire a new assistant. He published an advertisement regarding that in a newspaper. After seeing the advertisement, many candidates have applied for the job. Now chef wants to shor... | {"inputs": ["2\n1\n2", "2\n1\n3", "2\n2\n3", "2\n2\n5", "2\n2\n2", "2\n2\n1", "2\n4\n5", "2\n4\n1"], "outputs": ["1\n3", "1\n4\n", "3\n4\n", "3\n6\n", "3\n3\n", "3\n1\n", "7\n6\n", "7\n1\n"]} | 384 | 109 |
coding | Solve the programming task below in a Python markdown code block.
You'll be given a string, and have to return the total of all the unicode characters as an int. Should be able to handle any characters sent at it.
examples:
uniTotal("a") == 97
uniTotal("aaa") == 291
Also feel free to reuse/extend the following start... | {"functional": "_inputs = [['a'], ['b'], ['c'], [''], ['aaa'], ['abc'], ['Mary Had A Little Lamb'], ['Mary had a little lamb'], ['CodeWars rocks'], ['And so does Strive']]\n_outputs = [[97], [98], [99], [0], [291], [294], [1873], [2001], [1370], [1661]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, ... | 91 | 241 |
coding | Solve the programming task below in a Python markdown code block.
Dhiraj loves Chocolates.He loves chocolates so much that he can eat up to $1000$ chocolates a day. But his mom is fed up by this habit of him and decides to take things in her hand.
Its diwali Season and Dhiraj has got a lot of boxes of chocolates and Dh... | {"inputs": ["2\n20\n5\n8 7 2 10 5\n11\n4\n6 8 2 10"], "outputs": ["1\n0"]} | 490 | 44 |
coding | Solve the programming task below in a Python markdown code block.
The Little Elephant very much loves sums on intervals.
This time he has a pair of integers l and r (l ≤ r). The Little Elephant has to find the number of such integers x (l ≤ x ≤ r), that the first digit of integer x equals the last one (in decimal nota... | {"inputs": ["2 2\n", "1 2\n", "4 7\n", "7 8\n", "1 1\n", "2 3\n", "1 10\n", "5 45\n"], "outputs": ["1\n", "2\n", "4\n", "2\n", "1\n", "2\n", "9\n", "9\n"]} | 305 | 88 |
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.
Chef has a combination lock with $N$ wheels (numbered $1$ through $N$). For each valid $i$, on the $i$-th wheel, the integers from $0$ to $A_{i}$ (in... | {"inputs": ["3\n2\n2 2\n2\n5 5\n3\n3 4 5"], "outputs": ["443664157\n221832079\n598946612"]} | 718 | 60 |
coding | Solve the programming task below in a Python markdown code block.
Game "Minesweeper 1D" is played on a line of squares, the line's height is 1 square, the line's width is n squares. Some of the squares contain bombs. If a square doesn't contain a bomb, then it contains a number from 0 to 2 — the total number of bombs i... | {"inputs": ["?\n", "1\n", "0\n", "2\n", "*\n", "0\n", "*\n", "2\n"], "outputs": ["2\n", "0\n", "1\n", "0\n", "1\n", "1\n", "1\n", "0\n"]} | 489 | 70 |
coding | Solve the programming task below in a Python markdown code block.
Vasya has n items lying in a line. The items are consecutively numbered by numbers from 1 to n in such a way that the leftmost item has number 1, the rightmost item has number n. Each item has a weight, the i-th item weights wi kilograms.
Vasya needs to... | {"inputs": ["2 3 4 5 6\n1 2\n", "2 3 1 5 6\n1 2\n", "2 1 1 5 6\n1 2\n", "2 1 1 5 1\n1 3\n", "2 1 1 5 1\n1 2\n", "2 1 1 5 1\n2 3\n", "3 4 2 19 0\n5 3 99\n", "3 4 2 19 0\n2 3 99\n"], "outputs": ["11\n", "5\n", "3\n", "4\n", "3\n", "5\n", "214\n", "208\n"]} | 578 | 179 |
coding | Solve the programming task below in a Python markdown code block.
An uppercase or lowercase English letter \alpha will be given as input.
If \alpha is uppercase, print A; if it is lowercase, print a.
-----Constraints-----
- \alpha is an uppercase (A - Z) or lowercase (a - z) English letter.
-----Input-----
Input is ... | {"inputs": ["b", "C", "`", "D", "c", "E", "d", "F"], "outputs": ["a\n", "A\n", "a\n", "A\n", "a\n", "A\n", "a\n", "A\n"]} | 126 | 61 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.