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
It's March and you just can't seem to get your mind off brackets. However, it is not due to basketball. You need to extract statements within strings that are contained within brackets. You have to write a function that returns a list of statements that are contained within brackets given a string. If the value entered in the function is not a string, well, you know where that variable should be sitting. Good luck! Write your solution by modifying this code: ```python def bracket_buster(string): ``` Your solution should implemented in the function "bracket_buster". The inputs will be passed to it and it should return the correct solution. Now solve the problem and return the code.
[]
[]
1
stdio
Sergey is testing a next-generation processor. Instead of bytes the processor works with memory cells consisting of n bits. These bits are numbered from 1 to n. An integer is stored in the cell in the following way: the least significant bit is stored in the first bit of the cell, the next significant bit is stored in the second bit, and so on; the most significant bit is stored in the n-th bit. Now Sergey wants to test the following instruction: "add 1 to the value of the cell". As a result of the instruction, the integer that is written in the cell must be increased by one; if some of the most significant bits of the resulting number do not fit into the cell, they must be discarded. Sergey wrote certain values ​​of the bits in the cell and is going to add one to its value. How many bits of the cell will change after the operation? -----Input----- The first line contains a single integer n (1 ≤ n ≤ 100) — the number of bits in the cell. The second line contains a string consisting of n characters — the initial state of the cell. The first character denotes the state of the first bit of the cell. The second character denotes the second least significant bit and so on. The last character denotes the state of the most significant bit. -----Output----- Print a single integer — the number of bits in the cell which change their state after we add 1 to the cell. -----Examples----- Input 4 1100 Output 3 Input 4 1111 Output 4 -----Note----- In the first sample the cell ends up with value 0010, in the second sample — with 0000.
[ "4\n1100\n", "4\n1111\n", "1\n0\n", "1\n1\n", "2\n00\n", "2\n01\n", "2\n10\n", "2\n11\n", "10\n0000000000\n", "20\n11111111110110001100\n" ]
[ "3\n", "4\n", "1\n", "1\n", "1\n", "1\n", "2\n", "2\n", "1\n", "11\n" ]
1
stdio
Vasilisa the Wise from a far away kingdom got a present from her friend Helga the Wise from a farther away kingdom. The present is a surprise box, yet Vasilisa the Wise doesn't know yet what the surprise actually is because she cannot open the box. She hopes that you can help her in that. The box's lock is constructed like that. The box itself is represented by an absolutely perfect black cube with the identical deepening on each face (those are some foreign nanotechnologies that the far away kingdom scientists haven't dreamt of). The box is accompanied by six gems whose form matches the deepenings in the box's faces. The box can only be opened after it is correctly decorated by the gems, that is, when each deepening contains exactly one gem. Two ways of decorating the box are considered the same if they can be obtained one from the other one by arbitrarily rotating the box (note that the box is represented by a perfect nanotechnological cube) Now Vasilisa the Wise wants to know by the given set of colors the following: in how many ways would she decorate the box in the worst case to open it? To answer this question it is useful to know that two gems of one color are indistinguishable from each other. Help Vasilisa to solve this challenging problem. Input The first line contains exactly 6 characters without spaces from the set {R, O, Y, G, B, V} — they are the colors of gems with which the box should be decorated. Output Print the required number of different ways to decorate the box. Examples Input YYYYYY Output 1 Input BOOOOB Output 2 Input ROYGBV Output 30
[ "VYYYVV\n", "OBRRYY\n", "RRYOGB\n", "RROOYY\n", "GOGGVG\n", "GVGBVO\n", "BOBGBB\n", "OOYYBY\n", "VVRVVV\n", "VOVRBV\n" ]
[ "2\n", "8\n", "15\n", "6\n", "2\n", "8\n", "2\n", "3\n", "1\n", "5\n" ]
1
stdio
## Description: Remove all exclamation marks from the end of words. Words are separated by spaces in the sentence. ### Examples ``` remove("Hi!") === "Hi" remove("Hi!!!") === "Hi" remove("!Hi") === "!Hi" remove("!Hi!") === "!Hi" remove("Hi! Hi!") === "Hi Hi" remove("!!!Hi !!hi!!! !hi") === "!!!Hi !!hi !hi" ``` Write your solution by modifying this code: ```python def remove(s): ``` Your solution should implemented in the function "remove". 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 are required to create a simple calculator that returns the result of addition, subtraction, multiplication or division of two numbers. Your function will accept three arguments: The first and second argument should be numbers. The third argument should represent a sign indicating the operation to perform on these two numbers. ```if-not:csharp if the variables are not numbers or the sign does not belong to the list above a message "unknown value" must be returned. ``` ```if:csharp If the sign is not a valid sign, throw an ArgumentException. ``` # Example: ```python calculator(1, 2, '+') => 3 calculator(1, 2, '$') # result will be "unknown value" ``` Good luck! Write your solution by modifying this code: ```python def calculator(x,y,op): ``` Your solution should implemented in the function "calculator". 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 an array (or list or vector) of arrays (or, guess what, lists or vectors) of integers, your goal is to return the sum of a specific set of numbers, starting with elements whose position is equal to the main array length and going down by one at each step. Say for example the parent array (etc, etc) has 3 sub-arrays inside: you should consider the third element of the first sub-array, the second of the second array and the first element in the third one: `[[3, 2, 1, 0], [4, 6, 5, 3, 2], [9, 8, 7, 4]]` would have you considering `1` for `[3, 2, 1, 0]`, `6` for `[4, 6, 5, 3, 2]` and `9` for `[9, 8, 7, 4]`, which sums up to `16`. One small note is that not always each sub-array will have enough elements, in which case you should then use a default value (if provided) or `0` (if not provided), as shown in the test cases. Write your solution by modifying this code: ```python def elements_sum(arr, d=0): ``` Your solution should implemented in the function "elements_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
## Task In this kata you'll be given a string of English digits "collapsed" together, like this: `zeronineoneoneeighttwoseventhreesixfourtwofive` Your task is to split the string back to digits: `zero nine one one eight two seven three six four two five` ## Examples ``` three -> three eightsix -> eight six fivefourseven -> five four seven ninethreesixthree -> nine three six three fivethreefivesixthreenineonesevenoneeight -> five three five six three nine one seven one eight ``` Write your solution by modifying this code: ```python def uncollapse(digits): ``` Your solution should implemented in the function "uncollapse". The inputs will be passed to it and it should return the correct solution. Now solve the problem and return the code.
[]
[]
1
stdio
A nearby pie shop is having a special sale. For each pie you pay full price for, you may select one pie of a strictly lesser value to get for free. Given the prices of all the pies you wish to acquire, determine the minimum total amount you must pay for all of the pies. Input Input will begin with an integer n (1 ≤ n ≤ 500000), the number of pies you wish to acquire. Following this is a line with n integers, each indicating the cost of a pie. All costs are positive integers not exceeding 109. Output Print the minimum cost to acquire all the pies. Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier. Examples Input 6 3 4 5 3 4 5 Output 14 Input 5 5 5 5 5 5 Output 25 Input 4 309999 6000 2080 2080 Output 314159 Note In the first test case you can pay for a pie with cost 5 and get a pie with cost 4 for free, then pay for a pie with cost 5 and get a pie with cost 3 for free, then pay for a pie with cost 4 and get a pie with cost 3 for free. In the second test case you have to pay full price for every pie.
[ "30\n3 6 3 8 6 4 4 2 4 10 8 5 9 6 7 7 9 4 7 4 10 1 9 10 4 7 7 4 2 3\n", "1\n1\n", "50\n4 2 6 7 2 6 3 8 8 2 4 8 4 4 1 4 5 2 2 5 6 4 3 3 3 6 8 2 1 3 1 8 2 3 7 4 7 5 4 8 3 5 7 8 6 7 5 8 7 1\n", "40\n2 6 5 5 6 6 7 8 6 5 3 9 9 1 8 3 7 3 7 2 3 1 3 1 5 8 1 3 8 2 3 2 2 1 4 4 4 3 5 5\n", "10\n1 1 1 1 1 2 3 4 5 6\n",...
[ "96\n", "1\n", "130\n", "100\n", "16\n", "505072434\n", "22\n", "880460566", "96\n", "2\n" ]
1
stdio
Iahub likes chess very much. He even invented a new chess piece named Coder. A Coder can move (and attack) one square horizontally or vertically. More precisely, if the Coder is located at position (x, y), he can move to (or attack) positions (x + 1, y), (x–1, y), (x, y + 1) and (x, y–1). Iahub wants to know how many Coders can be placed on an n × n chessboard, so that no Coder attacks any other Coder. -----Input----- The first line contains an integer n (1 ≤ n ≤ 1000). -----Output----- On the first line print an integer, the maximum number of Coders that can be placed on the chessboard. On each of the next n lines print n characters, describing the configuration of the Coders. For an empty cell print an '.', and for a Coder print a 'C'. If there are multiple correct answers, you can print any. -----Examples----- Input 2 Output 2 C. .C
[ "2\n", "3\n", "4\n", "10\n", "15\n", "1\n", "15\n", "101\n", "3\n", "4\n" ]
[ "2\nC.\n.C\n", "5\nC.C\n.C.\nC.C\n", "8\nC.C.\n.C.C\nC.C.\n.C.C\n", "50\nC.C.C.C.C.\n.C.C.C.C.C\nC.C.C.C.C.\n.C.C.C.C.C\nC.C.C.C.C.\n.C.C.C.C.C\nC.C.C.C.C.\n.C.C.C.C.C\nC.C.C.C.C.\n.C.C.C.C.C\n", "113\nC.C.C.C.C.C.C.C\n.C.C.C.C.C.C.C.\nC.C.C.C.C.C.C.C\n.C.C.C.C.C.C.C.\nC.C.C.C.C.C.C.C\n.C.C.C.C.C.C.C.\nC.C....
1
stdio
Algorithmic predicament - Bug Fixing #9 Oh no! Timmy's algorithim has gone wrong! help Timmy fix his algorithim! Task Your task is to fix timmy's algorithim so it returns the group name with the highest total age. You will receive two groups of `people` objects, with two properties `name` and `age`. The name property is a string and the age property is a number. Your goal is to make the total the age of all people having the same name through both groups and return the name of the one with the highest age. If two names have the same total age return the first alphabetical name. Write your solution by modifying this code: ```python def highest_age(group1,group2): ``` Your solution should implemented in the function "highest_age". 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 is an integer N. Find the minimum possible positive integer k such that (1+2+\cdots+k) is a multiple of N. It can be proved that such a positive integer k always exists. Constraints * 1 \leq N \leq 10^{15} * All values in input are integers. Input Input is given from Standard Input in the following format: N Output Print the answer in a line. Examples Input 11 Output 10 Input 20200920 Output 1100144
[ "39730771", "5", "36307133", "71266519", "3807301", "3003457", "3532816", "6261239", "8870499", "11036793" ]
[ "39730770\n", "4\n", "3157141\n", "17269679\n", "928609\n", "295422\n", "220800\n", "914563\n", "328536\n", "3678930\n" ]
1
stdio
Bishwock is a chess figure that consists of three squares resembling an "L-bar". This figure can be rotated by 90, 180 and 270 degrees so it can have four possible states: XX XX .X X. X. .X XX XX Bishwocks don't attack any squares and can even occupy on the adjacent squares as long as they don't occupy the same square. Vasya has a board with $2\times n$ squares onto which he wants to put some bishwocks. To his dismay, several squares on this board are already occupied by pawns and Vasya can't put bishwocks there. However, pawns also don't attack bishwocks and they can occupy adjacent squares peacefully. Knowing the positions of pawns on the board, help Vasya to determine the maximum amount of bishwocks he can put onto the board so that they wouldn't occupy the same squares and wouldn't occupy squares with pawns. -----Input----- The input contains two nonempty strings that describe Vasya's board. Those strings contain only symbols "0" (zero) that denote the empty squares and symbols "X" (uppercase English letter) that denote the squares occupied by pawns. Strings are nonempty and are of the same length that does not exceed $100$. -----Output----- Output a single integer — the maximum amount of bishwocks that can be placed onto the given board. -----Examples----- Input 00 00 Output 1 Input 00X00X0XXX0 0XXX0X00X00 Output 4 Input 0X0X0 0X0X0 Output 0 Input 0XXX0 00000 Output 2
[ "00\n00\n", "00X00X0XXX0\n0XXX0X00X00\n", "0X0X0\n0X0X0\n", "0XXX0\n00000\n", "0\n0\n", "0\nX\n", "X\n0\n", "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX...
[ "1", "4", "0", "2", "0", "0", "0", "0", "18", "0" ]
1
stdio
I conducted an exit poll of the shopping amount at a department store. Create a program that takes the shopping amount data as input, calculates the average shopping amount per person, and outputs it. The number of people surveyed shall be 100,000 or less, and the shopping amount per person shall not exceed 1 million yen. Input The input is given in the following format: n v1 v2 :: vn The first line gives the number of people surveyed n, and the following n lines give the integer vi representing the purchase amount of the ith person. Output Please output the average shopping amount (integer: rounded down to the nearest whole number) on one line. Example Input 6 12300 5600 33800 0 26495 52000 Output 21699
[ "6\n23426\n5600\n33800\n0\n26495\n52000", "6\n23426\n5600\n33800\n0\n17519\n52000", "6\n23426\n5600\n33800\n0\n14222\n52000", "6\n23426\n5600\n33800\n0\n2007\n52000", "6\n23426\n5600\n33800\n0\n2007\n80378", "6\n23426\n5600\n33800\n0\n3681\n80378", "6\n23426\n5600\n33800\n0\n3681\n10193", "6\n46488\n5...
[ "23553\n", "22057\n", "21508\n", "19472\n", "24201\n", "24480\n", "12783\n", "16627\n", "16293\n", "16294\n" ]
1
stdio
Description In English we often use "neutral vowel sounds" such as "umm", "err", "ahh" as fillers in conversations to help them run smoothly. Bob always finds himself saying "err". Infact he adds an "err" to every single word he says that ends in a consonant! Because Bob is odd, he likes to stick to this habit even when emailing. Task Bob is begging you to write a function that adds "err" to the end of every word whose last letter is a consonant (not a vowel, y counts as a consonant). The input is a string that can contain upper and lowercase characters, some punctuation but no numbers. The solution should be returned as a string. NOTE: If the word ends with an uppercase consonant, the following "err" will be uppercase --> "ERR". eg: ``` "Hello, I am Mr Bob" --> "Hello, I amerr Mrerr Boberr" "THIS IS CRAZY!" --> "THISERR ISERR CRAZYERR!" ``` Good luck! Write your solution by modifying this code: ```python def err_bob(s): ``` Your solution should implemented in the function "err_bob". 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 number 81 has a special property, a certain power of the sum of its digits is equal to 81 (nine squared). Eighty one (81), is the first number in having this property (not considering numbers of one digit). The next one, is 512. Let's see both cases with the details 8 + 1 = 9 and 9^(2) = 81 512 = 5 + 1 + 2 = 8 and 8^(3) = 512 We need to make a function, ```power_sumDigTerm()```, that receives a number ```n``` and may output the ```n-th term``` of this sequence of numbers. The cases we presented above means that power_sumDigTerm(1) == 81 power_sumDigTerm(2) == 512 Happy coding! Write your solution by modifying this code: ```python def power_sumDigTerm(n): ``` Your solution should implemented in the function "power_sumDigTerm". The inputs will be passed to it and it should return the correct solution. Now solve the problem and return the code.
[]
[]
1
stdio
Summer vacation ended at last and the second semester has begun. You, a Kyoto University student, came to university and heard a rumor that somebody will barricade the entrance of your classroom. The barricade will be built just before the start of the A-th class and removed by Kyoto University students just before the start of the B-th class. All the classes conducted when the barricade is blocking the entrance will be cancelled and you will not be able to attend them. Today you take N classes and class i is conducted in the t_i-th period. You take at most one class in each period. Find the number of classes you can attend. Constraints * 1 \leq N \leq 1000 * 1 \leq A < B \leq 10^9 * 1 \leq t_i \leq 10^9 * All t_i values are distinct. Input N, A and B are given on the first line and t_i is given on the (i+1)-th line. N A B t1 : tN Output Print the number of classes you can attend. Examples Input 5 5 9 4 3 6 9 1 Output 4 Input 5 4 9 5 6 7 8 9 Output 1 Input 4 3 6 9 6 8 1 Output 4 Input 2 1 2 1 2 Output 1
[ "4 1 6\n9\n6\n8\n1", "2 1 2\n2\n2", "5 5 5\n5\n6\n11\n8\n9", "4 1 11\n7\n6\n0\n1", "4 3 6\n9\n6\n6\n1", "5 5 18\n5\n6\n7\n8\n9", "5 4 9\n5\n6\n11\n8\n9", "4 1 6\n9\n6\n0\n1", "2 2 2\n2\n2", "5 5 9\n5\n6\n11\n8\n9" ]
[ "3\n", "2\n", "5\n", "1\n", "4\n", "0\n", "2\n", "3\n", "2\n", "2\n" ]
1
stdio
Takahashi has N blue cards and M red cards. A string is written on each card. The string written on the i-th blue card is s_i, and the string written on the i-th red card is t_i. Takahashi will now announce a string, and then check every card. Each time he finds a blue card with the string announced by him, he will earn 1 yen (the currency of Japan); each time he finds a red card with that string, he will lose 1 yen. Here, we only consider the case where the string announced by Takahashi and the string on the card are exactly the same. For example, if he announces atcoder, he will not earn money even if there are blue cards with atcoderr, atcode, btcoder, and so on. (On the other hand, he will not lose money even if there are red cards with such strings, either.) At most how much can he earn on balance? Note that the same string may be written on multiple cards. -----Constraints----- - N and M are integers. - 1 \leq N, M \leq 100 - s_1, s_2, ..., s_N, t_1, t_2, ..., t_M are all strings of lengths between 1 and 10 (inclusive) consisting of lowercase English letters. -----Input----- Input is given from Standard Input in the following format: N s_1 s_2 : s_N M t_1 t_2 : t_M -----Output----- If Takahashi can earn at most X yen on balance, print X. -----Sample Input----- 3 apple orange apple 1 grape -----Sample Output----- 2 He can earn 2 yen by announcing apple.
[ "3\napple\norange\napple\n1\ngrape\n", "3\napple\norange\napple\n5\napple\napple\napple\napple\napple\n", "1\nvoldemort\n10\nvoldemort\nvoldemort\nvoldemort\nvoldemort\nvoldemort\nvoldemort\nvoldemort\nvoldemort\nvoldemort\nvoldemort\n", "6\nred\nred\nblue\nyellow\nyellow\nred\n5\nred\nred\nyellow\ngreen\nblu...
[ "2\n", "1\n", "0\n", "1\n", "1\n", "2\n", "0\n", "3\n", "1\n", "1\n" ]
1
stdio
Write a program that extracts n different numbers from the numbers 0 to 9 and outputs the number of combinations that add up to s. Each n number is from 0 to 9, and the same number cannot be used in one combination. For example, if n is 3 and s is 6, the combination of the three numbers totaling 6 is 1 + 2 + 3 = 6 0 + 1 + 5 = 6 0 + 2 + 4 = 6 There are three ways. Input Given multiple datasets. For each dataset, n (1 ≤ n ≤ 9) and s (0 ≤ s ≤ 100) are given on one line, separated by a single space. When both n and s are 0, it is the end of the input (in this case, the program is terminated without processing). The number of datasets does not exceed 50. Output For each dataset, output the number of combinations in which the sum of n integers is s on one line. Example Input 3 6 3 1 0 0 Output 3 0
[ "3 5\n3 1\n0 0", "3 0\n5 1\n0 0", "1 0\n5 1\n0 0", "3 6\n3 0\n0 0", "2 5\n1 1\n0 0", "2 0\n1 1\n0 0", "3 2\n0 0\n0 0", "2 2\n0 0\n0 0", "3 7\n3 1\n0 0", "3 8\n3 1\n0 0" ]
[ "2\n0\n", "0\n0\n", "1\n0\n", "3\n0\n", "3\n1\n", "0\n1\n", "0\n", "1\n", "4\n0\n", "5\n0\n" ]
1
stdio
Given an integer N, Chef wants to find the smallest positive integer M such that the bitwise XOR of M and M+1 is N. If no such M exists output -1. -----Input----- The first line of input contain an integer T denoting the number of test cases. Each of the following T lines contains an integer N for that test case. -----Output----- For each test case, output a single line containing the number M or -1 as described above. -----Constraints----- - 1 ≤ T ≤ 5000 - 1 ≤ N ≤ 230 -----Example----- Input: 1 3 Output: 1 -----Explanation-----First Example : M desired in the problem would be 1. As bitwise XOR of 1 and 2 is equal to 3.
[ "1\n3\n", "1\n1", "1\n2", "1\n7", "1\n15", "1\n31", "1\n63", "1\n127", "1\n6", "1\n4" ]
[ "1\n", "2\n", "-1\n", "3\n", "7\n", "15\n", "31\n", "63\n", "-1\n", "-1\n" ]
1
stdio
A teacher decides to give toffees to his students. He asks n students to stand in a queue. Since the teacher is very partial, he follows the following rule to distribute toffees. He looks at the first two students and gives more toffees to the student having higher marks than the other one. If they have the same marks they get the same number of toffees. The same procedure is followed for each pair of adjacent students starting from the first one to the last one. It is given that each student receives at least one toffee. You have to find the number of toffees given to each student by the teacher such that the total number of toffees is minimum. Input The first line of input contains the number of students n (2 ≤ n ≤ 1000). The second line gives (n - 1) characters consisting of "L", "R" and "=". For each pair of adjacent students "L" means that the left student has higher marks, "R" means that the right student has higher marks and "=" means that both have equal marks. Output Output consists of n integers separated by a space representing the number of toffees each student receives in the queue starting from the first one to the last one. Examples Input 5 LRLR Output 2 1 2 1 2 Input 5 =RRR Output 1 1 2 3 4
[ "166\nR===RL=LRRR=RRRL=LRR=R=RR==L=R=R=RRR=RR=RLLRRL=LLRL==L=R==RLR==RL=RR=LR==R=R=LLRLRLR=RR=RLLRLR=RRLL==L=LR=RR=RRRL=RLLLR==L=RRLRLLLLLLLRL===LRLRLRLRRLL=LRLL===LRLRR==\n", "3\nR=\n", "6\nRLRL=\n", "453\nR==LL==RRLLRRLR=L=LRLL=LRRR=R====L=RL======RR==RRRR=LRR=LLLRR=LLLLL===LL=LLL=LR=RLRL===L==R=LRL=L=R==RR...
[ "1 2 2 2 2 3 2 2 1 2 3 4 4 5 6 7 2 2 1 2 3 3 4 4 5 6 6 6 1 1 2 2 3 3 4 5 6 6 7 8 8 9 2 1 2 4 3 3 2 1 3 2 2 2 1 1 2 2 2 3 1 2 2 2 3 1 1 2 3 3 1 2 2 2 3 3 4 4 2 1 2 1 2 1 2 2 3 4 4 5 2 1 2 1 2 2 3 5 4 3 3 3 2 2 1 2 2 3 4 4 5 6 7 1 1 4 3 2 1 2 2 2 1 1 2 3 1 8 7 6 5 4 3 2 1 3 2 2 2 2 1 2 1 2 1 2 1 2 4 3 2 2 1 4 3 2 2 2...
1
stdio
Example Input crc 1 Output crc
[ "crb\n1", "bqc\n1", "bcq\n2", "ccq\n2", "cdq\n2", "dcq\n2", "dcq\n4", "qcd\n3", "qce\n3", "qce\n4" ]
[ "bcrcb\n", "bcqcb\n", "bqcqb\n", "NONE\n", "cqdqc\n", "dqcqd\n", "qdcdq\n", "qcdcq\n", "qcecq\n", "qeceq\n" ]
1
stdio
While surfing in web I found interesting math problem called "Always perfect". That means if you add 1 to the product of four consecutive numbers the answer is ALWAYS a perfect square. For example we have: 1,2,3,4 and the product will be 1X2X3X4=24. If we add 1 to the product that would become 25, since the result number is a perfect square the square root of 25 would be 5. So now lets write a function which takes numbers separated by commas in string format and returns the number which is a perfect square and the square root of that number. If string contains other characters than number or it has more or less than 4 numbers separated by comma function returns "incorrect input". If string contains 4 numbers but not consecutive it returns "not consecutive". Write your solution by modifying this code: ```python def check_root(string): ``` Your solution should implemented in the function "check_root". 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 method that returns true if a given parameter is a power of 4, and false if it's not. If parameter is not an Integer (eg String, Array) method should return false as well. (In C# Integer means all integer Types like Int16,Int32,.....) ### Examples ```python isPowerOf4 1024 #should return True isPowerOf4 102 #should return False isPowerOf4 64 #should return True ``` Write your solution by modifying this code: ```python def powerof4(n): ``` Your solution should implemented in the function "powerof4". The inputs will be passed to it and it should return the correct solution. Now solve the problem and return the code.
[]
[]
1
stdio
Yaroslav has an array, consisting of (2·n - 1) integers. In a single operation Yaroslav can change the sign of exactly n elements in the array. In other words, in one operation Yaroslav can select exactly n array elements, and multiply each of them by -1. Yaroslav is now wondering: what maximum sum of array elements can be obtained if it is allowed to perform any number of described operations? Help Yaroslav. -----Input----- The first line contains an integer n (2 ≤ n ≤ 100). The second line contains (2·n - 1) integers — the array elements. The array elements do not exceed 1000 in their absolute value. -----Output----- In a single line print the answer to the problem — the maximum sum that Yaroslav can get. -----Examples----- Input 2 50 50 50 Output 150 Input 2 -1 -100 -1 Output 100 -----Note----- In the first sample you do not need to change anything. The sum of elements equals 150. In the second sample you need to change the sign of the first two elements. Then we get the sum of the elements equal to 100.
[ "2\n50 50 50\n", "2\n-1 -100 -1\n", "3\n-959 -542 -669 -513 160\n", "4\n717 473 344 -51 -548 703 -869\n", "5\n270 -181 957 -509 -6 937 -175 434 -625\n", "6\n-403 901 -847 -708 -624 413 -293 709 886 445 716\n", "7\n-236 533 869 903 655 -714 27 890 -311 800 307 -682 665\n", "8\n-338 134 708 -761 -135 53...
[ "150\n", "100\n", "2843\n", "3603\n", "4094\n", "6359\n", "7592\n", "6463\n", "8094\n", "9591\n" ]
1
stdio
While most devs know about [big/little-endianness](https://en.wikipedia.org/wiki/Endianness), only a selected few know the secret of real hard core coolness with mid-endians. Your task is to take a number and return it in its mid-endian format, putting the most significant couple of bytes in the middle and all the others around it, alternating left and right. For example, consider the number `9999999`, whose hexadecimal representation would be `98967F` in big endian (the classic you get converting); it becomes `7F9698` in little-endian and `96987F` in mid-endian. Write a function to do that given a positive integer (in base 10) and remembering that you need to pad with `0`s when you get a single hex digit! Write your solution by modifying this code: ```python def mid_endian(n): ``` Your solution should implemented in the function "mid_endian". The inputs will be passed to it and it should return the correct solution. Now solve the problem and return the code.
[]
[]
1
stdio
Two integers are coprimes if the their only greatest common divisor is 1. ## Task In this kata you'll be given a number ```n >= 2``` and output a list with all positive integers less than ```gcd(n, k) == 1```, with ```k``` being any of the output numbers. The list cannot include duplicated entries and has to be sorted. ## Examples ``` 2 -> [1] 3 -> [1, 2] 6 -> [1, 5] 10 -> [1, 3, 7, 9] 20 -> [1, 3, 7, 9, 11, 13, 17, 19] 25 -> [1, 2, 3, 4, 6, 7, 8, 9, 11, 12, 13, 14, 16, 17, 18, 19, 21, 22, 23, 24] 30 -> [1, 7, 11, 13, 17, 19, 23, 29] ``` Write your solution by modifying this code: ```python def coprimes(n): ``` Your solution should implemented in the function "coprimes". 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 Bob decided to lay a parquet floor in his living room. The living room is of size n × m metres. Bob had planks of three types: a planks 1 × 2 meters, b planks 2 × 1 meters, and c planks 2 × 2 meters. Help Bob find out, if it is possible to parquet the living room with such a set of planks, and if it is possible, find one of the possible ways to do so. Bob doesn't have to use all the planks. Input The first input line contains 5 space-separated integer numbers n, m, a, b, c (1 ≤ n, m ≤ 100, 0 ≤ a, b, c ≤ 104), n and m — the living room dimensions, a, b and c — amount of planks 1 × 2, 2 × 1 и 2 × 2 respectively. It's not allowed to turn the planks. Output If it is not possible to parquet the room with such a set of planks, output IMPOSSIBLE. Otherwise output one of the possible ways to parquet the room — output n lines with m lower-case Latin letters each. Two squares with common sides should contain the same letters, if they belong to one and the same plank, and different letters otherwise. Different planks can be marked with one and the same letter (see examples). If the answer is not unique, output any. Examples Input 2 6 2 2 1 Output aabcca aabdda Input 1 1 100 100 100 Output IMPOSSIBLE Input 4 4 10 10 10 Output aabb aabb bbaa bbaa
[ "100 100 10000 10000 10000\n", "100 100 0 0 0\n", "100 100 2498 2498 1\n", "1 2 0 1 0\n", "100 100 2499 2499 0\n", "90 100 1488 2992 10\n", "2 1 1 0 0\n", "97 100 58 172 2310\n", "100 100 2474 270 1128\n", "99 99 2797 749 677\n" ]
[ "aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabb\naabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabb\nbbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaa\nbbaabbaab...
1
stdio
Several drivers had lined up for the Drag Racing Competition at the Tokyo Drift Street. Dom had organized the competition, but he was not available during all the races and hence he did not know their results. In the drag race match, 2 drivers race against each other and one of them is the winner, and the loser gets eliminated - there were no ties. The competition takes place as a knockout tournament. There are a total of N rounds, and the number of players in the tournament are 2^N. Dom's friend Letty gave him the results of all the races in this format: A B - denoting: Match was between A and B, and the winner was A. Note: The results are not ordered. Input: First line contains a single positive integer N. 2^N - 1 lines follow - Each line contains details of a match. Output: Print the name of the driver who won the Drag Racing Competition. Constraints: 1 ≤ N ≤ 15 Names of drivers do not contain more than 15 characters. (Candidates solving the question in Python or C++ will be given preference) SAMPLE INPUT 2 a b a c c d SAMPLE OUTPUT a Explanation Consider [a, b, c, d] to be the drivers. c eliminates d. a eliminates c. a eliminates b. Hence, a is the winner.
[ "9\nznejwgwpok wohkjjwlwn\nuwdszgerob pxutblrgio\ntnvpozvuib rmkroequbu\nxozaulqdsc wneolwstpl\ntnvpozvuib evrtybebba\nrfsijiyzzn ehbrqxwqft\nrphpmhvjxw luohdaqoyr\nrsdfhgmges chjthfleee\nqrjdszcwxt abzorlrlsh\ntgszjlyyra cdvenegwyc\nneigxtnilh mcizjrkuof\njyxkpozzlr iijjdgauzu\nvkzhdolaqo yldeohgpgi\nvtsnibclli ew...
[ "pxrtqhmuoa\n", "axtzpuwube\n", "qbpapwvndk\n", "ijetrpnsjc\n", "hrrugxurrh\n", "iwtqgydtbw\n", "fovjpmznym\n", "daoeglsuhs\n", "gkjjvchyhp\n", "tgajndqkfb\n" ]
1
stdio
For an integer ```k``` rearrange all the elements of the given array in such way, that: all elements that are less than ```k``` are placed before elements that are not less than ```k```; all elements that are less than ```k``` remain in the same order with respect to each other; all elements that are not less than ```k``` remain in the same order with respect to each other. For ```k = 6``` and ```elements = [6, 4, 10, 10, 6]```, the output should be ```splitByValue(k, elements) = [4, 6, 10, 10, 6]```. For ```k``` = 5 and ```elements = [1, 3, 5, 7, 6, 4, 2]```, the output should be ```splitByValue(k, elements) = [1, 3, 4, 2, 5, 7, 6]```. S: codefights.com Write your solution by modifying this code: ```python def split_by_value(k, elements): ``` Your solution should implemented in the function "split_by_value". The inputs will be passed to it and it should return the correct solution. Now solve the problem and return the code.
[]
[]
1
stdio
Due to another of his misbehaved, the primary school's teacher of the young Gauß, Herr J.G. Büttner, to keep the bored and unruly young schoolboy Karl Friedrich Gauss busy for a good long time, while he teaching arithmetic to his mates, assigned him the problem of adding up all the whole numbers from 1 through a given number `n`. Your task is to help the young Carl Friedrich to solve this problem as quickly as you can; so, he can astonish his teacher and rescue his recreation interval. Here's, an example: ``` f(n=100) // returns 5050 ``` It's your duty to verify that n is a valid positive integer number. If not, please, return false (None for Python, null for C#). > **Note:** the goal of this kata is to invite you to think about some 'basic' mathematic formula and how you can do performance optimization on your code. > Advanced - experienced users should try to solve it in one line, without loops, or optimizing the code as much as they can. ----- **Credits:** this kata was inspired by the farzher's kata 'Sum of large ints' . In fact, it can be seen as a sort of prep kata for that one. Write your solution by modifying this code: ```python def f(n): ``` Your solution should implemented in the function "f". 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 are given three numbers. Is there a way to replace variables A, B and C with these numbers so the equality A + B = C is correct? Input: There are three numbers X1, X2 and X3 (1 ≤ Xi ≤ 10^100), each on a separate line of input. Output: Output either "YES", if there is a way to substitute variables A, B and C with given numbers so the equality is correct, or "NO" otherwise. Sample Input: 1 2 3 Output: YES Sample Input: 1 2 4 Output YES Sample Input: 1 3 5 Output NO SAMPLE INPUT 1 2 3 SAMPLE OUTPUT YES
[ "1000000000000000000000000000000000000000000000000000000000000000000000000000\n2000000000000000000000000000000000000000000000000000000000000000000000000000\n4000000000000000000000000000000000000000000000000000000000000000000000000000", "3000000000000000000000000000000\n7000000000000000000000000000000\n20000000000...
[ "YES", "NO", "YES", "YES", "NO", "NO", "YES", "YES", "NO", "NO" ]
1
stdio
Teacher thinks that we make a lot of progress. Now we are even allowed to use decimal notation instead of counting sticks. After the test the teacher promised to show us a "very beautiful number". But the problem is, he's left his paper with the number in the teachers' office. The teacher remembers that the "very beautiful number" was strictly positive, didn't contain any leading zeroes, had the length of exactly p decimal digits, and if we move the last digit of the number to the beginning, it grows exactly x times. Besides, the teacher is sure that among all such numbers the "very beautiful number" is minimal possible. The teachers' office isn't near and the teacher isn't young. But we've passed the test and we deserved the right to see the "very beautiful number". Help to restore the justice, find the "very beautiful number" for us! -----Input----- The single line contains integers p, x (1 ≤ p ≤ 10^6, 1 ≤ x ≤ 9). -----Output----- If the teacher's made a mistake and such number doesn't exist, then print on a single line "Impossible" (without the quotes). Otherwise, print the "very beautiful number" without leading zeroes. -----Examples----- Input 6 5 Output 142857 Input 1 2 Output Impossible Input 6 4 Output 102564 -----Note----- Sample 1: 142857·5 = 714285. Sample 2: The number that consists of a single digit cannot stay what it is when multiplied by 2, thus, the answer to the test sample is "Impossible".
[ "6 5\n", "1 2\n", "6 4\n", "11 1\n", "42 5\n", "36 5\n", "56 3\n", "88 9\n", "81 7\n", "100 1\n" ]
[ "142857", "Impossible\n", "102564", "11111111111", "102040816326530612244897959183673469387755", "142857142857142857142857142857142857", "10344827586206896551724137931034482758620689655172413793", "1011235955056179775280898876404494382022471910112359550561797752808988764044943820224719", "Impossible...
1
stdio
Finish the solution so that it sorts the passed in array of numbers. If the function passes in an empty array or null/nil value then it should return an empty array. For example: ```python solution([1,2,3,10,5]) # should return [1,2,3,5,10] solution(None) # should return [] ``` ```Hakell sortNumbers [1, 2, 10, 50, 5] = Just [1, 2, 5, 10, 50] sortNumbers [] = Nothing ``` Write your solution by modifying this code: ```python def solution(nums): ``` Your solution should implemented in the function "solution". The inputs will be passed to it and it should return the correct solution. Now solve the problem and return the code.
[]
[]
1
stdio
# Introduction: Reversi is a game usually played by 2 people on a 8x8 board. Here we're only going to consider a single 8x1 row. Players take turns placing pieces, which are black on one side and white on the other, onto the board with their colour facing up. If one or more of the opponents pieces are sandwiched by the piece just played and another piece of the current player's colour, the opponents pieces are flipped to the current players colour. Note that the flipping stops when the first piece of the player's colour is reached. # Task: Your task is to take an array of moves and convert this into a string representing the state of the board after all those moves have been played. # Input: The input to your function will be an array of moves. Moves are represented by integers from 0 to 7 corresponding to the 8 squares on the board. Black plays first, and black and white alternate turns. Input is guaranteed to be valid. (No duplicates, all moves in range, but array may be empty) # Output: 8 character long string representing the final state of the board. Use '*' for black and 'O' for white and '.' for empty. # Examples: ```python reversi_row([]) # '........' reversi_row([3]) # '...*....' reversi_row([3,4]) # '...*O...' reversi_row([3,4,5]) # '...***..' ``` Write your solution by modifying this code: ```python def reversi_row(moves): ``` Your solution should implemented in the function "reversi_row". 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 A media access control address (MAC address) is a unique identifier assigned to network interfaces for communications on the physical network segment. The standard (IEEE 802) format for printing MAC-48 addresses in human-friendly form is six groups of two hexadecimal digits (0 to 9 or A to F), separated by hyphens (e.g. 01-23-45-67-89-AB). # Example For `inputString = "00-1B-63-84-45-E6"`, the output should be `true`; For `inputString = "Z1-1B-63-84-45-E6"`, the output should be `false`; For `inputString = "not a MAC-48 address"`, the output should be `false`. # Input/Output - `[input]` string `inputString` - `[output]` a boolean value `true` if inputString corresponds to MAC-48 address naming rules, `false` otherwise. Write your solution by modifying this code: ```python def is_mac_48_address(address): ``` Your solution should implemented in the function "is_mac_48_address". The inputs will be passed to it and it should return the correct solution. Now solve the problem and return the code.
[]
[]
1
stdio
Stepan has the newest electronic device with a display. Different digits can be shown on it. Each digit is shown on a seven-section indicator like it is shown on the picture below. [Image] So, for example, to show the digit 3 on the display, 5 sections must be highlighted; and for the digit 6, 6 sections must be highlighted. The battery of the newest device allows to highlight at most n sections on the display. Stepan wants to know the maximum possible integer number which can be shown on the display of his newest device. Your task is to determine this number. Note that this number must not contain leading zeros. Assume that the size of the display is enough to show any integer. -----Input----- The first line contains the integer n (2 ≤ n ≤ 100 000) — the maximum number of sections which can be highlighted on the display. -----Output----- Print the maximum integer which can be shown on the display of Stepan's newest device. -----Examples----- Input 2 Output 1 Input 3 Output 7
[ "2\n", "3\n", "4\n", "5\n", "6\n", "9\n", "156\n", "255\n", "8343\n", "156\n" ]
[ "1\n", "7\n", "11\n", "71\n", "111\n", "7111\n", "111111111111111111111111111111111111111111111111111111111111111111111111111111\n", "7111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n", "711111111111111111111111111111111...
1
stdio
AtCoDeer the deer found two positive integers, a and b. Determine whether the product of a and b is even or odd. -----Constraints----- - 1 ≤ a,b ≤ 10000 - a and b are integers. -----Input----- Input is given from Standard Input in the following format: a b -----Output----- If the product is odd, print Odd; if it is even, print Even. -----Sample Input----- 3 4 -----Sample Output----- Even As 3 × 4 = 12 is even, print Even.
[ "3 4\n", "1 21\n", "4 4", "1 15", "2 4", "2 15", "3 0", "2 26", "3 -1", "2 32" ]
[ "Even\n", "Odd\n", "Even\n", "Odd\n", "Even\n", "Even\n", "Even\n", "Even\n", "Odd\n", "Even\n" ]
1
stdio
Not considering number 1, the integer 153 is the first integer having this property: the sum of the third-power of each of its digits is equal to 153. Take a look: 153 = 1^3 + 5^3 + 3^3 = 1 + 125 + 27 = 153 The next number that experiments this particular behaviour is 370 with the same power. Write the function `eq_sum_powdig()`, that finds the numbers below a given upper limit `hMax` that fulfill this property but with different exponents as a power for the digits. eq_sum_powdig(hMax, exp): ----> sequence of numbers (sorted list) (Number one should not be considered). Let's see some cases: ```python eq_sum_powdig(100, 2) ----> [] eq_sum_powdig(1000, 2) ----> [] eq_sum_powdig(200, 3) ----> [153] eq_sum_powdig(370, 3) ----> [153, 370] ``` Enjoy it !! Write your solution by modifying this code: ```python def eq_sum_powdig(hMax, exp): ``` Your solution should implemented in the function "eq_sum_powdig". The inputs will be passed to it and it should return the correct solution. Now solve the problem and return the code.
[]
[]
1
stdio
Tavak and Seyyed are good friends. Seyyed is very funny and he told Tavak to solve the following problem instead of longest-path. You are given l and r. For all integers from l to r, inclusive, we wrote down all of their integer divisors except 1. Find the integer that we wrote down the maximum number of times. Solve the problem to show that it's not a NP problem. -----Input----- The first line contains two integers l and r (2 ≤ l ≤ r ≤ 10^9). -----Output----- Print single integer, the integer that appears maximum number of times in the divisors. If there are multiple answers, print any of them. -----Examples----- Input 19 29 Output 2 Input 3 6 Output 3 -----Note----- Definition of a divisor: https://www.mathsisfun.com/definitions/divisor-of-an-integer-.html The first example: from 19 to 29 these numbers are divisible by 2: {20, 22, 24, 26, 28}. The second example: from 3 to 6 these numbers are divisible by 3: {3, 6}.
[ "19 29\n", "3 6\n", "39 91\n", "76 134\n", "93 95\n", "17 35\n", "94 95\n", "51 52\n", "47 52\n", "38 98\n" ]
[ "2\n", "2\n", "2\n", "2\n", "2\n", "2\n", "2\n", "2\n", "2\n", "2\n" ]
1
stdio
Read problems statements in Mandarin Chinese and Russian. Chef had a hard day and want to play little bit. The game is called "Chain". Chef has the sequence of symbols. Each symbol is either '-' or '+'. The sequence is called Chain if each two neighboring symbols of sequence are either '-+' or '+-'. For example sequence '-+-+-+' is a Chain but sequence '-+-+--+' is not. Help Chef to calculate the minimum number of symbols he need to replace (ex. '-' to '+' or '+' to '-') to receive a Chain sequence. ------ Input ------ First line contains single integer T denoting the number of test cases. Line of each test case contains the string S consisting of symbols '-' and '+'. ------ Output ------ For each test case, in a single line print single interger - the minimal number of symbols Chef needs to replace to receive a Chain. ------ Constraints ------ $1 ≤ T ≤ 7$ $1 ≤ |S| ≤ 10^{5}$ ------ Subtasks ------ $Subtask 1 ≤ |S| ≤ 10, 1 ≤ T ≤ 7 Points: 20 $ $Subtask 1 ≤ |S| ≤ 1000, 1 ≤ T ≤ 7 Points: 30 $ $Subtask 1 ≤ |S| ≤ 10^{5}, 1 ≤ T ≤ 7Points: 50 $ ----- Sample Input 1 ------ 2 ---+-+-+++ ------- ----- Sample Output 1 ------ 2 3 ----- explanation 1 ------ Example case 1. We can change symbol 2 from '-' to '+' and symbol 9 from '+' to '-' and receive '-+-+-+-+-+'. Example case 2. We can change symbols 2, 4 and 6 from '-' to '+' and receive '-+-+-+-'.
[ "2\n---+-+-+++\n-------", "2\n+++-+-+---\n-------", "2\n-+--+++--+\n-------", "2\n-+-+-+-+-+\n-------", "2\n--++---+++\n-----+-", "2\n---+-+-+++\n-----+-", "2\n+-+-+-+--+\n-------", "2\n---+++-+-+\n-------", "2\n-+-+++---+\n-------", "2\n+-+++----+\n-------" ]
[ "2\n3", "2\n3\n", "4\n3\n", "0\n3\n", "4\n2\n", "2\n2\n", "2\n3\n", "2\n3\n", "2\n3\n", "4\n3\n" ]
1
stdio
The chef has a recipe he wishes to use for his guests, but the recipe will make far more food than he can serve to the guests. The chef therefore would like to make a reduced version of the recipe which has the same ratios of ingredients, but makes less food. The chef, however, does not like fractions. The original recipe contains only whole numbers of ingredients, and the chef wants the reduced recipe to only contain whole numbers of ingredients as well. Help the chef determine how much of each ingredient to use in order to make as little food as possible. ------ Input ------ Input will begin with an integer T, the number of test cases. Each test case consists of a single line. The line begins with a positive integer N, the number of ingredients. N integers follow, each indicating the quantity of a particular ingredient that is used. ------ Output ------ For each test case, output exactly N space-separated integers on a line, giving the quantity of each ingredient that the chef should use in order to make as little food as possible. ------ Constraints ------ T ≤ 100 2 ≤ N ≤ 50 All ingredient quantities are between 1 and 1000, inclusive. ----- Sample Input 1 ------ 3 2 4 4 3 2 3 4 4 3 15 9 6 ----- Sample Output 1 ------ 1 1 2 3 4 1 5 3 2
[ "3\n2 4 4\n3 2 3 4\n4 3 15 9 6", "3\n2 4 4\n3 2 3 4\n4 3 20 9 6", "3\n2 4 4\n3 2 1 4\n4 3 15 9 6", "3\n2 4 4\n3 2 3 4\n4 3 20 9 8", "3\n2 4 7\n3 2 1 4\n4 3 15 9 6", "3\n2 4 4\n3 2 3 6\n4 3 20 9 8", "3\n2 4 4\n3 2 3 8\n4 3 15 9 6", "3\n2 4 8\n3 2 3 4\n4 3 20 9 6", "3\n2 4 8\n3 2 1 4\n4 3 15 9 6", "...
[ "1 1\n2 3 4\n1 5 3 2", "1 1\n2 3 4\n3 20 9 6\n", "1 1\n2 1 4\n1 5 3 2\n", "1 1\n2 3 4\n3 20 9 8\n", "4 7\n2 1 4\n1 5 3 2\n", "1 1\n2 3 6\n3 20 9 8\n", "1 1\n2 3 8\n1 5 3 2\n", "1 2\n2 3 4\n3 20 9 6\n", "1 2\n2 1 4\n1 5 3 2\n", "1 1\n3 3 8\n1 5 3 2\n" ]
1
stdio
You are given a sequence of N integer numbers A. Calculate the sum of A_{i} AND A_{j} for all the pairs (i, j) where i < j. The AND operation is the Bitwise AND operation, defined as in here. ------ Input ------ The first line of input consists of the integer N. The second line contains N integer numbers - the sequence A. ------ Output ------ Output the answer to the problem on the first line of the output. ------ Scoring ------ Subtask 1 (13 points): N ≤ 1000, A_{i} ≤ 1. Subtask 2 (39 points): N ≤ 1000, A_{i} ≤ 10^{9}. Subtask 3 (21 points): N ≤ 10^{5}, A_{i} ≤ 1. Subtask 4 (27 points): N ≤ 10^{5}, A_{i} ≤ 10^{6}. ----- Sample Input 1 ------ 5 1 2 3 4 5 ----- Sample Output 1 ------ 9
[ "5\n1 2 3 4 5", "5\n2 2 3 4 5", "5\n2 2 6 4 5", "5\n0 2 6 4 5", "5\n1 2 5 4 6", "5\n0 2 3 4 5", "5\n2 2 6 6 5", "5\n1 2 8 4 6", "5\n0 2 5 4 4", "5\n0 2 3 0 5" ]
[ "9", "11\n", "18\n", "14\n", "15\n", "7\n", "24\n", "6\n", "12\n", "3\n" ]
1
stdio
We'll call an array of n non-negative integers a[1], a[2], ..., a[n] interesting, if it meets m constraints. The i-th of the m constraints consists of three integers li, ri, qi (1 ≤ li ≤ ri ≤ n) meaning that value <image> should be equal to qi. Your task is to find any interesting array of n elements or state that such array doesn't exist. Expression x&y means the bitwise AND of numbers x and y. In programming languages C++, Java and Python this operation is represented as "&", in Pascal — as "and". Input The first line contains two integers n, m (1 ≤ n ≤ 105, 1 ≤ m ≤ 105) — the number of elements in the array and the number of limits. Each of the next m lines contains three integers li, ri, qi (1 ≤ li ≤ ri ≤ n, 0 ≤ qi < 230) describing the i-th limit. Output If the interesting array exists, in the first line print "YES" (without the quotes) and in the second line print n integers a[1], a[2], ..., a[n] (0 ≤ a[i] < 230) decribing the interesting array. If there are multiple answers, print any of them. If the interesting array doesn't exist, print "NO" (without the quotes) in the single line. Examples Input 3 1 1 3 3 Output YES 3 3 3 Input 3 2 1 3 3 1 3 2 Output NO
[ "1 2\n1 1 1\n1 1 3\n", "1 1\n1 1 10\n", "1 2\n1 1 10\n1 1 5\n", "3 2\n1 2 536870912\n2 3 536870911\n", "1 1\n1 1 19\n", "3 2\n1 2 536870912\n3 3 536870911\n", "3 2\n1 2 536870912\n3 3 952275870\n", "3 2\n1 2 536870912\n3 3 121805432\n", "1 1\n1 1 11\n", "3 2\n1 2 536870912\n2 3 331461822\n" ]
[ "NO\n", "YES\n10\n", "NO\n", "YES\n536870912 1073741823 536870911\n", "YES\n19\n", "YES\n536870912 536870912 536870911\n", "YES\n536870912 536870912 952275870\n", "YES\n536870912 536870912 121805432\n", "YES\n11\n", "YES\n536870912 868332734 331461822\n" ]
1
stdio
Given a long number, return all the possible sum of two digits of it. For example, `12345`: all possible sum of two digits from that number are: [ 1 + 2, 1 + 3, 1 + 4, 1 + 5, 2 + 3, 2 + 4, 2 + 5, 3 + 4, 3 + 5, 4 + 5 ] Therefore the result must be: [ 3, 4, 5, 6, 5, 6, 7, 7, 8, 9 ] Write your solution by modifying this code: ```python def digits(num): ``` Your solution should implemented in the function "digits". 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 given weighted directed graph G(V, E), find the distance of the shortest route that meets the following criteria: * It is a closed cycle where it ends at the same point it starts. * It visits each vertex exactly once. Constraints * 2 ≤ |V| ≤ 15 * 0 ≤ di ≤ 1,000 * There are no multiedge Input |V| |E| s0 t0 d0 s1 t1 d1 : s|E|-1 t|E|-1 d|E|-1 |V| is the number of vertices and |E| is the number of edges in the graph. The graph vertices are named with the numbers 0, 1,..., |V|-1 respectively. si and ti represent source and target vertices of i-th edge (directed) and di represents the distance between si and ti (the i-th edge). Output Print the shortest distance in a line. If there is no solution, print -1. Examples Input 4 6 0 1 2 1 2 3 1 3 9 2 0 1 2 3 6 3 2 4 Output 16 Input 3 3 0 1 1 1 2 1 0 2 1 Output -1
[ "3 3\n0 0 1\n1 2 1\n0 2 1", "4 6\n0 1 2\n2 2 3\n1 3 9\n2 0 1\n2 3 6\n3 2 4", "4 6\n0 1 2\n2 2 3\n1 3 1\n2 0 1\n2 3 6\n3 2 4", "4 6\n0 1 2\n2 2 3\n1 3 14\n2 0 1\n2 3 19\n3 2 4", "1 1\n0 0 0\n1 2 1\n0 2 1", "4 6\n0 1 2\n2 2 3\n1 3 8\n2 0 1\n2 3 19\n3 2 4", "3 3\n0 0 1\n2 2 1\n0 2 1", "3 3\n0 1 1\n1 2 1\...
[ "-1\n", "16\n", "8\n", "21\n", "0\n", "15\n", "-1\n", "-1\n", "-1\n", "-1\n" ]
1
stdio
For given $N$ points in the 2D Euclidean plane, find the distance of the shortest tour that meets the following criteria: * Visit the points according to the following steps: 1. It starts from the leftmost point (starting point), goes strictly from left to right, and then visits the rightmost point (turn-around point). 2. Then it starts from the turn-around point, goes strictly from right to left, and then back to the starting point. * Through the processes 1. 2., the tour must visit each point at least once. Constraints * $2 \leq N \leq 1000$ * $-1000 \leq x_i, y_i \leq 1000$ * $x_i$ differ from each other * The given points are already sorted by x-coordinates Input The input data is given in the following format: $N$ $x_1$ $y_1$ $x_2$ $y_2$ ... $x_N$ $y_N$ Output Print the distance of the shortest tour in a line. The output should not have an error greater than 0.0001. Examples Input 3 0 0 1 1 2 0 Output 4.82842712 Input 4 0 1 1 2 2 0 3 1 Output 7.30056308 Input 5 0 0 1 2 2 1 3 2 4 0 Output 10.94427191
[ "3\n0 -1\n1 1\n2 0", "5\n-1 0\n1 2\n2 1\n3 2\n4 0", "4\n0 1\n1 2\n3 0\n3 1", "3\n0 -1\n1 2\n2 0", "4\n0 1\n1 4\n3 0\n3 1", "3\n0 -1\n1 0\n2 0", "4\n0 0\n1 4\n3 0\n3 1", "3\n0 -1\n1 0\n0 0", "4\n0 0\n1 6\n3 0\n3 1", "3\n0 0\n1 0\n0 0" ]
[ "5.886349517\n", "12.462840740\n", "7.812559200\n", "7.634413615\n", "10.930106596\n", "4.650281540\n", "11.728656901\n", "3.414213562\n", "15.467927337\n", "2.000000000\n" ]
1
stdio
Write a function that when given a URL as a string, parses out just the domain name and returns it as a string. For example: ```python domain_name("http://github.com/carbonfive/raygun") == "github" domain_name("http://www.zombie-bites.com") == "zombie-bites" domain_name("https://www.cnet.com") == "cnet" ``` Write your solution by modifying this code: ```python def domain_name(url): ``` Your solution should implemented in the function "domain_name". 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 are given two strings s and t consisting of lowercase English letters and an integer L. We will consider generating a string of length L by concatenating one or more copies of s and t. Here, it is allowed to use the same string more than once. For example, when s = `at`, t = `code` and L = 6, the strings `atatat`, `atcode` and `codeat` can be generated. Among the strings that can be generated in this way, find the lexicographically smallest one. In the cases given as input, it is always possible to generate a string of length L. Constraints * 1 ≤ L ≤ 2 × 10^5 * 1 ≤ |s|, |t| ≤ L * s and t consist of lowercase English letters. * It is possible to generate a string of length L in the way described in Problem Statement. Input Input is given from Standard Input in the following format: N x_1 s_1 x_2 s_2 : x_N s_N Output Print the lexicographically smallest string among the ones that can be generated in the way described in Problem Statement. Examples Input 6 at code Output atatat Input 8 coding festival Output festival Input 8 same same Output samesame Input 10 coin age Output ageagecoin
[ "10\ncoin\nahe", "8\ncoding\nfestiual", "6\nat\ncnde", "8\nsamd\nsame", "10\ncoin\naeh", "10\nnioc\naeh", "6\nta\nncde", "8\nsame\nsmae", "10\ncnin\naeh", "8\ngnicoc\nfisteual" ]
[ "aheahecoin\n", "festiual\n", "atatat\n", "samdsamd\n", "aehaehcoin\n", "aehaehnioc\n", "ncdeta\n", "samesame\n", "aehaehcnin\n", "fisteual\n" ]
1
stdio
You are given a range of positive integers from $l$ to $r$. Find such a pair of integers $(x, y)$ that $l \le x, y \le r$, $x \ne y$ and $x$ divides $y$. If there are multiple answers, print any of them. You are also asked to answer $T$ independent queries. -----Input----- The first line contains a single integer $T$ ($1 \le T \le 1000$) — the number of queries. Each of the next $T$ lines contains two integers $l$ and $r$ ($1 \le l \le r \le 998244353$) — inclusive borders of the range. It is guaranteed that testset only includes queries, which have at least one suitable pair. -----Output----- Print $T$ lines, each line should contain the answer — two integers $x$ and $y$ such that $l \le x, y \le r$, $x \ne y$ and $x$ divides $y$. The answer in the $i$-th line should correspond to the $i$-th query from the input. If there are multiple answers, print any of them. -----Example----- Input 3 1 10 3 14 1 10 Output 1 7 3 9 5 10
[ "3\n1 10\n3 14\n1 10\n", "3\n6969 696969\n6969 696969\n6969 696969\n", "1\n696969 100000000\n", "1\n69696969 998244353\n", "1\n69696969 998244353\n", "1\n696969 100000000\n", "3\n6969 696969\n6969 696969\n6969 696969\n", "3\n1 10\n3 14\n1 10\n", "1\n81363505 998244353\n", "1\n1163931 100000000\n" ...
[ "1 2\n3 6\n1 2\n", "6969 13938\n6969 13938\n6969 13938\n", "696969 1393938\n", "69696969 139393938\n", "69696969 139393938\n", "696969 1393938\n", "6969 13938\n6969 13938\n6969 13938\n", "1 2\n3 6\n1 2\n", "81363505 162727010\n", "1163931 2327862\n" ]
1
stdio
Vitaly is a diligent student who never missed a lesson in his five years of studying in the university. He always does his homework on time and passes his exams in time. During the last lesson the teacher has provided two strings s and t to Vitaly. The strings have the same length, they consist of lowercase English letters, string s is lexicographically smaller than string t. Vitaly wondered if there is such string that is lexicographically larger than string s and at the same is lexicographically smaller than string t. This string should also consist of lowercase English letters and have the length equal to the lengths of strings s and t. Let's help Vitaly solve this easy problem! Input The first line contains string s (1 ≤ |s| ≤ 100), consisting of lowercase English letters. Here, |s| denotes the length of the string. The second line contains string t (|t| = |s|), consisting of lowercase English letters. It is guaranteed that the lengths of strings s and t are the same and string s is lexicographically less than string t. Output If the string that meets the given requirements doesn't exist, print a single string "No such string" (without the quotes). If such string exists, print it. If there are multiple valid strings, you may print any of them. Examples Input a c Output b Input aaa zzz Output kkk Input abcdefg abcdefh Output No such string Note String s = s1s2... sn is said to be lexicographically smaller than t = t1t2... tn, if there exists such i, that s1 = t1, s2 = t2, ... si - 1 = ti - 1, si < ti.
[ "pkjlxzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\npkjlyaaaaaaaaaaaaaaaaaaaaaaaaaaaahr\n", "kexdbtpkjbwwyibjndbtmwqzolopqitgkomqggojevoankiepxirrcidxldlzsppehmoazdywltmjbxgsxgihwnwpmczjrcwpywl\nkexdbtpkjbwwyibjndbtmwqzolopqitgkomqggojevoankiepxirrcidxldlzsppehmoazdywltmjbxgsxgihwnwpmczjrcwpywm\n", "ddzzzzzzzzzzzzzzzzzzzzzzz...
[ "pkjlyaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "No such string", "deaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "aab", "baaa", "abcdefh", "No such string", "xqzbhslocdbifnyzyjenlpctocieaccsycmwlcebkqqkeibatfvylbqlutvjijgjhdetqsjqnoipqbmjhhzxggdobyvpczda...
1
stdio
You wrote all your unit test names in camelCase. But some of your colleagues have troubles reading these long test names. So you make a compromise to switch to underscore separation. To make these changes fast you wrote a class to translate a camelCase name into an underscore separated name. Implement the ToUnderscore() method. Example: `"ThisIsAUnitTest" => "This_Is_A_Unit_Test"` **But of course there are always special cases...** You also have some calculation tests. Make sure the results don't get split by underscores. So only add an underscore in front of the first number. Also Some people already used underscore names in their tests. You don't want to change them. But if they are not split correct you should adjust them. Some of your colleagues mark their tests with a leading and trailing underscore. Don't remove this. And of course you should handle empty strings to avoid unnecessary errors. Just return an empty string then. Example: `"Calculate15Plus5Equals20" => "Calculate_15_Plus_5_Equals_20"` `"This_Is_Already_Split_Correct" => "This_Is_Already_Split_Correct"` `"ThisIs_Not_SplitCorrect" => "This_Is_Not_Split_Correct"` `"_UnderscoreMarked_Test_Name_" => _Underscore_Marked_Test_Name_"` Write your solution by modifying this code: ```python def toUnderScore(name): ``` Your solution should implemented in the function "toUnderScore". 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 would like to get the 'weight' of a name by getting the sum of the ascii values. However you believe that capital letters should be worth more than mere lowercase letters. Spaces, numbers, or any other character are worth 0. Normally in ascii a has a value of 97 A has a value of 65 ' ' has a value of 32 0 has a value of 48 To find who has the 'weightier' name you will switch all the values so: A will be 97 a will be 65 ' ' will be 0 0 will be 0 etc... For example Joe will have a weight of 254, instead of 286 using normal ascii values. Write your solution by modifying this code: ```python def get_weight(name): ``` Your solution should implemented in the function "get_weight". The inputs will be passed to it and it should return the correct solution. Now solve the problem and return the code.
[]
[]
1
stdio
Snuke has come to a store that sells boxes containing balls. The store sells the following three kinds of boxes: * Red boxes, each containing R red balls * Green boxes, each containing G green balls * Blue boxes, each containing B blue balls Snuke wants to get a total of exactly N balls by buying r red boxes, g green boxes and b blue boxes. How many triples of non-negative integers (r,g,b) achieve this? Constraints * All values in input are integers. * 1 \leq R,G,B,N \leq 3000 Input Input is given from Standard Input in the following format: R G B N Output Print the answer. Examples Input 1 2 3 4 Output 4 Input 13 1 4 3000 Output 87058
[ "1 2 3 1", "13 1 4 540", "1 2 3 2", "17 1 4 540", "13 2 4 3000", "13 1 4 97", "18 1 4 540", "13 2 1 3000", "13 1 4 62", "13 1 4 92" ]
[ "1\n", "2898\n", "2\n", "2232\n", "43732\n", "108\n", "2116\n", "174001\n", "48\n", "98\n" ]
1
stdio
If you like Taco Bell, you will be familiar with their signature doritos locos taco. They're very good. Why can't everything be a taco? We're going to attempt that here, turning every word we find into the taco bell recipe with each ingredient. We want to input a word as a string, and return a list representing that word as a taco. ***Key*** all vowels (except 'y') = beef t = tomato l = lettuce c = cheese g = guacamole s = salsa ***NOTE*** We do not care about case here. 'S' is therefore equivalent to 's' in our taco. Ignore all other letters; we don't want our taco uneccesarily clustered or else it will be too difficult to eat. Note that no matter what ingredients are passed, our taco will always have a shell. Write your solution by modifying this code: ```python def tacofy(word): ``` Your solution should implemented in the function "tacofy". The inputs will be passed to it and it should return the correct solution. Now solve the problem and return the code.
[]
[]
1
stdio
Vanya wants to pass n exams and get the academic scholarship. He will get the scholarship if the average grade mark for all the exams is at least avg. The exam grade cannot exceed r. Vanya has passed the exams and got grade a_{i} for the i-th exam. To increase the grade for the i-th exam by 1 point, Vanya must write b_{i} essays. He can raise the exam grade multiple times. What is the minimum number of essays that Vanya needs to write to get scholarship? -----Input----- The first line contains three integers n, r, avg (1 ≤ n ≤ 10^5, 1 ≤ r ≤ 10^9, 1 ≤ avg ≤ min(r, 10^6)) — the number of exams, the maximum grade and the required grade point average, respectively. Each of the following n lines contains space-separated integers a_{i} and b_{i} (1 ≤ a_{i} ≤ r, 1 ≤ b_{i} ≤ 10^6). -----Output----- In the first line print the minimum number of essays. -----Examples----- Input 5 5 4 5 2 4 7 3 1 3 2 2 5 Output 4 Input 2 5 4 5 2 5 2 Output 0 -----Note----- In the first sample Vanya can write 2 essays for the 3rd exam to raise his grade by 2 points and 2 essays for the 4th exam to raise his grade by 1 point. In the second sample, Vanya doesn't need to write any essays as his general point average already is above average.
[ "5 5 4\n5 2\n4 7\n3 1\n3 2\n2 5\n", "2 5 4\n5 2\n5 2\n", "6 5 5\n1 7\n2 4\n3 5\n4 6\n5 6\n4 7\n", "1 1000000000 1000000\n1 1000000\n", "10 10 7\n1 10\n2 9\n3 8\n4 7\n5 6\n6 5\n7 4\n8 3\n9 2\n10 1\n", "3 5 2\n1 10\n1 7\n1 4\n", "10 10 10\n9 8\n3 9\n3 6\n10 5\n5 5\n6 10\n10 3\n6 7\n2 3\n9 8\n", "1 1 1\n...
[ "4\n", "0\n", "63\n", "999999000000\n", "70\n", "12\n", "238\n", "0\n", "54\n", "10\n" ]
1
stdio
We have a sandglass that runs for X seconds. The sand drops from the upper bulb at a rate of 1 gram per second. That is, the upper bulb initially contains X grams of sand. How many grams of sand will the upper bulb contains after t seconds? -----Constraints----- - 1≤X≤10^9 - 1≤t≤10^9 - X and t are integers. -----Input----- The input is given from Standard Input in the following format: X t -----Output----- Print the number of sand in the upper bulb after t second. -----Sample Input----- 100 17 -----Sample Output----- 83 17 out of the initial 100 grams of sand will be consumed, resulting in 83 grams.
[ "100 17\n", "48 58\n", "1000000000 1000000000\n", "48 39", "1000000010 1000000000", "000 17", "48 19", "1001000010 1000000000", "48 0", "1001000010 1000010000" ]
[ "83\n", "0\n", "0\n", "9\n", "10\n", "0\n", "29\n", "1000010\n", "48\n", "990010\n" ]
1
stdio
Oh no! Ghosts have reportedly swarmed the city. It's your job to get rid of them and save the day! In this kata, strings represent buildings while whitespaces within those strings represent ghosts. So what are you waiting for? Return the building(string) without any ghosts(whitespaces)! Example: Should return: If the building contains no ghosts, return the string: Write your solution by modifying this code: ```python def ghostbusters(building): ``` Your solution should implemented in the function "ghostbusters". 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 an arbitrary number of strings and interlaces them (combines them by alternating characters from each string). For example `combineStrings('abc', '123')` should return `'a1b2c3'`. If the strings are different lengths the function should interlace them until each string runs out, continuing to add characters from the remaining strings. For example `combineStrings('abcd', '123')` should return `'a1b2c3d'`. The function should take any number of arguments and combine them. For example `combineStrings('abc', '123', '£$%')` should return `'a1£b2$c3%'`. **Note: if only one argument is passed return only that string. If no arguments are passed return an empty string.** Write your solution by modifying this code: ```python def combine_strings(*args): ``` Your solution should implemented in the function "combine_strings". 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 is an image with a height of H pixels and a width of W pixels. Each of the pixels is represented by either . or *. The character representing the pixel at the i-th row from the top and the j-th column from the left, is denoted by C_{i,j}. Extend this image vertically so that its height is doubled. That is, print a image with a height of 2H pixels and a width of W pixels where the pixel at the i-th row and j-th column is equal to C_{(i+1)/2,j} (the result of division is rounded down). -----Constraints----- - 1≦H, W≦100 - C_{i,j} is either . or *. -----Input----- The input is given from Standard Input in the following format: H W C_{1,1}...C_{1,W} : C_{H,1}...C_{H,W} -----Output----- Print the extended image. -----Sample Input----- 2 2 *. .* -----Sample Output----- *. *. .* .*
[ "2 2\n*.\n.*\n", "1 4\n***.\n", "9 20\n.....***....***.....\n....*...*..*...*....\n...*.....**.....*...\n...*.....*......*...\n....*.....*....*....\n.....**..*...**.....\n.......*..*.*.......\n........**.*........\n.........**.........\n", "9 20\n.....***....***.....\n....*...*..*...*....\n...*.....**.....*.....
[ "*.\n*.\n.*\n.*\n", "***.\n***.\n", ".....***....***.....\n.....***....***.....\n....*...*..*...*....\n....*...*..*...*....\n...*.....**.....*...\n...*.....**.....*...\n...*.....*......*...\n...*.....*......*...\n....*.....*....*....\n....*.....*....*....\n.....**..*...**.....\n.....**..*...**.....\n.......*..*...
1
stdio
Witua is a little student from the University of Lviv. He enjoys studying math. Witua knows a lot of famous mathematicians like Eratosthenes, Pythagoras, Fermat, Diophantus, Furko, Gauss and so on. However, his favorite one is Euler. The only thing Witua likes more than Euler is Euler’s totient function φ. He is exploring the nature of this function. One of the steps of his work is finding φ(i)/i for all 2≤i≤N. He doesn’t need to know every such value, but Witua wonders for what value i, is φ(i)/i the maximum he can get? Help little student to find such i that φ(i)/i is maximum among all the 2≤i≤N. -----Input----- The first line contains single integer T - the number of test cases. Each of the next T lines contains a single integer N. -----Output----- For every test case output i such that φ(i)/i is maximum among all i (2≤i≤N) in a separate line. -----Constrains----- T (1≤T≤500 ) N(2≤N≤10^18) -----Example----- Input: 3 2 3 4 Output: 2 3 3 Explanationφ(2)/2=1/2 φ(3)/3=2/3 φ(4)/4=2/4
[ "3\n2\n3\n4\n", "3\n4\n3\n4", "3\n4\n2\n4", "3\n6\n2\n3", "3\n6\n2\n7", "3\n12\n2\n7", "3\n14\n2\n7", "3\n2\n2\n4", "3\n6\n4\n3", "3\n14\n3\n7" ]
[ "2\n3\n3\n", "3\n3\n3\n", "3\n2\n3\n", "5\n2\n3\n", "5\n2\n7\n", "11\n2\n7\n", "13\n2\n7\n", "2\n2\n3\n", "5\n3\n3\n", "13\n3\n7\n" ]
1
stdio
Read problems statements in Mandarin Chinese and Russian. You are given a multiset of N integers. Please find such a nonempty subset of it that the sum of the subset's elements is divisible by N. Otherwise, state that this subset doesn't exist. ------ Input ------ The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows. The first line of each test consists of a single integer N - the size of the multiset. The second line of each test contains N single space separated integers - the multiset's elements. ------ Output ------ For each test case output: -1 if the required subset doesn't exist If the required subset exists, output two lines. Output the size of the subset on the first line and output the list of indices of the multiset's element that form the required subset. Of course, any number can be taken in the subset no more than once. If there are several such subsets, you can output any. ------ Constraints ------ $1 ≤ The sum of N over all the test cases ≤ 10^{5}$ $Each element of the multiset is a positive integer, not exceeding 10^{9}.$ $1 ≤ N ≤ 15 : 37 points. $ $1 ≤ N ≤ 1000 : 24 points.$ $1 ≤ N ≤ 10^{5} : 39 points. $ ------ Example ------ Input: 1 3 4 6 10 Output: 1 2 ------ Explanation ------ We can pick {6} as the subset, then its sum is 6 and this is divisible by 3 - the size of the initial multiset.
[ "1\n3\n4 6 10", "1\n3\n4 6 16", "1\n3\n4 11 3", "1\n3\n2 11 3", "1\n3\n0 6 10", "1\n3\n4 4 4", "1\n3\n2 5 1", "1\n3\n4 6 4", "1\n3\n4 6 0", "1\n3\n4 6 3" ]
[ "1\n2", "1\n2 \n", "2\n1 2 \n", "1\n3 \n", "1\n1 \n", "3\n1 2 3 \n", "2\n2 3 \n", "1\n2 \n", "1\n2 \n", "1\n2 \n" ]
1
stdio
Today at the lesson Vitya learned a very interesting function — mex. Mex of a sequence of numbers is the minimum non-negative number that is not present in the sequence as element. For example, mex([4, 33, 0, 1, 1, 5]) = 2 and mex([1, 2, 3]) = 0. Vitya quickly understood all tasks of the teacher, but can you do the same? You are given an array consisting of n non-negative integers, and m queries. Each query is characterized by one number x and consists of the following consecutive steps: * Perform the bitwise addition operation modulo 2 (xor) of each array element with the number x. * Find mex of the resulting array. Note that after each query the array changes. Input First line contains two integer numbers n and m (1 ≤ n, m ≤ 3·105) — number of elements in array and number of queries. Next line contains n integer numbers ai (0 ≤ ai ≤ 3·105) — elements of then array. Each of next m lines contains query — one integer number x (0 ≤ x ≤ 3·105). Output For each query print the answer on a separate line. Examples Input 2 2 1 3 1 3 Output 1 0 Input 4 3 0 1 5 6 1 2 4 Output 2 0 0 Input 5 4 0 1 5 6 7 1 1 4 5 Output 2 2 0 2
[ "10 30\n0 0 0 0 0 0 0 0 0 0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n", "5 5\n1 2 3 4 5\n1\n2\n3\n4\n5\n", "17 30\n4194 1990 2257 1363 2798 386 3311 3152 1808 1453 3874 4388 1268 3924 3799 1269 968\n8\n8\n8\n8\n8\n8\n8\n8\n8\n8\n8\n8\n8\n8\n8\n8\n8\n8\n8\n8\n8\n...
[ "1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n", "1\n3\n0\n2\n1\n", "0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n", "0\n2\n0\n", "1\n0\n0\n2\n1\n", "0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n...
1
stdio
You have unlimited number of coins with values $1, 2, \ldots, n$. You want to select some set of coins having the total value of $S$. It is allowed to have multiple coins with the same value in the set. What is the minimum number of coins required to get sum $S$? -----Input----- The only line of the input contains two integers $n$ and $S$ ($1 \le n \le 100\,000$, $1 \le S \le 10^9$) -----Output----- Print exactly one integer — the minimum number of coins required to obtain sum $S$. -----Examples----- Input 5 11 Output 3 Input 6 16 Output 3 -----Note----- In the first example, some of the possible ways to get sum $11$ with $3$ coins are: $(3, 4, 4)$ $(2, 4, 5)$ $(1, 5, 5)$ $(3, 3, 5)$ It is impossible to get sum $11$ with less than $3$ coins. In the second example, some of the possible ways to get sum $16$ with $3$ coins are: $(5, 5, 6)$ $(4, 6, 6)$ It is impossible to get sum $16$ with less than $3$ coins.
[ "5 11\n", "6 16\n", "14 28\n", "5 29\n", "10 24\n", "1 30\n", "14969 66991573\n", "1 1000000000\n", "100000 1\n", "10 46\n" ]
[ "3", "3", "2", "6", "3", "30", "4476", "1000000000", "1", "5" ]
1
stdio
How many strings can be obtained by applying the following operation on a string S exactly K times: "choose one lowercase English letter and insert it somewhere"? The answer can be enormous, so print it modulo (10^9+7). -----Constraints----- - K is an integer between 1 and 10^6 (inclusive). - S is a string of length between 1 and 10^6 (inclusive) consisting of lowercase English letters. -----Input----- Input is given from Standard Input in the following format: K S -----Output----- Print the number of strings satisfying the condition, modulo (10^9+7). -----Sample Input----- 5 oof -----Sample Output----- 575111451 For example, we can obtain proofend, moonwolf, and onionpuf, while we cannot obtain oofsix, oofelevennn, voxafolt, or fooooooo.
[ "5\noof\n", "37564\nwhydidyoudesertme\n", "5\nooe", "37564\nwhydidzoudesertme", "5\neoo", "37564\nwhxdidzoudesertme", "5\ndoo", "37564\nwhxdidzoudesertne", "5\ndop", "37564\nwhxdiczoudesertne" ]
[ "575111451\n", "318008117\n", "575111451\n", "318008117\n", "575111451\n", "318008117\n", "575111451\n", "318008117\n", "575111451\n", "318008117\n" ]
1
stdio
Your boss decided to save money by purchasing some cut-rate optical character recognition software for scanning in the text of old novels to your database. At first it seems to capture words okay, but you quickly notice that it throws in a lot of numbers at random places in the text. For example: ```python string_clean('! !') == '! !' string_clean('123456789') == '' string_clean('This looks5 grea8t!') == 'This looks great!' ``` Your harried co-workers are looking to you for a solution to take this garbled text and remove all of the numbers. Your program will take in a string and clean out all numeric characters, and return a string with spacing and special characters `~#$%^&!@*():;"'.,?` all intact. Write your solution by modifying this code: ```python def string_clean(s): ``` Your solution should implemented in the function "string_clean". The inputs will be passed to it and it should return the correct solution. Now solve the problem and return the code.
[]
[]
1
stdio
Snuke is standing on a two-dimensional plane. In one operation, he can move by 1 in the positive x-direction, or move by 1 in the positive y-direction. Let us define a function f(r, c) as follows: - f(r,c) := (The number of paths from the point (0, 0) to the point (r, c) that Snuke can trace by repeating the operation above) Given are integers r_1, r_2, c_1, and c_2. Find the sum of f(i, j) over all pair of integers (i, j) such that r_1 ≤ i ≤ r_2 and c_1 ≤ j ≤ c_2, and compute this value modulo (10^9+7). -----Constraints----- - 1 ≤ r_1 ≤ r_2 ≤ 10^6 - 1 ≤ c_1 ≤ c_2 ≤ 10^6 - All values in input are integers. -----Input----- Input is given from Standard Input in the following format: r_1 c_1 r_2 c_2 -----Output----- Print the sum of f(i, j) modulo (10^9+7). -----Sample Input----- 1 1 2 2 -----Sample Output----- 14 For example, there are two paths from the point (0, 0) to the point (1, 1): (0,0) → (0,1) → (1,1) and (0,0) → (1,0) → (1,1), so f(1,1)=2. Similarly, f(1,2)=3, f(2,1)=3, and f(2,2)=6. Thus, the sum is 14.
[ "1 1 2 2\n", "314 159 2653 589\n", "1 1 1000000 1000000\n", "349 602 998593 983904\n", "33400 31000 33400 593020\n", "1999 1322 290329 1325\n", "799999 789898 979797 999999\n", "1000000 1000000 1000000 1000000\n", "53245 34234 643323 948342\n", "3 3 3 3\n" ]
[ "14\n", "602215194\n", "625314154\n", "601079779\n", "67962523\n", "333678807\n", "50188529\n", "192151600\n", "574642047\n", "20\n" ]
1
stdio
Phoenix is playing with a new puzzle, which consists of $n$ identical puzzle pieces. Each puzzle piece is a right isosceles triangle as shown below. A puzzle piece The goal of the puzzle is to create a square using the $n$ pieces. He is allowed to rotate and move the pieces around, but none of them can overlap and all $n$ pieces must be used (of course, the square shouldn't contain any holes as well). Can he do it? -----Input----- The input consists of multiple test cases. The first line contains an integer $t$ ($1 \le t \le 10^4$) — the number of test cases. The first line of each test case contains an integer $n$ ($1 \le n \le 10^9$) — the number of puzzle pieces. -----Output----- For each test case, if Phoenix can create a square with the $n$ puzzle pieces, print YES. Otherwise, print NO. -----Examples----- Input 3 2 4 6 Output YES YES NO -----Note----- For $n=2$, Phoenix can create a square like this: For $n=4$, Phoenix can create a square like this: For $n=6$, it is impossible for Phoenix to create a square.
[ "3\n2\n4\n6\n", "1\n999939200\n", "1\n92888450\n", "1\n1458\n", "1\n9060100\n", "1\n500101938\n", "1\n100000001\n", "1\n200040002\n", "1\n200000000\n", "1\n536870913\n" ]
[ "YES\nYES\nNO\n", "YES\n", "YES\n", "YES\n", "YES\n", "YES\n", "NO\n", "YES\n", "YES\n", "NO\n" ]
1
stdio
Alex doesn't like boredom. That's why whenever he gets bored, he comes up with games. One long winter evening he came up with a game and decided to play it. Given a sequence a consisting of n integers. The player can make several steps. In a single step he can choose an element of the sequence (let's denote it a_{k}) and delete it, at that all elements equal to a_{k} + 1 and a_{k} - 1 also must be deleted from the sequence. That step brings a_{k} points to the player. Alex is a perfectionist, so he decided to get as many points as possible. Help him. -----Input----- The first line contains integer n (1 ≤ n ≤ 10^5) that shows how many numbers are in Alex's sequence. The second line contains n integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10^5). -----Output----- Print a single integer — the maximum number of points that Alex can earn. -----Examples----- Input 2 1 2 Output 2 Input 3 1 2 3 Output 4 Input 9 1 2 1 3 2 2 2 2 3 Output 10 -----Note----- Consider the third test example. At first step we need to choose any element equal to 2. After that step our sequence looks like this [2, 2, 2, 2]. Then we do 4 steps, on each step we choose any element equals to 2. In total we earn 10 points.
[ "2\n1 2\n", "3\n1 2 3\n", "9\n1 2 1 3 2 2 2 2 3\n", "5\n3 3 4 5 4\n", "5\n5 3 5 3 4\n", "5\n4 2 3 2 5\n", "10\n10 5 8 9 5 6 8 7 2 8\n", "10\n1 1 1 1 1 1 2 3 4 4\n", "100\n6 6 8 9 7 9 6 9 5 7 7 4 5 3 9 1 10 3 4 5 8 9 6 5 6 4 10 9 1 4 1 7 1 4 9 10 8 2 9 9 10 5 8 9 5 6 8 7 2 8 7 6 2 6 10 8 6 2 5 5 3 2 ...
[ "2\n", "4\n", "10\n", "11\n", "16\n", "9\n", "46\n", "14\n", "296\n", "313\n" ]
1
stdio
A word or a sentence in some language is called a pangram if all the characters of the alphabet of this language appear in it at least once. Pangrams are often used to demonstrate fonts in printing or test the output devices. You are given a string consisting of lowercase and uppercase Latin letters. Check whether this string is a pangram. We say that the string contains a letter of the Latin alphabet if this letter occurs in the string in uppercase or lowercase. -----Input----- The first line contains a single integer n (1 ≤ n ≤ 100) — the number of characters in the string. The second line contains the string. The string consists only of uppercase and lowercase Latin letters. -----Output----- Output "YES", if the string is a pangram and "NO" otherwise. -----Examples----- Input 12 toosmallword Output NO Input 35 TheQuickBrownFoxJumpsOverTheLazyDog Output YES
[ "12\ntoosmallword\n", "35\nTheQuickBrownFoxJumpsOverTheLazyDog\n", "1\na\n", "26\nqwertyuiopasdfghjklzxcvbnm\n", "26\nABCDEFGHIJKLMNOPQRSTUVWXYZ\n", "48\nthereisasyetinsufficientdataforameaningfulanswer\n", "30\nToBeOrNotToBeThatIsTheQuestion\n", "30\njackdawslovemybigsphinxofquarz\n", "31\nTHEFIVEB...
[ "NO\n", "YES\n", "NO\n", "YES\n", "YES\n", "NO\n", "NO\n", "NO\n", "YES\n", "NO\n" ]
1
stdio
There are two rectangles. The lengths of the vertical sides of the first rectangle are A, and the lengths of the horizontal sides of the first rectangle are B. The lengths of the vertical sides of the second rectangle are C, and the lengths of the horizontal sides of the second rectangle are D. Print the area of the rectangle with the larger area. If the two rectangles have equal areas, print that area. -----Constraints----- - All input values are integers. - 1≤A≤10^4 - 1≤B≤10^4 - 1≤C≤10^4 - 1≤D≤10^4 -----Input----- The input is given from Standard Input in the following format: A B C D -----Output----- Print the area of the rectangle with the larger area. If the two rectangles have equal areas, print that area. -----Sample Input----- 3 5 2 7 -----Sample Output----- 15 The first rectangle has an area of 3×5=15, and the second rectangle has an area of 2×7=14. Thus, the output should be 15, the larger area.
[ "3 5 2 7\n", "100 600 200 300\n", "100 600 200 6", "3 3 2 7", "100 480 244 6", "0 3 0 7", "100 169 362 6", "100 311 362 6", "000 311 50 6", "110 311 50 6" ]
[ "15\n", "60000\n", "60000\n", "14\n", "48000\n", "0\n", "16900\n", "31100\n", "300\n", "34210\n" ]
1
stdio
Blackjack is a type of card game played in casinos, where the game is played using cards with numbers from 1 to 13. The score of each card is decided as follows. * 1 is 1 point or 11 points * From 2 to 9, the score is as written. * 10 points from 10 to 13 There are several participants in this game, including parents, each with several sets of cards. This set of cards is called a hand. The hand score is the total of the card scores. The calculation shall be performed as follows. * If the total score of the cards is greater than 21, the score of the hand is set to 0. * As the score of the card, 1 may be calculated as 1 point or 11 points, but the one with the maximum hand score shall be selected. Create a program that uses the information of the cards dealt as input and outputs the score of the hand. Input A sequence of multiple datasets is given as input. The end of the input is indicated by a single line of zeros. Each dataset is given in the following format: c1 c2 ... cn The integer ci (1 ≤ ci ≤ 13) written on the i-th card is given to each line, separated by blanks. The number of cards n does not exceed 100. The number of datasets does not exceed 200. Output The score of the hand is output to one line for each data set. Example Input 1 7 7 7 7 7 8 12 1 10 1 1 0 Output 11 21 0 21 12
[ "1\n7 7 7\n7 7 8\n12 1\n10 1 2\n0", "1\n7 7 7\n7 7 8\n10 1\n10 1 1\n0", "1\n7 7 7\n7 7 8\n2 1\n10 2 1\n0", "1\n7 9 7\n7 7 8\n2 1\n10 2 1\n0", "1\n7 9 7\n1 9 8\n2 1\n10 2 1\n0", "1\n7 4 7\n1 9 8\n2 1\n10 2 1\n0", "1\n7 4 2\n1 9 8\n2 1\n10 2 1\n0", "1\n7 3 2\n1 9 8\n2 1\n10 2 1\n0", "1\n7 3 4\n1 9 8\n...
[ "11\n21\n0\n21\n13\n", "11\n21\n0\n21\n12\n", "11\n21\n0\n13\n13\n", "11\n0\n0\n13\n13\n", "11\n0\n18\n13\n13\n", "11\n18\n18\n13\n13\n", "11\n13\n18\n13\n13\n", "11\n12\n18\n13\n13\n", "11\n14\n18\n13\n13\n", "11\n14\n18\n13\n14\n" ]
1
stdio
Create a function that takes a string and an integer (`n`). The function should return a string that repeats the input string `n` number of times. If anything other than a string is passed in you should return `"Not a string"` ## Example ``` "Hi", 2 --> "HiHi" 1234, 5 --> "Not a string" ``` Write your solution by modifying this code: ```python def repeat_it(string,n): ``` Your solution should implemented in the function "repeat_it". The inputs will be passed to it and it should return the correct solution. Now solve the problem and return the code.
[]
[]
1
stdio
Little Petya loves presents. His mum bought him two strings of the same size for his birthday. The strings consist of uppercase and lowercase Latin letters. Now Petya wants to compare those two strings lexicographically. The letters' case does not matter, that is an uppercase letter is considered equivalent to the corresponding lowercase letter. Help Petya perform the comparison. Input Each of the first two lines contains a bought string. The strings' lengths range from 1 to 100 inclusive. It is guaranteed that the strings are of the same length and also consist of uppercase and lowercase Latin letters. Output If the first string is less than the second one, print "-1". If the second string is less than the first one, print "1". If the strings are equal, print "0". Note that the letters' case is not taken into consideration when the strings are compared. Examples Input aaaa aaaA Output 0 Input abs Abz Output -1 Input abcdefg AbCdEfF Output 1 Note If you want more formal information about the lexicographical order (also known as the "dictionary order" or "alphabetical order"), you can visit the following site: * http://en.wikipedia.org/wiki/Lexicographical_order
[ "kigPrWNTOUNDBskAfefjhHYZNYdnfZWuXWzHiBxFQryBbAkPtenFwWvCSTYGpzOntUNzNUhxRWjKmicTwLwJAnbAxj\nkigpRWntOUNdBsKaFEFjhhYZnYDNfzWuXwZhibxFQRybbakPteNfwwvcStyGPzoNTunznuHXrWjKMIctWLWJANBAxJ\n", "DQBdtSEDtFGiNRUeJNbOIfDZnsryUlzJHGTXGFXnwsVyxNtLgmklmFvRCzYETBVdmkpJJIvIOkMDgCFHZOTODiYrkwXd\nDQbDtsEdTFginRUEJNBOIfdZnsryulZ...
[ "0\n", "0\n", "-1\n", "-1\n", "1\n", "1\n", "1\n", "1\n", "0\n", "-1\n" ]
1
stdio
Draw a rectangle which has a height of H cm and a width of W cm. Draw a 1-cm square by single '#'. Constraints * 1 ≤ H ≤ 300 * 1 ≤ W ≤ 300 Input The input consists of multiple datasets. Each dataset consists of two integers H and W separated by a single space. The input ends with two 0 (when both H and W are zero). Output For each dataset, print the rectangle made of H × W '#'. Print a blank line after each dataset. Example Input 3 4 5 6 2 2 0 0 Output #### #### #### ###### ###### ###### ###### ###### ## ##
[ "3 4\n5 6\n2 3\n0 0", "3 4\n5 6\n2 0\n0 0", "3 4\n5 6\n2 4\n0 0", "4 4\n5 6\n2 0\n0 0", "4 4\n5 6\n4 0\n0 0", "4 3\n5 6\n4 -1\n0 0", "3 5\n5 6\n2 2\n0 0", "3 4\n5 0\n2 2\n0 0", "3 4\n5 6\n2 1\n0 0", "6 4\n5 6\n2 4\n0 0" ]
[ "####\n####\n####\n\n######\n######\n######\n######\n######\n\n###\n###\n\n", "####\n####\n####\n\n######\n######\n######\n######\n######\n\n\n\n\n", "####\n####\n####\n\n######\n######\n######\n######\n######\n\n####\n####\n\n", "####\n####\n####\n####\n\n######\n######\n######\n######\n######\n\n\n\n\n", ...
1
stdio
Catherine has a deck of n cards, each of which is either red, green, or blue. As long as there are at least two cards left, she can do one of two actions: take any two (not necessarily adjacent) cards with different colors and exchange them for a new card of the third color; take any two (not necessarily adjacent) cards with the same color and exchange them for a new card with that color. She repeats this process until there is only one card left. What are the possible colors for the final card? -----Input----- The first line of the input contains a single integer n (1 ≤ n ≤ 200) — the total number of cards. The next line contains a string s of length n — the colors of the cards. s contains only the characters 'B', 'G', and 'R', representing blue, green, and red, respectively. -----Output----- Print a single string of up to three characters — the possible colors of the final card (using the same symbols as the input) in alphabetical order. -----Examples----- Input 2 RB Output G Input 3 GRG Output BR Input 5 BBBBB Output B -----Note----- In the first sample, Catherine has one red card and one blue card, which she must exchange for a green card. In the second sample, Catherine has two green cards and one red card. She has two options: she can exchange the two green cards for a green card, then exchange the new green card and the red card for a blue card. Alternatively, she can exchange a green and a red card for a blue card, then exchange the blue card and remaining green card for a red card. In the third sample, Catherine only has blue cards, so she can only exchange them for more blue cards.
[ "2\nRB\n", "3\nGRG\n", "5\nBBBBB\n", "1\nR\n", "200\nBBRGRRBBRGGGBGBGBGRRGRGRGRBGRGRRBBGRGBGRRGRRRGGBBRGBGBGBRBBBBBBBGGBRGGRRRGGRGBGBGGBRRRRBRRRBRBBGGBGBRGRGBBBBGGBGBBBGBGRRBRRRGBGGBBBRBGRBRRGGGRRGBBBGBGRRRRRRGGRGRGBBBRGGGBGGGBRBBRRGBGRGRBRRRBRBGRGGBRBB\n", "101\nRRRRRRRRRRRRRRRRRRRBRRRRRRRRRRRRRRRRRRRRRR...
[ "G\n", "BR\n", "B\n", "R\n", "BGR\n", "BG\n", "BGR\n", "BGR\n", "BGR\n", "B\n" ]
1
stdio
A palindrome is a word, phrase, number, or other sequence of characters which reads the same backward as forward. Examples of numerical palindromes are: * 232 * 110011 * 54322345 Complete the function to test if the given number (`num`) **can be rearranged** to form a numerical palindrome or not. Return a boolean (`true` if it can be rearranged to a palindrome, and `false` if it cannot). Return `"Not valid"` if the input is not an integer or is less than 0. For this kata, single digit numbers are **NOT** considered numerical palindromes. ## Examples ``` 5 => false 2121 => true 1331 => true 3357665 => true 1294 => false "109982" => "Not valid" -42 => "Not valid" ``` Write your solution by modifying this code: ```python def palindrome(num): ``` Your solution should implemented in the function "palindrome". The inputs will be passed to it and it should return the correct solution. Now solve the problem and return the code.
[]
[]
1
stdio
After several latest reforms many tourists are planning to visit Berland, and Berland people understood that it's an opportunity to earn money and changed their jobs to attract tourists. Petya, for example, left the IT corporation he had been working for and started to sell souvenirs at the market. This morning, as usual, Petya will come to the market. Petya has n different souvenirs to sell; ith souvenir is characterised by its weight w_{i} and cost c_{i}. Petya knows that he might not be able to carry all the souvenirs to the market. So Petya wants to choose a subset of souvenirs such that its total weight is not greater than m, and total cost is maximum possible. Help Petya to determine maximum possible total cost. -----Input----- The first line contains two integers n and m (1 ≤ n ≤ 100000, 1 ≤ m ≤ 300000) — the number of Petya's souvenirs and total weight that he can carry to the market. Then n lines follow. ith line contains two integers w_{i} and c_{i} (1 ≤ w_{i} ≤ 3, 1 ≤ c_{i} ≤ 10^9) — the weight and the cost of ith souvenir. -----Output----- Print one number — maximum possible total cost of souvenirs that Petya can carry to the market. -----Examples----- Input 1 1 2 1 Output 0 Input 2 2 1 3 2 2 Output 3 Input 4 3 3 10 2 7 2 8 1 1 Output 10
[ "1 1\n2 1\n", "2 2\n1 3\n2 2\n", "4 3\n3 10\n2 7\n2 8\n1 1\n", "5 5\n3 5\n2 6\n3 2\n1 1\n1 6\n", "6 6\n1 6\n1 4\n1 8\n3 2\n3 2\n2 8\n", "6 12\n1 7\n1 10\n2 8\n1 2\n2 9\n3 5\n", "6 18\n3 3\n1 10\n2 10\n3 6\n1 3\n2 3\n", "20 25\n2 13\n3 11\n1 32\n1 43\n3 85\n1 14\n2 57\n1 54\n1 38\n2 96\n2 89\n3 64\n1 7...
[ "0\n", "3\n", "10\n", "13\n", "26\n", "41\n", "35\n", "990\n", "1605\n", "22\n" ]
1
stdio
Chingel is practicing for a rowing competition to be held on this saturday. He is trying his best to win this tournament for which he needs to figure out how much time it takes to cover a certain distance. **Input** You will be provided with the total distance of the journey, speed of the boat and whether he is going downstream or upstream. The speed of the stream and direction of rowing will be given as a string. Check example test cases! **Output** The output returned should be the time taken to cover the distance. If the result has decimal places, round them to 2 fixed positions. `Show some love ;) Rank and Upvote!` Write your solution by modifying this code: ```python def time(distance, boat_speed, stream): ``` Your solution should implemented in the function "time". 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 we want to convert a string into an integer. The strings simply represent the numbers in words. Examples: * "one" => 1 * "twenty" => 20 * "two hundred forty-six" => 246 * "seven hundred eighty-three thousand nine hundred and nineteen" => 783919 Additional Notes: * The minimum number is "zero" (inclusively) * The maximum number, which must be supported is 1 million (inclusively) * The "and" in e.g. "one hundred and twenty-four" is optional, in some cases it's present and in others it's not * All tested numbers are valid, you don't need to validate them Write your solution by modifying this code: ```python def parse_int(string): ``` Your solution should implemented in the function "parse_int". The inputs will be passed to it and it should return the correct solution. Now solve the problem and return the code.
[]
[]
1
stdio
Example Input 7 >> Output 7
[ "7\n>=", "7\n=>", "7\n?=", "7\n=?", "7\n<?", "7\n?<", "7\n><", "7\n>?", "7\n?>", "7\n?;" ]
[ "7\n", "7\n", "7\n", "7\n", "7\n", "7\n", "7\n", "7\n", "7\n", "7\n" ]
1
stdio
On the eve of Teddy Day Chotu decided to buy a teddy for his girlfriend Choti. He has N coins each having distinct value from 1 to N. Now after collecting all the coins he went to buy a Teddy. Now the shopkeeper Motu told Chotu that there is only one Teddy in the shop of Value K. As Chotu is very bhondu(idiot) he wonders whether he can buy that teddy or not. As you are Chotu's friend, help him solve the problem. Input First line contains integer T denoting number of testcases. Second line contains two integer N and K denoting values of coins and value of Teddy respectively. Output For each test case print "YES" if chotu can buy teddy else "NO" without quotes. Constraints 1 ≤ T ≤ 100 1 ≤ N ≤ 10^8 1 ≤ K ≤ 10^18 SAMPLE INPUT 2 5 8 4 20 SAMPLE OUTPUT YES NO Explanation In the first case Chotu can use coins of value 3 and 5 to make 8. In the second case Chotu cannot make the desired value.
[ "100\n4 29\n11 89\n16 150\n14 125\n18 192\n5 30\n8 47\n5 18\n20 17\n14 127\n11 80\n10 71\n12 6\n6 31\n13 112\n4 10\n8 45\n7 40\n7 50\n2 13\n6 49\n1 17\n8 54\n13 107\n20 228\n4 37\n16 163\n19 5\n16 147\n10 68\n12 92\n5 1\n5 15\n7 47\n16 7\n2 28\n2 27\n10 59\n13 109\n7 45\n1 22\n15 13\n5 38\n1 30\n19 213\n8 50\n5 15\...
[ "NO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nYES\nNO\nNO\nNO\nYES\nNO\nNO\nYES\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nYES\nNO\nNO\nNO\nYES\nYES\nNO\nYES\nNO\nNO\nNO\nNO\nNO\nNO\nYES\nNO\nNO\nNO\nNO\nYES\nNO\nNO\nNO\nYES\nNO\nNO\nYES\nYES\nNO\nNO\nYES\nNO\nNO\nNO\nYES\nNO\nYES\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\n...
1
stdio
Hannibal is on a mission. He has to shoot a criminal. Hannibal was on the point (0, 0) and the criminal is on the point (Xc, Yc). But there is a wall between the point (X1, Y1) and (X2, Y2). You have to tell whether Hannibal can shoot criminal or not. INPUT: First line contains the total number of test cases T. For each test case, a single line contains space separated integers denoting X1, Y1, X2, Y2, Xc, Yc. OUTPUT: For each test case display YES, if Hannibal can shoot the criminal. Otherwise, display NO. Constraints: 1 ≤ T ≤ 100 1 ≤ X, Y ≤ 1000000 SAMPLE INPUT 2 1 1 2 2 3 3 2 2 3 3 1 1 SAMPLE OUTPUT NO YES
[ "2\n1 1 2 2 3 3\n2 2 3 3 1 1", "100\n514485 388976 839005 669007 -35746 820627\n-22300 -496891 -440342 179934 -76598 -35916\n-11644 21883 16840 463 113936 -85680\n-603635 450048 -805597 -333898 -213708 -571090\n-138484 -880640 520676 -793813 -794299 641302\n-211207 300339 263771 -725539 -269273 -54088\n-798338 23...
[ "NO\nYES", "YES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nNO\nNO\nYES\nYES\nYES\nYES\nYES\nNO\nYES\nYES\nYES\nNO\nNO\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nNO\nNO\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nNO\nYES\nYES\nYES\nYES\nYES\nNO\nYES\nYES\nNO\nYES\nYES\nYES\nYES\nYES\nYES\nNO\nYES\nYES\nYES\nYES\nYES\nYES...
1
stdio
Polycarpus just has been out of luck lately! As soon as he found a job in the "Binary Cat" cafe, the club got burgled. All ice-cream was stolen. On the burglary night Polycarpus kept a careful record of all club visitors. Each time a visitor entered the club, Polycarpus put down character "+" in his notes. Similarly, each time a visitor left the club, Polycarpus put character "-" in his notes. We know that all cases of going in and out happened consecutively, that is, no two events happened at the same time. Polycarpus doesn't remember whether there was somebody in the club at the moment when his shift begun and at the moment when it ended. Right now the police wonders what minimum number of distinct people Polycarpus could have seen. Assume that he sees anybody coming in or out of the club. Each person could have come in or out an arbitrary number of times. -----Input----- The only line of the input contains a sequence of characters "+" and "-", the characters are written one after another without any separators. The characters are written in the order, in which the corresponding events occurred. The given sequence has length from 1 to 300 characters, inclusive. -----Output----- Print the sought minimum number of people -----Examples----- Input +-+-+ Output 1 Input --- Output 3
[ "+-+-+\n", "---\n", "-\n", "--\n", "---\n", "----\n", "---+\n", "--+-\n", "--++\n", "-+--\n" ]
[ "1\n", "3\n", "1\n", "2\n", "3\n", "4\n", "3\n", "2\n", "2\n", "2\n" ]
1
stdio
After a hard quarter in the office you decide to get some rest on a vacation. So you will book a flight for you and your girlfriend and try to leave all the mess behind you. You will need a rental car in order for you to get around in your vacation. The manager of the car rental makes you some good offers. Every day you rent the car costs $40. If you rent the car for 7 or more days, you get $50 off your total. Alternatively, if you rent the car for 3 or more days, you get $20 off your total. Write a code that gives out the total amount for different days(d). Write your solution by modifying this code: ```python def rental_car_cost(d): ``` Your solution should implemented in the function "rental_car_cost". The inputs will be passed to it and it should return the correct solution. Now solve the problem and return the code.
[]
[]
1
stdio
To celebrate the opening of the Winter Computer School the organizers decided to buy in n liters of cola. However, an unexpected difficulty occurred in the shop: it turned out that cola is sold in bottles 0.5, 1 and 2 liters in volume. At that, there are exactly a bottles 0.5 in volume, b one-liter bottles and c of two-liter ones. The organizers have enough money to buy any amount of cola. What did cause the heated arguments was how many bottles of every kind to buy, as this question is pivotal for the distribution of cola among the participants (and organizers as well). Thus, while the organizers are having the argument, discussing different variants of buying cola, the Winter School can't start. Your task is to count the number of all the possible ways to buy exactly n liters of cola and persuade the organizers that this number is too large, and if they keep on arguing, then the Winter Computer School will have to be organized in summer. All the bottles of cola are considered indistinguishable, i.e. two variants of buying are different from each other only if they differ in the number of bottles of at least one kind. Input The first line contains four integers — n, a, b, c (1 ≤ n ≤ 10000, 0 ≤ a, b, c ≤ 5000). Output Print the unique number — the solution to the problem. If it is impossible to buy exactly n liters of cola, print 0. Examples Input 10 5 5 5 Output 9 Input 3 0 0 2 Output 0
[ "10 20 10 5\n", "20 1 2 3\n", "7 2 2 2\n", "25 10 5 10\n", "999 999 899 299\n", "10000 5000 0 5000\n", "2 2 2 2\n", "1 0 2 0\n", "3 3 2 1\n", "1 1 0 0\n" ]
[ "36\n", "0\n", "1\n", "12\n", "145000\n", "1251\n", "3\n", "1\n", "3\n", "0\n" ]
1
stdio
You are given a sequence of positive integers of length N, a = (a_1, a_2, ..., a_N). Your objective is to remove some of the elements in a so that a will be a good sequence. Here, an sequence b is a good sequence when the following condition holds true: - For each element x in b, the value x occurs exactly x times in b. For example, (3, 3, 3), (4, 2, 4, 1, 4, 2, 4) and () (an empty sequence) are good sequences, while (3, 3, 3, 3) and (2, 4, 1, 4, 2) are not. Find the minimum number of elements that needs to be removed so that a will be a good sequence. -----Constraints----- - 1 \leq N \leq 10^5 - a_i is an integer. - 1 \leq a_i \leq 10^9 -----Input----- Input is given from Standard Input in the following format: N a_1 a_2 ... a_N -----Output----- Print the minimum number of elements that needs to be removed so that a will be a good sequence. -----Sample Input----- 4 3 3 3 3 -----Sample Output----- 1 We can, for example, remove one occurrence of 3. Then, (3, 3, 3) is a good sequence.
[ "4\n3 3 3 3\n", "5\n2 4 1 4 2\n", "6\n1 2 2 3 3 3\n", "1\n1000000000\n", "8\n2 7 1 8 2 8 1 8\n" ]
[ "1\n", "2\n", "0\n", "1\n", "5\n" ]
1
stdio
# One is the loneliest number ## Task The range of vision of a digit is its own value. `1` can see one digit to the left and one digit to the right,` 2` can see two digits, and so on. Thus, the loneliness of a digit `N` is the sum of the digits which it can see. Given a non-negative integer, your funtion must determine if there's at least one digit `1` in this integer such that its loneliness value is minimal. ## Example ``` number = 34315 ``` digit | can see on the left | can see on the right | loneliness --- | --- | --- | --- 3 | - | 431 | 4 + 3 + 1 = 8 4 | 3 | 315 | 3 + 3 + 1 + 5 = 12 3 | 34 | 15 | 3 + 4 + 1 + 5 = 13 1 | 3 | 5 | 3 + 5 = 8 5 | 3431 | - | 3 + 4 + 3 + 1 = 11 Is there a `1` for which the loneliness is minimal? Yes. Write your solution by modifying this code: ```python def loneliest(number): ``` Your solution should implemented in the function "loneliest". The inputs will be passed to it and it should return the correct solution. Now solve the problem and return the code.
[]
[]
1
stdio
Extended Euclid Algorithm Given positive integers a and b, find the integer solution (x, y) to ax + by = gcd(a, b), where gcd(a, b) is the greatest common divisor of a and b. Constraints * 1 ≤ a, b ≤ 109 Input a b Two positive integers a and b are given separated by a space in a line. Output Print two integers x and y separated by a space. If there are several pairs of such x and y, print that pair for which |x| + |y| is the minimal (primarily) and x ≤ y (secondarily). Examples Input 4 12 Output 1 0 Input 3 8 Output 3 -1
[ "5 8", "5 15", "5 1", "5 2", "15 2", "55 2", "61 2", "47 2", "11 2", "6 8" ]
[ "-3 2\n", "1 0\n", "0 1\n", "1 -2\n", "1 -7\n", "1 -27\n", "1 -30\n", "1 -23\n", "1 -5\n", "-1 1\n" ]
1
stdio
Lucifer and Crowley being two most dangerous demons are fighting to become king of hell. A question is given to them. The one who solves it first becomes King. Given an array A of N elements and an integer M. Print YES if you find three distinct indexes i, j, k such that 1 ≤ i, j, k ≤ N and A[i]+A[j]+A[k] = M else print NO. Help Lucifer to win and become king of hell. Constraints 1 ≤ N ≤ 1000 0 ≤ Element of array ≤ 1000000000 Input First line contains two integers N and K separated with a space respectively. Next line contains N integers separated with space. Output In single line print YES or NO Setter : Shiv Dhingra SAMPLE INPUT 5 10 2 3 4 5 6 SAMPLE OUTPUT YES
[ "1000 10043313\n41 18467 6334 26500 19169 15724 11478 29358 26962 24464 5705 28145 23281 16827 9961 491 2995 11942 4827 5436 32391 14604 3902 153 292 12382 17421 18716 19718 19895 5447 21726 14771 11538 1869 19912 25667 26299 17035 9894 28703 23811 31322 30333 17673 4664 15141 7711 28253 6868 25547 27644 32662 3275...
[ "YES", "YES", "YES", "NO", "YES", "YES", "YES", "YES", "NO", "YES" ]
1
stdio
[Image] -----Input----- The first line of the input is a string (between 1 and 50 characters long, inclusive). Each character will be a letter of English alphabet, lowercase or uppercase. The second line of the input is an integer between 0 and 26, inclusive. -----Output----- Output the required string. -----Examples----- Input AprilFool 14 Output AprILFooL
[ "AprilFool\n14\n", "abcdefabc\n3\n", "fgWjSAlPOvcAbCdDEFjz\n7\n", "sm\n26\n", "GnlFOqPeZtPiBkvvLhaDvGPgFqBTnLgMT\n12\n", "sPWSFWWqZBPon\n3\n", "fQHHXCdeaintxHWcFcaSGWFvqnYMEByMlSNKumiFgnJB\n0\n", "RtsUOGkraqKyjTktAXloOEmQj\n18\n", "DuFhhnq\n4\n", "RvpuYTxsbDiJDOLauRlfatcfwvtnDzKyaewGrZ\n22\n" ]
[ "AprILFooL\n", "ABCdefABC\n", "FGwjsAlpovCABCDDEFjz\n", "SM\n", "GnLFoqpEztpIBKvvLHADvGpGFqBtnLGmt\n", "spwsfwwqzBpon\n", "fqhhxcdeaintxhwcfcasgwfvqnymebymlsnkumifgnjb\n", "RtsuOGKRAQKyJtKtAxLOOEMQJ\n", "Dufhhnq\n", "RVPUyTxSBDIJDOLAURLFATCFwVTNDzKyAEwGRz\n" ]
1
stdio
Let's call a set of positive integers a_1, a_2, ..., a_k quadratic if the product of the factorials of its elements is a square of an integer, i. e. ∏_{i=1}^{k} a_i! = m^2, for some integer m. You are given a positive integer n. Your task is to find a quadratic subset of a set 1, 2, ..., n of maximum size. If there are multiple answers, print any of them. Input A single line contains a single integer n (1 ≤ n ≤ 10^6). Output In the first line, print a single integer — the size of the maximum subset. In the second line, print the subset itself in an arbitrary order. Examples Input 1 Output 1 1 Input 4 Output 3 1 3 4 Input 7 Output 4 1 4 5 6 Input 9 Output 7 1 2 4 5 6 7 9
[ "8580\n", "11431\n", "29403\n", "867\n", "27\n", "7563\n", "13273\n", "11643\n", "1644\n", "5\n" ]
[ "8579\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 1...
1
stdio
Theofanis really likes sequences of positive integers, thus his teacher (Yeltsa Kcir) gave him a problem about a sequence that consists of only special numbers. Let's call a positive number special if it can be written as a sum of different non-negative powers of $n$. For example, for $n = 4$ number $17$ is special, because it can be written as $4^0 + 4^2 = 1 + 16 = 17$, but $9$ is not. Theofanis asks you to help him find the $k$-th special number if they are sorted in increasing order. Since this number may be too large, output it modulo $10^9+7$. -----Input----- The first line contains a single integer $t$ ($1 \le t \le 10^4$) — the number of test cases. The first and only line of each test case contains two integers $n$ and $k$ ($2 \le n \le 10^9$; $1 \le k \le 10^9$). -----Output----- For each test case, print one integer — the $k$-th special number in increasing order modulo $10^9+7$. -----Examples----- Input 3 3 4 2 12 105 564 Output 9 12 3595374 -----Note----- For $n = 3$ the sequence is $[1,3,4,9...]$
[ "3\n3 4\n2 12\n105 564\n", "3\n3 4\n2 6\n105 564\n", "3\n1 4\n2 6\n105 564\n", "3\n0 4\n2 6\n105 564\n", "3\n0 8\n0 6\n105 564\n", "3\n1 8\n0 6\n105 564\n", "3\n1 7\n0 6\n105 564\n", "3\n1 7\n0 6\n105 984\n", "3\n1 10\n0 6\n105 984\n", "3\n6 4\n2 12\n105 564\n" ]
[ "9\n12\n3595374\n", "9\n6\n3595374\n", "1\n6\n3595374\n", "0\n6\n3595374\n", "0\n0\n3595374\n", "1\n0\n3595374\n", "3\n0\n3595374\n", "3\n0\n713307087\n", "2\n0\n713307087\n", "36\n12\n3595374\n" ]
1
stdio
A breakthrough among computer games, "Civilization XIII", is striking in its scale and elaborate details. Let's take a closer look at one of them. The playing area in the game is split into congruent cells that are regular hexagons. The side of each cell is equal to 1. Each unit occupies exactly one cell of the playing field. The field can be considered infinite. Let's take a look at the battle unit called an "Archer". Each archer has a parameter "shot range". It's a positive integer that determines the radius of the circle in which the archer can hit a target. The center of the circle coincides with the center of the cell in which the archer stays. A cell is considered to be under the archer’s fire if and only if all points of this cell, including border points are located inside the circle or on its border. The picture below shows the borders for shot ranges equal to 3, 4 and 5. The archer is depicted as A. <image> Find the number of cells that are under fire for some archer. Input The first and only line of input contains a single positive integer k — the archer's shot range (1 ≤ k ≤ 106). Output Print the single number, the number of cells that are under fire. Please do not use the %lld specificator to read or write 64-bit integers in C++. It is preferred to use the cout stream (also you may use the %I64d specificator). Examples Input 3 Output 7 Input 4 Output 13 Input 5 Output 19
[ "10264\n", "217\n", "7\n", "777777\n", "47248\n", "13\n", "301\n", "1034\n", "6\n", "6486\n" ]
[ "127364821\n", "56425\n", "43\n", "731487842995\n", "2699275123\n", "175\n", "108847\n", "1290385\n", "31\n", "50854039\n" ]
1
stdio
It's bonus time in the big city! The fatcats are rubbing their paws in anticipation... but who is going to make the most money? Build a function that takes in two arguments (salary, bonus). Salary will be an integer, and bonus a boolean. If bonus is true, the salary should be multiplied by 10. If bonus is false, the fatcat did not make enough money and must receive only his stated salary. Return the total figure the individual will receive as a string prefixed with "£" (= `"\u00A3"`, JS, Go, and Java), "$" (C#, C++, Ruby, Clojure, Elixir, PHP and Python, Haskell, Lua) or "¥" (Rust). Write your solution by modifying this code: ```python def bonus_time(salary, bonus): ``` Your solution should implemented in the function "bonus_time". 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 an array of numbers, return a string made up of four parts: a) a four character 'word', made up of the characters derived from the first two and last two numbers in the array. order should be as read left to right (first, second, second last, last), b) the same as above, post sorting the array into ascending order, c) the same as above, post sorting the array into descending order, d) the same as above, post converting the array into ASCII characters and sorting alphabetically. The four parts should form a single string, each part separated by a hyphen: '-' example format of solution: 'asdf-tyui-ujng-wedg' Write your solution by modifying this code: ```python def sort_transform(arr): ``` Your solution should implemented in the function "sort_transform". The inputs will be passed to it and it should return the correct solution. Now solve the problem and return the code.
[]
[]
1
stdio
This is a follow up from my kata Insert Dashes. Write a function ```insertDashII(num)``` that will insert dashes ('-') between each two odd numbers and asterisk ('\*') between each even numbers in ```num``` For example: ```insertDashII(454793)``` --> 4547-9-3 ```insertDashII(1012356895)``` --> 10123-56*89-5 Zero shouldn't be considered even or odd. Write your solution by modifying this code: ```python def insert_dash2(num): ``` Your solution should implemented in the function "insert_dash2". The inputs will be passed to it and it should return the correct solution. Now solve the problem and return the code.
[]
[]
1
stdio
One day Nikita found the string containing letters "a" and "b" only. Nikita thinks that string is beautiful if it can be cut into 3 strings (possibly empty) without changing the order of the letters, where the 1-st and the 3-rd one contain only letters "a" and the 2-nd contains only letters "b". Nikita wants to make the string beautiful by removing some (possibly none) of its characters, but without changing their order. What is the maximum length of the string he can get? -----Input----- The first line contains a non-empty string of length not greater than 5 000 containing only lowercase English letters "a" and "b". -----Output----- Print a single integer — the maximum possible size of beautiful string Nikita can get. -----Examples----- Input abba Output 4 Input bab Output 2 -----Note----- It the first sample the string is already beautiful. In the second sample he needs to delete one of "b" to make it beautiful.
[ "abba\n", "bab\n", "bbabbbaabbbb\n", "bbabbbbbaaba\n", "bbabbbababaa\n", "aabbaababbab\n", "a\n", "b\n", "ab\n", "ba\n" ]
[ "4", "2", "9", "10", "9", "8", "1", "1", "2", "2" ]
1
stdio
Ksusha is a beginner coder. Today she starts studying arrays. She has array a_1, a_2, ..., a_{n}, consisting of n positive integers. Her university teacher gave her a task. Find such number in the array, that all array elements are divisible by it. Help her and find the number! -----Input----- The first line contains integer n (1 ≤ n ≤ 10^5), showing how many numbers the array has. The next line contains integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10^9) — the array elements. -----Output----- Print a single integer — the number from the array, such that all array elements are divisible by it. If such number doesn't exist, print -1. If there are multiple answers, you are allowed to print any of them. -----Examples----- Input 3 2 2 4 Output 2 Input 5 2 1 3 1 6 Output 1 Input 3 2 3 5 Output -1
[ "3\n2 2 4\n", "5\n2 1 3 1 6\n", "3\n2 3 5\n", "1\n331358794\n", "5\n506904227 214303304 136194869 838256937 183952885\n", "2\n500000000 1000000000\n", "2\n4 6\n", "5\n10 8 6 4 2\n", "2\n6 10\n", "1\n1000000000\n" ]
[ "2\n", "1\n", "-1\n", "331358794\n", "-1\n", "500000000\n", "-1\n", "2\n", "-1\n", "1000000000\n" ]
1
stdio
In this Kata your task will be to return the count of pairs that have consecutive numbers as follows: ```Haskell pairs([1,2,5,8,-4,-3,7,6,5]) = 3 The pairs are selected as follows [(1,2),(5,8),(-4,-3),(7,6),5] --the first pair is (1,2) and the numbers in the pair are consecutive; Count = 1 --the second pair is (5,8) and are not consecutive --the third pair is (-4,-3), consecutive. Count = 2 --the fourth pair is (7,6), also consecutive. Count = 3. --the last digit has no pair, so we ignore. ``` More examples in the 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 pairs(ar): ``` Your solution should implemented in the function "pairs". The inputs will be passed to it and it should return the correct solution. Now solve the problem and return the code.
[]
[]
1
stdio
A positive integer number n is written on a blackboard. It consists of not more than 105 digits. You have to transform it into a beautiful number by erasing some of the digits, and you want to erase as few digits as possible. The number is called beautiful if it consists of at least one digit, doesn't have leading zeroes and is a multiple of 3. For example, 0, 99, 10110 are beautiful numbers, and 00, 03, 122 are not. Write a program which for the given n will find a beautiful number such that n can be transformed into this number by erasing as few digits as possible. You can erase an arbitraty set of digits. For example, they don't have to go one after another in the number n. If it's impossible to obtain a beautiful number, print -1. If there are multiple answers, print any of them. Input The first line of input contains n — a positive integer number without leading zeroes (1 ≤ n < 10100000). Output Print one number — any beautiful number obtained by erasing as few as possible digits. If there is no answer, print - 1. Examples Input 1033 Output 33 Input 10 Output 0 Input 11 Output -1 Note In the first example it is enough to erase only the first digit to obtain a multiple of 3. But if we erase the first digit, then we obtain a number with a leading zero. So the minimum number of digits to be erased is two.
[ "100020001\n", "100000000000000000222\n", "8008\n", "10000555\n", "20020201\n", "7\n", "10001\n", "2000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002\n", "8059\n", "100000001\n" ]
[ "10002000\n", "1000000000000000002\n", "0\n", "100005\n", "2002020\n", "-1\n", "0\n", "0\n", "9\n", "0\n" ]
1
stdio