task_type stringclasses 4
values | problem stringlengths 14 5.23k | solution stringlengths 1 8.29k | problem_tokens int64 9 1.02k | solution_tokens int64 1 1.98k |
|---|---|---|---|---|
coding | Solve the programming task below in a Python markdown code block.
You have $2n$ integers $1, 2, \dots, 2n$. You have to redistribute these $2n$ elements into $n$ pairs. After that, you choose $x$ pairs and take minimum elements from them, and from the other $n - x$ pairs, you take maximum elements.
Your goal is to obt... | {"inputs": ["3\n1\n1\n5\n2 3 5 7 8\n2\n2 4\n", "3\n1\n1\n5\n2 4 5 7 8\n2\n1 2\n", "3\n1\n1\n5\n2 4 5 6 8\n2\n1 2\n", "3\n1\n2\n5\n3 4 5 7 9\n2\n2 4\n", "3\n1\n1\n5\n2 4 5 7 9\n2\n1 4\n", "3\n1\n1\n5\n1 4 5 7 8\n2\n1 2\n", "3\n1\n2\n5\n1 4 5 7 8\n2\n1 2\n", "3\n1\n1\n5\n1 4 5 7 9\n2\n1 4\n"], "outputs": ["1\n3\n2\n", "1... | 729 | 278 |
coding | Solve the programming task below in a Python markdown code block.
An onion array is an array that satisfies the following condition for all values of `j` and `k`:
If all of the following are `true`:
* `j >= 0`
* `k >= 0`
* `j + k = array.length - 1`
* `j != k`
then:
* `a[j] + a[k] <= 10`
### Examples:
```
[1, 2... | {"functional": "_inputs = [[[6, 0, 4]], [[1, 1, 15, 10, -1]]]\n_outputs = [[True], [False]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) != len(b): r... | 274 | 182 |
coding | Solve the programming task below in a Python markdown code block.
There are N people numbered 1 to N. Each of them is either an honest person whose testimonies are always correct or an unkind person whose testimonies may be correct or not.
Person i gives A_i testimonies. The j-th testimony by Person i is represented by... | {"inputs": ["1\n0\n", "2\n1\n2 0\n1\n1 1", "2\n1\n2 0\n0\n1 0", "2\n1\n2 0\n0\n2 0", "2\n1\n2 0\n0\n0 0", "2\n1\n2 0\n0\n0 1", "2\n1\n2 1\n1\n1 1", "2\n1\n2 1\n1\n1 0"], "outputs": ["1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "2\n", "1\n"]} | 449 | 149 |
coding | Solve the programming task below in a Python markdown code block.
Read problem statements in [Russian], [Mandarin Chinese], [Bengali], and [Vietnamese] as well.
There are three distinct points - A, B, C in the X-Y plane. Initially, you are located at point A. You want to reach the point C satisfying the following cond... | {"inputs": ["4\n1 1\n1 3\n3 3\n0 0\n2 2\n3 4\n5 2\n3 2\n1 2\n1 1\n-1 1\n10000 10000\n"], "outputs": ["YES\nNO\nYES\nNO"]} | 746 | 76 |
coding | Solve the programming task below in a Python markdown code block.
Let's call a string a phone number if it has length 11 and fits the pattern "8xxxxxxxxxx", where each "x" is replaced by a digit.
For example, "80123456789" and "80000000000" are phone numbers, while "8012345678" and "79000000000" are not.
You have $n$... | {"inputs": ["1\n0\n", "1\n8\n", "1\n8\n", "1\n0\n", "1\n1\n", "1\n2\n", "8\n12345678\n", "8\n12345678\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]} | 465 | 100 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a 2D integer array items where items[i] = [pricei, beautyi] denotes the price and beauty of an item respectively.
You are also given a 0-indexed integer array queries. For each queries[j], you want to de... | {"functional": "def check(candidate):\n assert candidate(items = [[1,2],[3,2],[2,4],[5,6],[3,5]], queries = [1,2,3,4,5,6]) == [2,4,5,5,6,6]\n assert candidate(items = [[1,2],[1,2],[1,3],[1,4]], queries = [1]) == [4]\n assert candidate(items = [[10,1000]], queries = [5]) == [0]\n\n\ncheck(Solution().maximumBeau... | 165 | 131 |
coding | Solve the programming task below in a Python markdown code block.
After his wife's tragic death, Eurydice, Orpheus descended to the realm of death to see her. Reaching its gates was uneasy, but passing through them proved to be even more challenging. Mostly because of Cerberus, the three-headed hound of Hades.
Orpheus... | {"inputs": ["7\nbabba\nabaac\ncodeforces\nzeroorez\nabcdcba\nbbbbbbb\na\n", "7\nabbab\nabaac\ncodeforces\nzeroorez\nabcdcba\nbbbbbbb\na\n", "7\nabbab\nabaac\ncodeforces\nzeroorez\nabadcbc\nbbbbbbb\na\n", "7\nabbab\nabaac\ncodeforces\nzeroorez\nabadcbc\nbbbbabb\na\n", "7\nbbbaa\nabaac\ncodeforces\nyeroorez\nabadcbc\nbba... | 619 | 351 |
coding | Solve the programming task below in a Python markdown code block.
You are given a square grid with $n$ rows and $n$ columns. Each cell contains either $0$ or $1$.
In an operation, you can select a cell of the grid and flip it (from $0 \to 1$ or $1 \to 0$). Find the minimum number of operations you need to obtain a squ... | {"inputs": ["5\n3\n010\n110\n010\n1\n0\n5\n11100\n11011\n01011\n10011\n11000\n5\n01000\n10101\n01010\n00010\n01001\n5\n11001\n00000\n11111\n10110\n01111\n"], "outputs": ["1\n0\n9\n7\n6\n"]} | 536 | 136 |
coding | Solve the programming task below in a Python markdown code block.
Read problems statements in Russian.
Chef has prepared a feast with N dishes for you. You like Chef's cooking, and so you want to eat all the dishes he has prepared for you. You are also given an array A of size N, where A_{i} represents the happiness ... | {"inputs": ["1\n3\n1 2 3", "1\n3\n-8 0 -2"], "outputs": ["18", "-10"]} | 455 | 37 |
coding | Solve the programming task below in a Python markdown code block.
# Task
We know that some numbers can be split into two primes. ie. `5 = 2 + 3, 10 = 3 + 7`. But some numbers are not. ie. `17, 27, 35`, etc..
Given a positive integer `n`. Determine whether it can be split into two primes. If yes, return the maximum pr... | {"functional": "_inputs = [[1], [3], [4], [5], [6], [7], [8], [9], [10], [11], [12], [20], [100]]\n_outputs = [[0], [0], [4], [6], [9], [10], [15], [14], [25], [0], [35], [91], [2491]]\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, re... | 311 | 242 |
coding | Solve the programming task below in a Python markdown code block.
2N players are running a competitive table tennis training on N tables numbered from 1 to N.
The training consists of rounds. In each round, the players form N pairs, one pair per table. In each pair, competitors play a match against each other. As a re... | {"inputs": ["4 2 3", "5 2 8", "6 3 3", "6 3 5", "1 2 5", "0 3 4", "1 3 8", "5 2 3"], "outputs": ["2\n", "3\n", "0\n", "1\n", "-2\n", "-3\n", "-4\n", "2"]} | 312 | 93 |
coding | Solve the programming task below in a Python markdown code block.
Takahashi is playing with N cards.
The i-th card has an integer X_i on it.
Takahashi is trying to create as many pairs of cards as possible satisfying one of the following conditions:
* The integers on the two cards are the same.
* The sum of the inte... | {"inputs": ["7 5\n3 1 4 1 5 9 3", "7 5\n3 1 4 1 5 8 3", "7 8\n4 2 5 1 5 9 3", "7 5\n3 1 4 1 5 4 3", "7 1\n3 1 4 1 5 4 3", "7 1\n4 1 4 1 5 4 3", "7 1\n6 1 4 1 5 4 3", "7 1\n6 0 4 1 5 4 3"], "outputs": ["3\n", "2\n", "1\n", "3\n", "3\n", "3\n", "3\n", "3\n"]} | 261 | 190 |
coding | Solve the programming task below in a Python markdown code block.
Welcome to PC Koshien, players. Physical condition management is important to participate in the event. It is said that at the turn of the season when the temperature fluctuates greatly, it puts a strain on the body and it is easy to catch a cold. The da... | {"inputs": ["42 25\n3 -2\n62 0\n2 30\n0 4\n0 0\n27 -2", "42 25\n3 -2\n62 0\n2 30\n0 2\n0 0\n27 -2", "42 25\n5 -1\n118 0\n2 9\n1 2\n-1 0\n5 -2", "42 25\n5 -1\n118 0\n2 9\n1 2\n-2 0\n5 -2", "42 25\n5 -1\n142 0\n2 9\n1 2\n-2 0\n5 -2", "42 25\n5 -1\n142 0\n2 9\n1 2\n-2 0\n5 -4", "42 25\n5 -1\n142 0\n2 9\n1 3\n-2 0\n5 -4", ... | 301 | 454 |
coding | Solve the programming task below in a Python markdown code block.
# Story&Task
The capital of Berland has n multifloor buildings. The architect who built up the capital was very creative, so all houses in the city were built in one row.
Let's enumerate all the houses from left to right, starting with 0. A house is c... | {"functional": "_inputs = [[[1, 2, 3, 1, 2]], [[3, 2, 1, 4]], [[1, 2, 3]], [[3, 2, 1]], [[1, 1, 1]]]\n_outputs = [[[3, 2, 0, 2, 0]], [[2, 3, 4, 0]], [[3, 2, 0]], [[0, 0, 0]], [[1, 1, 0]]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b,... | 466 | 257 |
coding | Solve the programming task below in a Python markdown code block.
Two players are playing a game. The game is played on a sequence of positive integer pairs. The players make their moves alternatively. During his move the player chooses a pair and decreases the larger integer in the pair by a positive multiple of the s... | {"inputs": ["3\n1\n2 3\n2\n4 5\n5 6\n2\n2 3\n3 5", "3\n1\n2 3\n2\n4 5\n5 6\n2\n2 3\n1 5", "3\n1\n2 3\n2\n4 5\n5 6\n1\n2 3\n3 5", "3\n1\n1 3\n2\n6 5\n5 6\n1\n2 6\n5 5", "3\n1\n2 3\n2\n4 5\n5 3\n1\n2 3\n3 5", "3\n1\n2 3\n2\n6 2\n5 6\n1\n2 6\n3 5", "3\n1\n2 1\n2\n6 5\n5 6\n1\n2 3\n1 5", "3\n1\n2 1\n2\n6 5\n5 3\n1\n2 3\n1 ... | 513 | 301 |
coding | Solve the programming task below in a Python markdown code block.
-----Input-----
The first line contains a single integer n (1 ≤ n ≤ 1000) — the number of points on a plane.
Each of the next n lines contains two real coordinates x_{i} and y_{i} of the $i^{\text{th}}$ point, specified with exactly 2 fractional digits... | {"inputs": ["1\n1.00 1.01\n", "1\n0.00 0.01\n", "1\n0.00 0.01\n", "1\n1.00 1.01\n", "1\n792.52 879.16\n", "1\n792.52 879.16\n", "1\n1000.00 999.99\n", "1\n1000.00 999.99\n"], "outputs": ["6.010\n", "5.010\n", "5.010", "6.010", "884.160\n", "884.160", "1004.990\n", "1004.990"]} | 655 | 206 |
coding | Solve the programming task below in a Python markdown code block.
Today is August 24, one of the five Product Days in a year.
A date m-d (m is the month, d is the date) is called a Product Day when d is a two-digit number, and all of the following conditions are satisfied (here d_{10} is the tens digit of the day and ... | {"inputs": ["0 1", "0 0", "1 0", "2 0", "9 1", "9 0", "2 1", "4 0"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]} | 301 | 78 |
coding | Solve the programming task below in a Python markdown code block.
A triple of numbers is said to be poor when two of those numbers are equal but the other number is different from those two numbers.
You will be given three integers A, B, and C. If this triple is poor, print Yes; otherwise, print No.
-----Constraints--... | {"inputs": ["2 3 4", "1 4 4", "7 9 6", "4 3 4", "1 4 8", "7 4 6", "4 5 4", "0 4 8"], "outputs": ["No\n", "Yes\n", "No\n", "Yes\n", "No\n", "No\n", "Yes\n", "No\n"]} | 162 | 94 |
coding | Solve the programming task below in a Python markdown code block.
Did you know that there are over 40,000 varieties of Rice in the world ? There are so many dishes that can be prepared with Rice too. A famous chef from Mumbai, Tid Gusto prepared a new dish and named it 'Tid Rice'. He posted the recipe in his newly desi... | {"inputs": ["3\n4\ntilak +\ntilak +\ntilak -\ntilak +\n3\nratna +\nshashi -\nratna -\n3\nbhavani -\nbhavani +\nbhavani -"], "outputs": ["1\n-2\n-1"]} | 602 | 77 |
coding | Solve the programming task below in a Python markdown code block.
itertools.combinations(iterable, r)
This tool returns the $\textbf{r}$ length subsequences of elements from the input iterable.
Combinations are emitted in lexicographic sorted order. So, if the input iterable is sorted, the combination tuples will be... | {"inputs": ["HACK 2\n"], "outputs": ["A\nC\nH\nK\nAC\nAH\nAK\nCH\nCK\nHK\n"]} | 393 | 35 |
coding | Solve the programming task below in a Python markdown code block.
Let us call a pair of integer numbers m-perfect, if at least one number in the pair is greater than or equal to m. Thus, the pairs (3, 3) and (0, 2) are 2-perfect while the pair (-1, 1) is not.
Two integers x, y are written on the blackboard. It is allo... | {"inputs": ["1 2 5\n", "0 1 8\n", "0 0 0\n", "0 0 1\n", "0 0 0\n", "0 0 1\n", "0 1 8\n", "0 0 0\n"], "outputs": ["2\n", "5\n", "0\n", "-1\n", "0\n", "-1\n", "5\n", "0\n"]} | 401 | 102 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given the root of a binary tree and an integer limit, delete all insufficient nodes in the tree simultaneously, and return the root of the resulting binary tree.
A node is insufficient if every root to leaf path inter... | {"functional": "def check(candidate):\n assert is_same_tree(candidate(root = tree_node([1,2,3,4,-99,-99,7,8,9,-99,-99,12,13,-99,14]), limit = 1), tree_node([1,2,3,4,None,None,7,8,9,None,14]))\n assert is_same_tree(candidate(root = tree_node([5,4,8,11,None,17,4,7,1,None,None,5,3]), limit = 22), tree_node([5,4,8,11... | 168 | 208 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a 0-indexed m x n binary matrix land where a 0 represents a hectare of forested land and a 1 represents a hectare of farmland.
To keep the land organized, there are designated rectangular areas of hectar... | {"functional": "def check(candidate):\n assert candidate(land = [[1,0,0],[0,1,1],[0,1,1]]) == [[0,0,0,0],[1,1,2,2]]\n assert candidate(land = [[1,1],[1,1]]) == [[0,0,1,1]]\n assert candidate(land = [[0]]) == []\n\n\ncheck(Solution().findFarmland)"} | 299 | 105 |
coding | Solve the programming task below in a Python markdown code block.
Given a set of $N$ axis-aligned rectangular seals, find the number of overlapped seals on the region which has the maximum number of overlapped seals.
Constraints
* $ 1 \leq N \leq 100000 $
* $ 0 \leq x1_i < x2_i \leq 1000 $
* $ 0 \leq y1_i < y2_i \leq... | {"inputs": ["2\n0 0 2 2\n2 0 4 4", "2\n0 0 3 2\n2 1 4 2", "2\n0 0 0 1\n2 2 4 2", "2\n0 0 3 1\n2 1 4 3", "2\n0 0 3 1\n2 1 4 2", "2\n0 0 3 1\n2 1 4 4", "2\n0 0 2 2\n2 0 2 2", "2\n0 0 3 1\n2 1 2 3"], "outputs": ["1\n", "2\n", "0\n", "1\n", "1\n", "1\n", "1\n", "1\n"]} | 354 | 190 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given an array points where points[i] = [xi, yi] is the coordinates of the ith point on a 2D plane. Multiple points can have the same coordinates.
You are also given an array queries where queries[j] = [xj, yj... | {"functional": "def check(candidate):\n assert candidate(points = [[1,3],[3,3],[5,3],[2,2]], queries = [[2,3,1],[4,3,1],[1,1,2]]) == [3,2,2]\n assert candidate(points = [[1,1],[2,2],[3,3],[4,4],[5,5]], queries = [[1,2,2],[2,2,2],[4,3,2],[4,3,3]]) == [2,3,2,4]\n\n\ncheck(Solution().countPoints)"} | 181 | 135 |
coding | Solve the programming task below in a Python markdown code block.
The winter in Berland lasts n days. For each day we know the forecast for the average air temperature that day.
Vasya has a new set of winter tires which allows him to drive safely no more than k days at any average air temperature. After k days of usi... | {"inputs": ["1 0\n1\n", "1 0\n0\n", "1 1\n1\n", "1 0\n0\n", "1 1\n1\n", "1 0\n1\n", "1 1\n0\n", "1 1\n2\n"], "outputs": ["0\n", "0\n", "0\n", "0", "0", "0", "0\n", "0\n"]} | 604 | 99 |
coding | Solve the programming task below in a Python markdown code block.
There are $N$ buckets numbered $1$ through $N$. The buckets contain balls; each ball has a color between $1$ and $K$. Let's denote the number of balls with color $j$ that are initially in bucket $i$ by $a_{i, j}$.
For each $i$ from $1$ to $N-1$ (in this ... | {"inputs": ["2 2\n0 1\n1 1"], "outputs": ["0.333333 0.666667"]} | 469 | 38 |
coding | Solve the programming task below in a Python markdown code block.
You are given a sequence $a$ consisting of $n$ integers $a_1, a_2, \dots, a_n$, and an integer $x$. Your task is to make the sequence $a$ sorted (it is considered sorted if the condition $a_1 \le a_2 \le a_3 \le \dots \le a_n$ holds).
To make the sequen... | {"inputs": ["3\n5 1\n5 21 8 7 9\n6 3\n2 3 7 2 18 7\n8 7\n2 21 9 7 7 14 2 3\n", "3\n5 1\n5 21 8 7 9\n6 3\n2 3 7 2 18 7\n8 7\n2 11 9 7 7 14 2 3\n", "3\n5 1\n5 21 8 7 9\n6 3\n2 3 7 2 18 7\n8 7\n2 11 9 7 7 14 3 3\n", "3\n5 1\n5 21 8 7 9\n6 3\n2 3 7 2 18 7\n8 7\n2 11 9 7 6 14 3 3\n", "3\n5 12\n5 15 8 7 9\n6 3\n2 3 7 2 18 7\... | 653 | 555 |
coding | Solve the programming task below in a Python markdown code block.
Chef is given a number in form of its binary representation S, having length N.
Determine if the number can be represented as a sum of exactly three non-negative powers of 2. Please refer to samples for further explanation.
Note that S will NOT contain... | {"inputs": ["4\n1\n1\n4\n1001\n5\n11001\n7\n1101101\n"], "outputs": ["NO\nYES\nYES\nNO\n"]} | 507 | 49 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given n points on a 2D plane where points[i] = [xi, yi], Return the widest vertical area between two points such that no points are inside the area.
A vertical area is an area of fixed-width extending infinitely along... | {"functional": "def check(candidate):\n assert candidate(points = [[8,7],[9,9],[7,4],[9,7]]) == 1\n assert candidate(points = [[3,1],[9,0],[1,0],[1,4],[5,3],[8,8]]) == 3\n\n\ncheck(Solution().maxWidthOfVerticalArea)"} | 140 | 82 |
coding | Solve the programming task below in a Python markdown code block.
Mishka is a little polar bear. As known, little bears loves spending their free time playing dice for chocolates. Once in a wonderful sunny morning, walking around blocks of ice, Mishka met her friend Chris, and they started playing the game.
Rules of t... | {"inputs": ["1\n1 1\n", "1\n1 1\n", "1\n1 0\n", "1\n2 1\n", "2\n6 1\n1 6\n", "2\n6 1\n1 8\n", "2\n6 1\n1 6\n", "3\n3 5\n2 1\n4 2\n"], "outputs": ["Friendship is magic!^^", "Friendship is magic!^^\n", "Mishka\n", "Mishka\n", "Friendship is magic!^^", "Friendship is magic!^^\n", "Friendship is magic!^^\n", "Mishka"]} | 539 | 153 |
coding | Solve the programming task below in a Python markdown code block.
A sequence a_1,a_2,... ,a_n is said to be /\/\/\/ when the following conditions are satisfied:
* For each i = 1,2,..., n-2, a_i = a_{i+2}.
* Exactly two different numbers appear in the sequence.
You are given a sequence v_1,v_2,...,v_n whose length i... | {"inputs": ["4\n3 2 3 2", "4\n4 1 3 2", "4\n4 1 3 0", "4\n4 1 3 1", "4\n4 1 6 1", "4\n4 0 6 1", "4\n4 0 9 1", "4\n8 0 9 1"], "outputs": ["0\n", "2\n", "2\n", "1\n", "1\n", "2\n", "2\n", "2\n"]} | 273 | 126 |
coding | Solve the programming task below in a Python markdown code block.
Tracy gives Charlie a [Directed Acyclic Graph] with N vertices. Among these N vertices, K vertices are *sources*, and L vertices are *sinks*.
Find out the maximum number of edges this graph can have.
Note:
A *source* is a vertex with no incoming edge.... | {"inputs": ["2\n3 1 1\n5 3 3\n"], "outputs": ["3\n4\n"]} | 479 | 28 |
coding | Solve the programming task below in a Python markdown code block.
Given two integers `a` and `b`, which can be positive or negative, find the sum of all the numbers between including them too and return it. If the two numbers are equal return `a` or `b`.
**Note:** `a` and `b` are not ordered!
## Examples
```python
g... | {"functional": "_inputs = [[0, 1], [1, 2], [5, -1], [505, 4], [321, 123], [0, -1], [-50, 0], [-1, -5], [-5, -5], [-505, 4], [-321, 123], [0, 0], [-5, -1], [5, 1], [-17, -17], [17, 17]]\n_outputs = [[1], [3], [14], [127759], [44178], [-1], [-1275], [-15], [-5], [-127755], [-44055], [0], [-15], [15], [-17], [17]]\nimport... | 378 | 336 |
coding | Solve the programming task below in a Python markdown code block.
After you had helped Fedor to find friends in the «Call of Soldiers 3» game, he stopped studying completely. Today, the English teacher told him to prepare an essay. Fedor didn't want to prepare the essay, so he asked Alex for help. Alex came to help and... | {"inputs": ["1\nR\n0\n", "1\nr\n0\n", "1\nR\n0\n", "1\nr\n0\n", "1\nQ\n0\n", "1\ns\n0\n", "1\nffff\n1\nffff r\n", "1\nffff\n1\nffff r\n"], "outputs": ["1 1\n", "1 1\n", "1 1\n", "1 1\n", "0 1\n", "0 1\n", "0 4\n", "0 4\n"]} | 565 | 124 |
coding | Solve the programming task below in a Python markdown code block.
On Unix system type files can be identified with the ls -l command which displays the type of the file in the first alphabetic letter of the file system permissions field. You can find more information about file type on Unix system on the [wikipedia pag... | {"functional": "_inputs = [['-rwxrwxrwx'], ['Drwxr-xr-x'], ['lrwxrw-rw-'], ['srwxrwxrwx']]\n_outputs = [['file'], ['door'], ['symlink'], ['socket']]\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 isin... | 289 | 195 |
coding | Solve the programming task below in a Python markdown code block.
Find the longest substring within a string that contains at most 2 unique characters.
```
substring("a") => "a"
substring("aaa") => "aaa"
substring("abacd") => "aba"
substring("abacddcd") => "cddcd"
substring("cefageaacceaccacca") => "accacca"
```
This... | {"functional": "_inputs = [[''], ['a'], ['aa'], ['aaa'], ['ab'], ['aba'], ['abc'], ['abcba'], ['bbacc'], ['ccddeeff'], ['bbacddddcdd'], ['abcddeejabbedsajaajjaajjajajajjajjaaacedajajaj'], ['aaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbccccccccccccccccccccddddddddddddddddddddeeeeeeeeeeeeeeeeeeeeffffffffffffffffffffgggggggggg... | 228 | 516 |
coding | Solve the programming task below in a Python markdown code block.
Harrenhal is the largest castle in the Seven Kingdoms and is the seat of House Whent in the Riverlands, on the north shore of the Gods Eye lake. Since the War of Conquest, however, it has become a dark and ruinous place.
(c) A Wiki of Ice and Fire
Now H... | {"inputs": ["1\nabbabaab\n\n"], "outputs": ["2"]} | 670 | 18 |
coding | Solve the programming task below in a Python markdown code block.
On Bertown's main street n trees are growing, the tree number i has the height of ai meters (1 ≤ i ≤ n). By the arrival of the President of Berland these trees were decided to be changed so that their heights formed a beautiful sequence. This means that ... | {"inputs": ["1\n511\n", "1\n909\n", "1\n587\n", "1\n645\n", "1\n637\n", "1\n731\n", "1\n211\n", "1\n2727\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]} | 465 | 103 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
The factorial of a positive integer n is the product of all positive integers less than or equal to n.
For example, factorial(10) = 10 * 9 * 8 * 7 * 6 * 5 * 4 * 3 * 2 * 1.
We make a clumsy factorial using the intege... | {"functional": "def check(candidate):\n assert candidate(4) == 7\n assert candidate(10) == 12\n\n\ncheck(Solution().clumsy)"} | 271 | 42 |
coding | Solve the programming task below in a Python markdown code block.
Katie, Kuro and Shiro are best friends. They have known each other since kindergarten. That's why they often share everything with each other and work together on some very hard problems.
Today is Shiro's birthday. She really loves pizza so she wants to... | {"inputs": ["3\n", "4\n", "0\n", "1\n", "2\n", "7\n", "8\n", "2\n"], "outputs": ["2", "5", "0", "1", "3", "4", "9", "3\n"]} | 394 | 63 |
coding | Solve the programming task below in a Python markdown code block.
Your job is to write a function that takes a string and a maximum number of characters per line and then inserts line breaks as necessary so that no line in the resulting string is longer than the specified limit.
If possible, line breaks should not spl... | {"functional": "_inputs = [['test', 7], ['hello world', 7], ['a lot of words for a single line', 10], ['this is a test', 4], ['a longword', 6], ['areallylongword', 6], ['aa', 3], ['aaa', 3], ['aaaa', 3], ['a a', 3], ['a aa', 3], ['a aaa', 3], ['a aaaa', 3], ['a aaaaa', 3], ['a a a', 3], ['a aa a', 3], ['a aaa a', 3], [... | 349 | 584 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given a string s and an integer k, reverse the first k characters for every 2k characters counting from the start of the string.
If there are fewer than k characters left, reverse all of them. If there are less than 2... | {"functional": "def check(candidate):\n assert candidate(s = \"abcdefg\", k = 2) == \"bacdfeg\"\n assert candidate(s = \"abcd\", k = 2) == \"bacd\"\n\n\ncheck(Solution().reverseStr)"} | 123 | 59 |
coding | Solve the programming task below in a Python markdown code block.
Write a program which reads an integer $S$ [second] and converts it to $h:m:s$ where $h$, $m$, $s$ denote hours, minutes (less than 60) and seconds (less than 60) respectively.
Constraints
* $0 \leq S \leq 86400$
Input
An integer $S$ is given in a li... | {"inputs": ["8", "6", "4", "2", "1", "3", "9", "0"], "outputs": ["0:0:8\n", "0:0:6\n", "0:0:4\n", "0:0:2\n", "0:0:1\n", "0:0:3\n", "0:0:9\n", "0:0:0\n"]} | 154 | 94 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given the root node of a binary search tree (BST) and a value to insert into the tree. Return the root node of the BST after the insertion. It is guaranteed that the new value does not exist in the original BS... | {"functional": "def check(candidate):\n assert is_same_tree(candidate(root = tree_node([4,2,7,1,3]), val = 5), tree_node([4,2,7,1,3,5]))\n assert is_same_tree(candidate(root = tree_node([40,20,60,10,30,50,70]), val = 25), tree_node([40,20,60,10,30,50,70,None,None,25]))\n assert is_same_tree(candidate(root = tr... | 190 | 181 |
coding | Solve the programming task below in a Python markdown code block.
Consider an array $a$ of length $n$ with elements numbered from $1$ to $n$. It is possible to remove the $i$-th element of $a$ if $gcd(a_i, i) = 1$, where $gcd$ denotes the greatest common divisor. After an element is removed, the elements to the right a... | {"inputs": ["2 3\n", "4 2\n", "4 6\n", "2 1\n", "17957 2\n", "300000 1\n", "2 1000000000000\n", "1337 424242424242\n"], "outputs": ["6\n", "26\n", "1494\n", "1\n", "653647969\n", "299999\n", "138131255\n", "119112628\n"]} | 672 | 154 |
coding | Solve the programming task below in a Python markdown code block.
Some scientists are working on protein recombination, and during their research, they have found a remarkable fact: there are 4 proteins in the protein ring that mutate after every second according to a fixed pattern. For simplicity, proteins are called ... | {"inputs": ["5 15\nAAAAD\n"], "outputs": ["DDDDA\n"]} | 583 | 22 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a string s consisting of digits and an integer k.
A round can be completed if the length of s is greater than k. In one round, do the following:
Divide s into consecutive groups of size k such that the ... | {"functional": "def check(candidate):\n assert candidate(s = \"11111222223\", k = 3) == \"135\"\n assert candidate(s = \"00000000\", k = 3) == \"000\"\n\n\ncheck(Solution().digitSum)"} | 218 | 76 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
In some array arr, the values were in arithmetic progression: the values arr[i + 1] - arr[i] are all equal for every 0 <= i < arr.length - 1.
A value from arr was removed that was not the first or last value in the ar... | {"functional": "def check(candidate):\n assert candidate(arr = [5,7,11,13]) == 9\n assert candidate(arr = [15,13,12]) == 14\n\n\ncheck(Solution().missingNumber)"} | 114 | 59 |
coding | Solve the programming task below in a Python markdown code block.
Chef Shifu wanted to celebrate the success of his new restaurant with all his employees. He was willing to host a party and he had decided the location of the party as well. However, Chef Shifu was a shy person and wanted to communicate with the least po... | {"inputs": ["2\n3 3\n1 2\n2 3\n1 3\n4 3\n1 2\n2 3\n3 4"], "outputs": ["1\n2"]} | 510 | 46 |
coding | Solve the programming task below in a Python markdown code block.
Count the number of labeled strongly connected digraphs with the given number of vertices.
Input Format
The first line contains $\mathbf{T}$, the number of queries.
Following are $\mathbf{T}$ lines. Each line contains one integer $N$, denoting the... | {"inputs": ["5\n1\n2\n3\n4\n1000\n"], "outputs": ["1\n1\n18\n1606\n871606913\n"]} | 199 | 47 |
coding | Solve the programming task below in a Python markdown code block.
In this problem you are to calculate the sum of all integers from 1 to n, but you should take all powers of two with minus in the sum.
For example, for n = 4 the sum is equal to - 1 - 2 + 3 - 4 = - 4, because 1, 2 and 4 are 2^0, 2^1 and 2^2 respective... | {"inputs": ["1\n4\n", "1\n8\n", "1\n2\n", "1\n3\n", "1\n6\n", "1\n5\n", "1\n7\n", "1\n16\n"], "outputs": ["-4\n", "6\n", "-3\n", "0\n", "7\n", "1\n", "14\n", "74\n"]} | 245 | 90 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
A perfect number is a positive integer that is equal to the sum of its positive divisors, excluding the number itself. A divisor of an integer x is an integer that can divide x evenly.
Given an integer n, return true ... | {"functional": "def check(candidate):\n assert candidate(num = 28) == True\n assert candidate(num = 7) == False\n\n\ncheck(Solution().checkPerfectNumber)"} | 105 | 43 |
coding | Solve the programming task below in a Python markdown code block.
Takahashi has N days of summer vacation.
His teacher gave him M summer assignments. It will take A_i days for him to do the i-th assignment.
He cannot do multiple assignments on the same day, or hang out on a day he does an assignment.
What is the maximu... | {"inputs": ["1 2\n0 1", "4 6\n2 0", "3 2\n7 4", "3 2\n7 8", "1 2\n7 8", "2 2\n7 8", "2 2\n6 8", "0 2\n6 8"], "outputs": ["0\n", "2\n", "-1\n", "-1\n", "-1\n", "-1\n", "-1\n", "-1\n"]} | 286 | 110 |
coding | Solve the programming task below in a Python markdown code block.
# Task
John is new to spreadsheets. He is well aware of rows and columns, but he is not comfortable with spreadsheets numbering system.
```
Spreadsheet Row Column
A1 R1C1
D5 R5C4
AA48 ... | {"functional": "_inputs = [['A1'], ['R1C1'], ['R5C4'], ['AA48'], ['BK12'], ['R12C63'], ['R85C26'], ['R31C78'], ['BZ31']]\n_outputs = [['R1C1'], ['A1'], ['D5'], ['R48C27'], ['R12C63'], ['BK12'], ['Z85'], ['BZ31'], ['R31C78']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float... | 295 | 259 |
coding | Solve the programming task below in a Python markdown code block.
Let's assume that v(n) is the largest prime number, that does not exceed n;
u(n) is the smallest prime number strictly greater than n.
Find $\sum_{i = 2}^{n} \frac{1}{v(i) u(i)}$.
-----Input-----
The first line contains integer t (1 ≤ t ≤ 500) —... | {"inputs": ["2\n2\n3\n", "2\n2\n3\n", "1\n649580447\n", "1\n649580447\n", "1\n642996383\n", "1\n577046292\n", "1\n564149555\n", "1\n512056728\n"], "outputs": ["1/6\n7/30\n", "1/6\n7/30\n", "421954771415489597/843909545429301074\n", "421954771415489597/843909545429301074\n", "413444317687254719/826888637946494782\n", "3... | 187 | 368 |
coding | Solve the programming task below in a Python markdown code block.
You are given four integer values $a$, $b$, $c$ and $m$.
Check if there exists a string that contains:
$a$ letters 'A';
$b$ letters 'B';
$c$ letters 'C';
no other letters;
exactly $m$ pairs of adjacent equal letters (exactly $m$ such positions $i$ ... | {"inputs": ["1\n2 1 4 4\n", "1\n1 1 4 4\n", "1\n1 1 1 46\n", "1\n1 1 1 46\n", "1\n1 1 2 46\n", "1\n1 1 2 55\n", "1\n1 1 3 55\n", "1\n1 2 3 55\n"], "outputs": ["YES\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n"]} | 378 | 140 |
coding | Solve the programming task below in a Python markdown code block.
You are given a permutation of the numbers 1, 2, ..., n and m pairs of positions (a_{j}, b_{j}).
At each step you can choose a pair from the given positions and swap the numbers in that positions. What is the lexicographically maximal permutation one ca... | {"inputs": ["1 1\n1\n1 1\n", "1 1\n1\n1 1\n", "3 1\n1 3 2\n1 2\n", "3 1\n3 2 1\n1 2\n", "3 1\n2 3 1\n1 1\n", "3 1\n3 2 1\n1 2\n", "3 1\n1 3 2\n1 2\n", "3 1\n2 3 1\n1 1\n"], "outputs": ["1\n", "1 \n", "3 1 2\n", "3 2 1\n", "2 3 1\n", "3 2 1 \n", "3 1 2 \n", "2 3 1 \n"]} | 374 | 186 |
coding | Solve the programming task below in a Python markdown code block.
Abhishek is fond of playing cricket very much. One morning, he is playing cricket with his friends. Abhishek is a right-hand batsman
.He has to face all types of balls either good or bad. There are total 26 balls in the game and each ball is represen... | {"inputs": ["2\nababab\nbgbbbbbbbbbbbbbbbbbbbbbbbb\n1\nacbacbacaa\nbbbbbbbbbbbbbbbbbbbbbbbbbb\n2"], "outputs": ["5\n8"]} | 673 | 43 |
coding | Solve the programming task below in a Python markdown code block.
Takahashi went to an all-you-can-eat buffet with N kinds of dishes and ate all of them (Dish 1, Dish 2, \ldots, Dish N) once.
The i-th dish (1 \leq i \leq N) he ate was Dish A_i.
When he eats Dish i (1 \leq i \leq N), he gains B_i satisfaction points.
Ad... | {"inputs": ["2\n2 1\n1 1\n1\n", "2\n1 0\n4 2\n56", "2\n1 0\n1 2\n56", "2\n1 0\n21 50\n2", "2\n1 0\n22 77\n2", "2\n1 0\n37 77\n2", "2\n1 0\n50 50\n50", "2\n1 0\n50 74\n56"], "outputs": ["2\n", "6\n", "3\n", "71\n", "99\n", "114\n", "100\n", "124\n"]} | 392 | 165 |
coding | Solve the programming task below in a Python markdown code block.
Recently Luba learned about a special kind of numbers that she calls beautiful numbers. The number is called beautiful iff its binary representation consists of k + 1 consecutive ones, and then k consecutive zeroes.
Some examples of beautiful numbers: ... | {"inputs": ["3\n", "1\n", "6\n", "9\n", "2\n", "5\n", "1\n", "5\n"], "outputs": ["1\n", "1\n", "6\n", "1\n", "1\n", "1\n", "1\n", "1\n"]} | 268 | 70 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a network of n nodes represented as an n x n adjacency matrix graph, where the ith node is directly connected to the jth node if graph[i][j] == 1.
Some nodes initial are initially infected by malware. Wh... | {"functional": "def check(candidate):\n assert candidate(graph = [[1,1,0],[1,1,0],[0,0,1]], initial = [0,1]) == 0\n assert candidate(graph = [[1,0,0],[0,1,0],[0,0,1]], initial = [0,2]) == 0\n assert candidate(graph = [[1,1,1],[1,1,1],[1,1,1]], initial = [1,2]) == 1\n\n\ncheck(Solution().minMalwareSpread)"} | 244 | 126 |
coding | Solve the programming task below in a Python markdown code block.
Takahashi is at an all-you-can-eat restaurant.
The restaurant offers N kinds of dishes. It takes A_i minutes to eat the i-th dish, whose deliciousness is B_i.
The restaurant has the following rules:
- You can only order one dish at a time. The dish orde... | {"inputs": ["2 60\n10 10\n60 100\n", "2 60\n10 13\n100 100", "2 60\n10 13\n100 101", "2 60\n10 10\n000 100", "2 60\n10 20\n100 101", "2 60\n10 30\n100 101", "2 60\n10 10\n100 100", "2 60\n10 10\n100 100\n"], "outputs": ["110\n", "113\n", "114\n", "110\n", "121\n", "131\n", "110", "110\n"]} | 378 | 214 |
coding | Solve the programming task below in a Python markdown code block.
G: Tree
problem
Given a tree consisting of N vertices. Each vertex of the tree is numbered from 1 to N. Of the N-1 edges, the i \ (= 1, 2, ..., N-1) edge connects the vertex u_i and the vertex v_i.
Write a program to find the number of K non-empty sub... | {"inputs": ["3 4\n1 2\n1 3", "3 2\n1 2\n2 3", "3 2\n2 2\n1 3", "3 1\n1 2\n2 3", "3 1\n1 2\n3 3", "1 2\n1 2\n2 3", "3 4\n1 2\n2 3", "1 1\n1 2\n2 3"], "outputs": ["0\n", "5\n", "1\n", "6\n", "3\n", "0\n", "0\n", "1\n"]} | 533 | 142 |
coding | Solve the programming task below in a Python markdown code block.
# Task
Given string `s`, which contains only letters from `a to z` in lowercase.
A set of alphabet is given by `abcdefghijklmnopqrstuvwxyz`.
2 sets of alphabets mean 2 or more alphabets.
Your task is to find the missing letter(s). You may need t... | {"functional": "_inputs = [['abcdefghijklmnopqrstuvwxy'], ['abcdefghijklmnopqrstuvwxyz'], ['aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyy'], ['abbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxy'], ['codewars']]\n_outputs = [['z'], [''], ['zz'], ['ayzz'], ['bfghijklmnpqtuvxyz']]\nimport math\ndef _deep_eq(a, b, tol=1... | 358 | 242 |
coding | Solve the programming task below in a Python markdown code block.
You are given a grid with $R$ rows (numbered $1$ through $R$) and $C$ columns (numbered $1$ through $C$). A cell in row $r$ and column $c$ is denoted by $(r, c)$. Two cells in the grid are adjacent if they have a common side. For each valid $i$ and $j$, ... | {"inputs": ["2\n3 3\n1 2 1\n2 3 2\n1 2 1\n3 4\n0 0 0 0\n0 0 0 0\n0 0 4 0"], "outputs": ["Stable\nUnstable"]} | 506 | 66 |
coding | Solve the programming task below in a Python markdown code block.
Let us consider a grid of squares with 10^9 rows and N columns. Let (i, j) be the square at the i-th column (1 \leq i \leq N) from the left and j-th row (1 \leq j \leq 10^9) from the bottom.
Snuke has cut out some part of the grid so that, for each i = ... | {"inputs": ["2\n4 2", "2\n2 2", "5\n2 1 2 1 2", "9\n3 3 5 4 1 2 4 2 1", "9\n2 3 7 4 1 2 4 2 1", "9\n2 3 4 4 1 2 4 2 1", "9\n2 3 2 4 1 2 4 2 1", "9\n2 3 2 4 1 2 4 2 2"], "outputs": ["24", "6", "256", "11520", "51200", "6400", "23040", "20736"]} | 462 | 184 |
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 | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given two 0-indexed integer permutations A and B of length n.
A prefix common array of A and B is an array C such that C[i] is equal to the count of numbers that are present at or before the index i in both A ... | {"functional": "def check(candidate):\n assert candidate(A = [1,3,2,4], B = [3,1,2,4]) == [0,2,3,4]\n assert candidate(A = [2,3,1], B = [3,1,2]) == [0,1,3]\n\n\ncheck(Solution().findThePrefixCommonArray)"} | 147 | 88 |
coding | Solve the programming task below in a Python markdown code block.
Madeline has an array $a$ of $n$ integers. A pair $(u, v)$ of integers forms an inversion in $a$ if:
$1 \le u < v \le n$. $a_u > a_v$.
Madeline recently found a magical paper, which allows her to write two indices $u$ and $v$ and swap the values $a... | {"inputs": ["1\n1\n", "1\n1\n", "1\n0\n", "1\n2\n", "1\n-1\n", "1\n-2\n", "1\n-3\n", "1\n-4\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]} | 598 | 90 |
coding | Solve the programming task below in a Python markdown code block.
We have N ID cards, and there are M gates.
We can pass the i-th gate if we have one of the following ID cards: the L_i-th, (L_i+1)-th, ..., and R_i-th ID cards.
How many of the ID cards allow us to pass all the gates alone?
-----Constraints-----
- All ... | {"inputs": ["1 1\n1 1\n", "4 2\n1 6\n2 4", "4 1\n1 4\n2 4", "4 2\n1 4\n2 4", "4 2\n1 0\n2 4", "4 2\n1 3\n2 0", "4 2\n0 6\n2 4", "4 2\n1 0\n2 6"], "outputs": ["1\n", "3\n", "4\n", "3\n", "0\n", "0\n", "3\n", "0\n"]} | 291 | 139 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an integer array nums and an integer k, return the number of pairs (i, j) where i < j such that |nums[i] - nums[j]| == k.
The value of |x| is defined as:
x if x >= 0.
-x if x < 0.
Please complete the followi... | {"functional": "def check(candidate):\n assert candidate(nums = [1,2,2,1], k = 1) == 4\n assert candidate(nums = [1,3], k = 3) == 0\n assert candidate(nums = [3,2,1,5,4], k = 2) == 3\n\n\ncheck(Solution().countKDifference)"} | 114 | 87 |
coding | Solve the programming task below in a Python markdown code block.
Vasya has the sequence consisting of n integers. Vasya consider the pair of integers x and y k-interesting, if their binary representation differs from each other exactly in k bits. For example, if k = 2, the pair of integers x = 5 and y = 3 is k-interes... | {"inputs": ["2 0\n1 1\n", "2 0\n0 0\n", "2 1\n0 1\n", "2 1\n0 2\n", "2 1\n0 1\n", "2 0\n1 1\n", "2 1\n0 2\n", "2 0\n0 0\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n"]} | 473 | 118 |
coding | Solve the programming task below in a Python markdown code block.
When you asked some guy in your class his name, he called himself S, where S is a string of length between 3 and 20 (inclusive) consisting of lowercase English letters. You have decided to choose some three consecutive characters from S and make it his n... | {"inputs": ["maohiro", "orihoam", "anphiro", "onphira", "arihpno", "nmpgira", "sgi`pmn", "nlp`igs"], "outputs": ["mao\n", "ori\n", "anp\n", "onp\n", "ari\n", "nmp\n", "sgi\n", "nlp\n"]} | 150 | 86 |
coding | Solve the programming task below in a Python markdown code block.
A binary string A is called *good* if it can be sorted (in non-decreasing order) using the following operation:
Select an i (1 ≤ i ≤ |A| - 1) and swap A_{i} with A_{i + 1}.
This operation can be performed on any i at most once.
For example, A = 10110 ... | {"inputs": ["2\n4\n0011\n6\n111000\n"], "outputs": ["10\n17\n"]} | 540 | 34 |
coding | Solve the programming task below in a Python markdown code block.
Did you know you can download more RAM? There is a shop with $n$ different pieces of software that increase your RAM. The $i$-th RAM increasing software takes $a_i$ GB of memory to run (temporarily, once the program is done running, you get the RAM back)... | {"inputs": ["1\n1 1000\n1000\n1000\n", "4\n3 10\n20 30 10\n9 100 10\n5 1\n1 1 5 1 1\n1 1 1 1 1\n5 1\n2 2 2 2 2\n100 100 100 100 100\n5 8\n128 64 32 16 8\n128 64 32 16 8\n"], "outputs": ["2000\n", "29\n6\n1\n256\n"]} | 608 | 166 |
coding | Solve the programming task below in a Python markdown code block.
Doremy's new city is under construction! The city can be regarded as a simple undirected graph with $n$ vertices. The $i$-th vertex has altitude $a_i$. Now Doremy is deciding which pairs of vertices should be connected with edges.
Due to economic reason... | {"inputs": ["4\n4\n2 2 3 1\n6\n5 2 3 1 5 2\n12\n7 2 4 9 1 4 6 3 7 4 2 3\n4\n1000000 1000000 1000000 1000000\n"], "outputs": ["3\n9\n35\n2\n"]} | 746 | 106 |
coding | Solve the programming task below in a Python markdown code block.
Given is an integer r.
How many times is the area of a circle of radius r larger than the area of a circle of radius 1?
It can be proved that the answer is always an integer under the constraints given.
-----Constraints-----
- 1 \leq r \leq 100
- All ... | {"inputs": ["2\n", "8\n", "1\n", "30\n", "27\n", "87\n", "22\n", "76\n"], "outputs": ["4\n", "64\n", "1\n", "900\n", "729\n", "7569\n", "484\n", "5776\n"]} | 187 | 88 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
A good meal is a meal that contains exactly two different food items with a sum of deliciousness equal to a power of two.
You can pick any two different foods to make a good meal.
Given an array of integers deliciousn... | {"functional": "def check(candidate):\n assert candidate(deliciousness = [1,3,5,7,9]) == 4\n assert candidate(deliciousness = [1,1,1,3,3,3,7]) == 15\n\n\ncheck(Solution().countPairs)"} | 160 | 68 |
coding | Solve the programming task below in a Python markdown code block.
You are given a range of positive integers from $l$ to $r$.
Find such a pair of integers $(x, y)$ that $l \le x, y \le r$, $x \ne y$ and $x$ divides $y$.
If there are multiple answers, print any of them.
You are also asked to answer $T$ independent qu... | {"inputs": ["1\n746 100000100\n", "3\n1 10\n3 14\n1 10\n", "3\n1 10\n3 14\n1 10\n", "3\n1 10\n5 14\n1 10\n", "3\n1 10\n9 20\n1 14\n", "3\n1 10\n3 10\n1 10\n", "3\n1 10\n5 14\n1 15\n", "3\n1 10\n5 14\n1 14\n"], "outputs": ["746 1492\n", "1 2\n3 6\n1 2\n", "1 2\n3 6\n1 2\n", "1 2\n5 10\n1 2\n", "1 2\n9 18\n1 2\n", "1 2\n... | 312 | 270 |
coding | Solve the programming task below in a Python markdown code block.
An n × n square matrix is special, if: it is binary, that is, each cell contains either a 0, or a 1; the number of ones in each row and column equals 2.
You are given n and the first m rows of the matrix. Print the number of special n × n matrices, s... | {"inputs": ["5 0 13\n", "5 0 13\n", "2 0 1000\n", "2 0 1000\n", "2 0 1010\n", "4 0 1100\n", "99 0 757\n", "2 0 1100\n"], "outputs": ["12\n", "12\n", "1\n", "1\n", "1\n", "90\n", "613\n", "1\n"]} | 347 | 127 |
coding | Solve the programming task below in a Python markdown code block.
Chef was driving on a highway at a speed of X km/hour.
To avoid accidents, there are fine imposed on overspeeding as follows:
No fine if the speed of the car ≤ 70 km/hour.
Rs 500 fine if the speed of the car is strictly greater than 70 and ≤ 100.
Rs 200... | {"inputs": ["7\n40\n110\n70\n100\n69\n101\n85\n"], "outputs": ["0\n2000\n0\n500\n0\n2000\n500\n"]} | 481 | 60 |
coding | Solve the programming task below in a Python markdown code block.
A jail has a number of prisoners and a number of treats to pass out to them. Their jailer decides the fairest way to divide the treats is to seat the prisoners around a circular table in sequentially numbered chairs. A chair number will be drawn from a... | {"inputs": ["2\n5 2 1\n5 2 2\n", "2\n7 19 2\n3 7 3\n"], "outputs": ["2\n3\n", "6\n3\n"]} | 722 | 51 |
coding | Solve the programming task below in a Python markdown code block.
Marc loves cupcakes, but he also likes to stay fit. Each cupcake has a calorie count, and Marc can walk a distance to expend those calories. If Marc has eaten $j$ cupcakes so far, after eating a cupcake with $\textbf{C}$ calories he must walk at least $... | {"inputs": ["3\n1 3 2\n", "4\n7 4 9 6\n"], "outputs": ["11\n", "79\n"]} | 632 | 38 |
coding | Solve the programming task below in a Python markdown code block.
In this kata, the number 0 is infected. You are given a list. Every turn, any item in the list that is adjacent to a 0 becomes infected and transforms into a 0. How many turns will it take for the whole list to become infected?
```
[0,1,1,0] ==> [0,0,0,... | {"functional": "_inputs = [[[0]], [[0, 1, 1, 0]], [[0, 1, 1, 1, 0]], [[1, 1, 0, 1, 1]], [[0, 1, 1, 1]], [[1, 1, 1, 0]]]\n_outputs = [[0], [1], [2], [2], [3], [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... | 254 | 238 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given an integer array nums where the largest integer is unique.
Determine whether the largest element in the array is at least twice as much as every other number in the array. If it is, return the index of t... | {"functional": "def check(candidate):\n assert candidate(nums = [3,6,1,0]) == 1\n assert candidate(nums = [1,2,3,4]) == -1\n\n\ncheck(Solution().dominantIndex)"} | 103 | 56 |
coding | Solve the programming task below in a Python markdown code block.
Can you imagine our life if we removed all zeros from it? For sure we will have many problems.
In this problem we will have a simple example if we removed all zeros from our life, it's the addition operation. Let's assume you are given this equation a +... | {"inputs": ["5\n4\n", "1\n1\n", "6\n4\n", "1\n6\n", "5\n1\n", "6\n3\n", "5\n2\n", "1\n10\n"], "outputs": ["YES\n", "YES\n", "NO\n", "YES\n", "YES\n", "YES\n", "YES\n", "NO\n"]} | 339 | 87 |
coding | Solve the programming task below in a Python markdown code block.
You have $n$ stacks of blocks. The $i$-th stack contains $h_i$ blocks and it's height is the number of blocks in it. In one move you can take a block from the $i$-th stack (if there is at least one block) and put it to the $i + 1$-th stack. Can you make ... | {"inputs": ["1\n5\n1000000000 1000000000 1000000000 1000000000 0\n", "1\n5\n1000000000 1000000000 1000000000 1000000000 0\n", "1\n5\n1000000000 1000000000 1000000000 1000000000 1\n", "1\n5\n1000000000 1000000010 1000000000 1000000000 1\n", "1\n5\n1000000000 1000000010 1000001000 1000000000 1\n", "1\n5\n1000000000 10000... | 581 | 454 |
coding | Solve the programming task below in a Python markdown code block.
A sequence a=\{a_1,a_2,a_3,......\} is determined as follows:
- The first term s is given as input.
- Let f(n) be the following function: f(n) = n/2 if n is even, and f(n) = 3n+1 if n is odd.
- a_i = s when i = 1, and a_i = f(a_{i-1}) when i > 1.
Find... | {"inputs": ["2", "6", "5", "9", "8", "7", "8\n", "7\n"], "outputs": ["4\n", "10\n", "7\n", "21\n", "5", "18", "5\n", "18\n"]} | 276 | 66 |
coding | Solve the programming task below in a Python markdown code block.
The numbers 12, 63 and 119 have something in common related with their divisors and their prime factors, let's see it.
```
Numbers PrimeFactorsSum(pfs) DivisorsSum(ds) Is ds divisible by pfs
12 2 + 2 + 3 = 7 1 + 2 + 3 ... | {"functional": "_inputs = [[10, 100], [20, 120], [50, 140]]\n_outputs = [[[12, 15, 35, 42, 60, 63, 66, 68, 84, 90, 95]], [[35, 42, 60, 63, 66, 68, 84, 90, 95, 110, 114, 119]], [[60, 63, 66, 68, 84, 90, 95, 110, 114, 119, 140]]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, fl... | 534 | 321 |
coding | Solve the programming task below in a Python markdown code block.
There are n cities in Berland and some pairs of them are connected by two-way roads. It is guaranteed that you can pass from any city to any other, moving along the roads. Cities are numerated from 1 to n.
Two fairs are currently taking place in Berland... | {"inputs": ["3\n7 7 3 5\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 5\n4 5 2 4\n1 2\n2 3\n3 4\n4 1\n4 2\n4 3 2 1\n1 2\n2 3\n4 1\n", "3\n7 7 3 5\n1 2\n2 3\n3 4\n2 5\n5 6\n6 7\n7 5\n4 5 2 4\n1 2\n2 3\n3 4\n4 1\n4 2\n4 3 2 1\n1 2\n2 3\n4 1\n", "3\n7 7 3 5\n1 2\n2 3\n1 4\n2 5\n5 6\n6 7\n7 5\n4 5 2 4\n1 2\n2 3\n3 4\n4 1\n4 2\n4 3 2 1\... | 611 | 774 |
coding | Solve the programming task below in a Python markdown code block.
Your task is to make a program takes in a sentence (without puncuation), adds all words to a list and returns the sentence as a string which is the positions of the word in the list. Casing should not matter too.
Example
-----
`"Ask not what your COUN... | {"functional": "_inputs = [['The bumble bee'], ['SILLY LITTLE BOYS silly little boys'], ['Ask not what your COUNTRY can do for you ASK WHAT YOU CAN DO FOR YOUR country'], ['The number 0 is such a strange number Strangely it has zero meaning']]\n_outputs = [['012'], ['012012'], ['01234567802856734'], ['012345617891011']... | 160 | 254 |
coding | Solve the programming task below in a Python markdown code block.
CODE FESTIVAL 2016 is going to be held. For the occasion, Mr. Takahashi decided to make a signboard.
He intended to write `CODEFESTIVAL2016` on it, but he mistakenly wrote a different string S. Fortunately, the string he wrote was the correct length.
S... | {"inputs": ["C0DEFESTIVAL2O61", "EDOC6102LAVITSEF", "C0DEFERTIVAL2O61", "C0DEGERTIVAL2O61", "CTDEGER0IVAL2O61", "CT/EGERDIVAL2O61", "CT0EGERDIVAK2O61", "1DO2LAVI6REGE0TC"], "outputs": ["4\n", "16\n", "5\n", "6\n", "7\n", "8\n", "9\n", "15\n"]} | 220 | 134 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You have a 1-indexed binary string of length n where all the bits are 0 initially. We will flip all the bits of this binary string (i.e., change them from 0 to 1) one by one. You are given a 1-indexed integer array fl... | {"functional": "def check(candidate):\n assert candidate(flips = [3,2,4,1,5]) == 2\n assert candidate(flips = [4,1,2,3]) == 1\n\n\ncheck(Solution().numTimesAllBlue)"} | 179 | 61 |
coding | Solve the programming task below in a Python markdown code block.
The Head Chef is receiving a lot of orders for cooking the best of the problems lately. For this, he organized an hiring event to hire some talented Chefs. He gave the following problem to test the skills of the participating Chefs. Can you solve this pr... | {"inputs": ["2\n2\n5\n\n"], "outputs": ["2\n8"]} | 756 | 20 |
coding | Solve the programming task below in a Python markdown code block.
Let's dive into the interesting topic of regular expressions! You are given some input, and you are required to check whether they are valid mobile numbers.
A valid mobile number is a ten digit number starting with a $7,8$ or $9$.
Concept
A valid ... | {"inputs": ["2\n9587456281\n1252478965\n"], "outputs": ["YES\nNO\n"]} | 269 | 38 |
coding | Solve the programming task below in a Python markdown code block.
You are given a bracket sequence consisting of $n$ characters '(' and/or )'. You perform several operations with it.
During one operation, you choose the shortest prefix of this string (some amount of first characters of the string) that is good and rem... | {"inputs": ["1\n14\n()(((())((()))\n", "1\n15\n((((()))))(((((\n", "1\n16\n((((()))))((((((\n", "1\n18\n()()())(())(())(()\n", "5\n2\n()\n3\n())\n4\n((((\n5\n)((()\n6\n)((()(\n", "5\n3\n)()\n8\n)()()(((\n4\n(()(\n5\n(())(\n6\n))((()\n", "8\n3\n)()\n8\n)()()(((\n4\n(()(\n5\n(())(\n6\n))((()\n5\n))())\n1\n)\n2\n)(\n"], "... | 508 | 279 |
coding | Solve the programming task below in a Python markdown code block.
The trafic on the Internet is increasing these days due to smartphones. The wireless carriers have to enhance their network infrastructure.
The network of a wireless carrier consists of a number of base stations and lines. Each line connects two base st... | {"inputs": ["3 3\n1 2 x+2\n2 2 2x+1\n3 1 x+1\n2 0\n3 2\n1 2 x\n2 3 2\n4 3\n1 2 x^3+2x^2+3x+4\n2 3 x^2+2x+3\n3 4 x+2\n0 0", "3 3\n1 2 x+2\n2 2 2x+1\n3 1 x+1\n2 0\n3 2\n1 2 x\n2 3 1\n4 3\n1 2 x^3+2x^2+3x+4\n2 3 x^2+2x+3\n3 4 x+2\n0 0", "3 3\n1 2 x+2\n2 2 2x+1\n3 1 x+1\n2 0\n3 2\n1 2 x\n2 3 4\n4 3\n1 2 x^3+2x^2+3x+4\n2 3 ... | 729 | 841 |
coding | Solve the programming task below in a Python markdown code block.
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well.
Chef has a machine which he uses to rotate sequences. If he puts a sequence $S_{1}, S_{2}, \ldots, S_{N}$ into the machine, it produces the sequence... | {"inputs": ["1\n4\n-5 4 1 2"], "outputs": ["7 7 4 5"]} | 703 | 29 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given a binary string s without leading zeros, return true if s contains at most one contiguous segment of ones. Otherwise, return false.
Please complete the following python code precisely:
```python
class ... | {"functional": "def check(candidate):\n assert candidate(s = \"1001\") == False\n assert candidate(s = \"110\") == True\n\n\ncheck(Solution().checkOnesSegment)"} | 81 | 48 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.