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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
80 | A | Panoramix's Prediction | PROGRAMMING | 800 | [
"brute force"
] | A. Panoramix's Prediction | 2 | 256 | A prime number is a number which has exactly two distinct divisors: one and itself. For example, numbers 2, 7, 3 are prime, and 1, 6, 4 are not.
The next prime number after *x* is the smallest prime number greater than *x*. For example, the next prime number after 2 is 3, and the next prime number after 3 is 5. Note t... | The first and only input line contains two positive integers β *n* and *m* (2<=β€<=*n*<=<<=*m*<=β€<=50). It is guaranteed that *n* is prime.
Pretests contain all the cases with restrictions 2<=β€<=*n*<=<<=*m*<=β€<=4. | Print YES, if *m* is the next prime number after *n*, or NO otherwise. | [
"3 5\n",
"7 11\n",
"7 9\n"
] | [
"YES",
"YES",
"NO"
] | none | 500 | [
{
"input": "3 5",
"output": "YES"
},
{
"input": "7 11",
"output": "YES"
},
{
"input": "7 9",
"output": "NO"
},
{
"input": "2 3",
"output": "YES"
},
{
"input": "2 4",
"output": "NO"
},
{
"input": "3 4",
"output": "NO"
},
{
"input": "3 5",
... | 1,599,643,572 | 2,147,483,647 | Python 3 | OK | TESTS | 45 | 218 | 0 |
n,m=map(int,input().split())
def prime(n):
for i in range(2,n):
if n%i==0:
return 'not'
return 'yes'
l=0
for i in range(n+1,m):
for j in range(2,i):
if(i % j==0):
break
else:
l+=1
# print(l)
if l>0 :
print('NO')
elif l<1 and prime(m)=='yes'... | Title: Panoramix's Prediction
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A prime number is a number which has exactly two distinct divisors: one and itself. For example, numbers 2, 7, 3 are prime, and 1, 6, 4 are not.
The next prime number after *x* is the smallest prime number greater t... | ```python
n,m=map(int,input().split())
def prime(n):
for i in range(2,n):
if n%i==0:
return 'not'
return 'yes'
l=0
for i in range(n+1,m):
for j in range(2,i):
if(i % j==0):
break
else:
l+=1
# print(l)
if l>0 :
print('NO')
elif l<1 and prime... | 3.9455 |
658 | A | Bear and Reverse Radewoosh | PROGRAMMING | 800 | [
"implementation"
] | null | null | Limak and Radewoosh are going to compete against each other in the upcoming algorithmic contest. They are equally skilled but they won't solve problems in the same order.
There will be *n* problems. The *i*-th problem has initial score *p**i* and it takes exactly *t**i* minutes to solve it. Problems are sorted by diff... | The first line contains two integers *n* and *c* (1<=β€<=*n*<=β€<=50,<=1<=β€<=*c*<=β€<=1000)Β β the number of problems and the constant representing the speed of loosing points.
The second line contains *n* integers *p*1,<=*p*2,<=...,<=*p**n* (1<=β€<=*p**i*<=β€<=1000,<=*p**i*<=<<=*p**i*<=+<=1)Β β initial scores.
The third... | Print "Limak" (without quotes) if Limak will get more points in total. Print "Radewoosh" (without quotes) if Radewoosh will get more points in total. Print "Tie" (without quotes) if Limak and Radewoosh will get the same total number of points. | [
"3 2\n50 85 250\n10 15 25\n",
"3 6\n50 85 250\n10 15 25\n",
"8 1\n10 20 30 40 50 60 70 80\n8 10 58 63 71 72 75 76\n"
] | [
"Limak\n",
"Radewoosh\n",
"Tie\n"
] | In the first sample, there are 3 problems. Limak solves them as follows:
1. Limak spends 10 minutes on the 1-st problem and he gets 50β-β*c*Β·10β=β50β-β2Β·10β=β30 points. 1. Limak spends 15 minutes on the 2-nd problem so he submits it 10β+β15β=β25 minutes after the start of the contest. For the 2-nd problem he gets 85... | 500 | [
{
"input": "3 2\n50 85 250\n10 15 25",
"output": "Limak"
},
{
"input": "3 6\n50 85 250\n10 15 25",
"output": "Radewoosh"
},
{
"input": "8 1\n10 20 30 40 50 60 70 80\n8 10 58 63 71 72 75 76",
"output": "Tie"
},
{
"input": "4 1\n3 5 6 9\n1 2 4 8",
"output": "Limak"
},
{... | 1,587,474,549 | 2,147,483,647 | Python 3 | OK | TESTS | 29 | 109 | 307,200 | n,c = map(int,input().split())
pi = list(map(int,input().split()))
ti = list(map(int,input().split()))
# for limak
s = 0
for i in range(1,n+1):
lst = sum(ti[:i])
a = pi[i-1]
maxm = max(0,(a - (c*lst)))
s += maxm
# for radewoosh
pi = pi[::-1]
ti = ti[::-1]
s1 = 0
for i in range(1,n+1):
... | Title: Bear and Reverse Radewoosh
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Limak and Radewoosh are going to compete against each other in the upcoming algorithmic contest. They are equally skilled but they won't solve problems in the same order.
There will be *n* problems. The *i*-... | ```python
n,c = map(int,input().split())
pi = list(map(int,input().split()))
ti = list(map(int,input().split()))
# for limak
s = 0
for i in range(1,n+1):
lst = sum(ti[:i])
a = pi[i-1]
maxm = max(0,(a - (c*lst)))
s += maxm
# for radewoosh
pi = pi[::-1]
ti = ti[::-1]
s1 = 0
for i in rang... | 3 | |
518 | A | Vitaly and Strings | PROGRAMMING | 1,600 | [
"constructive algorithms",
"strings"
] | null | null | Vitaly is a diligent student who never missed a lesson in his five years of studying in the university. He always does his homework on time and passes his exams in time.
During the last lesson the teacher has provided two strings *s* and *t* to Vitaly. The strings have the same length, they consist of lowercase Engli... | The first line contains string *s* (1<=β€<=|*s*|<=β€<=100), consisting of lowercase English letters. Here, |*s*| denotes the length of the string.
The second line contains string *t* (|*t*|<==<=|*s*|), consisting of lowercase English letters.
It is guaranteed that the lengths of strings *s* and *t* are the same and str... | If the string that meets the given requirements doesn't exist, print a single string "No such string" (without the quotes).
If such string exists, print it. If there are multiple valid strings, you may print any of them. | [
"a\nc\n",
"aaa\nzzz\n",
"abcdefg\nabcdefh\n"
] | [
"b\n",
"kkk\n",
"No such string\n"
] | String *s*β=β*s*<sub class="lower-index">1</sub>*s*<sub class="lower-index">2</sub>... *s*<sub class="lower-index">*n*</sub> is said to be lexicographically smaller than *t*β=β*t*<sub class="lower-index">1</sub>*t*<sub class="lower-index">2</sub>... *t*<sub class="lower-index">*n*</sub>, if there exists such *i*, that ... | 500 | [
{
"input": "a\nc",
"output": "b"
},
{
"input": "aaa\nzzz",
"output": "kkk"
},
{
"input": "abcdefg\nabcdefh",
"output": "No such string"
},
{
"input": "abcdefg\nabcfefg",
"output": "abcdefh"
},
{
"input": "frt\nfru",
"output": "No such string"
},
{
"inp... | 1,605,885,156 | 2,147,483,647 | Python 3 | OK | TESTS | 51 | 109 | 307,200 | s = input()
t = input()
length = len(s)
result = s
def changeChar(str, index, newChar):
return str[:index] + newChar + str[index + 1:]
def increaseChar(char):
if(char == 'z'):
return 'a'
return chr(ord(char) + 1)
checkIndex = length - 1
while(checkIndex >= 0):
newCh... | Title: Vitaly and Strings
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vitaly is a diligent student who never missed a lesson in his five years of studying in the university. He always does his homework on time and passes his exams in time.
During the last lesson the teacher has provi... | ```python
s = input()
t = input()
length = len(s)
result = s
def changeChar(str, index, newChar):
return str[:index] + newChar + str[index + 1:]
def increaseChar(char):
if(char == 'z'):
return 'a'
return chr(ord(char) + 1)
checkIndex = length - 1
while(checkIndex >= 0):
... | 3 | |
932 | A | Palindromic Supersequence | PROGRAMMING | 800 | [
"constructive algorithms"
] | null | null | You are given a string *A*. Find a string *B*, where *B* is a palindrome and *A* is a subsequence of *B*.
A subsequence of a string is a string that can be derived from it by deleting some (not necessarily consecutive) characters without changing the order of the remaining characters. For example, "cotst" is a subsequ... | First line contains a string *A* (1<=β€<=|*A*|<=β€<=103) consisting of lowercase Latin letters, where |*A*| is a length of *A*. | Output single line containing *B* consisting of only lowercase Latin letters. You do not need to find the shortest answer, the only restriction is that the length of string *B* should not exceed 104. If there are many possible *B*, print any of them. | [
"aba\n",
"ab\n"
] | [
"aba",
"aabaa"
] | In the first example, "aba" is a subsequence of "aba" which is a palindrome.
In the second example, "ab" is a subsequence of "aabaa" which is a palindrome. | 500 | [
{
"input": "aba",
"output": "abaaba"
},
{
"input": "ab",
"output": "abba"
},
{
"input": "krnyoixirslfszfqivgkaflgkctvbvksipwomqxlyqxhlbceuhbjbfnhofcgpgwdseffycthmlpcqejgskwjkbkbbmifnurnwyhevsoqzmtvzgfiqajfrgyuzxnrtxectcnlyoisbglpdbjbslxlpoymrcxmdtqhcnlvtqdwftuzgbdxsyscwbrguostbelnvtaqdmk... | 1,518,705,632 | 332 | Python 3 | OK | TESTS | 48 | 78 | 5,632,000 | a = input()
b = a
for i in range(len(a)):
b=b+(a[len(a)-i-1])
print(b)
| Title: Palindromic Supersequence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a string *A*. Find a string *B*, where *B* is a palindrome and *A* is a subsequence of *B*.
A subsequence of a string is a string that can be derived from it by deleting some (not necessarily co... | ```python
a = input()
b = a
for i in range(len(a)):
b=b+(a[len(a)-i-1])
print(b)
``` | 3 | |
758 | A | Holiday Of Equality | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | In Berland it is the holiday of equality. In honor of the holiday the king decided to equalize the welfare of all citizens in Berland by the expense of the state treasury.
Totally in Berland there are *n* citizens, the welfare of each of them is estimated as the integer in *a**i* burles (burle is the currency in Berl... | The first line contains the integer *n* (1<=β€<=*n*<=β€<=100)Β β the number of citizens in the kingdom.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n*, where *a**i* (0<=β€<=*a**i*<=β€<=106)Β β the welfare of the *i*-th citizen. | In the only line print the integer *S*Β β the minimum number of burles which are had to spend. | [
"5\n0 1 2 3 4\n",
"5\n1 1 0 1 1\n",
"3\n1 3 1\n",
"1\n12\n"
] | [
"10",
"1",
"4",
"0"
] | In the first example if we add to the first citizen 4 burles, to the second 3, to the third 2 and to the fourth 1, then the welfare of all citizens will equal 4.
In the second example it is enough to give one burle to the third citizen.
In the third example it is necessary to give two burles to the first and the thi... | 500 | [
{
"input": "5\n0 1 2 3 4",
"output": "10"
},
{
"input": "5\n1 1 0 1 1",
"output": "1"
},
{
"input": "3\n1 3 1",
"output": "4"
},
{
"input": "1\n12",
"output": "0"
},
{
"input": "3\n1 2 3",
"output": "3"
},
{
"input": "14\n52518 718438 358883 462189 853... | 1,667,803,287 | 2,147,483,647 | Python 3 | OK | TESTS | 41 | 46 | 0 | p=int(input())
a=list(map(int,input().split()))
k=max(a)
a.remove(k)
p=p-1
s=p*k
print(s-(sum(a))) | Title: Holiday Of Equality
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In Berland it is the holiday of equality. In honor of the holiday the king decided to equalize the welfare of all citizens in Berland by the expense of the state treasury.
Totally in Berland there are *n* citizens... | ```python
p=int(input())
a=list(map(int,input().split()))
k=max(a)
a.remove(k)
p=p-1
s=p*k
print(s-(sum(a)))
``` | 3 | |
378 | A | Playing with Dice | PROGRAMMING | 800 | [
"brute force"
] | null | null | Two players are playing a game. First each of them writes an integer from 1 to 6, and then a dice is thrown. The player whose written number got closer to the number on the dice wins. If both payers have the same difference, it's a draw.
The first player wrote number *a*, the second player wrote number *b*. How many w... | The single line contains two integers *a* and *b* (1<=β€<=*a*,<=*b*<=β€<=6)Β β the numbers written on the paper by the first and second player, correspondingly. | Print three integers: the number of ways to throw the dice at which the first player wins, the game ends with a draw or the second player wins, correspondingly. | [
"2 5\n",
"2 4\n"
] | [
"3 0 3\n",
"2 1 3\n"
] | The dice is a standard cube-shaped six-sided object with each side containing a number from 1 to 6, and where all numbers on all sides are distinct.
You can assume that number *a* is closer to number *x* than number *b*, if |*a*β-β*x*|β<β|*b*β-β*x*|. | 500 | [
{
"input": "2 5",
"output": "3 0 3"
},
{
"input": "2 4",
"output": "2 1 3"
},
{
"input": "5 3",
"output": "2 1 3"
},
{
"input": "1 6",
"output": "3 0 3"
},
{
"input": "5 1",
"output": "3 1 2"
},
{
"input": "6 3",
"output": "2 0 4"
},
{
"inp... | 1,673,716,298 | 2,147,483,647 | PyPy 3 | OK | TESTS | 38 | 78 | 0 | a,b=map(int,input().split())
win,draw,lose=0,0,0
for i in range(1,7):
if abs(a-i)<abs(b-i):
win+=1
elif abs(a-i)==abs(b-i):
draw+=1
else:
lose+=1
print(win,draw,lose) | Title: Playing with Dice
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Two players are playing a game. First each of them writes an integer from 1 to 6, and then a dice is thrown. The player whose written number got closer to the number on the dice wins. If both payers have the same diff... | ```python
a,b=map(int,input().split())
win,draw,lose=0,0,0
for i in range(1,7):
if abs(a-i)<abs(b-i):
win+=1
elif abs(a-i)==abs(b-i):
draw+=1
else:
lose+=1
print(win,draw,lose)
``` | 3 | |
711 | A | Bus to Udayland | PROGRAMMING | 800 | [
"brute force",
"implementation"
] | null | null | ZS the Coder and Chris the Baboon are travelling to Udayland! To get there, they have to get on the special IOI bus. The IOI bus has *n* rows of seats. There are 4 seats in each row, and the seats are separated into pairs by a walkway. When ZS and Chris came, some places in the bus was already occupied.
ZS and Chris a... | The first line of the input contains a single integer *n* (1<=β€<=*n*<=β€<=1000)Β β the number of rows of seats in the bus.
Then, *n* lines follow. Each line contains exactly 5 characters, the first two of them denote the first pair of seats in the row, the third character denotes the walkway (it always equals '|') and t... | If it is possible for Chris and ZS to sit at neighbouring empty seats, print "YES" (without quotes) in the first line. In the next *n* lines print the bus configuration, where the characters in the pair of seats for Chris and ZS is changed with characters '+'. Thus the configuration should differ from the input one by ... | [
"6\nOO|OX\nXO|XX\nOX|OO\nXX|OX\nOO|OO\nOO|XX\n",
"4\nXO|OX\nXO|XX\nOX|OX\nXX|OX\n",
"5\nXX|XX\nXX|XX\nXO|OX\nXO|OO\nOX|XO\n"
] | [
"YES\n++|OX\nXO|XX\nOX|OO\nXX|OX\nOO|OO\nOO|XX\n",
"NO\n",
"YES\nXX|XX\nXX|XX\nXO|OX\nXO|++\nOX|XO\n"
] | Note that the following is an incorrect configuration for the first sample case because the seats must be in the same pair.
O+|+X
XO|XX
OX|OO
XX|OX
OO|OO
OO|XX | 500 | [
{
"input": "6\nOO|OX\nXO|XX\nOX|OO\nXX|OX\nOO|OO\nOO|XX",
"output": "YES\n++|OX\nXO|XX\nOX|OO\nXX|OX\nOO|OO\nOO|XX"
},
{
"input": "4\nXO|OX\nXO|XX\nOX|OX\nXX|OX",
"output": "NO"
},
{
"input": "5\nXX|XX\nXX|XX\nXO|OX\nXO|OO\nOX|XO",
"output": "YES\nXX|XX\nXX|XX\nXO|OX\nXO|++\nOX|XO"
... | 1,648,883,876 | 2,147,483,647 | Python 3 | OK | TESTS | 71 | 62 | 0 | ans = "NO"
l = []
x = True
for i in range(int(input())):
a,b = input().split('|')
if a == "OO" and x:
a = "++"
x = False
elif b == "OO" and x:
b = "++"
x = False
l.append(a+'|'+b)
if x:
print("NO")
else:
print("YES")
for i in l:
print(... | Title: Bus to Udayland
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
ZS the Coder and Chris the Baboon are travelling to Udayland! To get there, they have to get on the special IOI bus. The IOI bus has *n* rows of seats. There are 4 seats in each row, and the seats are separated into pai... | ```python
ans = "NO"
l = []
x = True
for i in range(int(input())):
a,b = input().split('|')
if a == "OO" and x:
a = "++"
x = False
elif b == "OO" and x:
b = "++"
x = False
l.append(a+'|'+b)
if x:
print("NO")
else:
print("YES")
for i in l:
... | 3 | |
622 | A | Infinite Sequence | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | null | null | Consider the infinite sequence of integers: 1,<=1,<=2,<=1,<=2,<=3,<=1,<=2,<=3,<=4,<=1,<=2,<=3,<=4,<=5.... The sequence is built in the following way: at first the number 1 is written out, then the numbers from 1 to 2, then the numbers from 1 to 3, then the numbers from 1 to 4 and so on. Note that the sequence contains ... | The only line contains integer *n* (1<=β€<=*n*<=β€<=1014) β the position of the number to find.
Note that the given number is too large, so you should use 64-bit integer type to store it. In C++ you can use the long long integer type and in Java you can use long integer type. | Print the element in the *n*-th position of the sequence (the elements are numerated from one). | [
"3\n",
"5\n",
"10\n",
"55\n",
"56\n"
] | [
"2\n",
"2\n",
"4\n",
"10\n",
"1\n"
] | none | 0 | [
{
"input": "3",
"output": "2"
},
{
"input": "5",
"output": "2"
},
{
"input": "10",
"output": "4"
},
{
"input": "55",
"output": "10"
},
{
"input": "56",
"output": "1"
},
{
"input": "1000000000000",
"output": "88209"
},
{
"input": "8471941278... | 1,587,266,991 | 2,147,483,647 | PyPy 3 | OK | TESTS | 37 | 155 | 0 | import math
n = int(input())
cut = n+n
cut = int(math.sqrt(cut))
#print(cut)
if (cut*(cut+1))//2 >= n:
cut = (cut*(cut-1))//2
else:
cut = (cut*(cut+1))//2
print(n-cut) | Title: Infinite Sequence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Consider the infinite sequence of integers: 1,<=1,<=2,<=1,<=2,<=3,<=1,<=2,<=3,<=4,<=1,<=2,<=3,<=4,<=5.... The sequence is built in the following way: at first the number 1 is written out, then the numbers from 1 to 2,... | ```python
import math
n = int(input())
cut = n+n
cut = int(math.sqrt(cut))
#print(cut)
if (cut*(cut+1))//2 >= n:
cut = (cut*(cut-1))//2
else:
cut = (cut*(cut+1))//2
print(n-cut)
``` | 3 | |
0 | none | none | none | 0 | [
"none"
] | null | null | A very brave explorer Petya once decided to explore Paris catacombs. Since Petya is not really experienced, his exploration is just walking through the catacombs.
Catacombs consist of several rooms and bidirectional passages between some pairs of them. Some passages can connect a room to itself and since the passages ... | The first line contains a single integer *n* (1<=β€<=*n*<=β€<=2Β·105) β then number of notes in Petya's logbook.
The second line contains *n* non-negative integers *t*1,<=*t*2,<=...,<=*t**n* (0<=β€<=*t**i*<=<<=*i*) β notes in the logbook. | In the only line print a single integer β the minimum possible number of rooms in Paris catacombs. | [
"2\n0 0\n",
"5\n0 1 0 1 3\n"
] | [
"2\n",
"3\n"
] | In the first sample, sequence of rooms Petya visited could be, for example 1βββ1βββ2, 1βββ2βββ1 or 1βββ2βββ3. The minimum possible number of rooms is 2.
In the second sample, the sequence could be 1βββ2βββ3βββ1βββ2βββ1. | 0 | [
{
"input": "2\n0 0",
"output": "2"
},
{
"input": "5\n0 1 0 1 3",
"output": "3"
},
{
"input": "7\n0 1 0 0 0 0 0",
"output": "6"
},
{
"input": "100\n0 0 0 0 0 0 1 4 4 0 2 2 4 1 7 1 11 0 8 4 12 12 3 0 3 2 2 4 3 9 1 5 4 6 9 14 6 2 4 18 7 7 19 11 20 13 17 16 0 34 2 6 12 27 9 4 29 ... | 1,510,504,258 | 1,558 | Python 3 | OK | TESTS | 31 | 218 | 14,233,600 | n=int(input().strip())
a=list(map(int,input().strip().split()))
t=[-1]*(n+1)
t[0]=1
ans=1
new=1
for i in range(0,n):
x=a[i]
if t[x]!=-1:
t[i+1]=t[x]
t[x]=-1
else:
ans=ans+1
t[i+1]=ans
print(ans) | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A very brave explorer Petya once decided to explore Paris catacombs. Since Petya is not really experienced, his exploration is just walking through the catacombs.
Catacombs consist of several rooms and bidirectional passages betw... | ```python
n=int(input().strip())
a=list(map(int,input().strip().split()))
t=[-1]*(n+1)
t[0]=1
ans=1
new=1
for i in range(0,n):
x=a[i]
if t[x]!=-1:
t[i+1]=t[x]
t[x]=-1
else:
ans=ans+1
t[i+1]=ans
print(ans)
``` | 3 | |
591 | A | Wizards' Duel | PROGRAMMING | 900 | [
"implementation",
"math"
] | null | null | Harry Potter and He-Who-Must-Not-Be-Named engaged in a fight to the death once again. This time they are located at opposite ends of the corridor of length *l*. Two opponents simultaneously charge a deadly spell in the enemy. We know that the impulse of Harry's magic spell flies at a speed of *p* meters per second, and... | The first line of the input contains a single integer *l* (1<=β€<=*l*<=β€<=1<=000)Β β the length of the corridor where the fight takes place.
The second line contains integer *p*, the third line contains integer *q* (1<=β€<=*p*,<=*q*<=β€<=500)Β β the speeds of magical impulses for Harry Potter and He-Who-Must-Not-Be-Named, ... | Print a single real numberΒ β the distance from the end of the corridor, where Harry is located, to the place of the second meeting of the spell impulses. Your answer will be considered correct if its absolute or relative error will not exceed 10<=-<=4.
Namely: let's assume that your answer equals *a*, and the answer ... | [
"100\n50\n50\n",
"199\n60\n40\n"
] | [
"50\n",
"119.4\n"
] | In the first sample the speeds of the impulses are equal, so both of their meetings occur exactly in the middle of the corridor. | 500 | [
{
"input": "100\n50\n50",
"output": "50"
},
{
"input": "199\n60\n40",
"output": "119.4"
},
{
"input": "1\n1\n1",
"output": "0.5"
},
{
"input": "1\n1\n500",
"output": "0.001996007984"
},
{
"input": "1\n500\n1",
"output": "0.998003992"
},
{
"input": "1\n... | 1,512,059,646 | 2,147,483,647 | Python 3 | OK | TESTS | 45 | 77 | 6,041,600 | '''
Author: Sofen Hoque Anonta
'''
import re
import sys
import math
import itertools
import collections
def inputArray(TYPE= int):
return [TYPE(x) for x in input().split()]
def solve():
d= int(input())
p= int(input())
q= int(input())
print(p*d/(p+q))
if __name__ == '__main... | Title: Wizards' Duel
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Harry Potter and He-Who-Must-Not-Be-Named engaged in a fight to the death once again. This time they are located at opposite ends of the corridor of length *l*. Two opponents simultaneously charge a deadly spell in the en... | ```python
'''
Author: Sofen Hoque Anonta
'''
import re
import sys
import math
import itertools
import collections
def inputArray(TYPE= int):
return [TYPE(x) for x in input().split()]
def solve():
d= int(input())
p= int(input())
q= int(input())
print(p*d/(p+q))
if __name__ ... | 3 | |
596 | A | Wilbur and Swimming Pool | PROGRAMMING | 1,100 | [
"geometry",
"implementation"
] | null | null | After making bad dives into swimming pools, Wilbur wants to build a swimming pool in the shape of a rectangle in his backyard. He has set up coordinate axes, and he wants the sides of the rectangle to be parallel to them. Of course, the area of the rectangle must be positive. Wilbur had all four vertices of the planned... | The first line of the input contains a single integer *n* (1<=β€<=*n*<=β€<=4)Β β the number of vertices that were not erased by Wilbur's friend.
Each of the following *n* lines contains two integers *x**i* and *y**i* (<=-<=1000<=β€<=*x**i*,<=*y**i*<=β€<=1000)Β βthe coordinates of the *i*-th vertex that remains. Vertices are... | Print the area of the initial rectangle if it could be uniquely determined by the points remaining. Otherwise, print <=-<=1. | [
"2\n0 0\n1 1\n",
"1\n1 1\n"
] | [
"1\n",
"-1\n"
] | In the first sample, two opposite corners of the initial rectangle are given, and that gives enough information to say that the rectangle is actually a unit square.
In the second sample there is only one vertex left and this is definitely not enough to uniquely define the area. | 500 | [
{
"input": "2\n0 0\n1 1",
"output": "1"
},
{
"input": "1\n1 1",
"output": "-1"
},
{
"input": "1\n-188 17",
"output": "-1"
},
{
"input": "1\n71 -740",
"output": "-1"
},
{
"input": "4\n-56 -858\n-56 -174\n778 -858\n778 -174",
"output": "570456"
},
{
"inp... | 1,504,986,264 | 2,364 | Python 3 | OK | TESTS | 121 | 77 | 0 | import sys
n = int(input())
x = []
y = []
weight = height = 0
for i in range(n):
xx,yy = map(int,input().split())
x.append(xx)
y.append(yy)
if n == 1:
print('-1')
elif n == 2:
if x[0] == x[1] or y[0] == y[1]:
print('-1')
else:
print(abs((x[0]-x[1])*(y[0]-y[1])))
... | Title: Wilbur and Swimming Pool
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
After making bad dives into swimming pools, Wilbur wants to build a swimming pool in the shape of a rectangle in his backyard. He has set up coordinate axes, and he wants the sides of the rectangle to be parall... | ```python
import sys
n = int(input())
x = []
y = []
weight = height = 0
for i in range(n):
xx,yy = map(int,input().split())
x.append(xx)
y.append(yy)
if n == 1:
print('-1')
elif n == 2:
if x[0] == x[1] or y[0] == y[1]:
print('-1')
else:
print(abs((x[0]-x[1])*(y[0... | 3 | |
617 | A | Elephant | PROGRAMMING | 800 | [
"math"
] | null | null | An elephant decided to visit his friend. It turned out that the elephant's house is located at point 0 and his friend's house is located at point *x*(*x*<=><=0) of the coordinate line. In one step the elephant can move 1, 2, 3, 4 or 5 positions forward. Determine, what is the minimum number of steps he need to make ... | The first line of the input contains an integer *x* (1<=β€<=*x*<=β€<=1<=000<=000)Β β The coordinate of the friend's house. | Print the minimum number of steps that elephant needs to make to get from point 0 to point *x*. | [
"5\n",
"12\n"
] | [
"1\n",
"3\n"
] | In the first sample the elephant needs to make one step of length 5 to reach the point *x*.
In the second sample the elephant can get to point *x* if he moves by 3, 5 and 4. There are other ways to get the optimal answer but the elephant cannot reach *x* in less than three moves. | 500 | [
{
"input": "5",
"output": "1"
},
{
"input": "12",
"output": "3"
},
{
"input": "999999",
"output": "200000"
},
{
"input": "41",
"output": "9"
},
{
"input": "1000000",
"output": "200000"
},
{
"input": "1",
"output": "1"
},
{
"input": "2",
... | 1,696,271,855 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 31 | 0 | x=int(input())
b=x/5
c=int(b)
if b<1:
print("1")
elif x%5==0:
print(c)
else:
print(c+1) | Title: Elephant
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
An elephant decided to visit his friend. It turned out that the elephant's house is located at point 0 and his friend's house is located at point *x*(*x*<=><=0) of the coordinate line. In one step the elephant can move 1, 2... | ```python
x=int(input())
b=x/5
c=int(b)
if b<1:
print("1")
elif x%5==0:
print(c)
else:
print(c+1)
``` | 3 | |
383 | A | Milking cows | PROGRAMMING | 1,600 | [
"data structures",
"greedy"
] | null | null | Iahub helps his grandfather at the farm. Today he must milk the cows. There are *n* cows sitting in a row, numbered from 1 to *n* from left to right. Each cow is either facing to the left or facing to the right. When Iahub milks a cow, all the cows that see the current cow get scared and lose one unit of the quantity o... | The first line contains an integer *n* (1<=β€<=*n*<=β€<=200000). The second line contains *n* integers *a*1, *a*2, ..., *a**n*, where *a**i* is 0 if the cow number *i* is facing left, and 1 if it is facing right. | Print a single integer, the minimum amount of lost milk.
Please, do not write the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier. | [
"4\n0 0 1 0\n",
"5\n1 0 1 0 1\n"
] | [
"1",
"3"
] | In the first sample Iahub milks the cows in the following order: cow 3, cow 4, cow 2, cow 1. When he milks cow 3, cow 4 loses 1 unit of milk. After that, no more milk is lost. | 500 | [
{
"input": "4\n0 0 1 0",
"output": "1"
},
{
"input": "5\n1 0 1 0 1",
"output": "3"
},
{
"input": "50\n1 1 0 1 1 1 1 1 1 0 0 1 1 0 1 1 0 0 1 0 1 1 0 1 1 1 1 0 1 0 1 0 1 1 1 0 0 0 0 0 0 0 1 1 0 1 0 0 1 0",
"output": "416"
},
{
"input": "100\n1 1 0 0 1 1 1 1 0 1 1 1 1 1 1 1 0 0 ... | 1,674,548,565 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 42 | 109 | 15,872,000 | n = int(input())
cows = [int(i) for i in input().strip().split()
]
scare = 0
rightCows = 0
for i in cows:
if i==1: rightCows += 1
else: scare += rightCows
print(scare) | Title: Milking cows
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Iahub helps his grandfather at the farm. Today he must milk the cows. There are *n* cows sitting in a row, numbered from 1 to *n* from left to right. Each cow is either facing to the left or facing to the right. When Iahub... | ```python
n = int(input())
cows = [int(i) for i in input().strip().split()
]
scare = 0
rightCows = 0
for i in cows:
if i==1: rightCows += 1
else: scare += rightCows
print(scare)
``` | 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,690,618,936 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 40 | 61 | 0 | def f(j, a):
first_symbol = 0
symbol_found = False
for i in range(j, len(s)):
if s[i] == a:
first_symbol = i
symbol_found = True
return first_symbol
print("NO")
exit(0)
s=input()
h = f(0, 'h')
e = f(h + 1, 'e')
l = f(e + 1, '... | 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
def f(j, a):
first_symbol = 0
symbol_found = False
for i in range(j, len(s)):
if s[i] == a:
first_symbol = i
symbol_found = True
return first_symbol
print("NO")
exit(0)
s=input()
h = f(0, 'h')
e = f(h + 1, 'e')
l = ... | 3.9695 |
472 | A | Design Tutorial: Learn from Math | PROGRAMMING | 800 | [
"math",
"number theory"
] | null | null | One way to create a task is to learn from math. You can generate some random math statement or modify some theorems to get something new and build a new task from that.
For example, there is a statement called the "Goldbach's conjecture". It says: "each even number no less than four can be expressed as the sum of two ... | The only line contains an integer *n* (12<=β€<=*n*<=β€<=106). | Output two composite integers *x* and *y* (1<=<<=*x*,<=*y*<=<<=*n*) such that *x*<=+<=*y*<==<=*n*. If there are multiple solutions, you can output any of them. | [
"12\n",
"15\n",
"23\n",
"1000000\n"
] | [
"4 8\n",
"6 9\n",
"8 15\n",
"500000 500000\n"
] | In the first example, 12 = 4 + 8 and both 4, 8 are composite numbers. You can output "6 6" or "8 4" as well.
In the second example, 15 = 6 + 9. Note that you can't output "1 14" because 1 is not a composite number. | 500 | [
{
"input": "12",
"output": "4 8"
},
{
"input": "15",
"output": "6 9"
},
{
"input": "23",
"output": "8 15"
},
{
"input": "1000000",
"output": "500000 500000"
},
{
"input": "63874",
"output": "4 63870"
},
{
"input": "14568",
"output": "4 14564"
},
... | 1,676,055,513 | 2,147,483,647 | Python 3 | OK | TESTS | 33 | 46 | 0 | n = int(input())
if (n % 2 == 0):
print("4", (n - 4), end = " ")
else:
print("9", n - 9, end = " ") | Title: Design Tutorial: Learn from Math
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One way to create a task is to learn from math. You can generate some random math statement or modify some theorems to get something new and build a new task from that.
For example, there is a statemen... | ```python
n = int(input())
if (n % 2 == 0):
print("4", (n - 4), end = " ")
else:
print("9", n - 9, end = " ")
``` | 3 | |
961 | A | Tetris | PROGRAMMING | 900 | [
"implementation"
] | null | null | You are given a following process.
There is a platform with $n$ columns. $1 \times 1$ squares are appearing one after another in some columns on this platform. If there are no squares in the column, a square will occupy the bottom row. Otherwise a square will appear at the top of the highest square of this column.
... | The first line of input contain 2 integer numbers $n$ and $m$ ($1 \le n, m \le 1000$) β the length of the platform and the number of the squares.
The next line contain $m$ integer numbers $c_1, c_2, \dots, c_m$ ($1 \le c_i \le n$) β column in which $i$-th square will appear. | Print one integer β the amount of points you will receive. | [
"3 9\n1 1 2 2 2 3 1 2 3\n"
] | [
"2\n"
] | In the sample case the answer will be equal to $2$ because after the appearing of $6$-th square will be removed one row (counts of the squares on the platform will look like $[2~ 3~ 1]$, and after removing one row will be $[1~ 2~ 0]$).
After the appearing of $9$-th square counts will be $[2~ 3~ 1]$, and after removing... | 0 | [
{
"input": "3 9\n1 1 2 2 2 3 1 2 3",
"output": "2"
},
{
"input": "1 7\n1 1 1 1 1 1 1",
"output": "7"
},
{
"input": "1 1\n1",
"output": "1"
},
{
"input": "3 5\n1 1 1 2 3",
"output": "1"
},
{
"input": "4 6\n4 4 4 4 4 4",
"output": "0"
},
{
"input": "4 6\... | 1,626,190,546 | 2,147,483,647 | Python 3 | OK | TESTS | 29 | 92 | 6,963,200 | #Pre-Python USACO Week1-3
#https://codeforces.com/problemset/problem/961/A
line=input().strip().split()
n=int(line[0])
m=int(line[1])
index=input().split()
ct=[]
for i in range(n):
num=i+1
count=index.count(str(num))
ct.append(count)
print(min(ct))
| Title: Tetris
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a following process.
There is a platform with $n$ columns. $1 \times 1$ squares are appearing one after another in some columns on this platform. If there are no squares in the column, a square will occupy the bo... | ```python
#Pre-Python USACO Week1-3
#https://codeforces.com/problemset/problem/961/A
line=input().strip().split()
n=int(line[0])
m=int(line[1])
index=input().split()
ct=[]
for i in range(n):
num=i+1
count=index.count(str(num))
ct.append(count)
print(min(ct))
``` | 3 | |
116 | A | Tram | PROGRAMMING | 800 | [
"implementation"
] | null | null | Linear Kingdom has exactly one tram line. It has *n* stops, numbered from 1 to *n* in the order of tram's movement. At the *i*-th stop *a**i* passengers exit the tram, while *b**i* passengers enter it. The tram is empty before it arrives at the first stop. Also, when the tram arrives at the last stop, all passengers ex... | The first line contains a single number *n* (2<=β€<=*n*<=β€<=1000) β the number of the tram's stops.
Then *n* lines follow, each contains two integers *a**i* and *b**i* (0<=β€<=*a**i*,<=*b**i*<=β€<=1000) β the number of passengers that exits the tram at the *i*-th stop, and the number of passengers that enter the tram at... | Print a single integer denoting the minimum possible capacity of the tram (0 is allowed). | [
"4\n0 3\n2 5\n4 2\n4 0\n"
] | [
"6\n"
] | For the first example, a capacity of 6 is sufficient:
- At the first stop, the number of passengers inside the tram before arriving is 0. Then, 3 passengers enter the tram, and the number of passengers inside the tram becomes 3. - At the second stop, 2 passengers exit the tram (1 passenger remains inside). Then, 5 ... | 500 | [
{
"input": "4\n0 3\n2 5\n4 2\n4 0",
"output": "6"
},
{
"input": "5\n0 4\n4 6\n6 5\n5 4\n4 0",
"output": "6"
},
{
"input": "10\n0 5\n1 7\n10 8\n5 3\n0 5\n3 3\n8 8\n0 6\n10 1\n9 0",
"output": "18"
},
{
"input": "3\n0 1\n1 1\n1 0",
"output": "1"
},
{
"input": "4\n0 1... | 1,691,604,763 | 2,147,483,647 | Python 3 | OK | TESTS | 71 | 92 | 0 | n=int(input())
c,max1=0,0
for i in range(n):
m,n=map(int,input().split())
if i==0:
c=n
else:
c=c-m
c=c+n
#print(c)
max1=max(max1,c)
print(max1) | Title: Tram
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Linear Kingdom has exactly one tram line. It has *n* stops, numbered from 1 to *n* in the order of tram's movement. At the *i*-th stop *a**i* passengers exit the tram, while *b**i* passengers enter it. The tram is empty before it ... | ```python
n=int(input())
c,max1=0,0
for i in range(n):
m,n=map(int,input().split())
if i==0:
c=n
else:
c=c-m
c=c+n
#print(c)
max1=max(max1,c)
print(max1)
``` | 3 | |
967 | B | Watering System | PROGRAMMING | 1,000 | [
"math",
"sortings"
] | null | null | Arkady wants to water his only flower. Unfortunately, he has a very poor watering system that was designed for $n$ flowers and so it looks like a pipe with $n$ holes. Arkady can only use the water that flows from the first hole.
Arkady can block some of the holes, and then pour $A$ liters of water into the pipe. After... | The first line contains three integers $n$, $A$, $B$ ($1 \le n \le 100\,000$, $1 \le B \le A \le 10^4$)Β β the number of holes, the volume of water Arkady will pour into the system, and the volume he wants to get out of the first hole.
The second line contains $n$ integers $s_1, s_2, \ldots, s_n$ ($1 \le s_i \le 10^4$)... | Print a single integerΒ β the number of holes Arkady should block. | [
"4 10 3\n2 2 2 2\n",
"4 80 20\n3 2 1 4\n",
"5 10 10\n1000 1 1 1 1\n"
] | [
"1\n",
"0\n",
"4\n"
] | In the first example Arkady should block at least one hole. After that, $\frac{10 \cdot 2}{6} \approx 3.333$ liters of water will flow out of the first hole, and that suits Arkady.
In the second example even without blocking any hole, $\frac{80 \cdot 3}{10} = 24$ liters will flow out of the first hole, that is not les... | 1,000 | [
{
"input": "4 10 3\n2 2 2 2",
"output": "1"
},
{
"input": "4 80 20\n3 2 1 4",
"output": "0"
},
{
"input": "5 10 10\n1000 1 1 1 1",
"output": "4"
},
{
"input": "10 300 100\n20 1 3 10 8 5 3 6 4 3",
"output": "1"
},
{
"input": "10 300 100\n20 25 68 40 60 37 44 85 23 ... | 1,596,781,412 | 2,147,483,647 | PyPy 3 | OK | TESTS | 26 | 202 | 29,286,400 | def f(l1,l2):
n,a,b = l1
s = sum(l2)
l = l2[1:]
l.sort(reverse=True)
i = 0
while b*s>l2[0]*a:
s -= l[i]
i += 1
return i
l1 = list(map(int,input().split()))
l2 = list(map(int,input().split()))
print(f(l1,l2))
| Title: Watering System
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Arkady wants to water his only flower. Unfortunately, he has a very poor watering system that was designed for $n$ flowers and so it looks like a pipe with $n$ holes. Arkady can only use the water that flows from the fi... | ```python
def f(l1,l2):
n,a,b = l1
s = sum(l2)
l = l2[1:]
l.sort(reverse=True)
i = 0
while b*s>l2[0]*a:
s -= l[i]
i += 1
return i
l1 = list(map(int,input().split()))
l2 = list(map(int,input().split()))
print(f(l1,l2))
``` | 3 | |
313 | A | Ilya and Bank Account | PROGRAMMING | 900 | [
"implementation",
"number theory"
] | null | null | Ilya is a very clever lion, he lives in an unusual city ZooVille. In this city all the animals have their rights and obligations. Moreover, they even have their own bank accounts. The state of a bank account is an integer. The state of a bank account can be a negative number. This means that the owner of the account ow... | The single line contains integer *n* (10<=β€<=|*n*|<=β€<=109) β the state of Ilya's bank account. | In a single line print an integer β the maximum state of the bank account that Ilya can get. | [
"2230\n",
"-10\n",
"-100003\n"
] | [
"2230\n",
"0\n",
"-10000\n"
] | In the first test sample Ilya doesn't profit from using the present.
In the second test sample you can delete digit 1 and get the state of the account equal to 0. | 500 | [
{
"input": "2230",
"output": "2230"
},
{
"input": "-10",
"output": "0"
},
{
"input": "-100003",
"output": "-10000"
},
{
"input": "544883178",
"output": "544883178"
},
{
"input": "-847251738",
"output": "-84725173"
},
{
"input": "423654797",
"output... | 1,683,442,033 | 2,147,483,647 | Python 3 | OK | TESTS | 47 | 92 | 0 |
n = int(input())
if n >= 0 or n%10 == n:
print(n)
else:
if n%100 == n:
a = int(str(n)[:-1])
b = str(n)[-1]
if a > b:
print(a)
else:
print(b)
else:
val1 = int(str(n)[:-1])
val2 = int(str(n)[:-2] + str(n)[-1])
if v... | Title: Ilya and Bank Account
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Ilya is a very clever lion, he lives in an unusual city ZooVille. In this city all the animals have their rights and obligations. Moreover, they even have their own bank accounts. The state of a bank account is an... | ```python
n = int(input())
if n >= 0 or n%10 == n:
print(n)
else:
if n%100 == n:
a = int(str(n)[:-1])
b = str(n)[-1]
if a > b:
print(a)
else:
print(b)
else:
val1 = int(str(n)[:-1])
val2 = int(str(n)[:-2] + str(n)[-1])
... | 3 | |
976 | A | Minimum Binary Number | PROGRAMMING | 800 | [
"implementation"
] | null | null | String can be called correct if it consists of characters "0" and "1" and there are no redundant leading zeroes. Here are some examples: "0", "10", "1001".
You are given a correct string *s*.
You can perform two different operations on this string:
1. swap any pair of adjacent characters (for example, "101" "110"... | The first line contains integer number *n* (1<=β€<=*n*<=β€<=100) β the length of string *s*.
The second line contains the string *s* consisting of characters "0" and "1". It is guaranteed that the string *s* is correct. | Print one string β the minimum correct string that you can obtain from the given one. | [
"4\n1001\n",
"1\n1\n"
] | [
"100\n",
"1\n"
] | In the first example you can obtain the answer by the following sequence of operations: "1001" <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> "1010" <img align="middle" class="tex-formula" src="ht... | 0 | [
{
"input": "4\n1001",
"output": "100"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "100\n1110111100001111011111111010110011111111011110000111101101011100110110001011000000101010110101011100",
"output": "1000000000000000000000000000000000000000"
},
{
"input": "100\n100000... | 1,592,664,391 | 2,147,483,647 | PyPy 3 | OK | TESTS | 14 | 140 | 0 | n = int(input())
s = list(input())
for i in range(n):
if s[i] == '1':
for j in range(i+1, n):
if s[j] == '1':
s[j] = ''
print(''.join(s)) | Title: Minimum Binary Number
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
String can be called correct if it consists of characters "0" and "1" and there are no redundant leading zeroes. Here are some examples: "0", "10", "1001".
You are given a correct string *s*.
You can perform two... | ```python
n = int(input())
s = list(input())
for i in range(n):
if s[i] == '1':
for j in range(i+1, n):
if s[j] == '1':
s[j] = ''
print(''.join(s))
``` | 3 | |
900 | B | Position in Fraction | PROGRAMMING | 1,300 | [
"math",
"number theory"
] | null | null | You have a fraction . You need to find the first occurrence of digit *c* into decimal notation of the fraction after decimal point. | The first contains three single positive integers *a*, *b*, *c* (1<=β€<=*a*<=<<=*b*<=β€<=105, 0<=β€<=*c*<=β€<=9). | Print position of the first occurrence of digit *c* into the fraction. Positions are numbered from 1 after decimal point. It there is no such position, print -1. | [
"1 2 0\n",
"2 3 7\n"
] | [
"2",
"-1"
] | The fraction in the first example has the following decimal notation: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/896357459a466614a0542f34c9cfb0cef1afc9ed.png" style="max-width: 100.0%;max-height: 100.0%;"/>. The first zero stands on second position.
The fraction in the second example ... | 1,000 | [
{
"input": "1 2 0",
"output": "2"
},
{
"input": "2 3 7",
"output": "-1"
},
{
"input": "1 100000 1",
"output": "5"
},
{
"input": "1 7 7",
"output": "6"
},
{
"input": "99999 100000 8",
"output": "-1"
},
{
"input": "44102 73848 2",
"output": "132"
}... | 1,687,881,679 | 2,147,483,647 | Python 3 | OK | TESTS | 33 | 46 | 409,600 | # /**
# * author: brownfox2k6
# * created: 27/06/2023 22:48:46 Hanoi, Vietnam
# **/
import decimal
decimal.getcontext().prec = 5000
a, b, c = map(int, input().split())
a = decimal.Decimal(a)
b = decimal.Decimal(b)
x = decimal.Decimal(a / b)
x = str(x)[2:]
c = str(c)
if len(x) == 5000:
... | Title: Position in Fraction
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You have a fraction . You need to find the first occurrence of digit *c* into decimal notation of the fraction after decimal point.
Input Specification:
The first contains three single positive integers *a*, *b*, ... | ```python
# /**
# * author: brownfox2k6
# * created: 27/06/2023 22:48:46 Hanoi, Vietnam
# **/
import decimal
decimal.getcontext().prec = 5000
a, b, c = map(int, input().split())
a = decimal.Decimal(a)
b = decimal.Decimal(b)
x = decimal.Decimal(a / b)
x = str(x)[2:]
c = str(c)
if len(x) ... | 3 | |
900 | B | Position in Fraction | PROGRAMMING | 1,300 | [
"math",
"number theory"
] | null | null | You have a fraction . You need to find the first occurrence of digit *c* into decimal notation of the fraction after decimal point. | The first contains three single positive integers *a*, *b*, *c* (1<=β€<=*a*<=<<=*b*<=β€<=105, 0<=β€<=*c*<=β€<=9). | Print position of the first occurrence of digit *c* into the fraction. Positions are numbered from 1 after decimal point. It there is no such position, print -1. | [
"1 2 0\n",
"2 3 7\n"
] | [
"2",
"-1"
] | The fraction in the first example has the following decimal notation: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/896357459a466614a0542f34c9cfb0cef1afc9ed.png" style="max-width: 100.0%;max-height: 100.0%;"/>. The first zero stands on second position.
The fraction in the second example ... | 1,000 | [
{
"input": "1 2 0",
"output": "2"
},
{
"input": "2 3 7",
"output": "-1"
},
{
"input": "1 100000 1",
"output": "5"
},
{
"input": "1 7 7",
"output": "6"
},
{
"input": "99999 100000 8",
"output": "-1"
},
{
"input": "44102 73848 2",
"output": "132"
}... | 1,513,856,983 | 2,147,483,647 | Python 3 | OK | TESTS | 33 | 93 | 5,632,000 | a,b,c=map(int,input().split())
for i in range(b):
x,a=divmod(10*a,b)
if(x==c):
print(i+1)
exit()
print(-1) | Title: Position in Fraction
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You have a fraction . You need to find the first occurrence of digit *c* into decimal notation of the fraction after decimal point.
Input Specification:
The first contains three single positive integers *a*, *b*, ... | ```python
a,b,c=map(int,input().split())
for i in range(b):
x,a=divmod(10*a,b)
if(x==c):
print(i+1)
exit()
print(-1)
``` | 3 | |
379 | A | New Year Candles | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Vasily the Programmer loves romance, so this year he decided to illuminate his room with candles.
Vasily has *a* candles.When Vasily lights up a new candle, it first burns for an hour and then it goes out. Vasily is smart, so he can make *b* went out candles into a new candle. As a result, this new candle can be used ... | The single line contains two integers, *a* and *b* (1<=β€<=*a*<=β€<=1000;Β 2<=β€<=*b*<=β€<=1000). | Print a single integer β the number of hours Vasily can light up the room for. | [
"4 2\n",
"6 3\n"
] | [
"7\n",
"8\n"
] | Consider the first sample. For the first four hours Vasily lights up new candles, then he uses four burned out candles to make two new ones and lights them up. When these candles go out (stop burning), Vasily can make another candle. Overall, Vasily can light up the room for 7 hours. | 500 | [
{
"input": "4 2",
"output": "7"
},
{
"input": "6 3",
"output": "8"
},
{
"input": "1000 1000",
"output": "1001"
},
{
"input": "123 5",
"output": "153"
},
{
"input": "1000 2",
"output": "1999"
},
{
"input": "1 2",
"output": "1"
},
{
"input": ... | 1,654,648,135 | 2,147,483,647 | Python 3 | OK | TESTS | 32 | 46 | 0 | if __name__ == "__main__":
a, b = input().split()
a = int(a)
b = int(b)
cnt = 0
used = 0
while a > 0:
cnt += 1
a -= 1
used += 1
if used == b:
used -= b
a += 1
print(cnt)
| Title: New Year Candles
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasily the Programmer loves romance, so this year he decided to illuminate his room with candles.
Vasily has *a* candles.When Vasily lights up a new candle, it first burns for an hour and then it goes out. Vasily is s... | ```python
if __name__ == "__main__":
a, b = input().split()
a = int(a)
b = int(b)
cnt = 0
used = 0
while a > 0:
cnt += 1
a -= 1
used += 1
if used == b:
used -= b
a += 1
print(cnt)
``` | 3 | |
918 | B | Radio Station | PROGRAMMING | 900 | [
"implementation",
"strings"
] | null | null | As the guys fried the radio station facilities, the school principal gave them tasks as a punishment. Dustin's task was to add comments to nginx configuration for school's website. The school has *n* servers. Each server has a name and an ip (names aren't necessarily unique, but ips are). Dustin knows the ip and name o... | The first line of input contains two integers *n* and *m* (1<=β€<=*n*,<=*m*<=β€<=1000).
The next *n* lines contain the names and ips of the servers. Each line contains a string name, name of the server and a string ip, ip of the server, separated by space (1<=β€<=|*name*|<=β€<=10, *name* only consists of English lowercase... | Print *m* lines, the commands in the configuration file after Dustin did his task. | [
"2 2\nmain 192.168.0.2\nreplica 192.168.0.1\nblock 192.168.0.1;\nproxy 192.168.0.2;\n",
"3 5\ngoogle 8.8.8.8\ncodeforces 212.193.33.27\nserver 138.197.64.57\nredirect 138.197.64.57;\nblock 8.8.8.8;\ncf 212.193.33.27;\nunblock 8.8.8.8;\ncheck 138.197.64.57;\n"
] | [
"block 192.168.0.1; #replica\nproxy 192.168.0.2; #main\n",
"redirect 138.197.64.57; #server\nblock 8.8.8.8; #google\ncf 212.193.33.27; #codeforces\nunblock 8.8.8.8; #google\ncheck 138.197.64.57; #server\n"
] | none | 1,000 | [
{
"input": "2 2\nmain 192.168.0.2\nreplica 192.168.0.1\nblock 192.168.0.1;\nproxy 192.168.0.2;",
"output": "block 192.168.0.1; #replica\nproxy 192.168.0.2; #main"
},
{
"input": "3 5\ngoogle 8.8.8.8\ncodeforces 212.193.33.27\nserver 138.197.64.57\nredirect 138.197.64.57;\nblock 8.8.8.8;\ncf 212.193.3... | 1,584,702,162 | 2,147,483,647 | Python 3 | OK | TESTS | 28 | 124 | 307,200 | a=list(map(int,input().split()))
n,m=a[0],a[1]
dict={}
for i in range(n):
x=list(input().split())
dict[x[1]]=x[0]
for i in range(m):
y=list(input().split())
print(y[0]+" "+y[1]+" #"+dict[y[1][0:-1]])
| Title: Radio Station
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
As the guys fried the radio station facilities, the school principal gave them tasks as a punishment. Dustin's task was to add comments to nginx configuration for school's website. The school has *n* servers. Each server ... | ```python
a=list(map(int,input().split()))
n,m=a[0],a[1]
dict={}
for i in range(n):
x=list(input().split())
dict[x[1]]=x[0]
for i in range(m):
y=list(input().split())
print(y[0]+" "+y[1]+" #"+dict[y[1][0:-1]])
``` | 3 | |
707 | A | Brain's Photos | PROGRAMMING | 800 | [
"implementation"
] | null | null | Small, but very brave, mouse Brain was not accepted to summer school of young villains. He was upset and decided to postpone his plans of taking over the world, but to become a photographer instead.
As you may know, the coolest photos are on the film (because you can specify the hashtag #film for such).
Brain took a ... | The first line of the input contains two integers *n* and *m* (1<=β€<=*n*,<=*m*<=β€<=100)Β β the number of photo pixel matrix rows and columns respectively.
Then *n* lines describing matrix rows follow. Each of them contains *m* space-separated characters describing colors of pixels in a row. Each character in the line i... | Print the "#Black&White" (without quotes), if the photo is black-and-white and "#Color" (without quotes), if it is colored, in the only line. | [
"2 2\nC M\nY Y\n",
"3 2\nW W\nW W\nB B\n",
"1 1\nW\n"
] | [
"#Color",
"#Black&White",
"#Black&White"
] | none | 500 | [
{
"input": "2 2\nC M\nY Y",
"output": "#Color"
},
{
"input": "3 2\nW W\nW W\nB B",
"output": "#Black&White"
},
{
"input": "1 1\nW",
"output": "#Black&White"
},
{
"input": "2 3\nW W W\nB G Y",
"output": "#Color"
},
{
"input": "1 1\nW",
"output": "#Black&White"
... | 1,698,710,190 | 2,147,483,647 | Python 3 | OK | TESTS | 50 | 46 | 0 | m, n = map(int, input().split())
a = False
for i in range(m):
b = input().split()
if 'C' in b or 'M' in b or 'Y' in b:
a = True
print('#Black&White' if a == False else '#Color') | Title: Brain's Photos
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Small, but very brave, mouse Brain was not accepted to summer school of young villains. He was upset and decided to postpone his plans of taking over the world, but to become a photographer instead.
As you may know, the... | ```python
m, n = map(int, input().split())
a = False
for i in range(m):
b = input().split()
if 'C' in b or 'M' in b or 'Y' in b:
a = True
print('#Black&White' if a == False else '#Color')
``` | 3 | |
104 | A | Blackjack | PROGRAMMING | 800 | [
"implementation"
] | A. Blackjack | 2 | 256 | One rainy gloomy evening when all modules hid in the nearby cafes to drink hot energetic cocktails, the Hexadecimal virus decided to fly over the Mainframe to look for a Great Idea. And she has found one!
Why not make her own Codeforces, with blackjack and other really cool stuff? Many people will surely be willing to... | The only line contains *n* (1<=β€<=*n*<=β€<=25) β the required sum of points. | Print the numbers of ways to get the second card in the required way if the first card is the queen of spades. | [
"12\n",
"20\n",
"10\n"
] | [
"4",
"15",
"0"
] | In the first sample only four two's of different suits can earn the required sum of points.
In the second sample we can use all tens, jacks, queens and kings; overall it's 15 cards, as the queen of spades (as any other card) is only present once in the pack of cards and it's already in use.
In the third sample there ... | 500 | [
{
"input": "12",
"output": "4"
},
{
"input": "20",
"output": "15"
},
{
"input": "10",
"output": "0"
},
{
"input": "11",
"output": "4"
},
{
"input": "15",
"output": "4"
},
{
"input": "18",
"output": "4"
},
{
"input": "25",
"output": "0"
... | 1,659,180,105 | 2,147,483,647 | Python 3 | OK | TESTS | 25 | 92 | 0 | # Blackjack
def solution(n):
if n <= 10 or n > 21:
return 0
n -= 10
if n != 10:
return 4
else:
return 15
n = int(input())
res = solution(n)
print(res) | Title: Blackjack
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
One rainy gloomy evening when all modules hid in the nearby cafes to drink hot energetic cocktails, the Hexadecimal virus decided to fly over the Mainframe to look for a Great Idea. And she has found one!
Why not make her own Co... | ```python
# Blackjack
def solution(n):
if n <= 10 or n > 21:
return 0
n -= 10
if n != 10:
return 4
else:
return 15
n = int(input())
res = solution(n)
print(res)
``` | 3.977 |
59 | A | Word | PROGRAMMING | 800 | [
"implementation",
"strings"
] | A. Word | 2 | 256 | Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At th... | The first line contains a word *s* β it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100. | Print the corrected word *s*. If the given word *s* has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one. | [
"HoUse\n",
"ViP\n",
"maTRIx\n"
] | [
"house\n",
"VIP\n",
"matrix\n"
] | none | 500 | [
{
"input": "HoUse",
"output": "house"
},
{
"input": "ViP",
"output": "VIP"
},
{
"input": "maTRIx",
"output": "matrix"
},
{
"input": "BNHWpnpawg",
"output": "bnhwpnpawg"
},
{
"input": "VTYGP",
"output": "VTYGP"
},
{
"input": "CHNenu",
"output": "chn... | 1,582,377,182 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 218 | 0 | s=input()
ct=0
for c in s:
if c==c.upper(): ct+=1
print(s.upper() if ct>(len(s)/2) else s.lower()) | Title: Word
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it ei... | ```python
s=input()
ct=0
for c in s:
if c==c.upper(): ct+=1
print(s.upper() if ct>(len(s)/2) else s.lower())
``` | 3.9455 |
709 | A | Juicer | PROGRAMMING | 900 | [
"implementation"
] | null | null | Kolya is going to make fresh orange juice. He has *n* oranges of sizes *a*1,<=*a*2,<=...,<=*a**n*. Kolya will put them in the juicer in the fixed order, starting with orange of size *a*1, then orange of size *a*2 and so on. To be put in the juicer the orange must have size not exceeding *b*, so if Kolya sees an orange ... | The first line of the input contains three integers *n*, *b* and *d* (1<=β€<=*n*<=β€<=100<=000, 1<=β€<=*b*<=β€<=*d*<=β€<=1<=000<=000)Β β the number of oranges, the maximum size of the orange that fits in the juicer and the value *d*, which determines the condition when the waste section should be emptied.
The second line co... | Print one integerΒ β the number of times Kolya will have to empty the waste section. | [
"2 7 10\n5 6\n",
"1 5 10\n7\n",
"3 10 10\n5 7 7\n",
"1 1 1\n1\n"
] | [
"1\n",
"0\n",
"1\n",
"0\n"
] | In the first sample, Kolya will squeeze the juice from two oranges and empty the waste section afterwards.
In the second sample, the orange won't fit in the juicer so Kolya will have no juice at all. | 500 | [
{
"input": "2 7 10\n5 6",
"output": "1"
},
{
"input": "1 5 10\n7",
"output": "0"
},
{
"input": "3 10 10\n5 7 7",
"output": "1"
},
{
"input": "1 1 1\n1",
"output": "0"
},
{
"input": "2 951637 951638\n44069 951637",
"output": "1"
},
{
"input": "50 100 12... | 1,696,814,549 | 2,147,483,647 | PyPy 3 | OK | TESTS | 58 | 155 | 10,444,800 | n, b, d = map(int, input().split())
sizes = list(map(int, input().split()))
waste = 0
# Create a new list with only the sizes that are less than or equal to 'b'
filtered_sizes = [size for size in sizes if size <= b]
# Calculate waste
current_waste = 0
for size in filtered_sizes:
current_waste += size
... | Title: Juicer
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Kolya is going to make fresh orange juice. He has *n* oranges of sizes *a*1,<=*a*2,<=...,<=*a**n*. Kolya will put them in the juicer in the fixed order, starting with orange of size *a*1, then orange of size *a*2 and so on. To b... | ```python
n, b, d = map(int, input().split())
sizes = list(map(int, input().split()))
waste = 0
# Create a new list with only the sizes that are less than or equal to 'b'
filtered_sizes = [size for size in sizes if size <= b]
# Calculate waste
current_waste = 0
for size in filtered_sizes:
current_waste ... | 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,564,910,499 | 2,147,483,647 | PyPy 3 | OK | TESTS | 74 | 140 | 102,400 | def id(v,n):
if not v[0]%2 or not v[-1]%2:
return 0
if n%2:
return 1
else:
return 0
n=int(input())
v=[int(c) for c in input().split()]
if id(v,n):
t='Yes'
else:
t='No'
print(t) | 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
def id(v,n):
if not v[0]%2 or not v[-1]%2:
return 0
if n%2:
return 1
else:
return 0
n=int(input())
v=[int(c) for c in input().split()]
if id(v,n):
t='Yes'
else:
t='No'
print(t)
``` | 3 | |
620 | A | Professor GukiZ's Robot | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | Professor GukiZ makes a new robot. The robot are in the point with coordinates (*x*1,<=*y*1) and should go to the point (*x*2,<=*y*2). In a single step the robot can change any of its coordinates (maybe both of them) by one (decrease or increase). So the robot can move in one of the 8 directions. Find the minimal numbe... | The first line contains two integers *x*1,<=*y*1 (<=-<=109<=β€<=*x*1,<=*y*1<=β€<=109) β the start position of the robot.
The second line contains two integers *x*2,<=*y*2 (<=-<=109<=β€<=*x*2,<=*y*2<=β€<=109) β the finish position of the robot. | Print the only integer *d* β the minimal number of steps to get the finish position. | [
"0 0\n4 5\n",
"3 4\n6 1\n"
] | [
"5\n",
"3\n"
] | In the first example robot should increase both of its coordinates by one four times, so it will be in position (4,β4). After that robot should simply increase its *y* coordinate and get the finish position.
In the second example robot should simultaneously increase *x* coordinate and decrease *y* coordinate by one th... | 0 | [
{
"input": "0 0\n4 5",
"output": "5"
},
{
"input": "3 4\n6 1",
"output": "3"
},
{
"input": "0 0\n4 6",
"output": "6"
},
{
"input": "1 1\n-3 -5",
"output": "6"
},
{
"input": "-1 -1\n-10 100",
"output": "101"
},
{
"input": "1 -1\n100 -100",
"output":... | 1,584,383,996 | 2,147,483,647 | PyPy 3 | OK | TESTS | 75 | 156 | 0 | x,y=map(int,input().split())
a,b=map(int,input().split())
s=abs(x-a)
e=abs(y-b)
print(max(s,e))
| Title: Professor GukiZ's Robot
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Professor GukiZ makes a new robot. The robot are in the point with coordinates (*x*1,<=*y*1) and should go to the point (*x*2,<=*y*2). In a single step the robot can change any of its coordinates (maybe both of ... | ```python
x,y=map(int,input().split())
a,b=map(int,input().split())
s=abs(x-a)
e=abs(y-b)
print(max(s,e))
``` | 3 | |
894 | A | QAQ | PROGRAMMING | 800 | [
"brute force",
"dp"
] | null | null | "QAQ" is a word to denote an expression of crying. Imagine "Q" as eyes with tears and "A" as a mouth.
Now Diamond has given Bort a string consisting of only uppercase English letters of length *n*. There is a great number of "QAQ" in the string (Diamond is so cute!).
Bort wants to know how many subsequences "QAQ" are... | The only line contains a string of length *n* (1<=β€<=*n*<=β€<=100). It's guaranteed that the string only contains uppercase English letters. | Print a single integerΒ β the number of subsequences "QAQ" in the string. | [
"QAQAQYSYIOIWIN\n",
"QAQQQZZYNOIWIN\n"
] | [
"4\n",
"3\n"
] | In the first example there are 4 subsequences "QAQ": "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN". | 500 | [
{
"input": "QAQAQYSYIOIWIN",
"output": "4"
},
{
"input": "QAQQQZZYNOIWIN",
"output": "3"
},
{
"input": "QA",
"output": "0"
},
{
"input": "IAQVAQZLQBQVQFTQQQADAQJA",
"output": "24"
},
{
"input": "QQAAQASGAYAAAAKAKAQIQEAQAIAAIAQQQQQ",
"output": "378"
},
{
... | 1,686,259,940 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 43 | 78 | 2,560,000 | import collections
import math
def main():
# t = int(input())
# for _ in range(t):
#n = int(input())
s = input()
#a = list(map(int,input().split()))
#s = input()
solution(s)
# def isPalindrome(s):
# left = 0
# right = len(s)-1
# while left<right:
# if s[left]!=s[right]:
... | Title: QAQ
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
"QAQ" is a word to denote an expression of crying. Imagine "Q" as eyes with tears and "A" as a mouth.
Now Diamond has given Bort a string consisting of only uppercase English letters of length *n*. There is a great number of "QAQ"... | ```python
import collections
import math
def main():
# t = int(input())
# for _ in range(t):
#n = int(input())
s = input()
#a = list(map(int,input().split()))
#s = input()
solution(s)
# def isPalindrome(s):
# left = 0
# right = len(s)-1
# while left<right:
# if s[left]!=... | 3 | |
330 | A | Cakeminator | PROGRAMMING | 800 | [
"brute force",
"implementation"
] | null | null | You are given a rectangular cake, represented as an *r*<=Γ<=*c* grid. Each cell either has an evil strawberry, or is empty. For example, a 3<=Γ<=4 cake may look as follows:
The cakeminator is going to eat the cake! Each time he eats, he chooses a row or a column that does not contain any evil strawberries and contains... | The first line contains two integers *r* and *c* (2<=β€<=*r*,<=*c*<=β€<=10), denoting the number of rows and the number of columns of the cake. The next *r* lines each contains *c* characters β the *j*-th character of the *i*-th line denotes the content of the cell at row *i* and column *j*, and is either one of these:
... | Output the maximum number of cake cells that the cakeminator can eat. | [
"3 4\nS...\n....\n..S.\n"
] | [
"8\n"
] | For the first example, one possible way to eat the maximum number of cake cells is as follows (perform 3 eats). | 500 | [
{
"input": "3 4\nS...\n....\n..S.",
"output": "8"
},
{
"input": "2 2\n..\n..",
"output": "4"
},
{
"input": "2 2\nSS\nSS",
"output": "0"
},
{
"input": "7 3\nS..\nS..\nS..\nS..\nS..\nS..\nS..",
"output": "14"
},
{
"input": "3 5\n..S..\nSSSSS\n..S..",
"output": "... | 1,638,799,961 | 2,147,483,647 | Python 3 | OK | TESTS | 42 | 124 | 0 | r, c= map(int, input().split())
ar=[]
for i in range(r):
ar.append(input())
arr=[]
arc=[]
for i in range(r):
for j in range(c):
if ar[i][j]=="S":
arr.append(i)
arc.append(j)
rc=0
cc=0
for i in range(r):
if i not in arr:
rc += 1
for i in range(c... | Title: Cakeminator
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a rectangular cake, represented as an *r*<=Γ<=*c* grid. Each cell either has an evil strawberry, or is empty. For example, a 3<=Γ<=4 cake may look as follows:
The cakeminator is going to eat the cake! Each ti... | ```python
r, c= map(int, input().split())
ar=[]
for i in range(r):
ar.append(input())
arr=[]
arc=[]
for i in range(r):
for j in range(c):
if ar[i][j]=="S":
arr.append(i)
arc.append(j)
rc=0
cc=0
for i in range(r):
if i not in arr:
rc += 1
for i ... | 3 | |
199 | A | Hexadecimal's theorem | PROGRAMMING | 900 | [
"brute force",
"constructive algorithms",
"implementation",
"number theory"
] | null | null | Recently, a chaotic virus Hexadecimal advanced a new theorem which will shake the Universe. She thinks that each Fibonacci number can be represented as sum of three not necessary different Fibonacci numbers.
Let's remember how Fibonacci numbers can be calculated. *F*0<==<=0, *F*1<==<=1, and all the next numbers are *F... | The input contains of a single integer *n* (0<=β€<=*n*<=<<=109) β the number that should be represented by the rules described above. It is guaranteed that *n* is a Fibonacci number. | Output three required numbers: *a*, *b* and *c*. If there is no answer for the test you have to print "I'm too stupid to solve this problem" without the quotes.
If there are multiple answers, print any of them. | [
"3\n",
"13\n"
] | [
"1 1 1\n",
"2 3 8\n"
] | none | 500 | [
{
"input": "3",
"output": "1 1 1"
},
{
"input": "13",
"output": "2 3 8"
},
{
"input": "0",
"output": "0 0 0"
},
{
"input": "1",
"output": "1 0 0"
},
{
"input": "2",
"output": "1 1 0"
},
{
"input": "1597",
"output": "233 377 987"
},
{
"input... | 1,621,605,243 | 2,147,483,647 | Python 3 | OK | TESTS | 54 | 156 | 0 | n = int(input())
fib = [0, 0, 0, 1]
while fib[len(fib) - 1] + fib[len(fib) - 3] + fib[len(fib) - 4] < n:
fib.append(fib[-1] + fib[-2])
if n == 0:
print(0, 0, 0)
elif n == 2:
print(0, 1, 1)
else:
if fib[len(fib) - 1] + fib[len(fib) - 3] + fib[len(fib) - 4] != n:
print("I'm too stupid to solve this proble... | Title: Hexadecimal's theorem
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Recently, a chaotic virus Hexadecimal advanced a new theorem which will shake the Universe. She thinks that each Fibonacci number can be represented as sum of three not necessary different Fibonacci numbers.
Let'... | ```python
n = int(input())
fib = [0, 0, 0, 1]
while fib[len(fib) - 1] + fib[len(fib) - 3] + fib[len(fib) - 4] < n:
fib.append(fib[-1] + fib[-2])
if n == 0:
print(0, 0, 0)
elif n == 2:
print(0, 1, 1)
else:
if fib[len(fib) - 1] + fib[len(fib) - 3] + fib[len(fib) - 4] != n:
print("I'm too stupid to solve t... | 3 | |
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,696,929,377 | 2,147,483,647 | Python 3 | OK | TESTS | 28 | 46 | 0 | rows, columns = input().split()
rows, columns = int(rows), int(columns)
no_of_steps = 0
while rows >= 1 and columns >= 1:
rows -= 1; columns -= 1
no_of_steps += 1
if no_of_steps % 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
rows, columns = input().split()
rows, columns = int(rows), int(columns)
no_of_steps = 0
while rows >= 1 and columns >= 1:
rows -= 1; columns -= 1
no_of_steps += 1
if no_of_steps % 2 == 0:
print("Malvika")
else:
print("Akshat")
``` | 3 | |
479 | A | Expression | PROGRAMMING | 1,000 | [
"brute force",
"math"
] | null | null | Petya studies in a school and he adores Maths. His class has been studying arithmetic expressions. On the last class the teacher wrote three positive integers *a*, *b*, *c* on the blackboard. The task was to insert signs of operations '+' and '*', and probably brackets between the numbers so that the value of the resul... | The input contains three integers *a*, *b* and *c*, each on a single line (1<=β€<=*a*,<=*b*,<=*c*<=β€<=10). | Print the maximum value of the expression that you can obtain. | [
"1\n2\n3\n",
"2\n10\n3\n"
] | [
"9\n",
"60\n"
] | none | 500 | [
{
"input": "1\n2\n3",
"output": "9"
},
{
"input": "2\n10\n3",
"output": "60"
},
{
"input": "1\n1\n1",
"output": "3"
},
{
"input": "1\n2\n1",
"output": "4"
},
{
"input": "10\n10\n10",
"output": "1000"
},
{
"input": "5\n1\n3",
"output": "20"
},
{... | 1,687,357,431 | 2,147,483,647 | Python 3 | OK | TESTS | 29 | 46 | 0 | a=int(input())
b=int(input())
c=int(input())
if a==1 and c==1:
print(b+2)
elif a==b==1 or b==c==1:
print(2*max(a,c))
elif b==1:
print((min(a,c)+1)*max(a,c))
elif a==1 or c==1:
print((b+min(a,c))*max(a,c))
else:
print(a*b*c)
| Title: Expression
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya studies in a school and he adores Maths. His class has been studying arithmetic expressions. On the last class the teacher wrote three positive integers *a*, *b*, *c* on the blackboard. The task was to insert signs of ... | ```python
a=int(input())
b=int(input())
c=int(input())
if a==1 and c==1:
print(b+2)
elif a==b==1 or b==c==1:
print(2*max(a,c))
elif b==1:
print((min(a,c)+1)*max(a,c))
elif a==1 or c==1:
print((b+min(a,c))*max(a,c))
else:
print(a*b*c)
``` | 3 | |
780 | A | Andryusha and Socks | PROGRAMMING | 800 | [
"implementation"
] | null | null | Andryusha is an orderly boy and likes to keep things in their place.
Today he faced a problem to put his socks in the wardrobe. He has *n* distinct pairs of socks which are initially in a bag. The pairs are numbered from 1 to *n*. Andryusha wants to put paired socks together and put them in the wardrobe. He takes the ... | The first line contains the single integer *n* (1<=β€<=*n*<=β€<=105)Β β the number of sock pairs.
The second line contains 2*n* integers *x*1,<=*x*2,<=...,<=*x*2*n* (1<=β€<=*x**i*<=β€<=*n*), which describe the order in which Andryusha took the socks from the bag. More precisely, *x**i* means that the *i*-th sock Andryusha ... | Print single integerΒ β the maximum number of socks that were on the table at the same time. | [
"1\n1 1\n",
"3\n2 1 1 3 2 3\n"
] | [
"1\n",
"2\n"
] | In the first example Andryusha took a sock from the first pair and put it on the table. Then he took the next sock which is from the first pair as well, so he immediately puts both socks to the wardrobe. Thus, at most one sock was on the table at the same time.
In the second example Andryusha behaved as follows:
- ... | 500 | [
{
"input": "1\n1 1",
"output": "1"
},
{
"input": "3\n2 1 1 3 2 3",
"output": "2"
},
{
"input": "5\n5 1 3 2 4 3 1 2 4 5",
"output": "5"
},
{
"input": "10\n4 2 6 3 4 8 7 1 1 5 2 10 6 8 3 5 10 9 9 7",
"output": "6"
},
{
"input": "50\n30 47 31 38 37 50 36 43 9 23 2 2 ... | 1,579,158,857 | 2,147,483,647 | PyPy 3 | OK | TESTS | 56 | 280 | 18,022,400 | n = int(input())
l = list(map(int, input().split()))
a = set()
c = 0
res = []
for i in range(2 * n):
a.add(l[i])
if c < len(a):
c+=1
else:
a.discard(l[i])
res.append(c)
c = len(a)
print(max(res))
| Title: Andryusha and Socks
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Andryusha is an orderly boy and likes to keep things in their place.
Today he faced a problem to put his socks in the wardrobe. He has *n* distinct pairs of socks which are initially in a bag. The pairs are numbere... | ```python
n = int(input())
l = list(map(int, input().split()))
a = set()
c = 0
res = []
for i in range(2 * n):
a.add(l[i])
if c < len(a):
c+=1
else:
a.discard(l[i])
res.append(c)
c = len(a)
print(max(res))
``` | 3 | |
570 | A | Elections | PROGRAMMING | 1,100 | [
"implementation"
] | null | null | The country of Byalechinsk is running elections involving *n* candidates. The country consists of *m* cities. We know how many people in each city voted for each candidate.
The electoral system in the country is pretty unusual. At the first stage of elections the votes are counted for each city: it is assumed that in ... | The first line of the input contains two integers *n*, *m* (1<=β€<=*n*,<=*m*<=β€<=100) β the number of candidates and of cities, respectively.
Each of the next *m* lines contains *n* non-negative integers, the *j*-th number in the *i*-th line *a**ij* (1<=β€<=*j*<=β€<=*n*, 1<=β€<=*i*<=β€<=*m*, 0<=β€<=*a**ij*<=β€<=109) denotes ... | Print a single number β the index of the candidate who won the elections. The candidates are indexed starting from one. | [
"3 3\n1 2 3\n2 3 1\n1 2 1\n",
"3 4\n10 10 3\n5 1 6\n2 2 2\n1 5 7\n"
] | [
"2",
"1"
] | Note to the first sample test. At the first stage city 1 chosen candidate 3, city 2 chosen candidate 2, city 3 chosen candidate 2. The winner is candidate 2, he gained 2 votes.
Note to the second sample test. At the first stage in city 1 candidates 1 and 2 got the same maximum number of votes, but candidate 1 has a sm... | 500 | [
{
"input": "3 3\n1 2 3\n2 3 1\n1 2 1",
"output": "2"
},
{
"input": "3 4\n10 10 3\n5 1 6\n2 2 2\n1 5 7",
"output": "1"
},
{
"input": "1 3\n5\n3\n2",
"output": "1"
},
{
"input": "3 1\n1 2 3",
"output": "3"
},
{
"input": "3 1\n100 100 100",
"output": "1"
},
{... | 1,611,205,999 | 2,147,483,647 | PyPy 3 | OK | TESTS | 62 | 109 | 1,638,400 | n,m=map(int,input().split())
z=[0]*n
for x in range(m):
k=list(map(int,input().split()))
c=-1
for y in range(n):
if k[y]>c:
c=k[y]
ind=y
z[ind]+=1
q=max(z)
for x in range(n):
if z[x]==q:
print(x+1)
break | Title: Elections
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The country of Byalechinsk is running elections involving *n* candidates. The country consists of *m* cities. We know how many people in each city voted for each candidate.
The electoral system in the country is pretty unusu... | ```python
n,m=map(int,input().split())
z=[0]*n
for x in range(m):
k=list(map(int,input().split()))
c=-1
for y in range(n):
if k[y]>c:
c=k[y]
ind=y
z[ind]+=1
q=max(z)
for x in range(n):
if z[x]==q:
print(x+1)
break
``` | 3 | |
459 | A | Pashmak and Garden | PROGRAMMING | 1,200 | [
"implementation"
] | null | null | Pashmak has fallen in love with an attractive girl called Parmida since one year ago...
Today, Pashmak set up a meeting with his partner in a romantic garden. Unfortunately, Pashmak has forgotten where the garden is. But he remembers that the garden looks like a square with sides parallel to the coordinate axes. He al... | The first line contains four space-separated *x*1,<=*y*1,<=*x*2,<=*y*2 (<=-<=100<=β€<=*x*1,<=*y*1,<=*x*2,<=*y*2<=β€<=100) integers, where *x*1 and *y*1 are coordinates of the first tree and *x*2 and *y*2 are coordinates of the second tree. It's guaranteed that the given points are distinct. | If there is no solution to the problem, print -1. Otherwise print four space-separated integers *x*3,<=*y*3,<=*x*4,<=*y*4 that correspond to the coordinates of the two other trees. If there are several solutions you can output any of them.
Note that *x*3,<=*y*3,<=*x*4,<=*y*4 must be in the range (<=-<=1000<=β€<=*x*3,<... | [
"0 0 0 1\n",
"0 0 1 1\n",
"0 0 1 2\n"
] | [
"1 0 1 1\n",
"0 1 1 0\n",
"-1\n"
] | none | 500 | [
{
"input": "0 0 0 1",
"output": "1 0 1 1"
},
{
"input": "0 0 1 1",
"output": "0 1 1 0"
},
{
"input": "0 0 1 2",
"output": "-1"
},
{
"input": "-100 -100 100 100",
"output": "-100 100 100 -100"
},
{
"input": "-100 -100 99 100",
"output": "-1"
},
{
"input... | 1,679,386,669 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 74 | 62 | 0 | x1, y1, x2, y2 = map(int, input().split())
if x1 == x2:
x3 = x4 = x1 + abs(y1-y2)
y3 = y1
y4 = y2
print(x3,y3,x4,y4)
elif y1 == y2:
y3 = y4 = y1 + abs(x1-x2)
x3 = x1
x4 = x2
print(x3,y3,x4,y4)
elif abs(x1-x2) == abs(y1-y2):
print(x1,y2,x2,y1)
else: print(-1) | Title: Pashmak and Garden
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Pashmak has fallen in love with an attractive girl called Parmida since one year ago...
Today, Pashmak set up a meeting with his partner in a romantic garden. Unfortunately, Pashmak has forgotten where the garden is... | ```python
x1, y1, x2, y2 = map(int, input().split())
if x1 == x2:
x3 = x4 = x1 + abs(y1-y2)
y3 = y1
y4 = y2
print(x3,y3,x4,y4)
elif y1 == y2:
y3 = y4 = y1 + abs(x1-x2)
x3 = x1
x4 = x2
print(x3,y3,x4,y4)
elif abs(x1-x2) == abs(y1-y2):
print(x1,y2,x2,y1)
else: print(-1)
``... | 3 | |
919 | A | Supermarket | PROGRAMMING | 800 | [
"brute force",
"greedy",
"implementation"
] | null | null | We often go to supermarkets to buy some fruits or vegetables, and on the tag there prints the price for a kilo. But in some supermarkets, when asked how much the items are, the clerk will say that $a$ yuan for $b$ kilos (You don't need to care about what "yuan" is), the same as $a/b$ yuan for a kilo.
Now imagine you'd... | The first line contains two positive integers $n$ and $m$ ($1 \leq n \leq 5\,000$, $1 \leq m \leq 100$), denoting that there are $n$ supermarkets and you want to buy $m$ kilos of apples.
The following $n$ lines describe the information of the supermarkets. Each line contains two positive integers $a, b$ ($1 \leq a, b ... | The only line, denoting the minimum cost for $m$ kilos of apples. Please make sure that the absolute or relative error between your answer and the correct answer won't exceed $10^{-6}$.
Formally, let your answer be $x$, and the jury's answer be $y$. Your answer is considered correct if $\frac{|x - y|}{\max{(1, |y|)}} ... | [
"3 5\n1 2\n3 4\n1 3\n",
"2 1\n99 100\n98 99\n"
] | [
"1.66666667\n",
"0.98989899\n"
] | In the first sample, you are supposed to buy $5$ kilos of apples in supermarket $3$. The cost is $5/3$ yuan.
In the second sample, you are supposed to buy $1$ kilo of apples in supermarket $2$. The cost is $98/99$ yuan. | 500 | [
{
"input": "3 5\n1 2\n3 4\n1 3",
"output": "1.66666667"
},
{
"input": "2 1\n99 100\n98 99",
"output": "0.98989899"
},
{
"input": "50 37\n78 49\n96 4\n86 62\n28 4\n19 2\n79 43\n79 92\n95 35\n33 60\n54 84\n90 25\n2 25\n53 21\n86 52\n72 25\n6 78\n41 46\n3 68\n42 89\n33 35\n57 43\n99 45\n1 8... | 1,656,551,142 | 2,147,483,647 | Python 3 | OK | TESTS | 43 | 61 | 0 | (n, m) = map(int, input().split(' '))
comparison_price = []
for i in range(n):
(a, b) = map(int, input().split(' '))
average = a / b
comparison_price.append(average)
print(min(comparison_price) * m)
| Title: Supermarket
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
We often go to supermarkets to buy some fruits or vegetables, and on the tag there prints the price for a kilo. But in some supermarkets, when asked how much the items are, the clerk will say that $a$ yuan for $b$ kilos (Yo... | ```python
(n, m) = map(int, input().split(' '))
comparison_price = []
for i in range(n):
(a, b) = map(int, input().split(' '))
average = a / b
comparison_price.append(average)
print(min(comparison_price) * m)
``` | 3 | |
631 | B | Print Check | PROGRAMMING | 1,200 | [
"constructive algorithms",
"implementation"
] | null | null | Kris works in a large company "Blake Technologies". As a best engineer of the company he was assigned a task to develop a printer that will be able to print horizontal and vertical strips. First prototype is already built and Kris wants to tests it. He wants you to implement the program that checks the result of the pr... | The first line of the input contains three integers *n*, *m* and *k* (1<=<=β€<=<=*n*,<=<=*m*<=<=β€<=5000, *n*Β·*m*<=β€<=100<=000, 1<=β€<=*k*<=β€<=100<=000)Β β the dimensions of the sheet and the number of operations, respectively.
Each of the next *k* lines contains the description of exactly one query:
- 1Β *r**i*Β *a**i* ... | Print *n* lines containing *m* integers eachΒ β the resulting table after all operations are applied. | [
"3 3 3\n1 1 3\n2 2 1\n1 2 2\n",
"5 3 5\n1 1 1\n1 3 1\n1 5 1\n2 1 1\n2 3 1\n"
] | [
"3 1 3 \n2 2 2 \n0 1 0 \n",
"1 1 1 \n1 0 1 \n1 1 1 \n1 0 1 \n1 1 1 \n"
] | The figure below shows all three operations for the first sample step by step. The cells that were painted on the corresponding step are marked gray. | 1,000 | [
{
"input": "3 3 3\n1 1 3\n2 2 1\n1 2 2",
"output": "3 1 3 \n2 2 2 \n0 1 0 "
},
{
"input": "5 3 5\n1 1 1\n1 3 1\n1 5 1\n2 1 1\n2 3 1",
"output": "1 1 1 \n1 0 1 \n1 1 1 \n1 0 1 \n1 1 1 "
},
{
"input": "5 5 4\n1 2 1\n1 4 1\n2 2 1\n2 4 1",
"output": "0 1 0 1 0 \n1 1 1 1 1 \n0 1 0 1 0 \n1... | 1,513,883,683 | 2,147,483,647 | Python 3 | OK | TESTS | 56 | 857 | 6,246,400 | # speedtest
n, m, k = map(int, input().split())
row = [0]*n
col = [0]*m
for i in range(k):
t, rc, a = map(int, input().split())
rc -= 1
if t == 1:
row[rc] = (i, a)
else:
col[rc] = (i, a)
for i in range(n):
for j in range(m):
if type(row[i]) == tuple and type(... | Title: Print Check
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Kris works in a large company "Blake Technologies". As a best engineer of the company he was assigned a task to develop a printer that will be able to print horizontal and vertical strips. First prototype is already built a... | ```python
# speedtest
n, m, k = map(int, input().split())
row = [0]*n
col = [0]*m
for i in range(k):
t, rc, a = map(int, input().split())
rc -= 1
if t == 1:
row[rc] = (i, a)
else:
col[rc] = (i, a)
for i in range(n):
for j in range(m):
if type(row[i]) == tuple... | 3 | |
1 | A | Theatre Square | PROGRAMMING | 1,000 | [
"math"
] | A. Theatre Square | 1 | 256 | Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=Γ<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size *a*<=Γ<=*a*.
What is the least number of flagstones needed to pave the... | The input contains three positive integer numbers in the first line: *n*,<=<=*m* and *a* (1<=β€<=<=*n*,<=*m*,<=*a*<=β€<=109). | Write the needed number of flagstones. | [
"6 6 4\n"
] | [
"4\n"
] | none | 0 | [
{
"input": "6 6 4",
"output": "4"
},
{
"input": "1 1 1",
"output": "1"
},
{
"input": "2 1 1",
"output": "2"
},
{
"input": "1 2 1",
"output": "2"
},
{
"input": "2 2 1",
"output": "4"
},
{
"input": "2 1 2",
"output": "1"
},
{
"input": "1 1 3"... | 1,693,416,087 | 2,147,483,647 | Python 3 | OK | TESTS | 20 | 46 | 0 | import math
# Read input values
n, m, a = map(int, input().split())
# Calculate the number of flagstones needed for each dimension
num_flagstones_n = math.ceil(n / a)
num_flagstones_m = math.ceil(m / a)
# Calculate the total number of flagstones needed
total_flagstones = num_flagstones_n * num_flagstones_m... | Title: Theatre Square
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=Γ<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each ... | ```python
import math
# Read input values
n, m, a = map(int, input().split())
# Calculate the number of flagstones needed for each dimension
num_flagstones_n = math.ceil(n / a)
num_flagstones_m = math.ceil(m / a)
# Calculate the total number of flagstones needed
total_flagstones = num_flagstones_n * num_fl... | 3.977 |
873 | D | Merge Sort | PROGRAMMING | 1,800 | [
"constructive algorithms",
"divide and conquer"
] | null | null | Merge sort is a well-known sorting algorithm. The main function that sorts the elements of array *a* with indices from [*l*,<=*r*) can be implemented as follows:
1. If the segment [*l*,<=*r*) is already sorted in non-descending order (that is, for any *i* such that *l*<=β€<=*i*<=<<=*r*<=-<=1 *a*[*i*]<=β€<=*a*[*i*<=+... | The first line contains two numbers *n* and *k* (1<=β€<=*n*<=β€<=100000, 1<=β€<=*k*<=β€<=200000) β the size of a desired permutation and the number of *mergesort* calls required to sort it. | If a permutation of size *n* such that there will be exactly *k* calls of *mergesort* while sorting it doesn't exist, output <=-<=1. Otherwise output *n* integer numbers *a*[0],<=*a*[1],<=...,<=*a*[*n*<=-<=1] β the elements of a permutation that would meet the required conditions. If there are multiple answers, print a... | [
"3 3\n",
"4 1\n",
"5 6\n"
] | [
"2 1 3 ",
"1 2 3 4 ",
"-1\n"
] | none | 0 | [
{
"input": "3 3",
"output": "2 1 3 "
},
{
"input": "4 1",
"output": "1 2 3 4 "
},
{
"input": "5 6",
"output": "-1"
},
{
"input": "100 100",
"output": "-1"
},
{
"input": "10000 10001",
"output": "3 1 5 2 7 4 8 10 6 12 9 13 15 11 17 14 18 20 16 22 19 23 25 21 27... | 1,646,610,144 | 2,147,483,647 | PyPy 3 | OK | TESTS | 36 | 202 | 9,420,800 | def swap(m,n):
temp= arr[m]
arr[m]=arr[n]
arr[n]=temp
def solve(arr,l,r,k):
global count
if count>=k or r-l<2:
return
else:
m=int((l+r)/2)
swap(m,m-1)
count+=2
solve(arr,l,m,k)
solve(arr,m,r,k)
n,k=input().split()
n=int(n)
k=... | Title: Merge Sort
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Merge sort is a well-known sorting algorithm. The main function that sorts the elements of array *a* with indices from [*l*,<=*r*) can be implemented as follows:
1. If the segment [*l*,<=*r*) is already sorted in non-desce... | ```python
def swap(m,n):
temp= arr[m]
arr[m]=arr[n]
arr[n]=temp
def solve(arr,l,r,k):
global count
if count>=k or r-l<2:
return
else:
m=int((l+r)/2)
swap(m,m-1)
count+=2
solve(arr,l,m,k)
solve(arr,m,r,k)
n,k=input().split()
n=... | 3 | |
50 | A | Domino piling | PROGRAMMING | 800 | [
"greedy",
"math"
] | A. Domino piling | 2 | 256 | You are given a rectangular board of *M*<=Γ<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=Γ<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions:
1. Each domino completely covers ... | In a single line you are given two integers *M* and *N* β board sizes in squares (1<=β€<=*M*<=β€<=*N*<=β€<=16). | Output one number β the maximal number of dominoes, which can be placed. | [
"2 4\n",
"3 3\n"
] | [
"4\n",
"4\n"
] | none | 500 | [
{
"input": "2 4",
"output": "4"
},
{
"input": "3 3",
"output": "4"
},
{
"input": "1 5",
"output": "2"
},
{
"input": "1 6",
"output": "3"
},
{
"input": "1 15",
"output": "7"
},
{
"input": "1 16",
"output": "8"
},
{
"input": "2 5",
"outpu... | 1,650,503,524 | 2,147,483,647 | Python 3 | OK | TESTS | 35 | 92 | 0 | m,n=map(int,input().split())
max_num=(m*n)//2
print(max_num)
| Title: Domino piling
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
You are given a rectangular board of *M*<=Γ<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=Γ<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as p... | ```python
m,n=map(int,input().split())
max_num=(m*n)//2
print(max_num)
``` | 3.977 |
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,686,055,197 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 26 | 62 | 0 | n,m = map(int,input().split())
n_copy = n - (m-1)
maxi = (n_copy * (n_copy-1)) // 2
a = n//m
mini = a * (n % m) + (m*a**2-m*a)//2
print(mini,maxi)
| 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
n,m = map(int,input().split())
n_copy = n - (m-1)
maxi = (n_copy * (n_copy-1)) // 2
a = n//m
mini = a * (n % m) + (m*a**2-m*a)//2
print(mini,maxi)
``` | 3 | |
1,003 | A | Polycarp's Pockets | PROGRAMMING | 800 | [
"implementation"
] | null | null | Polycarp has $n$ coins, the value of the $i$-th coin is $a_i$. Polycarp wants to distribute all the coins between his pockets, but he cannot put two coins with the same value into the same pocket.
For example, if Polycarp has got six coins represented as an array $a = [1, 2, 4, 3, 3, 2]$, he can distribute the coins i... | The first line of the input contains one integer $n$ ($1 \le n \le 100$) β the number of coins.
The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 100$) β values of coins. | Print only one integer β the minimum number of pockets Polycarp needs to distribute all the coins so no two coins with the same value are put into the same pocket. | [
"6\n1 2 4 3 3 2\n",
"1\n100\n"
] | [
"2\n",
"1\n"
] | none | 0 | [
{
"input": "6\n1 2 4 3 3 2",
"output": "2"
},
{
"input": "1\n100",
"output": "1"
},
{
"input": "100\n100 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 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100... | 1,635,424,447 | 2,147,483,647 | Python 3 | OK | TESTS | 37 | 62 | 4,505,600 | n=int(input())
a=[int(x) for x in input().split()]
a.sort()
a.append(0)
res,count=1,1
for i in range(1,len(a)):
if a[i]==a[i-1]:
count+=1
else:
if count>res:
res=count
count=1
print(res) | Title: Polycarp's Pockets
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp has $n$ coins, the value of the $i$-th coin is $a_i$. Polycarp wants to distribute all the coins between his pockets, but he cannot put two coins with the same value into the same pocket.
For example, if Po... | ```python
n=int(input())
a=[int(x) for x in input().split()]
a.sort()
a.append(0)
res,count=1,1
for i in range(1,len(a)):
if a[i]==a[i-1]:
count+=1
else:
if count>res:
res=count
count=1
print(res)
``` | 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,638,093,853 | 2,147,483,647 | Python 3 | OK | TESTS | 45 | 92 | 0 | from math import gcd
*a, n = map(int, input().split())
counter = 0
while n >= 0:
n -= gcd(a[counter % 2], n)
counter = 1 - counter
print(counter) | Title: Epic Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Simon and Antisimon play a game. Initially each player receives one fixed positive integer that doesn't change throughout the game. Simon receives number *a* and Antisimon receives number *b*. They also have a heap of *n* sto... | ```python
from math import gcd
*a, n = map(int, input().split())
counter = 0
while n >= 0:
n -= gcd(a[counter % 2], n)
counter = 1 - counter
print(counter)
``` | 3 | |
298 | A | Snow Footprints | PROGRAMMING | 1,300 | [
"greedy",
"implementation"
] | null | null | There is a straight snowy road, divided into *n* blocks. The blocks are numbered from 1 to *n* from left to right. If one moves from the *i*-th block to the (*i*<=+<=1)-th block, he will leave a right footprint on the *i*-th block. Similarly, if one moves from the *i*-th block to the (*i*<=-<=1)-th block, he will leave... | The first line of the input contains integer *n* (3<=β€<=*n*<=β€<=1000).
The second line contains the description of the road β the string that consists of *n* characters. Each character will be either "." (a block without footprint), or "L" (a block with a left footprint), "R" (a block with a right footprint).
It's gu... | Print two space-separated integers β the values of *s* and *t*. If there are several possible solutions you can print any of them. | [
"9\n..RRLL...\n",
"11\n.RRRLLLLL..\n"
] | [
"3 4\n",
"7 5\n"
] | The first test sample is the one in the picture. | 500 | [
{
"input": "11\n.RRRLLLLL..",
"output": "7 5"
},
{
"input": "4\n.RL.",
"output": "3 2"
},
{
"input": "3\n.L.",
"output": "2 1"
},
{
"input": "3\n.R.",
"output": "2 3"
}
] | 1,605,270,041 | 2,147,483,647 | Python 3 | OK | TESTS | 23 | 218 | 307,200 | n = int(input())
myStr = input()
tempListL = 0
tempListR = 0
if myStr.find("R") == -1 :
forRevarse = range(len(myStr) , 0 , -1)
for i in forRevarse :
if myStr[i - 1] == "L" :
tempListL = i
break
else:
continue
print(tempListL , myStr.index("L")... | Title: Snow Footprints
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There is a straight snowy road, divided into *n* blocks. The blocks are numbered from 1 to *n* from left to right. If one moves from the *i*-th block to the (*i*<=+<=1)-th block, he will leave a right footprint on the *... | ```python
n = int(input())
myStr = input()
tempListL = 0
tempListR = 0
if myStr.find("R") == -1 :
forRevarse = range(len(myStr) , 0 , -1)
for i in forRevarse :
if myStr[i - 1] == "L" :
tempListL = i
break
else:
continue
print(tempListL , myStr.... | 3 | |
129 | B | Students and Shoelaces | PROGRAMMING | 1,200 | [
"brute force",
"dfs and similar",
"graphs",
"implementation"
] | null | null | Anna and Maria are in charge of the math club for junior students. When the club gathers together, the students behave badly. They've brought lots of shoe laces to the club and got tied with each other. Specifically, each string ties together two students. Besides, if two students are tied, then the lace connects the f... | The first line contains two integers *n* and *m* β the initial number of students and laces (). The students are numbered from 1 to *n*, and the laces are numbered from 1 to *m*. Next *m* lines each contain two integers *a* and *b* β the numbers of students tied by the *i*-th lace (1<=β€<=*a*,<=*b*<=β€<=*n*,<=*a*<=β <=*b*... | Print the single number β the number of groups of students that will be kicked out from the club. | [
"3 3\n1 2\n2 3\n3 1\n",
"6 3\n1 2\n2 3\n3 4\n",
"6 5\n1 4\n2 4\n3 4\n5 4\n6 4\n"
] | [
"0\n",
"2\n",
"1\n"
] | In the first sample Anna and Maria won't kick out any group of students β in the initial position every student is tied to two other students and Anna won't be able to reprimand anyone.
In the second sample four students are tied in a chain and two more are running by themselves. First Anna and Maria kick out the two ... | 1,000 | [
{
"input": "3 3\n1 2\n2 3\n3 1",
"output": "0"
},
{
"input": "6 3\n1 2\n2 3\n3 4",
"output": "2"
},
{
"input": "6 5\n1 4\n2 4\n3 4\n5 4\n6 4",
"output": "1"
},
{
"input": "100 0",
"output": "0"
},
{
"input": "5 5\n1 2\n2 3\n3 4\n4 5\n5 1",
"output": "0"
},
... | 1,598,329,168 | 2,147,483,647 | PyPy 3 | OK | TESTS | 70 | 404 | 3,584,000 | def answer(n,m,dp):
count=0
for k in range(n):
flag=1
l=[]
for i in range(1,n+1):
index=-1
count1=0
for j in range(1,n+1):
if dp[i][j]==1:
if index==-1:
index=j
... | Title: Students and Shoelaces
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Anna and Maria are in charge of the math club for junior students. When the club gathers together, the students behave badly. They've brought lots of shoe laces to the club and got tied with each other. Specifica... | ```python
def answer(n,m,dp):
count=0
for k in range(n):
flag=1
l=[]
for i in range(1,n+1):
index=-1
count1=0
for j in range(1,n+1):
if dp[i][j]==1:
if index==-1:
index=j
... | 3 | |
281 | A | Word Capitalization | PROGRAMMING | 800 | [
"implementation",
"strings"
] | null | null | Capitalization is writing a word with its first letter as a capital letter. Your task is to capitalize the given word.
Note, that during capitalization all the letters except the first one remains unchanged. | A single line contains a non-empty word. This word consists of lowercase and uppercase English letters. The length of the word will not exceed 103. | Output the given word after capitalization. | [
"ApPLe\n",
"konjac\n"
] | [
"ApPLe\n",
"Konjac\n"
] | none | 500 | [
{
"input": "ApPLe",
"output": "ApPLe"
},
{
"input": "konjac",
"output": "Konjac"
},
{
"input": "a",
"output": "A"
},
{
"input": "A",
"output": "A"
},
{
"input": "z",
"output": "Z"
},
{
"input": "ABACABA",
"output": "ABACABA"
},
{
"input": "... | 1,696,678,771 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 25 | 124 | 0 | def i():
return(int(input()))
def l():
return(list(map(int,input().split())))
def s():
return(input())
def m():
return(map(int,input().split()))
a = s()
b = a[0].upper()
print(b + a[1:])
| Title: Word Capitalization
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Capitalization is writing a word with its first letter as a capital letter. Your task is to capitalize the given word.
Note, that during capitalization all the letters except the first one remains unchanged.
Input... | ```python
def i():
return(int(input()))
def l():
return(list(map(int,input().split())))
def s():
return(input())
def m():
return(map(int,input().split()))
a = s()
b = a[0].upper()
print(b + a[1:])
``` | 3 | |
820 | A | Mister B and Book Reading | PROGRAMMING | 900 | [
"implementation"
] | null | null | Mister B once received a gift: it was a book about aliens, which he started read immediately. This book had *c* pages.
At first day Mister B read *v*0 pages, but after that he started to speed up. Every day, starting from the second, he read *a* pages more than on the previous day (at first day he read *v*0 pages, at ... | First and only line contains five space-separated integers: *c*, *v*0, *v*1, *a* and *l* (1<=β€<=*c*<=β€<=1000, 0<=β€<=*l*<=<<=*v*0<=β€<=*v*1<=β€<=1000, 0<=β€<=*a*<=β€<=1000) β the length of the book in pages, the initial reading speed, the maximum reading speed, the acceleration in reading speed and the number of pages fo... | Print one integer β the number of days Mister B needed to finish the book. | [
"5 5 10 5 4\n",
"12 4 12 4 1\n",
"15 1 100 0 0\n"
] | [
"1\n",
"3\n",
"15\n"
] | In the first sample test the book contains 5 pages, so Mister B read it right at the first day.
In the second sample test at first day Mister B read pages number 1β-β4, at second dayΒ β 4β-β11, at third dayΒ β 11β-β12 and finished the book.
In third sample test every day Mister B read 1 page of the book, so he finished... | 500 | [
{
"input": "5 5 10 5 4",
"output": "1"
},
{
"input": "12 4 12 4 1",
"output": "3"
},
{
"input": "15 1 100 0 0",
"output": "15"
},
{
"input": "1 1 1 0 0",
"output": "1"
},
{
"input": "1000 999 1000 1000 998",
"output": "2"
},
{
"input": "1000 2 2 5 1",
... | 1,498,574,970 | 870 | Python 3 | OK | TESTS | 110 | 77 | 5,529,600 | def br(c, v0, v1, a, l):
d = 1
read = v0
while read < c:
d += 1
read -= l
v0 = min(v1, v0 + a)
read += v0
return d
p0, p1, p2, p3, p4 = list(map(int, input().strip().split()))
print(br(p0, p1, p2, p3, p4)) | Title: Mister B and Book Reading
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mister B once received a gift: it was a book about aliens, which he started read immediately. This book had *c* pages.
At first day Mister B read *v*0 pages, but after that he started to speed up. Every day, ... | ```python
def br(c, v0, v1, a, l):
d = 1
read = v0
while read < c:
d += 1
read -= l
v0 = min(v1, v0 + a)
read += v0
return d
p0, p1, p2, p3, p4 = list(map(int, input().strip().split()))
print(br(p0, p1, p2, p3, p4))
``` | 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,672,394,843 | 2,147,483,647 | Python 3 | OK | TESTS | 20 | 46 | 0 | def solve():
n = int(input())
for _ in range(n):
s = input().strip()
if len(s) <= 10:
print(s)
else:
print('{}{}{}'.format(s[0], len(s) - 2,s[-1]))
solve() | 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
def solve():
n = int(input())
for _ in range(n):
s = input().strip()
if len(s) <= 10:
print(s)
else:
print('{}{}{}'.format(s[0], len(s) - 2,s[-1]))
solve()
``` | 3.977 |
349 | B | Color the Fence | PROGRAMMING | 1,700 | [
"data structures",
"dp",
"greedy",
"implementation"
] | null | null | Igor has fallen in love with Tanya. Now Igor wants to show his feelings and write a number on the fence opposite to Tanya's house. Igor thinks that the larger the number is, the more chance to win Tanya's heart he has.
Unfortunately, Igor could only get *v* liters of paint. He did the math and concluded that digit *d... | The first line contains a positive integer *v* (0<=β€<=*v*<=β€<=106). The second line contains nine positive integers *a*1,<=*a*2,<=...,<=*a*9 (1<=β€<=*a**i*<=β€<=105). | Print the maximum number Igor can write on the fence. If he has too little paint for any digit (so, he cannot write anything), print -1. | [
"5\n5 4 3 2 1 2 3 4 5\n",
"2\n9 11 1 12 5 8 9 10 6\n",
"0\n1 1 1 1 1 1 1 1 1\n"
] | [
"55555\n",
"33\n",
"-1\n"
] | none | 1,000 | [
{
"input": "5\n5 4 3 2 1 2 3 4 5",
"output": "55555"
},
{
"input": "2\n9 11 1 12 5 8 9 10 6",
"output": "33"
},
{
"input": "0\n1 1 1 1 1 1 1 1 1",
"output": "-1"
},
{
"input": "50\n5 3 10 2 2 4 3 6 5",
"output": "5555555555555555555555555"
},
{
"input": "22\n405 3... | 1,654,207,251 | 2,147,483,647 | PyPy 3 | OK | TESTS | 35 | 528 | 44,851,200 | import math
import bisect
def main():
v = int(input())
aux = list(map(int, input().split()))
liters = [(aux[i], i+1) for i in range(0, 9)]
liters = sorted(liters, key = lambda x : (x[0], -x[1]))
if v < liters[0][0]:
print(-1)
else:
num_rep = v//liters[0][0]
... | Title: Color the Fence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Igor has fallen in love with Tanya. Now Igor wants to show his feelings and write a number on the fence opposite to Tanya's house. Igor thinks that the larger the number is, the more chance to win Tanya's heart he has. ... | ```python
import math
import bisect
def main():
v = int(input())
aux = list(map(int, input().split()))
liters = [(aux[i], i+1) for i in range(0, 9)]
liters = sorted(liters, key = lambda x : (x[0], -x[1]))
if v < liters[0][0]:
print(-1)
else:
num_rep = v//liters[0]... | 3 | |
703 | A | Mishka and Game | PROGRAMMING | 800 | [
"implementation"
] | null | null | Mishka is a little polar bear. As known, little bears loves spending their free time playing dice for chocolates. Once in a wonderful sunny morning, walking around blocks of ice, Mishka met her friend Chris, and they started playing the game.
Rules of the game are very simple: at first number of rounds *n* is defined.... | The first line of the input contains single integer *n* *n* (1<=β€<=*n*<=β€<=100)Β β the number of game rounds.
The next *n* lines contains rounds description. *i*-th of them contains pair of integers *m**i* and *c**i* (1<=β€<=*m**i*,<=<=*c**i*<=β€<=6)Β β values on dice upper face after Mishka's and Chris' throws in *i*-th ... | If Mishka is the winner of the game, print "Mishka" (without quotes) in the only line.
If Chris is the winner of the game, print "Chris" (without quotes) in the only line.
If the result of the game is draw, print "Friendship is magic!^^" (without quotes) in the only line. | [
"3\n3 5\n2 1\n4 2\n",
"2\n6 1\n1 6\n",
"3\n1 5\n3 3\n2 2\n"
] | [
"Mishka",
"Friendship is magic!^^",
"Chris"
] | In the first sample case Mishka loses the first round, but wins second and third rounds and thus she is the winner of the game.
In the second sample case Mishka wins the first round, Chris wins the second round, and the game ends with draw with score 1:1.
In the third sample case Chris wins the first round, but there... | 500 | [
{
"input": "3\n3 5\n2 1\n4 2",
"output": "Mishka"
},
{
"input": "2\n6 1\n1 6",
"output": "Friendship is magic!^^"
},
{
"input": "3\n1 5\n3 3\n2 2",
"output": "Chris"
},
{
"input": "6\n4 1\n4 2\n5 3\n5 1\n5 3\n4 1",
"output": "Mishka"
},
{
"input": "8\n2 4\n1 4\n1 ... | 1,689,298,525 | 2,147,483,647 | Python 3 | OK | TESTS | 69 | 46 | 0 | #https://codeforces.com/problemset/problem/703/A
def get_answer(difference):
if(difference<0):
return "Chris"
elif(difference == 0):
return "Friendship is magic!^^"
else:
return "Mishka"
rounds = int(input())
result = 0
while rounds>0:
m, c = (int(x) for x in input... | Title: Mishka and Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mishka is a little polar bear. As known, little bears loves spending their free time playing dice for chocolates. Once in a wonderful sunny morning, walking around blocks of ice, Mishka met her friend Chris, and they st... | ```python
#https://codeforces.com/problemset/problem/703/A
def get_answer(difference):
if(difference<0):
return "Chris"
elif(difference == 0):
return "Friendship is magic!^^"
else:
return "Mishka"
rounds = int(input())
result = 0
while rounds>0:
m, c = (int(x) for ... | 3 | |
669 | A | Little Artem and Presents | PROGRAMMING | 800 | [
"math"
] | null | null | Little Artem got *n* stones on his birthday and now wants to give some of them to Masha. He knows that Masha cares more about the fact of receiving the present, rather than the value of that present, so he wants to give her stones as many times as possible. However, Masha remembers the last present she received, so Art... | The only line of the input contains a single integer *n* (1<=β€<=*n*<=β€<=109)Β β number of stones Artem received on his birthday. | Print the maximum possible number of times Artem can give presents to Masha. | [
"1\n",
"2\n",
"3\n",
"4\n"
] | [
"1\n",
"1\n",
"2\n",
"3\n"
] | In the first sample, Artem can only give 1 stone to Masha.
In the second sample, Atrem can give Masha 1 or 2 stones, though he can't give her 1 stone two times.
In the third sample, Atrem can first give Masha 2 stones, a then 1 more stone.
In the fourth sample, Atrem can first give Masha 1 stone, then 2 stones, and ... | 500 | [
{
"input": "1",
"output": "1"
},
{
"input": "2",
"output": "1"
},
{
"input": "3",
"output": "2"
},
{
"input": "4",
"output": "3"
},
{
"input": "100",
"output": "67"
},
{
"input": "101",
"output": "67"
},
{
"input": "102",
"output": "68"... | 1,684,783,044 | 2,147,483,647 | Python 3 | OK | TESTS | 26 | 46 | 0 | n=int(input())
if (n-1)%3==0:
k=(n-1)//3
print(2*k+1)
if (n-2)%3==0:
k=(n-2)//3
print(2*k+1)
if n%3==0:
print(2*(n//3))
| Title: Little Artem and Presents
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Artem got *n* stones on his birthday and now wants to give some of them to Masha. He knows that Masha cares more about the fact of receiving the present, rather than the value of that present, so he wan... | ```python
n=int(input())
if (n-1)%3==0:
k=(n-1)//3
print(2*k+1)
if (n-2)%3==0:
k=(n-2)//3
print(2*k+1)
if n%3==0:
print(2*(n//3))
``` | 3 | |
579 | A | Raising Bacteria | PROGRAMMING | 1,000 | [
"bitmasks"
] | null | null | You are a lover of bacteria. You want to raise some bacteria in a box.
Initially, the box is empty. Each morning, you can put any number of bacteria into the box. And each night, every bacterium in the box will split into two bacteria. You hope to see exactly *x* bacteria in the box at some moment.
What is the mini... | The only line containing one integer *x* (1<=β€<=*x*<=β€<=109). | The only line containing one integer: the answer. | [
"5\n",
"8\n"
] | [
"2\n",
"1\n"
] | For the first sample, we can add one bacterium in the box in the first day morning and at the third morning there will be 4 bacteria in the box. Now we put one more resulting 5 in the box. We added 2 bacteria in the process so the answer is 2.
For the second sample, we can put one in the first morning and in the 4-th ... | 250 | [
{
"input": "5",
"output": "2"
},
{
"input": "8",
"output": "1"
},
{
"input": "536870911",
"output": "29"
},
{
"input": "1",
"output": "1"
},
{
"input": "343000816",
"output": "14"
},
{
"input": "559980448",
"output": "12"
},
{
"input": "697... | 1,692,384,967 | 2,147,483,647 | Python 3 | OK | TESTS | 36 | 46 | 0 | def biggest_power_of_2_less_or_equal_to(x):
'''
Retorna a maior potΓͺncia de 2 menor ou igual a x.
'''
if (x == 0):
return 0
p2 = 1
while (p2 < x):
p2 = p2 * 2
if (p2 > x):
p2 = p2 / 2
return p2
def main():
x = int(input())
answer = 0
while (x > 0)... | Title: Raising Bacteria
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are a lover of bacteria. You want to raise some bacteria in a box.
Initially, the box is empty. Each morning, you can put any number of bacteria into the box. And each night, every bacterium in the box will split... | ```python
def biggest_power_of_2_less_or_equal_to(x):
'''
Retorna a maior potΓͺncia de 2 menor ou igual a x.
'''
if (x == 0):
return 0
p2 = 1
while (p2 < x):
p2 = p2 * 2
if (p2 > x):
p2 = p2 / 2
return p2
def main():
x = int(input())
answer = 0
whi... | 3 | |
26 | B | Regular Bracket Sequence | PROGRAMMING | 1,400 | [
"greedy"
] | B. Regular Bracket Sequence | 5 | 256 | A bracket sequence is called regular if it is possible to obtain correct arithmetic expression by inserting characters Β«+Β» and Β«1Β» into this sequence. For example, sequences Β«(())()Β», Β«()Β» and Β«(()(()))Β» are regular, while Β«)(Β», Β«(()Β» and Β«(()))(Β» are not.
One day Johnny got bracket sequence. He decided to remove some... | Input consists of a single line with non-empty string of Β«(Β» and Β«)Β» characters. Its length does not exceed 106. | Output the maximum possible length of a regular bracket sequence. | [
"(()))(\n",
"((()())\n"
] | [
"4\n",
"6\n"
] | none | 1,000 | [
{
"input": "(()))(",
"output": "4"
},
{
"input": "((()())",
"output": "6"
},
{
"input": "(",
"output": "0"
},
{
"input": ")",
"output": "0"
},
{
"input": ")(()(",
"output": "2"
},
{
"input": "))))))(",
"output": "0"
},
{
"input": "()()(()((... | 1,680,416,920 | 2,147,483,647 | Python 3 | OK | TESTS | 38 | 716 | 10,240,000 | L=[]
S=input()
C=0
for i in range(len(S)):
if S[i] == "(":
L.append("(")
elif S[i] == ")":
if not L:
continue
else:
L.pop()
C+=1
print(C*2)
| Title: Regular Bracket Sequence
Time Limit: 5 seconds
Memory Limit: 256 megabytes
Problem Description:
A bracket sequence is called regular if it is possible to obtain correct arithmetic expression by inserting characters Β«+Β» and Β«1Β» into this sequence. For example, sequences Β«(())()Β», Β«()Β» and Β«(()(()))Β» are regula... | ```python
L=[]
S=input()
C=0
for i in range(len(S)):
if S[i] == "(":
L.append("(")
elif S[i] == ")":
if not L:
continue
else:
L.pop()
C+=1
print(C*2)
``` | 3.909327 |
558 | A | Lala Land and Apple Trees | PROGRAMMING | 1,100 | [
"brute force",
"implementation",
"sortings"
] | null | null | Amr lives in Lala Land. Lala Land is a very beautiful country that is located on a coordinate line. Lala Land is famous with its apple trees growing everywhere.
Lala Land has exactly *n* apple trees. Tree number *i* is located in a position *x**i* and has *a**i* apples growing on it. Amr wants to collect apples from t... | The first line contains one number *n* (1<=β€<=*n*<=β€<=100), the number of apple trees in Lala Land.
The following *n* lines contains two integers each *x**i*, *a**i* (<=-<=105<=β€<=*x**i*<=β€<=105, *x**i*<=β <=0, 1<=β€<=*a**i*<=β€<=105), representing the position of the *i*-th tree and number of apples on it.
It's guarant... | Output the maximum number of apples Amr can collect. | [
"2\n-1 5\n1 5\n",
"3\n-2 2\n1 4\n-1 3\n",
"3\n1 9\n3 5\n7 10\n"
] | [
"10",
"9",
"9"
] | In the first sample test it doesn't matter if Amr chose at first to go left or right. In both cases he'll get all the apples.
In the second sample test the optimal solution is to go left to *x*β=ββ-β1, collect apples from there, then the direction will be reversed, Amr has to go to *x*β=β1, collect apples from there, ... | 500 | [
{
"input": "2\n-1 5\n1 5",
"output": "10"
},
{
"input": "3\n-2 2\n1 4\n-1 3",
"output": "9"
},
{
"input": "3\n1 9\n3 5\n7 10",
"output": "9"
},
{
"input": "1\n1 1",
"output": "1"
},
{
"input": "4\n10000 100000\n-1000 100000\n-2 100000\n-1 100000",
"output": "3... | 1,437,151,008 | 4,008 | Python 3 | OK | TESTS | 43 | 61 | 0 | n = int(input())
_coords = []
_apples = []
for i in range(n):
tree = [int(i) for i in input().split()]
_coords += [tree[0]]
_apples += [tree[1]]
coords_min = - 100001
coords_max = 100001
def get_next_left_index(coords):
next_left = coords_min
next_left_index = -1
for ind, x in en... | Title: Lala Land and Apple Trees
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Amr lives in Lala Land. Lala Land is a very beautiful country that is located on a coordinate line. Lala Land is famous with its apple trees growing everywhere.
Lala Land has exactly *n* apple trees. Tree num... | ```python
n = int(input())
_coords = []
_apples = []
for i in range(n):
tree = [int(i) for i in input().split()]
_coords += [tree[0]]
_apples += [tree[1]]
coords_min = - 100001
coords_max = 100001
def get_next_left_index(coords):
next_left = coords_min
next_left_index = -1
for in... | 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,565,089,304 | 2,147,483,647 | Python 3 | OK | TESTS | 32 | 218 | 0 | n = int(input())
num = list(map(int,input().split()))
for i in range(len(num)) :
if num[i]%2 == 0 :
num[i] = 0
else :
num[i] = 1
if num.count(1) == 1:
print(num.index(1) + 1)
if num.count(0) == 1:
print(num.index(0) + 1)
| Title: IQ test
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob β t... | ```python
n = int(input())
num = list(map(int,input().split()))
for i in range(len(num)) :
if num[i]%2 == 0 :
num[i] = 0
else :
num[i] = 1
if num.count(1) == 1:
print(num.index(1) + 1)
if num.count(0) == 1:
print(num.index(0) + 1)
``` | 3.9455 |
894 | A | QAQ | PROGRAMMING | 800 | [
"brute force",
"dp"
] | null | null | "QAQ" is a word to denote an expression of crying. Imagine "Q" as eyes with tears and "A" as a mouth.
Now Diamond has given Bort a string consisting of only uppercase English letters of length *n*. There is a great number of "QAQ" in the string (Diamond is so cute!).
Bort wants to know how many subsequences "QAQ" are... | The only line contains a string of length *n* (1<=β€<=*n*<=β€<=100). It's guaranteed that the string only contains uppercase English letters. | Print a single integerΒ β the number of subsequences "QAQ" in the string. | [
"QAQAQYSYIOIWIN\n",
"QAQQQZZYNOIWIN\n"
] | [
"4\n",
"3\n"
] | In the first example there are 4 subsequences "QAQ": "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN", "QAQAQYSYIOIWIN". | 500 | [
{
"input": "QAQAQYSYIOIWIN",
"output": "4"
},
{
"input": "QAQQQZZYNOIWIN",
"output": "3"
},
{
"input": "QA",
"output": "0"
},
{
"input": "IAQVAQZLQBQVQFTQQQADAQJA",
"output": "24"
},
{
"input": "QQAAQASGAYAAAAKAKAQIQEAQAIAAIAQQQQQ",
"output": "378"
},
{
... | 1,590,476,074 | 2,147,483,647 | PyPy 3 | OK | TESTS | 43 | 155 | 1,331,200 | class Main:
def __init__(self):
self.s = input()
def main(self):
pref_sum_As = [0]*self.s.__len__()
self.fill_cumulative_freq('A', pref_sum_As)
subsequence_QAQ_count = 0
for i in range(self.s.__len__()-2):
if self.s[i] == 'Q':
for j ... | Title: QAQ
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
"QAQ" is a word to denote an expression of crying. Imagine "Q" as eyes with tears and "A" as a mouth.
Now Diamond has given Bort a string consisting of only uppercase English letters of length *n*. There is a great number of "QAQ"... | ```python
class Main:
def __init__(self):
self.s = input()
def main(self):
pref_sum_As = [0]*self.s.__len__()
self.fill_cumulative_freq('A', pref_sum_As)
subsequence_QAQ_count = 0
for i in range(self.s.__len__()-2):
if self.s[i] == 'Q':
... | 3 | |
50 | A | Domino piling | PROGRAMMING | 800 | [
"greedy",
"math"
] | A. Domino piling | 2 | 256 | You are given a rectangular board of *M*<=Γ<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=Γ<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions:
1. Each domino completely covers ... | In a single line you are given two integers *M* and *N* β board sizes in squares (1<=β€<=*M*<=β€<=*N*<=β€<=16). | Output one number β the maximal number of dominoes, which can be placed. | [
"2 4\n",
"3 3\n"
] | [
"4\n",
"4\n"
] | none | 500 | [
{
"input": "2 4",
"output": "4"
},
{
"input": "3 3",
"output": "4"
},
{
"input": "1 5",
"output": "2"
},
{
"input": "1 6",
"output": "3"
},
{
"input": "1 15",
"output": "7"
},
{
"input": "1 16",
"output": "8"
},
{
"input": "2 5",
"outpu... | 1,665,167,232 | 2,147,483,647 | Python 3 | OK | TESTS | 35 | 92 | 0 | import math
M, N = map(int, input().split())
print(math.floor(N*M*0.5)) | Title: Domino piling
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
You are given a rectangular board of *M*<=Γ<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=Γ<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as p... | ```python
import math
M, N = map(int, input().split())
print(math.floor(N*M*0.5))
``` | 3.977 |
431 | A | Black Square | PROGRAMMING | 800 | [
"implementation"
] | null | null | Quite recently, a very smart student named Jury decided that lectures are boring, so he downloaded a game called "Black Square" on his super cool touchscreen phone.
In this game, the phone's screen is divided into four vertical strips. Each second, a black square appears on some of the strips. According to the rules o... | The first line contains four space-separated integers *a*1, *a*2, *a*3, *a*4 (0<=β€<=*a*1,<=*a*2,<=*a*3,<=*a*4<=β€<=104).
The second line contains string *s* (1<=β€<=|*s*|<=β€<=105), where the *Ρ*-th character of the string equals "1", if on the *i*-th second of the game the square appears on the first strip, "2", if it a... | Print a single integer β the total number of calories that Jury wastes. | [
"1 2 3 4\n123214\n",
"1 5 3 2\n11221\n"
] | [
"13\n",
"13\n"
] | none | 500 | [
{
"input": "1 2 3 4\n123214",
"output": "13"
},
{
"input": "1 5 3 2\n11221",
"output": "13"
},
{
"input": "5 5 5 1\n3422",
"output": "16"
},
{
"input": "4 3 2 1\n2",
"output": "3"
},
{
"input": "5651 6882 6954 4733\n2442313421",
"output": "60055"
},
{
... | 1,667,289,118 | 2,147,483,647 | Python 3 | OK | TESTS | 49 | 109 | 204,800 | a1, a2, a3, a4 = input().split()
s = input()
sum = 0
for i in range(len(s)):
if s[i] == "1":
sum = sum + int(a1)
if s[i] == "2":
sum = sum + int(a2)
if s[i] == "3":
sum = sum + int(a3)
if s[i] == "4":
sum = sum + int(a4)
print(sum) | Title: Black Square
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Quite recently, a very smart student named Jury decided that lectures are boring, so he downloaded a game called "Black Square" on his super cool touchscreen phone.
In this game, the phone's screen is divided into four ve... | ```python
a1, a2, a3, a4 = input().split()
s = input()
sum = 0
for i in range(len(s)):
if s[i] == "1":
sum = sum + int(a1)
if s[i] == "2":
sum = sum + int(a2)
if s[i] == "3":
sum = sum + int(a3)
if s[i] == "4":
sum = sum + int(a4)
print(sum)
``` | 3 | |
268 | A | Games | PROGRAMMING | 800 | [
"brute force"
] | null | null | Manao works on a sports TV. He's spent much time watching the football games of some country. After a while he began to notice different patterns. For example, each team has two sets of uniforms: home uniform and guest uniform. When a team plays a game at home, the players put on the home uniform. When a team plays as ... | The first line contains an integer *n* (2<=β€<=*n*<=β€<=30). Each of the following *n* lines contains a pair of distinct space-separated integers *h**i*, *a**i* (1<=β€<=*h**i*,<=*a**i*<=β€<=100) β the colors of the *i*-th team's home and guest uniforms, respectively. | In a single line print the number of games where the host team is going to play in the guest uniform. | [
"3\n1 2\n2 4\n3 4\n",
"4\n100 42\n42 100\n5 42\n100 5\n",
"2\n1 2\n1 2\n"
] | [
"1\n",
"5\n",
"0\n"
] | In the first test case the championship consists of 6 games. The only game with the event in question is the game between teams 2 and 1 on the stadium of team 2.
In the second test sample the host team will have to wear guest uniform in the games between teams: 1 and 2, 2 and 1, 2 and 3, 3 and 4, 4 and 2 (the host tea... | 500 | [
{
"input": "3\n1 2\n2 4\n3 4",
"output": "1"
},
{
"input": "4\n100 42\n42 100\n5 42\n100 5",
"output": "5"
},
{
"input": "2\n1 2\n1 2",
"output": "0"
},
{
"input": "7\n4 7\n52 55\n16 4\n55 4\n20 99\n3 4\n7 52",
"output": "6"
},
{
"input": "10\n68 42\n1 35\n25 70\n... | 1,673,155,740 | 2,147,483,647 | Python 3 | OK | TESTS | 31 | 92 | 0 | n=int(input())
count=0
h_a_list = []
for i in range(n):
h,a=map(int,input().split())
h_a_list.append([h,a])
for i in range(n):
for j in range(n):
if h_a_list[i][0]==h_a_list[j][1]:
count+=1
print(count) | Title: Games
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Manao works on a sports TV. He's spent much time watching the football games of some country. After a while he began to notice different patterns. For example, each team has two sets of uniforms: home uniform and guest uniform. W... | ```python
n=int(input())
count=0
h_a_list = []
for i in range(n):
h,a=map(int,input().split())
h_a_list.append([h,a])
for i in range(n):
for j in range(n):
if h_a_list[i][0]==h_a_list[j][1]:
count+=1
print(count)
``` | 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,693,591,344 | 2,147,483,647 | Python 3 | OK | TESTS | 20 | 92 | 0 | w=int(input())
peso_dividido= w % 2
if peso_dividido == 0 and w!= 2:
print("YES")
else: print("NO")
| 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
w=int(input())
peso_dividido= w % 2
if peso_dividido == 0 and w!= 2:
print("YES")
else: print("NO")
``` | 3.954 |
919 | A | Supermarket | PROGRAMMING | 800 | [
"brute force",
"greedy",
"implementation"
] | null | null | We often go to supermarkets to buy some fruits or vegetables, and on the tag there prints the price for a kilo. But in some supermarkets, when asked how much the items are, the clerk will say that $a$ yuan for $b$ kilos (You don't need to care about what "yuan" is), the same as $a/b$ yuan for a kilo.
Now imagine you'd... | The first line contains two positive integers $n$ and $m$ ($1 \leq n \leq 5\,000$, $1 \leq m \leq 100$), denoting that there are $n$ supermarkets and you want to buy $m$ kilos of apples.
The following $n$ lines describe the information of the supermarkets. Each line contains two positive integers $a, b$ ($1 \leq a, b ... | The only line, denoting the minimum cost for $m$ kilos of apples. Please make sure that the absolute or relative error between your answer and the correct answer won't exceed $10^{-6}$.
Formally, let your answer be $x$, and the jury's answer be $y$. Your answer is considered correct if $\frac{|x - y|}{\max{(1, |y|)}} ... | [
"3 5\n1 2\n3 4\n1 3\n",
"2 1\n99 100\n98 99\n"
] | [
"1.66666667\n",
"0.98989899\n"
] | In the first sample, you are supposed to buy $5$ kilos of apples in supermarket $3$. The cost is $5/3$ yuan.
In the second sample, you are supposed to buy $1$ kilo of apples in supermarket $2$. The cost is $98/99$ yuan. | 500 | [
{
"input": "3 5\n1 2\n3 4\n1 3",
"output": "1.66666667"
},
{
"input": "2 1\n99 100\n98 99",
"output": "0.98989899"
},
{
"input": "50 37\n78 49\n96 4\n86 62\n28 4\n19 2\n79 43\n79 92\n95 35\n33 60\n54 84\n90 25\n2 25\n53 21\n86 52\n72 25\n6 78\n41 46\n3 68\n42 89\n33 35\n57 43\n99 45\n1 8... | 1,628,411,644 | 2,147,483,647 | PyPy 3 | OK | TESTS | 43 | 171 | 23,756,800 | n,m = map(int,input().split())
ls = []
for i in range(n):
a,b = map(int,input().split())
cost = (m * a) / b
ls.append(cost)
print(min(ls)) | Title: Supermarket
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
We often go to supermarkets to buy some fruits or vegetables, and on the tag there prints the price for a kilo. But in some supermarkets, when asked how much the items are, the clerk will say that $a$ yuan for $b$ kilos (Yo... | ```python
n,m = map(int,input().split())
ls = []
for i in range(n):
a,b = map(int,input().split())
cost = (m * a) / b
ls.append(cost)
print(min(ls))
``` | 3 | |
984 | A | Game | PROGRAMMING | 800 | [
"sortings"
] | null | null | Two players play a game.
Initially there are $n$ integers $a_1, a_2, \ldots, a_n$ written on the board. Each turn a player selects one number and erases it from the board. This continues until there is only one number left on the board, i.Β e. $n - 1$ turns are made. The first player makes the first move, then players ... | The first line contains one integer $n$ ($1 \le n \le 1000$)Β β the number of numbers on the board.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^6$). | Print one number that will be left on the board. | [
"3\n2 1 3\n",
"3\n2 2 2\n"
] | [
"2",
"2"
] | In the first sample, the first player erases $3$ and the second erases $1$. $2$ is left on the board.
In the second sample, $2$ is left on the board regardless of the actions of the players. | 500 | [
{
"input": "3\n2 1 3",
"output": "2"
},
{
"input": "3\n2 2 2",
"output": "2"
},
{
"input": "9\n44 53 51 80 5 27 74 79 94",
"output": "53"
},
{
"input": "10\n38 82 23 37 96 4 81 60 67 86",
"output": "60"
},
{
"input": "10\n58 26 77 15 53 81 68 48 22 65",
"outpu... | 1,602,697,441 | 2,147,483,647 | Python 3 | OK | TESTS | 35 | 109 | 307,200 | t = int(input())
a = list(map(int,input().split(" ")))
a.sort()
if len(a) % 2 == 1:
print(a[t//2])
else:
print(a[t//2 - 1]) | Title: Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Two players play a game.
Initially there are $n$ integers $a_1, a_2, \ldots, a_n$ written on the board. Each turn a player selects one number and erases it from the board. This continues until there is only one number left on the... | ```python
t = int(input())
a = list(map(int,input().split(" ")))
a.sort()
if len(a) % 2 == 1:
print(a[t//2])
else:
print(a[t//2 - 1])
``` | 3 | |
656 | A | Da Vinci Powers | PROGRAMMING | 1,900 | [
"*special"
] | null | null | The input contains a single integer *a* (0<=β€<=*a*<=β€<=35).
Output a single integer. | The input contains a single integer *a* (0<=β€<=*a*<=β€<=35). | Output a single integer. | [
"3\n",
"10\n"
] | [
"8\n",
"1024\n"
] | none | 0 | [
{
"input": "3",
"output": "8"
},
{
"input": "10",
"output": "1024"
},
{
"input": "35",
"output": "33940307968"
},
{
"input": "0",
"output": "1"
},
{
"input": "1",
"output": "2"
},
{
"input": "2",
"output": "4"
},
{
"input": "4",
"output... | 1,589,046,199 | 2,147,483,647 | PyPy 3 | OK | TESTS | 36 | 140 | 20,172,800 |
i = int(input())
if i <= 12:
print(pow(2 , i))
else:
a = pow(2 , (i - 13)) * 100
print(pow(2 , i) - a) | Title: Da Vinci Powers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The input contains a single integer *a* (0<=β€<=*a*<=β€<=35).
Output a single integer.
Input Specification:
The input contains a single integer *a* (0<=β€<=*a*<=β€<=35).
Output Specification:
Output a single integer.
De... | ```python
i = int(input())
if i <= 12:
print(pow(2 , i))
else:
a = pow(2 , (i - 13)) * 100
print(pow(2 , i) - a)
``` | 3 | |
768 | B | Code For 1 | PROGRAMMING | 1,600 | [
"constructive algorithms",
"dfs and similar",
"divide and conquer"
] | null | null | Jon fought bravely to rescue the wildlings who were attacked by the white-walkers at Hardhome. On his arrival, Sam tells him that he wants to go to Oldtown to train at the Citadel to become a maester, so he can return and take the deceased Aemon's place as maester of Castle Black. Jon agrees to Sam's proposal and Sam s... | The first line contains three integers *n*, *l*, *r* (0<=β€<=*n*<=<<=250, 0<=β€<=*r*<=-<=*l*<=β€<=105, *r*<=β₯<=1, *l*<=β₯<=1) β initial element and the range *l* to *r*.
It is guaranteed that *r* is not greater than the length of the final list. | Output the total number of 1s in the range *l* to *r* in the final sequence. | [
"7 2 5\n",
"10 3 10\n"
] | [
"4\n",
"5\n"
] | Consider first example:
<img align="middle" class="tex-formula" src="https://espresso.codeforces.com/288fbb682a6fa1934a47b763d6851f9d32a06150.png" style="max-width: 100.0%;max-height: 100.0%;"/>
Elements on positions from 2-nd to 5-th in list is [1,β1,β1,β1]. The number of ones is 4.
For the second example:
<img al... | 1,000 | [
{
"input": "7 2 5",
"output": "4"
},
{
"input": "10 3 10",
"output": "5"
},
{
"input": "56 18 40",
"output": "20"
},
{
"input": "203 40 124",
"output": "67"
},
{
"input": "903316762502 354723010040 354723105411",
"output": "78355"
},
{
"input": "335343... | 1,653,996,829 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 33 | 77 | 3,174,400 | import sys
from collections import *
from functools import lru_cache
sys.setrecursionlimit(2000)
input = sys.stdin.readline
def main():
# @lru_cache(None)
def dp(x):
if x <= 1:
return 0
return (x%2 == 0) + 2 * dp(x//2)
def recurse(num,s,e):
... | Title: Code For 1
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Jon fought bravely to rescue the wildlings who were attacked by the white-walkers at Hardhome. On his arrival, Sam tells him that he wants to go to Oldtown to train at the Citadel to become a maester, so he can return and ta... | ```python
import sys
from collections import *
from functools import lru_cache
sys.setrecursionlimit(2000)
input = sys.stdin.readline
def main():
# @lru_cache(None)
def dp(x):
if x <= 1:
return 0
return (x%2 == 0) + 2 * dp(x//2)
def recurse(nu... | 3 | |
682 | A | Alyona and Numbers | PROGRAMMING | 1,100 | [
"constructive algorithms",
"math",
"number theory"
] | null | null | After finishing eating her bun, Alyona came up with two integers *n* and *m*. She decided to write down two columns of integersΒ β the first column containing integers from 1 to *n* and the second containing integers from 1 to *m*. Now the girl wants to count how many pairs of integers she can choose, one from the first... | The only line of the input contains two integers *n* and *m* (1<=β€<=*n*,<=*m*<=β€<=1<=000<=000). | Print the only integerΒ β the number of pairs of integers (*x*,<=*y*) such that 1<=β€<=*x*<=β€<=*n*, 1<=β€<=*y*<=β€<=*m* and (*x*<=+<=*y*) is divisible by 5. | [
"6 12\n",
"11 14\n",
"1 5\n",
"3 8\n",
"5 7\n",
"21 21\n"
] | [
"14\n",
"31\n",
"1\n",
"5\n",
"7\n",
"88\n"
] | Following pairs are suitable in the first sample case:
- for *x*β=β1 fits *y* equal to 4 or 9; - for *x*β=β2 fits *y* equal to 3 or 8; - for *x*β=β3 fits *y* equal to 2, 7 or 12; - for *x*β=β4 fits *y* equal to 1, 6 or 11; - for *x*β=β5 fits *y* equal to 5 or 10; - for *x*β=β6 fits *y* equal to 4 or 9.
Only th... | 500 | [
{
"input": "6 12",
"output": "14"
},
{
"input": "11 14",
"output": "31"
},
{
"input": "1 5",
"output": "1"
},
{
"input": "3 8",
"output": "5"
},
{
"input": "5 7",
"output": "7"
},
{
"input": "21 21",
"output": "88"
},
{
"input": "10 15",
... | 1,587,499,428 | 2,147,483,647 | PyPy 3 | OK | TESTS | 128 | 187 | 1,433,600 | from sys import stdin,stdout
from math import gcd, ceil, sqrt
ii1 = lambda: int(stdin.readline().strip())
is1 = lambda: stdin.readline().strip()
iia = lambda: list(map(int, stdin.readline().strip().split()))
isa = lambda: stdin.readline().strip().split()
mod = 1000000007
n, m = iia()
d = {}
for i in range(1,... | Title: Alyona and Numbers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
After finishing eating her bun, Alyona came up with two integers *n* and *m*. She decided to write down two columns of integersΒ β the first column containing integers from 1 to *n* and the second containing integers ... | ```python
from sys import stdin,stdout
from math import gcd, ceil, sqrt
ii1 = lambda: int(stdin.readline().strip())
is1 = lambda: stdin.readline().strip()
iia = lambda: list(map(int, stdin.readline().strip().split()))
isa = lambda: stdin.readline().strip().split()
mod = 1000000007
n, m = iia()
d = {}
for i i... | 3 | |
478 | C | Table Decorations | PROGRAMMING | 1,800 | [
"greedy"
] | null | null | You have *r* red, *g* green and *b* blue balloons. To decorate a single table for the banquet you need exactly three balloons. Three balloons attached to some table shouldn't have the same color. What maximum number *t* of tables can be decorated if we know number of balloons of each color?
Your task is to write a pro... | The single line contains three integers *r*, *g* and *b* (0<=β€<=*r*,<=*g*,<=*b*<=β€<=2Β·109) β the number of red, green and blue baloons respectively. The numbers are separated by exactly one space. | Print a single integer *t* β the maximum number of tables that can be decorated in the required manner. | [
"5 4 3\n",
"1 1 1\n",
"2 3 3\n"
] | [
"4\n",
"1\n",
"2\n"
] | In the first sample you can decorate the tables with the following balloon sets: "rgg", "gbb", "brr", "rrg", where "r", "g" and "b" represent the red, green and blue balls, respectively. | 1,500 | [
{
"input": "5 4 3",
"output": "4"
},
{
"input": "1 1 1",
"output": "1"
},
{
"input": "2 3 3",
"output": "2"
},
{
"input": "0 1 0",
"output": "0"
},
{
"input": "0 3 3",
"output": "2"
},
{
"input": "4 0 4",
"output": "2"
},
{
"input": "100000... | 1,658,778,881 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 42 | 62 | 0 | import bisect
import sys
import math
def get_ints(): return map(int, sys.stdin.readline().strip().split())
def get_list(): return list(map(int, sys.stdin.readline().strip().split()))
def get_string(): return sys.stdin.readline().strip()
def get_int(): return int(sys.stdin.readline().strip())
def get_list_strings(): ret... | Title: Table Decorations
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You have *r* red, *g* green and *b* blue balloons. To decorate a single table for the banquet you need exactly three balloons. Three balloons attached to some table shouldn't have the same color. What maximum number *... | ```python
import bisect
import sys
import math
def get_ints(): return map(int, sys.stdin.readline().strip().split())
def get_list(): return list(map(int, sys.stdin.readline().strip().split()))
def get_string(): return sys.stdin.readline().strip()
def get_int(): return int(sys.stdin.readline().strip())
def get_list_stri... | 3 | |
37 | A | Towers | PROGRAMMING | 1,000 | [
"sortings"
] | A. Towers | 2 | 256 | Little Vasya has received a young builderβs kit. The kit consists of several wooden bars, the lengths of all of them are known. The bars can be put one on the top of the other if their lengths are the same.
Vasya wants to construct the minimal number of towers from the bars. Help Vasya to use the bars in the best way ... | The first line contains an integer *N* (1<=β€<=*N*<=β€<=1000) β the number of bars at Vasyaβs disposal. The second line contains *N* space-separated integers *l**i* β the lengths of the bars. All the lengths are natural numbers not exceeding 1000. | In one line output two numbers β the height of the largest tower and their total number. Remember that Vasya should use all the bars. | [
"3\n1 2 3\n",
"4\n6 5 6 7\n"
] | [
"1 3\n",
"2 3\n"
] | none | 500 | [
{
"input": "3\n1 2 3",
"output": "1 3"
},
{
"input": "4\n6 5 6 7",
"output": "2 3"
},
{
"input": "4\n3 2 1 1",
"output": "2 3"
},
{
"input": "4\n1 2 3 3",
"output": "2 3"
},
{
"input": "3\n20 22 36",
"output": "1 3"
},
{
"input": "25\n47 30 94 41 45 20... | 1,612,984,640 | 2,147,483,647 | Python 3 | OK | TESTS | 61 | 154 | 307,200 | n = input()
a = list(map(int, input().split()))
brus = []
count = []
for i in range(len(a)):
# if a[i] not in brus:
brus.append(a.count(a[i]))
for i in a:
if i not in count:
count.append(i)
# print(brus, count, sep='\n')
print(max(brus), len(count)) | Title: Towers
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Little Vasya has received a young builderβs kit. The kit consists of several wooden bars, the lengths of all of them are known. The bars can be put one on the top of the other if their lengths are the same.
Vasya wants to construct... | ```python
n = input()
a = list(map(int, input().split()))
brus = []
count = []
for i in range(len(a)):
# if a[i] not in brus:
brus.append(a.count(a[i]))
for i in a:
if i not in count:
count.append(i)
# print(brus, count, sep='\n')
print(max(brus), len(count))
``` | 3.960928 |
294 | A | Shaass and Oskols | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | Shaass has decided to hunt some birds. There are *n* horizontal electricity wires aligned parallel to each other. Wires are numbered 1 to *n* from top to bottom. On each wire there are some oskols sitting next to each other. Oskol is the name of a delicious kind of birds in Shaass's territory. Supposed there are *a**i*... | The first line of the input contains an integer *n*, (1<=β€<=*n*<=β€<=100). The next line contains a list of space-separated integers *a*1,<=*a*2,<=...,<=*a**n*, (0<=β€<=*a**i*<=β€<=100).
The third line contains an integer *m*, (0<=β€<=*m*<=β€<=100). Each of the next *m* lines contains two integers *x**i* and *y**i*. The i... | On the *i*-th line of the output print the number of birds on the *i*-th wire. | [
"5\n10 10 10 10 10\n5\n2 5\n3 13\n2 12\n1 13\n4 6\n",
"3\n2 4 1\n1\n2 2\n"
] | [
"0\n12\n5\n0\n16\n",
"3\n0\n3\n"
] | none | 500 | [
{
"input": "5\n10 10 10 10 10\n5\n2 5\n3 13\n2 12\n1 13\n4 6",
"output": "0\n12\n5\n0\n16"
},
{
"input": "3\n2 4 1\n1\n2 2",
"output": "3\n0\n3"
},
{
"input": "5\n58 51 45 27 48\n5\n4 9\n5 15\n4 5\n5 8\n1 43",
"output": "0\n66\n57\n7\n0"
},
{
"input": "10\n48 53 10 28 91 56 8... | 1,543,395,767 | 2,147,483,647 | Python 3 | OK | TESTS | 31 | 248 | 0 | n = int(input())
a = list(map(int, input().split()))
shots = int(input())
for i in range(shots):
wire, oskol = map(int, input().split())
# index 0
if wire == 1:
if wire == len(a):
a[wire-1] = 0
else:
a[1] += a[0] - oskol
a[0] = 0
else:
... | Title: Shaass and Oskols
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Shaass has decided to hunt some birds. There are *n* horizontal electricity wires aligned parallel to each other. Wires are numbered 1 to *n* from top to bottom. On each wire there are some oskols sitting next to each... | ```python
n = int(input())
a = list(map(int, input().split()))
shots = int(input())
for i in range(shots):
wire, oskol = map(int, input().split())
# index 0
if wire == 1:
if wire == len(a):
a[wire-1] = 0
else:
a[1] += a[0] - oskol
a[0] = 0
... | 3 | |
907 | A | Masha and Bears | PROGRAMMING | 1,300 | [
"brute force",
"implementation"
] | null | null | A family consisting of father bear, mother bear and son bear owns three cars. Father bear can climb into the largest car and he likes it. Also, mother bear can climb into the middle car and she likes it. Moreover, son bear can climb into the smallest car and he likes it. It's known that the largest car is strictly larg... | You are given four integers *V*1, *V*2, *V*3, *V**m*(1<=β€<=*V**i*<=β€<=100)Β β sizes of father bear, mother bear, son bear and Masha, respectively. It's guaranteed that *V*1<=><=*V*2<=><=*V*3. | Output three integersΒ β sizes of father bear's car, mother bear's car and son bear's car, respectively.
If there are multiple possible solutions, print any.
If there is no solution, print "-1" (without quotes). | [
"50 30 10 10\n",
"100 50 10 21\n"
] | [
"50\n30\n10\n",
"-1\n"
] | In first test case all conditions for cars' sizes are satisfied.
In second test case there is no answer, because Masha should be able to climb into smallest car (so size of smallest car in not less than 21), but son bear should like it, so maximum possible size of it is 20. | 500 | [
{
"input": "50 30 10 10",
"output": "50\n30\n10"
},
{
"input": "100 50 10 21",
"output": "-1"
},
{
"input": "100 50 19 10",
"output": "100\n50\n19"
},
{
"input": "99 50 25 49",
"output": "100\n99\n49"
},
{
"input": "3 2 1 1",
"output": "4\n3\n1"
},
{
"... | 1,514,041,160 | 3,260 | Python 3 | OK | TESTS | 32 | 62 | 5,529,600 | v1,v2,v3,vm=map(int,input().split())
if vm>2*v3:
print(-1)
elif 2*vm<v3:
print(-1)
else:
if (2*vm<2*v2):
print(2*v1)
print(2*v2)
print(max(v3,vm))
else:
print(-1)
... | Title: Masha and Bears
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A family consisting of father bear, mother bear and son bear owns three cars. Father bear can climb into the largest car and he likes it. Also, mother bear can climb into the middle car and she likes it. Moreover, son b... | ```python
v1,v2,v3,vm=map(int,input().split())
if vm>2*v3:
print(-1)
elif 2*vm<v3:
print(-1)
else:
if (2*vm<2*v2):
print(2*v1)
print(2*v2)
print(max(v3,vm))
else:
print(-1)
... | 3 | |
825 | B | Five-In-a-Row | PROGRAMMING | 1,600 | [
"brute force",
"implementation"
] | null | null | Alice and Bob play 5-in-a-row game. They have a playing field of size 10<=Γ<=10. In turns they put either crosses or noughts, one at a time. Alice puts crosses and Bob puts noughts.
In current match they have made some turns and now it's Alice's turn. She wonders if she can put cross in such empty cell that she wins i... | You are given matrix 10<=Γ<=10 (10 lines of 10 characters each) with capital Latin letters 'X' being a cross, letters 'O' being a nought and '.' being an empty cell. The number of 'X' cells is equal to the number of 'O' cells and there is at least one of each type. There is at least one empty cell.
It is guaranteed th... | Print 'YES' if it's possible for Alice to win in one turn by putting cross in some empty cell. Otherwise print 'NO'. | [
"XX.XX.....\n.....OOOO.\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n",
"XXOXX.....\nOO.O......\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n"
] | [
"YES\n",
"NO\n"
] | none | 0 | [
{
"input": "O.......O.\n.....O.X..\n......O...\n....X.O...\n.O.O.....X\n.XO.....XX\n...X...X.O\n........O.\n........O.\n.X.X.....X",
"output": "NO"
},
{
"input": "....OX....\n..........\n.O..X...X.\nXXO..XO..O\nO.......X.\n...XX.....\n..O.O...OX\n.........X\n.....X..OO\n........O.",
"output": "N... | 1,690,188,034 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 156 | 62 | 0 | x=[]
biao=0
for i in range(10):
y=list(input())
x.append(y)
for i in range(10):
for j in range(6):
if x[i][j]=="X" or x[i][j]==".":
z=[]
for k in range(5):
z.append(x[i][j+k])
if z.count("X")==4 and z.count("O")==0:
biao... | Title: Five-In-a-Row
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Alice and Bob play 5-in-a-row game. They have a playing field of size 10<=Γ<=10. In turns they put either crosses or noughts, one at a time. Alice puts crosses and Bob puts noughts.
In current match they have made some t... | ```python
x=[]
biao=0
for i in range(10):
y=list(input())
x.append(y)
for i in range(10):
for j in range(6):
if x[i][j]=="X" or x[i][j]==".":
z=[]
for k in range(5):
z.append(x[i][j+k])
if z.count("X")==4 and z.count("O")==0:
... | 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,692,904,711 | 2,147,483,647 | Python 3 | OK | TESTS | 20 | 92 | 0 | def can_divide_watermelon(weight):
if weight % 2 == 0 and weight > 2:
return "YES"
else:
return "NO"
# Read input
w = int(input())
# Check if they can divide the watermelon as per the conditions
result = can_divide_watermelon(w)
# Print the result
print(result) | 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(weight):
if weight % 2 == 0 and weight > 2:
return "YES"
else:
return "NO"
# Read input
w = int(input())
# Check if they can divide the watermelon as per the conditions
result = can_divide_watermelon(w)
# Print the result
print(result)
``` | 3.954 |
108 | A | Palindromic Times | PROGRAMMING | 1,000 | [
"implementation",
"strings"
] | A. Palindromic Times | 2 | 256 | Tattah is asleep if and only if Tattah is attending a lecture. This is a well-known formula among Tattah's colleagues.
On a Wednesday afternoon, Tattah was attending Professor HH's lecture. At 12:21, right before falling asleep, he was staring at the digital watch around Saher's wrist. He noticed that the digits on th... | The first and only line of the input starts with a string with the format "HH:MM" where "HH" is from "00" to "23" and "MM" is from "00" to "59". Both "HH" and "MM" have exactly two digits. | Print the palindromic time of day that comes soonest after the time given in the input. If the input time is palindromic, output the soonest palindromic time after the input time. | [
"12:21\n",
"23:59\n"
] | [
"13:31\n",
"00:00\n"
] | none | 500 | [
{
"input": "12:21",
"output": "13:31"
},
{
"input": "23:59",
"output": "00:00"
},
{
"input": "15:51",
"output": "20:02"
},
{
"input": "10:44",
"output": "11:11"
},
{
"input": "04:02",
"output": "04:40"
},
{
"input": "02:11",
"output": "02:20"
},
... | 1,487,784,220 | 520 | Python 3 | OK | TESTS | 36 | 124 | 4,608,000 |
def next(h, m):
m += 1
if m == 60:
m = 0
h += 1
if h == 24:
h = 0
return (h, m)
a, b = map(int, input().split(':'))
found = False
result = None
while not found:
a, b = next(a, b)
a_pa, b_pa = '0'*(2 - len(str(a))) + str(a), '0'*(2 - len(str(b))) + str(b)
if a_pa ... | Title: Palindromic Times
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Tattah is asleep if and only if Tattah is attending a lecture. This is a well-known formula among Tattah's colleagues.
On a Wednesday afternoon, Tattah was attending Professor HH's lecture. At 12:21, right before falling... | ```python
def next(h, m):
m += 1
if m == 60:
m = 0
h += 1
if h == 24:
h = 0
return (h, m)
a, b = map(int, input().split(':'))
found = False
result = None
while not found:
a, b = next(a, b)
a_pa, b_pa = '0'*(2 - len(str(a))) + str(a), '0'*(2 - len(str(b))) + str(b)
... | 3.960417 |
263 | A | Beautiful Matrix | PROGRAMMING | 800 | [
"implementation"
] | null | null | You've got a 5<=Γ<=5 matrix, consisting of 24 zeroes and a single number one. Let's index the matrix rows by numbers from 1 to 5 from top to bottom, let's index the matrix columns by numbers from 1 to 5 from left to right. In one move, you are allowed to apply one of the two following transformations to the matrix:
1.... | The input consists of five lines, each line contains five integers: the *j*-th integer in the *i*-th line of the input represents the element of the matrix that is located on the intersection of the *i*-th row and the *j*-th column. It is guaranteed that the matrix consists of 24 zeroes and a single number one. | Print a single integer β the minimum number of moves needed to make the matrix beautiful. | [
"0 0 0 0 0\n0 0 0 0 1\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n",
"0 0 0 0 0\n0 0 0 0 0\n0 1 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n"
] | [
"3\n",
"1\n"
] | none | 500 | [
{
"input": "0 0 0 0 0\n0 0 0 0 1\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0",
"output": "3"
},
{
"input": "0 0 0 0 0\n0 0 0 0 0\n0 1 0 0 0\n0 0 0 0 0\n0 0 0 0 0",
"output": "1"
},
{
"input": "0 0 0 0 0\n0 0 0 0 0\n0 0 1 0 0\n0 0 0 0 0\n0 0 0 0 0",
"output": "0"
},
{
"input": "0 0 0 0 0... | 1,697,012,673 | 2,147,483,647 | Python 3 | OK | TESTS | 25 | 92 | 0 | mat = [list(map(int, input().split())) for i in range(5)]
def find_one(mat):
for i in range(5):
for j in range(5):
if mat[i][j]==1:
point=(i,j)
return point
def find_the_minimum_path(mat):
point= find_one(mat)
return abs(point[0] - 2) + abs(point[1] - 2)
pr... | Title: Beautiful Matrix
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You've got a 5<=Γ<=5 matrix, consisting of 24 zeroes and a single number one. Let's index the matrix rows by numbers from 1 to 5 from top to bottom, let's index the matrix columns by numbers from 1 to 5 from left to ri... | ```python
mat = [list(map(int, input().split())) for i in range(5)]
def find_one(mat):
for i in range(5):
for j in range(5):
if mat[i][j]==1:
point=(i,j)
return point
def find_the_minimum_path(mat):
point= find_one(mat)
return abs(point[0] - 2) + abs(point[... | 3 | |
500 | A | New Year Transportation | PROGRAMMING | 1,000 | [
"dfs and similar",
"graphs",
"implementation"
] | null | null | New Year is coming in Line World! In this world, there are *n* cells numbered by integers from 1 to *n*, as a 1<=Γ<=*n* board. People live in cells. However, it was hard to move between distinct cells, because of the difficulty of escaping the cell. People wanted to meet people who live in other cells.
So, user tncks0... | The first line contains two space-separated integers *n* (3<=β€<=*n*<=β€<=3<=Γ<=104) and *t* (2<=β€<=*t*<=β€<=*n*) β the number of cells, and the index of the cell which I want to go to.
The second line contains *n*<=-<=1 space-separated integers *a*1,<=*a*2,<=...,<=*a**n*<=-<=1 (1<=β€<=*a**i*<=β€<=*n*<=-<=*i*). It is guara... | If I can go to cell *t* using the transportation system, print "YES". Otherwise, print "NO". | [
"8 4\n1 2 1 2 1 2 1\n",
"8 5\n1 2 1 2 1 1 1\n"
] | [
"YES\n",
"NO\n"
] | In the first sample, the visited cells are: 1,β2,β4; so we can successfully visit the cell 4.
In the second sample, the possible cells to visit are: 1,β2,β4,β6,β7,β8; so we can't visit the cell 5, which we want to visit. | 500 | [
{
"input": "8 4\n1 2 1 2 1 2 1",
"output": "YES"
},
{
"input": "8 5\n1 2 1 2 1 1 1",
"output": "NO"
},
{
"input": "20 19\n13 16 7 6 12 1 5 7 8 6 5 7 5 5 3 3 2 2 1",
"output": "YES"
},
{
"input": "50 49\n11 7 1 41 26 36 19 16 38 14 36 35 37 27 20 27 3 6 21 2 27 11 18 17 19 16 ... | 1,696,218,176 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 46 | 3,584,000 | n , t = map(int,input().split())
a = list(map(int,input().split()))
m = 1
while True :
if m < t :
m+=a[m-1]
elif m == t :
print("YES")
break
else :
print("NO")
break | Title: New Year Transportation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
New Year is coming in Line World! In this world, there are *n* cells numbered by integers from 1 to *n*, as a 1<=Γ<=*n* board. People live in cells. However, it was hard to move between distinct cells, because o... | ```python
n , t = map(int,input().split())
a = list(map(int,input().split()))
m = 1
while True :
if m < t :
m+=a[m-1]
elif m == t :
print("YES")
break
else :
print("NO")
break
``` | 3 | |
155 | A | I_love_\%username\% | PROGRAMMING | 800 | [
"brute force"
] | null | null | Vasya adores sport programming. He can't write programs but he loves to watch the contests' progress. Vasya even has a favorite coder and Vasya pays special attention to him.
One day Vasya decided to collect the results of all contests where his favorite coder participated and track the progress of his coolness. For e... | The first line contains the single integer *n* (1<=β€<=*n*<=β€<=1000) β the number of contests where the coder participated.
The next line contains *n* space-separated non-negative integer numbers β they are the points which the coder has earned. The points are given in the chronological order. All points do not exceed ... | Print the single number β the number of amazing performances the coder has had during his whole history of participating in the contests. | [
"5\n100 50 200 150 200\n",
"10\n4664 6496 5814 7010 5762 5736 6944 4850 3698 7242\n"
] | [
"2\n",
"4\n"
] | In the first sample the performances number 2 and 3 are amazing.
In the second sample the performances number 2, 4, 9 and 10 are amazing. | 500 | [
{
"input": "5\n100 50 200 150 200",
"output": "2"
},
{
"input": "10\n4664 6496 5814 7010 5762 5736 6944 4850 3698 7242",
"output": "4"
},
{
"input": "1\n6",
"output": "0"
},
{
"input": "2\n2 1",
"output": "1"
},
{
"input": "5\n100 36 53 7 81",
"output": "2"
... | 1,673,459,880 | 2,147,483,647 | Python 3 | OK | TESTS | 37 | 436 | 0 | n=int(input())
inp=input()
c=0
score=list(map(int,inp.split(" ")))
for i in range(1,n):
flag=0
for j in range(i):
if score[j]<=score[i]:
flag=1
if flag==0:
c+=1
for i in range(1,n):
flag=0
for j in range(i):
if score[j]>=score[i]:
... | Title: I_love_\%username\%
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya adores sport programming. He can't write programs but he loves to watch the contests' progress. Vasya even has a favorite coder and Vasya pays special attention to him.
One day Vasya decided to collect the re... | ```python
n=int(input())
inp=input()
c=0
score=list(map(int,inp.split(" ")))
for i in range(1,n):
flag=0
for j in range(i):
if score[j]<=score[i]:
flag=1
if flag==0:
c+=1
for i in range(1,n):
flag=0
for j in range(i):
if score[j]>=score[i]:
... | 3 | |
633 | B | A Trivial Problem | PROGRAMMING | 1,300 | [
"brute force",
"constructive algorithms",
"math",
"number theory"
] | null | null | Mr. Santa asks all the great programmers of the world to solve a trivial problem. He gives them an integer *m* and asks for the number of positive integers *n*, such that the factorial of *n* ends with exactly *m* zeroes. Are you among those great programmers who can solve this problem? | The only line of input contains an integer *m* (1<=β€<=*m*<=β€<=100<=000)Β β the required number of trailing zeroes in factorial. | First print *k*Β β the number of values of *n* such that the factorial of *n* ends with *m* zeroes. Then print these *k* integers in increasing order. | [
"1\n",
"5\n"
] | [
"5\n5 6 7 8 9 ",
"0"
] | The factorial of *n* is equal to the product of all integers from 1 to *n* inclusive, that is *n*!β=β1Β·2Β·3Β·...Β·*n*.
In the first sample, 5!β=β120, 6!β=β720, 7!β=β5040, 8!β=β40320 and 9!β=β362880. | 500 | [
{
"input": "1",
"output": "5\n5 6 7 8 9 "
},
{
"input": "5",
"output": "0"
},
{
"input": "2",
"output": "5\n10 11 12 13 14 "
},
{
"input": "3",
"output": "5\n15 16 17 18 19 "
},
{
"input": "7",
"output": "5\n30 31 32 33 34 "
},
{
"input": "12",
"ou... | 1,623,924,214 | 2,147,483,647 | PyPy 3 | OK | TESTS | 68 | 109 | 1,536,000 | n = int(input())
k = 0
i = 1
while k < n:
a = i
while a % 5 == 0 and a != 0:
k = k + 1
a = a / 5
i = i + 1
if k != n:
print(0)
else:
print(5)
print(i - 1, i, i + 1, i + 2, i + 3) | Title: A Trivial Problem
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mr. Santa asks all the great programmers of the world to solve a trivial problem. He gives them an integer *m* and asks for the number of positive integers *n*, such that the factorial of *n* ends with exactly *m* zer... | ```python
n = int(input())
k = 0
i = 1
while k < n:
a = i
while a % 5 == 0 and a != 0:
k = k + 1
a = a / 5
i = i + 1
if k != n:
print(0)
else:
print(5)
print(i - 1, i, i + 1, i + 2, i + 3)
``` | 3 | |
766 | A | Mahmoud and Longest Uncommon Subsequence | PROGRAMMING | 1,000 | [
"constructive algorithms",
"strings"
] | null | null | While Mahmoud and Ehab were practicing for IOI, they found a problem which name was Longest common subsequence. They solved it, and then Ehab challenged Mahmoud with another problem.
Given two strings *a* and *b*, find the length of their longest uncommon subsequence, which is the longest string that is a subsequence ... | The first line contains string *a*, and the second lineΒ β string *b*. Both of these strings are non-empty and consist of lowercase letters of English alphabet. The length of each string is not bigger than 105 characters. | If there's no uncommon subsequence, print "-1". Otherwise print the length of the longest uncommon subsequence of *a* and *b*. | [
"abcd\ndefgh\n",
"a\na\n"
] | [
"5\n",
"-1\n"
] | In the first example: you can choose "defgh" from string *b* as it is the longest subsequence of string *b* that doesn't appear as a subsequence of string *a*. | 500 | [
{
"input": "abcd\ndefgh",
"output": "5"
},
{
"input": "a\na",
"output": "-1"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaacccccccccccccccccccccccccccccccccccccccccccccccccc\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaadddddddddddddddddddddddddddddddddddddddddddd... | 1,664,956,389 | 2,147,483,647 | Python 3 | OK | TESTS | 73 | 46 | 102,400 | x=input()
y=input()
if x==y:
print(-1)
else:
x=len(x)
y=len(y)
print(max(x,y)) | Title: Mahmoud and Longest Uncommon Subsequence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
While Mahmoud and Ehab were practicing for IOI, they found a problem which name was Longest common subsequence. They solved it, and then Ehab challenged Mahmoud with another problem.
Given two ... | ```python
x=input()
y=input()
if x==y:
print(-1)
else:
x=len(x)
y=len(y)
print(max(x,y))
``` | 3 | |
6 | A | Triangle | PROGRAMMING | 900 | [
"brute force",
"geometry"
] | A. Triangle | 2 | 64 | Johnny has a younger sister Anne, who is very clever and smart. As she came home from the kindergarten, she told his brother about the task that her kindergartener asked her to solve. The task was just to construct a triangle out of four sticks of different colours. Naturally, one of the sticks is extra. It is not allo... | The first line of the input contains four space-separated positive integer numbers not exceeding 100 β lengthes of the sticks. | Output TRIANGLE if it is possible to construct a non-degenerate triangle. Output SEGMENT if the first case cannot take place and it is possible to construct a degenerate triangle. Output IMPOSSIBLE if it is impossible to construct any triangle. Remember that you are to use three sticks. It is not allowed to break the s... | [
"4 2 1 3\n",
"7 2 2 4\n",
"3 5 9 1\n"
] | [
"TRIANGLE\n",
"SEGMENT\n",
"IMPOSSIBLE\n"
] | none | 0 | [
{
"input": "4 2 1 3",
"output": "TRIANGLE"
},
{
"input": "7 2 2 4",
"output": "SEGMENT"
},
{
"input": "3 5 9 1",
"output": "IMPOSSIBLE"
},
{
"input": "3 1 5 1",
"output": "IMPOSSIBLE"
},
{
"input": "10 10 10 10",
"output": "TRIANGLE"
},
{
"input": "11 ... | 1,478,968,621 | 2,147,483,647 | Python 3 | OK | TESTS | 83 | 124 | 0 | a,b,c,d=input().split()
a=int(a)
b=int(b)
c=int(c)
d=int(d)
if (a>b): a,b=b,a
if (b>c): b,c=c,b
if (c>d): c,d=d,c
if (a>b): a,b=b,a
if (b>c): b,c=c,b
if (a>b): a,b=b,a
if (a+b<c and b+c<d): print("IMPOSSIBLE")
elif (a+b>c or b+c>d): print ("TRIANGLE")
else: print ("SEGMENT")
| Title: Triangle
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
Johnny has a younger sister Anne, who is very clever and smart. As she came home from the kindergarten, she told his brother about the task that her kindergartener asked her to solve. The task was just to construct a triangle out o... | ```python
a,b,c,d=input().split()
a=int(a)
b=int(b)
c=int(c)
d=int(d)
if (a>b): a,b=b,a
if (b>c): b,c=c,b
if (c>d): c,d=d,c
if (a>b): a,b=b,a
if (b>c): b,c=c,b
if (a>b): a,b=b,a
if (a+b<c and b+c<d): print("IMPOSSIBLE")
elif (a+b>c or b+c>d): print ("TRIANGLE")
else: print ("SEGMENT")
``` | 3.969 |
599 | A | Patrick and Shopping | PROGRAMMING | 800 | [
"implementation"
] | null | null | Today Patrick waits for a visit from his friend Spongebob. To prepare for the visit, Patrick needs to buy some goodies in two stores located near his house. There is a *d*1 meter long road between his house and the first shop and a *d*2 meter long road between his house and the second shop. Also, there is a road of len... | The first line of the input contains three integers *d*1, *d*2, *d*3 (1<=β€<=*d*1,<=*d*2,<=*d*3<=β€<=108)Β β the lengths of the paths.
- *d*1 is the length of the path connecting Patrick's house and the first shop; - *d*2 is the length of the path connecting Patrick's house and the second shop; - *d*3 is the length o... | Print the minimum distance that Patrick will have to walk in order to visit both shops and return to his house. | [
"10 20 30\n",
"1 1 5\n"
] | [
"60\n",
"4\n"
] | The first sample is shown on the picture in the problem statement. One of the optimal routes is: house <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> first shop <img align="middle" class="tex-form... | 500 | [
{
"input": "10 20 30",
"output": "60"
},
{
"input": "1 1 5",
"output": "4"
},
{
"input": "100 33 34",
"output": "134"
},
{
"input": "777 777 777",
"output": "2331"
},
{
"input": "2 2 8",
"output": "8"
},
{
"input": "12 34 56",
"output": "92"
},
... | 1,674,219,445 | 2,147,483,647 | Python 3 | OK | TESTS | 21 | 46 | 0 | d1,d2,d3 = map(int,input().split())
x = (d1+d2)*2
y = (d1+d2+d3)
z = (d1+d3)*2
w = (d2+d3)*2
print(min(x,y,z,w)) | Title: Patrick and Shopping
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Today Patrick waits for a visit from his friend Spongebob. To prepare for the visit, Patrick needs to buy some goodies in two stores located near his house. There is a *d*1 meter long road between his house and the... | ```python
d1,d2,d3 = map(int,input().split())
x = (d1+d2)*2
y = (d1+d2+d3)
z = (d1+d3)*2
w = (d2+d3)*2
print(min(x,y,z,w))
``` | 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,668,383,335 | 2,147,483,647 | Python 3 | OK | TESTS | 46 | 124 | 716,800 | # vitality and pie
doors = int(input())
keys = [0]*26
sequence = input()
contador = 0
for i in range(len(sequence)):
valueAscii = ord(sequence[i])
if valueAscii >= 65 and valueAscii <= 90: # Γ© porta
if keys[valueAscii-65] == 0: contador += 1 # nΓ£o tem chave
else: keys[valueAscii-65] -= 1 # ... | 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
# vitality and pie
doors = int(input())
keys = [0]*26
sequence = input()
contador = 0
for i in range(len(sequence)):
valueAscii = ord(sequence[i])
if valueAscii >= 65 and valueAscii <= 90: # Γ© porta
if keys[valueAscii-65] == 0: contador += 1 # nΓ£o tem chave
else: keys[valueAscii-6... | 3 | |
431 | A | Black Square | PROGRAMMING | 800 | [
"implementation"
] | null | null | Quite recently, a very smart student named Jury decided that lectures are boring, so he downloaded a game called "Black Square" on his super cool touchscreen phone.
In this game, the phone's screen is divided into four vertical strips. Each second, a black square appears on some of the strips. According to the rules o... | The first line contains four space-separated integers *a*1, *a*2, *a*3, *a*4 (0<=β€<=*a*1,<=*a*2,<=*a*3,<=*a*4<=β€<=104).
The second line contains string *s* (1<=β€<=|*s*|<=β€<=105), where the *Ρ*-th character of the string equals "1", if on the *i*-th second of the game the square appears on the first strip, "2", if it a... | Print a single integer β the total number of calories that Jury wastes. | [
"1 2 3 4\n123214\n",
"1 5 3 2\n11221\n"
] | [
"13\n",
"13\n"
] | none | 500 | [
{
"input": "1 2 3 4\n123214",
"output": "13"
},
{
"input": "1 5 3 2\n11221",
"output": "13"
},
{
"input": "5 5 5 1\n3422",
"output": "16"
},
{
"input": "4 3 2 1\n2",
"output": "3"
},
{
"input": "5651 6882 6954 4733\n2442313421",
"output": "60055"
},
{
... | 1,666,889,344 | 2,147,483,647 | PyPy 3 | OK | TESTS | 49 | 93 | 1,945,600 | cal = list(map (int, input().split(' ')))
s = input()
sum = 0
for i in range (len(s)):
sum = sum + cal[int (s[i]) - 1]
print (sum)
| Title: Black Square
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Quite recently, a very smart student named Jury decided that lectures are boring, so he downloaded a game called "Black Square" on his super cool touchscreen phone.
In this game, the phone's screen is divided into four ve... | ```python
cal = list(map (int, input().split(' ')))
s = input()
sum = 0
for i in range (len(s)):
sum = sum + cal[int (s[i]) - 1]
print (sum)
``` | 3 | |
431 | A | Black Square | PROGRAMMING | 800 | [
"implementation"
] | null | null | Quite recently, a very smart student named Jury decided that lectures are boring, so he downloaded a game called "Black Square" on his super cool touchscreen phone.
In this game, the phone's screen is divided into four vertical strips. Each second, a black square appears on some of the strips. According to the rules o... | The first line contains four space-separated integers *a*1, *a*2, *a*3, *a*4 (0<=β€<=*a*1,<=*a*2,<=*a*3,<=*a*4<=β€<=104).
The second line contains string *s* (1<=β€<=|*s*|<=β€<=105), where the *Ρ*-th character of the string equals "1", if on the *i*-th second of the game the square appears on the first strip, "2", if it a... | Print a single integer β the total number of calories that Jury wastes. | [
"1 2 3 4\n123214\n",
"1 5 3 2\n11221\n"
] | [
"13\n",
"13\n"
] | none | 500 | [
{
"input": "1 2 3 4\n123214",
"output": "13"
},
{
"input": "1 5 3 2\n11221",
"output": "13"
},
{
"input": "5 5 5 1\n3422",
"output": "16"
},
{
"input": "4 3 2 1\n2",
"output": "3"
},
{
"input": "5651 6882 6954 4733\n2442313421",
"output": "60055"
},
{
... | 1,657,001,711 | 2,147,483,647 | Python 3 | OK | TESTS | 49 | 77 | 716,800 | a1,a2,a3,a4=list(map(int,input().split()))
str1=list(map(int,input()))
sum=0
for i in str1:
if i==1:sum+=a1
elif i==2:sum+=a2
elif i==3:sum+=a3
else :sum+=a4
print(sum) | Title: Black Square
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Quite recently, a very smart student named Jury decided that lectures are boring, so he downloaded a game called "Black Square" on his super cool touchscreen phone.
In this game, the phone's screen is divided into four ve... | ```python
a1,a2,a3,a4=list(map(int,input().split()))
str1=list(map(int,input()))
sum=0
for i in str1:
if i==1:sum+=a1
elif i==2:sum+=a2
elif i==3:sum+=a3
else :sum+=a4
print(sum)
``` | 3 | |
583 | A | Asphalting Roads | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | City X consists of *n* vertical and *n* horizontal infinite roads, forming *n*<=Γ<=*n* intersections. Roads (both vertical and horizontal) are numbered from 1 to *n*, and the intersections are indicated by the numbers of the roads that form them.
Sand roads have long been recognized out of date, so the decision was ma... | The first line contains integer *n* (1<=β€<=*n*<=β€<=50) β the number of vertical and horizontal roads in the city.
Next *n*2 lines contain the order of intersections in the schedule. The *i*-th of them contains two numbers *h**i*,<=*v**i* (1<=β€<=*h**i*,<=*v**i*<=β€<=*n*), separated by a space, and meaning that the inte... | In the single line print the numbers of the days when road works will be in progress in ascending order. The days are numbered starting from 1. | [
"2\n1 1\n1 2\n2 1\n2 2\n",
"1\n1 1\n"
] | [
"1 4 \n",
"1 \n"
] | In the sample the brigade acts like that:
1. On the first day the brigade comes to the intersection of the 1-st horizontal and the 1-st vertical road. As none of them has been asphalted, the workers asphalt the 1-st vertical and the 1-st horizontal road; 1. On the second day the brigade of the workers comes to the i... | 500 | [
{
"input": "2\n1 1\n1 2\n2 1\n2 2",
"output": "1 4 "
},
{
"input": "1\n1 1",
"output": "1 "
},
{
"input": "2\n1 1\n2 2\n1 2\n2 1",
"output": "1 2 "
},
{
"input": "2\n1 2\n2 2\n2 1\n1 1",
"output": "1 3 "
},
{
"input": "3\n2 2\n1 2\n3 2\n3 3\n1 1\n2 3\n1 3\n3 1\n2 ... | 1,617,431,024 | 2,147,483,647 | PyPy 3 | OK | TESTS | 39 | 171 | 3,891,200 | from collections import defaultdict as dd
from bisect import bisect_left as bl,bisect_right as br
inp =lambda: int(input())
strng =lambda: input().strip()
jn =lambda x,l: x.join(map(str,l))
strl =lambda: list(input().strip())
mul =lambda: map(int,input().strip().split())
mulf =lambda: map(fl... | Title: Asphalting Roads
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
City X consists of *n* vertical and *n* horizontal infinite roads, forming *n*<=Γ<=*n* intersections. Roads (both vertical and horizontal) are numbered from 1 to *n*, and the intersections are indicated by the numbers ... | ```python
from collections import defaultdict as dd
from bisect import bisect_left as bl,bisect_right as br
inp =lambda: int(input())
strng =lambda: input().strip()
jn =lambda x,l: x.join(map(str,l))
strl =lambda: list(input().strip())
mul =lambda: map(int,input().strip().split())
mulf =lamb... | 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,656,951,914 | 2,147,483,647 | PyPy 3 | OK | TESTS | 102 | 108 | 0 | n = input()
s = input()
lis = []
for i in range(0,len(n)):
if n[i] == s[i]:
lis.append(0)
else:
lis.append(1)
print(*lis,sep ='')
| Title: Ultra-Fast Mathematician
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 10... | ```python
n = input()
s = input()
lis = []
for i in range(0,len(n)):
if n[i] == s[i]:
lis.append(0)
else:
lis.append(1)
print(*lis,sep ='')
``` | 3.973 |
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,619,788,281 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 124 | 0 | word=input()
countlow=0
countup=0
for i in word:
if i.islower():
countlow=countlow+1
else:
countup=countup+1
if countup<=countlow:
print(word.lower())
else:
print(word.upper())
| Title: Word
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it ei... | ```python
word=input()
countlow=0
countup=0
for i in word:
if i.islower():
countlow=countlow+1
else:
countup=countup+1
if countup<=countlow:
print(word.lower())
else:
print(word.upper())
``` | 3.969 |
431 | C | k-Tree | PROGRAMMING | 1,600 | [
"dp",
"implementation",
"trees"
] | null | null | Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a *k*-tree.
A *k*-tree is an infinite rooted tree where:
- each vertex has exactly *k* children; - each edge has some weight; - if we look at the edges that goes... | A single line contains three space-separated integers: *n*, *k* and *d* (1<=β€<=*n*,<=*k*<=β€<=100; 1<=β€<=*d*<=β€<=*k*). | Print a single integer β the answer to the problem modulo 1000000007 (109<=+<=7). | [
"3 3 2\n",
"3 3 3\n",
"4 3 2\n",
"4 5 2\n"
] | [
"3\n",
"1\n",
"6\n",
"7\n"
] | none | 1,500 | [
{
"input": "3 3 2",
"output": "3"
},
{
"input": "3 3 3",
"output": "1"
},
{
"input": "4 3 2",
"output": "6"
},
{
"input": "4 5 2",
"output": "7"
},
{
"input": "28 6 3",
"output": "110682188"
},
{
"input": "5 100 1",
"output": "16"
},
{
"inp... | 1,664,096,109 | 2,147,483,647 | PyPy 3 | OK | TESTS | 54 | 124 | 3,584,000 | import collections
import heapq
import sys
import math
import itertools
import bisect
from io import BytesIO, IOBase
import os
######################################################################################
#--------------------------------------funs here-------------------------------------#
###################... | Title: k-Tree
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a *k*-tree.
A *k*-tree is an infinite rooted tree where:
- each vertex ... | ```python
import collections
import heapq
import sys
import math
import itertools
import bisect
from io import BytesIO, IOBase
import os
######################################################################################
#--------------------------------------funs here-------------------------------------#
#########... | 3 | |
151 | A | Soft Drinking | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | This winter is so cold in Nvodsk! A group of *n* friends decided to buy *k* bottles of a soft drink called "Take-It-Light" to warm up a bit. Each bottle has *l* milliliters of the drink. Also they bought *c* limes and cut each of them into *d* slices. After that they found *p* grams of salt.
To make a toast, each frie... | The first and only line contains positive integers *n*, *k*, *l*, *c*, *d*, *p*, *nl*, *np*, not exceeding 1000 and no less than 1. The numbers are separated by exactly one space. | Print a single integer β the number of toasts each friend can make. | [
"3 4 5 10 8 100 3 1\n",
"5 100 10 1 19 90 4 3\n",
"10 1000 1000 25 23 1 50 1\n"
] | [
"2\n",
"3\n",
"0\n"
] | A comment to the first sample:
Overall the friends have 4β*β5β=β20 milliliters of the drink, it is enough to make 20β/β3β=β6 toasts. The limes are enough for 10β*β8β=β80 toasts and the salt is enough for 100β/β1β=β100 toasts. However, there are 3 friends in the group, so the answer is *min*(6,β80,β100)β/β3β=β2. | 500 | [
{
"input": "3 4 5 10 8 100 3 1",
"output": "2"
},
{
"input": "5 100 10 1 19 90 4 3",
"output": "3"
},
{
"input": "10 1000 1000 25 23 1 50 1",
"output": "0"
},
{
"input": "1 7 4 5 5 8 3 2",
"output": "4"
},
{
"input": "2 3 3 5 5 10 1 3",
"output": "1"
},
{
... | 1,671,552,837 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 27 | 124 | 0 | n,k,l,c,d,p,nl,np=tuple(map(int,input().split()))
toast=min((k*l)//nl,c*d,p//np)
print(toast//n) | Title: Soft Drinking
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
This winter is so cold in Nvodsk! A group of *n* friends decided to buy *k* bottles of a soft drink called "Take-It-Light" to warm up a bit. Each bottle has *l* milliliters of the drink. Also they bought *c* limes and cut... | ```python
n,k,l,c,d,p,nl,np=tuple(map(int,input().split()))
toast=min((k*l)//nl,c*d,p//np)
print(toast//n)
``` | 3 | |
2 | A | Winner | PROGRAMMING | 1,500 | [
"hashing",
"implementation"
] | A. Winner | 1 | 64 | The winner of the card game popular in Berland "Berlogging" is determined according to the following rules. If at the end of the game there is only one player with the maximum number of points, he is the winner. The situation becomes more difficult if the number of such players is more than one. During each round a pla... | The first line contains an integer number *n* (1<=<=β€<=<=*n*<=<=β€<=<=1000), *n* is the number of rounds played. Then follow *n* lines, containing the information about the rounds in "name score" format in chronological order, where name is a string of lower-case Latin letters with the length from 1 to 32, and score is ... | Print the name of the winner. | [
"3\nmike 3\nandrew 5\nmike 2\n",
"3\nandrew 3\nandrew 2\nmike 5\n"
] | [
"andrew\n",
"andrew\n"
] | none | 0 | [
{
"input": "3\nmike 3\nandrew 5\nmike 2",
"output": "andrew"
},
{
"input": "3\nandrew 3\nandrew 2\nmike 5",
"output": "andrew"
},
{
"input": "5\nkaxqybeultn -352\nmgochgrmeyieyskhuourfg -910\nkaxqybeultn 691\nmgochgrmeyieyskhuourfg -76\nkaxqybeultn -303",
"output": "kaxqybeultn"
},... | 1,597,228,134 | 5,634 | Python 3 | OK | TESTS | 20 | 218 | 6,963,200 | n =int(input())
x = []
y = []
for i in range(n):
name,points = map(str,input().split())
x.append(name)
y.append(int(points))
d = {}
for N,p in zip(x,y):
if N in d:
d[N]+=p
else:
d[N]=p
d1 = {}
mx = 0
for i in range(n):
mx = max(mx,d[x[i]])
for i in range(n):
if x... | Title: Winner
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
The winner of the card game popular in Berland "Berlogging" is determined according to the following rules. If at the end of the game there is only one player with the maximum number of points, he is the winner. The situation becomes... | ```python
n =int(input())
x = []
y = []
for i in range(n):
name,points = map(str,input().split())
x.append(name)
y.append(int(points))
d = {}
for N,p in zip(x,y):
if N in d:
d[N]+=p
else:
d[N]=p
d1 = {}
mx = 0
for i in range(n):
mx = max(mx,d[x[i]])
for i in range(... | 3.83912 |
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,585,353,428 | 2,147,483,647 | Python 3 | OK | TESTS | 49 | 124 | 0 | trash = input()
word = input()
vowels = set(['a', 'e', 'i', 'o', 'u', 'y' ])
new_word = ''
for i in range(0, len(word)):
current = word[i]
prev = word[i - 1] if i - 1 >= 0 else None
if not(current in vowels and prev in vowels):
new_word = new_word + current
print(new_word)
... | 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
trash = input()
word = input()
vowels = set(['a', 'e', 'i', 'o', 'u', 'y' ])
new_word = ''
for i in range(0, len(word)):
current = word[i]
prev = word[i - 1] if i - 1 >= 0 else None
if not(current in vowels and prev in vowels):
new_word = new_word + current
print(new_word)
... | 3 | |
999 | A | Mishka and Contest | PROGRAMMING | 800 | [
"brute force",
"implementation"
] | null | null | Mishka started participating in a programming contest. There are $n$ problems in the contest. Mishka's problem-solving skill is equal to $k$.
Mishka arranges all problems from the contest into a list. Because of his weird principles, Mishka only solves problems from one of the ends of the list. Every time, he chooses ... | The first line of input contains two integers $n$ and $k$ ($1 \le n, k \le 100$) β the number of problems in the contest and Mishka's problem-solving skill.
The second line of input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 100$), where $a_i$ is the difficulty of the $i$-th problem. The problems are... | Print one integer β the maximum number of problems Mishka can solve. | [
"8 4\n4 2 3 1 5 1 6 4\n",
"5 2\n3 1 2 1 3\n",
"5 100\n12 34 55 43 21\n"
] | [
"5\n",
"0\n",
"5\n"
] | In the first example, Mishka can solve problems in the following order: $[4, 2, 3, 1, 5, 1, 6, 4] \rightarrow [2, 3, 1, 5, 1, 6, 4] \rightarrow [2, 3, 1, 5, 1, 6] \rightarrow [3, 1, 5, 1, 6] \rightarrow [1, 5, 1, 6] \rightarrow [5, 1, 6]$, so the number of solved problems will be equal to $5$.
In the second example, M... | 0 | [
{
"input": "8 4\n4 2 3 1 5 1 6 4",
"output": "5"
},
{
"input": "5 2\n3 1 2 1 3",
"output": "0"
},
{
"input": "5 100\n12 34 55 43 21",
"output": "5"
},
{
"input": "100 100\n44 47 36 83 76 94 86 69 31 2 22 77 37 51 10 19 25 78 53 25 1 29 48 95 35 53 22 72 49 86 60 38 13 91 89 1... | 1,691,918,699 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 48 | 77 | 0 | n,k = map(int,input().split())
a = list(map(int, input().split()))
sum1 = 0
sum2 = 0
ans = 0
for i in range(len(a)):
if a[i] <= k:
sum1 += 1
else :
break
for j in range(len(a) - 1, -1, -1):
if a[j] <= k:
sum2 += 1
else :
break
ans = sum1 + sum2
if ans > n ... | Title: Mishka and Contest
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mishka started participating in a programming contest. There are $n$ problems in the contest. Mishka's problem-solving skill is equal to $k$.
Mishka arranges all problems from the contest into a list. Because of his... | ```python
n,k = map(int,input().split())
a = list(map(int, input().split()))
sum1 = 0
sum2 = 0
ans = 0
for i in range(len(a)):
if a[i] <= k:
sum1 += 1
else :
break
for j in range(len(a) - 1, -1, -1):
if a[j] <= k:
sum2 += 1
else :
break
ans = sum1 + sum2
i... | 3 | |
847 | G | University Classes | PROGRAMMING | 900 | [
"implementation"
] | null | null | There are *n* student groups at the university. During the study day, each group can take no more than 7 classes. Seven time slots numbered from 1 to 7 are allocated for the classes.
The schedule on Monday is known for each group, i. e. time slots when group will have classes are known.
Your task is to determine the ... | The first line contains a single integer *n* (1<=β€<=*n*<=β€<=1000) β the number of groups.
Each of the following *n* lines contains a sequence consisting of 7 zeroes and ones β the schedule of classes on Monday for a group. If the symbol in a position equals to 1 then the group has class in the corresponding time slot... | Print minimum number of rooms needed to hold all groups classes on Monday. | [
"2\n0101010\n1010101\n",
"3\n0101011\n0011001\n0110111\n"
] | [
"1\n",
"3\n"
] | In the first example one room is enough. It will be occupied in each of the seven time slot by the first group or by the second group.
In the second example three rooms is enough, because in the seventh time slot all three groups have classes. | 0 | [
{
"input": "2\n0101010\n1010101",
"output": "1"
},
{
"input": "3\n0101011\n0011001\n0110111",
"output": "3"
},
{
"input": "1\n0111000",
"output": "1"
},
{
"input": "1\n0000000",
"output": "0"
},
{
"input": "1\n1111111",
"output": "1"
},
{
"input": "2\n... | 1,584,713,586 | 2,147,483,647 | PyPy 3 | OK | TESTS | 21 | 187 | 1,740,800 | n = int(input())
m = []
for i in range(n):
m.append(input())
ma = 0
for i in range(7):
at = 0
for j in range(n):
if m[j][i] == "1":
at += 1
ma = max(ma, at)
print(ma)
| Title: University Classes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* student groups at the university. During the study day, each group can take no more than 7 classes. Seven time slots numbered from 1 to 7 are allocated for the classes.
The schedule on Monday is known ... | ```python
n = int(input())
m = []
for i in range(n):
m.append(input())
ma = 0
for i in range(7):
at = 0
for j in range(n):
if m[j][i] == "1":
at += 1
ma = max(ma, at)
print(ma)
``` | 3 | |
431 | A | Black Square | PROGRAMMING | 800 | [
"implementation"
] | null | null | Quite recently, a very smart student named Jury decided that lectures are boring, so he downloaded a game called "Black Square" on his super cool touchscreen phone.
In this game, the phone's screen is divided into four vertical strips. Each second, a black square appears on some of the strips. According to the rules o... | The first line contains four space-separated integers *a*1, *a*2, *a*3, *a*4 (0<=β€<=*a*1,<=*a*2,<=*a*3,<=*a*4<=β€<=104).
The second line contains string *s* (1<=β€<=|*s*|<=β€<=105), where the *Ρ*-th character of the string equals "1", if on the *i*-th second of the game the square appears on the first strip, "2", if it a... | Print a single integer β the total number of calories that Jury wastes. | [
"1 2 3 4\n123214\n",
"1 5 3 2\n11221\n"
] | [
"13\n",
"13\n"
] | none | 500 | [
{
"input": "1 2 3 4\n123214",
"output": "13"
},
{
"input": "1 5 3 2\n11221",
"output": "13"
},
{
"input": "5 5 5 1\n3422",
"output": "16"
},
{
"input": "4 3 2 1\n2",
"output": "3"
},
{
"input": "5651 6882 6954 4733\n2442313421",
"output": "60055"
},
{
... | 1,683,079,039 | 2,147,483,647 | Python 3 | OK | TESTS | 49 | 62 | 1,126,400 | ap=list(map(int,input().split()))
bp=list(map(int,input()))
p,q=0,0
while p<4:
z=bp.count(p+1)
q+=(ap[p]*z)
p+=1
print(q)
| Title: Black Square
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Quite recently, a very smart student named Jury decided that lectures are boring, so he downloaded a game called "Black Square" on his super cool touchscreen phone.
In this game, the phone's screen is divided into four ve... | ```python
ap=list(map(int,input().split()))
bp=list(map(int,input()))
p,q=0,0
while p<4:
z=bp.count(p+1)
q+=(ap[p]*z)
p+=1
print(q)
``` | 3 | |
55 | C | Pie or die | PROGRAMMING | 1,900 | [
"games"
] | C. Pie or die | 2 | 256 | Volodya and Vlad play the following game. There are *k* pies at the cells of *n*<=<=Γ<=<=*m* board. Each turn Volodya moves one pie to the neighbouring (by side) cell. If the pie lies at the border of the board then Volodya can move it outside the board, get the pie and win. After Volodya's move, Vlad bans some edge at... | First line contains 3 integers, separated by space: 1<=β€<=*n*,<=*m*<=β€<=100 β dimensions of the board and 0<=β€<=*k*<=β€<=100 β the number of pies. Each of the next *k* lines contains 2 integers, separated by space: 1<=β€<=*x*<=β€<=*n*, 1<=β€<=*y*<=β€<=*m* β coordinates of the corresponding pie. There could be more than one ... | Output only one word: "YES" β if Volodya wins, "NO" β otherwise. | [
"2 2 1\n1 2\n",
"3 4 0\n",
"100 50 2\n50 25\n50 25\n"
] | [
"YES",
"NO",
"NO"
] | none | 1,500 | [
{
"input": "2 2 1\n1 2",
"output": "YES"
},
{
"input": "3 4 0",
"output": "NO"
},
{
"input": "100 50 2\n50 25\n50 25",
"output": "NO"
},
{
"input": "20 20 4\n10 10\n10 10\n10 10\n10 10",
"output": "NO"
},
{
"input": "15 15 1\n8 8",
"output": "NO"
},
{
... | 1,651,171,279 | 79 | Python 3 | OK | TESTS | 75 | 92 | 0 | n, m, k = map(int, input().split())
flag = False
while k > 0:
k -= 1
x, y = map(int, input().split())
d = min(x, n - x + 1, y, m - y + 1)
if d <= 5:
flag = True
print("YES" if flag else "NO") | Title: Pie or die
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Volodya and Vlad play the following game. There are *k* pies at the cells of *n*<=<=Γ<=<=*m* board. Each turn Volodya moves one pie to the neighbouring (by side) cell. If the pie lies at the border of the board then Volodya can ... | ```python
n, m, k = map(int, input().split())
flag = False
while k > 0:
k -= 1
x, y = map(int, input().split())
d = min(x, n - x + 1, y, m - y + 1)
if d <= 5:
flag = True
print("YES" if flag else "NO")
``` | 3.977 |
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,667,380,718 | 2,147,483,647 | Python 3 | OK | TESTS | 19 | 92 | 0 | x=input()
y=input()
i,j,c=0,0,1
while j<len(y) and i<len(x):
if x[i]==y[j]:
c+=1
i+=1
j+=1
print(c) | 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
x=input()
y=input()
i,j,c=0,0,1
while j<len(y) and i<len(x):
if x[i]==y[j]:
c+=1
i+=1
j+=1
print(c)
``` | 3 | |
376 | B | I.O.U. | PROGRAMMING | 1,300 | [
"implementation"
] | null | null | Imagine that there is a group of three friends: A, B and Π‘. A owes B 20 rubles and B owes C 20 rubles. The total sum of the debts is 40 rubles. You can see that the debts are not organized in a very optimal manner. Let's rearrange them like that: assume that A owes C 20 rubles and B doesn't owe anything to anybody. The... | The first line contains two integers *n* and *m* (1<=β€<=*n*<=β€<=100;Β 0<=β€<=*m*<=β€<=104). The next *m* lines contain the debts. The *i*-th line contains three integers *a**i*,<=*b**i*,<=*c**i* (1<=β€<=*a**i*,<=*b**i*<=β€<=*n*;Β *a**i*<=β <=*b**i*;Β 1<=β€<=*c**i*<=β€<=100), which mean that person *a**i* owes person *b**i* *c**i... | Print a single integer β the minimum sum of debts in the optimal rearrangement. | [
"5 3\n1 2 10\n2 3 1\n2 4 1\n",
"3 0\n",
"4 3\n1 2 1\n2 3 1\n3 1 1\n"
] | [
"10\n",
"0\n",
"0\n"
] | In the first sample, you can assume that person number 1 owes 8 rubles to person number 2, 1 ruble to person number 3 and 1 ruble to person number 4. He doesn't owe anybody else anything. In the end, the total debt equals 10.
In the second sample, there are no debts.
In the third sample, you can annul all the debts. | 1,000 | [
{
"input": "5 3\n1 2 10\n2 3 1\n2 4 1",
"output": "10"
},
{
"input": "3 0",
"output": "0"
},
{
"input": "4 3\n1 2 1\n2 3 1\n3 1 1",
"output": "0"
},
{
"input": "20 28\n1 5 6\n1 12 7\n1 13 4\n1 15 7\n1 20 3\n2 4 1\n2 15 6\n3 5 3\n3 8 10\n3 13 8\n3 20 6\n4 6 10\n4 12 8\n4 19 5\... | 1,629,459,430 | 2,147,483,647 | Python 3 | OK | TESTS | 29 | 77 | 6,963,200 | n,m=map(int,input().split())
d=dict()
for i in range(0,m):
a,b,c=map(int,input().split())
if a in d:
d[a]=d[a]+c
else:
d[a]=c
if b in d:
d[b]=d[b]-c
else:
d[b]=-c
print(abs(sum([i for i in d.values() if i<0]))) | Title: I.O.U.
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Imagine that there is a group of three friends: A, B and Π‘. A owes B 20 rubles and B owes C 20 rubles. The total sum of the debts is 40 rubles. You can see that the debts are not organized in a very optimal manner. Let's rearran... | ```python
n,m=map(int,input().split())
d=dict()
for i in range(0,m):
a,b,c=map(int,input().split())
if a in d:
d[a]=d[a]+c
else:
d[a]=c
if b in d:
d[b]=d[b]-c
else:
d[b]=-c
print(abs(sum([i for i in d.values() if i<0])))
``` | 3 | |
168 | A | Wizards and Demonstration | PROGRAMMING | 900 | [
"implementation",
"math"
] | null | null | Some country is populated by wizards. They want to organize a demonstration.
There are *n* people living in the city, *x* of them are the wizards who will surely go to the demonstration. Other city people (*n*<=-<=*x* people) do not support the wizards and aren't going to go to the demonstration. We know that the city... | The first line contains three space-separated integers, *n*, *x*, *y* (1<=β€<=*n*,<=*x*,<=*y*<=β€<=104,<=*x*<=β€<=*n*) β the number of citizens in the city, the number of wizards and the percentage the administration needs, correspondingly.
Please note that *y* can exceed 100 percent, that is, the administration wants to... | Print a single integer β the answer to the problem, the minimum number of clones to create, so that the demonstration involved no less than *y* percent of *n* (the real total city population). | [
"10 1 14\n",
"20 10 50\n",
"1000 352 146\n"
] | [
"1\n",
"0\n",
"1108\n"
] | In the first sample it is necessary that at least 14% of 10 people came to the demonstration. As the number of people should be integer, then at least two people should come. There is only one wizard living in the city and he is going to come. That isn't enough, so he needs to create one clone.
In the second sample 1... | 500 | [
{
"input": "10 1 14",
"output": "1"
},
{
"input": "20 10 50",
"output": "0"
},
{
"input": "1000 352 146",
"output": "1108"
},
{
"input": "68 65 20",
"output": "0"
},
{
"input": "78 28 27",
"output": "0"
},
{
"input": "78 73 58",
"output": "0"
},
... | 1,474,723,572 | 2,147,483,647 | Python 3 | OK | TESTS | 43 | 124 | 0 | import math
if __name__ == '__main__':
n, x, y = str(input()).split()
n = int(n)
x = int(x)
y = int(y)
print(max(0, int(math.ceil(n * y / 100)) - x))
| Title: Wizards and Demonstration
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Some country is populated by wizards. They want to organize a demonstration.
There are *n* people living in the city, *x* of them are the wizards who will surely go to the demonstration. Other city people (*n... | ```python
import math
if __name__ == '__main__':
n, x, y = str(input()).split()
n = int(n)
x = int(x)
y = int(y)
print(max(0, int(math.ceil(n * y / 100)) - x))
``` | 3 | |
297 | B | Fish Weight | PROGRAMMING | 1,600 | [
"constructive algorithms",
"greedy"
] | null | null | It is known that there are *k* fish species in the polar ocean, numbered from 1 to *k*. They are sorted by non-decreasing order of their weight, which is a positive number. Let the weight of the *i*-th type of fish be *w**i*, then 0<=<<=*w*1<=β€<=*w*2<=β€<=...<=β€<=*w**k* holds.
Polar bears Alice and Bob each have cau... | The first line contains three integers *n*,<=*m*,<=*k* (1<=β€<=*n*,<=*m*<=β€<=105,<=1<=β€<=*k*<=β€<=109) β the number of fish caught by Alice and Bob respectively, and the number of fish species.
The second line contains *n* integers each from 1 to *k*, the list of fish type caught by Alice. The third line contains *m* in... | Output "YES" (without quotes) if it is possible, and "NO" (without quotes) otherwise. | [
"3 3 3\n2 2 2\n1 1 3\n",
"4 7 9\n5 2 7 3\n3 5 2 7 3 8 7\n"
] | [
"YES\n",
"NO\n"
] | In the first sample, if *w*<sub class="lower-index">1</sub>β=β1,β*w*<sub class="lower-index">2</sub>β=β2,β*w*<sub class="lower-index">3</sub>β=β2.5, then Alice has a total of 2β+β2β+β2β=β6 weight units, while Bob only has 1β+β1β+β2.5β=β4.5.
In the second sample, the fish that Alice caught is a subset of Bob's. Theref... | 500 | [
{
"input": "3 3 3\n2 2 2\n1 1 3",
"output": "YES"
},
{
"input": "4 7 9\n5 2 7 3\n3 5 2 7 3 8 7",
"output": "NO"
},
{
"input": "5 5 10\n8 2 8 5 9\n9 1 7 5 1",
"output": "YES"
},
{
"input": "7 7 10\n8 2 8 10 6 9 10\n2 4 9 5 6 2 5",
"output": "YES"
},
{
"input": "15 ... | 1,658,759,536 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 62 | 278 | 18,944,000 | def solve():
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a.sort()
b.sort()
if n > m: return "YES"
if sum(a) > sum(b) or max(a) > max(b):
return "YES"
i, j = n - 1, m - 1
while i >= 0 and j >= 0:
... | Title: Fish Weight
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
It is known that there are *k* fish species in the polar ocean, numbered from 1 to *k*. They are sorted by non-decreasing order of their weight, which is a positive number. Let the weight of the *i*-th type of fish be *w**i... | ```python
def solve():
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a.sort()
b.sort()
if n > m: return "YES"
if sum(a) > sum(b) or max(a) > max(b):
return "YES"
i, j = n - 1, m - 1
while i >= 0 and j >... | 3 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.