problem
stringlengths
14
4.09k
solution
stringlengths
1
802k
task_type
stringclasses
3 values
problem_tokens
int64
5
895
Solve the programming task below in a Python markdown code block. You are an immigration officer in the Kingdom of AtCoder. The document carried by an immigrant has some number of integers written on it, and you need to check whether they meet certain criteria. According to the regulation, the immigrant should be allo...
{"inputs": ["3\n2 8 9", "3\n4 3 47", "3\n4 5 47", "3\n4 5 66", "3\n4 5 99", "3\n4 5 69", "3\n2 5 69", "3\n2 8 69"], "outputs": ["DENIED\n", "DENIED\n", "DENIED\n", "DENIED\n", "DENIED\n", "DENIED\n", "DENIED\n", "DENIED\n"]}
coding
253
Solve the programming task below in a Python markdown code block. Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for ...
{"inputs": ["1\n0\n", "1\n1\n", "2\n00\n", "2\n10\n", "2\n11\n", "2\n01\n", "3\n101\n", "3\n001\n"], "outputs": ["1\n", "1\n", "2\n", "2\n", "2\n", "2\n", "3\n", "3\n"]}
coding
506
Solve the programming task below in a Python markdown code block. You are given two strings $s$ and $t$ consisting of lowercase Latin letters. Also you have a string $z$ which is initially empty. You want string $z$ to be equal to string $t$. You can perform the following operation to achieve this: append any subsequen...
{"inputs": ["3\naabce\nace\nabacaba\naax\nty\nyyt\n", "3\naabce\nace\nabbcaaa\naax\nty\nyyt\n", "3\naabcf\nace\nabbcaaa\naax\nty\nyyt\n", "3\necbaa\nace\nabbcaaa\naax\nty\nyyt\n", "3\nbaacf\nace\nabbcaaa\naax\nty\nyyt\n", "3\naabce\nace\nabacaba\naax\nty\nyyt\n", "11\na\naaaaaaaaaaa\ncba\nabcabcabcabcabcabcabc\nbvdhsdv...
coding
430
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin Chinese . You are given two strings A and B of the same length. Each string contains N Lower case Latin character (from 'a' to 'z'). A shift operation will remove the first character of a string and add the same cha...
{"inputs": ["5\nccadd\nbddcc", "5\nccade\nbddcc", "5\nccade\nccdcb", "5\nddacc\nbddcc", "5\nddacc\nccddb", "5\nccade\nbcdcc", "5\ncacde\nccdcb", "5\nc`cde\nccdcb"], "outputs": ["3", "3\n", "0\n", "1\n", "2\n", "3\n", "0\n", "0\n"]}
coding
285
Solve the programming task below in a Python markdown code block. Given a [tree] containing N nodes. Each node can be coloured using exactly one of the C colours. Find the number of colourings of the tree such that: All nodes in a path of length at most two have distinct colours. As the answer can be huge, print it m...
{"inputs": ["3 3\n1 2\n1 3\n"], "outputs": ["6\n"]}
coding
466
Solve the programming task below in a Python markdown code block. In this Kata, you will be given a ```number```, two indexes (```index1``` and ```index2```) and a ```digit``` to look for. Your task will be to check if the ```digit``` exists in the ```number```, within the ```indexes``` given. Be careful, the ```index...
{"functional": "_inputs = [[1234567, 1, 0, 1], [1234567, 0, 1, 2], [67845123654, 4, 2, 4], [6668844536485, 0, 0, 6], [9999999999, 2, 5, 1]]\n_outputs = [[True], [True], [True], [True], [False]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose...
coding
432
Solve the programming task below in a Python markdown code block. Petya is the most responsible worker in the Research Institute. So he was asked to make a very important experiment: to melt the chocolate bar with a new laser device. The device consists of a rectangular field of n × m cells and a robotic arm. Each cell...
{"inputs": ["1\n3 3 3 2 1 1\n", "1\n4 5 2 2 4 2\n", "1\n2 5 1 5 2 2\n", "1\n5 6 3 4 4 2\n", "1\n3 5 2 4 3 5\n", "1\n2 6 2 6 2 3\n", "1\n2 2 1 2 2 1\n", "1\n7 3 6 2 5 2\n"], "outputs": ["5\n", "0\n", "6\n", "4\n", "2\n", "0\n", "2\n", "0\n"]}
coding
536
Solve the programming task below in a Python markdown code block. Chef and Chefina are competing against each other in a programming contest. They were both able to solve all the problems in the contest, so the winner between them must be decided by time penalty. Chef solved all the problems in X minutes and made P wro...
{"inputs": ["3\n10 8 2 3\n10 10 10 10\n40 21 2 0\n"], "outputs": ["Chef\nDraw\nChefina"]}
coding
721
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an array of integers arr, and three integers a, b and c. You need to find the number of good triplets. A triplet (arr[i], arr[j], arr[k]) is good if the following conditions are true: 0 <= i < j < k < arr.lengt...
{"functional": "def check(candidate):\n assert candidate(arr = [3,0,1,1,9,7], a = 7, b = 2, c = 3) == 4\n assert candidate(arr = [1,1,2,2,3], a = 0, b = 0, c = 1) == 0\n\n\ncheck(Solution().countGoodTriplets)"}
coding
179
Solve the programming task below in a Python markdown code block. Captain Fint is involved in another treasure hunt, but have found only one strange problem. The problem may be connected to the treasure's location or may not. That's why captain Flint decided to leave the solving the problem to his crew and offered an a...
{"inputs": ["2\n-1 100\n2 -1\n", "2\n-1 000\n2 -1\n", "2\n-1 101\n2 -1\n", "2\n-1 001\n2 -1\n", "2\n-2 101\n2 -1\n", "2\n-2 100\n2 -1\n", "2\n-2 000\n2 -1\n", "2\n-4 100\n2 -1\n"], "outputs": ["99\n2 1 \n", "-1\n2 1 ", "100\n2 1 ", "0\n2 1 ", "99\n2 1 ", "98\n2 1 ", "-2\n2 1 ", "96\n2 1 "]}
coding
641
Solve the programming task below in a Python markdown code block. A binary string is called a self-destructing string if it can reduced to an empty string by performing the following operation some number of times (possibly zero): Choose a valid integer $i$ such that the $i$-th character of the current string is differ...
{"inputs": ["3\n001101\n1101\n110"], "outputs": ["0\n1\n-1"]}
coding
564
Solve the programming task below in a Python markdown code block. There is a huge blanket on your bed but unfortunately it has N stains. You cover them using a single, rectangular silk cloth. The silk is expensive, which is why the rectangular piece needs to have the least area as possible. You love this blanket and d...
{"inputs": ["5 2\n0 1\n3 3\n2 0\n0 3\n2 3\n"], "outputs": ["8\n"]}
coding
450
Solve the programming task below in a Python markdown code block. Takahashi wants to print a document with N pages double-sided, where two pages of data can be printed on one sheet of paper. At least how many sheets of paper does he need? -----Constraints----- - N is an integer. - 1 \leq N \leq 100 -----Input----- ...
{"inputs": ["9", "3", "6", "1", "8", "5", "2", "5\n"], "outputs": ["5\n", "2\n", "3\n", "1\n", "4\n", "3", "1", "3\n"]}
coding
173
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an m x n matrix, return true if the matrix is Toeplitz. Otherwise, return false. A matrix is Toeplitz if every diagonal from top-left to bottom-right has the same elements.   Please complete the following python...
{"functional": "def check(candidate):\n assert candidate(matrix = [[1,2,3,4],[5,1,2,3],[9,5,1,2]]) == True\n assert candidate(matrix = [[1,2],[2,2]]) == False\n\n\ncheck(Solution().isToeplitzMatrix)"}
coding
96
Solve the programming task below in a Python markdown code block. Snuke has a string S consisting of three kinds of letters: `a`, `b` and `c`. He has a phobia for palindromes, and wants to permute the characters in S so that S will not contain a palindrome of length 2 or more as a substring. Determine whether this is ...
{"inputs": ["baa", "bba", "bab", "bbb", "abb", "abc", "cba", "bca"], "outputs": ["NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "YES\n", "YES\n", "YES\n"]}
coding
183
Solve the programming task below in a Python markdown code block. Berland National Library has recently been built in the capital of Berland. In addition, in the library you can take any of the collected works of Berland leaders, the library has a reading room. Today was the pilot launch of an automated reading room v...
{"inputs": ["1\n+ 1\n", "1\n- 1\n", "1\n- 1\n", "1\n+ 1\n", "1\n- 2\n", "1\n+ 2\n", "1\n- 4\n", "1\n- 8\n"], "outputs": ["1", "1", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n"]}
coding
633
Solve the programming task below in a Python markdown code block. You are given a multiset S. Over all pairs of subsets A and B, such that: * B ⊂ A; * |B| = |A| - 1; * greatest common divisor of all elements in A is equal to one; find the sum of ∑_{x ∈ A}{x} ⋅ ∑_{x ∈ B}{x}, modulo 998 244 353. Input The ...
{"inputs": ["1\n1 2\n", "1\n1 5\n", "1\n574 5\n", "1\n959 30\n", "1\n760 30\n", "1\n54560 5\n", "1\n11559 5\n", "1\n23041 5\n"], "outputs": ["4\n", "560\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]}
coding
391
Solve the programming task below in a Python markdown code block. Return an output string that translates an input string `s`/`$s` by replacing each character in `s`/`$s` with a number representing the number of times that character occurs in `s`/`$s` and separating each number with the character(s) `sep`/`$sep`. Also ...
{"functional": "_inputs = [['hello world', '-'], ['19999999', ':'], ['^^^**$', 'x']]\n_outputs = [['1-1-3-3-2-1-1-2-1-3-1'], ['1:7:7:7:7:7:7:7'], ['3x3x3x2x2x1']]\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...
coding
103
Solve the programming task below in a Python markdown code block. WW3 is near and Gru wants to recruit minions for his team. Gru went to the planet of minions to recruit minions, he saw that there are two villages separated by a river. He cannot recruit minions from both villages because then his team will have interna...
{"inputs": ["3\n1 0\n0 5 5\n0 6 5\n0 -8 20"], "outputs": ["20"]}
coding
360
Solve the programming task below in a Python markdown code block. Andryusha is an orderly boy and likes to keep things in their place. Today he faced a problem to put his socks in the wardrobe. He has n distinct pairs of socks which are initially in a bag. The pairs are numbered from 1 to n. Andryusha wants to put pai...
{"inputs": ["1\n1 1\n", "1\n1 1\n", "3\n2 1 1 3 2 3\n", "3\n2 1 1 3 2 3\n", "5\n5 1 3 2 4 3 1 2 4 5\n", "5\n5 1 3 2 4 3 1 2 4 5\n", "5\n5 2 3 1 4 3 1 2 4 5\n", "5\n5 2 3 1 4 3 2 2 4 5\n"], "outputs": ["1\n", "1\n", "2\n", "2\n", "5\n", "5\n", "5\n", "5\n"]}
coding
656
Solve the programming task below in a Python markdown code block. Jamie is a programmer, and James' girlfriend. She likes diamonds, and wants a diamond string from James. Since James doesn't know how to make this happen, he needs your help. ## Task You need to return a string that looks like a diamond shape when prin...
{"functional": "_inputs = [[3], [0], [2], [-1], [-2]]\n_outputs = [[' *\\n***\\n *\\n'], [None], [None], [None], [None]]\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 ...
coding
229
Solve the programming task below in a Python markdown code block. A sequence $(b_1, b_2, \ldots, b_k)$ is called strange, if the absolute difference between any pair of its elements is greater than or equal to the maximum element in the sequence. Formally speaking, it's strange if for every pair $(i, j)$ with $1 \le i<...
{"inputs": ["1\n1\n0\n", "1\n1\n0\n", "1\n1\n1\n", "1\n1\n2\n", "1\n2\n0 1\n", "1\n2\n0 1\n", "1\n3\n0 0 3\n", "1\n3\n0 0 4\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "2\n", "2\n", "2\n", "2\n"]}
coding
701
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an undirected tree consisting of n vertices numbered from 1 to n. A frog starts jumping from vertex 1. In one second, the frog jumps from its current vertex to another unvisited vertex if they are directly conne...
{"functional": "def check(candidate):\n assert candidate(n = 7, edges = [[1,2],[1,3],[1,7],[2,4],[2,6],[3,5]], t = 2, target = 4) == 0.16666666666666666 \n assert candidate(n = 7, edges = [[1,2],[1,3],[1,7],[2,4],[2,6],[3,5]], t = 1, target = 7) == 0.3333333333333333\n\n\ncheck(Solution().frogPosition)"}
coding
229
Solve the programming task below in a Python markdown code block. Soma is a fashionable girl. She absolutely loves shiny stones that she can put on as jewellery accessories. She has been collecting stones since her childhood - now she has become really good with identifying which ones are fake and which ones are not. ...
{"inputs": ["4\nabc\nabcdef\naA\nabAZ\naaa\na\nwhat\nnone", "4\nacb\nabcdef\naA\nabAZ\naaa\na\nwhat\nnone", "4\nacb\nabcdef\nAa\nabZA\naaa\n`\nwhat\nnone", "4\naca\nebcdaf\naA\nAbZa\n`aa\n`\nswha\nnomf", "4\nac`\nebcdae\naA\nAbZa\n`aa\n_\nsvha\nnome", "4\nac`\nebcdae\naA\nAbZ`\n`aa\n_\nsvha\nemon", "4\n`ca\neacdae\naA\...
coding
318
Solve the programming task below in a Python markdown code block. You are given a grid with n rows and m columns, where each cell has a non-negative integer written on it. We say the grid is good if for each cell the following condition holds: if it has a number k > 0 written on it, then exactly k of its neighboring ce...
{"inputs": ["5\n3 4\n0 0 0 0\n0 1 0 0\n0 0 0 0\n2 2\n3 0\n0 0\n2 2\n0 0\n0 0\n2 3\n0 0 0\n0 4 1\n4 4\n0 0 0 0\n0 2 0 1\n0 0 0 0\n0 0 0 0\n", "5\n3 4\n0 0 0 0\n0 1 0 0\n0 0 0 0\n2 2\n5 0\n0 0\n2 2\n0 0\n0 0\n2 3\n0 0 0\n0 4 1\n4 4\n0 0 0 0\n0 2 0 1\n0 0 0 0\n0 0 0 0\n", "5\n3 4\n0 0 0 0\n0 1 0 0\n0 0 0 0\n2 2\n3 0\n0 0\...
coding
758
Solve the programming task below in a Python markdown code block. Buses run between the cities A and B, the first one is at 05:00 AM and the last one departs not later than at 11:59 PM. A bus from the city A departs every a minutes and arrives to the city B in a t_{a} minutes, and a bus from the city B departs every b ...
{"inputs": ["1 1\n1 1\n10:28\n", "4 1\n5 4\n18:40\n", "8 8\n1 1\n13:24\n", "1 1\n1 1\n23:59\n", "3 1\n2 3\n05:03\n", "1 1\n3 2\n08:44\n", "1 3\n1 2\n21:43\n", "1 1\n3 2\n08:44\n"], "outputs": ["1\n", "1\n", "8\n", "1\n", "1\n", "0\n", "4\n", "0\n"]}
coding
555
Solve the programming task below in a Python markdown code block. Print the K-th element of the following sequence of length 32: 1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51 Constraints * 1 \leq K \leq 32 * All values in input are integers. Input Input is given...
{"inputs": ["8", "1", "5", "8", "1", "5", "6", "16"], "outputs": ["5\n", "1\n", "1\n", "5\n", "1\n", "1\n", "2", "14\n"]}
coding
191
Solve the programming task below in a Python markdown code block. Petya loves hockey very much. One day, as he was watching a hockey match, he fell asleep. Petya dreamt of being appointed to change a hockey team's name. Thus, Petya was given the original team name w and the collection of forbidden substrings s1, s2, .....
{"inputs": ["3\na\nA\na\nA\nb\n", "3\na\nA\na\nA\na\n", "3\nb\nA\na\nA\nb\n", "3\nb\nA\na\nB\nb\n", "3\nab\nBa\naB\nABBA\nl\n", "3\nab\nBa\naB\nABBA\na\n", "3\nab\nBa\naB\nABBB\nl\n", "3\nab\naB\naB\nABBA\na\n"], "outputs": ["B\n", "B\n", "B\n", "A\n", "LLLL\n", "BAAB\n", "LLBB\n", "BABA\n"]}
coding
693
Solve the programming task below in a Python markdown code block. You know that the Martians use a number system with base k. Digit b (0 ≤ b < k) is considered lucky, as the first contact between the Martians and the Earthlings occurred in year b (by Martian chronology). A digital root d(x) of number x is a number tha...
{"inputs": ["2 1 1\n0\n", "20 15 1\n6\n", "20 19 2\n16 13\n", "38 19 2\n16 13\n", "7 6 4\n3 5 0 8\n", "57 19 2\n16 13\n", "109 19 2\n16 3\n", "7 6 4\n3 5 0 4\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "1\n", "1\n"]}
coding
651
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin Chinese and Russian as well. Alice and Bob are playing the game. Initially, there is a single rooted tree. Players take turns alternately, Alice starts. In a single turn, Alice should choose any non-empty subset of...
{"inputs": ["3\n2\n1 2\n7\n1 3\n1 4\n4 2\n4 5\n4 6\n6 7\n1"], "outputs": ["2\n5\n1"]}
coding
407
Solve the programming task below in a Python markdown code block. We have two desks: A and B. Desk A has a vertical stack of N books on it, and Desk B similarly has M books on it. It takes us A_i minutes to read the i-th book from the top on Desk A (1 \leq i \leq N), and B_i minutes to read the i-th book from the top o...
{"inputs": ["0 3 000\n15 16 87\n83 94 18 4", "3 3 000\n57 16 125\n46 6 20 1", "0 3 000\n15 16 87\n83 94 18 14", "3 3 000\n60 16 4\n30 94 80 150", "3 3 000\n57 16 125\n46 9 20 14", "3 3 000\n57 16 125\n5 94 18 14", "-1 3 000\n26 9 87\n83 94 18 14", "3 3 100\n60 16 4\n30 94 80 150"], "outputs": ["0\n", "0\n", "0\n", "0\n...
coding
531
Solve the programming task below in a Python markdown code block. Sherlock considers a string to be valid if all characters of the string appear the same number of times. It is also valid if he can remove just $1$ character at $1$ index in the string, and the remaining characters will occur the same number of times. ...
{"inputs": ["aabbcd\n", "aabbccddeefghi\n", "abcdefghhgfedecba\n"], "outputs": ["NO\n", "NO\n", "YES\n"]}
coding
556
Solve the programming task below in a Python markdown code block. Catherine received an array of integers as a gift for March 8. Eventually she grew bored with it, and she started calculated various useless characteristics for it. She succeeded to do it for each one she came up with. But when she came up with another o...
{"inputs": ["2\n1 1\n", "2\n1 0\n", "2\n0 2\n", "2\n2 2\n", "2\n2 0\n", "2\n0 0\n", "2\n1 2\n", "3\n2 2 8\n"], "outputs": ["2\n", "1\n", "2\n", "4\n", "2\n", "0\n", "3\n", "4\n"]}
coding
548
Solve the programming task below in a Python markdown code block. Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. Сhef has assembled a football team! Now he needs to choose a name for his team. There are $N$ words in English that Chef considers *funny*. These wor...
{"inputs": ["3\n2\nsuf mas\n3\ngood game guys\n4\nhell bell best test"], "outputs": ["2\n0\n2"]}
coding
563
Solve the programming task below in a Python markdown code block. Constraints * 1 ≤ |V| ≤ 100 * 0 ≤ |E| ≤ 9900 * -2 × 107 ≤ di ≤ 2 × 107 * There are no parallel edges * There are no self-loops Input An edge-weighted graph G (V, E). |V| |E| s0 t0 d0 s1 t1 d1 : s|E|-1 t|E|-1 d|E|-1 |V| is the number of vertices an...
{"inputs": ["4 6\n0 1 1\n0 2 5\n1 2 3\n1 3 4\n2 3 1\n3 2 7", "4 6\n0 1 1\n0 2 5\n1 2 3\n0 3 4\n2 3 1\n3 2 7", "4 6\n0 1 1\n0 2 5\n1 2 3\n0 3 4\n2 3 1\n0 2 7", "4 6\n0 1 1\n0 2 5\n1 2 3\n0 2 4\n2 3 1\n0 2 7", "4 6\n0 1 1\n0 2 0\n1 2 2\n0 3 4\n2 3 1\n3 2 7", "4 6\n0 1 1\n0 2 5\n1 2 3\n0 3 3\n2 3 1\n3 2 7", "4 6\n0 1 1\n0...
coding
555
Solve the programming task below in a Python markdown code block. Valera has got n domino pieces in a row. Each piece consists of two halves — the upper one and the lower one. Each of the halves contains a number from 1 to 6. Valera loves even integers very much, so he wants the sum of the numbers on the upper halves a...
{"inputs": ["1\n2 3\n", "1\n2 4\n", "1\n1 1\n", "1\n1 2\n", "1\n2 2\n", "1\n1 1\n", "1\n1 2\n", "1\n2 2\n"], "outputs": ["-1\n", "0\n", "-1\n", "-1\n", "0\n", "-1\n", "-1\n", "0\n"]}
coding
454
Solve the programming task below in a Python markdown code block. In an infinite array with two rows, the numbers in the top row are denoted `. . . , A[−2], A[−1], A[0], A[1], A[2], . . .` and the numbers in the bottom row are denoted `. . . , B[−2], B[−1], B[0], B[1], B[2], . . .` For each integer `k`, the entry `...
{"functional": "_inputs = [[[1, 2, 3, 4], 2], [[38, 200, -18, 45], 1], [[1, 0, 0, 1], 5], [[0, 2, 0, 3], -2], [[-20, 1, -3, 14], -5], [[1, 2, 3, 5], 100], [[0, 4, 6, 13], 100]]\n_outputs = [[3], [200], [20], [-126], [-44402], [60560100487003612846322657690093088848428068520476594299], [335254562473098582210532865941148...
coding
362
Solve the programming task below in a Python markdown code block. In this Kata, you're to complete the function `sum_square_even_root_odd`. You will be given a list of numbers, `nums`, as the only argument to the function. Take each number in the list and *square* it if it is even, or *square root* the number if it is...
{"functional": "_inputs = [[[4, 5, 7, 8, 1, 2, 3, 0]], [[1, 14, 9, 8, 17, 21]]]\n_outputs = [[91.61], [272.71]]\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...
coding
141
Solve the programming task below in a Python markdown code block. Mrs Jefferson is a great teacher. One of her strategies that helped her to reach astonishing results in the learning process is to have some fun with her students. At school, she wants to make an arrangement of her class to play a certain game with her p...
{"functional": "_inputs = [[10], [14], [16], [22], [65]]\n_outputs = [[[4, 3, 2, 1]], [[5, 4, 3, 2]], [[-1]], [[7, 6, 5, 4]], [[33, 32]]]\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, (...
coding
364
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. Find the longest subsequence of nums that meets the following requirements: The subsequence is strictly increasing and The difference between adjacent elements in...
{"functional": "def check(candidate):\n assert candidate(nums = [4,2,1,4,3,4,5,8,15], k = 3) == 5\n assert candidate(nums = [7,4,5,1,8,12,4,7], k = 5) == 4\n assert candidate(nums = [1,5], k = 1) == 1\n\n\ncheck(Solution().lengthOfLIS)"}
coding
142
Solve the programming task below in a Python markdown code block. William has an array of $n$ integers $a_1, a_2, \dots, a_n$. In one move he can swap two neighboring items. Two items $a_i$ and $a_j$ are considered neighboring if the condition $|i - j| = 1$ is satisfied. William wants you to calculate the minimal numb...
{"inputs": ["1\n3\n1 1 1\n", "1\n3\n1 1 1\n", "1\n3\n1 1 0\n", "1\n3\n0 3 0\n", "1\n3\n1 2 0\n", "1\n3\n1 3 0\n", "1\n3\n0 3 1\n", "1\n3\n0 2 1\n"], "outputs": ["-1\n", "-1\n", "1\n", "0\n", "1\n", "1\n", "1\n", "1\n"]}
coding
631
Solve the programming task below in a Python markdown code block. Polycarp has prepared $n$ competitive programming problems. The topic of the $i$-th problem is $a_i$, and some problems' topics may coincide. Polycarp has to host several thematic contests. All problems in each contest should have the same topic, and al...
{"inputs": ["2\n1 1\n", "2\n1 1\n", "2\n2 1\n", "2\n4 1\n", "2\n5 1\n", "2\n5 0\n", "2\n1 0\n", "2\n5 -1\n"], "outputs": ["2\n", "2", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n"]}
coding
568
Please solve the programming task below using a self-contained code snippet in a markdown code block. A cell (r, c) of an excel sheet is represented as a string "<col><row>" where: <col> denotes the column number c of the cell. It is represented by alphabetical letters. For example, the 1st column is denoted by 'A...
{"functional": "def check(candidate):\n assert candidate(s = \"K1:L2\") == [\"K1\",\"K2\",\"L1\",\"L2\"]\n assert candidate(s = \"A1:F1\") == [\"A1\",\"B1\",\"C1\",\"D1\",\"E1\",\"F1\"]\n\n\ncheck(Solution().cellsInRange)"}
coding
287
Please solve the programming task below using a self-contained code snippet in a markdown code block. An image smoother is a filter of the size 3 x 3 that can be applied to each cell of an image by rounding down the average of the cell and the eight surrounding cells (i.e., the average of the nine cells in the blue sm...
{"functional": "def check(candidate):\n assert candidate(img = [[1,1,1],[1,0,1],[1,1,1]]) == [[0, 0, 0],[0, 0, 0], [0, 0, 0]]\n assert candidate(img = [[100,200,100],[200,50,200],[100,200,100]]) == [[137,141,137],[141,138,141],[137,141,137]]\n\n\ncheck(Solution().imageSmoother)"}
coding
171
Solve the programming task below in a Python markdown code block. It is known that fleas in Berland can jump only vertically and horizontally, and the length of the jump is always equal to s centimeters. A flea has found herself at the center of some cell of the checked board of the size n × m centimeters (each cell is...
{"inputs": ["1 2 3\n", "9 8 7\n", "4 5 6\n", "1 1 1\n", "1 1 2\n", "8 5 6\n", "1 8 7\n", "8 1 6\n"], "outputs": ["2", "8", "20", "1", "1", "20\n", "2\n", "4\n"]}
coding
266
Solve the programming task below in a Python markdown code block. Let's call the string beautiful if it does not contain a substring of length at least $2$, which is a palindrome. Recall that a palindrome is a string that reads the same way from the first character to the last and from the last character to the first. ...
{"inputs": ["1 1\na\n1 1\n", "1 1\na\n1 1\n", "5 4\nbaacb\n1 3\n1 5\n4 5\n2 3\n", "5 4\nbaacb\n1 3\n1 5\n4 5\n2 4\n", "5 4\nbaacb\n1 3\n2 5\n4 5\n2 4\n", "5 4\nbaacb\n1 3\n1 1\n4 5\n2 3\n", "5 4\nbaacb\n3 3\n1 3\n4 5\n2 3\n", "5 4\nbabcb\n2 3\n1 3\n3 5\n2 3\n"], "outputs": ["0\n", "0\n", "1\n2\n0\n1\n", "1\n2\n0\n1\n",...
coding
520
Solve the programming task below in a Python markdown code block. You've decided to carry out a survey in the theory of prime numbers. Let us remind you that a prime number is a positive integer that has exactly two distinct positive integer divisors. Consider positive integers a, a + 1, ..., b (a ≤ b). You want to fi...
{"inputs": ["2 4 2\n", "1 4 3\n", "5 8 2\n", "1 5 2\n", "6 8 3\n", "1 1 1\n", "1 2 1\n", "1 3 1\n"], "outputs": ["3\n", "-1\n", "4\n", "3\n", "-1\n", "-1\n", "2\n", "2\n"]}
coding
255
Solve the programming task below in a Python markdown code block. Read problems statements [Hindi] ,[Bengali] , [Mandarin chinese] , [Russian] and [Vietnamese] as well. The Euler totient function $\varphi(N)$ is defined as the number of integers between $1$ and $N$ (inclusive) which are coprime with $N$. You are give...
{"inputs": ["2\n6 2\n8 4"], "outputs": ["2\n2 1\n3 1\n1\n2 3"]}
coding
452
Solve the programming task below in a Python markdown code block. A pangram is a string that contains every letter of the alphabet. Given a sentence determine whether it is a pangram in the English alphabet. Ignore case. Return either pangram or not pangram as appropriate. Example $s=\text{'The quick brown fox ju...
{"inputs": ["We promptly judged antique ivory buckles for the prize", "We promptly judged antique ivory buckles for the next prize"], "outputs": ["not pangram", "pangram"]}
coding
299
Solve the programming task below in a Python markdown code block. After all the events in Orlando we all know, Sasha and Roma decided to find out who is still the team's biggest loser. Thankfully, Masha found somewhere a revolver with a rotating cylinder of n bullet slots able to contain exactly k bullets, now the boys...
{"inputs": ["3 0 3\n1\n2\n3\n", "3 1 3\n2\n2\n3\n", "3 1 3\n1\n2\n3\n", "4 0 4\n1\n2\n3\n4\n", "4 0 4\n1\n2\n3\n2\n", "4 0 4\n1\n2\n3\n3\n", "5 2 5\n2\n2\n3\n4\n5\n", "5 2 5\n1\n2\n3\n4\n5\n"], "outputs": ["...", "..X", "..X\n", "....\n", "....", "....", "...XX", "...XX\n"]}
coding
725
Solve the programming task below in a Python markdown code block. Walter White and Jesse Pinkman (a drug addict) both love to play with chemicals. One day they were playing with some chemicals to make an energy drink. Unknowingly they made a highly powerful drink. To test the drink on others also they called some of th...
{"inputs": ["1\n5\n1 2 3 4 5\n2 7 8 9 9\n"], "outputs": ["YES"]}
coding
724
Solve the programming task below in a Python markdown code block. # Back-Story Every day I travel on the freeway. When I am more bored than usual I sometimes like to play the following counting game I made up: * As I join the freeway my count is ```0``` * Add ```1``` for every car that I overtake * Subtract ```1``` ...
{"functional": "_inputs = [[50.0, 130.0, [[-1.0, 120.0], [-1.5, 120.0]]], [50.0, 110.0, [[1.0, 120.0], [1.5, 125.0]]], [50.0, 120.0, [[-1.0, 115.0], [-1.5, 110.0], [1.0, 130.0], [1.5, 130.0]]], [30.0, 100.0, [[-1.0, 110.0], [-0.7, 102.0], [-1.5, 108.0]]], [30.0, 130.0, [[1.0, 120.0], [0.7, 125.0], [1.5, 110.0]]], [50.0...
coding
323
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin Chinese , Russian and Vietnamese Chef likes to play table tennis. He found some statistics of matches which described who won the points in order. A game shall be won by the player first scoring 11 points except in...
{"inputs": ["2\n0101111111111\n11100000000000\n"], "outputs": ["WIN\nLOSE"]}
coding
395
Solve the programming task below in a Python markdown code block. Read problems statements [Mandarin] , [Bengali] , [Hindi] , [Russian] and [Vietnamese] as well. You are given a grid with $N$ rows and $M$ columns; each cell of this grid is either empty or contains an obstacle. Initially, all cells are colorless. You ...
{"inputs": ["2\n3 3\n..#\n...\n...\n3 3\n...\n.#.\n..."], "outputs": ["YES\nNO"]}
coding
429
Solve the programming task below in a Python markdown code block. In the previous challenge, you wrote code to perform an Insertion Sort on an unsorted array. But how would you prove that the code is correct? I.e. how do you show that for any input your code will provide the right output? Loop Invariant In computer ...
{"inputs": ["6\n7 4 3 5 6 2\n"], "outputs": ["2 3 4 5 6 7\n"]}
coding
653
Solve the programming task below in a Python markdown code block. There are N slimes standing on a number line. The i-th slime from the left is at position x_i. It is guaruanteed that 1 \leq x_1 < x_2 < \ldots < x_N \leq 10^{9}. Niwango will perform N-1 operations. The i-th operation consists of the following procedu...
{"inputs": ["3\n1 2 5", "3\n1 3 5", "3\n1 3 3", "3\n1 0 3", "3\n1 2 3", "3\n1 2 10", "3\n1 3 10", "3\n0 2 10"], "outputs": ["11\n", "10\n", "4\n", "7\n", "5", "26\n", "25\n", "28\n"]}
coding
442
Solve the programming task below in a Python markdown code block. We have N clocks. The hand of the i-th clock (1≤i≤N) rotates through 360° in exactly T_i seconds. Initially, the hand of every clock stands still, pointing directly upward. Now, Dolphin starts all the clocks simultaneously. In how many seconds will th...
{"inputs": ["2\n2\n5", "2\n3\n5", "2\n3\n3", "2\n3\n7", "2\n3\n9", "2\n3\n4", "2\n3\n6", "2\n0\n6"], "outputs": ["10\n", "15\n", "3\n", "21\n", "9\n", "12\n", "6\n", "0\n"]}
coding
272
Please solve the programming task below using a self-contained code snippet in a markdown code block. A string s can be partitioned into groups of size k using the following procedure: The first group consists of the first k characters of the string, the second group consists of the next k characters of the string, a...
{"functional": "def check(candidate):\n assert candidate(s = \"abcdefghi\", k = 3, fill = \"x\") == [\"abc\",\"def\",\"ghi\"]\n assert candidate(s = \"abcdefghij\", k = 3, fill = \"x\") == [\"abc\",\"def\",\"ghi\",\"jxx\"]\n\n\ncheck(Solution().divideString)"}
coding
215
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given two integers m and n representing a 0-indexed m x n grid. You are also given two 2D integer arrays guards and walls where guards[i] = [rowi, coli] and walls[j] = [rowj, colj] represent the positions of t...
{"functional": "def check(candidate):\n assert candidate(m = 4, n = 6, guards = [[0,0],[1,1],[2,3]], walls = [[0,1],[2,2],[1,4]]) == 7\n assert candidate(m = 3, n = 3, guards = [[1,1]], walls = [[0,1],[1,0],[2,1],[1,2]]) == 4\n\n\ncheck(Solution().countUnguarded)"}
coding
197
Solve the programming task below in a Python markdown code block. The solution of $ x ^ 3 = q $ is to calculate the recurrence formula $ x_ {n + 1} = x_n-\ frac {x_ {n} ^ 3 --q} {3x_ {n} ^ 2} $ It can be calculated approximately with. Put a positive number $ \ frac {q} {2} $ in $ x_1 $ $ x_2 = x_1-\ frac {x_ {1} ^ 3 ...
{"inputs": ["15\n8\n-1", "15\n3\n-1", "15\n1\n-1", "15\n5\n-1", "15\n9\n-1", "15\n2\n-1", "15\n6\n-1", "15\n4\n-1"], "outputs": ["2.466212\n2.000000\n", "2.466212\n1.442253\n", "2.466212\n1.000002\n", "2.466212\n1.709976\n", "2.466212\n2.080084\n", "2.466212\n1.259921\n", "2.466212\n1.817124\n", "2.466212\n1.587401\n"]...
coding
401
Solve the programming task below in a Python markdown code block. Igor found out discounts in a shop and decided to buy n items. Discounts at the store will last for a week and Igor knows about each item that its price now is a_{i}, and after a week of discounts its price will be b_{i}. Not all of sellers are honest, ...
{"inputs": ["1 0\n9\n8\n", "1 0\n9\n8\n", "2 0\n4 10\n1 2\n", "2 0\n4 10\n1 2\n", "2 1\n4 10\n1 2\n", "2 1\n4 10\n1 4\n", "2 0\n4 14\n1 2\n", "2 1\n3 10\n1 4\n"], "outputs": ["8\n", "8\n", "3\n", "3\n", "6\n", "8\n", "3\n", "7\n"]}
coding
522
Solve the programming task below in a Python markdown code block. Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. There are $N$ people on a street (numbered $1$ through $N$). For simplicity, we'll view them as points on a line. For each valid $i$, the position of...
{"inputs": ["3\n2\n3 6\n3\n1 3 5\n5\n1 2 5 6 7"], "outputs": ["1 1\n3 3\n2 3"]}
coding
632
Solve the programming task below in a Python markdown code block. Your classmates asked you to copy some paperwork for them. You know that there are 'n' classmates and the paperwork has 'm' pages. Your task is to calculate how many blank pages do you need. ### Example: ```python paperwork(5, 5) == 25 ``` **Note:** i...
{"functional": "_inputs = [[5, 5], [5, -5], [-5, -5], [-5, 5], [5, 0]]\n_outputs = [[25], [0], [0], [0], [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 l...
coding
128
Solve the programming task below in a Python markdown code block. Read problem statements in [Bengali], [Russian], [Mandarin] and [Vietnamese] as well. Chef has X coins worth 1 rupee each and Y coins worth 2 rupees each. He wants to distribute all of these X+Y coins to his two sons so that the total value of coins rec...
{"inputs": ["4\n2 2\n1 3\n4 0\n1 10\n"], "outputs": ["YES\nNO\nYES\nNO\n"]}
coding
376
Solve the programming task below in a Python markdown code block. ### Lyrics... Pyramids are amazing! Both in architectural and mathematical sense. If you have a computer, you can mess with pyramids even if you are not in Egypt at the time. For example, let's consider the following problem. Imagine that you have a pyr...
{"functional": "_inputs = [[[[3], [7, 4], [2, 4, 6], [8, 5, 9, 3]]], [[[75], [95, 64], [17, 47, 82], [18, 35, 87, 10], [20, 4, 82, 47, 65], [19, 1, 23, 75, 3, 34], [88, 2, 77, 73, 7, 63, 67], [99, 65, 4, 28, 6, 16, 70, 92], [41, 41, 26, 56, 83, 40, 80, 70, 33], [41, 48, 72, 33, 47, 32, 37, 16, 94, 29], [53, 71, 44, 65,...
coding
368
Solve the programming task below in a Python markdown code block. Well, here is another math class task. In mathematics, GCD is the greatest common divisor, and it's an easy task to calculate the GCD between two positive integers. A common divisor for two positive numbers is a number which both numbers are divisible b...
{"inputs": ["84 36\n1\n18 32\n", "48 4\n2\n8 100\n9 59\n", "48 4\n2\n8 100\n8 59\n", "48 72\n2\n8 29\n29 37\n", "48 72\n2\n8 29\n15 37\n", "48 72\n2\n8 58\n15 37\n", "48 72\n2\n8 98\n15 37\n", "48 72\n2\n8 192\n9 37\n"], "outputs": ["-1\n", "-1\n-1\n", "-1\n-1\n", "24\n-1\n", "24\n24\n", "24\n24\n", "24\n24\n", "24\n24...
coding
329
Solve the programming task below in a Python markdown code block. # Task In the Land Of Chess, bishops don't really like each other. In fact, when two bishops happen to stand on the same diagonal, they immediately rush towards the opposite ends of that same diagonal. Given the initial positions (in chess notation) o...
{"functional": "_inputs = [['d7', 'f5'], ['d8', 'b5'], ['a1', 'h8'], ['g3', 'e1'], ['b4', 'e7']]\n_outputs = [[['c8', 'h3']], [['b5', 'd8']], [['a1', 'h8']], [['e1', 'h4']], [['a3', 'f8']]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, ...
coding
368
Please solve the programming task below using a self-contained code snippet in a markdown code block. LeetCode wants to give one of its best employees the option to travel among n cities to collect algorithm problems. But all work and no play makes Jack a dull boy, you could take vacations in some particular cities an...
{"functional": "def check(candidate):\n assert candidate(flights = [[0,1,1],[1,0,1],[1,1,0]], days = [[1,3,1],[6,0,3],[3,3,3]]) == 12\n assert candidate(flights = [[0,0,0],[0,0,0],[0,0,0]], days = [[1,1,1],[7,7,7],[7,7,7]]) == 3\n assert candidate(flights = [[0,1,1],[1,0,1],[1,1,0]], days = [[7,0,0],[0,7,0],[0...
coding
466
Solve the programming task below in a Python markdown code block. Squirrel Liss is interested in sequences. She also has preferences of integers. She thinks n integers a1, a2, ..., an are good. Now she is interested in good sequences. A sequence x1, x2, ..., xk is called good if it satisfies the following three condit...
{"inputs": ["1\n1\n", "1\n4\n", "1\n2\n", "1\n8\n", "1\n3\n", "1\n7\n", "1\n9\n", "1\n6\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n"]}
coding
378
Solve the programming task below in a Python markdown code block. N Snukes called Snuke 1, Snuke 2, ..., Snuke N live in a town. There are K kinds of snacks sold in this town, called Snack 1, Snack 2, ..., Snack K. The following d_i Snukes have Snack i: Snuke A_{i, 1}, A_{i, 2}, \cdots, A_{i, {d_i}}. Takahashi will wal...
{"inputs": ["1 1\n1\n1\n", "3 1\n2\n1 3\n1\n3", "5 1\n2\n1 3\n1\n3", "9 0\n2\n4 0\n2\n0", "3 0\n2\n1 3\n1\n3", "5 1\n2\n1 4\n1\n3", "3 0\n1\n1 3\n1\n3", "5 1\n2\n1 4\n2\n3"], "outputs": ["0\n", "1\n", "3\n", "9\n", "3\n", "3\n", "3\n", "3\n"]}
coding
370
Solve the programming task below in a Python markdown code block. We saw the little game Marmot made for Mole's lunch. Now it's Marmot's dinner time and, as we all know, Marmot eats flowers. At every dinner he eats some red and white flowers. Therefore a dinner can be represented as a sequence of several flowers, some ...
{"inputs": ["1 1\n1 3\n", "1 1\n1 3\n", "1 1\n2 3\n", "1 2\n2 3\n", "1 1\n3 3\n", "1 2\n2 4\n", "1 2\n3 6\n", "1 1\n1 1\n"], "outputs": ["14\n", "14\n", "12\n", "5\n", "8\n", "10\n", "29\n", "2\n"]}
coding
446
Solve the programming task below in a Python markdown code block. You are given a ternary string (it is a string which consists only of characters '0', '1' and '2'). You can swap any two adjacent (consecutive) characters '0' and '1' (i.e. replace "01" with "10" or vice versa) or any two adjacent (consecutive) characte...
{"inputs": ["2\n", "1\n", "1\n", "2\n", "0\n", "20\n", "10\n", "12\n"], "outputs": ["2\n", "1\n", "1\n", "2\n", "0\n", "20\n", "01\n", "12\n"]}
coding
495
Solve the programming task below in a Python markdown code block. The government has invited bids from contractors to run canteens at all railway stations. Contractors will be allowed to bid for the catering contract at more than one station. However, to avoid monopolistic price-fixing, the government has declared that...
{"inputs": ["6\n10\n20\n25\n40\n30\n30\n4 5\n1 3\n3 4\n2 3\n6 4"], "outputs": ["90"]}
coding
517
Solve the programming task below in a Python markdown code block. During a recent research Berland scientists found out that there were n cities in Ancient Berland, joined by two-way paths. Any two cities are joined by no more than one path. No path joins a city with itself. According to a well-known tradition, the roa...
{"inputs": ["3\n", "1\n", "9\n", "6\n", "5\n", "7\n", "2\n", "8\n"], "outputs": ["2\n1 2\n1 3\n", "0\n", "20\n1 5\n1 6\n1 7\n1 8\n1 9\n2 5\n2 6\n2 7\n2 8\n2 9\n3 5\n3 6\n3 7\n3 8\n3 9\n4 5\n4 6\n4 7\n4 8\n4 9\n", "9\n1 4\n1 5\n1 6\n2 4\n2 5\n2 6\n3 4\n3 5\n3 6\n", "6\n1 3\n1 4\n1 5\n2 3\n2 4\n2 5\n", "12\n1 4\n1 5\n1 6...
coding
298
Solve the programming task below in a Python markdown code block. MoEngage noticed that some users are not aware of the practice page on CodeChef, and some others are not aware of the rated contests on CodeChef. So, MoEngage wants to send an email to the users depending on which of the following groups they fall into: ...
{"inputs": ["0 1", "1 0"], "outputs": ["https://www.codechef.com/practice", "https://www.codechef.com/contests"]}
coding
465
Solve the programming task below in a Python markdown code block. Read problems statements in mandarin chinese, russian and vietnamese as well. Chef wants to prepare a Cook-Off contest with 5 problems chosen from a set of N problems. He has marked the difficulty of each problem within a range identified by one of th...
{"inputs": ["3\n5\neasy\nmedium\nmedium-hard\nsimple\ncakewalk\n7\nsimple\nsimple\nmedium\nmedium\neasy-medium\ncakewalk\neasy\n7\ncakewalk\nsimple\neasy\neasy-medium\nmedium\nmedium-hard\nhard"], "outputs": ["Yes\nNo\nYes"]}
coding
576
Solve the programming task below in a Python markdown code block. Parsa has a humongous tree on $n$ vertices. On each vertex $v$ he has written two integers $l_v$ and $r_v$. To make Parsa's tree look even more majestic, Nima wants to assign a number $a_v$ ($l_v \le a_v \le r_v$) to each vertex $v$ such that the beaut...
{"inputs": ["3\n2\n1 7\n3 8\n1 2\n3\n1 3\n10 6\n7 9\n1 2\n2 3\n6\n3 1\n12 20\n6 19\n3 16\n5 17\n3 17\n3 3\n6 5\n1 5\n2 6\n4 6\n", "3\n2\n0 6\n3 8\n1 2\n3\n1 3\n4 6\n7 9\n1 2\n2 3\n6\n3 14\n12 21\n12 19\n3 12\n11 0\n3 0\n3 5\n6 5\n1 5\n2 6\n4 6\n", "3\n2\n1 6\n3 2\n1 2\n3\n1 3\n4 6\n7 9\n1 2\n2 3\n6\n3 14\n8 20\n12 19\n...
coding
619
Solve the programming task below in a Python markdown code block. Chef is asked to write a program that takes an array A of length N and two integers X, Y as input and modifies it as follows: Choose a random subset of elements of A (possibly empty) Increase all the elements of the chosen subset by X Increase the remai...
{"inputs": ["3\n3 2 5\n9 5 1\n11 10 3\n3 2 5\n9 5 1\n11 7 3\n3 2 5\n9 5 1\n11 7 7"], "outputs": ["Yes\nYes\nNo"]}
coding
619
Solve the programming task below in a Python markdown code block. There are n people taking dancing lessons. Every person is characterized by his/her dancing skill ai. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the following proces...
{"inputs": ["1\nD\n85367\n", "1\nE\n85367\n", "1\nF\n85367\n", "1\nG\n85367\n", "1\nF\n59056\n", "1\nF\n80903\n", "1\nF\n42037\n", "1\nF\n18127\n"], "outputs": ["0\n\n", "0\n\n", "0\n\n", "0\n\n", "0\n\n", "0\n\n", "0\n\n", "0\n\n"]}
coding
420
Solve the programming task below in a Python markdown code block. A few years ago Sajjad left his school and register to another one due to security reasons. Now he wishes to find Amir, one of his schoolmates and good friends. There are n schools numerated from 1 to n. One can travel between each pair of them, to do s...
{"inputs": ["2\n", "1\n", "2\n", "3\n", "4\n", "1\n", "3\n", "1\n"], "outputs": ["0\n", "0\n", "0\n", "1\n", "1\n", "0\n", "1\n", "0\n"]}
coding
246
Solve the programming task below in a Python markdown code block. In AtCoder, a person who has participated in a contest receives a color, which corresponds to the person's rating as follows: - Rating 1-399 : gray - Rating 400-799 : brown - Rating 800-1199 : green - Rating 1200-1599 : cyan - Rating 1600-1999 : b...
{"inputs": ["4\n2100 3230 248 21", "4\n2100 3230 248 26", "4\n2100 3992 248 26", "4\n2100 4691 248 409", "4\n2100 3230 248 409", "4\n2100 2500 248 2612", "4\n2100 2500 248 2218", "4\n2100 4691 248 2218"], "outputs": ["2 3\n", "2 3\n", "2 3\n", "3 4\n", "3 4\n", "3 3\n", "3 3\n", "2 3\n"]}
coding
383
Solve the programming task below in a Python markdown code block. Find the longest substring within a string that contains at most 2 unique characters. ``` substring("a") => "a" substring("aaa") => "aaa" substring("abacd") => "aba" substring("abacddcd") => "cddcd" substring("cefageaacceaccacca") => "accacca" ``` This...
{"functional": "_inputs = [[''], ['a'], ['aa'], ['aaa'], ['ab'], ['aba'], ['abc'], ['abcba'], ['bbacc'], ['ccddeeff'], ['bbacddddcdd'], ['abcddeejabbedsajaajjaajjajajajjajjaaacedajajaj'], ['aaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbccccccccccccccccccccddddddddddddddddddddeeeeeeeeeeeeeeeeeeeeffffffffffffffffffffgggggggggg...
coding
228
Solve the programming task below in a Python markdown code block. Tanya wants to go on a journey across the cities of Berland. There are $n$ cities situated along the main railroad line of Berland, and these cities are numbered from $1$ to $n$. Tanya plans her journey as follows. First of all, she will choose some cit...
{"inputs": ["2\n2 1\n", "2\n1 1\n", "2\n1 2\n", "2\n1 2\n", "2\n2 2\n", "2\n1 2\n", "2\n2 1\n", "2\n1 1\n"], "outputs": ["2\n", "1\n", "3\n", "3\n", "2\n", "3\n", "2\n", "1\n"]}
coding
701
Solve the programming task below in a Python markdown code block. You are playing a very popular game called Cubecraft. Initially, you have one stick and want to craft $k$ torches. One torch can be crafted using one stick and one coal. Hopefully, you've met a very handsome wandering trader who has two trade offers: e...
{"inputs": ["5\n2 2 5\n76 3 24\n7 15 9\n1000000000 1001000000 1000100001\n2 1000000001 1000000000\n", "5\n2 2 5\n76 19 24\n7 15 9\n1000000000 1001000000 1000000000\n2 1000000000 1000000000\n", "5\n2 2 5\n76 19 24\n7 15 9\n1000000000 1001000000 1000100000\n2 1000000000 1000000000\n", "5\n2 2 5\n76 19 24\n7 15 9\n1000000...
coding
492
Solve the programming task below in a Python markdown code block. A list of names is taken as input, in which a particular name can occur multiple times. You need to arrange these names as they will appear in the dictionary and also print the number of times the arranged names appear in the list taken as input. Input:...
{"inputs": ["3\nritesh\nsahil\nritesh"], "outputs": ["ritesh 2\nsahil 1"]}
coding
252
Solve the programming task below in a Python markdown code block. # Summary: Given a number, `num`, return the shortest amount of `steps` it would take from 1, to land exactly on that number. # Description: A `step` is defined as either: - Adding 1 to the number: `num += 1` - Doubling the number: `num *= 2` You will ...
{"functional": "_inputs = [[2], [3], [4], [5], [6], [7], [8], [9], [10], [20], [30], [40], [50], [11], [24], [37], [19], [48], [59], [65], [73], [83], [64], [99], [100], [10000], [1500], [1534], [1978], [2763], [9999], [2673], [4578], [9876], [2659], [7777], [9364], [7280], [4998], [9283], [8234], [7622], [800], [782],...
coding
345
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 ...
coding
688
Solve the programming task below in a Python markdown code block. Lee was cleaning his house for the party when he found a messy string under the carpets. Now he'd like to make it clean accurately and in a stylish way... The string $s$ he found is a binary string of length $n$ (i. e. string consists only of 0-s and 1-...
{"inputs": ["5\n10\n0001111111\n4\n0101\n8\n11001101\n10\n1110000000\n1\n1\n", "5\n10\n0001111111\n4\n0101\n8\n11001101\n10\n1010000000\n1\n1\n", "5\n10\n0011111111\n4\n0101\n8\n11001101\n10\n1010000000\n1\n1\n", "5\n10\n0001111110\n4\n0101\n8\n11001101\n10\n1110000000\n1\n1\n", "5\n10\n0001111110\n4\n0101\n8\n11001101...
coding
728
Solve the programming task below in a Python markdown code block. Let N be a positive integer. You are given a string s of length N - 1, consisting of `<` and `>`. Find the number of permutations (p_1, p_2, \ldots, p_N) of (1, 2, \ldots, N) that satisfy the following condition, modulo 10^9 + 7: * For each i (1 \leq i...
{"inputs": ["4\n<<>", "4\n<><", "5\n<<><", "5\n><<<", "5\n<<<<", "20\n>><<>>><>><>>><>>>>", "20\n>><<>>><>>>>>><>>><", "20\n>>>><>>>>><<>>><<>>"], "outputs": ["3\n", "5", "9\n", "4\n", "1", "217136290\n", "415929071\n", "784400335\n"]}
coding
285
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given two strings s1 and s2, both of length 4, consisting of lowercase English letters. You can apply the following operation on any of the two strings any number of times: Choose any two indices i and j such...
{"functional": "def check(candidate):\n assert candidate(s1 = \"abcd\", s2 = \"cdab\") == True\n assert candidate(s1 = \"abcd\", s2 = \"dacb\") == False\n\n\ncheck(Solution().canBeEqual)"}
coding
141
Solve the programming task below in a Python markdown code block. Problem GPA is an abbreviation for "Galaxy Point of Aizu" and takes real numbers from 0 to 4. GPA rock-paper-scissors is a game played by two people. After each player gives a signal of "rock-paper-scissors, pon (hoi)" to each other's favorite move, goo...
{"inputs": ["3\n1.000\n2.000\n3.000", "3\n1.000\n3.000\n3.000", "3\n1.000\n2.000\n3.4274102096399073", "3\n1.3153899733914476\n3.000\n3.000", "3\n1.000\n3.000\n3.1230319554116766", "3\n1.000\n2.000\n3.9759367558439593", "3\n1.000\n2.5451927881659007\n3.000", "3\n1.6470390157297516\n3.000\n3.000"], "outputs": ["0\n3\n6"...
coding
403
Solve the programming task below in a Python markdown code block. You are given an integer N. Find if it is possible to represent N as the sum of several(possibly zero) 2's and several(possibly zero) 7's. Formally, find if there exist two integers X, Y \ (X, Y ≥ 0) such that 2 \cdot X + 7\cdot Y = N. ------ Input Fo...
{"inputs": ["4\n2\n5\n7\n11\n"], "outputs": ["YES\nNO\nYES\nYES\n"]}
coding
377
Solve the programming task below in a Python markdown code block. Chef has an array A consisting of N integers (1-based indexing). He asks you to perform the following operation M times: for i = 2 to N: Ai = Ai + Ai-1 Your task is to find the xth element of the array (i.e., Ax) after performing the above operation...
{"inputs": ["2\n3 2 3\n1 2 3\n3 3 3\n1 2 3"], "outputs": ["5\n15"]}
coding
478
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin chinese, Russian and Vietnamese as well. Katya has a sequence of integers $a_{1}, a_{2}, \dots, a_{n}$ and an integer $m$. She defines a *good* sequence of integers as a non-empty sequence such that the sum of the ...
{"inputs": ["2\n2 3\n1 2\n2 3\n1 3"], "outputs": ["0\n1"]}
coding
393
Solve the programming task below in a Python markdown code block. You are given 3 numbers A, B, and C. Determine whether the average of A and B is strictly greater than C or not? NOTE: Average of A and B is defined as \frac{(A+B)}{2}. For example, average of 5 and 9 is 7, average of 5 and 8 is 6.5. ------ Input Form...
{"inputs": ["5\n5 9 6\n5 8 6\n5 7 6\n4 9 8\n3 7 2\n"], "outputs": ["YES\nYES\nNO\nNO\nYES\n"]}
coding
432
Solve the programming task below in a Python markdown code block. problem You are in charge of quality control at a machine manufacturing plant. This machine requires a power supply, a motor, and a cable as parts. The manufacturing plant has a power supply, b motors, and c cables, numbered from 1 to a, a + 1 to a + b,...
{"inputs": ["2 2 2\n4\n2 4 5 0\n2 3 6 0\n1 4 5 0\n2 3 2 1\n0 0 0", "2 2 2\n4\n2 4 5 0\n2 3 6 0\n1 4 5 0\n2 3 2 0\n0 0 0", "3 2 2\n4\n2 4 5 0\n2 3 6 0\n1 4 5 0\n2 3 5 1\n0 0 0", "2 2 2\n4\n3 4 5 0\n2 3 6 0\n1 4 4 1\n2 3 2 0\n0 0 0", "2 2 2\n4\n2 4 5 0\n1 3 6 0\n1 4 5 0\n2 3 2 1\n0 0 0", "3 2 2\n4\n2 4 5 0\n2 4 6 0\n1 4 ...
coding
692
Solve the programming task below in a Python markdown code block. You are given an integer sequence A of length N. Find the maximum absolute difference of two elements (with different indices) in A. -----Constraints----- - 2 \leq N \leq 100 - 1 \leq A_i \leq 10^9 - All values in input are integers. -----Input-----...
{"inputs": ["4\n1 4 6 3\n", "5\n1 1 1 1 1\n", "2\n1000000000 1\n", "2\n877914575 602436426\n", "2\n861648772 861648772\n", "16\n433933447 476190629 262703497 211047202 971407775 628894325 731963982 822804784 450968417 430302156 982631932 161735902 880895728 923078537 707723857 189330739\n", "63\n992120464 989248231 989...
coding
169
Solve the programming task below in a Python markdown code block. Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well You are given a binary string $S$ with length $N$ and an integer $K$, which is a divisor of $N$. A string is said to be $K$*-foldable* if it can be c...
{"inputs": ["2\n8 2\n00011101\n6 2\n100111"], "outputs": ["01100110\nIMPOSSIBLE"]}
coding
662
Solve the programming task below in a Python markdown code block. *** Nova polynomial subtract*** This kata is from a series on polynomial handling. ( [#1](http://www.codewars.com/kata/nova-polynomial-1-add-1) [#2](http://www.codewars.com/kata/570eb07e127ad107270005fe) [#3](http://www.codewars.com/kata/5714041e880...
{"functional": "_inputs = [[[], []], [[1, 2, 3, 4, 5, 6], []], [[], [1, 2, 3, 4, 5, 6]]]\n_outputs = [[[]], [[1, 2, 3, 4, 5, 6]], [[-1, -2, -3, -4, -5, -6]]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n ...
coding
404
Solve the programming task below in a Python markdown code block. Lots of geeky customers visit our chef's restaurant everyday. So, when asked to fill the feedback form, these customers represent the feedback using a binary string (i.e a string that contains only characters '0' and '1'. Now since chef is not that gre...
{"inputs": ["2\n11111110\n10101010101010", "2\n11101110\n10101010101010", "2\n11111110\n10101010111010", "2\n01010010\n10000000111111", "2\n11111111\n11000001111100", "2\n11101110\n10101010111010", "2\n11111110\n10100010111010", "2\n01111110\n10100010111010"], "outputs": ["Bad\nGood", "Good\nGood\n", "Bad\nGood\n", "Go...
coding
363