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. The princess is going to escape the dragon's cave, and she needs to plan it carefully. The princess runs at vp miles per hour, and the dragon flies at vd miles per hour. The dragon will discover the escape after t hours and will chase the princess immed...
{"inputs": ["1\n2\n1\n1\n6\n", "1\n2\n2\n1\n8\n", "1\n2\n1\n1\n8\n", "2\n1\n1\n1\n10\n", "2\n2\n1\n1\n10\n", "1\n2\n1\n1\n10\n", "83\n7\n7\n7\n46\n", "5\n3\n3\n3\n999\n"], "outputs": ["1\n", "1\n", "1\n", "0\n", "0\n", "2\n", "0\n", "0\n"]}
coding
532
Solve the programming task below in a Python markdown code block. Vasiliy is fond of solving different tasks. Today he found one he wasn't able to solve himself, so he asks you to help. Vasiliy is given n strings consisting of lowercase English letters. He wants them to be sorted in lexicographical order (as in the di...
{"inputs": ["2\n1 2\nba\nac\n", "2\n1 1\naa\naa\n", "2\n1 1\naa\naa\n", "2\n1 1\naa\na`\n", "2\n1 2\nab\nac\n", "2\n2 1\naa\na`\n", "2\n1 2\n`b\nac\n", "2\n2 1\naa\n`a\n"], "outputs": ["1\n", "0\n", "0", "-1\n", "0\n", "-1\n", "0\n", "-1\n"]}
coding
585
Solve the programming task below in a Python markdown code block. Dima loves Inna very much. He decided to write a song for her. Dima has a magic guitar with n strings and m frets. Dima makes the guitar produce sounds like that: to play a note, he needs to hold one of the strings on one of the frets and then pull the s...
{"inputs": ["1 10 9 5\n1 2 3 4 5 6 7 8 9 1\n1 1 9 2 3\n", "10 1 9 5\n1\n2\n3\n4\n5\n6\n7\n8\n9\n1\n1 1 9 2 3\n", "10 1 9 5\n1\n2\n3\n4\n5\n6\n7\n8\n9\n1\n1 1 9 2 3\n", "1 10 9 5\n1 2 3 4 5 6 7 8 9 1\n1 1 9 2 3\n", "1 10 9 5\n1 2 3 3 5 6 7 8 9 1\n1 1 9 2 3\n", "1 10 9 5\n1 2 3 3 5 6 7 6 9 1\n1 1 9 2 3\n", "10 1 9 5\n1\n...
coding
694
Solve the programming task below in a Python markdown code block. A cricket match is going to be held. The field is represented by a 1D plane. A cricketer, Mr. X has $N$ favorite shots. Each shot has a particular range. The range of the $i^{\mbox{th}}$ shot is from $\mbox{A}_{i}$ to $\mbox{B}_{i}$. That means his favo...
{"inputs": ["4 4 \n1 2 \n2 3\n4 5\n6 7\n1 5\n2 3\n4 7\n5 7 \n"], "outputs": ["9\n"]}
coding
610
Solve the programming task below in a Python markdown code block. Vasya has n items lying in a line. The items are consecutively numbered by numbers from 1 to n in such a way that the leftmost item has number 1, the rightmost item has number n. Each item has a weight, the i-th item weights w_{i} kilograms. Vasya needs...
{"inputs": ["2 3 4 5 6\n1 2\n", "2 3 4 5 6\n1 2\n", "2 6 4 5 6\n1 2\n", "4 7 2 3 9\n1 2 3 4\n", "4 7 2 3 9\n0 2 3 4\n", "4 7 2 3 9\n0 2 6 4\n", "4 7 4 3 9\n1 2 3 4\n", "4 7 2 3 9\n1 2 3 4\n"], "outputs": ["11\n", "11\n", "14\n", "34\n", "27\n", "33\n", "49\n", "34\n"]}
coding
608
Solve the programming task below in a Python markdown code block. You are given a positive integer $n$. Your task is to find any three integers $a$, $b$ and $c$ ($0 \le a, b, c \le 10^9$) for which $(a\oplus b)+(b\oplus c)+(a\oplus c)=n$, or determine that there are no such integers. Here $a \oplus b$ denotes the bitw...
{"inputs": ["5\n4\n1\n12\n2046\n194723326\n"], "outputs": ["0 2 2\n-1\n0 6 6\n0 1023 1023\n0 97361663 97361663\n"]}
coding
484
Solve the programming task below in a Python markdown code block. # Task In the field, two beggars A and B found some gold at the same time. They all wanted the gold, and they decided to use simple rules to distribute gold: ``` They divided gold into n piles and be in line. The amount of each pile and the order of pi...
{"functional": "_inputs = [[[4, 7, 2, 9, 5, 2]], [[10, 1000, 2, 1]]]\n_outputs = [[[11, 18]], [[12, 1001]]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len...
coding
546
Solve the programming task below in a Python markdown code block. JJ has an array A of size N. He can perform the following operations on the array at most K times: Set A_{i} := A_{i + 1} where 1 ≤ i ≤ N - 1 Set A_{i} := A_{i - 1} where 2 ≤ i ≤ N He wants to maximize the value of the minimum element of the array A. F...
{"inputs": ["4\n5 4\n5 4 3 2 1\n6 1\n8 2 3 9 6 10\n5 2\n4 3 4 3 5\n5 1000\n4 3 4 3 5\n"], "outputs": ["5\n3\n4\n5\n"]}
coding
746
Solve the programming task below in a Python markdown code block. Gennady owns a small hotel in the countryside where he lives a peaceful life. He loves to take long walks, watch sunsets and play cards with tourists staying in his hotel. His favorite game is called "Mau-Mau". To play Mau-Mau, you need a pack of $52$ c...
{"inputs": ["AS\n2H 4C TH JH AD\n", "2H\n3D 4C AC KD AS\n", "4D\nAS AC AD AH 5H\n", "3D\n8S 4S 2C AS 6H\n", "7H\nTC 4C KC AD 9S\n", "KH\n3C QD 9S KS 8D\n", "4H\nJH QC 5H 9H KD\n", "9H\nKC 6D KD 4C 2S\n"], "outputs": ["YES\n", "NO\n", "YES\n", "NO\n", "NO\n", "YES\n", "YES\n", "NO\n"]}
coding
578
Solve the programming task below in a Python markdown code block. Coming up with a new problem isn't as easy as many people think. Sometimes it is hard enough to name it. We'll consider a title original if it doesn't occur as a substring in any titles of recent Codeforces problems. You've got the titles of n last pro...
{"inputs": ["1\na\n", "1\nb\n", "1\nz\n", "1\nz\n", "1\na\n", "1\nb\n", "1\ny\n", "2\nhk\nobsp\n"], "outputs": ["b\n", "a\n", "a\n", "a\n", "b\n", "a\n", "a\n", "a\n"]}
coding
551
Solve the programming task below in a Python markdown code block. There are three houses on a number line: House 1, 2 and 3, with coordinates A, B and C, respectively. Print `Yes` if we pass the coordinate of House 3 on the straight way from House 1 to House 2 without making a detour, and print `No` otherwise. Constra...
{"inputs": ["8 2 4", "3 3 1", "3 8 7", "1 2 4", "4 3 1", "6 8 7", "1 0 4", "4 2 1"], "outputs": ["Yes\n", "No\n", "Yes\n", "No\n", "No\n", "Yes\n", "No\n", "No\n"]}
coding
219
Solve the programming task below in a Python markdown code block. Chef has a square-shaped chart paper with the side length equal to N. He wants to cut out K \times K squares from this chart paper. Find the maximum number of K \times K squares he can cut from the entire chart paper. Note that, some part of the chart...
{"inputs": ["3\n5 1\n2 2\n5 2\n"], "outputs": ["25\n1\n4\n"]}
coding
359
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"]}
coding
485
Solve the programming task below in a Python markdown code block. We have an array of unique elements. A special kind of permutation is the one that has all of its elements in a different position than the original. Let's see how many of these permutations may be generated from an array of four elements. We put the or...
{"functional": "_inputs = [[1], [4], [30]]\n_outputs = [[0], [9], [97581073836835777732377428235481]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) !=...
coding
314
Please solve the programming task below using a self-contained code snippet in a markdown code block. This question is about implementing a basic elimination algorithm for Candy Crush. Given an m x n integer array board representing the grid of candy where board[i][j] represents the type of candy. A value of board[i][...
{"functional": "def check(candidate):\n assert candidate(board = [[110,5,112,113,114],[210,211,5,213,214],[310,311,3,313,314],[410,411,412,5,414],[5,1,512,3,3],[610,4,1,613,614],[710,1,2,713,714],[810,1,2,1,1],[1,1,2,2,2],[4,1,4,4,1014]]) == [[0,0,0,0,0],[0,0,0,0,0],[0,0,0,0,0],[110,0,0,0,114],[210,0,0,0,214],[310,0...
coding
290
Solve the programming task below in a Python markdown code block. There are N children and Chef wants to give them 1 candy each. Chef already has X candies with him. To buy the rest, he visits a candy shop. In the shop, packets containing exactly 4 candies are available. Determine the minimum number of candy packets C...
{"inputs": ["4\n20 12\n10 100\n10 9\n20 9\n"], "outputs": ["2\n0\n1\n3\n"]}
coding
432
Solve the programming task below in a Python markdown code block. Complete the function/method so that it takes CamelCase string and returns the string in snake_case notation. Lowercase characters can be numbers. If method gets number, it should return string. Examples: ``` javascript // returns test_controller toUn...
{"functional": "_inputs = [['TestController'], ['ThisIsBeautifulDay'], ['Am7Days'], ['My3CodeIs4TimesBetter'], [5]]\n_outputs = [['test_controller'], ['this_is_beautiful_day'], ['am7_days'], ['my3_code_is4_times_better'], ['5']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, f...
coding
198
Solve the programming task below in a Python markdown code block. Chef gives an integer $K$ in the input. If the given number is beautiful binary number, print it, Else find its previous beautiful binary number. A beautiful binary number is a number whose binary representation does not contain any consecutive 1s. Note...
{"inputs": ["3\n3\n6\n8"], "outputs": ["2\n5\n8"]}
coding
272
Solve the programming task below in a Python markdown code block. Given an array $a$ of length $n$, tell us whether it has a non-empty subsequence such that the product of its elements is not a perfect square. A sequence $b$ is a subsequence of an array $a$ if $b$ can be obtained from $a$ by deleting some (possibly ze...
{"inputs": ["1\n1\n3\n", "1\n1\n5\n", "1\n1\n6\n", "1\n1\n7\n", "1\n1\n2\n", "1\n1\n8\n", "1\n1\n2\n", "1\n1\n8\n"], "outputs": ["YES\n", "YES\n", "YES\n", "YES\n", "YES\n", "YES\n", "YES\n", "YES\n"]}
coding
318
Solve the programming task below in a Python markdown code block. You are given the firstname and lastname of a person on two different lines. Your task is to read them and print the following: Hello firstname lastname! You just delved into python. Function Description Complete the print_full_name function in th...
{"inputs": ["Ross\nTaylor\n"], "outputs": ["Hello Ross Taylor! You just delved into python.\n"]}
coding
223
Solve the programming task below in a Python markdown code block. Consider the following numbers (where `n!` is `factorial(n)`): ``` u1 = (1 / 1!) * (1!) u2 = (1 / 2!) * (1! + 2!) u3 = (1 / 3!) * (1! + 2! + 3!) ... un = (1 / n!) * (1! + 2! + 3! + ... + n!) ``` Which will win: `1 / n!` or `(1! + 2! + 3! + ... + n!)`? ...
{"functional": "_inputs = [[5], [6], [7], [8], [20], [30], [50], [113], [200], [523], [1011], [10110]]\n_outputs = [[1.275], [1.2125], [1.173214], [1.146651], [1.052786], [1.034525], [1.020416], [1.008929], [1.005025], [1.001915], [1.00099], [1.000098]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, ...
coding
358
Solve the programming task below in a Python markdown code block. # Your Task The city of Darkishland has a strange hotel with infinite rooms. The groups that come to this hotel follow the following rules: * At the same time only members of one group can rent the hotel. * Each group comes in the morning of the check-...
{"functional": "_inputs = [[1, 6], [3, 10], [3, 14], [10, 1000], [1, 1000], [5, 4], [5, 7], [10000, 1000000000000000], [2, 20000000000000], [10, 900000000000000000], [34545, 565], [234234, 6577], [10, 10]]\n_outputs = [[3], [5], [6], [46], [45], [5], [6], [44721361], [6324555], [1341640786], [34545], [234234], [10]]\ni...
coding
341
Solve the programming task below in a Python markdown code block. Subodh is having N branches, where each branches have positive integral student. A minimize operation is performed on the branch such that all of them are reduced by the minimum number student in a branch. Suppose we have 5 branches and all of them have...
{"inputs": ["6\n5 4 4 2 2 8", "1000\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1...
coding
278
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin chinese, Russian and Vietnamese as well. Danya gave integers $a$, $b$ and $n$ to Archi. Archi wants to compare $a^{n}$ and $b^{n}$. Help Archi with this task. ------ Input ------ The first line of the input conta...
{"inputs": ["2\n3 4 5\n-3 2 4"], "outputs": ["2\n1"]}
coding
335
Solve the programming task below in a Python markdown code block. I have a lot of friends. Every friend is very small. I often go out with my friends. Put some friends in your backpack and go out together. Every morning I decide which friends to go out with that day. Put friends one by one in an empty backpack. I'm not...
{"inputs": ["4 1\n1\n2\n7\n9", "4 1\n1\n2\n7\n2", "4 1\n1\n1\n7\n9", "3 1\n1\n2\n7\n9", "4 1\n1\n2\n8\n2", "4 1\n1\n3\n7\n2", "3 1\n1\n4\n7\n9", "4 1\n1\n2\n8\n4"], "outputs": ["1\n", "1\n", "2\n", "1\n", "1\n", "1\n", "1\n", "1\n"]}
coding
447
Solve the programming task below in a Python markdown code block. You are given an array $a[0 \ldots n-1]$ of length $n$ which consists of non-negative integers. Note that array indices start from zero. An array is called good if the parity of each index matches the parity of the element at that index. More formally, ...
{"inputs": ["7\n1\n0\n1\n0\n1\n0\n1\n0\n1\n0\n1\n0\n1\n0\n", "7\n1\n0\n1\n0\n1\n0\n1\n0\n1\n0\n1\n0\n1\n0\n", "4\n4\n3 2 7 6\n3\n6 4 4\n1\n7\n7\n7 7 2 2 2 3 2\n", "4\n4\n6 2 7 6\n3\n6 4 4\n1\n7\n7\n6 7 4 2 2 3 2\n", "4\n4\n6 2 7 6\n3\n6 4 4\n1\n8\n7\n6 7 4 2 2 0 2\n", "4\n4\n6 2 7 1\n3\n6 2 4\n1\n8\n7\n6 7 4 2 2 0 2\n"...
coding
621
Solve the programming task below in a Python markdown code block. Chef has just started Programming, he is in first year of Engineering. Chef is reading about Relational Operators. Relational Operators are operators which check relatioship between two values. Given two numerical values A and B you need to help chef i...
{"inputs": ["3\n10 20\n20 10\n10 10"], "outputs": ["<\n>\n="]}
coding
250
Solve the programming task below in a Python markdown code block. You are an experienced Codeforces user. Today you found out that during your activity on Codeforces you have made y submissions, out of which x have been successful. Thus, your current success rate on Codeforces is equal to x / y. Your favorite rational...
{"inputs": ["1\n2 2 1 1\n", "1\n1 1 1 1\n", "1\n0 5 0 1\n", "1\n7 7 1 1\n", "1\n1 1 1 2\n", "1\n0 5 1 2\n", "1\n1 5 0 1\n", "1\n1 5 1 1\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "1\n", "5\n", "-1\n", "-1\n"]}
coding
451
Solve the programming task below in a Python markdown code block. You're hanging out with your friends in a bar, when suddenly one of them is so drunk, that he can't speak, and when he wants to say something, he writes it down on a paper. However, none of the words he writes make sense to you. He wants to help you, so ...
{"functional": "_inputs = [['yvvi'], ['Blf zoivzwb szw 10 yvvih'], [\"Ovg'h hdrn rm gsv ulfmgzrm!\"], [{'brand': 'Starobrno'}], [\"Tl slnv, blf'iv wifmp\"], [\"Hfiv r xzm wzmxv lm xlk'h xzi, slow nb yvvi\"], [True], [\"Hvv? R'n mlg gszg wifmp, r xzm hgroo gzpv nb xolgsvh luu\"], [123], [['Beer']]]\n_outputs = [['beer']...
coding
183
Solve the programming task below in a Python markdown code block. When you divide the successive powers of `10` by `13` you get the following remainders of the integer divisions: `1, 10, 9, 12, 3, 4`. Then the whole pattern repeats. Hence the following method: Multiply the right most digit of the number with the ...
{"functional": "_inputs = [[8529], [85299258], [5634], [1111111111], [987654321]]\n_outputs = [[79], [31], [57], [71], [30]]\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))...
coding
413
Solve the programming task below in a Python markdown code block. The only difference between easy and hard versions is constraints. The BerTV channel every day broadcasts one episode of one of the $k$ TV shows. You know the schedule for the next $n$ days: a sequence of integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le ...
{"inputs": ["4\n5 2 2\n1 2 1 2 1\n9 3 3\n3 3 3 2 2 2 1 1 1\n4 10 4\n10 8 6 4\n16 9 8\n3 1 4 1 5 9 2 6 5 3 5 8 9 7 9 3\n", "4\n5 2 2\n1 2 1 2 1\n9 3 3\n3 3 3 2 2 4 1 1 1\n4 10 4\n10 8 6 4\n16 9 8\n3 1 4 1 5 4 2 6 5 6 5 8 9 8 9 3\n", "4\n5 2 2\n1 2 1 2 1\n9 3 3\n3 3 3 2 2 2 1 1 1\n4 10 4\n10 8 6 4\n16 9 8\n3 1 4 1 5 4 2 ...
coding
755
Solve the programming task below in a Python markdown code block. You're about to go on a trip around the world! On this trip you're bringing your trusted backpack, that anything fits into. The bad news is that the airline has informed you, that your luggage cannot exceed a certain amount of weight. To make sure you'r...
{"functional": "_inputs = [[[15, 10, 9, 5], [1, 5, 3, 4], 8], [[20, 5, 10, 40, 15, 25], [1, 2, 3, 8, 7, 4], 10], [[19, 8, 6, 20, 3, 16], [8, 2, 3, 10, 1, 5], 17], [[100, 5, 16, 18, 50], [25, 1, 3, 2, 15], 14]]\n_outputs = [[29], [60], [46], [39]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) ...
coding
300
Solve the programming task below in a Python markdown code block. Takahashi has many red balls and blue balls. Now, he will place them in a row. Initially, there is no ball placed. Takahashi, who is very patient, will do the following operation 10^{100} times: - Place A blue balls at the end of the row of balls alread...
{"inputs": ["8 0 1", "8 3 7", "8 1 1", "8 1 7", "8 1 5", "6 1 0", "8 1 0", "6 2 3"], "outputs": ["0\n", "3\n", "4\n", "1\n", "2\n", "6\n", "8\n", "3\n"]}
coding
266
Solve the programming task below in a Python markdown code block. Meg the Rabbit decided to do something nice, specifically — to determine the shortest distance between two points on the surface of our planet. But Meg... what can you say, she wants everything simple. So, she already regards our planet as a two-dimensio...
{"inputs": ["5 1 5 2 5\n", "4 0 3 1 4\n", "5 4 0 5 1\n", "6 6 0 2 6\n", "5 4 0 5 2\n", "6 6 0 1 6\n", "2 0 1 2 0\n", "2 0 0 1 0\n"], "outputs": ["1\n", "2\n", "2\n", "10\n", "3\n", "11\n", "3\n", "1\n"]}
coding
316
Solve the programming task below in a Python markdown code block. Two players are playing a game on a $15\times15$ chessboard. The rules of the game are as follows: The game starts with $\boldsymbol{\mbox{k}}$ coins located at one or more $(x,y)$ coordinates on the board (a single cell may contain more than one coin)....
{"inputs": ["2\n3\n5 4\n5 8\n8 2\n6\n7 1\n7 2\n7 3\n7 4\n7 4\n7 4\n"], "outputs": ["First\nSecond\n"]}
coding
604
Solve the programming task below in a Python markdown code block. # Definition **_Disarium number_** is the number that *The sum of its digits powered with their respective positions is equal to the number itself*. ____ # Task **_Given_** a number, **_Find if it is Disarium or not_** . ____ # Warm-up (Highly reco...
{"functional": "_inputs = [[1024], [1306], [1999], [2427], [1048576], [2646798]]\n_outputs = [['Not !!'], ['Disarium !!'], ['Not !!'], ['Disarium !!'], ['Not !!'], ['Disarium !!']]\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_to...
coding
397
Solve the programming task below in a Python markdown code block. The internet is a very confounding place for some adults. Tom has just joined an online forum and is trying to fit in with all the teens and tweens. It seems like they're speaking in another language! Help Tom fit in by translating his well-formatted Eng...
{"functional": "_inputs = [['Hi, how are you today?'], ['I think it would be nice if we could all get along.'], [\"Let's eat, Grandma!\"], ['Woot woot woot woot woot woot!'], ['Hi, I can have cheeseburger?'], ['Sometimes I use ? in the middle of a sentence; is that ok?!'], ['Unto us a child is born.'], ['What happened ...
coding
713
Solve the programming task below in a Python markdown code block. An architect, Devunky, who lives in Water Deven, has been asked to renovate an old large hospital. In some countries, people don't want to use numbers that are disliked as numerophobia (4 and 9 are famous in Japan). However, the room numbers in this hos...
{"inputs": ["15\n100\n1000000000\n1\n0", "15\n110\n1000000000\n1\n0", "15\n101\n1000000000\n3\n0", "15\n110\n1000000000\n0\n0", "15\n101\n1001000000\n3\n0", "15\n100\n1000000000\n0\n0", "15\n111\n1001000000\n3\n0", "15\n000\n1000000000\n0\n0"], "outputs": ["19\n155\n9358757000\n1\n", "19\n178\n9358757000\n1\n", "19\n15...
coding
512
Solve the programming task below in a Python markdown code block. There are N cities and M roads. The i-th road (1≤i≤M) connects two cities a_i and b_i (1≤a_i,b_i≤N) bidirectionally. There may be more than one road that connects the same pair of two cities. For each city, how many roads are connected to the city? ----...
{"inputs": ["4 3\n1 2\n4 3\n1 4", "4 0\n1 2\n2 3\n1 4", "5 0\n1 2\n2 3\n1 4", "6 0\n0 3\n2 3\n1 4", "4 3\n1 2\n2 2\n1 4", "8 0\n1 2\n2 3\n1 4", "4 3\n1 2\n2 3\n1 4", "4 3\n1 2\n2 3\n1 4\n"], "outputs": ["2\n1\n1\n2\n", "0\n0\n0\n0\n", "0\n0\n0\n0\n0\n", "0\n0\n0\n0\n0\n0\n", "2\n3\n0\n1\n", "0\n0\n0\n0\n0\n0\n0\n0\n", ...
coding
281
Solve the programming task below in a Python markdown code block. The city of Fishtopia can be imagined as a grid of 4 rows and an odd number of columns. It has two main villages; the first is located at the top-left cell (1,1), people who stay there love fishing at the Tuna pond at the bottom-right cell (4, n). The se...
{"inputs": ["7 7\n", "9 5\n", "3 0\n", "5 0\n", "7 9\n", "5 4\n", "5 1\n", "9 4\n"], "outputs": ["YES\n.......\n.#####.\n.#...#.\n.......\n", "YES\n.........\n..#####..\n.........\n.........\n", "YES\n...\n...\n...\n...\n", "YES\n.....\n.....\n.....\n.....\n", "YES\n.......\n.#####.\n.##.##.\n.......\n", "YES\n.....\n....
coding
363
Solve the programming task below in a Python markdown code block. We define the diameter of a strongly-connected oriented graph, $G=(V,E)$, as the minimum integer $\boldsymbol{d}$ such that for each $u,v\in G$ there is a path from $\mbox{u}$ to $v$ of length $\leq d$ (recall that a path's length is its number of edges)...
{"inputs": ["5 2\n"], "outputs": ["2\n1 4\n2 0\n3 1\n4 2\n0 3\n"]}
coding
606
Solve the programming task below in a Python markdown code block. Recently, a chaotic virus Hexadecimal advanced a new theorem which will shake the Universe. She thinks that each Fibonacci number can be represented as sum of three not necessary different Fibonacci numbers. Let's remember how Fibonacci numbers can be c...
{"inputs": ["5\n", "1\n", "2\n", "0\n", "8\n", "3\n", "34\n", "55\n"], "outputs": ["0 0 5\n", "0 0 1\n", "0 0 2\n", "0 0 0\n", "0 0 8\n", "0 0 3\n", "0 0 34\n", "0 0 55\n"]}
coding
286
Solve the programming task below in a Python markdown code block. Create a function that takes in the sum and age difference of two people, calculates their individual ages, and returns a pair of values (oldest age first) if those exist or `null/None` if: * `sum < 0` * `difference < 0` * Either of the calculated ages ...
{"functional": "_inputs = [[24, 4], [30, 6], [70, 10], [18, 4], [63, 14], [80, 80], [63, -14], [-22, 15]]\n_outputs = [[[14, 10]], [[18, 12]], [[40, 30]], [[11, 7]], [[38.5, 24.5]], [[80, 0]], [None], [None]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n retu...
coding
106
Solve the programming task below in a Python markdown code block. It is said that a legendary treasure left by Mr. Yao is sleeping somewhere in Hachioji long ago. The treasure map, which is said to show its whereabouts, has been handed down by Yao's n descendants, divided into several pieces. Now, the descendants of M...
{"inputs": ["4\n1 1\n2 2 3\n2 1 2\n3 4 4 5\n0", "4\n1 1\n2 2 5\n2 0 2\n3 1 4 5\n0", "4\n1 1\n2 2 3\n2 1 2\n3 1 4 5\n0", "4\n1 1\n2 1 3\n2 0 1\n3 1 4 5\n0", "4\n1 1\n2 2 3\n2 0 4\n3 1 4 2\n0", "4\n1 1\n2 2 3\n2 1 2\n3 4 4 0\n0", "4\n1 1\n2 2 3\n2 2 2\n3 3 4 5\n0", "4\n1 1\n1 2 3\n2 1 2\n3 4 4 0\n0"], "outputs": ["-1\n",...
coding
605
Solve the programming task below in a Python markdown code block. The Chef has prepared the appetizers in the shapes of letters to spell a special message for the guests. There are n appetizers numbered from 0 to n-1 such that if the appetizers are arrayed in this order, they will display the message. The Chef plans to...
{"inputs": ["2\n2 chef\n4 enjoyourapplepie\n\n"], "outputs": ["cehf\neayejpuinpopolre"]}
coding
560
Solve the programming task below in a Python markdown code block. Tara was completing an Algorithms assignment and got stuck on a question. She thought of who can help her, and got reminded of Kabir who has good problem solving skills. The question is: Given N$N$ the number of elements in the sequence A1$A_1$,A2$A_2$ …...
{"inputs": ["1\n7\n3 2 15 6 8 5 10"], "outputs": ["5"]}
coding
402
Solve the programming task below in a Python markdown code block. Chef has a sequence of N$N$ integers A1,A2,...,AN$A_1, A_2, ..., A_N$. Chef thinks that a triplet of integers (i,j,k)$(i,j,k)$ is good if 1≤i<j<k≤N$1 \leq i < j < k \leq N$ and P$P$ in the following expression contains an odd number of ones in its binar...
{"inputs": ["1\n4\n1 1 2 3"], "outputs": ["1"]}
coding
532
Solve the programming task below in a Python markdown code block. Chef has an array of N numbers and a magic function which can swap two array values if their distance is strictly greater than K units. Since his friend Pishty is obsessed with sorted array, Chef wants to make the lexicographically minimum array possible...
{"inputs": ["6 2\n4 6 3 2 5 1"], "outputs": ["1 2 3 4 5 6"]}
coding
436
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an integer array nums (0-indexed). In one operation, you can choose an element of the array and increment it by 1. For example, if nums = [1,2,3], you can choose to increment nums[1] to make nums = [1,3...
{"functional": "def check(candidate):\n assert candidate(nums = [1,1,1]) == 3\n assert candidate(nums = [1,5,2,4,1]) == 14\n assert candidate(nums = [8]) == 0\n\n\ncheck(Solution().minOperations)"}
coding
166
Solve the programming task below in a Python markdown code block. A space explorer's ship crashed on Mars! They send a series of SOS messages to Earth for help. Letters in some of the SOS messages are altered by cosmic radiation during transmission. Given the signal received by Earth as a string, $\boldsymbol{\mathrm...
{"inputs": ["SOSSOT\n", "SOSSOSSOS\n", "SOSSPSSQSSOR\n"], "outputs": ["1\n", "0\n", "3\n"]}
coding
483
Solve the programming task below in a Python markdown code block. It is well known that Berland has n cities, which form the Silver ring — cities i and i + 1 (1 ≤ i < n) are connected by a road, as well as the cities n and 1. The goverment have decided to build m new roads. The list of the roads to build was prepared. ...
{"inputs": ["5 1\n3 5\n", "6 1\n6 2\n", "4 1\n4 2\n", "7 1\n4 7\n", "9 1\n6 2\n", "9 1\n4 7\n", "9 1\n4 2\n", "9 1\n1 2\n"], "outputs": ["i\n", "i\n", "i\n", "i\n", "i", "i", "i", "i"]}
coding
369
Solve the programming task below in a Python markdown code block. Calculate the number of items in a vector that appear at the same index in each vector, with the same value. ```python vector_affinity([1, 2, 3, 4, 5], [1, 2, 2, 4, 3]) # => 0.6 vector_affinity([1, 2, 3], [1, 2, 3]) # => 1.0 ``` Affinity value s...
{"functional": "_inputs = [[[1, 2, 3], [1, 2, 3, 4, 5]], [[1, 2, 3, 4], [1, 2, 3, 5]], [[1, 2, 3, 4, 5], []], [[1, 2, 3], [1, 2, 3]], [[6, 6, 6, 6, 6, 6], [6, None, None, 6, 6, None]], [[6], [6, 6, 6, 6, 6, 6]], [[], []], [[None], [None]]]\n_outputs = [[0.6], [0.75], [0.0], [1.0], [0.5], [0.16666666666666666], [1.0], [...
coding
201
Solve the programming task below in a Python markdown code block. Chef has two strings A and B of lengths N and M respectively. Chef can rearrange both strings in any way he wants. Let the rearranged string of A be A' and the rearranged string of B be B'. Determine whether we can construct rearrangements A' and B' s...
{"inputs": ["4\n5 2\nabcdd\nac\n3 3\nabc\nxyz\n2 4\naa\naaaa\n1 3\na\naax\n"], "outputs": ["YES\nNO\nYES\nNO\n"]}
coding
569
Solve the programming task below in a Python markdown code block. Dreamoon has a string s and a pattern string p. He first removes exactly x characters from s obtaining string s' as a result. Then he calculates $\operatorname{occ}(s^{\prime}, p)$ that is defined as the maximal number of non-overlapping substrings equal...
{"inputs": ["a\na\n", "a\nb\n", "a\na\n", "a\nb\n", "a\naa\n", "a\nab\n", "a\nab\n", "a\naa\n"], "outputs": ["1 0\n", "0 0\n", "1 0 \n", "0 0 \n", "0 0\n", "0 0\n", "0 0 \n", "0 0 \n"]}
coding
413
Solve the programming task below in a Python markdown code block. # Task Given an integer `n`, find the maximal number you can obtain by deleting exactly one digit of the given number. # Example For `n = 152`, the output should be `52`; For `n = 1001`, the output should be `101`. # Input/Output - `[input]` ...
{"functional": "_inputs = [[152], [1001], [10]]\n_outputs = [[52], [101], [1]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) != len(b): return False\n...
coding
142
Solve the programming task below in a Python markdown code block. Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya wonders eagerly what minimum...
{"inputs": ["7\n", "4\n", "5\n", "3\n", "1\n", "2\n", "6\n", "9\n"], "outputs": ["7\n", "4\n", "-1\n", "-1\n", "-1\n", "-1\n", "-1\n", "-1\n"]}
coding
185
Solve the programming task below in a Python markdown code block. Simply find the closest value to zero from the list. Notice that there are negatives in the list. List is always not empty and contains only integers. Return ```None``` if it is not possible to define only one of such values. And of course, we are expec...
{"functional": "_inputs = [[[10, 3, 9, 1]], [[2, 4, -1, -3]], [[5, 2, -2]], [[5, 2, 2]], [[13, 0, -6]], [[1]], [[5, 1, -1, 2, -10]], [[5, -5, -2, 5, -3]], [[27, 37, 48, -18, 42, 16, 5, 34, 35, 26, -34, 3, -43, 35, 0, -45, -7, 45, 34, -18, 44, 12, 6, -45, 33, 27, -2, 28, 12, 9]], [[11, -30, -18, 4, -13, 43, 12, -5, -6, ...
coding
161
Solve the programming task below in a Python markdown code block. You are given a rooted tree of $2^n - 1$ vertices. Every vertex of this tree has either $0$ children, or $2$ children. All leaves of this tree have the same distance from the root, and for every non-leaf vertex, one of its children is the left one, and t...
{"inputs": ["2\nBAA\n", "2\nABA\n", "2\nAAB\n", "2\nAAA\n", "2\nBBB\n", "2\nBBB\n", "2\nAAB\n", "2\nBBB\n"], "outputs": ["1\n", "2\n", "2\n", "1\n", "1\n", "1\n", "2\n", "1\n"]}
coding
593
Solve the programming task below in a Python markdown code block. Joisino has a formula consisting of N terms: A_1 op_1 A_2 ... op_{N-1} A_N. Here, A_i is an integer, and op_i is an binary operator either `+` or `-`. Because Joisino loves large numbers, she wants to maximize the evaluated value of the formula by insert...
{"inputs": ["3\n5 - 1 - 6", "3\n5 - 1 - 8", "3\n4 - 1 - 8", "3\n5 - 1 - 3", "5\n1 - 2 + 2 - 4 + 5", "5\n1 - 2 + 0 - 4 + 5", "5\n1 - 2 + 1 - 4 + 5", "5\n1 - 2 + 2 - 7 + 5"], "outputs": ["10\n", "12\n", "11\n", "7", "6\n", "8\n", "7\n", "9\n"]}
coding
320
Solve the programming task below in a Python markdown code block. Polycarp urgently needs a shovel! He comes to the shop and chooses an appropriate one. The shovel that Policarp chooses is sold for k burles. Assume that there is an unlimited number of such shovels in the shop. In his pocket Polycarp has an unlimited n...
{"inputs": ["1 1\n", "1 9\n", "1 2\n", "4 2\n", "9 3\n", "8 2\n", "1 3\n", "1 4\n"], "outputs": ["1\n", "9\n", "2\n", "3\n", "7\n", "4\n", "3\n", "4\n"]}
coding
487
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a 0-indexed 2D integer array nums. Initially, your score is 0. Perform the following operations until the matrix becomes empty: From each row in the matrix, select the largest number and remove it. In t...
{"functional": "def check(candidate):\n assert candidate(nums = [[7,2,1],[6,4,2],[6,5,3],[3,2,1]]) == 15\n assert candidate(nums = [[1]]) == 1\n\n\ncheck(Solution().matrixSum)"}
coding
139
Solve the programming task below in a Python markdown code block. A programming contest will be held at White Tiger University this year as well. There are several questions in the contest, each of which is assigned a score according to the difficulty level. The executive committee decided to calculate the score for e...
{"inputs": ["3\n1 0 100", "3\n2 0 100", "3\n1 1 100", "4\n11 15 58 1", "7\n2 0 4 2 2 0 0", "7\n2 1 4 2 2 0 0", "7\n2 1 4 2 4 0 0", "7\n2 1 2 2 4 0 0"], "outputs": ["1\n", "2\n", "1", "3", "2\n", "2\n", "2\n", "2\n"]}
coding
281
Solve the programming task below in a Python markdown code block. George has recently entered the BSUCP (Berland State University for Cool Programmers). George has a friend Alex who has also entered the university. Now they are moving into a dormitory. George and Alex want to live in the same room. The dormitory has ...
{"inputs": ["1\n0 0\n", "1\n0 0\n", "1\n0 1\n", "1\n0 2\n", "1\n-1 2\n", "1\n-1 0\n", "1\n-1 1\n", "1\n-2 1\n"], "outputs": ["0\n", "0\n", "0\n", "1\n", "1\n", "0\n", "1\n", "1\n"]}
coding
278
Solve the programming task below in a Python markdown code block. Cara is applying for several different jobs. The online application forms ask her to respond within a specific character count. Cara needs to check that her answers fit into the character limit. Annoyingly, some application forms count spaces as a chara...
{"functional": "_inputs = [['I am applying for the role of Base Manager on Titan.', 60, True], ['I am looking to relocate to the vicinity of Saturn for family reasons.', 70, True], ['As Deputy Base Manager on Phobos for five Martian years, I have significant relevant experience.', 90, False], ['A challenging career mom...
coding
386
Solve the programming task below in a Python markdown code block. Given an alphanumeric string made up of digits and lower case Latin characters only, find the sum of all the digit characters in the string. -----Input----- - The first line of the input contains an integer T denoting the number of test cases. Then T te...
{"inputs": ["1\nab1231da"], "outputs": ["7"]}
coding
204
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given two 0-indexed integer arrays nums1 and nums2, return a list answer of size 2 where: answer[0] is a list of all distinct integers in nums1 which are not present in nums2. answer[1] is a list of all distinct inte...
{"functional": "def check(candidate):\n assert candidate(nums1 = [1,2,3], nums2 = [2,4,6]) == [[1,3],[4,6]]\n assert candidate(nums1 = [1,2,3,3], nums2 = [1,1,2,2]) == [[3],[]]\n\n\ncheck(Solution().findDifference)"}
coding
139
Solve the programming task below in a Python markdown code block. Sasha grew up and went to first grade. To celebrate this event her mother bought her a multiplication table $M$ with $n$ rows and $n$ columns such that $M_{ij}=a_i \cdot a_j$ where $a_1, \dots, a_n$ is some sequence of positive integers. Of course, the ...
{"inputs": ["3\n0 2 4\n2 0 8\n4 8 0\n", "3\n0 4 4\n4 0 4\n4 4 0\n", "3\n0 6 6\n6 0 4\n6 4 0\n", "3\n0 6 6\n6 0 9\n6 9 0\n", "3\n0 9 9\n9 0 9\n9 9 0\n", "3\n0 4 8\n4 0 8\n8 8 0\n", "3\n0 6 6\n6 0 9\n6 9 0\n", "3\n0 4 8\n4 0 8\n8 8 0\n"], "outputs": ["1 2 4 ", "2 2 2 ", "3 2 2 ", "2 3 3 ", "3 3 3 ", "2 2 4 ", "2 3 3 ", "...
coding
460
Solve the programming task below in a Python markdown code block. Ichiro likes baseball and has decided to write a program which simulates baseball. The program reads events in an inning and prints score in that inning. There are only three events as follows: Single hit * put a runner on the first base. * the runner...
{"inputs": ["2\nHIT\nOUT\nHOMERUN\nHIT\nHIT\nHOMERUN\nHIT\nOUT\nHIT\nHIT\nHIT\nHIT\nOUT\nHIT\nHIT\nOUT\nHIT\nOUT\nOUT"], "outputs": ["7\n0"]}
coding
357
Solve the programming task below in a Python markdown code block. Sereja is hosting his birthday dinner. He invited his N close friends. Let us number the people from 1 to N according to the order in which they arrive at the event. The dinner is being held in long straight corridor in which people sit in a way such tha...
{"inputs": ["3\n1\n0\n3\n0 0 0\n5\n0 1 2 1 4"], "outputs": ["0\n0\n3"]}
coding
576
Solve the programming task below in a Python markdown code block. In this problem at each moment you have a set of intervals. You can move from interval (a, b) from our set to interval (c, d) from our set if and only if c < a < d or c < b < d. Also there is a path from interval I_1 from our set to interval I_2 from our...
{"inputs": ["5\n1 1 5\n1 5 11\n2 1 2\n1 2 9\n2 1 2\n", "5\n1 1 5\n1 5 11\n2 1 2\n1 2 9\n2 1 3\n", "5\n1 2 5\n1 5 11\n2 1 2\n1 2 4\n2 1 3\n", "5\n1 2 5\n1 5 11\n2 1 2\n1 2 9\n2 1 3\n", "5\n1 2 5\n1 5 11\n2 1 2\n1 3 9\n2 1 3\n", "5\n1 1 5\n1 5 11\n2 1 2\n1 3 9\n2 1 3\n", "5\n1 1 5\n1 5 11\n2 1 2\n1 2 9\n2 1 2\n", "9\n1 1...
coding
362
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin chinese, Russian and Vietnamese as well. You are given a string $S$ of lowercase English letters with length $N$. You are allowed to (but don't have to) choose one index in this string and change the letter at this ...
{"inputs": ["3\nabcd\ndbca\ndcba"], "outputs": ["6\n1\n0"]}
coding
389
Solve the programming task below in a Python markdown code block. Being a crewmate in the Among Us game, you will have to solve a task to win against the imposter. The task : You are given a certain number of bulbs(Say n) which are initially in OFF position. The bulbs are numbered from 1 to n. There will be n current...
{"inputs": ["2\n2\n20"], "outputs": ["1\n3"]}
coding
341
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a string s. Reorder the string using the following algorithm: Remove the smallest character from s and append it to the result. Remove the smallest character from s that is greater than the last appende...
{"functional": "def check(candidate):\n assert candidate(s = \"aaaabbbbcccc\") == \"abccbaabccba\"\n assert candidate(s = \"rat\") == \"art\"\n assert candidate(s = \"leetcode\") == \"cdelotee\"\n assert candidate(s = \"ggggggg\") == \"ggggggg\"\n assert candidate(s = \"spo\") == \"ops\"\n\n\ncheck(Solut...
coding
207
Solve the programming task below in a Python markdown code block. # Base64 Numeric Translator Our standard numbering system is (Base 10). That includes 0 through 9. Binary is (Base 2), only 1’s and 0’s. And Hexadecimal is (Base 16) (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F). A hexadecimal “F” has a (Base 10) va...
{"functional": "_inputs = [['WIN'], ['b64'], ['B64'], ['/+/'], ['HelloWorld']]\n_outputs = [[90637], [114360], [7864], [262079], [134710352538679645]]\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 is...
coding
442
Solve the programming task below in a Python markdown code block. Uppal-balu is busy in extraction of gold from ores. He got an assignment from his favorite professor MH sir, but he got stuck in a problem. Can you help Uppal-balu to solve the problem. You are given an array $a_1$, $a_2$, $\dots$, $a_n$ of length $n$. Y...
{"inputs": ["7 3 4\n8 2 3 7 8 1 1", "8 3 5\n7 2 1 3 6 5 6 2"], "outputs": ["5", "5"]}
coding
559
Solve the programming task below in a Python markdown code block. You are given a string S of length N consisting of lowercase English letters. Process Q queries of the following two types: - Type 1: change the i_q-th character of S to c_q. (Do nothing if the i_q-th character is already c_q.) - Type 2: answer the num...
{"inputs": ["7\nabcdbbd\n6\n2 3 6\n1 5 y\n2 1 1\n1 4 a\n1 7 d\n2 1 7", "7\nabccbbd\n6\n2 3 6\n1 5 y\n2 1 1\n1 4 a\n1 7 d\n2 0 7", "7\nabdcbbd\n6\n2 3 6\n1 5 z\n2 1 1\n1 4 a\n1 7 d\n2 0 7", "7\nabcdbbd\n6\n2 3 0\n1 5 z\n2 1 1\n1 4 a\n1 7 d\n2 1 7", "7\nabccbbd\n6\n2 3 5\n1 5 z\n2 1 1\n1 5 a\n1 7 d\n2 0 7", "7\nabcdbbd\n...
coding
489
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a binary array nums, return the maximum length of a contiguous subarray with an equal number of 0 and 1.   Please complete the following python code precisely: ```python class Solution: def findMaxLength(sel...
{"functional": "def check(candidate):\n assert candidate(nums = [0,1]) == 2\n assert candidate(nums = [0,1,0]) == 2\n\n\ncheck(Solution().findMaxLength)"}
coding
74
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 two integers $L$ and $R$. Find the smallest non-negative integer $N$ such that $$N \,\%\, L > N \,\%\, (L + 1) > \ldots > N \,\%\, (R ...
{"inputs": ["2\n4 6\n1 2"], "outputs": ["6\n-1"]}
coding
470
Solve the programming task below in a Python markdown code block. The HR manager was disappointed again. The last applicant failed the interview the same way as 24 previous ones. "Do I give such a hard task?" — the HR manager thought. "Just raise number 5 to the power of n and get last two digits of the number. Yes, of...
{"inputs": ["2\n", "7\n", "7\n", "3\n", "5\n", "8\n", "6\n", "9\n"], "outputs": ["25", "25", "25\n", "25\n", "25\n", "25\n", "25\n", "25\n"]}
coding
193
Solve the programming task below in a Python markdown code block. There are $n$ consecutive seat places in a railway carriage. Each place is either empty or occupied by a passenger. The university team for the Olympiad consists of $a$ student-programmers and $b$ student-athletes. Determine the largest number of studen...
{"inputs": ["1 0 1\n.\n", "1 1 1\n.\n", "1 1 1\n.\n", "1 0 1\n.\n", "1 0 2\n.\n", "1 1 2\n.\n", "1 2 1\n.\n", "2 2 0\n..\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n"]}
coding
501
Please solve the programming task below using a self-contained code snippet in a markdown code block. A valid parentheses string is either empty "", "(" + A + ")", or A + B, where A and B are valid parentheses strings, and + represents string concatenation. For example, "", "()", "(())()", and "(()(()))" are all vali...
{"functional": "def check(candidate):\n assert candidate(s = \"(()())(())\") == \"()()()\"\n assert candidate(s = \"(()())(())(()(()))\") == \"()()()()(())\"\n assert candidate(s = \"()()\") == \"\"\n\n\ncheck(Solution().removeOuterParentheses)"}
coding
197
Solve the programming task below in a Python markdown code block. Create a function that takes a string and an integer (`n`). The function should return a string that repeats the input string `n` number of times. If anything other than a string is passed in you should return `"Not a string"` ## Example ``` "Hi", 2...
{"functional": "_inputs = [['*', 3], ['Hello', 11], ['243624', 22], [[], 3], [24, 3], [True, 3], ['Hello', 0]]\n_outputs = [['***'], ['HelloHelloHelloHelloHelloHelloHelloHelloHelloHelloHello'], ['2436242436242436242436242436242436242436242436242436242436242436242436242436242436242436242436242436242436242436242436242436...
coding
115
Solve the programming task below in a Python markdown code block. For a given prime $\boldsymbol{p}$, define $\text{ord}_p(k)$ as the multiplicity of $\boldsymbol{p}$ in $\boldsymbol{\mbox{k}}$, i.e. the number of times $\boldsymbol{p}$ appears in the prime factorization of $\boldsymbol{k}$. For a given $\boldsymbol{p...
{"inputs": ["2\n2 6\n3 6\n"], "outputs": ["2\n2\n"]}
coding
488
Solve the programming task below in a Python markdown code block. There are $ n $ acitivities with start times $ \\ {s_i \\} $ and finish times $ \\ {t_i \\} $. Assuming that a person can only work on a single activity at a time, find the maximum number of activities that can be performed by a single person. Constrain...
{"inputs": ["3\n1 1\n2 3\n3 4", "3\n0 5\n3 4\n2 5", "3\n1 1\n2 4\n3 4", "3\n1 1\n2 4\n3 3", "3\n2 1\n2 4\n3 3", "3\n4 1\n2 4\n3 3", "3\n4 1\n2 4\n3 2", "3\n4 1\n4 4\n3 2"], "outputs": ["2\n", "1\n", "2\n", "2\n", "2\n", "2\n", "2\n", "3\n"]}
coding
279
Solve the programming task below in a Python markdown code block. You are given an alphabet consisting of n letters, your task is to make a string of the maximum possible length so that the following conditions are satisfied: the i-th letter occurs in the string no more than a_{i} times; the number of occurrences of...
{"inputs": ["2\n1 1\n", "2\n1 1\n", "2\n1 2\n", "2\n1 0\n", "3\n2 5 5\n", "3\n1 1 2\n", "3\n1 1 1\n", "3\n1 1 1\n"], "outputs": ["1\n", "1\n", "3\n", "1\n", "11\n", "3\n", "1\n", "1\n"]}
coding
293
Solve the programming task below in a Python markdown code block. Chef defines a group of three friends as a *perfect* group if the age of one person is equal to the sum of the age of remaining two people. Given that, the ages of three people in a group are A, B, and C respectively, find whether the group is *perfect...
{"inputs": ["4\n10 20 30\n23 51 17\n44 21 23\n30 30 30\n"], "outputs": ["YES\nNO\nYES\nNO\n"]}
coding
424
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an array of strings tokens that represents an arithmetic expression in a Reverse Polish Notation. Evaluate the expression. Return an integer that represents the value of the expression. Note that: The v...
{"functional": "def check(candidate):\n assert candidate(tokens = [\"2\",\"1\",\"+\",\"3\",\"*\"]) == 9\n assert candidate(tokens = [\"4\",\"13\",\"5\",\"/\",\"+\"]) == 6\n assert candidate(tokens = [\"10\",\"6\",\"9\",\"3\",\"+\",\"-11\",\"*\",\"/\",\"*\",\"17\",\"+\",\"5\",\"+\"]) == 22\n\n\ncheck(Solution()...
coding
159
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an array of integers, write a method to find indices m and n such that if you sorted elements m through n, the entire array would be sorted. Minimize n - m (that is, find the smallest such sequence). Return [m,n...
{"functional": "def check(candidate):\n assert candidate([1,2,4,7,10,11,7,12,6,7,16,18,19]) == [3,9]\n\n\ncheck(Solution().subSort)"}
coding
126
Solve the programming task below in a Python markdown code block. Check your arrows You have a quiver of arrows, but some have been damaged. The quiver contains arrows with an optional range information (different types of targets are positioned at different ranges), so each item is an arrow. You need to verify that y...
{"functional": "_inputs = [[[]], [[{'range': 5, 'damaged': False}]], [[{'range': 5, 'damaged': False}, {'range': 15, 'damaged': True}]], [[{'range': 5}, {'range': 10, 'damaged': True}, {'damaged': True}]], [[{'range': 10, 'damaged': True}, {'damaged': True}]]]\n_outputs = [[False], [True], [True], [True], [False]]\nimp...
coding
193
Solve the programming task below in a Python markdown code block. # Task A noob programmer was given two simple tasks: sum and sort the elements of the given array `arr` = [a1, a2, ..., an]. He started with summing and did it easily, but decided to store the sum he found in some random position of the original arr...
{"functional": "_inputs = [[[1, 12, 3, 6, 2]], [[1, -3, -5, 7, 2]], [[2, -1, 2, 2, -1]], [[-3, -3]]]\n_outputs = [[[1, 2, 3, 6]], [[-5, -3, 2, 7]], [[-1, -1, 2, 2]], [[-3]]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, ...
coding
410
Solve the programming task below in a Python markdown code block. An avid hiker keeps meticulous records of their hikes. During the last hike that took exactly $\textit{steps}$ steps, for every step it was noted if it was an uphill, $\mbox{U}$, or a downhill, $\mbox{D}$ step. Hikes always start and end at sea level, an...
{"inputs": ["8\nUDDDUDUU\n"], "outputs": ["1\n"]}
coding
449
Solve the programming task below in a Python markdown code block. You are given an array $a$ of length $n$ consisting of integers. You can apply the following operation, consisting of several steps, on the array $a$ zero or more times: you select two different numbers in the array $a_i$ and $a_j$; you remove $i$-th a...
{"inputs": ["1\n12\n2 2 2 2 4 4 4 4 6 6 6 6\n", "1\n12\n2 2 2 2 4 4 4 4 6 6 6 6\n", "1\n12\n1 2 2 2 4 4 4 4 6 6 6 6\n", "1\n12\n1 2 2 2 4 4 2 4 6 6 6 6\n", "1\n12\n2 2 2 2 7 4 4 4 6 6 6 6\n", "1\n12\n1 2 2 2 8 4 2 4 6 6 6 6\n", "1\n12\n2 2 2 2 7 4 4 4 5 6 6 6\n", "1\n12\n1 2 2 1 8 4 2 4 6 6 6 6\n"], "outputs": ["0\n", ...
coding
453
Solve the programming task below in a Python markdown code block. We consider permutations of the numbers $1,..., N$ for some $N$. By permutation we mean a rearrangment of the number $1,...,N$. For example 24517638245176382 \quad 4 \quad 5 \quad 1 \quad 7 \quad 6 \quad 3 \quad 8 is a permutation of $1,2,...,8$. Of cour...
{"inputs": ["8\n2 4 5 1 7 6 3 8", "8\n1 2 3 4 5 6 7 8"], "outputs": ["4\n1 2 4 1\n3 5 7 3\n6 6\n8 8", "8\n1 1\n2 2\n3 3\n4 4\n5 5\n6 6\n7 7\n8 8"]}
coding
747
Solve the programming task below in a Python markdown code block. There's a **"3 for 2"** (or **"2+1"** if you like) offer on mangoes. For a given quantity and price (per mango), calculate the total cost of the mangoes. ### Examples ```python mango(3, 3) ==> 6 # 2 mangoes for 3 = 6; +1 mango for free mango(9, 5) ==...
{"functional": "_inputs = [[3, 3], [9, 5]]\n_outputs = [[6], [30]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) != len(b): return False\n retu...
coding
154
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...
coding
233
Solve the programming task below in a Python markdown code block. Limak is a little polar bear. He plays by building towers from blocks. Every block is a cube with positive integer length of side. Limak has infinitely many blocks of each side length. A block with side a has volume a^3. A tower consisting of blocks wit...
{"inputs": ["6\n", "1\n", "2\n", "7\n", "8\n", "9\n", "2\n", "9\n"], "outputs": ["6 6\n", "1 1\n", "2 2\n", "7 7\n", "7 7\n", "7 7\n", "2 2\n", "7 7\n"]}
coding
541
Solve the programming task below in a Python markdown code block. Your team is writing a fancy new text editor and you've been tasked with implementing the line numbering. Write a function which takes a list of strings and returns each line prepended by the correct number. The numbering starts at 1. The format is `n:...
{"functional": "_inputs = [[[]], [['a', 'b', 'c']], [['', '', '', '', '']], [['', 'b', '', '', '']]]\n_outputs = [[[]], [['1: a', '2: b', '3: c']], [['1: ', '2: ', '3: ', '4: ', '5: ']], [['1: ', '2: b', '3: ', '4: ', '5: ']]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, flo...
coding
138
Solve the programming task below in a Python markdown code block. Given a mixed array of number and string representations of integers, add up the string integers and subtract this from the total of the non-string integers. Return as a number. Also feel free to reuse/extend the following starter code: ```python def d...
{"functional": "_inputs = [[[9, 3, '7', '3']], [['5', '0', 9, 3, 2, 1, '9', 6, 7]], [['3', 6, 6, 0, '5', 8, 5, '6', 2, '0']], [['1', '5', '8', 8, 9, 9, 2, '3']], [[8, 0, 0, 8, 5, 7, 2, 3, 7, 8, 6, 7]]]\n_outputs = [[2], [14], [13], [11], [61]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or ...
coding
69
Solve the programming task below in a Python markdown code block. In 21XX, an annual programming contest, Japan Algorithmist GrandPrix (JAG) has become one of the most popular mind sports events. JAG is conducted as a knockout tournament. This year, $N$ contestants will compete in JAG. A tournament chart is represente...
{"inputs": ["[[r-i]-[m-e]]\ne 0\nr 1\ni 1\nn 2", "[[m-y]-[a-o]]\nn 0\na 1\ny 2\nm 0", "[[r-i]-[m-e]]\nd 0\nr 1\ni 1\nn 2", "[[r-i]-[m-e]]\nd 0\nr 1\ni 1\nn 3", "[[r-i]-[m-e]]\nd 0\nr 1\nh 1\nn 3", "[[r-i]-[m-e]]\nd 0\nr 1\ng 1\nn 3", "[[r-i]-[m-e]]\nd 0\nr 1\ng 1\nm 3", "[[m-y]-[a-o]]\no 0\nb 1\ny 2\nm 0"], "outputs": ...
coding
636
Solve the programming task below in a Python markdown code block. Given a set of distinct integers, print the size of a maximal subset of $S$ where the sum of any $2$ numbers in $\text{S'}$ is not evenly divisible by $k$. Example $S=[19,10,12,10,24,25,22]$ $k=4$ One of the arrays that can be created is $S'[0]=[10,1...
{"inputs": ["4 3 \n1 7 2 4 \n"], "outputs": ["3\n"]}
coding
475