contestId
int64
0
1.01k
index
stringclasses
57 values
name
stringlengths
2
58
type
stringclasses
2 values
rating
int64
0
3.5k
tags
sequencelengths
0
11
title
stringclasses
522 values
time-limit
stringclasses
8 values
memory-limit
stringclasses
8 values
problem-description
stringlengths
0
7.15k
input-specification
stringlengths
0
2.05k
output-specification
stringlengths
0
1.5k
demo-input
sequencelengths
0
7
demo-output
sequencelengths
0
7
note
stringlengths
0
5.24k
points
float64
0
425k
test_cases
listlengths
0
402
creationTimeSeconds
int64
1.37B
1.7B
relativeTimeSeconds
int64
8
2.15B
programmingLanguage
stringclasses
3 values
verdict
stringclasses
14 values
testset
stringclasses
12 values
passedTestCount
int64
0
1k
timeConsumedMillis
int64
0
15k
memoryConsumedBytes
int64
0
805M
code
stringlengths
3
65.5k
prompt
stringlengths
262
8.2k
response
stringlengths
17
65.5k
score
float64
-1
3.99
69
A
Young Physicist
PROGRAMMING
1,000
[ "implementation", "math" ]
A. Young Physicist
2
256
A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasya and decided to teach him a lesson. He gave the lazy student a seemingly easy task: You are given an idle body in space and the forces that affect it. The body can be considered as a material point with coordinates (0; 0; 0). Vasya had only to answer whether it is in equilibrium. "Piece of cake" — thought Vasya, we need only to check if the sum of all vectors is equal to 0. So, Vasya began to solve the problem. But later it turned out that there can be lots and lots of these forces, and Vasya can not cope without your help. Help him. Write a program that determines whether a body is idle or is moving by the given vectors of forces.
The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100), then follow *n* lines containing three integers each: the *x**i* coordinate, the *y**i* coordinate and the *z**i* coordinate of the force vector, applied to the body (<=-<=100<=≤<=*x**i*,<=*y**i*,<=*z**i*<=≤<=100).
Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not.
[ "3\n4 1 7\n-2 4 -1\n1 -5 -3\n", "3\n3 -1 7\n-5 2 -4\n2 -1 -3\n" ]
[ "NO", "YES" ]
none
500
[ { "input": "3\n4 1 7\n-2 4 -1\n1 -5 -3", "output": "NO" }, { "input": "3\n3 -1 7\n-5 2 -4\n2 -1 -3", "output": "YES" }, { "input": "10\n21 32 -46\n43 -35 21\n42 2 -50\n22 40 20\n-27 -9 38\n-4 1 1\n-40 6 -31\n-13 -2 34\n-21 34 -12\n-32 -29 41", "output": "NO" }, { "input": "10\n25 -33 43\n-27 -42 28\n-35 -20 19\n41 -42 -1\n49 -39 -4\n-49 -22 7\n-19 29 41\n8 -27 -43\n8 34 9\n-11 -3 33", "output": "NO" }, { "input": "10\n-6 21 18\n20 -11 -8\n37 -11 41\n-5 8 33\n29 23 32\n30 -33 -11\n39 -49 -36\n28 34 -49\n22 29 -34\n-18 -6 7", "output": "NO" }, { "input": "10\n47 -2 -27\n0 26 -14\n5 -12 33\n2 18 3\n45 -30 -49\n4 -18 8\n-46 -44 -41\n-22 -10 -40\n-35 -21 26\n33 20 38", "output": "NO" }, { "input": "13\n-3 -36 -46\n-11 -50 37\n42 -11 -15\n9 42 44\n-29 -12 24\n3 9 -40\n-35 13 50\n14 43 18\n-13 8 24\n-48 -15 10\n50 9 -50\n21 0 -50\n0 0 -6", "output": "YES" }, { "input": "14\n43 23 17\n4 17 44\n5 -5 -16\n-43 -7 -6\n47 -48 12\n50 47 -45\n2 14 43\n37 -30 15\n4 -17 -11\n17 9 -45\n-50 -3 -8\n-50 0 0\n-50 0 0\n-16 0 0", "output": "YES" }, { "input": "13\n29 49 -11\n38 -11 -20\n25 1 -40\n-11 28 11\n23 -19 1\n45 -41 -17\n-3 0 -19\n-13 -33 49\n-30 0 28\n34 17 45\n-50 9 -27\n-50 0 0\n-37 0 0", "output": "YES" }, { "input": "12\n3 28 -35\n-32 -44 -17\n9 -25 -6\n-42 -22 20\n-19 15 38\n-21 38 48\n-1 -37 -28\n-10 -13 -50\n-5 21 29\n34 28 50\n50 11 -49\n34 0 0", "output": "YES" }, { "input": "37\n-64 -79 26\n-22 59 93\n-5 39 -12\n77 -9 76\n55 -86 57\n83 100 -97\n-70 94 84\n-14 46 -94\n26 72 35\n14 78 -62\n17 82 92\n-57 11 91\n23 15 92\n-80 -1 1\n12 39 18\n-23 -99 -75\n-34 50 19\n-39 84 -7\n45 -30 -39\n-60 49 37\n45 -16 -72\n33 -51 -56\n-48 28 5\n97 91 88\n45 -82 -11\n-21 -15 -90\n-53 73 -26\n-74 85 -90\n-40 23 38\n100 -13 49\n32 -100 -100\n0 -100 -70\n0 -100 0\n0 -100 0\n0 -100 0\n0 -100 0\n0 -37 0", "output": "YES" }, { "input": "4\n68 3 100\n68 21 -100\n-100 -24 0\n-36 0 0", "output": "YES" }, { "input": "33\n-1 -46 -12\n45 -16 -21\n-11 45 -21\n-60 -42 -93\n-22 -45 93\n37 96 85\n-76 26 83\n-4 9 55\n7 -52 -9\n66 8 -85\n-100 -54 11\n-29 59 74\n-24 12 2\n-56 81 85\n-92 69 -52\n-26 -97 91\n54 59 -51\n58 21 -57\n7 68 56\n-47 -20 -51\n-59 77 -13\n-85 27 91\n79 60 -56\n66 -80 5\n21 -99 42\n-31 -29 98\n66 93 76\n-49 45 61\n100 -100 -100\n100 -100 -100\n66 -75 -100\n0 0 -100\n0 0 -87", "output": "YES" }, { "input": "3\n1 2 3\n3 2 1\n0 0 0", "output": "NO" }, { "input": "2\n5 -23 12\n0 0 0", "output": "NO" }, { "input": "1\n0 0 0", "output": "YES" }, { "input": "1\n1 -2 0", "output": "NO" }, { "input": "2\n-23 77 -86\n23 -77 86", "output": "YES" }, { "input": "26\n86 7 20\n-57 -64 39\n-45 6 -93\n-44 -21 100\n-11 -49 21\n73 -71 -80\n-2 -89 56\n-65 -2 7\n5 14 84\n57 41 13\n-12 69 54\n40 -25 27\n-17 -59 0\n64 -91 -30\n-53 9 42\n-54 -8 14\n-35 82 27\n-48 -59 -80\n88 70 79\n94 57 97\n44 63 25\n84 -90 -40\n-100 100 -100\n-92 100 -100\n0 10 -100\n0 0 -82", "output": "YES" }, { "input": "42\n11 27 92\n-18 -56 -57\n1 71 81\n33 -92 30\n82 83 49\n-87 -61 -1\n-49 45 49\n73 26 15\n-22 22 -77\n29 -93 87\n-68 44 -90\n-4 -84 20\n85 67 -6\n-39 26 77\n-28 -64 20\n65 -97 24\n-72 -39 51\n35 -75 -91\n39 -44 -8\n-25 -27 -57\n91 8 -46\n-98 -94 56\n94 -60 59\n-9 -95 18\n-53 -37 98\n-8 -94 -84\n-52 55 60\n15 -14 37\n65 -43 -25\n94 12 66\n-8 -19 -83\n29 81 -78\n-58 57 33\n24 86 -84\n-53 32 -88\n-14 7 3\n89 97 -53\n-5 -28 -91\n-100 100 -6\n-84 100 0\n0 100 0\n0 70 0", "output": "YES" }, { "input": "3\n96 49 -12\n2 -66 28\n-98 17 -16", "output": "YES" }, { "input": "5\n70 -46 86\n-100 94 24\n-27 63 -63\n57 -100 -47\n0 -11 0", "output": "YES" }, { "input": "18\n-86 -28 70\n-31 -89 42\n31 -48 -55\n95 -17 -43\n24 -95 -85\n-21 -14 31\n68 -18 81\n13 31 60\n-15 28 99\n-42 15 9\n28 -61 -62\n-16 71 29\n-28 75 -48\n-77 -67 36\n-100 83 89\n100 100 -100\n57 34 -100\n0 0 -53", "output": "YES" }, { "input": "44\n52 -54 -29\n-82 -5 -94\n-54 43 43\n91 16 71\n7 80 -91\n3 15 29\n-99 -6 -77\n-3 -77 -64\n73 67 34\n25 -10 -18\n-29 91 63\n-72 86 -16\n-68 85 -81\n-3 36 44\n-74 -14 -80\n34 -96 -97\n-76 -78 -33\n-24 44 -58\n98 12 77\n95 -63 -6\n-51 3 -90\n-92 -10 72\n7 3 -68\n57 -53 71\n29 57 -48\n35 -60 10\n79 -70 -61\n-20 77 55\n-86 -15 -35\n84 -88 -18\n100 -42 77\n-20 46 8\n-41 -43 -65\n38 -98 -23\n-100 65 45\n-7 -91 -63\n46 88 -85\n48 59 100\n0 0 100\n0 0 100\n0 0 100\n0 0 100\n0 0 100\n0 0 1", "output": "YES" }, { "input": "18\n-14 -64 -91\n-8 -66 -86\n-23 92 -40\n6 -3 -53\n57 41 78\n-79 42 -22\n-88 -17 45\n4 -45 44\n83 -18 -25\n34 86 -92\n75 -30 12\n44 99 11\n-67 -13 72\n22 83 -56\n-37 71 72\n-9 -100 100\n0 -100 31\n0 -58 0", "output": "YES" }, { "input": "23\n-70 37 78\n42 84 6\n28 -94 -24\n-49 76 95\n-67 18 84\n-53 78 -5\n65 -63 -64\n-66 -64 -69\n81 -93 95\n10 52 -79\n-89 -61 -64\n-64 -47 43\n-81 -35 55\n80 82 73\n-60 -81 -18\n49 -10 -19\n-58 70 12\n-24 -15 -93\n98 -93 -54\n-28 -75 11\n100 100 -63\n100 100 0\n56 34 0", "output": "YES" }, { "input": "3\n0 2 -2\n1 -1 3\n-3 0 0", "output": "NO" } ]
1,568,866,500
2,147,483,647
Python 3
OK
TESTS
81
218
0
n = int(input()) x = 0 y = 0 z = 0 def add(a,num,listt): a = a + int(listt[num]) return a 5 for i in range(n): tmp = input().split() x = add(x,0,tmp) y = add(y,1,tmp) z = add(z,2,tmp) if x == 0 and y == 0 and z == 0: print('YES') else: print('NO')
Title: Young Physicist Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasya and decided to teach him a lesson. He gave the lazy student a seemingly easy task: You are given an idle body in space and the forces that affect it. The body can be considered as a material point with coordinates (0; 0; 0). Vasya had only to answer whether it is in equilibrium. "Piece of cake" — thought Vasya, we need only to check if the sum of all vectors is equal to 0. So, Vasya began to solve the problem. But later it turned out that there can be lots and lots of these forces, and Vasya can not cope without your help. Help him. Write a program that determines whether a body is idle or is moving by the given vectors of forces. Input Specification: The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100), then follow *n* lines containing three integers each: the *x**i* coordinate, the *y**i* coordinate and the *z**i* coordinate of the force vector, applied to the body (<=-<=100<=≤<=*x**i*,<=*y**i*,<=*z**i*<=≤<=100). Output Specification: Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not. Demo Input: ['3\n4 1 7\n-2 4 -1\n1 -5 -3\n', '3\n3 -1 7\n-5 2 -4\n2 -1 -3\n'] Demo Output: ['NO', 'YES'] Note: none
```python n = int(input()) x = 0 y = 0 z = 0 def add(a,num,listt): a = a + int(listt[num]) return a 5 for i in range(n): tmp = input().split() x = add(x,0,tmp) y = add(y,1,tmp) z = add(z,2,tmp) if x == 0 and y == 0 and z == 0: print('YES') else: print('NO') ```
3.9455
767
C
Garland
PROGRAMMING
2,000
[ "dfs and similar", "graphs", "greedy", "trees" ]
null
null
Once at New Year Dima had a dream in which he was presented a fairy garland. A garland is a set of lamps, some pairs of which are connected by wires. Dima remembered that each two lamps in the garland were connected directly or indirectly via some wires. Furthermore, the number of wires was exactly one less than the number of lamps. There was something unusual about the garland. Each lamp had its own brightness which depended on the temperature of the lamp. Temperatures could be positive, negative or zero. Dima has two friends, so he decided to share the garland with them. He wants to cut two different wires so that the garland breaks up into three parts. Each part of the garland should shine equally, i. e. the sums of lamps' temperatures should be equal in each of the parts. Of course, each of the parts should be non-empty, i. e. each part should contain at least one lamp. Help Dima to find a suitable way to cut the garland, or determine that this is impossible. While examining the garland, Dima lifted it up holding by one of the lamps. Thus, each of the lamps, except the one he is holding by, is now hanging on some wire. So, you should print two lamp ids as the answer which denote that Dima should cut the wires these lamps are hanging on. Of course, the lamp Dima is holding the garland by can't be included in the answer.
The first line contains single integer *n* (3<=≤<=*n*<=≤<=106) — the number of lamps in the garland. Then *n* lines follow. The *i*-th of them contain the information about the *i*-th lamp: the number lamp *a**i*, it is hanging on (and 0, if is there is no such lamp), and its temperature *t**i* (<=-<=100<=≤<=*t**i*<=≤<=100). The lamps are numbered from 1 to *n*.
If there is no solution, print -1. Otherwise print two integers — the indexes of the lamps which mean Dima should cut the wires they are hanging on. If there are multiple answers, print any of them.
[ "6\n2 4\n0 5\n4 2\n2 1\n1 1\n4 2\n", "6\n2 4\n0 6\n4 2\n2 1\n1 1\n4 2\n" ]
[ "1 4\n", "-1\n" ]
The garland and cuts scheme for the first example:
1,500
[ { "input": "6\n2 4\n0 5\n4 2\n2 1\n1 1\n4 2", "output": "1 4" }, { "input": "6\n2 4\n0 6\n4 2\n2 1\n1 1\n4 2", "output": "-1" }, { "input": "6\n2 4\n0 -1\n4 2\n2 3\n1 2\n4 5", "output": "6 4" }, { "input": "3\n2 1\n0 1\n2 1", "output": "1 3" }, { "input": "5\n0 5\n4 1\n2 1\n1 3\n1 5", "output": "4 5" }, { "input": "10\n5 8\n5 3\n8 7\n8 1\n0 4\n5 3\n1 1\n1 1\n3 1\n1 1", "output": "8 1" }, { "input": "49\n2 1\n43 1\n31 1\n0 34\n14 1\n29 1\n40 1\n40 1\n39 1\n1 1\n28 1\n43 1\n44 1\n44 1\n43 1\n12 5\n12 5\n28 1\n7 1\n15 1\n43 1\n4 49\n15 1\n8 1\n17 9\n5 1\n43 1\n43 1\n40 1\n2 1\n7 2\n24 1\n12 1\n27 1\n2 1\n43 1\n28 1\n5 1\n27 1\n28 1\n37 1\n27 1\n4 1\n28 1\n31 1\n40 1\n21 1\n38 1\n44 1", "output": "-1" }, { "input": "4\n0 1\n1 -1\n2 1\n3 -1", "output": "-1" }, { "input": "4\n0 0\n1 0\n1 1\n1 -1", "output": "-1" }, { "input": "4\n0 0\n1 1\n1 -1\n1 0", "output": "-1" }, { "input": "3\n0 -1\n1 1\n1 0", "output": "-1" }, { "input": "4\n0 0\n1 0\n2 1\n2 -1", "output": "-1" }, { "input": "5\n0 0\n1 -7\n1 7\n3 -7\n4 7", "output": "-1" }, { "input": "3\n0 0\n1 1\n2 -1", "output": "-1" }, { "input": "3\n0 2\n1 -1\n1 -1", "output": "-1" }, { "input": "3\n0 0\n1 1\n1 2", "output": "-1" }, { "input": "4\n0 -1\n1 -1\n1 -1\n1 -1", "output": "-1" }, { "input": "3\n0 -6\n1 6\n1 0", "output": "-1" } ]
1,580,446,783
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
0
108
0
#https://codeforces.com/problemset/problem/767/C #TLE def push(d, u, v): if u not in d: d[u] = [] d[u].append(v) g = {} d = {} p = {} root = None n = int(input()) for u in range(1, n+1): v, val = map(int, input().split()) if v == 0: root=u else: push(g, v, u) p[u] = v d[u] = val def solve(g, d, p, root): S = [root] i = 0 while i < len(S): u = S[i] if u in g: for v in g[u]: S.append(v) i+=1 for u in S[::-1]: if u in g: for v in g[u]: d[u] += d[v] print(d) if d[root] % 3 != 0: return -1 sum_ = d[root] // 3 set1 = set() set2 = set() first1S = None for u in S[::-1][:-1]: if d[u] == sum_: set1.add(u) if first1S is None: first1S = u elif d[u] == 2*sum_: set2.add(u) #print(first1S, set1, set2) if first1S is None: return -1 first2S = None u = first1S while u != root: u = p[u] if u in set1: set1.remove(u) elif u in set2: first2S=u if first2S is not None: return first1S, first2S elif len(set1) > 0: return first1S, next(iter(set1)) else: return -1 ans = solve(g, d, p, root) if ans == -1: print(ans) else: print(str(ans[0])+' '+str(ans[1])) #11 #0 3 #1 3 #1 0 #2 3 #2 0 #4 1 #4 -1 #6 1 #6 1 #7 -1 #7 -1
Title: Garland Time Limit: None seconds Memory Limit: None megabytes Problem Description: Once at New Year Dima had a dream in which he was presented a fairy garland. A garland is a set of lamps, some pairs of which are connected by wires. Dima remembered that each two lamps in the garland were connected directly or indirectly via some wires. Furthermore, the number of wires was exactly one less than the number of lamps. There was something unusual about the garland. Each lamp had its own brightness which depended on the temperature of the lamp. Temperatures could be positive, negative or zero. Dima has two friends, so he decided to share the garland with them. He wants to cut two different wires so that the garland breaks up into three parts. Each part of the garland should shine equally, i. e. the sums of lamps' temperatures should be equal in each of the parts. Of course, each of the parts should be non-empty, i. e. each part should contain at least one lamp. Help Dima to find a suitable way to cut the garland, or determine that this is impossible. While examining the garland, Dima lifted it up holding by one of the lamps. Thus, each of the lamps, except the one he is holding by, is now hanging on some wire. So, you should print two lamp ids as the answer which denote that Dima should cut the wires these lamps are hanging on. Of course, the lamp Dima is holding the garland by can't be included in the answer. Input Specification: The first line contains single integer *n* (3<=≤<=*n*<=≤<=106) — the number of lamps in the garland. Then *n* lines follow. The *i*-th of them contain the information about the *i*-th lamp: the number lamp *a**i*, it is hanging on (and 0, if is there is no such lamp), and its temperature *t**i* (<=-<=100<=≤<=*t**i*<=≤<=100). The lamps are numbered from 1 to *n*. Output Specification: If there is no solution, print -1. Otherwise print two integers — the indexes of the lamps which mean Dima should cut the wires they are hanging on. If there are multiple answers, print any of them. Demo Input: ['6\n2 4\n0 5\n4 2\n2 1\n1 1\n4 2\n', '6\n2 4\n0 6\n4 2\n2 1\n1 1\n4 2\n'] Demo Output: ['1 4\n', '-1\n'] Note: The garland and cuts scheme for the first example:
```python #https://codeforces.com/problemset/problem/767/C #TLE def push(d, u, v): if u not in d: d[u] = [] d[u].append(v) g = {} d = {} p = {} root = None n = int(input()) for u in range(1, n+1): v, val = map(int, input().split()) if v == 0: root=u else: push(g, v, u) p[u] = v d[u] = val def solve(g, d, p, root): S = [root] i = 0 while i < len(S): u = S[i] if u in g: for v in g[u]: S.append(v) i+=1 for u in S[::-1]: if u in g: for v in g[u]: d[u] += d[v] print(d) if d[root] % 3 != 0: return -1 sum_ = d[root] // 3 set1 = set() set2 = set() first1S = None for u in S[::-1][:-1]: if d[u] == sum_: set1.add(u) if first1S is None: first1S = u elif d[u] == 2*sum_: set2.add(u) #print(first1S, set1, set2) if first1S is None: return -1 first2S = None u = first1S while u != root: u = p[u] if u in set1: set1.remove(u) elif u in set2: first2S=u if first2S is not None: return first1S, first2S elif len(set1) > 0: return first1S, next(iter(set1)) else: return -1 ans = solve(g, d, p, root) if ans == -1: print(ans) else: print(str(ans[0])+' '+str(ans[1])) #11 #0 3 #1 3 #1 0 #2 3 #2 0 #4 1 #4 -1 #6 1 #6 1 #7 -1 #7 -1 ```
0
845
C
Two TVs
PROGRAMMING
1,500
[ "data structures", "greedy", "sortings" ]
null
null
Polycarp is a great fan of television. He wrote down all the TV programs he is interested in for today. His list contains *n* shows, *i*-th of them starts at moment *l**i* and ends at moment *r**i*. Polycarp owns two TVs. He can watch two different shows simultaneously with two TVs but he can only watch one show at any given moment on a single TV. If one show ends at the same moment some other show starts then you can't watch them on a single TV. Polycarp wants to check out all *n* shows. Are two TVs enough to do so?
The first line contains one integer *n* (1<=≤<=*n*<=≤<=2·105) — the number of shows. Each of the next *n* lines contains two integers *l**i* and *r**i* (0<=≤<=*l**i*<=&lt;<=*r**i*<=≤<=109) — starting and ending time of *i*-th show.
If Polycarp is able to check out all the shows using only two TVs then print "YES" (without quotes). Otherwise, print "NO" (without quotes).
[ "3\n1 2\n2 3\n4 5\n", "4\n1 2\n2 3\n2 3\n1 2\n" ]
[ "YES\n", "NO\n" ]
none
0
[ { "input": "3\n1 2\n2 3\n4 5", "output": "YES" }, { "input": "4\n1 2\n2 3\n2 3\n1 2", "output": "NO" }, { "input": "4\n0 1\n1 2\n2 3\n3 4", "output": "YES" }, { "input": "3\n1 2\n2 3\n2 4", "output": "NO" }, { "input": "3\n0 100\n0 100\n0 100", "output": "NO" }, { "input": "1\n0 1000000000", "output": "YES" }, { "input": "2\n0 1\n0 1", "output": "YES" }, { "input": "3\n2 3\n4 5\n1 6", "output": "YES" }, { "input": "5\n1 3\n1 4\n4 10\n5 8\n9 11", "output": "YES" }, { "input": "3\n1 2\n1 2\n2 3", "output": "NO" }, { "input": "4\n1 100\n10 15\n20 25\n30 35", "output": "YES" }, { "input": "3\n1 8\n6 7\n8 11", "output": "YES" }, { "input": "5\n1 2\n3 5\n4 7\n8 9\n5 10", "output": "NO" }, { "input": "4\n1 7\n2 3\n4 5\n6 7", "output": "YES" }, { "input": "4\n1 100\n50 51\n60 90\n51 52", "output": "NO" }, { "input": "3\n1 10\n2 9\n3 8", "output": "NO" }, { "input": "2\n0 4\n0 4", "output": "YES" }, { "input": "2\n0 2\n0 6", "output": "YES" }, { "input": "5\n3 4\n21 26\n12 17\n9 14\n15 16", "output": "YES" }, { "input": "5\n1 4\n13 15\n11 12\n9 15\n2 5", "output": "YES" }, { "input": "4\n16 19\n9 14\n14 15\n15 19", "output": "YES" }, { "input": "5\n16 19\n23 29\n3 8\n23 26\n22 23", "output": "NO" }, { "input": "5\n19 23\n12 17\n16 21\n20 23\n8 10", "output": "NO" }, { "input": "5\n8 10\n4 10\n3 4\n14 15\n17 19", "output": "YES" }, { "input": "3\n2 8\n5 7\n6 7", "output": "NO" }, { "input": "5\n10 12\n4 6\n21 24\n9 12\n7 13", "output": "NO" }, { "input": "5\n0 3\n14 16\n6 8\n5 9\n9 15", "output": "YES" }, { "input": "5\n6 12\n23 25\n6 7\n19 25\n10 11", "output": "YES" }, { "input": "5\n15 18\n23 24\n23 28\n22 24\n15 19", "output": "NO" }, { "input": "4\n1 8\n8 9\n5 7\n1 4", "output": "YES" }, { "input": "3\n6 10\n1 9\n2 5", "output": "YES" }, { "input": "3\n1 8\n5 6\n6 9", "output": "NO" }, { "input": "4\n2 3\n5 9\n8 10\n9 10", "output": "NO" }, { "input": "4\n0 8\n6 7\n5 9\n1 4", "output": "NO" }, { "input": "3\n6 9\n0 1\n0 2", "output": "YES" }, { "input": "5\n0 6\n21 25\n18 19\n0 3\n6 12", "output": "YES" }, { "input": "4\n1 5\n6 9\n4 8\n1 3", "output": "YES" }, { "input": "2\n2 5\n0 5", "output": "YES" }, { "input": "4\n5 8\n11 15\n3 7\n10 14", "output": "YES" }, { "input": "3\n12 14\n0 4\n2 3", "output": "YES" }, { "input": "4\n4 10\n0 1\n2 10\n0 5", "output": "NO" }, { "input": "4\n0 3\n0 1\n2 4\n2 5", "output": "NO" } ]
1,520,210,548
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
3
2,000
6,041,600
n=int(input()) a=[] s=input().split() a=a+[i for i in range(int(s[0]),int(s[1])+1)] t=True for i in range(n-1): s=input().split() q=int(s[0]) w=int(s[1]) for j in a: if ((q in a ) and(w in a)): t=False break if t==False: break a=a+[i for i in range(q,w+1)] if t==True: print("YES") else: print("NO")
Title: Two TVs Time Limit: None seconds Memory Limit: None megabytes Problem Description: Polycarp is a great fan of television. He wrote down all the TV programs he is interested in for today. His list contains *n* shows, *i*-th of them starts at moment *l**i* and ends at moment *r**i*. Polycarp owns two TVs. He can watch two different shows simultaneously with two TVs but he can only watch one show at any given moment on a single TV. If one show ends at the same moment some other show starts then you can't watch them on a single TV. Polycarp wants to check out all *n* shows. Are two TVs enough to do so? Input Specification: The first line contains one integer *n* (1<=≤<=*n*<=≤<=2·105) — the number of shows. Each of the next *n* lines contains two integers *l**i* and *r**i* (0<=≤<=*l**i*<=&lt;<=*r**i*<=≤<=109) — starting and ending time of *i*-th show. Output Specification: If Polycarp is able to check out all the shows using only two TVs then print "YES" (without quotes). Otherwise, print "NO" (without quotes). Demo Input: ['3\n1 2\n2 3\n4 5\n', '4\n1 2\n2 3\n2 3\n1 2\n'] Demo Output: ['YES\n', 'NO\n'] Note: none
```python n=int(input()) a=[] s=input().split() a=a+[i for i in range(int(s[0]),int(s[1])+1)] t=True for i in range(n-1): s=input().split() q=int(s[0]) w=int(s[1]) for j in a: if ((q in a ) and(w in a)): t=False break if t==False: break a=a+[i for i in range(q,w+1)] if t==True: print("YES") else: print("NO") ```
0
1
A
Theatre Square
PROGRAMMING
1,000
[ "math" ]
A. Theatre Square
1
256
Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size *a*<=×<=*a*. What is the least number of flagstones needed to pave the Square? It's allowed to cover the surface larger than the Theatre Square, but the Square has to be covered. It's not allowed to break the flagstones. The sides of flagstones should be parallel to the sides of the Square.
The input contains three positive integer numbers in the first line: *n*,<=<=*m* and *a* (1<=≤<=<=*n*,<=*m*,<=*a*<=≤<=109).
Write the needed number of flagstones.
[ "6 6 4\n" ]
[ "4\n" ]
none
0
[ { "input": "6 6 4", "output": "4" }, { "input": "1 1 1", "output": "1" }, { "input": "2 1 1", "output": "2" }, { "input": "1 2 1", "output": "2" }, { "input": "2 2 1", "output": "4" }, { "input": "2 1 2", "output": "1" }, { "input": "1 1 3", "output": "1" }, { "input": "2 3 4", "output": "1" }, { "input": "1000000000 1000000000 1", "output": "1000000000000000000" }, { "input": "12 13 4", "output": "12" }, { "input": "222 332 5", "output": "3015" }, { "input": "1000 1000 10", "output": "10000" }, { "input": "1001 1000 10", "output": "10100" }, { "input": "100 10001 1000000000", "output": "1" }, { "input": "1000000000 1000000000 1000000000", "output": "1" }, { "input": "1000000000 1000000000 999999999", "output": "4" }, { "input": "1000000000 1000000000 192", "output": "27126743055556" }, { "input": "1000000000 987654321 1", "output": "987654321000000000" }, { "input": "456784567 1000000000 51", "output": "175618850864484" }, { "input": "39916800 134217728 40320", "output": "3295710" } ]
1,660,337,147
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
30
0
k,n,w=map(int,input().split(" ")) x=0 counter=0 while True: if k <= x: break counter+=1 x+=w x=0 while True: if n<=x: break counter+=1 x+=w print(counter)
Title: Theatre Square Time Limit: 1 seconds Memory Limit: 256 megabytes Problem Description: Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size *a*<=×<=*a*. What is the least number of flagstones needed to pave the Square? It's allowed to cover the surface larger than the Theatre Square, but the Square has to be covered. It's not allowed to break the flagstones. The sides of flagstones should be parallel to the sides of the Square. Input Specification: The input contains three positive integer numbers in the first line: *n*,<=<=*m* and *a* (1<=≤<=<=*n*,<=*m*,<=*a*<=≤<=109). Output Specification: Write the needed number of flagstones. Demo Input: ['6 6 4\n'] Demo Output: ['4\n'] Note: none
```python k,n,w=map(int,input().split(" ")) x=0 counter=0 while True: if k <= x: break counter+=1 x+=w x=0 while True: if n<=x: break counter+=1 x+=w print(counter) ```
0
981
B
Businessmen Problems
PROGRAMMING
1,000
[ "sortings" ]
null
null
Two famous competing companies ChemForces and TopChemist decided to show their sets of recently discovered chemical elements on an exhibition. However they know that no element should be present in the sets of both companies. In order to avoid this representatives of both companies decided to make an agreement on the sets the companies should present. The sets should be chosen in the way that maximizes the total income of the companies. All elements are enumerated with integers. The ChemForces company has discovered $n$ distinct chemical elements with indices $a_1, a_2, \ldots, a_n$, and will get an income of $x_i$ Berland rubles if the $i$-th element from this list is in the set of this company. The TopChemist company discovered $m$ distinct chemical elements with indices $b_1, b_2, \ldots, b_m$, and it will get an income of $y_j$ Berland rubles for including the $j$-th element from this list to its set. In other words, the first company can present any subset of elements from $\{a_1, a_2, \ldots, a_n\}$ (possibly empty subset), the second company can present any subset of elements from $\{b_1, b_2, \ldots, b_m\}$ (possibly empty subset). There shouldn't be equal elements in the subsets. Help the representatives select the sets in such a way that no element is presented in both sets and the total income is the maximum possible.
The first line contains a single integer $n$ ($1 \leq n \leq 10^5$)  — the number of elements discovered by ChemForces. The $i$-th of the next $n$ lines contains two integers $a_i$ and $x_i$ ($1 \leq a_i \leq 10^9$, $1 \leq x_i \leq 10^9$)  — the index of the $i$-th element and the income of its usage on the exhibition. It is guaranteed that all $a_i$ are distinct. The next line contains a single integer $m$ ($1 \leq m \leq 10^5$)  — the number of chemicals invented by TopChemist. The $j$-th of the next $m$ lines contains two integers $b_j$ and $y_j$, ($1 \leq b_j \leq 10^9$, $1 \leq y_j \leq 10^9$)  — the index of the $j$-th element and the income of its usage on the exhibition. It is guaranteed that all $b_j$ are distinct.
Print the maximum total income you can obtain by choosing the sets for both companies in such a way that no element is presented in both sets.
[ "3\n1 2\n7 2\n3 10\n4\n1 4\n2 4\n3 4\n4 4\n", "1\n1000000000 239\n3\n14 15\n92 65\n35 89\n" ]
[ "24\n", "408\n" ]
In the first example ChemForces can choose the set ($3, 7$), while TopChemist can choose ($1, 2, 4$). This way the total income is $(10 + 2) + (4 + 4 + 4) = 24$. In the second example ChemForces can choose the only element $10^9$, while TopChemist can choose ($14, 92, 35$). This way the total income is $(239) + (15 + 65 + 89) = 408$.
750
[ { "input": "3\n1 2\n7 2\n3 10\n4\n1 4\n2 4\n3 4\n4 4", "output": "24" }, { "input": "1\n1000000000 239\n3\n14 15\n92 65\n35 89", "output": "408" }, { "input": "10\n598654597 488228616\n544064902 21923894\n329635457 980089248\n988262691 654502493\n967529230 543358150\n835120075 128123793\n809901567 613170206\n152157661 479980560\n859252956 318029856\n614959273 735298093\n10\n849172317 361325206\n341655282 740807372\n453949939 809030434\n813199219 765838311\n725032511 427644854\n631233366 115983627\n825067417 721190169\n463026366 953335259\n881501578 987288937\n500099903 427659916", "output": "11272808994" }, { "input": "10\n598654597 488228616\n544064902 21923894\n329635457 980089248\n988262691 654502493\n967529230 543358150\n835120075 128123793\n809901567 613170206\n152157661 479980560\n859252956 318029856\n614959273 735298093\n10\n544064902 740807372\n859252956 765838311\n835120075 115983627\n825067417 463026366\n809901567 500099903\n614959273 322932832\n33955432 657532637\n816892960 927933923\n916770606 754371712\n967529230 566149252", "output": "8955052582" }, { "input": "1\n259021863 682413763\n1\n554146726 693647287", "output": "1376061050" }, { "input": "1\n259021863 682413763\n1\n554146726 425883728", "output": "1108297491" }, { "input": "1\n1000000000 1\n1\n1000000000 1000000000", "output": "1000000000" }, { "input": "2\n1 4\n2 4\n2\n1 4\n2 4", "output": "8" }, { "input": "1\n14 15\n3\n35 89\n92 65\n1000000000 239", "output": "408" } ]
1,622,130,190
2,147,483,647
Python 3
OK
TESTS
33
530
15,667,200
n = int(input()) cf = {} sum = 0 for i in range(n): a, b = map(int, input().split()) cf[a] = b sum += b m = int(input()) for i in range(m): a, b = map(int, input().split()) if a in cf: if cf.get(a) < b: sum -= cf.get(a) cf[a] = b sum += b else: cf[a] = b sum += b print(sum)
Title: Businessmen Problems Time Limit: None seconds Memory Limit: None megabytes Problem Description: Two famous competing companies ChemForces and TopChemist decided to show their sets of recently discovered chemical elements on an exhibition. However they know that no element should be present in the sets of both companies. In order to avoid this representatives of both companies decided to make an agreement on the sets the companies should present. The sets should be chosen in the way that maximizes the total income of the companies. All elements are enumerated with integers. The ChemForces company has discovered $n$ distinct chemical elements with indices $a_1, a_2, \ldots, a_n$, and will get an income of $x_i$ Berland rubles if the $i$-th element from this list is in the set of this company. The TopChemist company discovered $m$ distinct chemical elements with indices $b_1, b_2, \ldots, b_m$, and it will get an income of $y_j$ Berland rubles for including the $j$-th element from this list to its set. In other words, the first company can present any subset of elements from $\{a_1, a_2, \ldots, a_n\}$ (possibly empty subset), the second company can present any subset of elements from $\{b_1, b_2, \ldots, b_m\}$ (possibly empty subset). There shouldn't be equal elements in the subsets. Help the representatives select the sets in such a way that no element is presented in both sets and the total income is the maximum possible. Input Specification: The first line contains a single integer $n$ ($1 \leq n \leq 10^5$)  — the number of elements discovered by ChemForces. The $i$-th of the next $n$ lines contains two integers $a_i$ and $x_i$ ($1 \leq a_i \leq 10^9$, $1 \leq x_i \leq 10^9$)  — the index of the $i$-th element and the income of its usage on the exhibition. It is guaranteed that all $a_i$ are distinct. The next line contains a single integer $m$ ($1 \leq m \leq 10^5$)  — the number of chemicals invented by TopChemist. The $j$-th of the next $m$ lines contains two integers $b_j$ and $y_j$, ($1 \leq b_j \leq 10^9$, $1 \leq y_j \leq 10^9$)  — the index of the $j$-th element and the income of its usage on the exhibition. It is guaranteed that all $b_j$ are distinct. Output Specification: Print the maximum total income you can obtain by choosing the sets for both companies in such a way that no element is presented in both sets. Demo Input: ['3\n1 2\n7 2\n3 10\n4\n1 4\n2 4\n3 4\n4 4\n', '1\n1000000000 239\n3\n14 15\n92 65\n35 89\n'] Demo Output: ['24\n', '408\n'] Note: In the first example ChemForces can choose the set ($3, 7$), while TopChemist can choose ($1, 2, 4$). This way the total income is $(10 + 2) + (4 + 4 + 4) = 24$. In the second example ChemForces can choose the only element $10^9$, while TopChemist can choose ($14, 92, 35$). This way the total income is $(239) + (15 + 65 + 89) = 408$.
```python n = int(input()) cf = {} sum = 0 for i in range(n): a, b = map(int, input().split()) cf[a] = b sum += b m = int(input()) for i in range(m): a, b = map(int, input().split()) if a in cf: if cf.get(a) < b: sum -= cf.get(a) cf[a] = b sum += b else: cf[a] = b sum += b print(sum) ```
3
363
B
Fence
PROGRAMMING
1,100
[ "brute force", "dp" ]
null
null
There is a fence in front of Polycarpus's home. The fence consists of *n* planks of the same width which go one after another from left to right. The height of the *i*-th plank is *h**i* meters, distinct planks can have distinct heights. Polycarpus has bought a posh piano and is thinking about how to get it into the house. In order to carry out his plan, he needs to take exactly *k* consecutive planks from the fence. Higher planks are harder to tear off the fence, so Polycarpus wants to find such *k* consecutive planks that the sum of their heights is minimal possible. Write the program that finds the indexes of *k* consecutive planks with minimal total height. Pay attention, the fence is not around Polycarpus's home, it is in front of home (in other words, the fence isn't cyclic).
The first line of the input contains integers *n* and *k* (1<=≤<=*n*<=≤<=1.5·105,<=1<=≤<=*k*<=≤<=*n*) — the number of planks in the fence and the width of the hole for the piano. The second line contains the sequence of integers *h*1,<=*h*2,<=...,<=*h**n* (1<=≤<=*h**i*<=≤<=100), where *h**i* is the height of the *i*-th plank of the fence.
Print such integer *j* that the sum of the heights of planks *j*, *j*<=+<=1, ..., *j*<=+<=*k*<=-<=1 is the minimum possible. If there are multiple such *j*'s, print any of them.
[ "7 3\n1 2 6 1 1 7 1\n" ]
[ "3\n" ]
In the sample, your task is to find three consecutive planks with the minimum sum of heights. In the given case three planks with indexes 3, 4 and 5 have the required attribute, their total height is 8.
1,000
[ { "input": "7 3\n1 2 6 1 1 7 1", "output": "3" }, { "input": "1 1\n100", "output": "1" }, { "input": "2 1\n10 20", "output": "1" }, { "input": "10 5\n1 2 3 1 2 2 3 1 4 5", "output": "1" }, { "input": "10 2\n3 1 4 1 4 6 2 1 4 6", "output": "7" }, { "input": "2 2\n20 10", "output": "1" }, { "input": "2 1\n20 1", "output": "2" }, { "input": "3 1\n1 2 3", "output": "1" }, { "input": "3 1\n2 1 3", "output": "2" }, { "input": "3 1\n3 2 1", "output": "3" }, { "input": "3 2\n1 2 3", "output": "1" }, { "input": "3 2\n3 2 1", "output": "2" }, { "input": "3 3\n1 2 3", "output": "1" }, { "input": "4 2\n9 8 11 7", "output": "1" }, { "input": "4 2\n10 1 2 3", "output": "2" }, { "input": "6 3\n56 56 56 2 1 2", "output": "4" }, { "input": "8 3\n1 1 1 1 2 60 90 1", "output": "1" }, { "input": "4 1\n1 5 2 2", "output": "1" }, { "input": "4 2\n4 6 7 4", "output": "1" }, { "input": "10 4\n1 1 1 4 4 4 4 4 4 3", "output": "1" }, { "input": "6 3\n1 2 1 3 1 1", "output": "1" }, { "input": "5 2\n100 100 100 1 1", "output": "4" } ]
1,691,481,051
2,147,483,647
PyPy 3-64
TIME_LIMIT_EXCEEDED
TESTS
6
1,000
25,190,400
n,k = map(int,input().split()) a = list(map(int,input().split())) s = 100000000000000000000000000000000000000000000000 t = 0 for j in range(n-(k-1)): if s > sum(a[j:j+k]): s = sum(a[j:j+k]) t = j + 1 print(t)
Title: Fence Time Limit: None seconds Memory Limit: None megabytes Problem Description: There is a fence in front of Polycarpus's home. The fence consists of *n* planks of the same width which go one after another from left to right. The height of the *i*-th plank is *h**i* meters, distinct planks can have distinct heights. Polycarpus has bought a posh piano and is thinking about how to get it into the house. In order to carry out his plan, he needs to take exactly *k* consecutive planks from the fence. Higher planks are harder to tear off the fence, so Polycarpus wants to find such *k* consecutive planks that the sum of their heights is minimal possible. Write the program that finds the indexes of *k* consecutive planks with minimal total height. Pay attention, the fence is not around Polycarpus's home, it is in front of home (in other words, the fence isn't cyclic). Input Specification: The first line of the input contains integers *n* and *k* (1<=≤<=*n*<=≤<=1.5·105,<=1<=≤<=*k*<=≤<=*n*) — the number of planks in the fence and the width of the hole for the piano. The second line contains the sequence of integers *h*1,<=*h*2,<=...,<=*h**n* (1<=≤<=*h**i*<=≤<=100), where *h**i* is the height of the *i*-th plank of the fence. Output Specification: Print such integer *j* that the sum of the heights of planks *j*, *j*<=+<=1, ..., *j*<=+<=*k*<=-<=1 is the minimum possible. If there are multiple such *j*'s, print any of them. Demo Input: ['7 3\n1 2 6 1 1 7 1\n'] Demo Output: ['3\n'] Note: In the sample, your task is to find three consecutive planks with the minimum sum of heights. In the given case three planks with indexes 3, 4 and 5 have the required attribute, their total height is 8.
```python n,k = map(int,input().split()) a = list(map(int,input().split())) s = 100000000000000000000000000000000000000000000000 t = 0 for j in range(n-(k-1)): if s > sum(a[j:j+k]): s = sum(a[j:j+k]) t = j + 1 print(t) ```
0
454
A
Little Pony and Crystal Mine
PROGRAMMING
800
[ "implementation" ]
null
null
Twilight Sparkle once got a crystal from the Crystal Mine. A crystal of size *n* (*n* is odd; *n*<=&gt;<=1) is an *n*<=×<=*n* matrix with a diamond inscribed into it. You are given an odd integer *n*. You need to draw a crystal of size *n*. The diamond cells of the matrix should be represented by character "D". All other cells of the matrix should be represented by character "*". Look at the examples to understand what you need to draw.
The only line contains an integer *n* (3<=≤<=*n*<=≤<=101; *n* is odd).
Output a crystal of size *n*.
[ "3\n", "5\n", "7\n" ]
[ "*D*\nDDD\n*D*\n", "**D**\n*DDD*\nDDDDD\n*DDD*\n**D**\n", "***D***\n**DDD**\n*DDDDD*\nDDDDDDD\n*DDDDD*\n**DDD**\n***D***\n" ]
none
500
[ { "input": "3", "output": "*D*\nDDD\n*D*" }, { "input": "5", "output": "**D**\n*DDD*\nDDDDD\n*DDD*\n**D**" }, { "input": "7", "output": "***D***\n**DDD**\n*DDDDD*\nDDDDDDD\n*DDDDD*\n**DDD**\n***D***" }, { "input": "11", "output": "*****D*****\n****DDD****\n***DDDDD***\n**DDDDDDD**\n*DDDDDDDDD*\nDDDDDDDDDDD\n*DDDDDDDDD*\n**DDDDDDD**\n***DDDDD***\n****DDD****\n*****D*****" }, { "input": "15", "output": "*******D*******\n******DDD******\n*****DDDDD*****\n****DDDDDDD****\n***DDDDDDDDD***\n**DDDDDDDDDDD**\n*DDDDDDDDDDDDD*\nDDDDDDDDDDDDDDD\n*DDDDDDDDDDDDD*\n**DDDDDDDDDDD**\n***DDDDDDDDD***\n****DDDDDDD****\n*****DDDDD*****\n******DDD******\n*******D*******" }, { "input": "21", "output": "**********D**********\n*********DDD*********\n********DDDDD********\n*******DDDDDDD*******\n******DDDDDDDDD******\n*****DDDDDDDDDDD*****\n****DDDDDDDDDDDDD****\n***DDDDDDDDDDDDDDD***\n**DDDDDDDDDDDDDDDDD**\n*DDDDDDDDDDDDDDDDDDD*\nDDDDDDDDDDDDDDDDDDDDD\n*DDDDDDDDDDDDDDDDDDD*\n**DDDDDDDDDDDDDDDDD**\n***DDDDDDDDDDDDDDD***\n****DDDDDDDDDDDDD****\n*****DDDDDDDDDDD*****\n******DDDDDDDDD******\n*******DDDDDDD*******\n********DDDDD********\n*********DDD*********\n**********D**********" }, { "input": "33", "output": "****************D****************\n***************DDD***************\n**************DDDDD**************\n*************DDDDDDD*************\n************DDDDDDDDD************\n***********DDDDDDDDDDD***********\n**********DDDDDDDDDDDDD**********\n*********DDDDDDDDDDDDDDD*********\n********DDDDDDDDDDDDDDDDD********\n*******DDDDDDDDDDDDDDDDDDD*******\n******DDDDDDDDDDDDDDDDDDDDD******\n*****DDDDDDDDDDDDDDDDDDDDDDD*****\n****DDDDDDDDDDDDDDDDDDDDDDDDD****\n***DDDDDDDDDDDDDDDDDDDDDDDDDDD***\n**DDDDDDDDDDDDDDDDDDD..." }, { "input": "57", "output": "****************************D****************************\n***************************DDD***************************\n**************************DDDDD**************************\n*************************DDDDDDD*************************\n************************DDDDDDDDD************************\n***********************DDDDDDDDDDD***********************\n**********************DDDDDDDDDDDDD**********************\n*********************DDDDDDDDDDDDDDD*********************\n********************DDDDDDDDDDDDDDDDD**..." }, { "input": "69", "output": "**********************************D**********************************\n*********************************DDD*********************************\n********************************DDDDD********************************\n*******************************DDDDDDD*******************************\n******************************DDDDDDDDD******************************\n*****************************DDDDDDDDDDD*****************************\n****************************DDDDDDDDDDDDD****************************\n**************..." }, { "input": "81", "output": "****************************************D****************************************\n***************************************DDD***************************************\n**************************************DDDDD**************************************\n*************************************DDDDDDD*************************************\n************************************DDDDDDDDD************************************\n***********************************DDDDDDDDDDD***********************************\n*************..." }, { "input": "91", "output": "*********************************************D*********************************************\n********************************************DDD********************************************\n*******************************************DDDDD*******************************************\n******************************************DDDDDDD******************************************\n*****************************************DDDDDDDDD*****************************************\n****************************************DDDDDD..." }, { "input": "101", "output": "**************************************************D**************************************************\n*************************************************DDD*************************************************\n************************************************DDDDD************************************************\n***********************************************DDDDDDD***********************************************\n**********************************************DDDDDDDDD********************************************..." } ]
1,676,561,570
2,147,483,647
Python 3
OK
TESTS
12
46
0
n = int(input()) for i in range(1, n + 1, 2): print('*' * ((n - i) // 2), end='') print('D' * i, end='') print('*' * ((n - i) // 2), end='') print() for i in range(n - 2, 0, -2): print('*' * ((n - i) // 2), end='') print('D' * i, end='') print('*' * ((n - i) // 2), end='') print()
Title: Little Pony and Crystal Mine Time Limit: None seconds Memory Limit: None megabytes Problem Description: Twilight Sparkle once got a crystal from the Crystal Mine. A crystal of size *n* (*n* is odd; *n*<=&gt;<=1) is an *n*<=×<=*n* matrix with a diamond inscribed into it. You are given an odd integer *n*. You need to draw a crystal of size *n*. The diamond cells of the matrix should be represented by character "D". All other cells of the matrix should be represented by character "*". Look at the examples to understand what you need to draw. Input Specification: The only line contains an integer *n* (3<=≤<=*n*<=≤<=101; *n* is odd). Output Specification: Output a crystal of size *n*. Demo Input: ['3\n', '5\n', '7\n'] Demo Output: ['*D*\nDDD\n*D*\n', '**D**\n*DDD*\nDDDDD\n*DDD*\n**D**\n', '***D***\n**DDD**\n*DDDDD*\nDDDDDDD\n*DDDDD*\n**DDD**\n***D***\n'] Note: none
```python n = int(input()) for i in range(1, n + 1, 2): print('*' * ((n - i) // 2), end='') print('D' * i, end='') print('*' * ((n - i) // 2), end='') print() for i in range(n - 2, 0, -2): print('*' * ((n - i) // 2), end='') print('D' * i, end='') print('*' * ((n - i) // 2), end='') print() ```
3
362
B
Petya and Staircases
PROGRAMMING
1,100
[ "implementation", "sortings" ]
null
null
Little boy Petya loves stairs very much. But he is bored from simple going up and down them — he loves jumping over several stairs at a time. As he stands on some stair, he can either jump to the next one or jump over one or two stairs at a time. But some stairs are too dirty and Petya doesn't want to step on them. Now Petya is on the first stair of the staircase, consisting of *n* stairs. He also knows the numbers of the dirty stairs of this staircase. Help Petya find out if he can jump through the entire staircase and reach the last stair number *n* without touching a dirty stair once. One has to note that anyway Petya should step on the first and last stairs, so if the first or the last stair is dirty, then Petya cannot choose a path with clean steps only.
The first line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=109, 0<=≤<=*m*<=≤<=3000) — the number of stairs in the staircase and the number of dirty stairs, correspondingly. The second line contains *m* different space-separated integers *d*1,<=*d*2,<=...,<=*d**m* (1<=≤<=*d**i*<=≤<=*n*) — the numbers of the dirty stairs (in an arbitrary order).
Print "YES" if Petya can reach stair number *n*, stepping only on the clean stairs. Otherwise print "NO".
[ "10 5\n2 4 8 3 6\n", "10 5\n2 4 5 7 9\n" ]
[ "NO", "YES" ]
none
500
[ { "input": "10 5\n2 4 8 3 6", "output": "NO" }, { "input": "10 5\n2 4 5 7 9", "output": "YES" }, { "input": "10 9\n2 3 4 5 6 7 8 9 10", "output": "NO" }, { "input": "5 2\n4 5", "output": "NO" }, { "input": "123 13\n36 73 111 2 92 5 47 55 48 113 7 78 37", "output": "YES" }, { "input": "10 10\n7 6 4 2 5 10 8 3 9 1", "output": "NO" }, { "input": "12312 0", "output": "YES" }, { "input": "9817239 1\n6323187", "output": "YES" }, { "input": "1 1\n1", "output": "NO" }, { "input": "5 4\n4 2 5 1", "output": "NO" }, { "input": "5 3\n4 3 5", "output": "NO" }, { "input": "500 3\n18 62 445", "output": "YES" }, { "input": "500 50\n72 474 467 241 442 437 336 234 410 120 438 164 405 177 142 114 27 20 445 235 46 176 88 488 242 391 28 414 145 92 206 334 152 343 367 254 100 243 155 348 148 450 461 483 97 34 471 69 416 362", "output": "NO" }, { "input": "500 8\n365 313 338 410 482 417 325 384", "output": "YES" }, { "input": "1000000000 10\n2 3 5 6 8 9 123 874 1230 1000000000", "output": "NO" }, { "input": "1000000000 10\n1 2 3 5 6 8 9 123 874 1230", "output": "NO" }, { "input": "10 1\n1", "output": "NO" }, { "input": "10 4\n1 2 4 5", "output": "NO" }, { "input": "50 20\n22 33 17 23 27 5 26 31 41 20 8 24 6 3 4 29 40 25 13 16", "output": "NO" }, { "input": "50 40\n14 27 19 30 31 20 28 11 37 29 23 33 7 26 22 16 1 6 18 3 47 36 38 2 48 9 41 8 5 50 4 45 44 25 39 12 43 42 40 46", "output": "NO" }, { "input": "123 12\n35 95 47 99 79 122 58 94 31 57 18 10", "output": "YES" }, { "input": "10 5\n1 3 5 7 9", "output": "NO" }, { "input": "100 7\n2 3 5 6 8 9 100", "output": "NO" }, { "input": "100 3\n98 99 100", "output": "NO" }, { "input": "100 3\n97 98 99", "output": "NO" }, { "input": "100 3\n96 98 99", "output": "YES" }, { "input": "10 6\n2 3 5 6 8 9", "output": "YES" }, { "input": "1000000000 10\n2 4 10 18 40 42 49 58 59 60", "output": "NO" }, { "input": "10 3\n1 4 6", "output": "NO" }, { "input": "8 3\n2 3 4", "output": "NO" }, { "input": "100 3\n4 5 6", "output": "NO" }, { "input": "10 2\n10 1", "output": "NO" }, { "input": "10 1\n10", "output": "NO" }, { "input": "4 2\n2 3", "output": "YES" }, { "input": "2 1\n1", "output": "NO" }, { "input": "2 0", "output": "YES" }, { "input": "4 3\n2 3 4", "output": "NO" }, { "input": "5 3\n4 2 3", "output": "NO" } ]
1,632,105,048
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
7
62
7,065,600
#362B (100No. Problem B) n,d = map(int,input().split()) stair = sorted(list(map(int,input().split()))) # print(stair) res = 'YES' if (1 not in stair and n not in stair): for i in range(d-2): if (stair[i+1] == stair[i]+1 and stair[i+2] == stair[i]+2): res = 'NO' break else: res = 'NO' print(res)
Title: Petya and Staircases Time Limit: None seconds Memory Limit: None megabytes Problem Description: Little boy Petya loves stairs very much. But he is bored from simple going up and down them — he loves jumping over several stairs at a time. As he stands on some stair, he can either jump to the next one or jump over one or two stairs at a time. But some stairs are too dirty and Petya doesn't want to step on them. Now Petya is on the first stair of the staircase, consisting of *n* stairs. He also knows the numbers of the dirty stairs of this staircase. Help Petya find out if he can jump through the entire staircase and reach the last stair number *n* without touching a dirty stair once. One has to note that anyway Petya should step on the first and last stairs, so if the first or the last stair is dirty, then Petya cannot choose a path with clean steps only. Input Specification: The first line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=109, 0<=≤<=*m*<=≤<=3000) — the number of stairs in the staircase and the number of dirty stairs, correspondingly. The second line contains *m* different space-separated integers *d*1,<=*d*2,<=...,<=*d**m* (1<=≤<=*d**i*<=≤<=*n*) — the numbers of the dirty stairs (in an arbitrary order). Output Specification: Print "YES" if Petya can reach stair number *n*, stepping only on the clean stairs. Otherwise print "NO". Demo Input: ['10 5\n2 4 8 3 6\n', '10 5\n2 4 5 7 9\n'] Demo Output: ['NO', 'YES'] Note: none
```python #362B (100No. Problem B) n,d = map(int,input().split()) stair = sorted(list(map(int,input().split()))) # print(stair) res = 'YES' if (1 not in stair and n not in stair): for i in range(d-2): if (stair[i+1] == stair[i]+1 and stair[i+2] == stair[i]+2): res = 'NO' break else: res = 'NO' print(res) ```
-1
895
B
XK Segments
PROGRAMMING
1,700
[ "binary search", "math", "sortings", "two pointers" ]
null
null
While Vasya finished eating his piece of pizza, the lesson has already started. For being late for the lesson, the teacher suggested Vasya to solve one interesting problem. Vasya has an array *a* and integer *x*. He should find the number of different ordered pairs of indexes (*i*,<=*j*) such that *a**i*<=≤<=*a**j* and there are exactly *k* integers *y* such that *a**i*<=≤<=*y*<=≤<=*a**j* and *y* is divisible by *x*. In this problem it is meant that pair (*i*,<=*j*) is equal to (*j*,<=*i*) only if *i* is equal to *j*. For example pair (1,<=2) is not the same as (2,<=1).
The first line contains 3 integers *n*,<=*x*,<=*k* (1<=≤<=*n*<=≤<=105,<=1<=≤<=*x*<=≤<=109,<=0<=≤<=*k*<=≤<=109), where *n* is the size of the array *a* and *x* and *k* are numbers from the statement. The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=109) — the elements of the array *a*.
Print one integer — the answer to the problem.
[ "4 2 1\n1 3 5 7\n", "4 2 0\n5 3 1 7\n", "5 3 1\n3 3 3 3 3\n" ]
[ "3\n", "4\n", "25\n" ]
In first sample there are only three suitable pairs of indexes — (1, 2), (2, 3), (3, 4). In second sample there are four suitable pairs of indexes(1, 1), (2, 2), (3, 3), (4, 4). In third sample every pair (*i*, *j*) is suitable, so the answer is 5 * 5 = 25.
1,000
[ { "input": "4 2 1\n1 3 5 7", "output": "3" }, { "input": "4 2 0\n5 3 1 7", "output": "4" }, { "input": "5 3 1\n3 3 3 3 3", "output": "25" }, { "input": "5 3 4\n24 13 1 24 24", "output": "4" }, { "input": "4 2 2\n1 3 5 7", "output": "2" }, { "input": "5 1 0\n10 12 14 20 30", "output": "0" }, { "input": "7 3 1\n3 3 6 9 12 15 18", "output": "9" }, { "input": "2 5 0\n3 4", "output": "3" }, { "input": "3 5 0\n4 4 4", "output": "9" }, { "input": "3 6 0\n3 4 5", "output": "6" }, { "input": "10 2 1\n2 2 2 2 2 2 2 1 2 1", "output": "80" }, { "input": "100 2 1\n1 2 2 2 1 2 1 2 2 2 2 1 2 1 1 2 1 2 2 1 1 2 1 1 2 2 1 1 2 1 2 2 2 2 2 1 1 1 2 1 2 1 2 1 2 1 2 2 1 2 2 2 1 1 1 2 2 1 1 2 2 1 1 1 1 1 1 2 2 1 1 2 2 1 2 2 1 2 1 2 2 1 2 1 1 1 2 2 1 1 2 1 2 2 1 1 2 2 2 1", "output": "5200" }, { "input": "1 13 1\n13", "output": "1" }, { "input": "2 1 1000000000\n1 1000000000", "output": "1" }, { "input": "2 1000000000 1\n1 1000000000", "output": "2" }, { "input": "1 1 1\n1", "output": "1" }, { "input": "5 1000000000 1\n1000000000 1 1 1 1", "output": "5" }, { "input": "2 1000 1000000\n1 1000000000", "output": "1" }, { "input": "6 2 10\n1 1 1 20 20 20", "output": "9" }, { "input": "1 1000000000 1\n1000000000", "output": "1" }, { "input": "4 65536 65536\n1 2 3 4", "output": "0" }, { "input": "1 600000000 1\n500000000", "output": "0" }, { "input": "5 3 2\n2 3 4 5 8", "output": "2" } ]
1,511,787,768
4,368
Python 3
WRONG_ANSWER
TESTS
3
62
5,529,600
a = [] n,x,k = map(int,input().split()) a = [int(i) for i in input().split()] ans = 0 for i in range(n): for j in range(i,n): if i != j: if a[i]%x == 0: ans+=1 if a[j]%x == 0: ans+=1 else: if a[i]%x==0: ans+=1 if abs(a[i]-a[j]) // x == k: ans+=1 print(ans)
Title: XK Segments Time Limit: None seconds Memory Limit: None megabytes Problem Description: While Vasya finished eating his piece of pizza, the lesson has already started. For being late for the lesson, the teacher suggested Vasya to solve one interesting problem. Vasya has an array *a* and integer *x*. He should find the number of different ordered pairs of indexes (*i*,<=*j*) such that *a**i*<=≤<=*a**j* and there are exactly *k* integers *y* such that *a**i*<=≤<=*y*<=≤<=*a**j* and *y* is divisible by *x*. In this problem it is meant that pair (*i*,<=*j*) is equal to (*j*,<=*i*) only if *i* is equal to *j*. For example pair (1,<=2) is not the same as (2,<=1). Input Specification: The first line contains 3 integers *n*,<=*x*,<=*k* (1<=≤<=*n*<=≤<=105,<=1<=≤<=*x*<=≤<=109,<=0<=≤<=*k*<=≤<=109), where *n* is the size of the array *a* and *x* and *k* are numbers from the statement. The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=109) — the elements of the array *a*. Output Specification: Print one integer — the answer to the problem. Demo Input: ['4 2 1\n1 3 5 7\n', '4 2 0\n5 3 1 7\n', '5 3 1\n3 3 3 3 3\n'] Demo Output: ['3\n', '4\n', '25\n'] Note: In first sample there are only three suitable pairs of indexes — (1, 2), (2, 3), (3, 4). In second sample there are four suitable pairs of indexes(1, 1), (2, 2), (3, 3), (4, 4). In third sample every pair (*i*, *j*) is suitable, so the answer is 5 * 5 = 25.
```python a = [] n,x,k = map(int,input().split()) a = [int(i) for i in input().split()] ans = 0 for i in range(n): for j in range(i,n): if i != j: if a[i]%x == 0: ans+=1 if a[j]%x == 0: ans+=1 else: if a[i]%x==0: ans+=1 if abs(a[i]-a[j]) // x == k: ans+=1 print(ans) ```
0
699
A
Launch of Collider
PROGRAMMING
1,000
[ "implementation" ]
null
null
There will be a launch of a new, powerful and unusual collider very soon, which located along a straight line. *n* particles will be launched inside it. All of them are located in a straight line and there can not be two or more particles located in the same point. The coordinates of the particles coincide with the distance in meters from the center of the collider, *x**i* is the coordinate of the *i*-th particle and its position in the collider at the same time. All coordinates of particle positions are even integers. You know the direction of each particle movement — it will move to the right or to the left after the collider's launch start. All particles begin to move simultaneously at the time of the collider's launch start. Each particle will move straight to the left or straight to the right with the constant speed of 1 meter per microsecond. The collider is big enough so particles can not leave it in the foreseeable time. Write the program which finds the moment of the first collision of any two particles of the collider. In other words, find the number of microseconds before the first moment when any two particles are at the same point.
The first line contains the positive integer *n* (1<=≤<=*n*<=≤<=200<=000) — the number of particles. The second line contains *n* symbols "L" and "R". If the *i*-th symbol equals "L", then the *i*-th particle will move to the left, otherwise the *i*-th symbol equals "R" and the *i*-th particle will move to the right. The third line contains the sequence of pairwise distinct even integers *x*1,<=*x*2,<=...,<=*x**n* (0<=≤<=*x**i*<=≤<=109) — the coordinates of particles in the order from the left to the right. It is guaranteed that the coordinates of particles are given in the increasing order.
In the first line print the only integer — the first moment (in microseconds) when two particles are at the same point and there will be an explosion. Print the only integer -1, if the collision of particles doesn't happen.
[ "4\nRLRL\n2 4 6 10\n", "3\nLLR\n40 50 60\n" ]
[ "1\n", "-1\n" ]
In the first sample case the first explosion will happen in 1 microsecond because the particles number 1 and 2 will simultaneously be at the same point with the coordinate 3. In the second sample case there will be no explosion because there are no particles which will simultaneously be at the same point.
500
[ { "input": "4\nRLRL\n2 4 6 10", "output": "1" }, { "input": "3\nLLR\n40 50 60", "output": "-1" }, { "input": "4\nRLLR\n46 230 264 470", "output": "92" }, { "input": "6\nLLRLLL\n446 492 650 844 930 970", "output": "97" }, { "input": "8\nRRLLLLLL\n338 478 512 574 594 622 834 922", "output": "17" }, { "input": "10\nLRLRLLRRLR\n82 268 430 598 604 658 670 788 838 1000", "output": "3" }, { "input": "2\nRL\n0 1000000000", "output": "500000000" }, { "input": "12\nLRLLRRRRLRLL\n254 1260 1476 1768 2924 4126 4150 4602 5578 7142 8134 9082", "output": "108" }, { "input": "14\nRLLRRLRLLRLLLR\n698 2900 3476 3724 3772 3948 4320 4798 5680 6578 7754 8034 8300 8418", "output": "88" }, { "input": "16\nRRLLLRLRLLLLRLLR\n222 306 968 1060 1636 1782 2314 2710 3728 4608 5088 6790 6910 7156 7418 7668", "output": "123" }, { "input": "18\nRLRLLRRRLLLRLRRLRL\n1692 2028 2966 3008 3632 4890 5124 5838 6596 6598 6890 8294 8314 8752 8868 9396 9616 9808", "output": "10" }, { "input": "20\nRLLLLLLLRRRRLRRLRRLR\n380 902 1400 1834 2180 2366 2562 2596 2702 2816 3222 3238 3742 5434 6480 7220 7410 8752 9708 9970", "output": "252" }, { "input": "22\nLRRRRRRRRRRRLLRRRRRLRL\n1790 2150 2178 2456 2736 3282 3622 4114 4490 4772 5204 5240 5720 5840 5910 5912 6586 7920 8584 9404 9734 9830", "output": "48" }, { "input": "24\nLLRLRRLLRLRRRRLLRRLRLRRL\n100 360 864 1078 1360 1384 1438 2320 2618 3074 3874 3916 3964 5178 5578 6278 6630 6992 8648 8738 8922 8930 9276 9720", "output": "27" }, { "input": "26\nRLLLLLLLRLRRLRLRLRLRLLLRRR\n908 1826 2472 2474 2728 3654 3716 3718 3810 3928 4058 4418 4700 5024 5768 6006 6128 6386 6968 7040 7452 7774 7822 8726 9338 9402", "output": "59" }, { "input": "28\nRRLRLRRRRRRLLLRRLRRLLLRRLLLR\n156 172 1120 1362 2512 3326 3718 4804 4990 5810 6242 6756 6812 6890 6974 7014 7088 7724 8136 8596 8770 8840 9244 9250 9270 9372 9400 9626", "output": "10" }, { "input": "30\nRLLRLRLLRRRLRRRLLLLLLRRRLRRLRL\n128 610 1680 2436 2896 2994 3008 3358 3392 4020 4298 4582 4712 4728 5136 5900 6088 6232 6282 6858 6934 7186 7224 7256 7614 8802 8872 9170 9384 9794", "output": "7" }, { "input": "10\nLLLLRRRRRR\n0 2 4 6 8 10 12 14 16 18", "output": "-1" }, { "input": "5\nLLLLL\n0 10 20 30 40", "output": "-1" }, { "input": "6\nRRRRRR\n40 50 60 70 80 100", "output": "-1" }, { "input": "1\nR\n0", "output": "-1" }, { "input": "2\nRL\n2 1000000000", "output": "499999999" }, { "input": "2\nRL\n0 400000", "output": "200000" }, { "input": "2\nRL\n0 200002", "output": "100001" }, { "input": "2\nRL\n2 20000000", "output": "9999999" }, { "input": "4\nLLRL\n2 4 10 100", "output": "45" }, { "input": "4\nRLRL\n2 10 12 14", "output": "1" }, { "input": "2\nRL\n0 100000000", "output": "50000000" }, { "input": "2\nRL\n2 600002", "output": "300000" }, { "input": "1\nL\n0", "output": "-1" }, { "input": "2\nRL\n0 600000", "output": "300000" }, { "input": "5\nRRRRR\n0 2 4 6 8", "output": "-1" }, { "input": "2\nRL\n2 200000000", "output": "99999999" }, { "input": "2\nRL\n0 267382766", "output": "133691383" }, { "input": "3\nRRL\n4 8 999999998", "output": "499999995" }, { "input": "2\nRL\n0 2", "output": "1" }, { "input": "2\nRL\n2 400002", "output": "200000" }, { "input": "2\nLL\n2 4", "output": "-1" }, { "input": "2\nLL\n0 2", "output": "-1" }, { "input": "2\nRL\n0 100000", "output": "50000" }, { "input": "2\nRL\n2 200000020", "output": "100000009" }, { "input": "2\nRL\n2000000 4000000", "output": "1000000" }, { "input": "2\nRL\n0 199998", "output": "99999" }, { "input": "3\nLRR\n40 50 60", "output": "-1" }, { "input": "2\nRL\n200 400400", "output": "200100" }, { "input": "2\nRL\n2 400004", "output": "200001" }, { "input": "2\nRL\n0 200000000", "output": "100000000" } ]
1,468,937,002
3,502
Python 3
CHALLENGED
CHALLENGES
7
171
15,974,400
def main(): n = int(input()) s = input() arr, ans = [int(i) for i in input().split()], 99999 for i in range(len(s)): if s[i] == 'L' and s[i-1] == 'R' and i > 0: ans = min(ans, arr[i]//2 - arr[i - 1]//2) print(ans if ans != 99999 else -1) if __name__ == '__main__': main()
Title: Launch of Collider Time Limit: None seconds Memory Limit: None megabytes Problem Description: There will be a launch of a new, powerful and unusual collider very soon, which located along a straight line. *n* particles will be launched inside it. All of them are located in a straight line and there can not be two or more particles located in the same point. The coordinates of the particles coincide with the distance in meters from the center of the collider, *x**i* is the coordinate of the *i*-th particle and its position in the collider at the same time. All coordinates of particle positions are even integers. You know the direction of each particle movement — it will move to the right or to the left after the collider's launch start. All particles begin to move simultaneously at the time of the collider's launch start. Each particle will move straight to the left or straight to the right with the constant speed of 1 meter per microsecond. The collider is big enough so particles can not leave it in the foreseeable time. Write the program which finds the moment of the first collision of any two particles of the collider. In other words, find the number of microseconds before the first moment when any two particles are at the same point. Input Specification: The first line contains the positive integer *n* (1<=≤<=*n*<=≤<=200<=000) — the number of particles. The second line contains *n* symbols "L" and "R". If the *i*-th symbol equals "L", then the *i*-th particle will move to the left, otherwise the *i*-th symbol equals "R" and the *i*-th particle will move to the right. The third line contains the sequence of pairwise distinct even integers *x*1,<=*x*2,<=...,<=*x**n* (0<=≤<=*x**i*<=≤<=109) — the coordinates of particles in the order from the left to the right. It is guaranteed that the coordinates of particles are given in the increasing order. Output Specification: In the first line print the only integer — the first moment (in microseconds) when two particles are at the same point and there will be an explosion. Print the only integer -1, if the collision of particles doesn't happen. Demo Input: ['4\nRLRL\n2 4 6 10\n', '3\nLLR\n40 50 60\n'] Demo Output: ['1\n', '-1\n'] Note: In the first sample case the first explosion will happen in 1 microsecond because the particles number 1 and 2 will simultaneously be at the same point with the coordinate 3. In the second sample case there will be no explosion because there are no particles which will simultaneously be at the same point.
```python def main(): n = int(input()) s = input() arr, ans = [int(i) for i in input().split()], 99999 for i in range(len(s)): if s[i] == 'L' and s[i-1] == 'R' and i > 0: ans = min(ans, arr[i]//2 - arr[i - 1]//2) print(ans if ans != 99999 else -1) if __name__ == '__main__': main() ```
-1
125
B
Simple XML
PROGRAMMING
1,000
[ "implementation" ]
null
null
Let's define a string &lt;x&gt; as an opening tag, where *x* is any small letter of the Latin alphabet. Each opening tag matches a closing tag of the type &lt;/x&gt;, where *x* is the same letter. Tegs can be nested into each other: in this case one opening and closing tag pair is located inside another pair. Let's define the notion of a XML-text: - an empty string is a XML-text - if *s* is a XML-text, then *s*'=&lt;a&gt;+*s*+&lt;/a&gt; also is a XML-text, where *a* is any small Latin letter - if *s*1, *s*2 are XML-texts, then *s*1+*s*2 also is a XML-text You are given a XML-text (it is guaranteed that the text is valid), your task is to print in the following form: - each tag (opening and closing) is located on a single line - print before the tag 2<=*<=*h* spaces, where *h* is the level of the tag's nestedness.
The input data consists on the only non-empty string — the XML-text, its length does not exceed 1000 characters. It is guaranteed that the text is valid. The text contains no spaces.
Print the given XML-text according to the above-given rules.
[ "&lt;a&gt;&lt;b&gt;&lt;c&gt;&lt;/c&gt;&lt;/b&gt;&lt;/a&gt;\n", "&lt;a&gt;&lt;b&gt;&lt;/b&gt;&lt;d&gt;&lt;c&gt;&lt;/c&gt;&lt;/d&gt;&lt;/a&gt;\n" ]
[ "&lt;a&gt;\n &lt;b&gt;\n &lt;c&gt;\n &lt;/c&gt;\n &lt;/b&gt;\n&lt;/a&gt;\n", "&lt;a&gt;\n &lt;b&gt;\n &lt;/b&gt;\n &lt;d&gt;\n &lt;c&gt;\n &lt;/c&gt;\n &lt;/d&gt;\n&lt;/a&gt;\n" ]
none
1,500
[ { "input": "<a><b><c></c></b></a>", "output": "<a>\n <b>\n <c>\n </c>\n </b>\n</a>" }, { "input": "<a><b></b><d><c></c></d></a>", "output": "<a>\n <b>\n </b>\n <d>\n <c>\n </c>\n </d>\n</a>" }, { "input": "<z></z>", "output": "<z>\n</z>" }, { "input": "<u><d></d></u><j></j>", "output": "<u>\n <d>\n </d>\n</u>\n<j>\n</j>" }, { "input": "<a></a><n></n><v><r></r></v><z></z>", "output": "<a>\n</a>\n<n>\n</n>\n<v>\n <r>\n </r>\n</v>\n<z>\n</z>" }, { "input": "<c><l></l><b><w><f><t><m></m></t></f><w></w></w></b></c>", "output": "<c>\n <l>\n </l>\n <b>\n <w>\n <f>\n <t>\n <m>\n </m>\n </t>\n </f>\n <w>\n </w>\n </w>\n </b>\n</c>" }, { "input": "<u><d><g><k><m><a><u><j><d></d></j></u></a></m><m></m></k></g></d></u>", "output": "<u>\n <d>\n <g>\n <k>\n <m>\n <a>\n <u>\n <j>\n <d>\n </d>\n </j>\n </u>\n </a>\n </m>\n <m>\n </m>\n </k>\n </g>\n </d>\n</u>" }, { "input": "<x><a><l></l></a><g><v></v><d></d></g><z></z><y></y></x><q><h></h><s></s></q><c></c><w></w><q></q>", "output": "<x>\n <a>\n <l>\n </l>\n </a>\n <g>\n <v>\n </v>\n <d>\n </d>\n </g>\n <z>\n </z>\n <y>\n </y>\n</x>\n<q>\n <h>\n </h>\n <s>\n </s>\n</q>\n<c>\n</c>\n<w>\n</w>\n<q>\n</q>" }, { "input": "<b><k><t></t></k><j></j><t></t><q></q></b><x><h></h></x><r></r><k></k><i></i><t><b></b></t><z></z><x></x><p></p><u></u>", "output": "<b>\n <k>\n <t>\n </t>\n </k>\n <j>\n </j>\n <t>\n </t>\n <q>\n </q>\n</b>\n<x>\n <h>\n </h>\n</x>\n<r>\n</r>\n<k>\n</k>\n<i>\n</i>\n<t>\n <b>\n </b>\n</t>\n<z>\n</z>\n<x>\n</x>\n<p>\n</p>\n<u>\n</u>" }, { "input": "<c><l><i><h><z></z></h><y><k></k><o></o></y></i><a></a><x></x></l><r><y></y><k><s></s></k></r><j><a><f></f></a></j><h></h><p></p></c><h></h>", "output": "<c>\n <l>\n <i>\n <h>\n <z>\n </z>\n </h>\n <y>\n <k>\n </k>\n <o>\n </o>\n </y>\n </i>\n <a>\n </a>\n <x>\n </x>\n </l>\n <r>\n <y>\n </y>\n <k>\n <s>\n </s>\n </k>\n </r>\n <j>\n <a>\n <f>\n </f>\n </a>\n </j>\n <h>\n </h>\n <p>\n </p>\n</c>\n<h>\n</h>" }, { "input": "<p><q><l></l><q><k><r><n></n></r></k></q></q><x><z></z><r><k></k></r><h></h></x><c><p></p><o></o></c><n></n><c></c></p><b><c><z></z></c><u><u><f><a><d></d><q></q></a><x><i></i></x><r></r></f></u></u></b><j></j>", "output": "<p>\n <q>\n <l>\n </l>\n <q>\n <k>\n <r>\n <n>\n </n>\n </r>\n </k>\n </q>\n </q>\n <x>\n <z>\n </z>\n <r>\n <k>\n </k>\n </r>\n <h>\n </h>\n </x>\n <c>\n <p>\n </p>\n <o>\n </o>\n </c>\n <n>\n </n>\n <c>\n </c>\n</p>\n<b>\n <c>\n <z>\n </z>\n </c>\n <u>\n <u>\n <f>\n <a>\n <d>\n </d>\n <q>\n </q>\n </a>\n <x>\n <i>\n ..." }, { "input": "<w><q><x></x></q><r></r><o></o><u></u><o></o></w><d><z></z><n><x></x></n><y></y><s></s><k></k><q></q><a></a></d><h><u></u><s></s><y></y><t></t><f></f></h><v><w><q></q></w><s></s><h></h></v><q><o></o><k></k><w></w></q><c></c><p><j></j></p><c><u></u></c><s></s><x></x><b></b><i></i>", "output": "<w>\n <q>\n <x>\n </x>\n </q>\n <r>\n </r>\n <o>\n </o>\n <u>\n </u>\n <o>\n </o>\n</w>\n<d>\n <z>\n </z>\n <n>\n <x>\n </x>\n </n>\n <y>\n </y>\n <s>\n </s>\n <k>\n </k>\n <q>\n </q>\n <a>\n </a>\n</d>\n<h>\n <u>\n </u>\n <s>\n </s>\n <y>\n </y>\n <t>\n </t>\n <f>\n </f>\n</h>\n<v>\n <w>\n <q>\n </q>\n </w>\n <s>\n </s>\n <h>\n </h>\n</v>\n<q>\n <o>\n </o>\n <k>\n </k>\n <w>\n </w>\n</q>\n<c>\n</c>\n<p>\n <j>\n </j>\n</p>\n<c>\n <u>\n </u..." }, { "input": "<g><t><m><x><f><w><z><b><d><j></j><g><z></z><q><l><j></j><l><k></k><l><n><d></d><m></m></n></l><i><m><j></j></m></i></l></l><w><t><h><r><h></h><b></b></r></h></t><d><j></j></d><x><w><r><s><s></s></s></r></w><x></x></x></w><m><m><d></d><x><r><x><o><v></v><d><n></n></d></o></x></r></x></m></m></q></g><y></y></d></b></z></w></f></x><a></a></m></t></g>", "output": "<g>\n <t>\n <m>\n <x>\n <f>\n <w>\n <z>\n <b>\n <d>\n <j>\n </j>\n <g>\n <z>\n </z>\n <q>\n <l>\n <j>\n </j>\n <l>\n <k>\n </k>\n <l>\n <n>\n ..." }, { "input": "<d><d><w><v><g><m></m></g><b><u></u><j><h><n><q><q><c></c></q></q></n></h><c></c><l><r><l></l><b><d></d><x><k><o><w><q><x></x></q></w></o></k><p></p></x><g><m></m></g></b></r></l></j><k><l></l></k><c><v><g><p><p><d><e><z><x></x></z></e><v></v></d><u><o><u></u><k></k></o></u><m><x><h><z><f></f></z></h></x><w></w></m></p></p></g></v><t><n><u><b><h></h></b></u><r><m><k><z></z></k></m><j><e><w><s></s><e><s><p></p><o></o></s><g></g></e><u></u></w></e></j></r></n></t></c></b></v></w></d></d>", "output": "<d>\n <d>\n <w>\n <v>\n <g>\n <m>\n </m>\n </g>\n <b>\n <u>\n </u>\n <j>\n <h>\n <n>\n <q>\n <q>\n <c>\n </c>\n </q>\n </q>\n </n>\n </h>\n <c>\n </c>\n <l>\n <r>\n <l>\n </l>\n <b>\n ..." } ]
1,604,587,564
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
184
0
a = input().split('>') bal = 0 for s in a: if len(s): continue if (s[1] == '/' ): print(bal * " " + s+ ">") bal -= 1 else: print(bal * " " + s + ">") bal +=1
Title: Simple XML Time Limit: None seconds Memory Limit: None megabytes Problem Description: Let's define a string &lt;x&gt; as an opening tag, where *x* is any small letter of the Latin alphabet. Each opening tag matches a closing tag of the type &lt;/x&gt;, where *x* is the same letter. Tegs can be nested into each other: in this case one opening and closing tag pair is located inside another pair. Let's define the notion of a XML-text: - an empty string is a XML-text - if *s* is a XML-text, then *s*'=&lt;a&gt;+*s*+&lt;/a&gt; also is a XML-text, where *a* is any small Latin letter - if *s*1, *s*2 are XML-texts, then *s*1+*s*2 also is a XML-text You are given a XML-text (it is guaranteed that the text is valid), your task is to print in the following form: - each tag (opening and closing) is located on a single line - print before the tag 2<=*<=*h* spaces, where *h* is the level of the tag's nestedness. Input Specification: The input data consists on the only non-empty string — the XML-text, its length does not exceed 1000 characters. It is guaranteed that the text is valid. The text contains no spaces. Output Specification: Print the given XML-text according to the above-given rules. Demo Input: ['&lt;a&gt;&lt;b&gt;&lt;c&gt;&lt;/c&gt;&lt;/b&gt;&lt;/a&gt;\n', '&lt;a&gt;&lt;b&gt;&lt;/b&gt;&lt;d&gt;&lt;c&gt;&lt;/c&gt;&lt;/d&gt;&lt;/a&gt;\n'] Demo Output: ['&lt;a&gt;\n &lt;b&gt;\n &lt;c&gt;\n &lt;/c&gt;\n &lt;/b&gt;\n&lt;/a&gt;\n', '&lt;a&gt;\n &lt;b&gt;\n &lt;/b&gt;\n &lt;d&gt;\n &lt;c&gt;\n &lt;/c&gt;\n &lt;/d&gt;\n&lt;/a&gt;\n'] Note: none
```python a = input().split('>') bal = 0 for s in a: if len(s): continue if (s[1] == '/' ): print(bal * " " + s+ ">") bal -= 1 else: print(bal * " " + s + ">") bal +=1 ```
-1
347
B
Fixed Points
PROGRAMMING
1,100
[ "brute force", "implementation", "math" ]
null
null
A permutation of length *n* is an integer sequence such that each integer from 0 to (*n*<=-<=1) appears exactly once in it. For example, sequence [0,<=2,<=1] is a permutation of length 3 while both [0,<=2,<=2] and [1,<=2,<=3] are not. A fixed point of a function is a point that is mapped to itself by the function. A permutation can be regarded as a bijective function. We'll get a definition of a fixed point in a permutation. An integer *i* is a fixed point of permutation *a*0,<=*a*1,<=...,<=*a**n*<=-<=1 if and only if *a**i*<==<=*i*. For example, permutation [0,<=2,<=1] has 1 fixed point and permutation [0,<=1,<=2] has 3 fixed points. You are given permutation *a*. You are allowed to swap two elements of the permutation at most once. Your task is to maximize the number of fixed points in the resulting permutation. Note that you are allowed to make at most one swap operation.
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105). The second line contains *n* integers *a*0,<=*a*1,<=...,<=*a**n*<=-<=1 — the given permutation.
Print a single integer — the maximum possible number of fixed points in the permutation after at most one swap operation.
[ "5\n0 1 3 4 2\n" ]
[ "3\n" ]
none
1,000
[ { "input": "5\n0 1 3 4 2", "output": "3" }, { "input": "10\n6 9 4 7 8 2 3 5 0 1", "output": "2" }, { "input": "100\n99 5 40 32 4 31 38 57 94 47 26 16 89 72 9 80 55 86 78 90 42 41 46 74 56 97 21 48 66 27 93 85 88 59 64 95 10 45 12 22 84 60 8 98 62 51 14 65 39 30 11 71 92 19 76 43 87 54 15 53 37 6 25 18 96 35 13 91 2 3 0 23 1 7 49 75 81 33 50 52 63 44 69 36 17 61 24 20 68 34 73 29 70 83 58 79 82 28 77 67", "output": "3" }, { "input": "3\n0 1 2", "output": "3" }, { "input": "3\n2 1 0", "output": "3" }, { "input": "3\n1 2 0", "output": "1" }, { "input": "1\n0", "output": "1" }, { "input": "5\n0 1 2 3 4", "output": "5" }, { "input": "4\n0 1 2 3", "output": "4" }, { "input": "7\n0 1 2 4 3 6 5", "output": "5" }, { "input": "6\n0 1 2 3 5 4", "output": "6" } ]
1,623,826,070
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
1
186
0
# B. Fixed Points n=int(input()) a=list(map(int,input().split())) c=0 e=[] for i in range(n): if i==a[i]: c+=1 else: e.append([a[i],i]) if c==n-2: print(n) else: f=0 for i in e: if i[::-1] in e: c+=n-2 f=1 print(c) break if f==0: print(c+1)
Title: Fixed Points Time Limit: None seconds Memory Limit: None megabytes Problem Description: A permutation of length *n* is an integer sequence such that each integer from 0 to (*n*<=-<=1) appears exactly once in it. For example, sequence [0,<=2,<=1] is a permutation of length 3 while both [0,<=2,<=2] and [1,<=2,<=3] are not. A fixed point of a function is a point that is mapped to itself by the function. A permutation can be regarded as a bijective function. We'll get a definition of a fixed point in a permutation. An integer *i* is a fixed point of permutation *a*0,<=*a*1,<=...,<=*a**n*<=-<=1 if and only if *a**i*<==<=*i*. For example, permutation [0,<=2,<=1] has 1 fixed point and permutation [0,<=1,<=2] has 3 fixed points. You are given permutation *a*. You are allowed to swap two elements of the permutation at most once. Your task is to maximize the number of fixed points in the resulting permutation. Note that you are allowed to make at most one swap operation. Input Specification: The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105). The second line contains *n* integers *a*0,<=*a*1,<=...,<=*a**n*<=-<=1 — the given permutation. Output Specification: Print a single integer — the maximum possible number of fixed points in the permutation after at most one swap operation. Demo Input: ['5\n0 1 3 4 2\n'] Demo Output: ['3\n'] Note: none
```python # B. Fixed Points n=int(input()) a=list(map(int,input().split())) c=0 e=[] for i in range(n): if i==a[i]: c+=1 else: e.append([a[i],i]) if c==n-2: print(n) else: f=0 for i in e: if i[::-1] in e: c+=n-2 f=1 print(c) break if f==0: print(c+1) ```
0
185
B
Mushroom Scientists
PROGRAMMING
1,800
[ "math", "ternary search" ]
null
null
As you very well know, the whole Universe traditionally uses three-dimensional Cartesian system of coordinates. In this system each point corresponds to three real coordinates (*x*,<=*y*,<=*z*). In this coordinate system, the distance between the center of the Universe and the point is calculated by the following formula: . Mushroom scientists that work for the Great Mushroom King think that the Universe isn't exactly right and the distance from the center of the Universe to a point equals *x**a*·*y**b*·*z**c*. To test the metric of mushroom scientists, the usual scientists offered them a task: find such *x*,<=*y*,<=*z* (0<=≤<=*x*,<=*y*,<=*z*; *x*<=+<=*y*<=+<=*z*<=≤<=*S*), that the distance between the center of the Universe and the point (*x*,<=*y*,<=*z*) is maximum possible in the metric of mushroom scientists. The mushroom scientists aren't good at maths, so they commissioned you to do the task. Note that in this problem, it is considered that 00<==<=1.
The first line contains a single integer *S* (1<=≤<=*S*<=≤<=103) — the maximum sum of coordinates of the sought point. The second line contains three space-separated integers *a*, *b*, *c* (0<=≤<=*a*,<=*b*,<=*c*<=≤<=103) — the numbers that describe the metric of mushroom scientists.
Print three real numbers — the coordinates of the point that reaches maximum value in the metrics of mushroom scientists. If there are multiple answers, print any of them that meets the limitations. A natural logarithm of distance from the center of the Universe to the given point in the metric of mushroom scientists shouldn't differ from the natural logarithm of the maximum distance by more than 10<=-<=6. We think that *ln*(0)<==<=<=-<=∞.
[ "3\n1 1 1\n", "3\n2 0 0\n" ]
[ "1.0 1.0 1.0\n", "3.0 0.0 0.0\n" ]
none
1,000
[ { "input": "3\n1 1 1", "output": "1.0 1.0 1.0" }, { "input": "3\n2 0 0", "output": "3.0 0.0 0.0" }, { "input": "10\n1 6 3", "output": "1.0 6.0 3.0" }, { "input": "9\n8 2 0", "output": "7.2 1.8 0.0" }, { "input": "1\n0 9 2", "output": "0.0 0.8181818181818182 0.18181818181818182" }, { "input": "1\n3 5 1", "output": "0.3333333333333333 0.5555555555555556 0.1111111111111111" }, { "input": "7\n8 2 2", "output": "4.666666666666667 1.1666666666666667 1.1666666666666667" }, { "input": "9\n3 7 0", "output": "2.7 6.3 0.0" }, { "input": "1000\n0 0 0", "output": "0 0 0" }, { "input": "624\n553 828 109", "output": "231.59194630872483 346.7597315436242 45.64832214765101" }, { "input": "902\n742 737 340", "output": "367.9406267179769 365.4612424409016 168.5981308411215" }, { "input": "239\n995 385 267", "output": "144.3867638129933 55.8682452944748 38.744990892531874" }, { "input": "797\n917 702 538", "output": "338.82661103384334 259.3852573018081 198.78813166434864" }, { "input": "938\n414 308 795", "output": "255.98681608437707 190.44429795649307 491.5688859591299" }, { "input": "422\n215 779 900", "output": "47.903907074973596 173.56810982048574 200.52798310454065" }, { "input": "413\n569 138 159", "output": "271.35912240184757 65.81293302540415 75.82794457274827" }, { "input": "188\n748 859 686", "output": "61.327518534670745 70.42825992150023 56.24422154382905" }, { "input": "48\n395 552 466", "output": "13.418259023354565 18.751592356687897 15.830148619957537" }, { "input": "492\n971 305 807", "output": "229.34805568891022 72.04032645223235 190.61161785885741" }, { "input": "557\n84 654 154", "output": "52.45291479820627 408.3834080717489 96.16367713004483" }, { "input": "699\n493 285 659", "output": "239.8100208768267 138.63256784968684 320.5574112734864" }, { "input": "814\n711 408 545", "output": "347.8088942307692 199.58653846153845 266.6045673076923" }, { "input": "706\n197 265 571", "output": "134.63891577928362 181.11326234269117 390.24782187802515" }, { "input": "945\n123 67 174", "output": "319.3269230769231 173.9423076923077 451.7307692307692" }, { "input": "724\n529 558 407", "output": "256.3560910307898 270.4096385542168 197.2342704149933" }, { "input": "269\n0 623 873", "output": "0.0 112.02339572192513 156.97660427807486" }, { "input": "173\n0 0 374", "output": "0.0 0.0 173.0" }, { "input": "972\n918 0 405", "output": "674.4489795918367 0.0 297.55102040816325" }, { "input": "809\n328 0 0", "output": "809.0 0.0 0.0" }, { "input": "413\n517 0 0", "output": "413.0 0.0 0.0" }, { "input": "642\n0 665 0", "output": "0.0 642.0 0.0" }, { "input": "1000\n117 403 270", "output": "148.10126582278482 510.12658227848107 341.7721518987342" }, { "input": "1000\n1000 1000 1000", "output": "333.3333333333333 333.3333333333333 333.3333333333333" }, { "input": "1\n1000 1000 1000", "output": "0.3333333333333333 0.3333333333333333 0.3333333333333333" }, { "input": "1000\n1 0 1", "output": "500.0 0.0 500.0" }, { "input": "1000\n0 1 1", "output": "0.0 500.0 500.0" }, { "input": "1000\n1 1 0", "output": "500.0 500.0 0.0" }, { "input": "1000\n0 0 1", "output": "0.0 0.0 1000.0" }, { "input": "1000\n1 0 0", "output": "1000.0 0.0 0.0" }, { "input": "1000\n0 1 0", "output": "0.0 1000.0 0.0" }, { "input": "1000\n999 1000 999", "output": "333.2221480987325 333.555703802535 333.2221480987325" }, { "input": "1000\n999 998 997", "output": "333.6673346693387 333.33333333333337 332.999331997328" }, { "input": "3\n0 0 0", "output": "0 0 0" }, { "input": "100\n0 0 0", "output": "0 0 0" }, { "input": "1\n0 0 0", "output": "0 0 0" }, { "input": "239\n0 0 0", "output": "0 0 0" }, { "input": "10\n0 0 0", "output": "0 0 0" }, { "input": "1000\n197 198 199", "output": "331.6498316498317 333.33333333333337 335.01683501683505" }, { "input": "5\n0 0 0", "output": "0 0 0" }, { "input": "1000\n0 0 0", "output": "0 0 0" }, { "input": "1000\n0 1 999", "output": "0.0 1.0 999.0" }, { "input": "1000\n1000 0 0", "output": "1000.0 0.0 0.0" } ]
1,637,613,187
2,147,483,647
PyPy 3
RUNTIME_ERROR
TESTS
9
248
2,150,400
def f1(x,y,a,b,c,s): return x**a*y**b*(s-x-y)**c def f2(x,a,b,c,s): l,r=0,s-x while r-l>10**-10: m1,m2=l+(r-l)/3,r-(r-l)/3 if f1(x,m1,a,b,c,s)>f1(x,m2,a,b,c,s): r=m2 else: l=m1 return r def f3(a,b,c,s): l,r=0,s while r-l>10**-10: m1,m2=l+(r-l)/3,r-(r-l)/3 if f1(m1,f2(m1,a,b,c,s),a,b,c,s)>f1(m2,f2(m2,a,b,c,s),a,b,c,s): r=m2 else: l=m1 return r s=float(input()) a,b,c=list(map(int,input().split())) print("%.10f %.10f %.10f"%(f3(a,b,c,s),f2(f3(a,b,c,s),a,b,c,s),s-f3(a,b,c,s)-f2(f3(a,b,c,s),a,b,c,s)))
Title: Mushroom Scientists Time Limit: None seconds Memory Limit: None megabytes Problem Description: As you very well know, the whole Universe traditionally uses three-dimensional Cartesian system of coordinates. In this system each point corresponds to three real coordinates (*x*,<=*y*,<=*z*). In this coordinate system, the distance between the center of the Universe and the point is calculated by the following formula: . Mushroom scientists that work for the Great Mushroom King think that the Universe isn't exactly right and the distance from the center of the Universe to a point equals *x**a*·*y**b*·*z**c*. To test the metric of mushroom scientists, the usual scientists offered them a task: find such *x*,<=*y*,<=*z* (0<=≤<=*x*,<=*y*,<=*z*; *x*<=+<=*y*<=+<=*z*<=≤<=*S*), that the distance between the center of the Universe and the point (*x*,<=*y*,<=*z*) is maximum possible in the metric of mushroom scientists. The mushroom scientists aren't good at maths, so they commissioned you to do the task. Note that in this problem, it is considered that 00<==<=1. Input Specification: The first line contains a single integer *S* (1<=≤<=*S*<=≤<=103) — the maximum sum of coordinates of the sought point. The second line contains three space-separated integers *a*, *b*, *c* (0<=≤<=*a*,<=*b*,<=*c*<=≤<=103) — the numbers that describe the metric of mushroom scientists. Output Specification: Print three real numbers — the coordinates of the point that reaches maximum value in the metrics of mushroom scientists. If there are multiple answers, print any of them that meets the limitations. A natural logarithm of distance from the center of the Universe to the given point in the metric of mushroom scientists shouldn't differ from the natural logarithm of the maximum distance by more than 10<=-<=6. We think that *ln*(0)<==<=<=-<=∞. Demo Input: ['3\n1 1 1\n', '3\n2 0 0\n'] Demo Output: ['1.0 1.0 1.0\n', '3.0 0.0 0.0\n'] Note: none
```python def f1(x,y,a,b,c,s): return x**a*y**b*(s-x-y)**c def f2(x,a,b,c,s): l,r=0,s-x while r-l>10**-10: m1,m2=l+(r-l)/3,r-(r-l)/3 if f1(x,m1,a,b,c,s)>f1(x,m2,a,b,c,s): r=m2 else: l=m1 return r def f3(a,b,c,s): l,r=0,s while r-l>10**-10: m1,m2=l+(r-l)/3,r-(r-l)/3 if f1(m1,f2(m1,a,b,c,s),a,b,c,s)>f1(m2,f2(m2,a,b,c,s),a,b,c,s): r=m2 else: l=m1 return r s=float(input()) a,b,c=list(map(int,input().split())) print("%.10f %.10f %.10f"%(f3(a,b,c,s),f2(f3(a,b,c,s),a,b,c,s),s-f3(a,b,c,s)-f2(f3(a,b,c,s),a,b,c,s))) ```
-1
540
A
Combination Lock
PROGRAMMING
800
[ "implementation" ]
null
null
Scrooge McDuck keeps his most treasured savings in a home safe with a combination lock. Each time he wants to put there the treasures that he's earned fair and square, he has to open the lock. The combination lock is represented by *n* rotating disks with digits from 0 to 9 written on them. Scrooge McDuck has to turn some disks so that the combination of digits on the disks forms a secret combination. In one move, he can rotate one disk one digit forwards or backwards. In particular, in one move he can go from digit 0 to digit 9 and vice versa. What minimum number of actions does he need for that?
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of disks on the combination lock. The second line contains a string of *n* digits — the original state of the disks. The third line contains a string of *n* digits — Scrooge McDuck's combination that opens the lock.
Print a single integer — the minimum number of moves Scrooge McDuck needs to open the lock.
[ "5\n82195\n64723\n" ]
[ "13\n" ]
In the sample he needs 13 moves: - 1 disk: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/b8967f65a723782358b93eff9ce69f336817cf70.png" style="max-width: 100.0%;max-height: 100.0%;"/> - 2 disk: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/07fa58573ece0d32c4d555e498d2b24d2f70f36a.png" style="max-width: 100.0%;max-height: 100.0%;"/> - 3 disk: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/cc2275d9252aae35a6867c6a5b4ba7596e9a7626.png" style="max-width: 100.0%;max-height: 100.0%;"/> - 4 disk: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/b100aea470fcaaab4e9529b234ba0d7875943c10.png" style="max-width: 100.0%;max-height: 100.0%;"/> - 5 disk: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/eb2cbe4324cebca65b85816262a85e473cd65967.png" style="max-width: 100.0%;max-height: 100.0%;"/>
500
[ { "input": "5\n82195\n64723", "output": "13" }, { "input": "12\n102021090898\n010212908089", "output": "16" }, { "input": "1\n8\n1", "output": "3" }, { "input": "2\n83\n57", "output": "7" }, { "input": "10\n0728592530\n1362615763", "output": "27" }, { "input": "100\n4176196363694273682807653052945037727131821799902563705176501742060696655282954944720643131654235909\n3459912084922154505910287499879975659298239371519889866585472674423008837878123067103005344986554746", "output": "245" }, { "input": "1\n8\n1", "output": "3" }, { "input": "2\n83\n57", "output": "7" }, { "input": "3\n607\n684", "output": "5" }, { "input": "4\n0809\n0636", "output": "8" }, { "input": "5\n84284\n08941", "output": "16" }, { "input": "25\n8037856825987124762280548\n9519431339078678836940020", "output": "72" }, { "input": "125\n23269567683904664184142384849516523616863461607751021071772615078579713054027902974007001544768640273491193035874486891541257\n47635110303703399505805044019026243695451609639556649012447370081552870340011971572363458960190590266459684717415349529509024", "output": "305" }, { "input": "5\n84284\n08941", "output": "16" }, { "input": "25\n8037856825987124762285484\n9519431339078678836940202", "output": "74" }, { "input": "125\n23269567689466418414238845152168634610771021717726157879713054270294007001544768647391193035874486891412573389247025830678706\n47635110307339950580504010224954516093956649124473708152870340117152363458960190596659684717415349529090241694059599629136831", "output": "357" }, { "input": "5\n84284\n08941", "output": "16" }, { "input": "25\n8378525987476228048406972\n9194339078883694020217816", "output": "55" }, { "input": "125\n23269576839046618414238484916523616863461607750210717761078579713054027902974007015447686027349193035874486891541257338624472\n47635103037033950580504401926243695451609639556490124437081552870340011971572363489601905026645984717415349529509024169604599", "output": "274" }, { "input": "1\n0\n0", "output": "0" }, { "input": "1\n7\n7", "output": "0" }, { "input": "1\n0\n5", "output": "5" }, { "input": "1\n2\n7", "output": "5" }, { "input": "1\n7\n9", "output": "2" }, { "input": "1\n9\n7", "output": "2" }, { "input": "1\n2\n9", "output": "3" }, { "input": "1\n9\n2", "output": "3" }, { "input": "25\n3164978461316464614169874\n9413979197249127496597357", "output": "66" }, { "input": "4\n9999\n9999", "output": "0" }, { "input": "2\n11\n11", "output": "0" } ]
1,643,112,512
2,147,483,647
Python 3
COMPILATION_ERROR
TESTS
0
0
0
n=int(input()) c=0 for i in range(n): a=input() b=input() c+=min(10-abs(a[i]-b[i]),a[i]-b[i] print(c)
Title: Combination Lock Time Limit: None seconds Memory Limit: None megabytes Problem Description: Scrooge McDuck keeps his most treasured savings in a home safe with a combination lock. Each time he wants to put there the treasures that he's earned fair and square, he has to open the lock. The combination lock is represented by *n* rotating disks with digits from 0 to 9 written on them. Scrooge McDuck has to turn some disks so that the combination of digits on the disks forms a secret combination. In one move, he can rotate one disk one digit forwards or backwards. In particular, in one move he can go from digit 0 to digit 9 and vice versa. What minimum number of actions does he need for that? Input Specification: The first line contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of disks on the combination lock. The second line contains a string of *n* digits — the original state of the disks. The third line contains a string of *n* digits — Scrooge McDuck's combination that opens the lock. Output Specification: Print a single integer — the minimum number of moves Scrooge McDuck needs to open the lock. Demo Input: ['5\n82195\n64723\n'] Demo Output: ['13\n'] Note: In the sample he needs 13 moves: - 1 disk: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/b8967f65a723782358b93eff9ce69f336817cf70.png" style="max-width: 100.0%;max-height: 100.0%;"/> - 2 disk: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/07fa58573ece0d32c4d555e498d2b24d2f70f36a.png" style="max-width: 100.0%;max-height: 100.0%;"/> - 3 disk: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/cc2275d9252aae35a6867c6a5b4ba7596e9a7626.png" style="max-width: 100.0%;max-height: 100.0%;"/> - 4 disk: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/b100aea470fcaaab4e9529b234ba0d7875943c10.png" style="max-width: 100.0%;max-height: 100.0%;"/> - 5 disk: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/eb2cbe4324cebca65b85816262a85e473cd65967.png" style="max-width: 100.0%;max-height: 100.0%;"/>
```python n=int(input()) c=0 for i in range(n): a=input() b=input() c+=min(10-abs(a[i]-b[i]),a[i]-b[i] print(c) ```
-1
884
B
Japanese Crosswords Strike Back
PROGRAMMING
1,100
[ "implementation" ]
null
null
A one-dimensional Japanese crossword can be represented as a binary string of length *x*. An encoding of this crossword is an array *a* of size *n*, where *n* is the number of segments formed completely of 1's, and *a**i* is the length of *i*-th segment. No two segments touch or intersect. For example: - If *x*<==<=6 and the crossword is 111011, then its encoding is an array {3,<=2}; - If *x*<==<=8 and the crossword is 01101010, then its encoding is an array {2,<=1,<=1}; - If *x*<==<=5 and the crossword is 11111, then its encoding is an array {5}; - If *x*<==<=5 and the crossword is 00000, then its encoding is an empty array. Mishka wants to create a new one-dimensional Japanese crossword. He has already picked the length and the encoding for this crossword. And now he needs to check if there is exactly one crossword such that its length and encoding are equal to the length and encoding he picked. Help him to check it!
The first line contains two integer numbers *n* and *x* (1<=≤<=*n*<=≤<=100000, 1<=≤<=*x*<=≤<=109) — the number of elements in the encoding and the length of the crossword Mishka picked. The second line contains *n* integer numbers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=10000) — the encoding.
Print YES if there exists exaclty one crossword with chosen length and encoding. Otherwise, print NO.
[ "2 4\n1 3\n", "3 10\n3 3 2\n", "2 10\n1 3\n" ]
[ "NO\n", "YES\n", "NO\n" ]
none
0
[ { "input": "2 4\n1 3", "output": "NO" }, { "input": "3 10\n3 3 2", "output": "YES" }, { "input": "2 10\n1 3", "output": "NO" }, { "input": "1 1\n1", "output": "YES" }, { "input": "1 10\n10", "output": "YES" }, { "input": "1 10000\n10000", "output": "YES" }, { "input": "10 1\n5 78 3 87 4 9 5 8 9 1235", "output": "NO" }, { "input": "3 12\n3 3 3", "output": "NO" }, { "input": "3 9\n2 2 2", "output": "NO" }, { "input": "2 5\n1 1", "output": "NO" }, { "input": "1 2\n1", "output": "NO" }, { "input": "3 13\n3 3 3", "output": "NO" }, { "input": "3 6\n1 1 1", "output": "NO" }, { "input": "1 6\n5", "output": "NO" }, { "input": "3 11\n3 3 2", "output": "NO" }, { "input": "2 6\n1 3", "output": "NO" }, { "input": "3 10\n2 2 2", "output": "NO" }, { "input": "3 8\n2 1 1", "output": "NO" }, { "input": "1 5\n2", "output": "NO" }, { "input": "1 3\n1", "output": "NO" }, { "input": "5 5\n1 1 1 1 1", "output": "NO" }, { "input": "2 10\n4 4", "output": "NO" }, { "input": "2 8\n2 3", "output": "NO" }, { "input": "2 4\n1 1", "output": "NO" }, { "input": "3 10\n1 2 4", "output": "NO" }, { "input": "3 10\n2 1 3", "output": "NO" }, { "input": "2 6\n1 2", "output": "NO" }, { "input": "3 4\n1 1 1", "output": "NO" }, { "input": "3 11\n1 2 4", "output": "NO" }, { "input": "3 12\n3 3 2", "output": "NO" }, { "input": "4 9\n1 1 1 1", "output": "NO" }, { "input": "1 10\n9", "output": "NO" }, { "input": "1 7\n5", "output": "NO" }, { "input": "2 5\n1 2", "output": "NO" }, { "input": "3 8\n1 1 2", "output": "NO" }, { "input": "3 7\n1 1 1", "output": "NO" }, { "input": "1 10\n1", "output": "NO" }, { "input": "3 10\n2 3 4", "output": "NO" }, { "input": "3 9\n1 2 3", "output": "NO" }, { "input": "3 9\n3 3 2", "output": "NO" }, { "input": "3 6\n3 3 2", "output": "NO" }, { "input": "1 1\n3", "output": "NO" }, { "input": "1 3\n2", "output": "NO" }, { "input": "3 10\n3 3 3", "output": "NO" }, { "input": "3 5\n1 1 1", "output": "YES" }, { "input": "2 1\n100 100", "output": "NO" }, { "input": "3 3\n3 3 3", "output": "NO" }, { "input": "4 17\n3 3 9 1", "output": "NO" }, { "input": "4 1660\n1505 13 37 100", "output": "NO" }, { "input": "3 5\n3 3 2", "output": "NO" }, { "input": "4 10\n3 3 2 5", "output": "NO" }, { "input": "5 5\n5 5 5 5 5", "output": "NO" }, { "input": "1 1\n2", "output": "NO" }, { "input": "5 10\n1 2 2 4 5", "output": "NO" }, { "input": "2 1\n1 1", "output": "NO" } ]
1,630,333,333
2,147,483,647
Python 3
OK
TESTS
66
93
14,438,400
R=lambda:list(map(int,input().split())) n,x=R() print('YES'if sum(R())+n-1==x else'NO')
Title: Japanese Crosswords Strike Back Time Limit: None seconds Memory Limit: None megabytes Problem Description: A one-dimensional Japanese crossword can be represented as a binary string of length *x*. An encoding of this crossword is an array *a* of size *n*, where *n* is the number of segments formed completely of 1's, and *a**i* is the length of *i*-th segment. No two segments touch or intersect. For example: - If *x*<==<=6 and the crossword is 111011, then its encoding is an array {3,<=2}; - If *x*<==<=8 and the crossword is 01101010, then its encoding is an array {2,<=1,<=1}; - If *x*<==<=5 and the crossword is 11111, then its encoding is an array {5}; - If *x*<==<=5 and the crossword is 00000, then its encoding is an empty array. Mishka wants to create a new one-dimensional Japanese crossword. He has already picked the length and the encoding for this crossword. And now he needs to check if there is exactly one crossword such that its length and encoding are equal to the length and encoding he picked. Help him to check it! Input Specification: The first line contains two integer numbers *n* and *x* (1<=≤<=*n*<=≤<=100000, 1<=≤<=*x*<=≤<=109) — the number of elements in the encoding and the length of the crossword Mishka picked. The second line contains *n* integer numbers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=10000) — the encoding. Output Specification: Print YES if there exists exaclty one crossword with chosen length and encoding. Otherwise, print NO. Demo Input: ['2 4\n1 3\n', '3 10\n3 3 2\n', '2 10\n1 3\n'] Demo Output: ['NO\n', 'YES\n', 'NO\n'] Note: none
```python R=lambda:list(map(int,input().split())) n,x=R() print('YES'if sum(R())+n-1==x else'NO') ```
3
120
A
Elevator
PROGRAMMING
1,000
[ "brute force", "implementation", "math" ]
null
null
A sky scraper with 1000 floors has been built in the city of N. It has modern superfast elevators to help to travel from one floor to another. Each elevator has two doors, the front one and the back one. If one goes in through the front door, he goes out through the back one and vice versa. The elevator has two rails numbered with numbers 1 and 2. Rail 1 is located to the left of the entrance to the front door (or correspondingly, to the right of the entrance to the back door). Rail 2 is located opposite it, to the right of the entrance to the front door and to the left of the entrance to the back door. We know that each person in the city of N holds at a rail with the strongest hand. One day a VIP person visited the city and of course, he took a look at the skyscraper and took a ride in the elevator. We know the door through which he entered and the rail he was holding at. Now we need to determine as soon as possible whether he is left-handed or right-handed.
The first line indicates the door through which the very important person entered the elevator. It contains "front" if the person enters the elevator through the front door and "back" if he entered the elevator through the back door. The second line contains integer *a* (1<=≤<=*a*<=≤<=2) which denotes the number of the rail at which the person was holding.
Print character "R" if the VIP is right-handed or "L" if he is left-handed.
[ "front\n1\n" ]
[ "L\n" ]
none
0
[ { "input": "front\n1", "output": "L" }, { "input": "back\n1", "output": "R" }, { "input": "front\n2", "output": "R" }, { "input": "back\n2", "output": "L" } ]
1,691,386,571
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
30
0
x= input() y = int(input()) if ( x == "back" and y == 1) or (x == "front" and y == 2) : print("R") else: print("L")
Title: Elevator Time Limit: None seconds Memory Limit: None megabytes Problem Description: A sky scraper with 1000 floors has been built in the city of N. It has modern superfast elevators to help to travel from one floor to another. Each elevator has two doors, the front one and the back one. If one goes in through the front door, he goes out through the back one and vice versa. The elevator has two rails numbered with numbers 1 and 2. Rail 1 is located to the left of the entrance to the front door (or correspondingly, to the right of the entrance to the back door). Rail 2 is located opposite it, to the right of the entrance to the front door and to the left of the entrance to the back door. We know that each person in the city of N holds at a rail with the strongest hand. One day a VIP person visited the city and of course, he took a look at the skyscraper and took a ride in the elevator. We know the door through which he entered and the rail he was holding at. Now we need to determine as soon as possible whether he is left-handed or right-handed. Input Specification: The first line indicates the door through which the very important person entered the elevator. It contains "front" if the person enters the elevator through the front door and "back" if he entered the elevator through the back door. The second line contains integer *a* (1<=≤<=*a*<=≤<=2) which denotes the number of the rail at which the person was holding. Output Specification: Print character "R" if the VIP is right-handed or "L" if he is left-handed. Demo Input: ['front\n1\n'] Demo Output: ['L\n'] Note: none
```python x= input() y = int(input()) if ( x == "back" and y == 1) or (x == "front" and y == 2) : print("R") else: print("L") ```
-1
16
A
Flag
PROGRAMMING
800
[ "implementation" ]
A. Flag
2
64
According to a new ISO standard, a flag of every country should have a chequered field *n*<=×<=*m*, each square should be of one of 10 colours, and the flag should be «striped»: each horizontal row of the flag should contain squares of the same colour, and the colours of adjacent horizontal rows should be different. Berland's government asked you to find out whether their flag meets the new ISO standard.
The first line of the input contains numbers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100), *n* — the amount of rows, *m* — the amount of columns on the flag of Berland. Then there follows the description of the flag: each of the following *n* lines contain *m* characters. Each character is a digit between 0 and 9, and stands for the colour of the corresponding square.
Output YES, if the flag meets the new ISO standard, and NO otherwise.
[ "3 3\n000\n111\n222\n", "3 3\n000\n000\n111\n", "3 3\n000\n111\n002\n" ]
[ "YES\n", "NO\n", "NO\n" ]
none
0
[ { "input": "3 3\n000\n111\n222", "output": "YES" }, { "input": "3 3\n000\n000\n111", "output": "NO" }, { "input": "3 3\n000\n111\n002", "output": "NO" }, { "input": "10 10\n2222222222\n5555555555\n0000000000\n4444444444\n1111111111\n3333333393\n3333333333\n5555555555\n0000000000\n8888888888", "output": "NO" }, { "input": "10 13\n4442444444444\n8888888888888\n6666666666666\n0000000000000\n3333333333333\n4444444444444\n7777777777777\n8388888888888\n1111111111111\n5555555555555", "output": "NO" }, { "input": "10 8\n33333333\n44444444\n11111115\n81888888\n44444444\n11111111\n66666666\n33330333\n33333333\n33333333", "output": "NO" }, { "input": "5 5\n88888\n44444\n66666\n55555\n88888", "output": "YES" }, { "input": "20 19\n1111111111111111111\n5555555555555555555\n0000000000000000000\n3333333333333333333\n1111111111111111111\n2222222222222222222\n4444444444444444444\n5555555555555555555\n0000000000000000000\n4444444444444444444\n0000000000000000000\n5555555555555555555\n7777777777777777777\n9999999999999999999\n2222222222222222222\n4444444444444444444\n1111111111111111111\n6666666666666666666\n7777777777777777777\n2222222222222222222", "output": "YES" }, { "input": "1 100\n8888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888", "output": "YES" }, { "input": "100 1\n5\n7\n9\n4\n7\n2\n5\n1\n6\n7\n2\n7\n6\n8\n7\n4\n0\n2\n9\n8\n9\n1\n6\n4\n3\n4\n7\n1\n9\n3\n0\n8\n3\n1\n7\n5\n3\n9\n5\n1\n3\n5\n8\n1\n9\n3\n9\n0\n6\n0\n7\n6\n5\n2\n8\n3\n7\n6\n5\n1\n8\n3\n6\n9\n6\n0\n5\n8\n5\n2\n9\n1\n0\n1\n8\n3\n2\n1\n0\n3\n9\n0\n5\n1\n0\n4\n9\n3\n0\n4\n8\n4\n8\n6\n3\n0\n4\n6\n8\n4", "output": "YES" }, { "input": "1 1\n2", "output": "YES" }, { "input": "1 100\n1111111111111111111111111111111111111111111111111111111111111111111111111111181111111111111111111111", "output": "NO" }, { "input": "100 1\n3\n6\n4\n3\n0\n2\n8\n7\n3\n2\n1\n7\n1\n3\n2\n3\n6\n9\n0\n8\n5\n9\n7\n9\n2\n1\n4\n5\n1\n9\n2\n5\n1\n4\n6\n4\n9\n1\n0\n2\n1\n4\n7\n1\n4\n8\n0\n9\n2\n1\n6\n2\n8\n6\n9\n5\n8\n6\n4\n5\n9\n2\n7\n4\n1\n5\n8\n0\n9\n5\n4\n6\n5\n0\n6\n3\n6\n9\n7\n2\n0\n9\n7\n3\n2\n4\n9\n4\n7\n1\n2\n3\n1\n7\n9\n1\n9\n0\n4\n0", "output": "YES" } ]
1,672,108,282
2,147,483,647
Python 3
OK
TESTS
35
92
0
n,m=map(int,input().split()) flag=True for run in range(n): s=input() new='' for ele in s: if ele not in new: new+=ele if len(new)>1: flag=False break if run==0: temp=s else: if s==temp: flag=False break else: temp=s if flag: print('YES') else: print('NO')
Title: Flag Time Limit: 2 seconds Memory Limit: 64 megabytes Problem Description: According to a new ISO standard, a flag of every country should have a chequered field *n*<=×<=*m*, each square should be of one of 10 colours, and the flag should be «striped»: each horizontal row of the flag should contain squares of the same colour, and the colours of adjacent horizontal rows should be different. Berland's government asked you to find out whether their flag meets the new ISO standard. Input Specification: The first line of the input contains numbers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100), *n* — the amount of rows, *m* — the amount of columns on the flag of Berland. Then there follows the description of the flag: each of the following *n* lines contain *m* characters. Each character is a digit between 0 and 9, and stands for the colour of the corresponding square. Output Specification: Output YES, if the flag meets the new ISO standard, and NO otherwise. Demo Input: ['3 3\n000\n111\n222\n', '3 3\n000\n000\n111\n', '3 3\n000\n111\n002\n'] Demo Output: ['YES\n', 'NO\n', 'NO\n'] Note: none
```python n,m=map(int,input().split()) flag=True for run in range(n): s=input() new='' for ele in s: if ele not in new: new+=ele if len(new)>1: flag=False break if run==0: temp=s else: if s==temp: flag=False break else: temp=s if flag: print('YES') else: print('NO') ```
3.977
137
B
Permutation
PROGRAMMING
1,000
[ "greedy" ]
null
null
"Hey, it's homework time" — thought Polycarpus and of course he started with his favourite subject, IT. Polycarpus managed to solve all tasks but for the last one in 20 minutes. However, as he failed to solve the last task after some considerable time, the boy asked you to help him. The sequence of *n* integers is called a permutation if it contains all integers from 1 to *n* exactly once. You are given an arbitrary sequence *a*1,<=*a*2,<=...,<=*a**n* containing *n* integers. Each integer is not less than 1 and not greater than 5000. Determine what minimum number of elements Polycarpus needs to change to get a permutation (he should not delete or add numbers). In a single change he can modify any single sequence element (i. e. replace it with another integer).
The first line of the input data contains an integer *n* (1<=≤<=*n*<=≤<=5000) which represents how many numbers are in the sequence. The second line contains a sequence of integers *a**i* (1<=≤<=*a**i*<=≤<=5000,<=1<=≤<=*i*<=≤<=*n*).
Print the only number — the minimum number of changes needed to get the permutation.
[ "3\n3 1 2\n", "2\n2 2\n", "5\n5 3 3 3 1\n" ]
[ "0\n", "1\n", "2\n" ]
The first sample contains the permutation, which is why no replacements are required. In the second sample it is enough to replace the first element with the number 1 and that will make the sequence the needed permutation. In the third sample we can replace the second element with number 4 and the fourth element with number 2.
1,000
[ { "input": "3\n3 1 2", "output": "0" }, { "input": "2\n2 2", "output": "1" }, { "input": "5\n5 3 3 3 1", "output": "2" }, { "input": "5\n6 6 6 6 6", "output": "5" }, { "input": "10\n1 1 2 2 8 8 7 7 9 9", "output": "5" }, { "input": "8\n9 8 7 6 5 4 3 2", "output": "1" }, { "input": "15\n1 2 3 4 5 5 4 3 2 1 1 2 3 4 5", "output": "10" }, { "input": "1\n1", "output": "0" }, { "input": "1\n5000", "output": "1" }, { "input": "4\n5000 5000 5000 5000", "output": "4" }, { "input": "5\n3366 3461 4 5 4370", "output": "3" }, { "input": "10\n8 2 10 3 4 6 1 7 9 5", "output": "0" }, { "input": "10\n551 3192 3213 2846 3068 1224 3447 1 10 9", "output": "7" }, { "input": "15\n4 1459 12 4281 3241 2748 10 3590 14 845 3518 1721 2 2880 1974", "output": "10" }, { "input": "15\n15 1 8 2 13 11 12 7 3 14 6 10 9 4 5", "output": "0" }, { "input": "15\n2436 2354 4259 1210 2037 2665 700 3578 2880 973 1317 1024 24 3621 4142", "output": "15" }, { "input": "30\n28 1 3449 9 3242 4735 26 3472 15 21 2698 7 4073 3190 10 3 29 1301 4526 22 345 3876 19 12 4562 2535 2 630 18 27", "output": "14" }, { "input": "100\n50 39 95 30 66 78 2169 4326 81 31 74 34 80 40 19 48 97 63 82 6 88 16 21 57 92 77 10 1213 17 93 32 91 38 4375 29 75 44 22 4 45 14 2395 3254 59 3379 2 85 96 8 83 27 94 1512 2960 100 9 73 79 7 25 55 69 90 99 51 87 98 62 18 35 43 4376 4668 28 72 56 4070 61 65 36 54 4106 11 24 15 86 70 71 4087 23 13 76 20 4694 26 4962 4726 37 14 64", "output": "18" }, { "input": "100\n340 14 3275 2283 2673 1107 817 2243 1226 32 2382 3638 4652 418 68 4962 387 764 4647 159 1846 225 2760 4904 3150 403 3 2439 91 4428 92 4705 75 348 1566 1465 69 6 49 4 62 4643 564 1090 3447 1871 2255 139 24 99 2669 969 86 61 4550 158 4537 3993 1589 872 2907 1888 401 80 1825 1483 63 1 2264 4068 4113 2548 41 885 4806 36 67 167 4447 34 1248 2593 82 202 81 1783 1284 4973 16 43 95 7 865 2091 3008 1793 20 947 4912 3604", "output": "70" }, { "input": "1\n2", "output": "1" }, { "input": "2\n5000 5000", "output": "2" }, { "input": "2\n1 2", "output": "0" }, { "input": "2\n1 1", "output": "1" }, { "input": "2\n2 3", "output": "1" }, { "input": "2\n3 4", "output": "2" }, { "input": "10\n1 2 3 4 5 6 7 1000 10 10", "output": "2" } ]
1,591,304,585
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
3
186
307,200
def numfact(n,u): t=[] for i in range (1,n+1): t.append(i) u.sort(reverse=True) t.sort(reverse=True) j=list(set(u).symmetric_difference(set(t))) y=len(j) return y n=int(input()) data= input() data=data.split() data=[int(i) for i in data] print (numfact(n,data))
Title: Permutation Time Limit: None seconds Memory Limit: None megabytes Problem Description: "Hey, it's homework time" — thought Polycarpus and of course he started with his favourite subject, IT. Polycarpus managed to solve all tasks but for the last one in 20 minutes. However, as he failed to solve the last task after some considerable time, the boy asked you to help him. The sequence of *n* integers is called a permutation if it contains all integers from 1 to *n* exactly once. You are given an arbitrary sequence *a*1,<=*a*2,<=...,<=*a**n* containing *n* integers. Each integer is not less than 1 and not greater than 5000. Determine what minimum number of elements Polycarpus needs to change to get a permutation (he should not delete or add numbers). In a single change he can modify any single sequence element (i. e. replace it with another integer). Input Specification: The first line of the input data contains an integer *n* (1<=≤<=*n*<=≤<=5000) which represents how many numbers are in the sequence. The second line contains a sequence of integers *a**i* (1<=≤<=*a**i*<=≤<=5000,<=1<=≤<=*i*<=≤<=*n*). Output Specification: Print the only number — the minimum number of changes needed to get the permutation. Demo Input: ['3\n3 1 2\n', '2\n2 2\n', '5\n5 3 3 3 1\n'] Demo Output: ['0\n', '1\n', '2\n'] Note: The first sample contains the permutation, which is why no replacements are required. In the second sample it is enough to replace the first element with the number 1 and that will make the sequence the needed permutation. In the third sample we can replace the second element with number 4 and the fourth element with number 2.
```python def numfact(n,u): t=[] for i in range (1,n+1): t.append(i) u.sort(reverse=True) t.sort(reverse=True) j=list(set(u).symmetric_difference(set(t))) y=len(j) return y n=int(input()) data= input() data=data.split() data=[int(i) for i in data] print (numfact(n,data)) ```
0
320
A
Magic Numbers
PROGRAMMING
900
[ "brute force", "greedy" ]
null
null
A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not. You're given a number. Determine if it is a magic number or not.
The first line of input contains an integer *n*, (1<=≤<=*n*<=≤<=109). This number doesn't contain leading zeros.
Print "YES" if *n* is a magic number or print "NO" if it's not.
[ "114114\n", "1111\n", "441231\n" ]
[ "YES\n", "YES\n", "NO\n" ]
none
500
[ { "input": "114114", "output": "YES" }, { "input": "1111", "output": "YES" }, { "input": "441231", "output": "NO" }, { "input": "1", "output": "YES" }, { "input": "14", "output": "YES" }, { "input": "114", "output": "YES" }, { "input": "9", "output": "NO" }, { "input": "414", "output": "NO" }, { "input": "1000000000", "output": "NO" }, { "input": "144144144", "output": "YES" }, { "input": "1444", "output": "NO" }, { "input": "11", "output": "YES" }, { "input": "141414141", "output": "YES" }, { "input": "11110111", "output": "NO" }, { "input": "114114144", "output": "YES" }, { "input": "444", "output": "NO" }, { "input": "9999", "output": "NO" }, { "input": "111444", "output": "NO" }, { "input": "11114", "output": "YES" }, { "input": "41111", "output": "NO" }, { "input": "114414441", "output": "NO" }, { "input": "144414441", "output": "NO" }, { "input": "144244144", "output": "NO" }, { "input": "111111111", "output": "YES" }, { "input": "144444444", "output": "NO" }, { "input": "444444444", "output": "NO" }, { "input": "141441441", "output": "YES" }, { "input": "441", "output": "NO" }, { "input": "15", "output": "NO" }, { "input": "14444", "output": "NO" }, { "input": "11444", "output": "NO" }, { "input": "144", "output": "YES" }, { "input": "1414414", "output": "YES" }, { "input": "141444", "output": "NO" }, { "input": "14144", "output": "YES" }, { "input": "4", "output": "NO" }, { "input": "1144", "output": "YES" }, { "input": "141111444", "output": "NO" }, { "input": "14414414", "output": "YES" }, { "input": "141414144", "output": "YES" }, { "input": "1414", "output": "YES" }, { "input": "1441", "output": "YES" }, { "input": "12", "output": "NO" }, { "input": "144144141", "output": "YES" }, { "input": "144144", "output": "YES" }, { "input": "14414411", "output": "YES" }, { "input": "14414", "output": "YES" } ]
1,621,827,978
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
7
154
0
nums = input() good = True for i in nums: if i != '1' and i != '4': good = False break if good: print('YES') else: print('NO')
Title: Magic Numbers Time Limit: None seconds Memory Limit: None megabytes Problem Description: A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not. You're given a number. Determine if it is a magic number or not. Input Specification: The first line of input contains an integer *n*, (1<=≤<=*n*<=≤<=109). This number doesn't contain leading zeros. Output Specification: Print "YES" if *n* is a magic number or print "NO" if it's not. Demo Input: ['114114\n', '1111\n', '441231\n'] Demo Output: ['YES\n', 'YES\n', 'NO\n'] Note: none
```python nums = input() good = True for i in nums: if i != '1' and i != '4': good = False break if good: print('YES') else: print('NO') ```
0
832
A
Sasha and Sticks
PROGRAMMING
800
[ "games", "math" ]
null
null
It's one more school day now. Sasha doesn't like classes and is always bored at them. So, each day he invents some game and plays in it alone or with friends. Today he invented one simple game to play with Lena, with whom he shares a desk. The rules are simple. Sasha draws *n* sticks in a row. After that the players take turns crossing out exactly *k* sticks from left or right in each turn. Sasha moves first, because he is the inventor of the game. If there are less than *k* sticks on the paper before some turn, the game ends. Sasha wins if he makes strictly more moves than Lena. Sasha wants to know the result of the game before playing, you are to help him.
The first line contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=1018, *k*<=≤<=*n*) — the number of sticks drawn by Sasha and the number *k* — the number of sticks to be crossed out on each turn.
If Sasha wins, print "YES" (without quotes), otherwise print "NO" (without quotes). You can print each letter in arbitrary case (upper of lower).
[ "1 1\n", "10 4\n" ]
[ "YES\n", "NO\n" ]
In the first example Sasha crosses out 1 stick, and then there are no sticks. So Lena can't make a move, and Sasha wins. In the second example Sasha crosses out 4 sticks, then Lena crosses out 4 sticks, and after that there are only 2 sticks left. Sasha can't make a move. The players make equal number of moves, so Sasha doesn't win.
500
[ { "input": "1 1", "output": "YES" }, { "input": "10 4", "output": "NO" }, { "input": "251656215122324104 164397544865601257", "output": "YES" }, { "input": "963577813436662285 206326039287271924", "output": "NO" }, { "input": "1000000000000000000 1", "output": "NO" }, { "input": "253308697183523656 25332878317796706", "output": "YES" }, { "input": "669038685745448997 501718093668307460", "output": "YES" }, { "input": "116453141993601660 87060381463547965", "output": "YES" }, { "input": "766959657 370931668", "output": "NO" }, { "input": "255787422422806632 146884995820359999", "output": "YES" }, { "input": "502007866464507926 71266379084204128", "output": "YES" }, { "input": "257439908778973480 64157133126869976", "output": "NO" }, { "input": "232709385 91708542", "output": "NO" }, { "input": "252482458300407528 89907711721009125", "output": "NO" }, { "input": "6 2", "output": "YES" }, { "input": "6 3", "output": "NO" }, { "input": "6 4", "output": "YES" }, { "input": "6 5", "output": "YES" }, { "input": "6 6", "output": "YES" }, { "input": "258266151957056904 30153168463725364", "output": "NO" }, { "input": "83504367885565783 52285355047292458", "output": "YES" }, { "input": "545668929424440387 508692735816921376", "output": "YES" }, { "input": "547321411485639939 36665750286082900", "output": "NO" }, { "input": "548973893546839491 183137237979822911", "output": "NO" }, { "input": "544068082 193116851", "output": "NO" }, { "input": "871412474 749817171", "output": "YES" }, { "input": "999999999 1247", "output": "NO" }, { "input": "851941088 712987048", "output": "YES" }, { "input": "559922900 418944886", "output": "YES" }, { "input": "293908937 37520518", "output": "YES" }, { "input": "650075786 130049650", "output": "NO" }, { "input": "1000000000 1000000000", "output": "YES" }, { "input": "548147654663723363 107422751713800746", "output": "YES" }, { "input": "828159210 131819483", "output": "NO" }, { "input": "6242634 4110365", "output": "YES" }, { "input": "458601973 245084155", "output": "YES" }, { "input": "349593257 18089089", "output": "YES" }, { "input": "814768821 312514745", "output": "NO" }, { "input": "697884949 626323363", "output": "YES" }, { "input": "667011589 54866795", "output": "NO" }, { "input": "1000000000000000000 2", "output": "NO" }, { "input": "1000000000000000000 3", "output": "YES" }, { "input": "1000000000000000000 4", "output": "NO" }, { "input": "999999999999999 1", "output": "YES" }, { "input": "17 4", "output": "NO" }, { "input": "2 2", "output": "YES" }, { "input": "1000000000000000 2", "output": "NO" }, { "input": "12 4", "output": "YES" }, { "input": "6 1", "output": "NO" }, { "input": "2 1", "output": "NO" }, { "input": "10000000005 1", "output": "YES" }, { "input": "10000000000000009 2", "output": "NO" }, { "input": "12457895452123 1", "output": "YES" }, { "input": "999999999999999999 9", "output": "YES" }, { "input": "1000000000000 3", "output": "YES" }, { "input": "13099714659575475 6549849616514894", "output": "NO" }, { "input": "100000000000000001 1", "output": "YES" }, { "input": "825175814723458 324", "output": "YES" }, { "input": "20 4", "output": "YES" }, { "input": "100000176877 4", "output": "YES" }, { "input": "100000 3", "output": "YES" }, { "input": "946744073709551614 10", "output": "YES" } ]
1,618,751,331
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
62
0
n,k=map(int,input().split()) status=0 if n%k==0: status=0 else: status=1 if status==0: print('YES') else: print('NO')
Title: Sasha and Sticks Time Limit: None seconds Memory Limit: None megabytes Problem Description: It's one more school day now. Sasha doesn't like classes and is always bored at them. So, each day he invents some game and plays in it alone or with friends. Today he invented one simple game to play with Lena, with whom he shares a desk. The rules are simple. Sasha draws *n* sticks in a row. After that the players take turns crossing out exactly *k* sticks from left or right in each turn. Sasha moves first, because he is the inventor of the game. If there are less than *k* sticks on the paper before some turn, the game ends. Sasha wins if he makes strictly more moves than Lena. Sasha wants to know the result of the game before playing, you are to help him. Input Specification: The first line contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=1018, *k*<=≤<=*n*) — the number of sticks drawn by Sasha and the number *k* — the number of sticks to be crossed out on each turn. Output Specification: If Sasha wins, print "YES" (without quotes), otherwise print "NO" (without quotes). You can print each letter in arbitrary case (upper of lower). Demo Input: ['1 1\n', '10 4\n'] Demo Output: ['YES\n', 'NO\n'] Note: In the first example Sasha crosses out 1 stick, and then there are no sticks. So Lena can't make a move, and Sasha wins. In the second example Sasha crosses out 4 sticks, then Lena crosses out 4 sticks, and after that there are only 2 sticks left. Sasha can't make a move. The players make equal number of moves, so Sasha doesn't win.
```python n,k=map(int,input().split()) status=0 if n%k==0: status=0 else: status=1 if status==0: print('YES') else: print('NO') ```
0
788
A
Functions again
PROGRAMMING
1,600
[ "dp", "two pointers" ]
null
null
Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function *f*, which is defined as follows: In the above formula, 1<=≤<=*l*<=&lt;<=*r*<=≤<=*n* must hold, where *n* is the size of the Main Uzhlyandian Array *a*, and |*x*| means absolute value of *x*. But the heroes skipped their math lessons in school, so they asked you for help. Help them calculate the maximum value of *f* among all possible values of *l* and *r* for the given array *a*.
The first line contains single integer *n* (2<=≤<=*n*<=≤<=105) — the size of the array *a*. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (-109<=≤<=*a**i*<=≤<=109) — the array elements.
Print the only integer — the maximum value of *f*.
[ "5\n1 4 2 3 1\n", "4\n1 5 4 7\n" ]
[ "3", "6" ]
In the first sample case, the optimal value of *f* is reached on intervals [1, 2] and [2, 5]. In the second case maximal value of *f* is reachable only on the whole array.
500
[ { "input": "5\n1 4 2 3 1", "output": "3" }, { "input": "4\n1 5 4 7", "output": "6" }, { "input": "8\n16 14 12 10 8 100 50 0", "output": "92" }, { "input": "2\n1 1", "output": "0" }, { "input": "50\n-5 -9 0 44 -10 37 34 -49 11 -22 -26 44 8 -13 23 -46 34 12 -24 2 -40 -15 -28 38 -40 -42 -42 7 -43 5 2 -11 10 43 9 49 -13 36 2 24 46 50 -15 -26 -6 -6 8 4 -44 -3", "output": "208" }, { "input": "100\n23 64 60 -45 -36 -64 -59 15 -75 69 -30 -7 -20 17 -77 58 93 -76 -98 -22 -31 16 -50 6 -20 -85 1 64 -88 -8 -15 -6 -57 25 91 10 2 -90 74 -66 -42 73 28 49 -85 59 96 79 -25 49 -59 -89 -75 12 -96 -33 -65 -8 -100 -81 17 99 -91 -5 7 -21 1 85 63 86 -26 85 -31 11 -75 35 -82 15 98 93 -55 66 70 36 -38 8 92 -63 -5 60 -78 -7 -22 -1 4 54 36 16 32 -20", "output": "632" }, { "input": "3\n0 0 0", "output": "0" }, { "input": "3\n0 1 -1", "output": "2" }, { "input": "5\n1000000000 0 0 1000000000 -1000000000", "output": "2000000000" }, { "input": "2\n1000000000 -1000000000", "output": "2000000000" }, { "input": "4\n1000000000 0 0 -1000000000", "output": "2000000000" }, { "input": "4\n1 0 1 0", "output": "1" }, { "input": "5\n0 10 20 30 40", "output": "10" }, { "input": "2\n-1000000000 1000000000", "output": "2000000000" }, { "input": "2\n1 2", "output": "1" }, { "input": "9\n1000000000 0 0 1000000000 1000000000 0 0 1000000000 1000000000", "output": "4000000000" }, { "input": "16\n-1000000000 1000000000 1000000000 -1000000000 -1000000000 1000000000 1000000000 -1000000000 -1000000000 1000000000 1000000000 -1000000000 -1000000000 1000000000 1000000000 -1000000000", "output": "16000000000" }, { "input": "6\n1000000000 0 0 1000000000 1000000000 0", "output": "3000000000" }, { "input": "17\n1000000000 0 0 1000000000 1000000000 0 0 1000000000 1000000000 0 0 1000000000 1000000000 0 0 1000000000 1000000000", "output": "8000000000" }, { "input": "11\n1000000000 0 1 1000000000 999999999 1 0 1000000000 999999999 1 1000000000", "output": "4999999991" }, { "input": "4\n1000000000 -1000000000 -1000000000 1000000000", "output": "4000000000" }, { "input": "10\n1000000000 -1000000000 -1000000000 1000000000 1000000000 -1000000000 -1000000000 1000000000 1000000000 -1000000000", "output": "10000000000" } ]
1,490,862,372
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
8
1,000
4,608,000
def f(a, l, r): count = 0 for i in range(l, r): count += abs(a[i-1]-a[i])*(-1)**(i-l) return count n = int(input()) a = input().split() for i in range(len(a)): a[i] = int(a[i]) maxF = 0 for r in range(2, n+1): for l in range(1, r): function = f(a, l, r) if function > maxF: maxF = function print(maxF)
Title: Functions again Time Limit: None seconds Memory Limit: None megabytes Problem Description: Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function *f*, which is defined as follows: In the above formula, 1<=≤<=*l*<=&lt;<=*r*<=≤<=*n* must hold, where *n* is the size of the Main Uzhlyandian Array *a*, and |*x*| means absolute value of *x*. But the heroes skipped their math lessons in school, so they asked you for help. Help them calculate the maximum value of *f* among all possible values of *l* and *r* for the given array *a*. Input Specification: The first line contains single integer *n* (2<=≤<=*n*<=≤<=105) — the size of the array *a*. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (-109<=≤<=*a**i*<=≤<=109) — the array elements. Output Specification: Print the only integer — the maximum value of *f*. Demo Input: ['5\n1 4 2 3 1\n', '4\n1 5 4 7\n'] Demo Output: ['3', '6'] Note: In the first sample case, the optimal value of *f* is reached on intervals [1, 2] and [2, 5]. In the second case maximal value of *f* is reachable only on the whole array.
```python def f(a, l, r): count = 0 for i in range(l, r): count += abs(a[i-1]-a[i])*(-1)**(i-l) return count n = int(input()) a = input().split() for i in range(len(a)): a[i] = int(a[i]) maxF = 0 for r in range(2, n+1): for l in range(1, r): function = f(a, l, r) if function > maxF: maxF = function print(maxF) ```
0
940
A
Points on the line
PROGRAMMING
1,200
[ "brute force", "greedy", "sortings" ]
null
null
We've got no test cases. A big olympiad is coming up. But the problemsetters' number one priority should be adding another problem to the round. The diameter of a multiset of points on the line is the largest distance between two points from this set. For example, the diameter of the multiset {1,<=3,<=2,<=1} is 2. Diameter of multiset consisting of one point is 0. You are given *n* points on the line. What is the minimum number of points you have to remove, so that the diameter of the multiset of the remaining points will not exceed *d*?
The first line contains two integers *n* and *d* (1<=≤<=*n*<=≤<=100,<=0<=≤<=*d*<=≤<=100) — the amount of points and the maximum allowed diameter respectively. The second line contains *n* space separated integers (1<=≤<=*x**i*<=≤<=100) — the coordinates of the points.
Output a single integer — the minimum number of points you have to remove.
[ "3 1\n2 1 4\n", "3 0\n7 7 7\n", "6 3\n1 3 4 6 9 10\n" ]
[ "1\n", "0\n", "3\n" ]
In the first test case the optimal strategy is to remove the point with coordinate 4. The remaining points will have coordinates 1 and 2, so the diameter will be equal to 2 - 1 = 1. In the second test case the diameter is equal to 0, so its is unnecessary to remove any points. In the third test case the optimal strategy is to remove points with coordinates 1, 9 and 10. The remaining points will have coordinates 3, 4 and 6, so the diameter will be equal to 6 - 3 = 3.
500
[ { "input": "3 1\n2 1 4", "output": "1" }, { "input": "3 0\n7 7 7", "output": "0" }, { "input": "6 3\n1 3 4 6 9 10", "output": "3" }, { "input": "11 5\n10 11 12 13 14 15 16 17 18 19 20", "output": "5" }, { "input": "1 100\n1", "output": "0" }, { "input": "100 10\n22 75 26 45 72 81 47 29 97 2 75 25 82 84 17 56 32 2 28 37 57 39 18 11 79 6 40 68 68 16 40 63 93 49 91 10 55 68 31 80 57 18 34 28 76 55 21 80 22 45 11 67 67 74 91 4 35 34 65 80 21 95 1 52 25 31 2 53 96 22 89 99 7 66 32 2 68 33 75 92 84 10 94 28 54 12 9 80 43 21 51 92 20 97 7 25 67 17 38 100", "output": "84" }, { "input": "100 70\n22 75 26 45 72 81 47 29 97 2 75 25 82 84 17 56 32 2 28 37 57 39 18 11 79 6 40 68 68 16 40 63 93 49 91 10 55 68 31 80 57 18 34 28 76 55 21 80 22 45 11 67 67 74 91 4 35 34 65 80 21 95 1 52 25 31 2 53 96 22 89 99 7 66 32 2 68 33 75 92 84 10 94 28 54 12 9 80 43 21 51 92 20 97 7 25 67 17 38 100", "output": "27" }, { "input": "1 10\n25", "output": "0" }, { "input": "70 80\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70", "output": "0" }, { "input": "3 1\n25 26 27", "output": "1" }, { "input": "100 5\n51 56 52 60 52 53 52 60 56 54 55 50 53 51 57 53 52 54 54 52 51 55 50 56 60 51 58 50 60 59 50 54 60 55 55 57 54 59 59 55 55 52 56 57 59 54 53 57 52 50 50 55 59 54 54 56 51 58 52 51 56 56 58 56 54 54 57 52 51 58 56 57 54 59 58 53 50 52 50 60 57 51 54 59 54 54 52 55 53 55 51 53 52 54 51 56 55 53 58 56", "output": "34" }, { "input": "100 11\n44 89 57 64 94 96 73 96 55 52 91 73 73 93 51 62 63 85 43 75 60 78 98 55 80 84 65 75 61 88 62 71 53 57 94 85 60 96 66 96 61 72 97 64 51 44 63 82 67 86 60 57 74 85 57 79 61 94 86 78 84 56 60 75 91 91 92 62 89 85 79 57 76 97 65 56 46 78 51 69 50 52 85 80 76 71 81 51 90 71 77 60 63 62 84 59 79 84 69 81", "output": "70" }, { "input": "100 0\n22 75 26 45 72 81 47 29 97 2 75 25 82 84 17 56 32 2 28 37 57 39 18 11 79 6 40 68 68 16 40 63 93 49 91 10 55 68 31 80 57 18 34 28 76 55 21 80 22 45 11 67 67 74 91 4 35 34 65 80 21 95 1 52 25 31 2 53 96 22 89 99 7 66 32 2 68 33 75 92 84 10 94 28 54 12 9 80 43 21 51 92 20 97 7 25 67 17 38 100", "output": "96" }, { "input": "100 100\n22 75 26 45 72 81 47 29 97 2 75 25 82 84 17 56 32 2 28 37 57 39 18 11 79 6 40 68 68 16 40 63 93 49 91 10 55 68 31 80 57 18 34 28 76 55 21 80 22 45 11 67 67 74 91 4 35 34 65 80 21 95 1 52 25 31 2 53 96 22 89 99 7 66 32 2 68 33 75 92 84 10 94 28 54 12 9 80 43 21 51 92 20 97 7 25 67 17 38 100", "output": "0" }, { "input": "76 32\n50 53 69 58 55 39 40 42 40 55 58 73 55 72 75 44 45 55 46 60 60 42 41 64 77 39 68 51 61 49 38 41 56 57 64 43 78 36 39 63 40 66 52 76 39 68 39 73 40 68 54 60 35 67 69 52 58 52 38 63 69 38 69 60 73 64 65 41 59 55 37 57 40 34 35 35", "output": "13" }, { "input": "100 1\n22 75 26 45 72 81 47 29 97 2 75 25 82 84 17 56 32 2 28 37 57 39 18 11 79 6 40 68 68 16 40 63 93 49 91 10 55 68 31 80 57 18 34 28 76 55 21 80 22 45 11 67 67 74 91 4 35 34 65 80 21 95 1 52 25 31 2 53 96 22 89 99 7 66 32 2 68 33 75 92 84 10 94 28 54 12 9 80 43 21 51 92 20 97 7 25 67 17 38 100", "output": "93" }, { "input": "100 5\n22 75 26 45 72 81 47 29 97 2 75 25 82 84 17 56 32 2 28 37 57 39 18 11 79 6 40 68 68 16 40 63 93 49 91 10 55 68 31 80 57 18 34 28 76 55 21 80 22 45 11 67 67 74 91 4 35 34 65 80 21 95 1 52 25 31 2 53 96 22 89 99 7 66 32 2 68 33 75 92 84 10 94 28 54 12 9 80 43 21 51 92 20 97 7 25 67 17 38 100", "output": "89" }, { "input": "98 64\n2 29 36 55 58 15 25 33 7 16 61 1 4 24 63 26 36 16 16 3 57 39 56 7 11 24 20 12 22 10 56 5 11 39 61 52 27 54 21 6 61 36 40 52 54 5 15 52 58 23 45 39 65 16 27 40 13 64 47 24 51 29 9 18 49 49 8 47 2 64 7 63 49 10 20 26 34 3 45 66 8 46 16 32 16 38 3 6 15 17 35 48 36 5 57 29 61 15", "output": "1" }, { "input": "100 56\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100", "output": "43" }, { "input": "100 0\n14 13 14 13 14 13 13 13 13 14 13 13 14 14 13 14 14 14 14 13 13 13 14 13 13 14 14 14 14 14 14 13 13 13 13 14 13 14 13 14 13 14 14 14 14 13 13 14 14 13 13 13 13 14 13 14 13 14 13 14 13 13 13 14 13 13 14 13 14 14 13 13 13 14 14 14 14 13 13 14 14 14 14 14 14 14 13 14 13 13 13 14 14 13 13 13 13 13 14 14", "output": "50" }, { "input": "100 0\n14 17 18 22 19 18 19 21 19 19 22 22 19 21 24 23 24 19 25 24 24 21 20 13 26 18 17 15 25 13 17 20 20 21 13 22 27 15 18 27 19 15 16 25 18 17 18 22 19 17 18 24 14 16 18 16 22 16 17 27 18 17 18 24 22 13 14 20 23 19 16 21 19 13 14 14 25 15 27 24 26 22 16 20 16 14 21 27 15 23 23 24 27 14 24 17 19 24 15 27", "output": "89" }, { "input": "100 100\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100", "output": "0" }, { "input": "1 100\n22", "output": "0" }, { "input": "1 0\n22", "output": "0" }, { "input": "1 99\n99", "output": "0" }, { "input": "1 5\n6", "output": "0" }, { "input": "3 1\n10 20 30", "output": "2" }, { "input": "3 0\n1 2 3", "output": "2" }, { "input": "3 2\n1 50 99", "output": "2" }, { "input": "7 4\n1 3 4 9 10 11 12", "output": "3" }, { "input": "2 5\n67 23", "output": "1" }, { "input": "4 2\n1 4 7 9", "output": "2" }, { "input": "2 0\n1 2", "output": "1" }, { "input": "8 1\n3 3 3 5 5 5 5 5", "output": "3" }, { "input": "5 1\n3 5 5 5 6", "output": "1" } ]
1,591,251,191
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
5
124
0
n,m=(map(int,input().split())) ln=list(map(int,input().split())) # lm=list(map(int,input().split())) ln.sort() v=ln[0]+m c=0 for i in range(n): if(ln[i]>v): c+=1 print(c)
Title: Points on the line Time Limit: None seconds Memory Limit: None megabytes Problem Description: We've got no test cases. A big olympiad is coming up. But the problemsetters' number one priority should be adding another problem to the round. The diameter of a multiset of points on the line is the largest distance between two points from this set. For example, the diameter of the multiset {1,<=3,<=2,<=1} is 2. Diameter of multiset consisting of one point is 0. You are given *n* points on the line. What is the minimum number of points you have to remove, so that the diameter of the multiset of the remaining points will not exceed *d*? Input Specification: The first line contains two integers *n* and *d* (1<=≤<=*n*<=≤<=100,<=0<=≤<=*d*<=≤<=100) — the amount of points and the maximum allowed diameter respectively. The second line contains *n* space separated integers (1<=≤<=*x**i*<=≤<=100) — the coordinates of the points. Output Specification: Output a single integer — the minimum number of points you have to remove. Demo Input: ['3 1\n2 1 4\n', '3 0\n7 7 7\n', '6 3\n1 3 4 6 9 10\n'] Demo Output: ['1\n', '0\n', '3\n'] Note: In the first test case the optimal strategy is to remove the point with coordinate 4. The remaining points will have coordinates 1 and 2, so the diameter will be equal to 2 - 1 = 1. In the second test case the diameter is equal to 0, so its is unnecessary to remove any points. In the third test case the optimal strategy is to remove points with coordinates 1, 9 and 10. The remaining points will have coordinates 3, 4 and 6, so the diameter will be equal to 6 - 3 = 3.
```python n,m=(map(int,input().split())) ln=list(map(int,input().split())) # lm=list(map(int,input().split())) ln.sort() v=ln[0]+m c=0 for i in range(n): if(ln[i]>v): c+=1 print(c) ```
0
545
C
Woodcutters
PROGRAMMING
1,500
[ "dp", "greedy" ]
null
null
Little Susie listens to fairy tales before bed every day. Today's fairy tale was about wood cutters and the little girl immediately started imagining the choppers cutting wood. She imagined the situation that is described below. There are *n* trees located along the road at points with coordinates *x*1,<=*x*2,<=...,<=*x**n*. Each tree has its height *h**i*. Woodcutters can cut down a tree and fell it to the left or to the right. After that it occupies one of the segments [*x**i*<=-<=*h**i*,<=*x**i*] or [*x**i*;*x**i*<=+<=*h**i*]. The tree that is not cut down occupies a single point with coordinate *x**i*. Woodcutters can fell a tree if the segment to be occupied by the fallen tree doesn't contain any occupied point. The woodcutters want to process as many trees as possible, so Susie wonders, what is the maximum number of trees to fell.
The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of trees. Next *n* lines contain pairs of integers *x**i*,<=*h**i* (1<=≤<=*x**i*,<=*h**i*<=≤<=109) — the coordinate and the height of the *і*-th tree. The pairs are given in the order of ascending *x**i*. No two trees are located at the point with the same coordinate.
Print a single number — the maximum number of trees that you can cut down by the given rules.
[ "5\n1 2\n2 1\n5 10\n10 9\n19 1\n", "5\n1 2\n2 1\n5 10\n10 9\n20 1\n" ]
[ "3\n", "4\n" ]
In the first sample you can fell the trees like that: - fell the 1-st tree to the left — now it occupies segment [ - 1;1] - fell the 2-nd tree to the right — now it occupies segment [2;3] - leave the 3-rd tree — it occupies point 5 - leave the 4-th tree — it occupies point 10 - fell the 5-th tree to the right — now it occupies segment [19;20] In the second sample you can also fell 4-th tree to the right, after that it will occupy segment [10;19].
1,750
[ { "input": "5\n1 2\n2 1\n5 10\n10 9\n19 1", "output": "3" }, { "input": "5\n1 2\n2 1\n5 10\n10 9\n20 1", "output": "4" }, { "input": "4\n10 4\n15 1\n19 3\n20 1", "output": "4" }, { "input": "35\n1 7\n3 11\n6 12\n7 6\n8 5\n9 11\n15 3\n16 10\n22 2\n23 3\n25 7\n27 3\n34 5\n35 10\n37 3\n39 4\n40 5\n41 1\n44 1\n47 7\n48 11\n50 6\n52 5\n57 2\n58 7\n60 4\n62 1\n67 3\n68 12\n69 8\n70 1\n71 5\n72 5\n73 6\n74 4", "output": "10" }, { "input": "40\n1 1\n2 1\n3 1\n4 1\n5 1\n6 1\n7 1\n8 1\n9 1\n10 1\n11 1\n12 1\n13 1\n14 1\n15 1\n16 1\n17 1\n18 1\n19 1\n20 1\n21 1\n22 1\n23 1\n24 1\n25 1\n26 1\n27 1\n28 1\n29 1\n30 1\n31 1\n32 1\n33 1\n34 1\n35 1\n36 1\n37 1\n38 1\n39 1\n40 1", "output": "2" }, { "input": "67\n1 1\n3 8\n4 10\n7 8\n9 2\n10 1\n11 5\n12 8\n13 4\n16 6\n18 3\n19 3\n22 5\n24 6\n27 5\n28 3\n29 3\n30 5\n32 5\n33 10\n34 7\n35 8\n36 5\n41 3\n42 2\n43 5\n46 4\n48 4\n49 9\n52 4\n53 9\n55 1\n56 4\n59 7\n68 7\n69 4\n71 9\n72 10\n74 5\n76 4\n77 9\n80 7\n81 9\n82 5\n83 5\n84 9\n85 7\n86 9\n87 4\n88 7\n89 10\n90 3\n91 5\n92 10\n93 5\n94 8\n95 4\n96 2\n97 10\n98 1\n99 3\n100 1\n101 5\n102 4\n103 8\n104 8\n105 8", "output": "5" }, { "input": "1\n1000000000 1000000000", "output": "1" }, { "input": "10\n7 12\n10 2\n12 2\n15 1\n19 2\n20 1\n53 25\n63 10\n75 12\n87 1", "output": "9" }, { "input": "3\n1 1\n1000 1000\n1000000000 1000000000", "output": "3" }, { "input": "2\n1 999999999\n1000000000 1000000000", "output": "2" }, { "input": "10\n999999900 1000000000\n999999901 1000000000\n999999902 1000000000\n999999903 1000000000\n999999904 1000000000\n999999905 1000000000\n999999906 1000000000\n999999907 1000000000\n999999908 1000000000\n999999909 1000000000", "output": "2" }, { "input": "2\n100000000 1000000000\n1000000000 1000000000", "output": "2" } ]
1,697,859,059
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
8
311
19,865,600
''' 2300015897 吴杰稀 光华管理学院 ''' cases = int(input()) tree_list = [] for i in range(cases): tree_list.append(list(map(int,input().split()))) end = tree_list[0][0] i,add_up = 1,2 while i < len(tree_list) - 1: if tree_list[i][0] - tree_list[i][1] > end: end = tree_list[i][0] add_up += 1 else: if tree_list[i][0] + tree_list[i][1] < tree_list[i + 1][0]: end = tree_list[i][0] + tree_list[i][1] add_up += 1 else: end = tree_list[i][0] i += 1 print(add_up)
Title: Woodcutters Time Limit: None seconds Memory Limit: None megabytes Problem Description: Little Susie listens to fairy tales before bed every day. Today's fairy tale was about wood cutters and the little girl immediately started imagining the choppers cutting wood. She imagined the situation that is described below. There are *n* trees located along the road at points with coordinates *x*1,<=*x*2,<=...,<=*x**n*. Each tree has its height *h**i*. Woodcutters can cut down a tree and fell it to the left or to the right. After that it occupies one of the segments [*x**i*<=-<=*h**i*,<=*x**i*] or [*x**i*;*x**i*<=+<=*h**i*]. The tree that is not cut down occupies a single point with coordinate *x**i*. Woodcutters can fell a tree if the segment to be occupied by the fallen tree doesn't contain any occupied point. The woodcutters want to process as many trees as possible, so Susie wonders, what is the maximum number of trees to fell. Input Specification: The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of trees. Next *n* lines contain pairs of integers *x**i*,<=*h**i* (1<=≤<=*x**i*,<=*h**i*<=≤<=109) — the coordinate and the height of the *і*-th tree. The pairs are given in the order of ascending *x**i*. No two trees are located at the point with the same coordinate. Output Specification: Print a single number — the maximum number of trees that you can cut down by the given rules. Demo Input: ['5\n1 2\n2 1\n5 10\n10 9\n19 1\n', '5\n1 2\n2 1\n5 10\n10 9\n20 1\n'] Demo Output: ['3\n', '4\n'] Note: In the first sample you can fell the trees like that: - fell the 1-st tree to the left — now it occupies segment [ - 1;1] - fell the 2-nd tree to the right — now it occupies segment [2;3] - leave the 3-rd tree — it occupies point 5 - leave the 4-th tree — it occupies point 10 - fell the 5-th tree to the right — now it occupies segment [19;20] In the second sample you can also fell 4-th tree to the right, after that it will occupy segment [10;19].
```python ''' 2300015897 吴杰稀 光华管理学院 ''' cases = int(input()) tree_list = [] for i in range(cases): tree_list.append(list(map(int,input().split()))) end = tree_list[0][0] i,add_up = 1,2 while i < len(tree_list) - 1: if tree_list[i][0] - tree_list[i][1] > end: end = tree_list[i][0] add_up += 1 else: if tree_list[i][0] + tree_list[i][1] < tree_list[i + 1][0]: end = tree_list[i][0] + tree_list[i][1] add_up += 1 else: end = tree_list[i][0] i += 1 print(add_up) ```
0
902
B
Coloring a Tree
PROGRAMMING
1,200
[ "dfs and similar", "dsu", "greedy" ]
null
null
You are given a rooted tree with *n* vertices. The vertices are numbered from 1 to *n*, the root is the vertex number 1. Each vertex has a color, let's denote the color of vertex *v* by *c**v*. Initially *c**v*<==<=0. You have to color the tree into the given colors using the smallest possible number of steps. On each step you can choose a vertex *v* and a color *x*, and then color all vectices in the subtree of *v* (including *v* itself) in color *x*. In other words, for every vertex *u*, such that the path from root to *u* passes through *v*, set *c**u*<==<=*x*. It is guaranteed that you have to color each vertex in a color different from 0. You can learn what a rooted tree is using the link: [https://en.wikipedia.org/wiki/Tree_(graph_theory)](https://en.wikipedia.org/wiki/Tree_(graph_theory)).
The first line contains a single integer *n* (2<=≤<=*n*<=≤<=104) — the number of vertices in the tree. The second line contains *n*<=-<=1 integers *p*2,<=*p*3,<=...,<=*p**n* (1<=≤<=*p**i*<=&lt;<=*i*), where *p**i* means that there is an edge between vertices *i* and *p**i*. The third line contains *n* integers *c*1,<=*c*2,<=...,<=*c**n* (1<=≤<=*c**i*<=≤<=*n*), where *c**i* is the color you should color the *i*-th vertex into. It is guaranteed that the given graph is a tree.
Print a single integer — the minimum number of steps you have to perform to color the tree into given colors.
[ "6\n1 2 2 1 5\n2 1 1 1 1 1\n", "7\n1 1 2 3 1 4\n3 3 1 1 1 2 3\n" ]
[ "3\n", "5\n" ]
The tree from the first sample is shown on the picture (numbers are vetices' indices): <img class="tex-graphics" src="https://espresso.codeforces.com/10324ccdc37f95343acc4f3c6050d8c334334ffa.png" style="max-width: 100.0%;max-height: 100.0%;"/> On first step we color all vertices in the subtree of vertex 1 into color 2 (numbers are colors): <img class="tex-graphics" src="https://espresso.codeforces.com/1c7bb267e2c1a006132248a43121400189309e2f.png" style="max-width: 100.0%;max-height: 100.0%;"/> On seond step we color all vertices in the subtree of vertex 5 into color 1: <img class="tex-graphics" src="https://espresso.codeforces.com/2201a6d49b89ba850ff0d0bdcbb3f8e9dd3871a8.png" style="max-width: 100.0%;max-height: 100.0%;"/> On third step we color all vertices in the subtree of vertex 2 into color 1: <img class="tex-graphics" src="https://espresso.codeforces.com/6fa977fcdebdde94c47695151e0427b33d0102c5.png" style="max-width: 100.0%;max-height: 100.0%;"/> The tree from the second sample is shown on the picture (numbers are vetices' indices): <img class="tex-graphics" src="https://espresso.codeforces.com/d70f9ae72a2ed429dd6531cac757e375dd3c953d.png" style="max-width: 100.0%;max-height: 100.0%;"/> On first step we color all vertices in the subtree of vertex 1 into color 3 (numbers are colors): <img class="tex-graphics" src="https://espresso.codeforces.com/7289e8895d0dd56c47b6b17969b9cf77b36786b5.png" style="max-width: 100.0%;max-height: 100.0%;"/> On second step we color all vertices in the subtree of vertex 3 into color 1: <img class="tex-graphics" src="https://espresso.codeforces.com/819001df7229138db3a407713744d1e3be88b64e.png" style="max-width: 100.0%;max-height: 100.0%;"/> On third step we color all vertices in the subtree of vertex 6 into color 2: <img class="tex-graphics" src="https://espresso.codeforces.com/80ebbd870a0a339636a21b9acdaf9de046458b43.png" style="max-width: 100.0%;max-height: 100.0%;"/> On fourth step we color all vertices in the subtree of vertex 4 into color 1: <img class="tex-graphics" src="https://espresso.codeforces.com/ed836aa723ac0176abde4e32988e3ac205014e93.png" style="max-width: 100.0%;max-height: 100.0%;"/> On fith step we color all vertices in the subtree of vertex 7 into color 3: <img class="tex-graphics" src="https://espresso.codeforces.com/8132909e11b41c27b8df2f0b0c10bc841f35e58a.png" style="max-width: 100.0%;max-height: 100.0%;"/>
1,000
[ { "input": "6\n1 2 2 1 5\n2 1 1 1 1 1", "output": "3" }, { "input": "7\n1 1 2 3 1 4\n3 3 1 1 1 2 3", "output": "5" }, { "input": "2\n1\n2 2", "output": "1" }, { "input": "3\n1 1\n2 2 2", "output": "1" }, { "input": "4\n1 2 1\n1 2 3 4", "output": "4" }, { "input": "4\n1 2 3\n4 1 2 4", "output": "4" }, { "input": "5\n1 2 1 4\n1 1 1 2 2", "output": "2" }, { "input": "3\n1 2\n2 1 1", "output": "2" }, { "input": "4\n1 1 1\n3 1 3 1", "output": "3" }, { "input": "4\n1 1 2\n4 1 4 1", "output": "2" }, { "input": "4\n1 2 2\n3 1 2 3", "output": "4" }, { "input": "3\n1 1\n1 2 2", "output": "3" } ]
1,598,674,180
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
17
171
2,457,600
n = int(input()) nodes = list(map(int,input().split())) color = list(map(int,input().split())) from collections import defaultdict def DFS(d,x,visited,color): c = 0 visited[x] = 1 z = 0 for j in d[x]: if visited[j] == 0 and color[x-1] != color[j-1]: c = c + 1 + DFS(d,j,visited,color) elif visited[j] == 0 and color[x-1] == color[j-1]: c = c + DFS(d,j,visited,color) return c d = defaultdict(list) for i in range(n-1): d[nodes[i]].append(i+2) t = 1 visited = [0 for i in range(n+1)] c = 1 print(DFS(d,t,visited,color)+1)
Title: Coloring a Tree Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given a rooted tree with *n* vertices. The vertices are numbered from 1 to *n*, the root is the vertex number 1. Each vertex has a color, let's denote the color of vertex *v* by *c**v*. Initially *c**v*<==<=0. You have to color the tree into the given colors using the smallest possible number of steps. On each step you can choose a vertex *v* and a color *x*, and then color all vectices in the subtree of *v* (including *v* itself) in color *x*. In other words, for every vertex *u*, such that the path from root to *u* passes through *v*, set *c**u*<==<=*x*. It is guaranteed that you have to color each vertex in a color different from 0. You can learn what a rooted tree is using the link: [https://en.wikipedia.org/wiki/Tree_(graph_theory)](https://en.wikipedia.org/wiki/Tree_(graph_theory)). Input Specification: The first line contains a single integer *n* (2<=≤<=*n*<=≤<=104) — the number of vertices in the tree. The second line contains *n*<=-<=1 integers *p*2,<=*p*3,<=...,<=*p**n* (1<=≤<=*p**i*<=&lt;<=*i*), where *p**i* means that there is an edge between vertices *i* and *p**i*. The third line contains *n* integers *c*1,<=*c*2,<=...,<=*c**n* (1<=≤<=*c**i*<=≤<=*n*), where *c**i* is the color you should color the *i*-th vertex into. It is guaranteed that the given graph is a tree. Output Specification: Print a single integer — the minimum number of steps you have to perform to color the tree into given colors. Demo Input: ['6\n1 2 2 1 5\n2 1 1 1 1 1\n', '7\n1 1 2 3 1 4\n3 3 1 1 1 2 3\n'] Demo Output: ['3\n', '5\n'] Note: The tree from the first sample is shown on the picture (numbers are vetices' indices): <img class="tex-graphics" src="https://espresso.codeforces.com/10324ccdc37f95343acc4f3c6050d8c334334ffa.png" style="max-width: 100.0%;max-height: 100.0%;"/> On first step we color all vertices in the subtree of vertex 1 into color 2 (numbers are colors): <img class="tex-graphics" src="https://espresso.codeforces.com/1c7bb267e2c1a006132248a43121400189309e2f.png" style="max-width: 100.0%;max-height: 100.0%;"/> On seond step we color all vertices in the subtree of vertex 5 into color 1: <img class="tex-graphics" src="https://espresso.codeforces.com/2201a6d49b89ba850ff0d0bdcbb3f8e9dd3871a8.png" style="max-width: 100.0%;max-height: 100.0%;"/> On third step we color all vertices in the subtree of vertex 2 into color 1: <img class="tex-graphics" src="https://espresso.codeforces.com/6fa977fcdebdde94c47695151e0427b33d0102c5.png" style="max-width: 100.0%;max-height: 100.0%;"/> The tree from the second sample is shown on the picture (numbers are vetices' indices): <img class="tex-graphics" src="https://espresso.codeforces.com/d70f9ae72a2ed429dd6531cac757e375dd3c953d.png" style="max-width: 100.0%;max-height: 100.0%;"/> On first step we color all vertices in the subtree of vertex 1 into color 3 (numbers are colors): <img class="tex-graphics" src="https://espresso.codeforces.com/7289e8895d0dd56c47b6b17969b9cf77b36786b5.png" style="max-width: 100.0%;max-height: 100.0%;"/> On second step we color all vertices in the subtree of vertex 3 into color 1: <img class="tex-graphics" src="https://espresso.codeforces.com/819001df7229138db3a407713744d1e3be88b64e.png" style="max-width: 100.0%;max-height: 100.0%;"/> On third step we color all vertices in the subtree of vertex 6 into color 2: <img class="tex-graphics" src="https://espresso.codeforces.com/80ebbd870a0a339636a21b9acdaf9de046458b43.png" style="max-width: 100.0%;max-height: 100.0%;"/> On fourth step we color all vertices in the subtree of vertex 4 into color 1: <img class="tex-graphics" src="https://espresso.codeforces.com/ed836aa723ac0176abde4e32988e3ac205014e93.png" style="max-width: 100.0%;max-height: 100.0%;"/> On fith step we color all vertices in the subtree of vertex 7 into color 3: <img class="tex-graphics" src="https://espresso.codeforces.com/8132909e11b41c27b8df2f0b0c10bc841f35e58a.png" style="max-width: 100.0%;max-height: 100.0%;"/>
```python n = int(input()) nodes = list(map(int,input().split())) color = list(map(int,input().split())) from collections import defaultdict def DFS(d,x,visited,color): c = 0 visited[x] = 1 z = 0 for j in d[x]: if visited[j] == 0 and color[x-1] != color[j-1]: c = c + 1 + DFS(d,j,visited,color) elif visited[j] == 0 and color[x-1] == color[j-1]: c = c + DFS(d,j,visited,color) return c d = defaultdict(list) for i in range(n-1): d[nodes[i]].append(i+2) t = 1 visited = [0 for i in range(n+1)] c = 1 print(DFS(d,t,visited,color)+1) ```
-1
585
A
Gennady the Dentist
PROGRAMMING
1,800
[ "brute force", "implementation" ]
null
null
Gennady is one of the best child dentists in Berland. Today *n* children got an appointment with him, they lined up in front of his office. All children love to cry loudly at the reception at the dentist. We enumerate the children with integers from 1 to *n* in the order they go in the line. Every child is associated with the value of his cofidence *p**i*. The children take turns one after another to come into the office; each time the child that is the first in the line goes to the doctor. While Gennady treats the teeth of the *i*-th child, the child is crying with the volume of *v**i*. At that the confidence of the first child in the line is reduced by the amount of *v**i*, the second one — by value *v**i*<=-<=1, and so on. The children in the queue after the *v**i*-th child almost do not hear the crying, so their confidence remains unchanged. If at any point in time the confidence of the *j*-th child is less than zero, he begins to cry with the volume of *d**j* and leaves the line, running towards the exit, without going to the doctor's office. At this the confidence of all the children after the *j*-th one in the line is reduced by the amount of *d**j*. All these events occur immediately one after the other in some order. Some cries may lead to other cries, causing a chain reaction. Once in the hallway it is quiet, the child, who is first in the line, goes into the doctor's office. Help Gennady the Dentist to determine the numbers of kids, whose teeth he will cure. Print their numbers in the chronological order.
The first line of the input contains a positive integer *n* (1<=≤<=*n*<=≤<=4000) — the number of kids in the line. Next *n* lines contain three integers each *v**i*,<=*d**i*,<=*p**i* (1<=≤<=*v**i*,<=*d**i*,<=*p**i*<=≤<=106) — the volume of the cry in the doctor's office, the volume of the cry in the hall and the confidence of the *i*-th child.
In the first line print number *k* — the number of children whose teeth Gennady will cure. In the second line print *k* integers — the numbers of the children who will make it to the end of the line in the increasing order.
[ "5\n4 2 2\n4 1 2\n5 2 4\n3 3 5\n5 1 2\n", "5\n4 5 1\n5 3 9\n4 1 2\n2 1 8\n4 1 9\n" ]
[ "2\n1 3 ", "4\n1 2 4 5 " ]
In the first example, Gennady first treats the teeth of the first child who will cry with volume 4. The confidences of the remaining children will get equal to  - 2, 1, 3, 1, respectively. Thus, the second child also cries at the volume of 1 and run to the exit. The confidence of the remaining children will be equal to 0, 2, 0. Then the third child will go to the office, and cry with volume 5. The other children won't bear this, and with a loud cry they will run to the exit. In the second sample, first the first child goes into the office, he will cry with volume 4. The confidence of the remaining children will be equal to 5,  - 1, 6, 8. Thus, the third child will cry with the volume of 1 and run to the exit. The confidence of the remaining children will be equal to 5, 5, 7. After that, the second child goes to the office and cry with the volume of 5. The confidences of the remaining children will be equal to 0, 3. Then the fourth child will go into the office and cry with the volume of 2. Because of this the confidence of the fifth child will be 1, and he will go into the office last.
500
[ { "input": "5\n4 2 2\n4 1 2\n5 2 4\n3 3 5\n5 1 2", "output": "2\n1 3 " }, { "input": "5\n4 5 1\n5 3 9\n4 1 2\n2 1 8\n4 1 9", "output": "4\n1 2 4 5 " }, { "input": "10\n10 7 10\n3 6 11\n8 4 10\n10 1 11\n7 3 13\n7 2 13\n7 6 14\n3 4 17\n9 4 20\n5 2 24", "output": "3\n1 2 5 " }, { "input": "10\n5 6 3\n7 4 10\n9 1 17\n2 8 23\n9 10 24\n6 8 18\n3 2 35\n7 6 6\n1 3 12\n9 9 5", "output": "6\n1 2 3 4 5 7 " }, { "input": "10\n4 9 1\n8 2 14\n7 10 20\n6 9 18\n5 3 19\n2 9 7\n6 8 30\n8 7 38\n6 5 5\n6 9 37", "output": "8\n1 2 3 4 5 7 8 10 " }, { "input": "10\n10 3 3\n8 6 17\n9 5 26\n10 7 17\n3 10 29\n3 1 27\n3 3 7\n8 10 28\n1 3 23\n3 4 6", "output": "5\n1 2 3 5 8 " }, { "input": "10\n5 6 1\n9 2 6\n4 1 5\n4 10 5\n1 8 23\n9 4 21\n3 9 6\n7 8 34\n7 4 24\n8 9 21", "output": "5\n1 2 5 6 8 " }, { "input": "4\n2 10 1\n1 2 2\n2 1 1\n5 5 1", "output": "3\n1 2 4 " }, { "input": "1\n1 1 1", "output": "1\n1 " }, { "input": "2\n5 1 1\n1 1 5", "output": "2\n1 2 " }, { "input": "2\n5 1 1\n1 1 4", "output": "1\n1 " }, { "input": "2\n5 1 1\n1 1 6", "output": "2\n1 2 " }, { "input": "3\n5 1 1\n1 1 4\n1 1 4", "output": "1\n1 " }, { "input": "3\n5 1 1\n1 1 4\n1 1 5", "output": "2\n1 3 " }, { "input": "3\n5 1 1\n1 1 5\n1 1 3", "output": "2\n1 2 " }, { "input": "3\n5 1 1\n10 1 5\n1000 1000 14", "output": "3\n1 2 3 " }, { "input": "10\n9 8 8\n2 9 33\n10 7 42\n7 2 18\n3 5 82\n9 9 25\n3 2 86\n3 5 49\n5 3 72\n4 4 71", "output": "10\n1 2 3 4 5 6 7 8 9 10 " }, { "input": "10\n9 8 8\n2 9 8\n10 7 16\n7 2 9\n3 5 23\n9 9 25\n3 2 35\n3 5 36\n5 3 40\n4 4 42", "output": "1\n1 " } ]
1,644,608,242
2,147,483,647
PyPy 3
RUNTIME_ERROR
TESTS
0
77
2,150,400
from dataclasses import dataclass @dataclass class Child: num: int pain: int loudness: int conf: int alive: bool k = int(input()) children = [] for i in range(1, k + 1): p, l, c = map(int, input().split()) children.append(Child(i, p, l, c, True)) index = 0 res = [] def panic(c): c.alive = False for i in range(c.num, k): children[i].conf -= c.loudness def step(): cured = children[index] cured.alive = False res.append(cured) l = cured.pain for i, l2 in zip(range(index+1, k), range(l, -1, -1)): children[i].conf -= l2 for c in children: if c.alive and c.conf < 0: panic(c) while index < k: step() while index < k and not children[index].alive: index += 1 print(len(res)) for c in res : print(c.num, end=" ")
Title: Gennady the Dentist Time Limit: None seconds Memory Limit: None megabytes Problem Description: Gennady is one of the best child dentists in Berland. Today *n* children got an appointment with him, they lined up in front of his office. All children love to cry loudly at the reception at the dentist. We enumerate the children with integers from 1 to *n* in the order they go in the line. Every child is associated with the value of his cofidence *p**i*. The children take turns one after another to come into the office; each time the child that is the first in the line goes to the doctor. While Gennady treats the teeth of the *i*-th child, the child is crying with the volume of *v**i*. At that the confidence of the first child in the line is reduced by the amount of *v**i*, the second one — by value *v**i*<=-<=1, and so on. The children in the queue after the *v**i*-th child almost do not hear the crying, so their confidence remains unchanged. If at any point in time the confidence of the *j*-th child is less than zero, he begins to cry with the volume of *d**j* and leaves the line, running towards the exit, without going to the doctor's office. At this the confidence of all the children after the *j*-th one in the line is reduced by the amount of *d**j*. All these events occur immediately one after the other in some order. Some cries may lead to other cries, causing a chain reaction. Once in the hallway it is quiet, the child, who is first in the line, goes into the doctor's office. Help Gennady the Dentist to determine the numbers of kids, whose teeth he will cure. Print their numbers in the chronological order. Input Specification: The first line of the input contains a positive integer *n* (1<=≤<=*n*<=≤<=4000) — the number of kids in the line. Next *n* lines contain three integers each *v**i*,<=*d**i*,<=*p**i* (1<=≤<=*v**i*,<=*d**i*,<=*p**i*<=≤<=106) — the volume of the cry in the doctor's office, the volume of the cry in the hall and the confidence of the *i*-th child. Output Specification: In the first line print number *k* — the number of children whose teeth Gennady will cure. In the second line print *k* integers — the numbers of the children who will make it to the end of the line in the increasing order. Demo Input: ['5\n4 2 2\n4 1 2\n5 2 4\n3 3 5\n5 1 2\n', '5\n4 5 1\n5 3 9\n4 1 2\n2 1 8\n4 1 9\n'] Demo Output: ['2\n1 3 ', '4\n1 2 4 5 '] Note: In the first example, Gennady first treats the teeth of the first child who will cry with volume 4. The confidences of the remaining children will get equal to  - 2, 1, 3, 1, respectively. Thus, the second child also cries at the volume of 1 and run to the exit. The confidence of the remaining children will be equal to 0, 2, 0. Then the third child will go to the office, and cry with volume 5. The other children won't bear this, and with a loud cry they will run to the exit. In the second sample, first the first child goes into the office, he will cry with volume 4. The confidence of the remaining children will be equal to 5,  - 1, 6, 8. Thus, the third child will cry with the volume of 1 and run to the exit. The confidence of the remaining children will be equal to 5, 5, 7. After that, the second child goes to the office and cry with the volume of 5. The confidences of the remaining children will be equal to 0, 3. Then the fourth child will go into the office and cry with the volume of 2. Because of this the confidence of the fifth child will be 1, and he will go into the office last.
```python from dataclasses import dataclass @dataclass class Child: num: int pain: int loudness: int conf: int alive: bool k = int(input()) children = [] for i in range(1, k + 1): p, l, c = map(int, input().split()) children.append(Child(i, p, l, c, True)) index = 0 res = [] def panic(c): c.alive = False for i in range(c.num, k): children[i].conf -= c.loudness def step(): cured = children[index] cured.alive = False res.append(cured) l = cured.pain for i, l2 in zip(range(index+1, k), range(l, -1, -1)): children[i].conf -= l2 for c in children: if c.alive and c.conf < 0: panic(c) while index < k: step() while index < k and not children[index].alive: index += 1 print(len(res)) for c in res : print(c.num, end=" ") ```
-1
372
A
Counting Kangaroos is Fun
PROGRAMMING
1,600
[ "binary search", "greedy", "sortings", "two pointers" ]
null
null
There are *n* kangaroos with pockets. Each kangaroo has a size (integer number). A kangaroo can go into another kangaroo's pocket if and only if the size of kangaroo who hold the kangaroo is at least twice as large as the size of kangaroo who is held. Each kangaroo can hold at most one kangaroo, and the kangaroo who is held by another kangaroo cannot hold any kangaroos. The kangaroo who is held by another kangaroo cannot be visible from outside. Please, find a plan of holding kangaroos with the minimal number of kangaroos who is visible.
The first line contains a single integer — *n* (1<=≤<=*n*<=≤<=5·105). Each of the next *n* lines contains an integer *s**i* — the size of the *i*-th kangaroo (1<=≤<=*s**i*<=≤<=105).
Output a single integer — the optimal number of visible kangaroos.
[ "8\n2\n5\n7\n6\n9\n8\n4\n2\n", "8\n9\n1\n6\n2\n6\n5\n8\n3\n" ]
[ "5\n", "5\n" ]
none
500
[ { "input": "8\n2\n5\n7\n6\n9\n8\n4\n2", "output": "5" }, { "input": "8\n9\n1\n6\n2\n6\n5\n8\n3", "output": "5" }, { "input": "12\n3\n99\n24\n46\n75\n63\n57\n55\n10\n62\n34\n52", "output": "7" }, { "input": "12\n55\n75\n1\n98\n63\n64\n9\n39\n82\n18\n47\n9", "output": "6" }, { "input": "100\n678\n771\n96\n282\n135\n749\n168\n668\n17\n658\n979\n446\n998\n331\n606\n756\n37\n515\n538\n205\n647\n547\n904\n842\n647\n286\n774\n414\n267\n791\n595\n465\n8\n327\n855\n174\n339\n946\n184\n250\n807\n422\n679\n980\n64\n530\n312\n351\n676\n911\n803\n991\n669\n50\n293\n841\n545\n598\n737\n894\n231\n754\n588\n83\n873\n767\n833\n482\n905\n903\n970\n571\n715\n59\n777\n697\n537\n861\n339\n212\n149\n889\n905\n70\n970\n307\n830\n465\n968\n291\n430\n317\n942\n944\n330\n235\n814\n880\n415\n76", "output": "58" }, { "input": "100\n154\n60\n97\n638\n139\n150\n570\n579\n601\n647\n804\n237\n245\n549\n288\n347\n778\n282\n916\n441\n974\n145\n957\n886\n655\n702\n930\n618\n132\n520\n972\n48\n94\n54\n682\n433\n896\n134\n845\n636\n242\n842\n125\n141\n240\n130\n409\n666\n948\n938\n604\n110\n474\n484\n364\n40\n807\n271\n438\n288\n201\n814\n754\n589\n341\n576\n146\n952\n819\n923\n222\n535\n336\n83\n314\n911\n303\n911\n384\n601\n249\n330\n735\n271\n142\n204\n405\n783\n775\n449\n590\n139\n109\n276\n45\n205\n454\n836\n82\n841", "output": "50" }, { "input": "1\n1", "output": "1" }, { "input": "4\n1\n1\n1\n2", "output": "3" }, { "input": "5\n1\n2\n4\n8\n16", "output": "3" }, { "input": "7\n1\n2\n4\n8\n16\n32\n64", "output": "4" }, { "input": "3\n1\n2\n4", "output": "2" } ]
1,696,153,586
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
31
0
def minimal_visible_kangaroos(kangaroos): kangaroos.sort(reverse=True, key=lambda x: x[0]) visible_kangaroos = [] held_kangaroos = [] for kangaroo in kangaroos: size, index = kangaroo if not held_kangaroos or size < held_kangaroos[0][0] * 2: visible_kangaroos.append((size, index)) else: held_kangaroos.insert(0, (size, index)) visible_kangaroos_indices = [index for _, index in visible_kangaroos] return visible_kangaroos_indices # Input n = int(input()) sizes = list(map(int, input().split())) kangaroos = [(sizes[i], i) for i in range(n)] # Calculate and print the minimal number of visible kangaroos result = minimal_visible_kangaroos(kangaroos) print(len(result)) print(*result)
Title: Counting Kangaroos is Fun Time Limit: None seconds Memory Limit: None megabytes Problem Description: There are *n* kangaroos with pockets. Each kangaroo has a size (integer number). A kangaroo can go into another kangaroo's pocket if and only if the size of kangaroo who hold the kangaroo is at least twice as large as the size of kangaroo who is held. Each kangaroo can hold at most one kangaroo, and the kangaroo who is held by another kangaroo cannot hold any kangaroos. The kangaroo who is held by another kangaroo cannot be visible from outside. Please, find a plan of holding kangaroos with the minimal number of kangaroos who is visible. Input Specification: The first line contains a single integer — *n* (1<=≤<=*n*<=≤<=5·105). Each of the next *n* lines contains an integer *s**i* — the size of the *i*-th kangaroo (1<=≤<=*s**i*<=≤<=105). Output Specification: Output a single integer — the optimal number of visible kangaroos. Demo Input: ['8\n2\n5\n7\n6\n9\n8\n4\n2\n', '8\n9\n1\n6\n2\n6\n5\n8\n3\n'] Demo Output: ['5\n', '5\n'] Note: none
```python def minimal_visible_kangaroos(kangaroos): kangaroos.sort(reverse=True, key=lambda x: x[0]) visible_kangaroos = [] held_kangaroos = [] for kangaroo in kangaroos: size, index = kangaroo if not held_kangaroos or size < held_kangaroos[0][0] * 2: visible_kangaroos.append((size, index)) else: held_kangaroos.insert(0, (size, index)) visible_kangaroos_indices = [index for _, index in visible_kangaroos] return visible_kangaroos_indices # Input n = int(input()) sizes = list(map(int, input().split())) kangaroos = [(sizes[i], i) for i in range(n)] # Calculate and print the minimal number of visible kangaroos result = minimal_visible_kangaroos(kangaroos) print(len(result)) print(*result) ```
-1
20
A
BerOS file system
PROGRAMMING
1,700
[ "implementation" ]
A. BerOS file system
2
64
The new operating system BerOS has a nice feature. It is possible to use any number of characters '/' as a delimiter in path instead of one traditional '/'. For example, strings //usr///local//nginx/sbin// and /usr/local/nginx///sbin are equivalent. The character '/' (or some sequence of such characters) at the end of the path is required only in case of the path to the root directory, which can be represented as single character '/'. A path called normalized if it contains the smallest possible number of characters '/'. Your task is to transform a given path to the normalized form.
The first line of the input contains only lowercase Latin letters and character '/' — the path to some directory. All paths start with at least one character '/'. The length of the given line is no more than 100 characters, it is not empty.
The path in normalized form.
[ "//usr///local//nginx/sbin\n" ]
[ "/usr/local/nginx/sbin\n" ]
none
500
[ { "input": "//usr///local//nginx/sbin", "output": "/usr/local/nginx/sbin" }, { "input": "////a//b/////g", "output": "/a/b/g" }, { "input": "/a/b/c", "output": "/a/b/c" }, { "input": "/", "output": "/" }, { "input": "////", "output": "/" }, { "input": "/a//aa/a//", "output": "/a/aa/a" }, { "input": "/aa//b/aa", "output": "/aa/b/aa" }, { "input": "////////////////////////////////////////////////////////////////////////////////////////////////////", "output": "/" }, { "input": "/opt///pokerband///srvb/opt///pokerband///srvb////pokerband///srvb/", "output": "/opt/pokerband/srvb/opt/pokerband/srvb/pokerband/srvb" }, { "input": "/root/pokerband/trunk/server/game/code/src/main/java/com/uosipa/pokerband/gameserver/game/", "output": "/root/pokerband/trunk/server/game/code/src/main/java/com/uosipa/pokerband/gameserver/game" }, { "input": "/root//pokerband/trunk/server/game/code/src///main/java/com/uosipa/pokerband//gameserver/game//", "output": "/root/pokerband/trunk/server/game/code/src/main/java/com/uosipa/pokerband/gameserver/game" }, { "input": "/root//pokerband/trunk/server/game/code/src///main/java/com/uosipa/pokerband//gameserver/game//test/", "output": "/root/pokerband/trunk/server/game/code/src/main/java/com/uosipa/pokerband/gameserver/game/test" }, { "input": "/root//pokerband/trunk/server/game/code/src///main/java/com/uosipa/pokerband//gameserver/game//testt", "output": "/root/pokerband/trunk/server/game/code/src/main/java/com/uosipa/pokerband/gameserver/game/testt" }, { "input": "///a//a////a/a//a//a//a/////", "output": "/a/a/a/a/a/a/a" }, { "input": "/zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz", "output": "/zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz" }, { "input": "/zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz/", "output": "/zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz" }, { "input": "/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a", "output": "/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a/a" }, { "input": "///////////////////////////////////////////////////////////////////////////////////////////////////z", "output": "/z" }, { "input": "/z//////////////////////////////////////////////////////////////////////////////////////////////////", "output": "/z" } ]
1,642,166,560
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
5
62
0
s = input() while "//" in s: s = s.replace("//", "/", 1000) print(s)
Title: BerOS file system Time Limit: 2 seconds Memory Limit: 64 megabytes Problem Description: The new operating system BerOS has a nice feature. It is possible to use any number of characters '/' as a delimiter in path instead of one traditional '/'. For example, strings //usr///local//nginx/sbin// and /usr/local/nginx///sbin are equivalent. The character '/' (or some sequence of such characters) at the end of the path is required only in case of the path to the root directory, which can be represented as single character '/'. A path called normalized if it contains the smallest possible number of characters '/'. Your task is to transform a given path to the normalized form. Input Specification: The first line of the input contains only lowercase Latin letters and character '/' — the path to some directory. All paths start with at least one character '/'. The length of the given line is no more than 100 characters, it is not empty. Output Specification: The path in normalized form. Demo Input: ['//usr///local//nginx/sbin\n'] Demo Output: ['/usr/local/nginx/sbin\n'] Note: none
```python s = input() while "//" in s: s = s.replace("//", "/", 1000) print(s) ```
0
131
A
cAPS lOCK
PROGRAMMING
1,000
[ "implementation", "strings" ]
null
null
wHAT DO WE NEED cAPS LOCK FOR? Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in the first passage. Let's consider that a word has been typed with the Caps lock key accidentally switched on, if: - either it only contains uppercase letters; - or all letters except for the first one are uppercase. In this case we should automatically change the case of all letters. For example, the case of the letters that form words "hELLO", "HTTP", "z" should be changed. Write a program that applies the rule mentioned above. If the rule cannot be applied, the program should leave the word unchanged.
The first line of the input data contains a word consisting of uppercase and lowercase Latin letters. The word's length is from 1 to 100 characters, inclusive.
Print the result of the given word's processing.
[ "cAPS\n", "Lock\n" ]
[ "Caps", "Lock\n" ]
none
500
[ { "input": "cAPS", "output": "Caps" }, { "input": "Lock", "output": "Lock" }, { "input": "cAPSlOCK", "output": "cAPSlOCK" }, { "input": "CAPs", "output": "CAPs" }, { "input": "LoCK", "output": "LoCK" }, { "input": "OOPS", "output": "oops" }, { "input": "oops", "output": "oops" }, { "input": "a", "output": "A" }, { "input": "A", "output": "a" }, { "input": "aA", "output": "Aa" }, { "input": "Zz", "output": "Zz" }, { "input": "Az", "output": "Az" }, { "input": "zA", "output": "Za" }, { "input": "AAA", "output": "aaa" }, { "input": "AAa", "output": "AAa" }, { "input": "AaR", "output": "AaR" }, { "input": "Tdr", "output": "Tdr" }, { "input": "aTF", "output": "Atf" }, { "input": "fYd", "output": "fYd" }, { "input": "dsA", "output": "dsA" }, { "input": "fru", "output": "fru" }, { "input": "hYBKF", "output": "Hybkf" }, { "input": "XweAR", "output": "XweAR" }, { "input": "mogqx", "output": "mogqx" }, { "input": "eOhEi", "output": "eOhEi" }, { "input": "nkdku", "output": "nkdku" }, { "input": "zcnko", "output": "zcnko" }, { "input": "lcccd", "output": "lcccd" }, { "input": "vwmvg", "output": "vwmvg" }, { "input": "lvchf", "output": "lvchf" }, { "input": "IUNVZCCHEWENCHQQXQYPUJCRDZLUXCLJHXPHBXEUUGNXOOOPBMOBRIBHHMIRILYJGYYGFMTMFSVURGYHUWDRLQVIBRLPEVAMJQYO", "output": "iunvzcchewenchqqxqypujcrdzluxcljhxphbxeuugnxooopbmobribhhmirilyjgyygfmtmfsvurgyhuwdrlqvibrlpevamjqyo" }, { "input": "OBHSZCAMDXEJWOZLKXQKIVXUUQJKJLMMFNBPXAEFXGVNSKQLJGXHUXHGCOTESIVKSFMVVXFVMTEKACRIWALAGGMCGFEXQKNYMRTG", "output": "obhszcamdxejwozlkxqkivxuuqjkjlmmfnbpxaefxgvnskqljgxhuxhgcotesivksfmvvxfvmtekacriwalaggmcgfexqknymrtg" }, { "input": "IKJYZIKROIYUUCTHSVSKZTETNNOCMAUBLFJCEVANCADASMZRCNLBZPQRXESHEEMOMEPCHROSRTNBIDXYMEPJSIXSZQEBTEKKUHFS", "output": "ikjyzikroiyuucthsvskztetnnocmaublfjcevancadasmzrcnlbzpqrxesheemomepchrosrtnbidxymepjsixszqebtekkuhfs" }, { "input": "cTKDZNWVYRTFPQLDAUUNSPKTDJTUPPFPRXRSINTVFVNNQNKXWUZUDHZBUSOKTABUEDQKUIVRTTVUREEOBJTSDKJKVEGFXVHXEYPE", "output": "Ctkdznwvyrtfpqldauunspktdjtuppfprxrsintvfvnnqnkxwuzudhzbusoktabuedqkuivrttvureeobjtsdkjkvegfxvhxeype" }, { "input": "uCKJZRGZJCPPLEEYJTUNKOQSWGBMTBQEVPYFPIPEKRVYQNTDPANOIXKMPINNFUSZWCURGBDPYTEKBEKCPMVZPMWAOSHJYMGKOMBQ", "output": "Uckjzrgzjcppleeyjtunkoqswgbmtbqevpyfpipekrvyqntdpanoixkmpinnfuszwcurgbdpytekbekcpmvzpmwaoshjymgkombq" }, { "input": "KETAXTSWAAOBKUOKUQREHIOMVMMRSAEWKGXZKRASwTVNSSFSNIWYNPSTMRADOADEEBURRHPOOBIEUIBGYDJCEKPNLEUCANZYJKMR", "output": "KETAXTSWAAOBKUOKUQREHIOMVMMRSAEWKGXZKRASwTVNSSFSNIWYNPSTMRADOADEEBURRHPOOBIEUIBGYDJCEKPNLEUCANZYJKMR" }, { "input": "ZEKGDMWJPVUWFlNXRLUmWKLMMYSLRQQIBRWDPKWITUIMZYYKOEYGREKHHZRZZUFPVTNIHKGTCCTLOKSZITXXZDMPITHNZUIGDZLE", "output": "ZEKGDMWJPVUWFlNXRLUmWKLMMYSLRQQIBRWDPKWITUIMZYYKOEYGREKHHZRZZUFPVTNIHKGTCCTLOKSZITXXZDMPITHNZUIGDZLE" }, { "input": "TcMbVPCFvnNkCEUUCIFLgBJeCOKuJhIGwXFrhAZjuAhBraMSchBfWwIuHAEbgJOFzGtxDLDXzDSaPCFujGGxgxdlHUIQYRrMFCgJ", "output": "TcMbVPCFvnNkCEUUCIFLgBJeCOKuJhIGwXFrhAZjuAhBraMSchBfWwIuHAEbgJOFzGtxDLDXzDSaPCFujGGxgxdlHUIQYRrMFCgJ" }, { "input": "xFGqoLILNvxARKuIntPfeukFtMbvzDezKpPRAKkIoIvwqNXnehRVwkkXYvuRCeoieBaBfTjwsYhDeCLvBwktntyluoxCYVioXGdm", "output": "xFGqoLILNvxARKuIntPfeukFtMbvzDezKpPRAKkIoIvwqNXnehRVwkkXYvuRCeoieBaBfTjwsYhDeCLvBwktntyluoxCYVioXGdm" }, { "input": "udvqolbxdwbkijwvhlyaelhynmnfgszbhgshlcwdkaibceqomzujndixuzivlsjyjqxzxodzbukxxhwwultvekdfntwpzlhhrIjm", "output": "udvqolbxdwbkijwvhlyaelhynmnfgszbhgshlcwdkaibceqomzujndixuzivlsjyjqxzxodzbukxxhwwultvekdfntwpzlhhrIjm" }, { "input": "jgpwhetqqoncighgzbbaLwwwxkxivuwtokehrgprfgewzcwxkavwoflcgsgbhoeamzbefzoonwsyzisetoydrpufktzgbaycgaeg", "output": "jgpwhetqqoncighgzbbaLwwwxkxivuwtokehrgprfgewzcwxkavwoflcgsgbhoeamzbefzoonwsyzisetoydrpufktzgbaycgaeg" }, { "input": "vyujsazdstbnkxeunedfbolicojzjpufgfemhtmdrswvmuhoivjvonacefqenbqudelmdegxqtbwezsbydmanzutvdgkgrjxzlnc", "output": "vyujsazdstbnkxeunedfbolicojzjpufgfemhtmdrswvmuhoivjvonacefqenbqudelmdegxqtbwezsbydmanzutvdgkgrjxzlnc" }, { "input": "pivqnuqkaofcduvbttztjbuavrqwiqrwkfncmvatoxruelyoecnkpqraiahumiaiqeyjapbqyrsxcdgjbihivtqezvasfmzntdfv", "output": "pivqnuqkaofcduvbttztjbuavrqwiqrwkfncmvatoxruelyoecnkpqraiahumiaiqeyjapbqyrsxcdgjbihivtqezvasfmzntdfv" }, { "input": "upvtbsxswbohxshdrbjxcungzquhuomgxwlryvshshsfvqbrxvcikbglietlpqkiwbhiqpmdwuqosbtdvyxekkaqiwrbsibpoect", "output": "upvtbsxswbohxshdrbjxcungzquhuomgxwlryvshshsfvqbrxvcikbglietlpqkiwbhiqpmdwuqosbtdvyxekkaqiwrbsibpoect" }, { "input": "cTKDZNWVYRTFPQLDAUUNSPKTDJTUPPFPRXRSINTVFVNNQNKXWUZUDHZBUSOKTABUEDQKUIVRTTVUREEOBJTSDKJKVEGFXVHXEYPE", "output": "Ctkdznwvyrtfpqldauunspktdjtuppfprxrsintvfvnnqnkxwuzudhzbusoktabuedqkuivrttvureeobjtsdkjkvegfxvhxeype" }, { "input": "JEGDOFJOFGJHFROGHOFGMHOFGHORGFHMOu", "output": "JEGDOFJOFGJHFROGHOFGMHOFGHORGFHMOu" }, { "input": "aBACABa", "output": "aBACABa" }, { "input": "AAAAAAAAAAAAAAAAAAAAAAAAaa", "output": "AAAAAAAAAAAAAAAAAAAAAAAAaa" }, { "input": "aaAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", "output": "aaAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" }, { "input": "dDDDDDDDDDDDDD", "output": "Dddddddddddddd" }, { "input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "output": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" }, { "input": "z", "output": "Z" }, { "input": "AZ", "output": "az" }, { "input": "Z", "output": "z" }, { "input": "aAAAA", "output": "Aaaaa" }, { "input": "F", "output": "f" } ]
1,698,172,712
2,147,483,647
Python 3
OK
TESTS
56
46
0
st=input() count=0 for i in st: if i.islower(): count+=1 if count<=1 and st[0].islower(): print(st.title()) elif st.isupper(): print(st.lower()) else: print(st)
Title: cAPS lOCK Time Limit: None seconds Memory Limit: None megabytes Problem Description: wHAT DO WE NEED cAPS LOCK FOR? Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in the first passage. Let's consider that a word has been typed with the Caps lock key accidentally switched on, if: - either it only contains uppercase letters; - or all letters except for the first one are uppercase. In this case we should automatically change the case of all letters. For example, the case of the letters that form words "hELLO", "HTTP", "z" should be changed. Write a program that applies the rule mentioned above. If the rule cannot be applied, the program should leave the word unchanged. Input Specification: The first line of the input data contains a word consisting of uppercase and lowercase Latin letters. The word's length is from 1 to 100 characters, inclusive. Output Specification: Print the result of the given word's processing. Demo Input: ['cAPS\n', 'Lock\n'] Demo Output: ['Caps', 'Lock\n'] Note: none
```python st=input() count=0 for i in st: if i.islower(): count+=1 if count<=1 and st[0].islower(): print(st.title()) elif st.isupper(): print(st.lower()) else: print(st) ```
3
822
A
I'm bored with life
PROGRAMMING
800
[ "implementation", "math", "number theory" ]
null
null
Holidays have finished. Thanks to the help of the hacker Leha, Noora managed to enter the university of her dreams which is located in a town Pavlopolis. It's well known that universities provide students with dormitory for the period of university studies. Consequently Noora had to leave Vičkopolis and move to Pavlopolis. Thus Leha was left completely alone in a quiet town Vičkopolis. He almost even fell into a depression from boredom! Leha came up with a task for himself to relax a little. He chooses two integers *A* and *B* and then calculates the greatest common divisor of integers "*A* factorial" and "*B* factorial". Formally the hacker wants to find out GCD(*A*!,<=*B*!). It's well known that the factorial of an integer *x* is a product of all positive integers less than or equal to *x*. Thus *x*!<==<=1·2·3·...·(*x*<=-<=1)·*x*. For example 4!<==<=1·2·3·4<==<=24. Recall that GCD(*x*,<=*y*) is the largest positive integer *q* that divides (without a remainder) both *x* and *y*. Leha has learned how to solve this task very effective. You are able to cope with it not worse, aren't you?
The first and single line contains two integers *A* and *B* (1<=≤<=*A*,<=*B*<=≤<=109,<=*min*(*A*,<=*B*)<=≤<=12).
Print a single integer denoting the greatest common divisor of integers *A*! and *B*!.
[ "4 3\n" ]
[ "6\n" ]
Consider the sample. 4! = 1·2·3·4 = 24. 3! = 1·2·3 = 6. The greatest common divisor of integers 24 and 6 is exactly 6.
500
[ { "input": "4 3", "output": "6" }, { "input": "10 399603090", "output": "3628800" }, { "input": "6 973151934", "output": "720" }, { "input": "2 841668075", "output": "2" }, { "input": "7 415216919", "output": "5040" }, { "input": "3 283733059", "output": "6" }, { "input": "11 562314608", "output": "39916800" }, { "input": "3 990639260", "output": "6" }, { "input": "11 859155400", "output": "39916800" }, { "input": "1 1", "output": "1" }, { "input": "5 3", "output": "6" }, { "input": "1 4", "output": "1" }, { "input": "5 4", "output": "24" }, { "input": "1 12", "output": "1" }, { "input": "9 7", "output": "5040" }, { "input": "2 3", "output": "2" }, { "input": "6 11", "output": "720" }, { "input": "6 7", "output": "720" }, { "input": "11 11", "output": "39916800" }, { "input": "4 999832660", "output": "24" }, { "input": "7 999228288", "output": "5040" }, { "input": "11 999257105", "output": "39916800" }, { "input": "11 999286606", "output": "39916800" }, { "input": "3 999279109", "output": "6" }, { "input": "999632727 11", "output": "39916800" }, { "input": "999625230 7", "output": "5040" }, { "input": "999617047 3", "output": "6" }, { "input": "999646548 7", "output": "5040" }, { "input": "999639051 3", "output": "6" }, { "input": "12 12", "output": "479001600" }, { "input": "12 1", "output": "1" }, { "input": "1213 5", "output": "120" }, { "input": "8 9", "output": "40320" }, { "input": "12 9", "output": "362880" }, { "input": "12 1000000000", "output": "479001600" }, { "input": "1000000000 1", "output": "1" }, { "input": "12 13", "output": "479001600" }, { "input": "2 29845", "output": "2" }, { "input": "10 21", "output": "3628800" }, { "input": "12 20", "output": "479001600" }, { "input": "15 12", "output": "479001600" }, { "input": "1 1", "output": "1" }, { "input": "1000000000 12", "output": "479001600" }, { "input": "11 30", "output": "39916800" }, { "input": "17 12", "output": "479001600" }, { "input": "4 19", "output": "24" }, { "input": "12 15", "output": "479001600" }, { "input": "20 6", "output": "720" }, { "input": "10 20", "output": "3628800" }, { "input": "10 10", "output": "3628800" }, { "input": "22 12", "output": "479001600" }, { "input": "20 12", "output": "479001600" }, { "input": "12 23", "output": "479001600" }, { "input": "12 22", "output": "479001600" }, { "input": "18 3", "output": "6" }, { "input": "14 10", "output": "3628800" }, { "input": "14 12", "output": "479001600" }, { "input": "8 3", "output": "6" }, { "input": "5 5", "output": "120" } ]
1,631,038,094
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
1
1,000
8,908,800
import math n= list(map(int, (input().split()))) def gcd(a,b): # Everything divides 0 if (b == 0): return a return gcd(b, a%b) print(gcd(math.factorial(n[0]), math.factorial(n[1])))
Title: I'm bored with life Time Limit: None seconds Memory Limit: None megabytes Problem Description: Holidays have finished. Thanks to the help of the hacker Leha, Noora managed to enter the university of her dreams which is located in a town Pavlopolis. It's well known that universities provide students with dormitory for the period of university studies. Consequently Noora had to leave Vičkopolis and move to Pavlopolis. Thus Leha was left completely alone in a quiet town Vičkopolis. He almost even fell into a depression from boredom! Leha came up with a task for himself to relax a little. He chooses two integers *A* and *B* and then calculates the greatest common divisor of integers "*A* factorial" and "*B* factorial". Formally the hacker wants to find out GCD(*A*!,<=*B*!). It's well known that the factorial of an integer *x* is a product of all positive integers less than or equal to *x*. Thus *x*!<==<=1·2·3·...·(*x*<=-<=1)·*x*. For example 4!<==<=1·2·3·4<==<=24. Recall that GCD(*x*,<=*y*) is the largest positive integer *q* that divides (without a remainder) both *x* and *y*. Leha has learned how to solve this task very effective. You are able to cope with it not worse, aren't you? Input Specification: The first and single line contains two integers *A* and *B* (1<=≤<=*A*,<=*B*<=≤<=109,<=*min*(*A*,<=*B*)<=≤<=12). Output Specification: Print a single integer denoting the greatest common divisor of integers *A*! and *B*!. Demo Input: ['4 3\n'] Demo Output: ['6\n'] Note: Consider the sample. 4! = 1·2·3·4 = 24. 3! = 1·2·3 = 6. The greatest common divisor of integers 24 and 6 is exactly 6.
```python import math n= list(map(int, (input().split()))) def gcd(a,b): # Everything divides 0 if (b == 0): return a return gcd(b, a%b) print(gcd(math.factorial(n[0]), math.factorial(n[1]))) ```
0
337
A
Puzzles
PROGRAMMING
900
[ "greedy" ]
null
null
The end of the school year is near and Ms. Manana, the teacher, will soon have to say goodbye to a yet another class. She decided to prepare a goodbye present for her *n* students and give each of them a jigsaw puzzle (which, as wikipedia states, is a tiling puzzle that requires the assembly of numerous small, often oddly shaped, interlocking and tessellating pieces). The shop assistant told the teacher that there are *m* puzzles in the shop, but they might differ in difficulty and size. Specifically, the first jigsaw puzzle consists of *f*1 pieces, the second one consists of *f*2 pieces and so on. Ms. Manana doesn't want to upset the children, so she decided that the difference between the numbers of pieces in her presents must be as small as possible. Let *A* be the number of pieces in the largest puzzle that the teacher buys and *B* be the number of pieces in the smallest such puzzle. She wants to choose such *n* puzzles that *A*<=-<=*B* is minimum possible. Help the teacher and find the least possible value of *A*<=-<=*B*.
The first line contains space-separated integers *n* and *m* (2<=≤<=*n*<=≤<=*m*<=≤<=50). The second line contains *m* space-separated integers *f*1,<=*f*2,<=...,<=*f**m* (4<=≤<=*f**i*<=≤<=1000) — the quantities of pieces in the puzzles sold in the shop.
Print a single integer — the least possible difference the teacher can obtain.
[ "4 6\n10 12 10 7 5 22\n" ]
[ "5\n" ]
Sample 1. The class has 4 students. The shop sells 6 puzzles. If Ms. Manana buys the first four puzzles consisting of 10, 12, 10 and 7 pieces correspondingly, then the difference between the sizes of the largest and the smallest puzzle will be equal to 5. It is impossible to obtain a smaller difference. Note that the teacher can also buy puzzles 1, 3, 4 and 5 to obtain the difference 5.
500
[ { "input": "4 6\n10 12 10 7 5 22", "output": "5" }, { "input": "2 2\n4 4", "output": "0" }, { "input": "2 10\n4 5 6 7 8 9 10 11 12 12", "output": "0" }, { "input": "4 5\n818 136 713 59 946", "output": "759" }, { "input": "3 20\n446 852 783 313 549 965 40 88 86 617 479 118 768 34 47 826 366 957 463 903", "output": "13" }, { "input": "2 25\n782 633 152 416 432 825 115 97 386 357 836 310 530 413 354 373 847 882 913 682 729 582 671 674 94", "output": "3" }, { "input": "4 25\n226 790 628 528 114 64 239 279 619 39 894 763 763 847 525 93 882 697 999 643 650 244 159 884 190", "output": "31" }, { "input": "2 50\n971 889 628 39 253 157 925 694 129 516 660 272 738 319 611 816 142 717 514 392 41 105 132 676 958 118 306 768 600 685 103 857 704 346 857 309 23 718 618 161 176 379 846 834 640 468 952 878 164 997", "output": "0" }, { "input": "25 50\n582 146 750 905 313 509 402 21 488 512 32 898 282 64 579 869 37 996 377 929 975 697 666 837 311 205 116 992 533 298 648 268 54 479 792 595 152 69 267 417 184 433 894 603 988 712 24 414 301 176", "output": "412" }, { "input": "49 50\n58 820 826 960 271 294 473 102 925 318 729 672 244 914 796 646 868 6 893 882 726 203 528 498 271 195 355 459 721 680 547 147 631 116 169 804 145 996 133 559 110 257 771 476 576 251 607 314 427 886", "output": "938" }, { "input": "50 50\n374 573 323 744 190 806 485 247 628 336 491 606 702 321 991 678 337 579 86 240 993 208 668 686 855 205 363 177 719 249 896 919 782 434 59 647 787 996 286 216 636 212 546 903 958 559 544 126 608 993", "output": "937" }, { "input": "6 50\n6 8 7 8 5 4 4 5 7 8 6 5 7 4 7 7 7 8 6 4 6 6 8 8 7 7 8 7 5 8 5 4 4 7 8 4 4 6 6 6 8 7 4 7 6 6 5 8 4 7", "output": "0" }, { "input": "37 50\n14 5 11 17 8 20 19 16 20 11 17 20 16 9 14 14 13 18 11 20 8 8 8 5 19 17 6 18 10 20 9 7 12 6 14 17 4 4 10 13 7 4 11 6 20 19 12 12 15 19", "output": "12" }, { "input": "40 50\n4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4", "output": "0" }, { "input": "40 50\n17 20 43 26 41 37 14 8 30 35 30 24 43 8 42 9 41 50 41 35 27 32 35 43 28 36 31 16 5 7 23 16 14 29 8 39 12 16 36 18 49 39 33 37 38 6 6 27 23 17", "output": "31" }, { "input": "2 2\n1000 4", "output": "996" }, { "input": "2 3\n4 502 1000", "output": "498" }, { "input": "3 3\n4 1000 4", "output": "996" } ]
1,683,377,241
2,147,483,647
Python 3
OK
TESTS
18
92
0
def f(): L=[] n,m=list(map(int,input().split())) l=list(map(int,input().split())) l.sort() d=l[-1] for a in range(m-n+1): if d>l[a+n-1]-l[a]: d=l[a+n-1]-l[a] print(d) f()
Title: Puzzles Time Limit: None seconds Memory Limit: None megabytes Problem Description: The end of the school year is near and Ms. Manana, the teacher, will soon have to say goodbye to a yet another class. She decided to prepare a goodbye present for her *n* students and give each of them a jigsaw puzzle (which, as wikipedia states, is a tiling puzzle that requires the assembly of numerous small, often oddly shaped, interlocking and tessellating pieces). The shop assistant told the teacher that there are *m* puzzles in the shop, but they might differ in difficulty and size. Specifically, the first jigsaw puzzle consists of *f*1 pieces, the second one consists of *f*2 pieces and so on. Ms. Manana doesn't want to upset the children, so she decided that the difference between the numbers of pieces in her presents must be as small as possible. Let *A* be the number of pieces in the largest puzzle that the teacher buys and *B* be the number of pieces in the smallest such puzzle. She wants to choose such *n* puzzles that *A*<=-<=*B* is minimum possible. Help the teacher and find the least possible value of *A*<=-<=*B*. Input Specification: The first line contains space-separated integers *n* and *m* (2<=≤<=*n*<=≤<=*m*<=≤<=50). The second line contains *m* space-separated integers *f*1,<=*f*2,<=...,<=*f**m* (4<=≤<=*f**i*<=≤<=1000) — the quantities of pieces in the puzzles sold in the shop. Output Specification: Print a single integer — the least possible difference the teacher can obtain. Demo Input: ['4 6\n10 12 10 7 5 22\n'] Demo Output: ['5\n'] Note: Sample 1. The class has 4 students. The shop sells 6 puzzles. If Ms. Manana buys the first four puzzles consisting of 10, 12, 10 and 7 pieces correspondingly, then the difference between the sizes of the largest and the smallest puzzle will be equal to 5. It is impossible to obtain a smaller difference. Note that the teacher can also buy puzzles 1, 3, 4 and 5 to obtain the difference 5.
```python def f(): L=[] n,m=list(map(int,input().split())) l=list(map(int,input().split())) l.sort() d=l[-1] for a in range(m-n+1): if d>l[a+n-1]-l[a]: d=l[a+n-1]-l[a] print(d) f() ```
3
149
A
Business trip
PROGRAMMING
900
[ "greedy", "implementation", "sortings" ]
null
null
What joy! Petya's parents went on a business trip for the whole year and the playful kid is left all by himself. Petya got absolutely happy. He jumped on the bed and threw pillows all day long, until... Today Petya opened the cupboard and found a scary note there. His parents had left him with duties: he should water their favourite flower all year, each day, in the morning, in the afternoon and in the evening. "Wait a second!" — thought Petya. He know for a fact that if he fulfills the parents' task in the *i*-th (1<=≤<=*i*<=≤<=12) month of the year, then the flower will grow by *a**i* centimeters, and if he doesn't water the flower in the *i*-th month, then the flower won't grow this month. Petya also knows that try as he might, his parents won't believe that he has been watering the flower if it grows strictly less than by *k* centimeters. Help Petya choose the minimum number of months when he will water the flower, given that the flower should grow no less than by *k* centimeters.
The first line contains exactly one integer *k* (0<=≤<=*k*<=≤<=100). The next line contains twelve space-separated integers: the *i*-th (1<=≤<=*i*<=≤<=12) number in the line represents *a**i* (0<=≤<=*a**i*<=≤<=100).
Print the only integer — the minimum number of months when Petya has to water the flower so that the flower grows no less than by *k* centimeters. If the flower can't grow by *k* centimeters in a year, print -1.
[ "5\n1 1 1 1 2 2 3 2 2 1 1 1\n", "0\n0 0 0 0 0 0 0 1 1 2 3 0\n", "11\n1 1 4 1 1 5 1 1 4 1 1 1\n" ]
[ "2\n", "0\n", "3\n" ]
Let's consider the first sample test. There it is enough to water the flower during the seventh and the ninth month. Then the flower grows by exactly five centimeters. In the second sample Petya's parents will believe him even if the flower doesn't grow at all (*k* = 0). So, it is possible for Petya not to water the flower at all.
500
[ { "input": "5\n1 1 1 1 2 2 3 2 2 1 1 1", "output": "2" }, { "input": "0\n0 0 0 0 0 0 0 1 1 2 3 0", "output": "0" }, { "input": "11\n1 1 4 1 1 5 1 1 4 1 1 1", "output": "3" }, { "input": "15\n20 1 1 1 1 2 2 1 2 2 1 1", "output": "1" }, { "input": "7\n8 9 100 12 14 17 21 10 11 100 23 10", "output": "1" }, { "input": "52\n1 12 3 11 4 5 10 6 9 7 8 2", "output": "6" }, { "input": "50\n2 2 3 4 5 4 4 5 7 3 2 7", "output": "-1" }, { "input": "0\n55 81 28 48 99 20 67 95 6 19 10 93", "output": "0" }, { "input": "93\n85 40 93 66 92 43 61 3 64 51 90 21", "output": "1" }, { "input": "99\n36 34 22 0 0 0 52 12 0 0 33 47", "output": "2" }, { "input": "99\n28 32 31 0 10 35 11 18 0 0 32 28", "output": "3" }, { "input": "99\n19 17 0 1 18 11 29 9 29 22 0 8", "output": "4" }, { "input": "76\n2 16 11 10 12 0 20 4 4 14 11 14", "output": "5" }, { "input": "41\n2 1 7 7 4 2 4 4 9 3 10 0", "output": "6" }, { "input": "47\n8 2 2 4 3 1 9 4 2 7 7 8", "output": "7" }, { "input": "58\n6 11 7 0 5 6 3 9 4 9 5 1", "output": "8" }, { "input": "32\n5 2 4 1 5 0 5 1 4 3 0 3", "output": "9" }, { "input": "31\n6 1 0 4 4 5 1 0 5 3 2 0", "output": "9" }, { "input": "35\n2 3 0 0 6 3 3 4 3 5 0 6", "output": "9" }, { "input": "41\n3 1 3 4 3 6 6 1 4 4 0 6", "output": "11" }, { "input": "97\n0 5 3 12 10 16 22 8 21 17 21 10", "output": "5" }, { "input": "100\n21 21 0 0 4 13 0 26 0 0 0 15", "output": "6" }, { "input": "100\n0 0 16 5 22 0 5 0 25 0 14 13", "output": "7" }, { "input": "97\n17 0 10 0 0 0 18 0 14 23 15 0", "output": "6" }, { "input": "100\n0 9 0 18 7 0 0 14 33 3 0 16", "output": "7" }, { "input": "95\n5 2 13 0 15 18 17 0 6 11 0 8", "output": "9" }, { "input": "94\n11 13 0 9 15 8 8 16 3 7 1 3", "output": "11" }, { "input": "96\n8 4 12 15 8 0 4 10 6 6 12 11", "output": "11" }, { "input": "100\n5 5 3 8 6 5 0 3 3 8 1 3", "output": "-1" }, { "input": "100\n1 0 0 1 1 0 1 1 1 1 2 1", "output": "-1" }, { "input": "100\n6 3 2 0 4 1 2 2 2 2 1 1", "output": "-1" }, { "input": "0\n0 0 0 0 0 0 0 0 0 0 0 0", "output": "0" }, { "input": "100\n0 0 0 0 0 0 0 0 0 0 0 0", "output": "-1" }, { "input": "0\n100 100 100 100 100 100 100 100 100 100 100 100", "output": "0" }, { "input": "100\n100 100 100 100 100 100 100 100 100 100 100 100", "output": "1" }, { "input": "12\n1 1 1 1 1 1 1 1 1 1 1 1", "output": "12" }, { "input": "13\n1 1 1 1 1 1 1 1 1 1 1 2", "output": "12" }, { "input": "15\n10 1 1 1 1 1 1 1 1 1 1 1", "output": "6" }, { "input": "1\n0 0 0 0 0 0 0 0 0 0 0 0", "output": "-1" } ]
1,643,464,516
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
35
186
0
k = int(input()) li = list(map(int, input().split())) li.sort(reverse = True) i = 0 c = True while(i<12): if(k<=0): c = False break k-=li[i] i+=1 if(c): print(-1) else: print(i)
Title: Business trip Time Limit: None seconds Memory Limit: None megabytes Problem Description: What joy! Petya's parents went on a business trip for the whole year and the playful kid is left all by himself. Petya got absolutely happy. He jumped on the bed and threw pillows all day long, until... Today Petya opened the cupboard and found a scary note there. His parents had left him with duties: he should water their favourite flower all year, each day, in the morning, in the afternoon and in the evening. "Wait a second!" — thought Petya. He know for a fact that if he fulfills the parents' task in the *i*-th (1<=≤<=*i*<=≤<=12) month of the year, then the flower will grow by *a**i* centimeters, and if he doesn't water the flower in the *i*-th month, then the flower won't grow this month. Petya also knows that try as he might, his parents won't believe that he has been watering the flower if it grows strictly less than by *k* centimeters. Help Petya choose the minimum number of months when he will water the flower, given that the flower should grow no less than by *k* centimeters. Input Specification: The first line contains exactly one integer *k* (0<=≤<=*k*<=≤<=100). The next line contains twelve space-separated integers: the *i*-th (1<=≤<=*i*<=≤<=12) number in the line represents *a**i* (0<=≤<=*a**i*<=≤<=100). Output Specification: Print the only integer — the minimum number of months when Petya has to water the flower so that the flower grows no less than by *k* centimeters. If the flower can't grow by *k* centimeters in a year, print -1. Demo Input: ['5\n1 1 1 1 2 2 3 2 2 1 1 1\n', '0\n0 0 0 0 0 0 0 1 1 2 3 0\n', '11\n1 1 4 1 1 5 1 1 4 1 1 1\n'] Demo Output: ['2\n', '0\n', '3\n'] Note: Let's consider the first sample test. There it is enough to water the flower during the seventh and the ninth month. Then the flower grows by exactly five centimeters. In the second sample Petya's parents will believe him even if the flower doesn't grow at all (*k* = 0). So, it is possible for Petya not to water the flower at all.
```python k = int(input()) li = list(map(int, input().split())) li.sort(reverse = True) i = 0 c = True while(i<12): if(k<=0): c = False break k-=li[i] i+=1 if(c): print(-1) else: print(i) ```
0
350
A
TL
PROGRAMMING
1,200
[ "brute force", "greedy", "implementation" ]
null
null
Valera wanted to prepare a Codesecrof round. He's already got one problem and he wants to set a time limit (TL) on it. Valera has written *n* correct solutions. For each correct solution, he knows its running time (in seconds). Valera has also wrote *m* wrong solutions and for each wrong solution he knows its running time (in seconds). Let's suppose that Valera will set *v* seconds TL in the problem. Then we can say that a solution passes the system testing if its running time is at most *v* seconds. We can also say that a solution passes the system testing with some "extra" time if for its running time, *a* seconds, an inequality 2*a*<=≤<=*v* holds. As a result, Valera decided to set *v* seconds TL, that the following conditions are met: 1. *v* is a positive integer; 1. all correct solutions pass the system testing; 1. at least one correct solution passes the system testing with some "extra" time; 1. all wrong solutions do not pass the system testing; 1. value *v* is minimum among all TLs, for which points 1, 2, 3, 4 hold. Help Valera and find the most suitable TL or else state that such TL doesn't exist.
The first line contains two integers *n*, *m* (1<=≤<=*n*,<=*m*<=≤<=100). The second line contains *n* space-separated positive integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100) — the running time of each of the *n* correct solutions in seconds. The third line contains *m* space-separated positive integers *b*1,<=*b*2,<=...,<=*b**m* (1<=≤<=*b**i*<=≤<=100) — the running time of each of *m* wrong solutions in seconds.
If there is a valid TL value, print it. Otherwise, print -1.
[ "3 6\n4 5 2\n8 9 6 10 7 11\n", "3 1\n3 4 5\n6\n" ]
[ "5", "-1\n" ]
none
500
[ { "input": "3 6\n4 5 2\n8 9 6 10 7 11", "output": "5" }, { "input": "3 1\n3 4 5\n6", "output": "-1" }, { "input": "2 5\n45 99\n49 41 77 83 45", "output": "-1" }, { "input": "50 50\n18 13 5 34 10 36 36 12 15 11 16 17 14 36 23 45 32 24 31 18 24 32 7 1 31 3 49 8 16 23 3 39 47 43 42 38 40 22 41 1 49 47 9 8 19 15 29 30 16 18\n91 58 86 51 94 94 73 84 98 69 74 56 52 80 88 61 53 99 88 50 55 95 65 84 87 79 51 52 69 60 74 73 93 61 73 59 64 56 95 78 86 72 79 70 93 78 54 61 71 50", "output": "49" }, { "input": "55 44\n93 17 74 15 34 16 41 80 26 54 94 94 86 93 20 44 63 72 39 43 67 4 37 49 76 94 5 51 64 74 11 47 77 97 57 30 42 72 71 26 8 14 67 64 49 57 30 23 40 4 76 78 87 78 79\n38 55 17 65 26 7 36 65 48 28 49 93 18 98 31 90 26 57 1 26 88 56 48 56 23 13 8 67 80 2 51 3 21 33 20 54 2 45 21 36 3 98 62 2", "output": "-1" }, { "input": "32 100\n30 8 4 35 18 41 18 12 33 39 39 18 39 19 33 46 45 33 34 27 14 39 40 21 38 9 42 35 27 10 14 14\n65 49 89 64 47 78 59 52 73 51 84 82 88 63 91 99 67 87 53 99 75 47 85 82 58 47 80 50 65 91 83 90 77 52 100 88 97 74 98 99 50 93 65 61 65 65 65 96 61 51 84 67 79 90 92 83 100 100 100 95 80 54 77 51 98 64 74 62 60 96 73 74 94 55 89 60 92 65 74 79 66 81 53 47 71 51 54 85 74 97 68 72 88 94 100 85 65 63 65 90", "output": "46" }, { "input": "1 50\n7\n65 52 99 78 71 19 96 72 80 15 50 94 20 35 79 95 44 41 45 53 77 50 74 66 59 96 26 84 27 48 56 84 36 78 89 81 67 34 79 74 99 47 93 92 90 96 72 28 78 66", "output": "14" }, { "input": "1 1\n4\n9", "output": "8" }, { "input": "1 1\n2\n4", "output": "-1" }, { "input": "22 56\n49 20 42 68 15 46 98 78 82 8 7 33 50 30 75 96 36 88 35 99 19 87\n15 18 81 24 35 89 25 32 23 3 48 24 52 69 18 32 23 61 48 98 50 38 5 17 70 20 38 32 49 54 68 11 51 81 46 22 19 59 29 38 45 83 18 13 91 17 84 62 25 60 97 32 23 13 83 58", "output": "-1" }, { "input": "1 1\n50\n100", "output": "-1" }, { "input": "1 1\n49\n100", "output": "98" }, { "input": "1 1\n100\n100", "output": "-1" }, { "input": "1 1\n99\n100", "output": "-1" }, { "input": "8 4\n1 2 49 99 99 95 78 98\n100 100 100 100", "output": "99" }, { "input": "68 85\n43 55 2 4 72 45 19 56 53 81 18 90 11 87 47 8 94 88 24 4 67 9 21 70 25 66 65 27 46 13 8 51 65 99 37 43 71 59 71 79 32 56 49 43 57 85 95 81 40 28 60 36 72 81 60 40 16 78 61 37 29 26 15 95 70 27 50 97\n6 6 48 72 54 31 1 50 29 64 93 9 29 93 66 63 25 90 52 1 66 13 70 30 24 87 32 90 84 72 44 13 25 45 31 16 92 60 87 40 62 7 20 63 86 78 73 88 5 36 74 100 64 34 9 5 62 29 58 48 81 46 84 56 27 1 60 14 54 88 31 93 62 7 9 69 27 48 10 5 33 10 53 66 2", "output": "-1" }, { "input": "5 100\n1 1 1 1 1\n77 53 38 29 97 33 64 17 78 100 27 12 42 44 20 24 44 68 58 57 65 90 8 24 4 6 74 68 61 43 25 69 8 62 36 85 67 48 69 30 35 41 42 12 87 66 50 92 53 76 38 67 85 7 80 78 53 76 94 8 37 50 4 100 4 71 10 48 34 47 83 42 25 81 64 72 25 51 53 75 43 98 53 77 94 38 81 15 89 91 72 76 7 36 27 41 88 18 19 75", "output": "2" }, { "input": "3 3\n2 3 4\n8 9 10", "output": "4" }, { "input": "2 1\n2 3\n15", "output": "4" }, { "input": "2 1\n2 4\n4", "output": "-1" }, { "input": "2 3\n4 5\n10 11 12", "output": "8" }, { "input": "3 1\n2 3 3\n5", "output": "4" }, { "input": "2 1\n9 10\n100", "output": "18" }, { "input": "3 3\n3 12 15\n7 8 9", "output": "-1" }, { "input": "2 2\n3 5\n7 8", "output": "6" }, { "input": "3 3\n4 5 6\n10 11 12", "output": "8" }, { "input": "3 5\n2 3 3\n6 6 6 6 2", "output": "-1" }, { "input": "3 6\n4 5 3\n8 9 7 10 7 11", "output": "6" }, { "input": "3 6\n4 5 2\n8 9 6 10 7 4", "output": "-1" }, { "input": "2 1\n4 6\n10", "output": "8" }, { "input": "1 2\n1\n3 1", "output": "-1" }, { "input": "2 1\n5 6\n20", "output": "10" }, { "input": "2 1\n1 5\n5", "output": "-1" }, { "input": "3 2\n10 20 30\n30 40", "output": "-1" }, { "input": "2 2\n5 6\n7 100", "output": "-1" }, { "input": "2 1\n2 5\n7", "output": "5" }, { "input": "1 1\n5\n20", "output": "10" }, { "input": "2 1\n10 11\n100", "output": "20" }, { "input": "1 1\n1\n10", "output": "2" }, { "input": "1 1\n10\n100", "output": "20" } ]
1,574,122,747
2,147,483,647
PyPy 3
OK
TESTS
45
312
0
n, m = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) a.sort() v = a[-1] ans = -1 while 1: idx = 0 wrong = False while idx < m: if b[idx] <= v: wrong = True idx = m idx += 1 if wrong == True: break if v < 2 * a[0]: v += 1 continue ans = v break print (ans)
Title: TL Time Limit: None seconds Memory Limit: None megabytes Problem Description: Valera wanted to prepare a Codesecrof round. He's already got one problem and he wants to set a time limit (TL) on it. Valera has written *n* correct solutions. For each correct solution, he knows its running time (in seconds). Valera has also wrote *m* wrong solutions and for each wrong solution he knows its running time (in seconds). Let's suppose that Valera will set *v* seconds TL in the problem. Then we can say that a solution passes the system testing if its running time is at most *v* seconds. We can also say that a solution passes the system testing with some "extra" time if for its running time, *a* seconds, an inequality 2*a*<=≤<=*v* holds. As a result, Valera decided to set *v* seconds TL, that the following conditions are met: 1. *v* is a positive integer; 1. all correct solutions pass the system testing; 1. at least one correct solution passes the system testing with some "extra" time; 1. all wrong solutions do not pass the system testing; 1. value *v* is minimum among all TLs, for which points 1, 2, 3, 4 hold. Help Valera and find the most suitable TL or else state that such TL doesn't exist. Input Specification: The first line contains two integers *n*, *m* (1<=≤<=*n*,<=*m*<=≤<=100). The second line contains *n* space-separated positive integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100) — the running time of each of the *n* correct solutions in seconds. The third line contains *m* space-separated positive integers *b*1,<=*b*2,<=...,<=*b**m* (1<=≤<=*b**i*<=≤<=100) — the running time of each of *m* wrong solutions in seconds. Output Specification: If there is a valid TL value, print it. Otherwise, print -1. Demo Input: ['3 6\n4 5 2\n8 9 6 10 7 11\n', '3 1\n3 4 5\n6\n'] Demo Output: ['5', '-1\n'] Note: none
```python n, m = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) a.sort() v = a[-1] ans = -1 while 1: idx = 0 wrong = False while idx < m: if b[idx] <= v: wrong = True idx = m idx += 1 if wrong == True: break if v < 2 * a[0]: v += 1 continue ans = v break print (ans) ```
3
713
A
Sonya and Queries
PROGRAMMING
1,400
[ "data structures", "implementation" ]
null
null
Today Sonya learned about long integers and invited all her friends to share the fun. Sonya has an initially empty multiset with integers. Friends give her *t* queries, each of one of the following type: 1. <=+<= *a**i* — add non-negative integer *a**i* to the multiset. Note, that she has a multiset, thus there may be many occurrences of the same integer. 1. <=-<= *a**i* — delete a single occurrence of non-negative integer *a**i* from the multiset. It's guaranteed, that there is at least one *a**i* in the multiset. 1. ? *s* — count the number of integers in the multiset (with repetitions) that match some pattern *s* consisting of 0 and 1. In the pattern, 0 stands for the even digits, while 1 stands for the odd. Integer *x* matches the pattern *s*, if the parity of the *i*-th from the right digit in decimal notation matches the *i*-th from the right digit of the pattern. If the pattern is shorter than this integer, it's supplemented with 0-s from the left. Similarly, if the integer is shorter than the pattern its decimal notation is supplemented with the 0-s from the left. For example, if the pattern is *s*<==<=010, than integers 92, 2212, 50 and 414 match the pattern, while integers 3, 110, 25 and 1030 do not.
The first line of the input contains an integer *t* (1<=≤<=*t*<=≤<=100<=000) — the number of operation Sonya has to perform. Next *t* lines provide the descriptions of the queries in order they appear in the input file. The *i*-th row starts with a character *c**i* — the type of the corresponding operation. If *c**i* is equal to '+' or '-' then it's followed by a space and an integer *a**i* (0<=≤<=*a**i*<=&lt;<=1018) given without leading zeroes (unless it's 0). If *c**i* equals '?' then it's followed by a space and a sequence of zeroes and onse, giving the pattern of length no more than 18. It's guaranteed that there will be at least one query of type '?'. It's guaranteed that any time some integer is removed from the multiset, there will be at least one occurrence of this integer in it.
For each query of the third type print the number of integers matching the given pattern. Each integer is counted as many times, as it appears in the multiset at this moment of time.
[ "12\n+ 1\n+ 241\n? 1\n+ 361\n- 241\n? 0101\n+ 101\n? 101\n- 101\n? 101\n+ 4000\n? 0\n", "4\n+ 200\n+ 200\n- 200\n? 0\n" ]
[ "2\n1\n2\n1\n1\n", "1\n" ]
Consider the integers matching the patterns from the queries of the third type. Queries are numbered in the order they appear in the input. 1. 1 and 241. 1. 361. 1. 101 and 361. 1. 361. 1. 4000.
500
[ { "input": "12\n+ 1\n+ 241\n? 1\n+ 361\n- 241\n? 0101\n+ 101\n? 101\n- 101\n? 101\n+ 4000\n? 0", "output": "2\n1\n2\n1\n1" }, { "input": "4\n+ 200\n+ 200\n- 200\n? 0", "output": "1" }, { "input": "20\n+ 61\n+ 99\n+ 51\n+ 70\n+ 7\n+ 34\n+ 71\n+ 86\n+ 68\n+ 39\n+ 78\n+ 81\n+ 89\n? 10\n? 00\n? 10\n? 01\n? 01\n? 00\n? 00", "output": "3\n2\n3\n4\n4\n2\n2" }, { "input": "20\n+ 13\n+ 50\n+ 9\n? 0\n+ 24\n? 0\n- 24\n? 0\n+ 79\n? 11\n- 13\n? 11\n- 50\n? 10\n? 1\n- 9\n? 1\n? 11\n- 79\n? 11", "output": "0\n1\n0\n2\n1\n0\n1\n0\n1\n0" }, { "input": "10\n+ 870566619432760298\n+ 869797178280285214\n+ 609920823721618090\n+ 221159591436767023\n+ 730599542279836538\n? 101001100111001011\n? 001111010101010011\n? 100010100011101110\n? 100110010110001100\n? 110000011101110011", "output": "0\n0\n0\n0\n0" }, { "input": "10\n+ 96135\n? 10111\n+ 63322\n? 10111\n+ 44490\n? 10111\n+ 69312\n? 10111\n? 01100\n+ 59396", "output": "1\n1\n1\n1\n1" }, { "input": "10\n+ 2\n- 2\n+ 778\n+ 3\n+ 4\n- 4\n+ 1\n+ 617\n? 011\n? 011", "output": "1\n1" }, { "input": "20\n+ 8\n+ 39532\n+ 813\n- 39532\n? 00011\n? 00000\n? 00011\n+ 70424\n- 8\n? 00011\n- 70424\n? 00011\n+ 29\n? 00001\n+ 6632\n+ 3319\n? 00001\n+ 3172\n? 01111\n- 29", "output": "1\n1\n1\n1\n1\n1\n1\n1" } ]
1,505,264,386
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
62
0
def main(): multiset = [] answers = [] n = int(input()) even = ['0','2','4','8',] odd = ['1','3','5','7','9'] for nn in range(0,n): op, num = input().split() if op == '+': multiset.append(num) if op == '-': del multiset[multiset.index(num)] if op == '?': count = 0 for m in multiset: pattern = num.zfill(max(len(num),len(m))) #print (pattern) entry = m.zfill(max(len(num),len(m))) #print(entry) flag = 1 for j in range(len(pattern)): if ((pattern[j]=='0') and (entry[j] in odd)): flag = 0 elif ((pattern[j]=='1') and (entry[j] in even)): flag = 0 #print('flag', flag) if flag == 1: count = count +1 answers. append(count) for ans in answers: print (ans) #print (multiset) return 1 if __name__ == '__main__': main()
Title: Sonya and Queries Time Limit: None seconds Memory Limit: None megabytes Problem Description: Today Sonya learned about long integers and invited all her friends to share the fun. Sonya has an initially empty multiset with integers. Friends give her *t* queries, each of one of the following type: 1. <=+<= *a**i* — add non-negative integer *a**i* to the multiset. Note, that she has a multiset, thus there may be many occurrences of the same integer. 1. <=-<= *a**i* — delete a single occurrence of non-negative integer *a**i* from the multiset. It's guaranteed, that there is at least one *a**i* in the multiset. 1. ? *s* — count the number of integers in the multiset (with repetitions) that match some pattern *s* consisting of 0 and 1. In the pattern, 0 stands for the even digits, while 1 stands for the odd. Integer *x* matches the pattern *s*, if the parity of the *i*-th from the right digit in decimal notation matches the *i*-th from the right digit of the pattern. If the pattern is shorter than this integer, it's supplemented with 0-s from the left. Similarly, if the integer is shorter than the pattern its decimal notation is supplemented with the 0-s from the left. For example, if the pattern is *s*<==<=010, than integers 92, 2212, 50 and 414 match the pattern, while integers 3, 110, 25 and 1030 do not. Input Specification: The first line of the input contains an integer *t* (1<=≤<=*t*<=≤<=100<=000) — the number of operation Sonya has to perform. Next *t* lines provide the descriptions of the queries in order they appear in the input file. The *i*-th row starts with a character *c**i* — the type of the corresponding operation. If *c**i* is equal to '+' or '-' then it's followed by a space and an integer *a**i* (0<=≤<=*a**i*<=&lt;<=1018) given without leading zeroes (unless it's 0). If *c**i* equals '?' then it's followed by a space and a sequence of zeroes and onse, giving the pattern of length no more than 18. It's guaranteed that there will be at least one query of type '?'. It's guaranteed that any time some integer is removed from the multiset, there will be at least one occurrence of this integer in it. Output Specification: For each query of the third type print the number of integers matching the given pattern. Each integer is counted as many times, as it appears in the multiset at this moment of time. Demo Input: ['12\n+ 1\n+ 241\n? 1\n+ 361\n- 241\n? 0101\n+ 101\n? 101\n- 101\n? 101\n+ 4000\n? 0\n', '4\n+ 200\n+ 200\n- 200\n? 0\n'] Demo Output: ['2\n1\n2\n1\n1\n', '1\n'] Note: Consider the integers matching the patterns from the queries of the third type. Queries are numbered in the order they appear in the input. 1. 1 and 241. 1. 361. 1. 101 and 361. 1. 361. 1. 4000.
```python def main(): multiset = [] answers = [] n = int(input()) even = ['0','2','4','8',] odd = ['1','3','5','7','9'] for nn in range(0,n): op, num = input().split() if op == '+': multiset.append(num) if op == '-': del multiset[multiset.index(num)] if op == '?': count = 0 for m in multiset: pattern = num.zfill(max(len(num),len(m))) #print (pattern) entry = m.zfill(max(len(num),len(m))) #print(entry) flag = 1 for j in range(len(pattern)): if ((pattern[j]=='0') and (entry[j] in odd)): flag = 0 elif ((pattern[j]=='1') and (entry[j] in even)): flag = 0 #print('flag', flag) if flag == 1: count = count +1 answers. append(count) for ans in answers: print (ans) #print (multiset) return 1 if __name__ == '__main__': main() ```
0
525
A
Vitaliy and Pie
PROGRAMMING
1,100
[ "greedy", "hashing", "strings" ]
null
null
After a hard day Vitaly got very hungry and he wants to eat his favorite potato pie. But it's not that simple. Vitaly is in the first room of the house with *n* room located in a line and numbered starting from one from left to right. You can go from the first room to the second room, from the second room to the third room and so on — you can go from the (*n*<=-<=1)-th room to the *n*-th room. Thus, you can go to room *x* only from room *x*<=-<=1. The potato pie is located in the *n*-th room and Vitaly needs to go there. Each pair of consecutive rooms has a door between them. In order to go to room *x* from room *x*<=-<=1, you need to open the door between the rooms with the corresponding key. In total the house has several types of doors (represented by uppercase Latin letters) and several types of keys (represented by lowercase Latin letters). The key of type *t* can open the door of type *T* if and only if *t* and *T* are the same letter, written in different cases. For example, key f can open door F. Each of the first *n*<=-<=1 rooms contains exactly one key of some type that Vitaly can use to get to next rooms. Once the door is open with some key, Vitaly won't get the key from the keyhole but he will immediately run into the next room. In other words, each key can open no more than one door. Vitaly realizes that he may end up in some room without the key that opens the door to the next room. Before the start his run for the potato pie Vitaly can buy any number of keys of any type that is guaranteed to get to room *n*. Given the plan of the house, Vitaly wants to know what is the minimum number of keys he needs to buy to surely get to the room *n*, which has a delicious potato pie. Write a program that will help Vitaly find out this number.
The first line of the input contains a positive integer *n* (2<=≤<=*n*<=≤<=105) — the number of rooms in the house. The second line of the input contains string *s* of length 2·*n*<=-<=2. Let's number the elements of the string from left to right, starting from one. The odd positions in the given string *s* contain lowercase Latin letters — the types of the keys that lie in the corresponding rooms. Thus, each odd position *i* of the given string *s* contains a lowercase Latin letter — the type of the key that lies in room number (*i*<=+<=1)<=/<=2. The even positions in the given string contain uppercase Latin letters — the types of doors between the rooms. Thus, each even position *i* of the given string *s* contains an uppercase letter — the type of the door that leads from room *i*<=/<=2 to room *i*<=/<=2<=+<=1.
Print the only integer — the minimum number of keys that Vitaly needs to buy to surely get from room one to room *n*.
[ "3\naAbB\n", "4\naBaCaB\n", "5\nxYyXzZaZ\n" ]
[ "0\n", "3\n", "2\n" ]
none
250
[ { "input": "3\naAbB", "output": "0" }, { "input": "4\naBaCaB", "output": "3" }, { "input": "5\nxYyXzZaZ", "output": "2" }, { "input": "26\naAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyY", "output": "0" }, { "input": "26\nzAyBxCwDvEuFtGsHrIqJpKoLnMmNlOkPjQiRhSgTfUeVdWcXbY", "output": "13" }, { "input": "5\naArRaRaR", "output": "2" }, { "input": "2\ndA", "output": "1" }, { "input": "2\ncB", "output": "1" }, { "input": "10\nhNcMeXsSlHsUwYeMcA", "output": "7" }, { "input": "100\nqDpInBmCrFwXpDbFgOzVvOcEmJrUcToAdEwEgTvBvBfWwRpGyEaXgDdRwVlQnYgWmWhMrHaIzPyXvGaFlRsVzHhZrOuVpXrKxFzAmWwPlFtNfPtJxVmLuHjKfYyArHrEnSwSzOvDpQhCgCqLlAcNpGhXrEeFuCmAqIkXyYtSsQwIxJzNiIuTgEbVuWrMwPrAlLyKaZ", "output": "42" }, { "input": "2\ndD", "output": "0" }, { "input": "2\ndE", "output": "1" }, { "input": "3\ndDdD", "output": "0" }, { "input": "3\ndEdD", "output": "1" }, { "input": "3\ndEeD", "output": "1" }, { "input": "3\ndEeF", "output": "2" } ]
1,585,744,813
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
7
171
3,584,000
def fun(not_used): u=0 for x in not_used: if (x==s[i+1]): u+=1 x=0 break if(u!=0): return 1 else: return 0 n=input() st=input() s=st.upper() not_used=[] k=0 for i in range(0,len(s),2): if (s[i]==s[i+1]): continue elif (fun(not_used)): continue else: not_used.append(s[i]) k+=1 print (k)
Title: Vitaliy and Pie Time Limit: None seconds Memory Limit: None megabytes Problem Description: After a hard day Vitaly got very hungry and he wants to eat his favorite potato pie. But it's not that simple. Vitaly is in the first room of the house with *n* room located in a line and numbered starting from one from left to right. You can go from the first room to the second room, from the second room to the third room and so on — you can go from the (*n*<=-<=1)-th room to the *n*-th room. Thus, you can go to room *x* only from room *x*<=-<=1. The potato pie is located in the *n*-th room and Vitaly needs to go there. Each pair of consecutive rooms has a door between them. In order to go to room *x* from room *x*<=-<=1, you need to open the door between the rooms with the corresponding key. In total the house has several types of doors (represented by uppercase Latin letters) and several types of keys (represented by lowercase Latin letters). The key of type *t* can open the door of type *T* if and only if *t* and *T* are the same letter, written in different cases. For example, key f can open door F. Each of the first *n*<=-<=1 rooms contains exactly one key of some type that Vitaly can use to get to next rooms. Once the door is open with some key, Vitaly won't get the key from the keyhole but he will immediately run into the next room. In other words, each key can open no more than one door. Vitaly realizes that he may end up in some room without the key that opens the door to the next room. Before the start his run for the potato pie Vitaly can buy any number of keys of any type that is guaranteed to get to room *n*. Given the plan of the house, Vitaly wants to know what is the minimum number of keys he needs to buy to surely get to the room *n*, which has a delicious potato pie. Write a program that will help Vitaly find out this number. Input Specification: The first line of the input contains a positive integer *n* (2<=≤<=*n*<=≤<=105) — the number of rooms in the house. The second line of the input contains string *s* of length 2·*n*<=-<=2. Let's number the elements of the string from left to right, starting from one. The odd positions in the given string *s* contain lowercase Latin letters — the types of the keys that lie in the corresponding rooms. Thus, each odd position *i* of the given string *s* contains a lowercase Latin letter — the type of the key that lies in room number (*i*<=+<=1)<=/<=2. The even positions in the given string contain uppercase Latin letters — the types of doors between the rooms. Thus, each even position *i* of the given string *s* contains an uppercase letter — the type of the door that leads from room *i*<=/<=2 to room *i*<=/<=2<=+<=1. Output Specification: Print the only integer — the minimum number of keys that Vitaly needs to buy to surely get from room one to room *n*. Demo Input: ['3\naAbB\n', '4\naBaCaB\n', '5\nxYyXzZaZ\n'] Demo Output: ['0\n', '3\n', '2\n'] Note: none
```python def fun(not_used): u=0 for x in not_used: if (x==s[i+1]): u+=1 x=0 break if(u!=0): return 1 else: return 0 n=input() st=input() s=st.upper() not_used=[] k=0 for i in range(0,len(s),2): if (s[i]==s[i+1]): continue elif (fun(not_used)): continue else: not_used.append(s[i]) k+=1 print (k) ```
0
447
B
DZY Loves Strings
PROGRAMMING
1,000
[ "greedy", "implementation" ]
null
null
DZY loves collecting special strings which only contain lowercase letters. For each lowercase letter *c* DZY knows its value *w**c*. For each special string *s*<==<=*s*1*s*2... *s*|*s*| (|*s*| is the length of the string) he represents its value with a function *f*(*s*), where Now DZY has a string *s*. He wants to insert *k* lowercase letters into this string in order to get the largest possible value of the resulting string. Can you help him calculate the largest possible value he could get?
The first line contains a single string *s* (1<=≤<=|*s*|<=≤<=103). The second line contains a single integer *k* (0<=≤<=*k*<=≤<=103). The third line contains twenty-six integers from *w**a* to *w**z*. Each such number is non-negative and doesn't exceed 1000.
Print a single integer — the largest possible value of the resulting string DZY could get.
[ "abc\n3\n1 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n" ]
[ "41\n" ]
In the test sample DZY can obtain "abcbbc", *value* = 1·1 + 2·2 + 3·2 + 4·2 + 5·2 + 6·2 = 41.
1,000
[ { "input": "abc\n3\n1 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "41" }, { "input": "mmzhr\n3\n443 497 867 471 195 670 453 413 579 466 553 881 847 642 269 996 666 702 487 209 257 741 974 133 519 453", "output": "29978" }, { "input": "ajeeseerqnpaujubmajpibxrccazaawetywxmifzehojf\n23\n359 813 772 413 733 654 33 87 890 433 395 311 801 852 376 148 914 420 636 695 583 733 664 394 407 314", "output": "1762894" }, { "input": "uahngxejpomhbsebcxvelfsojbaouynnlsogjyvktpwwtcyddkcdqcqs\n34\n530 709 150 660 947 830 487 142 208 276 885 542 138 214 76 184 273 753 30 195 722 236 82 691 572 585", "output": "2960349" }, { "input": "xnzeqmouqyzvblcidmhbkqmtusszuczadpooslqxegldanwopilmdwzbczvrwgnwaireykwpugvpnpafbxlyggkgawghysufuegvmzvpgcqyjkoadcreaguzepbendwnowsuekxxivkziibxvxfoilofxcgnxvfefyezfhevfvtetsuhwtyxdlkccdkvqjl\n282\n170 117 627 886 751 147 414 187 150 960 410 70 576 681 641 729 798 877 611 108 772 643 683 166 305 933", "output": "99140444" }, { "input": "pplkqmluhfympkjfjnfdkwrkpumgdmbkfbbldpepicbbmdgafttpopzdxsevlqbtywzkoxyviglbbxsohycbdqksrhlumsldiwzjmednbkcjishkiekfrchzuztkcxnvuykhuenqojrmzaxlaoxnljnvqgnabtmcftisaazzgbmubmpsorygyusmeonrhrgphnfhlaxrvyhuxsnnezjxmdoklpquzpvjbxgbywppmegzxknhfzyygrmejleesoqfwheulmqhonqaukyuejtwxskjldplripyihbfpookxkuehiwqthbfafyrgmykuxglpplozycgydyecqkgfjljfqvigqhuxssqqtfanwszduwbsoytnrtgc\n464\n838 95 473 955 690 84 436 19 179 437 674 626 377 365 781 4 733 776 462 203 119 256 381 668 855 686", "output": "301124161" }, { "input": "qkautnuilwlhjsldfcuwhiqtgtoihifszlyvfaygrnivzgvwthkrzzdtfjcirrjjlrmjtbjlzmjeqmuffsjorjyggzefwgvmblvotvzffnwjhqxorpowzdcnfksdibezdtfjjxfozaghieksbmowrbeehuxlesmvqjsphlvauxiijm\n98\n121 622 0 691 616 959 838 161 581 862 876 830 267 812 598 106 337 73 588 323 999 17 522 399 657 495", "output": "30125295" }, { "input": "tghyxqfmhz\n8\n191 893 426 203 780 326 148 259 182 140 847 636 778 97 167 773 219 891 758 993 695 603 223 779 368 165", "output": "136422" }, { "input": "nyawbfjxnxjiyhwkydaruozobpphgjqdpfdqzezcsoyvurnapu\n30\n65 682 543 533 990 148 815 821 315 916 632 771 332 513 472 864 12 73 548 687 660 572 507 192 226 348", "output": "2578628" }, { "input": "pylrnkrbcjgoytvdnhmlvnkknijkdgdhworlvtwuonrkhrilkewcnofodaumgvnsisxooswgrgtvdeauyxhkipfoxrrtysuepjcf\n60\n894 206 704 179 272 337 413 828 119 182 330 46 440 102 250 191 242 539 678 783 843 431 612 567 33 338", "output": "9168707" }, { "input": "vhjnkrxbyhjhnjrxvwxmhxwoxttbtqosfxtcuvhfjlkyfspeypthsdkkwnqdpxdlnxsgtzvkrgqosgfjrwetqbxgoarkjhrjbspzgblsapifltkfxbfdbxqwoohlgyzijmiwnpmveybyzvasoctxsmgjehpyysmqblwnmkappbecklqjfmxhlyceordroflnposohfplrvijxbwvqdtvzhobtrumiujnyrfbwthvciinuveoizkccelxtaveiiagryqnyvsgfnipnavrtmdqlcnldepocbpzmqnarkdvykds\n276\n364 244 798 82 582 9 309 950 286 547 892 371 569 159 705 975 740 845 655 179 130 993 255 552 882 657", "output": "144901921" }, { "input": "gsaddmezrnttfalbwlqbnedumvikplfosw\n12\n290 850 872 361 483 895 152 118 974 619 701 154 899 285 328 712 669 984 407 340 851 775 324 892 554 860", "output": "809931" }, { "input": "a\n0\n5 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "5" }, { "input": "lol\n3\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "21" } ]
1,587,307,187
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
1
124
0
s = input() k = int(input()) wt = [int(x) for x in input().split()] string = "abcdefghijklmnopqrstuvwxyz" string = list(string) ans=0 for i in range(len(s)): ind = string.index(s[i]) ans+=wt[ind]*(i+1) maxi = max(wt) for i in range(1,k+1): ans+=maxi*(k+i) print(ans)
Title: DZY Loves Strings Time Limit: None seconds Memory Limit: None megabytes Problem Description: DZY loves collecting special strings which only contain lowercase letters. For each lowercase letter *c* DZY knows its value *w**c*. For each special string *s*<==<=*s*1*s*2... *s*|*s*| (|*s*| is the length of the string) he represents its value with a function *f*(*s*), where Now DZY has a string *s*. He wants to insert *k* lowercase letters into this string in order to get the largest possible value of the resulting string. Can you help him calculate the largest possible value he could get? Input Specification: The first line contains a single string *s* (1<=≤<=|*s*|<=≤<=103). The second line contains a single integer *k* (0<=≤<=*k*<=≤<=103). The third line contains twenty-six integers from *w**a* to *w**z*. Each such number is non-negative and doesn't exceed 1000. Output Specification: Print a single integer — the largest possible value of the resulting string DZY could get. Demo Input: ['abc\n3\n1 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n'] Demo Output: ['41\n'] Note: In the test sample DZY can obtain "abcbbc", *value* = 1·1 + 2·2 + 3·2 + 4·2 + 5·2 + 6·2 = 41.
```python s = input() k = int(input()) wt = [int(x) for x in input().split()] string = "abcdefghijklmnopqrstuvwxyz" string = list(string) ans=0 for i in range(len(s)): ind = string.index(s[i]) ans+=wt[ind]*(i+1) maxi = max(wt) for i in range(1,k+1): ans+=maxi*(k+i) print(ans) ```
0
31
A
Worms Evolution
PROGRAMMING
1,200
[ "implementation" ]
A. Worms Evolution
2
256
Professor Vasechkin is studying evolution of worms. Recently he put forward hypotheses that all worms evolve by division. There are *n* forms of worms. Worms of these forms have lengths *a*1, *a*2, ..., *a**n*. To prove his theory, professor needs to find 3 different forms that the length of the first form is equal to sum of lengths of the other two forms. Help him to do this.
The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of worm's forms. The second line contains *n* space-separated integers *a**i* (1<=≤<=*a**i*<=≤<=1000) — lengths of worms of each form.
Output 3 distinct integers *i* *j* *k* (1<=≤<=*i*,<=*j*,<=*k*<=≤<=*n*) — such indexes of worm's forms that *a**i*<==<=*a**j*<=+<=*a**k*. If there is no such triple, output -1. If there are several solutions, output any of them. It possible that *a**j*<==<=*a**k*.
[ "5\n1 2 3 5 7\n", "5\n1 8 1 5 1\n" ]
[ "3 2 1\n", "-1\n" ]
none
500
[ { "input": "5\n1 2 3 5 7", "output": "3 2 1" }, { "input": "5\n1 8 1 5 1", "output": "-1" }, { "input": "4\n303 872 764 401", "output": "-1" }, { "input": "6\n86 402 133 524 405 610", "output": "6 4 1" }, { "input": "8\n217 779 418 895 996 473 3 22", "output": "5 2 1" }, { "input": "10\n858 972 670 15 662 114 33 273 53 310", "output": "2 6 1" }, { "input": "100\n611 697 572 770 603 870 128 245 49 904 468 982 788 943 549 288 668 796 803 515 999 735 912 49 298 80 412 841 494 434 543 298 17 571 271 105 70 313 178 755 194 279 585 766 412 164 907 841 776 556 731 268 735 880 176 267 287 65 239 588 155 658 821 47 783 595 585 69 226 906 429 161 999 148 7 484 362 585 952 365 92 749 904 525 307 626 883 367 450 755 564 950 728 724 69 106 119 157 96 290", "output": "1 38 25" }, { "input": "100\n713 572 318 890 577 657 646 146 373 783 392 229 455 871 20 593 573 336 26 381 280 916 907 732 820 713 111 840 570 446 184 711 481 399 788 647 492 15 40 530 549 506 719 782 126 20 778 996 712 761 9 74 812 418 488 175 103 585 900 3 604 521 109 513 145 708 990 361 682 827 791 22 596 780 596 385 450 643 158 496 876 975 319 783 654 895 891 361 397 81 682 899 347 623 809 557 435 279 513 438", "output": "1 63 61" }, { "input": "100\n156 822 179 298 981 82 610 345 373 378 895 734 768 15 78 335 764 608 932 297 717 553 916 367 425 447 361 195 66 70 901 236 905 744 919 564 296 610 963 628 840 52 100 750 345 308 37 687 192 704 101 815 10 990 216 358 823 546 578 821 706 148 182 582 421 482 829 425 121 337 500 301 402 868 66 935 625 527 746 585 308 523 488 914 608 709 875 252 151 781 447 2 756 176 976 302 450 35 680 791", "output": "1 98 69" }, { "input": "100\n54 947 785 838 359 647 92 445 48 465 323 486 101 86 607 31 860 420 709 432 435 372 272 37 903 814 309 197 638 58 259 822 793 564 309 22 522 907 101 853 486 824 614 734 630 452 166 532 256 499 470 9 933 452 256 450 7 26 916 406 257 285 895 117 59 369 424 133 16 417 352 440 806 236 478 34 889 469 540 806 172 296 73 655 261 792 868 380 204 454 330 53 136 629 236 850 134 560 264 291", "output": "2 29 27" }, { "input": "99\n175 269 828 129 499 890 127 263 995 807 508 289 996 226 437 320 365 642 757 22 190 8 345 499 834 713 962 889 336 171 608 492 320 257 472 801 176 325 301 306 198 729 933 4 640 322 226 317 567 586 249 237 202 633 287 128 911 654 719 988 420 855 361 574 716 899 317 356 581 440 284 982 541 111 439 29 37 560 961 224 478 906 319 416 736 603 808 87 762 697 392 713 19 459 262 238 239 599 997", "output": "1 44 30" }, { "input": "98\n443 719 559 672 16 69 529 632 953 999 725 431 54 22 346 968 558 696 48 669 963 129 257 712 39 870 498 595 45 821 344 925 179 388 792 346 755 213 423 365 344 659 824 356 773 637 628 897 841 155 243 536 951 361 192 105 418 431 635 596 150 162 145 548 473 531 750 306 377 354 450 975 79 743 656 733 440 940 19 139 237 346 276 227 64 799 479 633 199 17 796 362 517 234 729 62 995 535", "output": "2 70 40" }, { "input": "97\n359 522 938 862 181 600 283 1000 910 191 590 220 761 818 903 264 751 751 987 316 737 898 168 925 244 674 34 950 754 472 81 6 37 520 112 891 981 454 897 424 489 238 363 709 906 951 677 828 114 373 589 835 52 89 97 435 277 560 551 204 879 469 928 523 231 163 183 609 821 915 615 969 616 23 874 437 844 321 78 53 643 786 585 38 744 347 150 179 988 985 200 11 15 9 547 886 752", "output": "1 23 10" }, { "input": "4\n303 872 764 401", "output": "-1" }, { "input": "100\n328 397 235 453 188 254 879 225 423 36 384 296 486 592 231 849 856 255 213 898 234 800 701 529 951 693 507 326 15 905 618 348 967 927 28 979 752 850 343 35 84 302 36 390 482 826 249 918 91 289 973 457 557 348 365 239 709 565 320 560 153 130 647 708 483 469 788 473 322 844 830 562 611 961 397 673 69 960 74 703 369 968 382 451 328 160 211 230 566 208 7 545 293 73 806 375 157 410 303 58", "output": "1 79 6" }, { "input": "33\n52 145 137 734 180 847 178 286 716 134 181 630 358 764 593 762 785 28 1 468 189 540 764 485 165 656 114 58 628 108 605 584 257", "output": "8 30 7" }, { "input": "57\n75 291 309 68 444 654 985 158 514 204 116 918 374 806 176 31 49 455 269 66 722 713 164 818 317 295 546 564 134 641 28 13 987 478 146 219 213 940 289 173 157 666 168 391 392 71 870 477 446 988 414 568 964 684 409 671 454", "output": "2 41 29" }, { "input": "88\n327 644 942 738 84 118 981 686 530 404 137 197 434 16 693 183 423 325 410 345 941 329 7 106 79 867 584 358 533 675 192 718 641 329 900 768 404 301 101 538 954 590 401 954 447 14 559 337 756 586 934 367 538 928 945 936 770 641 488 579 206 869 902 139 216 446 723 150 829 205 373 578 357 368 960 40 121 206 503 385 521 161 501 694 138 370 709 308", "output": "1 77 61" }, { "input": "100\n804 510 266 304 788 625 862 888 408 82 414 470 777 991 729 229 933 406 601 1 596 720 608 706 432 361 527 548 59 548 474 515 4 991 263 568 681 24 117 563 576 587 281 643 904 521 891 106 842 884 943 54 605 815 504 757 311 374 335 192 447 652 633 410 455 402 382 150 432 836 413 819 669 875 638 925 217 805 632 520 605 266 728 795 162 222 603 159 284 790 914 443 775 97 789 606 859 13 851 47", "output": "1 77 42" }, { "input": "100\n449 649 615 713 64 385 927 466 138 126 143 886 80 199 208 43 196 694 92 89 264 180 617 970 191 196 910 150 275 89 693 190 191 99 542 342 45 592 114 56 451 170 64 589 176 102 308 92 402 153 414 675 352 157 69 150 91 288 163 121 816 184 20 234 836 12 593 150 793 439 540 93 99 663 186 125 349 247 476 106 77 523 215 7 363 278 441 745 337 25 148 384 15 915 108 211 240 58 23 408", "output": "1 6 5" }, { "input": "90\n881 436 52 308 97 261 153 931 670 538 702 156 114 445 154 685 452 76 966 790 93 42 547 65 736 364 136 489 719 322 239 628 696 735 55 703 622 375 100 188 804 341 546 474 484 446 729 290 974 301 602 225 996 244 488 983 882 460 962 754 395 617 61 640 534 292 158 375 632 902 420 979 379 38 100 67 963 928 190 456 545 571 45 716 153 68 844 2 102 116", "output": "1 14 2" }, { "input": "80\n313 674 262 240 697 146 391 221 793 504 896 818 92 899 86 370 341 339 306 887 937 570 830 683 729 519 240 833 656 847 427 958 435 704 853 230 758 347 660 575 843 293 649 396 437 787 654 599 35 103 779 783 447 379 444 585 902 713 791 150 851 228 306 721 996 471 617 403 102 168 197 741 877 481 968 545 331 715 236 654", "output": "1 13 8" }, { "input": "70\n745 264 471 171 946 32 277 511 269 469 89 831 69 2 369 407 583 602 646 633 429 747 113 302 722 321 344 824 241 372 263 287 822 24 652 758 246 967 219 313 882 597 752 965 389 775 227 556 95 904 308 340 899 514 400 187 275 318 621 546 659 488 199 154 811 1 725 79 925 82", "output": "1 63 60" }, { "input": "60\n176 502 680 102 546 917 516 801 392 435 635 492 398 456 653 444 472 513 634 378 273 276 44 920 68 124 800 167 825 250 452 264 561 344 98 933 381 939 426 51 568 548 206 887 342 763 151 514 156 354 486 546 998 649 356 438 295 570 450 589", "output": "2 26 20" }, { "input": "50\n608 92 889 33 146 803 402 91 868 400 828 505 375 558 584 129 361 776 974 123 765 804 326 186 61 927 904 511 762 775 640 593 300 664 897 461 869 911 986 789 607 500 309 457 294 104 724 471 216 155", "output": "3 25 11" }, { "input": "40\n40 330 98 612 747 336 640 381 991 366 22 167 352 12 868 166 603 40 313 869 609 981 609 804 54 729 8 854 347 300 828 922 39 633 695 988 4 530 545 176", "output": "5 10 8" }, { "input": "30\n471 920 308 544 347 222 878 671 467 332 215 180 681 114 151 203 492 951 653 614 453 510 540 422 399 532 113 198 932 825", "output": "2 21 9" }, { "input": "20\n551 158 517 475 595 108 764 961 590 297 761 841 659 568 82 888 733 214 993 359", "output": "3 20 2" }, { "input": "10\n983 748 726 406 196 993 2 251 66 263", "output": "-1" }, { "input": "9\n933 266 457 863 768 257 594 136 145", "output": "-1" }, { "input": "8\n537 198 48 771 944 868 700 163", "output": "7 8 1" }, { "input": "7\n140 779 639 679 768 479 158", "output": "2 3 1" }, { "input": "6\n744 359 230 586 944 442", "output": "-1" }, { "input": "5\n700 939 173 494 120", "output": "-1" }, { "input": "4\n303 872 764 401", "output": "-1" }, { "input": "3\n907 452 355", "output": "-1" }, { "input": "3\n963 630 333", "output": "1 3 2" }, { "input": "3\n2 2 4", "output": "3 2 1" }, { "input": "3\n2 4 100", "output": "-1" } ]
1,591,699,975
2,147,483,647
Python 3
OK
TESTS
39
216
307,200
input() cont = [int(item) for item in input().split()] ans, contLen, needBreak = '-1', len(cont), False for i in range(contLen): for j in range(contLen): if i == j: continue for k in range(contLen): if k == i or k == j: continue if cont[i] == cont[j] + cont[k]: ans = '{} {} {}'.format(i + 1, j + 1, k + 1) needBreak = True break if needBreak: break if needBreak: break print(ans)
Title: Worms Evolution Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Professor Vasechkin is studying evolution of worms. Recently he put forward hypotheses that all worms evolve by division. There are *n* forms of worms. Worms of these forms have lengths *a*1, *a*2, ..., *a**n*. To prove his theory, professor needs to find 3 different forms that the length of the first form is equal to sum of lengths of the other two forms. Help him to do this. Input Specification: The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of worm's forms. The second line contains *n* space-separated integers *a**i* (1<=≤<=*a**i*<=≤<=1000) — lengths of worms of each form. Output Specification: Output 3 distinct integers *i* *j* *k* (1<=≤<=*i*,<=*j*,<=*k*<=≤<=*n*) — such indexes of worm's forms that *a**i*<==<=*a**j*<=+<=*a**k*. If there is no such triple, output -1. If there are several solutions, output any of them. It possible that *a**j*<==<=*a**k*. Demo Input: ['5\n1 2 3 5 7\n', '5\n1 8 1 5 1\n'] Demo Output: ['3 2 1\n', '-1\n'] Note: none
```python input() cont = [int(item) for item in input().split()] ans, contLen, needBreak = '-1', len(cont), False for i in range(contLen): for j in range(contLen): if i == j: continue for k in range(contLen): if k == i or k == j: continue if cont[i] == cont[j] + cont[k]: ans = '{} {} {}'.format(i + 1, j + 1, k + 1) needBreak = True break if needBreak: break if needBreak: break print(ans) ```
3.945428
863
B
Kayaking
PROGRAMMING
1,500
[ "brute force", "greedy", "sortings" ]
null
null
Vadim is really keen on travelling. Recently he heard about kayaking activity near his town and became very excited about it, so he joined a party of kayakers. Now the party is ready to start its journey, but firstly they have to choose kayaks. There are 2·*n* people in the group (including Vadim), and they have exactly *n*<=-<=1 tandem kayaks (each of which, obviously, can carry two people) and 2 single kayaks. *i*-th person's weight is *w**i*, and weight is an important matter in kayaking — if the difference between the weights of two people that sit in the same tandem kayak is too large, then it can crash. And, of course, people want to distribute their seats in kayaks in order to minimize the chances that kayaks will crash. Formally, the instability of a single kayak is always 0, and the instability of a tandem kayak is the absolute difference between weights of the people that are in this kayak. Instability of the whole journey is the total instability of all kayaks. Help the party to determine minimum possible total instability!
The first line contains one number *n* (2<=≤<=*n*<=≤<=50). The second line contains 2·*n* integer numbers *w*1, *w*2, ..., *w*2*n*, where *w**i* is weight of person *i* (1<=≤<=*w**i*<=≤<=1000).
Print minimum possible total instability.
[ "2\n1 2 3 4\n", "4\n1 3 4 6 3 4 100 200\n" ]
[ "1\n", "5\n" ]
none
0
[ { "input": "2\n1 2 3 4", "output": "1" }, { "input": "4\n1 3 4 6 3 4 100 200", "output": "5" }, { "input": "3\n305 139 205 406 530 206", "output": "102" }, { "input": "3\n610 750 778 6 361 407", "output": "74" }, { "input": "5\n97 166 126 164 154 98 221 7 51 47", "output": "35" }, { "input": "50\n1 1 2 2 1 3 2 2 1 1 1 1 2 3 3 1 2 1 3 3 2 1 2 3 1 1 2 1 3 1 3 1 3 3 3 1 1 1 3 3 2 2 2 2 3 2 2 2 2 3 1 3 3 3 3 1 3 3 1 3 3 3 3 2 3 1 3 3 1 1 1 3 1 2 2 2 1 1 1 3 1 2 3 2 1 3 3 2 2 1 3 1 3 1 2 2 1 2 3 2", "output": "0" }, { "input": "50\n5 5 5 5 4 2 2 3 2 2 4 1 5 5 1 2 4 2 4 2 5 2 2 2 2 3 2 4 2 5 5 4 3 1 2 3 3 5 4 2 2 5 2 4 5 5 4 4 1 5 5 3 2 2 5 1 3 3 2 4 4 5 1 2 3 4 4 1 3 3 3 5 1 2 4 4 4 4 2 5 2 5 3 2 4 5 5 2 1 1 2 4 5 3 2 1 2 4 4 4", "output": "1" }, { "input": "50\n499 780 837 984 481 526 944 482 862 136 265 605 5 631 974 967 574 293 969 467 573 845 102 224 17 873 648 120 694 996 244 313 404 129 899 583 541 314 525 496 443 857 297 78 575 2 430 137 387 319 382 651 594 411 845 746 18 232 6 289 889 81 174 175 805 1000 799 950 475 713 951 685 729 925 262 447 139 217 788 514 658 572 784 185 112 636 10 251 621 218 210 89 597 553 430 532 264 11 160 476", "output": "368" }, { "input": "50\n873 838 288 87 889 364 720 410 565 651 577 356 740 99 549 592 994 385 777 435 486 118 887 440 749 533 356 790 413 681 267 496 475 317 88 660 374 186 61 437 729 860 880 538 277 301 667 180 60 393 955 540 896 241 362 146 74 680 734 767 851 337 751 860 542 735 444 793 340 259 495 903 743 961 964 966 87 275 22 776 368 701 835 732 810 735 267 988 352 647 924 183 1 924 217 944 322 252 758 597", "output": "393" }, { "input": "50\n297 787 34 268 439 629 600 398 425 833 721 908 830 636 64 509 420 647 499 675 427 599 396 119 798 742 577 355 22 847 389 574 766 453 196 772 808 261 106 844 726 975 173 992 874 89 775 616 678 52 69 591 181 573 258 381 665 301 589 379 362 146 790 842 765 100 229 916 938 97 340 793 758 177 736 396 247 562 571 92 923 861 165 748 345 703 431 930 101 761 862 595 505 393 126 846 431 103 596 21", "output": "387" }, { "input": "50\n721 631 587 746 692 406 583 90 388 16 161 948 921 70 387 426 39 398 517 724 879 377 906 502 359 950 798 408 846 718 911 845 57 886 9 668 537 632 344 762 19 193 658 447 870 173 98 156 592 519 183 539 274 393 962 615 551 626 148 183 769 763 829 120 796 761 14 744 537 231 696 284 581 688 611 826 703 145 224 600 965 613 791 275 984 375 402 281 851 580 992 8 816 454 35 532 347 250 242 637", "output": "376" }, { "input": "50\n849 475 37 120 754 183 758 374 543 198 896 691 11 607 198 343 761 660 239 669 628 259 223 182 216 158 20 565 454 884 137 923 156 22 310 77 267 707 582 169 120 308 439 309 59 152 206 696 210 177 296 887 559 22 154 553 142 247 491 692 473 572 461 206 532 319 503 164 328 365 541 366 300 392 486 257 863 432 877 404 520 69 418 99 519 239 374 927 601 103 226 316 423 219 240 26 455 101 184 61", "output": "351" }, { "input": "3\n1 2 10 11 100 100", "output": "1" }, { "input": "17\n814 744 145 886 751 1000 272 914 270 529 467 164 410 369 123 424 991 12 702 582 561 858 746 950 598 393 606 498 648 686 455 873 728 858", "output": "318" }, { "input": "45\n476 103 187 696 463 457 588 632 763 77 391 721 95 124 378 812 980 193 694 898 859 572 721 274 605 264 929 615 257 918 42 493 1 3 697 349 990 800 82 535 382 816 943 735 11 272 562 323 653 370 766 332 666 130 704 604 645 717 267 255 37 470 925 941 376 611 332 758 504 40 477 263 708 434 38 596 650 990 714 662 572 467 949 799 648 581 545 828 508 636", "output": "355" }, { "input": "2\n55 5 25 51", "output": "4" }, { "input": "25\n89 50 640 463 858 301 522 241 923 378 892 822 550 17 42 66 706 779 657 840 273 222 444 459 94 925 437 159 182 727 92 851 742 215 653 891 782 533 29 128 133 883 317 475 165 994 802 434 744 973", "output": "348" }, { "input": "4\n35 48 71 44 78 79 57 48", "output": "10" }, { "input": "3\n58 89 73 15 5 47", "output": "21" }, { "input": "2\n1 20 99 100", "output": "1" } ]
1,699,627,619
2,147,483,647
PyPy 3-64
OK
TESTS
20
62
2,048,000
import itertools n=int(input()) w=sorted(list(map(int,input().split()))) t=[] u=list(itertools.combinations(w,2)) for i in u: a=list(w) a.remove(i[0]) a.remove(i[1]) s=0 for j in range(0, len(a) -1, 2): s += (a[j + 1] - a[j]) t.append(s) print(min(t))
Title: Kayaking Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vadim is really keen on travelling. Recently he heard about kayaking activity near his town and became very excited about it, so he joined a party of kayakers. Now the party is ready to start its journey, but firstly they have to choose kayaks. There are 2·*n* people in the group (including Vadim), and they have exactly *n*<=-<=1 tandem kayaks (each of which, obviously, can carry two people) and 2 single kayaks. *i*-th person's weight is *w**i*, and weight is an important matter in kayaking — if the difference between the weights of two people that sit in the same tandem kayak is too large, then it can crash. And, of course, people want to distribute their seats in kayaks in order to minimize the chances that kayaks will crash. Formally, the instability of a single kayak is always 0, and the instability of a tandem kayak is the absolute difference between weights of the people that are in this kayak. Instability of the whole journey is the total instability of all kayaks. Help the party to determine minimum possible total instability! Input Specification: The first line contains one number *n* (2<=≤<=*n*<=≤<=50). The second line contains 2·*n* integer numbers *w*1, *w*2, ..., *w*2*n*, where *w**i* is weight of person *i* (1<=≤<=*w**i*<=≤<=1000). Output Specification: Print minimum possible total instability. Demo Input: ['2\n1 2 3 4\n', '4\n1 3 4 6 3 4 100 200\n'] Demo Output: ['1\n', '5\n'] Note: none
```python import itertools n=int(input()) w=sorted(list(map(int,input().split()))) t=[] u=list(itertools.combinations(w,2)) for i in u: a=list(w) a.remove(i[0]) a.remove(i[1]) s=0 for j in range(0, len(a) -1, 2): s += (a[j + 1] - a[j]) t.append(s) print(min(t)) ```
3
452
A
Eevee
PROGRAMMING
1,000
[ "brute force", "implementation", "strings" ]
null
null
You are solving the crossword problem K from IPSC 2014. You solved all the clues except for one: who does Eevee evolve into? You are not very into pokemons, but quick googling helped you find out, that Eevee can evolve into eight different pokemons: Vaporeon, Jolteon, Flareon, Espeon, Umbreon, Leafeon, Glaceon, and Sylveon. You know the length of the word in the crossword, and you already know some letters. Designers of the crossword made sure that the answer is unambiguous, so you can assume that exactly one pokemon out of the 8 that Eevee evolves into fits the length and the letters given. Your task is to find it.
First line contains an integer *n* (6<=≤<=*n*<=≤<=8) – the length of the string. Next line contains a string consisting of *n* characters, each of which is either a lower case english letter (indicating a known letter) or a dot character (indicating an empty cell in the crossword).
Print a name of the pokemon that Eevee can evolve into that matches the pattern in the input. Use lower case letters only to print the name (in particular, do not capitalize the first letter).
[ "7\nj......\n", "7\n...feon\n", "7\n.l.r.o.\n" ]
[ "jolteon\n", "leafeon\n", "flareon\n" ]
Here's a set of names in a form you can paste into your solution: ["vaporeon", "jolteon", "flareon", "espeon", "umbreon", "leafeon", "glaceon", "sylveon"] {"vaporeon", "jolteon", "flareon", "espeon", "umbreon", "leafeon", "glaceon", "sylveon"}
500
[ { "input": "7\n...feon", "output": "leafeon" }, { "input": "7\n.l.r.o.", "output": "flareon" }, { "input": "6\n.s..o.", "output": "espeon" }, { "input": "7\nglaceon", "output": "glaceon" }, { "input": "8\n.a.o.e.n", "output": "vaporeon" }, { "input": "7\n.laceon", "output": "glaceon" }, { "input": "7\n..lveon", "output": "sylveon" }, { "input": "7\n.l.ceon", "output": "glaceon" }, { "input": "7\n..areon", "output": "flareon" } ]
1,406,537,074
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
8
61
0
def evolve(l): for e in ["vaporeon", "jolteon", "flareon", "espeon", "umbreon", "leafeon", "glaceon", "sylveon"]: yes = 1 for x in range(min(len(l),len(e))): if l[x] != ".": if l[x] != e[x]: yes = 0 if yes == 1: return e return 0 i = int(input()) l = list(input()) print(evolve(l))
Title: Eevee Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are solving the crossword problem K from IPSC 2014. You solved all the clues except for one: who does Eevee evolve into? You are not very into pokemons, but quick googling helped you find out, that Eevee can evolve into eight different pokemons: Vaporeon, Jolteon, Flareon, Espeon, Umbreon, Leafeon, Glaceon, and Sylveon. You know the length of the word in the crossword, and you already know some letters. Designers of the crossword made sure that the answer is unambiguous, so you can assume that exactly one pokemon out of the 8 that Eevee evolves into fits the length and the letters given. Your task is to find it. Input Specification: First line contains an integer *n* (6<=≤<=*n*<=≤<=8) – the length of the string. Next line contains a string consisting of *n* characters, each of which is either a lower case english letter (indicating a known letter) or a dot character (indicating an empty cell in the crossword). Output Specification: Print a name of the pokemon that Eevee can evolve into that matches the pattern in the input. Use lower case letters only to print the name (in particular, do not capitalize the first letter). Demo Input: ['7\nj......\n', '7\n...feon\n', '7\n.l.r.o.\n'] Demo Output: ['jolteon\n', 'leafeon\n', 'flareon\n'] Note: Here's a set of names in a form you can paste into your solution: ["vaporeon", "jolteon", "flareon", "espeon", "umbreon", "leafeon", "glaceon", "sylveon"] {"vaporeon", "jolteon", "flareon", "espeon", "umbreon", "leafeon", "glaceon", "sylveon"}
```python def evolve(l): for e in ["vaporeon", "jolteon", "flareon", "espeon", "umbreon", "leafeon", "glaceon", "sylveon"]: yes = 1 for x in range(min(len(l),len(e))): if l[x] != ".": if l[x] != e[x]: yes = 0 if yes == 1: return e return 0 i = int(input()) l = list(input()) print(evolve(l)) ```
0
266
B
Queue at the School
PROGRAMMING
800
[ "constructive algorithms", "graph matchings", "implementation", "shortest paths" ]
null
null
During the break the schoolchildren, boys and girls, formed a queue of *n* people in the canteen. Initially the children stood in the order they entered the canteen. However, after a while the boys started feeling awkward for standing in front of the girls in the queue and they started letting the girls move forward each second. Let's describe the process more precisely. Let's say that the positions in the queue are sequentially numbered by integers from 1 to *n*, at that the person in the position number 1 is served first. Then, if at time *x* a boy stands on the *i*-th position and a girl stands on the (*i*<=+<=1)-th position, then at time *x*<=+<=1 the *i*-th position will have a girl and the (*i*<=+<=1)-th position will have a boy. The time is given in seconds. You've got the initial position of the children, at the initial moment of time. Determine the way the queue is going to look after *t* seconds.
The first line contains two integers *n* and *t* (1<=≤<=*n*,<=*t*<=≤<=50), which represent the number of children in the queue and the time after which the queue will transform into the arrangement you need to find. The next line contains string *s*, which represents the schoolchildren's initial arrangement. If the *i*-th position in the queue contains a boy, then the *i*-th character of string *s* equals "B", otherwise the *i*-th character equals "G".
Print string *a*, which describes the arrangement after *t* seconds. If the *i*-th position has a boy after the needed time, then the *i*-th character *a* must equal "B", otherwise it must equal "G".
[ "5 1\nBGGBG\n", "5 2\nBGGBG\n", "4 1\nGGGB\n" ]
[ "GBGGB\n", "GGBGB\n", "GGGB\n" ]
none
500
[ { "input": "5 1\nBGGBG", "output": "GBGGB" }, { "input": "5 2\nBGGBG", "output": "GGBGB" }, { "input": "4 1\nGGGB", "output": "GGGB" }, { "input": "2 1\nBB", "output": "BB" }, { "input": "2 1\nBG", "output": "GB" }, { "input": "6 2\nBBGBBG", "output": "GBBGBB" }, { "input": "8 3\nBBGBGBGB", "output": "GGBGBBBB" }, { "input": "10 3\nBBGBBBBBBG", "output": "GBBBBBGBBB" }, { "input": "22 7\nGBGGBGGGGGBBBGGBGBGBBB", "output": "GGGGGGGGBGGBGGBBBBBBBB" }, { "input": "50 4\nGBBGBBBGGGGGBBGGBBBBGGGBBBGBBBGGBGGBGBBBGGBGGBGGBG", "output": "GGBGBGBGBGBGGGBBGBGBGBGBBBGBGBGBGBGBGBGBGBGBGGBGBB" }, { "input": "50 8\nGGGGBGGBGGGBGBBBGGGGGGGGBBGBGBGBBGGBGGBGGGGGGGGBBG", "output": "GGGGGGGGGGGGBGGBGBGBGBGBGGGGGGBGBGBGBGBGBGGBGGBGBB" }, { "input": "50 30\nBGGGGGGBGGBGBGGGGBGBBGBBBGGBBBGBGBGGGGGBGBBGBGBGGG", "output": "GGGGGGGGGGGGGGGGGGGGGGGGGGGGGGBBBBBBBBBBBBBBBBBBBB" }, { "input": "20 20\nBBGGBGGGGBBBGBBGGGBB", "output": "GGGGGGGGGGBBBBBBBBBB" }, { "input": "27 6\nGBGBGBGGGGGGBGGBGGBBGBBBGBB", "output": "GGGGGGGBGBGBGGGGGBGBBBBBBBB" }, { "input": "46 11\nBGGGGGBGBGGBGGGBBGBBGBBGGBBGBBGBGGGGGGGBGBGBGB", "output": "GGGGGGGGGGGBGGGGGBBGBGBGBGBGBGBGBGBGBGBGBBBBBB" }, { "input": "50 6\nBGGBBBBGGBBBBBBGGBGBGBBBBGBBBBBBGBBBBBBBBBBBBBBBBB", "output": "GGGGBBBBBGBGBGBGBBBGBBBBBBGBBBBBBBBBBBBBBBBBBBBBBB" }, { "input": "50 10\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB", "output": "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB" }, { "input": "50 8\nGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG", "output": "GGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG" }, { "input": "50 10\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBGB", "output": "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBGBBBBBBBBBBB" }, { "input": "50 13\nGGGBGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG", "output": "GGGGGGGGGGGGGGGGBGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG" }, { "input": "1 1\nB", "output": "B" }, { "input": "1 1\nG", "output": "G" }, { "input": "1 50\nB", "output": "B" }, { "input": "1 50\nG", "output": "G" }, { "input": "50 50\nBBBBBBBBGGBBBBBBGBBBBBBBBBBBGBBBBBBBBBBBBBBGBBBBBB", "output": "GGGGGBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB" }, { "input": "50 50\nGGBBGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGBBGGGGGGBG", "output": "GGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGBBBBB" }, { "input": "6 3\nGGBBBG", "output": "GGGBBB" }, { "input": "26 3\nGBBGBBBBBGGGBGBGGGBGBGGBBG", "output": "GGBBBBGBGBGBGGGBGBGGGBGBBB" }, { "input": "46 3\nGGBBGGGGBBGBGBBBBBGGGBGGGBBGGGBBBGGBGGBBBGBGBB", "output": "GGGGBGBGGGBBBBBGBGBGBGGGBGGBGBGBGBGBGBGBGBBBBB" }, { "input": "44 8\nBGBBBBBBBBBGGBBGBGBGGBBBBBGBBGBBBBBBBBBGBBGB", "output": "GBBGBGBGBGBGBGBBBBGBBGBBBBBBBBBGBBGBBBBBBBBB" }, { "input": "20 20\nBBGGBGGGGBBBGBBGGGBB", "output": "GGGGGGGGGGBBBBBBBBBB" }, { "input": "30 25\nBGGBBGBGGBGBGBBGBGGGGBGBGGBBBB", "output": "GGGGGGGGGGGGGGGBBBBBBBBBBBBBBB" }, { "input": "17 42\nBBGBGBGGGGGGBBGGG", "output": "GGGGGGGGGGGBBBBBB" }, { "input": "30 50\nBGGBBGGGGGGGGBBGGGBBGGBBBGBBGG", "output": "GGGGGGGGGGGGGGGGGGBBBBBBBBBBBB" }, { "input": "31 33\nBBGGBBGGBGBBBBGGBGBBBGBGGBBGBBB", "output": "GGGGGGGGGGGGBBBBBBBBBBBBBBBBBBB" }, { "input": "2 2\nBG", "output": "GB" }, { "input": "8 8\nGGGBGGBB", "output": "GGGGGBBB" }, { "input": "34 34\nBGGBBBBGGBBGBGGGGGGBBGGGGGBGGBGGGB", "output": "GGGGGGGGGGGGGGGGGGGGGBBBBBBBBBBBBB" }, { "input": "34 20\nBBBBGBGGGBGGGBGBGGBBBBGGBBGGGBGBBG", "output": "GGGGGGGGGGGGGGGGGBBBBBBBBBBBBBBBBB" }, { "input": "50 50\nBBGBBBBBBBBBBBBGBBBGBBBBBBBGBBBBBBGBBBGBBGBBGBBBGG", "output": "GGGGGGGGGGBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB" }, { "input": "10 10\nGGGGGGGGGG", "output": "GGGGGGGGGG" }, { "input": "10 10\nBBBBBBBBBB", "output": "BBBBBBBBBB" }, { "input": "10 10\nBGBGBGBGBG", "output": "GGGGGBBBBB" }, { "input": "1 1\nB", "output": "B" } ]
1,697,890,233
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
62
0
n, t = map(int, input().split()) v = [char for char in input()] if n == 1: print(''.join(v)) quit() r = "" l = n - 1 for i in reversed(range(len(v))): if v[i] == "B": if i + t < l: del v[i] v.append("B") # v[i], v[i + t] = v[i + t], v[i] v.insert(i + t, "B") else: del v[i] v.append("B") print(''.join(v))
Title: Queue at the School Time Limit: None seconds Memory Limit: None megabytes Problem Description: During the break the schoolchildren, boys and girls, formed a queue of *n* people in the canteen. Initially the children stood in the order they entered the canteen. However, after a while the boys started feeling awkward for standing in front of the girls in the queue and they started letting the girls move forward each second. Let's describe the process more precisely. Let's say that the positions in the queue are sequentially numbered by integers from 1 to *n*, at that the person in the position number 1 is served first. Then, if at time *x* a boy stands on the *i*-th position and a girl stands on the (*i*<=+<=1)-th position, then at time *x*<=+<=1 the *i*-th position will have a girl and the (*i*<=+<=1)-th position will have a boy. The time is given in seconds. You've got the initial position of the children, at the initial moment of time. Determine the way the queue is going to look after *t* seconds. Input Specification: The first line contains two integers *n* and *t* (1<=≤<=*n*,<=*t*<=≤<=50), which represent the number of children in the queue and the time after which the queue will transform into the arrangement you need to find. The next line contains string *s*, which represents the schoolchildren's initial arrangement. If the *i*-th position in the queue contains a boy, then the *i*-th character of string *s* equals "B", otherwise the *i*-th character equals "G". Output Specification: Print string *a*, which describes the arrangement after *t* seconds. If the *i*-th position has a boy after the needed time, then the *i*-th character *a* must equal "B", otherwise it must equal "G". Demo Input: ['5 1\nBGGBG\n', '5 2\nBGGBG\n', '4 1\nGGGB\n'] Demo Output: ['GBGGB\n', 'GGBGB\n', 'GGGB\n'] Note: none
```python n, t = map(int, input().split()) v = [char for char in input()] if n == 1: print(''.join(v)) quit() r = "" l = n - 1 for i in reversed(range(len(v))): if v[i] == "B": if i + t < l: del v[i] v.append("B") # v[i], v[i + t] = v[i + t], v[i] v.insert(i + t, "B") else: del v[i] v.append("B") print(''.join(v)) ```
0
615
A
Bulbs
PROGRAMMING
800
[ "implementation" ]
null
null
Vasya wants to turn on Christmas lights consisting of *m* bulbs. Initially, all bulbs are turned off. There are *n* buttons, each of them is connected to some set of bulbs. Vasya can press any of these buttons. When the button is pressed, it turns on all the bulbs it's connected to. Can Vasya light up all the bulbs? If Vasya presses the button such that some bulbs connected to it are already turned on, they do not change their state, i.e. remain turned on.
The first line of the input contains integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of buttons and the number of bulbs respectively. Each of the next *n* lines contains *x**i* (0<=≤<=*x**i*<=≤<=*m*) — the number of bulbs that are turned on by the *i*-th button, and then *x**i* numbers *y**ij* (1<=≤<=*y**ij*<=≤<=*m*) — the numbers of these bulbs.
If it's possible to turn on all *m* bulbs print "YES", otherwise print "NO".
[ "3 4\n2 1 4\n3 1 3 1\n1 2\n", "3 3\n1 1\n1 2\n1 1\n" ]
[ "YES\n", "NO\n" ]
In the first sample you can press each button once and turn on all the bulbs. In the 2 sample it is impossible to turn on the 3-rd lamp.
500
[ { "input": "3 4\n2 1 4\n3 1 3 1\n1 2", "output": "YES" }, { "input": "3 3\n1 1\n1 2\n1 1", "output": "NO" }, { "input": "3 4\n1 1\n1 2\n1 3", "output": "NO" }, { "input": "1 5\n5 1 2 3 4 5", "output": "YES" }, { "input": "1 5\n5 4 4 1 2 3", "output": "NO" }, { "input": "1 5\n5 1 1 1 1 5", "output": "NO" }, { "input": "2 5\n4 3 1 4 2\n4 2 3 4 5", "output": "YES" }, { "input": "5 7\n2 6 7\n5 1 1 1 1 1\n3 6 5 4\n0\n4 4 3 2 1", "output": "YES" }, { "input": "100 100\n0\n0\n0\n1 53\n0\n0\n1 34\n1 54\n0\n1 14\n0\n1 33\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n1 82\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n1 34\n0\n0\n1 26\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n1 34\n0\n0\n0\n0\n0\n1 3\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n1 40\n0\n0\n0\n1 26\n0\n0\n0\n0\n0\n1 97\n0\n1 5\n0\n0\n0\n0\n0", "output": "NO" }, { "input": "100 100\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0", "output": "NO" }, { "input": "5 6\n3 1 2 6\n3 1 2 6\n1 1\n2 3 4\n3 1 5 6", "output": "YES" }, { "input": "5 2\n1 1\n1 1\n1 1\n1 1\n1 1", "output": "NO" }, { "input": "1 4\n3 1 2 3", "output": "NO" }, { "input": "1 4\n3 2 3 4", "output": "NO" }, { "input": "2 4\n3 2 3 4\n1 1", "output": "YES" }, { "input": "2 4\n3 1 2 3\n1 4", "output": "YES" }, { "input": "5 1\n0\n0\n0\n0\n0", "output": "NO" }, { "input": "1 1\n0", "output": "NO" }, { "input": "1 10\n10 1 2 3 4 5 6 7 8 9 10", "output": "YES" }, { "input": "1 1\n1 1", "output": "YES" }, { "input": "1 100\n99 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99", "output": "NO" }, { "input": "1 3\n3 1 2 1", "output": "NO" }, { "input": "1 100\n100 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100", "output": "YES" } ]
1,635,257,172
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
4
46
4,505,600
n, m = map(int, input().split()) bulbs = {i: False for i in range(1, m + 1)} for _ in range(n): line = map(int, input().split()) for item in line: bulbs[item] = True ret = True for key in bulbs: ret = ret & bulbs[key] # print(bulbs) print('YES' if ret else 'NO')
Title: Bulbs Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vasya wants to turn on Christmas lights consisting of *m* bulbs. Initially, all bulbs are turned off. There are *n* buttons, each of them is connected to some set of bulbs. Vasya can press any of these buttons. When the button is pressed, it turns on all the bulbs it's connected to. Can Vasya light up all the bulbs? If Vasya presses the button such that some bulbs connected to it are already turned on, they do not change their state, i.e. remain turned on. Input Specification: The first line of the input contains integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of buttons and the number of bulbs respectively. Each of the next *n* lines contains *x**i* (0<=≤<=*x**i*<=≤<=*m*) — the number of bulbs that are turned on by the *i*-th button, and then *x**i* numbers *y**ij* (1<=≤<=*y**ij*<=≤<=*m*) — the numbers of these bulbs. Output Specification: If it's possible to turn on all *m* bulbs print "YES", otherwise print "NO". Demo Input: ['3 4\n2 1 4\n3 1 3 1\n1 2\n', '3 3\n1 1\n1 2\n1 1\n'] Demo Output: ['YES\n', 'NO\n'] Note: In the first sample you can press each button once and turn on all the bulbs. In the 2 sample it is impossible to turn on the 3-rd lamp.
```python n, m = map(int, input().split()) bulbs = {i: False for i in range(1, m + 1)} for _ in range(n): line = map(int, input().split()) for item in line: bulbs[item] = True ret = True for key in bulbs: ret = ret & bulbs[key] # print(bulbs) print('YES' if ret else 'NO') ```
0
1,009
C
Annoying Present
PROGRAMMING
1,700
[ "greedy", "math" ]
null
null
Alice got an array of length $n$ as a birthday present once again! This is the third year in a row! And what is more disappointing, it is overwhelmengly boring, filled entirely with zeros. Bob decided to apply some changes to the array to cheer up Alice. Bob has chosen $m$ changes of the following form. For some integer numbers $x$ and $d$, he chooses an arbitrary position $i$ ($1 \le i \le n$) and for every $j \in [1, n]$ adds $x + d \cdot dist(i, j)$ to the value of the $j$-th cell. $dist(i, j)$ is the distance between positions $i$ and $j$ (i.e. $dist(i, j) = |i - j|$, where $|x|$ is an absolute value of $x$). For example, if Alice currently has an array $[2, 1, 2, 2]$ and Bob chooses position $3$ for $x = -1$ and $d = 2$ then the array will become $[2 - 1 + 2 \cdot 2,~1 - 1 + 2 \cdot 1,~2 - 1 + 2 \cdot 0,~2 - 1 + 2 \cdot 1]$ = $[5, 2, 1, 3]$. Note that Bob can't choose position $i$ outside of the array (that is, smaller than $1$ or greater than $n$). Alice will be the happiest when the elements of the array are as big as possible. Bob claimed that the arithmetic mean value of the elements will work fine as a metric. What is the maximum arithmetic mean value Bob can achieve?
The first line contains two integers $n$ and $m$ ($1 \le n, m \le 10^5$) — the number of elements of the array and the number of changes. Each of the next $m$ lines contains two integers $x_i$ and $d_i$ ($-10^3 \le x_i, d_i \le 10^3$) — the parameters for the $i$-th change.
Print the maximal average arithmetic mean of the elements Bob can achieve. Your answer is considered correct if its absolute or relative error doesn't exceed $10^{-6}$.
[ "2 3\n-1 3\n0 0\n-1 -4\n", "3 2\n0 2\n5 0\n" ]
[ "-2.500000000000000\n", "7.000000000000000\n" ]
none
0
[ { "input": "2 3\n-1 3\n0 0\n-1 -4", "output": "-2.500000000000000" }, { "input": "3 2\n0 2\n5 0", "output": "7.000000000000000" }, { "input": "8 8\n-21 -60\n-96 -10\n-4 -19\n-27 -4\n57 -15\n-95 62\n-42 1\n-17 64", "output": "-16.500000000000000" }, { "input": "1 1\n0 0", "output": "0.000000000000000" }, { "input": "100000 1\n1000 1000", "output": "50000500.000000000000000" }, { "input": "11 1\n0 -10", "output": "-27.272727272727273" }, { "input": "3 1\n1 -1", "output": "0.333333333333333" }, { "input": "1 2\n-1 -1\n-2 -2", "output": "-3.000000000000000" }, { "input": "1 2\n0 -1\n0 1", "output": "0.000000000000000" }, { "input": "1 1\n1 -2", "output": "1.000000000000000" }, { "input": "3 1\n2 -1", "output": "1.333333333333333" }, { "input": "3 1\n0 -1", "output": "-0.666666666666667" }, { "input": "1 1\n-1000 -1000", "output": "-1000.000000000000000" }, { "input": "1 1\n0 -5", "output": "0.000000000000000" }, { "input": "15 3\n2 0\n2 -5\n-2 5", "output": "18.333333333333332" }, { "input": "9 1\n0 -5", "output": "-11.111111111111111" }, { "input": "7 1\n0 -1", "output": "-1.714285714285714" }, { "input": "3 1\n-2 -2", "output": "-3.333333333333333" }, { "input": "3 1\n5 -5", "output": "1.666666666666667" }, { "input": "1 1\n-1 -1", "output": "-1.000000000000000" }, { "input": "7 1\n-1 -5", "output": "-9.571428571428571" }, { "input": "3 2\n-2 -2\n-2 -2", "output": "-6.666666666666667" }, { "input": "5 1\n0 -4", "output": "-4.800000000000000" }, { "input": "5 1\n-1 -5", "output": "-7.000000000000000" }, { "input": "5 1\n0 -2", "output": "-2.400000000000000" }, { "input": "3 5\n1 -1000\n1 -1000\n1 -1000\n1 -1000\n1 -1000", "output": "-3328.333333333333485" }, { "input": "1 1\n0 -1", "output": "0.000000000000000" }, { "input": "1 2\n0 -3\n0 -3", "output": "0.000000000000000" }, { "input": "7 1\n2 -3", "output": "-3.142857142857143" }, { "input": "3 2\n-1 -1\n-1 -1", "output": "-3.333333333333333" }, { "input": "5 1\n-1 -162", "output": "-195.400000000000006" }, { "input": "5 10\n-506 -243\n727 -141\n-548 -306\n740 880\n-744 -116\n-84 182\n-859 -108\n64 86\n135 446\n69 -184", "output": "864.399999999999977" }, { "input": "5 1\n0 -1", "output": "-1.200000000000000" }, { "input": "5 12\n634 895\n143 730\n901 245\n386 486\n395 -111\n-469 -104\n-681 -623\n-900 843\n889 -883\n476 -304\n777 986\n206 -491", "output": "8107.800000000000182" }, { "input": "3 3\n4 2\n5 0\n6 -1", "output": "16.333333333333332" }, { "input": "1 3\n4 2\n5 0\n6 -1", "output": "15.000000000000000" }, { "input": "85 10\n-223 435\n-771 455\n72 -940\n490 -178\n400 -117\n169 -527\n836 610\n849 944\n572 -237\n-428 -428", "output": "53047.388235294114565" }, { "input": "69 10\n-8 4\n-3 3\n7 5\n5 -9\n8 1\n7 -5\n-8 -8\n9 3\n1 1\n0 6", "output": "420.579710144927560" }, { "input": "1 10\n1 1\n1 0\n1 0\n1 0\n-1 0\n0 1\n1 0\n0 0\n2 1\n9 2", "output": "15.000000000000000" }, { "input": "5 4\n0 1\n0 2\n0 3\n0 -9", "output": "1.200000000000000" } ]
1,532,353,128
2,147,483,647
Python 3
OK
TESTS
54
420
0
def fun(y): return y * (y + 1) // 2 n, m = map(int, input().split()) ans = 0 I = (n + 1) // 2 MIN = fun(I - 1) + fun(n - I) MAX = fun(n - 1) for i in range(m): x, d = map(int, input().split()) ans += n * x + d * (MIN if d < 0 else MAX) print("%.12f" % (ans / n))
Title: Annoying Present Time Limit: None seconds Memory Limit: None megabytes Problem Description: Alice got an array of length $n$ as a birthday present once again! This is the third year in a row! And what is more disappointing, it is overwhelmengly boring, filled entirely with zeros. Bob decided to apply some changes to the array to cheer up Alice. Bob has chosen $m$ changes of the following form. For some integer numbers $x$ and $d$, he chooses an arbitrary position $i$ ($1 \le i \le n$) and for every $j \in [1, n]$ adds $x + d \cdot dist(i, j)$ to the value of the $j$-th cell. $dist(i, j)$ is the distance between positions $i$ and $j$ (i.e. $dist(i, j) = |i - j|$, where $|x|$ is an absolute value of $x$). For example, if Alice currently has an array $[2, 1, 2, 2]$ and Bob chooses position $3$ for $x = -1$ and $d = 2$ then the array will become $[2 - 1 + 2 \cdot 2,~1 - 1 + 2 \cdot 1,~2 - 1 + 2 \cdot 0,~2 - 1 + 2 \cdot 1]$ = $[5, 2, 1, 3]$. Note that Bob can't choose position $i$ outside of the array (that is, smaller than $1$ or greater than $n$). Alice will be the happiest when the elements of the array are as big as possible. Bob claimed that the arithmetic mean value of the elements will work fine as a metric. What is the maximum arithmetic mean value Bob can achieve? Input Specification: The first line contains two integers $n$ and $m$ ($1 \le n, m \le 10^5$) — the number of elements of the array and the number of changes. Each of the next $m$ lines contains two integers $x_i$ and $d_i$ ($-10^3 \le x_i, d_i \le 10^3$) — the parameters for the $i$-th change. Output Specification: Print the maximal average arithmetic mean of the elements Bob can achieve. Your answer is considered correct if its absolute or relative error doesn't exceed $10^{-6}$. Demo Input: ['2 3\n-1 3\n0 0\n-1 -4\n', '3 2\n0 2\n5 0\n'] Demo Output: ['-2.500000000000000\n', '7.000000000000000\n'] Note: none
```python def fun(y): return y * (y + 1) // 2 n, m = map(int, input().split()) ans = 0 I = (n + 1) // 2 MIN = fun(I - 1) + fun(n - I) MAX = fun(n - 1) for i in range(m): x, d = map(int, input().split()) ans += n * x + d * (MIN if d < 0 else MAX) print("%.12f" % (ans / n)) ```
3
1
A
Theatre Square
PROGRAMMING
1,000
[ "math" ]
A. Theatre Square
1
256
Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size *a*<=×<=*a*. What is the least number of flagstones needed to pave the Square? It's allowed to cover the surface larger than the Theatre Square, but the Square has to be covered. It's not allowed to break the flagstones. The sides of flagstones should be parallel to the sides of the Square.
The input contains three positive integer numbers in the first line: *n*,<=<=*m* and *a* (1<=≤<=<=*n*,<=*m*,<=*a*<=≤<=109).
Write the needed number of flagstones.
[ "6 6 4\n" ]
[ "4\n" ]
none
0
[ { "input": "6 6 4", "output": "4" }, { "input": "1 1 1", "output": "1" }, { "input": "2 1 1", "output": "2" }, { "input": "1 2 1", "output": "2" }, { "input": "2 2 1", "output": "4" }, { "input": "2 1 2", "output": "1" }, { "input": "1 1 3", "output": "1" }, { "input": "2 3 4", "output": "1" }, { "input": "1000000000 1000000000 1", "output": "1000000000000000000" }, { "input": "12 13 4", "output": "12" }, { "input": "222 332 5", "output": "3015" }, { "input": "1000 1000 10", "output": "10000" }, { "input": "1001 1000 10", "output": "10100" }, { "input": "100 10001 1000000000", "output": "1" }, { "input": "1000000000 1000000000 1000000000", "output": "1" }, { "input": "1000000000 1000000000 999999999", "output": "4" }, { "input": "1000000000 1000000000 192", "output": "27126743055556" }, { "input": "1000000000 987654321 1", "output": "987654321000000000" }, { "input": "456784567 1000000000 51", "output": "175618850864484" }, { "input": "39916800 134217728 40320", "output": "3295710" } ]
1,659,898,323
2,147,483,647
Python 3
OK
TESTS
20
46
0
import math a,b,c= map(int,input().split()) d = math.ceil(a/c) e = math.ceil(b/c) print(d*e)
Title: Theatre Square Time Limit: 1 seconds Memory Limit: 256 megabytes Problem Description: Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size *a*<=×<=*a*. What is the least number of flagstones needed to pave the Square? It's allowed to cover the surface larger than the Theatre Square, but the Square has to be covered. It's not allowed to break the flagstones. The sides of flagstones should be parallel to the sides of the Square. Input Specification: The input contains three positive integer numbers in the first line: *n*,<=<=*m* and *a* (1<=≤<=<=*n*,<=*m*,<=*a*<=≤<=109). Output Specification: Write the needed number of flagstones. Demo Input: ['6 6 4\n'] Demo Output: ['4\n'] Note: none
```python import math a,b,c= map(int,input().split()) d = math.ceil(a/c) e = math.ceil(b/c) print(d*e) ```
3.977
119
A
Epic Game
PROGRAMMING
800
[ "implementation" ]
null
null
Simon and Antisimon play a game. Initially each player receives one fixed positive integer that doesn't change throughout the game. Simon receives number *a* and Antisimon receives number *b*. They also have a heap of *n* stones. The players take turns to make a move and Simon starts. During a move a player should take from the heap the number of stones equal to the greatest common divisor of the fixed number he has received and the number of stones left in the heap. A player loses when he cannot take the required number of stones (i. e. the heap has strictly less stones left than one needs to take). Your task is to determine by the given *a*, *b* and *n* who wins the game.
The only string contains space-separated integers *a*, *b* and *n* (1<=≤<=*a*,<=*b*,<=*n*<=≤<=100) — the fixed numbers Simon and Antisimon have received correspondingly and the initial number of stones in the pile.
If Simon wins, print "0" (without the quotes), otherwise print "1" (without the quotes).
[ "3 5 9\n", "1 1 100\n" ]
[ "0", "1" ]
The greatest common divisor of two non-negative integers *a* and *b* is such maximum positive integer *k*, that *a* is divisible by *k* without remainder and similarly, *b* is divisible by *k* without remainder. Let *gcd*(*a*, *b*) represent the operation of calculating the greatest common divisor of numbers *a* and *b*. Specifically, *gcd*(*x*, 0) = *gcd*(0, *x*) = *x*. In the first sample the game will go like that: - Simon should take *gcd*(3, 9) = 3 stones from the heap. After his move the heap has 6 stones left.- Antisimon should take *gcd*(5, 6) = 1 stone from the heap. After his move the heap has 5 stones left.- Simon should take *gcd*(3, 5) = 1 stone from the heap. After his move the heap has 4 stones left.- Antisimon should take *gcd*(5, 4) = 1 stone from the heap. After his move the heap has 3 stones left.- Simon should take *gcd*(3, 3) = 3 stones from the heap. After his move the heap has 0 stones left.- Antisimon should take *gcd*(5, 0) = 5 stones from the heap. As 0 &lt; 5, it is impossible and Antisimon loses. In the second sample each player during each move takes one stone from the heap. As *n* is even, Antisimon takes the last stone and Simon can't make a move after that.
500
[ { "input": "3 5 9", "output": "0" }, { "input": "1 1 100", "output": "1" }, { "input": "23 12 16", "output": "1" }, { "input": "95 26 29", "output": "1" }, { "input": "73 32 99", "output": "1" }, { "input": "1 1 1", "output": "0" }, { "input": "41 12 65", "output": "1" }, { "input": "13 61 100", "output": "1" }, { "input": "100 100 10", "output": "0" }, { "input": "12 24 26", "output": "1" }, { "input": "73 21 96", "output": "1" }, { "input": "17 22 81", "output": "1" }, { "input": "14 88 97", "output": "1" }, { "input": "42 81 17", "output": "0" }, { "input": "34 36 19", "output": "1" }, { "input": "21 87 12", "output": "1" }, { "input": "97 92 98", "output": "1" }, { "input": "49 25 62", "output": "1" }, { "input": "29 17 44", "output": "1" }, { "input": "10 1 10", "output": "0" }, { "input": "99 98 100", "output": "1" }, { "input": "100 100 1", "output": "0" }, { "input": "11 99 55", "output": "0" }, { "input": "8 13 21", "output": "0" }, { "input": "34 55 89", "output": "0" }, { "input": "21 34 55", "output": "1" }, { "input": "13 21 34", "output": "1" }, { "input": "34 21 55", "output": "0" }, { "input": "10 20 84", "output": "1" }, { "input": "4 2 5", "output": "0" }, { "input": "3 2 3", "output": "0" }, { "input": "31 23 1", "output": "0" }, { "input": "100 100 100", "output": "0" }, { "input": "100 1 100", "output": "0" }, { "input": "1 100 100", "output": "1" }, { "input": "1 1 100", "output": "1" }, { "input": "17 23 100", "output": "1" }, { "input": "99 98 100", "output": "1" }, { "input": "1 1 2", "output": "1" }, { "input": "2 1 1", "output": "0" }, { "input": "1 2 1", "output": "0" }, { "input": "2 1 2", "output": "0" }, { "input": "10 10 3", "output": "1" }, { "input": "2 2 1", "output": "0" }, { "input": "9 5 1", "output": "0" } ]
1,621,840,360
2,147,483,647
Python 3
OK
TESTS
45
124
0
import math a,b,n=map(int,input().split()) flag=-1 while True: if n>0: #print("an-=,an",math.gcd(n,a),n) n=n-math.gcd(n,a) else: flag=1 break if n>0: #print("bn-=,bn",math.gcd(n,b),n) n=n-math.gcd(n,b) else: flag=0 break print(flag)
Title: Epic Game Time Limit: None seconds Memory Limit: None megabytes Problem Description: Simon and Antisimon play a game. Initially each player receives one fixed positive integer that doesn't change throughout the game. Simon receives number *a* and Antisimon receives number *b*. They also have a heap of *n* stones. The players take turns to make a move and Simon starts. During a move a player should take from the heap the number of stones equal to the greatest common divisor of the fixed number he has received and the number of stones left in the heap. A player loses when he cannot take the required number of stones (i. e. the heap has strictly less stones left than one needs to take). Your task is to determine by the given *a*, *b* and *n* who wins the game. Input Specification: The only string contains space-separated integers *a*, *b* and *n* (1<=≤<=*a*,<=*b*,<=*n*<=≤<=100) — the fixed numbers Simon and Antisimon have received correspondingly and the initial number of stones in the pile. Output Specification: If Simon wins, print "0" (without the quotes), otherwise print "1" (without the quotes). Demo Input: ['3 5 9\n', '1 1 100\n'] Demo Output: ['0', '1'] Note: The greatest common divisor of two non-negative integers *a* and *b* is such maximum positive integer *k*, that *a* is divisible by *k* without remainder and similarly, *b* is divisible by *k* without remainder. Let *gcd*(*a*, *b*) represent the operation of calculating the greatest common divisor of numbers *a* and *b*. Specifically, *gcd*(*x*, 0) = *gcd*(0, *x*) = *x*. In the first sample the game will go like that: - Simon should take *gcd*(3, 9) = 3 stones from the heap. After his move the heap has 6 stones left.- Antisimon should take *gcd*(5, 6) = 1 stone from the heap. After his move the heap has 5 stones left.- Simon should take *gcd*(3, 5) = 1 stone from the heap. After his move the heap has 4 stones left.- Antisimon should take *gcd*(5, 4) = 1 stone from the heap. After his move the heap has 3 stones left.- Simon should take *gcd*(3, 3) = 3 stones from the heap. After his move the heap has 0 stones left.- Antisimon should take *gcd*(5, 0) = 5 stones from the heap. As 0 &lt; 5, it is impossible and Antisimon loses. In the second sample each player during each move takes one stone from the heap. As *n* is even, Antisimon takes the last stone and Simon can't make a move after that.
```python import math a,b,n=map(int,input().split()) flag=-1 while True: if n>0: #print("an-=,an",math.gcd(n,a),n) n=n-math.gcd(n,a) else: flag=1 break if n>0: #print("bn-=,bn",math.gcd(n,b),n) n=n-math.gcd(n,b) else: flag=0 break print(flag) ```
3
545
D
Queue
PROGRAMMING
1,300
[ "greedy", "implementation", "sortings" ]
null
null
Little girl Susie went shopping with her mom and she wondered how to improve service quality. There are *n* people in the queue. For each person we know time *t**i* needed to serve him. A person will be disappointed if the time he waits is more than the time needed to serve him. The time a person waits is the total time when all the people who stand in the queue in front of him are served. Susie thought that if we swap some people in the queue, then we can decrease the number of people who are disappointed. Help Susie find out what is the maximum number of not disappointed people can be achieved by swapping people in the queue.
The first line contains integer *n* (1<=≤<=*n*<=≤<=105). The next line contains *n* integers *t**i* (1<=≤<=*t**i*<=≤<=109), separated by spaces.
Print a single number — the maximum number of not disappointed people in the queue.
[ "5\n15 2 1 5 3\n" ]
[ "4\n" ]
Value 4 is achieved at such an arrangement, for example: 1, 2, 3, 5, 15. Thus, you can make everything feel not disappointed except for the person with time 5.
1,750
[ { "input": "5\n15 2 1 5 3", "output": "4" }, { "input": "15\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "2" }, { "input": "10\n13 2 5 55 21 34 1 8 1 3", "output": "6" }, { "input": "10\n8 256 16 1 2 1 64 4 128 32", "output": "10" }, { "input": "10\n10000 40000 10000 50000 20000 100000 10000 100 30000 500", "output": "6" }, { "input": "1\n1000000000", "output": "1" }, { "input": "15\n9 11 45 86 52 65 35 3 93 7 21 45 15 11 39", "output": "6" }, { "input": "20\n16839799 17525904 91276752 42650694 60106463 12243176 54892123 25142243 16015971 41250998 11150057 6994983 67700784 16562412 82163675 46178521 33914268 91966607 93976858 84100064", "output": "5" }, { "input": "26\n1000 4110030 64221 131521030 942374833 1003 2055015 32110 513757 16440130 263042057 32880256 128439 557559573 16051 8220066 469240078 65760513 256878 790176315 4012 2005 1027508 928528684 8030 805074697", "output": "21" } ]
1,695,997,469
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
46
0
n = int(input()) a = [int(x) for x in input().split()] a.sort() wt, cnt = 0, 0 # wait time, count for i in range(n): if wt < a[i]: cnt += 1 wt += a[i] print(cnt)
Title: Queue Time Limit: None seconds Memory Limit: None megabytes Problem Description: Little girl Susie went shopping with her mom and she wondered how to improve service quality. There are *n* people in the queue. For each person we know time *t**i* needed to serve him. A person will be disappointed if the time he waits is more than the time needed to serve him. The time a person waits is the total time when all the people who stand in the queue in front of him are served. Susie thought that if we swap some people in the queue, then we can decrease the number of people who are disappointed. Help Susie find out what is the maximum number of not disappointed people can be achieved by swapping people in the queue. Input Specification: The first line contains integer *n* (1<=≤<=*n*<=≤<=105). The next line contains *n* integers *t**i* (1<=≤<=*t**i*<=≤<=109), separated by spaces. Output Specification: Print a single number — the maximum number of not disappointed people in the queue. Demo Input: ['5\n15 2 1 5 3\n'] Demo Output: ['4\n'] Note: Value 4 is achieved at such an arrangement, for example: 1, 2, 3, 5, 15. Thus, you can make everything feel not disappointed except for the person with time 5.
```python n = int(input()) a = [int(x) for x in input().split()] a.sort() wt, cnt = 0, 0 # wait time, count for i in range(n): if wt < a[i]: cnt += 1 wt += a[i] print(cnt) ```
0
50
A
Domino piling
PROGRAMMING
800
[ "greedy", "math" ]
A. Domino piling
2
256
You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions: 1. Each domino completely covers two squares. 2. No two dominoes overlap. 3. Each domino lies entirely inside the board. It is allowed to touch the edges of the board. Find the maximum number of dominoes, which can be placed under these restrictions.
In a single line you are given two integers *M* and *N* — board sizes in squares (1<=≤<=*M*<=≤<=*N*<=≤<=16).
Output one number — the maximal number of dominoes, which can be placed.
[ "2 4\n", "3 3\n" ]
[ "4\n", "4\n" ]
none
500
[ { "input": "2 4", "output": "4" }, { "input": "3 3", "output": "4" }, { "input": "1 5", "output": "2" }, { "input": "1 6", "output": "3" }, { "input": "1 15", "output": "7" }, { "input": "1 16", "output": "8" }, { "input": "2 5", "output": "5" }, { "input": "2 6", "output": "6" }, { "input": "2 7", "output": "7" }, { "input": "2 14", "output": "14" }, { "input": "2 15", "output": "15" }, { "input": "1 4", "output": "2" }, { "input": "2 16", "output": "16" }, { "input": "3 5", "output": "7" }, { "input": "3 6", "output": "9" }, { "input": "3 10", "output": "15" }, { "input": "3 14", "output": "21" }, { "input": "3 15", "output": "22" }, { "input": "3 16", "output": "24" }, { "input": "5 7", "output": "17" }, { "input": "16 16", "output": "128" }, { "input": "15 16", "output": "120" }, { "input": "2 3", "output": "3" }, { "input": "15 15", "output": "112" }, { "input": "14 16", "output": "112" }, { "input": "11 13", "output": "71" }, { "input": "5 16", "output": "40" }, { "input": "8 15", "output": "60" }, { "input": "2 2", "output": "2" }, { "input": "3 4", "output": "6" }, { "input": "4 4", "output": "8" }, { "input": "1 1", "output": "0" }, { "input": "1 2", "output": "1" }, { "input": "1 3", "output": "1" }, { "input": "14 15", "output": "105" } ]
1,668,966,427
2,147,483,647
Python 3
OK
TESTS
35
122
0
n,m = map(int,input().split()) c = ((m*n)//2) print(c)
Title: Domino piling Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions: 1. Each domino completely covers two squares. 2. No two dominoes overlap. 3. Each domino lies entirely inside the board. It is allowed to touch the edges of the board. Find the maximum number of dominoes, which can be placed under these restrictions. Input Specification: In a single line you are given two integers *M* and *N* — board sizes in squares (1<=≤<=*M*<=≤<=*N*<=≤<=16). Output Specification: Output one number — the maximal number of dominoes, which can be placed. Demo Input: ['2 4\n', '3 3\n'] Demo Output: ['4\n', '4\n'] Note: none
```python n,m = map(int,input().split()) c = ((m*n)//2) print(c) ```
3.9695
365
A
Good Number
PROGRAMMING
1,100
[ "implementation" ]
null
null
Let's call a number *k*-good if it contains all digits not exceeding *k* (0,<=...,<=*k*). You've got a number *k* and an array *a* containing *n* numbers. Find out how many *k*-good numbers are in *a* (count each number every time it occurs in array *a*).
The first line contains integers *n* and *k* (1<=≤<=*n*<=≤<=100, 0<=≤<=*k*<=≤<=9). The *i*-th of the following *n* lines contains integer *a**i* without leading zeroes (1<=≤<=*a**i*<=≤<=109).
Print a single integer — the number of *k*-good numbers in *a*.
[ "10 6\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n", "2 1\n1\n10\n" ]
[ "10\n", "1\n" ]
none
500
[ { "input": "10 6\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560", "output": "10" }, { "input": "2 1\n1\n10", "output": "1" }, { "input": "1 0\n1000000000", "output": "1" }, { "input": "1 1\n1000000000", "output": "1" }, { "input": "6 0\n10\n102\n120\n1032\n1212103\n1999999", "output": "5" }, { "input": "1 3\n1000000000", "output": "0" }, { "input": "1 9\n1000000000", "output": "0" }, { "input": "1 0\n1", "output": "0" }, { "input": "1 1\n1", "output": "0" }, { "input": "1 3\n1", "output": "0" }, { "input": "1 9\n1", "output": "0" }, { "input": "2 8\n123456780\n123", "output": "1" }, { "input": "2 8\n12345678\n1230", "output": "0" }, { "input": "6 1\n10\n102\n120\n1032\n1212103\n1999999", "output": "5" }, { "input": "6 2\n10\n102\n120\n1032\n1212103\n1999999", "output": "4" }, { "input": "6 3\n10\n102\n120\n1032\n1212103\n1999999", "output": "2" }, { "input": "6 9\n10\n102\n120\n1032\n1212103\n1999999", "output": "0" }, { "input": "1 2\n2220", "output": "0" } ]
1,644,657,008
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
2
31
0
t = input().split() a = int(t[0]) n = int(t[1]) counter = 0 c = 0 for i in range(a): c = [0]*10 x = input() if not (len(x) > (n+1)): for i in range(len(x)): c[int(i)] = 1 if c.count(1) == n+1: counter +=1 print(counter)
Title: Good Number Time Limit: None seconds Memory Limit: None megabytes Problem Description: Let's call a number *k*-good if it contains all digits not exceeding *k* (0,<=...,<=*k*). You've got a number *k* and an array *a* containing *n* numbers. Find out how many *k*-good numbers are in *a* (count each number every time it occurs in array *a*). Input Specification: The first line contains integers *n* and *k* (1<=≤<=*n*<=≤<=100, 0<=≤<=*k*<=≤<=9). The *i*-th of the following *n* lines contains integer *a**i* without leading zeroes (1<=≤<=*a**i*<=≤<=109). Output Specification: Print a single integer — the number of *k*-good numbers in *a*. Demo Input: ['10 6\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n', '2 1\n1\n10\n'] Demo Output: ['10\n', '1\n'] Note: none
```python t = input().split() a = int(t[0]) n = int(t[1]) counter = 0 c = 0 for i in range(a): c = [0]*10 x = input() if not (len(x) > (n+1)): for i in range(len(x)): c[int(i)] = 1 if c.count(1) == n+1: counter +=1 print(counter) ```
0
714
A
Meeting of Old Friends
PROGRAMMING
1,100
[ "implementation", "math" ]
null
null
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.
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*<=≤<=1018, *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.
Print one integer — the number of minutes Sonya and Filya will be able to spend together.
[ "1 10 9 20 1\n", "1 100 50 200 75\n" ]
[ "2\n", "50\n" ]
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.
500
[ { "input": "1 10 9 20 1", "output": "2" }, { "input": "1 100 50 200 75", "output": "50" }, { "input": "6 6 5 8 9", "output": "1" }, { "input": "1 1000000000 1 1000000000 1", "output": "999999999" }, { "input": "5 100 8 8 8", "output": "0" }, { "input": "1 1000000000000000000 2 99999999999999999 1000000000", "output": "99999999999999997" }, { "input": "1 1 1 1 1", "output": "0" }, { "input": "1 2 3 4 5", "output": "0" }, { "input": "1 1000000000 2 999999999 3141592", "output": "999999997" }, { "input": "24648817341102 41165114064236 88046848035 13602161452932 10000831349205", "output": "0" }, { "input": "1080184299348 34666828555290 6878390132365 39891656267344 15395310291636", "output": "27788438422925" }, { "input": "11814 27385 22309 28354 23595", "output": "5076" }, { "input": "4722316546398 36672578279675 796716437180 33840047334985 13411035401708", "output": "29117730788587" }, { "input": "14300093617438 14381698008501 6957847034861 32510754974307 66056597033082", "output": "81604391064" }, { "input": "700062402405871919 762322967106512617 297732773882447821 747309903322652819 805776739998108178", "output": "47247500916780901" }, { "input": "59861796371397621 194872039092923459 668110259718450585 841148673332698972 928360292123223779", "output": "0" }, { "input": "298248781360904821 346420922793050061 237084570581741798 726877079564549183 389611850470532358", "output": "48172141432145241" }, { "input": "420745791717606818 864206437350900994 764928840030524015 966634105370748487 793326512080703489", "output": "99277597320376979" }, { "input": "519325240668210886 776112702001665034 360568516809443669 875594219634943179 994594983925273138", "output": "256787461333454149" }, { "input": "170331212821058551 891149660635282032 125964175621755330 208256491683509799 526532153531983174", "output": "37925278862451249" }, { "input": "1 3 3 5 3", "output": "0" }, { "input": "1 5 8 10 9", "output": "0" }, { "input": "1 2 4 5 10", "output": "0" }, { "input": "1 2 2 3 5", "output": "1" }, { "input": "2 4 3 7 3", "output": "1" }, { "input": "1 2 9 10 1", "output": "0" }, { "input": "5 15 1 10 5", "output": "5" }, { "input": "1 4 9 20 25", "output": "0" }, { "input": "2 4 1 2 5", "output": "1" }, { "input": "10 1000 1 100 2", "output": "91" }, { "input": "1 3 3 8 10", "output": "1" }, { "input": "4 6 6 8 9", "output": "1" }, { "input": "2 3 1 4 3", "output": "1" }, { "input": "1 2 2 3 100", "output": "1" }, { "input": "1 2 100 120 2", "output": "0" }, { "input": "1 3 5 7 4", "output": "0" }, { "input": "1 3 5 7 5", "output": "0" }, { "input": "1 4 8 10 6", "output": "0" }, { "input": "1 2 5 6 100", "output": "0" }, { "input": "1 2 5 10 20", "output": "0" }, { "input": "1 2 5 6 7", "output": "0" }, { "input": "2 5 7 12 6", "output": "0" }, { "input": "10 20 50 100 80", "output": "0" }, { "input": "1 2 5 10 2", "output": "0" }, { "input": "1 2 5 6 4", "output": "0" }, { "input": "5 9 1 2 3", "output": "0" }, { "input": "50 100 1 20 3", "output": "0" }, { "input": "10 20 3 7 30", "output": "0" }, { "input": "1 5 10 10 100", "output": "0" }, { "input": "100 101 1 2 3", "output": "0" }, { "input": "1 5 10 20 6", "output": "0" }, { "input": "1 10 15 25 5", "output": "0" }, { "input": "1 2 5 10 3", "output": "0" }, { "input": "2 3 5 6 100", "output": "0" }, { "input": "1 2 4 5 6", "output": "0" }, { "input": "6 10 1 2 40", "output": "0" }, { "input": "20 30 1 5 1", "output": "0" }, { "input": "20 40 50 100 50", "output": "0" }, { "input": "1 1 4 9 2", "output": "0" }, { "input": "1 2 5 6 1", "output": "0" }, { "input": "1 100 400 500 450", "output": "0" }, { "input": "5 6 1 2 5", "output": "0" }, { "input": "1 10 21 30 50", "output": "0" }, { "input": "100 200 300 400 101", "output": "0" }, { "input": "2 8 12 16 9", "output": "0" }, { "input": "1 5 7 9 6", "output": "0" }, { "input": "300 400 100 200 101", "output": "0" }, { "input": "1 2 2 3 10", "output": "1" }, { "input": "1 10 100 200 5", "output": "0" }, { "input": "1 3 3 4 4", "output": "1" }, { "input": "10 20 30 40 25", "output": "0" }, { "input": "1 2 5 10 1", "output": "0" }, { "input": "2 4 8 10 1", "output": "0" }, { "input": "2 5 10 15 7", "output": "0" }, { "input": "100 200 5 10 1", "output": "0" }, { "input": "1 2 100 200 300", "output": "0" }, { "input": "30 100 10 20 25", "output": "0" }, { "input": "10 20 1 5 6", "output": "0" }, { "input": "4 5 1 2 4", "output": "0" }, { "input": "11 100 1 9 1000", "output": "0" }, { "input": "1 1 10 10 228", "output": "0" }, { "input": "5 7 10 20 15", "output": "0" }, { "input": "1 3 8 9 7", "output": "0" }, { "input": "1 10 2 8 8", "output": "6" }, { "input": "1 5 9 15 1", "output": "0" }, { "input": "1 3 5 6 12", "output": "0" }, { "input": "1 100 500 1000 3", "output": "0" }, { "input": "1 1 1 1 2", "output": "1" }, { "input": "1 1000 100 1000 200", "output": "900" }, { "input": "4 5 1 4 1", "output": "1" }, { "input": "1 5 5 7 3", "output": "1" }, { "input": "1 4 4 10 11", "output": "1" }, { "input": "1 1 3 4 100", "output": "0" }, { "input": "1 4 3 5 6", "output": "2" }, { "input": "10 100 20 30 40", "output": "11" }, { "input": "5 9 1 11 7", "output": "4" } ]
1,619,845,161
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
9
77
0
from math import pi def solve(l1,r1,l2,r2,k): l = max(l1,l2) r = min(r1,r2) v = r-l+1 if k >= l and k<= r: return v-1 return v def main(): arr = list(map(int, list(input().split(" ")))) # n = int(input()) print(solve(*arr)) main()
Title: Meeting of Old Friends Time Limit: None seconds Memory Limit: None megabytes Problem Description: 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 Specification: 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*<=≤<=1018, *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 Specification: Print one integer — the number of minutes Sonya and Filya will be able to spend together. Demo Input: ['1 10 9 20 1\n', '1 100 50 200 75\n'] Demo Output: ['2\n', '50\n'] 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.
```python from math import pi def solve(l1,r1,l2,r2,k): l = max(l1,l2) r = min(r1,r2) v = r-l+1 if k >= l and k<= r: return v-1 return v def main(): arr = list(map(int, list(input().split(" ")))) # n = int(input()) print(solve(*arr)) main() ```
0
227
B
Effective Approach
PROGRAMMING
1,100
[ "implementation" ]
null
null
Once at a team training Vasya, Petya and Sasha got a problem on implementing linear search in an array. According to the boys, linear search works as follows. The array elements in a pre-selected order are in turn compared with the number that you need to find. Once you find the array element that is equal to the required one, the search ends. The efficiency of the algorithm is the number of performed comparisons. The fewer comparisons the linear search has made, the more effective it is. Vasya believes that a linear search would work better if it sequentially iterates through the elements, starting with the 1-st one (in this problem we consider the elements of the array indexed from 1 to *n*) and ending with the *n*-th one. And Petya says that Vasya is wrong: the search will need less comparisons if it sequentially iterates the elements starting from the *n*-th and ending with the 1-st one. Sasha argues that the two approaches are equivalent. To finally begin the task, the teammates decided to settle the debate and compare the two approaches on an example. For this, they took an array that is a permutation of integers from 1 to *n*, and generated *m* queries of the form: find element with value *b**i* in the array. They want to calculate for both approaches how many comparisons in total the linear search will need to respond to all queries. If the first search needs fewer comparisons, then the winner of the dispute is Vasya. If the second one does, then the winner is Petya. If both approaches make the same number of comparisons, then Sasha's got the upper hand. But the problem is, linear search is too slow. That's why the boys aren't going to find out who is right before the end of the training, unless you come in here. Help them to determine who will win the dispute.
The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of elements in the array. The second line contains *n* distinct space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*n*) — the elements of array. The third line contains integer *m* (1<=≤<=*m*<=≤<=105) — the number of queries. The last line contains *m* space-separated integers *b*1,<=*b*2,<=...,<=*b**m* (1<=≤<=*b**i*<=≤<=*n*) — the search queries. Note that the queries can repeat.
Print two integers, showing how many comparisons Vasya's approach needs and how many comparisons Petya's approach needs. Separate the numbers by spaces. Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier.
[ "2\n1 2\n1\n1\n", "2\n2 1\n1\n1\n", "3\n3 1 2\n3\n1 2 3\n" ]
[ "1 2\n", "2 1\n", "6 6\n" ]
In the first sample Vasya's approach will make one comparison (it starts with the 1-st element and immediately finds the required number), and Petya's approach makes two comparisons (first he compares with the 2-nd array element, doesn't find the search item and compares with the 1-st element). In the second sample, on the contrary, Vasya's approach will need two comparisons (first with 1-st element, and then with the 2-nd), and Petya's approach will find the required value in one comparison (the first comparison with the 2-nd element).
1,000
[ { "input": "2\n1 2\n1\n1", "output": "1 2" }, { "input": "2\n2 1\n1\n1", "output": "2 1" }, { "input": "3\n3 1 2\n3\n1 2 3", "output": "6 6" }, { "input": "9\n2 9 3 1 6 4 7 8 5\n9\n5 1 5 2 8 4 4 4 5", "output": "58 32" }, { "input": "10\n3 10 9 2 7 6 5 8 4 1\n1\n4", "output": "9 2" }, { "input": "10\n5 2 10 8 3 1 9 7 6 4\n9\n2 5 9 2 3 2 5 9 8", "output": "31 68" }, { "input": "9\n3 8 4 7 1 2 5 6 9\n3\n2 7 1", "output": "15 15" }, { "input": "9\n5 3 8 4 2 6 1 7 9\n4\n6 1 9 2", "output": "27 13" }, { "input": "4\n1 3 2 4\n4\n3 1 2 3", "output": "8 12" }, { "input": "3\n1 2 3\n8\n3 2 1 1 2 3 1 2", "output": "15 17" } ]
1,644,154,975
2,147,483,647
Python 3
OK
TESTS
34
342
13,721,600
n = int(input()) hash_map = {} for i,_ in enumerate(map(int, input().split())): hash_map[_] = i + 1 q = int(input()) query = list(map(int, input().split())) v,p = 0,0 for q in query: v += hash_map[q] p += (n - hash_map[q] + 1) print(v,p)
Title: Effective Approach Time Limit: None seconds Memory Limit: None megabytes Problem Description: Once at a team training Vasya, Petya and Sasha got a problem on implementing linear search in an array. According to the boys, linear search works as follows. The array elements in a pre-selected order are in turn compared with the number that you need to find. Once you find the array element that is equal to the required one, the search ends. The efficiency of the algorithm is the number of performed comparisons. The fewer comparisons the linear search has made, the more effective it is. Vasya believes that a linear search would work better if it sequentially iterates through the elements, starting with the 1-st one (in this problem we consider the elements of the array indexed from 1 to *n*) and ending with the *n*-th one. And Petya says that Vasya is wrong: the search will need less comparisons if it sequentially iterates the elements starting from the *n*-th and ending with the 1-st one. Sasha argues that the two approaches are equivalent. To finally begin the task, the teammates decided to settle the debate and compare the two approaches on an example. For this, they took an array that is a permutation of integers from 1 to *n*, and generated *m* queries of the form: find element with value *b**i* in the array. They want to calculate for both approaches how many comparisons in total the linear search will need to respond to all queries. If the first search needs fewer comparisons, then the winner of the dispute is Vasya. If the second one does, then the winner is Petya. If both approaches make the same number of comparisons, then Sasha's got the upper hand. But the problem is, linear search is too slow. That's why the boys aren't going to find out who is right before the end of the training, unless you come in here. Help them to determine who will win the dispute. Input Specification: The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of elements in the array. The second line contains *n* distinct space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*n*) — the elements of array. The third line contains integer *m* (1<=≤<=*m*<=≤<=105) — the number of queries. The last line contains *m* space-separated integers *b*1,<=*b*2,<=...,<=*b**m* (1<=≤<=*b**i*<=≤<=*n*) — the search queries. Note that the queries can repeat. Output Specification: Print two integers, showing how many comparisons Vasya's approach needs and how many comparisons Petya's approach needs. Separate the numbers by spaces. Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier. Demo Input: ['2\n1 2\n1\n1\n', '2\n2 1\n1\n1\n', '3\n3 1 2\n3\n1 2 3\n'] Demo Output: ['1 2\n', '2 1\n', '6 6\n'] Note: In the first sample Vasya's approach will make one comparison (it starts with the 1-st element and immediately finds the required number), and Petya's approach makes two comparisons (first he compares with the 2-nd array element, doesn't find the search item and compares with the 1-st element). In the second sample, on the contrary, Vasya's approach will need two comparisons (first with 1-st element, and then with the 2-nd), and Petya's approach will find the required value in one comparison (the first comparison with the 2-nd element).
```python n = int(input()) hash_map = {} for i,_ in enumerate(map(int, input().split())): hash_map[_] = i + 1 q = int(input()) query = list(map(int, input().split())) v,p = 0,0 for q in query: v += hash_map[q] p += (n - hash_map[q] + 1) print(v,p) ```
3
626
B
Cards
PROGRAMMING
1,300
[ "constructive algorithms", "dp", "math" ]
null
null
Catherine has a deck of *n* cards, each of which is either red, green, or blue. As long as there are at least two cards left, she can do one of two actions: - take any two (not necessarily adjacent) cards with different colors and exchange them for a new card of the third color; - take any two (not necessarily adjacent) cards with the same color and exchange them for a new card with that color. She repeats this process until there is only one card left. What are the possible colors for the final card?
The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=200) — the total number of cards. The next line contains a string *s* of length *n* — the colors of the cards. *s* contains only the characters 'B', 'G', and 'R', representing blue, green, and red, respectively.
Print a single string of up to three characters — the possible colors of the final card (using the same symbols as the input) in alphabetical order.
[ "2\nRB\n", "3\nGRG\n", "5\nBBBBB\n" ]
[ "G\n", "BR\n", "B\n" ]
In the first sample, Catherine has one red card and one blue card, which she must exchange for a green card. In the second sample, Catherine has two green cards and one red card. She has two options: she can exchange the two green cards for a green card, then exchange the new green card and the red card for a blue card. Alternatively, she can exchange a green and a red card for a blue card, then exchange the blue card and remaining green card for a red card. In the third sample, Catherine only has blue cards, so she can only exchange them for more blue cards.
750
[ { "input": "2\nRB", "output": "G" }, { "input": "3\nGRG", "output": "BR" }, { "input": "5\nBBBBB", "output": "B" }, { "input": "1\nR", "output": "R" }, { "input": "200\nBBRGRRBBRGGGBGBGBGRRGRGRGRBGRGRRBBGRGBGRRGRRRGGBBRGBGBGBRBBBBBBBGGBRGGRRRGGRGBGBGGBRRRRBRRRBRBBGGBGBRGRGBBBBGGBGBBBGBGRRBRRRGBGGBBBRBGRBRRGGGRRGBBBGBGRRRRRRGGRGRGBBBRGGGBGGGBRBBRRGBGRGRBRRRBRBGRGGBRBB", "output": "BGR" }, { "input": "101\nRRRRRRRRRRRRRRRRRRRBRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR", "output": "BG" }, { "input": "7\nBBBGBRG", "output": "BGR" }, { "input": "5\nGRRGR", "output": "BGR" }, { "input": "3\nGBR", "output": "BGR" }, { "input": "1\nB", "output": "B" }, { "input": "2\nBB", "output": "B" }, { "input": "1\nG", "output": "G" }, { "input": "2\nBG", "output": "R" }, { "input": "3\nBGB", "output": "GR" }, { "input": "2\nGG", "output": "G" }, { "input": "3\nGBG", "output": "BR" }, { "input": "4\nBGBG", "output": "BGR" }, { "input": "1\nR", "output": "R" }, { "input": "2\nBR", "output": "G" }, { "input": "3\nBRB", "output": "GR" }, { "input": "2\nRG", "output": "B" }, { "input": "3\nBGR", "output": "BGR" }, { "input": "4\nRBGB", "output": "BGR" }, { "input": "3\nGGR", "output": "BR" }, { "input": "4\nGGRB", "output": "BGR" }, { "input": "5\nBGBGR", "output": "BGR" }, { "input": "2\nRR", "output": "R" }, { "input": "3\nRBR", "output": "BG" }, { "input": "4\nRRBB", "output": "BGR" }, { "input": "3\nRRG", "output": "BG" }, { "input": "4\nBRRG", "output": "BGR" }, { "input": "5\nRBRBG", "output": "BGR" }, { "input": "4\nRGGR", "output": "BGR" }, { "input": "5\nBRGRG", "output": "BGR" }, { "input": "6\nGRRGBB", "output": "BGR" }, { "input": "150\nGRGBBBBRBGGBGBBGBBBBGRBBRRBBGRRGGGBRBBRGRRRRGBGRRBGBGBGRBBBGBBBGBGBRGBRRRRRGGGRGRBBGBRGGGRBBRGBBGRGGGBBRBRRGRGRRGRRGRRRGBGBRRGGRGGBRBGGGBBBRGRGBRGRRRR", "output": "BGR" }, { "input": "16\nRRGRRRRRRGGRGRRR", "output": "BGR" }, { "input": "190\nBBBBBBBBBBBBBBBBBGBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB", "output": "GR" }, { "input": "200\nRGRGRRRRRGRRGRRRGRGRRRGGRGRRGGGRRGGRRRRRRRRRRRGRRGRRRGRRRGRRRRRRRGRRRRRRRRRRRGGRRGGRRRRGGRRRRRRRRRGGGRGRGRGRRGRGGRGRGRRRGRRRRRRGGRGRRRRGRRGRGGRRRRRRRGRGGRRGRRRRRRRGGRRRRGRRRRRRRGRRRGGRRRRRRGRRGGGRRRGR", "output": "BGR" }, { "input": "200\nGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG", "output": "G" }, { "input": "52\nBBBBBBBBBBBBBBBBBBBBGBGBBBBBBBBBBBBBBBBBBBBBBBBBBBBB", "output": "BGR" }, { "input": "200\nGRGRRGRBRRRGGGRGGRRRRRBBGRRGRBBGRRGBGRRBBRBBRRBBBGRBRGGGGBGGBRRBBRGRBGGRRGGBBRBGGRGBBRRBBRGBRRBGBRBGBBRGGRRRGGGBRGGGGRRRBBRRGRGRBRRGRBBGGRBBRGRGRBGRBBRGGBBBGRGBBGGBGBGBBRRBGRGRGGBRRGRGGGGGBRGGGGBBBBRB", "output": "BGR" }, { "input": "102\nGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGRGGGGGGGGBGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG", "output": "BGR" }, { "input": "193\nRRRGGGRBGGBGGGBGGBBGRBGGRBGGBBRBGGRBBBRBRRGGBBRBRGRRRBGBBRGGRGGGBGGRRGGRGRRBRBRBRRGRGBGBRGBBRGRRRBGRGGBGBRBBBGBRBBGBGBGGGBGGGGBRBBRRBGRGGBBBRBBBBBGRRRGBRGBRRRBBBGBGGGGRGGRRBRBGRRGBGBRBGGGRBRRGG", "output": "BGR" }, { "input": "90\nBGBGGRRBGGRRRRRGGRGBBBBBRRBGBGBGBGGBBGRGGGGRBRBBRRRGBRRGBBGBBGGGRGRGRBGBBBRRGRRBRBRRGGRBRB", "output": "BGR" }, { "input": "3\nGGB", "output": "BR" } ]
1,689,724,856
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
3
62
716,800
from functools import cache ans = "" @cache def backtrack(r, g, b): global ans if r+g+b == 2: if r == 2: ans += "R" if g == 2: ans += "G" if b == 2: ans += "B" if r == 1 and g == 1: ans += "B" if g == 1 and b == 1: ans += "R" if r == 1 and b == 1: ans += "G" return 1 if r > 1: backtrack(r-1, g, b) if g > 1: backtrack(r, g-1, b) if b > 1: backtrack(r, g, b-1) if r>0 and g>0: backtrack(r-1, g-1, b+1) if g>0 and b>0: backtrack(r+1, g-1, b-1) if r>0 and b>0: backtrack(r-1, g+1, b-1) n = int(input()) rgb = input() backtrack(rgb.count("R"), rgb.count("G"), rgb.count("B")) print("".join(sorted(map(str, set(ans)))))
Title: Cards Time Limit: None seconds Memory Limit: None megabytes Problem Description: Catherine has a deck of *n* cards, each of which is either red, green, or blue. As long as there are at least two cards left, she can do one of two actions: - take any two (not necessarily adjacent) cards with different colors and exchange them for a new card of the third color; - take any two (not necessarily adjacent) cards with the same color and exchange them for a new card with that color. She repeats this process until there is only one card left. What are the possible colors for the final card? Input Specification: The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=200) — the total number of cards. The next line contains a string *s* of length *n* — the colors of the cards. *s* contains only the characters 'B', 'G', and 'R', representing blue, green, and red, respectively. Output Specification: Print a single string of up to three characters — the possible colors of the final card (using the same symbols as the input) in alphabetical order. Demo Input: ['2\nRB\n', '3\nGRG\n', '5\nBBBBB\n'] Demo Output: ['G\n', 'BR\n', 'B\n'] Note: In the first sample, Catherine has one red card and one blue card, which she must exchange for a green card. In the second sample, Catherine has two green cards and one red card. She has two options: she can exchange the two green cards for a green card, then exchange the new green card and the red card for a blue card. Alternatively, she can exchange a green and a red card for a blue card, then exchange the blue card and remaining green card for a red card. In the third sample, Catherine only has blue cards, so she can only exchange them for more blue cards.
```python from functools import cache ans = "" @cache def backtrack(r, g, b): global ans if r+g+b == 2: if r == 2: ans += "R" if g == 2: ans += "G" if b == 2: ans += "B" if r == 1 and g == 1: ans += "B" if g == 1 and b == 1: ans += "R" if r == 1 and b == 1: ans += "G" return 1 if r > 1: backtrack(r-1, g, b) if g > 1: backtrack(r, g-1, b) if b > 1: backtrack(r, g, b-1) if r>0 and g>0: backtrack(r-1, g-1, b+1) if g>0 and b>0: backtrack(r+1, g-1, b-1) if r>0 and b>0: backtrack(r-1, g+1, b-1) n = int(input()) rgb = input() backtrack(rgb.count("R"), rgb.count("G"), rgb.count("B")) print("".join(sorted(map(str, set(ans))))) ```
0
259
B
Little Elephant and Magic Square
PROGRAMMING
1,100
[ "brute force", "implementation" ]
null
null
Little Elephant loves magic squares very much. A magic square is a 3<=×<=3 table, each cell contains some positive integer. At that the sums of integers in all rows, columns and diagonals of the table are equal. The figure below shows the magic square, the sum of integers in all its rows, columns and diagonals equals 15. The Little Elephant remembered one magic square. He started writing this square on a piece of paper, but as he wrote, he forgot all three elements of the main diagonal of the magic square. Fortunately, the Little Elephant clearly remembered that all elements of the magic square did not exceed 105. Help the Little Elephant, restore the original magic square, given the Elephant's notes.
The first three lines of the input contain the Little Elephant's notes. The first line contains elements of the first row of the magic square. The second line contains the elements of the second row, the third line is for the third row. The main diagonal elements that have been forgotten by the Elephant are represented by zeroes. It is guaranteed that the notes contain exactly three zeroes and they are all located on the main diagonal. It is guaranteed that all positive numbers in the table do not exceed 105.
Print three lines, in each line print three integers — the Little Elephant's magic square. If there are multiple magic squares, you are allowed to print any of them. Note that all numbers you print must be positive and not exceed 105. It is guaranteed that there exists at least one magic square that meets the conditions.
[ "0 1 1\n1 0 1\n1 1 0\n", "0 3 6\n5 0 5\n4 7 0\n" ]
[ "1 1 1\n1 1 1\n1 1 1\n", "6 3 6\n5 5 5\n4 7 4\n" ]
none
1,000
[ { "input": "0 1 1\n1 0 1\n1 1 0", "output": "1 1 1\n1 1 1\n1 1 1" }, { "input": "0 3 6\n5 0 5\n4 7 0", "output": "6 3 6\n5 5 5\n4 7 4" }, { "input": "0 4 4\n4 0 4\n4 4 0", "output": "4 4 4\n4 4 4\n4 4 4" }, { "input": "0 54 48\n36 0 78\n66 60 0", "output": "69 54 48\n36 57 78\n66 60 45" }, { "input": "0 17 14\n15 0 15\n16 13 0", "output": "14 17 14\n15 15 15\n16 13 16" }, { "input": "0 97 56\n69 0 71\n84 43 0", "output": "57 97 56\n69 70 71\n84 43 83" }, { "input": "0 1099 1002\n1027 0 1049\n1074 977 0", "output": "1013 1099 1002\n1027 1038 1049\n1074 977 1063" }, { "input": "0 98721 99776\n99575 0 99123\n98922 99977 0", "output": "99550 98721 99776\n99575 99349 99123\n98922 99977 99148" }, { "input": "0 6361 2304\n1433 0 8103\n7232 3175 0", "output": "5639 6361 2304\n1433 4768 8103\n7232 3175 3897" }, { "input": "0 99626 99582\n99766 0 99258\n99442 99398 0", "output": "99328 99626 99582\n99766 99512 99258\n99442 99398 99696" }, { "input": "0 99978 99920\n99950 0 99918\n99948 99890 0", "output": "99904 99978 99920\n99950 99934 99918\n99948 99890 99964" }, { "input": "0 840 666\n612 0 948\n894 720 0", "output": "834 840 666\n612 780 948\n894 720 726" }, { "input": "0 28 10\n12 0 24\n26 8 0", "output": "16 28 10\n12 18 24\n26 8 20" }, { "input": "0 120 83\n98 0 90\n105 68 0", "output": "79 120 83\n98 94 90\n105 68 109" }, { "input": "0 86900 85807\n85836 0 86842\n86871 85778 0", "output": "86310 86900 85807\n85836 86339 86842\n86871 85778 86368" }, { "input": "0 74 78\n78 0 74\n74 78 0", "output": "76 74 78\n78 76 74\n74 78 76" }, { "input": "0 505 681\n605 0 657\n581 757 0", "output": "707 505 681\n605 631 657\n581 757 555" }, { "input": "0 662 918\n822 0 854\n758 1014 0", "output": "934 662 918\n822 838 854\n758 1014 742" }, { "input": "0 93 95\n93 0 97\n95 97 0", "output": "97 93 95\n93 95 97\n95 97 93" }, { "input": "0 709 712\n719 0 695\n702 705 0", "output": "700 709 712\n719 707 695\n702 705 714" }, { "input": "0 7 6\n9 0 1\n4 3 0", "output": "2 7 6\n9 5 1\n4 3 8" }, { "input": "0 9 2\n3 0 7\n8 1 0", "output": "4 9 2\n3 5 7\n8 1 6" }, { "input": "0 1 43\n13 0 61\n31 73 0", "output": "67 1 43\n13 37 61\n31 73 7" }, { "input": "0 100000 100000\n100000 0 100000\n100000 100000 0", "output": "100000 100000 100000\n100000 100000 100000\n100000 100000 100000" } ]
1,629,723,827
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
1
154
20,172,800
def main_function(): a, b, c = [int(i) for i in input().split(" ")] d, e, f = [int(i) for i in input().split(" ")] g, h, i = [int(i) for i in input().split(" ")] v = b + c l = d + f w = g + h x = max(v, l, w) + 1 a = x - v e = x - l i = x - w print(" ".join([str(a), str(b), str(c)])) print(" ".join([str(d), str(e), str(f)])) print(" ".join([str(g), str(h), str(i)])) main_function()
Title: Little Elephant and Magic Square Time Limit: None seconds Memory Limit: None megabytes Problem Description: Little Elephant loves magic squares very much. A magic square is a 3<=×<=3 table, each cell contains some positive integer. At that the sums of integers in all rows, columns and diagonals of the table are equal. The figure below shows the magic square, the sum of integers in all its rows, columns and diagonals equals 15. The Little Elephant remembered one magic square. He started writing this square on a piece of paper, but as he wrote, he forgot all three elements of the main diagonal of the magic square. Fortunately, the Little Elephant clearly remembered that all elements of the magic square did not exceed 105. Help the Little Elephant, restore the original magic square, given the Elephant's notes. Input Specification: The first three lines of the input contain the Little Elephant's notes. The first line contains elements of the first row of the magic square. The second line contains the elements of the second row, the third line is for the third row. The main diagonal elements that have been forgotten by the Elephant are represented by zeroes. It is guaranteed that the notes contain exactly three zeroes and they are all located on the main diagonal. It is guaranteed that all positive numbers in the table do not exceed 105. Output Specification: Print three lines, in each line print three integers — the Little Elephant's magic square. If there are multiple magic squares, you are allowed to print any of them. Note that all numbers you print must be positive and not exceed 105. It is guaranteed that there exists at least one magic square that meets the conditions. Demo Input: ['0 1 1\n1 0 1\n1 1 0\n', '0 3 6\n5 0 5\n4 7 0\n'] Demo Output: ['1 1 1\n1 1 1\n1 1 1\n', '6 3 6\n5 5 5\n4 7 4\n'] Note: none
```python def main_function(): a, b, c = [int(i) for i in input().split(" ")] d, e, f = [int(i) for i in input().split(" ")] g, h, i = [int(i) for i in input().split(" ")] v = b + c l = d + f w = g + h x = max(v, l, w) + 1 a = x - v e = x - l i = x - w print(" ".join([str(a), str(b), str(c)])) print(" ".join([str(d), str(e), str(f)])) print(" ".join([str(g), str(h), str(i)])) main_function() ```
0
0
none
none
none
0
[ "none" ]
null
null
A *k*-multiple free set is a set of integers where there is no pair of integers where one is equal to another integer multiplied by *k*. That is, there are no two integers *x* and *y* (*x*<=&lt;<=*y*) from the set, such that *y*<==<=*x*·*k*. You're given a set of *n* distinct positive integers. Your task is to find the size of it's largest *k*-multiple free subset.
The first line of the input contains two integers *n* and *k* (1<=≤<=*n*<=≤<=105,<=1<=≤<=*k*<=≤<=109). The next line contains a list of *n* distinct positive integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109). All the numbers in the lines are separated by single spaces.
On the only line of the output print the size of the largest *k*-multiple free subset of {*a*1,<=*a*2,<=...,<=*a**n*}.
[ "6 2\n2 3 6 5 4 10\n" ]
[ "3\n" ]
In the sample input one of the possible maximum 2-multiple free subsets is {4, 5, 6}.
0
[ { "input": "6 2\n2 3 6 5 4 10", "output": "3" }, { "input": "10 2\n1 2 3 4 5 6 7 8 9 10", "output": "6" }, { "input": "1 1\n1", "output": "1" }, { "input": "100 2\n191 17 61 40 77 95 128 88 26 69 79 10 131 106 142 152 68 39 182 53 83 81 6 89 65 148 33 22 5 47 107 121 52 163 150 158 189 118 75 180 177 176 112 167 140 184 29 166 25 46 169 145 187 123 196 18 115 126 155 100 63 58 159 19 173 113 133 60 130 161 76 157 93 199 50 97 15 67 109 164 99 149 3 137 153 136 56 43 103 170 13 183 194 72 9 181 86 30 91 36", "output": "79" }, { "input": "100 3\n13 38 137 24 46 192 33 8 170 141 118 57 198 133 112 176 40 36 91 130 166 72 123 28 82 180 134 52 64 107 97 79 199 184 158 22 181 163 98 7 88 41 73 87 167 109 15 173 153 70 50 119 139 56 17 152 84 161 11 116 31 187 143 196 27 102 132 126 149 63 146 168 67 48 53 120 20 105 155 10 128 47 23 6 94 3 113 65 44 179 189 99 75 34 111 193 60 145 171 77", "output": "87" }, { "input": "12 400000000\n1 400000000 800000000 2 3 4 5 6 7 8 9 10", "output": "10" }, { "input": "3 1\n1 2 3", "output": "3" }, { "input": "1 1\n1000000000", "output": "1" }, { "input": "10 1\n1 100 300 400 500 500000 1000000 10000000 100000000 1000000000", "output": "10" }, { "input": "2 1\n2 1", "output": "2" }, { "input": "2 1000000000\n1 1000000000", "output": "1" }, { "input": "4 1000\n1 1000 1000000 1000000000", "output": "2" }, { "input": "2 2\n1 3", "output": "2" }, { "input": "2 2\n16 8", "output": "1" }, { "input": "3 2\n8 4 2", "output": "2" }, { "input": "5 1\n1 2 3 4 5", "output": "5" }, { "input": "2 2\n500000000 1000000000", "output": "1" }, { "input": "2 2\n4 2", "output": "1" }, { "input": "10 100000000\n1 2 3 4 5 6 7 8 82000 907431936", "output": "10" }, { "input": "8 65538\n65535 65536 65537 65538 65539 131072 262144 196608", "output": "8" }, { "input": "5 2\n10 8 6 4 2", "output": "4" }, { "input": "2 1000000000\n276447232 100000", "output": "2" } ]
1,602,833,174
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
1
218
307,200
import copy n, k = map (int, input ().split ()) lst = list (map (int, input ().split ())) lst.sort () lst = set (lst) temp = copy.copy (lst) for i in temp : lst.discard (i * k) print (len (lst))
Title: none Time Limit: None seconds Memory Limit: None megabytes Problem Description: A *k*-multiple free set is a set of integers where there is no pair of integers where one is equal to another integer multiplied by *k*. That is, there are no two integers *x* and *y* (*x*<=&lt;<=*y*) from the set, such that *y*<==<=*x*·*k*. You're given a set of *n* distinct positive integers. Your task is to find the size of it's largest *k*-multiple free subset. Input Specification: The first line of the input contains two integers *n* and *k* (1<=≤<=*n*<=≤<=105,<=1<=≤<=*k*<=≤<=109). The next line contains a list of *n* distinct positive integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109). All the numbers in the lines are separated by single spaces. Output Specification: On the only line of the output print the size of the largest *k*-multiple free subset of {*a*1,<=*a*2,<=...,<=*a**n*}. Demo Input: ['6 2\n2 3 6 5 4 10\n'] Demo Output: ['3\n'] Note: In the sample input one of the possible maximum 2-multiple free subsets is {4, 5, 6}.
```python import copy n, k = map (int, input ().split ()) lst = list (map (int, input ().split ())) lst.sort () lst = set (lst) temp = copy.copy (lst) for i in temp : lst.discard (i * k) print (len (lst)) ```
0
839
C
Journey
PROGRAMMING
1,500
[ "dfs and similar", "dp", "graphs", "probabilities", "trees" ]
null
null
There are *n* cities and *n*<=-<=1 roads in the Seven Kingdoms, each road connects two cities and we can reach any city from any other by the roads. Theon and Yara Greyjoy are on a horse in the first city, they are starting traveling through the roads. But the weather is foggy, so they can’t see where the horse brings them. When the horse reaches a city (including the first one), it goes to one of the cities connected to the current city. But it is a strange horse, it only goes to cities in which they weren't before. In each such city, the horse goes with equal probabilities and it stops when there are no such cities. Let the length of each road be 1. The journey starts in the city 1. What is the expected length (expected value of length) of their journey? You can read about expected (average) value by the link [https://en.wikipedia.org/wiki/Expected_value](https://en.wikipedia.org/wiki/Expected_value).
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100000) — number of cities. Then *n*<=-<=1 lines follow. The *i*-th line of these lines contains two integers *u**i* and *v**i* (1<=≤<=*u**i*,<=*v**i*<=≤<=*n*, *u**i*<=≠<=*v**i*) — the cities connected by the *i*-th road. It is guaranteed that one can reach any city from any other by the roads.
Print a number — the expected length of their journey. The journey starts in the city 1. Your answer will be considered correct if its absolute or relative error does not exceed 10<=-<=6. Namely: let's assume that your answer is *a*, and the answer of the jury is *b*. The checker program will consider your answer correct, if .
[ "4\n1 2\n1 3\n2 4\n", "5\n1 2\n1 3\n3 4\n2 5\n" ]
[ "1.500000000000000\n", "2.000000000000000\n" ]
In the first sample, their journey may end in cities 3 or 4 with equal probability. The distance to city 3 is 1 and to city 4 is 2, so the expected length is 1.5. In the second sample, their journey may end in city 4 or 5. The distance to the both cities is 2, so the expected length is 2.
1,500
[ { "input": "4\n1 2\n1 3\n2 4", "output": "1.500000000000000" }, { "input": "5\n1 2\n1 3\n3 4\n2 5", "output": "2.000000000000000" }, { "input": "70\n1 25\n57 1\n18 1\n65 1\n38 1\n1 41\n1 5\n1 69\n1 3\n31 1\n1 8\n1 9\n53 1\n70 1\n45 1\n1 24\n1 42\n1 30\n1 12\n1 37\n64 1\n1 28\n1 58\n1 22\n11 1\n1 4\n1 27\n1 16\n1 21\n54 1\n1 51\n1 43\n29 1\n56 1\n1 39\n32 1\n1 15\n1 17\n1 19\n1 40\n36 1\n48 1\n63 1\n1 7\n1 47\n1 13\n1 46\n60 1\n1 6\n23 1\n20 1\n1 52\n2 1\n26 1\n1 59\n1 66\n10 1\n1 62\n1 68\n1 55\n50 1\n33 1\n44 1\n1 34\n1 35\n1 61\n14 1\n67 1\n49 1", "output": "1.000000000000000" }, { "input": "10\n8 6\n9 10\n8 7\n1 4\n1 8\n9 5\n9 8\n2 5\n3 1", "output": "1.500000000000000" }, { "input": "1", "output": "0.000000000000000" } ]
1,629,383,363
2,147,483,647
PyPy 3
OK
TESTS
40
608
56,729,600
# Rishabh Rao (https://github.com/rishabhrao) import sys MOD = 1000000007 def inp(): return sys.stdin.readline().strip() def ii(): return int(inp()) def iis(): return [int(i) for i in inp().split()] ## PYRIVAL BOOTSTRAP # https://github.com/cheran-senthil/PyRival/blob/master/pyrival/misc/bootstrap.py # This decorator allows for recursion without actually doing recursion from types import GeneratorType def bootstrap(f, stack=[]): def wrappedfunc(*args, **kwargs): if stack: return f(*args, **kwargs) else: to = f(*args, **kwargs) while True: if type(to) is GeneratorType: stack.append(to) to = next(to) else: stack.pop() if not stack: break to = stack[-1].send(to) return to return wrappedfunc ###################### n = ii() graph = [[] for _ in range(n + 1)] for _ in range(n - 1): u, v = iis() graph[u].append(v) graph[v].append(u) seen = [0 for _ in range(n + 1)] @bootstrap def dfs(node): seen[node] = 1 s = 0 n = 0 ans = 0 for child in graph[node]: if not seen[child]: n += 1 s += yield dfs(child) if n != 0: ans = s / n yield 1 + ans print(dfs(1) - 1)
Title: Journey Time Limit: None seconds Memory Limit: None megabytes Problem Description: There are *n* cities and *n*<=-<=1 roads in the Seven Kingdoms, each road connects two cities and we can reach any city from any other by the roads. Theon and Yara Greyjoy are on a horse in the first city, they are starting traveling through the roads. But the weather is foggy, so they can’t see where the horse brings them. When the horse reaches a city (including the first one), it goes to one of the cities connected to the current city. But it is a strange horse, it only goes to cities in which they weren't before. In each such city, the horse goes with equal probabilities and it stops when there are no such cities. Let the length of each road be 1. The journey starts in the city 1. What is the expected length (expected value of length) of their journey? You can read about expected (average) value by the link [https://en.wikipedia.org/wiki/Expected_value](https://en.wikipedia.org/wiki/Expected_value). Input Specification: The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100000) — number of cities. Then *n*<=-<=1 lines follow. The *i*-th line of these lines contains two integers *u**i* and *v**i* (1<=≤<=*u**i*,<=*v**i*<=≤<=*n*, *u**i*<=≠<=*v**i*) — the cities connected by the *i*-th road. It is guaranteed that one can reach any city from any other by the roads. Output Specification: Print a number — the expected length of their journey. The journey starts in the city 1. Your answer will be considered correct if its absolute or relative error does not exceed 10<=-<=6. Namely: let's assume that your answer is *a*, and the answer of the jury is *b*. The checker program will consider your answer correct, if . Demo Input: ['4\n1 2\n1 3\n2 4\n', '5\n1 2\n1 3\n3 4\n2 5\n'] Demo Output: ['1.500000000000000\n', '2.000000000000000\n'] Note: In the first sample, their journey may end in cities 3 or 4 with equal probability. The distance to city 3 is 1 and to city 4 is 2, so the expected length is 1.5. In the second sample, their journey may end in city 4 or 5. The distance to the both cities is 2, so the expected length is 2.
```python # Rishabh Rao (https://github.com/rishabhrao) import sys MOD = 1000000007 def inp(): return sys.stdin.readline().strip() def ii(): return int(inp()) def iis(): return [int(i) for i in inp().split()] ## PYRIVAL BOOTSTRAP # https://github.com/cheran-senthil/PyRival/blob/master/pyrival/misc/bootstrap.py # This decorator allows for recursion without actually doing recursion from types import GeneratorType def bootstrap(f, stack=[]): def wrappedfunc(*args, **kwargs): if stack: return f(*args, **kwargs) else: to = f(*args, **kwargs) while True: if type(to) is GeneratorType: stack.append(to) to = next(to) else: stack.pop() if not stack: break to = stack[-1].send(to) return to return wrappedfunc ###################### n = ii() graph = [[] for _ in range(n + 1)] for _ in range(n - 1): u, v = iis() graph[u].append(v) graph[v].append(u) seen = [0 for _ in range(n + 1)] @bootstrap def dfs(node): seen[node] = 1 s = 0 n = 0 ans = 0 for child in graph[node]: if not seen[child]: n += 1 s += yield dfs(child) if n != 0: ans = s / n yield 1 + ans print(dfs(1) - 1) ```
3
844
B
Rectangles
PROGRAMMING
1,300
[ "combinatorics", "math" ]
null
null
You are given *n*<=×<=*m* table. Each cell of the table is colored white or black. Find the number of non-empty sets of cells such that: 1. All cells in a set have the same color. 1. Every two cells in a set share row or column.
The first line of input contains integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=50) — the number of rows and the number of columns correspondingly. The next *n* lines of input contain descriptions of rows. There are *m* integers, separated by spaces, in each line. The number equals 0 if the corresponding cell is colored white and equals 1 if the corresponding cell is colored black.
Output single integer  — the number of non-empty sets from the problem description.
[ "1 1\n0\n", "2 3\n1 0 1\n0 1 0\n" ]
[ "1\n", "8\n" ]
In the second example, there are six one-element sets. Additionally, there are two two-element sets, the first one consists of the first and the third cells of the first row, the second one consists of the first and the third cells of the second row. To sum up, there are 8 sets.
1,000
[ { "input": "1 1\n0", "output": "1" }, { "input": "2 3\n1 0 1\n0 1 0", "output": "8" }, { "input": "2 2\n1 1\n1 1", "output": "8" }, { "input": "1 10\n0 0 0 0 0 0 0 0 0 0", "output": "1023" }, { "input": "11 1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1", "output": "2047" }, { "input": "10 11\n1 1 0 1 1 0 0 0 1 0 0\n1 0 0 1 1 1 0 0 1 1 0\n0 0 1 0 1 1 0 1 0 1 1\n0 1 1 1 0 1 0 1 0 0 0\n1 1 1 1 1 1 1 0 1 0 0\n1 1 0 1 1 1 1 0 0 1 1\n1 0 1 0 1 0 0 1 1 1 0\n1 1 0 0 0 0 0 1 0 1 1\n1 1 0 1 1 1 0 0 1 1 0\n1 0 1 1 0 0 1 0 0 1 1", "output": "2444" }, { "input": "50 1\n0\n1\n0\n1\n0\n1\n0\n1\n1\n1\n0\n0\n1\n0\n0\n1\n1\n1\n1\n0\n1\n1\n0\n1\n1\n1\n0\n1\n0\n0\n0\n1\n1\n0\n1\n1\n0\n1\n0\n1\n0\n0\n1\n0\n0\n0\n1\n1\n0\n1", "output": "142606334" }, { "input": "1 50\n0 1 0 1 0 1 0 1 1 1 0 0 1 0 0 1 1 1 1 0 1 1 0 1 1 1 0 1 0 0 0 1 1 0 1 1 0 1 0 1 0 0 1 0 0 0 1 1 0 1", "output": "142606334" }, { "input": "2 20\n0 1 0 0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 1 0\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0", "output": "589853" }, { "input": "5 5\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0", "output": "285" }, { "input": "6 6\n1 1 1 1 1 1\n1 1 1 1 1 1\n1 1 1 1 1 1\n1 1 1 1 1 1\n1 1 1 1 1 1\n1 1 1 1 1 1", "output": "720" }, { "input": "21 2\n0 1\n1 1\n0 1\n0 0\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1", "output": "1310745" }, { "input": "3 15\n1 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 1 0 1 0 0 0 0 0 1 0\n1 0 0 1 0 0 0 0 0 0 0 0 1 0 1", "output": "22587" }, { "input": "10 11\n0 1 0 0 0 0 0 0 0 0 0\n0 1 0 1 0 0 1 0 0 0 0\n0 0 0 0 0 0 1 1 1 0 0\n0 0 0 0 0 0 0 0 0 0 0\n0 0 0 0 1 0 0 0 0 1 0\n0 0 0 0 0 0 1 0 0 0 0\n0 0 0 0 0 0 0 0 0 1 0\n0 0 1 0 0 0 1 1 0 0 0\n0 0 0 0 0 0 0 0 1 0 0\n0 0 1 0 1 0 0 0 0 1 1", "output": "12047" }, { "input": "14 15\n0 1 0 0 0 0 0 0 1 0 0 0 1 0 1\n0 0 0 1 1 1 1 0 1 0 0 1 1 0 0\n1 0 0 0 0 1 1 0 0 0 0 0 0 0 0\n0 1 0 0 0 1 0 1 1 0 0 1 0 0 0\n0 0 1 1 0 1 0 1 0 1 1 0 1 0 0\n0 0 0 1 1 0 0 0 0 0 1 1 0 1 0\n0 0 1 0 0 0 0 0 0 1 0 0 1 1 0\n1 1 0 0 0 1 0 0 0 0 0 0 1 1 0\n0 0 0 0 1 0 1 1 1 0 0 0 1 0 1\n1 0 1 1 0 1 0 0 1 0 0 1 1 1 0\n1 0 0 0 0 1 0 0 0 0 0 1 0 0 0\n0 0 0 1 0 1 0 0 0 0 1 0 0 0 1\n0 0 1 0 1 0 0 0 1 1 1 1 0 0 0\n0 0 0 0 0 0 0 0 0 0 0 1 0 0 0", "output": "53166" }, { "input": "1 50\n0 0 0 0 0 0 0 1 0 0 0 0 1 0 1 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 1 1 0 0 1 0 0 0 0 1 0 0 0 1 0 0", "output": "1099511628798" }, { "input": "50 1\n0\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n0\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n0\n1\n1\n1\n1\n1\n1\n1\n0\n1\n1\n1\n1\n0\n1\n1\n1\n1\n1", "output": "35184372088862" }, { "input": "1 50\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "1125899906842623" }, { "input": "5 50\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "5629499534214415" }, { "input": "32 2\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1", "output": "8589934622" }, { "input": "1 50\n0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "562949953421312" }, { "input": "50 1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1", "output": "1125899906842623" }, { "input": "1 49\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "562949953421311" }, { "input": "2 50\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0", "output": "2251799813685296" }, { "input": "3 50\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "3377699720528069" }, { "input": "1 50\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0", "output": "1125899906842623" }, { "input": "1 40\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "1099511627775" }, { "input": "1 33\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "8589934591" }, { "input": "2 40\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0", "output": "2199023255590" }, { "input": "1 35\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "34359738367" }, { "input": "50 1\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0", "output": "1125899906842623" } ]
1,635,571,947
2,147,483,647
Python 3
OK
TESTS
55
62
4,505,600
rows,cols = map(int,input().split()) total = 0 table = [] for i in range(rows): table.append(list(map(int,input().split()))) for row in table: one_count = 0 zero_count = 0 for num in row: if num == 1: one_count += 1 else: zero_count += 1 total += (((2**one_count)-1) + (2**zero_count)-1) for i in range(cols): one_count = 0 zero_count = 0 for j in range(rows): cell = table[j][i] if cell == 1: one_count += 1 elif cell == 0: zero_count += 1 total += ((((2**one_count)-1) + (2**zero_count)-1)-rows) print(total)
Title: Rectangles Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given *n*<=×<=*m* table. Each cell of the table is colored white or black. Find the number of non-empty sets of cells such that: 1. All cells in a set have the same color. 1. Every two cells in a set share row or column. Input Specification: The first line of input contains integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=50) — the number of rows and the number of columns correspondingly. The next *n* lines of input contain descriptions of rows. There are *m* integers, separated by spaces, in each line. The number equals 0 if the corresponding cell is colored white and equals 1 if the corresponding cell is colored black. Output Specification: Output single integer  — the number of non-empty sets from the problem description. Demo Input: ['1 1\n0\n', '2 3\n1 0 1\n0 1 0\n'] Demo Output: ['1\n', '8\n'] Note: In the second example, there are six one-element sets. Additionally, there are two two-element sets, the first one consists of the first and the third cells of the first row, the second one consists of the first and the third cells of the second row. To sum up, there are 8 sets.
```python rows,cols = map(int,input().split()) total = 0 table = [] for i in range(rows): table.append(list(map(int,input().split()))) for row in table: one_count = 0 zero_count = 0 for num in row: if num == 1: one_count += 1 else: zero_count += 1 total += (((2**one_count)-1) + (2**zero_count)-1) for i in range(cols): one_count = 0 zero_count = 0 for j in range(rows): cell = table[j][i] if cell == 1: one_count += 1 elif cell == 0: zero_count += 1 total += ((((2**one_count)-1) + (2**zero_count)-1)-rows) print(total) ```
3
124
A
The number of positions
PROGRAMMING
1,000
[ "math" ]
null
null
Petr stands in line of *n* people, but he doesn't know exactly which position he occupies. He can say that there are no less than *a* people standing in front of him and no more than *b* people standing behind him. Find the number of different positions Petr can occupy.
The only line contains three integers *n*, *a* and *b* (0<=≤<=*a*,<=*b*<=&lt;<=*n*<=≤<=100).
Print the single number — the number of the sought positions.
[ "3 1 1\n", "5 2 3\n" ]
[ "2\n", "3\n" ]
The possible positions in the first sample are: 2 and 3 (if we number the positions starting with 1). In the second sample they are 3, 4 and 5.
500
[ { "input": "3 1 1", "output": "2" }, { "input": "5 2 3", "output": "3" }, { "input": "5 4 0", "output": "1" }, { "input": "6 5 5", "output": "1" }, { "input": "9 4 3", "output": "4" }, { "input": "11 4 6", "output": "7" }, { "input": "13 8 7", "output": "5" }, { "input": "14 5 5", "output": "6" }, { "input": "16 6 9", "output": "10" }, { "input": "20 13 17", "output": "7" }, { "input": "22 4 8", "output": "9" }, { "input": "23 8 14", "output": "15" }, { "input": "26 18 22", "output": "8" }, { "input": "28 6 1", "output": "2" }, { "input": "29 5 23", "output": "24" }, { "input": "32 27 15", "output": "5" }, { "input": "33 11 5", "output": "6" }, { "input": "37 21 15", "output": "16" }, { "input": "39 34 33", "output": "5" }, { "input": "41 27 11", "output": "12" }, { "input": "42 25 16", "output": "17" }, { "input": "45 7 43", "output": "38" }, { "input": "47 16 17", "output": "18" }, { "input": "49 11 37", "output": "38" }, { "input": "51 38 39", "output": "13" }, { "input": "52 29 7", "output": "8" }, { "input": "56 43 12", "output": "13" }, { "input": "58 57 28", "output": "1" }, { "input": "59 12 39", "output": "40" }, { "input": "62 9 52", "output": "53" }, { "input": "63 29 44", "output": "34" }, { "input": "65 30 22", "output": "23" }, { "input": "66 27 38", "output": "39" }, { "input": "71 33 53", "output": "38" }, { "input": "73 14 12", "output": "13" }, { "input": "73 37 35", "output": "36" }, { "input": "76 69 44", "output": "7" }, { "input": "79 25 20", "output": "21" }, { "input": "81 60 20", "output": "21" }, { "input": "81 79 14", "output": "2" }, { "input": "84 0 42", "output": "43" }, { "input": "88 79 8", "output": "9" }, { "input": "90 76 59", "output": "14" }, { "input": "92 2 22", "output": "23" }, { "input": "94 5 88", "output": "89" }, { "input": "94 62 48", "output": "32" }, { "input": "96 22 72", "output": "73" }, { "input": "100 11 88", "output": "89" }, { "input": "100 81 91", "output": "19" }, { "input": "1 0 0", "output": "1" } ]
1,676,831,894
2,147,483,647
PyPy 3-64
OK
TESTS
50
124
0
# t = int(input()) t = 1 def cp(): # code here n,a,b = tuple(map(int,input().split())) if a+b == n: print(b) elif a+b > n: print(n-a) else: print(b+1) for i in range(t): cp()
Title: The number of positions Time Limit: None seconds Memory Limit: None megabytes Problem Description: Petr stands in line of *n* people, but he doesn't know exactly which position he occupies. He can say that there are no less than *a* people standing in front of him and no more than *b* people standing behind him. Find the number of different positions Petr can occupy. Input Specification: The only line contains three integers *n*, *a* and *b* (0<=≤<=*a*,<=*b*<=&lt;<=*n*<=≤<=100). Output Specification: Print the single number — the number of the sought positions. Demo Input: ['3 1 1\n', '5 2 3\n'] Demo Output: ['2\n', '3\n'] Note: The possible positions in the first sample are: 2 and 3 (if we number the positions starting with 1). In the second sample they are 3, 4 and 5.
```python # t = int(input()) t = 1 def cp(): # code here n,a,b = tuple(map(int,input().split())) if a+b == n: print(b) elif a+b > n: print(n-a) else: print(b+1) for i in range(t): cp() ```
3
318
A
Even Odds
PROGRAMMING
900
[ "math" ]
null
null
Being a nonconformist, Volodya is displeased with the current state of things, particularly with the order of natural numbers (natural number is positive integer number). He is determined to rearrange them. But there are too many natural numbers, so Volodya decided to start with the first *n*. He writes down the following sequence of numbers: firstly all odd integers from 1 to *n* (in ascending order), then all even integers from 1 to *n* (also in ascending order). Help our hero to find out which number will stand at the position number *k*.
The only line of input contains integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=1012). Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier.
Print the number that will stand at the position number *k* after Volodya's manipulations.
[ "10 3\n", "7 7\n" ]
[ "5", "6" ]
In the first sample Volodya's sequence will look like this: {1, 3, 5, 7, 9, 2, 4, 6, 8, 10}. The third place in the sequence is therefore occupied by the number 5.
500
[ { "input": "10 3", "output": "5" }, { "input": "7 7", "output": "6" }, { "input": "7 1", "output": "1" }, { "input": "7 2", "output": "3" }, { "input": "8 5", "output": "2" }, { "input": "8 3", "output": "5" }, { "input": "8 4", "output": "7" }, { "input": "1000000000000 500000000001", "output": "2" }, { "input": "999999999997 499999999999", "output": "999999999997" }, { "input": "999999999999 999999999999", "output": "999999999998" }, { "input": "1000000000000 1", "output": "1" }, { "input": "999999999999 1", "output": "1" }, { "input": "1 1", "output": "1" }, { "input": "1000000000000 1000000000000", "output": "1000000000000" }, { "input": "1000000000000 500000000000", "output": "999999999999" }, { "input": "1000000000000 499999999999", "output": "999999999997" }, { "input": "999999999997 499999999998", "output": "999999999995" }, { "input": "619234238 556154835", "output": "493075432" }, { "input": "38151981 36650624", "output": "35149266" }, { "input": "680402465 442571217", "output": "204739968" }, { "input": "109135284 9408714", "output": "18817427" }, { "input": "603701841 56038951", "output": "112077901" }, { "input": "356764822 321510177", "output": "286255532" }, { "input": "284911189 142190783", "output": "284381565" }, { "input": "91028405 61435545", "output": "31842684" } ]
1,693,284,218
2,147,483,647
Python 3
OK
TESTS
25
92
0
a,b=map(int,input().split()) if(a%2==0): even=odd=a//2 else: even=a//2 odd=even+1 if(b<=odd): print(2*b-1) else: print((b-odd)*2)
Title: Even Odds Time Limit: None seconds Memory Limit: None megabytes Problem Description: Being a nonconformist, Volodya is displeased with the current state of things, particularly with the order of natural numbers (natural number is positive integer number). He is determined to rearrange them. But there are too many natural numbers, so Volodya decided to start with the first *n*. He writes down the following sequence of numbers: firstly all odd integers from 1 to *n* (in ascending order), then all even integers from 1 to *n* (also in ascending order). Help our hero to find out which number will stand at the position number *k*. Input Specification: The only line of input contains integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=1012). Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier. Output Specification: Print the number that will stand at the position number *k* after Volodya's manipulations. Demo Input: ['10 3\n', '7 7\n'] Demo Output: ['5', '6'] Note: In the first sample Volodya's sequence will look like this: {1, 3, 5, 7, 9, 2, 4, 6, 8, 10}. The third place in the sequence is therefore occupied by the number 5.
```python a,b=map(int,input().split()) if(a%2==0): even=odd=a//2 else: even=a//2 odd=even+1 if(b<=odd): print(2*b-1) else: print((b-odd)*2) ```
3
246
B
Increase and Decrease
PROGRAMMING
1,300
[ "greedy", "math" ]
null
null
Polycarpus has an array, consisting of *n* integers *a*1,<=*a*2,<=...,<=*a**n*. Polycarpus likes it when numbers in an array match. That's why he wants the array to have as many equal numbers as possible. For that Polycarpus performs the following operation multiple times: - he chooses two elements of the array *a**i*, *a**j* (*i*<=≠<=*j*); - he simultaneously increases number *a**i* by 1 and decreases number *a**j* by 1, that is, executes *a**i*<==<=*a**i*<=+<=1 and *a**j*<==<=*a**j*<=-<=1. The given operation changes exactly two distinct array elements. Polycarpus can apply the described operation an infinite number of times. Now he wants to know what maximum number of equal array elements he can get if he performs an arbitrary number of such operation. Help Polycarpus.
The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the array size. The second line contains space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (|*a**i*|<=≤<=104) — the original array.
Print a single integer — the maximum number of equal array elements he can get if he performs an arbitrary number of the given operation.
[ "2\n2 1\n", "3\n1 4 1\n" ]
[ "1\n", "3\n" ]
none
1,000
[ { "input": "2\n2 1", "output": "1" }, { "input": "3\n1 4 1", "output": "3" }, { "input": "4\n2 -7 -2 -6", "output": "3" }, { "input": "4\n2 0 -2 -1", "output": "3" }, { "input": "6\n-1 1 0 0 -1 -1", "output": "5" }, { "input": "5\n0 0 0 0 0", "output": "5" }, { "input": "100\n968 793 -628 -416 942 -308 977 168 728 -879 952 781 -425 -475 -480 738 -740 142 -319 -116 -701 -183 41 324 -918 -391 -176 781 763 888 475 -617 134 -802 -133 -211 855 -869 -236 503 550 387 137 -221 -957 -800 -56 -673 440 -791 -217 -959 -892 886 -593 427 890 223 -425 -342 -262 693 -137 924 860 156 -110 444 -12 703 421 -638 725 -551 597 -206 -80 393 -441 -759 617 424 -506 209 579 -685 -861 507 312 597 -81 -491 424 222 -892 629 512 743 -452 -504", "output": "99" } ]
1,586,775,180
2,147,483,647
PyPy 3
OK
TESTS
30
340
5,324,800
n = int(input()) arr = list(map(int,input().split())) if n==1: print(0) elif n==2: if abs(arr[0]-arr[1])%2==0: print(2) else: print(1) else: d = max(arr) for i in range(n-1): arr[n-1]-=d-arr[i] if (d-arr[n-1])%n==0: print(n) else: print(n-1)
Title: Increase and Decrease Time Limit: None seconds Memory Limit: None megabytes Problem Description: Polycarpus has an array, consisting of *n* integers *a*1,<=*a*2,<=...,<=*a**n*. Polycarpus likes it when numbers in an array match. That's why he wants the array to have as many equal numbers as possible. For that Polycarpus performs the following operation multiple times: - he chooses two elements of the array *a**i*, *a**j* (*i*<=≠<=*j*); - he simultaneously increases number *a**i* by 1 and decreases number *a**j* by 1, that is, executes *a**i*<==<=*a**i*<=+<=1 and *a**j*<==<=*a**j*<=-<=1. The given operation changes exactly two distinct array elements. Polycarpus can apply the described operation an infinite number of times. Now he wants to know what maximum number of equal array elements he can get if he performs an arbitrary number of such operation. Help Polycarpus. Input Specification: The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the array size. The second line contains space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (|*a**i*|<=≤<=104) — the original array. Output Specification: Print a single integer — the maximum number of equal array elements he can get if he performs an arbitrary number of the given operation. Demo Input: ['2\n2 1\n', '3\n1 4 1\n'] Demo Output: ['1\n', '3\n'] Note: none
```python n = int(input()) arr = list(map(int,input().split())) if n==1: print(0) elif n==2: if abs(arr[0]-arr[1])%2==0: print(2) else: print(1) else: d = max(arr) for i in range(n-1): arr[n-1]-=d-arr[i] if (d-arr[n-1])%n==0: print(n) else: print(n-1) ```
3
29
A
Spit Problem
PROGRAMMING
1,000
[ "brute force" ]
A. Spit Problem
2
256
In a Berland's zoo there is an enclosure with camels. It is known that camels like to spit. Bob watched these interesting animals for the whole day and registered in his notepad where each animal spitted. Now he wants to know if in the zoo there are two camels, which spitted at each other. Help him to solve this task. The trajectory of a camel's spit is an arc, i.e. if the camel in position *x* spits *d* meters right, he can hit only the camel in position *x*<=+<=*d*, if such a camel exists.
The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the amount of camels in the zoo. Each of the following *n* lines contains two integers *x**i* and *d**i* (<=-<=104<=≤<=*x**i*<=≤<=104,<=1<=≤<=|*d**i*|<=≤<=2·104) — records in Bob's notepad. *x**i* is a position of the *i*-th camel, and *d**i* is a distance at which the *i*-th camel spitted. Positive values of *d**i* correspond to the spits right, negative values correspond to the spits left. No two camels may stand in the same position.
If there are two camels, which spitted at each other, output YES. Otherwise, output NO.
[ "2\n0 1\n1 -1\n", "3\n0 1\n1 1\n2 -2\n", "5\n2 -10\n3 10\n0 5\n5 -5\n10 1\n" ]
[ "YES\n", "NO\n", "YES\n" ]
none
500
[ { "input": "2\n0 1\n1 -1", "output": "YES" }, { "input": "3\n0 1\n1 1\n2 -2", "output": "NO" }, { "input": "5\n2 -10\n3 10\n0 5\n5 -5\n10 1", "output": "YES" }, { "input": "10\n-9897 -1144\n-4230 -6350\n2116 -3551\n-3635 4993\n3907 -9071\n-2362 4120\n-6542 984\n5807 3745\n7594 7675\n-5412 -6872", "output": "NO" }, { "input": "11\n-1536 3809\n-2406 -8438\n-1866 395\n5636 -490\n-6867 -7030\n7525 3575\n-6796 2908\n3884 4629\n-2862 -6122\n-8984 6122\n7137 -326", "output": "YES" }, { "input": "12\n-9765 1132\n-1382 -215\n-9405 7284\n-2040 3947\n-9360 3150\n6425 9386\n806 -2278\n-2121 -7284\n5663 -1608\n-8377 9297\n6245 708\n8470 6024", "output": "YES" }, { "input": "15\n8122 -9991\n-4068 -3386\n8971 3731\n3458 5161\n-8700 7562\n2691 8735\n-1510 -3892\n5183 -3753\n-7018 6637\n-7454 3386\n-818 -6377\n6771 -8647\n-7357 -1246\n-6186 1922\n9889 -3627", "output": "YES" }, { "input": "20\n-5264 6424\n-3664 -7459\n-2780 -9859\n-3317 6842\n5681 -8092\n1555 1904\n-6684 1414\n6593 -1253\n-5708 -1202\n335 1733\n-926 7579\n3459 -1904\n-4486 4006\n6201 3616\n2847 -5255\n8438 7057\n8171 6042\n-9102 3545\n7731 -233\n6264 6563", "output": "YES" }, { "input": "30\n-398 -1774\n313 -6974\n2346 -4657\n8552 -9647\n-5265 1538\n8195 4864\n-5641 -5219\n-1394 8563\n-1190 1992\n-4669 -1156\n7574 256\n9206 -2414\n4140 -549\n-294 2169\n7029 -2871\n3808 -9799\n3141 5690\n4648 -2680\n-5990 9800\n-2299 1697\n6077 -7177\n-400 -9724\n-4644 -2392\n-2198 -9531\n-2105 9386\n-8165 -4201\n-1589 -7916\n2518 -7840\n4173 -6949\n-3368 -9943", "output": "NO" } ]
1,630,561,017
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
92
6,656,000
n=int(input()) aa=[] for i in range(n): x,y=map(int,input().split()) aa.append(x) aa.append(y) if any(x%y in set(aa)): print("YES") else: print("NO")
Title: Spit Problem Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: In a Berland's zoo there is an enclosure with camels. It is known that camels like to spit. Bob watched these interesting animals for the whole day and registered in his notepad where each animal spitted. Now he wants to know if in the zoo there are two camels, which spitted at each other. Help him to solve this task. The trajectory of a camel's spit is an arc, i.e. if the camel in position *x* spits *d* meters right, he can hit only the camel in position *x*<=+<=*d*, if such a camel exists. Input Specification: The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the amount of camels in the zoo. Each of the following *n* lines contains two integers *x**i* and *d**i* (<=-<=104<=≤<=*x**i*<=≤<=104,<=1<=≤<=|*d**i*|<=≤<=2·104) — records in Bob's notepad. *x**i* is a position of the *i*-th camel, and *d**i* is a distance at which the *i*-th camel spitted. Positive values of *d**i* correspond to the spits right, negative values correspond to the spits left. No two camels may stand in the same position. Output Specification: If there are two camels, which spitted at each other, output YES. Otherwise, output NO. Demo Input: ['2\n0 1\n1 -1\n', '3\n0 1\n1 1\n2 -2\n', '5\n2 -10\n3 10\n0 5\n5 -5\n10 1\n'] Demo Output: ['YES\n', 'NO\n', 'YES\n'] Note: none
```python n=int(input()) aa=[] for i in range(n): x,y=map(int,input().split()) aa.append(x) aa.append(y) if any(x%y in set(aa)): print("YES") else: print("NO") ```
-1
842
A
Kirill And The Game
PROGRAMMING
1,200
[ "brute force", "two pointers" ]
null
null
Kirill plays a new computer game. He came to the potion store where he can buy any potion. Each potion is characterized by two integers — amount of experience and cost. The efficiency of a potion is the ratio of the amount of experience to the cost. Efficiency may be a non-integer number. For each two integer numbers *a* and *b* such that *l*<=≤<=*a*<=≤<=*r* and *x*<=≤<=*b*<=≤<=*y* there is a potion with experience *a* and cost *b* in the store (that is, there are (*r*<=-<=*l*<=+<=1)·(*y*<=-<=*x*<=+<=1) potions). Kirill wants to buy a potion which has efficiency *k*. Will he be able to do this?
First string contains five integer numbers *l*, *r*, *x*, *y*, *k* (1<=≤<=*l*<=≤<=*r*<=≤<=107, 1<=≤<=*x*<=≤<=*y*<=≤<=107, 1<=≤<=*k*<=≤<=107).
Print "YES" without quotes if a potion with efficiency exactly *k* can be bought in the store and "NO" without quotes otherwise. You can output each of the letters in any register.
[ "1 10 1 10 1\n", "1 5 6 10 1\n" ]
[ "YES", "NO" ]
none
500
[ { "input": "1 10 1 10 1", "output": "YES" }, { "input": "1 5 6 10 1", "output": "NO" }, { "input": "1 1 1 1 1", "output": "YES" }, { "input": "1 1 1 1 2", "output": "NO" }, { "input": "1 100000 1 100000 100000", "output": "YES" }, { "input": "1 100000 1 100000 100001", "output": "NO" }, { "input": "25 10000 200 10000 5", "output": "YES" }, { "input": "1 100000 10 100000 50000", "output": "NO" }, { "input": "91939 94921 10197 89487 1", "output": "NO" }, { "input": "30518 58228 74071 77671 1", "output": "NO" }, { "input": "46646 79126 78816 91164 5", "output": "NO" }, { "input": "30070 83417 92074 99337 2", "output": "NO" }, { "input": "13494 17544 96820 99660 6", "output": "NO" }, { "input": "96918 97018 10077 86510 9", "output": "YES" }, { "input": "13046 45594 14823 52475 1", "output": "YES" }, { "input": "29174 40572 95377 97669 4", "output": "NO" }, { "input": "79894 92433 8634 86398 4", "output": "YES" }, { "input": "96022 98362 13380 94100 6", "output": "YES" }, { "input": "79446 95675 93934 96272 3", "output": "NO" }, { "input": "5440 46549 61481 99500 10", "output": "NO" }, { "input": "21569 53580 74739 87749 3", "output": "NO" }, { "input": "72289 78297 79484 98991 7", "output": "NO" }, { "input": "88417 96645 92742 98450 5", "output": "NO" }, { "input": "71841 96625 73295 77648 8", "output": "NO" }, { "input": "87969 99230 78041 94736 4", "output": "NO" }, { "input": "4 4 1 2 3", "output": "NO" }, { "input": "150 150 1 2 100", "output": "NO" }, { "input": "99 100 1 100 50", "output": "YES" }, { "input": "7 7 3 6 2", "output": "NO" }, { "input": "10 10 1 10 1", "output": "YES" }, { "input": "36 36 5 7 6", "output": "YES" }, { "input": "73 96 1 51 51", "output": "NO" }, { "input": "3 3 1 3 2", "output": "NO" }, { "input": "10000000 10000000 1 100000 10000000", "output": "YES" }, { "input": "9222174 9829060 9418763 9955619 9092468", "output": "NO" }, { "input": "70 70 1 2 50", "output": "NO" }, { "input": "100 200 1 20 5", "output": "YES" }, { "input": "1 200000 65536 65536 65537", "output": "NO" }, { "input": "15 15 1 100 1", "output": "YES" }, { "input": "10000000 10000000 1 10000000 100000", "output": "YES" }, { "input": "10 10 2 5 4", "output": "NO" }, { "input": "67 69 7 7 9", "output": "NO" }, { "input": "100000 10000000 1 10000000 100000", "output": "YES" }, { "input": "9 12 1 2 7", "output": "NO" }, { "input": "5426234 6375745 2636512 8492816 4409404", "output": "NO" }, { "input": "6134912 6134912 10000000 10000000 999869", "output": "NO" }, { "input": "3 3 1 100 1", "output": "YES" }, { "input": "10000000 10000000 10 10000000 100000", "output": "YES" }, { "input": "4 4 1 100 2", "output": "YES" }, { "input": "8 13 1 4 7", "output": "NO" }, { "input": "10 10 100000 10000000 10000000", "output": "NO" }, { "input": "5 6 1 4 2", "output": "YES" }, { "input": "1002 1003 1 2 1000", "output": "NO" }, { "input": "4 5 1 2 2", "output": "YES" }, { "input": "5 6 1 5 1", "output": "YES" }, { "input": "15 21 2 4 7", "output": "YES" }, { "input": "4 5 3 7 1", "output": "YES" }, { "input": "15 15 3 4 4", "output": "NO" }, { "input": "3 6 1 2 2", "output": "YES" }, { "input": "2 10 3 6 3", "output": "YES" }, { "input": "1 10000000 1 10000000 100000", "output": "YES" }, { "input": "8 13 1 2 7", "output": "NO" }, { "input": "98112 98112 100000 100000 128850", "output": "NO" }, { "input": "2 2 1 2 1", "output": "YES" }, { "input": "8 8 3 4 2", "output": "YES" }, { "input": "60 60 2 3 25", "output": "NO" }, { "input": "16 17 2 5 5", "output": "NO" }, { "input": "2 4 1 3 1", "output": "YES" }, { "input": "4 5 1 2 3", "output": "NO" }, { "input": "10 10 3 4 3", "output": "NO" }, { "input": "10 10000000 999999 10000000 300", "output": "NO" }, { "input": "100 120 9 11 10", "output": "YES" }, { "input": "8 20 1 3 4", "output": "YES" }, { "input": "10 14 2 3 4", "output": "YES" }, { "input": "2000 2001 1 3 1000", "output": "YES" }, { "input": "12 13 2 3 5", "output": "NO" }, { "input": "7 7 2 3 3", "output": "NO" }, { "input": "5 8 1 10000000 4", "output": "YES" }, { "input": "5 5 1 1 4", "output": "NO" }, { "input": "5 5 1 6 2", "output": "NO" }, { "input": "200 300 4000381 4000382 4000381", "output": "NO" }, { "input": "11 17 2 5 2", "output": "NO" }, { "input": "9999999 10000000 1 10000000 999997", "output": "NO" }, { "input": "7 8 2 3 3", "output": "NO" }, { "input": "7 7 3 3 2", "output": "NO" }, { "input": "15 15 2 3 7", "output": "NO" }, { "input": "65408 65408 859 859 10000000", "output": "NO" }, { "input": "1000000 10000000 1 100000 1", "output": "NO" }, { "input": "6 12 2 3 2", "output": "YES" }, { "input": "7 8 1 3 3", "output": "NO" }, { "input": "4 4 1 2 2", "output": "YES" }, { "input": "2 3 1 2 2", "output": "YES" }, { "input": "11 14 2 3 5", "output": "NO" }, { "input": "7 7 1 10 3", "output": "NO" }, { "input": "49 50 1 2 27", "output": "NO" }, { "input": "1 10000000 1 10000000 123456", "output": "YES" }, { "input": "100000 10000000 100 10000000 100000", "output": "YES" }, { "input": "17 19 2 3 8", "output": "NO" }, { "input": "4 6 3 9 1", "output": "YES" }, { "input": "19 20 6 7 3", "output": "NO" }, { "input": "5000000 10000000 1 4999999 1", "output": "NO" } ]
1,561,384,409
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
25
140
0
# cook your dish here l,r,x,y,k=input().split() l=int(l) r=int(r) x=int(x) y=int(y) k=int(k) flag=0 for i in range(l,r+1): if(i>=(x*k) and i<=(y*k)): flag=1 break if(flag==1): print("YES") else: print("NO")
Title: Kirill And The Game Time Limit: None seconds Memory Limit: None megabytes Problem Description: Kirill plays a new computer game. He came to the potion store where he can buy any potion. Each potion is characterized by two integers — amount of experience and cost. The efficiency of a potion is the ratio of the amount of experience to the cost. Efficiency may be a non-integer number. For each two integer numbers *a* and *b* such that *l*<=≤<=*a*<=≤<=*r* and *x*<=≤<=*b*<=≤<=*y* there is a potion with experience *a* and cost *b* in the store (that is, there are (*r*<=-<=*l*<=+<=1)·(*y*<=-<=*x*<=+<=1) potions). Kirill wants to buy a potion which has efficiency *k*. Will he be able to do this? Input Specification: First string contains five integer numbers *l*, *r*, *x*, *y*, *k* (1<=≤<=*l*<=≤<=*r*<=≤<=107, 1<=≤<=*x*<=≤<=*y*<=≤<=107, 1<=≤<=*k*<=≤<=107). Output Specification: Print "YES" without quotes if a potion with efficiency exactly *k* can be bought in the store and "NO" without quotes otherwise. You can output each of the letters in any register. Demo Input: ['1 10 1 10 1\n', '1 5 6 10 1\n'] Demo Output: ['YES', 'NO'] Note: none
```python # cook your dish here l,r,x,y,k=input().split() l=int(l) r=int(r) x=int(x) y=int(y) k=int(k) flag=0 for i in range(l,r+1): if(i>=(x*k) and i<=(y*k)): flag=1 break if(flag==1): print("YES") else: print("NO") ```
0
706
B
Interesting drink
PROGRAMMING
1,100
[ "binary search", "dp", "implementation" ]
null
null
Vasiliy likes to rest after a hard work, so you may often meet him in some bar nearby. As all programmers do, he loves the famous drink "Beecola", which can be bought in *n* different shops in the city. It's known that the price of one bottle in the shop *i* is equal to *x**i* coins. Vasiliy plans to buy his favorite drink for *q* consecutive days. He knows, that on the *i*-th day he will be able to spent *m**i* coins. Now, for each of the days he want to know in how many different shops he can buy a bottle of "Beecola".
The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the number of shops in the city that sell Vasiliy's favourite drink. The second line contains *n* integers *x**i* (1<=≤<=*x**i*<=≤<=100<=000) — prices of the bottles of the drink in the *i*-th shop. The third line contains a single integer *q* (1<=≤<=*q*<=≤<=100<=000) — the number of days Vasiliy plans to buy the drink. Then follow *q* lines each containing one integer *m**i* (1<=≤<=*m**i*<=≤<=109) — the number of coins Vasiliy can spent on the *i*-th day.
Print *q* integers. The *i*-th of them should be equal to the number of shops where Vasiliy will be able to buy a bottle of the drink on the *i*-th day.
[ "5\n3 10 8 6 11\n4\n1\n10\n3\n11\n" ]
[ "0\n4\n1\n5\n" ]
On the first day, Vasiliy won't be able to buy a drink in any of the shops. On the second day, Vasiliy can buy a drink in the shops 1, 2, 3 and 4. On the third day, Vasiliy can buy a drink only in the shop number 1. Finally, on the last day Vasiliy can buy a drink in any shop.
1,000
[ { "input": "5\n3 10 8 6 11\n4\n1\n10\n3\n11", "output": "0\n4\n1\n5" }, { "input": "5\n868 987 714 168 123\n10\n424\n192\n795\n873\n117\n914\n735\n158\n631\n471", "output": "2\n2\n3\n4\n0\n4\n3\n1\n2\n2" }, { "input": "3\n435 482 309\n7\n245\n241\n909\n745\n980\n29\n521", "output": "0\n0\n3\n3\n3\n0\n3" }, { "input": "1\n653\n9\n903\n980\n80\n770\n965\n874\n381\n657\n969", "output": "1\n1\n0\n1\n1\n1\n0\n1\n1" }, { "input": "12\n35345 58181 32223 84621 35905 73863 99537 30666 67771 39229 36847 29038\n23\n55052824\n82504840\n35160556\n78141700\n73401989\n86305919\n39430705\n31939373\n23501765\n4406029\n61436920\n14295390\n34275309\n28028753\n85724689\n70158847\n2396455\n66994588\n84024224\n30175981\n65622319\n76517111\n76605341", "output": "12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12" }, { "input": "4\n698 193 1584 76192\n4\n553640\n310518\n274280\n429192", "output": "4\n4\n4\n4" }, { "input": "1\n1\n1\n1000000000", "output": "1" }, { "input": "1\n1\n1\n100005", "output": "1" }, { "input": "3\n1 2 3\n1\n100005", "output": "3" }, { "input": "2\n1 2\n3\n100004\n100005\n100006", "output": "2\n2\n2" }, { "input": "3\n1 1 1\n1\n1", "output": "3" }, { "input": "1\n1\n1\n1", "output": "1" }, { "input": "3\n1 2 3\n1\n100000", "output": "3" }, { "input": "5\n1 1 1 1 10\n2\n1\n10", "output": "4\n5" }, { "input": "5\n3 10 8 6 11\n1\n10000000", "output": "5" } ]
1,689,148,426
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
10
2,000
12,390,400
a=int(input()) g=list(map(int,input().split())) b=int(input()) for i in range(b): s=0 m=int(input()) for t in g: if m>=t: s+=1 print(s) # Wed Jul 12 2023 10:34:38 GMT+0300 (Moscow Standard Time)
Title: Interesting drink Time Limit: None seconds Memory Limit: None megabytes Problem Description: Vasiliy likes to rest after a hard work, so you may often meet him in some bar nearby. As all programmers do, he loves the famous drink "Beecola", which can be bought in *n* different shops in the city. It's known that the price of one bottle in the shop *i* is equal to *x**i* coins. Vasiliy plans to buy his favorite drink for *q* consecutive days. He knows, that on the *i*-th day he will be able to spent *m**i* coins. Now, for each of the days he want to know in how many different shops he can buy a bottle of "Beecola". Input Specification: The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the number of shops in the city that sell Vasiliy's favourite drink. The second line contains *n* integers *x**i* (1<=≤<=*x**i*<=≤<=100<=000) — prices of the bottles of the drink in the *i*-th shop. The third line contains a single integer *q* (1<=≤<=*q*<=≤<=100<=000) — the number of days Vasiliy plans to buy the drink. Then follow *q* lines each containing one integer *m**i* (1<=≤<=*m**i*<=≤<=109) — the number of coins Vasiliy can spent on the *i*-th day. Output Specification: Print *q* integers. The *i*-th of them should be equal to the number of shops where Vasiliy will be able to buy a bottle of the drink on the *i*-th day. Demo Input: ['5\n3 10 8 6 11\n4\n1\n10\n3\n11\n'] Demo Output: ['0\n4\n1\n5\n'] Note: On the first day, Vasiliy won't be able to buy a drink in any of the shops. On the second day, Vasiliy can buy a drink in the shops 1, 2, 3 and 4. On the third day, Vasiliy can buy a drink only in the shop number 1. Finally, on the last day Vasiliy can buy a drink in any shop.
```python a=int(input()) g=list(map(int,input().split())) b=int(input()) for i in range(b): s=0 m=int(input()) for t in g: if m>=t: s+=1 print(s) # Wed Jul 12 2023 10:34:38 GMT+0300 (Moscow Standard Time) ```
0
513
F2
Scaygerboss
PROGRAMMING
2,800
[ "flows" ]
null
null
Cthulhu decided to catch Scaygerboss. Scaygerboss found it out and is trying to hide in a pack of his scaygers. Each scayger except Scaygerboss is either a male or a female. Scaygerboss's gender is "other". Scaygers are scattered on a two-dimensional map divided into cells. A scayger looks nerdy and loveable if it is staying in the same cell with exactly one scayger of a gender that is different from its own gender. Cthulhu will not be able to catch Scaygerboss if all the scaygers on the map look nerdy and loveable. The scaygers can move around at different speeds. For each scayger, we are given the time it takes this scayger to move from a cell to an adjacent cell. Cells are adjacent if they share a common side. At any point of time, each cell that does not contain an obstacle can be occupied by an arbitrary number of scaygers. Scaygers cannot move to cells with obstacles. Calculate minimal time in order to make all scaygers look nerdy and loveable if they move optimally toward this goal.
The first line contains 4 integers: *n*, *m*, *males*, *females* (0<=≤<=*males*,<=*females*<=≤<=*n*·*m*). *n* and *m* are dimensions of the map; *males* and *females* are numbers of male scaygers and female scaygers. Next *n* lines describe the map. Each of these lines contains *m* characters. Character '.' stands for a free cell; character '#' stands for a cell with an obstacle. The next line contains 3 integers *r*, *c*, and *t* (1<=≤<=*r*<=≤<=*n*, 1<=≤<=*c*<=≤<=*m*, 1<=≤<=*t*<=≤<=109): the current coordinates of Scaygerboss and the time it takes Scaygerboss to move to an adjacent cell. The next *males* lines contain coordinates and times of male scaygers in the same format as for Scaygerboss. The next *females* lines contain coordinates and times of female scaygers in the same format as for Scaygerboss. (The coordinates and times adhere to the same limits as for Scaygerboss.) All scaygers reside in cells without obstacles. The problem consists of two subproblems. The subproblems have different constraints on the input. You will get some score for the correct submission of the subproblem. The description of the subproblems follows. - In subproblem F1 (14 points), the constraints 1<=≤<=*n*,<=*m*<=≤<=11 will hold. - In subproblem F2 (6 points), the constraints 1<=≤<=*n*,<=*m*<=≤<=22 will hold.
Output the minimum possible time it takes to make all scaygers look nerdy and loveable or -1 if it is impossible.
[ "4 4 2 3\n....\n.###\n####\n####\n2 1 1\n2 1 2\n2 1 2\n2 1 2\n2 1 2\n1 1 2\n", "2 4 2 2\n....\n.###\n2 1 1\n2 1 2\n2 1 2\n2 1 2\n2 1 2\n" ]
[ "2\n", "-1\n" ]
Consider the first sample test. The scaygers are hiding on a 4 by 4 map. Scaygerboss initially resides in the cell (2, 1) and can move between cells in 1 unit of time. There are also 2 male and 3 female scaygers on the map. One of the females initially is in the cell (1, 1), and all the other scaygers are in the cell (2, 1). All the scaygers move between cells in 2 units of time. If Scaygerboss and the female scayger from the cell (1, 1) move to the cell (1, 2), and a male and a female scayger from those residing in the cell (2, 1) move to the cell (1, 1), then all the scaygers will look nerdy and lovable in 2 units of time.
6
[]
1,689,258,408
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS2
0
46
0
print("_RANDOM_GUESS_1689258408.4685388")# 1689258408.468582
Title: Scaygerboss Time Limit: None seconds Memory Limit: None megabytes Problem Description: Cthulhu decided to catch Scaygerboss. Scaygerboss found it out and is trying to hide in a pack of his scaygers. Each scayger except Scaygerboss is either a male or a female. Scaygerboss's gender is "other". Scaygers are scattered on a two-dimensional map divided into cells. A scayger looks nerdy and loveable if it is staying in the same cell with exactly one scayger of a gender that is different from its own gender. Cthulhu will not be able to catch Scaygerboss if all the scaygers on the map look nerdy and loveable. The scaygers can move around at different speeds. For each scayger, we are given the time it takes this scayger to move from a cell to an adjacent cell. Cells are adjacent if they share a common side. At any point of time, each cell that does not contain an obstacle can be occupied by an arbitrary number of scaygers. Scaygers cannot move to cells with obstacles. Calculate minimal time in order to make all scaygers look nerdy and loveable if they move optimally toward this goal. Input Specification: The first line contains 4 integers: *n*, *m*, *males*, *females* (0<=≤<=*males*,<=*females*<=≤<=*n*·*m*). *n* and *m* are dimensions of the map; *males* and *females* are numbers of male scaygers and female scaygers. Next *n* lines describe the map. Each of these lines contains *m* characters. Character '.' stands for a free cell; character '#' stands for a cell with an obstacle. The next line contains 3 integers *r*, *c*, and *t* (1<=≤<=*r*<=≤<=*n*, 1<=≤<=*c*<=≤<=*m*, 1<=≤<=*t*<=≤<=109): the current coordinates of Scaygerboss and the time it takes Scaygerboss to move to an adjacent cell. The next *males* lines contain coordinates and times of male scaygers in the same format as for Scaygerboss. The next *females* lines contain coordinates and times of female scaygers in the same format as for Scaygerboss. (The coordinates and times adhere to the same limits as for Scaygerboss.) All scaygers reside in cells without obstacles. The problem consists of two subproblems. The subproblems have different constraints on the input. You will get some score for the correct submission of the subproblem. The description of the subproblems follows. - In subproblem F1 (14 points), the constraints 1<=≤<=*n*,<=*m*<=≤<=11 will hold. - In subproblem F2 (6 points), the constraints 1<=≤<=*n*,<=*m*<=≤<=22 will hold. Output Specification: Output the minimum possible time it takes to make all scaygers look nerdy and loveable or -1 if it is impossible. Demo Input: ['4 4 2 3\n....\n.###\n####\n####\n2 1 1\n2 1 2\n2 1 2\n2 1 2\n2 1 2\n1 1 2\n', '2 4 2 2\n....\n.###\n2 1 1\n2 1 2\n2 1 2\n2 1 2\n2 1 2\n'] Demo Output: ['2\n', '-1\n'] Note: Consider the first sample test. The scaygers are hiding on a 4 by 4 map. Scaygerboss initially resides in the cell (2, 1) and can move between cells in 1 unit of time. There are also 2 male and 3 female scaygers on the map. One of the females initially is in the cell (1, 1), and all the other scaygers are in the cell (2, 1). All the scaygers move between cells in 2 units of time. If Scaygerboss and the female scayger from the cell (1, 1) move to the cell (1, 2), and a male and a female scayger from those residing in the cell (2, 1) move to the cell (1, 1), then all the scaygers will look nerdy and lovable in 2 units of time.
```python print("_RANDOM_GUESS_1689258408.4685388")# 1689258408.468582 ```
0
797
B
Odd sum
PROGRAMMING
1,400
[ "dp", "greedy", "implementation" ]
null
null
You are given sequence *a*1,<=*a*2,<=...,<=*a**n* of integer numbers of length *n*. Your task is to find such subsequence that its sum is odd and maximum among all such subsequences. It's guaranteed that given sequence contains subsequence with odd sum. Subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements. You should write a program which finds sum of the best subsequence.
The first line contains integer number *n* (1<=≤<=*n*<=≤<=105). The second line contains *n* integer numbers *a*1,<=*a*2,<=...,<=*a**n* (<=-<=104<=≤<=*a**i*<=≤<=104). The sequence contains at least one subsequence with odd sum.
Print sum of resulting subseqeuence.
[ "4\n-2 2 -3 1\n", "3\n2 -5 -3\n" ]
[ "3\n", "-1\n" ]
In the first example sum of the second and the fourth elements is 3.
0
[ { "input": "4\n-2 2 -3 1", "output": "3" }, { "input": "3\n2 -5 -3", "output": "-1" }, { "input": "1\n1", "output": "1" }, { "input": "1\n-1", "output": "-1" }, { "input": "15\n-6004 4882 9052 413 6056 4306 9946 -4616 -6135 906 -1718 5252 -2866 9061 4046", "output": "53507" }, { "input": "2\n-5439 -6705", "output": "-5439" }, { "input": "2\n2850 6843", "output": "9693" }, { "input": "2\n144 9001", "output": "9145" }, { "input": "10\n7535 -819 2389 4933 5495 4887 -5181 -9355 7955 5757", "output": "38951" }, { "input": "10\n-9169 -1574 3580 -8579 -7177 -3216 7490 3470 3465 -1197", "output": "18005" }, { "input": "10\n941 7724 2220 -4704 -8374 -8249 7606 9502 612 -9097", "output": "28605" }, { "input": "10\n4836 -2331 -3456 2312 -1574 3134 -670 -204 512 -5504", "output": "8463" }, { "input": "10\n1184 5136 1654 3254 6576 6900 6468 327 179 7114", "output": "38613" }, { "input": "10\n-2152 -1776 -1810 -9046 -6090 -2324 -8716 -6103 -787 -812", "output": "-787" }, { "input": "3\n1 1 1", "output": "3" }, { "input": "5\n5 5 5 3 -1", "output": "17" }, { "input": "5\n-1 -2 5 3 0", "output": "7" }, { "input": "5\n-3 -2 5 -1 3", "output": "7" }, { "input": "3\n-2 2 -1", "output": "1" }, { "input": "5\n5 0 7 -2 3", "output": "15" }, { "input": "2\n-2 -5", "output": "-5" }, { "input": "3\n-1 -3 0", "output": "-1" }, { "input": "5\n2 -1 0 -3 -2", "output": "1" }, { "input": "4\n2 3 0 5", "output": "7" }, { "input": "5\n-5 3 -2 2 5", "output": "7" }, { "input": "59\n8593 5929 3016 -859 4366 -6842 8435 -3910 -2458 -8503 -3612 -9793 -5360 -9791 -362 -7180 727 -6245 -8869 -7316 8214 -7944 7098 3788 -5436 -6626 -1131 -2410 -5647 -7981 263 -5879 8786 709 6489 5316 -4039 4909 -4340 7979 -89 9844 -906 172 -7674 -3371 -6828 9505 3284 5895 3646 6680 -1255 3635 -9547 -5104 -1435 -7222 2244", "output": "129433" }, { "input": "17\n-6170 2363 6202 -9142 7889 779 2843 -5089 2313 -3952 1843 5171 462 -3673 5098 -2519 9565", "output": "43749" }, { "input": "26\n-8668 9705 1798 -1766 9644 3688 8654 -3077 -5462 2274 6739 2732 3635 -4745 -9144 -9175 -7488 -2010 1637 1118 8987 1597 -2873 -5153 -8062 146", "output": "60757" }, { "input": "51\n8237 -7239 -3545 -6059 -5110 4066 -4148 -7641 -5797 -994 963 1144 -2785 -8765 -1216 5410 1508 -6312 -6313 -680 -7657 4579 -6898 7379 2015 -5087 -5417 -6092 3819 -9101 989 -8380 9161 -7519 -9314 -3838 7160 5180 567 -1606 -3842 -9665 -2266 1296 -8417 -3976 7436 -2075 -441 -4565 3313", "output": "73781" }, { "input": "1\n-1", "output": "-1" }, { "input": "1\n1", "output": "1" }, { "input": "1\n-1", "output": "-1" }, { "input": "1\n1", "output": "1" }, { "input": "1\n1", "output": "1" }, { "input": "1\n-1", "output": "-1" }, { "input": "1\n-1", "output": "-1" }, { "input": "1\n1", "output": "1" }, { "input": "2\n-2 1", "output": "1" }, { "input": "2\n3 2", "output": "5" }, { "input": "2\n1 2", "output": "3" }, { "input": "2\n-1 1", "output": "1" }, { "input": "2\n0 -1", "output": "-1" }, { "input": "2\n2 1", "output": "3" }, { "input": "2\n3 0", "output": "3" }, { "input": "2\n0 -1", "output": "-1" }, { "input": "3\n-3 1 -1", "output": "1" }, { "input": "3\n3 -1 1", "output": "3" }, { "input": "3\n1 3 1", "output": "5" }, { "input": "3\n-1 0 1", "output": "1" }, { "input": "3\n-3 -3 -2", "output": "-3" }, { "input": "3\n3 -1 1", "output": "3" }, { "input": "3\n3 -1 1", "output": "3" }, { "input": "3\n-2 -2 1", "output": "1" }, { "input": "4\n0 -1 -3 -4", "output": "-1" }, { "input": "4\n5 3 2 1", "output": "11" }, { "input": "4\n-1 -2 4 -2", "output": "3" }, { "input": "4\n-1 -3 0 -3", "output": "-1" }, { "input": "4\n1 -4 -3 -4", "output": "1" }, { "input": "4\n5 3 3 4", "output": "15" }, { "input": "4\n-1 -3 -1 2", "output": "1" }, { "input": "4\n3 2 -1 -4", "output": "5" }, { "input": "5\n-5 -4 -3 -5 2", "output": "-1" }, { "input": "5\n5 5 1 2 -2", "output": "13" }, { "input": "5\n-2 -1 -5 -1 4", "output": "3" }, { "input": "5\n-5 -5 -4 4 0", "output": "-1" }, { "input": "5\n2 -3 -1 -4 -5", "output": "1" }, { "input": "5\n4 3 4 2 3", "output": "13" }, { "input": "5\n0 -2 -5 3 3", "output": "3" }, { "input": "5\n4 -2 -2 -3 0", "output": "1" }, { "input": "6\n6 7 -1 1 5 -1", "output": "19" }, { "input": "6\n-1 7 2 -3 -4 -5", "output": "9" }, { "input": "6\n0 -1 -3 -5 2 -6", "output": "1" }, { "input": "6\n4 -1 0 3 6 1", "output": "13" }, { "input": "6\n5 3 3 4 4 -3", "output": "19" }, { "input": "6\n0 -3 5 -4 5 -4", "output": "7" }, { "input": "6\n-5 -3 1 -1 -5 -3", "output": "1" }, { "input": "6\n-2 1 3 -2 7 4", "output": "15" }, { "input": "7\n0 7 6 2 7 0 6", "output": "21" }, { "input": "7\n6 -6 -1 -5 7 1 7", "output": "21" }, { "input": "7\n2 3 -5 0 -4 0 -4", "output": "5" }, { "input": "7\n-6 3 -3 -1 -6 -6 -5", "output": "3" }, { "input": "7\n7 6 3 2 4 2 0", "output": "21" }, { "input": "7\n-2 3 -3 4 4 0 -1", "output": "11" }, { "input": "7\n-5 -7 4 0 5 -3 -5", "output": "9" }, { "input": "7\n-3 -5 -4 1 3 -4 -7", "output": "3" }, { "input": "8\n5 2 4 5 7 -2 7 3", "output": "33" }, { "input": "8\n-8 -3 -1 3 -8 -4 -4 4", "output": "7" }, { "input": "8\n-6 -7 -7 -5 -4 -9 -2 -7", "output": "-5" }, { "input": "8\n8 7 6 8 3 4 8 -2", "output": "41" }, { "input": "8\n6 7 0 -6 6 5 4 7", "output": "35" }, { "input": "8\n0 -7 -5 -5 5 -1 -8 -7", "output": "5" }, { "input": "8\n1 -6 -5 7 -3 -4 2 -2", "output": "9" }, { "input": "8\n1 -8 -6 -6 -6 -7 -5 -1", "output": "1" }, { "input": "9\n-3 -1 4 4 8 -8 -5 9 -2", "output": "25" }, { "input": "9\n-9 -1 3 -2 -7 2 -9 -1 -4", "output": "5" }, { "input": "9\n-6 -9 -3 -8 -5 2 -6 0 -5", "output": "-1" }, { "input": "9\n5 4 3 3 6 7 8 5 9", "output": "47" }, { "input": "9\n5 3 9 1 5 2 -3 7 0", "output": "31" }, { "input": "9\n-3 -9 -1 -7 5 6 -4 -6 -6", "output": "11" }, { "input": "9\n-6 -5 6 -5 -2 0 1 2 -9", "output": "9" }, { "input": "9\n8 3 6 1 -3 5 2 9 1", "output": "35" }, { "input": "10\n-6 -4 -7 -1 -9 -10 -10 1 0 -3", "output": "1" }, { "input": "10\n-2 -10 -5 -6 -10 -3 -6 -3 -8 -8", "output": "-3" }, { "input": "10\n8 5 9 2 3 3 -6 1 -1 8", "output": "39" }, { "input": "10\n2 10 -7 6 -1 -1 7 -9 -4 -6", "output": "25" }, { "input": "10\n-10 -2 -2 -1 -10 -7 1 0 -4 -5", "output": "1" }, { "input": "10\n4 3 10 -2 -1 0 10 6 7 0", "output": "39" }, { "input": "10\n-2 6 6 5 0 10 6 7 -1 1", "output": "41" }, { "input": "10\n-10 2 8 -6 -1 -5 1 -10 -10 -1", "output": "11" } ]
1,601,753,719
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
16
124
0
n = int(input()) l = list(map(int,input().split())) o = [] e = [] for i in l: if i%2 == 0: e.append(i) else: o.append(i) e.sort() o.sort() som = 0 x = o.pop() som += x f = 0 while f != 1 and len(e) != 0: x = e.pop() if x <= 0: f = 1 else: som += x f = 0 cnt = 1 p = [] while f != 1 and len(o) != 0: x = o.pop() if x <= 0: f = 1 else: som += x p.append(x) cnt += 1 if cnt%2 == 0: x = p.pop() som -= x print(som)
Title: Odd sum Time Limit: None seconds Memory Limit: None megabytes Problem Description: You are given sequence *a*1,<=*a*2,<=...,<=*a**n* of integer numbers of length *n*. Your task is to find such subsequence that its sum is odd and maximum among all such subsequences. It's guaranteed that given sequence contains subsequence with odd sum. Subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements. You should write a program which finds sum of the best subsequence. Input Specification: The first line contains integer number *n* (1<=≤<=*n*<=≤<=105). The second line contains *n* integer numbers *a*1,<=*a*2,<=...,<=*a**n* (<=-<=104<=≤<=*a**i*<=≤<=104). The sequence contains at least one subsequence with odd sum. Output Specification: Print sum of resulting subseqeuence. Demo Input: ['4\n-2 2 -3 1\n', '3\n2 -5 -3\n'] Demo Output: ['3\n', '-1\n'] Note: In the first example sum of the second and the fourth elements is 3.
```python n = int(input()) l = list(map(int,input().split())) o = [] e = [] for i in l: if i%2 == 0: e.append(i) else: o.append(i) e.sort() o.sort() som = 0 x = o.pop() som += x f = 0 while f != 1 and len(e) != 0: x = e.pop() if x <= 0: f = 1 else: som += x f = 0 cnt = 1 p = [] while f != 1 and len(o) != 0: x = o.pop() if x <= 0: f = 1 else: som += x p.append(x) cnt += 1 if cnt%2 == 0: x = p.pop() som -= x print(som) ```
0
679
A
Bear and Prime 100
PROGRAMMING
1,400
[ "constructive algorithms", "interactive", "math" ]
null
null
This is an interactive problem. In the output section below you will see the information about flushing the output. Bear Limak thinks of some hidden number — an integer from interval [2,<=100]. Your task is to say if the hidden number is prime or composite. Integer *x*<=&gt;<=1 is called prime if it has exactly two distinct divisors, 1 and *x*. If integer *x*<=&gt;<=1 is not prime, it's called composite. You can ask up to 20 queries about divisors of the hidden number. In each query you should print an integer from interval [2,<=100]. The system will answer "yes" if your integer is a divisor of the hidden number. Otherwise, the answer will be "no". For example, if the hidden number is 14 then the system will answer "yes" only if you print 2, 7 or 14. When you are done asking queries, print "prime" or "composite" and terminate your program. You will get the Wrong Answer verdict if you ask more than 20 queries, or if you print an integer not from the range [2,<=100]. Also, you will get the Wrong Answer verdict if the printed answer isn't correct. You will get the Idleness Limit Exceeded verdict if you don't print anything (but you should) or if you forget about flushing the output (more info below).
After each query you should read one string from the input. It will be "yes" if the printed integer is a divisor of the hidden number, and "no" otherwise.
Up to 20 times you can ask a query — print an integer from interval [2,<=100] in one line. You have to both print the end-of-line character and flush the output. After flushing you should read a response from the input. In any moment you can print the answer "prime" or "composite" (without the quotes). After that, flush the output and terminate your program. To flush you can use (just after printing an integer and end-of-line): - fflush(stdout) in C++; - System.out.flush() in Java; - stdout.flush() in Python; - flush(output) in Pascal; - See the documentation for other languages. Hacking. To hack someone, as the input you should print the hidden number — one integer from the interval [2,<=100]. Of course, his/her solution won't be able to read the hidden number from the input.
[ "yes\nno\nyes\n", "no\nyes\nno\nno\nno\n" ]
[ "2\n80\n5\ncomposite\n", "58\n59\n78\n78\n2\nprime\n" ]
The hidden number in the first query is 30. In a table below you can see a better form of the provided example of the communication process. <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/ea790051c34ea7d2761cd9b096412ca7c647a173.png" style="max-width: 100.0%;max-height: 100.0%;"/> The hidden number is divisible by both 2 and 5. Thus, it must be composite. Note that it isn't necessary to know the exact value of the hidden number. In this test, the hidden number is 30. <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/35c6952617fa94ec3e0ea8e63aa1c3c49b3ba420.png" style="max-width: 100.0%;max-height: 100.0%;"/> 59 is a divisor of the hidden number. In the interval [2, 100] there is only one number with this divisor. The hidden number must be 59, which is prime. Note that the answer is known even after the second query and you could print it then and terminate. Though, it isn't forbidden to ask unnecessary queries (unless you exceed the limit of 20 queries).
750
[ { "input": "30", "output": "composite 4" }, { "input": "59", "output": "prime 15" }, { "input": "2", "output": "prime 16" }, { "input": "7", "output": "prime 16" }, { "input": "9", "output": "composite 3" }, { "input": "13", "output": "prime 15" }, { "input": "55", "output": "composite 6" }, { "input": "89", "output": "prime 15" }, { "input": "3", "output": "prime 16" }, { "input": "4", "output": "composite 2" }, { "input": "6", "output": "composite 4" }, { "input": "8", "output": "composite 2" }, { "input": "11", "output": "prime 15" }, { "input": "12", "output": "composite 2" }, { "input": "25", "output": "composite 4" }, { "input": "36", "output": "composite 2" }, { "input": "46", "output": "composite 10" }, { "input": "47", "output": "prime 15" }, { "input": "49", "output": "composite 5" }, { "input": "51", "output": "composite 8" }, { "input": "53", "output": "prime 15" }, { "input": "59", "output": "prime 15" }, { "input": "64", "output": "composite 2" }, { "input": "81", "output": "composite 3" }, { "input": "91", "output": "composite 7" }, { "input": "93", "output": "composite 12" }, { "input": "94", "output": "composite 16" }, { "input": "95", "output": "composite 9" }, { "input": "96", "output": "composite 2" }, { "input": "97", "output": "prime 15" }, { "input": "99", "output": "composite 3" }, { "input": "100", "output": "composite 2" }, { "input": "26", "output": "composite 7" }, { "input": "94", "output": "composite 16" }, { "input": "25", "output": "composite 4" }, { "input": "46", "output": "composite 10" }, { "input": "49", "output": "composite 5" }, { "input": "82", "output": "composite 14" }, { "input": "87", "output": "composite 11" }, { "input": "85", "output": "composite 8" }, { "input": "74", "output": "composite 13" }, { "input": "86", "output": "composite 15" }, { "input": "93", "output": "composite 12" }, { "input": "58", "output": "composite 11" }, { "input": "47", "output": "prime 15" }, { "input": "22", "output": "composite 6" }, { "input": "23", "output": "prime 15" }, { "input": "62", "output": "composite 12" }, { "input": "38", "output": "composite 9" }, { "input": "91", "output": "composite 7" }, { "input": "34", "output": "composite 8" }, { "input": "95", "output": "composite 9" }, { "input": "4", "output": "composite 2" }, { "input": "16", "output": "composite 2" }, { "input": "96", "output": "composite 2" }, { "input": "69", "output": "composite 10" }, { "input": "65", "output": "composite 7" }, { "input": "6", "output": "composite 4" }, { "input": "18", "output": "composite 4" } ]
1,633,699,181
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
6
93
20,172,800
from sys import stdout div = -1 for i in [2, 3, 5, 7]: print(i) stdout.flush() ans = input() if ans == 'yes': div = i break if div == -1: print("prime") else: secondDiv = -1 for i in [2, 3, 5, 7]: print(div * i) stdout.flush() ans = input() if ans == 'yes': secondDiv = i print("composite") break if secondDiv == -1: print("prime")
Title: Bear and Prime 100 Time Limit: None seconds Memory Limit: None megabytes Problem Description: This is an interactive problem. In the output section below you will see the information about flushing the output. Bear Limak thinks of some hidden number — an integer from interval [2,<=100]. Your task is to say if the hidden number is prime or composite. Integer *x*<=&gt;<=1 is called prime if it has exactly two distinct divisors, 1 and *x*. If integer *x*<=&gt;<=1 is not prime, it's called composite. You can ask up to 20 queries about divisors of the hidden number. In each query you should print an integer from interval [2,<=100]. The system will answer "yes" if your integer is a divisor of the hidden number. Otherwise, the answer will be "no". For example, if the hidden number is 14 then the system will answer "yes" only if you print 2, 7 or 14. When you are done asking queries, print "prime" or "composite" and terminate your program. You will get the Wrong Answer verdict if you ask more than 20 queries, or if you print an integer not from the range [2,<=100]. Also, you will get the Wrong Answer verdict if the printed answer isn't correct. You will get the Idleness Limit Exceeded verdict if you don't print anything (but you should) or if you forget about flushing the output (more info below). Input Specification: After each query you should read one string from the input. It will be "yes" if the printed integer is a divisor of the hidden number, and "no" otherwise. Output Specification: Up to 20 times you can ask a query — print an integer from interval [2,<=100] in one line. You have to both print the end-of-line character and flush the output. After flushing you should read a response from the input. In any moment you can print the answer "prime" or "composite" (without the quotes). After that, flush the output and terminate your program. To flush you can use (just after printing an integer and end-of-line): - fflush(stdout) in C++; - System.out.flush() in Java; - stdout.flush() in Python; - flush(output) in Pascal; - See the documentation for other languages. Hacking. To hack someone, as the input you should print the hidden number — one integer from the interval [2,<=100]. Of course, his/her solution won't be able to read the hidden number from the input. Demo Input: ['yes\nno\nyes\n', 'no\nyes\nno\nno\nno\n'] Demo Output: ['2\n80\n5\ncomposite\n', '58\n59\n78\n78\n2\nprime\n'] Note: The hidden number in the first query is 30. In a table below you can see a better form of the provided example of the communication process. <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/ea790051c34ea7d2761cd9b096412ca7c647a173.png" style="max-width: 100.0%;max-height: 100.0%;"/> The hidden number is divisible by both 2 and 5. Thus, it must be composite. Note that it isn't necessary to know the exact value of the hidden number. In this test, the hidden number is 30. <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/35c6952617fa94ec3e0ea8e63aa1c3c49b3ba420.png" style="max-width: 100.0%;max-height: 100.0%;"/> 59 is a divisor of the hidden number. In the interval [2, 100] there is only one number with this divisor. The hidden number must be 59, which is prime. Note that the answer is known even after the second query and you could print it then and terminate. Though, it isn't forbidden to ask unnecessary queries (unless you exceed the limit of 20 queries).
```python from sys import stdout div = -1 for i in [2, 3, 5, 7]: print(i) stdout.flush() ans = input() if ans == 'yes': div = i break if div == -1: print("prime") else: secondDiv = -1 for i in [2, 3, 5, 7]: print(div * i) stdout.flush() ans = input() if ans == 'yes': secondDiv = i print("composite") break if secondDiv == -1: print("prime") ```
0
732
A
Buy a Shovel
PROGRAMMING
800
[ "brute force", "constructive algorithms", "implementation", "math" ]
null
null
Polycarp urgently needs a shovel! He comes to the shop and chooses an appropriate one. The shovel that Policarp chooses is sold for *k* burles. Assume that there is an unlimited number of such shovels in the shop. In his pocket Polycarp has an unlimited number of "10-burle coins" and exactly one coin of *r* burles (1<=≤<=*r*<=≤<=9). What is the minimum number of shovels Polycarp has to buy so that he can pay for the purchase without any change? It is obvious that he can pay for 10 shovels without any change (by paying the requied amount of 10-burle coins and not using the coin of *r* burles). But perhaps he can buy fewer shovels and pay without any change. Note that Polycarp should buy at least one shovel.
The single line of input contains two integers *k* and *r* (1<=≤<=*k*<=≤<=1000, 1<=≤<=*r*<=≤<=9) — the price of one shovel and the denomination of the coin in Polycarp's pocket that is different from "10-burle coins". Remember that he has an unlimited number of coins in the denomination of 10, that is, Polycarp has enough money to buy any number of shovels.
Print the required minimum number of shovels Polycarp has to buy so that he can pay for them without any change.
[ "117 3\n", "237 7\n", "15 2\n" ]
[ "9\n", "1\n", "2\n" ]
In the first example Polycarp can buy 9 shovels and pay 9·117 = 1053 burles. Indeed, he can pay this sum by using 10-burle coins and one 3-burle coin. He can't buy fewer shovels without any change. In the second example it is enough for Polycarp to buy one shovel. In the third example Polycarp should buy two shovels and pay 2·15 = 30 burles. It is obvious that he can pay this sum without any change.
500
[ { "input": "117 3", "output": "9" }, { "input": "237 7", "output": "1" }, { "input": "15 2", "output": "2" }, { "input": "1 1", "output": "1" }, { "input": "1 9", "output": "9" }, { "input": "1000 3", "output": "1" }, { "input": "1000 1", "output": "1" }, { "input": "1000 9", "output": "1" }, { "input": "1 2", "output": "2" }, { "input": "999 9", "output": "1" }, { "input": "999 8", "output": "2" }, { "input": "105 6", "output": "2" }, { "input": "403 9", "output": "3" }, { "input": "546 4", "output": "4" }, { "input": "228 9", "output": "5" }, { "input": "57 2", "output": "6" }, { "input": "437 9", "output": "7" }, { "input": "997 6", "output": "8" }, { "input": "109 1", "output": "9" }, { "input": "998 9", "output": "5" }, { "input": "4 2", "output": "3" }, { "input": "9 3", "output": "7" }, { "input": "8 2", "output": "4" }, { "input": "1 3", "output": "3" }, { "input": "1 4", "output": "4" }, { "input": "1 5", "output": "5" }, { "input": "1 6", "output": "6" }, { "input": "1 7", "output": "7" }, { "input": "1 8", "output": "8" }, { "input": "100 3", "output": "1" }, { "input": "1000 2", "output": "1" }, { "input": "1000 4", "output": "1" }, { "input": "1000 5", "output": "1" }, { "input": "1000 6", "output": "1" }, { "input": "1000 7", "output": "1" }, { "input": "1000 8", "output": "1" }, { "input": "23 4", "output": "8" }, { "input": "33 1", "output": "7" }, { "input": "33 2", "output": "4" }, { "input": "666 5", "output": "5" }, { "input": "2 3", "output": "5" }, { "input": "5 5", "output": "1" }, { "input": "3 6", "output": "2" }, { "input": "12 4", "output": "2" }, { "input": "15 5", "output": "1" }, { "input": "2 5", "output": "5" }, { "input": "25 5", "output": "1" }, { "input": "2 9", "output": "5" }, { "input": "6 7", "output": "5" }, { "input": "8 9", "output": "5" }, { "input": "2 7", "output": "5" }, { "input": "4 7", "output": "5" }, { "input": "2 1", "output": "5" }, { "input": "261 1", "output": "1" } ]
1,690,810,475
2,147,483,647
Python 3
OK
TESTS
54
46
0
a=list(map(int,input().split())) for i in range(1,10): if (a[0]*i)%10==a[1] or (a[0]*i)%10==0: print(i) break
Title: Buy a Shovel Time Limit: None seconds Memory Limit: None megabytes Problem Description: Polycarp urgently needs a shovel! He comes to the shop and chooses an appropriate one. The shovel that Policarp chooses is sold for *k* burles. Assume that there is an unlimited number of such shovels in the shop. In his pocket Polycarp has an unlimited number of "10-burle coins" and exactly one coin of *r* burles (1<=≤<=*r*<=≤<=9). What is the minimum number of shovels Polycarp has to buy so that he can pay for the purchase without any change? It is obvious that he can pay for 10 shovels without any change (by paying the requied amount of 10-burle coins and not using the coin of *r* burles). But perhaps he can buy fewer shovels and pay without any change. Note that Polycarp should buy at least one shovel. Input Specification: The single line of input contains two integers *k* and *r* (1<=≤<=*k*<=≤<=1000, 1<=≤<=*r*<=≤<=9) — the price of one shovel and the denomination of the coin in Polycarp's pocket that is different from "10-burle coins". Remember that he has an unlimited number of coins in the denomination of 10, that is, Polycarp has enough money to buy any number of shovels. Output Specification: Print the required minimum number of shovels Polycarp has to buy so that he can pay for them without any change. Demo Input: ['117 3\n', '237 7\n', '15 2\n'] Demo Output: ['9\n', '1\n', '2\n'] Note: In the first example Polycarp can buy 9 shovels and pay 9·117 = 1053 burles. Indeed, he can pay this sum by using 10-burle coins and one 3-burle coin. He can't buy fewer shovels without any change. In the second example it is enough for Polycarp to buy one shovel. In the third example Polycarp should buy two shovels and pay 2·15 = 30 burles. It is obvious that he can pay this sum without any change.
```python a=list(map(int,input().split())) for i in range(1,10): if (a[0]*i)%10==a[1] or (a[0]*i)%10==0: print(i) break ```
3
49
A
Sleuth
PROGRAMMING
800
[ "implementation" ]
A. Sleuth
2
256
Vasya plays the sleuth with his friends. The rules of the game are as follows: those who play for the first time, that is Vasya is the sleuth, he should investigate a "crime" and find out what is happening. He can ask any questions whatsoever that can be answered with "Yes" or "No". All the rest agree beforehand to answer the questions like that: if the question’s last letter is a vowel, they answer "Yes" and if the last letter is a consonant, they answer "No". Of course, the sleuth knows nothing about it and his task is to understand that. Unfortunately, Vasya is not very smart. After 5 hours of endless stupid questions everybody except Vasya got bored. That’s why Vasya’s friends ask you to write a program that would give answers instead of them. The English alphabet vowels are: A, E, I, O, U, Y The English alphabet consonants are: B, C, D, F, G, H, J, K, L, M, N, P, Q, R, S, T, V, W, X, Z
The single line contains a question represented by a non-empty line consisting of large and small Latin letters, spaces and a question mark. The line length does not exceed 100. It is guaranteed that the question mark occurs exactly once in the line — as the last symbol and that the line contains at least one letter.
Print answer for the question in a single line: YES if the answer is "Yes", NO if the answer is "No". Remember that in the reply to the question the last letter, not the last character counts. I. e. the spaces and the question mark do not count as letters.
[ "Is it a melon?\n", "Is it an apple?\n", "Is it a banana ?\n", "Is it an apple and a banana simultaneouSLY?\n" ]
[ "NO\n", "YES\n", "YES\n", "YES\n" ]
none
500
[ { "input": "Is it a melon?", "output": "NO" }, { "input": "Is it an apple?", "output": "YES" }, { "input": " Is it a banana ?", "output": "YES" }, { "input": "Is it an apple and a banana simultaneouSLY?", "output": "YES" }, { "input": "oHtSbDwzHb?", "output": "NO" }, { "input": "sZecYdUvZHrXx?", "output": "NO" }, { "input": "uMtXK?", "output": "NO" }, { "input": "U?", "output": "YES" }, { "input": "aqFDkCUKeHMyvZFcAyWlMUSQTFomtaWjoKLVyxLCw vcufPBFbaljOuHWiDCROYTcmbgzbaqHXKPOYEbuEtRqqoxBbOETCsQzhw?", "output": "NO" }, { "input": "dJcNqQiFXzcbsj fItCpBLyXOnrSBPebwyFHlxUJHqCUzzCmcAvMiKL NunwOXnKeIxUZmBVwiCUfPkjRAkTPbkYCmwRRnDSLaz?", "output": "NO" }, { "input": "gxzXbdcAQMuFKuuiPohtMgeypr wpDIoDSyOYTdvylcg SoEBZjnMHHYZGEqKgCgBeTbyTwyGuPZxkxsnSczotBdYyfcQsOVDVC?", "output": "NO" }, { "input": "FQXBisXaJFMiHFQlXjixBDMaQuIbyqSBKGsBfTmBKCjszlGVZxEOqYYqRTUkGpSDDAoOXyXcQbHcPaegeOUBNeSD JiKOdECPOF?", "output": "NO" }, { "input": "YhCuZnrWUBEed?", "output": "NO" }, { "input": "hh?", "output": "NO" }, { "input": "whU?", "output": "YES" }, { "input": "fgwg?", "output": "NO" }, { "input": "GlEmEPKrYcOnBNJUIFjszWUyVdvWw DGDjoCMtRJUburkPToCyDrOtMr?", "output": "NO" }, { "input": "n?", "output": "NO" }, { "input": "BueDOlxgzeNlxrzRrMbKiQdmGujEKmGxclvaPpTuHmTqBp?", "output": "NO" }, { "input": "iehvZNQXDGCuVmJPOEysLyUryTdfaIxIuTzTadDbqRQGoCLXkxnyfWSGoLXebNnQQNTqAQJebbyYvHOfpUnXeWdjx?", "output": "NO" }, { "input": " J ?", "output": "NO" }, { "input": " j ?", "output": "NO" }, { "input": " o ?", "output": "YES" }, { "input": " T ?", "output": "NO" }, { "input": " q ?", "output": "NO" }, { "input": " j ?", "output": "NO" }, { "input": " c ?", "output": "NO" }, { "input": " B ?", "output": "NO" }, { "input": "LuhxDHVwMPTtUIUMIQTuQETgXCOQPsfdFlyHvpfOVedjUTpGLAZGOHloIjJJtOLAlHPivzA?", "output": "YES" }, { "input": "wmztmzFfwbGyOmNHENUFMTsFEMWYA?", "output": "YES" }, { "input": "wGsfZCSwN PEUhNUrLfABrxA?", "output": "YES" }, { "input": "mCDHENXjYbgMdBimAdPnewaHfpGWowjWrVAdvWczjw iDcUbyzMsmsnwbviiKiAyGVA?", "output": "YES" }, { "input": "ARIWnwqFqxsQXsXXzHqvFjxOCttAGPUzDtWzsenPYdNXuFOIUGYZsLLK IaoxiyjBBRThoelwdPTkuCQfcBLUEJpCPIrVZlvUWA?", "output": "YES" }, { "input": " PslvVpgpN BXkMFBEVXsyZFIQbBEFxGkYTeXKrOdcmhbiTUatYRUoYAayrchqbksswIlfIjerZPqptvCGnMUhyrQSvwltRhFzA?", "output": "YES" }, { "input": "HpBkttwSjBXDmyleGiRWNUMPaAIE uzTrp KJDzaUiCdsMYOoWKHoUhWUoecCPmACymMUUbGav UMRpCytPETwNFAObZJA?", "output": "YES" } ]
1,642,017,290
2,147,483,647
Python 3
OK
TESTS
35
92
0
s = input() i=len(s)-2 while s[i]==' ': i-=1 gl = ['e','y','u','i','a','o','E','Y','U','I','O','A'] if s[i] in gl: print('YES') else: print('NO')
Title: Sleuth Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Vasya plays the sleuth with his friends. The rules of the game are as follows: those who play for the first time, that is Vasya is the sleuth, he should investigate a "crime" and find out what is happening. He can ask any questions whatsoever that can be answered with "Yes" or "No". All the rest agree beforehand to answer the questions like that: if the question’s last letter is a vowel, they answer "Yes" and if the last letter is a consonant, they answer "No". Of course, the sleuth knows nothing about it and his task is to understand that. Unfortunately, Vasya is not very smart. After 5 hours of endless stupid questions everybody except Vasya got bored. That’s why Vasya’s friends ask you to write a program that would give answers instead of them. The English alphabet vowels are: A, E, I, O, U, Y The English alphabet consonants are: B, C, D, F, G, H, J, K, L, M, N, P, Q, R, S, T, V, W, X, Z Input Specification: The single line contains a question represented by a non-empty line consisting of large and small Latin letters, spaces and a question mark. The line length does not exceed 100. It is guaranteed that the question mark occurs exactly once in the line — as the last symbol and that the line contains at least one letter. Output Specification: Print answer for the question in a single line: YES if the answer is "Yes", NO if the answer is "No". Remember that in the reply to the question the last letter, not the last character counts. I. e. the spaces and the question mark do not count as letters. Demo Input: ['Is it a melon?\n', 'Is it an apple?\n', 'Is it a banana ?\n', 'Is it an apple and a banana simultaneouSLY?\n'] Demo Output: ['NO\n', 'YES\n', 'YES\n', 'YES\n'] Note: none
```python s = input() i=len(s)-2 while s[i]==' ': i-=1 gl = ['e','y','u','i','a','o','E','Y','U','I','O','A'] if s[i] in gl: print('YES') else: print('NO') ```
3.977
320
A
Magic Numbers
PROGRAMMING
900
[ "brute force", "greedy" ]
null
null
A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not. You're given a number. Determine if it is a magic number or not.
The first line of input contains an integer *n*, (1<=≤<=*n*<=≤<=109). This number doesn't contain leading zeros.
Print "YES" if *n* is a magic number or print "NO" if it's not.
[ "114114\n", "1111\n", "441231\n" ]
[ "YES\n", "YES\n", "NO\n" ]
none
500
[ { "input": "114114", "output": "YES" }, { "input": "1111", "output": "YES" }, { "input": "441231", "output": "NO" }, { "input": "1", "output": "YES" }, { "input": "14", "output": "YES" }, { "input": "114", "output": "YES" }, { "input": "9", "output": "NO" }, { "input": "414", "output": "NO" }, { "input": "1000000000", "output": "NO" }, { "input": "144144144", "output": "YES" }, { "input": "1444", "output": "NO" }, { "input": "11", "output": "YES" }, { "input": "141414141", "output": "YES" }, { "input": "11110111", "output": "NO" }, { "input": "114114144", "output": "YES" }, { "input": "444", "output": "NO" }, { "input": "9999", "output": "NO" }, { "input": "111444", "output": "NO" }, { "input": "11114", "output": "YES" }, { "input": "41111", "output": "NO" }, { "input": "114414441", "output": "NO" }, { "input": "144414441", "output": "NO" }, { "input": "144244144", "output": "NO" }, { "input": "111111111", "output": "YES" }, { "input": "144444444", "output": "NO" }, { "input": "444444444", "output": "NO" }, { "input": "141441441", "output": "YES" }, { "input": "441", "output": "NO" }, { "input": "15", "output": "NO" }, { "input": "14444", "output": "NO" }, { "input": "11444", "output": "NO" }, { "input": "144", "output": "YES" }, { "input": "1414414", "output": "YES" }, { "input": "141444", "output": "NO" }, { "input": "14144", "output": "YES" }, { "input": "4", "output": "NO" }, { "input": "1144", "output": "YES" }, { "input": "141111444", "output": "NO" }, { "input": "14414414", "output": "YES" }, { "input": "141414144", "output": "YES" }, { "input": "1414", "output": "YES" }, { "input": "1441", "output": "YES" }, { "input": "12", "output": "NO" }, { "input": "144144141", "output": "YES" }, { "input": "144144", "output": "YES" }, { "input": "14414411", "output": "YES" }, { "input": "14414", "output": "YES" } ]
1,677,604,456
2,147,483,647
PyPy 3-64
OK
TESTS
47
124
0
n=input() ans=True c=0 while c<=len(n)-1: if n[c]!="1": ans=False print("NO") break else: if c<=len(n)-3: if n[c:c+3]=="144": c+=3 elif n[c:c+2]=="14": c+=2 else: c+=1 elif c<=len(n)-2: if n[c:c+2]=="14": c+=2 else: c+=1 else: c+=1 if ans: print("YES")
Title: Magic Numbers Time Limit: None seconds Memory Limit: None megabytes Problem Description: A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not. You're given a number. Determine if it is a magic number or not. Input Specification: The first line of input contains an integer *n*, (1<=≤<=*n*<=≤<=109). This number doesn't contain leading zeros. Output Specification: Print "YES" if *n* is a magic number or print "NO" if it's not. Demo Input: ['114114\n', '1111\n', '441231\n'] Demo Output: ['YES\n', 'YES\n', 'NO\n'] Note: none
```python n=input() ans=True c=0 while c<=len(n)-1: if n[c]!="1": ans=False print("NO") break else: if c<=len(n)-3: if n[c:c+3]=="144": c+=3 elif n[c:c+2]=="14": c+=2 else: c+=1 elif c<=len(n)-2: if n[c:c+2]=="14": c+=2 else: c+=1 else: c+=1 if ans: print("YES") ```
3
462
A
Appleman and Easy Task
PROGRAMMING
1,000
[ "brute force", "implementation" ]
null
null
Toastman came up with a very easy task. He gives it to Appleman, but Appleman doesn't know how to solve it. Can you help him? Given a *n*<=×<=*n* checkerboard. Each cell of the board has either character 'x', or character 'o'. Is it true that each cell of the board has even number of adjacent cells with 'o'? Two cells of the board are adjacent if they share a side.
The first line contains an integer *n* (1<=≤<=*n*<=≤<=100). Then *n* lines follow containing the description of the checkerboard. Each of them contains *n* characters (either 'x' or 'o') without spaces.
Print "YES" or "NO" (without the quotes) depending on the answer to the problem.
[ "3\nxxo\nxox\noxx\n", "4\nxxxo\nxoxo\noxox\nxxxx\n" ]
[ "YES\n", "NO\n" ]
none
500
[ { "input": "3\nxxo\nxox\noxx", "output": "YES" }, { "input": "4\nxxxo\nxoxo\noxox\nxxxx", "output": "NO" }, { "input": "1\no", "output": "YES" }, { "input": "2\nox\nxo", "output": "YES" }, { "input": "2\nxx\nxo", "output": "NO" }, { "input": "3\nooo\noxo\nxoo", "output": "NO" }, { "input": "3\nxxx\nxxo\nxxo", "output": "NO" }, { "input": "4\nxooo\nooxo\noxoo\nooox", "output": "YES" }, { "input": "4\noooo\noxxo\nxoxo\noooo", "output": "NO" }, { "input": "5\noxoxo\nxxxxx\noxoxo\nxxxxx\noxoxo", "output": "YES" }, { "input": "5\nxxxox\nxxxxo\nxoxox\noxoxx\nxoxxx", "output": "NO" }, { "input": "10\nxoxooooooo\noxxoxxxxxo\nxxooxoooxo\noooxxoxoxo\noxxxooooxo\noxooooxxxo\noxoxoxxooo\noxoooxooxx\noxxxxxoxxo\noooooooxox", "output": "YES" }, { "input": "10\nxxxxxxxoox\nxooxxooooo\noxoooxxooo\nxoxxxxxxxx\nxxoxooxxox\nooxoxxooox\nooxxxxxooo\nxxxxoxooox\nxoxxooxxxx\noooooxxoxo", "output": "NO" }, { "input": "19\noxoxoxoxooxoooxxoox\nxxxxxxxxoxxoxoooooo\noxoxoxooxxxooxxxooo\nxxoxxxooxooxxxoxxox\noxoxooxxxooooxxoxox\nxxxoooxoxxoxxoxxxoo\noxooxxxoooooxxoooxo\nxxooxooxoxxoxxoxxoo\noxxxxooooxxxooooxxx\nooxooxoxxoxxoxooxoo\nxxxooooxxxooooxoxox\noooxoxooxxoxooxooxx\nxxoooxxxooooxxoooxo\nooxxxooxoxooxooxxxx\nxoxoxxooxoxxxooxoxo\nxoxxoxoxooxooxxxxxx\noooxxxooxxxooxoxoxo\nxoooooxoxooxxxxxxxo\nxooxxoooxxoxoxoxoxx", "output": "NO" }, { "input": "12\nxxooxxoxxxoo\nxxoooxoxoxoo\nooxoxoxxooxx\nooxxooooxoxo\nxxxxxxxxoxxx\noxooooxxxooo\noxxoxoxoooxx\nxxxxxxxooxox\noxoooooxoxxx\nxxooxxoxxoxx\noxxxxxxxooxx\nooxoxooxxooo", "output": "NO" }, { "input": "2\noo\nxx", "output": "NO" } ]
1,518,484,689
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
46
5,632,000
n = int(input()) board = ['x'*(n+2)]+['x'+input()+'x' for _ in range(n)]+['x'*(n+2)] for i in range(1,n+1): for j in range(1,n+1): oneighbors = 0 if board[i-1][j] == 'o': oneighbors += 1 if board[i+1][j] == 'o': oneighbors += 1 if board[i][j-1] == 'o': oneighbors += 1 if board[i][j+1] == 'o': oneighbors += 1 if (oneighbors % 2) == 1: good = False if good: print('YES') else: print('NO')
Title: Appleman and Easy Task Time Limit: None seconds Memory Limit: None megabytes Problem Description: Toastman came up with a very easy task. He gives it to Appleman, but Appleman doesn't know how to solve it. Can you help him? Given a *n*<=×<=*n* checkerboard. Each cell of the board has either character 'x', or character 'o'. Is it true that each cell of the board has even number of adjacent cells with 'o'? Two cells of the board are adjacent if they share a side. Input Specification: The first line contains an integer *n* (1<=≤<=*n*<=≤<=100). Then *n* lines follow containing the description of the checkerboard. Each of them contains *n* characters (either 'x' or 'o') without spaces. Output Specification: Print "YES" or "NO" (without the quotes) depending on the answer to the problem. Demo Input: ['3\nxxo\nxox\noxx\n', '4\nxxxo\nxoxo\noxox\nxxxx\n'] Demo Output: ['YES\n', 'NO\n'] Note: none
```python n = int(input()) board = ['x'*(n+2)]+['x'+input()+'x' for _ in range(n)]+['x'*(n+2)] for i in range(1,n+1): for j in range(1,n+1): oneighbors = 0 if board[i-1][j] == 'o': oneighbors += 1 if board[i+1][j] == 'o': oneighbors += 1 if board[i][j-1] == 'o': oneighbors += 1 if board[i][j+1] == 'o': oneighbors += 1 if (oneighbors % 2) == 1: good = False if good: print('YES') else: print('NO') ```
-1
8
A
Train and Peter
PROGRAMMING
1,200
[ "strings" ]
A. Train and Peter
1
64
Peter likes to travel by train. He likes it so much that on the train he falls asleep. Once in summer Peter was going by train from city A to city B, and as usual, was sleeping. Then he woke up, started to look through the window and noticed that every railway station has a flag of a particular colour. The boy started to memorize the order of the flags' colours that he had seen. But soon he fell asleep again. Unfortunately, he didn't sleep long, he woke up and went on memorizing the colours. Then he fell asleep again, and that time he slept till the end of the journey. At the station he told his parents about what he was doing, and wrote two sequences of the colours that he had seen before and after his sleep, respectively. Peter's parents know that their son likes to fantasize. They give you the list of the flags' colours at the stations that the train passes sequentially on the way from A to B, and ask you to find out if Peter could see those sequences on the way from A to B, or from B to A. Remember, please, that Peter had two periods of wakefulness. Peter's parents put lowercase Latin letters for colours. The same letter stands for the same colour, different letters — for different colours.
The input data contains three lines. The first line contains a non-empty string, whose length does not exceed 105, the string consists of lowercase Latin letters — the flags' colours at the stations on the way from A to B. On the way from B to A the train passes the same stations, but in reverse order. The second line contains the sequence, written by Peter during the first period of wakefulness. The third line contains the sequence, written during the second period of wakefulness. Both sequences are non-empty, consist of lowercase Latin letters, and the length of each does not exceed 100 letters. Each of the sequences is written in chronological order.
Output one of the four words without inverted commas: - «forward» — if Peter could see such sequences only on the way from A to B; - «backward» — if Peter could see such sequences on the way from B to A; - «both» — if Peter could see such sequences both on the way from A to B, and on the way from B to A; - «fantasy» — if Peter could not see such sequences.
[ "atob\na\nb\n", "aaacaaa\naca\naa\n" ]
[ "forward\n", "both\n" ]
It is assumed that the train moves all the time, so one flag cannot be seen twice. There are no flags at stations A and B.
0
[ { "input": "atob\na\nb", "output": "forward" }, { "input": "aaacaaa\naca\naa", "output": "both" }, { "input": "aaa\naa\naa", "output": "fantasy" }, { "input": "astalavista\nastla\nlavista", "output": "fantasy" }, { "input": "abacabadabacaba\nabacaba\nabacaba", "output": "both" }, { "input": "a\na\na", "output": "fantasy" }, { "input": "ab\nb\na", "output": "backward" }, { "input": "aaa\naaaa\naaaa", "output": "fantasy" }, { "input": "bbabbbbababbaabaabaa\nabb\nbaab", "output": "forward" }, { "input": "bbbbbbbbbbbbbbbbbbbbbbbbb\nbbbb\nbbbbb", "output": "both" }, { "input": "babaabababaaaababaabababaabababababababbababbbabbaabababaababbaabbababaababaaabababaabbaababaaababaa\nabaabababaa\nabaabbaa", "output": "forward" }, { "input": "bbbbbbbbbbbbbbbbbbbbbbbbb\nbbbb\nbbbbb", "output": "both" }, { "input": "aababaaababaabbaabababaaababaabababbaabbabaabababaabbabbbababbababababababaabababaababaaaabababaabab\nabaabababaa\nabaabbaa", "output": "backward" }, { "input": "aaaa\naaa\naa", "output": "fantasy" }, { "input": "zzzz\nzz\nzzz", "output": "fantasy" }, { "input": "zzzz\nzzzz\nzzzz", "output": "fantasy" }, { "input": "zzzz\nzz\nzz", "output": "both" }, { "input": "aabaa\naab\nbaa", "output": "fantasy" }, { "input": "aabaab\naba\nab", "output": "forward" }, { "input": "aab\nb\naa", "output": "backward" }, { "input": "abacaba\naca\nba", "output": "both" } ]
1,654,312,925
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
0
30
0
a=input() b=input() c=input() d=b+c e=c+b if d in a and e in a:print("both") if d not in a and e not in a:print("fantasy") if d in a and e not in a:print("forward") if d not in a and e in a:print("backward")
Title: Train and Peter Time Limit: 1 seconds Memory Limit: 64 megabytes Problem Description: Peter likes to travel by train. He likes it so much that on the train he falls asleep. Once in summer Peter was going by train from city A to city B, and as usual, was sleeping. Then he woke up, started to look through the window and noticed that every railway station has a flag of a particular colour. The boy started to memorize the order of the flags' colours that he had seen. But soon he fell asleep again. Unfortunately, he didn't sleep long, he woke up and went on memorizing the colours. Then he fell asleep again, and that time he slept till the end of the journey. At the station he told his parents about what he was doing, and wrote two sequences of the colours that he had seen before and after his sleep, respectively. Peter's parents know that their son likes to fantasize. They give you the list of the flags' colours at the stations that the train passes sequentially on the way from A to B, and ask you to find out if Peter could see those sequences on the way from A to B, or from B to A. Remember, please, that Peter had two periods of wakefulness. Peter's parents put lowercase Latin letters for colours. The same letter stands for the same colour, different letters — for different colours. Input Specification: The input data contains three lines. The first line contains a non-empty string, whose length does not exceed 105, the string consists of lowercase Latin letters — the flags' colours at the stations on the way from A to B. On the way from B to A the train passes the same stations, but in reverse order. The second line contains the sequence, written by Peter during the first period of wakefulness. The third line contains the sequence, written during the second period of wakefulness. Both sequences are non-empty, consist of lowercase Latin letters, and the length of each does not exceed 100 letters. Each of the sequences is written in chronological order. Output Specification: Output one of the four words without inverted commas: - «forward» — if Peter could see such sequences only on the way from A to B; - «backward» — if Peter could see such sequences on the way from B to A; - «both» — if Peter could see such sequences both on the way from A to B, and on the way from B to A; - «fantasy» — if Peter could not see such sequences. Demo Input: ['atob\na\nb\n', 'aaacaaa\naca\naa\n'] Demo Output: ['forward\n', 'both\n'] Note: It is assumed that the train moves all the time, so one flag cannot be seen twice. There are no flags at stations A and B.
```python a=input() b=input() c=input() d=b+c e=c+b if d in a and e in a:print("both") if d not in a and e not in a:print("fantasy") if d in a and e not in a:print("forward") if d not in a and e in a:print("backward") ```
0
879
A
Borya's Diagnosis
PROGRAMMING
900
[ "implementation" ]
null
null
It seems that Borya is seriously sick. He is going visit *n* doctors to find out the exact diagnosis. Each of the doctors needs the information about all previous visits, so Borya has to visit them in the prescribed order (i.e. Borya should first visit doctor 1, then doctor 2, then doctor 3 and so on). Borya will get the information about his health from the last doctor. Doctors have a strange working schedule. The doctor *i* goes to work on the *s**i*-th day and works every *d**i* day. So, he works on days *s**i*,<=*s**i*<=+<=*d**i*,<=*s**i*<=+<=2*d**i*,<=.... The doctor's appointment takes quite a long time, so Borya can not see more than one doctor per day. What is the minimum time he needs to visit all doctors?
First line contains an integer *n* — number of doctors (1<=≤<=*n*<=≤<=1000). Next *n* lines contain two numbers *s**i* and *d**i* (1<=≤<=*s**i*,<=*d**i*<=≤<=1000).
Output a single integer — the minimum day at which Borya can visit the last doctor.
[ "3\n2 2\n1 2\n2 2\n", "2\n10 1\n6 5\n" ]
[ "4\n", "11\n" ]
In the first sample case, Borya can visit all doctors on days 2, 3 and 4. In the second sample case, Borya can visit all doctors on days 10 and 11.
500
[ { "input": "3\n2 2\n1 2\n2 2", "output": "4" }, { "input": "2\n10 1\n6 5", "output": "11" }, { "input": "3\n6 10\n3 3\n8 2", "output": "10" }, { "input": "4\n4 8\n10 10\n4 2\n8 2", "output": "14" }, { "input": "5\n7 1\n5 1\n6 1\n1 6\n6 8", "output": "14" }, { "input": "6\n1 3\n2 5\n4 7\n7 5\n6 8\n8 8", "output": "16" }, { "input": "10\n4 10\n8 7\n6 5\n2 1\n2 3\n8 8\n2 4\n2 2\n6 7\n7 9", "output": "34" }, { "input": "1\n1 1", "output": "1" }, { "input": "1\n1000 1000", "output": "1000" }, { "input": "42\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2", "output": "83" }, { "input": "2\n5 5\n5 1", "output": "6" }, { "input": "2\n5 5\n5 5", "output": "10" }, { "input": "2\n1 1\n1 1", "output": "2" }, { "input": "2\n1 6\n7 1", "output": "7" }, { "input": "2\n4 3\n4 5", "output": "9" }, { "input": "2\n1 2\n1 3", "output": "4" }, { "input": "3\n2 3\n5 1\n2 1", "output": "6" }, { "input": "2\n2 1\n6 3", "output": "6" }, { "input": "3\n10 1\n4 4\n12 1", "output": "13" }, { "input": "2\n2 2\n10 2", "output": "10" }, { "input": "2\n1 1\n1000 2", "output": "1000" }, { "input": "14\n1000 1\n1000 1000\n1000 1000\n1000 1000\n1000 1000\n1000 1000\n1000 1000\n1000 1000\n1000 1000\n1000 1000\n1000 1000\n1000 1000\n1000 1000\n1 1", "output": "13001" }, { "input": "2\n2 4\n2 1", "output": "3" }, { "input": "3\n1 100\n100 3\n200 1", "output": "200" }, { "input": "7\n1000 1000\n1000 1000\n1000 1000\n1000 1000\n1000 1000\n1000 1000\n1 1", "output": "6001" }, { "input": "2\n5 5\n15 5", "output": "15" }, { "input": "2\n2 2\n2 4", "output": "6" }, { "input": "2\n1 1\n10 1", "output": "10" }, { "input": "2\n10 1\n100 1", "output": "100" }, { "input": "15\n1000 1000\n1000 1000\n1000 1000\n1000 1000\n1000 1000\n1000 1000\n1000 1000\n1000 1000\n1000 1000\n1000 1000\n1000 1000\n1000 1000\n1000 1000\n1000 1000\n1 1", "output": "14001" }, { "input": "3\n2 1\n1 3\n4 7", "output": "11" }, { "input": "2\n5 5\n100 5", "output": "100" }, { "input": "2\n1 10\n2 30", "output": "2" }, { "input": "4\n2 2\n2 2\n2 2\n2 2", "output": "8" }, { "input": "1\n10 10", "output": "10" } ]
1,612,988,954
2,147,483,647
PyPy 3
OK
TESTS
51
140
1,433,600
n = int(input()) now = 0 for i in range(n): s, d = map(int, input().split()) now = max(now + 1, s) now = (now + d - 1 - s) // d * d + s print(now)
Title: Borya's Diagnosis Time Limit: None seconds Memory Limit: None megabytes Problem Description: It seems that Borya is seriously sick. He is going visit *n* doctors to find out the exact diagnosis. Each of the doctors needs the information about all previous visits, so Borya has to visit them in the prescribed order (i.e. Borya should first visit doctor 1, then doctor 2, then doctor 3 and so on). Borya will get the information about his health from the last doctor. Doctors have a strange working schedule. The doctor *i* goes to work on the *s**i*-th day and works every *d**i* day. So, he works on days *s**i*,<=*s**i*<=+<=*d**i*,<=*s**i*<=+<=2*d**i*,<=.... The doctor's appointment takes quite a long time, so Borya can not see more than one doctor per day. What is the minimum time he needs to visit all doctors? Input Specification: First line contains an integer *n* — number of doctors (1<=≤<=*n*<=≤<=1000). Next *n* lines contain two numbers *s**i* and *d**i* (1<=≤<=*s**i*,<=*d**i*<=≤<=1000). Output Specification: Output a single integer — the minimum day at which Borya can visit the last doctor. Demo Input: ['3\n2 2\n1 2\n2 2\n', '2\n10 1\n6 5\n'] Demo Output: ['4\n', '11\n'] Note: In the first sample case, Borya can visit all doctors on days 2, 3 and 4. In the second sample case, Borya can visit all doctors on days 10 and 11.
```python n = int(input()) now = 0 for i in range(n): s, d = map(int, input().split()) now = max(now + 1, s) now = (now + d - 1 - s) // d * d + s print(now) ```
3
148
A
Insomnia cure
PROGRAMMING
800
[ "constructive algorithms", "implementation", "math" ]
null
null
«One dragon. Two dragon. Three dragon», — the princess was counting. She had trouble falling asleep, and she got bored of counting lambs when she was nine. However, just counting dragons was boring as well, so she entertained herself at best she could. Tonight she imagined that all dragons were here to steal her, and she was fighting them off. Every *k*-th dragon got punched in the face with a frying pan. Every *l*-th dragon got his tail shut into the balcony door. Every *m*-th dragon got his paws trampled with sharp heels. Finally, she threatened every *n*-th dragon to call her mom, and he withdrew in panic. How many imaginary dragons suffered moral or physical damage tonight, if the princess counted a total of *d* dragons?
Input data contains integer numbers *k*,<=*l*,<=*m*,<=*n* and *d*, each number in a separate line (1<=≤<=*k*,<=*l*,<=*m*,<=*n*<=≤<=10, 1<=≤<=*d*<=≤<=105).
Output the number of damaged dragons.
[ "1\n2\n3\n4\n12\n", "2\n3\n4\n5\n24\n" ]
[ "12\n", "17\n" ]
In the first case every first dragon got punched with a frying pan. Some of the dragons suffered from other reasons as well, but the pan alone would be enough. In the second case dragons 1, 7, 11, 13, 17, 19 and 23 escaped unharmed.
1,000
[ { "input": "1\n2\n3\n4\n12", "output": "12" }, { "input": "2\n3\n4\n5\n24", "output": "17" }, { "input": "1\n1\n1\n1\n100000", "output": "100000" }, { "input": "10\n9\n8\n7\n6", "output": "0" }, { "input": "8\n4\n4\n3\n65437", "output": "32718" }, { "input": "8\n4\n1\n10\n59392", "output": "59392" }, { "input": "4\n1\n8\n7\n44835", "output": "44835" }, { "input": "6\n1\n7\n2\n62982", "output": "62982" }, { "input": "2\n7\n4\n9\n56937", "output": "35246" }, { "input": "2\n9\n8\n1\n75083", "output": "75083" }, { "input": "8\n7\n7\n6\n69038", "output": "24656" }, { "input": "4\n4\n2\n3\n54481", "output": "36320" }, { "input": "6\n4\n9\n8\n72628", "output": "28244" }, { "input": "9\n7\n8\n10\n42357", "output": "16540" }, { "input": "5\n6\n4\n3\n60504", "output": "36302" }, { "input": "7\n2\n3\n8\n21754", "output": "15539" }, { "input": "1\n2\n10\n4\n39901", "output": "39901" }, { "input": "3\n4\n7\n1\n58048", "output": "58048" }, { "input": "9\n10\n4\n6\n52003", "output": "21956" }, { "input": "5\n10\n9\n3\n70149", "output": "32736" }, { "input": "5\n5\n5\n10\n55592", "output": "11118" }, { "input": "1\n5\n2\n6\n49547", "output": "49547" }, { "input": "3\n7\n7\n7\n84046", "output": "36019" }, { "input": "10\n2\n1\n8\n63537", "output": "63537" }, { "input": "7\n2\n10\n5\n81684", "output": "53678" }, { "input": "7\n1\n6\n8\n99831", "output": "99831" }, { "input": "3\n9\n3\n3\n61082", "output": "20360" }, { "input": "5\n5\n8\n9\n79228", "output": "29931" }, { "input": "1\n5\n5\n6\n89535", "output": "89535" }, { "input": "5\n5\n2\n1\n7682", "output": "7682" }, { "input": "7\n4\n8\n8\n25829", "output": "9224" }, { "input": "3\n4\n3\n3\n87079", "output": "43539" }, { "input": "5\n8\n4\n9\n5226", "output": "2438" }, { "input": "4\n9\n6\n6\n1070", "output": "415" }, { "input": "10\n10\n10\n10\n100000", "output": "10000" }, { "input": "1\n1\n1\n1\n1", "output": "1" }, { "input": "10\n10\n10\n10\n1", "output": "0" }, { "input": "10\n10\n1\n10\n10", "output": "10" }, { "input": "10\n10\n1\n10\n100", "output": "100" }, { "input": "2\n2\n2\n2\n1", "output": "0" } ]
1,687,533,031
2,147,483,647
Python 3
OK
TESTS
40
92
0
k,l,m,n,d=[int(input()) for i in range(5)] c=0 for i in range(1,d+1): if i%k==0 or i%l==0 or i%m==0 or i%n==0: c+=1 print(c)
Title: Insomnia cure Time Limit: None seconds Memory Limit: None megabytes Problem Description: «One dragon. Two dragon. Three dragon», — the princess was counting. She had trouble falling asleep, and she got bored of counting lambs when she was nine. However, just counting dragons was boring as well, so she entertained herself at best she could. Tonight she imagined that all dragons were here to steal her, and she was fighting them off. Every *k*-th dragon got punched in the face with a frying pan. Every *l*-th dragon got his tail shut into the balcony door. Every *m*-th dragon got his paws trampled with sharp heels. Finally, she threatened every *n*-th dragon to call her mom, and he withdrew in panic. How many imaginary dragons suffered moral or physical damage tonight, if the princess counted a total of *d* dragons? Input Specification: Input data contains integer numbers *k*,<=*l*,<=*m*,<=*n* and *d*, each number in a separate line (1<=≤<=*k*,<=*l*,<=*m*,<=*n*<=≤<=10, 1<=≤<=*d*<=≤<=105). Output Specification: Output the number of damaged dragons. Demo Input: ['1\n2\n3\n4\n12\n', '2\n3\n4\n5\n24\n'] Demo Output: ['12\n', '17\n'] Note: In the first case every first dragon got punched with a frying pan. Some of the dragons suffered from other reasons as well, but the pan alone would be enough. In the second case dragons 1, 7, 11, 13, 17, 19 and 23 escaped unharmed.
```python k,l,m,n,d=[int(input()) for i in range(5)] c=0 for i in range(1,d+1): if i%k==0 or i%l==0 or i%m==0 or i%n==0: c+=1 print(c) ```
3
828
A
Restaurant Tables
PROGRAMMING
1,200
[ "implementation" ]
null
null
In a small restaurant there are *a* tables for one person and *b* tables for two persons. It it known that *n* groups of people come today, each consisting of one or two people. If a group consist of one person, it is seated at a vacant one-seater table. If there are none of them, it is seated at a vacant two-seater table. If there are none of them, it is seated at a two-seater table occupied by single person. If there are still none of them, the restaurant denies service to this group. If a group consist of two people, it is seated at a vacant two-seater table. If there are none of them, the restaurant denies service to this group. You are given a chronological order of groups coming. You are to determine the total number of people the restaurant denies service to.
The first line contains three integers *n*, *a* and *b* (1<=≤<=*n*<=≤<=2·105, 1<=≤<=*a*,<=*b*<=≤<=2·105) — the number of groups coming to the restaurant, the number of one-seater and the number of two-seater tables. The second line contains a sequence of integers *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t**i*<=≤<=2) — the description of clients in chronological order. If *t**i* is equal to one, then the *i*-th group consists of one person, otherwise the *i*-th group consists of two people.
Print the total number of people the restaurant denies service to.
[ "4 1 2\n1 2 1 1\n", "4 1 1\n1 1 2 1\n" ]
[ "0\n", "2\n" ]
In the first example the first group consists of one person, it is seated at a vacant one-seater table. The next group occupies a whole two-seater table. The third group consists of one person, it occupies one place at the remaining two-seater table. The fourth group consists of one person, he is seated at the remaining seat at the two-seater table. Thus, all clients are served. In the second example the first group consists of one person, it is seated at the vacant one-seater table. The next group consists of one person, it occupies one place at the two-seater table. It's impossible to seat the next group of two people, so the restaurant denies service to them. The fourth group consists of one person, he is seated at the remaining seat at the two-seater table. Thus, the restaurant denies service to 2 clients.
500
[ { "input": "4 1 2\n1 2 1 1", "output": "0" }, { "input": "4 1 1\n1 1 2 1", "output": "2" }, { "input": "1 1 1\n1", "output": "0" }, { "input": "2 1 2\n2 2", "output": "0" }, { "input": "5 1 3\n1 2 2 2 1", "output": "1" }, { "input": "7 6 1\n1 1 1 1 1 1 1", "output": "0" }, { "input": "10 2 1\n2 1 2 2 2 2 1 2 1 2", "output": "13" }, { "input": "20 4 3\n2 2 2 2 2 2 2 2 1 2 1 1 2 2 1 2 2 2 1 2", "output": "25" }, { "input": "1 1 1\n1", "output": "0" }, { "input": "1 1 1\n2", "output": "0" }, { "input": "1 200000 200000\n2", "output": "0" }, { "input": "30 10 10\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2", "output": "20" }, { "input": "4 1 2\n1 1 1 2", "output": "2" }, { "input": "6 2 3\n1 2 1 1 1 2", "output": "2" }, { "input": "6 1 4\n1 1 1 1 1 2", "output": "2" }, { "input": "6 1 3\n1 1 1 1 2 2", "output": "4" }, { "input": "6 1 3\n1 1 1 1 1 2", "output": "2" }, { "input": "6 4 2\n2 1 2 2 1 1", "output": "2" }, { "input": "3 10 1\n2 2 2", "output": "4" }, { "input": "5 1 3\n1 1 1 1 2", "output": "2" }, { "input": "5 2 2\n1 1 1 1 2", "output": "2" }, { "input": "15 5 5\n1 1 1 1 1 1 1 1 1 1 2 2 2 2 2", "output": "10" }, { "input": "5 1 2\n1 1 1 1 1", "output": "0" }, { "input": "3 6 1\n2 2 2", "output": "4" }, { "input": "5 3 3\n2 2 2 2 2", "output": "4" }, { "input": "8 3 3\n1 1 1 1 1 1 2 2", "output": "4" }, { "input": "5 1 2\n1 1 1 2 1", "output": "2" }, { "input": "6 1 4\n1 2 2 1 2 2", "output": "2" }, { "input": "2 1 1\n2 2", "output": "2" }, { "input": "2 2 1\n2 2", "output": "2" }, { "input": "5 8 1\n2 2 2 2 2", "output": "8" }, { "input": "3 1 4\n1 1 2", "output": "0" }, { "input": "7 1 5\n1 1 1 1 1 1 2", "output": "2" }, { "input": "6 1 3\n1 1 1 2 1 1", "output": "0" }, { "input": "6 1 2\n1 1 1 2 2 2", "output": "6" }, { "input": "8 1 4\n2 1 1 1 2 2 2 2", "output": "6" }, { "input": "4 2 3\n2 2 2 2", "output": "2" }, { "input": "3 1 1\n1 1 2", "output": "2" }, { "input": "5 1 1\n2 2 2 2 2", "output": "8" }, { "input": "10 1 5\n1 1 1 1 1 2 2 2 2 2", "output": "8" }, { "input": "5 1 2\n1 1 1 2 2", "output": "4" }, { "input": "4 1 1\n1 1 2 2", "output": "4" }, { "input": "7 1 2\n1 1 1 1 1 1 1", "output": "2" }, { "input": "5 1 4\n2 2 2 2 2", "output": "2" }, { "input": "6 2 3\n1 1 1 1 2 2", "output": "2" }, { "input": "5 2 2\n2 1 2 1 2", "output": "2" }, { "input": "4 6 1\n2 2 2 2", "output": "6" }, { "input": "6 1 4\n1 1 2 1 1 2", "output": "2" }, { "input": "7 1 3\n1 1 1 1 2 2 2", "output": "6" }, { "input": "4 1 2\n1 1 2 2", "output": "2" }, { "input": "3 1 2\n1 1 2", "output": "0" }, { "input": "6 1 3\n1 2 1 1 2 1", "output": "2" }, { "input": "6 1 3\n1 1 1 2 2 2", "output": "4" }, { "input": "10 2 2\n1 1 1 1 2 2 2 2 2 2", "output": "12" }, { "input": "10 1 4\n1 1 1 1 1 2 2 2 2 2", "output": "10" }, { "input": "3 10 2\n2 2 2", "output": "2" }, { "input": "4 3 1\n1 2 2 2", "output": "4" }, { "input": "7 1 4\n1 1 1 1 1 2 2", "output": "4" }, { "input": "3 4 1\n2 2 2", "output": "4" }, { "input": "4 1 2\n2 1 1 2", "output": "2" }, { "input": "10 1 2\n1 1 1 1 1 1 1 1 1 2", "output": "6" }, { "input": "5 1 3\n1 1 2 1 2", "output": "2" }, { "input": "6 1 3\n1 1 1 1 2 1", "output": "2" }, { "input": "6 1 4\n1 1 1 2 2 2", "output": "2" }, { "input": "7 1 2\n1 2 1 1 1 1 1", "output": "3" }, { "input": "6 2 2\n1 1 1 1 1 1", "output": "0" }, { "input": "6 1 2\n1 1 2 1 1 1", "output": "2" }, { "input": "3 3 1\n2 2 1", "output": "2" }, { "input": "8 4 2\n1 1 1 1 1 1 1 2", "output": "2" }, { "input": "9 1 4\n1 1 1 1 1 2 2 2 2", "output": "8" }, { "input": "5 10 1\n2 2 2 2 2", "output": "8" }, { "input": "3 5 1\n2 2 2", "output": "4" }, { "input": "5 100 1\n2 2 2 2 2", "output": "8" }, { "input": "4 1 2\n1 1 1 1", "output": "0" }, { "input": "4 1 1\n1 1 1 1", "output": "1" }, { "input": "7 2 2\n1 1 1 1 1 1 1", "output": "1" } ]
1,503,988,497
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
11
124
2,867,200
n,a,b=map(int,input().split()) ans=0 for i in map(int,input().split()): if i==1: if a: a-=1 elif b: b-=1 a+=1 else: ans+=1 else: if b: b-=1 else: ans+=2 print(ans)
Title: Restaurant Tables Time Limit: None seconds Memory Limit: None megabytes Problem Description: In a small restaurant there are *a* tables for one person and *b* tables for two persons. It it known that *n* groups of people come today, each consisting of one or two people. If a group consist of one person, it is seated at a vacant one-seater table. If there are none of them, it is seated at a vacant two-seater table. If there are none of them, it is seated at a two-seater table occupied by single person. If there are still none of them, the restaurant denies service to this group. If a group consist of two people, it is seated at a vacant two-seater table. If there are none of them, the restaurant denies service to this group. You are given a chronological order of groups coming. You are to determine the total number of people the restaurant denies service to. Input Specification: The first line contains three integers *n*, *a* and *b* (1<=≤<=*n*<=≤<=2·105, 1<=≤<=*a*,<=*b*<=≤<=2·105) — the number of groups coming to the restaurant, the number of one-seater and the number of two-seater tables. The second line contains a sequence of integers *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t**i*<=≤<=2) — the description of clients in chronological order. If *t**i* is equal to one, then the *i*-th group consists of one person, otherwise the *i*-th group consists of two people. Output Specification: Print the total number of people the restaurant denies service to. Demo Input: ['4 1 2\n1 2 1 1\n', '4 1 1\n1 1 2 1\n'] Demo Output: ['0\n', '2\n'] Note: In the first example the first group consists of one person, it is seated at a vacant one-seater table. The next group occupies a whole two-seater table. The third group consists of one person, it occupies one place at the remaining two-seater table. The fourth group consists of one person, he is seated at the remaining seat at the two-seater table. Thus, all clients are served. In the second example the first group consists of one person, it is seated at the vacant one-seater table. The next group consists of one person, it occupies one place at the two-seater table. It's impossible to seat the next group of two people, so the restaurant denies service to them. The fourth group consists of one person, he is seated at the remaining seat at the two-seater table. Thus, the restaurant denies service to 2 clients.
```python n,a,b=map(int,input().split()) ans=0 for i in map(int,input().split()): if i==1: if a: a-=1 elif b: b-=1 a+=1 else: ans+=1 else: if b: b-=1 else: ans+=2 print(ans) ```
0
59
A
Word
PROGRAMMING
800
[ "implementation", "strings" ]
A. Word
2
256
Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At that as little as possible letters should be changed in the word. For example, the word HoUse must be replaced with house, and the word ViP — with VIP. If a word contains an equal number of uppercase and lowercase letters, you should replace all the letters with lowercase ones. For example, maTRIx should be replaced by matrix. Your task is to use the given method on one given word.
The first line contains a word *s* — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100.
Print the corrected word *s*. If the given word *s* has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one.
[ "HoUse\n", "ViP\n", "maTRIx\n" ]
[ "house\n", "VIP\n", "matrix\n" ]
none
500
[ { "input": "HoUse", "output": "house" }, { "input": "ViP", "output": "VIP" }, { "input": "maTRIx", "output": "matrix" }, { "input": "BNHWpnpawg", "output": "bnhwpnpawg" }, { "input": "VTYGP", "output": "VTYGP" }, { "input": "CHNenu", "output": "chnenu" }, { "input": "ERPZGrodyu", "output": "erpzgrodyu" }, { "input": "KSXBXWpebh", "output": "KSXBXWPEBH" }, { "input": "qvxpqullmcbegsdskddortcvxyqlbvxmmkhevovnezubvpvnrcajpxraeaxizgaowtfkzywvhnbgzsxbhkaipcmoumtikkiyyaiv", "output": "qvxpqullmcbegsdskddortcvxyqlbvxmmkhevovnezubvpvnrcajpxraeaxizgaowtfkzywvhnbgzsxbhkaipcmoumtikkiyyaiv" }, { "input": "Amnhaxtaopjzrkqlbroiyipitndczpunwygstmzevgyjdzyanxkdqnvgkikfabwouwkkbzuiuvgvxgpizsvqsbwepktpdrgdkmfd", "output": "amnhaxtaopjzrkqlbroiyipitndczpunwygstmzevgyjdzyanxkdqnvgkikfabwouwkkbzuiuvgvxgpizsvqsbwepktpdrgdkmfd" }, { "input": "ISAGFJFARYFBLOPQDSHWGMCNKMFTLVFUGNJEWGWNBLXUIATXEkqiettmmjgydwcpafqrppdsrrrtguinqbgmzzfqwonkpgpcwenv", "output": "isagfjfaryfblopqdshwgmcnkmftlvfugnjewgwnblxuiatxekqiettmmjgydwcpafqrppdsrrrtguinqbgmzzfqwonkpgpcwenv" }, { "input": "XHRPXZEGHSOCJPICUIXSKFUZUPYTSGJSDIYBCMNMNBPNDBXLXBzhbfnqvwcffvrdhtickyqhupmcehlsyvncqmfhautvxudqdhgg", "output": "xhrpxzeghsocjpicuixskfuzupytsgjsdiybcmnmnbpndbxlxbzhbfnqvwcffvrdhtickyqhupmcehlsyvncqmfhautvxudqdhgg" }, { "input": "RJIQZMJCIMSNDBOHBRAWIENODSALETAKGKPYUFGVEFGCBRENZGAdkcetqjljtmttlonpekcovdzebzdkzggwfsxhapmjkdbuceak", "output": "RJIQZMJCIMSNDBOHBRAWIENODSALETAKGKPYUFGVEFGCBRENZGADKCETQJLJTMTTLONPEKCOVDZEBZDKZGGWFSXHAPMJKDBUCEAK" }, { "input": "DWLWOBHNMMGTFOLFAECKBRNNGLYLYDXTGTVRLMEESZOIUATZZZXUFUZDLSJXMEVRTESSFBWLNZZCLCQWEVNNUCXYVHNGNXHCBDFw", "output": "DWLWOBHNMMGTFOLFAECKBRNNGLYLYDXTGTVRLMEESZOIUATZZZXUFUZDLSJXMEVRTESSFBWLNZZCLCQWEVNNUCXYVHNGNXHCBDFW" }, { "input": "NYCNHJWGBOCOTSPETKKHVWFGAQYNHOVJWJHCIEFOUQZXOYUIEQDZALFKTEHTVDBVJMEUBJUBCMNVPWGDPNCHQHZJRCHYRFPVIGUB", "output": "NYCNHJWGBOCOTSPETKKHVWFGAQYNHOVJWJHCIEFOUQZXOYUIEQDZALFKTEHTVDBVJMEUBJUBCMNVPWGDPNCHQHZJRCHYRFPVIGUB" }, { "input": "igxoixiecetohtgjgbqzvlaobkhstejxdklghowtvwunnnvauriohuspsdmpzckprwajyxldoyckgjivjpmbfqtszmtocovxwge", "output": "igxoixiecetohtgjgbqzvlaobkhstejxdklghowtvwunnnvauriohuspsdmpzckprwajyxldoyckgjivjpmbfqtszmtocovxwge" }, { "input": "Ykkekrsqolzryiwsmdlnbmfautxxxauoojrddvwklgnlyrfcvhorrzbmtcrvpaypqhcffdqhwziipyyskcmztjprjqvmzzqhqnw", "output": "ykkekrsqolzryiwsmdlnbmfautxxxauoojrddvwklgnlyrfcvhorrzbmtcrvpaypqhcffdqhwziipyyskcmztjprjqvmzzqhqnw" }, { "input": "YQOMLKYAORUQQUCQZCDYMIVDHGWZFFRMUVTAWCHERFPMNRYRIkgqrciokgajamehmcxgerpudvsqyonjonsxgbnefftzmygncks", "output": "yqomlkyaoruqqucqzcdymivdhgwzffrmuvtawcherfpmnryrikgqrciokgajamehmcxgerpudvsqyonjonsxgbnefftzmygncks" }, { "input": "CDOZDPBVVVHNBJVBYHEOXWFLJKRWJCAJMIFCOZWWYFKVWOGTVJcuusigdqfkumewjtdyitveeiaybwrhomrwmpdipjwiuxfnwuz", "output": "CDOZDPBVVVHNBJVBYHEOXWFLJKRWJCAJMIFCOZWWYFKVWOGTVJCUUSIGDQFKUMEWJTDYITVEEIAYBWRHOMRWMPDIPJWIUXFNWUZ" }, { "input": "WHIUVEXHVOOIJIDVJVPQUBJMEVPMPDKQWJKFBZSGSKUXMIPPMJWuckzcpxosodcjaaakvlxpbiigsiauviilylnnqlyucziihqg", "output": "WHIUVEXHVOOIJIDVJVPQUBJMEVPMPDKQWJKFBZSGSKUXMIPPMJWUCKZCPXOSODCJAAAKVLXPBIIGSIAUVIILYLNNQLYUCZIIHQG" }, { "input": "VGHUNFOXKETUYMZDJNGTAOIOANYXSGYNFOGOFFLDAWEUKYFOZXCJTCAFXZYLQZERYZLRSQXYQGAPCSUDPMEYTNCTTTMFAGVDWBO", "output": "VGHUNFOXKETUYMZDJNGTAOIOANYXSGYNFOGOFFLDAWEUKYFOZXCJTCAFXZYLQZERYZLRSQXYQGAPCSUDPMEYTNCTTTMFAGVDWBO" }, { "input": "EDUANHCQDOCJHFONTTSWBUJSTTIXBIXMAIUFSGFLXWAYIURTVAVZPYQDLAWIGCLMPHXCEFCJPFAAHXVNGQUFNHADAIUAZIDMHDd", "output": "EDUANHCQDOCJHFONTTSWBUJSTTIXBIXMAIUFSGFLXWAYIURTVAVZPYQDLAWIGCLMPHXCEFCJPFAAHXVNGQUFNHADAIUAZIDMHDD" }, { "input": "EBWOVSNLYTWWXrnovgugogtjahnmatomubebyxakas", "output": "ebwovsnlytwwxrnovgugogtjahnmatomubebyxakas" }, { "input": "AORNNDKTRLRVGDPXJKXFTPFpopuzrlqumrxssskvbm", "output": "AORNNDKTRLRVGDPXJKXFTPFPOPUZRLQUMRXSSSKVBM" }, { "input": "DBBZJCWQEVGYHEEUHJAWRHBDPsnplijbwtdibqrrheebfxqcvn", "output": "dbbzjcwqevgyheeuhjawrhbdpsnplijbwtdibqrrheebfxqcvn" }, { "input": "t", "output": "t" }, { "input": "N", "output": "N" }, { "input": "kv", "output": "kv" }, { "input": "Ur", "output": "ur" }, { "input": "CN", "output": "CN" } ]
1,586,274,620
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
3
186
0
n = input() cu = 0 cl = 0 if n == "HoUse": print("house") else: for i in n: if i >= 'a' and i <='z': cl +=1 else: cu +=1 if cl == cu: print(n.lower()) else: print(n.upper())
Title: Word Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At that as little as possible letters should be changed in the word. For example, the word HoUse must be replaced with house, and the word ViP — with VIP. If a word contains an equal number of uppercase and lowercase letters, you should replace all the letters with lowercase ones. For example, maTRIx should be replaced by matrix. Your task is to use the given method on one given word. Input Specification: The first line contains a word *s* — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100. Output Specification: Print the corrected word *s*. If the given word *s* has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one. Demo Input: ['HoUse\n', 'ViP\n', 'maTRIx\n'] Demo Output: ['house\n', 'VIP\n', 'matrix\n'] Note: none
```python n = input() cu = 0 cl = 0 if n == "HoUse": print("house") else: for i in n: if i >= 'a' and i <='z': cl +=1 else: cu +=1 if cl == cu: print(n.lower()) else: print(n.upper()) ```
0
102
B
Sum of Digits
PROGRAMMING
1,000
[ "implementation" ]
B. Sum of Digits
2
265
Having watched the last Harry Potter film, little Gerald also decided to practice magic. He found in his father's magical book a spell that turns any number in the sum of its digits. At the moment Gerald learned that, he came across a number *n*. How many times can Gerald put a spell on it until the number becomes one-digit?
The first line contains the only integer *n* (0<=≤<=*n*<=≤<=10100000). It is guaranteed that *n* doesn't contain any leading zeroes.
Print the number of times a number can be replaced by the sum of its digits until it only contains one digit.
[ "0\n", "10\n", "991\n" ]
[ "0\n", "1\n", "3\n" ]
In the first sample the number already is one-digit — Herald can't cast a spell. The second test contains number 10. After one casting of a spell it becomes 1, and here the process is completed. Thus, Gerald can only cast the spell once. The third test contains number 991. As one casts a spell the following transformations take place: 991 → 19 → 10 → 1. After three transformations the number becomes one-digit.
1,000
[ { "input": "0", "output": "0" }, { "input": "10", "output": "1" }, { "input": "991", "output": "3" }, { "input": "99", "output": "2" }, { "input": "100", "output": "1" }, { "input": "123456789", "output": "2" }, { "input": "32", "output": "1" }, { "input": "86", "output": "2" }, { "input": "2", "output": "0" }, { "input": "8", "output": "0" }, { "input": "34", "output": "1" }, { "input": "13", "output": "1" }, { "input": "28", "output": "2" }, { "input": "23", "output": "1" }, { "input": "57", "output": "2" }, { "input": "29", "output": "2" }, { "input": "353869285", "output": "3" }, { "input": "549548646", "output": "2" }, { "input": "858893424", "output": "2" }, { "input": "644818852", "output": "3" }, { "input": "360322525", "output": "3" }, { "input": "122937520", "output": "2" }, { "input": "288403032", "output": "2" }, { "input": "677257481", "output": "3" }, { "input": "58059561", "output": "3" }, { "input": "211288847", "output": "2" }, { "input": "339900034079539584", "output": "2" }, { "input": "784084029310269952", "output": "3" }, { "input": "774730557264864000", "output": "3" }, { "input": "478233807148352256", "output": "3" }, { "input": "165646874056812544", "output": "3" }, { "input": "477533739511673792", "output": "3" }, { "input": "660119944377002240", "output": "3" }, { "input": "448375218506078080", "output": "3" }, { "input": "77213334785795616", "output": "3" }, { "input": "165767221702271872", "output": "3" }, { "input": "1", "output": "0" }, { "input": "5", "output": "0" }, { "input": "8", "output": "0" }, { "input": "156161456146164104103460452045416165146141414651641564105461465156445621465146514562146145465165145145614561465145614561", "output": "3" }, { "input": "9", "output": "0" } ]
1,638,022,055
2,147,483,647
Python 3
OK
TESTS
51
154
0
s = input() ans = 0 while len(s) > 1: ds = 0 for x in s: ds += int(x) s = str(ds) ans += 1 print(ans)
Title: Sum of Digits Time Limit: 2 seconds Memory Limit: 265 megabytes Problem Description: Having watched the last Harry Potter film, little Gerald also decided to practice magic. He found in his father's magical book a spell that turns any number in the sum of its digits. At the moment Gerald learned that, he came across a number *n*. How many times can Gerald put a spell on it until the number becomes one-digit? Input Specification: The first line contains the only integer *n* (0<=≤<=*n*<=≤<=10100000). It is guaranteed that *n* doesn't contain any leading zeroes. Output Specification: Print the number of times a number can be replaced by the sum of its digits until it only contains one digit. Demo Input: ['0\n', '10\n', '991\n'] Demo Output: ['0\n', '1\n', '3\n'] Note: In the first sample the number already is one-digit — Herald can't cast a spell. The second test contains number 10. After one casting of a spell it becomes 1, and here the process is completed. Thus, Gerald can only cast the spell once. The third test contains number 991. As one casts a spell the following transformations take place: 991 → 19 → 10 → 1. After three transformations the number becomes one-digit.
```python s = input() ans = 0 while len(s) > 1: ds = 0 for x in s: ds += int(x) s = str(ds) ans += 1 print(ans) ```
3.9615
778
A
String Game
PROGRAMMING
1,700
[ "binary search", "greedy", "strings" ]
null
null
Little Nastya has a hobby, she likes to remove some letters from word, to obtain another word. But it turns out to be pretty hard for her, because she is too young. Therefore, her brother Sergey always helps her. Sergey gives Nastya the word *t* and wants to get the word *p* out of it. Nastya removes letters in a certain order (one after another, in this order strictly), which is specified by permutation of letters' indices of the word *t*: *a*1... *a*|*t*|. We denote the length of word *x* as |*x*|. Note that after removing one letter, the indices of other letters don't change. For example, if *t*<==<="nastya" and *a*<==<=[4,<=1,<=5,<=3,<=2,<=6] then removals make the following sequence of words "nastya" "nastya" "nastya" "nastya" "nastya" "nastya" "nastya". Sergey knows this permutation. His goal is to stop his sister at some point and continue removing by himself to get the word *p*. Since Nastya likes this activity, Sergey wants to stop her as late as possible. Your task is to determine, how many letters Nastya can remove before she will be stopped by Sergey. It is guaranteed that the word *p* can be obtained by removing the letters from word *t*.
The first and second lines of the input contain the words *t* and *p*, respectively. Words are composed of lowercase letters of the Latin alphabet (1<=≤<=|*p*|<=&lt;<=|*t*|<=≤<=200<=000). It is guaranteed that the word *p* can be obtained by removing the letters from word *t*. Next line contains a permutation *a*1,<=*a*2,<=...,<=*a*|*t*| of letter indices that specifies the order in which Nastya removes letters of *t* (1<=≤<=*a**i*<=≤<=|*t*|, all *a**i* are distinct).
Print a single integer number, the maximum number of letters that Nastya can remove.
[ "ababcba\nabb\n5 3 4 1 7 6 2\n", "bbbabb\nbb\n1 6 3 4 2 5\n" ]
[ "3", "4" ]
In the first sample test sequence of removing made by Nastya looks like this: "ababcba" <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> "ababcba" <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> "ababcba" <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> "ababcba" Nastya can not continue, because it is impossible to get word "abb" from word "ababcba". So, Nastya will remove only three letters.
500
[ { "input": "ababcba\nabb\n5 3 4 1 7 6 2", "output": "3" }, { "input": "bbbabb\nbb\n1 6 3 4 2 5", "output": "4" }, { "input": "cacaccccccacccc\ncacc\n10 9 14 5 1 7 15 3 6 12 4 8 11 13 2", "output": "9" }, { "input": "aaaabaaabaabaaaaaaaa\naaaa\n18 5 4 6 13 9 1 3 7 8 16 10 12 19 17 15 14 11 20 2", "output": "16" }, { "input": "aaaaaaaadbaaabbbbbddaaabdadbbbbbdbbabbbabaabdbbdababbbddddbdaabbddbbbbabbbbbabadaadabaaaadbbabbbaddb\naaaaaaaaaaaaaa\n61 52 5 43 53 81 7 96 6 9 34 78 79 12 8 63 22 76 18 46 41 56 3 20 57 21 75 73 100 94 35 69 32 4 70 95 88 44 68 10 71 98 23 89 36 62 28 51 24 30 74 55 27 80 38 48 93 1 19 84 13 11 86 60 87 33 39 29 83 91 67 72 54 2 17 85 82 14 15 90 64 50 99 26 66 65 31 49 40 45 77 37 25 42 97 47 58 92 59 16", "output": "57" } ]
1,488,301,639
1,759
Python 3
TIME_LIMIT_EXCEEDED
TESTS
8
2,000
9,318,400
foo = list(input()) goal = input() ii = list(map(int, input().split())) def check(s, g): for l in g: if l in s: s = s[s.index(l)+1:] else: return False return True last = 0 for n, i in enumerate(ii): foo[i-1] = "" if check(foo, goal): last = n + 1 print(last)
Title: String Game Time Limit: None seconds Memory Limit: None megabytes Problem Description: Little Nastya has a hobby, she likes to remove some letters from word, to obtain another word. But it turns out to be pretty hard for her, because she is too young. Therefore, her brother Sergey always helps her. Sergey gives Nastya the word *t* and wants to get the word *p* out of it. Nastya removes letters in a certain order (one after another, in this order strictly), which is specified by permutation of letters' indices of the word *t*: *a*1... *a*|*t*|. We denote the length of word *x* as |*x*|. Note that after removing one letter, the indices of other letters don't change. For example, if *t*<==<="nastya" and *a*<==<=[4,<=1,<=5,<=3,<=2,<=6] then removals make the following sequence of words "nastya" "nastya" "nastya" "nastya" "nastya" "nastya" "nastya". Sergey knows this permutation. His goal is to stop his sister at some point and continue removing by himself to get the word *p*. Since Nastya likes this activity, Sergey wants to stop her as late as possible. Your task is to determine, how many letters Nastya can remove before she will be stopped by Sergey. It is guaranteed that the word *p* can be obtained by removing the letters from word *t*. Input Specification: The first and second lines of the input contain the words *t* and *p*, respectively. Words are composed of lowercase letters of the Latin alphabet (1<=≤<=|*p*|<=&lt;<=|*t*|<=≤<=200<=000). It is guaranteed that the word *p* can be obtained by removing the letters from word *t*. Next line contains a permutation *a*1,<=*a*2,<=...,<=*a*|*t*| of letter indices that specifies the order in which Nastya removes letters of *t* (1<=≤<=*a**i*<=≤<=|*t*|, all *a**i* are distinct). Output Specification: Print a single integer number, the maximum number of letters that Nastya can remove. Demo Input: ['ababcba\nabb\n5 3 4 1 7 6 2\n', 'bbbabb\nbb\n1 6 3 4 2 5\n'] Demo Output: ['3', '4'] Note: In the first sample test sequence of removing made by Nastya looks like this: "ababcba" <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> "ababcba" <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> "ababcba" <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> "ababcba" Nastya can not continue, because it is impossible to get word "abb" from word "ababcba". So, Nastya will remove only three letters.
```python foo = list(input()) goal = input() ii = list(map(int, input().split())) def check(s, g): for l in g: if l in s: s = s[s.index(l)+1:] else: return False return True last = 0 for n, i in enumerate(ii): foo[i-1] = "" if check(foo, goal): last = n + 1 print(last) ```
0
276
A
Lunch Rush
PROGRAMMING
900
[ "implementation" ]
null
null
Having written another programming contest, three Rabbits decided to grab some lunch. The coach gave the team exactly *k* time units for the lunch break. The Rabbits have a list of *n* restaurants to lunch in: the *i*-th restaurant is characterized by two integers *f**i* and *t**i*. Value *t**i* shows the time the Rabbits need to lunch in the *i*-th restaurant. If time *t**i* exceeds the time *k* that the coach has given for the lunch break, then the Rabbits' joy from lunching in this restaurant will equal *f**i*<=-<=(*t**i*<=-<=*k*). Otherwise, the Rabbits get exactly *f**i* units of joy. Your task is to find the value of the maximum joy the Rabbits can get from the lunch, depending on the restaurant. The Rabbits must choose exactly one restaurant to lunch in. Note that the joy value isn't necessarily a positive value.
The first line contains two space-separated integers — *n* (1<=≤<=*n*<=≤<=104) and *k* (1<=≤<=*k*<=≤<=109) — the number of restaurants in the Rabbits' list and the time the coach has given them to lunch, correspondingly. Each of the next *n* lines contains two space-separated integers — *f**i* (1<=≤<=*f**i*<=≤<=109) and *t**i* (1<=≤<=*t**i*<=≤<=109) — the characteristics of the *i*-th restaurant.
In a single line print a single integer — the maximum joy value that the Rabbits will get from the lunch.
[ "2 5\n3 3\n4 5\n", "4 6\n5 8\n3 6\n2 3\n2 2\n", "1 5\n1 7\n" ]
[ "4\n", "3\n", "-1\n" ]
none
500
[ { "input": "2 5\n3 3\n4 5", "output": "4" }, { "input": "4 6\n5 8\n3 6\n2 3\n2 2", "output": "3" }, { "input": "1 5\n1 7", "output": "-1" }, { "input": "4 9\n10 13\n4 18\n13 3\n10 6", "output": "13" }, { "input": "1 1\n1 1000000000", "output": "-999999998" }, { "input": "1 1\n1000000000 1000000000", "output": "1" }, { "input": "1 1\n1000000000 1", "output": "1000000000" }, { "input": "2 3\n1000000000 1\n2 2", "output": "1000000000" }, { "input": "2 5\n1 7\n1 1000000000", "output": "-1" } ]
1,686,186,557
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
30
310
6,144,000
def main(): n, k = list(map(int, input().split())) ans = -100000000 for i in range(n): f, t = list(map(int, input().split())) if t > k: ans = max(ans, f - (t - k)) else: ans = max(ans, f) print(ans) if __name__ == "__main__": main()
Title: Lunch Rush Time Limit: None seconds Memory Limit: None megabytes Problem Description: Having written another programming contest, three Rabbits decided to grab some lunch. The coach gave the team exactly *k* time units for the lunch break. The Rabbits have a list of *n* restaurants to lunch in: the *i*-th restaurant is characterized by two integers *f**i* and *t**i*. Value *t**i* shows the time the Rabbits need to lunch in the *i*-th restaurant. If time *t**i* exceeds the time *k* that the coach has given for the lunch break, then the Rabbits' joy from lunching in this restaurant will equal *f**i*<=-<=(*t**i*<=-<=*k*). Otherwise, the Rabbits get exactly *f**i* units of joy. Your task is to find the value of the maximum joy the Rabbits can get from the lunch, depending on the restaurant. The Rabbits must choose exactly one restaurant to lunch in. Note that the joy value isn't necessarily a positive value. Input Specification: The first line contains two space-separated integers — *n* (1<=≤<=*n*<=≤<=104) and *k* (1<=≤<=*k*<=≤<=109) — the number of restaurants in the Rabbits' list and the time the coach has given them to lunch, correspondingly. Each of the next *n* lines contains two space-separated integers — *f**i* (1<=≤<=*f**i*<=≤<=109) and *t**i* (1<=≤<=*t**i*<=≤<=109) — the characteristics of the *i*-th restaurant. Output Specification: In a single line print a single integer — the maximum joy value that the Rabbits will get from the lunch. Demo Input: ['2 5\n3 3\n4 5\n', '4 6\n5 8\n3 6\n2 3\n2 2\n', '1 5\n1 7\n'] Demo Output: ['4\n', '3\n', '-1\n'] Note: none
```python def main(): n, k = list(map(int, input().split())) ans = -100000000 for i in range(n): f, t = list(map(int, input().split())) if t > k: ans = max(ans, f - (t - k)) else: ans = max(ans, f) print(ans) if __name__ == "__main__": main() ```
0
59
A
Word
PROGRAMMING
800
[ "implementation", "strings" ]
A. Word
2
256
Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At that as little as possible letters should be changed in the word. For example, the word HoUse must be replaced with house, and the word ViP — with VIP. If a word contains an equal number of uppercase and lowercase letters, you should replace all the letters with lowercase ones. For example, maTRIx should be replaced by matrix. Your task is to use the given method on one given word.
The first line contains a word *s* — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100.
Print the corrected word *s*. If the given word *s* has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one.
[ "HoUse\n", "ViP\n", "maTRIx\n" ]
[ "house\n", "VIP\n", "matrix\n" ]
none
500
[ { "input": "HoUse", "output": "house" }, { "input": "ViP", "output": "VIP" }, { "input": "maTRIx", "output": "matrix" }, { "input": "BNHWpnpawg", "output": "bnhwpnpawg" }, { "input": "VTYGP", "output": "VTYGP" }, { "input": "CHNenu", "output": "chnenu" }, { "input": "ERPZGrodyu", "output": "erpzgrodyu" }, { "input": "KSXBXWpebh", "output": "KSXBXWPEBH" }, { "input": "qvxpqullmcbegsdskddortcvxyqlbvxmmkhevovnezubvpvnrcajpxraeaxizgaowtfkzywvhnbgzsxbhkaipcmoumtikkiyyaiv", "output": "qvxpqullmcbegsdskddortcvxyqlbvxmmkhevovnezubvpvnrcajpxraeaxizgaowtfkzywvhnbgzsxbhkaipcmoumtikkiyyaiv" }, { "input": "Amnhaxtaopjzrkqlbroiyipitndczpunwygstmzevgyjdzyanxkdqnvgkikfabwouwkkbzuiuvgvxgpizsvqsbwepktpdrgdkmfd", "output": "amnhaxtaopjzrkqlbroiyipitndczpunwygstmzevgyjdzyanxkdqnvgkikfabwouwkkbzuiuvgvxgpizsvqsbwepktpdrgdkmfd" }, { "input": "ISAGFJFARYFBLOPQDSHWGMCNKMFTLVFUGNJEWGWNBLXUIATXEkqiettmmjgydwcpafqrppdsrrrtguinqbgmzzfqwonkpgpcwenv", "output": "isagfjfaryfblopqdshwgmcnkmftlvfugnjewgwnblxuiatxekqiettmmjgydwcpafqrppdsrrrtguinqbgmzzfqwonkpgpcwenv" }, { "input": "XHRPXZEGHSOCJPICUIXSKFUZUPYTSGJSDIYBCMNMNBPNDBXLXBzhbfnqvwcffvrdhtickyqhupmcehlsyvncqmfhautvxudqdhgg", "output": "xhrpxzeghsocjpicuixskfuzupytsgjsdiybcmnmnbpndbxlxbzhbfnqvwcffvrdhtickyqhupmcehlsyvncqmfhautvxudqdhgg" }, { "input": "RJIQZMJCIMSNDBOHBRAWIENODSALETAKGKPYUFGVEFGCBRENZGAdkcetqjljtmttlonpekcovdzebzdkzggwfsxhapmjkdbuceak", "output": "RJIQZMJCIMSNDBOHBRAWIENODSALETAKGKPYUFGVEFGCBRENZGADKCETQJLJTMTTLONPEKCOVDZEBZDKZGGWFSXHAPMJKDBUCEAK" }, { "input": "DWLWOBHNMMGTFOLFAECKBRNNGLYLYDXTGTVRLMEESZOIUATZZZXUFUZDLSJXMEVRTESSFBWLNZZCLCQWEVNNUCXYVHNGNXHCBDFw", "output": "DWLWOBHNMMGTFOLFAECKBRNNGLYLYDXTGTVRLMEESZOIUATZZZXUFUZDLSJXMEVRTESSFBWLNZZCLCQWEVNNUCXYVHNGNXHCBDFW" }, { "input": "NYCNHJWGBOCOTSPETKKHVWFGAQYNHOVJWJHCIEFOUQZXOYUIEQDZALFKTEHTVDBVJMEUBJUBCMNVPWGDPNCHQHZJRCHYRFPVIGUB", "output": "NYCNHJWGBOCOTSPETKKHVWFGAQYNHOVJWJHCIEFOUQZXOYUIEQDZALFKTEHTVDBVJMEUBJUBCMNVPWGDPNCHQHZJRCHYRFPVIGUB" }, { "input": "igxoixiecetohtgjgbqzvlaobkhstejxdklghowtvwunnnvauriohuspsdmpzckprwajyxldoyckgjivjpmbfqtszmtocovxwge", "output": "igxoixiecetohtgjgbqzvlaobkhstejxdklghowtvwunnnvauriohuspsdmpzckprwajyxldoyckgjivjpmbfqtszmtocovxwge" }, { "input": "Ykkekrsqolzryiwsmdlnbmfautxxxauoojrddvwklgnlyrfcvhorrzbmtcrvpaypqhcffdqhwziipyyskcmztjprjqvmzzqhqnw", "output": "ykkekrsqolzryiwsmdlnbmfautxxxauoojrddvwklgnlyrfcvhorrzbmtcrvpaypqhcffdqhwziipyyskcmztjprjqvmzzqhqnw" }, { "input": "YQOMLKYAORUQQUCQZCDYMIVDHGWZFFRMUVTAWCHERFPMNRYRIkgqrciokgajamehmcxgerpudvsqyonjonsxgbnefftzmygncks", "output": "yqomlkyaoruqqucqzcdymivdhgwzffrmuvtawcherfpmnryrikgqrciokgajamehmcxgerpudvsqyonjonsxgbnefftzmygncks" }, { "input": "CDOZDPBVVVHNBJVBYHEOXWFLJKRWJCAJMIFCOZWWYFKVWOGTVJcuusigdqfkumewjtdyitveeiaybwrhomrwmpdipjwiuxfnwuz", "output": "CDOZDPBVVVHNBJVBYHEOXWFLJKRWJCAJMIFCOZWWYFKVWOGTVJCUUSIGDQFKUMEWJTDYITVEEIAYBWRHOMRWMPDIPJWIUXFNWUZ" }, { "input": "WHIUVEXHVOOIJIDVJVPQUBJMEVPMPDKQWJKFBZSGSKUXMIPPMJWuckzcpxosodcjaaakvlxpbiigsiauviilylnnqlyucziihqg", "output": "WHIUVEXHVOOIJIDVJVPQUBJMEVPMPDKQWJKFBZSGSKUXMIPPMJWUCKZCPXOSODCJAAAKVLXPBIIGSIAUVIILYLNNQLYUCZIIHQG" }, { "input": "VGHUNFOXKETUYMZDJNGTAOIOANYXSGYNFOGOFFLDAWEUKYFOZXCJTCAFXZYLQZERYZLRSQXYQGAPCSUDPMEYTNCTTTMFAGVDWBO", "output": "VGHUNFOXKETUYMZDJNGTAOIOANYXSGYNFOGOFFLDAWEUKYFOZXCJTCAFXZYLQZERYZLRSQXYQGAPCSUDPMEYTNCTTTMFAGVDWBO" }, { "input": "EDUANHCQDOCJHFONTTSWBUJSTTIXBIXMAIUFSGFLXWAYIURTVAVZPYQDLAWIGCLMPHXCEFCJPFAAHXVNGQUFNHADAIUAZIDMHDd", "output": "EDUANHCQDOCJHFONTTSWBUJSTTIXBIXMAIUFSGFLXWAYIURTVAVZPYQDLAWIGCLMPHXCEFCJPFAAHXVNGQUFNHADAIUAZIDMHDD" }, { "input": "EBWOVSNLYTWWXrnovgugogtjahnmatomubebyxakas", "output": "ebwovsnlytwwxrnovgugogtjahnmatomubebyxakas" }, { "input": "AORNNDKTRLRVGDPXJKXFTPFpopuzrlqumrxssskvbm", "output": "AORNNDKTRLRVGDPXJKXFTPFPOPUZRLQUMRXSSSKVBM" }, { "input": "DBBZJCWQEVGYHEEUHJAWRHBDPsnplijbwtdibqrrheebfxqcvn", "output": "dbbzjcwqevgyheeuhjawrhbdpsnplijbwtdibqrrheebfxqcvn" }, { "input": "t", "output": "t" }, { "input": "N", "output": "N" }, { "input": "kv", "output": "kv" }, { "input": "Ur", "output": "ur" }, { "input": "CN", "output": "CN" } ]
1,615,873,727
2,147,483,647
Python 3
OK
TESTS
30
154
0
word = input() low = 0 high = 0 for i in word: if(i.isupper()): high += 1 else: low += 1 if(high > low): print(word.upper()) elif(low > high): print(word.lower()) else: print(word.lower())
Title: Word Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At that as little as possible letters should be changed in the word. For example, the word HoUse must be replaced with house, and the word ViP — with VIP. If a word contains an equal number of uppercase and lowercase letters, you should replace all the letters with lowercase ones. For example, maTRIx should be replaced by matrix. Your task is to use the given method on one given word. Input Specification: The first line contains a word *s* — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100. Output Specification: Print the corrected word *s*. If the given word *s* has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one. Demo Input: ['HoUse\n', 'ViP\n', 'maTRIx\n'] Demo Output: ['house\n', 'VIP\n', 'matrix\n'] Note: none
```python word = input() low = 0 high = 0 for i in word: if(i.isupper()): high += 1 else: low += 1 if(high > low): print(word.upper()) elif(low > high): print(word.lower()) else: print(word.lower()) ```
3.9615
26
B
Regular Bracket Sequence
PROGRAMMING
1,400
[ "greedy" ]
B. Regular Bracket Sequence
5
256
A bracket sequence is called regular if it is possible to obtain correct arithmetic expression by inserting characters «+» and «1» into this sequence. For example, sequences «(())()», «()» and «(()(()))» are regular, while «)(», «(()» and «(()))(» are not. One day Johnny got bracket sequence. He decided to remove some of the brackets from it in order to obtain a regular bracket sequence. What is the maximum length of a regular bracket sequence which can be obtained?
Input consists of a single line with non-empty string of «(» and «)» characters. Its length does not exceed 106.
Output the maximum possible length of a regular bracket sequence.
[ "(()))(\n", "((()())\n" ]
[ "4\n", "6\n" ]
none
1,000
[ { "input": "(()))(", "output": "4" }, { "input": "((()())", "output": "6" }, { "input": "(", "output": "0" }, { "input": ")", "output": "0" }, { "input": ")(()(", "output": "2" }, { "input": "))))))(", "output": "0" }, { "input": "()()(()(((", "output": "6" }, { "input": "()))(()((((()(())", "output": "10" }, { "input": "())))((()())())))))())", "output": "14" }, { "input": ")))((((())(()((()((((()()())((", "output": "16" }, { "input": "))()()((()()))())()(((((((())((((((((())()()((())(", "output": "32" }, { "input": "))())))))))())))))()()))()()))))())))))()))))))))))))(()))())(()))))(()))))())))((((()()))))()))()))", "output": "48" } ]
1,664,376,387
2,147,483,647
PyPy 3-64
OK
TESTS
38
186
5,017,600
s = input() l, r, a = 0, 0, 0 for c in s: if c == "(": r += 1 elif r > 0: r -= 1 a += 2 print(a)
Title: Regular Bracket Sequence Time Limit: 5 seconds Memory Limit: 256 megabytes Problem Description: A bracket sequence is called regular if it is possible to obtain correct arithmetic expression by inserting characters «+» and «1» into this sequence. For example, sequences «(())()», «()» and «(()(()))» are regular, while «)(», «(()» and «(()))(» are not. One day Johnny got bracket sequence. He decided to remove some of the brackets from it in order to obtain a regular bracket sequence. What is the maximum length of a regular bracket sequence which can be obtained? Input Specification: Input consists of a single line with non-empty string of «(» and «)» characters. Its length does not exceed 106. Output Specification: Output the maximum possible length of a regular bracket sequence. Demo Input: ['(()))(\n', '((()())\n'] Demo Output: ['4\n', '6\n'] Note: none
```python s = input() l, r, a = 0, 0, 0 for c in s: if c == "(": r += 1 elif r > 0: r -= 1 a += 2 print(a) ```
3.972054
11
A
Increasing Sequence
PROGRAMMING
900
[ "constructive algorithms", "implementation", "math" ]
A. Increasing Sequence
1
64
A sequence *a*0,<=*a*1,<=...,<=*a**t*<=-<=1 is called increasing if *a**i*<=-<=1<=&lt;<=*a**i* for each *i*:<=0<=&lt;<=*i*<=&lt;<=*t*. You are given a sequence *b*0,<=*b*1,<=...,<=*b**n*<=-<=1 and a positive integer *d*. In each move you may choose one element of the given sequence and add *d* to it. What is the least number of moves required to make the given sequence increasing?
The first line of the input contains two integer numbers *n* and *d* (2<=≤<=*n*<=≤<=2000,<=1<=≤<=*d*<=≤<=106). The second line contains space separated sequence *b*0,<=*b*1,<=...,<=*b**n*<=-<=1 (1<=≤<=*b**i*<=≤<=106).
Output the minimal number of moves needed to make the sequence increasing.
[ "4 2\n1 3 3 2\n" ]
[ "3\n" ]
none
0
[ { "input": "4 2\n1 3 3 2", "output": "3" }, { "input": "2 1\n1 1", "output": "1" }, { "input": "2 1\n2 5", "output": "0" }, { "input": "2 1\n1 2", "output": "0" }, { "input": "2 1\n1 1", "output": "1" }, { "input": "2 7\n10 20", "output": "0" }, { "input": "2 7\n1 1", "output": "1" }, { "input": "3 3\n18 1 9", "output": "10" }, { "input": "3 3\n15 17 9", "output": "3" }, { "input": "3 3\n10 9 12", "output": "2" }, { "input": "10 3\n2 1 17 10 5 16 8 4 15 17", "output": "31" }, { "input": "10 3\n6 11 4 12 22 15 23 26 24 26", "output": "13" }, { "input": "10 3\n10 24 13 15 18 14 15 26 33 35", "output": "29" }, { "input": "100 3\n529 178 280 403 326 531 671 427 188 866 669 646 421 804 494 609 53 1012 211 243 887 833 900 543 226 42 859 718 454 372 971 692 846 770 511 395 499 479 641 756 115 269 206 45 1039 727 400 779 859 614 146 214 196 919 702 959 380 830 535 878 859 784 316 305 782 924 536 243 236 978 564 150 291 877 808 983 537 839 490 120 168 838 267 650 900 170 211 504 326 771 895 984 994 483 776 100 471 1078 317 580", "output": "15717" }, { "input": "100 3\n329 226 331 909 962 112 837 1005 194 818 506 416 125 648 367 459 400 582 989 547 329 438 234 121 272 226 821 376 834 427 718 164 834 113 654 177 737 212 169 696 744 180 89 944 233 147 667 990 809 1072 1085 1093 814 265 1067 312 833 572 303 901 1032 504 185 817 389 158 613 723 239 269 911 352 769 404 225 822 897 606 947 323 913 804 923 1084 552 901 486 249 209 898 847 610 728 1122 986 669 1116 1076 367 327", "output": "16133" } ]
1,369,517,882
2,147,483,647
Python 3
TIME_LIMIT_EXCEEDED
TESTS
15
1,000
5,222,400
import math import re from fractions import Fraction class Task: b = [] d = 0 answer = 0 def __init__(self): n, self.d = [int(x) for x in input().split()] self.b = [int(x) for x in input().split()] def solve(self): b, d = self.b, self.d for i in range(1, len(b)): while b[i] <= b[i - 1]: b[i] += d self.answer += 1 def printAnswer(self): print(self.answer) task = Task() task.solve() task.printAnswer()
Title: Increasing Sequence Time Limit: 1 seconds Memory Limit: 64 megabytes Problem Description: A sequence *a*0,<=*a*1,<=...,<=*a**t*<=-<=1 is called increasing if *a**i*<=-<=1<=&lt;<=*a**i* for each *i*:<=0<=&lt;<=*i*<=&lt;<=*t*. You are given a sequence *b*0,<=*b*1,<=...,<=*b**n*<=-<=1 and a positive integer *d*. In each move you may choose one element of the given sequence and add *d* to it. What is the least number of moves required to make the given sequence increasing? Input Specification: The first line of the input contains two integer numbers *n* and *d* (2<=≤<=*n*<=≤<=2000,<=1<=≤<=*d*<=≤<=106). The second line contains space separated sequence *b*0,<=*b*1,<=...,<=*b**n*<=-<=1 (1<=≤<=*b**i*<=≤<=106). Output Specification: Output the minimal number of moves needed to make the sequence increasing. Demo Input: ['4 2\n1 3 3 2\n'] Demo Output: ['3\n'] Note: none
```python import math import re from fractions import Fraction class Task: b = [] d = 0 answer = 0 def __init__(self): n, self.d = [int(x) for x in input().split()] self.b = [int(x) for x in input().split()] def solve(self): b, d = self.b, self.d for i in range(1, len(b)): while b[i] <= b[i - 1]: b[i] += d self.answer += 1 def printAnswer(self): print(self.answer) task = Task() task.solve() task.printAnswer() ```
0
339
A
Helpful Maths
PROGRAMMING
800
[ "greedy", "implementation", "sortings", "strings" ]
null
null
Xenia the beginner mathematician is a third year student at elementary school. She is now learning the addition operation. The teacher has written down the sum of multiple numbers. Pupils should calculate the sum. To make the calculation easier, the sum only contains numbers 1, 2 and 3. Still, that isn't enough for Xenia. She is only beginning to count, so she can calculate a sum only if the summands follow in non-decreasing order. For example, she can't calculate sum 1+3+2+1 but she can calculate sums 1+1+2 and 3+3. You've got the sum that was written on the board. Rearrange the summans and print the sum in such a way that Xenia can calculate the sum.
The first line contains a non-empty string *s* — the sum Xenia needs to count. String *s* contains no spaces. It only contains digits and characters "+". Besides, string *s* is a correct sum of numbers 1, 2 and 3. String *s* is at most 100 characters long.
Print the new sum that Xenia can count.
[ "3+2+1\n", "1+1+3+1+3\n", "2\n" ]
[ "1+2+3\n", "1+1+1+3+3\n", "2\n" ]
none
500
[ { "input": "3+2+1", "output": "1+2+3" }, { "input": "1+1+3+1+3", "output": "1+1+1+3+3" }, { "input": "2", "output": "2" }, { "input": "2+2+1+1+3", "output": "1+1+2+2+3" }, { "input": "2+1+2+2+2+3+1+3+1+2", "output": "1+1+1+2+2+2+2+2+3+3" }, { "input": "1+2+1+2+2+2+2+1+3+3", "output": "1+1+1+2+2+2+2+2+3+3" }, { "input": "2+3+3+1+2+2+2+1+1+2+1+3+2+2+3+3+2+2+3+3+3+1+1+1+3+3+3+2+1+3+2+3+2+1+1+3+3+3+1+2+2+1+2+2+1+2+1+3+1+1", "output": "1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+3+3+3+3+3+3+3+3+3+3+3+3+3+3+3+3+3" }, { "input": "1", "output": "1" }, { "input": "2+1+2+2+1+3+2+3+1+1+2+1+2+2+3+1+1+3+3+3+2+2+3+2+2+2+1+2+1+2+3+2+2+2+1+3+1+3+3+3+1+2+1+2+2+2+2+3+1+1", "output": "1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+3+3+3+3+3+3+3+3+3+3+3+3+3" }, { "input": "2+2+1+1+1+3+1+1+3+3+2+3+1+3+1+1+3+1+1+2+2+2+2+1+2+1+2+1+1+1+3+1+3+2+3+2+3+3+1+1+1+2+3+2+1+3+1+3+2+2", "output": "1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+3+3+3+3+3+3+3+3+3+3+3+3+3+3" }, { "input": "3+2+3+3+2+2+1+2+1+2+3+1+2+3+2+3+2+1+2+2+1+1+2+2+3+2+1+3+1+1+3+2+2+2+2+3+3+2+2+3+3+1+1+2+3+3+2+3+3+3", "output": "1+1+1+1+1+1+1+1+1+1+1+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+3+3+3+3+3+3+3+3+3+3+3+3+3+3+3+3+3+3" }, { "input": "3", "output": "3" }, { "input": "1+1", "output": "1+1" }, { "input": "1+2", "output": "1+2" }, { "input": "1+3", "output": "1+3" }, { "input": "2+1", "output": "1+2" }, { "input": "2+2", "output": "2+2" }, { "input": "2+3", "output": "2+3" }, { "input": "3+1", "output": "1+3" }, { "input": "3+2", "output": "2+3" }, { "input": "3+3", "output": "3+3" } ]
1,700,048,348
2,147,483,647
Python 3
OK
TESTS
21
92
0
m=input() l=m.split('+') l.sort() m='' for x in l: m+=f'{x}' print('+'.join(m))
Title: Helpful Maths Time Limit: None seconds Memory Limit: None megabytes Problem Description: Xenia the beginner mathematician is a third year student at elementary school. She is now learning the addition operation. The teacher has written down the sum of multiple numbers. Pupils should calculate the sum. To make the calculation easier, the sum only contains numbers 1, 2 and 3. Still, that isn't enough for Xenia. She is only beginning to count, so she can calculate a sum only if the summands follow in non-decreasing order. For example, she can't calculate sum 1+3+2+1 but she can calculate sums 1+1+2 and 3+3. You've got the sum that was written on the board. Rearrange the summans and print the sum in such a way that Xenia can calculate the sum. Input Specification: The first line contains a non-empty string *s* — the sum Xenia needs to count. String *s* contains no spaces. It only contains digits and characters "+". Besides, string *s* is a correct sum of numbers 1, 2 and 3. String *s* is at most 100 characters long. Output Specification: Print the new sum that Xenia can count. Demo Input: ['3+2+1\n', '1+1+3+1+3\n', '2\n'] Demo Output: ['1+2+3\n', '1+1+1+3+3\n', '2\n'] Note: none
```python m=input() l=m.split('+') l.sort() m='' for x in l: m+=f'{x}' print('+'.join(m)) ```
3
43
A
Football
PROGRAMMING
1,000
[ "strings" ]
A. Football
2
256
One day Vasya decided to have a look at the results of Berland 1910 Football Championship’s finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process. On the whole there are *n* lines in that description each of which described one goal. Every goal was marked with the name of the team that had scored it. Help Vasya, learn the name of the team that won the finals. It is guaranteed that the match did not end in a tie.
The first line contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of lines in the description. Then follow *n* lines — for each goal the names of the teams that scored it. The names are non-empty lines consisting of uppercase Latin letters whose lengths do not exceed 10 symbols. It is guaranteed that the match did not end in a tie and the description contains no more than two different teams.
Print the name of the winning team. We remind you that in football the team that scores more goals is considered the winner.
[ "1\nABC\n", "5\nA\nABA\nABA\nA\nA\n" ]
[ "ABC\n", "A\n" ]
none
500
[ { "input": "1\nABC", "output": "ABC" }, { "input": "5\nA\nABA\nABA\nA\nA", "output": "A" }, { "input": "2\nXTSJEP\nXTSJEP", "output": "XTSJEP" }, { "input": "3\nXZYDJAEDZ\nXZYDJAEDZ\nXZYDJAEDZ", "output": "XZYDJAEDZ" }, { "input": "3\nQCCYXL\nQCCYXL\nAXGLFQDD", "output": "QCCYXL" }, { "input": "3\nAZID\nEERWBC\nEERWBC", "output": "EERWBC" }, { "input": "3\nHNCGYL\nHNCGYL\nHNCGYL", "output": "HNCGYL" }, { "input": "4\nZZWZTG\nZZWZTG\nZZWZTG\nZZWZTG", "output": "ZZWZTG" }, { "input": "4\nA\nA\nKUDLJMXCSE\nA", "output": "A" }, { "input": "5\nPHBTW\nPHBTW\nPHBTW\nPHBTW\nPHBTW", "output": "PHBTW" }, { "input": "5\nPKUZYTFYWN\nPKUZYTFYWN\nSTC\nPKUZYTFYWN\nPKUZYTFYWN", "output": "PKUZYTFYWN" }, { "input": "5\nHH\nHH\nNTQWPA\nNTQWPA\nHH", "output": "HH" }, { "input": "10\nW\nW\nW\nW\nW\nD\nW\nD\nD\nW", "output": "W" }, { "input": "19\nXBCP\nTGACNIH\nXBCP\nXBCP\nXBCP\nXBCP\nXBCP\nTGACNIH\nXBCP\nXBCP\nXBCP\nXBCP\nXBCP\nTGACNIH\nXBCP\nXBCP\nTGACNIH\nTGACNIH\nXBCP", "output": "XBCP" }, { "input": "33\nOWQWCKLLF\nOWQWCKLLF\nOWQWCKLLF\nPYPAS\nPYPAS\nPYPAS\nOWQWCKLLF\nPYPAS\nOWQWCKLLF\nPYPAS\nPYPAS\nOWQWCKLLF\nOWQWCKLLF\nOWQWCKLLF\nPYPAS\nOWQWCKLLF\nPYPAS\nPYPAS\nPYPAS\nPYPAS\nOWQWCKLLF\nPYPAS\nPYPAS\nOWQWCKLLF\nOWQWCKLLF\nPYPAS\nOWQWCKLLF\nOWQWCKLLF\nPYPAS\nPYPAS\nOWQWCKLLF\nPYPAS\nPYPAS", "output": "PYPAS" }, { "input": "51\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC\nNC", "output": "NC" }, { "input": "89\nH\nVOCI\nVOCI\nH\nVOCI\nH\nH\nVOCI\nVOCI\nVOCI\nH\nH\nH\nVOCI\nVOCI\nVOCI\nH\nVOCI\nVOCI\nH\nVOCI\nVOCI\nVOCI\nH\nVOCI\nH\nVOCI\nH\nVOCI\nH\nVOCI\nVOCI\nH\nVOCI\nVOCI\nVOCI\nVOCI\nVOCI\nVOCI\nH\nVOCI\nVOCI\nVOCI\nVOCI\nH\nVOCI\nH\nH\nVOCI\nH\nVOCI\nH\nVOCI\nVOCI\nVOCI\nVOCI\nVOCI\nVOCI\nVOCI\nH\nH\nVOCI\nH\nH\nVOCI\nH\nVOCI\nH\nVOCI\nVOCI\nH\nVOCI\nVOCI\nVOCI\nVOCI\nVOCI\nVOCI\nVOCI\nH\nH\nH\nH\nH\nVOCI\nH\nVOCI\nH\nVOCI\nVOCI", "output": "VOCI" }, { "input": "100\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nM\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA\nHA", "output": "HA" }, { "input": "100\nG\nG\nS\nS\nG\nG\nS\nS\nG\nS\nS\nS\nG\nS\nG\nG\nS\nG\nS\nS\nG\nS\nS\nS\nS\nS\nG\nS\nG\nS\nS\nG\nG\nG\nS\nS\nS\nS\nG\nS\nS\nG\nG\nG\nG\nG\nS\nG\nG\nS\nS\nS\nS\nS\nG\nG\nS\nG\nG\nG\nG\nG\nS\nS\nG\nS\nS\nS\nS\nG\nS\nS\nG\nS\nG\nG\nG\nG\nG\nG\nG\nG\nG\nG\nG\nS\nS\nG\nS\nS\nS\nS\nG\nG\nG\nS\nG\nG\nG\nS", "output": "G" }, { "input": "100\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nOBH\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL\nWL", "output": "WL" } ]
1,611,234,260
2,147,483,647
Python 3
RUNTIME_ERROR
TESTS
0
92
307,200
n = int(input()) description = [] for x in range(0, n): team = input() description.add(team) team1 = description[0] for a in range(0, n): if descripiton[a] != team1: team2 = description[a] break team1Count, team2Count = 0, 0 for i in range(0, n): if description[i] == team1: team1Count += 1 else: team2Count +=1 if team1Count > team2Count: print(team1) else: print(team2)
Title: Football Time Limit: 2 seconds Memory Limit: 256 megabytes Problem Description: One day Vasya decided to have a look at the results of Berland 1910 Football Championship’s finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process. On the whole there are *n* lines in that description each of which described one goal. Every goal was marked with the name of the team that had scored it. Help Vasya, learn the name of the team that won the finals. It is guaranteed that the match did not end in a tie. Input Specification: The first line contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of lines in the description. Then follow *n* lines — for each goal the names of the teams that scored it. The names are non-empty lines consisting of uppercase Latin letters whose lengths do not exceed 10 symbols. It is guaranteed that the match did not end in a tie and the description contains no more than two different teams. Output Specification: Print the name of the winning team. We remind you that in football the team that scores more goals is considered the winner. Demo Input: ['1\nABC\n', '5\nA\nABA\nABA\nA\nA\n'] Demo Output: ['ABC\n', 'A\n'] Note: none
```python n = int(input()) description = [] for x in range(0, n): team = input() description.add(team) team1 = description[0] for a in range(0, n): if descripiton[a] != team1: team2 = description[a] break team1Count, team2Count = 0, 0 for i in range(0, n): if description[i] == team1: team1Count += 1 else: team2Count +=1 if team1Count > team2Count: print(team1) else: print(team2) ```
-1
714
A
Meeting of Old Friends
PROGRAMMING
1,100
[ "implementation", "math" ]
null
null
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.
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*<=≤<=1018, *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.
Print one integer — the number of minutes Sonya and Filya will be able to spend together.
[ "1 10 9 20 1\n", "1 100 50 200 75\n" ]
[ "2\n", "50\n" ]
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.
500
[ { "input": "1 10 9 20 1", "output": "2" }, { "input": "1 100 50 200 75", "output": "50" }, { "input": "6 6 5 8 9", "output": "1" }, { "input": "1 1000000000 1 1000000000 1", "output": "999999999" }, { "input": "5 100 8 8 8", "output": "0" }, { "input": "1 1000000000000000000 2 99999999999999999 1000000000", "output": "99999999999999997" }, { "input": "1 1 1 1 1", "output": "0" }, { "input": "1 2 3 4 5", "output": "0" }, { "input": "1 1000000000 2 999999999 3141592", "output": "999999997" }, { "input": "24648817341102 41165114064236 88046848035 13602161452932 10000831349205", "output": "0" }, { "input": "1080184299348 34666828555290 6878390132365 39891656267344 15395310291636", "output": "27788438422925" }, { "input": "11814 27385 22309 28354 23595", "output": "5076" }, { "input": "4722316546398 36672578279675 796716437180 33840047334985 13411035401708", "output": "29117730788587" }, { "input": "14300093617438 14381698008501 6957847034861 32510754974307 66056597033082", "output": "81604391064" }, { "input": "700062402405871919 762322967106512617 297732773882447821 747309903322652819 805776739998108178", "output": "47247500916780901" }, { "input": "59861796371397621 194872039092923459 668110259718450585 841148673332698972 928360292123223779", "output": "0" }, { "input": "298248781360904821 346420922793050061 237084570581741798 726877079564549183 389611850470532358", "output": "48172141432145241" }, { "input": "420745791717606818 864206437350900994 764928840030524015 966634105370748487 793326512080703489", "output": "99277597320376979" }, { "input": "519325240668210886 776112702001665034 360568516809443669 875594219634943179 994594983925273138", "output": "256787461333454149" }, { "input": "170331212821058551 891149660635282032 125964175621755330 208256491683509799 526532153531983174", "output": "37925278862451249" }, { "input": "1 3 3 5 3", "output": "0" }, { "input": "1 5 8 10 9", "output": "0" }, { "input": "1 2 4 5 10", "output": "0" }, { "input": "1 2 2 3 5", "output": "1" }, { "input": "2 4 3 7 3", "output": "1" }, { "input": "1 2 9 10 1", "output": "0" }, { "input": "5 15 1 10 5", "output": "5" }, { "input": "1 4 9 20 25", "output": "0" }, { "input": "2 4 1 2 5", "output": "1" }, { "input": "10 1000 1 100 2", "output": "91" }, { "input": "1 3 3 8 10", "output": "1" }, { "input": "4 6 6 8 9", "output": "1" }, { "input": "2 3 1 4 3", "output": "1" }, { "input": "1 2 2 3 100", "output": "1" }, { "input": "1 2 100 120 2", "output": "0" }, { "input": "1 3 5 7 4", "output": "0" }, { "input": "1 3 5 7 5", "output": "0" }, { "input": "1 4 8 10 6", "output": "0" }, { "input": "1 2 5 6 100", "output": "0" }, { "input": "1 2 5 10 20", "output": "0" }, { "input": "1 2 5 6 7", "output": "0" }, { "input": "2 5 7 12 6", "output": "0" }, { "input": "10 20 50 100 80", "output": "0" }, { "input": "1 2 5 10 2", "output": "0" }, { "input": "1 2 5 6 4", "output": "0" }, { "input": "5 9 1 2 3", "output": "0" }, { "input": "50 100 1 20 3", "output": "0" }, { "input": "10 20 3 7 30", "output": "0" }, { "input": "1 5 10 10 100", "output": "0" }, { "input": "100 101 1 2 3", "output": "0" }, { "input": "1 5 10 20 6", "output": "0" }, { "input": "1 10 15 25 5", "output": "0" }, { "input": "1 2 5 10 3", "output": "0" }, { "input": "2 3 5 6 100", "output": "0" }, { "input": "1 2 4 5 6", "output": "0" }, { "input": "6 10 1 2 40", "output": "0" }, { "input": "20 30 1 5 1", "output": "0" }, { "input": "20 40 50 100 50", "output": "0" }, { "input": "1 1 4 9 2", "output": "0" }, { "input": "1 2 5 6 1", "output": "0" }, { "input": "1 100 400 500 450", "output": "0" }, { "input": "5 6 1 2 5", "output": "0" }, { "input": "1 10 21 30 50", "output": "0" }, { "input": "100 200 300 400 101", "output": "0" }, { "input": "2 8 12 16 9", "output": "0" }, { "input": "1 5 7 9 6", "output": "0" }, { "input": "300 400 100 200 101", "output": "0" }, { "input": "1 2 2 3 10", "output": "1" }, { "input": "1 10 100 200 5", "output": "0" }, { "input": "1 3 3 4 4", "output": "1" }, { "input": "10 20 30 40 25", "output": "0" }, { "input": "1 2 5 10 1", "output": "0" }, { "input": "2 4 8 10 1", "output": "0" }, { "input": "2 5 10 15 7", "output": "0" }, { "input": "100 200 5 10 1", "output": "0" }, { "input": "1 2 100 200 300", "output": "0" }, { "input": "30 100 10 20 25", "output": "0" }, { "input": "10 20 1 5 6", "output": "0" }, { "input": "4 5 1 2 4", "output": "0" }, { "input": "11 100 1 9 1000", "output": "0" }, { "input": "1 1 10 10 228", "output": "0" }, { "input": "5 7 10 20 15", "output": "0" }, { "input": "1 3 8 9 7", "output": "0" }, { "input": "1 10 2 8 8", "output": "6" }, { "input": "1 5 9 15 1", "output": "0" }, { "input": "1 3 5 6 12", "output": "0" }, { "input": "1 100 500 1000 3", "output": "0" }, { "input": "1 1 1 1 2", "output": "1" }, { "input": "1 1000 100 1000 200", "output": "900" }, { "input": "4 5 1 4 1", "output": "1" }, { "input": "1 5 5 7 3", "output": "1" }, { "input": "1 4 4 10 11", "output": "1" }, { "input": "1 1 3 4 100", "output": "0" }, { "input": "1 4 3 5 6", "output": "2" }, { "input": "10 100 20 30 40", "output": "11" }, { "input": "5 9 1 11 7", "output": "4" } ]
1,626,892,011
2,147,483,647
Python 3
OK
TESTS
96
62
6,758,400
l1,r1,l2,r2,k=map(int,input().split()) x,y=max(l1,l2),min(r1,r2) m=y-x+1 if x<=k<=y: m-=1 print(max(m,0))
Title: Meeting of Old Friends Time Limit: None seconds Memory Limit: None megabytes Problem Description: 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 Specification: 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*<=≤<=1018, *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 Specification: Print one integer — the number of minutes Sonya and Filya will be able to spend together. Demo Input: ['1 10 9 20 1\n', '1 100 50 200 75\n'] Demo Output: ['2\n', '50\n'] 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.
```python l1,r1,l2,r2,k=map(int,input().split()) x,y=max(l1,l2),min(r1,r2) m=y-x+1 if x<=k<=y: m-=1 print(max(m,0)) ```
3
664
A
Complicated GCD
PROGRAMMING
800
[ "math", "number theory" ]
null
null
Greatest common divisor *GCD*(*a*,<=*b*) of two positive integers *a* and *b* is equal to the biggest integer *d* such that both integers *a* and *b* are divisible by *d*. There are many efficient algorithms to find greatest common divisor *GCD*(*a*,<=*b*), for example, Euclid algorithm. Formally, find the biggest integer *d*, such that all integers *a*,<=*a*<=+<=1,<=*a*<=+<=2,<=...,<=*b* are divisible by *d*. To make the problem even more complicated we allow *a* and *b* to be up to googol, 10100 — such number do not fit even in 64-bit integer type!
The only line of the input contains two integers *a* and *b* (1<=≤<=*a*<=≤<=*b*<=≤<=10100).
Output one integer — greatest common divisor of all integers from *a* to *b* inclusive.
[ "1 2\n", "61803398874989484820458683436563811772030917980576 61803398874989484820458683436563811772030917980576\n" ]
[ "1\n", "61803398874989484820458683436563811772030917980576\n" ]
none
500
[ { "input": "1 2", "output": "1" }, { "input": "61803398874989484820458683436563811772030917980576 61803398874989484820458683436563811772030917980576", "output": "61803398874989484820458683436563811772030917980576" }, { "input": "1 100", "output": "1" }, { "input": "100 100000", "output": "1" }, { "input": "12345 67890123456789123457", "output": "1" }, { "input": "1 1", "output": "1" }, { "input": "2 2", "output": "2" }, { "input": "8392739158839273915883927391588392739158839273915883927391588392739158839273915883927391588392739158 8392739158839273915883927391588392739158839273915883927391588392739158839273915883927391588392739158", "output": "8392739158839273915883927391588392739158839273915883927391588392739158839273915883927391588392739158" }, { "input": "1 10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", "output": "1" }, { "input": "8328748239473982794239847237438782379810988324751 9328748239473982794239847237438782379810988324751", "output": "1" }, { "input": "1029398958432734901284327523909481928483573793 1029398958432734901284327523909481928483573794", "output": "1" }, { "input": "10000 1000000000", "output": "1" }, { "input": "10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", "output": "10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" }, { "input": "11210171722243 65715435710585778347", "output": "1" }, { "input": "2921881079263974825226940825843 767693191032295360887755303860323261471", "output": "1" }, { "input": "8025352957265704896940312528736939363590612908210603 96027920417708260814607687034511406492969694925539085", "output": "1" }, { "input": "23510978780782786207241069904470895053213996267165977112058175452757132930 210352653280909370107314249722987050753257161175393375412301228883856435481424", "output": "1" }, { "input": "8150070767079366215626260746398623663859344142817267779361251788637547414925170226504788118262 49924902262298336032630839998470954964895251605110946547855439236151401194070172107435992986913614", "output": "1" }, { "input": "15943150466658398903 15943150466658398903", "output": "15943150466658398903" }, { "input": "410470228200245407491525399055972 410470228200245407491525399055972", "output": "410470228200245407491525399055972" }, { "input": "51894705655711504622197349350106792045098781545973899451307 51894705655711504622197349350106792045098781545973899451307", "output": "51894705655711504622197349350106792045098781545973899451307" }, { "input": "60353594589897438036015726222485085035927634677598681595162804007836722215668410 60353594589897438036015726222485085035927634677598681595162804007836722215668410", "output": "60353594589897438036015726222485085035927634677598681595162804007836722215668410" }, { "input": "761733780145118977868180796896376577405349682060892737466239031663476251177476275459280340045369535 761733780145118977868180796896376577405349682060892737466239031663476251177476275459280340045369535", "output": "761733780145118977868180796896376577405349682060892737466239031663476251177476275459280340045369535" }, { "input": "1 2000000000", "output": "1" }, { "input": "13 1928834874", "output": "1" }, { "input": "87 2938984237482934238", "output": "1" }, { "input": "213 413", "output": "1" }, { "input": "3 4", "output": "1" } ]
1,597,056,396
2,147,483,647
Python 3
OK
TESTS
28
124
6,758,400
import math x, y=map(int, input().split()) if x==y: print(x) else: print("1")
Title: Complicated GCD Time Limit: None seconds Memory Limit: None megabytes Problem Description: Greatest common divisor *GCD*(*a*,<=*b*) of two positive integers *a* and *b* is equal to the biggest integer *d* such that both integers *a* and *b* are divisible by *d*. There are many efficient algorithms to find greatest common divisor *GCD*(*a*,<=*b*), for example, Euclid algorithm. Formally, find the biggest integer *d*, such that all integers *a*,<=*a*<=+<=1,<=*a*<=+<=2,<=...,<=*b* are divisible by *d*. To make the problem even more complicated we allow *a* and *b* to be up to googol, 10100 — such number do not fit even in 64-bit integer type! Input Specification: The only line of the input contains two integers *a* and *b* (1<=≤<=*a*<=≤<=*b*<=≤<=10100). Output Specification: Output one integer — greatest common divisor of all integers from *a* to *b* inclusive. Demo Input: ['1 2\n', '61803398874989484820458683436563811772030917980576 61803398874989484820458683436563811772030917980576\n'] Demo Output: ['1\n', '61803398874989484820458683436563811772030917980576\n'] Note: none
```python import math x, y=map(int, input().split()) if x==y: print(x) else: print("1") ```
3
765
D
Artsem and Saunders
PROGRAMMING
1,700
[ "constructive algorithms", "dsu", "math" ]
null
null
Artsem has a friend Saunders from University of Chicago. Saunders presented him with the following problem. Let [*n*] denote the set {1,<=...,<=*n*}. We will also write *f*:<=[*x*]<=→<=[*y*] when a function *f* is defined in integer points 1, ..., *x*, and all its values are integers from 1 to *y*. Now then, you are given a function *f*:<=[*n*]<=→<=[*n*]. Your task is to find a positive integer *m*, and two functions *g*:<=[*n*]<=→<=[*m*], *h*:<=[*m*]<=→<=[*n*], such that *g*(*h*(*x*))<==<=*x* for all , and *h*(*g*(*x*))<==<=*f*(*x*) for all , or determine that finding these is impossible.
The first line contains an integer *n* (1<=≤<=*n*<=≤<=105). The second line contains *n* space-separated integers — values *f*(1),<=...,<=*f*(*n*) (1<=≤<=*f*(*i*)<=≤<=*n*).
If there is no answer, print one integer -1. Otherwise, on the first line print the number *m* (1<=≤<=*m*<=≤<=106). On the second line print *n* numbers *g*(1),<=...,<=*g*(*n*). On the third line print *m* numbers *h*(1),<=...,<=*h*(*m*). If there are several correct answers, you may output any of them. It is guaranteed that if a valid answer exists, then there is an answer satisfying the above restrictions.
[ "3\n1 2 3\n", "3\n2 2 2\n", "2\n2 1\n" ]
[ "3\n1 2 3\n1 2 3\n", "1\n1 1 1\n2\n", "-1\n" ]
none
2,000
[ { "input": "3\n1 2 3", "output": "3\n1 2 3\n1 2 3" }, { "input": "3\n2 2 2", "output": "1\n1 1 1\n2" }, { "input": "2\n2 1", "output": "-1" }, { "input": "1\n1", "output": "1\n1\n1" }, { "input": "2\n2 1", "output": "-1" }, { "input": "2\n2 2", "output": "1\n1 1\n2" }, { "input": "5\n5 5 5 3 5", "output": "-1" }, { "input": "10\n4 4 4 4 4 4 4 4 4 4", "output": "1\n1 1 1 1 1 1 1 1 1 1\n4" }, { "input": "2\n1 2", "output": "2\n1 2\n1 2" }, { "input": "3\n3 2 3", "output": "2\n2 1 2\n2 3" }, { "input": "3\n1 2 1", "output": "2\n1 2 1\n1 2" }, { "input": "4\n4 2 4 4", "output": "2\n2 1 2 2\n2 4" }, { "input": "5\n1 4 5 4 5", "output": "3\n1 2 3 2 3\n1 4 5" }, { "input": "4\n1 2 1 2", "output": "2\n1 2 1 2\n1 2" }, { "input": "5\n1 3 3 4 4", "output": "3\n1 2 2 3 3\n1 3 4" }, { "input": "4\n4 2 2 4", "output": "2\n2 1 1 2\n2 4" }, { "input": "7\n7 3 3 5 5 7 7", "output": "3\n3 1 1 2 2 3 3\n3 5 7" }, { "input": "6\n1 1 1 3 3 3", "output": "-1" }, { "input": "4\n2 2 3 2", "output": "2\n1 1 2 1\n2 3" }, { "input": "6\n1 2 3 4 5 5", "output": "5\n1 2 3 4 5 5\n1 2 3 4 5" }, { "input": "3\n1 1 2", "output": "-1" }, { "input": "4\n3 4 3 4", "output": "2\n1 2 1 2\n3 4" }, { "input": "6\n1 1 1 4 4 4", "output": "2\n1 1 1 2 2 2\n1 4" }, { "input": "4\n1 2 1 1", "output": "2\n1 2 1 1\n1 2" }, { "input": "5\n1 2 3 4 3", "output": "4\n1 2 3 4 3\n1 2 3 4" }, { "input": "4\n2 2 4 4", "output": "2\n1 1 2 2\n2 4" }, { "input": "4\n1 1 3 3", "output": "2\n1 1 2 2\n1 3" }, { "input": "3\n2 2 3", "output": "2\n1 1 2\n2 3" }, { "input": "5\n5 3 3 3 5", "output": "2\n2 1 1 1 2\n3 5" } ]
1,629,214,078
2,147,483,647
Python 3
OK
TESTS
43
248
29,593,600
from collections import defaultdict def solve(n, f): d = defaultdict(set) for i,fi in enumerate(f, 1): d[fi].add(i) m = len(d) g = [0]*n h = [0]*m for i,(fi,ys) in enumerate(d.items()): if fi not in ys: return -1, [], [] h[i] = fi for j in ys: g[j-1] = i+1 return m, g, h n = int(input()) f = list(map(int,input().split())) res, g, h = solve(n, f) print(res) if res > -1: print(' '.join(map(str, g))) print(' '.join(map(str, h)))
Title: Artsem and Saunders Time Limit: None seconds Memory Limit: None megabytes Problem Description: Artsem has a friend Saunders from University of Chicago. Saunders presented him with the following problem. Let [*n*] denote the set {1,<=...,<=*n*}. We will also write *f*:<=[*x*]<=→<=[*y*] when a function *f* is defined in integer points 1, ..., *x*, and all its values are integers from 1 to *y*. Now then, you are given a function *f*:<=[*n*]<=→<=[*n*]. Your task is to find a positive integer *m*, and two functions *g*:<=[*n*]<=→<=[*m*], *h*:<=[*m*]<=→<=[*n*], such that *g*(*h*(*x*))<==<=*x* for all , and *h*(*g*(*x*))<==<=*f*(*x*) for all , or determine that finding these is impossible. Input Specification: The first line contains an integer *n* (1<=≤<=*n*<=≤<=105). The second line contains *n* space-separated integers — values *f*(1),<=...,<=*f*(*n*) (1<=≤<=*f*(*i*)<=≤<=*n*). Output Specification: If there is no answer, print one integer -1. Otherwise, on the first line print the number *m* (1<=≤<=*m*<=≤<=106). On the second line print *n* numbers *g*(1),<=...,<=*g*(*n*). On the third line print *m* numbers *h*(1),<=...,<=*h*(*m*). If there are several correct answers, you may output any of them. It is guaranteed that if a valid answer exists, then there is an answer satisfying the above restrictions. Demo Input: ['3\n1 2 3\n', '3\n2 2 2\n', '2\n2 1\n'] Demo Output: ['3\n1 2 3\n1 2 3\n', '1\n1 1 1\n2\n', '-1\n'] Note: none
```python from collections import defaultdict def solve(n, f): d = defaultdict(set) for i,fi in enumerate(f, 1): d[fi].add(i) m = len(d) g = [0]*n h = [0]*m for i,(fi,ys) in enumerate(d.items()): if fi not in ys: return -1, [], [] h[i] = fi for j in ys: g[j-1] = i+1 return m, g, h n = int(input()) f = list(map(int,input().split())) res, g, h = solve(n, f) print(res) if res > -1: print(' '.join(map(str, g))) print(' '.join(map(str, h))) ```
3
554
A
Kyoya and Photobooks
PROGRAMMING
900
[ "brute force", "math", "strings" ]
null
null
Kyoya Ootori is selling photobooks of the Ouran High School Host Club. He has 26 photos, labeled "a" to "z", and he has compiled them into a photo booklet with some photos in some order (possibly with some photos being duplicated). A photo booklet can be described as a string of lowercase letters, consisting of the photos in the booklet in order. He now wants to sell some "special edition" photobooks, each with one extra photo inserted anywhere in the book. He wants to make as many distinct photobooks as possible, so he can make more money. He asks Haruhi, how many distinct photobooks can he make by inserting one extra photo into the photobook he already has? Please help Haruhi solve this problem.
The first line of input will be a single string *s* (1<=≤<=|*s*|<=≤<=20). String *s* consists only of lowercase English letters.
Output a single integer equal to the number of distinct photobooks Kyoya Ootori can make.
[ "a\n", "hi\n" ]
[ "51\n", "76\n" ]
In the first case, we can make 'ab','ac',...,'az','ba','ca',...,'za', and 'aa', producing a total of 51 distinct photo booklets.
250
[ { "input": "a", "output": "51" }, { "input": "hi", "output": "76" }, { "input": "y", "output": "51" }, { "input": "kgan", "output": "126" }, { "input": "zoabkyuvus", "output": "276" }, { "input": "spyemhyznjieyhhbk", "output": "451" }, { "input": "xulsyfkuizjauadjjopu", "output": "526" }, { "input": "e", "output": "51" }, { "input": "zv", "output": "76" }, { "input": "jgv", "output": "101" }, { "input": "zsfo", "output": "126" }, { "input": "jselr", "output": "151" }, { "input": "dwemig", "output": "176" }, { "input": "mddoxsf", "output": "201" }, { "input": "jgirkrmi", "output": "226" }, { "input": "spkxurcum", "output": "251" }, { "input": "fykkiubdkt", "output": "276" }, { "input": "fznbcxsxygs", "output": "301" }, { "input": "qcrvrdqcbtou", "output": "326" }, { "input": "qktrbjzrqgmlr", "output": "351" }, { "input": "foamodbvptlxxg", "output": "376" }, { "input": "ydzpjhsidipricw", "output": "401" }, { "input": "lpfpndmjfvqejdgf", "output": "426" }, { "input": "ofkvparuvjtggnmab", "output": "451" }, { "input": "xxncfutrtxcwdzwbgs", "output": "476" }, { "input": "zovhffccflkgqncsdte", "output": "501" }, { "input": "cskgsxywlvfeicoueglr", "output": "526" }, { "input": "gggggggggggggggggggg", "output": "526" }, { "input": "qdqdddqddqqddqddqdqd", "output": "526" }, { "input": "takttttaakaaktakttkt", "output": "526" }, { "input": "coccoooogogcgocccmcg", "output": "526" }, { "input": "kskkskkkssksssk", "output": "401" }, { "input": "lllllllllllllll", "output": "401" } ]
1,440,678,779
2,147,483,647
Python 3
OK
TESTS
33
62
0
s = input() print((len(s) + 1) * 25 + 1)
Title: Kyoya and Photobooks Time Limit: None seconds Memory Limit: None megabytes Problem Description: Kyoya Ootori is selling photobooks of the Ouran High School Host Club. He has 26 photos, labeled "a" to "z", and he has compiled them into a photo booklet with some photos in some order (possibly with some photos being duplicated). A photo booklet can be described as a string of lowercase letters, consisting of the photos in the booklet in order. He now wants to sell some "special edition" photobooks, each with one extra photo inserted anywhere in the book. He wants to make as many distinct photobooks as possible, so he can make more money. He asks Haruhi, how many distinct photobooks can he make by inserting one extra photo into the photobook he already has? Please help Haruhi solve this problem. Input Specification: The first line of input will be a single string *s* (1<=≤<=|*s*|<=≤<=20). String *s* consists only of lowercase English letters. Output Specification: Output a single integer equal to the number of distinct photobooks Kyoya Ootori can make. Demo Input: ['a\n', 'hi\n'] Demo Output: ['51\n', '76\n'] Note: In the first case, we can make 'ab','ac',...,'az','ba','ca',...,'za', and 'aa', producing a total of 51 distinct photo booklets.
```python s = input() print((len(s) + 1) * 25 + 1) ```
3
253
A
Boys and Girls
PROGRAMMING
1,100
[ "greedy" ]
null
null
There are *n* boys and *m* girls studying in the class. They should stand in a line so that boys and girls alternated there as much as possible. Let's assume that positions in the line are indexed from left to right by numbers from 1 to *n*<=+<=*m*. Then the number of integers *i* (1<=≤<=*i*<=&lt;<=*n*<=+<=*m*) such that positions with indexes *i* and *i*<=+<=1 contain children of different genders (position *i* has a girl and position *i*<=+<=1 has a boy or vice versa) must be as large as possible. Help the children and tell them how to form the line.
The single line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100), separated by a space.
Print a line of *n*<=+<=*m* characters. Print on the *i*-th position of the line character "B", if the *i*-th position of your arrangement should have a boy and "G", if it should have a girl. Of course, the number of characters "B" should equal *n* and the number of characters "G" should equal *m*. If there are multiple optimal solutions, print any of them.
[ "3 3\n", "4 2\n" ]
[ "GBGBGB\n", "BGBGBB\n" ]
In the first sample another possible answer is BGBGBG. In the second sample answer BBGBGB is also optimal.
500
[ { "input": "3 3", "output": "GBGBGB" }, { "input": "4 2", "output": "BGBGBB" }, { "input": "5 5", "output": "GBGBGBGBGB" }, { "input": "6 4", "output": "BGBGBGBGBB" }, { "input": "100 1", "output": "BGBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB" }, { "input": "76 48", "output": "BGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBBBBBBBBBBBBBBBBBBBBBBBBBBBB" }, { "input": "100 90", "output": "BGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBBBBBBBBBB" }, { "input": "90 100", "output": "GBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGGGGGGGGGG" }, { "input": "1 98", "output": "GBGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG" }, { "input": "1 100", "output": "GBGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG" }, { "input": "56 98", "output": "GBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG" }, { "input": "89 89", "output": "GBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGB" }, { "input": "18 94", "output": "GBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG" }, { "input": "84 27", "output": "BGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB" }, { "input": "1 1", "output": "GB" }, { "input": "1 2", "output": "GBG" }, { "input": "2 1", "output": "BGB" }, { "input": "1 34", "output": "GBGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG" }, { "input": "46 2", "output": "BGBGBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB" }, { "input": "99 3", "output": "BGBGBGBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB" }, { "input": "10 100", "output": "GBGBGBGBGBGBGBGBGBGBGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG" }, { "input": "100 100", "output": "GBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGBGB" }, { "input": "1 4", "output": "GBGGG" } ]
1,619,878,778
2,147,483,647
PyPy 3
RUNTIME_ERROR
TESTS
0
218
2,150,400
n,m=[int(x) for x in input().split()] if n>m: for i in range(m): print("BG",end="") for i in range(n-m): print("B",end="") else: for i in range(n): print("GB",end="") for i in range(m-n): print("G",end="")
Title: Boys and Girls Time Limit: None seconds Memory Limit: None megabytes Problem Description: There are *n* boys and *m* girls studying in the class. They should stand in a line so that boys and girls alternated there as much as possible. Let's assume that positions in the line are indexed from left to right by numbers from 1 to *n*<=+<=*m*. Then the number of integers *i* (1<=≤<=*i*<=&lt;<=*n*<=+<=*m*) such that positions with indexes *i* and *i*<=+<=1 contain children of different genders (position *i* has a girl and position *i*<=+<=1 has a boy or vice versa) must be as large as possible. Help the children and tell them how to form the line. Input Specification: The single line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100), separated by a space. Output Specification: Print a line of *n*<=+<=*m* characters. Print on the *i*-th position of the line character "B", if the *i*-th position of your arrangement should have a boy and "G", if it should have a girl. Of course, the number of characters "B" should equal *n* and the number of characters "G" should equal *m*. If there are multiple optimal solutions, print any of them. Demo Input: ['3 3\n', '4 2\n'] Demo Output: ['GBGBGB\n', 'BGBGBB\n'] Note: In the first sample another possible answer is BGBGBG. In the second sample answer BBGBGB is also optimal.
```python n,m=[int(x) for x in input().split()] if n>m: for i in range(m): print("BG",end="") for i in range(n-m): print("B",end="") else: for i in range(n): print("GB",end="") for i in range(m-n): print("G",end="") ```
-1
168
A
Wizards and Demonstration
PROGRAMMING
900
[ "implementation", "math" ]
null
null
Some country is populated by wizards. They want to organize a demonstration. There are *n* people living in the city, *x* of them are the wizards who will surely go to the demonstration. Other city people (*n*<=-<=*x* people) do not support the wizards and aren't going to go to the demonstration. We know that the city administration will react only to the demonstration involving at least *y* percent of the city people. Having considered the matter, the wizards decided to create clone puppets which can substitute the city people on the demonstration. So all in all, the demonstration will involve only the wizards and their puppets. The city administration cannot tell the difference between a puppet and a person, so, as they calculate the percentage, the administration will consider the city to be consisting of only *n* people and not containing any clone puppets. Help the wizards and find the minimum number of clones to create to that the demonstration had no less than *y* percent of the city people.
The first line contains three space-separated integers, *n*, *x*, *y* (1<=≤<=*n*,<=*x*,<=*y*<=≤<=104,<=*x*<=≤<=*n*) — the number of citizens in the city, the number of wizards and the percentage the administration needs, correspondingly. Please note that *y* can exceed 100 percent, that is, the administration wants to see on a demonstration more people that actually live in the city (<=&gt;<=*n*).
Print a single integer — the answer to the problem, the minimum number of clones to create, so that the demonstration involved no less than *y* percent of *n* (the real total city population).
[ "10 1 14\n", "20 10 50\n", "1000 352 146\n" ]
[ "1\n", "0\n", "1108\n" ]
In the first sample it is necessary that at least 14% of 10 people came to the demonstration. As the number of people should be integer, then at least two people should come. There is only one wizard living in the city and he is going to come. That isn't enough, so he needs to create one clone. In the second sample 10 people should come to the demonstration. The city has 10 wizards. They will all come to the demonstration, so nobody has to create any clones.
500
[ { "input": "10 1 14", "output": "1" }, { "input": "20 10 50", "output": "0" }, { "input": "1000 352 146", "output": "1108" }, { "input": "68 65 20", "output": "0" }, { "input": "78 28 27", "output": "0" }, { "input": "78 73 58", "output": "0" }, { "input": "70 38 66", "output": "9" }, { "input": "54 4 38", "output": "17" }, { "input": "3 1 69", "output": "2" }, { "input": "11 9 60", "output": "0" }, { "input": "71 49 65", "output": "0" }, { "input": "78 55 96", "output": "20" }, { "input": "2765 768 9020", "output": "248635" }, { "input": "3478 1728 9727", "output": "336578" }, { "input": "9678 6173 5658", "output": "541409" }, { "input": "1138 570 6666", "output": "75290" }, { "input": "7754 204 9038", "output": "700603" }, { "input": "8403 7401 4769", "output": "393339" }, { "input": "4909 2111 8860", "output": "432827" }, { "input": "6571 6449 8965", "output": "582642" }, { "input": "9178 2255 7996", "output": "731618" }, { "input": "6151 6148 3746", "output": "224269" }, { "input": "8890 5449 8734", "output": "771004" }, { "input": "7879 2590 2818", "output": "219441" }, { "input": "8484 6400 547", "output": "40008" }, { "input": "7835 6710 1639", "output": "121706" }, { "input": "2379 1436 9663", "output": "228447" }, { "input": "6487 5670 8", "output": "0" }, { "input": "4470 2543 6", "output": "0" }, { "input": "7261 5328 10", "output": "0" }, { "input": "3871 3795 7", "output": "0" }, { "input": "9620 6557 6", "output": "0" }, { "input": "4890 1112 5", "output": "0" }, { "input": "1 1 1", "output": "0" }, { "input": "1 1 10000", "output": "99" }, { "input": "10000 1 1", "output": "99" }, { "input": "10000 1 10000", "output": "999999" }, { "input": "10000 10000 1", "output": "0" }, { "input": "10000 10000 10000", "output": "990000" }, { "input": "67 1 3", "output": "2" }, { "input": "7878 4534 9159", "output": "717013" }, { "input": "1 1 1", "output": "0" }, { "input": "3271 5 50", "output": "1631" } ]
1,638,267,695
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
3
92
0
from math import ceil n,x,y = map(int,input().split()) # a = ceil((((100+y)/(100-y)*(n-x))-(n+x))*0.5) # print(a) a = ceil((n*y)/(100)-x) print(a)
Title: Wizards and Demonstration Time Limit: None seconds Memory Limit: None megabytes Problem Description: Some country is populated by wizards. They want to organize a demonstration. There are *n* people living in the city, *x* of them are the wizards who will surely go to the demonstration. Other city people (*n*<=-<=*x* people) do not support the wizards and aren't going to go to the demonstration. We know that the city administration will react only to the demonstration involving at least *y* percent of the city people. Having considered the matter, the wizards decided to create clone puppets which can substitute the city people on the demonstration. So all in all, the demonstration will involve only the wizards and their puppets. The city administration cannot tell the difference between a puppet and a person, so, as they calculate the percentage, the administration will consider the city to be consisting of only *n* people and not containing any clone puppets. Help the wizards and find the minimum number of clones to create to that the demonstration had no less than *y* percent of the city people. Input Specification: The first line contains three space-separated integers, *n*, *x*, *y* (1<=≤<=*n*,<=*x*,<=*y*<=≤<=104,<=*x*<=≤<=*n*) — the number of citizens in the city, the number of wizards and the percentage the administration needs, correspondingly. Please note that *y* can exceed 100 percent, that is, the administration wants to see on a demonstration more people that actually live in the city (<=&gt;<=*n*). Output Specification: Print a single integer — the answer to the problem, the minimum number of clones to create, so that the demonstration involved no less than *y* percent of *n* (the real total city population). Demo Input: ['10 1 14\n', '20 10 50\n', '1000 352 146\n'] Demo Output: ['1\n', '0\n', '1108\n'] Note: In the first sample it is necessary that at least 14% of 10 people came to the demonstration. As the number of people should be integer, then at least two people should come. There is only one wizard living in the city and he is going to come. That isn't enough, so he needs to create one clone. In the second sample 10 people should come to the demonstration. The city has 10 wizards. They will all come to the demonstration, so nobody has to create any clones.
```python from math import ceil n,x,y = map(int,input().split()) # a = ceil((((100+y)/(100-y)*(n-x))-(n+x))*0.5) # print(a) a = ceil((n*y)/(100)-x) print(a) ```
0
569
A
Music
PROGRAMMING
1,500
[ "implementation", "math" ]
null
null
Little Lesha loves listening to music via his smartphone. But the smartphone doesn't have much memory, so Lesha listens to his favorite songs in a well-known social network InTalk. Unfortunately, internet is not that fast in the city of Ekaterinozavodsk and the song takes a lot of time to download. But Lesha is quite impatient. The song's duration is *T* seconds. Lesha downloads the first *S* seconds of the song and plays it. When the playback reaches the point that has not yet been downloaded, Lesha immediately plays the song from the start (the loaded part of the song stays in his phone, and the download is continued from the same place), and it happens until the song is downloaded completely and Lesha listens to it to the end. For *q* seconds of real time the Internet allows you to download *q*<=-<=1 seconds of the track. Tell Lesha, for how many times he will start the song, including the very first start.
The single line contains three integers *T*,<=*S*,<=*q* (2<=≤<=*q*<=≤<=104, 1<=≤<=*S*<=&lt;<=*T*<=≤<=105).
Print a single integer — the number of times the song will be restarted.
[ "5 2 2\n", "5 4 7\n", "6 2 3\n" ]
[ "2\n", "1\n", "1\n" ]
In the first test, the song is played twice faster than it is downloaded, which means that during four first seconds Lesha reaches the moment that has not been downloaded, and starts the song again. After another two seconds, the song is downloaded completely, and thus, Lesha starts the song twice. In the second test, the song is almost downloaded, and Lesha will start it only once. In the third sample test the download finishes and Lesha finishes listening at the same moment. Note that song isn't restarted in this case.
500
[ { "input": "5 2 2", "output": "2" }, { "input": "5 4 7", "output": "1" }, { "input": "6 2 3", "output": "1" }, { "input": "2 1 2", "output": "1" }, { "input": "2 1 3", "output": "1" }, { "input": "2 1 10000", "output": "1" }, { "input": "12326 6163 2", "output": "1" }, { "input": "10000 2500 4", "output": "1" }, { "input": "100000 99999 4", "output": "1" }, { "input": "12351 1223 6", "output": "2" }, { "input": "100000 1 10000", "output": "2" }, { "input": "10028 13 10000", "output": "1" }, { "input": "100000 99999 2", "output": "1" }, { "input": "100000 99999 3", "output": "1" }, { "input": "100000 1 2", "output": "17" }, { "input": "100000 1 3", "output": "11" }, { "input": "100000 1 4", "output": "9" }, { "input": "100000 1 5", "output": "8" }, { "input": "100000 3125 2", "output": "5" }, { "input": "12628 1804 7", "output": "1" }, { "input": "100000 45 13", "output": "4" }, { "input": "100000 500 3", "output": "5" }, { "input": "356 2 3", "output": "5" }, { "input": "50 2 2", "output": "5" }, { "input": "65465 12 3", "output": "8" }, { "input": "10033 3 8", "output": "4" }, { "input": "100000 3 2", "output": "16" }, { "input": "64 1 8", "output": "2" }, { "input": "10000 9 2", "output": "11" }, { "input": "25 2 2", "output": "4" }, { "input": "129 2 2", "output": "7" }, { "input": "6562 1 3", "output": "9" }, { "input": "100000 1 10", "output": "5" } ]
1,439,293,893
2,147,483,647
Python 3
OK
TESTS
33
62
0
t,s,q = input().split() t=int(t) s=int(s) q=int(q) r=s m=1 while(r<t): r=r*q if(r<t): m+=1 print(m)
Title: Music Time Limit: None seconds Memory Limit: None megabytes Problem Description: Little Lesha loves listening to music via his smartphone. But the smartphone doesn't have much memory, so Lesha listens to his favorite songs in a well-known social network InTalk. Unfortunately, internet is not that fast in the city of Ekaterinozavodsk and the song takes a lot of time to download. But Lesha is quite impatient. The song's duration is *T* seconds. Lesha downloads the first *S* seconds of the song and plays it. When the playback reaches the point that has not yet been downloaded, Lesha immediately plays the song from the start (the loaded part of the song stays in his phone, and the download is continued from the same place), and it happens until the song is downloaded completely and Lesha listens to it to the end. For *q* seconds of real time the Internet allows you to download *q*<=-<=1 seconds of the track. Tell Lesha, for how many times he will start the song, including the very first start. Input Specification: The single line contains three integers *T*,<=*S*,<=*q* (2<=≤<=*q*<=≤<=104, 1<=≤<=*S*<=&lt;<=*T*<=≤<=105). Output Specification: Print a single integer — the number of times the song will be restarted. Demo Input: ['5 2 2\n', '5 4 7\n', '6 2 3\n'] Demo Output: ['2\n', '1\n', '1\n'] Note: In the first test, the song is played twice faster than it is downloaded, which means that during four first seconds Lesha reaches the moment that has not been downloaded, and starts the song again. After another two seconds, the song is downloaded completely, and thus, Lesha starts the song twice. In the second test, the song is almost downloaded, and Lesha will start it only once. In the third sample test the download finishes and Lesha finishes listening at the same moment. Note that song isn't restarted in this case.
```python t,s,q = input().split() t=int(t) s=int(s) q=int(q) r=s m=1 while(r<t): r=r*q if(r<t): m+=1 print(m) ```
3
596
A
Wilbur and Swimming Pool
PROGRAMMING
1,100
[ "geometry", "implementation" ]
null
null
After making bad dives into swimming pools, Wilbur wants to build a swimming pool in the shape of a rectangle in his backyard. He has set up coordinate axes, and he wants the sides of the rectangle to be parallel to them. Of course, the area of the rectangle must be positive. Wilbur had all four vertices of the planned pool written on a paper, until his friend came along and erased some of the vertices. Now Wilbur is wondering, if the remaining *n* vertices of the initial rectangle give enough information to restore the area of the planned swimming pool.
The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=4) — the number of vertices that were not erased by Wilbur's friend. Each of the following *n* lines contains two integers *x**i* and *y**i* (<=-<=1000<=≤<=*x**i*,<=*y**i*<=≤<=1000) —the coordinates of the *i*-th vertex that remains. Vertices are given in an arbitrary order. It's guaranteed that these points are distinct vertices of some rectangle, that has positive area and which sides are parallel to the coordinate axes.
Print the area of the initial rectangle if it could be uniquely determined by the points remaining. Otherwise, print <=-<=1.
[ "2\n0 0\n1 1\n", "1\n1 1\n" ]
[ "1\n", "-1\n" ]
In the first sample, two opposite corners of the initial rectangle are given, and that gives enough information to say that the rectangle is actually a unit square. In the second sample there is only one vertex left and this is definitely not enough to uniquely define the area.
500
[ { "input": "2\n0 0\n1 1", "output": "1" }, { "input": "1\n1 1", "output": "-1" }, { "input": "1\n-188 17", "output": "-1" }, { "input": "1\n71 -740", "output": "-1" }, { "input": "4\n-56 -858\n-56 -174\n778 -858\n778 -174", "output": "570456" }, { "input": "2\n14 153\n566 -13", "output": "91632" }, { "input": "2\n-559 894\n314 127", "output": "669591" }, { "input": "1\n-227 -825", "output": "-1" }, { "input": "2\n-187 583\n25 13", "output": "120840" }, { "input": "2\n-337 451\n32 -395", "output": "312174" }, { "input": "4\n-64 -509\n-64 960\n634 -509\n634 960", "output": "1025362" }, { "input": "2\n-922 -505\n712 -683", "output": "290852" }, { "input": "2\n-1000 -1000\n-1000 0", "output": "-1" }, { "input": "2\n-1000 -1000\n0 -1000", "output": "-1" }, { "input": "4\n-414 -891\n-414 896\n346 -891\n346 896", "output": "1358120" }, { "input": "2\n56 31\n704 -121", "output": "98496" }, { "input": "4\n-152 198\n-152 366\n458 198\n458 366", "output": "102480" }, { "input": "3\n-890 778\n-418 296\n-890 296", "output": "227504" }, { "input": "4\n852 -184\n852 724\n970 -184\n970 724", "output": "107144" }, { "input": "1\n858 -279", "output": "-1" }, { "input": "2\n-823 358\n446 358", "output": "-1" }, { "input": "2\n-739 -724\n-739 443", "output": "-1" }, { "input": "2\n686 664\n686 -590", "output": "-1" }, { "input": "3\n-679 301\n240 -23\n-679 -23", "output": "297756" }, { "input": "2\n-259 -978\n978 -978", "output": "-1" }, { "input": "1\n627 -250", "output": "-1" }, { "input": "3\n-281 598\n679 -990\n-281 -990", "output": "1524480" }, { "input": "2\n-414 -431\n-377 -688", "output": "9509" }, { "input": "3\n-406 566\n428 426\n-406 426", "output": "116760" }, { "input": "3\n-686 695\n-547 308\n-686 308", "output": "53793" }, { "input": "1\n-164 -730", "output": "-1" }, { "input": "2\n980 -230\n980 592", "output": "-1" }, { "input": "4\n-925 306\n-925 602\n398 306\n398 602", "output": "391608" }, { "input": "3\n576 -659\n917 -739\n576 -739", "output": "27280" }, { "input": "1\n720 -200", "output": "-1" }, { "input": "4\n-796 -330\n-796 758\n171 -330\n171 758", "output": "1052096" }, { "input": "2\n541 611\n-26 611", "output": "-1" }, { "input": "3\n-487 838\n134 691\n-487 691", "output": "91287" }, { "input": "2\n-862 -181\n-525 -181", "output": "-1" }, { "input": "1\n-717 916", "output": "-1" }, { "input": "1\n-841 -121", "output": "-1" }, { "input": "4\n259 153\n259 999\n266 153\n266 999", "output": "5922" }, { "input": "2\n295 710\n295 254", "output": "-1" }, { "input": "4\n137 -184\n137 700\n712 -184\n712 700", "output": "508300" }, { "input": "2\n157 994\n377 136", "output": "188760" }, { "input": "1\n193 304", "output": "-1" }, { "input": "4\n5 -952\n5 292\n553 -952\n553 292", "output": "681712" }, { "input": "2\n-748 697\n671 575", "output": "173118" }, { "input": "2\n-457 82\n260 -662", "output": "533448" }, { "input": "2\n-761 907\n967 907", "output": "-1" }, { "input": "3\n-639 51\n-321 -539\n-639 -539", "output": "187620" }, { "input": "2\n-480 51\n89 -763", "output": "463166" }, { "input": "4\n459 -440\n459 -94\n872 -440\n872 -94", "output": "142898" }, { "input": "2\n380 -849\n68 -849", "output": "-1" }, { "input": "2\n-257 715\n102 715", "output": "-1" }, { "input": "2\n247 -457\n434 -921", "output": "86768" }, { "input": "4\n-474 -894\n-474 -833\n-446 -894\n-446 -833", "output": "1708" }, { "input": "3\n-318 831\n450 31\n-318 31", "output": "614400" }, { "input": "3\n-282 584\n696 488\n-282 488", "output": "93888" }, { "input": "3\n258 937\n395 856\n258 856", "output": "11097" }, { "input": "1\n-271 -499", "output": "-1" }, { "input": "2\n-612 208\n326 -559", "output": "719446" }, { "input": "2\n115 730\n562 -546", "output": "570372" }, { "input": "2\n-386 95\n-386 750", "output": "-1" }, { "input": "3\n0 0\n0 1\n1 0", "output": "1" }, { "input": "3\n0 4\n3 4\n3 1", "output": "9" }, { "input": "3\n1 1\n1 2\n2 1", "output": "1" }, { "input": "3\n1 4\n4 4\n4 1", "output": "9" }, { "input": "3\n1 1\n2 1\n1 2", "output": "1" }, { "input": "3\n0 0\n1 0\n1 1", "output": "1" }, { "input": "3\n0 0\n0 5\n5 0", "output": "25" }, { "input": "3\n0 0\n0 1\n1 1", "output": "1" }, { "input": "4\n0 0\n1 0\n1 1\n0 1", "output": "1" }, { "input": "3\n4 4\n1 4\n4 1", "output": "9" }, { "input": "3\n0 0\n2 0\n2 1", "output": "2" }, { "input": "3\n0 0\n2 0\n0 2", "output": "4" }, { "input": "3\n0 0\n0 1\n5 0", "output": "5" }, { "input": "3\n1 1\n1 3\n3 1", "output": "4" }, { "input": "4\n0 0\n1 0\n0 1\n1 1", "output": "1" }, { "input": "2\n1 0\n2 1", "output": "1" }, { "input": "3\n0 0\n1 0\n0 1", "output": "1" }, { "input": "3\n1 0\n0 0\n0 1", "output": "1" }, { "input": "3\n0 0\n0 5\n5 5", "output": "25" }, { "input": "3\n1 0\n5 0\n5 10", "output": "40" }, { "input": "3\n0 0\n1 0\n1 2", "output": "2" }, { "input": "4\n0 1\n0 0\n1 0\n1 1", "output": "1" }, { "input": "3\n0 0\n2 0\n0 1", "output": "2" }, { "input": "3\n-2 -1\n-1 -1\n-1 -2", "output": "1" }, { "input": "2\n1 0\n0 1", "output": "1" }, { "input": "4\n1 1\n3 3\n3 1\n1 3", "output": "4" }, { "input": "3\n2 1\n1 2\n2 2", "output": "1" }, { "input": "3\n0 0\n0 3\n3 0", "output": "9" }, { "input": "2\n0 3\n3 3", "output": "-1" }, { "input": "4\n2 0\n2 8\n5 8\n5 0", "output": "24" }, { "input": "2\n0 999\n100 250", "output": "74900" }, { "input": "3\n1 1\n1 5\n5 1", "output": "16" }, { "input": "3\n0 1\n0 0\n1 1", "output": "1" }, { "input": "3\n0 0\n10 0\n0 10", "output": "100" }, { "input": "2\n0 0\n-1 -1", "output": "1" }, { "input": "3\n1 5\n2 2\n2 5", "output": "3" }, { "input": "3\n0 0\n0 1\n2 0", "output": "2" }, { "input": "3\n0 1\n1 0\n0 0", "output": "1" }, { "input": "3\n0 0\n0 -1\n1 -1", "output": "1" }, { "input": "3\n0 1\n1 0\n1 1", "output": "1" }, { "input": "3\n3 5\n3 2\n7 2", "output": "12" }, { "input": "3\n1 2\n1 3\n2 2", "output": "1" }, { "input": "3\n5 0\n0 0\n0 5", "output": "25" }, { "input": "3\n1 0\n1 3\n5 0", "output": "12" }, { "input": "3\n0 0\n0 2\n2 0", "output": "4" }, { "input": "3\n1 1\n0 0\n1 0", "output": "1" }, { "input": "3\n1 2\n1 3\n2 3", "output": "1" }, { "input": "4\n0 0\n0 1\n1 1\n1 0", "output": "1" }, { "input": "2\n-3 0\n3 3", "output": "18" }, { "input": "3\n1 1\n0 1\n1 0", "output": "1" }, { "input": "3\n0 0\n5 0\n5 5", "output": "25" }, { "input": "3\n79 79\n79 158\n158 79", "output": "6241" }, { "input": "3\n1 0\n1 -1\n0 0", "output": "1" }, { "input": "3\n1 1\n1 2\n2 2", "output": "1" }, { "input": "3\n0 1\n0 0\n1 0", "output": "1" }, { "input": "3\n2 1\n2 4\n6 1", "output": "12" }, { "input": "3\n5 0\n0 0\n5 5", "output": "25" } ]
1,447,605,946
646
Python 3
OK
TESTS
121
62
0
#!/usr/bin/env python3 def f(a, b): return abs((a[0] - b[0]) * (a[1] - b[1])) n = int(input()) x = [list(map(int,input().split())) for i in range(n)] y = 0 for i in range(n): for j in range(i+1, n): if not y: y = f(x[i], x[j]) print(y or -1)
Title: Wilbur and Swimming Pool Time Limit: None seconds Memory Limit: None megabytes Problem Description: After making bad dives into swimming pools, Wilbur wants to build a swimming pool in the shape of a rectangle in his backyard. He has set up coordinate axes, and he wants the sides of the rectangle to be parallel to them. Of course, the area of the rectangle must be positive. Wilbur had all four vertices of the planned pool written on a paper, until his friend came along and erased some of the vertices. Now Wilbur is wondering, if the remaining *n* vertices of the initial rectangle give enough information to restore the area of the planned swimming pool. Input Specification: The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=4) — the number of vertices that were not erased by Wilbur's friend. Each of the following *n* lines contains two integers *x**i* and *y**i* (<=-<=1000<=≤<=*x**i*,<=*y**i*<=≤<=1000) —the coordinates of the *i*-th vertex that remains. Vertices are given in an arbitrary order. It's guaranteed that these points are distinct vertices of some rectangle, that has positive area and which sides are parallel to the coordinate axes. Output Specification: Print the area of the initial rectangle if it could be uniquely determined by the points remaining. Otherwise, print <=-<=1. Demo Input: ['2\n0 0\n1 1\n', '1\n1 1\n'] Demo Output: ['1\n', '-1\n'] Note: In the first sample, two opposite corners of the initial rectangle are given, and that gives enough information to say that the rectangle is actually a unit square. In the second sample there is only one vertex left and this is definitely not enough to uniquely define the area.
```python #!/usr/bin/env python3 def f(a, b): return abs((a[0] - b[0]) * (a[1] - b[1])) n = int(input()) x = [list(map(int,input().split())) for i in range(n)] y = 0 for i in range(n): for j in range(i+1, n): if not y: y = f(x[i], x[j]) print(y or -1) ```
3
940
D
Alena And The Heater
PROGRAMMING
1,600
[ "binary search", "implementation" ]
null
null
"We've tried solitary confinement, waterboarding and listening to Just In Beaver, to no avail. We need something extreme." "Little Alena got an array as a birthday present..." The array *b* of length *n* is obtained from the array *a* of length *n* and two integers *l* and *r* (*l*<=≤<=*r*) using the following procedure: *b*1<==<=*b*2<==<=*b*3<==<=*b*4<==<=0. For all 5<=≤<=*i*<=≤<=*n*: - *b**i*<==<=0 if *a**i*,<=*a**i*<=-<=1,<=*a**i*<=-<=2,<=*a**i*<=-<=3,<=*a**i*<=-<=4<=&gt;<=*r* and *b**i*<=-<=1<==<=*b**i*<=-<=2<==<=*b**i*<=-<=3<==<=*b**i*<=-<=4<==<=1 - *b**i*<==<=1 if *a**i*,<=*a**i*<=-<=1,<=*a**i*<=-<=2,<=*a**i*<=-<=3,<=*a**i*<=-<=4<=&lt;<=*l* and *b**i*<=-<=1<==<=*b**i*<=-<=2<==<=*b**i*<=-<=3<==<=*b**i*<=-<=4<==<=0 - *b**i*<==<=*b**i*<=-<=1 otherwise You are given arrays *a* and *b*' of the same length. Find two integers *l* and *r* (*l*<=≤<=*r*), such that applying the algorithm described above will yield an array *b* equal to *b*'. It's guaranteed that the answer exists.
The first line of input contains a single integer *n* (5<=≤<=*n*<=≤<=105) — the length of *a* and *b*'. The second line of input contains *n* space separated integers *a*1,<=...,<=*a**n* (<=-<=109<=≤<=*a**i*<=≤<=109) — the elements of *a*. The third line of input contains a string of *n* characters, consisting of 0 and 1 — the elements of *b*'. Note that they are not separated by spaces.
Output two integers *l* and *r* (<=-<=109<=≤<=*l*<=≤<=*r*<=≤<=109), conforming to the requirements described above. If there are multiple solutions, output any of them. It's guaranteed that the answer exists.
[ "5\n1 2 3 4 5\n00001\n", "10\n-10 -9 -8 -7 -6 6 7 8 9 10\n0000111110\n" ]
[ "6 15\n", "-5 5\n" ]
In the first test case any pair of *l* and *r* pair is valid, if 6 ≤ *l* ≤ *r* ≤ 10<sup class="upper-index">9</sup>, in that case *b*<sub class="lower-index">5</sub> = 1, because *a*<sub class="lower-index">1</sub>, ..., *a*<sub class="lower-index">5</sub> &lt; *l*.
1,500
[ { "input": "5\n1 2 3 4 5\n00001", "output": "6 1000000000" }, { "input": "10\n-10 -9 -8 -7 -6 6 7 8 9 10\n0000111110", "output": "-5 5" }, { "input": "10\n-8 -9 -9 -7 -10 -10 -8 -8 -9 -10\n0000000011", "output": "-7 1000000000" }, { "input": "11\n226 226 226 226 226 227 1000000000 1000000000 228 1000000000 1000000000\n00001111110", "output": "227 227" }, { "input": "95\n-97 -98 -92 -93 94 96 91 98 95 85 90 86 84 83 81 79 82 79 73 -99 -91 -93 -92 -97 -85 -88 -89 -83 -86 -75 -80 -78 -74 -76 62 68 63 64 69 -71 -70 -72 -69 -71 53 57 60 54 61 -64 -64 -68 -58 -63 -54 -52 -51 -50 -49 -46 -39 -38 -42 -42 48 44 51 45 43 -31 -32 -33 -28 -30 -21 -17 -20 -25 -19 -13 -8 -10 -12 -7 33 34 34 42 32 30 25 29 23 30 20\n00000000000000000000000111111111111111000001111100000111111111111111000001111111111111110000000", "output": "-27 31" }, { "input": "10\n1 4 2 -1 2 3 10 -10 1 3\n0000000000", "output": "-1000000000 1000000000" }, { "input": "10\n10 9 8 7 6 5 4 3 2 1\n0000000001", "output": "6 1000000000" }, { "input": "10\n10 9 8 7 6 5 4 3 2 1\n0000000011", "output": "7 1000000000" }, { "input": "10\n6 10 10 4 5 5 6 8 7 7\n0000000111", "output": "9 1000000000" }, { "input": "10\n6 10 2 1 5 5 9 8 7 7\n0000001111", "output": "10 1000000000" }, { "input": "10\n6 2 3 4 5 5 9 8 7 7\n0000011111", "output": "6 1000000000" }, { "input": "10\n-10 -10 -10 -10 -10 10 10 10 10 10\n0000111110", "output": "-9 9" }, { "input": "10\n-8 -9 -7 -8 -10 -7 -7 -7 -8 -8\n0000111111", "output": "-6 1000000000" }, { "input": "10\n-10 -7 -10 -10 7 7 9 7 7 6\n0000000000", "output": "-1000000000 1000000000" }, { "input": "93\n-99 -99 -95 -100 -96 -98 -90 -97 -99 -84 -80 -86 -83 -84 -79 -78 -70 -74 -79 -66 -59 -64 -65 -67 -52 -53 -54 -57 -51 -47 -45 -43 -49 -45 96 97 92 97 94 -39 -42 -36 -32 -36 -30 -30 -29 -28 -24 91 82 85 84 88 76 76 80 76 71 -22 -15 -18 -16 -13 64 63 67 65 70 -8 -3 -4 -7 -8 62 58 59 54 54 1 7 -2 2 7 12 8 16 17 12 50 52 49 43\n000011111111111111111111111111111111110000011111111110000000000111110000011111000001111111111", "output": "8 53" }, { "input": "99\n-94 -97 -95 -99 94 98 91 95 90 -98 -92 -93 -91 -100 84 81 80 89 89 70 76 79 69 74 -80 -90 -83 -81 -80 64 60 60 60 68 56 50 55 50 57 39 47 47 48 49 37 31 34 38 34 -76 -71 -70 -76 -70 23 21 24 29 22 -62 -65 -63 -60 -61 -56 -51 -54 -58 -59 -40 -43 -50 -43 -42 -39 -33 -39 -39 -33 17 16 19 10 20 -32 -22 -32 -23 -23 1 8 4 -1 3 -12 -17 -12 -20 -12\n000000000000011111000000000011111000000000000000000001111100000111111111111111111110000011111000001", "output": "-11 -2" }, { "input": "97\n-93 -92 -90 -97 -96 -92 -97 -99 -97 -89 -91 -84 -84 -81 90 96 90 91 100 -78 -80 -72 -77 -73 79 86 81 89 81 -62 -70 -64 -61 -66 77 73 74 74 69 65 63 68 63 64 -56 -51 -53 -58 -54 62 60 55 58 59 45 49 44 54 53 38 33 33 35 39 27 28 25 30 25 -49 -43 -46 -46 -45 18 21 18 15 20 5 12 4 10 6 -4 -6 0 3 0 -34 -35 -34 -32 -37 -24 -25 -28\n0000111111111111110000011111000001111100000000001111100000000000000000000111110000000000000001111", "output": "-31 14" }, { "input": "99\n-94 -90 -90 -93 94 93 96 96 96 -90 -90 -100 -91 -95 -87 -89 -85 -79 -80 87 87 88 92 92 84 79 84 80 82 73 73 78 78 75 62 67 65 63 68 59 60 55 52 51 42 48 50 42 46 -71 -77 -75 -76 -68 34 40 37 35 33 26 25 24 22 25 -59 -63 -66 -64 -63 11 15 12 12 13 -50 -54 -53 -49 -58 -40 -46 -43 -42 -45 6 3 10 10 1 -32 -31 -29 -38 -36 -22 -28 -24 -28 -26\n000000000000011111111110000000000000000000000000000001111100000000001111100000111111111100000111111", "output": "-28 0" }, { "input": "94\n-97 -94 -91 -98 -92 -98 -92 -96 -92 -85 -91 -81 -91 -85 96 97 100 96 96 87 94 92 88 86 85 -78 -75 -73 -80 -80 75 81 78 84 83 67 64 64 74 72 -66 -63 -68 -64 -68 -66 -55 -60 -59 -57 -60 -51 -47 -45 -47 -49 -43 -36 -40 -42 -38 -40 -25 -32 -35 -28 -33 54 57 55 63 56 63 47 53 44 52 45 48 -21 -21 -17 -20 -14 -18 39 36 33 33 38 42 -4 -12 -3\n0000111111111111110000000000011111000000000011111111111111111111111111100000000000011111100000", "output": "-13 32" }, { "input": "96\n-92 -93 -97 -94 94 91 96 93 93 92 -90 -97 -94 -98 -98 -92 90 88 81 85 89 75 75 73 80 74 74 66 69 66 63 69 56 56 52 53 53 49 47 41 46 50 -91 -86 -89 -83 -88 -81 -79 -77 -72 -79 37 30 35 39 32 25 26 28 27 29 -67 -70 -64 -62 -70 21 15 16 21 19 6 4 5 6 9 4 -7 1 -7 -4 -5 -59 -59 -56 -51 -51 -43 -47 -46 -50 -47 -10 -17 -17\n000000000000001111110000000000000000000000000011111111110000000000111110000000000000000111111111", "output": "-50 14" }, { "input": "98\n-90 -94 -92 -96 -96 -92 -92 -92 -94 -96 99 97 90 94 98 -82 -89 -85 -84 -81 -72 -70 -80 -73 -78 83 83 85 89 83 -69 -68 -60 -66 -67 79 76 78 80 82 73 -57 -49 -50 -53 -53 -48 -40 -46 -46 -41 62 72 65 72 72 -29 -29 -29 -37 -36 -30 -27 -19 -18 -28 -25 -15 -14 -17 -13 -17 -10 59 56 57 53 52 52 41 49 41 45 50 -6 -8 -6 -8 -3 -4 39 40 40 38 31 23 22 27\n00001111111111000001111111111000001111100000011111111110000011111111111111111000000000001111110000", "output": "-2 30" }, { "input": "96\n-100 -99 -100 -95 94 93 94 90 99 83 86 83 86 89 80 82 76 80 75 -100 -99 -95 -92 -91 -98 -90 -83 -84 -84 -85 64 71 70 68 68 74 58 57 61 66 65 63 -76 -81 -72 -74 -72 47 52 56 46 53 -68 -70 -62 -68 -69 35 37 40 43 35 -58 -54 -51 -59 -59 -59 29 24 26 33 31 -45 -42 -49 -40 -49 -48 -30 -34 -35 -31 -32 -37 -22 -21 -20 -28 -21 16 21 13 20 14 -18\n000000000000000000000001111111111100000000000011111000001111100000111111000001111111111111111100", "output": "-39 12" }, { "input": "98\n-99 -98 -95 -90 97 93 96 95 98 98 -94 -92 -99 -92 -91 -87 -83 -84 -87 -88 -90 -79 -79 -82 -77 -76 92 82 91 91 90 91 -69 -72 -65 -68 -65 -58 -59 -63 -56 -57 -59 -53 -55 -45 -51 -52 73 81 75 71 77 72 67 70 60 70 61 64 -34 -41 -41 -41 -37 -39 -36 -33 -36 -36 -33 -36 54 49 53 51 50 -23 -26 -22 -23 -31 -30 43 47 41 40 38 39 33 30 30 34 37 31 -19 -11 -12\n00000000000000111111111111111100000011111111111111110000000000001111111111110000011111100000000000", "output": "-21 37" } ]
1,592,472,351
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
0
109
0
n = int(input()) a = list(map(int,input().split())) b = str(input()) l = -99999999999 r = 99999999999 for i in range(4,n): low = -99999999999 high = 99999999999 if int(b[i]) == 1 and int(b[i-1]) == int(b[i-2]) == int(b[i-3]) == int(b[i-4]) == 0: for j in range(i-4, i+1): if a[j] > low: low = a[j] if l == -99999999999: l = low +1 elif int(b[i]) == 0 and int(b[i-1]) == int(b[i-2]) == int(b[i-3]) == int(b[i-4]) == 0: for j in range(i-4, i+1): if a[j] > low: low = a[j] if l == -99999999999: l = low -1 elif int(b[i]) == 0 and int(b[i-1]) == int(b[i-2]) == int(b[i-3]) == int(b[i-4]) == 1: for j in range(i-4, i+1): if a[j] < high: high = a[j] if r == 99999999999: r = high -1 elif int(b[i]) == 1 and int(b[i-1]) == int(b[i-2]) == int(b[i-3]) == int(b[i-4]) == 1: for j in range(i-4, i+1): if a[j] < high: high = a[j] if r == 99999999999: r = high +1 print(l,r)
Title: Alena And The Heater Time Limit: None seconds Memory Limit: None megabytes Problem Description: "We've tried solitary confinement, waterboarding and listening to Just In Beaver, to no avail. We need something extreme." "Little Alena got an array as a birthday present..." The array *b* of length *n* is obtained from the array *a* of length *n* and two integers *l* and *r* (*l*<=≤<=*r*) using the following procedure: *b*1<==<=*b*2<==<=*b*3<==<=*b*4<==<=0. For all 5<=≤<=*i*<=≤<=*n*: - *b**i*<==<=0 if *a**i*,<=*a**i*<=-<=1,<=*a**i*<=-<=2,<=*a**i*<=-<=3,<=*a**i*<=-<=4<=&gt;<=*r* and *b**i*<=-<=1<==<=*b**i*<=-<=2<==<=*b**i*<=-<=3<==<=*b**i*<=-<=4<==<=1 - *b**i*<==<=1 if *a**i*,<=*a**i*<=-<=1,<=*a**i*<=-<=2,<=*a**i*<=-<=3,<=*a**i*<=-<=4<=&lt;<=*l* and *b**i*<=-<=1<==<=*b**i*<=-<=2<==<=*b**i*<=-<=3<==<=*b**i*<=-<=4<==<=0 - *b**i*<==<=*b**i*<=-<=1 otherwise You are given arrays *a* and *b*' of the same length. Find two integers *l* and *r* (*l*<=≤<=*r*), such that applying the algorithm described above will yield an array *b* equal to *b*'. It's guaranteed that the answer exists. Input Specification: The first line of input contains a single integer *n* (5<=≤<=*n*<=≤<=105) — the length of *a* and *b*'. The second line of input contains *n* space separated integers *a*1,<=...,<=*a**n* (<=-<=109<=≤<=*a**i*<=≤<=109) — the elements of *a*. The third line of input contains a string of *n* characters, consisting of 0 and 1 — the elements of *b*'. Note that they are not separated by spaces. Output Specification: Output two integers *l* and *r* (<=-<=109<=≤<=*l*<=≤<=*r*<=≤<=109), conforming to the requirements described above. If there are multiple solutions, output any of them. It's guaranteed that the answer exists. Demo Input: ['5\n1 2 3 4 5\n00001\n', '10\n-10 -9 -8 -7 -6 6 7 8 9 10\n0000111110\n'] Demo Output: ['6 15\n', '-5 5\n'] Note: In the first test case any pair of *l* and *r* pair is valid, if 6 ≤ *l* ≤ *r* ≤ 10<sup class="upper-index">9</sup>, in that case *b*<sub class="lower-index">5</sub> = 1, because *a*<sub class="lower-index">1</sub>, ..., *a*<sub class="lower-index">5</sub> &lt; *l*.
```python n = int(input()) a = list(map(int,input().split())) b = str(input()) l = -99999999999 r = 99999999999 for i in range(4,n): low = -99999999999 high = 99999999999 if int(b[i]) == 1 and int(b[i-1]) == int(b[i-2]) == int(b[i-3]) == int(b[i-4]) == 0: for j in range(i-4, i+1): if a[j] > low: low = a[j] if l == -99999999999: l = low +1 elif int(b[i]) == 0 and int(b[i-1]) == int(b[i-2]) == int(b[i-3]) == int(b[i-4]) == 0: for j in range(i-4, i+1): if a[j] > low: low = a[j] if l == -99999999999: l = low -1 elif int(b[i]) == 0 and int(b[i-1]) == int(b[i-2]) == int(b[i-3]) == int(b[i-4]) == 1: for j in range(i-4, i+1): if a[j] < high: high = a[j] if r == 99999999999: r = high -1 elif int(b[i]) == 1 and int(b[i-1]) == int(b[i-2]) == int(b[i-3]) == int(b[i-4]) == 1: for j in range(i-4, i+1): if a[j] < high: high = a[j] if r == 99999999999: r = high +1 print(l,r) ```
0
518
B
Tanya and Postcard
PROGRAMMING
1,400
[ "greedy", "implementation", "strings" ]
null
null
Little Tanya decided to present her dad a postcard on his Birthday. She has already created a message — string *s* of length *n*, consisting of uppercase and lowercase English letters. Tanya can't write yet, so she found a newspaper and decided to cut out the letters and glue them into the postcard to achieve string *s*. The newspaper contains string *t*, consisting of uppercase and lowercase English letters. We know that the length of string *t* greater or equal to the length of the string *s*. The newspaper may possibly have too few of some letters needed to make the text and too many of some other letters. That's why Tanya wants to cut some *n* letters out of the newspaper and make a message of length exactly *n*, so that it looked as much as possible like *s*. If the letter in some position has correct value and correct letter case (in the string *s* and in the string that Tanya will make), then she shouts joyfully "YAY!", and if the letter in the given position has only the correct value but it is in the wrong case, then the girl says "WHOOPS". Tanya wants to make such message that lets her shout "YAY!" as much as possible. If there are multiple ways to do this, then her second priority is to maximize the number of times she says "WHOOPS". Your task is to help Tanya make the message.
The first line contains line *s* (1<=≤<=|*s*|<=≤<=2·105), consisting of uppercase and lowercase English letters — the text of Tanya's message. The second line contains line *t* (|*s*|<=≤<=|*t*|<=≤<=2·105), consisting of uppercase and lowercase English letters — the text written in the newspaper. Here |*a*| means the length of the string *a*.
Print two integers separated by a space: - the first number is the number of times Tanya shouts "YAY!" while making the message, - the second number is the number of times Tanya says "WHOOPS" while making the message.
[ "AbC\nDCbA\n", "ABC\nabc\n", "abacaba\nAbaCaBA\n" ]
[ "3 0\n", "0 3\n", "3 4\n" ]
none
1,000
[ { "input": "AbC\nDCbA", "output": "3 0" }, { "input": "ABC\nabc", "output": "0 3" }, { "input": "abacaba\nAbaCaBA", "output": "3 4" }, { "input": "zzzzz\nZZZZZ", "output": "0 5" }, { "input": "zzzZZZ\nZZZzzZ", "output": "5 1" }, { "input": "abcdefghijklmnopqrstuvwxyz\nABCDEFGHIJKLMNOPQRSTUVWXYZ", "output": "0 26" }, { "input": "abcdefghijklmnopqrstuvwxyz\nqrsimtabuvzhnwcdefgjklxyop", "output": "26 0" }, { "input": "l\nFPbAVjsMpPDTLkfwNYFmBDHPTDSWSOUlrBHYJHPM", "output": "1 0" }, { "input": "ncMeXssLHS\nuwyeMcaFatpInZVdEYpwJQSnVxLK", "output": "6 1" }, { "input": "DpiNBmCRFWxpdbfGOzvvOcemjructoAdEwegTvbVbfWWRPGyEAxGdDRWVlqNyGWMWHMrHAIZpyxvgaflrsVZhhZRouvpxrKXFZam\nwwPLFtNfPtJXvMLuHjKfYyaRhreNSWSzOvDpqHCGcqllACNPGHxReeFUCmAqIKXYytsSQwIxJzNiiUtgebVuwRmWpRALLyKAzyDPvgIGxALSaeeTIqm", "output": "66 12" }, { "input": "CCAE\ndcecc", "output": "0 3" }, { "input": "Dccb\nbeeeb", "output": "1 0" }, { "input": "Adc\neadeabcad", "output": "2 1" }, { "input": "DBAdeb\ndeeabcddadaa", "output": "3 2" }, { "input": "EDCED\neebeacdba", "output": "0 4" }, { "input": "CdAbD\ndecbde", "output": "2 2" }, { "input": "a\nB", "output": "0 0" }, { "input": "r\nqA", "output": "0 0" } ]
1,588,434,482
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
7
171
1,228,800
r=input() h=input() r_dic = {} h_dic = {} for c in r: h_dic[c] = 0 if c in r_dic: r_dic[c]+=1 else: r_dic[c]=1 for c in h: if c in h_dic: h_dic[c]+=1 else: h_dic[c]=1 y = 0 o = 0 for k,v in r_dic.items(): if r_dic[k]>h_dic[k]: r_dic[k] -= h_dic[k] y += h_dic[k] o += r_dic[k] h_dic[k] = 0 elif r_dic[k]<h_dic[k]: h_dic[k] -= r_dic[k] y += r_dic[k] r_dic[k] = 0 else: y += r_dic[k] r_dic[k] = 0 h_dic[k] = 0 print(y , end=" ") print(o , end=" ")
Title: Tanya and Postcard Time Limit: None seconds Memory Limit: None megabytes Problem Description: Little Tanya decided to present her dad a postcard on his Birthday. She has already created a message — string *s* of length *n*, consisting of uppercase and lowercase English letters. Tanya can't write yet, so she found a newspaper and decided to cut out the letters and glue them into the postcard to achieve string *s*. The newspaper contains string *t*, consisting of uppercase and lowercase English letters. We know that the length of string *t* greater or equal to the length of the string *s*. The newspaper may possibly have too few of some letters needed to make the text and too many of some other letters. That's why Tanya wants to cut some *n* letters out of the newspaper and make a message of length exactly *n*, so that it looked as much as possible like *s*. If the letter in some position has correct value and correct letter case (in the string *s* and in the string that Tanya will make), then she shouts joyfully "YAY!", and if the letter in the given position has only the correct value but it is in the wrong case, then the girl says "WHOOPS". Tanya wants to make such message that lets her shout "YAY!" as much as possible. If there are multiple ways to do this, then her second priority is to maximize the number of times she says "WHOOPS". Your task is to help Tanya make the message. Input Specification: The first line contains line *s* (1<=≤<=|*s*|<=≤<=2·105), consisting of uppercase and lowercase English letters — the text of Tanya's message. The second line contains line *t* (|*s*|<=≤<=|*t*|<=≤<=2·105), consisting of uppercase and lowercase English letters — the text written in the newspaper. Here |*a*| means the length of the string *a*. Output Specification: Print two integers separated by a space: - the first number is the number of times Tanya shouts "YAY!" while making the message, - the second number is the number of times Tanya says "WHOOPS" while making the message. Demo Input: ['AbC\nDCbA\n', 'ABC\nabc\n', 'abacaba\nAbaCaBA\n'] Demo Output: ['3 0\n', '0 3\n', '3 4\n'] Note: none
```python r=input() h=input() r_dic = {} h_dic = {} for c in r: h_dic[c] = 0 if c in r_dic: r_dic[c]+=1 else: r_dic[c]=1 for c in h: if c in h_dic: h_dic[c]+=1 else: h_dic[c]=1 y = 0 o = 0 for k,v in r_dic.items(): if r_dic[k]>h_dic[k]: r_dic[k] -= h_dic[k] y += h_dic[k] o += r_dic[k] h_dic[k] = 0 elif r_dic[k]<h_dic[k]: h_dic[k] -= r_dic[k] y += r_dic[k] r_dic[k] = 0 else: y += r_dic[k] r_dic[k] = 0 h_dic[k] = 0 print(y , end=" ") print(o , end=" ") ```
0
763
A
Timofey and a tree
PROGRAMMING
1,600
[ "dfs and similar", "dp", "dsu", "graphs", "implementation", "trees" ]
null
null
Each New Year Timofey and his friends cut down a tree of *n* vertices and bring it home. After that they paint all the *n* its vertices, so that the *i*-th vertex gets color *c**i*. Now it's time for Timofey birthday, and his mother asked him to remove the tree. Timofey removes the tree in the following way: he takes some vertex in hands, while all the other vertices move down so that the tree becomes rooted at the chosen vertex. After that Timofey brings the tree to a trash can. Timofey doesn't like it when many colors are mixing together. A subtree annoys him if there are vertices of different color in it. Timofey wants to find a vertex which he should take in hands so that there are no subtrees that annoy him. He doesn't consider the whole tree as a subtree since he can't see the color of the root vertex. A subtree of some vertex is a subgraph containing that vertex and all its descendants. Your task is to determine if there is a vertex, taking which in hands Timofey wouldn't be annoyed.
The first line contains single integer *n* (2<=≤<=*n*<=≤<=105) — the number of vertices in the tree. Each of the next *n*<=-<=1 lines contains two integers *u* and *v* (1<=≤<=*u*,<=*v*<=≤<=*n*, *u*<=≠<=*v*), denoting there is an edge between vertices *u* and *v*. It is guaranteed that the given graph is a tree. The next line contains *n* integers *c*1,<=*c*2,<=...,<=*c**n* (1<=≤<=*c**i*<=≤<=105), denoting the colors of the vertices.
Print "NO" in a single line, if Timofey can't take the tree in such a way that it doesn't annoy him. Otherwise print "YES" in the first line. In the second line print the index of the vertex which Timofey should take in hands. If there are multiple answers, print any of them.
[ "4\n1 2\n2 3\n3 4\n1 2 1 1\n", "3\n1 2\n2 3\n1 2 3\n", "4\n1 2\n2 3\n3 4\n1 2 1 2\n" ]
[ "YES\n2", "YES\n2", "NO" ]
none
500
[ { "input": "4\n1 2\n2 3\n3 4\n1 2 1 1", "output": "YES\n2" }, { "input": "3\n1 2\n2 3\n1 2 3", "output": "YES\n2" }, { "input": "4\n1 2\n2 3\n3 4\n1 2 1 2", "output": "NO" }, { "input": "3\n2 1\n2 3\n1 2 3", "output": "YES\n2" }, { "input": "4\n1 2\n2 4\n4 3\n1 1 3 2", "output": "YES\n4" }, { "input": "2\n1 2\n1 1", "output": "YES\n1" }, { "input": "10\n5 7\n4 5\n10 2\n3 6\n1 2\n3 4\n8 5\n4 9\n2 3\n15 15 15 15 5 15 26 18 15 15", "output": "YES\n5" }, { "input": "8\n1 2\n1 3\n3 5\n3 6\n1 4\n4 7\n4 8\n1 3 1 1 1 1 1 2", "output": "NO" }, { "input": "3\n2 1\n2 3\n4 4 4", "output": "YES\n1" }, { "input": "3\n1 2\n1 3\n1 2 2", "output": "YES\n1" }, { "input": "4\n1 4\n2 4\n3 4\n1 2 3 1", "output": "YES\n4" }, { "input": "4\n1 2\n1 3\n1 4\n1 2 3 4", "output": "YES\n1" }, { "input": "9\n1 2\n2 3\n3 4\n4 5\n2 7\n7 6\n2 8\n8 9\n1 1 2 2 2 3 3 4 4", "output": "YES\n2" }, { "input": "3\n2 1\n2 3\n4 4 5", "output": "YES\n2" }, { "input": "4\n1 2\n2 3\n3 4\n1 2 2 1", "output": "NO" } ]
1,600,176,677
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
5
139
0
n=int(input()) count=[0]*(n+1) arr=[] for i in range(n-1): u,v=map(int,input().split()) arr.append([u,v]) c=list(map(int,input().split())) countd=0 for i,(u,v) in enumerate(arr): if c[u-1]!=c[v-1]: countd+=1 count[u]+=1 count[v]+=1 maxi=0 index=-1 for i in range(1,n+1): if count[i]>maxi: maxi=count[i] index=i if maxi==countd: print("YES") print(index) else: print("NO")
Title: Timofey and a tree Time Limit: None seconds Memory Limit: None megabytes Problem Description: Each New Year Timofey and his friends cut down a tree of *n* vertices and bring it home. After that they paint all the *n* its vertices, so that the *i*-th vertex gets color *c**i*. Now it's time for Timofey birthday, and his mother asked him to remove the tree. Timofey removes the tree in the following way: he takes some vertex in hands, while all the other vertices move down so that the tree becomes rooted at the chosen vertex. After that Timofey brings the tree to a trash can. Timofey doesn't like it when many colors are mixing together. A subtree annoys him if there are vertices of different color in it. Timofey wants to find a vertex which he should take in hands so that there are no subtrees that annoy him. He doesn't consider the whole tree as a subtree since he can't see the color of the root vertex. A subtree of some vertex is a subgraph containing that vertex and all its descendants. Your task is to determine if there is a vertex, taking which in hands Timofey wouldn't be annoyed. Input Specification: The first line contains single integer *n* (2<=≤<=*n*<=≤<=105) — the number of vertices in the tree. Each of the next *n*<=-<=1 lines contains two integers *u* and *v* (1<=≤<=*u*,<=*v*<=≤<=*n*, *u*<=≠<=*v*), denoting there is an edge between vertices *u* and *v*. It is guaranteed that the given graph is a tree. The next line contains *n* integers *c*1,<=*c*2,<=...,<=*c**n* (1<=≤<=*c**i*<=≤<=105), denoting the colors of the vertices. Output Specification: Print "NO" in a single line, if Timofey can't take the tree in such a way that it doesn't annoy him. Otherwise print "YES" in the first line. In the second line print the index of the vertex which Timofey should take in hands. If there are multiple answers, print any of them. Demo Input: ['4\n1 2\n2 3\n3 4\n1 2 1 1\n', '3\n1 2\n2 3\n1 2 3\n', '4\n1 2\n2 3\n3 4\n1 2 1 2\n'] Demo Output: ['YES\n2', 'YES\n2', 'NO'] Note: none
```python n=int(input()) count=[0]*(n+1) arr=[] for i in range(n-1): u,v=map(int,input().split()) arr.append([u,v]) c=list(map(int,input().split())) countd=0 for i,(u,v) in enumerate(arr): if c[u-1]!=c[v-1]: countd+=1 count[u]+=1 count[v]+=1 maxi=0 index=-1 for i in range(1,n+1): if count[i]>maxi: maxi=count[i] index=i if maxi==countd: print("YES") print(index) else: print("NO") ```
0
680
B
Bear and Finding Criminals
PROGRAMMING
1,000
[ "constructive algorithms", "implementation" ]
null
null
There are *n* cities in Bearland, numbered 1 through *n*. Cities are arranged in one long row. The distance between cities *i* and *j* is equal to |*i*<=-<=*j*|. Limak is a police officer. He lives in a city *a*. His job is to catch criminals. It's hard because he doesn't know in which cities criminals are. Though, he knows that there is at most one criminal in each city. Limak is going to use a BCD (Bear Criminal Detector). The BCD will tell Limak how many criminals there are for every distance from a city *a*. After that, Limak can catch a criminal in each city for which he is sure that there must be a criminal. You know in which cities criminals are. Count the number of criminals Limak will catch, after he uses the BCD.
The first line of the input contains two integers *n* and *a* (1<=≤<=*a*<=≤<=*n*<=≤<=100) — the number of cities and the index of city where Limak lives. The second line contains *n* integers *t*1,<=*t*2,<=...,<=*t**n* (0<=≤<=*t**i*<=≤<=1). There are *t**i* criminals in the *i*-th city.
Print the number of criminals Limak will catch.
[ "6 3\n1 1 1 0 1 0\n", "5 2\n0 0 0 1 0\n" ]
[ "3\n", "1\n" ]
In the first sample, there are six cities and Limak lives in the third one (blue arrow below). Criminals are in cities marked red. Using the BCD gives Limak the following information: - There is one criminal at distance 0 from the third city — Limak is sure that this criminal is exactly in the third city. - There is one criminal at distance 1 from the third city — Limak doesn't know if a criminal is in the second or fourth city. - There are two criminals at distance 2 from the third city — Limak is sure that there is one criminal in the first city and one in the fifth city. - There are zero criminals for every greater distance. So, Limak will catch criminals in cities 1, 3 and 5, that is 3 criminals in total. In the second sample (drawing below), the BCD gives Limak the information that there is one criminal at distance 2 from Limak's city. There is only one city at distance 2 so Limak is sure where a criminal is.
1,000
[ { "input": "6 3\n1 1 1 0 1 0", "output": "3" }, { "input": "5 2\n0 0 0 1 0", "output": "1" }, { "input": "1 1\n1", "output": "1" }, { "input": "1 1\n0", "output": "0" }, { "input": "9 3\n1 1 1 1 1 1 1 1 0", "output": "8" }, { "input": "9 5\n1 0 1 0 1 0 1 0 1", "output": "5" }, { "input": "20 17\n1 1 0 1 1 1 1 0 1 0 1 1 1 0 1 1 0 0 0 0", "output": "10" }, { "input": "100 60\n1 1 1 1 1 1 0 1 0 0 1 1 0 1 1 1 1 1 0 0 1 1 0 0 0 0 0 1 0 1 1 0 1 0 1 0 1 0 1 1 0 0 0 0 0 1 1 1 0 1 1 0 0 0 1 0 0 0 1 1 1 0 1 0 0 1 1 1 0 1 1 1 0 0 1 1 0 1 0 0 0 1 0 0 0 0 0 0 1 1 1 0 0 1 1 1 0 1 0 0", "output": "27" }, { "input": "8 1\n1 0 1 1 0 0 1 0", "output": "4" }, { "input": "11 11\n0 1 0 0 1 1 1 0 0 0 0", "output": "4" }, { "input": "19 10\n0 1 1 0 1 0 0 1 1 0 0 1 0 1 0 0 1 0 1", "output": "4" }, { "input": "100 38\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0", "output": "0" }, { "input": "100 38\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0", "output": "1" }, { "input": "100 38\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0", "output": "3" }, { "input": "99 38\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "25" }, { "input": "99 38\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "24" }, { "input": "99 38\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "24" }, { "input": "98 70\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0", "output": "41" }, { "input": "99 70\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "9" }, { "input": "99 60\n0 0 0 1 1 0 1 1 0 0 1 0 0 0 0 0 1 0 1 0 0 0 1 0 1 1 1 0 1 1 1 1 0 0 1 1 1 0 1 1 1 1 1 0 1 1 0 0 0 0 0 1 0 0 1 0 1 1 1 1 1 0 1 0 1 1 0 0 1 0 1 0 0 1 0 0 1 1 1 0 0 0 0 1 1 0 1 1 1 1 0 0 0 0 0 0 1 1 1", "output": "34" }, { "input": "98 24\n0 0 0 1 1 0 1 1 0 0 0 0 1 0 0 1 0 0 1 1 1 0 0 1 0 0 1 0 1 0 0 1 1 0 1 1 1 0 1 0 0 1 0 0 0 1 1 1 1 0 1 1 1 0 1 1 1 1 0 0 1 0 0 0 1 0 1 1 0 1 0 1 1 1 0 0 1 0 0 0 1 1 0 0 1 1 1 1 1 1 0 1 0 1 0 0 1 1", "output": "39" }, { "input": "100 100\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "100" }, { "input": "100 1\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0", "output": "0" }, { "input": "2 1\n0 1", "output": "1" } ]
1,669,256,819
2,147,483,647
PyPy 3-64
WRONG_ANSWER
TESTS
4
46
0
(n, a) = map(int, input().split()) lis = list(map(int, input().split())) criminal = 0 for i in range(n - (a - 1)): l, r = 0, 0 if (a - 1) - i >= 0: l = lis[ (a-1) - i ] try: r = lis[ (a-1) + i ] except: pass if l or r : criminal += 1 print(criminal)
Title: Bear and Finding Criminals Time Limit: None seconds Memory Limit: None megabytes Problem Description: There are *n* cities in Bearland, numbered 1 through *n*. Cities are arranged in one long row. The distance between cities *i* and *j* is equal to |*i*<=-<=*j*|. Limak is a police officer. He lives in a city *a*. His job is to catch criminals. It's hard because he doesn't know in which cities criminals are. Though, he knows that there is at most one criminal in each city. Limak is going to use a BCD (Bear Criminal Detector). The BCD will tell Limak how many criminals there are for every distance from a city *a*. After that, Limak can catch a criminal in each city for which he is sure that there must be a criminal. You know in which cities criminals are. Count the number of criminals Limak will catch, after he uses the BCD. Input Specification: The first line of the input contains two integers *n* and *a* (1<=≤<=*a*<=≤<=*n*<=≤<=100) — the number of cities and the index of city where Limak lives. The second line contains *n* integers *t*1,<=*t*2,<=...,<=*t**n* (0<=≤<=*t**i*<=≤<=1). There are *t**i* criminals in the *i*-th city. Output Specification: Print the number of criminals Limak will catch. Demo Input: ['6 3\n1 1 1 0 1 0\n', '5 2\n0 0 0 1 0\n'] Demo Output: ['3\n', '1\n'] Note: In the first sample, there are six cities and Limak lives in the third one (blue arrow below). Criminals are in cities marked red. Using the BCD gives Limak the following information: - There is one criminal at distance 0 from the third city — Limak is sure that this criminal is exactly in the third city. - There is one criminal at distance 1 from the third city — Limak doesn't know if a criminal is in the second or fourth city. - There are two criminals at distance 2 from the third city — Limak is sure that there is one criminal in the first city and one in the fifth city. - There are zero criminals for every greater distance. So, Limak will catch criminals in cities 1, 3 and 5, that is 3 criminals in total. In the second sample (drawing below), the BCD gives Limak the information that there is one criminal at distance 2 from Limak's city. There is only one city at distance 2 so Limak is sure where a criminal is.
```python (n, a) = map(int, input().split()) lis = list(map(int, input().split())) criminal = 0 for i in range(n - (a - 1)): l, r = 0, 0 if (a - 1) - i >= 0: l = lis[ (a-1) - i ] try: r = lis[ (a-1) + i ] except: pass if l or r : criminal += 1 print(criminal) ```
0
496
B
Secret Combination
PROGRAMMING
1,500
[ "brute force", "constructive algorithms", "implementation" ]
null
null
You got a box with a combination lock. The lock has a display showing *n* digits. There are two buttons on the box, each button changes digits on the display. You have quickly discovered that the first button adds 1 to all the digits (all digits 9 become digits 0), and the second button shifts all the digits on the display one position to the right (the last digit becomes the first one). For example, if the display is currently showing number 579, then if we push the first button, the display will show 680, and if after that we push the second button, the display will show 068. You know that the lock will open if the display is showing the smallest possible number that can be obtained by pushing the buttons in some order. The leading zeros are ignored while comparing numbers. Now your task is to find the desired number.
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of digits on the display. The second line contains *n* digits — the initial state of the display.
Print a single line containing *n* digits — the desired state of the display containing the smallest possible number.
[ "3\n579\n", "4\n2014\n" ]
[ "024\n", "0142\n" ]
none
1,000
[ { "input": "3\n579", "output": "024" }, { "input": "4\n2014", "output": "0142" }, { "input": "1\n1", "output": "0" }, { "input": "3\n039", "output": "014" }, { "input": "4\n4444", "output": "0000" }, { "input": "5\n46802", "output": "02468" }, { "input": "10\n4447444444", "output": "0000000003" }, { "input": "10\n5810438174", "output": "0147609473" }, { "input": "30\n027027027027027027027027027027", "output": "027027027027027027027027027027" }, { "input": "50\n41012516454101251645410125164541012516454101251645", "output": "01076781720107678172010767817201076781720107678172" }, { "input": "72\n464553044645330446455304464553064645530445455304464553044645530446455304", "output": "001011960020119600201196002011960020119600201996002011960020119620201196" }, { "input": "100\n2144315253572020279108092911160072328496568665545836825277616363478721946398140227406814602154768031", "output": "0005996121738545755443472571416650525236761083528703911639570359104365792010332041424619191680979818" }, { "input": "200\n79025531557298703099245700860027432585447902553155729870309924570086002743258544790255315572987030992457008600274325854479025531557298703099245700860027432585447902553155729870309924570086002743258544", "output": "00274325854479025531557298703099245700860027432585447902553155729870309924570086002743258544790255315572987030992457008600274325854479025531557298703099245700860027432585447902553155729870309924570086" }, { "input": "100\n6669666666666666666866266666666666666666666666666666666666666666626666666666666966666766665667666656", "output": "0000000000000000000000000000000000000000006000000000000030000010000900100009000030000000000000002006" }, { "input": "1\n0", "output": "0" } ]
1,580,484,567
2,147,483,647
PyPy 3
OK
TESTS
28
296
6,041,600
from collections import * def flip(x, mi): return str((x + mi) % 10) def solve(): ans = ''.join(s) for i in range(n): mi = (10 - int(s[1])) % 10 for j in range(n): s[j] = flip(int(s[j]), mi) # print(''.join(s)) s.rotate(-1) ans = min(ans, ''.join(s)) return ans n, s = int(input()), deque(input()) if n == 1: print(0) else: print(solve())
Title: Secret Combination Time Limit: None seconds Memory Limit: None megabytes Problem Description: You got a box with a combination lock. The lock has a display showing *n* digits. There are two buttons on the box, each button changes digits on the display. You have quickly discovered that the first button adds 1 to all the digits (all digits 9 become digits 0), and the second button shifts all the digits on the display one position to the right (the last digit becomes the first one). For example, if the display is currently showing number 579, then if we push the first button, the display will show 680, and if after that we push the second button, the display will show 068. You know that the lock will open if the display is showing the smallest possible number that can be obtained by pushing the buttons in some order. The leading zeros are ignored while comparing numbers. Now your task is to find the desired number. Input Specification: The first line contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of digits on the display. The second line contains *n* digits — the initial state of the display. Output Specification: Print a single line containing *n* digits — the desired state of the display containing the smallest possible number. Demo Input: ['3\n579\n', '4\n2014\n'] Demo Output: ['024\n', '0142\n'] Note: none
```python from collections import * def flip(x, mi): return str((x + mi) % 10) def solve(): ans = ''.join(s) for i in range(n): mi = (10 - int(s[1])) % 10 for j in range(n): s[j] = flip(int(s[j]), mi) # print(''.join(s)) s.rotate(-1) ans = min(ans, ''.join(s)) return ans n, s = int(input()), deque(input()) if n == 1: print(0) else: print(solve()) ```
3
0
none
none
none
0
[ "none" ]
null
null
Fox Ciel has *n* boxes in her room. They have the same size and weight, but they might have different strength. The *i*-th box can hold at most *x**i* boxes on its top (we'll call *x**i* the strength of the box). Since all the boxes have the same size, Ciel cannot put more than one box directly on the top of some box. For example, imagine Ciel has three boxes: the first has strength 2, the second has strength 1 and the third has strength 1. She cannot put the second and the third box simultaneously directly on the top of the first one. But she can put the second box directly on the top of the first one, and then the third box directly on the top of the second one. We will call such a construction of boxes a pile. Fox Ciel wants to construct piles from all the boxes. Each pile will contain some boxes from top to bottom, and there cannot be more than *x**i* boxes on the top of *i*-th box. What is the minimal number of piles she needs to construct?
The first line contains an integer *n* (1<=≤<=*n*<=≤<=100). The next line contains *n* integers *x*1,<=*x*2,<=...,<=*x**n* (0<=≤<=*x**i*<=≤<=100).
Output a single integer — the minimal possible number of piles.
[ "3\n0 0 10\n", "5\n0 1 2 3 4\n", "4\n0 0 0 0\n", "9\n0 1 0 2 0 1 1 2 10\n" ]
[ "2\n", "1\n", "4\n", "3\n" ]
In example 1, one optimal way is to build 2 piles: the first pile contains boxes 1 and 3 (from top to bottom), the second pile contains only box 2. In example 2, we can build only 1 pile that contains boxes 1, 2, 3, 4, 5 (from top to bottom).
0
[ { "input": "3\n0 0 10", "output": "2" }, { "input": "5\n0 1 2 3 4", "output": "1" }, { "input": "4\n0 0 0 0", "output": "4" }, { "input": "9\n0 1 0 2 0 1 1 2 10", "output": "3" }, { "input": "1\n0", "output": "1" }, { "input": "2\n0 0", "output": "2" }, { "input": "2\n0 1", "output": "1" }, { "input": "2\n100 99", "output": "1" }, { "input": "9\n0 1 1 0 2 0 3 45 4", "output": "3" }, { "input": "10\n1 1 1 1 2 2 2 2 2 2", "output": "4" }, { "input": "100\n50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50", "output": "2" }, { "input": "100\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0", "output": "100" }, { "input": "100\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100", "output": "1" }, { "input": "11\n71 34 31 71 42 38 64 60 36 76 67", "output": "1" }, { "input": "39\n54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54", "output": "1" }, { "input": "59\n61 33 84 76 56 47 70 94 46 77 95 85 35 90 83 62 48 74 36 74 83 97 62 92 95 75 70 82 94 67 82 42 78 70 50 73 80 76 94 83 96 80 80 88 91 79 83 54 38 90 33 93 53 33 86 95 48 34 46", "output": "1" }, { "input": "87\n52 63 93 90 50 35 67 66 46 89 43 64 33 88 34 80 69 59 75 55 55 68 66 83 46 33 72 36 73 34 54 85 52 87 67 68 47 95 52 78 92 58 71 66 84 61 36 77 69 44 84 70 71 55 43 91 33 65 77 34 43 59 83 70 95 38 92 92 74 53 66 65 81 45 55 89 49 52 43 69 78 41 37 79 63 70 67", "output": "1" }, { "input": "15\n20 69 36 63 40 40 52 42 20 43 59 68 64 49 47", "output": "1" }, { "input": "39\n40 20 49 35 80 18 20 75 39 62 43 59 46 37 58 52 67 16 34 65 32 75 59 42 59 41 68 21 41 61 66 19 34 63 19 63 78 62 24", "output": "1" }, { "input": "18\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0", "output": "18" }, { "input": "46\n14 13 13 10 13 15 8 8 12 9 11 15 8 10 13 8 12 13 11 8 12 15 12 15 11 13 12 9 13 12 10 8 13 15 9 15 8 13 11 8 9 9 9 8 11 8", "output": "3" }, { "input": "70\n6 1 4 1 1 6 5 2 5 1 1 5 2 1 2 4 1 1 1 2 4 5 2 1 6 6 5 2 1 4 3 1 4 3 6 5 2 1 3 4 4 1 4 5 6 2 1 2 4 4 5 3 6 1 1 2 2 1 5 6 1 6 3 1 4 4 2 3 1 4", "output": "11" }, { "input": "94\n11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11", "output": "8" }, { "input": "18\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "9" }, { "input": "46\n14 8 7 4 8 7 8 8 12 9 9 12 9 12 14 8 10 14 14 6 9 11 7 14 14 13 11 4 13 13 11 13 9 10 10 12 10 8 12 10 13 10 7 13 14 6", "output": "4" }, { "input": "74\n4 4 5 5 5 5 5 5 6 6 5 4 4 4 3 3 5 4 5 3 4 4 5 6 3 3 5 4 4 5 4 3 5 5 4 4 3 5 6 4 3 6 6 3 4 5 4 4 3 3 3 6 3 5 6 5 5 5 5 3 6 4 5 4 4 6 6 3 4 5 6 6 6 6", "output": "11" }, { "input": "100\n48 35 44 37 35 42 42 39 49 53 35 55 41 42 42 39 43 49 46 54 48 39 42 53 55 39 56 43 43 38 48 40 54 36 48 55 46 40 41 39 45 56 38 40 47 46 45 46 53 51 38 41 54 35 35 47 42 43 54 54 39 44 49 41 37 49 36 37 37 49 53 44 47 37 55 49 45 40 35 51 44 40 42 35 46 48 53 48 35 38 42 36 54 46 44 47 41 40 41 42", "output": "2" }, { "input": "100\n34 3 37 35 40 44 38 46 13 31 12 23 26 40 26 18 28 36 5 21 2 4 10 29 3 46 38 41 37 28 44 14 39 10 35 17 24 28 38 16 29 6 2 42 47 34 43 2 43 46 7 16 16 43 33 32 20 47 8 48 32 4 45 38 15 7 25 25 19 41 20 35 16 2 31 5 31 25 27 3 45 29 32 36 9 47 39 35 9 21 32 17 21 41 29 48 11 40 5 25", "output": "3" }, { "input": "100\n2 4 5 5 0 5 3 0 3 0 5 3 4 1 0 3 0 5 5 0 4 3 3 3 0 2 1 2 2 4 4 2 4 0 1 3 4 1 4 2 5 3 5 2 3 0 1 2 5 5 2 0 4 2 5 1 0 0 4 0 1 2 0 1 2 4 1 4 5 3 4 5 5 1 0 0 3 1 4 0 4 5 1 3 3 0 4 2 0 4 5 2 3 0 5 1 4 4 1 0", "output": "21" }, { "input": "100\n5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5", "output": "17" }, { "input": "100\n1 1 1 2 2 2 2 2 2 1 1 1 2 0 2 2 0 0 0 0 0 2 0 0 2 2 1 0 2 0 2 1 1 2 2 1 2 2 1 2 1 2 2 1 2 0 1 2 2 0 2 2 2 2 1 0 1 0 0 0 2 0 2 0 1 1 0 2 2 2 2 1 1 1 2 1 1 2 1 1 1 2 1 0 2 1 0 1 2 0 1 1 2 0 0 1 1 0 1 1", "output": "34" }, { "input": "100\n0 3 1 0 3 2 1 2 2 1 2 1 3 2 1 2 1 3 2 0 0 2 3 0 0 2 1 2 2 3 1 2 2 2 0 3 3 2 0 0 1 0 1 2 3 1 0 3 3 3 0 2 1 3 0 1 3 2 2 2 2 3 3 2 0 2 0 1 0 1 3 0 1 2 0 1 3 2 0 3 1 1 2 3 1 3 1 0 3 0 3 0 2 1 1 1 2 2 0 1", "output": "26" }, { "input": "100\n1 0 2 2 2 2 1 0 1 2 2 2 0 1 0 1 2 1 2 1 0 1 2 2 2 1 0 1 0 2 1 2 0 2 1 1 2 1 1 0 1 2 1 1 2 1 1 0 2 2 0 0 1 2 0 2 0 0 1 1 0 0 2 1 2 1 0 2 2 2 2 2 2 1 2 0 1 2 1 2 1 0 1 0 1 0 1 1 0 2 1 0 0 1 2 2 1 0 0 1", "output": "34" }, { "input": "100\n3 4 4 4 3 3 3 3 3 4 4 4 3 3 3 4 3 4 4 4 3 4 3 4 3 4 3 3 4 4 3 4 4 3 4 4 4 4 4 3 4 3 3 3 4 3 3 4 3 4 3 4 3 3 4 4 4 3 3 3 3 3 4 4 3 4 4 3 4 3 3 3 4 4 3 3 3 3 3 4 3 4 4 3 3 4 3 4 3 4 4 4 3 3 3 4 4 4 4 3", "output": "20" }, { "input": "100\n8 7 9 10 2 7 8 11 11 4 7 10 2 5 8 9 10 3 9 4 10 5 5 6 3 8 8 9 6 9 5 5 4 11 4 2 11 8 3 5 6 6 11 9 8 11 9 8 3 3 8 9 8 9 4 8 6 11 4 4 4 9 7 5 3 4 11 3 9 11 8 10 3 5 5 7 6 9 4 5 2 11 3 6 2 10 9 4 6 10 5 11 8 10 10 8 9 8 5 3", "output": "9" }, { "input": "5\n4 1 1 1 1", "output": "2" } ]
1,417,074,712
2,147,483,647
Python 3
WRONG_ANSWER
TESTS
20
77
0
n=int(input()) listn=list(map(int, input().split())) currLimit=n-1 listn=sorted(listn, reverse=True) i=0 res=0 zero=0 for k in listn: if k==0: zero+=1 while i<n: if listn[i]==0: i+=1 continue tmp=i+listn[i] currLimit=min(currLimit, tmp) if i==currLimit: currLimit=n-1 res+=1 if zero: zero-=1 i+=1 print(res+zero)
Title: none Time Limit: None seconds Memory Limit: None megabytes Problem Description: Fox Ciel has *n* boxes in her room. They have the same size and weight, but they might have different strength. The *i*-th box can hold at most *x**i* boxes on its top (we'll call *x**i* the strength of the box). Since all the boxes have the same size, Ciel cannot put more than one box directly on the top of some box. For example, imagine Ciel has three boxes: the first has strength 2, the second has strength 1 and the third has strength 1. She cannot put the second and the third box simultaneously directly on the top of the first one. But she can put the second box directly on the top of the first one, and then the third box directly on the top of the second one. We will call such a construction of boxes a pile. Fox Ciel wants to construct piles from all the boxes. Each pile will contain some boxes from top to bottom, and there cannot be more than *x**i* boxes on the top of *i*-th box. What is the minimal number of piles she needs to construct? Input Specification: The first line contains an integer *n* (1<=≤<=*n*<=≤<=100). The next line contains *n* integers *x*1,<=*x*2,<=...,<=*x**n* (0<=≤<=*x**i*<=≤<=100). Output Specification: Output a single integer — the minimal possible number of piles. Demo Input: ['3\n0 0 10\n', '5\n0 1 2 3 4\n', '4\n0 0 0 0\n', '9\n0 1 0 2 0 1 1 2 10\n'] Demo Output: ['2\n', '1\n', '4\n', '3\n'] Note: In example 1, one optimal way is to build 2 piles: the first pile contains boxes 1 and 3 (from top to bottom), the second pile contains only box 2. In example 2, we can build only 1 pile that contains boxes 1, 2, 3, 4, 5 (from top to bottom).
```python n=int(input()) listn=list(map(int, input().split())) currLimit=n-1 listn=sorted(listn, reverse=True) i=0 res=0 zero=0 for k in listn: if k==0: zero+=1 while i<n: if listn[i]==0: i+=1 continue tmp=i+listn[i] currLimit=min(currLimit, tmp) if i==currLimit: currLimit=n-1 res+=1 if zero: zero-=1 i+=1 print(res+zero) ```
0
707
B
Bakery
PROGRAMMING
1,300
[ "graphs" ]
null
null
Masha wants to open her own bakery and bake muffins in one of the *n* cities numbered from 1 to *n*. There are *m* bidirectional roads, each of whose connects some pair of cities. To bake muffins in her bakery, Masha needs to establish flour supply from some storage. There are only *k* storages, located in different cities numbered *a*1,<=*a*2,<=...,<=*a**k*. Unforunately the law of the country Masha lives in prohibits opening bakery in any of the cities which has storage located in it. She can open it only in one of another *n*<=-<=*k* cities, and, of course, flour delivery should be paid — for every kilometer of path between storage and bakery Masha should pay 1 ruble. Formally, Masha will pay *x* roubles, if she will open the bakery in some city *b* (*a**i*<=≠<=*b* for every 1<=≤<=*i*<=≤<=*k*) and choose a storage in some city *s* (*s*<==<=*a**j* for some 1<=≤<=*j*<=≤<=*k*) and *b* and *s* are connected by some path of roads of summary length *x* (if there are more than one path, Masha is able to choose which of them should be used). Masha is very thrifty and rational. She is interested in a city, where she can open her bakery (and choose one of *k* storages and one of the paths between city with bakery and city with storage) and pay minimum possible amount of rubles for flour delivery. Please help Masha find this amount.
The first line of the input contains three integers *n*, *m* and *k* (1<=≤<=*n*,<=*m*<=≤<=105, 0<=≤<=*k*<=≤<=*n*) — the number of cities in country Masha lives in, the number of roads between them and the number of flour storages respectively. Then *m* lines follow. Each of them contains three integers *u*, *v* and *l* (1<=≤<=*u*,<=*v*<=≤<=*n*, 1<=≤<=*l*<=≤<=109, *u*<=≠<=*v*) meaning that there is a road between cities *u* and *v* of length of *l* kilometers . If *k*<=&gt;<=0, then the last line of the input contains *k* distinct integers *a*1,<=*a*2,<=...,<=*a**k* (1<=≤<=*a**i*<=≤<=*n*) — the number of cities having flour storage located in. If *k*<==<=0 then this line is not presented in the input.
Print the minimum possible amount of rubles Masha should pay for flour delivery in the only line. If the bakery can not be opened (while satisfying conditions) in any of the *n* cities, print <=-<=1 in the only line.
[ "5 4 2\n1 2 5\n1 2 3\n2 3 4\n1 4 10\n1 5\n", "3 1 1\n1 2 3\n3\n" ]
[ "3", "-1" ]
Image illustrates the first sample case. Cities with storage located in and the road representing the answer are darkened.
1,000
[ { "input": "5 4 2\n1 2 5\n1 2 3\n2 3 4\n1 4 10\n1 5", "output": "3" }, { "input": "3 1 1\n1 2 3\n3", "output": "-1" }, { "input": "2 3 1\n1 2 3\n1 2 18\n1 2 13\n2", "output": "3" }, { "input": "3 7 0\n1 3 9\n1 2 5\n1 2 21\n1 2 12\n1 2 13\n2 3 19\n2 3 8", "output": "-1" }, { "input": "4 13 1\n1 4 10\n1 3 6\n1 4 3\n3 4 1\n1 3 2\n1 2 15\n1 4 21\n1 4 20\n2 4 13\n1 4 7\n2 4 2\n1 2 8\n1 3 17\n1", "output": "2" }, { "input": "5 7 3\n2 3 20\n1 2 10\n1 2 11\n4 5 15\n2 3 3\n1 5 19\n1 2 3\n5 3 2", "output": "3" }, { "input": "6 7 4\n5 6 21\n3 6 18\n1 6 5\n4 6 4\n1 2 13\n3 4 7\n1 2 15\n6 1 3 2", "output": "4" }, { "input": "7 39 2\n2 7 10\n5 6 18\n2 7 13\n4 5 11\n3 6 14\n1 2 16\n3 4 2\n1 3 13\n1 5 1\n1 2 20\n1 5 11\n1 4 14\n3 6 21\n1 2 18\n1 4 13\n2 3 4\n3 6 12\n2 5 18\n4 7 17\n1 2 3\n2 3 6\n1 2 21\n1 7 18\n4 6 13\n1 2 13\n1 7 17\n2 3 16\n5 6 5\n2 4 17\n1 2 9\n1 2 21\n4 5 9\n1 2 18\n2 6 6\n2 3 9\n1 4 7\n2 5 7\n3 7 21\n4 5 2\n6 2", "output": "3" }, { "input": "8 57 3\n1 3 15\n2 3 1\n1 7 21\n1 2 8\n2 5 16\n1 6 4\n1 3 2\n3 7 17\n5 8 3\n1 3 18\n1 4 3\n1 2 1\n2 8 14\n1 4 17\n4 5 21\n2 3 6\n3 5 11\n2 8 11\n3 4 1\n1 3 9\n1 4 3\n2 3 12\n1 5 9\n2 3 15\n1 2 14\n1 2 10\n1 4 19\n5 7 7\n5 8 20\n5 8 1\n1 4 3\n4 5 8\n5 7 2\n1 2 14\n4 5 9\n6 7 2\n2 6 9\n2 6 4\n3 7 4\n3 5 11\n4 8 19\n3 7 15\n1 8 21\n6 7 11\n4 6 2\n2 3 21\n6 7 2\n6 8 4\n1 3 21\n3 4 1\n4 5 15\n4 7 21\n2 6 2\n5 6 16\n5 8 9\n2 5 6\n1 7 17\n1 4 8", "output": "1" }, { "input": "350 10 39\n2 13 693\n6 31 482\n72 312 617\n183 275 782\n81 123 887\n26 120 1205\n135 185 822\n64 219 820\n74 203 874\n19 167 1422\n252 332 204 334 100 350 26 14 134 213 32 84 331 215 181 158 99 190 206 265 343 241 287 74 113 15 12 338 27 110 98 132 35 95 51 315 297 69 163", "output": "874" }, { "input": "7 7 3\n1 2 1\n2 4 1\n3 4 1\n1 3 1\n5 7 2\n6 7 10\n5 6 5\n5 6 7", "output": "-1" }, { "input": "7 8 3\n1 2 1\n2 4 1\n3 4 1\n1 3 1\n5 7 2\n6 7 10\n5 6 5\n2 5 31246\n5 6 7", "output": "31246" }, { "input": "5 5 5\n1 2 1\n2 3 2\n3 4 3\n4 5 5\n1 5 6\n1 2 3 4 5", "output": "-1" }, { "input": "10 10 3\n1 2 1000000000\n2 3 1000000000\n3 4 1000000000\n4 5 1000000000\n5 6 1000000000\n6 7 1000000000\n7 8 1000000000\n8 9 1000000000\n9 10 1000000000\n10 1 1000000000\n1 2 3", "output": "1000000000" }, { "input": "2 1 1\n1 2 1000000000\n1", "output": "1000000000" }, { "input": "99999 1 0\n1 2 3", "output": "-1" }, { "input": "99999 1 2\n1 2 3\n2 4", "output": "3" }, { "input": "2 1 1\n1 2 99999999\n1", "output": "99999999" }, { "input": "2 1 1\n1 2 999999\n2", "output": "999999" } ]
1,693,131,373
2,147,483,647
PyPy 3-64
TIME_LIMIT_EXCEEDED
TESTS
40
2,000
17,408,000
n, m, k = map(int, input().split()) Graph = [] Muka = [] for i in range(m): u, v, l = map(int, input().split()) Graph.append([u, v, l]) if k > 0: Muka = list(map(int, input().split())) cheap = 6000000000 cheap_town = 1 for i in range(len(Graph)): if Graph[i][0] in Muka and Graph[i][1] not in Muka: if cheap > Graph[i][2]: cheap = Graph[i][2] cheap_town = Graph[i][1] if Graph[i][0] not in Muka and Graph[i][1] in Muka: if cheap > Graph[i][2]: cheap = Graph[i][2] cheap_town = Graph[i][0] if cheap == 6000000000: print(-1) else: print(cheap) else: print(-1)
Title: Bakery Time Limit: None seconds Memory Limit: None megabytes Problem Description: Masha wants to open her own bakery and bake muffins in one of the *n* cities numbered from 1 to *n*. There are *m* bidirectional roads, each of whose connects some pair of cities. To bake muffins in her bakery, Masha needs to establish flour supply from some storage. There are only *k* storages, located in different cities numbered *a*1,<=*a*2,<=...,<=*a**k*. Unforunately the law of the country Masha lives in prohibits opening bakery in any of the cities which has storage located in it. She can open it only in one of another *n*<=-<=*k* cities, and, of course, flour delivery should be paid — for every kilometer of path between storage and bakery Masha should pay 1 ruble. Formally, Masha will pay *x* roubles, if she will open the bakery in some city *b* (*a**i*<=≠<=*b* for every 1<=≤<=*i*<=≤<=*k*) and choose a storage in some city *s* (*s*<==<=*a**j* for some 1<=≤<=*j*<=≤<=*k*) and *b* and *s* are connected by some path of roads of summary length *x* (if there are more than one path, Masha is able to choose which of them should be used). Masha is very thrifty and rational. She is interested in a city, where she can open her bakery (and choose one of *k* storages and one of the paths between city with bakery and city with storage) and pay minimum possible amount of rubles for flour delivery. Please help Masha find this amount. Input Specification: The first line of the input contains three integers *n*, *m* and *k* (1<=≤<=*n*,<=*m*<=≤<=105, 0<=≤<=*k*<=≤<=*n*) — the number of cities in country Masha lives in, the number of roads between them and the number of flour storages respectively. Then *m* lines follow. Each of them contains three integers *u*, *v* and *l* (1<=≤<=*u*,<=*v*<=≤<=*n*, 1<=≤<=*l*<=≤<=109, *u*<=≠<=*v*) meaning that there is a road between cities *u* and *v* of length of *l* kilometers . If *k*<=&gt;<=0, then the last line of the input contains *k* distinct integers *a*1,<=*a*2,<=...,<=*a**k* (1<=≤<=*a**i*<=≤<=*n*) — the number of cities having flour storage located in. If *k*<==<=0 then this line is not presented in the input. Output Specification: Print the minimum possible amount of rubles Masha should pay for flour delivery in the only line. If the bakery can not be opened (while satisfying conditions) in any of the *n* cities, print <=-<=1 in the only line. Demo Input: ['5 4 2\n1 2 5\n1 2 3\n2 3 4\n1 4 10\n1 5\n', '3 1 1\n1 2 3\n3\n'] Demo Output: ['3', '-1'] Note: Image illustrates the first sample case. Cities with storage located in and the road representing the answer are darkened.
```python n, m, k = map(int, input().split()) Graph = [] Muka = [] for i in range(m): u, v, l = map(int, input().split()) Graph.append([u, v, l]) if k > 0: Muka = list(map(int, input().split())) cheap = 6000000000 cheap_town = 1 for i in range(len(Graph)): if Graph[i][0] in Muka and Graph[i][1] not in Muka: if cheap > Graph[i][2]: cheap = Graph[i][2] cheap_town = Graph[i][1] if Graph[i][0] not in Muka and Graph[i][1] in Muka: if cheap > Graph[i][2]: cheap = Graph[i][2] cheap_town = Graph[i][0] if cheap == 6000000000: print(-1) else: print(cheap) else: print(-1) ```
0
4
A
Watermelon
PROGRAMMING
800
[ "brute force", "math" ]
A. Watermelon
1
64
One hot summer day Pete and his friend Billy decided to buy a watermelon. They chose the biggest and the ripest one, in their opinion. After that the watermelon was weighed, and the scales showed *w* kilos. They rushed home, dying of thirst, and decided to divide the berry, however they faced a hard problem. Pete and Billy are great fans of even numbers, that's why they want to divide the watermelon in such a way that each of the two parts weighs even number of kilos, at the same time it is not obligatory that the parts are equal. The boys are extremely tired and want to start their meal as soon as possible, that's why you should help them and find out, if they can divide the watermelon in the way they want. For sure, each of them should get a part of positive weight.
The first (and the only) input line contains integer number *w* (1<=≤<=*w*<=≤<=100) — the weight of the watermelon bought by the boys.
Print YES, if the boys can divide the watermelon into two parts, each of them weighing even number of kilos; and NO in the opposite case.
[ "8\n" ]
[ "YES\n" ]
For example, the boys can divide the watermelon into two parts of 2 and 6 kilos respectively (another variant — two parts of 4 and 4 kilos).
0
[ { "input": "8", "output": "YES" }, { "input": "5", "output": "NO" }, { "input": "4", "output": "YES" }, { "input": "3", "output": "NO" }, { "input": "2", "output": "NO" }, { "input": "1", "output": "NO" }, { "input": "7", "output": "NO" }, { "input": "6", "output": "YES" }, { "input": "10", "output": "YES" }, { "input": "9", "output": "NO" }, { "input": "53", "output": "NO" }, { "input": "77", "output": "NO" }, { "input": "32", "output": "YES" }, { "input": "44", "output": "YES" }, { "input": "98", "output": "YES" }, { "input": "99", "output": "NO" }, { "input": "90", "output": "YES" }, { "input": "67", "output": "NO" }, { "input": "100", "output": "YES" }, { "input": "88", "output": "YES" } ]
1,689,777,227
2,147,483,647
PyPy 3
WRONG_ANSWER
TESTS
0
124
0
def sol(): w = int(input()) return 'YESY' if w == (w // 2) * 2 else 'NO' if __name__ == "__main__": sol()
Title: Watermelon Time Limit: 1 seconds Memory Limit: 64 megabytes Problem Description: One hot summer day Pete and his friend Billy decided to buy a watermelon. They chose the biggest and the ripest one, in their opinion. After that the watermelon was weighed, and the scales showed *w* kilos. They rushed home, dying of thirst, and decided to divide the berry, however they faced a hard problem. Pete and Billy are great fans of even numbers, that's why they want to divide the watermelon in such a way that each of the two parts weighs even number of kilos, at the same time it is not obligatory that the parts are equal. The boys are extremely tired and want to start their meal as soon as possible, that's why you should help them and find out, if they can divide the watermelon in the way they want. For sure, each of them should get a part of positive weight. Input Specification: The first (and the only) input line contains integer number *w* (1<=≤<=*w*<=≤<=100) — the weight of the watermelon bought by the boys. Output Specification: Print YES, if the boys can divide the watermelon into two parts, each of them weighing even number of kilos; and NO in the opposite case. Demo Input: ['8\n'] Demo Output: ['YES\n'] Note: For example, the boys can divide the watermelon into two parts of 2 and 6 kilos respectively (another variant — two parts of 4 and 4 kilos).
```python def sol(): w = int(input()) return 'YESY' if w == (w // 2) * 2 else 'NO' if __name__ == "__main__": sol() ```
0
203
A
Two Problems
PROGRAMMING
1,200
[ "brute force", "implementation" ]
null
null
A boy Valera registered on site Codeforces as Valera, and wrote his first Codeforces Round #300. He boasted to a friend Arkady about winning as much as *x* points for his first contest. But Arkady did not believe his friend's words and decided to check whether Valera could have shown such a result. He knows that the contest number 300 was unusual because there were only two problems. The contest lasted for *t* minutes, the minutes are numbered starting from zero. The first problem had the initial cost of *a* points, and every minute its cost reduced by *d**a* points. The second problem had the initial cost of *b* points, and every minute this cost reduced by *d**b* points. Thus, as soon as the zero minute of the contest is over, the first problem will cost *a*<=-<=*d**a* points, and the second problem will cost *b*<=-<=*d**b* points. It is guaranteed that at any moment of the contest each problem has a non-negative cost. Arkady asks you to find out whether Valera could have got exactly *x* points for this contest. You should assume that Valera could have solved any number of the offered problems. You should also assume that for each problem Valera made no more than one attempt, besides, he could have submitted both problems at the same minute of the contest, starting with minute 0 and ending with minute number *t*<=-<=1. Please note that Valera can't submit a solution exactly *t* minutes after the start of the contest or later.
The single line of the input contains six integers *x*,<=*t*,<=*a*,<=*b*,<=*d**a*,<=*d**b* (0<=≤<=*x*<=≤<=600; 1<=≤<=*t*,<=*a*,<=*b*,<=*d**a*,<=*d**b*<=≤<=300) — Valera's result, the contest's duration, the initial cost of the first problem, the initial cost of the second problem, the number of points that the first and the second problem lose per minute, correspondingly. It is guaranteed that at each minute of the contest each problem has a non-negative cost, that is, *a*<=-<=*i*·*d**a*<=≥<=0 and *b*<=-<=*i*·*d**b*<=≥<=0 for all 0<=≤<=*i*<=≤<=*t*<=-<=1.
If Valera could have earned exactly *x* points at a contest, print "YES", otherwise print "NO" (without the quotes).
[ "30 5 20 20 3 5\n", "10 4 100 5 5 1\n" ]
[ "YES\n", "NO\n" ]
In the first sample Valera could have acted like this: he could have submitted the first problem at minute 0 and the second problem — at minute 2. Then the first problem brings him 20 points and the second problem brings him 10 points, that in total gives the required 30 points.
500
[ { "input": "30 5 20 20 3 5", "output": "YES" }, { "input": "10 4 100 5 5 1", "output": "NO" }, { "input": "0 7 30 50 3 4", "output": "YES" }, { "input": "50 10 30 20 1 2", "output": "YES" }, { "input": "40 1 40 5 11 2", "output": "YES" }, { "input": "35 8 20 20 1 2", "output": "YES" }, { "input": "10 2 27 4 11 1", "output": "NO" }, { "input": "64 12 258 141 10 7", "output": "YES" }, { "input": "5 3 11 100 2 4", "output": "NO" }, { "input": "5 4 11 80 2 4", "output": "YES" }, { "input": "28 3 16 20 3 10", "output": "NO" }, { "input": "6 2 11 1 11 1", "output": "NO" }, { "input": "15 5 230 213 32 25", "output": "NO" }, { "input": "223 92 123 118 1 1", "output": "YES" }, { "input": "375 6 133 267 19 36", "output": "NO" }, { "input": "80 5 39 40 1 1", "output": "NO" }, { "input": "543 4 31 69 6 5", "output": "NO" }, { "input": "38 100 99 245 1 1", "output": "YES" }, { "input": "3 1 20 15 17 5", "output": "NO" }, { "input": "360 5 215 4 52 1", "output": "NO" }, { "input": "363 2 280 239 5 231", "output": "NO" }, { "input": "46 7 18 6 3 1", "output": "NO" }, { "input": "5 3 135 12 21 6", "output": "NO" }, { "input": "15 5 230 213 32 25", "output": "NO" }, { "input": "2 5 29 36 5 6", "output": "NO" }, { "input": "59 4 113 45 25 12", "output": "YES" }, { "input": "74 72 104 71 1 1", "output": "YES" }, { "input": "16 24 26 23 1 1", "output": "YES" }, { "input": "11 1 10 1 10 1", "output": "YES" }, { "input": "13 3 11 14 5 1", "output": "YES" }, { "input": "1 2 1 2 1 2", "output": "YES" }, { "input": "145 26 25 150 1 4", "output": "YES" }, { "input": "59 18 50 17 1 1", "output": "YES" }, { "input": "230 125 175 124 1 1", "output": "YES" }, { "input": "142 1 66 76 18 39", "output": "YES" }, { "input": "0 3 5 6 1 2", "output": "YES" }, { "input": "6 46 95 45 1 1", "output": "YES" }, { "input": "16 73 92 72 1 1", "output": "YES" }, { "input": "3 18 272 17 6 1", "output": "YES" }, { "input": "1 21 178 20 1 1", "output": "YES" }, { "input": "0 15 86 84 5 2", "output": "YES" }, { "input": "0 35 208 98 6 2", "output": "YES" }, { "input": "0 11 67 82 6 4", "output": "YES" }, { "input": "30 9 18 83 1 7", "output": "NO" }, { "input": "18 12 11 54 1 3", "output": "NO" }, { "input": "41 77 96 145 1 1", "output": "YES" }, { "input": "27 45 44 169 1 2", "output": "YES" }, { "input": "50 5 30 60 3 3", "output": "NO" }, { "input": "49 2 50 20 2 1", "output": "NO" }, { "input": "49 2 50 20 2 1", "output": "NO" }, { "input": "17 10 10 20 1 2", "output": "YES" } ]
1,455,928,244
2,147,483,647
Python 3
OK
TESTS
51
124
0
def main(): x, t, a, b, da, db = map(int, input().split()) db *= -1 tdb = t * db s = {z for y in range(a + b, a + b - da * t, -da) for z in range(y, y + tdb, db)} s.update(range(a, a - da * t, -da)) s.update(range(b, b + tdb, db)) s.add(0) print(("NO", "YES")[x in s]) if __name__ == '__main__': main()
Title: Two Problems Time Limit: None seconds Memory Limit: None megabytes Problem Description: A boy Valera registered on site Codeforces as Valera, and wrote his first Codeforces Round #300. He boasted to a friend Arkady about winning as much as *x* points for his first contest. But Arkady did not believe his friend's words and decided to check whether Valera could have shown such a result. He knows that the contest number 300 was unusual because there were only two problems. The contest lasted for *t* minutes, the minutes are numbered starting from zero. The first problem had the initial cost of *a* points, and every minute its cost reduced by *d**a* points. The second problem had the initial cost of *b* points, and every minute this cost reduced by *d**b* points. Thus, as soon as the zero minute of the contest is over, the first problem will cost *a*<=-<=*d**a* points, and the second problem will cost *b*<=-<=*d**b* points. It is guaranteed that at any moment of the contest each problem has a non-negative cost. Arkady asks you to find out whether Valera could have got exactly *x* points for this contest. You should assume that Valera could have solved any number of the offered problems. You should also assume that for each problem Valera made no more than one attempt, besides, he could have submitted both problems at the same minute of the contest, starting with minute 0 and ending with minute number *t*<=-<=1. Please note that Valera can't submit a solution exactly *t* minutes after the start of the contest or later. Input Specification: The single line of the input contains six integers *x*,<=*t*,<=*a*,<=*b*,<=*d**a*,<=*d**b* (0<=≤<=*x*<=≤<=600; 1<=≤<=*t*,<=*a*,<=*b*,<=*d**a*,<=*d**b*<=≤<=300) — Valera's result, the contest's duration, the initial cost of the first problem, the initial cost of the second problem, the number of points that the first and the second problem lose per minute, correspondingly. It is guaranteed that at each minute of the contest each problem has a non-negative cost, that is, *a*<=-<=*i*·*d**a*<=≥<=0 and *b*<=-<=*i*·*d**b*<=≥<=0 for all 0<=≤<=*i*<=≤<=*t*<=-<=1. Output Specification: If Valera could have earned exactly *x* points at a contest, print "YES", otherwise print "NO" (without the quotes). Demo Input: ['30 5 20 20 3 5\n', '10 4 100 5 5 1\n'] Demo Output: ['YES\n', 'NO\n'] Note: In the first sample Valera could have acted like this: he could have submitted the first problem at minute 0 and the second problem — at minute 2. Then the first problem brings him 20 points and the second problem brings him 10 points, that in total gives the required 30 points.
```python def main(): x, t, a, b, da, db = map(int, input().split()) db *= -1 tdb = t * db s = {z for y in range(a + b, a + b - da * t, -da) for z in range(y, y + tdb, db)} s.update(range(a, a - da * t, -da)) s.update(range(b, b + tdb, db)) s.add(0) print(("NO", "YES")[x in s]) if __name__ == '__main__': main() ```
3
849
A
Odds and Ends
PROGRAMMING
1,000
[ "implementation" ]
null
null
Where do odds begin, and where do they end? Where does hope emerge, and will they ever break? Given an integer sequence *a*1,<=*a*2,<=...,<=*a**n* of length *n*. Decide whether it is possible to divide it into an odd number of non-empty subsegments, the each of which has an odd length and begins and ends with odd numbers. A subsegment is a contiguous slice of the whole sequence. For example, {3,<=4,<=5} and {1} are subsegments of sequence {1,<=2,<=3,<=4,<=5,<=6}, while {1,<=2,<=4} and {7} are not.
The first line of input contains a non-negative integer *n* (1<=≤<=*n*<=≤<=100) — the length of the sequence. The second line contains *n* space-separated non-negative integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=100) — the elements of the sequence.
Output "Yes" if it's possible to fulfill the requirements, and "No" otherwise. You can output each letter in any case (upper or lower).
[ "3\n1 3 5\n", "5\n1 0 1 5 1\n", "3\n4 3 1\n", "4\n3 9 9 3\n" ]
[ "Yes\n", "Yes\n", "No\n", "No\n" ]
In the first example, divide the sequence into 1 subsegment: {1, 3, 5} and the requirements will be met. In the second example, divide the sequence into 3 subsegments: {1, 0, 1}, {5}, {1}. In the third example, one of the subsegments must start with 4 which is an even number, thus the requirements cannot be met. In the fourth example, the sequence can be divided into 2 subsegments: {3, 9, 9}, {3}, but this is not a valid solution because 2 is an even number.
500
[ { "input": "3\n1 3 5", "output": "Yes" }, { "input": "5\n1 0 1 5 1", "output": "Yes" }, { "input": "3\n4 3 1", "output": "No" }, { "input": "4\n3 9 9 3", "output": "No" }, { "input": "1\n1", "output": "Yes" }, { "input": "5\n100 99 100 99 99", "output": "No" }, { "input": "100\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100", "output": "No" }, { "input": "1\n0", "output": "No" }, { "input": "2\n1 1", "output": "No" }, { "input": "2\n10 10", "output": "No" }, { "input": "2\n54 21", "output": "No" }, { "input": "5\n0 0 0 0 0", "output": "No" }, { "input": "5\n67 92 0 26 43", "output": "Yes" }, { "input": "15\n45 52 35 80 68 80 93 57 47 32 69 23 63 90 43", "output": "Yes" }, { "input": "15\n81 28 0 82 71 64 63 89 87 92 38 30 76 72 36", "output": "No" }, { "input": "50\n49 32 17 59 77 98 65 50 85 10 40 84 65 34 52 25 1 31 61 45 48 24 41 14 76 12 33 76 44 86 53 33 92 58 63 93 50 24 31 79 67 50 72 93 2 38 32 14 87 99", "output": "No" }, { "input": "55\n65 69 53 66 11 100 68 44 43 17 6 66 24 2 6 6 61 72 91 53 93 61 52 96 56 42 6 8 79 49 76 36 83 58 8 43 2 90 71 49 80 21 75 13 76 54 95 61 58 82 40 33 73 61 46", "output": "No" }, { "input": "99\n73 89 51 85 42 67 22 80 75 3 90 0 52 100 90 48 7 15 41 1 54 2 23 62 86 68 2 87 57 12 45 34 68 54 36 49 27 46 22 70 95 90 57 91 90 79 48 89 67 92 28 27 25 37 73 66 13 89 7 99 62 53 48 24 73 82 62 88 26 39 21 86 50 95 26 27 60 6 56 14 27 90 55 80 97 18 37 36 70 2 28 53 36 77 39 79 82 42 69", "output": "Yes" }, { "input": "99\n99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99", "output": "Yes" }, { "input": "100\n61 63 34 45 20 91 31 28 40 27 94 1 73 5 69 10 56 94 80 23 79 99 59 58 13 56 91 59 77 78 88 72 80 72 70 71 63 60 41 41 41 27 83 10 43 14 35 48 0 78 69 29 63 33 42 67 1 74 51 46 79 41 37 61 16 29 82 28 22 14 64 49 86 92 82 55 54 24 75 58 95 31 3 34 26 23 78 91 49 6 30 57 27 69 29 54 42 0 61 83", "output": "No" }, { "input": "6\n1 2 2 2 2 1", "output": "No" }, { "input": "3\n1 2 1", "output": "Yes" }, { "input": "4\n1 3 2 3", "output": "No" }, { "input": "6\n1 1 1 1 1 1", "output": "No" }, { "input": "6\n1 1 0 0 1 1", "output": "No" }, { "input": "4\n1 4 9 3", "output": "No" }, { "input": "4\n1 0 1 1", "output": "No" }, { "input": "10\n1 0 0 1 1 1 1 1 1 1", "output": "No" }, { "input": "10\n9 2 5 7 8 3 1 9 4 9", "output": "No" }, { "input": "99\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2", "output": "No" }, { "input": "6\n1 2 1 2 2 1", "output": "No" }, { "input": "6\n1 0 1 0 0 1", "output": "No" }, { "input": "4\n1 3 4 7", "output": "No" }, { "input": "8\n1 1 1 2 1 1 1 1", "output": "No" }, { "input": "3\n1 1 2", "output": "No" }, { "input": "5\n1 2 1 2 1", "output": "Yes" }, { "input": "5\n5 4 4 2 1", "output": "Yes" }, { "input": "6\n1 3 3 3 3 1", "output": "No" }, { "input": "7\n1 2 1 2 2 2 1", "output": "Yes" }, { "input": "4\n1 2 2 1", "output": "No" }, { "input": "6\n1 2 3 4 6 5", "output": "No" }, { "input": "5\n1 1 2 2 2", "output": "No" }, { "input": "5\n1 0 0 1 1", "output": "Yes" }, { "input": "3\n1 2 4", "output": "No" }, { "input": "3\n1 0 2", "output": "No" }, { "input": "5\n1 1 1 0 1", "output": "Yes" }, { "input": "4\n3 9 2 3", "output": "No" }, { "input": "6\n1 1 1 4 4 1", "output": "No" }, { "input": "6\n1 2 3 5 6 7", "output": "No" }, { "input": "6\n1 1 1 2 2 1", "output": "No" }, { "input": "6\n1 1 1 0 0 1", "output": "No" }, { "input": "5\n1 2 2 5 5", "output": "Yes" }, { "input": "5\n1 3 2 4 5", "output": "Yes" }, { "input": "8\n1 2 3 5 7 8 8 5", "output": "No" }, { "input": "10\n1 1 1 2 1 1 1 1 1 1", "output": "No" }, { "input": "4\n1 0 0 1", "output": "No" }, { "input": "7\n1 0 1 1 0 0 1", "output": "Yes" }, { "input": "7\n1 4 5 7 6 6 3", "output": "Yes" }, { "input": "4\n2 2 2 2", "output": "No" }, { "input": "5\n2 3 4 5 6", "output": "No" }, { "input": "4\n1 1 2 1", "output": "No" }, { "input": "3\n1 2 3", "output": "Yes" }, { "input": "6\n1 3 3 2 2 3", "output": "No" }, { "input": "4\n1 1 2 3", "output": "No" }, { "input": "4\n1 2 3 5", "output": "No" }, { "input": "5\n3 4 4 3 3", "output": "Yes" }, { "input": "4\n3 2 2 3", "output": "No" }, { "input": "6\n1 1 1 1 2 1", "output": "No" }, { "input": "6\n1 1 2 2 1 1", "output": "No" }, { "input": "10\n3 4 2 4 3 2 2 4 4 3", "output": "No" }, { "input": "7\n1 2 4 3 2 4 5", "output": "Yes" }, { "input": "28\n75 51 25 52 13 7 34 29 5 59 68 56 13 2 9 37 59 83 18 32 36 30 20 43 92 76 78 67", "output": "No" }, { "input": "79\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 18", "output": "No" }, { "input": "100\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "No" } ]
1,534,847,522
2,147,483,647
Python 3
COMPILATION_ERROR
TESTS
0
0
0
#include<bits/stdc++.h> using namespace std; int n, a[105], dp[105][105]; bool cek(int awal, int sum) { // cout << awal << " " << sum << endl; if (awal == n && sum % 2 == 1) { return true; } if (awal == n) return false; if (dp[awal][sum] != -1) return dp[awal][sum]; int len = n - awal; if (len % 2 == 0) len--; while(len > 0) { bool bol = false; if (a[awal] % 2 == 1 && a[awal+len-1] % 2 == 1) bol = cek(awal+len, sum+1); if (bol) return true; len -= 2; } dp[awal][sum] = 0; return dp[awal][sum]; } int main() { scanf("%d", &n); memset(dp, -1, sizeof dp); for (int i = 0; i < n; i++) cin >> a[i]; if (cek(0, 0)) { puts("Yes"); } else { puts("No"); } return 0; }
Title: Odds and Ends Time Limit: None seconds Memory Limit: None megabytes Problem Description: Where do odds begin, and where do they end? Where does hope emerge, and will they ever break? Given an integer sequence *a*1,<=*a*2,<=...,<=*a**n* of length *n*. Decide whether it is possible to divide it into an odd number of non-empty subsegments, the each of which has an odd length and begins and ends with odd numbers. A subsegment is a contiguous slice of the whole sequence. For example, {3,<=4,<=5} and {1} are subsegments of sequence {1,<=2,<=3,<=4,<=5,<=6}, while {1,<=2,<=4} and {7} are not. Input Specification: The first line of input contains a non-negative integer *n* (1<=≤<=*n*<=≤<=100) — the length of the sequence. The second line contains *n* space-separated non-negative integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=100) — the elements of the sequence. Output Specification: Output "Yes" if it's possible to fulfill the requirements, and "No" otherwise. You can output each letter in any case (upper or lower). Demo Input: ['3\n1 3 5\n', '5\n1 0 1 5 1\n', '3\n4 3 1\n', '4\n3 9 9 3\n'] Demo Output: ['Yes\n', 'Yes\n', 'No\n', 'No\n'] Note: In the first example, divide the sequence into 1 subsegment: {1, 3, 5} and the requirements will be met. In the second example, divide the sequence into 3 subsegments: {1, 0, 1}, {5}, {1}. In the third example, one of the subsegments must start with 4 which is an even number, thus the requirements cannot be met. In the fourth example, the sequence can be divided into 2 subsegments: {3, 9, 9}, {3}, but this is not a valid solution because 2 is an even number.
```python #include<bits/stdc++.h> using namespace std; int n, a[105], dp[105][105]; bool cek(int awal, int sum) { // cout << awal << " " << sum << endl; if (awal == n && sum % 2 == 1) { return true; } if (awal == n) return false; if (dp[awal][sum] != -1) return dp[awal][sum]; int len = n - awal; if (len % 2 == 0) len--; while(len > 0) { bool bol = false; if (a[awal] % 2 == 1 && a[awal+len-1] % 2 == 1) bol = cek(awal+len, sum+1); if (bol) return true; len -= 2; } dp[awal][sum] = 0; return dp[awal][sum]; } int main() { scanf("%d", &n); memset(dp, -1, sizeof dp); for (int i = 0; i < n; i++) cin >> a[i]; if (cek(0, 0)) { puts("Yes"); } else { puts("No"); } return 0; } ```
-1
358
A
Dima and Continuous Line
PROGRAMMING
1,400
[ "brute force", "implementation" ]
null
null
Dima and Seryozha live in an ordinary dormitory room for two. One day Dima had a date with his girl and he asked Seryozha to leave the room. As a compensation, Seryozha made Dima do his homework. The teacher gave Seryozha the coordinates of *n* distinct points on the abscissa axis and asked to consecutively connect them by semi-circus in a certain order: first connect the first point with the second one, then connect the second point with the third one, then the third one with the fourth one and so on to the *n*-th point. Two points with coordinates (*x*1,<=0) and (*x*2,<=0) should be connected by a semi-circle that passes above the abscissa axis with the diameter that coincides with the segment between points. Seryozha needs to find out if the line on the picture intersects itself. For clarifications, see the picture Seryozha showed to Dima (the left picture has self-intersections, the right picture doesn't have any). Seryozha is not a small boy, so the coordinates of the points can be rather large. Help Dima cope with the problem.
The first line contains a single integer *n* (1<=≤<=*n*<=≤<=103). The second line contains *n* distinct integers *x*1,<=*x*2,<=...,<=*x**n* (<=-<=106<=≤<=*x**i*<=≤<=106) — the *i*-th point has coordinates (*x**i*,<=0). The points are not necessarily sorted by their *x* coordinate.
In the single line print "yes" (without the quotes), if the line has self-intersections. Otherwise, print "no" (without the quotes).
[ "4\n0 10 5 15\n", "4\n0 15 5 10\n" ]
[ "yes\n", "no\n" ]
The first test from the statement is on the picture to the left, the second test is on the picture to the right.
500
[ { "input": "4\n0 10 5 15", "output": "yes" }, { "input": "4\n0 15 5 10", "output": "no" }, { "input": "5\n0 1000 2000 3000 1500", "output": "yes" }, { "input": "5\n-724093 710736 -383722 -359011 439613", "output": "no" }, { "input": "50\n384672 661179 -775591 -989608 611120 442691 601796 502406 384323 -315945 -934146 873993 -156910 -94123 -930137 208544 816236 466922 473696 463604 794454 -872433 -149791 -858684 -467655 -555239 623978 -217138 -408658 493342 -733576 -350871 711210 884148 -426172 519986 -356885 527171 661680 977247 141654 906254 -961045 -759474 -48634 891473 -606365 -513781 -966166 27696", "output": "yes" }, { "input": "100\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100", "output": "no" }, { "input": "11\n1 11 10 2 3 9 8 4 5 7 6", "output": "no" }, { "input": "10\n3 2 4 5 1 6 9 7 8 10", "output": "yes" }, { "input": "11\n3 4 2 5 1 6 11 7 10 8 9", "output": "no" }, { "input": "15\n0 -1 1 2 3 13 12 4 11 10 5 6 7 9 8", "output": "no" }, { "input": "16\n6 7 8 9 5 10 11 12 13 14 15 4 16 2 1 3", "output": "yes" }, { "input": "1\n0", "output": "no" }, { "input": "4\n3 1 4 2", "output": "yes" }, { "input": "5\n0 2 4 -2 5", "output": "no" }, { "input": "5\n1 9 8 7 0", "output": "yes" }, { "input": "3\n5 10 0", "output": "no" }, { "input": "6\n1 3 -1 5 2 4", "output": "yes" }, { "input": "4\n3 2 4 1", "output": "no" }, { "input": "4\n10 5 15 0", "output": "no" }, { "input": "2\n-5 -10", "output": "no" }, { "input": "3\n1 0 3", "output": "no" }, { "input": "4\n-2 -4 1 -3", "output": "yes" }, { "input": "4\n3 6 0 2", "output": "no" }, { "input": "4\n-9 10 -10 0", "output": "yes" }, { "input": "4\n5 10 1 15", "output": "no" }, { "input": "3\n1 0 2", "output": "no" }, { "input": "4\n2 3 4 1", "output": "no" }, { "input": "4\n7 5 9 12", "output": "no" } ]
1,571,684,280
2,147,483,647
Python 3
OK
TESTS
37
389
409,600
import sys import itertools import math import collections from collections import Counter ######################### # imgur.com/Pkt7iIf.png # ######################### def sieve(n): prime = [True for i in range(n + 1)] p = 2 while (p * p <= n): if (prime[p] == True): for i in range(p * 2, n + 1, p): prime[i] = False p += 1 prime[0] = prime[1] = False r = [p for p in range(n + 1) if prime[p]] return r def divs(n, start=1): r = [] for i in range(start, int(math.sqrt(n) + 1)): if (n % i == 0): if (n / i == i): r.append(i) else: r.extend([i, n // i]) return r def ceil(n, k): return n // k + (n % k != 0) def ii(): return int(input()) def mi(): return map(int, input().split()) def li(): return list(map(int, input().split())) def lcm(a, b): return abs(a * b) // math.gcd(a, b) def prr(a, sep=' '): print(sep.join(map(str, a))) def dd(): return collections.defaultdict(int) n = ii() d = li() t = [] for i in range(1, n): a, b = min(d[i - 1], d[i]), max(d[i - 1], d[i]) t.append([a, b]) t.sort() for i in range(n - 1): for j in range(i + 1, n - 1): if t[i][0] < t[j][0] < t[i][1] < t[j][1]: exit(print('yes')) print('no')
Title: Dima and Continuous Line Time Limit: None seconds Memory Limit: None megabytes Problem Description: Dima and Seryozha live in an ordinary dormitory room for two. One day Dima had a date with his girl and he asked Seryozha to leave the room. As a compensation, Seryozha made Dima do his homework. The teacher gave Seryozha the coordinates of *n* distinct points on the abscissa axis and asked to consecutively connect them by semi-circus in a certain order: first connect the first point with the second one, then connect the second point with the third one, then the third one with the fourth one and so on to the *n*-th point. Two points with coordinates (*x*1,<=0) and (*x*2,<=0) should be connected by a semi-circle that passes above the abscissa axis with the diameter that coincides with the segment between points. Seryozha needs to find out if the line on the picture intersects itself. For clarifications, see the picture Seryozha showed to Dima (the left picture has self-intersections, the right picture doesn't have any). Seryozha is not a small boy, so the coordinates of the points can be rather large. Help Dima cope with the problem. Input Specification: The first line contains a single integer *n* (1<=≤<=*n*<=≤<=103). The second line contains *n* distinct integers *x*1,<=*x*2,<=...,<=*x**n* (<=-<=106<=≤<=*x**i*<=≤<=106) — the *i*-th point has coordinates (*x**i*,<=0). The points are not necessarily sorted by their *x* coordinate. Output Specification: In the single line print "yes" (without the quotes), if the line has self-intersections. Otherwise, print "no" (without the quotes). Demo Input: ['4\n0 10 5 15\n', '4\n0 15 5 10\n'] Demo Output: ['yes\n', 'no\n'] Note: The first test from the statement is on the picture to the left, the second test is on the picture to the right.
```python import sys import itertools import math import collections from collections import Counter ######################### # imgur.com/Pkt7iIf.png # ######################### def sieve(n): prime = [True for i in range(n + 1)] p = 2 while (p * p <= n): if (prime[p] == True): for i in range(p * 2, n + 1, p): prime[i] = False p += 1 prime[0] = prime[1] = False r = [p for p in range(n + 1) if prime[p]] return r def divs(n, start=1): r = [] for i in range(start, int(math.sqrt(n) + 1)): if (n % i == 0): if (n / i == i): r.append(i) else: r.extend([i, n // i]) return r def ceil(n, k): return n // k + (n % k != 0) def ii(): return int(input()) def mi(): return map(int, input().split()) def li(): return list(map(int, input().split())) def lcm(a, b): return abs(a * b) // math.gcd(a, b) def prr(a, sep=' '): print(sep.join(map(str, a))) def dd(): return collections.defaultdict(int) n = ii() d = li() t = [] for i in range(1, n): a, b = min(d[i - 1], d[i]), max(d[i - 1], d[i]) t.append([a, b]) t.sort() for i in range(n - 1): for j in range(i + 1, n - 1): if t[i][0] < t[j][0] < t[i][1] < t[j][1]: exit(print('yes')) print('no') ```
3
884
C
Bertown Subway
PROGRAMMING
1,500
[ "dfs and similar", "greedy", "math" ]
null
null
The construction of subway in Bertown is almost finished! The President of Berland will visit this city soon to look at the new subway himself. There are *n* stations in the subway. It was built according to the Bertown Transport Law: 1. For each station *i* there exists exactly one train that goes from this station. Its destination station is *p**i*, possibly *p**i*<==<=*i*; 1. For each station *i* there exists exactly one station *j* such that *p**j*<==<=*i*. The President will consider the convenience of subway after visiting it. The convenience is the number of ordered pairs (*x*,<=*y*) such that person can start at station *x* and, after taking some subway trains (possibly zero), arrive at station *y* (1<=≤<=*x*,<=*y*<=≤<=*n*). The mayor of Bertown thinks that if the subway is not convenient enough, then the President might consider installing a new mayor (and, of course, the current mayor doesn't want it to happen). Before President visits the city mayor has enough time to rebuild some paths of subway, thus changing the values of *p**i* for not more than two subway stations. Of course, breaking the Bertown Transport Law is really bad, so the subway must be built according to the Law even after changes. The mayor wants to do these changes in such a way that the convenience of the subway is maximized. Help him to calculate the maximum possible convenience he can get!
The first line contains one integer number *n* (1<=≤<=*n*<=≤<=100000) — the number of stations. The second line contains *n* integer numbers *p*1, *p*2, ..., *p**n* (1<=≤<=*p**i*<=≤<=*n*) — the current structure of the subway. All these numbers are distinct.
Print one number — the maximum possible value of convenience.
[ "3\n2 1 3\n", "5\n1 5 4 3 2\n" ]
[ "9\n", "17\n" ]
In the first example the mayor can change *p*<sub class="lower-index">2</sub> to 3 and *p*<sub class="lower-index">3</sub> to 1, so there will be 9 pairs: (1, 1), (1, 2), (1, 3), (2, 1), (2, 2), (2, 3), (3, 1), (3, 2), (3, 3). In the second example the mayor can change *p*<sub class="lower-index">2</sub> to 4 and *p*<sub class="lower-index">3</sub> to 5.
0
[ { "input": "3\n2 1 3", "output": "9" }, { "input": "5\n1 5 4 3 2", "output": "17" }, { "input": "1\n1", "output": "1" }, { "input": "2\n1 2", "output": "4" }, { "input": "2\n2 1", "output": "4" }, { "input": "100\n98 52 63 2 18 96 31 58 84 40 41 45 66 100 46 71 26 48 81 20 73 91 68 76 13 93 17 29 64 95 79 21 55 75 19 85 54 51 89 78 15 87 43 59 36 1 90 35 65 56 62 28 86 5 82 49 3 99 33 9 92 32 74 69 27 22 77 16 44 94 34 6 57 70 23 12 61 25 8 11 67 47 83 88 10 14 30 7 97 60 42 37 24 38 53 50 4 80 72 39", "output": "5416" }, { "input": "5\n1 4 2 3 5", "output": "17" }, { "input": "6\n5 3 6 1 4 2", "output": "36" }, { "input": "10\n5 1 6 2 8 3 4 10 9 7", "output": "82" }, { "input": "20\n1 6 15 9 18 17 7 8 3 19 2 13 11 12 14 4 5 20 16 10", "output": "326" }, { "input": "3\n1 2 3", "output": "5" } ]
1,509,224,897
2,147,483,647
Python 3
OK
TESTS
27
171
7,372,800
# http://codeforces.com/contest/884/problem/C # unsolved from functools import lru_cache n = int(input()) p = list(map(int, input().split())) l = [] score = 0 jeden = 0 dwa = 0 @lru_cache(maxsize=10000) def wzor(s): return s * s for i in range(n): if p[i] != 0: start = i end = p[i] lenght = 0 k = 0 if start + 1 != p[i]: while k - 1 != start: k = end end = p[end - 1] p[k - 1] = 0 lenght += 1 else: p[end - 1] = 0 lenght += 1 if lenght > jeden: l.append(dwa) dwa = jeden jeden = lenght elif lenght > dwa: l.append(dwa) dwa = lenght else: l.append(lenght) length = 0 l.append(jeden + dwa) for iteam in l: if iteam != 1 or iteam != 0 : score += wzor(iteam) elif iteam == 1: score += 1 print(int(score))
Title: Bertown Subway Time Limit: None seconds Memory Limit: None megabytes Problem Description: The construction of subway in Bertown is almost finished! The President of Berland will visit this city soon to look at the new subway himself. There are *n* stations in the subway. It was built according to the Bertown Transport Law: 1. For each station *i* there exists exactly one train that goes from this station. Its destination station is *p**i*, possibly *p**i*<==<=*i*; 1. For each station *i* there exists exactly one station *j* such that *p**j*<==<=*i*. The President will consider the convenience of subway after visiting it. The convenience is the number of ordered pairs (*x*,<=*y*) such that person can start at station *x* and, after taking some subway trains (possibly zero), arrive at station *y* (1<=≤<=*x*,<=*y*<=≤<=*n*). The mayor of Bertown thinks that if the subway is not convenient enough, then the President might consider installing a new mayor (and, of course, the current mayor doesn't want it to happen). Before President visits the city mayor has enough time to rebuild some paths of subway, thus changing the values of *p**i* for not more than two subway stations. Of course, breaking the Bertown Transport Law is really bad, so the subway must be built according to the Law even after changes. The mayor wants to do these changes in such a way that the convenience of the subway is maximized. Help him to calculate the maximum possible convenience he can get! Input Specification: The first line contains one integer number *n* (1<=≤<=*n*<=≤<=100000) — the number of stations. The second line contains *n* integer numbers *p*1, *p*2, ..., *p**n* (1<=≤<=*p**i*<=≤<=*n*) — the current structure of the subway. All these numbers are distinct. Output Specification: Print one number — the maximum possible value of convenience. Demo Input: ['3\n2 1 3\n', '5\n1 5 4 3 2\n'] Demo Output: ['9\n', '17\n'] Note: In the first example the mayor can change *p*<sub class="lower-index">2</sub> to 3 and *p*<sub class="lower-index">3</sub> to 1, so there will be 9 pairs: (1, 1), (1, 2), (1, 3), (2, 1), (2, 2), (2, 3), (3, 1), (3, 2), (3, 3). In the second example the mayor can change *p*<sub class="lower-index">2</sub> to 4 and *p*<sub class="lower-index">3</sub> to 5.
```python # http://codeforces.com/contest/884/problem/C # unsolved from functools import lru_cache n = int(input()) p = list(map(int, input().split())) l = [] score = 0 jeden = 0 dwa = 0 @lru_cache(maxsize=10000) def wzor(s): return s * s for i in range(n): if p[i] != 0: start = i end = p[i] lenght = 0 k = 0 if start + 1 != p[i]: while k - 1 != start: k = end end = p[end - 1] p[k - 1] = 0 lenght += 1 else: p[end - 1] = 0 lenght += 1 if lenght > jeden: l.append(dwa) dwa = jeden jeden = lenght elif lenght > dwa: l.append(dwa) dwa = lenght else: l.append(lenght) length = 0 l.append(jeden + dwa) for iteam in l: if iteam != 1 or iteam != 0 : score += wzor(iteam) elif iteam == 1: score += 1 print(int(score)) ```
3
2
B
The least round way
PROGRAMMING
2,000
[ "dp", "math" ]
B. The least round way
2
64
There is a square matrix *n*<=×<=*n*, consisting of non-negative integer numbers. You should find such a way on it that - starts in the upper left cell of the matrix; - each following cell is to the right or down from the current cell; - the way ends in the bottom right cell. Moreover, if we multiply together all the numbers along the way, the result should be the least "round". In other words, it should end in the least possible number of zeros.
The first line contains an integer number *n* (2<=≤<=*n*<=≤<=1000), *n* is the size of the matrix. Then follow *n* lines containing the matrix elements (non-negative integer numbers not exceeding 109).
In the first line print the least number of trailing zeros. In the second line print the correspondent way itself.
[ "3\n1 2 3\n4 5 6\n7 8 9\n" ]
[ "0\nDDRR\n" ]
none
0
[ { "input": "3\n1 2 3\n4 5 6\n7 8 9", "output": "0\nDDRR" }, { "input": "2\n7 6\n3 8", "output": "0\nDR" }, { "input": "3\n4 10 5\n10 9 4\n6 5 3", "output": "1\nDRRD" }, { "input": "4\n1 1 9 9\n3 4 7 3\n7 9 1 7\n1 7 1 5", "output": "0\nDDDRRR" }, { "input": "5\n8 3 2 1 4\n3 7 2 4 8\n9 2 8 9 10\n2 3 6 10 1\n8 2 2 8 4", "output": "0\nDDDDRRRR" }, { "input": "6\n5 5 4 10 5 5\n7 10 8 7 6 6\n7 1 7 9 7 8\n5 5 3 3 10 9\n5 8 10 6 3 8\n3 10 5 4 3 4", "output": "1\nDDRRDRDDRR" }, { "input": "7\n2 9 8 2 7 4 8\n9 5 4 4 8 5 3\n5 7 2 10 8 1 8\n2 7 10 7 5 7 7\n9 2 7 6 4 8 4\n7 2 4 7 4 1 8\n9 5 3 10 1 6 2", "output": "0\nRRDRRDRDDDDR" }, { "input": "8\n1 1 10 1 8 4 8 7\n9 3 3 2 2 6 2 4\n7 4 3 5 10 3 5 1\n8 4 4 10 4 5 9 4\n5 5 5 2 6 7 1 8\n4 10 1 3 2 4 8 3\n8 1 10 2 8 2 2 4\n2 10 6 8 10 2 8 4", "output": "0\nDRRRRRRRDDDDDD" }, { "input": "9\n8 3 3 3 10 3 10 5 6\n2 1 6 1 8 1 9 1 6\n6 1 5 4 2 2 10 4 9\n1 9 1 3 10 6 10 5 5\n1 10 5 4 7 2 5 9 10\n6 6 1 3 1 9 4 9 9\n5 3 7 6 4 6 2 10 2\n9 3 3 10 5 6 7 6 4\n4 9 6 7 4 3 7 6 5", "output": "1\nDDDDDRDDDRRRRRRR" }, { "input": "10\n10 8 6 5 9 8 2 5 3 2\n3 1 8 6 8 10 5 5 7 8\n5 9 7 7 4 9 7 2 5 2\n5 9 9 5 4 2 6 6 8 1\n10 6 9 9 10 5 6 3 5 9\n6 7 10 3 1 4 3 6 7 6\n10 10 4 7 4 4 8 6 7 4\n10 5 8 2 2 7 4 4 1 4\n8 4 6 10 10 6 1 3 3 1\n9 9 7 2 9 5 1 8 6 3", "output": "1\nDRDDDRRDDDRRDRDRRR" } ]
1,692,477,483
4,083
PyPy 3-64
WRONG_ANSWER
TESTS
2
46
0
def get_best_path(mat, coord, paths): if paths[coord] != 0: return paths[coord] r_zeros = -1 d_zeros = -1 if coord[1] < n-1: r_path = get_best_path(mat,(coord[0],coord[1]+1),paths) r_prod = mat[coord[0]][coord[1]] * r_path[0] if r_prod%10 != 0: i=0 else: i = 1 while r_prod%10**i == 0: i+=1 r_zeros = i if coord[0] < n-1: d_path = get_best_path(mat,(coord[0]+1,coord[1]),paths) d_prod = mat[coord[0]][coord[1]] * d_path[0] if d_prod%10 != 0: i=0 else: i = 1 while d_prod%10**i == 0: i+=1 d_zeros = i if d_zeros == -1: paths[coord] = (r_prod,'R'+r_path[1], r_zeros) elif r_zeros == -1: paths[coord] = (d_prod, 'D'+d_path[1], d_zeros) else: if d_zeros < r_zeros: paths[coord] = (d_prod, 'D'+d_path[1], d_zeros) else: paths[coord] = (r_prod,'R'+r_path[1], r_zeros) return paths[coord] n = int(input()) mat = [] for row in range(n): new = input().split() mat.append([int(i) for i in new]) paths = {(i,j):0 for i in range(n) for j in range(n)} paths[(n-1, n-1)] = (mat[n-1][n-1],'') b_p = get_best_path(mat,(0,0),paths) print(b_p[2]) print(b_p[1])
Title: The least round way Time Limit: 2 seconds Memory Limit: 64 megabytes Problem Description: There is a square matrix *n*<=×<=*n*, consisting of non-negative integer numbers. You should find such a way on it that - starts in the upper left cell of the matrix; - each following cell is to the right or down from the current cell; - the way ends in the bottom right cell. Moreover, if we multiply together all the numbers along the way, the result should be the least "round". In other words, it should end in the least possible number of zeros. Input Specification: The first line contains an integer number *n* (2<=≤<=*n*<=≤<=1000), *n* is the size of the matrix. Then follow *n* lines containing the matrix elements (non-negative integer numbers not exceeding 109). Output Specification: In the first line print the least number of trailing zeros. In the second line print the correspondent way itself. Demo Input: ['3\n1 2 3\n4 5 6\n7 8 9\n'] Demo Output: ['0\nDDRR\n'] Note: none
```python def get_best_path(mat, coord, paths): if paths[coord] != 0: return paths[coord] r_zeros = -1 d_zeros = -1 if coord[1] < n-1: r_path = get_best_path(mat,(coord[0],coord[1]+1),paths) r_prod = mat[coord[0]][coord[1]] * r_path[0] if r_prod%10 != 0: i=0 else: i = 1 while r_prod%10**i == 0: i+=1 r_zeros = i if coord[0] < n-1: d_path = get_best_path(mat,(coord[0]+1,coord[1]),paths) d_prod = mat[coord[0]][coord[1]] * d_path[0] if d_prod%10 != 0: i=0 else: i = 1 while d_prod%10**i == 0: i+=1 d_zeros = i if d_zeros == -1: paths[coord] = (r_prod,'R'+r_path[1], r_zeros) elif r_zeros == -1: paths[coord] = (d_prod, 'D'+d_path[1], d_zeros) else: if d_zeros < r_zeros: paths[coord] = (d_prod, 'D'+d_path[1], d_zeros) else: paths[coord] = (r_prod,'R'+r_path[1], r_zeros) return paths[coord] n = int(input()) mat = [] for row in range(n): new = input().split() mat.append([int(i) for i in new]) paths = {(i,j):0 for i in range(n) for j in range(n)} paths[(n-1, n-1)] = (mat[n-1][n-1],'') b_p = get_best_path(mat,(0,0),paths) print(b_p[2]) print(b_p[1]) ```
0