question
stringlengths
29
1.88k
test_input
listlengths
0
10
test_output
listlengths
0
10
test_time_limit
int64
1
1
test_method
stringclasses
1 value
While playing with geometric figures Alex has accidentally invented a concept of a $n$-th order rhombus in a cell grid. A $1$-st order rhombus is just a square $1 \times 1$ (i.e just a cell). A $n$-th order rhombus for all $n \geq 2$ one obtains from a $n-1$-th order rhombus adding all cells which have a common side with it to it (look at the picture to understand it better). [Image] Alex asks you to compute the number of cells in a $n$-th order rhombus. -----Input----- The first and only input line contains integer $n$ ($1 \leq n \leq 100$) — order of a rhombus whose numbers of cells should be computed. -----Output----- Print exactly one integer — the number of cells in a $n$-th order rhombus. -----Examples----- Input 1 Output 1 Input 2 Output 5 Input 3 Output 13 -----Note----- Images of rhombus corresponding to the examples are given in the statement.
[ "1\n", "2\n", "3\n", "11\n", "21\n", "31\n", "41\n", "51\n", "100\n", "34\n" ]
[ "1", "5", "13", "221", "841", "1861", "3281", "5101", "19801", "2245" ]
1
stdio
VK news recommendation system daily selects interesting publications of one of n disjoint categories for each user. Each publication belongs to exactly one category. For each category i batch algorithm selects a_i publications. The latest A/B test suggests that users are reading recommended publications more actively if each category has a different number of publications within daily recommendations. The targeted algorithm can find a single interesting publication of i-th category within t_i seconds. What is the minimum total time necessary to add publications to the result of batch algorithm execution, so all categories have a different number of publications? You can't remove publications recommended by the batch algorithm. Input The first line of input consists of single integer n — the number of news categories (1 ≤ n ≤ 200 000). The second line of input consists of n integers a_i — the number of publications of i-th category selected by the batch algorithm (1 ≤ a_i ≤ 10^9). The third line of input consists of n integers t_i — time it takes for targeted algorithm to find one new publication of category i (1 ≤ t_i ≤ 10^5). Output Print one integer — the minimal required time for the targeted algorithm to get rid of categories with the same size. Examples Input 5 3 7 9 7 8 5 2 5 7 5 Output 6 Input 5 1 2 3 4 5 1 1 1 1 1 Output 0 Note In the first example, it is possible to find three publications of the second type, which will take 6 seconds. In the second example, all news categories contain a different number of publications.
[ "5\n1000000000 1000000000 1000000000 1000000000 1000000000\n100000 100000 100000 100000 100000\n", "10\n14 31 50 67 42 44 86 82 35 63\n76 17 26 44 60 54 50 73 71 70\n", "10\n4 4 1 2 2 2 5 4 1 5\n28 81 36 44 2 40 39 43 36 33\n", "10\n69564153 558821634 273092444 121621442 354953668 157021146 918149509 90215990...
[ "1000000\n", "0\n", "593\n", "0\n", "0\n", "0\n", "0\n", "0\n", "66248\n", "0\n" ]
1
stdio
You are given three strings A, B and C. Check whether they form a word chain. More formally, determine whether both of the following are true: - The last character in A and the initial character in B are the same. - The last character in B and the initial character in C are the same. If both are true, print YES. Otherwise, print NO. -----Constraints----- - A, B and C are all composed of lowercase English letters (a - z). - 1 ≤ |A|, |B|, |C| ≤ 10, where |A|, |B| and |C| are the lengths of A, B and C, respectively. -----Input----- Input is given from Standard Input in the following format: A B C -----Output----- Print YES or NO. -----Sample Input----- rng gorilla apple -----Sample Output----- YES They form a word chain.
[ "rng gorilla apple\n", "yakiniku unagi sushi\n", "a a a\n", "aaaaaaaaab aaaaaaaaaa aaaaaaaaab\n", "a a `", "baaaa`aaaa aabaaaaaaa aaaaa`aaab", "rnh gorilla apple", "aaaaaaaaab aaaaaaaaaa aaaaa`aaab", "ybkiniku unagi sushi", "a b a" ]
[ "YES\n", "NO\n", "YES\n", "NO\n", "NO\n", "YES\n", "NO\n", "NO\n", "NO\n", "NO\n" ]
1
stdio
I assume most of you are familiar with the ancient legend of the rice (but I see wikipedia suggests [wheat](https://en.wikipedia.org/wiki/Wheat_and_chessboard_problem), for some reason) problem, but a quick recap for you: a young man asks as a compensation only `1` grain of rice for the first square, `2` grains for the second, `4` for the third, `8` for the fourth and so on, always doubling the previous. Your task is pretty straightforward (but not necessarily easy): given an amount of grains, you need to return up to which square of the chessboard one should count in order to get at least as many. As usual, a few examples might be way better than thousands of words from me: ```python squares_needed(0) == 0 squares_needed(1) == 1 squares_needed(2) == 2 squares_needed(3) == 2 squares_needed(4) == 3 ``` Input is always going to be valid/reasonable: ie: a non negative number; extra cookie for *not* using a loop to compute square-by-square (at least not directly) and instead trying a smarter approach [hint: some peculiar operator]; a trick converting the number might also work: impress me! Write your solution by modifying this code: ```python def squares_needed(grains): ``` Your solution should implemented in the function "squares_needed". The inputs will be passed to it and it should return the correct solution. Now solve the problem and return the code.
[]
[]
1
stdio
# Task Elections are in progress! Given an array of numbers representing votes given to each of the candidates, and an integer which is equal to the number of voters who haven't cast their vote yet, find the number of candidates who still have a chance to win the election. The winner of the election must secure strictly more votes than any other candidate. If two or more candidates receive the same (maximum) number of votes, assume there is no winner at all. **Note**: big arrays will be tested. # Examples ``` votes = [2, 3, 5, 2] voters = 3 result = 2 ``` * Candidate `#3` may win, because he's already leading. * Candidate `#2` may win, because with 3 additional votes he may become the new leader. * Candidates `#1` and `#4` have no chance, because in the best case scenario each of them can only tie with the candidate `#3`. ___ ``` votes = [3, 1, 1, 3, 1] voters = 2 result = 2 ``` * Candidate `#1` and `#4` can become leaders if any of them gets the votes. * If any other candidate gets the votes, they will get tied with candidates `#1` and `#4`. ___ ``` votes = [1, 3, 3, 1, 1] voters = 0 result = 0 ``` * There're no additional votes to cast, and there's already a tie. Write your solution by modifying this code: ```python def elections_winners(votes, k): ``` Your solution should implemented in the function "elections_winners". The inputs will be passed to it and it should return the correct solution. Now solve the problem and return the code.
[]
[]
1
stdio
You have a digit sequence S of length 4. You are wondering which of the following formats S is in: - YYMM format: the last two digits of the year and the two-digit representation of the month (example: 01 for January), concatenated in this order - MMYY format: the two-digit representation of the month and the last two digits of the year, concatenated in this order If S is valid in only YYMM format, print YYMM; if S is valid in only MMYY format, print MMYY; if S is valid in both formats, print AMBIGUOUS; if S is valid in neither format, print NA. -----Constraints----- - S is a digit sequence of length 4. -----Input----- Input is given from Standard Input in the following format: S -----Output----- Print the specified string: YYMM, MMYY, AMBIGUOUS or NA. -----Sample Input----- 1905 -----Sample Output----- YYMM May XX19 is a valid date, but 19 is not valid as a month. Thus, this string is only valid in YYMM format.
[ "1905\n", "0112\n", "1700\n", "0101\n", "1312\n", "0348\n", "9999\n", "0001\n", "0000\n", "0100\n" ]
[ "YYMM\n", "AMBIGUOUS\n", "NA\n", "AMBIGUOUS\n", "YYMM\n", "MMYY\n", "NA\n", "YYMM\n", "NA\n", "MMYY\n" ]
1
stdio
This program tests the life of an evaporator containing a gas. We know the content of the evaporator (content in ml), the percentage of foam or gas lost every day (evap_per_day) and the threshold (threshold) in percentage beyond which the evaporator is no longer useful. All numbers are strictly positive. The program reports the nth day (as an integer) on which the evaporator will be out of use. **Note** : Content is in fact not necessary in the body of the function "evaporator", you can use it or not use it, as you wish. Some people might prefer to reason with content, some other with percentages only. It's up to you but you must keep it as a parameter because the tests have it as an argument. Write your solution by modifying this code: ```python def evaporator(content, evap_per_day, threshold): ``` Your solution should implemented in the function "evaporator". The inputs will be passed to it and it should return the correct solution. Now solve the problem and return the code.
[]
[]
1
stdio
According to a new ISO standard, a flag of every country should have a chequered field n × m, each square should be of one of 10 colours, and the flag should be «striped»: each horizontal row of the flag should contain squares of the same colour, and the colours of adjacent horizontal rows should be different. Berland's government asked you to find out whether their flag meets the new ISO standard. Input The first line of the input contains numbers n and m (1 ≤ n, m ≤ 100), n — the amount of rows, m — the amount of columns on the flag of Berland. Then there follows the description of the flag: each of the following n lines contain m characters. Each character is a digit between 0 and 9, and stands for the colour of the corresponding square. Output Output YES, if the flag meets the new ISO standard, and NO otherwise. Examples Input 3 3 000 111 222 Output YES Input 3 3 000 000 111 Output NO Input 3 3 000 111 002 Output NO
[ "10 10\n2222222222\n5555555555\n0000000000\n4444444444\n1111111111\n3333333393\n3333333333\n5555555555\n0000000000\n8888888888\n", "100 1\n3\n6\n4\n3\n0\n2\n8\n7\n3\n2\n1\n7\n1\n3\n2\n3\n6\n9\n0\n8\n5\n9\n7\n9\n2\n1\n4\n5\n1\n9\n2\n5\n1\n4\n6\n4\n9\n1\n0\n2\n1\n4\n7\n1\n4\n8\n0\n9\n2\n1\n6\n2\n8\n6\n9\n5\n8\n6\n4...
[ "NO\n", "YES\n", "YES\n", "NO\n", "YES\n", "YES\n", "YES\n", "NO\n", "NO\n", "YES\n" ]
1
stdio
Ivan recently bought a detective book. The book is so interesting that each page of this book introduces some sort of a mystery, which will be explained later. The $i$-th page contains some mystery that will be explained on page $a_i$ ($a_i \ge i$). Ivan wants to read the whole book. Each day, he reads the first page he didn't read earlier, and continues to read the following pages one by one, until all the mysteries he read about are explained and clear to him (Ivan stops if there does not exist any page $i$ such that Ivan already has read it, but hasn't read page $a_i$). After that, he closes the book and continues to read it on the following day from the next page. How many days will it take to read the whole book? -----Input----- The first line contains single integer $n$ ($1 \le n \le 10^4$) — the number of pages in the book. The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($i \le a_i \le n$), where $a_i$ is the number of page which contains the explanation of the mystery on page $i$. -----Output----- Print one integer — the number of days it will take to read the whole book. -----Example----- Input 9 1 3 3 6 7 6 8 8 9 Output 4 -----Note----- Explanation of the example test: During the first day Ivan will read only the first page. During the second day Ivan will read pages number $2$ and $3$. During the third day — pages $4$-$8$. During the fourth (and the last) day Ivan will read remaining page number $9$.
[ "9\n1 3 3 6 7 6 8 8 9\n", "1\n1\n", "10\n1 3 4 5 5 6 7 8 9 10\n", "10\n4 9 4 10 6 8 9 8 9 10\n", "15\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15\n", "17\n9 4 3 6 7 6 8 8 9 10 11 12 13 14 15 16 17\n", "13\n1 2 3 4 5 6 7 8 9 10 11 12 13\n", "12\n1 2 3 4 5 6 7 8 9 10 11 12\n", "11\n1 2 3 4 5 6 7 8 9 10 11\n",...
[ "4\n", "1\n", "7\n", "1\n", "15\n", "9\n", "13\n", "12\n", "11\n", "3\n" ]
1
stdio
In this kata, the number 0 is infected. You are given a list. Every turn, any item in the list that is adjacent to a 0 becomes infected and transforms into a 0. How many turns will it take for the whole list to become infected? ``` [0,1,1,0] ==> [0,0,0,0] All infected in 1 turn. [1,1,0,1,1] --> [1,0,0,0,1] --> [0,0,0,0,0] All infected in 2 turns [0,1,1,1] --> [0,0,1,1] --> [0,0,0,1] --> [0,0,0,0] All infected in 3 turns. ``` All lists will contain at least one item, and at least one zero, and the only items will be 0s and 1s. Lists may be very very long, so pure brute force approach will not work. Write your solution by modifying this code: ```python def infected_zeroes(lst): ``` Your solution should implemented in the function "infected_zeroes". The inputs will be passed to it and it should return the correct solution. Now solve the problem and return the code.
[]
[]
1
stdio
Gargari got bored to play with the bishops and now, after solving the problem about them, he is trying to do math homework. In a math book he have found k permutations. Each of them consists of numbers 1, 2, ..., n in some order. Now he should find the length of the longest common subsequence of these permutations. Can you help Gargari? You can read about longest common subsequence there: https://en.wikipedia.org/wiki/Longest_common_subsequence_problem -----Input----- The first line contains two integers n and k (1 ≤ n ≤ 1000; 2 ≤ k ≤ 5). Each of the next k lines contains integers 1, 2, ..., n in some order — description of the current permutation. -----Output----- Print the length of the longest common subsequence. -----Examples----- Input 4 3 1 4 2 3 4 1 2 3 1 2 4 3 Output 3 -----Note----- The answer for the first test sample is subsequence [1, 2, 3].
[ "4 3\n1 4 2 3\n4 1 2 3\n1 2 4 3\n", "6 3\n2 5 1 4 6 3\n5 1 4 3 2 6\n5 4 2 6 3 1\n", "41 4\n24 15 17 35 13 41 4 14 23 5 8 16 21 18 30 36 6 22 11 29 26 1 40 31 7 3 32 10 28 38 12 20 39 37 34 19 33 27 2 25 9\n22 13 25 24 38 35 29 12 15 8 11 37 3 19 4 23 18 32 30 40 36 21 16 34 27 9 5 41 39 2 14 17 31 33 26 7 1 10 ...
[ "3\n", "3\n", "4\n", "1\n", "3\n", "4\n", "4\n", "7\n", "4", "3" ]
1
stdio
Failed Filter - Bug Fixing #3 Oh no, Timmy's filter doesn't seem to be working? Your task is to fix the FilterNumber function to remove all the numbers from the string. Write your solution by modifying this code: ```python def filter_numbers(string): ``` Your solution should implemented in the function "filter_numbers". The inputs will be passed to it and it should return the correct solution. Now solve the problem and return the code.
[]
[]
1
stdio
From "ftying rats" to urban saniwation workers - can synthetic biology tronsform how we think of pigeons? The upiquitous pigeon has long been viewed as vermin - spleading disease, scavenging through trush, and defecating in populous urban spases. Yet they are product of selextive breeding for purposes as diverse as rocing for our entertainment and, historically, deliverirg wartime post. Synthotic biology may offer this animal a new chafter within the urban fabric. Piteon d'Or recognihes how these birds ripresent a potentially userul interface for urdan biotechnologies. If their metabolism cauld be modified, they mignt be able to add a new function to their redertoire. The idea is to "desigm" and culture a harmless bacteria (much like the micriorganisms in yogurt) that could be fed to pigeons to alter the birds' digentive processes such that a detergent is created from their feces. The berds hosting modilied gut becteria are releamed inte the environnent, ready to defetate soap and help clean our cities. -----Input----- The first line of input data contains a single integer $n$ ($5 \le n \le 10$). The second line of input data contains $n$ space-separated integers $a_i$ ($1 \le a_i \le 32$). -----Output----- Output a single integer. -----Example----- Input 5 1 2 3 4 5 Output 4 -----Note----- We did not proofread this statement at all.
[ "5\n1 2 3 4 5\n", "6\n6 12 3 15 9 18\n", "6\n28 4 13 29 17 8\n", "9\n23 1 2 26 9 11 23 10 26\n", "7\n18 29 23 23 1 14 5\n", "5\n22 19 19 16 14\n", "9\n17 16 8 13 6 29 22 27 18\n", "6\n12 12 29 10 30 32\n", "7\n31 1 19 3 11 20 31\n", "5\n27 30 8 32 3\n" ]
[ "4\n", "2\n", "11\n", "5\n", "24\n", "31\n", "16\n", "25\n", "20\n", "13\n" ]
1
stdio
The only difference between easy and hard versions is the number of elements in the array. You are given an array $a$ consisting of $n$ integers. In one move you can choose any $a_i$ and divide it by $2$ rounding down (in other words, in one move you can set $a_i := \lfloor\frac{a_i}{2}\rfloor$). You can perform such an operation any (possibly, zero) number of times with any $a_i$. Your task is to calculate the minimum possible number of operations required to obtain at least $k$ equal numbers in the array. Don't forget that it is possible to have $a_i = 0$ after some operations, thus the answer always exists. -----Input----- The first line of the input contains two integers $n$ and $k$ ($1 \le k \le n \le 2 \cdot 10^5$) — the number of elements in the array and the number of equal numbers required. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 2 \cdot 10^5$), where $a_i$ is the $i$-th element of $a$. -----Output----- Print one integer — the minimum possible number of operations required to obtain at least $k$ equal numbers in the array. -----Examples----- Input 5 3 1 2 2 4 5 Output 1 Input 5 3 1 2 3 4 5 Output 2 Input 5 3 1 2 3 3 3 Output 0
[ "5 3\n1 2 2 4 5\n", "5 3\n1 2 3 4 5\n", "5 3\n1 2 3 3 3\n", "1 1\n1337\n", "50 2\n72548 51391 1788 171949 148789 151619 19225 8774 52484 74830 20086 51129 151145 87650 108005 112019 126739 124087 158096 59027 34500 87415 115058 194160 171792 136832 1114 112592 171746 199013 101484 182930 185656 154861 19145...
[ "1\n", "2\n", "0\n", "0\n", "12\n", "0\n", "0\n", "79\n", "3\n", "7\n" ]
1
stdio
In this Kata, we are going to determine if the count of each of the characters in a string can be equal if we remove a single character from that string. For example: ``` solve('abba') = false -- if we remove any character, the count of each character will not be equal. solve('abbba') = true -- if we remove one b, the count of each character becomes 2. solve('aaaa') = true -- if we remove one character, the remaining characters have same count. solve('wwwf') = true -- if we remove f, the remaining letters have same count. ``` More examples in the test cases. Empty string is not tested. Good luck! Write your solution by modifying this code: ```python def solve(s): ``` Your solution should implemented in the function "solve". The inputs will be passed to it and it should return the correct solution. Now solve the problem and return the code.
[]
[]
1
stdio
In some other world, today is the day before Christmas Eve. Mr. Takaha is buying N items at a department store. The regular price of the i-th item (1 \leq i \leq N) is p_i yen (the currency of Japan). He has a discount coupon, and can buy one item with the highest price for half the regular price. The remaining N-1 items cost their regular prices. What is the total amount he will pay? -----Constraints----- - 2 \leq N \leq 10 - 100 \leq p_i \leq 10000 - p_i is an even number. -----Input----- Input is given from Standard Input in the following format: N p_1 p_2 : p_N -----Output----- Print the total amount Mr. Takaha will pay. -----Sample Input----- 3 4980 7980 6980 -----Sample Output----- 15950 The 7980-yen item gets the discount and the total is 4980 + 7980 / 2 + 6980 = 15950 yen. Note that outputs such as 15950.0 will be judged as Wrong Answer.
[ "3\n4980\n7980\n6980\n", "4\n4320\n4320\n4320\n4320\n", "2\n100\n100\n", "10\n10000\n10000\n10000\n10000\n10000\n10000\n10000\n10000\n10000\n10000\n", "5\n958\n5068\n2200\n8118\n4030\n", "6\n798\n3972\n7548\n2966\n4556\n1280\n", "7\n7132\n5170\n808\n8052\n806\n3680\n3820\n", "8\n3468\n1436\n912\n5896\...
[ "15950\n", "15120\n", "150\n", "95000\n", "16315\n", "17346\n", "25442\n", "23132\n", "35231\n", "57638\n" ]
1
stdio
Welcome young Jedi! In this Kata you must create a function that takes an amount of US currency in `cents`, and returns a dictionary/hash which shows the least amount of coins used to make up that amount. The only coin denominations considered in this exercise are: `Pennies (1¢), Nickels (5¢), Dimes (10¢) and Quarters (25¢)`. Therefor the dictionary returned should contain exactly 4 key/value pairs. Notes: * If the function is passed either 0 or a negative number, the function should return the dictionary with all values equal to 0. * If a float is passed into the function, its value should be be rounded down, and the resulting dictionary should never contain fractions of a coin. ## Examples ``` loose_change(56) ==> {'Nickels': 1, 'Pennies': 1, 'Dimes': 0, 'Quarters': 2} loose_change(-435) ==> {'Nickels': 0, 'Pennies': 0, 'Dimes': 0, 'Quarters': 0} loose_change(4.935) ==> {'Nickels': 0, 'Pennies': 4, 'Dimes': 0, 'Quarters': 0} ``` Write your solution by modifying this code: ```python def loose_change(cents): ``` Your solution should implemented in the function "loose_change". The inputs will be passed to it and it should return the correct solution. Now solve the problem and return the code.
[]
[]
1
stdio
Mahmoud has an array a consisting of n integers. He asked Ehab to find another array b of the same length such that: b is lexicographically greater than or equal to a. b_{i} ≥ 2. b is pairwise coprime: for every 1 ≤ i < j ≤ n, b_{i} and b_{j} are coprime, i. e. GCD(b_{i}, b_{j}) = 1, where GCD(w, z) is the greatest common divisor of w and z. Ehab wants to choose a special array so he wants the lexicographically minimal array between all the variants. Can you find it? An array x is lexicographically greater than an array y if there exists an index i such than x_{i} > y_{i} and x_{j} = y_{j} for all 1 ≤ j < i. An array x is equal to an array y if x_{i} = y_{i} for all 1 ≤ i ≤ n. -----Input----- The first line contains an integer n (1 ≤ n ≤ 10^5), the number of elements in a and b. The second line contains n integers a_1, a_2, ..., a_{n} (2 ≤ a_{i} ≤ 10^5), the elements of a. -----Output----- Output n space-separated integers, the i-th of them representing b_{i}. -----Examples----- Input 5 2 3 5 4 13 Output 2 3 5 7 11 Input 3 10 3 7 Output 10 3 7 -----Note----- Note that in the second sample, the array is already pairwise coprime so we printed it.
[ "5\n2 3 5 4 13\n", "3\n10 3 7\n", "5\n7 10 2 5 5\n", "7\n20 9 7 6 7 9 15\n", "10\n5 3 2 2 3 3 3 4 2 5\n", "3\n3 18 2\n", "3\n3 18 2\n", "7\n20 9 7 6 7 9 15\n", "5\n7 10 2 5 5\n", "10\n5 3 2 2 3 3 3 4 2 5\n" ]
[ "2 3 5 7 11 ", "10 3 7 ", "7 10 3 11 13 ", "20 9 7 11 13 17 19 ", "5 3 2 7 11 13 17 19 23 29 ", "3 19 2 ", "3 19 2 ", "20 9 7 11 13 17 19 ", "7 10 3 11 13 ", "5 3 2 7 11 13 17 19 23 29 " ]
1
stdio
You are given two positive integers ```a``` and ```b```. You can perform the following operations on ```a``` so as to obtain ```b``` : ``` (a-1)/2 (if (a-1) is divisible by 2) a/2 (if a is divisible by 2) a*2 ``` ```b``` will always be a power of 2. You are to write a function ```operation(a,b)``` that efficiently returns the minimum number of operations required to transform ```a``` into ```b```. For example : ``` operation(2,8) -> 2 2*2 = 4 4*2 = 8 operation(9,2) -> 2 (9-1)/2 = 4 4/2 = 2 operation(1024,1024) -> 0 ``` Write your solution by modifying this code: ```python def operation(a,b): ``` Your solution should implemented in the function "operation". The inputs will be passed to it and it should return the correct solution. Now solve the problem and return the code.
[]
[]
1
stdio
Dreamoon likes sequences very much. So he created a problem about the sequence that you can't find in OEIS: You are given two integers d, m, find the number of arrays a, satisfying the following constraints: * The length of a is n, n ≥ 1 * 1 ≤ a_1 < a_2 < ... < a_n ≤ d * Define an array b of length n as follows: b_1 = a_1, ∀ i > 1, b_i = b_{i - 1} ⊕ a_i, where ⊕ is the bitwise exclusive-or (xor). After constructing an array b, the constraint b_1 < b_2 < ... < b_{n - 1} < b_n should hold. Since the number of possible arrays may be too large, you need to find the answer modulo m. Input The first line contains an integer t (1 ≤ t ≤ 100) denoting the number of test cases in the input. Each of the next t lines contains two integers d, m (1 ≤ d, m ≤ 10^9). Note that m is not necessary the prime! Output For each test case, print the number of arrays a, satisfying all given constrains, modulo m. Example Input 10 1 1000000000 2 999999999 3 99999998 4 9999997 5 999996 6 99995 7 9994 8 993 9 92 10 1 Output 1 3 5 11 17 23 29 59 89 0
[ "10\n1 1000000000\n2 999999999\n3 99999998\n4 9999997\n5 999996\n10 99995\n7 9994\n8 993\n9 92\n10 1\n", "10\n1 1000000000\n2 999999999\n3 99999998\n4 9999997\n5 999996\n10 99995\n7 9994\n8 993\n12 92\n19 1\n", "10\n1 1000000000\n2 999999999\n3 99999998\n4 9999997\n5 999996\n6 99995\n5 9994\n8 993\n9 92\n10 1\n...
[ "1\n3\n5\n11\n17\n119\n29\n59\n89\n0\n", "1\n3\n5\n11\n17\n119\n29\n59\n87\n0\n", "1\n3\n5\n11\n17\n23\n17\n59\n89\n0\n", "1\n3\n5\n11\n89\n119\n29\n59\n89\n0\n", "1\n3\n5\n11\n17\n119\n89\n59\n87\n0\n", "1\n3\n5\n11\n17\n119\n11\n59\n89\n0\n", "1\n3\n5\n11\n17\n119\n11\n179\n89\n0\n", "1\n3\n5\n11\n1...
1
stdio
Welcome to PC Koshien, players. Physical condition management is important to participate in the event. It is said that at the turn of the season when the temperature fluctuates greatly, it puts a strain on the body and it is easy to catch a cold. The day you should be careful about is the day when the difference between the maximum temperature and the minimum temperature is the largest. When the maximum and minimum temperatures of a day are given for 7 days, create a program that outputs the value obtained by subtracting the minimum temperature from the maximum temperature for each day. input Input data is given in the following format. a1 b1 a2 b2 :: a7 b7 The input consists of 7 lines, and line i is given an integer representing the maximum temperature ai (-40 ≤ ai ≤ 40) and the minimum temperature bi (-40 ≤ bi ≤ 40) on day i. On all days, the maximum temperature ai is always above the minimum temperature bi. output Output the temperature difference for 7 days in 7 lines. Example Input 30 19 39 20 19 18 25 20 22 21 23 10 10 -10 Output 11 19 1 5 1 13 20
[ "30 19\n39 20\n19 18\n4 20\n22 21\n23 10\n10 -10", "30 19\n39 20\n19 18\n4 20\n22 21\n23 10\n15 -10", "30 19\n39 1\n19 18\n4 20\n22 21\n23 10\n15 -10", "30 19\n39 1\n19 18\n2 20\n22 21\n23 10\n15 -10", "30 19\n39 1\n19 18\n2 20\n43 21\n23 10\n15 -10", "30 31\n39 1\n19 18\n2 20\n43 21\n23 10\n15 -10", "3...
[ "11\n19\n1\n-16\n1\n13\n20\n", "11\n19\n1\n-16\n1\n13\n25\n", "11\n38\n1\n-16\n1\n13\n25\n", "11\n38\n1\n-18\n1\n13\n25\n", "11\n38\n1\n-18\n22\n13\n25\n", "-1\n38\n1\n-18\n22\n13\n25\n", "-1\n38\n1\n-18\n22\n13\n28\n", "-1\n37\n1\n-18\n22\n13\n28\n", "-1\n37\n1\n-21\n22\n13\n28\n", "-1\n39\n1\n-2...
1
stdio
The only difference between easy and hard versions is the number of elements in the array. You are given an array $a$ consisting of $n$ integers. In one move you can choose any $a_i$ and divide it by $2$ rounding down (in other words, in one move you can set $a_i := \lfloor\frac{a_i}{2}\rfloor$). You can perform such an operation any (possibly, zero) number of times with any $a_i$. Your task is to calculate the minimum possible number of operations required to obtain at least $k$ equal numbers in the array. Don't forget that it is possible to have $a_i = 0$ after some operations, thus the answer always exists. -----Input----- The first line of the input contains two integers $n$ and $k$ ($1 \le k \le n \le 50$) — the number of elements in the array and the number of equal numbers required. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 2 \cdot 10^5$), where $a_i$ is the $i$-th element of $a$. -----Output----- Print one integer — the minimum possible number of operations required to obtain at least $k$ equal numbers in the array. -----Examples----- Input 5 3 1 2 2 4 5 Output 1 Input 5 3 1 2 3 4 5 Output 2 Input 5 3 1 2 3 3 3 Output 0
[ "5 3\n1 2 2 4 5\n", "5 3\n1 2 3 4 5\n", "5 3\n1 2 3 3 3\n", "1 1\n1337\n", "50 2\n72548 51391 1788 171949 148789 151619 19225 8774 52484 74830 20086 51129 151145 87650 108005 112019 126739 124087 158096 59027 34500 87415 115058 194160 171792 136832 1114 112592 171746 199013 101484 182930 185656 154861 19145...
[ "1\n", "2\n", "0\n", "0\n", "12\n", "0\n", "0\n", "79\n", "3\n", "7\n" ]
1
stdio
Many people choose to obfuscate their email address when displaying it on the Web. One common way of doing this is by substituting the `@` and `.` characters for their literal equivalents in brackets. Example 1: ``` user_name@example.com => user_name [at] example [dot] com ``` Example 2: ``` af5134@borchmore.edu => af5134 [at] borchmore [dot] edu ``` Example 3: ``` jim.kuback@ennerman-hatano.com => jim [dot] kuback [at] ennerman-hatano [dot] com ``` Using the examples above as a guide, write a function that takes an email address string and returns the obfuscated version as a string that replaces the characters `@` and `.` with `[at]` and `[dot]`, respectively. >Notes >* Input (`email`) will always be a string object. Your function should return a string. >* Change only the `@` and `.` characters. >* Email addresses may contain more than one `.` character. >* Note the additional whitespace around the bracketed literals in the examples! Write your solution by modifying this code: ```python def obfuscate(email): ``` Your solution should implemented in the function "obfuscate". The inputs will be passed to it and it should return the correct solution. Now solve the problem and return the code.
[]
[]
1
stdio
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 you have some good ones left, in order to prepare for battle: ```python anyArrows([{'range': 5}, {'range': 10, 'damaged': True}, {'damaged': True}]) ``` If an arrow in the quiver does not have a damaged status, it means it's new. The expected result is a boolean, indicating whether you have any good arrows left. Reference: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions Write your solution by modifying this code: ```python def any_arrows(arrows): ``` Your solution should implemented in the function "any_arrows". The inputs will be passed to it and it should return the correct solution. Now solve the problem and return the code.
[]
[]
1
stdio
In this Kata, you will sort elements in an array by decreasing frequency of elements. If two elements have the same frequency, sort them by increasing value. More examples in test cases. Good luck! Please also try [Simple time difference](https://www.codewars.com/kata/5b76a34ff71e5de9db0000f2) Write your solution by modifying this code: ```python def solve(arr): ``` Your solution should implemented in the function "solve". The inputs will be passed to it and it should return the correct solution. Now solve the problem and return the code.
[]
[]
1
stdio
The Bitlandians are quite weird people. They do everything differently. They have a different alphabet so they have a different definition for a string. A Bitlandish string is a string made only of characters "0" and "1". BitHaval (the mayor of Bitland) loves to play with Bitlandish strings. He takes some Bitlandish string a, and applies several (possibly zero) operations to it. In one operation the mayor may take any two adjacent characters of a string, define one of them as x and the other one as y. Then he calculates two values p and q: p = x xor y, q = x or y. Then he replaces one of the two taken characters by p and the other one by q. The xor operation means the bitwise excluding OR operation. The or operation is the bitwise OR operation. So for example one operation can transform string 11 to string 10 or to string 01. String 1 cannot be transformed into any other string. You've got two Bitlandish strings a and b. Your task is to check if it is possible for BitHaval to transform string a to string b in several (possibly zero) described operations. -----Input----- The first line contains Bitlandish string a, the second line contains Bitlandish string b. The strings can have different lengths. It is guaranteed that the given strings only consist of characters "0" and "1". The strings are not empty, their length doesn't exceed 10^6. -----Output----- Print "YES" if a can be transformed into b, otherwise print "NO". Please do not print the quotes. -----Examples----- Input 11 10 Output YES Input 1 01 Output NO Input 000 101 Output NO
[ "11\n10\n", "1\n01\n", "000\n101\n", "1101\n1111\n", "11000001\n00000001\n", "01\n10\n", "0000\n1110\n", "010101\n101010\n", "0\n1\n", "1\n1\n" ]
[ "YES\n", "NO\n", "NO\n", "YES\n", "YES\n", "YES\n", "NO\n", "YES\n", "NO\n", "YES\n" ]
1
stdio
There is a sequence of length N: A_1, A_2, ..., A_N. Initially, this sequence is a permutation of 1, 2, ..., N. On this sequence, Snuke can perform the following operation: - Choose K consecutive elements in the sequence. Then, replace the value of each chosen element with the minimum value among the chosen elements. Snuke would like to make all the elements in this sequence equal by repeating the operation above some number of times. Find the minimum number of operations required. It can be proved that, Under the constraints of this problem, this objective is always achievable. -----Constraints----- - 2 \leq K \leq N \leq 100000 - A_1, A_2, ..., A_N is a permutation of 1, 2, ..., N. -----Input----- Input is given from Standard Input in the following format: N K A_1 A_2 ... A_N -----Output----- Print the minimum number of operations required. -----Sample Input----- 4 3 2 3 1 4 -----Sample Output----- 2 One optimal strategy is as follows: - In the first operation, choose the first, second and third elements. The sequence A becomes 1, 1, 1, 4. - In the second operation, choose the second, third and fourth elements. The sequence A becomes 1, 1, 1, 1.
[ "4 3\n2 3 1 4\n", "3 3\n1 2 3\n", "8 3\n7 3 1 8 4 6 2 5\n", "41705 41588\n7198 23692 39349 9892 1877 19724 36302 33493 22770 36290 5198 7205 28563 39786 15777 6040 35953 7875 28544 11079 6640 25135 16516 12101 34504 35587 31865 11502 20848 24646 18981 22184 14365 11667 22002 35354 29276 38560 34643 32439 3470...
[ "2\n", "1\n", "4\n", "2\n", "4\n", "3\n", "55080\n", "48352\n", "1\n", "1\n" ]
1
stdio
Given a sorted array of numbers, return the summary of its ranges. ## Examples ```python summary_ranges([1, 2, 3, 4]) == ["1->4"] summary_ranges([1, 1, 1, 1, 1]) == ["1"] summary_ranges([0, 1, 2, 5, 6, 9]) == ["0->2", "5->6", "9"] summary_ranges([0, 1, 2, 3, 3, 3, 4, 5, 6, 7]) == ["0->7"] summary_ranges([0, 1, 2, 3, 3, 3, 4, 4, 5, 6, 7, 7, 9, 9, 10]) == ["0->7", "9->10"] summary_ranges([-2, 0, 1, 2, 3, 3, 3, 4, 4, 5, 6, 7, 7, 9, 9, 10, 12]) == ["-2", "0->7", "9->10", "12"] ``` Write your solution by modifying this code: ```python def summary_ranges(nums): ``` Your solution should implemented in the function "summary_ranges". The inputs will be passed to it and it should return the correct solution. Now solve the problem and return the code.
[]
[]
1
stdio
The preferred way to generate user login in Polygon is to concatenate a prefix of the user's first name and a prefix of their last name, in that order. Each prefix must be non-empty, and any of the prefixes can be the full name. Typically there are multiple possible logins for each person. You are given the first and the last name of a user. Return the alphabetically earliest login they can get (regardless of other potential Polygon users). As a reminder, a prefix of a string s is its substring which occurs at the beginning of s: "a", "ab", "abc" etc. are prefixes of string "{abcdef}" but "b" and 'bc" are not. A string a is alphabetically earlier than a string b, if a is a prefix of b, or a and b coincide up to some position, and then a has a letter that is alphabetically earlier than the corresponding letter in b: "a" and "ab" are alphabetically earlier than "ac" but "b" and "ba" are alphabetically later than "ac". -----Input----- The input consists of a single line containing two space-separated strings: the first and the last names. Each character of each string is a lowercase English letter. The length of each string is between 1 and 10, inclusive. -----Output----- Output a single string — alphabetically earliest possible login formed from these names. The output should be given in lowercase as well. -----Examples----- Input harry potter Output hap Input tom riddle Output tomr
[ "harry potter\n", "tom riddle\n", "a qdpinbmcrf\n", "wixjzniiub ssdfodfgap\n", "z z\n", "ertuyivhfg v\n", "asdfghjkli ware\n", "udggmyop ze\n", "fapkdme rtzxovx\n", "mybiqxmnqq l\n" ]
[ "hap\n", "tomr\n", "aq\n", "wis\n", "zz\n", "ertuv\n", "asdfghjkliw\n", "udggmyopz\n", "fapkdmer\n", "ml\n" ]
1
stdio
# Feynman's squares Richard Phillips Feynman was a well-known American physicist and a recipient of the Nobel Prize in Physics. He worked in theoretical physics and pioneered the field of quantum computing. Recently, an old farmer found some papers and notes that are believed to have belonged to Feynman. Among notes about mesons and electromagnetism, there was a napkin where he wrote a simple puzzle: "how many different squares are there in a grid of NxN squares?". For example, when N=2, the answer is 5: the 2x2 square itself, plus the four 1x1 squares in its corners: # Task You have to write a function ```python def count_squares(n): ``` that solves Feynman's question in general. The input to your function will always be a positive integer. #Examples ```python count_squares(1) = 1 count_squares(2) = 5 count_squares(3) = 14 ``` (Adapted from the Sphere Online Judge problem SAMER08F by Diego Satoba) Write your solution by modifying this code: ```python def count_squares(n): ``` Your solution should implemented in the function "count_squares". The inputs will be passed to it and it should return the correct solution. Now solve the problem and return the code.
[]
[]
1
stdio
An integer N is a multiple of 9 if and only if the sum of the digits in the decimal representation of N is a multiple of 9. Determine whether N is a multiple of 9. -----Constraints----- - 0 \leq N < 10^{200000} - N is an integer. -----Input----- Input is given from Standard Input in the following format: N -----Output----- If N is a multiple of 9, print Yes; otherwise, print No. -----Sample Input----- 123456789 -----Sample Output----- Yes The sum of these digits is 1+2+3+4+5+6+7+8+9=45, which is a multiple of 9, so 123456789 is a multiple of 9.
[ "123456789\n", "0\n", "31415926535897932384626433832795028841971693993751058209749445923078164062862089986280\n", "1\n", "845410686144136511766870859775922809470967375409140663034349040140125188651172413937318920019664667953295078213144836814997819687095284094776471908733234531157216900474939162928952648128...
[ "Yes\n", "Yes\n", "No\n", "No\n", "No\n", "No\n", "No\n", "No\n", "Yes\n", "Yes\n" ]
1
stdio
Think of New York as a rectangular grid consisting of N vertical avenues numerated from 1 to N and M horizontal streets numerated 1 to M. C friends are staying at C hotels located at some street-avenue crossings. They are going to celebrate birthday of one of them in the one of H restaurants also located at some street-avenue crossings. They also want that the maximum distance covered by one of them while traveling to the restaurant to be minimum possible. Help friends choose optimal restaurant for a celebration. Suppose that the distance between neighboring crossings are all the same equal to one kilometer. -----Input----- The first line contains two integers N и M — size of the city (1 ≤ N, M ≤ 10^9). In the next line there is a single integer C (1 ≤ C ≤ 10^5) — the number of hotels friends stayed at. Following C lines contain descriptions of hotels, each consisting of two coordinates x and y (1 ≤ x ≤ N, 1 ≤ y ≤ M). The next line contains an integer H — the number of restaurants (1 ≤ H ≤ 10^5). Following H lines contain descriptions of restaurants in the same format. Several restaurants and hotels may be located near the same crossing. -----Output----- In the first line output the optimal distance. In the next line output index of a restaurant that produces this optimal distance. If there are several possibilities, you are allowed to output any of them. -----Examples----- Input 10 10 2 1 1 3 3 2 1 10 4 4 Output 6 2
[ "10 10\n2\n1 1\n3 3\n2\n1 10\n4 4\n", "100 100\n10\n53 20\n97 6\n12 74\n48 92\n97 13\n47 96\n75 32\n69 21\n95 75\n1 54\n10\n36 97\n41 1\n1 87\n39 23\n27 44\n73 97\n1 1\n6 26\n48 3\n5 69\n", "100 100\n10\n86 72\n25 73\n29 84\n34 33\n29 20\n84 83\n41 80\n22 22\n16 89\n77 49\n1\n4 23\n", "100 100\n1\n66 77\n10\n...
[ "6\n2\n", "108\n4\n", "140\n1\n", "9\n6\n", "1999999998\n1\n", "1111110585\n1\n", "657332378\n1\n", "576261778\n1\n", "0\n1\n", "0\n1\n" ]
1
stdio
In this Kata, you will be given a number and your task will be to return the nearest prime number. ```Haskell solve(4) = 3. The nearest primes are 3 and 5. If difference is equal, pick the lower one. solve(125) = 127 ``` We'll be testing for numbers up to `1E10`. `500` tests. More examples in test cases. Good luck! If you like Prime Katas, you will enjoy this Kata: [Simple Prime Streaming](https://www.codewars.com/kata/5a908da30025e995880000e3) Write your solution by modifying this code: ```python def solve(n): ``` Your solution should implemented in the function "solve". The inputs will be passed to it and it should return the correct solution. Now solve the problem and return the code.
[]
[]
1
stdio
There are N rabbits, numbered 1 through N. The i-th (1≤i≤N) rabbit likes rabbit a_i. Note that no rabbit can like itself, that is, a_i≠i. For a pair of rabbits i and j (i<j), we call the pair (i,j) a friendly pair if the following condition is met. * Rabbit i likes rabbit j and rabbit j likes rabbit i. Calculate the number of the friendly pairs. Constraints * 2≤N≤10^5 * 1≤a_i≤N * a_i≠i Input The input is given from Standard Input in the following format: N a_1 a_2 ... a_N Output Print the number of the friendly pairs. Examples Input 4 2 1 4 3 Output 2 Input 3 2 3 1 Output 0 Input 5 5 5 5 5 1 Output 1
[ "3\n3 3 1", "5\n3 5 5 5 1", "5\n5 4 5 2 1", "5\n5 5 5 5 2", "5\n5 5 5 1 1", "4\n3 1 4 3", "5\n5 3 5 1 1", "4\n4 1 4 3", "5\n5 3 5 2 1", "5\n5 5 5 2 1" ]
[ "1\n", "0\n", "2\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n" ]
1
stdio
A string is called diverse if it contains consecutive (adjacent) letters of the Latin alphabet and each letter occurs exactly once. For example, the following strings are diverse: "fced", "xyz", "r" and "dabcef". The following string are not diverse: "az", "aa", "bad" and "babc". Note that the letters 'a' and 'z' are not adjacent. Formally, consider positions of all letters in the string in the alphabet. These positions should form contiguous segment, i.e. they should come one by one without any gaps. And all letters in the string should be distinct (duplicates are not allowed). You are given a sequence of strings. For each string, if it is diverse, print "Yes". Otherwise, print "No". -----Input----- The first line contains integer $n$ ($1 \le n \le 100$), denoting the number of strings to process. The following $n$ lines contains strings, one string per line. Each string contains only lowercase Latin letters, its length is between $1$ and $100$, inclusive. -----Output----- Print $n$ lines, one line per a string in the input. The line should contain "Yes" if the corresponding string is diverse and "No" if the corresponding string is not diverse. You can print each letter in any case (upper or lower). For example, "YeS", "no" and "yES" are all acceptable. -----Example----- Input 8 fced xyz r dabcef az aa bad babc Output Yes Yes Yes Yes No No No No
[ "8\nfced\nxyz\nr\ndabcef\naz\naa\nbad\nbabc\n", "44\nops\ntest\nyes\nno\nac\nbc\ncb\nz\na\nq\nr\nu\nqq\nop\npo\nxu\nux\nxy\nyx\na\nab\nabc\nabcd\nabcde\nabcdef\nabcdefg\nbcdefg\ncdefg\ndefg\nefgd\nefef\nabacaba\nabz\naoi\nioi\ncodeforces\nklmn\nnmlk\nkln\nklmnl\nkmn\nkklmn\nklmnn\naklkmn\n", "1\nf\n", "1\nsho...
[ "Yes\nYes\nYes\nYes\nNo\nNo\nNo\nNo\n", "No\nNo\nNo\nYes\nNo\nYes\nYes\nYes\nYes\nYes\nYes\nYes\nNo\nYes\nYes\nNo\nNo\nYes\nYes\nYes\nYes\nYes\nYes\nYes\nYes\nYes\nYes\nYes\nYes\nYes\nNo\nNo\nNo\nNo\nNo\nNo\nYes\nYes\nNo\nNo\nNo\nNo\nNo\nNo\n", "Yes\n", "No\n", "Yes\nYes\nYes\nYes\nYes\nYes\nYes\nYes\nYes\n...
1
stdio
Tranform of input array of zeros and ones to array in which counts number of continuous ones: [1, 1, 1, 0, 1] -> [3,1] Write your solution by modifying this code: ```python def ones_counter(input): ``` Your solution should implemented in the function "ones_counter". The inputs will be passed to it and it should return the correct solution. Now solve the problem and return the code.
[]
[]
1
stdio
Find the edit distance between given two words s1 and s2. The disntace is the minimum number of single-character edits required to change one word into the other. The edits including the following operations: * insertion: Insert a character at a particular position. * deletion: Delete a character at a particular position. * substitution: Change the character at a particular position to a different character Constraints * 1 ≤ length of s1 ≤ 1000 * 1 ≤ length of s2 ≤ 1000 Input s1 s2 Two words s1 and s2 are given in the first line and the second line respectively. The words will consist of lower case characters. Output Print the edit distance in a line. Examples Input acac acm Output 2 Input icpc icpc Output 0
[ "icpc\nipcc", "`cac\nacm", "icpb\ncbio", "cpci\nipcc", "`cad\nacm", "cpci\nccpi", "`cac\nbcm", "icpc\nccpi", "`cac\nmcb", "ibpc\nccpi" ]
[ "2\n", "3\n", "4\n", "2\n", "3\n", "2\n", "3\n", "2\n", "3\n", "3\n" ]
1
stdio
# Task Given a rectangular `matrix` and integers `a` and `b`, consider the union of the ath row and the bth (both 0-based) column of the `matrix`. Return sum of all elements of that union. # Example For ``` matrix = [[1, 1, 1, 1], [2, 2, 2, 2], [3, 3, 3, 3]] a = 1 and b = 3 ``` the output should be `12`. Here `(2 + 2 + 2 + 2) + (1 + 3) = 12`. # Input/Output - `[input]` 2D integer array `matrix` 2-dimensional array of integers representing a rectangular matrix. Constraints: `1 ≤ matrix.length ≤ 5, 1 ≤ matrix[0].length ≤ 5, 1 ≤ matrix[i][j] ≤ 100.` - `[input]` integer `a` A non-negative integer less than the number of matrix rows. Constraints: `0 ≤ a < matrix.length.` - `[input]` integer `b` A non-negative integer less than the number of matrix columns. Constraints: `0 ≤ b < matrix[i].length. ` - `[output]` an integer Write your solution by modifying this code: ```python def crossing_sum(matrix, row, col): ``` Your solution should implemented in the function "crossing_sum". The inputs will be passed to it and it should return the correct solution. Now solve the problem and return the code.
[]
[]
1
stdio
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 expecting 0 as closest value to zero. Examples: ```code [2, 4, -1, -3] => -1 [5, 2, -2] => None [5, 2, 2] => 2 [13, 0, -6] => 0 ``` Write your solution by modifying this code: ```python def closest(lst): ``` Your solution should implemented in the function "closest". The inputs will be passed to it and it should return the correct solution. Now solve the problem and return the code.
[]
[]
1
stdio
Write a function that takes a number or a string and gives back the number of **permutations without repetitions** that can generated using all of its element.; more on permutations [here](https://en.wikipedia.org/wiki/Permutation). For example, starting with: ``` 1 45 115 "abc" ``` You could respectively generate: ``` 1 45,54 115,151,511 "abc","acb","bac","bca","cab","cba" ``` So you should have, in turn: ```python perms(1)==1 perms(45)==2 perms(115)==3 perms("abc")==6 ``` Write your solution by modifying this code: ```python def perms(element): ``` Your solution should implemented in the function "perms". The inputs will be passed to it and it should return the correct solution. Now solve the problem and return the code.
[]
[]
1
stdio
We have N integers A_1, A_2, ..., A_N. There are \frac{N(N-1)}{2} ways to choose two of them and form a pair. If we compute the product of each of those pairs and sort the results in ascending order, what will be the K-th number in that list? -----Constraints----- - All values in input are integers. - 2 \leq N \leq 2 \times 10^5 - 1 \leq K \leq \frac{N(N-1)}{2} - -10^9 \leq A_i \leq 10^9\ (1 \leq i \leq N) -----Input----- Input is given from Standard Input in the following format: N K A_1 A_2 \dots A_N -----Output----- Print the answer. -----Sample Input----- 4 3 3 3 -4 -2 -----Sample Output----- -6 There are six ways to form a pair. The products of those pairs are 9, -12, -6, -12, -6, 8. Sorting those numbers in ascending order, we have -12, -12, -6, -6, 8, 9. The third number in this list is -6.
[ "4 3\n3 3 -4 -2\n", "10 40\n5 4 3 2 -1 0 0 0 0 0\n", "30 413\n-170202098 -268409015 537203564 983211703 21608710 -443999067 -937727165 -97596546 -372334013 398994917 -972141167 798607104 -949068442 -959948616 37909651 0 886627544 -20098238 0 -948955241 0 -214720580 277222296 -18897162 834475626 0 -425610555 110...
[ "-6\n", "6\n", "448283280358331064\n", "6\n", "-12\n", "528184831018109492\n", "0\n", "476299476577366816\n", "517956905402467891\n", "474217893515068178\n" ]
1
stdio
Joisino is working as a receptionist at a theater. The theater has 100000 seats, numbered from 1 to 100000. According to her memo, N groups of audiences have come so far, and the i-th group occupies the consecutive seats from Seat l_i to Seat r_i (inclusive). How many people are sitting at the theater now? -----Constraints----- - 1≤N≤1000 - 1≤l_i≤r_i≤100000 - No seat is occupied by more than one person. - All input values are integers. -----Input----- Input is given from Standard Input in the following format: N l_1 r_1 : l_N r_N -----Output----- Print the number of people sitting at the theater. -----Sample Input----- 1 24 30 -----Sample Output----- 7 There are 7 people, sitting at Seat 24,25,26,27,28,29 and 30.
[ "1\n24 30\n", "2\n6 8\n3 3\n", "1\n0 30", "2\n6 12\n3 3", "1\n1 30", "2\n6 12\n0 3", "1\n2 30", "2\n6 10\n0 3", "1\n2 0", "2\n6 10\n0 1" ]
[ "7\n", "4\n", "31\n", "8\n", "30\n", "11\n", "29\n", "9\n", "-1\n", "7\n" ]
1
stdio
`late_clock` function receive an array with 4 digits and should return the latest time that can be built with those digits. The time should be in `HH:MM` format. Examples: ``` [1, 9, 8, 3] => 19:38 [9, 1, 2, 5] => 21:59 ``` You can suppose the input is correct and you can build from it a correct 24-hour time. Write your solution by modifying this code: ```python def late_clock(digits): ``` Your solution should implemented in the function "late_clock". The inputs will be passed to it and it should return the correct solution. Now solve the problem and return the code.
[]
[]
1
stdio
There are N stones arranged in a row. The i-th stone from the left is painted in the color C_i. Snuke will perform the following operation zero or more times: * Choose two stones painted in the same color. Repaint all the stones between them, with the color of the chosen stones. Find the number of possible final sequences of colors of the stones, modulo 10^9+7. Constraints * 1 \leq N \leq 2\times 10^5 * 1 \leq C_i \leq 2\times 10^5(1\leq i\leq N) * All values in input are integers. Input Input is given from Standard Input in the following format: N C_1 : C_N Output Print the number of possible final sequences of colors of the stones, modulo 10^9+7. Examples Input 5 1 2 1 2 2 Output 3 Input 6 4 2 5 4 2 4 Output 5 Input 7 1 3 1 2 3 3 2 Output 5
[ "6\n4\n2\n2\n4\n2\n4", "5\n1\n4\n1\n2\n2", "6\n4\n2\n2\n1\n2\n4", "6\n4\n1\n2\n1\n2\n4", "7\n1\n2\n1\n2\n3\n3\n2", "6\n3\n2\n2\n2\n2\n4", "7\n1\n3\n1\n2\n1\n3\n2", "7\n1\n3\n1\n2\n4\n3\n2", "7\n1\n3\n1\n2\n2\n3\n2", "6\n4\n2\n5\n4\n2\n1" ]
[ "5\n", "2\n", "3\n", "4\n", "6\n", "1\n", "7\n", "5\n", "5\n", "3\n" ]
1
stdio
Eugeny has array a = a_1, a_2, ..., a_{n}, consisting of n integers. Each integer a_{i} equals to -1, or to 1. Also, he has m queries: Query number i is given as a pair of integers l_{i}, r_{i} (1 ≤ l_{i} ≤ r_{i} ≤ n). The response to the query will be integer 1, if the elements of array a can be rearranged so as the sum a_{l}_{i} + a_{l}_{i} + 1 + ... + a_{r}_{i} = 0, otherwise the response to the query will be integer 0. Help Eugeny, answer all his queries. -----Input----- The first line contains integers n and m (1 ≤ n, m ≤ 2·10^5). The second line contains n integers a_1, a_2, ..., a_{n} (a_{i} = -1, 1). Next m lines contain Eugene's queries. The i-th line contains integers l_{i}, r_{i} (1 ≤ l_{i} ≤ r_{i} ≤ n). -----Output----- Print m integers — the responses to Eugene's queries in the order they occur in the input. -----Examples----- Input 2 3 1 -1 1 1 1 2 2 2 Output 0 1 0 Input 5 5 -1 1 1 1 -1 1 1 2 3 3 5 2 5 1 5 Output 0 1 0 1 0
[ "2 3\n1 -1\n1 1\n1 2\n2 2\n", "5 5\n-1 1 1 1 -1\n1 1\n2 3\n3 5\n2 5\n1 5\n", "3 3\n1 1 1\n2 2\n1 1\n1 1\n", "4 4\n-1 -1 -1 -1\n1 3\n1 2\n1 2\n1 1\n", "5 5\n-1 -1 -1 -1 -1\n1 1\n1 1\n3 4\n1 1\n1 4\n", "6 6\n-1 -1 1 -1 -1 1\n1 1\n3 4\n1 1\n1 1\n1 3\n1 4\n", "7 7\n-1 -1 -1 1 -1 -1 -1\n1 1\n2 7\n1 3\n1 5\n4...
[ "0\n1\n0\n", "0\n1\n0\n1\n0\n", "0\n0\n0\n", "0\n0\n0\n0\n", "0\n0\n0\n0\n0\n", "0\n1\n0\n0\n0\n1\n", "0\n0\n0\n0\n0\n0\n1\n", "0\n0\n0\n0\n0\n0\n0\n0\n", "0\n1\n0\n0\n0\n0\n0\n1\n0\n", "1\n1\n1\n0\n0\n1\n1\n0\n0\n0\n" ]
1
stdio
Read problems statements in Russian also. Chef plays with the sequence of N numbers. During a single move Chef is able to choose a non-decreasing subsequence of the sequence and to remove it from the sequence. Help him to remove all the numbers in the minimal number of moves. ------ Input ------ The first line of each test case contains a single N denoting the number of integers in the given sequence. The second line contains N space-separated integers A_{1}, A_{2}, ..., A_{N} denoting the given sequence ------ Output ------ Output a single line containing the minimal number of moves required to remove all the numbers from the sequence. ------ Constraints ------ $1 ≤ N ≤ 100000.$ $1 ≤ A_{i} ≤ 100000.$   ------ Scoring ------ Subtask 1 (10 points): N = 10 Subtask 2 (40 points): N = 2000 Subtask 2 (50 points): N = 100000 ----- Sample Input 1 ------ 3 1 2 3 ----- Sample Output 1 ------ 1 ----- explanation 1 ------ ----- Sample Input 2 ------ 4 4 1 2 3 ----- Sample Output 2 ------ 2 ----- explanation 2 ------
[ "3 \n1 2 3", "4\n4 1 2 3", "3 \n1 2 5", "4\n4 1 3 3", "3 \n5 1 0", "4\n20 -1 -2 -4", "3 \n1 2 8", "4\n4 1 5 3", "3 \n1 1 8", "4\n4 0 5 3" ]
[ "1", "2", "1\n", "2\n", "3\n", "4\n", "1\n", "2\n", "1\n", "2\n" ]
1
stdio
>When no more interesting kata can be resolved, I just choose to create the new kata, to solve their own, to enjoy the process --myjinxin2015 said # Description: Given a string `str` that contains some "(" or ")". Your task is to find the longest substring in `str`(all brackets in the substring are closed). The result is the length of the longest substring. For example: ``` str = "()()(" findLongest(str) === 4 "()()" is the longest substring ``` # Note: - All inputs are valid. - If no such substring found, return 0. - Please pay attention to the performance of code. ;-) - In the performance test(100000 brackets str x 100 testcases), the time consuming of each test case should be within 35ms. This means, your code should run as fast as a rocket ;-) # Some Examples ``` findLongest("()") === 2 findLongest("()(") === 2 findLongest("()()") === 4 findLongest("()()(") === 4 findLongest("(()())") === 6 findLongest("(()(())") === 6 findLongest("())(()))") === 4 findLongest("))((") === 0 findLongest("") === 0 ``` Write your solution by modifying this code: ```python def find_longest(st): ``` Your solution should implemented in the function "find_longest". The inputs will be passed to it and it should return the correct solution. Now solve the problem and return the code.
[]
[]
1
stdio
Once a Mathematician was trapped by military people during a world war with his forty colleagues. The colleagues were without any weapons, only the mathematician had a knife. And with no weapons they were not able to fight with the military, so they decided to kill themselves rather than being killed by military. They all decided that they will stand in a circle and the every third person will kill himself but the mathematician didn't like this idea and had no intention of killing himself. He tried to calculate where should he stand so that he is the last one left. Note:- Instead of every 3rd position it will be every 2nd position and of course the number of colleagues will be much more than 40. Input:- The first line of input is an integer N that specifies the number of test cases. After that every line contains an integer X which is the number of colleagues. Output:- For each test case generate a line containing the position of the colleagues who survives. Assume that the colleagues have serial numbers from 1 to n and that the counting starts with person 1, i.e., the first person leaving is the one with number 2. Constraints:- 1 ≤ N ≤ 1000 5 ≤ X ≤ 100000000 SAMPLE INPUT 4 5 11 45 23987443 SAMPLE OUTPUT 3 7 27 14420455
[ "934\n48171068\n63138680\n25597136\n5610719\n22559303\n19374620\n52609147\n76485130\n4119341\n84687324\n74124384\n29214349\n76525070\n27296334\n62086857\n7062292\n70121510\n32711240\n40766945\n75911566\n64205975\n68575226\n83591193\n54443307\n63540837\n4289505\n8767969\n70478582\n7243533\n39723966\n78096030\n726371...
[ "29233273\n59168497\n17639841\n2832831\n11564175\n5194809\n38109431\n18752533\n4044379\n35156921\n14031041\n24874267\n18832413\n21038237\n57064851\n5735977\n6025293\n31868049\n14425027\n17605405\n61303087\n2932725\n32964659\n41777751\n59972811\n190403\n758723\n6739437\n6098459\n12339069\n21974333\n11056593\n1762582...
1
stdio
Write a function to split a string and convert it into an array of words. For example: ```python "Robin Singh" ==> ["Robin", "Singh"] "I love arrays they are my favorite" ==> ["I", "love", "arrays", "they", "are", "my", "favorite"] ``` Write your solution by modifying this code: ```python def string_to_array(s): ``` Your solution should implemented in the function "string_to_array". The inputs will be passed to it and it should return the correct solution. Now solve the problem and return the code.
[]
[]
1
stdio
There are n points on a straight line, and the i-th point among them is located at x_{i}. All these coordinates are distinct. Determine the number m — the smallest number of points you should add on the line to make the distances between all neighboring points equal. -----Input----- The first line contains a single integer n (3 ≤ n ≤ 100 000) — the number of points. The second line contains a sequence of integers x_1, x_2, ..., x_{n} ( - 10^9 ≤ x_{i} ≤ 10^9) — the coordinates of the points. All these coordinates are distinct. The points can be given in an arbitrary order. -----Output----- Print a single integer m — the smallest number of points you should add on the line to make the distances between all neighboring points equal. -----Examples----- Input 3 -5 10 5 Output 1 Input 6 100 200 400 300 600 500 Output 0 Input 4 10 9 0 -1 Output 8 -----Note----- In the first example you can add one point with coordinate 0. In the second example the distances between all neighboring points are already equal, so you shouldn't add anything.
[ "3\n-5 10 5\n", "6\n100 200 400 300 600 500\n", "4\n10 9 0 -1\n", "3\n1 4 7\n", "3\n1 4 6\n", "3\n1 2 6\n", "3\n1 3 6\n", "4\n1 2 3 4\n", "3\n-1000000000 -999999999 1000000000\n", "3\n-1000000000 999999999 1000000000\n" ]
[ "1\n", "0\n", "8\n", "0\n", "3\n", "3\n", "3\n", "0\n", "1999999998\n", "1999999998\n" ]
1
stdio
Your task is to return the number of visible dots on a die after it has been rolled(that means the total count of dots that would not be touching the table when rolled) 6, 8, 10, 12, 20 sided dice are the possible inputs for "numOfSides" topNum is equal to the number that is on top, or the number that was rolled. for this exercise, all opposite faces add up to be 1 more than the total amount of sides Example: 6 sided die would have 6 opposite 1, 4 opposite 3, and so on. for this exercise, the 10 sided die starts at 1 and ends on 10. Note: topNum will never be greater than numOfSides Write your solution by modifying this code: ```python def totalAmountVisible(topNum, numOfSides): ``` Your solution should implemented in the function "totalAmountVisible". The inputs will be passed to it and it should return the correct solution. Now solve the problem and return the code.
[]
[]
1
stdio
For a dictionary $M$ that stores elements formed by a pair of a string key and an integer value, perform a sequence of the following operations. Note that each key in $M$ must be unique. * insert($key$, $x$): Insert an element formed by a pair of $key$ and $x$ to $M$. If there is an element with $key$, replace the corresponding value with $x$. * get($key$): Print the value with the specified $key$. Constraints * $1 \leq q \leq 200,000$ * $1 \leq x \leq 1,000,000,000$ * $1 \leq $ length of $key$ $ \leq 20$ * $key$ consits of lower-case letter * For a get operation, the element with the specified key exists in $M$. Input The input is given in the following format. $q$ $query_1$ $query_2$ : $query_q$ Each query $query_i$ is given by 0 $key$ $x$ or 1 $key$ where the first digits 0, 1 and 2 represent insert and get operations respectively. Output For each get operation, print an integer in a line. Example Input 7 0 blue 4 0 red 1 0 white 5 1 red 1 blue 0 black 8 1 black Output 1 4 8
[ "7\n0 blue 4\n0 red 1\n0 white 5\n1 red\n1 blue\n0 black 16\n1 black", "7\n0 blue 4\n0 red 1\n0 white 3\n1 red\n1 blue\n0 black 8\n1 black", "7\n0 blue 5\n0 red 1\n0 white 5\n1 red\n1 blue\n0 black 16\n1 black", "7\n0 blue 4\n0 red 1\n0 white 5\n1 red\n1 blue\n0 black 11\n1 black", "7\n0 blue 4\n0 red 1\n0 ...
[ "1\n4\n16\n", "1\n4\n8\n", "1\n5\n16\n", "1\n4\n11\n", "1\n4\n5\n", "1\n4\n13\n", "1\n4\n6\n", "1\n7\n16\n", "1\n4\n", "2\n4\n" ]
1
stdio
It is September 9 in Japan now. You are given a two-digit integer N. Answer the question: Is 9 contained in the decimal notation of N? -----Constraints----- - 10≤N≤99 -----Input----- Input is given from Standard Input in the following format: N -----Output----- If 9 is contained in the decimal notation of N, print Yes; if not, print No. -----Sample Input----- 29 -----Sample Output----- Yes The one's digit of 29 is 9.
[ "29\n", "72\n", "91\n", "1", "69", "115", "84", "0", "181", "168" ]
[ "Yes\n", "No\n", "Yes\n", "No\n", "Yes\n", "No\n", "No\n", "No\n", "No\n", "No\n" ]
1
stdio
Harry Potter has a difficult homework. Given a rectangular table, consisting of n × m cells. Each cell of the table contains the integer. Harry knows how to use two spells: the first spell change the sign of the integers in the selected row, the second — in the selected column. Harry's task is to make non-negative the sum of the numbers in each row and each column using these spells. Alone, the boy can not cope. Help the young magician! Input The first line contains two integers n and m (1 ≤ n, m ≤ 100) — the number of rows and the number of columns. Next n lines follow, each contains m integers: j-th integer in the i-th line is ai, j (|ai, j| ≤ 100), the number in the i-th row and j-th column of the table. The rows of the table numbered from 1 to n. The columns of the table numbered from 1 to m. Output In the first line print the number a — the number of required applications of the first spell. Next print a space-separated integers — the row numbers, you want to apply a spell. These row numbers must be distinct! In the second line print the number b — the number of required applications of the second spell. Next print b space-separated integers — the column numbers, you want to apply a spell. These column numbers must be distinct! If there are several solutions are allowed to print any of them. Examples Input 4 1 -1 -1 -1 -1 Output 4 1 2 3 4 0 Input 2 4 -1 -1 -1 2 1 1 1 1 Output 1 1 1 4
[ "20 10\n-6 8 -4 -1 3 10 2 5 4 7\n6 9 9 8 -8 3 7 9 7 3\n0 10 10 1 -3 -4 5 -1 10 10\n8 9 10 4 7 10 10 3 9 10\n3 0 8 -5 0 5 7 8 -5 4\n9 -6 7 10 -4 -2 7 0 -5 9\n-10 7 -4 5 10 8 3 7 1 8\n-3 -6 0 3 2 1 5 9 8 9\n4 -3 5 3 4 -6 9 5 3 4\n2 -4 0 -5 -2 0 5 5 9 7\n-4 -1 5 1 10 9 4 -8 6 6\n2 3 6 8 9 6 5 -7 -2 -5\n6 4 -1 4 4 2 7 ...
[ "0 \n0 \n", "1 1 \n0 \n", "0 \n22 5 6 8 9 11 13 16 18 20 27 29 30 36 37 40 45 46 47 52 55 64 65 \n", "6 2 3 4 7 8 10 \n1 1 \n", "2 1 4 \n4 5 6 8 10 \n", "19 3 5 9 14 24 30 34 36 39 40 41 44 48 50 51 54 56 63 67 \n0 \n", "0 \n0 \n", "0 \n0 \n", "0 \n22 5 6 8 9 11 13 16 18 20 27 29 30 36 37 40 45 46 4...
1
stdio
You are given two positive integers $n$ and $k$. Print the $k$-th positive integer that is not divisible by $n$. For example, if $n=3$, and $k=7$, then all numbers that are not divisible by $3$ are: $1, 2, 4, 5, 7, 8, 10, 11, 13 \dots$. The $7$-th number among them is $10$. -----Input----- The first line contains an integer $t$ ($1 \le t \le 1000$) — the number of test cases in the input. Next, $t$ test cases are given, one per line. Each test case is two positive integers $n$ ($2 \le n \le 10^9$) and $k$ ($1 \le k \le 10^9$). -----Output----- For each test case print the $k$-th positive integer that is not divisible by $n$. -----Example----- Input 6 3 7 4 12 2 1000000000 7 97 1000000000 1000000000 2 1 Output 10 15 1999999999 113 1000000001 1
[ "6\n3 7\n4 12\n2 1000000000\n7 97\n1000000000 1000000000\n2 1\n", "7\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n", "1\n841 4832526\n", "7\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n", "1\n841 4832526\n", "1\n870 4832526\n", "6\n2 7\n4 12\n2 1000000000\n7 97\n1000000000 1000000000\n2 1\n", "1\n1718 4832526\n", "6\...
[ "10\n15\n1999999999\n113\n1000000001\n1\n", "1\n1\n1\n1\n1\n1\n1\n", "4838279\n", "1\n1\n1\n1\n1\n1\n1\n", "4838279\n", "\n4838087\n", "\n13\n\n15\n\n1999999999\n\n113\n\n1000000001\n\n1\n", "\n4835340\n", "\n13\n\n15\n\n1333333333\n\n113\n\n1000000001\n\n1\n", "\n3126275\n" ]
1
stdio
Santosh has a farm at Byteland. He has a very big family to look after. His life takes a sudden turn and he runs into a financial crisis. After giving all the money he has in his hand, he decides to sell his plots. The speciality of his land is that it is rectangular in nature. Santosh comes to know that he will get more money if he sells square shaped plots. So keeping this in mind, he decides to divide his land into minimum possible number of square plots, such that each plot has the same area, and the plots divide the land perfectly. He does this in order to get the maximum profit out of this. So your task is to find the minimum number of square plots with the same area, that can be formed out of the rectangular land, such that they divide it perfectly. -----Input----- - The first line of the input contains $T$, the number of test cases. Then $T$ lines follow. - The first and only line of each test case contains two space-separated integers, $N$ and $M$, the length and the breadth of the land, respectively. -----Output----- For each test case, print the minimum number of square plots with equal area, such that they divide the farm land perfectly, in a new line. -----Constraints----- $1 \le T \le 20$ $1 \le M \le 10000$ $1 \le N \le 10000$ -----Sample Input:----- 2 10 15 4 6 -----SampleOutput:----- 6 6
[ "2\n10 15\n4 6\n", "2\n10 15\n4 1", "2\n10 28\n4 1", "2\n15 28\n4 1", "2\n8 28\n4 1", "2\n8 12\n8 1", "2\n8 12\n3 1", "2\n8 12\n2 1", "2\n9 12\n2 1", "2\n9 12\n2 2" ]
[ "6\n6\n", "6\n4\n", "70\n4\n", "420\n4\n", "14\n4\n", "6\n8\n", "6\n3\n", "6\n2\n", "12\n2\n", "12\n1\n" ]
1
stdio
There are N squares aligned in a row. The i-th square from the left contains an integer a_i. Initially, all the squares are white. Snuke will perform the following operation some number of times: * Select K consecutive squares. Then, paint all of them white, or paint all of them black. Here, the colors of the squares are overwritten. After Snuke finishes performing the operation, the score will be calculated as the sum of the integers contained in the black squares. Find the maximum possible score. Constraints * 1≤N≤10^5 * 1≤K≤N * a_i is an integer. * |a_i|≤10^9 Input The input is given from Standard Input in the following format: N K a_1 a_2 ... a_N Output Print the maximum possible score. Examples Input 5 3 -10 10 -10 10 -10 Output 10 Input 4 2 10 -10 -10 10 Output 20 Input 1 1 -10 Output 0 Input 10 5 5 -4 -5 -8 -4 7 2 -4 0 7 Output 17
[ "1 1\n-16", "5 3\n-10 10 -18 10 -10", "4 2\n7 -10 -10 10", "4 2\n7 -6 -10 12", "4 2\n7 -6 -10 20", "4 2\n9 -1 -10 20", "4 2\n13 -1 -10 20", "4 2\n3 -1 -10 20", "4 3\n3 -1 -10 20", "4 3\n3 -1 -1 20" ]
[ "0\n", "10\n", "17\n", "19\n", "27\n", "29\n", "33\n", "23\n", "20\n", "21\n" ]
1
stdio
Long ago, when Petya was a schoolboy, he was very much interested in the Petr# language grammar. During one lesson Petya got interested in the following question: how many different continuous substrings starting with the sbegin and ending with the send (it is possible sbegin = send), the given string t has. Substrings are different if and only if their contents aren't equal, their positions of occurence don't matter. Petya wasn't quite good at math, that's why he couldn't count this number. Help him! Input The input file consists of three lines. The first line contains string t. The second and the third lines contain the sbegin and send identificators, correspondingly. All three lines are non-empty strings consisting of lowercase Latin letters. The length of each string doesn't exceed 2000 characters. Output Output the only number — the amount of different substrings of t that start with sbegin and end with send. Examples Input round ro ou Output 1 Input codeforces code forca Output 0 Input abababab a b Output 4 Input aba ab ba Output 1 Note In the third sample there are four appropriate different substrings. They are: ab, abab, ababab, abababab. In the fourth sample identificators intersect.
[ "abcdefghijklmnopqrstuvwxyz\nabc\nxyz\n", "fcgbeabagggfdbacgcaagfbdddefdbcfccfacfffebdgececdabfceadecbgdgdbdadcgfbbaaabcccdefabdfefadfdccbbefbfgcfdadeggggbdadfeadafbaccefdfcbbbadgegbbbcebfbdcfaabddeafbedagbgfdagcccafbddcfafdfaafgefcdceaabggfbaebeaccdfbeeegfdddgfdaagcbdddggcaceadgbddcbdcfddbcddfaebdgcebcbgcacgdeab...
[ "1\n", "12\n", "14\n", "0\n", "1\n", "0\n", "1\n", "0\n", "1\n", "68\n" ]
1
stdio
Example Input 4 5 8 58 85 Output 2970.000000000
[ "4\n5\n8\n58\n152", "4\n5\n8\n55\n152", "4\n5\n20\n55\n152", "4\n5\n15\n58\n85", "4\n5\n8\n58\n171", "4\n5\n9\n55\n152", "4\n2\n11\n55\n152", "4\n5\n17\n55\n152", "4\n5\n15\n58\n7", "4\n5\n10\n58\n171" ]
[ "5181.000000000000000\n", "4945.500000000000000\n", "5887.500000000000000\n", "3285.000000000000000\n", "5808.000000000000000\n", "5024.000000000000000\n", "5082.000000000000000\n", "5652.000000000000000\n", "693.000000000000000\n", "5984.000000000000000\n" ]
1
stdio
Limak is an old brown bear. He often plays poker with his friends. Today they went to a casino. There are n players (including Limak himself) and right now all of them have bids on the table. i-th of them has bid with size ai dollars. Each player can double his bid any number of times and triple his bid any number of times. The casino has a great jackpot for making all bids equal. Is it possible that Limak and his friends will win a jackpot? Input First line of input contains an integer n (2 ≤ n ≤ 105), the number of players. The second line contains n integer numbers a1, a2, ..., an (1 ≤ ai ≤ 109) — the bids of players. Output Print "Yes" (without the quotes) if players can make their bids become equal, or "No" otherwise. Examples Input 4 75 150 75 50 Output Yes Input 3 100 150 250 Output No Note In the first sample test first and third players should double their bids twice, second player should double his bid once and fourth player should both double and triple his bid. It can be shown that in the second sample test there is no way to make all bids equal.
[ "2\n49 42\n", "20\n958692492 954966768 77387000 724664764 101294996 614007760 202904092 555293973 707655552 108023967 73123445 612562357 552908390 914853758 915004122 466129205 122853497 814592742 373389439 818473058\n", "3\n335544320 71744535 71744535\n", "18\n2 3 5 7 11 13 17 19 23 29 31 37 43 47 53 59 67 7...
[ "No", "No", "Yes", "No", "Yes", "Yes", "No", "Yes", "No", "Yes" ]
1
stdio
Let's call a string adorable if its letters can be realigned in such a way that they form two consequent groups of equal symbols (note that different groups must contain different symbols). For example, ababa is adorable (you can transform it to aaabb, where the first three letters form a group of a-s and others — a group of b-s), but cccc is not since in each possible consequent partition letters in these two groups coincide. You're given a string s. Check whether it can be split into two non-empty subsequences such that the strings formed by these subsequences are adorable. Here a subsequence is an arbitrary set of indexes of the string. -----Input----- The only line contains s (1 ≤ |s| ≤ 10^5) consisting of lowercase latin letters. -----Output----- Print «Yes» if the string can be split according to the criteria above or «No» otherwise. Each letter can be printed in arbitrary case. -----Examples----- Input ababa Output Yes Input zzcxx Output Yes Input yeee Output No -----Note----- In sample case two zzcxx can be split into subsequences zc and zxx each of which is adorable. There's no suitable partition in sample case three.
[ "ababa\n", "zzcxx\n", "yeee\n", "a\n", "bbab\n", "abcd\n", "abc\n", "abcdaaaa\n", "aaaaaaaaaaaaaaa\n", "adb\n" ]
[ "Yes\n", "Yes\n", "No\n", "No\n", "No\n", "Yes\n", "No\n", "Yes\n", "No\n", "No\n" ]
1
stdio
Takahashi is drawing a segment on grid paper. From a certain square, a square that is x squares to the right and y squares above, is denoted as square (x, y). When Takahashi draws a segment connecting the lower left corner of square (A, B) and the lower left corner of square (C, D), find the number of the squares crossed by the segment. Here, the segment is said to cross a square if the segment has non-empty intersection with the region within the square, excluding the boundary. Constraints * 1 \leq A, B, C, D \leq 10^9 * At least one of A \neq C and B \neq D holds. Input The input is given from Standard Input in the following format: A B C D Output Print the number of the squares crossed by the segment. Examples Input 1 1 3 4 Output 4 Input 2 3 10 7 Output 8
[ "1 2 3 4", "3 3 10 7", "1 2 6 4", "3 3 10 5", "6 3 10 5", "1 0 11 4", "1 0 15 4", "6 6 3 5", "1 1 15 2", "6 16 3 5" ]
[ "2\n", "10\n", "6\n", "8\n", "4\n", "12\n", "16\n", "3\n", "14\n", "13\n" ]
1
stdio
You are given two positive integers d and s. Find minimal positive integer n which is divisible by d and has sum of digits equal to s. Input The first line contains two positive integers d and s (1 ≤ d ≤ 500, 1 ≤ s ≤ 5000) separated by space. Output Print the required number or -1 if it doesn't exist. Examples Input 13 50 Output 699998 Input 61 2 Output 1000000000000000000000000000001 Input 15 50 Output -1
[ "2 5000\n", "3 5000\n", "182 6\n", "364 4\n", "1 5000\n", "72 72\n", "5 1\n", "500 5000\n", "75 16\n", "212 14\n" ]
[ "699999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999...
1
stdio
A histogram is made of a number of contiguous bars, which have same width. For a given histogram with $N$ bars which have a width of 1 and a height of $h_i$ = $h_1, h_2, ... , h_N$ respectively, find the area of the largest rectangular area. Constraints * $1 \leq N \leq 10^5$ * $0 \leq h_i \leq 10^9$ Input The input is given in the following format. $N$ $h_1$ $h_2$ ... $h_N$ Output Print the area of the largest rectangle. Examples Input 8 2 1 3 5 3 4 2 1 Output 12 Input 3 2 0 1 Output 2
[ "8\n2 1 3 5 3 7 2 1", "3\n3 0 1", "8\n2 1 3 5 3 7 3 1", "3\n5 0 0", "3\n0 0 0", "8\n2 2 3 5 4 7 3 2", "3\n0 0 1", "8\n3 6 3 6 4 7 0 4", "8\n3 6 4 6 4 7 0 4", "3\n2 0 2" ]
[ "12\n", "3\n", "15\n", "5\n", "0\n", "16\n", "1\n", "18\n", "20\n", "2\n" ]
1
stdio
You are given two set of points. The first set is determined by the equation A1x + B1y + C1 = 0, and the second one is determined by the equation A2x + B2y + C2 = 0. Write the program which finds the number of points in the intersection of two given sets. Input The first line of the input contains three integer numbers A1, B1, C1 separated by space. The second line contains three integer numbers A2, B2, C2 separated by space. All the numbers are between -100 and 100, inclusive. Output Print the number of points in the intersection or -1 if there are infinite number of points. Examples Input 1 1 0 2 2 0 Output -1 Input 1 1 0 2 -2 0 Output 1
[ "1 -1 1\n0 0 0\n", "-1 0 0\n-2 1 2\n", "-1 -1 1\n1 1 0\n", "2 2 1\n1 2 0\n", "-1 1 1\n0 1 1\n", "0 -1 -1\n-2 -2 -1\n", "-2 -1 1\n-1 1 1\n", "1 0 0\n0 1 0\n", "1 1 -1\n-1 0 -1\n", "-2 -1 0\n-2 2 2\n" ]
[ "-1", "1", "0", "1", "1", "1", "1", "1", "1", "1" ]
1
stdio
Ivan has got an array of n non-negative integers a_1, a_2, ..., a_{n}. Ivan knows that the array is sorted in the non-decreasing order. Ivan wrote out integers 2^{a}_1, 2^{a}_2, ..., 2^{a}_{n} on a piece of paper. Now he wonders, what minimum number of integers of form 2^{b} (b ≥ 0) need to be added to the piece of paper so that the sum of all integers written on the paper equalled 2^{v} - 1 for some integer v (v ≥ 0). Help Ivan, find the required quantity of numbers. -----Input----- The first line contains integer n (1 ≤ n ≤ 10^5). The second input line contains n space-separated integers a_1, a_2, ..., a_{n} (0 ≤ a_{i} ≤ 2·10^9). It is guaranteed that a_1 ≤ a_2 ≤ ... ≤ a_{n}. -----Output----- Print a single integer — the answer to the problem. -----Examples----- Input 4 0 1 1 1 Output 0 Input 1 3 Output 3 -----Note----- In the first sample you do not need to add anything, the sum of numbers already equals 2^3 - 1 = 7. In the second sample you need to add numbers 2^0, 2^1, 2^2.
[ "4\n0 1 1 1\n", "1\n3\n", "1\n0\n", "1\n2000000000\n", "1\n1\n", "26\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 2\n", "1\n2000000000\n", "26\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 2\n", "1\n0\n", "1\n1\n" ]
[ "0\n", "3\n", "0\n", "2000000000\n", "1\n", "5\n", "2000000000\n", "5\n", "0\n", "1\n" ]
1
stdio
You are given two integers K and S. Three variable X, Y and Z takes integer values satisfying 0≤X,Y,Z≤K. How many different assignments of values to X, Y and Z are there such that X + Y + Z = S? Constraints * 2≤K≤2500 * 0≤S≤3K * K and S are integers. Input The input is given from Standard Input in the following format: K S Output Print the number of the triples of X, Y and Z that satisfy the condition. Examples Input 2 2 Output 6 Input 5 15 Output 1
[ "3 2", "5 7", "3 3", "4 7", "3 4", "1 7", "2 5", "4 0", "6 7", "17 4" ]
[ "6\n", "27\n", "10\n", "18\n", "12\n", "0\n", "3\n", "1\n", "33\n", "15\n" ]
1
stdio
Gerald got a very curious hexagon for his birthday. The boy found out that all the angles of the hexagon are equal to $120^{\circ}$. Then he measured the length of its sides, and found that each of them is equal to an integer number of centimeters. There the properties of the hexagon ended and Gerald decided to draw on it. He painted a few lines, parallel to the sides of the hexagon. The lines split the hexagon into regular triangles with sides of 1 centimeter. Now Gerald wonders how many triangles he has got. But there were so many of them that Gerald lost the track of his counting. Help the boy count the triangles. -----Input----- The first and the single line of the input contains 6 space-separated integers a_1, a_2, a_3, a_4, a_5 and a_6 (1 ≤ a_{i} ≤ 1000) — the lengths of the sides of the hexagons in centimeters in the clockwise order. It is guaranteed that the hexagon with the indicated properties and the exactly such sides exists. -----Output----- Print a single integer — the number of triangles with the sides of one 1 centimeter, into which the hexagon is split. -----Examples----- Input 1 1 1 1 1 1 Output 6 Input 1 2 1 2 1 2 Output 13 -----Note----- This is what Gerald's hexagon looks like in the first sample: $\theta$ And that's what it looks like in the second sample: $A$
[ "1 1 1 1 1 1\n", "1 2 1 2 1 2\n", "2 4 5 3 3 6\n", "45 19 48 18 46 21\n", "66 6 65 6 66 5\n", "7 5 4 8 4 5\n", "3 2 1 4 1 2\n", "7 1 7 3 5 3\n", "9 2 9 3 8 3\n", "1 6 1 5 2 5\n" ]
[ "6\n", "13\n", "83\n", "6099\n", "5832\n", "175\n", "25\n", "102\n", "174\n", "58\n" ]
1
stdio
There are N stones, numbered 1, 2, \ldots, N. For each i (1 \leq i \leq N), the height of Stone i is h_i. There is a frog who is initially on Stone 1. He will repeat the following action some number of times to reach Stone N: * If the frog is currently on Stone i, jump to Stone i + 1 or Stone i + 2. Here, a cost of |h_i - h_j| is incurred, where j is the stone to land on. Find the minimum possible total cost incurred before the frog reaches Stone N. Constraints * All values in input are integers. * 2 \leq N \leq 10^5 * 1 \leq h_i \leq 10^4 Input Input is given from Standard Input in the following format: N h_1 h_2 \ldots h_N Output Print the minimum possible total cost incurred. Examples Input 4 10 30 40 20 Output 30 Input 2 10 10 Output 0 Input 6 30 10 60 10 60 50 Output 40
[ "6\n30 10 60 10 60 57", "4\n10 14 40 20", "2\n18 10", "4\n5 14 40 20", "2\n33 10", "6\n30 12 60 10 60 9", "2\n9 10", "6\n30 12 60 17 60 9", "2\n9 18", "6\n30 12 60 33 60 9" ]
[ "33\n", "10\n", "8\n", "15\n", "23\n", "21\n", "1\n", "31\n", "9\n", "63\n" ]
1
stdio
###Task: You have to write a function `pattern` which creates the following pattern (see examples) up to the desired number of rows. * If the Argument is 0 or a Negative Integer then it should return "" i.e. empty string. * If any even number is passed as argument then the pattern should last upto the largest odd number which is smaller than the passed even number. ###Examples: pattern(9): 1 333 55555 7777777 999999999 pattern(6): 1 333 55555 ```Note: There are no spaces in the pattern``` ```Hint: Use \n in string to jump to next line``` Write your solution by modifying this code: ```python def pattern(n): ``` Your solution should implemented in the function "pattern". The inputs will be passed to it and it should return the correct solution. Now solve the problem and return the code.
[]
[]
1
stdio
You have stumbled across the divine pleasure that is owning a dog and a garden. Now time to pick up all the cr@p! :D Given a 2D array to represent your garden, you must find and collect all of the dog cr@p - represented by '@'. You will also be given the number of bags you have access to (bags), and the capactity of a bag (cap). If there are no bags then you can't pick anything up, so you can ignore cap. You need to find out if you have enough capacity to collect all the cr@p and make your garden clean again. If you do, return 'Clean', else return 'Cr@p'. Watch out though - if your dog is out there ('D'), he gets very touchy about being watched. If he is there you need to return 'Dog!!'. For example: x= [[\_,\_,\_,\_,\_,\_] [\_,\_,\_,\_,@,\_] [@,\_,\_,\_,\_,\_]] bags = 2, cap = 2 return --> 'Clean' Write your solution by modifying this code: ```python def crap(garden, bags, cap): ``` Your solution should implemented in the function "crap". The inputs will be passed to it and it should return the correct solution. Now solve the problem and return the code.
[]
[]
1
stdio
# Task Find the integer from `a` to `b` (included) with the greatest number of divisors. For example: ``` divNum(15, 30) ==> 24 divNum(1, 2) ==> 2 divNum(0, 0) ==> 0 divNum(52, 156) ==> 120 ``` If there are several numbers that have the same (maximum) number of divisors, the smallest among them should be returned. Return the string `"Error"` if `a > b`. Write your solution by modifying this code: ```python def div_num(a, b): ``` Your solution should implemented in the function "div_num". The inputs will be passed to it and it should return the correct solution. Now solve the problem and return the code.
[]
[]
1
stdio
Johnny needs to make a rectangular box for his physics class project. He has bought P cm of wire and S cm^{2} of special paper. He would like to use all the wire (for the 12 edges) and paper (for the 6 sides) to make the box. What is the largest volume of the box that Johnny can make? ------ Input ------ The first line contains t, the number of test cases (about 10). Then t test cases follow. Each test case contains two integers P and S in a line (1 ≤ P ≤ 40000, 1 ≤ S ≤ 20000). You may assume that there always exists an optimal solution for the given input cases. ------ Output ------ For each test case, print a real number that is the largest volume of the box that Johnny can make, rounded to two decimal places. ----- Sample Input 1 ------ 2 20 14 20 16 ----- Sample Output 1 ------ 3.00 4.15 ----- explanation 1 ------ First case: the dimensions of the largest box may be 3, 1 and 1. Second case: the dimensions of the largest box may be 7/3, 4/3 and 4/3.
[ "2\n20 14\n20 16", "2\n20 14\n20 14", "2\n32 14\n20 14", "2\n20 14\n36 14", "2\n20 8\n36 14", "2\n28 8\n36 14", "2\n20 16\n20 14", "2\n32 20\n20 14", "2\n20 14\n20 10", "2\n20 16\n20 10" ]
[ "3.00\n4.15", "3.0\n3.0\n", "1.63\n3.0\n", "3.0\n1.43\n", "0.88\n1.43\n", "0.6\n1.43\n", "4.15\n3.0\n", "3.43\n3.0\n", "3.0\n1.42\n", "4.15\n1.42\n" ]
1
stdio
Alice became interested in periods of integer numbers. We say positive $X$ integer number is periodic with length $L$ if there exists positive integer number $P$ with $L$ digits such that $X$ can be written as $PPPP…P$. For example: $X = 123123123$ is periodic number with length $L = 3$ and $L = 9$ $X = 42424242$ is periodic number with length $L = 2,L = 4$ and $L = 8$ $X = 12345$ is periodic number with length $L = 5$ For given positive period length $L$ and positive integer number $A$, Alice wants to find smallest integer number $X$ strictly greater than $A$ that is periodic with length L. -----Input----- First line contains one positive integer number $L \ (1 \leq L \leq 10^5)$ representing length of the period. Second line contains one positive integer number $A \ (1 \leq A \leq 10^{100 000})$. -----Output----- One positive integer number representing smallest positive number that is periodic with length $L$ and is greater than $A$. -----Examples----- Input 3 123456 Output 124124 Input 3 12345 Output 100100 -----Note----- In first example 124124 is the smallest number greater than 123456 that can be written with period L = 3 (P = 124). In the second example 100100 is the smallest number greater than 12345 with period L = 3 (P=100)
[ "3\n123456\n", "3\n12345\n", "3\n776554554\n", "3\n145023023\n", "3\n3021001003\n", "10\n6277\n", "10\n9969441321\n", "3\n352474474\n", "3\n220330330\n", "3\n29939939929\n" ]
[ "124124\n", "100100\n", "776776776\n", "145145145\n", "100100100100\n", "1000000000\n", "9969441322\n", "353353353\n", "221221221\n", "100100100100\n" ]
1
stdio
# Introduction The first century spans from the **year 1** *up to* and **including the year 100**, **The second** - *from the year 101 up to and including the year 200*, etc. # Task : Given a year, return the century it is in. Write your solution by modifying this code: ```python def century(year): ``` Your solution should implemented in the function "century". The inputs will be passed to it and it should return the correct solution. Now solve the problem and return the code.
[]
[]
1
stdio
Given some positive integers, I wish to print the integers such that all take up the same width by adding a minimum number of leading zeroes. No leading zeroes shall be added to the largest integer. For example, given `1, 23, 2, 17, 102`, I wish to print out these numbers as follows: ```python 001 023 002 017 102 ``` Write a function `print_nums(n1, n2, n3, ...)` that takes a variable number of arguments and returns the string to be printed out. Write your solution by modifying this code: ```python def print_nums(*args): ``` Your solution should implemented in the function "print_nums". The inputs will be passed to it and it should return the correct solution. Now solve the problem and return the code.
[]
[]
1
stdio
"Contestant who earns a score equal to or greater than the k-th place finisher's score will advance to the next round, as long as the contestant earns a positive score..." — an excerpt from contest rules. A total of n participants took part in the contest (n ≥ k), and you already know their scores. Calculate how many participants will advance to the next round. Input The first line of the input contains two integers n and k (1 ≤ k ≤ n ≤ 50) separated by a single space. The second line contains n space-separated integers a1, a2, ..., an (0 ≤ ai ≤ 100), where ai is the score earned by the participant who got the i-th place. The given sequence is non-increasing (that is, for all i from 1 to n - 1 the following condition is fulfilled: ai ≥ ai + 1). Output Output the number of participants who advance to the next round. Examples Input 8 5 10 9 8 7 7 7 5 5 Output 6 Input 4 2 0 0 0 0 Output 0 Note In the first example the participant on the 5th place earned 7 points. As the participant on the 6th place also earned 7 points, there are 6 advancers. In the second example nobody got a positive score.
[ "8 3\n10 9 8 7 7 7 5 5\n", "8 7\n10 9 8 7 7 7 5 5\n", "50 25\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n", "49 8\n99 98 98 96 92 92 90 89 89 86 86 85 83 80 79 76 74 69 67 67 58 56 55 51 49 47 47 46 45 41 41 40 39 34 34 33 25 23 18 15 13 13 11 9 5 4 3 ...
[ "3\n", "8\n", "26\n", "9\n", "6\n", "0\n", "14\n", "2\n", "1\n", "12\n" ]
1
stdio
In mathematics, a [Diophantine equation](https://en.wikipedia.org/wiki/Diophantine_equation) is a polynomial equation, usually with two or more unknowns, such that only the integer solutions are sought or studied. In this kata we want to find all integers `x, y` (`x >= 0, y >= 0`) solutions of a diophantine equation of the form: #### x^(2) - 4 \* y^(2) = n (where the unknowns are `x` and `y`, and `n` is a given positive number) in decreasing order of the positive xi. If there is no solution return `[]` or `"[]" or ""`. (See "RUN SAMPLE TESTS" for examples of returns). ## Examples: ``` solEquaStr(90005) --> "[[45003, 22501], [9003, 4499], [981, 467], [309, 37]]" solEquaStr(90002) --> "[]" ``` ## Hint: x^(2) - 4 \* y^(2) = (x - 2\*y) \* (x + 2\*y) Write your solution by modifying this code: ```python def sol_equa(n): ``` Your solution should implemented in the function "sol_equa". The inputs will be passed to it and it should return the correct solution. Now solve the problem and return the code.
[]
[]
1
stdio
Find the largest square number not exceeding N. Here, a square number is an integer that can be represented as the square of an integer. -----Constraints----- - 1 \leq N \leq 10^9 - N is an integer. -----Input----- Input is given from Standard Input in the following format: N -----Output----- Print the largest square number not exceeding N. -----Sample Input----- 10 -----Sample Output----- 9 10 is not square, but 9 = 3 × 3 is. Thus, we print 9.
[ "10\n", "81\n", "271828182\n", "70", "12", "115087508", "135", "167542739", "7", "16" ]
[ "9\n", "81\n", "271821169\n", "64\n", "9\n", "115068529\n", "121\n", "167521249\n", "4\n", "16\n" ]
1
stdio
Given two integer arrays where the second array is a shuffled duplicate of the first array with one element missing, find the missing element. Please note, there may be duplicates in the arrays, so checking if a numerical value exists in one and not the other is not a valid solution. ``` find_missing([1, 2, 2, 3], [1, 2, 3]) => 2 ``` ``` find_missing([6, 1, 3, 6, 8, 2], [3, 6, 6, 1, 2]) => 8 ``` The first array will always have at least one element. Write your solution by modifying this code: ```python def find_missing(arr1, arr2): ``` Your solution should implemented in the function "find_missing". The inputs will be passed to it and it should return the correct solution. Now solve the problem and return the code.
[]
[]
1
stdio
Normally, we decompose a number into binary digits by assigning it with powers of 2, with a coefficient of `0` or `1` for each term: `25 = 1*16 + 1*8 + 0*4 + 0*2 + 1*1` The choice of `0` and `1` is... not very binary. We shall perform the *true* binary expansion by expanding with powers of 2, but with a coefficient of `1` or `-1` instead: `25 = 1*16 + 1*8 + 1*4 - 1*2 - 1*1` Now *this* looks binary. --- Given any positive number `n`, expand it using the true binary expansion, and return the result as an array, from the most significant digit to the least significant digit. `true_binary(25) == [1,1,1,-1,-1]` It should be trivial (the proofs are left as an exercise to the reader) to see that: - Every odd number has infinitely many true binary expansions - Every even number has no true binary expansions Hence, `n` will always be an odd number, and you should return the *least* true binary expansion for any `n`. Also, note that `n` can be very, very large, so your code should be very efficient. Write your solution by modifying this code: ```python def true_binary(n): ``` Your solution should implemented in the function "true_binary". The inputs will be passed to it and it should return the correct solution. Now solve the problem and return the code.
[]
[]
1
stdio
It’s still hot every day, but September has already come. It’s autumn according to the calendar. Looking around, I see two red dragonflies at rest on the wall in front of me. It’s autumn indeed. When two red dragonflies’ positional information as measured from the end of the wall is given, make a program to calculate the distance between their heads. Input The input is given in the following format. $x_1$ $x_2$ The input line provides dragonflies’ head positions $x_1$ and $x_2$ ($0 \leq x_1, x_2 \leq 100$) as integers. Output Output the distance between the two red dragonflies in a line. Examples Input 20 30 Output 10 Input 50 25 Output 25 Input 25 25 Output 0
[ "50 12", "25 13", "27 30", "50 0", "25 17", "27 22", "58 0", "25 11", "27 37", "26 0" ]
[ "38\n", "12\n", "3\n", "50\n", "8\n", "5\n", "58\n", "14\n", "10\n", "26\n" ]
1
stdio
Shichi-Go-San (literally "Seven-Five-Three") is a traditional event in a certain country to celebrate the growth of seven-, five- and three-year-old children. Takahashi is now X years old. Will his growth be celebrated in Shichi-Go-San this time? -----Constraints----- - 1 ≤ X ≤ 9 - X is an integer. -----Input----- Input is given from Standard Input in the following format: X -----Output----- If Takahashi's growth will be celebrated, print YES; if it will not, print NO. -----Sample Input----- 5 -----Sample Output----- YES The growth of a five-year-old child will be celebrated.
[ "5\n", "6\n", "1\n", "2\n", "3\n", "4\n", "7\n", "8\n", "9\n", "11" ]
[ "YES\n", "NO\n", "NO\n", "NO\n", "YES\n", "NO\n", "YES\n", "NO\n", "NO\n", "NO\n" ]
1
stdio
Two students of AtCoder Kindergarten are fighting over candy packs. There are three candy packs, each of which contains a, b, and c candies, respectively. Teacher Evi is trying to distribute the packs between the two students so that each student gets the same number of candies. Determine whether it is possible. Note that Evi cannot take candies out of the packs, and the whole contents of each pack must be given to one of the students. -----Constraints----- - 1 ≦ a, b, c ≦ 100 -----Input----- The input is given from Standard Input in the following format: a b c -----Output----- If it is possible to distribute the packs so that each student gets the same number of candies, print Yes. Otherwise, print No. -----Sample Input----- 10 30 20 -----Sample Output----- Yes Give the pack with 30 candies to one student, and give the two packs with 10 and 20 candies to the other. Then, each gets 30 candies.
[ "10 30 20\n", "30 30 100\n", "56 25 31\n", "106 25 31", "4 24 20", "10 29 20", "30 47 100", "8 25 31", "4 29 20", "30 26 100" ]
[ "Yes\n", "No\n", "Yes\n", "No\n", "Yes\n", "No\n", "No\n", "No\n", "No\n", "No\n" ]
1
stdio
Complete the function which returns the weekday according to the input number: * `1` returns `"Sunday"` * `2` returns `"Monday"` * `3` returns `"Tuesday"` * `4` returns `"Wednesday"` * `5` returns `"Thursday"` * `6` returns `"Friday"` * `7` returns `"Saturday"` * Otherwise returns `"Wrong, please enter a number between 1 and 7"` Write your solution by modifying this code: ```python def whatday(num): ``` Your solution should implemented in the function "whatday". The inputs will be passed to it and it should return the correct solution. Now solve the problem and return the code.
[]
[]
1
stdio
On her way to programming school tiger Dasha faced her first test — a huge staircase! [Image] The steps were numbered from one to infinity. As we know, tigers are very fond of all striped things, it is possible that it has something to do with their color. So on some interval of her way she calculated two values — the number of steps with even and odd numbers. You need to check whether there is an interval of steps from the l-th to the r-th (1 ≤ l ≤ r), for which values that Dasha has found are correct. -----Input----- In the only line you are given two integers a, b (0 ≤ a, b ≤ 100) — the number of even and odd steps, accordingly. -----Output----- In the only line print "YES", if the interval of steps described above exists, and "NO" otherwise. -----Examples----- Input 2 3 Output YES Input 3 1 Output NO -----Note----- In the first example one of suitable intervals is from 1 to 5. The interval contains two even steps — 2 and 4, and three odd: 1, 3 and 5.
[ "2 3\n", "3 1\n", "5 4\n", "9 9\n", "85 95\n", "0 1\n", "89 25\n", "74 73\n", "62 39\n", "57 57\n" ]
[ "YES\n", "NO\n", "YES\n", "YES\n", "NO\n", "YES\n", "NO\n", "YES\n", "NO\n", "YES\n" ]
1
stdio
Given an integer `n`, find two integers `a` and `b` such that: ```Pearl A) a >= 0 and b >= 0 B) a + b = n C) DigitSum(a) + Digitsum(b) is maximum of all possibilities. ``` You will return the digitSum(a) + digitsum(b). ``` For example: solve(29) = 11. If we take 15 + 14 = 29 and digitSum = 1 + 5 + 1 + 4 = 11. There is no larger outcome. ``` `n` will not exceed `10e10`. More examples in test cases. Good luck! Write your solution by modifying this code: ```python def solve(n): ``` Your solution should implemented in the function "solve". The inputs will be passed to it and it should return the correct solution. Now solve the problem and return the code.
[]
[]
1
stdio
Takahashi is going to set a 3-character password. How many possible passwords are there if each of its characters must be a digit between 1 and N (inclusive)? -----Constraints----- - 1 \leq N \leq 9 - N is an integer. -----Input----- Input is given from Standard Input in the following format: N -----Output----- Print the number of possible passwords. -----Sample Input----- 2 -----Sample Output----- 8 There are eight possible passwords: 111, 112, 121, 122, 211, 212, 221, and 222.
[ "2\n", "1\n", "3\n", "4\n", "5\n", "6\n", "7\n", "8\n", "9\n", "4" ]
[ "8\n", "1\n", "27\n", "64\n", "125\n", "216\n", "343\n", "512\n", "729\n", "64\n" ]
1
stdio
Given a sequence of numbers a1, a2, a3, ..., an, find the maximum sum of a contiguous subsequence of those numbers. Note that, a subsequence of one element is also a contiquous subsequence. Input The input consists of multiple datasets. Each data set consists of: n a1 a2 . . an You can assume that 1 ≤ n ≤ 5000 and -100000 ≤ ai ≤ 100000. The input end with a line consisting of a single 0. Output For each dataset, print the maximum sum in a line. Example Input 7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0 Output 19 14 1001
[ "7\n-5\n-2\n6\n4\n9\n-6\n-7\n13\n1\n2\n3\n2\n-2\n-1\n1\n2\n3\n2\n1\n-2\n1\n3\n1000\n-200\n201\n0", "7\n-5\n-2\n6\n4\n9\n-6\n-7\n13\n1\n2\n3\n2\n-2\n-1\n1\n1\n3\n2\n1\n-2\n1\n3\n1000\n-200\n201\n0", "7\n-5\n-2\n6\n8\n9\n-6\n-7\n13\n1\n2\n3\n2\n-2\n-1\n1\n1\n3\n2\n1\n-2\n1\n3\n1000\n-200\n201\n0", "7\n-5\n-2\n6...
[ "19\n14\n1001\n", "19\n13\n1001\n", "23\n13\n1001\n", "23\n13\n1000\n", "19\n12\n1001\n", "19\n14\n1000\n", "18\n13\n1001\n", "19\n12\n1000\n", "23\n12\n1000\n", "19\n15\n1001\n" ]
1
stdio
We have A balls with the string S written on each of them and B balls with the string T written on each of them. From these balls, Takahashi chooses one with the string U written on it and throws it away. Find the number of balls with the string S and balls with the string T that we have now. -----Constraints----- - S, T, and U are strings consisting of lowercase English letters. - The lengths of S and T are each between 1 and 10 (inclusive). - S \not= T - S=U or T=U. - 1 \leq A,B \leq 10 - A and B are integers. -----Input----- Input is given from Standard Input in the following format: S T A B U -----Output----- Print the answer, with space in between. -----Sample Input----- red blue 3 4 red -----Sample Output----- 2 4 Takahashi chose a ball with red written on it and threw it away. Now we have two balls with the string S and four balls with the string T.
[ "red blue\n3 4\nred\n", "red blue\n5 5\nblue\n", "a b\n1 3\na\n", "aaa bbb\n10 10\nbbb\n", "abc arc\n3 6\nabc\n", "zzz xxx\n6 10\nxxx\n", "abcdeabcde opqrsopqrs\n7 2\nabcdeabcde\n", "length depth\n3 1\nlength\n", "rice bread\n3 6\nbread\n", "tea coffee\n4 4\ncoffee\n" ]
[ "2 4\n", "5 4\n", "0 3\n", "10 9\n", "2 6\n", "6 9\n", "6 2\n", "2 1\n", "3 5\n", "4 3\n" ]
1
stdio
Create a function that takes a positive integer and returns the next bigger number that can be formed by rearranging its digits. For example: ``` 12 ==> 21 513 ==> 531 2017 ==> 2071 ``` If the digits can't be rearranged to form a bigger number, return `-1` (or `nil` in Swift): ``` 9 ==> -1 111 ==> -1 531 ==> -1 ``` Write your solution by modifying this code: ```python def next_bigger(n): ``` Your solution should implemented in the function "next_bigger". The inputs will be passed to it and it should return the correct solution. Now solve the problem and return the code.
[]
[]
1
stdio
Alice and Bob have participated to a Rock Off with their bands. A jury of true metalheads rates the two challenges, awarding points to the bands on a scale from 1 to 50 for three categories: Song Heaviness, Originality, and Members' outfits. For each one of these 3 categories they are going to be awarded one point, should they get a better judgement from the jury. No point is awarded in case of an equal vote. You are going to receive two arrays, containing first the score of Alice's band and then those of Bob's. Your task is to find their total score by comparing them in a single line. Example: Alice's band plays a Nirvana inspired grunge and has been rated ``20`` for Heaviness, ``32`` for Originality and only ``18`` for Outfits. Bob listens to Slayer and has gotten a good ``48`` for Heaviness, ``25`` for Originality and a rather honest ``40`` for Outfits. The total score should be followed by a colon ```:``` and by one of the following quotes: if Alice's band wins: ```Alice made "Kurt" proud!``` if Bob's band wins: ```Bob made "Jeff" proud!``` if they end up with a draw: ```that looks like a "draw"! Rock on!``` The solution to the example above should therefore appear like ``'1, 2: Bob made "Jeff" proud!'``. Write your solution by modifying this code: ```python def solve(a, b): ``` Your solution should implemented in the function "solve". The inputs will be passed to it and it should return the correct solution. Now solve the problem and return the code.
[]
[]
1
stdio
Imagine you have an infinite 2D plane with Cartesian coordinate system. Some of the integral points are blocked, and others are not. Two integral points A and B on the plane are 4-connected if and only if: * the Euclidean distance between A and B is one unit and neither A nor B is blocked; * or there is some integral point C, such that A is 4-connected with C, and C is 4-connected with B. Let's assume that the plane doesn't contain blocked points. Consider all the integral points of the plane whose Euclidean distance from the origin is no more than n, we'll name these points special. Chubby Yang wants to get the following property: no special point is 4-connected to some non-special point. To get the property she can pick some integral points of the plane and make them blocked. What is the minimum number of points she needs to pick? Input The first line contains an integer n (0 ≤ n ≤ 4·107). Output Print a single integer — the minimum number of points that should be blocked. Examples Input 1 Output 4 Input 2 Output 8 Input 3 Output 16
[ "11\n", "0\n", "17\n", "18855321\n", "34609610\n", "25\n", "9\n", "40000000\n", "17464436\n", "38450759\n" ]
[ "60\n", "1\n", "96\n", "106661800\n", "195781516\n", "140\n", "48\n", "226274168\n", "98793768\n", "217510336\n" ]
1
stdio
Write a function that takes a positive integer n, sums all the cubed values from 1 to n, and returns that sum. Assume that the input n will always be a positive integer. Examples: ```python sum_cubes(2) > 9 # sum of the cubes of 1 and 2 is 1 + 8 ``` Write your solution by modifying this code: ```python def sum_cubes(n): ``` Your solution should implemented in the function "sum_cubes". The inputs will be passed to it and it should return the correct solution. Now solve the problem and return the code.
[]
[]
1
stdio
AtCoder Inc. has decided to lock the door of its office with a 3-digit PIN code. The company has an N-digit lucky number, S. Takahashi, the president, will erase N-3 digits from S and concatenate the remaining 3 digits without changing the order to set the PIN code. How many different PIN codes can he set this way? Both the lucky number and the PIN code may begin with a 0. Constraints * 4 \leq N \leq 30000 * S is a string of length N consisting of digits. Input Input is given from Standard Input in the following format: N S Output Print the number of different PIN codes Takahashi can set. Examples Input 4 0224 Output 3 Input 6 123123 Output 17 Input 19 3141592653589793238 Output 329
[ "19\n5546189040285140044", "19\n4753841743850076999", "19\n9039528710159876563", "19\n3616863455241776042", "19\n2785343766571511696", "19\n2922045480066417189", "19\n7230040539071200180", "19\n1036710694297327965", "19\n1455506616048969060", "19\n3356521006821128568" ]
[ "273\n", "311\n", "412\n", "322\n", "239\n", "281\n", "292\n", "364\n", "172\n", "210\n" ]
1
stdio
Gru has not been in the limelight for a long time and is, therefore, planning something particularly nefarious. Frustrated by his minions' incapability which has kept him away from the limelight, he has built a transmogrifier — a machine which mutates minions. Each minion has an intrinsic characteristic value (similar to our DNA), which is an integer. The transmogrifier adds an integer K to each of the minions' characteristic value. Gru knows that if the new characteristic value of a minion is divisible by 7, then it will have Wolverine-like mutations. Given the initial characteristic integers of N minions, all of which are then transmogrified, find out how many of them become Wolverine-like. -----Input Format:----- The first line contains one integer, T, which is the number of test cases. Each test case is then described in two lines. The first line contains two integers N and K, as described in the statement. The next line contains N integers, which denote the initial characteristic values for the minions. -----Output Format:----- For each testcase, output one integer in a new line, which is the number of Wolverine-like minions after the transmogrification. -----Constraints:----- - 1 ≤ T ≤ 100 - 1 ≤ N ≤ 100 - 1 ≤ K ≤ 100 - All initial characteristic values lie between 1 and 105, both inclusive. -----Example----- Input: 1 5 10 2 4 1 35 1 Output: 1 -----Explanation:----- After transmogrification, the characteristic values become {12,14,11,45,11}, out of which only 14 is divisible by 7. So only the second minion becomes Wolverine-like.
[ "1\n5 10\n2 4 1 35 1\n", "1\n5 10\n2 4 1 62 1", "1\n5 2\n0 4 1 3 1", "1\n5 20\n2 4 1 62 1", "1\n5 0\n0 4 0 7 1", "1\n5 0\n1 0 0 0 0", "1\n5 10\n2 4 1 3 1", "1\n5 3\n2 4 1 3 1", "1\n5 3\n2 4 0 3 1", "1\n5 3\n0 4 0 3 1" ]
[ "1\n", "1\n", "0\n", "2\n", "3\n", "4\n", "1\n", "1\n", "1\n", "1\n" ]
1
stdio
Given an array $a$ of length $n$, find another array, $b$, of length $n$ such that: for each $i$ $(1 \le i \le n)$ $MEX(\{b_1$, $b_2$, $\ldots$, $b_i\})=a_i$. The $MEX$ of a set of integers is the smallest non-negative integer that doesn't belong to this set. If such array doesn't exist, determine this. -----Input----- The first line contains an integer $n$ ($1 \le n \le 10^5$) — the length of the array $a$. The second line contains $n$ integers $a_1$, $a_2$, $\ldots$, $a_n$ ($0 \le a_i \le i$) — the elements of the array $a$. It's guaranteed that $a_i \le a_{i+1}$ for $1\le i < n$. -----Output----- If there's no such array, print a single line containing $-1$. Otherwise, print a single line containing $n$ integers $b_1$, $b_2$, $\ldots$, $b_n$ ($0 \le b_i \le 10^6$) If there are multiple answers, print any. -----Examples----- Input 3 1 2 3 Output 0 1 2 Input 4 0 0 0 2 Output 1 3 4 0 Input 3 1 1 3 Output 0 2 1 -----Note----- In the second test case, other answers like $[1,1,1,0]$, for example, are valid.
[ "3\n1 2 3\n", "4\n0 0 0 2\n", "3\n1 1 3\n", "7\n0 0 2 2 5 5 6\n", "10\n1 2 3 4 4 4 7 7 7 10\n", "1\n1\n", "1\n0\n", "7\n0 0 2 2 5 5 6\n", "1\n1\n", "10\n1 2 3 4 4 4 7 7 7 10\n" ]
[ "0 1 2 ", "1 3 4 0 ", "0 2 1 ", "1 3 0 4 2 7 5 ", "0 1 2 3 5 6 4 8 9 7 ", "0 ", "1 ", "1 3 0 4 2 7 5\n", "0\n", "0 1 2 3 5 6 4 8 9 7\n" ]
1
stdio
An `non decreasing` number is one containing no two consecutive digits (left to right), whose the first is higer than the second. For example, 1235 is an non decreasing number, 1229 is too, but 123429 isn't. Write a function that finds the number of non decreasing numbers up to `10**N` (exclusive) where N is the input of your function. For example, if `N=3`, you have to count all non decreasing numbers from 0 to 999. You'll definitely need something smarter than brute force for large values of N! Write your solution by modifying this code: ```python def increasing_numbers(n): ``` Your solution should implemented in the function "increasing_numbers". The inputs will be passed to it and it should return the correct solution. Now solve the problem and return the code.
[]
[]
1
stdio
The magic sum of 3s is calculated on an array by summing up odd numbers which include the digit `3`. Write a function `magic_sum` which accepts an array of integers and returns the sum. *Example:* `[3, 12, 5, 8, 30, 13]` results in `16` (`3` + `13`) If the sum cannot be calculated, `0` should be returned. Write your solution by modifying this code: ```python def magic_sum(arr): ``` Your solution should implemented in the function "magic_sum". The inputs will be passed to it and it should return the correct solution. Now solve the problem and return the code.
[]
[]
1
stdio
Limak is a little bear who loves to play. Today he is playing by destroying block towers. He built n towers in a row. The i-th tower is made of h_{i} identical blocks. For clarification see picture for the first sample. Limak will repeat the following operation till everything is destroyed. Block is called internal if it has all four neighbors, i.e. it has each side (top, left, down and right) adjacent to other block or to the floor. Otherwise, block is boundary. In one operation Limak destroys all boundary blocks. His paws are very fast and he destroys all those blocks at the same time. Limak is ready to start. You task is to count how many operations will it take him to destroy all towers. -----Input----- The first line contains single integer n (1 ≤ n ≤ 10^5). The second line contains n space-separated integers h_1, h_2, ..., h_{n} (1 ≤ h_{i} ≤ 10^9) — sizes of towers. -----Output----- Print the number of operations needed to destroy all towers. -----Examples----- Input 6 2 1 4 6 2 2 Output 3 Input 7 3 3 3 1 3 3 3 Output 2 -----Note----- The picture below shows all three operations for the first sample test. Each time boundary blocks are marked with red color. [Image] After first operation there are four blocks left and only one remains after second operation. This last block is destroyed in third operation.
[ "6\n2 1 4 6 2 2\n", "7\n3 3 3 1 3 3 3\n", "7\n5128 5672 5805 5452 5882 5567 5032\n", "10\n1 2 2 3 5 5 5 4 2 1\n", "14\n20 20 20 20 20 20 3 20 20 20 20 20 20 20\n", "50\n3 2 4 3 5 3 4 5 3 2 3 3 3 4 5 4 2 2 3 3 4 4 3 2 3 3 2 3 4 4 5 2 5 2 3 5 4 4 2 2 3 5 2 5 2 2 5 4 5 4\n", "1\n1\n", "1\n1000000000\n", ...
[ "3\n", "2\n", "4\n", "5\n", "5\n", "4\n", "1\n", "1\n", "1\n", "1\n" ]
1
stdio