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. Mario transforms each time he eats a mushroom as follows: If he is currently small, he turns normal. If he is currently normal, he turns huge. If he is currently huge, he turns small. Given that Mario was initially normal, find his size after eating X m...
{"inputs": ["3\n2\n4\n12"], "outputs": ["SMALL\nHUGE\nNORMAL"]}
384
25
coding
Solve the programming task below in a Python markdown code block. Neko loves divisors. During the latest number theory lesson, he got an interesting exercise from his math teacher. Neko has two integers $a$ and $b$. His goal is to find a non-negative integer $k$ such that the least common multiple of $a+k$ and $b+k$ i...
{"inputs": ["1 1\n", "2 3\n", "2 2\n", "2 6\n", "6 9\n", "2 3\n", "2 2\n", "2 6\n"], "outputs": ["0", "0", "0", "0", "0", "0\n", "0\n", "0\n"]}
307
81
coding
Solve the programming task below in a Python markdown code block. Chef has an array A of length N. Chef forms a binary array B of length N using the parity of the sums of adjacent elements in A. Formally, B_{i} = (A_{i} + A_{i+1}) \, \% \, 2 for 1 ≤ i ≤ N - 1 B_{N} = (A_{N} + A_{1}) \, \% \, 2 Here x \, \% \, y deno...
{"inputs": ["4\n2\n0 0\n2\n1 0\n4\n1 0 1 0\n3\n1 0 0\n"], "outputs": ["YES\nNO\nYES\nNO\n"]}
649
50
coding
Solve the programming task below in a Python markdown code block. Chef is given two integers N, S. Consider an array A of size N such that A[i]=i for every 1 ≤ i ≤ N. You are required to find any position x(1≤ x ≤ N) such that : (A[1]+A[2]+...A[x-1]) + (A[x+1]+A[x+2]+...A[N]) = S If there are multiple such position...
{"inputs": ["3\n4 8\n5 10\n2 3\n"], "outputs": ["2\n5\n-1\n"]}
313
32
coding
Solve the programming task below in a Python markdown code block. There are N squares arranged in a row, numbered 1, 2, ..., N from left to right. You are given a string S of length N consisting of `.` and `#`. If the i-th character of S is `#`, Square i contains a rock; if the i-th character of S is `.`, Square i is e...
{"inputs": ["9 1 3 7 6\n.#..#..", "4 1 3 7 6\n.#..#..", "8 1 3 7 6\n.#..#..", "1 1 3 7 6\n.#..#..", "8 1 4 7 6\n.#..#..", "8 2 4 7 6\n.#..#..", "5 1 3 7 6\n.#..#..", "0 1 3 7 6\n.#..#.."], "outputs": ["No\n", "No\n", "No\n", "No\n", "No\n", "No\n", "No\n", "No\n"]}
400
166
coding
Solve the programming task below in a Python markdown code block. Vasya has n burles. One bottle of Ber-Cola costs a burles and one Bars bar costs b burles. He can buy any non-negative integer number of bottles of Ber-Cola and any non-negative integer number of Bars bars. Find out if it's possible to buy some amount o...
{"inputs": ["7\n2\n3\n", "1\n7\n8\n", "4\n2\n2\n", "4\n1\n3\n", "4\n1\n2\n", "4\n3\n1\n", "4\n2\n1\n", "1\n1\n1\n"], "outputs": ["YES\n2 1\n", "NO\n", "YES\n0 2\n", "YES\n1 1\n", "YES\n0 2\n", "YES\n0 4\n", "YES\n0 4\n", "YES\n0 1\n"]}
558
130
coding
Solve the programming task below in a Python markdown code block. You are given a string $s$ of length $n$ consisting of characters a and/or b. Let $\operatorname{AB}(s)$ be the number of occurrences of string ab in $s$ as a substring. Analogically, $\operatorname{BA}(s)$ is the number of occurrences of ba in $s$ as a...
{"inputs": ["4\nb\naabbbabaa\nabbb\nabbaab\n", "4\nb\naabbbabaa\nabbb\nabbaab\n", "4\na\naabbbabaa\nabbb\nabbaab\n", "4\nb\naabbbabaa\nabbb\nabbabb\n", "4\na\naabababaa\nabbb\nabbaab\n", "4\nb\naabbbacaa\nabbb\nabbabb\n", "4\nc\naabbbacaa\nabbb\nabbabb\n", "4\nc\naacabbbaa\nabbb\nabbabb\n"], "outputs": ["b\naabbbabaa\n...
656
262
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Your music player contains n different songs. You want to listen to goal songs (not necessarily different) during your trip. To avoid boredom, you will create a playlist so that: Every song is played at least once. A...
{"functional": "def check(candidate):\n assert candidate(n = 3, goal = 3, k = 1) == 6\n assert candidate(n = 2, goal = 3, k = 0) == 6\n assert candidate(n = 2, goal = 3, k = 1) == 2\n\n\ncheck(Solution().numMusicPlaylists)"}
155
87
coding
Solve the programming task below in a Python markdown code block. Chef spent N days working really hard! He planned loads of tasks: as many as Ai tasks to do on the ith day! Chef's work was brutal, so he only managed to finish Bi tasks on the ith day. The good news is that Chef has a Time Machine! The Time Machine has...
{"inputs": ["1\n4 2 2\n5 7 6 1\n3 3 1 1\n6 3\n1 4"], "outputs": ["3"]}
720
42
coding
Solve the programming task below in a Python markdown code block. Killgrave wants to use his mind control powers to get money from the Justice League superheroes living in $N$ houses in Happy Harbor that are numbered sequentially from $1$ to $N$. There are $\mbox{M}$ roads, and each road $j$ connects two different hous...
{"inputs": ["3 2\n6 8 2\n1 2\n3 2\n"], "outputs": ["8 2\n"]}
708
32
coding
Solve the programming task below in a Python markdown code block. Balph is learning to play a game called Buma. In this game, he is given a row of colored balls. He has to choose the color of one new ball and the place to insert it (between two balls, or to the left of all the balls, or to the right of all the balls). ...
{"inputs": ["A\n", "B\n", "C\n", "D\n", "@\n", "E\n", "F\n", "G\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]}
424
70
coding
Solve the programming task below in a Python markdown code block. Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. Chef decided to write an infinite sequence. Initially, he wrote $0$, and then he started repeating the following process: Look at the last element wr...
{"inputs": ["1\n2"], "outputs": ["2"]}
604
14
coding
Solve the programming task below in a Python markdown code block. Our Chef is doing what he is best at, COOKING A BARBECUE for his guests. He has invited all of us, and taking the help of his apprentice to smoke the barbecues. The chef has got BBQ sticks, each can take N fillings, and he presents N distinctly filled st...
{"inputs": ["1\n4"], "outputs": ["5"]}
272
14
coding
Solve the programming task below in a Python markdown code block. You have n problems. You have estimated the difficulty of the i-th one as integer c_{i}. Now you want to prepare a problemset for a contest, using some of the problems you've made. A problemset for the contest must consist of at least two problems. You ...
{"inputs": ["1 10 6 1\n15\n", "1 10 6 1\n17\n", "1 10 6 2\n17\n", "1 10 20 1\n15\n", "1 10 20 1\n15\n", "3 5 6 1\n1 2 3\n", "3 5 8 1\n1 2 3\n", "3 5 8 1\n1 2 0\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "2\n", "2\n", "0\n"]}
459
158
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an array target that consists of distinct integers and another integer array arr that can have duplicates. In one operation, you can insert any integer at any position in arr. For example, if arr = [1,4,...
{"functional": "def check(candidate):\n assert candidate(target = [5,1,3], arr = [9,4,2,3,4]) == 2\n assert candidate(target = [6,4,8,1,3,2], arr = [4,7,6,2,3,8,6,1]) == 3\n\n\ncheck(Solution().minOperations)"}
238
89
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given two strings s1 and s2 of equal length consisting of letters "x" and "y" only. Your task is to make these two strings equal to each other. You can swap any two characters that belong to different strings,...
{"functional": "def check(candidate):\n assert candidate(s1 = \"xx\", s2 = \"yy\") == 1\n assert candidate(s1 = \"xy\", s2 = \"yx\") == 2\n assert candidate(s1 = \"xx\", s2 = \"xy\") == -1\n\n\ncheck(Solution().minimumSwap)"}
144
76
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given the root of a Binary Search Tree (BST), return the minimum absolute difference between the values of any two different nodes in the tree.   Please complete the following python code precisely: ```python # Defini...
{"functional": "def check(candidate):\n assert candidate(root = tree_node([4,2,6,1,3])) == 1\n assert candidate(root = tree_node([1,0,48,None,None,12,49])) == 1\n\n\ncheck(Solution().getMinimumDifference)"}
129
69
coding
Solve the programming task below in a Python markdown code block. When a warrior wants to talk with another one about peace or war he uses a smartphone. In one distinct country warriors who spent all time in training kata not always have enough money. So if they call some number they want to know which operator serve...
{"functional": "_inputs = [['80661111841'], ['80671991111'], ['80631551111'], ['80931551111'], ['80111551111']]\n_outputs = [['MTS'], ['Kyivstar'], ['Life:)'], ['Life:)'], ['no info']]\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...
294
235
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an n x n matrix where each of the rows and columns is sorted in ascending order, return the kth smallest element in the matrix. Note that it is the kth smallest element in the sorted order, not the kth distinct ...
{"functional": "def check(candidate):\n assert candidate(matrix = [[1,5,9],[10,11,13],[12,13,15]], k = 8) == 13\n assert candidate(matrix = [[-5]], k = 1) == -5\n\n\ncheck(Solution().kthSmallest)"}
120
79
coding
Solve the programming task below in a Python markdown code block. You are given a string $s$ consisting of $n$ lowercase Latin letters. Let's define a substring as a contiguous subsegment of a string. For example, "acab" is a substring of "abacaba" (it starts in position $3$ and ends in position $6$), but "aa" or "d" ...
{"inputs": ["2\nba\n", "2\naa\n", "2\nba\n", "2\naa\n", "2\nab\n", "2\nb`\n", "2\nb_\n", "2\nac\n"], "outputs": ["YES\n1 2\n", "NO\n", "YES\n1 2\n", "NO\n", "NO\n", "YES\n1 2\n", "YES\n1 2\n", "NO\n"]}
547
104
coding
Solve the programming task below in a Python markdown code block. We have a tree with N vertices. Vertex 1 is the root of the tree, and the parent of Vertex i (2 \leq i \leq N) is Vertex P_i. To each vertex in the tree, Snuke will allocate a color, either black or white, and a non-negative integer weight. Snuke has a f...
{"inputs": ["1\n\n1", "1\n\n2", "1\n\n3", "1\n\n6", "1\n\n9", "1\n\n4", "1\n\n5", "1\n\n8"], "outputs": ["POSSIBLE\n", "POSSIBLE\n", "POSSIBLE\n", "POSSIBLE\n", "POSSIBLE\n", "POSSIBLE\n", "POSSIBLE\n", "POSSIBLE\n"]}
401
102
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Two players play a turn based game on a binary tree. We are given the root of this binary tree, and the number of nodes n in the tree. n is odd, and each node has a distinct value from 1 to n. Initially, the first pla...
{"functional": "def check(candidate):\n assert candidate(root = tree_node([1,2,3,4,5,6,7,8,9,10,11]), n = 11, x = 3) == True\n assert candidate(root = tree_node([1,2,3]), n = 3, x = 1) == False\n\n\ncheck(Solution().btreeGameWinningMove)"}
364
96
coding
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin Chinese and Russian as well. Andrii is a great programmer. He recently managed to enter Ukrainian IOI team. His parents wanted to appreciate him and present him a DAG(Directed Acyclic Graph). His favourite TV show i...
{"inputs": ["3\n010\n000\n000"], "outputs": ["2\n1 3\n2 3"]}
420
32
coding
Solve the programming task below in a Python markdown code block. The National Championships are starting soon. There are 4 race categories, numbered from 1 to 4, that Chef is interested in. Chef is participating in exactly 2 of these categories. Chef has an arch-rival who is, unfortunately, the only person participa...
{"inputs": ["3\n4 3 1 2\n4 2 1 2\n2 1 1 2"], "outputs": ["2\n1\n0"]}
566
40
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an integer n, return the count of all numbers with unique digits, x, where 0 <= x < 10n.   Please complete the following python code precisely: ```python class Solution: def countNumbersWithUniqueDigits(self...
{"functional": "def check(candidate):\n assert candidate(n = 2) == 91\n assert candidate(n = 0) == 1\n\n\ncheck(Solution().countNumbersWithUniqueDigits)"}
78
47
coding
Solve the programming task below in a Python markdown code block. Given is a tree with N vertices numbered 1 to N, and N-1 edges numbered 1 to N-1. Edge i connects Vertex a_i and b_i bidirectionally and has a length of 1. Snuke will paint each vertex white or black. The niceness of a way of painting the graph is \max(X...
{"inputs": ["2\n1 2\n", "2\n2 1\n", "2\n2 1\n", "6\n1 2\n2 3\n3 4\n4 5\n3 6\n", "35\n25 4\n33 7\n11 26\n32 4\n12 7\n31 27\n19 6\n10 22\n17 12\n28 24\n28 1\n24 15\n30 24\n24 11\n23 18\n14 15\n4 29\n33 24\n15 34\n11 3\n4 35\n5 34\n34 2\n16 19\n7 18\n19 31\n22 8\n13 26\n20 6\n20 9\n4 33\n4 8\n29 19\n15 21\n"], "outputs": ...
354
275
coding
Solve the programming task below in a Python markdown code block. A dial lock is a kind of lock which has some dials with printed numbers. It has a special sequence of numbers, namely an unlocking sequence, to be opened. You are working at a manufacturer of dial locks. Your job is to verify that every manufactured loc...
{"inputs": ["4\n1357 1908\n0\n509138 5249\n0", "4\n1357 1908\n0\n509138 1663\n0", "4\n1357 2529\n0\n509138 1663\n0", "4\n1155 2529\n0\n509138 1663\n0", "4\n1155 2529\n0\n463161 1663\n0", "4\n5501 3524\n0\n829953 5963\n0", "4\n1772 9224\n0\n637757 358\n-1", "4\n1772 7811\n0\n637757 358\n-1"], "outputs": ["3\n", "3\n", "...
582
270
coding
Solve the programming task below in a Python markdown code block. Bear Limak prepares problems for a programming competition. Of course, it would be unprofessional to mention the sponsor name in the statement. Limak takes it seriously and he is going to change some words. To make it still possible to read, he will try ...
{"inputs": ["1\nZ\n", "1\nV\n", "1\nK\n", "1\nY\n", "1\nU\n", "2\nKV\n", "2\nVK\n", "2\nKU\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "1\n", "0\n"]}
499
87
coding
Solve the programming task below in a Python markdown code block. Chef has two binary strings A and B, each of length N. He can perform the following operation on A any number of times: Choose L and R (1 ≤ L ≤ R ≤ N), such that, in the [substring] A[L,R], the number of 1s is not equal to the number of 0s and reverse ...
{"inputs": ["3\n2\n11\n00\n5\n10110\n11001\n2\n10\n01"], "outputs": ["NO\nYES\nNO"]}
616
46
coding
Solve the programming task below in a Python markdown code block. Winter is here at the North and the White Walkers are close. John Snow has an army consisting of n soldiers. While the rest of the world is fighting for the Iron Throne, he is going to get ready for the attack of the White Walkers. He has created a meth...
{"inputs": ["3\n3 3 1\n", "3\n3 4 1\n", "3\n6 4 1\n", "3\n6 6 1\n", "3\n2 4 1\n", "3\n4 3 2\n", "3\n2 6 1\n", "3\n6 9 1\n"], "outputs": ["12\n", "7\n", "14\n", "24\n", "10\n", "13\n", "12\n", "21\n"]}
467
125
coding
Solve the programming task below in a Python markdown code block. ``` ************************* * Create a frame! * * __ __ * * / \~~~/ \ * * ,----( .. ) * * / \__ __/ * * /| (\ |( * * ^ \ /___\ /\ | * * |__| |__|-.. * ****************...
{"functional": "_inputs = [[['Small', 'frame'], '~'], [['Create', 'this', 'kata'], '+'], [['This is a very long single frame'], '-']]\n_outputs = [['~~~~~~~~~\\n~ Small ~\\n~ frame ~\\n~~~~~~~~~'], ['++++++++++\\n+ Create +\\n+ this +\\n+ kata +\\n++++++++++'], ['------------------------------------\\n- This is a v...
226
241
coding
Solve the programming task below in a Python markdown code block. There are $N$ cars (numbered $1$ through $N$) on a circular track with length $N$. For each $i$ ($2 \le i \le N$), the $i$-th of them is at a distance $i-1$ clockwise from car $1$, i.e. car $1$ needs to travel a distance $i-1$ clockwise to reach car $i$....
{"inputs": ["3\n5\n3 0 0 0 0\n5\n1 1 1 1 1\n5\n5 4 3 2 1"], "outputs": ["3\n5\n15"]}
429
53
coding
Solve the programming task below in a Python markdown code block. Background There is a message that is circulating via public media that claims a reader can easily read a message where the inner letters of each words is scrambled, as long as the first and last letters remain the same and the word contains all the lett...
{"functional": "_inputs = [['professionals'], ['i'], [''], ['me'], ['you'], ['card-carrying'], [\"shan't\"], ['-dcba'], ['dcba.'], [\"you've gotta dance like there's nobody watching, love like you'll never be hurt, sing like there's nobody listening, and live like it's heaven on earth.\"]]\n_outputs = [['paefilnoorsss'...
316
324
coding
Solve the programming task below in a Python markdown code block. In winter, the inhabitants of the Moscow Zoo are very bored, in particular, it concerns gorillas. You decided to entertain them and brought a permutation $p$ of length $n$ to the zoo. A permutation of length $n$ is an array consisting of $n$ distinct in...
{"inputs": ["1\n1\n1\n", "3\n1 3 2\n2 1 3\n", "6\n1 2 3 4 5 6\n6 5 4 3 2 1\n", "7\n7 3 6 2 1 5 4\n6 7 2 5 3 1 4\n"], "outputs": ["1\n", "2\n", "11\n", "16\n"]}
715
108
coding
Solve the programming task below in a Python markdown code block. Create a function that transforms any positive number to a string representing the number in words. The function should work for all numbers between 0 and 999999. ### Examples ``` number2words(0) ==> "zero" number2words(1) ==> "one" number2words(9...
{"functional": "_inputs = [[0], [1], [8], [5], [9], [10], [19], [20], [22], [54], [80], [98], [100], [301], [793], [800], [650], [1000], [1003], [3052], [7300], [7217], [8340], [99997], [888887]]\n_outputs = [['zero'], ['one'], ['eight'], ['five'], ['nine'], ['ten'], ['nineteen'], ['twenty'], ['twenty-two'], ['fifty-fo...
448
392
coding
Solve the programming task below in a Python markdown code block. You are given $n$ integer numbers $a_1, a_2, \dots, a_n$. Consider graph on $n$ nodes, in which nodes $i$, $j$ ($i\neq j$) are connected if and only if, $a_i$ AND $a_j\neq 0$, where AND denotes the bitwise AND operation. Find the length of the shortest ...
{"inputs": ["3\n1 1 3\n", "3\n5 5 5\n", "3\n1 1 3\n", "3\n5 5 5\n", "3\n2 1 3\n", "3\n4 5 5\n", "3\n2 2 3\n", "4\n1 2 4 8\n"], "outputs": ["3", "3", "3", "3", "-1\n", "3\n", "3\n", "-1"]}
322
115
coding
Solve the programming task below in a Python markdown code block. Mole is hungry again. He found one ant colony, consisting of n ants, ordered in a row. Each ant i (1 ≤ i ≤ n) has a strength si. In order to make his dinner more interesting, Mole organizes a version of «Hunger Games» for the ants. He chooses two number...
{"inputs": ["5\n1 5 2 4 2\n4\n1 5\n2 5\n3 5\n4 5\n", "5\n1 3 4 4 2\n4\n1 5\n2 5\n3 5\n4 5\n", "5\n1 3 4 4 2\n4\n1 5\n2 5\n3 5\n2 5\n", "5\n1 3 4 4 2\n4\n1 5\n2 5\n1 5\n4 5\n", "5\n1 3 4 4 2\n4\n1 5\n2 5\n1 5\n3 5\n", "5\n1 3 4 4 2\n4\n1 3\n2 5\n1 5\n3 5\n", "5\n1 3 4 2 2\n4\n1 5\n2 5\n3 5\n2 5\n", "5\n1 3 4 4 2\n4\n1 5...
602
342
coding
Solve the programming task below in a Python markdown code block. Catherine received an array of integers as a gift for March 8. Eventually she grew bored with it, and she started calculated various useless characteristics for it. She succeeded to do it for each one she came up with. But when she came up with another o...
{"inputs": ["2\n1 2\n", "2\n1 1\n", "2\n1 1\n", "2\n2 2\n", "2\n2 4\n", "2\n1 4\n", "2\n4 3\n", "2\n8 3\n"], "outputs": ["3", "2", "2\n", "4\n", "6\n", "5\n", "7\n", "11\n"]}
614
101
coding
Solve the programming task below in a Python markdown code block. Read problem statements in [Mandarin Chinese] and [Bengali]. There is an empty bus with M seats and a total of N people, numbered from 1 to N. Everyone is currently outside the bus. You are given a sequence of Q events of the following form. - +\ i : ...
{"inputs": ["2\n2 1 4\n+ 1\n+ 2\n- 1\n- 2\n3 2 6\n+ 2\n+ 1\n- 1\n+ 3\n- 3\n- 2", "2\n100 10 5\n+ 1\n+ 2\n- 3\n+ 3\n- 2\n6 4 4\n+ 3\n+ 2\n+ 1\n+ 4\n"], "outputs": ["Inconsistent\nConsistent", "Inconsistent\nConsistent\n"]}
616
131
coding
Solve the programming task below in a Python markdown code block. Right now she actually isn't. But she will be, if you don't solve this problem. You are given integers n, k, A and B. There is a number x, which is initially equal to n. You are allowed to perform two types of operations: Subtract 1 from x. This opera...
{"inputs": ["9\n2\n3\n1\n", "7\n2\n3\n1\n", "7\n2\n3\n1\n", "7\n2\n1\n1\n", "9\n2\n3\n0\n", "9\n2\n3\n1\n", "5\n5\n2\n20\n", "19\n3\n4\n2\n"], "outputs": ["6\n", "8\n", "8\n", "4\n", "3\n", "6\n", "8\n", "12\n"]}
404
121
coding
Solve the programming task below in a Python markdown code block. VK news recommendation system daily selects interesting publications of one of n disjoint categories for each user. Each publication belongs to exactly one category. For each category i batch algorithm selects a_i publications. The latest A/B test sugge...
{"inputs": ["1\n1\n72\n", "1\n5\n16\n", "1\n3\n31\n", "1\n5\n12\n", "1\n3\n47\n", "1\n5\n15\n", "1\n1\n100\n", "1\n1\n101\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]}
365
112
coding
Solve the programming task below in a Python markdown code block. A sorting algorithm A is said to have more time complexity than a sorting algorithm B if it uses more number of comparisons for sorting the same array than algorithm B. Given that algorithm A uses X comparisons to sort an array and algorithm B uses Y co...
{"inputs": ["4\n9 9\n15 7\n10 19\n21 20\n"], "outputs": ["NO\nYES\nNO\nYES"]}
530
40
coding
Solve the programming task below in a Python markdown code block. Lee was cleaning his house for the party when he found a messy string under the carpets. Now he'd like to make it clean accurately and in a stylish way... The string $s$ he found is a binary string of length $n$ (i. e. string consists only of 0-s and 1-...
{"inputs": ["5\n10\n0001111111\n4\n0101\n8\n11001101\n10\n1110000000\n1\n1\n", "5\n10\n0001111111\n4\n0101\n8\n11001101\n10\n1010000000\n1\n1\n", "5\n10\n0011111111\n4\n0101\n8\n11001101\n10\n1010000000\n1\n1\n", "5\n10\n0001111110\n4\n0101\n8\n11001101\n10\n1110000000\n1\n1\n", "5\n10\n0001111110\n4\n0101\n8\n11001101...
728
624
coding
Solve the programming task below in a Python markdown code block. Giga Tower is the tallest and deepest building in Cyberland. There are 17 777 777 777 floors, numbered from - 8 888 888 888 to 8 888 888 888. In particular, there is floor 0 between floor - 1 and floor 1. Every day, thousands of tourists come to this p...
{"inputs": ["0\n", "2\n", "4\n", "6\n", "8\n", "6\n", "4\n", "2\n"], "outputs": ["8\n", "6\n", "4\n", "2\n", "10\n", "2\n", "4\n", "6\n"]}
436
71
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Write an efficient algorithm that searches for a value target in an m x n integer matrix matrix. This matrix has the following properties: Integers in each row are sorted in ascending from left to right. Integers in ...
{"functional": "def check(candidate):\n assert candidate(matrix = [[1,4,7,11,15],[2,5,8,12,19],[3,6,9,16,22],[10,13,14,17,24],[18,21,23,26,30]], target = 5) == True\n assert candidate(matrix = [[1,4,7,11,15],[2,5,8,12,19],[3,6,9,16,22],[10,13,14,17,24],[18,21,23,26,30]], target = 20) == False\n\n\ncheck(Solution(...
108
180
coding
Solve the programming task below in a Python markdown code block. You task is to implement an simple interpreter for the notorious esoteric language [HQ9+](https://esolangs.org/wiki/HQ9+) that will work for a single character input: - If the input is `'H'`, return `'Hello World!'` - If the input is `'Q'`, return the i...
{"functional": "_inputs = [['X'], ['H'], ['Q']]\n_outputs = [[None], ['Hello World!'], ['Q']]\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):...
412
169
coding
Solve the programming task below in a Python markdown code block. You are given $n$ numbers $a_1, a_2, \dots, a_n$. With a cost of one coin you can perform the following operation: Choose one of these numbers and add or subtract $1$ from it. In particular, we can apply this operation to the same number several times....
{"inputs": ["2\n0 1\n", "2\n0 2\n", "2\n0 0\n", "2\n0 4\n", "2\n1 4\n", "2\n-1 1\n", "2\n-1 0\n", "2\n-1 2\n"], "outputs": ["1\n", "2\n", "2\n", "4\n", "3\n", "2", "1\n", "3\n"]}
527
104
coding
Solve the programming task below in a Python markdown code block. In CODE FESTIVAL XXXX, there are N+1 participants from all over the world, including Takahashi. Takahashi checked and found that the time gap (defined below) between the local times in his city and the i-th person's city was D_i hours. The time gap betw...
{"inputs": ["1\n9", "1\n0", "1\n11", "1\n10", "2\n8 8", "2\n2 0", "2\n6 8", "2\n9 7"], "outputs": ["9\n", "0", "11\n", "10\n", "8\n", "0\n", "6\n", "7\n"]}
353
89
coding
Solve the programming task below in a Python markdown code block. Given is a string S consisting of `0` and `1`. Find the number of strings, modulo 998244353, that can result from applying the following operation on S between 0 and K times (inclusive): * Choose a pair of integers i, j (1\leq i < j\leq |S|) such that t...
{"inputs": ["0111 1", "0111 0", "0011 1", "0001 1", "0011 2", "0101 5", "0011 0", "0101 1"], "outputs": ["2\n", "1\n", "3\n", "4\n", "6\n", "5\n", "1\n", "4"]}
346
101
coding
Solve the programming task below in a Python markdown code block. Problem Given the strings $ s $, $ t $. First, let the string set $ A = $ {$ s $}, $ B = \ phi $. At this time, I want to perform the following operations as much as possible. operation step1 Perform the following processing for all $ u ∊ A $. 1. Fr...
{"inputs": ["AABABCAC\nB", "AACABCAC\nB", "AACABCAC\nC", "AACAACAC\nC", "@ACAACAC\nC", "AABABCAC\nA", "AbCdEfG\naBcDeFh", "AbGdEfC\naBcDeFh"], "outputs": ["1\n", "1\n", "2\n", "2\n", "2\n", "2", "0\n", "0\n"]}
642
109
coding
Solve the programming task below in a Python markdown code block. You are given a string $S$. Find the number of ways to choose an unordered pair of non-overlapping non-empty substrings of this string (let's denote them by $s_1$ and $s_2$ in such a way that $s_2$ starts after $s_1$ ends) such that their concatenation $...
{"inputs": ["abba"], "outputs": ["7"]}
335
13
coding
Solve the programming task below in a Python markdown code block. The new "Avengers" movie has just been released! There are a lot of people at the cinema box office standing in a huge line. Each of them has a single `100`, `50` or `25` dollar bill. An "Avengers" ticket costs `25 dollars`. Vasya is currently working a...
{"functional": "_inputs = [[[25, 25, 50]], [[25, 25, 50, 100]], [[25, 100]], [[25, 25, 25, 25, 25, 25, 25, 25, 25, 25]], [[50, 50, 50, 50, 50, 50, 50, 50, 50, 50]], [[100, 100, 100, 100, 100, 100, 100, 100, 100, 100]], [[25, 25, 25, 25, 50, 100, 50]], [[50, 100, 100]], [[25, 25, 100]], [[25, 25, 25, 25, 25, 25, 25, 50,...
551
887
coding
Solve the programming task below in a Python markdown code block. There is an N-car train. You are given an integer i. Find the value of j such that the following statement is true: "the i-th car from the front of the train is the j-th car from the back." -----Constraints----- - 1 \leq N \leq 100 - 1 \leq i \leq N ...
{"inputs": ["2 1", "2 2", "4 1", "2 0", "9 1", "1 1", "4 2", "4 2\n"], "outputs": ["2\n", "1\n", "4\n", "3\n", "9\n", "1", "3", "3\n"]}
148
77
coding
Solve the programming task below in a Python markdown code block. Given an array of ones and zeroes, convert the equivalent binary value to an integer. Eg: `[0, 0, 0, 1]` is treated as `0001` which is the binary representation of `1`. Examples: ``` Testing: [0, 0, 0, 1] ==> 1 Testing: [0, 0, 1, 0] ==> 2 Testing: [0, ...
{"functional": "_inputs = [[[0, 0, 0, 1]], [[0, 0, 1, 0]], [[1, 1, 1, 1]], [[0, 1, 1, 0]]]\n_outputs = [[1], [2], [15], [6]]\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))...
255
211
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given two strings text1 and text2, return the length of their longest common subsequence. If there is no common subsequence, return 0. A subsequence of a string is a new string generated from the original string with ...
{"functional": "def check(candidate):\n assert candidate(text1 = \"abcde\", text2 = \"ace\" ) == 3 \n assert candidate(text1 = \"abc\", text2 = \"abc\") == 3\n assert candidate(text1 = \"abc\", text2 = \"def\") == 0\n\n\ncheck(Solution().longestCommonSubsequence)"}
153
83
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given three integers, k, digit1, and digit2, you want to find the smallest integer that is: Larger than k, A multiple of k, and Comprised of only the digits digit1 and/or digit2. Return the smallest such integer. If...
{"functional": "def check(candidate):\n assert candidate(k = 2, digit1 = 0, digit2 = 2) == 20\n assert candidate(k = 3, digit1 = 4, digit2 = 2) == 24\n assert candidate(k = 2, digit1 = 0, digit2 = 0) == -1\n\n\ncheck(Solution().findInteger)"}
143
93
coding
Solve the programming task below in a Python markdown code block. You are given an undirected graph consisting of N vertices and M edges. The vertices are numbered 1 to N, and the edges are numbered 1 to M. In addition, each vertex has a label, `A` or `B`. The label of Vertex i is s_i. Edge i bidirectionally connects v...
{"inputs": ["2 3\nAA\n1 1\n1 2\n2 2", "2 3\nAA\n1 2\n1 2\n2 2", "2 3\nBA\n1 1\n1 2\n2 2", "2 3\nBA\n2 1\n1 2\n2 2", "2 3\nBA\n1 1\n1 2\n2 1", "2 3\nBA\n2 2\n1 2\n2 2", "2 3\nAB\n1 1\n1 2\n2 2", "4 3\nABAB\n1 1\n2 3\n3 1"], "outputs": ["No\n", "No\n", "Yes\n", "No\n", "No\n", "No\n", "Yes", "No\n"]}
644
190
coding
Solve the programming task below in a Python markdown code block. An elephant decided to visit his friend. It turned out that the elephant's house is located at point 0 and his friend's house is located at point x(x > 0) of the coordinate line. In one step the elephant can move 1, 2, 3, 4 or 5 positions forward. Determ...
{"inputs": ["5\n", "1\n", "2\n", "3\n", "4\n", "3\n", "1\n", "4\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n"]}
254
70
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an integer num, return the number of steps to reduce it to zero. In one step, if the current number is even, you have to divide it by 2, otherwise, you have to subtract 1 from it.   Please complete the following...
{"functional": "def check(candidate):\n assert candidate(num = 14) == 6\n assert candidate(num = 8) == 4\n assert candidate(num = 123) == 12\n\n\ncheck(Solution().numberOfSteps)"}
94
59
coding
Solve the programming task below in a Python markdown code block. You can find anything whatsoever in our Galaxy! A cubical planet goes round an icosahedral star. Let us introduce a system of axes so that the edges of the cubical planet are parallel to the coordinate axes and two opposite vertices lay in the points (0,...
{"inputs": ["1 0 0\n0 0 0\n", "1 1 0\n0 0 1\n", "1 1 1\n0 1 1\n", "0 0 1\n1 0 0\n", "1 1 1\n0 0 0\n", "1 0 0\n0 1 0\n", "1 0 0\n0 1 1\n", "0 0 1\n1 0 1\n"], "outputs": ["YES\n", "NO\n", "YES\n", "YES\n", "NO\n", "YES\n", "NO\n", "YES\n"]}
254
150
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. There is a garland — a cyclic rope with red and green flowers on it in some order. The sequence of flower colours is described by a string $s$; since...
{"inputs": ["3\nRG\nRRGG\nRR"], "outputs": ["yes\nyes\nno"]}
464
23
coding
Solve the programming task below in a Python markdown code block. The chef is trying to solve some pattern problems, Chef wants your help to code it. Chef has one number K (odd) to form a new pattern. Help the chef to code this pattern problem. -----Input:----- - First-line will contain $T$, the number of test cases. ...
{"inputs": ["4\n1\n3\n5\n7"], "outputs": ["*\n*\n**\n*\n*\n**\n* *\n**\n*\n*\n**\n* *\n* *\n* *\n**\n*"]}
200
60
coding
Solve the programming task below in a Python markdown code block. There are $n$ rectangles in a row. You can either turn each rectangle by $90$ degrees or leave it as it is. If you turn a rectangle, its width will be height, and its height will be width. Notice that you can turn any number of rectangles, you also can t...
{"inputs": ["1\n1 1\n", "1\n1 1\n", "1\n1 2\n", "1\n2 2\n", "1\n3 2\n", "1\n4 2\n", "1\n0 2\n", "2\n3 4\n5 5\n"], "outputs": ["YES\n", "YES\n", "YES\n", "YES\n", "YES\n", "YES\n", "YES\n", "NO\n"]}
375
106
coding
Solve the programming task below in a Python markdown code block. Hexadecimal likes drawing. She has drawn many graphs already, both directed and not. Recently she has started to work on a still-life «interesting graph and apples». An undirected graph is called interesting, if each of its vertices belongs to one cycle ...
{"inputs": ["1 0\n", "2 0\n", "6 0\n", "50 0\n", "49 0\n", "49 0\n", "50 0\n", "6 1\n4 1\n"], "outputs": ["YES\n1\n1 1\n", "YES\n2\n1 2\n1 2\n", "YES\n6\n1 2\n1 3\n2 4\n3 5\n4 6\n5 6\n", "YES\n50\n1 2\n1 3\n2 4\n3 5\n4 6\n5 7\n6 8\n7 9\n8 10\n9 11\n10 12\n11 13\n12 14\n13 15\n14 16\n15 17\n16 18\n17 19\n18 20\n19 21\n2...
491
1,286
coding
Solve the programming task below in a Python markdown code block. There are N cities. There are also K roads and L railways, extending between the cities. The i-th road bidirectionally connects the p_i-th and q_i-th cities, and the i-th railway bidirectionally connects the r_i-th and s_i-th cities. No two roads connect...
{"inputs": ["4 3 1\n1 2\n2 3\n3 4\n2 3\n", "4 2 2\n1 2\n2 3\n1 4\n2 3\n", "7 4 4\n1 2\n2 3\n2 5\n6 7\n3 5\n4 5\n3 4\n6 7\n"], "outputs": ["1 2 2 1\n", "1 2 2 1\n", "1 1 2 1 2 2 2\n"]}
431
130
coding
Solve the programming task below in a Python markdown code block. Snuke loves flags. Snuke is placing N flags on a line. The i-th flag can be placed at either coordinate x_i or coordinate y_i. Snuke thinks that the flags look nicer when the smallest distance between two of them, d, is larger. Find the maximum possib...
{"inputs": ["3\n1 3\n2 5\n2 9", "3\n2 3\n2 5\n2 9", "3\n1 3\n2 5\n1 9", "3\n3 3\n2 5\n2 16", "3\n4 0\n5 0\n1 21", "3\n2 1\n8 0\n1 45", "3\n2 3\n2 5\n2 16", "3\n3 3\n2 5\n1 16"], "outputs": ["4\n", "3\n", "4", "2\n", "5\n", "7\n", "3\n", "2\n"]}
379
162
coding
Solve the programming task below in a Python markdown code block. Phone number in Berland is a sequence of n digits. Often, to make it easier to memorize the number, it is divided into groups of two or three digits. For example, the phone number 1198733 is easier to remember as 11-987-33. Your task is to find for a giv...
{"inputs": ["2\n74\n", "2\n33\n", "2\n24\n", "2\n46\n", "2\n15\n", "2\n16\n", "2\n22\n", "2\n71\n"], "outputs": ["74\n", "33\n", "24\n", "46\n", "15\n", "16\n", "22\n", "71\n"]}
224
102
coding
Solve the programming task below in a Python markdown code block. # Task Some children are playing rope skipping game. Children skip the rope at roughly the same speed: `once per second`. If the child fails during the jump, he needs to tidy up the rope and continue. This will take `3 seconds`. You are given an array `...
{"functional": "_inputs = [[[]], [[12, 23, 45]], [[17]], [[10, 20, 30, 40]], [[10, 20, 30, 40, 58]], [[10, 20, 30, 40, 47, 60]], [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]]]\n_outputs = [[60], [51], [57], [48], [48], [47], [30]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n ...
481
288
coding
Solve the programming task below in a Python markdown code block. Vasya is an active Internet user. One day he came across an Internet resource he liked, so he wrote its address in the notebook. We know that the address of the written resource has format: <protocol>://<domain>.ru[/<context>] where: <protocol> can eq...
{"inputs": ["ftprru\n", "ftprru\n", "ftparua\n", "httpzru\n", "ftparua\n", "httpzru\n", "httprrur\n", "httprrur\n"], "outputs": ["ftp://r.ru\n", "ftp://r.ru", "ftp://a.ru/a\n", "http://z.ru\n", "ftp://a.ru/a\n", "http://z.ru", "http://r.ru/r\n", "http://r.ru/r\n"]}
426
112
coding
Solve the programming task below in a Python markdown code block. Scientists working internationally use metric units almost exclusively. Unless that is, they wish to crash multimillion dollars worth of equipment on Mars. Your task is to write a simple function that takes a number of meters, and outputs it using metri...
{"functional": "_inputs = [[1], [999], [123456], [12300000], [9000000000.0], [9000000000000.0], [9000000000000000.0], [9e+18], [9e+21], [9e+24]]\n_outputs = [['1m'], ['999m'], ['123.456km'], ['12.3Mm'], ['9Gm'], ['9Tm'], ['9Pm'], ['9Em'], ['9Zm'], ['9Ym']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(...
243
303
coding
Solve the programming task below in a Python markdown code block. Given a sequence of items and a specific item in that sequence, return the item immediately following the item specified. If the item occurs more than once in a sequence, return the item after the first occurence. This should work for a sequence of any t...
{"functional": "_inputs = [[[1, 2, 3, 4, 5, 6, 7, 8], 3], [['a', 'b', 'c'], 'd'], [['a', 'b', 'c'], 'c'], ['testing', 't'], ['Hello!', 'o'], ['Hello!', '!'], ['Hello!', 'x']]\n_outputs = [[4], [None], [None], ['e'], ['!'], [None], [None]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isins...
180
243
coding
Solve the programming task below in a Python markdown code block. Mr. Vincent works in a door mat manufacturing company. One day, he designed a new door mat with the following specifications: Mat size must be $N$X$\mbox{M}$. ($N$ is an odd natural number, and $\mbox{M}$ is $3$ times $N$.) The design should have 'WELC...
{"inputs": ["9 27\n"], "outputs": ["------------.|.------------\n---------.|..|..|.---------\n------.|..|..|..|..|.------\n---.|..|..|..|..|..|..|.---\n----------WELCOME----------\n---.|..|..|..|..|..|..|.---\n------.|..|..|..|..|.------\n---------.|..|..|.---------\n------------.|.------------\n"]}
459
113
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. There is a one-dimensional garden on the x-axis. The garden starts at the point 0 and ends at the point n. (i.e., the length of the garden is n). There are n + 1 taps located at points [0, 1, ..., n] in the garden. Gi...
{"functional": "def check(candidate):\n assert candidate(n = 5, ranges = [3,4,1,1,0,0]) == 1\n assert candidate(n = 3, ranges = [0,0,0,0]) == -1\n\n\ncheck(Solution().minTaps)"}
191
70
coding
Solve the programming task below in a Python markdown code block. # Right in the Center _This is inspired by one of Nick Parlante's exercises on the [CodingBat](https://codingbat.com/java) online code practice tool._ Given a sequence of characters, does `"abc"` appear in the CENTER of the sequence? The sequence of c...
{"functional": "_inputs = [['abc'], ['abcabcabc'], ['AAabcBBB'], ['AAAabcBB'], ['AAAAabcBB'], ['AAabcabcBB'], ['abcabcabcabc'], ['AabcBBB'], [''], ['ABC'], ['abcZ'], ['Yabc']]\n_outputs = [[True], [True], [True], [True], [False], [False], [False], [False], [False], [False], [True], [True]]\nimport math\ndef _deep_eq(a,...
222
240
coding
Solve the programming task below in a Python markdown code block. One day Polycarpus got hold of two non-empty strings s and t, consisting of lowercase Latin letters. Polycarpus is quite good with strings, so he immediately wondered, how many different pairs of "x y" are there, such that x is a substring of string s, y...
{"inputs": ["a\nb\n", "`\nb\n", "`\nc\n", "_\nb\n", "_\na\n", "b\nab\n", "ab\na\n", "b\nba\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "1\n", "1\n", "1\n"]}
645
82
coding
Solve the programming task below in a Python markdown code block. Chef has a binary string S of length N. In one operation, Chef can: Select two indices i and j (1 ≤ i, j ≤ N, i \ne j) and flip S_{i} and S_{j}. (i.e. change 0 to 1 and 1 to 0) For example, if S = 10010 and chef applys operation on i = 1 and j = 3 the...
{"inputs": ["3\n6\n101011\n2\n01\n7\n1110000\n"], "outputs": ["YES\nNO\nYES\n"]}
637
42
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an array of strings names of size n. You will create n folders in your file system such that, at the ith minute, you will create a folder with the name names[i]. Since two files cannot have the same name, if you...
{"functional": "def check(candidate):\n assert candidate(names = [\"pes\",\"fifa\",\"gta\",\"pes(2019)\"]) == [\"pes\",\"fifa\",\"gta\",\"pes(2019)\"]\n assert candidate(names = [\"gta\",\"gta(1)\",\"gta\",\"avalon\"]) == [\"gta\",\"gta(1)\",\"gta(2)\",\"avalon\"]\n assert candidate(names = [\"onepiece\",\"one...
170
295
coding
Solve the programming task below in a Python markdown code block. Fangy the little walrus, as all the modern walruses, loves to communicate via text messaging. One day he faced the following problem: When he sends large texts, they are split into parts each containing n characters (which is the size of one text message...
{"inputs": ["2\na. b.\n", "4\na. A.\n", "2\na- b.\n", "8\nabc! ab.\n", "5\nabc. abcd.\n", "5\na. b. c. d.\n", "5\na. b. c- d.\n", "5\na. b/ c- d.\n"], "outputs": ["2\n", "2\n", "Impossible\n", "1\n", "2\n", "2\n", "2\n", "Impossible\n"]}
442
123
coding
Solve the programming task below in a Python markdown code block. The stardate is 1983, and Princess Heidi is getting better at detecting the Death Stars. This time, two Rebel spies have yet again given Heidi two maps with the possible locations of the Death Star. Since she got rid of all double agents last time, she k...
{"inputs": ["1 1\ng\ng\n", "1 1\ng\ng\n", "10 5\nsomer\nandom\nnoise\nmayth\neforc\nebewi\nthyou\nhctwo\nagain\nnoise\nsomermayth\nandomeforc\nnoiseebewi\nagainthyou\nnoisehctwo\n", "10 5\nsomer\nandom\nnoise\nmayth\neforc\nebewi\nthyou\nhctwo\nagain\nooise\nsomermayth\nandomeforc\nnoiseebewi\nagainthyou\nnoisehctwo\n"...
499
432
coding
Solve the programming task below in a Python markdown code block. You are given a permutation p of length n. Remove one element from permutation to make the number of records the maximum possible. We remind that in a sequence of numbers a_1, a_2, ..., a_{k} the element a_{i} is a record if for every integer j (1 ≤ j <...
{"inputs": ["1\n1\n", "1\n1\n", "3\n3 2 1\n", "3\n3 2 1\n", "5\n5 1 2 3 4\n", "5\n4 3 5 1 2\n", "5\n2 3 4 1 5\n", "5\n1 2 3 4 5\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "5\n", "1\n", "1\n", "1\n"]}
246
126
coding
Solve the programming task below in a Python markdown code block. Artem has an array of n positive integers. Artem decided to play with it. The game consists of n moves. Each move goes like this. Artem chooses some element of the array and removes it. For that, he gets min(a, b) points, where a and b are numbers that w...
{"inputs": ["1\n4\n", "1\n4\n", "1\n1\n", "1\n87\n", "1\n87\n", "1\n79\n", "1\n41\n", "1\n52\n"], "outputs": ["0\n", "0", "0\n", "0\n", "0", "0\n", "0\n", "0\n"]}
298
89
coding
Solve the programming task below in a Python markdown code block. We have a string S of length N consisting of A, B, and C. You can do the following operation on S zero or more times: - Choose i (1 \leq i \leq |S| - 1) such that S_i \neq S_{i + 1}. Replace S_i with the character (among A, B, and C) that is different f...
{"inputs": ["1\nA\n", "1\nB\n", "1\nC\n", "2\nAB\n", "2\nAC\n", "2\nBA\n", "2\nBC\n", "2\nCA\n"], "outputs": ["1\n", "1\n", "1\n", "2\n", "2\n", "2\n", "2\n", "2\n"]}
313
86
coding
Solve the programming task below in a Python markdown code block. ## Problem Determine whether a positive integer number is **colorful** or not. `263` is a colorful number because `[2, 6, 3, 2*6, 6*3, 2*6*3]` are all different; whereas `236` is not colorful, because `[2, 3, 6, 2*3, 3*6, 2*3*6]` have `6` twice. So ta...
{"functional": "_inputs = [[5], [23], [263], [235789], [50], [13], [236], [2357893]]\n_outputs = [[True], [True], [True], [True], [False], [False], [False], [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=...
180
214
coding
Solve the programming task below in a Python markdown code block. Rikhail Mubinchik believes that the current definition of prime numbers is obsolete as they are too complex and unpredictable. A palindromic number is another matter. It is aesthetically pleasing, and it has a number of remarkable properties. Help Rikhai...
{"inputs": ["1 1\n", "6 4\n", "3 1\n", "5 8\n", "4 9\n", "5 8\n", "4 9\n", "3 1\n"], "outputs": ["40\n", "172\n", "2530\n", "16\n", "10\n", "16", "10", "2530"]}
402
96
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 only of lowercase English letters. We call a substring special if it contains no character which has occurred at least twice (in other words, it does not contain a repeating charact...
{"functional": "def check(candidate):\n assert candidate(s = \"abcd\") == 10\n assert candidate(s = \"ooo\") == 3\n assert candidate(s = \"abab\") == 7\n\n\ncheck(Solution().numberOfSpecialSubstrings)"}
179
59
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You have k bags. You are given a 0-indexed integer array weights where weights[i] is the weight of the ith marble. You are also given the integer k. Divide the marbles into the k bags according to the following rules:...
{"functional": "def check(candidate):\n assert candidate(weights = [1,3,5,1], k = 2) == 4\n assert candidate(weights = [1, 3], k = 2) == 0\n\n\ncheck(Solution().putMarbles)"}
209
63
coding
Solve the programming task below in a Python markdown code block. You have N cups and 1 ball. The cups are arranged in a row, from left to right. You turned down all the cups, then inserted the ball into the leftmost cup. Then, you will perform the following Q operations: * The i-th operation: swap the positions of...
{"inputs": ["10 3\n1 3\n2 8\n4 5", "10 3\n1 3\n2 8\n4 2", "14 1\n1 3\n2 8\n5 5", "14 3\n2 1\n2 8\n5 7", "10 3\n1 3\n2 8\n5 5", "10 3\n1 3\n2 8\n4 1", "14 3\n1 3\n2 8\n5 5", "14 1\n1 3\n4 8\n5 5"], "outputs": ["5\n", "4\n", "3\n", "6\n", "4\n", "5\n", "4\n", "3\n"]}
371
182
coding
Solve the programming task below in a Python markdown code block. You are given an integer, $N$. Write a program to determine if $N$ is an element of the Fibonacci sequence. The first few elements of the Fibonacci sequence are $0,1,1,2,3,5,8,13,\cdots$. A Fibonacci sequence is one where every element is a sum of the...
{"inputs": ["3\n5\n7\n8\n"], "outputs": ["IsFibo\nIsNotFibo\nIsFibo\n"]}
401
31
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 defined a new type of rooted tree - divisor tree. In this tree, every node has a positive integer written on it. It follows some rules: The root can have any positiv...
{"inputs": ["11 12", "932451 935212"], "outputs": ["14", "101245"]}
714
40
coding
Solve the programming task below in a Python markdown code block. You are given two integers $l$ and $r$, $l\le r$. Find the largest possible value of $a mod b$ over all pairs $(a, b)$ of integers for which $r\ge a \ge b \ge l$. As a reminder, $a mod b$ is a remainder we get when dividing $a$ by $b$. For example, $26 ...
{"inputs": ["4\n1 1\n9312924 1000001000\n6 51\n1 481905067\n", "4\n1 1\n7655209 1000001000\n6 85\n1 481905067\n", "4\n1 1\n9312924 1000001000\n6 70\n1 481905067\n", "4\n1 1\n7655209 1000001000\n6 56\n1 481905067\n", "4\n1 1\n2508889 1010100000\n9 26\n1 999999999\n", "4\n1 1\n2508889 1010100000\n9 42\n1 999999999\n", "4...
393
574
coding
Solve the programming task below in a Python markdown code block. Cheesy Cheeseman just got a new monitor! He is happy with it, but he just discovered that his old desktop wallpaper no longer fits. He wants to find a new wallpaper, but does not know which size wallpaper he should be looking for, and alas, he just threw...
{"functional": "_inputs = [[1024, '4:3'], [1280, '16:9'], [3840, '32:9'], [1600, '4:3'], [1280, '5:4'], [2160, '3:2'], [1920, '16:9'], [5120, '32:9']]\n_outputs = [['1024x768'], ['1280x720'], ['3840x1080'], ['1600x1200'], ['1280x1024'], ['2160x1440'], ['1920x1080'], ['5120x1440']]\nimport math\ndef _deep_eq(a, b, tol=1...
167
327
coding
Solve the programming task below in a Python markdown code block. Harish has decided to go to Arya's hotel this morning. We all know he is crazy for masala dosas. And as usual he is always hungry. He decided to order all the masala dosas at once. But then he realised that he did not have enough money to buy all of them...
{"inputs": ["2\n16\n27"], "outputs": ["YES\nNO"]}
353
20
coding
Solve the programming task below in a Python markdown code block. problem AOR Ika made a set $ S = \\ {a_1, ..., a_N \\} $ and a map $ f: S → S $. $ f (a_i) = b_i $. For any element $ x $ in the set $ S $, all maps $ g, h: S → S $ satisfying $ g (f (x)) = h (f (x)) $ are $ g (x). ) = Determine if h (x) $ is satisfied,...
{"inputs": ["5\n2 1 3 4 5\n3 4 2 5 1", "5\n1 2 3 4 5\n2 4 3 5 1", "5\n1 3 2 4 5\n3 4 2 5 1", "5\n2 1 3 4 5\n2 4 3 5 1", "5\n1 4 3 2 5\n3 4 2 5 1", "5\n2 1 3 4 5\n3 4 2 5 1", "5\n1 2 3 4 5\n2 4 3 5 1", "5\n2 1 3 4 5\n3 4 1 5 2"], "outputs": ["Yes\n", "Yes\n", "Yes\n", "Yes\n", "Yes\n", "Yes\n", "Yes\n", "Yes\n"]}
153
222
coding
Solve the programming task below in a Python markdown code block. Takahashi will take part in an eating contest. Teams of N members will compete in this contest, and Takahashi's team consists of N players numbered 1 through N from youngest to oldest. The consumption coefficient of Member i is A_i. In the contest, N foo...
{"inputs": ["3 1\n4 2 1\n2 3 1", "3 6\n4 2 1\n2 3 1", "3 1\n8 2 1\n2 3 1", "3 8\n4 1 1\n2 3 1", "3 1\n2 2 1\n2 3 1", "3 6\n4 4 1\n2 3 1", "3 2\n8 2 1\n2 3 1", "3 1\n8 2 1\n1 3 1"], "outputs": ["4\n", "1\n", "7\n", "0\n", "3\n", "2\n", "6\n", "7\n"]}
565
174
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. In the universe Earth C-137, Rick discovered a special form of magnetic force between two balls if they are put in his new invented basket. Rick has n empty baskets, the ith basket is at position[i], Morty has m balls...
{"functional": "def check(candidate):\n assert candidate(position = [1,2,3,4,7], m = 3) == 3\n assert candidate(position = [5,4,3,2,1,1000000000], m = 2) == 999999999\n\n\ncheck(Solution().maxDistance)"}
159
88
coding
Solve the programming task below in a Python markdown code block. British mathematician John Littlewood once said about Indian mathematician Srinivasa Ramanujan that "every positive integer was one of his personal friends." It turns out that positive integers can also be friends with each other! You are given an array...
{"inputs": ["1\n3\n2 8943586220 45777194315\n", "1\n3\n2 7886764954 45777194315\n", "1\n3\n1 8943586220 276932169986\n", "1\n3\n1 8943586220 328707442366\n", "1\n3\n2 8943586220 328707442366\n", "1\n3\n2 8943586220 630301212521\n", "1\n3\n2 8943586220 844669376002\n", "1\n3\n2 8943586220 275585903615\n"], "outputs": ["...
546
292
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. A binary string is monotone increasing if it consists of some number of 0's (possibly none), followed by some number of 1's (also possibly none). You are given a binary string s. You can flip s[i] changing it from 0 t...
{"functional": "def check(candidate):\n assert candidate(s = \"00110\") == 1\n assert candidate(s = \"010110\") == 2\n assert candidate(s = \"00011000\") == 2\n\n\ncheck(Solution().minFlipsMonoIncr)"}
128
75
coding
Solve the programming task below in a Python markdown code block. -----Problem Statement----- Chef studies combinatorics. He tries to group objects by their rang (a positive integer associated with each object). He also gives the formula for calculating the number of different objects with rang N as following: the num...
{"inputs": ["4\n1 0 0 0\n1\n1 0 0 0\n3\n0 1 0 0\n2\n2 3 1 4\n10", "4\n1 0 0 0\n1\n1 0 0 0\n3\n0 1 0 0\n2\n2 3 1 4\n12", "4\n1 0 0 0\n1\n1 0 0 0\n3\n0 1 0 0\n2\n3 3 1 4\n10", "4\n2 0 0 0\n1\n1 0 0 0\n3\n0 1 0 0\n2\n2 3 1 4\n12", "4\n2 0 1 0\n1\n1 0 0 0\n3\n0 1 0 0\n2\n2 3 1 4\n12", "4\n2 0 1 0\n1\n1 0 0 0\n5\n0 1 0 0\n2...
619
501
coding
Solve the programming task below in a Python markdown code block. PolandBall is a young, clever Ball. He is interested in prime numbers. He has stated a following hypothesis: "There exists such a positive integer n that for each positive integer m number n·m + 1 is a prime number". Unfortunately, PolandBall is not exp...
{"inputs": ["3\n", "4\n", "1\n", "2\n", "5\n", "6\n", "7\n", "8\n"], "outputs": ["1", "2", "3", "4", "1", "4", "1", "1"]}
313
62
coding
Solve the programming task below in a Python markdown code block. There are only 2 type of denominations in Chefland: Coins worth 1 rupee each Notes worth 10 rupees each Chef wants to pay his friend exactly X rupees. What is the minimum number of coins Chef needs to pay exactly X rupees? ------ Input Format ------ ...
{"inputs": ["4\n53\n100\n9\n11\n"], "outputs": ["3\n0\n9\n1\n"]}
293
32