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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
451 | A | Game With Sticks | PROGRAMMING | 900 | [
"implementation"
] | null | null | After winning gold and silver in IOI 2014, Akshat and Malvika want to have some fun. Now they are playing a game on a grid made of *n* horizontal and *m* vertical sticks.
An intersection point is any point on the grid which is formed by the intersection of one horizontal stick and one vertical stick.
In the grid show... | The first line of input contains two space-separated integers, *n* and *m* (1<=β€<=*n*,<=*m*<=β€<=100). | Print a single line containing "Akshat" or "Malvika" (without the quotes), depending on the winner of the game. | [
"2 2\n",
"2 3\n",
"3 3\n"
] | [
"Malvika\n",
"Malvika\n",
"Akshat\n"
] | Explanation of the first sample:
The grid has four intersection points, numbered from 1 to 4.
If Akshat chooses intersection point 1, then he will remove two sticks (1β-β2 and 1β-β3). The resulting grid will look like this.
Now there is only one remaining intersection point (i.e. 4). Malvika must choose it and remov... | 500 | [
{
"input": "2 2",
"output": "Malvika"
},
{
"input": "2 3",
"output": "Malvika"
},
{
"input": "3 3",
"output": "Akshat"
},
{
"input": "20 68",
"output": "Malvika"
},
{
"input": "1 1",
"output": "Akshat"
},
{
"input": "1 2",
"output": "Akshat"
},
... | 1,682,757,744 | 2,147,483,647 | Python 3 | OK | TESTS | 28 | 46 | 0 | n,m =input().split()
if int(n)<= int(m):
if int(n)%2 == 0:
print("Malvika")
else:
print("Akshat")
else:
if int(m)%2 == 0:
print("Malvika")
else:
print("Akshat")
| Title: Game With Sticks
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
After winning gold and silver in IOI 2014, Akshat and Malvika want to have some fun. Now they are playing a game on a grid made of *n* horizontal and *m* vertical sticks.
An intersection point is any point on the grid... | ```python
n,m =input().split()
if int(n)<= int(m):
if int(n)%2 == 0:
print("Malvika")
else:
print("Akshat")
else:
if int(m)%2 == 0:
print("Malvika")
else:
print("Akshat")
``` | 3 | |
445 | B | DZY Loves Chemistry | PROGRAMMING | 1,400 | [
"dfs and similar",
"dsu",
"greedy"
] | null | null | DZY loves chemistry, and he enjoys mixing chemicals.
DZY has *n* chemicals, and *m* pairs of them will react. He wants to pour these chemicals into a test tube, and he needs to pour them in one by one, in any order.
Let's consider the danger of a test tube. Danger of an empty test tube is 1. And every time when DZY ... | The first line contains two space-separated integers *n* and *m* .
Each of the next *m* lines contains two space-separated integers *x**i* and *y**i* (1<=β€<=*x**i*<=<<=*y**i*<=β€<=*n*). These integers mean that the chemical *x**i* will react with the chemical *y**i*. Each pair of chemicals will appear at most once i... | Print a single integer β the maximum possible danger. | [
"1 0\n",
"2 1\n1 2\n",
"3 2\n1 2\n2 3\n"
] | [
"1\n",
"2\n",
"4\n"
] | In the first sample, there's only one way to pour, and the danger won't increase.
In the second sample, no matter we pour the 1st chemical first, or pour the 2nd chemical first, the answer is always 2.
In the third sample, there are four ways to achieve the maximum possible danger: 2-1-3, 2-3-1, 1-2-3 and 3-2-1 (that... | 1,000 | [
{
"input": "1 0",
"output": "1"
},
{
"input": "2 1\n1 2",
"output": "2"
},
{
"input": "3 2\n1 2\n2 3",
"output": "4"
},
{
"input": "10 10\n1 8\n4 10\n4 6\n5 10\n2 3\n1 7\n3 4\n3 6\n6 9\n3 7",
"output": "512"
},
{
"input": "20 20\n6 8\n13 20\n7 13\n6 17\n5 15\n1 12... | 1,600,454,986 | 2,147,483,647 | Python 3 | OK | TESTS | 32 | 109 | 307,200 | n, m = map(int, input().split())
graph, visited = [[] for _ in range(n + 1)], set()
for _ in range(m):
a, b = map(int, input().split())
graph[a].append(b)
graph[b].append(a)
def dfs(element):
visited.add(element)
for each in graph[element]:
if each not in visited:
... | Title: DZY Loves Chemistry
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
DZY loves chemistry, and he enjoys mixing chemicals.
DZY has *n* chemicals, and *m* pairs of them will react. He wants to pour these chemicals into a test tube, and he needs to pour them in one by one, in any order... | ```python
n, m = map(int, input().split())
graph, visited = [[] for _ in range(n + 1)], set()
for _ in range(m):
a, b = map(int, input().split())
graph[a].append(b)
graph[b].append(a)
def dfs(element):
visited.add(element)
for each in graph[element]:
if each not in visited:
... | 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,634,924,152 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 249 | 6,860,800 | def mincost(T,A,B):
min = 101
count = 0
for i in range(T):
if B[i]<min:
min = B[i]
count+=A[i]*min
return count
N = int(input())
P = []
Q = []
for i in range(N):
A,B = map(int,input().split())
P.append(A)
Q.append(B)
print(mincost(N,P,Q))
| 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
def mincost(T,A,B):
min = 101
count = 0
for i in range(T):
if B[i]<min:
min = B[i]
count+=A[i]*min
return count
N = int(input())
P = []
Q = []
for i in range(N):
A,B = map(int,input().split())
P.append(A)
Q.append(B)
print(mincost(N,P,Q)... | 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,695,722,400 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 71 | 154 | 0 | string = input()
result = string.split('WUB')
for word in result:
if len(word)!=0:
print(word,end=' ')
print() | 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
string = input()
result = string.split('WUB')
for word in result:
if len(word)!=0:
print(word,end=' ')
print()
``` | 3 | |
66 | B | Petya and Countryside | PROGRAMMING | 1,100 | [
"brute force",
"implementation"
] | B. Petya and Countryside | 2 | 256 | Little Petya often travels to his grandmother in the countryside. The grandmother has a large garden, which can be represented as a rectangle 1<=Γ<=*n* in size, when viewed from above. This rectangle is divided into *n* equal square sections. The garden is very unusual as each of the square sections possesses its own f... | The first line contains a positive integer *n* (1<=β€<=*n*<=β€<=1000). The second line contains *n* positive integers which are the height of the sections. All the numbers are no less than 1 and not more than 1000. | Print a single number, the maximal number of watered sections if we create artificial rain above exactly one section. | [
"1\n2\n",
"5\n1 2 1 2 1\n",
"8\n1 2 1 1 1 3 3 4\n"
] | [
"1\n",
"3\n",
"6\n"
] | none | 1,000 | [
{
"input": "1\n2",
"output": "1"
},
{
"input": "5\n1 2 1 2 1",
"output": "3"
},
{
"input": "8\n1 2 1 1 1 3 3 4",
"output": "6"
},
{
"input": "10\n1 2 3 4 5 6 7 8 9 10",
"output": "10"
},
{
"input": "10\n10 9 8 7 6 5 4 3 2 1",
"output": "10"
},
{
"input... | 1,667,992,274 | 2,147,483,647 | Python 3 | OK | TESTS | 80 | 92 | 0 |
def solve(n, l):
p = c = out = 1
for i in range(1, n):
if l[i] > l[i-1]:
p += 1
c = p
elif l[i] == l[i-1]:
p += 1
c += 1
else:
c += 1
p = 1
if c > out:
out = c
return out
n = int(input()... | Title: Petya and Countryside
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Little Petya often travels to his grandmother in the countryside. The grandmother has a large garden, which can be represented as a rectangle 1<=Γ<=*n* in size, when viewed from above. This rectangle is divided into *... | ```python
def solve(n, l):
p = c = out = 1
for i in range(1, n):
if l[i] > l[i-1]:
p += 1
c = p
elif l[i] == l[i-1]:
p += 1
c += 1
else:
c += 1
p = 1
if c > out:
out = c
return out
n = i... | 3.977 |
808 | A | Lucky Year | PROGRAMMING | 900 | [
"implementation"
] | null | null | Apart from having lots of holidays throughout the year, residents of Berland also have whole lucky years. Year is considered lucky if it has no more than 1 non-zero digit in its number. So years 100, 40000, 5 are lucky and 12, 3001 and 12345 are not.
You are given current year in Berland. Your task is to find how long... | The first line contains integer number *n* (1<=β€<=*n*<=β€<=109) β current year in Berland. | Output amount of years from the current year to the next lucky one. | [
"4\n",
"201\n",
"4000\n"
] | [
"1\n",
"99\n",
"1000\n"
] | In the first example next lucky year is 5. In the second one β 300. In the third β 5000. | 0 | [
{
"input": "4",
"output": "1"
},
{
"input": "201",
"output": "99"
},
{
"input": "4000",
"output": "1000"
},
{
"input": "9",
"output": "1"
},
{
"input": "10",
"output": "10"
},
{
"input": "1",
"output": "1"
},
{
"input": "100000000",
"ou... | 1,606,258,881 | 2,147,483,647 | Python 3 | OK | TESTS | 271 | 109 | 0 | n = input()
if len(n) == 1:
print(1)
else:
a = int(n[0])
zeros =''
for i in range(len(n)-1):
zeros += '0'
b = (a +1) * int('1'+ zeros)
difference = b - int(n)
print(difference) | Title: Lucky Year
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Apart from having lots of holidays throughout the year, residents of Berland also have whole lucky years. Year is considered lucky if it has no more than 1 non-zero digit in its number. So years 100, 40000, 5 are lucky and 1... | ```python
n = input()
if len(n) == 1:
print(1)
else:
a = int(n[0])
zeros =''
for i in range(len(n)-1):
zeros += '0'
b = (a +1) * int('1'+ zeros)
difference = b - int(n)
print(difference)
``` | 3 | |
535 | B | Tavas and SaDDas | PROGRAMMING | 1,100 | [
"bitmasks",
"brute force",
"combinatorics",
"implementation"
] | null | null | Once again Tavas started eating coffee mix without water! Keione told him that it smells awful, but he didn't stop doing that. That's why Keione told his smart friend, SaDDas to punish him! SaDDas took Tavas' headphones and told him: "If you solve the following problem, I'll return it to you."
The problem is:
You ar... | The first and only line of input contains a lucky number *n* (1<=β€<=*n*<=β€<=109). | Print the index of *n* among all lucky numbers. | [
"4\n",
"7\n",
"77\n"
] | [
"1\n",
"2\n",
"6\n"
] | none | 1,000 | [
{
"input": "4",
"output": "1"
},
{
"input": "7",
"output": "2"
},
{
"input": "77",
"output": "6"
},
{
"input": "4",
"output": "1"
},
{
"input": "474744",
"output": "83"
},
{
"input": "777774",
"output": "125"
},
{
"input": "447",
"outpu... | 1,632,312,786 | 2,147,483,647 | Python 3 | OK | TESTS | 33 | 78 | 6,758,400 | from sys import stdin,stdout
# stdin.readline()
for _ in range(1):
n=int(stdin.readline())
ans=0
c=0
while n>0:
c+=1
x=n%10
if x==7:
ans+=(2**c)
else:
ans+=(2**(c-1))
n=n//10
print(ans) | Title: Tavas and SaDDas
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Once again Tavas started eating coffee mix without water! Keione told him that it smells awful, but he didn't stop doing that. That's why Keione told his smart friend, SaDDas to punish him! SaDDas took Tavas' headphone... | ```python
from sys import stdin,stdout
# stdin.readline()
for _ in range(1):
n=int(stdin.readline())
ans=0
c=0
while n>0:
c+=1
x=n%10
if x==7:
ans+=(2**c)
else:
ans+=(2**(c-1))
n=n//10
print(ans)
``` | 3 | |
569 | B | Inventory | PROGRAMMING | 1,200 | [
"greedy",
"math"
] | null | null | Companies always have a lot of equipment, furniture and other things. All of them should be tracked. To do this, there is an inventory number assigned with each item. It is much easier to create a database by using those numbers and keep the track of everything.
During an audit, you were surprised to find out that the... | The first line contains a single integer *n*Β β the number of items (1<=β€<=*n*<=β€<=105).
The second line contains *n* numbers *a*1,<=*a*2,<=...,<=*a**n* (1<=β€<=*a**i*<=β€<=105)Β β the initial inventory numbers of the items. | Print *n* numbersΒ β the final inventory numbers of the items in the order they occur in the input. If there are multiple possible answers, you may print any of them. | [
"3\n1 3 2\n",
"4\n2 2 3 3\n",
"1\n2\n"
] | [
"1 3 2 \n",
"2 1 3 4 \n",
"1 \n"
] | In the first test the numeration is already a permutation, so there is no need to change anything.
In the second test there are two pairs of equal numbers, in each pair you need to replace one number.
In the third test you need to replace 2 by 1, as the numbering should start from one. | 1,000 | [
{
"input": "3\n1 3 2",
"output": "1 3 2 "
},
{
"input": "4\n2 2 3 3",
"output": "2 1 3 4 "
},
{
"input": "1\n2",
"output": "1 "
},
{
"input": "3\n3 3 1",
"output": "3 2 1 "
},
{
"input": "5\n1 1 1 1 1",
"output": "1 2 3 4 5 "
},
{
"input": "5\n5 3 4 4 ... | 1,597,647,547 | 2,147,483,647 | PyPy 3 | OK | TESTS | 29 | 280 | 18,227,200 | def main():
n = int(input())
a = list(map(int,input().split()))
used = set()
original = set(a)
not_used = set(range(1,n+1)) - original
for i in range(n):
if a[i] > n or a[i] in used:
temp = next(iter(not_used),None)
if temp is not None:
a[i] = tem... | Title: Inventory
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Companies always have a lot of equipment, furniture and other things. All of them should be tracked. To do this, there is an inventory number assigned with each item. It is much easier to create a database by using those numb... | ```python
def main():
n = int(input())
a = list(map(int,input().split()))
used = set()
original = set(a)
not_used = set(range(1,n+1)) - original
for i in range(n):
if a[i] > n or a[i] in used:
temp = next(iter(not_used),None)
if temp is not None:
... | 3 | |
688 | B | Lovely Palindromes | PROGRAMMING | 1,000 | [
"constructive algorithms",
"math"
] | null | null | Pari has a friend who loves palindrome numbers. A palindrome number is a number that reads the same forward or backward. For example 12321, 100001 and 1 are palindrome numbers, while 112 and 1021 are not.
Pari is trying to love them too, but only very special and gifted people can understand the beauty behind palindro... | The only line of the input contains a single integer *n* (1<=β€<=*n*<=β€<=10100<=000). | Print the *n*-th even-length palindrome number. | [
"1\n",
"10\n"
] | [
"11\n",
"1001\n"
] | The first 10 even-length palindrome numbers are 11,β22,β33,β... ,β88,β99 and 1001. | 1,000 | [
{
"input": "1",
"output": "11"
},
{
"input": "10",
"output": "1001"
},
{
"input": "11",
"output": "1111"
},
{
"input": "12",
"output": "1221"
},
{
"input": "100",
"output": "100001"
},
{
"input": "1321",
"output": "13211231"
},
{
"input": "... | 1,622,398,844 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 77 | 409,600 | a=input()
print(a+a[::-1]) | Title: Lovely Palindromes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Pari has a friend who loves palindrome numbers. A palindrome number is a number that reads the same forward or backward. For example 12321, 100001 and 1 are palindrome numbers, while 112 and 1021 are not.
Pari is tr... | ```python
a=input()
print(a+a[::-1])
``` | 3 | |
141 | A | Amusing Joke | PROGRAMMING | 800 | [
"implementation",
"sortings",
"strings"
] | null | null | So, the New Year holidays are over. Santa Claus and his colleagues can take a rest and have guests at last. When two "New Year and Christmas Men" meet, thear assistants cut out of cardboard the letters from the guest's name and the host's name in honor of this event. Then the hung the letters above the main entrance. O... | The input file consists of three lines: the first line contains the guest's name, the second line contains the name of the residence host and the third line contains letters in a pile that were found at the door in the morning. All lines are not empty and contain only uppercase Latin letters. The length of each line do... | Print "YES" without the quotes, if the letters in the pile could be permuted to make the names of the "New Year and Christmas Men". Otherwise, print "NO" without the quotes. | [
"SANTACLAUS\nDEDMOROZ\nSANTAMOROZDEDCLAUS\n",
"PAPAINOEL\nJOULUPUKKI\nJOULNAPAOILELUPUKKI\n",
"BABBONATALE\nFATHERCHRISTMAS\nBABCHRISTMASBONATALLEFATHER\n"
] | [
"YES\n",
"NO\n",
"NO\n"
] | In the first sample the letters written in the last line can be used to write the names and there won't be any extra letters left.
In the second sample letter "P" is missing from the pile and there's an extra letter "L".
In the third sample there's an extra letter "L". | 500 | [
{
"input": "SANTACLAUS\nDEDMOROZ\nSANTAMOROZDEDCLAUS",
"output": "YES"
},
{
"input": "PAPAINOEL\nJOULUPUKKI\nJOULNAPAOILELUPUKKI",
"output": "NO"
},
{
"input": "BABBONATALE\nFATHERCHRISTMAS\nBABCHRISTMASBONATALLEFATHER",
"output": "NO"
},
{
"input": "B\nA\nAB",
"output": ... | 1,691,106,002 | 2,147,483,647 | Python 3 | OK | TESTS | 54 | 92 | 0 | g=(input())
h=(input())
c=(input())
print("YES" if sorted(g+h)==sorted(c) else "NO") | Title: Amusing Joke
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
So, the New Year holidays are over. Santa Claus and his colleagues can take a rest and have guests at last. When two "New Year and Christmas Men" meet, thear assistants cut out of cardboard the letters from the guest's nam... | ```python
g=(input())
h=(input())
c=(input())
print("YES" if sorted(g+h)==sorted(c) else "NO")
``` | 3 | |
12 | A | Super Agent | PROGRAMMING | 800 | [
"implementation"
] | A. Super Agent | 2 | 256 | There is a very secret base in Potatoland where potato mash is made according to a special recipe. The neighbours from Porridgia decided to seize this recipe and to sell it to Pilauland. For this mission they have been preparing special agent Pearlo for many years. When, finally, Pearlo learned all secrets of espionage... | Input contains the matrix of three rows of three symbols each. Symbol Β«XΒ» means that the corresponding button was pressed, and Β«.Β» means that is was not pressed. The matrix may contain no Β«XΒ», also it may contain no Β«.Β». | Print YES if the password is symmetric with respect to the central button of the terminal and NO otherwise. | [
"XX.\n...\n.XX\n",
"X.X\nX..\n...\n"
] | [
"YES\n",
"NO\n"
] | If you are not familiar with the term Β«central symmetryΒ», you may look into http://en.wikipedia.org/wiki/Central_symmetry | 0 | [
{
"input": "XX.\n...\n.XX",
"output": "YES"
},
{
"input": ".X.\n.X.\n.X.",
"output": "YES"
},
{
"input": "XXX\nXXX\nXXX",
"output": "YES"
},
{
"input": "XXX\nX.X\nXXX",
"output": "YES"
},
{
"input": "X..\n.X.\n..X",
"output": "YES"
},
{
"input": "...\n... | 1,617,501,839 | 2,147,483,647 | PyPy 3 | OK | TESTS | 40 | 248 | 0 | m = []
for i in range(3):
m.append(input())
if m[0] != m[2][::-1]: print('NO')
else:
if(m[1][0] == m[1][2]):
print('YES')
else:
print('NO')
| Title: Super Agent
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
There is a very secret base in Potatoland where potato mash is made according to a special recipe. The neighbours from Porridgia decided to seize this recipe and to sell it to Pilauland. For this mission they have been preparin... | ```python
m = []
for i in range(3):
m.append(input())
if m[0] != m[2][::-1]: print('NO')
else:
if(m[1][0] == m[1][2]):
print('YES')
else:
print('NO')
``` | 3.938 |
43 | A | Football | PROGRAMMING | 1,000 | [
"strings"
] | A. Football | 2 | 256 | One day Vasya decided to have a look at the results of Berland 1910 Football Championshipβs finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process. On the whole there are *n* lines in that description each of which described one goal. E... | The first line contains an integer *n* (1<=β€<=*n*<=β€<=100) β the number of lines in the description. Then follow *n* lines β for each goal the names of the teams that scored it. The names are non-empty lines consisting of uppercase Latin letters whose lengths do not exceed 10 symbols. It is guaranteed that the match di... | Print the name of the winning team. We remind you that in football the team that scores more goals is considered the winner. | [
"1\nABC\n",
"5\nA\nABA\nABA\nA\nA\n"
] | [
"ABC\n",
"A\n"
] | none | 500 | [
{
"input": "1\nABC",
"output": "ABC"
},
{
"input": "5\nA\nABA\nABA\nA\nA",
"output": "A"
},
{
"input": "2\nXTSJEP\nXTSJEP",
"output": "XTSJEP"
},
{
"input": "3\nXZYDJAEDZ\nXZYDJAEDZ\nXZYDJAEDZ",
"output": "XZYDJAEDZ"
},
{
"input": "3\nQCCYXL\nQCCYXL\nAXGLFQDD",
... | 1,541,246,493 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 218 | 0 | num=int(input())
d={}
scores=[]
for i in range(num):
team=input()
if(team not in d):
d[team]=1
else:
d[team]+=1
listD=sorted(d.values())
for key in d.keys():
if(d[key]==listD[-1]):
print(key)
break
| 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
num=int(input())
d={}
scores=[]
for i in range(num):
team=input()
if(team not in d):
d[team]=1
else:
d[team]+=1
listD=sorted(d.values())
for key in d.keys():
if(d[key]==listD[-1]):
print(key)
break
``` | 3.9455 |
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,699,015,141 | 2,147,483,647 | Python 3 | OK | TESTS | 29 | 46 | 0 | n,h = map(int,input().split())
l = list(map(int,input().split()))
c = 0
for i in range(n):
if l[i]<=h:
c+=1
else:
c+=2
print(c) | 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())
l = list(map(int,input().split()))
c = 0
for i in range(n):
if l[i]<=h:
c+=1
else:
c+=2
print(c)
``` | 3 | |
148 | A | Insomnia cure | PROGRAMMING | 800 | [
"constructive algorithms",
"implementation",
"math"
] | null | null | Β«One dragon. Two dragon. Three dragonΒ», β the princess was counting. She had trouble falling asleep, and she got bored of counting lambs when she was nine.
However, just counting dragons was boring as well, so she entertained herself at best she could. Tonight she imagined that all dragons were here to steal her, and ... | Input data contains integer numbers *k*,<=*l*,<=*m*,<=*n* and *d*, each number in a separate line (1<=β€<=*k*,<=*l*,<=*m*,<=*n*<=β€<=10, 1<=β€<=*d*<=β€<=105). | Output the number of damaged dragons. | [
"1\n2\n3\n4\n12\n",
"2\n3\n4\n5\n24\n"
] | [
"12\n",
"17\n"
] | In the first case every first dragon got punched with a frying pan. Some of the dragons suffered from other reasons as well, but the pan alone would be enough.
In the second case dragons 1, 7, 11, 13, 17, 19 and 23 escaped unharmed. | 1,000 | [
{
"input": "1\n2\n3\n4\n12",
"output": "12"
},
{
"input": "2\n3\n4\n5\n24",
"output": "17"
},
{
"input": "1\n1\n1\n1\n100000",
"output": "100000"
},
{
"input": "10\n9\n8\n7\n6",
"output": "0"
},
{
"input": "8\n4\n4\n3\n65437",
"output": "32718"
},
{
"i... | 1,699,115,619 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 124 | 0 | k = int(input())
l = int(input())
m = int(input())
n = int(input())
d = int(input())
count = 0
while d>0:
if d%k==0 or d%l==0 or d%m==0 or d%n==0:
count = count + 1
d = d-1
print(count) | Title: Insomnia cure
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Β«One dragon. Two dragon. Three dragonΒ», β the princess was counting. She had trouble falling asleep, and she got bored of counting lambs when she was nine.
However, just counting dragons was boring as well, so she entert... | ```python
k = int(input())
l = int(input())
m = int(input())
n = int(input())
d = int(input())
count = 0
while d>0:
if d%k==0 or d%l==0 or d%m==0 or d%n==0:
count = count + 1
d = d-1
print(count)
``` | 3 | |
701 | B | Cells Not Under Attack | PROGRAMMING | 1,200 | [
"data structures",
"math"
] | null | null | Vasya has the square chessboard of size *n*<=Γ<=*n* and *m* rooks. Initially the chessboard is empty. Vasya will consequently put the rooks on the board one after another.
The cell of the field is under rook's attack, if there is at least one rook located in the same row or in the same column with this cell. If there ... | The first line of the input contains two integers *n* and *m* (1<=β€<=*n*<=β€<=100<=000, 1<=β€<=*m*<=β€<=*min*(100<=000,<=*n*2))Β β the size of the board and the number of rooks.
Each of the next *m* lines contains integers *x**i* and *y**i* (1<=β€<=*x**i*,<=*y**i*<=β€<=*n*)Β β the number of the row and the number of the col... | Print *m* integer, the *i*-th of them should be equal to the number of cells that are not under attack after first *i* rooks are put. | [
"3 3\n1 1\n3 1\n2 2\n",
"5 2\n1 5\n5 1\n",
"100000 1\n300 400\n"
] | [
"4 2 0 \n",
"16 9 \n",
"9999800001 \n"
] | On the picture below show the state of the board after put each of the three rooks. The cells which painted with grey color is not under the attack. | 750 | [
{
"input": "3 3\n1 1\n3 1\n2 2",
"output": "4 2 0 "
},
{
"input": "5 2\n1 5\n5 1",
"output": "16 9 "
},
{
"input": "100000 1\n300 400",
"output": "9999800001 "
},
{
"input": "10 4\n2 8\n1 8\n9 8\n6 9",
"output": "81 72 63 48 "
},
{
"input": "30 30\n3 13\n27 23\n18... | 1,631,389,176 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 373 | 23,142,400 | n, m=[int(k) for k in input().split()]
a, b=n, n
c, q=set(), set()
res=n*n
eta=[]
for j in range(m):
x, y=[int(k) for k in input().split()]
if x not in c:
a-=1
res-=b
c.add(x)
if y not in q:
b-=1
res-=a
q.add(y)
eta.append(res)
print(" ".jo... | Title: Cells Not Under Attack
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya has the square chessboard of size *n*<=Γ<=*n* and *m* rooks. Initially the chessboard is empty. Vasya will consequently put the rooks on the board one after another.
The cell of the field is under rook's a... | ```python
n, m=[int(k) for k in input().split()]
a, b=n, n
c, q=set(), set()
res=n*n
eta=[]
for j in range(m):
x, y=[int(k) for k in input().split()]
if x not in c:
a-=1
res-=b
c.add(x)
if y not in q:
b-=1
res-=a
q.add(y)
eta.append(res)
pr... | 3 | |
812 | C | Sagheer and Nubian Market | PROGRAMMING | 1,500 | [
"binary search",
"sortings"
] | null | null | On his trip to Luxor and Aswan, Sagheer went to a Nubian market to buy some souvenirs for his friends and relatives. The market has some strange rules. It contains *n* different items numbered from 1 to *n*. The *i*-th item has base cost *a**i* Egyptian pounds. If Sagheer buys *k* items with indices *x*1,<=*x*2,<=...,<... | The first line contains two integers *n* and *S* (1<=β€<=*n*<=β€<=105 and 1<=β€<=*S*<=β€<=109)Β β the number of souvenirs in the market and Sagheer's budget.
The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=β€<=*a**i*<=β€<=105)Β β the base costs of the souvenirs. | On a single line, print two integers *k*, *T*Β β the maximum number of souvenirs Sagheer can buy and the minimum total cost to buy these *k* souvenirs. | [
"3 11\n2 3 5\n",
"4 100\n1 2 5 6\n",
"1 7\n7\n"
] | [
"2 11\n",
"4 54\n",
"0 0\n"
] | In the first example, he cannot take the three items because they will cost him [5,β9,β14] with total cost 28. If he decides to take only two items, then the costs will be [4,β7,β11]. So he can afford the first and second items.
In the second example, he can buy all items as they will cost him [5,β10,β17,β22].
In the... | 1,500 | [
{
"input": "3 11\n2 3 5",
"output": "2 11"
},
{
"input": "4 100\n1 2 5 6",
"output": "4 54"
},
{
"input": "1 7\n7",
"output": "0 0"
},
{
"input": "1 7\n5",
"output": "1 6"
},
{
"input": "1 1\n1",
"output": "0 0"
},
{
"input": "4 33\n4 3 2 1",
"outp... | 1,581,626,880 | 2,147,483,647 | PyPy 3 | OK | TESTS | 57 | 467 | 24,064,000 | def arr_enu():
return list([[i + 1, int(x)] for i, x in enumerate(stdin.readline().split())])
def calculate(x):
tem = []
for i in range(n):
tem.append(a[i][1] + a[i][0] * x)
tem.sort()
s = sum(tem[:x])
return s
def bs():
global ans
en, be = n, 0
while ... | Title: Sagheer and Nubian Market
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
On his trip to Luxor and Aswan, Sagheer went to a Nubian market to buy some souvenirs for his friends and relatives. The market has some strange rules. It contains *n* different items numbered from 1 to *n*. T... | ```python
def arr_enu():
return list([[i + 1, int(x)] for i, x in enumerate(stdin.readline().split())])
def calculate(x):
tem = []
for i in range(n):
tem.append(a[i][1] + a[i][0] * x)
tem.sort()
s = sum(tem[:x])
return s
def bs():
global ans
en, be = n, 0
... | 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,450,252,141 | 2,147,483,647 | Python 3 | OK | TESTS | 32 | 92 | 0 | N=int(input())
n=[int(i) for i in input().split()]
a=[]
b=[]
for i in range(N):
if n[i]%2==0:
a.append(str(i+1))
else:
b.append(str(i+1))
if len(a)==1:
print(''.join(a))
else:
print(''.join(b))
| 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())
n=[int(i) for i in input().split()]
a=[]
b=[]
for i in range(N):
if n[i]%2==0:
a.append(str(i+1))
else:
b.append(str(i+1))
if len(a)==1:
print(''.join(a))
else:
print(''.join(b))
``` | 3.977 |
53 | C | Little Frog | PROGRAMMING | 1,200 | [
"constructive algorithms"
] | C. Little Frog | 2 | 256 | Once upon a time a little frog whose name was Vasya decided to travel around his home swamp. Overall there are *n* mounds on the swamp, located on one line. The distance between the neighboring mounds is one meter. Vasya wants to visit all the mounds in one day; besides, he wants to visit each one exactly once. For tha... | The single line contains a number *n* (1<=β€<=*n*<=β€<=104) which is the number of mounds. | Print *n* integers *p**i* (1<=β€<=*p**i*<=β€<=*n*) which are the frog's route plan.
- All the *p**i*'s should be mutually different. - All the |*p**i*β*p**i*<=+<=1|'s should be mutually different (1<=β€<=*i*<=β€<=*n*<=-<=1).
If there are several solutions, output any. | [
"2\n",
"3\n"
] | [
"1 2 ",
"1 3 2 "
] | none | 1,500 | [
{
"input": "2",
"output": "1 2 "
},
{
"input": "3",
"output": "1 3 2 "
},
{
"input": "4",
"output": "1 4 2 3 "
},
{
"input": "5",
"output": "1 5 2 4 3 "
},
{
"input": "6",
"output": "1 6 2 5 3 4 "
},
{
"input": "1",
"output": "1 "
},
{
"inp... | 1,571,540,858 | 2,147,483,647 | PyPy 3 | OK | TESTS | 22 | 342 | 3,788,800 | n = int(input())
x = 1
y = n
while 1:
if x > n // 2:
if n % 2: print(x)
break
print(x, y, end = " ")
x += 1
y -= 1 | Title: Little Frog
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Once upon a time a little frog whose name was Vasya decided to travel around his home swamp. Overall there are *n* mounds on the swamp, located on one line. The distance between the neighboring mounds is one meter. Vasya wants ... | ```python
n = int(input())
x = 1
y = n
while 1:
if x > n // 2:
if n % 2: print(x)
break
print(x, y, end = " ")
x += 1
y -= 1
``` | 3.907443 |
803 | D | Magazine Ad | PROGRAMMING | 1,900 | [
"binary search",
"greedy"
] | null | null | The main city magazine offers its readers an opportunity to publish their ads. The format of the ad should be like this:
There are space-separated non-empty words of lowercase and uppercase Latin letters.
There are hyphen characters '-' in some words, their positions set word wrapping points. Word can include more th... | The first line contains number *k* (1<=β€<=*k*<=β€<=105).
The second line contains the text of the ad β non-empty space-separated words of lowercase and uppercase Latin letters and hyphens. Total length of the ad don't exceed 106 characters. | Output minimal width of the ad. | [
"4\ngarage for sa-le\n",
"4\nEdu-ca-tion-al Ro-unds are so fun\n"
] | [
"7\n",
"10\n"
] | Here all spaces are replaced with dots.
In the first example one of possible results after all word wraps looks like this:
The second example: | 0 | [
{
"input": "4\ngarage for sa-le",
"output": "7"
},
{
"input": "4\nEdu-ca-tion-al Ro-unds are so fun",
"output": "10"
},
{
"input": "1\nj",
"output": "1"
},
{
"input": "10\nb",
"output": "1"
},
{
"input": "1\nQGVsfZevMD",
"output": "10"
},
{
"input": "1... | 1,694,223,443 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 30 | 202 | 38,400,000 | lines_limit = int(input())
text = input()
tokens = text.replace('-', ' ').split()
def is_enough(char_cnt_per_line: int) -> bool:
remaining_cnt = char_cnt_per_line
total_lines_cnt = 1
for i, t in enumerate(tokens):
if len(t) + (i != len(tokens) - 1) > remaining_cnt:
total_lines_cnt += 1
... | Title: Magazine Ad
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The main city magazine offers its readers an opportunity to publish their ads. The format of the ad should be like this:
There are space-separated non-empty words of lowercase and uppercase Latin letters.
There are hyphen... | ```python
lines_limit = int(input())
text = input()
tokens = text.replace('-', ' ').split()
def is_enough(char_cnt_per_line: int) -> bool:
remaining_cnt = char_cnt_per_line
total_lines_cnt = 1
for i, t in enumerate(tokens):
if len(t) + (i != len(tokens) - 1) > remaining_cnt:
total_lines... | 3 | |
78 | B | Easter Eggs | PROGRAMMING | 1,200 | [
"constructive algorithms",
"implementation"
] | B. Easter Eggs | 2 | 256 | The Easter Rabbit laid *n* eggs in a circle and is about to paint them.
Each egg should be painted one color out of 7: red, orange, yellow, green, blue, indigo or violet. Also, the following conditions should be satisfied:
- Each of the seven colors should be used to paint at least one egg. - Any four eggs lying s... | The only line contains an integer *n* β the amount of eggs (7<=β€<=*n*<=β€<=100). | Print one line consisting of *n* characters. The *i*-th character should describe the color of the *i*-th egg in the order they lie in the circle. The colors should be represented as follows: "R" stands for red, "O" stands for orange, "Y" stands for yellow, "G" stands for green, "B" stands for blue, "I" stands for indi... | [
"8\n",
"13\n"
] | [
"ROYGRBIV\n",
"ROYGBIVGBIVYG\n"
] | The way the eggs will be painted in the first sample is shown on the picture: | 1,000 | [
{
"input": "8",
"output": "ROYGBIVG"
},
{
"input": "13",
"output": "ROYGBIVOYGBIV"
},
{
"input": "7",
"output": "ROYGBIV"
},
{
"input": "10",
"output": "ROYGBIVYGB"
},
{
"input": "14",
"output": "ROYGBIVROYGBIV"
},
{
"input": "50",
"output": "ROYGB... | 1,640,061,056 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 34 | 186 | 0 | n = int(input())
s = ''
for i in range(n-3):
s += 'ROYG'[i%4]
print(s + 'BIV') | Title: Easter Eggs
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
The Easter Rabbit laid *n* eggs in a circle and is about to paint them.
Each egg should be painted one color out of 7: red, orange, yellow, green, blue, indigo or violet. Also, the following conditions should be satisfied:
-... | ```python
n = int(input())
s = ''
for i in range(n-3):
s += 'ROYG'[i%4]
print(s + 'BIV')
``` | 3.9535 |
965 | A | Paper Airplanes | PROGRAMMING | 800 | [
"math"
] | null | null | To make a paper airplane, one has to use a rectangular piece of paper. From a sheet of standard size you can make $s$ airplanes.
A group of $k$ people decided to make $n$ airplanes each. They are going to buy several packs of paper, each of them containing $p$ sheets, and then distribute the sheets between the people.... | The only line contains four integers $k$, $n$, $s$, $p$ ($1 \le k, n, s, p \le 10^4$)Β β the number of people, the number of airplanes each should make, the number of airplanes that can be made using one sheet and the number of sheets in one pack, respectively. | Print a single integerΒ β the minimum number of packs they should buy. | [
"5 3 2 3\n",
"5 3 100 1\n"
] | [
"4\n",
"5\n"
] | In the first sample they have to buy $4$ packs of paper: there will be $12$ sheets in total, and giving $2$ sheets to each person is enough to suit everyone's needs.
In the second sample they have to buy a pack for each person as they can't share sheets. | 500 | [
{
"input": "5 3 2 3",
"output": "4"
},
{
"input": "5 3 100 1",
"output": "5"
},
{
"input": "10000 10000 1 1",
"output": "100000000"
},
{
"input": "1 1 10000 10000",
"output": "1"
},
{
"input": "300 300 21 23",
"output": "196"
},
{
"input": "300 2 37 51... | 1,698,670,630 | 2,147,483,647 | Python 3 | OK | TESTS | 18 | 46 | 0 | k, n, s, p = map(int, input().split())
per_person = (n-1) // s+1
total_s = per_person * k
total_p = (total_s-1) // p+1
print(total_p) | Title: Paper Airplanes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
To make a paper airplane, one has to use a rectangular piece of paper. From a sheet of standard size you can make $s$ airplanes.
A group of $k$ people decided to make $n$ airplanes each. They are going to buy several p... | ```python
k, n, s, p = map(int, input().split())
per_person = (n-1) // s+1
total_s = per_person * k
total_p = (total_s-1) // p+1
print(total_p)
``` | 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,564,565,165 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 124 | 0 | a=[]
a=input()
c=0
l=len(a)
if(l>=5):
for i in range(l):
if(a[i]=='h'):
if(c==0):
c=c+1
elif(a[i]=='e'):
if(c==1):
c=c+1
elif(a[i]=='l'):
if(c==2):
c=c+1
elif(c==3):
... | 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
a=[]
a=input()
c=0
l=len(a)
if(l>=5):
for i in range(l):
if(a[i]=='h'):
if(c==0):
c=c+1
elif(a[i]=='e'):
if(c==1):
c=c+1
elif(a[i]=='l'):
if(c==2):
c=c+1
elif(c==3):
... | 3.938 |
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,615,823,070 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 77 | 307,200 | a,b = input().split()
a,b =[int(a),int(b)]
distress=0
total = b
for i in range(a):
inp = eval(input())
if total+inp<0:
distress = distress + 1
else:
total = total+inp
print(f'{total} {distress}')
| 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 = input().split()
a,b =[int(a),int(b)]
distress=0
total = b
for i in range(a):
inp = eval(input())
if total+inp<0:
distress = distress + 1
else:
total = total+inp
print(f'{total} {distress}')
``` | 3 | |
946 | A | Partition | PROGRAMMING | 800 | [
"greedy"
] | null | null | You are given a sequence *a* consisting of *n* integers. You may partition this sequence into two sequences *b* and *c* in such a way that every element belongs exactly to one of these sequences.
Let *B* be the sum of elements belonging to *b*, and *C* be the sum of elements belonging to *c* (if some of these sequenc... | The first line contains one integer *n* (1<=β€<=*n*<=β€<=100) β the number of elements in *a*.
The second line contains *n* integers *a*1, *a*2, ..., *a**n* (<=-<=100<=β€<=*a**i*<=β€<=100) β the elements of sequence *a*. | Print the maximum possible value of *B*<=-<=*C*, where *B* is the sum of elements of sequence *b*, and *C* is the sum of elements of sequence *c*. | [
"3\n1 -2 0\n",
"6\n16 23 16 15 42 8\n"
] | [
"3\n",
"120\n"
] | In the first example we may choose *b*β=β{1,β0}, *c*β=β{β-β2}. Then *B*β=β1, *C*β=ββ-β2, *B*β-β*C*β=β3.
In the second example we choose *b*β=β{16,β23,β16,β15,β42,β8}, *c*β=β{} (an empty sequence). Then *B*β=β120, *C*β=β0, *B*β-β*C*β=β120. | 0 | [
{
"input": "3\n1 -2 0",
"output": "3"
},
{
"input": "6\n16 23 16 15 42 8",
"output": "120"
},
{
"input": "1\n-1",
"output": "1"
},
{
"input": "100\n-100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -10... | 1,576,870,063 | 2,147,483,647 | PyPy 3 | OK | TESTS | 72 | 155 | 0 | n=input()
l=list(map(int,input().split()))
c=0
for i in l:
c+=abs(i)
print(c) | Title: Partition
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a sequence *a* consisting of *n* integers. You may partition this sequence into two sequences *b* and *c* in such a way that every element belongs exactly to one of these sequences.
Let *B* be the sum of eleme... | ```python
n=input()
l=list(map(int,input().split()))
c=0
for i in l:
c+=abs(i)
print(c)
``` | 3 | |
743 | B | Chloe and the sequence | PROGRAMMING | 1,200 | [
"binary search",
"bitmasks",
"constructive algorithms",
"implementation"
] | null | null | Chloe, the same as Vladik, is a competitive programmer. She didn't have any problems to get to the olympiad like Vladik, but she was confused by the task proposed on the olympiad.
Let's consider the following algorithm of generating a sequence of integers. Initially we have a sequence consisting of a single element eq... | The only line contains two integers *n* and *k* (1<=β€<=*n*<=β€<=50, 1<=β€<=*k*<=β€<=2*n*<=-<=1). | Print single integerΒ β the integer at the *k*-th position in the obtained sequence. | [
"3 2\n",
"4 8\n"
] | [
"2",
"4"
] | In the first sample the obtained sequence is [1,β2,β1,β3,β1,β2,β1]. The number on the second position is 2.
In the second sample the obtained sequence is [1,β2,β1,β3,β1,β2,β1,β4,β1,β2,β1,β3,β1,β2,β1]. The number on the eighth position is 4. | 1,000 | [
{
"input": "3 2",
"output": "2"
},
{
"input": "4 8",
"output": "4"
},
{
"input": "5 27",
"output": "1"
},
{
"input": "7 44",
"output": "3"
},
{
"input": "15 18432",
"output": "12"
},
{
"input": "20 259676",
"output": "3"
},
{
"input": "30 6... | 1,640,961,707 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 39 | 109 | 0 | import math
n, k = [int(i) for i in input().split()]
c = 0
while k % 2 == 0:
k = k//2
c += 1
print(c+1)
| Title: Chloe and the sequence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Chloe, the same as Vladik, is a competitive programmer. She didn't have any problems to get to the olympiad like Vladik, but she was confused by the task proposed on the olympiad.
Let's consider the following a... | ```python
import math
n, k = [int(i) for i in input().split()]
c = 0
while k % 2 == 0:
k = k//2
c += 1
print(c+1)
``` | 3 | |
604 | A | Uncowed Forces | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Kevin Sun has just finished competing in Codeforces Round #334! The round was 120 minutes long and featured five problems with maximum point values of 500, 1000, 1500, 2000, and 2500, respectively. Despite the challenging tasks, Kevin was uncowed and bulldozed through all of them, distinguishing himself from the herd a... | The first line of the input contains five space-separated integers *m*1, *m*2, *m*3, *m*4, *m*5, where *m**i* (0<=β€<=*m**i*<=β€<=119) is the time of Kevin's last submission for problem *i*. His last submission is always correct and gets accepted.
The second line contains five space-separated integers *w*1, *w*2, *w*3, ... | Print a single integer, the value of Kevin's final score. | [
"20 40 60 80 100\n0 1 2 3 4\n1 0\n",
"119 119 119 119 119\n0 0 0 0 0\n10 0\n"
] | [
"4900\n",
"4930\n"
] | In the second sample, Kevin takes 119 minutes on all of the problems. Therefore, he gets <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/42158dc2bc78cd21fa679530ae9ef8b9ea298d15.png" style="max-width: 100.0%;max-height: 100.0%;"/> of the points on each problem. So his score from solving pro... | 500 | [
{
"input": "20 40 60 80 100\n0 1 2 3 4\n1 0",
"output": "4900"
},
{
"input": "119 119 119 119 119\n0 0 0 0 0\n10 0",
"output": "4930"
},
{
"input": "3 6 13 38 60\n6 10 10 3 8\n9 9",
"output": "5088"
},
{
"input": "21 44 11 68 75\n6 2 4 8 4\n2 8",
"output": "4522"
},
{... | 1,609,238,334 | 2,147,483,647 | Python 3 | OK | TESTS | 57 | 155 | 819,200 | import math
import os
import random
import re
import sys
import functools
from operator import itemgetter, attrgetter
from collections import Counter
if __name__ == '__main__':
Y = lambda: list(map(int, input().split()))
P = lambda: map(int, input().split())
N = lambda: int(input())
m = ... | Title: Uncowed Forces
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Kevin Sun has just finished competing in Codeforces Round #334! The round was 120 minutes long and featured five problems with maximum point values of 500, 1000, 1500, 2000, and 2500, respectively. Despite the challengin... | ```python
import math
import os
import random
import re
import sys
import functools
from operator import itemgetter, attrgetter
from collections import Counter
if __name__ == '__main__':
Y = lambda: list(map(int, input().split()))
P = lambda: map(int, input().split())
N = lambda: int(input())
... | 3 | |
71 | A | Way Too Long Words | PROGRAMMING | 800 | [
"strings"
] | A. Way Too Long Words | 1 | 256 | Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome.
Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation.
This abbreviation is made lik... | The first line contains an integer *n* (1<=β€<=*n*<=β€<=100). Each of the following *n* lines contains one word. All the words consist of lowercase Latin letters and possess the lengths of from 1 to 100 characters. | Print *n* lines. The *i*-th line should contain the result of replacing of the *i*-th word from the input data. | [
"4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis\n"
] | [
"word\nl10n\ni18n\np43s\n"
] | none | 500 | [
{
"input": "4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis",
"output": "word\nl10n\ni18n\np43s"
},
{
"input": "5\nabcdefgh\nabcdefghi\nabcdefghij\nabcdefghijk\nabcdefghijklm",
"output": "abcdefgh\nabcdefghi\nabcdefghij\na9k\na11m"
},
{
"input":... | 1,679,735,533 | 2,147,483,647 | Python 3 | OK | TESTS | 20 | 46 | 0 | for _ in range(int(input())):
s= input()
n= len(s)
if n> 10:
print(s[0] + str(n- 2) + s[-1])
else:
print(s) | Title: Way Too Long Words
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome.
Let's consider a word too long, if its length is strictly more than 10 character... | ```python
for _ in range(int(input())):
s= input()
n= len(s)
if n> 10:
print(s[0] + str(n- 2) + s[-1])
else:
print(s)
``` | 3.977 |
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,697,987,403 | 2,147,483,647 | Python 3 | OK | TESTS | 71 | 92 | 0 | a = int(input())
sm = 0
mx = 0
for i in range(a):
a, b = map(int, input().split())
sm += b
sm -= a
if mx < sm:
mx = sm
print(mx)
| 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
a = int(input())
sm = 0
mx = 0
for i in range(a):
a, b = map(int, input().split())
sm += b
sm -= a
if mx < sm:
mx = sm
print(mx)
``` | 3 | |
440 | A | Forgotten Episode | PROGRAMMING | 800 | [
"implementation"
] | null | null | Polycarpus adores TV series. Right now he is ready to finish watching a season of a popular sitcom "Graph Theory". In total, the season has *n* episodes, numbered with integers from 1 to *n*.
Polycarpus watches episodes not one by one but in a random order. He has already watched all the episodes except for one. Which... | The first line of the input contains integer *n* (2<=β€<=*n*<=β€<=100000)Β β the number of episodes in a season. Assume that the episodes are numbered by integers from 1 to *n*.
The second line contains *n*<=-<=1 integer *a*1,<=*a*2,<=...,<=*a**n* (1<=β€<=*a**i*<=β€<=*n*)Β β the numbers of episodes that Polycarpus has watch... | Print the number of the episode that Polycarpus hasn't watched. | [
"10\n3 8 10 1 7 9 6 5 2\n"
] | [
"4\n"
] | none | 500 | [
{
"input": "10\n3 8 10 1 7 9 6 5 2",
"output": "4"
},
{
"input": "5\n4 3 2 1",
"output": "5"
},
{
"input": "2\n1",
"output": "2"
},
{
"input": "2\n2",
"output": "1"
},
{
"input": "3\n1 2",
"output": "3"
},
{
"input": "3\n1 3",
"output": "2"
},
... | 1,622,302,885 | 2,147,483,647 | Python 3 | OK | TESTS | 35 | 108 | 9,216,000 | n=int(input())
l=set(map(int,input().split()))
k=set(range(1,n+1))
k1=k-l
print(*k1)
| Title: Forgotten Episode
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarpus adores TV series. Right now he is ready to finish watching a season of a popular sitcom "Graph Theory". In total, the season has *n* episodes, numbered with integers from 1 to *n*.
Polycarpus watches episo... | ```python
n=int(input())
l=set(map(int,input().split()))
k=set(range(1,n+1))
k1=k-l
print(*k1)
``` | 3 | |
609 | B | The Best Gift | PROGRAMMING | 1,100 | [
"constructive algorithms",
"implementation"
] | null | null | Emily's birthday is next week and Jack has decided to buy a present for her. He knows she loves books so he goes to the local bookshop, where there are *n* books on sale from one of *m* genres.
In the bookshop, Jack decides to buy two books of different genres.
Based on the genre of books on sale in the shop, find th... | The first line contains two positive integers *n* and *m* (2<=β€<=*n*<=β€<=2Β·105,<=2<=β€<=*m*<=β€<=10) β the number of books in the bookstore and the number of genres.
The second line contains a sequence *a*1,<=*a*2,<=...,<=*a**n*, where *a**i* (1<=β€<=*a**i*<=β€<=*m*) equals the genre of the *i*-th book.
It is guaranteed ... | Print the only integer β the number of ways in which Jack can choose books.
It is guaranteed that the answer doesn't exceed the value 2Β·109. | [
"4 3\n2 1 3 1\n",
"7 4\n4 2 3 1 2 4 3\n"
] | [
"5\n",
"18\n"
] | The answer to the first test sample equals 5 as Sasha can choose:
1. the first and second books, 1. the first and third books, 1. the first and fourth books, 1. the second and third books, 1. the third and fourth books. | 0 | [
{
"input": "4 3\n2 1 3 1",
"output": "5"
},
{
"input": "7 4\n4 2 3 1 2 4 3",
"output": "18"
},
{
"input": "2 2\n1 2",
"output": "1"
},
{
"input": "3 2\n1 2 2",
"output": "2"
},
{
"input": "10 10\n1 2 3 4 5 6 7 8 9 10",
"output": "45"
},
{
"input": "9 2... | 1,686,791,258 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 42 | 93 | 15,974,400 | from collections import Counter
t=1
n,m = map(int,input().split())
a = Counter(map(int,input().split()))
ans = n*(n-1)//2
for i in range(1,m+1):
ans -= a[i]*(a[i]-1)//2
print(ans)
| Title: The Best Gift
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Emily's birthday is next week and Jack has decided to buy a present for her. He knows she loves books so he goes to the local bookshop, where there are *n* books on sale from one of *m* genres.
In the bookshop, Jack deci... | ```python
from collections import Counter
t=1
n,m = map(int,input().split())
a = Counter(map(int,input().split()))
ans = n*(n-1)//2
for i in range(1,m+1):
ans -= a[i]*(a[i]-1)//2
print(ans)
``` | 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,510,420,039 | 2,147,483,647 | Python 3 | OK | TESTS | 52 | 124 | 0 | n = int(input())
li = [int(num) for num in input().split(' ')]
total, ans = 0, 0
for num in li: total += num
for num in li:
if (total-num) % 2 == 0: ans += 1
print(ans) | 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())
li = [int(num) for num in input().split(' ')]
total, ans = 0, 0
for num in li: total += num
for num in li:
if (total-num) % 2 == 0: ans += 1
print(ans)
``` | 3 | |
387 | A | George and Sleep | PROGRAMMING | 900 | [
"implementation"
] | null | null | George woke up and saw the current time *s* on the digital clock. Besides, George knows that he has slept for time *t*.
Help George! Write a program that will, given time *s* and *t*, determine the time *p* when George went to bed. Note that George could have gone to bed yesterday relatively to the current time (see ... | The first line contains current time *s* as a string in the format "hh:mm". The second line contains time *t* in the format "hh:mm" β the duration of George's sleep. It is guaranteed that the input contains the correct time in the 24-hour format, that is, 00<=β€<=*hh*<=β€<=23, 00<=β€<=*mm*<=β€<=59. | In the single line print time *p* β the time George went to bed in the format similar to the format of the time in the input. | [
"05:50\n05:44\n",
"00:00\n01:00\n",
"00:01\n00:00\n"
] | [
"00:06\n",
"23:00\n",
"00:01\n"
] | In the first sample George went to bed at "00:06". Note that you should print the time only in the format "00:06". That's why answers "0:06", "00:6" and others will be considered incorrect.
In the second sample, George went to bed yesterday.
In the third sample, George didn't do to bed at all. | 500 | [
{
"input": "05:50\n05:44",
"output": "00:06"
},
{
"input": "00:00\n01:00",
"output": "23:00"
},
{
"input": "00:01\n00:00",
"output": "00:01"
},
{
"input": "23:59\n23:59",
"output": "00:00"
},
{
"input": "23:44\n23:55",
"output": "23:49"
},
{
"input": "... | 1,536,154,776 | 2,147,483,647 | Python 3 | OK | TESTS | 47 | 124 | 307,200 | n = [int(k) for k in input().split(':')]
m = [int(k) for k in input().split(':')]
k = n[0]*60 + n[1]
j = m[0]*60 + m[1]
def h(x):
for s in range(2 - len(x)):
x = str(0) + x
return x
def f(x):
a = int(x/60)
b = x%60
c = h(str(a))+':'+h(str(b))
return c
if k >= j:
print(f... | Title: George and Sleep
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
George woke up and saw the current time *s* on the digital clock. Besides, George knows that he has slept for time *t*.
Help George! Write a program that will, given time *s* and *t*, determine the time *p* when Geor... | ```python
n = [int(k) for k in input().split(':')]
m = [int(k) for k in input().split(':')]
k = n[0]*60 + n[1]
j = m[0]*60 + m[1]
def h(x):
for s in range(2 - len(x)):
x = str(0) + x
return x
def f(x):
a = int(x/60)
b = x%60
c = h(str(a))+':'+h(str(b))
return c
if k >= j:
... | 3 | |
791 | A | Bear and Big Brother | PROGRAMMING | 800 | [
"implementation"
] | null | null | Bear Limak wants to become the largest of bears, or at least to become larger than his brother Bob.
Right now, Limak and Bob weigh *a* and *b* respectively. It's guaranteed that Limak's weight is smaller than or equal to his brother's weight.
Limak eats a lot and his weight is tripled after every year, while Bob's we... | The only line of the input contains two integers *a* and *b* (1<=β€<=*a*<=β€<=*b*<=β€<=10)Β β the weight of Limak and the weight of Bob respectively. | Print one integer, denoting the integer number of years after which Limak will become strictly larger than Bob. | [
"4 7\n",
"4 9\n",
"1 1\n"
] | [
"2\n",
"3\n",
"1\n"
] | In the first sample, Limak weighs 4 and Bob weighs 7 initially. After one year their weights are 4Β·3β=β12 and 7Β·2β=β14 respectively (one weight is tripled while the other one is doubled). Limak isn't larger than Bob yet. After the second year weights are 36 and 28, so the first weight is greater than the second one. Li... | 500 | [
{
"input": "4 7",
"output": "2"
},
{
"input": "4 9",
"output": "3"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "4 6",
"output": "2"
},
{
"input": "1 10",
"output": "6"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "1 2",
"output... | 1,698,325,222 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 62 | 62 | 0 | Limak, Bob = map(int, input().split())
years = 0
while Limak <= Bob:
years, Limak, Bob = years + 1, Limak * 3, Bob * 2
print(years) | Title: Bear and Big Brother
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bear Limak wants to become the largest of bears, or at least to become larger than his brother Bob.
Right now, Limak and Bob weigh *a* and *b* respectively. It's guaranteed that Limak's weight is smaller than or e... | ```python
Limak, Bob = map(int, input().split())
years = 0
while Limak <= Bob:
years, Limak, Bob = years + 1, Limak * 3, Bob * 2
print(years)
``` | 3 | |
1,004 | A | Sonya and Hotels | PROGRAMMING | 900 | [
"implementation"
] | null | null | Sonya decided that having her own hotel business is the best way of earning money because she can profit and rest wherever she wants.
The country where Sonya lives is an endless line. There is a city in each integer coordinate on this line. She has $n$ hotels, where the $i$-th hotel is located in the city with coordin... | The first line contains two integers $n$ and $d$ ($1\leq n\leq 100$, $1\leq d\leq 10^9$)Β β the number of Sonya's hotels and the needed minimum distance from a new hotel to all others.
The second line contains $n$ different integers in strictly increasing order $x_1, x_2, \ldots, x_n$ ($-10^9\leq x_i\leq 10^9$)Β β coord... | Print the number of cities where Sonya can build a new hotel so that the minimum distance from this hotel to all others is equal to $d$. | [
"4 3\n-3 2 9 16\n",
"5 2\n4 8 11 18 19\n"
] | [
"6\n",
"5\n"
] | In the first example, there are $6$ possible cities where Sonya can build a hotel. These cities have coordinates $-6$, $5$, $6$, $12$, $13$, and $19$.
In the second example, there are $5$ possible cities where Sonya can build a hotel. These cities have coordinates $2$, $6$, $13$, $16$, and $21$. | 500 | [
{
"input": "4 3\n-3 2 9 16",
"output": "6"
},
{
"input": "5 2\n4 8 11 18 19",
"output": "5"
},
{
"input": "10 10\n-67 -59 -49 -38 -8 20 41 59 74 83",
"output": "8"
},
{
"input": "10 10\n0 20 48 58 81 95 111 137 147 159",
"output": "9"
},
{
"input": "100 1\n0 1 2 3... | 1,530,809,379 | 879 | Python 3 | OK | TESTS | 45 | 124 | 0 | n, d = map(int, input().split())
arr = list(map(int, input().split()))
if n == 1:
ans = 2
else:
s = set()
s.add(arr[0] - d)
s.add(arr[-1] + d)
for i in range(n):
if i == 0:
if arr[i + 1] - arr[i] - d >= d:
s.add(arr[i] + d)
elif i == n - 1:
if ... | Title: Sonya and Hotels
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Sonya decided that having her own hotel business is the best way of earning money because she can profit and rest wherever she wants.
The country where Sonya lives is an endless line. There is a city in each integer c... | ```python
n, d = map(int, input().split())
arr = list(map(int, input().split()))
if n == 1:
ans = 2
else:
s = set()
s.add(arr[0] - d)
s.add(arr[-1] + d)
for i in range(n):
if i == 0:
if arr[i + 1] - arr[i] - d >= d:
s.add(arr[i] + d)
elif i == n - 1:
... | 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,529,943,279 | 2,147,483,647 | Python 3 | OK | TESTS | 102 | 93 | 0 | from sys import stdin
a = stdin.readline()
b = stdin.readline()
r =''
for i in range(len(a)-1):
r+=str(int(bool(int(a[i])) != bool(int(b[i]))))
print(r) | Title: Ultra-Fast Mathematician
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 10... | ```python
from sys import stdin
a = stdin.readline()
b = stdin.readline()
r =''
for i in range(len(a)-1):
r+=str(int(bool(int(a[i])) != bool(int(b[i]))))
print(r)
``` | 3.97675 |
727 | A | Transformation: from A to B | PROGRAMMING | 1,000 | [
"brute force",
"dfs and similar",
"math"
] | null | null | Vasily has a number *a*, which he wants to turn into a number *b*. For this purpose, he can do two types of operations:
- multiply the current number by 2 (that is, replace the number *x* by 2Β·*x*); - append the digit 1 to the right of current number (that is, replace the number *x* by 10Β·*x*<=+<=1).
You need to he... | The first line contains two positive integers *a* and *b* (1<=β€<=*a*<=<<=*b*<=β€<=109)Β β the number which Vasily has and the number he wants to have. | If there is no way to get *b* from *a*, print "NO" (without quotes).
Otherwise print three lines. On the first line print "YES" (without quotes). The second line should contain single integer *k*Β β the length of the transformation sequence. On the third line print the sequence of transformations *x*1,<=*x*2,<=...,<=*x... | [
"2 162\n",
"4 42\n",
"100 40021\n"
] | [
"YES\n5\n2 4 8 81 162 \n",
"NO\n",
"YES\n5\n100 200 2001 4002 40021 \n"
] | none | 1,000 | [
{
"input": "2 162",
"output": "YES\n5\n2 4 8 81 162 "
},
{
"input": "4 42",
"output": "NO"
},
{
"input": "100 40021",
"output": "YES\n5\n100 200 2001 4002 40021 "
},
{
"input": "1 111111111",
"output": "YES\n9\n1 11 111 1111 11111 111111 1111111 11111111 111111111 "
},
... | 1,582,105,869 | 2,147,483,647 | PyPy 3 | OK | TESTS | 33 | 155 | 0 | a,b=input().split()
a=int(a)
b=int(b)
f=0
l=[]
while(b>a):
if (b%2==1):
if (b-1)%10==0:
l.append(b)
b=(b-1)//10
else:
print("NO")
f=1
break
else:
l.append(b)
b=b//2
if (f==0):
if a==b:
prin... | Title: Transformation: from A to B
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasily has a number *a*, which he wants to turn into a number *b*. For this purpose, he can do two types of operations:
- multiply the current number by 2 (that is, replace the number *x* by 2Β·*x*); - app... | ```python
a,b=input().split()
a=int(a)
b=int(b)
f=0
l=[]
while(b>a):
if (b%2==1):
if (b-1)%10==0:
l.append(b)
b=(b-1)//10
else:
print("NO")
f=1
break
else:
l.append(b)
b=b//2
if (f==0):
if a==b:
... | 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,636,641,226 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 32 | 124 | 28,467,200 | int(input())
b = list(map(int, input().split()))
kch = 0
knch = 0
for i in b[0], b[1], b[2]:
if i % 2 == 0:
kch += 1
else:
knch += 1
if knch > kch:
for i in range(len(b)):
if b[i] % 2 == 0:
print(i + 1)
exit(0)
else:
for i in range(len(b)):
if b[i] % 2 != 0:
print(i + 1)
exit(0... | 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
int(input())
b = list(map(int, input().split()))
kch = 0
knch = 0
for i in b[0], b[1], b[2]:
if i % 2 == 0:
kch += 1
else:
knch += 1
if knch > kch:
for i in range(len(b)):
if b[i] % 2 == 0:
print(i + 1)
exit(0)
else:
for i in range(len(b)):
if b[i] % 2 != 0:
print(i + 1)
... | 3.915976 |
732 | A | Buy a Shovel | PROGRAMMING | 800 | [
"brute force",
"constructive algorithms",
"implementation",
"math"
] | null | null | Polycarp urgently needs a shovel! He comes to the shop and chooses an appropriate one. The shovel that Policarp chooses is sold for *k* burles. Assume that there is an unlimited number of such shovels in the shop.
In his pocket Polycarp has an unlimited number of "10-burle coins" and exactly one coin of *r* burles (1<... | The single line of input contains two integers *k* and *r* (1<=β€<=*k*<=β€<=1000, 1<=β€<=*r*<=β€<=9)Β β the price of one shovel and the denomination of the coin in Polycarp's pocket that is different from "10-burle coins".
Remember that he has an unlimited number of coins in the denomination of 10, that is, Polycarp has e... | Print the required minimum number of shovels Polycarp has to buy so that he can pay for them without any change. | [
"117 3\n",
"237 7\n",
"15 2\n"
] | [
"9\n",
"1\n",
"2\n"
] | In the first example Polycarp can buy 9 shovels and pay 9Β·117β=β1053 burles. Indeed, he can pay this sum by using 10-burle coins and one 3-burle coin. He can't buy fewer shovels without any change.
In the second example it is enough for Polycarp to buy one shovel.
In the third example Polycarp should buy two shovels ... | 500 | [
{
"input": "117 3",
"output": "9"
},
{
"input": "237 7",
"output": "1"
},
{
"input": "15 2",
"output": "2"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "1 9",
"output": "9"
},
{
"input": "1000 3",
"output": "1"
},
{
"input": "1000 1",
... | 1,687,468,311 | 2,147,483,647 | Python 3 | OK | TESTS | 54 | 46 | 0 | k,r=map(int,input().split())
s=1
while (k*s)%10!=r and (k*s)%10!=0:
s+=1
print(s) | Title: Buy a Shovel
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp urgently needs a shovel! He comes to the shop and chooses an appropriate one. The shovel that Policarp chooses is sold for *k* burles. Assume that there is an unlimited number of such shovels in the shop.
In his ... | ```python
k,r=map(int,input().split())
s=1
while (k*s)%10!=r and (k*s)%10!=0:
s+=1
print(s)
``` | 3 | |
432 | A | Choosing Teams | PROGRAMMING | 800 | [
"greedy",
"implementation",
"sortings"
] | null | null | The Saratov State University Olympiad Programmers Training Center (SSU OPTC) has *n* students. For each student you know the number of times he/she has participated in the ACM ICPC world programming championship. According to the ACM ICPC rules, each person can participate in the world championship at most 5 times.
Th... | The first line contains two integers, *n* and *k* (1<=β€<=*n*<=β€<=2000;Β 1<=β€<=*k*<=β€<=5). The next line contains *n* integers: *y*1,<=*y*2,<=...,<=*y**n* (0<=β€<=*y**i*<=β€<=5), where *y**i* shows the number of times the *i*-th person participated in the ACM ICPC world championship. | Print a single number β the answer to the problem. | [
"5 2\n0 4 5 1 0\n",
"6 4\n0 1 2 3 4 5\n",
"6 5\n0 0 0 0 0 0\n"
] | [
"1\n",
"0\n",
"2\n"
] | In the first sample only one team could be made: the first, the fourth and the fifth participants.
In the second sample no teams could be created.
In the third sample two teams could be created. Any partition into two teams fits. | 500 | [
{
"input": "5 2\n0 4 5 1 0",
"output": "1"
},
{
"input": "6 4\n0 1 2 3 4 5",
"output": "0"
},
{
"input": "6 5\n0 0 0 0 0 0",
"output": "2"
},
{
"input": "3 4\n0 1 0",
"output": "1"
},
{
"input": "3 4\n0 2 0",
"output": "0"
},
{
"input": "6 5\n0 0 0 0 0... | 1,674,707,337 | 2,147,483,647 | PyPy 3 | OK | TESTS | 35 | 93 | 1,638,400 | from sys import stdin
first_line = [int(x) for x in stdin.readline().split()]
n= first_line[0]
k = first_line[1]
listy = [int(x) for x in stdin.readline().split()]
eligible = sum(1 for i in listy if i<6-k)
answer = eligible//3
print(answer)
| Title: Choosing Teams
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Saratov State University Olympiad Programmers Training Center (SSU OPTC) has *n* students. For each student you know the number of times he/she has participated in the ACM ICPC world programming championship. Accordi... | ```python
from sys import stdin
first_line = [int(x) for x in stdin.readline().split()]
n= first_line[0]
k = first_line[1]
listy = [int(x) for x in stdin.readline().split()]
eligible = sum(1 for i in listy if i<6-k)
answer = eligible//3
print(answer)
``` | 3 | |
990 | A | Commentary Boxes | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | null | null | Berland Football Cup starts really soon! Commentators from all over the world come to the event.
Organizers have already built $n$ commentary boxes. $m$ regional delegations will come to the Cup. Every delegation should get the same number of the commentary boxes. If any box is left unoccupied then the delegations wil... | The only line contains four integer numbers $n$, $m$, $a$ and $b$ ($1 \le n, m \le 10^{12}$, $1 \le a, b \le 100$), where $n$ is the initial number of the commentary boxes, $m$ is the number of delegations to come, $a$ is the fee to build a box and $b$ is the fee to demolish a box. | Output the minimal amount of burles organizers should pay to satisfy all the delegations (i.e. to make the number of the boxes be divisible by $m$). It is allowed that the final number of the boxes is equal to $0$. | [
"9 7 3 8\n",
"2 7 3 7\n",
"30 6 17 19\n"
] | [
"15\n",
"14\n",
"0\n"
] | In the first example organizers can build $5$ boxes to make the total of $14$ paying $3$ burles for the each of them.
In the second example organizers can demolish $2$ boxes to make the total of $0$ paying $7$ burles for the each of them.
In the third example organizers are already able to distribute all the boxes eq... | 0 | [
{
"input": "9 7 3 8",
"output": "15"
},
{
"input": "2 7 3 7",
"output": "14"
},
{
"input": "30 6 17 19",
"output": "0"
},
{
"input": "500000000001 1000000000000 100 100",
"output": "49999999999900"
},
{
"input": "1000000000000 750000000001 10 100",
"output": "... | 1,528,638,659 | 2,147,483,647 | Python 3 | OK | TESTS | 109 | 93 | 0 | n, m, a, b = map(int, input().split())
r = n % m
print(min(r * b, (m - r) * a))
| Title: Commentary Boxes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Berland Football Cup starts really soon! Commentators from all over the world come to the event.
Organizers have already built $n$ commentary boxes. $m$ regional delegations will come to the Cup. Every delegation shou... | ```python
n, m, a, b = map(int, input().split())
r = n % m
print(min(r * b, (m - r) * a))
``` | 3 | |
525 | A | Vitaliy and Pie | PROGRAMMING | 1,100 | [
"greedy",
"hashing",
"strings"
] | null | null | After a hard day Vitaly got very hungry and he wants to eat his favorite potato pie. But it's not that simple. Vitaly is in the first room of the house with *n* room located in a line and numbered starting from one from left to right. You can go from the first room to the second room, from the second room to the third ... | The first line of the input contains a positive integer *n* (2<=β€<=*n*<=β€<=105)Β βΒ the number of rooms in the house.
The second line of the input contains string *s* of length 2Β·*n*<=-<=2. Let's number the elements of the string from left to right, starting from one.
The odd positions in the given string *s* contain ... | Print the only integer β the minimum number of keys that Vitaly needs to buy to surely get from room one to room *n*. | [
"3\naAbB\n",
"4\naBaCaB\n",
"5\nxYyXzZaZ\n"
] | [
"0\n",
"3\n",
"2\n"
] | none | 250 | [
{
"input": "3\naAbB",
"output": "0"
},
{
"input": "4\naBaCaB",
"output": "3"
},
{
"input": "5\nxYyXzZaZ",
"output": "2"
},
{
"input": "26\naAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyY",
"output": "0"
},
{
"input": "26\nzAyBxCwDvEuFtGsHrIqJpKoLnMmNlOkPjQiRhSg... | 1,430,891,382 | 2,147,483,647 | Python 3 | OK | TESTS | 46 | 202 | 409,600 | # print ("Enter number of rooms")
n = int(input())
# print ("Enter the configuration")
a = input()
dic = {}
tobuy = 0
for i in range((n-1)*2):
if (i%2 == 0): # A key (small letter)
ch = a[i]
dic[ch] = dic.get(ch, 0)+1 # Clever way to either increment or add
else: # A door--either ope... | Title: Vitaliy and Pie
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
After a hard day Vitaly got very hungry and he wants to eat his favorite potato pie. But it's not that simple. Vitaly is in the first room of the house with *n* room located in a line and numbered starting from one from... | ```python
# print ("Enter number of rooms")
n = int(input())
# print ("Enter the configuration")
a = input()
dic = {}
tobuy = 0
for i in range((n-1)*2):
if (i%2 == 0): # A key (small letter)
ch = a[i]
dic[ch] = dic.get(ch, 0)+1 # Clever way to either increment or add
else: # A door--... | 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,554,310,755 | 2,147,483,647 | Python 3 | OK | TESTS | 58 | 109 | 0 | n,m,k=list(map(int,input().split(" ")))
a=list(map(int,input().split(" ")))
# print(n,k,m,a)
q=1000000000000
for i in range(1,n+1):
if(a[i-1]<=k and a[i-1]!=0):
distance=abs(m-i)
q=min(distance,q)
print(q*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=list(map(int,input().split(" ")))
a=list(map(int,input().split(" ")))
# print(n,k,m,a)
q=1000000000000
for i in range(1,n+1):
if(a[i-1]<=k and a[i-1]!=0):
distance=abs(m-i)
q=min(distance,q)
print(q*10)
``` | 3 | |
628 | A | Tennis Tournament | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | null | null | A tennis tournament with *n* participants is running. The participants are playing by an olympic system, so the winners move on and the losers drop out.
The tournament takes place in the following way (below, *m* is the number of the participants of the current round):
- let *k* be the maximal power of the number 2 ... | The only line contains three integers *n*,<=*b*,<=*p* (1<=β€<=*n*,<=*b*,<=*p*<=β€<=500) β the number of participants and the parameters described in the problem statement. | Print two integers *x* and *y* β the number of bottles and towels need for the tournament. | [
"5 2 3\n",
"8 2 4\n"
] | [
"20 15\n",
"35 32\n"
] | In the first example will be three rounds:
1. in the first round will be two matches and for each match 5 bottles of water are needed (two for each of the participants and one for the judge), 1. in the second round will be only one match, so we need another 5 bottles of water, 1. in the third round will also be onl... | 0 | [
{
"input": "5 2 3",
"output": "20 15"
},
{
"input": "8 2 4",
"output": "35 32"
},
{
"input": "10 1 500",
"output": "27 5000"
},
{
"input": "20 500 1",
"output": "19019 20"
},
{
"input": "100 123 99",
"output": "24453 9900"
},
{
"input": "500 1 1",
... | 1,455,894,425 | 425 | Python 3 | OK | TESTS | 38 | 62 | 0 | n, b, p = [int(x) for x in input().split()]
b1, p1 = 0, n*p
while n > 1:
n1 = 2 << (n.bit_length()-2)
b1 += (2*b + 1) * n1 // 2
n -= n1//2
print(b1, p1)
| Title: Tennis Tournament
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A tennis tournament with *n* participants is running. The participants are playing by an olympic system, so the winners move on and the losers drop out.
The tournament takes place in the following way (below, *m* is ... | ```python
n, b, p = [int(x) for x in input().split()]
b1, p1 = 0, n*p
while n > 1:
n1 = 2 << (n.bit_length()-2)
b1 += (2*b + 1) * n1 // 2
n -= n1//2
print(b1, p1)
``` | 3 | |
244 | A | Dividing Orange | PROGRAMMING | 900 | [
"implementation"
] | null | null | One day Ms Swan bought an orange in a shop. The orange consisted of *n*Β·*k* segments, numbered with integers from 1 to *n*Β·*k*.
There were *k* children waiting for Ms Swan at home. The children have recently learned about the orange and they decided to divide it between them. For that each child took a piece of paper... | The first line contains two integers *n*, *k* (1<=β€<=*n*,<=*k*<=β€<=30). The second line contains *k* space-separated integers *a*1,<=*a*2,<=...,<=*a**k* (1<=β€<=*a**i*<=β€<=*n*Β·*k*), where *a**i* is the number of the orange segment that the *i*-th child would like to get.
It is guaranteed that all numbers *a**i* are dis... | Print exactly *n*Β·*k* distinct integers. The first *n* integers represent the indexes of the segments the first child will get, the second *n* integers represent the indexes of the segments the second child will get, and so on. Separate the printed numbers with whitespaces.
You can print a child's segment indexes in a... | [
"2 2\n4 1\n",
"3 1\n2\n"
] | [
"2 4 \n1 3 \n",
"3 2 1 \n"
] | none | 500 | [
{
"input": "2 2\n4 1",
"output": "2 4 \n1 3 "
},
{
"input": "3 1\n2",
"output": "3 2 1 "
},
{
"input": "5 5\n25 24 23 22 21",
"output": "2 3 1 25 4 \n7 6 8 5 24 \n10 12 9 23 11 \n13 15 14 16 22 \n19 21 20 17 18 "
},
{
"input": "1 30\n8 22 13 25 10 30 12 27 6 4 7 2 20 16 26 14... | 1,608,041,137 | 2,147,483,647 | PyPy 3 | OK | TESTS | 29 | 372 | 1,740,800 | inp=list(map(int,input().split()))
n,k=inp
arr=[]
for i in range(k+1):
arr.append([])
from collections import Counter
a=list(map(int,input().split()))
for i in range(len(a)):
arr[i+1].append(a[i])
c=Counter(a)
j=1
for i in range(1,n*k+1):
if c[i]!=0:
continue
if len(arr[j])==n:
... | Title: Dividing Orange
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day Ms Swan bought an orange in a shop. The orange consisted of *n*Β·*k* segments, numbered with integers from 1 to *n*Β·*k*.
There were *k* children waiting for Ms Swan at home. The children have recently learned a... | ```python
inp=list(map(int,input().split()))
n,k=inp
arr=[]
for i in range(k+1):
arr.append([])
from collections import Counter
a=list(map(int,input().split()))
for i in range(len(a)):
arr[i+1].append(a[i])
c=Counter(a)
j=1
for i in range(1,n*k+1):
if c[i]!=0:
continue
if len(arr[j... | 3 | |
355 | B | Vasya and Public Transport | PROGRAMMING | 1,100 | [
"greedy",
"implementation"
] | null | null | Vasya often uses public transport. The transport in the city is of two types: trolleys and buses. The city has *n* buses and *m* trolleys, the buses are numbered by integers from 1 to *n*, the trolleys are numbered by integers from 1 to *m*.
Public transport is not free. There are 4 types of tickets:
1. A ticket fo... | The first line contains four integers *c*1,<=*c*2,<=*c*3,<=*c*4 (1<=β€<=*c*1,<=*c*2,<=*c*3,<=*c*4<=β€<=1000) β the costs of the tickets.
The second line contains two integers *n* and *m* (1<=β€<=*n*,<=*m*<=β€<=1000) β the number of buses and trolleys Vasya is going to use.
The third line contains *n* integers *a**i* (0<=... | Print a single number β the minimum sum of burles Vasya will have to spend on the tickets. | [
"1 3 7 19\n2 3\n2 5\n4 4 4\n",
"4 3 2 1\n1 3\n798\n1 2 3\n",
"100 100 8 100\n3 5\n7 94 12\n100 1 47 0 42\n"
] | [
"12\n",
"1\n",
"16\n"
] | In the first sample the profitable strategy is to buy two tickets of the first type (for the first bus), one ticket of the second type (for the second bus) and one ticket of the third type (for all trolleys). It totals to (2Β·1)β+β3β+β7β=β12 burles.
In the second sample the profitable strategy is to buy one ticket of t... | 1,000 | [
{
"input": "1 3 7 19\n2 3\n2 5\n4 4 4",
"output": "12"
},
{
"input": "4 3 2 1\n1 3\n798\n1 2 3",
"output": "1"
},
{
"input": "100 100 8 100\n3 5\n7 94 12\n100 1 47 0 42",
"output": "16"
},
{
"input": "3 103 945 1000\n7 9\n34 35 34 35 34 35 34\n0 0 0 0 0 0 0 0 0",
"output"... | 1,381,802,282 | 2,147,483,647 | Python 3 | OK | TESTS | 27 | 46 | 307,200 | import sys
# input
line_id = 0
for line in sys.stdin:
line_id = line_id + 1
line_data = line.split()
if line_id <= 2:
if line_id == 1:
c1 = int(line_data[0])
c2 = int(line_data[1])
c3 = int(line_data[2])
c4 = int(line_data[3])
e... | Title: Vasya and Public Transport
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya often uses public transport. The transport in the city is of two types: trolleys and buses. The city has *n* buses and *m* trolleys, the buses are numbered by integers from 1 to *n*, the trolleys are nu... | ```python
import sys
# input
line_id = 0
for line in sys.stdin:
line_id = line_id + 1
line_data = line.split()
if line_id <= 2:
if line_id == 1:
c1 = int(line_data[0])
c2 = int(line_data[1])
c3 = int(line_data[2])
c4 = int(line_data[3])
... | 3 | |
255 | A | Greg's Workout | PROGRAMMING | 800 | [
"implementation"
] | null | null | Greg is a beginner bodybuilder. Today the gym coach gave him the training plan. All it had was *n* integers *a*1,<=*a*2,<=...,<=*a**n*. These numbers mean that Greg needs to do exactly *n* exercises today. Besides, Greg should repeat the *i*-th in order exercise *a**i* times.
Greg now only does three types of exercise... | The first line contains integer *n* (1<=β€<=*n*<=β€<=20). The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=β€<=*a**i*<=β€<=25) β the number of times Greg repeats the exercises. | Print word "chest" (without the quotes), if the chest gets the most exercise, "biceps" (without the quotes), if the biceps gets the most exercise and print "back" (without the quotes) if the back gets the most exercise.
It is guaranteed that the input is such that the answer to the problem is unambiguous. | [
"2\n2 8\n",
"3\n5 1 10\n",
"7\n3 3 2 7 9 6 8\n"
] | [
"biceps\n",
"back\n",
"chest\n"
] | In the first sample Greg does 2 chest, 8 biceps and zero back exercises, so the biceps gets the most exercises.
In the second sample Greg does 5 chest, 1 biceps and 10 back exercises, so the back gets the most exercises.
In the third sample Greg does 18 chest, 12 biceps and 8 back exercises, so the chest gets the mos... | 500 | [
{
"input": "2\n2 8",
"output": "biceps"
},
{
"input": "3\n5 1 10",
"output": "back"
},
{
"input": "7\n3 3 2 7 9 6 8",
"output": "chest"
},
{
"input": "4\n5 6 6 2",
"output": "chest"
},
{
"input": "5\n8 2 2 6 3",
"output": "chest"
},
{
"input": "6\n8 7 ... | 1,620,805,993 | 2,147,483,647 | Python 3 | OK | TESTS | 61 | 124 | 6,963,200 | def f(n,l):
x=["chest","biceps","back"]
if n==1:
return x[n-1]
if n==2:
return x[l.index(max(l))]
l2=[0,0,0]
for i in range(0,n,3):
l2[0]+=l[i]
for i in range(0,n-1,3):
l2[1]+=l[i+1]
for i in range(0,n-2,3):
l2[2]+=l[i+2]
return x[l2.index(max(l2))]
n=int(input())
l=list(map(int,inp... | Title: Greg's Workout
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Greg is a beginner bodybuilder. Today the gym coach gave him the training plan. All it had was *n* integers *a*1,<=*a*2,<=...,<=*a**n*. These numbers mean that Greg needs to do exactly *n* exercises today. Besides, Greg ... | ```python
def f(n,l):
x=["chest","biceps","back"]
if n==1:
return x[n-1]
if n==2:
return x[l.index(max(l))]
l2=[0,0,0]
for i in range(0,n,3):
l2[0]+=l[i]
for i in range(0,n-1,3):
l2[1]+=l[i+1]
for i in range(0,n-2,3):
l2[2]+=l[i+2]
return x[l2.index(max(l2))]
n=int(input())
l=list(m... | 3 | |
46 | A | Ball Game | PROGRAMMING | 800 | [
"brute force",
"implementation"
] | A. Ball Game | 2 | 256 | A kindergarten teacher Natalia Pavlovna has invented a new ball game. This game not only develops the children's physique, but also teaches them how to count.
The game goes as follows. Kids stand in circle. Let's agree to think of the children as numbered with numbers from 1 to *n* clockwise and the child number 1 is... | The first line contains integer *n* (2<=β€<=*n*<=β€<=100) which indicates the number of kids in the circle. | In the single line print *n*<=-<=1 numbers which are the numbers of children who will get the ball after each throw. Separate the numbers by spaces. | [
"10\n",
"3\n"
] | [
"2 4 7 1 6 2 9 7 6\n",
"2 1\n"
] | none | 0 | [
{
"input": "10",
"output": "2 4 7 1 6 2 9 7 6"
},
{
"input": "3",
"output": "2 1"
},
{
"input": "4",
"output": "2 4 3"
},
{
"input": "5",
"output": "2 4 2 1"
},
{
"input": "6",
"output": "2 4 1 5 4"
},
{
"input": "7",
"output": "2 4 7 4 2 1"
},
... | 1,629,203,815 | 2,147,483,647 | Python 3 | OK | TESTS | 33 | 124 | 6,758,400 | n = int(input())
a = [i for i in range(1,n+1)]*n
b = []
for i in range(n):
b.append(a[(i*(i+1)//2)])
print(*b[1:])
| Title: Ball Game
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A kindergarten teacher Natalia Pavlovna has invented a new ball game. This game not only develops the children's physique, but also teaches them how to count.
The game goes as follows. Kids stand in circle. Let's agree to think... | ```python
n = int(input())
a = [i for i in range(1,n+1)]*n
b = []
for i in range(n):
b.append(a[(i*(i+1)//2)])
print(*b[1:])
``` | 3.956411 |
439 | A | Devu, the Singer and Churu, the Joker | PROGRAMMING | 900 | [
"greedy",
"implementation"
] | null | null | Devu is a renowned classical singer. He is invited to many big functions/festivals. Recently he was invited to "All World Classical Singing Festival". Other than Devu, comedian Churu was also invited.
Devu has provided organizers a list of the songs and required time for singing them. He will sing *n* songs, *i**th* s... | The first line contains two space separated integers *n*, *d* (1<=β€<=*n*<=β€<=100;Β 1<=β€<=*d*<=β€<=10000). The second line contains *n* space-separated integers: *t*1,<=*t*2,<=...,<=*t**n* (1<=β€<=*t**i*<=β€<=100). | If there is no way to conduct all the songs of Devu, output -1. Otherwise output the maximum number of jokes that Churu can crack in the grand event. | [
"3 30\n2 2 1\n",
"3 20\n2 1 1\n"
] | [
"5\n",
"-1\n"
] | Consider the first example. The duration of the event is 30 minutes. There could be maximum 5 jokes in the following way:
- First Churu cracks a joke in 5 minutes. - Then Devu performs the first song for 2 minutes. - Then Churu cracks 2 jokes in 10 minutes. - Now Devu performs second song for 2 minutes. - Then Ch... | 500 | [
{
"input": "3 30\n2 2 1",
"output": "5"
},
{
"input": "3 20\n2 1 1",
"output": "-1"
},
{
"input": "50 10000\n5 4 10 9 9 6 7 7 7 3 3 7 7 4 7 4 10 10 1 7 10 3 1 4 5 7 2 10 10 10 2 3 4 7 6 1 8 4 7 3 8 8 4 10 1 1 9 2 6 1",
"output": "1943"
},
{
"input": "50 10000\n4 7 15 9 11 12 ... | 1,616,138,372 | 2,147,483,647 | Python 3 | OK | TESTS | 26 | 77 | 0 | n,m=map(int,input().split())
x=list(map(int,input().split()))
if sum(x)+(n-1)*10>m:
print(-1)
else:
m=(m-sum(x))//5
print(m) | Title: Devu, the Singer and Churu, the Joker
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Devu is a renowned classical singer. He is invited to many big functions/festivals. Recently he was invited to "All World Classical Singing Festival". Other than Devu, comedian Churu was also invit... | ```python
n,m=map(int,input().split())
x=list(map(int,input().split()))
if sum(x)+(n-1)*10>m:
print(-1)
else:
m=(m-sum(x))//5
print(m)
``` | 3 | |
839 | C | Journey | PROGRAMMING | 1,500 | [
"dfs and similar",
"dp",
"graphs",
"probabilities",
"trees"
] | null | null | There are *n* cities and *n*<=-<=1 roads in the Seven Kingdoms, each road connects two cities and we can reach any city from any other by the roads.
Theon and Yara Greyjoy are on a horse in the first city, they are starting traveling through the roads. But the weather is foggy, so they canβt see where the horse brings... | The first line contains a single integer *n* (1<=β€<=*n*<=β€<=100000)Β β number of cities.
Then *n*<=-<=1 lines follow. The *i*-th line of these lines contains two integers *u**i* and *v**i* (1<=β€<=*u**i*,<=*v**i*<=β€<=*n*, *u**i*<=β <=*v**i*)Β β the cities connected by the *i*-th road.
It is guaranteed that one can reach ... | Print a numberΒ β the expected length of their journey. The journey starts in the city 1.
Your answer will be considered correct if its absolute or relative error does not exceed 10<=-<=6.
Namely: let's assume that your answer is *a*, and the answer of the jury is *b*. The checker program will consider your answer cor... | [
"4\n1 2\n1 3\n2 4\n",
"5\n1 2\n1 3\n3 4\n2 5\n"
] | [
"1.500000000000000\n",
"2.000000000000000\n"
] | In the first sample, their journey may end in cities 3 or 4 with equal probability. The distance to city 3 is 1 and to city 4 is 2, so the expected length is 1.5.
In the second sample, their journey may end in city 4 or 5. The distance to the both cities is 2, so the expected length is 2. | 1,500 | [
{
"input": "4\n1 2\n1 3\n2 4",
"output": "1.500000000000000"
},
{
"input": "5\n1 2\n1 3\n3 4\n2 5",
"output": "2.000000000000000"
},
{
"input": "70\n1 25\n57 1\n18 1\n65 1\n38 1\n1 41\n1 5\n1 69\n1 3\n31 1\n1 8\n1 9\n53 1\n70 1\n45 1\n1 24\n1 42\n1 30\n1 12\n1 37\n64 1\n1 28\n1 58\n1 22\... | 1,587,408,101 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 576 | 24,678,400 | #https://codeforces.com/problemset/problem/839/C
from collections import defaultdict
class Graph:
def __init__(self):
self.dict = defaultdict(set)
def main():
n_cities = int(input())
g = Graph()
s = []
visited = set()
for i in range(0,n_cities-1):
u, v = (int(j) for j in input().split())
g.d... | Title: Journey
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* cities and *n*<=-<=1 roads in the Seven Kingdoms, each road connects two cities and we can reach any city from any other by the roads.
Theon and Yara Greyjoy are on a horse in the first city, they are starting tr... | ```python
#https://codeforces.com/problemset/problem/839/C
from collections import defaultdict
class Graph:
def __init__(self):
self.dict = defaultdict(set)
def main():
n_cities = int(input())
g = Graph()
s = []
visited = set()
for i in range(0,n_cities-1):
u, v = (int(j) for j in input().split... | 3 | |
385 | A | Bear and Raspberry | PROGRAMMING | 1,000 | [
"brute force",
"greedy",
"implementation"
] | null | null | The bear decided to store some raspberry for the winter. He cunningly found out the price for a barrel of honey in kilos of raspberry for each of the following *n* days. According to the bear's data, on the *i*-th (1<=β€<=*i*<=β€<=*n*) day, the price for one barrel of honey is going to is *x**i* kilos of raspberry.
Unfo... | The first line contains two space-separated integers, *n* and *c* (2<=β€<=*n*<=β€<=100,<=0<=β€<=*c*<=β€<=100), β the number of days and the number of kilos of raspberry that the bear should give for borrowing the barrel.
The second line contains *n* space-separated integers *x*1,<=*x*2,<=...,<=*x**n* (0<=β€<=*x**i*<=β€<=100... | Print a single integer β the answer to the problem. | [
"5 1\n5 10 7 3 20\n",
"6 2\n100 1 10 40 10 40\n",
"3 0\n1 2 3\n"
] | [
"3\n",
"97\n",
"0\n"
] | In the first sample the bear will lend a honey barrel at day 3 and then sell it for 7. Then the bear will buy a barrel for 3 and return it to the friend. So, the profit is (7 - 3 - 1) = 3.
In the second sample bear will lend a honey barrel at day 1 and then sell it for 100. Then the bear buy the barrel for 1 at the da... | 500 | [
{
"input": "5 1\n5 10 7 3 20",
"output": "3"
},
{
"input": "6 2\n100 1 10 40 10 40",
"output": "97"
},
{
"input": "3 0\n1 2 3",
"output": "0"
},
{
"input": "2 0\n2 1",
"output": "1"
},
{
"input": "10 5\n10 1 11 2 12 3 13 4 14 5",
"output": "4"
},
{
"in... | 1,390,591,882 | 2,147,483,647 | Python 3 | OK | TESTS | 32 | 140 | 409,600 | n, c = map(int, input().split())
pr = list(map(int, input().split()))
maxim = 0
for cont in range(0,n-1,1):
m = pr[cont]-pr[cont+1]-c
if m > maxim:
maxim = m
print(maxim) | Title: Bear and Raspberry
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The bear decided to store some raspberry for the winter. He cunningly found out the price for a barrel of honey in kilos of raspberry for each of the following *n* days. According to the bear's data, on the *i*-th (1... | ```python
n, c = map(int, input().split())
pr = list(map(int, input().split()))
maxim = 0
for cont in range(0,n-1,1):
m = pr[cont]-pr[cont+1]-c
if m > maxim:
maxim = m
print(maxim)
``` | 3 | |
798 | A | Mike and palindrome | PROGRAMMING | 1,000 | [
"brute force",
"constructive algorithms",
"strings"
] | null | null | Mike has a string *s* consisting of only lowercase English letters. He wants to change exactly one character from the string so that the resulting one is a palindrome.
A palindrome is a string that reads the same backward as forward, for example strings "z", "aaa", "aba", "abccba" are palindromes, but strings "codefo... | The first and single line contains string *s* (1<=β€<=|*s*|<=β€<=15). | Print "YES" (without quotes) if Mike can change exactly one character so that the resulting string is palindrome or "NO" (without quotes) otherwise. | [
"abccaa\n",
"abbcca\n",
"abcda\n"
] | [
"YES\n",
"NO\n",
"YES\n"
] | none | 500 | [
{
"input": "abccaa",
"output": "YES"
},
{
"input": "abbcca",
"output": "NO"
},
{
"input": "abcda",
"output": "YES"
},
{
"input": "kyw",
"output": "YES"
},
{
"input": "fccf",
"output": "NO"
},
{
"input": "mnlm",
"output": "YES"
},
{
"input":... | 1,636,989,548 | 2,147,483,647 | Python 3 | OK | TESTS | 99 | 61 | 0 | t=input()
count=0
n=len(t)
if t[::1]==t[::-1]:
if n%2==0:
print("NO")
else:
print("YES")
else:
for i in range(0,n//2):
if t[i]!=t[n-1-i]:
count=count+1
else:
continue
if count==1:
print("YES")
else:
print("NO") | Title: Mike and palindrome
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mike has a string *s* consisting of only lowercase English letters. He wants to change exactly one character from the string so that the resulting one is a palindrome.
A palindrome is a string that reads the same ... | ```python
t=input()
count=0
n=len(t)
if t[::1]==t[::-1]:
if n%2==0:
print("NO")
else:
print("YES")
else:
for i in range(0,n//2):
if t[i]!=t[n-1-i]:
count=count+1
else:
continue
if count==1:
print("YES")
else:
pr... | 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,571,066,574 | 2,147,483,647 | Python 3 | OK | TESTS | 20 | 124 | 307,200 | n= int(input())
k= list(map(int, input().split()))
mat=[]
for i in range(n):
l=list(map(int, input().split()))
mat.append(l)
res=[]
temp=0
for i in range(n):
t= k[i]
demo=0
for j in range(t):
demo= demo+mat[i][j]
demo= demo*5
demo+= t*15
res.append(demo)
pri... | 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())
k= list(map(int, input().split()))
mat=[]
for i in range(n):
l=list(map(int, input().split()))
mat.append(l)
res=[]
temp=0
for i in range(n):
t= k[i]
demo=0
for j in range(t):
demo= demo+mat[i][j]
demo= demo*5
demo+= t*15
res.append(de... | 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,633,773,759 | 2,147,483,647 | PyPy 3 | OK | TESTS | 30 | 184 | 20,172,800 | n=input()
l=len(n)
lc=0
uc=0
for i in range(l):
if n[i].islower():
lc+=1
elif n[i].isupper():
uc+=1
if lc>uc:
n=n.lower()
elif uc>lc:
n=n.upper()
elif lc==uc:
n=n.lower()
print(n) | Title: Word
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it ei... | ```python
n=input()
l=len(n)
lc=0
uc=0
for i in range(l):
if n[i].islower():
lc+=1
elif n[i].isupper():
uc+=1
if lc>uc:
n=n.lower()
elif uc>lc:
n=n.upper()
elif lc==uc:
n=n.lower()
print(n)
``` | 3.916425 |
867 | A | Between the Offices | PROGRAMMING | 800 | [
"implementation"
] | null | null | As you may know, MemSQL has American offices in both San Francisco and Seattle. Being a manager in the company, you travel a lot between the two cities, always by plane.
You prefer flying from Seattle to San Francisco than in the other direction, because it's warmer in San Francisco. You are so busy that you don't rem... | The first line of input contains single integer *n* (2<=β€<=*n*<=β€<=100)Β β the number of days.
The second line contains a string of length *n* consisting of only capital 'S' and 'F' letters. If the *i*-th letter is 'S', then you were in Seattle office on that day. Otherwise you were in San Francisco. The days are given... | Print "YES" if you flew more times from Seattle to San Francisco, and "NO" otherwise.
You can print each letter in any case (upper or lower). | [
"4\nFSSF\n",
"2\nSF\n",
"10\nFFFFFFFFFF\n",
"10\nSSFFSFFSFF\n"
] | [
"NO\n",
"YES\n",
"NO\n",
"YES\n"
] | In the first example you were initially at San Francisco, then flew to Seattle, were there for two days and returned to San Francisco. You made one flight in each direction, so the answer is "NO".
In the second example you just flew from Seattle to San Francisco, so the answer is "YES".
In the third example you staye... | 500 | [
{
"input": "4\nFSSF",
"output": "NO"
},
{
"input": "2\nSF",
"output": "YES"
},
{
"input": "10\nFFFFFFFFFF",
"output": "NO"
},
{
"input": "10\nSSFFSFFSFF",
"output": "YES"
},
{
"input": "20\nSFSFFFFSSFFFFSSSSFSS",
"output": "NO"
},
{
"input": "20\nSSFFF... | 1,665,157,277 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 34 | 62 | 0 | n = int(input())
s = input()
sf = 0
fs = 0
for i in range(len(s)-1):
if s[i]+s[i+1] == 'SF':
sf += 1
elif s[i]+s[i+1] == "FS":
fs += 1
if sf>fs:
print("YES")
else:
print("NO")
| Title: Between the Offices
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
As you may know, MemSQL has American offices in both San Francisco and Seattle. Being a manager in the company, you travel a lot between the two cities, always by plane.
You prefer flying from Seattle to San Franci... | ```python
n = int(input())
s = input()
sf = 0
fs = 0
for i in range(len(s)-1):
if s[i]+s[i+1] == 'SF':
sf += 1
elif s[i]+s[i+1] == "FS":
fs += 1
if sf>fs:
print("YES")
else:
print("NO")
``` | 3 | |
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,577,732,739 | 2,147,483,647 | Python 3 | OK | TESTS | 26 | 124 | 0 | (b, p, f) = [int(a) for a in input().split(' ')]
t = ''
l = p - f
m = p + f
if l <= 1:
l = 1
else:
t = t + '<<' + ' '
if m > b:
m = b
for g in range (l, m + 1):
if g == p:
t = t + '(' + str(p) + ')' + ' '
else:
t = t + str(g) + ' '
if m < b:
t = t + '>>'
print (t... | 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
(b, p, f) = [int(a) for a in input().split(' ')]
t = ''
l = p - f
m = p + f
if l <= 1:
l = 1
else:
t = t + '<<' + ' '
if m > b:
m = b
for g in range (l, m + 1):
if g == p:
t = t + '(' + str(p) + ')' + ' '
else:
t = t + str(g) + ' '
if m < b:
t = t + '>>'... | 3 | |
285 | C | Building Permutation | PROGRAMMING | 1,200 | [
"greedy",
"implementation",
"sortings"
] | null | null | Permutation *p* is an ordered set of integers *p*1,<=<=*p*2,<=<=...,<=<=*p**n*, consisting of *n* distinct positive integers, each of them doesn't exceed *n*. We'll denote the *i*-th element of permutation *p* as *p**i*. We'll call number *n* the size or the length of permutation *p*1,<=<=*p*2,<=<=...,<=<=*p**n*.
You ... | The first line contains integer *n* (1<=β€<=*n*<=β€<=3Β·105) β the size of the sought permutation. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (<=-<=109<=β€<=*a**i*<=β€<=109). | Print a single number β the minimum number of moves.
Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier. | [
"2\n3 0\n",
"3\n-1 -1 2\n"
] | [
"2\n",
"6\n"
] | In the first sample you should decrease the first number by one and then increase the second number by one. The resulting permutation is (2,β1).
In the second sample you need 6 moves to build permutation (1,β3,β2). | 1,500 | [
{
"input": "2\n3 0",
"output": "2"
},
{
"input": "3\n-1 -1 2",
"output": "6"
},
{
"input": "5\n-3 5 -3 3 3",
"output": "10"
},
{
"input": "10\n9 6 -2 4 1 1 1 9 6 2",
"output": "18"
},
{
"input": "9\n2 0 0 6 5 4 1 9 3",
"output": "15"
},
{
"input": "100... | 1,591,705,228 | 2,147,483,647 | PyPy 3 | OK | TESTS | 33 | 514 | 26,112,000 | n=int(input())
arr=[int(i) for i in input().split()]
arr.sort()
ans=0
for i in range(n):
ans+=abs(arr[i]-i-1)
print(ans)
| Title: Building Permutation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Permutation *p* is an ordered set of integers *p*1,<=<=*p*2,<=<=...,<=<=*p**n*, consisting of *n* distinct positive integers, each of them doesn't exceed *n*. We'll denote the *i*-th element of permutation *p* as *... | ```python
n=int(input())
arr=[int(i) for i in input().split()]
arr.sort()
ans=0
for i in range(n):
ans+=abs(arr[i]-i-1)
print(ans)
``` | 3 | |
991 | D | Bishwock | PROGRAMMING | 1,500 | [
"dp",
"greedy"
] | null | null | Bishwock is a chess figure that consists of three squares resembling an "L-bar". This figure can be rotated by 90, 180 and 270 degrees so it can have four possible states:
Bishwocks don't attack any squares and can even occupy on the adjacent squares as long as they don't occupy the same square.
Vasya has a board wi... | The input contains two nonempty strings that describe Vasya's board. Those strings contain only symbols "0" (zero) that denote the empty squares and symbols "X" (uppercase English letter) that denote the squares occupied by pawns. Strings are nonempty and are of the same length that does not exceed $100$. | Output a single integerΒ β the maximum amount of bishwocks that can be placed onto the given board. | [
"00\n00\n",
"00X00X0XXX0\n0XXX0X00X00\n",
"0X0X0\n0X0X0\n",
"0XXX0\n00000\n"
] | [
"1",
"4",
"0",
"2"
] | none | 1,500 | [
{
"input": "00\n00",
"output": "1"
},
{
"input": "00X00X0XXX0\n0XXX0X00X00",
"output": "4"
},
{
"input": "0X0X0\n0X0X0",
"output": "0"
},
{
"input": "0XXX0\n00000",
"output": "2"
},
{
"input": "0\n0",
"output": "0"
},
{
"input": "0\nX",
"output": "... | 1,689,040,094 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 72 | 92 | 2,252,800 | from functools import cache
x = input()
y = input()
@cache
def dfs(a, b: bytes, index: int):
if index == len(x): return 0
ans = dfs(x[index], y[index], index + 1)
if (a == '0' or b == '0') and x[index] == '0' and y[index] == '0':
ans = max(ans, dfs('X', 'X', index + 1) + 1)
if a == '0' and b =... | Title: Bishwock
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bishwock is a chess figure that consists of three squares resembling an "L-bar". This figure can be rotated by 90, 180 and 270 degrees so it can have four possible states:
Bishwocks don't attack any squares and can even occup... | ```python
from functools import cache
x = input()
y = input()
@cache
def dfs(a, b: bytes, index: int):
if index == len(x): return 0
ans = dfs(x[index], y[index], index + 1)
if (a == '0' or b == '0') and x[index] == '0' and y[index] == '0':
ans = max(ans, dfs('X', 'X', index + 1) + 1)
if a == '... | 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,678,321,814 | 2,147,483,647 | Python 3 | OK | TESTS | 19 | 92 | 0 | s = input()
t = input()
c = s[0]
j = 0
count = 0
for i in range(len(t)):
if c == t[i]:
count += 1
j += 1
c = s[j]
print(count + 1)
| 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 = input()
c = s[0]
j = 0
count = 0
for i in range(len(t)):
if c == t[i]:
count += 1
j += 1
c = s[j]
print(count + 1)
``` | 3 | |
839 | A | Arya and Bran | PROGRAMMING | 900 | [
"implementation"
] | null | null | Bran and his older sister Arya are from the same house. Bran like candies so much, so Arya is going to give him some Candies.
At first, Arya and Bran have 0 Candies. There are *n* days, at the *i*-th day, Arya finds *a**i* candies in a box, that is given by the Many-Faced God. Every day she can give Bran at most 8 of ... | The first line contains two integers *n* and *k* (1<=β€<=*n*<=β€<=100, 1<=β€<=*k*<=β€<=10000).
The second line contains *n* integers *a*1,<=*a*2,<=*a*3,<=...,<=*a**n* (1<=β€<=*a**i*<=β€<=100). | If it is impossible for Arya to give Bran *k* candies within *n* days, print -1.
Otherwise print a single integerΒ β the minimum number of days Arya needs to give Bran *k* candies before the end of the *n*-th day. | [
"2 3\n1 2\n",
"3 17\n10 10 10\n",
"1 9\n10\n"
] | [
"2",
"3",
"-1"
] | In the first sample, Arya can give Bran 3 candies in 2 days.
In the second sample, Arya can give Bran 17 candies in 3 days, because she can give him at most 8 candies per day.
In the third sample, Arya can't give Bran 9 candies, because she can give him at most 8 candies per day and she must give him the candies with... | 500 | [
{
"input": "2 3\n1 2",
"output": "2"
},
{
"input": "3 17\n10 10 10",
"output": "3"
},
{
"input": "1 9\n10",
"output": "-1"
},
{
"input": "10 70\n6 5 2 3 3 2 1 4 3 2",
"output": "-1"
},
{
"input": "20 140\n40 4 81 40 10 54 34 50 84 60 16 1 90 78 38 93 99 60 81 99",... | 1,595,331,375 | 2,147,483,647 | Python 3 | OK | TESTS | 60 | 109 | 6,656,000 | n,k=map(int, input().split())
l=list(map(int, input().split()))
for i in range(n):
c=min(k,l[i],8)
if i!=n-1:
l[i+1]+=l[i]-c
k-=c
if k==0:
print(i+1)
break
else:
print("-1")
| Title: Arya and Bran
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bran and his older sister Arya are from the same house. Bran like candies so much, so Arya is going to give him some Candies.
At first, Arya and Bran have 0 Candies. There are *n* days, at the *i*-th day, Arya finds *a**... | ```python
n,k=map(int, input().split())
l=list(map(int, input().split()))
for i in range(n):
c=min(k,l[i],8)
if i!=n-1:
l[i+1]+=l[i]-c
k-=c
if k==0:
print(i+1)
break
else:
print("-1")
``` | 3 | |
205 | A | Little Elephant and Rozdil | PROGRAMMING | 900 | [
"brute force",
"implementation"
] | null | null | The Little Elephant loves Ukraine very much. Most of all he loves town Rozdol (ukr. "Rozdil").
However, Rozdil is dangerous to settle, so the Little Elephant wants to go to some other town. The Little Elephant doesn't like to spend much time on travelling, so for his journey he will choose a town that needs minimum ti... | The first line contains a single integer *n* (1<=β€<=*n*<=β€<=105) β the number of cities. The next line contains *n* integers, separated by single spaces: the *i*-th integer represents the time needed to go from town Rozdil to the *i*-th town. The time values are positive integers, not exceeding 109.
You can consider t... | Print the answer on a single line β the number of the town the Little Elephant will go to. If there are multiple cities with minimum travel time, print "Still Rozdil" (without the quotes). | [
"2\n7 4\n",
"7\n7 4 47 100 4 9 12\n"
] | [
"2\n",
"Still Rozdil\n"
] | In the first sample there are only two cities where the Little Elephant can go. The travel time for the first town equals 7, to the second one β 4. The town which is closest to Rodzil (the only one) is the second one, so the answer is 2.
In the second sample the closest cities are cities two and five, the travelling t... | 500 | [
{
"input": "2\n7 4",
"output": "2"
},
{
"input": "7\n7 4 47 100 4 9 12",
"output": "Still Rozdil"
},
{
"input": "1\n47",
"output": "1"
},
{
"input": "2\n1000000000 1000000000",
"output": "Still Rozdil"
},
{
"input": "7\n7 6 5 4 3 2 1",
"output": "7"
},
{
... | 1,662,906,958 | 2,147,483,647 | Python 3 | OK | TESTS | 45 | 156 | 7,987,200 | n=int(input())
l=list(map(int,input().split()))[:n]
k=min(l)
if l.count(k)==1:
print(l.index(k)+1)
else:
print('Still Rozdil') | Title: Little Elephant and Rozdil
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Little Elephant loves Ukraine very much. Most of all he loves town Rozdol (ukr. "Rozdil").
However, Rozdil is dangerous to settle, so the Little Elephant wants to go to some other town. The Little Elepha... | ```python
n=int(input())
l=list(map(int,input().split()))[:n]
k=min(l)
if l.count(k)==1:
print(l.index(k)+1)
else:
print('Still Rozdil')
``` | 3 | |
938 | A | Word Correction | PROGRAMMING | 800 | [
"implementation"
] | null | null | Victor tries to write his own text editor, with word correction included. However, the rules of word correction are really strange.
Victor thinks that if a word contains two consecutive vowels, then it's kinda weird and it needs to be replaced. So the word corrector works in such a way: as long as there are two consec... | The first line contains one integer *n* (1<=β€<=*n*<=β€<=100) β the number of letters in word *s* before the correction.
The second line contains a string *s* consisting of exactly *n* lowercase Latin letters β the word before the correction. | Output the word *s* after the correction. | [
"5\nweird\n",
"4\nword\n",
"5\naaeaa\n"
] | [
"werd\n",
"word\n",
"a\n"
] | Explanations of the examples:
1. There is only one replace: weird <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> werd;1. No replace needed since there are no two consecutive vowels;1. aaeaa <i... | 0 | [
{
"input": "5\nweird",
"output": "werd"
},
{
"input": "4\nword",
"output": "word"
},
{
"input": "5\naaeaa",
"output": "a"
},
{
"input": "100\naaaaabbbbboyoyoyoyoyacadabbbbbiuiufgiuiuaahjabbbklboyoyoyoyoyaaaaabbbbbiuiuiuiuiuaaaaabbbbbeyiyuyzyw",
"output": "abbbbbocadabbbbb... | 1,608,637,388 | 788 | Python 3 | OK | TESTS | 49 | 109 | 0 | n = input()
s = input()
vows = ["a", "e", "i", "o", "u", "y"]
s_new = ''
if s[0] in vows:
s_new = s[0]
for char in s:
if char not in vows:
s_new += char
else:
if s_new[-1] not in vows:
s_new += char
print(s_new)
| Title: Word Correction
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Victor tries to write his own text editor, with word correction included. However, the rules of word correction are really strange.
Victor thinks that if a word contains two consecutive vowels, then it's kinda weird an... | ```python
n = input()
s = input()
vows = ["a", "e", "i", "o", "u", "y"]
s_new = ''
if s[0] in vows:
s_new = s[0]
for char in s:
if char not in vows:
s_new += char
else:
if s_new[-1] not in vows:
s_new += char
print(s_new)
``` | 3 | |
507 | B | Amr and Pins | PROGRAMMING | 1,400 | [
"geometry",
"math"
] | null | null | Amr loves Geometry. One day he came up with a very interesting problem.
Amr has a circle of radius *r* and center in point (*x*,<=*y*). He wants the circle center to be in new position (*x*',<=*y*').
In one step Amr can put a pin to the border of the circle in a certain point, then rotate the circle around that pin b... | Input consists of 5 space-separated integers *r*, *x*, *y*, *x*' *y*' (1<=β€<=*r*<=β€<=105, <=-<=105<=β€<=*x*,<=*y*,<=*x*',<=*y*'<=β€<=105), circle radius, coordinates of original center of the circle and coordinates of destination center of the circle respectively. | Output a single integer β minimum number of steps required to move the center of the circle to the destination point. | [
"2 0 0 0 4\n",
"1 1 1 4 4\n",
"4 5 6 5 6\n"
] | [
"1\n",
"3\n",
"0\n"
] | In the first sample test the optimal way is to put a pin at point (0,β2) and rotate the circle by 180 degrees counter-clockwise (or clockwise, no matter).
<img class="tex-graphics" src="https://espresso.codeforces.com/4e40fd4cc24a2050a0488aa131e6244369328039.png" style="max-width: 100.0%;max-height: 100.0%;"/> | 1,000 | [
{
"input": "2 0 0 0 4",
"output": "1"
},
{
"input": "1 1 1 4 4",
"output": "3"
},
{
"input": "4 5 6 5 6",
"output": "0"
},
{
"input": "10 20 0 40 0",
"output": "1"
},
{
"input": "9 20 0 40 0",
"output": "2"
},
{
"input": "5 -1 -6 -5 1",
"output": "... | 1,569,574,193 | 2,147,483,647 | Python 3 | OK | TESTS | 37 | 139 | 0 | import math
g=input()
r,x,y,X,Y=[int(x) for x in g.split()]
d=math.sqrt((X-x)**2+(Y-y)**2)
l=1
if d==0:
print("0")
elif (2*r)>=d:
print("1")
else:
while (2*r)<d:
l+=1
d=d-2*r
print(l) | Title: Amr and Pins
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Amr loves Geometry. One day he came up with a very interesting problem.
Amr has a circle of radius *r* and center in point (*x*,<=*y*). He wants the circle center to be in new position (*x*',<=*y*').
In one step Amr can ... | ```python
import math
g=input()
r,x,y,X,Y=[int(x) for x in g.split()]
d=math.sqrt((X-x)**2+(Y-y)**2)
l=1
if d==0:
print("0")
elif (2*r)>=d:
print("1")
else:
while (2*r)<d:
l+=1
d=d-2*r
print(l)
``` | 3 | |
681 | A | A Good Contest | PROGRAMMING | 800 | [
"implementation"
] | null | null | Codeforces user' handle color depends on his ratingΒ β it is red if his rating is greater or equal to 2400; it is orange if his rating is less than 2400 but greater or equal to 2200, etc. Each time participant takes part in a rated contest, his rating is changed depending on his performance.
Anton wants the color of hi... | The first line of the input contains a single integer *n* (1<=β€<=*n*<=β€<=100)Β β the number of participants Anton has outscored in this contest .
The next *n* lines describe participants results: the *i*-th of them consists of a participant handle *name**i* and two integers *before**i* and *after**i* (<=-<=4000<=β€<=*be... | Print Β«YESΒ» (quotes for clarity), if Anton has performed good in the contest and Β«NOΒ» (quotes for clarity) otherwise. | [
"3\nBurunduk1 2526 2537\nBudAlNik 2084 2214\nsubscriber 2833 2749\n",
"3\nApplejack 2400 2400\nFluttershy 2390 2431\nPinkie_Pie -2500 -2450\n"
] | [
"YES",
"NO"
] | In the first sample, Anton has outscored user with handle Burunduk1, whose handle was colored red before the contest and his rating has increased after the contest.
In the second sample, Applejack's rating has not increased after the contest, while both Fluttershy's and Pinkie_Pie's handles were not colored red before... | 500 | [
{
"input": "3\nBurunduk1 2526 2537\nBudAlNik 2084 2214\nsubscriber 2833 2749",
"output": "YES"
},
{
"input": "3\nApplejack 2400 2400\nFluttershy 2390 2431\nPinkie_Pie -2500 -2450",
"output": "NO"
},
{
"input": "1\nDb -3373 3591",
"output": "NO"
},
{
"input": "5\nQ2bz 960 2342... | 1,593,980,866 | 2,147,483,647 | PyPy 3 | OK | TESTS | 60 | 155 | 20,172,800 | import sys
numCases = int(input())
isGood = False
for i in range(0, numCases):
inputArray = input().split(' ')
score1 = int(inputArray[1])
score2 = int(inputArray[2])
if score1 >= 2400 and score2 > score1:
isGood = True
if isGood:
print("YES")
else:
print("NO") | Title: A Good Contest
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Codeforces user' handle color depends on his ratingΒ β it is red if his rating is greater or equal to 2400; it is orange if his rating is less than 2400 but greater or equal to 2200, etc. Each time participant takes part ... | ```python
import sys
numCases = int(input())
isGood = False
for i in range(0, numCases):
inputArray = input().split(' ')
score1 = int(inputArray[1])
score2 = int(inputArray[2])
if score1 >= 2400 and score2 > score1:
isGood = True
if isGood:
print("YES")
else:
print("NO"... | 3 | |
469 | A | I Wanna Be the Guy | PROGRAMMING | 800 | [
"greedy",
"implementation"
] | null | null | There is a game called "I Wanna Be the Guy", consisting of *n* levels. Little X and his friend Little Y are addicted to the game. Each of them wants to pass the whole game.
Little X can pass only *p* levels of the game. And Little Y can pass only *q* levels of the game. You are given the indices of levels Little X can... | The first line contains a single integer *n* (1<=β€<=<=*n*<=β€<=100).
The next line contains an integer *p* (0<=β€<=*p*<=β€<=*n*) at first, then follows *p* distinct integers *a*1,<=*a*2,<=...,<=*a**p* (1<=β€<=*a**i*<=β€<=*n*). These integers denote the indices of levels Little X can pass. The next line contains the levels... | If they can pass all the levels, print "I become the guy.". If it's impossible, print "Oh, my keyboard!" (without the quotes). | [
"4\n3 1 2 3\n2 2 4\n",
"4\n3 1 2 3\n2 2 3\n"
] | [
"I become the guy.\n",
"Oh, my keyboard!\n"
] | In the first sample, Little X can pass levels [1 2 3], and Little Y can pass level [2 4], so they can pass all the levels both.
In the second sample, no one can pass level 4. | 500 | [
{
"input": "4\n3 1 2 3\n2 2 4",
"output": "I become the guy."
},
{
"input": "4\n3 1 2 3\n2 2 3",
"output": "Oh, my keyboard!"
},
{
"input": "10\n5 8 6 1 5 4\n6 1 3 2 9 4 6",
"output": "Oh, my keyboard!"
},
{
"input": "10\n8 8 10 7 3 1 4 2 6\n8 9 5 10 3 7 2 4 8",
"output":... | 1,691,433,471 | 2,147,483,647 | Python 3 | OK | TESTS | 29 | 46 | 0 | n = int(input())
x = input()[1:]
y = input()[1:]
xy = x+y
if all([str(i) in xy for i in range(1, n+1)]):
print('I become the guy.')
else:
print('Oh, my keyboard!') | Title: I Wanna Be the Guy
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There is a game called "I Wanna Be the Guy", consisting of *n* levels. Little X and his friend Little Y are addicted to the game. Each of them wants to pass the whole game.
Little X can pass only *p* levels of the g... | ```python
n = int(input())
x = input()[1:]
y = input()[1:]
xy = x+y
if all([str(i) in xy for i in range(1, n+1)]):
print('I become the guy.')
else:
print('Oh, my keyboard!')
``` | 3 | |
509 | A | Maximum in Table | PROGRAMMING | 800 | [
"brute force",
"implementation"
] | null | null | An *n*<=Γ<=*n* table *a* is defined as follows:
- The first row and the first column contain ones, that is: *a**i*,<=1<==<=*a*1,<=*i*<==<=1 for all *i*<==<=1,<=2,<=...,<=*n*. - Each of the remaining numbers in the table is equal to the sum of the number above it and the number to the left of it. In other words, the ... | The only line of input contains a positive integer *n* (1<=β€<=*n*<=β€<=10) β the number of rows and columns of the table. | Print a single line containing a positive integer *m* β the maximum value in the table. | [
"1\n",
"5\n"
] | [
"1",
"70"
] | In the second test the rows of the table look as follows: | 0 | [
{
"input": "1",
"output": "1"
},
{
"input": "5",
"output": "70"
},
{
"input": "2",
"output": "2"
},
{
"input": "3",
"output": "6"
},
{
"input": "4",
"output": "20"
},
{
"input": "6",
"output": "252"
},
{
"input": "7",
"output": "924"
... | 1,629,025,236 | 2,147,483,647 | Python 3 | OK | TESTS | 10 | 62 | 6,963,200 | def main(n):
n = int(n)
mas = []
for i in range(n):
mas.append([1]*n)
#print(mas)
for i in range(1,n):
for j in range(1,n):
mas[i][j] = mas[i-1][j] + mas[i][j-1]
#for i in range(n):
#mas[0][i] = 1
return mas[-1][-1]
print(main(input()... | Title: Maximum in Table
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
An *n*<=Γ<=*n* table *a* is defined as follows:
- The first row and the first column contain ones, that is: *a**i*,<=1<==<=*a*1,<=*i*<==<=1 for all *i*<==<=1,<=2,<=...,<=*n*. - Each of the remaining numbers in the t... | ```python
def main(n):
n = int(n)
mas = []
for i in range(n):
mas.append([1]*n)
#print(mas)
for i in range(1,n):
for j in range(1,n):
mas[i][j] = mas[i-1][j] + mas[i][j-1]
#for i in range(n):
#mas[0][i] = 1
return mas[-1][-1]
print(ma... | 3 | |
621 | A | Wet Shark and Odd and Even | PROGRAMMING | 900 | [
"implementation"
] | null | null | Today, Wet Shark is given *n* integers. Using any of these integers no more than once, Wet Shark wants to get maximum possible even (divisible by 2) sum. Please, calculate this value for Wet Shark.
Note, that if Wet Shark uses no integers from the *n* integers, the sum is an even integer 0. | The first line of the input contains one integer, *n* (1<=β€<=*n*<=β€<=100<=000). The next line contains *n* space separated integers given to Wet Shark. Each of these integers is in range from 1 to 109, inclusive. | Print the maximum possible even sum that can be obtained if we use some of the given integers. | [
"3\n1 2 3\n",
"5\n999999999 999999999 999999999 999999999 999999999\n"
] | [
"6",
"3999999996"
] | In the first sample, we can simply take all three integers for a total sum of 6.
In the second sample Wet Shark should take any four out of five integers 999β999β999. | 500 | [
{
"input": "3\n1 2 3",
"output": "6"
},
{
"input": "5\n999999999 999999999 999999999 999999999 999999999",
"output": "3999999996"
},
{
"input": "1\n1",
"output": "0"
},
{
"input": "15\n39 52 88 78 46 95 84 98 55 3 68 42 6 18 98",
"output": "870"
},
{
"input": "15\... | 1,578,372,713 | 2,147,483,647 | Python 3 | OK | TESTS | 87 | 171 | 8,499,200 | n = int(input())
a = [int(x) for x in input().split()]
if(sum(a) % 2 ==0):
print(sum(a))
else:
x =[]
for i in a:
if i % 2 !=0:
x.append(i)
print(sum(a) - min(x))
| Title: Wet Shark and Odd and Even
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Today, Wet Shark is given *n* integers. Using any of these integers no more than once, Wet Shark wants to get maximum possible even (divisible by 2) sum. Please, calculate this value for Wet Shark.
Note, th... | ```python
n = int(input())
a = [int(x) for x in input().split()]
if(sum(a) % 2 ==0):
print(sum(a))
else:
x =[]
for i in a:
if i % 2 !=0:
x.append(i)
print(sum(a) - min(x))
``` | 3 | |
902 | B | Coloring a Tree | PROGRAMMING | 1,200 | [
"dfs and similar",
"dsu",
"greedy"
] | null | null | You are given a rooted tree with *n* vertices. The vertices are numbered from 1 to *n*, the root is the vertex number 1.
Each vertex has a color, let's denote the color of vertex *v* by *c**v*. Initially *c**v*<==<=0.
You have to color the tree into the given colors using the smallest possible number of steps. On eac... | The first line contains a single integer *n* (2<=β€<=*n*<=β€<=104)Β β the number of vertices in the tree.
The second line contains *n*<=-<=1 integers *p*2,<=*p*3,<=...,<=*p**n* (1<=β€<=*p**i*<=<<=*i*), where *p**i* means that there is an edge between vertices *i* and *p**i*.
The third line contains *n* integers *c*1,<... | Print a single integerΒ β the minimum number of steps you have to perform to color the tree into given colors. | [
"6\n1 2 2 1 5\n2 1 1 1 1 1\n",
"7\n1 1 2 3 1 4\n3 3 1 1 1 2 3\n"
] | [
"3\n",
"5\n"
] | The tree from the first sample is shown on the picture (numbers are vetices' indices):
<img class="tex-graphics" src="https://espresso.codeforces.com/10324ccdc37f95343acc4f3c6050d8c334334ffa.png" style="max-width: 100.0%;max-height: 100.0%;"/>
On first step we color all vertices in the subtree of vertex 1 into color ... | 1,000 | [
{
"input": "6\n1 2 2 1 5\n2 1 1 1 1 1",
"output": "3"
},
{
"input": "7\n1 1 2 3 1 4\n3 3 1 1 1 2 3",
"output": "5"
},
{
"input": "2\n1\n2 2",
"output": "1"
},
{
"input": "3\n1 1\n2 2 2",
"output": "1"
},
{
"input": "4\n1 2 1\n1 2 3 4",
"output": "4"
},
{
... | 1,513,782,184 | 2,147,483,647 | Python 3 | OK | TESTS | 50 | 92 | 7,168,000 | n=int(input())
m=[]
p=list(map(int,input().split()))
c=[0]+list(map(int,input().split()))
m=[1]+[list() for i in range(n)]
for i in range(n-1):
m[p[i]].append(i+2)
stack=[[1,c[1]]]
k=1
while stack:
x,col=stack.pop(0)
for i in m[x]:
if c[i]!=col:
k+=1
stack.append([i... | Title: Coloring a Tree
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a rooted tree with *n* vertices. The vertices are numbered from 1 to *n*, the root is the vertex number 1.
Each vertex has a color, let's denote the color of vertex *v* by *c**v*. Initially *c**v*<==<=0.
... | ```python
n=int(input())
m=[]
p=list(map(int,input().split()))
c=[0]+list(map(int,input().split()))
m=[1]+[list() for i in range(n)]
for i in range(n-1):
m[p[i]].append(i+2)
stack=[[1,c[1]]]
k=1
while stack:
x,col=stack.pop(0)
for i in m[x]:
if c[i]!=col:
k+=1
stack... | 3 | |
989 | A | A Blend of Springtime | PROGRAMMING | 900 | [
"implementation",
"strings"
] | null | null | "What a pity it's already late spring," sighs Mino with regret, "one more drizzling night and they'd be gone."
"But these blends are at their best, aren't they?" Absorbed in the landscape, Kanno remains optimistic.
The landscape can be expressed as a row of consecutive cells, each of which either contains a flower o... | The first and only line of input contains a non-empty string $s$ consisting of uppercase English letters 'A', 'B', 'C' and characters '.' (dots) only ($\lvert s \rvert \leq 100$)Β β denoting cells containing an amber flower, a buff one, a canary yellow one, and no flowers, respectively. | Output "Yes" if it's possible that all three colours appear in some cell, and "No" otherwise.
You can print each letter in any case (upper or lower). | [
".BAC.\n",
"AA..CB\n"
] | [
"Yes\n",
"No\n"
] | In the first example, the buff and canary yellow flowers can leave their petals in the central cell, blending all three colours in it.
In the second example, it's impossible to satisfy the requirement because there is no way that amber and buff meet in any cell. | 500 | [
{
"input": ".BAC.",
"output": "Yes"
},
{
"input": "AA..CB",
"output": "No"
},
{
"input": ".",
"output": "No"
},
{
"input": "ACB.AAAAAA",
"output": "Yes"
},
{
"input": "B.BC.BBBCA",
"output": "Yes"
},
{
"input": "BA..CAB..B",
"output": "Yes"
},
... | 1,600,165,723 | 523 | Python 3 | OK | TESTS | 37 | 187 | 1,638,400 | from collections import Counter
import string
import math
import sys
def array_int():
return [int(i) for i in sys.stdin.readline().split()]
def vary(number_of_variables):
if number_of_variables==1:
return int(sys.stdin.readline())
if number_of_variables>=2:
return map(int,sys.stdin... | Title: A Blend of Springtime
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
"What a pity it's already late spring," sighs Mino with regret, "one more drizzling night and they'd be gone."
"But these blends are at their best, aren't they?" Absorbed in the landscape, Kanno remains optimisti... | ```python
from collections import Counter
import string
import math
import sys
def array_int():
return [int(i) for i in sys.stdin.readline().split()]
def vary(number_of_variables):
if number_of_variables==1:
return int(sys.stdin.readline())
if number_of_variables>=2:
return map(int... | 3 | |
447 | B | DZY Loves Strings | PROGRAMMING | 1,000 | [
"greedy",
"implementation"
] | null | null | DZY loves collecting special strings which only contain lowercase letters. For each lowercase letter *c* DZY knows its value *w**c*. For each special string *s*<==<=*s*1*s*2... *s*|*s*| (|*s*| is the length of the string) he represents its value with a function *f*(*s*), where
Now DZY has a string *s*. He wants to in... | The first line contains a single string *s*Β (1<=β€<=|*s*|<=β€<=103).
The second line contains a single integer *k*Β (0<=β€<=*k*<=β€<=103).
The third line contains twenty-six integers from *w**a* to *w**z*. Each such number is non-negative and doesn't exceed 1000. | Print a single integer β the largest possible value of the resulting string DZY could get. | [
"abc\n3\n1 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n"
] | [
"41\n"
] | In the test sample DZY can obtain "abcbbc", *value*β=β1Β·1β+β2Β·2β+β3Β·2β+β4Β·2β+β5Β·2β+β6Β·2β=β41. | 1,000 | [
{
"input": "abc\n3\n1 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "41"
},
{
"input": "mmzhr\n3\n443 497 867 471 195 670 453 413 579 466 553 881 847 642 269 996 666 702 487 209 257 741 974 133 519 453",
"output": "29978"
},
{
"input": "ajeeseerqnpaujubmajpibxrccazaawetyw... | 1,560,759,927 | 2,147,483,647 | Python 3 | OK | TESTS | 24 | 124 | 0 | # import sys
# sys.stdin=open("input.in",'r')
# sys.stdout=open("out.out",'w')
x=input()
n=int(input())
s=list(map(int,input().split()))
v=0
for i in range(len(x)):
m=ord(x[i])-97
v+=(i+1)*s[m]
s.sort()
i+=2
while n:
v+=i*s[-1]
n-=1
i+=1
print(v) | Title: DZY Loves Strings
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
DZY loves collecting special strings which only contain lowercase letters. For each lowercase letter *c* DZY knows its value *w**c*. For each special string *s*<==<=*s*1*s*2... *s*|*s*| (|*s*| is the length of the str... | ```python
# import sys
# sys.stdin=open("input.in",'r')
# sys.stdout=open("out.out",'w')
x=input()
n=int(input())
s=list(map(int,input().split()))
v=0
for i in range(len(x)):
m=ord(x[i])-97
v+=(i+1)*s[m]
s.sort()
i+=2
while n:
v+=i*s[-1]
n-=1
i+=1
print(v)
``` | 3 | |
462 | B | Appleman and Card Game | PROGRAMMING | 1,300 | [
"greedy"
] | null | null | Appleman has *n* cards. Each card has an uppercase letter written on it. Toastman must choose *k* cards from Appleman's cards. Then Appleman should give Toastman some coins depending on the chosen cards. Formally, for each Toastman's card *i* you should calculate how much Toastman's cards have the letter equal to lette... | The first line contains two integers *n* and *k* (1<=β€<=*k*<=β€<=*n*<=β€<=105). The next line contains *n* uppercase letters without spaces β the *i*-th letter describes the *i*-th card of the Appleman. | Print a single integer β the answer to the problem. | [
"15 10\nDZFDFZDFDDDDDDF\n",
"6 4\nYJSNPI\n"
] | [
"82\n",
"4\n"
] | In the first test example Toastman can choose nine cards with letter D and one additional card with any letter. For each card with D he will get 9 coins and for the additional card he will get 1 coin. | 1,000 | [
{
"input": "15 10\nDZFDFZDFDDDDDDF",
"output": "82"
},
{
"input": "6 4\nYJSNPI",
"output": "4"
},
{
"input": "5 3\nAOWBY",
"output": "3"
},
{
"input": "1 1\nV",
"output": "1"
},
{
"input": "2 1\nWT",
"output": "1"
},
{
"input": "2 2\nBL",
"output":... | 1,599,641,630 | 2,147,483,647 | PyPy 3 | OK | TESTS | 41 | 155 | 4,198,400 | n,k=map(int,input().split())
s=list(input())
d={}
for i in s:
try:
d[i]+=1
except:
d[i]=1
new=[]
for keys in d:
new.append(d[keys])
new.sort(reverse=True)
i=0
total=0
while(k>0):
if new[i]<=k:
total+=(new[i]**2)
k-=new[i]
i+=1
else:
... | Title: Appleman and Card Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Appleman has *n* cards. Each card has an uppercase letter written on it. Toastman must choose *k* cards from Appleman's cards. Then Appleman should give Toastman some coins depending on the chosen cards. Formally... | ```python
n,k=map(int,input().split())
s=list(input())
d={}
for i in s:
try:
d[i]+=1
except:
d[i]=1
new=[]
for keys in d:
new.append(d[keys])
new.sort(reverse=True)
i=0
total=0
while(k>0):
if new[i]<=k:
total+=(new[i]**2)
k-=new[i]
i+=1
else... | 3 | |
110 | A | Nearly Lucky Number | PROGRAMMING | 800 | [
"implementation"
] | A. Nearly Lucky Number | 2 | 256 | Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Unfortunately, not all numbers are lucky. Petya calls a number nearly lucky if the number of lucky d... | The only line contains an integer *n* (1<=β€<=*n*<=β€<=1018).
Please do not use the %lld specificator to read or write 64-bit numbers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specificator. | Print on the single line "YES" if *n* is a nearly lucky number. Otherwise, print "NO" (without the quotes). | [
"40047\n",
"7747774\n",
"1000000000000000000\n"
] | [
"NO\n",
"YES\n",
"NO\n"
] | In the first sample there are 3 lucky digits (first one and last two), so the answer is "NO".
In the second sample there are 7 lucky digits, 7 is lucky number, so the answer is "YES".
In the third sample there are no lucky digits, so the answer is "NO". | 500 | [
{
"input": "40047",
"output": "NO"
},
{
"input": "7747774",
"output": "YES"
},
{
"input": "1000000000000000000",
"output": "NO"
},
{
"input": "7",
"output": "NO"
},
{
"input": "4",
"output": "NO"
},
{
"input": "474404774",
"output": "NO"
},
{
... | 1,696,616,657 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 92 | 0 | x = input()
total = 0
for i in range(len(x)):
if x[i] == '4' or x[i] == '7':
total += 1
if total > 7:
break
if total == 4 or total == 7:
print('YES')
else:
print('NO') | Title: Nearly Lucky Number
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
... | ```python
x = input()
total = 0
for i in range(len(x)):
if x[i] == '4' or x[i] == '7':
total += 1
if total > 7:
break
if total == 4 or total == 7:
print('YES')
else:
print('NO')
``` | 3.977 |
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,679,330,082 | 2,147,483,647 | Python 3 | OK | TESTS | 102 | 46 | 0 | a=input()
b=input()
d=len(a)
c=""
for i in range(d):
if((int(a[i])+int(b[i]))==2):
c=c+"0"
else:
c=c+str(int(a[i])+int(b[i]))
print(c) | Title: Ultra-Fast Mathematician
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 10... | ```python
a=input()
b=input()
d=len(a)
c=""
for i in range(d):
if((int(a[i])+int(b[i]))==2):
c=c+"0"
else:
c=c+str(int(a[i])+int(b[i]))
print(c)
``` | 3.9885 |
401 | A | Vanya and Cards | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | Vanya loves playing. He even has a special set of cards to play with. Each card has a single integer. The number on the card can be positive, negative and can even be equal to zero. The only limit is, the number on each card doesn't exceed *x* in the absolute value.
Natasha doesn't like when Vanya spends a long time p... | The first line contains two integers: *n* (1<=β€<=*n*<=β€<=1000) β the number of found cards and *x* (1<=β€<=*x*<=β€<=1000) β the maximum absolute value of the number on a card. The second line contains *n* space-separated integers β the numbers on found cards. It is guaranteed that the numbers do not exceed *x* in their a... | Print a single number β the answer to the problem. | [
"3 2\n-1 1 2\n",
"2 3\n-2 -2\n"
] | [
"1\n",
"2\n"
] | In the first sample, Vanya needs to find a single card with number -2.
In the second sample, Vanya needs to find two cards with number 2. He can't find a single card with the required number as the numbers on the lost cards do not exceed 3 in their absolute value. | 500 | [
{
"input": "3 2\n-1 1 2",
"output": "1"
},
{
"input": "2 3\n-2 -2",
"output": "2"
},
{
"input": "4 4\n1 2 3 4",
"output": "3"
},
{
"input": "2 2\n-1 -1",
"output": "1"
},
{
"input": "15 5\n-2 -1 2 -4 -3 4 -4 -2 -2 2 -2 -1 1 -4 -2",
"output": "4"
},
{
"... | 1,614,233,387 | 2,147,483,647 | PyPy 3 | OK | TESTS | 47 | 108 | 0 |
n,m = map(int,input().split())
t = list(map(int,input().split()))
u= sum(t)
if u==0:print(0)
else:
if abs(u)<=m:print(1)
else:
if abs(u)%m==0:print(abs(u)//m)
else:print((abs(u)//m)+1)
| Title: Vanya and Cards
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vanya loves playing. He even has a special set of cards to play with. Each card has a single integer. The number on the card can be positive, negative and can even be equal to zero. The only limit is, the number on each... | ```python
n,m = map(int,input().split())
t = list(map(int,input().split()))
u= sum(t)
if u==0:print(0)
else:
if abs(u)<=m:print(1)
else:
if abs(u)%m==0:print(abs(u)//m)
else:print((abs(u)//m)+1)
``` | 3 | |
478 | B | Random Teams | PROGRAMMING | 1,300 | [
"combinatorics",
"constructive algorithms",
"greedy",
"math"
] | null | null | *n* participants of the competition were split into *m* teams in some manner so that each team has at least one participant. After the competition each pair of participants from the same team became friends.
Your task is to write a program that will find the minimum and the maximum number of pairs of friends that coul... | The only line of input contains two integers *n* and *m*, separated by a single space (1<=β€<=*m*<=β€<=*n*<=β€<=109) β the number of participants and the number of teams respectively. | The only line of the output should contain two integers *k**min* and *k**max* β the minimum possible number of pairs of friends and the maximum possible number of pairs of friends respectively. | [
"5 1\n",
"3 2\n",
"6 3\n"
] | [
"10 10\n",
"1 1\n",
"3 6\n"
] | In the first sample all the participants get into one team, so there will be exactly ten pairs of friends.
In the second sample at any possible arrangement one team will always have two participants and the other team will always have one participant. Thus, the number of pairs of friends will always be equal to one.
... | 1,000 | [
{
"input": "5 1",
"output": "10 10"
},
{
"input": "3 2",
"output": "1 1"
},
{
"input": "6 3",
"output": "3 6"
},
{
"input": "5 3",
"output": "2 3"
},
{
"input": "10 2",
"output": "20 36"
},
{
"input": "10 6",
"output": "4 10"
},
{
"input": ... | 1,677,739,633 | 2,147,483,647 | PyPy 3 | OK | TESTS | 26 | 93 | 0 | a,b = ([int(x) for x in input().split()])
c=a-(b-1)
d=(c*(c-1))//2
e=a//b
f=a%b
g=b-f
h=g*(e*(e-1))//2 + f*(e*(e+1))//2
print(h,d) | Title: Random Teams
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
*n* participants of the competition were split into *m* teams in some manner so that each team has at least one participant. After the competition each pair of participants from the same team became friends.
Your task is ... | ```python
a,b = ([int(x) for x in input().split()])
c=a-(b-1)
d=(c*(c-1))//2
e=a//b
f=a%b
g=b-f
h=g*(e*(e-1))//2 + f*(e*(e+1))//2
print(h,d)
``` | 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,664,013,427 | 2,147,483,647 | Python 3 | OK | TESTS | 21 | 46 | 0 | no3=int(input())
no4=list(map(int,input().split()))
while(0 in no4):
no4.remove(0)
no4=set(no4)
print(len(no4))
| 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
no3=int(input())
no4=list(map(int,input().split()))
while(0 in no4):
no4.remove(0)
no4=set(no4)
print(len(no4))
``` | 3 | |
902 | B | Coloring a Tree | PROGRAMMING | 1,200 | [
"dfs and similar",
"dsu",
"greedy"
] | null | null | You are given a rooted tree with *n* vertices. The vertices are numbered from 1 to *n*, the root is the vertex number 1.
Each vertex has a color, let's denote the color of vertex *v* by *c**v*. Initially *c**v*<==<=0.
You have to color the tree into the given colors using the smallest possible number of steps. On eac... | The first line contains a single integer *n* (2<=β€<=*n*<=β€<=104)Β β the number of vertices in the tree.
The second line contains *n*<=-<=1 integers *p*2,<=*p*3,<=...,<=*p**n* (1<=β€<=*p**i*<=<<=*i*), where *p**i* means that there is an edge between vertices *i* and *p**i*.
The third line contains *n* integers *c*1,<... | Print a single integerΒ β the minimum number of steps you have to perform to color the tree into given colors. | [
"6\n1 2 2 1 5\n2 1 1 1 1 1\n",
"7\n1 1 2 3 1 4\n3 3 1 1 1 2 3\n"
] | [
"3\n",
"5\n"
] | The tree from the first sample is shown on the picture (numbers are vetices' indices):
<img class="tex-graphics" src="https://espresso.codeforces.com/10324ccdc37f95343acc4f3c6050d8c334334ffa.png" style="max-width: 100.0%;max-height: 100.0%;"/>
On first step we color all vertices in the subtree of vertex 1 into color ... | 1,000 | [
{
"input": "6\n1 2 2 1 5\n2 1 1 1 1 1",
"output": "3"
},
{
"input": "7\n1 1 2 3 1 4\n3 3 1 1 1 2 3",
"output": "5"
},
{
"input": "2\n1\n2 2",
"output": "1"
},
{
"input": "3\n1 1\n2 2 2",
"output": "1"
},
{
"input": "4\n1 2 1\n1 2 3 4",
"output": "4"
},
{
... | 1,644,863,382 | 2,147,483,647 | PyPy 3 | OK | TESTS | 50 | 124 | 5,734,400 | from collections import defaultdict as di
from collections import deque as dq
n=int(input())
coupl = di(list)
nodess = [int(x)-1 for x in input().split()]
for i in range(n-1):
node = nodess[i]
coupl[i+1].append(node)
coupl[node].append(i+1)
colors = [int(x)-1 for x in input().split()]
Q=dq()
... | Title: Coloring a Tree
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a rooted tree with *n* vertices. The vertices are numbered from 1 to *n*, the root is the vertex number 1.
Each vertex has a color, let's denote the color of vertex *v* by *c**v*. Initially *c**v*<==<=0.
... | ```python
from collections import defaultdict as di
from collections import deque as dq
n=int(input())
coupl = di(list)
nodess = [int(x)-1 for x in input().split()]
for i in range(n-1):
node = nodess[i]
coupl[i+1].append(node)
coupl[node].append(i+1)
colors = [int(x)-1 for x in input().split()]
... | 3 | |
893 | C | Rumor | PROGRAMMING | 1,300 | [
"dfs and similar",
"graphs",
"greedy"
] | null | null | Vova promised himself that he would never play computer games... But recently Firestorm β a well-known game developing company β published their newest game, World of Farcraft, and it became really popular. Of course, Vova started playing it.
Now he tries to solve a quest. The task is to come to a settlement named Ove... | The first line contains two integer numbers *n* and *m* (1<=β€<=*n*<=β€<=105,<=0<=β€<=*m*<=β€<=105) β the number of characters in Overcity and the number of pairs of friends.
The second line contains *n* integer numbers *c**i* (0<=β€<=*c**i*<=β€<=109) β the amount of gold *i*-th character asks to start spreading the rumor.
... | Print one number β the minimum amount of gold Vova has to spend in order to finish the quest. | [
"5 2\n2 5 3 4 8\n1 4\n4 5\n",
"10 0\n1 2 3 4 5 6 7 8 9 10\n",
"10 5\n1 6 2 7 3 8 4 9 5 10\n1 2\n3 4\n5 6\n7 8\n9 10\n"
] | [
"10\n",
"55\n",
"15\n"
] | In the first example the best decision is to bribe the first character (he will spread the rumor to fourth character, and the fourth one will spread it to fifth). Also Vova has to bribe the second and the third characters, so they know the rumor.
In the second example Vova has to bribe everyone.
In the third example ... | 0 | [
{
"input": "5 2\n2 5 3 4 8\n1 4\n4 5",
"output": "10"
},
{
"input": "10 0\n1 2 3 4 5 6 7 8 9 10",
"output": "55"
},
{
"input": "10 5\n1 6 2 7 3 8 4 9 5 10\n1 2\n3 4\n5 6\n7 8\n9 10",
"output": "15"
},
{
"input": "1 0\n0",
"output": "0"
},
{
"input": "1 0\n10000000... | 1,665,558,208 | 2,147,483,647 | Python 3 | OK | TESTS | 46 | 530 | 16,793,600 | from collections import defaultdict
n,m = list(map(int,input().split()))
arr = list(map(int,input().split()))
parent = [i for i in range(n+1)]
rank = [0]*(n+1)
def find(p):
while p != parent[p]:
p = parent[p]
return p
def union(x, y):
x = find(x)
y = find(y)
if x!=y... | Title: Rumor
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vova promised himself that he would never play computer games... But recently Firestorm β a well-known game developing company β published their newest game, World of Farcraft, and it became really popular. Of course, Vova starte... | ```python
from collections import defaultdict
n,m = list(map(int,input().split()))
arr = list(map(int,input().split()))
parent = [i for i in range(n+1)]
rank = [0]*(n+1)
def find(p):
while p != parent[p]:
p = parent[p]
return p
def union(x, y):
x = find(x)
y = find(y)
... | 3 | |
633 | A | Ebony and Ivory | PROGRAMMING | 1,100 | [
"brute force",
"math",
"number theory"
] | null | null | Dante is engaged in a fight with "The Savior". Before he can fight it with his sword, he needs to break its shields. He has two guns, Ebony and Ivory, each of them is able to perform any non-negative number of shots.
For every bullet that hits the shield, Ebony deals *a* units of damage while Ivory deals *b* units of ... | The first line of the input contains three integers *a*, *b*, *c* (1<=β€<=*a*,<=*b*<=β€<=100,<=1<=β€<=*c*<=β€<=10<=000)Β β the number of units of damage dealt by Ebony gun and Ivory gun, and the total number of damage required to break the shield, respectively. | Print "Yes" (without quotes) if Dante can deal exactly *c* damage to the shield and "No" (without quotes) otherwise. | [
"4 6 15\n",
"3 2 7\n",
"6 11 6\n"
] | [
"No\n",
"Yes\n",
"Yes\n"
] | In the second sample, Dante can fire 1 bullet from Ebony and 2 from Ivory to deal exactly 1Β·3β+β2Β·2β=β7 damage. In the third sample, Dante can fire 1 bullet from ebony and no bullets from ivory to do 1Β·6β+β0Β·11β=β6 damage. | 250 | [
{
"input": "4 6 15",
"output": "No"
},
{
"input": "3 2 7",
"output": "Yes"
},
{
"input": "6 11 6",
"output": "Yes"
},
{
"input": "3 12 15",
"output": "Yes"
},
{
"input": "5 5 10",
"output": "Yes"
},
{
"input": "6 6 7",
"output": "No"
},
{
"... | 1,681,464,856 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 134 | 93 | 1,536,000 | a, b, c = map(int, input().split())
ans = "NO"
for i in range(c+1):
tmp = c - a*i
if tmp >= 0 and tmp%b == 0:
#print(i, (c-a*i)//b)
ans = "YES"
break
print(ans) | Title: Ebony and Ivory
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Dante is engaged in a fight with "The Savior". Before he can fight it with his sword, he needs to break its shields. He has two guns, Ebony and Ivory, each of them is able to perform any non-negative number of shots.
F... | ```python
a, b, c = map(int, input().split())
ans = "NO"
for i in range(c+1):
tmp = c - a*i
if tmp >= 0 and tmp%b == 0:
#print(i, (c-a*i)//b)
ans = "YES"
break
print(ans)
``` | 3 | |
254 | A | Cards with Numbers | PROGRAMMING | 1,200 | [
"constructive algorithms",
"sortings"
] | null | null | Petya has got 2*n* cards, each card contains some integer. The numbers on the cards can be the same. Let's index all cards by consecutive integers from 1 to 2*n*. We'll denote the number that is written on a card with number *i*, as *a**i*. In order to play one entertaining game with his friends, Petya needs to split t... | The first line contains integer *n* (1<=β€<=*n*<=β€<=3Β·105). The second line contains the sequence of 2*n* positive integers *a*1,<=*a*2,<=...,<=*a*2*n* (1<=β€<=*a**i*<=β€<=5000) β the numbers that are written on the cards. The numbers on the line are separated by single spaces. | If it is impossible to divide the cards into pairs so that cards in each pair had the same numbers, print on a single line integer -1. But if the required partition exists, then print *n* pairs of integers, a pair per line β the indices of the cards that form the pairs.
Separate the numbers on the lines by spaces. You... | [
"3\n20 30 10 30 20 10\n",
"1\n1 2\n"
] | [
"4 2\n1 5\n6 3\n",
"-1"
] | none | 500 | [
{
"input": "3\n20 30 10 30 20 10",
"output": "4 2\n1 5\n6 3"
},
{
"input": "1\n1 2",
"output": "-1"
},
{
"input": "5\n2 2 2 2 2 1 2 2 1 2",
"output": "2 1\n3 4\n7 5\n6 9\n10 8"
},
{
"input": "5\n2 1 2 2 1 1 1 1 1 2",
"output": "3 1\n2 5\n7 6\n8 9\n10 4"
},
{
"inpu... | 1,686,132,668 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 35 | 498 | 75,468,800 | import string
from collections import deque
alph = string.ascii_lowercase
def main():
with open('input.txt', 'r') as fin:
f = fin.readlines()
n = int(f[0])
a = list(map(int, f[1].split()))
d = {i:0 for i in a}
for i in a:
d[i] += 1
flag = 1
for i in li... | Title: Cards with Numbers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya has got 2*n* cards, each card contains some integer. The numbers on the cards can be the same. Let's index all cards by consecutive integers from 1 to 2*n*. We'll denote the number that is written on a card wit... | ```python
import string
from collections import deque
alph = string.ascii_lowercase
def main():
with open('input.txt', 'r') as fin:
f = fin.readlines()
n = int(f[0])
a = list(map(int, f[1].split()))
d = {i:0 for i in a}
for i in a:
d[i] += 1
flag = 1
f... | 3 | |
233 | A | Perfect Permutation | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | A permutation is a sequence of integers *p*1,<=*p*2,<=...,<=*p**n*, consisting of *n* distinct positive integers, each of them doesn't exceed *n*. Let's denote the *i*-th element of permutation *p* as *p**i*. We'll call number *n* the size of permutation *p*1,<=*p*2,<=...,<=*p**n*.
Nickolas adores permutations. He lik... | A single line contains a single integer *n* (1<=β€<=*n*<=β€<=100) β the permutation size. | If a perfect permutation of size *n* doesn't exist, print a single integer -1. Otherwise print *n* distinct integers from 1 to *n*, *p*1,<=*p*2,<=...,<=*p**n* β permutation *p*, that is perfect. Separate printed numbers by whitespaces. | [
"1\n",
"2\n",
"4\n"
] | [
"-1\n",
"2 1 \n",
"2 1 4 3 \n"
] | none | 500 | [
{
"input": "1",
"output": "-1"
},
{
"input": "2",
"output": "2 1 "
},
{
"input": "4",
"output": "2 1 4 3 "
},
{
"input": "3",
"output": "-1"
},
{
"input": "5",
"output": "-1"
},
{
"input": "6",
"output": "2 1 4 3 6 5 "
},
{
"input": "7",
... | 1,634,081,550 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 154 | 6,758,400 | # import inbuilt standard input output
from sys import stdin, stdout
def main():
len_ = int(stdin.readline())
if len_%2 == 0:
str_ = []
for j in range(0, len_, 2):
str_.append(str(j + 2))
str_.append(str(j + 1))
string_ = " ".join(str_)
stdout.write(strin... | Title: Perfect Permutation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A permutation is a sequence of integers *p*1,<=*p*2,<=...,<=*p**n*, consisting of *n* distinct positive integers, each of them doesn't exceed *n*. Let's denote the *i*-th element of permutation *p* as *p**i*. We'll ... | ```python
# import inbuilt standard input output
from sys import stdin, stdout
def main():
len_ = int(stdin.readline())
if len_%2 == 0:
str_ = []
for j in range(0, len_, 2):
str_.append(str(j + 2))
str_.append(str(j + 1))
string_ = " ".join(str_)
stdout.w... | 3 | |
757 | B | Bash's Big Day | PROGRAMMING | 1,400 | [
"greedy",
"math",
"number theory"
] | null | null | Bash has set out on a journey to become the greatest Pokemon master. To get his first Pokemon, he went to Professor Zulu's Lab. Since Bash is Professor Zulu's favourite student, Zulu allows him to take as many Pokemon from his lab as he pleases.
But Zulu warns him that a group of *k*<=><=1 Pokemon with strengths {*... | The input consists of two lines.
The first line contains an integer *n* (1<=β€<=*n*<=β€<=105), the number of Pokemon in the lab.
The next line contains *n* space separated integers, where the *i*-th of them denotes *s**i* (1<=β€<=*s**i*<=β€<=105), the strength of the *i*-th Pokemon. | Print single integerΒ β the maximum number of Pokemons Bash can take. | [
"3\n2 3 4\n",
"5\n2 3 4 6 7\n"
] | [
"2\n",
"3\n"
] | *gcd* (greatest common divisor) of positive integers set {*a*<sub class="lower-index">1</sub>,β*a*<sub class="lower-index">2</sub>,β...,β*a*<sub class="lower-index">*n*</sub>} is the maximum positive integer that divides all the integers {*a*<sub class="lower-index">1</sub>,β*a*<sub class="lower-index">2</sub>,β...,β*a... | 1,000 | [
{
"input": "3\n2 3 4",
"output": "2"
},
{
"input": "5\n2 3 4 6 7",
"output": "3"
},
{
"input": "3\n5 6 4",
"output": "2"
},
{
"input": "8\n41 74 4 27 85 39 100 36",
"output": "4"
},
{
"input": "6\n89 20 86 81 62 23",
"output": "3"
},
{
"input": "71\n23... | 1,615,566,308 | 2,147,483,647 | PyPy 3 | OK | TESTS | 134 | 467 | 10,854,400 | from collections import defaultdict
n = int(input())
a = list(map(int,input().split()))
factors = defaultdict(int)
for i in range(n):
root = int(a[i]**0.5)
for j in range(2,root+1):
if a[i]%j==0:
factors[j]+=1
while a[i]%j==0:
a[i]//=j
if a[i]>1:
f... | Title: Bash's Big Day
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bash has set out on a journey to become the greatest Pokemon master. To get his first Pokemon, he went to Professor Zulu's Lab. Since Bash is Professor Zulu's favourite student, Zulu allows him to take as many Pokemon fr... | ```python
from collections import defaultdict
n = int(input())
a = list(map(int,input().split()))
factors = defaultdict(int)
for i in range(n):
root = int(a[i]**0.5)
for j in range(2,root+1):
if a[i]%j==0:
factors[j]+=1
while a[i]%j==0:
a[i]//=j
if a[i]>1:
... | 3 | |
465 | A | inc ARG | PROGRAMMING | 900 | [
"implementation"
] | null | null | Sergey is testing a next-generation processor. Instead of bytes the processor works with memory cells consisting of *n* bits. These bits are numbered from 1 to *n*. An integer is stored in the cell in the following way: the least significant bit is stored in the first bit of the cell, the next significant bit is stored... | The first line contains a single integer *n* (1<=β€<=*n*<=β€<=100) β the number of bits in the cell.
The second line contains a string consisting of *n* characters β the initial state of the cell. The first character denotes the state of the first bit of the cell. The second character denotes the second least significan... | Print a single integer β the number of bits in the cell which change their state after we add 1 to the cell. | [
"4\n1100\n",
"4\n1111\n"
] | [
"3\n",
"4\n"
] | In the first sample the cell ends up with value 0010, in the second sample β with 0000. | 500 | [
{
"input": "4\n1100",
"output": "3"
},
{
"input": "4\n1111",
"output": "4"
},
{
"input": "1\n0",
"output": "1"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "2\n00",
"output": "1"
},
{
"input": "2\n01",
"output": "1"
},
{
"input": "2\n1... | 1,633,950,364 | 2,147,483,647 | Python 3 | OK | TESTS | 29 | 61 | 6,963,200 | n = int(input())
s = input()
change = 0
in_hand = 1
for i in range(n):
if (int(s[i]) + in_hand) == 0:
pass
elif (int(s[i]) + in_hand) == 1 and s[i] == "1":
pass
elif (int(s[i]) + in_hand) == 1 and in_hand == 1:
in_hand = 0
change += 1
else:
change... | Title: inc ARG
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Sergey is testing a next-generation processor. Instead of bytes the processor works with memory cells consisting of *n* bits. These bits are numbered from 1 to *n*. An integer is stored in the cell in the following way: the lea... | ```python
n = int(input())
s = input()
change = 0
in_hand = 1
for i in range(n):
if (int(s[i]) + in_hand) == 0:
pass
elif (int(s[i]) + in_hand) == 1 and s[i] == "1":
pass
elif (int(s[i]) + in_hand) == 1 and in_hand == 1:
in_hand = 0
change += 1
else:
... | 3 | |
4 | A | Watermelon | PROGRAMMING | 800 | [
"brute force",
"math"
] | A. Watermelon | 1 | 64 | One hot summer day Pete and his friend Billy decided to buy a watermelon. They chose the biggest and the ripest one, in their opinion. After that the watermelon was weighed, and the scales showed *w* kilos. They rushed home, dying of thirst, and decided to divide the berry, however they faced a hard problem.
Pete and ... | The first (and the only) input line contains integer number *w* (1<=β€<=*w*<=β€<=100) β the weight of the watermelon bought by the boys. | Print YES, if the boys can divide the watermelon into two parts, each of them weighing even number of kilos; and NO in the opposite case. | [
"8\n"
] | [
"YES\n"
] | For example, the boys can divide the watermelon into two parts of 2 and 6 kilos respectively (another variant β two parts of 4 and 4 kilos). | 0 | [
{
"input": "8",
"output": "YES"
},
{
"input": "5",
"output": "NO"
},
{
"input": "4",
"output": "YES"
},
{
"input": "3",
"output": "NO"
},
{
"input": "2",
"output": "NO"
},
{
"input": "1",
"output": "NO"
},
{
"input": "7",
"output": "NO"... | 1,686,974,575 | 2,147,483,647 | Python 3 | OK | TESTS | 20 | 92 | 0 | def can_divide_watermelon(w):
# Check if the weight is even and greater than 2
if w % 2 == 0 and w > 2:
return "YES"
else:
return "NO"
# Get the input weight of the watermelon
w = int(input())
# Check if the watermelon can be divided as desired
result = can_divide_watermelon(w)
# Print th... | Title: Watermelon
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
One hot summer day Pete and his friend Billy decided to buy a watermelon. They chose the biggest and the ripest one, in their opinion. After that the watermelon was weighed, and the scales showed *w* kilos. They rushed home, dyin... | ```python
def can_divide_watermelon(w):
# Check if the weight is even and greater than 2
if w % 2 == 0 and w > 2:
return "YES"
else:
return "NO"
# Get the input weight of the watermelon
w = int(input())
# Check if the watermelon can be divided as desired
result = can_divide_watermelon(w)
... | 3.954 |
776 | A | A Serial Killer | PROGRAMMING | 900 | [
"brute force",
"implementation",
"strings"
] | null | null | Our beloved detective, Sherlock is currently trying to catch a serial killer who kills a person each day. Using his powers of deduction, he came to know that the killer has a strategy for selecting his next victim.
The killer starts with two potential victims on his first day, selects one of these two, kills selected ... | First line of input contains two names (length of each of them doesn't exceed 10), the two initials potential victims. Next line contains integer *n* (1<=β€<=*n*<=β€<=1000), the number of days.
Next *n* lines contains two names (length of each of them doesn't exceed 10), first being the person murdered on this day and t... | Output *n*<=+<=1 lines, the *i*-th line should contain the two persons from which the killer selects for the *i*-th murder. The (*n*<=+<=1)-th line should contain the two persons from which the next victim is selected. In each line, the two names can be printed in any order. | [
"ross rachel\n4\nross joey\nrachel phoebe\nphoebe monica\nmonica chandler\n",
"icm codeforces\n1\ncodeforces technex\n"
] | [
"ross rachel\njoey rachel\njoey phoebe\njoey monica\njoey chandler\n",
"icm codeforces\nicm technex\n"
] | In first example, the killer starts with ross and rachel.
- After day 1, ross is killed and joey appears. - After day 2, rachel is killed and phoebe appears. - After day 3, phoebe is killed and monica appears. - After day 4, monica is killed and chandler appears. | 500 | [
{
"input": "ross rachel\n4\nross joey\nrachel phoebe\nphoebe monica\nmonica chandler",
"output": "ross rachel\njoey rachel\njoey phoebe\njoey monica\njoey chandler"
},
{
"input": "icm codeforces\n1\ncodeforces technex",
"output": "icm codeforces\nicm technex"
},
{
"input": "a b\n3\na c\n... | 1,530,190,368 | 468 | Python 3 | OK | TESTS | 57 | 108 | 0 | a, b = input().split(' ')
n = int(input())
print(a, b)
for i in range(n):
c, d = input().split(' ')
if c == a:
a = d
else:
b = d
print(a, b)
| Title: A Serial Killer
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Our beloved detective, Sherlock is currently trying to catch a serial killer who kills a person each day. Using his powers of deduction, he came to know that the killer has a strategy for selecting his next victim.
The... | ```python
a, b = input().split(' ')
n = int(input())
print(a, b)
for i in range(n):
c, d = input().split(' ')
if c == a:
a = d
else:
b = d
print(a, b)
``` | 3 | |
551 | A | GukiZ and Contest | PROGRAMMING | 800 | [
"brute force",
"implementation",
"sortings"
] | null | null | Professor GukiZ likes programming contests. He especially likes to rate his students on the contests he prepares. Now, he has decided to prepare a new contest.
In total, *n* students will attend, and before the start, every one of them has some positive integer rating. Students are indexed from 1 to *n*. Let's denote... | The first line contains integer *n* (1<=β€<=*n*<=β€<=2000), number of GukiZ's students.
The second line contains *n* numbers *a*1,<=*a*2,<=... *a**n* (1<=β€<=*a**i*<=β€<=2000) where *a**i* is the rating of *i*-th student (1<=β€<=*i*<=β€<=*n*). | In a single line, print the position after the end of the contest for each of *n* students in the same order as they appear in the input. | [
"3\n1 3 3\n",
"1\n1\n",
"5\n3 5 3 4 5\n"
] | [
"3 1 1\n",
"1\n",
"4 1 4 3 1\n"
] | In the first sample, students 2 and 3 are positioned first (there is no other student with higher rating), and student 1 is positioned third since there are two students with higher rating.
In the second sample, first student is the only one on the contest.
In the third sample, students 2 and 5 share the first positi... | 500 | [
{
"input": "3\n1 3 3",
"output": "3 1 1"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "5\n3 5 3 4 5",
"output": "4 1 4 3 1"
},
{
"input": "7\n1 3 5 4 2 2 1",
"output": "6 3 1 2 4 4 6"
},
{
"input": "11\n5 6 4 2 9 7 6 6 6 6 7",
"output": "9 4 10 11 1 2 4 4... | 1,619,871,237 | 2,147,483,647 | Python 3 | OK | TESTS | 36 | 1,123 | 102,400 | from sys import stdin
n=int(stdin.readline())
a=[int(x) for x in stdin.readline().split()]
for i in range(n):
c=0
for j in range(n):
if a[i]<a[j]:
c+=1
print(c+1,end=" ")
| Title: GukiZ and Contest
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Professor GukiZ likes programming contests. He especially likes to rate his students on the contests he prepares. Now, he has decided to prepare a new contest.
In total, *n* students will attend, and before the star... | ```python
from sys import stdin
n=int(stdin.readline())
a=[int(x) for x in stdin.readline().split()]
for i in range(n):
c=0
for j in range(n):
if a[i]<a[j]:
c+=1
print(c+1,end=" ")
``` | 3 | |
785 | A | Anton and Polyhedrons | PROGRAMMING | 800 | [
"implementation",
"strings"
] | null | null | Anton's favourite geometric figures are regular polyhedrons. Note that there are five kinds of regular polyhedrons:
- Tetrahedron. Tetrahedron has 4 triangular faces. - Cube. Cube has 6 square faces. - Octahedron. Octahedron has 8 triangular faces. - Dodecahedron. Dodecahedron has 12 pentagonal faces. - Icosahed... | The first line of the input contains a single integer *n* (1<=β€<=*n*<=β€<=200<=000)Β β the number of polyhedrons in Anton's collection.
Each of the following *n* lines of the input contains a string *s**i*Β β the name of the *i*-th polyhedron in Anton's collection. The string can look like this:
- "Tetrahedron" (withou... | Output one numberΒ β the total number of faces in all the polyhedrons in Anton's collection. | [
"4\nIcosahedron\nCube\nTetrahedron\nDodecahedron\n",
"3\nDodecahedron\nOctahedron\nOctahedron\n"
] | [
"42\n",
"28\n"
] | In the first sample Anton has one icosahedron, one cube, one tetrahedron and one dodecahedron. Icosahedron has 20 faces, cube has 6 faces, tetrahedron has 4 faces and dodecahedron has 12 faces. In total, they have 20β+β6β+β4β+β12β=β42 faces. | 500 | [
{
"input": "4\nIcosahedron\nCube\nTetrahedron\nDodecahedron",
"output": "42"
},
{
"input": "3\nDodecahedron\nOctahedron\nOctahedron",
"output": "28"
},
{
"input": "25\nIcosahedron\nOctahedron\nTetrahedron\nDodecahedron\nCube\nIcosahedron\nOctahedron\nCube\nTetrahedron\nIcosahedron\nIcosa... | 1,674,982,934 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 296 | 0 | n = int(input().strip())
cnt = 0
for i in range(n):
s = input().strip()
if s == "Icosahedron":
cnt += 20
if s == "Cube":
cnt += 6
if s == "Tetrahedron":
cnt += 4
if s == "Dodecahedron":
cnt += 12
if s == "Octahedron":
cnt += 8
print(cnt)
| Title: Anton and Polyhedrons
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Anton's favourite geometric figures are regular polyhedrons. Note that there are five kinds of regular polyhedrons:
- Tetrahedron. Tetrahedron has 4 triangular faces. - Cube. Cube has 6 square faces. - Octahe... | ```python
n = int(input().strip())
cnt = 0
for i in range(n):
s = input().strip()
if s == "Icosahedron":
cnt += 20
if s == "Cube":
cnt += 6
if s == "Tetrahedron":
cnt += 4
if s == "Dodecahedron":
cnt += 12
if s == "Octahedron":
cnt += 8
print(cnt)
``` | 3 | |
912 | B | New Year's Eve | PROGRAMMING | 1,300 | [
"bitmasks",
"constructive algorithms",
"number theory"
] | null | null | Since Grisha behaved well last year, at New Year's Eve he was visited by Ded Moroz who brought an enormous bag of gifts with him! The bag contains *n* sweet candies from the good ol' bakery, each labeled from 1 to *n* corresponding to its tastiness. No two candies have the same tastiness.
The choice of candies has a d... | The sole string contains two integers *n* and *k* (1<=β€<=*k*<=β€<=*n*<=β€<=1018). | Output one numberΒ β the largest possible xor-sum. | [
"4 3\n",
"6 6\n"
] | [
"7\n",
"7\n"
] | In the first sample case, one optimal answer is 1, 2 and 4, giving the xor-sum of 7.
In the second sample case, one can, for example, take all six candies and obtain the xor-sum of 7. | 1,000 | [
{
"input": "4 3",
"output": "7"
},
{
"input": "6 6",
"output": "7"
},
{
"input": "2 2",
"output": "3"
},
{
"input": "1022 10",
"output": "1023"
},
{
"input": "415853337373441 52",
"output": "562949953421311"
},
{
"input": "75 12",
"output": "127"
... | 1,656,389,029 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 58 | 109 | 512,000 | import sys
input = sys.stdin.readline
n, k = map(int, input().split())
if(k == 1):
print(n)
exit()
for i in range(61, -1, -1):
c = 1 << i
if(n & c):
break
print(2 * c - 1)
| Title: New Year's Eve
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Since Grisha behaved well last year, at New Year's Eve he was visited by Ded Moroz who brought an enormous bag of gifts with him! The bag contains *n* sweet candies from the good ol' bakery, each labeled from 1 to *n* co... | ```python
import sys
input = sys.stdin.readline
n, k = map(int, input().split())
if(k == 1):
print(n)
exit()
for i in range(61, -1, -1):
c = 1 << i
if(n & c):
break
print(2 * c - 1)
``` | 3 | |
443 | A | Anton and Letters | PROGRAMMING | 800 | [
"constructive algorithms",
"implementation"
] | null | null | Recently, Anton has found a set. The set consists of small English letters. Anton carefully wrote out all the letters from the set in one line, separated by a comma. He also added an opening curved bracket at the beginning of the line and a closing curved bracket at the end of the line.
Unfortunately, from time to ti... | The first and the single line contains the set of letters. The length of the line doesn't exceed 1000. It is guaranteed that the line starts from an opening curved bracket and ends with a closing curved bracket. Between them, small English letters are listed, separated by a comma. Each comma is followed by a space. | Print a single number β the number of distinct letters in Anton's set. | [
"{a, b, c}\n",
"{b, a, b, a}\n",
"{}\n"
] | [
"3\n",
"2\n",
"0\n"
] | none | 500 | [
{
"input": "{a, b, c}",
"output": "3"
},
{
"input": "{b, a, b, a}",
"output": "2"
},
{
"input": "{}",
"output": "0"
},
{
"input": "{a, a, c, b, b, b, c, c, c, c}",
"output": "3"
},
{
"input": "{a, c, b, b}",
"output": "3"
},
{
"input": "{a, b}",
"o... | 1,688,464,057 | 2,147,483,647 | Python 3 | OK | TESTS | 27 | 46 | 0 | s = input()
l = []
for i in s:
if i != '{' and i != '}' and i != ' ' and i != ',':
l.append(i)
c = 0
print(len(set(l))) | Title: Anton and Letters
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Recently, Anton has found a set. The set consists of small English letters. Anton carefully wrote out all the letters from the set in one line, separated by a comma. He also added an opening curved bracket at the begi... | ```python
s = input()
l = []
for i in s:
if i != '{' and i != '}' and i != ' ' and i != ',':
l.append(i)
c = 0
print(len(set(l)))
``` | 3 | |
29 | A | Spit Problem | PROGRAMMING | 1,000 | [
"brute force"
] | A. Spit Problem | 2 | 256 | In a Berland's zoo there is an enclosure with camels. It is known that camels like to spit. Bob watched these interesting animals for the whole day and registered in his notepad where each animal spitted. Now he wants to know if in the zoo there are two camels, which spitted at each other. Help him to solve this task.
... | The first line contains integer *n* (1<=β€<=*n*<=β€<=100) β the amount of camels in the zoo. Each of the following *n* lines contains two integers *x**i* and *d**i* (<=-<=104<=β€<=*x**i*<=β€<=104,<=1<=β€<=|*d**i*|<=β€<=2Β·104) β records in Bob's notepad. *x**i* is a position of the *i*-th camel, and *d**i* is a distance at wh... | If there are two camels, which spitted at each other, output YES. Otherwise, output NO. | [
"2\n0 1\n1 -1\n",
"3\n0 1\n1 1\n2 -2\n",
"5\n2 -10\n3 10\n0 5\n5 -5\n10 1\n"
] | [
"YES\n",
"NO\n",
"YES\n"
] | none | 500 | [
{
"input": "2\n0 1\n1 -1",
"output": "YES"
},
{
"input": "3\n0 1\n1 1\n2 -2",
"output": "NO"
},
{
"input": "5\n2 -10\n3 10\n0 5\n5 -5\n10 1",
"output": "YES"
},
{
"input": "10\n-9897 -1144\n-4230 -6350\n2116 -3551\n-3635 4993\n3907 -9071\n-2362 4120\n-6542 984\n5807 3745\n759... | 1,595,796,375 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 218 | 6,656,000 | # -*- coding: utf-8 -*-
lista,dist,cont = [],[],0
n = int(input())
for i in range(n):
x,y = map(int,input().split())
lista.append(x)
dist.append(x+y)
for i in range(n):
if dist[i] in lista:
if lista[i] == dist[lista.index(dist[i])]: cont = 1; break
if cont == 0: print('NO')
el... | 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
# -*- coding: utf-8 -*-
lista,dist,cont = [],[],0
n = int(input())
for i in range(n):
x,y = map(int,input().split())
lista.append(x)
dist.append(x+y)
for i in range(n):
if dist[i] in lista:
if lista[i] == dist[lista.index(dist[i])]: cont = 1; break
if cont == 0: print... | 3.933102 |
557 | A | Ilya and Diplomas | PROGRAMMING | 1,100 | [
"greedy",
"implementation",
"math"
] | null | null | Soon a school Olympiad in Informatics will be held in Berland, *n* schoolchildren will participate there.
At a meeting of the jury of the Olympiad it was decided that each of the *n* participants, depending on the results, will get a diploma of the first, second or third degree. Thus, each student will receive exactly... | The first line of the input contains a single integer *n* (3<=β€<=*n*<=β€<=3Β·106)Β βΒ the number of schoolchildren who will participate in the Olympiad.
The next line of the input contains two integers *min*1 and *max*1 (1<=β€<=*min*1<=β€<=*max*1<=β€<=106)Β βΒ the minimum and maximum limits on the number of diplomas of the fir... | In the first line of the output print three numbers, showing how many diplomas of the first, second and third degree will be given to students in the optimal variant of distributing diplomas.
The optimal variant of distributing diplomas is the one that maximizes the number of students who receive diplomas of the first... | [
"6\n1 5\n2 6\n3 7\n",
"10\n1 2\n1 3\n1 5\n",
"6\n1 3\n2 2\n2 2\n"
] | [
"1 2 3 \n",
"2 3 5 \n",
"2 2 2 \n"
] | none | 500 | [
{
"input": "6\n1 5\n2 6\n3 7",
"output": "1 2 3 "
},
{
"input": "10\n1 2\n1 3\n1 5",
"output": "2 3 5 "
},
{
"input": "6\n1 3\n2 2\n2 2",
"output": "2 2 2 "
},
{
"input": "55\n1 1000000\n40 50\n10 200",
"output": "5 40 10 "
},
{
"input": "3\n1 1\n1 1\n1 1",
"o... | 1,435,676,980 | 580 | Python 3 | OK | TESTS | 56 | 155 | 6,348,800 | import math,string,itertools,fractions,heapq,collections,re,array,bisect,copy
from itertools import chain, dropwhile, permutations, combinations
from collections import defaultdict, deque
# Guide:
# 1. construct complex data types while reading (e.g. graph adj list)
# 2. avoid any non-necessary time/memory usage
#... | Title: Ilya and Diplomas
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Soon a school Olympiad in Informatics will be held in Berland, *n* schoolchildren will participate there.
At a meeting of the jury of the Olympiad it was decided that each of the *n* participants, depending on the re... | ```python
import math,string,itertools,fractions,heapq,collections,re,array,bisect,copy
from itertools import chain, dropwhile, permutations, combinations
from collections import defaultdict, deque
# Guide:
# 1. construct complex data types while reading (e.g. graph adj list)
# 2. avoid any non-necessary time/memo... | 3 | |
119 | A | Epic Game | PROGRAMMING | 800 | [
"implementation"
] | null | null | Simon and Antisimon play a game. Initially each player receives one fixed positive integer that doesn't change throughout the game. Simon receives number *a* and Antisimon receives number *b*. They also have a heap of *n* stones. The players take turns to make a move and Simon starts. During a move a player should take... | The only string contains space-separated integers *a*, *b* and *n* (1<=β€<=*a*,<=*b*,<=*n*<=β€<=100) β the fixed numbers Simon and Antisimon have received correspondingly and the initial number of stones in the pile. | If Simon wins, print "0" (without the quotes), otherwise print "1" (without the quotes). | [
"3 5 9\n",
"1 1 100\n"
] | [
"0",
"1"
] | The greatest common divisor of two non-negative integers *a* and *b* is such maximum positive integer *k*, that *a* is divisible by *k* without remainder and similarly, *b* is divisible by *k* without remainder. Let *gcd*(*a*,β*b*) represent the operation of calculating the greatest common divisor of numbers *a* and *b... | 500 | [
{
"input": "3 5 9",
"output": "0"
},
{
"input": "1 1 100",
"output": "1"
},
{
"input": "23 12 16",
"output": "1"
},
{
"input": "95 26 29",
"output": "1"
},
{
"input": "73 32 99",
"output": "1"
},
{
"input": "1 1 1",
"output": "0"
},
{
"inpu... | 1,600,965,284 | 2,147,483,647 | Python 3 | OK | TESTS | 45 | 218 | 0 | """
Solution to Codeforces Problem 119A : https://codeforces.com/problemset/problem/119/A
"""
import math
def solve(a, b, n):
while 0 < n:
for ix, value in enumerate([a, b]):
n -= math.gcd(value, n)
if n == 0:
print(ix)
if __name__ == "__main__":
... | Title: Epic Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Simon and Antisimon play a game. Initially each player receives one fixed positive integer that doesn't change throughout the game. Simon receives number *a* and Antisimon receives number *b*. They also have a heap of *n* sto... | ```python
"""
Solution to Codeforces Problem 119A : https://codeforces.com/problemset/problem/119/A
"""
import math
def solve(a, b, n):
while 0 < n:
for ix, value in enumerate([a, b]):
n -= math.gcd(value, n)
if n == 0:
print(ix)
if __name__ == "__ma... | 3 | |
363 | B | Fence | PROGRAMMING | 1,100 | [
"brute force",
"dp"
] | null | null | There is a fence in front of Polycarpus's home. The fence consists of *n* planks of the same width which go one after another from left to right. The height of the *i*-th plank is *h**i* meters, distinct planks can have distinct heights.
Polycarpus has bought a posh piano and is thinking about how to get it into the h... | The first line of the input contains integers *n* and *k* (1<=β€<=*n*<=β€<=1.5Β·105,<=1<=β€<=*k*<=β€<=*n*) β the number of planks in the fence and the width of the hole for the piano. The second line contains the sequence of integers *h*1,<=*h*2,<=...,<=*h**n* (1<=β€<=*h**i*<=β€<=100), where *h**i* is the height of the *i*-th... | Print such integer *j* that the sum of the heights of planks *j*, *j*<=+<=1, ..., *j*<=+<=*k*<=-<=1 is the minimum possible. If there are multiple such *j*'s, print any of them. | [
"7 3\n1 2 6 1 1 7 1\n"
] | [
"3\n"
] | In the sample, your task is to find three consecutive planks with the minimum sum of heights. In the given case three planks with indexes 3, 4 and 5 have the required attribute, their total height is 8. | 1,000 | [
{
"input": "7 3\n1 2 6 1 1 7 1",
"output": "3"
},
{
"input": "1 1\n100",
"output": "1"
},
{
"input": "2 1\n10 20",
"output": "1"
},
{
"input": "10 5\n1 2 3 1 2 2 3 1 4 5",
"output": "1"
},
{
"input": "10 2\n3 1 4 1 4 6 2 1 4 6",
"output": "7"
},
{
"inp... | 1,687,377,345 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 51 | 108 | 19,046,400 | #author: sushmanth
from sys import stdin
input = stdin.readline
inp = lambda : list(map(int,input().split()))
def answer():
s = 0
for i in range(k):
s += a[i]
ans , index = s , 1
for i in range(k , n):
s -= a[i - k]
s += a[i]
if(ans > s):
... | Title: Fence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There is a fence in front of Polycarpus's home. The fence consists of *n* planks of the same width which go one after another from left to right. The height of the *i*-th plank is *h**i* meters, distinct planks can have distinct ... | ```python
#author: sushmanth
from sys import stdin
input = stdin.readline
inp = lambda : list(map(int,input().split()))
def answer():
s = 0
for i in range(k):
s += a[i]
ans , index = s , 1
for i in range(k , n):
s -= a[i - k]
s += a[i]
if(ans > s):... | 3 | |
678 | A | Johny Likes Numbers | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | Johny likes numbers *n* and *k* very much. Now Johny wants to find the smallest integer *x* greater than *n*, so it is divisible by the number *k*. | The only line contains two integers *n* and *k* (1<=β€<=*n*,<=*k*<=β€<=109). | Print the smallest integer *x*<=><=*n*, so it is divisible by the number *k*. | [
"5 3\n",
"25 13\n",
"26 13\n"
] | [
"6\n",
"26\n",
"39\n"
] | none | 0 | [
{
"input": "5 3",
"output": "6"
},
{
"input": "25 13",
"output": "26"
},
{
"input": "26 13",
"output": "39"
},
{
"input": "1 1",
"output": "2"
},
{
"input": "8 8",
"output": "16"
},
{
"input": "14 15",
"output": "15"
},
{
"input": "197 894"... | 1,632,933,109 | 2,147,483,647 | PyPy 3 | OK | TESTS | 37 | 108 | 20,172,800 | n,k=map(int,input().split())
print(((n+1)//k+((n+1)%k>0))*k)
| Title: Johny Likes Numbers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Johny likes numbers *n* and *k* very much. Now Johny wants to find the smallest integer *x* greater than *n*, so it is divisible by the number *k*.
Input Specification:
The only line contains two integers *n* and *... | ```python
n,k=map(int,input().split())
print(((n+1)//k+((n+1)%k>0))*k)
``` | 3 | |
545 | C | Woodcutters | PROGRAMMING | 1,500 | [
"dp",
"greedy"
] | null | null | Little Susie listens to fairy tales before bed every day. Today's fairy tale was about wood cutters and the little girl immediately started imagining the choppers cutting wood. She imagined the situation that is described below.
There are *n* trees located along the road at points with coordinates *x*1,<=*x*2,<=...,<=... | The first line contains integer *n* (1<=β€<=*n*<=β€<=105) β the number of trees.
Next *n* lines contain pairs of integers *x**i*,<=*h**i* (1<=β€<=*x**i*,<=*h**i*<=β€<=109) β the coordinate and the height of the *Ρ*-th tree.
The pairs are given in the order of ascending *x**i*. No two trees are located at the point with t... | Print a single number β the maximum number of trees that you can cut down by the given rules. | [
"5\n1 2\n2 1\n5 10\n10 9\n19 1\n",
"5\n1 2\n2 1\n5 10\n10 9\n20 1\n"
] | [
"3\n",
"4\n"
] | In the first sample you can fell the trees like that:
- fell the 1-st tree to the left β now it occupies segment [β-β1;1] - fell the 2-nd tree to the right β now it occupies segment [2;3] - leave the 3-rd tree β it occupies point 5 - leave the 4-th tree β it occupies point 10 - fell the 5-th tree to the right β ... | 1,750 | [
{
"input": "5\n1 2\n2 1\n5 10\n10 9\n19 1",
"output": "3"
},
{
"input": "5\n1 2\n2 1\n5 10\n10 9\n20 1",
"output": "4"
},
{
"input": "4\n10 4\n15 1\n19 3\n20 1",
"output": "4"
},
{
"input": "35\n1 7\n3 11\n6 12\n7 6\n8 5\n9 11\n15 3\n16 10\n22 2\n23 3\n25 7\n27 3\n34 5\n35 10... | 1,679,820,327 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 67 | 108 | 3,993,600 | from sys import stdin,stdout
input,print = stdin.readline,stdout.write
n=int(input())
back=-10**9
prev=-1
count=0
for i in range(n):
pos,curr=map(int,input().split())
#print(str(back),str(prev),str(pos),str(curr),str(count))
dist=pos-back
if prev==-1:
if curr<dist:
coun... | Title: Woodcutters
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Susie listens to fairy tales before bed every day. Today's fairy tale was about wood cutters and the little girl immediately started imagining the choppers cutting wood. She imagined the situation that is described b... | ```python
from sys import stdin,stdout
input,print = stdin.readline,stdout.write
n=int(input())
back=-10**9
prev=-1
count=0
for i in range(n):
pos,curr=map(int,input().split())
#print(str(back),str(prev),str(pos),str(curr),str(count))
dist=pos-back
if prev==-1:
if curr<dist:
... | 3 | |
371 | A | K-Periodic Array | PROGRAMMING | 1,000 | [
"greedy",
"implementation",
"math"
] | null | null | This task will exclusively concentrate only on the arrays where all elements equal 1 and/or 2.
Array *a* is *k*-period if its length is divisible by *k* and there is such array *b* of length *k*, that *a* is represented by array *b* written exactly times consecutively. In other words, array *a* is *k*-periodic, if it... | The first line of the input contains a pair of integers *n*, *k* (1<=β€<=*k*<=β€<=*n*<=β€<=100), where *n* is the length of the array and the value *n* is divisible by *k*. The second line contains the sequence of elements of the given array *a*1,<=*a*2,<=...,<=*a**n* (1<=β€<=*a**i*<=β€<=2), *a**i* is the *i*-th element of ... | Print the minimum number of array elements we need to change to make the array *k*-periodic. If the array already is *k*-periodic, then print 0. | [
"6 2\n2 1 2 2 2 1\n",
"8 4\n1 1 2 1 1 1 2 1\n",
"9 3\n2 1 1 1 2 1 1 1 2\n"
] | [
"1\n",
"0\n",
"3\n"
] | In the first sample it is enough to change the fourth element from 2 to 1, then the array changes to [2,β1,β2,β1,β2,β1].
In the second sample, the given array already is 4-periodic.
In the third sample it is enough to replace each occurrence of number two by number one. In this case the array will look as [1,β1,β1,β1... | 500 | [
{
"input": "6 2\n2 1 2 2 2 1",
"output": "1"
},
{
"input": "8 4\n1 1 2 1 1 1 2 1",
"output": "0"
},
{
"input": "9 3\n2 1 1 1 2 1 1 1 2",
"output": "3"
},
{
"input": "1 1\n2",
"output": "0"
},
{
"input": "2 1\n1 1",
"output": "0"
},
{
"input": "2 2\n2 2... | 1,661,538,055 | 2,147,483,647 | Python 3 | OK | TESTS | 24 | 46 | 0 | def contarMudancas(n, k):
vetor = list(map(int, input().split(' ')))
cont1 = []
cont2 = []
for i in range(k):
cont1.append(0)
cont2.append(0)
for i in range(n):
if vetor[i] == 1:
cont1[i % k] += 1
else:
cont2[i % k] += 1
minMudancas = 0
... | Title: K-Periodic Array
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
This task will exclusively concentrate only on the arrays where all elements equal 1 and/or 2.
Array *a* is *k*-period if its length is divisible by *k* and there is such array *b* of length *k*, that *a* is represent... | ```python
def contarMudancas(n, k):
vetor = list(map(int, input().split(' ')))
cont1 = []
cont2 = []
for i in range(k):
cont1.append(0)
cont2.append(0)
for i in range(n):
if vetor[i] == 1:
cont1[i % k] += 1
else:
cont2[i % k] += 1
minMudanc... | 3 | |
765 | E | Tree Folding | PROGRAMMING | 2,200 | [
"dfs and similar",
"dp",
"greedy",
"implementation",
"trees"
] | null | null | Vanya wants to minimize a tree. He can perform the following operation multiple times: choose a vertex *v*, and two disjoint (except for *v*) paths of equal length *a*0<==<=*v*, *a*1, ..., *a**k*, and *b*0<==<=*v*, *b*1, ..., *b**k*. Additionally, vertices *a*1, ..., *a**k*, *b*1, ..., *b**k* must not have any neighbou... | The first line of input contains the number of vertices *n* (2<=β€<=*n*<=β€<=2Β·105).
Next *n*<=-<=1 lines describe edges of the tree. Each of these lines contains two space-separated integers *u* and *v* (1<=β€<=*u*,<=*v*<=β€<=*n*, *u*<=β <=*v*)Β β indices of endpoints of the corresponding edge. It is guaranteed that the gi... | If it is impossible to obtain a path, print -1. Otherwise, print the minimum number of edges in a possible path. | [
"6\n1 2\n2 3\n2 4\n4 5\n1 6\n",
"7\n1 2\n1 3\n3 4\n1 5\n5 6\n6 7\n"
] | [
"3\n",
"-1\n"
] | In the first sample case, a path of three edges is obtained after merging paths 2β-β1β-β6 and 2β-β4β-β5.
It is impossible to perform any operation in the second sample case. For example, it is impossible to merge paths 1β-β3β-β4 and 1β-β5β-β6, since vertex 6 additionally has a neighbour 7 that is not present in the co... | 2,500 | [
{
"input": "6\n1 2\n2 3\n2 4\n4 5\n1 6",
"output": "3"
},
{
"input": "7\n1 2\n1 3\n3 4\n1 5\n5 6\n6 7",
"output": "-1"
},
{
"input": "2\n1 2",
"output": "1"
},
{
"input": "3\n3 1\n1 2",
"output": "1"
},
{
"input": "10\n5 10\n7 8\n8 3\n2 6\n3 2\n9 7\n4 5\n10 1\n6 4... | 1,681,926,453 | 5,553 | PyPy 3 | OK | TESTS | 54 | 904 | 82,534,400 | import sys, os, io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
n = int(input())
G = [set() for _ in range(n + 1)]
for _ in range(n - 1):
u, v = map(int, input().split())
G[u].add(v)
G[v].add(u)
q = []
x = [set() for _ in range(n + 1)]
cnt = [len(g) for g in G]
for i in range(1,... | Title: Tree Folding
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vanya wants to minimize a tree. He can perform the following operation multiple times: choose a vertex *v*, and two disjoint (except for *v*) paths of equal length *a*0<==<=*v*, *a*1, ..., *a**k*, and *b*0<==<=*v*, *b*1, .... | ```python
import sys, os, io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
n = int(input())
G = [set() for _ in range(n + 1)]
for _ in range(n - 1):
u, v = map(int, input().split())
G[u].add(v)
G[v].add(u)
q = []
x = [set() for _ in range(n + 1)]
cnt = [len(g) for g in G]
for i i... | 3 | |
581 | A | Vasya the Hipster | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | One day Vasya the Hipster decided to count how many socks he had. It turned out that he had *a* red socks and *b* blue socks.
According to the latest fashion, hipsters should wear the socks of different colors: a red one on the left foot, a blue one on the right foot.
Every day Vasya puts on new socks in the morning ... | The single line of the input contains two positive integers *a* and *b* (1<=β€<=*a*,<=*b*<=β€<=100) β the number of red and blue socks that Vasya's got. | Print two space-separated integers β the maximum number of days when Vasya can wear different socks and the number of days when he can wear the same socks until he either runs out of socks or cannot make a single pair from the socks he's got.
Keep in mind that at the end of the day Vasya throws away the socks that he'... | [
"3 1\n",
"2 3\n",
"7 3\n"
] | [
"1 1\n",
"2 0\n",
"3 2\n"
] | In the first sample Vasya can first put on one pair of different socks, after that he has two red socks left to wear on the second day. | 500 | [
{
"input": "3 1",
"output": "1 1"
},
{
"input": "2 3",
"output": "2 0"
},
{
"input": "7 3",
"output": "3 2"
},
{
"input": "100 100",
"output": "100 0"
},
{
"input": "4 10",
"output": "4 3"
},
{
"input": "6 10",
"output": "6 2"
},
{
"input":... | 1,662,631,552 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 46 | 0 | m,n=sorted(map(int,input().split()));print(m,(n-m)//2) | Title: Vasya the Hipster
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day Vasya the Hipster decided to count how many socks he had. It turned out that he had *a* red socks and *b* blue socks.
According to the latest fashion, hipsters should wear the socks of different colors: a red... | ```python
m,n=sorted(map(int,input().split()));print(m,(n-m)//2)
``` | 3 | |
16 | B | Burglar and Matches | PROGRAMMING | 900 | [
"greedy",
"implementation",
"sortings"
] | B. Burglar and Matches | 0 | 64 | A burglar got into a matches warehouse and wants to steal as many matches as possible. In the warehouse there are *m* containers, in the *i*-th container there are *a**i* matchboxes, and each matchbox contains *b**i* matches. All the matchboxes are of the same size. The burglar's rucksack can hold *n* matchboxes exactl... | The first line of the input contains integer *n* (1<=β€<=*n*<=β€<=2Β·108) and integer *m* (1<=β€<=*m*<=β€<=20). The *i*<=+<=1-th line contains a pair of numbers *a**i* and *b**i* (1<=β€<=*a**i*<=β€<=108,<=1<=β€<=*b**i*<=β€<=10). All the input numbers are integer. | Output the only number β answer to the problem. | [
"7 3\n5 10\n2 5\n3 6\n",
"3 3\n1 3\n2 2\n3 1\n"
] | [
"62\n",
"7\n"
] | none | 0 | [
{
"input": "7 3\n5 10\n2 5\n3 6",
"output": "62"
},
{
"input": "3 3\n1 3\n2 2\n3 1",
"output": "7"
},
{
"input": "1 1\n1 2",
"output": "2"
},
{
"input": "1 2\n1 9\n1 6",
"output": "9"
},
{
"input": "1 10\n1 1\n1 9\n1 3\n1 9\n1 7\n1 10\n1 4\n1 7\n1 3\n1 1",
"ou... | 1,584,631,281 | 2,147,483,647 | Python 3 | OK | TESTS | 49 | 218 | 307,200 |
n,m=map(int,input().split())
l=[]
for i in range(m):
x,y=map(int,input().split())
l.append((x,y))
l.sort(key=lambda x:x[1],reverse=True)
ans=0
for i in range(m):
if l[i][0]>=n:
x=n
else:
x=l[i][0]
n-=x
ans+=x*l[i][1]
print(ans) | Title: Burglar and Matches
Time Limit: 0 seconds
Memory Limit: 64 megabytes
Problem Description:
A burglar got into a matches warehouse and wants to steal as many matches as possible. In the warehouse there are *m* containers, in the *i*-th container there are *a**i* matchboxes, and each matchbox contains *b**i* mat... | ```python
n,m=map(int,input().split())
l=[]
for i in range(m):
x,y=map(int,input().split())
l.append((x,y))
l.sort(key=lambda x:x[1],reverse=True)
ans=0
for i in range(m):
if l[i][0]>=n:
x=n
else:
x=l[i][0]
n-=x
ans+=x*l[i][1]
print(ans)
``` | 3 |
849 | A | Odds and Ends | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Where do odds begin, and where do they end? Where does hope emerge, and will they ever break?
Given an integer sequence *a*1,<=*a*2,<=...,<=*a**n* of length *n*. Decide whether it is possible to divide it into an odd number of non-empty subsegments, the each of which has an odd length and begins and ends with odd numb... | The first line of input contains a non-negative integer *n* (1<=β€<=*n*<=β€<=100) β the length of the sequence.
The second line contains *n* space-separated non-negative integers *a*1,<=*a*2,<=...,<=*a**n* (0<=β€<=*a**i*<=β€<=100) β the elements of the sequence. | Output "Yes" if it's possible to fulfill the requirements, and "No" otherwise.
You can output each letter in any case (upper or lower). | [
"3\n1 3 5\n",
"5\n1 0 1 5 1\n",
"3\n4 3 1\n",
"4\n3 9 9 3\n"
] | [
"Yes\n",
"Yes\n",
"No\n",
"No\n"
] | In the first example, divide the sequence into 1 subsegment: {1,β3,β5} and the requirements will be met.
In the second example, divide the sequence into 3 subsegments: {1,β0,β1}, {5}, {1}.
In the third example, one of the subsegments must start with 4 which is an even number, thus the requirements cannot be met.
In ... | 500 | [
{
"input": "3\n1 3 5",
"output": "Yes"
},
{
"input": "5\n1 0 1 5 1",
"output": "Yes"
},
{
"input": "3\n4 3 1",
"output": "No"
},
{
"input": "4\n3 9 9 3",
"output": "No"
},
{
"input": "1\n1",
"output": "Yes"
},
{
"input": "5\n100 99 100 99 99",
"out... | 1,623,912,710 | 2,147,483,647 | PyPy 3 | OK | TESTS | 74 | 93 | 0 | n = int(input())
daf = list(map(int, input().split()))
if n%2 == 0 or daf[0]%2 == 0 or daf[-1]%2 == 0:
print("NO")
else:
print("YES")
| Title: Odds and Ends
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Where do odds begin, and where do they end? Where does hope emerge, and will they ever break?
Given an integer sequence *a*1,<=*a*2,<=...,<=*a**n* of length *n*. Decide whether it is possible to divide it into an odd num... | ```python
n = int(input())
daf = list(map(int, input().split()))
if n%2 == 0 or daf[0]%2 == 0 or daf[-1]%2 == 0:
print("NO")
else:
print("YES")
``` | 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,516,373,136 | 636 | PyPy 3 | OK | TESTS | 254 | 109 | 19,968,000 | n = int(input())
h, m = [int(z) for z in input().split()]
if "7" in str(h) or "7" in str(m):
print(0)
exit(0)
def time(x):
t = x // 60
m = x % 60
return t, m
cur = h * 60 + m
cnt = 0
while True:
cur -= n
cnt += 1
if cur < 0:
cur += 24 * 60
a, b = time(cur)
... | 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
n = int(input())
h, m = [int(z) for z in input().split()]
if "7" in str(h) or "7" in str(m):
print(0)
exit(0)
def time(x):
t = x // 60
m = x % 60
return t, m
cur = h * 60 + m
cnt = 0
while True:
cur -= n
cnt += 1
if cur < 0:
cur += 24 * 60
a, b = tim... | 3 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.