task_type stringclasses 1
value | problem stringlengths 209 3.39k | answer stringlengths 35 6.15k | problem_tokens int64 60 774 | answer_tokens int64 12 2.04k |
|---|---|---|---|---|
coding | Solve the programming task below in a Python markdown code block.
Given a set of N natural numbers 1,2,3........N and Q query.For each query you have to calculate the total number of subset in which Ith.
number of set come at Kth postion.Elements of every subset should be in sorted order.
The answer could be very l... | {"inputs": ["1\n3 3\n1 2\n2 1\n3 2"], "outputs": ["0\n2\n2"]} | 461 | 32 |
coding | Solve the programming task below in a Python markdown code block.
Your program will receive an array of complex numbers represented as strings. Your task is to write the `complexSum` function which have to return the sum as a string.
Complex numbers can be written in the form of `a+bi`, such as `2-3i` where `2` is th... | {"functional": "_inputs = [[['2+3i', '3-i']], [['2-3i', '3+i']], [['3', '-3+i']], [[]], [['3+4i']], [['123+456i']], [['0']], [['-i']], [['1', '1']], [['-5', '5']], [['1', '10', '100', '1000']], [['5+4i', '11+3i']], [['-2-4i', '-8+6i']], [['-1-i', '7+10i']], [['3+4i', '3-4i']], [['10+i', '10-i', '9']], [['2+3i', '0', '0... | 272 | 616 |
coding | Solve the programming task below in a Python markdown code block.
You are given two strings $s$ and $t$, both consisting only of lowercase Latin letters.
The substring $s[l..r]$ is the string which is obtained by taking characters $s_l, s_{l + 1}, \dots, s_r$ without changing the order.
Each of the occurrences of str... | {"inputs": ["1 1 1\na\na\n1 1\n", "1 1 1\na\nb\n1 1\n", "1 1 1\na\nb\n1 1\n", "1 1 1\na\na\n1 1\n", "1 2 1\na\nb\n1 1\n", "1 2 1\na\nb\n1 0\n", "1 1 1\na\nb\n1 0\n", "1 4 1\na\nb\n1 1\n"], "outputs": ["1\n", "0\n", "0\n", "1\n", "0\n", "0\n", "0\n", "0\n"]} | 546 | 166 |
coding | Solve the programming task below in a Python markdown code block.
Read problems statements in Mandarin Chinese and Russian.
Alice and Bob, both have to drink water. But they both don't want to go, so they will play a game to decide who will fetch water for both of them. Alice will choose a number randomly between 1 ... | {"inputs": ["3\n1 1\n1 2\n2 3", "3\n1 1\n1 3\n2 3", "3\n1 2\n1 3\n2 3", "3\n1 1\n1 1\n2 3", "3\n1 1\n2 1\n2 3", "3\n1 3\n1 3\n2 2", "3\n1 1\n2 1\n1 3", "3\n1 2\n2 1\n2 3"], "outputs": ["0/1\n1/2\n1/2", "0/1\n1/3\n1/2\n", "1/2\n1/3\n1/2\n", "0/1\n0/1\n1/2\n", "0/1\n1/2\n1/2\n", "1/3\n1/3\n1/2\n", "0/1\n1/2\n1/3\n", "1/2... | 428 | 237 |
coding | Solve the programming task below in a Python markdown code block.
Little Artem likes electronics. He can spend lots of time making different schemas and looking for novelties in the nearest electronics store. The new control element was delivered to the store recently and Artem immediately bought it.
That element can ... | {"inputs": ["5 5 1\n1 5\n", "5 5 1\n1 4\n", "9 5 1\n1 4\n", "5 6 1\n1 4\n", "4 6 1\n1 4\n", "5 7 1\n1 5\n", "9 5 1\n1 7\n", "9 5 1\n1 5\n"], "outputs": ["0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n", "0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n", "0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 ... | 693 | 666 |
coding | Solve the programming task below in a Python markdown code block.
You are given $a$ uppercase Latin letters 'A' and $b$ letters 'B'.
The period of the string is the smallest such positive integer $k$ that $s_i = s_{i~mod~k}$ ($0$-indexed) for each $i$. Note that this implies that $k$ won't always divide $a+b = |s|$.
... | {"inputs": ["2 4\n", "5 3\n", "1 1\n", "1 2\n", "2 1\n", "1 3\n", "3 1\n", "2 2\n"], "outputs": ["4\n", "5\n", "1\n", "2\n", "2\n", "2\n", "2\n", "3\n"]} | 378 | 86 |
coding | Solve the programming task below in a Python markdown code block.
Tattah's youngest brother, Tuftuf, is new to programming.
Since his older brother is such a good programmer, his biggest dream is to outshine him. Tuftuf is a student at the German University in Cairo (GUC) where he learns to write programs in Gava.
To... | {"inputs": ["2\n1 2\n", "2\n1 1\n", "2\n2 1\n", "2\n1 3\n", "2\n0 1\n", "2\n0 2\n", "2\n0 4\n", "2\n0 7\n"], "outputs": ["NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n"]} | 390 | 102 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
There are two mice and n different types of cheese, each type of cheese should be eaten by exactly one mouse.
A point of the cheese with index i (0-indexed) is:
reward1[i] if the first mouse eats it.
reward2[i] if th... | {"functional": "def check(candidate):\n assert candidate(reward1 = [1,1,3,4], reward2 = [4,4,1,1], k = 2) == 15\n assert candidate(reward1 = [1,1], reward2 = [1,1], k = 2) == 2\n\n\ncheck(Solution().miceAndCheese)"} | 164 | 89 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
There are buckets buckets of liquid, where exactly one of the buckets is poisonous. To figure out which one is poisonous, you feed some number of (poor) pigs the liquid to see whether they will die or not. Unfortunate... | {"functional": "def check(candidate):\n assert candidate(buckets = 1000, minutesToDie = 15, minutesToTest = 60) == 5\n assert candidate(buckets = 4, minutesToDie = 15, minutesToTest = 15) == 2\n assert candidate(buckets = 4, minutesToDie = 15, minutesToTest = 30) == 2\n\n\ncheck(Solution().poorPigs)"} | 272 | 111 |
coding | Solve the programming task below in a Python markdown code block.
After learning a lot about space exploration, a little girl named Ana wants to change the subject.
Ana is a girl who loves palindromes (string that can be read the same backwards as forward). She has learned how to check for a given string whether it's ... | {"inputs": ["3\naa\nbb\ncd\n", "3\naa\nbc\ncd\n", "3\naa\ncc\ncd\n", "3\naa\ncc\ndd\n", "3\naa\ncd\ndd\n", "3\naa\nbb\ncd\n", "6\naab\nabcac\ndffe\ned\naa\naade\n", "6\naab\nabcbc\ndffe\ned\naa\nabde\n"], "outputs": ["1\n", "0\n", "1\n", "3\n", "1\n", "1\n", "6\n", "3\n"]} | 547 | 143 |
coding | Solve the programming task below in a Python markdown code block.
Chef defines a group of three friends as a *perfect* group if the age of one person is equal to the sum of the age of remaining two people.
Given that, the ages of three people in a group are A, B, and C respectively, find whether the group is *perfect... | {"inputs": ["4\n10 20 30\n23 51 17\n44 21 23\n30 30 30\n"], "outputs": ["YES\nNO\nYES\nNO\n"]} | 424 | 56 |
coding | Solve the programming task below in a Python markdown code block.
A number m of the form 10x + y is divisible by 7 if and only if x − 2y is divisible by 7. In other words, subtract twice the last digit
from the number formed by the remaining digits. Continue to do this until a number known to be divisible or not by 7 ... | {"functional": "_inputs = [[1021], [477557101], [477557102], [2340029794923400297949], [1603], [371], [1369851], [483], [483595], [0], [170232833617690725]]\n_outputs = [[[10, 2]], [[28, 7]], [[47, 7]], [[14, 20]], [[7, 2]], [[35, 1]], [[0, 5]], [[42, 1]], [[28, 4]], [[0, 0]], [[0, 16]]]\nimport math\ndef _deep_eq(a, b... | 616 | 331 |
coding | Solve the programming task below in a Python markdown code block.
For 3 distinct prime integers A, B, and C (1 < A,B,C < 2^{30}), we define positive integers X, Y, and Z as:
X = A\oplus B, Y = B\oplus C, and Z = C\oplus A, where \oplus denotes the [bitwise XOR] operation.
Given only two integers X and Y and the fa... | {"inputs": ["2\n1 6\n9 15"], "outputs": ["2 3 5\n2 11 13"]} | 540 | 33 |
coding | Solve the programming task below in a Python markdown code block.
Welcome
This kata is inspired by This Kata
We have a string s
We have a number n
Here is a function that takes your string, concatenates the even-indexed chars to the front, odd-indexed chars to the back.
Examples
s = "Wow Example!"
result... | {"functional": "_inputs = [['Such Wow!', 1], ['better example', 2], ['qwertyuio', 2], ['Greetings', 8], ['I like it!', 1234], ['codingisfornerdsyounerd', 10101010], ['this_test_will_hurt_you', 12345678987654321]]\n_outputs = [['Sc o!uhWw'], ['bexltept merae'], ['qtorieuwy'], ['Gtsegenri'], ['Iiei t kl!'], ['criyinodeds... | 293 | 298 |
coding | Solve the programming task below in a Python markdown code block.
Write a function which converts the input string to uppercase.
~~~if:bf
For BF all inputs end with \0, all inputs are lowercases and there is no space between.
~~~
Also feel free to reuse/extend the following starter code:
```python
def make_upper_case... | {"functional": "_inputs = [['hello'], ['hello world'], ['hello world !'], ['heLlO wORLd !'], ['1,2,3 hello world!']]\n_outputs = [['HELLO'], ['HELLO WORLD'], ['HELLO WORLD !'], ['HELLO WORLD !'], ['1,2,3 HELLO WORLD!']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n ... | 76 | 214 |
coding | Solve the programming task below in a Python markdown code block.
You're given an integer N. Write a program to calculate the sum of all the digits of N.
-----Input-----
The first line contains an integer T, the total number of testcases. Then follow T lines, each line contains an integer N.
-----Output-----
For e... | {"inputs": ["3 \n595\n1\n8", "3 \n595\n1\n1", "3 \n831\n1\n1", "3 \n831\n1\n2", "3 \n831\n1\n0", "3 \n290\n39\n8", "3 \n562\n39\n8", "3 \n595\n39\n8"], "outputs": ["19\n1\n8\n", "19\n1\n1\n", "12\n1\n1\n", "12\n1\n2\n", "12\n1\n0\n", "11\n12\n8\n", "13\n12\n8\n", "19\n12\n8\n"]} | 152 | 180 |
coding | Solve the programming task below in a Python markdown code block.
Today, Wet Shark is given n integers. Using any of these integers no more than once, Wet Shark wants to get maximum possible even (divisible by 2) sum. Please, calculate this value for Wet Shark.
Note, that if Wet Shark uses no integers from the n inte... | {"inputs": ["1\n1\n", "1\n4\n", "1\n4\n", "1\n1\n", "1\n5\n", "1\n2\n", "1\n9\n", "1\n3\n"], "outputs": ["0", "4", "4", "0", "0\n", "2\n", "0\n", "0\n"]} | 300 | 82 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an initial array arr, every day you produce a new array using the array of the previous day.
On the i-th day, you do the following operations on the array of day i-1 to produce the array of day i:
If an element... | {"functional": "def check(candidate):\n assert candidate([6,2,3,4]) == [6,3,3,4]\n assert candidate([1,6,3,4,3,5]) == [1,4,4,4,4,5]\n\n\ncheck(Solution().transformArray)"} | 166 | 73 |
coding | Solve the programming task below in a Python markdown code block.
The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pronounced) reversely. For exam... | {"inputs": ["q\nq\n", "z\na\n", "w\nw\n", "q\nr\n", "z\n`\n", "x\nw\n", "r\nq\n", "z\n_\n"], "outputs": ["YES\n", "NO\n", "YES\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n"]} | 232 | 86 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given an integer array of unique positive integers nums. Consider the following graph:
There are nums.length nodes, labeled nums[0] to nums[nums.length - 1],
There is an undirected edge between nums[i] and nu... | {"functional": "def check(candidate):\n assert candidate(nums = [4,6,15,35]) == 4\n assert candidate(nums = [20,50,9,63]) == 2\n assert candidate(nums = [2,3,6,7,4,12,21,39]) == 8\n\n\ncheck(Solution().largestComponentSize)"} | 129 | 91 |
coding | Solve the programming task below in a Python markdown code block.
Read problem statements in [Russian], [Bengali], and [Mandarin Chinese] as well.
There are $N$ students standing in a canteen queue, numbered $1$ to $N$ from left to right. For each valid $i$, the $i$-th student has a height $h_{i}$.
Two students $i$ a... | {"inputs": ["1\n5\n1 2 2 3 2"], "outputs": ["0 1 1 0 0"]} | 532 | 32 |
coding | Solve the programming task below in a Python markdown code block.
Rohit was doing the work of his math class about three days but he is tired of make operations a lot and he should deliver his task tomorrow. His math’s teacher gives two numbers a and b. The problem consist in find the last digit of the potency of base ... | {"inputs": ["5\n19021463561276851735171355238976350962817489980593657752206579555021148207736012355943198456853373185208340964575628990983191088521799365137969929935263986287756454173080642274585186167796948331561682 8017\n4565194923754350257539737098390625395160137517839262785449977071416145818084360997843473461107344... | 228 | 1,740 |
coding | Solve the programming task below in a Python markdown code block.
Two players are playing a game of Tower Breakers! Player $1$ always moves first, and both players always play optimally.The rules of the game are as follows:
Initially there are $n$ towers.
Each tower is of height $m$.
The players move in alternat... | {"inputs": ["2\n2 2\n1 4\n"], "outputs": ["2\n1\n"]} | 706 | 24 |
coding | Solve the programming task below in a Python markdown code block.
There are three cities and thus three EVMs. An insider told Chef that his party got A, B, C votes respectively in these three cities according to the EVMs. Also, the total number of votes cast are P, Q, R respectively for the three cities.
Chef, being ... | {"inputs": ["3\n1 1 1 3 3 3\n49 1 49 50 100 50\n0 0 0 1 1 1\n"], "outputs": ["YES\nYES\nNO\n"]} | 610 | 60 |
coding | Solve the programming task below in a Python markdown code block.
Suppose you are living with two cats: A and B. There are $n$ napping spots where both cats usually sleep.
Your cats like to sleep and also like all these spots, so they change napping spot each hour cyclically:
Cat A changes its napping place in order:... | {"inputs": ["1\n35 950009\n", "1\n2 1615745\n", "1\n6 1687697\n", "1\n59 950009\n", "1\n22 313455\n", "1\n6 2518353\n", "1\n62 950009\n", "1\n35 669530\n"], "outputs": ["26\n", "1\n", "5\n", "4\n", "21\n", "3\n", "45\n", "24\n"]} | 748 | 154 |
coding | Solve the programming task below in a Python markdown code block.
You are given a string s consisting of lowercase Latin letters. Character c is called k-dominant iff each substring of s with length at least k contains this character c.
You have to find minimum k such that there exists at least one k-dominant characte... | {"inputs": ["a\n", "z\n", "a\n", "z\n", "ab\n", "ob\n", "zx\n", "xx\n"], "outputs": ["1\n", "1\n", "1", "1", "2\n", "2\n", "2\n", "1\n"]} | 152 | 68 |
coding | Solve the programming task below in a Python markdown code block.
$Alien$ likes to give challenges to $Codezen$ team to check their implementation ability, this time he has given a string $S$ and asked to find out whether the given string is a $GOOD$ string or not.
According to the challenge $GOOD$ String is a string t... | {"inputs": ["COOEY", "AMBITIOUSNESS"], "outputs": ["-1", "GOOD"]} | 298 | 24 |
coding | Solve the programming task below in a Python markdown code block.
In the year 4242, the language Haskell has evolved so much that it has become an AI. It can solve very challenging problems, in very little time. Humanity is worried that Haskell will take over the world. All hopes remain tied to the Competitive Programm... | {"inputs": ["1\n1 1"], "outputs": ["1"]} | 303 | 16 |
coding | Solve the programming task below in a Python markdown code block.
The Bitlandians are quite weird people. They do everything differently. They have a different alphabet so they have a different definition for a string.
A Bitlandish string is a string made only of characters "0" and "1".
BitHaval (the mayor of Bitland... | {"inputs": ["0\n1\n", "1\n1\n", "0\n0\n", "1\n0\n", "1\n1\n", "0\n0\n", "1\n0\n", "0\n1\n"], "outputs": ["NO\n", "YES\n", "YES\n", "NO\n", "YES\n", "YES\n", "NO\n", "NO\n"]} | 396 | 86 |
coding | Solve the programming task below in a Python markdown code block.
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well.
Chef has a standard chocolate of n by m pieces. More formally, chocolate is a rectangular plate consisting of n rows and m columns.
Here you can see an example of a standard... | {"inputs": ["2\n1 2\n1 3"], "outputs": ["Yes\nNo"]} | 482 | 22 |
coding | Solve the programming task below in a Python markdown code block.
Ayoub had an array $a$ of integers of size $n$ and this array had two interesting properties: All the integers in the array were between $l$ and $r$ (inclusive). The sum of all the elements was divisible by $3$.
Unfortunately, Ayoub has lost his arr... | {"inputs": ["2 1 3\n", "3 2 2\n", "1 1 1\n", "3 1 1\n", "3 1 1\n", "1 1 1\n", "6 1 1\n", "2 1 2\n"], "outputs": ["3\n", "1\n", "0\n", "1\n", "1", "0", "1\n", "2\n"]} | 373 | 100 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
A shop is selling candies at a discount. For every two candies sold, the shop gives a third candy for free.
The customer can choose any candy to take away for free as long as the cost of the chosen candy is less than ... | {"functional": "def check(candidate):\n assert candidate(cost = [1,2,3]) == 5\n assert candidate(cost = [6,5,7,9,2,2]) == 23\n assert candidate(cost = [5,5]) == 10\n\n\ncheck(Solution().minimumCost)"} | 198 | 73 |
coding | Solve the programming task below in a Python markdown code block.
Problem statement
AOR Ika-chan is in a bad mood lately. Apparently, I don't like the ratio of the number of followers to the number of followers of "Ikatta". Currently, AOR Ika-chan has $ A $ followers, $ B $ followers, and a ratio of $ A: B $.
Therefo... | {"inputs": ["7 4 3", "30 7 1", "37 7 1", "35 7 1", "35 1 1", "7 26 3", "35 2 1", "19 2 2"], "outputs": ["1\n", "23\n", "30\n", "28\n", "34\n", "6\n", "33\n", "15\n"]} | 571 | 107 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given a string s, return the maximum number of occurrences of any substring under the following rules:
The number of unique characters in the substring must be less than or equal to maxLetters.
The substring size mus... | {"functional": "def check(candidate):\n assert candidate(s = \"aababcaab\", maxLetters = 2, minSize = 3, maxSize = 4) == 2\n assert candidate(s = \"aaaa\", maxLetters = 1, minSize = 3, maxSize = 3) == 2\n assert candidate(s = \"aabcabcab\", maxLetters = 2, minSize = 2, maxSize = 3) == 3\n assert candidate(s... | 110 | 142 |
coding | Solve the programming task below in a Python markdown code block.
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well.
Chef has a number D containing only digits 0's and 1's. He wants to make the number to have all the digits same. For that, he will change exactly one digit, i.e. from 0 to 1 ... | {"inputs": ["2\n101\n11"], "outputs": ["Yes\nNo"]} | 351 | 21 |
coding | Solve the programming task below in a Python markdown code block.
We have a tree with N vertices. The i-th edge connects Vertex A_i and B_i bidirectionally.
Takahashi is standing at Vertex u, and Aoki is standing at Vertex v.
Now, they will play a game of tag as follows:
- 1. If Takahashi and Aoki are standing at the ... | {"inputs": ["2 1 2\n1 2", "2 1 2\n1 2\n", "5 4 5\n1 2\n1 3\n2 4\n1 5", "5 4 1\n1 2\n1 3\n3 4\n3 5", "5 4 1\n1 2\n2 3\n1 4\n3 5", "5 4 5\n1 2\n1 5\n2 4\n1 5", "5 4 5\n2 2\n1 3\n1 4\n1 5", "5 5 1\n1 2\n2 3\n1 4\n3 5"], "outputs": ["0", "0\n", "2\n", "1\n", "0\n", "2\n", "1\n", "2\n"]} | 473 | 198 |
coding | Solve the programming task below in a Python markdown code block.
You are given four integers $n$, $B$, $x$ and $y$. You should build a sequence $a_0, a_1, a_2, \dots, a_n$ where $a_0 = 0$ and for each $i \ge 1$ you can choose:
either $a_i = a_{i - 1} + x$
or $a_i = a_{i - 1} - y$.
Your goal is to build such a seque... | {"inputs": ["1\n200000 1 1 1\n", "1\n200000 9 9 9\n", "1\n200000 8 8 8\n", "1\n200000 7 7 7\n", "1\n200000 10 10 10\n", "1\n1000 100 200 300\n", "1\n2000 100 200 300\n", "1\n3000 100 200 300\n"], "outputs": ["100000\n", "900000\n", "800000\n", "700000\n", "1000000\n", "-100000\n", "-200000\n", "-300000\n"]} | 509 | 230 |
coding | Solve the programming task below in a Python markdown code block.
Gorodetskiy is a university student. He is really good at math and really likes solving engaging math problems. In the last exam, his professor gave him really hard math problems to solve, but Gorodetskiy could not solve them and failed the exam, so the ... | {"inputs": ["2\n3\n6"], "outputs": ["2\n4\n6\n5\n7\n8\n9\n10\n12"]} | 513 | 34 |
coding | Solve the programming task below in a Python markdown code block.
Valeric and Valerko missed the last Euro football game, so they decided to watch the game's key moments on the Net. They want to start watching as soon as possible but the connection speed is too low. If they turn on the video right now, it will "hang up... | {"inputs": ["2 1 4\n", "2 1 2\n", "5 2 1\n", "2 1 1\n", "6 2 4\n", "2 1 3\n", "5 1 5\n", "6 1 4\n"], "outputs": ["4\n", "2\n", "2\n", "1\n", "8\n", "3\n", "20\n", "20\n"]} | 659 | 104 |
coding | Solve the programming task below in a Python markdown code block.
Lunar New Year is approaching, and Bob is struggling with his homework – a number division problem.
There are $n$ positive integers $a_1, a_2, \ldots, a_n$ on Bob's homework paper, where $n$ is always an even number. Bob is asked to divide those numbers... | {"inputs": ["2\n1 1\n", "2\n1 1\n", "2\n2 1\n", "2\n2 0\n", "2\n0 0\n", "2\n669 34\n", "2\n669 52\n", "4\n8 5 2 3\n"], "outputs": ["4\n", "4\n", "9\n", "4\n", "0\n", "494209\n", "519841\n", "164\n"]} | 519 | 124 |
coding | Solve the programming task below in a Python markdown code block.
The average miner Vaganych took refresher courses. As soon as a miner completes the courses, he should take exams. The hardest one is a computer test called "Testing Pants for Sadness".
The test consists of n questions; the questions are to be answered ... | {"inputs": ["1\n2\n", "1\n3\n", "1\n10\n", "2\n2 1\n", "2\n2 3\n", "2\n1 2\n", "2\n1 1\n", "2\n2 2\n"], "outputs": ["2\n", "3\n", "10\n", "3\n", "7\n", "4\n", "2\n", "5\n"]} | 545 | 98 |
coding | Solve the programming task below in a Python markdown code block.
A participant can make 1 submission every 30 seconds. If a contest lasts for X minutes, what is the maximum number of submissions that the participant can make during it?
It is also given that the participant cannot make any submission in the last 5 sec... | {"inputs": ["4\n1\n2\n3\n4\n"], "outputs": ["2\n4\n6\n8\n"]} | 299 | 28 |
coding | Solve the programming task below in a Python markdown code block.
You are given two integer sequences S and T of length N and M, respectively, both consisting of integers between 1 and 10^5 (inclusive).
In how many pairs of a subsequence of S and a subsequence of T do the two subsequences are the same in content?
Here ... | {"inputs": ["2 2\n1 6\n3 1", "2 2\n2 6\n3 1", "2 2\n1 1\n1 1", "2 2\n1 3\n3 1", "2 2\n1 3\n3 1\n", "2 2\n1 1\n1 1\n", "4 4\n0 4 5 6\n3 4 5 6", "4 4\n0 4 5 6\n3 4 5 0"], "outputs": ["2\n", "1\n", "6", "3", "3\n", "6\n", "8\n", "5\n"]} | 445 | 158 |
coding | Solve the programming task below in a Python markdown code block.
Vasya and Petya are playing a simple game. Vasya thought of number x between 1 and n, and Petya tries to guess the number.
Petya can ask questions like: "Is the unknown number divisible by number y?".
The game is played by the following rules: first Pe... | {"inputs": ["4\n", "6\n", "1\n", "1\n", "2\n", "3\n", "5\n", "8\n"], "outputs": ["3\n2 4 3 \n", "4\n2 4 3 5 \n", "0\n\n", "0\n", "1\n2 ", "2\n2 3 ", "4\n2 4 3 5 ", "6\n2 4 8 3 5 7 "]} | 413 | 110 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a string s of length n containing only four kinds of characters: 'Q', 'W', 'E', and 'R'.
A string is said to be balanced if each of its characters appears n / 4 times where n is the length of the string.... | {"functional": "def check(candidate):\n assert candidate(s = \"QWER\") == 0\n assert candidate(s = \"QQWE\") == 1\n assert candidate(s = \"QQQW\") == 2\n assert candidate(s = \"QQQQ\") == 3\n\n\ncheck(Solution().balancedString)"} | 137 | 72 |
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 of length n, and an integer array queries of length m.
Return an array answer of length m where answer[i] is the maximum size of a subsequence that you can take from nums such that ... | {"functional": "def check(candidate):\n assert candidate(nums = [4,5,2,1], queries = [3,10,21]) == [2,3,4]\n assert candidate(nums = [2,3,4,5], queries = [1]) == [0]\n\n\ncheck(Solution().answerQueries)"} | 143 | 77 |
coding | Solve the programming task below in a Python markdown code block.
A problem setter is called an *expert* if at least 50 \% of their problems are approved by Chef.
Munchy submitted X problems for approval. If Y problems out of those were approved, find whether Munchy is an *expert* or not.
------ Input Format ------
... | {"inputs": ["4\n5 3\n1 1\n4 1\n2 1\n"], "outputs": ["YES\nYES\nNO\nYES"]} | 487 | 35 |
coding | Solve the programming task below in a Python markdown code block.
DZY has a sequence a, consisting of n integers.
We'll call a sequence a_{i}, a_{i} + 1, ..., a_{j} (1 ≤ i ≤ j ≤ n) a subsegment of the sequence a. The value (j - i + 1) denotes the length of the subsegment.
Your task is to find the longest subsegment o... | {"inputs": ["1\n1\n", "1\n3\n", "1\n1\n", "1\n3\n", "1\n2\n", "1\n5\n", "1\n4\n", "1\n42\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n"]} | 287 | 87 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Alice had a 0-indexed array arr consisting of n positive integers. She chose an arbitrary positive integer k and created two new 0-indexed integer arrays lower and higher in the following manner:
lower[i] = arr[i] - ... | {"functional": "def check(candidate):\n assert candidate(nums = [2,10,6,4,8,12]) == [3,7,11]\n assert candidate(nums = [1,1,3,3]) == [2,2]\n assert candidate(nums = [5,435]) == [220]\n\n\ncheck(Solution().recoverArray)"} | 238 | 89 |
coding | Solve the programming task below in a Python markdown code block.
Pari wants to buy an expensive chocolate from Arya. She has n coins, the value of the i-th coin is c_{i}. The price of the chocolate is k, so Pari will take a subset of her coins with sum equal to k and give it to Arya.
Looking at her coins, a question ... | {"inputs": ["1 79\n79\n", "1 79\n79\n", "1 114\n114\n", "1 114\n114\n", "3 50\n25 25 50\n", "3 50\n25 25 50\n", "5 6\n2 71 7 27 6\n", "5 6\n2 71 7 27 6\n"], "outputs": ["2\n0 79 \n", "2\n0 79 ", "2\n0 114 \n", "2\n0 114 ", "3\n0 25 50 \n", "3\n0 25 50 ", "2\n0 6 \n", "2\n0 6 "]} | 460 | 197 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given the head of a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numbers from the original list. Return the linked list sorted as well.
Please complete the following python... | {"functional": "def check(candidate):\n assert is_same_list(candidate(head = list_node([1,2,3,3,4,4,5])), list_node([1,2,5]))\n assert is_same_list(candidate(head = list_node([1,1,1,2,3])), list_node([2,3]))\n\n\ncheck(Solution().deleteDuplicates)"} | 125 | 85 |
coding | Solve the programming task below in a Python markdown code block.
.difference()
The tool .difference() returns a set with all the elements from the set that are not in an iterable.
Sometimes the - operator is used in place of the .difference() tool, but it only operates on the set of elements in set.
Set is immuta... | {"inputs": ["9\n1 2 3 4 5 6 7 8 9\n9\n10 1 2 3 11 21 55 6 8\n"], "outputs": ["4\n"]} | 567 | 56 |
coding | Solve the programming task below in a Python markdown code block.
Simple transposition is a basic and simple cryptography technique. We make 2 rows and put first a letter in the Row 1, the second in the Row 2, third in Row 1 and so on until the end. Then we put the text from Row 2 next to the Row 1 text and thats it.
... | {"functional": "_inputs = [['Sample text'], ['Simple transposition'], ['All that glitters is not gold'], ['The better part of valor is discretion'], ['Conscience does make cowards of us all'], ['Imagination is more important than knowledge']]\n_outputs = [['Sml etapetx'], ['Sml rnpstoipetasoiin'], ['Alta ltesi o odl ht... | 186 | 294 |
coding | Solve the programming task below in a Python markdown code block.
Kefaa has developed a novel decomposition of a tree. He claims that this decomposition solves many difficult problems related to trees. However, he doesn't know how to find it quickly, so he asks you to help him.
You are given a tree with $N$ vertices nu... | {"inputs": ["2\n4\n1 2\n1 3\n1 4\n7\n1 2\n2 3\n1 4\n4 5\n1 6\n6 7"], "outputs": ["YES\n1 2 3 4\nNO"]} | 593 | 62 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an array of integers citations where citations[i] is the number of citations a researcher received for their ith paper, return the researcher's h-index.
According to the definition of h-index on Wikipedia: The h... | {"functional": "def check(candidate):\n assert candidate(citations = [3,0,6,1,5]) == 3 \n assert candidate(citations = [1,3,1]) == 1\n\n\ncheck(Solution().hIndex)"} | 120 | 58 |
coding | Solve the programming task below in a Python markdown code block.
# Task
Suppose there are `n` people standing in a circle and they are numbered 1 through n in order.
Person 1 starts off with a sword and kills person 2. He then passes the sword to the next person still standing, in this case person 3. Person 3 the... | {"functional": "_inputs = [[5], [11], [1], [2], [3], [4], [8], [16], [15], [31]]\n_outputs = [[3], [7], [1], [1], [3], [1], [1], [1], [15], [31]]\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 isinsta... | 256 | 215 |
coding | Solve the programming task below in a Python markdown code block.
Snuke has N integers. Among them, the smallest is A, and the largest is B. We are interested in the sum of those N integers. How many different possible sums there are?
Constraints
* 1 ≤ N,A,B ≤ 10^9
* A and B are integers.
Input
Input is given from ... | {"inputs": ["5 5 3", "1 7 7", "4 4 8", "5 4 6", "7 1 2", "5 4 8", "3 0 2", "7 1 4"], "outputs": ["0\n", "1\n", "9\n", "7\n", "6\n", "13\n", "3\n", "16\n"]} | 154 | 96 |
coding | Solve the programming task below in a Python markdown code block.
Watson gives Sherlock two integers, $n$ and $\boldsymbol{\mbox{k}}$, and asks him to count the number of positive integer $\boldsymbol{i}$'s such that:
$i\cdot(n-i)\leq n\cdot k,\ \text{and}\ i<n$
Given $\textit{q}$ queries where each query consists... | {"inputs": ["2\n5 1\n5 2\n"], "outputs": ["2\n4\n"]} | 428 | 24 |
coding | Solve the programming task below in a Python markdown code block.
An element in an array is dominant if it is greater than all elements to its right. You will be given an array and your task will be to return a list of all dominant elements. For example:
```Haskell
solve([1,21,4,7,5]) = [21,7,5] because 21, 7 and 5 are... | {"functional": "_inputs = [[[16, 17, 14, 3, 14, 5, 2]], [[92, 52, 93, 31, 89, 87, 77, 105]], [[75, 47, 42, 56, 13, 55]], [[67, 54, 27, 85, 66, 88, 31, 24, 49]], [[76, 17, 25, 36, 29]], [[104, 18, 37, 9, 36, 47, 28]]]\n_outputs = [[[17, 14, 5, 2]], [[105]], [[75, 56, 55]], [[88, 49]], [[76, 36, 29]], [[104, 47, 28]]]\ni... | 165 | 378 |
coding | Solve the programming task below in a Python markdown code block.
You are given an integer sequence of length n, a_1, ..., a_n.
Let us consider performing the following n operations on an empty sequence b.
The i-th operation is as follows:
- Append a_i to the end of b.
- Reverse the order of the elements in b.
Find t... | {"inputs": ["3\n1 2 3\n", "4\n1 2 3 4\n", "1\n1000000000\n", "6\n0 6 7 6 7 0\n"], "outputs": ["3 1 2\n", "4 2 1 3\n", "1000000000\n", "0 6 6 0 7 7\n"]} | 384 | 104 |
coding | Solve the programming task below in a Python markdown code block.
There are $n$ block towers, numbered from $1$ to $n$. The $i$-th tower consists of $a_i$ blocks.
In one move, you can move one block from tower $i$ to tower $j$, but only if $a_i > a_j$. That move increases $a_j$ by $1$ and decreases $a_i$ by $1$. You c... | {"inputs": ["4\n3\n1 2 3\n3\n1 2 2\n2\n1 1000000000\n10\n3 8 6 7 4 1 2 4 10 1\n"], "outputs": ["3\n2\n500000001\n9\n"]} | 575 | 83 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an unsorted array of integers nums, return the length of the longest consecutive elements sequence.
You must write an algorithm that runs in O(n) time.
Please complete the following python code precisely:
```p... | {"functional": "def check(candidate):\n assert candidate(nums = [100,4,200,1,3,2]) == 4\n assert candidate(nums = [0,3,7,2,5,8,4,6,0,1]) == 9\n\n\ncheck(Solution().longestConsecutive)"} | 83 | 77 |
coding | Solve the programming task below in a Python markdown code block.
Given a sequence of numbers, find the largest pair sum in the sequence.
For example
```
[10, 14, 2, 23, 19] --> 42 (= 23 + 19)
[99, 2, 2, 23, 19] --> 122 (= 99 + 23)
```
Input sequence contains minimum two elements and every element is an integer.
Al... | {"functional": "_inputs = [[[10, 14, 2, 23, 19]], [[-100, -29, -24, -19, 19]], [[1, 2, 3, 4, 6, -1, 2]], [[-10, -8, -16, -18, -19]]]\n_outputs = [[42], [0], [10], [-18]]\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_... | 136 | 247 |
coding | Solve the programming task below in a Python markdown code block.
There are N children, numbered 1, 2, ..., N.
Snuke has decided to distribute x sweets among them. He needs to give out all the x sweets, but some of the children may get zero sweets.
For each i (1 \leq i \leq N), Child i will be happy if he/she gets ex... | {"inputs": ["2 1\n30 1", "2 0\n30 20", "2 1\n30 20", "2 1\n30 26", "2 0\n30 26", "2 10\n20 2", "2 0\n30 17", "2 0\n20 26"], "outputs": ["1\n", "0\n", "0\n", "0\n", "0\n", "1\n", "0\n", "0\n"]} | 296 | 125 |
coding | Solve the programming task below in a Python markdown code block.
There was a power value associated with each soldier of Ram’s troop. It was a known belief that if two soldiers could be paired such that their total power can be divided by 3 perfectly, the pairing becomes ultra-powerful. Ram was curious as to see how m... | {"inputs": ["5\n3\n1 2 3\n9\n2 3 4 5 11 3 5 6 4\n1\n2\n2 \n7 2\n3 \n9 9 9"], "outputs": ["1\n11\n0\n1\n3"]} | 313 | 70 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a positive integer n representing n cities numbered from 1 to n. You are also given a 2D array roads, where roads[i] = [ai, bi, costi] indicates that there is a bidirectional road between cities ai and b... | {"functional": "def check(candidate):\n assert candidate(n = 4, roads = [[1,2,4],[2,3,2],[2,4,5],[3,4,1],[1,3,4]], appleCost = [56,42,102,301], k = 2) == [54,42,48,51]\n assert candidate(n = 3, roads = [[1,2,5],[2,3,1],[3,1,2]], appleCost = [2,3,1], k = 3) == [2,3,1]\n\n\ncheck(Solution().minCost)"} | 265 | 151 |
coding | Solve the programming task below in a Python markdown code block.
You have three tasks, all of which need to be completed.
First, you can complete any one task at cost 0.
Then, just after completing the i-th task, you can complete the j-th task at cost |A_j - A_i|.
Here, |x| denotes the absolute value of x.
Find the mi... | {"inputs": ["3 5 2", "4 3 2", "4 3 0", "5 3 0", "0 1 6", "1 1 8", "0 1 8", "1 6 3"], "outputs": ["3\n", "2\n", "4\n", "5\n", "6\n", "7\n", "8\n", "5"]} | 233 | 93 |
coding | Solve the programming task below in a Python markdown code block.
There are n points on a straight line, and the i-th point among them is located at x_{i}. All these coordinates are distinct.
Determine the number m — the smallest number of points you should add on the line to make the distances between all neighboring... | {"inputs": ["3\n1 4 7\n", "3\n1 4 6\n", "3\n1 2 6\n", "3\n1 3 6\n", "3\n1 4 7\n", "3\n1 3 6\n", "3\n1 4 6\n", "3\n1 2 6\n"], "outputs": ["0\n", "3\n", "3\n", "3\n", "0\n", "3\n", "3\n", "3\n"]} | 301 | 118 |
coding | Solve the programming task below in a Python markdown code block.
One day Sasha visited the farmer 2D and his famous magnetic farm. On this farm, the crop grows due to the influence of a special magnetic field. Maintaining of the magnetic field is provided by $n$ machines, and the power of the $i$-th machine is $a_i$. ... | {"inputs": ["2\n42 9\n", "2\n42 9\n", "2\n74 1\n", "2\n2 10\n", "2\n2 12\n", "2\n1 12\n", "2\n75 7\n", "2\n42 7\n"], "outputs": ["39\n", "39", "39\n", "9\n", "10\n", "7\n", "46\n", "35\n"]} | 595 | 115 |
coding | Solve the programming task below in a Python markdown code block.
As the title suggests, this is the hard-core version of another neat kata.
The task is simple to explain: simply sum all the numbers from the first parameter being the beginning to the second parameter being the upper limit (possibly included), going i... | {"functional": "_inputs = [[2, 6, 2], [1, 5, 1], [1, 5, 3], [-1, -5, -3], [16, 15, 3], [-24, -2, 22], [-2, 4, 658], [780, 6851543, 5], [9383, 71418, 2], [20, 673388797, 5]]\n_outputs = [[12], [15], [5], [-5], [0], [-26], [-2], [4694363402480], [1253127200], [45345247259849570]]\nimport math\ndef _deep_eq(a, b, tol=1e-5... | 267 | 338 |
coding | Solve the programming task below in a Python markdown code block.
Alice and Bob are playing a game on a sequence $a_1, a_2, \dots, a_n$ of length $n$. They move in turns and Alice moves first.
In the turn of each player, he or she should select an integer and remove it from the sequence. The game ends when there is no... | {"inputs": ["4\n3\n1 3 5\n4\n1 3 5 7\n4\n1 2 3 4\n4\n10 20 30 40\n", "1\n100\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n"], "outputs": ["Alice\nAlice\nBob\nAlice... | 451 | 274 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given an array of integers stones where stones[i] is the weight of the ith stone.
We are playing a game with the stones. On each turn, we choose any two stones and smash them together. Suppose the stones have ... | {"functional": "def check(candidate):\n assert candidate(stones = [2,7,4,1,8,1]) == 1\n assert candidate(stones = [31,26,33,21,40]) == 5\n\n\ncheck(Solution().lastStoneWeightII)"} | 187 | 70 |
coding | Solve the programming task below in a Python markdown code block.
It's year 2018 and it's Christmas time! Before going for vacations, students of Hogwarts School of Witchcraft and Wizardry had their end semester exams.
$N$ students attended the semester exam. Once the exam was over, their results were displayed as eith... | {"inputs": ["1\n4\n3 2 2 2"], "outputs": ["1"]} | 451 | 22 |
coding | Solve the programming task below in a Python markdown code block.
Bobby has decided to hunt some Parrots. There are n horizontal branch of trees aligned parallel to each other. Branches are numbered 1 to n from top to bottom. On each branch there are some parrots sitting next to each other. Supposed there are a[i]$a[i]... | {"inputs": ["5\n10 10 10 10 10\n5\n2 5\n3 13\n2 12\n1 13\n4 6\n3\n2 4 1\n1\n2 2"], "outputs": ["0\n12\n5\n0\n16\n3\n0\n3"]} | 617 | 82 |
coding | Solve the programming task below in a Python markdown code block.
A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7.
Write a program which reads a list of N integers and prints the number of prime number... | {"inputs": ["5\n2\n4\n7\n5\n6", "5\n2\n3\n7\n5\n6", "5\n2\n7\n7\n5\n6", "5\n2\n2\n4\n5\n6", "5\n4\n3\n7\n5\n6", "5\n2\n3\n4\n5\n6", "5\n2\n12\n7\n5\n6", "5\n2\n7\n7\n5\n11"], "outputs": ["3\n", "4\n", "4\n", "3\n", "3\n", "3", "3\n", "5\n"]} | 202 | 143 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a positive integer num consisting of exactly four digits. Split num into two new integers new1 and new2 by using the digits found in num. Leading zeros are allowed in new1 and new2, and all the digits fo... | {"functional": "def check(candidate):\n assert candidate(num = 2932) == 52\n assert candidate(num = 4009) == 13\n\n\ncheck(Solution().minimumSum)"} | 190 | 51 |
coding | Solve the programming task below in a Python markdown code block.
You want to type the string $s$, consisting of $n$ lowercase Latin letters, using your favorite text editor Notepad#.
Notepad# supports two kinds of operations:
append any letter to the end of the string;
copy a continuous substring of an already type... | {"inputs": ["1\n3\nyes\n", "6\n10\ncodeforces\n8\nlabacaba\n5\nuohhh\n16\nisthissuffixtree\n1\nx\n4\nmomo\n"], "outputs": ["NO\n", "NO\nYES\nNO\nYES\nNO\nYES\n"]} | 438 | 73 |
coding | Solve the programming task below in a Python markdown code block.
Polycarp plays "Game 23". Initially he has a number $n$ and his goal is to transform it to $m$. In one move, he can multiply $n$ by $2$ or multiply $n$ by $3$. He can perform any number of moves.
Print the number of moves needed to transform $n$ to $m$.... | {"inputs": ["1 1\n", "1 2\n", "1 4\n", "1 5\n", "1 6\n", "2 5\n", "4 9\n", "2 7\n"], "outputs": ["0\n", "1\n", "2\n", "-1\n", "2\n", "-1\n", "-1\n", "-1\n"]} | 364 | 86 |
coding | Solve the programming task below in a Python markdown code block.
You are given a sequence $A_1, A_2, \ldots, A_N$. For each valid $i$, the star value of the element $A_i$ is the number of valid indices $j < i$ such that $A_j$ is divisible by $A_i$.
Chef is a curious person, so he wants to know the maximum star value i... | {"inputs": ["1\n7\n8 1 28 4 2 6 7"], "outputs": ["3"]} | 383 | 29 |
coding | Solve the programming task below in a Python markdown code block.
Read problems statements in Mandarin Chinese and Russian.
Little Elephant from Zoo of Lviv likes to paint.
He has n objects to paint, ordered in a row and numbered form left to right starting from 1. There are totally c colors, numbered from 0 to c-1... | {"inputs": ["2\n4 3 4\n1 2\n2 4\n3 3\n1 4\n7 10 7\n7 7\n3 4\n1 2\n5 5\n4 5\n2 7\n3 3"], "outputs": ["3.444444444\n22.943125000"]} | 442 | 92 |
coding | Solve the programming task below in a Python markdown code block.
You are given a binary string S. You are allowed to perform the following operation at most once:
Pick some [substring] of S
Flip all the values in this substring, i.e, convert 0 to 1 and vice versa
For example, if S = 1\underline{00101}011, you can pic... | {"inputs": ["3\n111\n000\n00100"], "outputs": ["10\n10\n26"]} | 640 | 33 |
coding | Solve the programming task below in a Python markdown code block.
Given a positive integer N, MoEngage wants you to determine if it is possible to rearrange the digits of N (in decimal representation) and obtain a [multiple] of 5.
For example, when N = 108, we can rearrange its digits to construct 180 = 36 \cdot 5 wh... | {"inputs": ["3\n3\n115\n3\n103\n3\n119"], "outputs": ["Yes\nYes\nNo"]} | 533 | 34 |
coding | Solve the programming task below in a Python markdown code block.
There are $n$ districts in the town, the $i$-th district belongs to the $a_i$-th bandit gang. Initially, no districts are connected to each other.
You are the mayor of the city and want to build $n-1$ two-way roads to connect all districts (two district... | {"inputs": ["1\n2\n7 7\n", "1\n2\n7 7\n", "1\n2\n3 7\n", "1\n2\n0 7\n", "1\n2\n11 7\n", "1\n2\n0 13\n", "1\n2\n1 13\n", "1\n2\n1 21\n"], "outputs": ["NO\n", "NO\n", "YES\n1 2\n", "YES\n1 2\n", "YES\n1 2\n", "YES\n1 2\n", "YES\n1 2\n", "YES\n1 2\n"]} | 621 | 146 |
coding | Solve the programming task below in a Python markdown code block.
Takahashi is not good at problems about trees in programming contests, and Aoki is helping him practice.
First, Takahashi created a tree with N vertices numbered 1 through N, and wrote 0 at each edge.
Then, Aoki gave him M queries. The i-th of them is ... | {"inputs": ["4 4\n1 2\n1 4\n1 3\n3 4", "4 4\n2 2\n1 4\n1 3\n3 4", "4 4\n1 2\n2 4\n1 3\n3 4", "5 5\n1 2\n5 5\n5 1\n3 4\n2 3", "5 1\n1 1\n6 5\n5 2\n3 4\n2 3", "5 1\n1 2\n5 5\n5 1\n3 4\n2 3", "5 1\n1 2\n6 5\n5 1\n3 4\n2 3", "5 1\n1 2\n6 5\n5 2\n3 4\n2 3"], "outputs": ["NO\n", "YES\n", "YES", "NO\n", "YES\n", "NO\n", "NO\n... | 340 | 225 |
coding | Solve the programming task below in a Python markdown code block.
School holidays come in Berland. The holidays are going to continue for n days. The students of school №N are having the time of their lives and the IT teacher Marina Sergeyevna, who has spent all the summer busy checking the BSE (Berland State Examinati... | {"inputs": ["1 1\n1 1\n", "5 1\n1 5\n", "10 1\n2 3\n", "6 2\n1 5\n6 6\n", "5 2\n1 1\n3 3\n", "5 2\n2 1\n3 3\n", "5 2\n1 1\n3 5\n", "5 2\n1 2\n3 5\n"], "outputs": ["OK\n", "OK\n", "1 0\n", "OK\n", "2 0\n", "1 0\n", "2 0\n", "OK\n"]} | 528 | 147 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You may recall that an array arr is a mountain array if and only if:
arr.length >= 3
There exists some index i (0-indexed) with 0 < i < arr.length - 1 such that:
arr[0] < arr[1] < ... < arr[i - 1] < arr[i]
arr[i] >... | {"functional": "def check(candidate):\n assert candidate(arr = [2,1,4,7,3,2,5]) == 5\n assert candidate(arr = [2,2,2]) == 0\n\n\ncheck(Solution().longestMountain)"} | 168 | 60 |
coding | Solve the programming task below in a Python markdown code block.
Given an alphanumeric string made up of digits and lower case Latin characters only, find the sum of all the digit characters in the string.
-----Input-----
- The first line of the input contains an integer T denoting the number of test cases. Then T te... | {"inputs": ["1\nab1231da"], "outputs": ["7"]} | 204 | 19 |
coding | Solve the programming task below in a Python markdown code block.
Fox Ciel has some flowers: r red flowers, g green flowers and b blue flowers. She wants to use these flowers to make several bouquets. There are 4 types of bouquets:
To make a "red bouquet", it needs 3 red flowers. To make a "green bouquet", it needs... | {"inputs": ["3 6 9\n", "4 4 4\n", "0 0 0\n", "0 3 6\n", "7 8 9\n", "8 8 9\n", "3 5 5\n", "0 1 1\n"], "outputs": ["6\n", "4\n", "0\n", "3\n", "7\n", "8\n", "4\n", "0\n"]} | 289 | 102 |
coding | Solve the programming task below in a Python markdown code block.
After a very long time, the Chef has a vacation. Chef has planned for two trips during this vacation - one with his family and the other with his friends. The family trip will take X days and the trip with friends will take Y days. Currently, the dates a... | {"inputs": ["2\n1 2 4\n2 2 3"], "outputs": ["YES\nNO"]} | 399 | 26 |
coding | Solve the programming task below in a Python markdown code block.
The last contest held on Johnny's favorite competitive programming platform has been received rather positively. However, Johnny's rating has dropped again! He thinks that the presented tasks are lovely, but don't show the truth about competitors' skills... | {"inputs": ["1\n1\n", "1\n1\n", "1\n399462040\n", "1\n338186953\n", "1\n158575687\n", "1\n313577823\n", "1\n247528392\n", "1\n452215226\n"], "outputs": ["1\n", "1\n", "798924063\n", "676373895\n", "317151359\n", "627155631\n", "495056769\n", "904430437\n"]} | 610 | 182 |
coding | Solve the programming task below in a Python markdown code block.
It's the sale season again and Chef bought items worth a total of X rupees. The sale season offer is as follows:
if X ≤ 100, no discount.
if 100 < X ≤ 1000, discount is 25 rupees.
if 1000 < X ≤ 5000, discount is 100 rupees.
if X > 5000, discount is 500 ... | {"inputs": ["4\n15\n70\n250\n1000\n"], "outputs": ["15\n70\n225\n975\n"]} | 355 | 41 |
coding | Solve the programming task below in a Python markdown code block.
Let's call a string good if and only if it consists of only two types of letters — 'a' and 'b' and every two consecutive letters are distinct. For example "baba" and "aba" are good strings and "abb" is a bad string.
You have $a$ strings "a", $b$ strings... | {"inputs": ["1 1 1\n", "2 1 2\n", "3 5 2\n", "2 2 1\n", "3 1 3\n", "2 2 3\n", "1 1 4\n", "1 1 2\n"], "outputs": ["4\n", "7\n", "11\n", "6\n", "9\n", "10\n", "10\n", "6\n"]} | 360 | 105 |
coding | Solve the programming task below in a Python markdown code block.
G --Derangement / Derangement
Story
Person D is doing research on permutations. At one point, D found a permutation class called "Derangement". "It's cool to have a perfect permutation !!! And it starts with D !!!", the person of D who had a crush on C... | {"inputs": ["5\n2 1 3 5 4", "5\n2 1 0 5 4", "5\n4 1 0 5 4", "5\n4 1 0 5 6", "5\n4 0 0 5 6", "5\n4 0 0 0 3", "5\n4 0 1 0 3", "5\n7 0 1 0 3"], "outputs": ["4\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]} | 526 | 142 |
coding | Solve the programming task below in a Python markdown code block.
A new e-mail service "Berlandesk" is going to be opened in Berland in the near future. The site administration wants to launch their project as soon as possible, that's why they ask you to help. You're suggested to implement the prototype of site registr... | {"inputs": ["1\nn\n", "1\nm\n", "1\nl\n", "1\nk\n", "1\no\n", "1\np\n", "2\nu\nu\n", "2\nv\nu\n"], "outputs": ["OK\n", "OK\n", "OK\n", "OK\n", "OK\n", "OK\n", "OK\nu1\n", "OK\nOK\n"]} | 378 | 95 |
coding | Solve the programming task below in a Python markdown code block.
Create a function which accepts one arbitrary string as an argument, and return a string of length 26.
The objective is to set each of the 26 characters of the output string to either `'1'` or `'0'` based on the fact whether the Nth letter of the alphab... | {"functional": "_inputs = [['a **& bZ'], ['Abc e $$ z'], ['!!a$%&RgTT'], [''], ['abcdefghijklmnopqrstuvwxyz'], ['aaaaaaaaaaa'], ['&%&%/$%$%$%$%GYtf67fg34678hgfdyd']]\n_outputs = [['11000000000000000000000001'], ['11101000000000000000000001'], ['10000010000000000101000000'], ['00000000000000000000000000'], ['11111111... | 230 | 406 |
coding | Solve the programming task below in a Python markdown code block.
A word or a sentence in some language is called a pangram if all the characters of the alphabet of this language appear in it at least once. Pangrams are often used to demonstrate fonts in printing or test the output devices.
You are given a string cons... | {"inputs": ["1\na\n", "1\na\n", "1\nb\n", "12\ntoosmallword\n", "12\ntoosmallworc\n", "12\ntoosmallword\n", "25\nnxYTzLFwzNolAumjgcAboyxAj\n", "25\nabcdefghijklmnopqrstuvwxy\n"], "outputs": ["NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n"]} | 210 | 122 |
coding | Solve the programming task below in a Python markdown code block.
Snuke is buying a lamp.
The light of the lamp can be adjusted to m levels of brightness, represented by integers from 1 through m, by the two buttons on the remote control.
The first button is a "forward" button. When this button is pressed, the brightne... | {"inputs": ["4 8\n1 5 1 4", "4 8\n1 5 1 5", "1 8\n1 5 2 1", "4 6\n0 5 1 4", "4 6\n2 3 2 1", "2 8\n1 5 1 5", "2 8\n1 5 1 0", "2 8\n1 5 1 1"], "outputs": ["7\n", "6\n", "0\n", "5\n", "4\n", "1\n", "1\n", "1\n"]} | 462 | 142 |
coding | Solve the programming task below in a Python markdown code block.
Chef's brother likes to put words in Chef's mouth.
Chef hates it about him of course.
He has decided to become extremely careful about what he speaks.
Fortunately, he knows how his brother transforms the words, that Chef uses.
He has decided to use only ... | {"inputs": ["3\n1\n14\n45"], "outputs": ["26\n456976\n827063120"]} | 378 | 38 |
coding | Solve the programming task below in a Python markdown code block.
Ann has recently started commuting by subway. We know that a one ride subway ticket costs a rubles. Besides, Ann found out that she can buy a special ticket for m rides (she can buy it several times). It costs b rubles. Ann did the math; she will need to... | {"inputs": ["6 2 1 2\n", "5 2 2 3\n", "1 1 1 1\n", "6 4 1 3\n", "8 5 2 8\n", "6 4 1 3\n", "1 1 1 1\n", "8 5 2 8\n"], "outputs": ["6\n", "8\n", "1\n", "5\n", "14\n", "5\n", "1\n", "14\n"]} | 260 | 120 |
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 and an integer k.
For each index i where 0 <= i < nums.length, change nums[i] to be either nums[i] + k or nums[i] - k.
The score of nums is the difference between the maximum and mi... | {"functional": "def check(candidate):\n assert candidate(nums = [1], k = 0) == 0\n assert candidate(nums = [0,10], k = 2) == 6\n assert candidate(nums = [1,3,6], k = 3) == 3\n\n\ncheck(Solution().smallestRangeII)"} | 127 | 79 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.