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
74
Solve the following coding problem using the programming language python: Dima loves representing an odd number as the sum of multiple primes, and Lisa loves it when there are at most three primes. Help them to represent the given number as the sum of at most than three primes. More formally, you are given an odd numer n. Find a set of numbers p_{i} (1 ≤ i ≤ k), such that 1 ≤ k ≤ 3 p_{i} is a prime $\sum_{i = 1}^{k} p_{i} = n$ The numbers p_{i} do not necessarily have to be distinct. It is guaranteed that at least one possible solution exists. -----Input----- The single line contains an odd number n (3 ≤ n < 10^9). -----Output----- In the first line print k (1 ≤ k ≤ 3), showing how many numbers are in the representation you found. In the second line print numbers p_{i} in any order. If there are multiple possible solutions, you can print any of them. -----Examples----- Input 27 Output 3 5 11 11 -----Note----- A prime is an integer strictly larger than one that is divisible only by one and by itself. 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()) def prime(p): if p == 1: return False fl=True for i in range(2,math.ceil(p**0.5) + 1): if p % i == 0: fl=False return fl def sum_of_primes(k): fl=True for i in range((k // 2) + 1): if prime(i) and prime(k-i): fl=True break return fl if prime(n): print(1) print(n) else: if prime(n-2): print(2) print(2 , n-2) else: l=1 for i in range(2, (n // 3) + 1): if prime(i) and sum_of_primes(n - i): l=i break print(3) r=1 for k in range((n-l) // 2): if prime(k) and prime(n-l-k): r=k break print(l,r,n-l-r) ```
vfc_10050
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/584/D", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "27\n", "output": "3\n2 2 23", "type": "stdin_stdout" } ] }
apps
verifiable_code
75
Solve the following coding problem using the programming language python: You are given a description of a depot. It is a rectangular checkered field of n × m size. Each cell in a field can be empty (".") or it can be occupied by a wall ("*"). You have one bomb. If you lay the bomb at the cell (x, y), then after triggering it will wipe out all walls in the row x and all walls in the column y. You are to determine if it is possible to wipe out all walls in the depot by placing and triggering exactly one bomb. The bomb can be laid both in an empty cell or in a cell occupied by a wall. -----Input----- The first line contains two positive integers n and m (1 ≤ n, m ≤ 1000) — the number of rows and columns in the depot field. The next n lines contain m symbols "." and "*" each — the description of the field. j-th symbol in i-th of them stands for cell (i, j). If the symbol is equal to ".", then the corresponding cell is empty, otherwise it equals "*" and the corresponding cell is occupied by a wall. -----Output----- If it is impossible to wipe out all walls by placing and triggering exactly one bomb, then print "NO" in the first line (without quotes). Otherwise print "YES" (without quotes) in the first line and two integers in the second line — the coordinates of the cell at which the bomb should be laid. If there are multiple answers, print any of them. -----Examples----- Input 3 4 .*.. .... .*.. Output YES 1 2 Input 3 3 ..* .*. *.. Output NO Input 6 5 ..*.. ..*.. ***** ..*.. ..*.. ..*.. Output YES 3 3 The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python n, m = list(map(int, input().split())) p = [] ans = 0 for i in range(n): s = input() ans += s.count('*') p.append(s) dp = [] for i in range(n): dp.append([0] * m) for i in range(n): col = p[i].count('*') for t in range(m): dp[i][t] = col for i in range(m): col = 0 for t in range(n): if p[t][i] == '*': col += 1 for t in range(n): dp[t][i] += col f = False for i in range(n): for t in range(m): if dp[i][t] - int(p[i][t] == '*') == ans: f = True print('YES') print(i + 1, t + 1) break if f: break if not f: print('NO') ```
vfc_10054
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/699/B", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 4\n.*..\n....\n.*..\n", "output": "YES\n1 2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 3\n..*\n.*.\n*..\n", "output": "NO\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "6 5\n..*..\n..*..\n*****\n..*..\n..*..\n..*..\n", "output": "YES\n3 3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 10\n**********\n", "output": "YES\n1 1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "10 1\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n", "output": "YES\n1 1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "10 10\n.........*\n.........*\n........**\n.........*\n.........*\n.........*\n.........*\n.........*\n.........*\n.........*\n", "output": "YES\n3 10\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
76
Solve the following coding problem using the programming language python: Berland Football Cup starts really soon! Commentators from all over the world come to the event. Organizers have already built $n$ commentary boxes. $m$ regional delegations will come to the Cup. Every delegation should get the same number of the commentary boxes. If any box is left unoccupied then the delegations will be upset. So each box should be occupied by exactly one delegation. If $n$ is not divisible by $m$, it is impossible to distribute the boxes to the delegations at the moment. Organizers can build a new commentary box paying $a$ burles and demolish a commentary box paying $b$ burles. They can both build and demolish boxes arbitrary number of times (each time paying a corresponding fee). It is allowed to demolish all the existing boxes. What is the minimal amount of burles organizers should pay to satisfy all the delegations (i.e. to make the number of the boxes be divisible by $m$)? -----Input----- The only line contains four integer numbers $n$, $m$, $a$ and $b$ ($1 \le n, m \le 10^{12}$, $1 \le a, b \le 100$), where $n$ is the initial number of the commentary boxes, $m$ is the number of delegations to come, $a$ is the fee to build a box and $b$ is the fee to demolish a box. -----Output----- Output the minimal amount of burles organizers should pay to satisfy all the delegations (i.e. to make the number of the boxes be divisible by $m$). It is allowed that the final number of the boxes is equal to $0$. -----Examples----- Input 9 7 3 8 Output 15 Input 2 7 3 7 Output 14 Input 30 6 17 19 Output 0 -----Note----- In the first example organizers can build $5$ boxes to make the total of $14$ paying $3$ burles for the each of them. In the second example organizers can demolish $2$ boxes to make the total of $0$ paying $7$ burles for the each of them. In the third example organizers are already able to distribute all the boxes equally among the delegations, each one get $5$ boxes. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python n, m, a, b = list(map(int, input().split())) k = n%m print(min(k*b, (m - k)*a)) ```
vfc_10058
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/990/A", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "9 7 3 8\n", "output": "15\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 7 3 7\n", "output": "14\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "30 6 17 19\n", "output": "0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "500000000001 1000000000000 100 100\n", "output": "49999999999900\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
78
Solve the following coding problem using the programming language python: The only difference between easy and hard versions is constraints. Polycarp loves to listen to music, so he never leaves the player, even on the way home from the university. Polycarp overcomes the distance from the university to the house in exactly $T$ minutes. In the player, Polycarp stores $n$ songs, each of which is characterized by two parameters: $t_i$ and $g_i$, where $t_i$ is the length of the song in minutes ($1 \le t_i \le 15$), $g_i$ is its genre ($1 \le g_i \le 3$). Polycarp wants to create such a playlist so that he can listen to music all the time on the way from the university to his home, and at the time of his arrival home, the playlist is over. Polycarp never interrupts songs and always listens to them from beginning to end. Thus, if he started listening to the $i$-th song, he would spend exactly $t_i$ minutes on its listening. Polycarp also does not like when two songs of the same genre play in a row (i.e. successively/adjacently) or when the songs in his playlist are repeated. Help Polycarpus count the number of different sequences of songs (their order matters), the total duration is exactly $T$, such that there are no two consecutive songs of the same genre in them and all the songs in the playlist are different. -----Input----- The first line of the input contains two integers $n$ and $T$ ($1 \le n \le 15, 1 \le T \le 225$) — the number of songs in the player and the required total duration, respectively. Next, the $n$ lines contain descriptions of songs: the $i$-th line contains two integers $t_i$ and $g_i$ ($1 \le t_i \le 15, 1 \le g_i \le 3$) — the duration of the $i$-th song and its genre, respectively. -----Output----- Output one integer — the number of different sequences of songs, the total length of exactly $T$, such that there are no two consecutive songs of the same genre in them and all the songs in the playlist are different. Since the answer may be huge, output it modulo $10^9 + 7$ (that is, the remainder when dividing the quantity by $10^9 + 7$). -----Examples----- Input 3 3 1 1 1 2 1 3 Output 6 Input 3 3 1 1 1 1 1 3 Output 2 Input 4 10 5 3 2 1 3 2 5 1 Output 10 -----Note----- In the first example, Polycarp can make any of the $6$ possible playlist by rearranging the available songs: $[1, 2, 3]$, $[1, 3, 2]$, $[2, 1, 3]$, $[2, 3, 1]$, $[3, 1, 2]$ and $[3, 2, 1]$ (indices of the songs are given). In the second example, the first and second songs cannot go in succession (since they have the same genre). Thus, Polycarp can create a playlist in one of $2$ possible ways: $[1, 3, 2]$ and $[2, 3, 1]$ (indices of the songs are given). In the third example, Polycarp can make the following playlists: $[1, 2, 3]$, $[1, 3, 2]$, $[2, 1, 3]$, $[2, 3, 1]$, $[3, 1, 2]$, $[3, 2, 1]$, $[1, 4]$, $[4, 1]$, $[2, 3, 4]$ and $[4, 3, 2]$ (indices of the songs are given). 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 factorial def lol(n): if n == 1: yield [0] yield [1] else: for p in lol(n - 1): p.append(0) yield p p[-1] = 1 yield p p.pop() def sp(g1, g2, g3, f): if g1 == 0: if g2 == g3: return 2 elif abs(g2 - g3) == 1: return 1 else: return 0 elif g2 == 0: if g1 == g3: return 2 elif abs(g1 - g3) == 1: return 1 else: return 0 elif g3 == 0: if g2 == g1: return 2 elif abs(g2 - g1) == 1: return 1 else: return 0 else: if f == 1: b = sp(g1, g2 - 1, g3, 2) c = sp(g1, g2, g3 - 1, 3) return b + c elif f == 2: a = sp(g1 - 1, g2, g3, 1) c = sp(g1, g2, g3 - 1, 3) return a + c elif f == 3: a = sp(g1 - 1, g2, g3, 1) b = sp(g1, g2 - 1, g3, 2) return a + b else: a = sp(g1 - 1, g2, g3, 1) b = sp(g1, g2 - 1, g3, 2) c = sp(g1, g2, g3 - 1, 3) return a + b + c n, T = map(int, input().split()) S = [] cnt = 0 M = 10 ** 9 + 7 for i in range(n): S.append(list(map(int, input().split()))) for p in lol(n): d = 0 g1, g2, g3 = 0, 0, 0 for i in range(n): if p[i]: d += S[i][0] if S[i][1] == 1: g1 += 1 elif S[i][1] == 2: g2 += 1 elif S[i][1] == 3: g3 += 1 if d == T: cnt += factorial(g1) * factorial(g2) * factorial(g3) * sp(g1, g2, g3, 0) cnt %= M print(cnt) ```
vfc_10066
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1185/G1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 3\n1 1\n1 2\n1 3\n", "output": "6\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 3\n1 1\n1 1\n1 3\n", "output": "2\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
79
Solve the following coding problem using the programming language python: Vivek initially has an empty array $a$ and some integer constant $m$. He performs the following algorithm: Select a random integer $x$ uniformly in range from $1$ to $m$ and append it to the end of $a$. Compute the greatest common divisor of integers in $a$. In case it equals to $1$, break Otherwise, return to step $1$. Find the expected length of $a$. It can be shown that it can be represented as $\frac{P}{Q}$ where $P$ and $Q$ are coprime integers and $Q\neq 0 \pmod{10^9+7}$. Print the value of $P \cdot Q^{-1} \pmod{10^9+7}$. -----Input----- The first and only line contains a single integer $m$ ($1 \leq m \leq 100000$). -----Output----- Print a single integer — the expected length of the array $a$ written as $P \cdot Q^{-1} \pmod{10^9+7}$. -----Examples----- Input 1 Output 1 Input 2 Output 2 Input 4 Output 333333338 -----Note----- In the first example, since Vivek can choose only integers from $1$ to $1$, he will have $a=[1]$ after the first append operation, and after that quit the algorithm. Hence the length of $a$ is always $1$, so its expected value is $1$ as well. In the second example, Vivek each time will append either $1$ or $2$, so after finishing the algorithm he will end up having some number of $2$'s (possibly zero), and a single $1$ in the end. The expected length of the list is $1\cdot \frac{1}{2} + 2\cdot \frac{1}{2^2} + 3\cdot \frac{1}{2^3} + \ldots = 2$. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python big = 100010 def gen_mu(): mu = [1]*big mu[0] = 0 P = [True]*big P[0] = P[1] = False for i in range(2,big): if P[i]: j = i while j<big: P[j] = False mu[j] *= -1 j += i j = i*i while j<big: mu[j] = 0 j += i*i return mu m = int(input()) mu = gen_mu() MOD = 10**9+7 def mod_inv(x): return pow(x, MOD-2, MOD) s = 1 for i in range(2,big): # p is probabilty that i | a random number [1,m] p = (m//i)*mod_inv(m) s += (-mu[i])*(p)*mod_inv(1-p) print(s%MOD) ```
vfc_10070
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1139/D", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n", "output": "2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n", "output": "333333338\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n", "output": "2\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
81
Solve the following coding problem using the programming language python: Neko loves divisors. During the latest number theory lesson, he got an interesting exercise from his math teacher. Neko has two integers $a$ and $b$. His goal is to find a non-negative integer $k$ such that the least common multiple of $a+k$ and $b+k$ is the smallest possible. If there are multiple optimal integers $k$, he needs to choose the smallest one. Given his mathematical talent, Neko had no trouble getting Wrong Answer on this problem. Can you help him solve it? -----Input----- The only line contains two integers $a$ and $b$ ($1 \le a, b \le 10^9$). -----Output----- Print the smallest non-negative integer $k$ ($k \ge 0$) such that the lowest common multiple of $a+k$ and $b+k$ is the smallest possible. If there are many possible integers $k$ giving the same value of the least common multiple, print the smallest one. -----Examples----- Input 6 10 Output 2 Input 21 31 Output 9 Input 5 10 Output 0 -----Note----- In the first test, one should choose $k = 2$, as the least common multiple of $6 + 2$ and $10 + 2$ is $24$, which is the smallest least common multiple possible. 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 gcd a, b = list(map(int, input().split())) if b < a: a, b = b, a if a == b: print(0) return c = b - a i = 1 ans = a * b // gcd(a, b) def get(x): A = (a + x - 1) // x * x B = A - a + b return A * B // gcd(A, B), A r = 0 while i * i <= c: if c % i == 0: A, AA = get(i) B, BB = get(c // i) if A < ans: ans = A r = AA - a if B < ans: ans = B r = BB - a if A == ans: r = min(r, AA - a) if B == ans: r = min(r, BB - a) i += 1 print(r) ```
vfc_10078
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1152/C", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "6 10\n", "output": "2", "type": "stdin_stdout" }, { "fn_name": null, "input": "21 31\n", "output": "9", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 10\n", "output": "0", "type": "stdin_stdout" }, { "fn_name": null, "input": "1924 5834\n", "output": "31", "type": "stdin_stdout" }, { "fn_name": null, "input": "9911 666013\n", "output": "318140", "type": "stdin_stdout" } ] }
apps
verifiable_code
82
Solve the following coding problem using the programming language python: Noora is a student of one famous high school. It's her final year in school — she is going to study in university next year. However, she has to get an «A» graduation certificate in order to apply to a prestigious one. In school, where Noora is studying, teachers are putting down marks to the online class register, which are integers from 1 to k. The worst mark is 1, the best is k. Mark that is going to the certificate, is calculated as an average of all the marks, rounded to the closest integer. If several answers are possible, rounding up is produced. For example, 7.3 is rounded to 7, but 7.5 and 7.8784 — to 8. For instance, if Noora has marks [8, 9], then the mark to the certificate is 9, because the average is equal to 8.5 and rounded to 9, but if the marks are [8, 8, 9], Noora will have graduation certificate with 8. To graduate with «A» certificate, Noora has to have mark k. Noora got n marks in register this year. However, she is afraid that her marks are not enough to get final mark k. Noora decided to ask for help in the internet, where hacker Leha immediately responded to her request. He is ready to hack class register for Noora and to add Noora any number of additional marks from 1 to k. At the same time, Leha want his hack be unseen to everyone, so he decided to add as less as possible additional marks. Please help Leha to calculate the minimal number of marks he has to add, so that final Noora's mark will become equal to k. -----Input----- The first line contains two integers n and k (1 ≤ n ≤ 100, 1 ≤ k ≤ 100) denoting the number of marks, received by Noora and the value of highest possible mark. The second line contains n integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ k) denoting marks received by Noora before Leha's hack. -----Output----- Print a single integer — minimal number of additional marks, that Leha has to add in order to change Noora's final mark to k. -----Examples----- Input 2 10 8 9 Output 4 Input 3 5 4 4 4 Output 3 -----Note----- Consider the first example testcase. Maximal mark is 10, Noora received two marks — 8 and 9, so current final mark is 9. To fix it, Leha can add marks [10, 10, 10, 10] (4 marks in total) to the registry, achieving Noora having average mark equal to $\frac{8 + 9 + 10 + 10 + 10 + 10}{6} = \frac{57}{6} = 9.5$. Consequently, new final mark is 10. Less number of marks won't fix the situation. In the second example Leha can add [5, 5, 5] to the registry, so that making average mark equal to 4.5, which is enough to have 5 in the certificate. 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())) s = sum(a) ans = 0 c = k - 0.5 while s / n < c: s += k n += 1 ans += 1 print(ans) ```
vfc_10082
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/810/A", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2 10\n8 9\n", "output": "4", "type": "stdin_stdout" } ] }
apps
verifiable_code
83
Solve the following coding problem using the programming language python: You are given an array of $n$ integers: $a_1, a_2, \ldots, a_n$. Your task is to find some non-zero integer $d$ ($-10^3 \leq d \leq 10^3$) such that, after each number in the array is divided by $d$, the number of positive numbers that are presented in the array is greater than or equal to half of the array size (i.e., at least $\lceil\frac{n}{2}\rceil$). Note that those positive numbers do not need to be an integer (e.g., a $2.5$ counts as a positive number). If there are multiple values of $d$ that satisfy the condition, you may print any of them. In case that there is no such $d$, print a single integer $0$. Recall that $\lceil x \rceil$ represents the smallest integer that is not less than $x$ and that zero ($0$) is neither positive nor negative. -----Input----- The first line contains one integer $n$ ($1 \le n \le 100$) — the number of elements in the array. The second line contains $n$ space-separated integers $a_1, a_2, \ldots, a_n$ ($-10^3 \le a_i \le 10^3$). -----Output----- Print one integer $d$ ($-10^3 \leq d \leq 10^3$ and $d \neq 0$) that satisfies the given condition. If there are multiple values of $d$ that satisfy the condition, you may print any of them. In case that there is no such $d$, print a single integer $0$. -----Examples----- Input 5 10 0 -7 2 6 Output 4 Input 7 0 0 1 -1 0 0 2 Output 0 -----Note----- In the first sample, $n = 5$, so we need at least $\lceil\frac{5}{2}\rceil = 3$ positive numbers after division. If $d = 4$, the array after division is $[2.5, 0, -1.75, 0.5, 1.5]$, in which there are $3$ positive numbers (namely: $2.5$, $0.5$, and $1.5$). In the second sample, there is no valid $d$, so $0$ should be printed. 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()) ar=list(map(int,input().split())) pos=0 neg=0 for a in ar: if(a>0):pos+=1 elif a<0:neg+=1 if(pos*2>=n): print(1) elif neg*2>=n: print(-1) else: print(0) ```
vfc_10086
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1130/A", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n10 0 -7 2 6\n", "output": "1", "type": "stdin_stdout" }, { "fn_name": null, "input": "7\n0 0 1 -1 0 0 2\n", "output": "0", "type": "stdin_stdout" } ] }
apps
verifiable_code
84
Solve the following coding problem using the programming language python: There are n shovels in Polycarp's shop. The i-th shovel costs i burles, that is, the first shovel costs 1 burle, the second shovel costs 2 burles, the third shovel costs 3 burles, and so on. Polycarps wants to sell shovels in pairs. Visitors are more likely to buy a pair of shovels if their total cost ends with several 9s. Because of this, Polycarp wants to choose a pair of shovels to sell in such a way that the sum of their costs ends with maximum possible number of nines. For example, if he chooses shovels with costs 12345 and 37454, their total cost is 49799, it ends with two nines. You are to compute the number of pairs of shovels such that their total cost ends with maximum possible number of nines. Two pairs are considered different if there is a shovel presented in one pair, but not in the other. -----Input----- The first line contains a single integer n (2 ≤ n ≤ 10^9) — the number of shovels in Polycarp's shop. -----Output----- Print the number of pairs of shovels such that their total cost ends with maximum possible number of nines. Note that it is possible that the largest number of 9s at the end is 0, then you should count all such ways. It is guaranteed that for every n ≤ 10^9 the answer doesn't exceed 2·10^9. -----Examples----- Input 7 Output 3 Input 14 Output 9 Input 50 Output 1 -----Note----- In the first example the maximum possible number of nines at the end is one. Polycarp cah choose the following pairs of shovels for that purpose: 2 and 7; 3 and 6; 4 and 5. In the second example the maximum number of nines at the end of total cost of two shovels is one. The following pairs of shovels suit Polycarp: 1 and 8; 2 and 7; 3 and 6; 4 and 5; 5 and 14; 6 and 13; 7 and 12; 8 and 11; 9 and 10. In the third example it is necessary to choose shovels 49 and 50, because the sum of their cost is 99, that means that the total number of nines is equal to two, which is maximum possible for n = 50. 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 as cin from sys import stdout as cout def main(): n = int(cin.readline()) o = 0 for x in range(9, 0, -1): if 10 ** x // 2 <= n: ##print(x) for i in range(9): q = 10 ** x * (i + 1) // 2 - 1 if q <= n: o += min(q, n - q) print(o) return print(n * (n - 1) // 2) main() ```
vfc_10090
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/899/D", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "7\n", "output": "3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "14\n", "output": "9\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "50\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "999999999\n", "output": "499999999\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "15\n", "output": "11\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n", "output": "3\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
85
Solve the following coding problem using the programming language python: Polycarpus likes giving presents to Paraskevi. He has bought two chocolate bars, each of them has the shape of a segmented rectangle. The first bar is a_1 × b_1 segments large and the second one is a_2 × b_2 segments large. Polycarpus wants to give Paraskevi one of the bars at the lunch break and eat the other one himself. Besides, he wants to show that Polycarpus's mind and Paraskevi's beauty are equally matched, so the two bars must have the same number of squares. To make the bars have the same number of squares, Polycarpus eats a little piece of chocolate each minute. Each minute he does the following: he either breaks one bar exactly in half (vertically or horizontally) and eats exactly a half of the bar, or he chips of exactly one third of a bar (vertically or horizontally) and eats exactly a third of the bar. In the first case he is left with a half, of the bar and in the second case he is left with two thirds of the bar. Both variants aren't always possible, and sometimes Polycarpus cannot chip off a half nor a third. For example, if the bar is 16 × 23, then Polycarpus can chip off a half, but not a third. If the bar is 20 × 18, then Polycarpus can chip off both a half and a third. If the bar is 5 × 7, then Polycarpus cannot chip off a half nor a third. What is the minimum number of minutes Polycarpus needs to make two bars consist of the same number of squares? Find not only the required minimum number of minutes, but also the possible sizes of the bars after the process. -----Input----- The first line of the input contains integers a_1, b_1 (1 ≤ a_1, b_1 ≤ 10^9) — the initial sizes of the first chocolate bar. The second line of the input contains integers a_2, b_2 (1 ≤ a_2, b_2 ≤ 10^9) — the initial sizes of the second bar. You can use the data of type int64 (in Pascal), long long (in С++), long (in Java) to process large integers (exceeding 2^31 - 1). -----Output----- In the first line print m — the sought minimum number of minutes. In the second and third line print the possible sizes of the bars after they are leveled in m minutes. Print the sizes using the format identical to the input format. Print the sizes (the numbers in the printed pairs) in any order. The second line must correspond to the first bar and the third line must correspond to the second bar. If there are multiple solutions, print any of them. If there is no solution, print a single line with integer -1. -----Examples----- Input 2 6 2 3 Output 1 1 6 2 3 Input 36 5 10 16 Output 3 16 5 5 16 Input 3 5 2 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 a,b=list(map(int,input().split())) c,d=list(map(int,input().split())) e=a*b f=c*d n=0 while e%2==0:e=e//2 while e%3==0:e=e//3 while f%2==0:f=f//2 while f%3==0:f=f//3 if e!=f:print("-1") else: i=0 j=0 e=a*b f=c*d while e%3==0: e=e//3 i+=1 while f%3==0: f=f//3 j+=1 k=i-j if k>0: for i in range(k): n+=1 if a%3==0:a=a*2//3 else:b=b*2//3 else: for i in range(0-k): n+=1 if c%3==0:c=c*2//3 else:d=d*2//3 e=a*b f=c*d i=0 j=0 while e%2==0: e=e//2 i+=1 while f%2==0: f=f//2 j+=1 k=i-j if k>0: for i in range(k): n+=1 if a%2==0:a=a//2 else:b=b//2 else: for i in range(0-k): n+=1 if c%2==0:c=c//2 else:d=d//2 print(n) print(a,b) print(c,d) ```
vfc_10094
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/490/D", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2 6\n2 3\n", "output": "1\n1 6\n2 3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "36 5\n10 16\n", "output": "3\n16 5\n5 16\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 5\n2 1\n", "output": "-1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "36 5\n10 12\n", "output": "1\n24 5\n10 12\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
86
Solve the following coding problem using the programming language python: Polycarp and Vasiliy love simple logical games. Today they play a game with infinite chessboard and one pawn for each player. Polycarp and Vasiliy move in turns, Polycarp starts. In each turn Polycarp can move his pawn from cell (x, y) to (x - 1, y) or (x, y - 1). Vasiliy can move his pawn from (x, y) to one of cells: (x - 1, y), (x - 1, y - 1) and (x, y - 1). Both players are also allowed to skip move. There are some additional restrictions — a player is forbidden to move his pawn to a cell with negative x-coordinate or y-coordinate or to the cell containing opponent's pawn The winner is the first person to reach cell (0, 0). You are given the starting coordinates of both pawns. Determine who will win if both of them play optimally well. -----Input----- The first line contains four integers: x_{p}, y_{p}, x_{v}, y_{v} (0 ≤ x_{p}, y_{p}, x_{v}, y_{v} ≤ 10^5) — Polycarp's and Vasiliy's starting coordinates. It is guaranteed that in the beginning the pawns are in different cells and none of them is in the cell (0, 0). -----Output----- Output the name of the winner: "Polycarp" or "Vasiliy". -----Examples----- Input 2 1 2 2 Output Polycarp Input 4 7 7 4 Output Vasiliy -----Note----- In the first sample test Polycarp starts in (2, 1) and will move to (1, 1) in the first turn. No matter what his opponent is doing, in the second turn Polycarp can move to (1, 0) and finally to (0, 0) in the third turn. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python a, b, x, y = map(int, input().split()) if a >= x: if b >= y: print('Vasiliy') else: z = y - b t = max(x - z, 0) if a - z <= t: print('Polycarp') else: print('Vasiliy') else: if b <= y: print('Polycarp') else: z = x - a t = max(y - z, 0) if b - z <= t: print('Polycarp') else: print('Vasiliy') ```
vfc_10098
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/532/C", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2 1 2 2\n", "output": "Polycarp\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 7 7 4\n", "output": "Vasiliy\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "20 0 7 22\n", "output": "Polycarp\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "80 100 83 97\n", "output": "Vasiliy\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "80 100 77 103\n", "output": "Vasiliy\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "55000 60000 55003 60100\n", "output": "Polycarp\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
87
Solve the following coding problem using the programming language python: Petr wants to make a calendar for current month. For this purpose he draws a table in which columns correspond to weeks (a week is seven consequent days from Monday to Sunday), rows correspond to weekdays, and cells contain dates. For example, a calendar for January 2017 should look like on the picture: $\left. \begin{array}{|r|r|r|r|r|r|} \hline & {2} & {9} & {16} & {23} & {30} \\ \hline & {3} & {10} & {17} & {24} & {31} \\ \hline & {4} & {11} & {18} & {25} & {} \\ \hline & {5} & {12} & {19} & {26} & {} \\ \hline & {6} & {13} & {20} & {27} & {} \\ \hline & {7} & {14} & {21} & {28} & {} \\ \hline 1 & {8} & {15} & {22} & {29} & {} \\ \hline \end{array} \right.$ Petr wants to know how many columns his table should have given the month and the weekday of the first date of that month? Assume that the year is non-leap. -----Input----- The only line contain two integers m and d (1 ≤ m ≤ 12, 1 ≤ d ≤ 7) — the number of month (January is the first month, December is the twelfth) and the weekday of the first date of this month (1 is Monday, 7 is Sunday). -----Output----- Print single integer: the number of columns the table should have. -----Examples----- Input 1 7 Output 6 Input 1 1 Output 5 Input 11 6 Output 5 -----Note----- The first example corresponds to the January 2017 shown on the picture in the statements. In the second example 1-st January is Monday, so the whole month fits into 5 columns. In the third example 1-st November is Saturday and 5 columns is enough. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python import sys arr = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] a, b = list(map(int, input().split())) a -= 1 b -= 1 ctr = 1 for i in range(arr[a] - 1): b += 1 if (b == 7): b = 0 ctr += 1 print(ctr) ```
vfc_10102
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/760/A", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1 7\n", "output": "6\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 1\n", "output": "5\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "11 6\n", "output": "5\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 7\n", "output": "5\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 1\n", "output": "4\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
88
Solve the following coding problem using the programming language python: The year 2015 is almost over. Limak is a little polar bear. He has recently learnt about the binary system. He noticed that the passing year has exactly one zero in its representation in the binary system — 2015_10 = 11111011111_2. Note that he doesn't care about the number of zeros in the decimal representation. Limak chose some interval of years. He is going to count all years from this interval that have exactly one zero in the binary representation. Can you do it faster? Assume that all positive integers are always written without leading zeros. -----Input----- The only line of the input contains two integers a and b (1 ≤ a ≤ b ≤ 10^18) — the first year and the last year in Limak's interval respectively. -----Output----- Print one integer – the number of years Limak will count in his chosen interval. -----Examples----- Input 5 10 Output 2 Input 2015 2015 Output 1 Input 100 105 Output 0 Input 72057594000000000 72057595000000000 Output 26 -----Note----- In the first sample Limak's interval contains numbers 5_10 = 101_2, 6_10 = 110_2, 7_10 = 111_2, 8_10 = 1000_2, 9_10 = 1001_2 and 10_10 = 1010_2. Two of them (101_2 and 110_2) have the described property. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python def zero(strx): k = [] str2 = list(strx) for i in range(1, len(str2)): str3 = str2[:] str3[i] = '0' k.append(''.join(str3)) return k a = [] for i in range(1, 64): a += zero('1'*i) ct = 0 x, y = list(map(int, input().split(' '))) for i in a: if x <= int(i, 2) <= y: ct+=1 print(ct) ```
vfc_10106
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/611/B", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5 10\n", "output": "2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2015 2015\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "100 105\n", "output": "0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "72057594000000000 72057595000000000\n", "output": "26\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 100\n", "output": "16\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
89
Solve the following coding problem using the programming language python: You are given an integer N. Consider all possible segments on the coordinate axis with endpoints at integer points with coordinates between 0 and N, inclusive; there will be $\frac{n(n + 1)}{2}$ of them. You want to draw these segments in several layers so that in each layer the segments don't overlap (they might touch at the endpoints though). You can not move the segments to a different location on the coordinate axis. Find the minimal number of layers you have to use for the given N. -----Input----- The only input line contains a single integer N (1 ≤ N ≤ 100). -----Output----- Output a single integer - the minimal number of layers required to draw the segments for the given N. -----Examples----- Input 2 Output 2 Input 3 Output 4 Input 4 Output 6 -----Note----- As an example, here are the segments and their optimal arrangement into layers for N = 4. [Image] 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(max((i+1)*(n-i)for i in range(n))) ```
vfc_10110
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/909/B", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n", "output": "2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n", "output": "4\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n", "output": "6\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "21\n", "output": "121\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "100\n", "output": "2550\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
90
Solve the following coding problem using the programming language python: Anya loves to fold and stick. Today she decided to do just that. Anya has n cubes lying in a line and numbered from 1 to n from left to right, with natural numbers written on them. She also has k stickers with exclamation marks. We know that the number of stickers does not exceed the number of cubes. Anya can stick an exclamation mark on the cube and get the factorial of the number written on the cube. For example, if a cube reads 5, then after the sticking it reads 5!, which equals 120. You need to help Anya count how many ways there are to choose some of the cubes and stick on some of the chosen cubes at most k exclamation marks so that the sum of the numbers written on the chosen cubes after the sticking becomes equal to S. Anya can stick at most one exclamation mark on each cube. Can you do it? Two ways are considered the same if they have the same set of chosen cubes and the same set of cubes with exclamation marks. -----Input----- The first line of the input contains three space-separated integers n, k and S (1 ≤ n ≤ 25, 0 ≤ k ≤ n, 1 ≤ S ≤ 10^16) — the number of cubes and the number of stickers that Anya has, and the sum that she needs to get. The second line contains n positive integers a_{i} (1 ≤ a_{i} ≤ 10^9) — the numbers, written on the cubes. The cubes in the input are described in the order from left to right, starting from the first one. Multiple cubes can contain the same numbers. -----Output----- Output the number of ways to choose some number of cubes and stick exclamation marks on some of them so that the sum of the numbers became equal to the given number S. -----Examples----- Input 2 2 30 4 3 Output 1 Input 2 2 7 4 3 Output 1 Input 3 1 1 1 1 1 Output 6 -----Note----- In the first sample the only way is to choose both cubes and stick an exclamation mark on each of them. In the second sample the only way is to choose both cubes but don't stick an exclamation mark on any of them. In the third sample it is possible to choose any of the cubes in three ways, and also we may choose to stick or not to stick the exclamation mark on it. So, the total number of ways is six. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python fact = [ 1 ] for i in range( 1, 20, 1 ): fact.append( fact[ i - 1 ] * i ) from collections import defaultdict N, K, S = list(map( int, input().split() )) A = list( map( int, input().split() ) ) ldp = [ [ defaultdict( int ) for i in range( K + 1 ) ] for j in range( 2 ) ] ldp[ 0 ][ 0 ][ 0 ] = 1 for i in range( N // 2 ): for j in range( K + 1 ): ldp[ ~ i & 1 ][ j ].clear() for j in range( K + 1 ): for key in ldp[ i & 1 ][ j ]: ldp[ ~ i & 1 ][ j ][ key ] += ldp[ i & 1 ][ j ][ key ] # toranai ldp[ ~ i & 1 ][ j ][ key + A[ i ] ] += ldp[ i & 1 ][ j ][ key ] # toru if j + 1 <= K and A[ i ] <= 18: ldp[ ~ i & 1 ][ j + 1 ][ key + fact[ A[ i ] ] ] += ldp[ i & 1 ][ j ][ key ] # kaijyou totte toru rdp = [ [ defaultdict( int ) for i in range( K + 1 ) ] for j in range( 2 ) ] rdp[ 0 ][ 0 ][ 0 ] = 1 for i in range( N - N // 2 ): for j in range( K + 1 ): rdp[ ~ i & 1 ][ j ].clear() for j in range( K + 1 ): for key in rdp[ i & 1 ][ j ]: rdp[ ~ i & 1 ][ j ][ key ] += rdp[ i & 1 ][ j ][ key ] rdp[ ~ i & 1 ][ j ][ key + A[ N // 2 + i ] ] += rdp[ i & 1 ][ j ][ key ] if j + 1 <= K and A[ N // 2 + i ] <= 18: rdp[ ~ i & 1 ][ j + 1 ][ key + fact[ A[ N // 2 + i ] ] ] += rdp[ i & 1 ][ j ][ key ] ans = 0 for i in range( K + 1 ): for key in ldp[ N // 2 & 1 ][ i ]: for j in range( 0, K - i + 1, 1 ): ans += ldp[ N // 2 & 1 ][ i ][ key ] * rdp[ N - N // 2 & 1 ][ j ][ S - key ] print( ans ) ```
vfc_10114
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/525/E", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2 2 30\n4 3\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 2 7\n4 3\n", "output": "1\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
91
Solve the following coding problem using the programming language python: Suppose you are performing the following algorithm. There is an array $v_1, v_2, \dots, v_n$ filled with zeroes at start. The following operation is applied to the array several times — at $i$-th step ($0$-indexed) you can: either choose position $pos$ ($1 \le pos \le n$) and increase $v_{pos}$ by $k^i$; or not choose any position and skip this step. You can choose how the algorithm would behave on each step and when to stop it. The question is: can you make array $v$ equal to the given array $a$ ($v_j = a_j$ for each $j$) after some step? -----Input----- The first line contains one integer $T$ ($1 \le T \le 1000$) — the number of test cases. Next $2T$ lines contain test cases — two lines per test case. The first line of each test case contains two integers $n$ and $k$ ($1 \le n \le 30$, $2 \le k \le 100$) — the size of arrays $v$ and $a$ and value $k$ used in the algorithm. The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($0 \le a_i \le 10^{16}$) — the array you'd like to achieve. -----Output----- For each test case print YES (case insensitive) if you can achieve the array $a$ after some step or NO (case insensitive) otherwise. -----Example----- Input 5 4 100 0 0 0 0 1 2 1 3 4 1 4 1 3 2 0 1 3 3 9 0 59049 810 Output YES YES NO NO YES -----Note----- In the first test case, you can stop the algorithm before the $0$-th step, or don't choose any position several times and stop the algorithm. In the second test case, you can add $k^0$ to $v_1$ and stop the algorithm. In the third test case, you can't make two $1$ in the array $v$. In the fifth test case, you can skip $9^0$ and $9^1$, then add $9^2$ and $9^3$ to $v_3$, skip $9^4$ and finally, add $9^5$ to $v_2$. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python t = int(input()) for _ in range(t): n,k = list(map(int,input().split())) a = list(map(int,input().split())) for i in range(60, -1, -1): m = k ** i for j in range(n): if a[j] >= m: a[j] -= m break if all(i == 0 for i in a): print('YES') else: print('NO') ```
vfc_10118
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1312/C", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n4 100\n0 0 0 0\n1 2\n1\n3 4\n1 4 1\n3 2\n0 1 3\n3 9\n0 59049 810\n", "output": "YES\nYES\nNO\nNO\nYES\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n5 2\n1 2 4 8 17\n2 3\n1 2\n4 3\n10 4 13 12\n", "output": "NO\nNO\nNO\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n1 10\n10000000000000000\n", "output": "YES\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n1 100\n10000000000000000\n", "output": "YES\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n2 2\n2251799813685248 2251799813685248\n", "output": "NO\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
92
Solve the following coding problem using the programming language python: Let's denote d(n) as the number of divisors of a positive integer n. You are given three integers a, b and c. Your task is to calculate the following sum: $\sum_{i = 1}^{a} \sum_{j = 1}^{b} \sum_{k = 1}^{c} d(i \cdot j \cdot k)$ Find the sum modulo 1073741824 (2^30). -----Input----- The first line contains three space-separated integers a, b and c (1 ≤ a, b, c ≤ 100). -----Output----- Print a single integer — the required sum modulo 1073741824 (2^30). -----Examples----- Input 2 2 2 Output 20 Input 5 6 7 Output 1520 -----Note----- For the first example. d(1·1·1) = d(1) = 1; d(1·1·2) = d(2) = 2; d(1·2·1) = d(2) = 2; d(1·2·2) = d(4) = 3; d(2·1·1) = d(2) = 2; d(2·1·2) = d(4) = 3; d(2·2·1) = d(4) = 3; d(2·2·2) = d(8) = 4. So the result is 1 + 2 + 2 + 3 + 2 + 3 + 3 + 4 = 20. 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 = map(int, input().split()) d = 1073741824 p = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97] t = [{} for i in range(101)] ans = {} for i in p: j = i m = 1 while j < 101: for k in range(j, 101, j): t[k][i] = m j = j * i m += 1 s = 0 for i in range(1, a + 1): for j in range(1, b + 1): q = {} for x in t[i].keys() | t[j].keys(): q[x] = t[i].get(x, 0) + t[j].get(x, 0) ij = i * j for k in range(1, c + 1): ijk = ij * k if ijk in ans: s += ans[ijk] else: y = 1 for x in q.keys() | t[k].keys(): y = y * (q.get(x, 0) + t[k].get(x, 0) + 1) ans[ijk] = y s += y print(s) ```
vfc_10122
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/236/B", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2 2 2\n", "output": "20\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 6 7\n", "output": "1520\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "91 42 25\n", "output": "3076687\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
93
Solve the following coding problem using the programming language python: Bessie the cow and her best friend Elsie each received a sliding puzzle on Pi Day. Their puzzles consist of a 2 × 2 grid and three tiles labeled 'A', 'B', and 'C'. The three tiles sit on top of the grid, leaving one grid cell empty. To make a move, Bessie or Elsie can slide a tile adjacent to the empty cell into the empty cell as shown below: $\rightarrow$ In order to determine if they are truly Best Friends For Life (BFFLs), Bessie and Elsie would like to know if there exists a sequence of moves that takes their puzzles to the same configuration (moves can be performed in both puzzles). Two puzzles are considered to be in the same configuration if each tile is on top of the same grid cell in both puzzles. Since the tiles are labeled with letters, rotations and reflections are not allowed. -----Input----- The first two lines of the input consist of a 2 × 2 grid describing the initial configuration of Bessie's puzzle. The next two lines contain a 2 × 2 grid describing the initial configuration of Elsie's puzzle. The positions of the tiles are labeled 'A', 'B', and 'C', while the empty cell is labeled 'X'. It's guaranteed that both puzzles contain exactly one tile with each letter and exactly one empty position. -----Output----- Output "YES"(without quotes) if the puzzles can reach the same configuration (and Bessie and Elsie are truly BFFLs). Otherwise, print "NO" (without quotes). -----Examples----- Input AB XC XB AC Output YES Input AB XC AC BX Output NO -----Note----- The solution to the first sample is described by the image. All Bessie needs to do is slide her 'A' tile down. In the second sample, the two puzzles can never be in the same configuration. Perhaps Bessie and Elsie are not meant to be friends after all... 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, d = input(), input(), input(), input() a = a + b[::-1] x = "X" for i in range(4): if a[i] == x: a = a[:i] + a[i + 1:] break c = c + d[::-1] for i in range(4): if c[i] == x: c = c[:i] + c[i + 1:] break flag = False for i in range(4): if a == c: flag = True c = c[1:] + c[0] if flag: print("YES") else: print("NO") ```
vfc_10126
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/645/A", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "AB\nXC\nXB\nAC\n", "output": "YES\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "AB\nXC\nAC\nBX\n", "output": "NO\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "XC\nBA\nCB\nAX\n", "output": "NO\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "AB\nXC\nAX\nCB\n", "output": "YES\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "CB\nAX\nXA\nBC\n", "output": "YES\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "BC\nXA\nBA\nXC\n", "output": "NO\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
94
Solve the following coding problem using the programming language python: Alexander is learning how to convert numbers from the decimal system to any other, however, he doesn't know English letters, so he writes any number only as a decimal number, it means that instead of the letter A he will write the number 10. Thus, by converting the number 475 from decimal to hexadecimal system, he gets 11311 (475 = 1·16^2 + 13·16^1 + 11·16^0). Alexander lived calmly until he tried to convert the number back to the decimal number system. Alexander remembers that he worked with little numbers so he asks to find the minimum decimal number so that by converting it to the system with the base n he will get the number k. -----Input----- The first line contains the integer n (2 ≤ n ≤ 10^9). The second line contains the integer k (0 ≤ k < 10^60), it is guaranteed that the number k contains no more than 60 symbols. All digits in the second line are strictly less than n. Alexander guarantees that the answer exists and does not exceed 10^18. The number k doesn't contain leading zeros. -----Output----- Print the number x (0 ≤ x ≤ 10^18) — the answer to the problem. -----Examples----- Input 13 12 Output 12 Input 16 11311 Output 475 Input 20 999 Output 3789 Input 17 2016 Output 594 -----Note----- In the first example 12 could be obtained by converting two numbers to the system with base 13: 12 = 12·13^0 or 15 = 1·13^1 + 2·13^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()) s=input() pw=[1] last=1 for i in range(70): if (last>1e19): break pw.append(last*n) last=last*n dp=[1e19]*100 for i in range(100): dp[i]=[1e19]*100 dp[len(s)][0]=0 for i in range(len(s),-1,-1): for power in range(0,len(pw)): cur='' for j in range(i-1,-1,-1): cur=s[j]+cur if (int(cur)>n or int(cur)*pw[power]>1e19): break; if ((cur[0]!='0' or len(cur)==1) and int(cur)<n): dp[j][power+1]=min(dp[j][power+1],dp[i][power]+int(cur)*pw[power]) print(min(dp[0])) ```
vfc_10130
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/758/D", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "13\n12\n", "output": "12", "type": "stdin_stdout" } ] }
apps
verifiable_code
95
Solve the following coding problem using the programming language python: Array of integers is unimodal, if: it is strictly increasing in the beginning; after that it is constant; after that it is strictly decreasing. The first block (increasing) and the last block (decreasing) may be absent. It is allowed that both of this blocks are absent. For example, the following three arrays are unimodal: [5, 7, 11, 11, 2, 1], [4, 4, 2], [7], but the following three are not unimodal: [5, 5, 6, 6, 1], [1, 2, 1, 2], [4, 5, 5, 6]. Write a program that checks if an array is unimodal. -----Input----- The first line contains integer n (1 ≤ n ≤ 100) — the number of elements in the array. The second line contains n integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 1 000) — the elements of the array. -----Output----- Print "YES" if the given array is unimodal. Otherwise, print "NO". You can output each letter in any case (upper or lower). -----Examples----- Input 6 1 5 5 5 4 2 Output YES Input 5 10 20 30 20 10 Output YES Input 4 1 2 1 2 Output NO Input 7 3 3 3 3 3 3 3 Output YES -----Note----- In the first example the array is unimodal, because it is strictly increasing in the beginning (from position 1 to position 2, inclusively), that it is constant (from position 2 to position 4, inclusively) and then it is strictly decreasing (from position 4 to position 6, inclusively). 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()) L = list(map(int, input().split())) i = 0 a = 0 while i < n and L[i] > a: a = L[i] i += 1 while i < n and L[i] == a: i += 1 while i < n and L[i] < a: a = L[i] i += 1 if i == n: print("YES") else: print("NO") ```
vfc_10134
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/831/A", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "6\n1 5 5 5 4 2\n", "output": "YES\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n10 20 30 20 10\n", "output": "YES\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
96
Solve the following coding problem using the programming language python: At first, let's define function $f(x)$ as follows: $$ \begin{matrix} f(x) & = & \left\{ \begin{matrix} \frac{x}{2} & \mbox{if } x \text{ is even} \\ x - 1 & \mbox{otherwise } \end{matrix} \right. \end{matrix} $$ We can see that if we choose some value $v$ and will apply function $f$ to it, then apply $f$ to $f(v)$, and so on, we'll eventually get $1$. Let's write down all values we get in this process in a list and denote this list as $path(v)$. For example, $path(1) = [1]$, $path(15) = [15, 14, 7, 6, 3, 2, 1]$, $path(32) = [32, 16, 8, 4, 2, 1]$. Let's write all lists $path(x)$ for every $x$ from $1$ to $n$. The question is next: what is the maximum value $y$ such that $y$ is contained in at least $k$ different lists $path(x)$? Formally speaking, you need to find maximum $y$ such that $\left| \{ x ~|~ 1 \le x \le n, y \in path(x) \} \right| \ge k$. -----Input----- The first line contains two integers $n$ and $k$ ($1 \le k \le n \le 10^{18}$). -----Output----- Print the only integer — the maximum value that is contained in at least $k$ paths. -----Examples----- Input 11 3 Output 5 Input 11 6 Output 4 Input 20 20 Output 1 Input 14 5 Output 6 Input 1000000 100 Output 31248 -----Note----- In the first example, the answer is $5$, since $5$ occurs in $path(5)$, $path(10)$ and $path(11)$. In the second example, the answer is $4$, since $4$ occurs in $path(4)$, $path(5)$, $path(8)$, $path(9)$, $path(10)$ and $path(11)$. In the third example $n = k$, so the answer is $1$, since $1$ is the only number occuring in all paths for integers from $1$ to $20$. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python def gg(n,lol): ans = 0 cur = 1 lol2 = lol while(2*lol+1<=n): cur *= 2 ans += cur lol = 2*lol+1 lol2 *= 2 if lol2*2 <= n: ans += n-lol2*2+1 return ans n,k = list(map(int,input().split())) low = 1 high = n//2 res = 1 while low <= high: mid = (low+high)//2 if gg(n,mid) >= k: res = mid low = mid+1 else: high = mid-1 if n == k: print(1) elif(gg(n,res)-1-gg(n,res*2) >= k): print(res*2+1) else: print(res*2) ```
vfc_10138
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1271/E", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "11 3\n", "output": "5\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
97
Solve the following coding problem using the programming language python: Consider a billiard table of rectangular size $n \times m$ with four pockets. Let's introduce a coordinate system with the origin at the lower left corner (see the picture). [Image] There is one ball at the point $(x, y)$ currently. Max comes to the table and strikes the ball. The ball starts moving along a line that is parallel to one of the axes or that makes a $45^{\circ}$ angle with them. We will assume that: the angles between the directions of the ball before and after a collision with a side are equal, the ball moves indefinitely long, it only stops when it falls into a pocket, the ball can be considered as a point, it falls into a pocket if and only if its coordinates coincide with one of the pockets, initially the ball is not in a pocket. Note that the ball can move along some side, in this case the ball will just fall into the pocket at the end of the side. Your task is to determine whether the ball will fall into a pocket eventually, and if yes, which of the four pockets it will be. -----Input----- The only line contains $6$ integers $n$, $m$, $x$, $y$, $v_x$, $v_y$ ($1 \leq n, m \leq 10^9$, $0 \leq x \leq n$; $0 \leq y \leq m$; $-1 \leq v_x, v_y \leq 1$; $(v_x, v_y) \neq (0, 0)$) — the width of the table, the length of the table, the $x$-coordinate of the initial position of the ball, the $y$-coordinate of the initial position of the ball, the $x$-component of its initial speed and the $y$-component of its initial speed, respectively. It is guaranteed that the ball is not initially in a pocket. -----Output----- Print the coordinates of the pocket the ball will fall into, or $-1$ if the ball will move indefinitely. -----Examples----- Input 4 3 2 2 -1 1 Output 0 0 Input 4 4 2 0 1 1 Output -1 Input 10 10 10 1 -1 0 Output -1 -----Note----- The first sample: [Image] The second sample: [Image] In the third sample the ball will never change its $y$ coordinate, so the ball will never fall into a pocket. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python def INV(a, m) : m0 = m y = 0 x = 1 if (m == 1) : return 0 while (a > 1) : q = a // m t = m m = a % m a = t t = y y = x - q * y x = t if (x < 0) : x = x + m0 return x def GCD(a, b): if a == 0: return b return GCD(b%a,a) def solve(): n, m, x, y, vx, vy = list(map(int, input().split())) if vx == 0: if x != 0 and x != n: print("-1") return 0 ans = [0,0] ans[0] = x if vy < 0: ans[1] = 0 else: ans[1] = m print(ans[0],ans[1]) return 0 if vy == 0: if y != 0 and y != m: print("-1") return 0 ans = [0,0] ans[1] = y if vx < 0: ans[0] = 0 else: ans[0] = n print(ans[0],ans[1]) return 0 if vx == -1 and x == 0: vx = 1 if vx == 1 and x == n: vx = -1 if vy == -1 and y == 0: vy = 1 if vy == 1 and y == m: vy = -1 g = GCD(n,m) m1 = n m2 = m a1 = -1 * vx * x % m1 a2 = -1 * vy * y % m2 if a1 % g != a2 % g: print("-1") return 0 if GCD(m1//g,m2) == 1: m1 = m1 // g else: m2 = m2 // g m1_bar = INV(m2,m1) m2_bar = INV(m1,m2) k = (a1 * m1_bar*m2 + a2 * m2_bar*m1) % (m1*m2) rowtouch = ((k+m-1)//m) % 2 coltouch = ((k+n-1)//n) % 2 ans = [0,0] if vx == 1: ans[0] = 0 else: ans[0] = n if vy == 1: ans[1] = 0 else: ans[1] = m if rowtouch == 1: ans[1] = m-ans[1] if coltouch == 1: ans[0] = n-ans[0] print(ans[0],ans[1]) return 0 solve() ```
vfc_10142
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/982/E", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4 3 2 2 -1 1\n", "output": "0 0", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 4 2 0 1 1\n", "output": "-1", "type": "stdin_stdout" }, { "fn_name": null, "input": "10 10 10 1 -1 0\n", "output": "-1", "type": "stdin_stdout" }, { "fn_name": null, "input": "1000000000 1000000000 1 1000000000 0 1\n", "output": "-1", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 1 1 0 -1 -1\n", "output": "0 1", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 2 1 2 1 1\n", "output": "-1", "type": "stdin_stdout" } ] }
apps
verifiable_code
98
Solve the following coding problem using the programming language python: Gerald bought two very rare paintings at the Sotheby's auction and he now wants to hang them on the wall. For that he bought a special board to attach it to the wall and place the paintings on the board. The board has shape of an a_1 × b_1 rectangle, the paintings have shape of a a_2 × b_2 and a_3 × b_3 rectangles. Since the paintings are painted in the style of abstract art, it does not matter exactly how they will be rotated, but still, one side of both the board, and each of the paintings must be parallel to the floor. The paintings can touch each other and the edges of the board, but can not overlap or go beyond the edge of the board. Gerald asks whether it is possible to place the paintings on the board, or is the board he bought not large enough? -----Input----- The first line contains two space-separated numbers a_1 and b_1 — the sides of the board. Next two lines contain numbers a_2, b_2, a_3 and b_3 — the sides of the paintings. All numbers a_{i}, b_{i} in the input are integers and fit into the range from 1 to 1000. -----Output----- If the paintings can be placed on the wall, print "YES" (without the quotes), and if they cannot, print "NO" (without the quotes). -----Examples----- Input 3 2 1 3 2 1 Output YES Input 5 5 3 3 3 3 Output NO Input 4 2 2 3 1 2 Output YES -----Note----- That's how we can place the pictures in the first test: [Image] And that's how we can do it in the third one. [Image] The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python a, b = [int(i) for i in input().split()] c, d = [int(i) for i in input().split()] e, f = [int(i) for i in input().split()] if c+e <=a and max(d,f) <=b: print("YES") elif c+e <=b and max(d,f) <=a: print("YES") elif c+f <=a and max(d,e) <=b: print("YES") elif c+f <=b and max(d,e) <=a: print("YES") elif d+e <=a and max(c,f) <=b: print("YES") elif d+e <=b and max(c,f) <=a: print("YES") elif d+f <=a and max(c,e) <=b: print("YES") elif d+f <=b and max(c,e) <=a: print("YES") else: print("NO") ```
vfc_10146
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/560/B", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 2\n1 3\n2 1\n", "output": "YES\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 5\n3 3\n3 3\n", "output": "NO\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 2\n2 3\n1 2\n", "output": "YES\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 3\n1 1\n1 1\n", "output": "YES\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1000 1000\n999 999\n1 1000\n", "output": "YES\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
99
Solve the following coding problem using the programming language python: Masha really loves algebra. On the last lesson, her strict teacher Dvastan gave she new exercise. You are given geometric progression b defined by two integers b_1 and q. Remind that a geometric progression is a sequence of integers b_1, b_2, b_3, ..., where for each i > 1 the respective term satisfies the condition b_{i} = b_{i} - 1·q, where q is called the common ratio of the progression. Progressions in Uzhlyandia are unusual: both b_1 and q can equal 0. Also, Dvastan gave Masha m "bad" integers a_1, a_2, ..., a_{m}, and an integer l. Masha writes all progression terms one by one onto the board (including repetitive) while condition |b_{i}| ≤ l is satisfied (|x| means absolute value of x). There is an exception: if a term equals one of the "bad" integers, Masha skips it (doesn't write onto the board) and moves forward to the next term. But the lesson is going to end soon, so Masha has to calculate how many integers will be written on the board. In order not to get into depression, Masha asked you for help: help her calculate how many numbers she will write, or print "inf" in case she needs to write infinitely many integers. -----Input----- The first line of input contains four integers b_1, q, l, m (-10^9 ≤ b_1, q ≤ 10^9, 1 ≤ l ≤ 10^9, 1 ≤ m ≤ 10^5) — the initial term and the common ratio of progression, absolute value of maximal number that can be written on the board and the number of "bad" integers, respectively. The second line contains m distinct integers a_1, a_2, ..., a_{m} (-10^9 ≤ a_{i} ≤ 10^9) — numbers that will never be written on the board. -----Output----- Print the only integer, meaning the number of progression terms that will be written on the board if it is finite, or "inf" (without quotes) otherwise. -----Examples----- Input 3 2 30 4 6 14 25 48 Output 3 Input 123 1 2143435 4 123 11 -5453 141245 Output 0 Input 123 1 2143435 4 54343 -13 6 124 Output inf -----Note----- In the first sample case, Masha will write integers 3, 12, 24. Progression term 6 will be skipped because it is a "bad" integer. Terms bigger than 24 won't be written because they exceed l by absolute value. In the second case, Masha won't write any number because all terms are equal 123 and this is a "bad" integer. In the third case, Masha will write infinitely integers 123. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python def main(): (b1, q, l, m) = list(map(int, input().split())) a = set(map(int, input().split())) if abs(b1) > l: print(0) else: if b1 == 0: if 0 in a: print(0) else: print("inf") elif q == 0: if 0 not in a: print("inf") elif b1 in a: print(0) else: print(1) elif q == 1: if b1 in a: print(0) else: print("inf") elif q == -1: if (b1 in a) and ((-b1) in a): print(0) else: print("inf") else: ans = 0 b = b1 for i in range(100): if b in a: b *= q if abs(b) > l: break continue ans += 1 b *= q if abs(b) > l: break print(ans) def __starting_point(): main() __starting_point() ```
vfc_10150
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/789/B", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 2 30 4\n6 14 25 48\n", "output": "3", "type": "stdin_stdout" }, { "fn_name": null, "input": "123 1 2143435 4\n123 11 -5453 141245\n", "output": "0", "type": "stdin_stdout" }, { "fn_name": null, "input": "123 1 2143435 4\n54343 -13 6 124\n", "output": "inf", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 2 25 2\n379195692 -69874783\n", "output": "4", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 2 30 3\n-691070108 -934106649 -220744807\n", "output": "4", "type": "stdin_stdout" } ] }
apps
verifiable_code
100
Solve the following coding problem using the programming language python: Innocentius has a problem — his computer monitor has broken. Now some of the pixels are "dead", that is, they are always black. As consequence, Innocentius can't play the usual computer games. He is recently playing the following game with his younger brother Polycarpus. Innocentius is touch-typing a program that paints a white square one-pixel wide frame on the black screen. As the monitor is broken, some pixels that should be white remain black. Polycarpus should look at what the program displayed on the screen and guess the position and size of the frame Innocentius has painted. Polycarpus doesn't like the game but Innocentius persuaded brother to play as "the game is good for the imagination and attention". Help Polycarpus, automatize his part in the gaming process. Write the code that finds such possible square frame that: the frame's width is 1 pixel, the frame doesn't go beyond the borders of the screen, all white pixels of the monitor are located on the frame, of all frames that satisfy the previous three conditions, the required frame must have the smallest size. Formally, a square frame is represented by such pixels of the solid square, that are on the square's border, that is, are not fully surrounded by the other pixels of the square. For example, if the frame's size is d = 3, then it consists of 8 pixels, if its size is d = 2, then it contains 4 pixels and if d = 1, then the frame is reduced to a single pixel. -----Input----- The first line contains the resolution of the monitor as a pair of integers n, m (1 ≤ n, m ≤ 2000). The next n lines contain exactly m characters each — the state of the monitor pixels at the moment of the game. Character "." (period, ASCII code 46) corresponds to the black pixel, and character "w" (lowercase English letter w) corresponds to the white pixel. It is guaranteed that at least one pixel of the monitor is white. -----Output----- Print the monitor screen. Represent the sought frame by characters "+" (the "plus" character). The pixels that has become white during the game mustn't be changed. Print them as "w". If there are multiple possible ways to position the frame of the minimum size, print any of them. If the required frame doesn't exist, then print a single line containing number -1. -----Examples----- Input 4 8 ..w..w.. ........ ........ ..w..w.. Output ..w++w.. ..+..+.. ..+..+.. ..w++w.. Input 5 6 ...... .w.... ...... ..w... ...... Output ...... +w+... +.+... ++w... ...... Input 2 4 .... .w.. Output .... .w.. Input 2 6 w..w.w ...w.. Output -1 -----Note----- In the first sample the required size of the optimal frame equals 4. In the second sample the size of the optimal frame equals 3. In the third sample, the size of the optimal frame is 1. In the fourth sample, the required frame doesn't exist. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python 3 def readln(): return list(map(int, input().split())) import sys def return: print(-1) return n, m = readln() mon = [list(input()) for _ in range(n)] hor = [i for i in range(n) if mon[i] != ['.'] * m] rmon = list(zip(*mon)) ver = [j for j in range(m) if rmon[j] != ('.',) * n] mini = hor[0] maxi = hor[-1] minj = ver[0] maxj = ver[-1] cnt_in = len([1 for i in range(mini + 1, maxi) for j in range(minj + 1, maxj) if mon[i][j] == 'w']) cnt_l = len([1 for i in range(mini + 1, maxi) if mon[i][minj] == 'w']) cnt_r = len([1 for i in range(mini + 1, maxi) if mon[i][maxj] == 'w']) cnt_d = len([1 for j in range(minj + 1, maxj) if mon[mini][j] == 'w']) cnt_u = len([1 for j in range(minj + 1, maxj) if mon[maxi][j] == 'w']) if cnt_in: return if maxi - mini < maxj - minj: k = maxj - minj + 1 if maxi == mini and cnt_d: if mini >= k - 1: mini -= k - 1 elif maxi + k - 1 < n: maxi += k - 1 else: return else: if not cnt_d: mini = max(0, maxi - k + 1) if maxi - maxi + 1 != k and not cnt_u: maxi = min(mini + k - 1, n - 1) if maxi - mini + 1 != k: return else: k = maxi - mini + 1 if maxj == minj and cnt_l: if minj >= k - 1: minj -= k - 1 elif maxj + k - 1 < m: maxj += k - 1 else: return else: if not cnt_l: minj = max(0, maxj - k + 1) if maxj - minj + 1 != k and not cnt_r: maxj = min(minj + k - 1, m - 1) if maxj - minj + 1 != k: return for i in range(mini, maxi + 1): if mon[i][minj] == '.': mon[i][minj] = '+' for i in range(mini, maxi + 1): if mon[i][maxj] == '.': mon[i][maxj] = '+' for j in range(minj, maxj + 1): if mon[mini][j] == '.': mon[mini][j] = '+' for j in range(minj, maxj + 1): if mon[maxi][j] == '.': mon[maxi][j] = '+' print('\n'.join([''.join(row) for row in mon])) ```
vfc_10154
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/370/D", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4 8\n..w..w..\n........\n........\n..w..w..\n", "output": "..w++w..\n..+..+..\n..+..+..\n..w++w..\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 6\n......\n.w....\n......\n..w...\n......\n", "output": "......\n+w+...\n+.+...\n++w...\n......\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 4\n....\n.w..\n", "output": "....\n.w..\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 6\nw..w.w\n...w..\n", "output": "-1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "9 4\n....\n....\n....\n....\n....\n..w.\n....\n....\n.w..\n", "output": "....\n....\n....\n....\n....\n++w+\n+..+\n+..+\n+w++\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
101
Solve the following coding problem using the programming language python: Vasya has n burles. One bottle of Ber-Cola costs a burles and one Bars bar costs b burles. He can buy any non-negative integer number of bottles of Ber-Cola and any non-negative integer number of Bars bars. Find out if it's possible to buy some amount of bottles of Ber-Cola and Bars bars and spend exactly n burles. In other words, you should find two non-negative integers x and y such that Vasya can buy x bottles of Ber-Cola and y Bars bars and x·a + y·b = n or tell that it's impossible. -----Input----- First line contains single integer n (1 ≤ n ≤ 10 000 000) — amount of money, that Vasya has. Second line contains single integer a (1 ≤ a ≤ 10 000 000) — cost of one bottle of Ber-Cola. Third line contains single integer b (1 ≤ b ≤ 10 000 000) — cost of one Bars bar. -----Output----- If Vasya can't buy Bars and Ber-Cola in such a way to spend exactly n burles print «NO» (without quotes). Otherwise in first line print «YES» (without quotes). In second line print two non-negative integers x and y — number of bottles of Ber-Cola and number of Bars bars Vasya should buy in order to spend exactly n burles, i.e. x·a + y·b = n. If there are multiple answers print any of them. Any of numbers x and y can be equal 0. -----Examples----- Input 7 2 3 Output YES 2 1 Input 100 25 10 Output YES 0 10 Input 15 4 8 Output NO Input 9960594 2551 2557 Output YES 1951 1949 -----Note----- In first example Vasya can buy two bottles of Ber-Cola and one Bars bar. He will spend exactly 2·2 + 1·3 = 7 burles. In second example Vasya can spend exactly n burles multiple ways: buy two bottles of Ber-Cola and five Bars bars; buy four bottles of Ber-Cola and don't buy Bars bars; don't buy Ber-Cola and buy 10 Bars bars. In third example it's impossible to but Ber-Cola and Bars bars in order to spend exactly n burles. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python def egcd(a, b): x,y, u,v = 0,1, 1,0 while a != 0: q, r = b//a, b%a m, n = x-u*q, y-v*q b,a, x,y, u,v = a,r, u,v, m,n gcd = b return gcd, x, y import math n=int(input()) a=int(input()) b=int(input()) gcd,x,y=(egcd(a,b)) status=0 if((n%gcd)!=0): print("NO") #print("point1") else: multiply=n/gcd x1=int(multiply*x) y1=int(multiply*y) #print("gcd and soln to n") #print(gcd,x1,y1) d1=b/gcd d2=a/gcd rangemin= int(math.ceil(-x1/d1)) rangemax= int(y1//d2) #print("rangemin and rangemax") #print(rangemin,rangemax) if(rangemin>rangemax): print("NO") #print("point2") else: #print("YES") #solx=x1+rangemin*d1 #soly=y1-rangemin*d2 m=rangemin while(m<=rangemax): solx=x1+m*d1 soly=y1-m*d2 if(solx>=0 and soly>=0): print("YES") status=1 print(str(int(solx))+" "+str(int(soly))) break m=m+1 if(status==0): print("NO") #print("point3") ```
vfc_10158
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/898/B", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "7\n2\n3\n", "output": "YES\n2 1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "100\n25\n10\n", "output": "YES\n0 10\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
102
Solve the following coding problem using the programming language python: Today Tavas got his test result as an integer score and he wants to share it with his girlfriend, Nafas. His phone operating system is Tavdroid, and its keyboard doesn't have any digits! He wants to share his score with Nafas via text, so he has no choice but to send this number using words. [Image] He ate coffee mix without water again, so right now he's really messed up and can't think. Your task is to help him by telling him what to type. -----Input----- The first and only line of input contains an integer s (0 ≤ s ≤ 99), Tavas's score. -----Output----- In the first and only line of output, print a single string consisting only from English lowercase letters and hyphens ('-'). Do not use spaces. -----Examples----- Input 6 Output six Input 99 Output ninety-nine Input 20 Output twenty -----Note----- You can find all you need to know about English numerals in http://en.wikipedia.org/wiki/English_numerals . 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()) if n == 0: print('zero') elif n == 1: print('one') elif n == 2: print('two') elif n == 3: print('three') elif n == 4: print('four') elif n == 5: print('five') elif n == 6: print('six') elif n == 7: print('seven') elif n == 8: print('eight') elif n == 9: print('nine') elif n == 10: print('ten') elif n == 11: print('eleven') elif n == 12: print('twelve') elif n == 13: print('thirteen') elif n == 14: print('fourteen') elif n == 15: print('fifteen') elif n == 16: print('sixteen') elif n == 17: print('seventeen') elif n == 18: print('eighteen') elif n == 19: print('nineteen') else: if n // 10 == 2: res = 'twenty' elif n // 10 == 3: res = 'thirty' elif n // 10 == 4: res = 'forty' elif n // 10 == 5: res = 'fifty' elif n // 10 == 6: res = 'sixty' elif n // 10 == 7: res = 'seventy' elif n // 10 == 8: res = 'eighty' elif n // 10 == 9: res = 'ninety' if n % 10 == 1: res += '-one' elif n % 10 == 2: res += '-two' elif n % 10 == 3: res += '-three' elif n % 10 == 4: res += '-four' elif n % 10 == 5: res += '-five' elif n % 10 == 6: res += '-six' elif n % 10 == 7: res += '-seven' elif n % 10 == 8: res += '-eight' elif n % 10 == 9: res += '-nine' print(res) ```
vfc_10162
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/535/A", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "6\n", "output": "six\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "99\n", "output": "ninety-nine\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
103
Solve the following coding problem using the programming language python: JATC and his friend Giraffe are currently in their room, solving some problems. Giraffe has written on the board an array $a_1$, $a_2$, ..., $a_n$ of integers, such that $1 \le a_1 < a_2 < \ldots < a_n \le 10^3$, and then went to the bathroom. JATC decided to prank his friend by erasing some consecutive elements in the array. Since he doesn't want for the prank to go too far, he will only erase in a way, such that Giraffe can still restore the array using the information from the remaining elements. Because Giraffe has created the array, he's also aware that it's an increasing array and all the elements are integers in the range $[1, 10^3]$. JATC wonders what is the greatest number of elements he can erase? -----Input----- The first line of the input contains a single integer $n$ ($1 \le n \le 100$) — the number of elements in the array. The second line of the input contains $n$ integers $a_i$ ($1 \le a_1<a_2<\dots<a_n \le 10^3$) — the array written by Giraffe. -----Output----- Print a single integer — the maximum number of consecutive elements in the array that JATC can erase. If it is impossible to erase even a single element, print $0$. -----Examples----- Input 6 1 3 4 5 6 9 Output 2 Input 3 998 999 1000 Output 2 Input 5 1 2 3 4 5 Output 4 -----Note----- In the first example, JATC can erase the third and fourth elements, leaving the array $[1, 3, \_, \_, 6, 9]$. As you can see, there is only one way to fill in the blanks. In the second example, JATC can erase the second and the third elements. The array will become $[998, \_, \_]$. Because all the elements are less than or equal to $1000$, the array is still can be restored. Note, that he can't erase the first $2$ elements. In the third example, JATC can erase the first $4$ elements. Since all the elements are greater than or equal to $1$, Giraffe can still restore the array. Note, that he can't erase the last $4$ elements. 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 = [0] + list(map(int, input().split())) + [1001] mx = 1 p = 1 for i in range(1, n + 2): if a[i] == a[i - 1] + 1: p += 1 mx = max(p, mx) else: p = 1 print(max(0, mx - 2)) ```
vfc_10166
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1062/A", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "6\n1 3 4 5 6 9\n", "output": "2", "type": "stdin_stdout" } ] }
apps
verifiable_code
104
Solve the following coding problem using the programming language python: Polycarp has created his own training plan to prepare for the programming contests. He will train for $n$ days, all days are numbered from $1$ to $n$, beginning from the first. On the $i$-th day Polycarp will necessarily solve $a_i$ problems. One evening Polycarp plans to celebrate the equator. He will celebrate it on the first evening of such a day that from the beginning of the training and to this day inclusive he will solve half or more of all the problems. Determine the index of day when Polycarp will celebrate the equator. -----Input----- The first line contains a single integer $n$ ($1 \le n \le 200\,000$) — the number of days to prepare for the programming contests. The second line contains a sequence $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10\,000$), where $a_i$ equals to the number of problems, which Polycarp will solve on the $i$-th day. -----Output----- Print the index of the day when Polycarp will celebrate the equator. -----Examples----- Input 4 1 3 2 1 Output 2 Input 6 2 2 2 2 2 2 Output 3 -----Note----- In the first example Polycarp will celebrate the equator on the evening of the second day, because up to this day (inclusive) he will solve $4$ out of $7$ scheduled problems on four days of the training. In the second example Polycarp will celebrate the equator on the evening of the third day, because up to this day (inclusive) he will solve $6$ out of $12$ scheduled problems on six days of the training. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python def main(): n = int(input()) a = list(int(x) for x in input().split()) s = sum(a) t = 0 for i in range(n): t += a[i] if 2 * t >= s: print(i + 1) return main() ```
vfc_10170
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/962/A", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n1 3 2 1\n", "output": "2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "6\n2 2 2 2 2 2\n", "output": "3\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
105
Solve the following coding problem using the programming language python: You stumbled upon a new kind of chess puzzles. The chessboard you are given is not necesserily $8 \times 8$, but it still is $N \times N$. Each square has some number written on it, all the numbers are from $1$ to $N^2$ and all the numbers are pairwise distinct. The $j$-th square in the $i$-th row has a number $A_{ij}$ written on it. In your chess set you have only three pieces: a knight, a bishop and a rook. At first, you put one of them on the square with the number $1$ (you can choose which one). Then you want to reach square $2$ (possibly passing through some other squares in process), then square $3$ and so on until you reach square $N^2$. In one step you are allowed to either make a valid move with the current piece or replace it with some other piece. Each square can be visited arbitrary number of times. A knight can move to a square that is two squares away horizontally and one square vertically, or two squares vertically and one square horizontally. A bishop moves diagonally. A rook moves horizontally or vertically. The move should be performed to a different square from the one a piece is currently standing on. You want to minimize the number of steps of the whole traversal. Among all the paths to have the same number of steps you want to choose the one with the lowest number of piece replacements. What is the path you should take to satisfy all conditions? -----Input----- The first line contains a single integer $N$ ($3 \le N \le 10$) — the size of the chessboard. Each of the next $N$ lines contains $N$ integers $A_{i1}, A_{i2}, \dots, A_{iN}$ ($1 \le A_{ij} \le N^2$) — the numbers written on the squares of the $i$-th row of the board. It is guaranteed that all $A_{ij}$ are pairwise distinct. -----Output----- The only line should contain two integers — the number of steps in the best answer and the number of replacement moves in it. -----Example----- Input 3 1 9 3 8 6 7 4 2 5 Output 12 1 -----Note----- Here are the steps for the first example (the starting piece is a knight): Move to $(3, 2)$ Move to $(1, 3)$ Move to $(3, 2)$ Replace the knight with a rook Move to $(3, 1)$ Move to $(3, 3)$ Move to $(3, 2)$ Move to $(2, 2)$ Move to $(2, 3)$ Move to $(2, 1)$ Move to $(1, 1)$ Move to $(1, 2)$ 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()) graph=[{},{},{}] for i in range(n): for j in range(n): graph[0][(i,j)]=[(k,j) for k in range(n)]+[(i,k) for k in range(n)] graph[0][(i,j)].remove((i,j)) graph[0][(i,j)].remove((i,j)) graph[1][(i,j)]=[] for k in range(n): for l in range(n): if abs(k-i)==abs(l-j)!=0: graph[1][(i,j)].append((k,l)) graph[2][(i,j)]=[] for k in range(n): for l in range(n): if {abs(k-i),abs(l-j)}=={1,2}: graph[2][(i,j)].append((k,l)) dists=[[{},{},{}],[{},{},{}],[{},{},{}]] for i in range(n): for j in range(n): for k in range(3): dists[k][k][(i,j,i,j)]=0 for i in range(n): for j in range(n): for k in range(3): layers=[[(i,j,k,0)],[],[],[],[]] for l in range(4): for guy in layers[l]: for m in range(3): if m!=guy[2]: if (i,j,guy[0],guy[1]) not in dists[k][m]: layers[l+1].append((guy[0],guy[1],m,guy[3]+1)) dists[k][m][(i,j,guy[0],guy[1])]=1000*(l+1)+guy[3]+1 for boi in graph[guy[2]][(guy[0],guy[1])]: if (i,j,boi[0],boi[1]) not in dists[k][guy[2]]: layers[l+1].append((boi[0],boi[1],guy[2],guy[3])) dists[k][guy[2]][(i,j,boi[0],boi[1])]=1000*(l+1)+guy[3] elif 1000*(l+1)+guy[3]<dists[k][guy[2]][(i,j,boi[0],boi[1])]: layers[l+1].append((boi[0],boi[1],guy[2],guy[3])) dists[k][guy[2]][(i,j,boi[0],boi[1])]=1000*(l+1)+guy[3] locs=[None]*(n**2) for i in range(n): a=list(map(int,input().split())) for j in range(n): locs[a[j]-1]=(i,j) best=(0,0,0) for i in range(n**2-1): tup=(locs[i][0],locs[i][1],locs[i+1][0],locs[i+1][1]) new0=min(best[0]+dists[0][0][tup],best[1]+dists[1][0][tup],best[2]+dists[2][0][tup]) new1=min(best[0]+dists[0][1][tup],best[1]+dists[1][1][tup],best[2]+dists[2][1][tup]) new2=min(best[0]+dists[0][2][tup],best[1]+dists[1][2][tup],best[2]+dists[2][2][tup]) best=(new0,new1,new2) a=min(best) print(a//1000,a%1000) ```
vfc_10174
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1065/D", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n1 9 3\n8 6 7\n4 2 5\n", "output": "12 1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n1 5 8\n9 2 4\n3 6 7\n", "output": "12 1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n5 4 1 13\n8 3 6 16\n15 9 14 12\n11 2 7 10\n", "output": "23 0\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
106
Solve the following coding problem using the programming language python: Есть n-подъездный дом, в каждом подъезде по m этажей, и на каждом этаже каждого подъезда ровно k квартир. Таким образом, в доме всего n·m·k квартир. Они пронумерованы естественным образом от 1 до n·m·k, то есть первая квартира на первом этаже в первом подъезде имеет номер 1, первая квартира на втором этаже первого подъезда имеет номер k + 1 и так далее. Особенность этого дома состоит в том, что он круглый. То есть если обходить его по часовой стрелке, то после подъезда номер 1 следует подъезд номер 2, затем подъезд номер 3 и так далее до подъезда номер n. После подъезда номер n снова идёт подъезд номер 1. Эдвард живёт в квартире номер a, а Наташа — в квартире номер b. Переход на 1 этаж вверх или вниз по лестнице занимает 5 секунд, переход от двери подъезда к двери соседнего подъезда — 15 секунд, а переход в пределах одного этажа одного подъезда происходит мгновенно. Также в каждом подъезде дома есть лифт. Он устроен следующим образом: он всегда приезжает ровно через 10 секунд после вызова, а чтобы переместить пассажира на один этаж вверх или вниз, лифт тратит ровно 1 секунду. Посадка и высадка происходят мгновенно. Помогите Эдварду найти минимальное время, за которое он сможет добраться до квартиры Наташи. Считайте, что Эдвард может выйти из подъезда только с первого этажа соответствующего подъезда (это происходит мгновенно). Если Эдвард стоит перед дверью какого-то подъезда, он может зайти в него и сразу окажется на первом этаже этого подъезда (это также происходит мгновенно). Эдвард может выбирать, в каком направлении идти вокруг дома. -----Входные данные----- В первой строке входных данных следуют три числа n, m, k (1 ≤ n, m, k ≤ 1000) — количество подъездов в доме, количество этажей в каждом подъезде и количество квартир на каждом этаже каждого подъезда соответственно. Во второй строке входных данных записаны два числа a и b (1 ≤ a, b ≤ n·m·k) — номера квартир, в которых живут Эдвард и Наташа, соответственно. Гарантируется, что эти номера различны. -----Выходные данные----- Выведите единственное целое число — минимальное время (в секундах), за которое Эдвард сможет добраться от своей квартиры до квартиры Наташи. -----Примеры----- Входные данные 4 10 5 200 6 Выходные данные 39 Входные данные 3 1 5 7 2 Выходные данные 15 -----Примечание----- В первом тестовом примере Эдвард находится в 4 подъезде на 10 этаже, а Наташа находится в 1 подъезде на 2 этаже. Поэтому Эдварду выгодно сначала спуститься на лифте на первый этаж (на это он потратит 19 секунд, из которых 10 — на ожидание и 9 — на поездку на лифте), затем обойти дом против часовой стрелки до подъезда номер 1 (на это он потратит 15 секунд), и наконец подняться по лестнице на этаж номер 2 (на это он потратит 5 секунд). Таким образом, ответ равен 19 + 15 + 5 = 39. Во втором тестовом примере Эдвард живёт в подъезде 2 на этаже 1, а Наташа находится в подъезде 1 на этаже 1. Поэтому Эдварду выгодно просто обойти дом по часовой стрелке до подъезда 1, на это он потратит 15 секунд. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python n, m, k = map(int, input().split()) a, b = map(int, input().split()) a -= 1 b -= 1 def p(x): return x // (m * k) def e(x): return (x - p(x) * m * k) // k def lift(x): return min(5 * x, 10 + x) if p(a) == p(b): dif = abs(e(a) - e(b)) print(lift(dif)) else: print(lift(e(a)) + 15 * min((p(a) - p(b) + n) % n, (p(b) - p(a) + n) % n) + lift(e(b))) ```
vfc_10178
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/649/B", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4 10 5\n200 6\n", "output": "39\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 1 5\n7 2\n", "output": "15\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "100 100 100\n1 1000000\n", "output": "124\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
107
Solve the following coding problem using the programming language python: Top-model Izabella participates in the competition. She wants to impress judges and show her mathematical skills. Her problem is following: for given string, consisting of only 0 and 1, tell if it's possible to remove some digits in such a way, that remaining number is a representation of some positive integer, divisible by 64, in the binary numerical system. -----Input----- In the only line given a non-empty binary string s with length up to 100. -----Output----- Print «yes» (without quotes) if it's possible to remove digits required way and «no» otherwise. -----Examples----- Input 100010001 Output yes Input 100 Output no -----Note----- In the first test case, you can get string 1 000 000 after removing two ones which is a representation of number 64 in the binary numerical system. You can read more about binary numeral system representation here: https://en.wikipedia.org/wiki/Binary_system The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python s = input() i = 0 while i < len(s) and s[i] == '0': i += 1 cnt = 0 while i < len(s): if s[i] == '0': cnt += 1 i += 1 if cnt >= 6: print('yes') else: print('no') ```
vfc_10182
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/887/A", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "100010001\n", "output": "yes", "type": "stdin_stdout" }, { "fn_name": null, "input": "100\n", "output": "no", "type": "stdin_stdout" }, { "fn_name": null, "input": "0000001000000\n", "output": "yes", "type": "stdin_stdout" } ] }
apps
verifiable_code
109
Solve the following coding problem using the programming language python: While Grisha was celebrating New Year with Ded Moroz, Misha gifted Sasha a small rectangular pond of size n × m, divided into cells of size 1 × 1, inhabited by tiny evil fishes (no more than one fish per cell, otherwise they'll strife!). The gift bundle also includes a square scoop of size r × r, designed for fishing. If the lower-left corner of the scoop-net is located at cell (x, y), all fishes inside the square (x, y)...(x + r - 1, y + r - 1) get caught. Note that the scoop-net should lie completely inside the pond when used. Unfortunately, Sasha is not that skilled in fishing and hence throws the scoop randomly. In order to not frustrate Sasha, Misha decided to release k fishes into the empty pond in such a way that the expected value of the number of caught fishes is as high as possible. Help Misha! In other words, put k fishes in the pond into distinct cells in such a way that when the scoop-net is placed into a random position among (n - r + 1)·(m - r + 1) possible positions, the average number of caught fishes is as high as possible. -----Input----- The only line contains four integers n, m, r, k (1 ≤ n, m ≤ 10^5, 1 ≤ r ≤ min(n, m), 1 ≤ k ≤ min(n·m, 10^5)). -----Output----- Print a single number — the maximum possible expected number of caught fishes. You answer is considered correct, is its absolute or relative error does not exceed 10^{ - 9}. Namely, 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^{-9}$. -----Examples----- Input 3 3 2 3 Output 2.0000000000 Input 12 17 9 40 Output 32.8333333333 -----Note----- In the first example you can put the fishes in cells (2, 1), (2, 2), (2, 3). In this case, for any of four possible positions of the scoop-net (highlighted with light green), the number of fishes inside is equal to two, and so is the expected value. [Image] The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python import heapq as hq from queue import PriorityQueue import math n,m,r, k= input().split() N = int(n) M = int(m) R = int(r) K = int(k) q = PriorityQueue() for i in range(1,math.floor((N+1)/2) + 1): maxi = min(min(i,N-i+1),min(R,N-R+1)) * min(min(R,M-R+1),math.ceil(M/2)) num = M - (2 * min(min(R,M-R+1),math.ceil(M/2))-2) mult = 2 if(i > math.floor(N/2)): mult = 1 q.put((-maxi,num * mult,i)) #print(str(maxi) + " " + str(num) + " " + str(mult)) ans = 0 while(K > 0): pop = q.get() #print(pop) a = -1 * pop[0] b = pop[1] c = pop[2] d = min(min(c,N-c+1),min(R,N-R+1)) if(d != a): # if(q.) # if(q.get(-(a - d)) != ) mult = 2 if (c > N / 2): mult = 1 q.put((-(a - d),2*mult,c)) ans += a * min(b,K) K -= b; tot = (N-R+1) * (M-R+1) #print("ANS = " + str(ans)) #print("FINANS = " + str(ans/tot)) print(str(ans/tot)) ''' d = [] for i in range(0,N): d.append([]) for j in range(0,M): d[i].append(0) tot = 0 for i in range(0,N-R+1): for j in range(0,M-R+1): for k in range(i,i+R): for l in range(j,j+R): d[k][l] += 1 tot += 1 print(N-R+1)*(M-R+1) * (R*R) print(tot) print() for i in d: print(i) ''' ```
vfc_10190
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/912/D", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 3 2 3\n", "output": "2.0000000000\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "12 17 9 40\n", "output": "32.8333333333\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 1 1 1\n", "output": "1.0000000000\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "10 10 5 100\n", "output": "25.0000000000\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
110
Solve the following coding problem using the programming language python: Nick had received an awesome array of integers $a=[a_1, a_2, \dots, a_n]$ as a gift for his $5$ birthday from his mother. He was already going to explore its various properties but after unpacking he was disappointed a lot because the product $a_1 \cdot a_2 \cdot \dots a_n$ of its elements seemed to him not large enough. He was ready to throw out the array, but his mother reassured him. She told him, that array would not be spoiled after the following operation: choose any index $i$ ($1 \le i \le n$) and do $a_i := -a_i - 1$. For example, he can change array $[3, -1, -4, 1]$ to an array $[-4, -1, 3, 1]$ after applying this operation to elements with indices $i=1$ and $i=3$. Kolya had immediately understood that sometimes it's possible to increase the product of integers of the array a lot. Now he has decided that he wants to get an array with the maximal possible product of integers using only this operation with its elements (possibly zero, one or more times, as many as he wants), it is not forbidden to do this operation several times for the same index. Help Kolya and print the array with the maximal possible product of elements $a_1 \cdot a_2 \cdot \dots a_n$ which can be received using only this operation in some order. If there are multiple answers, print any of them. -----Input----- The first line contains integer $n$ ($1 \leq n \leq 10^{5}$) — number of integers in the array. The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($-10^{6} \leq a_i \leq 10^{6}$) — elements of the array -----Output----- Print $n$ numbers — elements of the array with the maximal possible product of elements which can be received using only this operation in some order from the given array. If there are multiple answers, print any of them. -----Examples----- Input 4 2 2 2 2 Output -3 -3 -3 -3 Input 1 0 Output 0 Input 3 -3 -3 2 Output -3 -3 2 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())) if n == 1: if A[0] >= 0: print(A[0]) else: print(-A[0]-1) return for i in range(n): if A[i] < 0: pass else: A[i] = -A[i]-1 if n % 2 == 0: print(*A) return mim = 0 indmim = 0 for i in range(n): if A[i] < mim: mim = A[i] indmim = i A[indmim] = -A[indmim]-1 print(*A) ```
vfc_10194
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1180/B", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n2 2 2 2\n", "output": "-3 -3 -3 -3 ", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n0\n", "output": "0 ", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n-3 -3 2\n", "output": "-3 -3 2 ", "type": "stdin_stdout" }, { "fn_name": null, "input": "10\n2 10 6 8 -4 -11 -10 3 -3 8\n", "output": "-3 -11 -7 -9 -4 -11 -10 -4 -3 -9 ", "type": "stdin_stdout" }, { "fn_name": null, "input": "10\n8 6 3 9 8 7 7 7 7 6\n", "output": "-9 -7 -4 -10 -9 -8 -8 -8 -8 -7 ", "type": "stdin_stdout" } ] }
apps
verifiable_code
111
Solve the following coding problem using the programming language python: You are given two integers n and k. Find k-th smallest divisor of n, or report that it doesn't exist. Divisor of n is any such natural number, that n can be divided by it without remainder. -----Input----- The first line contains two integers n and k (1 ≤ n ≤ 10^15, 1 ≤ k ≤ 10^9). -----Output----- If n has less than k divisors, output -1. Otherwise, output the k-th smallest divisor of n. -----Examples----- Input 4 2 Output 2 Input 5 3 Output -1 Input 12 5 Output 6 -----Note----- In the first example, number 4 has three divisors: 1, 2 and 4. The second one is 2. In the second example, number 5 has only two divisors: 1 and 5. The third divisor doesn't exist, so the answer is -1. 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 math def factorization(n): res = [] limit = math.ceil(math.sqrt(n)) p = 2 cnt = 0 while n % p == 0: cnt += 1 n //= p if cnt > 0: res.append((p, cnt)) cnt = 0 for p in range(3, limit + 1, 2): if n % p == 0: while n % p == 0: cnt += 1 n //= p res.append((p, cnt)) cnt = 0 if n > 1: res.append((n, 1)) return res def divisor(n): res = set() factor = factorization(n) for p, c in factor: if res == set(): for i in range(c + 1): res.add(p ** i) else: t = set() for i in range(1, c + 1): for m in res: t.add(m * p**i) res = res | t res = list(sorted(res)) return res n, k = map(int, input().split()) # print(factorization(n), file=sys.stderr) # print(divisor(n), file=sys.stderr) n_div = divisor(n) if n == 1: if k == 1: ans = 1 else: ans = -1 elif k > len(n_div): ans = -1 else: ans = n_div[k - 1] print(ans) ```
vfc_10198
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/762/A", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4 2\n", "output": "2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 3\n", "output": "-1\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
113
Solve the following coding problem using the programming language python: For a given positive integer n denote its k-rounding as the minimum positive integer x, such that x ends with k or more zeros in base 10 and is divisible by n. For example, 4-rounding of 375 is 375·80 = 30000. 30000 is the minimum integer such that it ends with 4 or more zeros and is divisible by 375. Write a program that will perform the k-rounding of n. -----Input----- The only line contains two integers n and k (1 ≤ n ≤ 10^9, 0 ≤ k ≤ 8). -----Output----- Print the k-rounding of n. -----Examples----- Input 375 4 Output 30000 Input 10000 1 Output 10000 Input 38101 0 Output 38101 Input 123456789 8 Output 12345678900000000 The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python def main(): n, k = map(int, input().split()) num_2 = 0 num_5 = 0 x = n while (x % 2 == 0): num_2 += 1 x //= 2 while (x % 5 == 0): num_5 += 1 x //= 5 num_2 = k - min(num_2, k) num_5 = k - min(num_5, k) print(n * 5 ** num_5 * 2 ** num_2) main() ```
vfc_10206
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/858/A", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "375 4\n", "output": "30000\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "10000 1\n", "output": "10000\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
115
Solve the following coding problem using the programming language python: The Bad Luck Island is inhabited by three kinds of species: r rocks, s scissors and p papers. At some moments of time two random individuals meet (all pairs of individuals can meet equiprobably), and if they belong to different species, then one individual kills the other one: a rock kills scissors, scissors kill paper, and paper kills a rock. Your task is to determine for each species what is the probability that this species will be the only one to inhabit this island after a long enough period of time. -----Input----- The single line contains three integers r, s and p (1 ≤ r, s, p ≤ 100) — the original number of individuals in the species of rock, scissors and paper, respectively. -----Output----- Print three space-separated real numbers: the probabilities, at which the rocks, the scissors and the paper will be the only surviving species, respectively. The answer will be considered correct if the relative or absolute error of each number doesn't exceed 10^{ - 9}. -----Examples----- Input 2 2 2 Output 0.333333333333 0.333333333333 0.333333333333 Input 2 1 2 Output 0.150000000000 0.300000000000 0.550000000000 Input 1 1 3 Output 0.057142857143 0.657142857143 0.285714285714 The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python r, s, p = list(map(int, input().split())) dp = [[[0] * (p+1) for _ in range(s+1)] for _ in range(r+1)] dp[r][s][p] = 1 def nCk(n, k): if n <= k: return 1 res = 1 for i in range(k): res *= n-i for i in range(k): res //= (i+1) return res C = [nCk(i, 2) for i in range(r+s+p+1)] for ri in range(r, -1, -1): for si in range(s, -1, -1): for pi in range(p, -1, -1): t = ri * si + si * pi + pi * ri if t == 0: continue if ri > 0: dp[ri-1][si][pi] += dp[ri][si][pi] * ri * pi / t if si > 0: dp[ri][si-1][pi] += dp[ri][si][pi] * ri * si / t if pi > 0: dp[ri][si][pi-1] += dp[ri][si][pi] * si * pi / t r_sum = sum([dp[ri][0][0] for ri in range(r+1)]) s_sum = sum([dp[0][si][0] for si in range(s+1)]) p_sum = sum([dp[0][0][pi] for pi in range(p+1)]) print(r_sum, s_sum, p_sum) ```
vfc_10214
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/540/D", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2 2 2\n", "output": "0.333333333333 0.333333333333 0.333333333333\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 1 2\n", "output": "0.150000000000 0.300000000000 0.550000000000\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 1 3\n", "output": "0.057142857143 0.657142857143 0.285714285714\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 2 1\n", "output": "0.487662337662 0.072077922078 0.440259740260\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
116
Solve the following coding problem using the programming language python: Today an outstanding event is going to happen in the forest — hedgehog Filya will come to his old fried Sonya! Sonya is an owl and she sleeps during the day and stay awake from minute l_1 to minute r_1 inclusive. Also, during the minute k she prinks and is unavailable for Filya. Filya works a lot and he plans to visit Sonya from minute l_2 to minute r_2 inclusive. Calculate the number of minutes they will be able to spend together. -----Input----- The only line of the input contains integers l_1, r_1, l_2, r_2 and k (1 ≤ l_1, r_1, l_2, r_2, k ≤ 10^18, l_1 ≤ r_1, l_2 ≤ r_2), providing the segments of time for Sonya and Filya and the moment of time when Sonya prinks. -----Output----- Print one integer — the number of minutes Sonya and Filya will be able to spend together. -----Examples----- Input 1 10 9 20 1 Output 2 Input 1 100 50 200 75 Output 50 -----Note----- In the first sample, they will be together during minutes 9 and 10. In the second sample, they will be together from minute 50 to minute 74 and from minute 76 to minute 100. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python read = lambda: list(map(int, input().split())) l1, r1, l2, r2, k = read() R = min(r1, r2) L = max(l1, l2) ans = max(R - L + 1, 0) if L <= k <= R: ans = max(ans - 1, 0) print(ans) ```
vfc_10218
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/714/A", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1 10 9 20 1\n", "output": "2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 100 50 200 75\n", "output": "50\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "6 6 5 8 9\n", "output": "1\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
118
Solve the following coding problem using the programming language python: Ted has a pineapple. This pineapple is able to bark like a bulldog! At time t (in seconds) it barks for the first time. Then every s seconds after it, it barks twice with 1 second interval. Thus it barks at times t, t + s, t + s + 1, t + 2s, t + 2s + 1, etc. [Image] Barney woke up in the morning and wants to eat the pineapple, but he can't eat it when it's barking. Barney plans to eat it at time x (in seconds), so he asked you to tell him if it's gonna bark at that time. -----Input----- The first and only line of input contains three integers t, s and x (0 ≤ t, x ≤ 10^9, 2 ≤ s ≤ 10^9) — the time the pineapple barks for the first time, the pineapple barking interval, and the time Barney wants to eat the pineapple respectively. -----Output----- Print a single "YES" (without quotes) if the pineapple will bark at time x or a single "NO" (without quotes) otherwise in the only line of output. -----Examples----- Input 3 10 4 Output NO Input 3 10 3 Output YES Input 3 8 51 Output YES Input 3 8 52 Output YES -----Note----- In the first and the second sample cases pineapple will bark at moments 3, 13, 14, ..., so it won't bark at the moment 4 and will bark at the moment 3. In the third and fourth sample cases pineapple will bark at moments 3, 11, 12, 19, 20, 27, 28, 35, 36, 43, 44, 51, 52, 59, ..., so it will bark at both moments 51 and 52. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python t, s, x = list(map(int, input().split())) f = False if x - 1 > t and (x - 1 - t) % s == 0: f = True if x >= t and (x - t) % s == 0: f = True if f: print('YES') else: print('NO') ```
vfc_10226
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/697/A", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 10 4\n", "output": "NO\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 10 3\n", "output": "YES\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 8 51\n", "output": "YES\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 8 52\n", "output": "YES\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
119
Solve the following coding problem using the programming language python: You are given a sequence a_1, a_2, ..., a_{n} of one-dimensional segments numbered 1 through n. Your task is to find two distinct indices i and j such that segment a_{i} lies within segment a_{j}. Segment [l_1, r_1] lies within segment [l_2, r_2] iff l_1 ≥ l_2 and r_1 ≤ r_2. Print indices i and j. If there are multiple answers, print any of them. If no answer exists, print -1 -1. -----Input----- The first line contains one integer n (1 ≤ n ≤ 3·10^5) — the number of segments. Each of the next n lines contains two integers l_{i} and r_{i} (1 ≤ l_{i} ≤ r_{i} ≤ 10^9) — the i-th segment. -----Output----- Print two distinct indices i and j such that segment a_{i} lies within segment a_{j}. If there are multiple answers, print any of them. If no answer exists, print -1 -1. -----Examples----- Input 5 1 10 2 9 3 9 2 3 2 9 Output 2 1 Input 3 1 5 2 6 6 20 Output -1 -1 -----Note----- In the first example the following pairs are considered correct: (2, 1), (3, 1), (4, 1), (5, 1) — not even touching borders; (3, 2), (4, 2), (3, 5), (4, 5) — touch one border; (5, 2), (2, 5) — match exactly. 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 = [] for i in range(1, n + 1): l, r = list(map(int, input().split())) a.append([l, -r, i]) a.sort() hh = a[0][1] wahh = max(-1, a[0][2]) for i in range(1, n): if a[i][1] >= hh: print(a[i][2], wahh) return else: hh = a[i][1] wahh = a[i][2] print(-1, -1) ```
vfc_10230
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/976/C", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n1 10\n2 9\n3 9\n2 3\n2 9\n", "output": "2 1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n1 5\n2 6\n6 20\n", "output": "-1 -1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n1 1000000000\n", "output": "-1 -1\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
120
Solve the following coding problem using the programming language python: The process of mammoth's genome decoding in Berland comes to its end! One of the few remaining tasks is to restore unrecognized nucleotides in a found chain s. Each nucleotide is coded with a capital letter of English alphabet: 'A', 'C', 'G' or 'T'. Unrecognized nucleotides are coded by a question mark '?'. Thus, s is a string consisting of letters 'A', 'C', 'G', 'T' and characters '?'. It is known that the number of nucleotides of each of the four types in the decoded genome of mammoth in Berland should be equal. Your task is to decode the genome and replace each unrecognized nucleotide with one of the four types so that the number of nucleotides of each of the four types becomes equal. -----Input----- The first line contains the integer n (4 ≤ n ≤ 255) — the length of the genome. The second line contains the string s of length n — the coded genome. It consists of characters 'A', 'C', 'G', 'T' and '?'. -----Output----- If it is possible to decode the genome, print it. If there are multiple answer, print any of them. If it is not possible, print three equals signs in a row: "===" (without quotes). -----Examples----- Input 8 AG?C??CT Output AGACGTCT Input 4 AGCT Output AGCT Input 6 ????G? Output === Input 4 AA?? Output === -----Note----- In the first example you can replace the first question mark with the letter 'A', the second question mark with the letter 'G', the third question mark with the letter 'T', then each nucleotide in the genome would be presented twice. In the second example the genome is already decoded correctly and each nucleotide is exactly once in it. In the third and the fourth examples it is impossible to decode the genom. 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("data.txt") input=sys.stdin.readline n=int(input()) if n%4: print("===") else: t=input().strip() a=[n//4]*4 for i in t: if i=='A': a[0]-=1 elif i=='C': a[1]-=1 elif i=='G': a[2]-=1 elif i=='T': a[3]-=1 if min(a)<0: print("===") else: out=[] for i in t: if i=='?': if a[0]: out.append('A') a[0]-=1 elif a[1]: out.append('C') a[1]-=1 elif a[2]: out.append('G') a[2]-=1 elif a[3]: out.append('T') a[3]-=1 else: out.append(i) print("".join(out)) ```
vfc_10234
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/747/B", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "8\nAG?C??CT\n", "output": "AGACGTCT\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\nAGCT\n", "output": "AGCT\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "6\n????G?\n", "output": "===\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\nAA??\n", "output": "===\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
121
Solve the following coding problem using the programming language python: Ilya is an experienced player in tic-tac-toe on the 4 × 4 field. He always starts and plays with Xs. He played a lot of games today with his friend Arseny. The friends became tired and didn't finish the last game. It was Ilya's turn in the game when they left it. Determine whether Ilya could have won the game by making single turn or not. The rules of tic-tac-toe on the 4 × 4 field are as follows. Before the first turn all the field cells are empty. The two players take turns placing their signs into empty cells (the first player places Xs, the second player places Os). The player who places Xs goes first, the another one goes second. The winner is the player who first gets three of his signs in a row next to each other (horizontal, vertical or diagonal). -----Input----- The tic-tac-toe position is given in four lines. Each of these lines contains four characters. Each character is '.' (empty cell), 'x' (lowercase English letter x), or 'o' (lowercase English letter o). It is guaranteed that the position is reachable playing tic-tac-toe, and it is Ilya's turn now (in particular, it means that the game is not finished). It is possible that all the cells are empty, it means that the friends left without making single turn. -----Output----- Print single line: "YES" in case Ilya could have won by making single turn, and "NO" otherwise. -----Examples----- Input xx.. .oo. x... oox. Output YES Input x.ox ox.. x.o. oo.x Output NO Input x..x ..oo o... x.xo Output YES Input o.x. o... .x.. ooxx Output NO -----Note----- In the first example Ilya had two winning moves: to the empty cell in the left column and to the leftmost empty cell in the first row. In the second example it wasn't possible to win by making single turn. In the third example Ilya could have won by placing X in the last row between two existing Xs. In the fourth example it wasn't possible to win by making single turn. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python def chk(l): for i in range(4): for j in range(2): if l[i][j]==l[i][j+1]==l[i][j+2]=='x': return True for i in range(2): for j in range(4): if l[i][j]==l[i+1][j]==l[i+2][j]=='x': return True for i in range(2): for j in range(2): if l[i][j]==l[i+1][j+1]==l[i+2][j+2]=='x': return True for i in range(2): for j in range(2, 4): if l[i][j]==l[i+1][j-1]==l[i+2][j-2]=='x': return True return False a = [list(input()), list(input()), list(input()), list(input())] for i in range(4): for j in range(4): if a[i][j] != '.': continue a[i][j]='x' if chk(a): print("YES"); return a[i][j]='.' print("NO") ```
vfc_10238
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/754/B", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "xx..\n.oo.\nx...\noox.\n", "output": "YES\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "x.ox\nox..\nx.o.\noo.x\n", "output": "NO\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "x..x\n..oo\no...\nx.xo\n", "output": "YES\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "o.x.\no...\n.x..\nooxx\n", "output": "NO\n", "type": "stdin_stdout" }, { "fn_name": null, "input": ".xox\no.x.\nx.o.\n..o.\n", "output": "YES\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "o.oo\n.x.o\nx.x.\n.x..\n", "output": "YES\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
122
Solve the following coding problem using the programming language python: Vasya has an array a consisting of positive integer numbers. Vasya wants to divide this array into two non-empty consecutive parts (the prefix and the suffix) so that the sum of all elements in the first part equals to the sum of elements in the second part. It is not always possible, so Vasya will move some element before dividing the array (Vasya will erase some element and insert it into an arbitrary position). Inserting an element in the same position he was erased from is also considered moving. Can Vasya divide the array after choosing the right element to move and its new position? -----Input----- The first line contains single integer n (1 ≤ n ≤ 100000) — the size of the array. The second line contains n integers a_1, a_2... a_{n} (1 ≤ a_{i} ≤ 10^9) — the elements of the array. -----Output----- Print YES if Vasya can divide the array after moving one element. Otherwise print NO. -----Examples----- Input 3 1 3 2 Output YES Input 5 1 2 3 4 5 Output NO Input 5 2 2 3 4 5 Output YES -----Note----- In the first example Vasya can move the second element to the end of the array. In the second example no move can make the division possible. In the third example Vasya can move the fourth element by one position to the left. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python def solve(n,a): tot=0 for i in range(n): tot+=a[i] diffs = [] #alla suffix - prefix diffs[i]=prefix-suffix om delas innan element i diffs.append(-tot) for i in range(n): tot-=2*a[i] diffs.append(-tot) if tot==0: return ("YES") for i in range(n): diffmake=2*a[i] j=binary(diffs,diffmake) if j>i and j!=-1: return ("YES") j=binary(diffs,-diffmake) if i>=j and j!=-1: return ("YES") return ("NO") def binary(a,value): hi=len(a) lo=-1 while (lo+1<hi): mi=(lo+hi)//2 if a[mi]==value: return mi if a[mi]<value: lo=mi else: hi=mi return -1 n=int(input()) a = input().split() for i in range (n): a[i]=int(a[i]) print(solve(n,a)) ```
vfc_10242
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/808/D", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n1 3 2\n", "output": "YES\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n1 2 3 4 5\n", "output": "NO\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n2 2 3 4 5\n", "output": "YES\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n72 32 17 46 82\n", "output": "NO\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
123
Solve the following coding problem using the programming language python: A few years ago, Hitagi encountered a giant crab, who stole the whole of her body weight. Ever since, she tried to avoid contact with others, for fear that this secret might be noticed. To get rid of the oddity and recover her weight, a special integer sequence is needed. Hitagi's sequence has been broken for a long time, but now Kaiki provides an opportunity. Hitagi's sequence a has a length of n. Lost elements in it are denoted by zeros. Kaiki provides another sequence b, whose length k equals the number of lost elements in a (i.e. the number of zeros). Hitagi is to replace each zero in a with an element from b so that each element in b should be used exactly once. Hitagi knows, however, that, apart from 0, no integer occurs in a and b more than once in total. If the resulting sequence is not an increasing sequence, then it has the power to recover Hitagi from the oddity. You are to determine whether this is possible, or Kaiki's sequence is just another fake. In other words, you should detect whether it is possible to replace each zero in a with an integer from b so that each integer from b is used exactly once, and the resulting sequence is not increasing. -----Input----- The first line of input contains two space-separated positive integers n (2 ≤ n ≤ 100) and k (1 ≤ k ≤ n) — the lengths of sequence a and b respectively. The second line contains n space-separated integers a_1, a_2, ..., a_{n} (0 ≤ a_{i} ≤ 200) — Hitagi's broken sequence with exactly k zero elements. The third line contains k space-separated integers b_1, b_2, ..., b_{k} (1 ≤ b_{i} ≤ 200) — the elements to fill into Hitagi's sequence. Input guarantees that apart from 0, no integer occurs in a and b more than once in total. -----Output----- Output "Yes" if it's possible to replace zeros in a with elements in b and make the resulting sequence not increasing, and "No" otherwise. -----Examples----- Input 4 2 11 0 0 14 5 4 Output Yes Input 6 1 2 3 0 8 9 10 5 Output No Input 4 1 8 94 0 4 89 Output Yes Input 7 7 0 0 0 0 0 0 0 1 2 3 4 5 6 7 Output Yes -----Note----- In the first sample: Sequence a is 11, 0, 0, 14. Two of the elements are lost, and the candidates in b are 5 and 4. There are two possible resulting sequences: 11, 5, 4, 14 and 11, 4, 5, 14, both of which fulfill the requirements. Thus the answer is "Yes". In the second sample, the only possible resulting sequence is 2, 3, 5, 8, 9, 10, which is an increasing sequence and therefore invalid. 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, k = list(map(int, input().split())) a = [int(x) for x in input().split()] b = [int(x) for x in input().split()] b.sort(reverse=True) res = [] cur_b = 0 for a_i in a: if a_i != 0: res.append(a_i) else: res.append(b[cur_b]) cur_b += 1 if res != list(sorted(res)): print("Yes") else: print("No") ```
vfc_10246
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/814/A", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4 2\n11 0 0 14\n5 4\n", "output": "Yes\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "6 1\n2 3 0 8 9 10\n5\n", "output": "No\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
124
Solve the following coding problem using the programming language python: The Duck song For simplicity, we'll assume that there are only three types of grapes: green grapes, purple grapes and black grapes. Andrew, Dmitry and Michal are all grapes' lovers, however their preferences of grapes are different. To make all of them happy, the following should happen: Andrew, Dmitry and Michal should eat at least $x$, $y$ and $z$ grapes, respectively. Andrew has an extreme affinity for green grapes, thus he will eat green grapes and green grapes only. On the other hand, Dmitry is not a fan of black grapes — any types of grapes except black would do for him. In other words, Dmitry can eat green and purple grapes. Michal has a common taste — he enjoys grapes in general and will be pleased with any types of grapes, as long as the quantity is sufficient. Knowing that his friends are so fond of grapes, Aki decided to host a grape party with them. He has prepared a box with $a$ green grapes, $b$ purple grapes and $c$ black grapes. However, Aki isn't sure if the box he prepared contains enough grapes to make everyone happy. Can you please find out whether it's possible to distribute grapes so that everyone is happy or Aki has to buy some more grapes? It is not required to distribute all the grapes, so it's possible that some of them will remain unused. -----Input----- The first line contains three integers $x$, $y$ and $z$ ($1 \le x, y, z \le 10^5$) — the number of grapes Andrew, Dmitry and Michal want to eat. The second line contains three integers $a$, $b$, $c$ ($1 \le a, b, c \le 10^5$) — the number of green, purple and black grapes in the box. -----Output----- If there is a grape distribution that allows everyone to be happy, print "YES", otherwise print "NO". -----Examples----- Input 1 6 2 4 3 3 Output YES Input 5 1 1 4 3 2 Output NO -----Note----- In the first example, there is only one possible distribution: Andrew should take $1$ green grape, Dmitry should take $3$ remaining green grapes and $3$ purple grapes, and Michal will take $2$ out of $3$ available black grapes. In the second test, there is no possible distribution, since Andrew is not be able to eat enough green grapes. :( The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python x,y,z = list(map(int,input().split())) a,b,c = list(map(int,input().split())) if a < x: print("NO") return x -= a y += x if b < y: print("NO") return y -= b z += y if c < z: print("NO") return print("YES") ```
vfc_10250
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1114/A", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1 6 2\n4 3 3\n", "output": "YES\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 1 1\n4 3 2\n", "output": "NO\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 1 100000\n4 2 99995\n", "output": "NO\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 2 3\n3 2 1\n", "output": "YES\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 8 4\n3 1 9\n", "output": "NO\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
126
Solve the following coding problem using the programming language python: While swimming at the beach, Mike has accidentally dropped his cellphone into the water. There was no worry as he bought a cheap replacement phone with an old-fashioned keyboard. The keyboard has only ten digital equal-sized keys, located in the following way: [Image] Together with his old phone, he lost all his contacts and now he can only remember the way his fingers moved when he put some number in. One can formally consider finger movements as a sequence of vectors connecting centers of keys pressed consecutively to put in a number. For example, the finger movements for number "586" are the same as finger movements for number "253": [Image] [Image] Mike has already put in a number by his "finger memory" and started calling it, so he is now worrying, can he be sure that he is calling the correct number? In other words, is there any other number, that has the same finger movements? -----Input----- The first line of the input contains the only integer n (1 ≤ n ≤ 9) — the number of digits in the phone number that Mike put in. The second line contains the string consisting of n digits (characters from '0' to '9') representing the number that Mike put in. -----Output----- If there is no other phone number with the same finger movements and Mike can be sure he is calling the correct number, print "YES" (without quotes) in the only line. Otherwise print "NO" (without quotes) in the first line. -----Examples----- Input 3 586 Output NO Input 2 09 Output NO Input 9 123456789 Output YES Input 3 911 Output YES -----Note----- You can find the picture clarifying the first sample case in the statement above. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python # A input() l = list(map(int, list(input()))) if (1 in l or 4 in l or 7 in l or 0 in l) and (1 in l or 2 in l or 3 in l) and (3 in l or 6 in l or 9 in l or 0 in l) and (7 in l or 0 in l or 9 in l): print("YES") else: print("NO") ```
vfc_10258
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/689/A", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n586\n", "output": "NO\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n09\n", "output": "NO\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "9\n123456789\n", "output": "YES\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n911\n", "output": "YES\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n089\n", "output": "NO\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n159\n", "output": "YES\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
127
Solve the following coding problem using the programming language python: Summer holidays! Someone is going on trips, someone is visiting grandparents, but someone is trying to get a part-time job. This summer Noora decided that she wants to earn some money, and took a job in a shop as an assistant. Shop, where Noora is working, has a plan on the following n days. For each day sales manager knows exactly, that in i-th day k_{i} products will be put up for sale and exactly l_{i} clients will come to the shop that day. Also, the manager is sure, that everyone, who comes to the shop, buys exactly one product or, if there aren't any left, leaves the shop without buying anything. Moreover, due to the short shelf-life of the products, manager established the following rule: if some part of the products left on the shelves at the end of the day, that products aren't kept on the next day and are sent to the dump. For advertising purposes manager offered to start a sell-out in the shop. He asked Noora to choose any f days from n next for sell-outs. On each of f chosen days the number of products were put up for sale would be doubled. Thus, if on i-th day shop planned to put up for sale k_{i} products and Noora has chosen this day for sell-out, shelves of the shop would keep 2·k_{i} products. Consequently, there is an opportunity to sell two times more products on days of sell-out. Noora's task is to choose f days to maximize total number of sold products. She asks you to help her with such a difficult problem. -----Input----- The first line contains two integers n and f (1 ≤ n ≤ 10^5, 0 ≤ f ≤ n) denoting the number of days in shop's plan and the number of days that Noora has to choose for sell-out. Each line of the following n subsequent lines contains two integers k_{i}, l_{i} (0 ≤ k_{i}, l_{i} ≤ 10^9) denoting the number of products on the shelves of the shop on the i-th day and the number of clients that will come to the shop on i-th day. -----Output----- Print a single integer denoting the maximal number of products that shop can sell. -----Examples----- Input 4 2 2 1 3 5 2 3 1 5 Output 10 Input 4 1 0 2 0 3 3 5 0 6 Output 5 -----Note----- In the first example we can choose days with numbers 2 and 4 for sell-out. In this case new numbers of products for sale would be equal to [2, 6, 2, 2] respectively. So on the first day shop will sell 1 product, on the second — 5, on the third — 2, on the fourth — 2. In total 1 + 5 + 2 + 2 = 10 product units. In the second example it is possible to sell 5 products, if you choose third day for sell-out. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python n, f = list(map(int, input().split(' '))) res = 0 wow = [] for a0 in range(n): k, l = list(map(int, input().split(' '))) res += min(k, l) wow.append(min(2*k, l) - min(k, l)) wow = sorted(wow) i = len(wow)-1 for a0 in range(f): res += wow[i] i -= 1 print(res) ```
vfc_10262
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/810/B", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4 2\n2 1\n3 5\n2 3\n1 5\n", "output": "10", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 1\n0 2\n0 3\n3 5\n0 6\n", "output": "5", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 1\n5 8\n", "output": "8", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 1\n8 12\n6 11\n", "output": "19", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 1\n6 7\n5 7\n", "output": "13", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 1\n5 7\n6 7\n", "output": "13", "type": "stdin_stdout" } ] }
apps
verifiable_code
128
Solve the following coding problem using the programming language python: It is a balmy spring afternoon, and Farmer John's n cows are ruminating about link-cut cacti in their stalls. The cows, labeled 1 through n, are arranged so that the i-th cow occupies the i-th stall from the left. However, Elsie, after realizing that she will forever live in the shadows beyond Bessie's limelight, has formed the Mischievous Mess Makers and is plotting to disrupt this beautiful pastoral rhythm. While Farmer John takes his k minute long nap, Elsie and the Mess Makers plan to repeatedly choose two distinct stalls and swap the cows occupying those stalls, making no more than one swap each minute. Being the meticulous pranksters that they are, the Mischievous Mess Makers would like to know the maximum messiness attainable in the k minutes that they have. We denote as p_{i} the label of the cow in the i-th stall. The messiness of an arrangement of cows is defined as the number of pairs (i, j) such that i < j and p_{i} > p_{j}. -----Input----- The first line of the input contains two integers n and k (1 ≤ n, k ≤ 100 000) — the number of cows and the length of Farmer John's nap, respectively. -----Output----- Output a single integer, the maximum messiness that the Mischievous Mess Makers can achieve by performing no more than k swaps. -----Examples----- Input 5 2 Output 10 Input 1 10 Output 0 -----Note----- In the first sample, the Mischievous Mess Makers can swap the cows in the stalls 1 and 5 during the first minute, then the cows in stalls 2 and 4 during the second minute. This reverses the arrangement of cows, giving us a total messiness of 10. In the second sample, there is only one cow, so the maximum possible messiness is 0. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python # You lost the game. n,k = map(int, input().split()) r = 0 for i in range(min(k,n//2)): r += (n-2*i-1) + (n-2*i-2) print(r) ```
vfc_10266
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/645/B", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5 2\n", "output": "10\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 10\n", "output": "0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "100000 2\n", "output": "399990\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 1\n", "output": "0\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
129
Solve the following coding problem using the programming language python: Ivan is collecting coins. There are only $N$ different collectible coins, Ivan has $K$ of them. He will be celebrating his birthday soon, so all his $M$ freinds decided to gift him coins. They all agreed to three terms: Everyone must gift as many coins as others. All coins given to Ivan must be different. Not less than $L$ coins from gifts altogether, must be new in Ivan's collection. But his friends don't know which coins have Ivan already got in his collection. They don't want to spend money so they want to buy minimum quantity of coins, that satisfy all terms, irrespective of the Ivan's collection. Help them to find this minimum number of coins or define it's not possible to meet all the terms. -----Input----- The only line of input contains 4 integers $N$, $M$, $K$, $L$ ($1 \le K \le N \le 10^{18}$; $1 \le M, \,\, L \le 10^{18}$) — quantity of different coins, number of Ivan's friends, size of Ivan's collection and quantity of coins, that must be new in Ivan's collection. -----Output----- Print one number — minimal number of coins one friend can gift to satisfy all the conditions. If it is impossible to satisfy all three conditions print "-1" (without quotes). -----Examples----- Input 20 15 2 3 Output 1 Input 10 11 2 4 Output -1 -----Note----- In the first test, one coin from each friend is enough, as he will be presented with 15 different coins and 13 of them will definitely be new. In the second test, Ivan has 11 friends, but there are only 10 different coins. So all friends can't present him different coins. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python n, m, k, l = map(int, input().split()) cnt = (k + l + m - 1) // m if cnt * m > n: print(-1) else: print(cnt) ```
vfc_10270
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1068/A", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "20 15 2 3\n", "output": "1", "type": "stdin_stdout" }, { "fn_name": null, "input": "10 11 2 4\n", "output": "-1", "type": "stdin_stdout" } ] }
apps
verifiable_code
130
Solve the following coding problem using the programming language python: Polycarp has a checkered sheet of paper of size n × m. Polycarp painted some of cells with black, the others remained white. Inspired by Malevich's "Black Square", Polycarp wants to paint minimum possible number of white cells with black so that all black cells form a square. You are to determine the minimum possible number of cells needed to be painted black so that the black cells form a black square with sides parallel to the painting's sides. All the cells that do not belong to the square should be white. The square's side should have positive length. -----Input----- The first line contains two integers n and m (1 ≤ n, m ≤ 100) — the sizes of the sheet. The next n lines contain m letters 'B' or 'W' each — the description of initial cells' colors. If a letter is 'B', then the corresponding cell is painted black, otherwise it is painted white. -----Output----- Print the minimum number of cells needed to be painted black so that the black cells form a black square with sides parallel to the painting's sides. All the cells that do not belong to the square should be white. If it is impossible, print -1. -----Examples----- Input 5 4 WWWW WWWB WWWB WWBB WWWW Output 5 Input 1 2 BB Output -1 Input 3 3 WWW WWW WWW Output 1 -----Note----- In the first example it is needed to paint 5 cells — (2, 2), (2, 3), (3, 2), (3, 3) and (4, 2). Then there will be a square with side equal to three, and the upper left corner in (2, 2). In the second example all the cells are painted black and form a rectangle, so it's impossible to get a square. In the third example all cells are colored white, so it's sufficient to color any cell black. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python h, w = map(int, input().split()) x0, y0, x1, y1, c = 1000, 1000, -1, -1, 0 for i in range(h): row = str(input()) for j in range(w): if row[j] == 'B': x0, y0, x1, y1, c = min(x0, i), min(y0, j), max(x1, i), max(y1, j), c + 1 ln = max(x1 - x0 + 1, y1 - y0 + 1) if ln > min(h, w): print(-1) elif x1 == -1: print(1) else: print(ln * ln - c) ```
vfc_10274
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/828/B", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5 4\nWWWW\nWWWB\nWWWB\nWWBB\nWWWW\n", "output": "5\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 2\nBB\n", "output": "-1\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
131
Solve the following coding problem using the programming language python: There is a beautiful garden of stones in Innopolis. Its most beautiful place is the $n$ piles with stones numbered from $1$ to $n$. EJOI participants have visited this place twice. When they first visited it, the number of stones in piles was $x_1, x_2, \ldots, x_n$, correspondingly. One of the participants wrote down this sequence in a notebook. They visited it again the following day, and the number of stones in piles was equal to $y_1, y_2, \ldots, y_n$. One of the participants also wrote it down in a notebook. It is well known that every member of the EJOI jury during the night either sits in the room $108$ or comes to the place with stones. Each jury member who comes there either takes one stone for himself or moves one stone from one pile to another. We can assume that there is an unlimited number of jury members. No one except the jury goes to the place with stones at night. Participants want to know whether their notes can be correct or they are sure to have made a mistake. -----Input----- The first line of the input file contains a single integer $n$, the number of piles with stones in the garden ($1 \leq n \leq 50$). The second line contains $n$ integers separated by spaces $x_1, x_2, \ldots, x_n$, the number of stones in piles recorded in the notebook when the participants came to the place with stones for the first time ($0 \leq x_i \leq 1000$). The third line contains $n$ integers separated by spaces $y_1, y_2, \ldots, y_n$, the number of stones in piles recorded in the notebook when the participants came to the place with stones for the second time ($0 \leq y_i \leq 1000$). -----Output----- If the records can be consistent output "Yes", otherwise output "No" (quotes for clarity). -----Examples----- Input 5 1 2 3 4 5 2 1 4 3 5 Output Yes Input 5 1 1 1 1 1 1 0 1 0 1 Output Yes Input 3 2 3 9 1 7 9 Output No -----Note----- In the first example, the following could have happened during the night: one of the jury members moved one stone from the second pile to the first pile, and the other jury member moved one stone from the fourth pile to the third pile. In the second example, the jury took stones from the second and fourth piles. It can be proved that it is impossible for the jury members to move and took stones to convert the first array into the second array. 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())) b = list(map(int, input().split())) c = sum(a) d = sum(b) if c >= d: print('Yes') else: print('No') ```
vfc_10278
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1013/A", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n1 2 3 4 5\n2 1 4 3 5\n", "output": "Yes\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n1 1 1 1 1\n1 0 1 0 1\n", "output": "Yes\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n2 3 9\n1 7 9\n", "output": "No\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "40\n361 372 139 808 561 460 421 961 727 719 130 235 320 470 432 759 317 886 624 666 917 133 736 710 462 424 541 118 228 216 612 339 800 557 291 128 801 9 0 318\n364 689 60 773 340 571 627 932 581 856 131 153 406 475 217 716 433 519 417 552 919 53 923 605 319 359 516 121 207 180 373 343 905 641 477 416 927 207 160 245\n", "output": "Yes\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "45\n246 523 714 431 266 139 591 246 845 818 805 198 70 620 166 478 87 849 415 228 957 59 190 332 632 14 451 857 221 638 837 222 970 643 19 172 39 185 903 342 750 265 241 968 876\n460 389 541 164 324 52 246 107 826 864 693 132 10 697 429 434 99 950 164 85 972 157 327 337 592 241 350 962 130 673 967 373 657 923 456 347 394 76 743 407 724 117 268 741 918\n", "output": "Yes\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "50\n620 222 703 953 303 333 371 125 554 88 60 189 873 644 817 100 760 64 887 605 611 845 762 916 21 26 254 553 602 66 796 531 329 888 274 584 215 135 69 403 680 734 440 406 53 958 135 230 918 206\n464 128 878 999 197 358 447 191 530 218 63 443 630 587 836 232 659 117 787 254 667 646 498 845 252 179 452 390 455 16 686 522 236 945 498 635 445 225 7 38 553 946 563 457 102 942 130 310 941 312\n", "output": "Yes\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
132
Solve the following coding problem using the programming language python: Students Vasya and Petya are studying at the BSU (Byteland State University). At one of the breaks they decided to order a pizza. In this problem pizza is a circle of some radius. The pizza was delivered already cut into n pieces. The i-th piece is a sector of angle equal to a_{i}. Vasya and Petya want to divide all pieces of pizza into two continuous sectors in such way that the difference between angles of these sectors is minimal. Sector angle is sum of angles of all pieces in it. Pay attention, that one of sectors can be empty. -----Input----- The first line contains one integer n (1 ≤ n ≤ 360)  — the number of pieces into which the delivered pizza was cut. The second line contains n integers a_{i} (1 ≤ a_{i} ≤ 360)  — the angles of the sectors into which the pizza was cut. The sum of all a_{i} is 360. -----Output----- Print one integer  — the minimal difference between angles of sectors that will go to Vasya and Petya. -----Examples----- Input 4 90 90 90 90 Output 0 Input 3 100 100 160 Output 40 Input 1 360 Output 360 Input 4 170 30 150 10 Output 0 -----Note----- In first sample Vasya can take 1 and 2 pieces, Petya can take 3 and 4 pieces. Then the answer is |(90 + 90) - (90 + 90)| = 0. In third sample there is only one piece of pizza that can be taken by only one from Vasya and Petya. So the answer is |360 - 0| = 360. In fourth sample Vasya can take 1 and 4 pieces, then Petya will take 2 and 3 pieces. So the answer is |(170 + 10) - (30 + 150)| = 0. Picture explaning fourth sample: [Image] Both red and green sectors consist of two adjacent pieces of pizza. So Vasya can take green sector, then Petya will take red sector. 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 = 360 for i in range(n): x = 0 for j in range(i, n): x += a[j] mn = min(mn, abs(x - (360 - x))) print(mn) ```
vfc_10282
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/895/A", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n90 90 90 90\n", "output": "0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n100 100 160\n", "output": "40\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n360\n", "output": "360\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n170 30 150 10\n", "output": "0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n10 10 10 10 320\n", "output": "280\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
133
Solve the following coding problem using the programming language python: Alice got many presents these days. So she decided to pack them into boxes and send them to her friends. There are $n$ kinds of presents. Presents of one kind are identical (i.e. there is no way to distinguish two gifts of the same kind). Presents of different kinds are different (i.e. that is, two gifts of different kinds are distinguishable). The number of presents of each kind, that Alice has is very big, so we can consider Alice has an infinite number of gifts of each kind. Also, there are $m$ boxes. All of them are for different people, so they are pairwise distinct (consider that the names of $m$ friends are written on the boxes). For example, putting the first kind of present into the first box but not into the second box, is different from putting the first kind of present into the second box but not into the first box. Alice wants to pack presents with the following rules: She won't pack more than one present of each kind into the same box, so each box should contain presents of different kinds (i.e. each box contains a subset of $n$ kinds, empty boxes are allowed); For each kind at least one present should be packed into some box. Now Alice wants to know how many different ways to pack the presents exists. Please, help her and calculate this number. Since the answer can be huge, output it by modulo $10^9+7$. See examples and their notes for clarification. -----Input----- The first line contains two integers $n$ and $m$, separated by spaces ($1 \leq n,m \leq 10^9$) — the number of kinds of presents and the number of boxes that Alice has. -----Output----- Print one integer  — the number of ways to pack the presents with Alice's rules, calculated by modulo $10^9+7$ -----Examples----- Input 1 3 Output 7 Input 2 2 Output 9 -----Note----- In the first example, there are seven ways to pack presents: $\{1\}\{\}\{\}$ $\{\}\{1\}\{\}$ $\{\}\{\}\{1\}$ $\{1\}\{1\}\{\}$ $\{\}\{1\}\{1\}$ $\{1\}\{\}\{1\}$ $\{1\}\{1\}\{1\}$ In the second example there are nine ways to pack presents: $\{\}\{1,2\}$ $\{1\}\{2\}$ $\{1\}\{1,2\}$ $\{2\}\{1\}$ $\{2\}\{1,2\}$ $\{1,2\}\{\}$ $\{1,2\}\{1\}$ $\{1,2\}\{2\}$ $\{1,2\}\{1,2\}$ For example, the way $\{2\}\{2\}$ is wrong, because presents of the first kind should be used in the least one box. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python # Contest: Codeforces Round #593 (Div. 2) (https://codeforces.com/contest/1236) # Problem: B: Alice and the List of Presents (https://codeforces.com/contest/1236/problem/B) def rint(): return int(input()) def rints(): return list(map(int, input().split())) M = 10**9 + 7 n, m = rints() print(pow((pow(2, m, M) + M - 1) % M, n, M)) ```
vfc_10286
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1236/B", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1 3\n", "output": "7", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 2\n", "output": "9", "type": "stdin_stdout" }, { "fn_name": null, "input": "1000000000 1000000000\n", "output": "751201557", "type": "stdin_stdout" }, { "fn_name": null, "input": "489132389 96\n", "output": "496937", "type": "stdin_stdout" }, { "fn_name": null, "input": "462817723 208\n", "output": "886407548", "type": "stdin_stdout" } ] }
apps
verifiable_code
134
Solve the following coding problem using the programming language python: Katya studies in a fifth grade. Recently her class studied right triangles and the Pythagorean theorem. It appeared, that there are triples of positive integers such that you can construct a right triangle with segments of lengths corresponding to triple. Such triples are called Pythagorean triples. For example, triples (3, 4, 5), (5, 12, 13) and (6, 8, 10) are Pythagorean triples. Here Katya wondered if she can specify the length of some side of right triangle and find any Pythagorean triple corresponding to such length? Note that the side which length is specified can be a cathetus as well as hypotenuse. Katya had no problems with completing this task. Will you do the same? -----Input----- The only line of the input contains single integer n (1 ≤ n ≤ 10^9) — the length of some side of a right triangle. -----Output----- Print two integers m and k (1 ≤ m, k ≤ 10^18), such that n, m and k form a Pythagorean triple, in the only line. In case if there is no any Pythagorean triple containing integer n, print - 1 in the only line. If there are many answers, print any of them. -----Examples----- Input 3 Output 4 5 Input 6 Output 8 10 Input 1 Output -1 Input 17 Output 144 145 Input 67 Output 2244 2245 -----Note-----[Image] Illustration for the first sample. 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()) if n % 4 == 0: temp = n // 4 m = temp * 3 k = temp * 5 elif n % 2 == 0: n //= 2 m = n**2 // 2 k = m + 1 m *= 2 k *= 2 else: m = n**2 // 2 k = m + 1 if 3 > n: print("-1") else: print(m,k) ```
vfc_10290
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/707/C", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n", "output": "4 5", "type": "stdin_stdout" }, { "fn_name": null, "input": "6\n", "output": "8 10", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n", "output": "-1", "type": "stdin_stdout" }, { "fn_name": null, "input": "17\n", "output": "144 145", "type": "stdin_stdout" }, { "fn_name": null, "input": "67\n", "output": "2244 2245", "type": "stdin_stdout" }, { "fn_name": null, "input": "10\n", "output": "24 26", "type": "stdin_stdout" } ] }
apps
verifiable_code
135
Solve the following coding problem using the programming language python: Imp is watching a documentary about cave painting. [Image] Some numbers, carved in chaotic order, immediately attracted his attention. Imp rapidly proposed a guess that they are the remainders of division of a number n by all integers i from 1 to k. Unfortunately, there are too many integers to analyze for Imp. Imp wants you to check whether all these remainders are distinct. Formally, he wants to check, if all $n \text{mod} i$, 1 ≤ i ≤ k, are distinct, i. e. there is no such pair (i, j) that: 1 ≤ i < j ≤ k, $n \operatorname{mod} i = n \operatorname{mod} j$, where $x \operatorname{mod} y$ is the remainder of division x by y. -----Input----- The only line contains two integers n, k (1 ≤ n, k ≤ 10^18). -----Output----- Print "Yes", if all the remainders are distinct, and "No" otherwise. You can print each letter in arbitrary case (lower or upper). -----Examples----- Input 4 4 Output No Input 5 3 Output Yes -----Note----- In the first sample remainders modulo 1 and 4 coincide. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python def main(): n, k = map(int, input().split()) for i in range(1, k + 1): if (n % i != (i - 1)): print("No") return print("Yes") main() ```
vfc_10294
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/922/C", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4 4\n", "output": "No\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 3\n", "output": "Yes\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 1\n", "output": "Yes\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "744 18\n", "output": "No\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "47879 10\n", "output": "Yes\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
136
Solve the following coding problem using the programming language python: You are given two very long integers a, b (leading zeroes are allowed). You should check what number a or b is greater or determine that they are equal. The input size is very large so don't use the reading of symbols one by one. Instead of that use the reading of a whole line or token. As input/output can reach huge size it is recommended to use fast input/output methods: for example, prefer to use scanf/printf instead of cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java. Don't use the function input() in Python2 instead of it use the function raw_input(). -----Input----- The first line contains a non-negative integer a. The second line contains a non-negative integer b. The numbers a, b may contain leading zeroes. Each of them contains no more than 10^6 digits. -----Output----- Print the symbol "<" if a < b and the symbol ">" if a > b. If the numbers are equal print the symbol "=". -----Examples----- Input 9 10 Output < Input 11 10 Output > Input 00012345 12345 Output = Input 0123 9 Output > Input 0123 111 Output > The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python a = input() b = input() n, m = len(a), len(b) if n > m: b = '0' * (n - m) + b else: a = '0' * (m - n) + a i = 0 while i < max(n, m) and a[i] == b[i]: i += 1 print('=' if i == max(n, m) else '<' if int(a[i]) < int(b[i]) else '>') ```
vfc_10298
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/616/A", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "9\n10\n", "output": "<\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "11\n10\n", "output": ">\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "00012345\n12345\n", "output": "=\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "0123\n9\n", "output": ">\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "0123\n111\n", "output": ">\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "9\n9\n", "output": "=\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
137
Solve the following coding problem using the programming language python: Kuro has recently won the "Most intelligent cat ever" contest. The three friends then decided to go to Katie's home to celebrate Kuro's winning. After a big meal, they took a small break then started playing games. Kuro challenged Katie to create a game with only a white paper, a pencil, a pair of scissors and a lot of arrows (you can assume that the number of arrows is infinite). Immediately, Katie came up with the game called Topological Parity. The paper is divided into $n$ pieces enumerated from $1$ to $n$. Shiro has painted some pieces with some color. Specifically, the $i$-th piece has color $c_{i}$ where $c_{i} = 0$ defines black color, $c_{i} = 1$ defines white color and $c_{i} = -1$ means that the piece hasn't been colored yet. The rules of the game is simple. Players must put some arrows between some pairs of different pieces in such a way that for each arrow, the number in the piece it starts from is less than the number of the piece it ends at. Also, two different pieces can only be connected by at most one arrow. After that the players must choose the color ($0$ or $1$) for each of the unpainted pieces. The score of a valid way of putting the arrows and coloring pieces is defined as the number of paths of pieces of alternating colors. For example, $[1 \to 0 \to 1 \to 0]$, $[0 \to 1 \to 0 \to 1]$, $[1]$, $[0]$ are valid paths and will be counted. You can only travel from piece $x$ to piece $y$ if and only if there is an arrow from $x$ to $y$. But Kuro is not fun yet. He loves parity. Let's call his favorite parity $p$ where $p = 0$ stands for "even" and $p = 1$ stands for "odd". He wants to put the arrows and choose colors in such a way that the score has the parity of $p$. It seems like there will be so many ways which satisfy Kuro. He wants to count the number of them but this could be a very large number. Let's help him with his problem, but print it modulo $10^{9} + 7$. -----Input----- The first line contains two integers $n$ and $p$ ($1 \leq n \leq 50$, $0 \leq p \leq 1$) — the number of pieces and Kuro's wanted parity. The second line contains $n$ integers $c_{1}, c_{2}, ..., c_{n}$ ($-1 \leq c_{i} \leq 1$) — the colors of the pieces. -----Output----- Print a single integer — the number of ways to put the arrows and choose colors so the number of valid paths of alternating colors has the parity of $p$. -----Examples----- Input 3 1 -1 0 1 Output 6 Input 2 1 1 0 Output 1 Input 1 1 -1 Output 2 -----Note----- In the first example, there are $6$ ways to color the pieces and add the arrows, as are shown in the figure below. The scores are $3, 3, 5$ for the first row and $5, 3, 3$ for the second row, both from left to right. [Image] The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python n,p=list(map(int,input().split())) nums=[0]+list(map(int,input().split())) mod=10**9+7 f=[[[[0]*2 for _ in range(2)] for _ in range(2)] for _ in range(n+1)] _2=[0]*(n+1) _2[0]=1 for i in range(1,n+1): _2[i]=(_2[i-1]<<1)%mod f[0][0][0][0]=1 if nums[1]!=0: f[1][1][0][1]+=1 if nums[1]!=1: f[1][1][1][0]+=1 for i in range(2,n+1): for j in range(2): for ob in range(2): for ow in range(2): qwq=f[i-1][j][ob][ow] if nums[i]!=0: if ob: f[i][j][ob][ow]=(f[i][j][ob][ow]+qwq*_2[i-2])%mod f[i][j^1][ob][ow|1]=(f[i][j^1][ob][ow|1]+qwq*_2[i-2])%mod else: f[i][j^1][ob][ow|1]=(f[i][j^1][ob][ow|1]+qwq*_2[i-1])%mod if nums[i]!=1: if ow: f[i][j][ob][ow]=(f[i][j][ob][ow]+qwq*_2[i-2])%mod f[i][j^1][ob|1][ow]=(f[i][j^1][ob|1][ow]+qwq*_2[i-2])%mod else: f[i][j^1][ob|1][ow]=(f[i][j^1][ob|1][ow]+qwq*_2[i-1])%mod ans=0 for i in range(2): for j in range(2): ans=(ans+f[n][p][i][j])%mod print(ans) ```
vfc_10302
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/979/E", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 1\n-1 0 1\n", "output": "6", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 1\n1 0\n", "output": "1", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 1\n-1\n", "output": "2", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 0\n-1\n", "output": "0", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 1\n0\n", "output": "1", "type": "stdin_stdout" } ] }
apps
verifiable_code
138
Solve the following coding problem using the programming language python: Little girl Alyona is in a shop to buy some copybooks for school. She study four subjects so she wants to have equal number of copybooks for each of the subjects. There are three types of copybook's packs in the shop: it is possible to buy one copybook for a rubles, a pack of two copybooks for b rubles, and a pack of three copybooks for c rubles. Alyona already has n copybooks. What is the minimum amount of rubles she should pay to buy such number of copybooks k that n + k is divisible by 4? There are infinitely many packs of any type in the shop. Alyona can buy packs of different type in the same purchase. -----Input----- The only line contains 4 integers n, a, b, c (1 ≤ n, a, b, c ≤ 10^9). -----Output----- Print the minimum amount of rubles she should pay to buy such number of copybooks k that n + k is divisible by 4. -----Examples----- Input 1 1 3 4 Output 3 Input 6 2 1 1 Output 1 Input 4 4 4 4 Output 0 Input 999999999 1000000000 1000000000 1000000000 Output 1000000000 -----Note----- In the first example Alyona can buy 3 packs of 1 copybook for 3a = 3 rubles in total. After that she will have 4 copybooks which she can split between the subjects equally. In the second example Alyuna can buy a pack of 2 copybooks for b = 1 ruble. She will have 8 copybooks in total. In the third example Alyona can split the copybooks she already has between the 4 subject equally, so she doesn't need to buy anything. In the fourth example Alyona should buy one pack of one copybook. 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, c = map(int, input().split()) res = 10 ** 100 for i in range(50): for j in range(50): for k in range(50): if (n + i + 2 * j + 3 * k) % 4 == 0: res = min(res, a * i + b * j + c * k) print(res) ```
vfc_10306
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/740/A", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1 1 3 4\n", "output": "3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "6 2 1 1\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 4 4 4\n", "output": "0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "999999999 1000000000 1000000000 1000000000\n", "output": "1000000000\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
139
Solve the following coding problem using the programming language python: You are given a directed graph consisting of n vertices and m edges (each edge is directed, so it can be traversed in only one direction). You are allowed to remove at most one edge from it. Can you make this graph acyclic by removing at most one edge from it? A directed graph is called acyclic iff it doesn't contain any cycle (a non-empty path that starts and ends in the same vertex). -----Input----- The first line contains two integers n and m (2 ≤ n ≤ 500, 1 ≤ m ≤ min(n(n - 1), 100000)) — the number of vertices and the number of edges, respectively. Then m lines follow. Each line contains two integers u and v denoting a directed edge going from vertex u to vertex v (1 ≤ u, v ≤ n, u ≠ v). Each ordered pair (u, v) is listed at most once (there is at most one directed edge from u to v). -----Output----- If it is possible to make this graph acyclic by removing at most one edge, print YES. Otherwise, print NO. -----Examples----- Input 3 4 1 2 2 3 3 2 3 1 Output YES Input 5 6 1 2 2 3 3 2 3 1 2 1 4 5 Output NO -----Note----- In the first example you can remove edge $2 \rightarrow 3$, and the graph becomes acyclic. In the second example you have to remove at least two edges (for example, $2 \rightarrow 1$ and $2 \rightarrow 3$) in order to make the graph acyclic. 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()) g = [[] for i in range(n)] for _ in range(m): u,v = map(int, input().split()) g[u-1].append(v-1) st = [] vis = [0 for _ in range(n)] nxt = [0 for _ in range(n)] es = set() cycle=False for i in range(n): if cycle: break if vis[i] != 0: continue st = [i] vis[i] = 1 while len(st) > 0: v = st[-1] if nxt[v] < len(g[v]): u = g[v][nxt[v]] nxt[v] += 1 if vis[u] == 0 or vis[u] == 2: vis[u] = 1 st.append(u) else: ns = set() fr = len(st)-1 to = u while 1: ns.add((st[fr], to)) if st[fr] == u and len(ns) > 1: break elif st[fr] == u: ns.add((to, st[fr])) break to = st[fr] fr -= 1 es = ns cycle =True break else: vis[v] = 2 del st[-1] if not cycle: print('YES') return if len(es) == 50 and n == 500 and m == 100000: print('NO') return for edge in es: vis = [0 for _ in range(n)] nxt = [0 for _ in range(n)] fail = False for i in range(n): if vis[i] != 0: continue st = [i] vis[i] = 1 while len(st) > 0: v = st[-1] if nxt[v] < len(g[v]): u = g[v][nxt[v]] nxt[v] += 1 if v == edge[0] and u == edge[1]: continue if vis[u] == 0 or vis[u] == 2: vis[u] = 1 st.append(u) else: fail = True break else: vis[v] = 2 del st[-1] if not fail: print('YES') return print('NO') ```
vfc_10310
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/915/D", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 4\n1 2\n2 3\n3 2\n3 1\n", "output": "YES\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 6\n1 2\n2 3\n3 2\n3 1\n2 1\n4 5\n", "output": "NO\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 2\n1 2\n2 1\n", "output": "YES\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
140
Solve the following coding problem using the programming language python: The mayor of the Central Town wants to modernize Central Street, represented in this problem by the $(Ox)$ axis. On this street, there are $n$ antennas, numbered from $1$ to $n$. The $i$-th antenna lies on the position $x_i$ and has an initial scope of $s_i$: it covers all integer positions inside the interval $[x_i - s_i; x_i + s_i]$. It is possible to increment the scope of any antenna by $1$, this operation costs $1$ coin. We can do this operation as much as we want (multiple times on the same antenna if we want). To modernize the street, we need to make all integer positions from $1$ to $m$ inclusive covered by at least one antenna. Note that it is authorized to cover positions outside $[1; m]$, even if it's not required. What is the minimum amount of coins needed to achieve this modernization? -----Input----- The first line contains two integers $n$ and $m$ ($1 \le n \le 80$ and $n \le m \le 100\ 000$). The $i$-th of the next $n$ lines contains two integers $x_i$ and $s_i$ ($1 \le x_i \le m$ and $0 \le s_i \le m$). On each position, there is at most one antenna (values $x_i$ are pairwise distinct). -----Output----- You have to output a single integer: the minimum amount of coins required to make all integer positions from $1$ to $m$ inclusive covered by at least one antenna. -----Examples----- Input 3 595 43 2 300 4 554 10 Output 281 Input 1 1 1 1 Output 0 Input 2 50 20 0 3 1 Output 30 Input 5 240 13 0 50 25 60 5 155 70 165 70 Output 26 -----Note----- In the first example, here is a possible strategy: Increase the scope of the first antenna by $40$, so that it becomes $2 + 40 = 42$. This antenna will cover interval $[43 - 42; 43 + 42]$ which is $[1; 85]$ Increase the scope of the second antenna by $210$, so that it becomes $4 + 210 = 214$. This antenna will cover interval $[300 - 214; 300 + 214]$, which is $[86; 514]$ Increase the scope of the third antenna by $31$, so that it becomes $10 + 31 = 41$. This antenna will cover interval $[554 - 41; 554 + 41]$, which is $[513; 595]$ Total cost is $40 + 210 + 31 = 281$. We can prove that it's the minimum cost required to make all positions from $1$ to $595$ covered by at least one antenna. Note that positions $513$ and $514$ are in this solution covered by two different antennas, but it's not important. — In the second example, the first antenna already covers an interval $[0; 2]$ so we have nothing to do. Note that the only position that we needed to cover was position $1$; positions $0$ and $2$ are covered, but it's not important. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python import sys input = sys.stdin.readline n,m=list(map(int,input().split())) A=[] COVERED=[0]*(m+1) for i in range(n): x,y=list(map(int,input().split())) A.append((x-y,x+y)) for j in range(max(0,x-y),min(m+1,x+y+1)): COVERED[j]=1 if min(COVERED[1:])==1: print(0) return A.sort() DP=[m]*(m+2) DP[1]=0 covind=1 while COVERED[covind]==1: DP[covind]=0 covind+=1 DP[covind]=0 NEXT=[i+1 for i in range(m+1)] for j in range(m-1,-1,-1): if COVERED[j+1]==1: NEXT[j]=NEXT[j+1] def nex(i): if i<=m: return NEXT[i] else: return m+1 for i in range(1,m+1): if COVERED[i]==1: continue for x,y in A: if x<i: continue DP[nex(y+(x-i))]=min(DP[i]+(x-i),DP[nex(y+(x-i))]) #print(DP) ANS=DP[-1] for i in range(m,-1,-1): if DP[i]!=m+1: ANS=(min(ANS,DP[i]+(m+1-i))) print(ANS) ```
vfc_10314
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1253/E", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 595\n43 2\n300 4\n554 10\n", "output": "281\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 1\n1 1\n", "output": "0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 50\n20 0\n3 1\n", "output": "30\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
142
Solve the following coding problem using the programming language python: A New Year party is not a New Year party without lemonade! As usual, you are expecting a lot of guests, and buying lemonade has already become a pleasant necessity. Your favorite store sells lemonade in bottles of n different volumes at different costs. A single bottle of type i has volume 2^{i} - 1 liters and costs c_{i} roubles. The number of bottles of each type in the store can be considered infinite. You want to buy at least L liters of lemonade. How many roubles do you have to spend? -----Input----- The first line contains two integers n and L (1 ≤ n ≤ 30; 1 ≤ L ≤ 10^9) — the number of types of bottles in the store and the required amount of lemonade in liters, respectively. The second line contains n integers c_1, c_2, ..., c_{n} (1 ≤ c_{i} ≤ 10^9) — the costs of bottles of different types. -----Output----- Output a single integer — the smallest number of roubles you have to pay in order to buy at least L liters of lemonade. -----Examples----- Input 4 12 20 30 70 90 Output 150 Input 4 3 10000 1000 100 10 Output 10 Input 4 3 10 100 1000 10000 Output 30 Input 5 787787787 123456789 234567890 345678901 456789012 987654321 Output 44981600785557577 -----Note----- In the first example you should buy one 8-liter bottle for 90 roubles and two 2-liter bottles for 30 roubles each. In total you'll get 12 liters of lemonade for just 150 roubles. In the second example, even though you need only 3 liters, it's cheaper to buy a single 8-liter bottle for 10 roubles. In the third example it's best to buy three 1-liter bottles for 10 roubles each, getting three liters for 30 roubles. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python 3 # Copyright (C) 2017 Sayutin Dmitry. # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License as # published by the Free Software Foundation; version 3 # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; If not, see <http://www.gnu.org/licenses/>. def solve(a, l): if l == 0: return 0 if l == 1: return a[0] k = 0 while (2 ** k) < l: k += 1 return min(a[k], a[k - 1] + solve(a, l - (2 ** (k - 1)))) def main(): n, l = list(map(int, input().split())) a = list(map(int, input().split())) for i in range(n - 2, -1, -1): if a[i] > a[i + 1]: a[i] = a[i + 1] for i in range(1, n): if a[i] > 2 * a[i - 1]: a[i] = 2 * a[i - 1] while len(a) < 35: a.append(2 * a[len(a) - 1]) #print(a) print(solve(a, l)) main() ```
vfc_10322
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/913/C", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4 12\n20 30 70 90\n", "output": "150\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 3\n10000 1000 100 10\n", "output": "10\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 3\n10 100 1000 10000\n", "output": "30\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 787787787\n123456789 234567890 345678901 456789012 987654321\n", "output": "44981600785557577\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "30 792520535\n528145579 682850171 79476920 178914057 180053263 538638086 433143781 299775597 723428544 177615223 959893339 639448861 506106572 807471834 42398440 347390133 65783782 988164990 606389825 877178711 513188067 609539702 558894975 271129128 956393790 981348376 608410525 61890513 991440277 682151552\n", "output": "371343078\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "30 719520853\n1 3 7 9 21 44 81 49 380 256 1592 1523 4711 6202 1990 48063 112547 210599 481862 1021025 2016280 643778 4325308 3603826 20964534 47383630 100267203 126018116 187142230 604840362\n", "output": "87393281\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
143
Solve the following coding problem using the programming language python: Someone gave Alyona an array containing n positive integers a_1, a_2, ..., a_{n}. In one operation, Alyona can choose any element of the array and decrease it, i.e. replace with any positive integer that is smaller than the current one. Alyona can repeat this operation as many times as she wants. In particular, she may not apply any operation to the array at all. Formally, after applying some operations Alyona will get an array of n positive integers b_1, b_2, ..., b_{n} such that 1 ≤ b_{i} ≤ a_{i} for every 1 ≤ i ≤ n. Your task is to determine the maximum possible value of mex of this array. Mex of an array in this problem is the minimum positive integer that doesn't appear in this array. For example, mex of the array containing 1, 3 and 4 is equal to 2, while mex of the array containing 2, 3 and 2 is equal to 1. -----Input----- The first line of the input contains a single integer n (1 ≤ n ≤ 100 000) — the number of elements in the Alyona's array. The second line of the input contains n integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10^9) — the elements of the array. -----Output----- Print one positive integer — the maximum possible value of mex of the array after Alyona applies some (possibly none) operations. -----Examples----- Input 5 1 3 3 3 6 Output 5 Input 2 2 1 Output 3 -----Note----- In the first sample case if one will decrease the second element value to 2 and the fifth element value to 4 then the mex value of resulting array 1 2 3 3 4 will be equal to 5. To reach the answer to the second sample case one must not decrease any of the array elements. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python x=int(input()) l=list(map(int, input().split(' '))) l.sort() a=1 for i in l: if i>=a: a+=1 print(a) ```
vfc_10326
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/682/B", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n1 3 3 3 6\n", "output": "5\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n2 1\n", "output": "3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n1\n", "output": "2\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
144
Solve the following coding problem using the programming language python: Recently Vasya found a golden ticket — a sequence which consists of $n$ digits $a_1a_2\dots a_n$. Vasya considers a ticket to be lucky if it can be divided into two or more non-intersecting segments with equal sums. For example, ticket $350178$ is lucky since it can be divided into three segments $350$, $17$ and $8$: $3+5+0=1+7=8$. Note that each digit of sequence should belong to exactly one segment. Help Vasya! Tell him if the golden ticket he found is lucky or not. -----Input----- The first line contains one integer $n$ ($2 \le n \le 100$) — the number of digits in the ticket. The second line contains $n$ digits $a_1 a_2 \dots a_n$ ($0 \le a_i \le 9$) — the golden ticket. Digits are printed without spaces. -----Output----- If the golden ticket is lucky then print "YES", otherwise print "NO" (both case insensitive). -----Examples----- Input 5 73452 Output YES Input 4 1248 Output NO -----Note----- In the first example the ticket can be divided into $7$, $34$ and $52$: $7=3+4=5+2$. In the second example it is impossible to divide ticket into segments with equal sum. 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, list(input()))) for i in range(n - 1): sm = sum(a[:i + 1]) tn = 0 res = True has = False for j in range(i + 1, n): tn += a[j] if (tn == sm): tn = 0 has = True elif tn > sm: res = False break if (tn == 0 and res and has): print("YES") break else: print("NO") ```
vfc_10330
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1030/C", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n73452\n", "output": "YES\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n1248\n", "output": "NO\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
145
Solve the following coding problem using the programming language python: Those days, many boys use beautiful girls' photos as avatars in forums. So it is pretty hard to tell the gender of a user at the first glance. Last year, our hero went to a forum and had a nice chat with a beauty (he thought so). After that they talked very often and eventually they became a couple in the network. But yesterday, he came to see "her" in the real world and found out "she" is actually a very strong man! Our hero is very sad and he is too tired to love again now. So he came up with a way to recognize users' genders by their user names. This is his method: if the number of distinct characters in one's user name is odd, then he is a male, otherwise she is a female. You are given the string that denotes the user name, please help our hero to determine the gender of this user by his method. -----Input----- The first line contains a non-empty string, that contains only lowercase English letters — the user name. This string contains at most 100 letters. -----Output----- If it is a female by our hero's method, print "CHAT WITH HER!" (without the quotes), otherwise, print "IGNORE HIM!" (without the quotes). -----Examples----- Input wjmzbmr Output CHAT WITH HER! Input xiaodao Output IGNORE HIM! Input sevenkplus Output CHAT WITH HER! -----Note----- For the first example. There are 6 distinct characters in "wjmzbmr". These characters are: "w", "j", "m", "z", "b", "r". So wjmzbmr is a female and you should print "CHAT WITH HER!". The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python s = input() q = set() for i in range(0, len(s)): q.add(s[i]) print("IGNORE HIM!" if len(q) % 2 == 1 else "CHAT WITH HER!") ```
vfc_10334
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/236/A", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "wjmzbmr\n", "output": "CHAT WITH HER!\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
146
Solve the following coding problem using the programming language python: This morning, Roman woke up and opened the browser with $n$ opened tabs numbered from $1$ to $n$. There are two kinds of tabs: those with the information required for the test and those with social network sites. Roman decided that there are too many tabs open so he wants to close some of them. He decided to accomplish this by closing every $k$-th ($2 \leq k \leq n - 1$) tab. Only then he will decide whether he wants to study for the test or to chat on the social networks. Formally, Roman will choose one tab (let its number be $b$) and then close all tabs with numbers $c = b + i \cdot k$ that satisfy the following condition: $1 \leq c \leq n$ and $i$ is an integer (it may be positive, negative or zero). For example, if $k = 3$, $n = 14$ and Roman chooses $b = 8$, then he will close tabs with numbers $2$, $5$, $8$, $11$ and $14$. After closing the tabs Roman will calculate the amount of remaining tabs with the information for the test (let's denote it $e$) and the amount of remaining social network tabs ($s$). Help Roman to calculate the maximal absolute value of the difference of those values $|e - s|$ so that it would be easy to decide what to do next. -----Input----- The first line contains two integers $n$ and $k$ ($2 \leq k < n \leq 100$) — the amount of tabs opened currently and the distance between the tabs closed. The second line consists of $n$ integers, each of them equal either to $1$ or to $-1$. The $i$-th integer denotes the type of the $i$-th tab: if it is equal to $1$, this tab contains information for the test, and if it is equal to $-1$, it's a social network tab. -----Output----- Output a single integer — the maximum absolute difference between the amounts of remaining tabs of different types $|e - s|$. -----Examples----- Input 4 2 1 1 -1 1 Output 2 Input 14 3 -1 1 -1 -1 1 -1 -1 1 -1 -1 1 -1 -1 1 Output 9 -----Note----- In the first example we can choose $b = 1$ or $b = 3$. We will delete then one tab of each type and the remaining tabs are then all contain test information. Thus, $e = 2$ and $s = 0$ and $|e - s| = 2$. In the second example, on the contrary, we can leave opened only tabs that have social networks opened in them. 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())) t = list(map(int, input().split())) d = [0 for _ in range(n)] for _ in range(n): for i in range(n): if i % k != _ % k: d[_] += t[i] print(max(abs(d[_]) for _ in range(n))) ```
vfc_10338
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1100/A", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4 2\n1 1 -1 1\n", "output": "2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "14 3\n-1 1 -1 -1 1 -1 -1 1 -1 -1 1 -1 -1 1\n", "output": "9\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 2\n1 1 1 -1\n", "output": "2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 2\n-1 1 -1 -1\n", "output": "2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 2\n1 1 -1\n", "output": "1\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
147
Solve the following coding problem using the programming language python: R3D3 spent some time on an internship in MDCS. After earning enough money, he decided to go on a holiday somewhere far, far away. He enjoyed suntanning, drinking alcohol-free cocktails and going to concerts of popular local bands. While listening to "The White Buttons" and their hit song "Dacan the Baker", he met another robot for whom he was sure is the love of his life. Well, his summer, at least. Anyway, R3D3 was too shy to approach his potential soulmate, so he decided to write her a love letter. However, he stumbled upon a problem. Due to a terrorist threat, the Intergalactic Space Police was monitoring all letters sent in the area. Thus, R3D3 decided to invent his own alphabet, for which he was sure his love would be able to decipher. There are n letters in R3D3’s alphabet, and he wants to represent each letter as a sequence of '0' and '1', so that no letter’s sequence is a prefix of another letter's sequence. Since the Intergalactic Space Communications Service has lately introduced a tax for invented alphabets, R3D3 must pay a certain amount of money for each bit in his alphabet’s code (check the sample test for clarifications). He is too lovestruck to think clearly, so he asked you for help. Given the costs c_0 and c_1 for each '0' and '1' in R3D3’s alphabet, respectively, you should come up with a coding for the alphabet (with properties as above) with minimum total cost. -----Input----- The first line of input contains three integers n (2 ≤ n ≤ 10^8), c_0 and c_1 (0 ≤ c_0, c_1 ≤ 10^8) — the number of letters in the alphabet, and costs of '0' and '1', respectively. -----Output----- Output a single integer — minimum possible total a cost of the whole alphabet. -----Example----- Input 4 1 2 Output 12 -----Note----- There are 4 letters in the alphabet. The optimal encoding is "00", "01", "10", "11". There are 4 zeroes and 4 ones used, so the total cost is 4·1 + 4·2 = 12. 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("data.txt") input=sys.stdin.readline n,a,b=map(int,input().split()) if a<b: a,b=b,a if b==0: # 1 01 001 0001 ... is optimal, plus a long series of 0's print((n-1)*a) else: # pascal's triangle thing pascal=[[1]*20005] for i in range(20004): newrow=[1] for j in range(1,20005): newrow.append(newrow[-1]+pascal[-1][j]) if newrow[-1]>n: break pascal.append(newrow) def getcom(a,b): # return a+b choose b # if larger than n, return infinite if len(pascal[a])>b: return pascal[a][b] if b==0: return 1 if b==1: return a return 100000005 # start with the null node (prefix cost 0) # can split a node into two other nodes with added cost c+a+b # new nodes have prefix costs c+a, c+b # want n-1 splits in total n-=1 # now represents number of splits needed # binary search the last cost added lo=0 hi=a*int((n**0.5)*2+5) while 1: mid=(lo+hi)//2 # count stuff c0=0 # < mid c1=0 # = mid for i in range(mid//a+1): j=(mid-i*a)//b if (mid-i*a)%b!=0: # c0 += iC0 + (i+1)C1 + (i+2)C2 + ... + (i+j)Cj for k in range(j+1): #print(mid,i,k) c0+=getcom(i,k) if c0>n: break else: for k in range(j): #print(mid,i,k) c0+=getcom(i,k) if c0>n: break #print(mid,i,j,"c1") c1+=getcom(i,j) #print(mid,"is",c0,c1) if n<c0: hi=mid-1 elif c0+c1<n: lo=mid+1 else: # mid is correct cutoff lowcost=0 # sum of all cost, where cost < mid for i in range(mid//a+1): j=(mid-i*a)//b if (mid-i*a)%b!=0: for k in range(j+1): lowcost+=getcom(i,k)*(i*a+k*b) else: for k in range(j): lowcost+=getcom(i,k)*(i*a+k*b) temp=lowcost+(n-c0)*mid print(temp+n*(a+b)) break ```
vfc_10342
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/717/B", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4 1 2\n", "output": "12\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 1 5\n", "output": "6\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 1 1\n", "output": "5\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 5 5\n", "output": "60\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 0 0\n", "output": "0\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
148
Solve the following coding problem using the programming language python: The circle line of the Roflanpolis subway has $n$ stations. There are two parallel routes in the subway. The first one visits stations in order $1 \to 2 \to \ldots \to n \to 1 \to 2 \to \ldots$ (so the next stop after station $x$ is equal to $(x+1)$ if $x < n$ and $1$ otherwise). The second route visits stations in order $n \to (n-1) \to \ldots \to 1 \to n \to (n-1) \to \ldots$ (so the next stop after station $x$ is equal to $(x-1)$ if $x>1$ and $n$ otherwise). All trains depart their stations simultaneously, and it takes exactly $1$ minute to arrive at the next station. Two toads live in this city, their names are Daniel and Vlad. Daniel is currently in a train of the first route at station $a$ and will exit the subway when his train reaches station $x$. Coincidentally, Vlad is currently in a train of the second route at station $b$ and he will exit the subway when his train reaches station $y$. Surprisingly, all numbers $a,x,b,y$ are distinct. Toad Ilya asks you to check if Daniel and Vlad will ever be at the same station at the same time during their journey. In other words, check if there is a moment when their trains stop at the same station. Note that this includes the moments when Daniel or Vlad enter or leave the subway. -----Input----- The first line contains five space-separated integers $n$, $a$, $x$, $b$, $y$ ($4 \leq n \leq 100$, $1 \leq a, x, b, y \leq n$, all numbers among $a$, $x$, $b$, $y$ are distinct) — the number of stations in Roflanpolis, Daniel's start station, Daniel's finish station, Vlad's start station and Vlad's finish station, respectively. -----Output----- Output "YES" if there is a time moment when Vlad and Daniel are at the same station, and "NO" otherwise. You can print each letter in any case (upper or lower). -----Examples----- Input 5 1 4 3 2 Output YES Input 10 2 1 9 10 Output NO -----Note----- In the first example, Daniel and Vlad start at the stations $(1, 3)$. One minute later they are at stations $(2, 2)$. They are at the same station at this moment. Note that Vlad leaves the subway right after that. Consider the second example, let's look at the stations Vlad and Daniel are at. They are: initially $(2, 9)$, after $1$ minute $(3, 8)$, after $2$ minutes $(4, 7)$, after $3$ minutes $(5, 6)$, after $4$ minutes $(6, 5)$, after $5$ minutes $(7, 4)$, after $6$ minutes $(8, 3)$, after $7$ minutes $(9, 2)$, after $8$ minutes $(10, 1)$, after $9$ minutes $(1, 10)$. After that, they both leave the subway because they are at their finish stations, so there is no moment when they both are at the same station. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python n, a, x, b, y = map(int, input().split()) while a != x and b != y and a != b: if a == b: break a = a % n + 1 b = b - 1 if b - 1 else n print("YNEOS"[a != b::2]) ```
vfc_10346
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1169/A", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5 1 4 3 2\n", "output": "YES\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "10 2 1 9 10\n", "output": "NO\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 3 4 2 1\n", "output": "NO\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "100 2 97 84 89\n", "output": "YES\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "100 43 55 42 15\n", "output": "NO\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
149
Solve the following coding problem using the programming language python: Unlucky year in Berland is such a year that its number n can be represented as n = x^{a} + y^{b}, where a and b are non-negative integer numbers. For example, if x = 2 and y = 3 then the years 4 and 17 are unlucky (4 = 2^0 + 3^1, 17 = 2^3 + 3^2 = 2^4 + 3^0) and year 18 isn't unlucky as there is no such representation for it. Such interval of years that there are no unlucky years in it is called The Golden Age. You should write a program which will find maximum length of The Golden Age which starts no earlier than the year l and ends no later than the year r. If all years in the interval [l, r] are unlucky then the answer is 0. -----Input----- The first line contains four integer numbers x, y, l and r (2 ≤ x, y ≤ 10^18, 1 ≤ l ≤ r ≤ 10^18). -----Output----- Print the maximum length of The Golden Age within the interval [l, r]. If all years in the interval [l, r] are unlucky then print 0. -----Examples----- Input 2 3 1 10 Output 1 Input 3 5 10 22 Output 8 Input 2 3 3 5 Output 0 -----Note----- In the first example the unlucky years are 2, 3, 4, 5, 7, 9 and 10. So maximum length of The Golden Age is achived in the intervals [1, 1], [6, 6] and [8, 8]. In the second example the longest Golden Age is the interval [15, 22]. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python x,y,l,r=list(map(int,input().split())) b=set() a=0 b.add(l-1) b.add(r+1) for i in range(100): xx=x**i if xx>r: break for j in range(100): rr=xx+(y**j) if rr>r: break if rr>=l: b.add(rr) b=sorted(list(b)) for i in range(1,len(b)): a=max(a,b[i]-b[i-1]-1) print(a) ```
vfc_10350
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/813/B", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2 3 1 10\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 5 10 22\n", "output": "8\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 3 3 5\n", "output": "0\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
150
Solve the following coding problem using the programming language python: Mr. Funt now lives in a country with a very specific tax laws. The total income of mr. Funt during this year is equal to n (n ≥ 2) burles and the amount of tax he has to pay is calculated as the maximum divisor of n (not equal to n, of course). For example, if n = 6 then Funt has to pay 3 burles, while for n = 25 he needs to pay 5 and if n = 2 he pays only 1 burle. As mr. Funt is a very opportunistic person he wants to cheat a bit. In particular, he wants to split the initial n in several parts n_1 + n_2 + ... + n_{k} = n (here k is arbitrary, even k = 1 is allowed) and pay the taxes for each part separately. He can't make some part equal to 1 because it will reveal him. So, the condition n_{i} ≥ 2 should hold for all i from 1 to k. Ostap Bender wonders, how many money Funt has to pay (i.e. minimal) if he chooses and optimal way to split n in parts. -----Input----- The first line of the input contains a single integer n (2 ≤ n ≤ 2·10^9) — the total year income of mr. Funt. -----Output----- Print one integer — minimum possible number of burles that mr. Funt has to pay as a tax. -----Examples----- Input 4 Output 2 Input 27 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 is_izi(k): i = 2 while (i * i <= k): if (k % i == 0): return 0 i += 1 return 1 n = int(input()) if (is_izi(n)): print(1) elif n % 2 == 0: print(2) elif n % 2 == 1: if (is_izi(n - 2)): print(2) else: print(3) ```
vfc_10354
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/735/D", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n", "output": "2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "27\n", "output": "3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "10\n", "output": "2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2000000000\n", "output": "2\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
151
Solve the following coding problem using the programming language python: Beroffice text editor has a wide range of features that help working with text. One of the features is an automatic search for typos and suggestions of how to fix them. Beroffice works only with small English letters (i.e. with 26 letters from a to z). Beroffice thinks that a word is typed with a typo if there are three or more consonants in a row in the word. The only exception is that if the block of consonants has all letters the same, then this block (even if its length is greater than three) is not considered a typo. Formally, a word is typed with a typo if there is a block of not less that three consonants in a row, and there are at least two different letters in this block. For example: the following words have typos: "hellno", "hackcerrs" and "backtothefutttture"; the following words don't have typos: "helllllooooo", "tobeornottobe" and "oooooo". When Beroffice editor finds a word with a typo, it inserts as little as possible number of spaces in this word (dividing it into several words) in such a way that each of the resulting words is typed without any typos. Implement this feature of Beroffice editor. Consider the following letters as the only vowels: 'a', 'e', 'i', 'o' and 'u'. All the other letters are consonants in this problem. -----Input----- The only line contains a non-empty word consisting of small English letters. The length of the word is between 1 and 3000 letters. -----Output----- Print the given word without any changes if there are no typos. If there is at least one typo in the word, insert the minimum number of spaces into the word so that each of the resulting words doesn't have any typos. If there are multiple solutions, print any of them. -----Examples----- Input hellno Output hell no Input abacaba Output abacaba Input asdfasdf Output asd fasd f The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python s = input() st = {'a', 'e', 'i', 'o', 'u', ' '} res = "" def check(s): if (len(s) < 3): return True if (s[-1] not in st and s[-2] not in st and s[-3] not in st) and (s[-1] != s[-2] or s[-2] != s[-3] or s[-1] != s[-3]): return False return True for item in s: if not check(res + item): res += " " res += item print(res) ```
vfc_10358
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/858/C", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "hellno\n", "output": "hell no \n", "type": "stdin_stdout" }, { "fn_name": null, "input": "abacaba\n", "output": "abacaba \n", "type": "stdin_stdout" } ] }
apps
verifiable_code
152
Solve the following coding problem using the programming language python: Anton is playing a very interesting computer game, but now he is stuck at one of the levels. To pass to the next level he has to prepare n potions. Anton has a special kettle, that can prepare one potions in x seconds. Also, he knows spells of two types that can faster the process of preparing potions. Spells of this type speed up the preparation time of one potion. There are m spells of this type, the i-th of them costs b_{i} manapoints and changes the preparation time of each potion to a_{i} instead of x. Spells of this type immediately prepare some number of potions. There are k such spells, the i-th of them costs d_{i} manapoints and instantly create c_{i} potions. Anton can use no more than one spell of the first type and no more than one spell of the second type, and the total number of manapoints spent should not exceed s. Consider that all spells are used instantly and right before Anton starts to prepare potions. Anton wants to get to the next level as fast as possible, so he is interested in the minimum number of time he needs to spent in order to prepare at least n potions. -----Input----- The first line of the input contains three integers n, m, k (1 ≤ n ≤ 2·10^9, 1 ≤ m, k ≤ 2·10^5) — the number of potions, Anton has to make, the number of spells of the first type and the number of spells of the second type. The second line of the input contains two integers x and s (2 ≤ x ≤ 2·10^9, 1 ≤ s ≤ 2·10^9) — the initial number of seconds required to prepare one potion and the number of manapoints Anton can use. The third line contains m integers a_{i} (1 ≤ a_{i} < x) — the number of seconds it will take to prepare one potion if the i-th spell of the first type is used. The fourth line contains m integers b_{i} (1 ≤ b_{i} ≤ 2·10^9) — the number of manapoints to use the i-th spell of the first type. There are k integers c_{i} (1 ≤ c_{i} ≤ n) in the fifth line — the number of potions that will be immediately created if the i-th spell of the second type is used. It's guaranteed that c_{i} are not decreasing, i.e. c_{i} ≤ c_{j} if i < j. The sixth line contains k integers d_{i} (1 ≤ d_{i} ≤ 2·10^9) — the number of manapoints required to use the i-th spell of the second type. It's guaranteed that d_{i} are not decreasing, i.e. d_{i} ≤ d_{j} if i < j. -----Output----- Print one integer — the minimum time one has to spent in order to prepare n potions. -----Examples----- Input 20 3 2 10 99 2 4 3 20 10 40 4 15 10 80 Output 20 Input 20 3 2 10 99 2 4 3 200 100 400 4 15 100 800 Output 200 -----Note----- In the first sample, the optimum answer is to use the second spell of the first type that costs 10 manapoints. Thus, the preparation time of each potion changes to 4 seconds. Also, Anton should use the second spell of the second type to instantly prepare 15 potions spending 80 manapoints. The total number of manapoints used is 10 + 80 = 90, and the preparation time is 4·5 = 20 seconds (15 potions were prepared instantly, and the remaining 5 will take 4 seconds each). In the second sample, Anton can't use any of the spells, so he just prepares 20 potions, spending 10 seconds on each of them and the answer is 20·10 = 200. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python n, m, k = list(map(int, input().split())) x, s = list(map(int, input().split())) t = list(map(int, input().split())) pr = list(map(int, input().split())) t2 = list(map(int, input().split())) pr2 = list(map(int, input().split())) mass1 = [] minans = 10**20 for i in range(m): mass1.append((pr[i], t[i])) mass1.sort() mass1 = [(0, x)] + mass1 pr2 = [0] + pr2 t2 = [0] + t2 uk1 = len(mass1) - 1 uk2 = 0 maxw = 0 for uk1 in range(len(mass1) - 1, -1, -1): if (s < mass1[uk1][0]): continue while (uk2 < len(pr2) and mass1[uk1][0] + pr2[uk2] <= s): maxw = max(maxw, t2[uk2]) uk2 += 1 uk2 -= 1 minans = min(minans, (n - maxw) * mass1[uk1][1]) print(minans) ```
vfc_10362
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/734/C", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "20 3 2\n10 99\n2 4 3\n20 10 40\n4 15\n10 80\n", "output": "20\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "20 3 2\n10 99\n2 4 3\n200 100 400\n4 15\n100 800\n", "output": "200\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "10 3 3\n10 33\n1 7 6\n17 25 68\n2 9 10\n78 89 125\n", "output": "10\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "94 1 1\n26 324\n7\n236\n77\n5\n", "output": "119\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 4 5\n5 9\n1 2 1 1\n3 5 4 1\n1 1 1 1 3\n1 2 3 4 5\n", "output": "0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 4 2\n3 10\n2 1 1 1\n1 5 3 5\n1 1\n1 5\n", "output": "0\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
153
Solve the following coding problem using the programming language python: Polycarp takes part in a math show. He is given n tasks, each consists of k subtasks, numbered 1 through k. It takes him t_{j} minutes to solve the j-th subtask of any task. Thus, time required to solve a subtask depends only on its index, but not on the task itself. Polycarp can solve subtasks in any order. By solving subtask of arbitrary problem he earns one point. Thus, the number of points for task is equal to the number of solved subtasks in it. Moreover, if Polycarp completely solves the task (solves all k of its subtasks), he recieves one extra point. Thus, total number of points he recieves for the complete solution of the task is k + 1. Polycarp has M minutes of time. What is the maximum number of points he can earn? -----Input----- The first line contains three integer numbers n, k and M (1 ≤ n ≤ 45, 1 ≤ k ≤ 45, 0 ≤ M ≤ 2·10^9). The second line contains k integer numbers, values t_{j} (1 ≤ t_{j} ≤ 1000000), where t_{j} is the time in minutes required to solve j-th subtask of any task. -----Output----- Print the maximum amount of points Polycarp can earn in M minutes. -----Examples----- Input 3 4 11 1 2 3 4 Output 6 Input 5 5 10 1 2 4 8 16 Output 7 -----Note----- In the first example Polycarp can complete the first task and spend 1 + 2 + 3 + 4 = 10 minutes. He also has the time to solve one subtask of the second task in one minute. In the second example Polycarp can solve the first subtask of all five tasks and spend 5·1 = 5 minutes. Also he can solve the second subtasks of two tasks and spend 2·2 = 4 minutes. Thus, he earns 5 + 2 = 7 points in total. 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 = list(map(int, input().split())) l = list(map(int, input().split())) l.sort() s = sum(l) ans = 0 for i in range(n + 1): mi = m - s * i if mi < 0: break cnt = (k + 1) * i for j in range(k): x = min(mi // l[j], n - i) cnt += x mi -= l[j] * x ans = max(ans, cnt) print(ans) ```
vfc_10366
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/846/B", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 4 11\n1 2 3 4\n", "output": "6\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 5 10\n1 2 4 8 16\n", "output": "7\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
154
Solve the following coding problem using the programming language python: Recall that a binary search tree is a rooted binary tree, whose nodes each store a key and each have at most two distinguished subtrees, left and right. The key in each node must be greater than any key stored in the left subtree, and less than any key stored in the right subtree. The depth of a vertex is the number of edges on the simple path from the vertex to the root. In particular, the depth of the root is $0$. Let's call a binary search tree perfectly balanced if there doesn't exist a binary search tree with the same number of vertices that has a strictly smaller sum of depths of its vertices. Let's call a binary search tree with integer keys striped if both of the following conditions are satisfied for every vertex $v$: If $v$ has a left subtree whose root is $u$, then the parity of the key of $v$ is different from the parity of the key of $u$. If $v$ has a right subtree whose root is $w$, then the parity of the key of $v$ is the same as the parity of the key of $w$. You are given a single integer $n$. Find the number of perfectly balanced striped binary search trees with $n$ vertices that have distinct integer keys between $1$ and $n$, inclusive. Output this number modulo $998\,244\,353$. -----Input----- The only line contains a single integer $n$ ($1 \le n \le 10^6$), denoting the required number of vertices. -----Output----- Output the number of perfectly balanced striped binary search trees with $n$ vertices and distinct integer keys between $1$ and $n$, inclusive, modulo $998\,244\,353$. -----Examples----- Input 4 Output 1 Input 3 Output 0 -----Note----- In the first example, this is the only tree that satisfies the conditions: $\left. \begin{array}{l}{\text{perfectly balanced}} \\{\text{striped}} \\{\text{binary search tree}} \end{array} \right.$ In the second example, here are various trees that don't satisfy some condition: [Image] 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()) if N in [1, 2, 4, 5, 9, 10, 20, 21, 41, 42, 84, 85, 169, 170, 340, 341, 681, 682, 1364, 1365, 2729, 2730, 5460, 5461, 10921, 10922, 21844, 21845, 43689, 43690, 87380, 87381, 174761, 174762, 349524, 349525, 699049, 699050]: print(1) else: print(0) ```
vfc_10370
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1237/E", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n", "output": "0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "7\n", "output": "0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "8\n", "output": "0\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
155
Solve the following coding problem using the programming language python: You might have heard about the next game in Lara Croft series coming out this year. You also might have watched its trailer. Though you definitely missed the main idea about its plot, so let me lift the veil of secrecy. Lara is going to explore yet another dangerous dungeon. Game designers decided to use good old 2D environment. The dungeon can be represented as a rectangle matrix of n rows and m columns. Cell (x, y) is the cell in the x-th row in the y-th column. Lara can move between the neighbouring by side cells in all four directions. Moreover, she has even chosen the path for herself to avoid all the traps. She enters the dungeon in cell (1, 1), that is top left corner of the matrix. Then she goes down all the way to cell (n, 1) — the bottom left corner. Then she starts moving in the snake fashion — all the way to the right, one cell up, then to the left to the cell in 2-nd column, one cell up. She moves until she runs out of non-visited cells. n and m given are such that she always end up in cell (1, 2). Lara has already moved to a neighbouring cell k times. Can you determine her current position? -----Input----- The only line contains three integers n, m and k (2 ≤ n, m ≤ 10^9, n is always even, 0 ≤ k < n·m). Note that k doesn't fit into 32-bit integer type! -----Output----- Print the cell (the row and the column where the cell is situated) where Lara ends up after she moves k times. -----Examples----- Input 4 3 0 Output 1 1 Input 4 3 11 Output 1 2 Input 4 3 7 Output 3 2 -----Note----- Here is her path on matrix 4 by 3: [Image] The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python n, m, k = map(int, input().split()) ans = 0, 0 if k < n: ans = k + 1, 1 else: k -= n r = n - k // (m - 1) if r % 2: c = m - k % (m - 1) else: c = 2 + k % (m - 1) ans = r, c print(*ans) ```
vfc_10374
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/976/B", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4 3 0\n", "output": "1 1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 3 11\n", "output": "1 2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 3 7\n", "output": "3 2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1000000000 2 1999999999\n", "output": "1 2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1000000000 1000000000 999999999999999999\n", "output": "1 2\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
156
Solve the following coding problem using the programming language python: Today, Osama gave Fadi an integer $X$, and Fadi was wondering about the minimum possible value of $max(a, b)$ such that $LCM(a, b)$ equals $X$. Both $a$ and $b$ should be positive integers. $LCM(a, b)$ is the smallest positive integer that is divisible by both $a$ and $b$. For example, $LCM(6, 8) = 24$, $LCM(4, 12) = 12$, $LCM(2, 3) = 6$. Of course, Fadi immediately knew the answer. Can you be just like Fadi and find any such pair? -----Input----- The first and only line contains an integer $X$ ($1 \le X \le 10^{12}$). -----Output----- Print two positive integers, $a$ and $b$, such that the value of $max(a, b)$ is minimum possible and $LCM(a, b)$ equals $X$. If there are several possible such pairs, you can print any. -----Examples----- Input 2 Output 1 2 Input 6 Output 2 3 Input 4 Output 1 4 Input 1 Output 1 1 The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python import math x = int(input()) ans = 10**13 ab = [1, 1] for i in range(1, int(x**(1/2))+1): if x % i == 0: a = x//i b = i g = math.gcd(a, b) a *= g b *= g if ans > max(a, b): ans = max(a, b) ab = [a, b] print(ab[0], ab[1]) ```
vfc_10378
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1285/C", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n", "output": "1 2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "6\n", "output": "2 3\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
157
Solve the following coding problem using the programming language python: Nikolay has a lemons, b apples and c pears. He decided to cook a compote. According to the recipe the fruits should be in the ratio 1: 2: 4. It means that for each lemon in the compote should be exactly 2 apples and exactly 4 pears. You can't crumble up, break up or cut these fruits into pieces. These fruits — lemons, apples and pears — should be put in the compote as whole fruits. Your task is to determine the maximum total number of lemons, apples and pears from which Nikolay can cook the compote. It is possible that Nikolay can't use any fruits, in this case print 0. -----Input----- The first line contains the positive integer a (1 ≤ a ≤ 1000) — the number of lemons Nikolay has. The second line contains the positive integer b (1 ≤ b ≤ 1000) — the number of apples Nikolay has. The third line contains the positive integer c (1 ≤ c ≤ 1000) — the number of pears Nikolay has. -----Output----- Print the maximum total number of lemons, apples and pears from which Nikolay can cook the compote. -----Examples----- Input 2 5 7 Output 7 Input 4 7 13 Output 21 Input 2 3 2 Output 0 -----Note----- In the first example Nikolay can use 1 lemon, 2 apples and 4 pears, so the answer is 1 + 2 + 4 = 7. In the second example Nikolay can use 3 lemons, 6 apples and 12 pears, so the answer is 3 + 6 + 12 = 21. In the third example Nikolay don't have enough pears to cook any compote, so the answer is 0. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python n1 = int( input() ) n2 = int( input() ) n3 = int( input() ) print( min( n1 , n2 // 2 , n3 // 4 ) * 7 ) ```
vfc_10382
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/746/A", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n5\n7\n", "output": "7\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n7\n13\n", "output": "21\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n3\n2\n", "output": "0\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
158
Solve the following coding problem using the programming language python: Berland annual chess tournament is coming! Organizers have gathered 2·n chess players who should be divided into two teams with n people each. The first team is sponsored by BerOil and the second team is sponsored by BerMobile. Obviously, organizers should guarantee the win for the team of BerOil. Thus, organizers should divide all 2·n players into two teams with n people each in such a way that the first team always wins. Every chess player has its rating r_{i}. It is known that chess player with the greater rating always wins the player with the lower rating. If their ratings are equal then any of the players can win. After teams assignment there will come a drawing to form n pairs of opponents: in each pair there is a player from the first team and a player from the second team. Every chess player should be in exactly one pair. Every pair plays once. The drawing is totally random. Is it possible to divide all 2·n players into two teams with n people each so that the player from the first team in every pair wins regardless of the results of the drawing? -----Input----- The first line contains one integer n (1 ≤ n ≤ 100). The second line contains 2·n integers a_1, a_2, ... a_2n (1 ≤ a_{i} ≤ 1000). -----Output----- If it's possible to divide all 2·n players into two teams with n people each so that the player from the first team in every pair wins regardless of the results of the drawing, then print "YES". Otherwise print "NO". -----Examples----- Input 2 1 3 2 4 Output YES Input 1 3 3 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 = int(input()) z = list(map(int, input().split())) z.sort() if z[n - 1] < z[n]: print("YES") else: print("NO") ```
vfc_10386
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/845/A", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n1 3 2 4\n", "output": "YES\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n3 3\n", "output": "NO\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n1 1 1 1 2 2 3 3 3 3\n", "output": "NO\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n1 1 1 1 1 2 2 2 2 2\n", "output": "YES\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "10\n1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000\n", "output": "NO\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
159
Solve the following coding problem using the programming language python: You are given an array of n elements, you must make it a co-prime array in as few moves as possible. In each move you can insert any positive integral number you want not greater than 10^9 in any place in the array. An array is co-prime if any two adjacent numbers of it are co-prime. In the number theory, two integers a and b are said to be co-prime if the only positive integer that divides both of them is 1. -----Input----- The first line contains integer n (1 ≤ n ≤ 1000) — the number of elements in the given array. The second line contains n integers a_{i} (1 ≤ a_{i} ≤ 10^9) — the elements of the array a. -----Output----- Print integer k on the first line — the least number of elements needed to add to the array a to make it co-prime. The second line should contain n + k integers a_{j} — the elements of the array a after adding k elements to it. Note that the new array should be co-prime, so any two adjacent values should be co-prime. Also the new array should be got from the original array a by adding k elements to it. If there are multiple answers you can print any one of them. -----Example----- Input 3 2 7 28 Output 1 2 7 9 28 The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python import fractions n = int(input()) A = [int(x) for x in input().split()] B = [] for i in range(n-1): B.append(A[i]) if fractions.gcd(A[i], A[i+1]) != 1: B.append(1) B.append(A[-1]) print(len(B) - n) print(' '.join(map(str, B))) ```
vfc_10390
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/660/A", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n2 7 28\n", "output": "1\n2 7 1 28\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n1\n", "output": "0\n1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n548\n", "output": "0\n548\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n963837006\n", "output": "0\n963837006\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
161
Solve the following coding problem using the programming language python: Cat Furrier Transform is a popular algorithm among cat programmers to create longcats. As one of the greatest cat programmers ever exist, Neko wants to utilize this algorithm to create the perfect longcat. Assume that we have a cat with a number $x$. A perfect longcat is a cat with a number equal $2^m - 1$ for some non-negative integer $m$. For example, the numbers $0$, $1$, $3$, $7$, $15$ and so on are suitable for the perfect longcats. In the Cat Furrier Transform, the following operations can be performed on $x$: (Operation A): you select any non-negative integer $n$ and replace $x$ with $x \oplus (2^n - 1)$, with $\oplus$ being a bitwise XOR operator. (Operation B): replace $x$ with $x + 1$. The first applied operation must be of type A, the second of type B, the third of type A again, and so on. Formally, if we number operations from one in the order they are executed, then odd-numbered operations must be of type A and the even-numbered operations must be of type B. Neko wants to produce perfect longcats at industrial scale, thus for each cat Neko only wants to perform at most $40$ operations. Can you help Neko writing a transformation plan? Note that it is not required to minimize the number of operations. You just need to use no more than $40$ operations. -----Input----- The only line contains a single integer $x$ ($1 \le x \le 10^6$). -----Output----- The first line should contain a single integer $t$ ($0 \le t \le 40$) — the number of operations to apply. Then for each odd-numbered operation print the corresponding number $n_i$ in it. That is, print $\lceil \frac{t}{2} \rceil$ integers $n_i$ ($0 \le n_i \le 30$), denoting the replacement $x$ with $x \oplus (2^{n_i} - 1)$ in the corresponding step. If there are multiple possible answers, you can print any of them. It is possible to show, that there is at least one answer in the constraints of this problem. -----Examples----- Input 39 Output 4 5 3 Input 1 Output 0 Input 7 Output 0 -----Note----- In the first test, one of the transforms might be as follows: $39 \to 56 \to 57 \to 62 \to 63$. Or more precisely: Pick $n = 5$. $x$ is transformed into $39 \oplus 31$, or $56$. Increase $x$ by $1$, changing its value to $57$. Pick $n = 3$. $x$ is transformed into $57 \oplus 7$, or $62$. Increase $x$ by $1$, changing its value to $63 = 2^6 - 1$. In the second and third test, the number already satisfies the goal requirement. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python def main(): x = int(input()) n = x.bit_length() t = 0 ans = [] while True: if (x + 1) & (x) == 0: break if t & 1: x += 1 else: for i in range(n - 1, -1, -1): if not (1 << i) & x: ans.append(i + 1) x ^= (1 << (i + 1)) - 1 break t += 1 print(t) print(*ans) return 0 main() ```
vfc_10398
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1152/B", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "39\n", "output": "4\n5 3 ", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n", "output": "0\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
162
Solve the following coding problem using the programming language python: Luba thinks about watering her garden. The garden can be represented as a segment of length k. Luba has got n buckets, the i-th bucket allows her to water some continuous subsegment of garden of length exactly a_{i} each hour. Luba can't water any parts of the garden that were already watered, also she can't water the ground outside the garden. Luba has to choose one of the buckets in order to water the garden as fast as possible (as mentioned above, each hour she will water some continuous subsegment of length a_{i} if she chooses the i-th bucket). Help her to determine the minimum number of hours she has to spend watering the garden. It is guaranteed that Luba can always choose a bucket so it is possible water the garden. See the examples for better understanding. -----Input----- The first line of input contains two integer numbers n and k (1 ≤ n, k ≤ 100) — the number of buckets and the length of the garden, respectively. The second line of input contains n integer numbers a_{i} (1 ≤ a_{i} ≤ 100) — the length of the segment that can be watered by the i-th bucket in one hour. It is guaranteed that there is at least one bucket such that it is possible to water the garden in integer number of hours using only this bucket. -----Output----- Print one integer number — the minimum number of hours required to water the garden. -----Examples----- Input 3 6 2 3 5 Output 2 Input 6 7 1 2 3 4 5 6 Output 7 -----Note----- In the first test the best option is to choose the bucket that allows to water the segment of length 3. We can't choose the bucket that allows to water the segment of length 5 because then we can't water the whole garden. In the second test we can choose only the bucket that allows us to water the segment of length 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 = map(int, input().split()) a = list(map(int, input().split())) maxd = -1 for x in a: if k % x == 0: maxd = max(maxd, x) print(k // maxd) ```
vfc_10402
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/915/A", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 6\n2 3 5\n", "output": "2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "6 7\n1 2 3 4 5 6\n", "output": "7\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 97\n1 10 50 97 2\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 97\n1 10 50 100 2\n", "output": "97\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
163
Solve the following coding problem using the programming language python: On the way to Rio de Janeiro Ostap kills time playing with a grasshopper he took with him in a special box. Ostap builds a line of length n such that some cells of this line are empty and some contain obstacles. Then, he places his grasshopper to one of the empty cells and a small insect in another empty cell. The grasshopper wants to eat the insect. Ostap knows that grasshopper is able to jump to any empty cell that is exactly k cells away from the current (to the left or to the right). Note that it doesn't matter whether intermediate cells are empty or not as the grasshopper makes a jump over them. For example, if k = 1 the grasshopper can jump to a neighboring cell only, and if k = 2 the grasshopper can jump over a single cell. Your goal is to determine whether there is a sequence of jumps such that grasshopper will get from his initial position to the cell with an insect. -----Input----- The first line of the input contains two integers n and k (2 ≤ n ≤ 100, 1 ≤ k ≤ n - 1) — the number of cells in the line and the length of one grasshopper's jump. The second line contains a string of length n consisting of characters '.', '#', 'G' and 'T'. Character '.' means that the corresponding cell is empty, character '#' means that the corresponding cell contains an obstacle and grasshopper can't jump there. Character 'G' means that the grasshopper starts at this position and, finally, 'T' means that the target insect is located at this cell. It's guaranteed that characters 'G' and 'T' appear in this line exactly once. -----Output----- If there exists a sequence of jumps (each jump of length k), such that the grasshopper can get from his initial position to the cell with the insect, print "YES" (without quotes) in the only line of the input. Otherwise, print "NO" (without quotes). -----Examples----- Input 5 2 #G#T# Output YES Input 6 1 T....G Output YES Input 7 3 T..#..G Output NO Input 6 2 ..GT.. Output NO -----Note----- In the first sample, the grasshopper can make one jump to the right in order to get from cell 2 to cell 4. In the second sample, the grasshopper is only able to jump to neighboring cells but the way to the insect is free — he can get there by jumping left 5 times. In the third sample, the grasshopper can't make a single jump. In the fourth sample, the grasshopper can only jump to the cells with odd indices, thus he won't be able to reach the insect. 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 * from sys import * from queue import * from decimal import * n,k=(int(z) for z in input().split()) s=input() i=0 while i<len(s) and s[i] not in ["G","T"]: i+=1 i+=k while i<len(s) and s[i] not in ["G","T","#"]: i+=k if i>=len(s) or s[i]=="#": print("NO") else: print("YES") ```
vfc_10406
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/735/A", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5 2\n#G#T#\n", "output": "YES\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "6 1\nT....G\n", "output": "YES\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
164
Solve the following coding problem using the programming language python: It's a beautiful April day and Wallace is playing football with his friends. But his friends do not know that Wallace actually stayed home with Gromit and sent them his robotic self instead. Robo-Wallace has several advantages over the other guys. For example, he can hit the ball directly to the specified point. And yet, the notion of a giveaway is foreign to him. The combination of these features makes the Robo-Wallace the perfect footballer — as soon as the ball gets to him, he can just aim and hit the goal. He followed this tactics in the first half of the match, but he hit the goal rarely. The opposing team has a very good goalkeeper who catches most of the balls that fly directly into the goal. But Robo-Wallace is a quick thinker, he realized that he can cheat the goalkeeper. After all, they are playing in a football box with solid walls. Robo-Wallace can kick the ball to the other side, then the goalkeeper will not try to catch the ball. Then, if the ball bounces off the wall and flies into the goal, the goal will at last be scored. Your task is to help Robo-Wallace to detect a spot on the wall of the football box, to which the robot should kick the ball, so that the ball bounces once and only once off this wall and goes straight to the goal. In the first half of the match Robo-Wallace got a ball in the head and was severely hit. As a result, some of the schemes have been damaged. Because of the damage, Robo-Wallace can only aim to his right wall (Robo-Wallace is standing with his face to the opposing team's goal). The football box is rectangular. Let's introduce a two-dimensional coordinate system so that point (0, 0) lies in the lower left corner of the field, if you look at the box above. Robo-Wallace is playing for the team, whose goal is to the right. It is an improvised football field, so the gate of Robo-Wallace's rivals may be not in the middle of the left wall. [Image] In the given coordinate system you are given: y_1, y_2 — the y-coordinates of the side pillars of the goalposts of robo-Wallace's opponents; y_{w} — the y-coordinate of the wall to which Robo-Wallace is aiming; x_{b}, y_{b} — the coordinates of the ball's position when it is hit; r — the radius of the ball. A goal is scored when the center of the ball crosses the OY axis in the given coordinate system between (0, y_1) and (0, y_2). The ball moves along a straight line. The ball's hit on the wall is perfectly elastic (the ball does not shrink from the hit), the angle of incidence equals the angle of reflection. If the ball bounces off the wall not to the goal, that is, if it hits the other wall or the goal post, then the opposing team catches the ball and Robo-Wallace starts looking for miscalculation and gets dysfunctional. Such an outcome, if possible, should be avoided. We assume that the ball touches an object, if the distance from the center of the ball to the object is no greater than the ball radius r. -----Input----- The first and the single line contains integers y_1, y_2, y_{w}, x_{b}, y_{b}, r (1 ≤ y_1, y_2, y_{w}, x_{b}, y_{b} ≤ 10^6; y_1 < y_2 < y_{w}; y_{b} + r < y_{w}; 2·r < y_2 - y_1). It is guaranteed that the ball is positioned correctly in the field, doesn't cross any wall, doesn't touch the wall that Robo-Wallace is aiming at. The goal posts can't be located in the field corners. -----Output----- If Robo-Wallace can't score a goal in the described manner, print "-1" (without the quotes). Otherwise, print a single number x_{w} — the abscissa of his point of aiming. If there are multiple points of aiming, print the abscissa of any of them. When checking the correctness of the answer, all comparisons are made with the permissible absolute error, equal to 10^{ - 8}. It is recommended to print as many characters after the decimal point as possible. -----Examples----- Input 4 10 13 10 3 1 Output 4.3750000000 Input 1 4 6 2 2 1 Output -1 Input 3 10 15 17 9 2 Output 11.3333333333 -----Note----- Note that in the first and third samples other correct values of abscissa x_{w} are also possible. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python y1, y2, w, x, y, r = map(int, input().strip().split()) w -= r y1 = 2 * w - y1 - y - r y2 = 2 * w - y2 - y if x * x * (y2 - y1) * (y2 - y1) <= (y1 * y1 + x * x) * r * r: print(-1) else: print(f"{x * (y1 + y - w) / y1:.10f}") ```
vfc_10410
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/248/C", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4 10 13 10 3 1\n", "output": "4.3750000000\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 4 6 2 2 1\n", "output": "-1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 10 15 17 9 2\n", "output": "11.3333333333\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 9 30 3 3 1\n", "output": "-1\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
165
Solve the following coding problem using the programming language python: Vasiliy spent his vacation in a sanatorium, came back and found that he completely forgot details of his vacation! Every day there was a breakfast, a dinner and a supper in a dining room of the sanatorium (of course, in this order). The only thing that Vasiliy has now is a card from the dining room contaning notes how many times he had a breakfast, a dinner and a supper (thus, the card contains three integers). Vasiliy could sometimes have missed some meal, for example, he could have had a breakfast and a supper, but a dinner, or, probably, at some days he haven't been at the dining room at all. Vasiliy doesn't remember what was the time of the day when he arrived to sanatorium (before breakfast, before dinner, before supper or after supper), and the time when he left it (before breakfast, before dinner, before supper or after supper). So he considers any of these options. After Vasiliy arrived to the sanatorium, he was there all the time until he left. Please note, that it's possible that Vasiliy left the sanatorium on the same day he arrived. According to the notes in the card, help Vasiliy determine the minimum number of meals in the dining room that he could have missed. We shouldn't count as missed meals on the arrival day before Vasiliy's arrival and meals on the departure day after he left. -----Input----- The only line contains three integers b, d and s (0 ≤ b, d, s ≤ 10^18, b + d + s ≥ 1) — the number of breakfasts, dinners and suppers which Vasiliy had during his vacation in the sanatorium. -----Output----- Print single integer — the minimum possible number of meals which Vasiliy could have missed during his vacation. -----Examples----- Input 3 2 1 Output 1 Input 1 0 0 Output 0 Input 1 1 1 Output 0 Input 1000000000000000000 0 1000000000000000000 Output 999999999999999999 -----Note----- In the first sample, Vasiliy could have missed one supper, for example, in case he have arrived before breakfast, have been in the sanatorium for two days (including the day of arrival) and then have left after breakfast on the third day. In the second sample, Vasiliy could have arrived before breakfast, have had it, and immediately have left the sanatorium, not missing any meal. In the third sample, Vasiliy could have been in the sanatorium for one day, not missing any meal. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python a = list(map(int, input().split())) m = max(a) ans = 0 for i in range(3): if a[i] < m - 1: ans += (m - 1) - a[i] a[i] = m - 1 print(ans) ```
vfc_10414
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/732/C", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 2 1\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 0 0\n", "output": "0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 1 1\n", "output": "0\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
166
Solve the following coding problem using the programming language python: There is a matrix A of size x × y filled with integers. For every $i \in [ 1 . . x ]$, $j \in [ 1 . . y ]$ A_{i}, j = y(i - 1) + j. Obviously, every integer from [1..xy] occurs exactly once in this matrix. You have traversed some path in this matrix. Your path can be described as a sequence of visited cells a_1, a_2, ..., a_{n} denoting that you started in the cell containing the number a_1, then moved to the cell with the number a_2, and so on. From the cell located in i-th line and j-th column (we denote this cell as (i, j)) you can move into one of the following cells: (i + 1, j) — only if i < x; (i, j + 1) — only if j < y; (i - 1, j) — only if i > 1; (i, j - 1) — only if j > 1. Notice that making a move requires you to go to an adjacent cell. It is not allowed to stay in the same cell. You don't know x and y exactly, but you have to find any possible values for these numbers such that you could start in the cell containing the integer a_1, then move to the cell containing a_2 (in one step), then move to the cell containing a_3 (also in one step) and so on. Can you choose x and y so that they don't contradict with your sequence of moves? -----Input----- The first line contains one integer number n (1 ≤ n ≤ 200000) — the number of cells you visited on your path (if some cell is visited twice, then it's listed twice). The second line contains n integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10^9) — the integers in the cells on your path. -----Output----- If all possible values of x and y such that 1 ≤ x, y ≤ 10^9 contradict with the information about your path, print NO. Otherwise, print YES in the first line, and in the second line print the values x and y such that your path was possible with such number of lines and columns in the matrix. Remember that they must be positive integers not exceeding 10^9. -----Examples----- Input 8 1 2 3 6 9 8 5 2 Output YES 3 3 Input 6 1 2 1 2 5 3 Output NO Input 2 1 10 Output YES 4 9 -----Note----- The matrix and the path on it in the first test looks like this: [Image] Also there exist multiple correct answers for both the first and the third examples. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python MAXN = 1000000000 n = int(input()) a = list(map(int, input().split())) def solve1(): for i in range(n-1): if abs(a[i]-a[i+1]) != 1: return False print("YES\n%d %d" % (MAXN, 1)) return True def solve2(): w = -1 for i in range(n-1): d = abs(a[i]-a[i+1]) if d != 1: if w == -1: w = d elif w != d: return False if w <= 0: return False for i in range(n-1): if abs(a[i]-a[i+1]) == 1 and (a[i]-1)//w != (a[i+1]-1)//w: return False print("YES\n%d %d" % (MAXN, w)) return True if solve1(): pass elif solve2(): pass else: print("NO") ```
vfc_10418
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/954/C", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "8\n1 2 3 6 9 8 5 2\n", "output": "YES\n1000000000 3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "6\n1 2 1 2 5 3\n", "output": "NO\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n1 10\n", "output": "YES\n1000000000 9\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n1 2 2\n", "output": "NO\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
167
Solve the following coding problem using the programming language python: You are given two strings a and b. You have to remove the minimum possible number of consecutive (standing one after another) characters from string b in such a way that it becomes a subsequence of string a. It can happen that you will not need to remove any characters at all, or maybe you will have to remove all of the characters from b and make it empty. Subsequence of string s is any such string that can be obtained by erasing zero or more characters (not necessarily consecutive) from string s. -----Input----- The first line contains string a, and the second line — string b. Both of these strings are nonempty and consist of lowercase letters of English alphabet. The length of each string is no bigger than 10^5 characters. -----Output----- On the first line output a subsequence of string a, obtained from b by erasing the minimum number of consecutive characters. If the answer consists of zero characters, output «-» (a minus sign). -----Examples----- Input hi bob Output - Input abca accepted Output ac Input abacaba abcdcba Output abcba -----Note----- In the first example strings a and b don't share any symbols, so the longest string that you can get is empty. In the second example ac is a subsequence of a, and at the same time you can obtain it by erasing consecutive symbols cepted from string b. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python def get_substr_ends(haystack, needle): ans = [-1] index = 0 for char in needle: while index < len(haystack) and char != haystack[index]: index += 1 ans.append(index) if index < len(haystack): index += 1 return ans haystack = input() needle = input() pref = get_substr_ends(haystack, needle) suff = get_substr_ends(haystack[::-1], needle[::-1]) pref_index = 0 suff_len = 0 while suff_len < len(suff) and suff[suff_len] < len(haystack): suff_len += 1 suff_len -= 1 best_str = needle[len(needle) - suff_len:] if len(best_str) == len(needle): print(needle) return for pref_len in range(1, len(pref)): while suff_len >= 0 and suff[suff_len] + pref[pref_len] + 2 > len(haystack): suff_len -= 1 ans = pref_len + suff_len if ans > len(best_str) and suff_len >= 0: best_str = needle[:pref_len] + needle[len(needle) - suff_len:] print(best_str if best_str else '-') ```
vfc_10422
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/762/C", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "hi\nbob\n", "output": "-\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "abca\naccepted\n", "output": "ac\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "abacaba\nabcdcba\n", "output": "abcba\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "lo\neuhaqdhhzlnkmqnakgwzuhurqlpmdm\n", "output": "-\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "aaeojkdyuilpdvyewjfrftkpcobhcumwlaoiocbfdtvjkhgda\nmlmarpivirqbxcyhyerjoxlslyfzftrylpjyouypvk\n", "output": "ouypvk\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "npnkmawey\nareakefvowledfriyjejqnnaeqheoh\n", "output": "a\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
168
Solve the following coding problem using the programming language python: Vasya has a pile, that consists of some number of stones. $n$ times he either took one stone from the pile or added one stone to the pile. The pile was non-empty before each operation of taking one stone from the pile. You are given $n$ operations which Vasya has made. Find the minimal possible number of stones that can be in the pile after making these operations. -----Input----- The first line contains one positive integer $n$ — the number of operations, that have been made by Vasya ($1 \leq n \leq 100$). The next line contains the string $s$, consisting of $n$ symbols, equal to "-" (without quotes) or "+" (without quotes). If Vasya took the stone on $i$-th operation, $s_i$ is equal to "-" (without quotes), if added, $s_i$ is equal to "+" (without quotes). -----Output----- Print one integer — the minimal possible number of stones that can be in the pile after these $n$ operations. -----Examples----- Input 3 --- Output 0 Input 4 ++++ Output 4 Input 2 -+ Output 1 Input 5 ++-++ Output 3 -----Note----- In the first test, if Vasya had $3$ stones in the pile at the beginning, after making operations the number of stones will be equal to $0$. It is impossible to have less number of piles, so the answer is $0$. Please notice, that the number of stones at the beginning can't be less, than $3$, because in this case, Vasya won't be able to take a stone on some operation (the pile will be empty). In the second test, if Vasya had $0$ stones in the pile at the beginning, after making operations the number of stones will be equal to $4$. It is impossible to have less number of piles because after making $4$ operations the number of stones in the pile increases on $4$ stones. So, the answer is $4$. In the third test, if Vasya had $1$ stone in the pile at the beginning, after making operations the number of stones will be equal to $1$. It can be proved, that it is impossible to have less number of stones after making the operations. In the fourth test, if Vasya had $0$ stones in the pile at the beginning, after making operations the number of stones will be equal to $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()) s = input() b = 0 for i in s: if i == '+': b += 1 else: b -= 1 b = max(b, 0) print(b) ```
vfc_10426
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1159/A", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n---\n", "output": "0", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n++++\n", "output": "4", "type": "stdin_stdout" } ] }
apps
verifiable_code
169
Solve the following coding problem using the programming language python: Kolya Gerasimov loves kefir very much. He lives in year 1984 and knows all the details of buying this delicious drink. One day, as you probably know, he found himself in year 2084, and buying kefir there is much more complicated. Kolya is hungry, so he went to the nearest milk shop. In 2084 you may buy kefir in a plastic liter bottle, that costs a rubles, or in glass liter bottle, that costs b rubles. Also, you may return empty glass bottle and get c (c < b) rubles back, but you cannot return plastic bottles. Kolya has n rubles and he is really hungry, so he wants to drink as much kefir as possible. There were no plastic bottles in his 1984, so Kolya doesn't know how to act optimally and asks for your help. -----Input----- First line of the input contains a single integer n (1 ≤ n ≤ 10^18) — the number of rubles Kolya has at the beginning. Then follow three lines containing integers a, b and c (1 ≤ a ≤ 10^18, 1 ≤ c < b ≤ 10^18) — the cost of one plastic liter bottle, the cost of one glass liter bottle and the money one can get back by returning an empty glass bottle, respectively. -----Output----- Print the only integer — maximum number of liters of kefir, that Kolya can drink. -----Examples----- Input 10 11 9 8 Output 2 Input 10 5 6 1 Output 2 -----Note----- In the first sample, Kolya can buy one glass bottle, then return it and buy one more glass bottle. Thus he will drink 2 liters of kefir. In the second sample, Kolya can buy two plastic bottle and get two liters of kefir, or he can buy one liter glass bottle, then return it and buy one plastic bottle. In both cases he will drink two liters of kefir. 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=int(input()) b=int(input()) c=int(input()) r=n//a if n > c: r=max(r,(r-b+c)//a+1,(n-c)//(b-c)+((n-c)%(b-c)+c)//a) print(r) ```
vfc_10430
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/625/A", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "10\n11\n9\n8\n", "output": "2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "10\n5\n6\n1\n", "output": "2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n2\n2\n1\n", "output": "1\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
170
Solve the following coding problem using the programming language python: Two bored soldiers are playing card war. Their card deck consists of exactly n cards, numbered from 1 to n, all values are different. They divide cards between them in some manner, it's possible that they have different number of cards. Then they play a "war"-like card game. The rules are following. On each turn a fight happens. Each of them picks card from the top of his stack and puts on the table. The one whose card value is bigger wins this fight and takes both cards from the table to the bottom of his stack. More precisely, he first takes his opponent's card and puts to the bottom of his stack, and then he puts his card to the bottom of his stack. If after some turn one of the player's stack becomes empty, he loses and the other one wins. You have to calculate how many fights will happen and who will win the game, or state that game won't end. -----Input----- First line contains a single integer n (2 ≤ n ≤ 10), the number of cards. Second line contains integer k_1 (1 ≤ k_1 ≤ n - 1), the number of the first soldier's cards. Then follow k_1 integers that are the values on the first soldier's cards, from top to bottom of his stack. Third line contains integer k_2 (k_1 + k_2 = n), the number of the second soldier's cards. Then follow k_2 integers that are the values on the second soldier's cards, from top to bottom of his stack. All card values are different. -----Output----- If somebody wins in this game, print 2 integers where the first one stands for the number of fights before end of game and the second one is 1 or 2 showing which player has won. If the game won't end and will continue forever output - 1. -----Examples----- Input 4 2 1 3 2 4 2 Output 6 2 Input 3 1 2 2 1 3 Output -1 -----Note----- First sample: [Image] Second sample: [Image] 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()) k1 = list(map(int, input().split()[1:])) k2 = list(map(int, input().split()[1:])) i = 0 while True: if len(k1) == 0 or len(k2) == 0: break if i > 10000: break if k1[0] > k2[0]: k1 = k1[1:] + k2[0:1] + k1[0:1] k2 = k2[1:] else: k2 = k2[1:] + k1[0:1] + k2[0:1] k1 = k1[1:] i += 1 if i > 10000: print(-1) else: winner = 1 if len(k1) == 0: winner = 2 print(i, winner) ```
vfc_10434
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/546/C", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n2 1 3\n2 4 2\n", "output": "6 2", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n1 2\n2 1 3\n", "output": "-1", "type": "stdin_stdout" } ] }
apps
verifiable_code
171
Solve the following coding problem using the programming language python: You have probably registered on Internet sites many times. And each time you should enter your invented password. Usually the registration form automatically checks the password's crypt resistance. If the user's password isn't complex enough, a message is displayed. Today your task is to implement such an automatic check. Web-developers of the company Q assume that a password is complex enough, if it meets all of the following conditions: the password length is at least 5 characters; the password contains at least one large English letter; the password contains at least one small English letter; the password contains at least one digit. You are given a password. Please implement the automatic check of its complexity for company Q. -----Input----- The first line contains a non-empty sequence of characters (at most 100 characters). Each character is either a large English letter, or a small English letter, or a digit, or one of characters: "!", "?", ".", ",", "_". -----Output----- If the password is complex enough, print message "Correct" (without the quotes), otherwise print message "Too weak" (without the quotes). -----Examples----- Input abacaba Output Too weak Input X12345 Output Too weak Input CONTEST_is_STARTED!!11 Output Correct The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python s = input().strip() flag1 = len(s) >= 5 d1 = 'qwertyuiopasdfghjklzxcvbnm' d2 = 'QWERTYUIOPASDFGHJKLZXCVBNM' d3 = '123456789' flag2 = False flag3 = False flag4 = False for i in d1: if i in s: flag2 = True for i in d2: if i in s: flag3 = True for i in d3: if i in s: flag4 = True if(flag1 and flag2 and flag3 and flag4): print("Correct") else: print("Too weak") ```
vfc_10438
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/411/A", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "abacaba\n", "output": "Too weak\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "X12345\n", "output": "Too weak\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
172
Solve the following coding problem using the programming language python: In Berland each high school student is characterized by academic performance — integer value between 1 and 5. In high school 0xFF there are two groups of pupils: the group A and the group B. Each group consists of exactly n students. An academic performance of each student is known — integer value between 1 and 5. The school director wants to redistribute students between groups so that each of the two groups has the same number of students whose academic performance is equal to 1, the same number of students whose academic performance is 2 and so on. In other words, the purpose of the school director is to change the composition of groups, so that for each value of academic performance the numbers of students in both groups are equal. To achieve this, there is a plan to produce a series of exchanges of students between groups. During the single exchange the director selects one student from the class A and one student of class B. After that, they both change their groups. Print the least number of exchanges, in order to achieve the desired equal numbers of students for each academic performance. -----Input----- The first line of the input contains integer number n (1 ≤ n ≤ 100) — number of students in both groups. The second line contains sequence of integer numbers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 5), where a_{i} is academic performance of the i-th student of the group A. The third line contains sequence of integer numbers b_1, b_2, ..., b_{n} (1 ≤ b_{i} ≤ 5), where b_{i} is academic performance of the i-th student of the group B. -----Output----- Print the required minimum number of exchanges or -1, if the desired distribution of students can not be obtained. -----Examples----- Input 4 5 4 4 4 5 5 4 5 Output 1 Input 6 1 1 1 1 1 1 5 5 5 5 5 5 Output 3 Input 1 5 3 Output -1 Input 9 3 2 5 5 2 3 3 3 2 4 1 4 1 1 2 4 4 1 Output 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()) A = list(map(int,input().split())) B = list(map(int,input().split())) a = [0] * 5 b = [0] * 5 for j in range(n): a[A[j]-1] += 1 b[B[j]-1] +=1 per = 0 for j in range(5): if (a[j] + b[j]) % 2 == 1: per = 1 break if per == 1: print(-1) else: ans = 0 for j in range(5): if a[j] > b[j]: ans += (a[j] - b[j])//2 print(ans) ```
vfc_10442
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/779/A", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n5 4 4 4\n5 5 4 5\n", "output": "1\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
173
Solve the following coding problem using the programming language python: Imagine a city with n horizontal streets crossing m vertical streets, forming an (n - 1) × (m - 1) grid. In order to increase the traffic flow, mayor of the city has decided to make each street one way. This means in each horizontal street, the traffic moves only from west to east or only from east to west. Also, traffic moves only from north to south or only from south to north in each vertical street. It is possible to enter a horizontal street from a vertical street, or vice versa, at their intersection. [Image] The mayor has received some street direction patterns. Your task is to check whether it is possible to reach any junction from any other junction in the proposed street direction pattern. -----Input----- The first line of input contains two integers n and m, (2 ≤ n, m ≤ 20), denoting the number of horizontal streets and the number of vertical streets. The second line contains a string of length n, made of characters '<' and '>', denoting direction of each horizontal street. If the i-th character is equal to '<', the street is directed from east to west otherwise, the street is directed from west to east. Streets are listed in order from north to south. The third line contains a string of length m, made of characters '^' and 'v', denoting direction of each vertical street. If the i-th character is equal to '^', the street is directed from south to north, otherwise the street is directed from north to south. Streets are listed in order from west to east. -----Output----- If the given pattern meets the mayor's criteria, print a single line containing "YES", otherwise print a single line containing "NO". -----Examples----- Input 3 3 ><> v^v Output NO Input 4 6 <><> v^v^v^ Output YES -----Note----- The figure above shows street directions in the second sample test case. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python a, b = list(map(int, input().split(' '))) hor = input() ver = input() if (hor[0], ver[0]) == ('>', 'v') or (hor[0], ver[-1]) == ('<', 'v'): print("NO") elif (hor[-1], ver[0]) == ('>', '^') or (hor[-1], ver[-1]) == ('<', '^'): print("NO") else: print("YES") ```
vfc_10446
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/475/B", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 3\n><>\nv^v\n", "output": "NO\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 6\n<><>\nv^v^v^\n", "output": "YES\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 2\n<>\nv^\n", "output": "YES\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 2\n>>\n^v\n", "output": "NO\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 3\n>><\n^^v\n", "output": "YES\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 4\n>><\n^v^v\n", "output": "YES\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
174
Solve the following coding problem using the programming language python: Implication is a function of two logical arguments, its value is false if and only if the value of the first argument is true and the value of the second argument is false. Implication is written by using character '$\rightarrow$', and the arguments and the result of the implication are written as '0' (false) and '1' (true). According to the definition of the implication: $0 \rightarrow 0 = 1$ $0 \rightarrow 1 = 1$ $1 \rightarrow 0 = 0$ $1 \rightarrow 1 = 1$ When a logical expression contains multiple implications, then when there are no brackets, it will be calculated from left to fight. For example, $0 \rightarrow 0 \rightarrow 0 =(0 \rightarrow 0) \rightarrow 0 = 1 \rightarrow 0 = 0$. When there are brackets, we first calculate the expression in brackets. For example, $0 \rightarrow(0 \rightarrow 0) = 0 \rightarrow 1 = 1$. For the given logical expression $a_{1} \rightarrow a_{2} \rightarrow a_{3} \rightarrow \cdots \cdots a_{n}$ determine if it is possible to place there brackets so that the value of a logical expression is false. If it is possible, your task is to find such an arrangement of brackets. -----Input----- The first line contains integer n (1 ≤ n ≤ 100 000) — the number of arguments in a logical expression. The second line contains n numbers a_1, a_2, ..., a_{n} ($a_{i} \in \{0,1 \}$), which means the values of arguments in the expression in the order they occur. -----Output----- Print "NO" (without the quotes), if it is impossible to place brackets in the expression so that its value was equal to 0. Otherwise, print "YES" in the first line and the logical expression with the required arrangement of brackets in the second line. The expression should only contain characters '0', '1', '-' (character with ASCII code 45), '>' (character with ASCII code 62), '(' and ')'. Characters '-' and '>' can occur in an expression only paired like that: ("->") and represent implication. The total number of logical arguments (i.e. digits '0' and '1') in the expression must be equal to n. The order in which the digits follow in the expression from left to right must coincide with a_1, a_2, ..., a_{n}. The expression should be correct. More formally, a correct expression is determined as follows: Expressions "0", "1" (without the quotes) are correct. If v_1, v_2 are correct, then v_1->v_2 is a correct expression. If v is a correct expression, then (v) is a correct expression. The total number of characters in the resulting expression mustn't exceed 10^6. If there are multiple possible answers, you are allowed to print any of them. -----Examples----- Input 4 0 1 1 0 Output YES (((0)->1)->(1->0)) Input 2 1 1 Output NO Input 1 0 Output YES 0 The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python x = int(input()) seq = list(map(int, input().split(' '))) if seq == [0]: print("YES") print(0) elif seq == [0, 0]: print("NO") elif seq == [1, 0]: print("YES") print('1->0') elif seq == [0, 0, 0]: print("YES") print("(0->0)->0") elif seq == [1, 0, 0]: print("NO") elif seq[x-1] == 1: print("NO") #ENDS IN 1 elif seq[x-2] == 1: print("YES") print('->'.join([str(x) for x in seq])) #ENDS IN 10 elif seq == [1] * (x-2) + [0, 0]: print("NO") #000 BELOW elif seq[x-3] == 0: a = ('->'.join([str(x) for x in seq][0:x-3])) print("YES") print(a + '->(0->0)->0') #100 else: last = 0 for i in range(x-1): if seq[i] == 0 and seq[i+1] == 1: last = i seq[last] = '(0' seq[last+1] = '(1' seq[x-2] = '0))' print("YES") print('->'.join([str(x) for x in seq])) ```
vfc_10450
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/550/E", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n0 1 1 0\n", "output": "YES\n0->1->1->0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n1 1\n", "output": "NO\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
175
Solve the following coding problem using the programming language python: You have two variables a and b. Consider the following sequence of actions performed with these variables: If a = 0 or b = 0, end the process. Otherwise, go to step 2; If a ≥ 2·b, then set the value of a to a - 2·b, and repeat step 1. Otherwise, go to step 3; If b ≥ 2·a, then set the value of b to b - 2·a, and repeat step 1. Otherwise, end the process. Initially the values of a and b are positive integers, and so the process will be finite. You have to determine the values of a and b after the process ends. -----Input----- The only line of the input contains two integers n and m (1 ≤ n, m ≤ 10^18). n is the initial value of variable a, and m is the initial value of variable b. -----Output----- Print two integers — the values of a and b after the end of the process. -----Examples----- Input 12 5 Output 0 1 Input 31 12 Output 7 12 -----Note----- Explanations to the samples: a = 12, b = 5 $\rightarrow$ a = 2, b = 5 $\rightarrow$ a = 2, b = 1 $\rightarrow$ a = 0, b = 1; a = 31, b = 12 $\rightarrow$ a = 7, b = 12. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python a, b = [int(v) for v in input().split()] while a > 0 and b > 0: if a >= 2 * b: a %= 2 * b elif b >= 2 * a: b %= 2 * a else: break print(a, b) ```
vfc_10454
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/946/B", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "12 5\n", "output": "0 1\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
176
Solve the following coding problem using the programming language python: Find the number of k-divisible numbers on the segment [a, b]. In other words you need to find the number of such integer values x that a ≤ x ≤ b and x is divisible by k. -----Input----- The only line contains three space-separated integers k, a and b (1 ≤ k ≤ 10^18; - 10^18 ≤ a ≤ b ≤ 10^18). -----Output----- Print the required number. -----Examples----- Input 1 1 10 Output 10 Input 2 -4 4 Output 5 The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python s=input() ast=[int(i) for i in s.split(' ')] k,a,b=ast[0],ast[1],ast[2] s1=(a-1)//k s2=b//k print(s2-s1) ```
vfc_10458
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/597/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": "2 -4 4\n", "output": "5\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 1 1\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 0 0\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 0 1\n", "output": "2\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
177
Solve the following coding problem using the programming language python: Let's write all the positive integer numbers one after another from $1$ without any delimiters (i.e. as a single string). It will be the infinite sequence starting with 123456789101112131415161718192021222324252627282930313233343536... Your task is to print the $k$-th digit of this sequence. -----Input----- The first and only line contains integer $k$ ($1 \le k \le 10000$) — the position to process ($1$-based index). -----Output----- Print the $k$-th digit of the resulting infinite sequence. -----Examples----- Input 7 Output 7 Input 21 Output 5 The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python a = int(input()) s = "" for i in range(1, a+1): s += str(i) print(s[a-1]) ```
vfc_10462
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1177/A", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "7\n", "output": "7\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "21\n", "output": "5\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n", "output": "2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n", "output": "3\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
178
Solve the following coding problem using the programming language python: A telephone number is a sequence of exactly $11$ digits such that its first digit is 8. Vasya and Petya are playing a game. Initially they have a string $s$ of length $n$ ($n$ is odd) consisting of digits. Vasya makes the first move, then players alternate turns. In one move the player must choose a character and erase it from the current string. For example, if the current string 1121, after the player's move it may be 112, 111 or 121. The game ends when the length of string $s$ becomes 11. If the resulting string is a telephone number, Vasya wins, otherwise Petya wins. You have to determine if Vasya has a winning strategy (that is, if Vasya can win the game no matter which characters Petya chooses during his moves). -----Input----- The first line contains one integer $n$ ($13 \le n < 10^5$, $n$ is odd) — the length of string $s$. The second line contains the string $s$ ($|s| = n$) consisting only of decimal digits. -----Output----- If Vasya has a strategy that guarantees him victory, print YES. Otherwise print NO. -----Examples----- Input 13 8380011223344 Output YES Input 15 807345619350641 Output NO -----Note----- In the first example Vasya needs to erase the second character. Then Petya cannot erase a character from the remaining string 880011223344 so that it does not become a telephone number. In the second example after Vasya's turn Petya can erase one character character 8. The resulting string can't be a telephone number, because there is no digit 8 at all. 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(input()), input() cnt = (n - 11) // 2 cnt_8 = len(s[:n - 10].split('8')) - 1 if (cnt >= cnt_8): print ("NO") else: print ("YES") ```
vfc_10466
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1155/B", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "13\n8380011223344\n", "output": "YES\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "15\n807345619350641\n", "output": "NO\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "19\n8181818181111111111\n", "output": "YES\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "29\n88811188118181818118111111111\n", "output": "NO\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "15\n980848088815548\n", "output": "NO\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "13\n9999999998888\n", "output": "NO\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
179
Solve the following coding problem using the programming language python: Andrey thinks he is truly a successful developer, but in reality he didn't know about the binary search algorithm until recently. After reading some literature Andrey understood that this algorithm allows to quickly find a certain number $x$ in an array. For an array $a$ indexed from zero, and an integer $x$ the pseudocode of the algorithm is as follows: BinarySearch(a, x) left = 0 right = a.size() while left < right middle = (left + right) / 2 if a[middle] <= x then left = middle + 1 else right = middle if left > 0 and a[left - 1] == x then return true else return false Note that the elements of the array are indexed from zero, and the division is done in integers (rounding down). Andrey read that the algorithm only works if the array is sorted. However, he found this statement untrue, because there certainly exist unsorted arrays for which the algorithm find $x$! Andrey wants to write a letter to the book authors, but before doing that he must consider the permutations of size $n$ such that the algorithm finds $x$ in them. A permutation of size $n$ is an array consisting of $n$ distinct integers between $1$ and $n$ in arbitrary order. Help Andrey and find the number of permutations of size $n$ which contain $x$ at position $pos$ and for which the given implementation of the binary search algorithm finds $x$ (returns true). As the result may be extremely large, print the remainder of its division by $10^9+7$. -----Input----- The only line of input contains integers $n$, $x$ and $pos$ ($1 \le x \le n \le 1000$, $0 \le pos \le n - 1$) — the required length of the permutation, the number to search, and the required position of that number, respectively. -----Output----- Print a single number — the remainder of the division of the number of valid permutations by $10^9+7$. -----Examples----- Input 4 1 2 Output 6 Input 123 42 24 Output 824071958 -----Note----- All possible permutations in the first test case: $(2, 3, 1, 4)$, $(2, 4, 1, 3)$, $(3, 2, 1, 4)$, $(3, 4, 1, 2)$, $(4, 2, 1, 3)$, $(4, 3, 1, 2)$. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python MOD = 1000000007 def f(n, cnt): """ n! / (n - cnt)! """ ans = 1 for _ in range(cnt): ans = (ans * n) % MOD n -= 1 return ans def main(): n, x, pos = list(map(int, input().split())) chk1 = 0 chk_r = 0 left = 0 right = n while left < right: middle = (left + right) // 2 if middle <= pos: if middle < pos: chk1 += 1 left = middle + 1 else: chk_r += 1 right = middle if chk1 > x - 1 or chk_r > n - x: print(0) else: # (x - 1)! / (x - 1 - chk1)! * (n - x)! / (n - x - chk_r)! * (n - chk1 - chk_r - 1)! rest = n - chk1 - chk_r - 1 print(f(x - 1, chk1) * f(n - x, chk_r) * f(rest, rest) % MOD) main() ```
vfc_10470
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1436/C", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4 1 2\n", "output": "6\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "123 42 24\n", "output": "824071958\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
180
Solve the following coding problem using the programming language python: Andrey received a postcard from Irina. It contained only the words "Hello, Andrey!", and a strange string consisting of lowercase Latin letters, snowflakes and candy canes. Andrey thought that this string is an encrypted message, and decided to decrypt it. Andrey noticed that snowflakes and candy canes always stand after the letters, so he supposed that the message was encrypted as follows. Candy cane means that the letter before it can be removed, or can be left. A snowflake means that the letter before it can be removed, left, or repeated several times. For example, consider the following string: [Image] This string can encode the message «happynewyear». For this, candy canes and snowflakes should be used as follows: candy cane 1: remove the letter w, snowflake 1: repeat the letter p twice, candy cane 2: leave the letter n, snowflake 2: remove the letter w, snowflake 3: leave the letter e. [Image] Please note that the same string can encode different messages. For example, the string above can encode «hayewyar», «happpppynewwwwwyear», and other messages. Andrey knows that messages from Irina usually have a length of $k$ letters. Help him to find out if a given string can encode a message of $k$ letters, and if so, give an example of such a message. -----Input----- The first line contains the string received in the postcard. The string consists only of lowercase Latin letters, as well as the characters «*» and «?», meaning snowflake and candy cone, respectively. These characters can only appear immediately after the letter. The length of the string does not exceed $200$. The second line contains an integer number $k$ ($1 \leq k \leq 200$), the required message length. -----Output----- Print any message of length $k$ that the given string can encode, or «Impossible» if such a message does not exist. -----Examples----- Input hw?ap*yn?eww*ye*ar 12 Output happynewyear Input ab?a 2 Output aa Input ab?a 3 Output aba Input ababb 5 Output ababb Input ab?a 1 Output Impossible The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python s = input() k = int(input()) c = 0 p = 0 has_star = False for i in range(len(s)): if s[i] in ['*', '?']: if s[i] == '*': has_star = True c -= 1 else: p += 1 c += 1 if k < c: print("Impossible") elif (not has_star) and (k > p): print("Impossible") else: signs_to_add = k - c ans = "" for i in s: if signs_to_add == 0: if i not in ['*', '?']: ans += i else: ans = ans[:-1] continue if i == '?': signs_to_add -= 1 elif i == '*': signs_to_add -= 1 while signs_to_add > 0: ans += ans[-1] signs_to_add -= 1 else: ans += i print(ans) ```
vfc_10474
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1099/C", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "hw?ap*yn?eww*ye*ar\n12\n", "output": "hwapppyewyar", "type": "stdin_stdout" }, { "fn_name": null, "input": "ab?a\n2\n", "output": "aa", "type": "stdin_stdout" }, { "fn_name": null, "input": "ab?a\n3\n", "output": "aba", "type": "stdin_stdout" }, { "fn_name": null, "input": "ababb\n5\n", "output": "ababb", "type": "stdin_stdout" }, { "fn_name": null, "input": "ab?a\n1\n", "output": "Impossible", "type": "stdin_stdout" } ] }
apps
verifiable_code
181
Solve the following coding problem using the programming language python: Vasya started working in a machine vision company of IT City. Vasya's team creates software and hardware for identification of people by their face. One of the project's know-how is a camera rotating around its optical axis on shooting. People see an eye-catching gadget — a rotating camera — come up to it to see it better, look into it. And the camera takes their photo at that time. What could be better for high quality identification? But not everything is so simple. The pictures from camera appear rotated too (on clockwise camera rotation frame the content becomes rotated counter-clockwise). But the identification algorithm can work only with faces that are just slightly deviated from vertical. Vasya was entrusted to correct the situation — to rotate a captured image so that image would be minimally deviated from vertical. Requirements were severe. Firstly, the picture should be rotated only on angle divisible by 90 degrees to not lose a bit of information about the image. Secondly, the frames from the camera are so huge and FPS is so big that adequate rotation speed is provided by hardware FPGA solution only. And this solution can rotate only by 90 degrees clockwise. Of course, one can apply 90 degrees turn several times but for the sake of performance the number of turns should be minimized. Help Vasya implement the program that by the given rotation angle of the camera can determine the minimum number of 90 degrees clockwise turns necessary to get a picture in which up direction deviation from vertical is minimum. The next figure contains frames taken from an unrotated camera, then from rotated 90 degrees clockwise, then from rotated 90 degrees counter-clockwise. Arrows show direction to "true up". [Image] The next figure shows 90 degrees clockwise turn by FPGA hardware. [Image] -----Input----- The only line of the input contains one integer x ( - 10^18 ≤ x ≤ 10^18) — camera angle in degrees. Positive value denotes clockwise camera rotation, negative — counter-clockwise. -----Output----- Output one integer — the minimum required number of 90 degrees clockwise turns. -----Examples----- Input 60 Output 1 Input -60 Output 3 -----Note----- When the camera is rotated 60 degrees counter-clockwise (the second example), an image from it is rotated 60 degrees clockwise. One 90 degrees clockwise turn of the image result in 150 degrees clockwise total rotation and deviation from "true up" for one turn is 150 degrees. Two 90 degrees clockwise turns of the image result in 240 degrees clockwise total rotation and deviation from "true up" for two turns is 120 degrees because 240 degrees clockwise equal to 120 degrees counter-clockwise. Three 90 degrees clockwise turns of the image result in 330 degrees clockwise total rotation and deviation from "true up" for three turns is 30 degrees because 330 degrees clockwise equal to 30 degrees counter-clockwise. From 60, 150, 120 and 30 degrees deviations the smallest is 30, and it it achieved in three 90 degrees clockwise turns. 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())) % 360 ret, opt = 4, 361 for i in range(4): x = (n+90*i)%360 x = min(x, 360-x) if (x, i) < (opt, ret): opt, ret = x, i print(ret) ```
vfc_10478
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/630/M", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "60\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "-60\n", "output": "3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "0\n", "output": "0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "44\n", "output": "0\n", "type": "stdin_stdout" } ] }
apps
verifiable_code
182
Solve the following coding problem using the programming language python: Carl is a beginner magician. He has a blue, b violet and c orange magic spheres. In one move he can transform two spheres of the same color into one sphere of any other color. To make a spell that has never been seen before, he needs at least x blue, y violet and z orange spheres. Can he get them (possible, in multiple actions)? -----Input----- The first line of the input contains three integers a, b and c (0 ≤ a, b, c ≤ 1 000 000) — the number of blue, violet and orange spheres that are in the magician's disposal. The second line of the input contains three integers, x, y and z (0 ≤ x, y, z ≤ 1 000 000) — the number of blue, violet and orange spheres that he needs to get. -----Output----- If the wizard is able to obtain the required numbers of spheres, print "Yes". Otherwise, print "No". -----Examples----- Input 4 4 0 2 1 2 Output Yes Input 5 6 1 2 7 2 Output No Input 3 3 3 2 2 2 Output Yes -----Note----- In the first sample the wizard has 4 blue and 4 violet spheres. In his first action he can turn two blue spheres into one violet one. After that he will have 2 blue and 5 violet spheres. Then he turns 4 violet spheres into 2 orange spheres and he ends up with 2 blue, 1 violet and 2 orange spheres, which is exactly what he needs. 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())) x, y, z = list(map(int, input().split())) col = max(0, x - a) + max(0, y - b) + max(0, z - c) sum = max(0, (a - x) // 2) + max(0, (b - y) // 2) + max(0, (c - z) // 2) if sum >= col: print('Yes') else: print('No') ```
vfc_10482
{ "difficulty": "interview", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/606/A", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4 4 0\n2 1 2\n", "output": "Yes\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 6 1\n2 7 2\n", "output": "No\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 3 3\n2 2 2\n", "output": "Yes\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "0 0 0\n0 0 0\n", "output": "Yes\n", "type": "stdin_stdout" } ] }