question
large_stringlengths
265
13.2k
Solve the programming task below in a Python markdown code block. <image> Input The input contains a single integer a (1 ≤ a ≤ 18257). Output Print a single integer output (1 ≤ output ≤ 2·109). Examples Input 2 Output 13 Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
Solve the programming task below in a Python markdown code block. *Are you a file extension master? Let's find out by checking if Bill's files are images or audio files. Please use regex if available natively for your language.* You will create 2 string methods: - **isAudio/is_audio**, matching 1 or + uppercase/lowercase letter(s) (combination possible), with the extension .mp3, .flac, .alac, or .aac. - **isImage/is_image**, matching 1 or + uppercase/lowercase letter(s) (combination possible), with the extension .jpg, .jpeg, .png, .bmp, or .gif. *Note that this is not a generic image/audio files checker. It's meant to be a test for Bill's files only. Bill doesn't like punctuation. He doesn't like numbers, neither. Thus, his filenames are letter-only* **Rules** 1. It should return true or false, simply. 2. File extensions should consist of lowercase letters and numbers only. 3. File names should consist of letters only (uppercase, lowercase, or both) Good luck! Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
Solve the programming task below in a Python markdown code block. We have N+M balls, each of which has an integer written on it. It is known that: - The numbers written on N of the balls are even. - The numbers written on M of the balls are odd. Find the number of ways to choose two of the N+M balls (disregarding order) so that the sum of the numbers written on them is even. It can be shown that this count does not depend on the actual values written on the balls. -----Constraints----- - 0 \leq N,M \leq 100 - 2 \leq N+M - All values in input are integers. -----Input----- Input is given from Standard Input in the following format: N M -----Output----- Print the answer. -----Sample Input----- 2 1 -----Sample Output----- 1 For example, let us assume that the numbers written on the three balls are 1,2,4. - If we choose the two balls with 1 and 2, the sum is odd; - If we choose the two balls with 1 and 4, the sum is odd; - If we choose the two balls with 2 and 4, the sum is even. Thus, the answer is 1. Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
Solve the programming task below in a Python markdown code block. You are given an array $a$ of length $n$, and an integer $x$. You can perform the following operation as many times as you would like (possibly zero): replace two adjacent elements of the array by their sum. For example, if the initial array was $[3, 6, 9]$, in a single operation one can replace the last two elements by their sum, yielding an array $[3, 15]$, or replace the first two elements to get an array $[9, 9]$. Note that the size of the array decreases after each operation. The beauty of an array $b=[b_1, \ldots, b_k]$ is defined as $\sum_{i=1}^k \left\lceil \frac{b_i}{x} \right\rceil$, which means that we divide each element by $x$, round it up to the nearest integer, and sum up the resulting values. For example, if $x = 3$, and the array is $[4, 11, 6]$, the beauty of the array is equal to $\left\lceil \frac{4}{3} \right\rceil + \left\lceil \frac{11}{3} \right\rceil + \left\lceil \frac{6}{3} \right\rceil = 2 + 4 + 2 = 8$. Please determine the minimum and the maximum beauty you can get by performing some operations on the original array. -----Input----- The first input line contains a single integer $t$ — the number of test cases ($1 \le t \le 1000$). The first line of each test case contains two integers $n$ and $x$ ($1 \leq n \leq 10^5$, $1 \leq x \leq 10^9$). The next line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \leq a_i \leq 10^9$), the elements of the array $a$. It is guaranteed that the sum of values of $n$ over all test cases does not exceed $10^5$. -----Output----- For each test case output two integers — the minimal and the maximal possible beauty. -----Examples----- Input 2 3 3 3 6 9 3 3 6 4 11 Output 6 6 7 8 -----Note----- In the first test case the beauty of the array does not change if we perform any operations. In the second example we can leave the array unchanged to attain the maximum beauty, and to get the minimum beauty one can replace two elements $4$ and $11$ with their sum, yielding an array $[6, 15]$, which has its beauty equal to $7$. Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
Solve the programming task below in a Python markdown code block. By 2312 there were n Large Hadron Colliders in the inhabited part of the universe. Each of them corresponded to a single natural number from 1 to n. However, scientists did not know what activating several colliders simultaneously could cause, so the colliders were deactivated. In 2312 there was a startling discovery: a collider's activity is safe if and only if all numbers of activated colliders are pairwise relatively prime to each other (two numbers are relatively prime if their greatest common divisor equals 1)! If two colliders with relatively nonprime numbers are activated, it will cause a global collapse. Upon learning this, physicists rushed to turn the colliders on and off and carry out all sorts of experiments. To make sure than the scientists' quickness doesn't end with big trouble, the Large Hadron Colliders' Large Remote Control was created. You are commissioned to write the software for the remote (well, you do not expect anybody to operate it manually, do you?). Initially, all colliders are deactivated. Your program receives multiple requests of the form "activate/deactivate the i-th collider". The program should handle requests in the order of receiving them. The program should print the processed results in the format described below. To the request of "+ i" (that is, to activate the i-th collider), the program should print exactly one of the following responses: * "Success" if the activation was successful. * "Already on", if the i-th collider was already activated before the request. * "Conflict with j", if there is a conflict with the j-th collider (that is, the j-th collider is on, and numbers i and j are not relatively prime). In this case, the i-th collider shouldn't be activated. If a conflict occurs with several colliders simultaneously, you should print the number of any of them. The request of "- i" (that is, to deactivate the i-th collider), should receive one of the following responses from the program: * "Success", if the deactivation was successful. * "Already off", if the i-th collider was already deactivated before the request. You don't need to print quotes in the output of the responses to the requests. Input The first line contains two space-separated integers n and m (1 ≤ n, m ≤ 105) — the number of colliders and the number of requests, correspondingly. Next m lines contain numbers of requests, one per line, in the form of either "+ i" (without the quotes) — activate the i-th collider, or "- i" (without the quotes) — deactivate the i-th collider (1 ≤ i ≤ n). Output Print m lines — the results of executing requests in the above given format. The requests should be processed in the order, in which they are given in the input. Don't forget that the responses to the requests should be printed without quotes. Examples Input 10 10 + 6 + 10 + 5 - 10 - 5 - 6 + 10 + 3 + 6 + 3 Output Success Conflict with 6 Success Already off Success Success Success Success Conflict with 10 Already on Note Note that in the sample the colliders don't turn on after the second and ninth requests. The ninth request could also receive response "Conflict with 3". Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
Solve the programming task below in a Python markdown code block. Throughout Igor K.'s life he has had many situations worthy of attention. We remember the story with the virus, the story of his mathematical career and of course, his famous programming achievements. However, one does not always adopt new hobbies, one can quit something as well. This time Igor K. got disappointed in one of his hobbies: editing and voicing videos. Moreover, he got disappointed in it so much, that he decided to destroy his secret archive for good. Igor K. use Pindows XR operation system which represents files and folders by small icons. At that, m icons can fit in a horizontal row in any window. Igor K.'s computer contains n folders in the D: disk's root catalog. The folders are numbered from 1 to n in the order from the left to the right and from top to bottom (see the images). At that the folders with secret videos have numbers from a to b inclusive. Igor K. wants to delete them forever, at that making as few frame selections as possible, and then pressing Shift+Delete exactly once. What is the minimum number of times Igor K. will have to select the folder in order to select folders from a to b and only them? Let us note that if some selected folder is selected repeatedly, then it is deselected. Each selection possesses the shape of some rectangle with sides parallel to the screen's borders. Input The only line contains four integers n, m, a, b (1 ≤ n, m ≤ 109, 1 ≤ a ≤ b ≤ n). They are the number of folders in Igor K.'s computer, the width of a window and the numbers of the first and the last folders that need to be deleted. Output Print a single number: the least possible number of times Igor K. will have to select the folders using frames to select only the folders with numbers from a to b. Examples Input 11 4 3 9 Output 3 Input 20 5 2 20 Output 2 Note The images below illustrate statement tests. The first test: <image> In this test we can select folders 3 and 4 with out first selection, folders 5, 6, 7, 8 with our second selection and folder 9 with our third, last selection. The second test: <image> In this test we can first select all folders in the first row (2, 3, 4, 5), then — all other ones. Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
Solve the programming task below in a Python markdown code block. Find the intersection of two sets $A = \\{a_0, a_1, ..., a_{n-1}\\}$ and $B = \\{b_0, b_1, ..., b_{m-1}\\}$. Constraints * $1 \leq n, m \leq 200,000$ * $0 \leq a_0 < a_1 < ... < a_{n-1} \leq 10^9$ * $0 \leq b_0 < b_1 < ... < b_{m-1} \leq 10^9$ Input The input is given in the following format. $n$ $a_0 \; a_1 \; ... \; a_{n-1}$ $m$ $b_0 \; b_1 \; ... \; b_{m-1}$ Elements of $A$ and $B$ are given in ascending order respectively. There are no duplicate elements in each set. Output Print elements in the intersection in ascending order. Print an element in a line. Example Input 4 1 2 5 8 5 2 3 5 9 11 Output 2 5 Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
Solve the programming task below in a Python markdown code block. Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given n numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — to check his answers, he needs a program that among the given n numbers finds one that is different in evenness. Input The first line contains integer n (3 ≤ n ≤ 100) — amount of numbers in the task. The second line contains n space-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these numbers differs from the others in evenness. Output Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order. Examples Input 5 2 4 7 8 10 Output 3 Input 4 1 2 1 1 Output 2 Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
Solve the programming task below in a Python markdown code block. You had $n$ positive integers $a_1, a_2, \dots, a_n$ arranged in a circle. For each pair of neighboring numbers ($a_1$ and $a_2$, $a_2$ and $a_3$, ..., $a_{n - 1}$ and $a_n$, and $a_n$ and $a_1$), you wrote down: are the numbers in the pair equal or not. Unfortunately, you've lost a piece of paper with the array $a$. Moreover, you are afraid that even information about equality of neighboring elements may be inconsistent. So, you are wondering: is there any array $a$ which is consistent with information you have about equality or non-equality of corresponding pairs? -----Input----- The first line contains a single integer $t$ ($1 \le t \le 1000$) — the number of test cases. Next $t$ cases follow. The first and only line of each test case contains a non-empty string $s$ consisting of characters E and/or N. The length of $s$ is equal to the size of array $n$ and $2 \le n \le 50$. For each $i$ from $1$ to $n$: if $s_i =$ E then $a_i$ is equal to $a_{i + 1}$ ($a_n = a_1$ for $i = n$); if $s_i =$ N then $a_i$ is not equal to $a_{i + 1}$ ($a_n \neq a_1$ for $i = n$). -----Output----- For each test case, print YES if it's possible to choose array $a$ that are consistent with information from $s$ you know. Otherwise, print NO. It can be proved, that if there exists some array $a$, then there exists an array $a$ of positive integers with values less or equal to $10^9$. -----Examples----- Input 4 EEE EN ENNEENE NENN Output YES NO YES YES -----Note----- In the first test case, you can choose, for example, $a_1 = a_2 = a_3 = 5$. In the second test case, there is no array $a$, since, according to $s_1$, $a_1$ is equal to $a_2$, but, according to $s_2$, $a_2$ is not equal to $a_1$. In the third test case, you can, for example, choose array $a = [20, 20, 4, 50, 50, 50, 20]$. In the fourth test case, you can, for example, choose $a = [1, 3, 3, 7]$. Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
Solve the programming task below in a Python markdown code block. An element in an array is dominant if it is greater than all elements to its right. You will be given an array and your task will be to return a list of all dominant elements. For example: ```Haskell solve([1,21,4,7,5]) = [21,7,5] because 21, 7 and 5 are greater than elments to their right. solve([5,4,3,2,1]) = [5,4,3,2,1] Notice that the last element is always included. ``` More examples in the test cases. Good luck! Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
Solve the programming task below in a Python markdown code block. You still have partial information about the score during the historic football match. You are given a set of pairs $(a_i, b_i)$, indicating that at some point during the match the score was "$a_i$: $b_i$". It is known that if the current score is «$x$:$y$», then after the goal it will change to "$x+1$:$y$" or "$x$:$y+1$". What is the largest number of times a draw could appear on the scoreboard? The pairs "$a_i$:$b_i$" are given in chronological order (time increases), but you are given score only for some moments of time. The last pair corresponds to the end of the match. -----Input----- The first line contains a single integer $n$ ($1 \le n \le 10000$) — the number of known moments in the match. Each of the next $n$ lines contains integers $a_i$ and $b_i$ ($0 \le a_i, b_i \le 10^9$), denoting the score of the match at that moment (that is, the number of goals by the first team and the number of goals by the second team). All moments are given in chronological order, that is, sequences $x_i$ and $y_j$ are non-decreasing. The last score denotes the final result of the match. -----Output----- Print the maximum number of moments of time, during which the score was a draw. The starting moment of the match (with a score 0:0) is also counted. -----Examples----- Input 3 2 0 3 1 3 4 Output 2 Input 3 0 0 0 0 0 0 Output 1 Input 1 5 4 Output 5 -----Note----- In the example one of the possible score sequences leading to the maximum number of draws is as follows: 0:0, 1:0, 2:0, 2:1, 3:1, 3:2, 3:3, 3:4. Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
Solve the programming task below in a Python markdown code block. As a part of this Kata, you need to create a function that when provided with a triplet, returns the index of the numerical element that lies between the other two elements. The input to the function will be an array of three distinct numbers (Haskell: a tuple). For example: gimme([2, 3, 1]) => 0 *2* is the number that fits between *1* and *3* and the index of *2* in the input array is *0*. Another example (just to make sure it is clear): gimme([5, 10, 14]) => 1 *10* is the number that fits between *5* and *14* and the index of *10* in the input array is *1*. Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
Solve the programming task below in a Python markdown code block. How many multiples of d are there among the integers between L and R (inclusive)? Constraints * All values in input are integers. * 1 \leq L \leq R \leq 100 * 1 \leq d \leq 100 Input Input is given from Standard Input in the following format: L R d Output Print the number of multiples of d among the integers between L and R (inclusive). Examples Input 5 10 2 Output 3 Input 6 20 7 Output 2 Input 1 100 1 Output 100 Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
Solve the programming task below in a Python markdown code block. You are given an array $a$, consisting of $n$ positive integers. Let's call a concatenation of numbers $x$ and $y$ the number that is obtained by writing down numbers $x$ and $y$ one right after another without changing the order. For example, a concatenation of numbers $12$ and $3456$ is a number $123456$. Count the number of ordered pairs of positions $(i, j)$ ($i \neq j$) in array $a$ such that the concatenation of $a_i$ and $a_j$ is divisible by $k$. -----Input----- The first line contains two integers $n$ and $k$ ($1 \le n \le 2 \cdot 10^5$, $2 \le k \le 10^9$). The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$). -----Output----- Print a single integer — the number of ordered pairs of positions $(i, j)$ ($i \neq j$) in array $a$ such that the concatenation of $a_i$ and $a_j$ is divisible by $k$. -----Examples----- Input 6 11 45 1 10 12 11 7 Output 7 Input 4 2 2 78 4 10 Output 12 Input 5 2 3 7 19 3 3 Output 0 -----Note----- In the first example pairs $(1, 2)$, $(1, 3)$, $(2, 3)$, $(3, 1)$, $(3, 4)$, $(4, 2)$, $(4, 3)$ suffice. They produce numbers $451$, $4510$, $110$, $1045$, $1012$, $121$, $1210$, respectively, each of them is divisible by $11$. In the second example all $n(n - 1)$ pairs suffice. In the third example no pair is sufficient. Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
Solve the programming task below in a Python markdown code block. Andrii is good in Math, but not in Programming. He is asking you to solve following problem: Given an integer number N and two sets of integer A and B. Let set A contain all numbers from 1 to N and set B contain all numbers from N + 1 to 2N. Multiset C contains all sums a + b such that a belongs to A and b belongs to B. Note that multiset may contain several elements with the same values. For example, if N equals to three, then A = {1, 2, 3}, B = {4, 5, 6} and C = {5, 6, 6, 7, 7, 7, 8, 8, 9}. Andrii has M queries about multiset C. Every query is defined by a single integer q. Andrii wants to know the number of times q is contained in C. For example, number 6 is contained two times, 1 is not contained in C at all. Please, help Andrii to answer all the queries. -----Input----- The first line of the input contains two integers N and M. Each of the next M line contains one integer q, the query asked by Andrii. -----Output----- Output the answer for each query in separate lines as in example. -----Constraints----- - 1 ≤ N ≤ 109 - 1 ≤ M ≤ 105 - 1 ≤ q ≤ 3N -----Example----- Input: 3 5 6 2 9 7 5 Output: 2 0 1 3 1 Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
Solve the programming task below in a Python markdown code block. A bracket sequence is a string that is one of the following: - An empty string; - The concatenation of (, A, and ) in this order, for some bracket sequence A ; - The concatenation of A and B in this order, for some non-empty bracket sequences A and B / Given are N strings S_i. Can a bracket sequence be formed by concatenating all the N strings in some order? -----Constraints----- - 1 \leq N \leq 10^6 - The total length of the strings S_i is at most 10^6. - S_i is a non-empty string consisting of ( and ). -----Input----- Input is given from Standard Input in the following format: N S_1 : S_N -----Output----- If a bracket sequence can be formed by concatenating all the N strings in some order, print Yes; otherwise, print No. -----Sample Input----- 2 ) (() -----Sample Output----- Yes Concatenating (() and ) in this order forms a bracket sequence. Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
Solve the programming task below in a Python markdown code block. D: Sontaku (Surmise) Some twins like even numbers. Count how many even numbers are in $ N $ integers $ A_1, A_2, A_3, \ dots, A_N $. input The integer $ N $ is given on the first line. On the second line, $ N $ integers $ A_1, A_2, A_3, \ dots, A_N $ are given, separated by blanks. output Output an even number. However, insert a line break at the end. Constraint * $ N $ is an integer greater than or equal to $ 1 $ and less than or equal to $ 100 $ * $ A_1, A_2, A_3, \ dots, A_N $ are integers between $ 1 $ and $ 100 $ Input example 1 Five 4 3 5 2 6 Output example 1 3 $ A_1 = 4 $, $ A_4 = 2 $ and $ A_5 = 6 $ are even numbers. Therefore, the even number is $ 3 $. Input example 2 3 2 2 2 Output example 2 3 Even if the numbers are the same, if the positions in $ A_1, A_2, A_3, \ dots, A_N $ are different, they are counted as different numbers. Example Input 5 4 3 5 2 6 Output 3 Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
Solve the programming task below in a Python markdown code block. Program a function `sumAverage(arr)` where `arr` is an array containing arrays full of numbers, for example: ```python sum_average([[1, 2, 2, 1], [2, 2, 2, 1]]) ``` First, determine the average of each array. Then, return the sum of all the averages. - All numbers will be less than 100 and greater than -100. - `arr` will contain a maximum of 50 arrays. - After calculating all the averages, add them **all** together, **then** round down, as shown in the example below: The example given: `sumAverage([[3, 4, 1, 3, 5, 1, 4], [21, 54, 33, 21, 77]])`, the answer being 44. 1. Calculate the average of each individual array: ``` [3, 4, 1, 3, 5, 1, 4] = (3 + 4 + 1 + 3 + 5 + 1 + 4) / 7 = 3 [21, 54, 33, 21, 77] = (21 + 54 + 33 + 21 + 77) / 5 = 41.2 ``` 2. Add the average of each array together: ``` 3 + 41.2 = 44.2 ``` 3. Round the final average down: ~~~if:julia In Julia, the `Statistics` package is preloaded. ~~~ ```python import math math.floor(44.2) = 44 ``` Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
Solve the programming task below in a Python markdown code block. # Definition A **number** is called **_Automorphic number_** if and only if *its square ends in the same digits as the number itself*. ___ # Task **_Given_** a **number** *determine if it Automorphic or not* . ___ # Warm-up (Highly recommended) # [Playing With Numbers Series](https://www.codewars.com/collections/playing-with-numbers) ___ # Notes * The **_number_** passed to the function is **_positive_** * **_Single-digit_** numbers are considered **_Automorphic number_**. ___ # Input >> Output Examples ``` autoMorphic (25) -->> return "Automorphic" ``` ## **_Explanation_**: * `25` squared is `625` , **_Ends with the same number's digits which are 25_** . ___ ``` autoMorphic (13) -->> return "Not!!" ``` ## **_Explanation_**: * `13` squared is `169` , **_Not ending with the same number's digits which are 69_** . ___ ``` autoMorphic (76) -->> return "Automorphic" ``` ## **_Explanation_**: * `76` squared is `5776` , **_Ends with the same number's digits which are 76_** . ___ ``` autoMorphic (225) -->> return "Not!!" ``` ## **_Explanation_**: * `225` squared is `50625` , **_Not ending with the same number's digits which are 225_** . ___ ``` autoMorphic (625) -->> return "Automorphic" ``` ## **_Explanation_**: * `625` squared is `390625` , **_Ends with the same number's digits which are 625_** . ___ ``` autoMorphic (1) -->> return "Automorphic" ``` ## **_Explanation_**: * `1` squared is `1` , **_Ends with the same number's digits which are 1_** . ___ ``` autoMorphic (6) -->> return "Automorphic" ``` ## **_Explanation_**: * `6` squared is `36` , **_Ends with the same number's digits which are 6_** ___ ___ # [Playing with Numbers Series](https://www.codewars.com/collections/playing-with-numbers) # [Playing With Lists/Arrays Series](https://www.codewars.com/collections/playing-with-lists-slash-arrays) # [For More Enjoyable Katas](http://www.codewars.com/users/MrZizoScream/authored) ___ ## ALL translations are welcomed ## Enjoy Learning !! # Zizou Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
Solve the programming task below in a Python markdown code block. The pizza store wants to know how long each order will take. They know: - Prepping a pizza takes 3 mins - Cook a pizza takes 10 mins - Every salad takes 3 mins to make - Every appetizer takes 5 mins to make - There are 2 pizza ovens - 5 pizzas can fit in a oven - Prepping for a pizza must be done before it can be put in the oven - There are two pizza chefs and one chef for appitizers and salads combined - The two pizza chefs can work on the same pizza Write a function, order, which will tell the company how much time the order will take. See example tests for details. Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
Solve the programming task below in a Python markdown code block. Polycarpus loves hamburgers very much. He especially adores the hamburgers he makes with his own hands. Polycarpus thinks that there are only three decent ingredients to make hamburgers from: a bread, sausage and cheese. He writes down the recipe of his favorite "Le Hamburger de Polycarpus" as a string of letters 'B' (bread), 'S' (sausage) и 'C' (cheese). The ingredients in the recipe go from bottom to top, for example, recipe "ВSCBS" represents the hamburger where the ingredients go from bottom to top as bread, sausage, cheese, bread and sausage again. Polycarpus has n_{b} pieces of bread, n_{s} pieces of sausage and n_{c} pieces of cheese in the kitchen. Besides, the shop nearby has all three ingredients, the prices are p_{b} rubles for a piece of bread, p_{s} for a piece of sausage and p_{c} for a piece of cheese. Polycarpus has r rubles and he is ready to shop on them. What maximum number of hamburgers can he cook? You can assume that Polycarpus cannot break or slice any of the pieces of bread, sausage or cheese. Besides, the shop has an unlimited number of pieces of each ingredient. -----Input----- The first line of the input contains a non-empty string that describes the recipe of "Le Hamburger de Polycarpus". The length of the string doesn't exceed 100, the string contains only letters 'B' (uppercase English B), 'S' (uppercase English S) and 'C' (uppercase English C). The second line contains three integers n_{b}, n_{s}, n_{c} (1 ≤ n_{b}, n_{s}, n_{c} ≤ 100) — the number of the pieces of bread, sausage and cheese on Polycarpus' kitchen. The third line contains three integers p_{b}, p_{s}, p_{c} (1 ≤ p_{b}, p_{s}, p_{c} ≤ 100) — the price of one piece of bread, sausage and cheese in the shop. Finally, the fourth line contains integer r (1 ≤ r ≤ 10^12) — the number of rubles Polycarpus has. Please, do not write the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier. -----Output----- Print the maximum number of hamburgers Polycarpus can make. If he can't make any hamburger, print 0. -----Examples----- Input BBBSSC 6 4 1 1 2 3 4 Output 2 Input BBC 1 10 1 1 10 1 21 Output 7 Input BSC 1 1 1 1 1 3 1000000000000 Output 200000000001 Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
Solve the programming task below in a Python markdown code block. You are given a string $s$. Each character is either 0 or 1. You want all 1's in the string to form a contiguous subsegment. For example, if the string is 0, 1, 00111 or 01111100, then all 1's form a contiguous subsegment, and if the string is 0101, 100001 or 11111111111101, then this condition is not met. You may erase some (possibly none) 0's from the string. What is the minimum number of 0's that you have to erase? -----Input----- The first line contains one integer $t$ ($1 \le t \le 100$) — the number of test cases. Then $t$ lines follow, each representing a test case. Each line contains one string $s$ ($1 \le |s| \le 100$); each character of $s$ is either 0 or 1. -----Output----- Print $t$ integers, where the $i$-th integer is the answer to the $i$-th testcase (the minimum number of 0's that you have to erase from $s$). -----Example----- Input 3 010011 0 1111000 Output 2 0 0 -----Note----- In the first test case you have to delete the third and forth symbols from string 010011 (it turns into 0111). Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
Solve the programming task below in a Python markdown code block. Complete the function that calculates the derivative of a polynomial. A polynomial is an expression like: 3x^(4) - 2x^(2) + x - 10 ### How to calculate the derivative: * Take the exponent and multiply it with the coefficient * Reduce the exponent by 1 For example: 3x^(4) --> (4*3)x^((4-1)) = 12x^(3) ### Good to know: * The derivative of a constant is 0 (e.g. 100 --> 0) * Anything to the 0th exponent equals 1 (e.g. x^(0) = 1) * The derivative of the sum of two function is the sum of the derivatives Notes: * The exponentiation is marked with "^" * Exponents are always integers and >= 0 * Exponents are written only if > 1 * There are no spaces around the operators * Leading "+" signs are omitted See the examples below. ## Examples ```python derivative("-100") = "0" derivative("4x+1") = "4" # = 4x^0 + 0 derivative("-x^2+3x+4") = "-2x+3" # = -2x^1 + 3x^0 + 0 ``` Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
Solve the programming task below in a Python markdown code block. A telephone number is a sequence of exactly $11$ digits such that its first digit is 8. Vasya and Petya are playing a game. Initially they have a string $s$ of length $n$ ($n$ is odd) consisting of digits. Vasya makes the first move, then players alternate turns. In one move the player must choose a character and erase it from the current string. For example, if the current string 1121, after the player's move it may be 112, 111 or 121. The game ends when the length of string $s$ becomes 11. If the resulting string is a telephone number, Vasya wins, otherwise Petya wins. You have to determine if Vasya has a winning strategy (that is, if Vasya can win the game no matter which characters Petya chooses during his moves). -----Input----- The first line contains one integer $n$ ($13 \le n < 10^5$, $n$ is odd) — the length of string $s$. The second line contains the string $s$ ($|s| = n$) consisting only of decimal digits. -----Output----- If Vasya has a strategy that guarantees him victory, print YES. Otherwise print NO. -----Examples----- Input 13 8380011223344 Output YES Input 15 807345619350641 Output NO -----Note----- In the first example Vasya needs to erase the second character. Then Petya cannot erase a character from the remaining string 880011223344 so that it does not become a telephone number. In the second example after Vasya's turn Petya can erase one character character 8. The resulting string can't be a telephone number, because there is no digit 8 at all. Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
Solve the programming task below in a Python markdown code block. There is data that records the customer number of the business partner and the trading date on a monthly basis. Please create a program that reads this month's data and last month's data and outputs the customer number of the company with which you have transactions and the number of transactions for two consecutive months from last month. However, the number of monthly business partners is 1,000 or less. Input This month's data and last month's data are given separated by one blank line. Each data is given in the following format. c1, d1 c2, d2 ... ... ci (1 ≤ ci ≤ 1,000) is an integer representing the customer number, and di (1 ≤ di ≤ 31) is an integer representing the trading day. Output For companies that have transactions for two consecutive months, the customer number and the total number of transactions are output separated by a blank in ascending order of customer number. Example Input 123,10 56,12 34,14 123,3 56,4 123,5 Output 56 2 123 3 Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
Solve the programming task below in a Python markdown code block. Given is a string S consisting of `0` and `1`. Find the number of strings, modulo 998244353, that can result from applying the following operation on S zero or more times: * Remove the two characters at the beginning of S, erase one of them, and reinsert the other somewhere in S. This operation can be applied only when S has two or more characters. Constraints * 1 \leq |S| \leq 300 * S consists of `0` and `1`. Input Input is given from Standard Input in the following format: S Output Print the number of strings, modulo 998244353, that can result from applying the operation on S zero or more times. Examples Input 0001 Output 8 Input 110001 Output 24 Input 11101111011111000000000110000001111100011111000000001111111110000000111111111 Output 697354558 Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
Solve the programming task below in a Python markdown code block. Takahashi has decided to hold fastest-finger-fast quiz games. Kizahashi, who is in charge of making the scoreboard, is struggling to write the program that manages the players' scores in a game, which proceeds as follows. A game is played by N players, numbered 1 to N. At the beginning of a game, each player has K points. When a player correctly answers a question, each of the other N-1 players receives minus one (-1) point. There is no other factor that affects the players' scores. At the end of a game, the players with 0 points or lower are eliminated, and the remaining players survive. In the last game, the players gave a total of Q correct answers, the i-th of which was given by Player A_i. For Kizahashi, write a program that determines whether each of the N players survived this game. -----Constraints----- - All values in input are integers. - 2 \leq N \leq 10^5 - 1 \leq K \leq 10^9 - 1 \leq Q \leq 10^5 - 1 \leq A_i \leq N\ (1 \leq i \leq Q) -----Input----- Input is given from Standard Input in the following format: N K Q A_1 A_2 . . . A_Q -----Output----- Print N lines. The i-th line should contain Yes if Player i survived the game, and No otherwise. -----Sample Input----- 6 3 4 3 1 3 2 -----Sample Output----- No No Yes No No No In the beginning, the players' scores are (3, 3, 3, 3, 3, 3). - Player 3 correctly answers a question. The players' scores are now (2, 2, 3, 2, 2, 2). - Player 1 correctly answers a question. The players' scores are now (2, 1, 2, 1, 1, 1). - Player 3 correctly answers a question. The players' scores are now (1, 0, 2, 0, 0, 0). - Player 2 correctly answers a question. The players' scores are now (0, 0, 1, -1, -1, -1). Players 1, 2, 4, 5 and 6, who have 0 points or lower, are eliminated, and Player 3 survives this game. Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
Solve the programming task below in a Python markdown code block. In a small town the population is `p0 = 1000` at the beginning of a year. The population regularly increases by `2 percent` per year and moreover `50` new inhabitants per year come to live in the town. How many years does the town need to see its population greater or equal to `p = 1200` inhabitants? ``` At the end of the first year there will be: 1000 + 1000 * 0.02 + 50 => 1070 inhabitants At the end of the 2nd year there will be: 1070 + 1070 * 0.02 + 50 => 1141 inhabitants (number of inhabitants is an integer) At the end of the 3rd year there will be: 1141 + 1141 * 0.02 + 50 => 1213 It will need 3 entire years. ``` More generally given parameters: `p0, percent, aug (inhabitants coming or leaving each year), p (population to surpass)` the function `nb_year` should return `n` number of entire years needed to get a population greater or equal to `p`. aug is an integer, percent a positive or null number, p0 and p are positive integers (> 0) ``` Examples: nb_year(1500, 5, 100, 5000) -> 15 nb_year(1500000, 2.5, 10000, 2000000) -> 10 ``` Note: Don't forget to convert the percent parameter as a percentage in the body of your function: if the parameter percent is 2 you have to convert it to 0.02. Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
Solve the programming task below in a Python markdown code block. Salve, mi amice. Et tu quidem de lapis philosophorum. Barba non facit philosophum. Labor omnia vincit. Non potest creatio ex nihilo. Necesse est partibus. Rp:     I Aqua Fortis     I Aqua Regia     II Amalgama     VII Minium     IV Vitriol Misce in vitro et æstus, et nil admirari. Festina lente, et nulla tenaci invia est via. Fac et spera, Vale, Nicolas Flamel -----Input----- The first line of input contains several space-separated integers a_{i} (0 ≤ a_{i} ≤ 100). -----Output----- Print a single integer. -----Examples----- Input 2 4 6 8 10 Output 1 Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
Solve the programming task below in a Python markdown code block. There is a given string S consisting of N symbols. Your task is to find the number of ordered pairs of integers i and j such that 1. 1 ≤ i, j ≤ N 2. S[i] = S[j], that is the i-th symbol of string S is equal to the j-th. Input The single input line contains S, consisting of lowercase Latin letters and digits. It is guaranteed that string S in not empty and its length does not exceed 105. Output Print a single number which represents the number of pairs i and j with the needed property. Pairs (x, y) and (y, x) should be considered different, i.e. the ordered pairs count. Examples Input great10 Output 7 Input aaaaaaaaaa Output 100 Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
Solve the programming task below in a Python markdown code block. You are given a binary string $s$. Find the number of distinct cyclical binary strings of length $n$ which contain $s$ as a substring. The cyclical string $t$ contains $s$ as a substring if there is some cyclical shift of string $t$, such that $s$ is a substring of this cyclical shift of $t$. For example, the cyclical string "000111" contains substrings "001", "01110" and "10", but doesn't contain "0110" and "10110". Two cyclical strings are called different if they differ from each other as strings. For example, two different strings, which differ from each other by a cyclical shift, are still considered different cyclical strings. -----Input----- The first line contains a single integer $n$ ($1 \le n \le 40$) — the length of the target string $t$. The next line contains the string $s$ ($1 \le |s| \le n$) — the string which must be a substring of cyclical string $t$. String $s$ contains only characters '0' and '1'. -----Output----- Print the only integer — the number of distinct cyclical binary strings $t$, which contain $s$ as a substring. -----Examples----- Input 2 0 Output 3 Input 4 1010 Output 2 Input 20 10101010101010 Output 962 -----Note----- In the first example, there are three cyclical strings, which contain "0" — "00", "01" and "10". In the second example, there are only two such strings — "1010", "0101". Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
Solve the programming task below in a Python markdown code block. The University of Aizu has a park covered with grass, and there are no trees or buildings that block the sunlight. On sunny summer days, sprinklers installed in the park operate to sprinkle water on the lawn. The frog Pyonkichi lives in this park. Pyonkichi is not good at hot weather, and on summer days when the sun is strong, he will dry out and die if he is not exposed to the water of the sprinkler. The sprinklers installed in the park are supposed to sprinkle only one sprinkler at a time to save water, so Pyonkichi must move according to the operation of the sprinklers. <image> --- (a) Map of the park <image> | <image> --- | --- (b) Pyonkichi's jump range | (c) Sprinkler watering range The park is as shown in (a) of the above figure, the location in the park is represented by the coordinates 0 to 9 in each of the vertical and horizontal directions, and the black ● is the sprinkler, which indicates the order in which the numbers operate. This is just an example, and the location and order of operation of each sprinkler changes daily. Pyonkichi is clumsy, so he can only jump a certain distance to move. Pyonkichi's jumpable range is as shown in (b) above, and he cannot move to any other location. Moreover, one jump consumes a lot of physical strength, so you have to rest in the water for a while. The range in which the sprinkler can sprinkle water is as shown in the above figure (c), including the coordinates of the sprinkler itself. Each sprinkler will stop after a period of watering, and the next sprinkler will start working immediately. Pyonkichi shall jump only once at this time, and shall not jump until the next watering stops. Also, since the park is surrounded on all sides by scorching asphalt, it is assumed that you will not jump in a direction that would cause you to go out of the park. This summer was extremely hot. Was Pyonkichi able to survive? One day, read the initial position of Pyonkichi, the position of the sprinkler and the operation order, and if there is a movement path that Pyonkichi can survive, "OK", how? If you die even if you do your best, create a program that outputs "NA". However, the maximum number of sprinklers is 10, and Pyonkichi will jump from the initial position at the same time as the first sprinkler is activated. Input Given multiple datasets. Each dataset is given in the following format: px py n x1 y1 x2 y2 ... xn yn The first line gives the abscissa px and ordinate py of the initial position of Pyonkichi. The second line gives the number of sprinklers n. The third line gives the abscissa xi and the ordinate yi of the sprinkler that operates third. The input ends with two zero lines. The number of datasets does not exceed 20. Output For each dataset, print OK if it is alive, or NA on one line otherwise. Example Input 6 1 10 6 4 3 3 1 2 0 5 4 6 1 8 5 9 7 7 8 6 8 3 6 1 10 6 4 3 3 1 2 0 5 4 6 1 8 5 9 7 7 8 6 9 0 0 0 Output OK NA Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
Solve the programming task below in a Python markdown code block. An array is defined to be `odd-heavy` if it contains at least one odd element and every element whose value is `odd` is greater than every even-valued element. eg. ``` Array [11,4,9,2,8] is odd-heavy because:- its odd elements [11,9] are greater than all the even elements [4,2,8] Array [11,4,9,2,3,10] is not odd-heavy because:- one of it's even element 10 from [4,2,10] is greater than two of its odd elements [9,3] from [ 11,9,3] ``` write a function called `isOddHeavy` or `is_odd_heavy` that accepts an integer array and returns `true` if the array is `odd-heavy` else return `false`. Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
Solve the programming task below in a Python markdown code block. Vus the Cossack has two binary strings, that is, strings that consist only of "0" and "1". We call these strings $a$ and $b$. It is known that $|b| \leq |a|$, that is, the length of $b$ is at most the length of $a$. The Cossack considers every substring of length $|b|$ in string $a$. Let's call this substring $c$. He matches the corresponding characters in $b$ and $c$, after which he counts the number of positions where the two strings are different. We call this function $f(b, c)$. For example, let $b = 00110$, and $c = 11000$. In these strings, the first, second, third and fourth positions are different. Vus the Cossack counts the number of such substrings $c$ such that $f(b, c)$ is even. For example, let $a = 01100010$ and $b = 00110$. $a$ has four substrings of the length $|b|$: $01100$, $11000$, $10001$, $00010$. $f(00110, 01100) = 2$; $f(00110, 11000) = 4$; $f(00110, 10001) = 4$; $f(00110, 00010) = 1$. Since in three substrings, $f(b, c)$ is even, the answer is $3$. Vus can not find the answer for big strings. That is why he is asking you to help him. -----Input----- The first line contains a binary string $a$ ($1 \leq |a| \leq 10^6$) — the first string. The second line contains a binary string $b$ ($1 \leq |b| \leq |a|$) — the second string. -----Output----- Print one number — the answer. -----Examples----- Input 01100010 00110 Output 3 Input 1010111110 0110 Output 4 -----Note----- The first example is explained in the legend. In the second example, there are five substrings that satisfy us: $1010$, $0101$, $1111$, $1111$. Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
Solve the programming task below in a Python markdown code block. There are a total of A + B cats and dogs. Among them, A are known to be cats, but the remaining B are not known to be either cats or dogs. Determine if it is possible that there are exactly X cats among these A + B animals. -----Constraints----- - 1 \leq A \leq 100 - 1 \leq B \leq 100 - 1 \leq X \leq 200 - All values in input are integers. -----Input----- Input is given from Standard Input in the following format: A B X -----Output----- If it is possible that there are exactly X cats, print YES; if it is impossible, print NO. -----Sample Input----- 3 5 4 -----Sample Output----- YES If there are one cat and four dogs among the B = 5 animals, there are X = 4 cats in total. Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
Solve the programming task below in a Python markdown code block. Colonel has n badges. He wants to give one badge to every of his n soldiers. Each badge has a coolness factor, which shows how much it's owner reached. Coolness factor can be increased by one for the cost of one coin. For every pair of soldiers one of them should get a badge with strictly higher factor than the second one. Exact values of their factors aren't important, they just need to have distinct factors. Colonel knows, which soldier is supposed to get which badge initially, but there is a problem. Some of badges may have the same factor of coolness. Help him and calculate how much money has to be paid for making all badges have different factors of coolness. -----Input----- First line of input consists of one integer n (1 ≤ n ≤ 3000). Next line consists of n integers a_{i} (1 ≤ a_{i} ≤ n), which stand for coolness factor of each badge. -----Output----- Output single integer — minimum amount of coins the colonel has to pay. -----Examples----- Input 4 1 3 1 4 Output 1 Input 5 1 2 3 2 5 Output 2 -----Note----- In first sample test we can increase factor of first badge by 1. In second sample test we can increase factors of the second and the third badge by 1. Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
Solve the programming task below in a Python markdown code block. Water Country Water Deven has n cities. Each city is surrounded by water and looks like an island country. Water Deven has m bridges, and transportation between cities is carried out by these bridges, which allows you to travel to and from all cities. Recently, it was decided to reduce the maintenance cost of the bridge by reviewing the road specific financial resources. I couldn't maintain all the bridges and had to demolish some of them. Therefore, the challenge for Water Deven was to minimize the cost of maintaining the bridge while leaving the bridge so that it could reach any city. Create a program that inputs the number of cities, the number of bridges, and the maintenance cost of each bridge, so that you can go to any city using the bridge, and outputs the minimum value of the maintenance cost when the bridge is demolished. Please give me. There is no cost to demolish the bridge. However, each city shall be numbered sequentially from 0 to n-1. Input A sequence of multiple datasets is given as input. The end of the input is indicated by two lines of zeros. Each dataset is given in the following format: n m a1 b1 cost1 a2 b2 cost2 :: am bm costm The first line gives the number of cities n (2 ≤ n ≤ 100) and the number of bridges m (1 ≤ m ≤ 500). The following m lines give information about the i-th bridge. ai and bi are the numbers of the cities to which the bridge is connected, and costi (1 ≤ costi ≤ 1000) is the maintenance cost of the bridge. Output The total bridge maintenance cost is output to one line for each data set. Example Input 5 6 0 2 1 2 1 3 2 3 8 1 3 2 3 4 5 1 4 4 3 3 1 2 3 2 0 3 0 1 3 0 0 Output 10 6 Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
Solve the programming task below in a Python markdown code block. The problem set at CODE FESTIVAL 20XX Finals consists of N problems. The score allocated to the i-th (1≦i≦N) problem is i points. Takahashi, a contestant, is trying to score exactly N points. For that, he is deciding which problems to solve. As problems with higher scores are harder, he wants to minimize the highest score of a problem among the ones solved by him. Determine the set of problems that should be solved. Constraints * 1≦N≦10^7 Input The input is given from Standard Input in the following format: N Output Among the sets of problems with the total score of N, find a set in which the highest score of a problem is minimum, then print the indices of the problems in the set in any order, one per line. If there exists more than one such set, any of them will be accepted. Examples Input 4 Output 1 3 Input 7 Output 1 2 4 Input 1 Output 1 Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin Chinese and Russian as well. You are given a transparent three-dimensional table, the height equals to H and the base is a two-dimensional table N∙M. The layers of the 3D table are numbered from 1 to H. Each layer is a two-dimensional table, the rows are numbered from 1 to N and the columns are numbered from 1 to M. A pair (i, j) (1 ≤ i ≤ N, 1 ≤ j ≤ M) corresponds to the cell at the intersection of i'th row and j'th column of a two-dimensional table. We can paint cells of the three-dimensional table, but not more than T_{k} cells on k'th layer can be painted. Painting of one cell on k'th layer costs C_{k}. Your task is to find the minimum cost of painting the table thus that it can't be seen throught from the top (there is no cell which is unpainted on every layer). Formally you need to find a painting, that for any pair (i, j) (1 ≤ i ≤ N, 1 ≤ j ≤ M) there is a layer k (1 ≤ k ≤ H), where cell (i, j) is painted. If there is no such a painting then the answer is "Impossible". ------ Input ------ The first line contains three integers N, M and H. Each of the next H lines contains two integers T_{k} and C_{k}. ------ Output ------ The output should contain the minimum cost of the painting if there is one, otherwise output Impossible without quotes. ------ Constraints ------ 1 ≤ N∙M ≤ 10^{12}; 1 ≤ H ≤ 100000; 0 ≤ T_{k} ≤ 10^{12}, for each layer; 0 ≤ C_{k} ≤ 10^{5}, for each layer. ----- Sample Input 1 ------ 3 4 2 6 1 6 2 ----- Sample Output 1 ------ 18 ----- explanation 1 ------ In the first example, we should paint 6 cells on the first layer and 6 cells on the second layer. ----- Sample Input 2 ------ 2 2 3 1 1 1 2 1 3 ----- Sample Output 2 ------ Impossible ----- explanation 2 ------ In the second example, there are not enough cells to paint the table properly. Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
Solve the programming task below in a Python markdown code block. Your task in order to complete this Kata is to write a function which formats a duration, given as a number of seconds, in a human-friendly way. The function must accept a non-negative integer. If it is zero, it just returns `"now"`. Otherwise, the duration is expressed as a combination of `years`, `days`, `hours`, `minutes` and `seconds`. It is much easier to understand with an example: ```Fortran formatDuration (62) // returns "1 minute and 2 seconds" formatDuration (3662) // returns "1 hour, 1 minute and 2 seconds" ``` ```python format_duration(62) # returns "1 minute and 2 seconds" format_duration(3662) # returns "1 hour, 1 minute and 2 seconds" ``` **For the purpose of this Kata, a year is 365 days and a day is 24 hours.** Note that spaces are important. ### Detailed rules The resulting expression is made of components like `4 seconds`, `1 year`, etc. In general, a positive integer and one of the valid units of time, separated by a space. The unit of time is used in plural if the integer is greater than 1. The components are separated by a comma and a space (`", "`). Except the last component, which is separated by `" and "`, just like it would be written in English. A more significant units of time will occur before than a least significant one. Therefore, `1 second and 1 year` is not correct, but `1 year and 1 second` is. Different components have different unit of times. So there is not repeated units like in `5 seconds and 1 second`. A component will not appear at all if its value happens to be zero. Hence, `1 minute and 0 seconds` is not valid, but it should be just `1 minute`. A unit of time must be used "as much as possible". It means that the function should not return `61 seconds`, but `1 minute and 1 second` instead. Formally, the duration specified by of a component must not be greater than any valid more significant unit of time. Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
Solve the programming task below in a Python markdown code block. You've made it through the moat and up the steps of knowledge. You've won the temples games and now you're hunting for treasure in the final temple run. There's good news and bad news. You've found the treasure but you've triggered a nasty trap. You'll surely perish in the temple chamber. With your last movements, you've decided to draw an "X" marks the spot for the next archeologist. Given an odd number, n, draw an X for the next crew. Follow the example below. ` ` If n = 1 return 'X\n' and if you're given an even number or invalid input, return '?'. The output should be a string with no spaces after the final X on each line, but a \n to indicate a new line. Check out my other 80's Kids Katas: 80's Kids #1: How Many Licks Does It Take 80's Kids #2: Help Alf Find His Spaceship 80's Kids #3: Punky Brewster's Socks 80's Kids #4: Legends of the Hidden Temple 80's Kids #5: You Can't Do That on Television 80's Kids #6: Rock 'Em, Sock 'Em Robots 80's Kids #7: She's a Small Wonder 80's Kids #8: The Secret World of Alex Mack 80's Kids #9: Down in Fraggle Rock 80's Kids #10: Captain Planet Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
Solve the programming task below in a Python markdown code block. Vasiliy likes to rest after a hard work, so you may often meet him in some bar nearby. As all programmers do, he loves the famous drink "Beecola", which can be bought in n different shops in the city. It's known that the price of one bottle in the shop i is equal to x_{i} coins. Vasiliy plans to buy his favorite drink for q consecutive days. He knows, that on the i-th day he will be able to spent m_{i} coins. Now, for each of the days he want to know in how many different shops he can buy a bottle of "Beecola". -----Input----- The first line of the input contains a single integer n (1 ≤ n ≤ 100 000) — the number of shops in the city that sell Vasiliy's favourite drink. The second line contains n integers x_{i} (1 ≤ x_{i} ≤ 100 000) — prices of the bottles of the drink in the i-th shop. The third line contains a single integer q (1 ≤ q ≤ 100 000) — the number of days Vasiliy plans to buy the drink. Then follow q lines each containing one integer m_{i} (1 ≤ m_{i} ≤ 10^9) — the number of coins Vasiliy can spent on the i-th day. -----Output----- Print q integers. The i-th of them should be equal to the number of shops where Vasiliy will be able to buy a bottle of the drink on the i-th day. -----Example----- Input 5 3 10 8 6 11 4 1 10 3 11 Output 0 4 1 5 -----Note----- On the first day, Vasiliy won't be able to buy a drink in any of the shops. On the second day, Vasiliy can buy a drink in the shops 1, 2, 3 and 4. On the third day, Vasiliy can buy a drink only in the shop number 1. Finally, on the last day Vasiliy can buy a drink in any shop. Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
Solve the programming task below in a Python markdown code block. The JOI Railways is the only railway company in the Kingdom of JOI. There are $N$ stations numbered from $1$ to $N$ along a railway. Currently, two kinds of trains are operated; one is express and the other one is local. A local train stops at every station. For each $i$ ($1 \leq i < N$), by a local train, it takes $A$ minutes from the station $i$ to the station ($i + 1$). An express train stops only at the stations $S_1, S_2, ..., S_M$ ($1 = S_1 < S_2 < ... < S_M = N$). For each $i$ ($1 \leq i < N$), by an express train, it takes $B$ minutes from the station $i$ to the station ($i + 1$). The JOI Railways plans to operate another kind of trains called "semiexpress." For each $i$ ($1 \leq i < N$), by a semiexpress train, it takes $C$ minutes from the station $i$ to the station ($i + 1$). The stops of semiexpress trains are not yet determined. But they must satisfy the following conditions: * Semiexpress trains must stop at every station where express trains stop. * Semiexpress trains must stop at $K$ stations exactly. The JOI Railways wants to maximize the number of stations (except for the station 1) to which we can travel from the station 1 within $T$ minutes. The JOI Railways plans to determine the stops of semiexpress trains so that this number is maximized. We do not count the standing time of trains. When we travel from the station 1 to another station, we can take trains only to the direction where the numbers of stations increase. If several kinds of trains stop at the station $i$ ($2 \leq i \leq N - 1$), you can transfer between any trains which stop at that station. When the stops of semiexpress trains are determined appropriately, what is the maximum number of stations (except for the station 1) to which we can travel from the station 1 within $T$ minutes? Task Given the number of stations of the JOI Railways, the stops of express trains, the speeds of the trains, and maximum travel time, write a program which calculates the maximum number of stations which satisfy the condition on the travel time. Input Read the following data from the standard input. * The first line of input contains three space separated integers $N$, $M$, $K$. This means there are $N$ stations of the JOI Railways, an express train stops at $M$ stations, and a semiexpress train stops at $K$ stations, * The second line of input contains three space separated integers $A$, $B$, $C$. This means it takes $A$, $B$, $C$ minutes by a local, express, semiexpress train to travel from a station to the next station, respectively. >li> The third line of input contains an integer $T$. This means the JOI Railways wants to maximize the number of stations (except for the station 1) to which we can travel from the station 1 within $T$ minutes. * The $i$-th line ($1 \leq i \leq M$) of the following $M$ lines contains an integer $S_i$. This means an express train stops at the station $S_i$. Output Write one line to the standard output. The output contains the maximum number of stations satisfying the condition on the travel time. Constraints All input data satisfy the following conditions. * $2 \leq N \leq 1 000 000 000.$ * $2 \leq M \leq K \leq 3 000.$ * $K \leq N.$ * $1 \leq B < C < A \leq 1 000 000 000.$ * $1 \leq T \leq 10^{18}$ * $1 = S_1 < S_2 < ... < S_M = N$ Sample Input and Output Sample Input 1 10 3 5 10 3 5 30 1 6 10 Sample Output 1 8 In this sample input, there are 10 stations of the JOI Railways. An express train stops at three stations 1, 6, 10. Assume that the stops of an semiexpress train are 1, 5, 6, 8, 10. Then, among the stations 2, 3, ...10, we can travel from the station 1 to every station except for the station 9 within 30 minutes. For some $i$, the travel time and the route from the station 1 to the station $i$ are as follows: * From the station 1 to the station 3, we can travel using a local train only. The travel time is 20 minutes. * From the station 1 to the station 7, we travel from the station 1 to the station 6 by an express train, and transfer to a local train. The travel time is 25 minutes. * From the station 1 to the station 8, we travel from the station 1 to the station 6 by an express train, and transfer to a semiexpress train. The travel time is 25 minutes. * From the station 1 to the station 9, we travel from the station 1 to the station 6 by an express train, from the station 6 to the station 8 by a semiexpress train, and from the station 8 to the station 9 by a local train. In total, the travel time is 35 minutes. Sample Input 2 10 3 5 10 3 5 25 1 6 10 Sample Output 2 7 Sample Input 3 90 10 12 100000 1000 10000 10000 1 10 20 30 40 50 60 70 80 90 Sample Output 2 2 Sample Input 4 12 3 4 10 1 2 30 1 11 12 Sample Output 4 8 Sample Input 5 300 8 16 345678901 123456789 234567890 12345678901 1 10 77 82 137 210 297 300 Sample Output 5 72 Sample Input 6 1000000000 2 3000 1000000000 1 2 1000000000 1 1000000000 Sample Output 6 3000 Creative Commonse License The 16th Japanese Olympiad in Informatics (JOI 2016/2017) Final Round Example Input 10 3 5 10 3 5 30 1 6 10 Output 8 Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
Solve the programming task below in a Python markdown code block. Snuke has decided to play with N cards and a deque (that is, a double-ended queue). Each card shows an integer from 1 through N, and the deque is initially empty. Snuke will insert the cards at the beginning or the end of the deque one at a time, in order from 1 to N. Then, he will perform the following action N times: take out the card from the beginning or the end of the deque and eat it. Afterwards, we will construct an integer sequence by arranging the integers written on the eaten cards, in the order they are eaten. Among the sequences that can be obtained in this way, find the number of the sequences such that the K-th element is 1. Print the answer modulo 10^{9} + 7. -----Constraints----- - 1 ≦ K ≦ N ≦ 2{,}000 -----Input----- The input is given from Standard Input in the following format: N K -----Output----- Print the answer modulo 10^{9} + 7. -----Sample Input----- 2 1 -----Sample Output----- 1 There is one sequence satisfying the condition: 1,2. One possible way to obtain this sequence is the following: - Insert both cards, 1 and 2, at the end of the deque. - Eat the card at the beginning of the deque twice. Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
Solve the programming task below in a Python markdown code block. Petya loves lucky numbers. Everybody knows that positive integers are lucky if their decimal representation doesn't contain digits other than 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Lucky number is super lucky if it's decimal representation contains equal amount of digits 4 and 7. For example, numbers 47, 7744, 474477 are super lucky and 4, 744, 467 are not. One day Petya came across a positive integer n. Help him to find the least super lucky number which is not less than n. Input The only line contains a positive integer n (1 ≤ n ≤ 10100000). This number doesn't have leading zeroes. Output Output the least super lucky number that is more than or equal to n. Examples Input 4500 Output 4747 Input 47 Output 47 Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
Solve the programming task below in a Python markdown code block. There are $n$ students and $m$ clubs in a college. The clubs are numbered from $1$ to $m$. Each student has a potential $p_i$ and is a member of the club with index $c_i$. Initially, each student is a member of exactly one club. A technical fest starts in the college, and it will run for the next $d$ days. There is a coding competition every day in the technical fest. Every day, in the morning, exactly one student of the college leaves their club. Once a student leaves their club, they will never join any club again. Every day, in the afternoon, the director of the college will select one student from each club (in case some club has no members, nobody is selected from that club) to form a team for this day's coding competition. The strength of a team is the mex of potentials of the students in the team. The director wants to know the maximum possible strength of the team for each of the coming $d$ days. Thus, every day the director chooses such team, that the team strength is maximized. The mex of the multiset $S$ is the smallest non-negative integer that is not present in $S$. For example, the mex of the $\{0, 1, 1, 2, 4, 5, 9\}$ is $3$, the mex of $\{1, 2, 3\}$ is $0$ and the mex of $\varnothing$ (empty set) is $0$. -----Input----- The first line contains two integers $n$ and $m$ ($1 \leq m \leq n \leq 5000$), the number of students and the number of clubs in college. The second line contains $n$ integers $p_1, p_2, \ldots, p_n$ ($0 \leq p_i < 5000$), where $p_i$ is the potential of the $i$-th student. The third line contains $n$ integers $c_1, c_2, \ldots, c_n$ ($1 \leq c_i \leq m$), which means that $i$-th student is initially a member of the club with index $c_i$. The fourth line contains an integer $d$ ($1 \leq d \leq n$), number of days for which the director wants to know the maximum possible strength of the team. Each of the next $d$ lines contains an integer $k_i$ ($1 \leq k_i \leq n$), which means that $k_i$-th student lefts their club on the $i$-th day. It is guaranteed, that the $k_i$-th student has not left their club earlier. -----Output----- For each of the $d$ days, print the maximum possible strength of the team on that day. -----Examples----- Input 5 3 0 1 2 2 0 1 2 2 3 2 5 3 2 4 5 1 Output 3 1 1 1 0 Input 5 3 0 1 2 2 1 1 3 2 3 2 5 4 2 3 5 1 Output 3 2 2 1 0 Input 5 5 0 1 2 4 5 1 2 3 4 5 4 2 3 5 4 Output 1 1 1 1 -----Note----- Consider the first example: On the first day, student $3$ leaves their club. Now, the remaining students are $1$, $2$, $4$ and $5$. We can select students $1$, $2$ and $4$ to get maximum possible strength, which is $3$. Note, that we can't select students $1$, $2$ and $5$, as students $2$ and $5$ belong to the same club. Also, we can't select students $1$, $3$ and $4$, since student $3$ has left their club. On the second day, student $2$ leaves their club. Now, the remaining students are $1$, $4$ and $5$. We can select students $1$, $4$ and $5$ to get maximum possible strength, which is $1$. On the third day, the remaining students are $1$ and $5$. We can select students $1$ and $5$ to get maximum possible strength, which is $1$. On the fourth day, the remaining student is $1$. We can select student $1$ to get maximum possible strength, which is $1$. On the fifth day, no club has students and so the maximum possible strength is $0$. Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
Solve the programming task below in a Python markdown code block. A professor invented Cookie Breeding Machine for his students who like cookies very much. When one cookie with the taste of x is put into the machine and a non-negative integer y less than or equal to 127 is input on the machine, it consumes the cookie and generates two cookies with the taste of y and (x XOR y). Here, XOR represents Bitwise Exclusive OR. At first, there is only one cookie and the taste of it is D . Find the maximum value of the sum of the taste of the exactly N cookies generated after the following operation is conducted N-1 times. 1. Put one of the cookies into the machine. 2. Input a non-negative integer less than or equal to 127 on the machine. Constraints * 1 \leq T \leq 1000 * 1 \leq N_t \leq 1000 (1 \leq t \leq T) * 1 \leq D_t \leq 127 (1 \leq t \leq T) Input The input is given from Standard Input in the following format: T N_1 D_1 : N_T D_T The input consists of multiple test cases. An Integer T that represents the number of test cases is given on line 1. Each test case is given on the next T lines. In the t-th test case ( 1 \leq t \leq T ), N_t that represents the number of cookies generated through the operations and D_t that represents the taste of the initial cookie are given separated by space. Output For each test case, print the maximum value of the sum of the taste of the N cookies generated through the operations on one line. Example Input 3 3 1 4 108 1 10 Output 255 400 10 Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
Solve the programming task below in a Python markdown code block. # Task You know the slogan `p`, which the agitators have been chanting for quite a while now. Roka has heard this slogan a few times, but he missed almost all of them and grasped only their endings. You know the string `r` that Roka has heard. You need to determine what is the `minimal number` of times agitators repeated the slogan `p`, such that Roka could hear `r`. It is guaranteed the Roka heard nothing but the endings of the slogan P repeated several times. # Example For `p = "glorytoukraine", r = "ukraineaineaine"`, the output should be `3`. The slogan was `"glorytoukraine"`, and Roka heard `"ukraineaineaine"`. He could hear it as follows: `"ukraine"` + `"aine"` + `"aine"` = `"ukraineaineaine"`. # Input/Output - `[input]` string `p` The slogan the agitators chanted, a string of lowecase Latin letters. - `[input]` string `r` The string of lowercase Latin letters Roka has heard. - `[output]` an integer The `minimum number` of times the agitators chanted. Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
Solve the programming task below in a Python markdown code block. Hello! Your are given x and y and 2D array size tuple (width, height) and you have to: Calculate the according index in 1D space (zero-based). Do reverse operation. Implement: to_1D(x, y, size): --returns index in 1D space to_2D(n, size) --returns x and y in 2D space 1D array: [0, 1, 2, 3, 4, 5, 6, 7, 8] 2D array: [[0 -> (0,0), 1 -> (1,0), 2 -> (2,0)], [3 -> (0,1), 4 -> (1,1), 5 -> (2,1)], [6 -> (0,2), 7 -> (1,2), 8 -> (2,2)]] to_1D(0, 0, (3,3)) returns 0 to_1D(1, 1, (3,3)) returns 4 to_1D(2, 2, (3,3)) returns 8 to_2D(5, (3,3)) returns (2,1) to_2D(3, (3,3)) returns (0,1) Assume all input are valid: 1 < width < 500; 1 < height < 500 Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
Solve the programming task below in a Python markdown code block. Ann and Borya have n piles with candies and n is even number. There are a_{i} candies in pile with number i. Ann likes numbers which are square of some integer and Borya doesn't like numbers which are square of any integer. During one move guys can select some pile with candies and add one candy to it (this candy is new and doesn't belong to any other pile) or remove one candy (if there is at least one candy in this pile). Find out minimal number of moves that is required to make exactly n / 2 piles contain number of candies that is a square of some integer and exactly n / 2 piles contain number of candies that is not a square of any integer. -----Input----- First line contains one even integer n (2 ≤ n ≤ 200 000) — number of piles with candies. Second line contains sequence of integers a_1, a_2, ..., a_{n} (0 ≤ a_{i} ≤ 10^9) — amounts of candies in each pile. -----Output----- Output minimal number of steps required to make exactly n / 2 piles contain number of candies that is a square of some integer and exactly n / 2 piles contain number of candies that is not a square of any integer. If condition is already satisfied output 0. -----Examples----- Input 4 12 14 30 4 Output 2 Input 6 0 0 0 0 0 0 Output 6 Input 6 120 110 23 34 25 45 Output 3 Input 10 121 56 78 81 45 100 1 0 54 78 Output 0 -----Note----- In first example you can satisfy condition in two moves. During each move you should add one candy to second pile. After it size of second pile becomes 16. After that Borya and Ann will have two piles with number of candies which is a square of integer (second and fourth pile) and two piles with number of candies which is not a square of any integer (first and third pile). In second example you should add two candies to any three piles. Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
Solve the programming task below in a Python markdown code block. A system is transmitting messages in binary, however it is not a perfect transmission, and sometimes errors will occur which result in a single bit flipping from 0 to 1, or from 1 to 0. To resolve this, A 2-dimensional Parity Bit Code is used: https://en.wikipedia.org/wiki/Multidimensional_parity-check_code In this system, a message is arrayed out on a M x N grid. A 24-bit message could be put on a 4x6 grid like so: >1 0 1 0 0 1 >1 0 0 1 0 0 >0 1 1 1 0 1 >1 0 0 0 0 1 Then, Parity bits are computed for each row and for each column, equal to 1 if there is an odd number of 1s in the row of column, and 0 if it is an even number. The result for the above message looks like: >1 0 1 0 0 1 1 >1 0 0 1 0 0 0 >0 1 1 1 0 1 0 >1 0 0 0 0 1 0 >1 1 0 0 0 1 Since the 1st row, and 1st, 2nd and 6th column each have an odd number of 1s in them, and the others all do not. Then the whole message is sent, including the parity bits. This is arranged as: > message + row_parities + column_parities > 101001100100011101100001 + 1000 + 110001 > 1010011001000111011000011000110001 If an error occurs in transmission, the parity bit for a column and row will be incorrect, which can be used to identify and correct the error. If a row parity bit is incorrect, but all column bits are correct, then we can assume the row parity bit was the one flipped, and likewise if a column is wrong but all rows are correct. Your Task: Create a function correct, which takes in integers M and N, and a string of bits where the first M\*N represent the content of the message, the next M represent the parity bits for the rows, and the final N represent the parity bits for the columns. A single-bit error may or may not have appeared in the bit array. The function should check to see if there is a single-bit error in the coded message, correct it if it exists, and return the corrected string of bits. Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
Solve the programming task below in a Python markdown code block. You are given two non-empty strings $s$ and $t$, consisting of Latin letters. In one move, you can choose an occurrence of the string $t$ in the string $s$ and replace it with dots. Your task is to remove all occurrences of the string $t$ in the string $s$ in the minimum number of moves, and also calculate how many different sequences of moves of the minimum length exist. Two sequences of moves are considered different if the sets of indices at which the removed occurrences of the string $t$ in $s$ begin differ. For example, the sets $\{1, 2, 3\}$ and $\{1, 2, 4\}$ are considered different, the sets $\{2, 4, 6\}$ and $\{2, 6\}$ — too, but sets $\{3, 5\}$ and $\{5, 3\}$ — not. For example, let the string $s =$ "abababacababa" and the string $t =$ "aba". We can remove all occurrences of the string $t$ in $2$ moves by cutting out the occurrences of the string $t$ at the $3$th and $9$th positions. In this case, the string $s$ is an example of the form "ab...bac...ba". It is also possible to cut occurrences of the string $t$ at the $3$th and $11$th positions. There are two different sequences of minimum length moves. Since the answer can be large, output it modulo $10^9 + 7$. -----Input----- The first line of the input contains a single integer $q$ ($1 \le q \le 50$) — the number of test cases. The descriptions of the sets follow. The first line of each set contains a non-empty string $s$ ($1 \le |s| \le 500$) consisting of lowercase Latin letters. The second line of each set contains a non-empty string $t$ ($1 \le |t| \le 500$) consisting of lowercase Latin letters. It is guaranteed that the sum of string lengths $s$ over all test cases does not exceed $500$. Similarly, it is guaranteed that the sum of string lengths $t$ over all test cases does not exceed $500$. -----Output----- For each test case print two integers — the minimum number of moves and the number of different optimal sequences, modulo $10^9 + 7$. -----Examples----- Input 8 abababacababa aba ddddddd dddd xyzxyz xyz abc abcd abacaba abaca abc def aaaaaaaa a aaaaaaaa aa Output 2 2 1 4 2 1 0 1 1 1 0 1 8 1 3 6 -----Note----- The first test case is explained in the statement. In the second case, it is enough to cut any of the four occurrences. In the third case, string $s$ is the concatenation of two strings $t =$ "xyz", so there is a unique optimal sequence of $2$ moves. In the fourth and sixth cases, the string $s$ initially contains no occurrences of the string $t$. In the fifth case, the string $s$ contains exactly one occurrence of the string $t$. Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
Solve the programming task below in a Python markdown code block. We have had record hot temperatures this summer. To avoid heat stroke, you decided to buy a quantity of drinking water at the nearby supermarket. Two types of bottled water, 1 and 0.5 liter, are on sale at respective prices there. You have a definite quantity in your mind, but are willing to buy a quantity larger than that if: no combination of these bottles meets the quantity, or, the total price becomes lower. Given the prices for each bottle of water and the total quantity needed, make a program to seek the lowest price to buy greater than or equal to the quantity required. Input The input is given in the following format. $A$ $B$ $X$ The first line provides the prices for a 1-liter bottle $A$ ($1\leq A \leq 1000$), 500-milliliter bottle $B$ ($1 \leq B \leq 1000$), and the total water quantity needed $X$ ($1 \leq X \leq 20000$). All these values are given as integers, and the quantity of water in milliliters. Output Output the total price. Examples Input 180 100 2400 Output 460 Input 200 90 2018 Output 450 Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
Solve the programming task below in a Python markdown code block. C*++ language is quite similar to C++. The similarity manifests itself in the fact that the programs written in C*++ sometimes behave unpredictably and lead to absolutely unexpected effects. For example, let's imagine an arithmetic expression in C*++ that looks like this (expression is the main term): * expression ::= summand | expression + summand | expression - summand * summand ::= increment | coefficient*increment * increment ::= a++ | ++a * coefficient ::= 0|1|2|...|1000 For example, "5*a++-3*++a+a++" is a valid expression in C*++. Thus, we have a sum consisting of several summands divided by signs "+" or "-". Every summand is an expression "a++" or "++a" multiplied by some integer coefficient. If the coefficient is omitted, it is suggested being equal to 1. The calculation of such sum in C*++ goes the following way. First all the summands are calculated one after another, then they are summed by the usual arithmetic rules. If the summand contains "a++", then during the calculation first the value of the "a" variable is multiplied by the coefficient, then value of "a" is increased by 1. If the summand contains "++a", then the actions on it are performed in the reverse order: first "a" is increased by 1, then — multiplied by the coefficient. The summands may be calculated in any order, that's why sometimes the result of the calculation is completely unpredictable! Your task is to find its largest possible value. Input The first input line contains an integer a ( - 1000 ≤ a ≤ 1000) — the initial value of the variable "a". The next line contains an expression in C*++ language of the described type. The number of the summands in the expression does not exceed 1000. It is guaranteed that the line describing the expression contains no spaces and tabulation. Output Output a single number — the maximal possible value of the expression. Examples Input 1 5*a++-3*++a+a++ Output 11 Input 3 a+++++a Output 8 Note Consider the second example. Initially a = 3. Suppose that at first the first summand is calculated, and then the second one is. The first summand gets equal to 3, and the value of a is increased by 1. At the calculation of the second summand a is increased once more (gets equal to 5). The value of the second summand is 5, and together they give 8. If we calculate the second summand first and the first summand later, then the both summands equals to 4, and the result is 8, too. Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
Solve the programming task below in a Python markdown code block. There are $n$ warriors in a row. The power of the $i$-th warrior is $a_i$. All powers are pairwise distinct. You have two types of spells which you may cast: Fireball: you spend $x$ mana and destroy exactly $k$ consecutive warriors; Berserk: you spend $y$ mana, choose two consecutive warriors, and the warrior with greater power destroys the warrior with smaller power. For example, let the powers of warriors be $[2, 3, 7, 8, 11, 5, 4]$, and $k = 3$. If you cast Berserk on warriors with powers $8$ and $11$, the resulting sequence of powers becomes $[2, 3, 7, 11, 5, 4]$. Then, for example, if you cast Fireball on consecutive warriors with powers $[7, 11, 5]$, the resulting sequence of powers becomes $[2, 3, 4]$. You want to turn the current sequence of warriors powers $a_1, a_2, \dots, a_n$ into $b_1, b_2, \dots, b_m$. Calculate the minimum amount of mana you need to spend on it. -----Input----- The first line contains two integers $n$ and $m$ ($1 \le n, m \le 2 \cdot 10^5$) — the length of sequence $a$ and the length of sequence $b$ respectively. The second line contains three integers $x, k, y$ ($1 \le x, y, \le 10^9; 1 \le k \le n$) — the cost of fireball, the range of fireball and the cost of berserk respectively. The third line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le n$). It is guaranteed that all integers $a_i$ are pairwise distinct. The fourth line contains $m$ integers $b_1, b_2, \dots, b_m$ ($1 \le b_i \le n$). It is guaranteed that all integers $b_i$ are pairwise distinct. -----Output----- Print the minimum amount of mana for turning the sequnce $a_1, a_2, \dots, a_n$ into $b_1, b_2, \dots, b_m$, or $-1$ if it is impossible. -----Examples----- Input 5 2 5 2 3 3 1 4 5 2 3 5 Output 8 Input 4 4 5 1 4 4 3 1 2 2 4 3 1 Output -1 Input 4 4 2 1 11 1 3 2 4 1 3 2 4 Output 0 Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
Solve the programming task below in a Python markdown code block. Alice and Bob are studying for their class test together. The topic of the test is Prime Numbers. The preparation is getting too boring for their liking. To make it interesting, they turn it into a game. The winner will get an ice-cream treat from the other. The game is called Count K-Primes. A number is a $K$-prime if it has exactly $K$ distinct prime factors. The game is quite simple. Alice will give three numbers $A$, $B$ & $K$ to Bob. Bob needs to tell Alice the number of $K$-prime numbers between $A$ & $B$ (both inclusive). If Bob gives the correct answer, he gets a point. If not, Alice gets a point. They play this game $T$ times. Bob hasn't prepared so well. But he really wants to win the game. He wants you to tell him the correct answer. ------ Input ------ First line of input contains a single integer $T$, the number of times they play. Each game is described in a single line containing the three numbers $A$,$B$ & $K$. ------ Output ------ For each game, output on a separate line the number of $K$-primes between $A$ & $B$. ------ Constraints: ------ $1 ≤ T ≤ 10000$ $2 ≤ A ≤ B ≤ 100000$ $1 ≤ K ≤ 5$ ----- Sample Input 1 ------ 4 2 5 1 4 10 2 14 15 2 2 20 3 ----- Sample Output 1 ------ 4 2 2 0 ----- explanation 1 ------ Test case $1$: The range includes $4$ integers $\{2, 3, 4,5 \}$. We need to find the number of integers in this range having only $1$ distinct prime factor. - For $2$, since it is prime, it has $1$ distinct prime factor. - For $3$, since it is prime, it has $1$ distinct prime factor. - For $4$, we can write it as $2\times 2$. Thus, it has $1$ distinct prime factor which is $2$. - For $5$, since it is prime, it has $1$ distinct prime factor. Thus, all $4$ integers in the given range are $1$-primes. Test case $2$: The only *K-primes* in the given range are $6$ and $10$. This is because $6 = 2\times 3$ and $10 = 2\times 5$. Thus both these integers have $2$ distinct prime factors. Test case $3$: The only *K-primes* in the given range are $14$ and $15$. This is because $14 = 2\times 7$ and $15 = 3\times 5$. Thus both these integers have $2$ distinct prime factors. Test case $4$: There are no *K-primes* in the given range. Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
Solve the programming task below in a Python markdown code block. You drop a ball from a given height. After each bounce, the ball returns to some fixed proportion of its previous height. If the ball bounces to height 1 or less, we consider it to have stopped bouncing. Return the number of bounces it takes for the ball to stop moving. ``` bouncingBall(initialHeight, bouncingProportion) boucingBall(4, 0.5) After first bounce, ball bounces to height 2 After second bounce, ball bounces to height 1 Therefore answer is 2 bounces boucingBall(30, 0.3) After first bounce, ball bounces to height 9 After second bounce, ball bounces to height 2.7 After third bounce, ball bounces to height 0.81 Therefore answer is 3 bounces ``` Initial height is an integer in range [2,1000] Bouncing Proportion is a decimal in range [0, 1) Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
Solve the programming task below in a Python markdown code block. Æsir - CHAOS Æsir - V. "Everything has been planned out. No more hidden concerns. The condition of Cytus is also perfect. The time right now...... 00:01:12...... It's time." The emotion samples are now sufficient. After almost 3 years, it's time for Ivy to awake her bonded sister, Vanessa. The system inside A.R.C.'s Library core can be considered as an undirected graph with infinite number of processing nodes, numbered with all positive integers ($1, 2, 3, \ldots$). The node with a number $x$ ($x > 1$), is directly connected with a node with number $\frac{x}{f(x)}$, with $f(x)$ being the lowest prime divisor of $x$. Vanessa's mind is divided into $n$ fragments. Due to more than 500 years of coma, the fragments have been scattered: the $i$-th fragment is now located at the node with a number $k_i!$ (a factorial of $k_i$). To maximize the chance of successful awakening, Ivy decides to place the samples in a node $P$, so that the total length of paths from each fragment to $P$ is smallest possible. If there are multiple fragments located at the same node, the path from that node to $P$ needs to be counted multiple times. In the world of zeros and ones, such a requirement is very simple for Ivy. Not longer than a second later, she has already figured out such a node. But for a mere human like you, is this still possible? For simplicity, please answer the minimal sum of paths' lengths from every fragment to the emotion samples' assembly node $P$. -----Input----- The first line contains an integer $n$ ($1 \le n \le 10^6$) — number of fragments of Vanessa's mind. The second line contains $n$ integers: $k_1, k_2, \ldots, k_n$ ($0 \le k_i \le 5000$), denoting the nodes where fragments of Vanessa's mind are located: the $i$-th fragment is at the node with a number $k_i!$. -----Output----- Print a single integer, denoting the minimal sum of path from every fragment to the node with the emotion samples (a.k.a. node $P$). As a reminder, if there are multiple fragments at the same node, the distance from that node to $P$ needs to be counted multiple times as well. -----Examples----- Input 3 2 1 4 Output 5 Input 4 3 1 4 4 Output 6 Input 4 3 1 4 1 Output 6 Input 5 3 1 4 1 5 Output 11 -----Note----- Considering the first $24$ nodes of the system, the node network will look as follows (the nodes $1!$, $2!$, $3!$, $4!$ are drawn bold): [Image] For the first example, Ivy will place the emotion samples at the node $1$. From here: The distance from Vanessa's first fragment to the node $1$ is $1$. The distance from Vanessa's second fragment to the node $1$ is $0$. The distance from Vanessa's third fragment to the node $1$ is $4$. The total length is $5$. For the second example, the assembly node will be $6$. From here: The distance from Vanessa's first fragment to the node $6$ is $0$. The distance from Vanessa's second fragment to the node $6$ is $2$. The distance from Vanessa's third fragment to the node $6$ is $2$. The distance from Vanessa's fourth fragment to the node $6$ is again $2$. The total path length is $6$. Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
Solve the programming task below in a Python markdown code block. There are N integers written on a blackboard. The i-th integer is A_i. Takahashi and Aoki will arrange these integers in a row, as follows: * First, Takahashi will arrange the integers as he wishes. * Then, Aoki will repeatedly swap two adjacent integers that are coprime, as many times as he wishes. We will assume that Takahashi acts optimally so that the eventual sequence will be lexicographically as small as possible, and we will also assume that Aoki acts optimally so that the eventual sequence will be lexicographically as large as possible. Find the eventual sequence that will be produced. Constraints * 1 ≦ N ≦ 2000 * 1 ≦ A_i ≦ 10^8 Input The input is given from Standard Input in the following format: N A_1 A_2 … A_N Output Print the eventual sequence that will be produced, in a line. Examples Input 5 1 2 3 4 5 Output 5 3 2 4 1 Input 4 2 3 4 6 Output 2 4 6 3 Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
Solve the programming task below in a Python markdown code block. Polycarp found under the Christmas tree an array $a$ of $n$ elements and instructions for playing with it: At first, choose index $i$ ($1 \leq i \leq n$) — starting position in the array. Put the chip at the index $i$ (on the value $a_i$). While $i \leq n$, add $a_i$ to your score and move the chip $a_i$ positions to the right (i.e. replace $i$ with $i + a_i$). If $i > n$, then Polycarp ends the game. For example, if $n = 5$ and $a = [7, 3, 1, 2, 3]$, then the following game options are possible: Polycarp chooses $i = 1$. Game process: $i = 1 \overset{+7}{\longrightarrow} 8$. The score of the game is: $a_1 = 7$. Polycarp chooses $i = 2$. Game process: $i = 2 \overset{+3}{\longrightarrow} 5 \overset{+3}{\longrightarrow} 8$. The score of the game is: $a_2 + a_5 = 6$. Polycarp chooses $i = 3$. Game process: $i = 3 \overset{+1}{\longrightarrow} 4 \overset{+2}{\longrightarrow} 6$. The score of the game is: $a_3 + a_4 = 3$. Polycarp chooses $i = 4$. Game process: $i = 4 \overset{+2}{\longrightarrow} 6$. The score of the game is: $a_4 = 2$. Polycarp chooses $i = 5$. Game process: $i = 5 \overset{+3}{\longrightarrow} 8$. The score of the game is: $a_5 = 3$. Help Polycarp to find out the maximum score he can get if he chooses the starting index in an optimal way. -----Input----- The first line contains one integer $t$ ($1 \leq t \leq 10^4$) — the number of test cases. Then $t$ test cases follow. The first line of each test case contains one integer $n$ ($1 \leq n \leq 2 \cdot 10^5$) — the length of the array $a$. The next line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \leq a_i \leq 10^9$) — elements of the array $a$. It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$. -----Output----- For each test case, output on a separate line one number — the maximum score that Polycarp can get by playing the game on the corresponding array according to the instruction from the statement. Note that Polycarp chooses any starting position from $1$ to $n$ in such a way as to maximize his result. -----Examples----- Input 4 5 7 3 1 2 3 3 2 1 4 6 2 1000 2 3 995 1 5 1 1 1 1 1 Output 7 6 1000 5 -----Note----- The first test case is explained in the statement. In the second test case, the maximum score can be achieved by choosing $i = 1$. In the third test case, the maximum score can be achieved by choosing $i = 2$. In the fourth test case, the maximum score can be achieved by choosing $i = 1$. Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
Solve the programming task below in a Python markdown code block. You are given an array a with n elements. Each element of a is either 0 or 1. Let's denote the length of the longest subsegment of consecutive elements in a, consisting of only numbers one, as f(a). You can change no more than k zeroes to ones to maximize f(a). -----Input----- The first line contains two integers n and k (1 ≤ n ≤ 3·10^5, 0 ≤ k ≤ n) — the number of elements in a and the parameter k. The second line contains n integers a_{i} (0 ≤ a_{i} ≤ 1) — the elements of a. -----Output----- On the first line print a non-negative integer z — the maximal value of f(a) after no more than k changes of zeroes to ones. On the second line print n integers a_{j} — the elements of the array a after the changes. If there are multiple answers, you can print any one of them. -----Examples----- Input 7 1 1 0 0 1 1 0 1 Output 4 1 0 0 1 1 1 1 Input 10 2 1 0 0 1 0 1 0 1 0 1 Output 5 1 0 0 1 1 1 1 1 0 1 Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
Solve the programming task below in a Python markdown code block. You are given n positive integers a_1, …, a_n, and an integer k ≥ 2. Count the number of pairs i, j such that 1 ≤ i < j ≤ n, and there exists an integer x such that a_i ⋅ a_j = x^k. Input The first line contains two integers n and k (2 ≤ n ≤ 10^5, 2 ≤ k ≤ 100). The second line contains n integers a_1, …, a_n (1 ≤ a_i ≤ 10^5). Output Print a single integer — the number of suitable pairs. Example Input 6 3 1 3 9 8 24 1 Output 5 Note In the sample case, the suitable pairs are: * a_1 ⋅ a_4 = 8 = 2^3; * a_1 ⋅ a_6 = 1 = 1^3; * a_2 ⋅ a_3 = 27 = 3^3; * a_3 ⋅ a_5 = 216 = 6^3; * a_4 ⋅ a_6 = 8 = 2^3. Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
Solve the programming task below in a Python markdown code block. Bearland has n cities, numbered 1 through n. Cities are connected via bidirectional roads. Each road connects two distinct cities. No two roads connect the same pair of cities. Bear Limak was once in a city a and he wanted to go to a city b. There was no direct connection so he decided to take a long walk, visiting each city exactly once. Formally: * There is no road between a and b. * There exists a sequence (path) of n distinct cities v1, v2, ..., vn that v1 = a, vn = b and there is a road between vi and vi + 1 for <image>. On the other day, the similar thing happened. Limak wanted to travel between a city c and a city d. There is no road between them but there exists a sequence of n distinct cities u1, u2, ..., un that u1 = c, un = d and there is a road between ui and ui + 1 for <image>. Also, Limak thinks that there are at most k roads in Bearland. He wonders whether he remembers everything correctly. Given n, k and four distinct cities a, b, c, d, can you find possible paths (v1, ..., vn) and (u1, ..., un) to satisfy all the given conditions? Find any solution or print -1 if it's impossible. Input The first line of the input contains two integers n and k (4 ≤ n ≤ 1000, n - 1 ≤ k ≤ 2n - 2) — the number of cities and the maximum allowed number of roads, respectively. The second line contains four distinct integers a, b, c and d (1 ≤ a, b, c, d ≤ n). Output Print -1 if it's impossible to satisfy all the given conditions. Otherwise, print two lines with paths descriptions. The first of these two lines should contain n distinct integers v1, v2, ..., vn where v1 = a and vn = b. The second line should contain n distinct integers u1, u2, ..., un where u1 = c and un = d. Two paths generate at most 2n - 2 roads: (v1, v2), (v2, v3), ..., (vn - 1, vn), (u1, u2), (u2, u3), ..., (un - 1, un). Your answer will be considered wrong if contains more than k distinct roads or any other condition breaks. Note that (x, y) and (y, x) are the same road. Examples Input 7 11 2 4 7 3 Output 2 7 1 3 6 5 4 7 1 5 4 6 2 3 Input 1000 999 10 20 30 40 Output -1 Note In the first sample test, there should be 7 cities and at most 11 roads. The provided sample solution generates 10 roads, as in the drawing. You can also see a simple path of length n between 2 and 4, and a path between 7 and 3. <image> Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
Solve the programming task below in a Python markdown code block. This problem takes its name by arguably the most important event in the life of the ancient historian Josephus: according to his tale, he and his 40 soldiers were trapped in a cave by the Romans during a siege. Refusing to surrender to the enemy, they instead opted for mass suicide, with a twist: **they formed a circle and proceeded to kill one man every three, until one last man was left (and that it was supposed to kill himself to end the act)**. Well, Josephus and another man were the last two and, as we now know every detail of the story, you may have correctly guessed that they didn't exactly follow through the original idea. You are now to create a function that returns a Josephus permutation, taking as parameters the initial *array/list of items* to be permuted as if they were in a circle and counted out every *k* places until none remained. **Tips and notes:** it helps to start counting from 1 up to n, instead of the usual range 0..n-1; k will always be >=1. For example, with n=7 and k=3 `josephus(7,3)` should act this way. ``` [1,2,3,4,5,6,7] - initial sequence [1,2,4,5,6,7] => 3 is counted out and goes into the result [3] [1,2,4,5,7] => 6 is counted out and goes into the result [3,6] [1,4,5,7] => 2 is counted out and goes into the result [3,6,2] [1,4,5] => 7 is counted out and goes into the result [3,6,2,7] [1,4] => 5 is counted out and goes into the result [3,6,2,7,5] [4] => 1 is counted out and goes into the result [3,6,2,7,5,1] [] => 4 is counted out and goes into the result [3,6,2,7,5,1,4] ``` So our final result is: ``` josephus([1,2,3,4,5,6,7],3)==[3,6,2,7,5,1,4] ``` For more info, browse the Josephus Permutation page on wikipedia; related kata: Josephus Survivor. Also, [live game demo](https://iguacel.github.io/josephus/) by [OmniZoetrope](https://www.codewars.com/users/OmniZoetrope). Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
Solve the programming task below in a Python markdown code block. You are given $n$ blocks, each of them is of the form [color$_1$|value|color$_2$], where the block can also be flipped to get [color$_2$|value|color$_1$]. A sequence of blocks is called valid if the touching endpoints of neighboring blocks have the same color. For example, the sequence of three blocks A, B and C is valid if the left color of the B is the same as the right color of the A and the right color of the B is the same as the left color of C. The value of the sequence is defined as the sum of the values of the blocks in this sequence. Find the maximum possible value of the valid sequence that can be constructed from the subset of the given blocks. The blocks from the subset can be reordered and flipped if necessary. Each block can be used at most once in the sequence. -----Input----- The first line of input contains a single integer $n$ ($1 \le n \le 100$) — the number of given blocks. Each of the following $n$ lines describes corresponding block and consists of $\mathrm{color}_{1,i}$, $\mathrm{value}_i$ and $\mathrm{color}_{2,i}$ ($1 \le \mathrm{color}_{1,i}, \mathrm{color}_{2,i} \le 4$, $1 \le \mathrm{value}_i \le 100\,000$). -----Output----- Print exactly one integer — the maximum total value of the subset of blocks, which makes a valid sequence. -----Examples----- Input 6 2 1 4 1 2 4 3 4 4 2 8 3 3 16 3 1 32 2 Output 63 Input 7 1 100000 1 1 100000 2 1 100000 2 4 50000 3 3 50000 4 4 50000 4 3 50000 3 Output 300000 Input 4 1 1000 1 2 500 2 3 250 3 4 125 4 Output 1000 -----Note----- In the first example, it is possible to form a valid sequence from all blocks. One of the valid sequences is the following: [4|2|1] [1|32|2] [2|8|3] [3|16|3] [3|4|4] [4|1|2] The first block from the input ([2|1|4] $\to$ [4|1|2]) and second ([1|2|4] $\to$ [4|2|1]) are flipped. In the second example, the optimal answers can be formed from the first three blocks as in the following (the second or the third block from the input is flipped): [2|100000|1] [1|100000|1] [1|100000|2] In the third example, it is not possible to form a valid sequence of two or more blocks, so the answer is a sequence consisting only of the first block since it is the block with the largest value. Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
Solve the programming task below in a Python markdown code block. You are given two strings $s$ and $t$ both of length $n$ and both consisting of lowercase Latin letters. In one move, you can choose any length $len$ from $1$ to $n$ and perform the following operation: Choose any contiguous substring of the string $s$ of length $len$ and reverse it; at the same time choose any contiguous substring of the string $t$ of length $len$ and reverse it as well. Note that during one move you reverse exactly one substring of the string $s$ and exactly one substring of the string $t$. Also note that borders of substrings you reverse in $s$ and in $t$ can be different, the only restriction is that you reverse the substrings of equal length. For example, if $len=3$ and $n=5$, you can reverse $s[1 \dots 3]$ and $t[3 \dots 5]$, $s[2 \dots 4]$ and $t[2 \dots 4]$, but not $s[1 \dots 3]$ and $t[1 \dots 2]$. Your task is to say if it is possible to make strings $s$ and $t$ equal after some (possibly, empty) sequence of moves. You have to answer $q$ independent test cases. -----Input----- The first line of the input contains one integer $q$ ($1 \le q \le 10^4$) — the number of test cases. Then $q$ test cases follow. The first line of the test case contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) — the length of $s$ and $t$. The second line of the test case contains one string $s$ consisting of $n$ lowercase Latin letters. The third line of the test case contains one string $t$ consisting of $n$ lowercase Latin letters. It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$ ($\sum n \le 2 \cdot 10^5$). -----Output----- For each test case, print the answer on it — "YES" (without quotes) if it is possible to make strings $s$ and $t$ equal after some (possibly, empty) sequence of moves and "NO" otherwise. -----Example----- Input 4 4 abcd abdc 5 ababa baaba 4 asdf asdg 4 abcd badc Output NO YES NO YES Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
Solve the programming task below in a Python markdown code block. Once Vasya played bricks. All the bricks in the set had regular cubical shape. Vasya vas a talented architect, however the tower he built kept falling apart. Let us consider the building process. Vasya takes a brick and puts it on top of the already built tower so that the sides of the brick are parallel to the sides of the bricks he has already used. Let's introduce a Cartesian coordinate system on the horizontal plane, where Vasya puts the first brick. Then the projection of brick number i on the plane is a square with sides parallel to the axes of coordinates with opposite corners in points (xi, 1, yi, 1) and (xi, 2, yi, 2). The bricks are cast from homogeneous plastic and the weight of a brick a × a × a is a3 grams. It is guaranteed that Vasya puts any brick except the first one on the previous one, that is the area of intersection of the upper side of the previous brick and the lower side of the next brick is always positive. We (Vasya included) live in a normal world where the laws of physical statics work. And that is why, perhaps, if we put yet another brick, the tower will collapse under its own weight. Vasya puts the cubes consecutively one on top of the other until at least one cube loses the balance and falls down. If it happens, Vasya gets upset and stops the construction. Print the number of bricks in the maximal stable tower, that is the maximal number m satisfying the condition that all the towers consisting of bricks 1, 2, ..., k for every integer k from 1 to m remain stable. Input The first input file contains an integer n (1 ≤ n ≤ 100) which is the number of bricks. Each of the next n lines contains four numbers xi, 1, yi, 1, xi, 2, yi, 2 (xi, 1 ≠ xi, 2, |xi, 1 - xi, 2| = |yi, 1 - yi, 2|) which are the coordinates of the opposite angles of the base of the brick number i. The coordinates are integers and their absolute value does not exceed 50. The cubes are given in the order Vasya puts them. It is guaranteed that the area of intersection of the upper side of the brick number i - 1 and the lower side of the brick number i is strictly strictly greater than zero for all i ≥ 2. Output Print the number of bricks in the maximal stable tower. Examples Input 2 0 0 3 3 1 0 4 3 Output 2 Input 2 0 0 3 3 2 0 5 3 Output 1 Input 3 0 0 3 3 1 0 4 3 2 0 5 3 Output 3 Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
Solve the programming task below in a Python markdown code block. At the annual family gathering, the family likes to find the oldest living family member’s age and the youngest family member’s age and calculate the difference between them. You will be given an array of all the family members' ages, in any order. The ages will be given in whole numbers, so a baby of 5 months, will have an ascribed ‘age’ of 0. Return a new array (a tuple in Python) with [youngest age, oldest age, difference between the youngest and oldest age]. Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
Solve the programming task below in a Python markdown code block. For a positive integer n let's define a function f: f(n) = - 1 + 2 - 3 + .. + ( - 1)^{n}n Your task is to calculate f(n) for a given integer n. -----Input----- The single line contains the positive integer n (1 ≤ n ≤ 10^15). -----Output----- Print f(n) in a single line. -----Examples----- Input 4 Output 2 Input 5 Output -3 -----Note----- f(4) = - 1 + 2 - 3 + 4 = 2 f(5) = - 1 + 2 - 3 + 4 - 5 = - 3 Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
Solve the programming task below in a Python markdown code block. Limak is going to participate in a contest on the last day of the 2016. The contest will start at 20:00 and will last four hours, exactly until midnight. There will be n problems, sorted by difficulty, i.e. problem 1 is the easiest and problem n is the hardest. Limak knows it will take him 5·i minutes to solve the i-th problem. Limak's friends organize a New Year's Eve party and Limak wants to be there at midnight or earlier. He needs k minutes to get there from his house, where he will participate in the contest first. How many problems can Limak solve if he wants to make it to the party? -----Input----- The only line of the input contains two integers n and k (1 ≤ n ≤ 10, 1 ≤ k ≤ 240) — the number of the problems in the contest and the number of minutes Limak needs to get to the party from his house. -----Output----- Print one integer, denoting the maximum possible number of problems Limak can solve so that he could get to the party at midnight or earlier. -----Examples----- Input 3 222 Output 2 Input 4 190 Output 4 Input 7 1 Output 7 -----Note----- In the first sample, there are 3 problems and Limak needs 222 minutes to get to the party. The three problems require 5, 10 and 15 minutes respectively. Limak can spend 5 + 10 = 15 minutes to solve first two problems. Then, at 20:15 he can leave his house to get to the party at 23:57 (after 222 minutes). In this scenario Limak would solve 2 problems. He doesn't have enough time to solve 3 problems so the answer is 2. In the second sample, Limak can solve all 4 problems in 5 + 10 + 15 + 20 = 50 minutes. At 20:50 he will leave the house and go to the party. He will get there exactly at midnight. In the third sample, Limak needs only 1 minute to get to the party. He has enough time to solve all 7 problems. Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
Solve the programming task below in a Python markdown code block. Your friend who lives in undisclosed country is involved in debt. He is borrowing 100,000-yen from a loan shark. The loan shark adds 5% interest of the debt and rounds it to the nearest 1,000 above week by week. Write a program which computes the amount of the debt in n weeks. Input An integer n (0 ≤ n ≤ 100) is given in a line. Output Print the amout of the debt in a line. Example Input 5 Output 130000 Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
Solve the programming task below in a Python markdown code block. Pasha is participating in a contest on one well-known website. This time he wants to win the contest and will do anything to get to the first place! This contest consists of n problems, and Pasha solves ith problem in a_{i} time units (his solutions are always correct). At any moment of time he can be thinking about a solution to only one of the problems (that is, he cannot be solving two problems at the same time). The time Pasha spends to send his solutions is negligible. Pasha can send any number of solutions at the same moment. Unfortunately, there are too many participants, and the website is not always working. Pasha received the information that the website will be working only during m time periods, jth period is represented by its starting moment l_{j} and ending moment r_{j}. Of course, Pasha can send his solution only when the website is working. In other words, Pasha can send his solution at some moment T iff there exists a period x such that l_{x} ≤ T ≤ r_{x}. Pasha wants to know his best possible result. We need to tell him the minimal moment of time by which he is able to have solutions to all problems submitted, if he acts optimally, or say that it's impossible no matter how Pasha solves the problems. -----Input----- The first line contains one integer n (1 ≤ n ≤ 1000) — the number of problems. The second line contains n integers a_{i} (1 ≤ a_{i} ≤ 10^5) — the time Pasha needs to solve ith problem. The third line contains one integer m (0 ≤ m ≤ 1000) — the number of periods of time when the website is working. Next m lines represent these periods. jth line contains two numbers l_{j} and r_{j} (1 ≤ l_{j} < r_{j} ≤ 10^5) — the starting and the ending moment of jth period. It is guaranteed that the periods are not intersecting and are given in chronological order, so for every j > 1 the condition l_{j} > r_{j} - 1 is met. -----Output----- If Pasha can solve and submit all the problems before the end of the contest, print the minimal moment of time by which he can have all the solutions submitted. Otherwise print "-1" (without brackets). -----Examples----- Input 2 3 4 2 1 4 7 9 Output 7 Input 1 5 1 1 4 Output -1 Input 1 5 1 1 5 Output 5 -----Note----- In the first example Pasha can act like this: he solves the second problem in 4 units of time and sends it immediately. Then he spends 3 time units to solve the first problem and sends it 7 time units after the contest starts, because at this moment the website starts working again. In the second example Pasha invents the solution only after the website stops working for the last time. In the third example Pasha sends the solution exactly at the end of the first period. Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
Solve the programming task below in a Python markdown code block. Karen has just arrived at school, and she has a math test today! [Image] The test is about basic addition and subtraction. Unfortunately, the teachers were too busy writing tasks for Codeforces rounds, and had no time to make an actual test. So, they just put one question in the test that is worth all the points. There are n integers written on a row. Karen must alternately add and subtract each pair of adjacent integers, and write down the sums or differences on the next row. She must repeat this process on the values on the next row, and so on, until only one integer remains. The first operation should be addition. Note that, if she ended the previous row by adding the integers, she should start the next row by subtracting, and vice versa. The teachers will simply look at the last integer, and then if it is correct, Karen gets a perfect score, otherwise, she gets a zero for the test. Karen has studied well for this test, but she is scared that she might make a mistake somewhere and it will cause her final answer to be wrong. If the process is followed, what number can she expect to be written on the last row? Since this number can be quite large, output only the non-negative remainder after dividing it by 10^9 + 7. -----Input----- The first line of input contains a single integer n (1 ≤ n ≤ 200000), the number of numbers written on the first row. The next line contains n integers. Specifically, the i-th one among these is a_{i} (1 ≤ a_{i} ≤ 10^9), the i-th number on the first row. -----Output----- Output a single integer on a line by itself, the number on the final row after performing the process above. Since this number can be quite large, print only the non-negative remainder after dividing it by 10^9 + 7. -----Examples----- Input 5 3 6 9 12 15 Output 36 Input 4 3 7 5 2 Output 1000000006 -----Note----- In the first test case, the numbers written on the first row are 3, 6, 9, 12 and 15. Karen performs the operations as follows: [Image] The non-negative remainder after dividing the final number by 10^9 + 7 is still 36, so this is the correct output. In the second test case, the numbers written on the first row are 3, 7, 5 and 2. Karen performs the operations as follows: [Image] The non-negative remainder after dividing the final number by 10^9 + 7 is 10^9 + 6, so this is the correct output. Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
Solve the programming task below in a Python markdown code block. There are $n$ rectangles in a row. You can either turn each rectangle by $90$ degrees or leave it as it is. If you turn a rectangle, its width will be height, and its height will be width. Notice that you can turn any number of rectangles, you also can turn all or none of them. You can not change the order of the rectangles. Find out if there is a way to make the rectangles go in order of non-ascending height. In other words, after all the turns, a height of every rectangle has to be not greater than the height of the previous rectangle (if it is such). -----Input----- The first line contains a single integer $n$ ($1 \leq n \leq 10^5$) — the number of rectangles. Each of the next $n$ lines contains two integers $w_i$ and $h_i$ ($1 \leq w_i, h_i \leq 10^9$) — the width and the height of the $i$-th rectangle. -----Output----- Print "YES" (without quotes) if there is a way to make the rectangles go in order of non-ascending height, otherwise print "NO". You can print each letter in any case (upper or lower). -----Examples----- Input 3 3 4 4 6 3 5 Output YES Input 2 3 4 5 5 Output NO -----Note----- In the first test, you can rotate the second and the third rectangles so that the heights will be [4, 4, 3]. In the second test, there is no way the second rectangle will be not higher than the first one. Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
Solve the programming task below in a Python markdown code block. There are two rival donut shops. The first shop sells donuts at retail: each donut costs a dollars. The second shop sells donuts only in bulk: box of b donuts costs c dollars. So if you want to buy x donuts from this shop, then you have to buy the smallest number of boxes such that the total number of donuts in them is greater or equal to x. You want to determine two positive integer values: 1. how many donuts can you buy so that they are strictly cheaper in the first shop than in the second shop? 2. how many donuts can you buy so that they are strictly cheaper in the second shop than in the first shop? If any of these values doesn't exist then that value should be equal to -1. If there are multiple possible answers, then print any of them. The printed values should be less or equal to 10^9. It can be shown that under the given constraints such values always exist if any values exist at all. Input The first line contains a single integer t (1 ≤ t ≤ 1000) — the number of testcases. Each of the next t lines contains three integers a, b and c (1 ≤ a ≤ 10^9, 2 ≤ b ≤ 10^9, 1 ≤ c ≤ 10^9). Output For each testcase print two positive integers. For both shops print such x that buying x donuts in this shop is strictly cheaper than buying x donuts in the other shop. x should be greater than 0 and less or equal to 10^9. If there is no such x, then print -1. If there are multiple answers, then print any of them. Example Input 4 5 10 4 4 5 20 2 2 3 1000000000 1000000000 1000000000 Output -1 20 8 -1 1 2 -1 1000000000 Note In the first testcase buying any number of donuts will be cheaper in the second shop. For example, for 3 or 5 donuts you'll have to buy a box of 10 donuts for 4 dollars. 3 or 5 donuts in the first shop would cost you 15 or 25 dollars, respectively, however. For 20 donuts you'll have to buy two boxes for 8 dollars total. Note that 3 and 5 are also valid answers for the second shop, along with many other answers. In the second testcase buying any number of donuts will be either cheaper in the first shop or the same price. 8 donuts cost 32 dollars in the first shop and 40 dollars in the second shop (because you have to buy two boxes). 10 donuts will cost 40 dollars in both shops, so 10 is not a valid answer for any of the shops. In the third testcase 1 donut costs 2 and 3 dollars, respectively. 2 donuts cost 4 and 3 dollars. Thus, 1 is a valid answer for the first shop and 2 is a valid answer for the second shop. In the fourth testcase 10^9 donuts cost 10^{18} dollars in the first shop and 10^9 dollars in the second shop. Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
Solve the programming task below in a Python markdown code block. The Smart Beaver from ABBYY got hooked on square matrices. Now he is busy studying an n × n size matrix, where n is odd. The Smart Beaver considers the following matrix elements good: * Elements of the main diagonal. * Elements of the secondary diagonal. * Elements of the "middle" row — the row which has exactly <image> rows above it and the same number of rows below it. * Elements of the "middle" column — the column that has exactly <image> columns to the left of it and the same number of columns to the right of it. <image> The figure shows a 5 × 5 matrix. The good elements are marked with green. Help the Smart Beaver count the sum of good elements of the given matrix. Input The first line of input data contains a single odd integer n. Each of the next n lines contains n integers aij (0 ≤ aij ≤ 100) separated by single spaces — the elements of the given matrix. The input limitations for getting 30 points are: * 1 ≤ n ≤ 5 The input limitations for getting 100 points are: * 1 ≤ n ≤ 101 Output Print a single integer — the sum of good matrix elements. Examples Input 3 1 2 3 4 5 6 7 8 9 Output 45 Input 5 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Output 17 Note In the first sample all matrix elements will be good. Good elements in the second sample are shown on the figure. Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
Solve the programming task below in a Python markdown code block. Recently Luba bought a very interesting book. She knows that it will take t seconds to read the book. Luba wants to finish reading as fast as she can. But she has some work to do in each of n next days. The number of seconds that Luba has to spend working during i-th day is a_{i}. If some free time remains, she can spend it on reading. Help Luba to determine the minimum number of day when she finishes reading. It is guaranteed that the answer doesn't exceed n. Remember that there are 86400 seconds in a day. -----Input----- The first line contains two integers n and t (1 ≤ n ≤ 100, 1 ≤ t ≤ 10^6) — the number of days and the time required to read the book. The second line contains n integers a_{i} (0 ≤ a_{i} ≤ 86400) — the time Luba has to spend on her work during i-th day. -----Output----- Print the minimum day Luba can finish reading the book. It is guaranteed that answer doesn't exceed n. -----Examples----- Input 2 2 86400 86398 Output 2 Input 2 86400 0 86400 Output 1 Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
Solve the programming task below in a Python markdown code block. # Task You are given a regular array `arr`. Let's call a `step` the difference between two adjacent elements. Your task is to sum the elements which belong to the sequence of consecutive elements of length `at least 3 (but as long as possible)`, such that the steps between the elements in this sequence are the same. Note that some elements belong to two sequences and have to be counted twice. # Example For `arr = [54, 70, 86, 1, -2, -5, 0, 5, 78, 145, 212, 15]`, the output should be `639`. ``` There are 4 sequences of equal steps in the given array: {54, 70, 86} => step +16 {1, -2, -5} => step -3 {-5, 0, 5} => step +5 {78, 145, 212} => step +67 So the answer is (54 + 70 + 86) + (1 - 2 - 5) + (-5 + 0 + 5) + (78 + 145 + 212) = 639. The last element 15 was not be counted. ``` For `arr = [7, 2, 3, 2, -2, 400, 802]`, the output should be `1200`. ``` There is only 1 sequence in arr: {-2, 400, 802} => step +402 So the answer is: -2 + 400 + 802 = 1200 ``` For `arr = [1, 2, 3, 4, 5]`, the output should be `15`. Note that we should only count {1, 2, 3, 4, 5} as a whole, any other small subset such as {1, 2, 3},{2, 3, 4},{3, 4, 5} are belong to {1, 2, 3, 4, 5}. # Input/Output - `[input]` array.integer `arr` `3 ≤ arr.length ≤ 100` - `[output]` an integer The sum of sequences. Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
Solve the programming task below in a Python markdown code block. ## Welcome to my (amazing) kata! You are given a gigantic number to decode. Each number is a code that alternates in a pattern between encoded text and a smaller, encoded number. The pattern's length varies with every test, but the alternation between encoded text and an encoded number will always be there. Following this rule, each number tested begins with encoded text and ends with an encoded number. ## How the encoding works Now, we should probably review how the string of numbers is formed - considering you have to unform it. So, first, some text is taken, and encoded. The system of encoding is taking each letter's position in the alphabet and adding 100 to it. For example, `m` in the real text would be `113` in the code-number. After the text, there is a binary number. You should convert this number to a normal, base 10 decimal (all of them can be converted into whole, non-negative numbers). Separating encoded text and encoded numbers, there is a `98`. Because the numbers are in binary, the only digits they use are '0' and '1', and each letter of the alphabet, encoded, is between 101-127, all instances of `98` are to indicate a separation between encoded text and encoded numbers. There may also be a `98` at the very end of the number. When you return your final answer, the text and numbers should always be separated by a comma (`,`) ## Example ```python decode(103115104105123101118119981001098113113113981000) = "codewars, 18, mmm, 8" ``` The part of the code until the first `98` can be decoded to `"codewars"`. `10010` is binary for `18`. `113113113` translates to `"mmm"`. And `1000` is binary for `8`. Here is a visualisation of the example: Good luck! Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
Solve the programming task below in a Python markdown code block. One day Alice was cleaning up her basement when she noticed something very curious: an infinite set of wooden pieces! Each piece was made of five square tiles, with four tiles adjacent to the fifth center tile: [Image] By the pieces lay a large square wooden board. The board is divided into $n^2$ cells arranged into $n$ rows and $n$ columns. Some of the cells are already occupied by single tiles stuck to it. The remaining cells are free. Alice started wondering whether she could fill the board completely using the pieces she had found. Of course, each piece has to cover exactly five distinct cells of the board, no two pieces can overlap and every piece should fit in the board entirely, without some parts laying outside the board borders. The board however was too large for Alice to do the tiling by hand. Can you help determine if it's possible to fully tile the board? -----Input----- The first line of the input contains a single integer $n$ ($3 \leq n \leq 50$) — the size of the board. The following $n$ lines describe the board. The $i$-th line ($1 \leq i \leq n$) contains a single string of length $n$. Its $j$-th character ($1 \leq j \leq n$) is equal to "." if the cell in the $i$-th row and the $j$-th column is free; it is equal to "#" if it's occupied. You can assume that the board contains at least one free cell. -----Output----- Output YES if the board can be tiled by Alice's pieces, or NO otherwise. You can print each letter in any case (upper or lower). -----Examples----- Input 3 #.# ... #.# Output YES Input 4 ##.# #... #### ##.# Output NO Input 5 #.### ....# #.... ###.# ##### Output YES Input 5 #.### ....# #.... ....# #..## Output NO -----Note----- The following sketches show the example boards and their tilings if such tilings exist: [Image] Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
Solve the programming task below in a Python markdown code block. RJ Freight, a Japanese railroad company for freight operations has recently constructed exchange lines at Hazawa, Yokohama. The layout of the lines is shown in Figure B-1. <image> Figure B-1: Layout of the exchange lines A freight train consists of 2 to 72 freight cars. There are 26 types of freight cars, which are denoted by 26 lowercase letters from "a" to "z". The cars of the same type are indistinguishable from each other, and each car's direction doesn't matter either. Thus, a string of lowercase letters of length 2 to 72 is sufficient to completely express the configuration of a train. Upon arrival at the exchange lines, a train is divided into two sub-trains at an arbitrary position (prior to entering the storage lines). Each of the sub-trains may have its direction reversed (using the reversal line). Finally, the two sub-trains are connected in either order to form the final configuration. Note that the reversal operation is optional for each of the sub-trains. For example, if the arrival configuration is "abcd", the train is split into two sub-trains of either 3:1, 2:2 or 1:3 cars. For each of the splitting, possible final configurations are as follows ("+" indicates final concatenation position): [3:1] abc+d cba+d d+abc d+cba [2:2] ab+cd ab+dc ba+cd ba+dc cd+ab cd+ba dc+ab dc+ba [1:3] a+bcd a+dcb bcd+a dcb+a Excluding duplicates, 12 distinct configurations are possible. Given an arrival configuration, answer the number of distinct configurations which can be constructed using the exchange lines described above. Input The entire input looks like the following. > the number of datasets = m > 1st dataset > 2nd dataset > ... > m-th dataset > Each dataset represents an arriving train, and is a string of 2 to 72 lowercase letters in an input line. Output For each dataset, output the number of possible train configurations in a line. No other characters should appear in the output. Example Input 4 aa abba abcd abcde Output 1 6 12 18 Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
Solve the programming task below in a Python markdown code block. Valera is a little boy. Yesterday he got a huge Math hometask at school, so Valera didn't have enough time to properly learn the English alphabet for his English lesson. Unfortunately, the English teacher decided to have a test on alphabet today. At the test Valera got a square piece of squared paper. The length of the side equals n squares (n is an odd number) and each unit square contains some small letter of the English alphabet. Valera needs to know if the letters written on the square piece of paper form letter "X". Valera's teacher thinks that the letters on the piece of paper form an "X", if: on both diagonals of the square paper all letters are the same; all other squares of the paper (they are not on the diagonals) contain the same letter that is different from the letters on the diagonals. Help Valera, write the program that completes the described task for him. -----Input----- The first line contains integer n (3 ≤ n < 300; n is odd). Each of the next n lines contains n small English letters — the description of Valera's paper. -----Output----- Print string "YES", if the letters on the paper form letter "X". Otherwise, print string "NO". Print the strings without quotes. -----Examples----- Input 5 xooox oxoxo soxoo oxoxo xooox Output NO Input 3 wsw sws wsw Output YES Input 3 xpx pxp xpe Output NO Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
Solve the programming task below in a Python markdown code block. Chef has recently learnt some new facts about the famous number π. For example, he was surprised that ordinary fractions are sometimes used to represent this number approximately. For example, 22/7, 355/113 or even 103993/33102. Soon, by calculating the value of 22/7 and 355/113 on paper Chef became quite disappointed because these values are not precise enough. For example, 22/7 differs in the third digit after the decimal point. So, these values are definitely should not be used for serious calculations. However, Chef doesn't know anything about 103993/33102. This fraction is quite inconvenient to calculate on paper. Chef is curious how precise this value is. So he asks you to help him and to calculate the first K digits after the decimal point of such an approximation of π. He consider this ordinary fraction as infinite decimal fraction so formally he asks you to calculate this approximation truncated to the first K digits after the decimal point. ------ 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 only line of each test case contains a single integer K. ------ Output ------ For each test case output a single line containing the value of 103993/33102 truncated to the first K digits after the decimal point. Note that for K = 0 you should output just "3" without decimal point (quotes are for clarity). ------ Constraints ------ $0 ≤ K ≤ 10^{6}$ $1 ≤ T ≤ 2000$ $The sum of K over the input does not exceed 10^{6}$ ----- Sample Input 1 ------ 3 0 6 20 ----- Sample Output 1 ------ 3 3.141592 3.14159265301190260407 ----- explanation 1 ------ Example case 1. Here K = 0 so we don't need to output any digits after the decimal point. The decimal point itself also should not be output. Example case 2. Note that here we truncate (not round) the actual value of 103993/33102 to 6 digits after the decimal point. As you see from example case 3 rounded value here differs from truncated one. Example case 3. This example is only to show that this approximation of ? is also far from perfect :) Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
Solve the programming task below in a Python markdown code block. Although Inzane successfully found his beloved bone, Zane, his owner, has yet to return. To search for Zane, he would need a lot of money, of which he sadly has none. To deal with the problem, he has decided to hack the banks. [Image] There are n banks, numbered from 1 to n. There are also n - 1 wires connecting the banks. All banks are initially online. Each bank also has its initial strength: bank i has initial strength a_{i}. Let us define some keywords before we proceed. Bank i and bank j are neighboring if and only if there exists a wire directly connecting them. Bank i and bank j are semi-neighboring if and only if there exists an online bank k such that bank i and bank k are neighboring and bank k and bank j are neighboring. When a bank is hacked, it becomes offline (and no longer online), and other banks that are neighboring or semi-neighboring to it have their strengths increased by 1. To start his plan, Inzane will choose a bank to hack first. Indeed, the strength of such bank must not exceed the strength of his computer. After this, he will repeatedly choose some bank to hack next until all the banks are hacked, but he can continue to hack bank x if and only if all these conditions are met: Bank x is online. That is, bank x is not hacked yet. Bank x is neighboring to some offline bank. The strength of bank x is less than or equal to the strength of Inzane's computer. Determine the minimum strength of the computer Inzane needs to hack all the banks. -----Input----- The first line contains one integer n (1 ≤ n ≤ 3·10^5) — the total number of banks. The second line contains n integers a_1, a_2, ..., a_{n} ( - 10^9 ≤ a_{i} ≤ 10^9) — the strengths of the banks. Each of the next n - 1 lines contains two integers u_{i} and v_{i} (1 ≤ u_{i}, v_{i} ≤ n, u_{i} ≠ v_{i}) — meaning that there is a wire directly connecting banks u_{i} and v_{i}. It is guaranteed that the wires connect the banks in such a way that Inzane can somehow hack all the banks using a computer with appropriate strength. -----Output----- Print one integer — the minimum strength of the computer Inzane needs to accomplish the goal. -----Examples----- Input 5 1 2 3 4 5 1 2 2 3 3 4 4 5 Output 5 Input 7 38 -29 87 93 39 28 -55 1 2 2 5 3 2 2 4 1 7 7 6 Output 93 Input 5 1 2 7 6 7 1 5 5 3 3 4 2 4 Output 8 -----Note----- In the first sample, Inzane can hack all banks using a computer with strength 5. Here is how: Initially, strengths of the banks are [1, 2, 3, 4, 5]. He hacks bank 5, then strengths of the banks become [1, 2, 4, 5, - ]. He hacks bank 4, then strengths of the banks become [1, 3, 5, - , - ]. He hacks bank 3, then strengths of the banks become [2, 4, - , - , - ]. He hacks bank 2, then strengths of the banks become [3, - , - , - , - ]. He completes his goal by hacking bank 1. In the second sample, Inzane can hack banks 4, 2, 3, 1, 5, 7, and 6, in this order. This way, he can hack all banks using a computer with strength 93. Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
Solve the programming task below in a Python markdown code block. In the beginning of the new year Keivan decided to reverse his name. He doesn't like palindromes, so he changed Naviek to Navick. He is too selfish, so for a given n he wants to obtain a string of n characters, each of which is either 'a', 'b' or 'c', with no palindromes of length 3 appearing in the string as a substring. For example, the strings "abc" and "abca" suit him, while the string "aba" doesn't. He also want the number of letters 'c' in his string to be as little as possible. -----Input----- The first line contains single integer n (1 ≤ n ≤ 2·10^5) — the length of the string. -----Output----- Print the string that satisfies all the constraints. If there are multiple answers, print any of them. -----Examples----- Input 2 Output aa Input 3 Output bba -----Note----- A palindrome is a sequence of characters which reads the same backward and forward. Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
Solve the programming task below in a Python markdown code block. There are some perfect squares with a particular property. For example the number ```n = 256``` is a perfect square, its square root is ```16```. If we change the position of the digits of n, we may obtain another perfect square``` 625``` (square root = 25). With these three digits ```2```,```5``` and ```6``` we can get two perfect squares: ```[256,625]``` The number ```1354896``` may generate another ```4``` perfect squares, having with the number itself, a total of five perfect squares: ```[1354896, 3594816, 3481956, 5391684, 6395841]```, being the last one in the list, ```6395841```, the highest value of the set. Your task is to find the first perfect square above the given lower_limit, that can generate the given k number of perfect squares, and it doesn't contain the digit 0. Then return the maximum perfect square that can be obtained from its digits. Example with the cases seen above: ``` lower_limit = 200 k = 2 (amount of perfect squares) result = 625 lower_limit = 3550000 k = 5 (amount of perfect squares) result = 6395841 ``` Features of the random tests: ``` 100 <= lower_limit <= 1e6 2 <= k <= 5 number of tests = 45 ``` Have a good time! Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
Solve the programming task below in a Python markdown code block. In AtCoder Kingdom, Gregorian calendar is used, and dates are written in the "year-month-day" order, or the "month-day" order without the year. For example, May 3, 2018 is written as 2018-5-3, or 5-3 without the year. In this country, a date is called Takahashi when the month and the day are equal as numbers. For example, 5-5 is Takahashi. How many days from 2018-1-1 through 2018-a-b are Takahashi? -----Constraints----- - a is an integer between 1 and 12 (inclusive). - b is an integer between 1 and 31 (inclusive). - 2018-a-b is a valid date in Gregorian calendar. -----Input----- Input is given from Standard Input in the following format: a b -----Output----- Print the number of days from 2018-1-1 through 2018-a-b that are Takahashi. -----Sample Input----- 5 5 -----Sample Output----- 5 There are five days that are Takahashi: 1-1, 2-2, 3-3, 4-4 and 5-5. Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
Solve the programming task below in a Python markdown code block. You are given a set of strings S. Each string consists of lowercase Latin letters. For each string in this set, you want to calculate the minimum number of seconds required to type this string. To type a string, you have to start with an empty string and transform it into the string you want to type using the following actions: * if the current string is t, choose some lowercase Latin letter c and append it to the back of t, so the current string becomes t + c. This action takes 1 second; * use autocompletion. When you try to autocomplete the current string t, a list of all strings s ∈ S such that t is a prefix of s is shown to you. This list includes t itself, if t is a string from S, and the strings are ordered lexicographically. You can transform t into the i-th string from this list in i seconds. Note that you may choose any string from this list you want, it is not necessarily the string you are trying to type. What is the minimum number of seconds that you have to spend to type each string from S? Note that the strings from S are given in an unusual way. Input The first line contains one integer n (1 ≤ n ≤ 10^6). Then n lines follow, the i-th line contains one integer p_i (0 ≤ p_i < i) and one lowercase Latin character c_i. These lines form some set of strings such that S is its subset as follows: there are n + 1 strings, numbered from 0 to n; the 0-th string is an empty string, and the i-th string (i ≥ 1) is the result of appending the character c_i to the string p_i. It is guaranteed that all these strings are distinct. The next line contains one integer k (1 ≤ k ≤ n) — the number of strings in S. The last line contains k integers a_1, a_2, ..., a_k (1 ≤ a_i ≤ n, all a_i are pairwise distinct) denoting the indices of the strings generated by above-mentioned process that form the set S — formally, if we denote the i-th generated string as s_i, then S = {s_{a_1}, s_{a_2}, ..., s_{a_k}}. Output Print k integers, the i-th of them should be equal to the minimum number of seconds required to type the string s_{a_i}. Examples Input 10 0 i 1 q 2 g 0 k 1 e 5 r 4 m 5 h 3 p 3 e 5 8 9 1 10 6 Output 2 4 1 3 3 Input 8 0 a 1 b 2 a 2 b 4 a 4 b 5 c 6 d 5 2 3 4 7 8 Output 1 2 2 4 4 Note In the first example, S consists of the following strings: ieh, iqgp, i, iqge, ier. Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
Solve the programming task below in a Python markdown code block. Little Susie, thanks to her older brother, likes to play with cars. Today she decided to set up a tournament between them. The process of a tournament is described in the next paragraph. There are n toy cars. Each pair collides. The result of a collision can be one of the following: no car turned over, one car turned over, both cars turned over. A car is good if it turned over in no collision. The results of the collisions are determined by an n × n matrix А: there is a number on the intersection of the і-th row and j-th column that describes the result of the collision of the і-th and the j-th car: - 1: if this pair of cars never collided. - 1 occurs only on the main diagonal of the matrix. 0: if no car turned over during the collision. 1: if only the i-th car turned over during the collision. 2: if only the j-th car turned over during the collision. 3: if both cars turned over during the collision. Susie wants to find all the good cars. She quickly determined which cars are good. Can you cope with the task? -----Input----- The first line contains integer n (1 ≤ n ≤ 100) — the number of cars. Each of the next n lines contains n space-separated integers that determine matrix A. It is guaranteed that on the main diagonal there are - 1, and - 1 doesn't appear anywhere else in the matrix. It is guaranteed that the input is correct, that is, if A_{ij} = 1, then A_{ji} = 2, if A_{ij} = 3, then A_{ji} = 3, and if A_{ij} = 0, then A_{ji} = 0. -----Output----- Print the number of good cars and in the next line print their space-separated indices in the increasing order. -----Examples----- Input 3 -1 0 0 0 -1 1 0 2 -1 Output 2 1 3 Input 4 -1 3 3 3 3 -1 3 3 3 3 -1 3 3 3 3 -1 Output 0 Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
Solve the programming task below in a Python markdown code block. You are given a string and a number k. You are suggested to generate new strings by swapping any adjacent pair of characters in the string up to k times. Write a program to report the lexicographically smallest string among them. Input The input is given in the following format. s k The first line provides a string s. The second line provides the maximum number of swapping operations k (0 ≤ k ≤ 109). The string consists solely of lower-case alphabetical letters and has a length between 1 and 2 × 105. Output Output the lexicographically smallest string. Examples Input pckoshien 3 Output ckopshien Input pckoshien 10 Output cekophsin Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
Solve the programming task below in a Python markdown code block. Artem has an array of n positive integers. Artem decided to play with it. The game consists of n moves. Each move goes like this. Artem chooses some element of the array and removes it. For that, he gets min(a, b) points, where a and b are numbers that were adjacent with the removed number. If the number doesn't have an adjacent number to the left or right, Artem doesn't get any points. After the element is removed, the two parts of the array glue together resulting in the new array that Artem continues playing with. Borya wondered what maximum total number of points Artem can get as he plays this game. -----Input----- The first line contains a single integer n (1 ≤ n ≤ 5·10^5) — the number of elements in the array. The next line contains n integers a_{i} (1 ≤ a_{i} ≤ 10^6) — the values of the array elements. -----Output----- In a single line print a single integer — the maximum number of points Artem can get. -----Examples----- Input 5 3 1 5 2 6 Output 11 Input 5 1 2 3 4 5 Output 6 Input 5 1 100 101 100 1 Output 102 Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
Solve the programming task below in a Python markdown code block. In this kata you will create a function to check a non-negative input to see if it is a prime number. The function will take in a number and will return True if it is a prime number and False if it is not. A prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself. ### Examples Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
Solve the programming task below in a Python markdown code block. The statement of this problem shares a lot with problem A. The differences are that in this problem, the probability is introduced, and the constraint is different. A robot cleaner is placed on the floor of a rectangle room, surrounded by walls. The floor consists of n rows and m columns. The rows of the floor are numbered from 1 to n from top to bottom, and columns of the floor are numbered from 1 to m from left to right. The cell on the intersection of the r-th row and the c-th column is denoted as (r,c). The initial position of the robot is (r_b, c_b). In one second, the robot moves by dr rows and dc columns, that is, after one second, the robot moves from the cell (r, c) to (r + dr, c + dc). Initially dr = 1, dc = 1. If there is a vertical wall (the left or the right walls) in the movement direction, dc is reflected before the movement, so the new value of dc is -dc. And if there is a horizontal wall (the upper or lower walls), dr is reflected before the movement, so the new value of dr is -dr. Each second (including the moment before the robot starts moving), the robot cleans every cell lying in the same row or the same column as its position. There is only one dirty cell at (r_d, c_d). The job of the robot is to clean that dirty cell. After a lot of testings in problem A, the robot is now broken. It cleans the floor as described above, but at each second the cleaning operation is performed with probability \frac p {100} only, and not performed with probability 1 - \frac p {100}. The cleaning or not cleaning outcomes are independent each second. Given the floor size n and m, the robot's initial position (r_b, c_b) and the dirty cell's position (r_d, c_d), find the expected time for the robot to do its job. It can be shown that the answer can be expressed as an irreducible fraction \frac x y, where x and y are integers and y not ≡ 0 \pmod{10^9 + 7} . Output the integer equal to x ⋅ y^{-1} mod (10^9 + 7). In other words, output such an integer a that 0 ≤ a < 10^9 + 7 and a ⋅ y ≡ x \pmod {10^9 + 7}. Input Each test contains multiple test cases. The first line contains the number of test cases t (1 ≤ t ≤ 10). Description of the test cases follows. A test case consists of only one line, containing n, m, r_b, c_b, r_d, c_d, and p (4 ≤ n ⋅ m ≤ 10^5, n, m ≥ 2, 1 ≤ r_b, r_d ≤ n, 1 ≤ c_b, c_d ≤ m, 1 ≤ p ≤ 99) — the sizes of the room, the initial position of the robot, the position of the dirt cell and the probability of cleaning in percentage. Output For each test case, print a single integer — the expected time for the robot to clean the dirty cell, modulo 10^9 + 7. Example Input 6 2 2 1 1 2 1 25 3 3 1 2 2 2 25 10 10 1 1 10 10 75 10 10 10 10 1 1 75 5 5 1 3 2 2 10 97 98 3 5 41 43 50 Output 3 3 15 15 332103349 99224487 Note In the first test case, the robot has the opportunity to clean the dirty cell every second. Using the [geometric distribution](https://en.wikipedia.org/wiki/Geometric_distribution), we can find out that with the success rate of 25\%, the expected number of tries to clear the dirty cell is \frac 1 {0.25} = 4. But because the first moment the robot has the opportunity to clean the cell is before the robot starts moving, the answer is 3. <image> Illustration for the first example. The blue arc is the robot. The red star is the target dirt cell. The purple square is the initial position of the robot. Each second the robot has an opportunity to clean a row and a column, denoted by yellow stripes. In the second test case, the board size and the position are different, but the robot still has the opportunity to clean the dirty cell every second, and it has the same probability of cleaning. Therefore the answer is the same as in the first example. <image> Illustration for the second example. The third and the fourth case are almost the same. The only difference is that the position of the dirty cell and the robot are swapped. But the movements in both cases are identical, hence the same result. Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
Solve the programming task below in a Python markdown code block. a is an array of n positive integers, all of which are not greater than n. You have to process q queries to this array. Each query is represented by two numbers p and k. Several operations are performed in each query; each operation changes p to p + ap + k. There operations are applied until p becomes greater than n. The answer to the query is the number of performed operations. Input The first line contains one integer n (1 ≤ n ≤ 100000). The second line contains n integers — elements of a (1 ≤ ai ≤ n for each i from 1 to n). The third line containts one integer q (1 ≤ q ≤ 100000). Then q lines follow. Each line contains the values of p and k for corresponding query (1 ≤ p, k ≤ n). Output Print q integers, ith integer must be equal to the answer to ith query. Example Input 3 1 1 1 3 1 1 2 1 3 1 Output 2 1 1 Note Consider first example: In first query after first operation p = 3, after second operation p = 5. In next two queries p is greater than n after the first operation. Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
Solve the programming task below in a Python markdown code block. JOI has a stove in your room. JOI himself is resistant to the cold, so he doesn't need to put on the stove when he is alone in the room, but he needs to put on the stove when there are visitors. On this day, there are N guests under JOI. The ith (1 \ leq i \ leq N) visitor arrives at time T_i and leaves at time T_i + 1. There can never be more than one visitor at the same time. JOI can turn the stove on and off at any time. However, each time you turn on the stove, you will consume one match. JOI has only K matches, so he can only stove up to K times. The stove is gone at the beginning of the day. When the stove is on, fuel is consumed by that amount, so I want to set the time when the stove is on and off and minimize the total time when the stove is on. Example Input 3 2 1 3 6 Output 4 Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
Solve the programming task below in a Python markdown code block. Ori and Sein have overcome many difficult challenges. They finally lit the Shrouded Lantern and found Gumon Seal, the key to the Forlorn Ruins. When they tried to open the door to the ruins... nothing happened. Ori was very surprised, but Sein gave the explanation quickly: clever Gumon decided to make an additional defence for the door. There are $n$ lamps with Spirit Tree's light. Sein knows the time of turning on and off for the $i$-th lamp — $l_i$ and $r_i$ respectively. To open the door you have to choose $k$ lamps in such a way that there will be a moment of time when they all will be turned on. While Sein decides which of the $k$ lamps to pick, Ori is interested: how many ways there are to pick such $k$ lamps that the door will open? It may happen that Sein may be wrong and there are no such $k$ lamps. The answer might be large, so print it modulo $998\,244\,353$. -----Input----- First line contains two integers $n$ and $k$ ($1 \le n \le 3 \cdot 10^5$, $1 \le k \le n$) — total number of lamps and the number of lamps that must be turned on simultaneously. Next $n$ lines contain two integers $l_i$ ans $r_i$ ($1 \le l_i \le r_i \le 10^9$) — period of time when $i$-th lamp is turned on. -----Output----- Print one integer — the answer to the task modulo $998\,244\,353$. -----Examples----- Input 7 3 1 7 3 8 4 5 6 7 1 3 5 10 8 9 Output 9 Input 3 1 1 1 2 2 3 3 Output 3 Input 3 2 1 1 2 2 3 3 Output 0 Input 3 3 1 3 2 3 3 3 Output 1 Input 5 2 1 3 2 4 3 5 4 6 5 7 Output 7 -----Note----- In first test case there are nine sets of $k$ lamps: $(1, 2, 3)$, $(1, 2, 4)$, $(1, 2, 5)$, $(1, 2, 6)$, $(1, 3, 6)$, $(1, 4, 6)$, $(2, 3, 6)$, $(2, 4, 6)$, $(2, 6, 7)$. In second test case $k=1$, so the answer is 3. In third test case there are no such pairs of lamps. In forth test case all lamps are turned on in a time $3$, so the answer is 1. In fifth test case there are seven sets of $k$ lamps: $(1, 2)$, $(1, 3)$, $(2, 3)$, $(2, 4)$, $(3, 4)$, $(3, 5)$, $(4, 5)$. Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
Solve the programming task below in a Python markdown code block. It is the easy version of the problem. The difference is that in this version, there are no nodes with already chosen colors. Theofanis is starving, and he wants to eat his favorite food, sheftalia. However, he should first finish his homework. Can you help him with this problem? You have a perfect binary tree of $2^k - 1$ nodes — a binary tree where all vertices $i$ from $1$ to $2^{k - 1} - 1$ have exactly two children: vertices $2i$ and $2i + 1$. Vertices from $2^{k - 1}$ to $2^k - 1$ don't have any children. You want to color its vertices with the $6$ Rubik's cube colors (White, Green, Red, Blue, Orange and Yellow). Let's call a coloring good when all edges connect nodes with colors that are neighboring sides in the Rubik's cube. A picture of Rubik's cube and its 2D map. More formally: a white node can not be neighboring with white and yellow nodes; a yellow node can not be neighboring with white and yellow nodes; a green node can not be neighboring with green and blue nodes; a blue node can not be neighboring with green and blue nodes; a red node can not be neighboring with red and orange nodes; an orange node can not be neighboring with red and orange nodes; You want to calculate the number of the good colorings of the binary tree. Two colorings are considered different if at least one node is colored with a different color. The answer may be too large, so output the answer modulo $10^9+7$. -----Input----- The first and only line contains the integers $k$ ($1 \le k \le 60$) — the number of levels in the perfect binary tree you need to color. -----Output----- Print one integer — the number of the different colorings modulo $10^9+7$. -----Examples----- Input 3 Output 24576 Input 14 Output 934234 -----Note----- In the picture below, you can see one of the correct colorings of the first example. Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
Solve the programming task below in a Python markdown code block. You are given a positive integer x. Find any such 2 positive integers a and b such that GCD(a,b)+LCM(a,b)=x. As a reminder, GCD(a,b) is the greatest integer that divides both a and b. Similarly, LCM(a,b) is the smallest integer such that both a and b divide it. It's guaranteed that the solution always exists. If there are several such pairs (a, b), you can output any of them. Input The first line contains a single integer t (1 ≤ t ≤ 100) — the number of testcases. Each testcase consists of one line containing a single integer, x (2 ≤ x ≤ 10^9). Output For each testcase, output a pair of positive integers a and b (1 ≤ a, b ≤ 10^9) such that GCD(a,b)+LCM(a,b)=x. It's guaranteed that the solution always exists. If there are several such pairs (a, b), you can output any of them. Example Input 2 2 14 Output 1 1 6 4 Note In the first testcase of the sample, GCD(1,1)+LCM(1,1)=1+1=2. In the second testcase of the sample, GCD(6,4)+LCM(6,4)=2+12=14. Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
Solve the programming task below in a Python markdown code block. What are you doing at the end of the world? Are you busy? Will you save us? [Image] Nephren is playing a game with little leprechauns. She gives them an infinite array of strings, f_{0... ∞}. f_0 is "What are you doing at the end of the world? Are you busy? Will you save us?". She wants to let more people know about it, so she defines f_{i} = "What are you doing while sending "f_{i} - 1"? Are you busy? Will you send "f_{i} - 1"?" for all i ≥ 1. For example, f_1 is "What are you doing while sending "What are you doing at the end of the world? Are you busy? Will you save us?"? Are you busy? Will you send "What are you doing at the end of the world? Are you busy? Will you save us?"?". Note that the quotes in the very beginning and in the very end are for clarity and are not a part of f_1. It can be seen that the characters in f_{i} are letters, question marks, (possibly) quotation marks and spaces. Nephren will ask the little leprechauns q times. Each time she will let them find the k-th character of f_{n}. The characters are indexed starting from 1. If f_{n} consists of less than k characters, output '.' (without quotes). Can you answer her queries? -----Input----- The first line contains one integer q (1 ≤ q ≤ 10) — the number of Nephren's questions. Each of the next q lines describes Nephren's question and contains two integers n and k (0 ≤ n ≤ 10^5, 1 ≤ k ≤ 10^18). -----Output----- One line containing q characters. The i-th character in it should be the answer for the i-th query. -----Examples----- Input 3 1 1 1 2 1 111111111111 Output Wh. Input 5 0 69 1 194 1 139 0 47 1 66 Output abdef Input 10 4 1825 3 75 3 530 4 1829 4 1651 3 187 4 584 4 255 4 774 2 474 Output Areyoubusy -----Note----- For the first two examples, refer to f_0 and f_1 given in the legend. Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
Solve the programming task below in a Python markdown code block. Given a string that includes alphanumeric characters ('3a4B2d') return the expansion of that string: The numeric values represent the occurrence of each letter preceding that numeric value. There should be no numeric characters in the final string. Empty strings should return an empty string. The first occurrence of a numeric value should be the number of times each character behind it is repeated, until the next numeric value appears. ```python string_expansion('3D2a5d2f') == 'DDDaadddddff' ``` ```python string_expansion('3abc') == 'aaabbbccc' # correct string_expansion('3abc') != 'aaabc' # wrong string_expansion('3abc') != 'abcabcabc' # wrong ``` If there are two consecutive numeric characters the first one is ignored. ```python string_expansion('3d332f2a') == 'dddffaa' ``` If there are two consecutive alphabetic characters then the first character has no effect on the one after it. ```python string_expansion('abcde') == 'abcde' ``` Your code should be able to work for both lower and capital case letters. ```python string_expansion('') == '' ``` Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.