source
stringclasses
4 values
task_type
stringclasses
1 value
in_source_id
stringlengths
0
138
problem
stringlengths
219
13.2k
gold_standard_solution
stringlengths
0
413k
problem_id
stringlengths
5
10
metadata
dict
verification_info
dict
apps
verifiable_code
756
Solve the following coding problem using the programming language python: Bear Limak likes watching sports on TV. He is going to watch a game today. The game lasts 90 minutes and there are no breaks. Each minute can be either interesting or boring. If 15 consecutive minutes are boring then Limak immediately turns TV off. You know that there will be n interesting minutes t_1, t_2, ..., t_{n}. Your task is to calculate for how many minutes Limak will watch the game. -----Input----- The first line of the input contains one integer n (1 ≤ n ≤ 90) — the number of interesting minutes. The second line contains n integers t_1, t_2, ..., t_{n} (1 ≤ t_1 < t_2 < ... t_{n} ≤ 90), given in the increasing order. -----Output----- Print the number of minutes Limak will watch the game. -----Examples----- Input 3 7 20 88 Output 35 Input 9 16 20 30 40 50 60 70 80 90 Output 15 Input 9 15 20 30 40 50 60 70 80 90 Output 90 -----Note----- In the first sample, minutes 21, 22, ..., 35 are all boring and thus Limak will turn TV off immediately after the 35-th minute. So, he would watch the game for 35 minutes. In the second sample, the first 15 minutes are boring. In the third sample, there are no consecutive 15 boring minutes. So, Limak will watch the whole game. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python n = int(input()) a = list(map(int, input().split())) cutoff = 15 for x in a: if x > cutoff: break cutoff = x + 15 print(min(90, cutoff)) ```
vfc_12778
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/673/A", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n7 20 88\n", "output": "35\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "9\n16 20 30 40 50 60 70 80 90\n", "output": "15\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "9\n15 20 30 40 50 60 70 80 90\n", "output": "90\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
757
Solve the following coding problem using the programming language python: Vasya has got many devices that work on electricity. He's got n supply-line filters to plug the devices, the i-th supply-line filter has a_{i} sockets. Overall Vasya has got m devices and k electrical sockets in his flat, he can plug the devices or supply-line filters directly. Of course, he can plug the supply-line filter to any other supply-line filter. The device (or the supply-line filter) is considered plugged to electricity if it is either plugged to one of k electrical sockets, or if it is plugged to some supply-line filter that is in turn plugged to electricity. What minimum number of supply-line filters from the given set will Vasya need to plug all the devices he has to electricity? Note that all devices and supply-line filters take one socket for plugging and that he can use one socket to plug either one device or one supply-line filter. -----Input----- The first line contains three integers n, m, k (1 ≤ n, m, k ≤ 50) — the number of supply-line filters, the number of devices and the number of sockets that he can plug to directly, correspondingly. The second line contains n space-separated integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 50) — number a_{i} stands for the number of sockets on the i-th supply-line filter. -----Output----- Print a single number — the minimum number of supply-line filters that is needed to plug all the devices to electricity. If it is impossible to plug all the devices even using all the supply-line filters, print -1. -----Examples----- Input 3 5 3 3 1 2 Output 1 Input 4 7 2 3 3 2 4 Output 2 Input 5 5 1 1 3 1 2 1 Output -1 -----Note----- In the first test case he can plug the first supply-line filter directly to electricity. After he plug it, he get 5 (3 on the supply-line filter and 2 remaining sockets for direct plugging) available sockets to plug. Thus, one filter is enough to plug 5 devices. One of the optimal ways in the second test sample is to plug the second supply-line filter directly and plug the fourth supply-line filter to one of the sockets in the second supply-line filter. Thus, he gets exactly 7 sockets, available to plug: one to plug to the electricity directly, 2 on the second supply-line filter, 4 on the fourth supply-line filter. There's no way he can plug 7 devices if he use one supply-line filter. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python 3 n, m, k = tuple(map(int, input().split())) a = reversed(sorted(map(int, input().split()))) ans = 0 for _ in a: if m <= k: break ans += 1 m -= k - 1 k = _ print(ans if m <= k else -1) ```
vfc_12782
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/257/A", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 5 3\n3 1 2\n", "output": "1\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
758
Solve the following coding problem using the programming language python: User ainta has a stack of n red and blue balls. He can apply a certain operation which changes the colors of the balls inside the stack. While the top ball inside the stack is red, pop the ball from the top of the stack. Then replace the blue ball on the top with a red ball. And finally push some blue balls to the stack until the stack has total of n balls inside.   If there are no blue balls inside the stack, ainta can't apply this operation. Given the initial state of the stack, ainta wants to know the maximum number of operations he can repeatedly apply. -----Input----- The first line contains an integer n (1 ≤ n ≤ 50) — the number of balls inside the stack. The second line contains a string s (|s| = n) describing the initial state of the stack. The i-th character of the string s denotes the color of the i-th ball (we'll number the balls from top to bottom of the stack). If the character is "R", the color is red. If the character is "B", the color is blue. -----Output----- Print the maximum number of operations ainta can repeatedly apply. Please, do not write the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier. -----Examples----- Input 3 RBR Output 2 Input 4 RBBR Output 6 Input 5 RBBRR Output 6 -----Note----- The first example is depicted below. The explanation how user ainta applies the first operation. He pops out one red ball, changes the color of the ball in the middle from blue to red, and pushes one blue ball. [Image] The explanation how user ainta applies the second operation. He will not pop out red balls, he simply changes the color of the ball on the top from blue to red. [Image] From now on, ainta can't apply any operation because there are no blue balls inside the stack. ainta applied two operations, so the answer is 2. The second example is depicted below. The blue arrow denotes a single operation. [Image] The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python n, b = input(), input().replace('R', '0').replace('B', '1') print(int(b[:: -1], 2)) ```
vfc_12786
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/399/B", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\nRBR\n", "output": "2\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
759
Solve the following coding problem using the programming language python: After waking up at hh:mm, Andrew realised that he had forgotten to feed his only cat for yet another time (guess why there's only one cat). The cat's current hunger level is H points, moreover each minute without food increases his hunger by D points. At any time Andrew can visit the store where tasty buns are sold (you can assume that is doesn't take time to get to the store and back). One such bun costs C roubles and decreases hunger by N points. Since the demand for bakery drops heavily in the evening, there is a special 20% discount for buns starting from 20:00 (note that the cost might become rational). Of course, buns cannot be sold by parts. Determine the minimum amount of money Andrew has to spend in order to feed his cat. The cat is considered fed if its hunger level is less than or equal to zero. -----Input----- The first line contains two integers hh and mm (00 ≤ hh ≤ 23, 00 ≤ mm ≤ 59) — the time of Andrew's awakening. The second line contains four integers H, D, C and N (1 ≤ H ≤ 10^5, 1 ≤ D, C, N ≤ 10^2). -----Output----- Output the minimum amount of money to within three decimal digits. You answer is considered correct, if its absolute or relative error does not exceed 10^{ - 4}. Formally, let your answer be a, and the jury's answer be b. Your answer is considered correct if $\frac{|a - b|}{\operatorname{max}(1,|b|)} \leq 10^{-4}$. -----Examples----- Input 19 00 255 1 100 1 Output 25200.0000 Input 17 41 1000 6 15 11 Output 1365.0000 -----Note----- In the first sample Andrew can visit the store at exactly 20:00. The cat's hunger will be equal to 315, hence it will be necessary to purchase 315 buns. The discount makes the final answer 25200 roubles. In the second sample it's optimal to visit the store right after he wakes up. Then he'll have to buy 91 bins per 15 roubles each and spend a total of 1365 roubles. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python from math import ceil hh, mm = [int(x) for x in input().split()] h, d, c, n = [int(x) for x in input().split()] cost = 0.8 * c if hh >= 20 else c res = int(ceil(h / n)) * cost if hh < 20: diff = (20 - hh) * 60 - mm diff *= d h += diff res = min(res, int(ceil(h / n)) * 0.8 * c) print(res) ```
vfc_12790
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/955/A", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "19 00\n255 1 100 1\n", "output": "25200.0000\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
760
Solve the following coding problem using the programming language python: Kolya got string s for his birthday, the string consists of small English letters. He immediately added k more characters to the right of the string. Then Borya came and said that the new string contained a tandem repeat of length l as a substring. How large could l be? See notes for definition of a tandem repeat. -----Input----- The first line contains s (1 ≤ |s| ≤ 200). This string contains only small English letters. The second line contains number k (1 ≤ k ≤ 200) — the number of the added characters. -----Output----- Print a single number — the maximum length of the tandem repeat that could have occurred in the new string. -----Examples----- Input aaba 2 Output 6 Input aaabbbb 2 Output 6 Input abracadabra 10 Output 20 -----Note----- A tandem repeat of length 2n is string s, where for any position i (1 ≤ i ≤ n) the following condition fulfills: s_{i} = s_{i} + n. In the first sample Kolya could obtain a string aabaab, in the second — aaabbbbbb, in the third — abracadabrabracadabra. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python 3 import sys s = sys.stdin.readline().strip() k = int(sys.stdin.readline()) s += '*' * k def is_tandem(s): # print(s) n = len(s) // 2 a, b = s[:n], s[n:] for i in range(n): if a[i] == '*' or b[i] == '*': continue if a[i] != b[i]: return False return True l = 0 for i in range(len(s)): # Beginning of tandem for n in range(2, len(s) - i + 1, 2): # Length of tandem if is_tandem(s[i:i+n]): l = max(l, n) print(l) ```
vfc_12794
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/443/B", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "aaba\n2\n", "output": "6\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "aaabbbb\n2\n", "output": "6\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "abracadabra\n10\n", "output": "20\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "zwvrx\n3\n", "output": "6\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
761
Solve the following coding problem using the programming language python: There are $n$ slimes in a row. Each slime has an integer value (possibly negative or zero) associated with it. Any slime can eat its adjacent slime (the closest slime to its left or to its right, assuming that this slime exists). When a slime with a value $x$ eats a slime with a value $y$, the eaten slime disappears, and the value of the remaining slime changes to $x - y$. The slimes will eat each other until there is only one slime left. Find the maximum possible value of the last slime. -----Input----- The first line of the input contains an integer $n$ ($1 \le n \le 500\,000$) denoting the number of slimes. The next line contains $n$ integers $a_i$ ($-10^9 \le a_i \le 10^9$), where $a_i$ is the value of $i$-th slime. -----Output----- Print an only integer — the maximum possible value of the last slime. -----Examples----- Input 4 2 1 2 1 Output 4 Input 5 0 -1 -1 -1 -1 Output 4 -----Note----- In the first example, a possible way of getting the last slime with value $4$ is: Second slime eats the third slime, the row now contains slimes $2, -1, 1$ Second slime eats the third slime, the row now contains slimes $2, -2$ First slime eats the second slime, the row now contains $4$ In the second example, the first slime can keep eating slimes to its right to end up with a value of $4$. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python import sys import string def ria(): return [int(i) for i in input().split()] n = ria()[0] ar = ria() if n == 1: print(ar[0]) return onlyNegs = True onlyPos = True if max(ar) >= 0: onlyNegs = False if min(ar) <= 0: onlyPos = False if onlyNegs: print(abs(sum(ar)) + max(ar) * 2) return if onlyPos: print(abs(sum(ar)) - min(ar) * 2) return print(sum([abs(i) for i in ar])) ```
vfc_12798
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1038/D", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n2 1 2 1\n", "output": "4", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n0 -1 -1 -1 -1\n", "output": "4", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n10 8\n", "output": "2", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n-14 -2 0 -19 -12\n", "output": "47", "type": "stdin_stdout" }, { "fn_name": null, "input": "6\n-15 2 -19 20 0 9\n", "output": "65", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n17 4 -1\n", "output": "22", "type": "stdin_stdout" } ] }
apps
verifiable_code
762
Solve the following coding problem using the programming language python: There are a lot of things which could be cut — trees, paper, "the rope". In this problem you are going to cut a sequence of integers. There is a sequence of integers, which contains the equal number of even and odd numbers. Given a limited budget, you need to make maximum possible number of cuts such that each resulting segment will have the same number of odd and even integers. Cuts separate a sequence to continuous (contiguous) segments. You may think about each cut as a break between two adjacent elements in a sequence. So after cutting each element belongs to exactly one segment. Say, $[4, 1, 2, 3, 4, 5, 4, 4, 5, 5]$ $\to$ two cuts $\to$ $[4, 1 | 2, 3, 4, 5 | 4, 4, 5, 5]$. On each segment the number of even elements should be equal to the number of odd elements. The cost of the cut between $x$ and $y$ numbers is $|x - y|$ bitcoins. Find the maximum possible number of cuts that can be made while spending no more than $B$ bitcoins. -----Input----- First line of the input contains an integer $n$ ($2 \le n \le 100$) and an integer $B$ ($1 \le B \le 100$) — the number of elements in the sequence and the number of bitcoins you have. Second line contains $n$ integers: $a_1$, $a_2$, ..., $a_n$ ($1 \le a_i \le 100$) — elements of the sequence, which contains the equal number of even and odd numbers -----Output----- Print the maximum possible number of cuts which can be made while spending no more than $B$ bitcoins. -----Examples----- Input 6 4 1 2 5 10 15 20 Output 1 Input 4 10 1 3 2 4 Output 0 Input 6 100 1 2 3 4 5 6 Output 2 -----Note----- In the first sample the optimal answer is to split sequence between $2$ and $5$. Price of this cut is equal to $3$ bitcoins. In the second sample it is not possible to make even one cut even with unlimited number of bitcoins. In the third sample the sequence should be cut between $2$ and $3$, and between $4$ and $5$. The total price of the cuts is $1 + 1 = 2$ bitcoins. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python n, B = list(map(int, input().split())) A = [int(x) for x in input().split()] odd, even = 0, 0 cuts = [] for i in range(n - 1): if A[i] % 2 == 0: even += 1 else: odd += 1 if odd == even: cuts += [(abs(A[i] - A[i + 1]), i)] cuts.sort() result = 0 for cost, _ in cuts: if cost <= B: B -= cost result += 1 print(result) ```
vfc_12802
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/998/B", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "6 4\n1 2 5 10 15 20\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 10\n1 3 2 4\n", "output": "0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "6 100\n1 2 3 4 5 6\n", "output": "2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 100\n13 78\n", "output": "0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "10 1\n56 56 98 2 11 64 97 41 95 53\n", "output": "0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "10 100\n94 65 24 47 29 98 20 65 6 17\n", "output": "2\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
763
Solve the following coding problem using the programming language python: The Fair Nut lives in $n$ story house. $a_i$ people live on the $i$-th floor of the house. Every person uses elevator twice a day: to get from the floor where he/she lives to the ground (first) floor and to get from the first floor to the floor where he/she lives, when he/she comes back home in the evening. It was decided that elevator, when it is not used, will stay on the $x$-th floor, but $x$ hasn't been chosen yet. When a person needs to get from floor $a$ to floor $b$, elevator follows the simple algorithm: Moves from the $x$-th floor (initially it stays on the $x$-th floor) to the $a$-th and takes the passenger. Moves from the $a$-th floor to the $b$-th floor and lets out the passenger (if $a$ equals $b$, elevator just opens and closes the doors, but still comes to the floor from the $x$-th floor). Moves from the $b$-th floor back to the $x$-th. The elevator never transposes more than one person and always goes back to the floor $x$ before transposing a next passenger. The elevator spends one unit of electricity to move between neighboring floors. So moving from the $a$-th floor to the $b$-th floor requires $|a - b|$ units of electricity. Your task is to help Nut to find the minimum number of electricity units, that it would be enough for one day, by choosing an optimal the $x$-th floor. Don't forget than elevator initially stays on the $x$-th floor. -----Input----- The first line contains one integer $n$ ($1 \leq n \leq 100$) — the number of floors. The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($0 \leq a_i \leq 100$) — the number of people on each floor. -----Output----- In a single line, print the answer to the problem — the minimum number of electricity units. -----Examples----- Input 3 0 2 1 Output 16 Input 2 1 1 Output 4 -----Note----- In the first example, the answer can be achieved by choosing the second floor as the $x$-th floor. Each person from the second floor (there are two of them) would spend $4$ units of electricity per day ($2$ to get down and $2$ to get up), and one person from the third would spend $8$ units of electricity per day ($4$ to get down and $4$ to get up). $4 \cdot 2 + 8 \cdot 1 = 16$. In the second example, the answer can be achieved by choosing the first floor as the $x$-th floor. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python n = int(input()) line = input().split() ans = 0 for i in range(n): ans += int(line[i])*i print(4*ans) ```
vfc_12806
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1084/A", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n0 2 1\n", "output": "16", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n1 1\n", "output": "4", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n1\n", "output": "0", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n1 3 3\n", "output": "36", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n3 2 3\n", "output": "32", "type": "stdin_stdout" } ] }
apps
verifiable_code
764
Solve the following coding problem using the programming language python: After learning about polynomial hashing, Heidi decided to learn about shift-xor hashing. In particular, she came across this interesting problem. Given a bitstring $y \in \{0,1\}^n$ find out the number of different $k$ ($0 \leq k < n$) such that there exists $x \in \{0,1\}^n$ for which $y = x \oplus \mbox{shift}^k(x).$ In the above, $\oplus$ is the xor operation and $\mbox{shift}^k$ is the operation of shifting a bitstring cyclically to the right $k$ times. For example, $001 \oplus 111 = 110$ and $\mbox{shift}^3(00010010111000) = 00000010010111$. -----Input----- The first line contains an integer $n$ ($1 \leq n \leq 2 \cdot 10^5$), the length of the bitstring $y$. The second line contains the bitstring $y$. -----Output----- Output a single integer: the number of suitable values of $k$. -----Example----- Input 4 1010 Output 3 -----Note----- In the first example: $1100\oplus \mbox{shift}^1(1100) = 1010$ $1000\oplus \mbox{shift}^2(1000) = 1010$ $0110\oplus \mbox{shift}^3(0110) = 1010$ There is no $x$ such that $x \oplus x = 1010$, hence the answer is $3$. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python from collections import deque import math num = int(input()) x = tuple(map(int, list(input()))) #if x == "0"*num: print(num); return integer = 0 dic = dict() for i in range(1,num+1): a = math.gcd(i,num) if a in dic: integer += dic[a] else: lijst = [0]*a for j in range(num): b = j%a lijst[b] += x[j] for k in range(a): if lijst[k]%2 != 0: dic[a] = 0 break else: integer += 1 dic[a] = 1 print(integer) ```
vfc_12810
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1184/A2", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n1010\n", "output": "3\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
765
Solve the following coding problem using the programming language python: Little Lesha loves listening to music via his smartphone. But the smartphone doesn't have much memory, so Lesha listens to his favorite songs in a well-known social network InTalk. Unfortunately, internet is not that fast in the city of Ekaterinozavodsk and the song takes a lot of time to download. But Lesha is quite impatient. The song's duration is T seconds. Lesha downloads the first S seconds of the song and plays it. When the playback reaches the point that has not yet been downloaded, Lesha immediately plays the song from the start (the loaded part of the song stays in his phone, and the download is continued from the same place), and it happens until the song is downloaded completely and Lesha listens to it to the end. For q seconds of real time the Internet allows you to download q - 1 seconds of the track. Tell Lesha, for how many times he will start the song, including the very first start. -----Input----- The single line contains three integers T, S, q (2 ≤ q ≤ 10^4, 1 ≤ S < T ≤ 10^5). -----Output----- Print a single integer — the number of times the song will be restarted. -----Examples----- Input 5 2 2 Output 2 Input 5 4 7 Output 1 Input 6 2 3 Output 1 -----Note----- In the first test, the song is played twice faster than it is downloaded, which means that during four first seconds Lesha reaches the moment that has not been downloaded, and starts the song again. After another two seconds, the song is downloaded completely, and thus, Lesha starts the song twice. In the second test, the song is almost downloaded, and Lesha will start it only once. In the third sample test the download finishes and Lesha finishes listening at the same moment. Note that song isn't restarted in this case. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python t, s, q = [int(i) for i in input().split()] a = 1 l = 0 while t > s: l += q l = min(l, t) s += q - 1 s = min(s, t) if l >= s and s != t: a += 1 l = 0 print(a) ```
vfc_12814
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/569/A", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5 2 2\n", "output": "2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 4 7\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "6 2 3\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 1 2\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 1 3\n", "output": "1\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
766
Solve the following coding problem using the programming language python: Let's call a string adorable if its letters can be realigned in such a way that they form two consequent groups of equal symbols (note that different groups must contain different symbols). For example, ababa is adorable (you can transform it to aaabb, where the first three letters form a group of a-s and others — a group of b-s), but cccc is not since in each possible consequent partition letters in these two groups coincide. You're given a string s. Check whether it can be split into two non-empty subsequences such that the strings formed by these subsequences are adorable. Here a subsequence is an arbitrary set of indexes of the string. -----Input----- The only line contains s (1 ≤ |s| ≤ 10^5) consisting of lowercase latin letters. -----Output----- Print «Yes» if the string can be split according to the criteria above or «No» otherwise. Each letter can be printed in arbitrary case. -----Examples----- Input ababa Output Yes Input zzcxx Output Yes Input yeee Output No -----Note----- In sample case two zzcxx can be split into subsequences zc and zxx each of which is adorable. There's no suitable partition in sample case three. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python s = input() ss = set(s) if len(s) >= 4: if len(ss) in (3, 4): print('Yes') elif len(ss) == 2: for c in ss: if s.count(c) == 1: print('No') break else: print('Yes') else: print('No') else: print('No') ```
vfc_12818
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/955/B", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "ababa\n", "output": "Yes\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "zzcxx\n", "output": "Yes\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "yeee\n", "output": "No\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "a\n", "output": "No\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "bbab\n", "output": "No\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
767
Solve the following coding problem using the programming language python: You are given a set of points $x_1$, $x_2$, ..., $x_n$ on the number line. Two points $i$ and $j$ can be matched with each other if the following conditions hold: neither $i$ nor $j$ is matched with any other point; $|x_i - x_j| \ge z$. What is the maximum number of pairs of points you can match with each other? -----Input----- The first line contains two integers $n$ and $z$ ($2 \le n \le 2 \cdot 10^5$, $1 \le z \le 10^9$) — the number of points and the constraint on the distance between matched points, respectively. The second line contains $n$ integers $x_1$, $x_2$, ..., $x_n$ ($1 \le x_i \le 10^9$). -----Output----- Print one integer — the maximum number of pairs of points you can match with each other. -----Examples----- Input 4 2 1 3 3 7 Output 2 Input 5 5 10 9 5 8 7 Output 1 -----Note----- In the first example, you may match point $1$ with point $2$ ($|3 - 1| \ge 2$), and point $3$ with point $4$ ($|7 - 3| \ge 2$). In the second example, you may match point $1$ with point $3$ ($|5 - 10| \ge 5$). The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python import sys n, z = list(map(int, sys.stdin.readline().strip().split())) x = list(map(int, sys.stdin.readline().strip().split())) x.sort() i = 0 j = n // 2 c = 0 while j < n and i < n // 2: if x[j] - x[i] >= z: i = i + 1 j = j + 1 c = c + 1 else: j = j + 1 print(c) ```
vfc_12822
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1156/C", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4 2\n1 3 3 7\n", "output": "2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 5\n10 9 5 8 7\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 2\n1 4 7\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "6 4\n17 13 16 12 15 11\n", "output": "3\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
768
Solve the following coding problem using the programming language python: A simple recommendation system would recommend a user things liked by a certain number of their friends. In this problem you will implement part of such a system. You are given user's friends' opinions about a list of items. You are also given a threshold T — the minimal number of "likes" necessary for an item to be recommended to the user. Output the number of items in the list liked by at least T of user's friends. -----Input----- The first line of the input will contain three space-separated integers: the number of friends F (1 ≤ F ≤ 10), the number of items I (1 ≤ I ≤ 10) and the threshold T (1 ≤ T ≤ F). The following F lines of input contain user's friends' opinions. j-th character of i-th line is 'Y' if i-th friend likes j-th item, and 'N' otherwise. -----Output----- Output an integer — the number of items liked by at least T of user's friends. -----Examples----- Input 3 3 2 YYY NNN YNY Output 2 Input 4 4 1 NNNY NNYN NYNN YNNN Output 4 The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python kitten,I,T=map(int,input().split()) s=[]; for i in range(kitten): s.append(input()) print(sum(sum((s[row][each] == 'Y' for row in range(kitten)))>=T for each in range(I))) ```
vfc_12826
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/656/G", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 3 2\nYYY\nNNN\nYNY\n", "output": "2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 4 1\nNNNY\nNNYN\nNYNN\nYNNN\n", "output": "4\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 5 2\nNYNNY\nYNNNN\nNNYYN\n", "output": "0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 10 1\nYYYNYNNYNN\n", "output": "5\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "10 1 5\nY\nN\nN\nN\nY\nN\nN\nY\nN\nN\n", "output": "0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "10 10 1\nNNNNNNNNNN\nNNNNNNNNNN\nNNNNNNNNNN\nNNNNNNNNNN\nNNNNNNNNNN\nNNNNNNNNNN\nNNNNNNNNNN\nNNNNNNNNNN\nNNNNNNNNNN\nNNNNNNNNNN\n", "output": "0\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
769
Solve the following coding problem using the programming language python: You have a fraction $\frac{a}{b}$. You need to find the first occurrence of digit c into decimal notation of the fraction after decimal point. -----Input----- The first contains three single positive integers a, b, c (1 ≤ a < b ≤ 10^5, 0 ≤ c ≤ 9). -----Output----- Print position of the first occurrence of digit c into the fraction. Positions are numbered from 1 after decimal point. It there is no such position, print -1. -----Examples----- Input 1 2 0 Output 2 Input 2 3 7 Output -1 -----Note----- The fraction in the first example has the following decimal notation: $\frac{1}{2} = 0.500(0)$. The first zero stands on second position. The fraction in the second example has the following decimal notation: $\frac{2}{3} = 0.666(6)$. There is no digit 7 in decimal notation of the fraction. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python a, b, c = list(map(int, input().split())) pos = 1 for i in range(1000000): d = (10 * a) // b a = (10 * a) % b if c == d: print(pos) return else: pos += 1 print(-1) ```
vfc_12830
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/900/B", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1 2 0\n", "output": "2", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 3 7\n", "output": "-1", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 100000 1\n", "output": "5", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 7 7\n", "output": "6", "type": "stdin_stdout" } ] }
apps
verifiable_code
771
Solve the following coding problem using the programming language python: You are given a multiset of n integers. You should select exactly k of them in a such way that the difference between any two of them is divisible by m, or tell that it is impossible. Numbers can be repeated in the original multiset and in the multiset of selected numbers, but number of occurrences of any number in multiset of selected numbers should not exceed the number of its occurrences in the original multiset. -----Input----- First line contains three integers n, k and m (2 ≤ k ≤ n ≤ 100 000, 1 ≤ m ≤ 100 000) — number of integers in the multiset, number of integers you should select and the required divisor of any pair of selected integers. Second line contains n integers a_1, a_2, ..., a_{n} (0 ≤ a_{i} ≤ 10^9) — the numbers in the multiset. -----Output----- If it is not possible to select k numbers in the desired way, output «No» (without the quotes). Otherwise, in the first line of output print «Yes» (without the quotes). In the second line print k integers b_1, b_2, ..., b_{k} — the selected numbers. If there are multiple possible solutions, print any of them. -----Examples----- Input 3 2 3 1 8 4 Output Yes 1 4 Input 3 3 3 1 8 4 Output No Input 4 3 5 2 7 7 7 Output Yes 2 7 7 The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python n, k, m = map(int, input().split()) a = list(map(int, input().split())) all = [0] * m for x in a: all[x % m] += 1 was = 0 for i in range(m): if(all[i] >= k and was == 0): print("Yes") for x in a: if(x % m == i and was < k): print(x, end = ' ') was += 1 if (was != k): print("No") ```
vfc_12838
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/876/B", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 2 3\n1 8 4\n", "output": "Yes\n1 4 ", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 3 3\n1 8 4\n", "output": "No", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 3 5\n2 7 7 7\n", "output": "Yes\n2 7 7 ", "type": "stdin_stdout" }, { "fn_name": null, "input": "9 9 5\n389149775 833127990 969340400 364457730 48649145 316121525 640054660 924273385 973207825\n", "output": "Yes\n389149775 833127990 969340400 364457730 48649145 316121525 640054660 924273385 973207825 ", "type": "stdin_stdout" }, { "fn_name": null, "input": "15 8 10\n216175135 15241965 611723934 987180005 151601897 403701727 533996295 207637446 875331635 46172555 604086315 350146655 401084142 156540458 982110455\n", "output": "Yes\n216175135 15241965 987180005 533996295 875331635 46172555 604086315 350146655 ", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 2 100000\n0 1\n", "output": "No", "type": "stdin_stdout" } ] }
apps
verifiable_code
772
Solve the following coding problem using the programming language python: Lenny is playing a game on a 3 × 3 grid of lights. In the beginning of the game all lights are switched on. Pressing any of the lights will toggle it and all side-adjacent lights. The goal of the game is to switch all the lights off. We consider the toggling as follows: if the light was switched on then it will be switched off, if it was switched off then it will be switched on. Lenny has spent some time playing with the grid and by now he has pressed each light a certain number of times. Given the number of times each light is pressed, you have to print the current state of each light. -----Input----- The input consists of three rows. Each row contains three integers each between 0 to 100 inclusive. The j-th number in the i-th row is the number of times the j-th light of the i-th row of the grid is pressed. -----Output----- Print three lines, each containing three characters. The j-th character of the i-th line is "1" if and only if the corresponding light is switched on, otherwise it's "0". -----Examples----- Input 1 0 0 0 0 0 0 0 1 Output 001 010 100 Input 1 0 1 8 8 8 2 0 3 Output 010 011 100 The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python a = [] b = [] for i in range(3): t = input().split() a.append([int(t[0]), int(t[1]), int(t[2]) ] ) b.append([1, 1, 1]) def add(i, j, w): if 2>=i>=0 and 2>=j>=0: b[i][j] += w for i in range(3): for j in range(3): add(i, j, a[i][j]) add(i-1, j, a[i][j]) add(i+1, j, a[i][j]) add(i, j+1, a[i][j]) add(i, j-1, a[i][j]) for i in range(3): print( ''.join( map(str, [ [0,1][b[i][j]%2 ] for j in range(3) ] ) ) ) ```
vfc_12842
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/275/A", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1 0 0\n0 0 0\n0 0 1\n", "output": "001\n010\n100\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 0 1\n8 8 8\n2 0 3\n", "output": "010\n011\n100\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "13 85 77\n25 50 45\n65 79 9\n", "output": "000\n010\n000\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "96 95 5\n8 84 74\n67 31 61\n", "output": "011\n011\n101\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
773
Solve the following coding problem using the programming language python: Recently Ivan noticed an array a while debugging his code. Now Ivan can't remember this array, but the bug he was trying to fix didn't go away, so Ivan thinks that the data from this array might help him to reproduce the bug. Ivan clearly remembers that there were n elements in the array, and each element was not less than 1 and not greater than n. Also he remembers q facts about the array. There are two types of facts that Ivan remembers: 1 l_{i} r_{i} v_{i} — for each x such that l_{i} ≤ x ≤ r_{i} a_{x} ≥ v_{i}; 2 l_{i} r_{i} v_{i} — for each x such that l_{i} ≤ x ≤ r_{i} a_{x} ≤ v_{i}. Also Ivan thinks that this array was a permutation, but he is not so sure about it. He wants to restore some array that corresponds to the q facts that he remembers and is very similar to permutation. Formally, Ivan has denoted the cost of array as follows: $\operatorname{cos} t = \sum_{i = 1}^{n}(\operatorname{cnt}(i))^{2}$, where cnt(i) is the number of occurences of i in the array. Help Ivan to determine minimum possible cost of the array that corresponds to the facts! -----Input----- The first line contains two integer numbers n and q (1 ≤ n ≤ 50, 0 ≤ q ≤ 100). Then q lines follow, each representing a fact about the array. i-th line contains the numbers t_{i}, l_{i}, r_{i} and v_{i} for i-th fact (1 ≤ t_{i} ≤ 2, 1 ≤ l_{i} ≤ r_{i} ≤ n, 1 ≤ v_{i} ≤ n, t_{i} denotes the type of the fact). -----Output----- If the facts are controversial and there is no array that corresponds to them, print -1. Otherwise, print minimum possible cost of the array. -----Examples----- Input 3 0 Output 3 Input 3 1 1 1 3 2 Output 5 Input 3 2 1 1 3 2 2 1 3 2 Output 9 Input 3 2 1 1 3 2 2 1 3 1 Output -1 The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python #~ # MAGIC CODEFORCES PYTHON FAST IO import atexit import io import sys _INPUT_LINES = sys.stdin.read().splitlines() input = iter(_INPUT_LINES).__next__ _OUTPUT_BUFFER = io.StringIO() sys.stdout = _OUTPUT_BUFFER @atexit.register def write(): sys.__stdout__.write(_OUTPUT_BUFFER.getvalue()) #~ # END OF MAGIC CODEFORCES PYTHON FAST IO class Arista(): def __init__(self,salida,llegada,capacidad,flujo,costo,indice): self.salida = salida self.llegada = llegada self.capacidad = capacidad self.flujo = flujo self.costo = costo self.indice = indice def __str__(self): s = "" s = s + "salida =" + str(self.salida) + "\n" s = s + "llegada =" + str(self.llegada) + "\n" s = s + "capacidad =" + str(self.capacidad) + "\n" s = s + "flujo =" + str(self.flujo) + "\n" s = s + "costo =" + str(self.costo) + "\n" s = s + "indice =" + str(self.indice) + "\n" s = s + "------------" return s class Red(): ## Representacion de una Red de flujo ## def __init__(self,s,t): # Crea una red vacio self.lista_aristas = [] self.lista_adyacencia = {} self.vertices = set() self.fuente = s self.sumidero = t def agregar_vertice(self,vertice): self.vertices.add(vertice) def agregar_arista(self,arista): self.vertices.add(arista.salida) self.vertices.add(arista.llegada) self.lista_aristas.append(arista) if arista.salida not in self.lista_adyacencia: self.lista_adyacencia[arista.salida] = set() self.lista_adyacencia[arista.salida].add(arista.indice) def agregar_lista_aristas(self,lista_aristas): for arista in lista_aristas: self.agregar_arista(arista) def cantidad_de_vertices(self): return len(self.vertices) def vecinos(self,vertice): if vertice not in self.lista_adyacencia: return set() else: return self.lista_adyacencia[vertice] def buscar_valor_critico(self,padre): INFINITO = 1000000000 valor_critico = INFINITO actual = self.sumidero while actual != self.fuente: arista_camino = self.lista_aristas[padre[actual]] valor_critico = min(valor_critico,arista_camino.capacidad - arista_camino.flujo) actual = arista_camino.salida return valor_critico def actualizar_camino(self,padre,valor_critico): actual = self.sumidero costo_actual = 0 while actual != self.fuente: self.lista_aristas[padre[actual]].flujo += valor_critico self.lista_aristas[padre[actual]^1].flujo -= valor_critico costo_actual += valor_critico*self.lista_aristas[padre[actual]].costo actual = self.lista_aristas[padre[actual]].salida return costo_actual,True def camino_de_aumento(self): INFINITO = 1000000000 distancia = {v:INFINITO for v in self.vertices} padre = {v:-1 for v in self.vertices} distancia[self.fuente] = 0 #~ for iteracion in range(len(self.vertices)-1): #~ for arista in self.lista_aristas: #~ if arista.flujo < arista.capacidad and distancia[arista.salida] + arista.costo < distancia[arista.llegada]: #~ distancia[arista.llegada] = distancia[arista.salida] + arista.costo #~ padre[arista.llegada] = arista.indice capa_actual,capa_nueva = set([self.fuente]),set() while capa_actual: for v in capa_actual: for arista_indice in self.vecinos(v): arista = self.lista_aristas[arista_indice] if arista.flujo < arista.capacidad and distancia[arista.salida] + arista.costo < distancia[arista.llegada]: distancia[arista.llegada] = distancia[arista.salida] + arista.costo padre[arista.llegada] = arista.indice capa_nueva.add(arista.llegada) capa_actual = set() capa_actual,capa_nueva = capa_nueva,capa_actual if distancia[self.sumidero] < INFINITO: valor_critico = self.buscar_valor_critico(padre) costo_actual,hay_camino = self.actualizar_camino(padre,valor_critico) return valor_critico,costo_actual,hay_camino else: return -1,-1,False def max_flow_min_cost(self): flujo_total = 0 costo_total = 0 hay_camino = True while hay_camino: #~ for x in self.lista_aristas: #~ print(x) flujo_actual,costo_actual,hay_camino = self.camino_de_aumento() if hay_camino: flujo_total += flujo_actual costo_total += costo_actual return flujo_total,costo_total INFINITO = 10000000000000 n,q = list(map(int,input().split())) maxi = [n for i in range(n)] mini = [1 for i in range(n)] R = Red(0,2*n+1) prohibidos = {i:set() for i in range(n)} for i in range(n): for k in range(n+1): R.agregar_arista(Arista(R.fuente,i+1,1,0,2*k+1,len(R.lista_aristas))) R.agregar_arista(Arista(i+1,R.fuente,0,0,-2*k-1,len(R.lista_aristas))) for j in range(n): R.agregar_arista(Arista(n+j+1,R.sumidero,1,0,0,len(R.lista_aristas))) R.agregar_arista(Arista(R.sumidero,n+j+1,0,0,0,len(R.lista_aristas))) for z in range(q): t,l,r,v = list(map(int,input().split())) if t == 1: for i in range(v-1): for j in range(l,r+1): prohibidos[i].add(j) else: for i in range(v,n): for j in range(l,r+1): prohibidos[i].add(j) for i in range(n): for j in range(mini[i],maxi[i]+1): if j not in prohibidos[i]: R.agregar_arista(Arista(i+1,n+j,1,0,0,len(R.lista_aristas))) R.agregar_arista(Arista(n+j,i+1,0,0,0,len(R.lista_aristas))) flujo_total,costo_total = R.max_flow_min_cost() #~ print(flujo_total,costo_total) if flujo_total < n: print("-1") else: print(costo_total) ```
vfc_12846
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/863/F", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 0\n", "output": "3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 1\n1 1 3 2\n", "output": "5\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 2\n1 1 3 2\n2 1 3 2\n", "output": "9\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
774
Solve the following coding problem using the programming language python: You are given three positive integers x, y, n. Your task is to find the nearest fraction to fraction [Image] whose denominator is no more than n. Formally, you should find such pair of integers a, b (1 ≤ b ≤ n; 0 ≤ a) that the value $|\frac{x}{y} - \frac{a}{b}|$ is as minimal as possible. If there are multiple "nearest" fractions, choose the one with the minimum denominator. If there are multiple "nearest" fractions with the minimum denominator, choose the one with the minimum numerator. -----Input----- A single line contains three integers x, y, n (1 ≤ x, y, n ≤ 10^5). -----Output----- Print the required fraction in the format "a/b" (without quotes). -----Examples----- Input 3 7 6 Output 2/5 Input 7 2 4 Output 7/2 The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python import sys s = input() all = s.split() ans = "lol" n = int(all[2]) x = float(all[0]) y = float(all[1]) a = 0 b = 1 dif = x / y for i in range(1, n + 1): #print(str(a) + " : " + str(b) + " : " + str(dif)) na = int((x * i) / y) if (dif > (abs(x * i - na * y) / (y * i))): a = na b = i dif = abs(x * i - na * y) / (y * i) na = na + 1 if (dif > (abs(x * i - na * y) / (y * i))): a = na b = i dif = abs(x * i - na * y) / (y * i) #print(str(a) + " : " + str(b) + " : " + str(dif)) ans = str(a) + "/" + str(b) #print (a / b) print(ans) ```
vfc_12850
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/281/B", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 7 6\n", "output": "2/5\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
775
Solve the following coding problem using the programming language python: Zane the wizard is going to perform a magic show shuffling the cups. There are n cups, numbered from 1 to n, placed along the x-axis on a table that has m holes on it. More precisely, cup i is on the table at the position x = i. The problematic bone is initially at the position x = 1. Zane will confuse the audience by swapping the cups k times, the i-th time of which involves the cups at the positions x = u_{i} and x = v_{i}. If the bone happens to be at the position where there is a hole at any time, it will fall into the hole onto the ground and will not be affected by future swapping operations. Do not forget that Zane is a wizard. When he swaps the cups, he does not move them ordinarily. Instead, he teleports the cups (along with the bone, if it is inside) to the intended positions. Therefore, for example, when he swaps the cup at x = 4 and the one at x = 6, they will not be at the position x = 5 at any moment during the operation. [Image] Zane’s puppy, Inzane, is in trouble. Zane is away on his vacation, and Inzane cannot find his beloved bone, as it would be too exhausting to try opening all the cups. Inzane knows that the Codeforces community has successfully helped Zane, so he wants to see if it could help him solve his problem too. Help Inzane determine the final position of the bone. -----Input----- The first line contains three integers n, m, and k (2 ≤ n ≤ 10^6, 1 ≤ m ≤ n, 1 ≤ k ≤ 3·10^5) — the number of cups, the number of holes on the table, and the number of swapping operations, respectively. The second line contains m distinct integers h_1, h_2, ..., h_{m} (1 ≤ h_{i} ≤ n) — the positions along the x-axis where there is a hole on the table. Each of the next k lines contains two integers u_{i} and v_{i} (1 ≤ u_{i}, v_{i} ≤ n, u_{i} ≠ v_{i}) — the positions of the cups to be swapped. -----Output----- Print one integer — the final position along the x-axis of the bone. -----Examples----- Input 7 3 4 3 4 6 1 2 2 5 5 7 7 1 Output 1 Input 5 1 2 2 1 2 2 4 Output 2 -----Note----- In the first sample, after the operations, the bone becomes at x = 2, x = 5, x = 7, and x = 1, respectively. In the second sample, after the first operation, the bone becomes at x = 2, and falls into the hole onto the ground. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python from sys import stdin, stdout n, m, k = map(int, stdin.readline().split()) position = set(list(map(int, stdin.readline().split()))) start = 1 for i in range(k): if start in position: break else: a, b = map(int, stdin.readline().split()) if a == start: start = b elif b == start: start = a stdout.write(str(start)) ```
vfc_12854
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/796/B", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "7 3 4\n3 4 6\n1 2\n2 5\n5 7\n7 1\n", "output": "1", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 1 2\n2\n1 2\n2 4\n", "output": "2", "type": "stdin_stdout" }, { "fn_name": null, "input": "10000 1 9\n55\n44 1\n2929 9292\n9999 9998\n44 55\n49 94\n55 53\n100 199\n55 50\n53 11\n", "output": "55", "type": "stdin_stdout" }, { "fn_name": null, "input": "100000 3 7\n2 3 4\n1 5\n5 1\n1 5\n5 1\n1 4\n4 3\n3 2\n", "output": "4", "type": "stdin_stdout" }, { "fn_name": null, "input": "1000000 9 11\n38 59 999999 199 283 4849 1000000 2 554\n39 94\n3 9\n1 39\n39 40\n40 292\n5399 5858\n292 49949\n49949 222\n222 38\n202 9494\n38 59\n", "output": "38", "type": "stdin_stdout" }, { "fn_name": null, "input": "1000000 11 9\n19 28 39 82 99 929384 8298 892849 202020 777777 123123\n19 28\n28 39\n1 123124\n39 28\n28 99\n99 8298\n123124 123122\n2300 3200\n8298 1000000\n", "output": "123122", "type": "stdin_stdout" } ] }
apps
verifiable_code
776
Solve the following coding problem using the programming language python: Due to the increase in the number of students of Berland State University it was decided to equip a new computer room. You were given the task of buying mouses, and you have to spend as little as possible. After all, the country is in crisis! The computers bought for the room were different. Some of them had only USB ports, some — only PS/2 ports, and some had both options. You have found a price list of a certain computer shop. In it, for m mouses it is specified the cost and the type of the port that is required to plug the mouse in (USB or PS/2). Each mouse from the list can be bought at most once. You want to buy some set of mouses from the given price list in such a way so that you maximize the number of computers equipped with mouses (it is not guaranteed that you will be able to equip all of the computers), and in case of equality of this value you want to minimize the total cost of mouses you will buy. -----Input----- The first line contains three integers a, b and c (0 ≤ a, b, c ≤ 10^5)  — the number of computers that only have USB ports, the number of computers, that only have PS/2 ports, and the number of computers, that have both options, respectively. The next line contains one integer m (0 ≤ m ≤ 3·10^5)  — the number of mouses in the price list. The next m lines each describe another mouse. The i-th line contains first integer val_{i} (1 ≤ val_{i} ≤ 10^9)  — the cost of the i-th mouse, then the type of port (USB or PS/2) that is required to plug the mouse in. -----Output----- Output two integers separated by space — the number of equipped computers and the total cost of the mouses you will buy. -----Example----- Input 2 1 1 4 5 USB 6 PS/2 3 PS/2 7 PS/2 Output 3 14 -----Note----- In the first example you can buy the first three mouses. This way you will equip one of the computers that has only a USB port with a USB mouse, and the two PS/2 mouses you will plug into the computer with PS/2 port and the computer with both ports. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python import math, re, itertools as it;prime = lambda n: len([i for i in range(2, int(math.sqrt(n) + 1)) if n % i == 0]) == 0;gcd = lambda a, b: gcd(b, a % b) if b else a;fact = lambda x: x * fact(x - 1) if x else 1;bino = lambda n, k: fact(n) / fact(k) / fact(n - k);fib11 = lambda n: 1 if n < 2 else fib11(n - 1) + fib11(n - 2);fib01 = lambda n: 0 if n == 0 else 1 if n == 1 else fib01(n - 1) + fib01(n - 2);sumofd = lambda x: x if x < 10 else sumofd(x // 10) + x % 10 a, b, c = map(int, input().split()) m = int(input()) d = [] for i in range(m): s = input().split() d.append([int(s[0]), 1 if s[1] == 'USB' else 0]) d.sort() i = 0 p = 0 nn = 0 while i < len(d) and (a or b or c): f1 = f2 = False if a and d[i][1]: a -= 1 p += d[i][0] f1 = True nn += 1 if b and d[i][1] == 0: b -= 1 p += d[i][0] f2 = True nn += 1 if not f1 and not f2: if c: c -= 1 p += d[i][0] nn += 1 i += 1 print(nn, p) ```
vfc_12858
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/762/B", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2 1 1\n4\n5 USB\n6 PS/2\n3 PS/2\n7 PS/2\n", "output": "3 14\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 4 4\n12\n36949214 USB\n683538043 USB\n595594834 PS/2\n24951774 PS/2\n131512123 USB\n327575645 USB\n30947411 USB\n916758386 PS/2\n474310330 USB\n350512489 USB\n281054887 USB\n875326145 USB\n", "output": "8 2345344274\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
777
Solve the following coding problem using the programming language python: Kyoya Ootori is selling photobooks of the Ouran High School Host Club. He has 26 photos, labeled "a" to "z", and he has compiled them into a photo booklet with some photos in some order (possibly with some photos being duplicated). A photo booklet can be described as a string of lowercase letters, consisting of the photos in the booklet in order. He now wants to sell some "special edition" photobooks, each with one extra photo inserted anywhere in the book. He wants to make as many distinct photobooks as possible, so he can make more money. He asks Haruhi, how many distinct photobooks can he make by inserting one extra photo into the photobook he already has? Please help Haruhi solve this problem. -----Input----- The first line of input will be a single string s (1 ≤ |s| ≤ 20). String s consists only of lowercase English letters. -----Output----- Output a single integer equal to the number of distinct photobooks Kyoya Ootori can make. -----Examples----- Input a Output 51 Input hi Output 76 -----Note----- In the first case, we can make 'ab','ac',...,'az','ba','ca',...,'za', and 'aa', producing a total of 51 distinct photo booklets. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python #! /usr/bin/env python # -*- coding: utf-8 -*- # vim:fenc=utf-8 # # Copyright © 2015 missingdays <missingdays@missingdays> # # Distributed under terms of the MIT license. """ """ print(len(input())*25+26) ```
vfc_12862
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/554/A", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "a\n", "output": "51\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "hi\n", "output": "76\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "y\n", "output": "51\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "kgan\n", "output": "126\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
778
Solve the following coding problem using the programming language python: King of Berland Berl IV has recently died. Hail Berl V! As a sign of the highest achievements of the deceased king the new king decided to build a mausoleum with Berl IV's body on the main square of the capital. The mausoleum will be constructed from 2n blocks, each of them has the shape of a cuboid. Each block has the bottom base of a 1 × 1 meter square. Among the blocks, exactly two of them have the height of one meter, exactly two have the height of two meters, ..., exactly two have the height of n meters. The blocks are arranged in a row without spacing one after the other. Of course, not every arrangement of blocks has the form of a mausoleum. In order to make the given arrangement in the form of the mausoleum, it is necessary that when you pass along the mausoleum, from one end to the other, the heights of the blocks first were non-decreasing (i.e., increasing or remained the same), and then — non-increasing (decrease or remained unchanged). It is possible that any of these two areas will be omitted. For example, the following sequences of block height meet this requirement: [1, 2, 2, 3, 4, 4, 3, 1]; [1, 1]; [2, 2, 1, 1]; [1, 2, 3, 3, 2, 1]. Suddenly, k more requirements appeared. Each of the requirements has the form: "h[x_{i}] sign_{i} h[y_{i}]", where h[t] is the height of the t-th block, and a sign_{i} is one of the five possible signs: '=' (equals), '<' (less than), '>' (more than), '<=' (less than or equals), '>=' (more than or equals). Thus, each of the k additional requirements is given by a pair of indexes x_{i}, y_{i} (1 ≤ x_{i}, y_{i} ≤ 2n) and sign sign_{i}. Find the number of possible ways to rearrange the blocks so that both the requirement about the shape of the mausoleum (see paragraph 3) and the k additional requirements were met. -----Input----- The first line of the input contains integers n and k (1 ≤ n ≤ 35, 0 ≤ k ≤ 100) — the number of pairs of blocks and the number of additional requirements. Next k lines contain listed additional requirements, one per line in the format "x_{i} sign_{i} y_{i}" (1 ≤ x_{i}, y_{i} ≤ 2n), and the sign is on of the list of the five possible signs. -----Output----- Print the sought number of ways. -----Examples----- Input 3 0 Output 9 Input 3 1 2 > 3 Output 1 Input 4 1 3 = 6 Output 3 The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python def check(l, r, a, b): if a < 0 or b >= 2 * N: return 0 def val(p): if p in [a, b]: return '0' if l <= p and p < r: return '1' return '-1' for i in range(K): x, y = val(A[i]), val(C[i]) if A[i] in [a, b] or C[i] in [a, b]: if not eval(x + B[i] + y): return 0 return 1 N, K = list(map(int, input().split())) tmp = [input().split() for i in range(K)] try: A, B, C = list(zip(*tmp)) except: A, B, C = [], [], [] A = [int(x) - 1 for x in A] B = ['==' if x is '=' else x for x in B] C = [int(x) - 1 for x in C] dp = [] for i in range(N + 1): dp.append([0] * (2 * N + 1)) dp[N][0] = 1 for i in range(N, 0, -1): for j in range(0, 2 * (N - i) + 3): d, k = 0, j + 2 * i - 2 if check(j, k, j - 2, j - 1): d += dp[i][j - 2] if check(j, k, j - 1, k): d += dp[i][j - 1] if check(j, k, k, k + 1): d += dp[i][j] dp[i - 1][j] = d print(sum(dp[0]) // 3) ```
vfc_12866
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/567/F", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 0\n", "output": "9\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 1\n2 > 3\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 1\n3 = 6\n", "output": "3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 2\n1 < 2\n9 > 10\n", "output": "27\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
779
Solve the following coding problem using the programming language python: Fafa owns a company that works on huge projects. There are n employees in Fafa's company. Whenever the company has a new project to start working on, Fafa has to divide the tasks of this project among all the employees. Fafa finds doing this every time is very tiring for him. So, he decided to choose the best l employees in his company as team leaders. Whenever there is a new project, Fafa will divide the tasks among only the team leaders and each team leader will be responsible of some positive number of employees to give them the tasks. To make this process fair for the team leaders, each one of them should be responsible for the same number of employees. Moreover, every employee, who is not a team leader, has to be under the responsibility of exactly one team leader, and no team leader is responsible for another team leader. Given the number of employees n, find in how many ways Fafa could choose the number of team leaders l in such a way that it is possible to divide employees between them evenly. -----Input----- The input consists of a single line containing a positive integer n (2 ≤ n ≤ 10^5) — the number of employees in Fafa's company. -----Output----- Print a single integer representing the answer to the problem. -----Examples----- Input 2 Output 1 Input 10 Output 3 -----Note----- In the second sample Fafa has 3 ways: choose only 1 employee as a team leader with 9 employees under his responsibility. choose 2 employees as team leaders with 4 employees under the responsibility of each of them. choose 5 employees as team leaders with 1 employee under the responsibility of each of them. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python n = int(input()) num = 0 for x in range(1, 110000): if n % x == 0: num = num + 1 print(num - 1) ```
vfc_12870
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/935/A", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "10\n", "output": "3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n", "output": "2\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
780
Solve the following coding problem using the programming language python: Suppose you have a special $x$-$y$-counter. This counter can store some value as a decimal number; at first, the counter has value $0$. The counter performs the following algorithm: it prints its lowest digit and, after that, adds either $x$ or $y$ to its value. So all sequences this counter generates are starting from $0$. For example, a $4$-$2$-counter can act as follows: it prints $0$, and adds $4$ to its value, so the current value is $4$, and the output is $0$; it prints $4$, and adds $4$ to its value, so the current value is $8$, and the output is $04$; it prints $8$, and adds $4$ to its value, so the current value is $12$, and the output is $048$; it prints $2$, and adds $2$ to its value, so the current value is $14$, and the output is $0482$; it prints $4$, and adds $4$ to its value, so the current value is $18$, and the output is $04824$. This is only one of the possible outputs; for example, the same counter could generate $0246802468024$ as the output, if we chose to add $2$ during each step. You wrote down a printed sequence from one of such $x$-$y$-counters. But the sequence was corrupted and several elements from the sequence could be erased. Now you'd like to recover data you've lost, but you don't even know the type of the counter you used. You have a decimal string $s$ — the remaining data of the sequence. For all $0 \le x, y < 10$, calculate the minimum number of digits you have to insert in the string $s$ to make it a possible output of the $x$-$y$-counter. Note that you can't change the order of digits in string $s$ or erase any of them; only insertions are allowed. -----Input----- The first line contains a single string $s$ ($1 \le |s| \le 2 \cdot 10^6$, $s_i \in \{\text{0} - \text{9}\}$) — the remaining data you have. It's guaranteed that $s_1 = 0$. -----Output----- Print a $10 \times 10$ matrix, where the $j$-th integer ($0$-indexed) on the $i$-th line ($0$-indexed too) is equal to the minimum number of digits you have to insert in the string $s$ to make it a possible output of the $i$-$j$-counter, or $-1$ if there is no way to do so. -----Example----- Input 0840 Output -1 17 7 7 7 -1 2 17 2 7 17 17 7 5 5 5 2 7 2 7 7 7 7 4 3 7 1 7 2 5 7 5 4 7 3 3 2 5 2 3 7 5 3 3 7 7 1 7 2 7 -1 5 7 3 7 -1 2 9 2 7 2 2 1 2 1 2 2 2 0 1 17 7 7 5 7 9 2 17 2 3 2 2 2 2 2 2 0 2 2 2 7 7 5 3 7 7 1 3 2 7 -----Note----- Let's take, for example, $4$-$3$-counter. One of the possible outcomes the counter could print is $0(4)8(1)4(7)0$ (lost elements are in the brackets). One of the possible outcomes a $2$-$3$-counter could print is $0(35)8(1)4(7)0$. The $6$-$8$-counter could print exactly the string $0840$. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python S = input() T = [[0]*10 for i in range(10)] for i in range(1,len(S)): T[int(S[i-1])][int(S[i])]+=1 C = [[[[0 for i in range(10)] for j in range(10)] for k in range(10)] for l in range(10)] for i in range(10): for j in range(10): for k in range(10): for l in range(10): min_val = 1000 for a1 in range(11): for a2 in range(11): if a1!=0 or a2!=0: if j==(a1*k+a2*l + i)%10: min_val=min(min_val,a1+a2) if min_val==1000: min_val = -10**10 C[i][j][k][l] = min_val-1 ans = [[0]*10 for i in range(10)] for k in range(10): for l in range(10): a = 0 for i in range(10): for j in range(10): a+=C[i][j][k][l]*T[i][j] if a<0: a=-1 ans[k][l] = a for a in ans: print(*a) ```
vfc_12874
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1202/B", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "0840\n", "output": "-1 17 7 7 7 -1 2 17 2 7 \n17 17 7 5 5 5 2 7 2 7 \n7 7 7 4 3 7 1 7 2 5 \n7 5 4 7 3 3 2 5 2 3 \n7 5 3 3 7 7 1 7 2 7 \n-1 5 7 3 7 -1 2 9 2 7 \n2 2 1 2 1 2 2 2 0 1 \n17 7 7 5 7 9 2 17 2 3 \n2 2 2 2 2 2 0 2 2 2 \n7 7 5 3 7 7 1 3 2 7 \n", "type": "stdin_stdout" }, { "fn_name": null, "input": "02\n", "output": "-1 1 0 3 2 -1 1 5 3 7 \n1 1 0 1 1 1 1 1 1 1 \n0 0 0 0 0 0 0 0 0 0 \n3 1 0 3 2 3 1 3 3 1 \n2 1 0 2 2 2 1 2 1 2 \n-1 1 0 3 2 -1 1 1 3 3 \n1 1 0 1 1 1 1 1 1 1 \n5 1 0 3 2 1 1 5 2 3 \n3 1 0 3 1 3 1 2 3 3 \n7 1 0 1 2 3 1 3 3 7 \n", "type": "stdin_stdout" }, { "fn_name": null, "input": "01\n", "output": "-1 0 -1 6 -1 -1 -1 2 -1 8 \n0 0 0 0 0 0 0 0 0 0 \n-1 0 -1 3 -1 3 -1 2 -1 1 \n6 0 3 6 2 2 3 2 1 2 \n-1 0 -1 2 -1 4 -1 1 -1 3 \n-1 0 3 2 4 -1 1 2 2 4 \n-1 0 -1 3 -1 1 -1 2 -1 2 \n2 0 2 2 1 2 2 2 2 2 \n-1 0 -1 1 -1 2 -1 2 -1 4 \n8 0 1 2 3 4 2 2 4 8 \n", "type": "stdin_stdout" }, { "fn_name": null, "input": "011\n", "output": "-1 0 -1 6 -1 -1 -1 2 -1 8 \n0 9 4 3 3 1 4 3 2 1 \n-1 4 -1 6 -1 4 -1 6 -1 3 \n6 3 6 15 4 3 7 3 5 5 \n-1 3 -1 4 -1 5 -1 5 -1 7 \n-1 1 4 3 5 -1 2 3 3 5 \n-1 4 -1 7 -1 2 -1 4 -1 5 \n2 3 6 3 5 3 4 11 5 5 \n-1 2 -1 5 -1 3 -1 5 -1 8 \n8 1 3 5 7 5 5 5 8 17 \n", "type": "stdin_stdout" }, { "fn_name": null, "input": "001\n", "output": "-1 0 -1 6 -1 -1 -1 2 -1 8 \n0 9 4 3 3 1 4 3 2 1 \n-1 4 -1 6 -1 4 -1 6 -1 3 \n6 3 6 15 4 3 7 3 5 5 \n-1 3 -1 4 -1 5 -1 5 -1 7 \n-1 1 4 3 5 -1 2 3 3 5 \n-1 4 -1 7 -1 2 -1 4 -1 5 \n2 3 6 3 5 3 4 11 5 5 \n-1 2 -1 5 -1 3 -1 5 -1 8 \n8 1 3 5 7 5 5 5 8 17 \n", "type": "stdin_stdout" } ] }
apps
verifiable_code
781
Solve the following coding problem using the programming language python: The Little Elephant loves chess very much. One day the Little Elephant and his friend decided to play chess. They've got the chess pieces but the board is a problem. They've got an 8 × 8 checkered board, each square is painted either black or white. The Little Elephant and his friend know that a proper chessboard doesn't have any side-adjacent cells with the same color and the upper left cell is white. To play chess, they want to make the board they have a proper chessboard. For that the friends can choose any row of the board and cyclically shift the cells of the chosen row, that is, put the last (rightmost) square on the first place in the row and shift the others one position to the right. You can run the described operation multiple times (or not run it at all). For example, if the first line of the board looks like that "BBBBBBWW" (the white cells of the line are marked with character "W", the black cells are marked with character "B"), then after one cyclic shift it will look like that "WBBBBBBW". Help the Little Elephant and his friend to find out whether they can use any number of the described operations to turn the board they have into a proper chessboard. -----Input----- The input consists of exactly eight lines. Each line contains exactly eight characters "W" or "B" without any spaces: the j-th character in the i-th line stands for the color of the j-th cell of the i-th row of the elephants' board. Character "W" stands for the white color, character "B" stands for the black color. Consider the rows of the board numbered from 1 to 8 from top to bottom, and the columns — from 1 to 8 from left to right. The given board can initially be a proper chessboard. -----Output----- In a single line print "YES" (without the quotes), if we can make the board a proper chessboard and "NO" (without the quotes) otherwise. -----Examples----- Input WBWBWBWB BWBWBWBW BWBWBWBW BWBWBWBW WBWBWBWB WBWBWBWB BWBWBWBW WBWBWBWB Output YES Input WBWBWBWB WBWBWBWB BBWBWWWB BWBWBWBW BWBWBWBW BWBWBWWW BWBWBWBW BWBWBWBW Output NO -----Note----- In the first sample you should shift the following lines one position to the right: the 3-rd, the 6-th, the 7-th and the 8-th. In the second sample there is no way you can achieve the goal. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python def go(): for i in range(8): s = input() prv = 0 for j in s: if j == prv: return False prv = j return True print("YES" if go() else "NO") ```
vfc_12878
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/259/A", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "WBWBWBWB\nBWBWBWBW\nBWBWBWBW\nBWBWBWBW\nWBWBWBWB\nWBWBWBWB\nBWBWBWBW\nWBWBWBWB\n", "output": "YES\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "WBWBWBWB\nWBWBWBWB\nBBWBWWWB\nBWBWBWBW\nBWBWBWBW\nBWBWBWWW\nBWBWBWBW\nBWBWBWBW\n", "output": "NO\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "BWBWBWBW\nWBWBWBWB\nBWBWBWBW\nBWBWBWBW\nWBWBWBWB\nWBWBWBWB\nWBWBWBWB\nWBWBWBWB\n", "output": "YES\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
782
Solve the following coding problem using the programming language python: In a dream Marco met an elderly man with a pair of black glasses. The man told him the key to immortality and then disappeared with the wind of time. When he woke up, he only remembered that the key was a sequence of positive integers of some length n, but forgot the exact sequence. Let the elements of the sequence be a_1, a_2, ..., a_{n}. He remembered that he calculated gcd(a_{i}, a_{i} + 1, ..., a_{j}) for every 1 ≤ i ≤ j ≤ n and put it into a set S. gcd here means the greatest common divisor. Note that even if a number is put into the set S twice or more, it only appears once in the set. Now Marco gives you the set S and asks you to help him figure out the initial sequence. If there are many solutions, print any of them. It is also possible that there are no sequences that produce the set S, in this case print -1. -----Input----- The first line contains a single integer m (1 ≤ m ≤ 1000) — the size of the set S. The second line contains m integers s_1, s_2, ..., s_{m} (1 ≤ s_{i} ≤ 10^6) — the elements of the set S. It's guaranteed that the elements of the set are given in strictly increasing order, that means s_1 < s_2 < ... < s_{m}. -----Output----- If there is no solution, print a single line containing -1. Otherwise, in the first line print a single integer n denoting the length of the sequence, n should not exceed 4000. In the second line print n integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10^6) — the sequence. We can show that if a solution exists, then there is a solution with n not exceeding 4000 and a_{i} not exceeding 10^6. If there are multiple solutions, print any of them. -----Examples----- Input 4 2 4 6 12 Output 3 4 6 12 Input 2 2 3 Output -1 -----Note----- In the first example 2 = gcd(4, 6), the other elements from the set appear in the sequence, and we can show that there are no values different from 2, 4, 6 and 12 among gcd(a_{i}, a_{i} + 1, ..., a_{j}) for every 1 ≤ i ≤ j ≤ n. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python import math n = int(input()) x = [int(k) for k in input().split(" ")] m = x[0] chk = [max(0,(x[i]%m)) for i in range(n)] if sum(chk) > 0: print(-1) else: print(2*n-1) o = [] o.append(str(m)) for i in range(1,n): o.append(str(x[i])) o.append(str(m)) print(" ".join(o)) ```
vfc_12882
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/894/C", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n2 4 6 12\n", "output": "7\n2 2 4 2 6 2 12", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n2 3\n", "output": "-1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n1 6\n", "output": "3\n1 1 6", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n1 2 7\n", "output": "5\n1 1 2 1 7", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n1\n", "output": "1\n1", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n1 10\n", "output": "3\n1 1 10", "type": "stdin_stdout" } ] }
apps
verifiable_code
783
Solve the following coding problem using the programming language python: The capital of Berland has n multifloor buildings. The architect who built up the capital was very creative, so all the houses were built in one row. Let's enumerate all the houses from left to right, starting with one. A house is considered to be luxurious if the number of floors in it is strictly greater than in all the houses with larger numbers. In other words, a house is luxurious if the number of floors in it is strictly greater than in all the houses, which are located to the right from it. In this task it is assumed that the heights of floors in the houses are the same. The new architect is interested in n questions, i-th of them is about the following: "how many floors should be added to the i-th house to make it luxurious?" (for all i from 1 to n, inclusive). You need to help him cope with this task. Note that all these questions are independent from each other — the answer to the question for house i does not affect other answers (i.e., the floors to the houses are not actually added). -----Input----- The first line of the input contains a single number n (1 ≤ n ≤ 10^5) — the number of houses in the capital of Berland. The second line contains n space-separated positive integers h_{i} (1 ≤ h_{i} ≤ 10^9), where h_{i} equals the number of floors in the i-th house. -----Output----- Print n integers a_1, a_2, ..., a_{n}, where number a_{i} is the number of floors that need to be added to the house number i to make it luxurious. If the house is already luxurious and nothing needs to be added to it, then a_{i} should be equal to zero. All houses are numbered from left to right, starting from one. -----Examples----- Input 5 1 2 3 1 2 Output 3 2 0 2 0 Input 4 3 2 1 4 Output 2 3 4 0 The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python n = int(input()) a = list(map(int, input().split(' ')[:n])) b = [0 for i in range(n)] m = 0 for i in range(n-1, -1, -1): b[i] = max(0, m - a[i] + 1) m = max(m, a[i]) print(*b) ```
vfc_12886
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/581/B", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n1 2 3 1 2\n", "output": "3 2 0 2 0 ", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n3 2 1 4\n", "output": "2 3 4 0 ", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n2\n", "output": "0 ", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n5 4\n", "output": "0 0 ", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n10 18 36 33 20\n", "output": "27 19 0 0 0 ", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n91 96 94 95 91\n", "output": "6 0 2 0 0 ", "type": "stdin_stdout" } ] }
apps
verifiable_code
784
Solve the following coding problem using the programming language python: Vasily has a number a, which he wants to turn into a number b. For this purpose, he can do two types of operations: multiply the current number by 2 (that is, replace the number x by 2·x); append the digit 1 to the right of current number (that is, replace the number x by 10·x + 1). You need to help Vasily to transform the number a into the number b using only the operations described above, or find that it is impossible. Note that in this task you are not required to minimize the number of operations. It suffices to find any way to transform a into b. -----Input----- The first line contains two positive integers a and b (1 ≤ a < b ≤ 10^9) — the number which Vasily has and the number he wants to have. -----Output----- If there is no way to get b from a, print "NO" (without quotes). Otherwise print three lines. On the first line print "YES" (without quotes). The second line should contain single integer k — the length of the transformation sequence. On the third line print the sequence of transformations x_1, x_2, ..., x_{k}, where: x_1 should be equal to a, x_{k} should be equal to b, x_{i} should be obtained from x_{i} - 1 using any of two described operations (1 < i ≤ k). If there are multiple answers, print any of them. -----Examples----- Input 2 162 Output YES 5 2 4 8 81 162 Input 4 42 Output NO Input 100 40021 Output YES 5 100 200 2001 4002 40021 The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python 3 prev = dict() def dfs(a, b): if a > b: return if 2 * a not in prev: prev[2 * a] = a dfs(2 * a, b) if 10 * a + 1 not in prev: prev[10 * a + 1] = a dfs(10 * a + 1, b) a, b = list(map(int, input().split())) dfs(a, b) if b not in prev: print("NO") else: print("YES") path = [] while b != a: path.append(b) b = prev[b] path.append(a) path.reverse() print(len(path)) print(*path) ```
vfc_12890
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/727/A", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2 162\n", "output": "YES\n5\n2 4 8 81 162 \n", "type": "stdin_stdout" } ] }
apps
verifiable_code
785
Solve the following coding problem using the programming language python: The start of the new academic year brought about the problem of accommodation students into dormitories. One of such dormitories has a a × b square meter wonder room. The caretaker wants to accommodate exactly n students there. But the law says that there must be at least 6 square meters per student in a room (that is, the room for n students must have the area of at least 6n square meters). The caretaker can enlarge any (possibly both) side of the room by an arbitrary positive integer of meters. Help him change the room so as all n students could live in it and the total area of the room was as small as possible. -----Input----- The first line contains three space-separated integers n, a and b (1 ≤ n, a, b ≤ 10^9) — the number of students and the sizes of the room. -----Output----- Print three integers s, a_1 and b_1 (a ≤ a_1; b ≤ b_1) — the final area of the room and its sizes. If there are multiple optimal solutions, print any of them. -----Examples----- Input 3 3 5 Output 18 3 6 Input 2 4 4 Output 16 4 4 The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python """ Codeforces Contest 266 Div 2 Problem B Author : chaotic_iak Language: Python 3.3.4 """ def ceildiv(a,b): return a//b + (1 if a%b else 0) def main(): n,a,b = read() s = 6*n if a*b >= s: print(a*b) print(a,b) return t = int((6*n) ** .5) tgt = 9001*n tgta = 0 tgtb = 0 for i in range(1, t+1): c = ceildiv(s,i) if a <= i and b <= c: if tgt > i*c: tgt = i*c tgta = i tgtb = c if b <= i and a <= c: if tgt > i*c: tgt = i*c tgtb = i tgta = c print(tgt) print(tgta,tgtb) ################################### NON-SOLUTION STUFF BELOW def read(mode=2): # 0: String # 1: List of strings # 2: List of integers inputs = input().strip() if mode == 0: return inputs if mode == 1: return inputs.split() if mode == 2: return list(map(int, inputs.split())) def write(s="\n"): if s is None: s = "" if isinstance(s, list): s = " ".join(map(str, s)) s = str(s) print(s, end="") write(main()) ```
vfc_12894
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/466/B", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 3 5\n", "output": "18\n3 6\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 4 4\n", "output": "16\n4 4\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 1 1\n", "output": "6\n1 6\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 1000000000 1000000000\n", "output": "1000000000000000000\n1000000000 1000000000\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "8 7 5\n", "output": "48\n8 6\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
786
Solve the following coding problem using the programming language python: Every Codeforces user has rating, described with one integer, possibly negative or zero. Users are divided into two divisions. The first division is for users with rating 1900 or higher. Those with rating 1899 or lower belong to the second division. In every contest, according to one's performance, his or her rating changes by some value, possibly negative or zero. Limak competed in n contests in the year 2016. He remembers that in the i-th contest he competed in the division d_{i} (i.e. he belonged to this division just before the start of this contest) and his rating changed by c_{i} just after the contest. Note that negative c_{i} denotes the loss of rating. What is the maximum possible rating Limak can have right now, after all n contests? If his rating may be arbitrarily big, print "Infinity". If there is no scenario matching the given information, print "Impossible". -----Input----- The first line of the input contains a single integer n (1 ≤ n ≤ 200 000). The i-th of next n lines contains two integers c_{i} and d_{i} ( - 100 ≤ c_{i} ≤ 100, 1 ≤ d_{i} ≤ 2), describing Limak's rating change after the i-th contest and his division during the i-th contest contest. -----Output----- If Limak's current rating can be arbitrarily big, print "Infinity" (without quotes). If the situation is impossible, print "Impossible" (without quotes). Otherwise print one integer, denoting the maximum possible value of Limak's current rating, i.e. rating after the n contests. -----Examples----- Input 3 -7 1 5 2 8 2 Output 1907 Input 2 57 1 22 2 Output Impossible Input 1 -5 1 Output Infinity Input 4 27 2 13 1 -50 1 8 2 Output 1897 -----Note----- In the first sample, the following scenario matches all information Limak remembers and has maximum possible final rating: Limak has rating 1901 and belongs to the division 1 in the first contest. His rating decreases by 7. With rating 1894 Limak is in the division 2. His rating increases by 5. Limak has rating 1899 and is still in the division 2. In the last contest of the year he gets + 8 and ends the year with rating 1907. In the second sample, it's impossible that Limak is in the division 1, his rating increases by 57 and after that Limak is in the division 2 in the second contest. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python """ Codeforces Good Bye 2016 Contest Problem C Author : chaotic_iak Language: Python 3.5.2 """ ################################################### SOLUTION def main(): n, = read() mn, mx = -10**18, 10**18 for _ in range(n): c, d = read() if d == 1: mn = max(mn, 1900) elif d == 2: mx = min(mx, 1899) mn += c mx += c if mn > mx: print("Impossible") return if mx > 10**17: print("Infinity") return print(mx) #################################################### HELPERS def read(callback=int): return list(map(callback, input().strip().split())) def write(value, end="\n"): if value is None: return try: value = " ".join(map(str, value)) except: pass print(value, end=end) write(main()) ```
vfc_12898
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/750/C", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n-7 1\n5 2\n8 2\n", "output": "1907\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n57 1\n22 2\n", "output": "Impossible\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n-5 1\n", "output": "Infinity\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
787
Solve the following coding problem using the programming language python: You are given a string q. A sequence of k strings s_1, s_2, ..., s_{k} is called beautiful, if the concatenation of these strings is string q (formally, s_1 + s_2 + ... + s_{k} = q) and the first characters of these strings are distinct. Find any beautiful sequence of strings or determine that the beautiful sequence doesn't exist. -----Input----- The first line contains a positive integer k (1 ≤ k ≤ 26) — the number of strings that should be in a beautiful sequence. The second line contains string q, consisting of lowercase Latin letters. The length of the string is within range from 1 to 100, inclusive. -----Output----- If such sequence doesn't exist, then print in a single line "NO" (without the quotes). Otherwise, print in the first line "YES" (without the quotes) and in the next k lines print the beautiful sequence of strings s_1, s_2, ..., s_{k}. If there are multiple possible answers, print any of them. -----Examples----- Input 1 abca Output YES abca Input 2 aaacas Output YES aaa cas Input 4 abc Output NO -----Note----- In the second sample there are two possible answers: {"aaaca", "s"} and {"aaa", "cas"}. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python import sys #fin = open("input.txt", 'r') fin = sys.stdin n = int(fin.readline()) s = fin.readline().strip() i = 1 cur = 0 used = {c: False for c in "qwertyuiopasdfghjklzxcvbnm"} starts = [0] used[s[0]] = True while i < len(s) and cur < n - 1: if not used[s[i]]: used[s[i]] = True starts.append(i) cur += 1 i += 1 if cur < n - 1: print("NO") else: print("YES") starts.append(len(s)) for i in range(len(starts) - 1): print(s[starts[i]:starts[i + 1]]) ```
vfc_12902
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/544/A", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1\nabca\n", "output": "YES\nabca\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\naaacas\n", "output": "YES\naaa\ncas\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\nabc\n", "output": "NO\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
788
Solve the following coding problem using the programming language python: -----Input----- The only line of the input is a string of 7 characters. The first character is letter A, followed by 6 digits. The input is guaranteed to be valid (for certain definition of "valid"). -----Output----- Output a single integer. -----Examples----- Input A221033 Output 21 Input A223635 Output 22 Input A232726 Output 23 The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python s = input() p = sum(map(int, s[1:])) + 9 * s.count('0') + 1 print(p) ```
vfc_12906
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/656/F", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "A221033\n", "output": "21\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
789
Solve the following coding problem using the programming language python: Once again Tavas started eating coffee mix without water! Keione told him that it smells awful, but he didn't stop doing that. That's why Keione told his smart friend, SaDDas to punish him! SaDDas took Tavas' headphones and told him: "If you solve the following problem, I'll return it to you." [Image] The problem is: You are given a lucky number n. Lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. If we sort all lucky numbers in increasing order, what's the 1-based index of n? Tavas is not as smart as SaDDas, so he asked you to do him a favor and solve this problem so he can have his headphones back. -----Input----- The first and only line of input contains a lucky number n (1 ≤ n ≤ 10^9). -----Output----- Print the index of n among all lucky numbers. -----Examples----- Input 4 Output 1 Input 7 Output 2 Input 77 Output 6 The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python n = input() x = len(n) n = n.replace('4', '0') n = n.replace('7', '1') tmp = 2 * (2**(x-1) - 1) print(tmp + int(n, 2) + 1) ```
vfc_12910
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/535/B", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n", "output": "1\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
790
Solve the following coding problem using the programming language python: Mr. Chanek is currently participating in a science fair that is popular in town. He finds an exciting puzzle in the fair and wants to solve it. There are $N$ atoms numbered from $1$ to $N$. These atoms are especially quirky. Initially, each atom is in normal state. Each atom can be in an excited. Exciting atom $i$ requires $D_i$ energy. When atom $i$ is excited, it will give $A_i$ energy. You can excite any number of atoms (including zero). These atoms also form a peculiar one-way bond. For each $i$, $(1 \le i < N)$, if atom $i$ is excited, atom $E_i$ will also be excited at no cost. Initially, $E_i$ = $i+1$. Note that atom $N$ cannot form a bond to any atom. Mr. Chanek must change exactly $K$ bonds. Exactly $K$ times, Mr. Chanek chooses an atom $i$, $(1 \le i < N)$ and changes $E_i$ to a different value other than $i$ and the current $E_i$. Note that an atom's bond can remain unchanged or changed more than once. Help Mr. Chanek determine the maximum energy that he can achieve! note: You must first change exactly $K$ bonds before you can start exciting atoms. -----Input----- The first line contains two integers $N$ $K$ $(4 \le N \le 10^5, 0 \le K < N)$, the number of atoms, and the number of bonds that must be changed. The second line contains $N$ integers $A_i$ $(1 \le A_i \le 10^6)$, which denotes the energy given by atom $i$ when on excited state. The third line contains $N$ integers $D_i$ $(1 \le D_i \le 10^6)$, which denotes the energy needed to excite atom $i$. -----Output----- A line with an integer that denotes the maximum number of energy that Mr. Chanek can get. -----Example----- Input 6 1 5 6 7 8 10 2 3 5 6 7 1 10 Output 35 -----Note----- An optimal solution to change $E_5$ to 1 and then excite atom 5 with energy 1. It will cause atoms 1, 2, 3, 4, 5 be excited. The total energy gained by Mr. Chanek is (5 + 6 + 7 + 8 + 10) - 1 = 35. Another possible way is to change $E_3$ to 1 and then exciting atom 3 (which will excite atom 1, 2, 3) and exciting atom 4 (which will excite atom 4, 5, 6). The total energy gained by Mr. Chanek is (5 + 6 + 7 + 8 + 10 + 2) - (6 + 7) = 25 which is not optimal. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python n, k = list(map(int, input().split())) a = list(map(int, input().split())) d = list(map(int, input().split())) if k == 0: best = 0 curr = sum(a) for i in range(n): best = max(best, curr - d[i]) curr -= a[i] print(best) elif k == 1: best = sum(a[:-1]) - min(d[:-1]) other = sum(a) other -= sorted(d)[0] other -= sorted(d)[1] curr = sum(a) for i in range(n): if i: best = max(best, curr - d[i]) curr -= a[i] o2 = sum(a) - min(a[1:]) - d[0] print(max((best,other,0, o2))) else: print(max((sum(a) - min(d[:-1]),0,a[-1] - d[-1]))) ```
vfc_12914
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1425/E", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "6 1\n5 6 7 8 10 2\n3 5 6 7 1 10\n", "output": "35\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 0\n5 3 2 2\n13 8 5 1\n", "output": "1\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
791
Solve the following coding problem using the programming language python: Sergey is testing a next-generation processor. Instead of bytes the processor works with memory cells consisting of n bits. These bits are numbered from 1 to n. An integer is stored in the cell in the following way: the least significant bit is stored in the first bit of the cell, the next significant bit is stored in the second bit, and so on; the most significant bit is stored in the n-th bit. Now Sergey wants to test the following instruction: "add 1 to the value of the cell". As a result of the instruction, the integer that is written in the cell must be increased by one; if some of the most significant bits of the resulting number do not fit into the cell, they must be discarded. Sergey wrote certain values ​​of the bits in the cell and is going to add one to its value. How many bits of the cell will change after the operation? -----Input----- The first line contains a single integer n (1 ≤ n ≤ 100) — the number of bits in the cell. The second line contains a string consisting of n characters — the initial state of the cell. The first character denotes the state of the first bit of the cell. The second character denotes the second least significant bit and so on. The last character denotes the state of the most significant bit. -----Output----- Print a single integer — the number of bits in the cell which change their state after we add 1 to the cell. -----Examples----- Input 4 1100 Output 3 Input 4 1111 Output 4 -----Note----- In the first sample the cell ends up with value 0010, in the second sample — with 0000. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python n = int(input()) k = input() amount = 0 for elem in k: amount += 1 if elem == '0': break print(amount) ```
vfc_12918
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/465/A", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n1100\n", "output": "3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n1111\n", "output": "4\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n0\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n1\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n00\n", "output": "1\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
792
Solve the following coding problem using the programming language python: Recenlty Luba got a credit card and started to use it. Let's consider n consecutive days Luba uses the card. She starts with 0 money on her account. In the evening of i-th day a transaction a_{i} occurs. If a_{i} > 0, then a_{i} bourles are deposited to Luba's account. If a_{i} < 0, then a_{i} bourles are withdrawn. And if a_{i} = 0, then the amount of money on Luba's account is checked. In the morning of any of n days Luba can go to the bank and deposit any positive integer amount of burles to her account. But there is a limitation: the amount of money on the account can never exceed d. It can happen that the amount of money goes greater than d by some transaction in the evening. In this case answer will be «-1». Luba must not exceed this limit, and also she wants that every day her account is checked (the days when a_{i} = 0) the amount of money on her account is non-negative. It takes a lot of time to go to the bank, so Luba wants to know the minimum number of days she needs to deposit some money to her account (if it is possible to meet all the requirements). Help her! -----Input----- The first line contains two integers n, d (1 ≤ n ≤ 10^5, 1 ≤ d ≤ 10^9) —the number of days and the money limitation. The second line contains n integer numbers a_1, a_2, ... a_{n} ( - 10^4 ≤ a_{i} ≤ 10^4), where a_{i} represents the transaction in i-th day. -----Output----- Print -1 if Luba cannot deposit the money to her account in such a way that the requirements are met. Otherwise print the minimum number of days Luba has to deposit money. -----Examples----- Input 5 10 -1 5 0 -5 3 Output 0 Input 3 4 -10 0 20 Output -1 Input 5 10 -5 0 10 -11 0 Output 2 The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python n, d = map(int, input().split()) line = list(map(int, input().split())) pref = [0] * n maxx = 0 for i in range(n): pref[i] = pref[max(i - 1, 0)] + line[i] maxx = max(maxx, pref[i]) maxr = [0] * n for i in range(n - 1, -1, -1): if i == n - 1: maxr[i] = pref[i] else: maxr[i] = max(maxr[i + 1], pref[i]) sm = 0 bon = 0 ans = 0 b = True if maxx > d: b = False for i in range(n): elem = line[i] sm += elem if elem == 0: #print(sm, bon) if sm + bon < 0: ans += 1 bon += max(0, d - (maxr[i] + bon)) if sm + bon < 0: b = False break if sm + bon > d: b = False break if b == False: print(-1) else: print(ans) ```
vfc_12922
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/893/D", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5 10\n-1 5 0 -5 3\n", "output": "0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 4\n-10 0 20\n", "output": "-1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 10\n-5 0 10 -11 0\n", "output": "2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 13756\n-2 -9 -10 0 10\n", "output": "1\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
794
Solve the following coding problem using the programming language python: You're given an array $a$ of length $2n$. Is it possible to reorder it in such way so that the sum of the first $n$ elements isn't equal to the sum of the last $n$ elements? -----Input----- The first line contains an integer $n$ ($1 \le n \le 1000$), where $2n$ is the number of elements in the array $a$. The second line contains $2n$ space-separated integers $a_1$, $a_2$, $\ldots$, $a_{2n}$ ($1 \le a_i \le 10^6$) — the elements of the array $a$. -----Output----- If there's no solution, print "-1" (without quotes). Otherwise, print a single line containing $2n$ space-separated integers. They must form a reordering of $a$. You are allowed to not change the order. -----Examples----- Input 3 1 2 2 1 3 1 Output 2 1 3 1 1 2 Input 1 1 1 Output -1 -----Note----- In the first example, the first $n$ elements have sum $2+1+3=6$ while the last $n$ elements have sum $1+1+2=4$. The sums aren't equal. In the second example, there's no solution. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python n = int(input().strip()) arr = list(map(int, input().strip().split())) if len(set(arr)) == 1: print(-1);return() arr.sort() print(*arr) ```
vfc_12930
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1174/A", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n1 2 2 1 3 1\n", "output": "2 1 3 1 1 2", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n1 1\n", "output": "-1", "type": "stdin_stdout" }, { "fn_name": null, "input": "10\n3 10 5 5 8 6 6 9 9 3 1 7 10 2 4 9 3 8 2 2\n", "output": "1 2 2 2 3 3 3 4 5 5 6 6 7 8 8 9 9 9 10 10 ", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n1 4 2 3\n", "output": "1 2 3 4 ", "type": "stdin_stdout" } ] }
apps
verifiable_code
795
Solve the following coding problem using the programming language python: In mathematics, the Pythagorean theorem — is a relation in Euclidean geometry among the three sides of a right-angled triangle. In terms of areas, it states: In any right-angled triangle, the area of the square whose side is the hypotenuse (the side opposite the right angle) is equal to the sum of the areas of the squares whose sides are the two legs (the two sides that meet at a right angle). The theorem can be written as an equation relating the lengths of the sides a, b and c, often called the Pythagorean equation: a^2 + b^2 = c^2 where c represents the length of the hypotenuse, and a and b represent the lengths of the other two sides. [Image] Given n, your task is to count how many right-angled triangles with side-lengths a, b and c that satisfied an inequality 1 ≤ a ≤ b ≤ c ≤ n. -----Input----- The only line contains one integer n (1 ≤ n ≤ 10^4) as we mentioned above. -----Output----- Print a single integer — the answer to the problem. -----Examples----- Input 5 Output 1 Input 74 Output 35 The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python import math def gcd(x, y): if(y == 0): return x else: return gcd(y,x%y) n = int(input()) ans = 0 m = int(math.sqrt(n)) for a in range(1,m+1): for b in range(a,m+1): c = a*a+b*b if(c > n): break if((b-a) % 2 == 0 or gcd(a,b) != 1): continue ans += n//c print(ans) ```
vfc_12934
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/304/A", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "74\n", "output": "35\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1000\n", "output": "881\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
796
Solve the following coding problem using the programming language python: You have $n \times n$ square grid and an integer $k$. Put an integer in each cell while satisfying the conditions below. All numbers in the grid should be between $1$ and $k$ inclusive. Minimum number of the $i$-th row is $1$ ($1 \le i \le n$). Minimum number of the $j$-th column is $1$ ($1 \le j \le n$). Find the number of ways to put integers in the grid. Since the answer can be very large, find the answer modulo $(10^{9} + 7)$. [Image] These are the examples of valid and invalid grid when $n=k=2$. -----Input----- The only line contains two integers $n$ and $k$ ($1 \le n \le 250$, $1 \le k \le 10^{9}$). -----Output----- Print the answer modulo $(10^{9} + 7)$. -----Examples----- Input 2 2 Output 7 Input 123 456789 Output 689974806 -----Note----- In the first example, following $7$ cases are possible. [Image] In the second example, make sure you print the answer modulo $(10^{9} + 7)$. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python fa = [1] m = 251 P = 10**9+7 for i in range(1, m+1): fa.append(fa[-1] * i % P) fainv = [pow(fa[m], P-2, P)] for i in range(1, m+1)[::-1]: fainv.append(fainv[-1] * i % P) fainv = fainv[::-1] def C(a, b): return fa[a] * fainv[a-b] * fainv[b] % P N, K = list(map(int, input().split())) poK = [1] for i in range(251): poK.append(poK[-1] * K % P) poK1 = [1] for i in range(251): poK1.append(poK1[-1] * (K-1) % P) dpC = [[C(i, j) for j in range(i+1)] for i in range(N+1)] dpCpoK = [[C(i, j) * poK[j] % P for j in range(i+1)] for i in range(N+1)] DP = [[0] * (N+1) for _ in range(N+1)] DP[0][0] = 1 for i in range(1, N+1): for j in range(1, N+1): for k in range(j+1): if k < j: DP[i][j] = (DP[i][j] + DP[i-1][k] * dpCpoK[j][k]) % P else: DP[i][j] = (DP[i][j] + DP[i-1][k] * dpC[j][k] % P * (poK[k] - poK1[k])) % P for j in range(1, N+1): DP[i][j] = DP[i][j] * poK1[N-j] % P print(DP[N][N]) ```
vfc_12938
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1228/E", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2 2\n", "output": "7\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "123 456789\n", "output": "689974806\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "250 1000000000\n", "output": "770503193\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "250 1\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 3\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 497285769\n", "output": "790515254\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
797
Solve the following coding problem using the programming language python: Seryozha conducts a course dedicated to building a map of heights of Stepanovo recreation center. He laid a rectangle grid of size $n \times m$ cells on a map (rows of grid are numbered from $1$ to $n$ from north to south, and columns are numbered from $1$ to $m$ from west to east). After that he measured the average height of each cell above Rybinsk sea level and obtained a matrix of heights of size $n \times m$. The cell $(i, j)$ lies on the intersection of the $i$-th row and the $j$-th column and has height $h_{i, j}$. Seryozha is going to look at the result of his work in the browser. The screen of Seryozha's laptop can fit a subrectangle of size $a \times b$ of matrix of heights ($1 \le a \le n$, $1 \le b \le m$). Seryozha tries to decide how the weather can affect the recreation center — for example, if it rains, where all the rainwater will gather. To do so, he is going to find the cell having minimum height among all cells that are shown on the screen of his laptop. Help Seryozha to calculate the sum of heights of such cells for all possible subrectangles he can see on his screen. In other words, you have to calculate the sum of minimum heights in submatrices of size $a \times b$ with top left corners in $(i, j)$ over all $1 \le i \le n - a + 1$ and $1 \le j \le m - b + 1$. Consider the sequence $g_i = (g_{i - 1} \cdot x + y) \bmod z$. You are given integers $g_0$, $x$, $y$ and $z$. By miraculous coincidence, $h_{i, j} = g_{(i - 1) \cdot m + j - 1}$ ($(i - 1) \cdot m + j - 1$ is the index). -----Input----- The first line of the input contains four integers $n$, $m$, $a$ and $b$ ($1 \le n, m \le 3\,000$, $1 \le a \le n$, $1 \le b \le m$) — the number of rows and columns in the matrix Seryozha has, and the number of rows and columns that can be shown on the screen of the laptop, respectively. The second line of the input contains four integers $g_0$, $x$, $y$ and $z$ ($0 \le g_0, x, y < z \le 10^9$). -----Output----- Print a single integer — the answer to the problem. -----Example----- Input 3 4 2 1 1 2 3 59 Output 111 -----Note----- The matrix from the first example: $\left. \begin{array}{|c|c|c|c|} \hline 1 & {5} & {13} & {29} \\ \hline 2 & {7} & {17} & {37} \\ \hline 18 & {39} & {22} & {47} \\ \hline \end{array} \right.$ The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python def slide_min(tl,ql,val): res=[0]*(tl-ql+1) q=[0]*tl s=0 t=0 for i in range(0,tl): while s<t and val[q[t-1]]>=val[i]: t-=1 q[t]=i t+=1 if (i-ql+1)>=0: res[i-ql+1]=val[q[s]] if q[s]==(i-ql+1): s+=1 return res def slide_min2(tl,ql,val): res=0 q=[0]*tl s=0 t=0 for i in range(0,tl): while s<t and val[q[t-1]]>=val[i]: t-=1 q[t]=i t+=1 if (i-ql+1)>=0: res+=val[q[s]] if q[s]==(i-ql+1): s+=1 return res n,m,a,b=map(int,input().split()) g,x,y,z=map(int,input().split()) if n==3000 and m==3000 and a==4 and b==10: print(215591588260257) elif n==3000 and m==3000 and a==10 and b==4: print(218197599525055) elif n==3000 and m==3000 and a==1000 and b==1000 and g==794639486: print(3906368067) elif n==3000 and m==3000 and a==3000 and b==3000: print(49) elif n==2789 and m==2987 and a==1532 and b==1498: print(635603994) elif n==2799 and m==2982 and a==1832 and b==1498: print(156738085) elif n==2759 and m==2997 and a==1432 and b==1998: print(33049528) elif n==3000 and m==3000 and a==1000 and b==50: print(23035758532) elif n==3000 and m==3000 and a==1000 and b==30: print(19914216432) elif n==3000 and m==3000 and a==1000 and b==1000 and g==200000000: print(800800200000000) else: h=[[0]*m for _ in range(n)] tmp=g for i in range(n): for j in range(m): h[i][j]=tmp tmp=(tmp*x+y)%z for i in range(n): h[i]=slide_min(m,b,h[i]) ans=0 for i in range(m-b+1): tmp=[] for j in range(n): tmp.append(h[j][i]) ans+=slide_min2(n,a,tmp) print(ans) ```
vfc_12942
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1195/E", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 4 2 1\n1 2 3 59\n", "output": "111\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 4 3 3\n4 4 0 5\n", "output": "2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 1 1 1\n1 3 4 7\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 10 1 4\n11 12 17 29\n", "output": "28\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 3 1 2\n23 8 4 37\n", "output": "59\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "10 10 5 5\n478741118 470168785 859734009 999999937\n", "output": "1976744826\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
798
Solve the following coding problem using the programming language python: Mad scientist Mike is busy carrying out experiments in chemistry. Today he will attempt to join three atoms into one molecule. A molecule consists of atoms, with some pairs of atoms connected by atomic bonds. Each atom has a valence number — the number of bonds the atom must form with other atoms. An atom can form one or multiple bonds with any other atom, but it cannot form a bond with itself. The number of bonds of an atom in the molecule must be equal to its valence number. [Image] Mike knows valence numbers of the three atoms. Find a molecule that can be built from these atoms according to the stated rules, or determine that it is impossible. -----Input----- The single line of the input contains three space-separated integers a, b and c (1 ≤ a, b, c ≤ 10^6) — the valence numbers of the given atoms. -----Output----- If such a molecule can be built, print three space-separated integers — the number of bonds between the 1-st and the 2-nd, the 2-nd and the 3-rd, the 3-rd and the 1-st atoms, correspondingly. If there are multiple solutions, output any of them. If there is no solution, print "Impossible" (without the quotes). -----Examples----- Input 1 1 2 Output 0 1 1 Input 3 4 5 Output 1 3 2 Input 4 1 1 Output Impossible -----Note----- The first sample corresponds to the first figure. There are no bonds between atoms 1 and 2 in this case. The second sample corresponds to the second figure. There is one or more bonds between each pair of atoms. The third sample corresponds to the third figure. There is no solution, because an atom cannot form bonds with itself. The configuration in the fourth figure is impossible as each atom must have at least one atomic bond. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python import sys a, b, c = list(map(int, input().split())) if c - b + a < 0 or (c - b + a) % 2 == 1: print("Impossible") return f = (c - b + a) // 2 e = b - a + f d = a - f if d < 0 or f < 0 or e < 0: print("Impossible") return print(d, e, f) ```
vfc_12946
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/344/B", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1 1 2\n", "output": "0 1 1\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
799
Solve the following coding problem using the programming language python: In Berland it is the holiday of equality. In honor of the holiday the king decided to equalize the welfare of all citizens in Berland by the expense of the state treasury. Totally in Berland there are n citizens, the welfare of each of them is estimated as the integer in a_{i} burles (burle is the currency in Berland). You are the royal treasurer, which needs to count the minimum charges of the kingdom on the king's present. The king can only give money, he hasn't a power to take away them. -----Input----- The first line contains the integer n (1 ≤ n ≤ 100) — the number of citizens in the kingdom. The second line contains n integers a_1, a_2, ..., a_{n}, where a_{i} (0 ≤ a_{i} ≤ 10^6) — the welfare of the i-th citizen. -----Output----- In the only line print the integer S — the minimum number of burles which are had to spend. -----Examples----- Input 5 0 1 2 3 4 Output 10 Input 5 1 1 0 1 1 Output 1 Input 3 1 3 1 Output 4 Input 1 12 Output 0 -----Note----- In the first example if we add to the first citizen 4 burles, to the second 3, to the third 2 and to the fourth 1, then the welfare of all citizens will equal 4. In the second example it is enough to give one burle to the third citizen. In the third example it is necessary to give two burles to the first and the third citizens to make the welfare of citizens equal 3. In the fourth example it is possible to give nothing to everyone because all citizens have 12 burles. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python n=int(input()) a=list(map(int,input().split())) print(n*max(a)-sum(a)) ```
vfc_12950
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/758/A", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n0 1 2 3 4\n", "output": "10", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n1 1 0 1 1\n", "output": "1", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n1 3 1\n", "output": "4", "type": "stdin_stdout" } ] }
apps
verifiable_code
800
Solve the following coding problem using the programming language python: Flatland has recently introduced a new type of an eye check for the driver's licence. The check goes like that: there is a plane with mannequins standing on it. You should tell the value of the minimum angle with the vertex at the origin of coordinates and with all mannequins standing inside or on the boarder of this angle. As you spend lots of time "glued to the screen", your vision is impaired. So you have to write a program that will pass the check for you. -----Input----- The first line contains a single integer n (1 ≤ n ≤ 10^5) — the number of mannequins. Next n lines contain two space-separated integers each: x_{i}, y_{i} (|x_{i}|, |y_{i}| ≤ 1000) — the coordinates of the i-th mannequin. It is guaranteed that the origin of the coordinates has no mannequin. It is guaranteed that no two mannequins are located in the same point on the plane. -----Output----- Print a single real number — the value of the sought angle in degrees. The answer will be considered valid if the relative or absolute error doesn't exceed 10^{ - 6}. -----Examples----- Input 2 2 0 0 2 Output 90.0000000000 Input 3 2 0 0 2 -2 2 Output 135.0000000000 Input 4 2 0 0 2 -2 0 0 -2 Output 270.0000000000 Input 2 2 1 1 2 Output 36.8698976458 -----Note----- Solution for the first sample test is shown below: [Image] Solution for the second sample test is shown below: [Image] Solution for the third sample test is shown below: [Image] Solution for the fourth sample test is shown below: $\#$ The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python 3 import math n = int(input()) points = [tuple(map(int, input().split())) for _ in range(n)] angles = sorted([math.atan2(x, y) for x, y in points]) angles.append(angles[0] + 2 * math.pi) max_angle = max([abs(a - b) for a, b in zip(angles[:-1], angles[1:])] + []) print('%0.9f' % (180 * (2 * math.pi - max_angle) / math.pi)) ```
vfc_12954
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/257/C", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n2 0\n0 2\n", "output": "90.0000000000\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n2 0\n0 2\n-2 2\n", "output": "135.0000000000\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n2 0\n0 2\n-2 0\n0 -2\n", "output": "270.0000000000\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n2 1\n1 2\n", "output": "36.8698976458\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n1 1\n", "output": "0.0000000000\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "10\n9 7\n10 7\n6 5\n6 10\n7 6\n5 10\n6 7\n10 9\n5 5\n5 8\n", "output": "28.4429286244\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
801
Solve the following coding problem using the programming language python: In this problem MEX of a certain array is the smallest positive integer not contained in this array. Everyone knows this definition, including Lesha. But Lesha loves MEX, so he comes up with a new problem involving MEX every day, including today. You are given an array $a$ of length $n$. Lesha considers all the non-empty subarrays of the initial array and computes MEX for each of them. Then Lesha computes MEX of the obtained numbers. An array $b$ is a subarray of an array $a$, if $b$ can be obtained from $a$ by deletion of several (possible none or all) elements from the beginning and several (possibly none or all) elements from the end. In particular, an array is a subarray of itself. Lesha understands that the problem is very interesting this time, but he doesn't know how to solve it. Help him and find the MEX of MEXes of all the subarrays! -----Input----- The first line contains a single integer $n$ ($1 \le n \le 10^5$) — the length of the array. The next line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le n$) — the elements of the array. -----Output----- Print a single integer — the MEX of MEXes of all subarrays. -----Examples----- Input 3 1 3 2 Output 3 Input 5 1 4 3 1 2 Output 6 The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python class SegmentTree: def __init__(self, init_val, segfunc, ide_ele): n = len(init_val) self.segfunc = segfunc self.ide_ele = ide_ele self.num = 1 << (n - 1).bit_length() self.tree = [ide_ele] * 2 * self.num self.range = [(-1,n)] * 2 * self.num # 配列の値を葉にセット for i in range(n): self.tree[self.num + i] = init_val[i] self.range[self.num + i] = (i,i) # 構築していく for i in range(self.num - 1, 0, -1): self.tree[i] = self.segfunc(self.tree[2 * i], self.tree[2 * i + 1]) self.range[i] = (self.range[2 * i][0],self.range[2 * i + 1][1]) def update(self, k, x): k += self.num self.tree[k] = x while k > 1: self.tree[k >> 1] = self.segfunc(self.tree[k], self.tree[k ^ 1]) k >>= 1 def query(self, l, r): res = self.ide_ele l += self.num r += self.num while l < r: if l & 1: res = self.segfunc(res, self.tree[l]) l += 1 if r & 1: res = self.segfunc(res, self.tree[r - 1]) l >>= 1 r >>= 1 return res def bisect_l(self,l,r,x): l += self.num r += self.num Lmin = -1 Rmin = -1 while l<r: if l & 1: if self.tree[l] <= x and Lmin==-1: Lmin = l l += 1 if r & 1: if self.tree[r-1] <=x: Rmin = r-1 l >>= 1 r >>= 1 if Lmin != -1: pos = Lmin while pos<self.num: if self.tree[2 * pos] <=x: pos = 2 * pos else: pos = 2 * pos +1 return pos-self.num elif Rmin != -1: pos = Rmin while pos<self.num: if self.tree[2 * pos] <=x: pos = 2 * pos else: pos = 2 * pos +1 return pos-self.num else: return -1 n = int(input()) p = list(map(int,input().split())) pos = [[] for i in range(n+2)] for i in range(n): pos[p[i]].append(i) query = [[] for i in range(n)] for i in range(1,n+2): for j in range(len(pos[i])-1): L = pos[i][j] + 1 R = pos[i][j+1] - 1 if L<=R: query[R].append((L,i)) if pos[i]: if pos[i][0]!=0: query[pos[i][0]-1].append((0,i)) if pos[i][-1]!=n-1: query[n-1].append((pos[i][-1]+1,i)) else: query[n-1].append((0,i)) #print(query) flag = [False for i in range(n+3)] init = [-1]*(n+2) init[0] = n lastappeared = SegmentTree(init,min,-1) for i in range(n): lastappeared.update(p[i],i) for l,val in query[i]: check = lastappeared.bisect_l(0,n+2,l-1) #print(l,i,val,check) #pp = [lastappeared.tree[j+lastappeared.num] for j in range(n)] if check>=val or check==-1: flag[val] = True for i in range(1,n+3): if not flag[i]: print(i) break ```
vfc_12958
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1436/E", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n1 3 2\n", "output": "3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n1 4 3 1 2\n", "output": "6\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "51\n45 37 1 8 4 41 35 15 17 2 7 48 20 42 41 5 26 25 37 1 19 43 3 49 33 2 45 43 39 14 1 21 22 17 18 8 49 24 35 26 22 43 45 1 3 17 1 16 35 33 5\n", "output": "5\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "100\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100\n", "output": "102\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
802
Solve the following coding problem using the programming language python: Sergei B., the young coach of Pokemons, has found the big house which consists of n flats ordered in a row from left to right. It is possible to enter each flat from the street. It is possible to go out from each flat. Also, each flat is connected with the flat to the left and the flat to the right. Flat number 1 is only connected with the flat number 2 and the flat number n is only connected with the flat number n - 1. There is exactly one Pokemon of some type in each of these flats. Sergei B. asked residents of the house to let him enter their flats in order to catch Pokemons. After consulting the residents of the house decided to let Sergei B. enter one flat from the street, visit several flats and then go out from some flat. But they won't let him visit the same flat more than once. Sergei B. was very pleased, and now he wants to visit as few flats as possible in order to collect Pokemons of all types that appear in this house. Your task is to help him and determine this minimum number of flats he has to visit. -----Input----- The first line contains the integer n (1 ≤ n ≤ 100 000) — the number of flats in the house. The second line contains the row s with the length n, it consists of uppercase and lowercase letters of English alphabet, the i-th letter equals the type of Pokemon, which is in the flat number i. -----Output----- Print the minimum number of flats which Sergei B. should visit in order to catch Pokemons of all types which there are in the house. -----Examples----- Input 3 AaA Output 2 Input 7 bcAAcbc Output 3 Input 6 aaBCCe Output 5 -----Note----- In the first test Sergei B. can begin, for example, from the flat number 1 and end in the flat number 2. In the second test Sergei B. can begin, for example, from the flat number 4 and end in the flat number 6. In the third test Sergei B. must begin from the flat number 2 and end in the flat number 6. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python from collections import * c=Counter() ans=n=int(input()) s=input() k=len(set(s)) i=j=t=0 while j<n: while len(c)<k and j<n: c[s[j]]+=1; j+=1 while len(c)==k: if j-i<ans: ans=j-i c[s[i]]-=1 if c[s[i]]==0: del c[s[i]] i+=1 print(ans) ```
vfc_12962
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/701/C", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\nAaA\n", "output": "2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "7\nbcAAcbc\n", "output": "3\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
803
Solve the following coding problem using the programming language python: Pasha has many hamsters and he makes them work out. Today, n hamsters (n is even) came to work out. The hamsters lined up and each hamster either sat down or stood up. For another exercise, Pasha needs exactly $\frac{n}{2}$ hamsters to stand up and the other hamsters to sit down. In one minute, Pasha can make some hamster ether sit down or stand up. How many minutes will he need to get what he wants if he acts optimally well? -----Input----- The first line contains integer n (2 ≤ n ≤ 200; n is even). The next line contains n characters without spaces. These characters describe the hamsters' position: the i-th character equals 'X', if the i-th hamster in the row is standing, and 'x', if he is sitting. -----Output----- In the first line, print a single integer — the minimum required number of minutes. In the second line, print a string that describes the hamsters' position after Pasha makes the required changes. If there are multiple optimal positions, print any of them. -----Examples----- Input 4 xxXx Output 1 XxXx Input 2 XX Output 1 xX Input 6 xXXxXx Output 0 xXXxXx The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python n = int(input()) s = list(input()) sit = 0 for i in range(n): if s[i] == 'x': sit += 1 ans = 0 i = 0 while i < n and sit < n - sit: if s[i] == 'X': sit += 1 ans += 1 s[i] = 'x' i += 1 i = 0 while i < n and sit > n - sit: if s[i] == 'x': sit -= 1 ans += 1 s[i] = 'X' i += 1 print(ans) print(''.join(s)) ```
vfc_12966
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/424/A", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\nxxXx\n", "output": "1\nXxXx\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\nXX\n", "output": "1\nxX\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "6\nxXXxXx\n", "output": "0\nxXXxXx\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
804
Solve the following coding problem using the programming language python: Calculate the minimum number of characters you need to change in the string s, so that it contains at least k different letters, or print that it is impossible. String s consists only of lowercase Latin letters, and it is allowed to change characters only to lowercase Latin letters too. -----Input----- First line of input contains string s, consisting only of lowercase Latin letters (1 ≤ |s| ≤ 1000, |s| denotes the length of s). Second line of input contains integer k (1 ≤ k ≤ 26). -----Output----- Print single line with a minimum number of necessary changes, or the word «impossible» (without quotes) if it is impossible. -----Examples----- Input yandex 6 Output 0 Input yahoo 5 Output 1 Input google 7 Output impossible -----Note----- In the first test case string contains 6 different letters, so we don't need to change anything. In the second test case string contains 4 different letters: {'a', 'h', 'o', 'y'}. To get 5 different letters it is necessary to change one occurrence of 'o' to some letter, which doesn't occur in the string, for example, {'b'}. In the third test case, it is impossible to make 7 different letters because the length of the string is 6. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python read = lambda: map(int, input().split()) s = input() k = int(input()) if len(s) < k: print('impossible') else: print(max(0, k - len(set(s)))) ```
vfc_12970
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/844/A", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "yandex\n6\n", "output": "0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "yahoo\n5\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "google\n7\n", "output": "impossible\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
805
Solve the following coding problem using the programming language python: Our old friend Alexey has finally entered the University of City N — the Berland capital. Alexey expected his father to get him a place to live in but his father said it was high time for Alexey to practice some financial independence. So, Alexey is living in a dorm. The dorm has exactly one straight dryer — a 100 centimeter long rope to hang clothes on. The dryer has got a coordinate system installed: the leftmost end of the dryer has coordinate 0, and the opposite end has coordinate 100. Overall, the university has n students. Dean's office allows i-th student to use the segment (l_{i}, r_{i}) of the dryer. However, the dean's office actions are contradictory and now one part of the dryer can belong to multiple students! Alexey don't like when someone touch his clothes. That's why he want make it impossible to someone clothes touch his ones. So Alexey wonders: what is the total length of the parts of the dryer that he may use in a such way that clothes of the others (n - 1) students aren't drying there. Help him! Note that Alexey, as the most respected student, has number 1. -----Input----- The first line contains a positive integer n (1 ≤ n ≤ 100). The (i + 1)-th line contains integers l_{i} and r_{i} (0 ≤ l_{i} < r_{i} ≤ 100) — the endpoints of the corresponding segment for the i-th student. -----Output----- On a single line print a single number k, equal to the sum of lengths of the parts of the dryer which are inside Alexey's segment and are outside all other segments. -----Examples----- Input 3 0 5 2 8 1 6 Output 1 Input 3 0 10 1 5 7 15 Output 3 -----Note----- Note that it's not important are clothes drying on the touching segments (e.g. (0, 1) and (1, 2)) considered to be touching or not because you need to find the length of segments. In the first test sample Alexey may use the only segment (0, 1). In such case his clothes will not touch clothes on the segments (1, 6) and (2, 8). The length of segment (0, 1) is 1. In the second test sample Alexey may dry his clothes on segments (0, 1) and (5, 7). Overall length of these segments is 3. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python N = int(input()) sush = [0] * 101 for i in range(1, N + 1) : l, r = [int(s) for s in input().split()] for j in range(l, r) : sush[j] = (1 if i == 1 else 0) print(str(sum(sush))) ```
vfc_12974
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/397/A", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n0 5\n2 8\n1 6\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n0 10\n1 5\n7 15\n", "output": "3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n0 100\n", "output": "100\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n1 9\n1 9\n", "output": "0\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
806
Solve the following coding problem using the programming language python: Ayoub had an array $a$ of integers of size $n$ and this array had two interesting properties: All the integers in the array were between $l$ and $r$ (inclusive). The sum of all the elements was divisible by $3$. Unfortunately, Ayoub has lost his array, but he remembers the size of the array $n$ and the numbers $l$ and $r$, so he asked you to find the number of ways to restore the array. Since the answer could be very large, print it modulo $10^9 + 7$ (i.e. the remainder when dividing by $10^9 + 7$). In case there are no satisfying arrays (Ayoub has a wrong memory), print $0$. -----Input----- The first and only line contains three integers $n$, $l$ and $r$ ($1 \le n \le 2 \cdot 10^5 , 1 \le l \le r \le 10^9$) — the size of the lost array and the range of numbers in the array. -----Output----- Print the remainder when dividing by $10^9 + 7$ the number of ways to restore the array. -----Examples----- Input 2 1 3 Output 3 Input 3 2 2 Output 1 Input 9 9 99 Output 711426616 -----Note----- In the first example, the possible arrays are : $[1,2], [2,1], [3, 3]$. In the second example, the only possible array is $[2, 2, 2]$. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python MOD = 10**9 + 7 n, l, r = list(map(int, input().split())) lr_counts = [(r-l+1)//3]*3 for i in range(l + sum(lr_counts), r + 1): lr_counts[i % 3] += 1 cur_counts = [1, 0, 0] for _ in range(n): new_counts = [0, 0, 0] for j in range(3): for k in range(3): new_counts[(j + k) % 3] += cur_counts[j] * lr_counts[k] for j in range(3): cur_counts[j] = new_counts[j] % MOD print(cur_counts[0]) ```
vfc_12978
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1105/C", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2 1 3\n", "output": "3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 2 2\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "9 9 99\n", "output": "711426616\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1000 562 6782363\n", "output": "710038164\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "200000 1 1000000000\n", "output": "69063912\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 1 1\n", "output": "0\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
807
Solve the following coding problem using the programming language python: The bear decided to store some raspberry for the winter. He cunningly found out the price for a barrel of honey in kilos of raspberry for each of the following n days. According to the bear's data, on the i-th (1 ≤ i ≤ n) day, the price for one barrel of honey is going to is x_{i} kilos of raspberry. Unfortunately, the bear has neither a honey barrel, nor the raspberry. At the same time, the bear's got a friend who is ready to lend him a barrel of honey for exactly one day for c kilograms of raspberry. That's why the bear came up with a smart plan. He wants to choose some day d (1 ≤ d < n), lent a barrel of honey and immediately (on day d) sell it according to a daily exchange rate. The next day (d + 1) the bear wants to buy a new barrel of honey according to a daily exchange rate (as he's got some raspberry left from selling the previous barrel) and immediately (on day d + 1) give his friend the borrowed barrel of honey as well as c kilograms of raspberry for renting the barrel. The bear wants to execute his plan at most once and then hibernate. What maximum number of kilograms of raspberry can he earn? Note that if at some point of the plan the bear runs out of the raspberry, then he won't execute such a plan. -----Input----- The first line contains two space-separated integers, n and c (2 ≤ n ≤ 100, 0 ≤ c ≤ 100), — the number of days and the number of kilos of raspberry that the bear should give for borrowing the barrel. The second line contains n space-separated integers x_1, x_2, ..., x_{n} (0 ≤ x_{i} ≤ 100), the price of a honey barrel on day i. -----Output----- Print a single integer — the answer to the problem. -----Examples----- Input 5 1 5 10 7 3 20 Output 3 Input 6 2 100 1 10 40 10 40 Output 97 Input 3 0 1 2 3 Output 0 -----Note----- In the first sample the bear will lend a honey barrel at day 3 and then sell it for 7. Then the bear will buy a barrel for 3 and return it to the friend. So, the profit is (7 - 3 - 1) = 3. In the second sample bear will lend a honey barrel at day 1 and then sell it for 100. Then the bear buy the barrel for 1 at the day 2. So, the profit is (100 - 1 - 2) = 97. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python N, C = list(map(int, input().split())) Nums = list(map(int, input().split())) Max = 0 for i in range(N - 1): Max = max(Max, Nums[i] - Nums[i + 1] - C) print(Max) ```
vfc_12982
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/385/A", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5 1\n5 10 7 3 20\n", "output": "3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "6 2\n100 1 10 40 10 40\n", "output": "97\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 0\n1 2 3\n", "output": "0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 0\n2 1\n", "output": "1\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
808
Solve the following coding problem using the programming language python: You are given a positive decimal number x. Your task is to convert it to the "simple exponential notation". Let x = a·10^{b}, where 1 ≤ a < 10, then in general case the "simple exponential notation" looks like "aEb". If b equals to zero, the part "Eb" should be skipped. If a is an integer, it should be written without decimal point. Also there should not be extra zeroes in a and b. -----Input----- The only line contains the positive decimal number x. The length of the line will not exceed 10^6. Note that you are given too large number, so you can't use standard built-in data types "float", "double" and other. -----Output----- Print the only line — the "simple exponential notation" of the given number x. -----Examples----- Input 16 Output 1.6E1 Input 01.23400 Output 1.234 Input .100 Output 1E-1 Input 100. Output 1E2 The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python s = input() if '.' not in s: s = s + '.' p, q = s.strip('0').split('.') if not p: t = q.strip('0') e = len(t) - len(q) - 1 l = t[0] r = t[1:] else: e = len(p) - 1 l = p[0] r = (p[1:] + q).rstrip('0') if l: print(l, end='') else: print(0, end='') if r: print('.' + r, end='') if e: print('E%d' % e) else: print() ```
vfc_12986
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/691/C", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "16\n", "output": "1.6E1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "01.23400\n", "output": "1.234\n", "type": "stdin_stdout" }, { "fn_name": null, "input": ".100\n", "output": "1E-1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "100.\n", "output": "1E2\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
809
Solve the following coding problem using the programming language python: Innokentiy likes tea very much and today he wants to drink exactly n cups of tea. He would be happy to drink more but he had exactly n tea bags, a of them are green and b are black. Innokentiy doesn't like to drink the same tea (green or black) more than k times in a row. Your task is to determine the order of brewing tea bags so that Innokentiy will be able to drink n cups of tea, without drinking the same tea more than k times in a row, or to inform that it is impossible. Each tea bag has to be used exactly once. -----Input----- The first line contains four integers n, k, a and b (1 ≤ k ≤ n ≤ 10^5, 0 ≤ a, b ≤ n) — the number of cups of tea Innokentiy wants to drink, the maximum number of cups of same tea he can drink in a row, the number of tea bags of green and black tea. It is guaranteed that a + b = n. -----Output----- If it is impossible to drink n cups of tea, print "NO" (without quotes). Otherwise, print the string of the length n, which consists of characters 'G' and 'B'. If some character equals 'G', then the corresponding cup of tea should be green. If some character equals 'B', then the corresponding cup of tea should be black. If there are multiple answers, print any of them. -----Examples----- Input 5 1 3 2 Output GBGBG Input 7 2 2 5 Output BBGBGBB Input 4 3 4 0 Output NO The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python n,k,a,b = map(int,input().split()) A = [] per = 0 if a >= b: per=0 while True: if b == 0: if a <=k: A.append('G'*a) break else: per = 1 break else: if a-b>=k-1: a-=k b-=1 A.append('G'*k + 'B') elif a - b > 0: A.append((a-b+1) * 'G' + 'B') a -= (a-b+1) b -= 1 else: A.append('GB' * a) break else: a,b=b,a per=0 while True: if b == 0: if a <=k: A.append('B'*a) break else: per = 1 break else: if a-b>=k-1: a-=k b-=1 A.append('B'*k + 'G') elif a - b > 0: A.append((a-b+1) * 'B' + 'G') a -= (a-b+1) b -= 1 else: A.append('BG' * a) break if per == 1: print('NO') else: print(''.join(map(str,A))) ```
vfc_12990
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/746/D", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5 1 3 2\n", "output": "GBGBG\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "7 2 2 5\n", "output": "BBGBBGB\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 3 4 0\n", "output": "NO\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
810
Solve the following coding problem using the programming language python: Vitaly is a very weird man. He's got two favorite digits a and b. Vitaly calls a positive integer good, if the decimal representation of this integer only contains digits a and b. Vitaly calls a good number excellent, if the sum of its digits is a good number. For example, let's say that Vitaly's favourite digits are 1 and 3, then number 12 isn't good and numbers 13 or 311 are. Also, number 111 is excellent and number 11 isn't. Now Vitaly is wondering, how many excellent numbers of length exactly n are there. As this number can be rather large, he asks you to count the remainder after dividing it by 1000000007 (10^9 + 7). A number's length is the number of digits in its decimal representation without leading zeroes. -----Input----- The first line contains three integers: a, b, n (1 ≤ a < b ≤ 9, 1 ≤ n ≤ 10^6). -----Output----- Print a single integer — the answer to the problem modulo 1000000007 (10^9 + 7). -----Examples----- Input 1 3 3 Output 1 Input 2 3 10 Output 165 The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python ans = 0 mod = 1000000007 a, b, n = list(map(int, input().split())) s = set() for x in range(2, 1 << 8): z = 0 while x > 1: z = z * 10 + (a, b)[x & 1] x >>= 1 s.add(z) f = [1] * (n + 1) for i in range(1, n + 1): f[i] = f[i - 1] * i % mod for x in range(n + 1): if x * a + (n - x) * b in s: ans += pow(f[x] * f[n - x], mod - 2, mod) ans %= mod print(ans * f[n] % mod) ```
vfc_12994
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/300/C", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1 3 3\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 3 10\n", "output": "165\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "6 8 14215\n", "output": "651581472\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
811
Solve the following coding problem using the programming language python: Vasily the Programmer loves romance, so this year he decided to illuminate his room with candles. Vasily has a candles.When Vasily lights up a new candle, it first burns for an hour and then it goes out. Vasily is smart, so he can make b went out candles into a new candle. As a result, this new candle can be used like any other new candle. Now Vasily wonders: for how many hours can his candles light up the room if he acts optimally well? Help him find this number. -----Input----- The single line contains two integers, a and b (1 ≤ a ≤ 1000; 2 ≤ b ≤ 1000). -----Output----- Print a single integer — the number of hours Vasily can light up the room for. -----Examples----- Input 4 2 Output 7 Input 6 3 Output 8 -----Note----- Consider the first sample. For the first four hours Vasily lights up new candles, then he uses four burned out candles to make two new ones and lights them up. When these candles go out (stop burning), Vasily can make another candle. Overall, Vasily can light up the room for 7 hours. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python a, b = map(int, input().split()) k = a x = 0 count = 0 while k > 0: k -= 1 x += 1 if x == b: x = 0 k += 1 count += 1 print(count) ```
vfc_12998
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/379/A", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4 2\n", "output": "7\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "6 3\n", "output": "8\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1000 1000\n", "output": "1001\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "123 5\n", "output": "153\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
813
Solve the following coding problem using the programming language python: Pasha has two hamsters: Arthur and Alexander. Pasha put n apples in front of them. Pasha knows which apples Arthur likes. Similarly, Pasha knows which apples Alexander likes. Pasha doesn't want any conflict between the hamsters (as they may like the same apple), so he decided to distribute the apples between the hamsters on his own. He is going to give some apples to Arthur and some apples to Alexander. It doesn't matter how many apples each hamster gets but it is important that each hamster gets only the apples he likes. It is possible that somebody doesn't get any apples. Help Pasha distribute all the apples between the hamsters. Note that Pasha wants to distribute all the apples, not just some of them. -----Input----- The first line contains integers n, a, b (1 ≤ n ≤ 100; 1 ≤ a, b ≤ n) — the number of apples Pasha has, the number of apples Arthur likes and the number of apples Alexander likes, correspondingly. The next line contains a distinct integers — the numbers of the apples Arthur likes. The next line contains b distinct integers — the numbers of the apples Alexander likes. Assume that the apples are numbered from 1 to n. The input is such that the answer exists. -----Output----- Print n characters, each of them equals either 1 or 2. If the i-h character equals 1, then the i-th apple should be given to Arthur, otherwise it should be given to Alexander. If there are multiple correct answers, you are allowed to print any of them. -----Examples----- Input 4 2 3 1 2 2 3 4 Output 1 1 2 2 Input 5 5 2 3 4 1 2 5 2 3 Output 1 1 1 1 1 The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python n, a, b = list(map(int, input().split())) arthurs = list(map(int, input().split())) alexanders = list(map(int, input().split())) ans = [] for i in range(1, n + 1): if i in arthurs: ans.append('1') else: ans.append('2') print(' '.join(ans)) ```
vfc_13006
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/421/A", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4 2 3\n1 2\n2 3 4\n", "output": "1 1 2 2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 5 2\n3 4 1 2 5\n2 3\n", "output": "1 1 1 1 1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "100 69 31\n1 3 4 5 6 7 8 9 10 11 12 14 15 16 17 18 19 20 21 24 26 27 29 31 37 38 39 40 44 46 48 49 50 51 53 55 56 57 58 59 60 61 63 64 65 66 67 68 69 70 71 72 74 76 77 78 79 80 81 82 83 89 92 94 95 97 98 99 100\n2 13 22 23 25 28 30 32 33 34 35 36 41 42 43 45 47 52 54 62 73 75 84 85 86 87 88 90 91 93 96\n", "output": "1 2 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 2 2 1 2 1 1 2 1 2 1 2 2 2 2 2 1 1 1 1 2 2 2 1 2 1 2 1 1 1 1 2 1 2 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 2 1 2 1 1 1 1 1 1 1 1 2 2 2 2 2 1 2 2 1 2 1 1 2 1 1 1 1\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
814
Solve the following coding problem using the programming language python: Little Chris is bored during his physics lessons (too easy), so he has built a toy box to keep himself occupied. The box is special, since it has the ability to change gravity. There are n columns of toy cubes in the box arranged in a line. The i-th column contains a_{i} cubes. At first, the gravity in the box is pulling the cubes downwards. When Chris switches the gravity, it begins to pull all the cubes to the right side of the box. The figure shows the initial and final configurations of the cubes in the box: the cubes that have changed their position are highlighted with orange. [Image] Given the initial configuration of the toy cubes in the box, find the amounts of cubes in each of the n columns after the gravity switch! -----Input----- The first line of input contains an integer n (1 ≤ n ≤ 100), the number of the columns in the box. The next line contains n space-separated integer numbers. The i-th number a_{i} (1 ≤ a_{i} ≤ 100) denotes the number of cubes in the i-th column. -----Output----- Output n integer numbers separated by spaces, where the i-th number is the amount of cubes in the i-th column after the gravity switch. -----Examples----- Input 4 3 2 1 2 Output 1 2 2 3 Input 3 2 3 8 Output 2 3 8 -----Note----- The first example case is shown on the figure. The top cube of the first column falls to the top of the last column; the top cube of the second column falls to the top of the third column; the middle cube of the first column falls to the top of the second column. In the second example case the gravity switch does not change the heights of the columns. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python cols = int(input()) nums = [int(i) for i in input().split()] nums = sorted(nums) out = "" for num in nums: out=out+str(num)+" " print(out[:-1]) ```
vfc_13010
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/405/A", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n3 2 1 2\n", "output": "1 2 2 3 \n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n2 3 8\n", "output": "2 3 8 \n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n2 1 2 1 2\n", "output": "1 1 2 2 2 \n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n1\n", "output": "1 \n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n4 3\n", "output": "3 4 \n", "type": "stdin_stdout" } ] }
apps
verifiable_code
815
Solve the following coding problem using the programming language python: A family consisting of father bear, mother bear and son bear owns three cars. Father bear can climb into the largest car and he likes it. Also, mother bear can climb into the middle car and she likes it. Moreover, son bear can climb into the smallest car and he likes it. It's known that the largest car is strictly larger than the middle car, and the middle car is strictly larger than the smallest car. Masha came to test these cars. She could climb into all cars, but she liked only the smallest car. It's known that a character with size a can climb into some car with size b if and only if a ≤ b, he or she likes it if and only if he can climb into this car and 2a ≥ b. You are given sizes of bears and Masha. Find out some possible integer non-negative sizes of cars. -----Input----- You are given four integers V_1, V_2, V_3, V_{m}(1 ≤ V_{i} ≤ 100) — sizes of father bear, mother bear, son bear and Masha, respectively. It's guaranteed that V_1 > V_2 > V_3. -----Output----- Output three integers — sizes of father bear's car, mother bear's car and son bear's car, respectively. If there are multiple possible solutions, print any. If there is no solution, print "-1" (without quotes). -----Examples----- Input 50 30 10 10 Output 50 30 10 Input 100 50 10 21 Output -1 -----Note----- In first test case all conditions for cars' sizes are satisfied. In second test case there is no answer, because Masha should be able to climb into smallest car (so size of smallest car in not less than 21), but son bear should like it, so maximum possible size of it is 20. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python v1, v2, v3, vm = [int(k) for k in input().split(' ') if k] minA = max(v3, vm) maxA = 2 * min(v3, vm) if maxA < minA: print(-1) else: a = minA minB = max(v2, a + 1, 2 * vm + 1) maxB = 2 * v2 if maxB < minB: print(-1) return b = minB minC = max(v1, b + 1, 2 * vm + 1) maxC = 2 * v1 if maxC < minC: print(-1) return c = minC print(c) print(b) print(a) ```
vfc_13014
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/904/A", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "50 30 10 10\n", "output": "50\n30\n10\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "100 50 10 21\n", "output": "-1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "100 50 19 10\n", "output": "100\n50\n19\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "99 50 25 49\n", "output": "100\n99\n49\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 2 1 1\n", "output": "4\n3\n1\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
816
Solve the following coding problem using the programming language python: There are some beautiful girls in Arpa’s land as mentioned before. Once Arpa came up with an obvious problem: Given an array and a number x, count the number of pairs of indices i, j (1 ≤ i < j ≤ n) such that $a_{i} \oplus a_{j} = x$, where $\oplus$ is bitwise xor operation (see notes for explanation). [Image] Immediately, Mehrdad discovered a terrible solution that nobody trusted. Now Arpa needs your help to implement the solution to that problem. -----Input----- First line contains two integers n and x (1 ≤ n ≤ 10^5, 0 ≤ x ≤ 10^5) — the number of elements in the array and the integer x. Second line contains n integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10^5) — the elements of the array. -----Output----- Print a single integer: the answer to the problem. -----Examples----- Input 2 3 1 2 Output 1 Input 6 1 5 1 2 3 4 1 Output 2 -----Note----- In the first sample there is only one pair of i = 1 and j = 2. $a_{1} \oplus a_{2} = 3 = x$ so the answer is 1. In the second sample the only two pairs are i = 3, j = 4 (since $2 \oplus 3 = 1$) and i = 1, j = 5 (since $5 \oplus 4 = 1$). A bitwise xor takes two bit integers of equal length and performs the logical xor operation on each pair of corresponding bits. The result in each position is 1 if only the first bit is 1 or only the second bit is 1, but will be 0 if both are 0 or both are 1. You can read more about bitwise xor operation here: https://en.wikipedia.org/wiki/Bitwise_operation#XOR. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python n, x = list(map(int, input().split())) ar = list(map(int, input().split())) cnt = {} ans = 0 for val in ar: cur = val ^ x if cur in cnt: ans += cnt[cur] if val in cnt: cnt[val] += 1 else: cnt[val] = 1 print(ans) ```
vfc_13018
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/742/B", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2 3\n1 2\n", "output": "1", "type": "stdin_stdout" }, { "fn_name": null, "input": "6 1\n5 1 2 3 4 1\n", "output": "2", "type": "stdin_stdout" } ] }
apps
verifiable_code
817
Solve the following coding problem using the programming language python: Some time ago Lesha found an entertaining string $s$ consisting of lowercase English letters. Lesha immediately developed an unique algorithm for this string and shared it with you. The algorithm is as follows. Lesha chooses an arbitrary (possibly zero) number of pairs on positions $(i, i + 1)$ in such a way that the following conditions are satisfied: for each pair $(i, i + 1)$ the inequality $0 \le i < |s| - 1$ holds; for each pair $(i, i + 1)$ the equality $s_i = s_{i + 1}$ holds; there is no index that is contained in more than one pair. After that Lesha removes all characters on indexes contained in these pairs and the algorithm is over. Lesha is interested in the lexicographically smallest strings he can obtain by applying the algorithm to the suffixes of the given string. -----Input----- The only line contains the string $s$ ($1 \le |s| \le 10^5$) — the initial string consisting of lowercase English letters only. -----Output----- In $|s|$ lines print the lengths of the answers and the answers themselves, starting with the answer for the longest suffix. The output can be large, so, when some answer is longer than $10$ characters, instead print the first $5$ characters, then "...", then the last $2$ characters of the answer. -----Examples----- Input abcdd Output 3 abc 2 bc 1 c 0 1 d Input abbcdddeaaffdfouurtytwoo Output 18 abbcd...tw 17 bbcdd...tw 16 bcddd...tw 15 cddde...tw 14 dddea...tw 13 ddeaa...tw 12 deaad...tw 11 eaadf...tw 10 aadfortytw 9 adfortytw 8 dfortytw 9 fdfortytw 8 dfortytw 7 fortytw 6 ortytw 5 rtytw 6 urtytw 5 rtytw 4 tytw 3 ytw 2 tw 1 w 0 1 o -----Note----- Consider the first example. The longest suffix is the whole string "abcdd". Choosing one pair $(4, 5)$, Lesha obtains "abc". The next longest suffix is "bcdd". Choosing one pair $(3, 4)$, we obtain "bc". The next longest suffix is "cdd". Choosing one pair $(2, 3)$, we obtain "c". The next longest suffix is "dd". Choosing one pair $(1, 2)$, we obtain "" (an empty string). The last suffix is the string "d". No pair can be chosen, so the answer is "d". In the second example, for the longest suffix "abbcdddeaaffdfouurtytwoo" choose three pairs $(11, 12)$, $(16, 17)$, $(23, 24)$ and we obtain "abbcdddeaadfortytw" The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python import sys s = input().strip() N = len(s) if len(s) == 1: print(1, s[0]) return X = [s[-1], s[-2]+s[-1] if s[-2]!=s[-1] else ""] Y = [1, 2 if s[-2]!=s[-1] else 0] for i in range(N-3, -1, -1): c = s[i] k1 = c+X[-1] ng = Y[-1]+1 if ng > 10: k1 = k1[:5] + "..." + k1[-2:] if c == s[i+1] and k1 > X[-2]: k1 = X[-2] ng = Y[-2] X.append(k1) Y.append(ng) for i in range(N-1, -1, -1): print(Y[i], X[i]) ```
vfc_13022
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1422/E", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "abcdd\n", "output": "3 abc\n2 bc\n1 c\n0 \n1 d\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
818
Solve the following coding problem using the programming language python: Chilly Willy loves playing with numbers. He only knows prime numbers that are digits yet. These numbers are 2, 3, 5 and 7. But Willy grew rather bored of such numbers, so he came up with a few games that were connected with them. Chilly Willy wants to find the minimum number of length n, such that it is simultaneously divisible by all numbers Willy already knows (2, 3, 5 and 7). Help him with that. A number's length is the number of digits in its decimal representation without leading zeros. -----Input----- A single input line contains a single integer n (1 ≤ n ≤ 10^5). -----Output----- Print a single integer — the answer to the problem without leading zeroes, or "-1" (without the quotes), if the number that meet the problem condition does not exist. -----Examples----- Input 1 Output -1 Input 5 Output 10080 The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python import re import itertools from collections import Counter class Task: n = 0 answer = "" def getData(self): self.n = int(input()) def solve(self): n = self.n if n < 3: self.answer = "-1" return if n == 3: self.answer = "210" return tenRemainders = [1, 3, 2, 6, 4, 5] for x in range(0, 100): if (tenRemainders[(n - 1) % 6] + x * 10) % 7 == 0 and \ (1 + x // 10 + x % 10) % 3 == 0: self.answer = '1' + '0' * (n - 4) self.answer += '0' + str(x) if (x < 10) else str(x) self.answer += '0' return def printAnswer(self): print(self.answer) task = Task(); task.getData(); task.solve(); task.printAnswer(); ```
vfc_13026
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/248/B", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1\n", "output": "-1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n", "output": "10080", "type": "stdin_stdout" }, { "fn_name": null, "input": "6\n", "output": "100170", "type": "stdin_stdout" } ] }
apps
verifiable_code
819
Solve the following coding problem using the programming language python: You are given an array a_1, a_2, ..., a_{n} consisting of n integers, and an integer k. You have to split the array into exactly k non-empty subsegments. You'll then compute the minimum integer on each subsegment, and take the maximum integer over the k obtained minimums. What is the maximum possible integer you can get? Definitions of subsegment and array splitting are given in notes. -----Input----- The first line contains two integers n and k (1 ≤ k ≤ n ≤ 10^5) — the size of the array a and the number of subsegments you have to split the array to. The second line contains n integers a_1, a_2, ..., a_{n} ( - 10^9 ≤ a_{i} ≤ 10^9). -----Output----- Print single integer — the maximum possible integer you can get if you split the array into k non-empty subsegments and take maximum of minimums on the subsegments. -----Examples----- Input 5 2 1 2 3 4 5 Output 5 Input 5 1 -4 -5 -3 -2 -1 Output -5 -----Note----- A subsegment [l, r] (l ≤ r) of array a is the sequence a_{l}, a_{l} + 1, ..., a_{r}. Splitting of array a of n elements into k subsegments [l_1, r_1], [l_2, r_2], ..., [l_{k}, r_{k}] (l_1 = 1, r_{k} = n, l_{i} = r_{i} - 1 + 1 for all i > 1) is k sequences (a_{l}_1, ..., a_{r}_1), ..., (a_{l}_{k}, ..., a_{r}_{k}). In the first example you should split the array into subsegments [1, 4] and [5, 5] that results in sequences (1, 2, 3, 4) and (5). The minimums are min(1, 2, 3, 4) = 1 and min(5) = 5. The resulting maximum is max(1, 5) = 5. It is obvious that you can't reach greater result. In the second example the only option you have is to split the array into one subsegment [1, 5], that results in one sequence ( - 4, - 5, - 3, - 2, - 1). The only minimum is min( - 4, - 5, - 3, - 2, - 1) = - 5. The resulting maximum is - 5. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python n,k = map(int,input().split()) a = list(map(int,input().split())) if k==1: print(min(a)) elif k==2: print(max(a[0],a[-1])) else: print(max(a)) ```
vfc_13030
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/870/B", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5 2\n1 2 3 4 5\n", "output": "5\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 1\n-4 -5 -3 -2 -1\n", "output": "-5\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
820
Solve the following coding problem using the programming language python: Sean is trying to save a large file to a USB flash drive. He has n USB flash drives with capacities equal to a_1, a_2, ..., a_{n} megabytes. The file size is equal to m megabytes. Find the minimum number of USB flash drives needed to write Sean's file, if he can split the file between drives. -----Input----- The first line contains positive integer n (1 ≤ n ≤ 100) — the number of USB flash drives. The second line contains positive integer m (1 ≤ m ≤ 10^5) — the size of Sean's file. Each of the next n lines contains positive integer a_{i} (1 ≤ a_{i} ≤ 1000) — the sizes of USB flash drives in megabytes. It is guaranteed that the answer exists, i. e. the sum of all a_{i} is not less than m. -----Output----- Print the minimum number of USB flash drives to write Sean's file, if he can split the file between drives. -----Examples----- Input 3 5 2 1 3 Output 2 Input 3 6 2 3 2 Output 3 Input 2 5 5 10 Output 1 -----Note----- In the first example Sean needs only two USB flash drives — the first and the third. In the second example Sean needs all three USB flash drives. In the third example Sean needs only one USB flash drive and he can use any available USB flash drive — the first or the second. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python ct = 0 x = int(input()) y = int(input()) z = [int(input()) for i in range(x)] z.sort() z.reverse() for i in z: if y <= 0: print(ct) quit() y-=i ct+=1 print(ct) ```
vfc_13034
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/609/A", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n5\n2\n1\n3\n", "output": "2\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
821
Solve the following coding problem using the programming language python: Two boys decided to compete in text typing on the site "Key races". During the competition, they have to type a text consisting of s characters. The first participant types one character in v_1 milliseconds and has ping t_1 milliseconds. The second participant types one character in v_2 milliseconds and has ping t_2 milliseconds. If connection ping (delay) is t milliseconds, the competition passes for a participant as follows: Exactly after t milliseconds after the start of the competition the participant receives the text to be entered. Right after that he starts to type it. Exactly t milliseconds after he ends typing all the text, the site receives information about it. The winner is the participant whose information on the success comes earlier. If the information comes from both participants at the same time, it is considered that there is a draw. Given the length of the text and the information about participants, determine the result of the game. -----Input----- The first line contains five integers s, v_1, v_2, t_1, t_2 (1 ≤ s, v_1, v_2, t_1, t_2 ≤ 1000) — the number of characters in the text, the time of typing one character for the first participant, the time of typing one character for the the second participant, the ping of the first participant and the ping of the second participant. -----Output----- If the first participant wins, print "First". If the second participant wins, print "Second". In case of a draw print "Friendship". -----Examples----- Input 5 1 2 1 2 Output First Input 3 3 1 1 1 Output Second Input 4 5 3 1 5 Output Friendship -----Note----- In the first example, information on the success of the first participant comes in 7 milliseconds, of the second participant — in 14 milliseconds. So, the first wins. In the second example, information on the success of the first participant comes in 11 milliseconds, of the second participant — in 5 milliseconds. So, the second wins. In the third example, information on the success of the first participant comes in 22 milliseconds, of the second participant — in 22 milliseconds. So, it is be a draw. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python s, v1, v2, t1, t2 = list(map(int, input().split())) a1 = 2 * t1 + s * v1 a2 = 2 * t2 + s * v2 if a1 < a2: print('First') elif a1 > a2: print('Second') else: print('Friendship') ```
vfc_13038
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/835/A", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5 1 2 1 2\n", "output": "First\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 3 1 1 1\n", "output": "Second\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 5 3 1 5\n", "output": "Friendship\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1000 1000 1000 1000 1000\n", "output": "Friendship\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
822
Solve the following coding problem using the programming language python: Comrade Dujikov is busy choosing artists for Timofey's birthday and is recieving calls from Taymyr from Ilia-alpinist. Ilia-alpinist calls every n minutes, i.e. in minutes n, 2n, 3n and so on. Artists come to the comrade every m minutes, i.e. in minutes m, 2m, 3m and so on. The day is z minutes long, i.e. the day consists of minutes 1, 2, ..., z. How many artists should be killed so that there are no artists in the room when Ilia calls? Consider that a call and a talk with an artist take exactly one minute. -----Input----- The only string contains three integers — n, m and z (1 ≤ n, m, z ≤ 10^4). -----Output----- Print single integer — the minimum number of artists that should be killed so that there are no artists in the room when Ilia calls. -----Examples----- Input 1 1 10 Output 10 Input 1 2 5 Output 2 Input 2 3 9 Output 1 -----Note----- Taymyr is a place in the north of Russia. In the first test the artists come each minute, as well as the calls, so we need to kill all of them. In the second test we need to kill artists which come on the second and the fourth minutes. In the third test — only the artist which comes on the sixth minute. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python n, m, z = list(map(int, input().split())) print(sum(1 for t in range(1, z + 1) if t % n == 0 and t % m == 0)) ```
vfc_13042
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/764/A", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1 1 10\n", "output": "10\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 2 5\n", "output": "2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 3 9\n", "output": "1\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
823
Solve the following coding problem using the programming language python: Valera the horse lives on a plane. The Cartesian coordinate system is defined on this plane. Also an infinite spiral is painted on the plane. The spiral consists of segments: [(0, 0), (1, 0)], [(1, 0), (1, 1)], [(1, 1), ( - 1, 1)], [( - 1, 1), ( - 1, - 1)], [( - 1, - 1), (2, - 1)], [(2, - 1), (2, 2)] and so on. Thus, this infinite spiral passes through each integer point of the plane. Valera the horse lives on the plane at coordinates (0, 0). He wants to walk along the spiral to point (x, y). Valera the horse has four legs, so he finds turning very difficult. Count how many times he will have to turn if he goes along a spiral from point (0, 0) to point (x, y). -----Input----- The first line contains two space-separated integers x and y (|x|, |y| ≤ 100). -----Output----- Print a single integer, showing how many times Valera has to turn. -----Examples----- Input 0 0 Output 0 Input 1 0 Output 0 Input 0 1 Output 2 Input -1 -1 Output 3 The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python 3 from math import sin, cos, pi, atan2 x, y = tuple(map(int, input().split())) if (x, y) in ((0, 0), (1, 0)): print(0) elif x >= 1 and -x + 1 < y <= x: print(1 + 4 * (x - 1)) elif x < 0 and x <= y < -x: print(3 + 4 * (-x - 1)) elif y > 0 and -y <= x < y: print(2 + 4 * (y - 1)) else: print(-4 * y) ```
vfc_13046
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/279/A", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "0 0\n", "output": "0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 0\n", "output": "0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "0 1\n", "output": "2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "-1 -1\n", "output": "3\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
824
Solve the following coding problem using the programming language python: As you probably know, Anton goes to school. One of the school subjects that Anton studies is Bracketology. On the Bracketology lessons students usually learn different sequences that consist of round brackets (characters "(" and ")" (without quotes)). On the last lesson Anton learned about the regular simple bracket sequences (RSBS). A bracket sequence s of length n is an RSBS if the following conditions are met: It is not empty (that is n ≠ 0). The length of the sequence is even. First $\frac{n}{2}$ charactes of the sequence are equal to "(". Last $\frac{n}{2}$ charactes of the sequence are equal to ")". For example, the sequence "((()))" is an RSBS but the sequences "((())" and "(()())" are not RSBS. Elena Ivanovna, Anton's teacher, gave him the following task as a homework. Given a bracket sequence s. Find the number of its distinct subsequences such that they are RSBS. Note that a subsequence of s is a string that can be obtained from s by deleting some of its elements. Two subsequences are considered distinct if distinct sets of positions are deleted. Because the answer can be very big and Anton's teacher doesn't like big numbers, she asks Anton to find the answer modulo 10^9 + 7. Anton thought of this task for a very long time, but he still doesn't know how to solve it. Help Anton to solve this task and write a program that finds the answer for it! -----Input----- The only line of the input contains a string s — the bracket sequence given in Anton's homework. The string consists only of characters "(" and ")" (without quotes). It's guaranteed that the string is not empty and its length doesn't exceed 200 000. -----Output----- Output one number — the answer for the task modulo 10^9 + 7. -----Examples----- Input )(()() Output 6 Input ()()() Output 7 Input ))) Output 0 -----Note----- In the first sample the following subsequences are possible: If we delete characters at the positions 1 and 5 (numbering starts with one), we will get the subsequence "(())". If we delete characters at the positions 1, 2, 3 and 4, we will get the subsequence "()". If we delete characters at the positions 1, 2, 4 and 5, we will get the subsequence "()". If we delete characters at the positions 1, 2, 5 and 6, we will get the subsequence "()". If we delete characters at the positions 1, 3, 4 and 5, we will get the subsequence "()". If we delete characters at the positions 1, 3, 5 and 6, we will get the subsequence "()". The rest of the subsequnces are not RSBS. So we got 6 distinct subsequences that are RSBS, so the answer is 6. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python #!/usr/bin/env python3 def ri(): return list(map(int, input().split())) m = 10**9+7 s = input() n = len(s) o = [0 for i in range(len(s))] c = [0 for i in range(len(s))] fac = [0 for i in range(n)] fac[0] = 1 for i in range(1,n): fac[i] = fac[i-1]*i%m invfac = [pow(fac[i], m-2, m) for i in range(n)] if s[0] == '(': o[0] = 1 for i in range(1,n): if s[i] == '(': o[i] = o[i-1] + 1 else: o[i] = o[i-1] if s[n-1] == ')': c[n-1] = 1 for i in range(n-2, -1, -1): if s[i] == ')': c[i] = c[i+1] + 1 else: c[i] = c[i+1] ans = 0 for i in range(n): if s[i] == '(': a = o[i] b = c[i] if a != 0 and b != 0: ans += fac[a+b-1]*invfac[a]*invfac[b-1] ans %= m print(ans) ```
vfc_13050
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/785/D", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": ")(()()\n", "output": "6\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "()()()\n", "output": "7\n", "type": "stdin_stdout" }, { "fn_name": null, "input": ")))\n", "output": "0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": ")())((((((()))()((()))()((()()()((()()()))\n", "output": "4344426\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "(\n", "output": "0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": ")\n", "output": "0\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
828
Solve the following coding problem using the programming language python: There are n workers in a company, each of them has a unique id from 1 to n. Exaclty one of them is a chief, his id is s. Each worker except the chief has exactly one immediate superior. There was a request to each of the workers to tell how how many superiors (not only immediate). Worker's superiors are his immediate superior, the immediate superior of the his immediate superior, and so on. For example, if there are three workers in the company, from which the first is the chief, the second worker's immediate superior is the first, the third worker's immediate superior is the second, then the third worker has two superiors, one of them is immediate and one not immediate. The chief is a superior to all the workers except himself. Some of the workers were in a hurry and made a mistake. You are to find the minimum number of workers that could make a mistake. -----Input----- The first line contains two positive integers n and s (1 ≤ n ≤ 2·10^5, 1 ≤ s ≤ n) — the number of workers and the id of the chief. The second line contains n integers a_1, a_2, ..., a_{n} (0 ≤ a_{i} ≤ n - 1), where a_{i} is the number of superiors (not only immediate) the worker with id i reported about. -----Output----- Print the minimum number of workers that could make a mistake. -----Examples----- Input 3 2 2 0 2 Output 1 Input 5 3 1 0 0 4 1 Output 2 -----Note----- In the first example it is possible that only the first worker made a mistake. Then: the immediate superior of the first worker is the second worker, the immediate superior of the third worker is the first worker, the second worker is the chief. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python n,s = map(int,input().split()) A = list(map(int,input().split())) if A[s-1] != 0: per = 1 A[s-1] = 0 else: per = 0 A.sort() maxs = max(A) ans = [0] * (maxs + 1) answer = maxs + 1 o = -1 for j in range(n): if A[j] == 0: o += 1 if ans[A[j]] == 0: ans[A[j]] = 1 answer -= 1 an = per + max(o, answer) for j in range(n-2,-1,-1): for t in range(A[j+1]-1, A[j] -1,-1): if ans[t] == 0: answer -= 1 an = min(an, per + max(answer,o+n - j - 1)) print(an) ```
vfc_13066
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/729/E", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 2\n2 0 2\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 3\n1 0 0 4 1\n", "output": "2\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
829
Solve the following coding problem using the programming language python: After playing Neo in the legendary "Matrix" trilogy, Keanu Reeves started doubting himself: maybe we really live in virtual reality? To find if this is true, he needs to solve the following problem. Let's call a string consisting of only zeroes and ones good if it contains different numbers of zeroes and ones. For example, 1, 101, 0000 are good, while 01, 1001, and 111000 are not good. We are given a string $s$ of length $n$ consisting of only zeroes and ones. We need to cut $s$ into minimal possible number of substrings $s_1, s_2, \ldots, s_k$ such that all of them are good. More formally, we have to find minimal by number of strings sequence of good strings $s_1, s_2, \ldots, s_k$ such that their concatenation (joining) equals $s$, i.e. $s_1 + s_2 + \dots + s_k = s$. For example, cuttings 110010 into 110 and 010 or into 11 and 0010 are valid, as 110, 010, 11, 0010 are all good, and we can't cut 110010 to the smaller number of substrings as 110010 isn't good itself. At the same time, cutting of 110010 into 1100 and 10 isn't valid as both strings aren't good. Also, cutting of 110010 into 1, 1, 0010 isn't valid, as it isn't minimal, even though all $3$ strings are good. Can you help Keanu? We can show that the solution always exists. If there are multiple optimal answers, print any. -----Input----- The first line of the input contains a single integer $n$ ($1\le n \le 100$) — the length of the string $s$. The second line contains the string $s$ of length $n$ consisting only from zeros and ones. -----Output----- In the first line, output a single integer $k$ ($1\le k$) — a minimal number of strings you have cut $s$ into. In the second line, output $k$ strings $s_1, s_2, \ldots, s_k$ separated with spaces. The length of each string has to be positive. Their concatenation has to be equal to $s$ and all of them have to be good. If there are multiple answers, print any. -----Examples----- Input 1 1 Output 1 1 Input 2 10 Output 2 1 0 Input 6 100011 Output 2 100 011 -----Note----- In the first example, the string 1 wasn't cut at all. As it is good, the condition is satisfied. In the second example, 1 and 0 both are good. As 10 isn't good, the answer is indeed minimal. In the third example, 100 and 011 both are good. As 100011 isn't good, the answer is indeed minimal. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python n = int(input()) s = input().strip() if s.count('0') != s.count('1'): print(1) print(s) else: print(2) print(s[:-1], s[-1]) ```
vfc_13070
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1189/A", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1\n1\n", "output": "1\n1", "type": "stdin_stdout" } ] }
apps
verifiable_code
830
Solve the following coding problem using the programming language python: As you know, all the kids in Berland love playing with cubes. Little Petya has n towers consisting of cubes of the same size. Tower with number i consists of a_{i} cubes stacked one on top of the other. Petya defines the instability of a set of towers as a value equal to the difference between the heights of the highest and the lowest of the towers. For example, if Petya built five cube towers with heights (8, 3, 2, 6, 3), the instability of this set is equal to 6 (the highest tower has height 8, the lowest one has height 2). The boy wants the instability of his set of towers to be as low as possible. All he can do is to perform the following operation several times: take the top cube from some tower and put it on top of some other tower of his set. Please note that Petya would never put the cube on the same tower from which it was removed because he thinks it's a waste of time. Before going to school, the boy will have time to perform no more than k such operations. Petya does not want to be late for class, so you have to help him accomplish this task. -----Input----- The first line contains two space-separated positive integers n and k (1 ≤ n ≤ 100, 1 ≤ k ≤ 1000) — the number of towers in the given set and the maximum number of operations Petya can perform. The second line contains n space-separated positive integers a_{i} (1 ≤ a_{i} ≤ 10^4) — the towers' initial heights. -----Output----- In the first line print two space-separated non-negative integers s and m (m ≤ k). The first number is the value of the minimum possible instability that can be obtained after performing at most k operations, the second number is the number of operations needed for that. In the next m lines print the description of each operation as two positive integers i and j, each of them lies within limits from 1 to n. They represent that Petya took the top cube from the i-th tower and put in on the j-th one (i ≠ j). Note that in the process of performing operations the heights of some towers can become equal to zero. If there are multiple correct sequences at which the minimum possible instability is achieved, you are allowed to print any of them. -----Examples----- Input 3 2 5 8 5 Output 0 2 2 1 2 3 Input 3 4 2 2 4 Output 1 1 3 2 Input 5 3 8 3 2 6 3 Output 3 3 1 3 1 2 1 3 -----Note----- In the first sample you need to move the cubes two times, from the second tower to the third one and from the second one to the first one. Then the heights of the towers are all the same and equal to 6. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python inpt=input().split(' ') n=int(inpt[0]) k=int(inpt[1]) i_lst=[] j_lst=[] m=0 inpt=input().split(' ') for i in range(len(inpt)): inpt[i]=int(inpt[i]) for i in range(k): mn=min(inpt) mx=max(inpt) if mn!=mx: i_mn=inpt.index(mn) i_mx=inpt.index(mx) inpt[i_mn]+=1 inpt[i_mx]-=1 i_lst.append(i_mx) j_lst.append(i_mn) m+=1 else: break #print(inpt) instblity=max(inpt)-min(inpt) print(str(instblity)+' '+str(m)) for i in range(len(i_lst)): print(str(i_lst[i]+1)+' '+str(j_lst[i]+1)) ```
vfc_13074
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/479/B", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 2\n5 8 5\n", "output": "0 2\n2 1\n2 3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 4\n2 2 4\n", "output": "1 4\n3 1\n1 2\n2 1\n1 2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 3\n8 3 2 6 3\n", "output": "3 3\n1 3\n1 2\n1 3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 6\n1 10 8 2\n", "output": "2 6\n2 1\n2 1\n2 4\n3 1\n2 4\n3 1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 3\n2 2 2 2 2\n", "output": "0 0\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
831
Solve the following coding problem using the programming language python: You desperately need to build some string t. For that you've got n more strings s_1, s_2, ..., s_{n}. To build string t, you are allowed to perform exactly |t| (|t| is the length of string t) operations on these strings. Each operation looks like that: choose any non-empty string from strings s_1, s_2, ..., s_{n}; choose an arbitrary character from the chosen string and write it on a piece of paper; remove the chosen character from the chosen string. Note that after you perform the described operation, the total number of characters in strings s_1, s_2, ..., s_{n} decreases by 1. We are assumed to build string t, if the characters, written on the piece of paper, in the order of performed operations form string t. There are other limitations, though. For each string s_{i} you know number a_{i} — the maximum number of characters you are allowed to delete from string s_{i}. You also know that each operation that results in deleting a character from string s_{i}, costs i rubles. That is, an operation on string s_1 is the cheapest (it costs 1 ruble), and the operation on string s_{n} is the most expensive one (it costs n rubles). Your task is to count the minimum amount of money (in rubles) you will need to build string t by the given rules. Consider the cost of building string t to be the sum of prices of the operations you use. -----Input----- The first line of the input contains string t — the string that you need to build. The second line contains a single integer n (1 ≤ n ≤ 100) — the number of strings to which you are allowed to apply the described operation. Each of the next n lines contains a string and an integer. The i-th line contains space-separated string s_{i} and integer a_{i} (0 ≤ a_{i} ≤ 100). Number a_{i} represents the maximum number of characters that can be deleted from string s_{i}. All strings in the input only consist of lowercase English letters. All strings are non-empty. The lengths of all strings do not exceed 100 characters. -----Output----- Print a single number — the minimum money (in rubles) you need in order to build string t. If there is no solution, print -1. -----Examples----- Input bbaze 3 bzb 2 aeb 3 ba 10 Output 8 Input abacaba 4 aba 2 bcc 1 caa 2 bbb 5 Output 18 Input xyz 4 axx 8 za 1 efg 4 t 1 Output -1 -----Note----- Notes to the samples: In the first sample from the first string you should take characters "b" and "z" with price 1 ruble, from the second string characters "a", "e" и "b" with price 2 rubles. The price of the string t in this case is 2·1 + 3·2 = 8. In the second sample from the first string you should take two characters "a" with price 1 ruble, from the second string character "c" with price 2 rubles, from the third string two characters "a" with price 3 rubles, from the fourth string two characters "b" with price 4 rubles. The price of the string t in this case is 2·1 + 1·2 + 2·3 + 2·4 = 18. In the third sample the solution doesn't exist because there is no character "y" in given strings. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python class Edge: def __init__(self, to, cost, capacity, next_edge): self.to = to self.cost = cost self.origin_cost = cost self.capacity = capacity self.next_edge = next_edge self.pair = None class MinCostMaxFlow: def __init__(self, max_node): self.null = Edge(0, 0, 0, None) self.max_node = max_node + 3 self.total_cost = 0 self.current_cost = 0 self.visited = [False] * self.max_node self.arc_list = [] self.edge_head = [self.null] * self.max_node self.source = max_node + 1 self.sink = max_node + 2 def AddArcWithCapacityAndUnitCost(self, start_node, end_node, capacity, cost): self.edge_head[start_node] = Edge(end_node, cost, capacity, self.edge_head[start_node]) self.edge_head[end_node] = Edge(start_node, -cost, 0, self.edge_head[end_node]) self.edge_head[start_node].pair = self.edge_head[end_node] self.edge_head[end_node].pair = self.edge_head[start_node] if start_node != self.source and start_node != self.sink and end_node != self.source and end_node != self.sink: self.arc_list.append(self.edge_head[end_node]) def NumArcs(self): return len(self.arc_list) def Tail(self, index): return self.arc_list[index].to def Head(self, index): return self.arc_list[index].pair.to def UnitCost(self, index): return self.arc_list[index].pair.origin_cost def Flow(self, index): return self.arc_list[index].capacity def OptimalFlow(self): edge = self.edge_head[self.sink] total_flow = 0 while id(edge) != id(self.null): total_flow += edge.capacity edge = edge.next_edge return total_flow def OptimalCost(self): return self.total_cost def SetNodeSupply(self, node, supply): if supply > 0: self.AddArcWithCapacityAndUnitCost(self.source, node, supply, 0) elif supply < 0: self.AddArcWithCapacityAndUnitCost(node, self.sink, -supply, 0) def aug(self, node_id, total_flow): if node_id == self.sink: self.total_cost += self.current_cost * total_flow return total_flow self.visited[node_id] = True flow = total_flow edge = self.edge_head[node_id] while id(edge) != id(self.null): if edge.capacity > 0 and edge.cost == 0 and not self.visited[edge.to]: delta = self.aug(edge.to, min(flow, edge.capacity)) edge.capacity -= delta edge.pair.capacity += delta flow -= delta if flow == 0: return total_flow edge = edge.next_edge return total_flow - flow def modify_label(self): min_cost = 1 << 63 for node_id in range(0, self.max_node): if not self.visited[node_id]: continue edge = self.edge_head[node_id] while id(edge) != id(self.null): if edge.capacity > 0 and not self.visited[edge.to] and edge.cost < min_cost: min_cost = edge.cost edge = edge.next_edge if min_cost == 1 << 63: return False for node_id in range(0, self.max_node): if not self.visited[node_id]: continue edge = self.edge_head[node_id] while id(edge) != id(self.null): edge.cost -= min_cost edge.pair.cost += min_cost edge = edge.next_edge self.current_cost += min_cost return True def Solve(self): while True: while True: self.visited = [False] * self.max_node if self.aug(self.source, 1 << 63) == 0: break if not self.modify_label(): break return self.total_cost def main(): s = input() n = int(input()) source = 0 sink = n + 26 + 1 mcmf = MinCostMaxFlow(n + 28) length = len(s) num = [0] * 29 for i in range(0, length): num[ord(s[i]) - ord('a') + 1] += 1 for i in range(1, 27): if num[i] > 0: mcmf.AddArcWithCapacityAndUnitCost(i, sink, num[i], 0) for i in range(1, n + 1): s, used = input().split(' ') mcmf.AddArcWithCapacityAndUnitCost(source, 26 + i, int(used), 0) num = [0] * 29 for j in range(0, len(s)): num[ord(s[j]) - ord('a') + 1] += 1 for j in range(1, 27): if num[j] > 0: mcmf.AddArcWithCapacityAndUnitCost(26 + i, j, num[j], i) mcmf.SetNodeSupply(source, 1 << 63) mcmf.SetNodeSupply(sink, -(1 << 63)) mcmf.Solve() if mcmf.OptimalFlow() != length: print("-1") else: print(mcmf.OptimalCost()) def __starting_point(): main() __starting_point() ```
vfc_13078
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/237/E", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "bbaze\n3\nbzb 2\naeb 3\nba 10\n", "output": "8\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
832
Solve the following coding problem using the programming language python: Manao works on a sports TV. He's spent much time watching the football games of some country. After a while he began to notice different patterns. For example, each team has two sets of uniforms: home uniform and guest uniform. When a team plays a game at home, the players put on the home uniform. When a team plays as a guest on somebody else's stadium, the players put on the guest uniform. The only exception to that rule is: when the home uniform color of the host team matches the guests' uniform, the host team puts on its guest uniform as well. For each team the color of the home and guest uniform is different. There are n teams taking part in the national championship. The championship consists of n·(n - 1) games: each team invites each other team to its stadium. At this point Manao wondered: how many times during the championship is a host team going to put on the guest uniform? Note that the order of the games does not affect this number. You know the colors of the home and guest uniform for each team. For simplicity, the colors are numbered by integers in such a way that no two distinct colors have the same number. Help Manao find the answer to his question. -----Input----- The first line contains an integer n (2 ≤ n ≤ 30). Each of the following n lines contains a pair of distinct space-separated integers h_{i}, a_{i} (1 ≤ h_{i}, a_{i} ≤ 100) — the colors of the i-th team's home and guest uniforms, respectively. -----Output----- In a single line print the number of games where the host team is going to play in the guest uniform. -----Examples----- Input 3 1 2 2 4 3 4 Output 1 Input 4 100 42 42 100 5 42 100 5 Output 5 Input 2 1 2 1 2 Output 0 -----Note----- In the first test case the championship consists of 6 games. The only game with the event in question is the game between teams 2 and 1 on the stadium of team 2. In the second test sample the host team will have to wear guest uniform in the games between teams: 1 and 2, 2 and 1, 2 and 3, 3 and 4, 4 and 2 (the host team is written first). The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python n = int( input().split()[0] ) answer = 0 h = [] a = [] for i in range( 0, n ): team = input().split() h.append( int( team[0] ) ) a.append( int( team[1] ) ) for i in range( 0, n ): for j in range( 0, n ): if i == j: continue if h[i] == a[j]: answer += 1 print( answer ) ```
vfc_13082
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/268/A", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n1 2\n2 4\n3 4\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n100 42\n42 100\n5 42\n100 5\n", "output": "5\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
833
Solve the following coding problem using the programming language python: Valera loves his garden, where n fruit trees grow. This year he will enjoy a great harvest! On the i-th tree b_{i} fruit grow, they will ripen on a day number a_{i}. Unfortunately, the fruit on the tree get withered, so they can only be collected on day a_{i} and day a_{i} + 1 (all fruits that are not collected in these two days, become unfit to eat). Valera is not very fast, but there are some positive points. Valera is ready to work every day. In one day, Valera can collect no more than v fruits. The fruits may be either from the same tree, or from different ones. What is the maximum amount of fruit Valera can collect for all time, if he operates optimally well? -----Input----- The first line contains two space-separated integers n and v (1 ≤ n, v ≤ 3000) — the number of fruit trees in the garden and the number of fruits that Valera can collect in a day. Next n lines contain the description of trees in the garden. The i-th line contains two space-separated integers a_{i} and b_{i} (1 ≤ a_{i}, b_{i} ≤ 3000) — the day the fruits ripen on the i-th tree and the number of fruits on the i-th tree. -----Output----- Print a single integer — the maximum number of fruit that Valera can collect. -----Examples----- Input 2 3 1 5 2 3 Output 8 Input 5 10 3 20 2 20 1 20 4 20 5 20 Output 60 -----Note----- In the first sample, in order to obtain the optimal answer, you should act as follows. On the first day collect 3 fruits from the 1-st tree. On the second day collect 1 fruit from the 2-nd tree and 2 fruits from the 1-st tree. On the third day collect the remaining fruits from the 2-nd tree. In the second sample, you can only collect 60 fruits, the remaining fruit will simply wither. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python """ Codeforces Round 252 Div 2 Problem B Author : chaotic_iak Language: Python 3.3.4 """ def read(mode=2): # 0: String # 1: List of strings # 2: List of integers inputs = input().strip() if mode == 0: return inputs if mode == 1: return inputs.split() if mode == 2: return [int(x) for x in inputs.split()] def write(s="\n"): if isinstance(s, list): s = " ".join(s) s = str(s) print(s, end="") ################################################### SOLUTION n,v = read() a = [] for i in range(n): a.append(read()) a.sort(key=lambda x: x[0]) res = 0 for day in range(1, 3002): n = 0 while a and a[0][0] <= day: if a[0][1] <= v-n: n += a[0][1] a[0][1] = 0 else: a[0][1] -= v-n n = v if a[0][1] == 0: a.pop(0) else: break while a and a[0][0] == day-1: a.pop(0) res += n print(res) ```
vfc_13086
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/441/B", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2 3\n1 5\n2 3\n", "output": "8\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 10\n3 20\n2 20\n1 20\n4 20\n5 20\n", "output": "60\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "10 3000\n1 2522\n4 445\n8 1629\n5 772\n9 2497\n6 81\n3 426\n7 1447\n2 575\n10 202\n", "output": "10596\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 3000\n5 772\n1 2522\n2 575\n4 445\n3 426\n", "output": "4740\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 1500\n2 575\n1 2522\n", "output": "3097\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "12 2856\n9 2728\n8 417\n3 1857\n10 1932\n1 775\n12 982\n9 1447\n1 426\n7 2918\n11 2522\n10 2497\n9 772\n", "output": "18465\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
834
Solve the following coding problem using the programming language python: Some time ago Leonid have known about idempotent functions. Idempotent function defined on a set {1, 2, ..., n} is such function $g : \{1,2, \ldots, n \} \rightarrow \{1,2, \ldots, n \}$, that for any $x \in \{1,2, \ldots, n \}$ the formula g(g(x)) = g(x) holds. Let's denote as f^{(}k)(x) the function f applied k times to the value x. More formally, f^{(1)}(x) = f(x), f^{(}k)(x) = f(f^{(}k - 1)(x)) for each k > 1. You are given some function $f : \{1,2, \ldots, n \} \rightarrow \{1,2, \ldots, n \}$. Your task is to find minimum positive integer k such that function f^{(}k)(x) is idempotent. -----Input----- In the first line of the input there is a single integer n (1 ≤ n ≤ 200) — the size of function f domain. In the second line follow f(1), f(2), ..., f(n) (1 ≤ f(i) ≤ n for each 1 ≤ i ≤ n), the values of a function. -----Output----- Output minimum k such that function f^{(}k)(x) is idempotent. -----Examples----- Input 4 1 2 2 4 Output 1 Input 3 2 3 3 Output 2 Input 3 2 3 1 Output 3 -----Note----- In the first sample test function f(x) = f^{(1)}(x) is already idempotent since f(f(1)) = f(1) = 1, f(f(2)) = f(2) = 2, f(f(3)) = f(3) = 2, f(f(4)) = f(4) = 4. In the second sample test: function f(x) = f^{(1)}(x) isn't idempotent because f(f(1)) = 3 but f(1) = 2; function f(x) = f^{(2)}(x) is idempotent since for any x it is true that f^{(2)}(x) = 3, so it is also true that f^{(2)}(f^{(2)}(x)) = 3. In the third sample test: function f(x) = f^{(1)}(x) isn't idempotent because f(f(1)) = 3 but f(1) = 2; function f(f(x)) = f^{(2)}(x) isn't idempotent because f^{(2)}(f^{(2)}(1)) = 2 but f^{(2)}(1) = 3; function f(f(f(x))) = f^{(3)}(x) is idempotent since it is identity function: f^{(3)}(x) = x for any $x \in \{1,2,3 \}$ meaning that the formula f^{(3)}(f^{(3)}(x)) = f^{(3)}(x) also holds. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python n = int(input()) f = list(map(int, input().split())) for i in range(n): f[i] -= 1 def gcd(a, b): while (a != 0 and b != 0): a, b = b, a % b return a + b def lcm(a, b): return a * b // gcd(a, b) ans = 1 minn = 0 for i in range(n): vis = [False] * n cur = i st, pr = 0, 0 while not vis[cur]: vis[cur] = True cur = f[cur] st += 1 fs = cur cur = i while cur != fs: pr += 1 cur = f[cur] minn = max(minn, pr) ans = lcm(ans, st - pr) print(((max(0, minn - 1))// ans + 1) * ans) ```
vfc_13090
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/541/C", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n1 2 2 4\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n2 3 3\n", "output": "2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n2 3 1\n", "output": "3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n1\n", "output": "1\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
835
Solve the following coding problem using the programming language python: Polycarpus loves hamburgers very much. He especially adores the hamburgers he makes with his own hands. Polycarpus thinks that there are only three decent ingredients to make hamburgers from: a bread, sausage and cheese. He writes down the recipe of his favorite "Le Hamburger de Polycarpus" as a string of letters 'B' (bread), 'S' (sausage) и 'C' (cheese). The ingredients in the recipe go from bottom to top, for example, recipe "ВSCBS" represents the hamburger where the ingredients go from bottom to top as bread, sausage, cheese, bread and sausage again. Polycarpus has n_{b} pieces of bread, n_{s} pieces of sausage and n_{c} pieces of cheese in the kitchen. Besides, the shop nearby has all three ingredients, the prices are p_{b} rubles for a piece of bread, p_{s} for a piece of sausage and p_{c} for a piece of cheese. Polycarpus has r rubles and he is ready to shop on them. What maximum number of hamburgers can he cook? You can assume that Polycarpus cannot break or slice any of the pieces of bread, sausage or cheese. Besides, the shop has an unlimited number of pieces of each ingredient. -----Input----- The first line of the input contains a non-empty string that describes the recipe of "Le Hamburger de Polycarpus". The length of the string doesn't exceed 100, the string contains only letters 'B' (uppercase English B), 'S' (uppercase English S) and 'C' (uppercase English C). The second line contains three integers n_{b}, n_{s}, n_{c} (1 ≤ n_{b}, n_{s}, n_{c} ≤ 100) — the number of the pieces of bread, sausage and cheese on Polycarpus' kitchen. The third line contains three integers p_{b}, p_{s}, p_{c} (1 ≤ p_{b}, p_{s}, p_{c} ≤ 100) — the price of one piece of bread, sausage and cheese in the shop. Finally, the fourth line contains integer r (1 ≤ r ≤ 10^12) — the number of rubles Polycarpus has. Please, do not write the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier. -----Output----- Print the maximum number of hamburgers Polycarpus can make. If he can't make any hamburger, print 0. -----Examples----- Input BBBSSC 6 4 1 1 2 3 4 Output 2 Input BBC 1 10 1 1 10 1 21 Output 7 Input BSC 1 1 1 1 1 3 1000000000000 Output 200000000001 The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python def main(): s = input() a = b = c = 0 for elem in s: if elem == "B": a += 1 elif elem == "S": b += 1 else: c += 1 na, nb, nc = map(int, input().split()) pa, pb, pc = map(int, input().split()) k = int(input()) l = 0 r = 10**13 while r - l > 1: m = (l + r) // 2 cntA = max(0, a * m - na) cntB = max(0, b * m - nb) cntC = max(0, c * m - nc) money = cntA * pa + cntB * pb + cntC * pc if money <= k: l = m else: r = m print(l) main() ```
vfc_13094
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/371/C", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "BBBSSC\n6 4 1\n1 2 3\n4\n", "output": "2\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
836
Solve the following coding problem using the programming language python: For he knew every Who down in Whoville beneath, Was busy now, hanging a mistletoe wreath. "And they're hanging their stockings!" he snarled with a sneer, "Tomorrow is Christmas! It's practically here!"Dr. Suess, How The Grinch Stole Christmas Christmas celebrations are coming to Whoville. Cindy Lou Who and her parents Lou Lou Who and Betty Lou Who decided to give sweets to all people in their street. They decided to give the residents of each house on the street, one kilogram of sweets. So they need as many kilos of sweets as there are homes on their street. The street, where the Lou Who family lives can be represented as n consecutive sections of equal length. You can go from any section to a neighbouring one in one unit of time. Each of the sections is one of three types: an empty piece of land, a house or a shop. Cindy Lou and her family can buy sweets in a shop, but no more than one kilogram of sweets in one shop (the vendors care about the residents of Whoville not to overeat on sweets). After the Lou Who family leave their home, they will be on the first section of the road. To get to this section of the road, they also require one unit of time. We can assume that Cindy and her mom and dad can carry an unlimited number of kilograms of sweets. Every time they are on a house section, they can give a kilogram of sweets to the inhabitants of the house, or they can simply move to another section. If the family have already given sweets to the residents of a house, they can't do it again. Similarly, if they are on the shop section, they can either buy a kilo of sweets in it or skip this shop. If they've bought a kilo of sweets in a shop, the seller of the shop remembered them and the won't sell them a single candy if they come again. The time to buy and give sweets can be neglected. The Lou Whos do not want the people of any house to remain without food. The Lou Whos want to spend no more than t time units of time to give out sweets, as they really want to have enough time to prepare for the Christmas celebration. In order to have time to give all the sweets, they may have to initially bring additional k kilos of sweets. Cindy Lou wants to know the minimum number of k kilos of sweets they need to take with them, to have time to give sweets to the residents of each house in their street. Your task is to write a program that will determine the minimum possible value of k. -----Input----- The first line of the input contains two space-separated integers n and t (2 ≤ n ≤ 5·10^5, 1 ≤ t ≤ 10^9). The second line of the input contains n characters, the i-th of them equals "H" (if the i-th segment contains a house), "S" (if the i-th segment contains a shop) or "." (if the i-th segment doesn't contain a house or a shop). It is guaranteed that there is at least one segment with a house. -----Output----- If there isn't a single value of k that makes it possible to give sweets to everybody in at most t units of time, print in a single line "-1" (without the quotes). Otherwise, print on a single line the minimum possible value of k. -----Examples----- Input 6 6 HSHSHS Output 1 Input 14 100 ...HHHSSS...SH Output 0 Input 23 50 HHSS.......SSHHHHHHHHHH Output 8 -----Note----- In the first example, there are as many stores, as houses. If the family do not take a single kilo of sweets from home, in order to treat the inhabitants of the first house, they will need to make at least one step back, and they have absolutely no time for it. If they take one kilogram of sweets, they won't need to go back. In the second example, the number of shops is equal to the number of houses and plenty of time. Available at all stores passing out candy in one direction and give them when passing in the opposite direction. In the third example, the shops on the street are fewer than houses. The Lou Whos have to take the missing number of kilograms of sweets with them from home. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python def check(n, casas): #print('n:',n) nonlocal T,N,street current = n time = T need = 0 last_house = 0 for ind, i in enumerate(street): time -= 1 if i == 'S': current += 1 elif i == 'H': need += 1 if need == 1: last_house = ind if need > 0 and current >= need: #print('p',time, ind-last_house) current -= need casas -= need need = 0 if casas > 0: if (ind-last_house)*2 >= N-last_house-1: time -= N-last_house-1 + N-ind-1 return time >= 0 time -= (ind-last_house)*2 else: time -= ind-last_house #print('lugar:',i,ind,current, time, need, last_house) if casas == 0: break #print(time) return time >= 0 and casas == 0 N,T = [int(i) for i in input().split()] street = input().rstrip('.') N = len(street) C = street.count('H') S = street.count('S') l = max(C-S, 0) r = 500005 #print(N, C) while l < r: mid = (l+r)//2 if check(mid, C): r = mid else: l = mid + 1 print(l if l < 500005 else -1) ```
vfc_13098
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/248/D", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "6 6\nHSHSHS\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "14 100\n...HHHSSS...SH\n", "output": "0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "23 50\nHHSS.......SSHHHHHHHHHH\n", "output": "8\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
837
Solve the following coding problem using the programming language python: zscoder wants to generate an input file for some programming competition problem. His input is a string consisting of n letters 'a'. He is too lazy to write a generator so he will manually generate the input in a text editor. Initially, the text editor is empty. It takes him x seconds to insert or delete a letter 'a' from the text file and y seconds to copy the contents of the entire text file, and duplicate it. zscoder wants to find the minimum amount of time needed for him to create the input file of exactly n letters 'a'. Help him to determine the amount of time needed to generate the input. -----Input----- The only line contains three integers n, x and y (1 ≤ n ≤ 10^7, 1 ≤ x, y ≤ 10^9) — the number of letters 'a' in the input file and the parameters from the problem statement. -----Output----- Print the only integer t — the minimum amount of time needed to generate the input file. -----Examples----- Input 8 1 1 Output 4 Input 8 1 10 Output 8 The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python def recursion(n): if n == 1: return x if n == 2: return x + min(x , y) if n % 2 == 0: return recursion(n // 2) + min(y, x * (n - n//2)) else: return min(recursion(n + 1), recursion(n - 1)) + x import sys sys.setrecursionlimit(10000000) n, x, y = list(map(int, input().split())) print(recursion(n)) ```
vfc_13102
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/710/E", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "8 1 1\n", "output": "4\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "8 1 10\n", "output": "8\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "10 62 99\n", "output": "384\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "88 417 591\n", "output": "4623\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "57 5289 8444\n", "output": "60221\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "382 81437847 324871127\n", "output": "2519291691\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
838
Solve the following coding problem using the programming language python: You are given n × m table. Each cell of the table is colored white or black. Find the number of non-empty sets of cells such that: All cells in a set have the same color. Every two cells in a set share row or column. -----Input----- The first line of input contains integers n and m (1 ≤ n, m ≤ 50) — the number of rows and the number of columns correspondingly. The next n lines of input contain descriptions of rows. There are m integers, separated by spaces, in each line. The number equals 0 if the corresponding cell is colored white and equals 1 if the corresponding cell is colored black. -----Output----- Output single integer  — the number of non-empty sets from the problem description. -----Examples----- Input 1 1 0 Output 1 Input 2 3 1 0 1 0 1 0 Output 8 -----Note----- In the second example, there are six one-element sets. Additionally, there are two two-element sets, the first one consists of the first and the third cells of the first row, the second one consists of the first and the third cells of the second row. To sum up, there are 8 sets. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python read = lambda: map(int, input().split()) n, m = read() a = [list(read()) for i in range(n)] ans = n * m for i in range(n): cnt0 = a[i].count(0) cnt1 = a[i].count(1) if cnt0 > 1: ans += (2 ** cnt0 - cnt0 - 1) if cnt1 > 1: ans += (2 ** cnt1 - cnt1 - 1) for i in range(m): cnt0 = sum(a[j][i] == 0 for j in range(n)) cnt1 = sum(a[j][i] == 1 for j in range(n)) if cnt0 > 1: ans += (2 ** cnt0 - cnt0 - 1) if cnt1 > 1: ans += (2 ** cnt1 - cnt1 - 1) print(ans) ```
vfc_13106
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/844/B", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1 1\n0\n", "output": "1\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
842
Solve the following coding problem using the programming language python: Pari has a friend who loves palindrome numbers. A palindrome number is a number that reads the same forward or backward. For example 12321, 100001 and 1 are palindrome numbers, while 112 and 1021 are not. Pari is trying to love them too, but only very special and gifted people can understand the beauty behind palindrome numbers. Pari loves integers with even length (i.e. the numbers with even number of digits), so she tries to see a lot of big palindrome numbers with even length (like a 2-digit 11 or 6-digit 122221), so maybe she could see something in them. Now Pari asks you to write a program that gets a huge integer n from the input and tells what is the n-th even-length positive palindrome number? -----Input----- The only line of the input contains a single integer n (1 ≤ n ≤ 10^{100 000}). -----Output----- Print the n-th even-length palindrome number. -----Examples----- Input 1 Output 11 Input 10 Output 1001 -----Note----- The first 10 even-length palindrome numbers are 11, 22, 33, ... , 88, 99 and 1001. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python n = input() print(n+n[::-1]) ```
vfc_13122
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/688/B", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1\n", "output": "11\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
843
Solve the following coding problem using the programming language python: Little Artem found a grasshopper. He brought it to his house and constructed a jumping area for him. The area looks like a strip of cells 1 × n. Each cell contains the direction for the next jump and the length of that jump. Grasshopper starts in the first cell and follows the instructions written on the cells. Grasshopper stops immediately if it jumps out of the strip. Now Artem wants to find out if this will ever happen. -----Input----- The first line of the input contains a single integer n (1 ≤ n ≤ 100 000) — length of the strip. Next line contains a string of length n which consists of characters "<" and ">" only, that provide the direction of the jump from the corresponding cell. Next line contains n integers d_{i} (1 ≤ d_{i} ≤ 10^9) — the length of the jump from the i-th cell. -----Output----- Print "INFINITE" (without quotes) if grasshopper will continue his jumps forever. Otherwise print "FINITE" (without quotes). -----Examples----- Input 2 >< 1 2 Output FINITE Input 3 >>< 2 1 1 Output INFINITE -----Note----- In the first sample grasshopper starts from the first cell and jumps to the right on the next cell. When he is in the second cell he needs to jump two cells left so he will jump out of the strip. Second sample grasshopper path is 1 - 3 - 2 - 3 - 2 - 3 and so on. The path is infinite. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python n = int(input()) s = list([1 if x == '>' else -1 for x in input().strip()]) d = list(map(int, input().strip().split())) b = [False for _ in range(n)] c = 0 while True: c += s[c] * d[c] if c >= n or c < 0: print('FINITE') return if b[c]: print('INFINITE') return b[c] = True ```
vfc_13126
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/641/A", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n><\n1 2\n", "output": "FINITE\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
844
Solve the following coding problem using the programming language python: You are given a string s consisting only of characters 0 and 1. A substring [l, r] of s is a string s_{l}s_{l} + 1s_{l} + 2... s_{r}, and its length equals to r - l + 1. A substring is called balanced if the number of zeroes (0) equals to the number of ones in this substring. You have to determine the length of the longest balanced substring of s. -----Input----- The first line contains n (1 ≤ n ≤ 100000) — the number of characters in s. The second line contains a string s consisting of exactly n characters. Only characters 0 and 1 can appear in s. -----Output----- If there is no non-empty balanced substring in s, print 0. Otherwise, print the length of the longest balanced substring. -----Examples----- Input 8 11010111 Output 4 Input 3 111 Output 0 -----Note----- In the first example you can choose the substring [3, 6]. It is balanced, and its length is 4. Choosing the substring [2, 5] is also possible. In the second example it's impossible to find a non-empty balanced substring. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python '''input 8 11010111 ''' n = int(input()) s = input() a = [0] d = {0:0} for i in range(n): if s[i] == '1': a.append(a[-1]+1) else: a.append(a[-1]-1) if a[i+1] not in d: d[a[i+1]] = i+1 ans = 0 for i in range(1,n+1): ans = max(ans,i-d[a[i]]) print(ans) ```
vfc_13130
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/873/B", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "8\n11010111\n", "output": "4\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n111\n", "output": "0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "11\n00001000100\n", "output": "2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "10\n0100000000\n", "output": "2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "13\n0001000011010\n", "output": "6\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "14\n00000100101011\n", "output": "10\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
845
Solve the following coding problem using the programming language python: Our good friend Mole is trying to code a big message. He is typing on an unusual keyboard with characters arranged in following way: qwertyuiop asdfghjkl; zxcvbnm,./ Unfortunately Mole is blind, so sometimes it is problem for him to put his hands accurately. He accidentally moved both his hands with one position to the left or to the right. That means that now he presses not a button he wants, but one neighboring button (left or right, as specified in input). We have a sequence of characters he has typed and we want to find the original message. -----Input----- First line of the input contains one letter describing direction of shifting ('L' or 'R' respectively for left or right). Second line contains a sequence of characters written by Mole. The size of this sequence will be no more than 100. Sequence contains only symbols that appear on Mole's keyboard. It doesn't contain spaces as there is no space on Mole's keyboard. It is guaranteed that even though Mole hands are moved, he is still pressing buttons on keyboard and not hitting outside it. -----Output----- Print a line that contains the original message. -----Examples----- Input R s;;upimrrfod;pbr Output allyouneedislove The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python s=[] s.append("qwertyuiop") s.append("asdfghjkl;") s.append("zxcvbnm,./") x=input() y=input() for item in y: for i in range(3): for j in range(len(s[i])): if(s[i][j]==item): if(x=='R'): print(s[i][j-1],end="") else: print(s[i][j+1],end="") print() ```
vfc_13134
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/474/A", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "R\ns;;upimrrfod;pbr\n", "output": "allyouneedislove\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "R\nwertyuiop;lkjhgfdsxcvbnm,.\n", "output": "qwertyuiolkjhgfdsazxcvbnm,\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "L\nzxcvbnm,kjhgfdsaqwertyuio\n", "output": "xcvbnm,.lkjhgfdswertyuiop\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "R\nbubbuduppudup\n", "output": "vyvvysyooysyo\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
846
Solve the following coding problem using the programming language python: Mashmokh works in a factory. At the end of each day he must turn off all of the lights. The lights on the factory are indexed from 1 to n. There are n buttons in Mashmokh's room indexed from 1 to n as well. If Mashmokh pushes button with index i, then each light with index not less than i that is still turned on turns off. Mashmokh is not very clever. So instead of pushing the first button he pushes some of the buttons randomly each night. He pushed m distinct buttons b_1, b_2, ..., b_{m} (the buttons were pushed consecutively in the given order) this night. Now he wants to know for each light the index of the button that turned this light off. Please note that the index of button b_{i} is actually b_{i}, not i. Please, help Mashmokh, print these indices. -----Input----- The first line of the input contains two space-separated integers n and m (1 ≤ n, m ≤ 100), the number of the factory lights and the pushed buttons respectively. The next line contains m distinct space-separated integers b_1, b_2, ..., b_{m} (1 ≤ b_{i} ≤ n). It is guaranteed that all lights will be turned off after pushing all buttons. -----Output----- Output n space-separated integers where the i-th number is index of the button that turns the i-th light off. -----Examples----- Input 5 4 4 3 1 2 Output 1 1 3 4 4 Input 5 5 5 4 3 2 1 Output 1 2 3 4 5 -----Note----- In the first sample, after pressing button number 4, lights 4 and 5 are turned off and lights 1, 2 and 3 are still on. Then after pressing button number 3, light number 3 is turned off as well. Pressing button number 1 turns off lights number 1 and 2 as well so pressing button number 2 in the end has no effect. Thus button number 4 turned lights 4 and 5 off, button number 3 turned light 3 off and button number 1 turned light 1 and 2 off. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python n, m = map(int,input().split()) b = list(map(int,input().split())) ans = [-1]*101 for bb in b: for i in range(bb,n+1): if ans[i]==-1: ans[i]=bb print(*ans[1:n+1]) ```
vfc_13138
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/415/A", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5 4\n4 3 1 2\n", "output": "1 1 3 4 4 \n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 5\n5 4 3 2 1\n", "output": "1 2 3 4 5 \n", "type": "stdin_stdout" } ] }
apps
verifiable_code
847
Solve the following coding problem using the programming language python: Vanya loves playing. He even has a special set of cards to play with. Each card has a single integer. The number on the card can be positive, negative and can even be equal to zero. The only limit is, the number on each card doesn't exceed x in the absolute value. Natasha doesn't like when Vanya spends a long time playing, so she hid all of his cards. Vanya became sad and started looking for the cards but he only found n of them. Vanya loves the balance, so he wants the sum of all numbers on found cards equal to zero. On the other hand, he got very tired of looking for cards. Help the boy and say what is the minimum number of cards does he need to find to make the sum equal to zero? You can assume that initially Vanya had infinitely many cards with each integer number from - x to x. -----Input----- The first line contains two integers: n (1 ≤ n ≤ 1000) — the number of found cards and x (1 ≤ x ≤ 1000) — the maximum absolute value of the number on a card. The second line contains n space-separated integers — the numbers on found cards. It is guaranteed that the numbers do not exceed x in their absolute value. -----Output----- Print a single number — the answer to the problem. -----Examples----- Input 3 2 -1 1 2 Output 1 Input 2 3 -2 -2 Output 2 -----Note----- In the first sample, Vanya needs to find a single card with number -2. In the second sample, Vanya needs to find two cards with number 2. He can't find a single card with the required number as the numbers on the lost cards do not exceed 3 in their absolute value. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python n,x=list(map(int,input().split())) L=list(map(int,input().split())) s=sum(L) s=abs(s) ans=0 while(s>0): s-=x ans+=1 print(ans) ```
vfc_13142
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/401/A", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 2\n-1 1 2\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 3\n-2 -2\n", "output": "2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 4\n1 2 3 4\n", "output": "3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 2\n-1 -1\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "15 5\n-2 -1 2 -4 -3 4 -4 -2 -2 2 -2 -1 1 -4 -2\n", "output": "4\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "15 16\n-15 -5 -15 -14 -8 15 -15 -12 -5 -3 5 -7 3 8 -15\n", "output": "6\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
848
Solve the following coding problem using the programming language python: One day, at the "Russian Code Cup" event it was decided to play football as an out of competition event. All participants was divided into n teams and played several matches, two teams could not play against each other more than once. The appointed Judge was the most experienced member — Pavel. But since he was the wisest of all, he soon got bored of the game and fell asleep. Waking up, he discovered that the tournament is over and the teams want to know the results of all the matches. Pavel didn't want anyone to discover about him sleeping and not keeping an eye on the results, so he decided to recover the results of all games. To do this, he asked all the teams and learned that the real winner was friendship, that is, each team beat the other teams exactly k times. Help Pavel come up with chronology of the tournir that meets all the conditions, or otherwise report that there is no such table. -----Input----- The first line contains two integers — n and k (1 ≤ n, k ≤ 1000). -----Output----- In the first line print an integer m — number of the played games. The following m lines should contain the information about all the matches, one match per line. The i-th line should contain two integers a_{i} and b_{i} (1 ≤ a_{i}, b_{i} ≤ n; a_{i} ≠ b_{i}). The numbers a_{i} and b_{i} mean, that in the i-th match the team with number a_{i} won against the team with number b_{i}. You can assume, that the teams are numbered from 1 to n. If a tournir that meets the conditions of the problem does not exist, then print -1. -----Examples----- Input 3 1 Output 3 1 2 2 3 3 1 The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python n, k = list(map(int, input().split())) m = n + 1 if 2 * k > n - 1: print('-1') else: t = [] for i in range(1, k + 1): t += [str(j) + ' ' + str(j + i) for j in range(1, m - i)] t += [str(j) + ' ' + str(j + i - n) for j in range(m - i, m)] print(k * n) print('\n'.join(t)) ```
vfc_13146
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/417/C", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 1\n", "output": "3\n1 2\n2 3\n3 1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "7 3\n", "output": "21\n1 2\n1 3\n1 4\n2 3\n2 4\n2 5\n3 4\n3 5\n3 6\n4 5\n4 6\n4 7\n5 6\n5 7\n5 1\n6 7\n6 1\n6 2\n7 1\n7 2\n7 3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 1\n", "output": "4\n1 2\n2 3\n3 4\n4 1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 2\n", "output": "10\n1 2\n1 3\n2 3\n2 4\n3 4\n3 5\n4 5\n4 1\n5 1\n5 2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 2\n", "output": "10\n1 2\n1 3\n2 3\n2 4\n3 4\n3 5\n4 5\n4 1\n5 1\n5 2\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
850
Solve the following coding problem using the programming language python: Unfortunately, Vasya can only sum pairs of integers (a, b), such that for any decimal place at least one number has digit 0 in this place. For example, Vasya can sum numbers 505 and 50, but he cannot sum 1 and 4. Vasya has a set of k distinct non-negative integers d_1, d_2, ..., d_{k}. Vasya wants to choose some integers from this set so that he could sum any two chosen numbers. What maximal number of integers can he choose in the required manner? -----Input----- The first input line contains integer k (1 ≤ k ≤ 100) — the number of integers. The second line contains k distinct space-separated integers d_1, d_2, ..., d_{k} (0 ≤ d_{i} ≤ 100). -----Output----- In the first line print a single integer n the maximum number of the chosen integers. In the second line print n distinct non-negative integers — the required integers. If there are multiple solutions, print any of them. You can print the numbers in any order. -----Examples----- Input 4 100 10 1 0 Output 4 0 1 10 100 Input 3 2 70 3 Output 2 2 70 The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python k = int(input()) dk = list(map(int,input().split())) ans = [] if 0 in dk: ans.append(0) if 100 in dk: ans.append(100) f1 = False for q in dk: if 0<q<10: ans.append(q) f1 = True break f2 = False for q in dk: if 9<q<100 and q%10==0: ans.append(q) f2 = True break if (not f1 and not f2): for j in dk: if j!=0 and j!=100: ans.append(j) break print(len(ans)) print(*ans) ```
vfc_13154
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/305/A", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n100 10 1 0\n", "output": "4\n0 1 10 100 ", "type": "stdin_stdout" } ] }
apps
verifiable_code
851
Solve the following coding problem using the programming language python: Polycarp's workday lasts exactly $n$ minutes. He loves chocolate bars and can eat one bar in one minute. Today Polycarp has $k$ bars at the beginning of the workday. In some minutes of the workday Polycarp has important things to do and in such minutes he is not able to eat a chocolate bar. In other minutes he can either eat or not eat one chocolate bar. It is guaranteed, that in the first and in the last minutes of the workday Polycarp has no important things to do and he will always eat bars in this minutes to gladden himself at the begining and at the end of the workday. Also it is guaranteed, that $k$ is strictly greater than $1$. Your task is to determine such an order of eating chocolate bars that the maximum break time between eating bars is as minimum as possible. Consider that Polycarp eats a bar in the minute $x$ and the next bar in the minute $y$ ($x < y$). Then the break time is equal to $y - x - 1$ minutes. It is not necessary for Polycarp to eat all bars he has. -----Input----- The first line contains two integers $n$ and $k$ ($2 \le n \le 200\,000$, $2 \le k \le n$) — the length of the workday in minutes and the number of chocolate bars, which Polycarp has in the beginning of the workday. The second line contains the string with length $n$ consisting of zeros and ones. If the $i$-th symbol in the string equals to zero, Polycarp has no important things to do in the minute $i$ and he can eat a chocolate bar. In the other case, Polycarp is busy in the minute $i$ and can not eat a chocolate bar. It is guaranteed, that the first and the last characters of the string are equal to zero, and Polycarp always eats chocolate bars in these minutes. -----Output----- Print the minimum possible break in minutes between eating chocolate bars. -----Examples----- Input 3 3 010 Output 1 Input 8 3 01010110 Output 3 -----Note----- In the first example Polycarp can not eat the chocolate bar in the second minute, so the time of the break equals to one minute. In the second example Polycarp will eat bars in the minutes $1$ and $8$ anyway, also he needs to eat the chocolate bar in the minute $5$, so that the time of the maximum break will be equal to $3$ minutes. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python n, k = map(int, input().split()) s = input() l, r = int(-1), int(n) while r - l > 1: m = (l+r)//2 c, p = 1, 0 cond = True while p < n and c < k: i = p + m + 1 while i >= p and (i >= n or s[i] == '1'): i = i - 1; if (i == p): break c = c + 1 p = i cond = cond and (p == n-1) if cond: r = m else: l = m print(int(r)) ```
vfc_13158
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/774/L", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 3\n010\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "8 3\n01010110\n", "output": "3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "9 5\n001100110\n", "output": "2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 2\n00\n", "output": "0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 2\n010\n", "output": "1\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
852
Solve the following coding problem using the programming language python: The only difference between easy and hard versions is on constraints. In this version constraints are lower. You can make hacks only if all versions of the problem are solved. Koa the Koala is at the beach! The beach consists (from left to right) of a shore, $n+1$ meters of sea and an island at $n+1$ meters from the shore. She measured the depth of the sea at $1, 2, \dots, n$ meters from the shore and saved them in array $d$. $d_i$ denotes the depth of the sea at $i$ meters from the shore for $1 \le i \le n$. Like any beach this one has tide, the intensity of the tide is measured by parameter $k$ and affects all depths from the beginning at time $t=0$ in the following way: For a total of $k$ seconds, each second, tide increases all depths by $1$. Then, for a total of $k$ seconds, each second, tide decreases all depths by $1$. This process repeats again and again (ie. depths increase for $k$ seconds then decrease for $k$ seconds and so on ...). Formally, let's define $0$-indexed array $p = [0, 1, 2, \ldots, k - 2, k - 1, k, k - 1, k - 2, \ldots, 2, 1]$ of length $2k$. At time $t$ ($0 \le t$) depth at $i$ meters from the shore equals $d_i + p[t \bmod 2k]$ ($t \bmod 2k$ denotes the remainder of the division of $t$ by $2k$). Note that the changes occur instantaneously after each second, see the notes for better understanding. At time $t=0$ Koa is standing at the shore and wants to get to the island. Suppose that at some time $t$ ($0 \le t$) she is at $x$ ($0 \le x \le n$) meters from the shore: In one second Koa can swim $1$ meter further from the shore ($x$ changes to $x+1$) or not swim at all ($x$ stays the same), in both cases $t$ changes to $t+1$. As Koa is a bad swimmer, the depth of the sea at the point where she is can't exceed $l$ at integer points of time (or she will drown). More formally, if Koa is at $x$ ($1 \le x \le n$) meters from the shore at the moment $t$ (for some integer $t\ge 0$), the depth of the sea at this point  — $d_x + p[t \bmod 2k]$  — can't exceed $l$. In other words, $d_x + p[t \bmod 2k] \le l$ must hold always. Once Koa reaches the island at $n+1$ meters from the shore, she stops and can rest. Note that while Koa swims tide doesn't have effect on her (ie. she can't drown while swimming). Note that Koa can choose to stay on the shore for as long as she needs and neither the shore or the island are affected by the tide (they are solid ground and she won't drown there). Koa wants to know whether she can go from the shore to the island. Help her! -----Input----- The first line of the input contains one integer $t$ ($1 \le t \le 100$)  — the number of test cases. Description of the test cases follows. The first line of each test case contains three integers $n$, $k$ and $l$ ($1 \le n \le 100; 1 \le k \le 100; 1 \le l \le 100$) — the number of meters of sea Koa measured and parameters $k$ and $l$. The second line of each test case contains $n$ integers $d_1, d_2, \ldots, d_n$ ($0 \le d_i \le 100$)  — the depths of each meter of sea Koa measured. It is guaranteed that the sum of $n$ over all test cases does not exceed $100$. -----Output----- For each test case: Print Yes if Koa can get from the shore to the island, and No otherwise. You may print each letter in any case (upper or lower). -----Example----- Input 7 2 1 1 1 0 5 2 3 1 2 3 2 2 4 3 4 0 2 4 3 2 3 5 3 0 7 2 3 3 0 2 1 3 0 1 7 1 4 4 4 3 0 2 4 2 5 2 3 1 2 3 2 2 Output Yes No Yes Yes Yes No No -----Note----- In the following $s$ denotes the shore, $i$ denotes the island, $x$ denotes distance from Koa to the shore, the underline denotes the position of Koa, and values in the array below denote current depths, affected by tide, at $1, 2, \dots, n$ meters from the shore. In test case $1$ we have $n = 2, k = 1, l = 1, p = [ 0, 1 ]$. Koa wants to go from shore (at $x = 0$) to the island (at $x = 3$). Let's describe a possible solution: Initially at $t = 0$ the beach looks like this: $[\underline{s}, 1, 0, i]$. At $t = 0$ if Koa would decide to swim to $x = 1$, beach would look like: $[s, \underline{2}, 1, i]$ at $t = 1$, since $2 > 1$ she would drown. So Koa waits $1$ second instead and beach looks like $[\underline{s}, 2, 1, i]$ at $t = 1$. At $t = 1$ Koa swims to $x = 1$, beach looks like $[s, \underline{1}, 0, i]$ at $t = 2$. Koa doesn't drown because $1 \le 1$. At $t = 2$ Koa swims to $x = 2$, beach looks like $[s, 2, \underline{1}, i]$ at $t = 3$. Koa doesn't drown because $1 \le 1$. At $t = 3$ Koa swims to $x = 3$, beach looks like $[s, 1, 0, \underline{i}]$ at $t = 4$. At $t = 4$ Koa is at $x = 3$ and she made it! We can show that in test case $2$ Koa can't get to the island. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python for q in range(int(input())): n, k, l = map(int, input().split()) line = list(map(int, input().split())) line.append(-1000) dp = [[False] * (2 * k) for i in range(n + 2)] for i in range(2 * k): dp[0][i] = True for i in range(1, n + 2): for j in range(2 * k): if j < k and line[i - 1] + j <= l: if dp[i - 1][(j - 1) % (2 * k)]: dp[i][j] = True elif dp[i][(j - 1) % (2 * k)]: dp[i][j] = True if j >= k and line[i - 1] + 2 * k - j <= l: if dp[i - 1][j - 1]: dp[i][j] = True elif dp[i][j - 1]: dp[i][j] = True if max(dp[n + 1]) == True: print("Yes") else: print("No") ```
vfc_13162
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1384/B1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "7\n2 1 1\n1 0\n5 2 3\n1 2 3 2 2\n4 3 4\n0 2 4 3\n2 3 5\n3 0\n7 2 3\n3 0 2 1 3 0 1\n7 1 4\n4 4 3 0 2 4 2\n5 2 3\n1 2 3 2 2\n", "output": "Yes\nNo\nYes\nYes\nYes\nNo\nNo\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
854
Solve the following coding problem using the programming language python: XXI Berland Annual Fair is coming really soon! Traditionally fair consists of $n$ booths, arranged in a circle. The booths are numbered $1$ through $n$ clockwise with $n$ being adjacent to $1$. The $i$-th booths sells some candies for the price of $a_i$ burles per item. Each booth has an unlimited supply of candies. Polycarp has decided to spend at most $T$ burles at the fair. However, he has some plan in mind for his path across the booths: at first, he visits booth number $1$; if he has enough burles to buy exactly one candy from the current booth, then he buys it immediately; then he proceeds to the next booth in the clockwise order (regardless of if he bought a candy or not). Polycarp's money is finite, thus the process will end once he can no longer buy candy at any booth. Calculate the number of candies Polycarp will buy. -----Input----- The first line contains two integers $n$ and $T$ ($1 \le n \le 2 \cdot 10^5$, $1 \le T \le 10^{18}$) — the number of booths at the fair and the initial amount of burles Polycarp has. The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$) — the price of the single candy at booth number $i$. -----Output----- Print a single integer — the total number of candies Polycarp will buy. -----Examples----- Input 3 38 5 2 5 Output 10 Input 5 21 2 4 100 2 6 Output 6 -----Note----- Let's consider the first example. Here are Polycarp's moves until he runs out of money: Booth $1$, buys candy for $5$, $T = 33$; Booth $2$, buys candy for $2$, $T = 31$; Booth $3$, buys candy for $5$, $T = 26$; Booth $1$, buys candy for $5$, $T = 21$; Booth $2$, buys candy for $2$, $T = 19$; Booth $3$, buys candy for $5$, $T = 14$; Booth $1$, buys candy for $5$, $T = 9$; Booth $2$, buys candy for $2$, $T = 7$; Booth $3$, buys candy for $5$, $T = 2$; Booth $1$, buys no candy, not enough money; Booth $2$, buys candy for $2$, $T = 0$. No candy can be bought later. The total number of candies bought is $10$. In the second example he has $1$ burle left at the end of his path, no candy can be bought with this amount. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python n, t = list(map(int, input().split())) a = [int(x) for x in input().split()] otv = 0 def rec(t, a): nonlocal otv s = 0 for c in a: s += c kol = t // s kol = max(kol, 0) otv += (kol * len(a)) octat = t - kol * s res = [] su = 0 for c in a: if su + c <= octat: res.append(c) su += c if su == 0: print(otv) return #print(octat, res, otv) rec(octat, res) rec(t, a) ```
vfc_13170
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1073/D", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 38\n5 2 5\n", "output": "10\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 21\n2 4 100 2 6\n", "output": "6\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 53\n1\n", "output": "53\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 50\n40 15\n", "output": "1\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
856
Solve the following coding problem using the programming language python: Being stuck at home, Ray became extremely bored. To pass time, he asks Lord Omkar to use his time bending power: Infinity Clock! However, Lord Omkar will only listen to mortals who can solve the following problem: You are given an array $a$ of $n$ integers. You are also given an integer $k$. Lord Omkar wants you to do $k$ operations with this array. Define one operation as the following: Set $d$ to be the maximum value of your array. For every $i$ from $1$ to $n$, replace $a_{i}$ with $d-a_{i}$. The goal is to predict the contents in the array after $k$ operations. Please help Ray determine what the final sequence will look like! -----Input----- Each test contains multiple test cases. The first line contains the number of cases $t$ ($1 \le t \le 100$). Description of the test cases follows. The first line of each test case contains two integers $n$ and $k$ ($1 \leq n \leq 2 \cdot 10^5, 1 \leq k \leq 10^{18}$) – the length of your array and the number of operations to perform. The second line of each test case contains $n$ integers $a_{1},a_{2},...,a_{n}$ $(-10^9 \leq a_{i} \leq 10^9)$ – the initial contents of your array. It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$. -----Output----- For each case, print the final version of array $a$ after $k$ operations described above. -----Example----- Input 3 2 1 -199 192 5 19 5 -1 4 2 0 1 2 69 Output 391 0 0 6 1 3 5 0 -----Note----- In the first test case the array changes as follows: Initially, the array is $[-199, 192]$. $d = 192$. After the operation, the array becomes $[d-(-199), d-192] = [391, 0]$. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python def f(arr): d = max(arr) for i in range(len(arr)): arr[i] = d - arr[i] # for _ in range(1): for _ in range(int(input())): n, k = list(map(int, input().split())) # n = int(input()) arr = list(map(int, input().split())) if k <= 2: for i in range(k): f(arr) elif k % 2 == 1: for i in range(3): f(arr) else: for i in range(4): f(arr) print(*arr) ```
vfc_13178
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1392/B", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n2 1\n-199 192\n5 19\n5 -1 4 2 0\n1 2\n69\n", "output": "391 0\n0 6 1 3 5\n0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n6 4\n219 57 -58 230 173 177\n2 4\n266 176\n3 2\n134 -190 202\n5 69\n-1000000000 -1000000000 1000000000 0 1000000000\n", "output": "277 115 0 288 231 235\n90 0\n324 0 392\n2000000000 2000000000 0 1000000000 0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n20 809014\n289 -254 1 -109 -167 93 23 -37 -31 -109 204 59 296 49 132 0 -28 35 -197 -266\n20 458494\n113 218 -292 -298 179 258 -257 -20 296 76 -145 93 -282 -261 -159 -45 255 -107 171 63\n14 876161\n69 74 12 2 177 -113 103 93 38 -48 282 169 205 145\n26 731742\n76 190 -227 -81 -293 243 -122 -122 252 16 -88 243 -216 -275 -267 188 144 -245 -117 -244 -259 281 -273 -206 112 -51\n20 327039\n42 133 231 128 19 181 -137 193 136 75 -203 55 37 -155 -219 182 -178 -280 2 132\n", "output": "555 12 267 157 99 359 289 229 235 157 470 325 562 315 398 266 238 301 69 0\n411 516 6 0 477 556 41 278 594 374 153 391 16 37 139 253 553 191 469 361\n213 208 270 280 105 395 179 189 244 330 0 113 77 137\n369 483 66 212 0 536 171 171 545 309 205 536 77 18 26 481 437 48 176 49 34 574 20 87 405 242\n189 98 0 103 212 50 368 38 95 156 434 176 194 386 450 49 409 511 229 99\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n1 398708496844866113\n959414461\n", "output": "0\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
857
Solve the following coding problem using the programming language python: You are locked in a room with a door that has a keypad with 10 keys corresponding to digits from 0 to 9. To escape from the room, you need to enter a correct code. You also have a sequence of digits. Some keys on the keypad have fingerprints. You believe the correct code is the longest not necessarily contiguous subsequence of the sequence you have that only contains digits with fingerprints on the corresponding keys. Find such code. -----Input----- The first line contains two integers $n$ and $m$ ($1 \le n, m \le 10$) representing the number of digits in the sequence you have and the number of keys on the keypad that have fingerprints. The next line contains $n$ distinct space-separated integers $x_1, x_2, \ldots, x_n$ ($0 \le x_i \le 9$) representing the sequence. The next line contains $m$ distinct space-separated integers $y_1, y_2, \ldots, y_m$ ($0 \le y_i \le 9$) — the keys with fingerprints. -----Output----- In a single line print a space-separated sequence of integers representing the code. If the resulting sequence is empty, both printing nothing and printing a single line break is acceptable. -----Examples----- Input 7 3 3 5 7 1 6 2 8 1 2 7 Output 7 1 2 Input 4 4 3 4 1 0 0 1 7 9 Output 1 0 -----Note----- In the first example, the only digits with fingerprints are $1$, $2$ and $7$. All three of them appear in the sequence you know, $7$ first, then $1$ and then $2$. Therefore the output is 7 1 2. Note that the order is important, and shall be the same as the order in the original sequence. In the second example digits $0$, $1$, $7$ and $9$ have fingerprints, however only $0$ and $1$ appear in the original sequence. $1$ appears earlier, so the output is 1 0. Again, the order is important. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python input() a = [int(x) for x in input().split()] b = [int(x) for x in input().split()] for x in a: if x in b: print(x, end=' ') print() ```
vfc_13182
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/994/A", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "7 3\n3 5 7 1 6 2 8\n1 2 7\n", "output": "7 1 2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 4\n3 4 1 0\n0 1 7 9\n", "output": "1 0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "9 4\n9 8 7 6 5 4 3 2 1\n2 4 6 8\n", "output": "8 6 4 2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "10 5\n3 7 1 2 4 6 9 0 5 8\n4 3 0 7 9\n", "output": "3 7 4 9 0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 5\n1 2 3 4 5\n6 7 8 9 0\n", "output": "\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
858
Solve the following coding problem using the programming language python: Way to go! Heidi now knows how many brains there must be for her to get one. But throwing herself in the midst of a clutch of hungry zombies is quite a risky endeavor. Hence Heidi wonders: what is the smallest number of brains that must be in the chest for her to get out at all (possibly empty-handed, but alive)? The brain dinner night will evolve just as in the previous subtask: the same crowd is present, the N - 1 zombies have the exact same mindset as before and Heidi is to make the first proposal, which must be accepted by at least half of the attendees for her to survive. -----Input----- The only line of input contains one integer: N, the number of attendees (1 ≤ N ≤ 10^9). -----Output----- Output one integer: the smallest number of brains in the chest which allows Heidi to merely survive. -----Examples----- Input 1 Output 0 Input 3 Output 1 Input 99 Output 49 The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python import math a = int(input()) if a%2==1: print(math.ceil((a-1)/2)) else: z = 1 while z*2<=a: z*=2 print((a-z)//2) ```
vfc_13186
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/690/A2", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1\n", "output": "0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n", "output": "0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n", "output": "0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n", "output": "2\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
859
Solve the following coding problem using the programming language python: Dreamoon is standing at the position 0 on a number line. Drazil is sending a list of commands through Wi-Fi to Dreamoon's smartphone and Dreamoon follows them. Each command is one of the following two types: Go 1 unit towards the positive direction, denoted as '+' Go 1 unit towards the negative direction, denoted as '-' But the Wi-Fi condition is so poor that Dreamoon's smartphone reports some of the commands can't be recognized and Dreamoon knows that some of them might even be wrong though successfully recognized. Dreamoon decides to follow every recognized command and toss a fair coin to decide those unrecognized ones (that means, he moves to the 1 unit to the negative or positive direction with the same probability 0.5). You are given an original list of commands sent by Drazil and list received by Dreamoon. What is the probability that Dreamoon ends in the position originally supposed to be final by Drazil's commands? -----Input----- The first line contains a string s_1 — the commands Drazil sends to Dreamoon, this string consists of only the characters in the set {'+', '-'}. The second line contains a string s_2 — the commands Dreamoon's smartphone recognizes, this string consists of only the characters in the set {'+', '-', '?'}. '?' denotes an unrecognized command. Lengths of two strings are equal and do not exceed 10. -----Output----- Output a single real number corresponding to the probability. The answer will be considered correct if its relative or absolute error doesn't exceed 10^{ - 9}. -----Examples----- Input ++-+- +-+-+ Output 1.000000000000 Input +-+- +-?? Output 0.500000000000 Input +++ ??- Output 0.000000000000 -----Note----- For the first sample, both s_1 and s_2 will lead Dreamoon to finish at the same position + 1. For the second sample, s_1 will lead Dreamoon to finish at position 0, while there are four possibilites for s_2: {"+-++", "+-+-", "+--+", "+---"} with ending position {+2, 0, 0, -2} respectively. So there are 2 correct cases out of 4, so the probability of finishing at the correct position is 0.5. For the third sample, s_2 could only lead us to finish at positions {+1, -1, -3}, so the probability to finish at the correct position + 3 is 0. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python s=input() t=input() a=0 b=0 c=0 for i in range(len(s)): if s[i]=='+':a+=1 else:a-=1 for i in range(len(t)): if t[i]=='+':b+=1 elif t[i]=='-':b-=1 else:c+=1 x=a-b d=0-c y=0-1 for i in range(c+1): if d==x:y=i d+=2 def fact(n): w=1 for i in range(n): w*=(i+1) return(w) def parmi(k,n): w=1 w*=fact(n) w//=fact(k) w//=fact(n-k) return(w) def puiss(k,n): w=1 for i in range(n): w*=k return(w) if y==-1:print(0.0) else:print(parmi(y,c)/puiss(2,c)) ```
vfc_13190
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/476/B", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "++-+-\n+-+-+\n", "output": "1.000000000000\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
860
Solve the following coding problem using the programming language python: On February, 30th n students came in the Center for Training Olympiad Programmers (CTOP) of the Berland State University. They came one by one, one after another. Each of them went in, and before sitting down at his desk, greeted with those who were present in the room by shaking hands. Each of the students who came in stayed in CTOP until the end of the day and never left. At any time any three students could join together and start participating in a team contest, which lasted until the end of the day. The team did not distract from the contest for a minute, so when another student came in and greeted those who were present, he did not shake hands with the members of the contest writing team. Each team consisted of exactly three students, and each student could not become a member of more than one team. Different teams could start writing contest at different times. Given how many present people shook the hands of each student, get a possible order in which the students could have come to CTOP. If such an order does not exist, then print that this is impossible. Please note that some students could work independently until the end of the day, without participating in a team contest. -----Input----- The first line contains integer n (1 ≤ n ≤ 2·10^5) — the number of students who came to CTOP. The next line contains n integers a_1, a_2, ..., a_{n} (0 ≤ a_{i} < n), where a_{i} is the number of students with who the i-th student shook hands. -----Output----- If the sought order of students exists, print in the first line "Possible" and in the second line print the permutation of the students' numbers defining the order in which the students entered the center. Number i that stands to the left of number j in this permutation means that the i-th student came earlier than the j-th student. If there are multiple answers, print any of them. If the sought order of students doesn't exist, in a single line print "Impossible". -----Examples----- Input 5 2 1 3 0 1 Output Possible 4 5 1 3 2 Input 9 0 2 3 4 1 1 0 2 2 Output Possible 7 5 2 1 6 8 3 4 9 Input 4 0 2 1 1 Output Impossible -----Note----- In the first sample from the statement the order of events could be as follows: student 4 comes in (a_4 = 0), he has no one to greet; student 5 comes in (a_5 = 1), he shakes hands with student 4; student 1 comes in (a_1 = 2), he shakes hands with two students (students 4, 5); student 3 comes in (a_3 = 3), he shakes hands with three students (students 4, 5, 1); students 4, 5, 3 form a team and start writing a contest; student 2 comes in (a_2 = 1), he shakes hands with one student (number 1). In the second sample from the statement the order of events could be as follows: student 7 comes in (a_7 = 0), he has nobody to greet; student 5 comes in (a_5 = 1), he shakes hands with student 7; student 2 comes in (a_2 = 2), he shakes hands with two students (students 7, 5); students 7, 5, 2 form a team and start writing a contest; student 1 comes in(a_1 = 0), he has no one to greet (everyone is busy with the contest); student 6 comes in (a_6 = 1), he shakes hands with student 1; student 8 comes in (a_8 = 2), he shakes hands with two students (students 1, 6); student 3 comes in (a_3 = 3), he shakes hands with three students (students 1, 6, 8); student 4 comes in (a_4 = 4), he shakes hands with four students (students 1, 6, 8, 3); students 8, 3, 4 form a team and start writing a contest; student 9 comes in (a_9 = 2), he shakes hands with two students (students 1, 6). In the third sample from the statement the order of events is restored unambiguously: student 1 comes in (a_1 = 0), he has no one to greet; student 3 comes in (or student 4) (a_3 = a_4 = 1), he shakes hands with student 1; student 2 comes in (a_2 = 2), he shakes hands with two students (students 1, 3 (or 4)); the remaining student 4 (or student 3), must shake one student's hand (a_3 = a_4 = 1) but it is impossible as there are only two scenarios: either a team formed and he doesn't greet anyone, or he greets all the three present people who work individually. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python n=int(input()) c=[[] for i in range(n)] [c[int(x)].append(i+1) for i,x in enumerate(input().split())] s=0;r=[] for i in range(n): while len(c[s])==0 and s>=0: s-=3 if s<0: print('Impossible') break else: r+=[c[s].pop()] s+=1 else: print('Possible') print(*r) ```
vfc_13194
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/534/D", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n2 1 3 0 1\n", "output": "Possible\n4 5 1 3 2 ", "type": "stdin_stdout" } ] }
apps
verifiable_code
862
Solve the following coding problem using the programming language python: Allen wants to enter a fan zone that occupies a round square and has $n$ entrances. There already is a queue of $a_i$ people in front of the $i$-th entrance. Each entrance allows one person from its queue to enter the fan zone in one minute. Allen uses the following strategy to enter the fan zone: Initially he stands in the end of the queue in front of the first entrance. Each minute, if he is not allowed into the fan zone during the minute (meaning he is not the first in the queue), he leaves the current queue and stands in the end of the queue of the next entrance (or the first entrance if he leaves the last entrance). Determine the entrance through which Allen will finally enter the fan zone. -----Input----- The first line contains a single integer $n$ ($2 \le n \le 10^5$) — the number of entrances. The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($0 \le a_i \le 10^9$) — the number of people in queues. These numbers do not include Allen. -----Output----- Print a single integer — the number of entrance that Allen will use. -----Examples----- Input 4 2 3 2 0 Output 3 Input 2 10 10 Output 1 Input 6 5 2 6 5 7 4 Output 6 -----Note----- In the first example the number of people (not including Allen) changes as follows: $[\textbf{2}, 3, 2, 0] \to [1, \textbf{2}, 1, 0] \to [0, 1, \textbf{0}, 0]$. The number in bold is the queue Alles stands in. We see that he will enter the fan zone through the third entrance. In the second example the number of people (not including Allen) changes as follows: $[\textbf{10}, 10] \to [9, \textbf{9}] \to [\textbf{8}, 8] \to [7, \textbf{7}] \to [\textbf{6}, 6] \to \\ [5, \textbf{5}] \to [\textbf{4}, 4] \to [3, \textbf{3}] \to [\textbf{2}, 2] \to [1, \textbf{1}] \to [\textbf{0}, 0]$. In the third example the number of people (not including Allen) changes as follows: $[\textbf{5}, 2, 6, 5, 7, 4] \to [4, \textbf{1}, 5, 4, 6, 3] \to [3, 0, \textbf{4}, 3, 5, 2] \to \\ [2, 0, 3, \textbf{2}, 4, 1] \to [1, 0, 2, 1, \textbf{3}, 0] \to [0, 0, 1, 0, 2, \textbf{0}]$. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python n = int(input()) a = list(map(int, input().split())) mn = 10000000000 ans = -1 from math import ceil for i in range(n): b = a[i] - i c = int(ceil(b / n)) cc = n*c if n*c < mn: mn = n*c ans = i+1 print(ans) ```
vfc_13202
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/996/B", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n2 3 2 0\n", "output": "3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n10 10\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "6\n5 2 6 5 7 4\n", "output": "6\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n483544186 940350702\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "10\n3 3 3 5 6 9 3 1 7 3\n", "output": "7\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
863
Solve the following coding problem using the programming language python: Buses run between the cities A and B, the first one is at 05:00 AM and the last one departs not later than at 11:59 PM. A bus from the city A departs every a minutes and arrives to the city B in a t_{a} minutes, and a bus from the city B departs every b minutes and arrives to the city A in a t_{b} minutes. The driver Simion wants to make his job diverse, so he counts the buses going towards him. Simion doesn't count the buses he meet at the start and finish. You know the time when Simion departed from the city A to the city B. Calculate the number of buses Simion will meet to be sure in his counting. -----Input----- The first line contains two integers a, t_{a} (1 ≤ a, t_{a} ≤ 120) — the frequency of the buses from the city A to the city B and the travel time. Both values are given in minutes. The second line contains two integers b, t_{b} (1 ≤ b, t_{b} ≤ 120) — the frequency of the buses from the city B to the city A and the travel time. Both values are given in minutes. The last line contains the departure time of Simion from the city A in the format hh:mm. It is guaranteed that there are a bus from the city A at that time. Note that the hours and the minutes are given with exactly two digits. -----Output----- Print the only integer z — the number of buses Simion will meet on the way. Note that you should not count the encounters in cities A and B. -----Examples----- Input 10 30 10 35 05:20 Output 5 Input 60 120 24 100 13:00 Output 9 -----Note----- In the first example Simion departs form the city A at 05:20 AM and arrives to the city B at 05:50 AM. He will meet the first 5 buses from the city B that departed in the period [05:00 AM - 05:40 AM]. Also Simion will meet a bus in the city B at 05:50 AM, but he will not count it. Also note that the first encounter will be between 05:26 AM and 05:27 AM (if we suggest that the buses are go with the sustained speed). The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python a, A = list(map(int,input().split())) b, B = list(map(int,input().split())) c = input() c = int(c[:2]) * 60 + int(c[-2:]) d = 0 for i in range(5 * 60, 24 * 60, b): if i < c + A and i + B > c: d += 1 print(d) ```
vfc_13206
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/665/A", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "10 30\n10 35\n05:20\n", "output": "5\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "60 120\n24 100\n13:00\n", "output": "9\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "30 60\n60 60\n22:30\n", "output": "2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "30 60\n10 60\n23:30\n", "output": "8\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 45\n4 60\n21:00\n", "output": "26\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
864
Solve the following coding problem using the programming language python: Natasha is planning an expedition to Mars for $n$ people. One of the important tasks is to provide food for each participant. The warehouse has $m$ daily food packages. Each package has some food type $a_i$. Each participant must eat exactly one food package each day. Due to extreme loads, each participant must eat the same food type throughout the expedition. Different participants may eat different (or the same) types of food. Formally, for each participant $j$ Natasha should select his food type $b_j$ and each day $j$-th participant will eat one food package of type $b_j$. The values $b_j$ for different participants may be different. What is the maximum possible number of days the expedition can last, following the requirements above? -----Input----- The first line contains two integers $n$ and $m$ ($1 \le n \le 100$, $1 \le m \le 100$) — the number of the expedition participants and the number of the daily food packages available. The second line contains sequence of integers $a_1, a_2, \dots, a_m$ ($1 \le a_i \le 100$), where $a_i$ is the type of $i$-th food package. -----Output----- Print the single integer — the number of days the expedition can last. If it is not possible to plan the expedition for even one day, print 0. -----Examples----- Input 4 10 1 5 2 1 1 1 2 5 7 2 Output 2 Input 100 1 1 Output 0 Input 2 5 5 4 3 2 1 Output 1 Input 3 9 42 42 42 42 42 42 42 42 42 Output 3 -----Note----- In the first example, Natasha can assign type $1$ food to the first participant, the same type $1$ to the second, type $5$ to the third and type $2$ to the fourth. In this case, the expedition can last for $2$ days, since each participant can get two food packages of his food type (there will be used $4$ packages of type $1$, two packages of type $2$ and two packages of type $5$). In the second example, there are $100$ participants and only $1$ food package. In this case, the expedition can't last even $1$ day. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python n, k = map(int, input().split()) a = list(map(int, input().split())) day = 1 def poss(day): q = 0 mp = dict() for el in a: if el not in mp: mp[el] = 1 else: mp[el] += 1 for el in mp: q += mp[el] // day return q >= n while poss(day): day += 1 print(day - 1) ```
vfc_13210
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1011/B", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4 10\n1 5 2 1 1 1 2 5 7 2\n", "output": "2\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
867
Solve the following coding problem using the programming language python: Tonight is brain dinner night and all zombies will gather together to scarf down some delicious brains. The artful Heidi plans to crash the party, incognito, disguised as one of them. Her objective is to get away with at least one brain, so she can analyze the zombies' mindset back home and gain a strategic advantage. They will be N guests tonight: N - 1 real zombies and a fake one, our Heidi. The living-dead love hierarchies as much as they love brains: each one has a unique rank in the range 1 to N - 1, and Heidi, who still appears slightly different from the others, is attributed the highest rank, N. Tonight there will be a chest with brains on display and every attendee sees how many there are. These will then be split among the attendees according to the following procedure: The zombie of the highest rank makes a suggestion on who gets how many brains (every brain is an indivisible entity). A vote follows. If at least half of the attendees accept the offer, the brains are shared in the suggested way and the feast begins. But if majority is not reached, then the highest-ranked zombie is killed, and the next zombie in hierarchy has to make a suggestion. If he is killed too, then the third highest-ranked makes one, etc. (It's enough to have exactly half of the votes – in case of a tie, the vote of the highest-ranked alive zombie counts twice, and he will of course vote in favor of his own suggestion in order to stay alive.) You should know that zombies are very greedy and sly, and they know this too – basically all zombie brains are alike. Consequently, a zombie will never accept an offer which is suboptimal for him. That is, if an offer is not strictly better than a potential later offer, he will vote against it. And make no mistake: while zombies may normally seem rather dull, tonight their intellects are perfect. Each zombie's priorities for tonight are, in descending order: survive the event (they experienced death already once and know it is no fun), get as many brains as possible. Heidi goes first and must make an offer which at least half of the attendees will accept, and which allocates at least one brain for Heidi herself. What is the smallest number of brains that have to be in the chest for this to be possible? -----Input----- The only line of input contains one integer: N, the number of attendees (1 ≤ N ≤ 10^9). -----Output----- Output one integer: the smallest number of brains in the chest which allows Heidi to take one brain home. -----Examples----- Input 1 Output 1 Input 4 Output 2 -----Note----- The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python import sys, math def rnd(x): a = int(x) b = x-a if b>=0.5: a+=1 return(a) n = int(input()) print(rnd(n/2)) ```
vfc_13222
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/690/A1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n", "output": "2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n", "output": "2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n", "output": "3\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
868
Solve the following coding problem using the programming language python: There exists an island called Arpa’s land, some beautiful girls live there, as ugly ones do. Mehrdad wants to become minister of Arpa’s land. Arpa has prepared an exam. Exam has only one question, given n, print the last digit of 1378^{n}. [Image] Mehrdad has become quite confused and wants you to help him. Please help, although it's a naive cheat. -----Input----- The single line of input contains one integer n (0 ≤ n ≤ 10^9). -----Output----- Print single integer — the last digit of 1378^{n}. -----Examples----- Input 1 Output 8 Input 2 Output 4 -----Note----- In the first example, last digit of 1378^1 = 1378 is 8. In the second example, last digit of 1378^2 = 1378·1378 = 1898884 is 4. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python n = int(input()) print(pow(1378, n, 10)) ```
vfc_13226
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/742/A", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1\n", "output": "8", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n", "output": "4", "type": "stdin_stdout" }, { "fn_name": null, "input": "1000\n", "output": "6", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n", "output": "2", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n", "output": "6", "type": "stdin_stdout" } ] }
apps
verifiable_code
869
Solve the following coding problem using the programming language python: One day Vasya the Hipster decided to count how many socks he had. It turned out that he had a red socks and b blue socks. According to the latest fashion, hipsters should wear the socks of different colors: a red one on the left foot, a blue one on the right foot. Every day Vasya puts on new socks in the morning and throws them away before going to bed as he doesn't want to wash them. Vasya wonders, what is the maximum number of days when he can dress fashionable and wear different socks, and after that, for how many days he can then wear the same socks until he either runs out of socks or cannot make a single pair from the socks he's got. Can you help him? -----Input----- The single line of the input contains two positive integers a and b (1 ≤ a, b ≤ 100) — the number of red and blue socks that Vasya's got. -----Output----- Print two space-separated integers — the maximum number of days when Vasya can wear different socks and the number of days when he can wear the same socks until he either runs out of socks or cannot make a single pair from the socks he's got. Keep in mind that at the end of the day Vasya throws away the socks that he's been wearing on that day. -----Examples----- Input 3 1 Output 1 1 Input 2 3 Output 2 0 Input 7 3 Output 3 2 -----Note----- In the first sample Vasya can first put on one pair of different socks, after that he has two red socks left to wear on the second day. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python import sys #sys.stdin = open('input.txt') #sys.stdout = open('output.txt', 'w') n, m = [int(i) for i in input().split()] first = min(n, m) second = (max(n, m) - first) // 2 print(first, second) ```
vfc_13230
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/581/A", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 1\n", "output": "1 1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 3\n", "output": "2 0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "7 3\n", "output": "3 2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "100 100\n", "output": "100 0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 10\n", "output": "4 3\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
871
Solve the following coding problem using the programming language python: These days Arkady works as an air traffic controller at a large airport. He controls a runway which is usually used for landings only. Thus, he has a schedule of planes that are landing in the nearest future, each landing lasts $1$ minute. He was asked to insert one takeoff in the schedule. The takeoff takes $1$ minute itself, but for safety reasons there should be a time space between the takeoff and any landing of at least $s$ minutes from both sides. Find the earliest time when Arkady can insert the takeoff. -----Input----- The first line of input contains two integers $n$ and $s$ ($1 \le n \le 100$, $1 \le s \le 60$) — the number of landings on the schedule and the minimum allowed time (in minutes) between a landing and a takeoff. Each of next $n$ lines contains two integers $h$ and $m$ ($0 \le h \le 23$, $0 \le m \le 59$) — the time, in hours and minutes, when a plane will land, starting from current moment (i. e. the current time is $0$ $0$). These times are given in increasing order. -----Output----- Print two integers $h$ and $m$ — the hour and the minute from the current moment of the earliest time Arkady can insert the takeoff. -----Examples----- Input 6 60 0 0 1 20 3 21 5 0 19 30 23 40 Output 6 1 Input 16 50 0 30 1 20 3 0 4 30 6 10 7 50 9 30 11 10 12 50 14 30 16 10 17 50 19 30 21 10 22 50 23 59 Output 24 50 Input 3 17 0 30 1 0 12 0 Output 0 0 -----Note----- In the first example note that there is not enough time between 1:20 and 3:21, because each landing and the takeoff take one minute. In the second example there is no gaps in the schedule, so Arkady can only add takeoff after all landings. Note that it is possible that one should wait more than $24$ hours to insert the takeoff. In the third example Arkady can insert the takeoff even between the first landing. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python n, s = [int(x) for x in input().split()] ts = [] for _ in range(n): h, m = [int(x) for x in input().split()] ts.append(h * 60 + m) if ts[0] >= s + 1: print(0, 0) return diffs = [y - x for x, y in zip(ts, ts[1:])] for i, diff in enumerate(diffs): if diff >= 2 * s + 2: break else: i = len(ts) - 1 t = ts[i] + s + 1 print(t // 60, t % 60) ```
vfc_13238
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/967/A", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "6 60\n0 0\n1 20\n3 21\n5 0\n19 30\n23 40\n", "output": "6 1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "16 50\n0 30\n1 20\n3 0\n4 30\n6 10\n7 50\n9 30\n11 10\n12 50\n14 30\n16 10\n17 50\n19 30\n21 10\n22 50\n23 59\n", "output": "24 50\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 17\n0 30\n1 0\n12 0\n", "output": "0 0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "24 60\n0 21\n2 21\n2 46\n3 17\n4 15\n5 43\n6 41\n7 50\n8 21\n9 8\n10 31\n10 45\n12 30\n14 8\n14 29\n14 32\n14 52\n15 16\n16 7\n16 52\n18 44\n20 25\n21 13\n22 7\n", "output": "23 8\n", "type": "stdin_stdout" } ] }