contestId int64 0 1.01k | index stringclasses 40
values | name stringlengths 2 54 | type stringclasses 2
values | rating int64 0 3.4k | tags listlengths 0 7 | title stringclasses 393
values | time-limit stringclasses 7
values | memory-limit stringclasses 6
values | problem-description stringlengths 0 2.97k | input-specification stringlengths 4 1.87k | output-specification stringlengths 4 1.12k | demo-input listlengths 0 7 | demo-output listlengths 0 7 | note stringlengths 0 5.24k | points float64 0 3.5k | test_cases listlengths 0 402 | creationTimeSeconds int64 1.37B 1.7B | relativeTimeSeconds int64 8 2.15B | programmingLanguage stringclasses 3
values | verdict stringclasses 1
value | testset stringclasses 9
values | passedTestCount int64 1 402 | timeConsumedMillis int64 15 8.06k | memoryConsumedBytes int64 0 514M | code stringlengths 11 61.4k | prompt stringlengths 297 7.35k | response stringlengths 25 61.4k | score float64 2.82 3.99 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
190 | B | Surrounded | PROGRAMMING | 1,800 | [
"geometry"
] | null | null | So, the Berland is at war with its eternal enemy Flatland again, and Vasya, an accountant, was assigned to fulfil his duty to the nation.
Right now the situation in Berland is dismal β their both cities are surrounded! The armies of flatlanders stand on the borders of circles, the circles' centers are in the surround... | The input files consist of two lines. Each line represents the city and the flatland ring that surrounds it as three space-separated integers *x**i*, *y**i*, *r**i* (|*x**i*|,<=|*y**i*|<=β€<=104;Β 1<=β€<=*r**i*<=β€<=104) β the city's coordinates and the distance from the city to the flatlanders, correspondingly.
It is gua... | Print a single real number β the minimum detection radius of the described radar. The answer is considered correct if the absolute or relative error does not exceed 10<=-<=6. | [
"0 0 1\n6 0 3\n",
"-10 10 3\n10 -10 3\n"
] | [
"1.000000000000000",
"11.142135623730951"
] | The figure below shows the answer to the first sample. In this sample the best decision is to put the radar at point with coordinates (2,β0).
The figure below shows the answer for the second sample. In this sample the best decision is to put the radar at point with coordinates (0,β0). | 1,000 | [
{
"input": "0 0 1\n6 0 3",
"output": "1.000000000000000"
},
{
"input": "-10 10 3\n10 -10 3",
"output": "11.142135623730951"
},
{
"input": "2 1 3\n8 9 5",
"output": "1.000000000000000"
},
{
"input": "0 0 1\n-10 -10 9",
"output": "2.071067811865475"
},
{
"input": "1... | 1,517,054,393 | 3,593 | Python 3 | OK | TESTS | 43 | 62 | 5,632,000 | def dista(x1,y1,x2,y2):
dist=((x2-x1)**2+(y2-y1)**2)**(0.5)
return dist
x1,y1,r1=[int(i) for i in input().split()]
x2,y2,r2=[int(i) for i in input().split()]
if(dista(x1,y1,x2,y2)+min(r1,r2)<=max(r1,r2)):
ans=max(r1,r2)-dista(x1,y1,x2,y2)-min(r1,r2)
ans1=max(r1,r2)-min(r1,r2)
ans/=2
a... | Title: Surrounded
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
So, the Berland is at war with its eternal enemy Flatland again, and Vasya, an accountant, was assigned to fulfil his duty to the nation.
Right now the situation in Berland is dismal β their both cities are surrounded! The... | ```python
def dista(x1,y1,x2,y2):
dist=((x2-x1)**2+(y2-y1)**2)**(0.5)
return dist
x1,y1,r1=[int(i) for i in input().split()]
x2,y2,r2=[int(i) for i in input().split()]
if(dista(x1,y1,x2,y2)+min(r1,r2)<=max(r1,r2)):
ans=max(r1,r2)-dista(x1,y1,x2,y2)-min(r1,r2)
ans1=max(r1,r2)-min(r1,r2)
ans... | 3 | |
25 | A | IQ test | PROGRAMMING | 1,300 | [
"brute force"
] | A. IQ test | 2 | 256 | Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob β to check his answers, he needs a program that among the given *n* numbers finds one that i... | The first line contains integer *n* (3<=β€<=*n*<=β€<=100) β amount of numbers in the task. The second line contains *n* space-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these numbers differs from the others in evenness. | Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order. | [
"5\n2 4 7 8 10\n",
"4\n1 2 1 1\n"
] | [
"3\n",
"2\n"
] | none | 0 | [
{
"input": "5\n2 4 7 8 10",
"output": "3"
},
{
"input": "4\n1 2 1 1",
"output": "2"
},
{
"input": "3\n1 2 2",
"output": "1"
},
{
"input": "3\n100 99 100",
"output": "2"
},
{
"input": "3\n5 3 2",
"output": "3"
},
{
"input": "4\n43 28 1 91",
"output"... | 1,603,243,541 | 2,147,483,647 | Python 3 | OK | TESTS | 32 | 218 | 0 | n = int(input())
l = list(map(int, input().split()))
ch = []
nch = []
for i in range(len(l)):
if l[i] % 2 == 0:
ch.append(i)
else:
nch.append(i)
if len(ch) > len(nch):
print(nch[0] + 1)
else:
print(ch[0] + 1)
| Title: IQ test
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob β t... | ```python
n = int(input())
l = list(map(int, input().split()))
ch = []
nch = []
for i in range(len(l)):
if l[i] % 2 == 0:
ch.append(i)
else:
nch.append(i)
if len(ch) > len(nch):
print(nch[0] + 1)
else:
print(ch[0] + 1)
``` | 3.9455 |
29 | A | Spit Problem | PROGRAMMING | 1,000 | [
"brute force"
] | A. Spit Problem | 2 | 256 | In a Berland's zoo there is an enclosure with camels. It is known that camels like to spit. Bob watched these interesting animals for the whole day and registered in his notepad where each animal spitted. Now he wants to know if in the zoo there are two camels, which spitted at each other. Help him to solve this task.
... | The first line contains integer *n* (1<=β€<=*n*<=β€<=100) β the amount of camels in the zoo. Each of the following *n* lines contains two integers *x**i* and *d**i* (<=-<=104<=β€<=*x**i*<=β€<=104,<=1<=β€<=|*d**i*|<=β€<=2Β·104) β records in Bob's notepad. *x**i* is a position of the *i*-th camel, and *d**i* is a distance at wh... | If there are two camels, which spitted at each other, output YES. Otherwise, output NO. | [
"2\n0 1\n1 -1\n",
"3\n0 1\n1 1\n2 -2\n",
"5\n2 -10\n3 10\n0 5\n5 -5\n10 1\n"
] | [
"YES\n",
"NO\n",
"YES\n"
] | none | 500 | [
{
"input": "2\n0 1\n1 -1",
"output": "YES"
},
{
"input": "3\n0 1\n1 1\n2 -2",
"output": "NO"
},
{
"input": "5\n2 -10\n3 10\n0 5\n5 -5\n10 1",
"output": "YES"
},
{
"input": "10\n-9897 -1144\n-4230 -6350\n2116 -3551\n-3635 4993\n3907 -9071\n-2362 4120\n-6542 984\n5807 3745\n759... | 1,398,013,455 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 124 | 307,200 | def main():
n = int(input())
c = [tuple(map(int,input().split())) for i in range(n)]
pairs = [(a,b) for a in c for b in c]
for (a,b) in pairs:
if a[0] + a[1] == b[0] and b[0] + b[1] == a[0]:
return 'YES'
return 'NO'
print(main())
| Title: Spit Problem
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
In a Berland's zoo there is an enclosure with camels. It is known that camels like to spit. Bob watched these interesting animals for the whole day and registered in his notepad where each animal spitted. Now he wants to know ... | ```python
def main():
n = int(input())
c = [tuple(map(int,input().split())) for i in range(n)]
pairs = [(a,b) for a in c for b in c]
for (a,b) in pairs:
if a[0] + a[1] == b[0] and b[0] + b[1] == a[0]:
return 'YES'
return 'NO'
print(main())
``` | 3.968428 |
348 | A | Mafia | PROGRAMMING | 1,600 | [
"binary search",
"math",
"sortings"
] | null | null | One day *n* friends gathered together to play "Mafia". During each round of the game some player must be the supervisor and other *n*<=-<=1 people take part in the game. For each person we know in how many rounds he wants to be a player, not the supervisor: the *i*-th person wants to play *a**i* rounds. What is the min... | The first line contains integer *n* (3<=β€<=*n*<=β€<=105). The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=β€<=*a**i*<=β€<=109) β the *i*-th number in the list is the number of rounds the *i*-th person wants to play. | In a single line print a single integer β the minimum number of game rounds the friends need to let the *i*-th person play at least *a**i* rounds.
Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier. | [
"3\n3 2 2\n",
"4\n2 2 2 2\n"
] | [
"4\n",
"3\n"
] | You don't need to know the rules of "Mafia" to solve this problem. If you're curious, it's a game Russia got from the Soviet times: http://en.wikipedia.org/wiki/Mafia_(party_game). | 500 | [
{
"input": "3\n3 2 2",
"output": "4"
},
{
"input": "4\n2 2 2 2",
"output": "3"
},
{
"input": "7\n9 7 7 8 8 7 8",
"output": "9"
},
{
"input": "10\n13 12 10 13 13 14 10 10 12 12",
"output": "14"
},
{
"input": "10\n94 96 91 95 99 94 96 92 95 99",
"output": "106"
... | 1,628,967,102 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 248 | 15,872,000 | n=int(input())
lista=list(map(int,input().split()))
MaxValue, SumLista=max(lista), sum(lista)
r=n-2
for i in lista:
r += i
#esp=SumLista+n-2
calc=int(r//(n-1))
print(max(MaxValue, calc))
| Title: Mafia
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day *n* friends gathered together to play "Mafia". During each round of the game some player must be the supervisor and other *n*<=-<=1 people take part in the game. For each person we know in how many rounds he wants to be a... | ```python
n=int(input())
lista=list(map(int,input().split()))
MaxValue, SumLista=max(lista), sum(lista)
r=n-2
for i in lista:
r += i
#esp=SumLista+n-2
calc=int(r//(n-1))
print(max(MaxValue, calc))
``` | 3 | |
258 | A | Little Elephant and Bits | PROGRAMMING | 1,100 | [
"greedy",
"math"
] | null | null | The Little Elephant has an integer *a*, written in the binary notation. He wants to write this number on a piece of paper.
To make sure that the number *a* fits on the piece of paper, the Little Elephant ought to delete exactly one any digit from number *a* in the binary record. At that a new number appears. It consis... | The single line contains integer *a*, written in the binary notation without leading zeroes. This number contains more than 1 and at most 105 digits. | In the single line print the number that is written without leading zeroes in the binary notation β the answer to the problem. | [
"101\n",
"110010\n"
] | [
"11\n",
"11010\n"
] | In the first sample the best strategy is to delete the second digit. That results in number 11<sub class="lower-index">2</sub>β=β3<sub class="lower-index">10</sub>.
In the second sample the best strategy is to delete the third or fourth digits β that results in number 11010<sub class="lower-index">2</sub>β=β26<sub cla... | 500 | [
{
"input": "101",
"output": "11"
},
{
"input": "110010",
"output": "11010"
},
{
"input": "10000",
"output": "1000"
},
{
"input": "1111111110",
"output": "111111111"
},
{
"input": "10100101011110101",
"output": "1100101011110101"
},
{
"input": "11101001... | 1,564,173,369 | 2,147,483,647 | Python 3 | OK | TESTS | 37 | 218 | 409,600 | n = input()
loc = 0
for i in range(len(n)):
if n[i] == '0':
loc = i
break
ans = n[:loc] + n[loc+1:]
print(ans) | Title: Little Elephant and Bits
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Little Elephant has an integer *a*, written in the binary notation. He wants to write this number on a piece of paper.
To make sure that the number *a* fits on the piece of paper, the Little Elephant ought... | ```python
n = input()
loc = 0
for i in range(len(n)):
if n[i] == '0':
loc = i
break
ans = n[:loc] + n[loc+1:]
print(ans)
``` | 3 | |
777 | C | Alyona and Spreadsheet | PROGRAMMING | 1,600 | [
"binary search",
"data structures",
"dp",
"greedy",
"implementation",
"two pointers"
] | null | null | During the lesson small girl Alyona works with one famous spreadsheet computer program and learns how to edit tables.
Now she has a table filled with integers. The table consists of *n* rows and *m* columns. By *a**i*,<=*j* we will denote the integer located at the *i*-th row and the *j*-th column. We say that the tab... | The first line of the input contains two positive integers *n* and *m* (1<=β€<=*n*Β·*m*<=β€<=100<=000)Β β the number of rows and the number of columns in the table respectively. Note that your are given a constraint that bound the product of these two integers, i.e. the number of elements in the table.
Each of the followi... | Print "Yes" to the *i*-th line of the output if the table consisting of rows from *l**i* to *r**i* inclusive is sorted in non-decreasing order in at least one column. Otherwise, print "No". | [
"5 4\n1 2 3 5\n3 1 3 2\n4 5 2 3\n5 5 3 2\n4 4 3 4\n6\n1 1\n2 5\n4 5\n3 5\n1 3\n1 5\n"
] | [
"Yes\nNo\nYes\nYes\nYes\nNo\n"
] | In the sample, the whole table is not sorted in any column. However, rows 1β3 are sorted in column 1, while rows 4β5 are sorted in column 3. | 1,500 | [
{
"input": "5 4\n1 2 3 5\n3 1 3 2\n4 5 2 3\n5 5 3 2\n4 4 3 4\n6\n1 1\n2 5\n4 5\n3 5\n1 3\n1 5",
"output": "Yes\nNo\nYes\nYes\nYes\nNo"
},
{
"input": "1 1\n1\n1\n1 1",
"output": "Yes"
},
{
"input": "10 1\n523130301\n127101624\n15573616\n703140639\n628818570\n957494759\n161270109\n38686565... | 1,623,138,393 | 2,147,483,647 | PyPy 3 | OK | TESTS | 114 | 498 | 16,384,000 | ###### ### ####### ####### ## # ##### ### #####
# # # # # # # # # # # # # ###
# # # # # # # # # # # # # ###
###### ######### # # # # # # ... | Title: Alyona and Spreadsheet
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
During the lesson small girl Alyona works with one famous spreadsheet computer program and learns how to edit tables.
Now she has a table filled with integers. The table consists of *n* rows and *m* columns. By ... | ```python
###### ### ####### ####### ## # ##### ### #####
# # # # # # # # # # # # # ###
# # # # # # # # # # # # # ###
###### ######### # # # #... | 3 | |
271 | A | Beautiful Year | PROGRAMMING | 800 | [
"brute force"
] | null | null | It seems like the year of 2013 came only yesterday. Do you know a curious fact? The year of 2013 is the first year after the old 1987 with only distinct digits.
Now you are suggested to solve the following problem: given a year number, find the minimum year number which is strictly larger than the given one and has on... | The single line contains integer *y* (1000<=β€<=*y*<=β€<=9000) β the year number. | Print a single integer β the minimum year number that is strictly larger than *y* and all it's digits are distinct. It is guaranteed that the answer exists. | [
"1987\n",
"2013\n"
] | [
"2013\n",
"2014\n"
] | none | 500 | [
{
"input": "1987",
"output": "2013"
},
{
"input": "2013",
"output": "2014"
},
{
"input": "1000",
"output": "1023"
},
{
"input": "1001",
"output": "1023"
},
{
"input": "1234",
"output": "1235"
},
{
"input": "5555",
"output": "5601"
},
{
"inp... | 1,690,478,980 | 2,147,483,647 | Python 3 | OK | TESTS | 27 | 92 | 0 | s = int(input()) + 1
while len(set(str(s)))<4:s+=1
print(s) | Title: Beautiful Year
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
It seems like the year of 2013 came only yesterday. Do you know a curious fact? The year of 2013 is the first year after the old 1987 with only distinct digits.
Now you are suggested to solve the following problem: give... | ```python
s = int(input()) + 1
while len(set(str(s)))<4:s+=1
print(s)
``` | 3 | |
0 | none | none | none | 0 | [
"none"
] | null | null | You are given two lists of non-zero digits.
Let's call an integer pretty if its (base 10) representation has at least one digit from the first list and at least one digit from the second list. What is the smallest positive pretty integer? | The first line contains two integers *n* and *m* (1<=β€<=*n*,<=*m*<=β€<=9) β the lengths of the first and the second lists, respectively.
The second line contains *n* distinct digits *a*1,<=*a*2,<=...,<=*a**n* (1<=β€<=*a**i*<=β€<=9) β the elements of the first list.
The third line contains *m* distinct digits *b*1,<=*b*2... | Print the smallest pretty integer. | [
"2 3\n4 2\n5 7 6\n",
"8 8\n1 2 3 4 5 6 7 8\n8 7 6 5 4 3 2 1\n"
] | [
"25\n",
"1\n"
] | In the first example 25, 46, 24567 are pretty, as well as many other integers. The smallest among them is 25. 42 and 24 are not pretty because they don't have digits from the second list.
In the second example all integers that have at least one digit different from 9 are pretty. It's obvious that the smallest among t... | 0 | [
{
"input": "2 3\n4 2\n5 7 6",
"output": "25"
},
{
"input": "8 8\n1 2 3 4 5 6 7 8\n8 7 6 5 4 3 2 1",
"output": "1"
},
{
"input": "1 1\n9\n1",
"output": "19"
},
{
"input": "9 1\n5 4 2 3 6 1 7 9 8\n9",
"output": "9"
},
{
"input": "5 3\n7 2 5 8 6\n3 1 9",
"output"... | 1,508,056,793 | 2,093 | Python 3 | OK | TESTS | 52 | 62 | 5,529,600 | x,y = map(int,input().split())
lst1 = []
lst2 = []
num1 = map(int,input().split())
num2 = map(int,input().split())
for a in num1:
lst1.append(a)
for b in num2:
lst2.append(b)
lst1.sort()
lst2.sort()
intersec = []
for x in range(0,len(lst1)):
for y in range(0,len(lst2)):
if ... | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given two lists of non-zero digits.
Let's call an integer pretty if its (base 10) representation has at least one digit from the first list and at least one digit from the second list. What is the smallest positive pretty... | ```python
x,y = map(int,input().split())
lst1 = []
lst2 = []
num1 = map(int,input().split())
num2 = map(int,input().split())
for a in num1:
lst1.append(a)
for b in num2:
lst2.append(b)
lst1.sort()
lst2.sort()
intersec = []
for x in range(0,len(lst1)):
for y in range(0,len(lst2)):
... | 3 | |
911 | B | Two Cakes | PROGRAMMING | 1,200 | [
"binary search",
"brute force",
"implementation"
] | null | null | It's New Year's Eve soon, so Ivan decided it's high time he started setting the table. Ivan has bought two cakes and cut them into pieces: the first cake has been cut into *a* pieces, and the second one β into *b* pieces.
Ivan knows that there will be *n* people at the celebration (including himself), so Ivan has set ... | The first line contains three integers *n*, *a* and *b* (1<=β€<=*a*,<=*b*<=β€<=100, 2<=β€<=*n*<=β€<=*a*<=+<=*b*) β the number of plates, the number of pieces of the first cake, and the number of pieces of the second cake, respectively. | Print the maximum possible number *x* such that Ivan can distribute the cake in such a way that each plate will contain at least *x* pieces of cake. | [
"5 2 3\n",
"4 7 10\n"
] | [
"1\n",
"3\n"
] | In the first example there is only one way to distribute cakes to plates, all of them will have 1 cake on it.
In the second example you can have two plates with 3 and 4 pieces of the first cake and two plates both with 5 pieces of the second cake. Minimal number of pieces is 3. | 0 | [
{
"input": "5 2 3",
"output": "1"
},
{
"input": "4 7 10",
"output": "3"
},
{
"input": "100 100 100",
"output": "2"
},
{
"input": "10 100 3",
"output": "3"
},
{
"input": "2 9 29",
"output": "9"
},
{
"input": "4 6 10",
"output": "3"
},
{
"inp... | 1,580,570,076 | 2,147,483,647 | PyPy 3 | OK | TESTS | 135 | 156 | 0 | n,a,b = [int(i) for i in input().split()]
maxi = -1
for i in range(1,n):
if min(a//i,b//(n-i))>maxi:
maxi = int(min(a//i,b//(n-i)))
print(maxi)
| Title: Two Cakes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
It's New Year's Eve soon, so Ivan decided it's high time he started setting the table. Ivan has bought two cakes and cut them into pieces: the first cake has been cut into *a* pieces, and the second one β into *b* pieces.
Iv... | ```python
n,a,b = [int(i) for i in input().split()]
maxi = -1
for i in range(1,n):
if min(a//i,b//(n-i))>maxi:
maxi = int(min(a//i,b//(n-i)))
print(maxi)
``` | 3 | |
845 | C | Two TVs | PROGRAMMING | 1,500 | [
"data structures",
"greedy",
"sortings"
] | null | null | Polycarp is a great fan of television.
He wrote down all the TV programs he is interested in for today. His list contains *n* shows, *i*-th of them starts at moment *l**i* and ends at moment *r**i*.
Polycarp owns two TVs. He can watch two different shows simultaneously with two TVs but he can only watch one show at a... | The first line contains one integer *n* (1<=β€<=*n*<=β€<=2Β·105) β the number of shows.
Each of the next *n* lines contains two integers *l**i* and *r**i* (0<=β€<=*l**i*<=<<=*r**i*<=β€<=109) β starting and ending time of *i*-th show. | If Polycarp is able to check out all the shows using only two TVs then print "YES" (without quotes). Otherwise, print "NO" (without quotes). | [
"3\n1 2\n2 3\n4 5\n",
"4\n1 2\n2 3\n2 3\n1 2\n"
] | [
"YES\n",
"NO\n"
] | none | 0 | [
{
"input": "3\n1 2\n2 3\n4 5",
"output": "YES"
},
{
"input": "4\n1 2\n2 3\n2 3\n1 2",
"output": "NO"
},
{
"input": "4\n0 1\n1 2\n2 3\n3 4",
"output": "YES"
},
{
"input": "3\n1 2\n2 3\n2 4",
"output": "NO"
},
{
"input": "3\n0 100\n0 100\n0 100",
"output": "NO"
... | 1,544,719,862 | 2,147,483,647 | PyPy 3 | OK | TESTS | 58 | 1,028 | 20,377,600 | from sys import stdin
n=int(stdin.readline().strip())
s=[tuple(map(int,stdin.readline().strip().split())) for i in range(n)]
s.sort()
t1=-1,-1
t2=-1,-1
for i in s:
if i[0]>t1[1]:
t1=i
elif i[0]>t2[1]:
t2=i
else:
print("NO")
exit(0)
print("YES")
| Title: Two TVs
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp is a great fan of television.
He wrote down all the TV programs he is interested in for today. His list contains *n* shows, *i*-th of them starts at moment *l**i* and ends at moment *r**i*.
Polycarp owns two TVs. He ... | ```python
from sys import stdin
n=int(stdin.readline().strip())
s=[tuple(map(int,stdin.readline().strip().split())) for i in range(n)]
s.sort()
t1=-1,-1
t2=-1,-1
for i in s:
if i[0]>t1[1]:
t1=i
elif i[0]>t2[1]:
t2=i
else:
print("NO")
exit(0)
print("YES")
``` | 3 | |
818 | A | Diplomas and Certificates | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | There are *n* students who have taken part in an olympiad. Now it's time to award the students.
Some of them will receive diplomas, some wiil get certificates, and others won't receive anything. Students with diplomas and certificates are called winners. But there are some rules of counting the number of diplomas and ... | The first (and the only) line of input contains two integers *n* and *k* (1<=β€<=*n*,<=*k*<=β€<=1012), where *n* is the number of students and *k* is the ratio between the number of certificates and the number of diplomas. | Output three numbers: the number of students with diplomas, the number of students with certificates and the number of students who are not winners in case when the number of winners is maximum possible.
It's possible that there are no winners. | [
"18 2\n",
"9 10\n",
"1000000000000 5\n",
"1000000000000 499999999999\n"
] | [
"3 6 9\n",
"0 0 9\n",
"83333333333 416666666665 500000000002\n",
"1 499999999999 500000000000\n"
] | none | 0 | [
{
"input": "18 2",
"output": "3 6 9"
},
{
"input": "9 10",
"output": "0 0 9"
},
{
"input": "1000000000000 5",
"output": "83333333333 416666666665 500000000002"
},
{
"input": "1000000000000 499999999999",
"output": "1 499999999999 500000000000"
},
{
"input": "1 1",... | 1,662,705,238 | 2,147,483,647 | Python 3 | OK | TESTS | 44 | 46 | 0 | def solution(n, k):
d = (n//2)//(k+1)
if d > 0:
return [d, k*d, n - (k+1)*d]
else:
return [0, 0, n]
n, k = [int(x) for x in input().strip().split(" ")]
ans = solution(n, k)
print(ans[0], ans[1], ans[2]) | Title: Diplomas and Certificates
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* students who have taken part in an olympiad. Now it's time to award the students.
Some of them will receive diplomas, some wiil get certificates, and others won't receive anything. Students with... | ```python
def solution(n, k):
d = (n//2)//(k+1)
if d > 0:
return [d, k*d, n - (k+1)*d]
else:
return [0, 0, n]
n, k = [int(x) for x in input().strip().split(" ")]
ans = solution(n, k)
print(ans[0], ans[1], ans[2])
``` | 3 | |
796 | A | Buying A House | PROGRAMMING | 800 | [
"brute force",
"implementation"
] | null | null | Zane the wizard had never loved anyone before, until he fell in love with a girl, whose name remains unknown to us.
The girl lives in house *m* of a village. There are *n* houses in that village, lining in a straight line from left to right: house 1, house 2, ..., house *n*. The village is also well-structured: house ... | The first line contains three integers *n*, *m*, and *k* (2<=β€<=*n*<=β€<=100, 1<=β€<=*m*<=β€<=*n*, 1<=β€<=*k*<=β€<=100)Β β the number of houses in the village, the house where the girl lives, and the amount of money Zane has (in dollars), respectively.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (0<=β€<=... | Print one integerΒ β the minimum distance, in meters, from the house where the girl Zane likes lives to the house Zane can buy. | [
"5 1 20\n0 27 32 21 19\n",
"7 3 50\n62 0 0 0 99 33 22\n",
"10 5 100\n1 0 1 0 0 0 0 0 1 1\n"
] | [
"40",
"30",
"20"
] | In the first sample, with *k*β=β20 dollars, Zane can buy only house 5. The distance from house *m*β=β1 to house 5 is 10β+β10β+β10β+β10β=β40 meters.
In the second sample, Zane can buy houses 6 and 7. It is better to buy house 6 than house 7, since house *m*β=β3 and house 6 are only 30 meters away, while house *m*β=β3 a... | 500 | [
{
"input": "5 1 20\n0 27 32 21 19",
"output": "40"
},
{
"input": "7 3 50\n62 0 0 0 99 33 22",
"output": "30"
},
{
"input": "10 5 100\n1 0 1 0 0 0 0 0 1 1",
"output": "20"
},
{
"input": "5 3 1\n1 1 0 0 1",
"output": "10"
},
{
"input": "5 5 5\n1 0 5 6 0",
"outpu... | 1,598,440,066 | 2,147,483,647 | Python 3 | OK | TESTS | 58 | 109 | 307,200 | n,m,k=map(int,input().split())
l=list(map(int,input().split()))
x=[]
y=[]
for i in range(n):
if l[i]==0:
continue
elif l[i]<=k:
x.append(i+1)
for i in range(len(x)):
if x[i]>m:
y.append(x[i]-m)
elif x[i]<m:
y.append(m-x[i])
print(min(y)*10) | Title: Buying A House
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Zane the wizard had never loved anyone before, until he fell in love with a girl, whose name remains unknown to us.
The girl lives in house *m* of a village. There are *n* houses in that village, lining in a straight li... | ```python
n,m,k=map(int,input().split())
l=list(map(int,input().split()))
x=[]
y=[]
for i in range(n):
if l[i]==0:
continue
elif l[i]<=k:
x.append(i+1)
for i in range(len(x)):
if x[i]>m:
y.append(x[i]-m)
elif x[i]<m:
y.append(m-x[i])
print(min(y)*10)
``` | 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,631,545,277 | 2,147,483,647 | PyPy 3 | OK | TESTS | 34 | 139 | 21,708,800 | a,b=[int(v) for v in input().split()]
sum=0
for i in range(a):
x,t=[v for v in input().split()]
t=int(t)
if x=="+": b+=t
else:
if b>=t: b-=t
else: sum+=1
print(b,sum) | 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
a,b=[int(v) for v in input().split()]
sum=0
for i in range(a):
x,t=[v for v in input().split()]
t=int(t)
if x=="+": b+=t
else:
if b>=t: b-=t
else: sum+=1
print(b,sum)
``` | 3 | |
381 | A | Sereja and Dima | PROGRAMMING | 800 | [
"greedy",
"implementation",
"two pointers"
] | null | null | Sereja and Dima play a game. The rules of the game are very simple. The players have *n* cards in a row. Each card contains a number, all numbers on the cards are distinct. The players take turns, Sereja moves first. During his turn a player can take one card: either the leftmost card in a row, or the rightmost one. Th... | The first line contains integer *n* (1<=β€<=*n*<=β€<=1000) β the number of cards on the table. The second line contains space-separated numbers on the cards from left to right. The numbers on the cards are distinct integers from 1 to 1000. | On a single line, print two integers. The first number is the number of Sereja's points at the end of the game, the second number is the number of Dima's points at the end of the game. | [
"4\n4 1 2 10\n",
"7\n1 2 3 4 5 6 7\n"
] | [
"12 5\n",
"16 12\n"
] | In the first sample Sereja will take cards with numbers 10 and 2, so Sereja's sum is 12. Dima will take cards with numbers 4 and 1, so Dima's sum is 5. | 500 | [
{
"input": "4\n4 1 2 10",
"output": "12 5"
},
{
"input": "7\n1 2 3 4 5 6 7",
"output": "16 12"
},
{
"input": "42\n15 29 37 22 16 5 26 31 6 32 19 3 45 36 33 14 25 20 48 7 42 11 24 28 9 18 8 21 47 17 38 40 44 4 35 1 43 39 41 27 12 13",
"output": "613 418"
},
{
"input": "43\n32 ... | 1,673,722,238 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 46 | 0 | n = int(input())
l = input().split()
for i in range(len(l)):
l[i] = int(l[i])
sereja_score = 0
dima_score = 0
for i in range(len(l)):
if i % 2 == 0:
l2 = [l[0], l[-1]]
l1 = max(l2)
l.remove((l1))
sereja_score += l1
elif i % 2 == 1:
l4 = [l[0], l[-1]]
l3 = ma... | Title: Sereja and Dima
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Sereja and Dima play a game. The rules of the game are very simple. The players have *n* cards in a row. Each card contains a number, all numbers on the cards are distinct. The players take turns, Sereja moves first. Du... | ```python
n = int(input())
l = input().split()
for i in range(len(l)):
l[i] = int(l[i])
sereja_score = 0
dima_score = 0
for i in range(len(l)):
if i % 2 == 0:
l2 = [l[0], l[-1]]
l1 = max(l2)
l.remove((l1))
sereja_score += l1
elif i % 2 == 1:
l4 = [l[0], l[-1]]
... | 3 | |
725 | A | Jumping Ball | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | In a new version of the famous Pinball game, one of the most important parts of the game field is a sequence of *n* bumpers. The bumpers are numbered with integers from 1 to *n* from left to right. There are two types of bumpers. They are denoted by the characters '<' and '>'. When the ball hits the bumper at pos... | The first line of the input contains a single integer *n* (1<=β€<=*n*<=β€<=200<=000)Β β the length of the sequence of bumpers. The second line contains the string, which consists of the characters '<' and '>'. The character at the *i*-th position of this string corresponds to the type of the *i*-th bumper. | Print one integerΒ β the number of positions in the sequence such that the ball will eventually fall from the game field if it starts at that position. | [
"4\n<<><\n",
"5\n>>>>>\n",
"4\n>><<\n"
] | [
"2",
"5",
"0"
] | In the first sample, the ball will fall from the field if starts at position 1 or position 2.
In the second sample, any starting position will result in the ball falling from the field. | 500 | [
{
"input": "4\n<<><",
"output": "2"
},
{
"input": "5\n>>>>>",
"output": "5"
},
{
"input": "4\n>><<",
"output": "0"
},
{
"input": "3\n<<>",
"output": "3"
},
{
"input": "3\n<<<",
"output": "3"
},
{
"input": "3\n><<",
"output": "0"
},
{
"input... | 1,479,389,056 | 2,147,483,647 | Python 3 | OK | TESTS | 78 | 77 | 614,400 | if __name__ == '__main__':
n = int(input())
line = str(input())
num = 0
for it in line:
if it == '<':
num += 1
else:
break
for it in line[::-1]:
if it == '>':
num += 1
else:
break
print(num)
| Title: Jumping Ball
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In a new version of the famous Pinball game, one of the most important parts of the game field is a sequence of *n* bumpers. The bumpers are numbered with integers from 1 to *n* from left to right. There are two types of b... | ```python
if __name__ == '__main__':
n = int(input())
line = str(input())
num = 0
for it in line:
if it == '<':
num += 1
else:
break
for it in line[::-1]:
if it == '>':
num += 1
else:
break
print(num)
... | 3 | |
231 | A | Team | PROGRAMMING | 800 | [
"brute force",
"greedy"
] | null | null | One day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decided that they will implement a problem if at least two of them are sure about the solution.... | The first input line contains a single integer *n* (1<=β€<=*n*<=β€<=1000) β the number of problems in the contest. Then *n* lines contain three integers each, each integer is either 0 or 1. If the first number in the line equals 1, then Petya is sure about the problem's solution, otherwise he isn't sure. The second numbe... | Print a single integer β the number of problems the friends will implement on the contest. | [
"3\n1 1 0\n1 1 1\n1 0 0\n",
"2\n1 0 0\n0 1 1\n"
] | [
"2\n",
"1\n"
] | In the first sample Petya and Vasya are sure that they know how to solve the first problem and all three of them know how to solve the second problem. That means that they will write solutions for these problems. Only Petya is sure about the solution for the third problem, but that isn't enough, so the friends won't ta... | 500 | [
{
"input": "3\n1 1 0\n1 1 1\n1 0 0",
"output": "2"
},
{
"input": "2\n1 0 0\n0 1 1",
"output": "1"
},
{
"input": "1\n1 0 0",
"output": "0"
},
{
"input": "2\n1 0 0\n1 1 1",
"output": "1"
},
{
"input": "5\n1 0 0\n0 1 0\n1 1 1\n0 0 1\n0 0 0",
"output": "1"
},
... | 1,699,743,521 | 2,147,483,647 | Python 3 | OK | TESTS | 21 | 92 | 0 | # Input
n = int(input())
# Count the number of problems each friend is sure about
count_sure = 0
for _ in range(n):
p, v, t = map(int, input().split())
# Check if at least two friends are sure about the solution
if p + v + t >= 2:
count_sure += 1
# Output
print(count_sure)
| Title: Team
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decid... | ```python
# Input
n = int(input())
# Count the number of problems each friend is sure about
count_sure = 0
for _ in range(n):
p, v, t = map(int, input().split())
# Check if at least two friends are sure about the solution
if p + v + t >= 2:
count_sure += 1
# Output
print(count_sure)
... | 3 | |
519 | B | A and B and Compilation Errors | PROGRAMMING | 1,100 | [
"data structures",
"implementation",
"sortings"
] | null | null | A and B are preparing themselves for programming contests.
B loves to debug his code. But before he runs the solution and starts debugging, he has to first compile the code.
Initially, the compiler displayed *n* compilation errors, each of them is represented as a positive integer. After some effort, B managed to fix... | The first line of the input contains integer *n* (3<=β€<=*n*<=β€<=105) β the initial number of compilation errors.
The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=β€<=*a**i*<=β€<=109) β the errors the compiler displayed for the first time.
The third line contains *n*<=-<=1 space-sepa... | Print two numbers on a single line: the numbers of the compilation errors that disappeared after B made the first and the second correction, respectively. | [
"5\n1 5 8 123 7\n123 7 5 1\n5 1 7\n",
"6\n1 4 3 3 5 7\n3 7 5 4 3\n4 3 7 5\n"
] | [
"8\n123\n",
"1\n3\n"
] | In the first test sample B first corrects the error number 8, then the error number 123.
In the second test sample B first corrects the error number 1, then the error number 3. Note that if there are multiple errors with the same number, B can correct only one of them in one step. | 1,000 | [
{
"input": "5\n1 5 8 123 7\n123 7 5 1\n5 1 7",
"output": "8\n123"
},
{
"input": "6\n1 4 3 3 5 7\n3 7 5 4 3\n4 3 7 5",
"output": "1\n3"
},
{
"input": "3\n1 2 3\n3 2\n2",
"output": "1\n3"
},
{
"input": "10\n460626451 802090732 277246428 661369649 388684428 784303821 376287098 6... | 1,694,479,021 | 2,147,483,647 | Python 3 | OK | TESTS | 33 | 140 | 23,449,600 | from sys import stdin
input = stdin.readline
def main(data) -> None:
x = sum(data[0])
y = sum(data[1])
z = sum(data[2])
print(x-y)
print(y-z)
if __name__ == "__main__":
input()
main([list(map(int, input().split())) for _ in range(3)])
| Title: A and B and Compilation Errors
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A and B are preparing themselves for programming contests.
B loves to debug his code. But before he runs the solution and starts debugging, he has to first compile the code.
Initially, the compiler disp... | ```python
from sys import stdin
input = stdin.readline
def main(data) -> None:
x = sum(data[0])
y = sum(data[1])
z = sum(data[2])
print(x-y)
print(y-z)
if __name__ == "__main__":
input()
main([list(map(int, input().split())) for _ in range(3)])
``` | 3 | |
948 | A | Protect Sheep | PROGRAMMING | 900 | [
"brute force",
"dfs and similar",
"graphs",
"implementation"
] | null | null | Bob is a farmer. He has a large pasture with many sheep. Recently, he has lost some of them due to wolf attacks. He thus decided to place some shepherd dogs in such a way that all his sheep are protected.
The pasture is a rectangle consisting of *R*<=Γ<=*C* cells. Each cell is either empty, contains a sheep, a wolf or... | First line contains two integers *R* (1<=β€<=*R*<=β€<=500) and *C* (1<=β€<=*C*<=β€<=500), denoting the number of rows and the numbers of columns respectively.
Each of the following *R* lines is a string consisting of exactly *C* characters, representing one row of the pasture. Here, 'S' means a sheep, 'W' a wolf and '.' a... | If it is impossible to protect all sheep, output a single line with the word "No".
Otherwise, output a line with the word "Yes". Then print *R* lines, representing the pasture after placing dogs. Again, 'S' means a sheep, 'W' a wolf, 'D' is a dog and '.' an empty space. You are not allowed to move, remove or add a she... | [
"6 6\n..S...\n..S.W.\n.S....\n..W...\n...W..\n......\n",
"1 2\nSW\n",
"5 5\n.S...\n...S.\nS....\n...S.\n.S...\n"
] | [
"Yes\n..SD..\n..SDW.\n.SD...\n.DW...\nDD.W..\n......\n",
"No\n",
"Yes\n.S...\n...S.\nS.D..\n...S.\n.S...\n"
] | In the first example, we can split the pasture into two halves, one containing wolves and one containing sheep. Note that the sheep at (2,1) is safe, as wolves cannot move diagonally.
In the second example, there are no empty spots to put dogs that would guard the lone sheep.
In the third example, there are no wolves... | 500 | [
{
"input": "1 2\nSW",
"output": "No"
},
{
"input": "10 10\n....W.W.W.\n.........S\n.S.S...S..\nW.......SS\n.W..W.....\n.W...W....\nS..S...S.S\n....W...S.\n..S..S.S.S\nSS.......S",
"output": "Yes\nDDDDWDWDWD\nDDDDDDDDDS\nDSDSDDDSDD\nWDDDDDDDSS\nDWDDWDDDDD\nDWDDDWDDDD\nSDDSDDDSDS\nDDDDWDDDSD\nDDSD... | 1,520,698,194 | 2,094 | Python 3 | OK | TESTS | 98 | 217 | 6,144,000 | a,b = map(int, input().split())
anslist = [" "*(b+2)]
for i in range (a):
anslist.append(" "+ input() + " ")
anslist.append(" "*(b+2))
flag = 0
for k in range (1,a+1) :
p = anslist[k]
q = anslist[k+1]
r = anslist[k-1]
for j in range (1, b+1):
if (p[j] == "S" and p[j-1] == "W") or (p[j] == "S" and p[... | Title: Protect Sheep
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bob is a farmer. He has a large pasture with many sheep. Recently, he has lost some of them due to wolf attacks. He thus decided to place some shepherd dogs in such a way that all his sheep are protected.
The pasture is ... | ```python
a,b = map(int, input().split())
anslist = [" "*(b+2)]
for i in range (a):
anslist.append(" "+ input() + " ")
anslist.append(" "*(b+2))
flag = 0
for k in range (1,a+1) :
p = anslist[k]
q = anslist[k+1]
r = anslist[k-1]
for j in range (1, b+1):
if (p[j] == "S" and p[j-1] == "W") or (p[j] == ... | 3 | |
129 | A | Cookies | PROGRAMMING | 900 | [
"implementation"
] | null | null | Olga came to visit the twins Anna and Maria and saw that they have many cookies. The cookies are distributed into bags. As there are many cookies, Olga decided that it's no big deal if she steals a bag. However, she doesn't want the sisters to quarrel because of nothing when they divide the cookies. That's why Olga wan... | The first line contains the only integer *n* (1<=β€<=*n*<=β€<=100) β the number of cookie bags Anna and Maria have. The second line contains *n* integers *a**i* (1<=β€<=*a**i*<=β€<=100) β the number of cookies in the *i*-th bag. | Print in the only line the only number β the sought number of ways. If there are no such ways print 0. | [
"1\n1\n",
"10\n1 2 2 3 4 4 4 2 2 2\n",
"11\n2 2 2 2 2 2 2 2 2 2 99\n"
] | [
"1\n",
"8\n",
"1\n"
] | In the first sample Olga should take the only bag so that the twins ended up with the even number of cookies.
In the second sample Olga can take any of five bags with two cookies or any of three bags with four cookies β 5β+β3β=β8 ways in total.
In the third sample, no matter which bag with two cookies Olga chooses, t... | 500 | [
{
"input": "1\n1",
"output": "1"
},
{
"input": "10\n1 2 2 3 4 4 4 2 2 2",
"output": "8"
},
{
"input": "11\n2 2 2 2 2 2 2 2 2 2 99",
"output": "1"
},
{
"input": "2\n1 1",
"output": "0"
},
{
"input": "2\n2 2",
"output": "2"
},
{
"input": "2\n1 2",
"o... | 1,693,131,949 | 2,147,483,647 | Python 3 | OK | TESTS | 52 | 92 | 0 | n=int(input())
lis=list(map(int,input().strip().split()))
s=sum(lis)
if n==1:
print(1)
else:
c=0
nl=[]
if s%2==0:
for i in lis:
if i not in nl:
if i%2==0:
c=c+lis.count(i)
nl.append(i)
else:
for i in lis:
... | Title: Cookies
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Olga came to visit the twins Anna and Maria and saw that they have many cookies. The cookies are distributed into bags. As there are many cookies, Olga decided that it's no big deal if she steals a bag. However, she doesn't wan... | ```python
n=int(input())
lis=list(map(int,input().strip().split()))
s=sum(lis)
if n==1:
print(1)
else:
c=0
nl=[]
if s%2==0:
for i in lis:
if i not in nl:
if i%2==0:
c=c+lis.count(i)
nl.append(i)
else:
for ... | 3 | |
937 | A | Olympiad | PROGRAMMING | 800 | [
"implementation",
"sortings"
] | null | null | The recent All-Berland Olympiad in Informatics featured *n* participants with each scoring a certain amount of points.
As the head of the programming committee, you are to determine the set of participants to be awarded with diplomas with respect to the following criteria:
- At least one participant should get a di... | The first line contains a single integer *n* (1<=β€<=*n*<=β€<=100)Β β the number of participants.
The next line contains a sequence of *n* integers *a*1,<=*a*2,<=...,<=*a**n* (0<=β€<=*a**i*<=β€<=600)Β β participants' scores.
It's guaranteed that at least one participant has non-zero score. | Print a single integerΒ β the desired number of ways. | [
"4\n1 3 3 2\n",
"3\n1 1 1\n",
"4\n42 0 0 42\n"
] | [
"3\n",
"1\n",
"1\n"
] | There are three ways to choose a subset in sample case one.
1. Only participants with 3 points will get diplomas. 1. Participants with 2 or 3 points will get diplomas. 1. Everyone will get a diploma!
The only option in sample case two is to award everyone.
Note that in sample case three participants with zero sco... | 500 | [
{
"input": "4\n1 3 3 2",
"output": "3"
},
{
"input": "3\n1 1 1",
"output": "1"
},
{
"input": "4\n42 0 0 42",
"output": "1"
},
{
"input": "10\n1 0 1 0 1 0 0 0 0 1",
"output": "1"
},
{
"input": "10\n572 471 540 163 50 30 561 510 43 200",
"output": "10"
},
{
... | 1,617,091,599 | 2,147,483,647 | Python 3 | OK | TESTS | 21 | 62 | 0 | import sys
input = sys.stdin.readline
n = int(input())
a = [int(i) for i in input().split()]
res = [int(i) for i in a if i > 0]
print(len(set(res)))
| Title: Olympiad
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The recent All-Berland Olympiad in Informatics featured *n* participants with each scoring a certain amount of points.
As the head of the programming committee, you are to determine the set of participants to be awarded with ... | ```python
import sys
input = sys.stdin.readline
n = int(input())
a = [int(i) for i in input().split()]
res = [int(i) for i in a if i > 0]
print(len(set(res)))
``` | 3 | |
50 | A | Domino piling | PROGRAMMING | 800 | [
"greedy",
"math"
] | A. Domino piling | 2 | 256 | You are given a rectangular board of *M*<=Γ<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=Γ<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions:
1. Each domino completely covers ... | In a single line you are given two integers *M* and *N* β board sizes in squares (1<=β€<=*M*<=β€<=*N*<=β€<=16). | Output one number β the maximal number of dominoes, which can be placed. | [
"2 4\n",
"3 3\n"
] | [
"4\n",
"4\n"
] | none | 500 | [
{
"input": "2 4",
"output": "4"
},
{
"input": "3 3",
"output": "4"
},
{
"input": "1 5",
"output": "2"
},
{
"input": "1 6",
"output": "3"
},
{
"input": "1 15",
"output": "7"
},
{
"input": "1 16",
"output": "8"
},
{
"input": "2 5",
"outpu... | 1,611,482,840 | 2,147,483,647 | Python 3 | OK | TESTS | 35 | 154 | 0 | m,n=[int(x) for x in input().split()]
print((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((m*n)//2)
``` | 3.9615 |
9 | A | Die Roll | PROGRAMMING | 800 | [
"math",
"probabilities"
] | A. Die Roll | 1 | 64 | Yakko, Wakko and Dot, world-famous animaniacs, decided to rest from acting in cartoons, and take a leave to travel a bit. Yakko dreamt to go to Pennsylvania, his Motherland and the Motherland of his ancestors. Wakko thought about Tasmania, its beaches, sun and sea. Dot chose Transylvania as the most mysterious and unpr... | The only line of the input file contains two natural numbers Y and W β the results of Yakko's and Wakko's die rolls. | Output the required probability in the form of irreducible fraction in format Β«A/BΒ», where A β the numerator, and B β the denominator. If the required probability equals to zero, output Β«0/1Β». If the required probability equals to 1, output Β«1/1Β». | [
"4 2\n"
] | [
"1/2\n"
] | Dot will go to Transylvania, if she is lucky to roll 4, 5 or 6 points. | 0 | [
{
"input": "4 2",
"output": "1/2"
},
{
"input": "1 1",
"output": "1/1"
},
{
"input": "1 2",
"output": "5/6"
},
{
"input": "1 3",
"output": "2/3"
},
{
"input": "1 4",
"output": "1/2"
},
{
"input": "1 5",
"output": "1/3"
},
{
"input": "1 6",
... | 1,602,951,171 | 2,147,483,647 | Python 3 | OK | TESTS | 36 | 218 | 0 | def func (a, b):
if (b == 0):
return a
return func(b, a%b)
y, w = map(int, input().split())
a = 7 - max(y, w)
b = 6
c = func(a,b)
a /= c
b /= c
print("%d/%d"%(a, b))
| Title: Die Roll
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
Yakko, Wakko and Dot, world-famous animaniacs, decided to rest from acting in cartoons, and take a leave to travel a bit. Yakko dreamt to go to Pennsylvania, his Motherland and the Motherland of his ancestors. Wakko thought about T... | ```python
def func (a, b):
if (b == 0):
return a
return func(b, a%b)
y, w = map(int, input().split())
a = 7 - max(y, w)
b = 6
c = func(a,b)
a /= c
b /= c
print("%d/%d"%(a, b))
``` | 3.891 |
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,606,894,110 | 2,147,483,647 | PyPy 3 | OK | TESTS | 81 | 310 | 0 | X, Y, Z = 0, 0, 0
for _ in range(int(input())):
x, y, z = [int(j) for j in input().split()]
X += x
Y += y
Z += 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
X, Y, Z = 0, 0, 0
for _ in range(int(input())):
x, y, z = [int(j) for j in input().split()]
X += x
Y += y
Z += z
if X == 0 and Y == 0 and Z == 0:
print("YES")
else:
print("NO")
``` | 3.9225 |
437 | C | The Child and Toy | PROGRAMMING | 1,400 | [
"graphs",
"greedy",
"sortings"
] | null | null | On Children's Day, the child got a toy from Delayyy as a present. However, the child is so naughty that he can't wait to destroy the toy.
The toy consists of *n* parts and *m* ropes. Each rope links two parts, but every pair of parts is linked by at most one rope. To split the toy, the child must remove all its parts.... | The first line contains two integers *n* and *m* (1<=β€<=*n*<=β€<=1000; 0<=β€<=*m*<=β€<=2000). The second line contains *n* integers: *v*1,<=*v*2,<=...,<=*v**n* (0<=β€<=*v**i*<=β€<=105). Then followed *m* lines, each line contains two integers *x**i* and *y**i*, representing a rope from part *x**i* to part *y**i* (1<=β€<=*x**... | Output the minimum total energy the child should spend to remove all *n* parts of the toy. | [
"4 3\n10 20 30 40\n1 4\n1 2\n2 3\n",
"4 4\n100 100 100 100\n1 2\n2 3\n2 4\n3 4\n",
"7 10\n40 10 20 10 20 80 40\n1 5\n4 7\n4 5\n5 2\n5 7\n6 4\n1 6\n1 3\n4 3\n1 4\n"
] | [
"40\n",
"400\n",
"160\n"
] | One of the optimal sequence of actions in the first sample is:
- First, remove part 3, cost of the action is 20. - Then, remove part 2, cost of the action is 10. - Next, remove part 4, cost of the action is 10. - At last, remove part 1, cost of the action is 0.
So the total energy the child paid is 20β+β10β+β10β+... | 1,500 | [
{
"input": "4 3\n10 20 30 40\n1 4\n1 2\n2 3",
"output": "40"
},
{
"input": "4 4\n100 100 100 100\n1 2\n2 3\n2 4\n3 4",
"output": "400"
},
{
"input": "7 10\n40 10 20 10 20 80 40\n1 5\n4 7\n4 5\n5 2\n5 7\n6 4\n1 6\n1 3\n4 3\n1 4",
"output": "160"
},
{
"input": "1 0\n23333",
... | 1,626,176,686 | 2,147,483,647 | PyPy 3 | OK | TESTS | 29 | 140 | 23,654,400 | n, m =map(int, input().split())
v = list(map(int, input().split()))
s = 0
for _ in range(m):
x, y = map(int, input().split())
s += min(v[x-1], v[y-1])
print(s) | Title: The Child and Toy
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
On Children's Day, the child got a toy from Delayyy as a present. However, the child is so naughty that he can't wait to destroy the toy.
The toy consists of *n* parts and *m* ropes. Each rope links two parts, but ev... | ```python
n, m =map(int, input().split())
v = list(map(int, input().split()))
s = 0
for _ in range(m):
x, y = map(int, input().split())
s += min(v[x-1], v[y-1])
print(s)
``` | 3 | |
550 | A | Two Substrings | PROGRAMMING | 1,500 | [
"brute force",
"dp",
"greedy",
"implementation",
"strings"
] | null | null | You are given string *s*. Your task is to determine if the given string *s* contains two non-overlapping substrings "AB" and "BA" (the substrings can go in any order). | The only line of input contains a string *s* of length between 1 and 105 consisting of uppercase Latin letters. | Print "YES" (without the quotes), if string *s* contains two non-overlapping substrings "AB" and "BA", and "NO" otherwise. | [
"ABA\n",
"BACFAB\n",
"AXBYBXA\n"
] | [
"NO\n",
"YES\n",
"NO\n"
] | In the first sample test, despite the fact that there are substrings "AB" and "BA", their occurrences overlap, so the answer is "NO".
In the second sample test there are the following occurrences of the substrings: BACFAB.
In the third sample test there is no substring "AB" nor substring "BA". | 1,000 | [
{
"input": "ABA",
"output": "NO"
},
{
"input": "BACFAB",
"output": "YES"
},
{
"input": "AXBYBXA",
"output": "NO"
},
{
"input": "ABABAB",
"output": "YES"
},
{
"input": "BBBBBBBBBB",
"output": "NO"
},
{
"input": "ABBA",
"output": "YES"
},
{
"... | 1,683,879,504 | 2,147,483,647 | PyPy 3 | OK | TESTS | 85 | 93 | 614,400 | def contains_AB_and_BA(s):
if "AB" in s and "BA" in s[s.index("AB")+2:]:
return True
if "BA" in s and "AB" in s[s.index("BA")+2:]:
return True
return False
s = input()
if contains_AB_and_BA(s):
print("Yes")
else:
print("No") | Title: Two Substrings
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given string *s*. Your task is to determine if the given string *s* contains two non-overlapping substrings "AB" and "BA" (the substrings can go in any order).
Input Specification:
The only line of input contain... | ```python
def contains_AB_and_BA(s):
if "AB" in s and "BA" in s[s.index("AB")+2:]:
return True
if "BA" in s and "AB" in s[s.index("BA")+2:]:
return True
return False
s = input()
if contains_AB_and_BA(s):
print("Yes")
else:
print("No")
``` | 3 | |
940 | A | Points on the line | PROGRAMMING | 1,200 | [
"brute force",
"greedy",
"sortings"
] | null | null | We've got no test cases. A big olympiad is coming up. But the problemsetters' number one priority should be adding another problem to the round.
The diameter of a multiset of points on the line is the largest distance between two points from this set. For example, the diameter of the multiset {1,<=3,<=2,<=1} is 2.
D... | The first line contains two integers *n* and *d* (1<=β€<=*n*<=β€<=100,<=0<=β€<=*d*<=β€<=100)Β β the amount of points and the maximum allowed diameter respectively.
The second line contains *n* space separated integers (1<=β€<=*x**i*<=β€<=100)Β β the coordinates of the points. | Output a single integerΒ β the minimum number of points you have to remove. | [
"3 1\n2 1 4\n",
"3 0\n7 7 7\n",
"6 3\n1 3 4 6 9 10\n"
] | [
"1\n",
"0\n",
"3\n"
] | In the first test case the optimal strategy is to remove the point with coordinate 4. The remaining points will have coordinates 1 and 2, so the diameter will be equal to 2β-β1β=β1.
In the second test case the diameter is equal to 0, so its is unnecessary to remove any points.
In the third test case the optimal stra... | 500 | [
{
"input": "3 1\n2 1 4",
"output": "1"
},
{
"input": "3 0\n7 7 7",
"output": "0"
},
{
"input": "6 3\n1 3 4 6 9 10",
"output": "3"
},
{
"input": "11 5\n10 11 12 13 14 15 16 17 18 19 20",
"output": "5"
},
{
"input": "1 100\n1",
"output": "0"
},
{
"input"... | 1,554,867,283 | 2,147,483,647 | Python 3 | OK | TESTS | 35 | 109 | 0 | import sys
def minp():
return sys.stdin.readline().strip()
r = 0
n, d = map(int,minp().split())
a = sorted(map(int,minp().split()))
l = 0
r = 0
b = []
while l < n:
while (r < n-1) and (a[r+1]-a[l] <= d):
r += 1
b.append(r-l+1)
l += 1
print(n-max(b)) | Title: Points on the line
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
We've got no test cases. A big olympiad is coming up. But the problemsetters' number one priority should be adding another problem to the round.
The diameter of a multiset of points on the line is the largest dista... | ```python
import sys
def minp():
return sys.stdin.readline().strip()
r = 0
n, d = map(int,minp().split())
a = sorted(map(int,minp().split()))
l = 0
r = 0
b = []
while l < n:
while (r < n-1) and (a[r+1]-a[l] <= d):
r += 1
b.append(r-l+1)
l += 1
print(n-max(b))
``` | 3 | |
0 | none | none | none | 0 | [
"none"
] | null | null | Leha decided to move to a quiet town ViΔkopolis, because he was tired by living in Bankopolis. Upon arrival he immediately began to expand his network of hacked computers. During the week Leha managed to get access to *n* computers throughout the town. Incidentally all the computers, which were hacked by Leha, lie on t... | The first line contains one integer *n* (1<=β€<=*n*<=β€<=3Β·105) denoting the number of hacked computers.
The second line contains *n* integers *x*1,<=*x*2,<=...,<=*x**n* (1<=β€<=*x**i*<=β€<=109) denoting the coordinates of hacked computers. It is guaranteed that all *x**i* are distinct. | Print a single integerΒ β the required sum modulo 109<=+<=7. | [
"2\n4 7\n",
"3\n4 3 1\n"
] | [
"3\n",
"9\n"
] | There are three non-empty subsets in the first sample test:<img align="middle" class="tex-formula" src="https://espresso.codeforces.com/02b2d12556dad85f1c6c6912786eb87d4be2ea17.png" style="max-width: 100.0%;max-height: 100.0%;"/>, <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/22f6a537962c... | 0 | [
{
"input": "2\n4 7",
"output": "3"
},
{
"input": "3\n4 3 1",
"output": "9"
},
{
"input": "20\n8 11 13 19 21 34 36 44 57 58 61 63 76 78 79 81 85 86 90 95",
"output": "83396599"
},
{
"input": "20\n1 8 9 12 15 17 18 24 30 33 36 41 53 54 59 62 64 66 72 73",
"output": "6805914... | 1,495,340,392 | 2,147,483,647 | PyPy 3 | OK | TESTS | 69 | 1,434 | 30,515,200 | ###################################################
import atexit
import io
import sys
_INPUT_LINES = sys.stdin.read().splitlines()
input = iter(_INPUT_LINES).__next__
_OUTPUT_BUFFER = io.StringIO()
sys.stdout = _OUTPUT_BUFFER
@atexit.register
def write():
sys.__stdout__.write(_OUTPUT_BUFFER.getvalue())
######... | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Leha decided to move to a quiet town ViΔkopolis, because he was tired by living in Bankopolis. Upon arrival he immediately began to expand his network of hacked computers. During the week Leha managed to get access to *n* computer... | ```python
###################################################
import atexit
import io
import sys
_INPUT_LINES = sys.stdin.read().splitlines()
input = iter(_INPUT_LINES).__next__
_OUTPUT_BUFFER = io.StringIO()
sys.stdout = _OUTPUT_BUFFER
@atexit.register
def write():
sys.__stdout__.write(_OUTPUT_BUFFER.getvalue(... | 3 | |
272 | A | Dima and Friends | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | null | null | Dima and his friends have been playing hide and seek at Dima's place all night. As a result, Dima's place got messy. In the morning they decided that they need to clean the place.
To decide who exactly would clean the apartment, the friends want to play a counting-out game. First, all the guys stand in a circle, and t... | The first line contains integer *n* (1<=β€<=*n*<=β€<=100) β the number of Dima's friends. Dima himself isn't considered to be his own friend. The second line contains *n* positive integers, not exceeding 5, representing, how many fingers the Dima's friends will show.
The numbers in the lines are separated by a single s... | In a single line print the answer to the problem. | [
"1\n1\n",
"1\n2\n",
"2\n3 5\n"
] | [
"3\n",
"2\n",
"3\n"
] | In the first sample Dima can show 1, 3 or 5 fingers. If Dima shows 3 fingers, then the counting-out will go like that: Dima, his friend, Dima, his friend.
In the second sample Dima can show 2 or 4 fingers. | 500 | [
{
"input": "1\n1",
"output": "3"
},
{
"input": "1\n2",
"output": "2"
},
{
"input": "2\n3 5",
"output": "3"
},
{
"input": "2\n3 5",
"output": "3"
},
{
"input": "1\n5",
"output": "3"
},
{
"input": "5\n4 4 3 5 1",
"output": "4"
},
{
"input": "... | 1,590,674,671 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 186 | 0 | n = int(input())+1
l = list(map(int,input().split()))
s = sum(l)
count =0
for i in range(1,6):
s1 = s+i
if(s1%n!=1):
count+=1
print(count)
| Title: Dima and Friends
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Dima and his friends have been playing hide and seek at Dima's place all night. As a result, Dima's place got messy. In the morning they decided that they need to clean the place.
To decide who exactly would clean the... | ```python
n = int(input())+1
l = list(map(int,input().split()))
s = sum(l)
count =0
for i in range(1,6):
s1 = s+i
if(s1%n!=1):
count+=1
print(count)
``` | 3 | |
554 | A | Kyoya and Photobooks | PROGRAMMING | 900 | [
"brute force",
"math",
"strings"
] | null | null | Kyoya Ootori is selling photobooks of the Ouran High School Host Club. He has 26 photos, labeled "a" to "z", and he has compiled them into a photo booklet with some photos in some order (possibly with some photos being duplicated). A photo booklet can be described as a string of lowercase letters, consisting of the pho... | The first line of input will be a single string *s* (1<=β€<=|*s*|<=β€<=20). String *s* consists only of lowercase English letters. | Output a single integer equal to the number of distinct photobooks Kyoya Ootori can make. | [
"a\n",
"hi\n"
] | [
"51\n",
"76\n"
] | In the first case, we can make 'ab','ac',...,'az','ba','ca',...,'za', and 'aa', producing a total of 51 distinct photo booklets. | 250 | [
{
"input": "a",
"output": "51"
},
{
"input": "hi",
"output": "76"
},
{
"input": "y",
"output": "51"
},
{
"input": "kgan",
"output": "126"
},
{
"input": "zoabkyuvus",
"output": "276"
},
{
"input": "spyemhyznjieyhhbk",
"output": "451"
},
{
"i... | 1,693,633,398 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 33 | 62 | 0 | str = input()
a = len(str)
print(a * 25 + 26)
| Title: Kyoya and Photobooks
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Kyoya Ootori is selling photobooks of the Ouran High School Host Club. He has 26 photos, labeled "a" to "z", and he has compiled them into a photo booklet with some photos in some order (possibly with some photos b... | ```python
str = input()
a = len(str)
print(a * 25 + 26)
``` | 3 | |
960 | A | Check the string | PROGRAMMING | 1,200 | [
"implementation"
] | null | null | A has a string consisting of some number of lowercase English letters 'a'. He gives it to his friend B who appends some number of letters 'b' to the end of this string. Since both A and B like the characters 'a' and 'b', they have made sure that at this point, at least one 'a' and one 'b' exist in the string.
B now gi... | The first and only line consists of a string $S$ ($ 1 \le |S| \le 5\,000 $). It is guaranteed that the string will only consist of the lowercase English letters 'a', 'b', 'c'. | Print "YES" or "NO", according to the condition. | [
"aaabccc\n",
"bbacc\n",
"aabc\n"
] | [
"YES\n",
"NO\n",
"YES\n"
] | Consider first example: the number of 'c' is equal to the number of 'a'.
Consider second example: although the number of 'c' is equal to the number of the 'b', the order is not correct.
Consider third example: the number of 'c' is equal to the number of 'b'. | 500 | [
{
"input": "aaabccc",
"output": "YES"
},
{
"input": "bbacc",
"output": "NO"
},
{
"input": "aabc",
"output": "YES"
},
{
"input": "aabbcc",
"output": "YES"
},
{
"input": "aaacccbb",
"output": "NO"
},
{
"input": "abc",
"output": "YES"
},
{
"in... | 1,608,193,302 | 2,147,483,647 | PyPy 3 | OK | TESTS | 55 | 140 | 0 | s = input(); a = s.count('a'); b = s.count('b'); c = s.count('c')
if a==0 or b==0:
print('No')
exit(0)
if a*'a' + b*'b' + c*'c' == s and (a==c or b==c):
print('Yes')
else:
print('No') | Title: Check the string
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A has a string consisting of some number of lowercase English letters 'a'. He gives it to his friend B who appends some number of letters 'b' to the end of this string. Since both A and B like the characters 'a' and 'b... | ```python
s = input(); a = s.count('a'); b = s.count('b'); c = s.count('c')
if a==0 or b==0:
print('No')
exit(0)
if a*'a' + b*'b' + c*'c' == s and (a==c or b==c):
print('Yes')
else:
print('No')
``` | 3 | |
976 | A | Minimum Binary Number | PROGRAMMING | 800 | [
"implementation"
] | null | null | String can be called correct if it consists of characters "0" and "1" and there are no redundant leading zeroes. Here are some examples: "0", "10", "1001".
You are given a correct string *s*.
You can perform two different operations on this string:
1. swap any pair of adjacent characters (for example, "101" "110"... | The first line contains integer number *n* (1<=β€<=*n*<=β€<=100) β the length of string *s*.
The second line contains the string *s* consisting of characters "0" and "1". It is guaranteed that the string *s* is correct. | Print one string β the minimum correct string that you can obtain from the given one. | [
"4\n1001\n",
"1\n1\n"
] | [
"100\n",
"1\n"
] | In the first example you can obtain the answer by the following sequence of operations: "1001" <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> "1010" <img align="middle" class="tex-formula" src="ht... | 0 | [
{
"input": "4\n1001",
"output": "100"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "100\n1110111100001111011111111010110011111111011110000111101101011100110110001011000000101010110101011100",
"output": "1000000000000000000000000000000000000000"
},
{
"input": "100\n100000... | 1,550,566,475 | 2,147,483,647 | Python 3 | OK | TESTS | 14 | 124 | 0 | n=input()
s=input()
print('1'*int(bool(s.count("1")))+"0"*s.count("0")) | Title: Minimum Binary Number
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
String can be called correct if it consists of characters "0" and "1" and there are no redundant leading zeroes. Here are some examples: "0", "10", "1001".
You are given a correct string *s*.
You can perform two... | ```python
n=input()
s=input()
print('1'*int(bool(s.count("1")))+"0"*s.count("0"))
``` | 3 | |
435 | A | Queue on Bus Stop | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | It's that time of the year when the Russians flood their countryside summer cottages (dachas) and the bus stop has a lot of people. People rarely go to the dacha on their own, it's usually a group, so the people stand in queue by groups.
The bus stop queue has *n* groups of people. The *i*-th group from the beginning ... | The first line contains two integers *n* and *m* (1<=β€<=*n*,<=*m*<=β€<=100). The next line contains *n* integers: *a*1,<=*a*2,<=...,<=*a**n* (1<=β€<=*a**i*<=β€<=*m*). | Print a single integer β the number of buses that is needed to transport all *n* groups to the dacha countryside. | [
"4 3\n2 3 2 1\n",
"3 4\n1 2 1\n"
] | [
"3\n",
"1\n"
] | none | 500 | [
{
"input": "4 3\n2 3 2 1",
"output": "3"
},
{
"input": "3 4\n1 2 1",
"output": "1"
},
{
"input": "1 5\n4",
"output": "1"
},
{
"input": "5 1\n1 1 1 1 1",
"output": "5"
},
{
"input": "6 4\n1 3 2 3 4 1",
"output": "5"
},
{
"input": "6 8\n6 1 1 1 4 5",
... | 1,542,881,368 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 109 | 0 | import math
a = list(map(int,input().split()))
people = list(map(int,input().split()))
total_group = a[0]
seat_bus = a[1]
max_bus = total_group * seat_bus
check = 0
###check if people have same number of seat_bus
##check_same = [i for i in range(total_group) if people[i] == seat_bus]
###remove the same n... | Title: Queue on Bus Stop
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
It's that time of the year when the Russians flood their countryside summer cottages (dachas) and the bus stop has a lot of people. People rarely go to the dacha on their own, it's usually a group, so the people stand... | ```python
import math
a = list(map(int,input().split()))
people = list(map(int,input().split()))
total_group = a[0]
seat_bus = a[1]
max_bus = total_group * seat_bus
check = 0
###check if people have same number of seat_bus
##check_same = [i for i in range(total_group) if people[i] == seat_bus]
###remove ... | 3 | |
962 | A | Equator | PROGRAMMING | 1,300 | [
"implementation"
] | null | null | Polycarp has created his own training plan to prepare for the programming contests. He will train for $n$ days, all days are numbered from $1$ to $n$, beginning from the first.
On the $i$-th day Polycarp will necessarily solve $a_i$ problems. One evening Polycarp plans to celebrate the equator. He will celebrate it on... | The first line contains a single integer $n$ ($1 \le n \le 200\,000$) β the number of days to prepare for the programming contests.
The second line contains a sequence $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10\,000$), where $a_i$ equals to the number of problems, which Polycarp will solve on the $i$-th day. | Print the index of the day when Polycarp will celebrate the equator. | [
"4\n1 3 2 1\n",
"6\n2 2 2 2 2 2\n"
] | [
"2\n",
"3\n"
] | In the first example Polycarp will celebrate the equator on the evening of the second day, because up to this day (inclusive) he will solve $4$ out of $7$ scheduled problems on four days of the training.
In the second example Polycarp will celebrate the equator on the evening of the third day, because up to this day (... | 0 | [
{
"input": "4\n1 3 2 1",
"output": "2"
},
{
"input": "6\n2 2 2 2 2 2",
"output": "3"
},
{
"input": "1\n10000",
"output": "1"
},
{
"input": "3\n2 1 1",
"output": "1"
},
{
"input": "2\n1 3",
"output": "2"
},
{
"input": "4\n2 1 1 3",
"output": "3"
}... | 1,658,508,898 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 106 | 93 | 20,070,400 | from bisect import bisect_left
n = int(input())
a = list(map(int, input().split()))
for i in range(1, n):
a[i] += a[i-1]
if a[-1] % 2:
mid = (a[-1]+1)//2
else:
mid = a[-1]//2
print(bisect_left(a, mid)+1)
| Title: Equator
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp has created his own training plan to prepare for the programming contests. He will train for $n$ days, all days are numbered from $1$ to $n$, beginning from the first.
On the $i$-th day Polycarp will necessarily solve... | ```python
from bisect import bisect_left
n = int(input())
a = list(map(int, input().split()))
for i in range(1, n):
a[i] += a[i-1]
if a[-1] % 2:
mid = (a[-1]+1)//2
else:
mid = a[-1]//2
print(bisect_left(a, mid)+1)
``` | 3 | |
915 | A | Garden | PROGRAMMING | 900 | [
"implementation"
] | null | null | Luba thinks about watering her garden. The garden can be represented as a segment of length *k*. Luba has got *n* buckets, the *i*-th bucket allows her to water some continuous subsegment of garden of length exactly *a**i* each hour. Luba can't water any parts of the garden that were already watered, also she can't wat... | The first line of input contains two integer numbers *n* and *k* (1<=β€<=*n*,<=*k*<=β€<=100) β the number of buckets and the length of the garden, respectively.
The second line of input contains *n* integer numbers *a**i* (1<=β€<=*a**i*<=β€<=100) β the length of the segment that can be watered by the *i*-th bucket in one ... | Print one integer number β the minimum number of hours required to water the garden. | [
"3 6\n2 3 5\n",
"6 7\n1 2 3 4 5 6\n"
] | [
"2\n",
"7\n"
] | In the first test the best option is to choose the bucket that allows to water the segment of length 3. We can't choose the bucket that allows to water the segment of length 5 because then we can't water the whole garden.
In the second test we can choose only the bucket that allows us to water the segment of length 1. | 0 | [
{
"input": "3 6\n2 3 5",
"output": "2"
},
{
"input": "6 7\n1 2 3 4 5 6",
"output": "7"
},
{
"input": "5 97\n1 10 50 97 2",
"output": "1"
},
{
"input": "5 97\n1 10 50 100 2",
"output": "97"
},
{
"input": "100 100\n2 46 24 18 86 90 31 38 84 49 58 28 15 80 14 24 87 5... | 1,594,291,089 | 2,147,483,647 | PyPy 3 | OK | TESTS | 83 | 140 | 20,172,800 | l1 = [int(x) for x in input().split()]
total=l1[1]
l2 = [int(x) for x in input().split()]
l2.sort(reverse=True)
ans=1
for x in l2:
if total%x==0:
ans=x
break
ans = total//ans
print(ans) | Title: Garden
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Luba thinks about watering her garden. The garden can be represented as a segment of length *k*. Luba has got *n* buckets, the *i*-th bucket allows her to water some continuous subsegment of garden of length exactly *a**i* each ... | ```python
l1 = [int(x) for x in input().split()]
total=l1[1]
l2 = [int(x) for x in input().split()]
l2.sort(reverse=True)
ans=1
for x in l2:
if total%x==0:
ans=x
break
ans = total//ans
print(ans)
``` | 3 | |
677 | A | Vanya and Fence | PROGRAMMING | 800 | [
"implementation"
] | null | null | Vanya and his friends are walking along the fence of height *h* and they do not want the guard to notice them. In order to achieve this the height of each of the friends should not exceed *h*. If the height of some person is greater than *h* he can bend down and then he surely won't be noticed by the guard. The height ... | The first line of the input contains two integers *n* and *h* (1<=β€<=*n*<=β€<=1000, 1<=β€<=*h*<=β€<=1000)Β β the number of friends and the height of the fence, respectively.
The second line contains *n* integers *a**i* (1<=β€<=*a**i*<=β€<=2*h*), the *i*-th of them is equal to the height of the *i*-th person. | Print a single integerΒ β the minimum possible valid width of the road. | [
"3 7\n4 5 14\n",
"6 1\n1 1 1 1 1 1\n",
"6 5\n7 6 8 9 10 5\n"
] | [
"4\n",
"6\n",
"11\n"
] | In the first sample, only person number 3 must bend down, so the required width is equal to 1β+β1β+β2β=β4.
In the second sample, all friends are short enough and no one has to bend, so the width 1β+β1β+β1β+β1β+β1β+β1β=β6 is enough.
In the third sample, all the persons have to bend, except the last one. The required m... | 500 | [
{
"input": "3 7\n4 5 14",
"output": "4"
},
{
"input": "6 1\n1 1 1 1 1 1",
"output": "6"
},
{
"input": "6 5\n7 6 8 9 10 5",
"output": "11"
},
{
"input": "10 420\n214 614 297 675 82 740 174 23 255 15",
"output": "13"
},
{
"input": "10 561\n657 23 1096 487 785 66 481... | 1,696,404,001 | 2,147,483,647 | Python 3 | OK | TESTS | 29 | 46 | 0 | n, h = map(int, input().split())
arr = list(map(int, input().split()))
ans = n
for each in arr:
if each > h:
ans += 1
print(ans) | Title: Vanya and Fence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vanya and his friends are walking along the fence of height *h* and they do not want the guard to notice them. In order to achieve this the height of each of the friends should not exceed *h*. If the height of some pers... | ```python
n, h = map(int, input().split())
arr = list(map(int, input().split()))
ans = n
for each in arr:
if each > h:
ans += 1
print(ans)
``` | 3 | |
610 | A | Pasha and Stick | PROGRAMMING | 1,000 | [
"combinatorics",
"math"
] | null | null | Pasha has a wooden stick of some positive integer length *n*. He wants to perform exactly three cuts to get four parts of the stick. Each part must have some positive integer length and the sum of these lengths will obviously be *n*.
Pasha likes rectangles but hates squares, so he wonders, how many ways are there to ... | The first line of the input contains a positive integer *n* (1<=β€<=*n*<=β€<=2Β·109) β the length of Pasha's stick. | The output should contain a single integerΒ β the number of ways to split Pasha's stick into four parts of positive integer length so that it's possible to make a rectangle by connecting the ends of these parts, but is impossible to form a square. | [
"6\n",
"20\n"
] | [
"1\n",
"4\n"
] | There is only one way to divide the stick in the first sample {1, 1, 2, 2}.
Four ways to divide the stick in the second sample are {1, 1, 9, 9}, {2, 2, 8, 8}, {3, 3, 7, 7} and {4, 4, 6, 6}. Note that {5, 5, 5, 5} doesn't work. | 500 | [
{
"input": "6",
"output": "1"
},
{
"input": "20",
"output": "4"
},
{
"input": "1",
"output": "0"
},
{
"input": "2",
"output": "0"
},
{
"input": "3",
"output": "0"
},
{
"input": "4",
"output": "0"
},
{
"input": "2000000000",
"output": "4... | 1,565,659,992 | 2,147,483,647 | PyPy 3 | OK | TESTS | 76 | 140 | 0 | # @author Matheus Alves dos Santos
def divisible_by(value, n):
return ((value % n) == 0)
length = int(input())
ways = 0
if (divisible_by(length, 2)):
ways = (length // 4)
if (divisible_by(length, 4)):
ways -= 1
print(ways) | Title: Pasha and Stick
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Pasha has a wooden stick of some positive integer length *n*. He wants to perform exactly three cuts to get four parts of the stick. Each part must have some positive integer length and the sum of these lengths will obv... | ```python
# @author Matheus Alves dos Santos
def divisible_by(value, n):
return ((value % n) == 0)
length = int(input())
ways = 0
if (divisible_by(length, 2)):
ways = (length // 4)
if (divisible_by(length, 4)):
ways -= 1
print(ways)
``` | 3 | |
873 | D | Merge Sort | PROGRAMMING | 1,800 | [
"constructive algorithms",
"divide and conquer"
] | null | null | Merge sort is a well-known sorting algorithm. The main function that sorts the elements of array *a* with indices from [*l*,<=*r*) can be implemented as follows:
1. If the segment [*l*,<=*r*) is already sorted in non-descending order (that is, for any *i* such that *l*<=β€<=*i*<=<<=*r*<=-<=1 *a*[*i*]<=β€<=*a*[*i*<=+... | The first line contains two numbers *n* and *k* (1<=β€<=*n*<=β€<=100000, 1<=β€<=*k*<=β€<=200000) β the size of a desired permutation and the number of *mergesort* calls required to sort it. | If a permutation of size *n* such that there will be exactly *k* calls of *mergesort* while sorting it doesn't exist, output <=-<=1. Otherwise output *n* integer numbers *a*[0],<=*a*[1],<=...,<=*a*[*n*<=-<=1] β the elements of a permutation that would meet the required conditions. If there are multiple answers, print a... | [
"3 3\n",
"4 1\n",
"5 6\n"
] | [
"2 1 3 ",
"1 2 3 4 ",
"-1\n"
] | none | 0 | [
{
"input": "3 3",
"output": "2 1 3 "
},
{
"input": "4 1",
"output": "1 2 3 4 "
},
{
"input": "5 6",
"output": "-1"
},
{
"input": "100 100",
"output": "-1"
},
{
"input": "10000 10001",
"output": "3 1 5 2 7 4 8 10 6 12 9 13 15 11 17 14 18 20 16 22 19 23 25 21 27... | 1,594,489,566 | 2,147,483,647 | PyPy 3 | OK | TESTS | 36 | 218 | 35,635,200 | n,k = [int(x) for x in input().split()]
if k%2 == 0:
print(-1)
else:
# a completely unsorted list of length n
# will have 2(n-1) child calls
if k > 2*n-1:
print(-1)
else:
arr = [n-x for x in range(n)]
sorts = 2*n-1-k
segs = [[(0,n,n//2)]]
... | Title: Merge Sort
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Merge sort is a well-known sorting algorithm. The main function that sorts the elements of array *a* with indices from [*l*,<=*r*) can be implemented as follows:
1. If the segment [*l*,<=*r*) is already sorted in non-desce... | ```python
n,k = [int(x) for x in input().split()]
if k%2 == 0:
print(-1)
else:
# a completely unsorted list of length n
# will have 2(n-1) child calls
if k > 2*n-1:
print(-1)
else:
arr = [n-x for x in range(n)]
sorts = 2*n-1-k
segs = [[(0,n,n//2)]]
... | 3 | |
208 | A | Dubstep | PROGRAMMING | 900 | [
"strings"
] | null | null | Vasya works as a DJ in the best Berland nightclub, and he often uses dubstep music in his performance. Recently, he has decided to take a couple of old songs and make dubstep remixes from them.
Let's assume that a song consists of some number of words. To make the dubstep remix of this song, Vasya inserts a certain nu... | The input consists of a single non-empty string, consisting only of uppercase English letters, the string's length doesn't exceed 200 characters. It is guaranteed that before Vasya remixed the song, no word contained substring "WUB" in it; Vasya didn't change the word order. It is also guaranteed that initially the son... | Print the words of the initial song that Vasya used to make a dubsteb remix. Separate the words with a space. | [
"WUBWUBABCWUB\n",
"WUBWEWUBAREWUBWUBTHEWUBCHAMPIONSWUBMYWUBFRIENDWUB\n"
] | [
"ABC ",
"WE ARE THE CHAMPIONS MY FRIEND "
] | In the first sample: "WUBWUBABCWUB" = "WUB" + "WUB" + "ABC" + "WUB". That means that the song originally consisted of a single word "ABC", and all words "WUB" were added by Vasya.
In the second sample Vasya added a single word "WUB" between all neighbouring words, in the beginning and in the end, except for words "ARE... | 500 | [
{
"input": "WUBWUBABCWUB",
"output": "ABC "
},
{
"input": "WUBWEWUBAREWUBWUBTHEWUBCHAMPIONSWUBMYWUBFRIENDWUB",
"output": "WE ARE THE CHAMPIONS MY FRIEND "
},
{
"input": "WUBWUBWUBSR",
"output": "SR "
},
{
"input": "RWUBWUBWUBLWUB",
"output": "R L "
},
{
"input": "... | 1,676,914,100 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 71 | 124 | 0 | arr = list(input().split('WUB'))
for e in arr:
if e == '':
continue
print(e, end=' ')
| Title: Dubstep
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya works as a DJ in the best Berland nightclub, and he often uses dubstep music in his performance. Recently, he has decided to take a couple of old songs and make dubstep remixes from them.
Let's assume that a song consist... | ```python
arr = list(input().split('WUB'))
for e in arr:
if e == '':
continue
print(e, end=' ')
``` | 3 | |
260 | A | Adding Digits | PROGRAMMING | 1,400 | [
"implementation",
"math"
] | null | null | Vasya has got two number: *a* and *b*. However, Vasya finds number *a* too short. So he decided to repeat the operation of lengthening number *a* *n* times.
One operation of lengthening a number means adding exactly one digit to the number (in the decimal notation) to the right provided that the resulting number is di... | The first line contains three integers: *a*,<=*b*,<=*n* (1<=β€<=*a*,<=*b*,<=*n*<=β€<=105). | In a single line print the integer without leading zeros, which Vasya can get when he applies the lengthening operations to number *a* *n* times. If no such number exists, then print number -1. If there are multiple possible answers, print any of them. | [
"5 4 5\n",
"12 11 1\n",
"260 150 10\n"
] | [
"524848\n",
"121\n",
"-1\n"
] | none | 500 | [
{
"input": "5 4 5",
"output": "524848"
},
{
"input": "12 11 1",
"output": "121"
},
{
"input": "260 150 10",
"output": "-1"
},
{
"input": "78843 5684 42717",
"output": "-1"
},
{
"input": "93248 91435 1133",
"output": "-1"
},
{
"input": "100000 10 64479"... | 1,647,451,327 | 2,147,483,647 | Python 3 | OK | TESTS | 25 | 717 | 307,200 | a,b,n=map(int,input().split(" "))
num=a
flag=True
for i in range(0,10):
if (num*10+i)%b==0:
num=num*10+i
a=num
flag=False
break
if flag==True:
print(-1)
else:
a*=pow(10,n-1)
print(a)
| Title: Adding Digits
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya has got two number: *a* and *b*. However, Vasya finds number *a* too short. So he decided to repeat the operation of lengthening number *a* *n* times.
One operation of lengthening a number means adding exactly one ... | ```python
a,b,n=map(int,input().split(" "))
num=a
flag=True
for i in range(0,10):
if (num*10+i)%b==0:
num=num*10+i
a=num
flag=False
break
if flag==True:
print(-1)
else:
a*=pow(10,n-1)
print(a)
``` | 3 | |
263 | A | Beautiful Matrix | PROGRAMMING | 800 | [
"implementation"
] | null | null | You've got a 5<=Γ<=5 matrix, consisting of 24 zeroes and a single number one. Let's index the matrix rows by numbers from 1 to 5 from top to bottom, let's index the matrix columns by numbers from 1 to 5 from left to right. In one move, you are allowed to apply one of the two following transformations to the matrix:
1.... | The input consists of five lines, each line contains five integers: the *j*-th integer in the *i*-th line of the input represents the element of the matrix that is located on the intersection of the *i*-th row and the *j*-th column. It is guaranteed that the matrix consists of 24 zeroes and a single number one. | Print a single integer β the minimum number of moves needed to make the matrix beautiful. | [
"0 0 0 0 0\n0 0 0 0 1\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n",
"0 0 0 0 0\n0 0 0 0 0\n0 1 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n"
] | [
"3\n",
"1\n"
] | none | 500 | [
{
"input": "0 0 0 0 0\n0 0 0 0 1\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0",
"output": "3"
},
{
"input": "0 0 0 0 0\n0 0 0 0 0\n0 1 0 0 0\n0 0 0 0 0\n0 0 0 0 0",
"output": "1"
},
{
"input": "0 0 0 0 0\n0 0 0 0 0\n0 0 1 0 0\n0 0 0 0 0\n0 0 0 0 0",
"output": "0"
},
{
"input": "0 0 0 0 0... | 1,697,379,472 | 2,147,483,647 | PyPy 3 | OK | TESTS | 25 | 154 | 0 | import math
l=[]
for i in range(5):
ll = list(map(int,input().split()))
l.append(ll)
m = 0
n = 0
x=0
for i in range(5):
a = l[i]
for j in range(5):
if a[j] == 1:
m=i
n=j
x=1
break
if x==1:
break
M=0
if m... | Title: Beautiful Matrix
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You've got a 5<=Γ<=5 matrix, consisting of 24 zeroes and a single number one. Let's index the matrix rows by numbers from 1 to 5 from top to bottom, let's index the matrix columns by numbers from 1 to 5 from left to ri... | ```python
import math
l=[]
for i in range(5):
ll = list(map(int,input().split()))
l.append(ll)
m = 0
n = 0
x=0
for i in range(5):
a = l[i]
for j in range(5):
if a[j] == 1:
m=i
n=j
x=1
break
if x==1:
break
... | 3 | |
262 | A | Roma and Lucky Numbers | PROGRAMMING | 800 | [
"implementation"
] | null | null | Roma (a popular Russian name that means 'Roman') loves the Little Lvov Elephant's lucky numbers.
Let us remind you that lucky numbers are positive integers whose decimal representation only contains lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Roma's got *n* positive integer... | The first line contains two integers *n*, *k* (1<=β€<=*n*,<=*k*<=β€<=100). The second line contains *n* integers *a**i* (1<=β€<=*a**i*<=β€<=109) β the numbers that Roma has.
The numbers in the lines are separated by single spaces. | In a single line print a single integer β the answer to the problem. | [
"3 4\n1 2 4\n",
"3 2\n447 44 77\n"
] | [
"3\n",
"2\n"
] | In the first sample all numbers contain at most four lucky digits, so the answer is 3.
In the second sample number 447 doesn't fit in, as it contains more than two lucky digits. All other numbers are fine, so the answer is 2. | 500 | [
{
"input": "3 4\n1 2 4",
"output": "3"
},
{
"input": "3 2\n447 44 77",
"output": "2"
},
{
"input": "2 2\n507978501 180480073",
"output": "2"
},
{
"input": "9 6\n655243746 167613748 1470546 57644035 176077477 56984809 44677 215706823 369042089",
"output": "9"
},
{
... | 1,695,844,512 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 92 | 0 | n, k= map(int, input().split())
a = 0
b = 0
x = [str(y) for y in input().split()]
for i in x:
for j in range(len(i)):
if i[j] == "4" or i[j] == "7":
a+=1
if a <= k:
b+=1
a = 0
else:
a = 0
print(b)
| Title: Roma and Lucky Numbers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Roma (a popular Russian name that means 'Roman') loves the Little Lvov Elephant's lucky numbers.
Let us remind you that lucky numbers are positive integers whose decimal representation only contains lucky digits... | ```python
n, k= map(int, input().split())
a = 0
b = 0
x = [str(y) for y in input().split()]
for i in x:
for j in range(len(i)):
if i[j] == "4" or i[j] == "7":
a+=1
if a <= k:
b+=1
a = 0
else:
a = 0
print(b)
``` | 3 | |
94 | A | Restoring Password | PROGRAMMING | 900 | [
"implementation",
"strings"
] | A. Restoring Password | 2 | 256 | Igor K. always used to trust his favorite Kashpirovsky Antivirus. That is why he didn't hesitate to download the link one of his groupmates sent him via QIP Infinium. The link was said to contain "some real funny stuff about swine influenza". The antivirus had no objections and Igor K. run the flash application he had ... | The input data contains 11 lines. The first line represents the binary code 80 characters in length. That is the code written in Igor K.'s ISQ account's info. Next 10 lines contain pairwise distinct binary codes 10 characters in length, corresponding to numbers 0, 1, ..., 9. | Print one line containing 8 characters β The password to Igor K.'s ISQ account. It is guaranteed that the solution exists. | [
"01001100100101100000010110001001011001000101100110010110100001011010100101101100\n0100110000\n0100110010\n0101100000\n0101100010\n0101100100\n0101100110\n0101101000\n0101101010\n0101101100\n0101101110\n",
"10101101111001000010100100011010101101110010110111011000100011011110010110001000\n1001000010\n1101111001\n1... | [
"12345678\n",
"30234919\n"
] | none | 500 | [
{
"input": "01001100100101100000010110001001011001000101100110010110100001011010100101101100\n0100110000\n0100110010\n0101100000\n0101100010\n0101100100\n0101100110\n0101101000\n0101101010\n0101101100\n0101101110",
"output": "12345678"
},
{
"input": "1010110111100100001010010001101010110111001011011... | 1,593,360,193 | 2,147,483,647 | PyPy 3 | OK | TESTS | 50 | 280 | 20,172,800 | s = input()
d = {}
for i in range(10):
x = input()
d[x] = str(i)
ans = ''
for i in range(8):
ans += d[s[i*10 : (i * 10 + 10)]]
print(ans) | Title: Restoring Password
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Igor K. always used to trust his favorite Kashpirovsky Antivirus. That is why he didn't hesitate to download the link one of his groupmates sent him via QIP Infinium. The link was said to contain "some real funny stuff a... | ```python
s = input()
d = {}
for i in range(10):
x = input()
d[x] = str(i)
ans = ''
for i in range(8):
ans += d[s[i*10 : (i * 10 + 10)]]
print(ans)
``` | 3.892425 |
960 | B | Minimize the error | PROGRAMMING | 1,500 | [
"data structures",
"greedy",
"sortings"
] | null | null | You are given two arrays *A* and *B*, each of size *n*. The error, *E*, between these two arrays is defined . You have to perform exactly *k*1 operations on array *A* and exactly *k*2 operations on array *B*. In one operation, you have to choose one element of the array and increase or decrease it by 1.
Output the min... | The first line contains three space-separated integers *n* (1<=β€<=*n*<=β€<=103), *k*1 and *k*2 (0<=β€<=*k*1<=+<=*k*2<=β€<=103, *k*1 and *k*2 are non-negative) β size of arrays and number of operations to perform on *A* and *B* respectively.
Second line contains *n* space separated integers *a*1,<=*a*2,<=...,<=*a**n* (<=-... | Output a single integer β the minimum possible value of after doing exactly *k*1 operations on array *A* and exactly *k*2 operations on array *B*. | [
"2 0 0\n1 2\n2 3\n",
"2 1 0\n1 2\n2 2\n",
"2 5 7\n3 4\n14 4\n"
] | [
"2",
"0",
"1"
] | In the first sample case, we cannot perform any operations on *A* or *B*. Therefore the minimum possible error *E*β=β(1β-β2)<sup class="upper-index">2</sup>β+β(2β-β3)<sup class="upper-index">2</sup>β=β2.
In the second sample case, we are required to perform exactly one operation on *A*. In order to minimize error, we... | 1,000 | [
{
"input": "2 0 0\n1 2\n2 3",
"output": "2"
},
{
"input": "2 1 0\n1 2\n2 2",
"output": "0"
},
{
"input": "2 5 7\n3 4\n14 4",
"output": "1"
},
{
"input": "2 0 1\n1 2\n2 2",
"output": "0"
},
{
"input": "2 1 1\n0 0\n1 1",
"output": "0"
},
{
"input": "5 5 ... | 1,687,425,660 | 1,260 | Python 3 | OK | TESTS | 80 | 46 | 512,000 | n, k1, k2 = map (int, input ().split ())
a = list (map (int, input ().split ()))
b = list (map (int, input ().split ()))
c = list ()
for i in range (n) : c.append (abs (a[i] - b[i]))
c.sort (reverse = True)
for i in range (k1 + k2) :
if c[0] <= 0 : c[0] += 1
else : c[0] -= 1
i = 1
while i < n and c[i]... | Title: Minimize the error
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given two arrays *A* and *B*, each of size *n*. The error, *E*, between these two arrays is defined . You have to perform exactly *k*1 operations on array *A* and exactly *k*2 operations on array *B*. In one ... | ```python
n, k1, k2 = map (int, input ().split ())
a = list (map (int, input ().split ()))
b = list (map (int, input ().split ()))
c = list ()
for i in range (n) : c.append (abs (a[i] - b[i]))
c.sort (reverse = True)
for i in range (k1 + k2) :
if c[0] <= 0 : c[0] += 1
else : c[0] -= 1
i = 1
while i < ... | 3 | |
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,637,602,495 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 92 | 0 | s=input()
UC=0
LC=0
for i in s:
if(i.islower()):
LC=LC+1
elif(i.isupper()):
UC=UC+1
if(UC>LC):
print(s.upper())
elif(LC>UC):
print(s.lower())
elif(LC==UC):
print(s.lower()) | Title: Word
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it ei... | ```python
s=input()
UC=0
LC=0
for i in s:
if(i.islower()):
LC=LC+1
elif(i.isupper()):
UC=UC+1
if(UC>LC):
print(s.upper())
elif(LC>UC):
print(s.lower())
elif(LC==UC):
print(s.lower())
``` | 3.977 |
455 | A | Boredom | PROGRAMMING | 1,500 | [
"dp"
] | null | null | Alex doesn't like boredom. That's why whenever he gets bored, he comes up with games. One long winter evening he came up with a game and decided to play it.
Given a sequence *a* consisting of *n* integers. The player can make several steps. In a single step he can choose an element of the sequence (let's denote it *a*... | The first line contains integer *n* (1<=β€<=*n*<=β€<=105) that shows how many numbers are in Alex's sequence.
The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=β€<=*a**i*<=β€<=105). | Print a single integer β the maximum number of points that Alex can earn. | [
"2\n1 2\n",
"3\n1 2 3\n",
"9\n1 2 1 3 2 2 2 2 3\n"
] | [
"2\n",
"4\n",
"10\n"
] | Consider the third test example. At first step we need to choose any element equal to 2. After that step our sequence looks like this [2,β2,β2,β2]. Then we do 4 steps, on each step we choose any element equals to 2. In total we earn 10 points. | 500 | [
{
"input": "2\n1 2",
"output": "2"
},
{
"input": "3\n1 2 3",
"output": "4"
},
{
"input": "9\n1 2 1 3 2 2 2 2 3",
"output": "10"
},
{
"input": "5\n3 3 4 5 4",
"output": "11"
},
{
"input": "5\n5 3 5 3 4",
"output": "16"
},
{
"input": "5\n4 2 3 2 5",
... | 1,668,614,721 | 2,147,483,647 | Python 3 | OK | TESTS | 47 | 810 | 13,209,600 | n = int(input())
list1 = list(map(int,input().split()))
list2 = [0]*1000001
for i in list1:
list2[i] += 1
list3 = [0]*1000001
for q in range(1,1000001):
list3[q] = max(list3[q-1],list3[q-2]+q*list2[q])
print(list3[max(list1)]) | Title: Boredom
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Alex doesn't like boredom. That's why whenever he gets bored, he comes up with games. One long winter evening he came up with a game and decided to play it.
Given a sequence *a* consisting of *n* integers. The player can make ... | ```python
n = int(input())
list1 = list(map(int,input().split()))
list2 = [0]*1000001
for i in list1:
list2[i] += 1
list3 = [0]*1000001
for q in range(1,1000001):
list3[q] = max(list3[q-1],list3[q-2]+q*list2[q])
print(list3[max(list1)])
``` | 3 | |
408 | A | Line to Cashier | PROGRAMMING | 900 | [
"implementation"
] | null | null | Little Vasya went to the supermarket to get some groceries. He walked about the supermarket for a long time and got a basket full of products. Now he needs to choose the cashier to pay for the products.
There are *n* cashiers at the exit from the supermarket. At the moment the queue for the *i*-th cashier already has ... | The first line contains integer *n* (1<=β€<=*n*<=β€<=100)Β β the number of cashes in the shop. The second line contains *n* space-separated integers: *k*1,<=*k*2,<=...,<=*k**n* (1<=β€<=*k**i*<=β€<=100), where *k**i* is the number of people in the queue to the *i*-th cashier.
The *i*-th of the next *n* lines contains *k**i*... | Print a single integer β the minimum number of seconds Vasya needs to get to the cashier. | [
"1\n1\n1\n",
"4\n1 4 3 2\n100\n1 2 2 3\n1 9 1\n7 8\n"
] | [
"20\n",
"100\n"
] | In the second test sample, if Vasya goes to the first queue, he gets to the cashier in 100Β·5β+β15β=β515 seconds. But if he chooses the second queue, he will need 1Β·5β+β2Β·5β+β2Β·5β+β3Β·5β+β4Β·15β=β100 seconds. He will need 1Β·5β+β9Β·5β+β1Β·5β+β3Β·15β=β100 seconds for the third one and 7Β·5β+β8Β·5β+β2Β·15β=β105 seconds for the fou... | 500 | [
{
"input": "1\n1\n1",
"output": "20"
},
{
"input": "4\n1 4 3 2\n100\n1 2 2 3\n1 9 1\n7 8",
"output": "100"
},
{
"input": "4\n5 4 5 5\n3 1 3 1 2\n3 1 1 3\n1 1 1 2 2\n2 2 1 1 3",
"output": "100"
},
{
"input": "5\n5 3 6 6 4\n7 5 3 3 9\n6 8 2\n1 10 8 5 9 2\n9 7 8 5 9 10\n9 8 3 3"... | 1,667,661,790 | 2,147,483,647 | Python 3 | OK | TESTS | 20 | 46 | 0 | n = int(input())
input()
times = []
for i in range(n):
x = [int(i) for i in input().split()]
times.append((sum(x)*5) + len(x)*15)
print(min(times))
| Title: Line to Cashier
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Vasya went to the supermarket to get some groceries. He walked about the supermarket for a long time and got a basket full of products. Now he needs to choose the cashier to pay for the products.
There are *n* c... | ```python
n = int(input())
input()
times = []
for i in range(n):
x = [int(i) for i in input().split()]
times.append((sum(x)*5) + len(x)*15)
print(min(times))
``` | 3 | |
776 | B | Sherlock and his girlfriend | PROGRAMMING | 1,200 | [
"constructive algorithms",
"number theory"
] | null | null | Sherlock has a new girlfriend (so unlike him!). Valentine's day is coming and he wants to gift her some jewelry.
He bought *n* pieces of jewelry. The *i*-th piece has price equal to *i*<=+<=1, that is, the prices of the jewelry are 2,<=3,<=4,<=... *n*<=+<=1.
Watson gave Sherlock a challenge to color these jewelry pie... | The only line contains single integer *n* (1<=β€<=*n*<=β€<=100000)Β β the number of jewelry pieces. | The first line of output should contain a single integer *k*, the minimum number of colors that can be used to color the pieces of jewelry with the given constraints.
The next line should consist of *n* space-separated integers (between 1 and *k*) that specify the color of each piece in the order of increasing price.
... | [
"3\n",
"4\n"
] | [
"2\n1 1 2 ",
"2\n2 1 1 2\n"
] | In the first input, the colors for first, second and third pieces of jewelry having respective prices 2, 3 and 4 are 1, 1 and 2 respectively.
In this case, as 2 is a prime divisor of 4, colors of jewelry having prices 2 and 4 must be distinct. | 1,000 | [
{
"input": "3",
"output": "2\n1 1 2 "
},
{
"input": "4",
"output": "2\n1 1 2 1 "
},
{
"input": "17",
"output": "2\n1 1 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 "
},
{
"input": "25",
"output": "2\n1 1 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 2 "
},
{
"input": "85",
"ou... | 1,644,469,331 | 2,147,483,647 | Python 3 | OK | TESTS | 53 | 233 | 307,200 | n = int(input())
sieve = [False]*(n+2)
two = False
for i in range(2,n+2):
if not sieve[i]:
for j in range(2,(n+1)//i + 1): # To hit one below
sieve[i*j] = True
two = True
# paint prime numbers with different and others with different colors
if two:
print(2)
else:
print(1)
for... | Title: Sherlock and his girlfriend
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Sherlock has a new girlfriend (so unlike him!). Valentine's day is coming and he wants to gift her some jewelry.
He bought *n* pieces of jewelry. The *i*-th piece has price equal to *i*<=+<=1, that is, the ... | ```python
n = int(input())
sieve = [False]*(n+2)
two = False
for i in range(2,n+2):
if not sieve[i]:
for j in range(2,(n+1)//i + 1): # To hit one below
sieve[i*j] = True
two = True
# paint prime numbers with different and others with different colors
if two:
print(2)
else:
pr... | 3 | |
716 | A | Crazy Computer | PROGRAMMING | 800 | [
"implementation"
] | null | null | ZS the Coder is coding on a crazy computer. If you don't type in a word for a *c* consecutive seconds, everything you typed disappear!
More formally, if you typed a word at second *a* and then the next word at second *b*, then if *b*<=-<=*a*<=β€<=*c*, just the new word is appended to other words on the screen. If *b*<... | The first line contains two integers *n* and *c* (1<=β€<=*n*<=β€<=100<=000,<=1<=β€<=*c*<=β€<=109)Β β the number of words ZS the Coder typed and the crazy computer delay respectively.
The next line contains *n* integers *t*1,<=*t*2,<=...,<=*t**n* (1<=β€<=*t*1<=<<=*t*2<=<<=...<=<<=*t**n*<=β€<=109), where *t**i* denote... | Print a single positive integer, the number of words that remain on the screen after all *n* words was typed, in other words, at the second *t**n*. | [
"6 5\n1 3 8 14 19 20\n",
"6 1\n1 3 5 7 9 10\n"
] | [
"3",
"2"
] | The first sample is already explained in the problem statement.
For the second sample, after typing the first word at the second 1, it disappears because the next word is typed at the second 3 and 3β-β1β>β1. Similarly, only 1 word will remain at the second 9. Then, a word is typed at the second 10, so there will be... | 500 | [
{
"input": "6 5\n1 3 8 14 19 20",
"output": "3"
},
{
"input": "6 1\n1 3 5 7 9 10",
"output": "2"
},
{
"input": "1 1\n1000000000",
"output": "1"
},
{
"input": "5 5\n1 7 12 13 14",
"output": "4"
},
{
"input": "2 1000000000\n1 1000000000",
"output": "2"
},
{
... | 1,629,310,530 | 2,147,483,647 | Python 3 | OK | TESTS | 81 | 124 | 15,155,200 | #loser707
n,c=map(int,input().split())
a=list(map(int,input().split()))
l=[]
ans=0
for x,y in zip(a,a[1:]):
l.append(y-x)
for i in l:
if i<=c:
ans=ans+1
else:
ans=0
print(ans+1) | Title: Crazy Computer
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
ZS the Coder is coding on a crazy computer. If you don't type in a word for a *c* consecutive seconds, everything you typed disappear!
More formally, if you typed a word at second *a* and then the next word at second *... | ```python
#loser707
n,c=map(int,input().split())
a=list(map(int,input().split()))
l=[]
ans=0
for x,y in zip(a,a[1:]):
l.append(y-x)
for i in l:
if i<=c:
ans=ans+1
else:
ans=0
print(ans+1)
``` | 3 | |
265 | A | Colorful Stones (Simplified Edition) | PROGRAMMING | 800 | [
"implementation"
] | null | null | There is a sequence of colorful stones. The color of each stone is one of red, green, or blue. You are given a string *s*. The *i*-th (1-based) character of *s* represents the color of the *i*-th stone. If the character is "R", "G", or "B", the color of the corresponding stone is red, green, or blue, respectively.
Ini... | The input contains two lines. The first line contains the string *s* (1<=β€<=|*s*|<=β€<=50). The second line contains the string *t* (1<=β€<=|*t*|<=β€<=50). The characters of each string will be one of "R", "G", or "B". It is guaranteed that Liss don't move out of the sequence. | Print the final 1-based position of Liss in a single line. | [
"RGB\nRRR\n",
"RRRBGBRBBB\nBBBRR\n",
"BRRBGBRGRBGRGRRGGBGBGBRGBRGRGGGRBRRRBRBBBGRRRGGBBB\nBBRBGGRGRGBBBRBGRBRBBBBRBRRRBGBBGBBRRBBGGRBRRBRGRB\n"
] | [
"2\n",
"3\n",
"15\n"
] | none | 500 | [
{
"input": "RGB\nRRR",
"output": "2"
},
{
"input": "RRRBGBRBBB\nBBBRR",
"output": "3"
},
{
"input": "BRRBGBRGRBGRGRRGGBGBGBRGBRGRGGGRBRRRBRBBBGRRRGGBBB\nBBRBGGRGRGBBBRBGRBRBBBBRBRRRBGBBGBBRRBBGGRBRRBRGRB",
"output": "15"
},
{
"input": "G\nRRBBRBRRBR",
"output": "1"
},
... | 1,618,691,464 | 2,147,483,647 | Python 3 | OK | TESTS | 19 | 124 | 0 | s = input()
t = list(input())
move = 1
i = 0
while t:
if t[0] == s[i]:
move += 1
i += 1
t.pop(0)
print(move) | Title: Colorful Stones (Simplified Edition)
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There is a sequence of colorful stones. The color of each stone is one of red, green, or blue. You are given a string *s*. The *i*-th (1-based) character of *s* represents the color of the *i*-th st... | ```python
s = input()
t = list(input())
move = 1
i = 0
while t:
if t[0] == s[i]:
move += 1
i += 1
t.pop(0)
print(move)
``` | 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,689,740,765 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 62 | 0 | n=list(map(int, input().split()))
st=set(n)
print(len(n)-len(st)) | 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
n=list(map(int, input().split()))
st=set(n)
print(len(n)-len(st))
``` | 3 | |
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,682,605,273 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 122 | 0 | word = input()
big_letter = 0
small_letter = 0
for i in word:
if ord(i) < 95:
big_letter += 1
else:
small_letter += 1
print(word.lower() if small_letter >= big_letter else word.upper()) | Title: Word
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it ei... | ```python
word = input()
big_letter = 0
small_letter = 0
for i in word:
if ord(i) < 95:
big_letter += 1
else:
small_letter += 1
print(word.lower() if small_letter >= big_letter else word.upper())
``` | 3.9695 |
977 | A | Wrong Subtraction | PROGRAMMING | 800 | [
"implementation"
] | null | null | Little girl Tanya is learning how to decrease a number by one, but she does it wrong with a number consisting of two or more digits. Tanya subtracts one from a number by the following algorithm:
- if the last digit of the number is non-zero, she decreases the number by one; - if the last digit of the number is zero,... | The first line of the input contains two integer numbers $n$ and $k$ ($2 \le n \le 10^9$, $1 \le k \le 50$) β the number from which Tanya will subtract and the number of subtractions correspondingly. | Print one integer number β the result of the decreasing $n$ by one $k$ times.
It is guaranteed that the result will be positive integer number. | [
"512 4\n",
"1000000000 9\n"
] | [
"50\n",
"1\n"
] | The first example corresponds to the following sequence: $512 \rightarrow 511 \rightarrow 510 \rightarrow 51 \rightarrow 50$. | 0 | [
{
"input": "512 4",
"output": "50"
},
{
"input": "1000000000 9",
"output": "1"
},
{
"input": "131203 11",
"output": "12"
},
{
"input": "999999999 50",
"output": "9999"
},
{
"input": "999999999 49",
"output": "99990"
},
{
"input": "131203 9",
"outpu... | 1,696,433,373 | 2,147,483,647 | Python 3 | OK | TESTS | 11 | 46 | 0 | s = input()
l = list(map(int, s.split()))
for i in range(0,l[1]):
if(l[0]%10==0):
l[0]=l[0]//10
else:
l[0]=l[0]-1
print(l[0])
| Title: Wrong Subtraction
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little girl Tanya is learning how to decrease a number by one, but she does it wrong with a number consisting of two or more digits. Tanya subtracts one from a number by the following algorithm:
- if the last digit ... | ```python
s = input()
l = list(map(int, s.split()))
for i in range(0,l[1]):
if(l[0]%10==0):
l[0]=l[0]//10
else:
l[0]=l[0]-1
print(l[0])
``` | 3 | |
920 | B | Tea Queue | PROGRAMMING | 1,200 | [
"implementation"
] | null | null | Recently *n* students from city S moved to city P to attend a programming camp.
They moved there by train. In the evening, all students in the train decided that they want to drink some tea. Of course, no two people can use the same teapot simultaneously, so the students had to form a queue to get their tea.
*i*-th s... | The first line contains one integer *t* β the number of test cases to solve (1<=β€<=*t*<=β€<=1000).
Then *t* test cases follow. The first line of each test case contains one integer *n* (1<=β€<=*n*<=β€<=1000) β the number of students.
Then *n* lines follow. Each line contains two integer *l**i*, *r**i* (1<=β€<=*l**i*<=β€<=... | For each test case print *n* integers. *i*-th of them must be equal to the second when *i*-th student gets his tea, or 0 if he leaves without tea. | [
"2\n2\n1 3\n1 4\n3\n1 5\n1 1\n2 3\n"
] | [
"1 2 \n1 0 2 \n"
] | The example contains 2 tests:
1. During 1-st second, students 1 and 2 come to the queue, and student 1 gets his tea. Student 2 gets his tea during 2-nd second. 1. During 1-st second, students 1 and 2 come to the queue, student 1 gets his tea, and student 2 leaves without tea. During 2-nd second, student 3 comes and ... | 0 | [
{
"input": "2\n2\n1 3\n1 4\n3\n1 5\n1 1\n2 3",
"output": "1 2 \n1 0 2 "
},
{
"input": "19\n1\n1 1\n1\n1 2\n1\n1 1000\n1\n1 2000\n1\n2 2\n1\n2 3\n1\n2 1000\n1\n2 2000\n1\n1999 1999\n1\n1999 2000\n1\n2000 2000\n2\n1 1\n1 1\n2\n1 1\n1 2\n2\n1 2\n1 1\n2\n1 2000\n1 1\n2\n1 1\n1 2000\n2\n1 2000\n2 2\n2\n2... | 1,517,589,086 | 6,986 | Python 3 | OK | TESTS | 8 | 62 | 5,632,000 | t = int(input())
r = []
l = []
for i in range(t):
n = int(input())
for j in range(n):
lcurr, rcurr = map(int, input().split())
if j == 0:
t = lcurr + 1
print(t - 1, end=' ')
else:
if t > lcurr:
if rcurr >= t:
... | Title: Tea Queue
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Recently *n* students from city S moved to city P to attend a programming camp.
They moved there by train. In the evening, all students in the train decided that they want to drink some tea. Of course, no two people can use ... | ```python
t = int(input())
r = []
l = []
for i in range(t):
n = int(input())
for j in range(n):
lcurr, rcurr = map(int, input().split())
if j == 0:
t = lcurr + 1
print(t - 1, end=' ')
else:
if t > lcurr:
if rcurr >= t:
... | 3 | |
61 | A | Ultra-Fast Mathematician | PROGRAMMING | 800 | [
"implementation"
] | A. Ultra-Fast Mathematician | 2 | 256 | Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 1018 numbers in a single second.
One day in 230 AD Shapur was trying to find out if any one can possibly do... | There are two lines in each input. Each of them contains a single number. It is guaranteed that the numbers are made from 0 and 1 only and that their length is same. The numbers may start with 0. The length of each number doesn't exceed 100. | Write one line β the corresponding answer. Do not omit the leading 0s. | [
"1010100\n0100101\n",
"000\n111\n",
"1110\n1010\n",
"01110\n01100\n"
] | [
"1110001\n",
"111\n",
"0100\n",
"00010\n"
] | none | 500 | [
{
"input": "1010100\n0100101",
"output": "1110001"
},
{
"input": "000\n111",
"output": "111"
},
{
"input": "1110\n1010",
"output": "0100"
},
{
"input": "01110\n01100",
"output": "00010"
},
{
"input": "011101\n000001",
"output": "011100"
},
{
"input": "... | 1,449,845,340 | 2,147,483,647 | Python 3 | OK | TESTS | 102 | 62 | 0 | N=input()
M=input()
l=len(N)
for i in range (l):
x=int(N[i])
y=int(M[i])
if x==y:
d=0
if x!=y:
d=1
print(d,end='')
| 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
N=input()
M=input()
l=len(N)
for i in range (l):
x=int(N[i])
y=int(M[i])
if x==y:
d=0
if x!=y:
d=1
print(d,end='')
``` | 3.9845 |
939 | A | Love Triangle | PROGRAMMING | 800 | [
"graphs"
] | null | null | As you could know there are no male planes nor female planes. However, each plane on Earth likes some other plane. There are *n* planes on Earth, numbered from 1 to *n*, and the plane with number *i* likes the plane with number *f**i*, where 1<=β€<=*f**i*<=β€<=*n* and *f**i*<=β <=*i*.
We call a love triangle a situation ... | The first line contains a single integer *n* (2<=β€<=*n*<=β€<=5000)Β β the number of planes.
The second line contains *n* integers *f*1,<=*f*2,<=...,<=*f**n* (1<=β€<=*f**i*<=β€<=*n*, *f**i*<=β <=*i*), meaning that the *i*-th plane likes the *f**i*-th. | Output Β«YESΒ» if there is a love triangle consisting of planes on Earth. Otherwise, output Β«NOΒ».
You can output any letter in lower case or in upper case. | [
"5\n2 4 5 1 3\n",
"5\n5 5 5 5 1\n"
] | [
"YES\n",
"NO\n"
] | In first example plane 2 likes plane 4, plane 4 likes plane 1, plane 1 likes plane 2 and that is a love triangle.
In second example there are no love triangles. | 500 | [
{
"input": "5\n2 4 5 1 3",
"output": "YES"
},
{
"input": "5\n5 5 5 5 1",
"output": "NO"
},
{
"input": "3\n3 1 2",
"output": "YES"
},
{
"input": "10\n4 10 9 5 3 1 5 10 6 4",
"output": "NO"
},
{
"input": "10\n5 5 4 9 10 9 9 5 3 1",
"output": "YES"
},
{
"... | 1,679,633,526 | 2,147,483,647 | Python 3 | OK | TESTS | 16 | 46 | 0 | def res():
n = int(input())
planes = list(map(int, input().strip().split()))[:n]
for i in range(n):
a = planes[i]
b = planes[a-1]
c = planes[b-1]
if c == i+1:
print("YES")
break
else:
print("NO")
res()
| Title: Love Triangle
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
As you could know there are no male planes nor female planes. However, each plane on Earth likes some other plane. There are *n* planes on Earth, numbered from 1 to *n*, and the plane with number *i* likes the plane with ... | ```python
def res():
n = int(input())
planes = list(map(int, input().strip().split()))[:n]
for i in range(n):
a = planes[i]
b = planes[a-1]
c = planes[b-1]
if c == i+1:
print("YES")
break
else:
print("NO")
res()
``` | 3 | |
262 | A | Roma and Lucky Numbers | PROGRAMMING | 800 | [
"implementation"
] | null | null | Roma (a popular Russian name that means 'Roman') loves the Little Lvov Elephant's lucky numbers.
Let us remind you that lucky numbers are positive integers whose decimal representation only contains lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Roma's got *n* positive integer... | The first line contains two integers *n*, *k* (1<=β€<=*n*,<=*k*<=β€<=100). The second line contains *n* integers *a**i* (1<=β€<=*a**i*<=β€<=109) β the numbers that Roma has.
The numbers in the lines are separated by single spaces. | In a single line print a single integer β the answer to the problem. | [
"3 4\n1 2 4\n",
"3 2\n447 44 77\n"
] | [
"3\n",
"2\n"
] | In the first sample all numbers contain at most four lucky digits, so the answer is 3.
In the second sample number 447 doesn't fit in, as it contains more than two lucky digits. All other numbers are fine, so the answer is 2. | 500 | [
{
"input": "3 4\n1 2 4",
"output": "3"
},
{
"input": "3 2\n447 44 77",
"output": "2"
},
{
"input": "2 2\n507978501 180480073",
"output": "2"
},
{
"input": "9 6\n655243746 167613748 1470546 57644035 176077477 56984809 44677 215706823 369042089",
"output": "9"
},
{
... | 1,588,917,850 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 248 | 6,656,000 | # bsdk idhar kya dekhne ko aaya hai, khud kr!!!
# from math import *
# from itertools import *
# import random
n, k = map(int, input().split())
arr = list(map(str, input().split()))
count_ = 0
for i in arr:
if (i.count("4") + i.count("7")) > k:
continue
else:
count_ += 1
print(count_... | Title: Roma and Lucky Numbers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Roma (a popular Russian name that means 'Roman') loves the Little Lvov Elephant's lucky numbers.
Let us remind you that lucky numbers are positive integers whose decimal representation only contains lucky digits... | ```python
# bsdk idhar kya dekhne ko aaya hai, khud kr!!!
# from math import *
# from itertools import *
# import random
n, k = map(int, input().split())
arr = list(map(str, input().split()))
count_ = 0
for i in arr:
if (i.count("4") + i.count("7")) > k:
continue
else:
count_ += 1
pr... | 3 | |
899 | A | Splitting in Teams | PROGRAMMING | 800 | [
"constructive algorithms",
"greedy",
"math"
] | null | null | There were *n* groups of students which came to write a training contest. A group is either one person who can write the contest with anyone else, or two people who want to write the contest in the same team.
The coach decided to form teams of exactly three people for this training. Determine the maximum number of tea... | The first line contains single integer *n* (2<=β€<=*n*<=β€<=2Β·105) β the number of groups.
The second line contains a sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (1<=β€<=*a**i*<=β€<=2), where *a**i* is the number of people in group *i*. | Print the maximum number of teams of three people the coach can form. | [
"4\n1 1 2 1\n",
"2\n2 2\n",
"7\n2 2 2 1 1 1 1\n",
"3\n1 1 1\n"
] | [
"1\n",
"0\n",
"3\n",
"1\n"
] | In the first example the coach can form one team. For example, he can take students from the first, second and fourth groups.
In the second example he can't make a single team.
In the third example the coach can form three teams. For example, he can do this in the following way:
- The first group (of two people) an... | 500 | [
{
"input": "4\n1 1 2 1",
"output": "1"
},
{
"input": "2\n2 2",
"output": "0"
},
{
"input": "7\n2 2 2 1 1 1 1",
"output": "3"
},
{
"input": "3\n1 1 1",
"output": "1"
},
{
"input": "3\n2 2 2",
"output": "0"
},
{
"input": "3\n1 2 1",
"output": "1"
}... | 1,628,673,249 | 2,147,483,647 | Python 3 | OK | TESTS | 67 | 124 | 11,059,200 | n = int(input())
a = list(map(int, input().split()))
ones,twos = 0,0
for i in a:
if i == 1:
ones += 1
else:
twos += 1
if twos == 0:
print(ones//3)
elif ones == 0:
print(0)
else:
mn = min(ones,twos)
print(mn + (ones - mn)//3) | Title: Splitting in Teams
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There were *n* groups of students which came to write a training contest. A group is either one person who can write the contest with anyone else, or two people who want to write the contest in the same team.
The co... | ```python
n = int(input())
a = list(map(int, input().split()))
ones,twos = 0,0
for i in a:
if i == 1:
ones += 1
else:
twos += 1
if twos == 0:
print(ones//3)
elif ones == 0:
print(0)
else:
mn = min(ones,twos)
print(mn + (ones - mn)//3)
``` | 3 | |
540 | A | Combination Lock | PROGRAMMING | 800 | [
"implementation"
] | null | null | Scrooge McDuck keeps his most treasured savings in a home safe with a combination lock. Each time he wants to put there the treasures that he's earned fair and square, he has to open the lock.
The combination lock is represented by *n* rotating disks with digits from 0 to 9 written on them. Scrooge McDuck has to turn ... | The first line contains a single integer *n* (1<=β€<=*n*<=β€<=1000)Β β the number of disks on the combination lock.
The second line contains a string of *n* digitsΒ β the original state of the disks.
The third line contains a string of *n* digitsΒ β Scrooge McDuck's combination that opens the lock. | Print a single integerΒ β the minimum number of moves Scrooge McDuck needs to open the lock. | [
"5\n82195\n64723\n"
] | [
"13\n"
] | In the sample he needs 13 moves:
- 1 disk: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/b8967f65a723782358b93eff9ce69f336817cf70.png" style="max-width: 100.0%;max-height: 100.0%;"/> - 2 disk: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/07fa58573ece0d32... | 500 | [
{
"input": "5\n82195\n64723",
"output": "13"
},
{
"input": "12\n102021090898\n010212908089",
"output": "16"
},
{
"input": "1\n8\n1",
"output": "3"
},
{
"input": "2\n83\n57",
"output": "7"
},
{
"input": "10\n0728592530\n1362615763",
"output": "27"
},
{
... | 1,609,057,577 | 2,147,483,647 | Python 3 | OK | TESTS | 43 | 109 | 307,200 | n=int(input())
a=list(input())
if a[len(a)-1]=='\r':
a.pop()
b=list(input())
if b[len(b)-1]=='\r':
b.pop()
for i in range(len(a)):
a[i]=int(a[i])
for i in range(len(b)):
b[i]=int(b[i])
s=0
for i in range(len(a)):
s1=max(a[i],b[i])-min(a[i],b[i])
s2=(a[i]+10)-b[i]
s3=(b[i]+10)-... | Title: Combination Lock
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Scrooge McDuck keeps his most treasured savings in a home safe with a combination lock. Each time he wants to put there the treasures that he's earned fair and square, he has to open the lock.
The combination lock is ... | ```python
n=int(input())
a=list(input())
if a[len(a)-1]=='\r':
a.pop()
b=list(input())
if b[len(b)-1]=='\r':
b.pop()
for i in range(len(a)):
a[i]=int(a[i])
for i in range(len(b)):
b[i]=int(b[i])
s=0
for i in range(len(a)):
s1=max(a[i],b[i])-min(a[i],b[i])
s2=(a[i]+10)-b[i]
s3=... | 3 | |
534 | B | Covered Path | PROGRAMMING | 1,400 | [
"dp",
"greedy",
"math"
] | null | null | The on-board computer on Polycarp's car measured that the car speed at the beginning of some section of the path equals *v*1 meters per second, and in the end it is *v*2 meters per second. We know that this section of the route took exactly *t* seconds to pass.
Assuming that at each of the seconds the speed is constan... | The first line contains two integers *v*1 and *v*2 (1<=β€<=*v*1,<=*v*2<=β€<=100) β the speeds in meters per second at the beginning of the segment and at the end of the segment, respectively.
The second line contains two integers *t* (2<=β€<=*t*<=β€<=100) β the time when the car moves along the segment in seconds, *d* (0<... | Print the maximum possible length of the path segment in meters. | [
"5 6\n4 2\n",
"10 10\n10 0\n"
] | [
"26",
"100"
] | In the first sample the sequence of speeds of Polycarpus' car can look as follows: 5, 7, 8, 6. Thus, the total path is 5β+β7β+β8β+β6β=β26 meters.
In the second sample, as *d*β=β0, the car covers the whole segment at constant speed *v*β=β10. In *t*β=β10 seconds it covers the distance of 100 meters. | 1,000 | [
{
"input": "5 6\n4 2",
"output": "26"
},
{
"input": "10 10\n10 0",
"output": "100"
},
{
"input": "87 87\n2 10",
"output": "174"
},
{
"input": "1 11\n6 2",
"output": "36"
},
{
"input": "100 10\n10 10",
"output": "550"
},
{
"input": "1 1\n100 10",
"o... | 1,584,391,590 | 2,147,483,647 | PyPy 3 | OK | TESTS | 64 | 155 | 0 | # maa chudaaye duniya
v1, v2 = sorted(list(map(int, input().split())))
t, d = map(int, input().split())
s = v1 + v2
for i in range(1, t-1):
s += min(v1 + d*i, v2 + d*(t-i-1))
print(s) | Title: Covered Path
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The on-board computer on Polycarp's car measured that the car speed at the beginning of some section of the path equals *v*1 meters per second, and in the end it is *v*2 meters per second. We know that this section of the ... | ```python
# maa chudaaye duniya
v1, v2 = sorted(list(map(int, input().split())))
t, d = map(int, input().split())
s = v1 + v2
for i in range(1, t-1):
s += min(v1 + d*i, v2 + d*(t-i-1))
print(s)
``` | 3 | |
302 | A | Eugeny and Array | PROGRAMMING | 800 | [
"implementation"
] | null | null | Eugeny has array *a*<==<=*a*1,<=*a*2,<=...,<=*a**n*, consisting of *n* integers. Each integer *a**i* equals to -1, or to 1. Also, he has *m* queries:
- Query number *i* is given as a pair of integers *l**i*, *r**i* (1<=β€<=*l**i*<=β€<=*r**i*<=β€<=*n*). - The response to the query will be integer 1, if the elements of a... | The first line contains integers *n* and *m* (1<=β€<=*n*,<=*m*<=β€<=2Β·105). The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (*a**i*<==<=-1,<=1). Next *m* lines contain Eugene's queries. The *i*-th line contains integers *l**i*,<=*r**i* (1<=β€<=*l**i*<=β€<=*r**i*<=β€<=*n*). | Print *m* integers β the responses to Eugene's queries in the order they occur in the input. | [
"2 3\n1 -1\n1 1\n1 2\n2 2\n",
"5 5\n-1 1 1 1 -1\n1 1\n2 3\n3 5\n2 5\n1 5\n"
] | [
"0\n1\n0\n",
"0\n1\n0\n1\n0\n"
] | none | 500 | [
{
"input": "2 3\n1 -1\n1 1\n1 2\n2 2",
"output": "0\n1\n0"
},
{
"input": "5 5\n-1 1 1 1 -1\n1 1\n2 3\n3 5\n2 5\n1 5",
"output": "0\n1\n0\n1\n0"
},
{
"input": "3 3\n1 1 1\n2 2\n1 1\n1 1",
"output": "0\n0\n0"
},
{
"input": "4 4\n-1 -1 -1 -1\n1 3\n1 2\n1 2\n1 1",
"output": "... | 1,511,181,729 | 2,147,483,647 | Python 3 | OK | TESTS | 38 | 889 | 10,854,400 | n,m = map(int,input().split())
a = list(map(int, input().split()))
b = a.count(1)
c = min(b,n-b)
s = ''
for i in range(m):
left,right = map(int, input().split())
length = right - left + 1
if length % 2 or length //2 > c:
s += "0\n"
else:
s += "1\n"
print(s)
| Title: Eugeny and Array
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Eugeny has array *a*<==<=*a*1,<=*a*2,<=...,<=*a**n*, consisting of *n* integers. Each integer *a**i* equals to -1, or to 1. Also, he has *m* queries:
- Query number *i* is given as a pair of integers *l**i*, *r**i* (... | ```python
n,m = map(int,input().split())
a = list(map(int, input().split()))
b = a.count(1)
c = min(b,n-b)
s = ''
for i in range(m):
left,right = map(int, input().split())
length = right - left + 1
if length % 2 or length //2 > c:
s += "0\n"
else:
s += "1\n"
print(s)
``` | 3 | |
13 | A | Numbers | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | A. Numbers | 1 | 64 | Little Petya likes numbers a lot. He found that number 123 in base 16 consists of two digits: the first is 7 and the second is 11. So the sum of digits of 123 in base 16 is equal to 18.
Now he wonders what is an average value of sum of digits of the number *A* written in all bases from 2 to *A*<=-<=1.
Note that all c... | Input contains one integer number *A* (3<=β€<=*A*<=β€<=1000). | Output should contain required average value in format Β«X/YΒ», where X is the numerator and Y is the denominator. | [
"5\n",
"3\n"
] | [
"7/3\n",
"2/1\n"
] | In the first sample number 5 written in all bases from 2 to 4 looks so: 101, 12, 11. Sums of digits are 2, 3 and 2, respectively. | 0 | [
{
"input": "5",
"output": "7/3"
},
{
"input": "3",
"output": "2/1"
},
{
"input": "1000",
"output": "90132/499"
},
{
"input": "927",
"output": "155449/925"
},
{
"input": "260",
"output": "6265/129"
},
{
"input": "131",
"output": "3370/129"
},
{
... | 1,650,791,389 | 2,147,483,647 | Python 3 | OK | TESTS | 99 | 92 | 0 | a=int(input())
djel=[2, 3, 5, 7, 11, 13, 17, 19, 23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97]
zbr,br=0,0
for i in range(2,a):
br+=1
x=a
ost=[]
while x>0:
ost.append(x%i)
x=x//i
zbr+=sum(ost)
for i in djel:
while zbr%i==0 and br%i==0:
... | Title: Numbers
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
Little Petya likes numbers a lot. He found that number 123 in base 16 consists of two digits: the first is 7 and the second is 11. So the sum of digits of 123 in base 16 is equal to 18.
Now he wonders what is an average value of su... | ```python
a=int(input())
djel=[2, 3, 5, 7, 11, 13, 17, 19, 23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97]
zbr,br=0,0
for i in range(2,a):
br+=1
x=a
ost=[]
while x>0:
ost.append(x%i)
x=x//i
zbr+=sum(ost)
for i in djel:
while zbr%i==0 and br%i... | 3.954 |
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,579,293,512 | 2,147,483,647 | PyPy 3 | OK | TESTS | 63 | 140 | 0 | from sys import stdin
n,d=map(int,stdin.readline().split())
s=input()
#
last = 0
jump = 0
possible = True
while last<n-1:
for c in range(min(last+d,n-1),last,-1):
if s[c]=='1':
jump += 1
last = c
break
else:
possible = False
break
if possible:
print(jump)
else:
print(-1) | 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 sys import stdin
n,d=map(int,stdin.readline().split())
s=input()
#
last = 0
jump = 0
possible = True
while last<n-1:
for c in range(min(last+d,n-1),last,-1):
if s[c]=='1':
jump += 1
last = c
break
else:
possible = False
break
if possible:
print(jump)
else:
pri... | 3 | |
385 | B | Bear and Strings | PROGRAMMING | 1,200 | [
"brute force",
"greedy",
"implementation",
"math",
"strings"
] | null | null | The bear has a string *s*<==<=*s*1*s*2... *s*|*s*| (record |*s*| is the string's length), consisting of lowercase English letters. The bear wants to count the number of such pairs of indices *i*,<=*j* (1<=β€<=*i*<=β€<=*j*<=β€<=|*s*|), that string *x*(*i*,<=*j*)<==<=*s**i**s**i*<=+<=1... *s**j* contains at least one string... | The first line contains a non-empty string *s* (1<=β€<=|*s*|<=β€<=5000). It is guaranteed that the string only consists of lowercase English letters. | Print a single number β the answer to the problem. | [
"bearbtear\n",
"bearaabearc\n"
] | [
"6\n",
"20\n"
] | In the first sample, the following pairs (*i*,β*j*) match: (1,β4),β(1,β5),β(1,β6),β(1,β7),β(1,β8),β(1,β9).
In the second sample, the following pairs (*i*,β*j*) match: (1,ββ4),β(1,ββ5),β(1,ββ6),β(1,ββ7),β(1,ββ8),β(1,ββ9),β(1,ββ10),β(1,ββ11),β(2,ββ10),β(2,ββ11),β(3,ββ10),β(3,ββ11),β(4,ββ10),β(4,ββ11),β(5,ββ10),β(5,ββ11)... | 1,000 | [
{
"input": "bearbtear",
"output": "6"
},
{
"input": "bearaabearc",
"output": "20"
},
{
"input": "pbearbearhbearzqbearjkterasjhy",
"output": "291"
},
{
"input": "pbearjbearbebearnbabcffbearbearwubearjezpiorrbearbearjbdlbearbearqbearjbearwipmsbearoaftrsebearzsnqb",
"output"... | 1,532,446,423 | 2,147,483,647 | Python 3 | OK | TESTS | 43 | 171 | 716,800 | import re
s = input()
bears = [-1] + [m.start() for m in re.finditer('bear', s)]
sol = 0
for i in range(1, len(bears)):
sol += (bears[i] - bears[i-1]) * (len(s) - bears[i] - 3)
print(sol)
| Title: Bear and Strings
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The bear has a string *s*<==<=*s*1*s*2... *s*|*s*| (record |*s*| is the string's length), consisting of lowercase English letters. The bear wants to count the number of such pairs of indices *i*,<=*j* (1<=β€<=*i*<=β€<=*j... | ```python
import re
s = input()
bears = [-1] + [m.start() for m in re.finditer('bear', s)]
sol = 0
for i in range(1, len(bears)):
sol += (bears[i] - bears[i-1]) * (len(s) - bears[i] - 3)
print(sol)
``` | 3 | |
58 | A | Chat room | PROGRAMMING | 1,000 | [
"greedy",
"strings"
] | A. Chat room | 1 | 256 | Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word "hello". For example, ... | The first and only line contains the word *s*, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters. | If Vasya managed to say hello, print "YES", otherwise print "NO". | [
"ahhellllloou\n",
"hlelo\n"
] | [
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "ahhellllloou",
"output": "YES"
},
{
"input": "hlelo",
"output": "NO"
},
{
"input": "helhcludoo",
"output": "YES"
},
{
"input": "hehwelloho",
"output": "YES"
},
{
"input": "pnnepelqomhhheollvlo",
"output": "YES"
},
{
"input": "tymbzjyqhymeda... | 1,551,035,373 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 109 | 0 | x = input()
h = 'hello'
z, count = 0, 0
for i in range(len(h)):
for j in range(z, len(x)):
if h[i] == x[j]:
count += 1
z = j + 1
break
if count == len(h):
print("YES")
else:
print("NO")
| Title: Chat room
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letter... | ```python
x = input()
h = 'hello'
z, count = 0, 0
for i in range(len(h)):
for j in range(z, len(x)):
if h[i] == x[j]:
count += 1
z = j + 1
break
if count == len(h):
print("YES")
else:
print("NO")
``` | 3.9455 |
680 | A | Bear and Five Cards | PROGRAMMING | 800 | [
"constructive algorithms",
"implementation"
] | null | null | A little bear Limak plays a game. He has five cards. There is one number written on each card. Each number is a positive integer.
Limak can discard (throw out) some cards. His goal is to minimize the sum of numbers written on remaining (not discarded) cards.
He is allowed to at most once discard two or three cards wi... | The only line of the input contains five integers *t*1, *t*2, *t*3, *t*4 and *t*5 (1<=β€<=*t**i*<=β€<=100)Β β numbers written on cards. | Print the minimum possible sum of numbers written on remaining cards. | [
"7 3 7 3 20\n",
"7 9 3 1 8\n",
"10 10 10 10 10\n"
] | [
"26\n",
"28\n",
"20\n"
] | In the first sample, Limak has cards with numbers 7, 3, 7, 3 and 20. Limak can do one of the following.
- Do nothing and the sum would be 7β+β3β+β7β+β3β+β20β=β40. - Remove two cards with a number 7. The remaining sum would be 3β+β3β+β20β=β26. - Remove two cards with a number 3. The remaining sum would be 7β+β7β+β20... | 500 | [
{
"input": "7 3 7 3 20",
"output": "26"
},
{
"input": "7 9 3 1 8",
"output": "28"
},
{
"input": "10 10 10 10 10",
"output": "20"
},
{
"input": "8 7 1 8 7",
"output": "15"
},
{
"input": "7 7 7 8 8",
"output": "16"
},
{
"input": "8 8 8 2 2",
"output"... | 1,696,689,936 | 2,147,483,647 | Python 3 | OK | TESTS | 48 | 46 | 0 | # Read the input numbers into a list
numbers = list(map(int, input().split()))
# Calculate the total sum of numbers
total_sum = sum(numbers)
# Initialize a variable to store the minimum possible sum
min_sum = total_sum
# Iterate through each unique number in the list
for num in set(numbers):
# Count t... | Title: Bear and Five Cards
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A little bear Limak plays a game. He has five cards. There is one number written on each card. Each number is a positive integer.
Limak can discard (throw out) some cards. His goal is to minimize the sum of numbers... | ```python
# Read the input numbers into a list
numbers = list(map(int, input().split()))
# Calculate the total sum of numbers
total_sum = sum(numbers)
# Initialize a variable to store the minimum possible sum
min_sum = total_sum
# Iterate through each unique number in the list
for num in set(numbers):
... | 3 | |
514 | B | Han Solo and Lazer Gun | PROGRAMMING | 1,400 | [
"brute force",
"data structures",
"geometry",
"implementation",
"math"
] | null | null | There are *n* Imperial stormtroopers on the field. The battle field is a plane with Cartesian coordinate system. Each stormtrooper is associated with his coordinates (*x*,<=*y*) on this plane.
Han Solo has the newest duplex lazer gun to fight these stormtroopers. It is situated at the point (*x*0,<=*y*0). In one shot... | The first line contains three integers *n*, *x*0 ΠΈ *y*0 (1<=β€<=*n*<=β€<=1000, <=-<=104<=β€<=*x*0,<=*y*0<=β€<=104) β the number of stormtroopers on the battle field and the coordinates of your gun.
Next *n* lines contain two integers each *x**i*, *y**i* (<=-<=104<=β€<=*x**i*,<=*y**i*<=β€<=104) β the coordinates of the storm... | Print a single integer β the minimum number of shots Han Solo needs to destroy all the stormtroopers. | [
"4 0 0\n1 1\n2 2\n2 0\n-1 -1\n",
"2 1 2\n1 1\n1 0\n"
] | [
"2\n",
"1\n"
] | Explanation to the first and second samples from the statement, respectively: | 1,000 | [
{
"input": "4 0 0\n1 1\n2 2\n2 0\n-1 -1",
"output": "2"
},
{
"input": "2 1 2\n1 1\n1 0",
"output": "1"
},
{
"input": "1 1 1\n0 0",
"output": "1"
},
{
"input": "2 0 0\n10000 -10000\n-10000 10000",
"output": "1"
},
{
"input": "2 0 0\n10000 -10000\n10000 10000",
... | 1,684,428,592 | 2,147,483,647 | Python 3 | OK | TESTS | 29 | 46 | 0 | n=input().split()
l=[]
count=0
for i in range (int(n[0])):
x=input().split()
if int(x[0])-int(n[1])!=0:
y=(int(x[1])-int(n[2]))/(int(x[0])-int(n[1]))
if y not in l:
l.append(y)
else:
count=1
if count==1:
print(len(l)+1)
else:
print(len(l)) | Title: Han Solo and Lazer Gun
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* Imperial stormtroopers on the field. The battle field is a plane with Cartesian coordinate system. Each stormtrooper is associated with his coordinates (*x*,<=*y*) on this plane.
Han Solo has the ... | ```python
n=input().split()
l=[]
count=0
for i in range (int(n[0])):
x=input().split()
if int(x[0])-int(n[1])!=0:
y=(int(x[1])-int(n[2]))/(int(x[0])-int(n[1]))
if y not in l:
l.append(y)
else:
count=1
if count==1:
print(len(l)+1)
else:
print(len(l))
... | 3 | |
1,006 | A | Adjacent Replacements | PROGRAMMING | 800 | [
"implementation"
] | null | null | Mishka got an integer array $a$ of length $n$ as a birthday present (what a surprise!).
Mishka doesn't like this present and wants to change it somehow. He has invented an algorithm and called it "Mishka's Adjacent Replacements Algorithm". This algorithm can be represented as a sequence of steps:
- Replace each occu... | The first line of the input contains one integer number $n$ ($1 \le n \le 1000$) β the number of elements in Mishka's birthday present (surprisingly, an array).
The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$) β the elements of the array. | Print $n$ integers β $b_1, b_2, \dots, b_n$, where $b_i$ is the final value of the $i$-th element of the array after applying "Mishka's Adjacent Replacements Algorithm" to the array $a$. Note that you cannot change the order of elements in the array. | [
"5\n1 2 4 5 10\n",
"10\n10000 10 50605065 1 5 89 5 999999999 60506056 1000000000\n"
] | [
"1 1 3 5 9\n",
"9999 9 50605065 1 5 89 5 999999999 60506055 999999999\n"
] | The first example is described in the problem statement. | 0 | [
{
"input": "5\n1 2 4 5 10",
"output": "1 1 3 5 9"
},
{
"input": "10\n10000 10 50605065 1 5 89 5 999999999 60506056 1000000000",
"output": "9999 9 50605065 1 5 89 5 999999999 60506055 999999999"
},
{
"input": "1\n999999999",
"output": "999999999"
},
{
"input": "1\n1000000000",... | 1,600,692,960 | 2,147,483,647 | PyPy 3 | OK | TESTS | 18 | 280 | 7,065,600 | # 1006A
# https://codeforces.com/problemset/problem/1006/A
def findNthMin(arr, n):
sortedArr = list(sorted(set(arr)))
return sortedArr[n-1]
cnt = int(input())
numbers = [int(i) for i in input().split(' ')]
mx = max(numbers) + 1
curMin = 0
minNth = 1
while curMin < mx:
curMin = findNthMin(number... | Title: Adjacent Replacements
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mishka got an integer array $a$ of length $n$ as a birthday present (what a surprise!).
Mishka doesn't like this present and wants to change it somehow. He has invented an algorithm and called it "Mishka's Adjace... | ```python
# 1006A
# https://codeforces.com/problemset/problem/1006/A
def findNthMin(arr, n):
sortedArr = list(sorted(set(arr)))
return sortedArr[n-1]
cnt = int(input())
numbers = [int(i) for i in input().split(' ')]
mx = max(numbers) + 1
curMin = 0
minNth = 1
while curMin < mx:
curMin = findNth... | 3 | |
337 | A | Puzzles | PROGRAMMING | 900 | [
"greedy"
] | null | null | The end of the school year is near and Ms. Manana, the teacher, will soon have to say goodbye to a yet another class. She decided to prepare a goodbye present for her *n* students and give each of them a jigsaw puzzle (which, as wikipedia states, is a tiling puzzle that requires the assembly of numerous small, often od... | The first line contains space-separated integers *n* and *m* (2<=β€<=*n*<=β€<=*m*<=β€<=50). The second line contains *m* space-separated integers *f*1,<=*f*2,<=...,<=*f**m* (4<=β€<=*f**i*<=β€<=1000) β the quantities of pieces in the puzzles sold in the shop. | Print a single integer β the least possible difference the teacher can obtain. | [
"4 6\n10 12 10 7 5 22\n"
] | [
"5\n"
] | Sample 1. The class has 4 students. The shop sells 6 puzzles. If Ms. Manana buys the first four puzzles consisting of 10, 12, 10 and 7 pieces correspondingly, then the difference between the sizes of the largest and the smallest puzzle will be equal to 5. It is impossible to obtain a smaller difference. Note that the t... | 500 | [
{
"input": "4 6\n10 12 10 7 5 22",
"output": "5"
},
{
"input": "2 2\n4 4",
"output": "0"
},
{
"input": "2 10\n4 5 6 7 8 9 10 11 12 12",
"output": "0"
},
{
"input": "4 5\n818 136 713 59 946",
"output": "759"
},
{
"input": "3 20\n446 852 783 313 549 965 40 88 86 617... | 1,679,841,440 | 2,147,483,647 | PyPy 3 | OK | TESTS | 18 | 184 | 0 | import math
n,m=map(int,input().split())
a=sorted([int(x) for x in input().split()])
best=math.inf
for i in range(m):
if n+i-1>=m:break
best=min(best,a[n+i-1]-a[i])
print(best) | Title: Puzzles
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The end of the school year is near and Ms. Manana, the teacher, will soon have to say goodbye to a yet another class. She decided to prepare a goodbye present for her *n* students and give each of them a jigsaw puzzle (which, a... | ```python
import math
n,m=map(int,input().split())
a=sorted([int(x) for x in input().split()])
best=math.inf
for i in range(m):
if n+i-1>=m:break
best=min(best,a[n+i-1]-a[i])
print(best)
``` | 3 | |
748 | A | Santa Claus and a Place in a Class | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | Santa Claus is the first who came to the Christmas Olympiad, and he is going to be the first to take his place at a desk! In the classroom there are *n* lanes of *m* desks each, and there are two working places at each of the desks. The lanes are numbered from 1 to *n* from the left to the right, the desks in a lane ar... | The only line contains three integers *n*, *m* and *k* (1<=β€<=*n*,<=*m*<=β€<=10<=000, 1<=β€<=*k*<=β€<=2*nm*)Β β the number of lanes, the number of desks in each lane and the number of Santa Claus' place. | Print two integers: the number of lane *r*, the number of desk *d*, and a character *s*, which stands for the side of the desk Santa Claus. The character *s* should be "L", if Santa Clause should sit on the left, and "R" if his place is on the right. | [
"4 3 9\n",
"4 3 24\n",
"2 4 4\n"
] | [
"2 2 L\n",
"4 3 R\n",
"1 2 R\n"
] | The first and the second samples are shown on the picture. The green place corresponds to Santa Claus' place in the first example, the blue place corresponds to Santa Claus' place in the second example.
In the third sample there are two lanes with four desks in each, and Santa Claus has the fourth place. Thus, his pla... | 500 | [
{
"input": "4 3 9",
"output": "2 2 L"
},
{
"input": "4 3 24",
"output": "4 3 R"
},
{
"input": "2 4 4",
"output": "1 2 R"
},
{
"input": "3 10 24",
"output": "2 2 R"
},
{
"input": "10 3 59",
"output": "10 3 L"
},
{
"input": "10000 10000 160845880",
"... | 1,588,078,757 | 2,147,483,647 | Python 3 | OK | TESTS | 46 | 109 | 307,200 | import math
inp1=list(map(int,input().strip().split()))[:3]
r,c,val=inp1[0],inp1[1],inp1[2]
divi=c*2
if(val % 2):
val1=val+1
dir1='L'
else:
val1=val
dir1='R'
row=math.ceil(val1/divi)
rem=val1 % divi
col=rem // 2
if(rem==0):
col=c
print(row,col,dir1,end=" ")
print() | Title: Santa Claus and a Place in a Class
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Santa Claus is the first who came to the Christmas Olympiad, and he is going to be the first to take his place at a desk! In the classroom there are *n* lanes of *m* desks each, and there are two work... | ```python
import math
inp1=list(map(int,input().strip().split()))[:3]
r,c,val=inp1[0],inp1[1],inp1[2]
divi=c*2
if(val % 2):
val1=val+1
dir1='L'
else:
val1=val
dir1='R'
row=math.ceil(val1/divi)
rem=val1 % divi
col=rem // 2
if(rem==0):
col=c
print(row,col,dir1,end=" ")
print()
``` | 3 | |
706 | B | Interesting drink | PROGRAMMING | 1,100 | [
"binary search",
"dp",
"implementation"
] | null | null | Vasiliy likes to rest after a hard work, so you may often meet him in some bar nearby. As all programmers do, he loves the famous drink "Beecola", which can be bought in *n* different shops in the city. It's known that the price of one bottle in the shop *i* is equal to *x**i* coins.
Vasiliy plans to buy his favorite ... | The first line of the input contains a single integer *n* (1<=β€<=*n*<=β€<=100<=000)Β β the number of shops in the city that sell Vasiliy's favourite drink.
The second line contains *n* integers *x**i* (1<=β€<=*x**i*<=β€<=100<=000)Β β prices of the bottles of the drink in the *i*-th shop.
The third line contains a single i... | Print *q* integers. The *i*-th of them should be equal to the number of shops where Vasiliy will be able to buy a bottle of the drink on the *i*-th day. | [
"5\n3 10 8 6 11\n4\n1\n10\n3\n11\n"
] | [
"0\n4\n1\n5\n"
] | On the first day, Vasiliy won't be able to buy a drink in any of the shops.
On the second day, Vasiliy can buy a drink in the shops 1, 2, 3 and 4.
On the third day, Vasiliy can buy a drink only in the shop number 1.
Finally, on the last day Vasiliy can buy a drink in any shop. | 1,000 | [
{
"input": "5\n3 10 8 6 11\n4\n1\n10\n3\n11",
"output": "0\n4\n1\n5"
},
{
"input": "5\n868 987 714 168 123\n10\n424\n192\n795\n873\n117\n914\n735\n158\n631\n471",
"output": "2\n2\n3\n4\n0\n4\n3\n1\n2\n2"
},
{
"input": "3\n435 482 309\n7\n245\n241\n909\n745\n980\n29\n521",
"output": "... | 1,699,952,977 | 2,147,483,647 | Python 3 | OK | TESTS | 103 | 405 | 21,913,600 | #ηιε₯οΌε·₯ε¦ι’ 2300011118
coin_list = []
result_dict = {}
index = 0
n = int(input())
price_list = sorted(list(map(int, input().split())))
q = int(input())
for i in range(q):
coin_list.append(int(input()))
coin_list_new = sorted(coin_list)
for j in range(q):
for k in range(index, n):
if price_list[... | Title: Interesting drink
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasiliy likes to rest after a hard work, so you may often meet him in some bar nearby. As all programmers do, he loves the famous drink "Beecola", which can be bought in *n* different shops in the city. It's known tha... | ```python
#ηιε₯οΌε·₯ε¦ι’ 2300011118
coin_list = []
result_dict = {}
index = 0
n = int(input())
price_list = sorted(list(map(int, input().split())))
q = int(input())
for i in range(q):
coin_list.append(int(input()))
coin_list_new = sorted(coin_list)
for j in range(q):
for k in range(index, n):
if p... | 3 | |
703 | A | Mishka and Game | PROGRAMMING | 800 | [
"implementation"
] | null | null | Mishka is a little polar bear. As known, little bears loves spending their free time playing dice for chocolates. Once in a wonderful sunny morning, walking around blocks of ice, Mishka met her friend Chris, and they started playing the game.
Rules of the game are very simple: at first number of rounds *n* is defined.... | The first line of the input contains single integer *n* *n* (1<=β€<=*n*<=β€<=100)Β β the number of game rounds.
The next *n* lines contains rounds description. *i*-th of them contains pair of integers *m**i* and *c**i* (1<=β€<=*m**i*,<=<=*c**i*<=β€<=6)Β β values on dice upper face after Mishka's and Chris' throws in *i*-th ... | If Mishka is the winner of the game, print "Mishka" (without quotes) in the only line.
If Chris is the winner of the game, print "Chris" (without quotes) in the only line.
If the result of the game is draw, print "Friendship is magic!^^" (without quotes) in the only line. | [
"3\n3 5\n2 1\n4 2\n",
"2\n6 1\n1 6\n",
"3\n1 5\n3 3\n2 2\n"
] | [
"Mishka",
"Friendship is magic!^^",
"Chris"
] | In the first sample case Mishka loses the first round, but wins second and third rounds and thus she is the winner of the game.
In the second sample case Mishka wins the first round, Chris wins the second round, and the game ends with draw with score 1:1.
In the third sample case Chris wins the first round, but there... | 500 | [
{
"input": "3\n3 5\n2 1\n4 2",
"output": "Mishka"
},
{
"input": "2\n6 1\n1 6",
"output": "Friendship is magic!^^"
},
{
"input": "3\n1 5\n3 3\n2 2",
"output": "Chris"
},
{
"input": "6\n4 1\n4 2\n5 3\n5 1\n5 3\n4 1",
"output": "Mishka"
},
{
"input": "8\n2 4\n1 4\n1 ... | 1,698,259,691 | 2,147,483,647 | Python 3 | OK | TESTS | 69 | 46 | 0 | n = int(input())
m = 0
a = 0
for i in range(n):
b,c = list(map(int,input().split()))
if b > c:
m += 1
if c > b:
a += 1
if m > a:
print("Mishka")
if a > m:
print("Chris")
if a == m:
print("Friendship is magic!^^") | Title: Mishka and Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mishka is a little polar bear. As known, little bears loves spending their free time playing dice for chocolates. Once in a wonderful sunny morning, walking around blocks of ice, Mishka met her friend Chris, and they st... | ```python
n = int(input())
m = 0
a = 0
for i in range(n):
b,c = list(map(int,input().split()))
if b > c:
m += 1
if c > b:
a += 1
if m > a:
print("Mishka")
if a > m:
print("Chris")
if a == m:
print("Friendship is magic!^^")
``` | 3 | |
701 | C | They Are Everywhere | PROGRAMMING | 1,500 | [
"binary search",
"strings",
"two pointers"
] | null | null | Sergei B., the young coach of Pokemons, has found the big house which consists of *n* flats ordered in a row from left to right. It is possible to enter each flat from the street. It is possible to go out from each flat. Also, each flat is connected with the flat to the left and the flat to the right. Flat number 1 is ... | The first line contains the integer *n* (1<=β€<=*n*<=β€<=100<=000) β the number of flats in the house.
The second line contains the row *s* with the length *n*, it consists of uppercase and lowercase letters of English alphabet, the *i*-th letter equals the type of Pokemon, which is in the flat number *i*. | Print the minimum number of flats which Sergei B. should visit in order to catch Pokemons of all types which there are in the house. | [
"3\nAaA\n",
"7\nbcAAcbc\n",
"6\naaBCCe\n"
] | [
"2\n",
"3\n",
"5\n"
] | In the first test Sergei B. can begin, for example, from the flat number 1 and end in the flat number 2.
In the second test Sergei B. can begin, for example, from the flat number 4 and end in the flat number 6.
In the third test Sergei B. must begin from the flat number 2 and end in the flat number 6. | 1,000 | [
{
"input": "3\nAaA",
"output": "2"
},
{
"input": "7\nbcAAcbc",
"output": "3"
},
{
"input": "6\naaBCCe",
"output": "5"
},
{
"input": "1\nA",
"output": "1"
},
{
"input": "1\ng",
"output": "1"
},
{
"input": "52\nabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQ... | 1,661,361,749 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 80 | 93 | 3,891,200 | import sys
from math import sqrt, gcd, factorial, ceil, floor, pi, inf
from collections import deque, Counter, OrderedDict
from heapq import heapify, heappush, heappop
#sys.setrecursionlimit(10**5)
#======================================================#
input = lambda: sys.stdin.readline()
I = lambda: int(inp... | Title: They Are Everywhere
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Sergei B., the young coach of Pokemons, has found the big house which consists of *n* flats ordered in a row from left to right. It is possible to enter each flat from the street. It is possible to go out from each ... | ```python
import sys
from math import sqrt, gcd, factorial, ceil, floor, pi, inf
from collections import deque, Counter, OrderedDict
from heapq import heapify, heappush, heappop
#sys.setrecursionlimit(10**5)
#======================================================#
input = lambda: sys.stdin.readline()
I = lambd... | 3 | |
994 | A | Fingerprints | PROGRAMMING | 800 | [
"implementation"
] | null | null | You are locked in a room with a door that has a keypad with 10 keys corresponding to digits from 0 to 9. To escape from the room, you need to enter a correct code. You also have a sequence of digits.
Some keys on the keypad have fingerprints. You believe the correct code is the longest not necessarily contiguous subse... | The first line contains two integers $n$ and $m$ ($1 \le n, m \le 10$) representing the number of digits in the sequence you have and the number of keys on the keypad that have fingerprints.
The next line contains $n$ distinct space-separated integers $x_1, x_2, \ldots, x_n$ ($0 \le x_i \le 9$) representing the sequen... | In a single line print a space-separated sequence of integers representing the code. If the resulting sequence is empty, both printing nothing and printing a single line break is acceptable. | [
"7 3\n3 5 7 1 6 2 8\n1 2 7\n",
"4 4\n3 4 1 0\n0 1 7 9\n"
] | [
"7 1 2\n",
"1 0\n"
] | In the first example, the only digits with fingerprints are $1$, $2$ and $7$. All three of them appear in the sequence you know, $7$ first, then $1$ and then $2$. Therefore the output is 7 1 2. Note that the order is important, and shall be the same as the order in the original sequence.
In the second example digits $... | 500 | [
{
"input": "7 3\n3 5 7 1 6 2 8\n1 2 7",
"output": "7 1 2"
},
{
"input": "4 4\n3 4 1 0\n0 1 7 9",
"output": "1 0"
},
{
"input": "9 4\n9 8 7 6 5 4 3 2 1\n2 4 6 8",
"output": "8 6 4 2"
},
{
"input": "10 5\n3 7 1 2 4 6 9 0 5 8\n4 3 0 7 9",
"output": "3 7 4 9 0"
},
{
"... | 1,625,307,975 | 2,147,483,647 | Python 3 | OK | TESTS | 31 | 78 | 0 | n,m=map(int,input().split())
s=list(map(int,input().split()))
t=list(map(int,input().split()))
for i in range(n):
if s[i] in t:
print(s[i],end=" ")
| Title: Fingerprints
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are locked in a room with a door that has a keypad with 10 keys corresponding to digits from 0 to 9. To escape from the room, you need to enter a correct code. You also have a sequence of digits.
Some keys on the keyp... | ```python
n,m=map(int,input().split())
s=list(map(int,input().split()))
t=list(map(int,input().split()))
for i in range(n):
if s[i] in t:
print(s[i],end=" ")
``` | 3 | |
831 | A | Unimodal Array | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Array of integers is unimodal, if:
- it is strictly increasing in the beginning; - after that it is constant; - after that it is strictly decreasing.
The first block (increasing) and the last block (decreasing) may be absent. It is allowed that both of this blocks are absent.
For example, the following three arra... | The first line contains integer *n* (1<=β€<=*n*<=β€<=100) β the number of elements in the array.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=β€<=*a**i*<=β€<=1<=000) β the elements of the array. | Print "YES" if the given array is unimodal. Otherwise, print "NO".
You can output each letter in any case (upper or lower). | [
"6\n1 5 5 5 4 2\n",
"5\n10 20 30 20 10\n",
"4\n1 2 1 2\n",
"7\n3 3 3 3 3 3 3\n"
] | [
"YES\n",
"YES\n",
"NO\n",
"YES\n"
] | In the first example the array is unimodal, because it is strictly increasing in the beginning (from position 1 to position 2, inclusively), that it is constant (from position 2 to position 4, inclusively) and then it is strictly decreasing (from position 4 to position 6, inclusively). | 500 | [
{
"input": "6\n1 5 5 5 4 2",
"output": "YES"
},
{
"input": "5\n10 20 30 20 10",
"output": "YES"
},
{
"input": "4\n1 2 1 2",
"output": "NO"
},
{
"input": "7\n3 3 3 3 3 3 3",
"output": "YES"
},
{
"input": "6\n5 7 11 11 2 1",
"output": "YES"
},
{
"input":... | 1,641,052,054 | 2,147,483,647 | Python 3 | OK | TESTS | 101 | 61 | 0 | l=int(input())
l1=list(map(int,input().split()))
j=1
while j<l and l1[j-1]<l1[j]:
j+=1
while j<l and l1[j-1]==l1[j]:
j+=1
while j<l and l1[j-1]>l1[j]:
j+=1
if j==l:
print("YES")
else:
print("NO") | Title: Unimodal Array
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Array of integers is unimodal, if:
- it is strictly increasing in the beginning; - after that it is constant; - after that it is strictly decreasing.
The first block (increasing) and the last block (decreasing) may ... | ```python
l=int(input())
l1=list(map(int,input().split()))
j=1
while j<l and l1[j-1]<l1[j]:
j+=1
while j<l and l1[j-1]==l1[j]:
j+=1
while j<l and l1[j-1]>l1[j]:
j+=1
if j==l:
print("YES")
else:
print("NO")
``` | 3 | |
43 | A | Football | PROGRAMMING | 1,000 | [
"strings"
] | A. Football | 2 | 256 | One day Vasya decided to have a look at the results of Berland 1910 Football Championshipβs finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process. On the whole there are *n* lines in that description each of which described one goal. E... | The first line contains an integer *n* (1<=β€<=*n*<=β€<=100) β the number of lines in the description. Then follow *n* lines β for each goal the names of the teams that scored it. The names are non-empty lines consisting of uppercase Latin letters whose lengths do not exceed 10 symbols. It is guaranteed that the match di... | Print the name of the winning team. We remind you that in football the team that scores more goals is considered the winner. | [
"1\nABC\n",
"5\nA\nABA\nABA\nA\nA\n"
] | [
"ABC\n",
"A\n"
] | none | 500 | [
{
"input": "1\nABC",
"output": "ABC"
},
{
"input": "5\nA\nABA\nABA\nA\nA",
"output": "A"
},
{
"input": "2\nXTSJEP\nXTSJEP",
"output": "XTSJEP"
},
{
"input": "3\nXZYDJAEDZ\nXZYDJAEDZ\nXZYDJAEDZ",
"output": "XZYDJAEDZ"
},
{
"input": "3\nQCCYXL\nQCCYXL\nAXGLFQDD",
... | 1,614,698,474 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 124 | 307,200 | n = int(input())
arr1 = []
arr2 = []
first = 0
for i in range(n):
line = str(input())
if first == 0:
arr1.append(line)
elif line != arr1[-1]:
arr2.append(line)
else:
arr1.append(line)
first += 1
if len(arr1) > len(arr2):
print(arr1[-1])
else:
print(arr... | Title: Football
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
One day Vasya decided to have a look at the results of Berland 1910 Football Championshipβs finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process... | ```python
n = int(input())
arr1 = []
arr2 = []
first = 0
for i in range(n):
line = str(input())
if first == 0:
arr1.append(line)
elif line != arr1[-1]:
arr2.append(line)
else:
arr1.append(line)
first += 1
if len(arr1) > len(arr2):
print(arr1[-1])
else:
... | 3.968428 |
707 | A | Brain's Photos | PROGRAMMING | 800 | [
"implementation"
] | null | null | Small, but very brave, mouse Brain was not accepted to summer school of young villains. He was upset and decided to postpone his plans of taking over the world, but to become a photographer instead.
As you may know, the coolest photos are on the film (because you can specify the hashtag #film for such).
Brain took a ... | The first line of the input contains two integers *n* and *m* (1<=β€<=*n*,<=*m*<=β€<=100)Β β the number of photo pixel matrix rows and columns respectively.
Then *n* lines describing matrix rows follow. Each of them contains *m* space-separated characters describing colors of pixels in a row. Each character in the line i... | Print the "#Black&White" (without quotes), if the photo is black-and-white and "#Color" (without quotes), if it is colored, in the only line. | [
"2 2\nC M\nY Y\n",
"3 2\nW W\nW W\nB B\n",
"1 1\nW\n"
] | [
"#Color",
"#Black&White",
"#Black&White"
] | none | 500 | [
{
"input": "2 2\nC M\nY Y",
"output": "#Color"
},
{
"input": "3 2\nW W\nW W\nB B",
"output": "#Black&White"
},
{
"input": "1 1\nW",
"output": "#Black&White"
},
{
"input": "2 3\nW W W\nB G Y",
"output": "#Color"
},
{
"input": "1 1\nW",
"output": "#Black&White"
... | 1,658,329,545 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 50 | 62 | 0 | def is_colour(string):
if "C" in string or "M" in string or "Y" in string:
return True
return False
n = int(input().split()[0])
string = ""
for i in range(n):
string += input()
if is_colour(string):
print("#Color")
else:
print("#Black&White") | Title: Brain's Photos
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Small, but very brave, mouse Brain was not accepted to summer school of young villains. He was upset and decided to postpone his plans of taking over the world, but to become a photographer instead.
As you may know, the... | ```python
def is_colour(string):
if "C" in string or "M" in string or "Y" in string:
return True
return False
n = int(input().split()[0])
string = ""
for i in range(n):
string += input()
if is_colour(string):
print("#Color")
else:
print("#Black&White")
``` | 3 | |
916 | A | Jamie and Alarm Snooze | PROGRAMMING | 900 | [
"brute force",
"implementation",
"math"
] | null | null | Jamie loves sleeping. One day, he decides that he needs to wake up at exactly *hh*:<=*mm*. However, he hates waking up, so he wants to make waking up less painful by setting the alarm at a lucky time. He will then press the snooze button every *x* minutes until *hh*:<=*mm* is reached, and only then he will wake up. He ... | The first line contains a single integer *x* (1<=β€<=*x*<=β€<=60).
The second line contains two two-digit integers, *hh* and *mm* (00<=β€<=*hh*<=β€<=23,<=00<=β€<=*mm*<=β€<=59). | Print the minimum number of times he needs to press the button. | [
"3\n11 23\n",
"5\n01 07\n"
] | [
"2\n",
"0\n"
] | In the first sample, Jamie needs to wake up at 11:23. So, he can set his alarm at 11:17. He would press the snooze button when the alarm rings at 11:17 and at 11:20.
In the second sample, Jamie can set his alarm at exactly at 01:07 which is lucky. | 500 | [
{
"input": "3\n11 23",
"output": "2"
},
{
"input": "5\n01 07",
"output": "0"
},
{
"input": "34\n09 24",
"output": "3"
},
{
"input": "2\n14 37",
"output": "0"
},
{
"input": "14\n19 54",
"output": "9"
},
{
"input": "42\n15 44",
"output": "12"
},
... | 1,546,321,160 | 320 | PyPy 3 | OK | TESTS | 254 | 156 | 0 | x = int(input())
t = input().split()
h, m = int(t[0]), int(t[1])
i = 0
while True:
if '7' in str(h) or '7' in str(m):
print(i)
exit(0)
m -= x
if m < 0:
m += 60
h -= 1
if h < 0:
h += 24
i += 1 | Title: Jamie and Alarm Snooze
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Jamie loves sleeping. One day, he decides that he needs to wake up at exactly *hh*:<=*mm*. However, he hates waking up, so he wants to make waking up less painful by setting the alarm at a lucky time. He will the... | ```python
x = int(input())
t = input().split()
h, m = int(t[0]), int(t[1])
i = 0
while True:
if '7' in str(h) or '7' in str(m):
print(i)
exit(0)
m -= x
if m < 0:
m += 60
h -= 1
if h < 0:
h += 24
i += 1
``` | 3 | |
116 | A | Tram | PROGRAMMING | 800 | [
"implementation"
] | null | null | Linear Kingdom has exactly one tram line. It has *n* stops, numbered from 1 to *n* in the order of tram's movement. At the *i*-th stop *a**i* passengers exit the tram, while *b**i* passengers enter it. The tram is empty before it arrives at the first stop. Also, when the tram arrives at the last stop, all passengers ex... | The first line contains a single number *n* (2<=β€<=*n*<=β€<=1000) β the number of the tram's stops.
Then *n* lines follow, each contains two integers *a**i* and *b**i* (0<=β€<=*a**i*,<=*b**i*<=β€<=1000) β the number of passengers that exits the tram at the *i*-th stop, and the number of passengers that enter the tram at... | Print a single integer denoting the minimum possible capacity of the tram (0 is allowed). | [
"4\n0 3\n2 5\n4 2\n4 0\n"
] | [
"6\n"
] | For the first example, a capacity of 6 is sufficient:
- At the first stop, the number of passengers inside the tram before arriving is 0. Then, 3 passengers enter the tram, and the number of passengers inside the tram becomes 3. - At the second stop, 2 passengers exit the tram (1 passenger remains inside). Then, 5 ... | 500 | [
{
"input": "4\n0 3\n2 5\n4 2\n4 0",
"output": "6"
},
{
"input": "5\n0 4\n4 6\n6 5\n5 4\n4 0",
"output": "6"
},
{
"input": "10\n0 5\n1 7\n10 8\n5 3\n0 5\n3 3\n8 8\n0 6\n10 1\n9 0",
"output": "18"
},
{
"input": "3\n0 1\n1 1\n1 0",
"output": "1"
},
{
"input": "4\n0 1... | 1,691,574,416 | 2,147,483,647 | Python 3 | OK | TESTS | 71 | 92 | 0 | n = int(input())
passengers_inside = 0
min_capacity = 0
for _ in range(n):
a, b = map(int, input().split())
passengers_inside = passengers_inside - a + b
min_capacity = max(min_capacity, passengers_inside)
print(min_capacity)
| Title: Tram
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Linear Kingdom has exactly one tram line. It has *n* stops, numbered from 1 to *n* in the order of tram's movement. At the *i*-th stop *a**i* passengers exit the tram, while *b**i* passengers enter it. The tram is empty before it ... | ```python
n = int(input())
passengers_inside = 0
min_capacity = 0
for _ in range(n):
a, b = map(int, input().split())
passengers_inside = passengers_inside - a + b
min_capacity = max(min_capacity, passengers_inside)
print(min_capacity)
``` | 3 | |
37 | A | Towers | PROGRAMMING | 1,000 | [
"sortings"
] | A. Towers | 2 | 256 | Little Vasya has received a young builderβs kit. The kit consists of several wooden bars, the lengths of all of them are known. The bars can be put one on the top of the other if their lengths are the same.
Vasya wants to construct the minimal number of towers from the bars. Help Vasya to use the bars in the best way ... | The first line contains an integer *N* (1<=β€<=*N*<=β€<=1000) β the number of bars at Vasyaβs disposal. The second line contains *N* space-separated integers *l**i* β the lengths of the bars. All the lengths are natural numbers not exceeding 1000. | In one line output two numbers β the height of the largest tower and their total number. Remember that Vasya should use all the bars. | [
"3\n1 2 3\n",
"4\n6 5 6 7\n"
] | [
"1 3\n",
"2 3\n"
] | none | 500 | [
{
"input": "3\n1 2 3",
"output": "1 3"
},
{
"input": "4\n6 5 6 7",
"output": "2 3"
},
{
"input": "4\n3 2 1 1",
"output": "2 3"
},
{
"input": "4\n1 2 3 3",
"output": "2 3"
},
{
"input": "3\n20 22 36",
"output": "1 3"
},
{
"input": "25\n47 30 94 41 45 20... | 1,683,026,156 | 2,147,483,647 | Python 3 | OK | TESTS | 61 | 92 | 0 | n=int(input())
max_list=list()
line=input()
line_i=[int(s) for s in line.split()]
line_i=sorted(line_i)
sum=1
for i in range(n-1):
if line_i[i]==line_i[i+1]:
sum+=1
else:
max_list.append(sum)
sum=1
max_list.append(sum)
print(str(max(max_list))+" "+str(len(max_list)... | Title: Towers
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Little Vasya has received a young builderβs kit. The kit consists of several wooden bars, the lengths of all of them are known. The bars can be put one on the top of the other if their lengths are the same.
Vasya wants to construct... | ```python
n=int(input())
max_list=list()
line=input()
line_i=[int(s) for s in line.split()]
line_i=sorted(line_i)
sum=1
for i in range(n-1):
if line_i[i]==line_i[i+1]:
sum+=1
else:
max_list.append(sum)
sum=1
max_list.append(sum)
print(str(max(max_list))+" "+str(len... | 3.977 |
136 | A | Presents | PROGRAMMING | 800 | [
"implementation"
] | null | null | Little Petya very much likes gifts. Recently he has received a new laptop as a New Year gift from his mother. He immediately decided to give it to somebody else as what can be more pleasant than giving somebody gifts. And on this occasion he organized a New Year party at his place and invited *n* his friends there.
If... | The first line contains one integer *n* (1<=β€<=*n*<=β€<=100) β the quantity of friends Petya invited to the party. The second line contains *n* space-separated integers: the *i*-th number is *p**i* β the number of a friend who gave a gift to friend number *i*. It is guaranteed that each friend received exactly one gift.... | Print *n* space-separated integers: the *i*-th number should equal the number of the friend who gave a gift to friend number *i*. | [
"4\n2 3 4 1\n",
"3\n1 3 2\n",
"2\n1 2\n"
] | [
"4 1 2 3\n",
"1 3 2\n",
"1 2\n"
] | none | 500 | [
{
"input": "4\n2 3 4 1",
"output": "4 1 2 3"
},
{
"input": "3\n1 3 2",
"output": "1 3 2"
},
{
"input": "2\n1 2",
"output": "1 2"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "10\n1 3 2 6 4 5 7 9 8 10",
"output": "1 3 2 5 6 4 7 9 8 10"
},
{
"input"... | 1,688,312,709 | 2,147,483,647 | Python 3 | OK | TESTS | 101 | 92 | 0 | n=int(input())
x=list(map(int,input().split()))
z=[]
for i in range(1,n+1):
z.append(i)
a=[]
for i in range(1,n+1):
q=x.index(i)
a.append(str(z[q]))
m=" ".join(a)
print(m) | Title: Presents
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Petya very much likes gifts. Recently he has received a new laptop as a New Year gift from his mother. He immediately decided to give it to somebody else as what can be more pleasant than giving somebody gifts. And on t... | ```python
n=int(input())
x=list(map(int,input().split()))
z=[]
for i in range(1,n+1):
z.append(i)
a=[]
for i in range(1,n+1):
q=x.index(i)
a.append(str(z[q]))
m=" ".join(a)
print(m)
``` | 3 | |
131 | A | cAPS lOCK | PROGRAMMING | 1,000 | [
"implementation",
"strings"
] | null | null | wHAT DO WE NEED cAPS LOCK FOR?
Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in the first passage.
Let's consider that a word has been typed with the Caps lock key accidentall... | The first line of the input data contains a word consisting of uppercase and lowercase Latin letters. The word's length is from 1 to 100 characters, inclusive. | Print the result of the given word's processing. | [
"cAPS\n",
"Lock\n"
] | [
"Caps",
"Lock\n"
] | none | 500 | [
{
"input": "cAPS",
"output": "Caps"
},
{
"input": "Lock",
"output": "Lock"
},
{
"input": "cAPSlOCK",
"output": "cAPSlOCK"
},
{
"input": "CAPs",
"output": "CAPs"
},
{
"input": "LoCK",
"output": "LoCK"
},
{
"input": "OOPS",
"output": "oops"
},
{
... | 1,696,041,751 | 2,147,483,647 | Python 3 | OK | TESTS | 56 | 46 | 0 | # h
h= input()
if h.isupper() or (h[0].islower() and h[1:].isupper()) or (len(h)==1 and h.islower()):
h= h.swapcase()
print(h)
| Title: cAPS lOCK
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
wHAT DO WE NEED cAPS LOCK FOR?
Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in th... | ```python
# h
h= input()
if h.isupper() or (h[0].islower() and h[1:].isupper()) or (len(h)==1 and h.islower()):
h= h.swapcase()
print(h)
``` | 3 | |
486 | A | Calculating Function | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | For a positive integer *n* let's define a function *f*:
*f*(*n*)<==<=<=-<=1<=+<=2<=-<=3<=+<=..<=+<=(<=-<=1)*n**n*
Your task is to calculate *f*(*n*) for a given integer *n*. | The single line contains the positive integer *n* (1<=β€<=*n*<=β€<=1015). | Print *f*(*n*) in a single line. | [
"4\n",
"5\n"
] | [
"2\n",
"-3\n"
] | *f*(4)β=ββ-β1β+β2β-β3β+β4β=β2
*f*(5)β=ββ-β1β+β2β-β3β+β4β-β5β=ββ-β3 | 500 | [
{
"input": "4",
"output": "2"
},
{
"input": "5",
"output": "-3"
},
{
"input": "1000000000",
"output": "500000000"
},
{
"input": "1000000001",
"output": "-500000001"
},
{
"input": "1000000000000000",
"output": "500000000000000"
},
{
"input": "100",
... | 1,697,117,733 | 2,147,483,647 | Python 3 | OK | TESTS | 39 | 46 | 0 | N = int(input())
a = -1
if N % 2 == 0:
a += 1 + N
else:
a -= N
print(a // 2)
| Title: Calculating Function
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
For a positive integer *n* let's define a function *f*:
*f*(*n*)<==<=<=-<=1<=+<=2<=-<=3<=+<=..<=+<=(<=-<=1)*n**n*
Your task is to calculate *f*(*n*) for a given integer *n*.
Input Specification:
The single line... | ```python
N = int(input())
a = -1
if N % 2 == 0:
a += 1 + N
else:
a -= N
print(a // 2)
``` | 3 | |
192 | A | Funky Numbers | PROGRAMMING | 1,300 | [
"binary search",
"brute force",
"implementation"
] | null | null | As you very well know, this year's funkiest numbers are so called triangular numbers (that is, integers that are representable as , where *k* is some positive integer), and the coolest numbers are those that are representable as a sum of two triangular numbers.
A well-known hipster Andrew adores everything funky and c... | The first input line contains an integer *n* (1<=β€<=*n*<=β€<=109). | Print "YES" (without the quotes), if *n* can be represented as a sum of two triangular numbers, otherwise print "NO" (without the quotes). | [
"256\n",
"512\n"
] | [
"YES\n",
"NO\n"
] | In the first sample number <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/92095692c6ea93e9e3b837a0408ba7543549d5b2.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
In the second sample number 512 can not be represented as a sum of two triangular numbers. | 500 | [
{
"input": "256",
"output": "YES"
},
{
"input": "512",
"output": "NO"
},
{
"input": "80",
"output": "NO"
},
{
"input": "828",
"output": "YES"
},
{
"input": "6035",
"output": "NO"
},
{
"input": "39210",
"output": "YES"
},
{
"input": "79712",... | 1,608,222,565 | 2,147,483,647 | PyPy 3 | OK | TESTS | 71 | 310 | 2,457,600 | n=int(input())
k=1
arr=[]
while (k*(k+1))//2<=n:
arr.append((k*(k+1))//2)
k+=1
start=0
end=len(arr)-1
flag=0
while start<=end:
k=arr[start]+arr[end]
if k<n:
start+=1
continue
if k>n:
end-=1
continue
else:
flag=1
break
if flag==1... | Title: Funky Numbers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
As you very well know, this year's funkiest numbers are so called triangular numbers (that is, integers that are representable as , where *k* is some positive integer), and the coolest numbers are those that are represent... | ```python
n=int(input())
k=1
arr=[]
while (k*(k+1))//2<=n:
arr.append((k*(k+1))//2)
k+=1
start=0
end=len(arr)-1
flag=0
while start<=end:
k=arr[start]+arr[end]
if k<n:
start+=1
continue
if k>n:
end-=1
continue
else:
flag=1
break
... | 3 | |
588 | A | Duff and Meat | PROGRAMMING | 900 | [
"greedy"
] | null | null | Duff is addicted to meat! Malek wants to keep her happy for *n* days. In order to be happy in *i*-th day, she needs to eat exactly *a**i* kilograms of meat.
There is a big shop uptown and Malek wants to buy meat for her from there. In *i*-th day, they sell meat for *p**i* dollars per kilogram. Malek knows all numbers ... | The first line of input contains integer *n* (1<=β€<=*n*<=β€<=105), the number of days.
In the next *n* lines, *i*-th line contains two integers *a**i* and *p**i* (1<=β€<=*a**i*,<=*p**i*<=β€<=100), the amount of meat Duff needs and the cost of meat in that day. | Print the minimum money needed to keep Duff happy for *n* days, in one line. | [
"3\n1 3\n2 2\n3 1\n",
"3\n1 3\n2 1\n3 2\n"
] | [
"10\n",
"8\n"
] | In the first sample case: An optimal way would be to buy 1 kg on the first day, 2 kg on the second day and 3 kg on the third day.
In the second sample case: An optimal way would be to buy 1 kg on the first day and 5 kg (needed meat for the second and third day) on the second day. | 750 | [
{
"input": "3\n1 3\n2 2\n3 1",
"output": "10"
},
{
"input": "3\n1 3\n2 1\n3 2",
"output": "8"
},
{
"input": "1\n39 52",
"output": "2028"
},
{
"input": "2\n25 56\n94 17",
"output": "2998"
},
{
"input": "5\n39 21\n95 89\n73 90\n9 55\n85 32",
"output": "6321"
}... | 1,551,592,347 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 358 | 5,324,800 | n = int(input())
A = []
for i in range(n):
x, y = map(int, input().split())
A.append((y, x))
ans = i = j = 0
while i < n:
s = 0
j = i
while j < n and A[i][0] <= A[j][0]:
s+=A[j][1]
j+=1
ans += s*A[i][0]
i = j
print(ans)
| Title: Duff and Meat
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Duff is addicted to meat! Malek wants to keep her happy for *n* days. In order to be happy in *i*-th day, she needs to eat exactly *a**i* kilograms of meat.
There is a big shop uptown and Malek wants to buy meat for her ... | ```python
n = int(input())
A = []
for i in range(n):
x, y = map(int, input().split())
A.append((y, x))
ans = i = j = 0
while i < n:
s = 0
j = i
while j < n and A[i][0] <= A[j][0]:
s+=A[j][1]
j+=1
ans += s*A[i][0]
i = j
print(ans)
``` | 3 | |
758 | A | Holiday Of Equality | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | In Berland it is the holiday of equality. In honor of the holiday the king decided to equalize the welfare of all citizens in Berland by the expense of the state treasury.
Totally in Berland there are *n* citizens, the welfare of each of them is estimated as the integer in *a**i* burles (burle is the currency in Berl... | The first line contains the integer *n* (1<=β€<=*n*<=β€<=100)Β β the number of citizens in the kingdom.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n*, where *a**i* (0<=β€<=*a**i*<=β€<=106)Β β the welfare of the *i*-th citizen. | In the only line print the integer *S*Β β the minimum number of burles which are had to spend. | [
"5\n0 1 2 3 4\n",
"5\n1 1 0 1 1\n",
"3\n1 3 1\n",
"1\n12\n"
] | [
"10",
"1",
"4",
"0"
] | In the first example if we add to the first citizen 4 burles, to the second 3, to the third 2 and to the fourth 1, then the welfare of all citizens will equal 4.
In the second example it is enough to give one burle to the third citizen.
In the third example it is necessary to give two burles to the first and the thi... | 500 | [
{
"input": "5\n0 1 2 3 4",
"output": "10"
},
{
"input": "5\n1 1 0 1 1",
"output": "1"
},
{
"input": "3\n1 3 1",
"output": "4"
},
{
"input": "1\n12",
"output": "0"
},
{
"input": "3\n1 2 3",
"output": "3"
},
{
"input": "14\n52518 718438 358883 462189 853... | 1,673,615,970 | 2,147,483,647 | Python 3 | OK | TESTS | 41 | 46 | 0 | n = int(input())
a = list(map(int, input().split()))
S = 0
a.sort()
a_max = a[len(a) - 1]
for i in a:
S = S + (a_max - i)
print(S) | Title: Holiday Of Equality
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In Berland it is the holiday of equality. In honor of the holiday the king decided to equalize the welfare of all citizens in Berland by the expense of the state treasury.
Totally in Berland there are *n* citizens... | ```python
n = int(input())
a = list(map(int, input().split()))
S = 0
a.sort()
a_max = a[len(a) - 1]
for i in a:
S = S + (a_max - i)
print(S)
``` | 3 | |
258 | A | Little Elephant and Bits | PROGRAMMING | 1,100 | [
"greedy",
"math"
] | null | null | The Little Elephant has an integer *a*, written in the binary notation. He wants to write this number on a piece of paper.
To make sure that the number *a* fits on the piece of paper, the Little Elephant ought to delete exactly one any digit from number *a* in the binary record. At that a new number appears. It consis... | The single line contains integer *a*, written in the binary notation without leading zeroes. This number contains more than 1 and at most 105 digits. | In the single line print the number that is written without leading zeroes in the binary notation β the answer to the problem. | [
"101\n",
"110010\n"
] | [
"11\n",
"11010\n"
] | In the first sample the best strategy is to delete the second digit. That results in number 11<sub class="lower-index">2</sub>β=β3<sub class="lower-index">10</sub>.
In the second sample the best strategy is to delete the third or fourth digits β that results in number 11010<sub class="lower-index">2</sub>β=β26<sub cla... | 500 | [
{
"input": "101",
"output": "11"
},
{
"input": "110010",
"output": "11010"
},
{
"input": "10000",
"output": "1000"
},
{
"input": "1111111110",
"output": "111111111"
},
{
"input": "10100101011110101",
"output": "1100101011110101"
},
{
"input": "11101001... | 1,622,278,095 | 2,147,483,647 | PyPy 3 | OK | TESTS | 37 | 372 | 8,908,800 | def solve():
s = input()
b = True
z = set(s)
if z.__contains__("0"):
for i in s:
if b and i == "0":
b = False
continue
print(i,end="")
else:
print(s[1:])
return
try:
solve()
except:
pass | Title: Little Elephant and Bits
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Little Elephant has an integer *a*, written in the binary notation. He wants to write this number on a piece of paper.
To make sure that the number *a* fits on the piece of paper, the Little Elephant ought... | ```python
def solve():
s = input()
b = True
z = set(s)
if z.__contains__("0"):
for i in s:
if b and i == "0":
b = False
continue
print(i,end="")
else:
print(s[1:])
return
try:
solve()
except:
pass
``` | 3 | |
729 | A | Interview with Oleg | PROGRAMMING | 900 | [
"implementation",
"strings"
] | null | null | Polycarp has interviewed Oleg and has written the interview down without punctuation marks and spaces to save time. Thus, the interview is now a string *s* consisting of *n* lowercase English letters.
There is a filler word ogo in Oleg's speech. All words that can be obtained from ogo by adding go several times to the... | The first line contains a positive integer *n* (1<=β€<=*n*<=β€<=100)Β β the length of the interview.
The second line contains the string *s* of length *n*, consisting of lowercase English letters. | Print the interview text after the replacement of each of the fillers with "***". It is allowed for the substring "***" to have several consecutive occurences. | [
"7\naogogob\n",
"13\nogogmgogogogo\n",
"9\nogoogoogo\n"
] | [
"a***b\n",
"***gmg***\n",
"*********\n"
] | The first sample contains one filler word ogogo, so the interview for printing is "a***b".
The second sample contains two fillers ogo and ogogogo. Thus, the interview is transformed to "***gmg***". | 500 | [
{
"input": "7\naogogob",
"output": "a***b"
},
{
"input": "13\nogogmgogogogo",
"output": "***gmg***"
},
{
"input": "9\nogoogoogo",
"output": "*********"
},
{
"input": "32\nabcdefogoghijklmnogoopqrstuvwxyz",
"output": "abcdef***ghijklmn***opqrstuvwxyz"
},
{
"input":... | 1,610,743,487 | 2,147,483,647 | PyPy 3 | OK | TESTS | 48 | 124 | 2,150,400 | import re
n = input()
cad = input()
print(re.sub(r'o(go)+', '***', cad))
| Title: Interview with Oleg
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp has interviewed Oleg and has written the interview down without punctuation marks and spaces to save time. Thus, the interview is now a string *s* consisting of *n* lowercase English letters.
There is a fi... | ```python
import re
n = input()
cad = input()
print(re.sub(r'o(go)+', '***', cad))
``` | 3 | |
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,563,547,812 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 109 | 0 | # s
n=int(input())
k=int(input())
a=[]
for i in range(n):
a.append(int(input()))
a.sort(reverse=True)
i=0
while k>0:
k-=a[i]
i+=1
print(i) | 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
# s
n=int(input())
k=int(input())
a=[]
for i in range(n):
a.append(int(input()))
a.sort(reverse=True)
i=0
while k>0:
k-=a[i]
i+=1
print(i)
``` | 3 | |
745 | B | Hongcow Solves A Puzzle | PROGRAMMING | 1,400 | [
"implementation"
] | null | null | Hongcow likes solving puzzles.
One day, Hongcow finds two identical puzzle pieces, with the instructions "make a rectangle" next to them. The pieces can be described by an *n* by *m* grid of characters, where the character 'X' denotes a part of the puzzle and '.' denotes an empty part of the grid. It is guaranteed tha... | The first line of input will contain two integers *n* and *m* (1<=β€<=*n*,<=*m*<=β€<=500), the dimensions of the puzzle piece.
The next *n* lines will describe the jigsaw piece. Each line will have length *m* and will consist of characters '.' and 'X' only. 'X' corresponds to a part of the puzzle piece, '.' is an empty ... | Output "YES" if it is possible for Hongcow to make a rectangle. Output "NO" otherwise. | [
"2 3\nXXX\nXXX\n",
"2 2\n.X\nXX\n",
"5 5\n.....\n..X..\n.....\n.....\n.....\n"
] | [
"YES\n",
"NO\n",
"YES\n"
] | For the first sample, one example of a rectangle we can form is as follows
For the second sample, it is impossible to put two of those pieces without rotating or flipping to form a rectangle.
In the third sample, we can shift the first tile by one to the right, and then compose the following rectangle: | 1,000 | [
{
"input": "2 3\nXXX\nXXX",
"output": "YES"
},
{
"input": "2 2\n.X\nXX",
"output": "NO"
},
{
"input": "1 500\n.XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX... | 1,630,761,153 | 2,147,483,647 | Python 3 | OK | TESTS | 77 | 77 | 9,011,200 | n, m = map(int,input().split())
ans = []
for i in range(n):
s = input()
x = set(s)
if 'X' in x:
ans.append(s)
ans2 = []
a = zip(*ans)
for i in a:
x = set(i)
if 'X' in x:
ans2.append(i)
def f():
for i in ans2:
if '.' in i:
return "NO"
return... | Title: Hongcow Solves A Puzzle
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Hongcow likes solving puzzles.
One day, Hongcow finds two identical puzzle pieces, with the instructions "make a rectangle" next to them. The pieces can be described by an *n* by *m* grid of characters, where t... | ```python
n, m = map(int,input().split())
ans = []
for i in range(n):
s = input()
x = set(s)
if 'X' in x:
ans.append(s)
ans2 = []
a = zip(*ans)
for i in a:
x = set(i)
if 'X' in x:
ans2.append(i)
def f():
for i in ans2:
if '.' in i:
return "NO"
... | 3 | |
50 | A | Domino piling | PROGRAMMING | 800 | [
"greedy",
"math"
] | A. Domino piling | 2 | 256 | You are given a rectangular board of *M*<=Γ<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=Γ<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions:
1. Each domino completely covers ... | In a single line you are given two integers *M* and *N* β board sizes in squares (1<=β€<=*M*<=β€<=*N*<=β€<=16). | Output one number β the maximal number of dominoes, which can be placed. | [
"2 4\n",
"3 3\n"
] | [
"4\n",
"4\n"
] | none | 500 | [
{
"input": "2 4",
"output": "4"
},
{
"input": "3 3",
"output": "4"
},
{
"input": "1 5",
"output": "2"
},
{
"input": "1 6",
"output": "3"
},
{
"input": "1 15",
"output": "7"
},
{
"input": "1 16",
"output": "8"
},
{
"input": "2 5",
"outpu... | 1,696,998,514 | 2,147,483,647 | PyPy 3 | OK | TESTS | 35 | 184 | 0 | num = input().split()
num1 = [int(a) for a in num]
m = num1[0]
n = num1[1]
s = m * n
print(s // 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
num = input().split()
num1 = [int(a) for a in num]
m = num1[0]
n = num1[1]
s = m * n
print(s // 2)
``` | 3.954 |
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,667,547,988 | 2,147,483,647 | Python 3 | OK | TESTS | 28 | 46 | 0 | a,b=input().split()
if b != a:
print(1)
else:
print(a) | 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 b != a:
print(1)
else:
print(a)
``` | 3 | |
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,620,049,520 | 2,147,483,647 | Python 3 | OK | TESTS | 38 | 77 | 0 | a,b = map(int,input().split())
w=0
d=0
l=0
for i in range(1,7):
if abs(i-a)>abs(i-b):
l+=1
elif abs(i-a)==abs(i-b):
d+=1
elif abs(i-a)<abs(i-b):
w+=1
print(w,d,l) | 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 = map(int,input().split())
w=0
d=0
l=0
for i in range(1,7):
if abs(i-a)>abs(i-b):
l+=1
elif abs(i-a)==abs(i-b):
d+=1
elif abs(i-a)<abs(i-b):
w+=1
print(w,d,l)
``` | 3 | |
908 | A | New Year and Counting Cards | PROGRAMMING | 800 | [
"brute force",
"implementation"
] | null | null | Your friend has *n* cards.
You know that each card has a lowercase English letter on one side and a digit on the other.
Currently, your friend has laid out the cards on a table so only one side of each card is visible.
You would like to know if the following statement is true for cards that your friend owns: "If a c... | The first and only line of input will contain a string *s* (1<=β€<=|*s*|<=β€<=50), denoting the sides of the cards that you can see on the table currently. Each character of *s* is either a lowercase English letter or a digit. | Print a single integer, the minimum number of cards you must turn over to verify your claim. | [
"ee\n",
"z\n",
"0ay1\n"
] | [
"2\n",
"0\n",
"2\n"
] | In the first sample, we must turn over both cards. Note that even though both cards have the same letter, they could possibly have different numbers on the other side.
In the second sample, we don't need to turn over any cards. The statement is vacuously true, since you know your friend has no cards with a vowel on th... | 500 | [
{
"input": "ee",
"output": "2"
},
{
"input": "z",
"output": "0"
},
{
"input": "0ay1",
"output": "2"
},
{
"input": "0abcdefghijklmnopqrstuvwxyz1234567896",
"output": "10"
},
{
"input": "0a0a9e9e2i2i9o9o6u6u9z9z4x4x9b9b",
"output": "18"
},
{
"input": "01... | 1,627,754,883 | 2,147,483,647 | Python 3 | OK | TESTS | 38 | 77 | 6,758,400 | s = input()
d = {'a', 'e', 'i', 'o', 'u', '1', '3', '5', '7', '9'}
ret = 0
for c in s:
if c in d:
ret += 1
print(ret) | Title: New Year and Counting Cards
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Your friend has *n* cards.
You know that each card has a lowercase English letter on one side and a digit on the other.
Currently, your friend has laid out the cards on a table so only one side of each car... | ```python
s = input()
d = {'a', 'e', 'i', 'o', 'u', '1', '3', '5', '7', '9'}
ret = 0
for c in s:
if c in d:
ret += 1
print(ret)
``` | 3 | |
758 | A | Holiday Of Equality | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | In Berland it is the holiday of equality. In honor of the holiday the king decided to equalize the welfare of all citizens in Berland by the expense of the state treasury.
Totally in Berland there are *n* citizens, the welfare of each of them is estimated as the integer in *a**i* burles (burle is the currency in Berl... | The first line contains the integer *n* (1<=β€<=*n*<=β€<=100)Β β the number of citizens in the kingdom.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n*, where *a**i* (0<=β€<=*a**i*<=β€<=106)Β β the welfare of the *i*-th citizen. | In the only line print the integer *S*Β β the minimum number of burles which are had to spend. | [
"5\n0 1 2 3 4\n",
"5\n1 1 0 1 1\n",
"3\n1 3 1\n",
"1\n12\n"
] | [
"10",
"1",
"4",
"0"
] | In the first example if we add to the first citizen 4 burles, to the second 3, to the third 2 and to the fourth 1, then the welfare of all citizens will equal 4.
In the second example it is enough to give one burle to the third citizen.
In the third example it is necessary to give two burles to the first and the thi... | 500 | [
{
"input": "5\n0 1 2 3 4",
"output": "10"
},
{
"input": "5\n1 1 0 1 1",
"output": "1"
},
{
"input": "3\n1 3 1",
"output": "4"
},
{
"input": "1\n12",
"output": "0"
},
{
"input": "3\n1 2 3",
"output": "3"
},
{
"input": "14\n52518 718438 358883 462189 853... | 1,669,100,786 | 2,147,483,647 | Python 3 | OK | TESTS | 41 | 46 | 0 | n = int(input())
k = [int(i) for i in input().split()]
p = max(k)
m = 0
for i in k:
m += p-i
print(m) | Title: Holiday Of Equality
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In Berland it is the holiday of equality. In honor of the holiday the king decided to equalize the welfare of all citizens in Berland by the expense of the state treasury.
Totally in Berland there are *n* citizens... | ```python
n = int(input())
k = [int(i) for i in input().split()]
p = max(k)
m = 0
for i in k:
m += p-i
print(m)
``` | 3 | |
25 | A | IQ test | PROGRAMMING | 1,300 | [
"brute force"
] | A. IQ test | 2 | 256 | Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob β to check his answers, he needs a program that among the given *n* numbers finds one that i... | The first line contains integer *n* (3<=β€<=*n*<=β€<=100) β amount of numbers in the task. The second line contains *n* space-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these numbers differs from the others in evenness. | Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order. | [
"5\n2 4 7 8 10\n",
"4\n1 2 1 1\n"
] | [
"3\n",
"2\n"
] | none | 0 | [
{
"input": "5\n2 4 7 8 10",
"output": "3"
},
{
"input": "4\n1 2 1 1",
"output": "2"
},
{
"input": "3\n1 2 2",
"output": "1"
},
{
"input": "3\n100 99 100",
"output": "2"
},
{
"input": "3\n5 3 2",
"output": "3"
},
{
"input": "4\n43 28 1 91",
"output"... | 1,693,050,788 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 32 | 124 | 0 | n = int(input())
nums = list(map(int, input().split()))
evens = [i for i in nums if i % 2 == 0]
odds = [i for i in nums if i % 2 == 1]
print(nums.index(evens[0] if len(evens) == 1 else odds[0]) + 1)
| Title: IQ test
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob β t... | ```python
n = int(input())
nums = list(map(int, input().split()))
evens = [i for i in nums if i % 2 == 0]
odds = [i for i in nums if i % 2 == 1]
print(nums.index(evens[0] if len(evens) == 1 else odds[0]) + 1)
``` | 3.969 |
399 | A | Pages | PROGRAMMING | 0 | [
"implementation"
] | null | null | User ainta is making a web site. This time he is going to make a navigation of the pages. In his site, there are *n* pages numbered by integers from 1 to *n*. Assume that somebody is on the *p*-th page now. The navigation will look like this:
When someone clicks the button "<<" he is redirected to page 1, and wh... | The first and the only line contains three integers *n*, *p*, *k* (3<=β€<=*n*<=β€<=100; 1<=β€<=*p*<=β€<=*n*; 1<=β€<=*k*<=β€<=*n*) | Print the proper navigation. Follow the format of the output from the test samples. | [
"17 5 2\n",
"6 5 2\n",
"6 1 2\n",
"6 2 2\n",
"9 6 3\n",
"10 6 3\n",
"8 5 4\n"
] | [
"<< 3 4 (5) 6 7 >> ",
"<< 3 4 (5) 6 ",
"(1) 2 3 >> ",
"1 (2) 3 4 >>",
"<< 3 4 5 (6) 7 8 9",
"<< 3 4 5 (6) 7 8 9 >>",
"1 2 3 4 (5) 6 7 8 "
] | none | 500 | [
{
"input": "17 5 2",
"output": "<< 3 4 (5) 6 7 >> "
},
{
"input": "6 5 2",
"output": "<< 3 4 (5) 6 "
},
{
"input": "6 1 2",
"output": "(1) 2 3 >> "
},
{
"input": "6 2 2",
"output": "1 (2) 3 4 >> "
},
{
"input": "9 6 3",
"output": "<< 3 4 5 (6) 7 8 9 "
},
{... | 1,553,789,670 | 2,147,483,647 | Python 3 | OK | TESTS | 26 | 108 | 0 | if __name__ == '__main__':
[n, p, k] = [int(x) for x in input().split()]
navigation = []
if (p - k) > 1:
navigation.append('<<')
navigation += [str(x) for x in range(max(p - k, 1), p)]
navigation.append('(%i)' % p)
navigation += [str(x) for x in range(p + 1, min(p + k + 1, n + 1))]
... | Title: Pages
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
User ainta is making a web site. This time he is going to make a navigation of the pages. In his site, there are *n* pages numbered by integers from 1 to *n*. Assume that somebody is on the *p*-th page now. The navigation will lo... | ```python
if __name__ == '__main__':
[n, p, k] = [int(x) for x in input().split()]
navigation = []
if (p - k) > 1:
navigation.append('<<')
navigation += [str(x) for x in range(max(p - k, 1), p)]
navigation.append('(%i)' % p)
navigation += [str(x) for x in range(p + 1, min(p + k + 1, n ... | 3 | |
651 | B | Beautiful Paintings | PROGRAMMING | 1,200 | [
"greedy",
"sortings"
] | null | null | There are *n* pictures delivered for the new exhibition. The *i*-th painting has beauty *a**i*. We know that a visitor becomes happy every time he passes from a painting to a more beautiful one.
We are allowed to arranged pictures in any order. What is the maximum possible number of times the visitor may become happy ... | The first line of the input contains integer *n* (1<=β€<=*n*<=β€<=1000)Β β the number of painting.
The second line contains the sequence *a*1,<=*a*2,<=...,<=*a**n* (1<=β€<=*a**i*<=β€<=1000), where *a**i* means the beauty of the *i*-th painting. | Print one integerΒ β the maximum possible number of neighbouring pairs, such that *a**i*<=+<=1<=><=*a**i*, after the optimal rearrangement. | [
"5\n20 30 10 50 40\n",
"4\n200 100 100 200\n"
] | [
"4\n",
"2\n"
] | In the first sample, the optimal order is: 10,β20,β30,β40,β50.
In the second sample, the optimal order is: 100,β200,β100,β200. | 1,000 | [
{
"input": "5\n20 30 10 50 40",
"output": "4"
},
{
"input": "4\n200 100 100 200",
"output": "2"
},
{
"input": "10\n2 2 2 2 2 2 2 2 2 2",
"output": "0"
},
{
"input": "1\n1000",
"output": "0"
},
{
"input": "2\n444 333",
"output": "1"
},
{
"input": "100\n... | 1,648,823,655 | 2,147,483,647 | PyPy 3 | OK | TESTS | 31 | 93 | 1,740,800 | from collections import Counter
n = int(input())
a = sorted([int(i) for i in input().split()])
cnt = Counter(a)
res = []
for i in range(max(cnt.values())):
for key in cnt :
if cnt[key] != 0 : res.append(key); cnt[key] -= 1
ans = 0
for i in range(1, n) :
if res[i] > res[i-1] : ans... | Title: Beautiful Paintings
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* pictures delivered for the new exhibition. The *i*-th painting has beauty *a**i*. We know that a visitor becomes happy every time he passes from a painting to a more beautiful one.
We are allowed to a... | ```python
from collections import Counter
n = int(input())
a = sorted([int(i) for i in input().split()])
cnt = Counter(a)
res = []
for i in range(max(cnt.values())):
for key in cnt :
if cnt[key] != 0 : res.append(key); cnt[key] -= 1
ans = 0
for i in range(1, n) :
if res[i] > res[... | 3 | |
0 | none | none | none | 0 | [
"none"
] | null | null | Santa Claus is the first who came to the Christmas Olympiad, and he is going to be the first to take his place at a desk! In the classroom there are *n* lanes of *m* desks each, and there are two working places at each of the desks. The lanes are numbered from 1 to *n* from the left to the right, the desks in a lane ar... | The only line contains three integers *n*, *m* and *k* (1<=β€<=*n*,<=*m*<=β€<=10<=000, 1<=β€<=*k*<=β€<=2*nm*)Β β the number of lanes, the number of desks in each lane and the number of Santa Claus' place. | Print two integers: the number of lane *r*, the number of desk *d*, and a character *s*, which stands for the side of the desk Santa Claus. The character *s* should be "L", if Santa Clause should sit on the left, and "R" if his place is on the right. | [
"4 3 9\n",
"4 3 24\n",
"2 4 4\n"
] | [
"2 2 L\n",
"4 3 R\n",
"1 2 R\n"
] | The first and the second samples are shown on the picture. The green place corresponds to Santa Claus' place in the first example, the blue place corresponds to Santa Claus' place in the second example.
In the third sample there are two lanes with four desks in each, and Santa Claus has the fourth place. Thus, his pla... | 0 | [
{
"input": "4 3 9",
"output": "2 2 L"
},
{
"input": "4 3 24",
"output": "4 3 R"
},
{
"input": "2 4 4",
"output": "1 2 R"
},
{
"input": "3 10 24",
"output": "2 2 R"
},
{
"input": "10 3 59",
"output": "10 3 L"
},
{
"input": "10000 10000 160845880",
"... | 1,482,657,101 | 401 | Python 3 | OK | TESTS | 46 | 109 | 6,246,400 | import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time
sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7
def main():
n,l,t = list(map(int, input().split()))
a = (t+1)//2
s = 'L' if t%2==1 else 'R'
return ' '.join(map(str, [(a-1)//l+1, (a-1)%l+1, s]))
print... | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Santa Claus is the first who came to the Christmas Olympiad, and he is going to be the first to take his place at a desk! In the classroom there are *n* lanes of *m* desks each, and there are two working places at each of the desk... | ```python
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time
sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7
def main():
n,l,t = list(map(int, input().split()))
a = (t+1)//2
s = 'L' if t%2==1 else 'R'
return ' '.join(map(str, [(a-1)//l+1, (a-1)%l+1, s])... | 3 | |
51 | A | Cheaterius's Problem | PROGRAMMING | 1,300 | [
"implementation"
] | A. Cheaterius's Problem | 2 | 256 | Cheaterius is a famous in all the Berland astrologist, magician and wizard, and he also is a liar and a cheater. One of his latest inventions is Cheaterius' amulets! They bring luck and wealth, but are rather expensive. Cheaterius makes them himself. The technology of their making is kept secret. But we know that throu... | The first line contains an integer *n* (1<=β€<=*n*<=β€<=1000), where *n* is the number of amulets. Then the amulet's descriptions are contained. Every description occupies two lines and contains two numbers (from 1 to 6) in each line. Between every pair of amulets the line "**" is located. | Print the required number of piles. | [
"4\n31\n23\n**\n31\n23\n**\n13\n32\n**\n32\n13\n",
"4\n51\n26\n**\n54\n35\n**\n25\n61\n**\n45\n53\n"
] | [
"1\n",
"2\n"
] | none | 500 | [
{
"input": "4\n31\n23\n**\n31\n23\n**\n13\n32\n**\n32\n13",
"output": "1"
},
{
"input": "4\n51\n26\n**\n54\n35\n**\n25\n61\n**\n45\n53",
"output": "2"
},
{
"input": "4\n56\n61\n**\n31\n31\n**\n33\n11\n**\n11\n33",
"output": "2"
},
{
"input": "4\n36\n44\n**\n32\n46\n**\n66\n41... | 1,656,150,769 | 2,147,483,647 | Python 3 | OK | TESTS | 20 | 92 | 0 | n=int(input())
d=set()
for i in range(n):
s=input()+input()[::-1]
if i<n-1:input()
if all(s not in x for x in d):d.add(2*s)
print(len(d)) | Title: Cheaterius's Problem
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Cheaterius is a famous in all the Berland astrologist, magician and wizard, and he also is a liar and a cheater. One of his latest inventions is Cheaterius' amulets! They bring luck and wealth, but are rather expensive... | ```python
n=int(input())
d=set()
for i in range(n):
s=input()+input()[::-1]
if i<n-1:input()
if all(s not in x for x in d):d.add(2*s)
print(len(d))
``` | 3.977 |
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,604,878,930 | 2,147,483,647 | PyPy 3 | OK | TESTS | 30 | 280 | 0 | import sys
s = sys.stdin.read().strip()
d = sum(i.islower() or -1 for i in s)
print(d < 0 and s.upper() or s.lower())
| Title: Word
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it ei... | ```python
import sys
s = sys.stdin.read().strip()
d = sum(i.islower() or -1 for i in s)
print(d < 0 and s.upper() or s.lower())
``` | 3.93 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.