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 are an integer X and an integer sequence of length N: p_1, \ldots, p_N. Among the integers not contained in the sequence p_1, \ldots, p_N (not necessarily positive), find the integer nearest to X, that is, find the integer whose absolute difference...
{"inputs": ["1 0\n\n", "101 0", "100 0", "1 1\n1\n", "100 0\n\n", "100 2\n100 99\n", "3 1\n4 5 1 1 0", "3 2\n4 2 1 8 3"], "outputs": ["1\n", "101\n", "100", "0\n", "100\n", "101\n", "3\n", "5\n"]}
257
128
coding
Solve the programming task below in a Python markdown code block. Complete the function `scramble(str1, str2)` that returns `true` if a portion of ```str1``` characters can be rearranged to match ```str2```, otherwise returns ```false```. **Notes:** * Only lower case letters will be used (a-z). No punctuation or digi...
{"functional": "_inputs = [['rkqodlw', 'world'], ['cedewaraaossoqqyt', 'codewars'], ['katas', 'steak'], ['scriptjavx', 'javascript'], ['scriptingjava', 'javascript'], ['scriptsjava', 'javascripts'], ['javscripts', 'javascript'], ['aabbcamaomsccdd', 'commas'], ['commas', 'commas'], ['sammoc', 'commas']]\n_outputs = [[Tr...
170
270
coding
Solve the programming task below in a Python markdown code block. Read problems statements in [Hindi], [Mandarin Chinese], [Vietnamese], and [Bengali] as well. A semester in Chef's University has $120$ working days. The University's requirement is that a student should be present for at least $75\%$ of the working da...
{"inputs": ["3\n50\n00000000000000000000000000000000000000000000000000\n50\n01010101010101010101010101010101010101010101010101\n2\n01"], "outputs": ["NO\nYES\nYES"]}
620
129
coding
Solve the programming task below in a Python markdown code block. We have sticks numbered 1, \cdots, N. The length of Stick i (1 \leq i \leq N) is L_i. In how many ways can we choose three of the sticks with different lengths that can form a triangle? That is, find the number of triples of integers (i, j, k) (1 \leq i ...
{"inputs": ["1\n1\n", "2\n1 0", "2\n0 0", "2\n0 1", "2\n3 0", "2\n3 1", "2\n2 1", "2\n2 2"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]}
316
93
coding
Solve the programming task below in a Python markdown code block. I bought food at the store to make a lunch box to eat at lunch. At the store, I only got an elongated bag to put food in, so I had to stack all the food vertically and put it in the bag. I want to pack the bag with the heavy ones down so that it won't fa...
{"inputs": ["4\nsandwich 80 120\napple 50 200\ncheese 20 40\ncake 100 100\n9\nonigiri 66 300\nonigiri 80 300\nanpan 70 85\nmikan 50 80\nkenyuma 100 500\nchocolaud 50 350\ncookie 30 80\npusni 40 400\ncracker 40 275\n0", "4\ntandwich 80 120\napple 50 200\ncheese 14 5\ncake 100 100\n9\nonigiri 80 300\nonigiri 80 300\nnapn...
664
1,480
coding
Solve the programming task below in a Python markdown code block. Takahashi is taking exams on N subjects. The score on each subject will be an integer between 0 and K (inclusive). He has already taken exams on N-1 subjects and scored A_i points on the i-th subject. His goal is to achieve the average score of M points ...
{"inputs": ["2 1 1\n0\n", "4 100 60\n0 0 0\n", "5 10 7\n8 10 3 6\n", "5 20 10\n7 7 8 8\n", "5 20 10\n7 7 7 8\n", "5 20 10\n12 12 12 13\n", "5 20 10\n12 12 13 13\n", "4 100 60\n100 100 100\n"], "outputs": ["-1\n", "-1\n", "8\n", "20\n", "-1\n", "1\n", "0\n", "0\n"]}
292
188
coding
Solve the programming task below in a Python markdown code block. You are given a sequence of a journey in London, UK. The sequence will contain bus **numbers** and TFL tube names as **strings** e.g. ```python ['Northern', 'Central', 243, 1, 'Victoria'] ``` Journeys will always only contain a combination of tube names...
{"functional": "_inputs = [[[12, 'Central', 'Circle', 21]], [['Piccidilly', 56]], [['Northern', 'Central', 'Circle']], [['Piccidilly', 56, 93, 243]], [[386, 56, 1, 876]], [[]]]\n_outputs = [['\u00a37.80'], ['\u00a33.90'], ['\u00a37.20'], ['\u00a35.40'], ['\u00a33.00'], ['\u00a30.00']]\nimport math\ndef _deep_eq(a, b, t...
202
292
coding
Solve the programming task below in a Python markdown code block. The only difference between easy and hard versions is the maximum value of $n$. You are given a positive integer number $n$. You really love good numbers so you want to find the smallest good number greater than or equal to $n$. The positive integer is...
{"inputs": ["1\n6\n", "1\n8\n", "1\n662\n", "1\n937\n", "1\n150\n", "1\n719\n", "1\n940\n", "1\n435\n"], "outputs": ["9\n", "9\n", "729\n", "972\n", "243\n", "729\n", "972\n", "729\n"]}
619
110
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 once had a deep epiphany and ended up saying: Given a sequence of positive integers $a_{1}, a_{2}, \ldots, a_{N}$, if you take each of its $2^{N...
{"inputs": ["2\n2\n1 1\n3\n1 9 8"], "outputs": ["3\n27"]}
334
29
coding
Solve the programming task below in a Python markdown code block. Create a function `isAlt()` that accepts a string as an argument and validates whether the vowels (a, e, i, o, u) and consonants are in alternate order. ```python is_alt("amazon") // true is_alt("apple") // false is_alt("banana") // true ``` Arguments ...
{"functional": "_inputs = [['amazon'], ['apple'], ['banana'], ['orange'], ['helipad'], ['yay']]\n_outputs = [[True], [False], [True], [False], [True], [True]]\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 ...
108
187
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Alice and Bob continue their games with stones. There is a row of n stones, and each stone has an associated value. You are given an integer array stones, where stones[i] is the value of the ith stone. Alice and Bob t...
{"functional": "def check(candidate):\n assert candidate(stones = [2,1]) == True\n assert candidate(stones = [2]) == False\n assert candidate(stones = [5,1,2,4,3]) == False\n\n\ncheck(Solution().stoneGameIX)"}
179
66
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 goal. You want to choose a subsequence of nums such that the sum of its elements is the closest possible to goal. That is, if the sum of the subsequence's elements is...
{"functional": "def check(candidate):\n assert candidate(nums = [5,-7,3,5], goal = 6) == 0\n assert candidate(nums = [7,-9,15,-2], goal = -5) == 1\n assert candidate(nums = [1,2,3], goal = -7) == 7\n\n\ncheck(Solution().minAbsDifference)"}
154
88
coding
Solve the programming task below in a Python markdown code block. If Give an integer N . Write a program to obtain the sum of the first and last digits of this number. -----Input----- The first line contains an integer T, the total number of test cases. Then follow T lines, each line contains an integer N. -----Out...
{"inputs": ["3\n1234\n124894\n242323"], "outputs": ["5\n5\n5"]}
153
35
coding
Solve the programming task below in a Python markdown code block. This task will exclusively concentrate only on the arrays where all elements equal 1 and/or 2. Array a is k-period if its length is divisible by k and there is such array b of length k, that a is represented by array b written exactly $\frac{n}{k}$ time...
{"inputs": ["1 1\n2\n", "1 1\n2\n", "1 1\n1\n", "2 1\n1 1\n", "2 2\n2 2\n", "2 1\n1 2\n", "2 2\n2 1\n", "2 2\n2 2\n"], "outputs": ["0\n", "0", "0\n", "0\n", "0\n", "1\n", "0\n", "0"]}
575
110
coding
Solve the programming task below in a Python markdown code block. Write a program which reads two sequences of nodes obtained by the preorder tree walk and the inorder tree walk on a binary tree respectively, and prints a sequence of the nodes obtained by the postorder tree walk on the binary tree. Constraints * $1 \...
{"inputs": ["4\n1 2 3 4\n2 1 3 4", "4\n2 1 3 4\n2 1 3 4", "4\n2 1 3 4\n3 1 2 4", "4\n2 1 3 4\n1 2 3 4", "4\n1 4 3 2\n1 2 3 4", "4\n1 2 3 4\n1 2 4 3", "4\n2 1 3 4\n2 1 4 3", "4\n1 2 3 4\n2 1 3 4"], "outputs": ["2 4 3 1\n", "4 3 1 2\n", "3 1 4 2\n", "1 4 3 2\n", "2 3 4 1\n", "4 3 2 1\n", "4 3 1 2\n", "2 4 3 1\n"]}
268
238
coding
Solve the programming task below in a Python markdown code block. Your math teacher gave you the following problem: There are $n$ segments on the $x$-axis, $[l_1; r_1], [l_2; r_2], \ldots, [l_n; r_n]$. The segment $[l; r]$ includes the bounds, i.e. it is a set of such $x$ that $l \le x \le r$. The length of the segmen...
{"inputs": ["1\n2\n999999997 999999998\n999999999 1000000000\n", "1\n2\n999999997 999999998\n999999999 1000000000\n", "1\n2\n905303520 999999998\n999999999 1000000000\n", "1\n2\n905303520 999999998\n999999999 1000000001\n", "1\n1\n905303520 999999998\n999999999 1000000001\n", "1\n2\n71083781 1824489928\n999999999 10000...
636
424
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a 0-indexed integer array nums. In one operation, you can: Choose two different indices i and j such that 0 <= i, j < nums.length. Choose a non-negative integer k such that the kth bit (0-indexed) in th...
{"functional": "def check(candidate):\n assert candidate(nums = [4,3,1,2,4]) == 2\n assert candidate(nums = [1,10,4]) == 0\n\n\ncheck(Solution().beautifulSubarrays)"}
189
57
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. On a social network consisting of m users and some friendships between users, two users can communicate with each other if they know a common language. You are given an integer n, an array languages, and an array frie...
{"functional": "def check(candidate):\n assert candidate(n = 2, languages = [[1],[2],[1,2]], friendships = [[1,2],[1,3],[2,3]]) == 1\n assert candidate(n = 3, languages = [[2],[1,3],[1,2],[3]], friendships = [[1,4],[1,2],[3,4],[2,3]]) == 2\n\n\ncheck(Solution().minimumTeachings)"}
245
105
coding
Solve the programming task below in a Python markdown code block. Chef has bought N robots to transport cakes for a large community wedding. He has assigned unique indices, from 1 to N, to each of them. How it will happen? Chef arranges the N robots in a row, in the (increasing) order of their indices. Then, he chooses...
{"inputs": ["3\n2 0\n2 1\n4 2"], "outputs": ["No 1\nYes\nNo 2"]}
720
32
coding
Solve the programming task below in a Python markdown code block. ## **Task** You are given a positive integer (`n`), and your task is to find the largest number **less than** `n`, which can be written in the form `a**b`, where `a` can be any non-negative integer and `b` is an integer greater than or equal to `2`. Try...
{"functional": "_inputs = [[90], [6], [65], [2], [1], [81], [29], [4]]\n_outputs = [[[81, 2]], [[4, 1]], [[64, 3]], [[1, -1]], [[0, -1]], [[64, 3]], [[27, 1]], [[1, -1]]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs...
477
229
coding
Solve the programming task below in a Python markdown code block. You are given an array $a$ of length $n$. A subsequence of this array is valid, if it satisfies these two conditions: - There shouldn't be any two even numbers within a distance of $K$, both which have been chosen in the subsequence. i.e. there shouldn't...
{"inputs": ["3\n1 1\n3\n2 1\n2 2\n5 2\n1 2 3 4 6"], "outputs": ["3\n2\n11"]}
490
45
coding
Solve the programming task below in a Python markdown code block. How many hours do we have until New Year at M o'clock (24-hour notation) on 30th, December? -----Constraints----- - 1≤M≤23 - M is an integer. -----Input----- Input is given from Standard Input in the following format: M -----Output----- If we have x...
{"inputs": ["9", "8", "0", "4", "1", "2", "3", "5"], "outputs": ["39\n", "40\n", "48\n", "44\n", "47\n", "46\n", "45\n", "43\n"]}
137
70
coding
Solve the programming task below in a Python markdown code block. The only difference between easy and hard versions is the number of elements in the array. You are given an array $a$ consisting of $n$ integers. In one move you can choose any $a_i$ and divide it by $2$ rounding down (in other words, in one move you ca...
{"inputs": ["1 1\n1337\n", "1 1\n1337\n", "4 2\n9 9 9 9\n", "4 2\n3 3 3 3\n", "4 2\n2 2 2 2\n", "4 2\n3 3 3 3\n", "4 2\n9 9 9 9\n", "4 2\n2 2 2 2\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]}
370
144
coding
Solve the programming task below in a Python markdown code block. .symmetric_difference() The .symmetric_difference() operator returns a set with all the elements that are in the set and the iterable but not both. Sometimes, a ^ operator is used in place of the .symmetric_difference() tool, but it only operates on ...
{"inputs": ["9\n1 2 3 4 5 6 7 8 9\n9\n10 1 2 3 11 21 55 6 8\n"], "outputs": ["8\n"]}
637
56
coding
Solve the programming task below in a Python markdown code block. Chief's bot is playing an old DOS based game. There is a row of buildings of different heights arranged at each index along a number line. The bot starts at building $\mbox{o}$ and at a height of $\mbox{o}$. You must determine the minimum energy his b...
{"inputs": ["3\n4 4 4\n", "3\n1 6 4\n", "5\n3 4 3 2 4\n"], "outputs": ["4\n", "3\n", "4\n"]}
696
52
coding
Solve the programming task below in a Python markdown code block. Chef’s girlfriend is angry with him because he forgot her birthday. Chef decided to please her by gifting her a Love Graph. Chef has $N$ vertices: $V_1, V_2, \dots, V_N$. Love Graph is an undirected multigraph with no self-loops and can be constructed b...
{"inputs": ["1\n2 1"], "outputs": ["2"]}
494
16
coding
Solve the programming task below in a Python markdown code block. You are given a rooted tree with N nodes and the root of the tree, R, is also given. Each node of the tree contains a value, that is initially empty. You have to mantain the tree under two operations: Update Operation Report Operation Update Operation ...
{"inputs": ["7 7 1\n1 2\n2 3\n2 4\n2 5\n5 6\n6 7\nU 5 10 2\nU 4 5 3\nQ 1 7\nU 6 7 4\nQ 2 7\nQ 1 4\nQ 2 4\n"], "outputs": ["36\n54\n5\n5\n"]}
685
99
coding
Solve the programming task below in a Python markdown code block. You have a string $s_1 s_2 \ldots s_n$ and you stand on the left of the string looking right. You want to choose an index $k$ ($1 \le k \le n$) and place a mirror after the $k$-th letter, so that what you see is $s_1 s_2 \ldots s_k s_k s_{k - 1} \ldots s...
{"inputs": ["4\n10\ncodeforces\n9\ncbacbacba\n3\naaa\n4\nbbaa\n"], "outputs": ["cc\ncbaabc\naa\nbb\n"]}
465
46
coding
Solve the programming task below in a Python markdown code block. The objective is to return all pairs of integers from a given array of integers that have a difference of 2. The result array should be sorted in ascending order of values. Assume there are no duplicate integers in the array. The order of the integers ...
{"functional": "_inputs = [[[1, 2, 3, 4]], [[1, 3, 4, 6]], [[0, 3, 1, 4]], [[4, 1, 2, 3]], [[6, 3, 4, 1, 5]], [[3, 1, 6, 4]], [[1, 3, 5, 6, 8, 10, 15, 32, 12, 14, 56]], [[1, 4, 7, 10]], [[]]]\n_outputs = [[[[1, 3], [2, 4]]], [[[1, 3], [4, 6]]], [[[1, 3]]], [[[1, 3], [2, 4]]], [[[1, 3], [3, 5], [4, 6]]], [[[1, 3], [4, 6...
350
404
coding
Solve the programming task below in a Python markdown code block. Given is an undirected connected graph with N vertices numbered 1 to N, and M edges numbered 1 to M. The given graph may contain multi-edges but not self loops. Each edge has an integer label between 1 and N (inclusive). Edge i has a label c_i, and it co...
{"inputs": ["3 4\n1 2 1\n2 3 2\n3 1 3\n1 3 1\n"], "outputs": ["1\n2\n1\n"]}
621
44
coding
Solve the programming task below in a Python markdown code block. Anton likes to listen to fairy tales, especially when Danik, Anton's best friend, tells them. Right now Danik tells Anton a fairy tale: "Once upon a time, there lived an emperor. He was very rich and had much grain. One day he ordered to build a huge ba...
{"inputs": ["5 2\n", "8 1\n", "1 1\n", "2 1\n", "2 2\n", "3 1\n", "3 2\n", "3 3\n"], "outputs": ["4\n", "5\n", "1\n", "2\n", "2\n", "3\n", "3\n", "3\n"]}
712
86
coding
Solve the programming task below in a Python markdown code block. Bob has a string $s$ consisting of lowercase English letters. He defines $s'$ to be the string after removing all "a" characters from $s$ (keeping all other characters in the same order). He then generates a new string $t$ by concatenating $s$ and $s'$. ...
{"inputs": ["a\n", "b\n", "a\n", "b\n", "`\n", "c\n", "_\n", "^\n"], "outputs": ["a\n", ":(\n", "a", ":(", ":(\n", ":(\n", ":(\n", ":(\n"]}
364
72
coding
Solve the programming task below in a Python markdown code block. This is the hard version of the problem. The only difference is that in this version $n \leq 200000$. You can make hacks only if both versions of the problem are solved. There are $n$ potions in a line, with potion $1$ on the far left and potion $n$ on ...
{"inputs": ["1\n0\n", "1\n0\n", "1\n1\n", "1\n2\n", "1\n4\n", "1\n3\n", "1\n5\n", "1\n7\n"], "outputs": ["1", "1", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n"]}
366
84
coding
Solve the programming task below in a Python markdown code block. Chef is playing with weights. He has an object weighing W units. He also has three weights each of X, Y, and Z units respectively. Help him determine whether he can measure the exact weight of the object with one or more of these weights. If it is possi...
{"inputs": ["4\n5 2 1 6\n7 9 7 2\n20 8 10 12\n20 10 11 12\n"], "outputs": ["NO\nYES\nYES\nNO\n"]}
407
59
coding
Solve the programming task below in a Python markdown code block. You are given a sequence of integers a_{1},a_{2},a_{3}.....a_{n}. You are free to replace any integer with any other positive integer. How many integers must be replaced to make the resulting sequence strictly increasing? Input Format The first line ...
{"inputs": ["3\n4 10 20\n", "5\n1 2 2 3 4 \n", "6\n1 7 10 2 20 22\n"], "outputs": ["0\n", "3\n", "1\n"]}
340
64
coding
Solve the programming task below in a Python markdown code block. Make a program that takes a value (x) and returns "Bang" if the number is divisible by 3, "Boom" if it is divisible by 5, "BangBoom" if it divisible by 3 and 5, and "Miss" if it isn't divisible by any of them. Note: Your program should only return one va...
{"functional": "_inputs = [[30], [3], [98], [65], [23], [15], [4], [2], [45], [90], [21], [7], [6], [10003823], [41535], [712], [985], [164523]]\n_outputs = [['BangBoom'], ['Bang'], ['Miss'], ['Boom'], ['Miss'], ['BangBoom'], ['Miss'], ['Miss'], ['BangBoom'], ['BangBoom'], ['Bang'], ['Miss'], ['Bang'], ['Miss'], ['Bang...
146
289
coding
Solve the programming task below in a Python markdown code block. You are given an array of integers. Vasya can permute (change order) its integers. He wants to do it so that as many as possible integers will become on a place where a smaller integer used to stand. Help Vasya find the maximal number of such integers. ...
{"inputs": ["1\n1\n", "1\n1\n", "1\n2\n", "1\n4\n", "1\n3\n", "1\n5\n", "1\n8\n", "1\n7\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]}
481
86
coding
Solve the programming task below in a Python markdown code block. Alice has scored X marks in her test and Bob has scored Y marks in the same test. Alice is happy if she scored at least twice the marks of Bob’s score. Determine whether she is happy or not. ------ Input Format ------ - The first and only line of inpu...
{"inputs": ["2 1", "1 2"], "outputs": ["Yes", "No"]}
309
22
coding
Solve the programming task below in a Python markdown code block. Little Johnny Bubbles enjoys spending hours in front of his computer playing video games. His favorite game is Bubble Strike, fast-paced bubble shooting online game for two players. Each game is set in one of the N maps, each having different terrain co...
{"inputs": ["7 1.0000\n", "3 0.0000\n", "3 1.0000\n", "3 1.0000\n", "3 0.0000\n", "3 0.5879\n", "4 0.0000\n", "8 0.0000\n"], "outputs": ["6\n", "0\n", "2\n", "2\n", "0\n", "2\n", "0\n", "0\n"]}
373
126
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given the root of a binary tree and an integer distance. A pair of two different leaf nodes of a binary tree is said to be good if the length of the shortest path between them is less than or equal to distance...
{"functional": "def check(candidate):\n assert candidate(root = tree_node([1,2,3,None,4]), distance = 3) == 1\n assert candidate(root = tree_node([1,2,3,4,5,6,7]), distance = 3) == 2\n assert candidate(root = tree_node([7,1,4,6,None,5,3,None,None,None,None,None,2]), distance = 3) == 1\n assert candidate(roo...
162
157
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given two integer arrays, source and target, both of length n. You are also given an array allowedSwaps where each allowedSwaps[i] = [ai, bi] indicates that you are allowed to swap the elements at index ai and...
{"functional": "def check(candidate):\n assert candidate(source = [1,2,3,4], target = [2,1,4,5], allowedSwaps = [[0,1],[2,3]]) == 1\n assert candidate(source = [1,2,3,4], target = [1,3,2,4], allowedSwaps = []) == 2\n assert candidate(source = [5,1,2,4,3], target = [1,5,4,2,3], allowedSwaps = [[0,4],[4,2],[1,3]...
224
151
coding
Solve the programming task below in a Python markdown code block. You are given a string S of length N consisting of A, C, G and T. Answer the following Q queries: - Query i (1 \leq i \leq Q): You will be given integers l_i and r_i (1 \leq l_i < r_i \leq N). Consider the substring of S starting at index l_i and ending...
{"inputs": ["2 1\nAA\n1 2\n", "8 3\nACACTACG\n3 7\n2 3\n1 6", "8 3\nGCATCACA\n3 7\n2 3\n1 8", "8 3\nACBCTADG\n3 7\n2 3\n1 6", "8 3\nACACTACG\n3 7\n2 3\n1 2", "8 3\nACACTACG\n3 7\n4 3\n1 2", "8 3\nGAATCCCA\n3 7\n3 3\n2 8", "8 3\nACACTADG\n3 7\n2 4\n1 6"], "outputs": ["0\n", "2\n0\n2\n", "1\n0\n1\n", "0\n0\n1\n", "2\n0\n...
442
234
coding
Solve the programming task below in a Python markdown code block. Continuing the trend, this year too we present a 'Mystery' for you to solve! You will be given two numbers: a and b; and you have to output a single integer. See the sample test cases for hints. Input: The first line of the input will contain an integ...
{"inputs": ["15\n0 5\n0 3\n5 10\n1 10\n9 10\n999 10\n999 22\n65 65\n66 65\n222 222\n652 999\n1 1000\n253 999\n256 53\n987 57"], "outputs": ["0\n0\n5\n1\n9\n9\n9\n0\n1\n0\n652\n1\n253\n44\n18"]}
206
141
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. A confusing number is a number that when rotated 180 degrees becomes a different number with each digit valid. We can rotate digits of a number by 180 degrees to form new digits. When 0, 1, 6, 8, and 9 are rotated 18...
{"functional": "def check(candidate):\n assert candidate(n = 20) == 6\n assert candidate(n = 100) == 19\n\n\ncheck(Solution().confusingNumberII)"}
219
49
coding
Solve the programming task below in a Python markdown code block. Little town Nsk consists of n junctions connected by m bidirectional roads. Each road connects two distinct junctions and no two roads connect the same pair of junctions. It is possible to get from any junction to any other junction by these roads. The d...
{"inputs": ["2 1 2 1\n1 2\n", "2 1 2 1\n1 2\n", "2 1 2 2\n1 2\n", "2 1 1 2\n1 2\n", "3 2 2 3\n1 2\n2 3\n", "3 2 1 3\n1 2\n2 3\n", "3 2 2 3\n1 2\n2 3\n", "3 2 1 3\n1 2\n2 3\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "1\n", "0\n", "1\n", "0\n"]}
527
166
coding
Solve the programming task below in a Python markdown code block. Dr. Moriarty is about to send a message to Sherlock Holmes. He has a string s. String p is called a substring of string s if you can read it starting from some position in the string s. For example, string "aba" has six substrings: "a", "b", "a", "ab",...
{"inputs": ["a\na\n", "c\nh\n", "h\nb\n", "r\ni\n", "t\nv\n", "o\nu\n", "c\np\n", "a\nz\n"], "outputs": ["0\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n"]}
508
86
coding
Solve the programming task below in a Python markdown code block. Counting was a difficult task in ancient Rome. The Arabic numerals 0,1,2,3,…, 9 have not yet been disseminated. Instead, the following symbols were used: Arabic numerals | Roman numerals | Arabic numerals | Roman numerals | Arabic numerals | Roman numer...
{"inputs": ["VI\nCCCCLXXXXVIIII\nCDXCIX", "IV\nCCCILXXXXVICII\nCDXCIX", "IV\nCCCCLXXXXVIIII\nCDICXX", "VI\nCXCCLXXCXVIIII\nCDXCIX", "VI\nCCCILXXXXVICII\nCDXCIX", "VI\nCXDCLXXCXVIIII\nCDXCIX", "IV\nCCCILXXXXVIDII\nCDXCIX", "VI\nCCCILXXXXVICII\nDCXCIX"], "outputs": ["6\n499\n499\n", "4\n495\n499\n", "4\n499\n519\n", "6\n...
622
214
coding
Solve the programming task below in a Python markdown code block. ## Story John runs a shop, bought some goods, and then sells them. He used a special accounting method, like this: ``` [[60,20],[60,-20]] ``` Each sub array records the commodity price and profit/loss to sell (percentage). Positive mean profit and negat...
{"functional": "_inputs = [[[[60, 20], [60, -20]]], [[[60, 100], [60, -50]]], [[[60, 0], [60, 0]]]]\n_outputs = [[-5], [-30], [0]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, t...
203
211
coding
Solve the programming task below in a Python markdown code block. Given a sequence of $n$ numbers, $D=(d_1,d_2,\ldots,d_n)$, what's the maximum size of a subsequence of $\mbox{D}$ in which every pair is a nice pair? The pair $(a,b)$ is a nice pair iff at least one of the following condition holds. The parity of the...
{"inputs": ["4\n2 3 6 8\n"], "outputs": ["3\n"]}
491
22
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. One way to serialize a binary tree is to use preorder traversal. When we encounter a non-null node, we record the node's value. If it is a null node, we record using a sentinel value such as '#'. For example, the abo...
{"functional": "def check(candidate):\n assert candidate(preorder = \"9,3,4,#,#,1,#,#,2,#,6,#,#\") == True\n assert candidate(preorder = \"1,#\") == False\n assert candidate(preorder = \"9,#,#,1\") == False\n\n\ncheck(Solution().isValidSerialization)"}
221
77
coding
Solve the programming task below in a Python markdown code block. You are stacking some boxes containing gold weights on top of each other. If a box contains more weight than the box below it, it will crash downwards and combine their weights. e.g. If we stack [2] on top of [1], it will crash downwards and become a sin...
{"functional": "_inputs = [[[[1]]], [[[1, 2]]], [[[2], [1]]]]\n_outputs = [[[1]], [[1, 2]], [[3]]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) != le...
411
180
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. The DNA sequence is composed of a series of nucleotides abbreviated as 'A', 'C', 'G', and 'T'. For example, "ACGAATTCCG" is a DNA sequence. When studying DNA, it is useful to identify repeated sequences within the D...
{"functional": "def check(candidate):\n assert candidate(s = \"AAAAACCCCCAAAAACCCCCCAAAAAGGGTTT\") == [\"AAAAACCCCC\",\"CCCCCAAAAA\"]\n assert candidate(s = \"AAAAAAAAAAAAA\") == [\"AAAAAAAAAA\"]\n\n\ncheck(Solution().findRepeatedDnaSequences)"}
151
73
coding
Solve the programming task below in a Python markdown code block. You are given array consisting of n integers. Your task is to find the maximum length of an increasing subarray of the given array. A subarray is the sequence of consecutive elements of the array. Subarray is called increasing if each element of this su...
{"inputs": ["1\n1\n", "1\n1\n", "2\n2 1\n", "2\n1 2\n", "2\n1 2\n", "2\n2 1\n", "2\n1 4\n", "2\n2 2\n"], "outputs": ["1\n", "1\n", "1\n", "2\n", "2\n", "1\n", "2\n", "1\n"]}
217
98
coding
Solve the programming task below in a Python markdown code block. You are an upcoming movie director, and you have just released your first movie. You have also launched a simple review site with two buttons to press — upvote and downvote. However, the site is not so simple on the inside. There are two servers, each w...
{"inputs": ["1\n1\n2\n", "1\n1\n2\n", "1\n1\n3\n", "1\n1\n1\n", "4\n1\n2\n3\n1 2 3\n5\n1 1 1 1 1\n3\n3 3 2\n", "4\n1\n2\n3\n1 3 3\n5\n1 1 1 1 1\n3\n3 3 2\n", "4\n1\n1\n3\n1 3 3\n5\n1 1 1 1 1\n3\n3 3 2\n", "4\n1\n1\n3\n1 3 3\n5\n1 1 1 1 1\n3\n3 3 3\n"], "outputs": ["0\n", "0\n", "1\n", "1\n", "0\n2\n5\n2\n", "0\n3\n5\n2...
674
238
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. The thief has found himself a new place for his thievery again. There is only one entrance to this area, called root. Besides the root, each house has one and only one parent house. After a tour, the smart thief reali...
{"functional": "def check(candidate):\n assert candidate(root = tree_node([3,2,3,None,3,None,1])) == 7\n assert candidate(root = tree_node([3,4,5,1,3,None,1])) == 9\n\n\ncheck(Solution().rob)"}
202
67
coding
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. Chef likes inequalities. Please help him to solve next one. Given four integers a, b, c, d. Find number of solutions x < y, where a ≤ x ≤ b and c ≤ y ≤ d and x, y integers. ...
{"inputs": ["1\n2 3 3 4", "1\n2 999999 1 1000000"], "outputs": ["3", "499998500001"]}
309
56
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. There are n 1-indexed robots, each having a position on a line, health, and movement direction. You are given 0-indexed integer arrays positions, healths, and a string directions (directions[i] is either 'L' for left ...
{"functional": "def check(candidate):\n assert candidate(positions = [5,4,3,2,1], healths = [2,17,9,15,10], directions = \"RRRRR\") == [2,17,9,15,10]\n assert candidate(positions = [3,5,2,6], healths = [10,10,15,12], directions = \"RLRL\") == [14]\n assert candidate(positions = [1,2,5,6], healths = [10,10,11,1...
317
165
coding
Solve the programming task below in a Python markdown code block. We say that a odd number N is similar to 2017 when both N and (N+1)/2 are prime. You are given Q queries. In the i-th query, given two odd numbers l_i and r_i, find the number of odd numbers x similar to 2017 such that l_i ≤ x ≤ r_i. -----Constraints---...
{"inputs": ["1\n3 9", "1\n5 9", "1\n9 9", "1\n3 7", "1\n3 7\n", "1\n3 13", "4\n11 13\n7 0\n1 11\n39 2017", "4\n2 13\n7 1\n7 17\n879 2017"], "outputs": ["2\n", "1\n", "0\n", "2", "2\n", "3\n", "1\n-2\n2\n32\n", "3\n-2\n1\n16\n"]}
306
149
coding
Solve the programming task below in a Python markdown code block. Chef has a nice complete binary tree in his garden. Complete means that each node has exactly two sons, so the tree is infinite. Yesterday he had enumerated the nodes of the tree in such a way: - Let's call the nodes' level a number of nodes that occur ...
{"inputs": ["4\nrll\nrll\nr\nlllr", "4\nlrl\nrll\nr\nrlll", "4\nlrl\nrll\nr\nllrl", "4\nrll\nllr\nr\nlllr", "4\nrll\nrll\nr\nllrl", "4\nrll\nllr\nr\nrlll", "4\nllr\nllr\nr\nrlll", "4\nllr\nrll\nr\nrlll"], "outputs": ["14\n14\n4\n13\n", "10\n14\n4\n27\n", "10\n14\n4\n15\n", "14\n8\n4\n13\n", "14\n14\n4\n15\n", "14\n8\n4...
538
221
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an integer array bloomDay, an integer m and an integer k. You want to make m bouquets. To make a bouquet, you need to use k adjacent flowers from the garden. The garden consists of n flowers, the ith flo...
{"functional": "def check(candidate):\n assert candidate(bloomDay = [1,10,3,10,2], m = 3, k = 1) == 3\n assert candidate(bloomDay = [1,10,3,10,2], m = 3, k = 2) == -1\n assert candidate(bloomDay = [7,7,7,7,12,7,7], m = 2, k = 3) == 12\n assert candidate(bloomDay = [1000000000,1000000000], m = 1, k = 1) == 1...
161
221
coding
Solve the programming task below in a Python markdown code block. Just in case somebody missed it: this winter is totally cold in Nvodsk! It is so cold that one gets funny thoughts. For example, let's say there are strings with the length exactly n, based on the alphabet of size m. Any its substring with length equal t...
{"inputs": ["4 4 1\n", "5 4 5\n", "5 5 5\n", "5 2 5\n", "7 2 7\n", "5 2 1\n", "4 4 4\n", "5 5 1\n"], "outputs": ["256\n", "64\n", "125\n", "8\n", "16\n", "32\n", "16\n", "3125\n"]}
310
113
coding
Solve the programming task below in a Python markdown code block. Read problem statements in [Mandarin Chinese], [Russian], and [Vietnamese] as well. You are given the sizes of angles of a simple quadrilateral (in degrees) $A$, $B$, $C$ and $D$, in some order along its perimeter. Determine whether the quadrilateral is...
{"inputs": ["3\n10 20 30 300\n10 20 170 160\n179 1 179 1"], "outputs": ["NO\nYES\nNO"]}
512
55
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Two strings are considered close if you can attain one from the other using the following operations: Operation 1: Swap any two existing characters. For example, abcde -> aecdb Operation 2: Transform every occur...
{"functional": "def check(candidate):\n assert candidate(word1 = \"abc\", word2 = \"bca\") == True\n assert candidate(word1 = \"a\", word2 = \"aa\") == False\n assert candidate(word1 = \"cabbba\", word2 = \"abbccc\") == True\n\n\ncheck(Solution().closeStrings)"}
185
77
coding
Solve the programming task below in a Python markdown code block. There is a given string S consisting of N symbols. Your task is to find the number of ordered pairs of integers i and j such that 1. 1 ≤ i, j ≤ N 2. S[i] = S[j], that is the i-th symbol of string S is equal to the j-th. Input The single input line co...
{"inputs": ["w\n", "v\n", "u\n", "x\n", "t\n", "s\n", "r\n", "q\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n"]}
183
70
coding
Solve the programming task below in a Python markdown code block. You are given an array $a$ of $n$ integers, where $n$ is odd. You can make the following operation with it: Choose one of the elements of the array (for example $a_i$) and increase it by $1$ (that is, replace it with $a_i + 1$). You want to make the m...
{"inputs": ["1 1\n1\n", "1 1\n1\n", "1 1\n2\n", "3 2\n1 3 5\n", "3 1\n1 1 1\n", "3 1\n1 1 1\n", "3 2\n1 3 5\n", "3 100\n1 2 3\n"], "outputs": ["2", "2", "3\n", "5", "1", "1", "5", "52"]}
470
118
coding
Solve the programming task below in a Python markdown code block. Read problem statements in [Mandarin Chinese] and [Bengali]. You are given N identical squares, each with side length A. All the squares have their sides parallel to the x-axis and y-axis. That is, the squares are not tilted. You have to take several (p...
{"inputs": ["5\n3 2\n5 3\n16 18\n11 8\n8 6\n"], "outputs": ["2\n6\n72\n24\n12\n"]}
364
48
coding
Solve the programming task below in a Python markdown code block. Snuke is making sugar water in a beaker. Initially, the beaker is empty. Snuke can perform the following four types of operations any number of times. He may choose not to perform some types of operations. - Operation 1: Pour 100A grams of water into th...
{"inputs": ["3 1 1 20 5 179", "1 3 8 13 1 179", "2 1 1 20 3 179", "6 1 1 7 29 123", "1 2 5 20 15 179", "1 1 5 20 27 179", "2 1 1 20 17 179", "6 1 1 20 29 141"], "outputs": ["105 5\n", "100 0\n", "103 3\n", "123 23\n", "115 15\n", "125 25\n", "117 17\n", "129 29\n"]}
606
207
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given two strings, s1 and s2, write code to check if s2 is a rotation of s1 (e.g.,"waterbottle" is a rotation of"erbottlewat"). Can you use only one call to the method that checks if one word is a substring of another...
{"functional": "def check(candidate):\n assert candidate(s1 = \"waterbottle\", s2 = \"erbottlewat\") == True\n assert candidate(s1 = \"aa\", s2 = \"aba\") == False\n\n\ncheck(Solution().isFlipedString)"}
119
61
coding
Solve the programming task below in a Python markdown code block. Chef has allocated himself a budget of P rupees to buy Diwali crackers. There are only 3 types of crackers available in the market and each type of cracker can be bought any number of times. 1. Fuljhari, where each costs a rupees 2. Anar, where each cos...
{"inputs": ["3\n100 5 5 10 4 8\n16 2 2 2 1 1\n55 1 2 3 4 5"], "outputs": ["4\n4\n9"]}
693
57
coding
Solve the programming task below in a Python markdown code block. You are given a string $s$, consisting of brackets of two types: '(', ')', '[' and ']'. A string is called a regular bracket sequence (RBS) if it's of one of the following types: empty string; '(' + RBS + ')'; '[' + RBS + ']'; RBS + RBS. where plus...
{"inputs": ["4\n()\n()\n()\n()\n", "4\n()\n()\n()\n()\n", "4\n)(\n()\n()\n()\n", "4\n)(\n()\n((\n()\n", "4\n()\n()\n)(\n()\n", "4\n)(\n))\n()\n()\n", "4\n)(\n()\n((\n)(\n", "4\n()\n))\n()\n()\n"], "outputs": ["1\n1\n1\n1\n", "1\n1\n1\n1\n", "0\n1\n1\n1\n", "0\n1\n0\n1\n", "1\n1\n0\n1\n", "0\n0\n1\n1\n", "0\n1\n0\n0\n",...
461
192
coding
Solve the programming task below in a Python markdown code block. This is an easy version of the problem. The only difference between an easy and a hard version is in the number of queries. Polycarp grew a tree from $n$ vertices. We remind you that a tree of $n$ vertices is an undirected connected graph of $n$ vertice...
{"inputs": ["1\n1\n1\n1\n", "1\n2\n1\n1\n1\n1\n", "3\n3 1\n2 1\n1\n2\n1 2\n", "5\n4 2\n5 4\n1 4\n3 5\n1\n4\n1 3 5 2\n", "2\n1 2\n5\n1\n2\n1\n1\n1\n1\n2\n2 1\n2\n1 2\n", "6\n1 6\n6 5\n1 2\n2 3\n2 4\n1\n4\n5 2 4 3\n", "6\n1 2\n2 3\n1 4\n4 5\n4 6\n1\n4\n3 4 5 6\n", "7\n1 2\n2 3\n3 4\n1 5\n5 6\n5 7\n1\n3\n4 6 7\n"], "outpu...
730
268
coding
Solve the programming task below in a Python markdown code block. A new innovative ticketing systems for public transport is introduced in Bytesburg. Now there is a single travel card for all transport. To make a trip a passenger scan his card and then he is charged according to the fare. The fare is constructed in th...
{"inputs": ["1\n0\n", "1\n0\n", "1\n1\n", "1\n2\n", "1\n4\n", "1\n7\n", "1\n3\n", "1\n6\n"], "outputs": ["20\n", "20\n", "20\n", "20\n", "20\n", "20\n", "20\n", "20\n"]}
619
94
coding
Solve the programming task below in a Python markdown code block. We have a grid with H rows and W columns. The square at the i-th row and the j-th column will be called Square (i,j). The integers from 1 through H×W are written throughout the grid, and the integer written in Square (i,j) is A_{i,j}. You, a magical girl...
{"inputs": ["3 3 1\n1 4 3\n2 5 7\n8 9 6\n1\n4 8", "3 3 1\n1 4 3\n2 5 7\n8 9 6\n1\n4 9", "3 3 3\n1 4 3\n2 5 7\n8 9 6\n1\n4 8", "3 3 2\n1 4 3\n2 5 7\n8 9 6\n1\n4 1", "3 3 1\n1 4 3\n2 5 7\n8 9 6\n1\n8 9", "3 3 2\n1 4 3\n2 5 7\n8 9 6\n1\n4 8", "3 3 2\n1 4 3\n2 5 7\n8 9 6\n1\n4 8\n", "4 2 3\n3 7\n1 4\n5 2\n6 8\n2\n2 1\n2 2"...
578
290
coding
Solve the programming task below in a Python markdown code block. Your task is to remove all duplicate words from a string, leaving only single (first) words entries. Example: Input: 'alpha beta beta gamma gamma gamma delta alpha beta beta gamma gamma gamma delta' Output: 'alpha beta gamma delta' Also feel free to...
{"functional": "_inputs = [['alpha beta beta gamma gamma gamma delta alpha beta beta gamma gamma gamma delta'], ['my cat is my cat fat']]\n_outputs = [['alpha beta gamma delta'], ['my cat is fat']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isc...
84
185
coding
Solve the programming task below in a Python markdown code block. Alice has a positive integer N. She is wondering how many ordered pairs of positive integers (i, j) exist such that i + j = N. Help Alice figure out the answer. Note that since the pairs are ordered, (1, 2) and (2, 1) are considered different. ------...
{"inputs": ["1", "2", "3"], "outputs": ["0", "1", "2"]}
294
24
coding
Solve the programming task below in a Python markdown code block. You are given two integers $n$ and $k$. Your task is to find if $n$ can be represented as a sum of $k$ distinct positive odd (not divisible by $2$) integers or not. You have to answer $t$ independent test cases. -----Input----- The first line of the ...
{"inputs": ["1\n707 44\n", "1\n2 65536\n", "1\n2 65536\n", "1\n2 15317\n", "1\n3 15317\n", "1\n1 15317\n", "1\n0 15317\n", "1\n0 26405\n"], "outputs": ["NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n"]}
382
133
coding
Solve the programming task below in a Python markdown code block. Saitama accidentally destroyed a hotel again. To repay the hotel company, Genos has volunteered to operate an elevator in one of its other hotels. The elevator is special — it starts on the top floor, can only move down, and has infinite capacity. Floors...
{"inputs": ["1 1\n1 1\n", "1 1\n1 1\n", "1 1\n1 0\n", "1 1\n1 2\n", "1 2\n1 0\n", "1 1000\n1 1\n", "1 1000\n1 1\n", "1 1000\n1 2\n"], "outputs": ["2\n", "2\n", "1\n", "3\n", "2\n", "1000\n", "1000\n", "1000\n"]}
492
136
coding
Solve the programming task below in a Python markdown code block. # Grains Write a program that calculates the number of grains of wheat on a chessboard given that the number on each square is double the previous one. There are 64 squares on a chessboard. #Example: square(1) = 1 square(2) = 2 square(3) = 4 square(4)...
{"functional": "_inputs = [[1], [3], [4], [16], [32]]\n_outputs = [[1], [4], [8], [32768], [2147483648]]\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)...
126
192
coding
Solve the programming task below in a Python markdown code block. An AI has infected a text with a character!! This text is now **fully mutated** to this character. If the text or the character are empty, return an empty string. There will never be a case when both are empty as nothing is going on!! **Note:** The...
{"functional": "_inputs = [['abc', 'z'], ['', 'z'], ['abc', ''], ['_3ebzgh4', '&'], ['//case', ' ']]\n_outputs = [['zzz'], [''], [''], ['&&&&&&&&'], [' ']]\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)\...
134
198
coding
Solve the programming task below in a Python markdown code block. You and your friend are participating in a TV show "Run For Your Prize". At the start of the show n prizes are located on a straight line. i-th prize is located at position a_{i}. Positions of all prizes are distinct. You start at position 1, your frien...
{"inputs": ["1\n2\n", "1\n2\n", "1\n20\n", "1\n20\n", "1\n40\n", "1\n44\n", "1\n54\n", "1\n93\n"], "outputs": ["1\n", "1\n", "19\n", "19\n", "39\n", "43\n", "53\n", "92\n"]}
456
98
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed. All houses at this place are arranged in a circle. That means the first house is the neighbor of t...
{"functional": "def check(candidate):\n assert candidate(nums = [2,3,2]) == 3\n assert candidate(nums = [1,2,3,1]) == 4\n assert candidate(nums = [1,2,3]) == 3\n\n\ncheck(Solution().rob)"}
155
68
coding
Solve the programming task below in a Python markdown code block. You are given a digital clock with $n$ digits. Each digit shows an integer from $0$ to $9$, so the whole clock shows an integer from $0$ to $10^n-1$. The clock will show leading zeroes if the number is smaller than $10^{n-1}$. You want the clock to show...
{"inputs": ["7\n3\n007\n4\n1000\n5\n00000\n3\n103\n4\n2020\n9\n123456789\n30\n001678294039710047203946100020\n", "7\n3\n007\n4\n1000\n5\n00000\n3\n103\n4\n1247\n9\n123456789\n30\n001678294039710047203946100020\n", "7\n3\n007\n4\n1000\n5\n00000\n3\n153\n4\n1247\n9\n123456789\n30\n001678294039710047203946100020\n", "7\n3...
516
841
coding
Solve the programming task below in a Python markdown code block. For a given two numbers your mission is to derive a function that evaluates whether two given numbers are **abundant**, **deficient** or **perfect** and whether together they are **amicable**. ### Abundant Numbers An abundant number or excessive numbe...
{"functional": "_inputs = [[220, 284], [220, 280], [1184, 1210], [220221, 282224], [10744, 10856], [299920, 9284], [999220, 2849], [139815, 122265], [496, 28], [8128, 8128]]\n_outputs = [['abundant deficient amicable'], ['abundant abundant not amicable'], ['abundant deficient amicable'], ['deficient abundant not amicab...
741
363
coding
Solve the programming task below in a Python markdown code block. Note that the memory limit is unusual. You are given an integer n and two sequences a_1, a_2, ..., a_n and b_1, b_2, ..., b_n. Let's call a set of integers S such that S ⊆ \{1, 2, 3, ..., n\} strange, if, for every element i of S, the following conditi...
{"inputs": ["1\n6\n3\n", "1\n1\n8\n", "1\n1\n9\n", "1\n2\n9\n", "1\n5\n42\n", "1\n5\n-8\n", "1\n5\n45\n", "1\n5\n70\n"], "outputs": ["3\n", "8\n", "9\n", "9\n", "42\n", "0\n", "45\n", "70\n"]}
394
109
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. There are n cities. Some of them are connected, while some are not. If city a is connected directly with city b, and city b is connected directly with city c, then city a is connected indirectly with city c. A provinc...
{"functional": "def check(candidate):\n assert candidate(isConnected = [[1,1,0],[1,1,0],[0,0,1]]) == 2\n assert candidate(isConnected = [[1,0,0],[0,1,0],[0,0,1]]) == 3\n\n\ncheck(Solution().findCircleNum)"}
165
78
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. Append k unique positive integers that do not appear in nums to nums such that the resulting total sum is minimum. Return the sum of the k integers appended to num...
{"functional": "def check(candidate):\n assert candidate(nums = [1,4,25,10,25], k = 2) == 5\n assert candidate(nums = [5,6], k = 6) == 25\n\n\ncheck(Solution().minimalKSum)"}
98
68
coding
Solve the programming task below in a Python markdown code block. .intersection() The .intersection() operator returns the intersection of a set and the set of elements in an iterable. Sometimes, the & operator is used in place of the .intersection() operator, but it only operates on the set of elements in set. Th...
{"inputs": ["9\n1 2 3 4 5 6 7 8 9\n9\n10 1 2 3 11 21 55 6 8\n"], "outputs": ["5\n"]}
489
56
coding
Solve the programming task below in a Python markdown code block. The cockroach is one of the fastest insects. Write a function which takes its speed in km per hour and returns it in cm per second, rounded down to the integer (= floored). For example: ```python cockroach_speed(1.08) == 30 ``` Note! The input is a Re...
{"functional": "_inputs = [[1.08], [1.09], [0]]\n_outputs = [[30], [30], [0]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) != len(b): return False\n ...
123
176
coding
Solve the programming task below in a Python markdown code block. The Fair Nut likes kvass very much. On his birthday parents presented him $n$ kegs of kvass. There are $v_i$ liters of kvass in the $i$-th keg. Each keg has a lever. You can pour your glass by exactly $1$ liter pulling this lever. The Fair Nut likes this...
{"inputs": ["1 1\n1\n", "1 2\n1\n", "1 2\n1\n", "1 1\n1\n", "1 2\n2\n", "1 1\n2\n", "1 2\n3\n", "1 1\n0\n"], "outputs": ["0\n", "-1\n", "-1\n", "0\n", "0", "1", "1", "-1"]}
480
98
coding
Solve the programming task below in a Python markdown code block. Chef Two and Chef Ten are playing a game with a number $X$. In one turn, they can multiply $X$ by $2$. The goal of the game is to make $X$ divisible by $10$. Help the Chefs find the smallest number of turns necessary to win the game (it may be possible t...
{"inputs": ["3\n10\n25\n1"], "outputs": ["0\n1\n-1"]}
261
25
coding
Solve the programming task below in a Python markdown code block. The numbers of all offices in the new building of the Tax Office of IT City will have lucky numbers. Lucky number is a number that consists of digits 7 and 8 only. Find the maximum number of offices in the new building of the Tax Office given that a doo...
{"inputs": ["2\n", "1\n", "3\n", "5\n", "3\n", "5\n", "1\n", "6\n"], "outputs": ["6", "2", "14", "62", "14\n", "62\n", "2\n", "126\n"]}
152
72
coding
Solve the programming task below in a Python markdown code block. “Jesse, you asked me if I was in the meth business, or the money business… Neither. I’m in the empire business.” Walter’s sold his stack in Gray Matter Technologies, a company which he deserved half a credit, for peanuts. Now this company is worth a bill...
{"inputs": ["2\n5\n6 5 5 5 2\n5\n1 2 3 4 5"], "outputs": ["6 5 4 3 2\n1 2 3 4 5"]}
592
54
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an array nums with n integers, your task is to check if it could become non-decreasing by modifying at most one element. We define an array is non-decreasing if nums[i] <= nums[i + 1] holds for every i (0-based)...
{"functional": "def check(candidate):\n assert candidate(nums = [4,2,3]) == True\n assert candidate(nums = [4,2,1]) == False\n\n\ncheck(Solution().checkPossibility)"}
115
50
coding
Solve the programming task below in a Python markdown code block. Given an array with exactly 5 strings `"a"`, `"b"` or `"c"` (`char`s in Java, `character`s in Fortran), check if the array contains three and two of the same values. ## Examples ``` ["a", "a", "a", "b", "b"] ==> true // 3x "a" and 2x "b" ["a", "b", "c...
{"functional": "_inputs = [[['a', 'a', 'a', 'b', 'b']], [['a', 'c', 'a', 'c', 'b']], [['a', 'a', 'a', 'a', 'a']]]\n_outputs = [[True], [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=tol)\n if ...
181
206
coding
Solve the programming task below in a Python markdown code block. Given are positive integers A and B. Let us choose some number of positive common divisors of A and B. Here, any two of the chosen divisors must be coprime. At most, how many divisors can we choose?Definition of common divisor An integer d is said to be ...
{"inputs": ["1 1\n", "19 9", "31 9", "40 9", "66 9", "3 19", "3 38", "28 5"], "outputs": ["1\n", "1\n", "1\n", "1\n", "2\n", "1\n", "1\n", "1\n"]}
312
86
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an array nums containing n distinct numbers in the range [0, n], return the only number in the range that is missing from the array.   Please complete the following python code precisely: ```python class Solutio...
{"functional": "def check(candidate):\n assert candidate(nums = [3,0,1]) == 2\n assert candidate(nums = [0,1]) == 2\n assert candidate(nums = [9,6,4,2,3,5,7,0,1]) == 8\n assert candidate(nums = [0]) == 1\n\n\ncheck(Solution().missingNumber)"}
78
89
coding
Solve the programming task below in a Python markdown code block. You are given a tree with $N$ vertices (numbered $1$ through $N$) and a bag with $N$ markers. There is an integer written on each marker; each of these integers is $0$, $1$ or $2$. You must assign exactly one marker to each vertex. Let's define the unatt...
{"inputs": ["3\n3\n0 1 1\n1 2\n1 3\n3\n0 1 2\n1 2\n1 3\n4\n2 2 2 2\n1 2\n1 3\n3 4"], "outputs": ["1\n1\n0"]}
385
70
coding
Solve the programming task below in a Python markdown code block. A subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements. Longest common subsequence (LCS) of 2 sequences is a subsequence, with maximal length, which is common ...
{"inputs": ["5 6\n1 2 3 4 1\n3 4 1 2 1 3\n"], "outputs": ["1 2 3\n"]}
549
42
coding
Solve the programming task below in a Python markdown code block. Ivar the Boneless is a great leader. He is trying to capture Kattegat from Lagertha. The war has begun and wave after wave Ivar's warriors are falling in battle. Ivar has $n$ warriors, he places them on a straight line in front of the main gate, in a wa...
{"inputs": ["4 4\n1 2 3 4\n9 1 10 6\n", "4 4\n1 3 3 4\n9 1 10 6\n", "4 4\n1 3 6 4\n7 1 10 6\n", "4 4\n2 3 3 4\n7 1 10 6\n", "4 4\n2 3 3 4\n1 1 10 6\n", "4 4\n1 3 3 4\n7 1 10 6\n", "4 4\n1 2 6 4\n9 1 10 6\n", "4 4\n1 2 3 4\n9 1 10 6\n"], "outputs": ["1\n4\n4\n1\n", "1\n1\n4\n2\n", "2\n2\n4\n2\n", "2\n1\n4\n2\n", "4\n3\n...
671
270
coding
Solve the programming task below in a Python markdown code block. When preparing a tournament, Codeforces coordinators try treir best to make the first problem as easy as possible. This time the coordinator had chosen some problem and asked $n$ people about their opinions. Each person answered whether this problem is e...
{"inputs": ["1\n0\n", "1\n1\n", "1\n1\n", "1\n0\n", "2\n0 0\n", "2\n0 0\n", "3\n0 0 1\n", "3\n0 0 0\n"], "outputs": ["EASY\n", "HARD\n", "HARD\n", "EASY\n", "EASY\n", "EASY\n", "HARD\n", "EASY\n"]}
355
106