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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
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,620,807,713 | 2,147,483,647 | Python 3 | OK | TESTS | 85 | 1,325 | 23,142,400 | n=eval(input())
a=input()
b=list(map(eval,input().split()))
d=[]
for i in range(n-1):
if a[i]=='R' and a[i+1]=='L':
d.append(b[i+1]-b[i])
if len(d)!=0:
print(int(min(d)/2))
else:
print(-1)
| 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
n=eval(input())
a=input()
b=list(map(eval,input().split()))
d=[]
for i in range(n-1):
if a[i]=='R' and a[i+1]=='L':
d.append(b[i+1]-b[i])
if len(d)!=0:
print(int(min(d)/2))
else:
print(-1)
``` | 3 | |
483 | A | Counterexample | PROGRAMMING | 1,100 | [
"brute force",
"implementation",
"math",
"number theory"
] | null | null | Your friend has recently learned about coprime numbers. A pair of numbers {*a*,<=*b*} is called coprime if the maximum number that divides both *a* and *b* is equal to one.
Your friend often comes up with different statements. He has recently supposed that if the pair (*a*,<=*b*) is coprime and the pair (*b*,<=*c*) i... | The single line contains two positive space-separated integers *l*, *r* (1<=≤<=*l*<=≤<=*r*<=≤<=1018; *r*<=-<=*l*<=≤<=50). | Print three positive space-separated integers *a*, *b*, *c* — three distinct numbers (*a*,<=*b*,<=*c*) that form the counterexample. If there are several solutions, you are allowed to print any of them. The numbers must be printed in ascending order.
If the counterexample does not exist, print the single number -1. | [
"2 4\n",
"10 11\n",
"900000000000000009 900000000000000029\n"
] | [
"2 3 4\n",
"-1\n",
"900000000000000009 900000000000000010 900000000000000021\n"
] | In the first sample pair (2, 4) is not coprime and pairs (2, 3) and (3, 4) are.
In the second sample you cannot form a group of three distinct integers, so the answer is -1.
In the third sample it is easy to see that numbers 900000000000000009 and 900000000000000021 are divisible by three. | 500 | [
{
"input": "2 4",
"output": "2 3 4"
},
{
"input": "10 11",
"output": "-1"
},
{
"input": "900000000000000009 900000000000000029",
"output": "900000000000000009 900000000000000010 900000000000000021"
},
{
"input": "640097987171091791 640097987171091835",
"output": "64009798... | 1,585,762,986 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 1 | 124 | 0 | l,r = map(int,input().split())
a = l
while not(a%2 == 0):
a += 1
b = a + 1
c = a + 2
print(a,b,c) | Title: Counterexample
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Your friend has recently learned about coprime numbers. A pair of numbers {*a*,<=*b*} is called coprime if the maximum number that divides both *a* and *b* is equal to one.
Your friend often comes up with different st... | ```python
l,r = map(int,input().split())
a = l
while not(a%2 == 0):
a += 1
b = a + 1
c = a + 2
print(a,b,c)
``` | 0 | |
186 | A | Comparing Strings | PROGRAMMING | 1,100 | [
"implementation",
"strings"
] | null | null | Some dwarves that are finishing the StUDY (State University for Dwarven Youngsters) Bachelor courses, have been told "no genome, no degree". That means that all dwarves should write a thesis on genome. Dwarven genome is far from simple. It is represented by a string that consists of lowercase Latin letters.
Dwarf Mish... | The first line contains the first dwarf's genome: a non-empty string, consisting of lowercase Latin letters.
The second line contains the second dwarf's genome: a non-empty string, consisting of lowercase Latin letters.
The number of letters in each genome doesn't exceed 105. It is guaranteed that the strings that co... | Print "YES", if the dwarves belong to the same race. Otherwise, print "NO". | [
"ab\nba\n",
"aa\nab\n"
] | [
"YES\n",
"NO\n"
] | - First example: you can simply swap two letters in string "ab". So we get "ba". - Second example: we can't change string "aa" into string "ab", because "aa" does not contain letter "b". | 500 | [
{
"input": "ab\nba",
"output": "YES"
},
{
"input": "aa\nab",
"output": "NO"
},
{
"input": "a\nza",
"output": "NO"
},
{
"input": "vvea\nvvae",
"output": "YES"
},
{
"input": "rtfabanpc\natfabrnpc",
"output": "YES"
},
{
"input": "mt\ntm",
"output": "Y... | 1,616,150,520 | 2,147,483,647 | PyPy 3 | OK | TESTS | 53 | 218 | 10,035,200 | genome1=list(input())
genome2=list(input())
indexs=[]
flag=0
for i in range(min(len(genome2),len(genome1))):
if genome1[i]!=genome2[i] :
indexs.append(i)
if len(indexs)<=1 or len(indexs)>2:
print('NO')
exit()
genome1[indexs[0]],genome1[indexs[1]]=genome1[indexs[1]],genome1[indexs[0]]
if g... | Title: Comparing Strings
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Some dwarves that are finishing the StUDY (State University for Dwarven Youngsters) Bachelor courses, have been told "no genome, no degree". That means that all dwarves should write a thesis on genome. Dwarven genome ... | ```python
genome1=list(input())
genome2=list(input())
indexs=[]
flag=0
for i in range(min(len(genome2),len(genome1))):
if genome1[i]!=genome2[i] :
indexs.append(i)
if len(indexs)<=1 or len(indexs)>2:
print('NO')
exit()
genome1[indexs[0]],genome1[indexs[1]]=genome1[indexs[1]],genome1[indexs... | 3 | |
376 | B | I.O.U. | PROGRAMMING | 1,300 | [
"implementation"
] | null | null | Imagine that there is a group of three friends: A, B and С. A owes B 20 rubles and B owes C 20 rubles. The total sum of the debts is 40 rubles. You can see that the debts are not organized in a very optimal manner. Let's rearrange them like that: assume that A owes C 20 rubles and B doesn't owe anything to anybody. The... | The first line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=100; 0<=≤<=*m*<=≤<=104). The next *m* lines contain the debts. The *i*-th line contains three integers *a**i*,<=*b**i*,<=*c**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*; *a**i*<=≠<=*b**i*; 1<=≤<=*c**i*<=≤<=100), which mean that person *a**i* owes person *b**i* *c**i... | Print a single integer — the minimum sum of debts in the optimal rearrangement. | [
"5 3\n1 2 10\n2 3 1\n2 4 1\n",
"3 0\n",
"4 3\n1 2 1\n2 3 1\n3 1 1\n"
] | [
"10\n",
"0\n",
"0\n"
] | In the first sample, you can assume that person number 1 owes 8 rubles to person number 2, 1 ruble to person number 3 and 1 ruble to person number 4. He doesn't owe anybody else anything. In the end, the total debt equals 10.
In the second sample, there are no debts.
In the third sample, you can annul all the debts. | 1,000 | [
{
"input": "5 3\n1 2 10\n2 3 1\n2 4 1",
"output": "10"
},
{
"input": "3 0",
"output": "0"
},
{
"input": "4 3\n1 2 1\n2 3 1\n3 1 1",
"output": "0"
},
{
"input": "20 28\n1 5 6\n1 12 7\n1 13 4\n1 15 7\n1 20 3\n2 4 1\n2 15 6\n3 5 3\n3 8 10\n3 13 8\n3 20 6\n4 6 10\n4 12 8\n4 19 5\... | 1,615,792,733 | 2,147,483,647 | Python 3 | OK | TESTS | 29 | 62 | 0 | n, m = map(int, input().split())
d = [0 for i in range(n)]
for i in range(m):
a, b, c = map(int, input().split())
d[a-1] -= c
d[b-1] += c
print(sum(i for i in d if i > 0)) | Title: I.O.U.
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Imagine that there is a group of three friends: A, B and С. A owes B 20 rubles and B owes C 20 rubles. The total sum of the debts is 40 rubles. You can see that the debts are not organized in a very optimal manner. Let's rearran... | ```python
n, m = map(int, input().split())
d = [0 for i in range(n)]
for i in range(m):
a, b, c = map(int, input().split())
d[a-1] -= c
d[b-1] += c
print(sum(i for i in d if i > 0))
``` | 3 | |
155 | A | I_love_\%username\% | PROGRAMMING | 800 | [
"brute force"
] | null | null | Vasya adores sport programming. He can't write programs but he loves to watch the contests' progress. Vasya even has a favorite coder and Vasya pays special attention to him.
One day Vasya decided to collect the results of all contests where his favorite coder participated and track the progress of his coolness. For e... | The first line contains the single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of contests where the coder participated.
The next line contains *n* space-separated non-negative integer numbers — they are the points which the coder has earned. The points are given in the chronological order. All points do not exceed ... | Print the single number — the number of amazing performances the coder has had during his whole history of participating in the contests. | [
"5\n100 50 200 150 200\n",
"10\n4664 6496 5814 7010 5762 5736 6944 4850 3698 7242\n"
] | [
"2\n",
"4\n"
] | In the first sample the performances number 2 and 3 are amazing.
In the second sample the performances number 2, 4, 9 and 10 are amazing. | 500 | [
{
"input": "5\n100 50 200 150 200",
"output": "2"
},
{
"input": "10\n4664 6496 5814 7010 5762 5736 6944 4850 3698 7242",
"output": "4"
},
{
"input": "1\n6",
"output": "0"
},
{
"input": "2\n2 1",
"output": "1"
},
{
"input": "5\n100 36 53 7 81",
"output": "2"
... | 1,697,371,207 | 2,147,483,647 | Python 3 | OK | TESTS | 37 | 92 | 0 | n = int(input())
a = list(map(int, input().split()))
l = a[0]
b = a[0]
c = 0
for i in range(1,n):
if(a[i] > b):
c = c + 1
b = a[i]
if(a[i] < l):
c = c + 1
l = a[i]
print(c) | Title: I_love_\%username\%
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya adores sport programming. He can't write programs but he loves to watch the contests' progress. Vasya even has a favorite coder and Vasya pays special attention to him.
One day Vasya decided to collect the re... | ```python
n = int(input())
a = list(map(int, input().split()))
l = a[0]
b = a[0]
c = 0
for i in range(1,n):
if(a[i] > b):
c = c + 1
b = a[i]
if(a[i] < l):
c = c + 1
l = a[i]
print(c)
``` | 3 | |
228 | A | Is your horseshoe on the other hoof? | PROGRAMMING | 800 | [
"implementation"
] | null | null | Valera the Horse is going to the party with friends. He has been following the fashion trends for a while, and he knows that it is very popular to wear all horseshoes of different color. Valera has got four horseshoes left from the last year, but maybe some of them have the same color. In this case he needs to go to th... | The first line contains four space-separated integers *s*1,<=*s*2,<=*s*3,<=*s*4 (1<=≤<=*s*1,<=*s*2,<=*s*3,<=*s*4<=≤<=109) — the colors of horseshoes Valera has.
Consider all possible colors indexed with integers. | Print a single integer — the minimum number of horseshoes Valera needs to buy. | [
"1 7 3 3\n",
"7 7 7 7\n"
] | [
"1\n",
"3\n"
] | none | 500 | [
{
"input": "1 7 3 3",
"output": "1"
},
{
"input": "7 7 7 7",
"output": "3"
},
{
"input": "81170865 673572653 756938629 995577259",
"output": "0"
},
{
"input": "3491663 217797045 522540872 715355328",
"output": "0"
},
{
"input": "251590420 586975278 916631563 58697... | 1,687,141,561 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 92 | 0 | a,b,c,d = map(int,input().split())
hoes = [a,b,c,d,0]
cout = 0
for i in range(len(hoes)):
if i == 4:
break
if hoes[i] == hoes[i+1]:
cout += 1
print(cout)
| Title: Is your horseshoe on the other hoof?
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Valera the Horse is going to the party with friends. He has been following the fashion trends for a while, and he knows that it is very popular to wear all horseshoes of different color. Valera has ... | ```python
a,b,c,d = map(int,input().split())
hoes = [a,b,c,d,0]
cout = 0
for i in range(len(hoes)):
if i == 4:
break
if hoes[i] == hoes[i+1]:
cout += 1
print(cout)
``` | 0 | |
714 | B | Filya and Homework | PROGRAMMING | 1,200 | [
"implementation",
"sortings"
] | null | null | Today, hedgehog Filya went to school for the very first time! Teacher gave him a homework which Filya was unable to complete without your help.
Filya is given an array of non-negative integers *a*1,<=*a*2,<=...,<=*a**n*. First, he pick an integer *x* and then he adds *x* to some elements of the array (no more than onc... | The first line of the input contains an integer *n* (1<=≤<=*n*<=≤<=100<=000) — the number of integers in the Filya's array. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=109) — elements of the array. | If it's impossible to make all elements of the array equal using the process given in the problem statement, then print "NO" (without quotes) in the only line of the output. Otherwise print "YES" (without quotes). | [
"5\n1 3 3 2 1\n",
"5\n1 2 3 4 5\n"
] | [
"YES\n",
"NO\n"
] | In the first sample Filya should select *x* = 1, then add it to the first and the last elements of the array and subtract from the second and the third elements. | 1,000 | [
{
"input": "5\n1 3 3 2 1",
"output": "YES"
},
{
"input": "5\n1 2 3 4 5",
"output": "NO"
},
{
"input": "2\n1 2",
"output": "YES"
},
{
"input": "3\n1 2 3",
"output": "YES"
},
{
"input": "3\n1 1 1",
"output": "YES"
},
{
"input": "2\n1 1000000000",
"ou... | 1,631,231,192 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 14 | 967 | 20,582,400 |
def func(hashMap, currentSum):
if currentSum not in hashMap:
hashMap[currentSum] = 1
else:
hashMap[currentSum] += 1
def balance(array, num):
hashMap = {}
for currentNum in array:
currentSum = currentNum + num
func(hashMap, currentSum)
currentSum = ... | Title: Filya and Homework
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Today, hedgehog Filya went to school for the very first time! Teacher gave him a homework which Filya was unable to complete without your help.
Filya is given an array of non-negative integers *a*1,<=*a*2,<=...,<=*a... | ```python
def func(hashMap, currentSum):
if currentSum not in hashMap:
hashMap[currentSum] = 1
else:
hashMap[currentSum] += 1
def balance(array, num):
hashMap = {}
for currentNum in array:
currentSum = currentNum + num
func(hashMap, currentSum)
cur... | 0 | |
776 | A | A Serial Killer | PROGRAMMING | 900 | [
"brute force",
"implementation",
"strings"
] | null | null | Our beloved detective, Sherlock is currently trying to catch a serial killer who kills a person each day. Using his powers of deduction, he came to know that the killer has a strategy for selecting his next victim.
The killer starts with two potential victims on his first day, selects one of these two, kills selected ... | First line of input contains two names (length of each of them doesn't exceed 10), the two initials potential victims. Next line contains integer *n* (1<=≤<=*n*<=≤<=1000), the number of days.
Next *n* lines contains two names (length of each of them doesn't exceed 10), first being the person murdered on this day and t... | Output *n*<=+<=1 lines, the *i*-th line should contain the two persons from which the killer selects for the *i*-th murder. The (*n*<=+<=1)-th line should contain the two persons from which the next victim is selected. In each line, the two names can be printed in any order. | [
"ross rachel\n4\nross joey\nrachel phoebe\nphoebe monica\nmonica chandler\n",
"icm codeforces\n1\ncodeforces technex\n"
] | [
"ross rachel\njoey rachel\njoey phoebe\njoey monica\njoey chandler\n",
"icm codeforces\nicm technex\n"
] | In first example, the killer starts with ross and rachel.
- After day 1, ross is killed and joey appears. - After day 2, rachel is killed and phoebe appears. - After day 3, phoebe is killed and monica appears. - After day 4, monica is killed and chandler appears. | 500 | [
{
"input": "ross rachel\n4\nross joey\nrachel phoebe\nphoebe monica\nmonica chandler",
"output": "ross rachel\njoey rachel\njoey phoebe\njoey monica\njoey chandler"
},
{
"input": "icm codeforces\n1\ncodeforces technex",
"output": "icm codeforces\nicm technex"
},
{
"input": "a b\n3\na c\n... | 1,673,628,791 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | names = [input()]
for _ in range(int(input())):
string = input().split()
new_names = names[-1].split()
new_names[new_names.index(string[0])] = string[1]
names.append(' '.join(new_names)
print(*names, sep='\n')
| Title: A Serial Killer
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Our beloved detective, Sherlock is currently trying to catch a serial killer who kills a person each day. Using his powers of deduction, he came to know that the killer has a strategy for selecting his next victim.
The... | ```python
names = [input()]
for _ in range(int(input())):
string = input().split()
new_names = names[-1].split()
new_names[new_names.index(string[0])] = string[1]
names.append(' '.join(new_names)
print(*names, sep='\n')
``` | -1 | |
32 | E | Hide-and-Seek | PROGRAMMING | 2,400 | [
"geometry",
"implementation"
] | E. Hide-and-Seek | 2 | 256 | Victor and Peter are playing hide-and-seek. Peter has hidden, and Victor is to find him. In the room where they are playing, there is only one non-transparent wall and one double-sided mirror. Victor and Peter are points with coordinates (*x**v*,<=*y**v*) and (*x**p*,<=*y**p*) respectively. The wall is a segment joinin... | The first line contains two numbers *x**v* and *y**v* — coordinates of Victor.
The second line contains two numbers *x**p* and *y**p* — coordinates of Peter.
The third line contains 4 numbers *x**w*,<=1, *y**w*,<=1, *x**w*,<=2, *y**w*,<=2 — coordinates of the wall.
The forth line contains 4 numbers *x**m*,<=1, *y**m... | Output YES, if Victor can see Peter without leaving the initial spot. Otherwise output NO. | [
"-1 3\n1 3\n0 2 0 4\n0 0 0 1\n",
"0 0\n1 1\n0 1 1 0\n-100 -100 -101 -101\n",
"0 0\n1 1\n0 1 1 0\n-1 1 1 3\n",
"0 0\n10 0\n100 100 101 101\n1 0 3 0\n"
] | [
"NO\n",
"NO\n",
"YES\n",
"YES\n"
] | none | 2,500 | [
{
"input": "-1 3\n1 3\n0 2 0 4\n0 0 0 1",
"output": "NO"
},
{
"input": "0 0\n1 1\n0 1 1 0\n-100 -100 -101 -101",
"output": "NO"
},
{
"input": "0 0\n1 1\n0 1 1 0\n-1 1 1 3",
"output": "YES"
},
{
"input": "0 0\n10 0\n100 100 101 101\n1 0 3 0",
"output": "YES"
},
{
"... | 1,617,739,826 | 2,147,483,647 | PyPy 3 | OK | TESTS | 80 | 186 | 0 | xv,yv=list(map(int,input().split()))
xp,yp=list(map(int,input().split()))
xw1,yw1,xw2,yw2=list(map(int,input().split()))
xm1,ym1,xm2,ym2=list(map(int,input().split()))
def a(x1,y1,x2,y2,x3,y3,x4,y4):
if x1==x2:
if x3==x4:
return False
else:
k2=(y3-y4)/(x3-x4)
... | Title: Hide-and-Seek
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Victor and Peter are playing hide-and-seek. Peter has hidden, and Victor is to find him. In the room where they are playing, there is only one non-transparent wall and one double-sided mirror. Victor and Peter are points with... | ```python
xv,yv=list(map(int,input().split()))
xp,yp=list(map(int,input().split()))
xw1,yw1,xw2,yw2=list(map(int,input().split()))
xm1,ym1,xm2,ym2=list(map(int,input().split()))
def a(x1,y1,x2,y2,x3,y3,x4,y4):
if x1==x2:
if x3==x4:
return False
else:
k2=(y3-y4)/(x3-x... | 3.9535 |
671 | A | Recycling Bottles | PROGRAMMING | 1,800 | [
"dp",
"geometry",
"greedy",
"implementation"
] | null | null | It was recycling day in Kekoland. To celebrate it Adil and Bera went to Central Perk where they can take bottles from the ground and put them into a recycling bin.
We can think Central Perk as coordinate plane. There are *n* bottles on the ground, the *i*-th bottle is located at position (*x**i*,<=*y**i*). Both Adil a... | First line of the input contains six integers *a**x*, *a**y*, *b**x*, *b**y*, *t**x* and *t**y* (0<=≤<=*a**x*,<=*a**y*,<=*b**x*,<=*b**y*,<=*t**x*,<=*t**y*<=≤<=109) — initial positions of Adil, Bera and recycling bin respectively.
The second line contains a single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the number of bo... | Print one real number — the minimum possible total distance Adil and Bera need to walk in order to put all bottles into recycling bin. 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 ... | [
"3 1 1 2 0 0\n3\n1 1\n2 1\n2 3\n",
"5 0 4 2 2 0\n5\n5 2\n3 0\n5 5\n3 5\n3 3\n"
] | [
"11.084259940083\n",
"33.121375178000\n"
] | Consider the first sample.
Adil will use the following path: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/37eea809c04afe04f2670475cc5b21df4a90afd1.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
Bera will use the following path: <img align="middle" class="tex-formula" src="https:... | 500 | [
{
"input": "3 1 1 2 0 0\n3\n1 1\n2 1\n2 3",
"output": "11.084259940083"
},
{
"input": "5 0 4 2 2 0\n5\n5 2\n3 0\n5 5\n3 5\n3 3",
"output": "33.121375178000"
},
{
"input": "107 50 116 37 104 118\n12\n16 78\n95 113\n112 84\n5 88\n54 85\n112 80\n19 98\n25 14\n48 76\n95 70\n77 94\n38 32",
... | 1,553,454,346 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 40 | 1,435 | 10,035,200 | R = lambda: map(int, input().split())
ax, ay, bx, by, tx, ty = R()
n = int(input())
dp = [[0] * (n + 1) for i in range(4)]
for i in range(n):
x, y = R()
da, db, dt = ((x - ax) ** 2 + (y - ay) ** 2) ** 0.5, ((x - bx) ** 2 + (y - by) ** 2) ** 0.5, ((x - tx) ** 2 + (y - ty) ** 2) ** 0.5
dp[0][i] = dp[0]... | Title: Recycling Bottles
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
It was recycling day in Kekoland. To celebrate it Adil and Bera went to Central Perk where they can take bottles from the ground and put them into a recycling bin.
We can think Central Perk as coordinate plane. There... | ```python
R = lambda: map(int, input().split())
ax, ay, bx, by, tx, ty = R()
n = int(input())
dp = [[0] * (n + 1) for i in range(4)]
for i in range(n):
x, y = R()
da, db, dt = ((x - ax) ** 2 + (y - ay) ** 2) ** 0.5, ((x - bx) ** 2 + (y - by) ** 2) ** 0.5, ((x - tx) ** 2 + (y - ty) ** 2) ** 0.5
dp[0][... | 0 | |
883 | A | Automatic Door | PROGRAMMING | 2,200 | [
"implementation"
] | null | null | There is an automatic door at the entrance of a factory. The door works in the following way:
- when one or several people come to the door and it is closed, the door immediately opens automatically and all people immediately come inside, - when one or several people come to the door and it is open, all people immed... | The first line contains four integers *n*, *m*, *a* and *d* (1<=≤<=*n*,<=*a*<=≤<=109, 1<=≤<=*m*<=≤<=105, 1<=≤<=*d*<=≤<=1018) — the number of the employees, the number of the clients, the moment of time when the first employee will come and the period of time in which the door closes.
The second line contains integer s... | Print the number of times the door will open. | [
"1 1 3 4\n7\n",
"4 3 4 2\n7 9 11\n"
] | [
"1\n",
"4\n"
] | In the first example the only employee will come at moment 3. At this moment the door will open and will stay open until the moment 7. At the same moment of time the client will come, so at first he will enter and only after it the door will close. Thus the door will open one time. | 0 | [
{
"input": "1 1 3 4\n7",
"output": "1"
},
{
"input": "4 3 4 2\n7 9 11",
"output": "4"
},
{
"input": "10 10 51 69\n154 170 170 183 251 337 412 426 445 452",
"output": "6"
},
{
"input": "70 10 26 17\n361 371 579 585 629 872 944 1017 1048 1541",
"output": "70"
},
{
"... | 1,509,363,462 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 10 | 1,000 | 86,220,800 | #Sol3
n, m, a, d = map(int, input().split())
lst = []
c = 1
for i in list(map(int, input().split())):
while a * c < i:
lst.append(a * c)
c += 1
lst.append(i)
while c <= n:
lst.append(c * a)
c += 1
#print(lst)
count = 1
openPoint = lst[0]
closePoint = lst[0] + d
for i in range(1, len(lst)):
i... | Title: Automatic Door
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There is an automatic door at the entrance of a factory. The door works in the following way:
- when one or several people come to the door and it is closed, the door immediately opens automatically and all people imme... | ```python
#Sol3
n, m, a, d = map(int, input().split())
lst = []
c = 1
for i in list(map(int, input().split())):
while a * c < i:
lst.append(a * c)
c += 1
lst.append(i)
while c <= n:
lst.append(c * a)
c += 1
#print(lst)
count = 1
openPoint = lst[0]
closePoint = lst[0] + d
for i in range(1, len(... | 0 | |
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,672,246,545 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 30 | 0 | import math
x,y=map(int,input().split())
if(x<=y):
for i in range(x+1):
if(x%i==0 and y%i==0):
t=i
else:
for i in range(y+1):
if(x%i==0 and y%i==0):
t=i
print(t)
| 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):
for i in range(x+1):
if(x%i==0 and y%i==0):
t=i
else:
for i in range(y+1):
if(x%i==0 and y%i==0):
t=i
print(t)
``` | -1 | |
691 | B | s-palindrome | PROGRAMMING | 1,600 | [
"implementation",
"strings"
] | null | null | Let's call a string "s-palindrome" if it is symmetric about the middle of the string. For example, the string "oHo" is "s-palindrome", but the string "aa" is not. The string "aa" is not "s-palindrome", because the second half of it is not a mirror reflection of the first half.
You are given a string *s*. Check if the ... | The only line contains the string *s* (1<=≤<=|*s*|<=≤<=1000) which consists of only English letters. | Print "TAK" if the string *s* is "s-palindrome" and "NIE" otherwise. | [
"oXoxoXo\n",
"bod\n",
"ER\n"
] | [
"TAK\n",
"TAK\n",
"NIE\n"
] | none | 0 | [
{
"input": "oXoxoXo",
"output": "TAK"
},
{
"input": "bod",
"output": "TAK"
},
{
"input": "ER",
"output": "NIE"
},
{
"input": "o",
"output": "TAK"
},
{
"input": "a",
"output": "NIE"
},
{
"input": "opo",
"output": "NIE"
},
{
"input": "HCMoxkg... | 1,471,246,844 | 1,544 | Python 3 | WRONG_ANSWER | TESTS | 10 | 61 | 4,608,000 | s=input()
l=len(s)
li=['O','o','H','V','v','X','x','W','w','M','T','I','U','Y']
if(l&1):
if s[l//2] not in li:
print("NIE")
exit()
f=0
for i in range(len(s)//2):
if(s[i]==s[l-1-i]):
if s[i] not in li:
f=1
break
else:
if(s[i]!='b' or (s[i]=='b' and s[l-1-i]!='d')):
f=1
break
if(f):
print("NIE")
e... | Title: s-palindrome
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Let's call a string "s-palindrome" if it is symmetric about the middle of the string. For example, the string "oHo" is "s-palindrome", but the string "aa" is not. The string "aa" is not "s-palindrome", because the second h... | ```python
s=input()
l=len(s)
li=['O','o','H','V','v','X','x','W','w','M','T','I','U','Y']
if(l&1):
if s[l//2] not in li:
print("NIE")
exit()
f=0
for i in range(len(s)//2):
if(s[i]==s[l-1-i]):
if s[i] not in li:
f=1
break
else:
if(s[i]!='b' or (s[i]=='b' and s[l-1-i]!='d')):
f=1
break
if(f):
prin... | 0 | |
451 | B | Sort the Array | PROGRAMMING | 1,300 | [
"implementation",
"sortings"
] | null | null | Being a programmer, you like arrays a lot. For your birthday, your friends have given you an array *a* consisting of *n* distinct integers.
Unfortunately, the size of *a* is too small. You want a bigger array! Your friends agree to give you a bigger array, but only if you are able to answer the following question corr... | The first line of the input contains an integer *n* (1<=≤<=*n*<=≤<=105) — the size of array *a*.
The second line contains *n* distinct space-separated integers: *a*[1],<=*a*[2],<=...,<=*a*[*n*] (1<=≤<=*a*[*i*]<=≤<=109). | Print "yes" or "no" (without quotes), depending on the answer.
If your answer is "yes", then also print two space-separated integers denoting start and end (start must not be greater than end) indices of the segment to be reversed. If there are multiple ways of selecting these indices, print any of them. | [
"3\n3 2 1\n",
"4\n2 1 3 4\n",
"4\n3 1 2 4\n",
"2\n1 2\n"
] | [
"yes\n1 3\n",
"yes\n1 2\n",
"no\n",
"yes\n1 1\n"
] | Sample 1. You can reverse the entire array to get [1, 2, 3], which is sorted.
Sample 3. No segment can be reversed such that the array will be sorted.
Definitions
A segment [*l*, *r*] of array *a* is the sequence *a*[*l*], *a*[*l* + 1], ..., *a*[*r*].
If you have an array *a* of size *n* and you reverse its segment... | 1,000 | [
{
"input": "3\n3 2 1",
"output": "yes\n1 3"
},
{
"input": "4\n2 1 3 4",
"output": "yes\n1 2"
},
{
"input": "4\n3 1 2 4",
"output": "no"
},
{
"input": "2\n1 2",
"output": "yes\n1 1"
},
{
"input": "2\n58 4",
"output": "yes\n1 2"
},
{
"input": "5\n69 37 2... | 1,684,551,175 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 30 | 0 | l = int(input())
nums = [int(value) for value in input().split(" ")]
in_dec = False
exit_dec = False
dec_start = 1
dec_end = 1
for i in range(1, l):
is_dec = nums[i] < nums[i-1]
if exit_dec:
if is_dec:
print("NO")
break
elif in_dec:
if not is_de... | Title: Sort the Array
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Being a programmer, you like arrays a lot. For your birthday, your friends have given you an array *a* consisting of *n* distinct integers.
Unfortunately, the size of *a* is too small. You want a bigger array! Your frie... | ```python
l = int(input())
nums = [int(value) for value in input().split(" ")]
in_dec = False
exit_dec = False
dec_start = 1
dec_end = 1
for i in range(1, l):
is_dec = nums[i] < nums[i-1]
if exit_dec:
if is_dec:
print("NO")
break
elif in_dec:
if... | 0 | |
276 | C | Little Girl and Maximum Sum | PROGRAMMING | 1,500 | [
"data structures",
"greedy",
"implementation",
"sortings"
] | null | null | The little girl loves the problems on array queries very much.
One day she came across a rather well-known problem: you've got an array of $n$ elements (the elements of the array are indexed starting from 1); also, there are $q$ queries, each one is defined by a pair of integers $l_i$, $r_i$ $(1 \le l_i \le r_i \le n)... | The first line contains two space-separated integers $n$ ($1 \le n \le 2\cdot10^5$) and $q$ ($1 \le q \le 2\cdot10^5$) — the number of elements in the array and the number of queries, correspondingly.
The next line contains $n$ space-separated integers $a_i$ ($1 \le a_i \le 2\cdot10^5$) — the array elements.
Each of ... | In a single line print, a single integer — the maximum sum of query replies after the array elements are reordered.
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. | [
"3 3\n5 3 2\n1 2\n2 3\n1 3\n",
"5 3\n5 2 4 1 3\n1 5\n2 3\n2 3\n"
] | [
"25\n",
"33\n"
] | none | 1,500 | [
{
"input": "3 3\n5 3 2\n1 2\n2 3\n1 3",
"output": "25"
},
{
"input": "5 3\n5 2 4 1 3\n1 5\n2 3\n2 3",
"output": "33"
},
{
"input": "34 21\n23 38 16 49 44 50 48 34 33 19 18 31 11 15 20 47 44 30 39 33 45 46 1 13 27 16 31 36 17 23 38 5 30 16\n8 16\n14 27\n8 26\n1 8\n5 6\n23 28\n4 33\n13 30\... | 1,670,323,429 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 0 | 92 | 0 | n,m=map(int,input().split())
arr=sorted(map(int,input().split()))
ans=[0 for _ in range(n)]
for _ in range(m):
x,y=map(int,input().split())
ans[x-1]+=1
if y!=n:
ans[y]-=1
for i in range(1,n):
ans[i]+=ans[i-1]
arr.sort()
solution=0
for i in range(n):
solution+=(ans[i]*arr[i])
pr... | Title: Little Girl and Maximum Sum
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The little girl loves the problems on array queries very much.
One day she came across a rather well-known problem: you've got an array of $n$ elements (the elements of the array are indexed starting from 1... | ```python
n,m=map(int,input().split())
arr=sorted(map(int,input().split()))
ans=[0 for _ in range(n)]
for _ in range(m):
x,y=map(int,input().split())
ans[x-1]+=1
if y!=n:
ans[y]-=1
for i in range(1,n):
ans[i]+=ans[i-1]
arr.sort()
solution=0
for i in range(n):
solution+=(ans[i]*a... | 0 | |
319 | B | Psychos in a Line | PROGRAMMING | 1,900 | [
"data structures",
"implementation"
] | null | null | There are *n* psychos standing in a line. Each psycho is assigned a unique integer from 1 to *n*. At each step every psycho who has an id greater than the psycho to his right (if exists) kills his right neighbor in the line. Note that a psycho might kill and get killed at the same step.
You're given the initial arran... | The first line of input contains integer *n* denoting the number of psychos, (1<=≤<=*n*<=≤<=105). In the second line there will be a list of *n* space separated distinct integers each in range 1 to *n*, inclusive — ids of the psychos in the line from left to right. | Print the number of steps, so that the line remains the same afterward. | [
"10\n10 9 7 8 6 5 3 4 2 1\n",
"6\n1 2 3 4 5 6\n"
] | [
"2\n",
"0\n"
] | In the first sample line of the psychos transforms as follows: [10 9 7 8 6 5 3 4 2 1] → [10 8 4] → [10]. So, there are two steps. | 1,000 | [
{
"input": "10\n10 9 7 8 6 5 3 4 2 1",
"output": "2"
},
{
"input": "6\n1 2 3 4 5 6",
"output": "0"
},
{
"input": "6\n6 5 4 3 2 1",
"output": "1"
},
{
"input": "10\n10 7 4 2 5 8 9 6 3 1",
"output": "4"
},
{
"input": "15\n15 9 5 10 7 11 14 6 2 3 12 1 8 13 4",
"o... | 1,372,200,158 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 1 | 1,000 | 204,800 | from symbol import continue_stmt
__author__ = 'Lokki'
n = input()
b = input()
lst = b.split()
t = []
flag = True
c = 0
while (flag):
flag = False
c += 1
k = len(lst) - 1
while (k > 0):
if (int(lst[k - 1]) < int(lst[k])):
t.insert(0, lst[k])
flag = Tru... | Title: Psychos in a Line
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* psychos standing in a line. Each psycho is assigned a unique integer from 1 to *n*. At each step every psycho who has an id greater than the psycho to his right (if exists) kills his right neighbor in th... | ```python
from symbol import continue_stmt
__author__ = 'Lokki'
n = input()
b = input()
lst = b.split()
t = []
flag = True
c = 0
while (flag):
flag = False
c += 1
k = len(lst) - 1
while (k > 0):
if (int(lst[k - 1]) < int(lst[k])):
t.insert(0, lst[k])
... | 0 | |
427 | A | Police Recruits | PROGRAMMING | 800 | [
"implementation"
] | null | null | The police department of your city has just started its journey. Initially, they don’t have any manpower. So, they started hiring new recruits in groups.
Meanwhile, crimes keeps occurring within the city. One member of the police force can investigate only one crime during his/her lifetime.
If there is no police offi... | The first line of input will contain an integer *n* (1<=≤<=*n*<=≤<=105), the number of events. The next line will contain *n* space-separated integers.
If the integer is -1 then it means a crime has occurred. Otherwise, the integer will be positive, the number of officers recruited together at that time. No more than ... | Print a single integer, the number of crimes which will go untreated. | [
"3\n-1 -1 1\n",
"8\n1 -1 1 -1 -1 1 1 1\n",
"11\n-1 -1 2 -1 -1 -1 -1 -1 -1 -1 -1\n"
] | [
"2\n",
"1\n",
"8\n"
] | Lets consider the second example:
1. Firstly one person is hired. 1. Then crime appears, the last hired person will investigate this crime. 1. One more person is hired. 1. One more crime appears, the last hired person will investigate this crime. 1. Crime appears. There is no free policeman at the time, so this c... | 500 | [
{
"input": "3\n-1 -1 1",
"output": "2"
},
{
"input": "8\n1 -1 1 -1 -1 1 1 1",
"output": "1"
},
{
"input": "11\n-1 -1 2 -1 -1 -1 -1 -1 -1 -1 -1",
"output": "8"
},
{
"input": "7\n-1 -1 1 1 -1 -1 1",
"output": "2"
},
{
"input": "21\n-1 -1 -1 -1 -1 3 2 -1 6 -1 -1 2 1 ... | 1,679,186,897 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 63 | 77 | 13,209,600 | t=int(input())
l=list(map(int,input().strip().split()))
a=0
for i in range(t):
if l[i]>0:
a=a+l[i]
else:
if a>0:
l[i]=l[i]+1
a=a-1
print(l.count(-1)) | Title: Police Recruits
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The police department of your city has just started its journey. Initially, they don’t have any manpower. So, they started hiring new recruits in groups.
Meanwhile, crimes keeps occurring within the city. One member of... | ```python
t=int(input())
l=list(map(int,input().strip().split()))
a=0
for i in range(t):
if l[i]>0:
a=a+l[i]
else:
if a>0:
l[i]=l[i]+1
a=a-1
print(l.count(-1))
``` | 3 | |
900 | A | Find Extra One | PROGRAMMING | 800 | [
"geometry",
"implementation"
] | null | null | You have *n* distinct points on a plane, none of them lie on *OY* axis. Check that there is a point after removal of which the remaining points are located on one side of the *OY* axis. | The first line contains a single positive integer *n* (2<=≤<=*n*<=≤<=105).
The following *n* lines contain coordinates of the points. The *i*-th of these lines contains two single integers *x**i* and *y**i* (|*x**i*|,<=|*y**i*|<=≤<=109, *x**i*<=≠<=0). No two points coincide. | Print "Yes" if there is such a point, "No" — otherwise.
You can print every letter in any case (upper or lower). | [
"3\n1 1\n-1 -1\n2 -1\n",
"4\n1 1\n2 2\n-1 1\n-2 2\n",
"3\n1 2\n2 1\n4 60\n"
] | [
"Yes",
"No",
"Yes"
] | In the first example the second point can be removed.
In the second example there is no suitable for the condition point.
In the third example any point can be removed. | 500 | [
{
"input": "3\n1 1\n-1 -1\n2 -1",
"output": "Yes"
},
{
"input": "4\n1 1\n2 2\n-1 1\n-2 2",
"output": "No"
},
{
"input": "3\n1 2\n2 1\n4 60",
"output": "Yes"
},
{
"input": "10\n1 1\n2 2\n3 3\n4 4\n5 5\n6 6\n7 7\n8 8\n9 9\n-1 -1",
"output": "Yes"
},
{
"input": "2\n1... | 1,566,162,754 | 2,147,483,647 | PyPy 3 | OK | TESTS | 71 | 997 | 9,420,800 | import sys
from collections import defaultdict
#input = sys.stdin.readline
def main():
n = int(input())
x_pos = 0
x_neg = 0
for _ in range(n):
x, y = map(int, input().split())
if x > 0:
x_pos += 1
else:
x_neg += 1
print('YES' if n < ... | Title: Find Extra One
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You have *n* distinct points on a plane, none of them lie on *OY* axis. Check that there is a point after removal of which the remaining points are located on one side of the *OY* axis.
Input Specification:
The first li... | ```python
import sys
from collections import defaultdict
#input = sys.stdin.readline
def main():
n = int(input())
x_pos = 0
x_neg = 0
for _ in range(n):
x, y = map(int, input().split())
if x > 0:
x_pos += 1
else:
x_neg += 1
print('YE... | 3 | |
151 | A | Soft Drinking | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | This winter is so cold in Nvodsk! A group of *n* friends decided to buy *k* bottles of a soft drink called "Take-It-Light" to warm up a bit. Each bottle has *l* milliliters of the drink. Also they bought *c* limes and cut each of them into *d* slices. After that they found *p* grams of salt.
To make a toast, each frie... | The first and only line contains positive integers *n*, *k*, *l*, *c*, *d*, *p*, *nl*, *np*, not exceeding 1000 and no less than 1. The numbers are separated by exactly one space. | Print a single integer — the number of toasts each friend can make. | [
"3 4 5 10 8 100 3 1\n",
"5 100 10 1 19 90 4 3\n",
"10 1000 1000 25 23 1 50 1\n"
] | [
"2\n",
"3\n",
"0\n"
] | A comment to the first sample:
Overall the friends have 4 * 5 = 20 milliliters of the drink, it is enough to make 20 / 3 = 6 toasts. The limes are enough for 10 * 8 = 80 toasts and the salt is enough for 100 / 1 = 100 toasts. However, there are 3 friends in the group, so the answer is *min*(6, 80, 100) / 3 = 2. | 500 | [
{
"input": "3 4 5 10 8 100 3 1",
"output": "2"
},
{
"input": "5 100 10 1 19 90 4 3",
"output": "3"
},
{
"input": "10 1000 1000 25 23 1 50 1",
"output": "0"
},
{
"input": "1 7 4 5 5 8 3 2",
"output": "4"
},
{
"input": "2 3 3 5 5 10 1 3",
"output": "1"
},
{
... | 1,676,054,468 | 2,147,483,647 | Python 3 | OK | TESTS | 27 | 92 | 0 | z=[int(i) for i in input().split()]
n=z[0]
k=z[1]
l=z[2]
c=z[3]
d=z[4]
p=z[5]
nl=z[6]
np=z[7]
t=(k*l)//nl
slic=c*d
salt=p//np
print(min(t,slic,salt)//n) | Title: Soft Drinking
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
This winter is so cold in Nvodsk! A group of *n* friends decided to buy *k* bottles of a soft drink called "Take-It-Light" to warm up a bit. Each bottle has *l* milliliters of the drink. Also they bought *c* limes and cut... | ```python
z=[int(i) for i in input().split()]
n=z[0]
k=z[1]
l=z[2]
c=z[3]
d=z[4]
p=z[5]
nl=z[6]
np=z[7]
t=(k*l)//nl
slic=c*d
salt=p//np
print(min(t,slic,salt)//n)
``` | 3 | |
469 | A | I Wanna Be the Guy | PROGRAMMING | 800 | [
"greedy",
"implementation"
] | null | null | There is a game called "I Wanna Be the Guy", consisting of *n* levels. Little X and his friend Little Y are addicted to the game. Each of them wants to pass the whole game.
Little X can pass only *p* levels of the game. And Little Y can pass only *q* levels of the game. You are given the indices of levels Little X can... | The first line contains a single integer *n* (1<=≤<=<=*n*<=≤<=100).
The next line contains an integer *p* (0<=≤<=*p*<=≤<=*n*) at first, then follows *p* distinct integers *a*1,<=*a*2,<=...,<=*a**p* (1<=≤<=*a**i*<=≤<=*n*). These integers denote the indices of levels Little X can pass. The next line contains the levels... | If they can pass all the levels, print "I become the guy.". If it's impossible, print "Oh, my keyboard!" (without the quotes). | [
"4\n3 1 2 3\n2 2 4\n",
"4\n3 1 2 3\n2 2 3\n"
] | [
"I become the guy.\n",
"Oh, my keyboard!\n"
] | In the first sample, Little X can pass levels [1 2 3], and Little Y can pass level [2 4], so they can pass all the levels both.
In the second sample, no one can pass level 4. | 500 | [
{
"input": "4\n3 1 2 3\n2 2 4",
"output": "I become the guy."
},
{
"input": "4\n3 1 2 3\n2 2 3",
"output": "Oh, my keyboard!"
},
{
"input": "10\n5 8 6 1 5 4\n6 1 3 2 9 4 6",
"output": "Oh, my keyboard!"
},
{
"input": "10\n8 8 10 7 3 1 4 2 6\n8 9 5 10 3 7 2 4 8",
"output":... | 1,691,571,008 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 29 | 62 | 0 | n = int(input())
a = input().split()
b = input().split()
a.pop(0)
b.pop(0)
c = a+b
for i in range(1, n+1):
if str(i) not in c:
print("Oh, my keyboard!")
raise SystemExit
print("I become the guy.") | Title: I Wanna Be the Guy
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There is a game called "I Wanna Be the Guy", consisting of *n* levels. Little X and his friend Little Y are addicted to the game. Each of them wants to pass the whole game.
Little X can pass only *p* levels of the g... | ```python
n = int(input())
a = input().split()
b = input().split()
a.pop(0)
b.pop(0)
c = a+b
for i in range(1, n+1):
if str(i) not in c:
print("Oh, my keyboard!")
raise SystemExit
print("I become the guy.")
``` | 3 | |
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,660,143,851 | 2,147,483,647 | Python 3 | OK | TESTS | 81 | 92 | 0 | import math
loop = int(input())
x = 0
y = 0
z = 0
somme = 0
for i in range(loop):
frc = list(map(int, input().split()))
x = frc[0] + x
y = frc[1] + y
z = frc[2] + z
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
import math
loop = int(input())
x = 0
y = 0
z = 0
somme = 0
for i in range(loop):
frc = list(map(int, input().split()))
x = frc[0] + x
y = frc[1] + y
z = frc[2] + z
if x == 0 and y == 0 and z == 0:
print('YES')
else:
print('NO')
``` | 3.977 |
805 | A | Fake NP | PROGRAMMING | 1,000 | [
"greedy",
"math"
] | null | null | Tavak and Seyyed are good friends. Seyyed is very funny and he told Tavak to solve the following problem instead of longest-path.
You are given *l* and *r*. For all integers from *l* to *r*, inclusive, we wrote down all of their integer divisors except 1. Find the integer that we wrote down the maximum number of times... | The first line contains two integers *l* and *r* (2<=≤<=*l*<=≤<=*r*<=≤<=109). | Print single integer, the integer that appears maximum number of times in the divisors.
If there are multiple answers, print any of them. | [
"19 29\n",
"3 6\n"
] | [
"2\n",
"3\n"
] | Definition of a divisor: [https://www.mathsisfun.com/definitions/divisor-of-an-integer-.html](https://www.mathsisfun.com/definitions/divisor-of-an-integer-.html)
The first example: from 19 to 29 these numbers are divisible by 2: {20, 22, 24, 26, 28}.
The second example: from 3 to 6 these numbers are divisible by 3: {... | 500 | [
{
"input": "19 29",
"output": "2"
},
{
"input": "3 6",
"output": "2"
},
{
"input": "39 91",
"output": "2"
},
{
"input": "76 134",
"output": "2"
},
{
"input": "93 95",
"output": "2"
},
{
"input": "17 35",
"output": "2"
},
{
"input": "94 95",... | 1,577,725,058 | 2,147,483,647 | Python 3 | OK | TESTS | 93 | 124 | 307,200 | l,r = list(map(int, input().split()))
print(l) if l==r else print(2) | Title: Fake NP
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Tavak and Seyyed are good friends. Seyyed is very funny and he told Tavak to solve the following problem instead of longest-path.
You are given *l* and *r*. For all integers from *l* to *r*, inclusive, we wrote down all of the... | ```python
l,r = list(map(int, input().split()))
print(l) if l==r else print(2)
``` | 3 | |
749 | A | Bachgold Problem | PROGRAMMING | 800 | [
"greedy",
"implementation",
"math",
"number theory"
] | null | null | Bachgold problem is very easy to formulate. Given a positive integer *n* represent it as a sum of maximum possible number of prime numbers. One can prove that such representation exists for any integer greater than 1.
Recall that integer *k* is called prime if it is greater than 1 and has exactly two positive integer ... | The only line of the input contains a single integer *n* (2<=≤<=*n*<=≤<=100<=000). | The first line of the output contains a single integer *k* — maximum possible number of primes in representation.
The second line should contain *k* primes with their sum equal to *n*. You can print them in any order. If there are several optimal solution, print any of them. | [
"5\n",
"6\n"
] | [
"2\n2 3\n",
"3\n2 2 2\n"
] | none | 500 | [
{
"input": "5",
"output": "2\n2 3"
},
{
"input": "6",
"output": "3\n2 2 2"
},
{
"input": "2",
"output": "1\n2"
},
{
"input": "3",
"output": "1\n3"
},
{
"input": "99999",
"output": "49999\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 ... | 1,621,503,533 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 77 | 102,400 | n = int(input())
if(n%2 == 0):
print(n//2)
for i in range(1,(n//2) + 1):
print(2 , end = " ")
print()
else:
if(n%3 == 0):
print(n//3)
for i in range(1, (n//3) + 1):
print(3, end = " ")
print()
else:
print(n//2)
for i in range(1,n//2):
... | Title: Bachgold Problem
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bachgold problem is very easy to formulate. Given a positive integer *n* represent it as a sum of maximum possible number of prime numbers. One can prove that such representation exists for any integer greater than 1.
... | ```python
n = int(input())
if(n%2 == 0):
print(n//2)
for i in range(1,(n//2) + 1):
print(2 , end = " ")
print()
else:
if(n%3 == 0):
print(n//3)
for i in range(1, (n//3) + 1):
print(3, end = " ")
print()
else:
print(n//2)
for i in range(1,n/... | 0 | |
41 | A | Translation | PROGRAMMING | 800 | [
"implementation",
"strings"
] | A. Translation | 2 | 256 | The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pronounced) reversely. For example, a Berlandish word code corresponds to a Birlandish word edoc.... | The first line contains word *s*, the second line contains word *t*. The words consist of lowercase Latin letters. The input data do not consist unnecessary spaces. The words are not empty and their lengths do not exceed 100 symbols. | If the word *t* is a word *s*, written reversely, print YES, otherwise print NO. | [
"code\nedoc\n",
"abb\naba\n",
"code\ncode\n"
] | [
"YES\n",
"NO\n",
"NO\n"
] | none | 500 | [
{
"input": "code\nedoc",
"output": "YES"
},
{
"input": "abb\naba",
"output": "NO"
},
{
"input": "code\ncode",
"output": "NO"
},
{
"input": "abacaba\nabacaba",
"output": "YES"
},
{
"input": "q\nq",
"output": "YES"
},
{
"input": "asrgdfngfnmfgnhweratgjkk... | 1,613,224,913 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 9 | 124 | 0 | # Solving
s = input()
t = input()
count = 0
for i in range(len(s)):
if t[i] == s[-(i + 1)]:
count += 1
if count == len(s):
print("YES")
else:
print("NO")
| Title: Translation
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pron... | ```python
# Solving
s = input()
t = input()
count = 0
for i in range(len(s)):
if t[i] == s[-(i + 1)]:
count += 1
if count == len(s):
print("YES")
else:
print("NO")
``` | -1 |
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,632,843,376 | 2,147,483,647 | Python 3 | OK | TESTS | 35 | 124 | 6,758,400 | m,n=[int(x) for x in input().split()]
print(int(m*n//2)) | Title: Domino piling
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as p... | ```python
m,n=[int(x) for x in input().split()]
print(int(m*n//2))
``` | 3.956411 |
910 | A | The Way to Home | PROGRAMMING | 800 | [
"dfs and similar",
"dp",
"greedy",
"implementation"
] | null | null | A frog lives on the axis *Ox* and needs to reach home which is in the point *n*. She starts from the point 1. The frog can jump to the right at a distance not more than *d*. So, after she jumped from the point *x* she can reach the point *x*<=+<=*a*, where *a* is an integer from 1 to *d*.
For each point from 1 to *n* ... | The first line contains two integers *n* and *d* (2<=≤<=*n*<=≤<=100, 1<=≤<=*d*<=≤<=*n*<=-<=1) — the point, which the frog wants to reach, and the maximal length of the frog jump.
The second line contains a string *s* of length *n*, consisting of zeros and ones. If a character of the string *s* equals to zero, then in ... | If the frog can not reach the home, print -1.
In the other case, print the minimal number of jumps that the frog needs to reach the home which is in the point *n* from the point 1. | [
"8 4\n10010101\n",
"4 2\n1001\n",
"8 4\n11100101\n",
"12 3\n101111100101\n"
] | [
"2\n",
"-1\n",
"3\n",
"4\n"
] | In the first example the from can reach home in two jumps: the first jump from the point 1 to the point 4 (the length of the jump is three), and the second jump from the point 4 to the point 8 (the length of the jump is four).
In the second example the frog can not reach home, because to make it she need to jump on a ... | 500 | [
{
"input": "8 4\n10010101",
"output": "2"
},
{
"input": "4 2\n1001",
"output": "-1"
},
{
"input": "8 4\n11100101",
"output": "3"
},
{
"input": "12 3\n101111100101",
"output": "4"
},
{
"input": "5 4\n11011",
"output": "1"
},
{
"input": "5 4\n10001",
... | 1,612,206,717 | 2,147,483,647 | PyPy 3 | OK | TESTS | 63 | 109 | 1,638,400 | from collections import defaultdict
class Graph:
def __init__(self):
self.graph = defaultdict(list)
self.visit = {}
self.ff=0
self.count=0
def flag(self):
return self.ff
def creategh(self,a,b):
self.graph[a].append(b)
def DFSUtil(sel... | Title: The Way to Home
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A frog lives on the axis *Ox* and needs to reach home which is in the point *n*. She starts from the point 1. The frog can jump to the right at a distance not more than *d*. So, after she jumped from the point *x* she c... | ```python
from collections import defaultdict
class Graph:
def __init__(self):
self.graph = defaultdict(list)
self.visit = {}
self.ff=0
self.count=0
def flag(self):
return self.ff
def creategh(self,a,b):
self.graph[a].append(b)
def D... | 3 | |
284 | A | Cows and Primitive Roots | PROGRAMMING | 1,400 | [
"implementation",
"math",
"number theory"
] | null | null | The cows have just learned what a primitive root is! Given a prime *p*, a primitive root is an integer *x* (1<=≤<=*x*<=<<=*p*) such that none of integers *x*<=-<=1,<=*x*2<=-<=1,<=...,<=*x**p*<=-<=2<=-<=1 are divisible by *p*, but *x**p*<=-<=1<=-<=1 is.
Unfortunately, computing primitive roots can be time consumin... | The input contains a single line containing an integer *p* (2<=≤<=*p*<=<<=2000). It is guaranteed that *p* is a prime. | Output on a single line the number of primitive roots . | [
"3\n",
"5\n"
] | [
"1\n",
"2\n"
] | The only primitive root <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/3722298ba062e95b18705d1253eb4e5d31e3b2d1.png" style="max-width: 100.0%;max-height: 100.0%;"/> is 2.
The primitive roots <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/1d85c6a17ef1c42b53cf9... | 500 | [
{
"input": "3",
"output": "1"
},
{
"input": "5",
"output": "2"
},
{
"input": "7",
"output": "2"
},
{
"input": "11",
"output": "4"
},
{
"input": "17",
"output": "8"
},
{
"input": "19",
"output": "6"
},
{
"input": "1583",
"output": "672"
... | 1,368,473,001 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 6 | 2,000 | 102,400 | ##A
def phi(n):
res=n
i=2
while(i*i<=n):
if not n%i:
while(not n%i): n/=i
res-=(res/i)
i+=1
if (n>1):
res-=(res/n)
return int(res)
p=int(input())
print(phi(p-1))
| Title: Cows and Primitive Roots
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The cows have just learned what a primitive root is! Given a prime *p*, a primitive root is an integer *x* (1<=≤<=*x*<=<<=*p*) such that none of integers *x*<=-<=1,<=*x*2<=-<=1,<=...,<=*x**p*<=-<=2<=-<=1 ar... | ```python
##A
def phi(n):
res=n
i=2
while(i*i<=n):
if not n%i:
while(not n%i): n/=i
res-=(res/i)
i+=1
if (n>1):
res-=(res/n)
return int(res)
p=int(input())
print(phi(p-1))
``` | 0 | |
378 | A | Playing with Dice | PROGRAMMING | 800 | [
"brute force"
] | null | null | Two players are playing a game. First each of them writes an integer from 1 to 6, and then a dice is thrown. The player whose written number got closer to the number on the dice wins. If both payers have the same difference, it's a draw.
The first player wrote number *a*, the second player wrote number *b*. How many w... | The single line contains two integers *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=6) — the numbers written on the paper by the first and second player, correspondingly. | Print three integers: the number of ways to throw the dice at which the first player wins, the game ends with a draw or the second player wins, correspondingly. | [
"2 5\n",
"2 4\n"
] | [
"3 0 3\n",
"2 1 3\n"
] | The dice is a standard cube-shaped six-sided object with each side containing a number from 1 to 6, and where all numbers on all sides are distinct.
You can assume that number *a* is closer to number *x* than number *b*, if |*a* - *x*| < |*b* - *x*|. | 500 | [
{
"input": "2 5",
"output": "3 0 3"
},
{
"input": "2 4",
"output": "2 1 3"
},
{
"input": "5 3",
"output": "2 1 3"
},
{
"input": "1 6",
"output": "3 0 3"
},
{
"input": "5 1",
"output": "3 1 2"
},
{
"input": "6 3",
"output": "2 0 4"
},
{
"inp... | 1,639,670,919 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 38 | 139 | 0 | a,b=[int(x) for x in input().split()]
A=0
D=0
B=0
for x in range(1,7):
if(abs(a-x)<abs(b-x)):
A+=1
elif(abs(a-x)==abs(b-x)):
D+=1
elif((abs(a-x)>abs(b-x))):
B+=1
print(A,D,B)
| Title: Playing with Dice
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Two players are playing a game. First each of them writes an integer from 1 to 6, and then a dice is thrown. The player whose written number got closer to the number on the dice wins. If both payers have the same diff... | ```python
a,b=[int(x) for x in input().split()]
A=0
D=0
B=0
for x in range(1,7):
if(abs(a-x)<abs(b-x)):
A+=1
elif(abs(a-x)==abs(b-x)):
D+=1
elif((abs(a-x)>abs(b-x))):
B+=1
print(A,D,B)
``` | 3 | |
443 | A | Anton and Letters | PROGRAMMING | 800 | [
"constructive algorithms",
"implementation"
] | null | null | Recently, Anton has found a set. The set consists of small English letters. Anton carefully wrote out all the letters from the set in one line, separated by a comma. He also added an opening curved bracket at the beginning of the line and a closing curved bracket at the end of the line.
Unfortunately, from time to ti... | The first and the single line contains the set of letters. The length of the line doesn't exceed 1000. It is guaranteed that the line starts from an opening curved bracket and ends with a closing curved bracket. Between them, small English letters are listed, separated by a comma. Each comma is followed by a space. | Print a single number — the number of distinct letters in Anton's set. | [
"{a, b, c}\n",
"{b, a, b, a}\n",
"{}\n"
] | [
"3\n",
"2\n",
"0\n"
] | none | 500 | [
{
"input": "{a, b, c}",
"output": "3"
},
{
"input": "{b, a, b, a}",
"output": "2"
},
{
"input": "{}",
"output": "0"
},
{
"input": "{a, a, c, b, b, b, c, c, c, c}",
"output": "3"
},
{
"input": "{a, c, b, b}",
"output": "3"
},
{
"input": "{a, b}",
"o... | 1,699,235,473 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 2 | 62 | 0 | #gets the set of unique letters
actualSet = set(input())
#prints number of unique letters (removing ' ', '{', '}', and ',')
print(len(actualSet) - 4) | Title: Anton and Letters
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Recently, Anton has found a set. The set consists of small English letters. Anton carefully wrote out all the letters from the set in one line, separated by a comma. He also added an opening curved bracket at the begi... | ```python
#gets the set of unique letters
actualSet = set(input())
#prints number of unique letters (removing ' ', '{', '}', and ',')
print(len(actualSet) - 4)
``` | 0 | |
349 | A | Cinema Line | PROGRAMMING | 1,100 | [
"greedy",
"implementation"
] | null | null | The new "Die Hard" movie has just been released! There are *n* people at the cinema box office standing in a huge line. Each of them has a single 100, 50 or 25 ruble bill. A "Die Hard" ticket costs 25 rubles. Can the booking clerk sell a ticket to each person and give the change if he initially has no money and sells t... | The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of people in the line. The next line contains *n* integers, each of them equals 25, 50 or 100 — the values of the bills the people have. The numbers are given in the order from the beginning of the line (at the box office) to the end of the line. | Print "YES" (without the quotes) if the booking clerk can sell a ticket to each person and give the change. Otherwise print "NO". | [
"4\n25 25 50 50\n",
"2\n25 100\n",
"4\n50 50 25 25\n"
] | [
"YES\n",
"NO\n",
"NO\n"
] | none | 500 | [
{
"input": "4\n25 25 50 50",
"output": "YES"
},
{
"input": "2\n25 100",
"output": "NO"
},
{
"input": "4\n50 50 25 25",
"output": "NO"
},
{
"input": "3\n25 50 100",
"output": "NO"
},
{
"input": "10\n25 25 25 25 25 25 25 25 25 25",
"output": "YES"
},
{
"... | 1,642,961,658 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 25 | 154 | 5,222,400 | n = int(input())
money = [i for i in input().split()]
twenty5 = 0
fifty = 0
hundred = 0
flag = True
for i in range(n):
if money[i] == '25':
twenty5 += 1
elif money[i] == '50':
if twenty5 > 0:
twenty5 -= 1
else:
flag = False
break
... | Title: Cinema Line
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The new "Die Hard" movie has just been released! There are *n* people at the cinema box office standing in a huge line. Each of them has a single 100, 50 or 25 ruble bill. A "Die Hard" ticket costs 25 rubles. Can the bookin... | ```python
n = int(input())
money = [i for i in input().split()]
twenty5 = 0
fifty = 0
hundred = 0
flag = True
for i in range(n):
if money[i] == '25':
twenty5 += 1
elif money[i] == '50':
if twenty5 > 0:
twenty5 -= 1
else:
flag = False
... | 0 | |
253 | B | Physics Practical | PROGRAMMING | 1,400 | [
"binary search",
"dp",
"sortings",
"two pointers"
] | null | null | One day Vasya was on a physics practical, performing the task on measuring the capacitance. He followed the teacher's advice and did as much as *n* measurements, and recorded the results in the notebook. After that he was about to show the results to the teacher, but he remembered that at the last lesson, the teacher h... | The first line contains integer *n* (2<=≤<=*n*<=≤<=105) — the number of measurements Vasya made. The second line contains *n* integers *c*1,<=*c*2,<=...,<=*c**n* (1<=≤<=*c**i*<=≤<=5000) — the results of the measurements. The numbers on the second line are separated by single spaces. | Print a single integer — the minimum number of results Vasya will have to remove. | [
"6\n4 5 3 8 3 7\n",
"4\n4 3 2 4\n"
] | [
"2\n",
"0\n"
] | In the first sample you can remove the fourth and the sixth measurement results (values 8 and 7). Then the maximum of the remaining values will be 5, and the minimum one will be 3. Or else, you can remove the third and fifth results (both equal 3). After that the largest remaining result will be 8, and the smallest one... | 1,000 | [
{
"input": "6\n4 5 3 8 3 7",
"output": "2"
},
{
"input": "4\n4 3 2 4",
"output": "0"
},
{
"input": "6\n5 6 4 9 4 8",
"output": "1"
},
{
"input": "4\n5 4 1 5",
"output": "1"
},
{
"input": "2\n3 2",
"output": "0"
},
{
"input": "10\n39 9 18 13 6 16 47 15 ... | 1,620,463,658 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 9 | 1,000 | 13,107,200 |
# open file
fp = open('input.txt','r')
# read first line
line = fp.readline().strip()
line = fp.readline().strip()
data = [int(w) for w in line.split()]
fp.close()
data.sort()
max_value = 0
for i in range(len(data)):
for j in range(len(data) - 1, i - 1, -1):
if 2 * data[i] >= data[j]:
if ... | Title: Physics Practical
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day Vasya was on a physics practical, performing the task on measuring the capacitance. He followed the teacher's advice and did as much as *n* measurements, and recorded the results in the notebook. After that he... | ```python
# open file
fp = open('input.txt','r')
# read first line
line = fp.readline().strip()
line = fp.readline().strip()
data = [int(w) for w in line.split()]
fp.close()
data.sort()
max_value = 0
for i in range(len(data)):
for j in range(len(data) - 1, i - 1, -1):
if 2 * data[i] >= data[j]:
... | 0 | |
535 | B | Tavas and SaDDas | PROGRAMMING | 1,100 | [
"bitmasks",
"brute force",
"combinatorics",
"implementation"
] | null | null | Once again Tavas started eating coffee mix without water! Keione told him that it smells awful, but he didn't stop doing that. That's why Keione told his smart friend, SaDDas to punish him! SaDDas took Tavas' headphones and told him: "If you solve the following problem, I'll return it to you."
The problem is:
You ar... | The first and only line of input contains a lucky number *n* (1<=≤<=*n*<=≤<=109). | Print the index of *n* among all lucky numbers. | [
"4\n",
"7\n",
"77\n"
] | [
"1\n",
"2\n",
"6\n"
] | none | 1,000 | [
{
"input": "4",
"output": "1"
},
{
"input": "7",
"output": "2"
},
{
"input": "77",
"output": "6"
},
{
"input": "4",
"output": "1"
},
{
"input": "474744",
"output": "83"
},
{
"input": "777774",
"output": "125"
},
{
"input": "447",
"outpu... | 1,577,981,144 | 2,147,483,647 | PyPy 3 | OK | TESTS | 33 | 155 | 0 | n = "7"+input()
n = n.replace("4", "0").replace("7", "1")
print(int(n, 2) - 1)
| Title: Tavas and SaDDas
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Once again Tavas started eating coffee mix without water! Keione told him that it smells awful, but he didn't stop doing that. That's why Keione told his smart friend, SaDDas to punish him! SaDDas took Tavas' headphone... | ```python
n = "7"+input()
n = n.replace("4", "0").replace("7", "1")
print(int(n, 2) - 1)
``` | 3 | |
99 | A | Help Far Away Kingdom | PROGRAMMING | 800 | [
"strings"
] | A. Help Far Away Kingdom | 2 | 256 | In a far away kingdom lived the King, the Prince, the Shoemaker, the Dressmaker and many other citizens. They lived happily until great trouble came into the Kingdom. The ACMers settled there.
Most damage those strange creatures inflicted upon the kingdom was that they loved high precision numbers. As a result, the Ki... | The first line contains a single number to round up — the integer part (a non-empty set of decimal digits that do not start with 0 — with the exception of a case when the set consists of a single digit — in this case 0 can go first), then follows character «.» (a dot), and then follows the fractional part (any non-empt... | If the last number of the integer part is not equal to 9, print the rounded-up number without leading zeroes. Otherwise, print the message "GOTO Vasilisa." (without the quotes). | [
"0.0\n",
"1.49\n",
"1.50\n",
"2.71828182845904523536\n",
"3.14159265358979323846\n",
"12345678901234567890.1\n",
"123456789123456789.999\n"
] | [
"0",
"1",
"2",
"3",
"3",
"12345678901234567890",
"GOTO Vasilisa."
] | none | 500 | [
{
"input": "0.0",
"output": "0"
},
{
"input": "1.49",
"output": "1"
},
{
"input": "1.50",
"output": "2"
},
{
"input": "2.71828182845904523536",
"output": "3"
},
{
"input": "3.14159265358979323846",
"output": "3"
},
{
"input": "12345678901234567890.1",
... | 1,600,171,935 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 6 | 280 | 0 | n=input()
ss=n
s=ss.split('.')
d=(s[0][-1])+'.'+s[1]
d=float(d)
f=round(d)
s[0]=s[0].replace(s[0][-1],str(f))
print(int(s[0]))
| Title: Help Far Away Kingdom
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
In a far away kingdom lived the King, the Prince, the Shoemaker, the Dressmaker and many other citizens. They lived happily until great trouble came into the Kingdom. The ACMers settled there.
Most damage those stran... | ```python
n=input()
ss=n
s=ss.split('.')
d=(s[0][-1])+'.'+s[1]
d=float(d)
f=round(d)
s[0]=s[0].replace(s[0][-1],str(f))
print(int(s[0]))
``` | 0 |
851 | A | Arpa and a research in Mexican wave | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | Arpa is researching the Mexican wave.
There are *n* spectators in the stadium, labeled from 1 to *n*. They start the Mexican wave at time 0.
- At time 1, the first spectator stands. - At time 2, the second spectator stands. - ... - At time *k*, the *k*-th spectator stands. - At time *k*<=+<=1, the (*k*<=+<=1)-t... | The first line contains three integers *n*, *k*, *t* (1<=≤<=*n*<=≤<=109, 1<=≤<=*k*<=≤<=*n*, 1<=≤<=*t*<=<<=*n*<=+<=*k*). | Print single integer: how many spectators are standing at time *t*. | [
"10 5 3\n",
"10 5 7\n",
"10 5 12\n"
] | [
"3\n",
"5\n",
"3\n"
] | In the following a sitting spectator is represented as -, a standing spectator is represented as ^.
- At *t* = 0 ---------- <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/4d97e684117250a9afe9be022ab8a63653dd15aa.png" style="max-width: 100.0%;max-height: 100.0%;"/> number of standing spe... | 500 | [
{
"input": "10 5 3",
"output": "3"
},
{
"input": "10 5 7",
"output": "5"
},
{
"input": "10 5 12",
"output": "3"
},
{
"input": "840585600 770678331 788528791",
"output": "770678331"
},
{
"input": "25462281 23343504 8024619",
"output": "8024619"
},
{
"in... | 1,504,554,119 | 2,147,483,647 | Python 3 | OK | TESTS | 166 | 62 | 0 | n,k,t=map(int,input().split())
if t<=k:
print(t)
elif t >= k+1 and t<=n:
print(k)
else:
u= t -n
print( k -u )
| Title: Arpa and a research in Mexican wave
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Arpa is researching the Mexican wave.
There are *n* spectators in the stadium, labeled from 1 to *n*. They start the Mexican wave at time 0.
- At time 1, the first spectator stands. - At time 2,... | ```python
n,k,t=map(int,input().split())
if t<=k:
print(t)
elif t >= k+1 and t<=n:
print(k)
else:
u= t -n
print( k -u )
``` | 3 | |
724 | A | Checking the Calendar | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | You are given names of two days of the week.
Please, determine whether it is possible that during some non-leap year the first day of some month was equal to the first day of the week you are given, while the first day of the next month was equal to the second day of the week you are given. Both months should belong t... | The input consists of two lines, each of them containing the name of exactly one day of the week. It's guaranteed that each string in the input is from the set "monday", "tuesday", "wednesday", "thursday", "friday", "saturday", "sunday". | Print "YES" (without quotes) if such situation is possible during some non-leap year. Otherwise, print "NO" (without quotes). | [
"monday\ntuesday\n",
"sunday\nsunday\n",
"saturday\ntuesday\n"
] | [
"NO\n",
"YES\n",
"YES\n"
] | In the second sample, one can consider February 1 and March 1 of year 2015. Both these days were Sundays.
In the third sample, one can consider July 1 and August 1 of year 2017. First of these two days is Saturday, while the second one is Tuesday. | 500 | [
{
"input": "monday\ntuesday",
"output": "NO"
},
{
"input": "sunday\nsunday",
"output": "YES"
},
{
"input": "saturday\ntuesday",
"output": "YES"
},
{
"input": "tuesday\nthursday",
"output": "YES"
},
{
"input": "friday\nwednesday",
"output": "NO"
},
{
"i... | 1,475,929,683 | 783 | Python 3 | WRONG_ANSWER | PRETESTS | 2 | 61 | 4,608,000 | monday, tuesday, wednesday, thursday, friday, saturday, sunday = range(7)
week = ["monday", "tuesday", "wednesday", "thursday", "friday", "saturday", "sunday"]
day1 = input()
day2 = input()
months = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
f = 0
s = 0
for i in range(7):
if week[i] == day1:
... | Title: Checking the Calendar
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given names of two days of the week.
Please, determine whether it is possible that during some non-leap year the first day of some month was equal to the first day of the week you are given, while the fir... | ```python
monday, tuesday, wednesday, thursday, friday, saturday, sunday = range(7)
week = ["monday", "tuesday", "wednesday", "thursday", "friday", "saturday", "sunday"]
day1 = input()
day2 = input()
months = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
f = 0
s = 0
for i in range(7):
if week[i] ==... | 0 | |
812 | C | Sagheer and Nubian Market | PROGRAMMING | 1,500 | [
"binary search",
"sortings"
] | null | null | On his trip to Luxor and Aswan, Sagheer went to a Nubian market to buy some souvenirs for his friends and relatives. The market has some strange rules. It contains *n* different items numbered from 1 to *n*. The *i*-th item has base cost *a**i* Egyptian pounds. If Sagheer buys *k* items with indices *x*1,<=*x*2,<=...,<... | The first line contains two integers *n* and *S* (1<=≤<=*n*<=≤<=105 and 1<=≤<=*S*<=≤<=109) — the number of souvenirs in the market and Sagheer's budget.
The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=105) — the base costs of the souvenirs. | On a single line, print two integers *k*, *T* — the maximum number of souvenirs Sagheer can buy and the minimum total cost to buy these *k* souvenirs. | [
"3 11\n2 3 5\n",
"4 100\n1 2 5 6\n",
"1 7\n7\n"
] | [
"2 11\n",
"4 54\n",
"0 0\n"
] | In the first example, he cannot take the three items because they will cost him [5, 9, 14] with total cost 28. If he decides to take only two items, then the costs will be [4, 7, 11]. So he can afford the first and second items.
In the second example, he can buy all items as they will cost him [5, 10, 17, 22].
In the... | 1,500 | [
{
"input": "3 11\n2 3 5",
"output": "2 11"
},
{
"input": "4 100\n1 2 5 6",
"output": "4 54"
},
{
"input": "1 7\n7",
"output": "0 0"
},
{
"input": "1 7\n5",
"output": "1 6"
},
{
"input": "1 1\n1",
"output": "0 0"
},
{
"input": "4 33\n4 3 2 1",
"outp... | 1,618,046,701 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 6 | 93 | 0 | def ap_function(a,d,n):
ans = a+ (d*(n-1))
return ans
n,k = map(int,input().split())
arr = list(map(int,input().split()))
if k<=arr[0]:
print(0,0)
elif n==1:
print(1,arr[0]+1)
else:
curr_sum = arr[0]+1
to_plus = 1
plus = 2
last_one = arr[-1]
items,cost = 1,arr[0]
for i in range(1,n):
last_on... | Title: Sagheer and Nubian Market
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
On his trip to Luxor and Aswan, Sagheer went to a Nubian market to buy some souvenirs for his friends and relatives. The market has some strange rules. It contains *n* different items numbered from 1 to *n*. T... | ```python
def ap_function(a,d,n):
ans = a+ (d*(n-1))
return ans
n,k = map(int,input().split())
arr = list(map(int,input().split()))
if k<=arr[0]:
print(0,0)
elif n==1:
print(1,arr[0]+1)
else:
curr_sum = arr[0]+1
to_plus = 1
plus = 2
last_one = arr[-1]
items,cost = 1,arr[0]
for i in range(1,n):
... | 0 | |
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,580,208,982 | 2,147,483,647 | Python 3 | OK | TESTS | 28 | 109 | 307,200 | a,b=input().split()
if a==b:print(a)
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
a,b=input().split()
if a==b:print(a)
else:print(1)
``` | 3 | |
80 | A | Panoramix's Prediction | PROGRAMMING | 800 | [
"brute force"
] | A. Panoramix's Prediction | 2 | 256 | A prime number is a number which has exactly two distinct divisors: one and itself. For example, numbers 2, 7, 3 are prime, and 1, 6, 4 are not.
The next prime number after *x* is the smallest prime number greater than *x*. For example, the next prime number after 2 is 3, and the next prime number after 3 is 5. Note t... | The first and only input line contains two positive integers — *n* and *m* (2<=≤<=*n*<=<<=*m*<=≤<=50). It is guaranteed that *n* is prime.
Pretests contain all the cases with restrictions 2<=≤<=*n*<=<<=*m*<=≤<=4. | Print YES, if *m* is the next prime number after *n*, or NO otherwise. | [
"3 5\n",
"7 11\n",
"7 9\n"
] | [
"YES",
"YES",
"NO"
] | none | 500 | [
{
"input": "3 5",
"output": "YES"
},
{
"input": "7 11",
"output": "YES"
},
{
"input": "7 9",
"output": "NO"
},
{
"input": "2 3",
"output": "YES"
},
{
"input": "2 4",
"output": "NO"
},
{
"input": "3 4",
"output": "NO"
},
{
"input": "3 5",
... | 1,623,440,133 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 124 | 0 | a,b=list(map(int,input().split()))
l=[]
for i in range(a,b+1):
f=0
for j in range(2,i):
if (i%j==0):
f+=1
if f==0:
l.append(i)
if len(l)==1:
print("NO")
elif len(l)==2:
if l[1]==b:
print("YES")
else:
print("NO") | Title: Panoramix's Prediction
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A prime number is a number which has exactly two distinct divisors: one and itself. For example, numbers 2, 7, 3 are prime, and 1, 6, 4 are not.
The next prime number after *x* is the smallest prime number greater t... | ```python
a,b=list(map(int,input().split()))
l=[]
for i in range(a,b+1):
f=0
for j in range(2,i):
if (i%j==0):
f+=1
if f==0:
l.append(i)
if len(l)==1:
print("NO")
elif len(l)==2:
if l[1]==b:
print("YES")
else:
print("NO")
``` | 0 |
592 | B | The Monster and the Squirrel | PROGRAMMING | 1,100 | [
"math"
] | null | null | Ari the monster always wakes up very early with the first ray of the sun and the first thing she does is feeding her squirrel.
Ari draws a regular convex polygon on the floor and numbers it's vertices 1,<=2,<=...,<=*n* in clockwise order. Then starting from the vertex 1 she draws a ray in the direction of each other v... | The first and only line of the input contains a single integer *n* (3<=≤<=*n*<=≤<=54321) - the number of vertices of the regular polygon drawn by Ari. | Print the minimum number of jumps Ada should make to collect all the walnuts. Note, that she doesn't need to leave the polygon after. | [
"5\n",
"3\n"
] | [
"9\n",
"1\n"
] | One of the possible solutions for the first sample is shown on the picture above. | 1,000 | [
{
"input": "5",
"output": "9"
},
{
"input": "3",
"output": "1"
},
{
"input": "54321",
"output": "2950553761"
},
{
"input": "4",
"output": "4"
},
{
"input": "6",
"output": "16"
},
{
"input": "7",
"output": "25"
},
{
"input": "8",
"output... | 1,446,310,862 | 1,862 | Python 3 | OK | TESTS | 24 | 61 | 0 | import sys
#sys.stdin = open("input.txt")
#sys.stdout = open("output.txt", "w")
n = int(input())
ans = (n - 4) * (n - 3) + 2 * (n - 3) + (n - 2)
print(ans) | Title: The Monster and the Squirrel
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Ari the monster always wakes up very early with the first ray of the sun and the first thing she does is feeding her squirrel.
Ari draws a regular convex polygon on the floor and numbers it's vertices 1,<=... | ```python
import sys
#sys.stdin = open("input.txt")
#sys.stdout = open("output.txt", "w")
n = int(input())
ans = (n - 4) * (n - 3) + 2 * (n - 3) + (n - 2)
print(ans)
``` | 3 | |
0 | none | none | none | 0 | [
"none"
] | null | null | Hooray! Berl II, the king of Berland is making a knight tournament. The king has already sent the message to all knights in the kingdom and they in turn agreed to participate in this grand event.
As for you, you're just a simple peasant. There's no surprise that you slept in this morning and were late for the tourname... | The first line contains two integers *n*, *m* (2<=≤<=*n*<=≤<=3·105; 1<=≤<=*m*<=≤<=3·105) — the number of knights and the number of fights. Each of the following *m* lines contains three integers *l**i*,<=*r**i*,<=*x**i* (1<=≤<=*l**i*<=<<=*r**i*<=≤<=*n*; *l**i*<=≤<=*x**i*<=≤<=*r**i*) — the description of the *i*-th f... | Print *n* integers. If the *i*-th knight lost, then the *i*-th number should equal the number of the knight that beat the knight number *i*. If the *i*-th knight is the winner, then the *i*-th number must equal 0. | [
"4 3\n1 2 1\n1 3 3\n1 4 4\n",
"8 4\n3 5 4\n3 7 6\n2 8 8\n1 8 1\n"
] | [
"3 1 4 0 ",
"0 8 4 6 4 8 6 1 "
] | Consider the first test case. Knights 1 and 2 fought the first fight and knight 1 won. Knights 1 and 3 fought the second fight and knight 3 won. The last fight was between knights 3 and 4, knight 4 won. | 0 | [
{
"input": "4 3\n1 2 1\n1 3 3\n1 4 4",
"output": "3 1 4 0 "
},
{
"input": "8 4\n3 5 4\n3 7 6\n2 8 8\n1 8 1",
"output": "0 8 4 6 4 8 6 1 "
},
{
"input": "2 1\n1 2 1",
"output": "0 1 "
},
{
"input": "2 1\n1 2 2",
"output": "2 0 "
},
{
"input": "3 1\n1 3 1",
"out... | 1,382,424,639 | 3,339 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 10 | 3,000 | 1,126,400 | n,m=map(int,input().split())
a=[0]*n
k=0
for i in range(m):
l,r,x=map(int,input().split())
for j in range(l-1,r):
if a[j]==0 and j+1!=x:
a[j]=x
k+=1
if k==n-1:
break
print(*a) | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Hooray! Berl II, the king of Berland is making a knight tournament. The king has already sent the message to all knights in the kingdom and they in turn agreed to participate in this grand event.
As for you, you're just a simple ... | ```python
n,m=map(int,input().split())
a=[0]*n
k=0
for i in range(m):
l,r,x=map(int,input().split())
for j in range(l-1,r):
if a[j]==0 and j+1!=x:
a[j]=x
k+=1
if k==n-1:
break
print(*a)
``` | 0 | |
387 | B | George and Round | PROGRAMMING | 1,200 | [
"brute force",
"greedy",
"two pointers"
] | null | null | George decided to prepare a Codesecrof round, so he has prepared *m* problems for the round. Let's number the problems with integers 1 through *m*. George estimates the *i*-th problem's complexity by integer *b**i*.
To make the round good, he needs to put at least *n* problems there. Besides, he needs to have at least... | The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=3000) — the minimal number of problems in a good round and the number of problems George's prepared. The second line contains space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a*1<=<<=*a*2<=<<=...<=<<=*a**n*<=≤<=106) — the requirem... | Print a single integer — the answer to the problem. | [
"3 5\n1 2 3\n1 2 2 3 3\n",
"3 5\n1 2 3\n1 1 1 1 1\n",
"3 1\n2 3 4\n1\n"
] | [
"0\n",
"2\n",
"3\n"
] | In the first sample the set of the prepared problems meets the requirements for a good round.
In the second sample, it is enough to come up with and prepare two problems with complexities 2 and 3 to get a good round.
In the third sample it is very easy to get a good round if come up with and prepare extra problems wi... | 1,000 | [
{
"input": "3 5\n1 2 3\n1 2 2 3 3",
"output": "0"
},
{
"input": "3 5\n1 2 3\n1 1 1 1 1",
"output": "2"
},
{
"input": "3 1\n2 3 4\n1",
"output": "3"
},
{
"input": "29 100\n20 32 41 67 72 155 331 382 399 412 465 470 484 511 515 529 616 637 679 715 733 763 826 843 862 903 925 97... | 1,630,448,657 | 2,147,483,647 | Python 3 | OK | TESTS | 41 | 77 | 7,372,800 | # /*@@@@@@@@@@@@@@@@@@@@@@@@@@&..@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
# @@@@@@@@@@@@@@@@@@@@@@@@@@@& * *@@@@@@@% .&@@@@@@@@@@@@@@@@@@@@@@@@
# @@@@@@@@@@@@@@@*%@@@@@@@@@@ .&@# @@@@@ *& .@@@@@@@@@@@@@@@@@@@@@@@@
# @@@@@@@@@@@@@@& . %@@@@@, @@@@@, &@# *@@@% /@@@@@@#. %@@@@@@@@@@@@
# @@@@@@@@@@@@@@& %@@%. #@(... | Title: George and Round
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
George decided to prepare a Codesecrof round, so he has prepared *m* problems for the round. Let's number the problems with integers 1 through *m*. George estimates the *i*-th problem's complexity by integer *b**i*.
T... | ```python
# /*@@@@@@@@@@@@@@@@@@@@@@@@@@&..@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
# @@@@@@@@@@@@@@@@@@@@@@@@@@@& * *@@@@@@@% .&@@@@@@@@@@@@@@@@@@@@@@@@
# @@@@@@@@@@@@@@@*%@@@@@@@@@@ .&@# @@@@@ *& .@@@@@@@@@@@@@@@@@@@@@@@@
# @@@@@@@@@@@@@@& . %@@@@@, @@@@@, &@# *@@@% /@@@@@@#. %@@@@@@@@@@@@
# @@@@@@@@@@@@@@& ... | 3 | |
0 | none | none | none | 0 | [
"none"
] | null | null | We'll call a set of positive integers *a* beautiful if the following condition fulfills: for any prime *p*, if , then . In other words, if one number from the set is divisible by prime *p*, then at least half of numbers from the set is divisible by *p*.
Your task is to find any beautiful set, where the number of eleme... | The first line contains integer *k* (10<=≤<=*k*<=≤<=5000) that shows how many numbers the required beautiful set should have. | In the first line print *k* space-separated integers that are a beautiful set. If there are multiple such sets, you are allowed to print any of them. | [
"10\n"
] | [
"16 18 24 27 36 48 54 72 108 144 \n"
] | none | 0 | [] | 1,659,312,056 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 46 | 0 | x = 0
for _ in range(int(input())):
print(x,end=' ')
x+=2 | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
We'll call a set of positive integers *a* beautiful if the following condition fulfills: for any prime *p*, if , then . In other words, if one number from the set is divisible by prime *p*, then at least half of numbers from the s... | ```python
x = 0
for _ in range(int(input())):
print(x,end=' ')
x+=2
``` | 0 | |
609 | A | USB Flash Drives | PROGRAMMING | 800 | [
"greedy",
"implementation",
"sortings"
] | null | null | Sean is trying to save a large file to a USB flash drive. He has *n* USB flash drives with capacities equal to *a*1,<=*a*2,<=...,<=*a**n* megabytes. The file size is equal to *m* megabytes.
Find the minimum number of USB flash drives needed to write Sean's file, if he can split the file between drives. | The first line contains positive integer *n* (1<=≤<=*n*<=≤<=100) — the number of USB flash drives.
The second line contains positive integer *m* (1<=≤<=*m*<=≤<=105) — the size of Sean's file.
Each of the next *n* lines contains positive integer *a**i* (1<=≤<=*a**i*<=≤<=1000) — the sizes of USB flash drives in megabyt... | Print the minimum number of USB flash drives to write Sean's file, if he can split the file between drives. | [
"3\n5\n2\n1\n3\n",
"3\n6\n2\n3\n2\n",
"2\n5\n5\n10\n"
] | [
"2\n",
"3\n",
"1\n"
] | In the first example Sean needs only two USB flash drives — the first and the third.
In the second example Sean needs all three USB flash drives.
In the third example Sean needs only one USB flash drive and he can use any available USB flash drive — the first or the second. | 0 | [
{
"input": "3\n5\n2\n1\n3",
"output": "2"
},
{
"input": "3\n6\n2\n3\n2",
"output": "3"
},
{
"input": "2\n5\n5\n10",
"output": "1"
},
{
"input": "5\n16\n8\n1\n3\n4\n9",
"output": "2"
},
{
"input": "10\n121\n10\n37\n74\n56\n42\n39\n6\n68\n8\n100",
"output": "2"
... | 1,617,794,698 | 2,147,483,647 | PyPy 3 | OK | TESTS | 34 | 109 | 1,331,200 | def insertion_sort(l):
for i in range(len(l)):
for j in (range(i)):
k = i - j
if l[k] >= l[k - 1]:
l[k - 1], l[k] = l[k], l[k - 1]
else:
break
return l
def selection_sort(l):
for i in range(len(l)):
min_ind ... | Title: USB Flash Drives
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Sean is trying to save a large file to a USB flash drive. He has *n* USB flash drives with capacities equal to *a*1,<=*a*2,<=...,<=*a**n* megabytes. The file size is equal to *m* megabytes.
Find the minimum number of... | ```python
def insertion_sort(l):
for i in range(len(l)):
for j in (range(i)):
k = i - j
if l[k] >= l[k - 1]:
l[k - 1], l[k] = l[k], l[k - 1]
else:
break
return l
def selection_sort(l):
for i in range(len(l)):
... | 3 | |
368 | B | Sereja and Suffixes | PROGRAMMING | 1,100 | [
"data structures",
"dp"
] | null | null | Sereja has an array *a*, consisting of *n* integers *a*1, *a*2, ..., *a**n*. The boy cannot sit and do nothing, he decided to study an array. Sereja took a piece of paper and wrote out *m* integers *l*1,<=*l*2,<=...,<=*l**m* (1<=≤<=*l**i*<=≤<=*n*). For each number *l**i* he wants to know how many distinct numbers are s... | The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=105). The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=105) — the array elements.
Next *m* lines contain integers *l*1,<=*l*2,<=...,<=*l**m*. The *i*-th line contains integer *l**i* (1<=≤<=*l**i*<=≤<=*n*). | Print *m* lines — on the *i*-th line print the answer to the number *l**i*. | [
"10 10\n1 2 3 4 1 2 3 4 100000 99999\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n"
] | [
"6\n6\n6\n6\n6\n5\n4\n3\n2\n1\n"
] | none | 1,000 | [
{
"input": "10 10\n1 2 3 4 1 2 3 4 100000 99999\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10",
"output": "6\n6\n6\n6\n6\n5\n4\n3\n2\n1"
},
{
"input": "8 3\n8 6 4 3 4 2 4 8\n6\n4\n2",
"output": "3\n4\n5"
},
{
"input": "7 10\n1 3 8 6 2 2 7\n4\n2\n6\n3\n4\n4\n6\n2\n7\n4",
"output": "3\n5\n2\n4\n3\n3\... | 1,690,002,995 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 30 | 140 | 19,763,200 | from sys import stdin
def solve():
n, m = map(int, stdin.readline().split())
A = [int(x) for x in stdin.readline().split()]
res = [0] * n
seen = set()
for i in range(n - 1, -1, -1):
seen.add(A[i])
res[i] = len(seen)
for _ in range(m):
i = int(stdin.rea... | Title: Sereja and Suffixes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Sereja has an array *a*, consisting of *n* integers *a*1, *a*2, ..., *a**n*. The boy cannot sit and do nothing, he decided to study an array. Sereja took a piece of paper and wrote out *m* integers *l*1,<=*l*2,<=...... | ```python
from sys import stdin
def solve():
n, m = map(int, stdin.readline().split())
A = [int(x) for x in stdin.readline().split()]
res = [0] * n
seen = set()
for i in range(n - 1, -1, -1):
seen.add(A[i])
res[i] = len(seen)
for _ in range(m):
i = int... | 3 | |
443 | A | Anton and Letters | PROGRAMMING | 800 | [
"constructive algorithms",
"implementation"
] | null | null | Recently, Anton has found a set. The set consists of small English letters. Anton carefully wrote out all the letters from the set in one line, separated by a comma. He also added an opening curved bracket at the beginning of the line and a closing curved bracket at the end of the line.
Unfortunately, from time to ti... | The first and the single line contains the set of letters. The length of the line doesn't exceed 1000. It is guaranteed that the line starts from an opening curved bracket and ends with a closing curved bracket. Between them, small English letters are listed, separated by a comma. Each comma is followed by a space. | Print a single number — the number of distinct letters in Anton's set. | [
"{a, b, c}\n",
"{b, a, b, a}\n",
"{}\n"
] | [
"3\n",
"2\n",
"0\n"
] | none | 500 | [
{
"input": "{a, b, c}",
"output": "3"
},
{
"input": "{b, a, b, a}",
"output": "2"
},
{
"input": "{}",
"output": "0"
},
{
"input": "{a, a, c, b, b, b, c, c, c, c}",
"output": "3"
},
{
"input": "{a, c, b, b}",
"output": "3"
},
{
"input": "{a, b}",
"o... | 1,688,586,845 | 2,147,483,647 | Python 3 | OK | TESTS | 27 | 46 | 0 | a=(input(""))
a.translate("{")
a.translate("}")
gazly=[]
wazly=a.translate( { ord(i): None for i in '{}, '} )
for x in wazly:
if x in gazly:
continue
else:
gazly.append(x)
print(len(gazly)) | Title: Anton and Letters
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Recently, Anton has found a set. The set consists of small English letters. Anton carefully wrote out all the letters from the set in one line, separated by a comma. He also added an opening curved bracket at the begi... | ```python
a=(input(""))
a.translate("{")
a.translate("}")
gazly=[]
wazly=a.translate( { ord(i): None for i in '{}, '} )
for x in wazly:
if x in gazly:
continue
else:
gazly.append(x)
print(len(gazly))
``` | 3 | |
158 | B | Taxi | PROGRAMMING | 1,100 | [
"*special",
"greedy",
"implementation"
] | null | null | After the lessons *n* groups of schoolchildren went outside and decided to visit Polycarpus to celebrate his birthday. We know that the *i*-th group consists of *s**i* friends (1<=≤<=*s**i*<=≤<=4), and they want to go to Polycarpus together. They decided to get there by taxi. Each car can carry at most four passengers.... | The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of groups of schoolchildren. The second line contains a sequence of integers *s*1,<=*s*2,<=...,<=*s**n* (1<=≤<=*s**i*<=≤<=4). The integers are separated by a space, *s**i* is the number of children in the *i*-th group. | Print the single number — the minimum number of taxis necessary to drive all children to Polycarpus. | [
"5\n1 2 4 3 3\n",
"8\n2 3 4 4 2 1 3 1\n"
] | [
"4\n",
"5\n"
] | In the first test we can sort the children into four cars like this:
- the third group (consisting of four children), - the fourth group (consisting of three children), - the fifth group (consisting of three children), - the first and the second group (consisting of one and two children, correspondingly).
There a... | 1,000 | [
{
"input": "5\n1 2 4 3 3",
"output": "4"
},
{
"input": "8\n2 3 4 4 2 1 3 1",
"output": "5"
},
{
"input": "5\n4 4 4 4 4",
"output": "5"
},
{
"input": "12\n1 1 1 1 1 1 1 1 1 1 1 1",
"output": "3"
},
{
"input": "2\n2 1",
"output": "1"
},
{
"input": "4\n3 ... | 1,699,098,663 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 3 | 92 | 0 | x = int(input())
arr = [int(i) for i in input().split()]
t1 = 0
t2 = 0
t3 = 0
t4 = 0
t = 0
for i in arr:
if i == 1:
t1 += 1
elif i == 2:
t2 += 1
elif i == 3:
t3 += 1
else:
t4 += 1
while x != 0:
if t1 != 0:
if t3 != 0:
t += 1
t1 -= 1
t3 -= 1
x ... | Title: Taxi
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
After the lessons *n* groups of schoolchildren went outside and decided to visit Polycarpus to celebrate his birthday. We know that the *i*-th group consists of *s**i* friends (1<=≤<=*s**i*<=≤<=4), and they want to go to Polycarpu... | ```python
x = int(input())
arr = [int(i) for i in input().split()]
t1 = 0
t2 = 0
t3 = 0
t4 = 0
t = 0
for i in arr:
if i == 1:
t1 += 1
elif i == 2:
t2 += 1
elif i == 3:
t3 += 1
else:
t4 += 1
while x != 0:
if t1 != 0:
if t3 != 0:
t += 1
t1 -= 1
t3 -= 1... | 0 | |
23 | A | You're Given a String... | PROGRAMMING | 1,200 | [
"brute force",
"greedy"
] | A. You're Given a String... | 2 | 256 | You're given a string of lower-case Latin letters. Your task is to find the length of its longest substring that can be met in the string at least twice. These occurrences can overlap (see sample test 2). | The first input line contains the string. It's guaranteed, that the string is non-empty, consists of lower-case Latin letters, and its length doesn't exceed 100. | Output one number — length of the longest substring that can be met in the string at least twice. | [
"abcd\n",
"ababa\n",
"zzz\n"
] | [
"0",
"3",
"2"
] | none | 0 | [
{
"input": "abcd",
"output": "0"
},
{
"input": "ababa",
"output": "3"
},
{
"input": "zzz",
"output": "2"
},
{
"input": "kmmm",
"output": "2"
},
{
"input": "wzznz",
"output": "1"
},
{
"input": "qlzazaaqll",
"output": "2"
},
{
"input": "lzggg... | 1,378,943,242 | 2,147,483,647 | Python 3 | OK | TESTS | 45 | 124 | 0 | s=input()
n=len(s)
done=False
for length in range(n-1,0,-1):
if(done):
break
for start in range(n):
if(start+length-1>=n):
break
x=s.count(s[start:start+length])
if(x>1):
print(length)
done=True
break
if(x==1):
... | Title: You're Given a String...
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
You're given a string of lower-case Latin letters. Your task is to find the length of its longest substring that can be met in the string at least twice. These occurrences can overlap (see sample test 2).
Input Sp... | ```python
s=input()
n=len(s)
done=False
for length in range(n-1,0,-1):
if(done):
break
for start in range(n):
if(start+length-1>=n):
break
x=s.count(s[start:start+length])
if(x>1):
print(length)
done=True
break
if(x==1):
... | 3.969 |
821 | A | Okabe and Future Gadget Laboratory | PROGRAMMING | 800 | [
"implementation"
] | null | null | Okabe needs to renovate the Future Gadget Laboratory after he tried doing some crazy experiments! The lab is represented as an *n* by *n* square grid of integers. A good lab is defined as a lab in which every number not equal to 1 can be expressed as the sum of a number in the same row and a number in the same column. ... | The first line of input contains the integer *n* (1<=≤<=*n*<=≤<=50) — the size of the lab.
The next *n* lines contain *n* space-separated integers denoting a row of the grid. The *j*-th integer in the *i*-th row is *a**i*,<=*j* (1<=≤<=*a**i*,<=*j*<=≤<=105). | Print "Yes" if the given lab is good and "No" otherwise.
You can output each letter in upper or lower case. | [
"3\n1 1 2\n2 3 1\n6 4 1\n",
"3\n1 5 2\n1 1 1\n1 2 3\n"
] | [
"Yes\n",
"No\n"
] | In the first sample test, the 6 in the bottom left corner is valid because it is the sum of the 2 above it and the 4 on the right. The same holds for every number not equal to 1 in this table, so the answer is "Yes".
In the second sample test, the 5 cannot be formed as the sum of an integer in the same row and an inte... | 500 | [
{
"input": "3\n1 1 2\n2 3 1\n6 4 1",
"output": "Yes"
},
{
"input": "3\n1 5 2\n1 1 1\n1 2 3",
"output": "No"
},
{
"input": "1\n1",
"output": "Yes"
},
{
"input": "4\n1 1 1 1\n1 11 1 2\n2 5 1 4\n3 9 4 1",
"output": "Yes"
},
{
"input": "4\n1 1 1 1\n1 7 1 1\n1 3 1 2\n2... | 1,512,707,164 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 46 | 5,529,600 | n = int(input())
arr = []
for i in range(n):
arr.append(map(int, input().split()))
f = True
for i in range(n):
for j in range(n):
if arr[i][j] > 1:
if not any(arr[i][j] == arr[i][k] + arr[l][j] for k in range(n) for l in range(n)):
f = False
print("Yes" if f e... | Title: Okabe and Future Gadget Laboratory
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Okabe needs to renovate the Future Gadget Laboratory after he tried doing some crazy experiments! The lab is represented as an *n* by *n* square grid of integers. A good lab is defined as a lab in whi... | ```python
n = int(input())
arr = []
for i in range(n):
arr.append(map(int, input().split()))
f = True
for i in range(n):
for j in range(n):
if arr[i][j] > 1:
if not any(arr[i][j] == arr[i][k] + arr[l][j] for k in range(n) for l in range(n)):
f = False
print("Y... | -1 | |
996 | B | World Cup | PROGRAMMING | 1,300 | [
"binary search",
"math"
] | null | null | Allen wants to enter a fan zone that occupies a round square and has $n$ entrances.
There already is a queue of $a_i$ people in front of the $i$-th entrance. Each entrance allows one person from its queue to enter the fan zone in one minute.
Allen uses the following strategy to enter the fan zone:
- Initially he s... | The first line contains a single integer $n$ ($2 \le n \le 10^5$) — the number of entrances.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($0 \le a_i \le 10^9$) — the number of people in queues. These numbers do not include Allen. | Print a single integer — the number of entrance that Allen will use. | [
"4\n2 3 2 0\n",
"2\n10 10\n",
"6\n5 2 6 5 7 4\n"
] | [
"3\n",
"1\n",
"6\n"
] | In the first example the number of people (not including Allen) changes as follows: $[\textbf{2}, 3, 2, 0] \to [1, \textbf{2}, 1, 0] \to [0, 1, \textbf{0}, 0]$. The number in bold is the queue Alles stands in. We see that he will enter the fan zone through the third entrance.
In the second example the number of people... | 1,000 | [
{
"input": "4\n2 3 2 0",
"output": "3"
},
{
"input": "2\n10 10",
"output": "1"
},
{
"input": "6\n5 2 6 5 7 4",
"output": "6"
},
{
"input": "2\n483544186 940350702",
"output": "1"
},
{
"input": "10\n3 3 3 5 6 9 3 1 7 3",
"output": "7"
},
{
"input": "10\... | 1,688,752,952 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 2 | 1,000 | 0 | #L
n = int(input())
a = [int(x) for x in input().split()]
for i in range(10**9):
if (a[i%n]-i==0):
print(i%n+1)
break | Title: World Cup
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Allen wants to enter a fan zone that occupies a round square and has $n$ entrances.
There already is a queue of $a_i$ people in front of the $i$-th entrance. Each entrance allows one person from its queue to enter the fan zo... | ```python
#L
n = int(input())
a = [int(x) for x in input().split()]
for i in range(10**9):
if (a[i%n]-i==0):
print(i%n+1)
break
``` | 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,667,150,821 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 17 | 62 | 0 | a = input()
a = a.replace("144", "")
a = a.replace("14", "")
a = a.replace("1", "")
if (len(a) == 0):
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
a = input()
a = a.replace("144", "")
a = a.replace("14", "")
a = a.replace("1", "")
if (len(a) == 0):
print("YES")
else:
print("NO")
``` | 0 | |
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,622,310,045 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 2 | 154 | 0 | from math import gcd
a,b,n=input().split()
a=int(a)
b=int(b)
n=int(n)
m=n
if(a==b):
if(n%2==0):
print("1")
else:
print("0")
else:
while(n>0):
n=n-(gcd(a,n))
if(n==0):
print("0")
break
n-n-(gcd(b,m))
if(n... | 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
from math import gcd
a,b,n=input().split()
a=int(a)
b=int(b)
n=int(n)
m=n
if(a==b):
if(n%2==0):
print("1")
else:
print("0")
else:
while(n>0):
n=n-(gcd(a,n))
if(n==0):
print("0")
break
n-n-(gcd(b,m))
... | 0 | |
780 | A | Andryusha and Socks | PROGRAMMING | 800 | [
"implementation"
] | null | null | Andryusha is an orderly boy and likes to keep things in their place.
Today he faced a problem to put his socks in the wardrobe. He has *n* distinct pairs of socks which are initially in a bag. The pairs are numbered from 1 to *n*. Andryusha wants to put paired socks together and put them in the wardrobe. He takes the ... | The first line contains the single integer *n* (1<=≤<=*n*<=≤<=105) — the number of sock pairs.
The second line contains 2*n* integers *x*1,<=*x*2,<=...,<=*x*2*n* (1<=≤<=*x**i*<=≤<=*n*), which describe the order in which Andryusha took the socks from the bag. More precisely, *x**i* means that the *i*-th sock Andryusha ... | Print single integer — the maximum number of socks that were on the table at the same time. | [
"1\n1 1\n",
"3\n2 1 1 3 2 3\n"
] | [
"1\n",
"2\n"
] | In the first example Andryusha took a sock from the first pair and put it on the table. Then he took the next sock which is from the first pair as well, so he immediately puts both socks to the wardrobe. Thus, at most one sock was on the table at the same time.
In the second example Andryusha behaved as follows:
- ... | 500 | [
{
"input": "1\n1 1",
"output": "1"
},
{
"input": "3\n2 1 1 3 2 3",
"output": "2"
},
{
"input": "5\n5 1 3 2 4 3 1 2 4 5",
"output": "5"
},
{
"input": "10\n4 2 6 3 4 8 7 1 1 5 2 10 6 8 3 5 10 9 9 7",
"output": "6"
},
{
"input": "50\n30 47 31 38 37 50 36 43 9 23 2 2 ... | 1,592,884,990 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 3 | 2,000 | 31,948,800 | def answer():
a = int(input())
b = input().split()
c=[]
d=[]
for x in b:
if x not in d:
c.append(1)
d.append(x)
else:
c.append(0)
i=0
ans=0
temp=0
#print(c)
while i<len(c):
if c[i]:
temp+=1
... | Title: Andryusha and Socks
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Andryusha is an orderly boy and likes to keep things in their place.
Today he faced a problem to put his socks in the wardrobe. He has *n* distinct pairs of socks which are initially in a bag. The pairs are numbere... | ```python
def answer():
a = int(input())
b = input().split()
c=[]
d=[]
for x in b:
if x not in d:
c.append(1)
d.append(x)
else:
c.append(0)
i=0
ans=0
temp=0
#print(c)
while i<len(c):
if c[i]:
... | 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,599,215,767 | 2,147,483,647 | PyPy 3 | OK | TESTS | 30 | 280 | 0 | s=input()
l=[]
uc=0
lc=0
for i in s:
l.append(i)
for i in range(len(s)):
if ord(l[i]) in range (65,91):
uc+=1
if ord(l[i]) in range (97,123):
lc+=1
if uc>lc:
s=s.upper()
if uc<lc or uc==lc:
s=s.lower()
print(s)
| 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
s=input()
l=[]
uc=0
lc=0
for i in s:
l.append(i)
for i in range(len(s)):
if ord(l[i]) in range (65,91):
uc+=1
if ord(l[i]) in range (97,123):
lc+=1
if uc>lc:
s=s.upper()
if uc<lc or uc==lc:
s=s.lower()
print(s)
``` | 3.93 |
617 | A | Elephant | PROGRAMMING | 800 | [
"math"
] | null | null | An elephant decided to visit his friend. It turned out that the elephant's house is located at point 0 and his friend's house is located at point *x*(*x*<=><=0) of the coordinate line. In one step the elephant can move 1, 2, 3, 4 or 5 positions forward. Determine, what is the minimum number of steps he need to make ... | The first line of the input contains an integer *x* (1<=≤<=*x*<=≤<=1<=000<=000) — The coordinate of the friend's house. | Print the minimum number of steps that elephant needs to make to get from point 0 to point *x*. | [
"5\n",
"12\n"
] | [
"1\n",
"3\n"
] | In the first sample the elephant needs to make one step of length 5 to reach the point *x*.
In the second sample the elephant can get to point *x* if he moves by 3, 5 and 4. There are other ways to get the optimal answer but the elephant cannot reach *x* in less than three moves. | 500 | [
{
"input": "5",
"output": "1"
},
{
"input": "12",
"output": "3"
},
{
"input": "999999",
"output": "200000"
},
{
"input": "41",
"output": "9"
},
{
"input": "1000000",
"output": "200000"
},
{
"input": "1",
"output": "1"
},
{
"input": "2",
... | 1,694,084,775 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | x=int(input())
if(x>5):
x=x-5
elif(x>=4);
x=x-4
elif(x>=3):
x=x-3
elif(x>=2):
x=x-2
else:
x=x-1
print(x) | Title: Elephant
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
An elephant decided to visit his friend. It turned out that the elephant's house is located at point 0 and his friend's house is located at point *x*(*x*<=><=0) of the coordinate line. In one step the elephant can move 1, 2... | ```python
x=int(input())
if(x>5):
x=x-5
elif(x>=4);
x=x-4
elif(x>=3):
x=x-3
elif(x>=2):
x=x-2
else:
x=x-1
print(x)
``` | -1 | |
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,626,816,829 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 154 | 6,758,400 | a = input()
l_c = 0
u_c = 0
for i in range(len(a)):
if a[i] == a[i].lower():
l_c += 1
else:
u_c += 1
print(*([a.lower()], [a.upper()])[int(u_c > l_c)]) | 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
a = input()
l_c = 0
u_c = 0
for i in range(len(a)):
if a[i] == a[i].lower():
l_c += 1
else:
u_c += 1
print(*([a.lower()], [a.upper()])[int(u_c > l_c)])
``` | 3.948911 |
83 | A | Magical Array | PROGRAMMING | 1,300 | [
"math"
] | A. Magical Array | 2 | 256 | Valery is very interested in magic. Magic attracts him so much that he sees it everywhere. He explains any strange and weird phenomenon through intervention of supernatural forces. But who would have thought that even in a regular array of numbers Valera manages to see something beautiful and magical.
Valera absolutel... | The first line of the input data contains an integer *n* (1<=≤<=*n*<=≤<=105). The second line contains an array of original integers *a*1,<=*a*2,<=...,<=*a**n* (<=-<=109<=≤<=*a**i*<=≤<=109). | Print on the single line the answer to the problem: the amount of subarrays, which are magical.
Please do not use the %lld specificator to read or write 64-bit numbers in C++. It is recommended to use cin, cout streams (you can also use the %I64d specificator). | [
"4\n2 1 1 4\n",
"5\n-2 -2 -2 0 1\n"
] | [
"5\n",
"8\n"
] | Notes to sample tests:
Magical subarrays are shown with pairs of indices [a;b] of the beginning and the end.
In the first sample: [1;1], [2;2], [3;3], [4;4], [2;3].
In the second sample: [1;1], [2;2], [3;3], [4;4], [5;5], [1;2], [2;3], [1;3]. | 500 | [
{
"input": "4\n2 1 1 4",
"output": "5"
},
{
"input": "5\n-2 -2 -2 0 1",
"output": "8"
},
{
"input": "1\n10",
"output": "1"
},
{
"input": "2\n5 6",
"output": "2"
},
{
"input": "5\n5 5 4 5 5",
"output": "7"
},
{
"input": "8\n1 2 0 0 0 0 3 3",
"output... | 1,385,224,223 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 92 | 0 | j = 1000000001
k = s = 0
for i in map(int, input().split()):
if i == j: k += 1
else:
s += k * (k + 1)
j, k = i, 1
print((s + k * (k + 1)) // 2) | Title: Magical Array
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Valery is very interested in magic. Magic attracts him so much that he sees it everywhere. He explains any strange and weird phenomenon through intervention of supernatural forces. But who would have thought that even in a re... | ```python
j = 1000000001
k = s = 0
for i in map(int, input().split()):
if i == j: k += 1
else:
s += k * (k + 1)
j, k = i, 1
print((s + k * (k + 1)) // 2)
``` | 0 |
975 | D | Ghosts | PROGRAMMING | 2,000 | [
"geometry",
"math"
] | null | null | Ghosts live in harmony and peace, they travel the space without any purpose other than scare whoever stands in their way.
There are $n$ ghosts in the universe, they move in the $OXY$ plane, each one of them has its own velocity that does not change in time: $\overrightarrow{V} = V_{x}\overrightarrow{i} + V_{y}\overrig... | The first line contains three integers $n$, $a$ and $b$ ($1 \leq n \leq 200000$, $1 \leq |a| \leq 10^9$, $0 \le |b| \le 10^9$) — the number of ghosts in the universe and the parameters of the straight line.
Each of the next $n$ lines contains three integers $x_i$, $V_{xi}$, $V_{yi}$ ($-10^9 \leq x_i \leq 10^9$, $-10^9... | Output one line: experience index of the ghost kind $GX$ in the indefinite future. | [
"4 1 1\n1 -1 -1\n2 1 1\n3 1 1\n4 -1 -1\n",
"3 1 0\n-1 1 0\n0 0 -1\n1 -1 -2\n",
"3 1 0\n0 0 0\n1 0 0\n2 0 0\n"
] | [
"8\n",
"6\n",
"0\n"
] | There are four collisions $(1,2,T-0.5)$, $(1,3,T-1)$, $(2,4,T+1)$, $(3,4,T+0.5)$, where $(u,v,t)$ means a collision happened between ghosts $u$ and $v$ at moment $t$. At each collision, each ghost gained one experience point, this means that $GX = 4 \cdot 2 = 8$.
In the second test, all points will collide when $t = T... | 2,000 | [
{
"input": "4 1 1\n1 -1 -1\n2 1 1\n3 1 1\n4 -1 -1",
"output": "8"
},
{
"input": "3 1 0\n-1 1 0\n0 0 -1\n1 -1 -2",
"output": "6"
},
{
"input": "3 1 0\n0 0 0\n1 0 0\n2 0 0",
"output": "0"
},
{
"input": "10 7 -626288749\n795312099 49439844 266151109\n-842143911 23740808 62497340... | 1,525,231,728 | 2,147,483,647 | Python 3 | OK | TESTS | 36 | 904 | 43,008,000 | import sys
if locals()['__file__'][-2:] == 'py':
sys.stdin = open('in.txt', 'r')
from sys import stdin
rl = lambda l: tuple(map(int, l.split()))
n, a, b = rl(input())
l = list(map(rl, stdin.readlines()))
c, d = {}, {}
r = 0
for _, x, y in l:
i, j = a * x - y, (x, y)
r += c.get(i, 0) - d.get(j, 0)
c[i] =... | Title: Ghosts
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Ghosts live in harmony and peace, they travel the space without any purpose other than scare whoever stands in their way.
There are $n$ ghosts in the universe, they move in the $OXY$ plane, each one of them has its own velocity... | ```python
import sys
if locals()['__file__'][-2:] == 'py':
sys.stdin = open('in.txt', 'r')
from sys import stdin
rl = lambda l: tuple(map(int, l.split()))
n, a, b = rl(input())
l = list(map(rl, stdin.readlines()))
c, d = {}, {}
r = 0
for _, x, y in l:
i, j = a * x - y, (x, y)
r += c.get(i, 0) - d.get(j, 0)
... | 3 | |
884 | A | Book Reading | PROGRAMMING | 800 | [
"implementation"
] | null | null | Recently Luba bought a very interesting book. She knows that it will take *t* seconds to read the book. Luba wants to finish reading as fast as she can.
But she has some work to do in each of *n* next days. The number of seconds that Luba has to spend working during *i*-th day is *a**i*. If some free time remains, she... | The first line contains two integers *n* and *t* (1<=≤<=*n*<=≤<=100, 1<=≤<=*t*<=≤<=106) — the number of days and the time required to read the book.
The second line contains *n* integers *a**i* (0<=≤<=*a**i*<=≤<=86400) — the time Luba has to spend on her work during *i*-th day. | Print the minimum day Luba can finish reading the book.
It is guaranteed that answer doesn't exceed *n*. | [
"2 2\n86400 86398\n",
"2 86400\n0 86400\n"
] | [
"2\n",
"1\n"
] | none | 0 | [
{
"input": "2 2\n86400 86398",
"output": "2"
},
{
"input": "2 86400\n0 86400",
"output": "1"
},
{
"input": "2 86400\n1 86399",
"output": "2"
},
{
"input": "100 1000000\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0... | 1,644,449,320 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 31 | 0 | # for the number of days and the time to read a book
n, t = input("Enter two values: ").split()
# take the number of times she have to work
lst = input("enter the time: ").split()
for i in range(len(lst)):
lst[i] = int(lst[i])
counter = 0
for item in range(len(lst)):
s = 86400 - lst[item]
if s >= i... | Title: Book Reading
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Recently Luba bought a very interesting book. She knows that it will take *t* seconds to read the book. Luba wants to finish reading as fast as she can.
But she has some work to do in each of *n* next days. The number of ... | ```python
# for the number of days and the time to read a book
n, t = input("Enter two values: ").split()
# take the number of times she have to work
lst = input("enter the time: ").split()
for i in range(len(lst)):
lst[i] = int(lst[i])
counter = 0
for item in range(len(lst)):
s = 86400 - lst[item]
... | 0 | |
282 | A | Bit++ | PROGRAMMING | 800 | [
"implementation"
] | null | null | The classic programming language of Bitland is Bit++. This language is so peculiar and complicated.
The language is that peculiar as it has exactly one variable, called *x*. Also, there are two operations:
- Operation ++ increases the value of variable *x* by 1. - Operation -- decreases the value of variable *x* by... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=150) — the number of statements in the programme.
Next *n* lines contain a statement each. Each statement contains exactly one operation (++ or --) and exactly one variable *x* (denoted as letter «X»). Thus, there are no empty statements. The operation and th... | Print a single integer — the final value of *x*. | [
"1\n++X\n",
"2\nX++\n--X\n"
] | [
"1\n",
"0\n"
] | none | 500 | [
{
"input": "1\n++X",
"output": "1"
},
{
"input": "2\nX++\n--X",
"output": "0"
},
{
"input": "3\n++X\n++X\n++X",
"output": "3"
},
{
"input": "2\n--X\n--X",
"output": "-2"
},
{
"input": "5\n++X\n--X\n++X\n--X\n--X",
"output": "-1"
},
{
"input": "28\nX--\... | 1,698,383,336 | 2,147,483,647 | Python 3 | OK | TESTS | 36 | 46 | 0 | n=int(input())
x=0
for i in range(0,n):
j=input()
if(j=="X++" or j=="++X"):
x=x+1
elif(j=="X--"or j=="--X"):
x=x-1
print(x) | Title: Bit++
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The classic programming language of Bitland is Bit++. This language is so peculiar and complicated.
The language is that peculiar as it has exactly one variable, called *x*. Also, there are two operations:
- Operation ++ incre... | ```python
n=int(input())
x=0
for i in range(0,n):
j=input()
if(j=="X++" or j=="++X"):
x=x+1
elif(j=="X--"or j=="--X"):
x=x-1
print(x)
``` | 3 | |
702 | A | Maximum Increase | PROGRAMMING | 800 | [
"dp",
"greedy",
"implementation"
] | null | null | You are given array consisting of *n* integers. Your task is to find the maximum length of an increasing subarray of the given array.
A subarray is the sequence of consecutive elements of the array. Subarray is called increasing if each element of this subarray strictly greater than previous. | The first line contains single positive integer *n* (1<=≤<=*n*<=≤<=105) — the number of integers.
The second line contains *n* positive integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109). | Print the maximum length of an increasing subarray of the given array. | [
"5\n1 7 2 11 15\n",
"6\n100 100 100 100 100 100\n",
"3\n1 2 3\n"
] | [
"3\n",
"1\n",
"3\n"
] | none | 0 | [
{
"input": "5\n1 7 2 11 15",
"output": "3"
},
{
"input": "6\n100 100 100 100 100 100",
"output": "1"
},
{
"input": "3\n1 2 3",
"output": "3"
},
{
"input": "1\n1000000000",
"output": "1"
},
{
"input": "10\n802030518 598196518 640274071 983359971 71550121 96204862 7... | 1,657,991,497 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 4 | 77 | 0 | n = int(input())
l = list(map(int, input().split()))
length = 1
maxlen = 1
for i in range(1,len(l)):
if l[i] > l[i-1]:
length = length + 1
# print(l[i],l[i-1], length)
else:
if(length>maxlen):
maxlen = length
length = 1
maxlen = length
print(maxlen) | Title: Maximum Increase
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given array consisting of *n* integers. Your task is to find the maximum length of an increasing subarray of the given array.
A subarray is the sequence of consecutive elements of the array. Subarray is called... | ```python
n = int(input())
l = list(map(int, input().split()))
length = 1
maxlen = 1
for i in range(1,len(l)):
if l[i] > l[i-1]:
length = length + 1
# print(l[i],l[i-1], length)
else:
if(length>maxlen):
maxlen = length
length = 1
maxlen = length
print(maxlen)
``` | 0 | |
769 | B | News About Credit | PROGRAMMING | 1,200 | [
"*special",
"greedy",
"two pointers"
] | null | null | Polycarp studies at the university in the group which consists of *n* students (including himself). All they are registrated in the social net "TheContacnt!".
Not all students are equally sociable. About each student you know the value *a**i* — the maximum number of messages which the *i*-th student is agree to send p... | The first line contains the positive integer *n* (2<=≤<=*n*<=≤<=100) — the number of students.
The second line contains the sequence *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=100), where *a**i* equals to the maximum number of messages which can the *i*-th student agree to send. Consider that Polycarp always has th... | Print -1 to the first line if it is impossible to inform all students about credit.
Otherwise, in the first line print the integer *k* — the number of messages which will be sent. In each of the next *k* lines print two distinct integers *f* and *t*, meaning that the student number *f* sent the message with news to t... | [
"4\n1 2 1 0\n",
"6\n2 0 1 3 2 0\n",
"3\n0 2 2\n"
] | [
"3\n1 2\n2 4\n2 3\n",
"6\n1 3\n3 4\n1 2\n4 5\n5 6\n4 6\n",
"-1\n"
] | In the first test Polycarp (the student number 1) can send the message to the student number 2, who after that can send the message to students number 3 and 4. Thus, all students knew about the credit. | 1,000 | [
{
"input": "4\n1 2 1 0",
"output": "3\n1 2\n2 3\n2 4"
},
{
"input": "6\n2 0 1 3 2 0",
"output": "5\n1 4\n1 5\n4 3\n4 2\n4 6"
},
{
"input": "3\n0 2 2",
"output": "-1"
},
{
"input": "2\n0 0",
"output": "-1"
},
{
"input": "2\n1 0",
"output": "1\n1 2"
},
{
... | 1,488,648,807 | 20,007 | Python 3 | OK | TESTS | 60 | 62 | 4,915,200 | n=int(input())
ai=input().split()
res=[]
prov=[1]
for i in range(0,n):
ai[i]=int(ai[i])
prov.append(0)
prov.remove(0)
i=0
if ai[0]!=0 and sum(ai)>=(n-1):
it=True
else:
it=False
if it:
for j in range(0,n):
if prov[j]==1:
for i in range(0,n):
if pro... | Title: News About Credit
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp studies at the university in the group which consists of *n* students (including himself). All they are registrated in the social net "TheContacnt!".
Not all students are equally sociable. About each student... | ```python
n=int(input())
ai=input().split()
res=[]
prov=[1]
for i in range(0,n):
ai[i]=int(ai[i])
prov.append(0)
prov.remove(0)
i=0
if ai[0]!=0 and sum(ai)>=(n-1):
it=True
else:
it=False
if it:
for j in range(0,n):
if prov[j]==1:
for i in range(0,n):
... | 3 | |
686 | A | Free Ice Cream | PROGRAMMING | 800 | [
"constructive algorithms",
"implementation"
] | null | null | After their adventure with the magic mirror Kay and Gerda have returned home and sometimes give free ice cream to kids in the summer.
At the start of the day they have *x* ice cream packs. Since the ice cream is free, people start standing in the queue before Kay and Gerda's house even in the night. Each person in the... | The first line contains two space-separated integers *n* and *x* (1<=≤<=*n*<=≤<=1000, 0<=≤<=*x*<=≤<=109).
Each of the next *n* lines contains a character '+' or '-', and an integer *d**i*, separated by a space (1<=≤<=*d**i*<=≤<=109). Record "+ *d**i*" in *i*-th line means that a carrier with *d**i* ice cream packs occ... | Print two space-separated integers — number of ice cream packs left after all operations, and number of kids that left the house in distress. | [
"5 7\n+ 5\n- 10\n- 20\n+ 40\n- 20\n",
"5 17\n- 16\n- 2\n- 98\n+ 100\n- 98\n"
] | [
"22 1\n",
"3 2\n"
] | Consider the first sample.
1. Initially Kay and Gerda have 7 packs of ice cream. 1. Carrier brings 5 more, so now they have 12 packs. 1. A kid asks for 10 packs and receives them. There are only 2 packs remaining. 1. Another kid asks for 20 packs. Kay and Gerda do not have them, so the kid goes away distressed. 1.... | 500 | [
{
"input": "5 7\n+ 5\n- 10\n- 20\n+ 40\n- 20",
"output": "22 1"
},
{
"input": "5 17\n- 16\n- 2\n- 98\n+ 100\n- 98",
"output": "3 2"
},
{
"input": "6 1000000000\n+ 1000000000\n+ 1000000000\n+ 1000000000\n+ 1000000000\n+ 1000000000\n+ 1000000000",
"output": "7000000000 0"
},
{
... | 1,611,012,142 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 77 | 0 |
kidscounter =0
x , y =map(int,input().split())
for i in range(x):
s = input().split()
A = s[0]
B = int(s[1])
if A == '+':
y+=B
else:
if y >= B:
y-=B
else:
kidscounter+=1
print(y,kidscounter) | Title: Free Ice Cream
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
After their adventure with the magic mirror Kay and Gerda have returned home and sometimes give free ice cream to kids in the summer.
At the start of the day they have *x* ice cream packs. Since the ice cream is free, p... | ```python
kidscounter =0
x , y =map(int,input().split())
for i in range(x):
s = input().split()
A = s[0]
B = int(s[1])
if A == '+':
y+=B
else:
if y >= B:
y-=B
else:
kidscounter+=1
print(y,kidscounter)
``` | 3 | |
478 | B | Random Teams | PROGRAMMING | 1,300 | [
"combinatorics",
"constructive algorithms",
"greedy",
"math"
] | null | null | *n* participants of the competition were split into *m* teams in some manner so that each team has at least one participant. After the competition each pair of participants from the same team became friends.
Your task is to write a program that will find the minimum and the maximum number of pairs of friends that coul... | The only line of input contains two integers *n* and *m*, separated by a single space (1<=≤<=*m*<=≤<=*n*<=≤<=109) — the number of participants and the number of teams respectively. | The only line of the output should contain two integers *k**min* and *k**max* — the minimum possible number of pairs of friends and the maximum possible number of pairs of friends respectively. | [
"5 1\n",
"3 2\n",
"6 3\n"
] | [
"10 10\n",
"1 1\n",
"3 6\n"
] | In the first sample all the participants get into one team, so there will be exactly ten pairs of friends.
In the second sample at any possible arrangement one team will always have two participants and the other team will always have one participant. Thus, the number of pairs of friends will always be equal to one.
... | 1,000 | [
{
"input": "5 1",
"output": "10 10"
},
{
"input": "3 2",
"output": "1 1"
},
{
"input": "6 3",
"output": "3 6"
},
{
"input": "5 3",
"output": "2 3"
},
{
"input": "10 2",
"output": "20 36"
},
{
"input": "10 6",
"output": "4 10"
},
{
"input": ... | 1,694,905,076 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 3 | 61 | 0 | from math import comb, ceil
n, m = map(int, input().split())
# pior caso
time_menor = comb((n // m), 2) * (m - 1)
time_maior = comb(ceil(n / m), 2)
print(time_menor + time_maior, comb(n - (m - 1), 2))
| Title: Random Teams
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
*n* participants of the competition were split into *m* teams in some manner so that each team has at least one participant. After the competition each pair of participants from the same team became friends.
Your task is ... | ```python
from math import comb, ceil
n, m = map(int, input().split())
# pior caso
time_menor = comb((n // m), 2) * (m - 1)
time_maior = comb(ceil(n / m), 2)
print(time_menor + time_maior, comb(n - (m - 1), 2))
``` | 0 | |
275 | A | Lights Out | PROGRAMMING | 900 | [
"implementation"
] | null | null | Lenny is playing a game on a 3<=×<=3 grid of lights. In the beginning of the game all lights are switched on. Pressing any of the lights will toggle it and all side-adjacent lights. The goal of the game is to switch all the lights off. We consider the toggling as follows: if the light was switched on then it will be sw... | The input consists of three rows. Each row contains three integers each between 0 to 100 inclusive. The *j*-th number in the *i*-th row is the number of times the *j*-th light of the *i*-th row of the grid is pressed. | Print three lines, each containing three characters. The *j*-th character of the *i*-th line is "1" if and only if the corresponding light is switched on, otherwise it's "0". | [
"1 0 0\n0 0 0\n0 0 1\n",
"1 0 1\n8 8 8\n2 0 3\n"
] | [
"001\n010\n100\n",
"010\n011\n100\n"
] | none | 500 | [
{
"input": "1 0 0\n0 0 0\n0 0 1",
"output": "001\n010\n100"
},
{
"input": "1 0 1\n8 8 8\n2 0 3",
"output": "010\n011\n100"
},
{
"input": "13 85 77\n25 50 45\n65 79 9",
"output": "000\n010\n000"
},
{
"input": "96 95 5\n8 84 74\n67 31 61",
"output": "011\n011\n101"
},
{... | 1,641,808,489 | 2,147,483,647 | Python 3 | OK | TESTS | 33 | 62 | 0 | (a,b,c)=[int(x) for x in input().split()]
(d,e,f)=[int(x) for x in input().split()]
(g,h,i)=[int(x) for x in input().split()]
j=k=l=m=n=o=p=q=r=1
for z in range (a):
if j==1:j=0
else:j=1
if k==1:k=0
else:k=1
if m==1:m=0
else:m=1
for z in range (b):
if j==1:j=0
else:j=1
... | Title: Lights Out
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Lenny is playing a game on a 3<=×<=3 grid of lights. In the beginning of the game all lights are switched on. Pressing any of the lights will toggle it and all side-adjacent lights. The goal of the game is to switch all the ... | ```python
(a,b,c)=[int(x) for x in input().split()]
(d,e,f)=[int(x) for x in input().split()]
(g,h,i)=[int(x) for x in input().split()]
j=k=l=m=n=o=p=q=r=1
for z in range (a):
if j==1:j=0
else:j=1
if k==1:k=0
else:k=1
if m==1:m=0
else:m=1
for z in range (b):
if j==1:j=0
... | 3 | |
377 | A | Maze | PROGRAMMING | 1,600 | [
"dfs and similar"
] | null | null | Pavel loves grid mazes. A grid maze is an *n*<=×<=*m* rectangle maze where each cell is either empty, or is a wall. You can go from one cell to another only if both cells are empty and have a common side.
Pavel drew a grid maze with all empty cells forming a connected area. That is, you can go from any empty cell to a... | The first line contains three integers *n*, *m*, *k* (1<=≤<=*n*,<=*m*<=≤<=500, 0<=≤<=*k*<=<<=*s*), where *n* and *m* are the maze's height and width, correspondingly, *k* is the number of walls Pavel wants to add and letter *s* represents the number of empty cells in the original maze.
Each of the next *n* lines co... | Print *n* lines containing *m* characters each: the new maze that fits Pavel's requirements. Mark the empty cells that you transformed into walls as "X", the other cells must be left without changes (that is, "." and "#").
It is guaranteed that a solution exists. If there are multiple solutions you can output any of t... | [
"3 4 2\n#..#\n..#.\n#...\n",
"5 4 5\n#...\n#.#.\n.#..\n...#\n.#.#\n"
] | [
"#.X#\nX.#.\n#...\n",
"#XXX\n#X#.\nX#..\n...#\n.#.#\n"
] | none | 500 | [
{
"input": "5 4 5\n#...\n#.#.\n.#..\n...#\n.#.#",
"output": "#XXX\n#X#.\nX#..\n...#\n.#.#"
},
{
"input": "3 3 2\n#.#\n...\n#.#",
"output": "#X#\nX..\n#.#"
},
{
"input": "7 7 18\n#.....#\n..#.#..\n.#...#.\n...#...\n.#...#.\n..#.#..\n#.....#",
"output": "#XXXXX#\nXX#X#X.\nX#XXX#.\nXXX#... | 1,670,649,138 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 77 | 3,584,000 | from queue import Queue
H, W, K = map(int, input().split())
G = [list(input()) for _ in range(H)]
start = None
for i in range(H):
if '.' in G[i]:
start = i, G[i].index('.')
break
visited = [W * [False] for _ in range(H)]
dots = []
visited[start[0]][start[1]] = True
queue = Queue()... | Title: Maze
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Pavel loves grid mazes. A grid maze is an *n*<=×<=*m* rectangle maze where each cell is either empty, or is a wall. You can go from one cell to another only if both cells are empty and have a common side.
Pavel drew a grid maze w... | ```python
from queue import Queue
H, W, K = map(int, input().split())
G = [list(input()) for _ in range(H)]
start = None
for i in range(H):
if '.' in G[i]:
start = i, G[i].index('.')
break
visited = [W * [False] for _ in range(H)]
dots = []
visited[start[0]][start[1]] = True
queue... | 0 | |
803 | A | Maximal Binary Matrix | PROGRAMMING | 1,400 | [
"constructive algorithms"
] | null | null | You are given matrix with *n* rows and *n* columns filled with zeroes. You should put *k* ones in it in such a way that the resulting matrix is symmetrical with respect to the main diagonal (the diagonal that goes from the top left to the bottom right corner) and is lexicographically maximal.
One matrix is lexicograph... | The first line consists of two numbers *n* and *k* (1<=≤<=*n*<=≤<=100, 0<=≤<=*k*<=≤<=106). | If the answer exists then output resulting matrix. Otherwise output -1. | [
"2 1\n",
"3 2\n",
"2 5\n"
] | [
"1 0 \n0 0 \n",
"1 0 0 \n0 1 0 \n0 0 0 \n",
"-1\n"
] | none | 0 | [
{
"input": "2 1",
"output": "1 0 \n0 0 "
},
{
"input": "3 2",
"output": "1 0 0 \n0 1 0 \n0 0 0 "
},
{
"input": "2 5",
"output": "-1"
},
{
"input": "1 0",
"output": "0 "
},
{
"input": "1 1",
"output": "1 "
},
{
"input": "20 398",
"output": "1 1 1 1 ... | 1,698,214,083 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 31 | 0 | def create_symmetrical_matrix(n, k):
# If k is larger than the maximum number of ones in the matrix, or the matrix size is too small, return -1
max_ones = (n * n) // 2
if k > max_ones or k < 0:
return -1
# Create an empty matrix of zeros
matrix = [[0] * n for _ in range(n)]
# Distribut... | Title: Maximal Binary Matrix
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given matrix with *n* rows and *n* columns filled with zeroes. You should put *k* ones in it in such a way that the resulting matrix is symmetrical with respect to the main diagonal (the diagonal that goes... | ```python
def create_symmetrical_matrix(n, k):
# If k is larger than the maximum number of ones in the matrix, or the matrix size is too small, return -1
max_ones = (n * n) // 2
if k > max_ones or k < 0:
return -1
# Create an empty matrix of zeros
matrix = [[0] * n for _ in range(n)]
#... | 0 | |
205 | A | Little Elephant and Rozdil | PROGRAMMING | 900 | [
"brute force",
"implementation"
] | null | null | The Little Elephant loves Ukraine very much. Most of all he loves town Rozdol (ukr. "Rozdil").
However, Rozdil is dangerous to settle, so the Little Elephant wants to go to some other town. The Little Elephant doesn't like to spend much time on travelling, so for his journey he will choose a town that needs minimum ti... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105) — the number of cities. The next line contains *n* integers, separated by single spaces: the *i*-th integer represents the time needed to go from town Rozdil to the *i*-th town. The time values are positive integers, not exceeding 109.
You can consider t... | Print the answer on a single line — the number of the town the Little Elephant will go to. If there are multiple cities with minimum travel time, print "Still Rozdil" (without the quotes). | [
"2\n7 4\n",
"7\n7 4 47 100 4 9 12\n"
] | [
"2\n",
"Still Rozdil\n"
] | In the first sample there are only two cities where the Little Elephant can go. The travel time for the first town equals 7, to the second one — 4. The town which is closest to Rodzil (the only one) is the second one, so the answer is 2.
In the second sample the closest cities are cities two and five, the travelling t... | 500 | [
{
"input": "2\n7 4",
"output": "2"
},
{
"input": "7\n7 4 47 100 4 9 12",
"output": "Still Rozdil"
},
{
"input": "1\n47",
"output": "1"
},
{
"input": "2\n1000000000 1000000000",
"output": "Still Rozdil"
},
{
"input": "7\n7 6 5 4 3 2 1",
"output": "7"
},
{
... | 1,578,916,746 | 2,147,483,647 | Python 3 | OK | TESTS | 45 | 278 | 8,806,400 | input()
A = list(map(int, input().split()))
x = min(A)
print(A.index(x)+1 if A.count(x) < 2 else 'Still Rozdil') | Title: Little Elephant and Rozdil
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Little Elephant loves Ukraine very much. Most of all he loves town Rozdol (ukr. "Rozdil").
However, Rozdil is dangerous to settle, so the Little Elephant wants to go to some other town. The Little Elepha... | ```python
input()
A = list(map(int, input().split()))
x = min(A)
print(A.index(x)+1 if A.count(x) < 2 else 'Still Rozdil')
``` | 3 | |
821 | B | Okabe and Banana Trees | PROGRAMMING | 1,300 | [
"brute force",
"math"
] | null | null | Okabe needs bananas for one of his experiments for some strange reason. So he decides to go to the forest and cut banana trees.
Consider the point (*x*,<=*y*) in the 2D plane such that *x* and *y* are integers and 0<=≤<=*x*,<=*y*. There is a tree in such a point, and it has *x*<=+<=*y* bananas. There are no trees nor ... | The first line of input contains two space-separated integers *m* and *b* (1<=≤<=*m*<=≤<=1000, 1<=≤<=*b*<=≤<=10000). | Print the maximum number of bananas Okabe can get from the trees he cuts. | [
"1 5\n",
"2 3\n"
] | [
"30\n",
"25\n"
] | The graph above corresponds to sample test 1. The optimal rectangle is shown in red and has 30 bananas. | 1,000 | [
{
"input": "1 5",
"output": "30"
},
{
"input": "2 3",
"output": "25"
},
{
"input": "4 6",
"output": "459"
},
{
"input": "6 3",
"output": "171"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "10 1",
"output": "55"
},
{
"input": "20 10",
... | 1,624,943,386 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 46 | 0 | def se(m,b,s,v):
if s=="x":
return (m*b-v)//m
else:
return (m*b-m*v)
def main():
m, b=tuple(map(int,input().split()))
y=se(m,b,"x",0)//2
x=se(m,b,"y",y)
print((y+1)*(x+1)*(x+y)//2)
if __name__=='__main__':
main() | Title: Okabe and Banana Trees
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Okabe needs bananas for one of his experiments for some strange reason. So he decides to go to the forest and cut banana trees.
Consider the point (*x*,<=*y*) in the 2D plane such that *x* and *y* are integers a... | ```python
def se(m,b,s,v):
if s=="x":
return (m*b-v)//m
else:
return (m*b-m*v)
def main():
m, b=tuple(map(int,input().split()))
y=se(m,b,"x",0)//2
x=se(m,b,"y",y)
print((y+1)*(x+1)*(x+y)//2)
if __name__=='__main__':
main()
``` | 0 | |
281 | A | Word Capitalization | PROGRAMMING | 800 | [
"implementation",
"strings"
] | null | null | Capitalization is writing a word with its first letter as a capital letter. Your task is to capitalize the given word.
Note, that during capitalization all the letters except the first one remains unchanged. | A single line contains a non-empty word. This word consists of lowercase and uppercase English letters. The length of the word will not exceed 103. | Output the given word after capitalization. | [
"ApPLe\n",
"konjac\n"
] | [
"ApPLe\n",
"Konjac\n"
] | none | 500 | [
{
"input": "ApPLe",
"output": "ApPLe"
},
{
"input": "konjac",
"output": "Konjac"
},
{
"input": "a",
"output": "A"
},
{
"input": "A",
"output": "A"
},
{
"input": "z",
"output": "Z"
},
{
"input": "ABACABA",
"output": "ABACABA"
},
{
"input": "... | 1,696,510,026 | 2,147,483,647 | Python 3 | OK | TESTS | 25 | 92 | 0 | x = input()
c = x[0].upper()
print(c+x[1:]) | Title: Word Capitalization
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Capitalization is writing a word with its first letter as a capital letter. Your task is to capitalize the given word.
Note, that during capitalization all the letters except the first one remains unchanged.
Input... | ```python
x = input()
c = x[0].upper()
print(c+x[1:])
``` | 3 | |
205 | A | Little Elephant and Rozdil | PROGRAMMING | 900 | [
"brute force",
"implementation"
] | null | null | The Little Elephant loves Ukraine very much. Most of all he loves town Rozdol (ukr. "Rozdil").
However, Rozdil is dangerous to settle, so the Little Elephant wants to go to some other town. The Little Elephant doesn't like to spend much time on travelling, so for his journey he will choose a town that needs minimum ti... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105) — the number of cities. The next line contains *n* integers, separated by single spaces: the *i*-th integer represents the time needed to go from town Rozdil to the *i*-th town. The time values are positive integers, not exceeding 109.
You can consider t... | Print the answer on a single line — the number of the town the Little Elephant will go to. If there are multiple cities with minimum travel time, print "Still Rozdil" (without the quotes). | [
"2\n7 4\n",
"7\n7 4 47 100 4 9 12\n"
] | [
"2\n",
"Still Rozdil\n"
] | In the first sample there are only two cities where the Little Elephant can go. The travel time for the first town equals 7, to the second one — 4. The town which is closest to Rodzil (the only one) is the second one, so the answer is 2.
In the second sample the closest cities are cities two and five, the travelling t... | 500 | [
{
"input": "2\n7 4",
"output": "2"
},
{
"input": "7\n7 4 47 100 4 9 12",
"output": "Still Rozdil"
},
{
"input": "1\n47",
"output": "1"
},
{
"input": "2\n1000000000 1000000000",
"output": "Still Rozdil"
},
{
"input": "7\n7 6 5 4 3 2 1",
"output": "7"
},
{
... | 1,628,225,653 | 2,147,483,647 | PyPy 3 | OK | TESTS | 45 | 404 | 30,924,800 | def process():
n = int(input())
arr = list(map(int, input().split()))
min_index = -1
min_value = float('inf')
count = 0
for i in range(len(arr)):
if arr[i] < min_value:
min_value = arr[i]
min_index = i
count = 1
elif arr[... | Title: Little Elephant and Rozdil
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Little Elephant loves Ukraine very much. Most of all he loves town Rozdol (ukr. "Rozdil").
However, Rozdil is dangerous to settle, so the Little Elephant wants to go to some other town. The Little Elepha... | ```python
def process():
n = int(input())
arr = list(map(int, input().split()))
min_index = -1
min_value = float('inf')
count = 0
for i in range(len(arr)):
if arr[i] < min_value:
min_value = arr[i]
min_index = i
count = 1
... | 3 | |
535 | B | Tavas and SaDDas | PROGRAMMING | 1,100 | [
"bitmasks",
"brute force",
"combinatorics",
"implementation"
] | null | null | Once again Tavas started eating coffee mix without water! Keione told him that it smells awful, but he didn't stop doing that. That's why Keione told his smart friend, SaDDas to punish him! SaDDas took Tavas' headphones and told him: "If you solve the following problem, I'll return it to you."
The problem is:
You ar... | The first and only line of input contains a lucky number *n* (1<=≤<=*n*<=≤<=109). | Print the index of *n* among all lucky numbers. | [
"4\n",
"7\n",
"77\n"
] | [
"1\n",
"2\n",
"6\n"
] | none | 1,000 | [
{
"input": "4",
"output": "1"
},
{
"input": "7",
"output": "2"
},
{
"input": "77",
"output": "6"
},
{
"input": "4",
"output": "1"
},
{
"input": "474744",
"output": "83"
},
{
"input": "777774",
"output": "125"
},
{
"input": "447",
"outpu... | 1,434,704,061 | 2,147,483,647 | Python 3 | OK | TESTS | 33 | 62 | 0 | def main():
res = 1
for c in input():
res *= 2
if c == '7':
res += 1
print(res - 1)
if __name__ == '__main__':
main()
| Title: Tavas and SaDDas
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Once again Tavas started eating coffee mix without water! Keione told him that it smells awful, but he didn't stop doing that. That's why Keione told his smart friend, SaDDas to punish him! SaDDas took Tavas' headphone... | ```python
def main():
res = 1
for c in input():
res *= 2
if c == '7':
res += 1
print(res - 1)
if __name__ == '__main__':
main()
``` | 3 | |
43 | B | Letter | PROGRAMMING | 1,100 | [
"implementation",
"strings"
] | B. Letter | 2 | 256 | Vasya decided to write an anonymous letter cutting the letters out of a newspaper heading. He knows heading *s*1 and text *s*2 that he wants to send. Vasya can use every single heading letter no more than once. Vasya doesn't have to cut the spaces out of the heading — he just leaves some blank space to mark them. Help ... | The first line contains a newspaper heading *s*1. The second line contains the letter text *s*2. *s*1 и *s*2 are non-empty lines consisting of spaces, uppercase and lowercase Latin letters, whose lengths do not exceed 200 symbols. The uppercase and lowercase letters should be differentiated. Vasya does not cut spaces o... | If Vasya can write the given anonymous letter, print YES, otherwise print NO | [
"Instead of dogging Your footsteps it disappears but you dont notice anything\nwhere is your dog\n",
"Instead of dogging Your footsteps it disappears but you dont notice anything\nYour dog is upstears\n",
"Instead of dogging your footsteps it disappears but you dont notice anything\nYour dog is upstears\n",
"... | [
"NO\n",
"YES\n",
"NO\n",
"YES\n"
] | none | 1,000 | [
{
"input": "Instead of dogging Your footsteps it disappears but you dont notice anything\nwhere is your dog",
"output": "NO"
},
{
"input": "Instead of dogging Your footsteps it disappears but you dont notice anything\nYour dog is upstears",
"output": "YES"
},
{
"input": "Instead of doggi... | 1,598,249,343 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 218 | 6,963,200 | newsP = input()
s = input()
countN = [0]*(52)
countS = [0]*(52)
a = ord("a")
A = ord("A")
z = ord("z")
Z = ord("Z")
for x in newsP:
if(x == " "):
continue
if(ord(x) >= a and ord(x) <= z):
countN[ord(x) - a] += 1
else:
countN[26 + ord(x)-A] += 1
for x in s:
if(x == " "):
continue
if(ord(... | Title: Letter
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya decided to write an anonymous letter cutting the letters out of a newspaper heading. He knows heading *s*1 and text *s*2 that he wants to send. Vasya can use every single heading letter no more than once. Vasya doesn't have to... | ```python
newsP = input()
s = input()
countN = [0]*(52)
countS = [0]*(52)
a = ord("a")
A = ord("A")
z = ord("z")
Z = ord("Z")
for x in newsP:
if(x == " "):
continue
if(ord(x) >= a and ord(x) <= z):
countN[ord(x) - a] += 1
else:
countN[26 + ord(x)-A] += 1
for x in s:
if(x == " "):
continue... | 3.93253 |
876 | A | Trip For Meal | PROGRAMMING | 900 | [
"math"
] | null | null | Winnie-the-Pooh likes honey very much! That is why he decided to visit his friends. Winnie has got three best friends: Rabbit, Owl and Eeyore, each of them lives in his own house. There are winding paths between each pair of houses. The length of a path between Rabbit's and Owl's houses is *a* meters, between Rabbit's ... | First line contains an integer *n* (1<=≤<=*n*<=≤<=100) — number of visits.
Second line contains an integer *a* (1<=≤<=*a*<=≤<=100) — distance between Rabbit's and Owl's houses.
Third line contains an integer *b* (1<=≤<=*b*<=≤<=100) — distance between Rabbit's and Eeyore's houses.
Fourth line contains an integer *c* ... | Output one number — minimum distance in meters Winnie must go through to have a meal *n* times. | [
"3\n2\n3\n1\n",
"1\n2\n3\n5\n"
] | [
"3\n",
"0\n"
] | In the first test case the optimal path for Winnie is the following: first have a meal in Rabbit's house, then in Owl's house, then in Eeyore's house. Thus he will pass the distance 2 + 1 = 3.
In the second test case Winnie has a meal in Rabbit's house and that is for him. So he doesn't have to walk anywhere at all. | 500 | [
{
"input": "3\n2\n3\n1",
"output": "3"
},
{
"input": "1\n2\n3\n5",
"output": "0"
},
{
"input": "10\n1\n8\n3",
"output": "9"
},
{
"input": "7\n10\n5\n6",
"output": "30"
},
{
"input": "9\n9\n7\n5",
"output": "42"
},
{
"input": "9\n37\n85\n76",
"outpu... | 1,689,299,124 | 2,147,483,647 | Python 3 | OK | TESTS | 48 | 46 | 0 | n=int(input())
a=int(input())
b=int(input())
c=int(input())
h1=a
h2=b
h3=c
d=1
e=0
while(d!=n):
house = min(h1, h2)
e=e+house
if house==h1:
h1=house
h2=h3
h3=max(h1,h2)
else:
h2=house
h1=h3
h3=max(h1,h2)
d=d+1
print(e) | Title: Trip For Meal
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Winnie-the-Pooh likes honey very much! That is why he decided to visit his friends. Winnie has got three best friends: Rabbit, Owl and Eeyore, each of them lives in his own house. There are winding paths between each pair... | ```python
n=int(input())
a=int(input())
b=int(input())
c=int(input())
h1=a
h2=b
h3=c
d=1
e=0
while(d!=n):
house = min(h1, h2)
e=e+house
if house==h1:
h1=house
h2=h3
h3=max(h1,h2)
else:
h2=house
h1=h3
h3=max(h1,h2)
d=d+1
print(e)
``... | 3 | |
157 | A | Game Outcome | PROGRAMMING | 800 | [
"brute force"
] | null | null | Sherlock Holmes and Dr. Watson played some game on a checkered board *n*<=×<=*n* in size. During the game they put numbers on the board's squares by some tricky rules we don't know. However, the game is now over and each square of the board contains exactly one number. To understand who has won, they need to count the ... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=30). Each of the following *n* lines contain *n* space-separated integers. The *j*-th number on the *i*-th line represents the number on the square that belongs to the *j*-th column and the *i*-th row on the board. All number on the board are integers from 1 to 100. | Print the single number — the number of the winning squares. | [
"1\n1\n",
"2\n1 2\n3 4\n",
"4\n5 7 8 4\n9 5 3 2\n1 6 6 4\n9 5 7 3\n"
] | [
"0\n",
"2\n",
"6\n"
] | In the first example two upper squares are winning.
In the third example three left squares in the both middle rows are winning: | 500 | [
{
"input": "1\n1",
"output": "0"
},
{
"input": "2\n1 2\n3 4",
"output": "2"
},
{
"input": "4\n5 7 8 4\n9 5 3 2\n1 6 6 4\n9 5 7 3",
"output": "6"
},
{
"input": "2\n1 1\n1 1",
"output": "0"
},
{
"input": "3\n1 2 3\n4 5 6\n7 8 9",
"output": "4"
},
{
"inpu... | 1,567,427,870 | 2,147,483,647 | PyPy 3 | OK | TESTS | 49 | 280 | 2,048,000 | n = int(input())
m = []
for i in range(n):
m.append(list(map(int, input().split())))
ans = 0
for i in range(n):
for j in range(n):
t = 0
for k in range(n):
t += m[k][j]
if t > sum(m[i]):
ans += 1
print(ans) | Title: Game Outcome
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Sherlock Holmes and Dr. Watson played some game on a checkered board *n*<=×<=*n* in size. During the game they put numbers on the board's squares by some tricky rules we don't know. However, the game is now over and each s... | ```python
n = int(input())
m = []
for i in range(n):
m.append(list(map(int, input().split())))
ans = 0
for i in range(n):
for j in range(n):
t = 0
for k in range(n):
t += m[k][j]
if t > sum(m[i]):
ans += 1
print(ans)
``` | 3 | |
63 | A | Sinking Ship | PROGRAMMING | 900 | [
"implementation",
"sortings",
"strings"
] | A. Sinking Ship | 2 | 256 | The ship crashed into a reef and is sinking. Now the entire crew must be evacuated. All *n* crew members have already lined up in a row (for convenience let's label them all from left to right with positive integers from 1 to *n*) and await further instructions. However, one should evacuate the crew properly, in a stri... | The first line contains an integer *n*, which is the number of people in the crew (1<=≤<=*n*<=≤<=100). Then follow *n* lines. The *i*-th of those lines contains two words — the name of the crew member who is *i*-th in line, and his status on the ship. The words are separated by exactly one space. There are no other spa... | Print *n* lines. The *i*-th of them should contain the name of the crew member who must be the *i*-th one to leave the ship. | [
"6\nJack captain\nAlice woman\nCharlie man\nTeddy rat\nBob child\nJulia woman\n"
] | [
"Teddy\nAlice\nBob\nJulia\nCharlie\nJack\n"
] | none | 500 | [
{
"input": "6\nJack captain\nAlice woman\nCharlie man\nTeddy rat\nBob child\nJulia woman",
"output": "Teddy\nAlice\nBob\nJulia\nCharlie\nJack"
},
{
"input": "1\nA captain",
"output": "A"
},
{
"input": "1\nAbcdefjhij captain",
"output": "Abcdefjhij"
},
{
"input": "5\nA captain... | 1,626,630,738 | 2,147,483,647 | PyPy 3 | OK | TESTS | 26 | 216 | 20,172,800 | r,w,m,c=[],[],[],[]
for i in range(int(input())):
x,y=input().split()
if y=='rat':r.append(x)
elif y=='woman' or y=='child':w.append(x)
elif y=='man':m.append(x)
else:c.append(x)
for i in r:print(i)
for j in w:print(j)
for i in m:print(i)
for i in c:print(i) | Title: Sinking Ship
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
The ship crashed into a reef and is sinking. Now the entire crew must be evacuated. All *n* crew members have already lined up in a row (for convenience let's label them all from left to right with positive integers from 1 to ... | ```python
r,w,m,c=[],[],[],[]
for i in range(int(input())):
x,y=input().split()
if y=='rat':r.append(x)
elif y=='woman' or y=='child':w.append(x)
elif y=='man':m.append(x)
else:c.append(x)
for i in r:print(i)
for j in w:print(j)
for i in m:print(i)
for i in c:print(i)
``` | 3.908425 |
1,006 | C | Three Parts of the Array | PROGRAMMING | 1,200 | [
"binary search",
"data structures",
"two pointers"
] | null | null | You are given an array $d_1, d_2, \dots, d_n$ consisting of $n$ integer numbers.
Your task is to split this array into three parts (some of which may be empty) in such a way that each element of the array belongs to exactly one of the three parts, and each of the parts forms a consecutive contiguous subsegment (possib... | The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) — the number of elements in the array $d$.
The second line of the input contains $n$ integers $d_1, d_2, \dots, d_n$ ($1 \le d_i \le 10^9$) — the elements of the array $d$. | Print a single integer — the maximum possible value of $sum_1$, considering that the condition $sum_1 = sum_3$ must be met.
Obviously, at least one valid way to split the array exists (use $a=c=0$ and $b=n$). | [
"5\n1 3 1 1 4\n",
"5\n1 3 2 1 4\n",
"3\n4 1 2\n"
] | [
"5\n",
"4\n",
"0\n"
] | In the first example there is only one possible splitting which maximizes $sum_1$: $[1, 3, 1], [~], [1, 4]$.
In the second example the only way to have $sum_1=4$ is: $[1, 3], [2, 1], [4]$.
In the third example there is only one way to split the array: $[~], [4, 1, 2], [~]$. | 0 | [
{
"input": "5\n1 3 1 1 4",
"output": "5"
},
{
"input": "5\n1 3 2 1 4",
"output": "4"
},
{
"input": "3\n4 1 2",
"output": "0"
},
{
"input": "1\n1000000000",
"output": "0"
},
{
"input": "2\n1 1",
"output": "1"
},
{
"input": "5\n1 3 5 4 5",
"output": ... | 1,624,855,360 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 982 | 5,529,600 | size_array = 2 * int(input())
raw_array = map(int, input().split())
array = []
for i in raw_array:
array.append(i)
array.append(0)
b = size_array // 2
a = b -1
while True:
sum1 = sum(array[:a + 1])
sum2 = sum(array[b :])
if sum1 == sum2:
break
if sum1 < sum2:
a += 1
... | Title: Three Parts of the Array
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given an array $d_1, d_2, \dots, d_n$ consisting of $n$ integer numbers.
Your task is to split this array into three parts (some of which may be empty) in such a way that each element of the array belo... | ```python
size_array = 2 * int(input())
raw_array = map(int, input().split())
array = []
for i in raw_array:
array.append(i)
array.append(0)
b = size_array // 2
a = b -1
while True:
sum1 = sum(array[:a + 1])
sum2 = sum(array[b :])
if sum1 == sum2:
break
if sum1 < sum2:
a +... | 0 | |
26 | A | Almost Prime | PROGRAMMING | 900 | [
"number theory"
] | A. Almost Prime | 2 | 256 | A number is called almost prime if it has exactly two distinct prime divisors. For example, numbers 6, 18, 24 are almost prime, while 4, 8, 9, 42 are not. Find the amount of almost prime numbers which are between 1 and *n*, inclusive. | Input contains one integer number *n* (1<=≤<=*n*<=≤<=3000). | Output the amount of almost prime numbers between 1 and *n*, inclusive. | [
"10\n",
"21\n"
] | [
"2\n",
"8\n"
] | none | 500 | [
{
"input": "10",
"output": "2"
},
{
"input": "21",
"output": "8"
},
{
"input": "1",
"output": "0"
},
{
"input": "2",
"output": "0"
},
{
"input": "4",
"output": "0"
},
{
"input": "3",
"output": "0"
},
{
"input": "8",
"output": "1"
},
... | 1,638,188,192 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 12 | 186 | 0 | n = int(input())
res: int = 0
list1 = []
for z in range(1000):
list1.append(0)
for i in range(2, n+1):
for j in range(2, i):
if list1[j] == 0 and i % j == 0:
list1[i] = list1[i] + 1
if list1[i] == 2:
res = res + 1
print(res)
| Title: Almost Prime
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A number is called almost prime if it has exactly two distinct prime divisors. For example, numbers 6, 18, 24 are almost prime, while 4, 8, 9, 42 are not. Find the amount of almost prime numbers which are between 1 and *n*, in... | ```python
n = int(input())
res: int = 0
list1 = []
for z in range(1000):
list1.append(0)
for i in range(2, n+1):
for j in range(2, i):
if list1[j] == 0 and i % j == 0:
list1[i] = list1[i] + 1
if list1[i] == 2:
res = res + 1
print(res)
``` | -1 |
27 | E | Number With The Given Amount Of Divisors | PROGRAMMING | 2,000 | [
"brute force",
"dp",
"number theory"
] | E. Number With The Given Amount Of Divisors | 2 | 256 | Given the number *n*, find the smallest positive integer which has exactly *n* divisors. It is guaranteed that for the given *n* the answer will not exceed 1018. | The first line of the input contains integer *n* (1<=≤<=*n*<=≤<=1000). | Output the smallest positive integer with exactly *n* divisors. | [
"4\n",
"6\n"
] | [
"6\n",
"12\n"
] | none | 2,500 | [
{
"input": "1",
"output": "1"
},
{
"input": "7",
"output": "64"
},
{
"input": "8",
"output": "24"
},
{
"input": "9",
"output": "36"
},
{
"input": "10",
"output": "48"
},
{
"input": "15",
"output": "144"
},
{
"input": "20",
"output": "24... | 1,688,918,318 | 2,147,483,647 | Python 3 | OK | TESTS | 22 | 92 | 0 | ans = 2e18
now = []
p = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29]
def dfs(x):
global ans
if x == 1:
res = 1
for i in range(len(now)):
res *= pow(p[i], now[i] - 1)
if res > 1e18:
return
ans = min(ans, res)
for i in range(x, 1, -1):
... | Title: Number With The Given Amount Of Divisors
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Given the number *n*, find the smallest positive integer which has exactly *n* divisors. It is guaranteed that for the given *n* the answer will not exceed 1018.
Input Specification:
The first line... | ```python
ans = 2e18
now = []
p = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29]
def dfs(x):
global ans
if x == 1:
res = 1
for i in range(len(now)):
res *= pow(p[i], now[i] - 1)
if res > 1e18:
return
ans = min(ans, res)
for i in range(x, 1,... | 3.977 |
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,647,017,362 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 15 | 0 | n = int(input())
for i in range((n//2)+1):
print((abs((n//2)-i))*"*"+("D"*(2*i+1))+(abs((n//2)-i))*"*")
k = 0
for j in range(1,n,2):
k += 1
print((k*"*")+((n-j)*"D")+(k*"*")) | 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((n//2)+1):
print((abs((n//2)-i))*"*"+("D"*(2*i+1))+(abs((n//2)-i))*"*")
k = 0
for j in range(1,n,2):
k += 1
print((k*"*")+((n-j)*"D")+(k*"*"))
``` | 0 | |
632 | A | Grandma Laura and Apples | PROGRAMMING | 1,200 | [] | null | null | Grandma Laura came to the market to sell some apples. During the day she sold all the apples she had. But grandma is old, so she forgot how many apples she had brought to the market.
She precisely remembers she had *n* buyers and each of them bought exactly half of the apples she had at the moment of the purchase and ... | The first line contains two integers *n* and *p* (1<=≤<=*n*<=≤<=40,<=2<=≤<=*p*<=≤<=1000) — the number of the buyers and the cost of one apple. It is guaranteed that the number *p* is even.
The next *n* lines contains the description of buyers. Each buyer is described with the string half if he simply bought half of th... | Print the only integer *a* — the total money grandma should have at the end of the day.
Note that the answer can be too large, so you should use 64-bit integer type to store it. In C++ you can use the long long integer type and in Java you can use long integer type. | [
"2 10\nhalf\nhalfplus\n",
"3 10\nhalfplus\nhalfplus\nhalfplus\n"
] | [
"15\n",
"55\n"
] | In the first sample at the start of the day the grandma had two apples. First she sold one apple and then she sold a half of the second apple and gave a half of the second apple as a present to the second buyer. | 0 | [
{
"input": "2 10\nhalf\nhalfplus",
"output": "15"
},
{
"input": "3 10\nhalfplus\nhalfplus\nhalfplus",
"output": "55"
},
{
"input": "10 328\nhalf\nhalfplus\nhalfplus\nhalf\nhalfplus\nhalf\nhalf\nhalf\nhalfplus\nhalfplus",
"output": "258300"
},
{
"input": "1 2\nhalfplus",
"... | 1,565,868,989 | 2,147,483,647 | PyPy 3 | OK | TESTS | 9 | 140 | 0 | n,k = map(int,input().split())
tot = 0
h = 0
l = []
for _ in range(n):
a = input()
if a == "half":
l.append(0)
else:
l.append(1)
h += 1
l.reverse()
for i in l:
if i == 1:
tot *= 2
tot += 1
else:
tot *= 2
print(tot*k-h*k//2)
| Title: Grandma Laura and Apples
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Grandma Laura came to the market to sell some apples. During the day she sold all the apples she had. But grandma is old, so she forgot how many apples she had brought to the market.
She precisely remembers sh... | ```python
n,k = map(int,input().split())
tot = 0
h = 0
l = []
for _ in range(n):
a = input()
if a == "half":
l.append(0)
else:
l.append(1)
h += 1
l.reverse()
for i in l:
if i == 1:
tot *= 2
tot += 1
else:
tot *= 2
print(tot*k-h*k//2)
``` | 3 | |
731 | A | Night at the Museum | PROGRAMMING | 800 | [
"implementation",
"strings"
] | null | null | Grigoriy, like the hero of one famous comedy film, found a job as a night security guard at the museum. At first night he received embosser and was to take stock of the whole exposition.
Embosser is a special devise that allows to "print" the text of a plastic tape. Text is printed sequentially, character by character... | The only line of input contains the name of some exhibit — the non-empty string consisting of no more than 100 characters. It's guaranteed that the string consists of only lowercase English letters. | Print one integer — the minimum number of rotations of the wheel, required to print the name given in the input. | [
"zeus\n",
"map\n",
"ares\n"
] | [
"18\n",
"35\n",
"34\n"
] | To print the string from the first sample it would be optimal to perform the following sequence of rotations:
1. from 'a' to 'z' (1 rotation counterclockwise), 1. from 'z' to 'e' (5 clockwise rotations), 1. from 'e' to 'u' (10 rotations counterclockwise), 1. from 'u' to 's' (2 counterclockwise rotations). | 500 | [
{
"input": "zeus",
"output": "18"
},
{
"input": "map",
"output": "35"
},
{
"input": "ares",
"output": "34"
},
{
"input": "l",
"output": "11"
},
{
"input": "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuv",
"... | 1,670,304,595 | 2,147,483,647 | Python 3 | OK | TESTS | 44 | 46 | 0 | s=input()
t=27
r=[]
for i in s:
x=abs(t-(ord(i)-96))
r.append(min(x,26-x))
t=ord(i)-96
print(sum(r)) | Title: Night at the Museum
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Grigoriy, like the hero of one famous comedy film, found a job as a night security guard at the museum. At first night he received embosser and was to take stock of the whole exposition.
Embosser is a special devis... | ```python
s=input()
t=27
r=[]
for i in s:
x=abs(t-(ord(i)-96))
r.append(min(x,26-x))
t=ord(i)-96
print(sum(r))
``` | 3 | |
146 | A | Lucky Ticket | PROGRAMMING | 800 | [
"implementation"
] | null | null | Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Petya loves tickets very much. As we know, each ticket has a number that is a positive integer. It... | The first line contains an even integer *n* (2<=≤<=*n*<=≤<=50) — the length of the ticket number that needs to be checked. The second line contains an integer whose length equals exactly *n* — the ticket number. The number may contain leading zeros. | On the first line print "YES" if the given ticket number is lucky. Otherwise, print "NO" (without the quotes). | [
"2\n47\n",
"4\n4738\n",
"4\n4774\n"
] | [
"NO\n",
"NO\n",
"YES\n"
] | In the first sample the sum of digits in the first half does not equal the sum of digits in the second half (4 ≠ 7).
In the second sample the ticket number is not the lucky number. | 500 | [
{
"input": "2\n47",
"output": "NO"
},
{
"input": "4\n4738",
"output": "NO"
},
{
"input": "4\n4774",
"output": "YES"
},
{
"input": "4\n4570",
"output": "NO"
},
{
"input": "6\n477477",
"output": "YES"
},
{
"input": "6\n777777",
"output": "YES"
},
... | 1,597,625,280 | 2,147,483,647 | Python 3 | OK | TESTS | 46 | 216 | 307,200 | num=int(input())
a=list(map(int,input()))
l4=l7=0
for i in range(num):
if a[i]==4:
l4+=1
elif a[i]==7:
l7+=1
else:
break
if l4+l7!=num:
print("NO")
else:
h=num//2
s0=sum(a[:h]);s1=sum(a[h:])
if s0!=s1:
print("NO")
else:
print("YES") | Title: Lucky Ticket
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
... | ```python
num=int(input())
a=list(map(int,input()))
l4=l7=0
for i in range(num):
if a[i]==4:
l4+=1
elif a[i]==7:
l7+=1
else:
break
if l4+l7!=num:
print("NO")
else:
h=num//2
s0=sum(a[:h]);s1=sum(a[h:])
if s0!=s1:
print("NO")
else:
print("YES")
``` | 3 | |
551 | A | GukiZ and Contest | PROGRAMMING | 800 | [
"brute force",
"implementation",
"sortings"
] | null | null | Professor GukiZ likes programming contests. He especially likes to rate his students on the contests he prepares. Now, he has decided to prepare a new contest.
In total, *n* students will attend, and before the start, every one of them has some positive integer rating. Students are indexed from 1 to *n*. Let's denote... | The first line contains integer *n* (1<=≤<=*n*<=≤<=2000), number of GukiZ's students.
The second line contains *n* numbers *a*1,<=*a*2,<=... *a**n* (1<=≤<=*a**i*<=≤<=2000) where *a**i* is the rating of *i*-th student (1<=≤<=*i*<=≤<=*n*). | In a single line, print the position after the end of the contest for each of *n* students in the same order as they appear in the input. | [
"3\n1 3 3\n",
"1\n1\n",
"5\n3 5 3 4 5\n"
] | [
"3 1 1\n",
"1\n",
"4 1 4 3 1\n"
] | In the first sample, students 2 and 3 are positioned first (there is no other student with higher rating), and student 1 is positioned third since there are two students with higher rating.
In the second sample, first student is the only one on the contest.
In the third sample, students 2 and 5 share the first positi... | 500 | [
{
"input": "3\n1 3 3",
"output": "3 1 1"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "5\n3 5 3 4 5",
"output": "4 1 4 3 1"
},
{
"input": "7\n1 3 5 4 2 2 1",
"output": "6 3 1 2 4 4 6"
},
{
"input": "11\n5 6 4 2 9 7 6 6 6 6 7",
"output": "9 4 10 11 1 2 4 4... | 1,624,254,156 | 2,147,483,647 | Python 3 | OK | TESTS | 36 | 108 | 0 | n = int(input())
nums = [int(x) for x in input().strip().split()]
s = sorted(nums)[::-1]
#print(nums)
#print(s)
for i in nums:
print(1 + s.index(i), end = " ")
| Title: GukiZ and Contest
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Professor GukiZ likes programming contests. He especially likes to rate his students on the contests he prepares. Now, he has decided to prepare a new contest.
In total, *n* students will attend, and before the star... | ```python
n = int(input())
nums = [int(x) for x in input().strip().split()]
s = sorted(nums)[::-1]
#print(nums)
#print(s)
for i in nums:
print(1 + s.index(i), end = " ")
``` | 3 | |
305 | B | Continued Fractions | PROGRAMMING | 1,700 | [
"brute force",
"implementation",
"math"
] | null | null | A continued fraction of height *n* is a fraction of form . You are given two rational numbers, one is represented as and the other one is represented as a finite fraction of height *n*. Check if they are equal. | The first line contains two space-separated integers *p*,<=*q* (1<=≤<=*q*<=≤<=*p*<=≤<=1018) — the numerator and the denominator of the first fraction.
The second line contains integer *n* (1<=≤<=*n*<=≤<=90) — the height of the second fraction. The third line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a... | Print "YES" if these fractions are equal and "NO" otherwise. | [
"9 4\n2\n2 4\n",
"9 4\n3\n2 3 1\n",
"9 4\n3\n1 2 4\n"
] | [
"YES\n",
"YES\n",
"NO\n"
] | In the first sample <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/5ff92f27aebea2560d99ad61202d20bab5ee5390.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
In the second sample <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/221368c79c05fc0ecad4e5f7a64f3... | 1,000 | [
{
"input": "9 4\n2\n2 4",
"output": "YES"
},
{
"input": "9 4\n3\n2 3 1",
"output": "YES"
},
{
"input": "9 4\n3\n1 2 4",
"output": "NO"
},
{
"input": "39088169 24157817\n36\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2",
"output": "YES"
},
{
... | 1,518,308,883 | 2,147,483,647 | Python 3 | OK | TESTS | 49 | 124 | 5,632,000 | from sys import stdin
def read(): return map(int, stdin.readline().split())
def gcd(a,b): return a if b == 0 else gcd(b, a%b)
def simp(a,b):
g = gcd(a,b)
return a//g, b//g
def calc(a):
if len(a) == 1:
return a[0], 1
y, x = calc(a[1:])
return simp(a[0]*y+x, y)
num, den = read()
nu... | Title: Continued Fractions
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A continued fraction of height *n* is a fraction of form . You are given two rational numbers, one is represented as and the other one is represented as a finite fraction of height *n*. Check if they are equal.
In... | ```python
from sys import stdin
def read(): return map(int, stdin.readline().split())
def gcd(a,b): return a if b == 0 else gcd(b, a%b)
def simp(a,b):
g = gcd(a,b)
return a//g, b//g
def calc(a):
if len(a) == 1:
return a[0], 1
y, x = calc(a[1:])
return simp(a[0]*y+x, y)
num, den = ... | 3 | |
774 | E | Big Number and Remainder | PROGRAMMING | 2,300 | [
"*special",
"math",
"number theory"
] | null | null | Stepan has a very big positive integer.
Let's consider all cyclic shifts of Stepan's integer (if we look at his integer like at a string) which are also integers (i.e. they do not have leading zeros). Let's call such shifts as good shifts. For example, for the integer 10203 the good shifts are the integer itself 10203... | The first line contains the integer which Stepan has. The length of Stepan's integer is between 2 and 200<=000 digits, inclusive. It is guaranteed that Stepan's integer does not contain leading zeros.
The second line contains the integer *m* (2<=≤<=*m*<=≤<=108) — the number by which Stepan divides good shifts of his i... | Print the minimum remainder which Stepan can get if he divides all good shifts of his integer by the given number *m*. | [
"521\n3\n",
"1001\n5\n",
"5678901234567890123456789\n10000\n"
] | [
"2\n",
"0\n",
"123\n"
] | In the first example all good shifts of the integer 521 (good shifts are equal to 521, 215 and 152) has same remainder 2 when dividing by 3.
In the second example there are only two good shifts: the Stepan's integer itself and the shift by one position to the right. The integer itself is 1001 and the remainder after d... | 0 | [
{
"input": "521\n3",
"output": "2"
},
{
"input": "1001\n5",
"output": "0"
},
{
"input": "5678901234567890123456789\n10000",
"output": "123"
},
{
"input": "552352155\n13",
"output": "2"
},
{
"input": "11533077525260\n193983",
"output": "22331"
},
{
"inp... | 1,492,195,753 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 9 | 3,000 | 5,529,600 | n = input()
m = input()
m = int(m)
l = len(n)
minimum = m-1
for i in range(l):
if(n[i] == '0'):
continue
x = n[i:] + n[:i]
x = int(x)
if(minimum > x%m):
minimum = x%m
print(minimum)
| Title: Big Number and Remainder
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Stepan has a very big positive integer.
Let's consider all cyclic shifts of Stepan's integer (if we look at his integer like at a string) which are also integers (i.e. they do not have leading zeros). Let's ca... | ```python
n = input()
m = input()
m = int(m)
l = len(n)
minimum = m-1
for i in range(l):
if(n[i] == '0'):
continue
x = n[i:] + n[:i]
x = int(x)
if(minimum > x%m):
minimum = x%m
print(minimum)
``` | 0 | |
611 | A | New Year and Days | PROGRAMMING | 900 | [
"implementation"
] | null | null | Today is Wednesday, the third day of the week. What's more interesting is that tomorrow is the last day of the year 2015.
Limak is a little polar bear. He enjoyed this year a lot. Now, he is so eager to the coming year 2016.
Limak wants to prove how responsible a bear he is. He is going to regularly save candies for ... | The only line of the input is in one of the following two formats:
- "*x* of week" where *x* (1<=≤<=*x*<=≤<=7) denotes the day of the week. The 1-st day is Monday and the 7-th one is Sunday. - "*x* of month" where *x* (1<=≤<=*x*<=≤<=31) denotes the day of the month. | Print one integer — the number of candies Limak will save in the year 2016. | [
"4 of week\n",
"30 of month\n"
] | [
"52\n",
"11\n"
] | Polar bears use the Gregorian calendar. It is the most common calendar and you likely use it too. You can read about it on Wikipedia if you want to – [https://en.wikipedia.org/wiki/Gregorian_calendar](https://en.wikipedia.org/wiki/Gregorian_calendar). The week starts with Monday.
In the first sample Limak wants to sav... | 500 | [
{
"input": "4 of week",
"output": "52"
},
{
"input": "30 of month",
"output": "11"
},
{
"input": "17 of month",
"output": "12"
},
{
"input": "31 of month",
"output": "7"
},
{
"input": "6 of week",
"output": "53"
},
{
"input": "1 of week",
"output":... | 1,451,488,358 | 458 | Python 3 | OK | TESTS | 38 | 61 | 0 | sent = input().split()
x = int(sent[0])
if sent[-1] == 'week':
if x in [5, 6]:
print(53)
else:
print(52)
else:
if x == 31:
print(7)
elif x == 30:
print(11)
else:
print(12)
| Title: New Year and Days
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Today is Wednesday, the third day of the week. What's more interesting is that tomorrow is the last day of the year 2015.
Limak is a little polar bear. He enjoyed this year a lot. Now, he is so eager to the coming ye... | ```python
sent = input().split()
x = int(sent[0])
if sent[-1] == 'week':
if x in [5, 6]:
print(53)
else:
print(52)
else:
if x == 31:
print(7)
elif x == 30:
print(11)
else:
print(12)
``` | 3 | |
200 | B | Drinks | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | Little Vasya loves orange juice very much. That's why any food and drink in his kitchen necessarily contains orange juice. There are *n* drinks in his fridge, the volume fraction of orange juice in the *i*-th drink equals *p**i* percent.
One day Vasya decided to make himself an orange cocktail. He took equal proportio... | The first input line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of orange-containing drinks in Vasya's fridge. The second line contains *n* integers *p**i* (0<=≤<=*p**i*<=≤<=100) — the volume fraction of orange juice in the *i*-th drink, in percent. The numbers are separated by a space. | Print the volume fraction in percent of orange juice in Vasya's cocktail. The answer will be considered correct if the absolute or relative error does not exceed 10<=<=-<=4. | [
"3\n50 50 100\n",
"4\n0 25 50 75\n"
] | [
"66.666666666667\n",
"37.500000000000\n"
] | Note to the first sample: let's assume that Vasya takes *x* milliliters of each drink from the fridge. Then the volume of pure juice in the cocktail will equal <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/c1fac6e64d3a8ee6a5ac138cbe51e60039b22473.png" style="max-width: 100.0%;max-height: ... | 500 | [
{
"input": "3\n50 50 100",
"output": "66.666666666667"
},
{
"input": "4\n0 25 50 75",
"output": "37.500000000000"
},
{
"input": "3\n0 1 8",
"output": "3.000000000000"
},
{
"input": "5\n96 89 93 95 70",
"output": "88.600000000000"
},
{
"input": "7\n62 41 78 4 38 39... | 1,695,265,724 | 2,147,483,647 | PyPy 3 | OK | TESTS | 31 | 156 | 0 | n = int(input())
list = [int(x) for x in input().split()]
print(sum(list)/n) | Title: Drinks
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Vasya loves orange juice very much. That's why any food and drink in his kitchen necessarily contains orange juice. There are *n* drinks in his fridge, the volume fraction of orange juice in the *i*-th drink equals *p**i*... | ```python
n = int(input())
list = [int(x) for x in input().split()]
print(sum(list)/n)
``` | 3 | |
70 | A | Cookies | PROGRAMMING | 1,300 | [
"math"
] | A. Cookies | 1 | 256 | Fangy collects cookies. Once he decided to take a box and put cookies into it in some way. If we take a square *k*<=×<=*k* in size, divided into blocks 1<=×<=1 in size and paint there the main diagonal together with cells, which lie above it, then the painted area will be equal to the area occupied by one cookie *k* in... | The first line contains a single integer *n* (0<=≤<=*n*<=≤<=1000). | Print the single number, equal to the number of empty cells in the box. The answer should be printed modulo 106<=+<=3. | [
"3\n"
] | [
"9"
] | If the box possesses the base of 2<sup class="upper-index">3</sup> × 2<sup class="upper-index">3</sup> (as in the example), then the cookies will be put there in the following manner: | 500 | [
{
"input": "3",
"output": "9"
},
{
"input": "1",
"output": "1"
},
{
"input": "2",
"output": "3"
},
{
"input": "4",
"output": "27"
},
{
"input": "6",
"output": "243"
},
{
"input": "11",
"output": "59049"
},
{
"input": "14",
"output": "59... | 1,607,431,298 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 93 | 307,200 | def solve():
n = int(input())
mod = 10 **6 + 3
if (n == 0):
print(1)
return
if (n == 1):
print(1)
return
dp = [0] * (n + 1)
dp[0] = 0
dp[1] = 1
dp[2] = 3
for i in range(3, n + 1):
dp[i] = (dp[i - 1] + dp[i - 2] * 2 + 4) % mod
... | Title: Cookies
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Fangy collects cookies. Once he decided to take a box and put cookies into it in some way. If we take a square *k*<=×<=*k* in size, divided into blocks 1<=×<=1 in size and paint there the main diagonal together with cells, which li... | ```python
def solve():
n = int(input())
mod = 10 **6 + 3
if (n == 0):
print(1)
return
if (n == 1):
print(1)
return
dp = [0] * (n + 1)
dp[0] = 0
dp[1] = 1
dp[2] = 3
for i in range(3, n + 1):
dp[i] = (dp[i - 1] + dp[i - 2] * 2 + 4) ... | 0 |
581 | A | Vasya the Hipster | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | One day Vasya the Hipster decided to count how many socks he had. It turned out that he had *a* red socks and *b* blue socks.
According to the latest fashion, hipsters should wear the socks of different colors: a red one on the left foot, a blue one on the right foot.
Every day Vasya puts on new socks in the morning ... | The single line of the input contains two positive integers *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=100) — the number of red and blue socks that Vasya's got. | Print two space-separated integers — the maximum number of days when Vasya can wear different socks and the number of days when he can wear the same socks until he either runs out of socks or cannot make a single pair from the socks he's got.
Keep in mind that at the end of the day Vasya throws away the socks that he'... | [
"3 1\n",
"2 3\n",
"7 3\n"
] | [
"1 1\n",
"2 0\n",
"3 2\n"
] | In the first sample Vasya can first put on one pair of different socks, after that he has two red socks left to wear on the second day. | 500 | [
{
"input": "3 1",
"output": "1 1"
},
{
"input": "2 3",
"output": "2 0"
},
{
"input": "7 3",
"output": "3 2"
},
{
"input": "100 100",
"output": "100 0"
},
{
"input": "4 10",
"output": "4 3"
},
{
"input": "6 10",
"output": "6 2"
},
{
"input":... | 1,673,363,619 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 46 | 0 | socks = list(map(int,input().split(" ")))
red = socks[0]
blue = socks[1]
print(str(min(red,blue)) + " " + str(int((max(red,blue) - min(red,blue))/2))) | Title: Vasya the Hipster
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day Vasya the Hipster decided to count how many socks he had. It turned out that he had *a* red socks and *b* blue socks.
According to the latest fashion, hipsters should wear the socks of different colors: a red... | ```python
socks = list(map(int,input().split(" ")))
red = socks[0]
blue = socks[1]
print(str(min(red,blue)) + " " + str(int((max(red,blue) - min(red,blue))/2)))
``` | 3 | |
485 | A | Factory | PROGRAMMING | 1,400 | [
"implementation",
"math",
"matrices"
] | null | null | One industrial factory is reforming working plan. The director suggested to set a mythical detail production norm. If at the beginning of the day there were *x* details in the factory storage, then by the end of the day the factory has to produce (remainder after dividing *x* by *m*) more details. Unfortunately, no cu... | The first line contains two integers *a* and *m* (1<=≤<=*a*,<=*m*<=≤<=105). | Print "Yes" (without quotes) if the production will eventually stop, otherwise print "No". | [
"1 5\n",
"3 6\n"
] | [
"No\n",
"Yes\n"
] | none | 1,000 | [
{
"input": "1 5",
"output": "No"
},
{
"input": "3 6",
"output": "Yes"
},
{
"input": "1 8",
"output": "Yes"
},
{
"input": "2 3",
"output": "No"
},
{
"input": "3 24",
"output": "Yes"
},
{
"input": "1 1",
"output": "Yes"
},
{
"input": "100000 ... | 1,614,769,245 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 31 | 0 | def factory(a,m):
s = set()
while a%m != 0:
r = a%m
if r in s:
return False
else:
a += r
s.add(r)
return True
a,m = map(int, input().split())
if factory(a,m):
print("YES")
else:
print("NO") | Title: Factory
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One industrial factory is reforming working plan. The director suggested to set a mythical detail production norm. If at the beginning of the day there were *x* details in the factory storage, then by the end of the day the fac... | ```python
def factory(a,m):
s = set()
while a%m != 0:
r = a%m
if r in s:
return False
else:
a += r
s.add(r)
return True
a,m = map(int, input().split())
if factory(a,m):
print("YES")
else:
print("NO")
``` | 0 | |
61 | A | Ultra-Fast Mathematician | PROGRAMMING | 800 | [
"implementation"
] | A. Ultra-Fast Mathematician | 2 | 256 | Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 1018 numbers in a single second.
One day in 230 AD Shapur was trying to find out if any one can possibly do... | There are two lines in each input. Each of them contains a single number. It is guaranteed that the numbers are made from 0 and 1 only and that their length is same. The numbers may start with 0. The length of each number doesn't exceed 100. | Write one line — the corresponding answer. Do not omit the leading 0s. | [
"1010100\n0100101\n",
"000\n111\n",
"1110\n1010\n",
"01110\n01100\n"
] | [
"1110001\n",
"111\n",
"0100\n",
"00010\n"
] | none | 500 | [
{
"input": "1010100\n0100101",
"output": "1110001"
},
{
"input": "000\n111",
"output": "111"
},
{
"input": "1110\n1010",
"output": "0100"
},
{
"input": "01110\n01100",
"output": "00010"
},
{
"input": "011101\n000001",
"output": "011100"
},
{
"input": "... | 1,674,577,248 | 2,147,483,647 | Python 3 | OK | TESTS | 102 | 46 | 0 | n1 = input()
n2 = input()
output = ''
for i in range(len(n1)) :
output += str(int(n1[i]) ^ int(n2[i]) )
print(output)
| Title: Ultra-Fast Mathematician
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 10... | ```python
n1 = input()
n2 = input()
output = ''
for i in range(len(n1)) :
output += str(int(n1[i]) ^ int(n2[i]) )
print(output)
``` | 3.9885 |
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,644,178,873 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 15 | 0 | import math
key1 = int(input())
key2 = int(input())
print (math.gcd(key1, key2)) | 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
key1 = int(input())
key2 = int(input())
print (math.gcd(key1, key2))
``` | -1 | |
813 | B | The Golden Age | PROGRAMMING | 1,800 | [
"brute force",
"math"
] | null | null | Unlucky year in Berland is such a year that its number *n* can be represented as *n*<==<=*x**a*<=+<=*y**b*, where *a* and *b* are non-negative integer numbers.
For example, if *x*<==<=2 and *y*<==<=3 then the years 4 and 17 are unlucky (4<==<=20<=+<=31, 17<==<=23<=+<=32<==<=24<=+<=30) and year 18 isn't unlucky as the... | The first line contains four integer numbers *x*, *y*, *l* and *r* (2<=≤<=*x*,<=*y*<=≤<=1018, 1<=≤<=*l*<=≤<=*r*<=≤<=1018). | Print the maximum length of The Golden Age within the interval [*l*,<=*r*].
If all years in the interval [*l*,<=*r*] are unlucky then print 0. | [
"2 3 1 10\n",
"3 5 10 22\n",
"2 3 3 5\n"
] | [
"1\n",
"8\n",
"0\n"
] | In the first example the unlucky years are 2, 3, 4, 5, 7, 9 and 10. So maximum length of The Golden Age is achived in the intervals [1, 1], [6, 6] and [8, 8].
In the second example the longest Golden Age is the interval [15, 22]. | 0 | [
{
"input": "2 3 1 10",
"output": "1"
},
{
"input": "3 5 10 22",
"output": "8"
},
{
"input": "2 3 3 5",
"output": "0"
},
{
"input": "2 2 1 10",
"output": "1"
},
{
"input": "2 2 1 1000000",
"output": "213568"
},
{
"input": "2 2 1 1000000000000000000",
... | 1,629,121,040 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 18 | 109 | 22,323,200 | overlap = lambda a, b: min(a[1], b[1]) - max(a[0], b[0]) + 1
x, y, l, r = map(int, input().split())
curx, dis, ans = 1, {1, 10 ** 18 + 5}, 0
while curx <= r:
cury = 1
while cury + curx <= r:
dis.add(curx + cury)
cury *= y
curx *= x
dis = sorted(dis)
for i in range(1, len(dis)):... | Title: The Golden Age
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Unlucky year in Berland is such a year that its number *n* can be represented as *n*<==<=*x**a*<=+<=*y**b*, where *a* and *b* are non-negative integer numbers.
For example, if *x*<==<=2 and *y*<==<=3 then the years 4 a... | ```python
overlap = lambda a, b: min(a[1], b[1]) - max(a[0], b[0]) + 1
x, y, l, r = map(int, input().split())
curx, dis, ans = 1, {1, 10 ** 18 + 5}, 0
while curx <= r:
cury = 1
while cury + curx <= r:
dis.add(curx + cury)
cury *= y
curx *= x
dis = sorted(dis)
for i in range(1, ... | 0 | |
2 | A | Winner | PROGRAMMING | 1,500 | [
"hashing",
"implementation"
] | A. Winner | 1 | 64 | The winner of the card game popular in Berland "Berlogging" is determined according to the following rules. If at the end of the game there is only one player with the maximum number of points, he is the winner. The situation becomes more difficult if the number of such players is more than one. During each round a pla... | The first line contains an integer number *n* (1<=<=≤<=<=*n*<=<=≤<=<=1000), *n* is the number of rounds played. Then follow *n* lines, containing the information about the rounds in "name score" format in chronological order, where name is a string of lower-case Latin letters with the length from 1 to 32, and score is ... | Print the name of the winner. | [
"3\nmike 3\nandrew 5\nmike 2\n",
"3\nandrew 3\nandrew 2\nmike 5\n"
] | [
"andrew\n",
"andrew\n"
] | none | 0 | [
{
"input": "3\nmike 3\nandrew 5\nmike 2",
"output": "andrew"
},
{
"input": "3\nandrew 3\nandrew 2\nmike 5",
"output": "andrew"
},
{
"input": "5\nkaxqybeultn -352\nmgochgrmeyieyskhuourfg -910\nkaxqybeultn 691\nmgochgrmeyieyskhuourfg -76\nkaxqybeultn -303",
"output": "kaxqybeultn"
},... | 1,620,095,870 | 2,147,483,647 | PyPy 3 | OK | TESTS | 20 | 248 | 1,843,200 | from collections import OrderedDict
n = int(input())
names_score_dict = OrderedDict()
lis = []
for _ in range(n):
name, score = input().split()
names_score_dict[name] = names_score_dict.get(name, 0) + int(score)
lis += [(names_score_dict[name], name)]
m = max(names_score_dict.values())
for v, k... | Title: Winner
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
The winner of the card game popular in Berland "Berlogging" is determined according to the following rules. If at the end of the game there is only one player with the maximum number of points, he is the winner. The situation becomes... | ```python
from collections import OrderedDict
n = int(input())
names_score_dict = OrderedDict()
lis = []
for _ in range(n):
name, score = input().split()
names_score_dict[name] = names_score_dict.get(name, 0) + int(score)
lis += [(names_score_dict[name], name)]
m = max(names_score_dict.values())... | 3.862267 |
394 | A | Counting Sticks | PROGRAMMING | 0 | [
"brute force",
"implementation"
] | null | null | When new students come to the Specialized Educational and Scientific Centre (SESC) they need to start many things from the beginning. Sometimes the teachers say (not always unfairly) that we cannot even count. So our teachers decided to teach us arithmetics from the start. And what is the best way to teach students add... | The single line contains the initial expression. It is guaranteed that the expression looks like *A*<=+<=*B*<==<=*C*, where 1<=≤<=*A*,<=*B*,<=*C*<=≤<=100. | If there isn't a way to shift the stick so the expression becomes correct, print on a single line "Impossible" (without the quotes). If there is a way, print the resulting expression. Follow the format of the output from the test samples. Don't print extra space characters.
If there are multiple correct answers, print... | [
"||+|=|||||\n",
"|||||+||=||\n",
"|+|=||||||\n",
"||||+||=||||||\n"
] | [
"|||+|=||||\n",
"Impossible\n",
"Impossible\n",
"||||+||=||||||\n"
] | In the first sample we can shift stick from the third group of sticks to the first one.
In the second sample we cannot shift vertical stick from + sign to the second group of sticks. So we cannot make a - sign.
There is no answer in the third sample because we cannot remove sticks from the expression.
In the forth s... | 500 | [
{
"input": "||+|=|||||",
"output": "|||+|=||||"
},
{
"input": "|||||+||=||",
"output": "Impossible"
},
{
"input": "|+|=||||||",
"output": "Impossible"
},
{
"input": "||||+||=||||||",
"output": "||||+||=||||||"
},
{
"input": "||||||||||||+|||||||||||=||||||||||||||... | 1,569,592,877 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 7 | 139 | 102,400 | __author__ = 'Esfandiar'
s1,s2 = input().split('=')
a = s1.count('|')
b = s2.count('|')
if a == b:
print(s1+'='+s2)
elif abs(a-b) != 2:
print('Impossible')
else:
if a < b:
print(s1+'|'+'='+s2[:len(s2)-1])
else:
q1,q2=s1.split('+')
if q1.count('|') == 1:
print(s1[:len(... | Title: Counting Sticks
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
When new students come to the Specialized Educational and Scientific Centre (SESC) they need to start many things from the beginning. Sometimes the teachers say (not always unfairly) that we cannot even count. So our te... | ```python
__author__ = 'Esfandiar'
s1,s2 = input().split('=')
a = s1.count('|')
b = s2.count('|')
if a == b:
print(s1+'='+s2)
elif abs(a-b) != 2:
print('Impossible')
else:
if a < b:
print(s1+'|'+'='+s2[:len(s2)-1])
else:
q1,q2=s1.split('+')
if q1.count('|') == 1:
prin... | 0 | |
765 | B | Code obfuscation | PROGRAMMING | 1,100 | [
"greedy",
"implementation",
"strings"
] | null | null | Kostya likes Codeforces contests very much. However, he is very disappointed that his solutions are frequently hacked. That's why he decided to obfuscate (intentionally make less readable) his code before upcoming contest.
To obfuscate the code, Kostya first looks at the first variable name used in his program and rep... | In the only line of input there is a string *S* of lowercase English letters (1<=≤<=|*S*|<=≤<=500) — the identifiers of a program with removed whitespace characters. | If this program can be a result of Kostya's obfuscation, print "YES" (without quotes), otherwise print "NO". | [
"abacaba\n",
"jinotega\n"
] | [
"YES\n",
"NO\n"
] | In the first sample case, one possible list of identifiers would be "number string number character number string number". Here how Kostya would obfuscate the program:
- replace all occurences of number with a, the result would be "a string a character a string a",- replace all occurences of string with b, the result... | 1,000 | [
{
"input": "abacaba",
"output": "YES"
},
{
"input": "jinotega",
"output": "NO"
},
{
"input": "aaaaaaaaaaa",
"output": "YES"
},
{
"input": "aba",
"output": "YES"
},
{
"input": "bab",
"output": "NO"
},
{
"input": "a",
"output": "YES"
},
{
"in... | 1,516,955,127 | 1,587 | Python 3 | WRONG_ANSWER | TESTS | 11 | 77 | 5,734,400 | from collections import OrderedDict
s = input()
print('YES' if ''.join(list(OrderedDict.fromkeys(list(s)))) in 'abcdefghijklmnopqrstuvwxyz' else 'NO')
| Title: Code obfuscation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Kostya likes Codeforces contests very much. However, he is very disappointed that his solutions are frequently hacked. That's why he decided to obfuscate (intentionally make less readable) his code before upcoming cont... | ```python
from collections import OrderedDict
s = input()
print('YES' if ''.join(list(OrderedDict.fromkeys(list(s)))) in 'abcdefghijklmnopqrstuvwxyz' else 'NO')
``` | 0 | |
670 | A | Holidays | PROGRAMMING | 900 | [
"brute force",
"constructive algorithms",
"greedy",
"math"
] | null | null | On the planet Mars a year lasts exactly *n* days (there are no leap years on Mars). But Martians have the same weeks as earthlings — 5 work days and then 2 days off. Your task is to determine the minimum possible and the maximum possible number of days off per year on Mars. | The first line of the input contains a positive integer *n* (1<=≤<=*n*<=≤<=1<=000<=000) — the number of days in a year on Mars. | Print two integers — the minimum possible and the maximum possible number of days off per year on Mars. | [
"14\n",
"2\n"
] | [
"4 4\n",
"0 2\n"
] | In the first sample there are 14 days in a year on Mars, and therefore independently of the day a year starts with there will be exactly 4 days off .
In the second sample there are only 2 days in a year on Mars, and they can both be either work days or days off. | 500 | [
{
"input": "14",
"output": "4 4"
},
{
"input": "2",
"output": "0 2"
},
{
"input": "1",
"output": "0 1"
},
{
"input": "3",
"output": "0 2"
},
{
"input": "4",
"output": "0 2"
},
{
"input": "5",
"output": "0 2"
},
{
"input": "6",
"output":... | 1,667,257,364 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 30 | 0 | n=int(input())
c=((n//7)*2)
print(c,(n%7)+c) | Title: Holidays
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
On the planet Mars a year lasts exactly *n* days (there are no leap years on Mars). But Martians have the same weeks as earthlings — 5 work days and then 2 days off. Your task is to determine the minimum possible and the maxim... | ```python
n=int(input())
c=((n//7)*2)
print(c,(n%7)+c)
``` | 0 | |
279 | B | Books | PROGRAMMING | 1,400 | [
"binary search",
"brute force",
"implementation",
"two pointers"
] | null | null | When Valera has got some free time, he goes to the library to read some books. Today he's got *t* free minutes to read. That's why Valera took *n* books in the library and for each book he estimated the time he is going to need to read it. Let's number the books by integers from 1 to *n*. Valera needs *a**i* minutes to... | The first line contains two integers *n* and *t* (1<=≤<=*n*<=≤<=105; 1<=≤<=*t*<=≤<=109) — the number of books and the number of free minutes Valera's got. The second line contains a sequence of *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=104), where number *a**i* shows the number of minutes that the boy n... | Print a single integer — the maximum number of books Valera can read. | [
"4 5\n3 1 2 1\n",
"3 3\n2 2 3\n"
] | [
"3\n",
"1\n"
] | none | 1,000 | [
{
"input": "4 5\n3 1 2 1",
"output": "3"
},
{
"input": "3 3\n2 2 3",
"output": "1"
},
{
"input": "1 3\n5",
"output": "0"
},
{
"input": "1 10\n4",
"output": "1"
},
{
"input": "2 10\n6 4",
"output": "2"
},
{
"input": "6 10\n2 3 4 2 1 1",
"output": "4... | 1,671,997,748 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 38 | 186 | 14,131,200 | n,t=map(int,input().split())
arr=list(map(int,input().split()))
psum=[0]
for i in range(n):
psum.append(psum[i]+arr[i])
bmax=0
p1=0
p2=1
while True:
if psum[p2]-psum[p1]<=t:
if p2-p1>bmax:
bmax=p2-p1
if p2==n:
break
else:
p2+=1
else:
if p2-... | Title: Books
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
When Valera has got some free time, he goes to the library to read some books. Today he's got *t* free minutes to read. That's why Valera took *n* books in the library and for each book he estimated the time he is going to need t... | ```python
n,t=map(int,input().split())
arr=list(map(int,input().split()))
psum=[0]
for i in range(n):
psum.append(psum[i]+arr[i])
bmax=0
p1=0
p2=1
while True:
if psum[p2]-psum[p1]<=t:
if p2-p1>bmax:
bmax=p2-p1
if p2==n:
break
else:
p2+=1
else:
... | 3 | |
0 | none | none | none | 0 | [
"none"
] | null | null | One day Natalia was walking in the woods when she met a little mushroom gnome. The gnome told her the following story:
Everybody knows that the mushroom gnomes' power lies in the magic mushrooms that grow in the native woods of the gnomes. There are *n* trees and *m* magic mushrooms in the woods: the *i*-th tree grows... | The first line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=105, 1<=≤<=*m*<=≤<=104) — the number of trees and mushrooms, respectively.
Each of the next *n* lines contain four integers — *a**i*, *h**i*, *l**i*, *r**i* (|*a**i*|<=≤<=109, 1<=≤<=*h**i*<=≤<=109, 0<=≤<=*l**i*,<=*r**i*,<=*l**i*<=+<=*r**i*<=≤<=100) which ... | Print a real number — the expectation of the total magical power of the surviving mushrooms. The result is accepted with relative or absolute accuracy 10<=-<=4. | [
"1 1\n2 2 50 50\n1 1\n",
"2 1\n2 2 50 50\n4 2 50 50\n3 1\n"
] | [
"0.5000000000\n",
"0.2500000000\n"
] | It is believed that the mushroom with the coordinate *x* belongs to the right-open interval [*l*, *r*) if and only if *l* ≤ *x* < *r*. Similarly, the mushroom with the coordinate *x* belongs to the left-open interval (*l*, *r*] if and only if *l* < *x* ≤ *r*.
In the first test the mushroom survives with the prob... | 0 | [] | 1,689,447,846 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 31 | 0 | print("_RANDOM_GUESS_1689447846.407337")# 1689447846.407357 | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day Natalia was walking in the woods when she met a little mushroom gnome. The gnome told her the following story:
Everybody knows that the mushroom gnomes' power lies in the magic mushrooms that grow in the native woods of t... | ```python
print("_RANDOM_GUESS_1689447846.407337")# 1689447846.407357
``` | 0 | |
546 | A | Soldier and Bananas | PROGRAMMING | 800 | [
"brute force",
"implementation",
"math"
] | null | null | A soldier wants to buy *w* bananas in the shop. He has to pay *k* dollars for the first banana, 2*k* dollars for the second one and so on (in other words, he has to pay *i*·*k* dollars for the *i*-th banana).
He has *n* dollars. How many dollars does he have to borrow from his friend soldier to buy *w* bananas? | The first line contains three positive integers *k*,<=*n*,<=*w* (1<=<=≤<=<=*k*,<=*w*<=<=≤<=<=1000, 0<=≤<=*n*<=≤<=109), the cost of the first banana, initial number of dollars the soldier has and number of bananas he wants. | Output one integer — the amount of dollars that the soldier must borrow from his friend. If he doesn't have to borrow money, output 0. | [
"3 17 4\n"
] | [
"13"
] | none | 500 | [
{
"input": "3 17 4",
"output": "13"
},
{
"input": "1 2 1",
"output": "0"
},
{
"input": "1 1 1",
"output": "0"
},
{
"input": "1 5 6",
"output": "16"
},
{
"input": "1 1000000000 1",
"output": "0"
},
{
"input": "1000 0 1000",
"output": "500500000"
}... | 1,698,784,646 | 2,147,483,647 | Python 3 | OK | TESTS | 15 | 31 | 0 | x,y,z=map(int,input().split())
a=0
for i in range(1,z+1):
a+=i*x
if a>y:
print(a-y)
else:
print(0) | Title: Soldier and Bananas
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A soldier wants to buy *w* bananas in the shop. He has to pay *k* dollars for the first banana, 2*k* dollars for the second one and so on (in other words, he has to pay *i*·*k* dollars for the *i*-th banana).
He h... | ```python
x,y,z=map(int,input().split())
a=0
for i in range(1,z+1):
a+=i*x
if a>y:
print(a-y)
else:
print(0)
``` | 3 |
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.