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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
151 | A | Soft Drinking | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | This winter is so cold in Nvodsk! A group of *n* friends decided to buy *k* bottles of a soft drink called "Take-It-Light" to warm up a bit. Each bottle has *l* milliliters of the drink. Also they bought *c* limes and cut each of them into *d* slices. After that they found *p* grams of salt.
To make a toast, each frie... | The first and only line contains positive integers *n*, *k*, *l*, *c*, *d*, *p*, *nl*, *np*, not exceeding 1000 and no less than 1. The numbers are separated by exactly one space. | Print a single integer — the number of toasts each friend can make. | [
"3 4 5 10 8 100 3 1\n",
"5 100 10 1 19 90 4 3\n",
"10 1000 1000 25 23 1 50 1\n"
] | [
"2\n",
"3\n",
"0\n"
] | A comment to the first sample:
Overall the friends have 4 * 5 = 20 milliliters of the drink, it is enough to make 20 / 3 = 6 toasts. The limes are enough for 10 * 8 = 80 toasts and the salt is enough for 100 / 1 = 100 toasts. However, there are 3 friends in the group, so the answer is *min*(6, 80, 100) / 3 = 2. | 500 | [
{
"input": "3 4 5 10 8 100 3 1",
"output": "2"
},
{
"input": "5 100 10 1 19 90 4 3",
"output": "3"
},
{
"input": "10 1000 1000 25 23 1 50 1",
"output": "0"
},
{
"input": "1 7 4 5 5 8 3 2",
"output": "4"
},
{
"input": "2 3 3 5 5 10 1 3",
"output": "1"
},
{
... | 1,673,776,078 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 62 | 0 | n,k,l,c,d,p,nl,np=map(int,input().split())
t1=(k*l)//n
limes=c*d
salt=p//np
print((min(t1,limes,salt))//3)
| Title: Soft Drinking
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
This winter is so cold in Nvodsk! A group of *n* friends decided to buy *k* bottles of a soft drink called "Take-It-Light" to warm up a bit. Each bottle has *l* milliliters of the drink. Also they bought *c* limes and cut... | ```python
n,k,l,c,d,p,nl,np=map(int,input().split())
t1=(k*l)//n
limes=c*d
salt=p//np
print((min(t1,limes,salt))//3)
``` | 0 | |
322 | B | Ciel and Flowers | PROGRAMMING | 1,600 | [
"combinatorics",
"math"
] | null | null | Fox Ciel has some flowers: *r* red flowers, *g* green flowers and *b* blue flowers. She wants to use these flowers to make several bouquets. There are 4 types of bouquets:
- To make a "red bouquet", it needs 3 red flowers. - To make a "green bouquet", it needs 3 green flowers. - To make a "blue bouquet", it needs 3... | The first line contains three integers *r*, *g* and *b* (0<=≤<=*r*,<=*g*,<=*b*<=≤<=109) — the number of red, green and blue flowers. | Print the maximal number of bouquets Fox Ciel can make. | [
"3 6 9\n",
"4 4 4\n",
"0 0 0\n"
] | [
"6\n",
"4\n",
"0\n"
] | In test case 1, we can make 1 red bouquet, 2 green bouquets and 3 blue bouquets.
In test case 2, we can make 1 red, 1 green, 1 blue and 1 mixing bouquet. | 1,000 | [
{
"input": "3 6 9",
"output": "6"
},
{
"input": "4 4 4",
"output": "4"
},
{
"input": "0 0 0",
"output": "0"
},
{
"input": "0 3 6",
"output": "3"
},
{
"input": "7 8 9",
"output": "7"
},
{
"input": "8 8 9",
"output": "8"
},
{
"input": "15 3 9... | 1,586,519,765 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 5 | 218 | 0 | r,g,b=[*map(int,input().split())]
ans=0
ans+=(r//3)
r-=(r//3)*3
ans+=(g//3)
g-=(g//3)*3
ans+=(b//3)
b-=(b//3)*3
count=min(r,b,g)
print(count+ans) | Title: Ciel and Flowers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Fox Ciel has some flowers: *r* red flowers, *g* green flowers and *b* blue flowers. She wants to use these flowers to make several bouquets. There are 4 types of bouquets:
- To make a "red bouquet", it needs 3 red fl... | ```python
r,g,b=[*map(int,input().split())]
ans=0
ans+=(r//3)
r-=(r//3)*3
ans+=(g//3)
g-=(g//3)*3
ans+=(b//3)
b-=(b//3)*3
count=min(r,b,g)
print(count+ans)
``` | 0 | |
1,009 | C | Annoying Present | PROGRAMMING | 1,700 | [
"greedy",
"math"
] | null | null | Alice got an array of length $n$ as a birthday present once again! This is the third year in a row!
And what is more disappointing, it is overwhelmengly boring, filled entirely with zeros. Bob decided to apply some changes to the array to cheer up Alice.
Bob has chosen $m$ changes of the following form. For some int... | The first line contains two integers $n$ and $m$ ($1 \le n, m \le 10^5$) — the number of elements of the array and the number of changes.
Each of the next $m$ lines contains two integers $x_i$ and $d_i$ ($-10^3 \le x_i, d_i \le 10^3$) — the parameters for the $i$-th change. | Print the maximal average arithmetic mean of the elements Bob can achieve.
Your answer is considered correct if its absolute or relative error doesn't exceed $10^{-6}$. | [
"2 3\n-1 3\n0 0\n-1 -4\n",
"3 2\n0 2\n5 0\n"
] | [
"-2.500000000000000\n",
"7.000000000000000\n"
] | none | 0 | [
{
"input": "2 3\n-1 3\n0 0\n-1 -4",
"output": "-2.500000000000000"
},
{
"input": "3 2\n0 2\n5 0",
"output": "7.000000000000000"
},
{
"input": "8 8\n-21 -60\n-96 -10\n-4 -19\n-27 -4\n57 -15\n-95 62\n-42 1\n-17 64",
"output": "-16.500000000000000"
},
{
"input": "1 1\n0 0",
... | 1,567,298,693 | 2,147,483,647 | PyPy 3 | OK | TESTS | 54 | 935 | 7,782,400 | import math
def main():
n,m = map(int,input().split())
total = 0
for i in range(m):
x,d = map(int,input().split())
if d >= 0:
total += (d*n*(n-1)//2)
else:
n1 = math.floor((n-1)/2)
n2 = math.ceil((n-1)/2)
total += (d*n1*(... | Title: Annoying Present
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Alice got an array of length $n$ as a birthday present once again! This is the third year in a row!
And what is more disappointing, it is overwhelmengly boring, filled entirely with zeros. Bob decided to apply some c... | ```python
import math
def main():
n,m = map(int,input().split())
total = 0
for i in range(m):
x,d = map(int,input().split())
if d >= 0:
total += (d*n*(n-1)//2)
else:
n1 = math.floor((n-1)/2)
n2 = math.ceil((n-1)/2)
total ... | 3 | |
485 | B | Valuable Resources | PROGRAMMING | 1,300 | [
"brute force",
"greedy"
] | null | null | Many computer strategy games require building cities, recruiting army, conquering tribes, collecting resources. Sometimes it leads to interesting problems.
Let's suppose that your task is to build a square city. The world map uses the Cartesian coordinates. The sides of the city should be parallel to coordinate axes.... | The first line of the input contains number *n* — the number of mines on the map (2<=≤<=*n*<=≤<=1000). Each of the next *n* lines contains a pair of integers *x**i* and *y**i* — the coordinates of the corresponding mine (<=-<=109<=≤<=*x**i*,<=*y**i*<=≤<=109). All points are pairwise distinct. | Print the minimum area of the city that can cover all the mines with valuable resources. | [
"2\n0 0\n2 2\n",
"2\n0 0\n0 3\n"
] | [
"4\n",
"9\n"
] | none | 500 | [
{
"input": "2\n0 0\n2 2",
"output": "4"
},
{
"input": "2\n0 0\n0 3",
"output": "9"
},
{
"input": "2\n0 1\n1 0",
"output": "1"
},
{
"input": "3\n2 2\n1 1\n3 3",
"output": "4"
},
{
"input": "3\n3 1\n1 3\n2 2",
"output": "4"
},
{
"input": "3\n0 1\n1 0\n2 ... | 1,646,942,069 | 2,147,483,647 | PyPy 3-64 | RUNTIME_ERROR | TESTS | 0 | 62 | 3,379,200 | t=int(input())
for i in range(t):
n=int(input())
if n>19:
print("NO",end="")
else:
print("YES")
for i in range(0,n):
print(3**i,end=" ")
print()
| Title: Valuable Resources
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Many computer strategy games require building cities, recruiting army, conquering tribes, collecting resources. Sometimes it leads to interesting problems.
Let's suppose that your task is to build a square city. Th... | ```python
t=int(input())
for i in range(t):
n=int(input())
if n>19:
print("NO",end="")
else:
print("YES")
for i in range(0,n):
print(3**i,end=" ")
print()
``` | -1 | |
292 | B | Network Topology | PROGRAMMING | 1,200 | [
"graphs",
"implementation"
] | null | null | This problem uses a simplified network topology model, please read the problem statement carefully and use it as a formal document as you develop the solution.
Polycarpus continues working as a system administrator in a large corporation. The computer network of this corporation consists of *n* computers, some of them... | The first line contains two space-separated integers *n* and *m* (4<=≤<=*n*<=≤<=105; 3<=≤<=*m*<=≤<=105) — the number of nodes and edges in the graph, correspondingly. Next *m* lines contain the description of the graph's edges. The *i*-th line contains a space-separated pair of integers *x**i*, *y**i* (1<=≤<=*x**i*,<=*... | In a single line print the network topology name of the given graph. If the answer is the bus, print "bus topology" (without the quotes), if the answer is the ring, print "ring topology" (without the quotes), if the answer is the star, print "star topology" (without the quotes). If no answer fits, print "unknown topolo... | [
"4 3\n1 2\n2 3\n3 4\n",
"4 4\n1 2\n2 3\n3 4\n4 1\n",
"4 3\n1 2\n1 3\n1 4\n",
"4 4\n1 2\n2 3\n3 1\n1 4\n"
] | [
"bus topology\n",
"ring topology\n",
"star topology\n",
"unknown topology\n"
] | none | 1,000 | [
{
"input": "4 3\n1 2\n2 3\n3 4",
"output": "bus topology"
},
{
"input": "4 4\n1 2\n2 3\n3 4\n4 1",
"output": "ring topology"
},
{
"input": "4 3\n1 2\n1 3\n1 4",
"output": "star topology"
},
{
"input": "4 4\n1 2\n2 3\n3 1\n1 4",
"output": "unknown topology"
},
{
"i... | 1,689,344,021 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 19 | 92 | 0 | n, m = map(int, input().split())
degree = [0] * n
for i in range(m):
u, v = map(int, input().split())
u -= 1; v -= 1
degree[u] += 1
degree[v] += 1
c1 = degree.count(1)
c2 = degree.count(2)
if c2 == n:
print("ring topology")
elif c1 == 2:
print("bus topology")
elif c1 == n - 1:
... | Title: Network Topology
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
This problem uses a simplified network topology model, please read the problem statement carefully and use it as a formal document as you develop the solution.
Polycarpus continues working as a system administrator in... | ```python
n, m = map(int, input().split())
degree = [0] * n
for i in range(m):
u, v = map(int, input().split())
u -= 1; v -= 1
degree[u] += 1
degree[v] += 1
c1 = degree.count(1)
c2 = degree.count(2)
if c2 == n:
print("ring topology")
elif c1 == 2:
print("bus topology")
elif c1 == ... | 0 | |
246 | B | Increase and Decrease | PROGRAMMING | 1,300 | [
"greedy",
"math"
] | null | null | Polycarpus has an array, consisting of *n* integers *a*1,<=*a*2,<=...,<=*a**n*. Polycarpus likes it when numbers in an array match. That's why he wants the array to have as many equal numbers as possible. For that Polycarpus performs the following operation multiple times:
- he chooses two elements of the array *a**i... | The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the array size. The second line contains space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (|*a**i*|<=≤<=104) — the original array. | Print a single integer — the maximum number of equal array elements he can get if he performs an arbitrary number of the given operation. | [
"2\n2 1\n",
"3\n1 4 1\n"
] | [
"1\n",
"3\n"
] | none | 1,000 | [
{
"input": "2\n2 1",
"output": "1"
},
{
"input": "3\n1 4 1",
"output": "3"
},
{
"input": "4\n2 -7 -2 -6",
"output": "3"
},
{
"input": "4\n2 0 -2 -1",
"output": "3"
},
{
"input": "6\n-1 1 0 0 -1 -1",
"output": "5"
},
{
"input": "5\n0 0 0 0 0",
"outp... | 1,694,725,961 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 62 | 0 | n=int(input())
a=list(map(int,input().split()))
j=sum(a)//n
man=[]
mos=[]
m=0
for i in range(0,len(a)) :
if j-a[i]<0 :
man.append(abs(j-a[i]))
else :
mos.append(j-a[i])
m+=j-a[i]
o=0
man.sort()
for i in range(0,len(man)) :
if m-man[i]>=0 :
o+=1
m-=man... | Title: Increase and Decrease
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarpus has an array, consisting of *n* integers *a*1,<=*a*2,<=...,<=*a**n*. Polycarpus likes it when numbers in an array match. That's why he wants the array to have as many equal numbers as possible. For that... | ```python
n=int(input())
a=list(map(int,input().split()))
j=sum(a)//n
man=[]
mos=[]
m=0
for i in range(0,len(a)) :
if j-a[i]<0 :
man.append(abs(j-a[i]))
else :
mos.append(j-a[i])
m+=j-a[i]
o=0
man.sort()
for i in range(0,len(man)) :
if m-man[i]>=0 :
o+=1
... | 0 | |
914 | A | Perfect Squares | PROGRAMMING | 900 | [
"brute force",
"implementation",
"math"
] | null | null | Given an array *a*1,<=*a*2,<=...,<=*a**n* of *n* integers, find the largest number in the array that is not a perfect square.
A number *x* is said to be a perfect square if there exists an integer *y* such that *x*<==<=*y*2. | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of elements in the array.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (<=-<=106<=≤<=*a**i*<=≤<=106) — the elements of the array.
It is guaranteed that at least one element of the array is not a perfect square. | Print the largest number in the array which is not a perfect square. It is guaranteed that an answer always exists. | [
"2\n4 2\n",
"8\n1 2 4 8 16 32 64 576\n"
] | [
"2\n",
"32\n"
] | In the first sample case, 4 is a perfect square, so the largest number in the array that is not a perfect square is 2. | 500 | [
{
"input": "2\n4 2",
"output": "2"
},
{
"input": "8\n1 2 4 8 16 32 64 576",
"output": "32"
},
{
"input": "3\n-1 -4 -9",
"output": "-1"
},
{
"input": "5\n918375 169764 598796 76602 538757",
"output": "918375"
},
{
"input": "5\n804610 765625 2916 381050 93025",
... | 1,682,091,466 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 2 | 31 | 0 |
from math import sqrt
number = int(input())
l = list(map(int , input().split()))
res= []
for i in l:
x=sqrt(i)
if x - int(x) != 0 :
res.append(i)
print(res[-1])
| Title: Perfect Squares
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Given an array *a*1,<=*a*2,<=...,<=*a**n* of *n* integers, find the largest number in the array that is not a perfect square.
A number *x* is said to be a perfect square if there exists an integer *y* such that *x*<==<... | ```python
from math import sqrt
number = int(input())
l = list(map(int , input().split()))
res= []
for i in l:
x=sqrt(i)
if x - int(x) != 0 :
res.append(i)
print(res[-1])
``` | -1 | |
160 | A | Twins | PROGRAMMING | 900 | [
"greedy",
"sortings"
] | null | null | Imagine that you have a twin brother or sister. Having another person that looks exactly like you seems very unusual. It's hard to say if having something of an alter ego is good or bad. And if you do have a twin, then you very well know what it's like.
Now let's imagine a typical morning in your family. You haven't w... | The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of coins. The second line contains a sequence of *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=100) — the coins' values. All numbers are separated with spaces. | In the single line print the single number — the minimum needed number of coins. | [
"2\n3 3\n",
"3\n2 1 2\n"
] | [
"2\n",
"2\n"
] | In the first sample you will have to take 2 coins (you and your twin have sums equal to 6, 0 correspondingly). If you take 1 coin, you get sums 3, 3. If you take 0 coins, you get sums 0, 6. Those variants do not satisfy you as your sum should be strictly more that your twins' sum.
In the second sample one coin isn't e... | 500 | [
{
"input": "2\n3 3",
"output": "2"
},
{
"input": "3\n2 1 2",
"output": "2"
},
{
"input": "1\n5",
"output": "1"
},
{
"input": "5\n4 2 2 2 2",
"output": "3"
},
{
"input": "7\n1 10 1 2 1 1 1",
"output": "1"
},
{
"input": "5\n3 2 3 3 1",
"output": "3"
... | 1,697,012,430 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 30 | 0 | input()
Coins = [int(x) for x in input().split(" ")]
Coins.sort()
TotalVal = 0
for v in Coins:
TotalVal += v
CoinsTaken = 0
MinVal = 0
for i in Coins:
if MinVal > TotalVal/2:
break
MinVal += Coins[i]
CoinsTaken += 1
print(CoinsTaken) | Title: Twins
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Imagine that you have a twin brother or sister. Having another person that looks exactly like you seems very unusual. It's hard to say if having something of an alter ego is good or bad. And if you do have a twin, then you very w... | ```python
input()
Coins = [int(x) for x in input().split(" ")]
Coins.sort()
TotalVal = 0
for v in Coins:
TotalVal += v
CoinsTaken = 0
MinVal = 0
for i in Coins:
if MinVal > TotalVal/2:
break
MinVal += Coins[i]
CoinsTaken += 1
print(CoinsTaken)
``` | -1 | |
445 | B | DZY Loves Chemistry | PROGRAMMING | 1,400 | [
"dfs and similar",
"dsu",
"greedy"
] | null | null | DZY loves chemistry, and he enjoys mixing chemicals.
DZY has *n* chemicals, and *m* pairs of them will react. He wants to pour these chemicals into a test tube, and he needs to pour them in one by one, in any order.
Let's consider the danger of a test tube. Danger of an empty test tube is 1. And every time when DZY ... | The first line contains two space-separated integers *n* and *m* .
Each of the next *m* lines contains two space-separated integers *x**i* and *y**i* (1<=≤<=*x**i*<=<<=*y**i*<=≤<=*n*). These integers mean that the chemical *x**i* will react with the chemical *y**i*. Each pair of chemicals will appear at most once i... | Print a single integer — the maximum possible danger. | [
"1 0\n",
"2 1\n1 2\n",
"3 2\n1 2\n2 3\n"
] | [
"1\n",
"2\n",
"4\n"
] | In the first sample, there's only one way to pour, and the danger won't increase.
In the second sample, no matter we pour the 1st chemical first, or pour the 2nd chemical first, the answer is always 2.
In the third sample, there are four ways to achieve the maximum possible danger: 2-1-3, 2-3-1, 1-2-3 and 3-2-1 (that... | 1,000 | [
{
"input": "1 0",
"output": "1"
},
{
"input": "2 1\n1 2",
"output": "2"
},
{
"input": "3 2\n1 2\n2 3",
"output": "4"
},
{
"input": "10 10\n1 8\n4 10\n4 6\n5 10\n2 3\n1 7\n3 4\n3 6\n6 9\n3 7",
"output": "512"
},
{
"input": "20 20\n6 8\n13 20\n7 13\n6 17\n5 15\n1 12... | 1,626,809,443 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 61 | 6,963,200 | n,m = map(int,input().split())
listas = []
largo = len(listas)
if m == 0:
print(1)
else:
for i in range(m):
a,b=map(int,input().split())
if largo == 0:
listas.append([a,b])
largo += 1
else:
contador = 0
#prin... | Title: DZY Loves Chemistry
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
DZY loves chemistry, and he enjoys mixing chemicals.
DZY has *n* chemicals, and *m* pairs of them will react. He wants to pour these chemicals into a test tube, and he needs to pour them in one by one, in any order... | ```python
n,m = map(int,input().split())
listas = []
largo = len(listas)
if m == 0:
print(1)
else:
for i in range(m):
a,b=map(int,input().split())
if largo == 0:
listas.append([a,b])
largo += 1
else:
contador = 0
... | 0 | |
401 | A | Vanya and Cards | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | Vanya loves playing. He even has a special set of cards to play with. Each card has a single integer. The number on the card can be positive, negative and can even be equal to zero. The only limit is, the number on each card doesn't exceed *x* in the absolute value.
Natasha doesn't like when Vanya spends a long time p... | The first line contains two integers: *n* (1<=≤<=*n*<=≤<=1000) — the number of found cards and *x* (1<=≤<=*x*<=≤<=1000) — the maximum absolute value of the number on a card. The second line contains *n* space-separated integers — the numbers on found cards. It is guaranteed that the numbers do not exceed *x* in their a... | Print a single number — the answer to the problem. | [
"3 2\n-1 1 2\n",
"2 3\n-2 -2\n"
] | [
"1\n",
"2\n"
] | In the first sample, Vanya needs to find a single card with number -2.
In the second sample, Vanya needs to find two cards with number 2. He can't find a single card with the required number as the numbers on the lost cards do not exceed 3 in their absolute value. | 500 | [
{
"input": "3 2\n-1 1 2",
"output": "1"
},
{
"input": "2 3\n-2 -2",
"output": "2"
},
{
"input": "4 4\n1 2 3 4",
"output": "3"
},
{
"input": "2 2\n-1 -1",
"output": "1"
},
{
"input": "15 5\n-2 -1 2 -4 -3 4 -4 -2 -2 2 -2 -1 1 -4 -2",
"output": "4"
},
{
"... | 1,604,308,452 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 2 | 124 | 0 |
n,x = map(int,input().split())
f = list(map(int,input().split()))
s = sum(f)
req = -(s)
if req>=-(x) and req<=x :
print(1)
else :
cnt = 0
make = abs(req)
while(req>x) :
req = req-x
cnt = cnt + 1
print(cnt+1)
... | Title: Vanya and Cards
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vanya loves playing. He even has a special set of cards to play with. Each card has a single integer. The number on the card can be positive, negative and can even be equal to zero. The only limit is, the number on each... | ```python
n,x = map(int,input().split())
f = list(map(int,input().split()))
s = sum(f)
req = -(s)
if req>=-(x) and req<=x :
print(1)
else :
cnt = 0
make = abs(req)
while(req>x) :
req = req-x
cnt = cnt + 1
print(cnt+1) ... | 0 | |
939 | A | Love Triangle | PROGRAMMING | 800 | [
"graphs"
] | null | null | As you could know there are no male planes nor female planes. However, each plane on Earth likes some other plane. There are *n* planes on Earth, numbered from 1 to *n*, and the plane with number *i* likes the plane with number *f**i*, where 1<=≤<=*f**i*<=≤<=*n* and *f**i*<=≠<=*i*.
We call a love triangle a situation ... | The first line contains a single integer *n* (2<=≤<=*n*<=≤<=5000) — the number of planes.
The second line contains *n* integers *f*1,<=*f*2,<=...,<=*f**n* (1<=≤<=*f**i*<=≤<=*n*, *f**i*<=≠<=*i*), meaning that the *i*-th plane likes the *f**i*-th. | Output «YES» if there is a love triangle consisting of planes on Earth. Otherwise, output «NO».
You can output any letter in lower case or in upper case. | [
"5\n2 4 5 1 3\n",
"5\n5 5 5 5 1\n"
] | [
"YES\n",
"NO\n"
] | In first example plane 2 likes plane 4, plane 4 likes plane 1, plane 1 likes plane 2 and that is a love triangle.
In second example there are no love triangles. | 500 | [
{
"input": "5\n2 4 5 1 3",
"output": "YES"
},
{
"input": "5\n5 5 5 5 1",
"output": "NO"
},
{
"input": "3\n3 1 2",
"output": "YES"
},
{
"input": "10\n4 10 9 5 3 1 5 10 6 4",
"output": "NO"
},
{
"input": "10\n5 5 4 9 10 9 9 5 3 1",
"output": "YES"
},
{
"... | 1,698,495,075 | 2,147,483,647 | Python 3 | OK | TESTS | 16 | 109 | 716,800 | # цикл + счетчик 3
n = int(input())
arr = list(map(int, input().split()))
arr.insert(0,0)
active = [False]*(n+1)
trio = False
for i in range(1, n+1):
tmp = set()
cur = i
while cur not in tmp:
tmp.add(cur)
cur = arr[cur]
if len(tmp) == 3 and i == cur:
trio = True
print('YES' if... | Title: Love Triangle
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
As you could know there are no male planes nor female planes. However, each plane on Earth likes some other plane. There are *n* planes on Earth, numbered from 1 to *n*, and the plane with number *i* likes the plane with ... | ```python
# цикл + счетчик 3
n = int(input())
arr = list(map(int, input().split()))
arr.insert(0,0)
active = [False]*(n+1)
trio = False
for i in range(1, n+1):
tmp = set()
cur = i
while cur not in tmp:
tmp.add(cur)
cur = arr[cur]
if len(tmp) == 3 and i == cur:
trio = True
prin... | 3 | |
255 | A | Greg's Workout | PROGRAMMING | 800 | [
"implementation"
] | null | null | Greg is a beginner bodybuilder. Today the gym coach gave him the training plan. All it had was *n* integers *a*1,<=*a*2,<=...,<=*a**n*. These numbers mean that Greg needs to do exactly *n* exercises today. Besides, Greg should repeat the *i*-th in order exercise *a**i* times.
Greg now only does three types of exercise... | The first line contains integer *n* (1<=≤<=*n*<=≤<=20). The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=25) — the number of times Greg repeats the exercises. | Print word "chest" (without the quotes), if the chest gets the most exercise, "biceps" (without the quotes), if the biceps gets the most exercise and print "back" (without the quotes) if the back gets the most exercise.
It is guaranteed that the input is such that the answer to the problem is unambiguous. | [
"2\n2 8\n",
"3\n5 1 10\n",
"7\n3 3 2 7 9 6 8\n"
] | [
"biceps\n",
"back\n",
"chest\n"
] | In the first sample Greg does 2 chest, 8 biceps and zero back exercises, so the biceps gets the most exercises.
In the second sample Greg does 5 chest, 1 biceps and 10 back exercises, so the back gets the most exercises.
In the third sample Greg does 18 chest, 12 biceps and 8 back exercises, so the chest gets the mos... | 500 | [
{
"input": "2\n2 8",
"output": "biceps"
},
{
"input": "3\n5 1 10",
"output": "back"
},
{
"input": "7\n3 3 2 7 9 6 8",
"output": "chest"
},
{
"input": "4\n5 6 6 2",
"output": "chest"
},
{
"input": "5\n8 2 2 6 3",
"output": "chest"
},
{
"input": "6\n8 7 ... | 1,655,808,149 | 2,147,483,647 | Python 3 | OK | TESTS | 61 | 92 | 0 | a=input()
b=input()
b=b.split()
bi=0
ba=0
ch=0
for x in range(0,len(b),3):
ch+=int(b[x])
for y in range(1,len(b),3):
bi+=int(b[y])
for z in range(2,len(b),3):
ba+=int(b[z])
if ch>bi and ch>ba:
print('chest')
elif bi>ch and bi>ba:
print('biceps')
else:
print('back')
... | Title: Greg's Workout
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Greg is a beginner bodybuilder. Today the gym coach gave him the training plan. All it had was *n* integers *a*1,<=*a*2,<=...,<=*a**n*. These numbers mean that Greg needs to do exactly *n* exercises today. Besides, Greg ... | ```python
a=input()
b=input()
b=b.split()
bi=0
ba=0
ch=0
for x in range(0,len(b),3):
ch+=int(b[x])
for y in range(1,len(b),3):
bi+=int(b[y])
for z in range(2,len(b),3):
ba+=int(b[z])
if ch>bi and ch>ba:
print('chest')
elif bi>ch and bi>ba:
print('biceps')
else:
print('back')
... | 3 | |
628 | C | Bear and String Distance | PROGRAMMING | 1,300 | [
"greedy",
"strings"
] | null | null | Limak is a little polar bear. He likes nice strings — strings of length *n*, consisting of lowercase English letters only.
The distance between two letters is defined as the difference between their positions in the alphabet. For example, , and .
Also, the distance between two nice strings is defined as the sum of di... | The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=105, 0<=≤<=*k*<=≤<=106).
The second line contains a string *s* of length *n*, consisting of lowercase English letters. | If there is no string satisfying the given conditions then print "-1" (without the quotes).
Otherwise, print any nice string *s*' that . | [
"4 26\nbear\n",
"2 7\naf\n",
"3 1000\nhey\n"
] | [
"roar",
"db\n",
"-1\n"
] | none | 0 | [
{
"input": "4 26\nbear",
"output": "zcar"
},
{
"input": "2 7\naf",
"output": "hf"
},
{
"input": "3 1000\nhey",
"output": "-1"
},
{
"input": "5 50\nkzsij",
"output": "zaiij"
},
{
"input": "5 500\nvsdxg",
"output": "-1"
},
{
"input": "1 0\na",
"outpu... | 1,629,471,994 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 5 | 93 | 7,987,200 |
def main():
for i in range(1):
solve()
def solve():
n, k = pair()
s = list(input())
for i in range(n):
s[i] = ord(s[i])
c = 0
while k > 0 and c < len(s):
if k >= 122 - s[c]:
k-= (122-s[c])
s[c] = 122
else:
... | Title: Bear and String Distance
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Limak is a little polar bear. He likes nice strings — strings of length *n*, consisting of lowercase English letters only.
The distance between two letters is defined as the difference between their positions ... | ```python
def main():
for i in range(1):
solve()
def solve():
n, k = pair()
s = list(input())
for i in range(n):
s[i] = ord(s[i])
c = 0
while k > 0 and c < len(s):
if k >= 122 - s[c]:
k-= (122-s[c])
s[c] = 122
else:
... | 0 | |
844 | A | Diversity | PROGRAMMING | 1,000 | [
"greedy",
"implementation",
"strings"
] | null | null | Calculate the minimum number of characters you need to change in the string *s*, so that it contains at least *k* different letters, or print that it is impossible.
String *s* consists only of lowercase Latin letters, and it is allowed to change characters only to lowercase Latin letters too. | First line of input contains string *s*, consisting only of lowercase Latin letters (1<=≤<=|*s*|<=≤<=1000, |*s*| denotes the length of *s*).
Second line of input contains integer *k* (1<=≤<=*k*<=≤<=26). | Print single line with a minimum number of necessary changes, or the word «impossible» (without quotes) if it is impossible. | [
"yandex\n6\n",
"yahoo\n5\n",
"google\n7\n"
] | [
"0\n",
"1\n",
"impossible\n"
] | In the first test case string contains 6 different letters, so we don't need to change anything.
In the second test case string contains 4 different letters: {'*a*', '*h*', '*o*', '*y*'}. To get 5 different letters it is necessary to change one occurrence of '*o*' to some letter, which doesn't occur in the string, for... | 500 | [
{
"input": "yandex\n6",
"output": "0"
},
{
"input": "yahoo\n5",
"output": "1"
},
{
"input": "google\n7",
"output": "impossible"
},
{
"input": "a\n1",
"output": "0"
},
{
"input": "z\n2",
"output": "impossible"
},
{
"input": "fwgfrwgkuwghfiruhewgirueguhe... | 1,503,997,099 | 2,147,483,647 | Python 3 | OK | TESTS | 41 | 62 | 0 | n = input()
k = int(input())
print('impossible' if k > len(n) else max(0,k - len(set(n))))
| Title: Diversity
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Calculate the minimum number of characters you need to change in the string *s*, so that it contains at least *k* different letters, or print that it is impossible.
String *s* consists only of lowercase Latin letters, and it... | ```python
n = input()
k = int(input())
print('impossible' if k > len(n) else max(0,k - len(set(n))))
``` | 3 | |
601 | A | The Two Routes | PROGRAMMING | 1,600 | [
"graphs",
"shortest paths"
] | null | null | In Absurdistan, there are *n* towns (numbered 1 through *n*) and *m* bidirectional railways. There is also an absurdly simple road network — for each pair of different towns *x* and *y*, there is a bidirectional road between towns *x* and *y* if and only if there is no railway between them. Travelling to a different to... | The first line of the input contains two integers *n* and *m* (2<=≤<=*n*<=≤<=400, 0<=≤<=*m*<=≤<=*n*(*n*<=-<=1)<=/<=2) — the number of towns and the number of railways respectively.
Each of the next *m* lines contains two integers *u* and *v*, denoting a railway between towns *u* and *v* (1<=≤<=*u*,<=*v*<=≤<=*n*, *u*<=... | Output one integer — the smallest possible time of the later vehicle's arrival in town *n*. If it's impossible for at least one of the vehicles to reach town *n*, output <=-<=1. | [
"4 2\n1 3\n3 4\n",
"4 6\n1 2\n1 3\n1 4\n2 3\n2 4\n3 4\n",
"5 5\n4 2\n3 5\n4 5\n5 1\n1 2\n"
] | [
"2\n",
"-1\n",
"3\n"
] | In the first sample, the train can take the route <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/7c0aa60a06309ef607b7159fd7f3687ea0d943ce.png" style="max-width: 100.0%;max-height: 100.0%;"/> and the bus can take the route <img align="middle" class="tex-formula" src="https://espresso.codefo... | 500 | [
{
"input": "4 2\n1 3\n3 4",
"output": "2"
},
{
"input": "4 6\n1 2\n1 3\n1 4\n2 3\n2 4\n3 4",
"output": "-1"
},
{
"input": "5 5\n4 2\n3 5\n4 5\n5 1\n1 2",
"output": "3"
},
{
"input": "5 4\n1 2\n3 2\n3 4\n5 4",
"output": "4"
},
{
"input": "3 1\n1 2",
"output": "... | 1,610,455,344 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 4 | 140 | 3,993,600 | def bfs(graph, st, dest):
import queue, collections
q = queue.Queue()
visited = set()
q.put(1)
vis.add(1)
dist = collections.defaultdict(int)
dist[1] = 0
while not q.empty():
cur = q.get()
visited.add(cur)
for neigh in graph[cur]:
if neigh ... | Title: The Two Routes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In Absurdistan, there are *n* towns (numbered 1 through *n*) and *m* bidirectional railways. There is also an absurdly simple road network — for each pair of different towns *x* and *y*, there is a bidirectional road bet... | ```python
def bfs(graph, st, dest):
import queue, collections
q = queue.Queue()
visited = set()
q.put(1)
vis.add(1)
dist = collections.defaultdict(int)
dist[1] = 0
while not q.empty():
cur = q.get()
visited.add(cur)
for neigh in graph[cur]:
... | 0 | |
387 | A | George and Sleep | PROGRAMMING | 900 | [
"implementation"
] | null | null | George woke up and saw the current time *s* on the digital clock. Besides, George knows that he has slept for time *t*.
Help George! Write a program that will, given time *s* and *t*, determine the time *p* when George went to bed. Note that George could have gone to bed yesterday relatively to the current time (see ... | The first line contains current time *s* as a string in the format "hh:mm". The second line contains time *t* in the format "hh:mm" — the duration of George's sleep. It is guaranteed that the input contains the correct time in the 24-hour format, that is, 00<=≤<=*hh*<=≤<=23, 00<=≤<=*mm*<=≤<=59. | In the single line print time *p* — the time George went to bed in the format similar to the format of the time in the input. | [
"05:50\n05:44\n",
"00:00\n01:00\n",
"00:01\n00:00\n"
] | [
"00:06\n",
"23:00\n",
"00:01\n"
] | In the first sample George went to bed at "00:06". Note that you should print the time only in the format "00:06". That's why answers "0:06", "00:6" and others will be considered incorrect.
In the second sample, George went to bed yesterday.
In the third sample, George didn't do to bed at all. | 500 | [
{
"input": "05:50\n05:44",
"output": "00:06"
},
{
"input": "00:00\n01:00",
"output": "23:00"
},
{
"input": "00:01\n00:00",
"output": "00:01"
},
{
"input": "23:59\n23:59",
"output": "00:00"
},
{
"input": "23:44\n23:55",
"output": "23:49"
},
{
"input": "... | 1,634,490,595 | 2,147,483,647 | PyPy 3 | OK | TESTS | 47 | 93 | 0 | h, m = map(int, input().split(':'))
hh, mm = map(int, input().split(':'))
s = h * 60 + m
t = hh * 60 + mm
ans = s - t
if ans < 0:
ans = 1440 + ans
if len(str(ans // 60)) == 1:
if len(str(ans % 60)) == 1:
print(f'0{ans // 60}:0{ans % 60}')
else:
print(f'0{ans // 60}:{ans % 60}')
e... | Title: George and Sleep
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
George woke up and saw the current time *s* on the digital clock. Besides, George knows that he has slept for time *t*.
Help George! Write a program that will, given time *s* and *t*, determine the time *p* when Geor... | ```python
h, m = map(int, input().split(':'))
hh, mm = map(int, input().split(':'))
s = h * 60 + m
t = hh * 60 + mm
ans = s - t
if ans < 0:
ans = 1440 + ans
if len(str(ans // 60)) == 1:
if len(str(ans % 60)) == 1:
print(f'0{ans // 60}:0{ans % 60}')
else:
print(f'0{ans // 60}:{ans ... | 3 | |
136 | A | Presents | PROGRAMMING | 800 | [
"implementation"
] | null | null | Little Petya very much likes gifts. Recently he has received a new laptop as a New Year gift from his mother. He immediately decided to give it to somebody else as what can be more pleasant than giving somebody gifts. And on this occasion he organized a New Year party at his place and invited *n* his friends there.
If... | The first line contains one integer *n* (1<=≤<=*n*<=≤<=100) — the quantity of friends Petya invited to the party. The second line contains *n* space-separated integers: the *i*-th number is *p**i* — the number of a friend who gave a gift to friend number *i*. It is guaranteed that each friend received exactly one gift.... | Print *n* space-separated integers: the *i*-th number should equal the number of the friend who gave a gift to friend number *i*. | [
"4\n2 3 4 1\n",
"3\n1 3 2\n",
"2\n1 2\n"
] | [
"4 1 2 3\n",
"1 3 2\n",
"1 2\n"
] | none | 500 | [
{
"input": "4\n2 3 4 1",
"output": "4 1 2 3"
},
{
"input": "3\n1 3 2",
"output": "1 3 2"
},
{
"input": "2\n1 2",
"output": "1 2"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "10\n1 3 2 6 4 5 7 9 8 10",
"output": "1 3 2 5 6 4 7 9 8 10"
},
{
"input"... | 1,683,547,194 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 101 | 124 | 0 | import sys
input=sys.stdin.readline
n=int(input())
lst=[*map(int,input().split())]
answer=[0]*n
for i,f in enumerate(lst):
answer[f-1]=i+1
print(' '.join(map(str,answer))) | Title: Presents
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Petya very much likes gifts. Recently he has received a new laptop as a New Year gift from his mother. He immediately decided to give it to somebody else as what can be more pleasant than giving somebody gifts. And on t... | ```python
import sys
input=sys.stdin.readline
n=int(input())
lst=[*map(int,input().split())]
answer=[0]*n
for i,f in enumerate(lst):
answer[f-1]=i+1
print(' '.join(map(str,answer)))
``` | 3 | |
965 | A | Paper Airplanes | PROGRAMMING | 800 | [
"math"
] | null | null | To make a paper airplane, one has to use a rectangular piece of paper. From a sheet of standard size you can make $s$ airplanes.
A group of $k$ people decided to make $n$ airplanes each. They are going to buy several packs of paper, each of them containing $p$ sheets, and then distribute the sheets between the people.... | The only line contains four integers $k$, $n$, $s$, $p$ ($1 \le k, n, s, p \le 10^4$) — the number of people, the number of airplanes each should make, the number of airplanes that can be made using one sheet and the number of sheets in one pack, respectively. | Print a single integer — the minimum number of packs they should buy. | [
"5 3 2 3\n",
"5 3 100 1\n"
] | [
"4\n",
"5\n"
] | In the first sample they have to buy $4$ packs of paper: there will be $12$ sheets in total, and giving $2$ sheets to each person is enough to suit everyone's needs.
In the second sample they have to buy a pack for each person as they can't share sheets. | 500 | [
{
"input": "5 3 2 3",
"output": "4"
},
{
"input": "5 3 100 1",
"output": "5"
},
{
"input": "10000 10000 1 1",
"output": "100000000"
},
{
"input": "1 1 10000 10000",
"output": "1"
},
{
"input": "300 300 21 23",
"output": "196"
},
{
"input": "300 2 37 51... | 1,585,057,468 | 2,147,483,647 | Python 3 | OK | TESTS | 18 | 109 | 0 | import math
k,n,s,p=map(int,input().split())
x=math.ceil(n/s)
if x>0:
y=x*k
z=math.ceil(y/p)
else:
z=k
print(z) | Title: Paper Airplanes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
To make a paper airplane, one has to use a rectangular piece of paper. From a sheet of standard size you can make $s$ airplanes.
A group of $k$ people decided to make $n$ airplanes each. They are going to buy several p... | ```python
import math
k,n,s,p=map(int,input().split())
x=math.ceil(n/s)
if x>0:
y=x*k
z=math.ceil(y/p)
else:
z=k
print(z)
``` | 3 | |
329 | B | Biridian Forest | PROGRAMMING | 1,500 | [
"dfs and similar",
"shortest paths"
] | null | null | You're a mikemon breeder currently in the middle of your journey to become a mikemon master. Your current obstacle is go through the infamous Biridian Forest.
The forest
The Biridian Forest is a two-dimensional grid consisting of *r* rows and *c* columns. Each cell in Biridian Forest may contain a tree, or may be vac... | The first line consists of two integers: *r* and *c* (1<=≤<=*r*,<=*c*<=≤<=1000), denoting the number of rows and the number of columns in Biridian Forest. The next *r* rows will each depict a row of the map, where each character represents the content of a single cell:
- 'T': A cell occupied by a tree. - 'S': An em... | A single line denoted the minimum possible number of mikemon battles that you have to participate in if you pick a strategy that minimize this number. | [
"5 7\n000E0T3\nT0TT0T0\n010T0T0\n2T0T0T0\n0T0S000\n",
"1 4\nSE23\n"
] | [
"3\n",
"2\n"
] | The following picture illustrates the first example. The blue line denotes a possible sequence of moves that you should post in your blog:
The three breeders on the left side of the map will be able to battle you — the lone breeder can simply stay in his place until you come while the other two breeders can move to wh... | 1,000 | [
{
"input": "5 7\n000E0T3\nT0TT0T0\n010T0T0\n2T0T0T0\n0T0S000",
"output": "3"
},
{
"input": "1 4\nSE23",
"output": "2"
},
{
"input": "3 3\n000\nS0E\n000",
"output": "0"
},
{
"input": "5 5\nS9999\nTTTT9\n99999\n9TTTT\n9999E",
"output": "135"
},
{
"input": "1 10\n9T9... | 1,524,921,628 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 4 | 186 | 7,168,000 | from collections import defaultdict
r,c = map(int, input().split())
l = []
l1 = {}
s=()
e=()
for i in range(r):
st = list(input())
if 'S' in st:
s = (i, st.index('S'))
if 'E' in st:
e = (i, st.index('E'))
l.append(st)
valids = {(i,j) for i in range(r) for j in range(c) if l[i][j] != 'T'}
imp = [((i,j),l[i][j])... | Title: Biridian Forest
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You're a mikemon breeder currently in the middle of your journey to become a mikemon master. Your current obstacle is go through the infamous Biridian Forest.
The forest
The Biridian Forest is a two-dimensional grid c... | ```python
from collections import defaultdict
r,c = map(int, input().split())
l = []
l1 = {}
s=()
e=()
for i in range(r):
st = list(input())
if 'S' in st:
s = (i, st.index('S'))
if 'E' in st:
e = (i, st.index('E'))
l.append(st)
valids = {(i,j) for i in range(r) for j in range(c) if l[i][j] != 'T'}
imp = [((i,j... | -1 | |
510 | A | Fox And Snake | PROGRAMMING | 800 | [
"implementation"
] | null | null | Fox Ciel starts to learn programming. The first task is drawing a fox! However, that turns out to be too hard for a beginner, so she decides to draw a snake instead.
A snake is a pattern on a *n* by *m* table. Denote *c*-th cell of *r*-th row as (*r*,<=*c*). The tail of the snake is located at (1,<=1), then it's body ... | The only line contains two integers: *n* and *m* (3<=≤<=*n*,<=*m*<=≤<=50).
*n* is an odd number. | Output *n* lines. Each line should contain a string consisting of *m* characters. Do not output spaces. | [
"3 3\n",
"3 4\n",
"5 3\n",
"9 9\n"
] | [
"###\n..#\n###\n",
"####\n...#\n####\n",
"###\n..#\n###\n#..\n###\n",
"#########\n........#\n#########\n#........\n#########\n........#\n#########\n#........\n#########\n"
] | none | 500 | [
{
"input": "3 3",
"output": "###\n..#\n###"
},
{
"input": "3 4",
"output": "####\n...#\n####"
},
{
"input": "5 3",
"output": "###\n..#\n###\n#..\n###"
},
{
"input": "9 9",
"output": "#########\n........#\n#########\n#........\n#########\n........#\n#########\n#........\n#... | 1,689,230,668 | 2,147,483,647 | Python 3 | OK | TESTS | 28 | 31 | 0 | n,m = list(map(int, input().split()))
for i in range(1,n+1):
if i% 4 ==0:
print('#'+(m-1)*'.')
elif i% 2 ==0:
print((m-1)*'.'+'#')
else:
print(m*'#') | Title: Fox And Snake
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Fox Ciel starts to learn programming. The first task is drawing a fox! However, that turns out to be too hard for a beginner, so she decides to draw a snake instead.
A snake is a pattern on a *n* by *m* table. Denote *c*... | ```python
n,m = list(map(int, input().split()))
for i in range(1,n+1):
if i% 4 ==0:
print('#'+(m-1)*'.')
elif i% 2 ==0:
print((m-1)*'.'+'#')
else:
print(m*'#')
``` | 3 | |
427 | A | Police Recruits | PROGRAMMING | 800 | [
"implementation"
] | null | null | The police department of your city has just started its journey. Initially, they don’t have any manpower. So, they started hiring new recruits in groups.
Meanwhile, crimes keeps occurring within the city. One member of the police force can investigate only one crime during his/her lifetime.
If there is no police offi... | The first line of input will contain an integer *n* (1<=≤<=*n*<=≤<=105), the number of events. The next line will contain *n* space-separated integers.
If the integer is -1 then it means a crime has occurred. Otherwise, the integer will be positive, the number of officers recruited together at that time. No more than ... | Print a single integer, the number of crimes which will go untreated. | [
"3\n-1 -1 1\n",
"8\n1 -1 1 -1 -1 1 1 1\n",
"11\n-1 -1 2 -1 -1 -1 -1 -1 -1 -1 -1\n"
] | [
"2\n",
"1\n",
"8\n"
] | Lets consider the second example:
1. Firstly one person is hired. 1. Then crime appears, the last hired person will investigate this crime. 1. One more person is hired. 1. One more crime appears, the last hired person will investigate this crime. 1. Crime appears. There is no free policeman at the time, so this c... | 500 | [
{
"input": "3\n-1 -1 1",
"output": "2"
},
{
"input": "8\n1 -1 1 -1 -1 1 1 1",
"output": "1"
},
{
"input": "11\n-1 -1 2 -1 -1 -1 -1 -1 -1 -1 -1",
"output": "8"
},
{
"input": "7\n-1 -1 1 1 -1 -1 1",
"output": "2"
},
{
"input": "21\n-1 -1 -1 -1 -1 3 2 -1 6 -1 -1 2 1 ... | 1,685,830,561 | 2,147,483,647 | Python 3 | OK | TESTS | 63 | 78 | 9,216,000 | a, b = int(input()), input().split()
b = [int(i) for i in b]
c = 0
otvet = 0
for i in range(a):
c += b[i]
if c < 0:
otvet += 1
c = 0
print(otvet) | Title: Police Recruits
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The police department of your city has just started its journey. Initially, they don’t have any manpower. So, they started hiring new recruits in groups.
Meanwhile, crimes keeps occurring within the city. One member of... | ```python
a, b = int(input()), input().split()
b = [int(i) for i in b]
c = 0
otvet = 0
for i in range(a):
c += b[i]
if c < 0:
otvet += 1
c = 0
print(otvet)
``` | 3 | |
385 | C | Bear and Prime Numbers | PROGRAMMING | 1,700 | [
"binary search",
"brute force",
"data structures",
"dp",
"implementation",
"math",
"number theory"
] | null | null | Recently, the bear started studying data structures and faced the following problem.
You are given a sequence of integers *x*1,<=*x*2,<=...,<=*x**n* of length *n* and *m* queries, each of them is characterized by two integers *l**i*,<=*r**i*. Let's introduce *f*(*p*) to represent the number of such indexes *k*, that *... | The first line contains integer *n* (1<=≤<=*n*<=≤<=106). The second line contains *n* integers *x*1,<=*x*2,<=...,<=*x**n* (2<=≤<=*x**i*<=≤<=107). The numbers are not necessarily distinct.
The third line contains integer *m* (1<=≤<=*m*<=≤<=50000). Each of the following *m* lines contains a pair of space-separated integ... | Print *m* integers — the answers to the queries on the order the queries appear in the input. | [
"6\n5 5 7 10 14 15\n3\n2 11\n3 12\n4 4\n",
"7\n2 3 5 7 11 4 8\n2\n8 10\n2 123\n"
] | [
"9\n7\n0\n",
"0\n7\n"
] | Consider the first sample. Overall, the first sample has 3 queries.
1. The first query *l* = 2, *r* = 11 comes. You need to count *f*(2) + *f*(3) + *f*(5) + *f*(7) + *f*(11) = 2 + 1 + 4 + 2 + 0 = 9. 1. The second query comes *l* = 3, *r* = 12. You need to count *f*(3) + *f*(5) + *f*(7) + *f*(11) = 1 + 4 + 2 + 0 = 7.... | 1,500 | [
{
"input": "6\n5 5 7 10 14 15\n3\n2 11\n3 12\n4 4",
"output": "9\n7\n0"
},
{
"input": "7\n2 3 5 7 11 4 8\n2\n8 10\n2 123",
"output": "0\n7"
},
{
"input": "9\n50 50 50 50 50 50 50 50 50\n7\n20 20\n8 13\n13 13\n6 14\n3 5\n15 17\n341 1792",
"output": "0\n0\n0\n0\n9\n0\n0"
},
{
"... | 1,615,884,765 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 5 | 1,653 | 239,001,600 | import os
import sys
from io import BytesIO, IOBase
def main():
pass
# region fastio
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in... | Title: Bear and Prime Numbers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Recently, the bear started studying data structures and faced the following problem.
You are given a sequence of integers *x*1,<=*x*2,<=...,<=*x**n* of length *n* and *m* queries, each of them is characterized b... | ```python
import os
import sys
from io import BytesIO, IOBase
def main():
pass
# region fastio
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or ... | 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,631,625,163 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 2 | 218 | 20,172,800 | m , n = map(int, input().split())
count = 0
#vertikal, geht nur wenn m => 2
if m >= 2:
count = count + n
#Horizontal, geht nur wenn n => 2
if n >= 2:
count = count + int(n/2)*(m-2)
print(count) | 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())
count = 0
#vertikal, geht nur wenn m => 2
if m >= 2:
count = count + n
#Horizontal, geht nur wenn n => 2
if n >= 2:
count = count + int(n/2)*(m-2)
print(count)
``` | 0 |
443 | A | Anton and Letters | PROGRAMMING | 800 | [
"constructive algorithms",
"implementation"
] | null | null | Recently, Anton has found a set. The set consists of small English letters. Anton carefully wrote out all the letters from the set in one line, separated by a comma. He also added an opening curved bracket at the beginning of the line and a closing curved bracket at the end of the line.
Unfortunately, from time to ti... | The first and the single line contains the set of letters. The length of the line doesn't exceed 1000. It is guaranteed that the line starts from an opening curved bracket and ends with a closing curved bracket. Between them, small English letters are listed, separated by a comma. Each comma is followed by a space. | Print a single number — the number of distinct letters in Anton's set. | [
"{a, b, c}\n",
"{b, a, b, a}\n",
"{}\n"
] | [
"3\n",
"2\n",
"0\n"
] | none | 500 | [
{
"input": "{a, b, c}",
"output": "3"
},
{
"input": "{b, a, b, a}",
"output": "2"
},
{
"input": "{}",
"output": "0"
},
{
"input": "{a, a, c, b, b, b, c, c, c, c}",
"output": "3"
},
{
"input": "{a, c, b, b}",
"output": "3"
},
{
"input": "{a, b}",
"o... | 1,687,844,073 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 1 | 31 | 0 | a=set(map(str,input().split()))
b=[]
for i in a:
if i not in b:
b.append(i)
print(len(b)) | Title: Anton and Letters
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Recently, Anton has found a set. The set consists of small English letters. Anton carefully wrote out all the letters from the set in one line, separated by a comma. He also added an opening curved bracket at the begi... | ```python
a=set(map(str,input().split()))
b=[]
for i in a:
if i not in b:
b.append(i)
print(len(b))
``` | 0 | |
155 | A | I_love_\%username\% | PROGRAMMING | 800 | [
"brute force"
] | null | null | Vasya adores sport programming. He can't write programs but he loves to watch the contests' progress. Vasya even has a favorite coder and Vasya pays special attention to him.
One day Vasya decided to collect the results of all contests where his favorite coder participated and track the progress of his coolness. For e... | The first line contains the single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of contests where the coder participated.
The next line contains *n* space-separated non-negative integer numbers — they are the points which the coder has earned. The points are given in the chronological order. All points do not exceed ... | Print the single number — the number of amazing performances the coder has had during his whole history of participating in the contests. | [
"5\n100 50 200 150 200\n",
"10\n4664 6496 5814 7010 5762 5736 6944 4850 3698 7242\n"
] | [
"2\n",
"4\n"
] | In the first sample the performances number 2 and 3 are amazing.
In the second sample the performances number 2, 4, 9 and 10 are amazing. | 500 | [
{
"input": "5\n100 50 200 150 200",
"output": "2"
},
{
"input": "10\n4664 6496 5814 7010 5762 5736 6944 4850 3698 7242",
"output": "4"
},
{
"input": "1\n6",
"output": "0"
},
{
"input": "2\n2 1",
"output": "1"
},
{
"input": "5\n100 36 53 7 81",
"output": "2"
... | 1,698,129,253 | 2,147,483,647 | Python 3 | OK | TESTS | 37 | 92 | 0 | n = int(input())
count = 0
l = list(map(int, input().split()))
mini = l[0]
maxi = l[0]
count = 0
for i in range(1,n):
if l[i] > maxi:
maxi = l[i]
count += 1
elif l[i] < mini:
mini = l[i]
count += 1
print(count)
| Title: I_love_\%username\%
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya adores sport programming. He can't write programs but he loves to watch the contests' progress. Vasya even has a favorite coder and Vasya pays special attention to him.
One day Vasya decided to collect the re... | ```python
n = int(input())
count = 0
l = list(map(int, input().split()))
mini = l[0]
maxi = l[0]
count = 0
for i in range(1,n):
if l[i] > maxi:
maxi = l[i]
count += 1
elif l[i] < mini:
mini = l[i]
count += 1
print(count)
``` | 3 | |
612 | A | The Text Splitting | PROGRAMMING | 1,300 | [
"brute force",
"implementation",
"strings"
] | null | null | You are given the string *s* of length *n* and the numbers *p*,<=*q*. Split the string *s* to pieces of length *p* and *q*.
For example, the string "Hello" for *p*<==<=2, *q*<==<=3 can be split to the two strings "Hel" and "lo" or to the two strings "He" and "llo".
Note it is allowed to split the string *s* to the st... | The first line contains three positive integers *n*,<=*p*,<=*q* (1<=≤<=*p*,<=*q*<=≤<=*n*<=≤<=100).
The second line contains the string *s* consists of lowercase and uppercase latin letters and digits. | If it's impossible to split the string *s* to the strings of length *p* and *q* print the only number "-1".
Otherwise in the first line print integer *k* — the number of strings in partition of *s*.
Each of the next *k* lines should contain the strings in partition. Each string should be of the length *p* or *q*. The... | [
"5 2 3\nHello\n",
"10 9 5\nCodeforces\n",
"6 4 5\nPrivet\n",
"8 1 1\nabacabac\n"
] | [
"2\nHe\nllo\n",
"2\nCodef\norces\n",
"-1\n",
"8\na\nb\na\nc\na\nb\na\nc\n"
] | none | 0 | [
{
"input": "5 2 3\nHello",
"output": "2\nHe\nllo"
},
{
"input": "10 9 5\nCodeforces",
"output": "2\nCodef\norces"
},
{
"input": "6 4 5\nPrivet",
"output": "-1"
},
{
"input": "8 1 1\nabacabac",
"output": "8\na\nb\na\nc\na\nb\na\nc"
},
{
"input": "1 1 1\n1",
"ou... | 1,451,057,195 | 1,595 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 20 | 1,000 | 0 | import sys
def possible(n, p, q, steps = []):
"""
if (n % p == 0): return True
if (n % q == 0): return True
if ((n-p) % q == 0): return True
if ((n-q) % p == 0): return True
return False
"""
if (n == 0): return (True, steps)
if (n < 0): return (False, steps)
op_a = possible(n-p... | Title: The Text Splitting
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given the string *s* of length *n* and the numbers *p*,<=*q*. Split the string *s* to pieces of length *p* and *q*.
For example, the string "Hello" for *p*<==<=2, *q*<==<=3 can be split to the two strings "H... | ```python
import sys
def possible(n, p, q, steps = []):
"""
if (n % p == 0): return True
if (n % q == 0): return True
if ((n-p) % q == 0): return True
if ((n-q) % p == 0): return True
return False
"""
if (n == 0): return (True, steps)
if (n < 0): return (False, steps)
op_a = po... | 0 | |
767 | A | Snacktower | PROGRAMMING | 1,100 | [
"data structures",
"implementation"
] | null | null | According to an old legeng, a long time ago Ankh-Morpork residents did something wrong to miss Fortune, and she cursed them. She said that at some time *n* snacks of distinct sizes will fall on the city, and the residents should build a Snacktower of them by placing snacks one on another. Of course, big snacks should b... | The first line contains single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the total number of snacks.
The second line contains *n* integers, the *i*-th of them equals the size of the snack which fell on the *i*-th day. Sizes are distinct integers from 1 to *n*. | Print *n* lines. On the *i*-th of them print the sizes of the snacks which the residents placed on the top of the Snacktower on the *i*-th day in the order they will do that. If no snack is placed on some day, leave the corresponding line empty. | [
"3\n3 1 2\n",
"5\n4 5 1 2 3\n"
] | [
"3\n \n2 1",
"5 4\n \n \n3 2 1\n"
] | In the example a snack of size 3 fell on the first day, and the residents immediately placed it. On the second day a snack of size 1 fell, and the residents weren't able to place it because they were missing the snack of size 2. On the third day a snack of size 2 fell, and the residents immediately placed it. Right aft... | 500 | [
{
"input": "3\n3 1 2",
"output": "3 \n\n2 1 "
},
{
"input": "5\n4 5 1 2 3",
"output": "5 4 \n\n\n3 2 1 "
},
{
"input": "1\n1",
"output": "1 "
},
{
"input": "2\n1 2",
"output": "2 1 "
},
{
"input": "10\n5 1 6 2 8 3 4 10 9 7",
"output": "10 \n9 8 \n7 6 5 4 3 2 1... | 1,673,186,487 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 25 | 186 | 13,926,400 | n = int(input())
l = [int(x) for x in input().split()]
x = n
l1 = [0]*(n+1)
for i in l:
l1[i]=1
while l1[x]:
print(x,end=' ')
x-=1
print() | Title: Snacktower
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
According to an old legeng, a long time ago Ankh-Morpork residents did something wrong to miss Fortune, and she cursed them. She said that at some time *n* snacks of distinct sizes will fall on the city, and the residents sh... | ```python
n = int(input())
l = [int(x) for x in input().split()]
x = n
l1 = [0]*(n+1)
for i in l:
l1[i]=1
while l1[x]:
print(x,end=' ')
x-=1
print()
``` | 3 | |
289 | B | Polo the Penguin and Matrix | PROGRAMMING | 1,400 | [
"brute force",
"dp",
"implementation",
"sortings",
"ternary search"
] | null | null | Little penguin Polo has an *n*<=×<=*m* matrix, consisting of integers. Let's index the matrix rows from 1 to *n* from top to bottom and let's index the columns from 1 to *m* from left to right. Let's represent the matrix element on the intersection of row *i* and column *j* as *a**ij*.
In one move the penguin can add ... | The first line contains three integers *n*, *m* and *d* (1<=≤<=*n*,<=*m*<=≤<=100,<=1<=≤<=*d*<=≤<=104) — the matrix sizes and the *d* parameter. Next *n* lines contain the matrix: the *j*-th integer in the *i*-th row is the matrix element *a**ij* (1<=≤<=*a**ij*<=≤<=104). | In a single line print a single integer — the minimum number of moves the penguin needs to make all matrix elements equal. If that is impossible, print "-1" (without the quotes). | [
"2 2 2\n2 4\n6 8\n",
"1 2 7\n6 7\n"
] | [
"4\n",
"-1\n"
] | none | 1,000 | [
{
"input": "2 2 2\n2 4\n6 8",
"output": "4"
},
{
"input": "1 2 7\n6 7",
"output": "-1"
},
{
"input": "3 2 1\n5 7\n1 2\n5 100",
"output": "104"
},
{
"input": "3 3 3\n5 8 5\n11 11 17\n14 5 2",
"output": "12"
},
{
"input": "3 3 3\n5 8 5\n11 11 17\n14 5 3",
"outpu... | 1,587,015,500 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 154 | 307,200 | n, m, d = [int(i) for i in input().split()]
matrix = []
for i in range(n):
arr = [int(i) for i in input().split()]
matrix += arr
x = matrix[0]%d
ter_count = 0
for i in range(len(matrix)):
if matrix[i]%d == x:
ter_count += 1
if ter_count == len(matrix):
matrix.sort()
size = len(ma... | Title: Polo the Penguin and Matrix
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little penguin Polo has an *n*<=×<=*m* matrix, consisting of integers. Let's index the matrix rows from 1 to *n* from top to bottom and let's index the columns from 1 to *m* from left to right. Let's represe... | ```python
n, m, d = [int(i) for i in input().split()]
matrix = []
for i in range(n):
arr = [int(i) for i in input().split()]
matrix += arr
x = matrix[0]%d
ter_count = 0
for i in range(len(matrix)):
if matrix[i]%d == x:
ter_count += 1
if ter_count == len(matrix):
matrix.sort()
siz... | 0 | |
748 | A | Santa Claus and a Place in a Class | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | Santa Claus is the first who came to the Christmas Olympiad, and he is going to be the first to take his place at a desk! In the classroom there are *n* lanes of *m* desks each, and there are two working places at each of the desks. The lanes are numbered from 1 to *n* from the left to the right, the desks in a lane ar... | The only line contains three integers *n*, *m* and *k* (1<=≤<=*n*,<=*m*<=≤<=10<=000, 1<=≤<=*k*<=≤<=2*nm*) — the number of lanes, the number of desks in each lane and the number of Santa Claus' place. | Print two integers: the number of lane *r*, the number of desk *d*, and a character *s*, which stands for the side of the desk Santa Claus. The character *s* should be "L", if Santa Clause should sit on the left, and "R" if his place is on the right. | [
"4 3 9\n",
"4 3 24\n",
"2 4 4\n"
] | [
"2 2 L\n",
"4 3 R\n",
"1 2 R\n"
] | The first and the second samples are shown on the picture. The green place corresponds to Santa Claus' place in the first example, the blue place corresponds to Santa Claus' place in the second example.
In the third sample there are two lanes with four desks in each, and Santa Claus has the fourth place. Thus, his pla... | 500 | [
{
"input": "4 3 9",
"output": "2 2 L"
},
{
"input": "4 3 24",
"output": "4 3 R"
},
{
"input": "2 4 4",
"output": "1 2 R"
},
{
"input": "3 10 24",
"output": "2 2 R"
},
{
"input": "10 3 59",
"output": "10 3 L"
},
{
"input": "10000 10000 160845880",
"... | 1,610,091,767 | 2,147,483,647 | PyPy 3 | OK | TESTS | 46 | 140 | 0 | n,m,k = map(int,input().split())
x = (k+1)//2
r = (x+m-1)//m
c = (x-1)%m+1
ch = 'R'
if k&1:
ch = 'L'
print(r,c,ch) | Title: Santa Claus and a Place in a Class
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Santa Claus is the first who came to the Christmas Olympiad, and he is going to be the first to take his place at a desk! In the classroom there are *n* lanes of *m* desks each, and there are two work... | ```python
n,m,k = map(int,input().split())
x = (k+1)//2
r = (x+m-1)//m
c = (x-1)%m+1
ch = 'R'
if k&1:
ch = 'L'
print(r,c,ch)
``` | 3 | |
384 | A | Coder | PROGRAMMING | 800 | [
"implementation"
] | null | null | Iahub likes chess very much. He even invented a new chess piece named Coder. A Coder can move (and attack) one square horizontally or vertically. More precisely, if the Coder is located at position (*x*,<=*y*), he can move to (or attack) positions (*x*<=+<=1,<=*y*), (*x*–1,<=*y*), (*x*,<=*y*<=+<=1) and (*x*,<=*y*–1).
... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=1000). | On the first line print an integer, the maximum number of Coders that can be placed on the chessboard.
On each of the next *n* lines print *n* characters, describing the configuration of the Coders. For an empty cell print an '.', and for a Coder print a 'C'.
If there are multiple correct answers, you can print any. | [
"2\n"
] | [
"2\nC.\n.C\n"
] | none | 500 | [
{
"input": "2",
"output": "2\nC.\n.C"
},
{
"input": "3",
"output": "5\nC.C\n.C.\nC.C"
},
{
"input": "4",
"output": "8\nC.C.\n.C.C\nC.C.\n.C.C"
},
{
"input": "10",
"output": "50\nC.C.C.C.C.\n.C.C.C.C.C\nC.C.C.C.C.\n.C.C.C.C.C\nC.C.C.C.C.\n.C.C.C.C.C\nC.C.C.C.C.\n.C.C.C.C.C... | 1,630,988,027 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 3 | 77 | 20,172,800 | def solve(n):
if n == 1:
result = 1
elif n == 2:
result = 2
else:
result = n + 2 ** (n-2)
print(result)
for i in range(n):
s = ''
if i % 2 == 0:
for j in range(n):
if j % 2 == 0:
s += 'C'
... | Title: Coder
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Iahub likes chess very much. He even invented a new chess piece named Coder. A Coder can move (and attack) one square horizontally or vertically. More precisely, if the Coder is located at position (*x*,<=*y*), he can move to (or... | ```python
def solve(n):
if n == 1:
result = 1
elif n == 2:
result = 2
else:
result = n + 2 ** (n-2)
print(result)
for i in range(n):
s = ''
if i % 2 == 0:
for j in range(n):
if j % 2 == 0:
s +=... | 0 | |
605 | A | Sorting Railway Cars | PROGRAMMING | 1,600 | [
"constructive algorithms",
"greedy"
] | null | null | An infinitely long railway has a train consisting of *n* cars, numbered from 1 to *n* (the numbers of all the cars are distinct) and positioned in arbitrary order. David Blaine wants to sort the railway cars in the order of increasing numbers. In one move he can make one of the cars disappear from its place and telepor... | The first line of the input contains integer *n* (1<=≤<=*n*<=≤<=100<=000) — the number of cars in the train.
The second line contains *n* integers *p**i* (1<=≤<=*p**i*<=≤<=*n*, *p**i*<=≠<=*p**j* if *i*<=≠<=*j*) — the sequence of the numbers of the cars in the train. | Print a single integer — the minimum number of actions needed to sort the railway cars. | [
"5\n4 1 2 5 3\n",
"4\n4 1 3 2\n"
] | [
"2\n",
"2\n"
] | In the first sample you need first to teleport the 4-th car, and then the 5-th car to the end of the train. | 500 | [
{
"input": "5\n4 1 2 5 3",
"output": "2"
},
{
"input": "4\n4 1 3 2",
"output": "2"
},
{
"input": "1\n1",
"output": "0"
},
{
"input": "2\n1 2",
"output": "0"
},
{
"input": "2\n2 1",
"output": "1"
},
{
"input": "6\n5 3 6 1 4 2",
"output": "4"
},
... | 1,539,098,495 | 2,147,483,647 | PyPy 3 | OK | TESTS | 66 | 202 | 11,059,200 | ## KALAM
N = 100000 + 77
n = int(input())
a = list(map(int , input().split()))
T = [0] * N
A = 0
for i in a:
T[i] = T[i - 1] + 1
A = max(A , T[i])
print(n - A)
| Title: Sorting Railway Cars
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
An infinitely long railway has a train consisting of *n* cars, numbered from 1 to *n* (the numbers of all the cars are distinct) and positioned in arbitrary order. David Blaine wants to sort the railway cars in the... | ```python
## KALAM
N = 100000 + 77
n = int(input())
a = list(map(int , input().split()))
T = [0] * N
A = 0
for i in a:
T[i] = T[i - 1] + 1
A = max(A , T[i])
print(n - A)
``` | 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,680,959,192 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 68 | 77 | 1,945,600 | import sys
input = sys.stdin.readline
n, s = map(int, input().split())
if s > n:
print(0)
else:
c = 0
for i in range(s, min(s+200, n)+1):
a = sum(int(j) for j in str(i))
if i-s >= a:
c += 1
print(n-min(s+200, n)+c)
| 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
import sys
input = sys.stdin.readline
n, s = map(int, input().split())
if s > n:
print(0)
else:
c = 0
for i in range(s, min(s+200, n)+1):
a = sum(int(j) for j in str(i))
if i-s >= a:
c += 1
print(n-min(s+200, n)+c)
``` | 3 | |
996 | A | Hit the Lottery | PROGRAMMING | 800 | [
"dp",
"greedy"
] | null | null | Allen has a LOT of money. He has $n$ dollars in the bank. For security reasons, he wants to withdraw it in cash (we will not disclose the reasons here). The denominations for dollar bills are $1$, $5$, $10$, $20$, $100$. What is the minimum number of bills Allen could receive after withdrawing his entire balance? | The first and only line of input contains a single integer $n$ ($1 \le n \le 10^9$). | Output the minimum number of bills that Allen could receive. | [
"125\n",
"43\n",
"1000000000\n"
] | [
"3\n",
"5\n",
"10000000\n"
] | In the first sample case, Allen can withdraw this with a $100$ dollar bill, a $20$ dollar bill, and a $5$ dollar bill. There is no way for Allen to receive $125$ dollars in one or two bills.
In the second sample case, Allen can withdraw two $20$ dollar bills and three $1$ dollar bills.
In the third sample case, Allen... | 500 | [
{
"input": "125",
"output": "3"
},
{
"input": "43",
"output": "5"
},
{
"input": "1000000000",
"output": "10000000"
},
{
"input": "4",
"output": "4"
},
{
"input": "5",
"output": "1"
},
{
"input": "1",
"output": "1"
},
{
"input": "74",
"o... | 1,686,573,880 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 6 | 31 | 0 | n = int(input())
l = (1, 5, 10, 20, 50, 100)
res = n // 100
n %= 100
dp = [0]
for i in range(1, n + 1):
Min = 1000
for j in l:
if j > i:
break
Min = min(Min, dp[i - j])
dp.append(Min + 1)
res += dp[-1]
print(res) | Title: Hit the Lottery
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Allen has a LOT of money. He has $n$ dollars in the bank. For security reasons, he wants to withdraw it in cash (we will not disclose the reasons here). The denominations for dollar bills are $1$, $5$, $10$, $20$, $100$... | ```python
n = int(input())
l = (1, 5, 10, 20, 50, 100)
res = n // 100
n %= 100
dp = [0]
for i in range(1, n + 1):
Min = 1000
for j in l:
if j > i:
break
Min = min(Min, dp[i - j])
dp.append(Min + 1)
res += dp[-1]
print(res)
``` | 0 | |
842 | A | Kirill And The Game | PROGRAMMING | 1,200 | [
"brute force",
"two pointers"
] | null | null | Kirill plays a new computer game. He came to the potion store where he can buy any potion. Each potion is characterized by two integers — amount of experience and cost. The efficiency of a potion is the ratio of the amount of experience to the cost. Efficiency may be a non-integer number.
For each two integer numbers ... | First string contains five integer numbers *l*, *r*, *x*, *y*, *k* (1<=≤<=*l*<=≤<=*r*<=≤<=107, 1<=≤<=*x*<=≤<=*y*<=≤<=107, 1<=≤<=*k*<=≤<=107). | Print "YES" without quotes if a potion with efficiency exactly *k* can be bought in the store and "NO" without quotes otherwise.
You can output each of the letters in any register. | [
"1 10 1 10 1\n",
"1 5 6 10 1\n"
] | [
"YES",
"NO"
] | none | 500 | [
{
"input": "1 10 1 10 1",
"output": "YES"
},
{
"input": "1 5 6 10 1",
"output": "NO"
},
{
"input": "1 1 1 1 1",
"output": "YES"
},
{
"input": "1 1 1 1 2",
"output": "NO"
},
{
"input": "1 100000 1 100000 100000",
"output": "YES"
},
{
"input": "1 100000 ... | 1,655,309,395 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 13 | 77 | 1,228,800 | import sys
input = sys.stdin.readline
l, r, x, y, k = map(int, input().split())
if x*k > r or y*k < l:
print("NO")
else:
for i in range(x, y+1, k):
if l <= i <= r:
print("YES")
break
else:
print("NO") | Title: Kirill And The Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Kirill plays a new computer game. He came to the potion store where he can buy any potion. Each potion is characterized by two integers — amount of experience and cost. The efficiency of a potion is the ratio of the... | ```python
import sys
input = sys.stdin.readline
l, r, x, y, k = map(int, input().split())
if x*k > r or y*k < l:
print("NO")
else:
for i in range(x, y+1, k):
if l <= i <= r:
print("YES")
break
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,671,695,515 | 2,147,483,647 | Python 3 | OK | TESTS | 35 | 92 | 0 | a,b = map(int,input().split())
res = a*b // 2
print(res) | 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
a,b = map(int,input().split())
res = a*b // 2
print(res)
``` | 3.977 |
988 | C | Equal Sums | PROGRAMMING | 1,400 | [
"implementation",
"sortings"
] | null | null | You are given $k$ sequences of integers. The length of the $i$-th sequence equals to $n_i$.
You have to choose exactly two sequences $i$ and $j$ ($i \ne j$) such that you can remove exactly one element in each of them in such a way that the sum of the changed sequence $i$ (its length will be equal to $n_i - 1$) equals... | The first line contains an integer $k$ ($2 \le k \le 2 \cdot 10^5$) — the number of sequences.
Then $k$ pairs of lines follow, each pair containing a sequence.
The first line in the $i$-th pair contains one integer $n_i$ ($1 \le n_i < 2 \cdot 10^5$) — the length of the $i$-th sequence. The second line of the $i$-t... | If it is impossible to choose two sequences such that they satisfy given conditions, print "NO" (without quotes). Otherwise in the first line print "YES" (without quotes), in the second line — two integers $i$, $x$ ($1 \le i \le k, 1 \le x \le n_i$), in the third line — two integers $j$, $y$ ($1 \le j \le k, 1 \le y \l... | [
"2\n5\n2 3 1 3 2\n6\n1 1 2 2 2 1\n",
"3\n1\n5\n5\n1 1 1 1 1\n2\n2 3\n",
"4\n6\n2 2 2 2 2 2\n5\n2 2 2 2 2\n3\n2 2 2\n5\n2 2 2 2 2\n"
] | [
"YES\n2 6\n1 2\n",
"NO\n",
"YES\n2 2\n4 1\n"
] | In the first example there are two sequences $[2, 3, 1, 3, 2]$ and $[1, 1, 2, 2, 2, 1]$. You can remove the second element from the first sequence to get $[2, 1, 3, 2]$ and you can remove the sixth element from the second sequence to get $[1, 1, 2, 2, 2]$. The sums of the both resulting sequences equal to $8$, i.e. the... | 0 | [
{
"input": "2\n5\n2 3 1 3 2\n6\n1 1 2 2 2 1",
"output": "YES\n2 1\n1 4"
},
{
"input": "3\n1\n5\n5\n1 1 1 1 1\n2\n2 3",
"output": "NO"
},
{
"input": "4\n6\n2 2 2 2 2 2\n5\n2 2 2 2 2\n3\n2 2 2\n5\n2 2 2 2 2",
"output": "YES\n4 1\n2 5"
},
{
"input": "2\n2\n0 -10000\n2\n10000 0",... | 1,671,610,551 | 3,951 | PyPy 3-64 | TIME_LIMIT_EXCEEDED | TESTS | 28 | 2,000 | 31,232,000 | from collections import defaultdict
import sys
input = sys.stdin.readline
k = int(input())
lst = []
for _ in range(k):
n = int(input())
arr = list(map(int, input().split()))
d = {}
s = sum(arr)
for i, e in enumerate(arr):
if s - e not in d:
d[s-e] = i+1
lst.a... | Title: Equal Sums
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given $k$ sequences of integers. The length of the $i$-th sequence equals to $n_i$.
You have to choose exactly two sequences $i$ and $j$ ($i \ne j$) such that you can remove exactly one element in each of them in su... | ```python
from collections import defaultdict
import sys
input = sys.stdin.readline
k = int(input())
lst = []
for _ in range(k):
n = int(input())
arr = list(map(int, input().split()))
d = {}
s = sum(arr)
for i, e in enumerate(arr):
if s - e not in d:
d[s-e] = i+1
... | 0 | |
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,687,257,497 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 30 | 0 | def x(w):
if w == 2:
return ("NO")
elif w % 2 == 0:
return("YES")
else:
return("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
def x(w):
if w == 2:
return ("NO")
elif w % 2 == 0:
return("YES")
else:
return("NO")
``` | 0 |
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,686,832,469 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 15 | 0 | a = int (input())
b = int (input())
c = int (input())
if ( a == 1 , b == 2 , c == 3):
print ((a + b)* c)
elif (a > 1 , b > 2 , c > 3):
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 , b == 2 , c == 3):
print ((a + b)* c)
elif (a > 1 , b > 2 , c > 3):
print (a * b * c)
``` | 0 | |
295 | A | Greg and Array | PROGRAMMING | 1,400 | [
"data structures",
"implementation"
] | null | null | Greg has an array *a*<==<=*a*1,<=*a*2,<=...,<=*a**n* and *m* operations. Each operation looks as: *l**i*, *r**i*, *d**i*, (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*). To apply operation *i* to the array means to increase all array elements with numbers *l**i*,<=*l**i*<=+<=1,<=...,<=*r**i* by value *d**i*.
Greg wrote down *k* qu... | The first line contains integers *n*, *m*, *k* (1<=≤<=*n*,<=*m*,<=*k*<=≤<=105). The second line contains *n* integers: *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=105) — the initial array.
Next *m* lines contain operations, the operation number *i* is written as three integers: *l**i*, *r**i*, *d**i*, (1<=≤<=*l**i*<=... | On a single line print *n* integers *a*1,<=*a*2,<=...,<=*a**n* — the array after executing all the queries. Separate the printed numbers by spaces.
Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams of the %I64d specifier. | [
"3 3 3\n1 2 3\n1 2 1\n1 3 2\n2 3 4\n1 2\n1 3\n2 3\n",
"1 1 1\n1\n1 1 1\n1 1\n",
"4 3 6\n1 2 3 4\n1 2 1\n2 3 2\n3 4 4\n1 2\n1 3\n2 3\n1 2\n1 3\n2 3\n"
] | [
"9 18 17\n",
"2\n",
"5 18 31 20\n"
] | none | 500 | [
{
"input": "3 3 3\n1 2 3\n1 2 1\n1 3 2\n2 3 4\n1 2\n1 3\n2 3",
"output": "9 18 17"
},
{
"input": "1 1 1\n1\n1 1 1\n1 1",
"output": "2"
},
{
"input": "4 3 6\n1 2 3 4\n1 2 1\n2 3 2\n3 4 4\n1 2\n1 3\n2 3\n1 2\n1 3\n2 3",
"output": "5 18 31 20"
},
{
"input": "1 1 1\n0\n1 1 0\n1 1... | 1,658,824,091 | 2,147,483,647 | PyPy 3-64 | TIME_LIMIT_EXCEEDED | TESTS | 25 | 1,500 | 17,100,800 | import sys
input = sys.stdin.readline
n, m, k = map(int, input().split())
w = list(map(int, input().split()))
g = [list(map(int, input().split())) for _ in range(m)]
d = [0]*m
for _ in range(k):
x, y = map(int, input().split())
for i in range(x-1, y):
d[i] += 1
for i in range(m):
fo... | Title: Greg and Array
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Greg has an array *a*<==<=*a*1,<=*a*2,<=...,<=*a**n* and *m* operations. Each operation looks as: *l**i*, *r**i*, *d**i*, (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*). To apply operation *i* to the array means to increase all array... | ```python
import sys
input = sys.stdin.readline
n, m, k = map(int, input().split())
w = list(map(int, input().split()))
g = [list(map(int, input().split())) for _ in range(m)]
d = [0]*m
for _ in range(k):
x, y = map(int, input().split())
for i in range(x-1, y):
d[i] += 1
for i in range(m... | 0 | |
417 | C | Football | PROGRAMMING | 1,400 | [
"constructive algorithms",
"graphs",
"implementation"
] | null | null | One day, at the "Russian Code Cup" event it was decided to play football as an out of competition event. All participants was divided into *n* teams and played several matches, two teams could not play against each other more than once.
The appointed Judge was the most experienced member — Pavel. But since he was the ... | The first line contains two integers — *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=1000). | In the first line print an integer *m* — number of the played games. The following *m* lines should contain the information about all the matches, one match per line. The *i*-th line should contain two integers *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*; *a**i*<=≠<=*b**i*). The numbers *a**i* and *b**i* mean, tha... | [
"3 1\n"
] | [
"3\n1 2\n2 3\n3 1\n"
] | none | 1,500 | [
{
"input": "3 1",
"output": "3\n1 2\n2 3\n3 1"
},
{
"input": "7 3",
"output": "21\n1 2\n1 3\n1 4\n2 3\n2 4\n2 5\n3 4\n3 5\n3 6\n4 5\n4 6\n4 7\n5 6\n5 7\n5 1\n6 7\n6 1\n6 2\n7 1\n7 2\n7 3"
},
{
"input": "4 1",
"output": "4\n1 2\n2 3\n3 4\n4 1"
},
{
"input": "5 2",
"output"... | 1,604,425,777 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 25 | 1,000 | 307,200 | n,k=map(int,input().split())
a=n*(n-1)//2
if(n*k>a):
print(-1)
else:
print(n*k)
i=1
while(i<=n):
k1=1
for j in range(k):
a=i+j+1
if(a>n):
print(i,k1)
k1+=1
else:
print(i,a)
i+=1
| Title: Football
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day, at the "Russian Code Cup" event it was decided to play football as an out of competition event. All participants was divided into *n* teams and played several matches, two teams could not play against each other more ... | ```python
n,k=map(int,input().split())
a=n*(n-1)//2
if(n*k>a):
print(-1)
else:
print(n*k)
i=1
while(i<=n):
k1=1
for j in range(k):
a=i+j+1
if(a>n):
print(i,k1)
k1+=1
else:
print(i,a)
... | 0 | |
902 | A | Visiting a Friend | PROGRAMMING | 1,100 | [
"greedy",
"implementation"
] | null | null | Pig is visiting a friend.
Pig's house is located at point 0, and his friend's house is located at point *m* on an axis.
Pig can use teleports to move along the axis.
To use a teleport, Pig should come to a certain point (where the teleport is located) and choose where to move: for each teleport there is the rightmos... | The first line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=100,<=1<=≤<=*m*<=≤<=100) — the number of teleports and the location of the friend's house.
The next *n* lines contain information about teleports.
The *i*-th of these lines contains two integers *a**i* and *b**i* (0<=≤<=*a**i*<=≤<=*b**i*<=≤<=*m*), where ... | Print "YES" if there is a path from Pig's house to his friend's house that uses only teleports, and "NO" otherwise.
You can print each letter in arbitrary case (upper or lower). | [
"3 5\n0 2\n2 4\n3 5\n",
"3 7\n0 4\n2 5\n6 7\n"
] | [
"YES\n",
"NO\n"
] | The first example is shown on the picture below:
Pig can use the first teleport from his house (point 0) to reach point 2, then using the second teleport go from point 2 to point 3, then using the third teleport go from point 3 to point 5, where his friend lives.
The second example is shown on the picture below:
You... | 500 | [
{
"input": "3 5\n0 2\n2 4\n3 5",
"output": "YES"
},
{
"input": "3 7\n0 4\n2 5\n6 7",
"output": "NO"
},
{
"input": "1 1\n0 0",
"output": "NO"
},
{
"input": "30 10\n0 7\n1 2\n1 2\n1 4\n1 4\n1 3\n2 2\n2 4\n2 6\n2 9\n2 2\n3 5\n3 8\n4 8\n4 5\n4 6\n5 6\n5 7\n6 6\n6 9\n6 7\n6 9\n7 7... | 1,513,715,742 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 46 | 5,529,600 | import sys
n,m = list(map(int, input().strip().split()))
start = 0
for _ in range(n):
a,b = list(map(int, input().strip().split()))
if start < a:
print('NO')
sys.exit(0)
start = b
print('YES')
| Title: Visiting a Friend
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Pig is visiting a friend.
Pig's house is located at point 0, and his friend's house is located at point *m* on an axis.
Pig can use teleports to move along the axis.
To use a teleport, Pig should come to a certain ... | ```python
import sys
n,m = list(map(int, input().strip().split()))
start = 0
for _ in range(n):
a,b = list(map(int, input().strip().split()))
if start < a:
print('NO')
sys.exit(0)
start = b
print('YES')
``` | 0 | |
745 | A | Hongcow Learns the Cyclic Shift | PROGRAMMING | 900 | [
"implementation",
"strings"
] | null | null | Hongcow is learning to spell! One day, his teacher gives him a word that he needs to learn to spell. Being a dutiful student, he immediately learns how to spell the word.
Hongcow has decided to try to make new words from this one. He starts by taking the word he just learned how to spell, and moves the last character ... | The first line of input will be a single string *s* (1<=≤<=|*s*|<=≤<=50), the word Hongcow initially learns how to spell. The string *s* consists only of lowercase English letters ('a'–'z'). | Output a single integer equal to the number of distinct strings that Hongcow can obtain by applying the cyclic shift arbitrarily many times to the given string. | [
"abcd\n",
"bbb\n",
"yzyz\n"
] | [
"4\n",
"1\n",
"2\n"
] | For the first sample, the strings Hongcow can generate are "abcd", "dabc", "cdab", and "bcda".
For the second sample, no matter how many times Hongcow does the cyclic shift, Hongcow can only generate "bbb".
For the third sample, the two strings Hongcow can generate are "yzyz" and "zyzy". | 500 | [
{
"input": "abcd",
"output": "4"
},
{
"input": "bbb",
"output": "1"
},
{
"input": "yzyz",
"output": "2"
},
{
"input": "abcdefghijklmnopqrstuvwxyabcdefghijklmnopqrstuvwxy",
"output": "25"
},
{
"input": "zclkjadoprqronzclkjadoprqronzclkjadoprqron",
"output": "14... | 1,481,995,183 | 2,683 | Python 3 | OK | TESTS | 28 | 62 | 4,608,000 | n = input().strip()
l = []
ans = 0
for i in range(len(n)):
if n[i:]+n[:i] not in l:
l.append(n[i:]+n[:i])
ans += 1
else:
break
print(ans) | Title: Hongcow Learns the Cyclic Shift
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Hongcow is learning to spell! One day, his teacher gives him a word that he needs to learn to spell. Being a dutiful student, he immediately learns how to spell the word.
Hongcow has decided to try to m... | ```python
n = input().strip()
l = []
ans = 0
for i in range(len(n)):
if n[i:]+n[:i] not in l:
l.append(n[i:]+n[:i])
ans += 1
else:
break
print(ans)
``` | 3 | |
56 | A | Bar | PROGRAMMING | 1,000 | [
"implementation"
] | A. Bar | 2 | 256 | According to Berland laws it is only allowed to sell alcohol to people not younger than 18 years. Vasya's job is to monitor the law's enforcement. Tonight he entered a bar and saw *n* people sitting there. For every one of them Vasya happened to determine either the age or the drink the person is having. Vasya can chec... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=100) which is the number of the bar's clients. Then follow *n* lines, each describing one visitor. A line either contains his age (an integer from 0 to 1000) or his drink (a string of capital Latin letters from 1 to 100 in length). It is guaranteed that the input da... | Print a single number which is the number of people Vasya should check to guarantee the law enforcement. | [
"5\n18\nVODKA\nCOKE\n19\n17\n"
] | [
"2\n"
] | In the sample test the second and fifth clients should be checked. | 500 | [
{
"input": "5\n18\nVODKA\nCOKE\n19\n17",
"output": "2"
},
{
"input": "2\n2\nGIN",
"output": "2"
},
{
"input": "3\nWHISKEY\n3\nGIN",
"output": "3"
},
{
"input": "4\n813\nIORBQITQXMPTFAEMEQDQIKFGKGOTNKTOSZCBRPXJLUKVLVHJYNRUJXK\nRUM\nRHVRWGODYWWTYZFLFYKCVUFFRTQDINKNWPKFHZBFWBHWI... | 1,685,260,620 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 92 | 0 | count = 0
for i in range(int(input())):
n = input()
list1 = ["ABSINTH", "BEER", "BRANDY", "CHAMPAGNE", "GIN", "RUM", "SAKE", "TEQUILA", "VODKA", "WHISKEY", "WINE"]
list2 = []
for j in range(18,101):
list2.append(str(j))
# print(list1)
if not(n in list2) or (n in list1):
... | Title: Bar
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
According to Berland laws it is only allowed to sell alcohol to people not younger than 18 years. Vasya's job is to monitor the law's enforcement. Tonight he entered a bar and saw *n* people sitting there. For every one of them Vasya h... | ```python
count = 0
for i in range(int(input())):
n = input()
list1 = ["ABSINTH", "BEER", "BRANDY", "CHAMPAGNE", "GIN", "RUM", "SAKE", "TEQUILA", "VODKA", "WHISKEY", "WINE"]
list2 = []
for j in range(18,101):
list2.append(str(j))
# print(list1)
if not(n in list2) or (n in list1):... | 0 |
659 | C | Tanya and Toys | PROGRAMMING | 1,200 | [
"greedy",
"implementation"
] | null | null | In Berland recently a new collection of toys went on sale. This collection consists of 109 types of toys, numbered with integers from 1 to 109. A toy from the new collection of the *i*-th type costs *i* bourles.
Tania has managed to collect *n* different types of toys *a*1,<=*a*2,<=...,<=*a**n* from the new collection... | The first line contains two integers *n* (1<=≤<=*n*<=≤<=100<=000) and *m* (1<=≤<=*m*<=≤<=109) — the number of types of toys that Tanya already has and the number of bourles that her mom is willing to spend on buying new toys.
The next line contains *n* distinct integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109... | In the first line print a single integer *k* — the number of different types of toys that Tanya should choose so that the number of different types of toys in her collection is maximum possible. Of course, the total cost of the selected toys should not exceed *m*.
In the second line print *k* distinct space-separated ... | [
"3 7\n1 3 4\n",
"4 14\n4 6 12 8\n"
] | [
"2\n2 5 \n",
"4\n7 2 3 1\n"
] | In the first sample mom should buy two toys: one toy of the 2-nd type and one toy of the 5-th type. At any other purchase for 7 bourles (assuming that the toys of types 1, 3 and 4 have already been bought), it is impossible to buy two and more toys. | 1,000 | [
{
"input": "3 7\n1 3 4",
"output": "2\n2 5 "
},
{
"input": "4 14\n4 6 12 8",
"output": "4\n1 2 3 5 "
},
{
"input": "5 6\n97746 64770 31551 96547 65684",
"output": "3\n1 2 3 "
},
{
"input": "10 10\n94125 56116 29758 94024 29289 31663 99794 35076 25328 58656",
"output": "4\... | 1,610,474,416 | 2,147,483,647 | Python 3 | OK | TESTS | 61 | 171 | 10,547,200 | '''I=lambda:map(int,input().split())
n,m=I()
a=set(I())
b=[]
i=1
while i<=m:
if i not in a:b.append(str(i));m-=i
i+=1
print(len(b),'\n'+' '.join(b))'''
n,m=map(int,input().split())
l=set(map(int,input().split()))
i = 1
d = []
while i <= m:
if i not in l:
d.append(i)
m -= i
... | Title: Tanya and Toys
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In Berland recently a new collection of toys went on sale. This collection consists of 109 types of toys, numbered with integers from 1 to 109. A toy from the new collection of the *i*-th type costs *i* bourles.
Tania h... | ```python
'''I=lambda:map(int,input().split())
n,m=I()
a=set(I())
b=[]
i=1
while i<=m:
if i not in a:b.append(str(i));m-=i
i+=1
print(len(b),'\n'+' '.join(b))'''
n,m=map(int,input().split())
l=set(map(int,input().split()))
i = 1
d = []
while i <= m:
if i not in l:
d.append(i)
... | 3 | |
604 | B | More Cowbell | PROGRAMMING | 1,400 | [
"binary search",
"greedy"
] | null | null | Kevin Sun wants to move his precious collection of *n* cowbells from Naperthrill to Exeter, where there is actually grass instead of corn. Before moving, he must pack his cowbells into *k* boxes of a fixed size. In order to keep his collection safe during transportation, he won't place more than two cowbells into a sin... | The first line of the input contains two space-separated integers *n* and *k* (1<=≤<=*n*<=≤<=2·*k*<=≤<=100<=000), denoting the number of cowbells and the number of boxes, respectively.
The next line contains *n* space-separated integers *s*1,<=*s*2,<=...,<=*s**n* (1<=≤<=*s*1<=≤<=*s*2<=≤<=...<=≤<=*s**n*<=≤<=1<=000<=000... | Print a single integer, the smallest *s* for which it is possible for Kevin to put all of his cowbells into *k* boxes of size *s*. | [
"2 1\n2 5\n",
"4 3\n2 3 5 9\n",
"3 2\n3 5 7\n"
] | [
"7\n",
"9\n",
"8\n"
] | In the first sample, Kevin must pack his two cowbells into the same box.
In the second sample, Kevin can pack together the following sets of cowbells: {2, 3}, {5} and {9}.
In the third sample, the optimal solution is {3, 5} and {7}. | 1,000 | [
{
"input": "2 1\n2 5",
"output": "7"
},
{
"input": "4 3\n2 3 5 9",
"output": "9"
},
{
"input": "3 2\n3 5 7",
"output": "8"
},
{
"input": "20 11\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"output": "2"
},
{
"input": "10 10\n3 15 31 61 63 63 68 94 98 100",
"outp... | 1,448,984,909 | 809 | PyPy 3 | TIME_LIMIT_EXCEEDED | PRETESTS | 7 | 2,000 | 10,444,800 | n, k = map(int, input().split())
s = list(map(int, input().split()))
maxi = 0
while 2 * (k - 1) >= (n - 1):
maxi = max(maxi, s[-1])
s.pop()
k -= 1
n -= 1
while len(s) >= 2:
maxi = max(maxi, s[-1] + s[0])
s.pop(0)
s.pop()
if len(s) == 1:
maxi = max(maxi, s[0])
print(maxi)
... | Title: More Cowbell
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Kevin Sun wants to move his precious collection of *n* cowbells from Naperthrill to Exeter, where there is actually grass instead of corn. Before moving, he must pack his cowbells into *k* boxes of a fixed size. In order t... | ```python
n, k = map(int, input().split())
s = list(map(int, input().split()))
maxi = 0
while 2 * (k - 1) >= (n - 1):
maxi = max(maxi, s[-1])
s.pop()
k -= 1
n -= 1
while len(s) >= 2:
maxi = max(maxi, s[-1] + s[0])
s.pop(0)
s.pop()
if len(s) == 1:
maxi = max(maxi, s[0])
prin... | 0 | |
832 | A | Sasha and Sticks | PROGRAMMING | 800 | [
"games",
"math"
] | null | null | It's one more school day now. Sasha doesn't like classes and is always bored at them. So, each day he invents some game and plays in it alone or with friends.
Today he invented one simple game to play with Lena, with whom he shares a desk. The rules are simple. Sasha draws *n* sticks in a row. After that the players t... | The first line contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=1018, *k*<=≤<=*n*) — the number of sticks drawn by Sasha and the number *k* — the number of sticks to be crossed out on each turn. | If Sasha wins, print "YES" (without quotes), otherwise print "NO" (without quotes).
You can print each letter in arbitrary case (upper of lower). | [
"1 1\n",
"10 4\n"
] | [
"YES\n",
"NO\n"
] | In the first example Sasha crosses out 1 stick, and then there are no sticks. So Lena can't make a move, and Sasha wins.
In the second example Sasha crosses out 4 sticks, then Lena crosses out 4 sticks, and after that there are only 2 sticks left. Sasha can't make a move. The players make equal number of moves, so Sas... | 500 | [
{
"input": "1 1",
"output": "YES"
},
{
"input": "10 4",
"output": "NO"
},
{
"input": "251656215122324104 164397544865601257",
"output": "YES"
},
{
"input": "963577813436662285 206326039287271924",
"output": "NO"
},
{
"input": "1000000000000000000 1",
"output":... | 1,673,545,909 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 41 | 46 | 0 | n, k = map(int, input().split())
if int(n/k)%2 == 1:
print('YES')
else:
print('NO')
| Title: Sasha and Sticks
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
It's one more school day now. Sasha doesn't like classes and is always bored at them. So, each day he invents some game and plays in it alone or with friends.
Today he invented one simple game to play with Lena, with ... | ```python
n, k = map(int, input().split())
if int(n/k)%2 == 1:
print('YES')
else:
print('NO')
``` | 0 | |
526 | C | Om Nom and Candies | PROGRAMMING | 2,000 | [
"brute force",
"greedy",
"math"
] | null | null | A sweet little monster Om Nom loves candies very much. One day he found himself in a rather tricky situation that required him to think a bit in order to enjoy candies the most. Would you succeed with the same task if you were on his place?
One day, when he came to his friend Evan, Om Nom didn't find him at home but h... | The single line contains five integers *C*,<=*H**r*,<=*H**b*,<=*W**r*,<=*W**b* (1<=≤<=*C*,<=*H**r*,<=*H**b*,<=*W**r*,<=*W**b*<=≤<=109). | Print a single integer — the maximum number of joy units that Om Nom can get. | [
"10 3 5 2 3\n"
] | [
"16\n"
] | In the sample test Om Nom can eat two candies of each type and thus get 16 joy units. | 1,250 | [
{
"input": "10 3 5 2 3",
"output": "16"
},
{
"input": "5 3 1 6 7",
"output": "0"
},
{
"input": "982068341 55 57 106 109",
"output": "513558662"
},
{
"input": "930064129 32726326 25428197 83013449 64501049",
"output": "363523396"
},
{
"input": "927155987 21197 1599... | 1,428,173,967 | 8,667 | Python 3 | TIME_LIMIT_EXCEEDED | PRETESTS | 2 | 1,000 | 0 | #!/usr/bin/env python3
# -*- coding: utf-8 -*-
# author: firolunis
# version: 0.1
c, hr, hb, wr, wb = input().split()
c, hr, hb, wr, wb = int(c), int(hr), int(hb), int(wr), int(wb)
varr = c // wr * hr
varb = c // wb * hb
var1 = max(varr, varb)
for i in range(c // wr - 1, 0, -1):
vart = i * hr + (c - i * wr) // wb ... | Title: Om Nom and Candies
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A sweet little monster Om Nom loves candies very much. One day he found himself in a rather tricky situation that required him to think a bit in order to enjoy candies the most. Would you succeed with the same task i... | ```python
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# author: firolunis
# version: 0.1
c, hr, hb, wr, wb = input().split()
c, hr, hb, wr, wb = int(c), int(hr), int(hb), int(wr), int(wb)
varr = c // wr * hr
varb = c // wb * hb
var1 = max(varr, varb)
for i in range(c // wr - 1, 0, -1):
vart = i * hr + (c - i * ... | 0 | |
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,515,771,305 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 62 | 5,632,000 | def issorted(l):
min = l[0]
for i in range(1,len(l)):
if(l[i] > min):
f = 1
min = l[i]
else:
return 0
return 1
s = input()
ih, ie, il1, il2, io = -1 ,-1, -1, -1, -1
if 'h' in s:
ih = s.index('h')
if ih is not -1 and 'e' in s[ih+1:]:
ie = s.index('e', ih+1)
if ie is not -1 and 'l' in s[ie+1:]:
il1 = ... | Title: Chat room
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word *s*. It is considered that Vasya managed to say hello if several letter... | ```python
def issorted(l):
min = l[0]
for i in range(1,len(l)):
if(l[i] > min):
f = 1
min = l[i]
else:
return 0
return 1
s = input()
ih, ie, il1, il2, io = -1 ,-1, -1, -1, -1
if 'h' in s:
ih = s.index('h')
if ih is not -1 and 'e' in s[ih+1:]:
ie = s.index('e', ih+1)
if ie is not -1 and 'l' in s[ie+1:... | 3.95851 |
378 | A | Playing with Dice | PROGRAMMING | 800 | [
"brute force"
] | null | null | Two players are playing a game. First each of them writes an integer from 1 to 6, and then a dice is thrown. The player whose written number got closer to the number on the dice wins. If both payers have the same difference, it's a draw.
The first player wrote number *a*, the second player wrote number *b*. How many w... | The single line contains two integers *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=6) — the numbers written on the paper by the first and second player, correspondingly. | Print three integers: the number of ways to throw the dice at which the first player wins, the game ends with a draw or the second player wins, correspondingly. | [
"2 5\n",
"2 4\n"
] | [
"3 0 3\n",
"2 1 3\n"
] | The dice is a standard cube-shaped six-sided object with each side containing a number from 1 to 6, and where all numbers on all sides are distinct.
You can assume that number *a* is closer to number *x* than number *b*, if |*a* - *x*| < |*b* - *x*|. | 500 | [
{
"input": "2 5",
"output": "3 0 3"
},
{
"input": "2 4",
"output": "2 1 3"
},
{
"input": "5 3",
"output": "2 1 3"
},
{
"input": "1 6",
"output": "3 0 3"
},
{
"input": "5 1",
"output": "3 1 2"
},
{
"input": "6 3",
"output": "2 0 4"
},
{
"inp... | 1,639,462,631 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 38 | 109 | 0 | # import sys
# sys.stdout = open('DSA/Stacks/output.txt', 'w')
# sys.stdin = open('DSA/Stacks/input.txt', 'r')
a,b = map(int, input().split())
wa=0
wb=0
d=0
for i in range(1,7):
if abs(i-a)>abs(i-b):
wa+=1
elif abs(i-a)<abs(i-b):
wb+=1
else:
d+=1
print(wb,d,wa) | Title: Playing with Dice
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Two players are playing a game. First each of them writes an integer from 1 to 6, and then a dice is thrown. The player whose written number got closer to the number on the dice wins. If both payers have the same diff... | ```python
# import sys
# sys.stdout = open('DSA/Stacks/output.txt', 'w')
# sys.stdin = open('DSA/Stacks/input.txt', 'r')
a,b = map(int, input().split())
wa=0
wb=0
d=0
for i in range(1,7):
if abs(i-a)>abs(i-b):
wa+=1
elif abs(i-a)<abs(i-b):
wb+=1
else:
d+=1
print(wb,... | 3 | |
709 | A | Juicer | PROGRAMMING | 900 | [
"implementation"
] | null | null | Kolya is going to make fresh orange juice. He has *n* oranges of sizes *a*1,<=*a*2,<=...,<=*a**n*. Kolya will put them in the juicer in the fixed order, starting with orange of size *a*1, then orange of size *a*2 and so on. To be put in the juicer the orange must have size not exceeding *b*, so if Kolya sees an orange ... | The first line of the input contains three integers *n*, *b* and *d* (1<=≤<=*n*<=≤<=100<=000, 1<=≤<=*b*<=≤<=*d*<=≤<=1<=000<=000) — the number of oranges, the maximum size of the orange that fits in the juicer and the value *d*, which determines the condition when the waste section should be emptied.
The second line co... | Print one integer — the number of times Kolya will have to empty the waste section. | [
"2 7 10\n5 6\n",
"1 5 10\n7\n",
"3 10 10\n5 7 7\n",
"1 1 1\n1\n"
] | [
"1\n",
"0\n",
"1\n",
"0\n"
] | In the first sample, Kolya will squeeze the juice from two oranges and empty the waste section afterwards.
In the second sample, the orange won't fit in the juicer so Kolya will have no juice at all. | 500 | [
{
"input": "2 7 10\n5 6",
"output": "1"
},
{
"input": "1 5 10\n7",
"output": "0"
},
{
"input": "3 10 10\n5 7 7",
"output": "1"
},
{
"input": "1 1 1\n1",
"output": "0"
},
{
"input": "2 951637 951638\n44069 951637",
"output": "1"
},
{
"input": "50 100 12... | 1,692,306,663 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 5 | 61 | 12,800,000 | def my_solution(b, d, oranges):
empty = 0
waste = 0
for orange in oranges:
if orange < b:
waste += orange
if waste > d:
empty += 1
waste = 0
print(empty)
n, b, d = map(int, input().split())
oranges = [int(orange) for orange i... | Title: Juicer
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Kolya is going to make fresh orange juice. He has *n* oranges of sizes *a*1,<=*a*2,<=...,<=*a**n*. Kolya will put them in the juicer in the fixed order, starting with orange of size *a*1, then orange of size *a*2 and so on. To b... | ```python
def my_solution(b, d, oranges):
empty = 0
waste = 0
for orange in oranges:
if orange < b:
waste += orange
if waste > d:
empty += 1
waste = 0
print(empty)
n, b, d = map(int, input().split())
oranges = [int(orange) fo... | 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,672,077,817 | 817 | Python 3 | OK | TESTS | 20 | 46 | 0 | import math
def bonAppetit(n, m, a):
return math.ceil(n / a) * math.ceil(m / a)
if __name__ == '__main__':
N, M, A = input().rstrip().split()
N = int(N)
M = int(M)
A = int(A)
print(bonAppetit(N, M, A))
| 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
def bonAppetit(n, m, a):
return math.ceil(n / a) * math.ceil(m / a)
if __name__ == '__main__':
N, M, A = input().rstrip().split()
N = int(N)
M = int(M)
A = int(A)
print(bonAppetit(N, M, A))
``` | 3.977 |
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,688,147,415 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 62 | 0 | # cook your dish here
a=[int(i) for i in input().split()]
b=[int(i) for i in input().split()]
dif=0
mi=max(b)
for i in range(a[1]):
for j in range(i+1,a[1]):
dif=b[i]-b[j]
if dif>0:
mi=min(dif,mi)
print(mi)
| 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
# cook your dish here
a=[int(i) for i in input().split()]
b=[int(i) for i in input().split()]
dif=0
mi=max(b)
for i in range(a[1]):
for j in range(i+1,a[1]):
dif=b[i]-b[j]
if dif>0:
mi=min(dif,mi)
print(mi)
``` | 0 | |
911 | C | Three Garlands | PROGRAMMING | 1,400 | [
"brute force",
"constructive algorithms"
] | null | null | Mishka is decorating the Christmas tree. He has got three garlands, and all of them will be put on the tree. After that Mishka will switch these garlands on.
When a garland is switched on, it periodically changes its state — sometimes it is lit, sometimes not. Formally, if *i*-th garland is switched on during *x*-th s... | The first line contains three integers *k*1, *k*2 and *k*3 (1<=≤<=*k**i*<=≤<=1500) — time intervals of the garlands. | If Mishka can choose moments of time to switch on the garlands in such a way that each second after switching the garlands on at least one garland will be lit, print YES.
Otherwise, print NO. | [
"2 2 3\n",
"4 2 3\n"
] | [
"YES\n",
"NO\n"
] | In the first example Mishka can choose *x*<sub class="lower-index">1</sub> = 1, *x*<sub class="lower-index">2</sub> = 2, *x*<sub class="lower-index">3</sub> = 1. The first garland will be lit during seconds 1, 3, 5, 7, ..., the second — 2, 4, 6, 8, ..., which already cover all the seconds after the 2-nd one. It doesn't... | 0 | [
{
"input": "2 2 3",
"output": "YES"
},
{
"input": "4 2 3",
"output": "NO"
},
{
"input": "1499 1498 1500",
"output": "NO"
},
{
"input": "1500 1500 1500",
"output": "NO"
},
{
"input": "100 4 1",
"output": "YES"
},
{
"input": "4 2 4",
"output": "YES"
... | 1,517,525,387 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 5 | 62 | 5,632,000 | k = sorted(map(int, input().split()))
print('YES' if k[0] == 1 or k[1] == 2 or k[0] == 3 and k[2] == 3 else 'NO') | Title: Three Garlands
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mishka is decorating the Christmas tree. He has got three garlands, and all of them will be put on the tree. After that Mishka will switch these garlands on.
When a garland is switched on, it periodically changes its st... | ```python
k = sorted(map(int, input().split()))
print('YES' if k[0] == 1 or k[1] == 2 or k[0] == 3 and k[2] == 3 else 'NO')
``` | 0 | |
6 | A | Triangle | PROGRAMMING | 900 | [
"brute force",
"geometry"
] | A. Triangle | 2 | 64 | Johnny has a younger sister Anne, who is very clever and smart. As she came home from the kindergarten, she told his brother about the task that her kindergartener asked her to solve. The task was just to construct a triangle out of four sticks of different colours. Naturally, one of the sticks is extra. It is not allo... | The first line of the input contains four space-separated positive integer numbers not exceeding 100 — lengthes of the sticks. | Output TRIANGLE if it is possible to construct a non-degenerate triangle. Output SEGMENT if the first case cannot take place and it is possible to construct a degenerate triangle. Output IMPOSSIBLE if it is impossible to construct any triangle. Remember that you are to use three sticks. It is not allowed to break the s... | [
"4 2 1 3\n",
"7 2 2 4\n",
"3 5 9 1\n"
] | [
"TRIANGLE\n",
"SEGMENT\n",
"IMPOSSIBLE\n"
] | none | 0 | [
{
"input": "4 2 1 3",
"output": "TRIANGLE"
},
{
"input": "7 2 2 4",
"output": "SEGMENT"
},
{
"input": "3 5 9 1",
"output": "IMPOSSIBLE"
},
{
"input": "3 1 5 1",
"output": "IMPOSSIBLE"
},
{
"input": "10 10 10 10",
"output": "TRIANGLE"
},
{
"input": "11 ... | 1,651,117,178 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 83 | 124 | 0 |
nums = list(map(int, input().split(' ')))
nums.sort()
if nums[0]+nums[1] > nums[2] or nums[1]+nums[2] > nums[3]: print("TRIANGLE")
elif nums[0]+nums[1] == nums[2] or nums[1]+nums[2] == nums[3]: print("SEGMENT")
else: print("IMPOSSIBLE") | Title: Triangle
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
Johnny has a younger sister Anne, who is very clever and smart. As she came home from the kindergarten, she told his brother about the task that her kindergartener asked her to solve. The task was just to construct a triangle out o... | ```python
nums = list(map(int, input().split(' ')))
nums.sort()
if nums[0]+nums[1] > nums[2] or nums[1]+nums[2] > nums[3]: print("TRIANGLE")
elif nums[0]+nums[1] == nums[2] or nums[1]+nums[2] == nums[3]: print("SEGMENT")
else: print("IMPOSSIBLE")
``` | 3.969 |
558 | B | Amr and The Large Array | PROGRAMMING | 1,300 | [
"implementation"
] | null | null | Amr has got a large array of size *n*. Amr doesn't like large arrays so he intends to make it smaller.
Amr doesn't care about anything in the array except the beauty of it. The beauty of the array is defined to be the maximum number of times that some number occurs in this array. He wants to choose the smallest subseg... | The first line contains one number *n* (1<=≤<=*n*<=≤<=105), the size of the array.
The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=106), representing elements of the array. | Output two integers *l*,<=*r* (1<=≤<=*l*<=≤<=*r*<=≤<=*n*), the beginning and the end of the subsegment chosen respectively.
If there are several possible answers you may output any of them. | [
"5\n1 1 2 2 1\n",
"5\n1 2 2 3 1\n",
"6\n1 2 2 1 1 2\n"
] | [
"1 5",
"2 3",
"1 5"
] | A subsegment *B* of an array *A* from *l* to *r* is an array of size *r* - *l* + 1 where *B*<sub class="lower-index">*i*</sub> = *A*<sub class="lower-index">*l* + *i* - 1</sub> for all 1 ≤ *i* ≤ *r* - *l* + 1 | 1,000 | [
{
"input": "5\n1 1 2 2 1",
"output": "1 5"
},
{
"input": "5\n1 2 2 3 1",
"output": "2 3"
},
{
"input": "6\n1 2 2 1 1 2",
"output": "1 5"
},
{
"input": "10\n1 1000000 2 1000000 3 2 1000000 1 2 1",
"output": "2 7"
},
{
"input": "10\n1 2 3 4 5 5 1 2 3 4",
"output... | 1,638,694,280 | 2,147,483,647 | PyPy 3-64 | TIME_LIMIT_EXCEEDED | TESTS | 9 | 1,000 | 13,004,800 | from collections import Counter
n = int(input())
L = list(map(int,input().split()))
c = Counter(L)
U = c.values()
res = []
for k in c.keys():
if c[k] == max(U):
res.append(k)
ans = []
for c in res:
first = -1
last = -1
for i in range(n):
if L[i] == c:
first = i
... | Title: Amr and The Large Array
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Amr has got a large array of size *n*. Amr doesn't like large arrays so he intends to make it smaller.
Amr doesn't care about anything in the array except the beauty of it. The beauty of the array is defined to... | ```python
from collections import Counter
n = int(input())
L = list(map(int,input().split()))
c = Counter(L)
U = c.values()
res = []
for k in c.keys():
if c[k] == max(U):
res.append(k)
ans = []
for c in res:
first = -1
last = -1
for i in range(n):
if L[i] == c:
first = ... | 0 | |
597 | B | Restaurant | PROGRAMMING | 1,600 | [
"dp",
"greedy",
"sortings"
] | null | null | A restaurant received *n* orders for the rental. Each rental order reserve the restaurant for a continuous period of time, the *i*-th order is characterized by two time values — the start time *l**i* and the finish time *r**i* (*l**i*<=≤<=*r**i*).
Restaurant management can accept and reject orders. What is the maximal... | The first line contains integer number *n* (1<=≤<=*n*<=≤<=5·105) — number of orders. The following *n* lines contain integer values *l**i* and *r**i* each (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=109). | Print the maximal number of orders that can be accepted. | [
"2\n7 11\n4 7\n",
"5\n1 2\n2 3\n3 4\n4 5\n5 6\n",
"6\n4 8\n1 5\n4 7\n2 5\n1 3\n6 8\n"
] | [
"1\n",
"3\n",
"2\n"
] | none | 1,000 | [
{
"input": "2\n7 11\n4 7",
"output": "1"
},
{
"input": "5\n1 2\n2 3\n3 4\n4 5\n5 6",
"output": "3"
},
{
"input": "6\n4 8\n1 5\n4 7\n2 5\n1 3\n6 8",
"output": "2"
},
{
"input": "1\n1 1",
"output": "1"
},
{
"input": "2\n4 6\n4 8",
"output": "1"
},
{
"inp... | 1,447,324,939 | 2,147,483,647 | Python 3 | OK | TESTS | 70 | 2,994 | 40,960,000 | ints = lambda:list(map(int,input().split()))
rd = lambda:input()
n=ints()[0]
A = []
for i in range(n):
l,r = ints()
A.append((r,r-l))
A.sort()
cnt,ct = 0,0
for p in A:
if ct + p[1] > p[0]:
continue
else:
ct = p[0] + 1
cnt+=1
print (cnt)
| Title: Restaurant
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A restaurant received *n* orders for the rental. Each rental order reserve the restaurant for a continuous period of time, the *i*-th order is characterized by two time values — the start time *l**i* and the finish time *r**... | ```python
ints = lambda:list(map(int,input().split()))
rd = lambda:input()
n=ints()[0]
A = []
for i in range(n):
l,r = ints()
A.append((r,r-l))
A.sort()
cnt,ct = 0,0
for p in A:
if ct + p[1] > p[0]:
continue
else:
ct = p[0] + 1
cnt+=1
print (cnt)
``` | 3 | |
35 | D | Animals | PROGRAMMING | 1,700 | [
"dp",
"greedy"
] | D. Animals | 2 | 64 | Once upon a time DravDe, an outstanding person famous for his professional achievements (as you must remember, he works in a warehouse storing Ogudar-Olok, a magical but non-alcoholic drink) came home after a hard day. That day he had to drink 9875 boxes of the drink and, having come home, he went to bed at once.
Drav... | The first input line contains integers *n* and *X* (1<=≤<=*n*<=≤<=100,<=1<=≤<=*X*<=≤<=104) — amount of days in DravDe’s dream and the total amount of food (in tons) that was there initially. The second line contains integers *c**i* (1<=≤<=*c**i*<=≤<=300). Numbers in the second line are divided by a space. | Output the only number — the maximum possible amount of animals on the farm by the end of the *n*-th day given that the food was enough for everybody. | [
"3 4\n1 1 1\n",
"3 6\n1 1 1\n"
] | [
"2\n",
"3\n"
] | Note to the first example: DravDe leaves the second and the third animal on the farm. The second animal will eat one ton of food on the second day and one ton on the third day. The third animal will eat one ton of food on the third day. | 2,000 | [
{
"input": "3 4\n1 1 1",
"output": "2"
},
{
"input": "3 6\n1 1 1",
"output": "3"
},
{
"input": "1 12\n1",
"output": "1"
},
{
"input": "3 100\n1 1 1",
"output": "3"
},
{
"input": "5 75\n1 1 1 1 1",
"output": "5"
},
{
"input": "7 115\n1 1 1 1 1 1 1",
... | 1,506,567,264 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 92 | 0 | n,m=map(int,input().split(" "))
L=list(map(int,input().split(" ")))
cont=0
at=0
for k in range(n):
ac=L[k]
if(at*2+ac<=m):
cont+=1
at=ac+at
print(cont)
| Title: Animals
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
Once upon a time DravDe, an outstanding person famous for his professional achievements (as you must remember, he works in a warehouse storing Ogudar-Olok, a magical but non-alcoholic drink) came home after a hard day. That day he h... | ```python
n,m=map(int,input().split(" "))
L=list(map(int,input().split(" ")))
cont=0
at=0
for k in range(n):
ac=L[k]
if(at*2+ac<=m):
cont+=1
at=ac+at
print(cont)
``` | -1 |
625 | B | War of the Corporations | PROGRAMMING | 1,200 | [
"constructive algorithms",
"greedy",
"strings"
] | null | null | A long time ago, in a galaxy far far away two giant IT-corporations Pineapple and Gogol continue their fierce competition. Crucial moment is just around the corner: Gogol is ready to release it's new tablet Lastus 3000.
This new device is equipped with specially designed artificial intelligence (AI). Employees of Pine... | The first line of the input contains the name of AI designed by Gogol, its length doesn't exceed 100<=000 characters. Second line contains the name of the phone released by Pineapple 200 years ago, its length doesn't exceed 30. Both string are non-empty and consist of only small English letters. | Print the minimum number of characters that must be replaced with "#" in order to obtain that the name of the phone doesn't occur in the name of AI as a substring. | [
"intellect\ntell\n",
"google\napple\n",
"sirisiri\nsir\n"
] | [
"1",
"0",
"2"
] | In the first sample AI's name may be replaced with "int#llect".
In the second sample Gogol can just keep things as they are.
In the third sample one of the new possible names of AI may be "s#ris#ri". | 750 | [
{
"input": "intellect\ntell",
"output": "1"
},
{
"input": "google\napple",
"output": "0"
},
{
"input": "sirisiri\nsir",
"output": "2"
},
{
"input": "sirisiri\nsiri",
"output": "2"
},
{
"input": "aaaaaaa\naaaa",
"output": "1"
},
{
"input": "bbbbbb\nbb",... | 1,487,400,121 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 46 | 4,608,000 | string=str(input())
substring=str(input())
n=0
boolean=True
print(string.index(substring))
while(boolean):
if substring in string:
string=string[:string.index(substring)+len(substring)].replace(substring,"")+string[string.index(substring)+len(substring):]
n+=1
else:
boolean=False
print(n... | Title: War of the Corporations
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A long time ago, in a galaxy far far away two giant IT-corporations Pineapple and Gogol continue their fierce competition. Crucial moment is just around the corner: Gogol is ready to release it's new tablet Last... | ```python
string=str(input())
substring=str(input())
n=0
boolean=True
print(string.index(substring))
while(boolean):
if substring in string:
string=string[:string.index(substring)+len(substring)].replace(substring,"")+string[string.index(substring)+len(substring):]
n+=1
else:
boolean=Fal... | 0 | |
989 | A | A Blend of Springtime | PROGRAMMING | 900 | [
"implementation",
"strings"
] | null | null | "What a pity it's already late spring," sighs Mino with regret, "one more drizzling night and they'd be gone."
"But these blends are at their best, aren't they?" Absorbed in the landscape, Kanno remains optimistic.
The landscape can be expressed as a row of consecutive cells, each of which either contains a flower o... | The first and only line of input contains a non-empty string $s$ consisting of uppercase English letters 'A', 'B', 'C' and characters '.' (dots) only ($\lvert s \rvert \leq 100$) — denoting cells containing an amber flower, a buff one, a canary yellow one, and no flowers, respectively. | Output "Yes" if it's possible that all three colours appear in some cell, and "No" otherwise.
You can print each letter in any case (upper or lower). | [
".BAC.\n",
"AA..CB\n"
] | [
"Yes\n",
"No\n"
] | In the first example, the buff and canary yellow flowers can leave their petals in the central cell, blending all three colours in it.
In the second example, it's impossible to satisfy the requirement because there is no way that amber and buff meet in any cell. | 500 | [
{
"input": ".BAC.",
"output": "Yes"
},
{
"input": "AA..CB",
"output": "No"
},
{
"input": ".",
"output": "No"
},
{
"input": "ACB.AAAAAA",
"output": "Yes"
},
{
"input": "B.BC.BBBCA",
"output": "Yes"
},
{
"input": "BA..CAB..B",
"output": "Yes"
},
... | 1,528,896,918 | 2,147,483,647 | Python 3 | OK | TESTS | 37 | 93 | 0 |
s = input()
lens = int(len(s))
for i in range(lens - 2):
if s[i:i+3] in ['ABC','ACB','BAC','BCA','CAB','CBA']:
print('Yes')
break
else:
print('No')
| Title: A Blend of Springtime
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
"What a pity it's already late spring," sighs Mino with regret, "one more drizzling night and they'd be gone."
"But these blends are at their best, aren't they?" Absorbed in the landscape, Kanno remains optimisti... | ```python
s = input()
lens = int(len(s))
for i in range(lens - 2):
if s[i:i+3] in ['ABC','ACB','BAC','BCA','CAB','CBA']:
print('Yes')
break
else:
print('No')
``` | 3 | |
96 | A | Football | PROGRAMMING | 900 | [
"implementation",
"strings"
] | A. Football | 2 | 256 | Petya loves football very much. One day, as he was watching a football match, he was writing the players' current positions on a piece of paper. To simplify the situation he depicted it as a string consisting of zeroes and ones. A zero corresponds to players of one team; a one corresponds to players of another team. If... | The first input line contains a non-empty string consisting of characters "0" and "1", which represents players. The length of the string does not exceed 100 characters. There's at least one player from each team present on the field. | Print "YES" if the situation is dangerous. Otherwise, print "NO". | [
"001001\n",
"1000000001\n"
] | [
"NO\n",
"YES\n"
] | none | 500 | [
{
"input": "001001",
"output": "NO"
},
{
"input": "1000000001",
"output": "YES"
},
{
"input": "00100110111111101",
"output": "YES"
},
{
"input": "11110111111111111",
"output": "YES"
},
{
"input": "01",
"output": "NO"
},
{
"input": "10100101",
"outp... | 1,687,972,825 | 2,147,483,647 | Python 3 | OK | TESTS | 44 | 92 | 0 | s = input()
dangerous = False
count =1
for i in range(1,len(s)):
if s[i] == s[i-1]:
count+=1
else:
count = 1
if count>=7:
dangerous =True
break
if dangerous:
print("YES")
else:
print("NO") | Title: Football
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Petya loves football very much. One day, as he was watching a football match, he was writing the players' current positions on a piece of paper. To simplify the situation he depicted it as a string consisting of zeroes and ones. A... | ```python
s = input()
dangerous = False
count =1
for i in range(1,len(s)):
if s[i] == s[i-1]:
count+=1
else:
count = 1
if count>=7:
dangerous =True
break
if dangerous:
print("YES")
else:
print("NO")
``` | 3.977 |
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,616,636,669 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 122 | 0 | n = input()
arr = n.split(" ")
print(
round(
((int(arr[0])*int(arr[1]))-1)/2
)
) | Title: Domino piling
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as p... | ```python
n = input()
arr = n.split(" ")
print(
round(
((int(arr[0])*int(arr[1]))-1)/2
)
)
``` | 0 |
776 | A | A Serial Killer | PROGRAMMING | 900 | [
"brute force",
"implementation",
"strings"
] | null | null | Our beloved detective, Sherlock is currently trying to catch a serial killer who kills a person each day. Using his powers of deduction, he came to know that the killer has a strategy for selecting his next victim.
The killer starts with two potential victims on his first day, selects one of these two, kills selected ... | First line of input contains two names (length of each of them doesn't exceed 10), the two initials potential victims. Next line contains integer *n* (1<=≤<=*n*<=≤<=1000), the number of days.
Next *n* lines contains two names (length of each of them doesn't exceed 10), first being the person murdered on this day and t... | Output *n*<=+<=1 lines, the *i*-th line should contain the two persons from which the killer selects for the *i*-th murder. The (*n*<=+<=1)-th line should contain the two persons from which the next victim is selected. In each line, the two names can be printed in any order. | [
"ross rachel\n4\nross joey\nrachel phoebe\nphoebe monica\nmonica chandler\n",
"icm codeforces\n1\ncodeforces technex\n"
] | [
"ross rachel\njoey rachel\njoey phoebe\njoey monica\njoey chandler\n",
"icm codeforces\nicm technex\n"
] | In first example, the killer starts with ross and rachel.
- After day 1, ross is killed and joey appears. - After day 2, rachel is killed and phoebe appears. - After day 3, phoebe is killed and monica appears. - After day 4, monica is killed and chandler appears. | 500 | [
{
"input": "ross rachel\n4\nross joey\nrachel phoebe\nphoebe monica\nmonica chandler",
"output": "ross rachel\njoey rachel\njoey phoebe\njoey monica\njoey chandler"
},
{
"input": "icm codeforces\n1\ncodeforces technex",
"output": "icm codeforces\nicm technex"
},
{
"input": "a b\n3\na c\n... | 1,699,979,403 | 303 | PyPy 3-64 | OK | TESTS | 57 | 62 | 0 | import sys
input = sys.stdin.buffer.readline
def process(A):
n = len(A)
answer = [A[0]]
for i in range(1, n):
a1, b1 = answer[-1]
a2, b2 = A[i]
if a1==a2:
answer.append([b1, b2])
elif a1==b2:
answer.append([a2, b1])
elif b1==a2:... | Title: A Serial Killer
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Our beloved detective, Sherlock is currently trying to catch a serial killer who kills a person each day. Using his powers of deduction, he came to know that the killer has a strategy for selecting his next victim.
The... | ```python
import sys
input = sys.stdin.buffer.readline
def process(A):
n = len(A)
answer = [A[0]]
for i in range(1, n):
a1, b1 = answer[-1]
a2, b2 = A[i]
if a1==a2:
answer.append([b1, b2])
elif a1==b2:
answer.append([a2, b1])
el... | 3 | |
914 | A | Perfect Squares | PROGRAMMING | 900 | [
"brute force",
"implementation",
"math"
] | null | null | Given an array *a*1,<=*a*2,<=...,<=*a**n* of *n* integers, find the largest number in the array that is not a perfect square.
A number *x* is said to be a perfect square if there exists an integer *y* such that *x*<==<=*y*2. | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of elements in the array.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (<=-<=106<=≤<=*a**i*<=≤<=106) — the elements of the array.
It is guaranteed that at least one element of the array is not a perfect square. | Print the largest number in the array which is not a perfect square. It is guaranteed that an answer always exists. | [
"2\n4 2\n",
"8\n1 2 4 8 16 32 64 576\n"
] | [
"2\n",
"32\n"
] | In the first sample case, 4 is a perfect square, so the largest number in the array that is not a perfect square is 2. | 500 | [
{
"input": "2\n4 2",
"output": "2"
},
{
"input": "8\n1 2 4 8 16 32 64 576",
"output": "32"
},
{
"input": "3\n-1 -4 -9",
"output": "-1"
},
{
"input": "5\n918375 169764 598796 76602 538757",
"output": "918375"
},
{
"input": "5\n804610 765625 2916 381050 93025",
... | 1,539,872,237 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 2 | 108 | 0 | x=int(input())
l=list(map(int,input().split()))
k={}
for i in l:
k[i]=(i**0.5)
f=[]
for i in k.keys():
if k[i]%1==0:
pass
else:
f.append(i)
print(max(f))
| Title: Perfect Squares
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Given an array *a*1,<=*a*2,<=...,<=*a**n* of *n* integers, find the largest number in the array that is not a perfect square.
A number *x* is said to be a perfect square if there exists an integer *y* such that *x*<==<... | ```python
x=int(input())
l=list(map(int,input().split()))
k={}
for i in l:
k[i]=(i**0.5)
f=[]
for i in k.keys():
if k[i]%1==0:
pass
else:
f.append(i)
print(max(f))
``` | -1 | |
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,584,719,901 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 9 | 216 | 307,200 | def checkForEveness(firstNum, secondNum, thirdNum):
if firstNum % 2 == 0:
if secondNum % 2 == 0:
print(initialIndex + 2)
else:
if thirdNum % 2 == 0:
print(initialIndex + 1)
else:
print(initialIndex)
else:
if secondNum % ... | 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
def checkForEveness(firstNum, secondNum, thirdNum):
if firstNum % 2 == 0:
if secondNum % 2 == 0:
print(initialIndex + 2)
else:
if thirdNum % 2 == 0:
print(initialIndex + 1)
else:
print(initialIndex)
else:
if se... | -1 |
625 | C | K-special Tables | PROGRAMMING | 1,300 | [
"constructive algorithms",
"implementation"
] | null | null | People do many crazy things to stand out in a crowd. Some of them dance, some learn by heart rules of Russian language, some try to become an outstanding competitive programmers, while others collect funny math objects.
Alis is among these collectors. Right now she wants to get one of *k*-special tables. In case you f... | The first line of the input contains two integers *n* and *k* (1<=≤<=*n*<=≤<=500,<=1<=≤<=*k*<=≤<=*n*) — the size of the table Alice is looking for and the column that should have maximum possible sum. | First print the sum of the integers in the *k*-th column of the required table.
Next *n* lines should contain the description of the table itself: first line should contains *n* elements of the first row, second line should contain *n* elements of the second row and so on.
If there are multiple suitable table, you ar... | [
"4 1\n",
"5 3\n"
] | [
"28\n1 2 3 4\n5 6 7 8\n9 10 11 12\n13 14 15 16\n",
"85\n5 6 17 18 19\n9 10 23 24 25\n7 8 20 21 22\n3 4 14 15 16\n1 2 11 12 13\n\n"
] | none | 1,000 | [
{
"input": "4 1",
"output": "28\n1 2 3 4\n5 6 7 8\n9 10 11 12\n13 14 15 16"
},
{
"input": "5 3",
"output": "85\n1 2 11 12 13\n3 4 14 15 16\n5 6 17 18 19\n7 8 20 21 22\n9 10 23 24 25"
},
{
"input": "1 1",
"output": "1\n1"
},
{
"input": "2 1",
"output": "4\n1 2\n3 4"
},
... | 1,456,590,430 | 2,147,483,647 | Python 3 | OK | TESTS | 52 | 124 | 307,200 | n, k = map(int, input().split())
left = 1
right = n ** 2
sum = right - (n - k)
s = sum
for _ in range(n - 1):
s -= (n - k + 1)
sum += s
print(sum)
for _ in range(n):
ans = []
if k > 1:
ans.append(' '.join(map(str, range(left, left + (k - 1)))))
ans.append(' '.join(map(str,... | Title: K-special Tables
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
People do many crazy things to stand out in a crowd. Some of them dance, some learn by heart rules of Russian language, some try to become an outstanding competitive programmers, while others collect funny math objects... | ```python
n, k = map(int, input().split())
left = 1
right = n ** 2
sum = right - (n - k)
s = sum
for _ in range(n - 1):
s -= (n - k + 1)
sum += s
print(sum)
for _ in range(n):
ans = []
if k > 1:
ans.append(' '.join(map(str, range(left, left + (k - 1)))))
ans.append(' '.joi... | 3 | |
616 | B | Dinner with Emma | PROGRAMMING | 1,000 | [
"games",
"greedy"
] | null | null | Jack decides to invite Emma out for a dinner. Jack is a modest student, he doesn't want to go to an expensive restaurant. Emma is a girl with high taste, she prefers elite places.
Munhattan consists of *n* streets and *m* avenues. There is exactly one restaurant on the intersection of each street and avenue. The stree... | The first line contains two integers *n*,<=*m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of streets and avenues in Munhattan.
Each of the next *n* lines contains *m* integers *c**ij* (1<=≤<=*c**ij*<=≤<=109) — the cost of the dinner in the restaurant on the intersection of the *i*-th street and the *j*-th avenue. | Print the only integer *a* — the cost of the dinner for Jack and Emma. | [
"3 4\n4 1 3 5\n2 2 2 2\n5 4 5 1\n",
"3 3\n1 2 3\n2 3 1\n3 1 2\n"
] | [
"2\n",
"1\n"
] | In the first example if Emma chooses the first or the third streets Jack can choose an avenue with the cost of the dinner 1. So she chooses the second street and Jack chooses any avenue. The cost of the dinner is 2.
In the second example regardless of Emma's choice Jack can choose a restaurant with the cost of the din... | 0 | [
{
"input": "3 4\n4 1 3 5\n2 2 2 2\n5 4 5 1",
"output": "2"
},
{
"input": "3 3\n1 2 3\n2 3 1\n3 1 2",
"output": "1"
},
{
"input": "1 1\n1",
"output": "1"
},
{
"input": "1 10\n74 35 82 39 1 84 29 41 70 12",
"output": "1"
},
{
"input": "10 1\n44\n23\n65\n17\n48\n29\n... | 1,615,120,015 | 2,147,483,647 | PyPy 3 | OK | TESTS | 16 | 108 | 1,638,400 | cases, b = map(int, input().split())
st = set()
mn = float("-inf")
while cases:
cases -= 1
arr = sorted(map(int, input().split()))
if min(arr) > mn:
ans = arr
mn = min(arr)
print(mn) | Title: Dinner with Emma
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Jack decides to invite Emma out for a dinner. Jack is a modest student, he doesn't want to go to an expensive restaurant. Emma is a girl with high taste, she prefers elite places.
Munhattan consists of *n* streets and... | ```python
cases, b = map(int, input().split())
st = set()
mn = float("-inf")
while cases:
cases -= 1
arr = sorted(map(int, input().split()))
if min(arr) > mn:
ans = arr
mn = min(arr)
print(mn)
``` | 3 | |
359 | C | Prime Number | PROGRAMMING | 1,900 | [
"math",
"number theory"
] | null | null | Simon has a prime number *x* and an array of non-negative integers *a*1,<=*a*2,<=...,<=*a**n*.
Simon loves fractions very much. Today he wrote out number on a piece of paper. After Simon led all fractions to a common denominator and summed them up, he got a fraction: , where number *t* equals *x**a*1<=+<=*a*2<=+<=...... | The first line contains two positive integers *n* and *x* (1<=≤<=*n*<=≤<=105, 2<=≤<=*x*<=≤<=109) — the size of the array and the prime number.
The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a*1<=≤<=*a*2<=≤<=...<=≤<=*a**n*<=≤<=109). | Print a single number — the answer to the problem modulo 1000000007 (109<=+<=7). | [
"2 2\n2 2\n",
"3 3\n1 2 3\n",
"2 2\n29 29\n",
"4 5\n0 0 0 0\n"
] | [
"8\n",
"27\n",
"73741817\n",
"1\n"
] | In the first sample <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/7745f7cc87c6c5f753e3414fad9baa3b1e3fea48.png" style="max-width: 100.0%;max-height: 100.0%;"/>. Thus, the answer to the problem is 8.
In the second sample, <img align="middle" class="tex-formula" src="https://espresso.codef... | 1,500 | [
{
"input": "2 2\n2 2",
"output": "8"
},
{
"input": "3 3\n1 2 3",
"output": "27"
},
{
"input": "2 2\n29 29",
"output": "73741817"
},
{
"input": "4 5\n0 0 0 0",
"output": "1"
},
{
"input": "1 2\n1000000000",
"output": "1"
},
{
"input": "26 2\n0 0 0 0 0 0... | 1,596,426,493 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 7 | 327 | 40,857,600 | def solve(n,x):
from collections import Counter
ct = Counter(map(int,input().split()))
s = sum([v*ct[v] for v in ct.keys()])
d = {s-v: ct[v] for v in ct.keys()}
for v in sorted(d.keys()):
if d[v]%x==0:
k = 0
while d[v]%x==0:
k += 1
d[v]... | Title: Prime Number
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Simon has a prime number *x* and an array of non-negative integers *a*1,<=*a*2,<=...,<=*a**n*.
Simon loves fractions very much. Today he wrote out number on a piece of paper. After Simon led all fractions to a common den... | ```python
def solve(n,x):
from collections import Counter
ct = Counter(map(int,input().split()))
s = sum([v*ct[v] for v in ct.keys()])
d = {s-v: ct[v] for v in ct.keys()}
for v in sorted(d.keys()):
if d[v]%x==0:
k = 0
while d[v]%x==0:
k += 1
... | 0 | |
469 | A | I Wanna Be the Guy | PROGRAMMING | 800 | [
"greedy",
"implementation"
] | null | null | There is a game called "I Wanna Be the Guy", consisting of *n* levels. Little X and his friend Little Y are addicted to the game. Each of them wants to pass the whole game.
Little X can pass only *p* levels of the game. And Little Y can pass only *q* levels of the game. You are given the indices of levels Little X can... | The first line contains a single integer *n* (1<=≤<=<=*n*<=≤<=100).
The next line contains an integer *p* (0<=≤<=*p*<=≤<=*n*) at first, then follows *p* distinct integers *a*1,<=*a*2,<=...,<=*a**p* (1<=≤<=*a**i*<=≤<=*n*). These integers denote the indices of levels Little X can pass. The next line contains the levels... | If they can pass all the levels, print "I become the guy.". If it's impossible, print "Oh, my keyboard!" (without the quotes). | [
"4\n3 1 2 3\n2 2 4\n",
"4\n3 1 2 3\n2 2 3\n"
] | [
"I become the guy.\n",
"Oh, my keyboard!\n"
] | In the first sample, Little X can pass levels [1 2 3], and Little Y can pass level [2 4], so they can pass all the levels both.
In the second sample, no one can pass level 4. | 500 | [
{
"input": "4\n3 1 2 3\n2 2 4",
"output": "I become the guy."
},
{
"input": "4\n3 1 2 3\n2 2 3",
"output": "Oh, my keyboard!"
},
{
"input": "10\n5 8 6 1 5 4\n6 1 3 2 9 4 6",
"output": "Oh, my keyboard!"
},
{
"input": "10\n8 8 10 7 3 1 4 2 6\n8 9 5 10 3 7 2 4 8",
"output":... | 1,699,549,654 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 31 | 0 | n= int(input())
X = list(map(int,input().split()))
Y = list(map(int,input().split()))
X = X + Y
win = True
for i in range(1,n):
if i not in X:
win=False
print("Oh, my keyboard!")
break
if(win):
print("I become the guy.") | Title: I Wanna Be the Guy
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There is a game called "I Wanna Be the Guy", consisting of *n* levels. Little X and his friend Little Y are addicted to the game. Each of them wants to pass the whole game.
Little X can pass only *p* levels of the g... | ```python
n= int(input())
X = list(map(int,input().split()))
Y = list(map(int,input().split()))
X = X + Y
win = True
for i in range(1,n):
if i not in X:
win=False
print("Oh, my keyboard!")
break
if(win):
print("I become the guy.")
``` | 0 | |
810 | B | Summer sell-off | PROGRAMMING | 1,300 | [
"greedy",
"sortings"
] | null | null | Summer holidays! Someone is going on trips, someone is visiting grandparents, but someone is trying to get a part-time job. This summer Noora decided that she wants to earn some money, and took a job in a shop as an assistant.
Shop, where Noora is working, has a plan on the following *n* days. For each day sales manag... | The first line contains two integers *n* and *f* (1<=≤<=*n*<=≤<=105,<=0<=≤<=*f*<=≤<=*n*) denoting the number of days in shop's plan and the number of days that Noora has to choose for sell-out.
Each line of the following *n* subsequent lines contains two integers *k**i*,<=*l**i* (0<=≤<=*k**i*,<=*l**i*<=≤<=109) denotin... | Print a single integer denoting the maximal number of products that shop can sell. | [
"4 2\n2 1\n3 5\n2 3\n1 5\n",
"4 1\n0 2\n0 3\n3 5\n0 6\n"
] | [
"10",
"5"
] | In the first example we can choose days with numbers 2 and 4 for sell-out. In this case new numbers of products for sale would be equal to [2, 6, 2, 2] respectively. So on the first day shop will sell 1 product, on the second — 5, on the third — 2, on the fourth — 2. In total 1 + 5 + 2 + 2 = 10 product units.
In the s... | 1,000 | [
{
"input": "4 2\n2 1\n3 5\n2 3\n1 5",
"output": "10"
},
{
"input": "4 1\n0 2\n0 3\n3 5\n0 6",
"output": "5"
},
{
"input": "1 1\n5 8",
"output": "8"
},
{
"input": "2 1\n8 12\n6 11",
"output": "19"
},
{
"input": "2 1\n6 7\n5 7",
"output": "13"
},
{
"inpu... | 1,663,789,738 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 15 | 717 | 12,902,400 | n,f = list(map(int, input().split()))
days = []
for _ in range(n):
p,k = list(map(int,input().split()))
days.append((p,k))
days.sort(key = lambda i: min(2*i[0], i[1]), reverse = True)
total = 0
# print(days)
for p,c in days:
if p >= c:
total += c
else:
if f:
... | Title: Summer sell-off
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Summer holidays! Someone is going on trips, someone is visiting grandparents, but someone is trying to get a part-time job. This summer Noora decided that she wants to earn some money, and took a job in a shop as an ass... | ```python
n,f = list(map(int, input().split()))
days = []
for _ in range(n):
p,k = list(map(int,input().split()))
days.append((p,k))
days.sort(key = lambda i: min(2*i[0], i[1]), reverse = True)
total = 0
# print(days)
for p,c in days:
if p >= c:
total += c
else:
if f: ... | 0 | |
49 | A | Sleuth | PROGRAMMING | 800 | [
"implementation"
] | A. Sleuth | 2 | 256 | Vasya plays the sleuth with his friends. The rules of the game are as follows: those who play for the first time, that is Vasya is the sleuth, he should investigate a "crime" and find out what is happening. He can ask any questions whatsoever that can be answered with "Yes" or "No". All the rest agree beforehand to ans... | The single line contains a question represented by a non-empty line consisting of large and small Latin letters, spaces and a question mark. The line length does not exceed 100. It is guaranteed that the question mark occurs exactly once in the line — as the last symbol and that the line contains at least one letter. | Print answer for the question in a single line: YES if the answer is "Yes", NO if the answer is "No".
Remember that in the reply to the question the last letter, not the last character counts. I. e. the spaces and the question mark do not count as letters. | [
"Is it a melon?\n",
"Is it an apple?\n",
"Is it a banana ?\n",
"Is it an apple and a banana simultaneouSLY?\n"
] | [
"NO\n",
"YES\n",
"YES\n",
"YES\n"
] | none | 500 | [
{
"input": "Is it a melon?",
"output": "NO"
},
{
"input": "Is it an apple?",
"output": "YES"
},
{
"input": " Is it a banana ?",
"output": "YES"
},
{
"input": "Is it an apple and a banana simultaneouSLY?",
"output": "YES"
},
{
"input": "oHtSbDwzHb?",
... | 1,585,557,909 | 2,147,483,647 | Python 3 | OK | TESTS | 35 | 218 | 0 | #sleuth
q = input().strip('? ').lower()
if q[-1] in ['a', 'e', 'i', 'o', 'u', 'y']:
print("YES")
else:
print("NO")
| Title: Sleuth
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya plays the sleuth with his friends. The rules of the game are as follows: those who play for the first time, that is Vasya is the sleuth, he should investigate a "crime" and find out what is happening. He can ask any questions ... | ```python
#sleuth
q = input().strip('? ').lower()
if q[-1] in ['a', 'e', 'i', 'o', 'u', 'y']:
print("YES")
else:
print("NO")
``` | 3.9455 |
356 | A | Knight Tournament | PROGRAMMING | 1,500 | [
"data structures",
"dsu"
] | null | null | Hooray! Berl II, the king of Berland is making a knight tournament. The king has already sent the message to all knights in the kingdom and they in turn agreed to participate in this grand event.
As for you, you're just a simple peasant. There's no surprise that you slept in this morning and were late for the tourname... | The first line contains two integers *n*, *m* (2<=≤<=*n*<=≤<=3·105; 1<=≤<=*m*<=≤<=3·105) — the number of knights and the number of fights. Each of the following *m* lines contains three integers *l**i*,<=*r**i*,<=*x**i* (1<=≤<=*l**i*<=<<=*r**i*<=≤<=*n*; *l**i*<=≤<=*x**i*<=≤<=*r**i*) — the description of the *i*-th f... | Print *n* integers. If the *i*-th knight lost, then the *i*-th number should equal the number of the knight that beat the knight number *i*. If the *i*-th knight is the winner, then the *i*-th number must equal 0. | [
"4 3\n1 2 1\n1 3 3\n1 4 4\n",
"8 4\n3 5 4\n3 7 6\n2 8 8\n1 8 1\n"
] | [
"3 1 4 0 ",
"0 8 4 6 4 8 6 1 "
] | Consider the first test case. Knights 1 and 2 fought the first fight and knight 1 won. Knights 1 and 3 fought the second fight and knight 3 won. The last fight was between knights 3 and 4, knight 4 won. | 500 | [
{
"input": "4 3\n1 2 1\n1 3 3\n1 4 4",
"output": "3 1 4 0 "
},
{
"input": "8 4\n3 5 4\n3 7 6\n2 8 8\n1 8 1",
"output": "0 8 4 6 4 8 6 1 "
},
{
"input": "2 1\n1 2 1",
"output": "0 1 "
},
{
"input": "2 1\n1 2 2",
"output": "2 0 "
},
{
"input": "3 1\n1 3 1",
"out... | 1,683,858,803 | 2,147,483,647 | Python 3 | OK | TESTS | 63 | 1,247 | 26,316,800 | knights, lutas = [int(x) for x in input().split()]
resultado = [0 for _ in range(knights)]
array = [i + 1 for i in range(1, knights + 1)]
for _ in range(lutas):
k1, k2, w = [int(x) for x in input().split()]
i = k1
while i <= k2:
proximo = array[i - 1]
if i < w:
array[i - 1] = w... | Title: Knight Tournament
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Hooray! Berl II, the king of Berland is making a knight tournament. The king has already sent the message to all knights in the kingdom and they in turn agreed to participate in this grand event.
As for you, you're j... | ```python
knights, lutas = [int(x) for x in input().split()]
resultado = [0 for _ in range(knights)]
array = [i + 1 for i in range(1, knights + 1)]
for _ in range(lutas):
k1, k2, w = [int(x) for x in input().split()]
i = k1
while i <= k2:
proximo = array[i - 1]
if i < w:
array[... | 3 | |
553 | A | Kyoya and Colored Balls | PROGRAMMING | 1,500 | [
"combinatorics",
"dp",
"math"
] | null | null | Kyoya Ootori has a bag with *n* colored balls that are colored with *k* different colors. The colors are labeled from 1 to *k*. Balls of the same color are indistinguishable. He draws balls from the bag one by one until the bag is empty. He noticed that he drew the last ball of color *i* before drawing the last ball of... | The first line of input will have one integer *k* (1<=≤<=*k*<=≤<=1000) the number of colors.
Then, *k* lines will follow. The *i*-th line will contain *c**i*, the number of balls of the *i*-th color (1<=≤<=*c**i*<=≤<=1000).
The total number of balls doesn't exceed 1000. | A single integer, the number of ways that Kyoya can draw the balls from the bag as described in the statement, modulo 1<=000<=000<=007. | [
"3\n2\n2\n1\n",
"4\n1\n2\n3\n4\n"
] | [
"3\n",
"1680\n"
] | In the first sample, we have 2 balls of color 1, 2 balls of color 2, and 1 ball of color 3. The three ways for Kyoya are: | 250 | [
{
"input": "3\n2\n2\n1",
"output": "3"
},
{
"input": "4\n1\n2\n3\n4",
"output": "1680"
},
{
"input": "10\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100",
"output": "12520708"
},
{
"input": "5\n10\n10\n10\n10\n10",
"output": "425711769"
},
{
"input": "11\n291\n3... | 1,643,918,621 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 30 | 0 | from math import*
def fac(m):
fact = 1
for num in range(2, m + 1):
fact *= num
return fact
k = int((input('')))
i = 0
colors = []
for i in range(k):
i = i + 1
colors.append(int(input('')))
colors.reverse()
m = sum(colors)
v = fac(m)
for x in range(len(colors)):
v ... | Title: Kyoya and Colored Balls
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Kyoya Ootori has a bag with *n* colored balls that are colored with *k* different colors. The colors are labeled from 1 to *k*. Balls of the same color are indistinguishable. He draws balls from the bag one by o... | ```python
from math import*
def fac(m):
fact = 1
for num in range(2, m + 1):
fact *= num
return fact
k = int((input('')))
i = 0
colors = []
for i in range(k):
i = i + 1
colors.append(int(input('')))
colors.reverse()
m = sum(colors)
v = fac(m)
for x in range(len(colors)... | 0 | |
809 | A | Do you want a date? | PROGRAMMING | 1,500 | [
"implementation",
"math",
"sortings"
] | null | null | Leha decided to move to a quiet town Vičkopolis, because he was tired by living in Bankopolis. Upon arrival he immediately began to expand his network of hacked computers. During the week Leha managed to get access to *n* computers throughout the town. Incidentally all the computers, which were hacked by Leha, lie on t... | The first line contains one integer *n* (1<=≤<=*n*<=≤<=3·105) denoting the number of hacked computers.
The second line contains *n* integers *x*1,<=*x*2,<=...,<=*x**n* (1<=≤<=*x**i*<=≤<=109) denoting the coordinates of hacked computers. It is guaranteed that all *x**i* are distinct. | Print a single integer — the required sum modulo 109<=+<=7. | [
"2\n4 7\n",
"3\n4 3 1\n"
] | [
"3\n",
"9\n"
] | There are three non-empty subsets in the first sample test:<img align="middle" class="tex-formula" src="https://espresso.codeforces.com/02b2d12556dad85f1c6c6912786eb87d4be2ea17.png" style="max-width: 100.0%;max-height: 100.0%;"/>, <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/22f6a537962c... | 500 | [
{
"input": "2\n4 7",
"output": "3"
},
{
"input": "3\n4 3 1",
"output": "9"
},
{
"input": "20\n8 11 13 19 21 34 36 44 57 58 61 63 76 78 79 81 85 86 90 95",
"output": "83396599"
},
{
"input": "20\n1 8 9 12 15 17 18 24 30 33 36 41 53 54 59 62 64 66 72 73",
"output": "6805914... | 1,602,866,174 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 7 | 2,000 | 27,852,800 | n = int(input())
x = sorted(list(map(int, input().split())), reverse=True)
ans = 0
for i in range(n):
s = 2**(n-i-1) - 2**i
ans += s*x[i]
print(ans % 1000000007)
| Title: Do you want a date?
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Leha decided to move to a quiet town Vičkopolis, because he was tired by living in Bankopolis. Upon arrival he immediately began to expand his network of hacked computers. During the week Leha managed to get access ... | ```python
n = int(input())
x = sorted(list(map(int, input().split())), reverse=True)
ans = 0
for i in range(n):
s = 2**(n-i-1) - 2**i
ans += s*x[i]
print(ans % 1000000007)
``` | 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,543,774,973 | 2,147,483,647 | Python 3 | OK | TESTS | 25 | 218 | 0 | def dopolnenie(s, lst):
count, b = 0, list()
for elem in lst:
if s in elem:
b.append(elem)
count += 1
if count != 0 and b[0].startswith(s):
return b[0]
return s
t = input()
n = int(input())
a = list()
for i in range(n):
z = input()
a.appe... | 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
def dopolnenie(s, lst):
count, b = 0, list()
for elem in lst:
if s in elem:
b.append(elem)
count += 1
if count != 0 and b[0].startswith(s):
return b[0]
return s
t = input()
n = int(input())
a = list()
for i in range(n):
z = input()
... | 3.9455 |
892 | B | Wrath | PROGRAMMING | 1,200 | [
"greedy",
"implementation",
"two pointers"
] | null | null | Hands that shed innocent blood!
There are *n* guilty people in a line, the *i*-th of them holds a claw with length *L**i*. The bell rings and every person kills some of people in front of him. All people kill others at the same time. Namely, the *i*-th person kills the *j*-th person if and only if *j*<=<<=*i* and *... | The first line contains one integer *n* (1<=≤<=*n*<=≤<=106) — the number of guilty people.
Second line contains *n* space-separated integers *L*1,<=*L*2,<=...,<=*L**n* (0<=≤<=*L**i*<=≤<=109), where *L**i* is the length of the *i*-th person's claw. | Print one integer — the total number of alive people after the bell rings. | [
"4\n0 1 0 10\n",
"2\n0 0\n",
"10\n1 1 3 0 0 0 2 1 0 3\n"
] | [
"1\n",
"2\n",
"3\n"
] | In first sample the last person kills everyone in front of him. | 1,000 | [
{
"input": "4\n0 1 0 10",
"output": "1"
},
{
"input": "2\n0 0",
"output": "2"
},
{
"input": "10\n1 1 3 0 0 0 2 1 0 3",
"output": "3"
},
{
"input": "10\n0 0 2 0 0 3 3 2 2 0",
"output": "2"
},
{
"input": "1\n0",
"output": "1"
},
{
"input": "5\n0 0 0 1 0"... | 1,510,934,686 | 5,386 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 15 | 2,000 | 76,492,800 | n = int(input())
L = list(map(int, input().split()))
b = []
for i in range(n):
b.append(1)
for i in range(len(L) - 1, -1, -1):
if L[i] > i:
for r in range(i):
b[r] = 0
break
else:
for j in range(i - L[i], i):
b[j] = 0
print(b.count(1)) | Title: Wrath
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Hands that shed innocent blood!
There are *n* guilty people in a line, the *i*-th of them holds a claw with length *L**i*. The bell rings and every person kills some of people in front of him. All people kill others at the same ... | ```python
n = int(input())
L = list(map(int, input().split()))
b = []
for i in range(n):
b.append(1)
for i in range(len(L) - 1, -1, -1):
if L[i] > i:
for r in range(i):
b[r] = 0
break
else:
for j in range(i - L[i], i):
b[j] = 0
print(b.count(1))
`... | 0 | |
383 | A | Milking cows | PROGRAMMING | 1,600 | [
"data structures",
"greedy"
] | null | null | Iahub helps his grandfather at the farm. Today he must milk the cows. There are *n* cows sitting in a row, numbered from 1 to *n* from left to right. Each cow is either facing to the left or facing to the right. When Iahub milks a cow, all the cows that see the current cow get scared and lose one unit of the quantity o... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=200000). The second line contains *n* integers *a*1, *a*2, ..., *a**n*, where *a**i* is 0 if the cow number *i* is facing left, and 1 if it is facing right. | Print a single integer, the minimum amount of lost milk.
Please, do not write the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier. | [
"4\n0 0 1 0\n",
"5\n1 0 1 0 1\n"
] | [
"1",
"3"
] | In the first sample Iahub milks the cows in the following order: cow 3, cow 4, cow 2, cow 1. When he milks cow 3, cow 4 loses 1 unit of milk. After that, no more milk is lost. | 500 | [
{
"input": "4\n0 0 1 0",
"output": "1"
},
{
"input": "5\n1 0 1 0 1",
"output": "3"
},
{
"input": "50\n1 1 0 1 1 1 1 1 1 0 0 1 1 0 1 1 0 0 1 0 1 1 0 1 1 1 1 0 1 0 1 0 1 1 1 0 0 0 0 0 0 0 1 1 0 1 0 0 1 0",
"output": "416"
},
{
"input": "100\n1 1 0 0 1 1 1 1 0 1 1 1 1 1 1 1 0 0 ... | 1,656,692,760 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 42 | 326 | 158,105,600 | #If you win, you live. You cannot win unless you fight.
# remember hash hack use tuple
import string
from sys import stdin,setrecursionlimit
input=stdin.readline
rd=lambda: map(lambda s: int(s), input().strip().split())
ri=lambda: int(input())
rs=lambda :input().strip()
setrecursionlimit(10**5)
from collectio... | Title: Milking cows
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Iahub helps his grandfather at the farm. Today he must milk the cows. There are *n* cows sitting in a row, numbered from 1 to *n* from left to right. Each cow is either facing to the left or facing to the right. When Iahub... | ```python
#If you win, you live. You cannot win unless you fight.
# remember hash hack use tuple
import string
from sys import stdin,setrecursionlimit
input=stdin.readline
rd=lambda: map(lambda s: int(s), input().strip().split())
ri=lambda: int(input())
rs=lambda :input().strip()
setrecursionlimit(10**5)
from... | 3 | |
50 | A | Domino piling | PROGRAMMING | 800 | [
"greedy",
"math"
] | A. Domino piling | 2 | 256 | You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions:
1. Each domino completely covers ... | In a single line you are given two integers *M* and *N* — board sizes in squares (1<=≤<=*M*<=≤<=*N*<=≤<=16). | Output one number — the maximal number of dominoes, which can be placed. | [
"2 4\n",
"3 3\n"
] | [
"4\n",
"4\n"
] | none | 500 | [
{
"input": "2 4",
"output": "4"
},
{
"input": "3 3",
"output": "4"
},
{
"input": "1 5",
"output": "2"
},
{
"input": "1 6",
"output": "3"
},
{
"input": "1 15",
"output": "7"
},
{
"input": "1 16",
"output": "8"
},
{
"input": "2 5",
"outpu... | 1,689,775,697 | 2,147,483,647 | PyPy 3 | OK | TESTS | 35 | 154 | 0 | def Dominepiling(j,k):
return (j * k) // 2
j,k= map(int, input().split())
print(Dominepiling(j,k)) | 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
def Dominepiling(j,k):
return (j * k) // 2
j,k= map(int, input().split())
print(Dominepiling(j,k))
``` | 3.9615 |
80 | A | Panoramix's Prediction | PROGRAMMING | 800 | [
"brute force"
] | A. Panoramix's Prediction | 2 | 256 | A prime number is a number which has exactly two distinct divisors: one and itself. For example, numbers 2, 7, 3 are prime, and 1, 6, 4 are not.
The next prime number after *x* is the smallest prime number greater than *x*. For example, the next prime number after 2 is 3, and the next prime number after 3 is 5. Note t... | The first and only input line contains two positive integers — *n* and *m* (2<=≤<=*n*<=<<=*m*<=≤<=50). It is guaranteed that *n* is prime.
Pretests contain all the cases with restrictions 2<=≤<=*n*<=<<=*m*<=≤<=4. | Print YES, if *m* is the next prime number after *n*, or NO otherwise. | [
"3 5\n",
"7 11\n",
"7 9\n"
] | [
"YES",
"YES",
"NO"
] | none | 500 | [
{
"input": "3 5",
"output": "YES"
},
{
"input": "7 11",
"output": "YES"
},
{
"input": "7 9",
"output": "NO"
},
{
"input": "2 3",
"output": "YES"
},
{
"input": "2 4",
"output": "NO"
},
{
"input": "3 4",
"output": "NO"
},
{
"input": "3 5",
... | 1,678,995,914 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 39 | 92 | 0 | a = (2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47)
n, m = map(int, input().split())
print("YES" if a[a.index(n)+1] == m else "NO") | Title: Panoramix's Prediction
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A prime number is a number which has exactly two distinct divisors: one and itself. For example, numbers 2, 7, 3 are prime, and 1, 6, 4 are not.
The next prime number after *x* is the smallest prime number greater t... | ```python
a = (2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47)
n, m = map(int, input().split())
print("YES" if a[a.index(n)+1] == m else "NO")
``` | -1 |
714 | B | Filya and Homework | PROGRAMMING | 1,200 | [
"implementation",
"sortings"
] | null | null | Today, hedgehog Filya went to school for the very first time! Teacher gave him a homework which Filya was unable to complete without your help.
Filya is given an array of non-negative integers *a*1,<=*a*2,<=...,<=*a**n*. First, he pick an integer *x* and then he adds *x* to some elements of the array (no more than onc... | The first line of the input contains an integer *n* (1<=≤<=*n*<=≤<=100<=000) — the number of integers in the Filya's array. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=109) — elements of the array. | If it's impossible to make all elements of the array equal using the process given in the problem statement, then print "NO" (without quotes) in the only line of the output. Otherwise print "YES" (without quotes). | [
"5\n1 3 3 2 1\n",
"5\n1 2 3 4 5\n"
] | [
"YES\n",
"NO\n"
] | In the first sample Filya should select *x* = 1, then add it to the first and the last elements of the array and subtract from the second and the third elements. | 1,000 | [
{
"input": "5\n1 3 3 2 1",
"output": "YES"
},
{
"input": "5\n1 2 3 4 5",
"output": "NO"
},
{
"input": "2\n1 2",
"output": "YES"
},
{
"input": "3\n1 2 3",
"output": "YES"
},
{
"input": "3\n1 1 1",
"output": "YES"
},
{
"input": "2\n1 1000000000",
"ou... | 1,580,461,714 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 9 | 108 | 0 | n=int(input())
arr=list(map(int,input().split()))
a=set()
for i in arr:
a.add(i)
if len(a)==1 or len(a)==2:
print('YES')
elif len(a)==3:
a=list(a)
if 2*a[1]==arr[0]+arr[2]:
print('YES')
else:
print('NO')
else:
print('NO')
| Title: Filya and Homework
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Today, hedgehog Filya went to school for the very first time! Teacher gave him a homework which Filya was unable to complete without your help.
Filya is given an array of non-negative integers *a*1,<=*a*2,<=...,<=*a... | ```python
n=int(input())
arr=list(map(int,input().split()))
a=set()
for i in arr:
a.add(i)
if len(a)==1 or len(a)==2:
print('YES')
elif len(a)==3:
a=list(a)
if 2*a[1]==arr[0]+arr[2]:
print('YES')
else:
print('NO')
else:
print('NO')
``` | 0 | |
961 | A | Tetris | PROGRAMMING | 900 | [
"implementation"
] | null | null | You are given a following process.
There is a platform with $n$ columns. $1 \times 1$ squares are appearing one after another in some columns on this platform. If there are no squares in the column, a square will occupy the bottom row. Otherwise a square will appear at the top of the highest square of this column.
... | The first line of input contain 2 integer numbers $n$ and $m$ ($1 \le n, m \le 1000$) — the length of the platform and the number of the squares.
The next line contain $m$ integer numbers $c_1, c_2, \dots, c_m$ ($1 \le c_i \le n$) — column in which $i$-th square will appear. | Print one integer — the amount of points you will receive. | [
"3 9\n1 1 2 2 2 3 1 2 3\n"
] | [
"2\n"
] | In the sample case the answer will be equal to $2$ because after the appearing of $6$-th square will be removed one row (counts of the squares on the platform will look like $[2~ 3~ 1]$, and after removing one row will be $[1~ 2~ 0]$).
After the appearing of $9$-th square counts will be $[2~ 3~ 1]$, and after removing... | 0 | [
{
"input": "3 9\n1 1 2 2 2 3 1 2 3",
"output": "2"
},
{
"input": "1 7\n1 1 1 1 1 1 1",
"output": "7"
},
{
"input": "1 1\n1",
"output": "1"
},
{
"input": "3 5\n1 1 1 2 3",
"output": "1"
},
{
"input": "4 6\n4 4 4 4 4 4",
"output": "0"
},
{
"input": "4 6\... | 1,629,355,587 | 2,147,483,647 | PyPy 3 | OK | TESTS | 29 | 93 | 21,606,400 | n, len = [int(x) for x in input().split()]
points = 0
counter = 0
sequence = [int(x) for x in input().split()]
platform = [0] * n
for item in sequence:
platform[item - 1] += 1
flag = True
for x in platform:
if x < points + 1:
flag = False
break
if flag:
points +=... | Title: Tetris
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a following process.
There is a platform with $n$ columns. $1 \times 1$ squares are appearing one after another in some columns on this platform. If there are no squares in the column, a square will occupy the bo... | ```python
n, len = [int(x) for x in input().split()]
points = 0
counter = 0
sequence = [int(x) for x in input().split()]
platform = [0] * n
for item in sequence:
platform[item - 1] += 1
flag = True
for x in platform:
if x < points + 1:
flag = False
break
if flag:
... | 3 | |
507 | B | Amr and Pins | PROGRAMMING | 1,400 | [
"geometry",
"math"
] | null | null | Amr loves Geometry. One day he came up with a very interesting problem.
Amr has a circle of radius *r* and center in point (*x*,<=*y*). He wants the circle center to be in new position (*x*',<=*y*').
In one step Amr can put a pin to the border of the circle in a certain point, then rotate the circle around that pin b... | Input consists of 5 space-separated integers *r*, *x*, *y*, *x*' *y*' (1<=≤<=*r*<=≤<=105, <=-<=105<=≤<=*x*,<=*y*,<=*x*',<=*y*'<=≤<=105), circle radius, coordinates of original center of the circle and coordinates of destination center of the circle respectively. | Output a single integer — minimum number of steps required to move the center of the circle to the destination point. | [
"2 0 0 0 4\n",
"1 1 1 4 4\n",
"4 5 6 5 6\n"
] | [
"1\n",
"3\n",
"0\n"
] | In the first sample test the optimal way is to put a pin at point (0, 2) and rotate the circle by 180 degrees counter-clockwise (or clockwise, no matter).
<img class="tex-graphics" src="https://espresso.codeforces.com/4e40fd4cc24a2050a0488aa131e6244369328039.png" style="max-width: 100.0%;max-height: 100.0%;"/> | 1,000 | [
{
"input": "2 0 0 0 4",
"output": "1"
},
{
"input": "1 1 1 4 4",
"output": "3"
},
{
"input": "4 5 6 5 6",
"output": "0"
},
{
"input": "10 20 0 40 0",
"output": "1"
},
{
"input": "9 20 0 40 0",
"output": "2"
},
{
"input": "5 -1 -6 -5 1",
"output": "... | 1,666,270,411 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 37 | 62 | 0 | # Amr and Pins
r,x,y,a,b = map(int,input().split(" "))
d = ((x-a)**2 + (y-b)**2)**0.5
steps = (d/(r*2))
if steps != int(steps):
steps = int(steps) + 1
print(int(steps)) | Title: Amr and Pins
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Amr loves Geometry. One day he came up with a very interesting problem.
Amr has a circle of radius *r* and center in point (*x*,<=*y*). He wants the circle center to be in new position (*x*',<=*y*').
In one step Amr can ... | ```python
# Amr and Pins
r,x,y,a,b = map(int,input().split(" "))
d = ((x-a)**2 + (y-b)**2)**0.5
steps = (d/(r*2))
if steps != int(steps):
steps = int(steps) + 1
print(int(steps))
``` | 3 | |
546 | A | Soldier and Bananas | PROGRAMMING | 800 | [
"brute force",
"implementation",
"math"
] | null | null | A soldier wants to buy *w* bananas in the shop. He has to pay *k* dollars for the first banana, 2*k* dollars for the second one and so on (in other words, he has to pay *i*·*k* dollars for the *i*-th banana).
He has *n* dollars. How many dollars does he have to borrow from his friend soldier to buy *w* bananas? | The first line contains three positive integers *k*,<=*n*,<=*w* (1<=<=≤<=<=*k*,<=*w*<=<=≤<=<=1000, 0<=≤<=*n*<=≤<=109), the cost of the first banana, initial number of dollars the soldier has and number of bananas he wants. | Output one integer — the amount of dollars that the soldier must borrow from his friend. If he doesn't have to borrow money, output 0. | [
"3 17 4\n"
] | [
"13"
] | none | 500 | [
{
"input": "3 17 4",
"output": "13"
},
{
"input": "1 2 1",
"output": "0"
},
{
"input": "1 1 1",
"output": "0"
},
{
"input": "1 5 6",
"output": "16"
},
{
"input": "1 1000000000 1",
"output": "0"
},
{
"input": "1000 0 1000",
"output": "500500000"
}... | 1,694,613,546 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 30 | 0 | k,w,n=map(int,input().split())
sum=0
for i in range(w):
sum=sum+k*i
if sum>n or sum==n:
print(0)
else:
print(sum-w-1) | Title: Soldier and Bananas
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A soldier wants to buy *w* bananas in the shop. He has to pay *k* dollars for the first banana, 2*k* dollars for the second one and so on (in other words, he has to pay *i*·*k* dollars for the *i*-th banana).
He h... | ```python
k,w,n=map(int,input().split())
sum=0
for i in range(w):
sum=sum+k*i
if sum>n or sum==n:
print(0)
else:
print(sum-w-1)
``` | 0 | |
609 | B | The Best Gift | PROGRAMMING | 1,100 | [
"constructive algorithms",
"implementation"
] | null | null | Emily's birthday is next week and Jack has decided to buy a present for her. He knows she loves books so he goes to the local bookshop, where there are *n* books on sale from one of *m* genres.
In the bookshop, Jack decides to buy two books of different genres.
Based on the genre of books on sale in the shop, find th... | The first line contains two positive integers *n* and *m* (2<=≤<=*n*<=≤<=2·105,<=2<=≤<=*m*<=≤<=10) — the number of books in the bookstore and the number of genres.
The second line contains a sequence *a*1,<=*a*2,<=...,<=*a**n*, where *a**i* (1<=≤<=*a**i*<=≤<=*m*) equals the genre of the *i*-th book.
It is guaranteed ... | Print the only integer — the number of ways in which Jack can choose books.
It is guaranteed that the answer doesn't exceed the value 2·109. | [
"4 3\n2 1 3 1\n",
"7 4\n4 2 3 1 2 4 3\n"
] | [
"5\n",
"18\n"
] | The answer to the first test sample equals 5 as Sasha can choose:
1. the first and second books, 1. the first and third books, 1. the first and fourth books, 1. the second and third books, 1. the third and fourth books. | 0 | [
{
"input": "4 3\n2 1 3 1",
"output": "5"
},
{
"input": "7 4\n4 2 3 1 2 4 3",
"output": "18"
},
{
"input": "2 2\n1 2",
"output": "1"
},
{
"input": "3 2\n1 2 2",
"output": "2"
},
{
"input": "10 10\n1 2 3 4 5 6 7 8 9 10",
"output": "45"
},
{
"input": "9 2... | 1,538,578,607 | 2,147,483,647 | Python 3 | OK | TESTS | 42 | 234 | 3,993,600 | n, m = map(int, input().split())
arr = list(map(int, input().split()))
dict = {}
for i in range(n):
genre = arr[i]
if genre in dict:
dict[genre] += 1
else:
dict[genre] = 1
count = 0
for i in range(1, m):
for j in range(i + 1, m + 1):
count += dict[i] * dict[j]
pr... | Title: The Best Gift
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Emily's birthday is next week and Jack has decided to buy a present for her. He knows she loves books so he goes to the local bookshop, where there are *n* books on sale from one of *m* genres.
In the bookshop, Jack deci... | ```python
n, m = map(int, input().split())
arr = list(map(int, input().split()))
dict = {}
for i in range(n):
genre = arr[i]
if genre in dict:
dict[genre] += 1
else:
dict[genre] = 1
count = 0
for i in range(1, m):
for j in range(i + 1, m + 1):
count += dict[i] * dic... | 3 | |
334 | B | Eight Point Sets | PROGRAMMING | 1,400 | [
"sortings"
] | null | null | Gerald is very particular to eight point sets. He thinks that any decent eight point set must consist of all pairwise intersections of three distinct integer vertical straight lines and three distinct integer horizontal straight lines, except for the average of these nine points. In other words, there must be three int... | The input consists of eight lines, the *i*-th line contains two space-separated integers *x**i* and *y**i* (0<=≤<=*x**i*,<=*y**i*<=≤<=106). You do not have any other conditions for these points. | In a single line print word "respectable", if the given set of points corresponds to Gerald's decency rules, and "ugly" otherwise. | [
"0 0\n0 1\n0 2\n1 0\n1 2\n2 0\n2 1\n2 2\n",
"0 0\n1 0\n2 0\n3 0\n4 0\n5 0\n6 0\n7 0\n",
"1 1\n1 2\n1 3\n2 1\n2 2\n2 3\n3 1\n3 2\n"
] | [
"respectable\n",
"ugly\n",
"ugly\n"
] | none | 1,000 | [
{
"input": "0 0\n0 1\n0 2\n1 0\n1 2\n2 0\n2 1\n2 2",
"output": "respectable"
},
{
"input": "0 0\n1 0\n2 0\n3 0\n4 0\n5 0\n6 0\n7 0",
"output": "ugly"
},
{
"input": "1 1\n1 2\n1 3\n2 1\n2 2\n2 3\n3 1\n3 2",
"output": "ugly"
},
{
"input": "0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0\n0 0... | 1,551,530,693 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 32 | 218 | 0 | import sys
a=[]
b=[]
for i in range(8):
x,y=[int(k) for k in input().split()]
a.append(x)
b.append(y)
seta=set(a)
setb=set(b)
if len(seta)==3 and len(setb)==3:
x=sorted(seta)
y=sorted(setb)
point=[]
for i in range(8):
point.append((a[i],b[i]))
for i in range(3):
... | Title: Eight Point Sets
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Gerald is very particular to eight point sets. He thinks that any decent eight point set must consist of all pairwise intersections of three distinct integer vertical straight lines and three distinct integer horizonta... | ```python
import sys
a=[]
b=[]
for i in range(8):
x,y=[int(k) for k in input().split()]
a.append(x)
b.append(y)
seta=set(a)
setb=set(b)
if len(seta)==3 and len(setb)==3:
x=sorted(seta)
y=sorted(setb)
point=[]
for i in range(8):
point.append((a[i],b[i]))
for i in ra... | 0 | |
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,505,659,239 | 5,739 | Python 3 | WRONG_ANSWER | PRETESTS | 2 | 46 | 4,608,000 | n, m= map(int, input().split())
k = []
j = []
l = 0
for i in range(m):
k.append(0)
j.append(0)
x,y= map(int, input().split())
k[i] = x
j[i] = y
k.sort()
j.sort()
mini = 1000
for i in range(0,m-1,1):
if (k[i+1] - k[i]) <= mini and (k[i+1] - k[i]) != 0:
mini = k[i+1] - k[i]
... | 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())
k = []
j = []
l = 0
for i in range(m):
k.append(0)
j.append(0)
x,y= map(int, input().split())
k[i] = x
j[i] = y
k.sort()
j.sort()
mini = 1000
for i in range(0,m-1,1):
if (k[i+1] - k[i]) <= mini and (k[i+1] - k[i]) != 0:
mini = k[i+... | 0 | |
750 | A | New Year and Hurry | PROGRAMMING | 800 | [
"binary search",
"brute force",
"implementation",
"math"
] | null | null | Limak is going to participate in a contest on the last day of the 2016. The contest will start at 20:00 and will last four hours, exactly until midnight. There will be *n* problems, sorted by difficulty, i.e. problem 1 is the easiest and problem *n* is the hardest. Limak knows it will take him 5·*i* minutes to solve th... | The only line of the input contains two integers *n* and *k* (1<=≤<=*n*<=≤<=10, 1<=≤<=*k*<=≤<=240) — the number of the problems in the contest and the number of minutes Limak needs to get to the party from his house. | Print one integer, denoting the maximum possible number of problems Limak can solve so that he could get to the party at midnight or earlier. | [
"3 222\n",
"4 190\n",
"7 1\n"
] | [
"2\n",
"4\n",
"7\n"
] | In the first sample, there are 3 problems and Limak needs 222 minutes to get to the party. The three problems require 5, 10 and 15 minutes respectively. Limak can spend 5 + 10 = 15 minutes to solve first two problems. Then, at 20:15 he can leave his house to get to the party at 23:57 (after 222 minutes). In this scenar... | 500 | [
{
"input": "3 222",
"output": "2"
},
{
"input": "4 190",
"output": "4"
},
{
"input": "7 1",
"output": "7"
},
{
"input": "10 135",
"output": "6"
},
{
"input": "10 136",
"output": "5"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "1 240",
... | 1,693,819,452 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 4 | 46 | 0 | n,t=map(int,input().split())
m = 240 - t
c = 0
a = 5
while(c<n and a<=m):
a+= 5*(c+1)
c+=1
print(c) | Title: New Year and Hurry
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Limak is going to participate in a contest on the last day of the 2016. The contest will start at 20:00 and will last four hours, exactly until midnight. There will be *n* problems, sorted by difficulty, i.e. problem... | ```python
n,t=map(int,input().split())
m = 240 - t
c = 0
a = 5
while(c<n and a<=m):
a+= 5*(c+1)
c+=1
print(c)
``` | 0 | |
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,643,441,290 | 2,147,483,647 | PyPy 3 | OK | TESTS | 63 | 93 | 0 | import math
def kesava(n):
for i in range(1,1001):
for j in range(2,int(math.sqrt((n*i)+1))+1):
if ((n*i)+1)%j==0:
return i
print(kesava(int(input()))) | 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
import math
def kesava(n):
for i in range(1,1001):
for j in range(2,int(math.sqrt((n*i)+1))+1):
if ((n*i)+1)%j==0:
return i
print(kesava(int(input())))
``` | 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,679,063,035 | 2,147,483,647 | Python 3 | OK | TESTS | 61 | 124 | 0 | input()
l = input().split()
print(max(l.count(i) for i in l), len(set(l)))
| 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
input()
l = input().split()
print(max(l.count(i) for i in l), len(set(l)))
``` | 3.969 |
660 | C | Hard Process | PROGRAMMING | 1,600 | [
"binary search",
"dp",
"two pointers"
] | null | null | You are given an array *a* with *n* elements. Each element of *a* is either 0 or 1.
Let's denote the length of the longest subsegment of consecutive elements in *a*, consisting of only numbers one, as *f*(*a*). You can change no more than *k* zeroes to ones to maximize *f*(*a*). | The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=3·105,<=0<=≤<=*k*<=≤<=*n*) — the number of elements in *a* and the parameter *k*.
The second line contains *n* integers *a**i* (0<=≤<=*a**i*<=≤<=1) — the elements of *a*. | On the first line print a non-negative integer *z* — the maximal value of *f*(*a*) after no more than *k* changes of zeroes to ones.
On the second line print *n* integers *a**j* — the elements of the array *a* after the changes.
If there are multiple answers, you can print any one of them. | [
"7 1\n1 0 0 1 1 0 1\n",
"10 2\n1 0 0 1 0 1 0 1 0 1\n"
] | [
"4\n1 0 0 1 1 1 1\n",
"5\n1 0 0 1 1 1 1 1 0 1\n"
] | none | 0 | [
{
"input": "7 1\n1 0 0 1 1 0 1",
"output": "4\n1 0 0 1 1 1 1"
},
{
"input": "10 2\n1 0 0 1 0 1 0 1 0 1",
"output": "5\n1 0 0 1 1 1 1 1 0 1"
},
{
"input": "1 0\n0",
"output": "0\n0"
},
{
"input": "1 0\n0",
"output": "0\n0"
},
{
"input": "7 0\n0 1 0 0 0 1 0",
"o... | 1,692,174,278 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 31 | 0 | def maximize_subsegment(n, k, a):
left = 0
max_len = 0
max_left = 0
changes = 0
for right in range(n):
if a[right] == 0:
changes += 1
while changes > k:
if a[left] == 0:
changes -= 1
left += 1
if right - left + 1 > max_len:... | Title: Hard Process
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given an array *a* with *n* elements. Each element of *a* is either 0 or 1.
Let's denote the length of the longest subsegment of consecutive elements in *a*, consisting of only numbers one, as *f*(*a*). You can ch... | ```python
def maximize_subsegment(n, k, a):
left = 0
max_len = 0
max_left = 0
changes = 0
for right in range(n):
if a[right] == 0:
changes += 1
while changes > k:
if a[left] == 0:
changes -= 1
left += 1
if right - left + 1 ... | 0 | |
365 | A | Good Number | PROGRAMMING | 1,100 | [
"implementation"
] | null | null | Let's call a number *k*-good if it contains all digits not exceeding *k* (0,<=...,<=*k*). You've got a number *k* and an array *a* containing *n* numbers. Find out how many *k*-good numbers are in *a* (count each number every time it occurs in array *a*). | The first line contains integers *n* and *k* (1<=≤<=*n*<=≤<=100, 0<=≤<=*k*<=≤<=9). The *i*-th of the following *n* lines contains integer *a**i* without leading zeroes (1<=≤<=*a**i*<=≤<=109). | Print a single integer — the number of *k*-good numbers in *a*. | [
"10 6\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n",
"2 1\n1\n10\n"
] | [
"10\n",
"1\n"
] | none | 500 | [
{
"input": "10 6\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560",
"output": "10"
},
{
"input": "2 1\n1\n10",
"output": "1"
},
{
"input": "1 0\n1000000000",
"output": "1"
},
{
"input": "1 1\n1000000000",
"output": "1"
},
{
... | 1,642,657,972 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 46 | 0 | n, k = map(int,input().split())
b = []
for i in range(k+1):
b.append(i)
count = 0
for t in range(n):
a = [int(i) for i in input()]
a.sort()
if set(a) == set(b):
count += 1
print(count)
| Title: Good Number
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Let's call a number *k*-good if it contains all digits not exceeding *k* (0,<=...,<=*k*). You've got a number *k* and an array *a* containing *n* numbers. Find out how many *k*-good numbers are in *a* (count each number eve... | ```python
n, k = map(int,input().split())
b = []
for i in range(k+1):
b.append(i)
count = 0
for t in range(n):
a = [int(i) for i in input()]
a.sort()
if set(a) == set(b):
count += 1
print(count)
``` | 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,670,609,895 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 35 | 122 | 0 | import sys
def main():
d, s = map(int, sys.stdin.readline().split())
print((d*s)//2)
if __name__ == '__main__':
main() | 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 sys
def main():
d, s = map(int, sys.stdin.readline().split())
print((d*s)//2)
if __name__ == '__main__':
main()
``` | 3.9695 |
237 | A | Free Cash | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Valera runs a 24/7 fast food cafe. He magically learned that next day *n* people will visit his cafe. For each person we know the arrival time: the *i*-th person comes exactly at *h**i* hours *m**i* minutes. The cafe spends less than a minute to serve each client, but if a client comes in and sees that there is no free... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105), that is the number of cafe visitors.
Each of the following *n* lines has two space-separated integers *h**i* and *m**i* (0<=≤<=*h**i*<=≤<=23; 0<=≤<=*m**i*<=≤<=59), representing the time when the *i*-th person comes into the cafe.
Note that the time is... | Print a single integer — the minimum number of cashes, needed to serve all clients next day. | [
"4\n8 0\n8 10\n8 10\n8 45\n",
"3\n0 12\n10 11\n22 22\n"
] | [
"2\n",
"1\n"
] | In the first sample it is not enough one cash to serve all clients, because two visitors will come into cafe in 8:10. Therefore, if there will be one cash in cafe, then one customer will be served by it, and another one will not wait and will go away.
In the second sample all visitors will come in different times, so ... | 500 | [
{
"input": "4\n8 0\n8 10\n8 10\n8 45",
"output": "2"
},
{
"input": "3\n0 12\n10 11\n22 22",
"output": "1"
},
{
"input": "5\n12 8\n15 27\n15 27\n16 2\n19 52",
"output": "2"
},
{
"input": "7\n5 6\n7 34\n7 34\n7 34\n12 29\n15 19\n20 23",
"output": "3"
},
{
"input": "... | 1,605,249,804 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 56 | 592 | 4,710,400 | n=int(input())
lst = []
for i in range(0,n):
m = input().split(" ")
m = ":".join(m)
lst.append(m)
lst2=[]
n = len(lst)
i = 0
lst.append('0')
while i<n-1:
c = 1
while lst[i]==lst[i+1]:
c+=1
i+=1
else:
lst2.append(c)
i+=1
print(max(lst2)) | Title: Free Cash
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Valera runs a 24/7 fast food cafe. He magically learned that next day *n* people will visit his cafe. For each person we know the arrival time: the *i*-th person comes exactly at *h**i* hours *m**i* minutes. The cafe spends l... | ```python
n=int(input())
lst = []
for i in range(0,n):
m = input().split(" ")
m = ":".join(m)
lst.append(m)
lst2=[]
n = len(lst)
i = 0
lst.append('0')
while i<n-1:
c = 1
while lst[i]==lst[i+1]:
c+=1
i+=1
else:
lst2.append(c)
i+=1
print(max(l... | -1 | |
245 | E | Mishap in Club | PROGRAMMING | 1,400 | [
"greedy",
"implementation"
] | null | null | Polycarpus just has been out of luck lately! As soon as he found a job in the "Binary Cat" cafe, the club got burgled. All ice-cream was stolen.
On the burglary night Polycarpus kept a careful record of all club visitors. Each time a visitor entered the club, Polycarpus put down character "+" in his notes. Similarly, ... | The only line of the input contains a sequence of characters "+" and "-", the characters are written one after another without any separators. The characters are written in the order, in which the corresponding events occurred. The given sequence has length from 1 to 300 characters, inclusive. | Print the sought minimum number of people | [
"+-+-+\n",
"---"
] | [
"1\n",
"3"
] | none | 0 | [
{
"input": "+-+-+",
"output": "1"
},
{
"input": "---",
"output": "3"
},
{
"input": "-",
"output": "1"
},
{
"input": "--",
"output": "2"
},
{
"input": "---",
"output": "3"
},
{
"input": "----",
"output": "4"
},
{
"input": "---+",
"output... | 1,592,856,893 | 2,147,483,647 | PyPy 3 | OK | TESTS | 30 | 280 | 20,172,800 | s=input()
count=0
# m=0÷
# extr÷a=0
a,b=0,0
for i in s:
if i=="+":
count+=1
else:
count-=1
a=min(a,count)
b=max(b,count)
print (b-a) | Title: Mishap in Club
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarpus just has been out of luck lately! As soon as he found a job in the "Binary Cat" cafe, the club got burgled. All ice-cream was stolen.
On the burglary night Polycarpus kept a careful record of all club visitor... | ```python
s=input()
count=0
# m=0÷
# extr÷a=0
a,b=0,0
for i in s:
if i=="+":
count+=1
else:
count-=1
a=min(a,count)
b=max(b,count)
print (b-a)
``` | 3 | |
519 | B | A and B and Compilation Errors | PROGRAMMING | 1,100 | [
"data structures",
"implementation",
"sortings"
] | null | null | A and B are preparing themselves for programming contests.
B loves to debug his code. But before he runs the solution and starts debugging, he has to first compile the code.
Initially, the compiler displayed *n* compilation errors, each of them is represented as a positive integer. After some effort, B managed to fix... | The first line of the input contains integer *n* (3<=≤<=*n*<=≤<=105) — the initial number of compilation errors.
The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the errors the compiler displayed for the first time.
The third line contains *n*<=-<=1 space-sepa... | Print two numbers on a single line: the numbers of the compilation errors that disappeared after B made the first and the second correction, respectively. | [
"5\n1 5 8 123 7\n123 7 5 1\n5 1 7\n",
"6\n1 4 3 3 5 7\n3 7 5 4 3\n4 3 7 5\n"
] | [
"8\n123\n",
"1\n3\n"
] | In the first test sample B first corrects the error number 8, then the error number 123.
In the second test sample B first corrects the error number 1, then the error number 3. Note that if there are multiple errors with the same number, B can correct only one of them in one step. | 1,000 | [
{
"input": "5\n1 5 8 123 7\n123 7 5 1\n5 1 7",
"output": "8\n123"
},
{
"input": "6\n1 4 3 3 5 7\n3 7 5 4 3\n4 3 7 5",
"output": "1\n3"
},
{
"input": "3\n1 2 3\n3 2\n2",
"output": "1\n3"
},
{
"input": "10\n460626451 802090732 277246428 661369649 388684428 784303821 376287098 6... | 1,621,073,693 | 2,147,483,647 | Python 3 | OK | TESTS | 33 | 171 | 15,052,800 | n = int (input ()) #количество ошибок
a_1 = list (map (int, input ().split ()))
a_2 = list (map (int, input ().split ()))
a_3 = list (map (int, input ().split ()))
print (sum (a_1) - sum (a_2), sum (a_2) - sum (a_3), sep = '\n')
| Title: A and B and Compilation Errors
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A and B are preparing themselves for programming contests.
B loves to debug his code. But before he runs the solution and starts debugging, he has to first compile the code.
Initially, the compiler disp... | ```python
n = int (input ()) #количество ошибок
a_1 = list (map (int, input ().split ()))
a_2 = list (map (int, input ().split ()))
a_3 = list (map (int, input ().split ()))
print (sum (a_1) - sum (a_2), sum (a_2) - sum (a_3), sep = '\n')
``` | 3 | |
722 | A | Broken Clock | PROGRAMMING | 1,300 | [
"brute force",
"implementation"
] | null | null | You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes change from 0 to 59.
You are given a time in format HH:MM that is currently displayed on the broken ... | The first line of the input contains one integer 12 or 24, that denote 12-hours or 24-hours format respectively.
The second line contains the time in format HH:MM, that is currently displayed on the clock. First two characters stand for the hours, while next two show the minutes. | The only line of the output should contain the time in format HH:MM that is a correct time in the given format. It should differ from the original in as few positions as possible. If there are many optimal solutions you can print any of them. | [
"24\n17:30\n",
"12\n17:30\n",
"24\n99:99\n"
] | [
"17:30\n",
"07:30\n",
"09:09\n"
] | none | 500 | [
{
"input": "24\n17:30",
"output": "17:30"
},
{
"input": "12\n17:30",
"output": "07:30"
},
{
"input": "24\n99:99",
"output": "09:09"
},
{
"input": "12\n05:54",
"output": "05:54"
},
{
"input": "12\n00:05",
"output": "01:05"
},
{
"input": "24\n23:80",
... | 1,475,331,319 | 618 | Python 3 | OK | TESTS | 52 | 77 | 0 | def best(h, n, x):
best = ''
bestCnt = 10
begin = 0
end = n
if x == 'h':
if n == 12:
begin = 1
end = 13
for i in range(begin, end):
si = str(i)
if len(si) == 1:
si = '0' + si
bad = 0
for x, y in zip(h, si):
i... | Title: Broken Clock
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a broken clock. You know, that it is supposed to show time in 12- or 24-hours HH:MM format. In 12-hours format hours change from 1 to 12, while in 24-hours it changes from 0 to 23. In both formats minutes cha... | ```python
def best(h, n, x):
best = ''
bestCnt = 10
begin = 0
end = n
if x == 'h':
if n == 12:
begin = 1
end = 13
for i in range(begin, end):
si = str(i)
if len(si) == 1:
si = '0' + si
bad = 0
for x, y in zip(h, si):
... | 3 | |
38 | A | Army | PROGRAMMING | 800 | [
"implementation"
] | A. Army | 2 | 256 | The Berland Armed Forces System consists of *n* ranks that are numbered using natural numbers from 1 to *n*, where 1 is the lowest rank and *n* is the highest rank.
One needs exactly *d**i* years to rise from rank *i* to rank *i*<=+<=1. Reaching a certain rank *i* having not reached all the previous *i*<=-<=1 ranks is... | The first input line contains an integer *n* (2<=≤<=*n*<=≤<=100). The second line contains *n*<=-<=1 integers *d**i* (1<=≤<=*d**i*<=≤<=100). The third input line contains two integers *a* and *b* (1<=≤<=*a*<=<<=*b*<=≤<=*n*). The numbers on the lines are space-separated. | Print the single number which is the number of years that Vasya needs to rise from rank *a* to rank *b*. | [
"3\n5 6\n1 2\n",
"3\n5 6\n1 3\n"
] | [
"5\n",
"11\n"
] | none | 0 | [
{
"input": "3\n5 6\n1 2",
"output": "5"
},
{
"input": "3\n5 6\n1 3",
"output": "11"
},
{
"input": "2\n55\n1 2",
"output": "55"
},
{
"input": "3\n85 78\n1 3",
"output": "163"
},
{
"input": "4\n63 4 49\n2 3",
"output": "4"
},
{
"input": "5\n93 83 42 56\n... | 1,694,269,843 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 62 | 0 | x = int(input())
z = []
w = []
z[0:] = map(int,input().split())
w[0:] = map(int,input().split())
count = 0
for i in range(w[0] - 1, w[1] - w[0]):
count += z[i]
print(count) | Title: Army
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
The Berland Armed Forces System consists of *n* ranks that are numbered using natural numbers from 1 to *n*, where 1 is the lowest rank and *n* is the highest rank.
One needs exactly *d**i* years to rise from rank *i* to rank *i*<=+<... | ```python
x = int(input())
z = []
w = []
z[0:] = map(int,input().split())
w[0:] = map(int,input().split())
count = 0
for i in range(w[0] - 1, w[1] - w[0]):
count += z[i]
print(count)
``` | 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,589,388,286 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 154 | 6,963,200 | import math
n = eval(input(""))
l = list(map(int, input("").split()))
d = []
m = 0
for i in range(n):
if i + 1 < n:
d.append(abs(l[i+1]-l[i]))
print(d)
for i in range(len(d)):
if d.count(d[i]) < len(d)-2:
m = i
print(m+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
import math
n = eval(input(""))
l = list(map(int, input("").split()))
d = []
m = 0
for i in range(n):
if i + 1 < n:
d.append(abs(l[i+1]-l[i]))
print(d)
for i in range(len(d)):
if d.count(d[i]) < len(d)-2:
m = i
print(m+1)
``` | 0 |
1 | B | Spreadsheet | PROGRAMMING | 1,600 | [
"implementation",
"math"
] | B. Spreadsheets | 10 | 64 | In the popular spreadsheets systems (for example, in Excel) the following numeration of columns is used. The first column has number A, the second — number B, etc. till column 26 that is marked by Z. Then there are two-letter numbers: column 27 has number AA, 28 — AB, column 52 is marked by AZ. After ZZ there follow th... | The first line of the input contains integer number *n* (1<=≤<=*n*<=≤<=105), the number of coordinates in the test. Then there follow *n* lines, each of them contains coordinates. All the coordinates are correct, there are no cells with the column and/or the row numbers larger than 106 . | Write *n* lines, each line should contain a cell coordinates in the other numeration system. | [
"2\nR23C55\nBC23\n"
] | [
"BC23\nR23C55\n"
] | none | 0 | [
{
"input": "2\nR23C55\nBC23",
"output": "BC23\nR23C55"
},
{
"input": "1\nA1",
"output": "R1C1"
},
{
"input": "5\nR8C3\nD1\nR7C2\nR8C9\nR8C9",
"output": "C8\nR1C4\nB7\nI8\nI8"
},
{
"input": "4\nR4C25\nR90C35\nAP55\nX83",
"output": "Y4\nAI90\nR55C42\nR83C24"
},
{
"i... | 1,663,240,203 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 5 | 372 | 3,788,800 | def col2num(col):
num = 0
for c in col:
num = num * 26 + (ord(c.upper()) - ord('A')) + 1
return num
def col2str(col):
col, rem = divmod(col - 1, 26)
char = chr(65 + rem)
if col:
return col2str(col) + char
else:
return char
n = int(input())
for _ i... | Title: Spreadsheet
Time Limit: 10 seconds
Memory Limit: 64 megabytes
Problem Description:
In the popular spreadsheets systems (for example, in Excel) the following numeration of columns is used. The first column has number A, the second — number B, etc. till column 26 that is marked by Z. Then there are two-letter n... | ```python
def col2num(col):
num = 0
for c in col:
num = num * 26 + (ord(c.upper()) - ord('A')) + 1
return num
def col2str(col):
col, rem = divmod(col - 1, 26)
char = chr(65 + rem)
if col:
return col2str(col) + char
else:
return char
n = int(input()... | 0 |
689 | A | Mike and Cellphone | PROGRAMMING | 1,400 | [
"brute force",
"constructive algorithms",
"implementation"
] | null | null | While swimming at the beach, Mike has accidentally dropped his cellphone into the water. There was no worry as he bought a cheap replacement phone with an old-fashioned keyboard. The keyboard has only ten digital equal-sized keys, located in the following way:
Together with his old phone, he lost all his contacts and ... | The first line of the input contains the only integer *n* (1<=≤<=*n*<=≤<=9) — the number of digits in the phone number that Mike put in.
The second line contains the string consisting of *n* digits (characters from '0' to '9') representing the number that Mike put in. | If there is no other phone number with the same finger movements and Mike can be sure he is calling the correct number, print "YES" (without quotes) in the only line.
Otherwise print "NO" (without quotes) in the first line. | [
"3\n586\n",
"2\n09\n",
"9\n123456789\n",
"3\n911\n"
] | [
"NO\n",
"NO\n",
"YES\n",
"YES\n"
] | You can find the picture clarifying the first sample case in the statement above. | 500 | [
{
"input": "3\n586",
"output": "NO"
},
{
"input": "2\n09",
"output": "NO"
},
{
"input": "9\n123456789",
"output": "YES"
},
{
"input": "3\n911",
"output": "YES"
},
{
"input": "3\n089",
"output": "NO"
},
{
"input": "3\n159",
"output": "YES"
},
{
... | 1,665,512,727 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 46 | 0 | t=1
while t>0:
t-=1
n=int(input())
s=input()
a=[]
for i in range(0,len(s)):
if s[i]!='0':
a.append(int(s[i]))
else:
a.append(11)
b=c=d=e=[]
for i in range(0,len(s)):
b.append(a[i]-3)
c.append(a[i]-1)
d.append(a[i]... | Title: Mike and Cellphone
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
While swimming at the beach, Mike has accidentally dropped his cellphone into the water. There was no worry as he bought a cheap replacement phone with an old-fashioned keyboard. The keyboard has only ten digital equ... | ```python
t=1
while t>0:
t-=1
n=int(input())
s=input()
a=[]
for i in range(0,len(s)):
if s[i]!='0':
a.append(int(s[i]))
else:
a.append(11)
b=c=d=e=[]
for i in range(0,len(s)):
b.append(a[i]-3)
c.append(a[i]-1)
d.a... | 0 | |
0 | none | none | none | 0 | [
"none"
] | null | null | Alyona's mother wants to present an array of *n* non-negative integers to Alyona. The array should be special.
Alyona is a capricious girl so after she gets the array, she inspects *m* of its subarrays. Subarray is a set of some subsequent elements of the array. The *i*-th subarray is described with two integers *l**... | The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=105).
The next *m* lines contain information about the subarrays chosen by Alyona. The *i*-th of these lines contains two integers *l**i* and *r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*), that describe the subarray *a*[*l**i*],<=*a*[*l**i*<=+<=1],<=...,... | In the first line print single integer — the maximum possible minimum mex.
In the second line print *n* integers — the array *a*. All the elements in *a* should be between 0 and 109.
It is guaranteed that there is an optimal answer in which all the elements in *a* are between 0 and 109.
If there are multiple solutio... | [
"5 3\n1 3\n2 5\n4 5\n",
"4 2\n1 4\n2 4\n"
] | [
"2\n1 0 2 1 0\n",
"3\n5 2 0 1"
] | The first example: the mex of the subarray (1, 3) is equal to 3, the mex of the subarray (2, 5) is equal to 3, the mex of the subarray (4, 5) is equal to 2 as well, thus the minumal mex among the subarrays chosen by Alyona is equal to 2. | 0 | [
{
"input": "5 3\n1 3\n2 5\n4 5",
"output": "2\n0 1 0 1 0"
},
{
"input": "4 2\n1 4\n2 4",
"output": "3\n0 1 2 0"
},
{
"input": "1 1\n1 1",
"output": "1\n0"
},
{
"input": "2 1\n2 2",
"output": "1\n0 0"
},
{
"input": "5 6\n2 4\n2 3\n1 4\n3 4\n2 5\n1 3",
"output":... | 1,512,354,653 | 2,147,483,647 | Python 3 | OK | TESTS | 69 | 670 | 5,939,200 | #import sys
#sys.stdin = open("stdin.inp", "r")
n, m = map(int, input().split())
minx = 0xfffffff
for i in range(0, m):
u, v = map(int, input().split())
minx = min(v - u + 1, minx)
print(minx)
for i in range(0, n):
print(i % minx, end=" ") | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Alyona's mother wants to present an array of *n* non-negative integers to Alyona. The array should be special.
Alyona is a capricious girl so after she gets the array, she inspects *m* of its subarrays. Subarray is a set of some... | ```python
#import sys
#sys.stdin = open("stdin.inp", "r")
n, m = map(int, input().split())
minx = 0xfffffff
for i in range(0, m):
u, v = map(int, input().split())
minx = min(v - u + 1, minx)
print(minx)
for i in range(0, n):
print(i % minx, end=" ")
``` | 3 |
Subsets and Splits
Successful Python Submissions
Retrieves all records from the train dataset where the verdict is 'OK', providing basic filtering but limited analytical value.
SQL Console for MatrixStudio/Codeforces-Python-Submissions
Retrieves records of users with a rating of 1600 or higher and a verdict of 'OK', providing basic filtering but limited analytical value.
SQL Console for MatrixStudio/Codeforces-Python-Submissions
Counts the number of entries with a rating above 2000 and a verdict of 'OK', providing basic filtering but limited analytical value.
SQL Console for MatrixStudio/Codeforces-Python-Submissions
Counts the number of entries with a 'OK' verdict, providing a basic overview of a specific category within the dataset.