contestId int64 0 1.01k | index stringclasses 57
values | name stringlengths 2 58 | type stringclasses 2
values | rating int64 0 3.5k | tags listlengths 0 11 | title stringclasses 522
values | time-limit stringclasses 8
values | memory-limit stringclasses 8
values | problem-description stringlengths 0 7.15k | input-specification stringlengths 0 2.05k | output-specification stringlengths 0 1.5k | demo-input listlengths 0 7 | demo-output listlengths 0 7 | note stringlengths 0 5.24k | points float64 0 425k | test_cases listlengths 0 402 | creationTimeSeconds int64 1.37B 1.7B | relativeTimeSeconds int64 8 2.15B | programmingLanguage stringclasses 3
values | verdict stringclasses 14
values | testset stringclasses 12
values | passedTestCount int64 0 1k | timeConsumedMillis int64 0 15k | memoryConsumedBytes int64 0 805M | code stringlengths 3 65.5k | prompt stringlengths 262 8.2k | response stringlengths 17 65.5k | score float64 -1 3.99 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
492 | A | Vanya and Cubes | PROGRAMMING | 800 | [
"implementation"
] | null | null | Vanya got *n* cubes. He decided to build a pyramid from them. Vanya wants to build the pyramid as follows: the top level of the pyramid must consist of 1 cube, the second level must consist of 1<=+<=2<==<=3 cubes, the third level must have 1<=+<=2<=+<=3<==<=6 cubes, and so on. Thus, the *i*-th level of the pyramid must... | The first line contains integer *n* (1<=≤<=*n*<=≤<=104) — the number of cubes given to Vanya. | Print the maximum possible height of the pyramid in the single line. | [
"1\n",
"25\n"
] | [
"1\n",
"4\n"
] | Illustration to the second sample: | 500 | [
{
"input": "1",
"output": "1"
},
{
"input": "25",
"output": "4"
},
{
"input": "2",
"output": "1"
},
{
"input": "4115",
"output": "28"
},
{
"input": "9894",
"output": "38"
},
{
"input": "7969",
"output": "35"
},
{
"input": "6560",
"outpu... | 1,693,678,676 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 31 | 0 | def main():
n = int(input())
i = 1
c = 1
while True:
i = i + (i+1)
if i <= n:
c += 1
else:
break
print(c)
if __name__ == "__main__":
main() | Title: Vanya and Cubes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vanya got *n* cubes. He decided to build a pyramid from them. Vanya wants to build the pyramid as follows: the top level of the pyramid must consist of 1 cube, the second level must consist of 1<=+<=2<==<=3 cubes, the t... | ```python
def main():
n = int(input())
i = 1
c = 1
while True:
i = i + (i+1)
if i <= n:
c += 1
else:
break
print(c)
if __name__ == "__main__":
main()
``` | 0 | |
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 | |
400 | B | Inna and New Matrix of Candies | PROGRAMMING | 1,200 | [
"brute force",
"implementation",
"schedules"
] | null | null | Inna likes sweets and a game called the "Candy Matrix". Today, she came up with the new game "Candy Matrix 2: Reload".
The field for the new game is a rectangle table of size *n*<=×<=*m*. Each line of the table contains one cell with a dwarf figurine, one cell with a candy, the other cells of the line are empty. The g... | The first line of the input contains two integers *n* and *m* (1<=≤<=*n*<=≤<=1000; 2<=≤<=*m*<=≤<=1000).
Next *n* lines each contain *m* characters — the game field for the "Candy Martix 2: Reload". Character "*" represents an empty cell of the field, character "G" represents a dwarf and character "S" represents a can... | In a single line print a single integer — either the minimum number of moves needed to achieve the aim of the game, or -1, if the aim cannot be achieved on the given game field. | [
"3 4\n*G*S\nG**S\n*G*S\n",
"1 3\nS*G\n"
] | [
"2\n",
"-1\n"
] | none | 1,000 | [
{
"input": "3 4\n*G*S\nG**S\n*G*S",
"output": "2"
},
{
"input": "1 3\nS*G",
"output": "-1"
},
{
"input": "10 10\nG********S\n*G*******S\n**G******S\n***G*****S\n****G****S\n*****G***S\n******G**S\n*******G*S\n********GS\nG********S",
"output": "9"
},
{
"input": "5 10\nG***S**... | 1,580,457,873 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 109 | 307,200 | n,m=map(int,input().split())
dp=[]
for i in range(n):
x=input()
dp.append(x)
d={}
for i in range(n):
for j in range(m):
if dp[i][j]=='G':
p=j
if dp[i][j]=='S':
q=j
if p<q:
d[i+1]=q-p-1
else:
d[-(i+1)]=m-p-1
#print(d)
cout=-1
y=min(d.items(),key... | Title: Inna and New Matrix of Candies
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Inna likes sweets and a game called the "Candy Matrix". Today, she came up with the new game "Candy Matrix 2: Reload".
The field for the new game is a rectangle table of size *n*<=×<=*m*. Each line of th... | ```python
n,m=map(int,input().split())
dp=[]
for i in range(n):
x=input()
dp.append(x)
d={}
for i in range(n):
for j in range(m):
if dp[i][j]=='G':
p=j
if dp[i][j]=='S':
q=j
if p<q:
d[i+1]=q-p-1
else:
d[-(i+1)]=m-p-1
#print(d)
cout=-1
y=min(d.i... | 0 | |
787 | A | The Monster | PROGRAMMING | 1,200 | [
"brute force",
"math",
"number theory"
] | null | null | A monster is chasing after Rick and Morty on another planet. They're so frightened that sometimes they scream. More accurately, Rick screams at times *b*,<=*b*<=+<=*a*,<=*b*<=+<=2*a*,<=*b*<=+<=3*a*,<=... and Morty screams at times *d*,<=*d*<=+<=*c*,<=*d*<=+<=2*c*,<=*d*<=+<=3*c*,<=....
The Monster will catch them if a... | The first line of input contains two integers *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=100).
The second line contains two integers *c* and *d* (1<=≤<=*c*,<=*d*<=≤<=100). | Print the first time Rick and Morty will scream at the same time, or <=-<=1 if they will never scream at the same time. | [
"20 2\n9 19\n",
"2 1\n16 12\n"
] | [
"82\n",
"-1\n"
] | In the first sample testcase, Rick's 5th scream and Morty's 8th time are at time 82.
In the second sample testcase, all Rick's screams will be at odd times and Morty's will be at even times, so they will never scream at the same time. | 500 | [
{
"input": "20 2\n9 19",
"output": "82"
},
{
"input": "2 1\n16 12",
"output": "-1"
},
{
"input": "39 52\n88 78",
"output": "1222"
},
{
"input": "59 96\n34 48",
"output": "1748"
},
{
"input": "87 37\n91 29",
"output": "211"
},
{
"input": "11 81\n49 7",
... | 1,490,292,115 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 22 | 920 | 4,608,000 | from sys import stdin, stdout
a, b = map(int, stdin.readline().split())
c, d = map(int, stdin.readline().split())
for y in range(10 ** 6):
if (d + c * y - b) / a == int((d + c * y - b) / a) > 0 and (d + y * c == b + a * int((d + c * y - b) / a)):
stdout.write(str(d + c * y))
break
else:... | Title: The Monster
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A monster is chasing after Rick and Morty on another planet. They're so frightened that sometimes they scream. More accurately, Rick screams at times *b*,<=*b*<=+<=*a*,<=*b*<=+<=2*a*,<=*b*<=+<=3*a*,<=... and Morty screams a... | ```python
from sys import stdin, stdout
a, b = map(int, stdin.readline().split())
c, d = map(int, stdin.readline().split())
for y in range(10 ** 6):
if (d + c * y - b) / a == int((d + c * y - b) / a) > 0 and (d + y * c == b + a * int((d + c * y - b) / a)):
stdout.write(str(d + c * y))
br... | 0 | |
764 | B | Timofey and cubes | PROGRAMMING | 900 | [
"constructive algorithms",
"implementation"
] | null | null | Young Timofey has a birthday today! He got kit of *n* cubes as a birthday present from his parents. Every cube has a number *a**i*, which is written on it. Timofey put all the cubes in a row and went to unpack other presents.
In this time, Timofey's elder brother, Dima reordered the cubes using the following rule. Sup... | The first line contains single integer *n* (1<=≤<=*n*<=≤<=2·105) — the number of cubes.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (<=-<=109<=≤<=*a**i*<=≤<=109), where *a**i* is the number written on the *i*-th cube after Dima has changed their order. | Print *n* integers, separated by spaces — the numbers written on the cubes in their initial order.
It can be shown that the answer is unique. | [
"7\n4 3 7 6 9 1 2\n",
"8\n6 1 4 2 5 6 9 2\n"
] | [
"2 3 9 6 7 1 4",
"2 1 6 2 5 4 9 6"
] | Consider the first sample.
1. At the begining row was [2, 3, 9, 6, 7, 1, 4]. 1. After first operation row was [4, 1, 7, 6, 9, 3, 2]. 1. After second operation row was [4, 3, 9, 6, 7, 1, 2]. 1. After third operation row was [4, 3, 7, 6, 9, 1, 2]. 1. At fourth operation we reverse just middle element, so nothing ha... | 1,000 | [
{
"input": "7\n4 3 7 6 9 1 2",
"output": "2 3 9 6 7 1 4"
},
{
"input": "8\n6 1 4 2 5 6 9 2",
"output": "2 1 6 2 5 4 9 6"
},
{
"input": "1\n1424",
"output": "1424"
},
{
"input": "9\n-7 9 -4 9 -6 11 15 2 -10",
"output": "-10 9 15 9 -6 11 -4 2 -7"
},
{
"input": "2\n2... | 1,487,075,919 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 31 | 4,505,600 | n = int(input())
arr = input().split()
for i in range(0,n):
arr[i] = int(arr[i])
start = int ((n+1) / 2)
tmp = 0
for i in reversed(range(1, start)):
tmp = arr[i - 1]
arr[i - 1] = arr[n - i]
arr[n - i] = tmp
print(arr)
| Title: Timofey and cubes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Young Timofey has a birthday today! He got kit of *n* cubes as a birthday present from his parents. Every cube has a number *a**i*, which is written on it. Timofey put all the cubes in a row and went to unpack other p... | ```python
n = int(input())
arr = input().split()
for i in range(0,n):
arr[i] = int(arr[i])
start = int ((n+1) / 2)
tmp = 0
for i in reversed(range(1, start)):
tmp = arr[i - 1]
arr[i - 1] = arr[n - i]
arr[n - i] = tmp
print(arr)
``` | 0 | |
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 | |
962 | A | Equator | PROGRAMMING | 1,300 | [
"implementation"
] | null | null | Polycarp has created his own training plan to prepare for the programming contests. He will train for $n$ days, all days are numbered from $1$ to $n$, beginning from the first.
On the $i$-th day Polycarp will necessarily solve $a_i$ problems. One evening Polycarp plans to celebrate the equator. He will celebrate it on... | The first line contains a single integer $n$ ($1 \le n \le 200\,000$) — the number of days to prepare for the programming contests.
The second line contains a sequence $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10\,000$), where $a_i$ equals to the number of problems, which Polycarp will solve on the $i$-th day. | Print the index of the day when Polycarp will celebrate the equator. | [
"4\n1 3 2 1\n",
"6\n2 2 2 2 2 2\n"
] | [
"2\n",
"3\n"
] | In the first example Polycarp will celebrate the equator on the evening of the second day, because up to this day (inclusive) he will solve $4$ out of $7$ scheduled problems on four days of the training.
In the second example Polycarp will celebrate the equator on the evening of the third day, because up to this day (... | 0 | [
{
"input": "4\n1 3 2 1",
"output": "2"
},
{
"input": "6\n2 2 2 2 2 2",
"output": "3"
},
{
"input": "1\n10000",
"output": "1"
},
{
"input": "3\n2 1 1",
"output": "1"
},
{
"input": "2\n1 3",
"output": "2"
},
{
"input": "4\n2 1 1 3",
"output": "3"
}... | 1,523,485,678 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 93 | 7,475,200 | #Equator .. 962A
from random import choice
n = int(input())
a = input().split()
A = list(map(int,a))
avg = sum(A)//len(A)
if n < 100000:
c = 0
else:
c = n//2 - 500
if avg == choice(A):
print(n//2)
else:
while c < len(A):
if sum(A[0:c]) < sum(A)/2:
c+=1
e... | Title: Equator
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp has created his own training plan to prepare for the programming contests. He will train for $n$ days, all days are numbered from $1$ to $n$, beginning from the first.
On the $i$-th day Polycarp will necessarily solve... | ```python
#Equator .. 962A
from random import choice
n = int(input())
a = input().split()
A = list(map(int,a))
avg = sum(A)//len(A)
if n < 100000:
c = 0
else:
c = n//2 - 500
if avg == choice(A):
print(n//2)
else:
while c < len(A):
if sum(A[0:c]) < sum(A)/2:
c+=1
... | 0 | |
780 | A | Andryusha and Socks | PROGRAMMING | 800 | [
"implementation"
] | null | null | Andryusha is an orderly boy and likes to keep things in their place.
Today he faced a problem to put his socks in the wardrobe. He has *n* distinct pairs of socks which are initially in a bag. The pairs are numbered from 1 to *n*. Andryusha wants to put paired socks together and put them in the wardrobe. He takes the ... | The first line contains the single integer *n* (1<=≤<=*n*<=≤<=105) — the number of sock pairs.
The second line contains 2*n* integers *x*1,<=*x*2,<=...,<=*x*2*n* (1<=≤<=*x**i*<=≤<=*n*), which describe the order in which Andryusha took the socks from the bag. More precisely, *x**i* means that the *i*-th sock Andryusha ... | Print single integer — the maximum number of socks that were on the table at the same time. | [
"1\n1 1\n",
"3\n2 1 1 3 2 3\n"
] | [
"1\n",
"2\n"
] | In the first example Andryusha took a sock from the first pair and put it on the table. Then he took the next sock which is from the first pair as well, so he immediately puts both socks to the wardrobe. Thus, at most one sock was on the table at the same time.
In the second example Andryusha behaved as follows:
- ... | 500 | [
{
"input": "1\n1 1",
"output": "1"
},
{
"input": "3\n2 1 1 3 2 3",
"output": "2"
},
{
"input": "5\n5 1 3 2 4 3 1 2 4 5",
"output": "5"
},
{
"input": "10\n4 2 6 3 4 8 7 1 1 5 2 10 6 8 3 5 10 9 9 7",
"output": "6"
},
{
"input": "50\n30 47 31 38 37 50 36 43 9 23 2 2 ... | 1,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 | |
755 | A | PolandBall and Hypothesis | PROGRAMMING | 800 | [
"brute force",
"graphs",
"math",
"number theory"
] | null | null | PolandBall is a young, clever Ball. He is interested in prime numbers. He has stated a following hypothesis: "There exists such a positive integer *n* that for each positive integer *m* number *n*·*m*<=+<=1 is a prime number".
Unfortunately, PolandBall is not experienced yet and doesn't know that his hypothesis is inc... | The only number in the input is *n* (1<=≤<=*n*<=≤<=1000) — number from the PolandBall's hypothesis. | Output such *m* that *n*·*m*<=+<=1 is not a prime number. Your answer will be considered correct if you output any suitable *m* such that 1<=≤<=*m*<=≤<=103. It is guaranteed the the answer exists. | [
"3\n",
"4\n"
] | [
"1",
"2"
] | A prime number (or a prime) is a natural number greater than 1 that has no positive divisors other than 1 and itself.
For the first sample testcase, 3·1 + 1 = 4. We can output 1.
In the second sample testcase, 4·1 + 1 = 5. We cannot output 1 because 5 is prime. However, *m* = 2 is okay since 4·2 + 1 = 9, which is not... | 500 | [
{
"input": "3",
"output": "1"
},
{
"input": "4",
"output": "2"
},
{
"input": "10",
"output": "2"
},
{
"input": "153",
"output": "1"
},
{
"input": "1000",
"output": "1"
},
{
"input": "1",
"output": "3"
},
{
"input": "2",
"output": "4"
... | 1,627,905,953 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 5 | 93 | 20,172,800 | n = int(input())
ans = 1
if n % 2 == 0:
ans = 2
print(ans) | Title: PolandBall and Hypothesis
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
PolandBall is a young, clever Ball. He is interested in prime numbers. He has stated a following hypothesis: "There exists such a positive integer *n* that for each positive integer *m* number *n*·*m*<=+<=1 is... | ```python
n = int(input())
ans = 1
if n % 2 == 0:
ans = 2
print(ans)
``` | 0 | |
675 | A | Infinite Sequence | PROGRAMMING | 1,100 | [
"math"
] | null | null | Vasya likes everything infinite. Now he is studying the properties of a sequence *s*, such that its first element is equal to *a* (*s*1<==<=*a*), and the difference between any two neighbouring elements is equal to *c* (*s**i*<=-<=*s**i*<=-<=1<==<=*c*). In particular, Vasya wonders if his favourite integer *b* appears ... | The first line of the input contain three integers *a*, *b* and *c* (<=-<=109<=≤<=*a*,<=*b*,<=*c*<=≤<=109) — the first element of the sequence, Vasya's favorite number and the difference between any two neighbouring elements of the sequence, respectively. | If *b* appears in the sequence *s* print "YES" (without quotes), otherwise print "NO" (without quotes). | [
"1 7 3\n",
"10 10 0\n",
"1 -4 5\n",
"0 60 50\n"
] | [
"YES\n",
"YES\n",
"NO\n",
"NO\n"
] | In the first sample, the sequence starts from integers 1, 4, 7, so 7 is its element.
In the second sample, the favorite integer of Vasya is equal to the first element of the sequence.
In the third sample all elements of the sequence are greater than Vasya's favorite integer.
In the fourth sample, the sequence starts... | 500 | [
{
"input": "1 7 3",
"output": "YES"
},
{
"input": "10 10 0",
"output": "YES"
},
{
"input": "1 -4 5",
"output": "NO"
},
{
"input": "0 60 50",
"output": "NO"
},
{
"input": "1 -4 -5",
"output": "YES"
},
{
"input": "0 1 0",
"output": "NO"
},
{
... | 1,523,601,744 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 9 | 1,000 | 7,065,600 | a , b ,c=(map(int ,input().split()))
def inte():
global a
global b
global c
while(True):
if(a==0 and c==0):
break
a=a+c
if(a>=b):
break
if(a==b):
print('YES')
else:
print('NO')
if(a==b):
print('YES')
elif(a<0 an... | Title: Infinite Sequence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya likes everything infinite. Now he is studying the properties of a sequence *s*, such that its first element is equal to *a* (*s*1<==<=*a*), and the difference between any two neighbouring elements is equal to *c... | ```python
a , b ,c=(map(int ,input().split()))
def inte():
global a
global b
global c
while(True):
if(a==0 and c==0):
break
a=a+c
if(a>=b):
break
if(a==b):
print('YES')
else:
print('NO')
if(a==b):
print('YES')
e... | 0 | |
514 | A | Chewbaсca and Number | PROGRAMMING | 1,200 | [
"greedy",
"implementation"
] | null | null | Luke Skywalker gave Chewbacca an integer number *x*. Chewbacca isn't good at numbers but he loves inverting digits in them. Inverting digit *t* means replacing it with digit 9<=-<=*t*.
Help Chewbacca to transform the initial number *x* to the minimum possible positive number by inverting some (possibly, zero) digits.... | The first line contains a single integer *x* (1<=≤<=*x*<=≤<=1018) — the number that Luke Skywalker gave to Chewbacca. | Print the minimum possible positive number that Chewbacca can obtain after inverting some digits. The number shouldn't contain leading zeroes. | [
"27\n",
"4545\n"
] | [
"22\n",
"4444\n"
] | none | 500 | [
{
"input": "27",
"output": "22"
},
{
"input": "4545",
"output": "4444"
},
{
"input": "1",
"output": "1"
},
{
"input": "9",
"output": "9"
},
{
"input": "8772",
"output": "1222"
},
{
"input": "81",
"output": "11"
},
{
"input": "71723447",
... | 1,667,058,761 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 15 | 0 |
num = [int(n) for n in list(input())]
if(num[0]>4):
temp = 9-num[i]
num[i]= str(tem)
for i in range(1,len(num)):
temp = 9-num[i]
if(num[i]>temp):
num[i]= temp
num[i]= str(num[i])
print(''.join(num))
| Title: Chewbaсca and Number
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Luke Skywalker gave Chewbacca an integer number *x*. Chewbacca isn't good at numbers but he loves inverting digits in them. Inverting digit *t* means replacing it with digit 9<=-<=*t*.
Help Chewbacca to transform... | ```python
num = [int(n) for n in list(input())]
if(num[0]>4):
temp = 9-num[i]
num[i]= str(tem)
for i in range(1,len(num)):
temp = 9-num[i]
if(num[i]>temp):
num[i]= temp
num[i]= str(num[i])
print(''.join(num))
``` | -1 | |
461 | A | Appleman and Toastman | PROGRAMMING | 1,200 | [
"greedy",
"sortings"
] | null | null | Appleman and Toastman play a game. Initially Appleman gives one group of *n* numbers to the Toastman, then they start to complete the following tasks:
- Each time Toastman gets a group of numbers, he sums up all the numbers and adds this sum to the score. Then he gives the group to the Appleman. - Each time Appleman... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=3·105). The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=106) — the initial group that is given to Toastman. | Print a single integer — the largest possible score. | [
"3\n3 1 5\n",
"1\n10\n"
] | [
"26\n",
"10\n"
] | Consider the following situation in the first example. Initially Toastman gets group [3, 1, 5] and adds 9 to the score, then he give the group to Appleman. Appleman splits group [3, 1, 5] into two groups: [3, 5] and [1]. Both of them should be given to Toastman. When Toastman receives group [1], he adds 1 to score and ... | 500 | [
{
"input": "3\n3 1 5",
"output": "26"
},
{
"input": "1\n10",
"output": "10"
},
{
"input": "10\n8 10 2 5 6 2 4 7 2 1",
"output": "376"
},
{
"input": "10\n171308 397870 724672 431255 228496 892002 542924 718337 888642 161821",
"output": "40204082"
},
{
"input": "10\... | 1,409,096,554 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 |
>>> def a () :
h=3
sums=0
c,b=0,0
h=input()
num=list(h)
minum=int(num[0])
lenth=len(num)
while c<len(num):
if num[c]==' ':
del(num[c])
c=c+1
c=0
while num!=[]:
while c<len(num):
v=int(num[c])
... | Title: Appleman and Toastman
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Appleman and Toastman play a game. Initially Appleman gives one group of *n* numbers to the Toastman, then they start to complete the following tasks:
- Each time Toastman gets a group of numbers, he sums up all... | ```python
>>> def a () :
h=3
sums=0
c,b=0,0
h=input()
num=list(h)
minum=int(num[0])
lenth=len(num)
while c<len(num):
if num[c]==' ':
del(num[c])
c=c+1
c=0
while num!=[]:
while c<len(num):
v=int(num[c])... | -1 | |
923 | B | Producing Snow | PROGRAMMING | 1,600 | [
"binary search",
"data structures"
] | null | null | Alice likes snow a lot! Unfortunately, this year's winter is already over, and she can't expect to have any more of it. Bob has thus bought her a gift — a large snow maker. He plans to make some amount of snow every day. On day *i* he will make a pile of snow of volume *V**i* and put it in her garden.
Each day, every ... | The first line contains a single integer *N* (1<=≤<=*N*<=≤<=105) — the number of days.
The second line contains *N* integers *V*1,<=*V*2,<=...,<=*V**N* (0<=≤<=*V**i*<=≤<=109), where *V**i* is the initial size of a snow pile made on the day *i*.
The third line contains *N* integers *T*1,<=*T*2,<=...,<=*T**N* (0<=≤<=*... | Output a single line with *N* integers, where the *i*-th integer represents the total volume of snow melted on day *i*. | [
"3\n10 10 5\n5 7 2\n",
"5\n30 25 20 15 10\n9 10 12 4 13\n"
] | [
"5 12 4\n",
"9 20 35 11 25\n"
] | In the first sample, Bob first makes a snow pile of volume 10, which melts to the size of 5 on the same day. On the second day, he makes another pile of size 10. Since it is a bit warmer than the day before, the first pile disappears completely while the second pile shrinks to 3. At the end of the second day, he has on... | 1,000 | [
{
"input": "3\n10 10 5\n5 7 2",
"output": "5 12 4"
},
{
"input": "5\n30 25 20 15 10\n9 10 12 4 13",
"output": "9 20 35 11 25"
},
{
"input": "4\n0 0 0 0\n1 2 3 4",
"output": "0 0 0 0"
},
{
"input": "10\n11 39 16 34 25 3 12 11 31 16\n10 0 4 9 8 9 7 8 9 2",
"output": "10 0 9... | 1,520,702,393 | 6,292 | Python 3 | TIME_LIMIT_EXCEEDED | PRETESTS | 3 | 1,000 | 17,920,000 | from heapq import *
def read_line_of_numbers():
return map(int, input().split())
class Node:
def __init__(self, val, i):
self.val = val
self.i = i
def __lt__(self, other):
if self.val == other.val:
return self.i > other.i
else:
ret... | Title: Producing Snow
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Alice likes snow a lot! Unfortunately, this year's winter is already over, and she can't expect to have any more of it. Bob has thus bought her a gift — a large snow maker. He plans to make some amount of snow every day.... | ```python
from heapq import *
def read_line_of_numbers():
return map(int, input().split())
class Node:
def __init__(self, val, i):
self.val = val
self.i = i
def __lt__(self, other):
if self.val == other.val:
return self.i > other.i
else:
... | 0 | |
712 | C | Memory and De-Evolution | PROGRAMMING | 1,600 | [
"greedy",
"math"
] | null | null | Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length *x*, and he wishes to perform operations to obtain an equilateral triangle of side length *y*.
In a single second, he can modify the length of a single side of the current triangle suc... | The first and only line contains two integers *x* and *y* (3<=≤<=*y*<=<<=*x*<=≤<=100<=000) — the starting and ending equilateral triangle side lengths respectively. | Print a single integer — the minimum number of seconds required for Memory to obtain the equilateral triangle of side length *y* if he starts with the equilateral triangle of side length *x*. | [
"6 3\n",
"8 5\n",
"22 4\n"
] | [
"4\n",
"3\n",
"6\n"
] | In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides *a*, *b*, and *c* as (*a*, *b*, *c*). Then, Memory can do <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/18af21f738bad490df83097a90e1f2879a4b21... | 1,500 | [
{
"input": "6 3",
"output": "4"
},
{
"input": "8 5",
"output": "3"
},
{
"input": "22 4",
"output": "6"
},
{
"input": "4 3",
"output": "3"
},
{
"input": "57 27",
"output": "4"
},
{
"input": "61 3",
"output": "9"
},
{
"input": "5 4",
"out... | 1,473,528,600 | 2,700 | Python 3 | TIME_LIMIT_EXCEEDED | PRETESTS | 0 | 2,000 | 0 | ds = [i for i in range(1,1001)]
t = 1
while True:
tt = t*t
if(tt>1000):
break
ds.remove(tt)
t += 1
import math
def check(x,d):
y = int(math.sqrt(((x**2-1)/d)))-1
for i in range(3):
if(y+i>0):
if(x**2-d*((y+i)**2)==1):
return 1
retu... | Title: Memory and De-Evolution
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length *x*, and he wishes to perform operations to obtain an equilateral triangle o... | ```python
ds = [i for i in range(1,1001)]
t = 1
while True:
tt = t*t
if(tt>1000):
break
ds.remove(tt)
t += 1
import math
def check(x,d):
y = int(math.sqrt(((x**2-1)/d)))-1
for i in range(3):
if(y+i>0):
if(x**2-d*((y+i)**2)==1):
return 1... | 0 | |
133 | A | HQ9+ | PROGRAMMING | 900 | [
"implementation"
] | null | null | HQ9+ is a joke programming language which has only four one-character instructions:
- "H" prints "Hello, World!",- "Q" prints the source code of the program itself,- "9" prints the lyrics of "99 Bottles of Beer" song, - "+" increments the value stored in the internal accumulator.
Instructions "H" and "Q" are case-s... | The input will consist of a single line *p* which will give a program in HQ9+. String *p* will contain between 1 and 100 characters, inclusive. ASCII-code of each character of *p* will be between 33 (exclamation mark) and 126 (tilde), inclusive. | Output "YES", if executing the program will produce any output, and "NO" otherwise. | [
"Hi!\n",
"Codeforces\n"
] | [
"YES\n",
"NO\n"
] | In the first case the program contains only one instruction — "H", which prints "Hello, World!".
In the second case none of the program characters are language instructions. | 500 | [
{
"input": "Hi!",
"output": "YES"
},
{
"input": "Codeforces",
"output": "NO"
},
{
"input": "a+b=c",
"output": "NO"
},
{
"input": "hq-lowercase",
"output": "NO"
},
{
"input": "Q",
"output": "YES"
},
{
"input": "9",
"output": "YES"
},
{
"inpu... | 1,690,279,641 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 60 | 0 | a=int(input())
while(a!=0):
s=str(input())
val=0
for i in range(len(s)):
if(s[i]=="H" or s[i]=="+" or s[i]=="9" or s[i]=="Q"):
val=1
if(val==1):
print("YES")
else:
print("NO")
a=a-1; | Title: HQ9+
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
HQ9+ is a joke programming language which has only four one-character instructions:
- "H" prints "Hello, World!",- "Q" prints the source code of the program itself,- "9" prints the lyrics of "99 Bottles of Beer" song, - "+" in... | ```python
a=int(input())
while(a!=0):
s=str(input())
val=0
for i in range(len(s)):
if(s[i]=="H" or s[i]=="+" or s[i]=="9" or s[i]=="Q"):
val=1
if(val==1):
print("YES")
else:
print("NO")
a=a-1;
``` | -1 | |
3 | C | Tic-tac-toe | PROGRAMMING | 1,800 | [
"brute force",
"games",
"implementation"
] | C. Tic-tac-toe | 1 | 64 | Certainly, everyone is familiar with tic-tac-toe game. The rules are very simple indeed. Two players take turns marking the cells in a 3<=×<=3 grid (one player always draws crosses, the other — noughts). The player who succeeds first in placing three of his marks in a horizontal, vertical or diagonal line wins, and the... | The input consists of three lines, each of the lines contains characters ".", "X" or "0" (a period, a capital letter X, or a digit zero). | Print one of the six verdicts: first, second, illegal, the first player won, the second player won or draw. | [
"X0X\n.0.\n.X.\n"
] | [
"second\n"
] | none | 0 | [
{
"input": "X0X\n.0.\n.X.",
"output": "second"
},
{
"input": "0.X\nXX.\n000",
"output": "illegal"
},
{
"input": "XXX\n.0.\n000",
"output": "illegal"
},
{
"input": "XXX\n...\n000",
"output": "illegal"
},
{
"input": "X.X\nX..\n00.",
"output": "second"
},
{
... | 1,641,916,873 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 62 | 0 | win_positions = [
[1, 2, 3],
[4, 5, 6],
[7, 8, 9],
[1, 4, 7],
[2, 5, 8],
[3, 6, 9],
[1, 5, 9],
[3, 5, 7],
]
def check_winner(__board):
for i in win_positions:
count = 0
temp = ""
for j in i:
if temp != "":
if (
... | Title: Tic-tac-toe
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
Certainly, everyone is familiar with tic-tac-toe game. The rules are very simple indeed. Two players take turns marking the cells in a 3<=×<=3 grid (one player always draws crosses, the other — noughts). The player who succeeds ... | ```python
win_positions = [
[1, 2, 3],
[4, 5, 6],
[7, 8, 9],
[1, 4, 7],
[2, 5, 8],
[3, 6, 9],
[1, 5, 9],
[3, 5, 7],
]
def check_winner(__board):
for i in win_positions:
count = 0
temp = ""
for j in i:
if temp != "":
... | 0 |
677 | A | Vanya and Fence | PROGRAMMING | 800 | [
"implementation"
] | null | null | Vanya and his friends are walking along the fence of height *h* and they do not want the guard to notice them. In order to achieve this the height of each of the friends should not exceed *h*. If the height of some person is greater than *h* he can bend down and then he surely won't be noticed by the guard. The height ... | The first line of the input contains two integers *n* and *h* (1<=≤<=*n*<=≤<=1000, 1<=≤<=*h*<=≤<=1000) — the number of friends and the height of the fence, respectively.
The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=2*h*), the *i*-th of them is equal to the height of the *i*-th person. | Print a single integer — the minimum possible valid width of the road. | [
"3 7\n4 5 14\n",
"6 1\n1 1 1 1 1 1\n",
"6 5\n7 6 8 9 10 5\n"
] | [
"4\n",
"6\n",
"11\n"
] | In the first sample, only person number 3 must bend down, so the required width is equal to 1 + 1 + 2 = 4.
In the second sample, all friends are short enough and no one has to bend, so the width 1 + 1 + 1 + 1 + 1 + 1 = 6 is enough.
In the third sample, all the persons have to bend, except the last one. The required m... | 500 | [
{
"input": "3 7\n4 5 14",
"output": "4"
},
{
"input": "6 1\n1 1 1 1 1 1",
"output": "6"
},
{
"input": "6 5\n7 6 8 9 10 5",
"output": "11"
},
{
"input": "10 420\n214 614 297 675 82 740 174 23 255 15",
"output": "13"
},
{
"input": "10 561\n657 23 1096 487 785 66 481... | 1,694,018,470 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 15 | 0 | a,b = input().split()
a = int(a)
b = int(b)
l = 0
for i in range(a):
n = input()
if(n>=b):
l+=2
else:
l+=1
print(l)
| Title: Vanya and Fence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vanya and his friends are walking along the fence of height *h* and they do not want the guard to notice them. In order to achieve this the height of each of the friends should not exceed *h*. If the height of some pers... | ```python
a,b = input().split()
a = int(a)
b = int(b)
l = 0
for i in range(a):
n = input()
if(n>=b):
l+=2
else:
l+=1
print(l)
``` | -1 | |
340 | B | Maximal Area Quadrilateral | PROGRAMMING | 2,100 | [
"brute force",
"geometry"
] | null | null | Iahub has drawn a set of *n* points in the cartesian plane which he calls "special points". A quadrilateral is a simple polygon without self-intersections with four sides (also called edges) and four vertices (also called corners). Please note that a quadrilateral doesn't have to be convex. A special quadrilateral is o... | The first line contains integer *n* (4<=≤<=*n*<=≤<=300). Each of the next *n* lines contains two integers: *x**i*, *y**i* (<=-<=1000<=≤<=*x**i*,<=*y**i*<=≤<=1000) — the cartesian coordinates of *i*th special point. It is guaranteed that no three points are on the same line. It is guaranteed that no two points coincide. | Output a single real number — the maximal area of a special quadrilateral. The answer will be considered correct if its absolute or relative error does't exceed 10<=-<=9. | [
"5\n0 0\n0 4\n4 0\n4 4\n2 3\n"
] | [
"16.000000"
] | In the test example we can choose first 4 points to be the vertices of the quadrilateral. They form a square by side 4, so the area is 4·4 = 16. | 3,000 | [
{
"input": "5\n0 0\n0 4\n4 0\n4 4\n2 3",
"output": "16.000000"
},
{
"input": "10\n-6 -4\n-7 5\n-7 -7\n5 -7\n4 -9\n-6 7\n2 9\n-4 -6\n2 10\n-10 -4",
"output": "166.000000"
},
{
"input": "4\n-3 3\n0 3\n-2 -1\n2 2",
"output": "11.000000"
},
{
"input": "5\n-4 -3\n-3 -2\n3 3\n-1 2\... | 1,379,601,917 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 62 | 0 | file = open('input.txt');
def square(p1, p2, p3):
return ((p2[0] - p1[0]) * (p3[1] - p1[0]) - (p2[1] - p1[0]) * (p3[0] - p1[0]))
count_points = int(file.readline())
points = []
for x in range(count_points):
points.append([int(x) for x in input().split()])
file.close()
max_square = -1
for p1 ... | Title: Maximal Area Quadrilateral
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Iahub has drawn a set of *n* points in the cartesian plane which he calls "special points". A quadrilateral is a simple polygon without self-intersections with four sides (also called edges) and four vertices... | ```python
file = open('input.txt');
def square(p1, p2, p3):
return ((p2[0] - p1[0]) * (p3[1] - p1[0]) - (p2[1] - p1[0]) * (p3[0] - p1[0]))
count_points = int(file.readline())
points = []
for x in range(count_points):
points.append([int(x) for x in input().split()])
file.close()
max_square = -1
... | -1 | |
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 | |
741 | A | Arpa's loud Owf and Mehrdad's evil plan | PROGRAMMING | 1,600 | [
"dfs and similar",
"math"
] | null | null | As you have noticed, there are lovely girls in Arpa’s land.
People in Arpa's land are numbered from 1 to *n*. Everyone has exactly one crush, *i*-th person's crush is person with the number *crush**i*.
Someday Arpa shouted Owf loudly from the top of the palace and a funny game started in Arpa's land. The rules are as... | The first line of input contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of people in Arpa's land.
The second line contains *n* integers, *i*-th of them is *crush**i* (1<=≤<=*crush**i*<=≤<=*n*) — the number of *i*-th person's crush. | If there is no *t* satisfying the condition, print -1. Otherwise print such smallest *t*. | [
"4\n2 3 1 4\n",
"4\n4 4 4 4\n",
"4\n2 1 4 3\n"
] | [
"3\n",
"-1\n",
"1\n"
] | In the first sample suppose *t* = 3.
If the first person starts some round:
The first person calls the second person and says "Owwwf", then the second person calls the third person and says "Owwf", then the third person calls the first person and says "Owf", so the first person becomes Joon-Joon of the round. So the... | 500 | [
{
"input": "4\n2 3 1 4",
"output": "3"
},
{
"input": "4\n4 4 4 4",
"output": "-1"
},
{
"input": "4\n2 1 4 3",
"output": "1"
},
{
"input": "5\n2 4 3 1 2",
"output": "-1"
},
{
"input": "5\n2 2 4 4 5",
"output": "-1"
},
{
"input": "5\n2 4 5 4 2",
"out... | 1,620,740,118 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 1 | 1,000 | 21,401,600 | from math import gcd
def lcm(a,b):
return a*b//gcd(a,b)
n=int(input())
c=[0]+list(map(int,input().split()))
g=[[] for i in range(n+1)]
use=set()
for i in range(1,n+1):
g[c[i]].append(i)
use.add(c[i])
if len(use)!=n:
print(-1)
s=[]
for i in range(1,n+1):
p=c[i]
l=1
while p!=i:
p=c[p]
... | Title: Arpa's loud Owf and Mehrdad's evil plan
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
As you have noticed, there are lovely girls in Arpa’s land.
People in Arpa's land are numbered from 1 to *n*. Everyone has exactly one crush, *i*-th person's crush is person with the number *cru... | ```python
from math import gcd
def lcm(a,b):
return a*b//gcd(a,b)
n=int(input())
c=[0]+list(map(int,input().split()))
g=[[] for i in range(n+1)]
use=set()
for i in range(1,n+1):
g[c[i]].append(i)
use.add(c[i])
if len(use)!=n:
print(-1)
s=[]
for i in range(1,n+1):
p=c[i]
l=1
while p!=i:
... | 0 | |
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 | |
615 | A | Bulbs | PROGRAMMING | 800 | [
"implementation"
] | null | null | Vasya wants to turn on Christmas lights consisting of *m* bulbs. Initially, all bulbs are turned off. There are *n* buttons, each of them is connected to some set of bulbs. Vasya can press any of these buttons. When the button is pressed, it turns on all the bulbs it's connected to. Can Vasya light up all the bulbs?
I... | The first line of the input contains integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of buttons and the number of bulbs respectively.
Each of the next *n* lines contains *x**i* (0<=≤<=*x**i*<=≤<=*m*) — the number of bulbs that are turned on by the *i*-th button, and then *x**i* numbers *y**ij* (1<=≤<=*y**... | If it's possible to turn on all *m* bulbs print "YES", otherwise print "NO". | [
"3 4\n2 1 4\n3 1 3 1\n1 2\n",
"3 3\n1 1\n1 2\n1 1\n"
] | [
"YES\n",
"NO\n"
] | In the first sample you can press each button once and turn on all the bulbs. In the 2 sample it is impossible to turn on the 3-rd lamp. | 500 | [
{
"input": "3 4\n2 1 4\n3 1 3 1\n1 2",
"output": "YES"
},
{
"input": "3 3\n1 1\n1 2\n1 1",
"output": "NO"
},
{
"input": "3 4\n1 1\n1 2\n1 3",
"output": "NO"
},
{
"input": "1 5\n5 1 2 3 4 5",
"output": "YES"
},
{
"input": "1 5\n5 4 4 1 2 3",
"output": "NO"
},... | 1,676,818,810 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 30 | 0 | a,b=map(int,input().split())
x=[]
cal=[]
for i in range(a):
c=list(map(int,input().split()))
for i in range(len(c)):
if c[i] not in x:
x.append(c[i])
x.sort()
for i in range(1,b+1):
cal.append(i)
if x==cal:
print("YES")
else:
print("NO")
| Title: Bulbs
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya wants to turn on Christmas lights consisting of *m* bulbs. Initially, all bulbs are turned off. There are *n* buttons, each of them is connected to some set of bulbs. Vasya can press any of these buttons. When the button is... | ```python
a,b=map(int,input().split())
x=[]
cal=[]
for i in range(a):
c=list(map(int,input().split()))
for i in range(len(c)):
if c[i] not in x:
x.append(c[i])
x.sort()
for i in range(1,b+1):
cal.append(i)
if x==cal:
print("YES")
else:
print("NO")
``... | 0 | |
814 | A | An abandoned sentiment from past | PROGRAMMING | 900 | [
"constructive algorithms",
"greedy",
"implementation",
"sortings"
] | null | null | A few years ago, Hitagi encountered a giant crab, who stole the whole of her body weight. Ever since, she tried to avoid contact with others, for fear that this secret might be noticed.
To get rid of the oddity and recover her weight, a special integer sequence is needed. Hitagi's sequence has been broken for a long t... | The first line of input contains two space-separated positive integers *n* (2<=≤<=*n*<=≤<=100) and *k* (1<=≤<=*k*<=≤<=*n*) — the lengths of sequence *a* and *b* respectively.
The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=200) — Hitagi's broken sequence with exactly ... | Output "Yes" if it's possible to replace zeros in *a* with elements in *b* and make the resulting sequence not increasing, and "No" otherwise. | [
"4 2\n11 0 0 14\n5 4\n",
"6 1\n2 3 0 8 9 10\n5\n",
"4 1\n8 94 0 4\n89\n",
"7 7\n0 0 0 0 0 0 0\n1 2 3 4 5 6 7\n"
] | [
"Yes\n",
"No\n",
"Yes\n",
"Yes\n"
] | In the first sample:
- Sequence *a* is 11, 0, 0, 14. - Two of the elements are lost, and the candidates in *b* are 5 and 4. - There are two possible resulting sequences: 11, 5, 4, 14 and 11, 4, 5, 14, both of which fulfill the requirements. Thus the answer is "Yes".
In the second sample, the only possible resulti... | 500 | [
{
"input": "4 2\n11 0 0 14\n5 4",
"output": "Yes"
},
{
"input": "6 1\n2 3 0 8 9 10\n5",
"output": "No"
},
{
"input": "4 1\n8 94 0 4\n89",
"output": "Yes"
},
{
"input": "7 7\n0 0 0 0 0 0 0\n1 2 3 4 5 6 7",
"output": "Yes"
},
{
"input": "40 1\n23 26 27 28 31 35 38 4... | 1,522,598,529 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 12 | 78 | 7,065,600 | n,k = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = 1
j = 0
for i in range(n-1):
if a[i] > a[i+1] and a[i+1] != 0:
c = 0
if a[i]==0:
j = i
if k == 1 and c == 1 and b[0] > a[j-1] :
print("No")
else:
print("Yes") | Title: An abandoned sentiment from past
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A few years ago, Hitagi encountered a giant crab, who stole the whole of her body weight. Ever since, she tried to avoid contact with others, for fear that this secret might be noticed.
To get rid of t... | ```python
n,k = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = 1
j = 0
for i in range(n-1):
if a[i] > a[i+1] and a[i+1] != 0:
c = 0
if a[i]==0:
j = i
if k == 1 and c == 1 and b[0] > a[j-1] :
print("No")
else:
print("Yes")
`... | 0 | |
689 | C | Mike and Chocolate Thieves | PROGRAMMING | 1,700 | [
"binary search",
"combinatorics",
"math"
] | null | null | Bad news came to Mike's village, some thieves stole a bunch of chocolates from the local factory! Horrible!
Aside from loving sweet things, thieves from this area are known to be very greedy. So after a thief takes his number of chocolates for himself, the next thief will take exactly *k* times more than the previous... | The single line of input contains the integer *m* (1<=≤<=*m*<=≤<=1015) — the number of ways the thieves might steal the chocolates, as rumours say. | Print the only integer *n* — the maximum amount of chocolates that thieves' bags can carry. If there are more than one *n* satisfying the rumors, print the smallest one.
If there is no such *n* for a false-rumoured *m*, print <=-<=1. | [
"1\n",
"8\n",
"10\n"
] | [
"8\n",
"54\n",
"-1\n"
] | In the first sample case the smallest *n* that leads to exactly one way of stealing chocolates is *n* = 8, whereas the amounts of stealed chocolates are (1, 2, 4, 8) (the number of chocolates stolen by each of the thieves).
In the second sample case the smallest *n* that leads to exactly 8 ways is *n* = 54 with the po... | 1,500 | [
{
"input": "1",
"output": "8"
},
{
"input": "8",
"output": "54"
},
{
"input": "10",
"output": "-1"
},
{
"input": "27",
"output": "152"
},
{
"input": "28206",
"output": "139840"
},
{
"input": "32",
"output": "184"
},
{
"input": "115",
"o... | 1,667,537,907 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 0 | 2,000 | 0 | def f(n):
ret=0
for k in range(2,n+1):
if k*k*k<=n+1:
ret+=(n//(k*k*k))
return ret
m=int(input())
lo=0
hi=10**18
ans=-1
while(lo<=hi):
mid=lo+(hi-lo)//2
ret=f(mid)
if ret==m:
ans=mid
if ret>=m:
hi=mid-1
else:
lo=mid+1
print(a... | Title: Mike and Chocolate Thieves
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bad news came to Mike's village, some thieves stole a bunch of chocolates from the local factory! Horrible!
Aside from loving sweet things, thieves from this area are known to be very greedy. So after a thi... | ```python
def f(n):
ret=0
for k in range(2,n+1):
if k*k*k<=n+1:
ret+=(n//(k*k*k))
return ret
m=int(input())
lo=0
hi=10**18
ans=-1
while(lo<=hi):
mid=lo+(hi-lo)//2
ret=f(mid)
if ret==m:
ans=mid
if ret>=m:
hi=mid-1
else:
lo=mid+... | 0 | |
401 | C | Team | PROGRAMMING | 1,400 | [
"constructive algorithms",
"greedy",
"implementation"
] | null | null | Now it's time of Olympiads. Vanya and Egor decided to make his own team to take part in a programming Olympiad. They've been best friends ever since primary school and hopefully, that can somehow help them in teamwork.
For each team Olympiad, Vanya takes his play cards with numbers. He takes only the cards containing ... | The first line contains two integers: *n* (1<=≤<=*n*<=≤<=106) — the number of cards containing number 0; *m* (1<=≤<=*m*<=≤<=106) — the number of cards containing number 1. | In a single line print the required sequence of zeroes and ones without any spaces. If such sequence is impossible to obtain, print -1. | [
"1 2\n",
"4 8\n",
"4 10\n",
"1 5\n"
] | [
"101\n",
"110110110101\n",
"11011011011011\n",
"-1\n"
] | none | 1,500 | [
{
"input": "1 2",
"output": "101"
},
{
"input": "4 8",
"output": "110110110101"
},
{
"input": "4 10",
"output": "11011011011011"
},
{
"input": "1 5",
"output": "-1"
},
{
"input": "3 4",
"output": "1010101"
},
{
"input": "3 10",
"output": "-1"
},
... | 1,639,403,065 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 31 | 0 | n,m=map(int,input().split())
if m>2*n+2 or m<2 or n>m:
print(-1)
else:
if m<=2*n:
print('110'*(m-n)+'10'*(2*n-m))
else:
print('110'*(m-n-1)+'11') | Title: Team
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Now it's time of Olympiads. Vanya and Egor decided to make his own team to take part in a programming Olympiad. They've been best friends ever since primary school and hopefully, that can somehow help them in teamwork.
For each t... | ```python
n,m=map(int,input().split())
if m>2*n+2 or m<2 or n>m:
print(-1)
else:
if m<=2*n:
print('110'*(m-n)+'10'*(2*n-m))
else:
print('110'*(m-n-1)+'11')
``` | 0 | |
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 | |
50 | E | Square Equation Roots | PROGRAMMING | 2,300 | [
"math"
] | E. Square Equation Roots | 5 | 256 | A schoolboy Petya studies square equations. The equations that are included in the school curriculum, usually look simple:
Petya noticed that some equations have two real roots, some of them have only one root and some equations don't have real roots at all. Moreover it turned out that several different square equati... | The single line contains two integers *n* and *m*. (1<=≤<=*n*,<=*m*<=≤<=5000000). | Print a single number which is the number of real roots of the described set of equations. | [
"3 3\n",
"1 2\n"
] | [
"12\n",
"1\n"
] | In the second test from the statement the following equations are analysed:
*b* = 1, *c* = 1: *x*<sup class="upper-index">2</sup> + 2*x* + 1 = 0; The root is *x* = - 1
*b* = 1, *c* = 2: *x*<sup class="upper-index">2</sup> + 2*x* + 2 = 0; No roots
Overall there's one root
In the second test the following equatio... | 2,500 | [] | 1,611,069,404 | 2,147,483,647 | PyPy 3 | MEMORY_LIMIT_EXCEEDED | TESTS | 22 | 4,086 | 268,390,400 | from math import sqrt
if __name__ == "__main__":
n, m = map(int,input().strip().split())
b = 1
s = set()
while b <= n:
first_part = -b
second_part = b ** 2 - 1
count = 0
while second_part >= 0 and count < m:
s.add(first_part + sqrt(second_part))
s.... | Title: Square Equation Roots
Time Limit: 5 seconds
Memory Limit: 256 megabytes
Problem Description:
A schoolboy Petya studies square equations. The equations that are included in the school curriculum, usually look simple:
Petya noticed that some equations have two real roots, some of them have only one root and s... | ```python
from math import sqrt
if __name__ == "__main__":
n, m = map(int,input().strip().split())
b = 1
s = set()
while b <= n:
first_part = -b
second_part = b ** 2 - 1
count = 0
while second_part >= 0 and count < m:
s.add(first_part + sqrt(second_part))
... | 0 |
980 | A | Links and Pearls | PROGRAMMING | 900 | [
"implementation",
"math"
] | null | null | A necklace can be described as a string of links ('-') and pearls ('o'), with the last link or pearl connected to the first one.
You can remove a link or a pearl and insert it between two other existing links or pearls (or between a link and a pearl) on the necklace. This process can be repeated as many times as you l... | The only line of input contains a string $s$ ($3 \leq |s| \leq 100$), representing the necklace, where a dash '-' represents a link and the lowercase English letter 'o' represents a pearl. | Print "YES" if the links and pearls can be rejoined such that the number of links between adjacent pearls is equal. Otherwise print "NO".
You can print each letter in any case (upper or lower). | [
"-o-o--",
"-o---\n",
"-o---o-\n",
"ooo\n"
] | [
"YES",
"YES",
"NO",
"YES\n"
] | none | 500 | [
{
"input": "-o-o--",
"output": "YES"
},
{
"input": "-o---",
"output": "YES"
},
{
"input": "-o---o-",
"output": "NO"
},
{
"input": "ooo",
"output": "YES"
},
{
"input": "---",
"output": "YES"
},
{
"input": "--o-o-----o----o--oo-o-----ooo-oo---o--",
"... | 1,637,161,122 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 7 | 31 | 0 | #!/usr/bin/env python
# coding=utf-8
'''
Author: Deean
Date: 2021-11-17 22:55:41
LastEditTime: 2021-11-17 22:57:36
Description: Links and Pearls
FilePath: CF980A.py
'''
def func():
s = input().strip()
if s.count("o") == 0 or s.count("-") == 0:
print("YES")
elif s.count("-") % 2 == 0:
print... | Title: Links and Pearls
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A necklace can be described as a string of links ('-') and pearls ('o'), with the last link or pearl connected to the first one.
You can remove a link or a pearl and insert it between two other existing links or pearl... | ```python
#!/usr/bin/env python
# coding=utf-8
'''
Author: Deean
Date: 2021-11-17 22:55:41
LastEditTime: 2021-11-17 22:57:36
Description: Links and Pearls
FilePath: CF980A.py
'''
def func():
s = input().strip()
if s.count("o") == 0 or s.count("-") == 0:
print("YES")
elif s.count("-") % 2 == 0:
... | 0 | |
845 | A | Chess Tourney | PROGRAMMING | 1,100 | [
"implementation",
"sortings"
] | null | null | Berland annual chess tournament is coming!
Organizers have gathered 2·*n* chess players who should be divided into two teams with *n* people each. The first team is sponsored by BerOil and the second team is sponsored by BerMobile. Obviously, organizers should guarantee the win for the team of BerOil.
Thus, organizer... | The first line contains one integer *n* (1<=≤<=*n*<=≤<=100).
The second line contains 2·*n* integers *a*1,<=*a*2,<=... *a*2*n* (1<=≤<=*a**i*<=≤<=1000). | If it's possible to divide all 2·*n* players into two teams with *n* people each so that the player from the first team in every pair wins regardless of the results of the drawing, then print "YES". Otherwise print "NO". | [
"2\n1 3 2 4\n",
"1\n3 3\n"
] | [
"YES\n",
"NO\n"
] | none | 0 | [
{
"input": "2\n1 3 2 4",
"output": "YES"
},
{
"input": "1\n3 3",
"output": "NO"
},
{
"input": "5\n1 1 1 1 2 2 3 3 3 3",
"output": "NO"
},
{
"input": "5\n1 1 1 1 1 2 2 2 2 2",
"output": "YES"
},
{
"input": "10\n1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000... | 1,503,330,032 | 2,132 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 30 | 0 | answer = True
Drawings= []
numTeamPlayers = int(input())
for number in range(0 , numTeamPlayers * 2):
Drawings.append(int(input()))
for item in range(0, numTeamPlayers):
if item != 0:
item = item +1
if Drawings[item] >= Drawings[item + 1]:
answer = False and answer
else:
answer = True and answer
... | Title: Chess Tourney
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Berland annual chess tournament is coming!
Organizers have gathered 2·*n* chess players who should be divided into two teams with *n* people each. The first team is sponsored by BerOil and the second team is sponsored by... | ```python
answer = True
Drawings= []
numTeamPlayers = int(input())
for number in range(0 , numTeamPlayers * 2):
Drawings.append(int(input()))
for item in range(0, numTeamPlayers):
if item != 0:
item = item +1
if Drawings[item] >= Drawings[item + 1]:
answer = False and answer
else:
answer = True a... | -1 | |
712 | A | Memory and Crow | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | There are *n* integers *b*1,<=*b*2,<=...,<=*b**n* written in a row. For all *i* from 1 to *n*, values *a**i* are defined by the crows performing the following procedure:
- The crow sets *a**i* initially 0. - The crow then adds *b**i* to *a**i*, subtracts *b**i*<=+<=1, adds the *b**i*<=+<=2 number, and so on until th... | The first line of the input contains a single integer *n* (2<=≤<=*n*<=≤<=100<=000) — the number of integers written in the row.
The next line contains *n*, the *i*'th of which is *a**i* (<=-<=109<=≤<=*a**i*<=≤<=109) — the value of the *i*'th number. | Print *n* integers corresponding to the sequence *b*1,<=*b*2,<=...,<=*b**n*. It's guaranteed that the answer is unique and fits in 32-bit integer type. | [
"5\n6 -4 8 -2 3\n",
"5\n3 -2 -1 5 6\n"
] | [
"2 4 6 1 3 \n",
"1 -3 4 11 6 \n"
] | In the first sample test, the crows report the numbers 6, - 4, 8, - 2, and 3 when he starts at indices 1, 2, 3, 4 and 5 respectively. It is easy to check that the sequence 2 4 6 1 3 satisfies the reports. For example, 6 = 2 - 4 + 6 - 1 + 3, and - 4 = 4 - 6 + 1 - 3.
In the second sample test, the sequence 1, - 3, 4, ... | 500 | [
{
"input": "5\n6 -4 8 -2 3",
"output": "2 4 6 1 3 "
},
{
"input": "5\n3 -2 -1 5 6",
"output": "1 -3 4 11 6 "
},
{
"input": "10\n13 -2 532 -63 -23 -63 -64 -23 12 10",
"output": "11 530 469 -86 -86 -127 -87 -11 22 10 "
},
{
"input": "10\n0 0 0 0 0 0 0 0 0 0",
"output": "0 0... | 1,583,728,001 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 4 | 2,000 | 10,752,000 | x=int(input());a=list(map(int,input().split()));n=[a[-1]]
for i in range(1,x):
p=0
n.append(a[-(i)-1])
while 1==1:
p+=1
n[-1]=n[-1]+n[i-p]
if p==i:break
p+=1
n[-1]=n[-1]-n[i-p]
if p==i:break
print(*n[::-1])
| Title: Memory and Crow
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* integers *b*1,<=*b*2,<=...,<=*b**n* written in a row. For all *i* from 1 to *n*, values *a**i* are defined by the crows performing the following procedure:
- The crow sets *a**i* initially 0. - The crow... | ```python
x=int(input());a=list(map(int,input().split()));n=[a[-1]]
for i in range(1,x):
p=0
n.append(a[-(i)-1])
while 1==1:
p+=1
n[-1]=n[-1]+n[i-p]
if p==i:break
p+=1
n[-1]=n[-1]-n[i-p]
if p==i:break
print(*n[::-1])
``` | 0 | |
1 | A | Theatre Square | PROGRAMMING | 1,000 | [
"math"
] | A. Theatre Square | 1 | 256 | Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size *a*<=×<=*a*.
What is the least number of flagstones needed to pave the... | The input contains three positive integer numbers in the first line: *n*,<=<=*m* and *a* (1<=≤<=<=*n*,<=*m*,<=*a*<=≤<=109). | Write the needed number of flagstones. | [
"6 6 4\n"
] | [
"4\n"
] | none | 0 | [
{
"input": "6 6 4",
"output": "4"
},
{
"input": "1 1 1",
"output": "1"
},
{
"input": "2 1 1",
"output": "2"
},
{
"input": "1 2 1",
"output": "2"
},
{
"input": "2 2 1",
"output": "4"
},
{
"input": "2 1 2",
"output": "1"
},
{
"input": "1 1 3"... | 1,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 |
131 | A | cAPS lOCK | PROGRAMMING | 1,000 | [
"implementation",
"strings"
] | null | null | wHAT DO WE NEED cAPS LOCK FOR?
Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in the first passage.
Let's consider that a word has been typed with the Caps lock key accidentall... | The first line of the input data contains a word consisting of uppercase and lowercase Latin letters. The word's length is from 1 to 100 characters, inclusive. | Print the result of the given word's processing. | [
"cAPS\n",
"Lock\n"
] | [
"Caps",
"Lock\n"
] | none | 500 | [
{
"input": "cAPS",
"output": "Caps"
},
{
"input": "Lock",
"output": "Lock"
},
{
"input": "cAPSlOCK",
"output": "cAPSlOCK"
},
{
"input": "CAPs",
"output": "CAPs"
},
{
"input": "LoCK",
"output": "LoCK"
},
{
"input": "OOPS",
"output": "oops"
},
{
... | 1,689,167,808 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | x=input()
i=1
count=0
while(i<len(x)):
if(x[0].islower() and x[i].isupper()):
count+=1
i++
if(x[0].isupper()):
print(x.captialize())
if(count==len(x)-2):
print(x.capitalize())
else:
print(x)
| Title: cAPS lOCK
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
wHAT DO WE NEED cAPS LOCK FOR?
Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in th... | ```python
x=input()
i=1
count=0
while(i<len(x)):
if(x[0].islower() and x[i].isupper()):
count+=1
i++
if(x[0].isupper()):
print(x.captialize())
if(count==len(x)-2):
print(x.capitalize())
else:
print(x)
``` | -1 | |
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,653,163,020 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 5 | 46 | 0 | n, m, a = input().split()
if int(n)//int(a) == 0: div_na = 1
else: div_na = int(n)//int(a)
if int(m)//int(a) == 0: div_ma = 1
else: div_ma=int(m)//int(a)
if int(n)%int(a) > 0:
mod_na = 1
else: mod_na = 0
if int(m)%int(a) > 0:
mod_ma = 1
else: mod_ma = 0
if mod_na == 0 and mod_ma == 0: k = 0
else: ... | 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
n, m, a = input().split()
if int(n)//int(a) == 0: div_na = 1
else: div_na = int(n)//int(a)
if int(m)//int(a) == 0: div_ma = 1
else: div_ma=int(m)//int(a)
if int(n)%int(a) > 0:
mod_na = 1
else: mod_na = 0
if int(m)%int(a) > 0:
mod_ma = 1
else: mod_ma = 0
if mod_na == 0 and mod_ma == 0: k =... | 0 |
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 | |
114 | A | Cifera | PROGRAMMING | 1,000 | [
"math"
] | null | null | When Petya went to school, he got interested in large numbers and what they were called in ancient times. For instance, he learned that the Russian word "tma" (which now means "too much to be counted") used to stand for a thousand and "tma tmyschaya" (which literally means "the tma of tmas") used to stand for a million... | The first input line contains integer number *k*, the second line contains integer number *l* (2<=≤<=*k*,<=*l*<=≤<=231<=-<=1). | You should print in the first line of the output "YES", if the number belongs to the set petriciumus cifera and otherwise print "NO". If the number belongs to the set, then print on the seconds line the only number — the importance of number *l*. | [
"5\n25\n",
"3\n8\n"
] | [
"YES\n1\n",
"NO\n"
] | none | 500 | [
{
"input": "5\n25",
"output": "YES\n1"
},
{
"input": "3\n8",
"output": "NO"
},
{
"input": "123\n123",
"output": "YES\n0"
},
{
"input": "99\n970300",
"output": "NO"
},
{
"input": "1000\n6666666",
"output": "NO"
},
{
"input": "59\n3571",
"output": "N... | 1,626,633,433 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 60 | 218 | 20,172,800 | k = int(input())
l = int(input())
c=0
if(l%k!=0):
print('NO')
else:
while(l>1):
l = l//k
#print(l)
c+=1
if(l==1):
print('YES')
print(c-1)
else:
print("NO") | Title: Cifera
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
When Petya went to school, he got interested in large numbers and what they were called in ancient times. For instance, he learned that the Russian word "tma" (which now means "too much to be counted") used to stand for a thousa... | ```python
k = int(input())
l = int(input())
c=0
if(l%k!=0):
print('NO')
else:
while(l>1):
l = l//k
#print(l)
c+=1
if(l==1):
print('YES')
print(c-1)
else:
print("NO")
``` | 0 | |
50 | A | Domino piling | PROGRAMMING | 800 | [
"greedy",
"math"
] | A. Domino piling | 2 | 256 | You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions:
1. Each domino completely covers ... | In a single line you are given two integers *M* and *N* — board sizes in squares (1<=≤<=*M*<=≤<=*N*<=≤<=16). | Output one number — the maximal number of dominoes, which can be placed. | [
"2 4\n",
"3 3\n"
] | [
"4\n",
"4\n"
] | none | 500 | [
{
"input": "2 4",
"output": "4"
},
{
"input": "3 3",
"output": "4"
},
{
"input": "1 5",
"output": "2"
},
{
"input": "1 6",
"output": "3"
},
{
"input": "1 15",
"output": "7"
},
{
"input": "1 16",
"output": "8"
},
{
"input": "2 5",
"outpu... | 1,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 |
792 | A | New Bus Route | PROGRAMMING | 1,100 | [
"implementation",
"sortings"
] | null | null | There are *n* cities situated along the main road of Berland. Cities are represented by their coordinates — integer numbers *a*1,<=*a*2,<=...,<=*a**n*. All coordinates are pairwise distinct.
It is possible to get from one city to another only by bus. But all buses and roads are very old, so the Minister of Transport d... | The first line contains one integer number *n* (2<=≤<=*n*<=≤<=2·105).
The second line contains *n* integer numbers *a*1,<=*a*2,<=...,<=*a**n* (<=-<=109<=≤<=*a**i*<=≤<=109). All numbers *a**i* are pairwise distinct. | Print two integer numbers — the minimal distance and the quantity of pairs with this distance. | [
"4\n6 -3 0 4\n",
"3\n-2 0 2\n"
] | [
"2 1\n",
"2 2\n"
] | In the first example the distance between the first city and the fourth city is |4 - 6| = 2, and it is the only pair with this distance. | 0 | [
{
"input": "4\n6 -3 0 4",
"output": "2 1"
},
{
"input": "3\n-2 0 2",
"output": "2 2"
},
{
"input": "2\n1 2",
"output": "1 1"
},
{
"input": "2\n1000000000 -1000000000",
"output": "2000000000 1"
},
{
"input": "5\n-979619606 -979619602 -979619604 -979619605 -97961960... | 1,491,191,132 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 8 | 1,000 | 38,809,600 | n = int(input())
nNumbers = input()
nIntegers = nNumbers.split(" ")
differences = []
for i in range(len(nIntegers)):
x = i + 1
while(x < len(nIntegers)):
res = int(nIntegers[i]) - int(nIntegers[x])
differences.append(abs(res))
x = x + 1
... | Title: New Bus Route
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* cities situated along the main road of Berland. Cities are represented by their coordinates — integer numbers *a*1,<=*a*2,<=...,<=*a**n*. All coordinates are pairwise distinct.
It is possible to get from on... | ```python
n = int(input())
nNumbers = input()
nIntegers = nNumbers.split(" ")
differences = []
for i in range(len(nIntegers)):
x = i + 1
while(x < len(nIntegers)):
res = int(nIntegers[i]) - int(nIntegers[x])
differences.append(abs(res))
x = x ... | 0 | |
190 | C | STL | PROGRAMMING | 1,500 | [
"dfs and similar"
] | null | null | Vasya used to be an accountant before the war began and he is one of the few who knows how to operate a computer, so he was assigned as the programmer.
We all know that programs often store sets of integers. For example, if we have a problem about a weighted directed graph, its edge can be represented by three integer... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105), showing how many numbers the type dictated by Gena contains.
The second line contains space-separated words, said by Gena. Each of them is either "pair" or "int" (without the quotes).
It is guaranteed that the total number of words does not exceed 105 ... | If it is possible to add the punctuation marks so as to get a correct type of language X-- as a result, print a single line that represents the resulting type. Otherwise, print "Error occurred" (without the quotes). Inside the record of a type should not be any extra spaces and other characters.
It is guaranteed that... | [
"3\npair pair int int int\n",
"1\npair int\n"
] | [
"pair<pair<int,int>,int>",
"Error occurred"
] | none | 1,500 | [
{
"input": "3\npair pair int int int",
"output": "pair<pair<int,int>,int>"
},
{
"input": "1\npair int",
"output": "Error occurred"
},
{
"input": "4\npair pair int int pair int int",
"output": "pair<pair<int,int>,pair<int,int>>"
},
{
"input": "4\npair pair pair int int int int... | 1,591,090,463 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 7 | 2,000 | 14,540,800 | n = input()
arr = input().split()
res, s = '', []
for i in arr:
res += i
while i == 'int' and s and s[-1]:
res += '>'
if s: s.pop()
if s: s.pop()
s.append(i == 'int')
res += ',' if i == 'int' else '<'
if res.count('<') == res.count('>'):
print(res[: -1])
else... | Title: STL
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya used to be an accountant before the war began and he is one of the few who knows how to operate a computer, so he was assigned as the programmer.
We all know that programs often store sets of integers. For example, if we hav... | ```python
n = input()
arr = input().split()
res, s = '', []
for i in arr:
res += i
while i == 'int' and s and s[-1]:
res += '>'
if s: s.pop()
if s: s.pop()
s.append(i == 'int')
res += ',' if i == 'int' else '<'
if res.count('<') == res.count('>'):
print(res[: ... | 0 | |
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,699,106,890 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 62 | 0 | n = int(input())
home_colors = []
count = 0
for _ in range(n):
h, a = input().split()
home_colors.append([h,a])
for i in range(len(home_colors)):
for j in range(len(home_colors)):
if home_colors[i][0] == home_colors[j][1]:
count += 1
print(count)
print(home_colors) | 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())
home_colors = []
count = 0
for _ in range(n):
h, a = input().split()
home_colors.append([h,a])
for i in range(len(home_colors)):
for j in range(len(home_colors)):
if home_colors[i][0] == home_colors[j][1]:
count += 1
print(count)
print(home_col... | 0 | |
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 | |
550 | A | Two Substrings | PROGRAMMING | 1,500 | [
"brute force",
"dp",
"greedy",
"implementation",
"strings"
] | null | null | You are given string *s*. Your task is to determine if the given string *s* contains two non-overlapping substrings "AB" and "BA" (the substrings can go in any order). | The only line of input contains a string *s* of length between 1 and 105 consisting of uppercase Latin letters. | Print "YES" (without the quotes), if string *s* contains two non-overlapping substrings "AB" and "BA", and "NO" otherwise. | [
"ABA\n",
"BACFAB\n",
"AXBYBXA\n"
] | [
"NO\n",
"YES\n",
"NO\n"
] | In the first sample test, despite the fact that there are substrings "AB" and "BA", their occurrences overlap, so the answer is "NO".
In the second sample test there are the following occurrences of the substrings: BACFAB.
In the third sample test there is no substring "AB" nor substring "BA". | 1,000 | [
{
"input": "ABA",
"output": "NO"
},
{
"input": "BACFAB",
"output": "YES"
},
{
"input": "AXBYBXA",
"output": "NO"
},
{
"input": "ABABAB",
"output": "YES"
},
{
"input": "BBBBBBBBBB",
"output": "NO"
},
{
"input": "ABBA",
"output": "YES"
},
{
"... | 1,672,273,148 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 5 | 46 | 0 | a=input ()
if "AB" in a and "BA" in a and a.count("A")==a.count("B"):
print ("YES")
else:
print ("NO") | Title: Two Substrings
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given string *s*. Your task is to determine if the given string *s* contains two non-overlapping substrings "AB" and "BA" (the substrings can go in any order).
Input Specification:
The only line of input contain... | ```python
a=input ()
if "AB" in a and "BA" in a and a.count("A")==a.count("B"):
print ("YES")
else:
print ("NO")
``` | 0 | |
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 | |
842 | B | Gleb And Pizza | PROGRAMMING | 1,100 | [
"geometry"
] | null | null | Gleb ordered pizza home. When the courier delivered the pizza, he was very upset, because several pieces of sausage lay on the crust, and he does not really like the crust.
The pizza is a circle of radius *r* and center at the origin. Pizza consists of the main part — circle of radius *r*<=-<=*d* with center at the or... | First string contains two integer numbers *r* and *d* (0<=≤<=*d*<=<<=*r*<=≤<=500) — the radius of pizza and the width of crust.
Next line contains one integer number *n* — the number of pieces of sausage (1<=≤<=*n*<=≤<=105).
Each of next *n* lines contains three integer numbers *x**i*, *y**i* and *r**i* (<=-<=500<... | Output the number of pieces of sausage that lay on the crust. | [
"8 4\n7\n7 8 1\n-7 3 2\n0 2 1\n0 -2 2\n-3 -3 1\n0 6 2\n5 3 1\n",
"10 8\n4\n0 0 9\n0 0 10\n1 0 1\n1 0 2\n"
] | [
"2\n",
"0\n"
] | Below is a picture explaining the first example. Circles of green color denote pieces of sausage lying on the crust. | 1,000 | [
{
"input": "8 4\n7\n7 8 1\n-7 3 2\n0 2 1\n0 -2 2\n-3 -3 1\n0 6 2\n5 3 1",
"output": "2"
},
{
"input": "10 8\n4\n0 0 9\n0 0 10\n1 0 1\n1 0 2",
"output": "0"
},
{
"input": "1 0\n1\n1 1 0",
"output": "0"
},
{
"input": "3 0\n5\n3 0 0\n0 3 0\n-3 0 0\n0 -3 0\n3 0 1",
"output": ... | 1,504,020,078 | 978 | Python 3 | WRONG_ANSWER | PRETESTS | 0 | 46 | 0 | from math import sqrt
r,d = map(int, input().split())
n = int(input())
ans = 0
for i in range(n):
x,y,c = map(int, input().split())
print(sqrt(x**2 + y**2) - c, sqrt(x**2 + y**2) + c)
if min(sqrt(x**2 + y**2) - c, 0) >= (r-d) and sqrt(x**2 + y**2) + c <= r:
ans += 1
print(ans) | Title: Gleb And Pizza
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Gleb ordered pizza home. When the courier delivered the pizza, he was very upset, because several pieces of sausage lay on the crust, and he does not really like the crust.
The pizza is a circle of radius *r* and center... | ```python
from math import sqrt
r,d = map(int, input().split())
n = int(input())
ans = 0
for i in range(n):
x,y,c = map(int, input().split())
print(sqrt(x**2 + y**2) - c, sqrt(x**2 + y**2) + c)
if min(sqrt(x**2 + y**2) - c, 0) >= (r-d) and sqrt(x**2 + y**2) + c <= r:
ans += 1
print(ans)
`... | 0 | |
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 |
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,590,166,167 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 34 | 109 | 0 | s = input()
a = 0
g = 'hello'
for i in range(len(s)):
if g[a] == s[i]:
if a < 4:
a = a + 1
if a == 4:
print('YES')
else:
print('NO')
| Title: Chat room
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letter... | ```python
s = input()
a = 0
g = 'hello'
for i in range(len(s)):
if g[a] == s[i]:
if a < 4:
a = a + 1
if a == 4:
print('YES')
else:
print('NO')
``` | 0 |
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,611,764,465 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 60 | 0 | n = int(input())
y = list(map(int, input().split()))
tower = n
high = 1
max = 0
y.sort() #[5,6,6,7]
for i in range(len(y) - 1):
if y[i] == y[i+1]:
high += 1
tower -= 1
max = high
else:
high = 1
print(max, tower) | Title: Towers
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Little Vasya has received a young builder’s kit. The kit consists of several wooden bars, the lengths of all of them are known. The bars can be put one on the top of the other if their lengths are the same.
Vasya wants to construct... | ```python
n = int(input())
y = list(map(int, input().split()))
tower = n
high = 1
max = 0
y.sort() #[5,6,6,7]
for i in range(len(y) - 1):
if y[i] == y[i+1]:
high += 1
tower -= 1
max = high
else:
high = 1
print(max, tower)
``` | 0 |
799 | A | Carrot Cakes | PROGRAMMING | 1,100 | [
"brute force",
"implementation"
] | null | null | In some game by Playrix it takes *t* minutes for an oven to bake *k* carrot cakes, all cakes are ready at the same moment *t* minutes after they started baking. Arkady needs at least *n* cakes to complete a task, but he currently don't have any. However, he has infinitely many ingredients and one oven. Moreover, Arkady... | The only line contains four integers *n*, *t*, *k*, *d* (1<=≤<=*n*,<=*t*,<=*k*,<=*d*<=≤<=1<=000) — the number of cakes needed, the time needed for one oven to bake *k* cakes, the number of cakes baked at the same time, the time needed to build the second oven. | If it is reasonable to build the second oven, print "YES". Otherwise print "NO". | [
"8 6 4 5\n",
"8 6 4 6\n",
"10 3 11 4\n",
"4 2 1 4\n"
] | [
"YES\n",
"NO\n",
"NO\n",
"YES\n"
] | In the first example it is possible to get 8 cakes in 12 minutes using one oven. The second oven can be built in 5 minutes, so after 6 minutes the first oven bakes 4 cakes, the second oven bakes 4 more ovens after 11 minutes. Thus, it is reasonable to build the second oven.
In the second example it doesn't matter whe... | 500 | [
{
"input": "8 6 4 5",
"output": "YES"
},
{
"input": "8 6 4 6",
"output": "NO"
},
{
"input": "10 3 11 4",
"output": "NO"
},
{
"input": "4 2 1 4",
"output": "YES"
},
{
"input": "28 17 16 26",
"output": "NO"
},
{
"input": "60 69 9 438",
"output": "NO"... | 1,694,610,537 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 6 | 31 | 0 | u = list(map(int,input().split()))
x = (u[1]+u[3]) / u[1]
if x* u[2] < u[0]:
print("YES")
else :
print("NO")
| Title: Carrot Cakes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In some game by Playrix it takes *t* minutes for an oven to bake *k* carrot cakes, all cakes are ready at the same moment *t* minutes after they started baking. Arkady needs at least *n* cakes to complete a task, but he cu... | ```python
u = list(map(int,input().split()))
x = (u[1]+u[3]) / u[1]
if x* u[2] < u[0]:
print("YES")
else :
print("NO")
``` | 0 | |
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 | |
337 | A | Puzzles | PROGRAMMING | 900 | [
"greedy"
] | null | null | The end of the school year is near and Ms. Manana, the teacher, will soon have to say goodbye to a yet another class. She decided to prepare a goodbye present for her *n* students and give each of them a jigsaw puzzle (which, as wikipedia states, is a tiling puzzle that requires the assembly of numerous small, often od... | The first line contains space-separated integers *n* and *m* (2<=≤<=*n*<=≤<=*m*<=≤<=50). The second line contains *m* space-separated integers *f*1,<=*f*2,<=...,<=*f**m* (4<=≤<=*f**i*<=≤<=1000) — the quantities of pieces in the puzzles sold in the shop. | Print a single integer — the least possible difference the teacher can obtain. | [
"4 6\n10 12 10 7 5 22\n"
] | [
"5\n"
] | Sample 1. The class has 4 students. The shop sells 6 puzzles. If Ms. Manana buys the first four puzzles consisting of 10, 12, 10 and 7 pieces correspondingly, then the difference between the sizes of the largest and the smallest puzzle will be equal to 5. It is impossible to obtain a smaller difference. Note that the t... | 500 | [
{
"input": "4 6\n10 12 10 7 5 22",
"output": "5"
},
{
"input": "2 2\n4 4",
"output": "0"
},
{
"input": "2 10\n4 5 6 7 8 9 10 11 12 12",
"output": "0"
},
{
"input": "4 5\n818 136 713 59 946",
"output": "759"
},
{
"input": "3 20\n446 852 783 313 549 965 40 88 86 617... | 1,673,005,106 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 92 | 0 | n,m =map(int,input().split())
l=list(map(int, input().split()))
l=sorted(l)
min=min(l)
ans=l[n-1]-min
print(ans)
# 10 12 10 7 5 22 | Title: Puzzles
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The end of the school year is near and Ms. Manana, the teacher, will soon have to say goodbye to a yet another class. She decided to prepare a goodbye present for her *n* students and give each of them a jigsaw puzzle (which, a... | ```python
n,m =map(int,input().split())
l=list(map(int, input().split()))
l=sorted(l)
min=min(l)
ans=l[n-1]-min
print(ans)
# 10 12 10 7 5 22
``` | 0 | |
158 | A | Next Round | PROGRAMMING | 800 | [
"*special",
"implementation"
] | null | null | "Contestant who earns a score equal to or greater than the *k*-th place finisher's score will advance to the next round, as long as the contestant earns a positive score..." — an excerpt from contest rules.
A total of *n* participants took part in the contest (*n*<=≥<=*k*), and you already know their scores. Calculate... | The first line of the input contains two integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=50) separated by a single space.
The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=100), where *a**i* is the score earned by the participant who got the *i*-th place. The given sequence... | Output the number of participants who advance to the next round. | [
"8 5\n10 9 8 7 7 7 5 5\n",
"4 2\n0 0 0 0\n"
] | [
"6\n",
"0\n"
] | In the first example the participant on the 5th place earned 7 points. As the participant on the 6th place also earned 7 points, there are 6 advancers.
In the second example nobody got a positive score. | 500 | [
{
"input": "8 5\n10 9 8 7 7 7 5 5",
"output": "6"
},
{
"input": "4 2\n0 0 0 0",
"output": "0"
},
{
"input": "5 1\n1 1 1 1 1",
"output": "5"
},
{
"input": "5 5\n1 1 1 1 1",
"output": "5"
},
{
"input": "1 1\n10",
"output": "1"
},
{
"input": "17 14\n16 15... | 1,698,925,217 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 62 | 0 | n=int(input())
k=int(input())
scores=[]
c=0
for i in range(n):
item=int(input())
scores.append(item)
for i in range(n):
if scores[i]>=scores[k-1]:
c=c+1
print('t')
print(c) | Title: Next Round
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
"Contestant who earns a score equal to or greater than the *k*-th place finisher's score will advance to the next round, as long as the contestant earns a positive score..." — an excerpt from contest rules.
A total of *n* p... | ```python
n=int(input())
k=int(input())
scores=[]
c=0
for i in range(n):
item=int(input())
scores.append(item)
for i in range(n):
if scores[i]>=scores[k-1]:
c=c+1
print('t')
print(c)
``` | -1 | |
9 | C | Hexadecimal's Numbers | PROGRAMMING | 1,200 | [
"brute force",
"implementation",
"math"
] | C. Hexadecimal's Numbers | 1 | 64 | One beautiful July morning a terrible thing happened in Mainframe: a mean virus Megabyte somehow got access to the memory of his not less mean sister Hexadecimal. He loaded there a huge amount of *n* different natural numbers from 1 to *n* to obtain total control over her energy.
But his plan failed. The reason for th... | Input data contains the only number *n* (1<=≤<=*n*<=≤<=109). | Output the only number — answer to the problem. | [
"10\n"
] | [
"2"
] | For *n* = 10 the answer includes numbers 1 and 10. | 0 | [
{
"input": "10",
"output": "2"
},
{
"input": "20",
"output": "3"
},
{
"input": "72",
"output": "3"
},
{
"input": "99",
"output": "3"
},
{
"input": "100",
"output": "4"
},
{
"input": "101",
"output": "5"
},
{
"input": "102",
"output": "5... | 1,637,691,329 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 62 | 0 | import sys
import math
from sys import stdin, stdout
from itertools import permutations
# TAKE INPUT
def get_ints_in_variables():
return map(int, sys.stdin.readline().strip().split())
def get_int(): return int(input())
def get_ints_in_list(): return list(
map(int, sys.stdin.readline().strip().split(... | Title: Hexadecimal's Numbers
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
One beautiful July morning a terrible thing happened in Mainframe: a mean virus Megabyte somehow got access to the memory of his not less mean sister Hexadecimal. He loaded there a huge amount of *n* different natural ... | ```python
import sys
import math
from sys import stdin, stdout
from itertools import permutations
# TAKE INPUT
def get_ints_in_variables():
return map(int, sys.stdin.readline().strip().split())
def get_int(): return int(input())
def get_ints_in_list(): return list(
map(int, sys.stdin.readline().stri... | 0 |
644 | B | Processing Queries | PROGRAMMING | 1,700 | [
"*special",
"constructive algorithms",
"data structures",
"two pointers"
] | null | null | In this problem you have to simulate the workflow of one-thread server. There are *n* queries to process, the *i*-th will be received at moment *t**i* and needs to be processed for *d**i* units of time. All *t**i* are guaranteed to be distinct.
When a query appears server may react in three possible ways:
1. If ser... | The first line of the input contains two integers *n* and *b* (1<=≤<=*n*,<=*b*<=≤<=200<=000) — the number of queries and the maximum possible size of the query queue.
Then follow *n* lines with queries descriptions (in chronological order). Each description consists of two integers *t**i* and *d**i* (1<=≤<=*t**i*,<=*d... | Print the sequence of *n* integers *e*1,<=*e*2,<=...,<=*e**n*, where *e**i* is the moment the server will finish to process the *i*-th query (queries are numbered in the order they appear in the input) or <=-<=1 if the corresponding query will be rejected. | [
"5 1\n2 9\n4 8\n10 9\n15 2\n19 1\n",
"4 1\n2 8\n4 8\n10 9\n15 2\n"
] | [
"11 19 -1 21 22 \n",
"10 18 27 -1 \n"
] | Consider the first sample.
1. The server will start to process first query at the moment 2 and will finish to process it at the moment 11. 1. At the moment 4 second query appears and proceeds to the queue. 1. At the moment 10 third query appears. However, the server is still busy with query 1, *b* = 1 and there is... | 1,000 | [
{
"input": "5 1\n2 9\n4 8\n10 9\n15 2\n19 1",
"output": "11 19 -1 21 22 "
},
{
"input": "4 1\n2 8\n4 8\n10 9\n15 2",
"output": "10 18 27 -1 "
},
{
"input": "1 1\n1000000000 1000000000",
"output": "2000000000 "
},
{
"input": "4 3\n999999996 1000000000\n999999997 1000000000\n99... | 1,564,603,763 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 11 | 2,682 | 30,412,800 | #Processing Queries
import queue
class Query:
def __init__(self, t, d):
self.t = t
self.d = d
n, b = map(int, input().split())
a = []
for i in range(n):
t, d = map(int, input().split())
a.append(Query(t, d))
q = queue.Queue()
rejected_q = queue.Queue()
i = 0
while q... | Title: Processing Queries
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In this problem you have to simulate the workflow of one-thread server. There are *n* queries to process, the *i*-th will be received at moment *t**i* and needs to be processed for *d**i* units of time. All *t**i* ar... | ```python
#Processing Queries
import queue
class Query:
def __init__(self, t, d):
self.t = t
self.d = d
n, b = map(int, input().split())
a = []
for i in range(n):
t, d = map(int, input().split())
a.append(Query(t, d))
q = queue.Queue()
rejected_q = queue.Queue()
i = ... | 0 | |
863 | B | Kayaking | PROGRAMMING | 1,500 | [
"brute force",
"greedy",
"sortings"
] | null | null | Vadim is really keen on travelling. Recently he heard about kayaking activity near his town and became very excited about it, so he joined a party of kayakers.
Now the party is ready to start its journey, but firstly they have to choose kayaks. There are 2·*n* people in the group (including Vadim), and they have exact... | The first line contains one number *n* (2<=≤<=*n*<=≤<=50).
The second line contains 2·*n* integer numbers *w*1, *w*2, ..., *w*2*n*, where *w**i* is weight of person *i* (1<=≤<=*w**i*<=≤<=1000). | Print minimum possible total instability. | [
"2\n1 2 3 4\n",
"4\n1 3 4 6 3 4 100 200\n"
] | [
"1\n",
"5\n"
] | none | 0 | [
{
"input": "2\n1 2 3 4",
"output": "1"
},
{
"input": "4\n1 3 4 6 3 4 100 200",
"output": "5"
},
{
"input": "3\n305 139 205 406 530 206",
"output": "102"
},
{
"input": "3\n610 750 778 6 361 407",
"output": "74"
},
{
"input": "5\n97 166 126 164 154 98 221 7 51 47",
... | 1,672,445,852 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 30 | 0 | import sys
o = sys.stdin.readlines()
arr2 = [line.rstrip('\n') for line in o]
arr = [x for y in arr2 for x in y.split()]
for element in range(len(arr)):
arr[element] = int(arr[element])
arr.pop(0)
arr.sort()
difference = 0
maxdifference = 0
for i in range(0,len(arr)-1):
difference = arr[i+1] - arr[... | Title: Kayaking
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vadim is really keen on travelling. Recently he heard about kayaking activity near his town and became very excited about it, so he joined a party of kayakers.
Now the party is ready to start its journey, but firstly they hav... | ```python
import sys
o = sys.stdin.readlines()
arr2 = [line.rstrip('\n') for line in o]
arr = [x for y in arr2 for x in y.split()]
for element in range(len(arr)):
arr[element] = int(arr[element])
arr.pop(0)
arr.sort()
difference = 0
maxdifference = 0
for i in range(0,len(arr)-1):
difference = arr[i... | 0 | |
793 | A | Oleg and shares | PROGRAMMING | 900 | [
"implementation",
"math"
] | null | null | Oleg the bank client checks share prices every day. There are *n* share prices he is interested in. Today he observed that each second exactly one of these prices decreases by *k* rubles (note that each second exactly one price changes, but at different seconds different prices can change). Prices can become negative. ... | The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=105,<=1<=≤<=*k*<=≤<=109) — the number of share prices, and the amount of rubles some price decreases each second.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the initial prices. | Print the only line containing the minimum number of seconds needed for prices to become equal, of «-1» if it is impossible. | [
"3 3\n12 9 15\n",
"2 2\n10 9\n",
"4 1\n1 1000000000 1000000000 1000000000\n"
] | [
"3",
"-1",
"2999999997"
] | Consider the first example.
Suppose the third price decreases in the first second and become equal 12 rubles, then the first price decreases and becomes equal 9 rubles, and in the third second the third price decreases again and becomes equal 9 rubles. In this case all prices become equal 9 rubles in 3 seconds.
Ther... | 500 | [
{
"input": "3 3\n12 9 15",
"output": "3"
},
{
"input": "2 2\n10 9",
"output": "-1"
},
{
"input": "4 1\n1 1000000000 1000000000 1000000000",
"output": "2999999997"
},
{
"input": "1 11\n123",
"output": "0"
},
{
"input": "20 6\n38 86 86 50 98 62 32 2 14 62 98 50 2 50... | 1,691,345,915 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 93 | 14,028,800 | # بسم الله (accepted)
# problem : i have to reduce 'n' stock prices by 'k' minimum no_of_times to make them equal , if they can't be equal , then print -1
n ,k = map(int , input().split(' '))
initial_prices = input().split(' ')
initial_prices = [int(price) for price in initial_prices]
count = 0
lowest_s... | Title: Oleg and shares
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Oleg the bank client checks share prices every day. There are *n* share prices he is interested in. Today he observed that each second exactly one of these prices decreases by *k* rubles (note that each second exactly o... | ```python
# بسم الله (accepted)
# problem : i have to reduce 'n' stock prices by 'k' minimum no_of_times to make them equal , if they can't be equal , then print -1
n ,k = map(int , input().split(' '))
initial_prices = input().split(' ')
initial_prices = [int(price) for price in initial_prices]
count = 0... | 0 | |
1 | A | Theatre Square | PROGRAMMING | 1,000 | [
"math"
] | A. Theatre Square | 1 | 256 | Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size *a*<=×<=*a*.
What is the least number of flagstones needed to pave the... | The input contains three positive integer numbers in the first line: *n*,<=<=*m* and *a* (1<=≤<=<=*n*,<=*m*,<=*a*<=≤<=109). | Write the needed number of flagstones. | [
"6 6 4\n"
] | [
"4\n"
] | none | 0 | [
{
"input": "6 6 4",
"output": "4"
},
{
"input": "1 1 1",
"output": "1"
},
{
"input": "2 1 1",
"output": "2"
},
{
"input": "1 2 1",
"output": "2"
},
{
"input": "2 2 1",
"output": "4"
},
{
"input": "2 1 2",
"output": "1"
},
{
"input": "1 1 3"... | 1,695,131,388 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 30 | 0 | t = int(input())
for i in range(t):
a, b = map(int, input().split())
print((min(max(2 * b,a),max(2 * a,b)))** 2) | 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
t = int(input())
for i in range(t):
a, b = map(int, input().split())
print((min(max(2 * b,a),max(2 * a,b)))** 2)
``` | -1 |
690 | A1 | Collective Mindsets (easy) | PROGRAMMING | 1,100 | [] | null | null | Tonight is brain dinner night and all zombies will gather together to scarf down some delicious brains. The artful Heidi plans to crash the party, incognito, disguised as one of them. Her objective is to get away with at least one brain, so she can analyze the zombies' mindset back home and gain a strategic advantage.
... | The only line of input contains one integer: *N*, the number of attendees (1<=≤<=*N*<=≤<=109). | Output one integer: the smallest number of brains in the chest which allows Heidi to take one brain home. | [
"1\n",
"4\n"
] | [
"1\n",
"2\n"
] | 0 | [
{
"input": "1",
"output": "1"
},
{
"input": "4",
"output": "2"
},
{
"input": "2",
"output": "1"
},
{
"input": "3",
"output": "2"
},
{
"input": "5",
"output": "3"
},
{
"input": "6",
"output": "3"
},
{
"input": "7",
"output": "4"
},
{... | 1,489,426,488 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 46 | 4,608,000 | import sys
data = sys.stdin.readlines()
print("Counted", len(data), "lines.")
print(data) | Title: Collective Mindsets (easy)
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Tonight is brain dinner night and all zombies will gather together to scarf down some delicious brains. The artful Heidi plans to crash the party, incognito, disguised as one of them. Her objective is to get ... | ```python
import sys
data = sys.stdin.readlines()
print("Counted", len(data), "lines.")
print(data)
``` | 0 | ||
439 | A | Devu, the Singer and Churu, the Joker | PROGRAMMING | 900 | [
"greedy",
"implementation"
] | null | null | Devu is a renowned classical singer. He is invited to many big functions/festivals. Recently he was invited to "All World Classical Singing Festival". Other than Devu, comedian Churu was also invited.
Devu has provided organizers a list of the songs and required time for singing them. He will sing *n* songs, *i**th* s... | The first line contains two space separated integers *n*, *d* (1<=≤<=*n*<=≤<=100; 1<=≤<=*d*<=≤<=10000). The second line contains *n* space-separated integers: *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t**i*<=≤<=100). | If there is no way to conduct all the songs of Devu, output -1. Otherwise output the maximum number of jokes that Churu can crack in the grand event. | [
"3 30\n2 2 1\n",
"3 20\n2 1 1\n"
] | [
"5\n",
"-1\n"
] | Consider the first example. The duration of the event is 30 minutes. There could be maximum 5 jokes in the following way:
- First Churu cracks a joke in 5 minutes. - Then Devu performs the first song for 2 minutes. - Then Churu cracks 2 jokes in 10 minutes. - Now Devu performs second song for 2 minutes. - Then Ch... | 500 | [
{
"input": "3 30\n2 2 1",
"output": "5"
},
{
"input": "3 20\n2 1 1",
"output": "-1"
},
{
"input": "50 10000\n5 4 10 9 9 6 7 7 7 3 3 7 7 4 7 4 10 10 1 7 10 3 1 4 5 7 2 10 10 10 2 3 4 7 6 1 8 4 7 3 8 8 4 10 1 1 9 2 6 1",
"output": "1943"
},
{
"input": "50 10000\n4 7 15 9 11 12 ... | 1,654,592,877 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 20 | 62 | 0 | l=list(map(int,input().split()))
n=l[0]
d=l[1]
t=l=list(map(int,input().split()))
gap=(n-1)*10
if(gap>=d):
print(-1)
else:
print((d-sum(t))//5)
| Title: Devu, the Singer and Churu, the Joker
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Devu is a renowned classical singer. He is invited to many big functions/festivals. Recently he was invited to "All World Classical Singing Festival". Other than Devu, comedian Churu was also invit... | ```python
l=list(map(int,input().split()))
n=l[0]
d=l[1]
t=l=list(map(int,input().split()))
gap=(n-1)*10
if(gap>=d):
print(-1)
else:
print((d-sum(t))//5)
``` | 0 | |
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 | |
858 | B | Which floor? | PROGRAMMING | 1,500 | [
"brute force",
"implementation"
] | null | null | In a building where Polycarp lives there are equal number of flats on each floor. Unfortunately, Polycarp don't remember how many flats are on each floor, but he remembers that the flats are numbered from 1 from lower to upper floors. That is, the first several flats are on the first floor, the next several flats are o... | The first line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=100, 0<=≤<=*m*<=≤<=100), where *n* is the number of the flat you need to restore floor for, and *m* is the number of flats in Polycarp's memory.
*m* lines follow, describing the Polycarp's memory: each of these lines contains a pair of integers *k**i*,<=*... | Print the number of the floor in which the *n*-th flat is located, if it is possible to determine it in a unique way. Print -1 if it is not possible to uniquely restore this floor. | [
"10 3\n6 2\n2 1\n7 3\n",
"8 4\n3 1\n6 2\n5 2\n2 1\n"
] | [
"4\n",
"-1\n"
] | In the first example the 6-th flat is on the 2-nd floor, while the 7-th flat is on the 3-rd, so, the 6-th flat is the last on its floor and there are 3 flats on each floor. Thus, the 10-th flat is on the 4-th floor.
In the second example there can be 3 or 4 flats on each floor, so we can't restore the floor for the 8-... | 750 | [
{
"input": "10 3\n6 2\n2 1\n7 3",
"output": "4"
},
{
"input": "8 4\n3 1\n6 2\n5 2\n2 1",
"output": "-1"
},
{
"input": "8 3\n7 2\n6 2\n1 1",
"output": "2"
},
{
"input": "4 2\n8 3\n3 1",
"output": "2"
},
{
"input": "11 4\n16 4\n11 3\n10 3\n15 4",
"output": "3"
... | 1,539,705,684 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 109 | 0 | n,m = map(int,input().split())
a = []
b = []
N = -1
for i in range(m):
a.append(0)
b.append(0)
for i in range(m):
a[i], b[i] = map(int,input().split())
for i in range(m):
for j in range(m):
if abs(a[i]-a[j]) == 1 and b[i] < b[j]: N = a[i]//b[i]
if N == -1: print(N)
else:
if n... | Title: Which floor?
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In a building where Polycarp lives there are equal number of flats on each floor. Unfortunately, Polycarp don't remember how many flats are on each floor, but he remembers that the flats are numbered from 1 from lower to u... | ```python
n,m = map(int,input().split())
a = []
b = []
N = -1
for i in range(m):
a.append(0)
b.append(0)
for i in range(m):
a[i], b[i] = map(int,input().split())
for i in range(m):
for j in range(m):
if abs(a[i]-a[j]) == 1 and b[i] < b[j]: N = a[i]//b[i]
if N == -1: print(N)
else:... | 0 | |
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 | |
817 | C | Really Big Numbers | PROGRAMMING | 1,600 | [
"binary search",
"brute force",
"dp",
"math"
] | null | null | Ivan likes to learn different things about numbers, but he is especially interested in really big numbers. Ivan thinks that a positive integer number *x* is really big if the difference between *x* and the sum of its digits (in decimal representation) is not less than *s*. To prove that these numbers may have different... | The first (and the only) line contains two integers *n* and *s* (1<=≤<=*n*,<=*s*<=≤<=1018). | Print one integer — the quantity of really big numbers that are not greater than *n*. | [
"12 1\n",
"25 20\n",
"10 9\n"
] | [
"3\n",
"0\n",
"1\n"
] | In the first example numbers 10, 11 and 12 are really big.
In the second example there are no really big numbers that are not greater than 25 (in fact, the first really big number is 30: 30 - 3 ≥ 20).
In the third example 10 is the only really big number (10 - 1 ≥ 9). | 0 | [
{
"input": "12 1",
"output": "3"
},
{
"input": "25 20",
"output": "0"
},
{
"input": "10 9",
"output": "1"
},
{
"input": "300 1000",
"output": "0"
},
{
"input": "500 1000",
"output": "0"
},
{
"input": "1000 2000",
"output": "0"
},
{
"input":... | 1,497,614,829 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 7 | 1,000 | 0 | n,s = map(int,input().split())
def is_big(m):
r = [int(k) for k in list(str(m))]
return m-sum(r) >= s
def calcul():
r = list(str(n))
k = len(r)
res = 0
c = int(r[0])
for t in range(c):
z = int("".join([str(t)] + ["0" for _ in range(k-1)]))
z1 = int("".join([str... | Title: Really Big Numbers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Ivan likes to learn different things about numbers, but he is especially interested in really big numbers. Ivan thinks that a positive integer number *x* is really big if the difference between *x* and the sum of its... | ```python
n,s = map(int,input().split())
def is_big(m):
r = [int(k) for k in list(str(m))]
return m-sum(r) >= s
def calcul():
r = list(str(n))
k = len(r)
res = 0
c = int(r[0])
for t in range(c):
z = int("".join([str(t)] + ["0" for _ in range(k-1)]))
z1 = int(""... | 0 | |
65 | A | Harry Potter and Three Spells | PROGRAMMING | 1,800 | [
"implementation",
"math"
] | A. Harry Potter and Three Spells | 2 | 256 | A long time ago (probably even in the first book), Nicholas Flamel, a great alchemist and the creator of the Philosopher's Stone, taught Harry Potter three useful spells. The first one allows you to convert *a* grams of sand into *b* grams of lead, the second one allows you to convert *c* grams of lead into *d* grams o... | The first line contains 6 integers *a*, *b*, *c*, *d*, *e*, *f* (0<=≤<=*a*,<=*b*,<=*c*,<=*d*,<=*e*,<=*f*<=≤<=1000). | Print "Ron", if it is possible to get an infinitely large amount of gold having a certain finite amount of sand (and not having any gold and lead at all), i.e., Ron is right. Otherwise, print "Hermione". | [
"100 200 250 150 200 250\n",
"100 50 50 200 200 100\n",
"100 10 200 20 300 30\n",
"0 0 0 0 0 0\n",
"1 1 0 1 1 1\n",
"1 0 1 2 1 2\n",
"100 1 100 1 0 1\n"
] | [
"Ron\n",
"Hermione\n",
"Hermione\n",
"Hermione\n",
"Ron\n",
"Hermione\n",
"Ron\n"
] | Consider the first sample. Let's start with the 500 grams of sand. Apply the first spell 5 times and turn the sand into 1000 grams of lead. Then apply the second spell 4 times to get 600 grams of gold. Let’s take 400 grams from the resulting amount of gold turn them back into sand. We get 500 grams of sand and 200 gram... | 500 | [
{
"input": "100 200 250 150 200 250",
"output": "Ron"
},
{
"input": "100 50 50 200 200 100",
"output": "Hermione"
},
{
"input": "100 10 200 20 300 30",
"output": "Hermione"
},
{
"input": "0 0 0 0 0 0",
"output": "Hermione"
},
{
"input": "1 1 0 1 1 1",
"output"... | 1,594,267,452 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 248 | 6,656,000 | a,b,c,d,e,f=map(int,input().split())
if a==0 or c==0 or e==0:
print("Hermione")
exit()
k1=b/a
k2=d/c
k3=f/e
if k1*k2*k3 > 1:
print("Ron")
else:
print("Hermione")
| Title: Harry Potter and Three Spells
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A long time ago (probably even in the first book), Nicholas Flamel, a great alchemist and the creator of the Philosopher's Stone, taught Harry Potter three useful spells. The first one allows you to convert *a... | ```python
a,b,c,d,e,f=map(int,input().split())
if a==0 or c==0 or e==0:
print("Hermione")
exit()
k1=b/a
k2=d/c
k3=f/e
if k1*k2*k3 > 1:
print("Ron")
else:
print("Hermione")
``` | 0 |
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 | |
659 | A | Round House | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | null | null | Vasya lives in a round building, whose entrances are numbered sequentially by integers from 1 to *n*. Entrance *n* and entrance 1 are adjacent.
Today Vasya got bored and decided to take a walk in the yard. Vasya lives in entrance *a* and he decided that during his walk he will move around the house *b* entrances in th... | The single line of the input contains three space-separated integers *n*, *a* and *b* (1<=≤<=*n*<=≤<=100,<=1<=≤<=*a*<=≤<=*n*,<=<=-<=100<=≤<=*b*<=≤<=100) — the number of entrances at Vasya's place, the number of his entrance and the length of his walk, respectively. | Print a single integer *k* (1<=≤<=*k*<=≤<=*n*) — the number of the entrance where Vasya will be at the end of his walk. | [
"6 2 -5\n",
"5 1 3\n",
"3 2 7\n"
] | [
"3\n",
"4\n",
"3\n"
] | The first example is illustrated by the picture in the statements. | 500 | [
{
"input": "6 2 -5",
"output": "3"
},
{
"input": "5 1 3",
"output": "4"
},
{
"input": "3 2 7",
"output": "3"
},
{
"input": "1 1 0",
"output": "1"
},
{
"input": "1 1 -1",
"output": "1"
},
{
"input": "1 1 1",
"output": "1"
},
{
"input": "100 ... | 1,540,877,902 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 18 | 109 | 0 | str = input().split()
n = int(str[0])
a = int(str[1])
b = int(str[2])
output = 0
if b<0:
print(n+(a+b))
else:
print(a + (b%n))
| Title: Round House
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya lives in a round building, whose entrances are numbered sequentially by integers from 1 to *n*. Entrance *n* and entrance 1 are adjacent.
Today Vasya got bored and decided to take a walk in the yard. Vasya lives in e... | ```python
str = input().split()
n = int(str[0])
a = int(str[1])
b = int(str[2])
output = 0
if b<0:
print(n+(a+b))
else:
print(a + (b%n))
``` | 0 | |
911 | B | Two Cakes | PROGRAMMING | 1,200 | [
"binary search",
"brute force",
"implementation"
] | null | null | It's New Year's Eve soon, so Ivan decided it's high time he started setting the table. Ivan has bought two cakes and cut them into pieces: the first cake has been cut into *a* pieces, and the second one — into *b* pieces.
Ivan knows that there will be *n* people at the celebration (including himself), so Ivan has set ... | The first line contains three integers *n*, *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=100, 2<=≤<=*n*<=≤<=*a*<=+<=*b*) — the number of plates, the number of pieces of the first cake, and the number of pieces of the second cake, respectively. | Print the maximum possible number *x* such that Ivan can distribute the cake in such a way that each plate will contain at least *x* pieces of cake. | [
"5 2 3\n",
"4 7 10\n"
] | [
"1\n",
"3\n"
] | In the first example there is only one way to distribute cakes to plates, all of them will have 1 cake on it.
In the second example you can have two plates with 3 and 4 pieces of the first cake and two plates both with 5 pieces of the second cake. Minimal number of pieces is 3. | 0 | [
{
"input": "5 2 3",
"output": "1"
},
{
"input": "4 7 10",
"output": "3"
},
{
"input": "100 100 100",
"output": "2"
},
{
"input": "10 100 3",
"output": "3"
},
{
"input": "2 9 29",
"output": "9"
},
{
"input": "4 6 10",
"output": "3"
},
{
"inp... | 1,516,388,196 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 6 | 61 | 5,632,000 | N,a,b=map(int,(input().split(" ")))
if(N==(a+b)):
print("1")
elif(a>=(b*N) or (b>=N*a)):
if(a>b):
print(b)
else:
print(a)
else:
if(a>b):
a1=a
b1=b
else:
b1=a
a1=b
i=2
while(i<b+1):
w=int(b1//i)
w1=int(a1//i)
if(w+w1>=(N+N)):
i=i+1
else:
... | Title: Two Cakes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
It's New Year's Eve soon, so Ivan decided it's high time he started setting the table. Ivan has bought two cakes and cut them into pieces: the first cake has been cut into *a* pieces, and the second one — into *b* pieces.
Iv... | ```python
N,a,b=map(int,(input().split(" ")))
if(N==(a+b)):
print("1")
elif(a>=(b*N) or (b>=N*a)):
if(a>b):
print(b)
else:
print(a)
else:
if(a>b):
a1=a
b1=b
else:
b1=a
a1=b
i=2
while(i<b+1):
w=int(b1//i)
w1=int(a1//i)
if(w+w1>=(N+N)):
i=i+1
... | -1 | |
0 | none | none | none | 0 | [
"none"
] | null | null | An atom of element X can exist in *n* distinct states with energies *E*1<=<<=*E*2<=<<=...<=<<=*E**n*. Arkady wants to build a laser on this element, using a three-level scheme. Here is a simplified description of the scheme.
Three distinct states *i*, *j* and *k* are selected, where *i*<=<<=*j*<=<<=*k*... | The first line contains two integers *n* and *U* (3<=≤<=*n*<=≤<=105, 1<=≤<=*U*<=≤<=109) — the number of states and the maximum possible difference between *E**k* and *E**i*.
The second line contains a sequence of integers *E*1,<=*E*2,<=...,<=*E**n* (1<=≤<=*E*1<=<<=*E*2...<=<<=*E**n*<=≤<=109). It is guaranteed th... | If it is not possible to choose three states that satisfy all constraints, print -1.
Otherwise, print one real number η — the maximum possible energy conversion efficiency. Your answer is considered correct its absolute or relative error does not exceed 10<=-<=9.
Formally, let your answer be *a*, and the jury's answe... | [
"4 4\n1 3 5 7\n",
"10 8\n10 13 15 16 17 19 20 22 24 25\n",
"3 1\n2 5 10\n"
] | [
"0.5\n",
"0.875\n",
"-1\n"
] | In the first example choose states 1, 2 and 3, so that the energy conversion efficiency becomes equal to <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/147ae7a830722917b0aa37d064df8eb74cfefb97.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
In the second example choose states 4, 5 a... | 0 | [
{
"input": "4 4\n1 3 5 7",
"output": "0.5"
},
{
"input": "10 8\n10 13 15 16 17 19 20 22 24 25",
"output": "0.875"
},
{
"input": "3 1\n2 5 10",
"output": "-1"
},
{
"input": "5 3\n4 6 8 9 10",
"output": "0.5"
},
{
"input": "10 128\n110 121 140 158 174 188 251 271 27... | 1,545,684,488 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 93 | 0 | n,U=map(int,input().split())
Ar=list(map(int,input().split()))
m1=[]
m2=[]
for i in range(n-1):
p=Ar[i+1]-Ar[i]
m1.append(p)
m2.append(i)
p=[]
p.append(sorted(m1)[0])
M=[]
for x,y in sorted(list(zip(m1,m2))):
if x in p:
p.append(x)
M.append(y)
else:
break
# p... | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
An atom of element X can exist in *n* distinct states with energies *E*1<=<<=*E*2<=<<=...<=<<=*E**n*. Arkady wants to build a laser on this element, using a three-level scheme. Here is a simplified description of the sche... | ```python
n,U=map(int,input().split())
Ar=list(map(int,input().split()))
m1=[]
m2=[]
for i in range(n-1):
p=Ar[i+1]-Ar[i]
m1.append(p)
m2.append(i)
p=[]
p.append(sorted(m1)[0])
M=[]
for x,y in sorted(list(zip(m1,m2))):
if x in p:
p.append(x)
M.append(y)
else:
... | 0 | |
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 | |
161 | A | Dress'em in Vests! | PROGRAMMING | 1,300 | [
"binary search",
"brute force",
"greedy",
"two pointers"
] | null | null | The Two-dimensional kingdom is going through hard times... This morning the Three-Dimensional kingdom declared war on the Two-dimensional one. This (possibly armed) conflict will determine the ultimate owner of the straight line.
The Two-dimensional kingdom has a regular army of *n* people. Each soldier registered him... | The first input line contains four integers *n*, *m*, *x* and *y* (1<=≤<=*n*,<=*m*<=≤<=105, 0<=≤<=*x*,<=*y*<=≤<=109) — the number of soldiers, the number of vests and two numbers that specify the soldiers' unpretentiousness, correspondingly.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i... | In the first line print a single integer *k* — the maximum number of soldiers equipped with bulletproof vests.
In the next *k* lines print *k* pairs, one pair per line, as "*u**i* *v**i*" (without the quotes). Pair (*u**i*, *v**i*) means that soldier number *u**i* must wear vest number *v**i*. Soldiers and vests are ... | [
"5 3 0 0\n1 2 3 3 4\n1 3 5\n",
"3 3 2 2\n1 5 9\n3 5 7\n"
] | [
"2\n1 1\n3 2\n",
"3\n1 1\n2 2\n3 3\n"
] | In the first sample you need the vests' sizes to match perfectly: the first soldier gets the first vest (size 1), the third soldier gets the second vest (size 3). This sample allows another answer, which gives the second vest to the fourth soldier instead of the third one.
In the second sample the vest size can differ... | 1,000 | [
{
"input": "5 3 0 0\n1 2 3 3 4\n1 3 5",
"output": "2\n1 1\n3 2"
},
{
"input": "3 3 2 2\n1 5 9\n3 5 7",
"output": "3\n1 1\n2 2\n3 3"
},
{
"input": "1 1 0 0\n1\n1",
"output": "1\n1 1"
},
{
"input": "1 1 0 0\n1\n2",
"output": "0"
},
{
"input": "2 3 1 4\n1 5\n1 2 2",
... | 1,613,751,481 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 5 | 92 | 307,200 | n , m, x, y= map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = []
for i in range(n):
C.append([0,0])
l = 0
r = 0
j = 0
k = 0
while r != m and l != n:
if (B[r] >= A[l]-x) and (B[r] <= A[l]+y):
C[j][0] = l + 1
C[j][1] = r + 1... | Title: Dress'em in Vests!
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Two-dimensional kingdom is going through hard times... This morning the Three-Dimensional kingdom declared war on the Two-dimensional one. This (possibly armed) conflict will determine the ultimate owner of the s... | ```python
n , m, x, y= map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = []
for i in range(n):
C.append([0,0])
l = 0
r = 0
j = 0
k = 0
while r != m and l != n:
if (B[r] >= A[l]-x) and (B[r] <= A[l]+y):
C[j][0] = l + 1
C[j][... | 0 | |
922 | B | Magic Forest | PROGRAMMING | 1,300 | [
"brute force"
] | null | null | Imp is in a magic forest, where xorangles grow (wut?)
A xorangle of order *n* is such a non-degenerate triangle, that lengths of its sides are integers not exceeding *n*, and the xor-sum of the lengths is equal to zero. Imp has to count the number of distinct xorangles of order *n* to get out of the forest.
Formally... | The only line contains a single integer *n* (1<=≤<=*n*<=≤<=2500). | Print the number of xorangles of order *n*. | [
"6\n",
"10\n"
] | [
"1\n",
"2\n"
] | The only xorangle in the first sample is (3, 5, 6). | 1,000 | [
{
"input": "6",
"output": "1"
},
{
"input": "10",
"output": "2"
},
{
"input": "3",
"output": "0"
},
{
"input": "4",
"output": "0"
},
{
"input": "5",
"output": "0"
},
{
"input": "2500",
"output": "700393"
},
{
"input": "952",
"output": "... | 1,619,692,668 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 4 | 78 | 0 | n = int(input())
print(n//5)
| Title: Magic Forest
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Imp is in a magic forest, where xorangles grow (wut?)
A xorangle of order *n* is such a non-degenerate triangle, that lengths of its sides are integers not exceeding *n*, and the xor-sum of the lengths is equal to zero. I... | ```python
n = int(input())
print(n//5)
``` | 0 | |
6 | B | President's Office | PROGRAMMING | 1,100 | [
"implementation"
] | B. President's Office | 2 | 64 | President of Berland has a very vast office-room, where, apart from him, work his subordinates. Each subordinate, as well as President himself, has his own desk of a unique colour. Each desk is rectangular, and its sides are parallel to the office walls. One day President decided to establish an assembly, of which all ... | The first line contains two separated by a space integer numbers *n*, *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the length and the width of the office-room, and *c* character — the President's desk colour. The following *n* lines contain *m* characters each — the office-room description. It is guaranteed that the colour of each ... | Print the only number — the amount of President's deputies. | [
"3 4 R\nG.B.\n.RR.\nTTT.\n",
"3 3 Z\n...\n.H.\n..Z\n"
] | [
"2\n",
"0\n"
] | none | 0 | [
{
"input": "3 4 R\nG.B.\n.RR.\nTTT.",
"output": "2"
},
{
"input": "3 3 Z\n...\n.H.\n..Z",
"output": "0"
},
{
"input": "1 1 C\nC",
"output": "0"
},
{
"input": "2 2 W\nKW\nKW",
"output": "1"
},
{
"input": "1 10 H\n....DDHHHH",
"output": "1"
},
{
"input":... | 1,677,354,478 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 8 | 61 | 0 | l = input().split()
n,m,c = int(l[0]),int(l[1]),l[2]
l = []
row,column=[],[]
letters = [c]
count = 0
for i in range(n):
s = input()
if c in s:
row.append(i)
for j in range(m):
if s[j]==c:
column.append(j)
l.append(s)
for i in range(n):
for j in ... | Title: President's Office
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
President of Berland has a very vast office-room, where, apart from him, work his subordinates. Each subordinate, as well as President himself, has his own desk of a unique colour. Each desk is rectangular, and its sides ... | ```python
l = input().split()
n,m,c = int(l[0]),int(l[1]),l[2]
l = []
row,column=[],[]
letters = [c]
count = 0
for i in range(n):
s = input()
if c in s:
row.append(i)
for j in range(m):
if s[j]==c:
column.append(j)
l.append(s)
for i in range(n):
... | 0 |
253 | E | Printer | PROGRAMMING | 2,200 | [
"binary search",
"data structures",
"implementation",
"sortings"
] | null | null | Let's consider a network printer that functions like that. It starts working at time 0. In each second it can print one page of a text. At some moments of time the printer receives printing tasks. We know that a printer received *n* tasks. Let's number the tasks by consecutive integers from 1 to *n*. Then the task numb... | The first line contains integer *n* (1<=≤<=*n*<=≤<=50000). Next *n* lines describe the tasks. The *i*-th of these lines contains three integers *t**i*, *s**i* and *p**i*, separated by single spaces (0<=≤<=*t**i*<=≤<=109,<=1<=≤<=*s**i*,<=*p**i*<=≤<=109). Exactly one task (let's assume that his number is *x*) has number ... | In the first line print integer *p**x* — the priority of the task number *x* (1<=≤<=*p**x*<=≤<=109, remember that all priorities should be distinct). Then print *n* integers, the *i*-th of them represents the moment of time when the last page of the task number *i* finished printing.
It is guaranteed that at least on... | [
"3\n4 3 -1\n0 2 2\n1 3 3\n7\n",
"3\n3 1 2\n2 3 3\n3 1 -1\n4\n"
] | [
"4\n7 8 4\n",
"4\n7 6 4\n"
] | Let's consider the first test case. Let's assume that the unknown priority equals 4, then the printer's actions for each second are as follows:
- the beginning of the 1-st second (time 0). The queue has task 2. The printer prints the first page of this task; - the beginning of the 2-nd second (time 1). The queue has... | 2,500 | [] | 1,691,770,369 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 92 | 0 | print("_RANDOM_GUESS_1691770369.3821852")# 1691770369.382202 | Title: Printer
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Let's consider a network printer that functions like that. It starts working at time 0. In each second it can print one page of a text. At some moments of time the printer receives printing tasks. We know that a printer receive... | ```python
print("_RANDOM_GUESS_1691770369.3821852")# 1691770369.382202
``` | 0 | |
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,641,251,729 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 60 | 0 | numCount = int(input())
nums = [int(num) for num in input()]
first_2_same = False
evenness = False
sum_of_first_2 = nums[0] + nums[1]
sum_of_first_3 = sum_of_first_2 + nums[2]
if (sum_of_first_2 % 2 == 0):
if (nums[0] % 2 == 0):
evenness = True
else:
if (sum_of_first_3 % 2 == 1):
even... | 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
numCount = int(input())
nums = [int(num) for num in input()]
first_2_same = False
evenness = False
sum_of_first_2 = nums[0] + nums[1]
sum_of_first_3 = sum_of_first_2 + nums[2]
if (sum_of_first_2 % 2 == 0):
if (nums[0] % 2 == 0):
evenness = True
else:
if (sum_of_first_3 % 2 == 1):
... | -1 |
50 | A | Domino piling | PROGRAMMING | 800 | [
"greedy",
"math"
] | A. Domino piling | 2 | 256 | You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions:
1. Each domino completely covers ... | In a single line you are given two integers *M* and *N* — board sizes in squares (1<=≤<=*M*<=≤<=*N*<=≤<=16). | Output one number — the maximal number of dominoes, which can be placed. | [
"2 4\n",
"3 3\n"
] | [
"4\n",
"4\n"
] | none | 500 | [
{
"input": "2 4",
"output": "4"
},
{
"input": "3 3",
"output": "4"
},
{
"input": "1 5",
"output": "2"
},
{
"input": "1 6",
"output": "3"
},
{
"input": "1 15",
"output": "7"
},
{
"input": "1 16",
"output": "8"
},
{
"input": "2 5",
"outpu... | 1,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 |
839 | C | Journey | PROGRAMMING | 1,500 | [
"dfs and similar",
"dp",
"graphs",
"probabilities",
"trees"
] | null | null | There are *n* cities and *n*<=-<=1 roads in the Seven Kingdoms, each road connects two cities and we can reach any city from any other by the roads.
Theon and Yara Greyjoy are on a horse in the first city, they are starting traveling through the roads. But the weather is foggy, so they can’t see where the horse brings... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100000) — number of cities.
Then *n*<=-<=1 lines follow. The *i*-th line of these lines contains two integers *u**i* and *v**i* (1<=≤<=*u**i*,<=*v**i*<=≤<=*n*, *u**i*<=≠<=*v**i*) — the cities connected by the *i*-th road.
It is guaranteed that one can reach ... | Print a number — the expected length of their journey. The journey starts in the city 1.
Your answer will be considered correct if its absolute or relative error does not exceed 10<=-<=6.
Namely: let's assume that your answer is *a*, and the answer of the jury is *b*. The checker program will consider your answer cor... | [
"4\n1 2\n1 3\n2 4\n",
"5\n1 2\n1 3\n3 4\n2 5\n"
] | [
"1.500000000000000\n",
"2.000000000000000\n"
] | In the first sample, their journey may end in cities 3 or 4 with equal probability. The distance to city 3 is 1 and to city 4 is 2, so the expected length is 1.5.
In the second sample, their journey may end in city 4 or 5. The distance to the both cities is 2, so the expected length is 2. | 1,500 | [
{
"input": "4\n1 2\n1 3\n2 4",
"output": "1.500000000000000"
},
{
"input": "5\n1 2\n1 3\n3 4\n2 5",
"output": "2.000000000000000"
},
{
"input": "70\n1 25\n57 1\n18 1\n65 1\n38 1\n1 41\n1 5\n1 69\n1 3\n31 1\n1 8\n1 9\n53 1\n70 1\n45 1\n1 24\n1 42\n1 30\n1 12\n1 37\n64 1\n1 28\n1 58\n1 22\... | 1,627,590,368 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 61 | 7,065,600 | from sys import stdin , stdout
input = stdin.buffer.readline
import collections
n = int(input())
tree = collections.defaultdict(list)
for _ in range(n - 1) :
u , v = map(int , input().split())
u -= 1
v -= 1
tree[u].append(v)
tree[v].append(u)
queue = collections.deque()
queue.ap... | Title: Journey
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* cities and *n*<=-<=1 roads in the Seven Kingdoms, each road connects two cities and we can reach any city from any other by the roads.
Theon and Yara Greyjoy are on a horse in the first city, they are starting tr... | ```python
from sys import stdin , stdout
input = stdin.buffer.readline
import collections
n = int(input())
tree = collections.defaultdict(list)
for _ in range(n - 1) :
u , v = map(int , input().split())
u -= 1
v -= 1
tree[u].append(v)
tree[v].append(u)
queue = collections.deque()... | 0 | |
352 | A | Jeff and Digits | PROGRAMMING | 1,000 | [
"brute force",
"implementation",
"math"
] | null | null | Jeff's got *n* cards, each card contains either digit 0, or digit 5. Jeff can choose several cards and put them in a line so that he gets some number. What is the largest possible number divisible by 90 Jeff can make from the cards he's got?
Jeff must make the number without leading zero. At that, we assume that numbe... | The first line contains integer *n* (1<=≤<=*n*<=≤<=103). The next line contains *n* integers *a*1, *a*2, ..., *a**n* (*a**i*<==<=0 or *a**i*<==<=5). Number *a**i* represents the digit that is written on the *i*-th card. | In a single line print the answer to the problem — the maximum number, divisible by 90. If you can't make any divisible by 90 number from the cards, print -1. | [
"4\n5 0 5 0\n",
"11\n5 5 5 5 5 5 5 5 0 5 5\n"
] | [
"0\n",
"5555555550\n"
] | In the first test you can make only one number that is a multiple of 90 — 0.
In the second test you can make number 5555555550, it is a multiple of 90. | 500 | [
{
"input": "4\n5 0 5 0",
"output": "0"
},
{
"input": "11\n5 5 5 5 5 5 5 5 0 5 5",
"output": "5555555550"
},
{
"input": "7\n5 5 5 5 5 5 5",
"output": "-1"
},
{
"input": "1\n5",
"output": "-1"
},
{
"input": "1\n0",
"output": "0"
},
{
"input": "11\n5 0 5 ... | 1,698,171,760 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 2 | 62 | 0 | n = int(input())
data = list(map(int, input().split()))
ans = ((data.count(5)//9)*9) * "5" + data.count(0) * "0"
print(int(ans)) | Title: Jeff and Digits
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Jeff's got *n* cards, each card contains either digit 0, or digit 5. Jeff can choose several cards and put them in a line so that he gets some number. What is the largest possible number divisible by 90 Jeff can make fr... | ```python
n = int(input())
data = list(map(int, input().split()))
ans = ((data.count(5)//9)*9) * "5" + data.count(0) * "0"
print(int(ans))
``` | -1 | |
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 | |
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,646,875,029 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 49 | 92 | 512,000 | n, m = map(int, input().strip().split())
adj = {i + 1: set() for i in range(n)}
for _ in range(m):
x, y = map(int, input().strip().split())
adj[x].add(y)
adj[y].add(x)
look = set()
for k, v in adj.items():
if len(v) == 1:
look.add(k)
i = 0
while len(look) > 0:
increment = False
next_l... | 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
n, m = map(int, input().strip().split())
adj = {i + 1: set() for i in range(n)}
for _ in range(m):
x, y = map(int, input().strip().split())
adj[x].add(y)
adj[y].add(x)
look = set()
for k, v in adj.items():
if len(v) == 1:
look.add(k)
i = 0
while len(look) > 0:
increment = False
... | 0 | |
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 | |
219 | A | k-String | PROGRAMMING | 1,000 | [
"implementation",
"strings"
] | null | null | A string is called a *k*-string if it can be represented as *k* concatenated copies of some string. For example, the string "aabaabaabaab" is at the same time a 1-string, a 2-string and a 4-string, but it is not a 3-string, a 5-string, or a 6-string and so on. Obviously any string is a 1-string.
You are given a string... | The first input line contains integer *k* (1<=≤<=*k*<=≤<=1000). The second line contains *s*, all characters in *s* are lowercase English letters. The string length *s* satisfies the inequality 1<=≤<=|*s*|<=≤<=1000, where |*s*| is the length of string *s*. | Rearrange the letters in string *s* in such a way that the result is a *k*-string. Print the result on a single output line. If there are multiple solutions, print any of them.
If the solution doesn't exist, print "-1" (without quotes). | [
"2\naazz\n",
"3\nabcabcabz\n"
] | [
"azaz\n",
"-1\n"
] | none | 500 | [
{
"input": "2\naazz",
"output": "azaz"
},
{
"input": "3\nabcabcabz",
"output": "-1"
},
{
"input": "1\na",
"output": "a"
},
{
"input": "2\nabba",
"output": "abab"
},
{
"input": "2\naaab",
"output": "-1"
},
{
"input": "7\nabacaba",
"output": "-1"
}... | 1,626,264,034 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 122 | 7,065,600 | from collections import Counter
n = int(input())
s = Counter(input())
p = True
for i in s:
if s[i]%n:
p = False
else:
s[i] = s[i]//n
ans = ''.join(i*e for i,e in s.items())
print(ans*n) | Title: k-String
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A string is called a *k*-string if it can be represented as *k* concatenated copies of some string. For example, the string "aabaabaabaab" is at the same time a 1-string, a 2-string and a 4-string, but it is not a 3-string, a ... | ```python
from collections import Counter
n = int(input())
s = Counter(input())
p = True
for i in s:
if s[i]%n:
p = False
else:
s[i] = s[i]//n
ans = ''.join(i*e for i,e in s.items())
print(ans*n)
``` | 0 | |
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,099,754 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 46 | 5,529,600 | import math
a = list(map(int, input().split()))
d = a[0]/a[1]
d = d*(10)
d = str(d)
for i in range(0, len(d)):
if d[i]==a[2]:
break
if str(a[2]) not in d:
print("-1")
else:
print(i) | 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
import math
a = list(map(int, input().split()))
d = a[0]/a[1]
d = d*(10)
d = str(d)
for i in range(0, len(d)):
if d[i]==a[2]:
break
if str(a[2]) not in d:
print("-1")
else:
print(i)
``` | 0 | |
53 | A | Autocomplete | PROGRAMMING | 1,100 | [
"implementation"
] | A. Autocomplete | 2 | 256 | Autocomplete is a program function that enables inputting the text (in editors, command line shells, browsers etc.) completing the text by its inputted part. Vasya is busy working on a new browser called 'BERowser'. He happens to be working on the autocomplete function in the address line at this very moment. A list co... | The first line contains the *s* line which is the inputted part. The second line contains an integer *n* (1<=≤<=*n*<=≤<=100) which is the number of visited pages. Then follow *n* lines which are the visited pages, one on each line. All the lines have lengths of from 1 to 100 symbols inclusively and consist of lowercase... | If *s* is not the beginning of any of *n* addresses of the visited pages, print *s*. Otherwise, print the lexicographically minimal address of one of the visited pages starting from *s*.
The lexicographical order is the order of words in a dictionary. The lexicographical comparison of lines is realized by the '<' o... | [
"next\n2\nnextpermutation\nnextelement\n",
"find\n4\nfind\nfindfirstof\nfindit\nfand\n",
"find\n4\nfondfind\nfondfirstof\nfondit\nfand\n"
] | [
"nextelement\n",
"find\n",
"find\n"
] | none | 500 | [
{
"input": "next\n2\nnextpermutation\nnextelement",
"output": "nextelement"
},
{
"input": "find\n4\nfind\nfindfirstof\nfindit\nfand",
"output": "find"
},
{
"input": "find\n4\nfondfind\nfondfirstof\nfondit\nfand",
"output": "find"
},
{
"input": "kudljmxcse\n4\nkudljmxcse\nszje... | 1,604,086,951 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 15 | 280 | 0 | s = input()
res = float('inf')
flag = 0
for j in range(int(input())):
k = input()
if((k.find(s)!=-1) and (k.find(s)==0)):
l = len(k)
if(l<=res):
res = l
s1 = k
flag = 1
if((k==s) or (k.find(s)==-1 and flag == 0) ):
s1=s
print(s1)
| Title: Autocomplete
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Autocomplete is a program function that enables inputting the text (in editors, command line shells, browsers etc.) completing the text by its inputted part. Vasya is busy working on a new browser called 'BERowser'. He happens... | ```python
s = input()
res = float('inf')
flag = 0
for j in range(int(input())):
k = input()
if((k.find(s)!=-1) and (k.find(s)==0)):
l = len(k)
if(l<=res):
res = l
s1 = k
flag = 1
if((k==s) or (k.find(s)==-1 and flag == 0) ):
s1=s
print(s1)
``` | 0 |
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 |
0 | none | none | none | 0 | [
"none"
] | null | null | There are *n* phone numbers in Polycarp's contacts on his phone. Each number is a 9-digit integer, starting with a digit different from 0. All the numbers are distinct.
There is the latest version of Berdroid OS installed on Polycarp's phone. If some number is entered, is shows up all the numbers in the contacts for w... | The first line contains single integer *n* (1<=≤<=*n*<=≤<=70000) — the total number of phone contacts in Polycarp's contacts.
The phone numbers follow, one in each line. Each number is a positive 9-digit integer starting with a digit from 1 to 9. All the numbers are distinct. | Print exactly *n* lines: the *i*-th of them should contain the shortest non-empty sequence of digits, such that if Polycarp enters it, the Berdroid OS shows up only the *i*-th number from the contacts. If there are several such sequences, print any of them. | [
"3\n123456789\n100000000\n100123456\n",
"4\n123456789\n193456789\n134567819\n934567891\n"
] | [
"9\n000\n01\n",
"2\n193\n81\n91\n"
] | none | 0 | [
{
"input": "3\n123456789\n100000000\n100123456",
"output": "9\n000\n01"
},
{
"input": "4\n123456789\n193456789\n134567819\n934567891",
"output": "2\n193\n81\n91"
},
{
"input": "1\n167038488",
"output": "4"
},
{
"input": "5\n115830748\n403459907\n556271610\n430358099\n41396141... | 1,644,480,834 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 15 | 0 | n = int(input())
mapp = {}
for i in range(n):
str = input()
mapp[str] = i
for a in range(9):
for l in range(9):
if l+a>9:
break
sub = str[a:l]
if sub in mapp and mapp[sub]!=i:
mapp[sub] = -1
elif sub not in mapp:
... | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* phone numbers in Polycarp's contacts on his phone. Each number is a 9-digit integer, starting with a digit different from 0. All the numbers are distinct.
There is the latest version of Berdroid OS installed on Poly... | ```python
n = int(input())
mapp = {}
for i in range(n):
str = input()
mapp[str] = i
for a in range(9):
for l in range(9):
if l+a>9:
break
sub = str[a:l]
if sub in mapp and mapp[sub]!=i:
mapp[sub] = -1
elif sub not in map... | 0 |
Subsets and Splits
Successful Python Submissions
Retrieves all records from the train dataset where the verdict is 'OK', providing basic filtering but limited analytical value.
SQL Console for MatrixStudio/Codeforces-Python-Submissions
Retrieves records of users with a rating of 1600 or higher and a verdict of 'OK', providing basic filtering but limited analytical value.
SQL Console for MatrixStudio/Codeforces-Python-Submissions
Counts the number of entries with a rating above 2000 and a verdict of 'OK', providing basic filtering but limited analytical value.
SQL Console for MatrixStudio/Codeforces-Python-Submissions
Counts the number of entries with a 'OK' verdict, providing a basic overview of a specific category within the dataset.