question
large_stringlengths
265
13.2k
Solve the programming task below in a Python markdown code block. Takahashi is standing on a multiplication table with infinitely many rows and columns. The square (i,j) contains the integer i \times j. Initially, Takahashi is standing at (1,1). In one move, he can move from (i,j) to either (i+1,j) or (i,j+1). Given an integer N, find the minimum number of moves needed to reach a square that contains N. -----Constraints----- - 2 \leq N \leq 10^{12} - N is an integer. -----Input----- Input is given from Standard Input in the following format: N -----Output----- Print the minimum number of moves needed to reach a square that contains the integer N. -----Sample Input----- 10 -----Sample Output----- 5 (2,5) can be reached in five moves. We cannot reach a square that contains 10 in less than five moves. 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 have decided to play the game "Rock, Paper, Scissors". The game consists of several rounds, each round is independent of each other. In each round, both players show one of the following things at the same time: rock, paper or scissors. If both players showed the same things then the round outcome is a draw. Otherwise, the following rules applied: if one player showed rock and the other one showed scissors, then the player who showed rock is considered the winner and the other one is considered the loser; if one player showed scissors and the other one showed paper, then the player who showed scissors is considered the winner and the other one is considered the loser; if one player showed paper and the other one showed rock, then the player who showed paper is considered the winner and the other one is considered the loser. Alice and Bob decided to play exactly $n$ rounds of the game described above. Alice decided to show rock $a_1$ times, show scissors $a_2$ times and show paper $a_3$ times. Bob decided to show rock $b_1$ times, show scissors $b_2$ times and show paper $b_3$ times. Though, both Alice and Bob did not choose the sequence in which they show things. It is guaranteed that $a_1 + a_2 + a_3 = n$ and $b_1 + b_2 + b_3 = n$. Your task is to find two numbers: the minimum number of round Alice can win; the maximum number of rounds Alice can win. -----Input----- The first line of the input contains one integer $n$ ($1 \le n \le 10^{9}$) — the number of rounds. The second line of the input contains three integers $a_1, a_2, a_3$ ($0 \le a_i \le n$) — the number of times Alice will show rock, scissors and paper, respectively. It is guaranteed that $a_1 + a_2 + a_3 = n$. The third line of the input contains three integers $b_1, b_2, b_3$ ($0 \le b_j \le n$) — the number of times Bob will show rock, scissors and paper, respectively. It is guaranteed that $b_1 + b_2 + b_3 = n$. -----Output----- Print two integers: the minimum and the maximum number of rounds Alice can win. -----Examples----- Input 2 0 1 1 1 1 0 Output 0 1 Input 15 5 5 5 5 5 5 Output 0 15 Input 3 0 0 3 3 0 0 Output 3 3 Input 686 479 178 29 11 145 530 Output 22 334 Input 319 10 53 256 182 103 34 Output 119 226 -----Note----- In the first example, Alice will not win any rounds if she shows scissors and then paper and Bob shows rock and then scissors. In the best outcome, Alice will win one round if she shows paper and then scissors, and Bob shows rock and then scissors. In the second example, Alice will not win any rounds if Bob shows the same things as Alice each round. In the third example, Alice always shows paper and Bob always shows rock so Alice will win all three rounds anyway. 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 is given in two editions, which differ exclusively in the constraints on the number $n$. You are given an array of integers $a[1], a[2], \dots, a[n].$ A block is a sequence of contiguous (consecutive) elements $a[l], a[l+1], \dots, a[r]$ ($1 \le l \le r \le n$). Thus, a block is defined by a pair of indices $(l, r)$. Find a set of blocks $(l_1, r_1), (l_2, r_2), \dots, (l_k, r_k)$ such that: They do not intersect (i.e. they are disjoint). Formally, for each pair of blocks $(l_i, r_i)$ and $(l_j, r_j$) where $i \neq j$ either $r_i < l_j$ or $r_j < l_i$. For each block the sum of its elements is the same. Formally, $$a[l_1]+a[l_1+1]+\dots+a[r_1]=a[l_2]+a[l_2+1]+\dots+a[r_2]=$$ $$\dots =$$ $$a[l_k]+a[l_k+1]+\dots+a[r_k].$$ The number of the blocks in the set is maximum. Formally, there does not exist a set of blocks $(l_1', r_1'), (l_2', r_2'), \dots, (l_{k'}', r_{k'}')$ satisfying the above two requirements with $k' > k$. $\left. \begin{array}{|l|l|l|l|l|l|} \hline 4 & {1} & {2} & {2} & {1} & {5} & {3} \\ \hline \end{array} \right.$ The picture corresponds to the first example. Blue boxes illustrate blocks. Write a program to find such a set of blocks. -----Input----- The first line contains integer $n$ ($1 \le n \le 50$) — the length of the given array. The second line contains the sequence of elements $a[1], a[2], \dots, a[n]$ ($-10^5 \le a_i \le 10^5$). -----Output----- In the first line print the integer $k$ ($1 \le k \le n$). The following $k$ lines should contain blocks, one per line. In each line print a pair of indices $l_i, r_i$ ($1 \le l_i \le r_i \le n$) — the bounds of the $i$-th block. You can print blocks in any order. If there are multiple answers, print any of them. -----Examples----- Input 7 4 1 2 2 1 5 3 Output 3 7 7 2 3 4 5 Input 11 -5 -4 -3 -2 -1 0 1 2 3 4 5 Output 2 3 4 1 1 Input 4 1 1 1 1 Output 4 4 4 1 1 2 2 3 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. You are given two strings $s$ and $t$. Both strings have length $n$ and consist of lowercase Latin letters. The characters in the strings are numbered from $1$ to $n$. You can successively perform the following move any number of times (possibly, zero): swap any two adjacent (neighboring) characters of $s$ (i.e. for any $i = \{1, 2, \dots, n - 1\}$ you can swap $s_i$ and $s_{i + 1})$. You can't apply a move to the string $t$. The moves are applied to the string $s$ one after another. Your task is to obtain the string $t$ from the string $s$. Find any way to do it with at most $10^4$ such moves. You do not have to minimize the number of moves, just find any sequence of moves of length $10^4$ or less to transform $s$ into $t$. -----Input----- The first line of the input contains one integer $n$ ($1 \le n \le 50$) — the length of strings $s$ and $t$. The second line of the input contains the string $s$ consisting of $n$ lowercase Latin letters. The third line of the input contains the string $t$ consisting of $n$ lowercase Latin letters. -----Output----- If it is impossible to obtain the string $t$ using moves, print "-1". Otherwise in the first line print one integer $k$ — the number of moves to transform $s$ to $t$. Note that $k$ must be an integer number between $0$ and $10^4$ inclusive. In the second line print $k$ integers $c_j$ ($1 \le c_j < n$), where $c_j$ means that on the $j$-th move you swap characters $s_{c_j}$ and $s_{c_j + 1}$. If you do not need to apply any moves, print a single integer $0$ in the first line and either leave the second line empty or do not print it at all. -----Examples----- Input 6 abcdef abdfec Output 4 3 5 4 5 Input 4 abcd accd Output -1 -----Note----- In the first example the string $s$ changes as follows: "abcdef" $\rightarrow$ "abdcef" $\rightarrow$ "abdcfe" $\rightarrow$ "abdfce" $\rightarrow$ "abdfec". In the second example there is no way to transform the string $s$ into the string $t$ through any allowed moves. 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. Ivan wants to play a game with you. He picked some string $s$ of length $n$ consisting only of lowercase Latin letters. You don't know this string. Ivan has informed you about all its improper prefixes and suffixes (i.e. prefixes and suffixes of lengths from $1$ to $n-1$), but he didn't tell you which strings are prefixes and which are suffixes. Ivan wants you to guess which of the given $2n-2$ strings are prefixes of the given string and which are suffixes. It may be impossible to guess the string Ivan picked (since multiple strings may give the same set of suffixes and prefixes), but Ivan will accept your answer if there is at least one string that is consistent with it. Let the game begin! -----Input----- The first line of the input contains one integer number $n$ ($2 \le n \le 100$) — the length of the guessed string $s$. The next $2n-2$ lines are contain prefixes and suffixes, one per line. Each of them is the string of length from $1$ to $n-1$ consisting only of lowercase Latin letters. They can be given in arbitrary order. It is guaranteed that there are exactly $2$ strings of each length from $1$ to $n-1$. It is also guaranteed that these strings are prefixes and suffixes of some existing string of length $n$. -----Output----- Print one string of length $2n-2$ — the string consisting only of characters 'P' and 'S'. The number of characters 'P' should be equal to the number of characters 'S'. The $i$-th character of this string should be 'P' if the $i$-th of the input strings is the prefix and 'S' otherwise. If there are several possible answers, you can print any. -----Examples----- Input 5 ba a abab a aba baba ab aba Output SPPSPSPS Input 3 a aa aa a Output PPSS Input 2 a c Output PS -----Note----- The only string which Ivan can guess in the first example is "ababa". The only string which Ivan can guess in the second example is "aaa". Answers "SPSP", "SSPP" and "PSPS" are also acceptable. In the third example Ivan can guess the string "ac" or the string "ca". The answer "SP" is also acceptable. 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 house with $n$ flats situated on the main street of Berlatov. Vova is watching this house every night. The house can be represented as an array of $n$ integer numbers $a_1, a_2, \dots, a_n$, where $a_i = 1$ if in the $i$-th flat the light is on and $a_i = 0$ otherwise. Vova thinks that people in the $i$-th flats are disturbed and cannot sleep if and only if $1 < i < n$ and $a_{i - 1} = a_{i + 1} = 1$ and $a_i = 0$. Vova is concerned by the following question: what is the minimum number $k$ such that if people from exactly $k$ pairwise distinct flats will turn off the lights then nobody will be disturbed? Your task is to find this number $k$. -----Input----- The first line of the input contains one integer $n$ ($3 \le n \le 100$) — the number of flats in the house. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($a_i \in \{0, 1\}$), where $a_i$ is the state of light in the $i$-th flat. -----Output----- Print only one integer — the minimum number $k$ such that if people from exactly $k$ pairwise distinct flats will turn off the light then nobody will be disturbed. -----Examples----- Input 10 1 1 0 1 1 0 1 0 1 0 Output 2 Input 5 1 1 0 0 0 Output 0 Input 4 1 1 1 1 Output 0 -----Note----- In the first example people from flats $2$ and $7$ or $4$ and $7$ can turn off the light and nobody will be disturbed. It can be shown that there is no better answer in this example. There are no disturbed people in second and third 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. You are given an array $a$ consisting of $n$ integers. Your task is to say the number of such positive integers $x$ such that $x$ divides each number from the array. In other words, you have to find the number of common divisors of all elements in the array. For example, if the array $a$ will be $[2, 4, 6, 2, 10]$, then $1$ and $2$ divide each number from the array (so the answer for this test is $2$). -----Input----- The first line of the input contains one integer $n$ ($1 \le n \le 4 \cdot 10^5$) — the number of elements in $a$. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^{12}$), where $a_i$ is the $i$-th element of $a$. -----Output----- Print one integer — the number of such positive integers $x$ such that $x$ divides each number from the given array (in other words, the answer is the number of common divisors of all elements in the array). -----Examples----- Input 5 1 2 3 4 5 Output 1 Input 6 6 90 12 18 30 18 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. Vova's house is an array consisting of $n$ elements (yeah, this is the first problem, I think, where someone lives in the array). There are heaters in some positions of the array. The $i$-th element of the array is $1$ if there is a heater in the position $i$, otherwise the $i$-th element of the array is $0$. Each heater has a value $r$ ($r$ is the same for all heaters). This value means that the heater at the position $pos$ can warm up all the elements in range $[pos - r + 1; pos + r - 1]$. Vova likes to walk through his house while he thinks, and he hates cold positions of his house. Vova wants to switch some of his heaters on in such a way that each element of his house will be warmed up by at least one heater. Vova's target is to warm up the whole house (all the elements of the array), i.e. if $n = 6$, $r = 2$ and heaters are at positions $2$ and $5$, then Vova can warm up the whole house if he switches all the heaters in the house on (then the first $3$ elements will be warmed up by the first heater and the last $3$ elements will be warmed up by the second heater). Initially, all the heaters are off. But from the other hand, Vova didn't like to pay much for the electricity. So he wants to switch the minimum number of heaters on in such a way that each element of his house is warmed up by at least one heater. Your task is to find this number of heaters or say that it is impossible to warm up the whole house. -----Input----- The first line of the input contains two integers $n$ and $r$ ($1 \le n, r \le 1000$) — the number of elements in the array and the value of heaters. The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($0 \le a_i \le 1$) — the Vova's house description. -----Output----- Print one integer — the minimum number of heaters needed to warm up the whole house or -1 if it is impossible to do it. -----Examples----- Input 6 2 0 1 1 0 0 1 Output 3 Input 5 3 1 0 0 0 1 Output 2 Input 5 10 0 0 0 0 0 Output -1 Input 10 3 0 0 1 1 0 1 0 0 0 1 Output 3 -----Note----- In the first example the heater at the position $2$ warms up elements $[1; 3]$, the heater at the position $3$ warms up elements $[2, 4]$ and the heater at the position $6$ warms up elements $[5; 6]$ so the answer is $3$. In the second example the heater at the position $1$ warms up elements $[1; 3]$ and the heater at the position $5$ warms up elements $[3; 5]$ so the answer is $2$. In the third example there are no heaters so the answer is -1. In the fourth example the heater at the position $3$ warms up elements $[1; 5]$, the heater at the position $6$ warms up elements $[4; 8]$ and the heater at the position $10$ warms up elements $[8; 10]$ so the answer is $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 positive integer N. How many tuples (A,B,C) of positive integers satisfy A \times B + C = N? -----Constraints----- - 2 \leq N \leq 10^6 - All values in input are integers. -----Input----- Input is given from Standard Input in the following format: N -----Output----- Print the answer. -----Sample Input----- 3 -----Sample Output----- 3 There are 3 tuples of integers that satisfy A \times B + C = 3: (A, B, C) = (1, 1, 2), (1, 2, 1), (2, 1, 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 a bracket sequence $s$ consisting of $n$ opening '(' and closing ')' brackets. A regular bracket sequence is a bracket sequence that can be transformed into a correct arithmetic expression by inserting characters '1' and '+' between the original characters of the sequence. For example, bracket sequences "()()", "(())" are regular (the resulting expressions are: "(1)+(1)", "((1+1)+1)"), and ")(" and "(" are not. You can change the type of some bracket $s_i$. It means that if $s_i = $ ')' then you can change it to '(' and vice versa. Your task is to calculate the number of positions $i$ such that if you change the type of the $i$-th bracket, then the resulting bracket sequence becomes regular. -----Input----- The first line of the input contains one integer $n$ ($1 \le n \le 10^6$) — the length of the bracket sequence. The second line of the input contains the string $s$ consisting of $n$ opening '(' and closing ')' brackets. -----Output----- Print one integer — the number of positions $i$ such that if you change the type of the $i$-th bracket, then the resulting bracket sequence becomes regular. -----Examples----- Input 6 (((()) Output 3 Input 6 ()()() Output 0 Input 1 ) Output 0 Input 8 )))((((( 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. The only difference between easy and hard versions is the length of the string. You are given a string $s$ and a string $t$, both consisting only of lowercase Latin letters. It is guaranteed that $t$ can be obtained from $s$ by removing some (possibly, zero) number of characters (not necessary contiguous) from $s$ without changing order of remaining characters (in other words, it is guaranteed that $t$ is a subsequence of $s$). For example, the strings "test", "tst", "tt", "et" and "" are subsequences of the string "test". But the strings "tset", "se", "contest" are not subsequences of the string "test". You want to remove some substring (contiguous subsequence) from $s$ of maximum possible length such that after removing this substring $t$ will remain a subsequence of $s$. If you want to remove the substring $s[l;r]$ then the string $s$ will be transformed to $s_1 s_2 \dots s_{l-1} s_{r+1} s_{r+2} \dots s_{|s|-1} s_{|s|}$ (where $|s|$ is the length of $s$). Your task is to find the maximum possible length of the substring you can remove so that $t$ is still a subsequence of $s$. -----Input----- The first line of the input contains one string $s$ consisting of at least $1$ and at most $2 \cdot 10^5$ lowercase Latin letters. The second line of the input contains one string $t$ consisting of at least $1$ and at most $2 \cdot 10^5$ lowercase Latin letters. It is guaranteed that $t$ is a subsequence of $s$. -----Output----- Print one integer — the maximum possible length of the substring you can remove so that $t$ is still a subsequence of $s$. -----Examples----- Input bbaba bb Output 3 Input baaba ab Output 2 Input abcde abcde Output 0 Input asdfasdf fasd 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. Given are integers a,b,c and d. If x and y are integers and a \leq x \leq b and c\leq y \leq d hold, what is the maximum possible value of x \times y? -----Constraints----- - -10^9 \leq a \leq b \leq 10^9 - -10^9 \leq c \leq d \leq 10^9 - All values in input are integers. -----Input----- Input is given from Standard Input in the following format: a b c d -----Output----- Print the answer. -----Sample Input----- 1 2 1 1 -----Sample Output----- 2 If x = 1 and y = 1 then x \times y = 1. If x = 2 and y = 1 then x \times y = 2. Therefore, the answer is 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. Vova had a pretty weird sleeping schedule. There are $h$ hours in a day. Vova will sleep exactly $n$ times. The $i$-th time he will sleep exactly after $a_i$ hours from the time he woke up. You can assume that Vova woke up exactly at the beginning of this story (the initial time is $0$). Each time Vova sleeps exactly one day (in other words, $h$ hours). Vova thinks that the $i$-th sleeping time is good if he starts to sleep between hours $l$ and $r$ inclusive. Vova can control himself and before the $i$-th time can choose between two options: go to sleep after $a_i$ hours or after $a_i - 1$ hours. Your task is to say the maximum number of good sleeping times Vova can obtain if he acts optimally. -----Input----- The first line of the input contains four integers $n, h, l$ and $r$ ($1 \le n \le 2000, 3 \le h \le 2000, 0 \le l \le r < h$) — the number of times Vova goes to sleep, the number of hours in a day and the segment of the good sleeping time. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i < h$), where $a_i$ is the number of hours after which Vova goes to sleep the $i$-th time. -----Output----- Print one integer — the maximum number of good sleeping times Vova can obtain if he acts optimally. -----Example----- Input 7 24 21 23 16 17 14 20 20 11 22 Output 3 -----Note----- The maximum number of good times in the example is $3$. The story starts from $t=0$. Then Vova goes to sleep after $a_1 - 1$ hours, now the time is $15$. This time is not good. Then Vova goes to sleep after $a_2 - 1$ hours, now the time is $15 + 16 = 7$. This time is also not good. Then Vova goes to sleep after $a_3$ hours, now the time is $7 + 14 = 21$. This time is good. Then Vova goes to sleep after $a_4 - 1$ hours, now the time is $21 + 19 = 16$. This time is not good. Then Vova goes to sleep after $a_5$ hours, now the time is $16 + 20 = 12$. This time is not good. Then Vova goes to sleep after $a_6$ hours, now the time is $12 + 11 = 23$. This time is good. Then Vova goes to sleep after $a_7$ hours, now the time is $23 + 22 = 21$. This time is also good. 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 problemset consisting of $n$ problems. The difficulty of the $i$-th problem is $a_i$. It is guaranteed that all difficulties are distinct and are given in the increasing order. You have to assemble the contest which consists of some problems of the given problemset. In other words, the contest you have to assemble should be a subset of problems (not necessary consecutive) of the given problemset. There is only one condition that should be satisfied: for each problem but the hardest one (the problem with the maximum difficulty) there should be a problem with the difficulty greater than the difficulty of this problem but not greater than twice the difficulty of this problem. In other words, let $a_{i_1}, a_{i_2}, \dots, a_{i_p}$ be the difficulties of the selected problems in increasing order. Then for each $j$ from $1$ to $p-1$ $a_{i_{j + 1}} \le a_{i_j} \cdot 2$ should hold. It means that the contest consisting of only one problem is always valid. Among all contests satisfying the condition above you have to assemble one with the maximum number of problems. Your task is to find this number of problems. -----Input----- The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) — the number of problems in the problemset. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$) — difficulties of the problems. It is guaranteed that difficulties of the problems are distinct and are given in the increasing order. -----Output----- Print a single integer — maximum number of problems in the contest satisfying the condition in the problem statement. -----Examples----- Input 10 1 2 5 6 7 10 21 23 24 49 Output 4 Input 5 2 10 50 110 250 Output 1 Input 6 4 7 12 100 150 199 Output 3 -----Note----- Description of the first example: there are $10$ valid contests consisting of $1$ problem, $10$ valid contests consisting of $2$ problems ($[1, 2], [5, 6], [5, 7], [5, 10], [6, 7], [6, 10], [7, 10], [21, 23], [21, 24], [23, 24]$), $5$ valid contests consisting of $3$ problems ($[5, 6, 7], [5, 6, 10], [5, 7, 10], [6, 7, 10], [21, 23, 24]$) and a single valid contest consisting of $4$ problems ($[5, 6, 7, 10]$). In the second example all the valid contests consist of $1$ problem. In the third example are two contests consisting of $3$ problems: $[4, 7, 12]$ and $[100, 150, 199]$. 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$ integers $a_1, a_2, \dots, a_n$. Your problem is to find such pair of indices $i, j$ ($1 \le i < j \le n$) that $lcm(a_i, a_j)$ is minimum possible. $lcm(x, y)$ is the least common multiple of $x$ and $y$ (minimum positive number such that both $x$ and $y$ are divisors of this number). -----Input----- The first line of the input contains one integer $n$ ($2 \le n \le 10^6$) — the number of elements in $a$. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^7$), where $a_i$ is the $i$-th element of $a$. -----Output----- Print two integers $i$ and $j$ ($1 \le i < j \le n$) such that the value of $lcm(a_i, a_j)$ is minimum among all valid pairs $i, j$. If there are multiple answers, you can print any. -----Examples----- Input 5 2 4 8 3 6 Output 1 2 Input 5 5 2 11 3 7 Output 2 4 Input 6 2 5 10 1 10 2 Output 1 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. There is a staircase with N steps. Takahashi is now standing at the foot of the stairs, that is, on the 0-th step. He can climb up one or two steps at a time. However, the treads of the a_1-th, a_2-th, a_3-th, \ldots, a_M-th steps are broken, so it is dangerous to set foot on those steps. How many are there to climb up to the top step, that is, the N-th step, without setting foot on the broken steps? Find the count modulo 1\ 000\ 000\ 007. -----Constraints----- - 1 \leq N \leq 10^5 - 0 \leq M \leq N-1 - 1 \leq a_1 < a_2 < ... < a_M \leq N-1 -----Input----- Input is given from Standard Input in the following format: N M a_1 a_2 . . . a_M -----Output----- Print the number of ways to climb up the stairs under the condition, modulo 1\ 000\ 000\ 007. -----Sample Input----- 6 1 3 -----Sample Output----- 4 There are four ways to climb up the stairs, as follows: - 0 \to 1 \to 2 \to 4 \to 5 \to 6 - 0 \to 1 \to 2 \to 4 \to 6 - 0 \to 2 \to 4 \to 5 \to 6 - 0 \to 2 \to 4 \to 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. Programmers' kids solve this riddle in 5-10 minutes. How fast can you do it? -----Input----- The input contains a single integer n (0 ≤ n ≤ 2000000000). -----Output----- Output a single integer. -----Examples----- Input 11 Output 2 Input 14 Output 0 Input 61441 Output 2 Input 571576 Output 10 Input 2128506 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. -----Input----- The input contains a single integer a (1 ≤ a ≤ 30). -----Output----- Output a single integer. -----Example----- Input 3 Output 27 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. -----Input----- The input contains a single integer a (10 ≤ a ≤ 999). -----Output----- Output 0 or 1. -----Examples----- Input 13 Output 1 Input 927 Output 1 Input 48 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. DO YOU EXPECT ME TO FIND THIS OUT? WHAT BASE AND/XOR LANGUAGE INCLUDES string? DON'T BYTE OF MORE THAN YOU CAN CHEW YOU CAN ONLY DISTORT THE LARGEST OF MATHEMATICS SO FAR SAYING "ABRACADABRA" WITHOUT A MAGIC AND WON'T DO YOU ANY GOOD THE LAST STACK RUPTURES. ALL DIE. OH, THE EMBARRASSMENT! I HAVE NO ARRAY AND I MUST SCREAM ELEMENTS MAY NOT BE STORED IN WEST HYPERSPACE -----Input----- The first line of input data contains a single integer n (1 ≤ n ≤ 10). The second line of input data contains n space-separated integers a_{i} (1 ≤ a_{i} ≤ 11). -----Output----- Output a single integer. -----Example----- Input 4 2 5 3 1 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. Polycarp wants to buy exactly $n$ shovels. The shop sells packages with shovels. The store has $k$ types of packages: the package of the $i$-th type consists of exactly $i$ shovels ($1 \le i \le k$). The store has an infinite number of packages of each type. Polycarp wants to choose one type of packages and then buy several (one or more) packages of this type. What is the smallest number of packages Polycarp will have to buy to get exactly $n$ shovels? For example, if $n=8$ and $k=7$, then Polycarp will buy $2$ packages of $4$ shovels. Help Polycarp find the minimum number of packages that he needs to buy, given that he: will buy exactly $n$ shovels in total; the sizes of all packages he will buy are all the same and the number of shovels in each package is an integer from $1$ to $k$, inclusive. -----Input----- The first line contains an integer $t$ ($1 \le t \le 100$) — the number of test cases in the input. Then, $t$ test cases follow, one per line. Each test case consists of two positive integers $n$ ($1 \le n \le 10^9$) and $k$ ($1 \le k \le 10^9$) — the number of shovels and the number of types of packages. -----Output----- Print $t$ answers to the test cases. Each answer is a positive integer — the minimum number of packages. -----Example----- Input 5 8 7 8 1 6 10 999999733 999999732 999999733 999999733 Output 2 8 1 999999733 1 -----Note----- The answer to the first test case was explained in the statement. In the second test case, there is only one way to buy $8$ shovels — $8$ packages of one shovel. In the third test case, you need to buy a $1$ package of $6$ shovels. 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 switches with "on" and "off" state, and M bulbs. The switches are numbered 1 to N, and the bulbs are numbered 1 to M. Bulb i is connected to k_i switches: Switch s_{i1}, s_{i2}, ..., and s_{ik_i}. It is lighted when the number of switches that are "on" among these switches is congruent to p_i modulo 2. How many combinations of "on" and "off" states of the switches light all the bulbs? -----Constraints----- - 1 \leq N, M \leq 10 - 1 \leq k_i \leq N - 1 \leq s_{ij} \leq N - s_{ia} \neq s_{ib} (a \neq b) - p_i is 0 or 1. - All values in input are integers. -----Input----- Input is given from Standard Input in the following format: N M k_1 s_{11} s_{12} ... s_{1k_1} : k_M s_{M1} s_{M2} ... s_{Mk_M} p_1 p_2 ... p_M -----Output----- Print the number of combinations of "on" and "off" states of the switches that light all the bulbs. -----Sample Input----- 2 2 2 1 2 1 2 0 1 -----Sample Output----- 1 - Bulb 1 is lighted when there is an even number of switches that are "on" among the following: Switch 1 and 2. - Bulb 2 is lighted when there is an odd number of switches that are "on" among the following: Switch 2. There are four possible combinations of states of (Switch 1, Switch 2): (on, on), (on, off), (off, on) and (off, off). Among them, only (on, on) lights all the bulbs, so we should print 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. Consider an analog clock whose hour and minute hands are A and B centimeters long, respectively. An endpoint of the hour hand and an endpoint of the minute hand are fixed at the same point, around which each hand rotates clockwise at constant angular velocity. It takes the hour and minute hands 12 hours and 1 hour to make one full rotation, respectively. At 0 o'clock, the two hands overlap each other. H hours and M minutes later, what is the distance in centimeters between the unfixed endpoints of the hands? -----Constraints----- - All values in input are integers. - 1 \leq A, B \leq 1000 - 0 \leq H \leq 11 - 0 \leq M \leq 59 -----Input----- Input is given from Standard Input in the following format: A B H M -----Output----- Print the answer without units. Your output will be accepted when its absolute or relative error from the correct value is at most 10^{-9}. -----Sample Input----- 3 4 9 0 -----Sample Output----- 5.00000000000000000000 The two hands will be in the positions shown in the figure below, so the answer is 5 centimeters. 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 integer sequence $a_1, a_2, \dots, a_n$. Find the number of pairs of indices $(l, r)$ ($1 \le l \le r \le n$) such that the value of median of $a_l, a_{l+1}, \dots, a_r$ is exactly the given number $m$. The median of a sequence is the value of an element which is in the middle of the sequence after sorting it in non-decreasing order. If the length of the sequence is even, the left of two middle elements is used. For example, if $a=[4, 2, 7, 5]$ then its median is $4$ since after sorting the sequence, it will look like $[2, 4, 5, 7]$ and the left of two middle elements is equal to $4$. The median of $[7, 1, 2, 9, 6]$ equals $6$ since after sorting, the value $6$ will be in the middle of the sequence. Write a program to find the number of pairs of indices $(l, r)$ ($1 \le l \le r \le n$) such that the value of median of $a_l, a_{l+1}, \dots, a_r$ is exactly the given number $m$. -----Input----- The first line contains integers $n$ and $m$ ($1 \le n,m \le 2\cdot10^5$) — the length of the given sequence and the required value of the median. The second line contains an integer sequence $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 2\cdot10^5$). -----Output----- Print the required number. -----Examples----- Input 5 4 1 4 5 60 4 Output 8 Input 3 1 1 1 1 Output 6 Input 15 2 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 Output 97 -----Note----- In the first example, the suitable pairs of indices are: $(1, 3)$, $(1, 4)$, $(1, 5)$, $(2, 2)$, $(2, 3)$, $(2, 5)$, $(4, 5)$ 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. The only difference between easy and hard versions is a number of elements in the array. You are given an array $a$ consisting of $n$ integers. The value of the $i$-th element of the array is $a_i$. You are also given a set of $m$ segments. The $j$-th segment is $[l_j; r_j]$, where $1 \le l_j \le r_j \le n$. You can choose some subset of the given set of segments and decrease values on each of the chosen segments by one (independently). For example, if the initial array $a = [0, 0, 0, 0, 0]$ and the given segments are $[1; 3]$ and $[2; 4]$ then you can choose both of them and the array will become $b = [-1, -2, -2, -1, 0]$. You have to choose some subset of the given segments (each segment can be chosen at most once) in such a way that if you apply this subset of segments to the array $a$ and obtain the array $b$ then the value $\max\limits_{i=1}^{n}b_i - \min\limits_{i=1}^{n}b_i$ will be maximum possible. Note that you can choose the empty set. If there are multiple answers, you can print any. If you are Python programmer, consider using PyPy instead of Python when you submit your code. -----Input----- The first line of the input contains two integers $n$ and $m$ ($1 \le n \le 300, 0 \le m \le 300$) — the length of the array $a$ and the number of segments, respectively. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($-10^6 \le a_i \le 10^6$), where $a_i$ is the value of the $i$-th element of the array $a$. The next $m$ lines are contain two integers each. The $j$-th of them contains two integers $l_j$ and $r_j$ ($1 \le l_j \le r_j \le n$), where $l_j$ and $r_j$ are the ends of the $j$-th segment. -----Output----- In the first line of the output print one integer $d$ — the maximum possible value $\max\limits_{i=1}^{n}b_i - \min\limits_{i=1}^{n}b_i$ if $b$ is the array obtained by applying some subset of the given segments to the array $a$. In the second line of the output print one integer $q$ ($0 \le q \le m$) — the number of segments you apply. In the third line print $q$ distinct integers $c_1, c_2, \dots, c_q$ in any order ($1 \le c_k \le m$) — indices of segments you apply to the array $a$ in such a way that the value $\max\limits_{i=1}^{n}b_i - \min\limits_{i=1}^{n}b_i$ of the obtained array $b$ is maximum possible. If there are multiple answers, you can print any. -----Examples----- Input 5 4 2 -2 3 1 2 1 3 4 5 2 5 1 3 Output 6 2 1 4 Input 5 4 2 -2 3 1 4 3 5 3 4 2 4 2 5 Output 7 2 3 2 Input 1 0 1000000 Output 0 0 -----Note----- In the first example the obtained array $b$ will be $[0, -4, 1, 1, 2]$ so the answer is $6$. In the second example the obtained array $b$ will be $[2, -3, 1, -1, 4]$ so the answer is $7$. In the third example you cannot do anything so the answer 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 string is called diverse if it contains consecutive (adjacent) letters of the Latin alphabet and each letter occurs exactly once. For example, the following strings are diverse: "fced", "xyz", "r" and "dabcef". The following string are not diverse: "az", "aa", "bad" and "babc". Note that the letters 'a' and 'z' are not adjacent. Formally, consider positions of all letters in the string in the alphabet. These positions should form contiguous segment, i.e. they should come one by one without any gaps. And all letters in the string should be distinct (duplicates are not allowed). You are given a sequence of strings. For each string, if it is diverse, print "Yes". Otherwise, print "No". -----Input----- The first line contains integer $n$ ($1 \le n \le 100$), denoting the number of strings to process. The following $n$ lines contains strings, one string per line. Each string contains only lowercase Latin letters, its length is between $1$ and $100$, inclusive. -----Output----- Print $n$ lines, one line per a string in the input. The line should contain "Yes" if the corresponding string is diverse and "No" if the corresponding string is not diverse. You can print each letter in any case (upper or lower). For example, "YeS", "no" and "yES" are all acceptable. -----Example----- Input 8 fced xyz r dabcef az aa bad babc Output Yes Yes Yes Yes No No No No 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 only difference between easy and hard versions is a number of elements in the array. You are given an array $a$ consisting of $n$ integers. The value of the $i$-th element of the array is $a_i$. You are also given a set of $m$ segments. The $j$-th segment is $[l_j; r_j]$, where $1 \le l_j \le r_j \le n$. You can choose some subset of the given set of segments and decrease values on each of the chosen segments by one (independently). For example, if the initial array $a = [0, 0, 0, 0, 0]$ and the given segments are $[1; 3]$ and $[2; 4]$ then you can choose both of them and the array will become $b = [-1, -2, -2, -1, 0]$. You have to choose some subset of the given segments (each segment can be chosen at most once) in such a way that if you apply this subset of segments to the array $a$ and obtain the array $b$ then the value $\max\limits_{i=1}^{n}b_i - \min\limits_{i=1}^{n}b_i$ will be maximum possible. Note that you can choose the empty set. If there are multiple answers, you can print any. If you are Python programmer, consider using PyPy instead of Python when you submit your code. -----Input----- The first line of the input contains two integers $n$ and $m$ ($1 \le n \le 10^5, 0 \le m \le 300$) — the length of the array $a$ and the number of segments, respectively. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($-10^6 \le a_i \le 10^6$), where $a_i$ is the value of the $i$-th element of the array $a$. The next $m$ lines are contain two integers each. The $j$-th of them contains two integers $l_j$ and $r_j$ ($1 \le l_j \le r_j \le n$), where $l_j$ and $r_j$ are the ends of the $j$-th segment. -----Output----- In the first line of the output print one integer $d$ — the maximum possible value $\max\limits_{i=1}^{n}b_i - \min\limits_{i=1}^{n}b_i$ if $b$ is the array obtained by applying some subset of the given segments to the array $a$. In the second line of the output print one integer $q$ ($0 \le q \le m$) — the number of segments you apply. In the third line print $q$ distinct integers $c_1, c_2, \dots, c_q$ in any order ($1 \le c_k \le m$) — indices of segments you apply to the array $a$ in such a way that the value $\max\limits_{i=1}^{n}b_i - \min\limits_{i=1}^{n}b_i$ of the obtained array $b$ is maximum possible. If there are multiple answers, you can print any. -----Examples----- Input 5 4 2 -2 3 1 2 1 3 4 5 2 5 1 3 Output 6 2 4 1 Input 5 4 2 -2 3 1 4 3 5 3 4 2 4 2 5 Output 7 2 3 2 Input 1 0 1000000 Output 0 0 -----Note----- In the first example the obtained array $b$ will be $[0, -4, 1, 1, 2]$ so the answer is $6$. In the second example the obtained array $b$ will be $[2, -3, 1, -1, 4]$ so the answer is $7$. In the third example you cannot do anything so the answer 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. The only difference between problems C1 and C2 is that all values in input of problem C1 are distinct (this condition may be false for problem C2). You are given a sequence $a$ consisting of $n$ integers. All these integers are distinct, each value from $1$ to $n$ appears in the sequence exactly once. You are making a sequence of moves. During each move you must take either the leftmost element of the sequence or the rightmost element of the sequence, write it down and remove it from the sequence. Your task is to write down a strictly increasing sequence, and among all such sequences you should take the longest (the length of the sequence is the number of elements in it). For example, for the sequence $[2, 1, 5, 4, 3]$ the answer is $4$ (you take $2$ and the sequence becomes $[1, 5, 4, 3]$, then you take the rightmost element $3$ and the sequence becomes $[1, 5, 4]$, then you take $4$ and the sequence becomes $[1, 5]$ and then you take $5$ and the sequence becomes $[1]$, the obtained increasing sequence is $[2, 3, 4, 5]$). -----Input----- The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) — the number of elements in $a$. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le n$), where $a_i$ is the $i$-th element of $a$. All these integers are pairwise distinct. -----Output----- In the first line of the output print $k$ — the maximum number of elements in a strictly increasing sequence you can obtain. In the second line print a string $s$ of length $k$, where the $j$-th character of this string $s_j$ should be 'L' if you take the leftmost element during the $j$-th move and 'R' otherwise. If there are multiple answers, you can print any. -----Examples----- Input 5 2 1 5 4 3 Output 4 LRRR Input 7 1 3 5 6 7 4 2 Output 7 LRLRLLL Input 3 1 2 3 Output 3 LLL Input 4 1 2 4 3 Output 4 LLRL -----Note----- The first example is described in the problem statement. 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$ integers. You can remove at most one element from this array. Thus, the final length of the array is $n-1$ or $n$. Your task is to calculate the maximum possible length of the strictly increasing contiguous subarray of the remaining array. Recall that the contiguous subarray $a$ with indices from $l$ to $r$ is $a[l \dots r] = a_l, a_{l + 1}, \dots, a_r$. The subarray $a[l \dots r]$ is called strictly increasing if $a_l < a_{l+1} < \dots < a_r$. -----Input----- The first line of the input contains one integer $n$ ($2 \le n \le 2 \cdot 10^5$) — the number of elements in $a$. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the $i$-th element of $a$. -----Output----- Print one integer — the maximum possible length of the strictly increasing contiguous subarray of the array $a$ after removing at most one element. -----Examples----- Input 5 1 2 5 3 4 Output 4 Input 2 1 2 Output 2 Input 7 6 5 4 3 2 4 3 Output 2 -----Note----- In the first example, you can delete $a_3=5$. Then the resulting array will be equal to $[1, 2, 3, 4]$ and the length of its largest increasing subarray will be equal to $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. The only difference between easy and hard versions is the number of elements in the array. You are given an array $a$ consisting of $n$ integers. In one move you can choose any $a_i$ and divide it by $2$ rounding down (in other words, in one move you can set $a_i := \lfloor\frac{a_i}{2}\rfloor$). You can perform such an operation any (possibly, zero) number of times with any $a_i$. Your task is to calculate the minimum possible number of operations required to obtain at least $k$ equal numbers in the array. Don't forget that it is possible to have $a_i = 0$ after some operations, thus the answer always exists. -----Input----- The first line of the input contains two integers $n$ and $k$ ($1 \le k \le n \le 50$) — the number of elements in the array and the number of equal numbers required. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 2 \cdot 10^5$), where $a_i$ is the $i$-th element of $a$. -----Output----- Print one integer — the minimum possible number of operations required to obtain at least $k$ equal numbers in the array. -----Examples----- Input 5 3 1 2 2 4 5 Output 1 Input 5 3 1 2 3 4 5 Output 2 Input 5 3 1 2 3 3 3 Output 0 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 many red balls and blue balls. Now, he will place them in a row. Initially, there is no ball placed. Takahashi, who is very patient, will do the following operation 10^{100} times: - Place A blue balls at the end of the row of balls already placed. Then, place B red balls at the end of the row. How many blue balls will be there among the first N balls in the row of balls made this way? -----Constraints----- - 1 \leq N \leq 10^{18} - A, B \geq 0 - 0 < A + B \leq 10^{18} - All values in input are integers. -----Input----- Input is given from Standard Input in the following format: N A B -----Output----- Print the number of blue balls that will be there among the first N balls in the row of balls. -----Sample Input----- 8 3 4 -----Sample Output----- 4 Let b denote a blue ball, and r denote a red ball. The first eight balls in the row will be bbbrrrrb, among which there are four blue balls. 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 guessed some integer number $x$. You are given a list of almost all its divisors. Almost all means that there are all divisors except $1$ and $x$ in the list. Your task is to find the minimum possible integer $x$ that can be the guessed number, or say that the input data is contradictory and it is impossible to find such number. You have to answer $t$ independent queries. -----Input----- The first line of the input contains one integer $t$ ($1 \le t \le 25$) — the number of queries. Then $t$ queries follow. The first line of the query contains one integer $n$ ($1 \le n \le 300$) — the number of divisors in the list. The second line of the query contains $n$ integers $d_1, d_2, \dots, d_n$ ($2 \le d_i \le 10^6$), where $d_i$ is the $i$-th divisor of the guessed number. It is guaranteed that all values $d_i$ are distinct. -----Output----- For each query print the answer to it. If the input data in the query is contradictory and it is impossible to find such number $x$ that the given list of divisors is the list of almost all its divisors, print -1. Otherwise print the minimum possible $x$. -----Example----- Input 2 8 8 2 12 6 4 24 16 3 1 2 Output 48 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. Polycarp knows that if the sum of the digits of a number is divisible by $3$, then the number itself is divisible by $3$. He assumes that the numbers, the sum of the digits of which is divisible by $4$, are also somewhat interesting. Thus, he considers a positive integer $n$ interesting if its sum of digits is divisible by $4$. Help Polycarp find the nearest larger or equal interesting number for the given number $a$. That is, find the interesting number $n$ such that $n \ge a$ and $n$ is minimal. -----Input----- The only line in the input contains an integer $a$ ($1 \le a \le 1000$). -----Output----- Print the nearest greater or equal interesting number for the given number $a$. In other words, print the interesting number $n$ such that $n \ge a$ and $n$ is minimal. -----Examples----- Input 432 Output 435 Input 99 Output 103 Input 237 Output 237 Input 42 Output 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. Polycarp wrote on the board a string $s$ containing only lowercase Latin letters ('a'-'z'). This string is known for you and given in the input. After that, he erased some letters from the string $s$, and he rewrote the remaining letters in any order. As a result, he got some new string $t$. You have to find it with some additional information. Suppose that the string $t$ has length $m$ and the characters are numbered from left to right from $1$ to $m$. You are given a sequence of $m$ integers: $b_1, b_2, \ldots, b_m$, where $b_i$ is the sum of the distances $|i-j|$ from the index $i$ to all such indices $j$ that $t_j > t_i$ (consider that 'a'<'b'<...<'z'). In other words, to calculate $b_i$, Polycarp finds all such indices $j$ that the index $j$ contains a letter that is later in the alphabet than $t_i$ and sums all the values $|i-j|$. For example, if $t$ = "abzb", then: since $t_1$='a', all other indices contain letters which are later in the alphabet, that is: $b_1=|1-2|+|1-3|+|1-4|=1+2+3=6$; since $t_2$='b', only the index $j=3$ contains the letter, which is later in the alphabet, that is: $b_2=|2-3|=1$; since $t_3$='z', then there are no indexes $j$ such that $t_j>t_i$, thus $b_3=0$; since $t_4$='b', only the index $j=3$ contains the letter, which is later in the alphabet, that is: $b_4=|4-3|=1$. Thus, if $t$ = "abzb", then $b=[6,1,0,1]$. Given the string $s$ and the array $b$, find any possible string $t$ for which the following two requirements are fulfilled simultaneously: $t$ is obtained from $s$ by erasing some letters (possibly zero) and then writing the rest in any order; the array, constructed from the string $t$ according to the rules above, equals to the array $b$ specified in the input data. -----Input----- The first line contains an integer $q$ ($1 \le q \le 100$) — the number of test cases in the test. Then $q$ test cases follow. Each test case consists of three lines: the first line contains string $s$, which has a length from $1$ to $50$ and consists of lowercase English letters; the second line contains positive integer $m$ ($1 \le m \le |s|$), where $|s|$ is the length of the string $s$, and $m$ is the length of the array $b$; the third line contains the integers $b_1, b_2, \dots, b_m$ ($0 \le b_i \le 1225$). It is guaranteed that in each test case an answer exists. -----Output----- Output $q$ lines: the $k$-th of them should contain the answer (string $t$) to the $k$-th test case. It is guaranteed that an answer to each test case exists. If there are several answers, output any. -----Example----- Input 4 abac 3 2 1 0 abc 1 0 abba 3 1 0 1 ecoosdcefr 10 38 13 24 14 11 5 3 24 17 0 Output aac b aba codeforces -----Note----- In the first test case, such strings $t$ are suitable: "aac', "aab". In the second test case, such trings $t$ are suitable: "a", "b", "c". In the third test case, only the string $t$ equals to "aba" is suitable, but the character 'b' can be from the second or third position. 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. 1000000000000001 dogs suddenly appeared under the roof of Roger's house, all of which he decided to keep. The dogs had been numbered 1 through 1000000000000001, but he gave them new names, as follows: - the dogs numbered 1,2,\cdots,26 were respectively given the names a, b, ..., z; - the dogs numbered 27,28,29,\cdots,701,702 were respectively given the names aa, ab, ac, ..., zy, zz; - the dogs numbered 703,704,705,\cdots,18277,18278 were respectively given the names aaa, aab, aac, ..., zzy, zzz; - the dogs numbered 18279,18280,18281,\cdots,475253,475254 were respectively given the names aaaa, aaab, aaac, ..., zzzy, zzzz; - the dogs numbered 475255,475256,\cdots were respectively given the names aaaaa, aaaab, ...; - and so on. To sum it up, the dogs numbered 1, 2, \cdots were respectively given the following names: a, b, ..., z, aa, ab, ..., az, ba, bb, ..., bz, ..., za, zb, ..., zz, aaa, aab, ..., aaz, aba, abb, ..., abz, ..., zzz, aaaa, ... Now, Roger asks you: "What is the name for the dog numbered N?" -----Constraints----- - N is an integer. - 1 \leq N \leq 1000000000000001 -----Input----- Input is given from Standard Input in the following format: N -----Output----- Print the answer to Roger's question as a string consisting of lowercase English letters. -----Sample Input----- 2 -----Sample Output----- b 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 text consisting of $n$ space-separated words. There is exactly one space character between any pair of adjacent words. There are no spaces before the first word and no spaces after the last word. The length of text is the number of letters and spaces in it. $w_i$ is the $i$-th word of text. All words consist only of lowercase Latin letters. Let's denote a segment of words $w[i..j]$ as a sequence of words $w_i, w_{i + 1}, \dots, w_j$. Two segments of words $w[i_1 .. j_1]$ and $w[i_2 .. j_2]$ are considered equal if $j_1 - i_1 = j_2 - i_2$, $j_1 \ge i_1$, $j_2 \ge i_2$, and for every $t \in [0, j_1 - i_1]$ $w_{i_1 + t} = w_{i_2 + t}$. For example, for the text "to be or not to be" the segments $w[1..2]$ and $w[5..6]$ are equal, they correspond to the words "to be". An abbreviation is a replacement of some segments of words with their first uppercase letters. In order to perform an abbreviation, you have to choose at least two non-intersecting equal segments of words, and replace each chosen segment with the string consisting of first letters of the words in the segment (written in uppercase). For example, for the text "a ab a a b ab a a b c" you can replace segments of words $w[2..4]$ and $w[6..8]$ with an abbreviation "AAA" and obtain the text "a AAA b AAA b c", or you can replace segments of words $w[2..5]$ and $w[6..9]$ with an abbreviation "AAAB" and obtain the text "a AAAB AAAB c". What is the minimum length of the text after at most one abbreviation? -----Input----- The first line of the input contains one integer $n$ ($1 \le n \le 300$) — the number of words in the text. The next line contains $n$ space-separated words of the text $w_1, w_2, \dots, w_n$. Each word consists only of lowercase Latin letters. It is guaranteed that the length of text does not exceed $10^5$. -----Output----- Print one integer — the minimum length of the text after at most one abbreviation. -----Examples----- Input 6 to be or not to be Output 12 Input 10 a ab a a b ab a a b c Output 13 Input 6 aa bb aa aa bb bb Output 11 -----Note----- In the first example you can obtain the text "TB or not TB". In the second example you can obtain the text "a AAAB AAAB c". In the third example you can obtain the text "AB aa AB bb". 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 is practicing his problem solving skill. He has a list of $n$ problems with difficulties $a_1, a_2, \dots, a_n$, respectively. His plan is to practice for exactly $k$ days. Each day he has to solve at least one problem from his list. Polycarp solves the problems in the order they are given in his list, he cannot skip any problem from his list. He has to solve all $n$ problems in exactly $k$ days. Thus, each day Polycarp solves a contiguous sequence of (consecutive) problems from the start of the list. He can't skip problems or solve them multiple times. As a result, in $k$ days he will solve all the $n$ problems. The profit of the $j$-th day of Polycarp's practice is the maximum among all the difficulties of problems Polycarp solves during the $j$-th day (i.e. if he solves problems with indices from $l$ to $r$ during a day, then the profit of the day is $\max\limits_{l \le i \le r}a_i$). The total profit of his practice is the sum of the profits over all $k$ days of his practice. You want to help Polycarp to get the maximum possible total profit over all valid ways to solve problems. Your task is to distribute all $n$ problems between $k$ days satisfying the conditions above in such a way, that the total profit is maximum. For example, if $n = 8, k = 3$ and $a = [5, 4, 2, 6, 5, 1, 9, 2]$, one of the possible distributions with maximum total profit is: $[5, 4, 2], [6, 5], [1, 9, 2]$. Here the total profit equals $5 + 6 + 9 = 20$. -----Input----- The first line of the input contains two integers $n$ and $k$ ($1 \le k \le n \le 2000$) — the number of problems and the number of days, respectively. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 2000$) — difficulties of problems in Polycarp's list, in the order they are placed in the list (i.e. in the order Polycarp will solve them). -----Output----- In the first line of the output print the maximum possible total profit. In the second line print exactly $k$ positive integers $t_1, t_2, \dots, t_k$ ($t_1 + t_2 + \dots + t_k$ must equal $n$), where $t_j$ means the number of problems Polycarp will solve during the $j$-th day in order to achieve the maximum possible total profit of his practice. If there are many possible answers, you may print any of them. -----Examples----- Input 8 3 5 4 2 6 5 1 9 2 Output 20 3 2 3 Input 5 1 1 1 1 1 1 Output 1 5 Input 4 2 1 2000 2000 2 Output 4000 2 2 -----Note----- The first example is described in the problem statement. In the second example there is only one possible distribution. In the third example the best answer is to distribute problems in the following way: $[1, 2000], [2000, 2]$. The total profit of this distribution is $2000 + 2000 = 4000$. 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. Kolya got an integer array $a_1, a_2, \dots, a_n$. The array can contain both positive and negative integers, but Kolya doesn't like $0$, so the array doesn't contain any zeros. Kolya doesn't like that the sum of some subsegments of his array can be $0$. The subsegment is some consecutive segment of elements of the array. You have to help Kolya and change his array in such a way that it doesn't contain any subsegments with the sum $0$. To reach this goal, you can insert any integers between any pair of adjacent elements of the array (integers can be really any: positive, negative, $0$, any by absolute value, even such a huge that they can't be represented in most standard programming languages). Your task is to find the minimum number of integers you have to insert into Kolya's array in such a way that the resulting array doesn't contain any subsegments with the sum $0$. -----Input----- The first line of the input contains one integer $n$ ($2 \le n \le 200\,000$) — the number of elements in Kolya's array. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($-10^{9} \le a_i \le 10^{9}, a_i \neq 0$) — the description of Kolya's array. -----Output----- Print the minimum number of integers you have to insert into Kolya's array in such a way that the resulting array doesn't contain any subsegments with the sum $0$. -----Examples----- Input 4 1 -5 3 2 Output 1 Input 5 4 -2 3 -9 2 Output 0 Input 9 -1 1 -1 1 -1 1 1 -1 -1 Output 6 Input 8 16 -5 -11 -15 10 5 4 -4 Output 3 -----Note----- Consider the first example. There is only one subsegment with the sum $0$. It starts in the second element and ends in the fourth element. It's enough to insert one element so the array doesn't contain any subsegments with the sum equal to zero. For example, it is possible to insert the integer $1$ between second and third elements of the array. There are no subsegments having sum $0$ in the second example so you don't need to do anything. 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 integers $n$ and $m$. You have to construct the array $a$ of length $n$ consisting of non-negative integers (i.e. integers greater than or equal to zero) such that the sum of elements of this array is exactly $m$ and the value $\sum\limits_{i=1}^{n-1} |a_i - a_{i+1}|$ is the maximum possible. Recall that $|x|$ is the absolute value of $x$. In other words, you have to maximize the sum of absolute differences between adjacent (consecutive) elements. For example, if the array $a=[1, 3, 2, 5, 5, 0]$ then the value above for this array is $|1-3| + |3-2| + |2-5| + |5-5| + |5-0| = 2 + 1 + 3 + 0 + 5 = 11$. Note that this example doesn't show the optimal answer but it shows how the required value for some array is calculated. You have to answer $t$ independent test cases. -----Input----- The first line of the input contains one integer $t$ ($1 \le t \le 10^4$) — the number of test cases. Then $t$ test cases follow. The only line of the test case contains two integers $n$ and $m$ ($1 \le n, m \le 10^9$) — the length of the array and its sum correspondingly. -----Output----- For each test case, print the answer — the maximum possible value of $\sum\limits_{i=1}^{n-1} |a_i - a_{i+1}|$ for the array $a$ consisting of $n$ non-negative integers with the sum $m$. -----Example----- Input 5 1 100 2 2 5 5 2 1000000000 1000000000 1000000000 Output 0 2 10 1000000000 2000000000 -----Note----- In the first test case of the example, the only possible array is $[100]$ and the answer is obviously $0$. In the second test case of the example, one of the possible arrays is $[2, 0]$ and the answer is $|2-0| = 2$. In the third test case of the example, one of the possible arrays is $[0, 2, 0, 3, 0]$ and the answer is $|0-2| + |2-0| + |0-3| + |3-0| = 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. Takahashi loves the number 7 and multiples of K. Where is the first occurrence of a multiple of K in the sequence 7,77,777,\ldots? (Also see Output and Sample Input/Output below.) If the sequence contains no multiples of K, print -1 instead. -----Constraints----- - 1 \leq K \leq 10^6 - K is an integer. -----Input----- Input is given from Standard Input in the following format: K -----Output----- Print an integer representing the position of the first occurrence of a multiple of K. (For example, if the first occurrence is the fourth element of the sequence, print 4.) -----Sample Input----- 101 -----Sample Output----- 4 None of 7, 77, and 777 is a multiple of 101, but 7777 is. 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 permutation $p_1, p_2, \dots, p_n$. A permutation of length $n$ is a sequence such that each integer between $1$ and $n$ occurs exactly once in the sequence. Find the number of pairs of indices $(l, r)$ ($1 \le l \le r \le n$) such that the value of the median of $p_l, p_{l+1}, \dots, p_r$ is exactly the given number $m$. The median of a sequence is the value of the element which is in the middle of the sequence after sorting it in non-decreasing order. If the length of the sequence is even, the left of two middle elements is used. For example, if $a=[4, 2, 7, 5]$ then its median is $4$ since after sorting the sequence, it will look like $[2, 4, 5, 7]$ and the left of two middle elements is equal to $4$. The median of $[7, 1, 2, 9, 6]$ equals $6$ since after sorting, the value $6$ will be in the middle of the sequence. Write a program to find the number of pairs of indices $(l, r)$ ($1 \le l \le r \le n$) such that the value of the median of $p_l, p_{l+1}, \dots, p_r$ is exactly the given number $m$. -----Input----- The first line contains integers $n$ and $m$ ($1 \le n \le 2\cdot10^5$, $1 \le m \le n$) — the length of the given sequence and the required value of the median. The second line contains a permutation $p_1, p_2, \dots, p_n$ ($1 \le p_i \le n$). Each integer between $1$ and $n$ occurs in $p$ exactly once. -----Output----- Print the required number. -----Examples----- Input 5 4 2 4 5 3 1 Output 4 Input 5 5 1 2 3 4 5 Output 1 Input 15 8 1 15 2 14 3 13 4 8 12 5 11 6 10 7 9 Output 48 -----Note----- In the first example, the suitable pairs of indices are: $(1, 3)$, $(2, 2)$, $(2, 3)$ and $(2, 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. The only difference between easy and hard versions is the constraints. Polycarp has to write a coursework. The coursework consists of $m$ pages. Polycarp also has $n$ cups of coffee. The coffee in the $i$-th cup has $a_i$ caffeine in it. Polycarp can drink some cups of coffee (each one no more than once). He can drink cups in any order. Polycarp drinks each cup instantly and completely (i.e. he cannot split any cup into several days). Surely, courseworks are not usually being written in a single day (in a perfect world of Berland, at least). Some of them require multiple days of hard work. Let's consider some day of Polycarp's work. Consider Polycarp drinks $k$ cups of coffee during this day and caffeine dosages of cups Polycarp drink during this day are $a_{i_1}, a_{i_2}, \dots, a_{i_k}$. Then the first cup he drinks gives him energy to write $a_{i_1}$ pages of coursework, the second cup gives him energy to write $max(0, a_{i_2} - 1)$ pages, the third cup gives him energy to write $max(0, a_{i_3} - 2)$ pages, ..., the $k$-th cup gives him energy to write $max(0, a_{i_k} - k + 1)$ pages. If Polycarp doesn't drink coffee during some day, he cannot write coursework at all that day. Polycarp has to finish his coursework as soon as possible (spend the minimum number of days to do it). Your task is to find out this number of days or say that it is impossible. -----Input----- The first line of the input contains two integers $n$ and $m$ ($1 \le n \le 100$, $1 \le m \le 10^4$) — the number of cups of coffee and the number of pages in the coursework. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 100$), where $a_i$ is the caffeine dosage of coffee in the $i$-th cup. -----Output----- If it is impossible to write the coursework, print -1. Otherwise print the minimum number of days Polycarp needs to do it. -----Examples----- Input 5 8 2 3 1 1 2 Output 4 Input 7 10 1 3 4 2 1 4 2 Output 2 Input 5 15 5 5 5 5 5 Output 1 Input 5 16 5 5 5 5 5 Output 2 Input 5 26 5 5 5 5 5 Output -1 -----Note----- In the first example Polycarp can drink fourth cup during first day (and write $1$ page), first and second cups during second day (and write $2 + (3 - 1) = 4$ pages), fifth cup during the third day (and write $2$ pages) and third cup during the fourth day (and write $1$ page) so the answer is $4$. It is obvious that there is no way to write the coursework in three or less days in this test. In the second example Polycarp can drink third, fourth and second cups during first day (and write $4 + (2 - 1) + (3 - 2) = 6$ pages) and sixth cup during second day (and write $4$ pages) so the answer is $2$. It is obvious that Polycarp cannot write the whole coursework in one day in this test. In the third example Polycarp can drink all cups of coffee during first day and write $5 + (5 - 1) + (5 - 2) + (5 - 3) + (5 - 4) = 15$ pages of coursework. In the fourth example Polycarp cannot drink all cups during first day and should drink one of them during the second day. So during first day he will write $5 + (5 - 1) + (5 - 2) + (5 - 3) = 14$ pages of coursework and during second day he will write $5$ pages of coursework. This is enough to complete it. In the fifth example Polycarp cannot write the whole coursework at all, even if he will drink one cup of coffee during each day, so 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. Polycarp likes arithmetic progressions. A sequence $[a_1, a_2, \dots, a_n]$ is called an arithmetic progression if for each $i$ ($1 \le i < n$) the value $a_{i+1} - a_i$ is the same. For example, the sequences $[42]$, $[5, 5, 5]$, $[2, 11, 20, 29]$ and $[3, 2, 1, 0]$ are arithmetic progressions, but $[1, 0, 1]$, $[1, 3, 9]$ and $[2, 3, 1]$ are not. It follows from the definition that any sequence of length one or two is an arithmetic progression. Polycarp found some sequence of positive integers $[b_1, b_2, \dots, b_n]$. He agrees to change each element by at most one. In the other words, for each element there are exactly three options: an element can be decreased by $1$, an element can be increased by $1$, an element can be left unchanged. Determine a minimum possible number of elements in $b$ which can be changed (by exactly one), so that the sequence $b$ becomes an arithmetic progression, or report that it is impossible. It is possible that the resulting sequence contains element equals $0$. -----Input----- The first line contains a single integer $n$ $(1 \le n \le 100\,000)$ — the number of elements in $b$. The second line contains a sequence $b_1, b_2, \dots, b_n$ $(1 \le b_i \le 10^{9})$. -----Output----- If it is impossible to make an arithmetic progression with described operations, print -1. In the other case, print non-negative integer — the minimum number of elements to change to make the given sequence becomes an arithmetic progression. The only allowed operation is to add/to subtract one from an element (can't use operation twice to the same position). -----Examples----- Input 4 24 21 14 10 Output 3 Input 2 500 500 Output 0 Input 3 14 5 1 Output -1 Input 5 1 3 6 9 12 Output 1 -----Note----- In the first example Polycarp should increase the first number on $1$, decrease the second number on $1$, increase the third number on $1$, and the fourth number should left unchanged. So, after Polycarp changed three elements by one, his sequence became equals to $[25, 20, 15, 10]$, which is an arithmetic progression. In the second example Polycarp should not change anything, because his sequence is an arithmetic progression. In the third example it is impossible to make an arithmetic progression. In the fourth example Polycarp should change only the first element, he should decrease it on one. After that his sequence will looks like $[0, 3, 6, 9, 12]$, which is an arithmetic progression. 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 a coach at your local university. There are $n$ students under your supervision, the programming skill of the $i$-th student is $a_i$. You have to form $k$ teams for yet another new programming competition. As you know, the more students are involved in competition the more probable the victory of your university is! So you have to form no more than $k$ (and at least one) non-empty teams so that the total number of students in them is maximized. But you also know that each team should be balanced. It means that the programming skill of each pair of students in each team should differ by no more than $5$. Teams are independent from one another (it means that the difference between programming skills of two students from two different teams does not matter). It is possible that some students not be included in any team at all. Your task is to report the maximum possible total number of students in no more than $k$ (and at least one) non-empty balanced teams. If you are Python programmer, consider using PyPy instead of Python when you submit your code. -----Input----- The first line of the input contains two integers $n$ and $k$ ($1 \le k \le n \le 5000$) — the number of students and the maximum number of teams, correspondingly. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is a programming skill of the $i$-th student. -----Output----- Print one integer — the maximum possible total number of students in no more than $k$ (and at least one) non-empty balanced teams. -----Examples----- Input 5 2 1 2 15 15 15 Output 5 Input 6 1 36 4 1 25 9 16 Output 2 Input 4 4 1 10 100 1000 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. Takahashi is taking exams on N subjects. The score on each subject will be an integer between 0 and K (inclusive). He has already taken exams on N-1 subjects and scored A_i points on the i-th subject. His goal is to achieve the average score of M points or above on the N subjects. Print the minimum number of points Takahashi needs on the final subject to achieve his goal. If the goal is unachievable, print -1 instead. -----Constraints----- - 2 \leq N \leq 100 - 1 \leq K \leq 100 - 1 \leq M \leq K - 0 \leq A_i \leq K - All values in input are integers. -----Input----- Input is given from Standard Input in the following format: N K M A_1 A_2 ... A_{N-1} -----Output----- Print the minimum number of points required on the final subject, or -1. -----Sample Input----- 5 10 7 8 10 3 6 -----Sample Output----- 8 If he scores 8 points on the final subject, his average score will be (8+10+3+6+8)/5 = 7 points, which meets the goal. 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. You are given a binary matrix $a$ of size $n \times m$. A binary matrix is a matrix where each element is either $0$ or $1$. You may perform some (possibly zero) operations with this matrix. During each operation you can inverse the row of this matrix or a column of this matrix. Formally, inverting a row is changing all values in this row to the opposite ($0$ to $1$, $1$ to $0$). Inverting a column is changing all values in this column to the opposite. Your task is to sort the initial matrix by some sequence of such operations. The matrix is considered sorted if the array $[a_{1, 1}, a_{1, 2}, \dots, a_{1, m}, a_{2, 1}, a_{2, 2}, \dots, a_{2, m}, \dots, a_{n, m - 1}, a_{n, m}]$ is sorted in non-descending order. -----Input----- The first line of the input contains two integers $n$ and $m$ ($1 \le n, m \le 200$) — the number of rows and the number of columns in the matrix. The next $n$ lines contain $m$ integers each. The $j$-th element in the $i$-th line is $a_{i, j}$ ($0 \le a_{i, j} \le 1$) — the element of $a$ at position $(i, j)$. -----Output----- If it is impossible to obtain a sorted matrix, print "NO" in the first line. Otherwise print "YES" in the first line. In the second line print a string $r$ of length $n$. The $i$-th character $r_i$ of this string should be '1' if the $i$-th row of the matrix is inverted and '0' otherwise. In the third line print a string $c$ of length $m$. The $j$-th character $c_j$ of this string should be '1' if the $j$-th column of the matrix is inverted and '0' otherwise. If there are multiple answers, you can print any. -----Examples----- Input 2 2 1 1 0 1 Output YES 00 10 Input 3 4 0 0 0 1 0 0 0 0 1 1 1 1 Output YES 010 0000 Input 3 3 0 0 0 1 0 1 1 1 0 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. -----Input----- The only line of the input contains a string of digits. The length of the string is between 1 and 10, inclusive. -----Output----- Output "Yes" or "No". -----Examples----- Input 373 Output Yes Input 121 Output No Input 436 Output 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. One very experienced problem writer decided to prepare a problem for April Fools Day contest. The task was very simple - given an arithmetic expression, return the result of evaluating this expression. However, looks like there is a bug in the reference solution... -----Input----- The only line of input data contains the arithmetic expression. The expression will contain between 2 and 10 operands, separated with arithmetic signs plus and/or minus. Each operand will be an integer between 0 and 255, inclusive. -----Output----- Reproduce the output of the reference solution, including the bug. -----Examples----- Input 8-7+6-5+4-3+2-1-0 Output 4 Input 2+2 Output -46 Input 112-37 Output 375 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 king of Berland organizes a ball! $n$ pair are invited to the ball, they are numbered from $1$ to $n$. Each pair consists of one man and one woman. Each dancer (either man or woman) has a monochrome costume. The color of each costume is represented by an integer from $1$ to $k$, inclusive. Let $b_i$ be the color of the man's costume and $g_i$ be the color of the woman's costume in the $i$-th pair. You have to choose a color for each dancer's costume (i.e. values $b_1, b_2, \dots, b_n$ and $g_1, g_2, \dots g_n$) in such a way that: for every $i$: $b_i$ and $g_i$ are integers between $1$ and $k$, inclusive; there are no two completely identical pairs, i.e. no two indices $i, j$ ($i \ne j$) such that $b_i = b_j$ and $g_i = g_j$ at the same time; there is no pair such that the color of the man's costume is the same as the color of the woman's costume in this pair, i.e. $b_i \ne g_i$ for every $i$; for each two consecutive (adjacent) pairs both man's costume colors and woman's costume colors differ, i.e. for every $i$ from $1$ to $n-1$ the conditions $b_i \ne b_{i + 1}$ and $g_i \ne g_{i + 1}$ hold. Let's take a look at the examples of bad and good color choosing (for $n=4$ and $k=3$, man is the first in a pair and woman is the second): Bad color choosing: $(1, 2)$, $(2, 3)$, $(3, 2)$, $(1, 2)$ — contradiction with the second rule (there are equal pairs); $(2, 3)$, $(1, 1)$, $(3, 2)$, $(1, 3)$ — contradiction with the third rule (there is a pair with costumes of the same color); $(1, 2)$, $(2, 3)$, $(1, 3)$, $(2, 1)$ — contradiction with the fourth rule (there are two consecutive pairs such that colors of costumes of men/women are the same). Good color choosing: $(1, 2)$, $(2, 1)$, $(1, 3)$, $(3, 1)$; $(1, 2)$, $(3, 1)$, $(2, 3)$, $(3, 2)$; $(3, 1)$, $(1, 2)$, $(2, 3)$, $(3, 2)$. You have to find any suitable color choosing or say that no suitable choosing exists. -----Input----- The only line of the input contains two integers $n$ and $k$ ($2 \le n, k \le 2 \cdot 10^5$) — the number of pairs and the number of colors. -----Output----- If it is impossible to find any suitable colors choosing, print "NO". Otherwise print "YES" and then the colors of the costumes of pairs in the next $n$ lines. The $i$-th line should contain two integers $b_i$ and $g_i$ — colors of costumes of man and woman in the $i$-th pair, respectively. You can print each letter in any case (upper or lower). For example, "YeS", "no" and "yES" are all acceptable. -----Examples----- Input 4 3 Output YES 3 1 1 3 3 2 2 3 Input 10 4 Output YES 2 1 1 3 4 2 3 4 4 3 3 2 2 4 4 1 1 4 3 1 Input 13 4 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. The only difference between easy and hard versions is the constraints. Vova likes pictures with kittens. The news feed in the social network he uses can be represented as an array of $n$ consecutive pictures (with kittens, of course). Vova likes all these pictures, but some are more beautiful than the others: the $i$-th picture has beauty $a_i$. Vova wants to repost exactly $x$ pictures in such a way that: each segment of the news feed of at least $k$ consecutive pictures has at least one picture reposted by Vova; the sum of beauty values of reposted pictures is maximum possible. For example, if $k=1$ then Vova has to repost all the pictures in the news feed. If $k=2$ then Vova can skip some pictures, but between every pair of consecutive pictures Vova has to repost at least one of them. Your task is to calculate the maximum possible sum of values of reposted pictures if Vova follows conditions described above, or say that there is no way to satisfy all conditions. -----Input----- The first line of the input contains three integers $n, k$ and $x$ ($1 \le k, x \le n \le 200$) — the number of pictures in the news feed, the minimum length of segment with at least one repost in it and the number of pictures Vova is ready to repost. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the beauty of the $i$-th picture. -----Output----- Print -1 if there is no way to repost some pictures to satisfy all the conditions in the problem statement. Otherwise print one integer — the maximum sum of values of reposted pictures if Vova follows conditions described in the problem statement. -----Examples----- Input 5 2 3 5 1 3 10 1 Output 18 Input 6 1 5 10 30 30 70 10 10 Output -1 Input 4 3 1 1 100 1 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 work as a system administrator in a dormitory, which has $n$ rooms one after another along a straight hallway. Rooms are numbered from $1$ to $n$. You have to connect all $n$ rooms to the Internet. You can connect each room to the Internet directly, the cost of such connection for the $i$-th room is $i$ coins. Some rooms also have a spot for a router. The cost of placing a router in the $i$-th room is also $i$ coins. You cannot place a router in a room which does not have a spot for it. When you place a router in the room $i$, you connect all rooms with the numbers from $max(1,~i - k)$ to $min(n,~i + k)$ inclusive to the Internet, where $k$ is the range of router. The value of $k$ is the same for all routers. Calculate the minimum total cost of connecting all $n$ rooms to the Internet. You can assume that the number of rooms which have a spot for a router is not greater than the number of routers you have. -----Input----- The first line of the input contains two integers $n$ and $k$ ($1 \le n, k \le 2 \cdot 10^5$) — the number of rooms and the range of each router. The second line of the input contains one string $s$ of length $n$, consisting only of zeros and ones. If the $i$-th character of the string equals to '1' then there is a spot for a router in the $i$-th room. If the $i$-th character of the string equals to '0' then you cannot place a router in the $i$-th room. -----Output----- Print one integer — the minimum total cost of connecting all $n$ rooms to the Internet. -----Examples----- Input 5 2 00100 Output 3 Input 6 1 000000 Output 21 Input 4 1 0011 Output 4 Input 12 6 000010000100 Output 15 -----Note----- In the first example it is enough to place the router in the room $3$, then all rooms will be connected to the Internet. The total cost of connection is $3$. In the second example you can place routers nowhere, so you need to connect all rooms directly. Thus, the total cost of connection of all rooms is $1 + 2 + 3 + 4 + 5 + 6 = 21$. In the third example you need to connect the room $1$ directly and place the router in the room $3$. Thus, the total cost of connection of all rooms is $1 + 3 = 4$. In the fourth example you need to place routers in rooms $5$ and $10$. Then all rooms will be connected to the Internet. The total cost of connection is $5 + 10 = 15$. 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, who is a novice in competitive programming, wants to learn M algorithms. Initially, his understanding level of each of the M algorithms is 0. Takahashi is visiting a bookstore, where he finds N books on algorithms. The i-th book (1\leq i\leq N) is sold for C_i yen (the currency of Japan). If he buys and reads it, his understanding level of the j-th algorithm will increase by A_{i,j} for each j (1\leq j\leq M). There is no other way to increase the understanding levels of the algorithms. Takahashi's objective is to make his understanding levels of all the M algorithms X or higher. Determine whether this objective is achievable. If it is achievable, find the minimum amount of money needed to achieve it. 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 programming competition site AtCode provides algorithmic problems. Each problem is allocated a score based on its difficulty. Currently, for each integer i between 1 and D (inclusive), there are p_i problems with a score of 100i points. These p_1 + … + p_D problems are all of the problems available on AtCode. A user of AtCode has a value called total score. The total score of a user is the sum of the following two elements: - Base score: the sum of the scores of all problems solved by the user. - Perfect bonuses: when a user solves all problems with a score of 100i points, he/she earns the perfect bonus of c_i points, aside from the base score (1 ≤ i ≤ D). Takahashi, who is the new user of AtCode, has not solved any problem. His objective is to have a total score of G or more points. At least how many problems does he need to solve for this objective? -----Constraints----- - 1 ≤ D ≤ 10 - 1 ≤ p_i ≤ 100 - 100 ≤ c_i ≤ 10^6 - 100 ≤ G - All values in input are integers. - c_i and G are all multiples of 100. - It is possible to have a total score of G or more points. -----Input----- Input is given from Standard Input in the following format: D G p_1 c_1 : p_D c_D -----Output----- Print the minimum number of problems that needs to be solved in order to have a total score of G or more points. Note that this objective is always achievable (see Constraints). -----Sample Input----- 2 700 3 500 5 800 -----Sample Output----- 3 In this case, there are three problems each with 100 points and five problems each with 200 points. The perfect bonus for solving all the 100-point problems is 500 points, and the perfect bonus for solving all the 200-point problems is 800 points. Takahashi's objective is to have a total score of 700 points or more. One way to achieve this objective is to solve four 200-point problems and earn a base score of 800 points. However, if we solve three 100-point problems, we can earn the perfect bonus of 500 points in addition to the base score of 300 points, for a total score of 800 points, and we can achieve the objective with fewer 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. Tanya has $n$ candies numbered from $1$ to $n$. The $i$-th candy has the weight $a_i$. She plans to eat exactly $n-1$ candies and give the remaining candy to her dad. Tanya eats candies in order of increasing their numbers, exactly one candy per day. Your task is to find the number of such candies $i$ (let's call these candies good) that if dad gets the $i$-th candy then the sum of weights of candies Tanya eats in even days will be equal to the sum of weights of candies Tanya eats in odd days. Note that at first, she will give the candy, after it she will eat the remaining candies one by one. For example, $n=4$ and weights are $[1, 4, 3, 3]$. Consider all possible cases to give a candy to dad: Tanya gives the $1$-st candy to dad ($a_1=1$), the remaining candies are $[4, 3, 3]$. She will eat $a_2=4$ in the first day, $a_3=3$ in the second day, $a_4=3$ in the third day. So in odd days she will eat $4+3=7$ and in even days she will eat $3$. Since $7 \ne 3$ this case shouldn't be counted to the answer (this candy isn't good). Tanya gives the $2$-nd candy to dad ($a_2=4$), the remaining candies are $[1, 3, 3]$. She will eat $a_1=1$ in the first day, $a_3=3$ in the second day, $a_4=3$ in the third day. So in odd days she will eat $1+3=4$ and in even days she will eat $3$. Since $4 \ne 3$ this case shouldn't be counted to the answer (this candy isn't good). Tanya gives the $3$-rd candy to dad ($a_3=3$), the remaining candies are $[1, 4, 3]$. She will eat $a_1=1$ in the first day, $a_2=4$ in the second day, $a_4=3$ in the third day. So in odd days she will eat $1+3=4$ and in even days she will eat $4$. Since $4 = 4$ this case should be counted to the answer (this candy is good). Tanya gives the $4$-th candy to dad ($a_4=3$), the remaining candies are $[1, 4, 3]$. She will eat $a_1=1$ in the first day, $a_2=4$ in the second day, $a_3=3$ in the third day. So in odd days she will eat $1+3=4$ and in even days she will eat $4$. Since $4 = 4$ this case should be counted to the answer (this candy is good). In total there $2$ cases which should counted (these candies are good), so the answer is $2$. -----Input----- The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) — the number of candies. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^4$), where $a_i$ is the weight of the $i$-th candy. -----Output----- Print one integer — the number of such candies $i$ (good candies) that if dad gets the $i$-th candy then the sum of weights of candies Tanya eats in even days will be equal to the sum of weights of candies Tanya eats in odd days. -----Examples----- Input 7 5 5 4 5 5 5 6 Output 2 Input 8 4 8 8 7 8 4 4 5 Output 2 Input 9 2 3 4 2 2 3 2 2 4 Output 3 -----Note----- In the first example indices of good candies are $[1, 2]$. In the second example indices of good candies are $[2, 3]$. In the third example indices of good candies are $[4, 5, 9]$. 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 only difference between easy and hard versions is the constraints. Vova likes pictures with kittens. The news feed in the social network he uses can be represented as an array of $n$ consecutive pictures (with kittens, of course). Vova likes all these pictures, but some are more beautiful than the others: the $i$-th picture has beauty $a_i$. Vova wants to repost exactly $x$ pictures in such a way that: each segment of the news feed of at least $k$ consecutive pictures has at least one picture reposted by Vova; the sum of beauty values of reposted pictures is maximum possible. For example, if $k=1$ then Vova has to repost all the pictures in the news feed. If $k=2$ then Vova can skip some pictures, but between every pair of consecutive pictures Vova has to repost at least one of them. Your task is to calculate the maximum possible sum of values of reposted pictures if Vova follows conditions described above, or say that there is no way to satisfy all conditions. -----Input----- The first line of the input contains three integers $n, k$ and $x$ ($1 \le k, x \le n \le 5000$) — the number of pictures in the news feed, the minimum length of segment with at least one repost in it and the number of pictures Vova is ready to repost. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the beauty of the $i$-th picture. -----Output----- Print -1 if there is no way to repost some pictures to satisfy all the conditions in the problem statement. Otherwise print one integer — the maximum sum of values of reposted pictures if Vova follows conditions described in the problem statement. -----Examples----- Input 5 2 3 5 1 3 10 1 Output 18 Input 6 1 5 10 30 30 70 10 10 Output -1 Input 4 3 1 1 100 1 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. La Confiserie d'ABC sells cakes at 4 dollars each and doughnuts at 7 dollars each. Determine if there is a way to buy some of them for exactly N dollars. You can buy two or more doughnuts and two or more cakes, and you can also choose to buy zero doughnuts or zero cakes. -----Constraints----- - N is an integer between 1 and 100, inclusive. -----Input----- Input is given from Standard Input in the following format: N -----Output----- If there is a way to buy some cakes and some doughnuts for exactly N dollars, print Yes; otherwise, print No. -----Sample Input----- 11 -----Sample Output----- Yes If you buy one cake and one doughnut, the total will be 4 + 7 = 11 dollars. 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 Ancient Kingdom of Snuke, there was a pyramid to strengthen the authority of Takahashi, the president of AtCoder Inc. The pyramid had center coordinates (C_X, C_Y) and height H. The altitude of coordinates (X, Y) is max(H - |X - C_X| - |Y - C_Y|, 0). Aoki, an explorer, conducted a survey to identify the center coordinates and height of this pyramid. As a result, he obtained the following information: - C_X, C_Y was integers between 0 and 100 (inclusive), and H was an integer not less than 1. - Additionally, he obtained N pieces of information. The i-th of them is: "the altitude of point (x_i, y_i) is h_i." This was enough to identify the center coordinates and the height of the pyramid. Find these values with the clues above. -----Constraints----- - N is an integer between 1 and 100 (inclusive). - x_i and y_i are integers between 0 and 100 (inclusive). - h_i is an integer between 0 and 10^9 (inclusive). - The N coordinates (x_1, y_1), (x_2, y_2), (x_3, y_3), ..., (x_N, y_N) are all different. - The center coordinates and the height of the pyramid can be uniquely identified. -----Input----- Input is given from Standard Input in the following format: N x_1 y_1 h_1 x_2 y_2 h_2 x_3 y_3 h_3 : x_N y_N h_N -----Output----- Print values C_X, C_Y and H representing the center coordinates and the height of the pyramid in one line, with spaces in between. -----Sample Input----- 4 2 3 5 2 1 5 1 2 5 3 2 5 -----Sample Output----- 2 2 6 In this case, the center coordinates and the height can be identified as (2, 2) and 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. Takahashi loves palindromes. Non-palindromic strings are unacceptable to him. Each time he hugs a string, he can change one of its characters to any character of his choice. Given is a string S. Find the minimum number of hugs needed to make S palindromic. -----Constraints----- - S is a string consisting of lowercase English letters. - The length of S is between 1 and 100 (inclusive). -----Input----- Input is given from Standard Input in the following format: S -----Output----- Print the minimum number of hugs needed to make S palindromic. -----Sample Input----- redcoder -----Sample Output----- 1 For example, we can change the fourth character to o and get a palindrome redooder. 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. Having learned the multiplication table, Takahashi can multiply two integers between 1 and 9 (inclusive) together. Given an integer N, determine whether N can be represented as the product of two integers between 1 and 9. If it can, print Yes; if it cannot, print No. -----Constraints----- - 1 \leq N \leq 100 - N is an integer. -----Input----- Input is given from Standard Input in the following format: N -----Output----- If N can be represented as the product of two integers between 1 and 9 (inclusive), print Yes; if it cannot, print No. -----Sample Input----- 10 -----Sample Output----- Yes 10 can be represented as, for example, 2 \times 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. Having learned the multiplication table, Takahashi can multiply two integers between 1 and 9 (inclusive) together. He cannot do any other calculation. Given are two integers A and B. If Takahashi can calculate A \times B, print the result; if he cannot, print -1 instead. -----Constraints----- - 1 \leq A \leq 20 - 1 \leq B \leq 20 - All values in input are integers. -----Input----- Input is given from Standard Input in the following format: A B -----Output----- If Takahashi can calculate A \times B, print the result; if he cannot, print -1. -----Sample Input----- 2 5 -----Sample Output----- 10 2 \times 5 = 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. There are $n$ cities in Berland. Some pairs of cities are connected by roads. All roads are bidirectional. Each road connects two different cities. There is at most one road between a pair of cities. The cities are numbered from $1$ to $n$. It is known that, from the capital (the city with the number $1$), you can reach any other city by moving along the roads. The President of Berland plans to improve the country's road network. The budget is enough to repair exactly $n-1$ roads. The President plans to choose a set of $n-1$ roads such that: it is possible to travel from the capital to any other city along the $n-1$ chosen roads, if $d_i$ is the number of roads needed to travel from the capital to city $i$, moving only along the $n-1$ chosen roads, then $d_1 + d_2 + \dots + d_n$ is minimized (i.e. as minimal as possible). In other words, the set of $n-1$ roads should preserve the connectivity of the country, and the sum of distances from city $1$ to all cities should be minimized (where you can only use the $n-1$ chosen roads). The president instructed the ministry to prepare $k$ possible options to choose $n-1$ roads so that both conditions above are met. Write a program that will find $k$ possible ways to choose roads for repair. If there are fewer than $k$ ways, then the program should output all possible valid ways to choose roads. -----Input----- The first line of the input contains integers $n$, $m$ and $k$ ($2 \le n \le 2\cdot10^5, n-1 \le m \le 2\cdot10^5, 1 \le k \le 2\cdot10^5$), where $n$ is the number of cities in the country, $m$ is the number of roads and $k$ is the number of options to choose a set of roads for repair. It is guaranteed that $m \cdot k \le 10^6$. The following $m$ lines describe the roads, one road per line. Each line contains two integers $a_i$, $b_i$ ($1 \le a_i, b_i \le n$, $a_i \ne b_i$) — the numbers of the cities that the $i$-th road connects. There is at most one road between a pair of cities. The given set of roads is such that you can reach any city from the capital. -----Output----- Print $t$ ($1 \le t \le k$) — the number of ways to choose a set of roads for repair. Recall that you need to find $k$ different options; if there are fewer than $k$ of them, then you need to find all possible different valid options. In the following $t$ lines, print the options, one per line. Print an option as a string of $m$ characters where the $j$-th character is equal to '1' if the $j$-th road is included in the option, and is equal to '0' if the road is not included. The roads should be numbered according to their order in the input. The options can be printed in any order. All the $t$ lines should be different. Since it is guaranteed that $m \cdot k \le 10^6$, the total length of all the $t$ lines will not exceed $10^6$. If there are several answers, output any of them. -----Examples----- Input 4 4 3 1 2 2 3 1 4 4 3 Output 2 1110 1011 Input 4 6 3 1 2 2 3 1 4 4 3 2 4 1 3 Output 1 101001 Input 5 6 2 1 2 1 3 2 4 2 5 3 4 3 5 Output 2 111100 110110 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. Vova's family is building the Great Vova Wall (named by Vova himself). Vova's parents, grandparents, grand-grandparents contributed to it. Now it's totally up to Vova to put the finishing touches. The current state of the wall can be respresented by a sequence $a$ of $n$ integers, with $a_i$ being the height of the $i$-th part of the wall. Vova can only use $2 \times 1$ bricks to put in the wall (he has infinite supply of them, however). Vova can put bricks horizontally on the neighboring parts of the wall of equal height. It means that if for some $i$ the current height of part $i$ is the same as for part $i + 1$, then Vova can put a brick there and thus increase both heights by 1. Obviously, Vova can't put bricks in such a way that its parts turn out to be off the borders (to the left of part $1$ of the wall or to the right of part $n$ of it). The next paragraph is specific to the version 1 of the problem. Vova can also put bricks vertically. That means increasing height of any part of the wall by 2. Vova is a perfectionist, so he considers the wall completed when: all parts of the wall has the same height; the wall has no empty spaces inside it. Can Vova complete the wall using any amount of bricks (possibly zero)? -----Input----- The first line contains a single integer $n$ ($1 \le n \le 2 \cdot 10^5$) — the number of parts in the wall. The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$) — the initial heights of the parts of the wall. -----Output----- Print "YES" if Vova can complete the wall using any amount of bricks (possibly zero). Print "NO" otherwise. -----Examples----- Input 5 2 1 1 2 5 Output YES Input 3 4 5 3 Output YES Input 2 10 10 Output YES Input 3 1 2 3 Output NO -----Note----- In the first example Vova can put a brick on parts 2 and 3 to make the wall $[2, 2, 2, 2, 5]$ and then put 3 bricks on parts 1 and 2 and 3 bricks on parts 3 and 4 to make it $[5, 5, 5, 5, 5]$. In the second example Vova can put a brick vertically on part 3 to make the wall $[4, 5, 5]$, then horizontally on parts 2 and 3 to make it $[4, 6, 6]$ and then vertically on part 1 to make it $[6, 6, 6]$. In the third example the wall is already complete. 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 superhero fights with a monster. The battle consists of rounds, each of which lasts exactly $n$ minutes. After a round ends, the next round starts immediately. This is repeated over and over again. Each round has the same scenario. It is described by a sequence of $n$ numbers: $d_1, d_2, \dots, d_n$ ($-10^6 \le d_i \le 10^6$). The $i$-th element means that monster's hp (hit points) changes by the value $d_i$ during the $i$-th minute of each round. Formally, if before the $i$-th minute of a round the monster's hp is $h$, then after the $i$-th minute it changes to $h := h + d_i$. The monster's initial hp is $H$. It means that before the battle the monster has $H$ hit points. Print the first minute after which the monster dies. The monster dies if its hp is less than or equal to $0$. Print -1 if the battle continues infinitely. -----Input----- The first line contains two integers $H$ and $n$ ($1 \le H \le 10^{12}$, $1 \le n \le 2\cdot10^5$). The second line contains the sequence of integers $d_1, d_2, \dots, d_n$ ($-10^6 \le d_i \le 10^6$), where $d_i$ is the value to change monster's hp in the $i$-th minute of a round. -----Output----- Print -1 if the superhero can't kill the monster and the battle will last infinitely. Otherwise, print the positive integer $k$ such that $k$ is the first minute after which the monster is dead. -----Examples----- Input 1000 6 -100 -200 -300 125 77 -4 Output 9 Input 1000000000000 5 -1 0 0 0 0 Output 4999999999996 Input 10 4 -3 -6 5 4 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. Two-gram is an ordered pair (i.e. string of length two) of capital Latin letters. For example, "AZ", "AA", "ZA" — three distinct two-grams. You are given a string $s$ consisting of $n$ capital Latin letters. Your task is to find any two-gram contained in the given string as a substring (i.e. two consecutive characters of the string) maximal number of times. For example, for string $s$ = "BBAABBBA" the answer is two-gram "BB", which contained in $s$ three times. In other words, find any most frequent two-gram. Note that occurrences of the two-gram can overlap with each other. -----Input----- The first line of the input contains integer number $n$ ($2 \le n \le 100$) — the length of string $s$. The second line of the input contains the string $s$ consisting of $n$ capital Latin letters. -----Output----- Print the only line containing exactly two capital Latin letters — any two-gram contained in the given string $s$ as a substring (i.e. two consecutive characters of the string) maximal number of times. -----Examples----- Input 7 ABACABA Output AB Input 5 ZZZAA Output ZZ -----Note----- In the first example "BA" is also valid answer. In the second example the only two-gram "ZZ" can be printed because it contained in the string "ZZZAA" two times. 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 string S of an odd length is said to be a strong palindrome if and only if all of the following conditions are satisfied: - S is a palindrome. - Let N be the length of S. The string formed by the 1-st through ((N-1)/2)-th characters of S is a palindrome. - The string consisting of the (N+3)/2-st through N-th characters of S is a palindrome. Determine whether S is a strong palindrome. -----Constraints----- - S consists of lowercase English letters. - The length of S is an odd number between 3 and 99 (inclusive). -----Input----- Input is given from Standard Input in the following format: S -----Output----- If S is a strong palindrome, print Yes; otherwise, print No. -----Sample Input----- akasaka -----Sample Output----- Yes - S is akasaka. - The string formed by the 1-st through the 3-rd characters is aka. - The string formed by the 5-th through the 7-th characters is aka. All of these are palindromes, so S is a strong palindrome. 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. Compute A \times B, truncate its fractional part, and print the result as an integer. -----Constraints----- - 0 \leq A \leq 10^{15} - 0 \leq B < 10 - A is an integer. - B is a number with two digits after the decimal point. -----Input----- Input is given from Standard Input in the following format: A B -----Output----- Print the answer as an integer. -----Sample Input----- 198 1.10 -----Sample Output----- 217 We have 198 \times 1.10 = 217.8. After truncating the fractional part, we have the answer: 217. 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 sisters Alice and Betty. You have $n$ candies. You want to distribute these $n$ candies between two sisters in such a way that: Alice will get $a$ ($a > 0$) candies; Betty will get $b$ ($b > 0$) candies; each sister will get some integer number of candies; Alice will get a greater amount of candies than Betty (i.e. $a > b$); all the candies will be given to one of two sisters (i.e. $a+b=n$). Your task is to calculate the number of ways to distribute exactly $n$ candies between sisters in a way described above. Candies are indistinguishable. Formally, find the number of ways to represent $n$ as the sum of $n=a+b$, where $a$ and $b$ are positive integers and $a>b$. You have to answer $t$ independent test cases. -----Input----- The first line of the input contains one integer $t$ ($1 \le t \le 10^4$) — the number of test cases. Then $t$ test cases follow. The only line of a test case contains one integer $n$ ($1 \le n \le 2 \cdot 10^9$) — the number of candies you have. -----Output----- For each test case, print the answer — the number of ways to distribute exactly $n$ candies between two sisters in a way described in the problem statement. If there is no way to satisfy all the conditions, print $0$. -----Example----- Input 6 7 1 2 3 2000000000 763243547 Output 3 0 0 1 999999999 381621773 -----Note----- For the test case of the example, the $3$ possible ways to distribute candies are: $a=6$, $b=1$; $a=5$, $b=2$; $a=4$, $b=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. There are $n$ cities and $m$ roads in Berland. Each road connects a pair of cities. The roads in Berland are one-way. What is the minimum number of new roads that need to be built to make all the cities reachable from the capital? New roads will also be one-way. -----Input----- The first line of input consists of three integers $n$, $m$ and $s$ ($1 \le n \le 5000, 0 \le m \le 5000, 1 \le s \le n$) — the number of cities, the number of roads and the index of the capital. Cities are indexed from $1$ to $n$. The following $m$ lines contain roads: road $i$ is given as a pair of cities $u_i$, $v_i$ ($1 \le u_i, v_i \le n$, $u_i \ne v_i$). For each pair of cities $(u, v)$, there can be at most one road from $u$ to $v$. Roads in opposite directions between a pair of cities are allowed (i.e. from $u$ to $v$ and from $v$ to $u$). -----Output----- Print one integer — the minimum number of extra roads needed to make all the cities reachable from city $s$. If all the cities are already reachable from $s$, print 0. -----Examples----- Input 9 9 1 1 2 1 3 2 3 1 5 5 6 6 1 1 8 9 8 7 1 Output 3 Input 5 4 5 1 2 2 3 3 4 4 1 Output 1 -----Note----- The first example is illustrated by the following: [Image] For example, you can add roads ($6, 4$), ($7, 9$), ($1, 7$) to make all the cities reachable from $s = 1$. The second example is illustrated by the following: [Image] In this example, you can add any one of the roads ($5, 1$), ($5, 2$), ($5, 3$), ($5, 4$) to make all the cities reachable from $s = 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. In Republic of Atcoder, there are N prefectures, and a total of M cities that belong to those prefectures. City i is established in year Y_i and belongs to Prefecture P_i. You can assume that there are no multiple cities that are established in the same year. It is decided to allocate a 12-digit ID number to each city. If City i is the x-th established city among the cities that belong to Prefecture i, the first six digits of the ID number of City i is P_i, and the last six digits of the ID number is x. Here, if P_i or x (or both) has less than six digits, zeros are added to the left until it has six digits. Find the ID numbers for all the cities. Note that there can be a prefecture with no cities. -----Constraints----- - 1 \leq N \leq 10^5 - 1 \leq M \leq 10^5 - 1 \leq P_i \leq N - 1 \leq Y_i \leq 10^9 - Y_i are all different. - All values in input are integers. -----Input----- Input is given from Standard Input in the following format: N M P_1 Y_1 : P_M Y_M -----Output----- Print the ID numbers for all the cities, in ascending order of indices (City 1, City 2, ...). -----Sample Input----- 2 3 1 32 2 63 1 12 -----Sample Output----- 000001000002 000002000001 000001000001 - As City 1 is the second established city among the cities that belong to Prefecture 1, its ID number is 000001000002. - As City 2 is the first established city among the cities that belong to Prefecture 2, its ID number is 000002000001. - As City 3 is the first established city among the cities that belong to Prefecture 1, its ID number is 000001000001. 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. Golorps are mysterious creatures who feed on variables. Golorp's name is a program in some programming language. Some scientists believe that this language is Befunge; golorps are tantalizingly silent. Variables consumed by golorps can take values from 0 to 9, inclusive. For each golorp its daily diet is defined by its name. Some golorps are so picky that they can't be fed at all. Besides, all golorps are very health-conscious and try to eat as little as possible. Given a choice of several valid sequences of variable values, each golorp will choose lexicographically smallest one. For the purposes of this problem you can assume that a golorp consists of jaws and a stomach. The number of variables necessary to feed a golorp is defined by the shape of its jaws. Variables can get to the stomach only via the jaws. A hungry golorp is visiting you. You know its name; feed it or figure out that it's impossible. -----Input----- The input is a single string (between 13 and 1024 characters long) — the name of the visiting golorp. All names are similar and will resemble the ones given in the samples. The name is guaranteed to be valid. -----Output----- Output lexicographically smallest sequence of variable values fit for feeding this golorp. Values should be listed in the order in which they get into the jaws. If the golorp is impossible to feed, output "false". -----Examples----- Input ?(_-_/___*__):-___>__. Output 0010 Input ?(__-_+_/_____):-__>__,_____<__. Output false Input ?(______________________/____+_______*__-_____*______-___):-__<___,___<____,____<_____,_____<______,______<_______. Output 0250341 Input ?(__+___+__-___):-___>__. Output 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. There is a rectangular grid of size $n \times m$. Each cell has a number written on it; the number on the cell ($i, j$) is $a_{i, j}$. Your task is to calculate the number of paths from the upper-left cell ($1, 1$) to the bottom-right cell ($n, m$) meeting the following constraints: You can move to the right or to the bottom only. Formally, from the cell ($i, j$) you may move to the cell ($i, j + 1$) or to the cell ($i + 1, j$). The target cell can't be outside of the grid. The xor of all the numbers on the path from the cell ($1, 1$) to the cell ($n, m$) must be equal to $k$ (xor operation is the bitwise exclusive OR, it is represented as '^' in Java or C++ and "xor" in Pascal). Find the number of such paths in the given grid. -----Input----- The first line of the input contains three integers $n$, $m$ and $k$ ($1 \le n, m \le 20$, $0 \le k \le 10^{18}$) — the height and the width of the grid, and the number $k$. The next $n$ lines contain $m$ integers each, the $j$-th element in the $i$-th line is $a_{i, j}$ ($0 \le a_{i, j} \le 10^{18}$). -----Output----- Print one integer — the number of paths from ($1, 1$) to ($n, m$) with xor sum equal to $k$. -----Examples----- Input 3 3 11 2 1 5 7 10 0 12 6 4 Output 3 Input 3 4 2 1 3 3 3 0 3 3 2 3 0 1 1 Output 5 Input 3 4 1000000000000000000 1 3 3 3 0 3 3 2 3 0 1 1 Output 0 -----Note----- All the paths from the first example: $(1, 1) \rightarrow (2, 1) \rightarrow (3, 1) \rightarrow (3, 2) \rightarrow (3, 3)$; $(1, 1) \rightarrow (2, 1) \rightarrow (2, 2) \rightarrow (2, 3) \rightarrow (3, 3)$; $(1, 1) \rightarrow (1, 2) \rightarrow (2, 2) \rightarrow (3, 2) \rightarrow (3, 3)$. All the paths from the second example: $(1, 1) \rightarrow (2, 1) \rightarrow (3, 1) \rightarrow (3, 2) \rightarrow (3, 3) \rightarrow (3, 4)$; $(1, 1) \rightarrow (2, 1) \rightarrow (2, 2) \rightarrow (3, 2) \rightarrow (3, 3) \rightarrow (3, 4)$; $(1, 1) \rightarrow (2, 1) \rightarrow (2, 2) \rightarrow (2, 3) \rightarrow (2, 4) \rightarrow (3, 4)$; $(1, 1) \rightarrow (1, 2) \rightarrow (2, 2) \rightarrow (2, 3) \rightarrow (3, 3) \rightarrow (3, 4)$; $(1, 1) \rightarrow (1, 2) \rightarrow (1, 3) \rightarrow (2, 3) \rightarrow (3, 3) \rightarrow (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. A string $s$ of length $n$ can be encrypted by the following algorithm: iterate over all divisors of $n$ in decreasing order (i.e. from $n$ to $1$), for each divisor $d$, reverse the substring $s[1 \dots d]$ (i.e. the substring which starts at position $1$ and ends at position $d$). For example, the above algorithm applied to the string $s$="codeforces" leads to the following changes: "codeforces" $\to$ "secrofedoc" $\to$ "orcesfedoc" $\to$ "rocesfedoc" $\to$ "rocesfedoc" (obviously, the last reverse operation doesn't change the string because $d=1$). You are given the encrypted string $t$. Your task is to decrypt this string, i.e., to find a string $s$ such that the above algorithm results in string $t$. It can be proven that this string $s$ always exists and is unique. -----Input----- The first line of input consists of a single integer $n$ ($1 \le n \le 100$) — the length of the string $t$. The second line of input consists of the string $t$. The length of $t$ is $n$, and it consists only of lowercase Latin letters. -----Output----- Print a string $s$ such that the above algorithm results in $t$. -----Examples----- Input 10 rocesfedoc Output codeforces Input 16 plmaetwoxesisiht Output thisisexampletwo Input 1 z Output z -----Note----- The first example is described in the problem statement. 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 + B is often used as an example of the easiest problem possible to show some contest platform. However, some scientists have observed that sometimes this problem is not so easy to get accepted. Want to try? -----Input----- The input contains two integers a and b (0 ≤ a, b ≤ 10^3), separated by a single space. -----Output----- Output the sum of the given integers. -----Examples----- Input 5 14 Output 19 Input 381 492 Output 873 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 problem you will write a simple generator of Brainfuck (https://en.wikipedia.org/wiki/Brainfuck) calculators. You are given an arithmetic expression consisting of integers from 0 to 255 and addition/subtraction signs between them. Output a Brainfuck program which, when executed, will print the result of evaluating this expression. We use a fairly standard Brainfuck interpreter for checking the programs: 30000 memory cells. memory cells store integers from 0 to 255 with unsigned 8-bit wraparound. console input (, command) is not supported, but it's not needed for this problem. -----Input----- The only line of input data contains the arithmetic expression. The expression will contain between 2 and 10 operands, separated with arithmetic signs plus and/or minus. Each operand will be an integer between 0 and 255, inclusive. The calculations result is guaranteed to be an integer between 0 and 255, inclusive (results of intermediary calculations might be outside of these boundaries). -----Output----- Output a Brainfuck program which, when executed, will print the result of evaluating this expression. The program must be at most 5000000 characters long (including the non-command characters), and its execution must be complete in at most 50000000 steps. -----Examples----- Input 2+3 Output ++> +++> <[<+>-]< ++++++++++++++++++++++++++++++++++++++++++++++++. Input 9-7 Output +++++++++> +++++++> <[<->-]< ++++++++++++++++++++++++++++++++++++++++++++++++. -----Note----- You can download the source code of the Brainfuck interpreter by the link http://assets.codeforces.com/rounds/784/bf.cpp. We use this code to interpret outputs. 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 only difference between the easy and the hard versions is the maximum value of $k$. You are given an infinite sequence of form "112123123412345$\dots$" which consist of blocks of all consecutive positive integers written one after another. The first block consists of all numbers from $1$ to $1$, the second one — from $1$ to $2$, the third one — from $1$ to $3$, $\dots$, the $i$-th block consists of all numbers from $1$ to $i$. So the first $56$ elements of the sequence are "11212312341234512345612345671234567812345678912345678910". Elements of the sequence are numbered from one. For example, the $1$-st element of the sequence is $1$, the $3$-rd element of the sequence is $2$, the $20$-th element of the sequence is $5$, the $38$-th element is $2$, the $56$-th element of the sequence is $0$. Your task is to answer $q$ independent queries. In the $i$-th query you are given one integer $k_i$. Calculate the digit at the position $k_i$ of the sequence. -----Input----- The first line of the input contains one integer $q$ ($1 \le q \le 500$) — the number of queries. The $i$-th of the following $q$ lines contains one integer $k_i$ $(1 \le k_i \le 10^{18})$ — the description of the corresponding query. -----Output----- Print $q$ lines. In the $i$-th line print one digit $x_i$ $(0 \le x_i \le 9)$ — the answer to the query $i$, i.e. $x_i$ should be equal to the element at the position $k_i$ of the sequence. -----Examples----- Input 5 1 3 20 38 56 Output 1 2 5 2 0 Input 4 2132 506 999999999999999999 1000000000000000000 Output 8 2 4 1 -----Note----- Answers on queries from the first example are described in the problem statement. 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 integer N. Among the integers between 1 and N (inclusive), how many Shichi-Go-San numbers (literally "Seven-Five-Three numbers") are there? Here, a Shichi-Go-San number is a positive integer that satisfies the following condition: - When the number is written in base ten, each of the digits 7, 5 and 3 appears at least once, and the other digits never appear. -----Constraints----- - 1 \leq N < 10^9 - N is an integer. -----Input----- Input is given from Standard Input in the following format: N -----Output----- Print the number of the Shichi-Go-San numbers between 1 and N (inclusive). -----Sample Input----- 575 -----Sample Output----- 4 There are four Shichi-Go-San numbers not greater than 575: 357, 375, 537 and 573. 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. N tiles are arranged in a row from left to right. The initial color of each tile is represented by a string S of length N. The i-th tile from the left is painted black if the i-th character of S is 0, and painted white if that character is 1. You want to repaint some of the tiles black or white, so that any two adjacent tiles have different colors. At least how many tiles need to be repainted to satisfy the condition? -----Constraints----- - 1 \leq |S| \leq 10^5 - S_i is 0 or 1. -----Input----- Input is given from Standard Input in the following format: S -----Output----- Print the minimum number of tiles that need to be repainted to satisfy the condition. -----Sample Input----- 000 -----Sample Output----- 1 The condition can be satisfied by repainting the middle tile white. 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 an immigration officer in the Kingdom of AtCoder. The document carried by an immigrant has some number of integers written on it, and you need to check whether they meet certain criteria. According to the regulation, the immigrant should be allowed entry to the kingdom if and only if the following condition is satisfied: - All even numbers written on the document are divisible by 3 or 5. If the immigrant should be allowed entry according to the regulation, output APPROVED; otherwise, print DENIED. -----Notes----- - The condition in the statement can be rephrased as "If x is an even number written on the document, x is divisible by 3 or 5". Here "if" and "or" are logical terms. -----Constraints----- - All values in input are integers. - 1 \leq N \leq 100 - 1 \leq A_i \leq 1000 -----Input----- Input is given from Standard Input in the following format: N A_1 A_2 \dots A_N -----Output----- If the immigrant should be allowed entry according to the regulation, print APPROVED; otherwise, print DENIED. -----Sample Input----- 5 6 7 9 10 31 -----Sample Output----- APPROVED The even numbers written on the document are 6 and 10. All of them are divisible by 3 or 5, so the immigrant should be allowed entry. 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 2028 and after a continuous growth, AtCoder Inc. finally built an empire with six cities (City 1, 2, 3, 4, 5, 6)! There are five means of transport in this empire: - Train: travels from City 1 to 2 in one minute. A train can occupy at most A people. - Bus: travels from City 2 to 3 in one minute. A bus can occupy at most B people. - Taxi: travels from City 3 to 4 in one minute. A taxi can occupy at most C people. - Airplane: travels from City 4 to 5 in one minute. An airplane can occupy at most D people. - Ship: travels from City 5 to 6 in one minute. A ship can occupy at most E people. For each of them, one vehicle leaves the city at each integer time (time 0, 1, 2, ...). There is a group of N people at City 1, and they all want to go to City 6. At least how long does it take for all of them to reach there? You can ignore the time needed to transfer. -----Constraints----- - 1 \leq N, A, B, C, D, E \leq 10^{15} - All values in input are integers. -----Input----- Input is given from Standard Input in the following format: N A B C D E -----Output----- Print the minimum time required for all of the people to reach City 6, in minutes. -----Sample Input----- 5 3 2 4 3 5 -----Sample Output----- 7 One possible way to travel is as follows. First, there are N = 5 people at City 1, as shown in the following image: In the first minute, three people travels from City 1 to City 2 by train. Note that a train can only occupy at most three people. In the second minute, the remaining two people travels from City 1 to City 2 by train, and two of the three people who were already at City 2 travels to City 3 by bus. Note that a bus can only occupy at most two people. In the third minute, two people travels from City 2 to City 3 by train, and another two people travels from City 3 to City 4 by taxi. From then on, if they continue traveling without stopping until they reach City 6, all of them can reach there in seven minutes. There is no way for them to reach City 6 in 6 minutes or less. 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 integer sequences A_1,A_2,\ldots,A_N of length N satisfy all of the following conditions? - 0 \leq A_i \leq 9 - There exists some i such that A_i=0 holds. - There exists some i such that A_i=9 holds. The answer can be very large, so output it modulo 10^9 + 7. -----Constraints----- - 1 \leq N \leq 10^6 - N is an integer. -----Input----- Input is given from Standard Input in the following format: N -----Output----- Print the answer modulo 10^9 + 7. -----Sample Input----- 2 -----Sample Output----- 2 Two sequences \{0,9\} and \{9,0\} satisfy all conditions. 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 minimum prime number greater than or equal to X. -----Notes----- A prime number is an integer greater than 1 that cannot be evenly divided by any positive integer except 1 and itself. For example, 2, 3, and 5 are prime numbers, while 4 and 6 are not. -----Constraints----- - 2 \le X \le 10^5 - All values in input are integers. -----Input----- Input is given from Standard Input in the following format: X -----Output----- Print the minimum prime number greater than or equal to X. -----Sample Input----- 20 -----Sample Output----- 23 The minimum prime number greater than or equal to 20 is 23. 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 a string S consisting of uppercase English letters. Additionally, an integer N will be given. Shift each character of S by N in alphabetical order (see below), and print the resulting string. We assume that A follows Z. For example, shifting A by 2 results in C (A \to B \to C), and shifting Y by 3 results in B (Y \to Z \to A \to B). -----Constraints----- - 0 \leq N \leq 26 - 1 \leq |S| \leq 10^4 - S consists of uppercase English letters. -----Input----- Input is given from Standard Input in the following format: N S -----Output----- Print the string resulting from shifting each character of S by N in alphabetical order. -----Sample Input----- 2 ABCXYZ -----Sample Output----- CDEZAB Note that A follows Z. 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. Authors guessed an array $a$ consisting of $n$ integers; each integer is not less than $2$ and not greater than $2 \cdot 10^5$. You don't know the array $a$, but you know the array $b$ which is formed from it with the following sequence of operations: Firstly, let the array $b$ be equal to the array $a$; Secondly, for each $i$ from $1$ to $n$: if $a_i$ is a prime number, then one integer $p_{a_i}$ is appended to array $b$, where $p$ is an infinite sequence of prime numbers ($2, 3, 5, \dots$); otherwise (if $a_i$ is not a prime number), the greatest divisor of $a_i$ which is not equal to $a_i$ is appended to $b$; Then the obtained array of length $2n$ is shuffled and given to you in the input. Here $p_{a_i}$ means the $a_i$-th prime number. The first prime $p_1 = 2$, the second one is $p_2 = 3$, and so on. Your task is to recover any suitable array $a$ that forms the given array $b$. It is guaranteed that the answer exists (so the array $b$ is obtained from some suitable array $a$). If there are multiple answers, you can print any. -----Input----- The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) — the number of elements in $a$. The second line of the input contains $2n$ integers $b_1, b_2, \dots, b_{2n}$ ($2 \le b_i \le 2750131$), where $b_i$ is the $i$-th element of $b$. $2750131$ is the $199999$-th prime number. -----Output----- In the only line of the output print $n$ integers $a_1, a_2, \dots, a_n$ ($2 \le a_i \le 2 \cdot 10^5$) in any order — the array $a$ from which the array $b$ can be obtained using the sequence of moves given in the problem statement. If there are multiple answers, you can print any. -----Examples----- Input 3 3 5 2 3 2 4 Output 3 4 2 Input 1 2750131 199999 Output 199999 Input 1 3 6 Output 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. You are given an array $a$ consisting of $n$ integers. Let's denote monotonic renumeration of array $a$ as an array $b$ consisting of $n$ integers such that all of the following conditions are met: $b_1 = 0$; for every pair of indices $i$ and $j$ such that $1 \le i, j \le n$, if $a_i = a_j$, then $b_i = b_j$ (note that if $a_i \ne a_j$, it is still possible that $b_i = b_j$); for every index $i \in [1, n - 1]$ either $b_i = b_{i + 1}$ or $b_i + 1 = b_{i + 1}$. For example, if $a = [1, 2, 1, 2, 3]$, then two possible monotonic renumerations of $a$ are $b = [0, 0, 0, 0, 0]$ and $b = [0, 0, 0, 0, 1]$. Your task is to calculate the number of different monotonic renumerations of $a$. The answer may be large, so print it modulo $998244353$. -----Input----- The first line contains one integer $n$ ($2 \le n \le 2 \cdot 10^5$) — the number of elements in $a$. The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$). -----Output----- Print one integer — the number of different monotonic renumerations of $a$, taken modulo $998244353$. -----Examples----- Input 5 1 2 1 2 3 Output 2 Input 2 100 1 Output 2 Input 4 1 3 3 7 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. A sequence $a_1, a_2, \dots, a_n$ is called good if, for each element $a_i$, there exists an element $a_j$ ($i \ne j$) such that $a_i+a_j$ is a power of two (that is, $2^d$ for some non-negative integer $d$). For example, the following sequences are good: $[5, 3, 11]$ (for example, for $a_1=5$ we can choose $a_2=3$. Note that their sum is a power of two. Similarly, such an element can be found for $a_2$ and $a_3$), $[1, 1, 1, 1023]$, $[7, 39, 89, 25, 89]$, $[]$. Note that, by definition, an empty sequence (with a length of $0$) is good. For example, the following sequences are not good: $[16]$ (for $a_1=16$, it is impossible to find another element $a_j$ such that their sum is a power of two), $[4, 16]$ (for $a_1=4$, it is impossible to find another element $a_j$ such that their sum is a power of two), $[1, 3, 2, 8, 8, 8]$ (for $a_3=2$, it is impossible to find another element $a_j$ such that their sum is a power of two). You are given a sequence $a_1, a_2, \dots, a_n$. What is the minimum number of elements you need to remove to make it good? You can delete an arbitrary set of elements. -----Input----- The first line contains the integer $n$ ($1 \le n \le 120000$) — the length of the given sequence. The second line contains the sequence of integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$). -----Output----- Print the minimum number of elements needed to be removed from the given sequence in order to make it good. It is possible that you need to delete all $n$ elements, make it empty, and thus get a good sequence. -----Examples----- Input 6 4 7 1 5 4 9 Output 1 Input 5 1 2 3 4 5 Output 2 Input 1 16 Output 1 Input 4 1 1 1 1023 Output 0 -----Note----- In the first example, it is enough to delete one element $a_4=5$. The remaining elements form the sequence $[4, 7, 1, 4, 9]$, which is good. 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 flower bed, there are N flowers, numbered 1,2,......,N. Initially, the heights of all flowers are 0. You are given a sequence h=\{h_1,h_2,h_3,......\} as input. You would like to change the height of Flower k to h_k for all k (1 \leq k \leq N), by repeating the following "watering" operation: - Specify integers l and r. Increase the height of Flower x by 1 for all x such that l \leq x \leq r. Find the minimum number of watering operations required to satisfy the condition. -----Constraints----- - 1 \leq N \leq 100 - 0 \leq h_i \leq 100 - All values in input are integers. -----Input----- Input is given from Standard Input in the following format: N h_1 h_2 h_3 ...... h_N -----Output----- Print the minimum number of watering operations required to satisfy the condition. -----Sample Input----- 4 1 2 2 1 -----Sample Output----- 2 The minimum number of watering operations required is 2. One way to achieve it is: - Perform the operation with (l,r)=(1,3). - Perform the operation with (l,r)=(2,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. The busses in Berland are equipped with a video surveillance system. The system records information about changes in the number of passengers in a bus after stops. If $x$ is the number of passengers in a bus just before the current bus stop and $y$ is the number of passengers in the bus just after current bus stop, the system records the number $y-x$. So the system records show how number of passengers changed. The test run was made for single bus and $n$ bus stops. Thus, the system recorded the sequence of integers $a_1, a_2, \dots, a_n$ (exactly one number for each bus stop), where $a_i$ is the record for the bus stop $i$. The bus stops are numbered from $1$ to $n$ in chronological order. Determine the number of possible ways how many people could be in the bus before the first bus stop, if the bus has a capacity equals to $w$ (that is, at any time in the bus there should be from $0$ to $w$ passengers inclusive). -----Input----- The first line contains two integers $n$ and $w$ $(1 \le n \le 1\,000, 1 \le w \le 10^{9})$ — the number of bus stops and the capacity of the bus. The second line contains a sequence $a_1, a_2, \dots, a_n$ $(-10^{6} \le a_i \le 10^{6})$, where $a_i$ equals to the number, which has been recorded by the video system after the $i$-th bus stop. -----Output----- Print the number of possible ways how many people could be in the bus before the first bus stop, if the bus has a capacity equals to $w$. If the situation is contradictory (i.e. for any initial number of passengers there will be a contradiction), print 0. -----Examples----- Input 3 5 2 1 -3 Output 3 Input 2 4 -1 1 Output 4 Input 4 10 2 4 1 2 Output 2 -----Note----- In the first example initially in the bus could be $0$, $1$ or $2$ passengers. In the second example initially in the bus could be $1$, $2$, $3$ or $4$ passengers. In the third example initially in the bus could be $0$ or $1$ passenger. 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$ distinct points on a coordinate line, the coordinate of $i$-th point equals to $x_i$. Choose a subset of the given set of points such that the distance between each pair of points in a subset is an integral power of two. It is necessary to consider each pair of points, not only adjacent. Note that any subset containing one element satisfies the condition above. Among all these subsets, choose a subset with maximum possible size. In other words, you have to choose the maximum possible number of points $x_{i_1}, x_{i_2}, \dots, x_{i_m}$ such that for each pair $x_{i_j}$, $x_{i_k}$ it is true that $|x_{i_j} - x_{i_k}| = 2^d$ where $d$ is some non-negative integer number (not necessarily the same for each pair of points). -----Input----- The first line contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) — the number of points. The second line contains $n$ pairwise distinct integers $x_1, x_2, \dots, x_n$ ($-10^9 \le x_i \le 10^9$) — the coordinates of points. -----Output----- In the first line print $m$ — the maximum possible number of points in a subset that satisfies the conditions described above. In the second line print $m$ integers — the coordinates of points in the subset you have chosen. If there are multiple answers, print any of them. -----Examples----- Input 6 3 5 4 7 10 12 Output 3 7 3 5 Input 5 -1 2 5 8 11 Output 1 8 -----Note----- In the first example the answer is $[7, 3, 5]$. Note, that $|7-3|=4=2^2$, $|7-5|=2=2^1$ and $|3-5|=2=2^1$. You can't find a subset having more points satisfying the required property. 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 a deposit of 100 yen (the currency of Japan) in AtCoder Bank. The bank pays an annual interest rate of 1 % compounded annually. (A fraction of less than one yen is discarded.) Assuming that nothing other than the interest affects Takahashi's balance, in how many years does the balance reach X yen or above for the first time? -----Constraints----- - 101 \le X \le 10^{18} - All values in input are integers. -----Input----- Input is given from Standard Input in the following format: X -----Output----- Print the number of years it takes for Takahashi's balance to reach X yen or above for the first time. -----Sample Input----- 103 -----Sample Output----- 3 - The balance after one year is 101 yen. - The balance after two years is 102 yen. - The balance after three years is 103 yen. Thus, it takes three years for the balance to reach 103 yen or above. 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 \displaystyle{\sum_{a=1}^{K}\sum_{b=1}^{K}\sum_{c=1}^{K} \gcd(a,b,c)}. Here \gcd(a,b,c) denotes the greatest common divisor of a, b, and c. -----Constraints----- - 1 \leq K \leq 200 - K is an integer. -----Input----- Input is given from Standard Input in the following format: K -----Output----- Print the value of \displaystyle{\sum_{a=1}^{K}\sum_{b=1}^{K}\sum_{c=1}^{K} \gcd(a,b,c)}. -----Sample Input----- 2 -----Sample Output----- 9 \gcd(1,1,1)+\gcd(1,1,2)+\gcd(1,2,1)+\gcd(1,2,2)+\gcd(2,1,1)+\gcd(2,1,2)+\gcd(2,2,1)+\gcd(2,2,2)=1+1+1+1+1+1+1+2=9 Thus, the answer is 9. 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. Tak performed the following action N times: rolling two dice. The result of the i-th roll is D_{i,1} and D_{i,2}. Check if doublets occurred at least three times in a row. Specifically, check if there exists at lease one i such that D_{i,1}=D_{i,2}, D_{i+1,1}=D_{i+1,2} and D_{i+2,1}=D_{i+2,2} hold. -----Constraints----- - 3 \leq N \leq 100 - 1\leq D_{i,j} \leq 6 - All values in input are integers. -----Input----- Input is given from Standard Input in the following format: N D_{1,1} D_{1,2} \vdots D_{N,1} D_{N,2} -----Output----- Print Yes if doublets occurred at least three times in a row. Print No otherwise. -----Sample Input----- 5 1 2 6 6 4 4 3 3 3 2 -----Sample Output----- Yes From the second roll to the fourth roll, three doublets occurred in a row. 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 an integer r. How many times is the area of a circle of radius r larger than the area of a circle of radius 1? It can be proved that the answer is always an integer under the constraints given. -----Constraints----- - 1 \leq r \leq 100 - All values in input are integers. -----Input----- Input is given from Standard Input in the following format: r -----Output----- Print the area of a circle of radius r, divided by the area of a circle of radius 1, as an integer. -----Sample Input----- 2 -----Sample Output----- 4 The area of a circle of radius 2 is 4 times larger than the area of a circle of radius 1. Note that output must be an integer - for example, 4.0 will not be accepted. 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. Determine if an N-sided polygon (not necessarily convex) with sides of length L_1, L_2, ..., L_N can be drawn in a two-dimensional plane. You can use the following theorem: Theorem: an N-sided polygon satisfying the condition can be drawn if and only if the longest side is strictly shorter than the sum of the lengths of the other N-1 sides. -----Constraints----- - All values in input are integers. - 3 \leq N \leq 10 - 1 \leq L_i \leq 100 -----Input----- Input is given from Standard Input in the following format: N L_1 L_2 ... L_N -----Output----- If an N-sided polygon satisfying the condition can be drawn, print Yes; otherwise, print No. -----Sample Input----- 4 3 8 5 1 -----Sample Output----- Yes Since 8 < 9 = 3 + 5 + 1, it follows from the theorem that such a polygon can be drawn on a plane. 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. If there is an integer not less than 0 satisfying the following conditions, print the smallest such integer; otherwise, print -1. - The integer has exactly N digits in base ten. (We assume 0 to be a 1-digit integer. For other integers, leading zeros are not allowed.) - The s_i-th digit from the left is c_i. \left(i = 1, 2, \cdots, M\right) -----Constraints----- - All values in input are integers. - 1 \leq N \leq 3 - 0 \leq M \leq 5 - 1 \leq s_i \leq N - 0 \leq c_i \leq 9 -----Input----- Input is given from Standard Input in the following format: N M s_1 c_1 \vdots s_M c_M -----Output----- Print the answer. -----Sample Input----- 3 3 1 7 3 2 1 7 -----Sample Output----- 702 702 satisfies the conditions - its 1-st and 3-rd digits are 7 and 2, respectively - while no non-negative integer less than 702 satisfies them. 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 integers N and K. Find the number of triples (a,b,c) of positive integers not greater than N such that a+b,b+c and c+a are all multiples of K. The order of a,b,c does matter, and some of them can be the same. -----Constraints----- - 1 \leq N,K \leq 2\times 10^5 - N and K are integers. -----Input----- Input is given from Standard Input in the following format: N K -----Output----- Print the number of triples (a,b,c) of positive integers not greater than N such that a+b,b+c and c+a are all multiples of K. -----Sample Input----- 3 2 -----Sample Output----- 9 (1,1,1),(1,1,3),(1,3,1),(1,3,3),(2,2,2),(3,1,1),(3,1,3),(3,3,1) and (3,3,3) satisfy the condition. 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 an integer N, find the base -2 representation of N. Here, S is the base -2 representation of N when the following are all satisfied: - S is a string consisting of 0 and 1. - Unless S = 0, the initial character of S is 1. - Let S = S_k S_{k-1} ... S_0, then S_0 \times (-2)^0 + S_1 \times (-2)^1 + ... + S_k \times (-2)^k = N. It can be proved that, for any integer M, the base -2 representation of M is uniquely determined. -----Constraints----- - Every value in input is integer. - -10^9 \leq N \leq 10^9 -----Input----- Input is given from Standard Input in the following format: N -----Output----- Print the base -2 representation of N. -----Sample Input----- -9 -----Sample Output----- 1011 As (-2)^0 + (-2)^1 + (-2)^3 = 1 + (-2) + (-8) = -9, 1011 is the base -2 representation of -9. 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. Hearing that energy drinks increase rating in those sites, Takahashi decides to buy up M cans of energy drinks. There are N stores that sell energy drinks. In the i-th store, he can buy at most B_i cans of energy drinks for A_i yen (the currency of Japan) each. What is the minimum amount of money with which he can buy M cans of energy drinks? It is guaranteed that, in the given inputs, a sufficient amount of money can always buy M cans of energy drinks. -----Constraints----- - All values in input are integers. - 1 \leq N, M \leq 10^5 - 1 \leq A_i \leq 10^9 - 1 \leq B_i \leq 10^5 - B_1 + ... + B_N \geq M -----Input----- Input is given from Standard Input in the following format: N M A_1 B_1 A_2 B_2 \vdots A_N B_N -----Output----- Print the minimum amount of money with which Takahashi can buy M cans of energy drinks. -----Sample Input----- 2 5 4 9 2 4 -----Sample Output----- 12 With 12 yen, we can buy one drink at the first store and four drinks at the second store, for the total of five drinks. However, we cannot buy 5 drinks with 11 yen or less. 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 squares arranged in a row from left to right. The height of the i-th square from the left is H_i. You will land on a square of your choice, then repeat moving to the adjacent square on the right as long as the height of the next square is not greater than that of the current square. Find the maximum number of times you can move. -----Constraints----- - All values in input are integers. - 1 \leq N \leq 10^5 - 1 \leq H_i \leq 10^9 -----Input----- Input is given from Standard Input in the following format: N H_1 H_2 ... H_N -----Output----- Print the maximum number of times you can move. -----Sample Input----- 5 10 4 8 7 3 -----Sample Output----- 2 By landing on the third square from the left, you can move to the right 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.