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. There is a directed graph with N vertices and M edges. The i-th edge (1≤i≤M) points from vertex a_i to vertex b_i, and has a weight c_i. We will play the following single-player game using this graph and a piece. Initially, the piece is placed at vertex ...
{"inputs": ["2 2\n1 2 2\n2 1 1", "2 2\n1 2 1\n2 1 1", "2 2\n1 2 1\n2 1 1\n", "3 3\n1 2 4\n2 2 3\n1 3 5", "3 3\n1 2 6\n2 3 0\n1 3 5", "3 3\n2 1 6\n2 3 1\n1 3 1", "3 2\n1 2 6\n1 3 0\n1 3 5", "3 3\n2 1 3\n2 3 1\n1 3 2"], "outputs": ["inf\n", "inf", "inf\n", "5\n", "6\n", "1\n", "0\n", "2\n"]}
517
204
coding
Solve the programming task below in a Python markdown code block. We get more and more news about DDoS-attacks of popular websites. Arseny is an admin and he thinks that a website is under a DDoS-attack if the total number of requests for a some period of time exceeds $100 \cdot t$, where $t$ — the number of seconds i...
{"inputs": ["1\n41\n", "1\n41\n", "1\n75\n", "1\n101\n", "1\n101\n", "1\n001\n", "1\n000\n", "1\n654\n"], "outputs": ["0\n", "0\n", "0\n", "1\n", "1\n", "0\n", "0\n", "1\n"]}
376
99
coding
Solve the programming task below in a Python markdown code block. We guessed some integer number $x$. You are given a list of almost all its divisors. Almost all means that there are all divisors except $1$ and $x$ in the list. Your task is to find the minimum possible integer $x$ that can be the guessed number, or sa...
{"inputs": ["2\n1\n25\n2\n5 25\n", "2\n1\n25\n2\n5 25\n", "2\n1\n31\n2\n5 25\n", "1\n2\n141440 554400\n", "1\n2\n141440 554400\n", "2\n8\n8 2 12 6 4 24 16 3\n1\n2\n", "2\n8\n8 2 12 6 4 24 16 3\n1\n2\n", "2\n5\n999983 999979 999961 999959 999952\n1\n23\n"], "outputs": ["-1\n125\n", "-1\n125\n", "961\n125\n", "-1\n", "-1...
347
255
coding
Solve the programming task below in a Python markdown code block. # Task Yesterday you found some shoes in your room. Each shoe is described by two values: ``` type indicates if it's a left or a right shoe; size is the size of the shoe. ``` Your task is to check whether it is possible to pair the shoes you found in s...
{"functional": "_inputs = [[[[0, 21], [1, 23], [1, 21], [0, 23]]], [[[0, 21], [1, 23], [1, 21], [1, 23]]], [[[0, 23], [1, 21], [1, 23], [0, 21], [1, 22], [0, 22]]], [[[0, 23], [1, 21], [1, 23], [0, 21]]], [[[0, 23], [1, 21], [1, 22], [0, 21]]], [[[0, 23]]], [[[0, 23], [1, 23]]], [[[0, 23], [1, 23], [1, 23], [0, 23]]], ...
333
450
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 decided to start a new firm called PatentChef. However, he's stuck with some big legal issues. Their firm has received offers from a lot of companies, so Chef told h...
{"inputs": ["2\n4 4 2 4\nEEOO\n4 3 1 4\nEEOO"], "outputs": ["yes\nno"]}
714
38
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. A sentence consists of lowercase letters ('a' to 'z'), digits ('0' to '9'), hyphens ('-'), punctuation marks ('!', '.', and ','), and spaces (' ') only. Each sentence can be broken down into one or more tokens separat...
{"functional": "def check(candidate):\n assert candidate(sentence = \"cat and dog\") == 3\n assert candidate(sentence = \"!this 1-s b8d!\") == 0\n assert candidate(sentence = \"alice and bob are playing stone-game10\") == 5\n\n\ncheck(Solution().countValidWords)"}
224
77
coding
Solve the programming task below in a Python markdown code block. You are given a sequence $a_1, a_2, \dots, a_n$ consisting of $n$ integers. You may perform the following operation on this sequence: choose any element and either increase or decrease it by one. Calculate the minimum possible difference between the ma...
{"inputs": ["3 3\n7 12 8\n", "3 3\n7 12 8\n", "4 5\n3 1 7 5\n", "4 5\n3 1 7 5\n", "5 1\n6 4 6 7 7\n", "5 1\n6 4 6 7 7\n", "5 1\n6 4 6 11 7\n", "3 10\n100 100 100\n"], "outputs": ["2\n", "2\n", "2\n", "2\n", "2\n", "2\n", "6\n", "0\n"]}
411
160
coding
Solve the programming task below in a Python markdown code block. Given a complete binary tree with the height of H, we index the nodes respectively top-down and left-right from 1. The i-th node stores a positive integer Vi. Define Pi as follows: Pi=Vi if the i-th node is a leaf, otherwise Pi=max(Vi*PL, Vi*PR), where L...
{"inputs": ["2\n1 2 3\n3\n3 1 5 2 6 4 7\n0"], "outputs": ["3\n105"]}
306
40
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an integer num. You will apply the following steps exactly two times: Pick a digit x (0 <= x <= 9). Pick another digit y (0 <= y <= 9). The digit y can be equal to x. Replace all the occurrences of x in...
{"functional": "def check(candidate):\n assert candidate(num = 555) == 888\n assert candidate(num = 9) == 8\n assert candidate(num = 123456) == 820000\n assert candidate(num = 10000) == 80000\n assert candidate(num = 9288) == 8700\n\n\ncheck(Solution().maxDiff)"}
160
107
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given the root of a binary tree, return its maximum depth. A binary tree's maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.   Please complete the following...
{"functional": "def check(candidate):\n assert candidate(root = tree_node([3,9,20,None,None,15,7])) == 3\n assert candidate(root = tree_node([1,None,2])) == 2\n\n\ncheck(Solution().maxDepth)"}
141
62
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given the head of a singly linked list, group all the nodes with odd indices together followed by the nodes with even indices, and return the reordered list. The first node is considered odd, and the second node is ev...
{"functional": "def check(candidate):\n assert is_same_list(candidate(head = list_node([1,2,3,4,5])), list_node([1,3,5,2,4]))\n assert is_same_list(candidate(head = list_node([2,1,3,5,6,4,7])), list_node([2,3,6,7,1,5,4]))\n\n\ncheck(Solution().oddEvenList)"}
184
100
coding
Solve the programming task below in a Python markdown code block. Did you know that the yummy golden triangle was introduced in India as early as 13th century ? By the way, I'm referring to the popular South Asian snack, Samosa. I guess its hard to code while thinking of Samosa, especially if you are very hungry now ; ...
{"inputs": ["1\n2\n10 20 34 55\n4\n7 5\n2 4\n21 6\n7 2", "1\n2\n12 20 34 55\n4\n7 5\n2 4\n21 6\n7 2", "1\n2\n12 20 34 55\n2\n7 5\n2 4\n21 6\n7 2", "1\n2\n12 20 34 55\n1\n7 5\n2 4\n21 6\n7 2", "1\n2\n10 20 34 55\n4\n7 14\n7 4\n14 6\n7 2", "1\n2\n10 20 34 55\n4\n7 14\n7 4\n21 6\n7 2", "1\n2\n10 20 34 55\n4\n7 14\n2 4\n21...
631
330
coding
Solve the programming task below in a Python markdown code block. Chef is given two strings A and B of length N containing lowercase English letters. Chef can rearrange both the strings in any way he wants. He wants to minimize the length of LCS ([Longest Common Subsequence] of both the strings. Find the minimum leng...
{"inputs": ["3\n4\naaaa\naaab\n1\nc\nz\n5\nabcde\ncdefg\n"], "outputs": ["3\n0\n1\n"]}
413
40
coding
Solve the programming task below in a Python markdown code block. Today is Devu's birthday. For celebrating the occasion, he bought n sweets from the nearby market. He has invited his f friends. He would like to distribute the sweets among them. As he is a nice guy and the occasion is great, he doesn't want any friend ...
{"inputs": ["1\n1 1\n", "1\n1 1\n", "2\n2 1\n2 2\n", "2\n2 1\n2 2\n", "2\n4 1\n2 2\n", "3\n3 1\n3 2\n3 3\n", "3\n3 1\n3 2\n3 3\n", "3\n5 1\n3 2\n3 3\n"], "outputs": ["1\n", "1\n", "0\n1\n", "0\n1\n", "0\n1\n", "0\n2\n1\n", "0\n2\n1\n", "0\n2\n1\n"]}
514
156
coding
Solve the programming task below in a Python markdown code block. Istiak is learning about arithmetic progressions. Today, he wrote an arithmetic sequence on a piece of paper. Istiak was very happy that he managed to write an arithmetic sequence and went out for lunch. Istiak's friend Rafsan likes to irritate him by pl...
{"inputs": ["3\n4\n1 3 10 7\n5\n-10 -5 0 5 10\n4\n2 2 2 10"], "outputs": ["1 3 5 7\n-10 -5 0 5 10\n2 2 2 2"]}
580
76
coding
Solve the programming task below in a Python markdown code block. ----- RANJANA QUIZ ----- Prof. Ranjana decided to conduct a quiz in her class. She divided all the students of her class into groups of three. Consider that no student was left out after the division. She gave different sets of questions to every group....
{"inputs": ["5\n6 5 4\n2 3 7\n4 6 5\n7 2 3\n5 3 1"], "outputs": ["1"]}
326
42
coding
Solve the programming task below in a Python markdown code block. We are still with squared integers. Given 4 integers `a, b, c, d` we form the sum of the squares of `a` and `b` and then the sum of the squares of `c` and `d`. We multiply the two sums hence a number `n` and we try to decompose `n` in a sum of two squar...
{"functional": "_inputs = [[1, 2, 1, 3], [2, 3, 4, 5], [1, 2, 2, 3], [1, 1, 3, 5], [10, 11, 12, 13], [1, 20, -4, -5], [100, 100, 100, 100], [0, 0, 0, 0], [-14, 12, -10, 8], [7, 96, -1, 81], [112, 0, 0, 1]]\n_outputs = [[[[1, 7], [5, 5]]], [[[2, 23], [7, 22]]], [[[1, 8], [4, 7]]], [[[2, 8]]], [[[2, 263], [23, 262]]], [[...
629
454
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an array of strings words, return the first palindromic string in the array. If there is no such string, return an empty string "". A string is palindromic if it reads the same forward and backward.   Please com...
{"functional": "def check(candidate):\n assert candidate(words = [\"abc\",\"car\",\"ada\",\"racecar\",\"cool\"]) == \"ada\"\n assert candidate(words = [\"notapalindrome\",\"racecar\"]) == \"racecar\"\n assert candidate(words = [\"def\",\"ghi\"]) == \"\"\n\n\ncheck(Solution().firstPalindrome)"}
96
81
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Your laptop keyboard is faulty, and whenever you type a character 'i' on it, it reverses the string that you have written. Typing other characters works as expected. You are given a 0-indexed string s, and you type ea...
{"functional": "def check(candidate):\n assert candidate(s = \"string\") == \"rtsng\"\n assert candidate(s = \"poiinter\") == \"ponter\"\n\n\ncheck(Solution().finalString)"}
119
48
coding
Solve the programming task below in a Python markdown code block. Some time ago Mister B detected a strange signal from the space, which he started to study. After some transformation the signal turned out to be a permutation p of length n or its cyclic shift. For the further investigation Mister B need some basis, th...
{"inputs": ["2\n1 2\n", "2\n2 1\n", "2\n1 2\n", "2\n2 1\n", "3\n1 2 3\n", "3\n2 3 1\n", "3\n3 2 1\n", "3\n1 3 3\n"], "outputs": ["0 0\n", "0 1\n", "0 0\n", "0 1\n", "0 0\n", "0 1\n", "2 1\n", "1 0\n"]}
588
126
coding
Solve the programming task below in a Python markdown code block. Description F, who likes to dance, decided to practice a hardcore dance called JUMP STYLE at a certain dance hall. The floor is tiled in an N × N grid. To support the dance practice, each tile has the coordinates of the tile to jump to the next step. F...
{"inputs": ["1\n0 0\n2\n1 1 0 1\n1 0 0 0\n2\n1 1 0 1\n1 1 1 0\n3\n0 1 2 2 2 0\n0 2 1 2 2 1\n0 0 0 1 1 1\n4\n3 2 2 0 3 2 2 1\n1 1 0 3 1 1 3 1\n0 3 2 3 3 0 2 3\n1 1 1 1 3 2 1 3\n0", "1\n0 0\n2\n1 1 0 1\n1 0 0 0\n2\n1 1 0 1\n1 1 1 0\n3\n0 1 2 2 2 0\n0 2 1 2 2 1\n0 0 0 1 1 0\n4\n3 2 2 0 3 2 2 1\n1 1 0 3 1 1 3 1\n0 3 2 3 3 ...
688
1,286
coding
Solve the programming task below in a Python markdown code block. Takahashi has a lot of peculiar devices. These cylindrical devices receive balls from left and right. Each device is in one of the two states A and B, and for each state, the device operates as follows: * When a device in state A receives a ball from ei...
{"inputs": ["5 1\nAAAAA", "5 2\nAAABA", "5 1\nAAABA", "5 3\nAAABA", "5 1\nAAAAB", "5 2\nAAAAA", "5 1\nAAABB", "5 3\nAAAAA"], "outputs": ["BAAAA\n", "BBABA\n", "BAABA\n", "ABABA\n", "BAAAB\n", "BBBBA\n", "BAABB\n", "AAABA\n"]}
525
112
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. An integer n is strictly palindromic if, for every base b between 2 and n - 2 (inclusive), the string representation of the integer n in base b is palindromic. Given an integer n, return true if n is strictly palindro...
{"functional": "def check(candidate):\n assert candidate(n = 9) == False\n assert candidate(n = 4) == False\n\n\ncheck(Solution().isStrictlyPalindromic)"}
129
46
coding
Solve the programming task below in a Python markdown code block. Given an array A of length N, your task is to find the element which repeats in A maximum number of times as well as the corresponding count. In case of ties, choose the smaller element first. ------ Input ------ First line of input contains an intege...
{"inputs": ["2\n5\n1 2 3 2 5\n6\n1 2 2 1 1 2"], "outputs": ["2 2\n1 3"]}
282
44
coding
Solve the programming task below in a Python markdown code block. Bimokh is Mashmokh's boss. For the following n days he decided to pay to his workers in a new way. At the beginning of each day he will give each worker a certain amount of tokens. Then at the end of each day each worker can give some of his tokens back ...
{"inputs": ["1 1 1\n1\n", "1 1 1\n1\n", "3 1 2\n1 2 3\n", "3 1 2\n1 0 3\n", "3 1 3\n1 0 3\n", "3 1 3\n2 0 3\n", "3 1 4\n1 0 3\n", "3 1 2\n1 1 1\n"], "outputs": ["0 ", "0\n", "1 0 1 ", "1 0 1\n", "1 0 0\n", "2 0 0\n", "1 0 3\n", "1 1 1\n"]}
412
164
coding
Solve the programming task below in a Python markdown code block. Your friend Ivan asked you to help him rearrange his desktop. The desktop can be represented as a rectangle matrix of size $n \times m$ consisting of characters '.' (empty cell of the desktop) and '*' (an icon). The desktop is called good if all its ico...
{"inputs": ["1 1 1\n*\n1 1\n", "2 5 5\n*...*\n*****\n1 3\n2 2\n1 3\n1 5\n2 3\n", "4 4 8\n..**\n.*..\n*...\n...*\n1 3\n2 3\n3 1\n2 3\n3 4\n4 3\n2 3\n2 2\n"], "outputs": ["0\n", "2\n3\n3\n3\n2\n", "3\n4\n4\n3\n4\n5\n5\n5\n"]}
605
142
coding
Solve the programming task below in a Python markdown code block. Every day, Mike goes to his job by a bus, where he buys a ticket. On the ticket, there is a letter-code that can be represented as a string of upper-case Latin letters. Mike believes that the day will be successful in case exactly two different letters i...
{"inputs": ["2\nABABAB\nABC"], "outputs": ["YES\nNO"]}
331
20
coding
Solve the programming task below in a Python markdown code block. Jzzhu have n non-negative integers a1, a2, ..., an. We will call a sequence of indexes i1, i2, ..., ik (1 ≤ i1 < i2 < ... < ik ≤ n) a group of size k. Jzzhu wonders, how many groups exists such that ai1 & ai2 & ... & aik = 0 (1 ≤ k ≤ n)? Help him and p...
{"inputs": ["1\n1\n", "1\n0\n", "1\n2\n", "1\n4\n", "1\n8\n", "1\n14\n", "2\n1 0\n", "2\n0 1\n"], "outputs": ["0\n", "1\n", "0", "0", "0", "0", "2\n", "2\n"]}
265
87
coding
Solve the programming task below in a Python markdown code block. Two players (numbered $\mbox{1}$ and $2$) are playing a game of Tower Breakers! The rules of the game are as follows: Player $\mbox{1}$ always moves first, and both players always move optimally. Initially there are $N$ towers of various heights. The pl...
{"inputs": ["2\n2 \n1 2\n3 \n1 2 3\n"], "outputs": ["1\n2\n"]}
507
32
coding
Solve the programming task below in a Python markdown code block. Oh no! You have stumbled upon a mysterious signal consisting of beeps of various lengths, and it is of utmost importance that you find out the secret message hidden in the beeps. There are long and short beeps, the longer ones roughly three times as lo...
{"functional": "_inputs = [['.... . .-.. .-.. --- .-- --- .-. .-.. -..'], ['.---- ... - .- -. -.. ..--- -. -..'], ['.. .- -- .- - . ... -'], ['.- -... -.-. -.. . ..-. --. .... .. .--- -.- .-.. -- -. --- .--. --.- .-. ... - ..- ...- .-- -..- -.-- --.. ----- .---- ..--- ...-- ....- ..... -.... --... ---.. ----.'], ...
520
304
coding
Solve the programming task below in a Python markdown code block. Create a function that takes a list of one or more non-negative integers, and arranges them such that they form the largest possible number. Examples: `largestArrangement([4, 50, 8, 145])` returns 8504145 (8-50-4-145) `largestArrangement([4, 40, 7])` ...
{"functional": "_inputs = [[[50, 2, 1, 9]], [[3655, 89]], [[8]], [[12, 13, 89, 155, 8, 26, 0]], [[76, 4, 3, 81, 514, 6, 716]], [[817, 6879, 163, 348, 8, 22, 47]], [[411, 742, 89, 691, 284]], [[587, 625, 638, 898, 122]], [[797, 535, 210, 87]], [[5, 2, 1, 9, 50, 56]], [[197, 853, 819]], [[23044, 2, 7626, 914, 7800]], [[4...
262
1,354
coding
Solve the programming task below in a Python markdown code block. You are given a weighted graph with $N$ nodes and $M$ edges. Some of the nodes are marked as special nodes. Your task is to find the shortest pairwise distance between any two different special nodes. -----Input----- - The first line of the input contai...
{"inputs": ["5 5 3\n1 3 5\n1 2 3\n2 3 4\n3 4 1\n4 5 8\n1 5 19"], "outputs": ["7"]}
597
53
coding
Solve the programming task below in a Python markdown code block. In Python, code blocks don't have explicit begin/end or curly braces to mark beginning and end of the block. Instead, code blocks are defined by indentation. We will consider an extremely simplified subset of Python with only two types of statements. S...
{"inputs": ["1\ns\n", "1\ns\n", "2\nf\ns\n", "2\ns\ns\n", "2\nf\ns\n", "2\ns\ns\n", "3\nf\nf\ns\n", "3\nf\nf\ns\n"], "outputs": ["1\n", "1", "1\n", "1\n", "1", "1", "1\n", "1"]}
450
98
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You have n tasks and m workers. Each task has a strength requirement stored in a 0-indexed integer array tasks, with the ith task requiring tasks[i] strength to complete. The strength of each worker is stored in a 0-i...
{"functional": "def check(candidate):\n assert candidate(tasks = [3,2,1], workers = [0,3,3], pills = 1, strength = 1) == 3\n assert candidate(tasks = [5,4], workers = [0,0,0], pills = 1, strength = 5) == 1\n assert candidate(tasks = [10,15,30], workers = [0,10,10,10,10], pills = 3, strength = 10) == 2\n ass...
233
178
coding
Solve the programming task below in a Python markdown code block. You are given an integer sequence of length N. The i-th term in the sequence is a_i. In one operation, you can select a term and either increment or decrement it by one. At least how many operations are necessary to satisfy the following conditions? - F...
{"inputs": ["4\n1 -3 1 0\n", "5\n3 -6 4 -5 7\n", "6\n-1 4 3 2 -5 4\n"], "outputs": ["4\n", "0\n", "8\n"]}
300
61
coding
Solve the programming task below in a Python markdown code block. Given N integers A_1, ..., A_N, compute A_1 \times ... \times A_N. However, if the result exceeds 10^{18}, print -1 instead. -----Constraints----- - 2 \leq N \leq 10^5 - 0 \leq A_i \leq 10^{18} - All values in input are integers. -----Input----- Inp...
{"inputs": ["3\n011 1 315218201", "3\n001 188 468791915", "3\n011 188 468791915", "3\n011 291 468791915", "3\n011 133 468791915", "3\n011 133 735631313", "3\n011 133 315218201", "3\n101 2947 468791915"], "outputs": ["3467400211\n", "88132880020\n", "969461680220\n", "1500602919915\n", "685842571645\n", "1076228610919\n...
257
295
coding
Solve the programming task below in a Python markdown code block. You have a string S consisting of N uppercase English letters. You are allowed to perform at most one operation of following kind: Choose any position in the string, remove the character at that position and insert it back to any other place in the strin...
{"inputs": ["2\n4\nDCBA\n7\nXYZZYZZ", "2\n4\nDCBA\n7\nXYZZYZY", "2\n4\nDCBA\n7\nXZZZYZZ", "2\n4\nABCD\n7\nXYZZYZY", "2\n4\nCBAD\n7\nXYZZYZY", "2\n4\nCBAD\n7\nYZYZZYX", "2\n4\nCDAB\n7\nYZYZZYX", "2\n4\nCDAB\n7\nYZYZZYW"], "outputs": ["ADCB\nXYYZZZZ", "ADCB\nXYYZZYZ\n", "ADCB\nXYZZZZZ\n", "ABCD\nXYYZZYZ\n", "ACBD\nXYYZZY...
297
206
coding
Solve the programming task below in a Python markdown code block. In this Kata, you will be given an array of integers and your task is to return the number of arithmetic progressions of size `3` that are possible from that list. In each progression, the differences between the elements must be the same. ``` [1, 2, 3,...
{"functional": "_inputs = [[[1, 2, 3, 4, 5]], [[1, 2, 3, 5, 7, 9]], [[0, 5, 8, 9, 11, 13, 14, 16, 17, 19]], [[0, 1, 2, 3, 5, 6, 7, 11, 13, 15, 17, 19]], [[0, 1, 4, 5, 7, 9, 10, 13, 15, 16, 18, 19]], [[0, 1, 2, 3, 5, 8, 11, 13, 14, 16, 18, 19]]]\n_outputs = [[4], [5], [10], [17], [15], [13]]\nimport math\ndef _deep_eq(a...
172
364
coding
Solve the programming task below in a Python markdown code block. You have a fence consisting of $n$ vertical boards. The width of each board is $1$. The height of the $i$-th board is $a_i$. You think that the fence is great if there is no pair of adjacent boards having the same height. More formally, the fence is grea...
{"inputs": ["3\n3\n2 4\n2 1\n3 5\n3\n2 3\n2 2\n2 6\n4\n1 7\n3 3\n2 6\n1000000000 2\n", "3\n3\n2 4\n2 0\n3 5\n3\n2 3\n2 2\n2 6\n4\n1 7\n3 3\n2 6\n1000000000 4\n", "3\n3\n2 4\n2 1\n0 5\n3\n2 3\n2 2\n1 6\n4\n1 7\n3 3\n2 6\n1000000000 2\n", "3\n3\n2 4\n2 0\n3 5\n3\n2 3\n2 2\n2 6\n4\n1 7\n3 3\n3 6\n1000000000 4\n", "3\n3\n2...
605
542
coding
Solve the programming task below in a Python markdown code block. There is a legend in the IT City college. A student that failed to answer all questions on the game theory exam is given one more chance by his professor. The student has to play a game with the professor. The game is played on a square field consisting...
{"inputs": ["1\n", "2\n", "3\n", "4\n", "5\n", "4\n", "5\n", "3\n"], "outputs": ["1", "2", "1", "2", "1", "2", "1", "1"]}
258
62
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. An integer x is numerically balanced if for every digit d in the number x, there are exactly d occurrences of that digit in x. Given an integer n, return the smallest numerically balanced number strictly greater than ...
{"functional": "def check(candidate):\n assert candidate(n = 1) == 22\n assert candidate(n = 1000) == 1333\n assert candidate(n = 3000) == 3133\n\n\ncheck(Solution().nextBeautifulNumber)"}
93
69
coding
Solve the programming task below in a Python markdown code block. You are given two integers a and b. In one turn, you can do one of the following operations: * Take an integer c (c > 1 and a should be divisible by c) and replace a with a/c; * Take an integer c (c > 1 and b should be divisible by c) and replace ...
{"inputs": ["1\n8 5469 4\n", "1\n8 5469 1\n", "1\n7 5469 1\n", "1\n8 2465 4\n", "1\n8 5469 2\n", "1\n9 5469 1\n", "1\n8 2661 4\n", "1\n9 5469 2\n"], "outputs": ["YES\n", "NO\n", "NO\n", "YES\n", "YES\n", "NO\n", "YES\n", "YES\n"]}
445
142
coding
Solve the programming task below in a Python markdown code block. You are given an array $a$ consisting of $n$ integers $a_1, a_2, \dots , a_n$. In one operation you can choose two elements of the array and replace them with the element equal to their sum (it does not matter where you insert the new element). For exam...
{"inputs": ["1\n5\n3 3 3 3 3\n", "1\n5\n3 3 3 3 3\n", "1\n5\n3 3 0 3 3\n", "1\n5\n3 3 1 3 3\n", "1\n5\n3 0 1 4 3\n", "1\n5\n2 1 0 2 2\n", "1\n5\n0 3 0 3 3\n", "1\n5\n3 0 1 3 3\n"], "outputs": ["5\n", "5\n", "5\n", "4\n", "3\n", "2\n", "5\n", "4\n"]}
522
166
coding
Solve the programming task below in a Python markdown code block. You have an array A of size N containing only positive numbers. You have to output the maximum possible value of A[i]%A[j] where 1<=i,j<=N. -----Input----- The first line of each test case contains a single integer N denoting the size of the array. The...
{"inputs": ["2\n1\n2"], "outputs": ["1"]}
272
16
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a string s, partition s such that every substring of the partition is a palindrome. Return the minimum cuts needed for a palindrome partitioning of s.   Please complete the following python code precisely: ```py...
{"functional": "def check(candidate):\n assert candidate(s = \"aab\") == 1\n assert candidate(s = \"a\") == 0\n assert candidate(s = \"ab\") == 1\n\n\ncheck(Solution().minCut)"}
78
55
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Consider a matrix M with dimensions width * height, such that every cell has value 0 or 1, and any square sub-matrix of M of size sideLength * sideLength has at most maxOnes ones. Return the maximum possible number of...
{"functional": "def check(candidate):\n assert candidate(width = 3, height = 3, sideLength = 2, maxOnes = 1) == 4\n assert candidate(width = 3, height = 3, sideLength = 2, maxOnes = 2) == 6\n\n\ncheck(Solution().maximumNumberOfOnes)"}
127
81
coding
Solve the programming task below in a Python markdown code block. There are N children standing in a line from left to right. The activeness of the i-th child from the left is A_i. You can rearrange these children just one time in any order you like. When a child who originally occupies the x-th position from the left ...
{"inputs": ["4\n1 4 4 2", "4\n1 8 4 2", "4\n2 8 4 2", "4\n4 8 4 1", "4\n1 0 4 2", "4\n1 4 4 0", "4\n2 8 0 1", "4\n1 3 4 2"], "outputs": ["22\n", "30\n", "32\n", "34\n", "15\n", "18\n", "23\n", "20"]}
320
133
coding
Solve the programming task below in a Python markdown code block. Chef has closed his restaurant and decided to run a fruit stand instead. His signature dish is a fruit chaat consisting of 2 bananas and 1 apple. He currently has X bananas and Y apples. How many chaats can he make with the fruits he currently has? ---...
{"inputs": ["3\n72 50\n38 93\n51 4"], "outputs": ["36\n19\n4\n"]}
281
36
coding
Solve the programming task below in a Python markdown code block. Today, Mezo is playing a game. Zoma, a character in that game, is initially at position $x = 0$. Mezo starts sending $n$ commands to Zoma. There are two possible commands: 'L' (Left) sets the position $x: =x - 1$; 'R' (Right) sets the position $x: =x +...
{"inputs": ["1\nL\n", "1\nR\n", "1\nR\n", "1\nL\n", "2\nLR\n", "2\nLR\n", "2\nRL\n", "4\nLRLR\n"], "outputs": ["2\n", "2\n", "2\n", "2\n", "3\n", "3\n", "3\n", "5\n"]}
416
88
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...
{"inputs": ["1\n1\n7\n", "1\n2\n7\n", "1\n2\n4\n", "1\n1\n72\n", "1\n5\n16\n", "1\n3\n31\n", "1\n1\n72\n", "1\n3\n31\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]}
409
107
coding
Solve the programming task below in a Python markdown code block. Chef has scored A, B, and C marks in 3 different subjects respectively. Chef will fail if the average score of any two subjects is less than 35. Determine whether Chef will pass or fail. ------ Input Format ------ - First line will contain T, number...
{"inputs": ["4\n23 47 52\n28 36 80\n0 100 0\n35 35 35\n"], "outputs": ["Pass\nFail\nFail\nPass"]}
418
54
coding
Solve the programming task below in a Python markdown code block. You are given a positive integer N. You have to split each digit of N into either of two non-empty subsequences A or B. For example, if N = 104, some possible values of (A, B) can be (10, 4), (14, 0) and (1, 4). Note that, after separating the digits ...
{"inputs": ["2\n10\n73452"], "outputs": ["NO\nYES\n"]}
599
24
coding
Solve the programming task below in a Python markdown code block. Let's dive into decorators! You are given $N$ mobile numbers. Sort them in ascending order then print them in the standard format shown below: +91 xxxxx xxxxx The given mobile numbers may have $+91$, $91$ or $\mbox{0}$ written before the actual $10$ di...
{"inputs": ["3\n07895462130\n919875641230\n9195969878\n"], "outputs": ["+91 78954 62130\n+91 91959 69878\n+91 98756 41230\n"]}
322
96
coding
Solve the programming task below in a Python markdown code block. You've had a baby. Well done. Nice isn't it? Life destroying... but in a good way. Part of your new routine is lying awake at night worrying that you've either lost the baby... or that you have more than 1! Given a string of words (x), you need to cal...
{"functional": "_inputs = [['baby'], ['abby'], ['baby baby baby'], ['Why the hell are there so many babies?!'], ['Anyone remember life before babies?'], ['Happy babies boom ba by?'], ['b a b y'], [''], ['none here']]\n_outputs = [[1], [1], [3], [1], [1], [2], [1], [\"Where's the baby?!\"], [\"Where's the baby?!\"]]\nim...
227
238
coding
Solve the programming task below in a Python markdown code block. A manufacturing project consists of exactly $K$ tasks. The board overviewing the project wants to hire $K$ teams of workers — one for each task. All teams begin working simultaneously. Obviously, there must be at least one person in each team. For a team...
{"inputs": ["2\n2 3\n2 6"], "outputs": ["4\n5"]}
527
22
coding
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin chinese, Russian and Vietnamese as well. When the final results for the employement competition were announced, Nour Eddin Ramadan was thrilled to find his name among the accepted co-Chefs. However, after a while N...
{"inputs": ["4\n2\n3\n4\n10000000000"], "outputs": ["1\n2\n3\n69999300"]}
430
43
coding
Solve the programming task below in a Python markdown code block. There is an array with some numbers. All numbers are equal except for one. Try to find it! ```python find_uniq([ 1, 1, 1, 2, 1, 1 ]) == 2 find_uniq([ 0, 0, 0.55, 0, 0 ]) == 0.55 ``` It’s guaranteed that array contains at least 3 numbers. The tests con...
{"functional": "_inputs = [[[1, 1, 1, 2, 1, 1]], [[0, 0, 0.55, 0, 0]], [[4, 4, 4, 3, 4, 4, 4, 4]], [[5, 5, 5, 5, 4, 5, 5, 5]], [[6, 6, 6, 6, 6, 5, 6, 6]], [[7, 7, 7, 7, 7, 7, 6, 7]], [[8, 8, 8, 8, 8, 8, 8, 7]], [[3, 3, 3, 3, 3, 3, 3, 2]], [[2, 2, 2, 2, 2, 2, 2, 1]], [[0, 1, 1, 1, 1, 1, 1, 1]]]\n_outputs = [[2], [0.55],...
238
410
coding
Solve the programming task below in a Python markdown code block. There is a grid with N rows and N columns of squares. Let (i,j) be the square at the i-th row from the top and the j-th column from the left. These squares have to be painted in one of the C colors from Color 1 to Color C. Initially, (i,j) is painted in ...
{"inputs": ["2 3\n0 1 1\n1 1 1\n1 4 0\n1 2\n3 3", "2 3\n0 1 1\n1 1 1\n2 4 0\n1 2\n3 3", "2 3\n0 1 1\n1 0 1\n1 4 0\n1 2\n1 3", "2 3\n0 2 1\n1 1 1\n2 4 0\n1 2\n3 3", "2 3\n0 1 1\n1 0 1\n1 4 0\n1 2\n2 3", "2 3\n1 3 1\n1 1 1\n2 4 0\n1 2\n3 3", "2 3\n2 3 1\n2 1 1\n3 4 0\n1 2\n3 3", "2 3\n1 1 1\n1 1 1\n1 4 0\n1 2\n3 3"], "ou...
617
286
coding
Solve the programming task below in a Python markdown code block. $N$ sages are sitting around a round table with $N$ seats. Each sage holds chopsticks with his dominant hand to eat his dinner. The following happens in this situation. * If sage $i$ is right-handed and a left-handed sage sits on his right, a level of f...
{"inputs": ["3\n0 0 0\n1 1 3", "3\n0 1 0\n1 1 2", "3\n0 0 1\n1 2 5", "3\n0 0 1\n1 0 7", "3\n0 0 1\n2 1 7", "3\n0 0 1\n1 1 8", "3\n0 0 0\n1 1 2", "3\n0 0 0\n1 2 5"], "outputs": ["0\n", "2\n", "6\n", "7\n", "8\n", "9\n", "0\n", "0\n"]}
400
158
coding
Solve the programming task below in a Python markdown code block. You are given two integers A and B. Find the largest value among A+B, A-B and A \times B. -----Constraints----- - -1000 \leq A,B \leq 1000 - All values in input are integers. -----Input----- Input is given from Standard Input in the following format:...
{"inputs": ["6 1", "6 0", "9 1", "3 0", "9 0", "4 0", "5 0", "3 5"], "outputs": ["7\n", "6\n", "10\n", "3\n", "9\n", "4\n", "5\n", "15\n"]}
149
80
coding
Solve the programming task below in a Python markdown code block. Petya has got an interesting flower. Petya is a busy person, so he sometimes forgets to water it. You are given $n$ days from Petya's live and you have to determine what happened with his flower in the end. The flower grows as follows: If the flower is...
{"inputs": ["1\n10\n1 1 1 1 1 1 1 1 1 1\n", "4\n3\n1 0 1\n3\n0 1 1\n4\n1 0 0 1\n1\n0\n"], "outputs": ["47\n", "3\n7\n-1\n1\n"]}
441
83
coding
Solve the programming task below in a Python markdown code block. You received a whatsup message from an unknown number. Could it be from that girl/boy with a foreign accent you met yesterday evening? Write a simple regex to check if the string contains the word hallo in different languages. These are the languages o...
{"functional": "_inputs = [['hello'], ['ciao bella!'], ['salut'], ['hallo, salut'], ['hombre! Hola!'], [\"Hallo, wie geht's dir?\"], ['AHOJ!'], ['czesc'], ['meh'], ['Ahoj']]\n_outputs = [[True], [True], [True], [True], [True], [True], [True], [True], [False], [True]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if ...
210
236
coding
Solve the programming task below in a Python markdown code block. There are N mountains in a circle, called Mountain 1, Mountain 2, ..., Mountain N in clockwise order. N is an odd number. Between these mountains, there are N dams, called Dam 1, Dam 2, ..., Dam N. Dam i (1 \leq i \leq N) is located between Mountain i an...
{"inputs": ["3\n2 0 4", "3\n2 0 6", "3\n2 0 0", "3\n0 0 6", "3\n2 1 5", "3\n2 2 4", "3\n2 2 4\n", "5\n3 8 1 5 5"], "outputs": ["6 -2 2\n", "8 -4 4\n", "2 2 -2\n", "6 -6 6\n", "6 -2 4\n", "4 0 4", "4 0 4\n", "-4 10 6 -4 14\n"]}
493
152
coding
Solve the programming task below in a Python markdown code block. Little Joty has got a task to do. She has a line of n tiles indexed from 1 to n. She has to paint them in a strange pattern. An unpainted tile should be painted Red if it's index is divisible by a and an unpainted tile should be painted Blue if it's ind...
{"inputs": ["1 1 1 1 1\n", "1 2 2 2 2\n", "2 1 3 3 3\n", "3 1 1 3 3\n", "4 1 5 4 3\n", "8 8 1 1 1\n", "6 6 2 8 2\n", "5 2 2 4 1\n"], "outputs": ["1\n", "0\n", "6\n", "9\n", "16\n", "8\n", "12\n", "8\n"]}
300
136
coding
Solve the programming task below in a Python markdown code block. Mr. Dango's family has extremely huge number of members. Once it had about 100 members, and now it has as many as population of a city. It is jokingly guessed that the member might fill this planet in near future. They all have warm and gracious personal...
{"inputs": ["3\n1 1 2 3\n0 1 2 2\n1 2 0 3\n7\n1 2 2 1\n0 2 3 2\n0 1 3 1\n2 1 1 2\n5 3 4 2\n4 3 6 1\n4 2 5 1\n0", "3\n1 2 2 3\n0 1 2 2\n1 2 0 3\n7\n1 2 0 1\n0 2 3 2\n0 0 3 2\n2 2 1 2\n5 3 4 2\n4 3 6 1\n4 0 5 1\n0", "3\n1 1 2 3\n0 0 2 2\n1 2 0 3\n0\n1 2 2 1\n0 2 3 2\n0 1 3 0\n2 1 1 2\n5 3 4 2\n4 3 6 1\n4 2 5 1\n0", "3\n1...
763
748
coding
Solve the programming task below in a Python markdown code block. You are given a set of $n$ segments on the axis $Ox$, each segment has integer endpoints between $1$ and $m$ inclusive. Segments may intersect, overlap or even coincide with each other. Each segment is characterized by two integers $l_i$ and $r_i$ ($1 \l...
{"inputs": ["1 7\n1 7\n", "1 7\n5 5\n", "1 2\n1 1\n", "1 7\n5 5\n", "1 2\n1 1\n", "1 9\n5 5\n", "1 3\n1 1\n", "1 7\n1 7\n"], "outputs": ["0\n\n", "6\n1 2 3 4 6 7 \n", "1\n2 \n", "6\n1 2 3 4 6 7\n", "1\n2\n", "8\n1 2 3 4 6 7 8 9\n", "2\n2 3\n", "0\n\n"]}
505
170
coding
Solve the programming task below in a Python markdown code block. In this kata, the number 0 is infected. You are given a list. Every turn, any item in the list that is adjacent to a 0 becomes infected and transforms into a 0. How many turns will it take for the whole list to become infected? ``` [0,1,1,0] ==> [0,0,0,...
{"functional": "_inputs = [[[0]], [[0, 1, 1, 0]], [[0, 1, 1, 1, 0]], [[1, 1, 0, 1, 1]], [[0, 1, 1, 1]], [[1, 1, 1, 0]]]\n_outputs = [[0], [1], [2], [2], [3], [3]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol...
254
238
coding
Solve the programming task below in a Python markdown code block. Takahashi recorded his daily life for the last few days as a integer sequence of length 2N, as follows: * a_1, b_1, a_2, b_2, ... , a_N, b_N This means that, starting from a certain time T, he was: * sleeping for exactly a_1 seconds * then awake for...
{"inputs": ["3\n11001 2265\n499 81568\n5242 218", "3\n10000 2054\n499 42643\n5242 146", "3\n10000 2054\n499 42643\n5242 218", "3\n10000 2054\n499 64506\n5242 218", "3\n11000 2054\n499 64506\n5242 218", "3\n11000 2265\n499 64506\n5242 218", "3\n11001 2265\n499 64506\n5242 218", "3\n11162 10322\n5814 7716\n84163 87"], "o...
531
303
coding
Solve the programming task below in a Python markdown code block. Arkady invited Anna for a dinner to a sushi restaurant. The restaurant is a bit unusual: it offers $n$ pieces of sushi aligned in a row, and a customer has to choose a continuous subsegment of these sushi to buy. The pieces of sushi are of two types: ei...
{"inputs": ["2\n1 2\n", "2\n2 1\n", "2\n1 2\n", "2\n2 1\n", "3\n1 1 2\n", "3\n2 1 1\n", "3\n1 1 2\n", "3\n2 1 1\n"], "outputs": ["2\n", "2\n", "2\n", "2\n", "2\n", "2\n", "2\n", "2\n"]}
596
110
coding
Solve the programming task below in a Python markdown code block. A new task for you! You have to create a method, that corrects a given time string. There was a problem in addition, so many of the time strings are broken. Time-Format is european. So from "00:00:00" to "23:59:59". Some examples: "09:10:01" -> "09:1...
{"functional": "_inputs = [[None], [''], ['001122'], ['00;11;22'], ['0a:1c:22'], ['09:10:01'], ['11:70:10'], ['19:99:99'], ['24:01:01'], ['52:01:01'], ['14:59:94']]\n_outputs = [[None], [''], [None], [None], [None], ['09:10:01'], ['12:10:10'], ['20:40:39'], ['00:01:01'], ['04:01:01'], ['15:00:34']]\nimport math\ndef _d...
260
315
coding
Solve the programming task below in a Python markdown code block. The girl Taylor has a beautiful calendar for the year y. In the calendar all days are given with their days of week: Monday, Tuesday, Wednesday, Thursday, Friday, Saturday and Sunday. The calendar is so beautiful that she wants to know what is the next ...
{"inputs": ["2016\n", "2000\n", "1000\n", "1900\n", "1899\n", "1004\n", "2100\n", "1313\n"], "outputs": ["2044\n", "2028\n", "1006\n", "1906\n", "1905\n", "1032\n", "2106\n", "1319\n"]}
274
118
coding
Solve the programming task below in a Python markdown code block. For Diwali, Chef arranges all $K$ laddus in a row in his sweet shop. Whenever a customer comes to buy laddus, chef follows a rule that each customer must buy all laddus on odd position. After the selection of the laddu, a new row is formed, and again out...
{"inputs": ["3\n1\n5\n8"], "outputs": ["1\n4\n8"]}
309
22
coding
Solve the programming task below in a Python markdown code block. Consider the following arithmetic progression with n terms: * x, x + d, x + 2d, \ldots, x + (n-1)d What is the product of all terms in this sequence? Compute the answer modulo 1\ 000\ 003. You are given Q queries of this form. In the i-th query, com...
{"inputs": ["2\n7 3 4\n12345 30036 63", "2\n7 3 4\n12345 57737 63", "2\n7 1 1\n9796 9219 1485", "2\n7 2 4\n12345 57737 63", "2\n7 1 1\n9796 9219 2637", "2\n3 2 4\n12345 57737 63", "2\n3 1 4\n12345 57737 63", "2\n3 1 0\n12345 57737 63"], "outputs": ["14560\n487009\n", "14560\n462686\n", "7\n37900\n", "9009\n462686\n", "...
276
300
coding
Solve the programming task below in a Python markdown code block. ## The Riddle The King of a small country invites 1000 senators to his annual party. As a tradition, each senator brings the King a bottle of wine. Soon after, the Queen discovers that one of the senators is trying to assassinate the King by giving him ...
{"functional": "_inputs = [[[0]], [[1]], [[2]], [[3]], [[4]], [[5]], [[6]], [[7]], [[8]], [[9]], [[3, 5, 6, 7, 8, 9]], [[0, 3, 5, 4, 9, 8]], [[0, 1, 9, 3, 5]], [[0, 1, 2, 3, 4, 6]], [[0, 1, 3, 4]]]\n_outputs = [[1], [2], [4], [8], [16], [32], [64], [128], [256], [512], [1000], [825], [555], [95], [27]]\nimport math\nde...
304
321
coding
Solve the programming task below in a Python markdown code block. Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1. You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 slimes on...
{"inputs": ["1\n", "2\n", "3\n", "8\n", "4\n", "5\n", "6\n", "8\n"], "outputs": ["1\n", "2\n", "2 1\n", "4\n", "3\n", "3 1\n", "3 2\n", "4 \n"]}
485
77
coding
Solve the programming task below in a Python markdown code block. In "Takahashi-ya", a ramen restaurant, a bowl of ramen costs 700 yen (the currency of Japan), plus 100 yen for each kind of topping (boiled egg, sliced pork, green onions). A customer ordered a bowl of ramen and told which toppings to put on his ramen to...
{"inputs": ["pxo", "yxx", "opo", "oxp", "xyx", "opn", "xpo", "xzx"], "outputs": ["800\n", "700\n", "900\n", "800\n", "700\n", "800\n", "800\n", "700\n"]}
305
85
coding
Solve the programming task below in a Python markdown code block. You are given N integers A_{1}, A_{2}, \ldots, A_{N}. You can perform the following operation any number of times: Select any index i such that 1 ≤ i ≤ (N-1); Subtract 1 from A_{i} and 2 from A_{i+1}. Find the smallest possible value of |A_{1}| + |A_{...
{"inputs": ["4\n2\n2 4\n3\n1 1 1\n6\n-4 2 -4 2 -4 2\n1\n-100000000\n"], "outputs": ["0\n2\n15\n100000000\n"]}
684
71
coding
Solve the programming task below in a Python markdown code block. International Carpenters Professionals Company (ICPC) is a top construction company with a lot of expert carpenters. What makes ICPC a top company is their original language. The syntax of the language is simply given in CFG as follows: S -> SS | (S) ...
{"inputs": ["3\n0 ) 0\n7 * 0\n1 ( 0", "3\n0 ( 8\n10 ) 2\n0 ( 3", "3\n0 ( 8\n10 ) 4\n0 ( 3", "3\n0 ( 8\n10 ) 4\n0 ' 3", "3\n0 ( 3\n10 ) 4\n0 ' 3", "3\n-1 ) 0\n8 ( 19\n4 ' 2", "3\n-2 ) 0\n7 ) 0\n4 ( 11", "3\n0 ( 8\n10 ) 5\n10 ( 5"], "outputs": ["Yes\nYes\nYes\n", "No\nNo\nNo\n", "No\nNo\nNo\n", "No\nNo\nNo\n", "No\nNo\nN...
555
224
coding
Solve the programming task below in a Python markdown code block. The time is 2020. There is data that saves the qualifying results of PC Koshien 2020. This data stores the reference number and the number of correct answers assigned to each team. Here, the ranking is determined by the number of correct answers, and the...
{"inputs": ["1,20\n2,20\n3,30\n4,10\n5,10\n6,20\n0,0\n1\n2\n4\n1", "1,20\n2,20\n3,30\n4,10\n5,10\n0,26\n0,0\n1\n2\n4\n1", "1,20\n2,20\n3,30\n4,10\n5,10\n0,26\n0,0\n0\n2\n4\n1", "1,20\n2,20\n3,30\n4,10\n5,10\n0,26\n0,0\n1\n2\n4\n0", "1,20\n2,20\n3,30\n4,10\n5,10\n0,26\n0,0\n1\n3\n4\n0", "1,20\n2,20\n3,30\n4,10\n5,10\n0,...
537
430
coding
Solve the programming task below in a Python markdown code block. It's the academic year's end, fateful moment of your school report. The averages must be calculated. All the students come to you and entreat you to calculate their average for them. Easy ! You just need to write a script. Return the average of the give...
{"functional": "_inputs = [[[2, 2, 2, 2]], [[1, 5, 87, 45, 8, 8]], [[2, 5, 13, 20, 16, 16, 10]], [[1, 2, 15, 15, 17, 11, 12, 17, 17, 14, 13, 15, 6, 11, 8, 7]]]\n_outputs = [[2], [25], [11], [11]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclo...
107
280
coding
Solve the programming task below in a Python markdown code block. You are given an array A and an integer X. You are allowed to perform the following operation on the array: Select two distinct indices i and j and set both A_{i} and A_{j} as ((A_{i} \oplus A_{j}) \mid X) simultaneously. Here \oplus and \mid denote the ...
{"inputs": ["2\n3 6\n5 7 9\n5 4\n2 3 4 17 9\n"], "outputs": ["0\n2"]}
605
40
coding
Solve the programming task below in a Python markdown code block. We are given a sequence of coplanar points and see all the possible triangles that may be generated which all combinations of three points. We have the following list of points with the cartesian coordinates of each one: ``` Points [x, y] A [1, 2] ...
{"functional": "_inputs = [[[[1, 2], [3, 3], [4, 1], [1, 1], [4, -1]]], [[[1, 2], [4, -1], [3, 3], [4, -1], [4, 1], [1, 1], [4, -1], [4, -1], [3, 3], [1, 2]]]]\n_outputs = [[3], [3]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_...
362
249
coding
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin Chinese and Vietnamese as well. It is well-known that ∑sqrt(a_{i}), a_{i} ∈ N is a root of some integer-coefficient polynomial. For example: sqrt(2) is a root of polynomial: x^{2} − 2. Now, your task is to find not ...
{"inputs": ["2\n1\n2\n2\n2 3"], "outputs": ["2\n1000000005 0 1\n4\n1 0 999999997 0 1"]}
440
57
coding
Solve the programming task below in a Python markdown code block. For this problem you must create a program that says who ate the last cookie. If the input is a string then "Zach" ate the cookie. If the input is a float or an int then "Monica" ate the cookie. If the input is anything else "the dog" ate the cookie. The...
{"functional": "_inputs = [['Ryan'], [2.3], [26], [True], ['True'], [False], [1.98528462]]\n_outputs = [['Who ate the last cookie? It was Zach!'], ['Who ate the last cookie? It was Monica!'], ['Who ate the last cookie? It was Monica!'], ['Who ate the last cookie? It was the dog!'], ['Who ate the last cookie? It was Zac...
175
266
coding
Solve the programming task below in a Python markdown code block. Not so long ago, Vlad came up with an interesting function: $f_a(x)=\left\lfloor\frac{x}{a}\right\rfloor + x mod a$, where $\left\lfloor\frac{x}{a}\right\rfloor$ is $\frac{x}{a}$, rounded down, $x mod a$ — the remainder of the integer division of $x$ by...
{"inputs": ["1\n1 100 55\n", "1\n6 999998 9\n", "1\n87 95 696969\n", "3\n1 100 54\n1 100 55\n1 100 56\n", "5\n1 4 3\n5 8 4\n6 10 6\n1 1000000000 1000000000\n10 12 8\n"], "outputs": ["54\n", "111118\n", "95\n", "53\n54\n55\n", "2\n4\n5\n999999999\n5\n"]}
631
187
coding
Solve the programming task below in a Python markdown code block. Given is a positive integer N. We will choose an integer K between 2 and N (inclusive), then we will repeat the operation below until N becomes less than K. - Operation: if K divides N, replace N with N/K; otherwise, replace N with N-K. In how many choi...
{"inputs": ["9", "5", "2", "3", "4", "6", "6\n", "2\n"], "outputs": ["5\n", "3\n", "1\n", "2\n", "3\n", "3", "3\n", "1\n"]}
239
63
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a string s, find the longest palindromic subsequence's length in s. A subsequence is a sequence that can be derived from another sequence by deleting some or no elements without changing the order of the remaini...
{"functional": "def check(candidate):\n assert candidate(s = \"bbbab\") == 4\n assert candidate(s = \"cbbd\") == 2\n\n\ncheck(Solution().longestPalindromeSubseq)"}
96
49
coding
Solve the programming task below in a Python markdown code block. You're playing a game with a friend involving a bag of marbles. In the bag are ten marbles: * 1 smooth red marble * 4 bumpy red marbles * 2 bumpy yellow marbles * 1 smooth yellow marble * 1 bumpy green marble * 1 smooth green marble You can see that th...
{"functional": "_inputs = [['red', 'bumpy'], ['green', 'bumpy'], ['yellow', 'smooth'], ['red', 'smooth'], ['green', 'smooth'], ['yellow', 'bumpy']]\n_outputs = [['0.57'], ['0.14'], ['0.33'], ['0.33'], ['0.33'], ['0.28']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n...
401
223
coding
Solve the programming task below in a Python markdown code block. You have a collection of lovely poems. Unfortuantely they aren't formatted very well. They're all on one line, like this: ``` Beautiful is better than ugly. Explicit is better than implicit. Simple is better than complex. Complex is better than complica...
{"functional": "_inputs = [['Beautiful is better than ugly. Explicit is better than implicit. Simple is better than complex. Complex is better than complicated.'], [\"Flat is better than nested. Sparse is better than dense. Readability counts. Special cases aren't special enough to break the rules.\"], ['Although pract...
270
547
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given the head of a linked list. Delete the middle node, and return the head of the modified linked list. The middle node of a linked list of size n is the ⌊n / 2⌋th node from the start using 0-based indexing,...
{"functional": "def check(candidate):\n assert is_same_list(candidate(head = list_node([1,3,4,7,1,2,6])), list_node([1,3,4,1,2,6]))\n assert is_same_list(candidate(head = list_node([1,2,3,4])), list_node([1,2,4]))\n assert is_same_list(candidate(head = list_node([2,1])), list_node([2]))\n\n\ncheck(Solution().d...
205
113
coding
Solve the programming task below in a Python markdown code block. Consider the following pseudocode, run on an array $A=[a_0,a_1,...,a_{n-1}]$ of length $n$: rep := 0 while A not empty: B := [] for x in A, y in A: if x != y: append absolute_value(x - y) to B A := B rep := rep + 1 Given the val...
{"inputs": ["3\n1 3 4\n"], "outputs": ["4\n"]}
438
20
coding
Solve the programming task below in a Python markdown code block. Chef had a sequence of positive integers with length $N + K$. He managed to calculate the arithmetic average of all elements of this sequence (let's denote it by $V$), but then, his little brother deleted $K$ elements from it. All deleted elements had th...
{"inputs": ["3\n3 3 4\n2 7 3\n3 1 4\n7 6 5\n3 3 4\n2 8 3"], "outputs": ["4\n-1\n-1"]}
424
54
coding
Solve the programming task below in a Python markdown code block. Pay attention to the non-standard memory limit in this problem. In order to cut off efficient solutions from inefficient ones in this problem, the time limit is rather strict. Prefer to use compiled statically typed languages (e.g. C++). If you use Pyth...
{"inputs": ["7\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n", "7\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n", "7\n1\n1\n1\n1\n1\n0\n1\n1\n1\n1\n1\n1\n1\n1\n", "7\n1\n1\n1\n1\n1\n1\n1\n0\n1\n1\n1\n1\n1\n1\n", "7\n1\n1\n1\n1\n1\n1\n1\n0\n1\n1\n1\n1\n1\n0\n", "7\n1\n0\n1\n1\n1\n1\n1\n0\n1\n1\n1\n1\n1\n1\n", "5\n9\n3 1 4 1...
718
450
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. There are n people and 40 types of hats labeled from 1 to 40. Given a 2D integer array hats, where hats[i] is a list of all hats preferred by the ith person. Return the number of ways that the n people wear different ...
{"functional": "def check(candidate):\n assert candidate(hats = [[3,4],[4,5],[5]]) == 1\n assert candidate(hats = [[3,5,1],[3,5]]) == 4\n assert candidate(hats = [[1,2,3,4],[1,2,3,4],[1,2,3,4],[1,2,3,4]]) == 24\n assert candidate(hats = [[1,2,3],[2,3,5,6],[1,3,7,9],[1,8,9],[2,5,7]]) == 111\n\n\ncheck(Soluti...
130
153
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a 2D integer array intervals, where intervals[i] = [lefti, righti] describes the ith interval starting at lefti and ending at righti (inclusive). The size of an interval is defined as the number of integ...
{"functional": "def check(candidate):\n assert candidate(intervals = [[1,4],[2,4],[3,6],[4,4]], queries = [2,3,4,5]) == [3,3,1,4]\n assert candidate(intervals = [[2,3],[2,5],[1,8],[20,25]], queries = [2,19,5,22]) == [2,-1,4,6]\n\n\ncheck(Solution().minInterval)"}
179
113
coding
Solve the programming task below in a Python markdown code block. For a string S, let f(S) be the lexicographically smallest cyclic shift of S. For example, if S = `babca`, f(S) = `ababc` because this is the smallest among all cyclic shifts (`babca`, `abcab`, `bcaba`, `cabab`, `ababc`). You are given three integers X,...
{"inputs": ["2 1 0", "1 1 0", "0 2 0", "1 0 1", "2 0 0", "1 0 0", "2 2 1", "2 0 1"], "outputs": ["aab\n", "ab\n", "bb\n", "ac\n", "aa\n", "a\n", "abbac\n", "aac\n"]}
236
95
coding
Solve the programming task below in a Python markdown code block. *This is the advanced version of the [Minimum and Maximum Product of k Elements](https://www.codewars.com/kata/minimum-and-maximum-product-of-k-elements/) kata.* --- Given a list of **integers** and a positive integer `k` (> 0), find the minimum and m...
{"functional": "_inputs = [[[0, 1, 2, 3, 4], 2], [[0, -1, -2, -3, -4], 2], [[0, -1, -2, -3, -4], 3], [[-1, -2, -3, -4], 2], [[-1, -2, -3, -4], 3], [[], 2], [[-4, -10, -1], 2], [[0, 6, 3, 5, 4], 4], [[5, 4, 3, 3, 6], 2]]\n_outputs = [[[0, 12]], [[0, 12]], [[-24, 0]], [[2, 12]], [[-24, -6]], [None], [[4, 40]], [[0, 360]]...
322
353
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an encoded string, return its decoded string. The encoding rule is: k[encoded_string], where the encoded_string inside the square brackets is being repeated exactly k times. Note that k is guaranteed to be a pos...
{"functional": "def check(candidate):\n assert candidate(s = \"3[a]2[bc]\") == \"aaabcbc\"\n assert candidate(s = \"3[a2[c]]\") == \"accaccacc\"\n assert candidate(s = \"2[abc]3[cd]ef\") == \"abcabccdcdcdef\"\n assert candidate(s = \"abc3[cd]xyz\") == \"abccdcdcdxyz\"\n\n\ncheck(Solution().decodeString)"}
183
106
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. Consider the following function, where + denotes string concatenation. function BinaryConcatenation(integer X, integer Y): string binX = binary repr...
{"inputs": ["2\n2\n5 9\n7\n1 2 4 8 16 64 128"], "outputs": ["12\n127"]}
624
43
coding
Solve the programming task below in a Python markdown code block. E869120 has A 1-yen coins and infinitely many 500-yen coins. Determine if he can pay exactly N yen using only these coins. -----Constraints----- - N is an integer between 1 and 10000 (inclusive). - A is an integer between 0 and 1000 (inclusive). ---...
{"inputs": ["2763\n1", "37\n308", "2763\n2", "37\n135", "37\n244", "37\n290", "37\n381", "37\n605"], "outputs": ["No\n", "Yes\n", "No\n", "Yes\n", "Yes\n", "Yes\n", "Yes\n", "Yes\n"]}
201
102