contestId int64 0 1.01k | index stringclasses 57
values | name stringlengths 2 58 | type stringclasses 2
values | rating int64 0 3.5k | tags listlengths 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 listlengths 0 7 | demo-output listlengths 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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
789 | A | Anastasia and pebbles | PROGRAMMING | 1,100 | [
"implementation",
"math"
] | null | null | Anastasia loves going for a walk in Central Uzhlyandian Park. But she became uninterested in simple walking, so she began to collect Uzhlyandian pebbles. At first, she decided to collect all the pebbles she could find in the park.
She has only two pockets. She can put at most *k* pebbles in each pocket at the same tim... | The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=105, 1<=≤<=*k*<=≤<=109) — the number of different pebble types and number of pebbles Anastasia can place in one pocket.
The second line contains *n* integers *w*1,<=*w*2,<=...,<=*w**n* (1<=≤<=*w**i*<=≤<=104) — number of pebbles of each type. | The only line of output contains one integer — the minimum number of days Anastasia needs to collect all the pebbles. | [
"3 2\n2 3 4\n",
"5 4\n3 1 8 9 7\n"
] | [
"3\n",
"5\n"
] | In the first sample case, Anastasia can collect all pebbles of the first type on the first day, of second type — on the second day, and of third type — on the third day.
Optimal sequence of actions in the second sample case:
- In the first day Anastasia collects 8 pebbles of the third type. - In the second day she... | 500 | [
{
"input": "3 2\n2 3 4",
"output": "3"
},
{
"input": "5 4\n3 1 8 9 7",
"output": "5"
},
{
"input": "1 22\n1",
"output": "1"
},
{
"input": "3 57\n78 165 54",
"output": "3"
},
{
"input": "5 72\n74 10 146 189 184",
"output": "6"
},
{
"input": "9 13\n132 8... | 1,491,466,003 | 2,147,483,647 | Python 3 | OK | TESTS | 31 | 170 | 12,902,400 | import math
types, capacity = map(int, input().split())
pebbles = list(
map(lambda x: math.ceil(x / capacity),
map(int, input().split()))
)
print(math.ceil(sum(pebbles)/2)) | Title: Anastasia and pebbles
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Anastasia loves going for a walk in Central Uzhlyandian Park. But she became uninterested in simple walking, so she began to collect Uzhlyandian pebbles. At first, she decided to collect all the pebbles she could ... | ```python
import math
types, capacity = map(int, input().split())
pebbles = list(
map(lambda x: math.ceil(x / capacity),
map(int, input().split()))
)
print(math.ceil(sum(pebbles)/2))
``` | 3 | |
699 | B | One Bomb | PROGRAMMING | 1,400 | [
"implementation"
] | null | null | You are given a description of a depot. It is a rectangular checkered field of *n*<=×<=*m* size. Each cell in a field can be empty (".") or it can be occupied by a wall ("*").
You have one bomb. If you lay the bomb at the cell (*x*,<=*y*), then after triggering it will wipe out all walls in the row *x* and all walls ... | The first line contains two positive integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=1000) — the number of rows and columns in the depot field.
The next *n* lines contain *m* symbols "." and "*" each — the description of the field. *j*-th symbol in *i*-th of them stands for cell (*i*,<=*j*). If the symbol is equal to ".", ... | If it is impossible to wipe out all walls by placing and triggering exactly one bomb, then print "NO" in the first line (without quotes).
Otherwise print "YES" (without quotes) in the first line and two integers in the second line — the coordinates of the cell at which the bomb should be laid. If there are multiple an... | [
"3 4\n.*..\n....\n.*..\n",
"3 3\n..*\n.*.\n*..\n",
"6 5\n..*..\n..*..\n*****\n..*..\n..*..\n..*..\n"
] | [
"YES\n1 2\n",
"NO\n",
"YES\n3 3\n"
] | none | 1,000 | [
{
"input": "3 4\n.*..\n....\n.*..",
"output": "YES\n1 2"
},
{
"input": "3 3\n..*\n.*.\n*..",
"output": "NO"
},
{
"input": "6 5\n..*..\n..*..\n*****\n..*..\n..*..\n..*..",
"output": "YES\n3 3"
},
{
"input": "1 10\n**********",
"output": "YES\n1 1"
},
{
"input": "10... | 1,468,939,387 | 5,887 | Python 3 | WRONG_ANSWER | PRETESTS | 2 | 46 | 0 | n, m = map(int, input().split())
a = []
for i in range(n):
a.append(list(input()))
b = [0] * n
c = [0] * m
cnt = 0
for i in range(n):
for j in range(m):
cur = int(a[i][j] == '*')
b[i] += cur
c[j] += cur
cnt += cur
x = y = None
for i in range(n):
for j in range(... | Title: One Bomb
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a description of a depot. It is a rectangular checkered field of *n*<=×<=*m* size. Each cell in a field can be empty (".") or it can be occupied by a wall ("*").
You have one bomb. If you lay the bomb at the ce... | ```python
n, m = map(int, input().split())
a = []
for i in range(n):
a.append(list(input()))
b = [0] * n
c = [0] * m
cnt = 0
for i in range(n):
for j in range(m):
cur = int(a[i][j] == '*')
b[i] += cur
c[j] += cur
cnt += cur
x = y = None
for i in range(n):
for j... | 0 | |
114 | A | Cifera | PROGRAMMING | 1,000 | [
"math"
] | null | null | When Petya went to school, he got interested in large numbers and what they were called in ancient times. For instance, he learned that the Russian word "tma" (which now means "too much to be counted") used to stand for a thousand and "tma tmyschaya" (which literally means "the tma of tmas") used to stand for a million... | The first input line contains integer number *k*, the second line contains integer number *l* (2<=≤<=*k*,<=*l*<=≤<=231<=-<=1). | You should print in the first line of the output "YES", if the number belongs to the set petriciumus cifera and otherwise print "NO". If the number belongs to the set, then print on the seconds line the only number — the importance of number *l*. | [
"5\n25\n",
"3\n8\n"
] | [
"YES\n1\n",
"NO\n"
] | none | 500 | [
{
"input": "5\n25",
"output": "YES\n1"
},
{
"input": "3\n8",
"output": "NO"
},
{
"input": "123\n123",
"output": "YES\n0"
},
{
"input": "99\n970300",
"output": "NO"
},
{
"input": "1000\n6666666",
"output": "NO"
},
{
"input": "59\n3571",
"output": "N... | 1,450,355,155 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 62 | 0 | K = int(input())
L = int(input())
importance = 0
while L > 1:
L = L//N
importance += 1
if L == 1:
print('YES')
print(importance-1)
else:
print('NO') | Title: Cifera
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
When Petya went to school, he got interested in large numbers and what they were called in ancient times. For instance, he learned that the Russian word "tma" (which now means "too much to be counted") used to stand for a thousa... | ```python
K = int(input())
L = int(input())
importance = 0
while L > 1:
L = L//N
importance += 1
if L == 1:
print('YES')
print(importance-1)
else:
print('NO')
``` | -1 | |
593 | B | Anton and Lines | PROGRAMMING | 1,600 | [
"geometry",
"sortings"
] | null | null | The teacher gave Anton a large geometry homework, but he didn't do it (as usual) as he participated in a regular round on Codeforces. In the task he was given a set of *n* lines defined by the equations *y*<==<=*k**i*·*x*<=+<=*b**i*. It was necessary to determine whether there is at least one point of intersection of t... | The first line of the input contains an integer *n* (2<=≤<=*n*<=≤<=100<=000) — the number of lines in the task given to Anton. The second line contains integers *x*1 and *x*2 (<=-<=1<=000<=000<=≤<=*x*1<=<<=*x*2<=≤<=1<=000<=000) defining the strip inside which you need to find a point of intersection of at least two ... | Print "Yes" (without quotes), if there is at least one intersection of two distinct lines, located strictly inside the strip. Otherwise print "No" (without quotes). | [
"4\n1 2\n1 2\n1 0\n0 1\n0 2\n",
"2\n1 3\n1 0\n-1 3\n",
"2\n1 3\n1 0\n0 2\n",
"2\n1 3\n1 0\n0 3\n"
] | [
"NO",
"YES",
"YES",
"NO"
] | In the first sample there are intersections located on the border of the strip, but there are no intersections located strictly inside it. | 1,000 | [
{
"input": "4\n1 2\n1 2\n1 0\n0 1\n0 2",
"output": "NO"
},
{
"input": "2\n1 3\n1 0\n-1 3",
"output": "YES"
},
{
"input": "2\n1 3\n1 0\n0 2",
"output": "YES"
},
{
"input": "2\n1 3\n1 0\n0 3",
"output": "NO"
},
{
"input": "2\n0 1\n-1000000 1000000\n1000000 -1000000"... | 1,446,657,502 | 2,002 | Python 3 | SKIPPED | PRETESTS | 16 | 592 | 14,336,000 | import sys
#sys.stdin = open("input.txt")
#sys.stdout = open("output.txt", "w")
n = int(input())
k = []
b = []
x1, x2 = (int(i) for i in input().split())
for i in range(n):
k1, b1 = (int(j) for j in input().split())
k.append(k1)
b.append(b1)
zn = [(k[i]*x1 + b[i], k[i]*x2 + b[i]) for i in range(n)]
#print(zn)
... | Title: Anton and Lines
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The teacher gave Anton a large geometry homework, but he didn't do it (as usual) as he participated in a regular round on Codeforces. In the task he was given a set of *n* lines defined by the equations *y*<==<=*k**i*·*... | ```python
import sys
#sys.stdin = open("input.txt")
#sys.stdout = open("output.txt", "w")
n = int(input())
k = []
b = []
x1, x2 = (int(i) for i in input().split())
for i in range(n):
k1, b1 = (int(j) for j in input().split())
k.append(k1)
b.append(b1)
zn = [(k[i]*x1 + b[i], k[i]*x2 + b[i]) for i in range(n)]
#... | -1 | |
967 | B | Watering System | PROGRAMMING | 1,000 | [
"math",
"sortings"
] | null | null | Arkady wants to water his only flower. Unfortunately, he has a very poor watering system that was designed for $n$ flowers and so it looks like a pipe with $n$ holes. Arkady can only use the water that flows from the first hole.
Arkady can block some of the holes, and then pour $A$ liters of water into the pipe. After... | The first line contains three integers $n$, $A$, $B$ ($1 \le n \le 100\,000$, $1 \le B \le A \le 10^4$) — the number of holes, the volume of water Arkady will pour into the system, and the volume he wants to get out of the first hole.
The second line contains $n$ integers $s_1, s_2, \ldots, s_n$ ($1 \le s_i \le 10^4$)... | Print a single integer — the number of holes Arkady should block. | [
"4 10 3\n2 2 2 2\n",
"4 80 20\n3 2 1 4\n",
"5 10 10\n1000 1 1 1 1\n"
] | [
"1\n",
"0\n",
"4\n"
] | In the first example Arkady should block at least one hole. After that, $\frac{10 \cdot 2}{6} \approx 3.333$ liters of water will flow out of the first hole, and that suits Arkady.
In the second example even without blocking any hole, $\frac{80 \cdot 3}{10} = 24$ liters will flow out of the first hole, that is not les... | 1,000 | [
{
"input": "4 10 3\n2 2 2 2",
"output": "1"
},
{
"input": "4 80 20\n3 2 1 4",
"output": "0"
},
{
"input": "5 10 10\n1000 1 1 1 1",
"output": "4"
},
{
"input": "10 300 100\n20 1 3 10 8 5 3 6 4 3",
"output": "1"
},
{
"input": "10 300 100\n20 25 68 40 60 37 44 85 23 ... | 1,529,042,344 | 2,147,483,647 | Python 3 | OK | TESTS | 26 | 187 | 6,348,800 | n,a,b=map(int,input().split())
z=list(map(int,input().split()))
first=z[0]
s=sum(z)
del(z[0])
z.sort()
i=n-2
while first*a/s<b:
s-=z[i]
i-=1
print(n-i-2)
| Title: Watering System
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Arkady wants to water his only flower. Unfortunately, he has a very poor watering system that was designed for $n$ flowers and so it looks like a pipe with $n$ holes. Arkady can only use the water that flows from the fi... | ```python
n,a,b=map(int,input().split())
z=list(map(int,input().split()))
first=z[0]
s=sum(z)
del(z[0])
z.sort()
i=n-2
while first*a/s<b:
s-=z[i]
i-=1
print(n-i-2)
``` | 3 | |
578 | B | "Or" Game | PROGRAMMING | 1,700 | [
"brute force",
"greedy"
] | null | null | You are given *n* numbers *a*1,<=*a*2,<=...,<=*a**n*. You can perform at most *k* operations. For each operation you can multiply one of the numbers by *x*. We want to make as large as possible, where denotes the bitwise OR.
Find the maximum possible value of after performing at most *k* operations optimally. | The first line contains three integers *n*, *k* and *x* (1<=≤<=*n*<=≤<=200<=000, 1<=≤<=*k*<=≤<=10, 2<=≤<=*x*<=≤<=8).
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=109). | Output the maximum value of a bitwise OR of sequence elements after performing operations. | [
"3 1 2\n1 1 1\n",
"4 2 3\n1 2 4 8\n"
] | [
"3\n",
"79\n"
] | For the first sample, any possible choice of doing one operation will result the same three numbers 1, 1, 2 so the result is <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/1ee73b671ed4bc53f2f96ed1a85fd98388e1712b.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
For the second sample... | 500 | [
{
"input": "3 1 2\n1 1 1",
"output": "3"
},
{
"input": "4 2 3\n1 2 4 8",
"output": "79"
},
{
"input": "2 1 2\n12 9",
"output": "30"
},
{
"input": "2 1 2\n12 7",
"output": "31"
},
{
"input": "3 1 3\n3 2 0",
"output": "11"
},
{
"input": "5 10 8\n10000000... | 1,642,089,440 | 2,147,483,647 | Python 3 | OK | TESTS | 32 | 451 | 16,486,400 | n,k,x=map(int,input().split())
*a,=map(int,input().split())
l=[0]*(n+1)
r=[0]*(n+1)
for i in range(0,n):
l[i+1]=l[i]|a[i]
r[n-i-1]=r[n-i]|a[n-i-1]
num=x**k
res=-1
for i in range(0,n):
res=max(l[i]|(a[i]*num)|r[i+1],res)
print(res)
| Title: "Or" Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given *n* numbers *a*1,<=*a*2,<=...,<=*a**n*. You can perform at most *k* operations. For each operation you can multiply one of the numbers by *x*. We want to make as large as possible, where denotes the bitwise OR... | ```python
n,k,x=map(int,input().split())
*a,=map(int,input().split())
l=[0]*(n+1)
r=[0]*(n+1)
for i in range(0,n):
l[i+1]=l[i]|a[i]
r[n-i-1]=r[n-i]|a[n-i-1]
num=x**k
res=-1
for i in range(0,n):
res=max(l[i]|(a[i]*num)|r[i+1],res)
print(res)
``` | 3 | |
251 | A | Points on Line | PROGRAMMING | 1,300 | [
"binary search",
"combinatorics",
"two pointers"
] | null | null | Little Petya likes points a lot. Recently his mom has presented him *n* points lying on the line *OX*. Now Petya is wondering in how many ways he can choose three distinct points so that the distance between the two farthest of them doesn't exceed *d*.
Note that the order of the points inside the group of three chosen... | The first line contains two integers: *n* and *d* (1<=≤<=*n*<=≤<=105; 1<=≤<=*d*<=≤<=109). The next line contains *n* integers *x*1,<=*x*2,<=...,<=*x**n*, their absolute value doesn't exceed 109 — the *x*-coordinates of the points that Petya has got.
It is guaranteed that the coordinates of the points in the input stri... | Print a single integer — the number of groups of three points, where the distance between two farthest points doesn't exceed *d*.
Please do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier. | [
"4 3\n1 2 3 4\n",
"4 2\n-3 -2 -1 0\n",
"5 19\n1 10 20 30 50\n"
] | [
"4\n",
"2\n",
"1\n"
] | In the first sample any group of three points meets our conditions.
In the seconds sample only 2 groups of three points meet our conditions: {-3, -2, -1} and {-2, -1, 0}.
In the third sample only one group does: {1, 10, 20}. | 500 | [
{
"input": "4 3\n1 2 3 4",
"output": "4"
},
{
"input": "4 2\n-3 -2 -1 0",
"output": "2"
},
{
"input": "5 19\n1 10 20 30 50",
"output": "1"
},
{
"input": "10 5\n31 36 43 47 48 50 56 69 71 86",
"output": "2"
},
{
"input": "10 50\n1 4 20 27 65 79 82 83 99 100",
"... | 1,570,209,524 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 6 | 186 | 0 | def cnk(n):
return 0 if 3 > n else n * (n - 1) * (n - 2) // 6
n, d = input().split()
n, d = int(n), float(d)
dots = list(map(int, input().split()))
l, r, res = 0, 0, 0
while l < n:
while r < n and dots[r] - dots[l] <= d:
r += 1
res += cnk(r - l)
if r == n:
break
... | Title: Points on Line
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Petya likes points a lot. Recently his mom has presented him *n* points lying on the line *OX*. Now Petya is wondering in how many ways he can choose three distinct points so that the distance between the two fart... | ```python
def cnk(n):
return 0 if 3 > n else n * (n - 1) * (n - 2) // 6
n, d = input().split()
n, d = int(n), float(d)
dots = list(map(int, input().split()))
l, r, res = 0, 0, 0
while l < n:
while r < n and dots[r] - dots[l] <= d:
r += 1
res += cnk(r - l)
if r == n:
br... | 0 | |
469 | A | I Wanna Be the Guy | PROGRAMMING | 800 | [
"greedy",
"implementation"
] | null | null | There is a game called "I Wanna Be the Guy", consisting of *n* levels. Little X and his friend Little Y are addicted to the game. Each of them wants to pass the whole game.
Little X can pass only *p* levels of the game. And Little Y can pass only *q* levels of the game. You are given the indices of levels Little X can... | The first line contains a single integer *n* (1<=≤<=<=*n*<=≤<=100).
The next line contains an integer *p* (0<=≤<=*p*<=≤<=*n*) at first, then follows *p* distinct integers *a*1,<=*a*2,<=...,<=*a**p* (1<=≤<=*a**i*<=≤<=*n*). These integers denote the indices of levels Little X can pass. The next line contains the levels... | If they can pass all the levels, print "I become the guy.". If it's impossible, print "Oh, my keyboard!" (without the quotes). | [
"4\n3 1 2 3\n2 2 4\n",
"4\n3 1 2 3\n2 2 3\n"
] | [
"I become the guy.\n",
"Oh, my keyboard!\n"
] | In the first sample, Little X can pass levels [1 2 3], and Little Y can pass level [2 4], so they can pass all the levels both.
In the second sample, no one can pass level 4. | 500 | [
{
"input": "4\n3 1 2 3\n2 2 4",
"output": "I become the guy."
},
{
"input": "4\n3 1 2 3\n2 2 3",
"output": "Oh, my keyboard!"
},
{
"input": "10\n5 8 6 1 5 4\n6 1 3 2 9 4 6",
"output": "Oh, my keyboard!"
},
{
"input": "10\n8 8 10 7 3 1 4 2 6\n8 9 5 10 3 7 2 4 8",
"output":... | 1,694,503,401 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 46 | 0 | n = int(input())
p_lst = input().split()[1:]
q_lst = input().split()[1:]
lst = p_lst + q_lst
word = "".join(lst)
if "1" in word and "2" in word and "3" in word and "4" in word:
print("I become the guy.")
else:
print("Oh, my keyboard!") | Title: I Wanna Be the Guy
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There is a game called "I Wanna Be the Guy", consisting of *n* levels. Little X and his friend Little Y are addicted to the game. Each of them wants to pass the whole game.
Little X can pass only *p* levels of the g... | ```python
n = int(input())
p_lst = input().split()[1:]
q_lst = input().split()[1:]
lst = p_lst + q_lst
word = "".join(lst)
if "1" in word and "2" in word and "3" in word and "4" in word:
print("I become the guy.")
else:
print("Oh, my keyboard!")
``` | 0 | |
608 | A | Saitama Destroys Hotel | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | null | null | Saitama accidentally destroyed a hotel again. To repay the hotel company, Genos has volunteered to operate an elevator in one of its other hotels. The elevator is special — it starts on the top floor, can only move down, and has infinite capacity. Floors are numbered from 0 to *s* and elevator initially starts on floor... | The first line of input contains two integers *n* and *s* (1<=≤<=*n*<=≤<=100, 1<=≤<=*s*<=≤<=1000) — the number of passengers and the number of the top floor respectively.
The next *n* lines each contain two space-separated integers *f**i* and *t**i* (1<=≤<=*f**i*<=≤<=*s*, 1<=≤<=*t**i*<=≤<=1000) — the floor and the tim... | Print a single integer — the minimum amount of time in seconds needed to bring all the passengers to floor 0. | [
"3 7\n2 1\n3 8\n5 2\n",
"5 10\n2 77\n3 33\n8 21\n9 12\n10 64\n"
] | [
"11\n",
"79\n"
] | In the first sample, it takes at least 11 seconds to bring all passengers to floor 0. Here is how this could be done:
1. Move to floor 5: takes 2 seconds.
2. Pick up passenger 3.
3. Move to floor 3: takes 2 seconds.
4. Wait for passenger 2 to arrive: takes 4 seconds.
5. Pick up passenger 2.
6. Go to floor 2: take... | 500 | [
{
"input": "3 7\n2 1\n3 8\n5 2",
"output": "11"
},
{
"input": "5 10\n2 77\n3 33\n8 21\n9 12\n10 64",
"output": "79"
},
{
"input": "1 1000\n1000 1000",
"output": "2000"
},
{
"input": "1 1\n1 1",
"output": "2"
},
{
"input": "1 1000\n1 1",
"output": "1000"
},
... | 1,450,889,097 | 597 | Python 3 | OK | TESTS | 39 | 62 | 0 | n,s=(map(int,input().split()))
curtime=0
a=[]
for _ in range(n):
a.append(tuple(map(int,input().split())))
a.sort()
a.reverse()
for i in a:
curtime+=max(s-i[0],i[1]-curtime)
s=i[0]
print(curtime+a[-1][0])
| Title: Saitama Destroys Hotel
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Saitama accidentally destroyed a hotel again. To repay the hotel company, Genos has volunteered to operate an elevator in one of its other hotels. The elevator is special — it starts on the top floor, can only mo... | ```python
n,s=(map(int,input().split()))
curtime=0
a=[]
for _ in range(n):
a.append(tuple(map(int,input().split())))
a.sort()
a.reverse()
for i in a:
curtime+=max(s-i[0],i[1]-curtime)
s=i[0]
print(curtime+a[-1][0])
``` | 3 | |
796 | A | Buying A House | PROGRAMMING | 800 | [
"brute force",
"implementation"
] | null | null | Zane the wizard had never loved anyone before, until he fell in love with a girl, whose name remains unknown to us.
The girl lives in house *m* of a village. There are *n* houses in that village, lining in a straight line from left to right: house 1, house 2, ..., house *n*. The village is also well-structured: house ... | The first line contains three integers *n*, *m*, and *k* (2<=≤<=*n*<=≤<=100, 1<=≤<=*m*<=≤<=*n*, 1<=≤<=*k*<=≤<=100) — the number of houses in the village, the house where the girl lives, and the amount of money Zane has (in dollars), respectively.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=... | Print one integer — the minimum distance, in meters, from the house where the girl Zane likes lives to the house Zane can buy. | [
"5 1 20\n0 27 32 21 19\n",
"7 3 50\n62 0 0 0 99 33 22\n",
"10 5 100\n1 0 1 0 0 0 0 0 1 1\n"
] | [
"40",
"30",
"20"
] | In the first sample, with *k* = 20 dollars, Zane can buy only house 5. The distance from house *m* = 1 to house 5 is 10 + 10 + 10 + 10 = 40 meters.
In the second sample, Zane can buy houses 6 and 7. It is better to buy house 6 than house 7, since house *m* = 3 and house 6 are only 30 meters away, while house *m* = 3 a... | 500 | [
{
"input": "5 1 20\n0 27 32 21 19",
"output": "40"
},
{
"input": "7 3 50\n62 0 0 0 99 33 22",
"output": "30"
},
{
"input": "10 5 100\n1 0 1 0 0 0 0 0 1 1",
"output": "20"
},
{
"input": "5 3 1\n1 1 0 0 1",
"output": "10"
},
{
"input": "5 5 5\n1 0 5 6 0",
"outpu... | 1,602,213,537 | 2,147,483,647 | Python 3 | OK | TESTS | 58 | 108 | 307,200 | n, zane, money = map(int, input().split())
houses = [int(x) for x in input().split()]
def findHouseToBuy(n, zane, money):
start = zane - 1
end = zane - 1
distance = 10
while start > 0 and end < n - 1:
start -= 1
end += 1
if houses[start] != 0 and houses[start] <= money or houses[end] != 0 and ... | Title: Buying A House
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Zane the wizard had never loved anyone before, until he fell in love with a girl, whose name remains unknown to us.
The girl lives in house *m* of a village. There are *n* houses in that village, lining in a straight li... | ```python
n, zane, money = map(int, input().split())
houses = [int(x) for x in input().split()]
def findHouseToBuy(n, zane, money):
start = zane - 1
end = zane - 1
distance = 10
while start > 0 and end < n - 1:
start -= 1
end += 1
if houses[start] != 0 and houses[start] <= money or houses[end]... | 3 | |
761 | A | Dasha and Stairs | PROGRAMMING | 1,000 | [
"brute force",
"constructive algorithms",
"implementation",
"math"
] | null | null | On her way to programming school tiger Dasha faced her first test — a huge staircase!
The steps were numbered from one to infinity. As we know, tigers are very fond of all striped things, it is possible that it has something to do with their color. So on some interval of her way she calculated two values — the number ... | In the only line you are given two integers *a*, *b* (0<=≤<=*a*,<=*b*<=≤<=100) — the number of even and odd steps, accordingly. | In the only line print "YES", if the interval of steps described above exists, and "NO" otherwise. | [
"2 3\n",
"3 1\n"
] | [
"YES\n",
"NO\n"
] | In the first example one of suitable intervals is from 1 to 5. The interval contains two even steps — 2 and 4, and three odd: 1, 3 and 5. | 500 | [
{
"input": "2 3",
"output": "YES"
},
{
"input": "3 1",
"output": "NO"
},
{
"input": "5 4",
"output": "YES"
},
{
"input": "9 9",
"output": "YES"
},
{
"input": "85 95",
"output": "NO"
},
{
"input": "0 1",
"output": "YES"
},
{
"input": "89 25"... | 1,485,930,852 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 15 | 4,608,000 | a = input("")
b = input("")
sum = int(a) + int (b)
even = odd = 0
for i in range(1,sum+1):
if i % 2 == 0:
even = even + 1
else:
odd = odd + 1
print (even)
print (odd)
if even == int(a) and odd == int(b):
print ('YES')
else:
print ('NO')
| Title: Dasha and Stairs
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
On her way to programming school tiger Dasha faced her first test — a huge staircase!
The steps were numbered from one to infinity. As we know, tigers are very fond of all striped things, it is possible that it has so... | ```python
a = input("")
b = input("")
sum = int(a) + int (b)
even = odd = 0
for i in range(1,sum+1):
if i % 2 == 0:
even = even + 1
else:
odd = odd + 1
print (even)
print (odd)
if even == int(a) and odd == int(b):
print ('YES')
else:
print ('NO')
``` | -1 | |
71 | A | Way Too Long Words | PROGRAMMING | 800 | [
"strings"
] | A. Way Too Long Words | 1 | 256 | Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome.
Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation.
This abbreviation is made lik... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=100). Each of the following *n* lines contains one word. All the words consist of lowercase Latin letters and possess the lengths of from 1 to 100 characters. | Print *n* lines. The *i*-th line should contain the result of replacing of the *i*-th word from the input data. | [
"4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis\n"
] | [
"word\nl10n\ni18n\np43s\n"
] | none | 500 | [
{
"input": "4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis",
"output": "word\nl10n\ni18n\np43s"
},
{
"input": "5\nabcdefgh\nabcdefghi\nabcdefghij\nabcdefghijk\nabcdefghijklm",
"output": "abcdefgh\nabcdefghi\nabcdefghij\na9k\na11m"
},
{
"input":... | 1,696,614,470 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 15 | 0 | n = int(input("Enter number of lines: "))
strList = []
while n > 0:
string = input("Enter a word: ")
length = len(string)
if length > 10:
abb = f"{string[0]}{length-2}{string[-1]}"
strList.append(abb)
else:
strList.append(string)
n -= 1
for i in strList:
p... | Title: Way Too Long Words
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome.
Let's consider a word too long, if its length is strictly more than 10 character... | ```python
n = int(input("Enter number of lines: "))
strList = []
while n > 0:
string = input("Enter a word: ")
length = len(string)
if length > 10:
abb = f"{string[0]}{length-2}{string[-1]}"
strList.append(abb)
else:
strList.append(string)
n -= 1
for i in strLi... | 0 |
931 | B | World Cup | PROGRAMMING | 1,200 | [
"constructive algorithms",
"implementation"
] | null | null | The last stage of Football World Cup is played using the play-off system.
There are *n* teams left in this stage, they are enumerated from 1 to *n*. Several rounds are held, in each round the remaining teams are sorted in the order of their ids, then the first in this order plays with the second, the third — with the ... | The only line contains three integers *n*, *a* and *b* (2<=≤<=*n*<=≤<=256, 1<=≤<=*a*,<=*b*<=≤<=*n*) — the total number of teams, and the ids of the teams that Arkady is interested in.
It is guaranteed that *n* is such that in each round an even number of team advance, and that *a* and *b* are not equal. | In the only line print "Final!" (without quotes), if teams *a* and *b* can meet in the Final.
Otherwise, print a single integer — the number of the round in which teams *a* and *b* can meet. The round are enumerated from 1. | [
"4 1 2\n",
"8 2 6\n",
"8 7 5\n"
] | [
"1\n",
"Final!\n",
"2\n"
] | In the first example teams 1 and 2 meet in the first round.
In the second example teams 2 and 6 can only meet in the third round, which is the Final, if they win all their opponents in earlier rounds.
In the third example the teams with ids 7 and 5 can meet in the second round, if they win their opponents in the firs... | 1,000 | [
{
"input": "4 1 2",
"output": "1"
},
{
"input": "8 2 6",
"output": "Final!"
},
{
"input": "8 7 5",
"output": "2"
},
{
"input": "128 30 98",
"output": "Final!"
},
{
"input": "256 128 256",
"output": "Final!"
},
{
"input": "256 2 127",
"output": "7"
... | 1,600,247,239 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 77 | 204,800 | import math
s = input().split()
n = int(s[0])
a = int(s[1])
b = int(s[2])
tmp = 0
n1 = 0
n2=n
while (n//2!=0):
if (abs(a - b)>= n//2):
tmp=n1
n=0
n//=2
n1+=1
print(math.log2(n)-tmp if tmp!=0 else "Final!")
| Title: World Cup
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The last stage of Football World Cup is played using the play-off system.
There are *n* teams left in this stage, they are enumerated from 1 to *n*. Several rounds are held, in each round the remaining teams are sorted in th... | ```python
import math
s = input().split()
n = int(s[0])
a = int(s[1])
b = int(s[2])
tmp = 0
n1 = 0
n2=n
while (n//2!=0):
if (abs(a - b)>= n//2):
tmp=n1
n=0
n//=2
n1+=1
print(math.log2(n)-tmp if tmp!=0 else "Final!")
``` | -1 | |
104 | A | Blackjack | PROGRAMMING | 800 | [
"implementation"
] | A. Blackjack | 2 | 256 | One rainy gloomy evening when all modules hid in the nearby cafes to drink hot energetic cocktails, the Hexadecimal virus decided to fly over the Mainframe to look for a Great Idea. And she has found one!
Why not make her own Codeforces, with blackjack and other really cool stuff? Many people will surely be willing to... | The only line contains *n* (1<=≤<=*n*<=≤<=25) — the required sum of points. | Print the numbers of ways to get the second card in the required way if the first card is the queen of spades. | [
"12\n",
"20\n",
"10\n"
] | [
"4",
"15",
"0"
] | In the first sample only four two's of different suits can earn the required sum of points.
In the second sample we can use all tens, jacks, queens and kings; overall it's 15 cards, as the queen of spades (as any other card) is only present once in the pack of cards and it's already in use.
In the third sample there ... | 500 | [
{
"input": "12",
"output": "4"
},
{
"input": "20",
"output": "15"
},
{
"input": "10",
"output": "0"
},
{
"input": "11",
"output": "4"
},
{
"input": "15",
"output": "4"
},
{
"input": "18",
"output": "4"
},
{
"input": "25",
"output": "0"
... | 1,631,542,523 | 2,147,483,647 | PyPy 3 | OK | TESTS | 25 | 216 | 20,172,800 | n=int(input())
n-=10
if n>11: print(0)
elif n==11: print(4)
elif n==10: print(15)
elif n<10 and n>=1: print(4)
elif n<=0: print(0) | Title: Blackjack
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
One rainy gloomy evening when all modules hid in the nearby cafes to drink hot energetic cocktails, the Hexadecimal virus decided to fly over the Mainframe to look for a Great Idea. And she has found one!
Why not make her own Co... | ```python
n=int(input())
n-=10
if n>11: print(0)
elif n==11: print(4)
elif n==10: print(15)
elif n<10 and n>=1: print(4)
elif n<=0: print(0)
``` | 3.908425 |
940 | B | Our Tanya is Crying Out Loud | PROGRAMMING | 1,400 | [
"dp",
"greedy"
] | null | null | Right now she actually isn't. But she will be, if you don't solve this problem.
You are given integers *n*, *k*, *A* and *B*. There is a number *x*, which is initially equal to *n*. You are allowed to perform two types of operations:
1. Subtract 1 from *x*. This operation costs you *A* coins. 1. Divide *x* by *k*.... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=2·109).
The second line contains a single integer *k* (1<=≤<=*k*<=≤<=2·109).
The third line contains a single integer *A* (1<=≤<=*A*<=≤<=2·109).
The fourth line contains a single integer *B* (1<=≤<=*B*<=≤<=2·109). | Output a single integer — the minimum amount of coins you have to pay to make *x* equal to 1. | [
"9\n2\n3\n1\n",
"5\n5\n2\n20\n",
"19\n3\n4\n2\n"
] | [
"6\n",
"8\n",
"12\n"
] | In the first testcase, the optimal strategy is as follows:
- Subtract 1 from *x* (9 → 8) paying 3 coins. - Divide *x* by 2 (8 → 4) paying 1 coin. - Divide *x* by 2 (4 → 2) paying 1 coin. - Divide *x* by 2 (2 → 1) paying 1 coin.
The total cost is 6 coins.
In the second test case the optimal strategy is to subtra... | 1,250 | [
{
"input": "9\n2\n3\n1",
"output": "6"
},
{
"input": "5\n5\n2\n20",
"output": "8"
},
{
"input": "19\n3\n4\n2",
"output": "12"
},
{
"input": "1845999546\n999435865\n1234234\n2323423",
"output": "1044857680578777"
},
{
"input": "1604353664\n1604353665\n9993432\n1",
... | 1,521,970,838 | 2,147,483,647 | Python 3 | OK | TESTS | 58 | 93 | 7,065,600 | n,k,a,b = int(input()),int(input()),int(input()),int(input())
if k==1: print(a*(n-1))
else:
ans = 0
while n>1:
if n%k==0:
nw = n//k
diff = n-nw
if a*diff<b:
ans += a*diff
else: ans += b
n = nw
else:
... | Title: Our Tanya is Crying Out Loud
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Right now she actually isn't. But she will be, if you don't solve this problem.
You are given integers *n*, *k*, *A* and *B*. There is a number *x*, which is initially equal to *n*. You are allowed to perf... | ```python
n,k,a,b = int(input()),int(input()),int(input()),int(input())
if k==1: print(a*(n-1))
else:
ans = 0
while n>1:
if n%k==0:
nw = n//k
diff = n-nw
if a*diff<b:
ans += a*diff
else: ans += b
n = nw
else:... | 3 | |
408 | A | Line to Cashier | PROGRAMMING | 900 | [
"implementation"
] | null | null | Little Vasya went to the supermarket to get some groceries. He walked about the supermarket for a long time and got a basket full of products. Now he needs to choose the cashier to pay for the products.
There are *n* cashiers at the exit from the supermarket. At the moment the queue for the *i*-th cashier already has ... | The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of cashes in the shop. The second line contains *n* space-separated integers: *k*1,<=*k*2,<=...,<=*k**n* (1<=≤<=*k**i*<=≤<=100), where *k**i* is the number of people in the queue to the *i*-th cashier.
The *i*-th of the next *n* lines contains *k**i*... | Print a single integer — the minimum number of seconds Vasya needs to get to the cashier. | [
"1\n1\n1\n",
"4\n1 4 3 2\n100\n1 2 2 3\n1 9 1\n7 8\n"
] | [
"20\n",
"100\n"
] | In the second test sample, if Vasya goes to the first queue, he gets to the cashier in 100·5 + 15 = 515 seconds. But if he chooses the second queue, he will need 1·5 + 2·5 + 2·5 + 3·5 + 4·15 = 100 seconds. He will need 1·5 + 9·5 + 1·5 + 3·15 = 100 seconds for the third one and 7·5 + 8·5 + 2·15 = 105 seconds for the fou... | 500 | [
{
"input": "1\n1\n1",
"output": "20"
},
{
"input": "4\n1 4 3 2\n100\n1 2 2 3\n1 9 1\n7 8",
"output": "100"
},
{
"input": "4\n5 4 5 5\n3 1 3 1 2\n3 1 1 3\n1 1 1 2 2\n2 2 1 1 3",
"output": "100"
},
{
"input": "5\n5 3 6 6 4\n7 5 3 3 9\n6 8 2\n1 10 8 5 9 2\n9 7 8 5 9 10\n9 8 3 3"... | 1,578,684,193 | 2,147,483,647 | Python 3 | OK | TESTS | 20 | 109 | 307,200 | n=int(input())
l=list(map(int,input().split()))
k=[15*l[x]+sum(list(map(int,input().split())))*5 for x in range(n)]
print(min(k)) | Title: Line to Cashier
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Vasya went to the supermarket to get some groceries. He walked about the supermarket for a long time and got a basket full of products. Now he needs to choose the cashier to pay for the products.
There are *n* c... | ```python
n=int(input())
l=list(map(int,input().split()))
k=[15*l[x]+sum(list(map(int,input().split())))*5 for x in range(n)]
print(min(k))
``` | 3 | |
268 | A | Games | PROGRAMMING | 800 | [
"brute force"
] | null | null | Manao works on a sports TV. He's spent much time watching the football games of some country. After a while he began to notice different patterns. For example, each team has two sets of uniforms: home uniform and guest uniform. When a team plays a game at home, the players put on the home uniform. When a team plays as ... | The first line contains an integer *n* (2<=≤<=*n*<=≤<=30). Each of the following *n* lines contains a pair of distinct space-separated integers *h**i*, *a**i* (1<=≤<=*h**i*,<=*a**i*<=≤<=100) — the colors of the *i*-th team's home and guest uniforms, respectively. | In a single line print the number of games where the host team is going to play in the guest uniform. | [
"3\n1 2\n2 4\n3 4\n",
"4\n100 42\n42 100\n5 42\n100 5\n",
"2\n1 2\n1 2\n"
] | [
"1\n",
"5\n",
"0\n"
] | In the first test case the championship consists of 6 games. The only game with the event in question is the game between teams 2 and 1 on the stadium of team 2.
In the second test sample the host team will have to wear guest uniform in the games between teams: 1 and 2, 2 and 1, 2 and 3, 3 and 4, 4 and 2 (the host tea... | 500 | [
{
"input": "3\n1 2\n2 4\n3 4",
"output": "1"
},
{
"input": "4\n100 42\n42 100\n5 42\n100 5",
"output": "5"
},
{
"input": "2\n1 2\n1 2",
"output": "0"
},
{
"input": "7\n4 7\n52 55\n16 4\n55 4\n20 99\n3 4\n7 52",
"output": "6"
},
{
"input": "10\n68 42\n1 35\n25 70\n... | 1,681,478,819 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 60 | 0 | n = int(input())
home = []
away = []
for i in range(n):
h,a = map(int,input().split())
home.append(h)
away.append(a)
c = 0
for i in range(n):
for j in range(n):
print(j)
if i!=j:
if home[i]==away[j]:
c+=1
print(c) | Title: Games
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Manao works on a sports TV. He's spent much time watching the football games of some country. After a while he began to notice different patterns. For example, each team has two sets of uniforms: home uniform and guest uniform. W... | ```python
n = int(input())
home = []
away = []
for i in range(n):
h,a = map(int,input().split())
home.append(h)
away.append(a)
c = 0
for i in range(n):
for j in range(n):
print(j)
if i!=j:
if home[i]==away[j]:
c+=1
print(c)
``` | 0 | |
613 | A | Peter and Snow Blower | PROGRAMMING | 1,900 | [
"binary search",
"geometry",
"ternary search"
] | null | null | Peter got a new snow blower as a New Year present. Of course, Peter decided to try it immediately. After reading the instructions he realized that it does not work like regular snow blowing machines. In order to make it work, you need to tie it to some point that it does not cover, and then switch it on. As a result it... | The first line of the input contains three integers — the number of vertices of the polygon *n* (), and coordinates of point *P*.
Each of the next *n* lines contains two integers — coordinates of the vertices of the polygon in the clockwise or counterclockwise order. It is guaranteed that no three consecutive vertices... | Print a single real value number — the area of the region that will be cleared. 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 ... | [
"3 0 0\n0 1\n-1 2\n1 2\n",
"4 1 -1\n0 0\n1 2\n2 0\n1 1\n"
] | [
"12.566370614359172464\n",
"21.991148575128551812\n"
] | In the first sample snow will be removed from that area: | 750 | [
{
"input": "3 0 0\n0 1\n-1 2\n1 2",
"output": "12.566370614359172464"
},
{
"input": "4 1 -1\n0 0\n1 2\n2 0\n1 1",
"output": "21.991148575128551812"
},
{
"input": "3 0 0\n-1 1\n0 3\n1 1",
"output": "25.132741228718344928"
},
{
"input": "3 -4 2\n-3 2\n5 -5\n5 3",
"output": ... | 1,579,368,045 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 92 | 307,200 | import math
PI = 3.141592653589793
r_max = 0
r_min = 2*(10**12)
def dot(v1, v2):
return v1[0]*v2[0] + v1[1]*v2[1]
def cross(v1, v2):
return v1[0]*v2[1] - v1[1]*v2[0]
def mag(x,y):
return math.sqrt(x**2 + y**2)
def main():
n, x0, y0 = map(int, input().split())
x, y = x0, y0
... | Title: Peter and Snow Blower
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Peter got a new snow blower as a New Year present. Of course, Peter decided to try it immediately. After reading the instructions he realized that it does not work like regular snow blowing machines. In order to m... | ```python
import math
PI = 3.141592653589793
r_max = 0
r_min = 2*(10**12)
def dot(v1, v2):
return v1[0]*v2[0] + v1[1]*v2[1]
def cross(v1, v2):
return v1[0]*v2[1] - v1[1]*v2[0]
def mag(x,y):
return math.sqrt(x**2 + y**2)
def main():
n, x0, y0 = map(int, input().split())
x, y =... | -1 | |
393 | A | Nineteen | PROGRAMMING | 0 | [] | null | null | Alice likes word "nineteen" very much. She has a string *s* and wants the string to contain as many such words as possible. For that reason she can rearrange the letters of the string.
For example, if she has string "xiineteenppnnnewtnee", she can get string "xnineteenppnineteenw", containing (the occurrences marked) ... | The first line contains a non-empty string *s*, consisting only of lowercase English letters. The length of string *s* doesn't exceed 100. | Print a single integer — the maximum number of "nineteen"s that she can get in her string. | [
"nniinneetteeeenn\n",
"nneteenabcnneteenabcnneteenabcnneteenabcnneteenabcii\n",
"nineteenineteen\n"
] | [
"2",
"2",
"2"
] | none | 500 | [
{
"input": "nniinneetteeeenn",
"output": "2"
},
{
"input": "nneteenabcnneteenabcnneteenabcnneteenabcnneteenabcii",
"output": "2"
},
{
"input": "nineteenineteen",
"output": "2"
},
{
"input": "nssemsnnsitjtihtthij",
"output": "0"
},
{
"input": "eehihnttehtherjsihihn... | 1,553,887,581 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 77 | 0 | a=input("string")
count=0
x=list()
for i in a:
x.append(i)
n=0
it=0
e=0
t=0
for i in x:
if i=='n':
n=n+1
if i=='i':
it=it+1
if i=='e':
e=e+1
if i=='t':
t=t+1
n=(n-1)//2
e=e//3
count=min(n,e,it,t)
print(count) | Title: Nineteen
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Alice likes word "nineteen" very much. She has a string *s* and wants the string to contain as many such words as possible. For that reason she can rearrange the letters of the string.
For example, if she has string "xiinetee... | ```python
a=input("string")
count=0
x=list()
for i in a:
x.append(i)
n=0
it=0
e=0
t=0
for i in x:
if i=='n':
n=n+1
if i=='i':
it=it+1
if i=='e':
e=e+1
if i=='t':
t=t+1
n=(n-1)//2
e=e//3
count=min(n,e,it,t)
print(count)
``` | 0 | |
894 | A | QAQ | PROGRAMMING | 800 | [
"brute force",
"dp"
] | null | null | "QAQ" is a word to denote an expression of crying. Imagine "Q" as eyes with tears and "A" as a mouth.
Now Diamond has given Bort a string consisting of only uppercase English letters of length *n*. There is a great number of "QAQ" in the string (Diamond is so cute!).
Bort wants to know how many subsequences "QAQ" are... | The only line contains a string of length *n* (1<=≤<=*n*<=≤<=100). It's guaranteed that the string only contains uppercase English letters. | Print a single integer — the number of subsequences "QAQ" in the string. | [
"QAQAQYSYIOIWIN\n",
"QAQQQZZYNOIWIN\n"
] | [
"4\n",
"3\n"
] | In the first example there are 4 subsequences "QAQ": "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN". | 500 | [
{
"input": "QAQAQYSYIOIWIN",
"output": "4"
},
{
"input": "QAQQQZZYNOIWIN",
"output": "3"
},
{
"input": "QA",
"output": "0"
},
{
"input": "IAQVAQZLQBQVQFTQQQADAQJA",
"output": "24"
},
{
"input": "QQAAQASGAYAAAAKAKAQIQEAQAIAAIAQQQQQ",
"output": "378"
},
{
... | 1,670,937,230 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 31 | 0 | a = input()
koef = 0
koil = 0
masQ = []
masA = []
a.split(sep=None, maxsplit=-1)
for i in range(len(a)):
if a[i] == 'Q':
masQ.append(koef)
koef += 1
if a[i] == 'A':
masA.append(koef)
koef += 1
for i in range(0, len(masQ) - 1):
for j in masA:
if j > masQ[i] and j < m... | Title: QAQ
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
"QAQ" is a word to denote an expression of crying. Imagine "Q" as eyes with tears and "A" as a mouth.
Now Diamond has given Bort a string consisting of only uppercase English letters of length *n*. There is a great number of "QAQ"... | ```python
a = input()
koef = 0
koil = 0
masQ = []
masA = []
a.split(sep=None, maxsplit=-1)
for i in range(len(a)):
if a[i] == 'Q':
masQ.append(koef)
koef += 1
if a[i] == 'A':
masA.append(koef)
koef += 1
for i in range(0, len(masQ) - 1):
for j in masA:
if j > masQ[i]... | 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 ... | 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",
"outpu... | 1,692,121,583 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 35 | 154 | 0 | a,b=map(int,input().split())
if a%2==0 or b%2==0:
res=(a*b)//2
else:
res=(a*b-1)//2
print(res) | 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 p... | ```python
a,b=map(int,input().split())
if a%2==0 or b%2==0:
res=(a*b)//2
else:
res=(a*b-1)//2
print(res)
``` | 3.9615 |
352 | B | Jeff and Periods | PROGRAMMING | 1,300 | [
"implementation",
"sortings"
] | null | null | One day Jeff got hold of an integer sequence *a*1, *a*2, ..., *a**n* of length *n*. The boy immediately decided to analyze the sequence. For that, he needs to find all values of *x*, for which these conditions hold:
- *x* occurs in sequence *a*. - Consider all positions of numbers *x* in the sequence *a* (such *i*, ... | The first line contains integer *n* (1<=≤<=*n*<=≤<=105). The next line contains integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=105). The numbers are separated by spaces. | In the first line print integer *t* — the number of valid *x*. On each of the next *t* lines print two integers *x* and *p**x*, where *x* is current suitable value, *p**x* is the common difference between numbers in the progression (if *x* occurs exactly once in the sequence, *p**x* must equal 0). Print the pairs in th... | [
"1\n2\n",
"8\n1 2 1 3 1 2 1 5\n"
] | [
"1\n2 0\n",
"4\n1 2\n2 4\n3 0\n5 0\n"
] | In the first test 2 occurs exactly once in the sequence, ergo *p*<sub class="lower-index">2</sub> = 0. | 1,000 | [
{
"input": "1\n2",
"output": "1\n2 0"
},
{
"input": "8\n1 2 1 3 1 2 1 5",
"output": "4\n1 2\n2 4\n3 0\n5 0"
},
{
"input": "3\n1 10 5",
"output": "3\n1 0\n5 0\n10 0"
},
{
"input": "4\n9 9 3 5",
"output": "3\n3 0\n5 0\n9 1"
},
{
"input": "6\n1 2 2 1 1 2",
"outpu... | 1,633,514,543 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 92 | 6,963,200 | n = int(input())
a_1 = input().split(' ')
a = []
d = dict()
px = []
for i in a_1:
a.append(int(i))
a.sort()
s_1 = set()
for i in a :
if i in s_1:
d[i]+=1
else:
s_1.add(i)
d[i]=1
s = list(s_1)
for i in s:
if d[i]>1 :
z = 2*i
px.append(z)
eli... | Title: Jeff and Periods
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day Jeff got hold of an integer sequence *a*1, *a*2, ..., *a**n* of length *n*. The boy immediately decided to analyze the sequence. For that, he needs to find all values of *x*, for which these conditions hold:
-... | ```python
n = int(input())
a_1 = input().split(' ')
a = []
d = dict()
px = []
for i in a_1:
a.append(int(i))
a.sort()
s_1 = set()
for i in a :
if i in s_1:
d[i]+=1
else:
s_1.add(i)
d[i]=1
s = list(s_1)
for i in s:
if d[i]>1 :
z = 2*i
px.append(z... | 0 | |
903 | A | Hungry Student Problem | PROGRAMMING | 900 | [
"greedy",
"implementation"
] | null | null | Ivan's classes at the university have just finished, and now he wants to go to the local CFK cafe and eat some fried chicken.
CFK sells chicken chunks in small and large portions. A small portion contains 3 chunks; a large one — 7 chunks. Ivan wants to eat exactly *x* chunks. Now he wonders whether he can buy exactly ... | The first line contains one integer *n* (1<=≤<=*n*<=≤<=100) — the number of testcases.
The *i*-th of the following *n* lines contains one integer *x**i* (1<=≤<=*x**i*<=≤<=100) — the number of chicken chunks Ivan wants to eat. | Print *n* lines, in *i*-th line output YES if Ivan can buy exactly *x**i* chunks. Otherwise, print NO. | [
"2\n6\n5\n"
] | [
"YES\nNO\n"
] | In the first example Ivan can buy two small portions.
In the second example Ivan cannot buy exactly 5 chunks, since one small portion is not enough, but two small portions or one large is too much. | 0 | [
{
"input": "2\n6\n5",
"output": "YES\nNO"
},
{
"input": "100\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n12\n13\n14\n15\n16\n17\n18\n19\n20\n21\n22\n23\n24\n25\n26\n27\n28\n29\n30\n31\n32\n33\n34\n35\n36\n37\n38\n39\n40\n41\n42\n43\n44\n45\n46\n47\n48\n49\n50\n51\n52\n53\n54\n55\n56\n57\n58\n59\n60\n61\n62\... | 1,606,760,705 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 93 | 0 | n = int(input())
for item in range(n):
a = int(input())
if (a >= 7 and (a % 7 == 0 or a % 7 == 3 or a % 7 == 6)) or (a >= 3 and (a % 3 == 0 or (a != 4 and a % 3 == 1))) or (a >=10 and (a % 10 == 0 or a % 10 == 3 or a % 10 == 6 or a % 10 == 9 or a % 10 == 7)):
print("YES")
else:
print(... | Title: Hungry Student Problem
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Ivan's classes at the university have just finished, and now he wants to go to the local CFK cafe and eat some fried chicken.
CFK sells chicken chunks in small and large portions. A small portion contains 3 chun... | ```python
n = int(input())
for item in range(n):
a = int(input())
if (a >= 7 and (a % 7 == 0 or a % 7 == 3 or a % 7 == 6)) or (a >= 3 and (a % 3 == 0 or (a != 4 and a % 3 == 1))) or (a >=10 and (a % 10 == 0 or a % 10 == 3 or a % 10 == 6 or a % 10 == 9 or a % 10 == 7)):
print("YES")
else:
... | 0 | |
61 | A | Ultra-Fast Mathematician | PROGRAMMING | 800 | [
"implementation"
] | A. Ultra-Fast Mathematician | 2 | 256 | Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 1018 numbers in a single second.
One day in 230 AD Shapur was trying to find out if any one can possibly do... | There are two lines in each input. Each of them contains a single number. It is guaranteed that the numbers are made from 0 and 1 only and that their length is same. The numbers may start with 0. The length of each number doesn't exceed 100. | Write one line — the corresponding answer. Do not omit the leading 0s. | [
"1010100\n0100101\n",
"000\n111\n",
"1110\n1010\n",
"01110\n01100\n"
] | [
"1110001\n",
"111\n",
"0100\n",
"00010\n"
] | none | 500 | [
{
"input": "1010100\n0100101",
"output": "1110001"
},
{
"input": "000\n111",
"output": "111"
},
{
"input": "1110\n1010",
"output": "0100"
},
{
"input": "01110\n01100",
"output": "00010"
},
{
"input": "011101\n000001",
"output": "011100"
},
{
"input": "... | 1,670,786,315 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 102 | 62 | 0 | import sys
#sys.stdin = open("input.txt", "r")
#sys.stdout = open("output.txt", "w")
def main():
m = sys.stdin.readline().rstrip()
n = sys.stdin.readline().rstrip()
answer = []
for i in range(len(m)):
if m[i] == n[i]:
answer.append(0)
else:
answ... | Title: Ultra-Fast Mathematician
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 10... | ```python
import sys
#sys.stdin = open("input.txt", "r")
#sys.stdout = open("output.txt", "w")
def main():
m = sys.stdin.readline().rstrip()
n = sys.stdin.readline().rstrip()
answer = []
for i in range(len(m)):
if m[i] == n[i]:
answer.append(0)
else:
... | 3.9845 |
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 in... | 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... | 1,551,329,883 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 93 | 0 | s = input()
t = input()
if s == t :
print(s)
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 gre... | ```python
s = input()
t = input()
if s == t :
print(s)
else :
print(1)
``` | -1 | |
835 | A | Key races | PROGRAMMING | 800 | [
"math"
] | null | null | Two boys decided to compete in text typing on the site "Key races". During the competition, they have to type a text consisting of *s* characters. The first participant types one character in *v*1 milliseconds and has ping *t*1 milliseconds. The second participant types one character in *v*2 milliseconds and has ping *... | The first line contains five integers *s*, *v*1, *v*2, *t*1, *t*2 (1<=≤<=*s*,<=*v*1,<=*v*2,<=*t*1,<=*t*2<=≤<=1000) — the number of characters in the text, the time of typing one character for the first participant, the time of typing one character for the the second participant, the ping of the first participant and th... | If the first participant wins, print "First". If the second participant wins, print "Second". In case of a draw print "Friendship". | [
"5 1 2 1 2\n",
"3 3 1 1 1\n",
"4 5 3 1 5\n"
] | [
"First\n",
"Second\n",
"Friendship\n"
] | In the first example, information on the success of the first participant comes in 7 milliseconds, of the second participant — in 14 milliseconds. So, the first wins.
In the second example, information on the success of the first participant comes in 11 milliseconds, of the second participant — in 5 milliseconds. So, ... | 500 | [
{
"input": "5 1 2 1 2",
"output": "First"
},
{
"input": "3 3 1 1 1",
"output": "Second"
},
{
"input": "4 5 3 1 5",
"output": "Friendship"
},
{
"input": "1000 1000 1000 1000 1000",
"output": "Friendship"
},
{
"input": "1 1 1 1 1",
"output": "Friendship"
},
... | 1,676,023,910 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 32 | 77 | 0 | s, v1, v2, k1, k2=map(int, input().split())
first=(s*v1)+(k1*2)
second=(s*v2)+(k2*2)
if first==second:
print('Friendship')
else:
if first>second:
print('Second')
else:
print('First') | Title: Key races
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Two boys decided to compete in text typing on the site "Key races". During the competition, they have to type a text consisting of *s* characters. The first participant types one character in *v*1 milliseconds and has ping *t... | ```python
s, v1, v2, k1, k2=map(int, input().split())
first=(s*v1)+(k1*2)
second=(s*v2)+(k2*2)
if first==second:
print('Friendship')
else:
if first>second:
print('Second')
else:
print('First')
``` | 3 | |
13 | A | Numbers | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | A. Numbers | 1 | 64 | Little Petya likes numbers a lot. He found that number 123 in base 16 consists of two digits: the first is 7 and the second is 11. So the sum of digits of 123 in base 16 is equal to 18.
Now he wonders what is an average value of sum of digits of the number *A* written in all bases from 2 to *A*<=-<=1.
Note that all c... | Input contains one integer number *A* (3<=≤<=*A*<=≤<=1000). | Output should contain required average value in format «X/Y», where X is the numerator and Y is the denominator. | [
"5\n",
"3\n"
] | [
"7/3\n",
"2/1\n"
] | In the first sample number 5 written in all bases from 2 to 4 looks so: 101, 12, 11. Sums of digits are 2, 3 and 2, respectively. | 0 | [
{
"input": "5",
"output": "7/3"
},
{
"input": "3",
"output": "2/1"
},
{
"input": "1000",
"output": "90132/499"
},
{
"input": "927",
"output": "155449/925"
},
{
"input": "260",
"output": "6265/129"
},
{
"input": "131",
"output": "3370/129"
},
{
... | 1,669,855,349 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 92 | 0 | A = int(input())
total = 0
for b in range(2,A):
digits = []
a = A
while a:
digits.append(int(a % b))
a //= b
total += sum(digits)
print(f'{total}/{A-2}') | Title: Numbers
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
Little Petya likes numbers a lot. He found that number 123 in base 16 consists of two digits: the first is 7 and the second is 11. So the sum of digits of 123 in base 16 is equal to 18.
Now he wonders what is an average value of su... | ```python
A = int(input())
total = 0
for b in range(2,A):
digits = []
a = A
while a:
digits.append(int(a % b))
a //= b
total += sum(digits)
print(f'{total}/{A-2}')
``` | 0 |
58 | A | Chat room | PROGRAMMING | 1,000 | [
"greedy",
"strings"
] | A. Chat room | 1 | 256 | Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, ... | The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters. | If Vasya managed to say hello, print "YES", otherwise print "NO". | [
"ahhellllloou\n",
"hlelo\n"
] | [
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "ahhellllloou",
"output": "YES"
},
{
"input": "hlelo",
"output": "NO"
},
{
"input": "helhcludoo",
"output": "YES"
},
{
"input": "hehwelloho",
"output": "YES"
},
{
"input": "pnnepelqomhhheollvlo",
"output": "YES"
},
{
"input": "tymbzjyqhymeda... | 1,691,044,884 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 40 | 62 | 0 | str=input()
h=False
e=False
l1=False
l2=False
o=False
for i in range(len(str)):
if str[i]=='h' :
h=True
elif str[i]=='e' and h==True:
e=True
elif str[i]=='l' and e==True and l1!=True:
l1=True
elif str[i]=='l' and l1==True:
l2=True
elif str[i]=='o' and l... | Title: Chat room
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letter... | ```python
str=input()
h=False
e=False
l1=False
l2=False
o=False
for i in range(len(str)):
if str[i]=='h' :
h=True
elif str[i]=='e' and h==True:
e=True
elif str[i]=='l' and e==True and l1!=True:
l1=True
elif str[i]=='l' and l1==True:
l2=True
elif str[i]=... | 3.969 |
894 | A | QAQ | PROGRAMMING | 800 | [
"brute force",
"dp"
] | null | null | "QAQ" is a word to denote an expression of crying. Imagine "Q" as eyes with tears and "A" as a mouth.
Now Diamond has given Bort a string consisting of only uppercase English letters of length *n*. There is a great number of "QAQ" in the string (Diamond is so cute!).
Bort wants to know how many subsequences "QAQ" are... | The only line contains a string of length *n* (1<=≤<=*n*<=≤<=100). It's guaranteed that the string only contains uppercase English letters. | Print a single integer — the number of subsequences "QAQ" in the string. | [
"QAQAQYSYIOIWIN\n",
"QAQQQZZYNOIWIN\n"
] | [
"4\n",
"3\n"
] | In the first example there are 4 subsequences "QAQ": "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN". | 500 | [
{
"input": "QAQAQYSYIOIWIN",
"output": "4"
},
{
"input": "QAQQQZZYNOIWIN",
"output": "3"
},
{
"input": "QA",
"output": "0"
},
{
"input": "IAQVAQZLQBQVQFTQQQADAQJA",
"output": "24"
},
{
"input": "QQAAQASGAYAAAAKAKAQIQEAQAIAAIAQQQQQ",
"output": "378"
},
{
... | 1,610,710,320 | 2,147,483,647 | PyPy 3 | OK | TESTS | 43 | 108 | 0 | # -*- coding: utf-8 -*-
"""
Created on Fri Jan 15 14:27:01 2021
@author: Олег
"""
s = input()
ql = 0
c = 0
qr = s.count('Q')
for i in range(len(s)):
if s[i] == 'Q':
ql += 1
qr -= 1
elif s[i] == 'A':
c += ql * qr
print(c)
| Title: QAQ
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
"QAQ" is a word to denote an expression of crying. Imagine "Q" as eyes with tears and "A" as a mouth.
Now Diamond has given Bort a string consisting of only uppercase English letters of length *n*. There is a great number of "QAQ"... | ```python
# -*- coding: utf-8 -*-
"""
Created on Fri Jan 15 14:27:01 2021
@author: Олег
"""
s = input()
ql = 0
c = 0
qr = s.count('Q')
for i in range(len(s)):
if s[i] == 'Q':
ql += 1
qr -= 1
elif s[i] == 'A':
c += ql * qr
print(c)
``` | 3 | |
995 | C | Leaving the Bar | PROGRAMMING | 2,300 | [
"brute force",
"data structures",
"geometry",
"greedy",
"math",
"sortings"
] | null | null | For a vector $\vec{v} = (x, y)$, define $|v| = \sqrt{x^2 + y^2}$.
Allen had a bit too much to drink at the bar, which is at the origin. There are $n$ vectors $\vec{v_1}, \vec{v_2}, \cdots, \vec{v_n}$. Allen will make $n$ moves. As Allen's sense of direction is impaired, during the $i$-th move he will either move in th... | The first line contains a single integer $n$ ($1 \le n \le 10^5$) — the number of moves.
Each of the following lines contains two space-separated integers $x_i$ and $y_i$, meaning that $\vec{v_i} = (x_i, y_i)$. We have that $|v_i| \le 10^6$ for all $i$. | Output a single line containing $n$ integers $c_1, c_2, \cdots, c_n$, each of which is either $1$ or $-1$. Your solution is correct if the value of $p = \sum_{i = 1}^n c_i \vec{v_i}$, satisfies $|p| \le 1.5 \cdot 10^6$.
It can be shown that a solution always exists under the given constraints. | [
"3\n999999 0\n0 999999\n999999 0\n",
"1\n-824590 246031\n",
"8\n-67761 603277\n640586 -396671\n46147 -122580\n569609 -2112\n400 914208\n131792 309779\n-850150 -486293\n5272 721899\n"
] | [
"1 1 -1 \n",
"1 \n",
"1 1 1 1 1 1 1 -1 \n"
] | none | 1,500 | [
{
"input": "3\n999999 0\n0 999999\n999999 0",
"output": "1 1 -1 "
},
{
"input": "1\n-824590 246031",
"output": "1 "
},
{
"input": "8\n-67761 603277\n640586 -396671\n46147 -122580\n569609 -2112\n400 914208\n131792 309779\n-850150 -486293\n5272 721899",
"output": "1 1 1 1 1 1 1 -1 "
... | 1,529,864,045 | 5,945 | Python 3 | WRONG_ANSWER | PRETESTS | 6 | 217 | 3,788,800 | n = int(input())
res = []
for _ in range(n):
a, b = [int(x) for x in input().split()]
res.append((a, b))
res = sorted(enumerate(res), key=lambda x: x[1][0] ** 2 + x[1][1] ** 2, reverse=True)
def norm(x):
return x[0] ** 2 + x[1] ** 2
def add(x, y):
return (x[0] + y[0], x[1] + y[1])
def ... | Title: Leaving the Bar
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
For a vector $\vec{v} = (x, y)$, define $|v| = \sqrt{x^2 + y^2}$.
Allen had a bit too much to drink at the bar, which is at the origin. There are $n$ vectors $\vec{v_1}, \vec{v_2}, \cdots, \vec{v_n}$. Allen will make $... | ```python
n = int(input())
res = []
for _ in range(n):
a, b = [int(x) for x in input().split()]
res.append((a, b))
res = sorted(enumerate(res), key=lambda x: x[1][0] ** 2 + x[1][1] ** 2, reverse=True)
def norm(x):
return x[0] ** 2 + x[1] ** 2
def add(x, y):
return (x[0] + y[0], x[1] + y... | 0 | |
189 | A | Cut Ribbon | PROGRAMMING | 1,300 | [
"brute force",
"dp"
] | null | null | Polycarpus has a ribbon, its length is *n*. He wants to cut the ribbon in a way that fulfils the following two conditions:
- After the cutting each ribbon piece should have length *a*, *b* or *c*. - After the cutting the number of ribbon pieces should be maximum.
Help Polycarpus and find the number of ribbon piece... | The first line contains four space-separated integers *n*, *a*, *b* and *c* (1<=≤<=*n*,<=*a*,<=*b*,<=*c*<=≤<=4000) — the length of the original ribbon and the acceptable lengths of the ribbon pieces after the cutting, correspondingly. The numbers *a*, *b* and *c* can coincide. | Print a single number — the maximum possible number of ribbon pieces. It is guaranteed that at least one correct ribbon cutting exists. | [
"5 5 3 2\n",
"7 5 5 2\n"
] | [
"2\n",
"2\n"
] | In the first example Polycarpus can cut the ribbon in such way: the first piece has length 2, the second piece has length 3.
In the second example Polycarpus can cut the ribbon in such way: the first piece has length 5, the second piece has length 2. | 500 | [
{
"input": "5 5 3 2",
"output": "2"
},
{
"input": "7 5 5 2",
"output": "2"
},
{
"input": "4 4 4 4",
"output": "1"
},
{
"input": "1 1 1 1",
"output": "1"
},
{
"input": "4000 1 2 3",
"output": "4000"
},
{
"input": "4000 3 4 5",
"output": "1333"
},
... | 1,677,250,065 | 2,147,483,647 | Python 3 | OK | TESTS | 58 | 62 | 0 |
n, a, b, c = map(int, input().split())
dp = [0] + [-1e9]*5000
for i in range(1, n + 1):
dp[i] = max(dp[i - a], dp[i - b], dp[i - c]) + 1
print(dp[n]) | Title: Cut Ribbon
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarpus has a ribbon, its length is *n*. He wants to cut the ribbon in a way that fulfils the following two conditions:
- After the cutting each ribbon piece should have length *a*, *b* or *c*. - After the cutting the... | ```python
n, a, b, c = map(int, input().split())
dp = [0] + [-1e9]*5000
for i in range(1, n + 1):
dp[i] = max(dp[i - a], dp[i - b], dp[i - c]) + 1
print(dp[n])
``` | 3 | |
567 | C | Geometric Progression | PROGRAMMING | 1,700 | [
"binary search",
"data structures",
"dp"
] | null | null | Polycarp loves geometric progressions very much. Since he was only three years old, he loves only the progressions of length three. He also has a favorite integer *k* and a sequence *a*, consisting of *n* integers.
He wants to know how many subsequences of length three can be selected from *a*, so that they form a geo... | The first line of the input contains two integers, *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=2·105), showing how many numbers Polycarp's sequence has and his favorite number.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (<=-<=109<=≤<=*a**i*<=≤<=109) — elements of the sequence. | Output a single number — the number of ways to choose a subsequence of length three, such that it forms a geometric progression with a common ratio *k*. | [
"5 2\n1 1 2 2 4\n",
"3 1\n1 1 1\n",
"10 3\n1 2 6 2 3 6 9 18 3 9\n"
] | [
"4",
"1",
"6"
] | In the first sample test the answer is four, as any of the two 1s can be chosen as the first element, the second element can be any of the 2s, and the third element of the subsequence must be equal to 4. | 1,500 | [
{
"input": "5 2\n1 1 2 2 4",
"output": "4"
},
{
"input": "3 1\n1 1 1",
"output": "1"
},
{
"input": "10 3\n1 2 6 2 3 6 9 18 3 9",
"output": "6"
},
{
"input": "20 2\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20",
"output": "5"
},
{
"input": "5 3\n5 15 15 15 45... | 1,630,874,014 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 60 | 311 | 45,875,200 | from collections import Counter
n, k=[int(v) for v in input().split()]
w=[int(v) for v in input().split()]
d=Counter(w)
a, b, c={}, {}, {}
res=0
if k!=1:
for j in w:
if j in a:
a[j]+=1
else:
a[j]=1
if j%k==0 and j//k in a:
if j in b:
... | Title: Geometric Progression
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp loves geometric progressions very much. Since he was only three years old, he loves only the progressions of length three. He also has a favorite integer *k* and a sequence *a*, consisting of *n* integers... | ```python
from collections import Counter
n, k=[int(v) for v in input().split()]
w=[int(v) for v in input().split()]
d=Counter(w)
a, b, c={}, {}, {}
res=0
if k!=1:
for j in w:
if j in a:
a[j]+=1
else:
a[j]=1
if j%k==0 and j//k in a:
if j in b:... | 0 | |
670 | D1 | Magic Powder - 1 | PROGRAMMING | 1,400 | [
"binary search",
"brute force",
"implementation"
] | null | null | This problem is given in two versions that differ only by constraints. If you can solve this problem in large constraints, then you can just write a single solution to the both versions. If you find the problem too difficult in large constraints, you can write solution to the simplified version only.
Waking up in the ... | The first line of the input contains two positive integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=1000) — the number of ingredients and the number of grams of the magic powder.
The second line contains the sequence *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=1000), where the *i*-th number is equal to the number of grams of... | Print the maximum number of cookies, which Apollinaria will be able to bake using the ingredients that she has and the magic powder. | [
"3 1\n2 1 4\n11 3 16\n",
"4 3\n4 3 5 6\n11 12 14 20\n"
] | [
"4\n",
"3\n"
] | In the first sample it is profitably for Apollinaria to make the existing 1 gram of her magic powder to ingredient with the index 2, then Apollinaria will be able to bake 4 cookies.
In the second sample Apollinaria should turn 1 gram of magic powder to ingredient with the index 1 and 1 gram of magic powder to ingredie... | 1,000 | [
{
"input": "3 1\n2 1 4\n11 3 16",
"output": "4"
},
{
"input": "4 3\n4 3 5 6\n11 12 14 20",
"output": "3"
},
{
"input": "10 926\n5 6 8 1 2 5 1 8 4 4\n351 739 998 725 953 970 906 691 707 1000",
"output": "137"
},
{
"input": "20 925\n7 3 1 2 1 3 1 3 1 2 3 1 5 8 1 3 7 3 4 2\n837 ... | 1,618,686,270 | 2,147,483,647 | Python 3 | OK | TESTS | 119 | 77 | 0 | class Solution:
def getList(self):
return list(map(int,input().split()))
def solve(self):
n,k = input().split()
n = int(n)
k = int(k)
a = self.getList()
b = self.getList()
c = [b[i]//a[i] for i in range(n)]
total = min(c)
left = ... | Title: Magic Powder - 1
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
This problem is given in two versions that differ only by constraints. If you can solve this problem in large constraints, then you can just write a single solution to the both versions. If you find the problem too dif... | ```python
class Solution:
def getList(self):
return list(map(int,input().split()))
def solve(self):
n,k = input().split()
n = int(n)
k = int(k)
a = self.getList()
b = self.getList()
c = [b[i]//a[i] for i in range(n)]
total = min(c)
... | 3 | |
776 | A | A Serial Killer | PROGRAMMING | 900 | [
"brute force",
"implementation",
"strings"
] | null | null | Our beloved detective, Sherlock is currently trying to catch a serial killer who kills a person each day. Using his powers of deduction, he came to know that the killer has a strategy for selecting his next victim.
The killer starts with two potential victims on his first day, selects one of these two, kills selected ... | First line of input contains two names (length of each of them doesn't exceed 10), the two initials potential victims. Next line contains integer *n* (1<=≤<=*n*<=≤<=1000), the number of days.
Next *n* lines contains two names (length of each of them doesn't exceed 10), first being the person murdered on this day and t... | Output *n*<=+<=1 lines, the *i*-th line should contain the two persons from which the killer selects for the *i*-th murder. The (*n*<=+<=1)-th line should contain the two persons from which the next victim is selected. In each line, the two names can be printed in any order. | [
"ross rachel\n4\nross joey\nrachel phoebe\nphoebe monica\nmonica chandler\n",
"icm codeforces\n1\ncodeforces technex\n"
] | [
"ross rachel\njoey rachel\njoey phoebe\njoey monica\njoey chandler\n",
"icm codeforces\nicm technex\n"
] | In first example, the killer starts with ross and rachel.
- After day 1, ross is killed and joey appears. - After day 2, rachel is killed and phoebe appears. - After day 3, phoebe is killed and monica appears. - After day 4, monica is killed and chandler appears. | 500 | [
{
"input": "ross rachel\n4\nross joey\nrachel phoebe\nphoebe monica\nmonica chandler",
"output": "ross rachel\njoey rachel\njoey phoebe\njoey monica\njoey chandler"
},
{
"input": "icm codeforces\n1\ncodeforces technex",
"output": "icm codeforces\nicm technex"
},
{
"input": "a b\n3\na c\n... | 1,518,390,597 | 2,147,483,647 | Python 3 | OK | TESTS | 57 | 77 | 5,632,000 | # -*- coding: utf-8 -*-
"""
Created on Sun Feb 11 17:42:31 2018
@author: arjun
"""
f1,f2 = list(map(str,input().split()))
print(f1,f2)
n = int(input())
for _ in range(n):
dead,replace = list(map(str,input().split()))
if(dead==f1):
f1 = replace
else:
f2 = replace
print(f... | Title: A Serial Killer
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Our beloved detective, Sherlock is currently trying to catch a serial killer who kills a person each day. Using his powers of deduction, he came to know that the killer has a strategy for selecting his next victim.
The... | ```python
# -*- coding: utf-8 -*-
"""
Created on Sun Feb 11 17:42:31 2018
@author: arjun
"""
f1,f2 = list(map(str,input().split()))
print(f1,f2)
n = int(input())
for _ in range(n):
dead,replace = list(map(str,input().split()))
if(dead==f1):
f1 = replace
else:
f2 = replace
... | 3 | |
892 | A | Greed | PROGRAMMING | 900 | [
"greedy",
"implementation"
] | null | null | Jafar has *n* cans of cola. Each can is described by two integers: remaining volume of cola *a**i* and can's capacity *b**i* (*a**i* <=≤<= *b**i*).
Jafar has decided to pour all remaining cola into just 2 cans, determine if he can do this or not! | The first line of the input contains one integer *n* (2<=≤<=*n*<=≤<=100<=000) — number of cola cans.
The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=109) — volume of remaining cola in cans.
The third line contains *n* space-separated integers that *b*1,<=*b*2,<=...,<... | Print "YES" (without quotes) if it is possible to pour all remaining cola in 2 cans. Otherwise print "NO" (without quotes).
You can print each letter in any case (upper or lower). | [
"2\n3 5\n3 6\n",
"3\n6 8 9\n6 10 12\n",
"5\n0 0 5 0 0\n1 1 8 10 5\n",
"4\n4 1 0 3\n5 2 2 3\n"
] | [
"YES\n",
"NO\n",
"YES\n",
"YES\n"
] | In the first sample, there are already 2 cans, so the answer is "YES". | 500 | [
{
"input": "2\n3 5\n3 6",
"output": "YES"
},
{
"input": "3\n6 8 9\n6 10 12",
"output": "NO"
},
{
"input": "5\n0 0 5 0 0\n1 1 8 10 5",
"output": "YES"
},
{
"input": "4\n4 1 0 3\n5 2 2 3",
"output": "YES"
},
{
"input": "10\n9 10 24 11 1 7 8 3 28 14\n86 20 34 11 22 9... | 1,583,427,790 | 2,147,483,647 | PyPy 3 | OK | TESTS | 39 | 342 | 13,209,600 | n= int(input())
can = list(map(int, input().split()))
capacity = list(map(int, input().split()))
vol= sum(can)
capacity.sort(reverse=True)
max_capacity = int(capacity[0]) + int(capacity[1])
if vol<=max_capacity:
print("YES")
else:
print("NO") | Title: Greed
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Jafar has *n* cans of cola. Each can is described by two integers: remaining volume of cola *a**i* and can's capacity *b**i* (*a**i* <=≤<= *b**i*).
Jafar has decided to pour all remaining cola into just 2 cans, determine if he c... | ```python
n= int(input())
can = list(map(int, input().split()))
capacity = list(map(int, input().split()))
vol= sum(can)
capacity.sort(reverse=True)
max_capacity = int(capacity[0]) + int(capacity[1])
if vol<=max_capacity:
print("YES")
else:
print("NO")
``` | 3 | |
519 | E | A and B and Lecture Rooms | PROGRAMMING | 2,100 | [
"binary search",
"data structures",
"dfs and similar",
"dp",
"trees"
] | null | null | A and B are preparing themselves for programming contests.
The University where A and B study is a set of rooms connected by corridors. Overall, the University has *n* rooms connected by *n*<=-<=1 corridors so that you can get from any room to any other one by moving along the corridors. The rooms are numbered from 1 ... | The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of rooms in the University.
The next *n*<=-<=1 lines describe the corridors. The *i*-th of these lines (1<=≤<=*i*<=≤<=*n*<=-<=1) contains two integers *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*), showing that the *i*-th corridor connects rooms ... | In the *i*-th (1<=≤<=*i*<=≤<=*m*) line print the number of rooms that are equidistant from the rooms where A and B write contest on the *i*-th day. | [
"4\n1 2\n1 3\n2 4\n1\n2 3\n",
"4\n1 2\n2 3\n2 4\n2\n1 2\n1 3\n"
] | [
"1\n",
"0\n2\n"
] | in the first sample there is only one room at the same distance from rooms number 2 and 3 — room number 1. | 2,500 | [
{
"input": "4\n1 2\n1 3\n2 4\n1\n2 3",
"output": "1"
},
{
"input": "4\n1 2\n2 3\n2 4\n2\n1 2\n1 3",
"output": "0\n2"
},
{
"input": "15\n1 2\n1 3\n1 4\n2 5\n2 6\n2 7\n5 8\n6 9\n9 14\n14 15\n7 10\n4 13\n3 11\n3 12\n6\n10 15\n13 12\n2 15\n8 4\n15 12\n6 13",
"output": "1\n10\n1\n7\n0\n4"... | 1,682,960,114 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 6 | 2,000 | 14,336,000 | n = int(input())
adj = {i: [] for i in range(1, n+1)}
for _ in range(n-1):
a, b = map(int, input().split())
adj[a].append(b)
adj[b].append(a)
m = int(input())
for _ in range(m):
x, y = map(int, input().split())
dist_x = [-1] * (n+1)
dist_y = [-1] * (n+1)
def dfs(... | Title: A and B and Lecture Rooms
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A and B are preparing themselves for programming contests.
The University where A and B study is a set of rooms connected by corridors. Overall, the University has *n* rooms connected by *n*<=-<=1 corridors s... | ```python
n = int(input())
adj = {i: [] for i in range(1, n+1)}
for _ in range(n-1):
a, b = map(int, input().split())
adj[a].append(b)
adj[b].append(a)
m = int(input())
for _ in range(m):
x, y = map(int, input().split())
dist_x = [-1] * (n+1)
dist_y = [-1] * (n+1)
... | 0 | |
3 | A | Shortest path of the king | PROGRAMMING | 1,000 | [
"greedy",
"shortest paths"
] | A. Shortest path of the king | 1 | 64 | The king is left alone on the chessboard. In spite of this loneliness, he doesn't lose heart, because he has business of national importance. For example, he has to pay an official visit to square *t*. As the king is not in habit of wasting his time, he wants to get from his current position *s* to square *t* in the le... | The first line contains the chessboard coordinates of square *s*, the second line — of square *t*.
Chessboard coordinates consist of two characters, the first one is a lowercase Latin letter (from a to h), the second one is a digit from 1 to 8. | In the first line print *n* — minimum number of the king's moves. Then in *n* lines print the moves themselves. Each move is described with one of the 8: L, R, U, D, LU, LD, RU or RD.
L, R, U, D stand respectively for moves left, right, up and down (according to the picture), and 2-letter combinations stand for diago... | [
"a8\nh1\n"
] | [
"7\nRD\nRD\nRD\nRD\nRD\nRD\nRD\n"
] | none | 0 | [
{
"input": "a8\nh1",
"output": "7\nRD\nRD\nRD\nRD\nRD\nRD\nRD"
},
{
"input": "b2\nb4",
"output": "2\nU\nU"
},
{
"input": "a5\na5",
"output": "0"
},
{
"input": "h1\nb2",
"output": "6\nLU\nL\nL\nL\nL\nL"
},
{
"input": "c5\nh2",
"output": "5\nRD\nRD\nRD\nR\nR"
... | 1,627,042,808 | 2,147,483,647 | PyPy 3 | RUNTIME_ERROR | TESTS | 3 | 248 | 22,323,200 | import sys
input = sys.stdin.readline
src = input().rstrip()
dst = input().rstrip()
# source's position
s_i = 8-int(src[1])
s_j = ord(src[0])-97
# destination's position
d_i = 8-int(dst[1])
d_j = ord(dst[0])-97
diff_i = d_i-s_i
diff_j = d_j-s_j
ans = 0
sub_path = ''
path = ''
if abs(diff_i) < abs(diff_j):
if di... | Title: Shortest path of the king
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
The king is left alone on the chessboard. In spite of this loneliness, he doesn't lose heart, because he has business of national importance. For example, he has to pay an official visit to square *t*. As the king ... | ```python
import sys
input = sys.stdin.readline
src = input().rstrip()
dst = input().rstrip()
# source's position
s_i = 8-int(src[1])
s_j = ord(src[0])-97
# destination's position
d_i = 8-int(dst[1])
d_j = ord(dst[0])-97
diff_i = d_i-s_i
diff_j = d_j-s_j
ans = 0
sub_path = ''
path = ''
if abs(diff_i) < abs(diff_j):... | -1 |
544 | B | Sea and Islands | PROGRAMMING | 1,400 | [
"constructive algorithms",
"implementation"
] | null | null | A map of some object is a rectangular field consisting of *n* rows and *n* columns. Each cell is initially occupied by the sea but you can cover some some cells of the map with sand so that exactly *k* islands appear on the map. We will call a set of sand cells to be island if it is possible to get from each of them to... | The single line contains two positive integers *n*, *k* (1<=≤<=*n*<=≤<=100, 0<=≤<=*k*<=≤<=*n*2) — the size of the map and the number of islands you should form. | If the answer doesn't exist, print "NO" (without the quotes) in a single line.
Otherwise, print "YES" in the first line. In the next *n* lines print the description of the map. Each of the lines of the description must consist only of characters 'S' and 'L', where 'S' is a cell that is occupied by the sea and 'L' is t... | [
"5 2\n",
"5 25\n"
] | [
"YES\nSSSSS\nLLLLL\nSSSSS\nLLLLL\nSSSSS\n",
"NO\n"
] | none | 1,000 | [
{
"input": "5 2",
"output": "YES\nSSSSS\nLLLLL\nSSSSS\nLLLLL\nSSSSS"
},
{
"input": "5 25",
"output": "NO"
},
{
"input": "82 6047",
"output": "NO"
},
{
"input": "6 5",
"output": "YES\nLSLSLS\nSLSLSS\nSSSSSS\nSSSSSS\nSSSSSS\nSSSSSS"
},
{
"input": "10 80",
"outpu... | 1,497,859,215 | 2,147,483,647 | Python 3 | OK | TESTS | 42 | 62 | 0 | n, k = [int(x) for x in input().split()]
if (n * n + 1) // 2 < k:
print("NO")
else:
print("YES")
arr = ['L'] * k + ['S'] * ((n * n + 1) // 2 - k)
s = 'S'.join(arr)
if n % 2 == 0:
s += 'S'
turn = 1
while s:
print(s[:n][::turn])
s = s[n:]
if n % 2 =... | Title: Sea and Islands
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A map of some object is a rectangular field consisting of *n* rows and *n* columns. Each cell is initially occupied by the sea but you can cover some some cells of the map with sand so that exactly *k* islands appear on... | ```python
n, k = [int(x) for x in input().split()]
if (n * n + 1) // 2 < k:
print("NO")
else:
print("YES")
arr = ['L'] * k + ['S'] * ((n * n + 1) // 2 - k)
s = 'S'.join(arr)
if n % 2 == 0:
s += 'S'
turn = 1
while s:
print(s[:n][::turn])
s = s[n:]
... | 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... | 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 f... | 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 ... | 1,661,428,644 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 39 | 124 | 0 | n = int(input())
v = sorted(map(int, input().split()))[::-1]
for i in range(13):
if sum(v[:i]) >= n:
print(i)
exit(0)
print(-1) | 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 open... | ```python
n = int(input())
v = sorted(map(int, input().split()))[::-1]
for i in range(13):
if sum(v[:i]) >= n:
print(i)
exit(0)
print(-1)
``` | 3 | |
835 | A | Key races | PROGRAMMING | 800 | [
"math"
] | null | null | Two boys decided to compete in text typing on the site "Key races". During the competition, they have to type a text consisting of *s* characters. The first participant types one character in *v*1 milliseconds and has ping *t*1 milliseconds. The second participant types one character in *v*2 milliseconds and has ping *... | The first line contains five integers *s*, *v*1, *v*2, *t*1, *t*2 (1<=≤<=*s*,<=*v*1,<=*v*2,<=*t*1,<=*t*2<=≤<=1000) — the number of characters in the text, the time of typing one character for the first participant, the time of typing one character for the the second participant, the ping of the first participant and th... | If the first participant wins, print "First". If the second participant wins, print "Second". In case of a draw print "Friendship". | [
"5 1 2 1 2\n",
"3 3 1 1 1\n",
"4 5 3 1 5\n"
] | [
"First\n",
"Second\n",
"Friendship\n"
] | In the first example, information on the success of the first participant comes in 7 milliseconds, of the second participant — in 14 milliseconds. So, the first wins.
In the second example, information on the success of the first participant comes in 11 milliseconds, of the second participant — in 5 milliseconds. So, ... | 500 | [
{
"input": "5 1 2 1 2",
"output": "First"
},
{
"input": "3 3 1 1 1",
"output": "Second"
},
{
"input": "4 5 3 1 5",
"output": "Friendship"
},
{
"input": "1000 1000 1000 1000 1000",
"output": "Friendship"
},
{
"input": "1 1 1 1 1",
"output": "Friendship"
},
... | 1,574,357,391 | 2,147,483,647 | Python 3 | OK | TESTS | 32 | 124 | 0 | import time
def calculateWinner(lenS, first_tps, sec_tps, first_ping, sec_ping):
winner = ""
first_ttime = lenS * first_tps + 2 * (first_ping)
sec_ttime = lenS * sec_tps + 2 * (sec_ping)
if first_ttime < sec_ttime:
winner = "First"
elif first_ttime > sec_ttime:
winner... | Title: Key races
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Two boys decided to compete in text typing on the site "Key races". During the competition, they have to type a text consisting of *s* characters. The first participant types one character in *v*1 milliseconds and has ping *t... | ```python
import time
def calculateWinner(lenS, first_tps, sec_tps, first_ping, sec_ping):
winner = ""
first_ttime = lenS * first_tps + 2 * (first_ping)
sec_ttime = lenS * sec_tps + 2 * (sec_ping)
if first_ttime < sec_ttime:
winner = "First"
elif first_ttime > sec_ttime:
... | 3 | |
385 | B | Bear and Strings | PROGRAMMING | 1,200 | [
"brute force",
"greedy",
"implementation",
"math",
"strings"
] | null | null | The bear has a string *s*<==<=*s*1*s*2... *s*|*s*| (record |*s*| is the string's length), consisting of lowercase English letters. The bear wants to count the number of such pairs of indices *i*,<=*j* (1<=≤<=*i*<=≤<=*j*<=≤<=|*s*|), that string *x*(*i*,<=*j*)<==<=*s**i**s**i*<=+<=1... *s**j* contains at least one string... | The first line contains a non-empty string *s* (1<=≤<=|*s*|<=≤<=5000). It is guaranteed that the string only consists of lowercase English letters. | Print a single number — the answer to the problem. | [
"bearbtear\n",
"bearaabearc\n"
] | [
"6\n",
"20\n"
] | In the first sample, the following pairs (*i*, *j*) match: (1, 4), (1, 5), (1, 6), (1, 7), (1, 8), (1, 9).
In the second sample, the following pairs (*i*, *j*) match: (1, 4), (1, 5), (1, 6), (1, 7), (1, 8), (1, 9), (1, 10), (1, 11), (2, 10), (2, 11), (3, 10), (3, 11), (4, 10), (4, 11), (5, 10), (5, 11)... | 1,000 | [
{
"input": "bearbtear",
"output": "6"
},
{
"input": "bearaabearc",
"output": "20"
},
{
"input": "pbearbearhbearzqbearjkterasjhy",
"output": "291"
},
{
"input": "pbearjbearbebearnbabcffbearbearwubearjezpiorrbearbearjbdlbearbearqbearjbearwipmsbearoaftrsebearzsnqb",
"output"... | 1,596,658,108 | 2,147,483,647 | PyPy 3 | OK | TESTS | 43 | 156 | 21,606,400 | import sys
def mi(s):
return map(int, s.strip().split())
def lmi(s):
return list(mi(s))
def mf(f, s):
return map(f, s)
def lmf(f, s):
return list(mf(f, s))
def main(s):
intervals = []
for i in range(len(s) - 3):
if s[i:i+4] == "bear":
intervals.append((i, i + 3))
co... | Title: Bear and Strings
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The bear has a string *s*<==<=*s*1*s*2... *s*|*s*| (record |*s*| is the string's length), consisting of lowercase English letters. The bear wants to count the number of such pairs of indices *i*,<=*j* (1<=≤<=*i*<=≤<=*j... | ```python
import sys
def mi(s):
return map(int, s.strip().split())
def lmi(s):
return list(mi(s))
def mf(f, s):
return map(f, s)
def lmf(f, s):
return list(mf(f, s))
def main(s):
intervals = []
for i in range(len(s) - 3):
if s[i:i+4] == "bear":
intervals.append((i, i + 3... | 3 | |
469 | A | I Wanna Be the Guy | PROGRAMMING | 800 | [
"greedy",
"implementation"
] | null | null | There is a game called "I Wanna Be the Guy", consisting of *n* levels. Little X and his friend Little Y are addicted to the game. Each of them wants to pass the whole game.
Little X can pass only *p* levels of the game. And Little Y can pass only *q* levels of the game. You are given the indices of levels Little X can... | The first line contains a single integer *n* (1<=≤<=<=*n*<=≤<=100).
The next line contains an integer *p* (0<=≤<=*p*<=≤<=*n*) at first, then follows *p* distinct integers *a*1,<=*a*2,<=...,<=*a**p* (1<=≤<=*a**i*<=≤<=*n*). These integers denote the indices of levels Little X can pass. The next line contains the levels... | If they can pass all the levels, print "I become the guy.". If it's impossible, print "Oh, my keyboard!" (without the quotes). | [
"4\n3 1 2 3\n2 2 4\n",
"4\n3 1 2 3\n2 2 3\n"
] | [
"I become the guy.\n",
"Oh, my keyboard!\n"
] | In the first sample, Little X can pass levels [1 2 3], and Little Y can pass level [2 4], so they can pass all the levels both.
In the second sample, no one can pass level 4. | 500 | [
{
"input": "4\n3 1 2 3\n2 2 4",
"output": "I become the guy."
},
{
"input": "4\n3 1 2 3\n2 2 3",
"output": "Oh, my keyboard!"
},
{
"input": "10\n5 8 6 1 5 4\n6 1 3 2 9 4 6",
"output": "Oh, my keyboard!"
},
{
"input": "10\n8 8 10 7 3 1 4 2 6\n8 9 5 10 3 7 2 4 8",
"output":... | 1,693,329,577 | 2,147,483,647 | Python 3 | OK | TESTS | 29 | 46 | 0 | n=int(input())
p=list(map(int,input().split()))
s=list(map(int,input().split()))
p.pop(0)
s.pop(0)
m=[]
for i in range(1,n+1):
m.append(i)
sum=0
for j in m:
if j in p+s:
sum+=1
if sum==len(m):
print("I become the guy.")
else:
print("Oh, my keyboard!")
| Title: I Wanna Be the Guy
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There is a game called "I Wanna Be the Guy", consisting of *n* levels. Little X and his friend Little Y are addicted to the game. Each of them wants to pass the whole game.
Little X can pass only *p* levels of the g... | ```python
n=int(input())
p=list(map(int,input().split()))
s=list(map(int,input().split()))
p.pop(0)
s.pop(0)
m=[]
for i in range(1,n+1):
m.append(i)
sum=0
for j in m:
if j in p+s:
sum+=1
if sum==len(m):
print("I become the guy.")
else:
print("Oh, my keyboard!")
... | 3 | |
588 | A | Duff and Meat | PROGRAMMING | 900 | [
"greedy"
] | null | null | Duff is addicted to meat! Malek wants to keep her happy for *n* days. In order to be happy in *i*-th day, she needs to eat exactly *a**i* kilograms of meat.
There is a big shop uptown and Malek wants to buy meat for her from there. In *i*-th day, they sell meat for *p**i* dollars per kilogram. Malek knows all numbers ... | The first line of input contains integer *n* (1<=≤<=*n*<=≤<=105), the number of days.
In the next *n* lines, *i*-th line contains two integers *a**i* and *p**i* (1<=≤<=*a**i*,<=*p**i*<=≤<=100), the amount of meat Duff needs and the cost of meat in that day. | Print the minimum money needed to keep Duff happy for *n* days, in one line. | [
"3\n1 3\n2 2\n3 1\n",
"3\n1 3\n2 1\n3 2\n"
] | [
"10\n",
"8\n"
] | In the first sample case: An optimal way would be to buy 1 kg on the first day, 2 kg on the second day and 3 kg on the third day.
In the second sample case: An optimal way would be to buy 1 kg on the first day and 5 kg (needed meat for the second and third day) on the second day. | 750 | [
{
"input": "3\n1 3\n2 2\n3 1",
"output": "10"
},
{
"input": "3\n1 3\n2 1\n3 2",
"output": "8"
},
{
"input": "1\n39 52",
"output": "2028"
},
{
"input": "2\n25 56\n94 17",
"output": "2998"
},
{
"input": "5\n39 21\n95 89\n73 90\n9 55\n85 32",
"output": "6321"
}... | 1,649,458,600 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 5 | 46 | 0 | n=int(input())
la=[]
lp=[]
for x in range(n) :
a,p=map(int,input().split())
la.append(a)
lp.append(p)
sm=0
for x in range(len(lp)) :
if lp[x]==min(lp) :
sm+=(sum(la[x:])*lp[x])
break
else:
sm+=la[x]*lp[x]
print(sm) | Title: Duff and Meat
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Duff is addicted to meat! Malek wants to keep her happy for *n* days. In order to be happy in *i*-th day, she needs to eat exactly *a**i* kilograms of meat.
There is a big shop uptown and Malek wants to buy meat for her ... | ```python
n=int(input())
la=[]
lp=[]
for x in range(n) :
a,p=map(int,input().split())
la.append(a)
lp.append(p)
sm=0
for x in range(len(lp)) :
if lp[x]==min(lp) :
sm+=(sum(la[x:])*lp[x])
break
else:
sm+=la[x]*lp[x]
print(sm)
``` | 0 | |
520 | B | Two Buttons | PROGRAMMING | 1,400 | [
"dfs and similar",
"graphs",
"greedy",
"implementation",
"math",
"shortest paths"
] | null | null | Vasya has found a strange device. On the front panel of a device there are: a red button, a blue button and a display showing some positive integer. After clicking the red button, device multiplies the displayed number by two. After clicking the blue button, device subtracts one from the number on the display. If at so... | The first and the only line of the input contains two distinct integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=104), separated by a space . | Print a single number — the minimum number of times one needs to push the button required to get the number *m* out of number *n*. | [
"4 6\n",
"10 1\n"
] | [
"2\n",
"9\n"
] | In the first example you need to push the blue button once, and then push the red button once.
In the second example, doubling the number is unnecessary, so we need to push the blue button nine times. | 1,000 | [
{
"input": "4 6",
"output": "2"
},
{
"input": "10 1",
"output": "9"
},
{
"input": "1 2",
"output": "1"
},
{
"input": "2 1",
"output": "1"
},
{
"input": "1 3",
"output": "3"
},
{
"input": "3 1",
"output": "2"
},
{
"input": "2 10",
"outpu... | 1,692,335,930 | 2,147,483,647 | Python 3 | OK | TESTS | 51 | 46 | 0 | n,m=map(int,input().split())
count=0
while n<m:
if m%2==0:
m//=2
else:
m+=1
count+=1
count+= n-m
print(count) | Title: Two Buttons
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya has found a strange device. On the front panel of a device there are: a red button, a blue button and a display showing some positive integer. After clicking the red button, device multiplies the displayed number by t... | ```python
n,m=map(int,input().split())
count=0
while n<m:
if m%2==0:
m//=2
else:
m+=1
count+=1
count+= n-m
print(count)
``` | 3 | |
122 | A | Lucky Division | PROGRAMMING | 1,000 | [
"brute force",
"number theory"
] | null | null | Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Petya calls a number almost lucky if it could be evenly divided by some lucky number. Help him find ... | The single line contains an integer *n* (1<=≤<=*n*<=≤<=1000) — the number that needs to be checked. | In the only line print "YES" (without the quotes), if number *n* is almost lucky. Otherwise, print "NO" (without the quotes). | [
"47\n",
"16\n",
"78\n"
] | [
"YES\n",
"YES\n",
"NO\n"
] | Note that all lucky numbers are almost lucky as any number is evenly divisible by itself.
In the first sample 47 is a lucky number. In the second sample 16 is divisible by 4. | 500 | [
{
"input": "47",
"output": "YES"
},
{
"input": "16",
"output": "YES"
},
{
"input": "78",
"output": "NO"
},
{
"input": "48",
"output": "YES"
},
{
"input": "100",
"output": "YES"
},
{
"input": "107",
"output": "NO"
},
{
"input": "77",
"ou... | 1,694,933,677 | 2,147,483,647 | Python 3 | OK | TESTS | 36 | 92 | 0 | a = int(input())
def lucky(no):
while no!=0:
x = no%10
no //= 10
if x!= 7 and x!=4:
return 0
else:
return 1
for i in range(1,a//2+1):
if lucky(i)==1:
if a%i==0:
print('YES')
break
else:
if lucky(a) == 1:
... | Title: Lucky Division
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
... | ```python
a = int(input())
def lucky(no):
while no!=0:
x = no%10
no //= 10
if x!= 7 and x!=4:
return 0
else:
return 1
for i in range(1,a//2+1):
if lucky(i)==1:
if a%i==0:
print('YES')
break
else:
if lucky(a)... | 3 | |
9 | A | Die Roll | PROGRAMMING | 800 | [
"math",
"probabilities"
] | A. Die Roll | 1 | 64 | Yakko, Wakko and Dot, world-famous animaniacs, decided to rest from acting in cartoons, and take a leave to travel a bit. Yakko dreamt to go to Pennsylvania, his Motherland and the Motherland of his ancestors. Wakko thought about Tasmania, its beaches, sun and sea. Dot chose Transylvania as the most mysterious and unpr... | The only line of the input file contains two natural numbers Y and W — the results of Yakko's and Wakko's die rolls. | Output the required probability in the form of irreducible fraction in format «A/B», where A — the numerator, and B — the denominator. If the required probability equals to zero, output «0/1». If the required probability equals to 1, output «1/1». | [
"4 2\n"
] | [
"1/2\n"
] | Dot will go to Transylvania, if she is lucky to roll 4, 5 or 6 points. | 0 | [
{
"input": "4 2",
"output": "1/2"
},
{
"input": "1 1",
"output": "1/1"
},
{
"input": "1 2",
"output": "5/6"
},
{
"input": "1 3",
"output": "2/3"
},
{
"input": "1 4",
"output": "1/2"
},
{
"input": "1 5",
"output": "1/3"
},
{
"input": "1 6",
... | 1,627,656,994 | 2,147,483,647 | PyPy 3 | RUNTIME_ERROR | TESTS | 0 | 248 | 22,220,800 | Y = int(input())
W = int(input())
lts = [Y,W]
lts.sort()
angka = lts[-1]
if 0<Y<7 and 0<W<7:
if angka == 1:
print("1/1")
elif angka == 2:
print("5/6")
elif angka == 3:
print("2/3")
elif angka == 4:
print("1/2")
elif angka == 5:
print("1/3")
elif angka ==... | Title: Die Roll
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
Yakko, Wakko and Dot, world-famous animaniacs, decided to rest from acting in cartoons, and take a leave to travel a bit. Yakko dreamt to go to Pennsylvania, his Motherland and the Motherland of his ancestors. Wakko thought about T... | ```python
Y = int(input())
W = int(input())
lts = [Y,W]
lts.sort()
angka = lts[-1]
if 0<Y<7 and 0<W<7:
if angka == 1:
print("1/1")
elif angka == 2:
print("5/6")
elif angka == 3:
print("2/3")
elif angka == 4:
print("1/2")
elif angka == 5:
print("1/3")
eli... | -1 |
27 | A | Next Test | PROGRAMMING | 1,200 | [
"implementation",
"sortings"
] | A. Next Test | 2 | 256 | «Polygon» is a system which allows to create programming tasks in a simple and professional way. When you add a test to the problem, the corresponding form asks you for the test index. As in most cases it is clear which index the next test will have, the system suggests the default value of the index. It is calculated ... | The first line contains one integer *n* (1<=≤<=*n*<=≤<=3000) — the amount of previously added tests. The second line contains *n* distinct integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=3000) — indexes of these tests. | Output the required default value for the next test index. | [
"3\n1 7 2\n"
] | [
"3\n"
] | none | 500 | [
{
"input": "1\n1",
"output": "2"
},
{
"input": "2\n2 1",
"output": "3"
},
{
"input": "3\n3 4 1",
"output": "2"
},
{
"input": "4\n6 4 3 5",
"output": "1"
},
{
"input": "5\n3 2 1 7 4",
"output": "5"
},
{
"input": "6\n4 1 2 5 3 7",
"output": "6"
},
... | 1,587,755,019 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 218 | 307,200 | n=int(input())
a=[int(i) for i in input().split()]
a.sort()
b=[]
for i in range(n):
b.append(i+1)
ans=n+1
for i in range(n):
if a[i]!=b[i]:
ans=b[i]
break
print(ans) | Title: Next Test
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
«Polygon» is a system which allows to create programming tasks in a simple and professional way. When you add a test to the problem, the corresponding form asks you for the test index. As in most cases it is clear which index the... | ```python
n=int(input())
a=[int(i) for i in input().split()]
a.sort()
b=[]
for i in range(n):
b.append(i+1)
ans=n+1
for i in range(n):
if a[i]!=b[i]:
ans=b[i]
break
print(ans)
``` | 3.944928 |
432 | A | Choosing Teams | PROGRAMMING | 800 | [
"greedy",
"implementation",
"sortings"
] | null | null | The Saratov State University Olympiad Programmers Training Center (SSU OPTC) has *n* students. For each student you know the number of times he/she has participated in the ACM ICPC world programming championship. According to the ACM ICPC rules, each person can participate in the world championship at most 5 times.
Th... | The first line contains two integers, *n* and *k* (1<=≤<=*n*<=≤<=2000; 1<=≤<=*k*<=≤<=5). The next line contains *n* integers: *y*1,<=*y*2,<=...,<=*y**n* (0<=≤<=*y**i*<=≤<=5), where *y**i* shows the number of times the *i*-th person participated in the ACM ICPC world championship. | Print a single number — the answer to the problem. | [
"5 2\n0 4 5 1 0\n",
"6 4\n0 1 2 3 4 5\n",
"6 5\n0 0 0 0 0 0\n"
] | [
"1\n",
"0\n",
"2\n"
] | In the first sample only one team could be made: the first, the fourth and the fifth participants.
In the second sample no teams could be created.
In the third sample two teams could be created. Any partition into two teams fits. | 500 | [
{
"input": "5 2\n0 4 5 1 0",
"output": "1"
},
{
"input": "6 4\n0 1 2 3 4 5",
"output": "0"
},
{
"input": "6 5\n0 0 0 0 0 0",
"output": "2"
},
{
"input": "3 4\n0 1 0",
"output": "1"
},
{
"input": "3 4\n0 2 0",
"output": "0"
},
{
"input": "6 5\n0 0 0 0 0... | 1,698,912,334 | 2,147,483,647 | Python 3 | OK | TESTS | 35 | 46 | 0 | n, k = map(int, input().split(' '))
inp = map(int, input().split(' '))
add_turns = map(lambda x: x + k, inp)
satisfied = filter(lambda x: x <= 5, add_turns)
n_teams = len(list(satisfied)) // 3
print(n_teams)
| Title: Choosing Teams
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Saratov State University Olympiad Programmers Training Center (SSU OPTC) has *n* students. For each student you know the number of times he/she has participated in the ACM ICPC world programming championship. Accordi... | ```python
n, k = map(int, input().split(' '))
inp = map(int, input().split(' '))
add_turns = map(lambda x: x + k, inp)
satisfied = filter(lambda x: x <= 5, add_turns)
n_teams = len(list(satisfied)) // 3
print(n_teams)
``` | 3 | |
749 | A | Bachgold Problem | PROGRAMMING | 800 | [
"greedy",
"implementation",
"math",
"number theory"
] | null | null | Bachgold problem is very easy to formulate. Given a positive integer *n* represent it as a sum of maximum possible number of prime numbers. One can prove that such representation exists for any integer greater than 1.
Recall that integer *k* is called prime if it is greater than 1 and has exactly two positive integer ... | The only line of the input contains a single integer *n* (2<=≤<=*n*<=≤<=100<=000). | The first line of the output contains a single integer *k* — maximum possible number of primes in representation.
The second line should contain *k* primes with their sum equal to *n*. You can print them in any order. If there are several optimal solution, print any of them. | [
"5\n",
"6\n"
] | [
"2\n2 3\n",
"3\n2 2 2\n"
] | none | 500 | [
{
"input": "5",
"output": "2\n2 3"
},
{
"input": "6",
"output": "3\n2 2 2"
},
{
"input": "2",
"output": "1\n2"
},
{
"input": "3",
"output": "1\n3"
},
{
"input": "99999",
"output": "49999\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 ... | 1,637,683,091 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 30 | 0 | # from collections import Counter
# for _ in range(int(input())):
N = int(input())
ans = []
if N % 2 == 0:
T = N // 2
ans = [2]*T
else:
T = N // 2
ans = [2] * (T-1)
ans.append(3)
print(*ans,sep=" ") | Title: Bachgold Problem
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bachgold problem is very easy to formulate. Given a positive integer *n* represent it as a sum of maximum possible number of prime numbers. One can prove that such representation exists for any integer greater than 1.
... | ```python
# from collections import Counter
# for _ in range(int(input())):
N = int(input())
ans = []
if N % 2 == 0:
T = N // 2
ans = [2]*T
else:
T = N // 2
ans = [2] * (T-1)
ans.append(3)
print(*ans,sep=" ")
``` | 0 | |
272 | D | Dima and Two Sequences | PROGRAMMING | 1,600 | [
"combinatorics",
"math",
"sortings"
] | null | null | Little Dima has two sequences of points with integer coordinates: sequence (*a*1,<=1),<=(*a*2,<=2),<=...,<=(*a**n*,<=*n*) and sequence (*b*1,<=1),<=(*b*2,<=2),<=...,<=(*b**n*,<=*n*).
Now Dima wants to count the number of distinct sequences of points of length 2·*n* that can be assembled from these sequences, such that... | The first line contains integer *n* (1<=≤<=*n*<=≤<=105). The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109). The third line contains *n* integers *b*1,<=*b*2,<=...,<=*b**n* (1<=≤<=*b**i*<=≤<=109). The numbers in the lines are separated by spaces.
The last line contains integer *m* ... | In the single line print the remainder after dividing the answer to the problem by number *m*. | [
"1\n1\n2\n7\n",
"2\n1 2\n2 3\n11\n"
] | [
"1\n",
"2\n"
] | In the first sample you can get only one sequence: (1, 1), (2, 1).
In the second sample you can get such sequences : (1, 1), (2, 2), (2, 1), (3, 2); (1, 1), (2, 1), (2, 2), (3, 2). Thus, the answer is 2. | 2,000 | [
{
"input": "1\n1\n2\n7",
"output": "1"
},
{
"input": "2\n1 2\n2 3\n11",
"output": "2"
},
{
"input": "100\n1 8 10 6 5 3 2 3 4 2 3 7 1 1 5 1 4 1 8 1 5 5 6 5 3 7 4 5 5 3 8 7 8 6 8 9 10 7 8 5 8 9 1 3 7 2 6 1 7 7 2 8 1 5 4 2 10 4 9 8 1 10 1 5 9 8 1 9 5 1 5 7 1 6 7 8 8 2 2 3 3 7 2 10 6 3 6 3 5... | 1,627,835,872 | 2,147,483,647 | PyPy 3 | OK | TESTS | 51 | 778 | 47,718,400 | n = int(input()) #tamaño de las sucesiones
a_n = input().split() #sucesion a_n
b_n = input().split() #sucesion b_n
k = int(input()) #numero para obtener un resultado de la forma km + r con 0 <= r < k
def solution(n, a_n, b_n, k):
c_n = {} #sucesion c_n que representa la union de a_n co... | Title: Dima and Two Sequences
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Dima has two sequences of points with integer coordinates: sequence (*a*1,<=1),<=(*a*2,<=2),<=...,<=(*a**n*,<=*n*) and sequence (*b*1,<=1),<=(*b*2,<=2),<=...,<=(*b**n*,<=*n*).
Now Dima wants to count the ... | ```python
n = int(input()) #tamaño de las sucesiones
a_n = input().split() #sucesion a_n
b_n = input().split() #sucesion b_n
k = int(input()) #numero para obtener un resultado de la forma km + r con 0 <= r < k
def solution(n, a_n, b_n, k):
c_n = {} #sucesion c_n que representa la union... | 3 | |
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 ... | 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... | 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... | 1,619,784,097 | 2,147,483,647 | PyPy 3 | OK | TESTS | 45 | 218 | 0 | n, m = map(int, input().split())
good = list(map(int, input().split()))
bad = list(map(int, input().split()))
minimum_g, maximum_g = min(good), max(good)
minimum_time = -1
if(minimum_g == maximum_g):
minimum_time = 2*minimum_g
else:
minimum_time = max(2*minimum_g, maximum_g)
if(min(bad)<=minimum_time... | 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). Val... | ```python
n, m = map(int, input().split())
good = list(map(int, input().split()))
bad = list(map(int, input().split()))
minimum_g, maximum_g = min(good), max(good)
minimum_time = -1
if(minimum_g == maximum_g):
minimum_time = 2*minimum_g
else:
minimum_time = max(2*minimum_g, maximum_g)
if(min(bad)<=mi... | 3 | |
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 ... | 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",
"outpu... | 1,682,371,751 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 62 | 0 | m, n = map(int, input().split())
board = [[0] * n for _ in range(m)]
count = 0
for i in range(m):
for j in range(n):
if j < n-1 and board[i][j] == 0 and board[i][j+1] == 0:
# Укладываем горизонтальную доминошку
board[i][j] = board[i][j+1] = 1
count += 1
e... | 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 p... | ```python
m, n = map(int, input().split())
board = [[0] * n for _ in range(m)]
count = 0
for i in range(m):
for j in range(n):
if j < n-1 and board[i][j] == 0 and board[i][j+1] == 0:
# Укладываем горизонтальную доминошку
board[i][j] = board[i][j+1] = 1
count += 1
... | 0 |
218 | B | Airport | PROGRAMMING | 1,100 | [
"implementation"
] | null | null | Lolek and Bolek are about to travel abroad by plane. The local airport has a special "Choose Your Plane" offer. The offer's conditions are as follows:
- it is up to a passenger to choose a plane to fly on; - if the chosen plane has *x* (*x*<=><=0) empty seats at the given moment, then the ticket for such a plane ... | The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=1000) — the number of passengers in the queue and the number of planes in the airport, correspondingly. The next line contains *m* integers *a*1,<=*a*2,<=...,<=*a**m* (1<=≤<=*a**i*<=≤<=1000) — *a**i* stands for the number of empty seats in the *i*-th... | Print two integers — the maximum and the minimum number of zlotys that the airport administration can earn, correspondingly. | [
"4 3\n2 1 1\n",
"4 3\n2 2 2\n"
] | [
"5 5\n",
"7 6\n"
] | In the first test sample the number of passengers is equal to the number of empty seats, so regardless of the way the planes are chosen, the administration will earn the same sum.
In the second sample the sum is maximized if the 1-st person in the queue buys a ticket to the 1-st plane, the 2-nd person — to the 2-nd pl... | 500 | [
{
"input": "4 3\n2 1 1",
"output": "5 5"
},
{
"input": "4 3\n2 2 2",
"output": "7 6"
},
{
"input": "10 5\n10 3 3 1 2",
"output": "58 26"
},
{
"input": "10 1\n10",
"output": "55 55"
},
{
"input": "10 1\n100",
"output": "955 955"
},
{
"input": "10 2\n4 7... | 1,692,988,475 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 33 | 154 | 13,209,600 | # n - passengers
n, m = map(int, input().split())
args = list(map(int, input().split()))
args.sort()
def calc(min=True):
result = []
start = 0
if min:
while start < len(args):
result += list(range(1, args[start] + 1))[::-1]
start += 1
return result
args = calc()
min =... | Title: Airport
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Lolek and Bolek are about to travel abroad by plane. The local airport has a special "Choose Your Plane" offer. The offer's conditions are as follows:
- it is up to a passenger to choose a plane to fly on; - if the chosen pl... | ```python
# n - passengers
n, m = map(int, input().split())
args = list(map(int, input().split()))
args.sort()
def calc(min=True):
result = []
start = 0
if min:
while start < len(args):
result += list(range(1, args[start] + 1))[::-1]
start += 1
return result
args = ca... | 3 | |
844 | A | Diversity | PROGRAMMING | 1,000 | [
"greedy",
"implementation",
"strings"
] | null | null | Calculate the minimum number of characters you need to change in the string *s*, so that it contains at least *k* different letters, or print that it is impossible.
String *s* consists only of lowercase Latin letters, and it is allowed to change characters only to lowercase Latin letters too. | First line of input contains string *s*, consisting only of lowercase Latin letters (1<=≤<=|*s*|<=≤<=1000, |*s*| denotes the length of *s*).
Second line of input contains integer *k* (1<=≤<=*k*<=≤<=26). | Print single line with a minimum number of necessary changes, or the word «impossible» (without quotes) if it is impossible. | [
"yandex\n6\n",
"yahoo\n5\n",
"google\n7\n"
] | [
"0\n",
"1\n",
"impossible\n"
] | In the first test case string contains 6 different letters, so we don't need to change anything.
In the second test case string contains 4 different letters: {'*a*', '*h*', '*o*', '*y*'}. To get 5 different letters it is necessary to change one occurrence of '*o*' to some letter, which doesn't occur in the string, for... | 500 | [
{
"input": "yandex\n6",
"output": "0"
},
{
"input": "yahoo\n5",
"output": "1"
},
{
"input": "google\n7",
"output": "impossible"
},
{
"input": "a\n1",
"output": "0"
},
{
"input": "z\n2",
"output": "impossible"
},
{
"input": "fwgfrwgkuwghfiruhewgirueguhe... | 1,589,818,114 | 2,147,483,647 | Python 3 | OK | TESTS | 41 | 108 | 0 | k=input()
n=int(input())
k1=[]
if(len(k)<n):
print("impossible")
else:
for i in k:
if i not in k1:
k1.append(i)
print(max(0,n-len(k1)))
| Title: Diversity
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Calculate the minimum number of characters you need to change in the string *s*, so that it contains at least *k* different letters, or print that it is impossible.
String *s* consists only of lowercase Latin letters, and it... | ```python
k=input()
n=int(input())
k1=[]
if(len(k)<n):
print("impossible")
else:
for i in k:
if i not in k1:
k1.append(i)
print(max(0,n-len(k1)))
``` | 3 | |
229 | A | Shifts | PROGRAMMING | 1,500 | [
"brute force",
"two pointers"
] | null | null | You are given a table consisting of *n* rows and *m* columns. Each cell of the table contains a number, 0 or 1. In one move we can choose some row of the table and cyclically shift its values either one cell to the left, or one cell to the right.
To cyclically shift a table row one cell to the right means to move the ... | The first line contains two space-separated integers: *n* (1<=≤<=*n*<=≤<=100) — the number of rows in the table and *m* (1<=≤<=*m*<=≤<=104) — the number of columns in the table. Then *n* lines follow, each of them contains *m* characters "0" or "1": the *j*-th character of the *i*-th line describes the contents of the ... | Print a single number: the minimum number of moves needed to get only numbers 1 in some column of the table. If this is impossible, print -1. | [
"3 6\n101010\n000100\n100000\n",
"2 3\n111\n000\n"
] | [
"3\n",
"-1\n"
] | In the first sample one way to achieve the goal with the least number of moves is as follows: cyclically shift the second row to the right once, then shift the third row to the left twice. Then the table column before the last one will contain only 1s.
In the second sample one can't shift the rows to get a column cont... | 500 | [
{
"input": "3 6\n101010\n000100\n100000",
"output": "3"
},
{
"input": "2 3\n111\n000",
"output": "-1"
},
{
"input": "1 1\n1",
"output": "0"
},
{
"input": "1 1\n0",
"output": "-1"
},
{
"input": "3 1\n1\n1\n0",
"output": "-1"
},
{
"input": "6 2\n10\n11\n... | 1,570,252,601 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 218 | 0 | n, m = [int(i) for i in input().split()]
ans = [[0 for i in range(n)] for t in range(m)]
matr = list()
for i in range(n):
matr.append([int(x) for x in input()])
if not sum(matr[i]):
print(-1)
exit(0)
print("\n---matr---\n")
for it in matr:
print(it)
print("\n-------\n")
for t... | Title: Shifts
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a table consisting of *n* rows and *m* columns. Each cell of the table contains a number, 0 or 1. In one move we can choose some row of the table and cyclically shift its values either one cell to the left, or one ... | ```python
n, m = [int(i) for i in input().split()]
ans = [[0 for i in range(n)] for t in range(m)]
matr = list()
for i in range(n):
matr.append([int(x) for x in input()])
if not sum(matr[i]):
print(-1)
exit(0)
print("\n---matr---\n")
for it in matr:
print(it)
print("\n-------\... | 0 | |
573 | C | Bear and Drawing | PROGRAMMING | 2,300 | [
"constructive algorithms",
"dfs and similar",
"trees"
] | null | null | Limak is a little bear who learns to draw. People usually start with houses, fences and flowers but why would bears do it? Limak lives in the forest and he decides to draw a tree.
Recall that tree is a connected graph consisting of *n* vertices and *n*<=-<=1 edges.
Limak chose a tree with *n* vertices. He has infinit... | The first line contains single integer *n* (1<=≤<=*n*<=≤<=105).
Next *n*<=-<=1 lines contain description of a tree. *i*-th of them contains two space-separated integers *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*,<=*a**i*<=≠<=*b**i*) denoting an edge between vertices *a**i* and *b**i*. It's guaranteed that given ... | Print "Yes" (without the quotes) if Limak can draw chosen tree. Otherwise, print "No" (without the quotes). | [
"8\n1 2\n1 3\n1 6\n6 4\n6 7\n6 5\n7 8\n",
"13\n1 2\n1 3\n1 4\n2 5\n2 6\n2 7\n3 8\n3 9\n3 10\n4 11\n4 12\n4 13\n"
] | [
"Yes\n",
"No\n"
] | none | 1,750 | [] | 1,691,716,387 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 30 | 0 | print("_RANDOM_GUESS_1691716387.4453554")# 1691716387.4453738 | Title: Bear and Drawing
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Limak is a little bear who learns to draw. People usually start with houses, fences and flowers but why would bears do it? Limak lives in the forest and he decides to draw a tree.
Recall that tree is a connected graph... | ```python
print("_RANDOM_GUESS_1691716387.4453554")# 1691716387.4453738
``` | 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 ... | 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,624,208,637 | 2,147,483,647 | PyPy 3 | RUNTIME_ERROR | TESTS | 3 | 93 | 2,048,000 | # A. Meeting of Old Friends
l1,r1,l2,r2,k=map(int,input().split())
if l2>r1 or r2<l1:
print(0)
elif l2<=r1 and l2>l1:
ans=(r1-l2)+1
if k>=l2 and k<=r1:
ans-=1
print(ans)
elif r2>=l1 and r2<=r1:
ans=abs(li-r2)+1
if k>=l1 and k<=r2:
ans-=1
print(ans)
else:
an... | 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 inclusi... | ```python
# A. Meeting of Old Friends
l1,r1,l2,r2,k=map(int,input().split())
if l2>r1 or r2<l1:
print(0)
elif l2<=r1 and l2>l1:
ans=(r1-l2)+1
if k>=l2 and k<=r1:
ans-=1
print(ans)
elif r2>=l1 and r2<=r1:
ans=abs(li-r2)+1
if k>=l1 and k<=r2:
ans-=1
print(ans)
els... | -1 | |
709 | A | Juicer | PROGRAMMING | 900 | [
"implementation"
] | null | null | Kolya is going to make fresh orange juice. He has *n* oranges of sizes *a*1,<=*a*2,<=...,<=*a**n*. Kolya will put them in the juicer in the fixed order, starting with orange of size *a*1, then orange of size *a*2 and so on. To be put in the juicer the orange must have size not exceeding *b*, so if Kolya sees an orange ... | The first line of the input contains three integers *n*, *b* and *d* (1<=≤<=*n*<=≤<=100<=000, 1<=≤<=*b*<=≤<=*d*<=≤<=1<=000<=000) — the number of oranges, the maximum size of the orange that fits in the juicer and the value *d*, which determines the condition when the waste section should be emptied.
The second line co... | Print one integer — the number of times Kolya will have to empty the waste section. | [
"2 7 10\n5 6\n",
"1 5 10\n7\n",
"3 10 10\n5 7 7\n",
"1 1 1\n1\n"
] | [
"1\n",
"0\n",
"1\n",
"0\n"
] | In the first sample, Kolya will squeeze the juice from two oranges and empty the waste section afterwards.
In the second sample, the orange won't fit in the juicer so Kolya will have no juice at all. | 500 | [
{
"input": "2 7 10\n5 6",
"output": "1"
},
{
"input": "1 5 10\n7",
"output": "0"
},
{
"input": "3 10 10\n5 7 7",
"output": "1"
},
{
"input": "1 1 1\n1",
"output": "0"
},
{
"input": "2 951637 951638\n44069 951637",
"output": "1"
},
{
"input": "50 100 12... | 1,695,277,167 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 15 | 0 | n, b, d = map(int, input().split())
s = list(map(int, input.split()))
w = 0
ec = 0
c = 0
print(n," ",b," ",d)
print(s)
| Title: Juicer
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Kolya is going to make fresh orange juice. He has *n* oranges of sizes *a*1,<=*a*2,<=...,<=*a**n*. Kolya will put them in the juicer in the fixed order, starting with orange of size *a*1, then orange of size *a*2 and so on. To b... | ```python
n, b, d = map(int, input().split())
s = list(map(int, input.split()))
w = 0
ec = 0
c = 0
print(n," ",b," ",d)
print(s)
``` | -1 | |
855 | A | Tom Riddle's Diary | PROGRAMMING | 800 | [
"brute force",
"implementation",
"strings"
] | null | null | Harry Potter is on a mission to destroy You-Know-Who's Horcruxes. The first Horcrux that he encountered in the Chamber of Secrets is Tom Riddle's diary. The diary was with Ginny and it forced her to open the Chamber of Secrets. Harry wants to know the different people who had ever possessed the diary to make sure they ... | First line of input contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of names in the list.
Next *n* lines each contain a string *s**i*, consisting of lowercase English letters. The length of each string is between 1 and 100. | Output *n* lines each containing either "YES" or "NO" (without quotes), depending on whether this string was already present in the stream or not.
You can print each letter in any case (upper or lower). | [
"6\ntom\nlucius\nginny\nharry\nginny\nharry\n",
"3\na\na\na\n"
] | [
"NO\nNO\nNO\nNO\nYES\nYES\n",
"NO\nYES\nYES\n"
] | In test case 1, for *i* = 5 there exists *j* = 3 such that *s*<sub class="lower-index">*i*</sub> = *s*<sub class="lower-index">*j*</sub> and *j* < *i*, which means that answer for *i* = 5 is "YES". | 500 | [
{
"input": "6\ntom\nlucius\nginny\nharry\nginny\nharry",
"output": "NO\nNO\nNO\nNO\nYES\nYES"
},
{
"input": "3\na\na\na",
"output": "NO\nYES\nYES"
},
{
"input": "1\nzn",
"output": "NO"
},
{
"input": "9\nliyzmbjwnzryjokufuxcqtzwworjeoxkbaqrujrhdidqdvwdfzilwszgnzglnnbogaclckfnb... | 1,691,056,002 | 2,147,483,647 | Python 3 | OK | TESTS | 55 | 46 | 0 | n = int(input())
a = []
for i in range(n):
b = input()
if b in a:
print('Yes')
else:
print('No')
a.append(b)
| Title: Tom Riddle's Diary
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Harry Potter is on a mission to destroy You-Know-Who's Horcruxes. The first Horcrux that he encountered in the Chamber of Secrets is Tom Riddle's diary. The diary was with Ginny and it forced her to open the Chamber ... | ```python
n = int(input())
a = []
for i in range(n):
b = input()
if b in a:
print('Yes')
else:
print('No')
a.append(b)
``` | 3 | |
616 | E | Sum of Remainders | PROGRAMMING | 2,200 | [
"implementation",
"math",
"number theory"
] | null | null | Calculate the value of the sum: *n* mod 1 + *n* mod 2 + *n* mod 3 + ... + *n* mod *m*. As the result can be very large, you should print the value modulo 109<=+<=7 (the remainder when divided by 109<=+<=7).
The modulo operator *a* mod *b* stands for the remainder after dividing *a* by *b*. For example 10 mod 3 = 1. | The only line contains two integers *n*,<=*m* (1<=≤<=*n*,<=*m*<=≤<=1013) — the parameters of the sum. | Print integer *s* — the value of the required sum modulo 109<=+<=7. | [
"3 4\n",
"4 4\n",
"1 1\n"
] | [
"4\n",
"1\n",
"0\n"
] | none | 0 | [
{
"input": "3 4",
"output": "4"
},
{
"input": "4 4",
"output": "1"
},
{
"input": "1 1",
"output": "0"
},
{
"input": "20000000 10000000",
"output": "176305083"
},
{
"input": "10000000000000 10000000000000",
"output": "869957328"
},
{
"input": "1 1000000... | 1,676,602,788 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 3 | 2,000 | 0 | n,m=map(int,input().split())
co=0
for t in range(m):
co+=n%(t+1)
print(co%(10**9+7))
| Title: Sum of Remainders
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Calculate the value of the sum: *n* mod 1 + *n* mod 2 + *n* mod 3 + ... + *n* mod *m*. As the result can be very large, you should print the value modulo 109<=+<=7 (the remainder when divided by 109<=+<=7).
The modul... | ```python
n,m=map(int,input().split())
co=0
for t in range(m):
co+=n%(t+1)
print(co%(10**9+7))
``` | 0 | |
797 | C | Minimal string | PROGRAMMING | 1,700 | [
"data structures",
"greedy",
"strings"
] | null | null | Petya recieved a gift of a string *s* with length up to 105 characters for his birthday. He took two more empty strings *t* and *u* and decided to play a game. This game has two possible moves:
- Extract the first character of *s* and append *t* with this character. - Extract the last character of *t* and append *u*... | First line contains non-empty string *s* (1<=≤<=|*s*|<=≤<=105), consisting of lowercase English letters. | Print resulting string *u*. | [
"cab\n",
"acdb\n"
] | [
"abc\n",
"abdc\n"
] | none | 0 | [
{
"input": "cab",
"output": "abc"
},
{
"input": "acdb",
"output": "abdc"
},
{
"input": "a",
"output": "a"
},
{
"input": "ab",
"output": "ab"
},
{
"input": "ba",
"output": "ab"
},
{
"input": "dijee",
"output": "deeji"
},
{
"input": "bhrmc",
... | 1,586,099,537 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 8 | 108 | 307,200 | s = input()
t = [s[0]]
u = ""
for i in range(1,len(s)):
if s[i] <= t[-1]:
t.append(s[i])
else:
flag = False
for j in range(i+1, len(s)):
if s[j] < t[-1]:
flag = True
break
if len(t) != 0 and flag == False:
... | Title: Minimal string
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya recieved a gift of a string *s* with length up to 105 characters for his birthday. He took two more empty strings *t* and *u* and decided to play a game. This game has two possible moves:
- Extract the first char... | ```python
s = input()
t = [s[0]]
u = ""
for i in range(1,len(s)):
if s[i] <= t[-1]:
t.append(s[i])
else:
flag = False
for j in range(i+1, len(s)):
if s[j] < t[-1]:
flag = True
break
if len(t) != 0 and flag ... | 0 | |
134 | A | Average Numbers | PROGRAMMING | 1,200 | [
"brute force",
"implementation"
] | null | null | You are given a sequence of positive integers *a*1,<=*a*2,<=...,<=*a**n*. Find all such indices *i*, that the *i*-th element equals the arithmetic mean of all other elements (that is all elements except for this one). | The first line contains the integer *n* (2<=≤<=*n*<=≤<=2·105). The second line contains elements of the sequence *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=1000). All the elements are positive integers. | Print on the first line the number of the sought indices. Print on the second line the sought indices in the increasing order. All indices are integers from 1 to *n*.
If the sought elements do not exist, then the first output line should contain number 0. In this case you may either not print the second line or print ... | [
"5\n1 2 3 4 5\n",
"4\n50 50 50 50\n"
] | [
"1\n3 ",
"4\n1 2 3 4 "
] | none | 500 | [
{
"input": "5\n1 2 3 4 5",
"output": "1\n3 "
},
{
"input": "4\n50 50 50 50",
"output": "4\n1 2 3 4 "
},
{
"input": "3\n2 3 1",
"output": "1\n1 "
},
{
"input": "2\n4 2",
"output": "0"
},
{
"input": "2\n1 1",
"output": "2\n1 2 "
},
{
"input": "10\n3 3 3 ... | 1,570,292,882 | 2,147,483,647 | Python 3 | OK | TESTS | 58 | 296 | 19,046,400 | import sys
S = sys.stdin.read()
S = [int(x) for x in S.split('\n')[1].split()]
s = sum(S)
n = len(S)
T = [i+1 for i in range(n) if n*S[i] == s]
print(len(T))
print(' '.join([str(x) for x in T]))
| Title: Average Numbers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a sequence of positive integers *a*1,<=*a*2,<=...,<=*a**n*. Find all such indices *i*, that the *i*-th element equals the arithmetic mean of all other elements (that is all elements except for this one).
... | ```python
import sys
S = sys.stdin.read()
S = [int(x) for x in S.split('\n')[1].split()]
s = sum(S)
n = len(S)
T = [i+1 for i in range(n) if n*S[i] == s]
print(len(T))
print(' '.join([str(x) for x in T]))
``` | 3 | |
61 | A | Ultra-Fast Mathematician | PROGRAMMING | 800 | [
"implementation"
] | A. Ultra-Fast Mathematician | 2 | 256 | Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 1018 numbers in a single second.
One day in 230 AD Shapur was trying to find out if any one can possibly do... | There are two lines in each input. Each of them contains a single number. It is guaranteed that the numbers are made from 0 and 1 only and that their length is same. The numbers may start with 0. The length of each number doesn't exceed 100. | Write one line — the corresponding answer. Do not omit the leading 0s. | [
"1010100\n0100101\n",
"000\n111\n",
"1110\n1010\n",
"01110\n01100\n"
] | [
"1110001\n",
"111\n",
"0100\n",
"00010\n"
] | none | 500 | [
{
"input": "1010100\n0100101",
"output": "1110001"
},
{
"input": "000\n111",
"output": "111"
},
{
"input": "1110\n1010",
"output": "0100"
},
{
"input": "01110\n01100",
"output": "00010"
},
{
"input": "011101\n000001",
"output": "011100"
},
{
"input": "... | 1,674,466,646 | 2,147,483,647 | Python 3 | OK | TESTS | 102 | 46 | 0 | a=input()
b=input()
r=""
n=len(b)
for i in range(n):
if((a[i]=='1' and b[i]=='0')or(a[i]=='0' and b[i]=='1')):
r+='1'
else:
r+='0'
print(r) | Title: Ultra-Fast Mathematician
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 10... | ```python
a=input()
b=input()
r=""
n=len(b)
for i in range(n):
if((a[i]=='1' and b[i]=='0')or(a[i]=='0' and b[i]=='1')):
r+='1'
else:
r+='0'
print(r)
``` | 3.9885 |
194 | A | Exams | PROGRAMMING | 900 | [
"implementation",
"math"
] | null | null | One day the Codeforces round author sat exams. He had *n* exams and he needed to get an integer from 2 to 5 for each exam. He will have to re-sit each failed exam, i.e. the exam that gets mark 2.
The author would need to spend too much time and effort to make the sum of his marks strictly more than *k*. That could ha... | The single input line contains space-separated integers *n* and *k* (1<=≤<=*n*<=≤<=50, 1<=≤<=*k*<=≤<=250) — the number of exams and the required sum of marks.
It is guaranteed that there exists a way to pass *n* exams in the way that makes the sum of marks equal exactly *k*. | Print the single number — the minimum number of exams that the author will get a 2 for, considering that the sum of marks for all exams must equal *k*. | [
"4 8\n",
"4 10\n",
"1 3\n"
] | [
"4\n",
"2\n",
"0\n"
] | In the first sample the author has to get a 2 for all his exams.
In the second sample he should get a 3 for two exams and a 2 for two more.
In the third sample he should get a 3 for one exam. | 500 | [
{
"input": "4 8",
"output": "4"
},
{
"input": "4 10",
"output": "2"
},
{
"input": "1 3",
"output": "0"
},
{
"input": "1 2",
"output": "1"
},
{
"input": "4 9",
"output": "3"
},
{
"input": "50 234",
"output": "0"
},
{
"input": "50 100",
"... | 1,643,983,804 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 5 | 154 | 0 | import math
n,k=[int(x) for x in input().split()]
c=n*2
d=0
if c==k:
print(n)
else:
d=k-c
print(n-d)
| Title: Exams
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day the Codeforces round author sat exams. He had *n* exams and he needed to get an integer from 2 to 5 for each exam. He will have to re-sit each failed exam, i.e. the exam that gets mark 2.
The author would need to spend ... | ```python
import math
n,k=[int(x) for x in input().split()]
c=n*2
d=0
if c==k:
print(n)
else:
d=k-c
print(n-d)
``` | 0 | |
397 | A | On Segment's Own Points | PROGRAMMING | 0 | [
"implementation"
] | null | null | Our old friend Alexey has finally entered the University of City N — the Berland capital. Alexey expected his father to get him a place to live in but his father said it was high time for Alexey to practice some financial independence. So, Alexey is living in a dorm.
The dorm has exactly one straight dryer — a 100 ce... | The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100). The (*i*<=+<=1)-th line contains integers *l**i* and *r**i* (0<=≤<=*l**i*<=<<=*r**i*<=≤<=100) — the endpoints of the corresponding segment for the *i*-th student. | On a single line print a single number *k*, equal to the sum of lengths of the parts of the dryer which are inside Alexey's segment and are outside all other segments. | [
"3\n0 5\n2 8\n1 6\n",
"3\n0 10\n1 5\n7 15\n"
] | [
"1\n",
"3\n"
] | Note that it's not important are clothes drying on the touching segments (e.g. (0, 1) and (1, 2)) considered to be touching or not because you need to find the length of segments.
In the first test sample Alexey may use the only segment (0, 1). In such case his clothes will not touch clothes on the segments (1, 6) and... | 500 | [
{
"input": "3\n0 5\n2 8\n1 6",
"output": "1"
},
{
"input": "3\n0 10\n1 5\n7 15",
"output": "3"
},
{
"input": "1\n0 100",
"output": "100"
},
{
"input": "2\n1 9\n1 9",
"output": "0"
},
{
"input": "2\n1 9\n5 10",
"output": "4"
},
{
"input": "2\n1 9\n3 5",... | 1,461,238,943 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 93 | 6,144,000 | from sys import setrecursionlimit, exit, stdin
from math import ceil, floor, acos, pi
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from functools import reduce
import itertools
setrecursionlimit(10**7)
RI=lambda x=' ': list(map(int,input().split(x)))
RS=lambda x=' ': input().rst... | Title: On Segment's Own Points
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Our old friend Alexey has finally entered the University of City N — the Berland capital. Alexey expected his father to get him a place to live in but his father said it was high time for Alexey to practice some... | ```python
from sys import setrecursionlimit, exit, stdin
from math import ceil, floor, acos, pi
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from functools import reduce
import itertools
setrecursionlimit(10**7)
RI=lambda x=' ': list(map(int,input().split(x)))
RS=lambda x=' ': i... | 0 | |
0 | none | none | none | 0 | [
"none"
] | null | null | Appleman and Toastman play a game. Initially Appleman gives one group of *n* numbers to the Toastman, then they start to complete the following tasks:
- Each time Toastman gets a group of numbers, he sums up all the numbers and adds this sum to the score. Then he gives the group to the Appleman. - Each time Appleman... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=3·105). The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=106) — the initial group that is given to Toastman. | Print a single integer — the largest possible score. | [
"3\n3 1 5\n",
"1\n10\n"
] | [
"26\n",
"10\n"
] | Consider the following situation in the first example. Initially Toastman gets group [3, 1, 5] and adds 9 to the score, then he give the group to Appleman. Appleman splits group [3, 1, 5] into two groups: [3, 5] and [1]. Both of them should be given to Toastman. When Toastman receives group [1], he adds 1 to score and ... | 0 | [
{
"input": "3\n3 1 5",
"output": "26"
},
{
"input": "1\n10",
"output": "10"
},
{
"input": "10\n8 10 2 5 6 2 4 7 2 1",
"output": "376"
},
{
"input": "10\n171308 397870 724672 431255 228496 892002 542924 718337 888642 161821",
"output": "40204082"
},
{
"input": "10\... | 1,411,547,364 | 5,064 | Python 3 | RUNTIME_ERROR | TESTS | 6 | 62 | 3,993,600 | n = int(input())
m = [0 for i in range(n)]
str = input()
h = str.split(sep=None, maxsplit=10)
for i in range(n):
m[i] = int(h[i])
m.sort(key=None, reverse=False)
result = 0
if(n>1):
for i in range(len(m)):
result += m[i]*(i+2)
result -= m[len(m)-1]
else:
result = m[0]
print(result) | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Appleman and Toastman play a game. Initially Appleman gives one group of *n* numbers to the Toastman, then they start to complete the following tasks:
- Each time Toastman gets a group of numbers, he sums up all the numbers and ... | ```python
n = int(input())
m = [0 for i in range(n)]
str = input()
h = str.split(sep=None, maxsplit=10)
for i in range(n):
m[i] = int(h[i])
m.sort(key=None, reverse=False)
result = 0
if(n>1):
for i in range(len(m)):
result += m[i]*(i+2)
result -= m[len(m)-1]
else:
result = m[0]
pri... | -1 | |
625 | A | Guest From the Past | PROGRAMMING | 1,700 | [
"implementation",
"math"
] | null | null | Kolya Gerasimov loves kefir very much. He lives in year 1984 and knows all the details of buying this delicious drink. One day, as you probably know, he found himself in year 2084, and buying kefir there is much more complicated.
Kolya is hungry, so he went to the nearest milk shop. In 2084 you may buy kefir in a plas... | First line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=1018) — the number of rubles Kolya has at the beginning.
Then follow three lines containing integers *a*, *b* and *c* (1<=≤<=*a*<=≤<=1018, 1<=≤<=*c*<=<<=*b*<=≤<=1018) — the cost of one plastic liter bottle, the cost of one glass liter bottle and t... | Print the only integer — maximum number of liters of kefir, that Kolya can drink. | [
"10\n11\n9\n8\n",
"10\n5\n6\n1\n"
] | [
"2\n",
"2\n"
] | In the first sample, Kolya can buy one glass bottle, then return it and buy one more glass bottle. Thus he will drink 2 liters of kefir.
In the second sample, Kolya can buy two plastic bottle and get two liters of kefir, or he can buy one liter glass bottle, then return it and buy one plastic bottle. In both cases he ... | 750 | [
{
"input": "10\n11\n9\n8",
"output": "2"
},
{
"input": "10\n5\n6\n1",
"output": "2"
},
{
"input": "2\n2\n2\n1",
"output": "1"
},
{
"input": "10\n3\n3\n1",
"output": "4"
},
{
"input": "10\n1\n2\n1",
"output": "10"
},
{
"input": "10\n2\n3\n1",
"outpu... | 1,461,192,145 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 10 | 62 | 5,120,000 | import math
n = int(input())
a = int(input())
b = int(input())
c = int(input())
if a < b:
print(math.floor(n / a))
else:
if n - math.floor((n - b) / (b - c)) * (b - c) >= b:
print(math.floor((n - b) / (b - c)) + 1)
else:
print(math.floor((n - b) / (b - c)))
| Title: Guest From the Past
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Kolya Gerasimov loves kefir very much. He lives in year 1984 and knows all the details of buying this delicious drink. One day, as you probably know, he found himself in year 2084, and buying kefir there is much mor... | ```python
import math
n = int(input())
a = int(input())
b = int(input())
c = int(input())
if a < b:
print(math.floor(n / a))
else:
if n - math.floor((n - b) / (b - c)) * (b - c) >= b:
print(math.floor((n - b) / (b - c)) + 1)
else:
print(math.floor((n - b) / (b - c)))
``` | 0 | |
598 | A | Tricky Sum | PROGRAMMING | 900 | [
"math"
] | null | null | In this problem you are to calculate the sum of all integers from 1 to *n*, but you should take all powers of two with minus in the sum.
For example, for *n*<==<=4 the sum is equal to <=-<=1<=-<=2<=+<=3<=-<=4<==<=<=-<=4, because 1, 2 and 4 are 20, 21 and 22 respectively.
Calculate the answer for *t* values of *n*. | The first line of the input contains a single integer *t* (1<=≤<=*t*<=≤<=100) — the number of values of *n* to be processed.
Each of next *t* lines contains a single integer *n* (1<=≤<=*n*<=≤<=109). | Print the requested sum for each of *t* integers *n* given in the input. | [
"2\n4\n1000000000\n"
] | [
"-4\n499999998352516354\n"
] | The answer for the first sample is explained in the statement. | 0 | [
{
"input": "2\n4\n1000000000",
"output": "-4\n499999998352516354"
},
{
"input": "10\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10",
"output": "-1\n-3\n0\n-4\n1\n7\n14\n6\n15\n25"
},
{
"input": "10\n10\n9\n47\n33\n99\n83\n62\n1\n100\n53",
"output": "25\n15\n1002\n435\n4696\n3232\n1827\n-1\n4796\n130... | 1,698,299,505 | 2,147,483,647 | PyPy 3 | OK | TESTS | 21 | 93 | 1,331,200 |
for _ in range(int(input())):
n = int(input())
s = ((1 + n)*n) // 2
p = 1
while p <= n:
s -= p*2
p *= 2
print(str(s))
| Title: Tricky Sum
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In this problem you are to calculate the sum of all integers from 1 to *n*, but you should take all powers of two with minus in the sum.
For example, for *n*<==<=4 the sum is equal to <=-<=1<=-<=2<=+<=3<=-<=4<==<=<=-<=4, be... | ```python
for _ in range(int(input())):
n = int(input())
s = ((1 + n)*n) // 2
p = 1
while p <= n:
s -= p*2
p *= 2
print(str(s))
``` | 3 | |
180 | F | Mathematical Analysis Rocks! | PROGRAMMING | 1,200 | [
"constructive algorithms",
"implementation",
"math"
] | null | null | Students of group 199 have written their lectures dismally. Now an exam on Mathematical Analysis is approaching and something has to be done asap (that is, quickly). Let's number the students of the group from 1 to *n*. Each student *i* (1<=≤<=*i*<=≤<=*n*) has a best friend *p*[*i*] (1<=≤<=*p*[*i*]<=≤<=*n*). In fact, e... | The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of students in the group. The second line contains sequence of different integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*n*). The third line contains the sequence of different integers *b*1,<=*b*2,<=...,<=*b**n* (1<=≤<=*b**i*<=≤<=*n*). | Print sequence *n* of different integers *p*[1],<=*p*[2],<=...,<=*p*[*n*] (1<=≤<=*p*[*i*]<=≤<=*n*). It is guaranteed that the solution exists and that it is unique. | [
"4\n2 1 4 3\n3 4 2 1\n",
"5\n5 2 3 1 4\n1 3 2 4 5\n",
"2\n1 2\n2 1\n"
] | [
"4 3 1 2 ",
"4 3 2 5 1 ",
"2 1 "
] | none | 0 | [
{
"input": "4\n2 1 4 3\n3 4 2 1",
"output": "4 3 1 2 "
},
{
"input": "5\n5 2 3 1 4\n1 3 2 4 5",
"output": "4 3 2 5 1 "
},
{
"input": "2\n1 2\n2 1",
"output": "2 1 "
},
{
"input": "1\n1\n1",
"output": "1 "
},
{
"input": "2\n1 2\n1 2",
"output": "1 2 "
},
{
... | 1,656,148,542 | 2,147,483,647 | PyPy 3 | OK | TESTS | 40 | 996 | 15,052,800 |
import sys
input = sys.stdin.readline
n = int(input())
w = list(map(int, input().split()))
s = list(map(int, input().split()))
d = [j for i, j in sorted(zip(w, s))]
print(' '.join(map(str, d))) | Title: Mathematical Analysis Rocks!
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Students of group 199 have written their lectures dismally. Now an exam on Mathematical Analysis is approaching and something has to be done asap (that is, quickly). Let's number the students of the group f... | ```python
import sys
input = sys.stdin.readline
n = int(input())
w = list(map(int, input().split()))
s = list(map(int, input().split()))
d = [j for i, j in sorted(zip(w, s))]
print(' '.join(map(str, d)))
``` | 3 | |
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 od... | 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 t... | 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... | 1,685,162,329 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 62 | 0 | n, m = input().split()
n=int(n)
m=int(m)
l = list(map(int,input().split()))
l.sort()
ans = 1001
for i in range(m-n):
cur = l[i+n-1]-l[i]
if ans > cur:
ans=cur
print(ans)
| 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, a... | ```python
n, m = input().split()
n=int(n)
m=int(m)
l = list(map(int,input().split()))
l.sort()
ans = 1001
for i in range(m-n):
cur = l[i+n-1]-l[i]
if ans > cur:
ans=cur
print(ans)
``` | 0 | |
257 | A | Sockets | PROGRAMMING | 1,100 | [
"greedy",
"implementation",
"sortings"
] | null | null | Vasya has got many devices that work on electricity. He's got *n* supply-line filters to plug the devices, the *i*-th supply-line filter has *a**i* sockets.
Overall Vasya has got *m* devices and *k* electrical sockets in his flat, he can plug the devices or supply-line filters directly. Of course, he can plug the supp... | The first line contains three integers *n*, *m*, *k* (1<=≤<=*n*,<=*m*,<=*k*<=≤<=50) — the number of supply-line filters, the number of devices and the number of sockets that he can plug to directly, correspondingly. The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=50) —... | Print a single number — the minimum number of supply-line filters that is needed to plug all the devices to electricity. If it is impossible to plug all the devices even using all the supply-line filters, print -1. | [
"3 5 3\n3 1 2\n",
"4 7 2\n3 3 2 4\n",
"5 5 1\n1 3 1 2 1\n"
] | [
"1\n",
"2\n",
"-1\n"
] | In the first test case he can plug the first supply-line filter directly to electricity. After he plug it, he get 5 (3 on the supply-line filter and 2 remaining sockets for direct plugging) available sockets to plug. Thus, one filter is enough to plug 5 devices.
One of the optimal ways in the second test sample is to ... | 500 | [
{
"input": "3 5 3\n3 1 2",
"output": "1"
},
{
"input": "4 7 2\n3 3 2 4",
"output": "2"
},
{
"input": "5 5 1\n1 3 1 2 1",
"output": "-1"
},
{
"input": "4 5 8\n3 2 4 3",
"output": "0"
},
{
"input": "5 10 1\n4 3 4 2 4",
"output": "3"
},
{
"input": "7 13 2... | 1,654,923,617 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 62 | 0 | n, m = map(int, input().split())
a = list(map(int, input().split()))
minus = a.count(-1)
pluss = a.count(1)
for i in range(m):
l, r = map(int, input().split())
if((r-l)%2==0):
print(0)
else:
value = (r-l)+1
d = value//2
if(d<=minus and d<=pluss):
pri... | Title: Sockets
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya has got many devices that work on electricity. He's got *n* supply-line filters to plug the devices, the *i*-th supply-line filter has *a**i* sockets.
Overall Vasya has got *m* devices and *k* electrical sockets in his f... | ```python
n, m = map(int, input().split())
a = list(map(int, input().split()))
minus = a.count(-1)
pluss = a.count(1)
for i in range(m):
l, r = map(int, input().split())
if((r-l)%2==0):
print(0)
else:
value = (r-l)+1
d = value//2
if(d<=minus and d<=pluss):
... | -1 | |
0 | none | none | none | 0 | [
"none"
] | null | null | Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Petya has two strings *a* and *b* of the same length *n*. The strings consist only of lucky digits... | The first and the second line contains strings *a* and *b*, correspondingly. Strings *a* and *b* have equal lengths and contain only lucky digits. The strings are not empty, their length does not exceed 105. | Print on the single line the single number — the minimum number of operations needed to convert string *a* into string *b*. | [
"47\n74\n",
"774\n744\n",
"777\n444\n"
] | [
"1\n",
"1\n",
"3\n"
] | In the first sample it is enough simply to swap the first and the second digit.
In the second sample we should replace the second digit with its opposite.
In the third number we should replace all three digits with their opposites. | 0 | [
{
"input": "47\n74",
"output": "1"
},
{
"input": "774\n744",
"output": "1"
},
{
"input": "777\n444",
"output": "3"
},
{
"input": "74747474\n77777777",
"output": "4"
},
{
"input": "444444444444\n777777777777",
"output": "12"
},
{
"input": "4744744447774... | 1,630,903,447 | 2,147,483,647 | Python 3 | OK | TESTS | 51 | 186 | 7,168,000 | a=input()
b=input()
f=0
s=0
for i in range(len(a)):
if a[i]!=b[i]:
if a[i]=="4":
f+=1
else:
s+=1
print(max(s,f)) | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Petya ha... | ```python
a=input()
b=input()
f=0
s=0
for i in range(len(a)):
if a[i]!=b[i]:
if a[i]=="4":
f+=1
else:
s+=1
print(max(s,f))
``` | 3 | |
707 | A | Brain's Photos | PROGRAMMING | 800 | [
"implementation"
] | null | null | Small, but very brave, mouse Brain was not accepted to summer school of young villains. He was upset and decided to postpone his plans of taking over the world, but to become a photographer instead.
As you may know, the coolest photos are on the film (because you can specify the hashtag #film for such).
Brain took a ... | The first line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of photo pixel matrix rows and columns respectively.
Then *n* lines describing matrix rows follow. Each of them contains *m* space-separated characters describing colors of pixels in a row. Each character in the line i... | Print the "#Black&White" (without quotes), if the photo is black-and-white and "#Color" (without quotes), if it is colored, in the only line. | [
"2 2\nC M\nY Y\n",
"3 2\nW W\nW W\nB B\n",
"1 1\nW\n"
] | [
"#Color",
"#Black&White",
"#Black&White"
] | none | 500 | [
{
"input": "2 2\nC M\nY Y",
"output": "#Color"
},
{
"input": "3 2\nW W\nW W\nB B",
"output": "#Black&White"
},
{
"input": "1 1\nW",
"output": "#Black&White"
},
{
"input": "2 3\nW W W\nB G Y",
"output": "#Color"
},
{
"input": "1 1\nW",
"output": "#Black&White"
... | 1,655,475,563 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 6 | 46 | 0 | n, m = map(int, input().split())
for i in range(n):
color = list(map(str, input().split()))
if color[m-1]=="W" or color[m-1]=="G" or color[m-1]=="B":
print("#Black&White")
else:
print("#Color") | Title: Brain's Photos
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Small, but very brave, mouse Brain was not accepted to summer school of young villains. He was upset and decided to postpone his plans of taking over the world, but to become a photographer instead.
As you may know, the... | ```python
n, m = map(int, input().split())
for i in range(n):
color = list(map(str, input().split()))
if color[m-1]=="W" or color[m-1]=="G" or color[m-1]=="B":
print("#Black&White")
else:
print("#Color")
``` | 0 | |
83 | A | Magical Array | PROGRAMMING | 1,300 | [
"math"
] | A. Magical Array | 2 | 256 | Valery is very interested in magic. Magic attracts him so much that he sees it everywhere. He explains any strange and weird phenomenon through intervention of supernatural forces. But who would have thought that even in a regular array of numbers Valera manages to see something beautiful and magical.
Valera absolutel... | The first line of the input data contains an integer *n* (1<=≤<=*n*<=≤<=105). The second line contains an array of original integers *a*1,<=*a*2,<=...,<=*a**n* (<=-<=109<=≤<=*a**i*<=≤<=109). | Print on the single line the answer to the problem: the amount of subarrays, which are magical.
Please do not use the %lld specificator to read or write 64-bit numbers in C++. It is recommended to use cin, cout streams (you can also use the %I64d specificator). | [
"4\n2 1 1 4\n",
"5\n-2 -2 -2 0 1\n"
] | [
"5\n",
"8\n"
] | Notes to sample tests:
Magical subarrays are shown with pairs of indices [a;b] of the beginning and the end.
In the first sample: [1;1], [2;2], [3;3], [4;4], [2;3].
In the second sample: [1;1], [2;2], [3;3], [4;4], [5;5], [1;2], [2;3], [1;3]. | 500 | [
{
"input": "4\n2 1 1 4",
"output": "5"
},
{
"input": "5\n-2 -2 -2 0 1",
"output": "8"
},
{
"input": "1\n10",
"output": "1"
},
{
"input": "2\n5 6",
"output": "2"
},
{
"input": "5\n5 5 4 5 5",
"output": "7"
},
{
"input": "8\n1 2 0 0 0 0 3 3",
"output... | 1,623,997,756 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 4 | 124 | 0 | # -*- coding: utf-8 -*-
"""Untitled65.ipynb
Automatically generated by Colaboratory.
Original file is located at
https://colab.research.google.com/drive/1kH9gF2Sz0uEW-8MC5Exb7nZuB4f5BTlb
"""
n=int(input())
l1=list(map(int,input().split()))
def set(n):
c=0
for i in range(0,n):
c=c+(n-i)
return(c)
l2=[]
... | Title: Magical Array
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Valery is very interested in magic. Magic attracts him so much that he sees it everywhere. He explains any strange and weird phenomenon through intervention of supernatural forces. But who would have thought that even in a re... | ```python
# -*- coding: utf-8 -*-
"""Untitled65.ipynb
Automatically generated by Colaboratory.
Original file is located at
https://colab.research.google.com/drive/1kH9gF2Sz0uEW-8MC5Exb7nZuB4f5BTlb
"""
n=int(input())
l1=list(map(int,input().split()))
def set(n):
c=0
for i in range(0,n):
c=c+(n-i)
return... | -1 |
484 | A | Bits | PROGRAMMING | 1,700 | [
"bitmasks",
"constructive algorithms"
] | null | null | Let's denote as the number of bits set ('1' bits) in the binary representation of the non-negative integer *x*.
You are given multiple queries consisting of pairs of integers *l* and *r*. For each query, find the *x*, such that *l*<=≤<=*x*<=≤<=*r*, and is maximum possible. If there are multiple such numbers find the... | The first line contains integer *n* — the number of queries (1<=≤<=*n*<=≤<=10000).
Each of the following *n* lines contain two integers *l**i*,<=*r**i* — the arguments for the corresponding query (0<=≤<=*l**i*<=≤<=*r**i*<=≤<=1018). | For each query print the answer in a separate line. | [
"3\n1 2\n2 4\n1 10\n"
] | [
"1\n3\n7\n"
] | The binary representations of numbers from 1 to 10 are listed below:
1<sub class="lower-index">10</sub> = 1<sub class="lower-index">2</sub>
2<sub class="lower-index">10</sub> = 10<sub class="lower-index">2</sub>
3<sub class="lower-index">10</sub> = 11<sub class="lower-index">2</sub>
4<sub class="lower-index">10</su... | 500 | [
{
"input": "3\n1 2\n2 4\n1 10",
"output": "1\n3\n7"
},
{
"input": "55\n1 1\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n2 2\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n2 9\n2 10\n3 3\n3 4\n3 5\n3 6\n3 7\n3 8\n3 9\n3 10\n4 4\n4 5\n4 6\n4 7\n4 8\n4 9\n4 10\n5 5\n5 6\n5 7\n5 8\n5 9\n5 10\n6 6\n6 7\n6 8\n6 9\n6 10... | 1,568,732,123 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 109 | 0 | n = int(input())
max=0
for i in range(n):
l, r = map(int, input().split(" "))
for j in range(l, r+1):
aux = bin(j)[2:]
ones = aux.count("1")
if(ones > max):
max = ones
ans = j
print(ans)
| Title: Bits
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Let's denote as the number of bits set ('1' bits) in the binary representation of the non-negative integer *x*.
You are given multiple queries consisting of pairs of integers *l* and *r*. For each query, find the *x*, such that ... | ```python
n = int(input())
max=0
for i in range(n):
l, r = map(int, input().split(" "))
for j in range(l, r+1):
aux = bin(j)[2:]
ones = aux.count("1")
if(ones > max):
max = ones
ans = j
print(ans)
``` | 0 | |
61 | A | Ultra-Fast Mathematician | PROGRAMMING | 800 | [
"implementation"
] | A. Ultra-Fast Mathematician | 2 | 256 | Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 1018 numbers in a single second.
One day in 230 AD Shapur was trying to find out if any one can possibly do... | There are two lines in each input. Each of them contains a single number. It is guaranteed that the numbers are made from 0 and 1 only and that their length is same. The numbers may start with 0. The length of each number doesn't exceed 100. | Write one line — the corresponding answer. Do not omit the leading 0s. | [
"1010100\n0100101\n",
"000\n111\n",
"1110\n1010\n",
"01110\n01100\n"
] | [
"1110001\n",
"111\n",
"0100\n",
"00010\n"
] | none | 500 | [
{
"input": "1010100\n0100101",
"output": "1110001"
},
{
"input": "000\n111",
"output": "111"
},
{
"input": "1110\n1010",
"output": "0100"
},
{
"input": "01110\n01100",
"output": "00010"
},
{
"input": "011101\n000001",
"output": "011100"
},
{
"input": "... | 1,592,817,342 | 2,147,483,647 | PyPy 3 | OK | TESTS | 102 | 171 | 0 | x=input()
y=input()
a=[]
for i in range (len(x)):
z=int(x[i])^int(y[i])
a.append(z)
print("".join(str(elem) for elem in a)) | Title: Ultra-Fast Mathematician
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 10... | ```python
x=input()
y=input()
a=[]
for i in range (len(x)):
z=int(x[i])^int(y[i])
a.append(z)
print("".join(str(elem) for elem in a))
``` | 3.95725 |
893 | C | Rumor | PROGRAMMING | 1,300 | [
"dfs and similar",
"graphs",
"greedy"
] | null | null | Vova promised himself that he would never play computer games... But recently Firestorm — a well-known game developing company — published their newest game, World of Farcraft, and it became really popular. Of course, Vova started playing it.
Now he tries to solve a quest. The task is to come to a settlement named Ove... | The first line contains two integer numbers *n* and *m* (1<=≤<=*n*<=≤<=105,<=0<=≤<=*m*<=≤<=105) — the number of characters in Overcity and the number of pairs of friends.
The second line contains *n* integer numbers *c**i* (0<=≤<=*c**i*<=≤<=109) — the amount of gold *i*-th character asks to start spreading the rumor.
... | Print one number — the minimum amount of gold Vova has to spend in order to finish the quest. | [
"5 2\n2 5 3 4 8\n1 4\n4 5\n",
"10 0\n1 2 3 4 5 6 7 8 9 10\n",
"10 5\n1 6 2 7 3 8 4 9 5 10\n1 2\n3 4\n5 6\n7 8\n9 10\n"
] | [
"10\n",
"55\n",
"15\n"
] | In the first example the best decision is to bribe the first character (he will spread the rumor to fourth character, and the fourth one will spread it to fifth). Also Vova has to bribe the second and the third characters, so they know the rumor.
In the second example Vova has to bribe everyone.
In the third example ... | 0 | [
{
"input": "5 2\n2 5 3 4 8\n1 4\n4 5",
"output": "10"
},
{
"input": "10 0\n1 2 3 4 5 6 7 8 9 10",
"output": "55"
},
{
"input": "10 5\n1 6 2 7 3 8 4 9 5 10\n1 2\n3 4\n5 6\n7 8\n9 10",
"output": "15"
},
{
"input": "1 0\n0",
"output": "0"
},
{
"input": "1 0\n10000000... | 1,631,632,054 | 2,147,483,647 | PyPy 3 | RUNTIME_ERROR | TESTS | 3 | 998 | 36,966,400 |
n,m = map(int,input().split())
t= list(map(int,input().split()))
adj=[[] for i in range(n)]
if set(t)==(0):
print(0)
else:
for i in range(m):
a,b = map(int,input().split())
a-=1
b-=1
adj[a].append(b)
adj[b].append(a)
def dfs(node,... | Title: Rumor
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vova promised himself that he would never play computer games... But recently Firestorm — a well-known game developing company — published their newest game, World of Farcraft, and it became really popular. Of course, Vova starte... | ```python
n,m = map(int,input().split())
t= list(map(int,input().split()))
adj=[[] for i in range(n)]
if set(t)==(0):
print(0)
else:
for i in range(m):
a,b = map(int,input().split())
a-=1
b-=1
adj[a].append(b)
adj[b].append(a)
def... | -1 | |
381 | A | Sereja and Dima | PROGRAMMING | 800 | [
"greedy",
"implementation",
"two pointers"
] | null | null | Sereja and Dima play a game. The rules of the game are very simple. The players have *n* cards in a row. Each card contains a number, all numbers on the cards are distinct. The players take turns, Sereja moves first. During his turn a player can take one card: either the leftmost card in a row, or the rightmost one. Th... | The first line contains integer *n* (1<=≤<=*n*<=≤<=1000) — the number of cards on the table. The second line contains space-separated numbers on the cards from left to right. The numbers on the cards are distinct integers from 1 to 1000. | On a single line, print two integers. The first number is the number of Sereja's points at the end of the game, the second number is the number of Dima's points at the end of the game. | [
"4\n4 1 2 10\n",
"7\n1 2 3 4 5 6 7\n"
] | [
"12 5\n",
"16 12\n"
] | In the first sample Sereja will take cards with numbers 10 and 2, so Sereja's sum is 12. Dima will take cards with numbers 4 and 1, so Dima's sum is 5. | 500 | [
{
"input": "4\n4 1 2 10",
"output": "12 5"
},
{
"input": "7\n1 2 3 4 5 6 7",
"output": "16 12"
},
{
"input": "42\n15 29 37 22 16 5 26 31 6 32 19 3 45 36 33 14 25 20 48 7 42 11 24 28 9 18 8 21 47 17 38 40 44 4 35 1 43 39 41 27 12 13",
"output": "613 418"
},
{
"input": "43\n32 ... | 1,685,203,514 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 34 | 77 | 0 | number_of_elems = int(input())
cards = list(map(int, input().split()))
sereja_score = 0
dima_score = 0
for i in range(number_of_elems):
if i % 2 == 0:
if cards[-1] > cards[0]:
sereja_score += cards[-1]
cards.remove(cards[-1])
elif cards[-1] == cards[0]:
... | Title: Sereja and Dima
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Sereja and Dima play a game. The rules of the game are very simple. The players have *n* cards in a row. Each card contains a number, all numbers on the cards are distinct. The players take turns, Sereja moves first. Du... | ```python
number_of_elems = int(input())
cards = list(map(int, input().split()))
sereja_score = 0
dima_score = 0
for i in range(number_of_elems):
if i % 2 == 0:
if cards[-1] > cards[0]:
sereja_score += cards[-1]
cards.remove(cards[-1])
elif cards[-1] == cards[0]:
... | 3 | |
952 | B | A Map of the Cat | PROGRAMMING | 1,900 | [
"brute force",
"interactive"
] | null | null | If you have ever interacted with a cat, you have probably noticed that they are quite particular about how to pet them. Here is an approximate map of a normal cat.
However, some cats won't tolerate this nonsense from the humans. Here is a map of a grumpy cat.
You have met a cat. Can you figure out whether it's normal... | none | none | [] | [] | Please make sure to use the stream flushing operation after each query in order not to leave part of your output in some buffer. | 0 | [
{
"input": "5 0 1 2 5 3 5 4 5 5",
"output": "Correct answer 'normal'"
},
{
"input": "5 5 5 6 6 7 8 9 10 11",
"output": "Correct answer 'grumpy'"
},
{
"input": "10 6 5 7 5 6 11 5 8 9",
"output": "Correct answer 'grumpy'"
},
{
"input": "7 10 8 9 6 5 5 11 5 6",
"output": "Co... | 1,666,683,650 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 31 | 0 | normal = ["great!", "cool", "not bad", "don't touch me!", "don't think so"]
grumpy = ["Terrrible", "Worse", "Go die in a hole", "Are you serious?"]
for i in range(7):
print(i)
s = input()
if s in normal:
print("normal")
break
elif s in grumpy:
print("grumpy")
br... | Title: A Map of the Cat
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
If you have ever interacted with a cat, you have probably noticed that they are quite particular about how to pet them. Here is an approximate map of a normal cat.
However, some cats won't tolerate this nonsense from ... | ```python
normal = ["great!", "cool", "not bad", "don't touch me!", "don't think so"]
grumpy = ["Terrrible", "Worse", "Go die in a hole", "Are you serious?"]
for i in range(7):
print(i)
s = input()
if s in normal:
print("normal")
break
elif s in grumpy:
print("grumpy")
... | 0 | |
38 | A | Army | PROGRAMMING | 800 | [
"implementation"
] | A. Army | 2 | 256 | The Berland Armed Forces System consists of *n* ranks that are numbered using natural numbers from 1 to *n*, where 1 is the lowest rank and *n* is the highest rank.
One needs exactly *d**i* years to rise from rank *i* to rank *i*<=+<=1. Reaching a certain rank *i* having not reached all the previous *i*<=-<=1 ranks is... | The first input line contains an integer *n* (2<=≤<=*n*<=≤<=100). The second line contains *n*<=-<=1 integers *d**i* (1<=≤<=*d**i*<=≤<=100). The third input line contains two integers *a* and *b* (1<=≤<=*a*<=<<=*b*<=≤<=*n*). The numbers on the lines are space-separated. | Print the single number which is the number of years that Vasya needs to rise from rank *a* to rank *b*. | [
"3\n5 6\n1 2\n",
"3\n5 6\n1 3\n"
] | [
"5\n",
"11\n"
] | none | 0 | [
{
"input": "3\n5 6\n1 2",
"output": "5"
},
{
"input": "3\n5 6\n1 3",
"output": "11"
},
{
"input": "2\n55\n1 2",
"output": "55"
},
{
"input": "3\n85 78\n1 3",
"output": "163"
},
{
"input": "4\n63 4 49\n2 3",
"output": "4"
},
{
"input": "5\n93 83 42 56\n... | 1,694,944,236 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 50 | 124 | 0 | n, ans = int(input()), 0
a = list(map(int , input().split()))
b = list(map(int , input().split()))
for i in range(b[0] - 1, b[1] - 1):
ans += a[i]
print(ans) | Title: Army
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
The Berland Armed Forces System consists of *n* ranks that are numbered using natural numbers from 1 to *n*, where 1 is the lowest rank and *n* is the highest rank.
One needs exactly *d**i* years to rise from rank *i* to rank *i*<=+<... | ```python
n, ans = int(input()), 0
a = list(map(int , input().split()))
b = list(map(int , input().split()))
for i in range(b[0] - 1, b[1] - 1):
ans += a[i]
print(ans)
``` | 3.969 |
609 | A | USB Flash Drives | PROGRAMMING | 800 | [
"greedy",
"implementation",
"sortings"
] | null | null | Sean is trying to save a large file to a USB flash drive. He has *n* USB flash drives with capacities equal to *a*1,<=*a*2,<=...,<=*a**n* megabytes. The file size is equal to *m* megabytes.
Find the minimum number of USB flash drives needed to write Sean's file, if he can split the file between drives. | The first line contains positive integer *n* (1<=≤<=*n*<=≤<=100) — the number of USB flash drives.
The second line contains positive integer *m* (1<=≤<=*m*<=≤<=105) — the size of Sean's file.
Each of the next *n* lines contains positive integer *a**i* (1<=≤<=*a**i*<=≤<=1000) — the sizes of USB flash drives in megabyt... | Print the minimum number of USB flash drives to write Sean's file, if he can split the file between drives. | [
"3\n5\n2\n1\n3\n",
"3\n6\n2\n3\n2\n",
"2\n5\n5\n10\n"
] | [
"2\n",
"3\n",
"1\n"
] | In the first example Sean needs only two USB flash drives — the first and the third.
In the second example Sean needs all three USB flash drives.
In the third example Sean needs only one USB flash drive and he can use any available USB flash drive — the first or the second. | 0 | [
{
"input": "3\n5\n2\n1\n3",
"output": "2"
},
{
"input": "3\n6\n2\n3\n2",
"output": "3"
},
{
"input": "2\n5\n5\n10",
"output": "1"
},
{
"input": "5\n16\n8\n1\n3\n4\n9",
"output": "2"
},
{
"input": "10\n121\n10\n37\n74\n56\n42\n39\n6\n68\n8\n100",
"output": "2"
... | 1,562,538,364 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 109 | 0 | n = int(input())
m = int(input())
l = []
for i in range(n):
a = int(input())
l.append(a)
l = sorted(l, reverse = True)
x = 0
z = 0
for i in l:
x += i
z += 1
if x >= m:
print(z)
break | Title: USB Flash Drives
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Sean is trying to save a large file to a USB flash drive. He has *n* USB flash drives with capacities equal to *a*1,<=*a*2,<=...,<=*a**n* megabytes. The file size is equal to *m* megabytes.
Find the minimum number of... | ```python
n = int(input())
m = int(input())
l = []
for i in range(n):
a = int(input())
l.append(a)
l = sorted(l, reverse = True)
x = 0
z = 0
for i in l:
x += i
z += 1
if x >= m:
print(z)
break
``` | 3 | |
265 | A | Colorful Stones (Simplified Edition) | PROGRAMMING | 800 | [
"implementation"
] | null | null | There is a sequence of colorful stones. The color of each stone is one of red, green, or blue. You are given a string *s*. The *i*-th (1-based) character of *s* represents the color of the *i*-th stone. If the character is "R", "G", or "B", the color of the corresponding stone is red, green, or blue, respectively.
Ini... | The input contains two lines. The first line contains the string *s* (1<=≤<=|*s*|<=≤<=50). The second line contains the string *t* (1<=≤<=|*t*|<=≤<=50). The characters of each string will be one of "R", "G", or "B". It is guaranteed that Liss don't move out of the sequence. | Print the final 1-based position of Liss in a single line. | [
"RGB\nRRR\n",
"RRRBGBRBBB\nBBBRR\n",
"BRRBGBRGRBGRGRRGGBGBGBRGBRGRGGGRBRRRBRBBBGRRRGGBBB\nBBRBGGRGRGBBBRBGRBRBBBBRBRRRBGBBGBBRRBBGGRBRRBRGRB\n"
] | [
"2\n",
"3\n",
"15\n"
] | none | 500 | [
{
"input": "RGB\nRRR",
"output": "2"
},
{
"input": "RRRBGBRBBB\nBBBRR",
"output": "3"
},
{
"input": "BRRBGBRGRBGRGRRGGBGBGBRGBRGRGGGRBRRRBRBBBGRRRGGBBB\nBBRBGGRGRGBBBRBGRBRBBBBRBRRRBGBBGBBRRBBGGRBRRBRGRB",
"output": "15"
},
{
"input": "G\nRRBBRBRRBR",
"output": "1"
},
... | 1,685,836,376 | 2,147,483,647 | Python 3 | OK | TESTS | 19 | 92 | 0 | colorful_stones = input()
instructions = input()
liss_position = 1
for instruction in instructions:
if colorful_stones[liss_position - 1] == instruction:
liss_position += 1
print(liss_position)
| Title: Colorful Stones (Simplified Edition)
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There is a sequence of colorful stones. The color of each stone is one of red, green, or blue. You are given a string *s*. The *i*-th (1-based) character of *s* represents the color of the *i*-th st... | ```python
colorful_stones = input()
instructions = input()
liss_position = 1
for instruction in instructions:
if colorful_stones[liss_position - 1] == instruction:
liss_position += 1
print(liss_position)
``` | 3 | |
673 | A | Bear and Game | PROGRAMMING | 800 | [
"implementation"
] | null | null | Bear Limak likes watching sports on TV. He is going to watch a game today. The game lasts 90 minutes and there are no breaks.
Each minute can be either interesting or boring. If 15 consecutive minutes are boring then Limak immediately turns TV off.
You know that there will be *n* interesting minutes *t*1,<=*t*2,<=...... | The first line of the input contains one integer *n* (1<=≤<=*n*<=≤<=90) — the number of interesting minutes.
The second line contains *n* integers *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t*1<=<<=*t*2<=<<=... *t**n*<=≤<=90), given in the increasing order. | Print the number of minutes Limak will watch the game. | [
"3\n7 20 88\n",
"9\n16 20 30 40 50 60 70 80 90\n",
"9\n15 20 30 40 50 60 70 80 90\n"
] | [
"35\n",
"15\n",
"90\n"
] | In the first sample, minutes 21, 22, ..., 35 are all boring and thus Limak will turn TV off immediately after the 35-th minute. So, he would watch the game for 35 minutes.
In the second sample, the first 15 minutes are boring.
In the third sample, there are no consecutive 15 boring minutes. So, Limak will watch the w... | 500 | [
{
"input": "3\n7 20 88",
"output": "35"
},
{
"input": "9\n16 20 30 40 50 60 70 80 90",
"output": "15"
},
{
"input": "9\n15 20 30 40 50 60 70 80 90",
"output": "90"
},
{
"input": "30\n6 11 12 15 22 24 30 31 32 33 34 35 40 42 44 45 47 50 53 54 57 58 63 67 75 77 79 81 83 88",
... | 1,545,480,846 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 6 | 109 | 0 | x=eval(input())
y=list(map(int,input().split()))
k=15
i=0
if(y[i]>15):
print(15)
else:
sum=y[i]
while(i<x-1):
if(y[i+1]-y[i]<=15):
sum=sum+(y[i+1]-y[i])
else:
sum=sum+15
break
i+=1
if((90-sum)<=15):
print((90-sum)+sum)
else:
print(sum)
| Title: Bear and Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bear Limak likes watching sports on TV. He is going to watch a game today. The game lasts 90 minutes and there are no breaks.
Each minute can be either interesting or boring. If 15 consecutive minutes are boring then Lim... | ```python
x=eval(input())
y=list(map(int,input().split()))
k=15
i=0
if(y[i]>15):
print(15)
else:
sum=y[i]
while(i<x-1):
if(y[i+1]-y[i]<=15):
sum=sum+(y[i+1]-y[i])
else:
sum=sum+15
break
i+=1
if((90-sum)<=15):
print((90-sum)+sum)
else:
print(sum)
``` | 0 | |
792 | A | New Bus Route | PROGRAMMING | 1,100 | [
"implementation",
"sortings"
] | null | null | There are *n* cities situated along the main road of Berland. Cities are represented by their coordinates — integer numbers *a*1,<=*a*2,<=...,<=*a**n*. All coordinates are pairwise distinct.
It is possible to get from one city to another only by bus. But all buses and roads are very old, so the Minister of Transport d... | The first line contains one integer number *n* (2<=≤<=*n*<=≤<=2·105).
The second line contains *n* integer numbers *a*1,<=*a*2,<=...,<=*a**n* (<=-<=109<=≤<=*a**i*<=≤<=109). All numbers *a**i* are pairwise distinct. | Print two integer numbers — the minimal distance and the quantity of pairs with this distance. | [
"4\n6 -3 0 4\n",
"3\n-2 0 2\n"
] | [
"2 1\n",
"2 2\n"
] | In the first example the distance between the first city and the fourth city is |4 - 6| = 2, and it is the only pair with this distance. | 0 | [
{
"input": "4\n6 -3 0 4",
"output": "2 1"
},
{
"input": "3\n-2 0 2",
"output": "2 2"
},
{
"input": "2\n1 2",
"output": "1 1"
},
{
"input": "2\n1000000000 -1000000000",
"output": "2000000000 1"
},
{
"input": "5\n-979619606 -979619602 -979619604 -979619605 -97961960... | 1,595,401,467 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 93 | 6,963,200 | l=int(input())
p=input().split()
s=[]
for i in range(l):
s1=3*10**9
for j in range(i+1,l):
if(s1>abs(int(p[j])-int(p[i]))):
s1=abs(int(p[j])-int(p[i]))
s.append(s1)
print(min(s),s.count(min(s))) | Title: New Bus Route
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* cities situated along the main road of Berland. Cities are represented by their coordinates — integer numbers *a*1,<=*a*2,<=...,<=*a**n*. All coordinates are pairwise distinct.
It is possible to get from on... | ```python
l=int(input())
p=input().split()
s=[]
for i in range(l):
s1=3*10**9
for j in range(i+1,l):
if(s1>abs(int(p[j])-int(p[i]))):
s1=abs(int(p[j])-int(p[i]))
s.append(s1)
print(min(s),s.count(min(s)))
``` | 0 | |
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 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 wh... | 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\n759... | 1,556,375,991 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 218 | 0 | c=[tuple(map(int,input().split())) for _ in range(int(input()))]
print('YES' if any(sum(ci)==cj[0] and sum(cj)==ci[0] for ci in c for cj in c) else '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 ... | ```python
c=[tuple(map(int,input().split())) for _ in range(int(input()))]
print('YES' if any(sum(ci)==cj[0] and sum(cj)==ci[0] for ci in c for cj in c) else 'NO')
``` | 3.9455 |
680 | A | Bear and Five Cards | PROGRAMMING | 800 | [
"constructive algorithms",
"implementation"
] | null | null | A little bear Limak plays a game. He has five cards. There is one number written on each card. Each number is a positive integer.
Limak can discard (throw out) some cards. His goal is to minimize the sum of numbers written on remaining (not discarded) cards.
He is allowed to at most once discard two or three cards wi... | The only line of the input contains five integers *t*1, *t*2, *t*3, *t*4 and *t*5 (1<=≤<=*t**i*<=≤<=100) — numbers written on cards. | Print the minimum possible sum of numbers written on remaining cards. | [
"7 3 7 3 20\n",
"7 9 3 1 8\n",
"10 10 10 10 10\n"
] | [
"26\n",
"28\n",
"20\n"
] | In the first sample, Limak has cards with numbers 7, 3, 7, 3 and 20. Limak can do one of the following.
- Do nothing and the sum would be 7 + 3 + 7 + 3 + 20 = 40. - Remove two cards with a number 7. The remaining sum would be 3 + 3 + 20 = 26. - Remove two cards with a number 3. The remaining sum would be 7 + 7 + 20... | 500 | [
{
"input": "7 3 7 3 20",
"output": "26"
},
{
"input": "7 9 3 1 8",
"output": "28"
},
{
"input": "10 10 10 10 10",
"output": "20"
},
{
"input": "8 7 1 8 7",
"output": "15"
},
{
"input": "7 7 7 8 8",
"output": "16"
},
{
"input": "8 8 8 2 2",
"output"... | 1,600,489,717 | 2,147,483,647 | Python 3 | OK | TESTS | 48 | 109 | 307,200 | t = sorted(list(map(int, input().split())))
b = []
for i in range(5):
if t.count(t[i])>1:
if t.count(t[i])>3:
b.append(t[i]*3)
else:
b.append(t[i]*t.count(t[i]))
if len(b)==0:
print(sum(t))
else:
print(sum(t)-max(b)) | Title: Bear and Five Cards
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A little bear Limak plays a game. He has five cards. There is one number written on each card. Each number is a positive integer.
Limak can discard (throw out) some cards. His goal is to minimize the sum of numbers... | ```python
t = sorted(list(map(int, input().split())))
b = []
for i in range(5):
if t.count(t[i])>1:
if t.count(t[i])>3:
b.append(t[i]*3)
else:
b.append(t[i]*t.count(t[i]))
if len(b)==0:
print(sum(t))
else:
print(sum(t)-max(b))
``` | 3 | |
27 | B | Tournament | PROGRAMMING | 1,300 | [
"bitmasks",
"brute force",
"dfs and similar",
"greedy"
] | B. Tournament | 2 | 256 | The tournament «Sleepyhead-2010» in the rapid falling asleep has just finished in Berland. *n* best participants from the country have participated in it. The tournament consists of games, each of them is a match between two participants. *n*·(*n*<=-<=1)<=/<=2 games were played during the tournament, and each participa... | The first line contains one integer *n* (3<=≤<=*n*<=≤<=50) — the number of participants. The following *n*·(*n*<=-<=1)<=/<=2<=-<=1 lines contain the results of the games. Each game is described in a single line by two integers *x**i*,<=*y**i* (1<=≤<=*x**i*,<=*y**i*<=≤<=*n*,<=*x**i*<=≠<=*y**i*), where *x**i* и *y**i* ar... | Output two integers *x* and *y* — the missing record. If there are several solutions, output any of them. | [
"4\n4 2\n4 1\n2 3\n2 1\n3 1\n"
] | [
"4 3\n"
] | none | 1,000 | [
{
"input": "3\n3 2\n1 2",
"output": "1 3"
},
{
"input": "4\n2 4\n3 4\n1 2\n1 4\n1 3",
"output": "2 3"
},
{
"input": "5\n3 5\n2 5\n1 5\n1 4\n4 3\n1 3\n2 3\n4 5\n4 2",
"output": "1 2"
},
{
"input": "6\n3 4\n3 5\n5 4\n1 2\n5 6\n2 6\n5 2\n3 6\n3 2\n4 6\n2 4\n1 3\n1 5\n1 4",
"... | 1,629,001,890 | 2,147,483,647 | PyPy 3 | OK | TESTS | 35 | 310 | 23,654,400 |
n=int(input())
d={}
l=[]
for i in range((n*(n-1))//2-1):
x,y=map(int,input().split())
l.append([x,y])
d[x]=d.get(x,0)+1
d[y]=d.get(y,0)+1
ans=[]
for i in d.keys():
if d[i]==n-2:
ans.append(i)
f1=0
f2=0
for i in l:
if i[0]==ans[0]:
f1+=1
elif i[1]==ans[0]:
... | Title: Tournament
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
The tournament «Sleepyhead-2010» in the rapid falling asleep has just finished in Berland. *n* best participants from the country have participated in it. The tournament consists of games, each of them is a match between two par... | ```python
n=int(input())
d={}
l=[]
for i in range((n*(n-1))//2-1):
x,y=map(int,input().split())
l.append([x,y])
d[x]=d.get(x,0)+1
d[y]=d.get(y,0)+1
ans=[]
for i in d.keys():
if d[i]==n-2:
ans.append(i)
f1=0
f2=0
for i in l:
if i[0]==ans[0]:
f1+=1
elif i[1]=... | 3.87844 |
334 | A | Candy Bags | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Gerald has *n* younger brothers and their number happens to be even. One day he bought *n*2 candy bags. One bag has one candy, one bag has two candies, one bag has three candies and so on. In fact, for each integer *k* from 1 to *n*2 he has exactly one bag with *k* candies.
Help him give *n* bags of candies to each b... | The single line contains a single integer *n* (*n* is even, 2<=≤<=*n*<=≤<=100) — the number of Gerald's brothers. | Let's assume that Gerald indexes his brothers with numbers from 1 to *n*. You need to print *n* lines, on the *i*-th line print *n* integers — the numbers of candies in the bags for the *i*-th brother. Naturally, all these numbers should be distinct and be within limits from 1 to *n*2. You can print the numbers in the ... | [
"2\n"
] | [
"1 4\n2 3\n"
] | The sample shows Gerald's actions if he has two brothers. In this case, his bags contain 1, 2, 3 and 4 candies. He can give the bags with 1 and 4 candies to one brother and the bags with 2 and 3 to the other brother. | 500 | [
{
"input": "2",
"output": "1 4\n2 3"
},
{
"input": "4",
"output": "1 16 2 15\n3 14 4 13\n5 12 6 11\n7 10 8 9"
},
{
"input": "6",
"output": "1 36 2 35 3 34\n4 33 5 32 6 31\n7 30 8 29 9 28\n10 27 11 26 12 25\n13 24 14 23 15 22\n16 21 17 20 18 19"
},
{
"input": "8",
"output"... | 1,595,358,797 | 2,147,483,647 | PyPy 3 | OK | TESTS | 21 | 342 | 23,859,200 | num = int(input())
arr = [x for x in range(1, num ** 2 + 1)]
for x in range(len(arr) // 2):
print(arr[x], arr[~x])
| Title: Candy Bags
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Gerald has *n* younger brothers and their number happens to be even. One day he bought *n*2 candy bags. One bag has one candy, one bag has two candies, one bag has three candies and so on. In fact, for each integer *k* from ... | ```python
num = int(input())
arr = [x for x in range(1, num ** 2 + 1)]
for x in range(len(arr) // 2):
print(arr[x], arr[~x])
``` | 3 | |
682 | A | Alyona and Numbers | PROGRAMMING | 1,100 | [
"constructive algorithms",
"math",
"number theory"
] | null | null | After finishing eating her bun, Alyona came up with two integers *n* and *m*. She decided to write down two columns of integers — the first column containing integers from 1 to *n* and the second containing integers from 1 to *m*. Now the girl wants to count how many pairs of integers she can choose, one from the first... | The only line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=1<=000<=000). | Print the only integer — the number of pairs of integers (*x*,<=*y*) such that 1<=≤<=*x*<=≤<=*n*, 1<=≤<=*y*<=≤<=*m* and (*x*<=+<=*y*) is divisible by 5. | [
"6 12\n",
"11 14\n",
"1 5\n",
"3 8\n",
"5 7\n",
"21 21\n"
] | [
"14\n",
"31\n",
"1\n",
"5\n",
"7\n",
"88\n"
] | Following pairs are suitable in the first sample case:
- for *x* = 1 fits *y* equal to 4 or 9; - for *x* = 2 fits *y* equal to 3 or 8; - for *x* = 3 fits *y* equal to 2, 7 or 12; - for *x* = 4 fits *y* equal to 1, 6 or 11; - for *x* = 5 fits *y* equal to 5 or 10; - for *x* = 6 fits *y* equal to 4 or 9.
Only th... | 500 | [
{
"input": "6 12",
"output": "14"
},
{
"input": "11 14",
"output": "31"
},
{
"input": "1 5",
"output": "1"
},
{
"input": "3 8",
"output": "5"
},
{
"input": "5 7",
"output": "7"
},
{
"input": "21 21",
"output": "88"
},
{
"input": "10 15",
... | 1,613,936,046 | 2,147,483,647 | Python 3 | OK | TESTS | 128 | 436 | 0 | n,m=map(int,input().split())
ans=0
for i in range(1,n+1):
ans+=(i%5+m)//5
print(ans) | Title: Alyona and Numbers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
After finishing eating her bun, Alyona came up with two integers *n* and *m*. She decided to write down two columns of integers — the first column containing integers from 1 to *n* and the second containing integers ... | ```python
n,m=map(int,input().split())
ans=0
for i in range(1,n+1):
ans+=(i%5+m)//5
print(ans)
``` | 3 | |
136 | A | Presents | PROGRAMMING | 800 | [
"implementation"
] | null | null | Little Petya very much likes gifts. Recently he has received a new laptop as a New Year gift from his mother. He immediately decided to give it to somebody else as what can be more pleasant than giving somebody gifts. And on this occasion he organized a New Year party at his place and invited *n* his friends there.
If... | The first line contains one integer *n* (1<=≤<=*n*<=≤<=100) — the quantity of friends Petya invited to the party. The second line contains *n* space-separated integers: the *i*-th number is *p**i* — the number of a friend who gave a gift to friend number *i*. It is guaranteed that each friend received exactly one gift.... | Print *n* space-separated integers: the *i*-th number should equal the number of the friend who gave a gift to friend number *i*. | [
"4\n2 3 4 1\n",
"3\n1 3 2\n",
"2\n1 2\n"
] | [
"4 1 2 3\n",
"1 3 2\n",
"1 2\n"
] | none | 500 | [
{
"input": "4\n2 3 4 1",
"output": "4 1 2 3"
},
{
"input": "3\n1 3 2",
"output": "1 3 2"
},
{
"input": "2\n1 2",
"output": "1 2"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "10\n1 3 2 6 4 5 7 9 8 10",
"output": "1 3 2 5 6 4 7 9 8 10"
},
{
"input"... | 1,695,334,994 | 2,147,483,647 | PyPy 3 | OK | TESTS | 101 | 186 | 0 | n = int(input())
presents = [ int(i) for i in input().split()]
i = 1
while (i <= n):
print(presents.index(i)+1, end=' ')
i += 1
| Title: Presents
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Petya very much likes gifts. Recently he has received a new laptop as a New Year gift from his mother. He immediately decided to give it to somebody else as what can be more pleasant than giving somebody gifts. And on t... | ```python
n = int(input())
presents = [ int(i) for i in input().split()]
i = 1
while (i <= n):
print(presents.index(i)+1, end=' ')
i += 1
``` | 3 | |
158 | B | Taxi | PROGRAMMING | 1,100 | [
"*special",
"greedy",
"implementation"
] | null | null | After the lessons *n* groups of schoolchildren went outside and decided to visit Polycarpus to celebrate his birthday. We know that the *i*-th group consists of *s**i* friends (1<=≤<=*s**i*<=≤<=4), and they want to go to Polycarpus together. They decided to get there by taxi. Each car can carry at most four passengers.... | The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of groups of schoolchildren. The second line contains a sequence of integers *s*1,<=*s*2,<=...,<=*s**n* (1<=≤<=*s**i*<=≤<=4). The integers are separated by a space, *s**i* is the number of children in the *i*-th group. | Print the single number — the minimum number of taxis necessary to drive all children to Polycarpus. | [
"5\n1 2 4 3 3\n",
"8\n2 3 4 4 2 1 3 1\n"
] | [
"4\n",
"5\n"
] | In the first test we can sort the children into four cars like this:
- the third group (consisting of four children), - the fourth group (consisting of three children), - the fifth group (consisting of three children), - the first and the second group (consisting of one and two children, correspondingly).
There a... | 1,000 | [
{
"input": "5\n1 2 4 3 3",
"output": "4"
},
{
"input": "8\n2 3 4 4 2 1 3 1",
"output": "5"
},
{
"input": "5\n4 4 4 4 4",
"output": "5"
},
{
"input": "12\n1 1 1 1 1 1 1 1 1 1 1 1",
"output": "3"
},
{
"input": "2\n2 1",
"output": "1"
},
{
"input": "4\n3 ... | 1,699,451,261 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 0 | 186 | 0 | n = int(input())
groups = list(map(int, input().split()))
group_count = {1: 0, 2: 0, 3: 0, 4: 0}
for group in groups:
group_count[group] += 1
taxis_needed = group_count[4]
5,3
x = min(group_count[3],group_count[1])
taxis_needed+=x
if x!=0:
if x==group_count[3]:
group_count[3]=0
... | Title: Taxi
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
After the lessons *n* groups of schoolchildren went outside and decided to visit Polycarpus to celebrate his birthday. We know that the *i*-th group consists of *s**i* friends (1<=≤<=*s**i*<=≤<=4), and they want to go to Polycarpu... | ```python
n = int(input())
groups = list(map(int, input().split()))
group_count = {1: 0, 2: 0, 3: 0, 4: 0}
for group in groups:
group_count[group] += 1
taxis_needed = group_count[4]
5,3
x = min(group_count[3],group_count[1])
taxis_needed+=x
if x!=0:
if x==group_count[3]:
group_count[3]=0... | 0 | |
621 | A | Wet Shark and Odd and Even | PROGRAMMING | 900 | [
"implementation"
] | null | null | Today, Wet Shark is given *n* integers. Using any of these integers no more than once, Wet Shark wants to get maximum possible even (divisible by 2) sum. Please, calculate this value for Wet Shark.
Note, that if Wet Shark uses no integers from the *n* integers, the sum is an even integer 0. | The first line of the input contains one integer, *n* (1<=≤<=*n*<=≤<=100<=000). The next line contains *n* space separated integers given to Wet Shark. Each of these integers is in range from 1 to 109, inclusive. | Print the maximum possible even sum that can be obtained if we use some of the given integers. | [
"3\n1 2 3\n",
"5\n999999999 999999999 999999999 999999999 999999999\n"
] | [
"6",
"3999999996"
] | In the first sample, we can simply take all three integers for a total sum of 6.
In the second sample Wet Shark should take any four out of five integers 999 999 999. | 500 | [
{
"input": "3\n1 2 3",
"output": "6"
},
{
"input": "5\n999999999 999999999 999999999 999999999 999999999",
"output": "3999999996"
},
{
"input": "1\n1",
"output": "0"
},
{
"input": "15\n39 52 88 78 46 95 84 98 55 3 68 42 6 18 98",
"output": "870"
},
{
"input": "15\... | 1,691,001,047 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 87 | 92 | 13,516,800 | n = int(input())
a = list(map(int,input().split()))
lowest_odd = 10**9+1
Sum = 0
for a_i in a:
Sum += a_i
if a_i % 2 == 1 and a_i < lowest_odd:
lowest_odd = a_i
if (Sum % 2 == 0):
print (Sum)
else:
print(Sum - lowest_odd) | Title: Wet Shark and Odd and Even
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Today, Wet Shark is given *n* integers. Using any of these integers no more than once, Wet Shark wants to get maximum possible even (divisible by 2) sum. Please, calculate this value for Wet Shark.
Note, th... | ```python
n = int(input())
a = list(map(int,input().split()))
lowest_odd = 10**9+1
Sum = 0
for a_i in a:
Sum += a_i
if a_i % 2 == 1 and a_i < lowest_odd:
lowest_odd = a_i
if (Sum % 2 == 0):
print (Sum)
else:
print(Sum - lowest_odd)
``` | 3 | |
698 | A | Vacations | PROGRAMMING | 1,400 | [
"dp"
] | null | null | Vasya has *n* days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this *n* days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the *i*-th day there are four options:
1. on this day the gym is close... | The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100) — the number of days of Vasya's vacations.
The second line contains the sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=3) separated by space, where:
- *a**i* equals 0, if on the *i*-th day of vacations the gym is closed and the co... | Print the minimum possible number of days on which Vasya will have a rest. Remember that Vasya refuses:
- to do sport on any two consecutive days, - to write the contest on any two consecutive days. | [
"4\n1 3 2 0\n",
"7\n1 3 3 2 1 2 3\n",
"2\n2 2\n"
] | [
"2\n",
"0\n",
"1\n"
] | In the first test Vasya can write the contest on the day number 1 and do sport on the day number 3. Thus, he will have a rest for only 2 days.
In the second test Vasya should write contests on days number 1, 3, 5 and 7, in other days do sport. Thus, he will not have a rest for a single day.
In the third test Vasya ca... | 500 | [
{
"input": "4\n1 3 2 0",
"output": "2"
},
{
"input": "7\n1 3 3 2 1 2 3",
"output": "0"
},
{
"input": "2\n2 2",
"output": "1"
},
{
"input": "1\n0",
"output": "1"
},
{
"input": "10\n0 0 1 1 0 0 0 0 1 0",
"output": "8"
},
{
"input": "100\n3 2 3 3 3 2 3 1 ... | 1,597,929,445 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 5 | 93 | 307,200 | """Vasya has n days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this n days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the i-th day there are four options:
on this day the gym is closed and... | Title: Vacations
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya has *n* days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this *n* days: whether that gym opened and whether a contest was carried out in the Int... | ```python
"""Vasya has n days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this n days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the i-th day there are four options:
on this day the gym is ... | 0 | |
755 | B | PolandBall and Game | PROGRAMMING | 1,100 | [
"binary search",
"data structures",
"games",
"greedy",
"sortings",
"strings"
] | null | null | PolandBall is playing a game with EnemyBall. The rules are simple. Players have to say words in turns. You cannot say a word which was already said. PolandBall starts. The Ball which can't say a new word loses.
You're given two lists of words familiar to PolandBall and EnemyBall. Can you determine who wins the game, i... | The first input line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=103) — number of words PolandBall and EnemyBall know, respectively.
Then *n* strings follow, one per line — words familiar to PolandBall.
Then *m* strings follow, one per line — words familiar to EnemyBall.
Note that one Ball cannot know a w... | In a single line of print the answer — "YES" if PolandBall wins and "NO" otherwise. Both Balls play optimally. | [
"5 1\npolandball\nis\na\ncool\ncharacter\nnope\n",
"2 2\nkremowka\nwadowicka\nkremowka\nwiedenska\n",
"1 2\na\na\nb\n"
] | [
"YES",
"YES",
"NO"
] | In the first example PolandBall knows much more words and wins effortlessly.
In the second example if PolandBall says kremowka first, then EnemyBall cannot use that word anymore. EnemyBall can only say wiedenska. PolandBall says wadowicka and wins. | 1,000 | [
{
"input": "5 1\npolandball\nis\na\ncool\ncharacter\nnope",
"output": "YES"
},
{
"input": "2 2\nkremowka\nwadowicka\nkremowka\nwiedenska",
"output": "YES"
},
{
"input": "1 2\na\na\nb",
"output": "NO"
},
{
"input": "2 2\na\nb\nb\nc",
"output": "YES"
},
{
"input": "... | 1,634,946,042 | 2,147,483,647 | Python 3 | OK | TESTS | 33 | 46 | 6,041,600 | if __name__ == '__main__':
n, m = map(int, input().split())
s = set()
for _ in range(n + m):
s.add(input())
k = n + m - len(s)
if n > m:
print("YES")
elif m > n:
print("NO")
elif n + k % 2 > m:
print("YES")
else:
print("NO")
... | Title: PolandBall and Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
PolandBall is playing a game with EnemyBall. The rules are simple. Players have to say words in turns. You cannot say a word which was already said. PolandBall starts. The Ball which can't say a new word loses.
You... | ```python
if __name__ == '__main__':
n, m = map(int, input().split())
s = set()
for _ in range(n + m):
s.add(input())
k = n + m - len(s)
if n > m:
print("YES")
elif m > n:
print("NO")
elif n + k % 2 > m:
print("YES")
else:
print("NO")
... | 3 | |
272 | A | Dima and Friends | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | null | null | Dima and his friends have been playing hide and seek at Dima's place all night. As a result, Dima's place got messy. In the morning they decided that they need to clean the place.
To decide who exactly would clean the apartment, the friends want to play a counting-out game. First, all the guys stand in a circle, and t... | The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of Dima's friends. Dima himself isn't considered to be his own friend. The second line contains *n* positive integers, not exceeding 5, representing, how many fingers the Dima's friends will show.
The numbers in the lines are separated by a single s... | In a single line print the answer to the problem. | [
"1\n1\n",
"1\n2\n",
"2\n3 5\n"
] | [
"3\n",
"2\n",
"3\n"
] | In the first sample Dima can show 1, 3 or 5 fingers. If Dima shows 3 fingers, then the counting-out will go like that: Dima, his friend, Dima, his friend.
In the second sample Dima can show 2 or 4 fingers. | 500 | [
{
"input": "1\n1",
"output": "3"
},
{
"input": "1\n2",
"output": "2"
},
{
"input": "2\n3 5",
"output": "3"
},
{
"input": "2\n3 5",
"output": "3"
},
{
"input": "1\n5",
"output": "3"
},
{
"input": "5\n4 4 3 5 1",
"output": "4"
},
{
"input": "... | 1,688,224,986 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 5 | 92 | 0 | n = int(input())
fingers = list(map(int,(input()).split(" ")))
add = n + sum(fingers) + 1
if add % 2 == 0:
print(2)
else:
print(3) | Title: Dima and Friends
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Dima and his friends have been playing hide and seek at Dima's place all night. As a result, Dima's place got messy. In the morning they decided that they need to clean the place.
To decide who exactly would clean the... | ```python
n = int(input())
fingers = list(map(int,(input()).split(" ")))
add = n + sum(fingers) + 1
if add % 2 == 0:
print(2)
else:
print(3)
``` | 0 | |
625 | B | War of the Corporations | PROGRAMMING | 1,200 | [
"constructive algorithms",
"greedy",
"strings"
] | null | null | A long time ago, in a galaxy far far away two giant IT-corporations Pineapple and Gogol continue their fierce competition. Crucial moment is just around the corner: Gogol is ready to release it's new tablet Lastus 3000.
This new device is equipped with specially designed artificial intelligence (AI). Employees of Pine... | The first line of the input contains the name of AI designed by Gogol, its length doesn't exceed 100<=000 characters. Second line contains the name of the phone released by Pineapple 200 years ago, its length doesn't exceed 30. Both string are non-empty and consist of only small English letters. | Print the minimum number of characters that must be replaced with "#" in order to obtain that the name of the phone doesn't occur in the name of AI as a substring. | [
"intellect\ntell\n",
"google\napple\n",
"sirisiri\nsir\n"
] | [
"1",
"0",
"2"
] | In the first sample AI's name may be replaced with "int#llect".
In the second sample Gogol can just keep things as they are.
In the third sample one of the new possible names of AI may be "s#ris#ri". | 750 | [
{
"input": "intellect\ntell",
"output": "1"
},
{
"input": "google\napple",
"output": "0"
},
{
"input": "sirisiri\nsir",
"output": "2"
},
{
"input": "sirisiri\nsiri",
"output": "2"
},
{
"input": "aaaaaaa\naaaa",
"output": "1"
},
{
"input": "bbbbbb\nbb",... | 1,639,069,199 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 30 | 0 | str1=""
str2=""
str = input()
str2=input()
print(str1.count(str2)) | Title: War of the Corporations
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A long time ago, in a galaxy far far away two giant IT-corporations Pineapple and Gogol continue their fierce competition. Crucial moment is just around the corner: Gogol is ready to release it's new tablet Last... | ```python
str1=""
str2=""
str = input()
str2=input()
print(str1.count(str2))
``` | 0 | |
144 | A | Arrival of the General | PROGRAMMING | 800 | [
"implementation"
] | null | null | A Ministry for Defense sent a general to inspect the Super Secret Military Squad under the command of the Colonel SuperDuper. Having learned the news, the colonel ordered to all *n* squad soldiers to line up on the parade ground.
By the military charter the soldiers should stand in the order of non-increasing of their... | The first input line contains the only integer *n* (2<=≤<=*n*<=≤<=100) which represents the number of soldiers in the line. The second line contains integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100) the values of the soldiers' heights in the order of soldiers' heights' increasing in the order from the beginnin... | Print the only integer — the minimum number of seconds the colonel will need to form a line-up the general will like. | [
"4\n33 44 11 22\n",
"7\n10 10 58 31 63 40 76\n"
] | [
"2\n",
"10\n"
] | In the first sample the colonel will need to swap the first and second soldier and then the third and fourth soldier. That will take 2 seconds. The resulting position of the soldiers is (44, 33, 22, 11).
In the second sample the colonel may swap the soldiers in the following sequence:
1. (10, 10, 58, 31, 63, 40, 76)... | 500 | [
{
"input": "4\n33 44 11 22",
"output": "2"
},
{
"input": "7\n10 10 58 31 63 40 76",
"output": "10"
},
{
"input": "2\n88 89",
"output": "1"
},
{
"input": "5\n100 95 100 100 88",
"output": "0"
},
{
"input": "7\n48 48 48 48 45 45 45",
"output": "0"
},
{
"... | 1,694,286,312 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 39 | 124 | 0 | n = int(input())
a = list(map(int, input().split()))
b = a.index(max(a)) + a[::-1].index(min(a))
print(b - (b >= n)) | Title: Arrival of the General
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A Ministry for Defense sent a general to inspect the Super Secret Military Squad under the command of the Colonel SuperDuper. Having learned the news, the colonel ordered to all *n* squad soldiers to line up on t... | ```python
n = int(input())
a = list(map(int, input().split()))
b = a.index(max(a)) + a[::-1].index(min(a))
print(b - (b >= n))
``` | 3 | |
910 | A | The Way to Home | PROGRAMMING | 800 | [
"dfs and similar",
"dp",
"greedy",
"implementation"
] | null | null | A frog lives on the axis *Ox* and needs to reach home which is in the point *n*. She starts from the point 1. The frog can jump to the right at a distance not more than *d*. So, after she jumped from the point *x* she can reach the point *x*<=+<=*a*, where *a* is an integer from 1 to *d*.
For each point from 1 to *n* ... | The first line contains two integers *n* and *d* (2<=≤<=*n*<=≤<=100, 1<=≤<=*d*<=≤<=*n*<=-<=1) — the point, which the frog wants to reach, and the maximal length of the frog jump.
The second line contains a string *s* of length *n*, consisting of zeros and ones. If a character of the string *s* equals to zero, then in ... | If the frog can not reach the home, print -1.
In the other case, print the minimal number of jumps that the frog needs to reach the home which is in the point *n* from the point 1. | [
"8 4\n10010101\n",
"4 2\n1001\n",
"8 4\n11100101\n",
"12 3\n101111100101\n"
] | [
"2\n",
"-1\n",
"3\n",
"4\n"
] | In the first example the from can reach home in two jumps: the first jump from the point 1 to the point 4 (the length of the jump is three), and the second jump from the point 4 to the point 8 (the length of the jump is four).
In the second example the frog can not reach home, because to make it she need to jump on a ... | 500 | [
{
"input": "8 4\n10010101",
"output": "2"
},
{
"input": "4 2\n1001",
"output": "-1"
},
{
"input": "8 4\n11100101",
"output": "3"
},
{
"input": "12 3\n101111100101",
"output": "4"
},
{
"input": "5 4\n11011",
"output": "1"
},
{
"input": "5 4\n10001",
... | 1,696,790,276 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 14 | 1,000 | 0 | def move(path, actual, end, maxDist, best, count):
if actual == end-1:
if best[0] == -1: best[0] = count
if count < best[0]:best[0] = count
return
for i in range(maxDist,1,-1):
if(path[actual]=="1" and actual+i <= end-1):
move(path, actual+i, end, maxDist, best, count+1)
end, maxDist = map(... | Title: The Way to Home
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A frog lives on the axis *Ox* and needs to reach home which is in the point *n*. She starts from the point 1. The frog can jump to the right at a distance not more than *d*. So, after she jumped from the point *x* she c... | ```python
def move(path, actual, end, maxDist, best, count):
if actual == end-1:
if best[0] == -1: best[0] = count
if count < best[0]:best[0] = count
return
for i in range(maxDist,1,-1):
if(path[actual]=="1" and actual+i <= end-1):
move(path, actual+i, end, maxDist, best, count+1)
end, maxD... | 0 | |
484 | A | Bits | PROGRAMMING | 1,700 | [
"bitmasks",
"constructive algorithms"
] | null | null | Let's denote as the number of bits set ('1' bits) in the binary representation of the non-negative integer *x*.
You are given multiple queries consisting of pairs of integers *l* and *r*. For each query, find the *x*, such that *l*<=≤<=*x*<=≤<=*r*, and is maximum possible. If there are multiple such numbers find the... | The first line contains integer *n* — the number of queries (1<=≤<=*n*<=≤<=10000).
Each of the following *n* lines contain two integers *l**i*,<=*r**i* — the arguments for the corresponding query (0<=≤<=*l**i*<=≤<=*r**i*<=≤<=1018). | For each query print the answer in a separate line. | [
"3\n1 2\n2 4\n1 10\n"
] | [
"1\n3\n7\n"
] | The binary representations of numbers from 1 to 10 are listed below:
1<sub class="lower-index">10</sub> = 1<sub class="lower-index">2</sub>
2<sub class="lower-index">10</sub> = 10<sub class="lower-index">2</sub>
3<sub class="lower-index">10</sub> = 11<sub class="lower-index">2</sub>
4<sub class="lower-index">10</su... | 500 | [
{
"input": "3\n1 2\n2 4\n1 10",
"output": "1\n3\n7"
},
{
"input": "55\n1 1\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n2 2\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n2 9\n2 10\n3 3\n3 4\n3 5\n3 6\n3 7\n3 8\n3 9\n3 10\n4 4\n4 5\n4 6\n4 7\n4 8\n4 9\n4 10\n5 5\n5 6\n5 7\n5 8\n5 9\n5 10\n6 6\n6 7\n6 8\n6 9\n6 10... | 1,583,446,237 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 78 | 0 |
for q in range(int(input())):
l, r = map(int,input().split())
com = 0
res = 0
while 1 :
if l<= com <=r:
res = com
com = (com<<1) + 1
if com > r:
break
print(res) | Title: Bits
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Let's denote as the number of bits set ('1' bits) in the binary representation of the non-negative integer *x*.
You are given multiple queries consisting of pairs of integers *l* and *r*. For each query, find the *x*, such that ... | ```python
for q in range(int(input())):
l, r = map(int,input().split())
com = 0
res = 0
while 1 :
if l<= com <=r:
res = com
com = (com<<1) + 1
if com > r:
break
print(res)
``` | 0 | |
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. E... | 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 di... | 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",
... | 1,541,249,900 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | lines=int(input())
index=0
A=0
B=0
C=0
D=0
E=0
F=0
G=0
H=0
I=0
J=0
while index<lines
goals=input()
a=goals.find(A)
A=A+a
b=goals.find(B)
B=B+b
c=goals.find(C)
C=C+c
d=goals.find(D)
D=D+d
e=goals.find(E)
E=E+e
f=goals.find(F)
F=F+f
g=goals.find(G)
G=G+g
h=g... | 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... | ```python
lines=int(input())
index=0
A=0
B=0
C=0
D=0
E=0
F=0
G=0
H=0
I=0
J=0
while index<lines
goals=input()
a=goals.find(A)
A=A+a
b=goals.find(B)
B=B+b
c=goals.find(C)
C=C+c
d=goals.find(D)
D=D+d
e=goals.find(E)
E=E+e
f=goals.find(F)
F=F+f
g=goals.find(G)
G=G... | -1 |
Subsets and Splits
Successful Python Submissions
Retrieves all records from the train dataset where the verdict is 'OK', providing basic filtering but limited analytical value.
SQL Console for MatrixStudio/Codeforces-Python-Submissions
Retrieves records of users with a rating of 1600 or higher and a verdict of 'OK', providing basic filtering but limited analytical value.
SQL Console for MatrixStudio/Codeforces-Python-Submissions
Counts the number of entries with a rating above 2000 and a verdict of 'OK', providing basic filtering but limited analytical value.
SQL Console for MatrixStudio/Codeforces-Python-Submissions
Counts the number of entries with a 'OK' verdict, providing a basic overview of a specific category within the dataset.