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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
69 | A | Young Physicist | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | A. Young Physicist | 2 | 256 | A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasy... | The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100), then follow *n* lines containing three integers each: the *x**i* coordinate, the *y**i* coordinate and the *z**i* coordinate of the force vector, applied to the body (<=-<=100<=≤<=*x**i*,<=*y**i*,<=*z**i*<=≤<=100). | Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not. | [
"3\n4 1 7\n-2 4 -1\n1 -5 -3\n",
"3\n3 -1 7\n-5 2 -4\n2 -1 -3\n"
] | [
"NO",
"YES"
] | none | 500 | [
{
"input": "3\n4 1 7\n-2 4 -1\n1 -5 -3",
"output": "NO"
},
{
"input": "3\n3 -1 7\n-5 2 -4\n2 -1 -3",
"output": "YES"
},
{
"input": "10\n21 32 -46\n43 -35 21\n42 2 -50\n22 40 20\n-27 -9 38\n-4 1 1\n-40 6 -31\n-13 -2 34\n-21 34 -12\n-32 -29 41",
"output": "NO"
},
{
"input": "10... | 1,568,866,500 | 2,147,483,647 | Python 3 | OK | TESTS | 81 | 218 | 0 | n = int(input())
x = 0
y = 0
z = 0
def add(a,num,listt):
a = a + int(listt[num])
return a
5
for i in range(n):
tmp = input().split()
x = add(x,0,tmp)
y = add(y,1,tmp)
z = add(z,2,tmp)
if x == 0 and y == 0 and z == 0:
print('YES')
else:
print('NO') | Title: Young Physicist
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. S... | ```python
n = int(input())
x = 0
y = 0
z = 0
def add(a,num,listt):
a = a + int(listt[num])
return a
5
for i in range(n):
tmp = input().split()
x = add(x,0,tmp)
y = add(y,1,tmp)
z = add(z,2,tmp)
if x == 0 and y == 0 and z == 0:
print('YES')
else:
print('NO')
``` | 3.9455 |
767 | C | Garland | PROGRAMMING | 2,000 | [
"dfs and similar",
"graphs",
"greedy",
"trees"
] | null | null | Once at New Year Dima had a dream in which he was presented a fairy garland. A garland is a set of lamps, some pairs of which are connected by wires. Dima remembered that each two lamps in the garland were connected directly or indirectly via some wires. Furthermore, the number of wires was exactly one less than the nu... | The first line contains single integer *n* (3<=≤<=*n*<=≤<=106) — the number of lamps in the garland.
Then *n* lines follow. The *i*-th of them contain the information about the *i*-th lamp: the number lamp *a**i*, it is hanging on (and 0, if is there is no such lamp), and its temperature *t**i* (<=-<=100<=≤<=*t**i*<=≤... | If there is no solution, print -1.
Otherwise print two integers — the indexes of the lamps which mean Dima should cut the wires they are hanging on. If there are multiple answers, print any of them. | [
"6\n2 4\n0 5\n4 2\n2 1\n1 1\n4 2\n",
"6\n2 4\n0 6\n4 2\n2 1\n1 1\n4 2\n"
] | [
"1 4\n",
"-1\n"
] | The garland and cuts scheme for the first example: | 1,500 | [
{
"input": "6\n2 4\n0 5\n4 2\n2 1\n1 1\n4 2",
"output": "1 4"
},
{
"input": "6\n2 4\n0 6\n4 2\n2 1\n1 1\n4 2",
"output": "-1"
},
{
"input": "6\n2 4\n0 -1\n4 2\n2 3\n1 2\n4 5",
"output": "6 4"
},
{
"input": "3\n2 1\n0 1\n2 1",
"output": "1 3"
},
{
"input": "5\n0 5\... | 1,580,446,783 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 0 | 108 | 0 | #https://codeforces.com/problemset/problem/767/C
#TLE
def push(d, u, v):
if u not in d:
d[u] = []
d[u].append(v)
g = {}
d = {}
p = {}
root = None
n = int(input())
for u in range(1, n+1):
v, val = map(int, input().split())
if v == 0:
root=u
else:
... | Title: Garland
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Once at New Year Dima had a dream in which he was presented a fairy garland. A garland is a set of lamps, some pairs of which are connected by wires. Dima remembered that each two lamps in the garland were connected directly or... | ```python
#https://codeforces.com/problemset/problem/767/C
#TLE
def push(d, u, v):
if u not in d:
d[u] = []
d[u].append(v)
g = {}
d = {}
p = {}
root = None
n = int(input())
for u in range(1, n+1):
v, val = map(int, input().split())
if v == 0:
root=u
els... | 0 | |
845 | C | Two TVs | PROGRAMMING | 1,500 | [
"data structures",
"greedy",
"sortings"
] | null | null | Polycarp is a great fan of television.
He wrote down all the TV programs he is interested in for today. His list contains *n* shows, *i*-th of them starts at moment *l**i* and ends at moment *r**i*.
Polycarp owns two TVs. He can watch two different shows simultaneously with two TVs but he can only watch one show at a... | The first line contains one integer *n* (1<=≤<=*n*<=≤<=2·105) — the number of shows.
Each of the next *n* lines contains two integers *l**i* and *r**i* (0<=≤<=*l**i*<=<<=*r**i*<=≤<=109) — starting and ending time of *i*-th show. | If Polycarp is able to check out all the shows using only two TVs then print "YES" (without quotes). Otherwise, print "NO" (without quotes). | [
"3\n1 2\n2 3\n4 5\n",
"4\n1 2\n2 3\n2 3\n1 2\n"
] | [
"YES\n",
"NO\n"
] | none | 0 | [
{
"input": "3\n1 2\n2 3\n4 5",
"output": "YES"
},
{
"input": "4\n1 2\n2 3\n2 3\n1 2",
"output": "NO"
},
{
"input": "4\n0 1\n1 2\n2 3\n3 4",
"output": "YES"
},
{
"input": "3\n1 2\n2 3\n2 4",
"output": "NO"
},
{
"input": "3\n0 100\n0 100\n0 100",
"output": "NO"
... | 1,520,210,548 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 3 | 2,000 | 6,041,600 | n=int(input())
a=[]
s=input().split()
a=a+[i for i in range(int(s[0]),int(s[1])+1)]
t=True
for i in range(n-1):
s=input().split()
q=int(s[0])
w=int(s[1])
for j in a:
if ((q in a ) and(w in a)):
t=False
... | Title: Two TVs
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp is a great fan of television.
He wrote down all the TV programs he is interested in for today. His list contains *n* shows, *i*-th of them starts at moment *l**i* and ends at moment *r**i*.
Polycarp owns two TVs. He ... | ```python
n=int(input())
a=[]
s=input().split()
a=a+[i for i in range(int(s[0]),int(s[1])+1)]
t=True
for i in range(n-1):
s=input().split()
q=int(s[0])
w=int(s[1])
for j in a:
if ((q in a ) and(w in a)):
t=Fals... | 0 | |
1 | A | Theatre Square | PROGRAMMING | 1,000 | [
"math"
] | A. Theatre Square | 1 | 256 | Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size *a*<=×<=*a*.
What is the least number of flagstones needed to pave the... | The input contains three positive integer numbers in the first line: *n*,<=<=*m* and *a* (1<=≤<=<=*n*,<=*m*,<=*a*<=≤<=109). | Write the needed number of flagstones. | [
"6 6 4\n"
] | [
"4\n"
] | none | 0 | [
{
"input": "6 6 4",
"output": "4"
},
{
"input": "1 1 1",
"output": "1"
},
{
"input": "2 1 1",
"output": "2"
},
{
"input": "1 2 1",
"output": "2"
},
{
"input": "2 2 1",
"output": "4"
},
{
"input": "2 1 2",
"output": "1"
},
{
"input": "1 1 3"... | 1,660,337,147 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 30 | 0 | k,n,w=map(int,input().split(" "))
x=0
counter=0
while True:
if k <= x:
break
counter+=1
x+=w
x=0
while True:
if n<=x:
break
counter+=1
x+=w
print(counter) | Title: Theatre Square
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each ... | ```python
k,n,w=map(int,input().split(" "))
x=0
counter=0
while True:
if k <= x:
break
counter+=1
x+=w
x=0
while True:
if n<=x:
break
counter+=1
x+=w
print(counter)
``` | 0 |
981 | B | Businessmen Problems | PROGRAMMING | 1,000 | [
"sortings"
] | null | null | Two famous competing companies ChemForces and TopChemist decided to show their sets of recently discovered chemical elements on an exhibition. However they know that no element should be present in the sets of both companies.
In order to avoid this representatives of both companies decided to make an agreement on the ... | The first line contains a single integer $n$ ($1 \leq n \leq 10^5$) — the number of elements discovered by ChemForces.
The $i$-th of the next $n$ lines contains two integers $a_i$ and $x_i$ ($1 \leq a_i \leq 10^9$, $1 \leq x_i \leq 10^9$) — the index of the $i$-th element and the income of its usage on the exhibitio... | Print the maximum total income you can obtain by choosing the sets for both companies in such a way that no element is presented in both sets. | [
"3\n1 2\n7 2\n3 10\n4\n1 4\n2 4\n3 4\n4 4\n",
"1\n1000000000 239\n3\n14 15\n92 65\n35 89\n"
] | [
"24\n",
"408\n"
] | In the first example ChemForces can choose the set ($3, 7$), while TopChemist can choose ($1, 2, 4$). This way the total income is $(10 + 2) + (4 + 4 + 4) = 24$.
In the second example ChemForces can choose the only element $10^9$, while TopChemist can choose ($14, 92, 35$). This way the total income is $(239) + (15 + ... | 750 | [
{
"input": "3\n1 2\n7 2\n3 10\n4\n1 4\n2 4\n3 4\n4 4",
"output": "24"
},
{
"input": "1\n1000000000 239\n3\n14 15\n92 65\n35 89",
"output": "408"
},
{
"input": "10\n598654597 488228616\n544064902 21923894\n329635457 980089248\n988262691 654502493\n967529230 543358150\n835120075 128123793\... | 1,622,130,190 | 2,147,483,647 | Python 3 | OK | TESTS | 33 | 530 | 15,667,200 | n = int(input())
cf = {}
sum = 0
for i in range(n):
a, b = map(int, input().split())
cf[a] = b
sum += b
m = int(input())
for i in range(m):
a, b = map(int, input().split())
if a in cf:
if cf.get(a) < b:
sum -= cf.get(a)
cf[a] = b
sum += b
... | Title: Businessmen Problems
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Two famous competing companies ChemForces and TopChemist decided to show their sets of recently discovered chemical elements on an exhibition. However they know that no element should be present in the sets of both... | ```python
n = int(input())
cf = {}
sum = 0
for i in range(n):
a, b = map(int, input().split())
cf[a] = b
sum += b
m = int(input())
for i in range(m):
a, b = map(int, input().split())
if a in cf:
if cf.get(a) < b:
sum -= cf.get(a)
cf[a] = b
su... | 3 | |
363 | B | Fence | PROGRAMMING | 1,100 | [
"brute force",
"dp"
] | null | null | There is a fence in front of Polycarpus's home. The fence consists of *n* planks of the same width which go one after another from left to right. The height of the *i*-th plank is *h**i* meters, distinct planks can have distinct heights.
Polycarpus has bought a posh piano and is thinking about how to get it into the h... | The first line of the input contains integers *n* and *k* (1<=≤<=*n*<=≤<=1.5·105,<=1<=≤<=*k*<=≤<=*n*) — the number of planks in the fence and the width of the hole for the piano. The second line contains the sequence of integers *h*1,<=*h*2,<=...,<=*h**n* (1<=≤<=*h**i*<=≤<=100), where *h**i* is the height of the *i*-th... | Print such integer *j* that the sum of the heights of planks *j*, *j*<=+<=1, ..., *j*<=+<=*k*<=-<=1 is the minimum possible. If there are multiple such *j*'s, print any of them. | [
"7 3\n1 2 6 1 1 7 1\n"
] | [
"3\n"
] | In the sample, your task is to find three consecutive planks with the minimum sum of heights. In the given case three planks with indexes 3, 4 and 5 have the required attribute, their total height is 8. | 1,000 | [
{
"input": "7 3\n1 2 6 1 1 7 1",
"output": "3"
},
{
"input": "1 1\n100",
"output": "1"
},
{
"input": "2 1\n10 20",
"output": "1"
},
{
"input": "10 5\n1 2 3 1 2 2 3 1 4 5",
"output": "1"
},
{
"input": "10 2\n3 1 4 1 4 6 2 1 4 6",
"output": "7"
},
{
"inp... | 1,691,481,051 | 2,147,483,647 | PyPy 3-64 | TIME_LIMIT_EXCEEDED | TESTS | 6 | 1,000 | 25,190,400 | n,k = map(int,input().split())
a = list(map(int,input().split()))
s = 100000000000000000000000000000000000000000000000
t = 0
for j in range(n-(k-1)):
if s > sum(a[j:j+k]):
s = sum(a[j:j+k])
t = j + 1
print(t)
| Title: Fence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There is a fence in front of Polycarpus's home. The fence consists of *n* planks of the same width which go one after another from left to right. The height of the *i*-th plank is *h**i* meters, distinct planks can have distinct ... | ```python
n,k = map(int,input().split())
a = list(map(int,input().split()))
s = 100000000000000000000000000000000000000000000000
t = 0
for j in range(n-(k-1)):
if s > sum(a[j:j+k]):
s = sum(a[j:j+k])
t = j + 1
print(t)
``` | 0 | |
454 | A | Little Pony and Crystal Mine | PROGRAMMING | 800 | [
"implementation"
] | null | null | Twilight Sparkle once got a crystal from the Crystal Mine. A crystal of size *n* (*n* is odd; *n*<=><=1) is an *n*<=×<=*n* matrix with a diamond inscribed into it.
You are given an odd integer *n*. You need to draw a crystal of size *n*. The diamond cells of the matrix should be represented by character "D". All ot... | The only line contains an integer *n* (3<=≤<=*n*<=≤<=101; *n* is odd). | Output a crystal of size *n*. | [
"3\n",
"5\n",
"7\n"
] | [
"*D*\nDDD\n*D*\n",
"**D**\n*DDD*\nDDDDD\n*DDD*\n**D**\n",
"***D***\n**DDD**\n*DDDDD*\nDDDDDDD\n*DDDDD*\n**DDD**\n***D***\n"
] | none | 500 | [
{
"input": "3",
"output": "*D*\nDDD\n*D*"
},
{
"input": "5",
"output": "**D**\n*DDD*\nDDDDD\n*DDD*\n**D**"
},
{
"input": "7",
"output": "***D***\n**DDD**\n*DDDDD*\nDDDDDDD\n*DDDDD*\n**DDD**\n***D***"
},
{
"input": "11",
"output": "*****D*****\n****DDD****\n***DDDDD***\n**... | 1,676,561,570 | 2,147,483,647 | Python 3 | OK | TESTS | 12 | 46 | 0 | n = int(input())
for i in range(1, n + 1, 2):
print('*' * ((n - i) // 2), end='')
print('D' * i, end='')
print('*' * ((n - i) // 2), end='')
print()
for i in range(n - 2, 0, -2):
print('*' * ((n - i) // 2), end='')
print('D' * i, end='')
print('*' * ((n - i) // 2), end='')
print() | Title: Little Pony and Crystal Mine
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Twilight Sparkle once got a crystal from the Crystal Mine. A crystal of size *n* (*n* is odd; *n*<=><=1) is an *n*<=×<=*n* matrix with a diamond inscribed into it.
You are given an odd integer *n*. You ... | ```python
n = int(input())
for i in range(1, n + 1, 2):
print('*' * ((n - i) // 2), end='')
print('D' * i, end='')
print('*' * ((n - i) // 2), end='')
print()
for i in range(n - 2, 0, -2):
print('*' * ((n - i) // 2), end='')
print('D' * i, end='')
print('*' * ((n - i) // 2), end='')
print()
``` | 3 | |
362 | B | Petya and Staircases | PROGRAMMING | 1,100 | [
"implementation",
"sortings"
] | null | null | Little boy Petya loves stairs very much. But he is bored from simple going up and down them — he loves jumping over several stairs at a time. As he stands on some stair, he can either jump to the next one or jump over one or two stairs at a time. But some stairs are too dirty and Petya doesn't want to step on them.
No... | The first line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=109, 0<=≤<=*m*<=≤<=3000) — the number of stairs in the staircase and the number of dirty stairs, correspondingly. The second line contains *m* different space-separated integers *d*1,<=*d*2,<=...,<=*d**m* (1<=≤<=*d**i*<=≤<=*n*) — the numbers of the dirty s... | Print "YES" if Petya can reach stair number *n*, stepping only on the clean stairs. Otherwise print "NO". | [
"10 5\n2 4 8 3 6\n",
"10 5\n2 4 5 7 9\n"
] | [
"NO",
"YES"
] | none | 500 | [
{
"input": "10 5\n2 4 8 3 6",
"output": "NO"
},
{
"input": "10 5\n2 4 5 7 9",
"output": "YES"
},
{
"input": "10 9\n2 3 4 5 6 7 8 9 10",
"output": "NO"
},
{
"input": "5 2\n4 5",
"output": "NO"
},
{
"input": "123 13\n36 73 111 2 92 5 47 55 48 113 7 78 37",
"outp... | 1,632,105,048 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 7 | 62 | 7,065,600 | #362B (100No. Problem B)
n,d = map(int,input().split())
stair = sorted(list(map(int,input().split())))
# print(stair)
res = 'YES'
if (1 not in stair and n not in stair):
for i in range(d-2):
if (stair[i+1] == stair[i]+1 and stair[i+2] == stair[i]+2):
res = 'NO'
break
else:
res = 'NO' ... | Title: Petya and Staircases
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little boy Petya loves stairs very much. But he is bored from simple going up and down them — he loves jumping over several stairs at a time. As he stands on some stair, he can either jump to the next one or jump o... | ```python
#362B (100No. Problem B)
n,d = map(int,input().split())
stair = sorted(list(map(int,input().split())))
# print(stair)
res = 'YES'
if (1 not in stair and n not in stair):
for i in range(d-2):
if (stair[i+1] == stair[i]+1 and stair[i+2] == stair[i]+2):
res = 'NO'
break
else:
res =... | -1 | |
895 | B | XK Segments | PROGRAMMING | 1,700 | [
"binary search",
"math",
"sortings",
"two pointers"
] | null | null | While Vasya finished eating his piece of pizza, the lesson has already started. For being late for the lesson, the teacher suggested Vasya to solve one interesting problem. Vasya has an array *a* and integer *x*. He should find the number of different ordered pairs of indexes (*i*,<=*j*) such that *a**i*<=≤<=*a**j* and... | The first line contains 3 integers *n*,<=*x*,<=*k* (1<=≤<=*n*<=≤<=105,<=1<=≤<=*x*<=≤<=109,<=0<=≤<=*k*<=≤<=109), where *n* is the size of the array *a* and *x* and *k* are numbers from the statement.
The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=109) — the elements of the array *a*. | Print one integer — the answer to the problem. | [
"4 2 1\n1 3 5 7\n",
"4 2 0\n5 3 1 7\n",
"5 3 1\n3 3 3 3 3\n"
] | [
"3\n",
"4\n",
"25\n"
] | In first sample there are only three suitable pairs of indexes — (1, 2), (2, 3), (3, 4).
In second sample there are four suitable pairs of indexes(1, 1), (2, 2), (3, 3), (4, 4).
In third sample every pair (*i*, *j*) is suitable, so the answer is 5 * 5 = 25. | 1,000 | [
{
"input": "4 2 1\n1 3 5 7",
"output": "3"
},
{
"input": "4 2 0\n5 3 1 7",
"output": "4"
},
{
"input": "5 3 1\n3 3 3 3 3",
"output": "25"
},
{
"input": "5 3 4\n24 13 1 24 24",
"output": "4"
},
{
"input": "4 2 2\n1 3 5 7",
"output": "2"
},
{
"input": "5... | 1,511,787,768 | 4,368 | Python 3 | WRONG_ANSWER | TESTS | 3 | 62 | 5,529,600 | a = []
n,x,k = map(int,input().split())
a = [int(i) for i in input().split()]
ans = 0
for i in range(n):
for j in range(i,n):
if i != j:
if a[i]%x == 0:
ans+=1
if a[j]%x == 0:
ans+=1
else:
if a[i]%x==0:
... | Title: XK Segments
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
While Vasya finished eating his piece of pizza, the lesson has already started. For being late for the lesson, the teacher suggested Vasya to solve one interesting problem. Vasya has an array *a* and integer *x*. He should ... | ```python
a = []
n,x,k = map(int,input().split())
a = [int(i) for i in input().split()]
ans = 0
for i in range(n):
for j in range(i,n):
if i != j:
if a[i]%x == 0:
ans+=1
if a[j]%x == 0:
ans+=1
else:
if a[i]%x==0:
... | 0 | |
699 | A | Launch of Collider | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | There will be a launch of a new, powerful and unusual collider very soon, which located along a straight line. *n* particles will be launched inside it. All of them are located in a straight line and there can not be two or more particles located in the same point. The coordinates of the particles coincide with the dis... | The first line contains the positive integer *n* (1<=≤<=*n*<=≤<=200<=000) — the number of particles.
The second line contains *n* symbols "L" and "R". If the *i*-th symbol equals "L", then the *i*-th particle will move to the left, otherwise the *i*-th symbol equals "R" and the *i*-th particle will move to the right.... | In the first line print the only integer — the first moment (in microseconds) when two particles are at the same point and there will be an explosion.
Print the only integer -1, if the collision of particles doesn't happen. | [
"4\nRLRL\n2 4 6 10\n",
"3\nLLR\n40 50 60\n"
] | [
"1\n",
"-1\n"
] | In the first sample case the first explosion will happen in 1 microsecond because the particles number 1 and 2 will simultaneously be at the same point with the coordinate 3.
In the second sample case there will be no explosion because there are no particles which will simultaneously be at the same point. | 500 | [
{
"input": "4\nRLRL\n2 4 6 10",
"output": "1"
},
{
"input": "3\nLLR\n40 50 60",
"output": "-1"
},
{
"input": "4\nRLLR\n46 230 264 470",
"output": "92"
},
{
"input": "6\nLLRLLL\n446 492 650 844 930 970",
"output": "97"
},
{
"input": "8\nRRLLLLLL\n338 478 512 574 59... | 1,468,937,002 | 3,502 | Python 3 | CHALLENGED | CHALLENGES | 7 | 171 | 15,974,400 | def main():
n = int(input())
s = input()
arr, ans = [int(i) for i in input().split()], 99999
for i in range(len(s)):
if s[i] == 'L' and s[i-1] == 'R' and i > 0:
ans = min(ans, arr[i]//2 - arr[i - 1]//2)
print(ans if ans != 99999 else -1)
if __name__ == '__main__':
main() | Title: Launch of Collider
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There will be a launch of a new, powerful and unusual collider very soon, which located along a straight line. *n* particles will be launched inside it. All of them are located in a straight line and there can not be... | ```python
def main():
n = int(input())
s = input()
arr, ans = [int(i) for i in input().split()], 99999
for i in range(len(s)):
if s[i] == 'L' and s[i-1] == 'R' and i > 0:
ans = min(ans, arr[i]//2 - arr[i - 1]//2)
print(ans if ans != 99999 else -1)
if __name__ == '__main__':
main()
``` | -1 | |
125 | B | Simple XML | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Let's define a string <x> as an opening tag, where *x* is any small letter of the Latin alphabet. Each opening tag matches a closing tag of the type </x>, where *x* is the same letter.
Tegs can be nested into each other: in this case one opening and closing tag pair is located inside another pair.
Let's d... | The input data consists on the only non-empty string — the XML-text, its length does not exceed 1000 characters. It is guaranteed that the text is valid. The text contains no spaces. | Print the given XML-text according to the above-given rules. | [
"<a><b><c></c></b></a>\n",
"<a><b></b><d><c></c></d></a>\n"
] | [
"<a>\n <b>\n <c>\n </c>\n </b>\n</a>\n",
"<a>\n <b>\n </b>\n <d>\n <c>\n </c>\n </d>\n</a>\n"
] | none | 1,500 | [
{
"input": "<a><b><c></c></b></a>",
"output": "<a>\n <b>\n <c>\n </c>\n </b>\n</a>"
},
{
"input": "<a><b></b><d><c></c></d></a>",
"output": "<a>\n <b>\n </b>\n <d>\n <c>\n </c>\n </d>\n</a>"
},
{
"input": "<z></z>",
"output": "<z>\n</z>"
},
{
"input": "<u><d... | 1,604,587,564 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 184 | 0 | a = input().split('>')
bal = 0
for s in a:
if len(s):
continue
if (s[1] == '/' ):
print(bal * " " + s+ ">")
bal -= 1
else:
print(bal * " " + s + ">")
bal +=1
| Title: Simple XML
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Let's define a string <x> as an opening tag, where *x* is any small letter of the Latin alphabet. Each opening tag matches a closing tag of the type </x>, where *x* is the same letter.
Tegs can be nested into ea... | ```python
a = input().split('>')
bal = 0
for s in a:
if len(s):
continue
if (s[1] == '/' ):
print(bal * " " + s+ ">")
bal -= 1
else:
print(bal * " " + s + ">")
bal +=1
``` | -1 | |
347 | B | Fixed Points | PROGRAMMING | 1,100 | [
"brute force",
"implementation",
"math"
] | null | null | A permutation of length *n* is an integer sequence such that each integer from 0 to (*n*<=-<=1) appears exactly once in it. For example, sequence [0,<=2,<=1] is a permutation of length 3 while both [0,<=2,<=2] and [1,<=2,<=3] are not.
A fixed point of a function is a point that is mapped to itself by the function. A p... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105). The second line contains *n* integers *a*0,<=*a*1,<=...,<=*a**n*<=-<=1 — the given permutation. | Print a single integer — the maximum possible number of fixed points in the permutation after at most one swap operation. | [
"5\n0 1 3 4 2\n"
] | [
"3\n"
] | none | 1,000 | [
{
"input": "5\n0 1 3 4 2",
"output": "3"
},
{
"input": "10\n6 9 4 7 8 2 3 5 0 1",
"output": "2"
},
{
"input": "100\n99 5 40 32 4 31 38 57 94 47 26 16 89 72 9 80 55 86 78 90 42 41 46 74 56 97 21 48 66 27 93 85 88 59 64 95 10 45 12 22 84 60 8 98 62 51 14 65 39 30 11 71 92 19 76 43 87 54 15... | 1,623,826,070 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 1 | 186 | 0 | # B. Fixed Points
n=int(input())
a=list(map(int,input().split()))
c=0
e=[]
for i in range(n):
if i==a[i]:
c+=1
else:
e.append([a[i],i])
if c==n-2:
print(n)
else:
f=0
for i in e:
if i[::-1] in e:
c+=n-2
f=1
print(c)
... | Title: Fixed Points
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A permutation of length *n* is an integer sequence such that each integer from 0 to (*n*<=-<=1) appears exactly once in it. For example, sequence [0,<=2,<=1] is a permutation of length 3 while both [0,<=2,<=2] and [1,<=2,<... | ```python
# B. Fixed Points
n=int(input())
a=list(map(int,input().split()))
c=0
e=[]
for i in range(n):
if i==a[i]:
c+=1
else:
e.append([a[i],i])
if c==n-2:
print(n)
else:
f=0
for i in e:
if i[::-1] in e:
c+=n-2
f=1
print(... | 0 | |
185 | B | Mushroom Scientists | PROGRAMMING | 1,800 | [
"math",
"ternary search"
] | null | null | As you very well know, the whole Universe traditionally uses three-dimensional Cartesian system of coordinates. In this system each point corresponds to three real coordinates (*x*,<=*y*,<=*z*). In this coordinate system, the distance between the center of the Universe and the point is calculated by the following formu... | The first line contains a single integer *S* (1<=≤<=*S*<=≤<=103) — the maximum sum of coordinates of the sought point.
The second line contains three space-separated integers *a*, *b*, *c* (0<=≤<=*a*,<=*b*,<=*c*<=≤<=103) — the numbers that describe the metric of mushroom scientists. | Print three real numbers — the coordinates of the point that reaches maximum value in the metrics of mushroom scientists. If there are multiple answers, print any of them that meets the limitations.
A natural logarithm of distance from the center of the Universe to the given point in the metric of mushroom scientists ... | [
"3\n1 1 1\n",
"3\n2 0 0\n"
] | [
"1.0 1.0 1.0\n",
"3.0 0.0 0.0\n"
] | none | 1,000 | [
{
"input": "3\n1 1 1",
"output": "1.0 1.0 1.0"
},
{
"input": "3\n2 0 0",
"output": "3.0 0.0 0.0"
},
{
"input": "10\n1 6 3",
"output": "1.0 6.0 3.0"
},
{
"input": "9\n8 2 0",
"output": "7.2 1.8 0.0"
},
{
"input": "1\n0 9 2",
"output": "0.0 0.8181818181818182 0.... | 1,637,613,187 | 2,147,483,647 | PyPy 3 | RUNTIME_ERROR | TESTS | 9 | 248 | 2,150,400 | def f1(x,y,a,b,c,s):
return x**a*y**b*(s-x-y)**c
def f2(x,a,b,c,s):
l,r=0,s-x
while r-l>10**-10:
m1,m2=l+(r-l)/3,r-(r-l)/3
if f1(x,m1,a,b,c,s)>f1(x,m2,a,b,c,s):
r=m2
else:
l=m1
return r
def f3(a,b,c,s):
l,r=0,s
while r-l>10**-10:
... | Title: Mushroom Scientists
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
As you very well know, the whole Universe traditionally uses three-dimensional Cartesian system of coordinates. In this system each point corresponds to three real coordinates (*x*,<=*y*,<=*z*). In this coordinate s... | ```python
def f1(x,y,a,b,c,s):
return x**a*y**b*(s-x-y)**c
def f2(x,a,b,c,s):
l,r=0,s-x
while r-l>10**-10:
m1,m2=l+(r-l)/3,r-(r-l)/3
if f1(x,m1,a,b,c,s)>f1(x,m2,a,b,c,s):
r=m2
else:
l=m1
return r
def f3(a,b,c,s):
l,r=0,s
while r-l>10**... | -1 | |
540 | A | Combination Lock | PROGRAMMING | 800 | [
"implementation"
] | null | null | Scrooge McDuck keeps his most treasured savings in a home safe with a combination lock. Each time he wants to put there the treasures that he's earned fair and square, he has to open the lock.
The combination lock is represented by *n* rotating disks with digits from 0 to 9 written on them. Scrooge McDuck has to turn ... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of disks on the combination lock.
The second line contains a string of *n* digits — the original state of the disks.
The third line contains a string of *n* digits — Scrooge McDuck's combination that opens the lock. | Print a single integer — the minimum number of moves Scrooge McDuck needs to open the lock. | [
"5\n82195\n64723\n"
] | [
"13\n"
] | In the sample he needs 13 moves:
- 1 disk: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/b8967f65a723782358b93eff9ce69f336817cf70.png" style="max-width: 100.0%;max-height: 100.0%;"/> - 2 disk: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/07fa58573ece0d32... | 500 | [
{
"input": "5\n82195\n64723",
"output": "13"
},
{
"input": "12\n102021090898\n010212908089",
"output": "16"
},
{
"input": "1\n8\n1",
"output": "3"
},
{
"input": "2\n83\n57",
"output": "7"
},
{
"input": "10\n0728592530\n1362615763",
"output": "27"
},
{
... | 1,643,112,512 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | n=int(input())
c=0
for i in range(n):
a=input()
b=input()
c+=min(10-abs(a[i]-b[i]),a[i]-b[i]
print(c) | Title: Combination Lock
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Scrooge McDuck keeps his most treasured savings in a home safe with a combination lock. Each time he wants to put there the treasures that he's earned fair and square, he has to open the lock.
The combination lock is ... | ```python
n=int(input())
c=0
for i in range(n):
a=input()
b=input()
c+=min(10-abs(a[i]-b[i]),a[i]-b[i]
print(c)
``` | -1 | |
884 | B | Japanese Crosswords Strike Back | PROGRAMMING | 1,100 | [
"implementation"
] | null | null | A one-dimensional Japanese crossword can be represented as a binary string of length *x*. An encoding of this crossword is an array *a* of size *n*, where *n* is the number of segments formed completely of 1's, and *a**i* is the length of *i*-th segment. No two segments touch or intersect.
For example:
- If *x*<==<... | The first line contains two integer numbers *n* and *x* (1<=≤<=*n*<=≤<=100000, 1<=≤<=*x*<=≤<=109) — the number of elements in the encoding and the length of the crossword Mishka picked.
The second line contains *n* integer numbers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=10000) — the encoding. | Print YES if there exists exaclty one crossword with chosen length and encoding. Otherwise, print NO. | [
"2 4\n1 3\n",
"3 10\n3 3 2\n",
"2 10\n1 3\n"
] | [
"NO\n",
"YES\n",
"NO\n"
] | none | 0 | [
{
"input": "2 4\n1 3",
"output": "NO"
},
{
"input": "3 10\n3 3 2",
"output": "YES"
},
{
"input": "2 10\n1 3",
"output": "NO"
},
{
"input": "1 1\n1",
"output": "YES"
},
{
"input": "1 10\n10",
"output": "YES"
},
{
"input": "1 10000\n10000",
"output":... | 1,630,333,333 | 2,147,483,647 | Python 3 | OK | TESTS | 66 | 93 | 14,438,400 | R=lambda:list(map(int,input().split()))
n,x=R()
print('YES'if sum(R())+n-1==x else'NO')
| Title: Japanese Crosswords Strike Back
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A one-dimensional Japanese crossword can be represented as a binary string of length *x*. An encoding of this crossword is an array *a* of size *n*, where *n* is the number of segments formed completely ... | ```python
R=lambda:list(map(int,input().split()))
n,x=R()
print('YES'if sum(R())+n-1==x else'NO')
``` | 3 | |
120 | A | Elevator | PROGRAMMING | 1,000 | [
"brute force",
"implementation",
"math"
] | null | null | A sky scraper with 1000 floors has been built in the city of N. It has modern superfast elevators to help to travel from one floor to another. Each elevator has two doors, the front one and the back one. If one goes in through the front door, he goes out through the back one and vice versa. The elevator has two rails n... | The first line indicates the door through which the very important person entered the elevator. It contains "front" if the person enters the elevator through the front door and "back" if he entered the elevator through the back door. The second line contains integer *a* (1<=≤<=*a*<=≤<=2) which denotes the number of the... | Print character "R" if the VIP is right-handed or "L" if he is left-handed. | [
"front\n1\n"
] | [
"L\n"
] | none | 0 | [
{
"input": "front\n1",
"output": "L"
},
{
"input": "back\n1",
"output": "R"
},
{
"input": "front\n2",
"output": "R"
},
{
"input": "back\n2",
"output": "L"
}
] | 1,691,386,571 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 30 | 0 | x= input()
y = int(input())
if ( x == "back" and y == 1) or (x == "front" and y == 2) :
print("R")
else:
print("L") | Title: Elevator
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A sky scraper with 1000 floors has been built in the city of N. It has modern superfast elevators to help to travel from one floor to another. Each elevator has two doors, the front one and the back one. If one goes in through... | ```python
x= input()
y = int(input())
if ( x == "back" and y == 1) or (x == "front" and y == 2) :
print("R")
else:
print("L")
``` | -1 | |
16 | A | Flag | PROGRAMMING | 800 | [
"implementation"
] | A. Flag | 2 | 64 | According to a new ISO standard, a flag of every country should have a chequered field *n*<=×<=*m*, each square should be of one of 10 colours, and the flag should be «striped»: each horizontal row of the flag should contain squares of the same colour, and the colours of adjacent horizontal rows should be different. Be... | The first line of the input contains numbers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100), *n* — the amount of rows, *m* — the amount of columns on the flag of Berland. Then there follows the description of the flag: each of the following *n* lines contain *m* characters. Each character is a digit between 0 and 9, and stands ... | Output YES, if the flag meets the new ISO standard, and NO otherwise. | [
"3 3\n000\n111\n222\n",
"3 3\n000\n000\n111\n",
"3 3\n000\n111\n002\n"
] | [
"YES\n",
"NO\n",
"NO\n"
] | none | 0 | [
{
"input": "3 3\n000\n111\n222",
"output": "YES"
},
{
"input": "3 3\n000\n000\n111",
"output": "NO"
},
{
"input": "3 3\n000\n111\n002",
"output": "NO"
},
{
"input": "10 10\n2222222222\n5555555555\n0000000000\n4444444444\n1111111111\n3333333393\n3333333333\n5555555555\n0000000... | 1,672,108,282 | 2,147,483,647 | Python 3 | OK | TESTS | 35 | 92 | 0 | n,m=map(int,input().split())
flag=True
for run in range(n):
s=input()
new=''
for ele in s:
if ele not in new:
new+=ele
if len(new)>1:
flag=False
break
if run==0:
temp=s
else:
if s==temp:
flag=False
break
... | Title: Flag
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
According to a new ISO standard, a flag of every country should have a chequered field *n*<=×<=*m*, each square should be of one of 10 colours, and the flag should be «striped»: each horizontal row of the flag should contain squares of... | ```python
n,m=map(int,input().split())
flag=True
for run in range(n):
s=input()
new=''
for ele in s:
if ele not in new:
new+=ele
if len(new)>1:
flag=False
break
if run==0:
temp=s
else:
if s==temp:
flag=False
... | 3.977 |
137 | B | Permutation | PROGRAMMING | 1,000 | [
"greedy"
] | null | null | "Hey, it's homework time" — thought Polycarpus and of course he started with his favourite subject, IT. Polycarpus managed to solve all tasks but for the last one in 20 minutes. However, as he failed to solve the last task after some considerable time, the boy asked you to help him.
The sequence of *n* integers is cal... | The first line of the input data contains an integer *n* (1<=≤<=*n*<=≤<=5000) which represents how many numbers are in the sequence. The second line contains a sequence of integers *a**i* (1<=≤<=*a**i*<=≤<=5000,<=1<=≤<=*i*<=≤<=*n*). | Print the only number — the minimum number of changes needed to get the permutation. | [
"3\n3 1 2\n",
"2\n2 2\n",
"5\n5 3 3 3 1\n"
] | [
"0\n",
"1\n",
"2\n"
] | The first sample contains the permutation, which is why no replacements are required.
In the second sample it is enough to replace the first element with the number 1 and that will make the sequence the needed permutation.
In the third sample we can replace the second element with number 4 and the fourth element with... | 1,000 | [
{
"input": "3\n3 1 2",
"output": "0"
},
{
"input": "2\n2 2",
"output": "1"
},
{
"input": "5\n5 3 3 3 1",
"output": "2"
},
{
"input": "5\n6 6 6 6 6",
"output": "5"
},
{
"input": "10\n1 1 2 2 8 8 7 7 9 9",
"output": "5"
},
{
"input": "8\n9 8 7 6 5 4 3 2"... | 1,591,304,585 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 186 | 307,200 | def numfact(n,u):
t=[]
for i in range (1,n+1):
t.append(i)
u.sort(reverse=True)
t.sort(reverse=True)
j=list(set(u).symmetric_difference(set(t)))
y=len(j)
return y
n=int(input())
data= input()
data=data.split()
data=[int(i) for i in data]
print (numfact(n,data))
... | Title: Permutation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
"Hey, it's homework time" — thought Polycarpus and of course he started with his favourite subject, IT. Polycarpus managed to solve all tasks but for the last one in 20 minutes. However, as he failed to solve the last task ... | ```python
def numfact(n,u):
t=[]
for i in range (1,n+1):
t.append(i)
u.sort(reverse=True)
t.sort(reverse=True)
j=list(set(u).symmetric_difference(set(t)))
y=len(j)
return y
n=int(input())
data= input()
data=data.split()
data=[int(i) for i in data]
print (numfact(n,data))
... | 0 | |
320 | A | Magic Numbers | PROGRAMMING | 900 | [
"brute force",
"greedy"
] | null | null | A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not.
You're given a number. Determine if it is a magic number or not. | The first line of input contains an integer *n*, (1<=≤<=*n*<=≤<=109). This number doesn't contain leading zeros. | Print "YES" if *n* is a magic number or print "NO" if it's not. | [
"114114\n",
"1111\n",
"441231\n"
] | [
"YES\n",
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "114114",
"output": "YES"
},
{
"input": "1111",
"output": "YES"
},
{
"input": "441231",
"output": "NO"
},
{
"input": "1",
"output": "YES"
},
{
"input": "14",
"output": "YES"
},
{
"input": "114",
"output": "YES"
},
{
"input": "9",... | 1,621,827,978 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 7 | 154 | 0 | nums = input()
good = True
for i in nums:
if i != '1' and i != '4':
good = False
break
if good:
print('YES')
else:
print('NO') | Title: Magic Numbers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not.
You're ... | ```python
nums = input()
good = True
for i in nums:
if i != '1' and i != '4':
good = False
break
if good:
print('YES')
else:
print('NO')
``` | 0 | |
832 | A | Sasha and Sticks | PROGRAMMING | 800 | [
"games",
"math"
] | null | null | It's one more school day now. Sasha doesn't like classes and is always bored at them. So, each day he invents some game and plays in it alone or with friends.
Today he invented one simple game to play with Lena, with whom he shares a desk. The rules are simple. Sasha draws *n* sticks in a row. After that the players t... | The first line contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=1018, *k*<=≤<=*n*) — the number of sticks drawn by Sasha and the number *k* — the number of sticks to be crossed out on each turn. | If Sasha wins, print "YES" (without quotes), otherwise print "NO" (without quotes).
You can print each letter in arbitrary case (upper of lower). | [
"1 1\n",
"10 4\n"
] | [
"YES\n",
"NO\n"
] | In the first example Sasha crosses out 1 stick, and then there are no sticks. So Lena can't make a move, and Sasha wins.
In the second example Sasha crosses out 4 sticks, then Lena crosses out 4 sticks, and after that there are only 2 sticks left. Sasha can't make a move. The players make equal number of moves, so Sas... | 500 | [
{
"input": "1 1",
"output": "YES"
},
{
"input": "10 4",
"output": "NO"
},
{
"input": "251656215122324104 164397544865601257",
"output": "YES"
},
{
"input": "963577813436662285 206326039287271924",
"output": "NO"
},
{
"input": "1000000000000000000 1",
"output":... | 1,618,751,331 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 62 | 0 | n,k=map(int,input().split())
status=0
if n%k==0:
status=0
else:
status=1
if status==0:
print('YES')
else:
print('NO')
| Title: Sasha and Sticks
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
It's one more school day now. Sasha doesn't like classes and is always bored at them. So, each day he invents some game and plays in it alone or with friends.
Today he invented one simple game to play with Lena, with ... | ```python
n,k=map(int,input().split())
status=0
if n%k==0:
status=0
else:
status=1
if status==0:
print('YES')
else:
print('NO')
``` | 0 | |
788 | A | Functions again | PROGRAMMING | 1,600 | [
"dp",
"two pointers"
] | null | null | Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function *f*, which is defined ... | The first line contains single integer *n* (2<=≤<=*n*<=≤<=105) — the size of the array *a*.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (-109<=≤<=*a**i*<=≤<=109) — the array elements. | Print the only integer — the maximum value of *f*. | [
"5\n1 4 2 3 1\n",
"4\n1 5 4 7\n"
] | [
"3",
"6"
] | In the first sample case, the optimal value of *f* is reached on intervals [1, 2] and [2, 5].
In the second case maximal value of *f* is reachable only on the whole array. | 500 | [
{
"input": "5\n1 4 2 3 1",
"output": "3"
},
{
"input": "4\n1 5 4 7",
"output": "6"
},
{
"input": "8\n16 14 12 10 8 100 50 0",
"output": "92"
},
{
"input": "2\n1 1",
"output": "0"
},
{
"input": "50\n-5 -9 0 44 -10 37 34 -49 11 -22 -26 44 8 -13 23 -46 34 12 -24 2 -4... | 1,490,862,372 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 8 | 1,000 | 4,608,000 | def f(a, l, r):
count = 0
for i in range(l, r):
count += abs(a[i-1]-a[i])*(-1)**(i-l)
return count
n = int(input())
a = input().split()
for i in range(len(a)):
a[i] = int(a[i])
maxF = 0
for r in range(2, n+1):
for l in range(1, r):
function = f(a, l, r)
if function > maxF:
... | Title: Functions again
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found t... | ```python
def f(a, l, r):
count = 0
for i in range(l, r):
count += abs(a[i-1]-a[i])*(-1)**(i-l)
return count
n = int(input())
a = input().split()
for i in range(len(a)):
a[i] = int(a[i])
maxF = 0
for r in range(2, n+1):
for l in range(1, r):
function = f(a, l, r)
if function... | 0 | |
940 | A | Points on the line | PROGRAMMING | 1,200 | [
"brute force",
"greedy",
"sortings"
] | null | null | We've got no test cases. A big olympiad is coming up. But the problemsetters' number one priority should be adding another problem to the round.
The diameter of a multiset of points on the line is the largest distance between two points from this set. For example, the diameter of the multiset {1,<=3,<=2,<=1} is 2.
D... | The first line contains two integers *n* and *d* (1<=≤<=*n*<=≤<=100,<=0<=≤<=*d*<=≤<=100) — the amount of points and the maximum allowed diameter respectively.
The second line contains *n* space separated integers (1<=≤<=*x**i*<=≤<=100) — the coordinates of the points. | Output a single integer — the minimum number of points you have to remove. | [
"3 1\n2 1 4\n",
"3 0\n7 7 7\n",
"6 3\n1 3 4 6 9 10\n"
] | [
"1\n",
"0\n",
"3\n"
] | In the first test case the optimal strategy is to remove the point with coordinate 4. The remaining points will have coordinates 1 and 2, so the diameter will be equal to 2 - 1 = 1.
In the second test case the diameter is equal to 0, so its is unnecessary to remove any points.
In the third test case the optimal stra... | 500 | [
{
"input": "3 1\n2 1 4",
"output": "1"
},
{
"input": "3 0\n7 7 7",
"output": "0"
},
{
"input": "6 3\n1 3 4 6 9 10",
"output": "3"
},
{
"input": "11 5\n10 11 12 13 14 15 16 17 18 19 20",
"output": "5"
},
{
"input": "1 100\n1",
"output": "0"
},
{
"input"... | 1,591,251,191 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 5 | 124 | 0 | n,m=(map(int,input().split()))
ln=list(map(int,input().split()))
# lm=list(map(int,input().split()))
ln.sort()
v=ln[0]+m
c=0
for i in range(n):
if(ln[i]>v):
c+=1
print(c) | Title: Points on the line
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
We've got no test cases. A big olympiad is coming up. But the problemsetters' number one priority should be adding another problem to the round.
The diameter of a multiset of points on the line is the largest dista... | ```python
n,m=(map(int,input().split()))
ln=list(map(int,input().split()))
# lm=list(map(int,input().split()))
ln.sort()
v=ln[0]+m
c=0
for i in range(n):
if(ln[i]>v):
c+=1
print(c)
``` | 0 | |
545 | C | Woodcutters | PROGRAMMING | 1,500 | [
"dp",
"greedy"
] | null | null | Little Susie listens to fairy tales before bed every day. Today's fairy tale was about wood cutters and the little girl immediately started imagining the choppers cutting wood. She imagined the situation that is described below.
There are *n* trees located along the road at points with coordinates *x*1,<=*x*2,<=...,<=... | The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of trees.
Next *n* lines contain pairs of integers *x**i*,<=*h**i* (1<=≤<=*x**i*,<=*h**i*<=≤<=109) — the coordinate and the height of the *і*-th tree.
The pairs are given in the order of ascending *x**i*. No two trees are located at the point with t... | Print a single number — the maximum number of trees that you can cut down by the given rules. | [
"5\n1 2\n2 1\n5 10\n10 9\n19 1\n",
"5\n1 2\n2 1\n5 10\n10 9\n20 1\n"
] | [
"3\n",
"4\n"
] | In the first sample you can fell the trees like that:
- fell the 1-st tree to the left — now it occupies segment [ - 1;1] - fell the 2-nd tree to the right — now it occupies segment [2;3] - leave the 3-rd tree — it occupies point 5 - leave the 4-th tree — it occupies point 10 - fell the 5-th tree to the right — ... | 1,750 | [
{
"input": "5\n1 2\n2 1\n5 10\n10 9\n19 1",
"output": "3"
},
{
"input": "5\n1 2\n2 1\n5 10\n10 9\n20 1",
"output": "4"
},
{
"input": "4\n10 4\n15 1\n19 3\n20 1",
"output": "4"
},
{
"input": "35\n1 7\n3 11\n6 12\n7 6\n8 5\n9 11\n15 3\n16 10\n22 2\n23 3\n25 7\n27 3\n34 5\n35 10... | 1,697,859,059 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 8 | 311 | 19,865,600 | '''
2300015897
吴杰稀
光华管理学院
'''
cases = int(input())
tree_list = []
for i in range(cases):
tree_list.append(list(map(int,input().split())))
end = tree_list[0][0]
i,add_up = 1,2
while i < len(tree_list) - 1:
if tree_list[i][0] - tree_list[i][1] > end:
end = tree_list[i][0]
add_u... | Title: Woodcutters
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Susie listens to fairy tales before bed every day. Today's fairy tale was about wood cutters and the little girl immediately started imagining the choppers cutting wood. She imagined the situation that is described b... | ```python
'''
2300015897
吴杰稀
光华管理学院
'''
cases = int(input())
tree_list = []
for i in range(cases):
tree_list.append(list(map(int,input().split())))
end = tree_list[0][0]
i,add_up = 1,2
while i < len(tree_list) - 1:
if tree_list[i][0] - tree_list[i][1] > end:
end = tree_list[i][0]
... | 0 | |
902 | B | Coloring a Tree | PROGRAMMING | 1,200 | [
"dfs and similar",
"dsu",
"greedy"
] | null | null | You are given a rooted tree with *n* vertices. The vertices are numbered from 1 to *n*, the root is the vertex number 1.
Each vertex has a color, let's denote the color of vertex *v* by *c**v*. Initially *c**v*<==<=0.
You have to color the tree into the given colors using the smallest possible number of steps. On eac... | The first line contains a single integer *n* (2<=≤<=*n*<=≤<=104) — the number of vertices in the tree.
The second line contains *n*<=-<=1 integers *p*2,<=*p*3,<=...,<=*p**n* (1<=≤<=*p**i*<=<<=*i*), where *p**i* means that there is an edge between vertices *i* and *p**i*.
The third line contains *n* integers *c*1,<... | Print a single integer — the minimum number of steps you have to perform to color the tree into given colors. | [
"6\n1 2 2 1 5\n2 1 1 1 1 1\n",
"7\n1 1 2 3 1 4\n3 3 1 1 1 2 3\n"
] | [
"3\n",
"5\n"
] | The tree from the first sample is shown on the picture (numbers are vetices' indices):
<img class="tex-graphics" src="https://espresso.codeforces.com/10324ccdc37f95343acc4f3c6050d8c334334ffa.png" style="max-width: 100.0%;max-height: 100.0%;"/>
On first step we color all vertices in the subtree of vertex 1 into color ... | 1,000 | [
{
"input": "6\n1 2 2 1 5\n2 1 1 1 1 1",
"output": "3"
},
{
"input": "7\n1 1 2 3 1 4\n3 3 1 1 1 2 3",
"output": "5"
},
{
"input": "2\n1\n2 2",
"output": "1"
},
{
"input": "3\n1 1\n2 2 2",
"output": "1"
},
{
"input": "4\n1 2 1\n1 2 3 4",
"output": "4"
},
{
... | 1,598,674,180 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 17 | 171 | 2,457,600 | n = int(input())
nodes = list(map(int,input().split()))
color = list(map(int,input().split()))
from collections import defaultdict
def DFS(d,x,visited,color):
c = 0
visited[x] = 1
z = 0
for j in d[x]:
if visited[j] == 0 and color[x-1] != color[j-1]:
c = c + 1 + DFS(d,j,visited,color)
... | Title: Coloring a Tree
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a rooted tree with *n* vertices. The vertices are numbered from 1 to *n*, the root is the vertex number 1.
Each vertex has a color, let's denote the color of vertex *v* by *c**v*. Initially *c**v*<==<=0.
... | ```python
n = int(input())
nodes = list(map(int,input().split()))
color = list(map(int,input().split()))
from collections import defaultdict
def DFS(d,x,visited,color):
c = 0
visited[x] = 1
z = 0
for j in d[x]:
if visited[j] == 0 and color[x-1] != color[j-1]:
c = c + 1 + DFS(d,j,visited,... | -1 | |
585 | A | Gennady the Dentist | PROGRAMMING | 1,800 | [
"brute force",
"implementation"
] | null | null | Gennady is one of the best child dentists in Berland. Today *n* children got an appointment with him, they lined up in front of his office.
All children love to cry loudly at the reception at the dentist. We enumerate the children with integers from 1 to *n* in the order they go in the line. Every child is associated ... | The first line of the input contains a positive integer *n* (1<=≤<=*n*<=≤<=4000) — the number of kids in the line.
Next *n* lines contain three integers each *v**i*,<=*d**i*,<=*p**i* (1<=≤<=*v**i*,<=*d**i*,<=*p**i*<=≤<=106) — the volume of the cry in the doctor's office, the volume of the cry in the hall and the conf... | In the first line print number *k* — the number of children whose teeth Gennady will cure.
In the second line print *k* integers — the numbers of the children who will make it to the end of the line in the increasing order. | [
"5\n4 2 2\n4 1 2\n5 2 4\n3 3 5\n5 1 2\n",
"5\n4 5 1\n5 3 9\n4 1 2\n2 1 8\n4 1 9\n"
] | [
"2\n1 3 ",
"4\n1 2 4 5 "
] | In the first example, Gennady first treats the teeth of the first child who will cry with volume 4. The confidences of the remaining children will get equal to - 2, 1, 3, 1, respectively. Thus, the second child also cries at the volume of 1 and run to the exit. The confidence of the remaining children will be equal to... | 500 | [
{
"input": "5\n4 2 2\n4 1 2\n5 2 4\n3 3 5\n5 1 2",
"output": "2\n1 3 "
},
{
"input": "5\n4 5 1\n5 3 9\n4 1 2\n2 1 8\n4 1 9",
"output": "4\n1 2 4 5 "
},
{
"input": "10\n10 7 10\n3 6 11\n8 4 10\n10 1 11\n7 3 13\n7 2 13\n7 6 14\n3 4 17\n9 4 20\n5 2 24",
"output": "3\n1 2 5 "
},
{
... | 1,644,608,242 | 2,147,483,647 | PyPy 3 | RUNTIME_ERROR | TESTS | 0 | 77 | 2,150,400 | from dataclasses import dataclass
@dataclass
class Child:
num: int
pain: int
loudness: int
conf: int
alive: bool
k = int(input())
children = []
for i in range(1, k + 1):
p, l, c = map(int, input().split())
children.append(Child(i, p, l, c, True))
index = 0
res = []
def panic(c):
... | Title: Gennady the Dentist
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Gennady is one of the best child dentists in Berland. Today *n* children got an appointment with him, they lined up in front of his office.
All children love to cry loudly at the reception at the dentist. We enumer... | ```python
from dataclasses import dataclass
@dataclass
class Child:
num: int
pain: int
loudness: int
conf: int
alive: bool
k = int(input())
children = []
for i in range(1, k + 1):
p, l, c = map(int, input().split())
children.append(Child(i, p, l, c, True))
index = 0
res = []
def pan... | -1 | |
372 | A | Counting Kangaroos is Fun | PROGRAMMING | 1,600 | [
"binary search",
"greedy",
"sortings",
"two pointers"
] | null | null | There are *n* kangaroos with pockets. Each kangaroo has a size (integer number). A kangaroo can go into another kangaroo's pocket if and only if the size of kangaroo who hold the kangaroo is at least twice as large as the size of kangaroo who is held.
Each kangaroo can hold at most one kangaroo, and the kangaroo who i... | The first line contains a single integer — *n* (1<=≤<=*n*<=≤<=5·105). Each of the next *n* lines contains an integer *s**i* — the size of the *i*-th kangaroo (1<=≤<=*s**i*<=≤<=105). | Output a single integer — the optimal number of visible kangaroos. | [
"8\n2\n5\n7\n6\n9\n8\n4\n2\n",
"8\n9\n1\n6\n2\n6\n5\n8\n3\n"
] | [
"5\n",
"5\n"
] | none | 500 | [
{
"input": "8\n2\n5\n7\n6\n9\n8\n4\n2",
"output": "5"
},
{
"input": "8\n9\n1\n6\n2\n6\n5\n8\n3",
"output": "5"
},
{
"input": "12\n3\n99\n24\n46\n75\n63\n57\n55\n10\n62\n34\n52",
"output": "7"
},
{
"input": "12\n55\n75\n1\n98\n63\n64\n9\n39\n82\n18\n47\n9",
"output": "6"
... | 1,696,153,586 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 31 | 0 | def minimal_visible_kangaroos(kangaroos):
kangaroos.sort(reverse=True, key=lambda x: x[0])
visible_kangaroos = []
held_kangaroos = []
for kangaroo in kangaroos:
size, index = kangaroo
if not held_kangaroos or size < held_kangaroos[0][0] * 2:
visible_kangaroos.append((size, i... | Title: Counting Kangaroos is Fun
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* kangaroos with pockets. Each kangaroo has a size (integer number). A kangaroo can go into another kangaroo's pocket if and only if the size of kangaroo who hold the kangaroo is at least twice as ... | ```python
def minimal_visible_kangaroos(kangaroos):
kangaroos.sort(reverse=True, key=lambda x: x[0])
visible_kangaroos = []
held_kangaroos = []
for kangaroo in kangaroos:
size, index = kangaroo
if not held_kangaroos or size < held_kangaroos[0][0] * 2:
visible_kangaroos.appen... | -1 | |
20 | A | BerOS file system | PROGRAMMING | 1,700 | [
"implementation"
] | A. BerOS file system | 2 | 64 | The new operating system BerOS has a nice feature. It is possible to use any number of characters '/' as a delimiter in path instead of one traditional '/'. For example, strings //usr///local//nginx/sbin// and /usr/local/nginx///sbin are equivalent. The character '/' (or some sequence of such characters) at the end of ... | The first line of the input contains only lowercase Latin letters and character '/' — the path to some directory. All paths start with at least one character '/'. The length of the given line is no more than 100 characters, it is not empty. | The path in normalized form. | [
"//usr///local//nginx/sbin\n"
] | [
"/usr/local/nginx/sbin\n"
] | none | 500 | [
{
"input": "//usr///local//nginx/sbin",
"output": "/usr/local/nginx/sbin"
},
{
"input": "////a//b/////g",
"output": "/a/b/g"
},
{
"input": "/a/b/c",
"output": "/a/b/c"
},
{
"input": "/",
"output": "/"
},
{
"input": "////",
"output": "/"
},
{
"input": "... | 1,642,166,560 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 5 | 62 | 0 | s = input()
while "//" in s:
s = s.replace("//", "/", 1000)
print(s) | Title: BerOS file system
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
The new operating system BerOS has a nice feature. It is possible to use any number of characters '/' as a delimiter in path instead of one traditional '/'. For example, strings //usr///local//nginx/sbin// and /usr/local/n... | ```python
s = input()
while "//" in s:
s = s.replace("//", "/", 1000)
print(s)
``` | 0 |
131 | A | cAPS lOCK | PROGRAMMING | 1,000 | [
"implementation",
"strings"
] | null | null | wHAT DO WE NEED cAPS LOCK FOR?
Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in the first passage.
Let's consider that a word has been typed with the Caps lock key accidentall... | The first line of the input data contains a word consisting of uppercase and lowercase Latin letters. The word's length is from 1 to 100 characters, inclusive. | Print the result of the given word's processing. | [
"cAPS\n",
"Lock\n"
] | [
"Caps",
"Lock\n"
] | none | 500 | [
{
"input": "cAPS",
"output": "Caps"
},
{
"input": "Lock",
"output": "Lock"
},
{
"input": "cAPSlOCK",
"output": "cAPSlOCK"
},
{
"input": "CAPs",
"output": "CAPs"
},
{
"input": "LoCK",
"output": "LoCK"
},
{
"input": "OOPS",
"output": "oops"
},
{
... | 1,698,172,712 | 2,147,483,647 | Python 3 | OK | TESTS | 56 | 46 | 0 | st=input()
count=0
for i in st:
if i.islower():
count+=1
if count<=1 and st[0].islower():
print(st.title())
elif st.isupper():
print(st.lower())
else:
print(st)
| Title: cAPS lOCK
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
wHAT DO WE NEED cAPS LOCK FOR?
Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in th... | ```python
st=input()
count=0
for i in st:
if i.islower():
count+=1
if count<=1 and st[0].islower():
print(st.title())
elif st.isupper():
print(st.lower())
else:
print(st)
``` | 3 | |
822 | A | I'm bored with life | PROGRAMMING | 800 | [
"implementation",
"math",
"number theory"
] | null | null | Holidays have finished. Thanks to the help of the hacker Leha, Noora managed to enter the university of her dreams which is located in a town Pavlopolis. It's well known that universities provide students with dormitory for the period of university studies. Consequently Noora had to leave Vičkopolis and move to Pavlopo... | The first and single line contains two integers *A* and *B* (1<=≤<=*A*,<=*B*<=≤<=109,<=*min*(*A*,<=*B*)<=≤<=12). | Print a single integer denoting the greatest common divisor of integers *A*! and *B*!. | [
"4 3\n"
] | [
"6\n"
] | Consider the sample.
4! = 1·2·3·4 = 24. 3! = 1·2·3 = 6. The greatest common divisor of integers 24 and 6 is exactly 6. | 500 | [
{
"input": "4 3",
"output": "6"
},
{
"input": "10 399603090",
"output": "3628800"
},
{
"input": "6 973151934",
"output": "720"
},
{
"input": "2 841668075",
"output": "2"
},
{
"input": "7 415216919",
"output": "5040"
},
{
"input": "3 283733059",
"ou... | 1,631,038,094 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 1 | 1,000 | 8,908,800 | import math
n= list(map(int, (input().split())))
def gcd(a,b):
# Everything divides 0
if (b == 0):
return a
return gcd(b, a%b)
print(gcd(math.factorial(n[0]), math.factorial(n[1])))
| Title: I'm bored with life
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Holidays have finished. Thanks to the help of the hacker Leha, Noora managed to enter the university of her dreams which is located in a town Pavlopolis. It's well known that universities provide students with dormi... | ```python
import math
n= list(map(int, (input().split())))
def gcd(a,b):
# Everything divides 0
if (b == 0):
return a
return gcd(b, a%b)
print(gcd(math.factorial(n[0]), math.factorial(n[1])))
``` | 0 | |
337 | A | Puzzles | PROGRAMMING | 900 | [
"greedy"
] | null | null | The end of the school year is near and Ms. Manana, the teacher, will soon have to say goodbye to a yet another class. She decided to prepare a goodbye present for her *n* students and give each of them a jigsaw puzzle (which, as wikipedia states, is a tiling puzzle that requires the assembly of numerous small, often 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,683,377,241 | 2,147,483,647 | Python 3 | OK | TESTS | 18 | 92 | 0 | def f():
L=[]
n,m=list(map(int,input().split()))
l=list(map(int,input().split()))
l.sort()
d=l[-1]
for a in range(m-n+1):
if d>l[a+n-1]-l[a]:
d=l[a+n-1]-l[a]
print(d)
f()
| Title: Puzzles
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The end of the school year is near and Ms. Manana, the teacher, will soon have to say goodbye to a yet another class. She decided to prepare a goodbye present for her *n* students and give each of them a jigsaw puzzle (which, a... | ```python
def f():
L=[]
n,m=list(map(int,input().split()))
l=list(map(int,input().split()))
l.sort()
d=l[-1]
for a in range(m-n+1):
if d>l[a+n-1]-l[a]:
d=l[a+n-1]-l[a]
print(d)
f()
``` | 3 | |
149 | A | Business trip | PROGRAMMING | 900 | [
"greedy",
"implementation",
"sortings"
] | null | null | What joy! Petya's parents went on a business trip for the whole year and the playful kid is left all by himself. Petya got absolutely happy. He jumped on the bed and threw pillows all day long, until...
Today Petya opened the cupboard and found a scary note there. His parents had left him with duties: he should water... | 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,643,464,516 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 35 | 186 | 0 | k = int(input())
li = list(map(int, input().split()))
li.sort(reverse = True)
i = 0
c = True
while(i<12):
if(k<=0):
c = False
break
k-=li[i]
i+=1
if(c):
print(-1)
else:
print(i) | Title: Business trip
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
What joy! Petya's parents went on a business trip for the whole year and the playful kid is left all by himself. Petya got absolutely happy. He jumped on the bed and threw pillows all day long, until...
Today Petya open... | ```python
k = int(input())
li = list(map(int, input().split()))
li.sort(reverse = True)
i = 0
c = True
while(i<12):
if(k<=0):
c = False
break
k-=li[i]
i+=1
if(c):
print(-1)
else:
print(i)
``` | 0 | |
350 | A | TL | PROGRAMMING | 1,200 | [
"brute force",
"greedy",
"implementation"
] | null | null | Valera wanted to prepare a Codesecrof round. He's already got one problem and he wants to set a time limit (TL) on it.
Valera has written *n* correct solutions. For each correct solution, he knows its running time (in seconds). Valera has also wrote *m* wrong solutions and for each wrong solution he knows its running ... | 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,574,122,747 | 2,147,483,647 | PyPy 3 | OK | TESTS | 45 | 312 | 0 | n, m = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a.sort()
v = a[-1]
ans = -1
while 1:
idx = 0
wrong = False
while idx < m:
if b[idx] <= v:
wrong = True
idx = m
idx += 1
if wrong == True:... | 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())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a.sort()
v = a[-1]
ans = -1
while 1:
idx = 0
wrong = False
while idx < m:
if b[idx] <= v:
wrong = True
idx = m
idx += 1
if wron... | 3 | |
713 | A | Sonya and Queries | PROGRAMMING | 1,400 | [
"data structures",
"implementation"
] | null | null | Today Sonya learned about long integers and invited all her friends to share the fun. Sonya has an initially empty multiset with integers. Friends give her *t* queries, each of one of the following type:
1. <=+<= *a**i* — add non-negative integer *a**i* to the multiset. Note, that she has a multiset, thus there may b... | The first line of the input contains an integer *t* (1<=≤<=*t*<=≤<=100<=000) — the number of operation Sonya has to perform.
Next *t* lines provide the descriptions of the queries in order they appear in the input file. The *i*-th row starts with a character *c**i* — the type of the corresponding operation. If *c**i* ... | For each query of the third type print the number of integers matching the given pattern. Each integer is counted as many times, as it appears in the multiset at this moment of time. | [
"12\n+ 1\n+ 241\n? 1\n+ 361\n- 241\n? 0101\n+ 101\n? 101\n- 101\n? 101\n+ 4000\n? 0\n",
"4\n+ 200\n+ 200\n- 200\n? 0\n"
] | [
"2\n1\n2\n1\n1\n",
"1\n"
] | Consider the integers matching the patterns from the queries of the third type. Queries are numbered in the order they appear in the input.
1. 1 and 241. 1. 361. 1. 101 and 361. 1. 361. 1. 4000. | 500 | [
{
"input": "12\n+ 1\n+ 241\n? 1\n+ 361\n- 241\n? 0101\n+ 101\n? 101\n- 101\n? 101\n+ 4000\n? 0",
"output": "2\n1\n2\n1\n1"
},
{
"input": "4\n+ 200\n+ 200\n- 200\n? 0",
"output": "1"
},
{
"input": "20\n+ 61\n+ 99\n+ 51\n+ 70\n+ 7\n+ 34\n+ 71\n+ 86\n+ 68\n+ 39\n+ 78\n+ 81\n+ 89\n? 10\n? 00... | 1,505,264,386 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 62 | 0 | def main():
multiset = []
answers = []
n = int(input())
even = ['0','2','4','8',]
odd = ['1','3','5','7','9']
for nn in range(0,n):
op, num = input().split()
if op == '+':
multiset.append(num)
if op == '-':
del multiset[multiset.index(num)]
if op == '?':
count = 0
for m in multiset:
patte... | Title: Sonya and Queries
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Today Sonya learned about long integers and invited all her friends to share the fun. Sonya has an initially empty multiset with integers. Friends give her *t* queries, each of one of the following type:
1. <=+<= *a... | ```python
def main():
multiset = []
answers = []
n = int(input())
even = ['0','2','4','8',]
odd = ['1','3','5','7','9']
for nn in range(0,n):
op, num = input().split()
if op == '+':
multiset.append(num)
if op == '-':
del multiset[multiset.index(num)]
if op == '?':
count = 0
for m in multiset:... | 0 | |
525 | A | Vitaliy and Pie | PROGRAMMING | 1,100 | [
"greedy",
"hashing",
"strings"
] | null | null | After a hard day Vitaly got very hungry and he wants to eat his favorite potato pie. But it's not that simple. Vitaly is in the first room of the house with *n* room located in a line and numbered starting from one from left to right. You can go from the first room to the second room, from the second room to the third ... | The first line of the input contains a positive integer *n* (2<=≤<=*n*<=≤<=105) — the number of rooms in the house.
The second line of the input contains string *s* of length 2·*n*<=-<=2. Let's number the elements of the string from left to right, starting from one.
The odd positions in the given string *s* contain ... | Print the only integer — the minimum number of keys that Vitaly needs to buy to surely get from room one to room *n*. | [
"3\naAbB\n",
"4\naBaCaB\n",
"5\nxYyXzZaZ\n"
] | [
"0\n",
"3\n",
"2\n"
] | none | 250 | [
{
"input": "3\naAbB",
"output": "0"
},
{
"input": "4\naBaCaB",
"output": "3"
},
{
"input": "5\nxYyXzZaZ",
"output": "2"
},
{
"input": "26\naAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyY",
"output": "0"
},
{
"input": "26\nzAyBxCwDvEuFtGsHrIqJpKoLnMmNlOkPjQiRhSg... | 1,585,744,813 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 7 | 171 | 3,584,000 | def fun(not_used):
u=0
for x in not_used:
if (x==s[i+1]):
u+=1
x=0
break
if(u!=0):
return 1
else:
return 0
n=input()
st=input()
s=st.upper()
not_used=[]
k=0
for i in range(0,len(s),2):
if (s[i]==s[i+1]):
continue
elif (fun(not_used)):
continue
else:
not_used.append(s[i])
k+=1
print (k) | Title: Vitaliy and Pie
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
After a hard day Vitaly got very hungry and he wants to eat his favorite potato pie. But it's not that simple. Vitaly is in the first room of the house with *n* room located in a line and numbered starting from one from... | ```python
def fun(not_used):
u=0
for x in not_used:
if (x==s[i+1]):
u+=1
x=0
break
if(u!=0):
return 1
else:
return 0
n=input()
st=input()
s=st.upper()
not_used=[]
k=0
for i in range(0,len(s),2):
if (s[i]==s[i+1]):
continue
elif (fun(not_used)):
continue
else:
not_used.append(s[i])
k+=1
p... | 0 | |
447 | B | DZY Loves Strings | PROGRAMMING | 1,000 | [
"greedy",
"implementation"
] | null | null | DZY loves collecting special strings which only contain lowercase letters. For each lowercase letter *c* DZY knows its value *w**c*. For each special string *s*<==<=*s*1*s*2... *s*|*s*| (|*s*| is the length of the string) he represents its value with a function *f*(*s*), where
Now DZY has a string *s*. He wants to in... | The first line contains a single string *s* (1<=≤<=|*s*|<=≤<=103).
The second line contains a single integer *k* (0<=≤<=*k*<=≤<=103).
The third line contains twenty-six integers from *w**a* to *w**z*. Each such number is non-negative and doesn't exceed 1000. | Print a single integer — the largest possible value of the resulting string DZY could get. | [
"abc\n3\n1 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n"
] | [
"41\n"
] | In the test sample DZY can obtain "abcbbc", *value* = 1·1 + 2·2 + 3·2 + 4·2 + 5·2 + 6·2 = 41. | 1,000 | [
{
"input": "abc\n3\n1 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "41"
},
{
"input": "mmzhr\n3\n443 497 867 471 195 670 453 413 579 466 553 881 847 642 269 996 666 702 487 209 257 741 974 133 519 453",
"output": "29978"
},
{
"input": "ajeeseerqnpaujubmajpibxrccazaawetyw... | 1,587,307,187 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 1 | 124 | 0 | s = input()
k = int(input())
wt = [int(x) for x in input().split()]
string = "abcdefghijklmnopqrstuvwxyz"
string = list(string)
ans=0
for i in range(len(s)):
ind = string.index(s[i])
ans+=wt[ind]*(i+1)
maxi = max(wt)
for i in range(1,k+1):
ans+=maxi*(k+i)
print(ans) | Title: DZY Loves Strings
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
DZY loves collecting special strings which only contain lowercase letters. For each lowercase letter *c* DZY knows its value *w**c*. For each special string *s*<==<=*s*1*s*2... *s*|*s*| (|*s*| is the length of the str... | ```python
s = input()
k = int(input())
wt = [int(x) for x in input().split()]
string = "abcdefghijklmnopqrstuvwxyz"
string = list(string)
ans=0
for i in range(len(s)):
ind = string.index(s[i])
ans+=wt[ind]*(i+1)
maxi = max(wt)
for i in range(1,k+1):
ans+=maxi*(k+i)
print(ans)
``` | 0 | |
31 | A | Worms Evolution | PROGRAMMING | 1,200 | [
"implementation"
] | A. Worms Evolution | 2 | 256 | Professor Vasechkin is studying evolution of worms. Recently he put forward hypotheses that all worms evolve by division. There are *n* forms of worms. Worms of these forms have lengths *a*1, *a*2, ..., *a**n*. To prove his theory, professor needs to find 3 different forms that the length of the first form is equal to ... | The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of worm's forms. The second line contains *n* space-separated integers *a**i* (1<=≤<=*a**i*<=≤<=1000) — lengths of worms of each form. | Output 3 distinct integers *i* *j* *k* (1<=≤<=*i*,<=*j*,<=*k*<=≤<=*n*) — such indexes of worm's forms that *a**i*<==<=*a**j*<=+<=*a**k*. If there is no such triple, output -1. If there are several solutions, output any of them. It possible that *a**j*<==<=*a**k*. | [
"5\n1 2 3 5 7\n",
"5\n1 8 1 5 1\n"
] | [
"3 2 1\n",
"-1\n"
] | none | 500 | [
{
"input": "5\n1 2 3 5 7",
"output": "3 2 1"
},
{
"input": "5\n1 8 1 5 1",
"output": "-1"
},
{
"input": "4\n303 872 764 401",
"output": "-1"
},
{
"input": "6\n86 402 133 524 405 610",
"output": "6 4 1"
},
{
"input": "8\n217 779 418 895 996 473 3 22",
"output":... | 1,591,699,975 | 2,147,483,647 | Python 3 | OK | TESTS | 39 | 216 | 307,200 | input()
cont = [int(item) for item in input().split()]
ans, contLen, needBreak = '-1', len(cont), False
for i in range(contLen):
for j in range(contLen):
if i == j:
continue
for k in range(contLen):
if k == i or k == j:
continue
if cont[i... | Title: Worms Evolution
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Professor Vasechkin is studying evolution of worms. Recently he put forward hypotheses that all worms evolve by division. There are *n* forms of worms. Worms of these forms have lengths *a*1, *a*2, ..., *a**n*. To prove his... | ```python
input()
cont = [int(item) for item in input().split()]
ans, contLen, needBreak = '-1', len(cont), False
for i in range(contLen):
for j in range(contLen):
if i == j:
continue
for k in range(contLen):
if k == i or k == j:
continue
... | 3.945428 |
863 | B | Kayaking | PROGRAMMING | 1,500 | [
"brute force",
"greedy",
"sortings"
] | null | null | Vadim is really keen on travelling. Recently he heard about kayaking activity near his town and became very excited about it, so he joined a party of kayakers.
Now the party is ready to start its journey, but firstly they have to choose kayaks. There are 2·*n* people in the group (including Vadim), and they have exact... | The first line contains one number *n* (2<=≤<=*n*<=≤<=50).
The second line contains 2·*n* integer numbers *w*1, *w*2, ..., *w*2*n*, where *w**i* is weight of person *i* (1<=≤<=*w**i*<=≤<=1000). | Print minimum possible total instability. | [
"2\n1 2 3 4\n",
"4\n1 3 4 6 3 4 100 200\n"
] | [
"1\n",
"5\n"
] | none | 0 | [
{
"input": "2\n1 2 3 4",
"output": "1"
},
{
"input": "4\n1 3 4 6 3 4 100 200",
"output": "5"
},
{
"input": "3\n305 139 205 406 530 206",
"output": "102"
},
{
"input": "3\n610 750 778 6 361 407",
"output": "74"
},
{
"input": "5\n97 166 126 164 154 98 221 7 51 47",
... | 1,699,627,619 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 20 | 62 | 2,048,000 | import itertools
n=int(input())
w=sorted(list(map(int,input().split())))
t=[]
u=list(itertools.combinations(w,2))
for i in u:
a=list(w)
a.remove(i[0])
a.remove(i[1])
s=0
for j in range(0, len(a) -1, 2):
s += (a[j + 1] - a[j])
t.append(s)
print(min(t)) | Title: Kayaking
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vadim is really keen on travelling. Recently he heard about kayaking activity near his town and became very excited about it, so he joined a party of kayakers.
Now the party is ready to start its journey, but firstly they hav... | ```python
import itertools
n=int(input())
w=sorted(list(map(int,input().split())))
t=[]
u=list(itertools.combinations(w,2))
for i in u:
a=list(w)
a.remove(i[0])
a.remove(i[1])
s=0
for j in range(0, len(a) -1, 2):
s += (a[j + 1] - a[j])
t.append(s)
print(min(t))
``` | 3 | |
452 | A | Eevee | PROGRAMMING | 1,000 | [
"brute force",
"implementation",
"strings"
] | null | null | You are solving the crossword problem K from IPSC 2014. You solved all the clues except for one: who does Eevee evolve into? You are not very into pokemons, but quick googling helped you find out, that Eevee can evolve into eight different pokemons: Vaporeon, Jolteon, Flareon, Espeon, Umbreon, Leafeon, Glaceon, and Syl... | First line contains an integer *n* (6<=≤<=*n*<=≤<=8) – the length of the string.
Next line contains a string consisting of *n* characters, each of which is either a lower case english letter (indicating a known letter) or a dot character (indicating an empty cell in the crossword). | Print a name of the pokemon that Eevee can evolve into that matches the pattern in the input. Use lower case letters only to print the name (in particular, do not capitalize the first letter). | [
"7\nj......\n",
"7\n...feon\n",
"7\n.l.r.o.\n"
] | [
"jolteon\n",
"leafeon\n",
"flareon\n"
] | Here's a set of names in a form you can paste into your solution:
["vaporeon", "jolteon", "flareon", "espeon", "umbreon", "leafeon", "glaceon", "sylveon"]
{"vaporeon", "jolteon", "flareon", "espeon", "umbreon", "leafeon", "glaceon", "sylveon"} | 500 | [
{
"input": "7\n...feon",
"output": "leafeon"
},
{
"input": "7\n.l.r.o.",
"output": "flareon"
},
{
"input": "6\n.s..o.",
"output": "espeon"
},
{
"input": "7\nglaceon",
"output": "glaceon"
},
{
"input": "8\n.a.o.e.n",
"output": "vaporeon"
},
{
"input": "... | 1,406,537,074 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 8 | 61 | 0 | def evolve(l):
for e in ["vaporeon", "jolteon", "flareon", "espeon", "umbreon", "leafeon", "glaceon", "sylveon"]:
yes = 1
for x in range(min(len(l),len(e))):
if l[x] != ".":
if l[x] != e[x]:
yes = 0
if yes == 1:
return e
... | Title: Eevee
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are solving the crossword problem K from IPSC 2014. You solved all the clues except for one: who does Eevee evolve into? You are not very into pokemons, but quick googling helped you find out, that Eevee can evolve into eight... | ```python
def evolve(l):
for e in ["vaporeon", "jolteon", "flareon", "espeon", "umbreon", "leafeon", "glaceon", "sylveon"]:
yes = 1
for x in range(min(len(l),len(e))):
if l[x] != ".":
if l[x] != e[x]:
yes = 0
if yes == 1:
re... | 0 | |
266 | B | Queue at the School | PROGRAMMING | 800 | [
"constructive algorithms",
"graph matchings",
"implementation",
"shortest paths"
] | null | null | During the break the schoolchildren, boys and girls, formed a queue of *n* people in the canteen. Initially the children stood in the order they entered the canteen. However, after a while the boys started feeling awkward for standing in front of the girls in the queue and they started letting the girls move forward ea... | The first line contains two integers *n* and *t* (1<=≤<=*n*,<=*t*<=≤<=50), which represent the number of children in the queue and the time after which the queue will transform into the arrangement you need to find.
The next line contains string *s*, which represents the schoolchildren's initial arrangement. If the *... | Print string *a*, which describes the arrangement after *t* seconds. If the *i*-th position has a boy after the needed time, then the *i*-th character *a* must equal "B", otherwise it must equal "G". | [
"5 1\nBGGBG\n",
"5 2\nBGGBG\n",
"4 1\nGGGB\n"
] | [
"GBGGB\n",
"GGBGB\n",
"GGGB\n"
] | none | 500 | [
{
"input": "5 1\nBGGBG",
"output": "GBGGB"
},
{
"input": "5 2\nBGGBG",
"output": "GGBGB"
},
{
"input": "4 1\nGGGB",
"output": "GGGB"
},
{
"input": "2 1\nBB",
"output": "BB"
},
{
"input": "2 1\nBG",
"output": "GB"
},
{
"input": "6 2\nBBGBBG",
"outpu... | 1,697,890,233 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 62 | 0 | n, t = map(int, input().split())
v = [char for char in input()]
if n == 1:
print(''.join(v))
quit()
r = ""
l = n - 1
for i in reversed(range(len(v))):
if v[i] == "B":
if i + t < l:
del v[i]
v.append("B")
# v[i], v[i + t] = v[i + t], v[i]
... | Title: Queue at the School
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
During the break the schoolchildren, boys and girls, formed a queue of *n* people in the canteen. Initially the children stood in the order they entered the canteen. However, after a while the boys started feeling a... | ```python
n, t = map(int, input().split())
v = [char for char in input()]
if n == 1:
print(''.join(v))
quit()
r = ""
l = n - 1
for i in reversed(range(len(v))):
if v[i] == "B":
if i + t < l:
del v[i]
v.append("B")
# v[i], v[i + t] = v[i + t], v... | 0 | |
615 | A | Bulbs | PROGRAMMING | 800 | [
"implementation"
] | null | null | Vasya wants to turn on Christmas lights consisting of *m* bulbs. Initially, all bulbs are turned off. There are *n* buttons, each of them is connected to some set of bulbs. Vasya can press any of these buttons. When the button is pressed, it turns on all the bulbs it's connected to. Can Vasya light up all the bulbs?
I... | The first line of the input contains integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of buttons and the number of bulbs respectively.
Each of the next *n* lines contains *x**i* (0<=≤<=*x**i*<=≤<=*m*) — the number of bulbs that are turned on by the *i*-th button, and then *x**i* numbers *y**ij* (1<=≤<=*y**... | If it's possible to turn on all *m* bulbs print "YES", otherwise print "NO". | [
"3 4\n2 1 4\n3 1 3 1\n1 2\n",
"3 3\n1 1\n1 2\n1 1\n"
] | [
"YES\n",
"NO\n"
] | In the first sample you can press each button once and turn on all the bulbs. In the 2 sample it is impossible to turn on the 3-rd lamp. | 500 | [
{
"input": "3 4\n2 1 4\n3 1 3 1\n1 2",
"output": "YES"
},
{
"input": "3 3\n1 1\n1 2\n1 1",
"output": "NO"
},
{
"input": "3 4\n1 1\n1 2\n1 3",
"output": "NO"
},
{
"input": "1 5\n5 1 2 3 4 5",
"output": "YES"
},
{
"input": "1 5\n5 4 4 1 2 3",
"output": "NO"
},... | 1,635,257,172 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 46 | 4,505,600 | n, m = map(int, input().split())
bulbs = {i: False for i in range(1, m + 1)}
for _ in range(n):
line = map(int, input().split())
for item in line:
bulbs[item] = True
ret = True
for key in bulbs:
ret = ret & bulbs[key]
# print(bulbs)
print('YES' if ret else 'NO') | Title: Bulbs
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya wants to turn on Christmas lights consisting of *m* bulbs. Initially, all bulbs are turned off. There are *n* buttons, each of them is connected to some set of bulbs. Vasya can press any of these buttons. When the button is... | ```python
n, m = map(int, input().split())
bulbs = {i: False for i in range(1, m + 1)}
for _ in range(n):
line = map(int, input().split())
for item in line:
bulbs[item] = True
ret = True
for key in bulbs:
ret = ret & bulbs[key]
# print(bulbs)
print('YES' if ret else 'NO')
``` | 0 | |
1,009 | C | Annoying Present | PROGRAMMING | 1,700 | [
"greedy",
"math"
] | null | null | Alice got an array of length $n$ as a birthday present once again! This is the third year in a row!
And what is more disappointing, it is overwhelmengly boring, filled entirely with zeros. Bob decided to apply some changes to the array to cheer up Alice.
Bob has chosen $m$ changes of the following form. For some int... | The first line contains two integers $n$ and $m$ ($1 \le n, m \le 10^5$) — the number of elements of the array and the number of changes.
Each of the next $m$ lines contains two integers $x_i$ and $d_i$ ($-10^3 \le x_i, d_i \le 10^3$) — the parameters for the $i$-th change. | Print the maximal average arithmetic mean of the elements Bob can achieve.
Your answer is considered correct if its absolute or relative error doesn't exceed $10^{-6}$. | [
"2 3\n-1 3\n0 0\n-1 -4\n",
"3 2\n0 2\n5 0\n"
] | [
"-2.500000000000000\n",
"7.000000000000000\n"
] | none | 0 | [
{
"input": "2 3\n-1 3\n0 0\n-1 -4",
"output": "-2.500000000000000"
},
{
"input": "3 2\n0 2\n5 0",
"output": "7.000000000000000"
},
{
"input": "8 8\n-21 -60\n-96 -10\n-4 -19\n-27 -4\n57 -15\n-95 62\n-42 1\n-17 64",
"output": "-16.500000000000000"
},
{
"input": "1 1\n0 0",
... | 1,532,353,128 | 2,147,483,647 | Python 3 | OK | TESTS | 54 | 420 | 0 | def fun(y):
return y * (y + 1) // 2
n, m = map(int, input().split())
ans = 0
I = (n + 1) // 2
MIN = fun(I - 1) + fun(n - I)
MAX = fun(n - 1)
for i in range(m):
x, d = map(int, input().split())
ans += n * x + d * (MIN if d < 0 else MAX)
print("%.12f" % (ans / n))
| Title: Annoying Present
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Alice got an array of length $n$ as a birthday present once again! This is the third year in a row!
And what is more disappointing, it is overwhelmengly boring, filled entirely with zeros. Bob decided to apply some c... | ```python
def fun(y):
return y * (y + 1) // 2
n, m = map(int, input().split())
ans = 0
I = (n + 1) // 2
MIN = fun(I - 1) + fun(n - I)
MAX = fun(n - 1)
for i in range(m):
x, d = map(int, input().split())
ans += n * x + d * (MIN if d < 0 else MAX)
print("%.12f" % (ans / n))
``` | 3 | |
1 | A | Theatre Square | PROGRAMMING | 1,000 | [
"math"
] | A. Theatre Square | 1 | 256 | Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size *a*<=×<=*a*.
What is the least number of flagstones needed to pave the... | The input contains three positive integer numbers in the first line: *n*,<=<=*m* and *a* (1<=≤<=<=*n*,<=*m*,<=*a*<=≤<=109). | Write the needed number of flagstones. | [
"6 6 4\n"
] | [
"4\n"
] | none | 0 | [
{
"input": "6 6 4",
"output": "4"
},
{
"input": "1 1 1",
"output": "1"
},
{
"input": "2 1 1",
"output": "2"
},
{
"input": "1 2 1",
"output": "2"
},
{
"input": "2 2 1",
"output": "4"
},
{
"input": "2 1 2",
"output": "1"
},
{
"input": "1 1 3"... | 1,659,898,323 | 2,147,483,647 | Python 3 | OK | TESTS | 20 | 46 | 0 | import math
a,b,c= map(int,input().split())
d = math.ceil(a/c)
e = math.ceil(b/c)
print(d*e) | Title: Theatre Square
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each ... | ```python
import math
a,b,c= map(int,input().split())
d = math.ceil(a/c)
e = math.ceil(b/c)
print(d*e)
``` | 3.977 |
119 | A | Epic Game | PROGRAMMING | 800 | [
"implementation"
] | null | null | Simon and Antisimon play a game. Initially each player receives one fixed positive integer that doesn't change throughout the game. Simon receives number *a* and Antisimon receives number *b*. They also have a heap of *n* stones. The players take turns to make a move and Simon starts. During a move a player should take... | The only string contains space-separated integers *a*, *b* and *n* (1<=≤<=*a*,<=*b*,<=*n*<=≤<=100) — the fixed numbers Simon and Antisimon have received correspondingly and the initial number of stones in the pile. | If Simon wins, print "0" (without the quotes), otherwise print "1" (without the quotes). | [
"3 5 9\n",
"1 1 100\n"
] | [
"0",
"1"
] | The greatest common divisor of two non-negative integers *a* and *b* is such maximum positive integer *k*, that *a* is divisible by *k* without remainder and similarly, *b* is divisible by *k* without remainder. Let *gcd*(*a*, *b*) represent the operation of calculating the greatest common divisor of numbers *a* and *b... | 500 | [
{
"input": "3 5 9",
"output": "0"
},
{
"input": "1 1 100",
"output": "1"
},
{
"input": "23 12 16",
"output": "1"
},
{
"input": "95 26 29",
"output": "1"
},
{
"input": "73 32 99",
"output": "1"
},
{
"input": "1 1 1",
"output": "0"
},
{
"inpu... | 1,621,840,360 | 2,147,483,647 | Python 3 | OK | TESTS | 45 | 124 | 0 | import math
a,b,n=map(int,input().split())
flag=-1
while True:
if n>0:
#print("an-=,an",math.gcd(n,a),n)
n=n-math.gcd(n,a)
else:
flag=1
break
if n>0:
#print("bn-=,bn",math.gcd(n,b),n)
n=n-math.gcd(n,b)
else:
flag=0
break
p... | Title: Epic Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Simon and Antisimon play a game. Initially each player receives one fixed positive integer that doesn't change throughout the game. Simon receives number *a* and Antisimon receives number *b*. They also have a heap of *n* sto... | ```python
import math
a,b,n=map(int,input().split())
flag=-1
while True:
if n>0:
#print("an-=,an",math.gcd(n,a),n)
n=n-math.gcd(n,a)
else:
flag=1
break
if n>0:
#print("bn-=,bn",math.gcd(n,b),n)
n=n-math.gcd(n,b)
else:
flag=0
... | 3 | |
545 | D | Queue | PROGRAMMING | 1,300 | [
"greedy",
"implementation",
"sortings"
] | null | null | Little girl Susie went shopping with her mom and she wondered how to improve service quality.
There are *n* people in the queue. For each person we know time *t**i* needed to serve him. A person will be disappointed if the time he waits is more than the time needed to serve him. The time a person waits is the total t... | The first line contains integer *n* (1<=≤<=*n*<=≤<=105).
The next line contains *n* integers *t**i* (1<=≤<=*t**i*<=≤<=109), separated by spaces. | Print a single number — the maximum number of not disappointed people in the queue. | [
"5\n15 2 1 5 3\n"
] | [
"4\n"
] | Value 4 is achieved at such an arrangement, for example: 1, 2, 3, 5, 15. Thus, you can make everything feel not disappointed except for the person with time 5. | 1,750 | [
{
"input": "5\n15 2 1 5 3",
"output": "4"
},
{
"input": "15\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "2"
},
{
"input": "10\n13 2 5 55 21 34 1 8 1 3",
"output": "6"
},
{
"input": "10\n8 256 16 1 2 1 64 4 128 32",
"output": "10"
},
{
"input": "10\n10000 40000 1000... | 1,695,997,469 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 46 | 0 | n = int(input())
a = [int(x) for x in input().split()]
a.sort()
wt, cnt = 0, 0 # wait time, count
for i in range(n):
if wt < a[i]:
cnt += 1
wt += a[i]
print(cnt) | Title: Queue
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little girl Susie went shopping with her mom and she wondered how to improve service quality.
There are *n* people in the queue. For each person we know time *t**i* needed to serve him. A person will be disappointed if the time... | ```python
n = int(input())
a = [int(x) for x in input().split()]
a.sort()
wt, cnt = 0, 0 # wait time, count
for i in range(n):
if wt < a[i]:
cnt += 1
wt += a[i]
print(cnt)
``` | 0 | |
50 | A | Domino piling | PROGRAMMING | 800 | [
"greedy",
"math"
] | A. Domino piling | 2 | 256 | You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions:
1. Each domino completely covers ... | 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,668,966,427 | 2,147,483,647 | Python 3 | OK | TESTS | 35 | 122 | 0 | n,m = map(int,input().split())
c = ((m*n)//2)
print(c)
| Title: Domino piling
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as p... | ```python
n,m = map(int,input().split())
c = ((m*n)//2)
print(c)
``` | 3.9695 |
365 | A | Good Number | PROGRAMMING | 1,100 | [
"implementation"
] | null | null | Let's call a number *k*-good if it contains all digits not exceeding *k* (0,<=...,<=*k*). You've got a number *k* and an array *a* containing *n* numbers. Find out how many *k*-good numbers are in *a* (count each number every time it occurs in array *a*). | The first line contains integers *n* and *k* (1<=≤<=*n*<=≤<=100, 0<=≤<=*k*<=≤<=9). The *i*-th of the following *n* lines contains integer *a**i* without leading zeroes (1<=≤<=*a**i*<=≤<=109). | Print a single integer — the number of *k*-good numbers in *a*. | [
"10 6\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n",
"2 1\n1\n10\n"
] | [
"10\n",
"1\n"
] | none | 500 | [
{
"input": "10 6\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560",
"output": "10"
},
{
"input": "2 1\n1\n10",
"output": "1"
},
{
"input": "1 0\n1000000000",
"output": "1"
},
{
"input": "1 1\n1000000000",
"output": "1"
},
{
... | 1,644,657,008 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 31 | 0 | t = input().split()
a = int(t[0])
n = int(t[1])
counter = 0
c = 0
for i in range(a):
c = [0]*10
x = input()
if not (len(x) > (n+1)):
for i in range(len(x)):
c[int(i)] = 1
if c.count(1) == n+1:
counter +=1
print(counter)
| Title: Good Number
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Let's call a number *k*-good if it contains all digits not exceeding *k* (0,<=...,<=*k*). You've got a number *k* and an array *a* containing *n* numbers. Find out how many *k*-good numbers are in *a* (count each number eve... | ```python
t = input().split()
a = int(t[0])
n = int(t[1])
counter = 0
c = 0
for i in range(a):
c = [0]*10
x = input()
if not (len(x) > (n+1)):
for i in range(len(x)):
c[int(i)] = 1
if c.count(1) == n+1:
counter +=1
print(counter)
``` | 0 | |
714 | A | Meeting of Old Friends | PROGRAMMING | 1,100 | [
"implementation",
"math"
] | null | null | Today an outstanding event is going to happen in the forest — hedgehog Filya will come to his old fried Sonya!
Sonya is an owl and she sleeps during the day and stay awake from minute *l*1 to minute *r*1 inclusive. Also, during the minute *k* she prinks and is unavailable for Filya.
Filya works a lot and he plans to ... | 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,619,845,161 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 9 | 77 | 0 | from math import pi
def solve(l1,r1,l2,r2,k):
l = max(l1,l2)
r = min(r1,r2)
v = r-l+1
if k >= l and k<= r:
return v-1
return v
def main():
arr = list(map(int, list(input().split(" "))))
# n = int(input())
print(solve(*arr))
main() | Title: Meeting of Old Friends
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Today an outstanding event is going to happen in the forest — hedgehog Filya will come to his old fried Sonya!
Sonya is an owl and she sleeps during the day and stay awake from minute *l*1 to minute *r*1 inclusi... | ```python
from math import pi
def solve(l1,r1,l2,r2,k):
l = max(l1,l2)
r = min(r1,r2)
v = r-l+1
if k >= l and k<= r:
return v-1
return v
def main():
arr = list(map(int, list(input().split(" "))))
# n = int(input())
print(solve(*arr))
main()
``` | 0 | |
227 | B | Effective Approach | PROGRAMMING | 1,100 | [
"implementation"
] | null | null | Once at a team training Vasya, Petya and Sasha got a problem on implementing linear search in an array.
According to the boys, linear search works as follows. The array elements in a pre-selected order are in turn compared with the number that you need to find. Once you find the array element that is equal to the requ... | The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of elements in the array. The second line contains *n* distinct space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*n*) — the elements of array.
The third line contains integer *m* (1<=≤<=*m*<=≤<=105) — the number of queries. The ... | Print two integers, showing how many comparisons Vasya's approach needs and how many comparisons Petya's approach needs. Separate the numbers by spaces.
Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier. | [
"2\n1 2\n1\n1\n",
"2\n2 1\n1\n1\n",
"3\n3 1 2\n3\n1 2 3\n"
] | [
"1 2\n",
"2 1\n",
"6 6\n"
] | In the first sample Vasya's approach will make one comparison (it starts with the 1-st element and immediately finds the required number), and Petya's approach makes two comparisons (first he compares with the 2-nd array element, doesn't find the search item and compares with the 1-st element).
In the second sample, o... | 1,000 | [
{
"input": "2\n1 2\n1\n1",
"output": "1 2"
},
{
"input": "2\n2 1\n1\n1",
"output": "2 1"
},
{
"input": "3\n3 1 2\n3\n1 2 3",
"output": "6 6"
},
{
"input": "9\n2 9 3 1 6 4 7 8 5\n9\n5 1 5 2 8 4 4 4 5",
"output": "58 32"
},
{
"input": "10\n3 10 9 2 7 6 5 8 4 1\n1\n4... | 1,644,154,975 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 342 | 13,721,600 | n = int(input())
hash_map = {}
for i,_ in enumerate(map(int, input().split())):
hash_map[_] = i + 1
q = int(input())
query = list(map(int, input().split()))
v,p = 0,0
for q in query:
v += hash_map[q]
p += (n - hash_map[q] + 1)
print(v,p)
| Title: Effective Approach
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Once at a team training Vasya, Petya and Sasha got a problem on implementing linear search in an array.
According to the boys, linear search works as follows. The array elements in a pre-selected order are in turn c... | ```python
n = int(input())
hash_map = {}
for i,_ in enumerate(map(int, input().split())):
hash_map[_] = i + 1
q = int(input())
query = list(map(int, input().split()))
v,p = 0,0
for q in query:
v += hash_map[q]
p += (n - hash_map[q] + 1)
print(v,p)
``` | 3 | |
626 | B | Cards | PROGRAMMING | 1,300 | [
"constructive algorithms",
"dp",
"math"
] | null | null | Catherine has a deck of *n* cards, each of which is either red, green, or blue. As long as there are at least two cards left, she can do one of two actions:
- take any two (not necessarily adjacent) cards with different colors and exchange them for a new card of the third color; - take any two (not necessarily adja... | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=200) — the total number of cards.
The next line contains a string *s* of length *n* — the colors of the cards. *s* contains only the characters 'B', 'G', and 'R', representing blue, green, and red, respectively. | Print a single string of up to three characters — the possible colors of the final card (using the same symbols as the input) in alphabetical order. | [
"2\nRB\n",
"3\nGRG\n",
"5\nBBBBB\n"
] | [
"G\n",
"BR\n",
"B\n"
] | In the first sample, Catherine has one red card and one blue card, which she must exchange for a green card.
In the second sample, Catherine has two green cards and one red card. She has two options: she can exchange the two green cards for a green card, then exchange the new green card and the red card for a blue car... | 750 | [
{
"input": "2\nRB",
"output": "G"
},
{
"input": "3\nGRG",
"output": "BR"
},
{
"input": "5\nBBBBB",
"output": "B"
},
{
"input": "1\nR",
"output": "R"
},
{
"input": "200\nBBRGRRBBRGGGBGBGBGRRGRGRGRBGRGRRBBGRGBGRRGRRRGGBBRGBGBGBRBBBBBBBGGBRGGRRRGGRGBGBGGBRRRRBRRRBRBB... | 1,689,724,856 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 3 | 62 | 716,800 | from functools import cache
ans = ""
@cache
def backtrack(r, g, b):
global ans
if r+g+b == 2:
if r == 2: ans += "R"
if g == 2: ans += "G"
if b == 2: ans += "B"
if r == 1 and g == 1: ans += "B"
if g == 1 and b == 1: ans += "R"
if r == 1 and b == 1: a... | Title: Cards
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Catherine has a deck of *n* cards, each of which is either red, green, or blue. As long as there are at least two cards left, she can do one of two actions:
- take any two (not necessarily adjacent) cards with different colors... | ```python
from functools import cache
ans = ""
@cache
def backtrack(r, g, b):
global ans
if r+g+b == 2:
if r == 2: ans += "R"
if g == 2: ans += "G"
if b == 2: ans += "B"
if r == 1 and g == 1: ans += "B"
if g == 1 and b == 1: ans += "R"
if r == 1 and... | 0 | |
259 | B | Little Elephant and Magic Square | PROGRAMMING | 1,100 | [
"brute force",
"implementation"
] | null | null | Little Elephant loves magic squares very much.
A magic square is a 3<=×<=3 table, each cell contains some positive integer. At that the sums of integers in all rows, columns and diagonals of the table are equal. The figure below shows the magic square, the sum of integers in all its rows, columns and diagonals equals ... | The first three lines of the input contain the Little Elephant's notes. The first line contains elements of the first row of the magic square. The second line contains the elements of the second row, the third line is for the third row. The main diagonal elements that have been forgotten by the Elephant are represented... | Print three lines, in each line print three integers — the Little Elephant's magic square. If there are multiple magic squares, you are allowed to print any of them. Note that all numbers you print must be positive and not exceed 105.
It is guaranteed that there exists at least one magic square that meets the conditio... | [
"0 1 1\n1 0 1\n1 1 0\n",
"0 3 6\n5 0 5\n4 7 0\n"
] | [
"1 1 1\n1 1 1\n1 1 1\n",
"6 3 6\n5 5 5\n4 7 4\n"
] | none | 1,000 | [
{
"input": "0 1 1\n1 0 1\n1 1 0",
"output": "1 1 1\n1 1 1\n1 1 1"
},
{
"input": "0 3 6\n5 0 5\n4 7 0",
"output": "6 3 6\n5 5 5\n4 7 4"
},
{
"input": "0 4 4\n4 0 4\n4 4 0",
"output": "4 4 4\n4 4 4\n4 4 4"
},
{
"input": "0 54 48\n36 0 78\n66 60 0",
"output": "69 54 48\n36 5... | 1,629,723,827 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 1 | 154 | 20,172,800 |
def main_function():
a, b, c = [int(i) for i in input().split(" ")]
d, e, f = [int(i) for i in input().split(" ")]
g, h, i = [int(i) for i in input().split(" ")]
v = b + c
l = d + f
w = g + h
x = max(v, l, w) + 1
a = x - v
e = x - l
i = x - w
print(" ".join([str(... | Title: Little Elephant and Magic Square
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Elephant loves magic squares very much.
A magic square is a 3<=×<=3 table, each cell contains some positive integer. At that the sums of integers in all rows, columns and diagonals of the table ... | ```python
def main_function():
a, b, c = [int(i) for i in input().split(" ")]
d, e, f = [int(i) for i in input().split(" ")]
g, h, i = [int(i) for i in input().split(" ")]
v = b + c
l = d + f
w = g + h
x = max(v, l, w) + 1
a = x - v
e = x - l
i = x - w
print(" ".... | 0 | |
0 | none | none | none | 0 | [
"none"
] | null | null | A *k*-multiple free set is a set of integers where there is no pair of integers where one is equal to another integer multiplied by *k*. That is, there are no two integers *x* and *y* (*x*<=<<=*y*) from the set, such that *y*<==<=*x*·*k*.
You're given a set of *n* distinct positive integers. Your task is to find th... | The first line of the input contains two integers *n* and *k* (1<=≤<=*n*<=≤<=105,<=1<=≤<=*k*<=≤<=109). The next line contains a list of *n* distinct positive integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109).
All the numbers in the lines are separated by single spaces. | On the only line of the output print the size of the largest *k*-multiple free subset of {*a*1,<=*a*2,<=...,<=*a**n*}. | [
"6 2\n2 3 6 5 4 10\n"
] | [
"3\n"
] | In the sample input one of the possible maximum 2-multiple free subsets is {4, 5, 6}. | 0 | [
{
"input": "6 2\n2 3 6 5 4 10",
"output": "3"
},
{
"input": "10 2\n1 2 3 4 5 6 7 8 9 10",
"output": "6"
},
{
"input": "1 1\n1",
"output": "1"
},
{
"input": "100 2\n191 17 61 40 77 95 128 88 26 69 79 10 131 106 142 152 68 39 182 53 83 81 6 89 65 148 33 22 5 47 107 121 52 163 1... | 1,602,833,174 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 218 | 307,200 | import copy
n, k = map (int, input ().split ())
lst = list (map (int, input ().split ()))
lst.sort ()
lst = set (lst)
temp = copy.copy (lst)
for i in temp :
lst.discard (i * k)
print (len (lst))
| Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A *k*-multiple free set is a set of integers where there is no pair of integers where one is equal to another integer multiplied by *k*. That is, there are no two integers *x* and *y* (*x*<=<<=*y*) from the set, such that *y*<=... | ```python
import copy
n, k = map (int, input ().split ())
lst = list (map (int, input ().split ()))
lst.sort ()
lst = set (lst)
temp = copy.copy (lst)
for i in temp :
lst.discard (i * k)
print (len (lst))
``` | 0 | |
839 | C | Journey | PROGRAMMING | 1,500 | [
"dfs and similar",
"dp",
"graphs",
"probabilities",
"trees"
] | null | null | There are *n* cities and *n*<=-<=1 roads in the Seven Kingdoms, each road connects two cities and we can reach any city from any other by the roads.
Theon and Yara Greyjoy are on a horse in the first city, they are starting traveling through the roads. But the weather is foggy, so they can’t see where the horse brings... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100000) — number of cities.
Then *n*<=-<=1 lines follow. The *i*-th line of these lines contains two integers *u**i* and *v**i* (1<=≤<=*u**i*,<=*v**i*<=≤<=*n*, *u**i*<=≠<=*v**i*) — the cities connected by the *i*-th road.
It is guaranteed that one can reach ... | Print a number — the expected length of their journey. The journey starts in the city 1.
Your answer will be considered correct if its absolute or relative error does not exceed 10<=-<=6.
Namely: let's assume that your answer is *a*, and the answer of the jury is *b*. The checker program will consider your answer cor... | [
"4\n1 2\n1 3\n2 4\n",
"5\n1 2\n1 3\n3 4\n2 5\n"
] | [
"1.500000000000000\n",
"2.000000000000000\n"
] | In the first sample, their journey may end in cities 3 or 4 with equal probability. The distance to city 3 is 1 and to city 4 is 2, so the expected length is 1.5.
In the second sample, their journey may end in city 4 or 5. The distance to the both cities is 2, so the expected length is 2. | 1,500 | [
{
"input": "4\n1 2\n1 3\n2 4",
"output": "1.500000000000000"
},
{
"input": "5\n1 2\n1 3\n3 4\n2 5",
"output": "2.000000000000000"
},
{
"input": "70\n1 25\n57 1\n18 1\n65 1\n38 1\n1 41\n1 5\n1 69\n1 3\n31 1\n1 8\n1 9\n53 1\n70 1\n45 1\n1 24\n1 42\n1 30\n1 12\n1 37\n64 1\n1 28\n1 58\n1 22\... | 1,629,383,363 | 2,147,483,647 | PyPy 3 | OK | TESTS | 40 | 608 | 56,729,600 | # Rishabh Rao (https://github.com/rishabhrao)
import sys
MOD = 1000000007
def inp(): return sys.stdin.readline().strip()
def ii(): return int(inp())
def iis(): return [int(i) for i in inp().split()]
## PYRIVAL BOOTSTRAP
# https://github.com/cheran-senthil/PyRival/blob/master/pyrival/misc/bootstrap.py
# Th... | Title: Journey
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* cities and *n*<=-<=1 roads in the Seven Kingdoms, each road connects two cities and we can reach any city from any other by the roads.
Theon and Yara Greyjoy are on a horse in the first city, they are starting tr... | ```python
# Rishabh Rao (https://github.com/rishabhrao)
import sys
MOD = 1000000007
def inp(): return sys.stdin.readline().strip()
def ii(): return int(inp())
def iis(): return [int(i) for i in inp().split()]
## PYRIVAL BOOTSTRAP
# https://github.com/cheran-senthil/PyRival/blob/master/pyrival/misc/bootstra... | 3 | |
844 | B | Rectangles | PROGRAMMING | 1,300 | [
"combinatorics",
"math"
] | null | null | You are given *n*<=×<=*m* table. Each cell of the table is colored white or black. Find the number of non-empty sets of cells such that:
1. All cells in a set have the same color. 1. Every two cells in a set share row or column. | The first line of input contains integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=50) — the number of rows and the number of columns correspondingly.
The next *n* lines of input contain descriptions of rows. There are *m* integers, separated by spaces, in each line. The number equals 0 if the corresponding cell is colored wh... | Output single integer — the number of non-empty sets from the problem description. | [
"1 1\n0\n",
"2 3\n1 0 1\n0 1 0\n"
] | [
"1\n",
"8\n"
] | In the second example, there are six one-element sets. Additionally, there are two two-element sets, the first one consists of the first and the third cells of the first row, the second one consists of the first and the third cells of the second row. To sum up, there are 8 sets. | 1,000 | [
{
"input": "1 1\n0",
"output": "1"
},
{
"input": "2 3\n1 0 1\n0 1 0",
"output": "8"
},
{
"input": "2 2\n1 1\n1 1",
"output": "8"
},
{
"input": "1 10\n0 0 0 0 0 0 0 0 0 0",
"output": "1023"
},
{
"input": "11 1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1",
"output": "2047"... | 1,635,571,947 | 2,147,483,647 | Python 3 | OK | TESTS | 55 | 62 | 4,505,600 | rows,cols = map(int,input().split())
total = 0
table = []
for i in range(rows):
table.append(list(map(int,input().split())))
for row in table:
one_count = 0
zero_count = 0
for num in row:
if num == 1:
one_count += 1
else:
zero_count += 1
... | Title: Rectangles
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given *n*<=×<=*m* table. Each cell of the table is colored white or black. Find the number of non-empty sets of cells such that:
1. All cells in a set have the same color. 1. Every two cells in a set share row or ... | ```python
rows,cols = map(int,input().split())
total = 0
table = []
for i in range(rows):
table.append(list(map(int,input().split())))
for row in table:
one_count = 0
zero_count = 0
for num in row:
if num == 1:
one_count += 1
else:
zero_cou... | 3 | |
124 | A | The number of positions | PROGRAMMING | 1,000 | [
"math"
] | null | null | Petr stands in line of *n* people, but he doesn't know exactly which position he occupies. He can say that there are no less than *a* people standing in front of him and no more than *b* people standing behind him. Find the number of different positions Petr can occupy. | The only line contains three integers *n*, *a* and *b* (0<=≤<=*a*,<=*b*<=<<=*n*<=≤<=100). | Print the single number — the number of the sought positions. | [
"3 1 1\n",
"5 2 3\n"
] | [
"2\n",
"3\n"
] | The possible positions in the first sample are: 2 and 3 (if we number the positions starting with 1).
In the second sample they are 3, 4 and 5. | 500 | [
{
"input": "3 1 1",
"output": "2"
},
{
"input": "5 2 3",
"output": "3"
},
{
"input": "5 4 0",
"output": "1"
},
{
"input": "6 5 5",
"output": "1"
},
{
"input": "9 4 3",
"output": "4"
},
{
"input": "11 4 6",
"output": "7"
},
{
"input": "13 8 ... | 1,676,831,894 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 50 | 124 | 0 | # t = int(input())
t = 1
def cp():
# code here
n,a,b = tuple(map(int,input().split()))
if a+b == n:
print(b)
elif a+b > n:
print(n-a)
else:
print(b+1)
for i in range(t):
cp()
| Title: The number of positions
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petr stands in line of *n* people, but he doesn't know exactly which position he occupies. He can say that there are no less than *a* people standing in front of him and no more than *b* people standing behind h... | ```python
# t = int(input())
t = 1
def cp():
# code here
n,a,b = tuple(map(int,input().split()))
if a+b == n:
print(b)
elif a+b > n:
print(n-a)
else:
print(b+1)
for i in range(t):
cp()
``` | 3 | |
318 | A | Even Odds | PROGRAMMING | 900 | [
"math"
] | null | null | Being a nonconformist, Volodya is displeased with the current state of things, particularly with the order of natural numbers (natural number is positive integer number). He is determined to rearrange them. But there are too many natural numbers, so Volodya decided to start with the first *n*. He writes down the follow... | The only line of input contains integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=1012).
Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier. | Print the number that will stand at the position number *k* after Volodya's manipulations. | [
"10 3\n",
"7 7\n"
] | [
"5",
"6"
] | In the first sample Volodya's sequence will look like this: {1, 3, 5, 7, 9, 2, 4, 6, 8, 10}. The third place in the sequence is therefore occupied by the number 5. | 500 | [
{
"input": "10 3",
"output": "5"
},
{
"input": "7 7",
"output": "6"
},
{
"input": "7 1",
"output": "1"
},
{
"input": "7 2",
"output": "3"
},
{
"input": "8 5",
"output": "2"
},
{
"input": "8 3",
"output": "5"
},
{
"input": "8 4",
"output... | 1,693,284,218 | 2,147,483,647 | Python 3 | OK | TESTS | 25 | 92 | 0 | a,b=map(int,input().split())
if(a%2==0):
even=odd=a//2
else:
even=a//2
odd=even+1
if(b<=odd):
print(2*b-1)
else:
print((b-odd)*2) | Title: Even Odds
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Being a nonconformist, Volodya is displeased with the current state of things, particularly with the order of natural numbers (natural number is positive integer number). He is determined to rearrange them. But there are too ... | ```python
a,b=map(int,input().split())
if(a%2==0):
even=odd=a//2
else:
even=a//2
odd=even+1
if(b<=odd):
print(2*b-1)
else:
print((b-odd)*2)
``` | 3 | |
246 | B | Increase and Decrease | PROGRAMMING | 1,300 | [
"greedy",
"math"
] | null | null | Polycarpus has an array, consisting of *n* integers *a*1,<=*a*2,<=...,<=*a**n*. Polycarpus likes it when numbers in an array match. That's why he wants the array to have as many equal numbers as possible. For that Polycarpus performs the following operation multiple times:
- he chooses two elements of the array *a**i... | The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the array size. The second line contains space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (|*a**i*|<=≤<=104) — the original array. | Print a single integer — the maximum number of equal array elements he can get if he performs an arbitrary number of the given operation. | [
"2\n2 1\n",
"3\n1 4 1\n"
] | [
"1\n",
"3\n"
] | none | 1,000 | [
{
"input": "2\n2 1",
"output": "1"
},
{
"input": "3\n1 4 1",
"output": "3"
},
{
"input": "4\n2 -7 -2 -6",
"output": "3"
},
{
"input": "4\n2 0 -2 -1",
"output": "3"
},
{
"input": "6\n-1 1 0 0 -1 -1",
"output": "5"
},
{
"input": "5\n0 0 0 0 0",
"outp... | 1,586,775,180 | 2,147,483,647 | PyPy 3 | OK | TESTS | 30 | 340 | 5,324,800 | n = int(input())
arr = list(map(int,input().split()))
if n==1:
print(0)
elif n==2:
if abs(arr[0]-arr[1])%2==0:
print(2)
else:
print(1)
else:
d = max(arr)
for i in range(n-1):
arr[n-1]-=d-arr[i]
if (d-arr[n-1])%n==0:
print(n)
else:
print(n-1)
| Title: Increase and Decrease
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarpus has an array, consisting of *n* integers *a*1,<=*a*2,<=...,<=*a**n*. Polycarpus likes it when numbers in an array match. That's why he wants the array to have as many equal numbers as possible. For that... | ```python
n = int(input())
arr = list(map(int,input().split()))
if n==1:
print(0)
elif n==2:
if abs(arr[0]-arr[1])%2==0:
print(2)
else:
print(1)
else:
d = max(arr)
for i in range(n-1):
arr[n-1]-=d-arr[i]
if (d-arr[n-1])%n==0:
print(n)
else:
print(n-1)
``` | 3 | |
29 | A | Spit Problem | PROGRAMMING | 1,000 | [
"brute force"
] | A. Spit Problem | 2 | 256 | In a Berland's zoo there is an enclosure with camels. It is known that camels like to spit. Bob watched these interesting animals for the whole day and registered in his notepad where each animal spitted. Now he wants to know if in the zoo there are two camels, which spitted at each other. Help him to solve this task.
... | The 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,630,561,017 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 92 | 6,656,000 | n=int(input())
aa=[]
for i in range(n):
x,y=map(int,input().split())
aa.append(x)
aa.append(y)
if any(x%y in set(aa)):
print("YES")
else:
print("NO") | Title: Spit Problem
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
In a Berland's zoo there is an enclosure with camels. It is known that camels like to spit. Bob watched these interesting animals for the whole day and registered in his notepad where each animal spitted. Now he wants to know ... | ```python
n=int(input())
aa=[]
for i in range(n):
x,y=map(int,input().split())
aa.append(x)
aa.append(y)
if any(x%y in set(aa)):
print("YES")
else:
print("NO")
``` | -1 |
842 | A | Kirill And The Game | PROGRAMMING | 1,200 | [
"brute force",
"two pointers"
] | null | null | Kirill plays a new computer game. He came to the potion store where he can buy any potion. Each potion is characterized by two integers — amount of experience and cost. The efficiency of a potion is the ratio of the amount of experience to the cost. Efficiency may be a non-integer number.
For each two integer numbers ... | First string contains five integer numbers *l*, *r*, *x*, *y*, *k* (1<=≤<=*l*<=≤<=*r*<=≤<=107, 1<=≤<=*x*<=≤<=*y*<=≤<=107, 1<=≤<=*k*<=≤<=107). | Print "YES" without quotes if a potion with efficiency exactly *k* can be bought in the store and "NO" without quotes otherwise.
You can output each of the letters in any register. | [
"1 10 1 10 1\n",
"1 5 6 10 1\n"
] | [
"YES",
"NO"
] | none | 500 | [
{
"input": "1 10 1 10 1",
"output": "YES"
},
{
"input": "1 5 6 10 1",
"output": "NO"
},
{
"input": "1 1 1 1 1",
"output": "YES"
},
{
"input": "1 1 1 1 2",
"output": "NO"
},
{
"input": "1 100000 1 100000 100000",
"output": "YES"
},
{
"input": "1 100000 ... | 1,561,384,409 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 25 | 140 | 0 | # cook your dish here
l,r,x,y,k=input().split()
l=int(l)
r=int(r)
x=int(x)
y=int(y)
k=int(k)
flag=0
for i in range(l,r+1):
if(i>=(x*k) and i<=(y*k)):
flag=1
break
if(flag==1):
print("YES")
else:
print("NO") | Title: Kirill And The Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Kirill plays a new computer game. He came to the potion store where he can buy any potion. Each potion is characterized by two integers — amount of experience and cost. The efficiency of a potion is the ratio of the... | ```python
# cook your dish here
l,r,x,y,k=input().split()
l=int(l)
r=int(r)
x=int(x)
y=int(y)
k=int(k)
flag=0
for i in range(l,r+1):
if(i>=(x*k) and i<=(y*k)):
flag=1
break
if(flag==1):
print("YES")
else:
print("NO")
``` | 0 | |
706 | B | Interesting drink | PROGRAMMING | 1,100 | [
"binary search",
"dp",
"implementation"
] | null | null | Vasiliy likes to rest after a hard work, so you may often meet him in some bar nearby. As all programmers do, he loves the famous drink "Beecola", which can be bought in *n* different shops in the city. It's known that the price of one bottle in the shop *i* is equal to *x**i* coins.
Vasiliy plans to buy his favorite ... | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the number of shops in the city that sell Vasiliy's favourite drink.
The second line contains *n* integers *x**i* (1<=≤<=*x**i*<=≤<=100<=000) — prices of the bottles of the drink in the *i*-th shop.
The third line contains a single i... | Print *q* integers. The *i*-th of them should be equal to the number of shops where Vasiliy will be able to buy a bottle of the drink on the *i*-th day. | [
"5\n3 10 8 6 11\n4\n1\n10\n3\n11\n"
] | [
"0\n4\n1\n5\n"
] | On the first day, Vasiliy won't be able to buy a drink in any of the shops.
On the second day, Vasiliy can buy a drink in the shops 1, 2, 3 and 4.
On the third day, Vasiliy can buy a drink only in the shop number 1.
Finally, on the last day Vasiliy can buy a drink in any shop. | 1,000 | [
{
"input": "5\n3 10 8 6 11\n4\n1\n10\n3\n11",
"output": "0\n4\n1\n5"
},
{
"input": "5\n868 987 714 168 123\n10\n424\n192\n795\n873\n117\n914\n735\n158\n631\n471",
"output": "2\n2\n3\n4\n0\n4\n3\n1\n2\n2"
},
{
"input": "3\n435 482 309\n7\n245\n241\n909\n745\n980\n29\n521",
"output": "... | 1,689,148,426 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 10 | 2,000 | 12,390,400 | a=int(input())
g=list(map(int,input().split()))
b=int(input())
for i in range(b):
s=0
m=int(input())
for t in g:
if m>=t:
s+=1
print(s)
# Wed Jul 12 2023 10:34:38 GMT+0300 (Moscow Standard Time)
| Title: Interesting drink
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasiliy likes to rest after a hard work, so you may often meet him in some bar nearby. As all programmers do, he loves the famous drink "Beecola", which can be bought in *n* different shops in the city. It's known tha... | ```python
a=int(input())
g=list(map(int,input().split()))
b=int(input())
for i in range(b):
s=0
m=int(input())
for t in g:
if m>=t:
s+=1
print(s)
# Wed Jul 12 2023 10:34:38 GMT+0300 (Moscow Standard Time)
``` | 0 | |
513 | F2 | Scaygerboss | PROGRAMMING | 2,800 | [
"flows"
] | null | null | Cthulhu decided to catch Scaygerboss. Scaygerboss found it out and is trying to hide in a pack of his scaygers. Each scayger except Scaygerboss is either a male or a female. Scaygerboss's gender is "other".
Scaygers are scattered on a two-dimensional map divided into cells. A scayger looks nerdy and loveable if it is ... | The first line contains 4 integers: *n*, *m*, *males*, *females* (0<=≤<=*males*,<=*females*<=≤<=*n*·*m*). *n* and *m* are dimensions of the map; *males* and *females* are numbers of male scaygers and female scaygers.
Next *n* lines describe the map. Each of these lines contains *m* characters. Character '.' stands for... | Output the minimum possible time it takes to make all scaygers look nerdy and loveable or -1 if it is impossible. | [
"4 4 2 3\n....\n.###\n####\n####\n2 1 1\n2 1 2\n2 1 2\n2 1 2\n2 1 2\n1 1 2\n",
"2 4 2 2\n....\n.###\n2 1 1\n2 1 2\n2 1 2\n2 1 2\n2 1 2\n"
] | [
"2\n",
"-1\n"
] | Consider the first sample test. The scaygers are hiding on a 4 by 4 map. Scaygerboss initially resides in the cell (2, 1) and can move between cells in 1 unit of time. There are also 2 male and 3 female scaygers on the map. One of the females initially is in the cell (1, 1), and all the other scaygers are in the cell (... | 6 | [] | 1,689,258,408 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS2 | 0 | 46 | 0 | print("_RANDOM_GUESS_1689258408.4685388")# 1689258408.468582 | Title: Scaygerboss
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Cthulhu decided to catch Scaygerboss. Scaygerboss found it out and is trying to hide in a pack of his scaygers. Each scayger except Scaygerboss is either a male or a female. Scaygerboss's gender is "other".
Scaygers are sc... | ```python
print("_RANDOM_GUESS_1689258408.4685388")# 1689258408.468582
``` | 0 | |
797 | B | Odd sum | PROGRAMMING | 1,400 | [
"dp",
"greedy",
"implementation"
] | null | null | You are given sequence *a*1,<=*a*2,<=...,<=*a**n* of integer numbers of length *n*. Your task is to find such subsequence that its sum is odd and maximum among all such subsequences. It's guaranteed that given sequence contains subsequence with odd sum.
Subsequence is a sequence that can be derived from another sequen... | The first line contains integer number *n* (1<=≤<=*n*<=≤<=105).
The second line contains *n* integer numbers *a*1,<=*a*2,<=...,<=*a**n* (<=-<=104<=≤<=*a**i*<=≤<=104). The sequence contains at least one subsequence with odd sum. | Print sum of resulting subseqeuence. | [
"4\n-2 2 -3 1\n",
"3\n2 -5 -3\n"
] | [
"3\n",
"-1\n"
] | In the first example sum of the second and the fourth elements is 3. | 0 | [
{
"input": "4\n-2 2 -3 1",
"output": "3"
},
{
"input": "3\n2 -5 -3",
"output": "-1"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "1\n-1",
"output": "-1"
},
{
"input": "15\n-6004 4882 9052 413 6056 4306 9946 -4616 -6135 906 -1718 5252 -2866 9061 4046",
"ou... | 1,601,753,719 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 16 | 124 | 0 | n = int(input())
l = list(map(int,input().split()))
o = []
e = []
for i in l:
if i%2 == 0:
e.append(i)
else:
o.append(i)
e.sort()
o.sort()
som = 0
x = o.pop()
som += x
f = 0
while f != 1 and len(e) != 0:
x = e.pop()
if x <= 0:
f = 1
else:
som... | Title: Odd sum
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given sequence *a*1,<=*a*2,<=...,<=*a**n* of integer numbers of length *n*. Your task is to find such subsequence that its sum is odd and maximum among all such subsequences. It's guaranteed that given sequence contains... | ```python
n = int(input())
l = list(map(int,input().split()))
o = []
e = []
for i in l:
if i%2 == 0:
e.append(i)
else:
o.append(i)
e.sort()
o.sort()
som = 0
x = o.pop()
som += x
f = 0
while f != 1 and len(e) != 0:
x = e.pop()
if x <= 0:
f = 1
else:
... | 0 | |
679 | A | Bear and Prime 100 | PROGRAMMING | 1,400 | [
"constructive algorithms",
"interactive",
"math"
] | null | null | This is an interactive problem. In the output section below you will see the information about flushing the output.
Bear Limak thinks of some hidden number — an integer from interval [2,<=100]. Your task is to say if the hidden number is prime or composite.
Integer *x*<=><=1 is called prime if it has exactly two d... | After each query you should read one string from the input. It will be "yes" if the printed integer is a divisor of the hidden number, and "no" otherwise. | Up to 20 times you can ask a query — print an integer from interval [2,<=100] in one line. You have to both print the end-of-line character and flush the output. After flushing you should read a response from the input.
In any moment you can print the answer "prime" or "composite" (without the quotes). After that, flu... | [
"yes\nno\nyes\n",
"no\nyes\nno\nno\nno\n"
] | [
"2\n80\n5\ncomposite\n",
"58\n59\n78\n78\n2\nprime\n"
] | The hidden number in the first query is 30. In a table below you can see a better form of the provided example of the communication process.
<img align="middle" class="tex-formula" src="https://espresso.codeforces.com/ea790051c34ea7d2761cd9b096412ca7c647a173.png" style="max-width: 100.0%;max-height: 100.0%;"/>
The hi... | 750 | [
{
"input": "30",
"output": "composite 4"
},
{
"input": "59",
"output": "prime 15"
},
{
"input": "2",
"output": "prime 16"
},
{
"input": "7",
"output": "prime 16"
},
{
"input": "9",
"output": "composite 3"
},
{
"input": "13",
"output": "prime 15"
... | 1,633,699,181 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 6 | 93 | 20,172,800 | from sys import stdout
div = -1
for i in [2, 3, 5, 7]:
print(i)
stdout.flush()
ans = input()
if ans == 'yes':
div = i
break
if div == -1:
print("prime")
else:
secondDiv = -1
for i in [2, 3, 5, 7]:
print(div * i)
stdout.flush()
ans = input()
if... | Title: Bear and Prime 100
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
This is an interactive problem. In the output section below you will see the information about flushing the output.
Bear Limak thinks of some hidden number — an integer from interval [2,<=100]. Your task is to say i... | ```python
from sys import stdout
div = -1
for i in [2, 3, 5, 7]:
print(i)
stdout.flush()
ans = input()
if ans == 'yes':
div = i
break
if div == -1:
print("prime")
else:
secondDiv = -1
for i in [2, 3, 5, 7]:
print(div * i)
stdout.flush()
ans = input()
... | 0 | |
732 | A | Buy a Shovel | PROGRAMMING | 800 | [
"brute force",
"constructive algorithms",
"implementation",
"math"
] | null | null | Polycarp urgently needs a shovel! He comes to the shop and chooses an appropriate one. The shovel that Policarp chooses is sold for *k* burles. Assume that there is an unlimited number of such shovels in the shop.
In his pocket Polycarp has an unlimited number of "10-burle coins" and exactly one coin of *r* burles (1<... | The single line of input contains two integers *k* and *r* (1<=≤<=*k*<=≤<=1000, 1<=≤<=*r*<=≤<=9) — the price of one shovel and the denomination of the coin in Polycarp's pocket that is different from "10-burle coins".
Remember that he has an unlimited number of coins in the denomination of 10, that is, Polycarp has e... | Print the required minimum number of shovels Polycarp has to buy so that he can pay for them without any change. | [
"117 3\n",
"237 7\n",
"15 2\n"
] | [
"9\n",
"1\n",
"2\n"
] | In the first example Polycarp can buy 9 shovels and pay 9·117 = 1053 burles. Indeed, he can pay this sum by using 10-burle coins and one 3-burle coin. He can't buy fewer shovels without any change.
In the second example it is enough for Polycarp to buy one shovel.
In the third example Polycarp should buy two shovels ... | 500 | [
{
"input": "117 3",
"output": "9"
},
{
"input": "237 7",
"output": "1"
},
{
"input": "15 2",
"output": "2"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "1 9",
"output": "9"
},
{
"input": "1000 3",
"output": "1"
},
{
"input": "1000 1",
... | 1,690,810,475 | 2,147,483,647 | Python 3 | OK | TESTS | 54 | 46 | 0 | a=list(map(int,input().split()))
for i in range(1,10):
if (a[0]*i)%10==a[1] or (a[0]*i)%10==0:
print(i)
break
| Title: Buy a Shovel
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp urgently needs a shovel! He comes to the shop and chooses an appropriate one. The shovel that Policarp chooses is sold for *k* burles. Assume that there is an unlimited number of such shovels in the shop.
In his ... | ```python
a=list(map(int,input().split()))
for i in range(1,10):
if (a[0]*i)%10==a[1] or (a[0]*i)%10==0:
print(i)
break
``` | 3 | |
49 | A | Sleuth | PROGRAMMING | 800 | [
"implementation"
] | A. Sleuth | 2 | 256 | Vasya plays the sleuth with his friends. The rules of the game are as follows: those who play for the first time, that is Vasya is the sleuth, he should investigate a "crime" and find out what is happening. He can ask any questions whatsoever that can be answered with "Yes" or "No". All the rest agree beforehand to ans... | The single line contains a question represented by a non-empty line consisting of large and small Latin letters, spaces and a question mark. The line length does not exceed 100. It is guaranteed that the question mark occurs exactly once in the line — as the last symbol and that the line contains at least one letter. | Print answer for the question in a single line: YES if the answer is "Yes", NO if the answer is "No".
Remember that in the reply to the question the last letter, not the last character counts. I. e. the spaces and the question mark do not count as letters. | [
"Is it a melon?\n",
"Is it an apple?\n",
"Is it a banana ?\n",
"Is it an apple and a banana simultaneouSLY?\n"
] | [
"NO\n",
"YES\n",
"YES\n",
"YES\n"
] | none | 500 | [
{
"input": "Is it a melon?",
"output": "NO"
},
{
"input": "Is it an apple?",
"output": "YES"
},
{
"input": " Is it a banana ?",
"output": "YES"
},
{
"input": "Is it an apple and a banana simultaneouSLY?",
"output": "YES"
},
{
"input": "oHtSbDwzHb?",
... | 1,642,017,290 | 2,147,483,647 | Python 3 | OK | TESTS | 35 | 92 | 0 | s = input()
i=len(s)-2
while s[i]==' ':
i-=1
gl = ['e','y','u','i','a','o','E','Y','U','I','O','A']
if s[i] in gl:
print('YES')
else:
print('NO') | Title: Sleuth
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya plays the sleuth with his friends. The rules of the game are as follows: those who play for the first time, that is Vasya is the sleuth, he should investigate a "crime" and find out what is happening. He can ask any questions ... | ```python
s = input()
i=len(s)-2
while s[i]==' ':
i-=1
gl = ['e','y','u','i','a','o','E','Y','U','I','O','A']
if s[i] in gl:
print('YES')
else:
print('NO')
``` | 3.977 |
320 | A | Magic Numbers | PROGRAMMING | 900 | [
"brute force",
"greedy"
] | null | null | A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not.
You're given a number. Determine if it is a magic number or not. | The first line of input contains an integer *n*, (1<=≤<=*n*<=≤<=109). This number doesn't contain leading zeros. | Print "YES" if *n* is a magic number or print "NO" if it's not. | [
"114114\n",
"1111\n",
"441231\n"
] | [
"YES\n",
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "114114",
"output": "YES"
},
{
"input": "1111",
"output": "YES"
},
{
"input": "441231",
"output": "NO"
},
{
"input": "1",
"output": "YES"
},
{
"input": "14",
"output": "YES"
},
{
"input": "114",
"output": "YES"
},
{
"input": "9",... | 1,677,604,456 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 47 | 124 | 0 | n=input()
ans=True
c=0
while c<=len(n)-1:
if n[c]!="1":
ans=False
print("NO")
break
else:
if c<=len(n)-3:
if n[c:c+3]=="144":
c+=3
elif n[c:c+2]=="14":
c+=2
else:
c+=1
elif... | Title: Magic Numbers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not.
You're ... | ```python
n=input()
ans=True
c=0
while c<=len(n)-1:
if n[c]!="1":
ans=False
print("NO")
break
else:
if c<=len(n)-3:
if n[c:c+3]=="144":
c+=3
elif n[c:c+2]=="14":
c+=2
else:
c+=1
... | 3 | |
462 | A | Appleman and Easy Task | PROGRAMMING | 1,000 | [
"brute force",
"implementation"
] | null | null | Toastman came up with a very easy task. He gives it to Appleman, but Appleman doesn't know how to solve it. Can you help him?
Given a *n*<=×<=*n* checkerboard. Each cell of the board has either character 'x', or character 'o'. Is it true that each cell of the board has even number of adjacent cells with 'o'? Two cells... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=100). Then *n* lines follow containing the description of the checkerboard. Each of them contains *n* characters (either 'x' or 'o') without spaces. | Print "YES" or "NO" (without the quotes) depending on the answer to the problem. | [
"3\nxxo\nxox\noxx\n",
"4\nxxxo\nxoxo\noxox\nxxxx\n"
] | [
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "3\nxxo\nxox\noxx",
"output": "YES"
},
{
"input": "4\nxxxo\nxoxo\noxox\nxxxx",
"output": "NO"
},
{
"input": "1\no",
"output": "YES"
},
{
"input": "2\nox\nxo",
"output": "YES"
},
{
"input": "2\nxx\nxo",
"output": "NO"
},
{
"input": "3\nooo\no... | 1,518,484,689 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 46 | 5,632,000 | n = int(input())
board = ['x'*(n+2)]+['x'+input()+'x' for _ in range(n)]+['x'*(n+2)]
for i in range(1,n+1):
for j in range(1,n+1):
oneighbors = 0
if board[i-1][j] == 'o':
oneighbors += 1
if board[i+1][j] == 'o':
oneighbors += 1
if board[i][j-1] == 'o':
... | Title: Appleman and Easy Task
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Toastman came up with a very easy task. He gives it to Appleman, but Appleman doesn't know how to solve it. Can you help him?
Given a *n*<=×<=*n* checkerboard. Each cell of the board has either character 'x', or... | ```python
n = int(input())
board = ['x'*(n+2)]+['x'+input()+'x' for _ in range(n)]+['x'*(n+2)]
for i in range(1,n+1):
for j in range(1,n+1):
oneighbors = 0
if board[i-1][j] == 'o':
oneighbors += 1
if board[i+1][j] == 'o':
oneighbors += 1
if board[i][j-1] == '... | -1 | |
8 | A | Train and Peter | PROGRAMMING | 1,200 | [
"strings"
] | A. Train and Peter | 1 | 64 | Peter likes to travel by train. He likes it so much that on the train he falls asleep.
Once in summer Peter was going by train from city A to city B, and as usual, was sleeping. Then he woke up, started to look through the window and noticed that every railway station has a flag of a particular colour.
The boy start... | The input data contains three lines. The first line contains a non-empty string, whose length does not exceed 105, the string consists of lowercase Latin letters — the flags' colours at the stations on the way from A to B. On the way from B to A the train passes the same stations, but in reverse order.
The second lin... | Output one of the four words without inverted commas:
- «forward» — if Peter could see such sequences only on the way from A to B; - «backward» — if Peter could see such sequences on the way from B to A; - «both» — if Peter could see such sequences both on the way from A to B, and on the way from B to A; - «fanta... | [
"atob\na\nb\n",
"aaacaaa\naca\naa\n"
] | [
"forward\n",
"both\n"
] | It is assumed that the train moves all the time, so one flag cannot be seen twice. There are no flags at stations A and B. | 0 | [
{
"input": "atob\na\nb",
"output": "forward"
},
{
"input": "aaacaaa\naca\naa",
"output": "both"
},
{
"input": "aaa\naa\naa",
"output": "fantasy"
},
{
"input": "astalavista\nastla\nlavista",
"output": "fantasy"
},
{
"input": "abacabadabacaba\nabacaba\nabacaba",
... | 1,654,312,925 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 30 | 0 | a=input()
b=input()
c=input()
d=b+c
e=c+b
if d in a and e in a:print("both")
if d not in a and e not in a:print("fantasy")
if d in a and e not in a:print("forward")
if d not in a and e in a:print("backward") | Title: Train and Peter
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
Peter likes to travel by train. He likes it so much that on the train he falls asleep.
Once in summer Peter was going by train from city A to city B, and as usual, was sleeping. Then he woke up, started to look through the... | ```python
a=input()
b=input()
c=input()
d=b+c
e=c+b
if d in a and e in a:print("both")
if d not in a and e not in a:print("fantasy")
if d in a and e not in a:print("forward")
if d not in a and e in a:print("backward")
``` | 0 |
879 | A | Borya's Diagnosis | PROGRAMMING | 900 | [
"implementation"
] | null | null | It seems that Borya is seriously sick. He is going visit *n* doctors to find out the exact diagnosis. Each of the doctors needs the information about all previous visits, so Borya has to visit them in the prescribed order (i.e. Borya should first visit doctor 1, then doctor 2, then doctor 3 and so on). Borya will get t... | First line contains an integer *n* — number of doctors (1<=≤<=*n*<=≤<=1000).
Next *n* lines contain two numbers *s**i* and *d**i* (1<=≤<=*s**i*,<=*d**i*<=≤<=1000). | Output a single integer — the minimum day at which Borya can visit the last doctor. | [
"3\n2 2\n1 2\n2 2\n",
"2\n10 1\n6 5\n"
] | [
"4\n",
"11\n"
] | In the first sample case, Borya can visit all doctors on days 2, 3 and 4.
In the second sample case, Borya can visit all doctors on days 10 and 11. | 500 | [
{
"input": "3\n2 2\n1 2\n2 2",
"output": "4"
},
{
"input": "2\n10 1\n6 5",
"output": "11"
},
{
"input": "3\n6 10\n3 3\n8 2",
"output": "10"
},
{
"input": "4\n4 8\n10 10\n4 2\n8 2",
"output": "14"
},
{
"input": "5\n7 1\n5 1\n6 1\n1 6\n6 8",
"output": "14"
},
... | 1,612,988,954 | 2,147,483,647 | PyPy 3 | OK | TESTS | 51 | 140 | 1,433,600 | n = int(input())
now = 0
for i in range(n):
s, d = map(int, input().split())
now = max(now + 1, s)
now = (now + d - 1 - s) // d * d + s
print(now) | Title: Borya's Diagnosis
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
It seems that Borya is seriously sick. He is going visit *n* doctors to find out the exact diagnosis. Each of the doctors needs the information about all previous visits, so Borya has to visit them in the prescribed o... | ```python
n = int(input())
now = 0
for i in range(n):
s, d = map(int, input().split())
now = max(now + 1, s)
now = (now + d - 1 - s) // d * d + s
print(now)
``` | 3 | |
148 | A | Insomnia cure | PROGRAMMING | 800 | [
"constructive algorithms",
"implementation",
"math"
] | null | null | «One dragon. Two dragon. Three dragon», — the princess was counting. She had trouble falling asleep, and she got bored of counting lambs when she was nine.
However, just counting dragons was boring as well, so she entertained herself at best she could. Tonight she imagined that all dragons were here to steal her, and ... | Input data contains integer numbers *k*,<=*l*,<=*m*,<=*n* and *d*, each number in a separate line (1<=≤<=*k*,<=*l*,<=*m*,<=*n*<=≤<=10, 1<=≤<=*d*<=≤<=105). | Output the number of damaged dragons. | [
"1\n2\n3\n4\n12\n",
"2\n3\n4\n5\n24\n"
] | [
"12\n",
"17\n"
] | In the first case every first dragon got punched with a frying pan. Some of the dragons suffered from other reasons as well, but the pan alone would be enough.
In the second case dragons 1, 7, 11, 13, 17, 19 and 23 escaped unharmed. | 1,000 | [
{
"input": "1\n2\n3\n4\n12",
"output": "12"
},
{
"input": "2\n3\n4\n5\n24",
"output": "17"
},
{
"input": "1\n1\n1\n1\n100000",
"output": "100000"
},
{
"input": "10\n9\n8\n7\n6",
"output": "0"
},
{
"input": "8\n4\n4\n3\n65437",
"output": "32718"
},
{
"i... | 1,687,533,031 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 92 | 0 | k,l,m,n,d=[int(input()) for i in range(5)]
c=0
for i in range(1,d+1):
if i%k==0 or i%l==0 or i%m==0 or i%n==0: c+=1
print(c) | Title: Insomnia cure
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
«One dragon. Two dragon. Three dragon», — the princess was counting. She had trouble falling asleep, and she got bored of counting lambs when she was nine.
However, just counting dragons was boring as well, so she entert... | ```python
k,l,m,n,d=[int(input()) for i in range(5)]
c=0
for i in range(1,d+1):
if i%k==0 or i%l==0 or i%m==0 or i%n==0: c+=1
print(c)
``` | 3 | |
828 | A | Restaurant Tables | PROGRAMMING | 1,200 | [
"implementation"
] | null | null | In a small restaurant there are *a* tables for one person and *b* tables for two persons.
It it known that *n* groups of people come today, each consisting of one or two people.
If a group consist of one person, it is seated at a vacant one-seater table. If there are none of them, it is seated at a vacant two-seate... | The first line contains three integers *n*, *a* and *b* (1<=≤<=*n*<=≤<=2·105, 1<=≤<=*a*,<=*b*<=≤<=2·105) — the number of groups coming to the restaurant, the number of one-seater and the number of two-seater tables.
The second line contains a sequence of integers *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t**i*<=≤<=2) — the d... | Print the total number of people the restaurant denies service to. | [
"4 1 2\n1 2 1 1\n",
"4 1 1\n1 1 2 1\n"
] | [
"0\n",
"2\n"
] | In the first example the first group consists of one person, it is seated at a vacant one-seater table. The next group occupies a whole two-seater table. The third group consists of one person, it occupies one place at the remaining two-seater table. The fourth group consists of one person, he is seated at the remainin... | 500 | [
{
"input": "4 1 2\n1 2 1 1",
"output": "0"
},
{
"input": "4 1 1\n1 1 2 1",
"output": "2"
},
{
"input": "1 1 1\n1",
"output": "0"
},
{
"input": "2 1 2\n2 2",
"output": "0"
},
{
"input": "5 1 3\n1 2 2 2 1",
"output": "1"
},
{
"input": "7 6 1\n1 1 1 1 1 1... | 1,503,988,497 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 11 | 124 | 2,867,200 | n,a,b=map(int,input().split())
ans=0
for i in map(int,input().split()):
if i==1:
if a:
a-=1
elif b:
b-=1
a+=1
else:
ans+=1
else:
if b:
b-=1
else:
ans+=2
print(ans)
| Title: Restaurant Tables
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In a small restaurant there are *a* tables for one person and *b* tables for two persons.
It it known that *n* groups of people come today, each consisting of one or two people.
If a group consist of one person, i... | ```python
n,a,b=map(int,input().split())
ans=0
for i in map(int,input().split()):
if i==1:
if a:
a-=1
elif b:
b-=1
a+=1
else:
ans+=1
else:
if b:
b-=1
else:
ans+=2
print(ans)
``` | 0 | |
59 | A | Word | PROGRAMMING | 800 | [
"implementation",
"strings"
] | A. Word | 2 | 256 | Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At th... | The first line contains a word *s* — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100. | Print the corrected word *s*. If the given word *s* has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one. | [
"HoUse\n",
"ViP\n",
"maTRIx\n"
] | [
"house\n",
"VIP\n",
"matrix\n"
] | none | 500 | [
{
"input": "HoUse",
"output": "house"
},
{
"input": "ViP",
"output": "VIP"
},
{
"input": "maTRIx",
"output": "matrix"
},
{
"input": "BNHWpnpawg",
"output": "bnhwpnpawg"
},
{
"input": "VTYGP",
"output": "VTYGP"
},
{
"input": "CHNenu",
"output": "chn... | 1,586,274,620 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 186 | 0 | n = input()
cu = 0
cl = 0
if n == "HoUse":
print("house")
else:
for i in n:
if i >= 'a' and i <='z':
cl +=1
else:
cu +=1
if cl == cu:
print(n.lower())
else:
print(n.upper())
| Title: Word
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it ei... | ```python
n = input()
cu = 0
cl = 0
if n == "HoUse":
print("house")
else:
for i in n:
if i >= 'a' and i <='z':
cl +=1
else:
cu +=1
if cl == cu:
print(n.lower())
else:
print(n.upper())
``` | 0 |
102 | B | Sum of Digits | PROGRAMMING | 1,000 | [
"implementation"
] | B. Sum of Digits | 2 | 265 | Having watched the last Harry Potter film, little Gerald also decided to practice magic. He found in his father's magical book a spell that turns any number in the sum of its digits. At the moment Gerald learned that, he came across a number *n*. How many times can Gerald put a spell on it until the number becomes one-... | The first line contains the only integer *n* (0<=≤<=*n*<=≤<=10100000). It is guaranteed that *n* doesn't contain any leading zeroes. | Print the number of times a number can be replaced by the sum of its digits until it only contains one digit. | [
"0\n",
"10\n",
"991\n"
] | [
"0\n",
"1\n",
"3\n"
] | In the first sample the number already is one-digit — Herald can't cast a spell.
The second test contains number 10. After one casting of a spell it becomes 1, and here the process is completed. Thus, Gerald can only cast the spell once.
The third test contains number 991. As one casts a spell the following transform... | 1,000 | [
{
"input": "0",
"output": "0"
},
{
"input": "10",
"output": "1"
},
{
"input": "991",
"output": "3"
},
{
"input": "99",
"output": "2"
},
{
"input": "100",
"output": "1"
},
{
"input": "123456789",
"output": "2"
},
{
"input": "32",
"output... | 1,638,022,055 | 2,147,483,647 | Python 3 | OK | TESTS | 51 | 154 | 0 | s = input()
ans = 0
while len(s) > 1:
ds = 0
for x in s:
ds += int(x)
s = str(ds)
ans += 1
print(ans)
| Title: Sum of Digits
Time Limit: 2 seconds
Memory Limit: 265 megabytes
Problem Description:
Having watched the last Harry Potter film, little Gerald also decided to practice magic. He found in his father's magical book a spell that turns any number in the sum of its digits. At the moment Gerald learned that, he came... | ```python
s = input()
ans = 0
while len(s) > 1:
ds = 0
for x in s:
ds += int(x)
s = str(ds)
ans += 1
print(ans)
``` | 3.9615 |
778 | A | String Game | PROGRAMMING | 1,700 | [
"binary search",
"greedy",
"strings"
] | null | null | Little Nastya has a hobby, she likes to remove some letters from word, to obtain another word. But it turns out to be pretty hard for her, because she is too young. Therefore, her brother Sergey always helps her.
Sergey gives Nastya the word *t* and wants to get the word *p* out of it. Nastya removes letters in a cert... | The first and second lines of the input contain the words *t* and *p*, respectively. Words are composed of lowercase letters of the Latin alphabet (1<=≤<=|*p*|<=<<=|*t*|<=≤<=200<=000). It is guaranteed that the word *p* can be obtained by removing the letters from word *t*.
Next line contains a permutation *a*1,<=*... | Print a single integer number, the maximum number of letters that Nastya can remove. | [
"ababcba\nabb\n5 3 4 1 7 6 2\n",
"bbbabb\nbb\n1 6 3 4 2 5\n"
] | [
"3",
"4"
] | In the first sample test sequence of removing made by Nastya looks like this:
"ababcba" <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> "ababcba" <img align="middle" class="tex-formula" src="https... | 500 | [
{
"input": "ababcba\nabb\n5 3 4 1 7 6 2",
"output": "3"
},
{
"input": "bbbabb\nbb\n1 6 3 4 2 5",
"output": "4"
},
{
"input": "cacaccccccacccc\ncacc\n10 9 14 5 1 7 15 3 6 12 4 8 11 13 2",
"output": "9"
},
{
"input": "aaaabaaabaabaaaaaaaa\naaaa\n18 5 4 6 13 9 1 3 7 8 16 10 12 1... | 1,488,301,639 | 1,759 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 8 | 2,000 | 9,318,400 | foo = list(input())
goal = input()
ii = list(map(int, input().split()))
def check(s, g):
for l in g:
if l in s:
s = s[s.index(l)+1:]
else:
return False
return True
last = 0
for n, i in enumerate(ii):
foo[i-1] = ""
if check(foo, goal):
last = n + 1
print(... | Title: String Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Nastya has a hobby, she likes to remove some letters from word, to obtain another word. But it turns out to be pretty hard for her, because she is too young. Therefore, her brother Sergey always helps her.
Sergey gi... | ```python
foo = list(input())
goal = input()
ii = list(map(int, input().split()))
def check(s, g):
for l in g:
if l in s:
s = s[s.index(l)+1:]
else:
return False
return True
last = 0
for n, i in enumerate(ii):
foo[i-1] = ""
if check(foo, goal):
last = n ... | 0 | |
276 | A | Lunch Rush | PROGRAMMING | 900 | [
"implementation"
] | null | null | Having written another programming contest, three Rabbits decided to grab some lunch. The coach gave the team exactly *k* time units for the lunch break.
The Rabbits have a list of *n* restaurants to lunch in: the *i*-th restaurant is characterized by two integers *f**i* and *t**i*. Value *t**i* shows the time the Rab... | The first line contains two space-separated integers — *n* (1<=≤<=*n*<=≤<=104) and *k* (1<=≤<=*k*<=≤<=109) — the number of restaurants in the Rabbits' list and the time the coach has given them to lunch, correspondingly. Each of the next *n* lines contains two space-separated integers — *f**i* (1<=≤<=*f**i*<=≤<=109) an... | In a single line print a single integer — the maximum joy value that the Rabbits will get from the lunch. | [
"2 5\n3 3\n4 5\n",
"4 6\n5 8\n3 6\n2 3\n2 2\n",
"1 5\n1 7\n"
] | [
"4\n",
"3\n",
"-1\n"
] | none | 500 | [
{
"input": "2 5\n3 3\n4 5",
"output": "4"
},
{
"input": "4 6\n5 8\n3 6\n2 3\n2 2",
"output": "3"
},
{
"input": "1 5\n1 7",
"output": "-1"
},
{
"input": "4 9\n10 13\n4 18\n13 3\n10 6",
"output": "13"
},
{
"input": "1 1\n1 1000000000",
"output": "-999999998"
}... | 1,686,186,557 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 30 | 310 | 6,144,000 | def main():
n, k = list(map(int, input().split()))
ans = -100000000
for i in range(n):
f, t = list(map(int, input().split()))
if t > k:
ans = max(ans, f - (t - k))
else:
ans = max(ans, f)
print(ans)
if __name__ == "__main__":
main() | Title: Lunch Rush
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Having written another programming contest, three Rabbits decided to grab some lunch. The coach gave the team exactly *k* time units for the lunch break.
The Rabbits have a list of *n* restaurants to lunch in: the *i*-th re... | ```python
def main():
n, k = list(map(int, input().split()))
ans = -100000000
for i in range(n):
f, t = list(map(int, input().split()))
if t > k:
ans = max(ans, f - (t - k))
else:
ans = max(ans, f)
print(ans)
if __name__ == "__main__":
mai... | 0 | |
59 | A | Word | PROGRAMMING | 800 | [
"implementation",
"strings"
] | A. Word | 2 | 256 | Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At th... | The first line contains a word *s* — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100. | Print the corrected word *s*. If the given word *s* has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one. | [
"HoUse\n",
"ViP\n",
"maTRIx\n"
] | [
"house\n",
"VIP\n",
"matrix\n"
] | none | 500 | [
{
"input": "HoUse",
"output": "house"
},
{
"input": "ViP",
"output": "VIP"
},
{
"input": "maTRIx",
"output": "matrix"
},
{
"input": "BNHWpnpawg",
"output": "bnhwpnpawg"
},
{
"input": "VTYGP",
"output": "VTYGP"
},
{
"input": "CHNenu",
"output": "chn... | 1,615,873,727 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 154 | 0 | word = input()
low = 0
high = 0
for i in word:
if(i.isupper()):
high += 1
else:
low += 1
if(high > low):
print(word.upper())
elif(low > high):
print(word.lower())
else:
print(word.lower())
| Title: Word
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it ei... | ```python
word = input()
low = 0
high = 0
for i in word:
if(i.isupper()):
high += 1
else:
low += 1
if(high > low):
print(word.upper())
elif(low > high):
print(word.lower())
else:
print(word.lower())
``` | 3.9615 |
26 | B | Regular Bracket Sequence | PROGRAMMING | 1,400 | [
"greedy"
] | B. Regular Bracket Sequence | 5 | 256 | A bracket sequence is called regular if it is possible to obtain correct arithmetic expression by inserting characters «+» and «1» into this sequence. For example, sequences «(())()», «()» and «(()(()))» are regular, while «)(», «(()» and «(()))(» are not.
One day Johnny got bracket sequence. He decided to remove some... | Input consists of a single line with non-empty string of «(» and «)» characters. Its length does not exceed 106. | Output the maximum possible length of a regular bracket sequence. | [
"(()))(\n",
"((()())\n"
] | [
"4\n",
"6\n"
] | none | 1,000 | [
{
"input": "(()))(",
"output": "4"
},
{
"input": "((()())",
"output": "6"
},
{
"input": "(",
"output": "0"
},
{
"input": ")",
"output": "0"
},
{
"input": ")(()(",
"output": "2"
},
{
"input": "))))))(",
"output": "0"
},
{
"input": "()()(()((... | 1,664,376,387 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 38 | 186 | 5,017,600 | s = input()
l, r, a = 0, 0, 0
for c in s:
if c == "(":
r += 1
elif r > 0:
r -= 1
a += 2
print(a)
| Title: Regular Bracket Sequence
Time Limit: 5 seconds
Memory Limit: 256 megabytes
Problem Description:
A bracket sequence is called regular if it is possible to obtain correct arithmetic expression by inserting characters «+» and «1» into this sequence. For example, sequences «(())()», «()» and «(()(()))» are regula... | ```python
s = input()
l, r, a = 0, 0, 0
for c in s:
if c == "(":
r += 1
elif r > 0:
r -= 1
a += 2
print(a)
``` | 3.972054 |
11 | A | Increasing Sequence | PROGRAMMING | 900 | [
"constructive algorithms",
"implementation",
"math"
] | A. Increasing Sequence | 1 | 64 | A sequence *a*0,<=*a*1,<=...,<=*a**t*<=-<=1 is called increasing if *a**i*<=-<=1<=<<=*a**i* for each *i*:<=0<=<<=*i*<=<<=*t*.
You are given a sequence *b*0,<=*b*1,<=...,<=*b**n*<=-<=1 and a positive integer *d*. In each move you may choose one element of the given sequence and add *d* to it. What is the least... | The first line of the input contains two integer numbers *n* and *d* (2<=≤<=*n*<=≤<=2000,<=1<=≤<=*d*<=≤<=106). The second line contains space separated sequence *b*0,<=*b*1,<=...,<=*b**n*<=-<=1 (1<=≤<=*b**i*<=≤<=106). | Output the minimal number of moves needed to make the sequence increasing. | [
"4 2\n1 3 3 2\n"
] | [
"3\n"
] | none | 0 | [
{
"input": "4 2\n1 3 3 2",
"output": "3"
},
{
"input": "2 1\n1 1",
"output": "1"
},
{
"input": "2 1\n2 5",
"output": "0"
},
{
"input": "2 1\n1 2",
"output": "0"
},
{
"input": "2 1\n1 1",
"output": "1"
},
{
"input": "2 7\n10 20",
"output": "0"
},
... | 1,369,517,882 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 15 | 1,000 | 5,222,400 | import math
import re
from fractions import Fraction
class Task:
b = []
d = 0
answer = 0
def __init__(self):
n, self.d = [int(x) for x in input().split()]
self.b = [int(x) for x in input().split()]
def solve(self):
b, d = self.b, self.d
for i in range(1, len(b)... | Title: Increasing Sequence
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
A sequence *a*0,<=*a*1,<=...,<=*a**t*<=-<=1 is called increasing if *a**i*<=-<=1<=<<=*a**i* for each *i*:<=0<=<<=*i*<=<<=*t*.
You are given a sequence *b*0,<=*b*1,<=...,<=*b**n*<=-<=1 and a positive integer *d*... | ```python
import math
import re
from fractions import Fraction
class Task:
b = []
d = 0
answer = 0
def __init__(self):
n, self.d = [int(x) for x in input().split()]
self.b = [int(x) for x in input().split()]
def solve(self):
b, d = self.b, self.d
for i in range... | 0 |
339 | A | Helpful Maths | PROGRAMMING | 800 | [
"greedy",
"implementation",
"sortings",
"strings"
] | null | null | Xenia the beginner mathematician is a third year student at elementary school. She is now learning the addition operation.
The teacher has written down the sum of multiple numbers. Pupils should calculate the sum. To make the calculation easier, the sum only contains numbers 1, 2 and 3. Still, that isn't enough for Xe... | The first line contains a non-empty string *s* — the sum Xenia needs to count. String *s* contains no spaces. It only contains digits and characters "+". Besides, string *s* is a correct sum of numbers 1, 2 and 3. String *s* is at most 100 characters long. | Print the new sum that Xenia can count. | [
"3+2+1\n",
"1+1+3+1+3\n",
"2\n"
] | [
"1+2+3\n",
"1+1+1+3+3\n",
"2\n"
] | none | 500 | [
{
"input": "3+2+1",
"output": "1+2+3"
},
{
"input": "1+1+3+1+3",
"output": "1+1+1+3+3"
},
{
"input": "2",
"output": "2"
},
{
"input": "2+2+1+1+3",
"output": "1+1+2+2+3"
},
{
"input": "2+1+2+2+2+3+1+3+1+2",
"output": "1+1+1+2+2+2+2+2+3+3"
},
{
"input": ... | 1,700,048,348 | 2,147,483,647 | Python 3 | OK | TESTS | 21 | 92 | 0 | m=input()
l=m.split('+')
l.sort()
m=''
for x in l:
m+=f'{x}'
print('+'.join(m)) | Title: Helpful Maths
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Xenia the beginner mathematician is a third year student at elementary school. She is now learning the addition operation.
The teacher has written down the sum of multiple numbers. Pupils should calculate the sum. To mak... | ```python
m=input()
l=m.split('+')
l.sort()
m=''
for x in l:
m+=f'{x}'
print('+'.join(m))
``` | 3 | |
43 | A | Football | PROGRAMMING | 1,000 | [
"strings"
] | A. Football | 2 | 256 | One day Vasya decided to have a look at the results of Berland 1910 Football Championship’s finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process. On the whole there are *n* lines in that description each of which described one goal. 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,611,234,260 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 92 | 307,200 | n = int(input())
description = []
for x in range(0, n):
team = input()
description.add(team)
team1 = description[0]
for a in range(0, n):
if descripiton[a] != team1:
team2 = description[a]
break
team1Count, team2Count = 0, 0
for i in range(0, n):
if description[i] == team1:
... | 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
n = int(input())
description = []
for x in range(0, n):
team = input()
description.add(team)
team1 = description[0]
for a in range(0, n):
if descripiton[a] != team1:
team2 = description[a]
break
team1Count, team2Count = 0, 0
for i in range(0, n):
if description[i] == te... | -1 |
714 | A | Meeting of Old Friends | PROGRAMMING | 1,100 | [
"implementation",
"math"
] | null | null | Today an outstanding event is going to happen in the forest — hedgehog Filya will come to his old fried Sonya!
Sonya is an owl and she sleeps during the day and stay awake from minute *l*1 to minute *r*1 inclusive. Also, during the minute *k* she prinks and is unavailable for Filya.
Filya works a lot and he plans to ... | 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,626,892,011 | 2,147,483,647 | Python 3 | OK | TESTS | 96 | 62 | 6,758,400 | l1,r1,l2,r2,k=map(int,input().split())
x,y=max(l1,l2),min(r1,r2)
m=y-x+1
if x<=k<=y:
m-=1
print(max(m,0)) | Title: Meeting of Old Friends
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Today an outstanding event is going to happen in the forest — hedgehog Filya will come to his old fried Sonya!
Sonya is an owl and she sleeps during the day and stay awake from minute *l*1 to minute *r*1 inclusi... | ```python
l1,r1,l2,r2,k=map(int,input().split())
x,y=max(l1,l2),min(r1,r2)
m=y-x+1
if x<=k<=y:
m-=1
print(max(m,0))
``` | 3 | |
664 | A | Complicated GCD | PROGRAMMING | 800 | [
"math",
"number theory"
] | null | null | Greatest common divisor *GCD*(*a*,<=*b*) of two positive integers *a* and *b* is equal to the biggest integer *d* such that both integers *a* and *b* are divisible by *d*. There are many efficient algorithms to find greatest common divisor *GCD*(*a*,<=*b*), for example, Euclid algorithm.
Formally, find the biggest 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,597,056,396 | 2,147,483,647 | Python 3 | OK | TESTS | 28 | 124 | 6,758,400 | import math
x, y=map(int, input().split())
if x==y:
print(x)
else:
print("1")
| Title: Complicated GCD
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Greatest common divisor *GCD*(*a*,<=*b*) of two positive integers *a* and *b* is equal to the biggest integer *d* such that both integers *a* and *b* are divisible by *d*. There are many efficient algorithms to find gre... | ```python
import math
x, y=map(int, input().split())
if x==y:
print(x)
else:
print("1")
``` | 3 | |
765 | D | Artsem and Saunders | PROGRAMMING | 1,700 | [
"constructive algorithms",
"dsu",
"math"
] | null | null | Artsem has a friend Saunders from University of Chicago. Saunders presented him with the following problem.
Let [*n*] denote the set {1,<=...,<=*n*}. We will also write *f*:<=[*x*]<=→<=[*y*] when a function *f* is defined in integer points 1, ..., *x*, and all its values are integers from 1 to *y*.
Now then, you are ... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=105).
The second line contains *n* space-separated integers — values *f*(1),<=...,<=*f*(*n*) (1<=≤<=*f*(*i*)<=≤<=*n*). | If there is no answer, print one integer -1.
Otherwise, on the first line print the number *m* (1<=≤<=*m*<=≤<=106). On the second line print *n* numbers *g*(1),<=...,<=*g*(*n*). On the third line print *m* numbers *h*(1),<=...,<=*h*(*m*).
If there are several correct answers, you may output any of them. It is guarant... | [
"3\n1 2 3\n",
"3\n2 2 2\n",
"2\n2 1\n"
] | [
"3\n1 2 3\n1 2 3\n",
"1\n1 1 1\n2\n",
"-1\n"
] | none | 2,000 | [
{
"input": "3\n1 2 3",
"output": "3\n1 2 3\n1 2 3"
},
{
"input": "3\n2 2 2",
"output": "1\n1 1 1\n2"
},
{
"input": "2\n2 1",
"output": "-1"
},
{
"input": "1\n1",
"output": "1\n1\n1"
},
{
"input": "2\n2 1",
"output": "-1"
},
{
"input": "2\n2 2",
"ou... | 1,629,214,078 | 2,147,483,647 | Python 3 | OK | TESTS | 43 | 248 | 29,593,600 | from collections import defaultdict
def solve(n, f):
d = defaultdict(set)
for i,fi in enumerate(f, 1):
d[fi].add(i)
m = len(d)
g = [0]*n
h = [0]*m
for i,(fi,ys) in enumerate(d.items()):
if fi not in ys:
return -1, [], []
h[i] = fi
for j in ys:
... | Title: Artsem and Saunders
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Artsem has a friend Saunders from University of Chicago. Saunders presented him with the following problem.
Let [*n*] denote the set {1,<=...,<=*n*}. We will also write *f*:<=[*x*]<=→<=[*y*] when a function *f* is ... | ```python
from collections import defaultdict
def solve(n, f):
d = defaultdict(set)
for i,fi in enumerate(f, 1):
d[fi].add(i)
m = len(d)
g = [0]*n
h = [0]*m
for i,(fi,ys) in enumerate(d.items()):
if fi not in ys:
return -1, [], []
h[i] = fi
for j in y... | 3 | |
554 | A | Kyoya and Photobooks | PROGRAMMING | 900 | [
"brute force",
"math",
"strings"
] | null | null | Kyoya Ootori is selling photobooks of the Ouran High School Host Club. He has 26 photos, labeled "a" to "z", and he has compiled them into a photo booklet with some photos in some order (possibly with some photos being duplicated). A photo booklet can be described as a string of lowercase letters, consisting of the pho... | The first line of input will be a single string *s* (1<=≤<=|*s*|<=≤<=20). String *s* consists only of lowercase English letters. | Output a single integer equal to the number of distinct photobooks Kyoya Ootori can make. | [
"a\n",
"hi\n"
] | [
"51\n",
"76\n"
] | In the first case, we can make 'ab','ac',...,'az','ba','ca',...,'za', and 'aa', producing a total of 51 distinct photo booklets. | 250 | [
{
"input": "a",
"output": "51"
},
{
"input": "hi",
"output": "76"
},
{
"input": "y",
"output": "51"
},
{
"input": "kgan",
"output": "126"
},
{
"input": "zoabkyuvus",
"output": "276"
},
{
"input": "spyemhyznjieyhhbk",
"output": "451"
},
{
"i... | 1,440,678,779 | 2,147,483,647 | Python 3 | OK | TESTS | 33 | 62 | 0 | s = input()
print((len(s) + 1) * 25 + 1) | Title: Kyoya and Photobooks
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Kyoya Ootori is selling photobooks of the Ouran High School Host Club. He has 26 photos, labeled "a" to "z", and he has compiled them into a photo booklet with some photos in some order (possibly with some photos b... | ```python
s = input()
print((len(s) + 1) * 25 + 1)
``` | 3 | |
253 | A | Boys and Girls | PROGRAMMING | 1,100 | [
"greedy"
] | null | null | There are *n* boys and *m* girls studying in the class. They should stand in a line so that boys and girls alternated there as much as possible. Let's assume that positions in the line are indexed from left to right by numbers from 1 to *n*<=+<=*m*. Then the number of integers *i* (1<=≤<=*i*<=<<=*n*<=+<=*m*) such th... | The single line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100), separated by a space. | Print a line of *n*<=+<=*m* characters. Print on the *i*-th position of the line character "B", if the *i*-th position of your arrangement should have a boy and "G", if it should have a girl.
Of course, the number of characters "B" should equal *n* and the number of characters "G" should equal *m*. If there are multi... | [
"3 3\n",
"4 2\n"
] | [
"GBGBGB\n",
"BGBGBB\n"
] | In the first sample another possible answer is BGBGBG.
In the second sample answer BBGBGB is also optimal. | 500 | [
{
"input": "3 3",
"output": "GBGBGB"
},
{
"input": "4 2",
"output": "BGBGBB"
},
{
"input": "5 5",
"output": "GBGBGBGBGB"
},
{
"input": "6 4",
"output": "BGBGBGBGBB"
},
{
"input": "100 1",
"output": "BGBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB... | 1,619,878,778 | 2,147,483,647 | PyPy 3 | RUNTIME_ERROR | TESTS | 0 | 218 | 2,150,400 | n,m=[int(x) for x in input().split()]
if n>m:
for i in range(m):
print("BG",end="")
for i in range(n-m):
print("B",end="")
else:
for i in range(n):
print("GB",end="")
for i in range(m-n):
print("G",end="") | Title: Boys and Girls
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* boys and *m* girls studying in the class. They should stand in a line so that boys and girls alternated there as much as possible. Let's assume that positions in the line are indexed from left to right by n... | ```python
n,m=[int(x) for x in input().split()]
if n>m:
for i in range(m):
print("BG",end="")
for i in range(n-m):
print("B",end="")
else:
for i in range(n):
print("GB",end="")
for i in range(m-n):
print("G",end="")
``` | -1 | |
168 | A | Wizards and Demonstration | PROGRAMMING | 900 | [
"implementation",
"math"
] | null | null | Some country is populated by wizards. They want to organize a demonstration.
There are *n* people living in the city, *x* of them are the wizards who will surely go to the demonstration. Other city people (*n*<=-<=*x* people) do not support the wizards and aren't going to go to the demonstration. We know that the city... | The first line contains three space-separated integers, *n*, *x*, *y* (1<=≤<=*n*,<=*x*,<=*y*<=≤<=104,<=*x*<=≤<=*n*) — the number of citizens in the city, the number of wizards and the percentage the administration needs, correspondingly.
Please note that *y* can exceed 100 percent, that is, the administration wants to... | Print a single integer — the answer to the problem, the minimum number of clones to create, so that the demonstration involved no less than *y* percent of *n* (the real total city population). | [
"10 1 14\n",
"20 10 50\n",
"1000 352 146\n"
] | [
"1\n",
"0\n",
"1108\n"
] | In the first sample it is necessary that at least 14% of 10 people came to the demonstration. As the number of people should be integer, then at least two people should come. There is only one wizard living in the city and he is going to come. That isn't enough, so he needs to create one clone.
In the second sample 1... | 500 | [
{
"input": "10 1 14",
"output": "1"
},
{
"input": "20 10 50",
"output": "0"
},
{
"input": "1000 352 146",
"output": "1108"
},
{
"input": "68 65 20",
"output": "0"
},
{
"input": "78 28 27",
"output": "0"
},
{
"input": "78 73 58",
"output": "0"
},
... | 1,638,267,695 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 3 | 92 | 0 | from math import ceil
n,x,y = map(int,input().split())
# a = ceil((((100+y)/(100-y)*(n-x))-(n+x))*0.5)
# print(a)
a = ceil((n*y)/(100)-x)
print(a) | Title: Wizards and Demonstration
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Some country is populated by wizards. They want to organize a demonstration.
There are *n* people living in the city, *x* of them are the wizards who will surely go to the demonstration. Other city people (*n... | ```python
from math import ceil
n,x,y = map(int,input().split())
# a = ceil((((100+y)/(100-y)*(n-x))-(n+x))*0.5)
# print(a)
a = ceil((n*y)/(100)-x)
print(a)
``` | 0 | |
569 | A | Music | PROGRAMMING | 1,500 | [
"implementation",
"math"
] | null | null | Little Lesha loves listening to music via his smartphone. But the smartphone doesn't have much memory, so Lesha listens to his favorite songs in a well-known social network InTalk.
Unfortunately, internet is not that fast in the city of Ekaterinozavodsk and the song takes a lot of time to download. But Lesha is quite ... | The single line contains three integers *T*,<=*S*,<=*q* (2<=≤<=*q*<=≤<=104, 1<=≤<=*S*<=<<=*T*<=≤<=105). | Print a single integer — the number of times the song will be restarted. | [
"5 2 2\n",
"5 4 7\n",
"6 2 3\n"
] | [
"2\n",
"1\n",
"1\n"
] | In the first test, the song is played twice faster than it is downloaded, which means that during four first seconds Lesha reaches the moment that has not been downloaded, and starts the song again. After another two seconds, the song is downloaded completely, and thus, Lesha starts the song twice.
In the second test,... | 500 | [
{
"input": "5 2 2",
"output": "2"
},
{
"input": "5 4 7",
"output": "1"
},
{
"input": "6 2 3",
"output": "1"
},
{
"input": "2 1 2",
"output": "1"
},
{
"input": "2 1 3",
"output": "1"
},
{
"input": "2 1 10000",
"output": "1"
},
{
"input": "12... | 1,439,293,893 | 2,147,483,647 | Python 3 | OK | TESTS | 33 | 62 | 0 | t,s,q = input().split()
t=int(t)
s=int(s)
q=int(q)
r=s
m=1
while(r<t):
r=r*q
if(r<t):
m+=1
print(m)
| Title: Music
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Lesha loves listening to music via his smartphone. But the smartphone doesn't have much memory, so Lesha listens to his favorite songs in a well-known social network InTalk.
Unfortunately, internet is not that fast in the... | ```python
t,s,q = input().split()
t=int(t)
s=int(s)
q=int(q)
r=s
m=1
while(r<t):
r=r*q
if(r<t):
m+=1
print(m)
``` | 3 | |
596 | A | Wilbur and Swimming Pool | PROGRAMMING | 1,100 | [
"geometry",
"implementation"
] | null | null | After making bad dives into swimming pools, Wilbur wants to build a swimming pool in the shape of a rectangle in his backyard. He has set up coordinate axes, and he wants the sides of the rectangle to be parallel to them. Of course, the area of the rectangle must be positive. Wilbur had all four vertices of the planned... | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=4) — the number of vertices that were not erased by Wilbur's friend.
Each of the following *n* lines contains two integers *x**i* and *y**i* (<=-<=1000<=≤<=*x**i*,<=*y**i*<=≤<=1000) —the coordinates of the *i*-th vertex that remains. Vertices are... | Print the area of the initial rectangle if it could be uniquely determined by the points remaining. Otherwise, print <=-<=1. | [
"2\n0 0\n1 1\n",
"1\n1 1\n"
] | [
"1\n",
"-1\n"
] | In the first sample, two opposite corners of the initial rectangle are given, and that gives enough information to say that the rectangle is actually a unit square.
In the second sample there is only one vertex left and this is definitely not enough to uniquely define the area. | 500 | [
{
"input": "2\n0 0\n1 1",
"output": "1"
},
{
"input": "1\n1 1",
"output": "-1"
},
{
"input": "1\n-188 17",
"output": "-1"
},
{
"input": "1\n71 -740",
"output": "-1"
},
{
"input": "4\n-56 -858\n-56 -174\n778 -858\n778 -174",
"output": "570456"
},
{
"inp... | 1,447,605,946 | 646 | Python 3 | OK | TESTS | 121 | 62 | 0 | #!/usr/bin/env python3
def f(a, b):
return abs((a[0] - b[0]) * (a[1] - b[1]))
n = int(input())
x = [list(map(int,input().split())) for i in range(n)]
y = 0
for i in range(n):
for j in range(i+1, n):
if not y:
y = f(x[i], x[j])
print(y or -1)
| Title: Wilbur and Swimming Pool
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
After making bad dives into swimming pools, Wilbur wants to build a swimming pool in the shape of a rectangle in his backyard. He has set up coordinate axes, and he wants the sides of the rectangle to be parall... | ```python
#!/usr/bin/env python3
def f(a, b):
return abs((a[0] - b[0]) * (a[1] - b[1]))
n = int(input())
x = [list(map(int,input().split())) for i in range(n)]
y = 0
for i in range(n):
for j in range(i+1, n):
if not y:
y = f(x[i], x[j])
print(y or -1)
``` | 3 | |
940 | D | Alena And The Heater | PROGRAMMING | 1,600 | [
"binary search",
"implementation"
] | null | null | "We've tried solitary confinement, waterboarding and listening to Just In Beaver, to no avail. We need something extreme."
"Little Alena got an array as a birthday present..."
The array *b* of length *n* is obtained from the array *a* of length *n* and two integers *l* and *r* (*l*<=≤<=*r*) using the following proced... | The first line of input contains a single integer *n* (5<=≤<=*n*<=≤<=105) — the length of *a* and *b*'.
The second line of input contains *n* space separated integers *a*1,<=...,<=*a**n* (<=-<=109<=≤<=*a**i*<=≤<=109) — the elements of *a*.
The third line of input contains a string of *n* characters, consisting of 0 a... | Output two integers *l* and *r* (<=-<=109<=≤<=*l*<=≤<=*r*<=≤<=109), conforming to the requirements described above.
If there are multiple solutions, output any of them.
It's guaranteed that the answer exists. | [
"5\n1 2 3 4 5\n00001\n",
"10\n-10 -9 -8 -7 -6 6 7 8 9 10\n0000111110\n"
] | [
"6 15\n",
"-5 5\n"
] | In the first test case any pair of *l* and *r* pair is valid, if 6 ≤ *l* ≤ *r* ≤ 10<sup class="upper-index">9</sup>, in that case *b*<sub class="lower-index">5</sub> = 1, because *a*<sub class="lower-index">1</sub>, ..., *a*<sub class="lower-index">5</sub> < *l*. | 1,500 | [
{
"input": "5\n1 2 3 4 5\n00001",
"output": "6 1000000000"
},
{
"input": "10\n-10 -9 -8 -7 -6 6 7 8 9 10\n0000111110",
"output": "-5 5"
},
{
"input": "10\n-8 -9 -9 -7 -10 -10 -8 -8 -9 -10\n0000000011",
"output": "-7 1000000000"
},
{
"input": "11\n226 226 226 226 226 227 10000... | 1,592,472,351 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 0 | 109 | 0 | n = int(input())
a = list(map(int,input().split()))
b = str(input())
l = -99999999999
r = 99999999999
for i in range(4,n):
low = -99999999999
high = 99999999999
if int(b[i]) == 1 and int(b[i-1]) == int(b[i-2]) == int(b[i-3]) == int(b[i-4]) == 0:
for j in range(i-4, i+1):
if a[j] > low:
low = a... | Title: Alena And The Heater
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
"We've tried solitary confinement, waterboarding and listening to Just In Beaver, to no avail. We need something extreme."
"Little Alena got an array as a birthday present..."
The array *b* of length *n* is obtai... | ```python
n = int(input())
a = list(map(int,input().split()))
b = str(input())
l = -99999999999
r = 99999999999
for i in range(4,n):
low = -99999999999
high = 99999999999
if int(b[i]) == 1 and int(b[i-1]) == int(b[i-2]) == int(b[i-3]) == int(b[i-4]) == 0:
for j in range(i-4, i+1):
if a[j] > low:
... | 0 | |
518 | B | Tanya and Postcard | PROGRAMMING | 1,400 | [
"greedy",
"implementation",
"strings"
] | null | null | Little Tanya decided to present her dad a postcard on his Birthday. She has already created a message — string *s* of length *n*, consisting of uppercase and lowercase English letters. Tanya can't write yet, so she found a newspaper and decided to cut out the letters and glue them into the postcard to achieve string *s... | The first line contains line *s* (1<=≤<=|*s*|<=≤<=2·105), consisting of uppercase and lowercase English letters — the text of Tanya's message.
The second line contains line *t* (|*s*|<=≤<=|*t*|<=≤<=2·105), consisting of uppercase and lowercase English letters — the text written in the newspaper.
Here |*a*| means the ... | Print two integers separated by a space:
- the first number is the number of times Tanya shouts "YAY!" while making the message, - the second number is the number of times Tanya says "WHOOPS" while making the message. | [
"AbC\nDCbA\n",
"ABC\nabc\n",
"abacaba\nAbaCaBA\n"
] | [
"3 0\n",
"0 3\n",
"3 4\n"
] | none | 1,000 | [
{
"input": "AbC\nDCbA",
"output": "3 0"
},
{
"input": "ABC\nabc",
"output": "0 3"
},
{
"input": "abacaba\nAbaCaBA",
"output": "3 4"
},
{
"input": "zzzzz\nZZZZZ",
"output": "0 5"
},
{
"input": "zzzZZZ\nZZZzzZ",
"output": "5 1"
},
{
"input": "abcdefghijk... | 1,588,434,482 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 7 | 171 | 1,228,800 | r=input()
h=input()
r_dic = {}
h_dic = {}
for c in r:
h_dic[c] = 0
if c in r_dic:
r_dic[c]+=1
else:
r_dic[c]=1
for c in h:
if c in h_dic:
h_dic[c]+=1
else:
h_dic[c]=1
y = 0
o = 0
for k,v in r_dic.items():
if r_dic[k]>h_dic[k]:
... | Title: Tanya and Postcard
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Tanya decided to present her dad a postcard on his Birthday. She has already created a message — string *s* of length *n*, consisting of uppercase and lowercase English letters. Tanya can't write yet, so she f... | ```python
r=input()
h=input()
r_dic = {}
h_dic = {}
for c in r:
h_dic[c] = 0
if c in r_dic:
r_dic[c]+=1
else:
r_dic[c]=1
for c in h:
if c in h_dic:
h_dic[c]+=1
else:
h_dic[c]=1
y = 0
o = 0
for k,v in r_dic.items():
if r_dic[k]>h_dic[k]:... | 0 | |
763 | A | Timofey and a tree | PROGRAMMING | 1,600 | [
"dfs and similar",
"dp",
"dsu",
"graphs",
"implementation",
"trees"
] | null | null | Each New Year Timofey and his friends cut down a tree of *n* vertices and bring it home. After that they paint all the *n* its vertices, so that the *i*-th vertex gets color *c**i*.
Now it's time for Timofey birthday, and his mother asked him to remove the tree. Timofey removes the tree in the following way: he takes ... | The first line contains single integer *n* (2<=≤<=*n*<=≤<=105) — the number of vertices in the tree.
Each of the next *n*<=-<=1 lines contains two integers *u* and *v* (1<=≤<=*u*,<=*v*<=≤<=*n*, *u*<=≠<=*v*), denoting there is an edge between vertices *u* and *v*. It is guaranteed that the given graph is a tree.
The n... | Print "NO" in a single line, if Timofey can't take the tree in such a way that it doesn't annoy him.
Otherwise print "YES" in the first line. In the second line print the index of the vertex which Timofey should take in hands. If there are multiple answers, print any of them. | [
"4\n1 2\n2 3\n3 4\n1 2 1 1\n",
"3\n1 2\n2 3\n1 2 3\n",
"4\n1 2\n2 3\n3 4\n1 2 1 2\n"
] | [
"YES\n2",
"YES\n2",
"NO"
] | none | 500 | [
{
"input": "4\n1 2\n2 3\n3 4\n1 2 1 1",
"output": "YES\n2"
},
{
"input": "3\n1 2\n2 3\n1 2 3",
"output": "YES\n2"
},
{
"input": "4\n1 2\n2 3\n3 4\n1 2 1 2",
"output": "NO"
},
{
"input": "3\n2 1\n2 3\n1 2 3",
"output": "YES\n2"
},
{
"input": "4\n1 2\n2 4\n4 3\n1 1 ... | 1,600,176,677 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 5 | 139 | 0 | n=int(input())
count=[0]*(n+1)
arr=[]
for i in range(n-1):
u,v=map(int,input().split())
arr.append([u,v])
c=list(map(int,input().split()))
countd=0
for i,(u,v) in enumerate(arr):
if c[u-1]!=c[v-1]:
countd+=1
count[u]+=1
count[v]+=1
maxi=0
index=-1
for i in range(... | Title: Timofey and a tree
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Each New Year Timofey and his friends cut down a tree of *n* vertices and bring it home. After that they paint all the *n* its vertices, so that the *i*-th vertex gets color *c**i*.
Now it's time for Timofey birthda... | ```python
n=int(input())
count=[0]*(n+1)
arr=[]
for i in range(n-1):
u,v=map(int,input().split())
arr.append([u,v])
c=list(map(int,input().split()))
countd=0
for i,(u,v) in enumerate(arr):
if c[u-1]!=c[v-1]:
countd+=1
count[u]+=1
count[v]+=1
maxi=0
index=-1
for i... | 0 | |
680 | B | Bear and Finding Criminals | PROGRAMMING | 1,000 | [
"constructive algorithms",
"implementation"
] | null | null | There are *n* cities in Bearland, numbered 1 through *n*. Cities are arranged in one long row. The distance between cities *i* and *j* is equal to |*i*<=-<=*j*|.
Limak is a police officer. He lives in a city *a*. His job is to catch criminals. It's hard because he doesn't know in which cities criminals are. Though, he... | The first line of the input contains two integers *n* and *a* (1<=≤<=*a*<=≤<=*n*<=≤<=100) — the number of cities and the index of city where Limak lives.
The second line contains *n* integers *t*1,<=*t*2,<=...,<=*t**n* (0<=≤<=*t**i*<=≤<=1). There are *t**i* criminals in the *i*-th city. | Print the number of criminals Limak will catch. | [
"6 3\n1 1 1 0 1 0\n",
"5 2\n0 0 0 1 0\n"
] | [
"3\n",
"1\n"
] | In the first sample, there are six cities and Limak lives in the third one (blue arrow below). Criminals are in cities marked red.
Using the BCD gives Limak the following information:
- There is one criminal at distance 0 from the third city — Limak is sure that this criminal is exactly in the third city. - There i... | 1,000 | [
{
"input": "6 3\n1 1 1 0 1 0",
"output": "3"
},
{
"input": "5 2\n0 0 0 1 0",
"output": "1"
},
{
"input": "1 1\n1",
"output": "1"
},
{
"input": "1 1\n0",
"output": "0"
},
{
"input": "9 3\n1 1 1 1 1 1 1 1 0",
"output": "8"
},
{
"input": "9 5\n1 0 1 0 1 0... | 1,669,256,819 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 4 | 46 | 0 | (n, a) = map(int, input().split())
lis = list(map(int, input().split()))
criminal = 0
for i in range(n - (a - 1)):
l, r = 0, 0
if (a - 1) - i >= 0:
l = lis[ (a-1) - i ]
try:
r = lis[ (a-1) + i ]
except:
pass
if l or r :
criminal += 1
pri... | Title: Bear and Finding Criminals
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* cities in Bearland, numbered 1 through *n*. Cities are arranged in one long row. The distance between cities *i* and *j* is equal to |*i*<=-<=*j*|.
Limak is a police officer. He lives in a city... | ```python
(n, a) = map(int, input().split())
lis = list(map(int, input().split()))
criminal = 0
for i in range(n - (a - 1)):
l, r = 0, 0
if (a - 1) - i >= 0:
l = lis[ (a-1) - i ]
try:
r = lis[ (a-1) + i ]
except:
pass
if l or r :
criminal +... | 0 | |
496 | B | Secret Combination | PROGRAMMING | 1,500 | [
"brute force",
"constructive algorithms",
"implementation"
] | null | null | You got a box with a combination lock. The lock has a display showing *n* digits. There are two buttons on the box, each button changes digits on the display. You have quickly discovered that the first button adds 1 to all the digits (all digits 9 become digits 0), and the second button shifts all the digits on the dis... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of digits on the display.
The second line contains *n* digits — the initial state of the display. | Print a single line containing *n* digits — the desired state of the display containing the smallest possible number. | [
"3\n579\n",
"4\n2014\n"
] | [
"024\n",
"0142\n"
] | none | 1,000 | [
{
"input": "3\n579",
"output": "024"
},
{
"input": "4\n2014",
"output": "0142"
},
{
"input": "1\n1",
"output": "0"
},
{
"input": "3\n039",
"output": "014"
},
{
"input": "4\n4444",
"output": "0000"
},
{
"input": "5\n46802",
"output": "02468"
},
... | 1,580,484,567 | 2,147,483,647 | PyPy 3 | OK | TESTS | 28 | 296 | 6,041,600 | from collections import *
def flip(x, mi):
return str((x + mi) % 10)
def solve():
ans = ''.join(s)
for i in range(n):
mi = (10 - int(s[1])) % 10
for j in range(n):
s[j] = flip(int(s[j]), mi)
# print(''.join(s))
s.rotate(-1)
ans = min(ans... | Title: Secret Combination
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You got a box with a combination lock. The lock has a display showing *n* digits. There are two buttons on the box, each button changes digits on the display. You have quickly discovered that the first button adds 1 ... | ```python
from collections import *
def flip(x, mi):
return str((x + mi) % 10)
def solve():
ans = ''.join(s)
for i in range(n):
mi = (10 - int(s[1])) % 10
for j in range(n):
s[j] = flip(int(s[j]), mi)
# print(''.join(s))
s.rotate(-1)
ans... | 3 | |
0 | none | none | none | 0 | [
"none"
] | null | null | Fox Ciel has *n* boxes in her room. They have the same size and weight, but they might have different strength. The *i*-th box can hold at most *x**i* boxes on its top (we'll call *x**i* the strength of the box).
Since all the boxes have the same size, Ciel cannot put more than one box directly on the top of some box... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=100). The next line contains *n* integers *x*1,<=*x*2,<=...,<=*x**n* (0<=≤<=*x**i*<=≤<=100). | Output a single integer — the minimal possible number of piles. | [
"3\n0 0 10\n",
"5\n0 1 2 3 4\n",
"4\n0 0 0 0\n",
"9\n0 1 0 2 0 1 1 2 10\n"
] | [
"2\n",
"1\n",
"4\n",
"3\n"
] | In example 1, one optimal way is to build 2 piles: the first pile contains boxes 1 and 3 (from top to bottom), the second pile contains only box 2.
In example 2, we can build only 1 pile that contains boxes 1, 2, 3, 4, 5 (from top to bottom). | 0 | [
{
"input": "3\n0 0 10",
"output": "2"
},
{
"input": "5\n0 1 2 3 4",
"output": "1"
},
{
"input": "4\n0 0 0 0",
"output": "4"
},
{
"input": "9\n0 1 0 2 0 1 1 2 10",
"output": "3"
},
{
"input": "1\n0",
"output": "1"
},
{
"input": "2\n0 0",
"output": "... | 1,417,074,712 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 20 | 77 | 0 | n=int(input())
listn=list(map(int, input().split()))
currLimit=n-1
listn=sorted(listn, reverse=True)
i=0
res=0
zero=0
for k in listn:
if k==0:
zero+=1
while i<n:
if listn[i]==0:
i+=1
continue
tmp=i+listn[i]
currLimit=min(currLimit, tmp)
if i==currLimit:
currLim... | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Fox Ciel has *n* boxes in her room. They have the same size and weight, but they might have different strength. The *i*-th box can hold at most *x**i* boxes on its top (we'll call *x**i* the strength of the box).
Since all the b... | ```python
n=int(input())
listn=list(map(int, input().split()))
currLimit=n-1
listn=sorted(listn, reverse=True)
i=0
res=0
zero=0
for k in listn:
if k==0:
zero+=1
while i<n:
if listn[i]==0:
i+=1
continue
tmp=i+listn[i]
currLimit=min(currLimit, tmp)
if i==currLimit:
... | 0 | |
707 | B | Bakery | PROGRAMMING | 1,300 | [
"graphs"
] | null | null | Masha wants to open her own bakery and bake muffins in one of the *n* cities numbered from 1 to *n*. There are *m* bidirectional roads, each of whose connects some pair of cities.
To bake muffins in her bakery, Masha needs to establish flour supply from some storage. There are only *k* storages, located in different c... | The first line of the input contains three integers *n*, *m* and *k* (1<=≤<=*n*,<=*m*<=≤<=105, 0<=≤<=*k*<=≤<=*n*) — the number of cities in country Masha lives in, the number of roads between them and the number of flour storages respectively.
Then *m* lines follow. Each of them contains three integers *u*, *v* and *l... | Print the minimum possible amount of rubles Masha should pay for flour delivery in the only line.
If the bakery can not be opened (while satisfying conditions) in any of the *n* cities, print <=-<=1 in the only line. | [
"5 4 2\n1 2 5\n1 2 3\n2 3 4\n1 4 10\n1 5\n",
"3 1 1\n1 2 3\n3\n"
] | [
"3",
"-1"
] | Image illustrates the first sample case. Cities with storage located in and the road representing the answer are darkened. | 1,000 | [
{
"input": "5 4 2\n1 2 5\n1 2 3\n2 3 4\n1 4 10\n1 5",
"output": "3"
},
{
"input": "3 1 1\n1 2 3\n3",
"output": "-1"
},
{
"input": "2 3 1\n1 2 3\n1 2 18\n1 2 13\n2",
"output": "3"
},
{
"input": "3 7 0\n1 3 9\n1 2 5\n1 2 21\n1 2 12\n1 2 13\n2 3 19\n2 3 8",
"output": "-1"
... | 1,693,131,373 | 2,147,483,647 | PyPy 3-64 | TIME_LIMIT_EXCEEDED | TESTS | 40 | 2,000 | 17,408,000 | n, m, k = map(int, input().split())
Graph = []
Muka = []
for i in range(m):
u, v, l = map(int, input().split())
Graph.append([u, v, l])
if k > 0:
Muka = list(map(int, input().split()))
cheap = 6000000000
cheap_town = 1
for i in range(len(Graph)):
if Graph[i][0] in Muka and G... | Title: Bakery
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Masha wants to open her own bakery and bake muffins in one of the *n* cities numbered from 1 to *n*. There are *m* bidirectional roads, each of whose connects some pair of cities.
To bake muffins in her bakery, Masha needs to e... | ```python
n, m, k = map(int, input().split())
Graph = []
Muka = []
for i in range(m):
u, v, l = map(int, input().split())
Graph.append([u, v, l])
if k > 0:
Muka = list(map(int, input().split()))
cheap = 6000000000
cheap_town = 1
for i in range(len(Graph)):
if Graph[i][0] in ... | 0 | |
4 | A | Watermelon | PROGRAMMING | 800 | [
"brute force",
"math"
] | A. Watermelon | 1 | 64 | One hot summer day Pete and his friend Billy decided to buy a watermelon. They chose the biggest and the ripest one, in their opinion. After that the watermelon was weighed, and the scales showed *w* kilos. They rushed home, dying of thirst, and decided to divide the berry, however they faced a hard problem.
Pete and ... | The first (and the only) input line contains integer number *w* (1<=≤<=*w*<=≤<=100) — the weight of the watermelon bought by the boys. | Print YES, if the boys can divide the watermelon into two parts, each of them weighing even number of kilos; and NO in the opposite case. | [
"8\n"
] | [
"YES\n"
] | For example, the boys can divide the watermelon into two parts of 2 and 6 kilos respectively (another variant — two parts of 4 and 4 kilos). | 0 | [
{
"input": "8",
"output": "YES"
},
{
"input": "5",
"output": "NO"
},
{
"input": "4",
"output": "YES"
},
{
"input": "3",
"output": "NO"
},
{
"input": "2",
"output": "NO"
},
{
"input": "1",
"output": "NO"
},
{
"input": "7",
"output": "NO"... | 1,689,777,227 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 0 | 124 | 0 | def sol():
w = int(input())
return 'YESY' if w == (w // 2) * 2 else 'NO'
if __name__ == "__main__":
sol() | Title: Watermelon
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
One hot summer day Pete and his friend Billy decided to buy a watermelon. They chose the biggest and the ripest one, in their opinion. After that the watermelon was weighed, and the scales showed *w* kilos. They rushed home, dyin... | ```python
def sol():
w = int(input())
return 'YESY' if w == (w // 2) * 2 else 'NO'
if __name__ == "__main__":
sol()
``` | 0 |
203 | A | Two Problems | PROGRAMMING | 1,200 | [
"brute force",
"implementation"
] | null | null | A boy Valera registered on site Codeforces as Valera, and wrote his first Codeforces Round #300. He boasted to a friend Arkady about winning as much as *x* points for his first contest. But Arkady did not believe his friend's words and decided to check whether Valera could have shown such a result.
He knows that the c... | The single line of the input contains six integers *x*,<=*t*,<=*a*,<=*b*,<=*d**a*,<=*d**b* (0<=≤<=*x*<=≤<=600; 1<=≤<=*t*,<=*a*,<=*b*,<=*d**a*,<=*d**b*<=≤<=300) — Valera's result, the contest's duration, the initial cost of the first problem, the initial cost of the second problem, the number of points that the first an... | If Valera could have earned exactly *x* points at a contest, print "YES", otherwise print "NO" (without the quotes). | [
"30 5 20 20 3 5\n",
"10 4 100 5 5 1\n"
] | [
"YES\n",
"NO\n"
] | In the first sample Valera could have acted like this: he could have submitted the first problem at minute 0 and the second problem — at minute 2. Then the first problem brings him 20 points and the second problem brings him 10 points, that in total gives the required 30 points. | 500 | [
{
"input": "30 5 20 20 3 5",
"output": "YES"
},
{
"input": "10 4 100 5 5 1",
"output": "NO"
},
{
"input": "0 7 30 50 3 4",
"output": "YES"
},
{
"input": "50 10 30 20 1 2",
"output": "YES"
},
{
"input": "40 1 40 5 11 2",
"output": "YES"
},
{
"input": "3... | 1,455,928,244 | 2,147,483,647 | Python 3 | OK | TESTS | 51 | 124 | 0 | def main():
x, t, a, b, da, db = map(int, input().split())
db *= -1
tdb = t * db
s = {z for y in range(a + b, a + b - da * t, -da) for z in range(y, y + tdb, db)}
s.update(range(a, a - da * t, -da))
s.update(range(b, b + tdb, db))
s.add(0)
print(("NO", "YES")[x in s])
if __name__ == '__... | Title: Two Problems
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A boy Valera registered on site Codeforces as Valera, and wrote his first Codeforces Round #300. He boasted to a friend Arkady about winning as much as *x* points for his first contest. But Arkady did not believe his frien... | ```python
def main():
x, t, a, b, da, db = map(int, input().split())
db *= -1
tdb = t * db
s = {z for y in range(a + b, a + b - da * t, -da) for z in range(y, y + tdb, db)}
s.update(range(a, a - da * t, -da))
s.update(range(b, b + tdb, db))
s.add(0)
print(("NO", "YES")[x in s])
if __nam... | 3 | |
849 | A | Odds and Ends | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Where do odds begin, and where do they end? Where does hope emerge, and will they ever break?
Given an integer sequence *a*1,<=*a*2,<=...,<=*a**n* of length *n*. Decide whether it is possible to divide it into an odd number of non-empty subsegments, the each of which has an odd length and begins and ends with odd numb... | The first line of input contains a non-negative integer *n* (1<=≤<=*n*<=≤<=100) — the length of the sequence.
The second line contains *n* space-separated non-negative integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=100) — the elements of the sequence. | Output "Yes" if it's possible to fulfill the requirements, and "No" otherwise.
You can output each letter in any case (upper or lower). | [
"3\n1 3 5\n",
"5\n1 0 1 5 1\n",
"3\n4 3 1\n",
"4\n3 9 9 3\n"
] | [
"Yes\n",
"Yes\n",
"No\n",
"No\n"
] | In the first example, divide the sequence into 1 subsegment: {1, 3, 5} and the requirements will be met.
In the second example, divide the sequence into 3 subsegments: {1, 0, 1}, {5}, {1}.
In the third example, one of the subsegments must start with 4 which is an even number, thus the requirements cannot be met.
In ... | 500 | [
{
"input": "3\n1 3 5",
"output": "Yes"
},
{
"input": "5\n1 0 1 5 1",
"output": "Yes"
},
{
"input": "3\n4 3 1",
"output": "No"
},
{
"input": "4\n3 9 9 3",
"output": "No"
},
{
"input": "1\n1",
"output": "Yes"
},
{
"input": "5\n100 99 100 99 99",
"out... | 1,534,847,522 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | #include<bits/stdc++.h>
using namespace std;
int n, a[105], dp[105][105];
bool cek(int awal, int sum) {
// cout << awal << " " << sum << endl;
if (awal == n && sum % 2 == 1) {
return true;
}
if (awal == n) return false;
if (dp[awal][sum] != -1) return dp[awal][sum];
int len ... | Title: Odds and Ends
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Where do odds begin, and where do they end? Where does hope emerge, and will they ever break?
Given an integer sequence *a*1,<=*a*2,<=...,<=*a**n* of length *n*. Decide whether it is possible to divide it into an odd num... | ```python
#include<bits/stdc++.h>
using namespace std;
int n, a[105], dp[105][105];
bool cek(int awal, int sum) {
// cout << awal << " " << sum << endl;
if (awal == n && sum % 2 == 1) {
return true;
}
if (awal == n) return false;
if (dp[awal][sum] != -1) return dp[awal][sum];
... | -1 | |
358 | A | Dima and Continuous Line | PROGRAMMING | 1,400 | [
"brute force",
"implementation"
] | null | null | Dima and Seryozha live in an ordinary dormitory room for two. One day Dima had a date with his girl and he asked Seryozha to leave the room. As a compensation, Seryozha made Dima do his homework.
The teacher gave Seryozha the coordinates of *n* distinct points on the abscissa axis and asked to consecutively connect th... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=103). The second line contains *n* distinct integers *x*1,<=*x*2,<=...,<=*x**n* (<=-<=106<=≤<=*x**i*<=≤<=106) — the *i*-th point has coordinates (*x**i*,<=0). The points are not necessarily sorted by their *x* coordinate. | In the single line print "yes" (without the quotes), if the line has self-intersections. Otherwise, print "no" (without the quotes). | [
"4\n0 10 5 15\n",
"4\n0 15 5 10\n"
] | [
"yes\n",
"no\n"
] | The first test from the statement is on the picture to the left, the second test is on the picture to the right. | 500 | [
{
"input": "4\n0 10 5 15",
"output": "yes"
},
{
"input": "4\n0 15 5 10",
"output": "no"
},
{
"input": "5\n0 1000 2000 3000 1500",
"output": "yes"
},
{
"input": "5\n-724093 710736 -383722 -359011 439613",
"output": "no"
},
{
"input": "50\n384672 661179 -775591 -989... | 1,571,684,280 | 2,147,483,647 | Python 3 | OK | TESTS | 37 | 389 | 409,600 | import sys
import itertools
import math
import collections
from collections import Counter
#########################
# imgur.com/Pkt7iIf.png #
#########################
def sieve(n):
prime = [True for i in range(n + 1)]
p = 2
while (p * p <= n):
if (prime[p] == True):
fo... | Title: Dima and Continuous Line
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Dima and Seryozha live in an ordinary dormitory room for two. One day Dima had a date with his girl and he asked Seryozha to leave the room. As a compensation, Seryozha made Dima do his homework.
The teacher g... | ```python
import sys
import itertools
import math
import collections
from collections import Counter
#########################
# imgur.com/Pkt7iIf.png #
#########################
def sieve(n):
prime = [True for i in range(n + 1)]
p = 2
while (p * p <= n):
if (prime[p] == True):
... | 3 | |
884 | C | Bertown Subway | PROGRAMMING | 1,500 | [
"dfs and similar",
"greedy",
"math"
] | null | null | The construction of subway in Bertown is almost finished! The President of Berland will visit this city soon to look at the new subway himself.
There are *n* stations in the subway. It was built according to the Bertown Transport Law:
1. For each station *i* there exists exactly one train that goes from this station... | The first line contains one integer number *n* (1<=≤<=*n*<=≤<=100000) — the number of stations.
The second line contains *n* integer numbers *p*1, *p*2, ..., *p**n* (1<=≤<=*p**i*<=≤<=*n*) — the current structure of the subway. All these numbers are distinct. | Print one number — the maximum possible value of convenience. | [
"3\n2 1 3\n",
"5\n1 5 4 3 2\n"
] | [
"9\n",
"17\n"
] | In the first example the mayor can change *p*<sub class="lower-index">2</sub> to 3 and *p*<sub class="lower-index">3</sub> to 1, so there will be 9 pairs: (1, 1), (1, 2), (1, 3), (2, 1), (2, 2), (2, 3), (3, 1), (3, 2), (3, 3).
In the second example the mayor can change *p*<sub class="lower-index">2</sub> to 4 and *p*<... | 0 | [
{
"input": "3\n2 1 3",
"output": "9"
},
{
"input": "5\n1 5 4 3 2",
"output": "17"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "2\n1 2",
"output": "4"
},
{
"input": "2\n2 1",
"output": "4"
},
{
"input": "100\n98 52 63 2 18 96 31 58 84 40 41 45 66 ... | 1,509,224,897 | 2,147,483,647 | Python 3 | OK | TESTS | 27 | 171 | 7,372,800 | # http://codeforces.com/contest/884/problem/C
# unsolved
from functools import lru_cache
n = int(input())
p = list(map(int, input().split()))
l = []
score = 0
jeden = 0
dwa = 0
@lru_cache(maxsize=10000)
def wzor(s):
return s * s
for i in range(n):
if p[i] != 0:
start = i
... | Title: Bertown Subway
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The construction of subway in Bertown is almost finished! The President of Berland will visit this city soon to look at the new subway himself.
There are *n* stations in the subway. It was built according to the Bertown... | ```python
# http://codeforces.com/contest/884/problem/C
# unsolved
from functools import lru_cache
n = int(input())
p = list(map(int, input().split()))
l = []
score = 0
jeden = 0
dwa = 0
@lru_cache(maxsize=10000)
def wzor(s):
return s * s
for i in range(n):
if p[i] != 0:
star... | 3 | |
2 | B | The least round way | PROGRAMMING | 2,000 | [
"dp",
"math"
] | B. The least round way | 2 | 64 | There is a square matrix *n*<=×<=*n*, consisting of non-negative integer numbers. You should find such a way on it that
- starts in the upper left cell of the matrix; - each following cell is to the right or down from the current cell; - the way ends in the bottom right cell.
Moreover, if we multiply together all... | The first line contains an integer number *n* (2<=≤<=*n*<=≤<=1000), *n* is the size of the matrix. Then follow *n* lines containing the matrix elements (non-negative integer numbers not exceeding 109). | In the first line print the least number of trailing zeros. In the second line print the correspondent way itself. | [
"3\n1 2 3\n4 5 6\n7 8 9\n"
] | [
"0\nDDRR\n"
] | none | 0 | [
{
"input": "3\n1 2 3\n4 5 6\n7 8 9",
"output": "0\nDDRR"
},
{
"input": "2\n7 6\n3 8",
"output": "0\nDR"
},
{
"input": "3\n4 10 5\n10 9 4\n6 5 3",
"output": "1\nDRRD"
},
{
"input": "4\n1 1 9 9\n3 4 7 3\n7 9 1 7\n1 7 1 5",
"output": "0\nDDDRRR"
},
{
"input": "5\n8 3... | 1,692,477,483 | 4,083 | PyPy 3-64 | WRONG_ANSWER | TESTS | 2 | 46 | 0 | def get_best_path(mat, coord, paths):
if paths[coord] != 0:
return paths[coord]
r_zeros = -1
d_zeros = -1
if coord[1] < n-1:
r_path = get_best_path(mat,(coord[0],coord[1]+1),paths)
r_prod = mat[coord[0]][coord[1]] * r_path[0]
if r_prod%10 != 0:
i=0
els... | Title: The least round way
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
There is a square matrix *n*<=×<=*n*, consisting of non-negative integer numbers. You should find such a way on it that
- starts in the upper left cell of the matrix; - each following cell is to the right or down fro... | ```python
def get_best_path(mat, coord, paths):
if paths[coord] != 0:
return paths[coord]
r_zeros = -1
d_zeros = -1
if coord[1] < n-1:
r_path = get_best_path(mat,(coord[0],coord[1]+1),paths)
r_prod = mat[coord[0]][coord[1]] * r_path[0]
if r_prod%10 != 0:
i=0
... | 0 |
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.