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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
61 | A | Ultra-Fast Mathematician | PROGRAMMING | 800 | [
"implementation"
] | A. Ultra-Fast Mathematician | 2 | 256 | Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 1018 numbers in a single second.
One day in 230 AD Shapur was trying to find out if any one can possibly do... | There are two lines in each input. Each of them contains a single number. It is guaranteed that the numbers are made from 0 and 1 only and that their length is same. The numbers may start with 0. The length of each number doesn't exceed 100. | Write one line — the corresponding answer. Do not omit the leading 0s. | [
"1010100\n0100101\n",
"000\n111\n",
"1110\n1010\n",
"01110\n01100\n"
] | [
"1110001\n",
"111\n",
"0100\n",
"00010\n"
] | none | 500 | [
{
"input": "1010100\n0100101",
"output": "1110001"
},
{
"input": "000\n111",
"output": "111"
},
{
"input": "1110\n1010",
"output": "0100"
},
{
"input": "01110\n01100",
"output": "00010"
},
{
"input": "011101\n000001",
"output": "011100"
},
{
"input": "... | 1,593,802,364 | 2,147,483,647 | PyPy 3 | OK | TESTS | 102 | 140 | 0 | n = input()
m = input()
for i in range(len(n)):
print(int(n[i]) ^ int(m[i]), end = "")
| Title: Ultra-Fast Mathematician
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Shapur was an extremely gifted student. He was great at everything including Combinatorics, Algebra, Number Theory, Geometry, Calculus, etc. He was not only smart but extraordinarily fast! He could manage to sum 10... | ```python
n = input()
m = input()
for i in range(len(n)):
print(int(n[i]) ^ int(m[i]), end = "")
``` | 3.965 |
779 | B | Weird Rounding | PROGRAMMING | 1,100 | [
"brute force",
"greedy"
] | null | null | Polycarp is crazy about round numbers. He especially likes the numbers divisible by 10*k*.
In the given number of *n* Polycarp wants to remove the least number of digits to get a number that is divisible by 10*k*. For example, if *k*<==<=3, in the number 30020 it is enough to delete a single digit (2). In this case, t... | The only line of the input contains two integer numbers *n* and *k* (0<=≤<=*n*<=≤<=2<=000<=000<=000, 1<=≤<=*k*<=≤<=9).
It is guaranteed that the answer exists. All numbers in the input are written in traditional notation of integers, that is, without any extra leading zeros. | Print *w* — the required minimal number of digits to erase. After removing the appropriate *w* digits from the number *n*, the result should have a value that is divisible by 10*k*. The result can start with digit 0 in the single case (the result is zero and written by exactly the only digit 0). | [
"30020 3\n",
"100 9\n",
"10203049 2\n"
] | [
"1\n",
"2\n",
"3\n"
] | In the example 2 you can remove two digits: 1 and any 0. The result is number 0 which is divisible by any number. | 1,000 | [
{
"input": "30020 3",
"output": "1"
},
{
"input": "100 9",
"output": "2"
},
{
"input": "10203049 2",
"output": "3"
},
{
"input": "0 1",
"output": "0"
},
{
"input": "0 9",
"output": "0"
},
{
"input": "100 2",
"output": "0"
},
{
"input": "102... | 1,488,216,793 | 1,993 | Python 3 | WRONG_ANSWER | TESTS | 2 | 46 | 4,608,000 | a,b=map(int,input().split())
p=a
b=10**b
k=a//b
a=a-(k*b)
a=str(a)
v=0
if b>p:
v=len(a)-1
else:
for i in range(len(a)):
if int(a[i])>1:
v=v+1
print(v)
| Title: Weird Rounding
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp is crazy about round numbers. He especially likes the numbers divisible by 10*k*.
In the given number of *n* Polycarp wants to remove the least number of digits to get a number that is divisible by 10*k*. For e... | ```python
a,b=map(int,input().split())
p=a
b=10**b
k=a//b
a=a-(k*b)
a=str(a)
v=0
if b>p:
v=len(a)-1
else:
for i in range(len(a)):
if int(a[i])>1:
v=v+1
print(v)
``` | 0 | |
78 | B | Easter Eggs | PROGRAMMING | 1,200 | [
"constructive algorithms",
"implementation"
] | B. Easter Eggs | 2 | 256 | The Easter Rabbit laid *n* eggs in a circle and is about to paint them.
Each egg should be painted one color out of 7: red, orange, yellow, green, blue, indigo or violet. Also, the following conditions should be satisfied:
- Each of the seven colors should be used to paint at least one egg. - Any four eggs lying s... | The only line contains an integer *n* — the amount of eggs (7<=≤<=*n*<=≤<=100). | Print one line consisting of *n* characters. The *i*-th character should describe the color of the *i*-th egg in the order they lie in the circle. The colors should be represented as follows: "R" stands for red, "O" stands for orange, "Y" stands for yellow, "G" stands for green, "B" stands for blue, "I" stands for indi... | [
"8\n",
"13\n"
] | [
"ROYGRBIV\n",
"ROYGBIVGBIVYG\n"
] | The way the eggs will be painted in the first sample is shown on the picture: | 1,000 | [
{
"input": "8",
"output": "ROYGBIVG"
},
{
"input": "13",
"output": "ROYGBIVOYGBIV"
},
{
"input": "7",
"output": "ROYGBIV"
},
{
"input": "10",
"output": "ROYGBIVYGB"
},
{
"input": "14",
"output": "ROYGBIVROYGBIV"
},
{
"input": "50",
"output": "ROYGB... | 1,571,720,035 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 218 | 0 | n = int(input())
s = 'ROYGBIV'
s1 = 'GBIV'
print(s, (n - 7) // 4 * s1, s1[:(n - 7) % 4], sep='')
| Title: Easter Eggs
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
The Easter Rabbit laid *n* eggs in a circle and is about to paint them.
Each egg should be painted one color out of 7: red, orange, yellow, green, blue, indigo or violet. Also, the following conditions should be satisfied:
-... | ```python
n = int(input())
s = 'ROYGBIV'
s1 = 'GBIV'
print(s, (n - 7) // 4 * s1, s1[:(n - 7) % 4], sep='')
``` | 3.9455 |
336 | A | Vasily the Bear and Triangle | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | null | null | Vasily the bear has a favorite rectangle, it has one vertex at point (0,<=0), and the opposite vertex at point (*x*,<=*y*). Of course, the sides of Vasya's favorite rectangle are parallel to the coordinate axes.
Vasya also loves triangles, if the triangles have one vertex at point *B*<==<=(0,<=0). That's why today he... | The first line contains two integers *x*,<=*y* (<=-<=109<=≤<=*x*,<=*y*<=≤<=109,<=*x*<=≠<=0,<=*y*<=≠<=0). | Print in the single line four integers *x*1,<=*y*1,<=*x*2,<=*y*2 — the coordinates of the required points. | [
"10 5\n",
"-10 5\n"
] | [
"0 15 15 0\n",
"-15 0 0 15\n"
] | <img class="tex-graphics" src="https://espresso.codeforces.com/a9ea2088c4294ce8f23801562fda36b830df2c3f.png" style="max-width: 100.0%;max-height: 100.0%;"/>
Figure to the first sample | 500 | [
{
"input": "10 5",
"output": "0 15 15 0"
},
{
"input": "-10 5",
"output": "-15 0 0 15"
},
{
"input": "20 -10",
"output": "0 -30 30 0"
},
{
"input": "-10 -1000000000",
"output": "-1000000010 0 0 -1000000010"
},
{
"input": "-1000000000 -1000000000",
"output": "-... | 1,631,882,233 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 122 | 6,963,200 | x,y = map(int, input().split())
if x > 0 and y > 0:
print(0, x+y, x+y, 0)
elif x < 0 and y > 0:
print(x-y, 0, 0, -(x-y))
elif x < 0 and y < 0:
print(x+y, 0, 0, -(x+y))
else:
print(0, -(x-y), x-y, 0)
| Title: Vasily the Bear and Triangle
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasily the bear has a favorite rectangle, it has one vertex at point (0,<=0), and the opposite vertex at point (*x*,<=*y*). Of course, the sides of Vasya's favorite rectangle are parallel to the coordinate ... | ```python
x,y = map(int, input().split())
if x > 0 and y > 0:
print(0, x+y, x+y, 0)
elif x < 0 and y > 0:
print(x-y, 0, 0, -(x-y))
elif x < 0 and y < 0:
print(x+y, 0, 0, -(x+y))
else:
print(0, -(x-y), x-y, 0)
``` | 0 | |
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,689,424,150 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 63 | 93 | 13,209,600 | # import sys
# sys.stdin = open('./input.txt', 'r')
# sys.stdout = open('./output.txt', 'w')
n = int(input())
events = list(map(int, input().split()))
untreated = 0
free = 0
for event in events:
if event > 0:
free += event
else:
if free > 0:
free -= 1
else:
... | 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
# import sys
# sys.stdin = open('./input.txt', 'r')
# sys.stdout = open('./output.txt', 'w')
n = int(input())
events = list(map(int, input().split()))
untreated = 0
free = 0
for event in events:
if event > 0:
free += event
else:
if free > 0:
free -= 1
... | 3 | |
334 | A | Candy Bags | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Gerald has *n* younger brothers and their number happens to be even. One day he bought *n*2 candy bags. One bag has one candy, one bag has two candies, one bag has three candies and so on. In fact, for each integer *k* from 1 to *n*2 he has exactly one bag with *k* candies.
Help him give *n* bags of candies to each b... | The single line contains a single integer *n* (*n* is even, 2<=≤<=*n*<=≤<=100) — the number of Gerald's brothers. | Let's assume that Gerald indexes his brothers with numbers from 1 to *n*. You need to print *n* lines, on the *i*-th line print *n* integers — the numbers of candies in the bags for the *i*-th brother. Naturally, all these numbers should be distinct and be within limits from 1 to *n*2. You can print the numbers in the ... | [
"2\n"
] | [
"1 4\n2 3\n"
] | The sample shows Gerald's actions if he has two brothers. In this case, his bags contain 1, 2, 3 and 4 candies. He can give the bags with 1 and 4 candies to one brother and the bags with 2 and 3 to the other brother. | 500 | [
{
"input": "2",
"output": "1 4\n2 3"
},
{
"input": "4",
"output": "1 16 2 15\n3 14 4 13\n5 12 6 11\n7 10 8 9"
},
{
"input": "6",
"output": "1 36 2 35 3 34\n4 33 5 32 6 31\n7 30 8 29 9 28\n10 27 11 26 12 25\n13 24 14 23 15 22\n16 21 17 20 18 19"
},
{
"input": "8",
"output"... | 1,502,766,119 | 2,147,483,647 | Python 3 | OK | TESTS | 21 | 154 | 4,915,200 | n = int(input())
bags = []
for i in range(1, n**2+1):
bags.append(i);
brothers = []
for i in range(n):
brothers.append([])
i=0
while(i < int(n/2)):
j=0
while(j < n):
brothers[j].append(bags[0])
brothers[j].append(bags[-1])
bags.pop(... | Title: Candy Bags
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Gerald has *n* younger brothers and their number happens to be even. One day he bought *n*2 candy bags. One bag has one candy, one bag has two candies, one bag has three candies and so on. In fact, for each integer *k* from ... | ```python
n = int(input())
bags = []
for i in range(1, n**2+1):
bags.append(i);
brothers = []
for i in range(n):
brothers.append([])
i=0
while(i < int(n/2)):
j=0
while(j < n):
brothers[j].append(bags[0])
brothers[j].append(bags[-1])
... | 3 | |
652 | F | Ants on a Circle | PROGRAMMING | 2,800 | [
"constructive algorithms",
"math"
] | null | null | *n* ants are on a circle of length *m*. An ant travels one unit of distance per one unit of time. Initially, the ant number *i* is located at the position *s**i* and is facing in the direction *d**i* (which is either L or R). Positions are numbered in counterclockwise order starting from some point. Positions of the al... | The first line contains three integers *n*, *m* and *t* (2<=≤<=*n*<=≤<=3·105,<=2<=≤<=*m*<=≤<=109,<=0<=≤<=*t*<=≤<=1018) — the number of ants, the length of the circle and the number of time units.
Each of the next *n* lines contains integer *s**i* and symbol *d**i* (1<=≤<=*s**i*<=≤<=*m* and *d**i* is either L or R) — t... | Print *n* integers *x**j* — the position of the *j*-th ant after *t* units of time. The ants are numbered from 1 to *n* in order of their appearing in input. | [
"2 4 8\n1 R\n3 L\n",
"4 8 6\n6 R\n5 L\n1 R\n8 L\n",
"4 8 2\n1 R\n5 L\n6 L\n8 R\n"
] | [
"1 3\n",
"7 4 2 7\n",
"3 3 4 2\n"
] | none | 0 | [
{
"input": "2 4 8\n1 R\n3 L",
"output": "1 3"
},
{
"input": "4 8 6\n6 R\n5 L\n1 R\n8 L",
"output": "7 4 2 7"
},
{
"input": "4 8 2\n1 R\n5 L\n6 L\n8 R",
"output": "3 3 4 2"
},
{
"input": "10 10 90\n2 R\n1 R\n3 L\n4 R\n7 L\n8 L\n6 R\n9 R\n5 R\n10 L",
"output": "10 9 1 2 5 6... | 1,693,157,383 | 2,147,483,647 | PyPy 3-64 | TIME_LIMIT_EXCEEDED | TESTS | 22 | 2,000 | 34,099,200 | n, m, t = map(int, input().split())
reord = []
ord = []
total_speed = 0
outpos = []
for i in range(n):
s, c = input().split()
s = int(s) % m
reord.append((s % m, i))
if c == 'R':
total_speed += 1
outpos.append((int(s) + t) % m)
else:
total_speed -= 1
out... | Title: Ants on a Circle
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
*n* ants are on a circle of length *m*. An ant travels one unit of distance per one unit of time. Initially, the ant number *i* is located at the position *s**i* and is facing in the direction *d**i* (which is either L... | ```python
n, m, t = map(int, input().split())
reord = []
ord = []
total_speed = 0
outpos = []
for i in range(n):
s, c = input().split()
s = int(s) % m
reord.append((s % m, i))
if c == 'R':
total_speed += 1
outpos.append((int(s) + t) % m)
else:
total_speed -= 1
... | 0 | |
25 | B | Phone numbers | PROGRAMMING | 1,100 | [
"implementation"
] | B. Phone numbers | 2 | 256 | Phone number in Berland is a sequence of *n* digits. Often, to make it easier to memorize the number, it is divided into groups of two or three digits. For example, the phone number 1198733 is easier to remember as 11-987-33. Your task is to find for a given phone number any of its divisions into groups of two or three... | The first line contains integer *n* (2<=≤<=*n*<=≤<=100) — amount of digits in the phone number. The second line contains *n* digits — the phone number to divide into groups. | Output any of divisions of the given phone number into groups of two or three digits. Separate groups by single character -. If the answer is not unique, output any. | [
"6\n549871\n",
"7\n1198733\n"
] | [
"54-98-71",
"11-987-33\n"
] | none | 0 | [
{
"input": "6\n549871",
"output": "54-98-71"
},
{
"input": "7\n1198733",
"output": "119-87-33"
},
{
"input": "2\n74",
"output": "74"
},
{
"input": "2\n33",
"output": "33"
},
{
"input": "3\n074",
"output": "074"
},
{
"input": "3\n081",
"output": "08... | 1,586,652,579 | 2,147,483,647 | Python 3 | OK | TESTS | 20 | 280 | 307,200 | def string2list(x):
x=x.split()
i=0
#print(hi)
for i in range(len(x)):
x[i]=int(x[i])
return x
#def list2string(x)
# (' '.join(state.rem[0:states.total]))
n=int(input())
number=input()
k=0
current=0
output=['']*(3*n)
if n % 2==0:
while k<n:
#print('The value of k is')
#... | Title: Phone numbers
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Phone number in Berland is a sequence of *n* digits. Often, to make it easier to memorize the number, it is divided into groups of two or three digits. For example, the phone number 1198733 is easier to remember as 11-987-33.... | ```python
def string2list(x):
x=x.split()
i=0
#print(hi)
for i in range(len(x)):
x[i]=int(x[i])
return x
#def list2string(x)
# (' '.join(state.rem[0:states.total]))
n=int(input())
number=input()
k=0
current=0
output=['']*(3*n)
if n % 2==0:
while k<n:
#print('The value of k is')... | 3.929428 |
372 | A | Counting Kangaroos is Fun | PROGRAMMING | 1,600 | [
"binary search",
"greedy",
"sortings",
"two pointers"
] | null | null | There are *n* kangaroos with pockets. Each kangaroo has a size (integer number). A kangaroo can go into another kangaroo's pocket if and only if the size of kangaroo who hold the kangaroo is at least twice as large as the size of kangaroo who is held.
Each kangaroo can hold at most one kangaroo, and the kangaroo who i... | The first line contains a single integer — *n* (1<=≤<=*n*<=≤<=5·105). Each of the next *n* lines contains an integer *s**i* — the size of the *i*-th kangaroo (1<=≤<=*s**i*<=≤<=105). | Output a single integer — the optimal number of visible kangaroos. | [
"8\n2\n5\n7\n6\n9\n8\n4\n2\n",
"8\n9\n1\n6\n2\n6\n5\n8\n3\n"
] | [
"5\n",
"5\n"
] | none | 500 | [
{
"input": "8\n2\n5\n7\n6\n9\n8\n4\n2",
"output": "5"
},
{
"input": "8\n9\n1\n6\n2\n6\n5\n8\n3",
"output": "5"
},
{
"input": "12\n3\n99\n24\n46\n75\n63\n57\n55\n10\n62\n34\n52",
"output": "7"
},
{
"input": "12\n55\n75\n1\n98\n63\n64\n9\n39\n82\n18\n47\n9",
"output": "6"
... | 1,592,288,154 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 8 | 1,000 | 10,240,000 | n = int(input())
k = [int(input()) for _ in range(n)]
k.sort()
half = n//2
i, j = 0, half
ans = n
for i in range(half):
while True:
if k[i] * 2 <= k[j]:
ans -= 1
j += 1
break
j += 1
if j == n:
break
if j == n:
break
... | Title: Counting Kangaroos is Fun
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* kangaroos with pockets. Each kangaroo has a size (integer number). A kangaroo can go into another kangaroo's pocket if and only if the size of kangaroo who hold the kangaroo is at least twice as ... | ```python
n = int(input())
k = [int(input()) for _ in range(n)]
k.sort()
half = n//2
i, j = 0, half
ans = n
for i in range(half):
while True:
if k[i] * 2 <= k[j]:
ans -= 1
j += 1
break
j += 1
if j == n:
break
if j == n:
... | 0 | |
940 | B | Our Tanya is Crying Out Loud | PROGRAMMING | 1,400 | [
"dp",
"greedy"
] | null | null | Right now she actually isn't. But she will be, if you don't solve this problem.
You are given integers *n*, *k*, *A* and *B*. There is a number *x*, which is initially equal to *n*. You are allowed to perform two types of operations:
1. Subtract 1 from *x*. This operation costs you *A* coins. 1. Divide *x* by *k*.... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=2·109).
The second line contains a single integer *k* (1<=≤<=*k*<=≤<=2·109).
The third line contains a single integer *A* (1<=≤<=*A*<=≤<=2·109).
The fourth line contains a single integer *B* (1<=≤<=*B*<=≤<=2·109). | Output a single integer — the minimum amount of coins you have to pay to make *x* equal to 1. | [
"9\n2\n3\n1\n",
"5\n5\n2\n20\n",
"19\n3\n4\n2\n"
] | [
"6\n",
"8\n",
"12\n"
] | In the first testcase, the optimal strategy is as follows:
- Subtract 1 from *x* (9 → 8) paying 3 coins. - Divide *x* by 2 (8 → 4) paying 1 coin. - Divide *x* by 2 (4 → 2) paying 1 coin. - Divide *x* by 2 (2 → 1) paying 1 coin.
The total cost is 6 coins.
In the second test case the optimal strategy is to subtra... | 1,250 | [
{
"input": "9\n2\n3\n1",
"output": "6"
},
{
"input": "5\n5\n2\n20",
"output": "8"
},
{
"input": "19\n3\n4\n2",
"output": "12"
},
{
"input": "1845999546\n999435865\n1234234\n2323423",
"output": "1044857680578777"
},
{
"input": "1604353664\n1604353665\n9993432\n1",
... | 1,589,189,815 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 2 | 124 | 20,172,800 | n=int(input())
k=int(input())
a=int(input())
b=int(input())
cost=0
while n>1:
if n%k==0:
x=n//k
if b>a*(n-x):
cost+=a*(n-x)
else:
cost+=b
n=n//k
else:
if n<k:
cost+=n-1
n=1
else:
x=n%k
... | Title: Our Tanya is Crying Out Loud
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Right now she actually isn't. But she will be, if you don't solve this problem.
You are given integers *n*, *k*, *A* and *B*. There is a number *x*, which is initially equal to *n*. You are allowed to perf... | ```python
n=int(input())
k=int(input())
a=int(input())
b=int(input())
cost=0
while n>1:
if n%k==0:
x=n//k
if b>a*(n-x):
cost+=a*(n-x)
else:
cost+=b
n=n//k
else:
if n<k:
cost+=n-1
n=1
else:
... | 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,501,808 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 60 | 0 | board = input("Board Size: ")
M = int(board.split(" ")[0])
N = int(board.split(" ")[1])
print((M*N)//2) | Title: Domino piling
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as p... | ```python
board = input("Board Size: ")
M = int(board.split(" ")[0])
N = int(board.split(" ")[1])
print((M*N)//2)
``` | 0 |
59 | A | Word | PROGRAMMING | 800 | [
"implementation",
"strings"
] | A. Word | 2 | 256 | Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At th... | The first line contains a word *s* — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100. | Print the corrected word *s*. If the given word *s* has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one. | [
"HoUse\n",
"ViP\n",
"maTRIx\n"
] | [
"house\n",
"VIP\n",
"matrix\n"
] | none | 500 | [
{
"input": "HoUse",
"output": "house"
},
{
"input": "ViP",
"output": "VIP"
},
{
"input": "maTRIx",
"output": "matrix"
},
{
"input": "BNHWpnpawg",
"output": "bnhwpnpawg"
},
{
"input": "VTYGP",
"output": "VTYGP"
},
{
"input": "CHNenu",
"output": "chn... | 1,632,070,175 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 154 | 6,758,400 | s = input()
l = [1 if c.islower() else 0 for c in s]
print(s.upper() if 2*sum(l)<len(s) else s.lower())
| Title: Word
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it ei... | ```python
s = input()
l = [1 if c.islower() else 0 for c in s]
print(s.upper() if 2*sum(l)<len(s) else s.lower())
``` | 3.948911 |
629 | A | Far Relative’s Birthday Cake | PROGRAMMING | 800 | [
"brute force",
"combinatorics",
"constructive algorithms",
"implementation"
] | null | null | Door's family is going celebrate Famil Doors's birthday party. They love Famil Door so they are planning to make his birthday cake weird!
The cake is a *n*<=×<=*n* square consisting of equal squares with side length 1. Each square is either empty or consists of a single chocolate. They bought the cake and randomly sta... | In the first line of the input, you are given a single integer *n* (1<=≤<=*n*<=≤<=100) — the length of the side of the cake.
Then follow *n* lines, each containing *n* characters. Empty cells are denoted with '.', while cells that contain chocolates are denoted by 'C'. | Print the value of Famil Door's happiness, i.e. the number of pairs of chocolate pieces that share the same row or the same column. | [
"3\n.CC\nC..\nC.C\n",
"4\nCC..\nC..C\n.CC.\n.CC.\n"
] | [
"4\n",
"9\n"
] | If we number rows from top to bottom and columns from left to right, then, pieces that share the same row in the first sample are:
1. (1, 2) and (1, 3) 1. (3, 1) and (3, 3) 1. (2, 1) and (3, 1) 1. (1, 3) and (3, 3) | 500 | [
{
"input": "3\n.CC\nC..\nC.C",
"output": "4"
},
{
"input": "4\nCC..\nC..C\n.CC.\n.CC.",
"output": "9"
},
{
"input": "5\n.CCCC\nCCCCC\n.CCC.\nCC...\n.CC.C",
"output": "46"
},
{
"input": "7\n.CC..CC\nCC.C..C\nC.C..C.\nC...C.C\nCCC.CCC\n.CC...C\n.C.CCC.",
"output": "84"
},... | 1,455,986,549 | 449 | Python 3 | OK | TESTS | 48 | 62 | 0 | def C(k):
return (k*(k-1))//2
n=int(input())
r=[0 for i in range(n)]
c=[0 for i in range(n)]
for i in range(n):
s=input()
for j in range(n):
if s[j]=='C':
r[i]+=1
c[j]+=1
ans=0
for i in range(n):
ans+=(C(r[i])+C(c[i]))
print(ans)
| Title: Far Relative’s Birthday Cake
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Door's family is going celebrate Famil Doors's birthday party. They love Famil Door so they are planning to make his birthday cake weird!
The cake is a *n*<=×<=*n* square consisting of equal squares with s... | ```python
def C(k):
return (k*(k-1))//2
n=int(input())
r=[0 for i in range(n)]
c=[0 for i in range(n)]
for i in range(n):
s=input()
for j in range(n):
if s[j]=='C':
r[i]+=1
c[j]+=1
ans=0
for i in range(n):
ans+=(C(r[i])+C(c[i]))
print(ans)
``` | 3 | |
41 | A | Translation | PROGRAMMING | 800 | [
"implementation",
"strings"
] | A. Translation | 2 | 256 | The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pronounced) reversely. For example, a Berlandish word code corresponds to a Birlandish word edoc.... | The first line contains word *s*, the second line contains word *t*. The words consist of lowercase Latin letters. The input data do not consist unnecessary spaces. The words are not empty and their lengths do not exceed 100 symbols. | If the word *t* is a word *s*, written reversely, print YES, otherwise print NO. | [
"code\nedoc\n",
"abb\naba\n",
"code\ncode\n"
] | [
"YES\n",
"NO\n",
"NO\n"
] | none | 500 | [
{
"input": "code\nedoc",
"output": "YES"
},
{
"input": "abb\naba",
"output": "NO"
},
{
"input": "code\ncode",
"output": "NO"
},
{
"input": "abacaba\nabacaba",
"output": "YES"
},
{
"input": "q\nq",
"output": "YES"
},
{
"input": "asrgdfngfnmfgnhweratgjkk... | 1,661,414,865 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 9 | 92 | 0 | n=list(input())
x=list(input())
if len(n)>len(x):
print("NO")
elif len(x)>len(n):
print("NO")
else:
k=len(x)
p=0
for i in range(k):
if x[i]==n[-1-i]:
p=p+1
if p==k:
print("YES")
else:
print("NO")
| Title: Translation
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pron... | ```python
n=list(input())
x=list(input())
if len(n)>len(x):
print("NO")
elif len(x)>len(n):
print("NO")
else:
k=len(x)
p=0
for i in range(k):
if x[i]==n[-1-i]:
p=p+1
if p==k:
print("YES")
else:
print("NO")
``` | -1 |
995 | C | Leaving the Bar | PROGRAMMING | 2,300 | [
"brute force",
"data structures",
"geometry",
"greedy",
"math",
"sortings"
] | null | null | For a vector $\vec{v} = (x, y)$, define $|v| = \sqrt{x^2 + y^2}$.
Allen had a bit too much to drink at the bar, which is at the origin. There are $n$ vectors $\vec{v_1}, \vec{v_2}, \cdots, \vec{v_n}$. Allen will make $n$ moves. As Allen's sense of direction is impaired, during the $i$-th move he will either move in th... | The first line contains a single integer $n$ ($1 \le n \le 10^5$) — the number of moves.
Each of the following lines contains two space-separated integers $x_i$ and $y_i$, meaning that $\vec{v_i} = (x_i, y_i)$. We have that $|v_i| \le 10^6$ for all $i$. | Output a single line containing $n$ integers $c_1, c_2, \cdots, c_n$, each of which is either $1$ or $-1$. Your solution is correct if the value of $p = \sum_{i = 1}^n c_i \vec{v_i}$, satisfies $|p| \le 1.5 \cdot 10^6$.
It can be shown that a solution always exists under the given constraints. | [
"3\n999999 0\n0 999999\n999999 0\n",
"1\n-824590 246031\n",
"8\n-67761 603277\n640586 -396671\n46147 -122580\n569609 -2112\n400 914208\n131792 309779\n-850150 -486293\n5272 721899\n"
] | [
"1 1 -1 \n",
"1 \n",
"1 1 1 1 1 1 1 -1 \n"
] | none | 1,500 | [
{
"input": "3\n999999 0\n0 999999\n999999 0",
"output": "1 1 -1 "
},
{
"input": "1\n-824590 246031",
"output": "1 "
},
{
"input": "8\n-67761 603277\n640586 -396671\n46147 -122580\n569609 -2112\n400 914208\n131792 309779\n-850150 -486293\n5272 721899",
"output": "1 1 1 1 1 1 1 -1 "
... | 1,530,031,570 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 0 | 2,000 | 512,000 | import random
n = int(input())
v = []
for _ in range(0, n):
x, y = map(int, input().split())
v.append([x, y, x*x+y*y])
while 1>0:
for i in range(n):
random.shuffle(v)
x = 0
y = 0
ans = []
if (x+v[i][0])**2+(y+v[i][1])**2 < (x-v[i][0])**2+(y-v[i][1])**2... | Title: Leaving the Bar
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
For a vector $\vec{v} = (x, y)$, define $|v| = \sqrt{x^2 + y^2}$.
Allen had a bit too much to drink at the bar, which is at the origin. There are $n$ vectors $\vec{v_1}, \vec{v_2}, \cdots, \vec{v_n}$. Allen will make $... | ```python
import random
n = int(input())
v = []
for _ in range(0, n):
x, y = map(int, input().split())
v.append([x, y, x*x+y*y])
while 1>0:
for i in range(n):
random.shuffle(v)
x = 0
y = 0
ans = []
if (x+v[i][0])**2+(y+v[i][1])**2 < (x-v[i][0])**2+(y-v... | 0 | |
129 | B | Students and Shoelaces | PROGRAMMING | 1,200 | [
"brute force",
"dfs and similar",
"graphs",
"implementation"
] | null | null | Anna and Maria are in charge of the math club for junior students. When the club gathers together, the students behave badly. They've brought lots of shoe laces to the club and got tied with each other. Specifically, each string ties together two students. Besides, if two students are tied, then the lace connects the f... | The first line contains two integers *n* and *m* — the initial number of students and laces (). The students are numbered from 1 to *n*, and the laces are numbered from 1 to *m*. Next *m* lines each contain two integers *a* and *b* — the numbers of students tied by the *i*-th lace (1<=≤<=*a*,<=*b*<=≤<=*n*,<=*a*<=≠<=*b*... | Print the single number — the number of groups of students that will be kicked out from the club. | [
"3 3\n1 2\n2 3\n3 1\n",
"6 3\n1 2\n2 3\n3 4\n",
"6 5\n1 4\n2 4\n3 4\n5 4\n6 4\n"
] | [
"0\n",
"2\n",
"1\n"
] | In the first sample Anna and Maria won't kick out any group of students — in the initial position every student is tied to two other students and Anna won't be able to reprimand anyone.
In the second sample four students are tied in a chain and two more are running by themselves. First Anna and Maria kick out the two ... | 1,000 | [
{
"input": "3 3\n1 2\n2 3\n3 1",
"output": "0"
},
{
"input": "6 3\n1 2\n2 3\n3 4",
"output": "2"
},
{
"input": "6 5\n1 4\n2 4\n3 4\n5 4\n6 4",
"output": "1"
},
{
"input": "100 0",
"output": "0"
},
{
"input": "5 5\n1 2\n2 3\n3 4\n4 5\n5 1",
"output": "0"
},
... | 1,670,132,097 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 5 | 62 | 0 | def main():
V, E = list(map(int, input().split()))
A = [[] for _ in range(V)]
for _ in range(E):
x, y = list(map(int, input().split()))
x -= 1
y -= 1
A[x].append(y)
A[y].append(x)
group = 0
compare = 1
while True:
reprimand = []
... | Title: Students and Shoelaces
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Anna and Maria are in charge of the math club for junior students. When the club gathers together, the students behave badly. They've brought lots of shoe laces to the club and got tied with each other. Specifica... | ```python
def main():
V, E = list(map(int, input().split()))
A = [[] for _ in range(V)]
for _ in range(E):
x, y = list(map(int, input().split()))
x -= 1
y -= 1
A[x].append(y)
A[y].append(x)
group = 0
compare = 1
while True:
reprimand = ... | 0 | |
78 | A | Haiku | PROGRAMMING | 800 | [
"implementation",
"strings"
] | A. Haiku | 2 | 256 | Haiku is a genre of Japanese traditional poetry.
A haiku poem consists of 17 syllables split into three phrases, containing 5, 7 and 5 syllables correspondingly (the first phrase should contain exactly 5 syllables, the second phrase should contain exactly 7 syllables, and the third phrase should contain exactly 5 syll... | The input data consists of three lines. The length of each line is between 1 and 100, inclusive. The *i*-th line contains the *i*-th phrase of the poem. Each phrase consists of one or more words, which are separated by one or more spaces. A word is a non-empty sequence of lowercase Latin letters. Leading and/or trailin... | Print "YES" (without the quotes) if the poem is a haiku. Otherwise, print "NO" (also without the quotes). | [
"on codeforces \nbeta round is running\n a rustling of keys \n",
"how many gallons\nof edo s rain did you drink\n cuckoo\n"
] | [
"YES",
"NO"
] | none | 500 | [
{
"input": "on codeforces \nbeta round is running\n a rustling of keys ",
"output": "YES"
},
{
"input": "how many gallons\nof edo s rain did you drink\n cuckoo",
"output": "NO"
},
{
"input": " hatsu shigure\n saru mo komino wo\nhoshige nari",
... | 1,694,202,992 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 40 | 124 | 0 | def main():
ans=''
for i in range(3):
s=input()
count=0
if(i==0 or i==2):
for j in range(len(s)):
if (s[j]=='a' or s[j]=='e' or s[j]=='i' or s[j]=='o' or s[j]=='u'):
count+=1
if count!=5:
ans='NO'
... | Title: Haiku
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Haiku is a genre of Japanese traditional poetry.
A haiku poem consists of 17 syllables split into three phrases, containing 5, 7 and 5 syllables correspondingly (the first phrase should contain exactly 5 syllables, the second phrase... | ```python
def main():
ans=''
for i in range(3):
s=input()
count=0
if(i==0 or i==2):
for j in range(len(s)):
if (s[j]=='a' or s[j]=='e' or s[j]=='i' or s[j]=='o' or s[j]=='u'):
count+=1
if count!=5:
a... | 3.969 |
258 | A | Little Elephant and Bits | PROGRAMMING | 1,100 | [
"greedy",
"math"
] | null | null | The Little Elephant has an integer *a*, written in the binary notation. He wants to write this number on a piece of paper.
To make sure that the number *a* fits on the piece of paper, the Little Elephant ought to delete exactly one any digit from number *a* in the binary record. At that a new number appears. It consis... | The single line contains integer *a*, written in the binary notation without leading zeroes. This number contains more than 1 and at most 105 digits. | In the single line print the number that is written without leading zeroes in the binary notation — the answer to the problem. | [
"101\n",
"110010\n"
] | [
"11\n",
"11010\n"
] | In the first sample the best strategy is to delete the second digit. That results in number 11<sub class="lower-index">2</sub> = 3<sub class="lower-index">10</sub>.
In the second sample the best strategy is to delete the third or fourth digits — that results in number 11010<sub class="lower-index">2</sub> = 26<sub cla... | 500 | [
{
"input": "101",
"output": "11"
},
{
"input": "110010",
"output": "11010"
},
{
"input": "10000",
"output": "1000"
},
{
"input": "1111111110",
"output": "111111111"
},
{
"input": "10100101011110101",
"output": "1100101011110101"
},
{
"input": "11101001... | 1,591,912,372 | 2,147,483,647 | PyPy 3 | OK | TESTS | 37 | 342 | 9,420,800 | n=input()
n=list(n)
if(n.count('0')==0):
print(''.join(map(str,n[0:len(n)-1])))
else:
a=n.index('0')
n.remove(n[a])
print(''.join(map(str,n)))
| Title: Little Elephant and Bits
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Little Elephant has an integer *a*, written in the binary notation. He wants to write this number on a piece of paper.
To make sure that the number *a* fits on the piece of paper, the Little Elephant ought... | ```python
n=input()
n=list(n)
if(n.count('0')==0):
print(''.join(map(str,n[0:len(n)-1])))
else:
a=n.index('0')
n.remove(n[a])
print(''.join(map(str,n)))
``` | 3 | |
116 | A | Tram | PROGRAMMING | 800 | [
"implementation"
] | null | null | Linear Kingdom has exactly one tram line. It has *n* stops, numbered from 1 to *n* in the order of tram's movement. At the *i*-th stop *a**i* passengers exit the tram, while *b**i* passengers enter it. The tram is empty before it arrives at the first stop. Also, when the tram arrives at the last stop, all passengers ex... | The first line contains a single number *n* (2<=≤<=*n*<=≤<=1000) — the number of the tram's stops.
Then *n* lines follow, each contains two integers *a**i* and *b**i* (0<=≤<=*a**i*,<=*b**i*<=≤<=1000) — the number of passengers that exits the tram at the *i*-th stop, and the number of passengers that enter the tram at... | Print a single integer denoting the minimum possible capacity of the tram (0 is allowed). | [
"4\n0 3\n2 5\n4 2\n4 0\n"
] | [
"6\n"
] | For the first example, a capacity of 6 is sufficient:
- At the first stop, the number of passengers inside the tram before arriving is 0. Then, 3 passengers enter the tram, and the number of passengers inside the tram becomes 3. - At the second stop, 2 passengers exit the tram (1 passenger remains inside). Then, 5 ... | 500 | [
{
"input": "4\n0 3\n2 5\n4 2\n4 0",
"output": "6"
},
{
"input": "5\n0 4\n4 6\n6 5\n5 4\n4 0",
"output": "6"
},
{
"input": "10\n0 5\n1 7\n10 8\n5 3\n0 5\n3 3\n8 8\n0 6\n10 1\n9 0",
"output": "18"
},
{
"input": "3\n0 1\n1 1\n1 0",
"output": "1"
},
{
"input": "4\n0 1... | 1,691,687,268 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 2 | 124 | 0 | n = int(input())
c = 0
d= 0
for _ in range(n):
a, b = map(int, input().split())
d = c - a + b
c = max(c, d)
print(c) | Title: Tram
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Linear Kingdom has exactly one tram line. It has *n* stops, numbered from 1 to *n* in the order of tram's movement. At the *i*-th stop *a**i* passengers exit the tram, while *b**i* passengers enter it. The tram is empty before it ... | ```python
n = int(input())
c = 0
d= 0
for _ in range(n):
a, b = map(int, input().split())
d = c - a + b
c = max(c, d)
print(c)
``` | 0 | |
725 | A | Jumping Ball | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | In a new version of the famous Pinball game, one of the most important parts of the game field is a sequence of *n* bumpers. The bumpers are numbered with integers from 1 to *n* from left to right. There are two types of bumpers. They are denoted by the characters '<' and '>'. When the ball hits the bumper at pos... | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=200<=000) — the length of the sequence of bumpers. The second line contains the string, which consists of the characters '<' and '>'. The character at the *i*-th position of this string corresponds to the type of the *i*-th bumper. | Print one integer — the number of positions in the sequence such that the ball will eventually fall from the game field if it starts at that position. | [
"4\n<<><\n",
"5\n>>>>>\n",
"4\n>><<\n"
] | [
"2",
"5",
"0"
] | In the first sample, the ball will fall from the field if starts at position 1 or position 2.
In the second sample, any starting position will result in the ball falling from the field. | 500 | [
{
"input": "4\n<<><",
"output": "2"
},
{
"input": "5\n>>>>>",
"output": "5"
},
{
"input": "4\n>><<",
"output": "0"
},
{
"input": "3\n<<>",
"output": "3"
},
{
"input": "3\n<<<",
"output": "3"
},
{
"input": "3\n><<",
"output": "0"
},
{
"input... | 1,641,773,678 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 78 | 124 | 1,228,800 | print(int(input())-len(input().lstrip("<").rstrip(">"))) | Title: Jumping Ball
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In a new version of the famous Pinball game, one of the most important parts of the game field is a sequence of *n* bumpers. The bumpers are numbered with integers from 1 to *n* from left to right. There are two types of b... | ```python
print(int(input())-len(input().lstrip("<").rstrip(">")))
``` | 3 | |
935 | A | Fafa and his Company | PROGRAMMING | 800 | [
"brute force",
"implementation"
] | null | null | Fafa owns a company that works on huge projects. There are *n* employees in Fafa's company. Whenever the company has a new project to start working on, Fafa has to divide the tasks of this project among all the employees.
Fafa finds doing this every time is very tiring for him. So, he decided to choose the best *l* em... | The input consists of a single line containing a positive integer *n* (2<=≤<=*n*<=≤<=105) — the number of employees in Fafa's company. | Print a single integer representing the answer to the problem. | [
"2\n",
"10\n"
] | [
"1\n",
"3\n"
] | In the second sample Fafa has 3 ways:
- choose only 1 employee as a team leader with 9 employees under his responsibility. - choose 2 employees as team leaders with 4 employees under the responsibility of each of them. - choose 5 employees as team leaders with 1 employee under the responsibility of each of them. | 500 | [
{
"input": "2",
"output": "1"
},
{
"input": "10",
"output": "3"
},
{
"input": "3",
"output": "1"
},
{
"input": "4",
"output": "2"
},
{
"input": "6",
"output": "3"
},
{
"input": "13",
"output": "1"
},
{
"input": "100000",
"output": "35"
... | 1,652,754,419 | 2,147,483,647 | Python 3 | OK | TESTS | 33 | 46 | 4,300,800 | x=int(input())
a=0
for i in range(1,x):
if x%i==0:
a+=1
print(a) | Title: Fafa and his Company
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Fafa owns a company that works on huge projects. There are *n* employees in Fafa's company. Whenever the company has a new project to start working on, Fafa has to divide the tasks of this project among all the emp... | ```python
x=int(input())
a=0
for i in range(1,x):
if x%i==0:
a+=1
print(a)
``` | 3 | |
244 | A | Dividing Orange | PROGRAMMING | 900 | [
"implementation"
] | null | null | One day Ms Swan bought an orange in a shop. The orange consisted of *n*·*k* segments, numbered with integers from 1 to *n*·*k*.
There were *k* children waiting for Ms Swan at home. The children have recently learned about the orange and they decided to divide it between them. For that each child took a piece of paper... | The first line contains two integers *n*, *k* (1<=≤<=*n*,<=*k*<=≤<=30). The second line contains *k* space-separated integers *a*1,<=*a*2,<=...,<=*a**k* (1<=≤<=*a**i*<=≤<=*n*·*k*), where *a**i* is the number of the orange segment that the *i*-th child would like to get.
It is guaranteed that all numbers *a**i* are dis... | Print exactly *n*·*k* distinct integers. The first *n* integers represent the indexes of the segments the first child will get, the second *n* integers represent the indexes of the segments the second child will get, and so on. Separate the printed numbers with whitespaces.
You can print a child's segment indexes in a... | [
"2 2\n4 1\n",
"3 1\n2\n"
] | [
"2 4 \n1 3 \n",
"3 2 1 \n"
] | none | 500 | [
{
"input": "2 2\n4 1",
"output": "2 4 \n1 3 "
},
{
"input": "3 1\n2",
"output": "3 2 1 "
},
{
"input": "5 5\n25 24 23 22 21",
"output": "2 3 1 25 4 \n7 6 8 5 24 \n10 12 9 23 11 \n13 15 14 16 22 \n19 21 20 17 18 "
},
{
"input": "1 30\n8 22 13 25 10 30 12 27 6 4 7 2 20 16 26 14... | 1,565,503,726 | 1,126 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 186 | 0 | import sys
ioRead = sys.stdin.readline
ioWrite = lambda x: sys.stdout.write(f"{x}\n")
n,k = ioRead().split(" ")
l = [-1 for _ in range(n*k)]
ol = map(int,ioRead().split(" "))
for o in ol:
l[o - 1] = 1
i = 0
for c in range(k):
printable = [str(ol[c])]
for _ in range(n):
while l[i]... | Title: Dividing Orange
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day Ms Swan bought an orange in a shop. The orange consisted of *n*·*k* segments, numbered with integers from 1 to *n*·*k*.
There were *k* children waiting for Ms Swan at home. The children have recently learned a... | ```python
import sys
ioRead = sys.stdin.readline
ioWrite = lambda x: sys.stdout.write(f"{x}\n")
n,k = ioRead().split(" ")
l = [-1 for _ in range(n*k)]
ol = map(int,ioRead().split(" "))
for o in ol:
l[o - 1] = 1
i = 0
for c in range(k):
printable = [str(ol[c])]
for _ in range(n):
... | -1 | |
152 | B | Steps | PROGRAMMING | 1,300 | [
"binary search",
"implementation"
] | null | null | One day Vasya went out for a walk in the yard but there weren't any of his friends outside and he had no one to play touch and run. But the boy didn't lose the high spirits and decided to play touch and run with himself. You may ask: "How did he do that?" The answer is simple.
Vasya noticed that the yard is a rectangu... | The first input line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=109) — the yard's sizes. The second line contains integers *x**c* and *y**c* — the initial square's coordinates (1<=≤<=*x**c*<=≤<=*n*,<=1<=≤<=*y**c*<=≤<=*m*).
The third line contains an integer *k* (1<=≤<=*k*<=≤<=104) — the number of vectors. ... | Print the single number — the number of steps Vasya had made.
Please do not use the %lld specificator to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specificator. | [
"4 5\n1 1\n3\n1 1\n1 1\n0 -2\n",
"10 10\n1 2\n1\n-1 0\n"
] | [
"4\n",
"0\n"
] | In the first sample Vasya is initially positioned at square (1, 1) and makes 3 steps by the first vector (1, 1). So, he consecutively visits the squares (2, 2), (3, 3), (4, 4). Then he makes 0 steps by the second vector (1, 1). He makes 1 more step by the third vector (0, - 2) and he ends up in square (4, 2). Overall,... | 1,000 | [
{
"input": "4 5\n1 1\n3\n1 1\n1 1\n0 -2",
"output": "4"
},
{
"input": "10 10\n1 2\n1\n-1 0",
"output": "0"
},
{
"input": "10 20\n10 3\n10\n-2 -6\n-1 0\n-8 0\n0 5\n-1 3\n16 -16\n-1 9\n0 -18\n9 -1\n-9 5",
"output": "13"
},
{
"input": "20 10\n14 4\n10\n6 0\n-7 -7\n12 -2\n-4 9\n2... | 1,664,035,843 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 34 | 404 | 9,728,000 | n,m = list(map(int,input().split()))
xc,yc = list(map(int,input().split()))
k = int(input())
vect = []
for _ in range(k):
dx,dy = list(map(int,input().split()))
vect.append((dx,dy))
steps = 0
for dx,dy in vect:
x,y= xc + dx,yc + dy
# print(xc,yc,dx,dy,steps)
if 0 < x <= n and 0 <... | Title: Steps
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day Vasya went out for a walk in the yard but there weren't any of his friends outside and he had no one to play touch and run. But the boy didn't lose the high spirits and decided to play touch and run with himself. You may ... | ```python
n,m = list(map(int,input().split()))
xc,yc = list(map(int,input().split()))
k = int(input())
vect = []
for _ in range(k):
dx,dy = list(map(int,input().split()))
vect.append((dx,dy))
steps = 0
for dx,dy in vect:
x,y= xc + dx,yc + dy
# print(xc,yc,dx,dy,steps)
if 0 < x <=... | 3 | |
233 | A | Perfect Permutation | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | A permutation is a sequence of integers *p*1,<=*p*2,<=...,<=*p**n*, consisting of *n* distinct positive integers, each of them doesn't exceed *n*. Let's denote the *i*-th element of permutation *p* as *p**i*. We'll call number *n* the size of permutation *p*1,<=*p*2,<=...,<=*p**n*.
Nickolas adores permutations. He lik... | A single line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the permutation size. | If a perfect permutation of size *n* doesn't exist, print a single integer -1. Otherwise print *n* distinct integers from 1 to *n*, *p*1,<=*p*2,<=...,<=*p**n* — permutation *p*, that is perfect. Separate printed numbers by whitespaces. | [
"1\n",
"2\n",
"4\n"
] | [
"-1\n",
"2 1 \n",
"2 1 4 3 \n"
] | none | 500 | [
{
"input": "1",
"output": "-1"
},
{
"input": "2",
"output": "2 1 "
},
{
"input": "4",
"output": "2 1 4 3 "
},
{
"input": "3",
"output": "-1"
},
{
"input": "5",
"output": "-1"
},
{
"input": "6",
"output": "2 1 4 3 6 5 "
},
{
"input": "7",
... | 1,681,987,598 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 2 | 124 | 0 | x=int(input())
t=[int(i) for i in range(1,x+1)]
if x<=1:
print(-1)
else:
for i in range(0,len(t)-1):
temp=t[i]
t[i]=t[i+1]
t[i+1]=temp
print(*t) | Title: Perfect Permutation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A permutation is a sequence of integers *p*1,<=*p*2,<=...,<=*p**n*, consisting of *n* distinct positive integers, each of them doesn't exceed *n*. Let's denote the *i*-th element of permutation *p* as *p**i*. We'll ... | ```python
x=int(input())
t=[int(i) for i in range(1,x+1)]
if x<=1:
print(-1)
else:
for i in range(0,len(t)-1):
temp=t[i]
t[i]=t[i+1]
t[i+1]=temp
print(*t)
``` | 0 | |
778 | A | String Game | PROGRAMMING | 1,700 | [
"binary search",
"greedy",
"strings"
] | null | null | Little Nastya has a hobby, she likes to remove some letters from word, to obtain another word. But it turns out to be pretty hard for her, because she is too young. Therefore, her brother Sergey always helps her.
Sergey gives Nastya the word *t* and wants to get the word *p* out of it. Nastya removes letters in a cert... | The first and second lines of the input contain the words *t* and *p*, respectively. Words are composed of lowercase letters of the Latin alphabet (1<=≤<=|*p*|<=<<=|*t*|<=≤<=200<=000). It is guaranteed that the word *p* can be obtained by removing the letters from word *t*.
Next line contains a permutation *a*1,<=*... | Print a single integer number, the maximum number of letters that Nastya can remove. | [
"ababcba\nabb\n5 3 4 1 7 6 2\n",
"bbbabb\nbb\n1 6 3 4 2 5\n"
] | [
"3",
"4"
] | In the first sample test sequence of removing made by Nastya looks like this:
"ababcba" <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> "ababcba" <img align="middle" class="tex-formula" src="https... | 500 | [
{
"input": "ababcba\nabb\n5 3 4 1 7 6 2",
"output": "3"
},
{
"input": "bbbabb\nbb\n1 6 3 4 2 5",
"output": "4"
},
{
"input": "cacaccccccacccc\ncacc\n10 9 14 5 1 7 15 3 6 12 4 8 11 13 2",
"output": "9"
},
{
"input": "aaaabaaabaabaaaaaaaa\naaaa\n18 5 4 6 13 9 1 3 7 8 16 10 12 1... | 1,611,807,763 | 2,147,483,647 | PyPy 3 | OK | TESTS | 43 | 499 | 26,828,800 | # import inbuilt standard input output
import sys
from sys import stdin, stdout
# suppose a function called main() and
# all the operations are performed
# ////////// Get integer values in variables \\\\\\\\\\\\\\\\\\\\\\\
def get_ints_in_variables():
return map(int, sys.stdin.readline().strip().spli... | Title: String Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Nastya has a hobby, she likes to remove some letters from word, to obtain another word. But it turns out to be pretty hard for her, because she is too young. Therefore, her brother Sergey always helps her.
Sergey gi... | ```python
# import inbuilt standard input output
import sys
from sys import stdin, stdout
# suppose a function called main() and
# all the operations are performed
# ////////// Get integer values in variables \\\\\\\\\\\\\\\\\\\\\\\
def get_ints_in_variables():
return map(int, sys.stdin.readline().st... | 3 | |
71 | A | Way Too Long Words | PROGRAMMING | 800 | [
"strings"
] | A. Way Too Long Words | 1 | 256 | Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome.
Let's consider a word too long, if its length is strictly more than 10 characters. All too long words should be replaced with a special abbreviation.
This abbreviation is made lik... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=100). Each of the following *n* lines contains one word. All the words consist of lowercase Latin letters and possess the lengths of from 1 to 100 characters. | Print *n* lines. The *i*-th line should contain the result of replacing of the *i*-th word from the input data. | [
"4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis\n"
] | [
"word\nl10n\ni18n\np43s\n"
] | none | 500 | [
{
"input": "4\nword\nlocalization\ninternationalization\npneumonoultramicroscopicsilicovolcanoconiosis",
"output": "word\nl10n\ni18n\np43s"
},
{
"input": "5\nabcdefgh\nabcdefghi\nabcdefghij\nabcdefghijk\nabcdefghijklm",
"output": "abcdefgh\nabcdefghi\nabcdefghij\na9k\na11m"
},
{
"input":... | 1,693,904,499 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 31 | 0 | ############ ---- Input Functions ---- ############
def inp():
return(int(input()))
def inlt():
return(list(map(int,input().split())))
def insr():
s = input()
return(list(s[:len(s) - 1]))
def invr():
return(map(int,input().split()))
nbrWords = inp()
words = insr()
for i in ra... | Title: Way Too Long Words
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Sometimes some words like "localization" or "internationalization" are so long that writing them many times in one text is quite tiresome.
Let's consider a word too long, if its length is strictly more than 10 character... | ```python
############ ---- Input Functions ---- ############
def inp():
return(int(input()))
def inlt():
return(list(map(int,input().split())))
def insr():
s = input()
return(list(s[:len(s) - 1]))
def invr():
return(map(int,input().split()))
nbrWords = inp()
words = insr()
f... | -1 |
744 | C | Hongcow Buys a Deck of Cards | PROGRAMMING | 2,400 | [
"bitmasks",
"brute force",
"dp"
] | null | null | One day, Hongcow goes to the store and sees a brand new deck of *n* special cards. Each individual card is either red or blue. He decides he wants to buy them immediately. To do this, he needs to play a game with the owner of the store.
This game takes some number of turns to complete. On a turn, Hongcow may do one of... | The first line of input will contain a single integer *n* (1<=≤<=*n*<=≤<=16).
The next *n* lines of input will contain three tokens *c**i*, *r**i* and *b**i*. *c**i* will be 'R' or 'B', denoting the color of the card as red or blue. *r**i* will be an integer denoting the amount of red resources required to obtain the ... | Output a single integer, denoting the minimum number of turns needed to acquire all the cards. | [
"3\nR 0 1\nB 1 0\nR 1 1\n",
"3\nR 3 0\nR 2 0\nR 1 0\n"
] | [
"4\n",
"6\n"
] | For the first sample, Hongcow's four moves are as follows:
1. Collect tokens 1. Buy card 1 1. Buy card 2 1. Buy card 3
For the second sample, one optimal strategy is as follows:
1. Collect tokens 1. Collect tokens 1. Buy card 2 1. Collect tokens 1. Buy card 3 1. Buy card 1 | 1,750 | [
{
"input": "3\nR 0 1\nB 1 0\nR 1 1",
"output": "4"
},
{
"input": "3\nR 3 0\nR 2 0\nR 1 0",
"output": "6"
},
{
"input": "8\nB 0 1\nR 2 3\nB 2 1\nR 4 2\nB 1 3\nB 1 10\nB 3 4\nR 3 4",
"output": "17"
},
{
"input": "16\nR 10000000 10000000\nR 10000000 10000000\nR 10000000 10000000... | 1,481,997,464 | 4,963 | PyPy 3 | TIME_LIMIT_EXCEEDED | PRETESTS | 4 | 2,000 | 45,056,000 | from functools import *
from re import *
from sys import stderr
def readint():
return int(input())
def readfloat():
return float(input())
def readarray(N, foo=input):
return [foo() for i in range(N)]
def readlinearray(foo=int):
return map(foo, input().split())
def NOD(a, b):
while b:
a,b = ... | Title: Hongcow Buys a Deck of Cards
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day, Hongcow goes to the store and sees a brand new deck of *n* special cards. Each individual card is either red or blue. He decides he wants to buy them immediately. To do this, he needs to play a gam... | ```python
from functools import *
from re import *
from sys import stderr
def readint():
return int(input())
def readfloat():
return float(input())
def readarray(N, foo=input):
return [foo() for i in range(N)]
def readlinearray(foo=int):
return map(foo, input().split())
def NOD(a, b):
while b:
... | 0 | |
877 | A | Alex and broken contest | PROGRAMMING | 1,100 | [
"implementation",
"strings"
] | null | null | One day Alex was creating a contest about his friends, but accidentally deleted it. Fortunately, all the problems were saved, but now he needs to find them among other problems.
But there are too many problems, to do it manually. Alex asks you to write a program, which will determine if a problem is from this contest ... | The only line contains string from lowercase and uppercase letters and "_" symbols of length, not more than 100 — the name of the problem. | Print "YES", if problem is from this contest, and "NO" otherwise. | [
"Alex_and_broken_contest\n",
"NikitaAndString\n",
"Danil_and_Olya\n"
] | [
"NO",
"YES",
"NO"
] | none | 500 | [
{
"input": "Alex_and_broken_contest",
"output": "NO"
},
{
"input": "NikitaAndString",
"output": "YES"
},
{
"input": "Danil_and_Olya",
"output": "NO"
},
{
"input": "Slava____and_the_game",
"output": "YES"
},
{
"input": "Olya_and_energy_drinks",
"output": "YES"
... | 1,510,732,759 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 5 | 62 | 0 | x = input()
c = x.count('Danil')+x.count('Olya')+x.count('Slava')+x.count('Danil')+x.count('Nikita')
print('YES' if c == 1 else 'No') | Title: Alex and broken contest
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day Alex was creating a contest about his friends, but accidentally deleted it. Fortunately, all the problems were saved, but now he needs to find them among other problems.
But there are too many problems,... | ```python
x = input()
c = x.count('Danil')+x.count('Olya')+x.count('Slava')+x.count('Danil')+x.count('Nikita')
print('YES' if c == 1 else 'No')
``` | 0 | |
592 | C | The Big Race | PROGRAMMING | 1,800 | [
"math"
] | null | null | Vector Willman and Array Bolt are the two most famous athletes of Byteforces. They are going to compete in a race with a distance of *L* meters today.
Willman and Bolt have exactly the same speed, so when they compete the result is always a tie. That is a problem for the organizers because they want a winner.
While ... | The first line of the input contains three integers *t*, *w* and *b* (1<=≤<=*t*,<=*w*,<=*b*<=≤<=5·1018) — the maximum possible length of the racetrack, the length of Willman's steps and the length of Bolt's steps respectively. | Print the answer to the problem as an irreducible fraction . Follow the format of the samples output.
The fraction (*p* and *q* are integers, and both *p*<=≥<=0 and *q*<=><=0 holds) is called irreducible, if there is no such integer *d*<=><=1, that both *p* and *q* are divisible by *d*. | [
"10 3 2\n",
"7 1 2\n"
] | [
"3/10\n",
"3/7\n"
] | In the first sample Willman and Bolt will tie in case 1, 6 or 7 are chosen as the length of the racetrack. | 1,500 | [
{
"input": "10 3 2",
"output": "3/10"
},
{
"input": "7 1 2",
"output": "3/7"
},
{
"input": "1 1 1",
"output": "1/1"
},
{
"input": "5814 31 7",
"output": "94/2907"
},
{
"input": "94268 813 766",
"output": "765/94268"
},
{
"input": "262610 5583 4717",
... | 1,446,406,241 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 15 | 62 | 0 | def rez(p,q):
if p==0:
return '0/1'
p1,q1=min(p,q),max(p,q)
d=p1
while q1%p1>0:
d=q1%p1
q1,p1=p1,d
q1=q//d
p1=p//d
return str(p1)+'/'+str(q1)
s=input()
a=s.split(' ')
t,w,b=int(a[0]),int(a[1]),int(a[2])
m=min(w,b)-1
n=t//(w*b)
d=t%(w*b)
p=m+n+(n-1)*... | Title: The Big Race
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vector Willman and Array Bolt are the two most famous athletes of Byteforces. They are going to compete in a race with a distance of *L* meters today.
Willman and Bolt have exactly the same speed, so when they compete the... | ```python
def rez(p,q):
if p==0:
return '0/1'
p1,q1=min(p,q),max(p,q)
d=p1
while q1%p1>0:
d=q1%p1
q1,p1=p1,d
q1=q//d
p1=p//d
return str(p1)+'/'+str(q1)
s=input()
a=s.split(' ')
t,w,b=int(a[0]),int(a[1]),int(a[2])
m=min(w,b)-1
n=t//(w*b)
d=t%(w*b)
p=... | 0 | |
478 | B | Random Teams | PROGRAMMING | 1,300 | [
"combinatorics",
"constructive algorithms",
"greedy",
"math"
] | null | null | *n* participants of the competition were split into *m* teams in some manner so that each team has at least one participant. After the competition each pair of participants from the same team became friends.
Your task is to write a program that will find the minimum and the maximum number of pairs of friends that coul... | The only line of input contains two integers *n* and *m*, separated by a single space (1<=≤<=*m*<=≤<=*n*<=≤<=109) — the number of participants and the number of teams respectively. | The only line of the output should contain two integers *k**min* and *k**max* — the minimum possible number of pairs of friends and the maximum possible number of pairs of friends respectively. | [
"5 1\n",
"3 2\n",
"6 3\n"
] | [
"10 10\n",
"1 1\n",
"3 6\n"
] | In the first sample all the participants get into one team, so there will be exactly ten pairs of friends.
In the second sample at any possible arrangement one team will always have two participants and the other team will always have one participant. Thus, the number of pairs of friends will always be equal to one.
... | 1,000 | [
{
"input": "5 1",
"output": "10 10"
},
{
"input": "3 2",
"output": "1 1"
},
{
"input": "6 3",
"output": "3 6"
},
{
"input": "5 3",
"output": "2 3"
},
{
"input": "10 2",
"output": "20 36"
},
{
"input": "10 6",
"output": "4 10"
},
{
"input": ... | 1,690,862,178 | 2,147,483,647 | Python 3 | OK | TESTS | 26 | 46 | 0 | def cal(a):
if a < 2:
return 0
return a * (a - 1) // 2
def Solve():
n, m = map(int, input().split())
tmp = n - m + 1
mx = cal(tmp)
mn = 0
tmp1 = n // m
tmp2 = n % m
mn += tmp2 * cal(tmp1 + 1) + (m - tmp2) * cal(tmp1)
print(mn, mx)
if __name__ == "__main... | Title: Random Teams
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
*n* participants of the competition were split into *m* teams in some manner so that each team has at least one participant. After the competition each pair of participants from the same team became friends.
Your task is ... | ```python
def cal(a):
if a < 2:
return 0
return a * (a - 1) // 2
def Solve():
n, m = map(int, input().split())
tmp = n - m + 1
mx = cal(tmp)
mn = 0
tmp1 = n // m
tmp2 = n % m
mn += tmp2 * cal(tmp1 + 1) + (m - tmp2) * cal(tmp1)
print(mn, mx)
if __name__ ... | 3 | |
864 | C | Bus | PROGRAMMING | 1,500 | [
"greedy",
"implementation",
"math"
] | null | null | A bus moves along the coordinate line *Ox* from the point *x*<==<=0 to the point *x*<==<=*a*. After starting from the point *x*<==<=0, it reaches the point *x*<==<=*a*, immediately turns back and then moves to the point *x*<==<=0. After returning to the point *x*<==<=0 it immediately goes back to the point *x*<==<=*a* ... | The first line contains four integers *a*, *b*, *f*, *k* (0<=<<=*f*<=<<=*a*<=≤<=106, 1<=≤<=*b*<=≤<=109, 1<=≤<=*k*<=≤<=104) — the endpoint of the first bus journey, the capacity of the fuel tank of the bus, the point where the gas station is located, and the required number of journeys. | Print the minimum number of times the bus needs to refuel to make *k* journeys. If it is impossible for the bus to make *k* journeys, print -1. | [
"6 9 2 4\n",
"6 10 2 4\n",
"6 5 4 3\n"
] | [
"4\n",
"2\n",
"-1\n"
] | In the first example the bus needs to refuel during each journey.
In the second example the bus can pass 10 units of distance without refueling. So the bus makes the whole first journey, passes 4 units of the distance of the second journey and arrives at the point with the gas station. Then it can refuel its tank, fin... | 1,500 | [
{
"input": "6 9 2 4",
"output": "4"
},
{
"input": "6 10 2 4",
"output": "2"
},
{
"input": "6 5 4 3",
"output": "-1"
},
{
"input": "2 2 1 1",
"output": "0"
},
{
"input": "10 4 6 10",
"output": "-1"
},
{
"input": "3 1 1 1",
"output": "-1"
},
{
... | 1,591,269,901 | 2,147,483,647 | PyPy 3 | OK | TESTS | 48 | 140 | 1,433,600 | a, bm, f, k = [int(i) for i in input().split()]
b = bm
r1, r2 = f, a - f
count = 0
for i in range(k):
b -= r1
if b < 0:
print(-1)
exit(0)
if b < 2 * r2 and i != k - 1:
b = bm
count += 1
elif i == k - 1:
if b < r2:
b = bm
coun... | Title: Bus
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A bus moves along the coordinate line *Ox* from the point *x*<==<=0 to the point *x*<==<=*a*. After starting from the point *x*<==<=0, it reaches the point *x*<==<=*a*, immediately turns back and then moves to the point *x*<==<=0. ... | ```python
a, bm, f, k = [int(i) for i in input().split()]
b = bm
r1, r2 = f, a - f
count = 0
for i in range(k):
b -= r1
if b < 0:
print(-1)
exit(0)
if b < 2 * r2 and i != k - 1:
b = bm
count += 1
elif i == k - 1:
if b < r2:
b = bm
... | 3 | |
174 | A | Problem About Equation | PROGRAMMING | 1,100 | [
"math"
] | null | null | A group of *n* merry programmers celebrate Robert Floyd's birthday. Polucarpus has got an honourable task of pouring Ber-Cola to everybody. Pouring the same amount of Ber-Cola to everybody is really important. In other words, the drink's volume in each of the *n* mugs must be the same.
Polycarpus has already began the... | The first line contains a pair of integers *n*, *b* (2<=≤<=*n*<=≤<=100,<=1<=≤<=*b*<=≤<=100), where *n* is the total number of friends in the group and *b* is the current volume of drink in the bottle. The second line contains a sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=100), where *a**i* is the ... | Print a single number "-1" (without the quotes), if there is no solution. Otherwise, print *n* float numbers *c*1,<=*c*2,<=...,<=*c**n*, where *c**i* is the volume of the drink to add in the *i*-th mug. Print the numbers with no less than 6 digits after the decimal point, print each *c**i* on a single line. Polycarpus ... | [
"5 50\n1 2 3 4 5\n",
"2 2\n1 100\n"
] | [
"12.000000\n11.000000\n10.000000\n9.000000\n8.000000\n",
"-1\n"
] | none | 500 | [
{
"input": "5 50\n1 2 3 4 5",
"output": "12.000000\n11.000000\n10.000000\n9.000000\n8.000000"
},
{
"input": "2 2\n1 100",
"output": "-1"
},
{
"input": "2 2\n1 1",
"output": "1.000000\n1.000000"
},
{
"input": "3 2\n1 2 1",
"output": "1.000000\n0.000000\n1.000000"
},
{
... | 1,428,236,596 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | Python 3.4.0b1 (v3.4.0b1:3405dc9a6afa, Nov 24 2013, 19:09:12) [MSC v.1600 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> ================================ RESTART ================================
>>>
2
Traceback (most recent call last):
File "D:/Python34/cfcodes/1.... | Title: Problem About Equation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A group of *n* merry programmers celebrate Robert Floyd's birthday. Polucarpus has got an honourable task of pouring Ber-Cola to everybody. Pouring the same amount of Ber-Cola to everybody is really important. In... | ```python
Python 3.4.0b1 (v3.4.0b1:3405dc9a6afa, Nov 24 2013, 19:09:12) [MSC v.1600 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> ================================ RESTART ================================
>>>
2
Traceback (most recent call last):
File "D:/Python34/... | -1 | |
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,463,855 | 2,147,483,647 | Python 3 | OK | TESTS | 46 | 77 | 307,200 | s = input().split()
n = int(s[0])
m = int(s[1])
k = int(s[2])
if k % 2 == 0:
k = int(k / 2)
a = int(k / m)
b = k % m
if b != 0:
print(a+1, b, 'R')
else:
print(a, m, 'R')
else:
k = int((k +1) / 2)
a = int(k / m)
b = k % m
if b != 0:
print(a+1, ... | 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
s = input().split()
n = int(s[0])
m = int(s[1])
k = int(s[2])
if k % 2 == 0:
k = int(k / 2)
a = int(k / m)
b = k % m
if b != 0:
print(a+1, b, 'R')
else:
print(a, m, 'R')
else:
k = int((k +1) / 2)
a = int(k / m)
b = k % m
if b != 0:
p... | 3 | |
710 | A | King Moves | PROGRAMMING | 800 | [
"implementation"
] | null | null | The only king stands on the standard chess board. You are given his position in format "cd", where *c* is the column from 'a' to 'h' and *d* is the row from '1' to '8'. Find the number of moves permitted for the king.
Check the king's moves here [https://en.wikipedia.org/wiki/King_(chess)](https://en.wikipedia.org/wik... | The only line contains the king's position in the format "cd", where 'c' is the column from 'a' to 'h' and 'd' is the row from '1' to '8'. | Print the only integer *x* — the number of moves permitted for the king. | [
"e4\n"
] | [
"8\n"
] | none | 0 | [
{
"input": "e4",
"output": "8"
},
{
"input": "a1",
"output": "3"
},
{
"input": "h8",
"output": "3"
},
{
"input": "a4",
"output": "5"
},
{
"input": "g7",
"output": "8"
},
{
"input": "e1",
"output": "5"
},
{
"input": "b2",
"output": "8"
... | 1,567,157,673 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 124 | 0 |
# -*- coding: utf-8 -*-
# @Date : 2019-08-30 14:56:18
# @Author : raj lath ([email protected])
# @Link : link
# @Version : 1.0.0
import sys
sys.setrecursionlimit(10**5+1)
inf = int(10 ** 20)
max_val = inf
min_val = -inf
RW = lambda : sys.stdin.readline().strip()
RI = lambda : int(RW())... | Title: King Moves
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The only king stands on the standard chess board. You are given his position in format "cd", where *c* is the column from 'a' to 'h' and *d* is the row from '1' to '8'. Find the number of moves permitted for the king.
Check... | ```python
# -*- coding: utf-8 -*-
# @Date : 2019-08-30 14:56:18
# @Author : raj lath ([email protected])
# @Link : link
# @Version : 1.0.0
import sys
sys.setrecursionlimit(10**5+1)
inf = int(10 ** 20)
max_val = inf
min_val = -inf
RW = lambda : sys.stdin.readline().strip()
RI = lambda :... | 0 | |
842 | B | Gleb And Pizza | PROGRAMMING | 1,100 | [
"geometry"
] | null | null | Gleb ordered pizza home. When the courier delivered the pizza, he was very upset, because several pieces of sausage lay on the crust, and he does not really like the crust.
The pizza is a circle of radius *r* and center at the origin. Pizza consists of the main part — circle of radius *r*<=-<=*d* with center at the or... | First string contains two integer numbers *r* and *d* (0<=≤<=*d*<=<<=*r*<=≤<=500) — the radius of pizza and the width of crust.
Next line contains one integer number *n* — the number of pieces of sausage (1<=≤<=*n*<=≤<=105).
Each of next *n* lines contains three integer numbers *x**i*, *y**i* and *r**i* (<=-<=500<... | Output the number of pieces of sausage that lay on the crust. | [
"8 4\n7\n7 8 1\n-7 3 2\n0 2 1\n0 -2 2\n-3 -3 1\n0 6 2\n5 3 1\n",
"10 8\n4\n0 0 9\n0 0 10\n1 0 1\n1 0 2\n"
] | [
"2\n",
"0\n"
] | Below is a picture explaining the first example. Circles of green color denote pieces of sausage lying on the crust. | 1,000 | [
{
"input": "8 4\n7\n7 8 1\n-7 3 2\n0 2 1\n0 -2 2\n-3 -3 1\n0 6 2\n5 3 1",
"output": "2"
},
{
"input": "10 8\n4\n0 0 9\n0 0 10\n1 0 1\n1 0 2",
"output": "0"
},
{
"input": "1 0\n1\n1 1 0",
"output": "0"
},
{
"input": "3 0\n5\n3 0 0\n0 3 0\n-3 0 0\n0 -3 0\n3 0 1",
"output": ... | 1,504,022,754 | 3,654 | Python 3 | WRONG_ANSWER | PRETESTS | 4 | 61 | 0 | import math
r,d=input().split()
r=int(r)
d=int(d)
n=int(input())
count=0
for i in range(0,n):
x,y,rs=input().split()
x=int(x)
y=int(y)
rs=int(rs)
ds=math.sqrt(x**2+y**2)
if((ds-rs)>=d and (ds+rs)<=r):
count+=1
print(count)
| Title: Gleb And Pizza
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Gleb ordered pizza home. When the courier delivered the pizza, he was very upset, because several pieces of sausage lay on the crust, and he does not really like the crust.
The pizza is a circle of radius *r* and center... | ```python
import math
r,d=input().split()
r=int(r)
d=int(d)
n=int(input())
count=0
for i in range(0,n):
x,y,rs=input().split()
x=int(x)
y=int(y)
rs=int(rs)
ds=math.sqrt(x**2+y**2)
if((ds-rs)>=d and (ds+rs)<=r):
count+=1
print(count)
``` | 0 | |
405 | A | Gravity Flip | PROGRAMMING | 900 | [
"greedy",
"implementation",
"sortings"
] | null | null | Little Chris is bored during his physics lessons (too easy), so he has built a toy box to keep himself occupied. The box is special, since it has the ability to change gravity.
There are *n* columns of toy cubes in the box arranged in a line. The *i*-th column contains *a**i* cubes. At first, the gravity in the box is... | The first line of input contains an integer *n* (1<=≤<=*n*<=≤<=100), the number of the columns in the box. The next line contains *n* space-separated integer numbers. The *i*-th number *a**i* (1<=≤<=*a**i*<=≤<=100) denotes the number of cubes in the *i*-th column. | Output *n* integer numbers separated by spaces, where the *i*-th number is the amount of cubes in the *i*-th column after the gravity switch. | [
"4\n3 2 1 2\n",
"3\n2 3 8\n"
] | [
"1 2 2 3 \n",
"2 3 8 \n"
] | The first example case is shown on the figure. The top cube of the first column falls to the top of the last column; the top cube of the second column falls to the top of the third column; the middle cube of the first column falls to the top of the second column.
In the second example case the gravity switch does not ... | 500 | [
{
"input": "4\n3 2 1 2",
"output": "1 2 2 3 "
},
{
"input": "3\n2 3 8",
"output": "2 3 8 "
},
{
"input": "5\n2 1 2 1 2",
"output": "1 1 2 2 2 "
},
{
"input": "1\n1",
"output": "1 "
},
{
"input": "2\n4 3",
"output": "3 4 "
},
{
"input": "6\n100 40 60 20... | 1,697,402,173 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 15 | 0 | a = int(input("a"))
mas=[]
for i in range(a):
mas.append(int(input()))
mas.sort()
for i in range(a):
print(mas[i]) | Title: Gravity Flip
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Chris is bored during his physics lessons (too easy), so he has built a toy box to keep himself occupied. The box is special, since it has the ability to change gravity.
There are *n* columns of toy cubes in the bo... | ```python
a = int(input("a"))
mas=[]
for i in range(a):
mas.append(int(input()))
mas.sort()
for i in range(a):
print(mas[i])
``` | -1 | |
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,691,381,901 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 46 | 0 | n = int(input())
list_of_lists = []
for _ in range(n):
list_of_lists.append(list(input().split()))
for i in range(len(list_of_lists)):
list_of_lists[i].sort()
for j in range(len(list_of_lists) - 1):
a = list_of_lists[j]
b = list_of_lists[j + 1]
for k in range(len(a)):
x = b.count(a... | 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())
list_of_lists = []
for _ in range(n):
list_of_lists.append(list(input().split()))
for i in range(len(list_of_lists)):
list_of_lists[i].sort()
for j in range(len(list_of_lists) - 1):
a = list_of_lists[j]
b = list_of_lists[j + 1]
for k in range(len(a)):
x =... | -1 | |
727 | C | Guess the Array | PROGRAMMING | 1,400 | [
"constructive algorithms",
"interactive",
"math"
] | null | null | This is an interactive problem. You should use flush operation after each printed line. For example, in C++ you should use fflush(stdout), in Java you should use System.out.flush(), and in Pascal — flush(output).
In this problem you should guess an array *a* which is unknown for you. The only information you have init... | none | none | [
"5\n \n9\n \n7\n \n9\n \n11\n \n6\n "
] | [
"? 1 5\n \n? 2 3\n \n? 4 1\n \n? 5 2\n \n? 3 4\n \n! 4 6 1 5 5"
] | The format of a test to make a hack is:
- The first line contains an integer number *n* (3 ≤ *n* ≤ 5000) — the length of the array.- The second line contains *n* numbers *a*<sub class="lower-index">1</sub>, *a*<sub class="lower-index">2</sub>, ..., *a*<sub class="lower-index">*n*</sub> (1 ≤ *a*<sub class="lower-inde... | 1,500 | [
{
"input": "5\n4 6 1 5 5",
"output": "5 out of 5"
},
{
"input": "3\n1 1 1",
"output": "3 out of 3"
},
{
"input": "4\n100 1 100 1",
"output": "4 out of 4"
},
{
"input": "10\n9 5 10 7 4 4 8 5 10 5",
"output": "10 out of 10"
},
{
"input": "3\n1 1 1",
"output": "3... | 1,690,497,624 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 30 | 0 | print("_RANDOM_GUESS_1690497624.6871467")# 1690497624.6871698 | Title: Guess the Array
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
This is an interactive problem. You should use flush operation after each printed line. For example, in C++ you should use fflush(stdout), in Java you should use System.out.flush(), and in Pascal — flush(output).
In th... | ```python
print("_RANDOM_GUESS_1690497624.6871467")# 1690497624.6871698
``` | 0 | |
1,010 | C | Border | PROGRAMMING | 1,800 | [
"number theory"
] | null | null | Astronaut Natasha arrived on Mars. She knows that the Martians are very poor aliens. To ensure a better life for the Mars citizens, their emperor decided to take tax from every tourist who visited the planet. Natasha is the inhabitant of Earth, therefore she had to pay the tax to enter the territory of Mars.
There are... | The first line contains two integers $n$ and $k$ ($1 \le n \le 100\,000$, $2 \le k \le 100\,000$) — the number of denominations of banknotes and the base of the number system on Mars.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^9$) — denominations of banknotes on Mars.
All numbers... | On the first line output the number of values $d$ for which Natasha can make the Martians happy.
In the second line, output all these values in increasing order.
Print all numbers in decimal notation. | [
"2 8\n12 20\n",
"3 10\n10 20 30\n"
] | [
"2\n0 4 ",
"1\n0 "
] | Consider the first test case. It uses the octal number system.
If you take one banknote with the value of $12$, you will get $14_8$ in octal system. The last digit is $4_8$.
If you take one banknote with the value of $12$ and one banknote with the value of $20$, the total value will be $32$. In the octal system, it i... | 1,000 | [
{
"input": "2 8\n12 20",
"output": "2\n0 4 "
},
{
"input": "3 10\n10 20 30",
"output": "1\n0 "
},
{
"input": "5 10\n20 16 4 16 2",
"output": "5\n0 2 4 6 8 "
},
{
"input": "10 5\n4 6 8 6 4 10 2 10 8 6",
"output": "5\n0 1 2 3 4 "
},
{
"input": "20 25\n15 10 5 20 10 ... | 1,532,660,912 | 2,147,483,647 | PyPy 3 | OK | TESTS | 107 | 358 | 12,595,200 | from math import gcd
n,k=map(int,input().split())
g=0
l=list(map(int,input().split()))
for e in l:
g=gcd(g,gcd(e,k))
print(k//g)
for i in range(0,k,g): print(i,end=' ') | Title: Border
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Astronaut Natasha arrived on Mars. She knows that the Martians are very poor aliens. To ensure a better life for the Mars citizens, their emperor decided to take tax from every tourist who visited the planet. Natasha is the inha... | ```python
from math import gcd
n,k=map(int,input().split())
g=0
l=list(map(int,input().split()))
for e in l:
g=gcd(g,gcd(e,k))
print(k//g)
for i in range(0,k,g): print(i,end=' ')
``` | 3 | |
810 | A | Straight <<A>> | PROGRAMMING | 900 | [
"implementation",
"math"
] | null | null | Noora is a student of one famous high school. It's her final year in school — she is going to study in university next year. However, she has to get an «A» graduation certificate in order to apply to a prestigious one.
In school, where Noora is studying, teachers are putting down marks to the online class register, wh... | The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=100,<=1<=≤<=*k*<=≤<=100) denoting the number of marks, received by Noora and the value of highest possible mark.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*k*) denoting marks received by Noora before Leha's hack. | Print a single integer — minimal number of additional marks, that Leha has to add in order to change Noora's final mark to *k*. | [
"2 10\n8 9\n",
"3 5\n4 4 4\n"
] | [
"4",
"3"
] | Consider the first example testcase.
Maximal mark is 10, Noora received two marks — 8 and 9, so current final mark is 9. To fix it, Leha can add marks [10, 10, 10, 10] (4 marks in total) to the registry, achieving Noora having average mark equal to <img align="middle" class="tex-formula" src="https://espresso.codeforc... | 500 | [
{
"input": "2 10\n8 9",
"output": "4"
},
{
"input": "3 5\n4 4 4",
"output": "3"
},
{
"input": "3 10\n10 8 9",
"output": "3"
},
{
"input": "2 23\n21 23",
"output": "2"
},
{
"input": "5 10\n5 10 10 9 10",
"output": "7"
},
{
"input": "12 50\n18 10 26 22 2... | 1,597,255,322 | 2,147,483,647 | PyPy 3 | OK | TESTS | 106 | 156 | 1,331,200 | a,b=map(int,input().split())
r=list(map(int,input().split()))
s=sum(r)
#(s+b*k)/(a+k)>=a-1/2
k=0
while (s+b*k)*2<(2*b-1)*(a+k):
k+=1
print(k) | Title: Straight <<A>>
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Noora is a student of one famous high school. It's her final year in school — she is going to study in university next year. However, she has to get an «A» graduation certificate in order to apply to a prestigious one.
... | ```python
a,b=map(int,input().split())
r=list(map(int,input().split()))
s=sum(r)
#(s+b*k)/(a+k)>=a-1/2
k=0
while (s+b*k)*2<(2*b-1)*(a+k):
k+=1
print(k)
``` | 3 | |
378 | A | Playing with Dice | PROGRAMMING | 800 | [
"brute force"
] | null | null | Two players are playing a game. First each of them writes an integer from 1 to 6, and then a dice is thrown. The player whose written number got closer to the number on the dice wins. If both payers have the same difference, it's a draw.
The first player wrote number *a*, the second player wrote number *b*. How many w... | The single line contains two integers *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=6) — the numbers written on the paper by the first and second player, correspondingly. | Print three integers: the number of ways to throw the dice at which the first player wins, the game ends with a draw or the second player wins, correspondingly. | [
"2 5\n",
"2 4\n"
] | [
"3 0 3\n",
"2 1 3\n"
] | The dice is a standard cube-shaped six-sided object with each side containing a number from 1 to 6, and where all numbers on all sides are distinct.
You can assume that number *a* is closer to number *x* than number *b*, if |*a* - *x*| < |*b* - *x*|. | 500 | [
{
"input": "2 5",
"output": "3 0 3"
},
{
"input": "2 4",
"output": "2 1 3"
},
{
"input": "5 3",
"output": "2 1 3"
},
{
"input": "1 6",
"output": "3 0 3"
},
{
"input": "5 1",
"output": "3 1 2"
},
{
"input": "6 3",
"output": "2 0 4"
},
{
"inp... | 1,568,320,430 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 77 | 0 | (a,b) = (int(s) for s in input().split())
first_win = 0
second_win = 0
draw = 0
for i in range(1,7):
if abs(a-i) < abs(b-i): first_win +=1
elif abs(a-i) > abs(b-i): second_win +=1
else: draw +=1
print(first_win, second_win, draw)
| Title: Playing with Dice
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Two players are playing a game. First each of them writes an integer from 1 to 6, and then a dice is thrown. The player whose written number got closer to the number on the dice wins. If both payers have the same diff... | ```python
(a,b) = (int(s) for s in input().split())
first_win = 0
second_win = 0
draw = 0
for i in range(1,7):
if abs(a-i) < abs(b-i): first_win +=1
elif abs(a-i) > abs(b-i): second_win +=1
else: draw +=1
print(first_win, second_win, draw)
``` | 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,664,006,163 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 35 | 124 | 0 | M, N = map(int, input().split())
if M % 2 == 0 or N % 2 == 0:
a = (M * N) // 2
else:
a = (M * N -1) // 2
print(a)
| 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())
if M % 2 == 0 or N % 2 == 0:
a = (M * N) // 2
else:
a = (M * N -1) // 2
print(a)
``` | 3.969 |
631 | B | Print Check | PROGRAMMING | 1,200 | [
"constructive algorithms",
"implementation"
] | null | null | Kris works in a large company "Blake Technologies". As a best engineer of the company he was assigned a task to develop a printer that will be able to print horizontal and vertical strips. First prototype is already built and Kris wants to tests it. He wants you to implement the program that checks the result of the pr... | The first line of the input contains three integers *n*, *m* and *k* (1<=<=≤<=<=*n*,<=<=*m*<=<=≤<=5000, *n*·*m*<=≤<=100<=000, 1<=≤<=*k*<=≤<=100<=000) — the dimensions of the sheet and the number of operations, respectively.
Each of the next *k* lines contains the description of exactly one query:
- 1 *r**i* *a**i* ... | Print *n* lines containing *m* integers each — the resulting table after all operations are applied. | [
"3 3 3\n1 1 3\n2 2 1\n1 2 2\n",
"5 3 5\n1 1 1\n1 3 1\n1 5 1\n2 1 1\n2 3 1\n"
] | [
"3 1 3 \n2 2 2 \n0 1 0 \n",
"1 1 1 \n1 0 1 \n1 1 1 \n1 0 1 \n1 1 1 \n"
] | The figure below shows all three operations for the first sample step by step. The cells that were painted on the corresponding step are marked gray. | 1,000 | [
{
"input": "3 3 3\n1 1 3\n2 2 1\n1 2 2",
"output": "3 1 3 \n2 2 2 \n0 1 0 "
},
{
"input": "5 3 5\n1 1 1\n1 3 1\n1 5 1\n2 1 1\n2 3 1",
"output": "1 1 1 \n1 0 1 \n1 1 1 \n1 0 1 \n1 1 1 "
},
{
"input": "5 5 4\n1 2 1\n1 4 1\n2 2 1\n2 4 1",
"output": "0 1 0 1 0 \n1 1 1 1 1 \n0 1 0 1 0 \n1... | 1,481,949,159 | 2,147,483,647 | Python 3 | OK | TESTS | 56 | 779 | 1,843,200 | from collections import defaultdict, deque, Counter, OrderedDict
import threading,sys
def main():
n,m,k = map(int, input().split())
nl = [(-1,0) for i in range(n)]
ml = [(-1,0) for i in range(m)]
for i in range(k):
a,b,c = map(int,input().split())
if a == 1:
nl... | Title: Print Check
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Kris works in a large company "Blake Technologies". As a best engineer of the company he was assigned a task to develop a printer that will be able to print horizontal and vertical strips. First prototype is already built a... | ```python
from collections import defaultdict, deque, Counter, OrderedDict
import threading,sys
def main():
n,m,k = map(int, input().split())
nl = [(-1,0) for i in range(n)]
ml = [(-1,0) for i in range(m)]
for i in range(k):
a,b,c = map(int,input().split())
if a == 1:
... | 3 | |
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,771,204 | 2,147,483,647 | Python 3 | OK | TESTS | 41 | 93 | 0 | s, k = list(input()), int(input())
if k>26 or k>len(s): print('impossible')
else:
if k - len(set(s)) < 0: print(0)
else: print(k-len(set(s))) | 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
s, k = list(input()), int(input())
if k>26 or k>len(s): print('impossible')
else:
if k - len(set(s)) < 0: print(0)
else: print(k-len(set(s)))
``` | 3 | |
381 | A | Sereja and Dima | PROGRAMMING | 800 | [
"greedy",
"implementation",
"two pointers"
] | null | null | Sereja and Dima play a game. The rules of the game are very simple. The players have *n* cards in a row. Each card contains a number, all numbers on the cards are distinct. The players take turns, Sereja moves first. During his turn a player can take one card: either the leftmost card in a row, or the rightmost one. Th... | The first line contains integer *n* (1<=≤<=*n*<=≤<=1000) — the number of cards on the table. The second line contains space-separated numbers on the cards from left to right. The numbers on the cards are distinct integers from 1 to 1000. | On a single line, print two integers. The first number is the number of Sereja's points at the end of the game, the second number is the number of Dima's points at the end of the game. | [
"4\n4 1 2 10\n",
"7\n1 2 3 4 5 6 7\n"
] | [
"12 5\n",
"16 12\n"
] | In the first sample Sereja will take cards with numbers 10 and 2, so Sereja's sum is 12. Dima will take cards with numbers 4 and 1, so Dima's sum is 5. | 500 | [
{
"input": "4\n4 1 2 10",
"output": "12 5"
},
{
"input": "7\n1 2 3 4 5 6 7",
"output": "16 12"
},
{
"input": "42\n15 29 37 22 16 5 26 31 6 32 19 3 45 36 33 14 25 20 48 7 42 11 24 28 9 18 8 21 47 17 38 40 44 4 35 1 43 39 41 27 12 13",
"output": "613 418"
},
{
"input": "43\n32 ... | 1,686,018,553 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 46 | 0 | n = int(input())
l_n = list(map(int, input().split()))
se = 0
di = 0
l = 0
r = n - 1
p = True
while l <= r:
if p:
if l_n[l] > l_n[r]:
se += l_n[l]
l += 1
else:
se += l_n[r]
r -= 1
else:
if l_n[l] > l_n[r]:
di += l_n[l]
... | Title: Sereja and Dima
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Sereja and Dima play a game. The rules of the game are very simple. The players have *n* cards in a row. Each card contains a number, all numbers on the cards are distinct. The players take turns, Sereja moves first. Du... | ```python
n = int(input())
l_n = list(map(int, input().split()))
se = 0
di = 0
l = 0
r = n - 1
p = True
while l <= r:
if p:
if l_n[l] > l_n[r]:
se += l_n[l]
l += 1
else:
se += l_n[r]
r -= 1
else:
if l_n[l] > l_n[r]:
di += l_n[l... | 3 | |
732 | A | Buy a Shovel | PROGRAMMING | 800 | [
"brute force",
"constructive algorithms",
"implementation",
"math"
] | null | null | Polycarp urgently needs a shovel! He comes to the shop and chooses an appropriate one. The shovel that Policarp chooses is sold for *k* burles. Assume that there is an unlimited number of such shovels in the shop.
In his pocket Polycarp has an unlimited number of "10-burle coins" and exactly one coin of *r* burles (1<... | The single line of input contains two integers *k* and *r* (1<=≤<=*k*<=≤<=1000, 1<=≤<=*r*<=≤<=9) — the price of one shovel and the denomination of the coin in Polycarp's pocket that is different from "10-burle coins".
Remember that he has an unlimited number of coins in the denomination of 10, that is, Polycarp has e... | Print the required minimum number of shovels Polycarp has to buy so that he can pay for them without any change. | [
"117 3\n",
"237 7\n",
"15 2\n"
] | [
"9\n",
"1\n",
"2\n"
] | In the first example Polycarp can buy 9 shovels and pay 9·117 = 1053 burles. Indeed, he can pay this sum by using 10-burle coins and one 3-burle coin. He can't buy fewer shovels without any change.
In the second example it is enough for Polycarp to buy one shovel.
In the third example Polycarp should buy two shovels ... | 500 | [
{
"input": "117 3",
"output": "9"
},
{
"input": "237 7",
"output": "1"
},
{
"input": "15 2",
"output": "2"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "1 9",
"output": "9"
},
{
"input": "1000 3",
"output": "1"
},
{
"input": "1000 1",
... | 1,680,783,134 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 2 | 46 | 0 | a,b=map(int,input().split())
ans=0
for i in range(1,10):
if((a-b*i)%10==0):
ans=i
print(ans)
| Title: Buy a Shovel
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp urgently needs a shovel! He comes to the shop and chooses an appropriate one. The shovel that Policarp chooses is sold for *k* burles. Assume that there is an unlimited number of such shovels in the shop.
In his ... | ```python
a,b=map(int,input().split())
ans=0
for i in range(1,10):
if((a-b*i)%10==0):
ans=i
print(ans)
``` | 0 | |
31 | A | Worms Evolution | PROGRAMMING | 1,200 | [
"implementation"
] | A. Worms Evolution | 2 | 256 | Professor Vasechkin is studying evolution of worms. Recently he put forward hypotheses that all worms evolve by division. There are *n* forms of worms. Worms of these forms have lengths *a*1, *a*2, ..., *a**n*. To prove his theory, professor needs to find 3 different forms that the length of the first form is equal to ... | The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of worm's forms. The second line contains *n* space-separated integers *a**i* (1<=≤<=*a**i*<=≤<=1000) — lengths of worms of each form. | Output 3 distinct integers *i* *j* *k* (1<=≤<=*i*,<=*j*,<=*k*<=≤<=*n*) — such indexes of worm's forms that *a**i*<==<=*a**j*<=+<=*a**k*. If there is no such triple, output -1. If there are several solutions, output any of them. It possible that *a**j*<==<=*a**k*. | [
"5\n1 2 3 5 7\n",
"5\n1 8 1 5 1\n"
] | [
"3 2 1\n",
"-1\n"
] | none | 500 | [
{
"input": "5\n1 2 3 5 7",
"output": "3 2 1"
},
{
"input": "5\n1 8 1 5 1",
"output": "-1"
},
{
"input": "4\n303 872 764 401",
"output": "-1"
},
{
"input": "6\n86 402 133 524 405 610",
"output": "6 4 1"
},
{
"input": "8\n217 779 418 895 996 473 3 22",
"output":... | 1,666,860,807 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 62 | 0 | #31A
flag=0
n=int(input())
s=list(map(int,input().split()))
s=sorted(s)
if n%2==1:
n=n+1
if s[len(s)-1]>(s[len(s)-2]+s[len(s)-3]):
print("-1")
else:
for i in range(len(s)-1,int(n/2)-2,-1):
for j in range(i-1,-1,-1):
for k in range(j-1,-1,-1):
if (s[i])==(s[j]+s[k]):
p... | Title: Worms Evolution
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Professor Vasechkin is studying evolution of worms. Recently he put forward hypotheses that all worms evolve by division. There are *n* forms of worms. Worms of these forms have lengths *a*1, *a*2, ..., *a**n*. To prove his... | ```python
#31A
flag=0
n=int(input())
s=list(map(int,input().split()))
s=sorted(s)
if n%2==1:
n=n+1
if s[len(s)-1]>(s[len(s)-2]+s[len(s)-3]):
print("-1")
else:
for i in range(len(s)-1,int(n/2)-2,-1):
for j in range(i-1,-1,-1):
for k in range(j-1,-1,-1):
if (s[i])==(s[j]+s[k]):
... | 0 |
459 | A | Pashmak and Garden | PROGRAMMING | 1,200 | [
"implementation"
] | null | null | Pashmak has fallen in love with an attractive girl called Parmida since one year ago...
Today, Pashmak set up a meeting with his partner in a romantic garden. Unfortunately, Pashmak has forgotten where the garden is. But he remembers that the garden looks like a square with sides parallel to the coordinate axes. He al... | The first line contains four space-separated *x*1,<=*y*1,<=*x*2,<=*y*2 (<=-<=100<=≤<=*x*1,<=*y*1,<=*x*2,<=*y*2<=≤<=100) integers, where *x*1 and *y*1 are coordinates of the first tree and *x*2 and *y*2 are coordinates of the second tree. It's guaranteed that the given points are distinct. | If there is no solution to the problem, print -1. Otherwise print four space-separated integers *x*3,<=*y*3,<=*x*4,<=*y*4 that correspond to the coordinates of the two other trees. If there are several solutions you can output any of them.
Note that *x*3,<=*y*3,<=*x*4,<=*y*4 must be in the range (<=-<=1000<=≤<=*x*3,<... | [
"0 0 0 1\n",
"0 0 1 1\n",
"0 0 1 2\n"
] | [
"1 0 1 1\n",
"0 1 1 0\n",
"-1\n"
] | none | 500 | [
{
"input": "0 0 0 1",
"output": "1 0 1 1"
},
{
"input": "0 0 1 1",
"output": "0 1 1 0"
},
{
"input": "0 0 1 2",
"output": "-1"
},
{
"input": "-100 -100 100 100",
"output": "-100 100 100 -100"
},
{
"input": "-100 -100 99 100",
"output": "-1"
},
{
"input... | 1,670,681,114 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 30 | 0 | x1, y1, x2, y2 = map(int, input().split())
d1 = abs(x1 - x2)
d2 = abs(y1 - y2)
x3 = x1 + d1
y3 = y1 + d2
x4 = x2 + d1
y4 = y2 + d2
if -100 <= x3 <= 100 and -100 <= y3 <= 100 and -100 <= x4 <= 100 and -100 <= y4 <= 100:
print(x3, y3, x4, y4)
else:
print(-1)
| Title: Pashmak and Garden
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Pashmak has fallen in love with an attractive girl called Parmida since one year ago...
Today, Pashmak set up a meeting with his partner in a romantic garden. Unfortunately, Pashmak has forgotten where the garden is... | ```python
x1, y1, x2, y2 = map(int, input().split())
d1 = abs(x1 - x2)
d2 = abs(y1 - y2)
x3 = x1 + d1
y3 = y1 + d2
x4 = x2 + d1
y4 = y2 + d2
if -100 <= x3 <= 100 and -100 <= y3 <= 100 and -100 <= x4 <= 100 and -100 <= y4 <= 100:
print(x3, y3, x4, y4)
else:
print(-1)
``` | 0 | |
849 | A | Odds and Ends | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Where do odds begin, and where do they end? Where does hope emerge, and will they ever break?
Given an integer sequence *a*1,<=*a*2,<=...,<=*a**n* of length *n*. Decide whether it is possible to divide it into an odd number of non-empty subsegments, the each of which has an odd length and begins and ends with odd numb... | The first line of input contains a non-negative integer *n* (1<=≤<=*n*<=≤<=100) — the length of the sequence.
The second line contains *n* space-separated non-negative integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=100) — the elements of the sequence. | Output "Yes" if it's possible to fulfill the requirements, and "No" otherwise.
You can output each letter in any case (upper or lower). | [
"3\n1 3 5\n",
"5\n1 0 1 5 1\n",
"3\n4 3 1\n",
"4\n3 9 9 3\n"
] | [
"Yes\n",
"Yes\n",
"No\n",
"No\n"
] | In the first example, divide the sequence into 1 subsegment: {1, 3, 5} and the requirements will be met.
In the second example, divide the sequence into 3 subsegments: {1, 0, 1}, {5}, {1}.
In the third example, one of the subsegments must start with 4 which is an even number, thus the requirements cannot be met.
In ... | 500 | [
{
"input": "3\n1 3 5",
"output": "Yes"
},
{
"input": "5\n1 0 1 5 1",
"output": "Yes"
},
{
"input": "3\n4 3 1",
"output": "No"
},
{
"input": "4\n3 9 9 3",
"output": "No"
},
{
"input": "1\n1",
"output": "Yes"
},
{
"input": "5\n100 99 100 99 99",
"out... | 1,504,275,367 | 2,467 | Python 3 | WRONG_ANSWER | TESTS | 12 | 61 | 0 | n=int(input())
a=list(map(int,input().split()))
if a[0]%2==0 or a[-1]%2==0:
print('No')
else:
a=[i for i in range(n) if a[i]%2==1]
n=len(a)
a=[a[i+1]-a[i] for i in range(n-1)]
l=0
n=len(a)
for i in range(n):
if a[i]%2==0:
l+=1
elif i>0 and a[i]%2==1 a... | Title: Odds and Ends
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Where do odds begin, and where do they end? Where does hope emerge, and will they ever break?
Given an integer sequence *a*1,<=*a*2,<=...,<=*a**n* of length *n*. Decide whether it is possible to divide it into an odd num... | ```python
n=int(input())
a=list(map(int,input().split()))
if a[0]%2==0 or a[-1]%2==0:
print('No')
else:
a=[i for i in range(n) if a[i]%2==1]
n=len(a)
a=[a[i+1]-a[i] for i in range(n-1)]
l=0
n=len(a)
for i in range(n):
if a[i]%2==0:
l+=1
elif i>0 and a... | 0 | |
41 | A | Translation | PROGRAMMING | 800 | [
"implementation",
"strings"
] | A. Translation | 2 | 256 | The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pronounced) reversely. For example, a Berlandish word code corresponds to a Birlandish word edoc.... | The first line contains word *s*, the second line contains word *t*. The words consist of lowercase Latin letters. The input data do not consist unnecessary spaces. The words are not empty and their lengths do not exceed 100 symbols. | If the word *t* is a word *s*, written reversely, print YES, otherwise print NO. | [
"code\nedoc\n",
"abb\naba\n",
"code\ncode\n"
] | [
"YES\n",
"NO\n",
"NO\n"
] | none | 500 | [
{
"input": "code\nedoc",
"output": "YES"
},
{
"input": "abb\naba",
"output": "NO"
},
{
"input": "code\ncode",
"output": "NO"
},
{
"input": "abacaba\nabacaba",
"output": "YES"
},
{
"input": "q\nq",
"output": "YES"
},
{
"input": "asrgdfngfnmfgnhweratgjkk... | 1,639,859,442 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 92 | 0 | a = input()
b = input()
if a == b[::-1]:
print("YES")
else:
print("NO")
# Sat Dec 18 2021 20:30:41 GMT+0000 (Coordinated Universal Time)
| Title: Translation
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pron... | ```python
a = input()
b = input()
if a == b[::-1]:
print("YES")
else:
print("NO")
# Sat Dec 18 2021 20:30:41 GMT+0000 (Coordinated Universal Time)
``` | 3.977 |
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,630,508,896 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 77 | 6,963,200 | n, b, d = input().split()
n = int(n)
b = int(b)
d = int(d)
a = list(map(int, input().strip().split()))
sum = 0
cnt = 0
for i in a:
sum += i
for i in a:
if i <= b and sum >= d:
cnt += 1
if cnt != 0:
cnt -= (n - 1)
print(cnt)
else:
print(cnt) | Title: Juicer
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Kolya is going to make fresh orange juice. He has *n* oranges of sizes *a*1,<=*a*2,<=...,<=*a**n*. Kolya will put them in the juicer in the fixed order, starting with orange of size *a*1, then orange of size *a*2 and so on. To b... | ```python
n, b, d = input().split()
n = int(n)
b = int(b)
d = int(d)
a = list(map(int, input().strip().split()))
sum = 0
cnt = 0
for i in a:
sum += i
for i in a:
if i <= b and sum >= d:
cnt += 1
if cnt != 0:
cnt -= (n - 1)
print(cnt)
else:
print(cnt)
``` | 0 | |
911 | B | Two Cakes | PROGRAMMING | 1,200 | [
"binary search",
"brute force",
"implementation"
] | null | null | It's New Year's Eve soon, so Ivan decided it's high time he started setting the table. Ivan has bought two cakes and cut them into pieces: the first cake has been cut into *a* pieces, and the second one — into *b* pieces.
Ivan knows that there will be *n* people at the celebration (including himself), so Ivan has set ... | The first line contains three integers *n*, *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=100, 2<=≤<=*n*<=≤<=*a*<=+<=*b*) — the number of plates, the number of pieces of the first cake, and the number of pieces of the second cake, respectively. | Print the maximum possible number *x* such that Ivan can distribute the cake in such a way that each plate will contain at least *x* pieces of cake. | [
"5 2 3\n",
"4 7 10\n"
] | [
"1\n",
"3\n"
] | In the first example there is only one way to distribute cakes to plates, all of them will have 1 cake on it.
In the second example you can have two plates with 3 and 4 pieces of the first cake and two plates both with 5 pieces of the second cake. Minimal number of pieces is 3. | 0 | [
{
"input": "5 2 3",
"output": "1"
},
{
"input": "4 7 10",
"output": "3"
},
{
"input": "100 100 100",
"output": "2"
},
{
"input": "10 100 3",
"output": "3"
},
{
"input": "2 9 29",
"output": "9"
},
{
"input": "4 6 10",
"output": "3"
},
{
"inp... | 1,514,633,304 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 3 | 93 | 23,040,000 | n,a,b = [int(i) for i in input().split()]
for i in range(100, 0, -1):
pa = a // i
pb = n - pa
if pa != 0:
if b // i >= pb:
print(i)
exit(0)
| Title: Two Cakes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
It's New Year's Eve soon, so Ivan decided it's high time he started setting the table. Ivan has bought two cakes and cut them into pieces: the first cake has been cut into *a* pieces, and the second one — into *b* pieces.
Iv... | ```python
n,a,b = [int(i) for i in input().split()]
for i in range(100, 0, -1):
pa = a // i
pb = n - pa
if pa != 0:
if b // i >= pb:
print(i)
exit(0)
``` | 0 | |
265 | A | Colorful Stones (Simplified Edition) | PROGRAMMING | 800 | [
"implementation"
] | null | null | There is a sequence of colorful stones. The color of each stone is one of red, green, or blue. You are given a string *s*. The *i*-th (1-based) character of *s* represents the color of the *i*-th stone. If the character is "R", "G", or "B", the color of the corresponding stone is red, green, or blue, respectively.
Ini... | The input contains two lines. The first line contains the string *s* (1<=≤<=|*s*|<=≤<=50). The second line contains the string *t* (1<=≤<=|*t*|<=≤<=50). The characters of each string will be one of "R", "G", or "B". It is guaranteed that Liss don't move out of the sequence. | Print the final 1-based position of Liss in a single line. | [
"RGB\nRRR\n",
"RRRBGBRBBB\nBBBRR\n",
"BRRBGBRGRBGRGRRGGBGBGBRGBRGRGGGRBRRRBRBBBGRRRGGBBB\nBBRBGGRGRGBBBRBGRBRBBBBRBRRRBGBBGBBRRBBGGRBRRBRGRB\n"
] | [
"2\n",
"3\n",
"15\n"
] | none | 500 | [
{
"input": "RGB\nRRR",
"output": "2"
},
{
"input": "RRRBGBRBBB\nBBBRR",
"output": "3"
},
{
"input": "BRRBGBRGRBGRGRRGGBGBGBRGBRGRGGGRBRRRBRBBBGRRRGGBBB\nBBRBGGRGRGBBBRBGRBRBBBBRBRRRBGBBGBBRRBBGGRBRRBRGRB",
"output": "15"
},
{
"input": "G\nRRBBRBRRBR",
"output": "1"
},
... | 1,692,442,276 | 2,147,483,647 | Python 3 | OK | TESTS | 19 | 122 | 0 | stones =input().strip()
orders =input().strip()
p1 = 0
p2 = 0
output= 1
while p1 < len(stones) and p2 <len(orders):
if stones[p1] == orders[p2]:
output+=1
p1+=1
p2+=1
else:
p2+=1
print(output) | Title: Colorful Stones (Simplified Edition)
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There is a sequence of colorful stones. The color of each stone is one of red, green, or blue. You are given a string *s*. The *i*-th (1-based) character of *s* represents the color of the *i*-th st... | ```python
stones =input().strip()
orders =input().strip()
p1 = 0
p2 = 0
output= 1
while p1 < len(stones) and p2 <len(orders):
if stones[p1] == orders[p2]:
output+=1
p1+=1
p2+=1
else:
p2+=1
print(output)
``` | 3 | |
620 | A | Professor GukiZ's Robot | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | Professor GukiZ makes a new robot. The robot are in the point with coordinates (*x*1,<=*y*1) and should go to the point (*x*2,<=*y*2). In a single step the robot can change any of its coordinates (maybe both of them) by one (decrease or increase). So the robot can move in one of the 8 directions. Find the minimal numbe... | The first line contains two integers *x*1,<=*y*1 (<=-<=109<=≤<=*x*1,<=*y*1<=≤<=109) — the start position of the robot.
The second line contains two integers *x*2,<=*y*2 (<=-<=109<=≤<=*x*2,<=*y*2<=≤<=109) — the finish position of the robot. | Print the only integer *d* — the minimal number of steps to get the finish position. | [
"0 0\n4 5\n",
"3 4\n6 1\n"
] | [
"5\n",
"3\n"
] | In the first example robot should increase both of its coordinates by one four times, so it will be in position (4, 4). After that robot should simply increase its *y* coordinate and get the finish position.
In the second example robot should simultaneously increase *x* coordinate and decrease *y* coordinate by one th... | 0 | [
{
"input": "0 0\n4 5",
"output": "5"
},
{
"input": "3 4\n6 1",
"output": "3"
},
{
"input": "0 0\n4 6",
"output": "6"
},
{
"input": "1 1\n-3 -5",
"output": "6"
},
{
"input": "-1 -1\n-10 100",
"output": "101"
},
{
"input": "1 -1\n100 -100",
"output":... | 1,616,137,071 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 46 | 0 | a,b=map(int,input().split(' '))
x,y=map(int,input().split(' '))
print(max(x,y)-min(a,b)) | Title: Professor GukiZ's Robot
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Professor GukiZ makes a new robot. The robot are in the point with coordinates (*x*1,<=*y*1) and should go to the point (*x*2,<=*y*2). In a single step the robot can change any of its coordinates (maybe both of ... | ```python
a,b=map(int,input().split(' '))
x,y=map(int,input().split(' '))
print(max(x,y)-min(a,b))
``` | 0 | |
490 | A | Team Olympiad | PROGRAMMING | 800 | [
"greedy",
"implementation",
"sortings"
] | null | null | The School №0 of the capital of Berland has *n* children studying in it. All the children in this school are gifted: some of them are good at programming, some are good at maths, others are good at PE (Physical Education). Hence, for each child we know value *t**i*:
- *t**i*<==<=1, if the *i*-th child is good at prog... | The first line contains integer *n* (1<=≤<=*n*<=≤<=5000) — the number of children in the school. The second line contains *n* integers *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t**i*<=≤<=3), where *t**i* describes the skill of the *i*-th child. | In the first line output integer *w* — the largest possible number of teams.
Then print *w* lines, containing three numbers in each line. Each triple represents the indexes of the children forming the team. You can print both the teams, and the numbers in the triplets in any order. The children are numbered from 1 to... | [
"7\n1 3 1 3 2 1 2\n",
"4\n2 1 1 2\n"
] | [
"2\n3 5 2\n6 7 4\n",
"0\n"
] | none | 500 | [
{
"input": "7\n1 3 1 3 2 1 2",
"output": "2\n3 5 2\n6 7 4"
},
{
"input": "4\n2 1 1 2",
"output": "0"
},
{
"input": "1\n2",
"output": "0"
},
{
"input": "2\n3 1",
"output": "0"
},
{
"input": "3\n2 1 2",
"output": "0"
},
{
"input": "3\n1 2 3",
"output... | 1,698,475,435 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 31 | 0 | n = int(input())
a = list(map(int, input().split()))
b = [i for i in range(len(a)) if a[i]==1]
c = [i for i in range(len(a)) if a[i]==2]
d = [i for i in range(len(a)) if a[i]==3]
k = min(len(b),len(c),len(d))
print(k)
for i in range(k):
print(b[i], c[i], d[i]) | Title: Team Olympiad
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The School №0 of the capital of Berland has *n* children studying in it. All the children in this school are gifted: some of them are good at programming, some are good at maths, others are good at PE (Physical Education)... | ```python
n = int(input())
a = list(map(int, input().split()))
b = [i for i in range(len(a)) if a[i]==1]
c = [i for i in range(len(a)) if a[i]==2]
d = [i for i in range(len(a)) if a[i]==3]
k = min(len(b),len(c),len(d))
print(k)
for i in range(k):
print(b[i], c[i], d[i])
``` | 0 | |
456 | A | Laptops | PROGRAMMING | 1,100 | [
"sortings"
] | null | null | One day Dima and Alex had an argument about the price and quality of laptops. Dima thinks that the more expensive a laptop is, the better it is. Alex disagrees. Alex thinks that there are two laptops, such that the price of the first laptop is less (strictly smaller) than the price of the second laptop but the quality ... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=105) — the number of laptops.
Next *n* lines contain two integers each, *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*), where *a**i* is the price of the *i*-th laptop, and *b**i* is the number that represents the quality of the *i*-th laptop (the larger the numb... | If Alex is correct, print "Happy Alex", otherwise print "Poor Alex" (without the quotes). | [
"2\n1 2\n2 1\n"
] | [
"Happy Alex\n"
] | none | 500 | [
{
"input": "2\n1 2\n2 1",
"output": "Happy Alex"
},
{
"input": "2\n1 1\n2 2",
"output": "Poor Alex"
},
{
"input": "3\n2 2\n3 3\n1 1",
"output": "Poor Alex"
},
{
"input": "3\n3 3\n1 2\n2 1",
"output": "Happy Alex"
},
{
"input": "1\n1 1",
"output": "Poor Alex"
... | 1,688,850,175 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 15 | 0 | T = int(input())
ans = []
for i in range(T):
price, quality = list(map(int, input().split()))
ans.append([price, quality])
ans.sort()
max_quality = float("inf")
result = "Poor Alex"
for i in range(len(ans)):
if max_quality > ans[i][1]:
result = "Happy Alex"
else:
m... | Title: Laptops
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day Dima and Alex had an argument about the price and quality of laptops. Dima thinks that the more expensive a laptop is, the better it is. Alex disagrees. Alex thinks that there are two laptops, such that the price of the... | ```python
T = int(input())
ans = []
for i in range(T):
price, quality = list(map(int, input().split()))
ans.append([price, quality])
ans.sort()
max_quality = float("inf")
result = "Poor Alex"
for i in range(len(ans)):
if max_quality > ans[i][1]:
result = "Happy Alex"
else:
... | 0 | |
466 | C | Number of Ways | PROGRAMMING | 1,700 | [
"binary search",
"brute force",
"data structures",
"dp",
"two pointers"
] | null | null | You've got array *a*[1],<=*a*[2],<=...,<=*a*[*n*], consisting of *n* integers. Count the number of ways to split all the elements of the array into three contiguous parts so that the sum of elements in each part is the same.
More formally, you need to find the number of such pairs of indices *i*,<=*j* (2<=≤<=*i*<=≤<=... | The first line contains integer *n* (1<=≤<=*n*<=≤<=5·105), showing how many numbers are in the array. The second line contains *n* integers *a*[1], *a*[2], ..., *a*[*n*] (|*a*[*i*]|<=≤<=<=109) — the elements of array *a*. | Print a single integer — the number of ways to split the array into three parts with the same sum. | [
"5\n1 2 3 0 3\n",
"4\n0 1 -1 0\n",
"2\n4 1\n"
] | [
"2\n",
"1\n",
"0\n"
] | none | 1,500 | [
{
"input": "5\n1 2 3 0 3",
"output": "2"
},
{
"input": "4\n0 1 -1 0",
"output": "1"
},
{
"input": "2\n4 1",
"output": "0"
},
{
"input": "9\n0 0 0 0 0 0 0 0 0",
"output": "28"
},
{
"input": "10\n2 5 -2 2 -3 -2 3 5 -5 -2",
"output": "0"
},
{
"input": "1\... | 1,699,345,698 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 31 | 0 | n = int(input())
arr = [int(x) for x in input().split()]
tot = sum(arr)
if tot % 3 != 0:
print(0)
else:
s = tot // 3
cnt1, cnt2, subsum = 0, 0, 0
for i in range(n):
subsum += arr[i]
if subsum == 2 * s : cnt2 += cnt1
if subsum == s: cnt1 += 1
print(cnt2) | Title: Number of Ways
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You've got array *a*[1],<=*a*[2],<=...,<=*a*[*n*], consisting of *n* integers. Count the number of ways to split all the elements of the array into three contiguous parts so that the sum of elements in each part is the s... | ```python
n = int(input())
arr = [int(x) for x in input().split()]
tot = sum(arr)
if tot % 3 != 0:
print(0)
else:
s = tot // 3
cnt1, cnt2, subsum = 0, 0, 0
for i in range(n):
subsum += arr[i]
if subsum == 2 * s : cnt2 += cnt1
if subsum == s: cnt1 += 1
print(cnt... | 0 | |
690 | A1 | Collective Mindsets (easy) | PROGRAMMING | 1,100 | [] | null | null | Tonight is brain dinner night and all zombies will gather together to scarf down some delicious brains. The artful Heidi plans to crash the party, incognito, disguised as one of them. Her objective is to get away with at least one brain, so she can analyze the zombies' mindset back home and gain a strategic advantage.
... | The only line of input contains one integer: *N*, the number of attendees (1<=≤<=*N*<=≤<=109). | Output one integer: the smallest number of brains in the chest which allows Heidi to take one brain home. | [
"1\n",
"4\n"
] | [
"1\n",
"2\n"
] | 0 | [
{
"input": "1",
"output": "1"
},
{
"input": "4",
"output": "2"
},
{
"input": "2",
"output": "1"
},
{
"input": "3",
"output": "2"
},
{
"input": "5",
"output": "3"
},
{
"input": "6",
"output": "3"
},
{
"input": "7",
"output": "4"
},
{... | 1,468,137,888 | 288 | Python 3 | OK | TESTS | 30 | 62 | 0 | a = int(input())
print((a + a%2) //2) | Title: Collective Mindsets (easy)
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Tonight is brain dinner night and all zombies will gather together to scarf down some delicious brains. The artful Heidi plans to crash the party, incognito, disguised as one of them. Her objective is to get ... | ```python
a = int(input())
print((a + a%2) //2)
``` | 3 | ||
251 | A | Points on Line | PROGRAMMING | 1,300 | [
"binary search",
"combinatorics",
"two pointers"
] | null | null | Little Petya likes points a lot. Recently his mom has presented him *n* points lying on the line *OX*. Now Petya is wondering in how many ways he can choose three distinct points so that the distance between the two farthest of them doesn't exceed *d*.
Note that the order of the points inside the group of three chosen... | The first line contains two integers: *n* and *d* (1<=≤<=*n*<=≤<=105; 1<=≤<=*d*<=≤<=109). The next line contains *n* integers *x*1,<=*x*2,<=...,<=*x**n*, their absolute value doesn't exceed 109 — the *x*-coordinates of the points that Petya has got.
It is guaranteed that the coordinates of the points in the input stri... | Print a single integer — the number of groups of three points, where the distance between two farthest points doesn't exceed *d*.
Please do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier. | [
"4 3\n1 2 3 4\n",
"4 2\n-3 -2 -1 0\n",
"5 19\n1 10 20 30 50\n"
] | [
"4\n",
"2\n",
"1\n"
] | In the first sample any group of three points meets our conditions.
In the seconds sample only 2 groups of three points meet our conditions: {-3, -2, -1} and {-2, -1, 0}.
In the third sample only one group does: {1, 10, 20}. | 500 | [
{
"input": "4 3\n1 2 3 4",
"output": "4"
},
{
"input": "4 2\n-3 -2 -1 0",
"output": "2"
},
{
"input": "5 19\n1 10 20 30 50",
"output": "1"
},
{
"input": "10 5\n31 36 43 47 48 50 56 69 71 86",
"output": "2"
},
{
"input": "10 50\n1 4 20 27 65 79 82 83 99 100",
"... | 1,601,038,707 | 2,147,483,647 | Python 3 | OK | TESTS | 39 | 528 | 8,806,400 | from bisect import bisect_right
n,d = map(int,input().split())
a=list(map(int,input().split()))
res=0
for i in range(n-2):
j=bisect_right(a,a[i]+d)
k=j-i
res+=(k-1)*(k-2)//2
print(res)
| Title: Points on Line
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Petya likes points a lot. Recently his mom has presented him *n* points lying on the line *OX*. Now Petya is wondering in how many ways he can choose three distinct points so that the distance between the two fart... | ```python
from bisect import bisect_right
n,d = map(int,input().split())
a=list(map(int,input().split()))
res=0
for i in range(n-2):
j=bisect_right(a,a[i]+d)
k=j-i
res+=(k-1)*(k-2)//2
print(res)
``` | 3 | |
250 | A | Paper Work | PROGRAMMING | 1,000 | [
"greedy"
] | null | null | Polycarpus has been working in the analytic department of the "F.R.A.U.D." company for as much as *n* days. Right now his task is to make a series of reports about the company's performance for the last *n* days. We know that the main information in a day report is value *a**i*, the company's profit on the *i*-th day. ... | The first line contains integer *n* (1<=≤<=*n*<=≤<=100), *n* is the number of days. The second line contains a sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (|*a**i*|<=≤<=100), where *a**i* means the company profit on the *i*-th day. It is possible that the company has no days with the negative *a**i*. | Print an integer *k* — the required minimum number of folders. In the second line print a sequence of integers *b*1, *b*2, ..., *b**k*, where *b**j* is the number of day reports in the *j*-th folder.
If there are multiple ways to sort the reports into *k* days, print any of them. | [
"11\n1 2 3 -4 -5 -6 5 -5 -6 -7 6\n",
"5\n0 -1 100 -1 0\n"
] | [
"3\n5 3 3 ",
"1\n5 "
] | Here goes a way to sort the reports from the first sample into three folders:
In the second sample you can put all five reports in one folder. | 500 | [
{
"input": "11\n1 2 3 -4 -5 -6 5 -5 -6 -7 6",
"output": "3\n5 3 3 "
},
{
"input": "5\n0 -1 100 -1 0",
"output": "1\n5 "
},
{
"input": "1\n0",
"output": "1\n1 "
},
{
"input": "1\n-1",
"output": "1\n1 "
},
{
"input": "2\n0 0",
"output": "1\n2 "
},
{
"inp... | 1,589,468,496 | 2,147,483,647 | PyPy 3 | OK | TESTS | 69 | 280 | 20,172,800 | z = int(input())
l = list(map(int, input().rstrip().split(" ")))
count = 0
pac = 0
pac_list = []
i = 0
while i < z:
if l[i] < 0:
count = count + 1
pac = pac+1
if count ==3:
pac_list.append(pac-1)
pac = 0
i = i - 1
count = 0
i = i + 1
if pac > 0:
... | Title: Paper Work
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarpus has been working in the analytic department of the "F.R.A.U.D." company for as much as *n* days. Right now his task is to make a series of reports about the company's performance for the last *n* days. We know tha... | ```python
z = int(input())
l = list(map(int, input().rstrip().split(" ")))
count = 0
pac = 0
pac_list = []
i = 0
while i < z:
if l[i] < 0:
count = count + 1
pac = pac+1
if count ==3:
pac_list.append(pac-1)
pac = 0
i = i - 1
count = 0
i = i + 1
if p... | 3 | |
22 | A | Second Order Statistics | PROGRAMMING | 800 | [
"brute force"
] | A. Second Order Statistics | 2 | 256 | Once Bob needed to find the second order statistics of a sequence of integer numbers. Lets choose each number from the sequence exactly once and sort them. The value on the second position is the second order statistics of the given sequence. In other words it is the smallest element strictly greater than the minimum. ... | The first input line contains integer *n* (1<=≤<=*n*<=≤<=100) — amount of numbers in the sequence. The second line contains *n* space-separated integer numbers — elements of the sequence. These numbers don't exceed 100 in absolute value. | If the given sequence has the second order statistics, output this order statistics, otherwise output NO. | [
"4\n1 2 2 -4\n",
"5\n1 2 3 1 1\n"
] | [
"1\n",
"2\n"
] | none | 0 | [
{
"input": "4\n1 2 2 -4",
"output": "1"
},
{
"input": "5\n1 2 3 1 1",
"output": "2"
},
{
"input": "1\n28",
"output": "NO"
},
{
"input": "2\n-28 12",
"output": "12"
},
{
"input": "3\n-83 40 -80",
"output": "-80"
},
{
"input": "8\n93 77 -92 26 21 -48 53 ... | 1,627,522,543 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 92 | 6,758,400 | n = int(input())
x = [int(i) for i in input().split()]
m = min(x)
lol = 1
if n <= 2:
lol = 69420
print("No")
while lol == 1:
m = m+1
if x.count(m) >= 1:
lol = 3
print(m)
else:
continue
| Title: Second Order Statistics
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Once Bob needed to find the second order statistics of a sequence of integer numbers. Lets choose each number from the sequence exactly once and sort them. The value on the second position is the second order statis... | ```python
n = int(input())
x = [int(i) for i in input().split()]
m = min(x)
lol = 1
if n <= 2:
lol = 69420
print("No")
while lol == 1:
m = m+1
if x.count(m) >= 1:
lol = 3
print(m)
else:
continue
``` | 0 |
509 | A | Maximum in Table | PROGRAMMING | 800 | [
"brute force",
"implementation"
] | null | null | An *n*<=×<=*n* table *a* is defined as follows:
- The first row and the first column contain ones, that is: *a**i*,<=1<==<=*a*1,<=*i*<==<=1 for all *i*<==<=1,<=2,<=...,<=*n*. - Each of the remaining numbers in the table is equal to the sum of the number above it and the number to the left of it. In other words, the ... | The only line of input contains a positive integer *n* (1<=≤<=*n*<=≤<=10) — the number of rows and columns of the table. | Print a single line containing a positive integer *m* — the maximum value in the table. | [
"1\n",
"5\n"
] | [
"1",
"70"
] | In the second test the rows of the table look as follows: | 0 | [
{
"input": "1",
"output": "1"
},
{
"input": "5",
"output": "70"
},
{
"input": "2",
"output": "2"
},
{
"input": "3",
"output": "6"
},
{
"input": "4",
"output": "20"
},
{
"input": "6",
"output": "252"
},
{
"input": "7",
"output": "924"
... | 1,669,915,654 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 46 | 0 | print([0, 1, 5, 15, 35, 75, 140, 259, 435, 735, 1155, 1841, 2765, 4200, 6125, 8975, 12731, 18179, 25235, 35180, 48055, 65681, 88299, 118895, 157690][int(input())]) | Title: Maximum in Table
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
An *n*<=×<=*n* table *a* is defined as follows:
- The first row and the first column contain ones, that is: *a**i*,<=1<==<=*a*1,<=*i*<==<=1 for all *i*<==<=1,<=2,<=...,<=*n*. - Each of the remaining numbers in the t... | ```python
print([0, 1, 5, 15, 35, 75, 140, 259, 435, 735, 1155, 1841, 2765, 4200, 6125, 8975, 12731, 18179, 25235, 35180, 48055, 65681, 88299, 118895, 157690][int(input())])
``` | 0 | |
665 | C | Simple Strings | PROGRAMMING | 1,300 | [
"dp",
"greedy",
"strings"
] | null | null | zscoder loves simple strings! A string *t* is called simple if every pair of adjacent characters are distinct. For example ab, aba, zscoder are simple whereas aa, add are not simple.
zscoder is given a string *s*. He wants to change a minimum number of characters so that the string *s* becomes simple. Help him with th... | The only line contains the string *s* (1<=≤<=|*s*|<=≤<=2·105) — the string given to zscoder. The string *s* consists of only lowercase English letters. | Print the simple string *s*' — the string *s* after the minimal number of changes. If there are multiple solutions, you may output any of them.
Note that the string *s*' should also consist of only lowercase English letters. | [
"aab\n",
"caaab\n",
"zscoder\n"
] | [
"bab\n",
"cabab\n",
"zscoder\n"
] | none | 0 | [
{
"input": "aab",
"output": "bab"
},
{
"input": "caaab",
"output": "cabab"
},
{
"input": "zscoder",
"output": "zscoder"
},
{
"input": "u",
"output": "u"
},
{
"input": "h",
"output": "h"
},
{
"input": "dtottttotd",
"output": "dtotataotd"
},
{
... | 1,562,093,200 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 0 | 2,000 | 0 | a=input()
for x in range (len(a)):
if a[x]==a[x-1]:
if a[x]=='z':
a.replace(a[x],"a")
continue
a.replace(a[x],chr(ord(a[x])+1))
while((x+1)<=len(a) and a[x+1]==a[x]):
if a[x]=='z':
a.replace(a[x],"a")
continue
a.replace(a... | Title: Simple Strings
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
zscoder loves simple strings! A string *t* is called simple if every pair of adjacent characters are distinct. For example ab, aba, zscoder are simple whereas aa, add are not simple.
zscoder is given a string *s*. He wa... | ```python
a=input()
for x in range (len(a)):
if a[x]==a[x-1]:
if a[x]=='z':
a.replace(a[x],"a")
continue
a.replace(a[x],chr(ord(a[x])+1))
while((x+1)<=len(a) and a[x+1]==a[x]):
if a[x]=='z':
a.replace(a[x],"a")
continue
a... | 0 | |
698 | B | Fix a Tree | PROGRAMMING | 1,700 | [
"constructive algorithms",
"dfs and similar",
"dsu",
"graphs",
"trees"
] | null | null | A tree is an undirected connected graph without cycles.
Let's consider a rooted undirected tree with *n* vertices, numbered 1 through *n*. There are many ways to represent such a tree. One way is to create an array with *n* integers *p*1,<=*p*2,<=...,<=*p**n*, where *p**i* denotes a parent of vertex *i* (here, for con... | The first line of the input contains an integer *n* (2<=≤<=*n*<=≤<=200<=000) — the number of vertices in the tree.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*n*). | In the first line print the minimum number of elements to change, in order to get a valid sequence.
In the second line, print any valid sequence possible to get from (*a*1,<=*a*2,<=...,<=*a**n*) in the minimum number of changes. If there are many such sequences, any of them will be accepted. | [
"4\n2 3 3 4\n",
"5\n3 2 2 5 3\n",
"8\n2 3 5 4 1 6 6 7\n"
] | [
"1\n2 3 4 4 \n",
"0\n3 2 2 5 3 \n",
"2\n2 3 7 8 1 6 6 7\n"
] | In the first sample, it's enough to change one element. In the provided output, a sequence represents a tree rooted in a vertex 4 (because *p*<sub class="lower-index">4</sub> = 4), which you can see on the left drawing below. One of other correct solutions would be a sequence 2 3 3 2, representing a tree rooted in vert... | 1,000 | [
{
"input": "4\n2 3 3 4",
"output": "1\n2 3 4 4 "
},
{
"input": "5\n3 2 2 5 3",
"output": "0\n3 2 2 5 3 "
},
{
"input": "8\n2 3 5 4 1 6 6 7",
"output": "2\n2 3 7 8 1 6 6 7"
},
{
"input": "2\n1 2",
"output": "1\n2 2 "
},
{
"input": "7\n4 3 2 6 3 5 2",
"output": ... | 1,674,080,691 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 4 | 61 | 0 | n=int(input())
arr=[int(h) for h in input().split()]
visited=[0]*n
change=[]
root=[]
for i in range(1,n+1):
if arr[i-1]==i:
root.append(i)
j=i
if visited[i-1]==1:
continue
h=set()
while j not in h:
h.add(j)
visited[j-1]=1
j=arr[j-1]
if j i... | Title: Fix a Tree
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A tree is an undirected connected graph without cycles.
Let's consider a rooted undirected tree with *n* vertices, numbered 1 through *n*. There are many ways to represent such a tree. One way is to create an array with *n*... | ```python
n=int(input())
arr=[int(h) for h in input().split()]
visited=[0]*n
change=[]
root=[]
for i in range(1,n+1):
if arr[i-1]==i:
root.append(i)
j=i
if visited[i-1]==1:
continue
h=set()
while j not in h:
h.add(j)
visited[j-1]=1
j=arr[j-1]
... | 0 | |
908 | A | New Year and Counting Cards | PROGRAMMING | 800 | [
"brute force",
"implementation"
] | null | null | Your friend has *n* cards.
You know that each card has a lowercase English letter on one side and a digit on the other.
Currently, your friend has laid out the cards on a table so only one side of each card is visible.
You would like to know if the following statement is true for cards that your friend owns: "If a c... | The first and only line of input will contain a string *s* (1<=≤<=|*s*|<=≤<=50), denoting the sides of the cards that you can see on the table currently. Each character of *s* is either a lowercase English letter or a digit. | Print a single integer, the minimum number of cards you must turn over to verify your claim. | [
"ee\n",
"z\n",
"0ay1\n"
] | [
"2\n",
"0\n",
"2\n"
] | In the first sample, we must turn over both cards. Note that even though both cards have the same letter, they could possibly have different numbers on the other side.
In the second sample, we don't need to turn over any cards. The statement is vacuously true, since you know your friend has no cards with a vowel on th... | 500 | [
{
"input": "ee",
"output": "2"
},
{
"input": "z",
"output": "0"
},
{
"input": "0ay1",
"output": "2"
},
{
"input": "0abcdefghijklmnopqrstuvwxyz1234567896",
"output": "10"
},
{
"input": "0a0a9e9e2i2i9o9o6u6u9z9z4x4x9b9b",
"output": "18"
},
{
"input": "01... | 1,525,718,985 | 2,147,483,647 | Python 3 | OK | TESTS | 38 | 93 | 7,065,600 | g = ['a','e','i','o','u']
ch = ['1','3','5','7','9',]
ans = 0
s = input()
n = len(s)
for i in range(n):
if (s[i] in ch or s[i] in g):
ans+=1
print(ans)
| Title: New Year and Counting Cards
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Your friend has *n* cards.
You know that each card has a lowercase English letter on one side and a digit on the other.
Currently, your friend has laid out the cards on a table so only one side of each car... | ```python
g = ['a','e','i','o','u']
ch = ['1','3','5','7','9',]
ans = 0
s = input()
n = len(s)
for i in range(n):
if (s[i] in ch or s[i] in g):
ans+=1
print(ans)
``` | 3 | |
987 | B | High School: Become Human | PROGRAMMING | 1,100 | [
"math"
] | null | null | Year 2118. Androids are in mass production for decades now, and they do all the work for humans. But androids have to go to school to be able to solve creative tasks. Just like humans before.
It turns out that high school struggles are not gone. If someone is not like others, he is bullied. Vasya-8800 is an economy-cl... | On the only line of input there are two integers $x$ and $y$ ($1 \le x, y \le 10^{9}$). | If $x^y < y^x$, then print '<' (without quotes). If $x^y > y^x$, then print '>' (without quotes). If $x^y = y^x$, then print '=' (without quotes). | [
"5 8\n",
"10 3\n",
"6 6\n"
] | [
">\n",
"<\n",
"=\n"
] | In the first example $5^8 = 5 \cdot 5 \cdot 5 \cdot 5 \cdot 5 \cdot 5 \cdot 5 \cdot 5 = 390625$, and $8^5 = 8 \cdot 8 \cdot 8 \cdot 8 \cdot 8 = 32768$. So you should print '>'.
In the second example $10^3 = 1000 < 3^{10} = 59049$.
In the third example $6^6 = 46656 = 6^6$. | 1,000 | [
{
"input": "5 8",
"output": ">"
},
{
"input": "10 3",
"output": "<"
},
{
"input": "6 6",
"output": "="
},
{
"input": "14 1",
"output": ">"
},
{
"input": "2 4",
"output": "="
},
{
"input": "987654321 123456987",
"output": "<"
},
{
"input": "... | 1,623,777,709 | 2,147,483,647 | PyPy 3 | OK | TESTS | 48 | 93 | 0 | from math import log
x, y = map(int, input().strip().split(" "))
c, d = y*log(x), x*log(y)
# print(c, d)
if c < d:print("<")
elif c > d:print(">")
else:print("=")
| Title: High School: Become Human
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Year 2118. Androids are in mass production for decades now, and they do all the work for humans. But androids have to go to school to be able to solve creative tasks. Just like humans before.
It turns out tha... | ```python
from math import log
x, y = map(int, input().strip().split(" "))
c, d = y*log(x), x*log(y)
# print(c, d)
if c < d:print("<")
elif c > d:print(">")
else:print("=")
``` | 3 | |
758 | A | Holiday Of Equality | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | In Berland it is the holiday of equality. In honor of the holiday the king decided to equalize the welfare of all citizens in Berland by the expense of the state treasury.
Totally in Berland there are *n* citizens, the welfare of each of them is estimated as the integer in *a**i* burles (burle is the currency in Berl... | The first line contains the integer *n* (1<=≤<=*n*<=≤<=100) — the number of citizens in the kingdom.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n*, where *a**i* (0<=≤<=*a**i*<=≤<=106) — the welfare of the *i*-th citizen. | In the only line print the integer *S* — the minimum number of burles which are had to spend. | [
"5\n0 1 2 3 4\n",
"5\n1 1 0 1 1\n",
"3\n1 3 1\n",
"1\n12\n"
] | [
"10",
"1",
"4",
"0"
] | In the first example if we add to the first citizen 4 burles, to the second 3, to the third 2 and to the fourth 1, then the welfare of all citizens will equal 4.
In the second example it is enough to give one burle to the third citizen.
In the third example it is necessary to give two burles to the first and the thi... | 500 | [
{
"input": "5\n0 1 2 3 4",
"output": "10"
},
{
"input": "5\n1 1 0 1 1",
"output": "1"
},
{
"input": "3\n1 3 1",
"output": "4"
},
{
"input": "1\n12",
"output": "0"
},
{
"input": "3\n1 2 3",
"output": "3"
},
{
"input": "14\n52518 718438 358883 462189 853... | 1,688,377,481 | 2,147,483,647 | Python 3 | OK | TESTS | 41 | 46 | 0 | # https://codeforces.com/problemset/problem/758/A
citizens = int(input())
burles_per_citizen = list(map(int, input().split()))
richest_citizen_brules = max(burles_per_citizen)
burles_required = (richest_citizen_brules * citizens) - sum(burles_per_citizen)
print(burles_required)
| Title: Holiday Of Equality
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In Berland it is the holiday of equality. In honor of the holiday the king decided to equalize the welfare of all citizens in Berland by the expense of the state treasury.
Totally in Berland there are *n* citizens... | ```python
# https://codeforces.com/problemset/problem/758/A
citizens = int(input())
burles_per_citizen = list(map(int, input().split()))
richest_citizen_brules = max(burles_per_citizen)
burles_required = (richest_citizen_brules * citizens) - sum(burles_per_citizen)
print(burles_required)
``` | 3 | |
841 | A | Generous Kefa | PROGRAMMING | 900 | [
"brute force",
"implementation"
] | null | null | One day Kefa found *n* baloons. For convenience, we denote color of *i*-th baloon as *s**i* — lowercase letter of the Latin alphabet. Also Kefa has *k* friends. Friend will be upset, If he get two baloons of the same color. Kefa want to give out all baloons to his friends. Help Kefa to find out, can he give out all his... | The first line contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=100) — the number of baloons and friends.
Next line contains string *s* — colors of baloons. | Answer to the task — «YES» or «NO» in a single line.
You can choose the case (lower or upper) for each letter arbitrary. | [
"4 2\naabb\n",
"6 3\naacaab\n"
] | [
"YES\n",
"NO\n"
] | In the first sample Kefa can give 1-st and 3-rd baloon to the first friend, and 2-nd and 4-th to the second.
In the second sample Kefa needs to give to all his friends baloons of color a, but one baloon will stay, thats why answer is «NO». | 500 | [
{
"input": "4 2\naabb",
"output": "YES"
},
{
"input": "6 3\naacaab",
"output": "NO"
},
{
"input": "2 2\nlu",
"output": "YES"
},
{
"input": "5 3\novvoo",
"output": "YES"
},
{
"input": "36 13\nbzbzcffczzcbcbzzfzbbfzfzzbfbbcbfccbf",
"output": "YES"
},
{
"... | 1,651,129,279 | 2,147,483,647 | Python 3 | OK | TESTS | 114 | 46 | 0 | n, k = map(int, input().split())
s = input()
d = {}
count = 0
for i in s:
if i in d:
d[i] += 1
else:
d[i] = 1
for j in d:
if d[j]>k:
count+=1
if count>0:
print('NO')
else:
print('YES') | Title: Generous Kefa
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day Kefa found *n* baloons. For convenience, we denote color of *i*-th baloon as *s**i* — lowercase letter of the Latin alphabet. Also Kefa has *k* friends. Friend will be upset, If he get two baloons of the same colo... | ```python
n, k = map(int, input().split())
s = input()
d = {}
count = 0
for i in s:
if i in d:
d[i] += 1
else:
d[i] = 1
for j in d:
if d[j]>k:
count+=1
if count>0:
print('NO')
else:
print('YES')
``` | 3 | |
544 | B | Sea and Islands | PROGRAMMING | 1,400 | [
"constructive algorithms",
"implementation"
] | null | null | A map of some object is a rectangular field consisting of *n* rows and *n* columns. Each cell is initially occupied by the sea but you can cover some some cells of the map with sand so that exactly *k* islands appear on the map. We will call a set of sand cells to be island if it is possible to get from each of them to... | The single line contains two positive integers *n*, *k* (1<=≤<=*n*<=≤<=100, 0<=≤<=*k*<=≤<=*n*2) — the size of the map and the number of islands you should form. | If the answer doesn't exist, print "NO" (without the quotes) in a single line.
Otherwise, print "YES" in the first line. In the next *n* lines print the description of the map. Each of the lines of the description must consist only of characters 'S' and 'L', where 'S' is a cell that is occupied by the sea and 'L' is t... | [
"5 2\n",
"5 25\n"
] | [
"YES\nSSSSS\nLLLLL\nSSSSS\nLLLLL\nSSSSS\n",
"NO\n"
] | none | 1,000 | [
{
"input": "5 2",
"output": "YES\nSSSSS\nLLLLL\nSSSSS\nLLLLL\nSSSSS"
},
{
"input": "5 25",
"output": "NO"
},
{
"input": "82 6047",
"output": "NO"
},
{
"input": "6 5",
"output": "YES\nLSLSLS\nSLSLSS\nSSSSSS\nSSSSSS\nSSSSSS\nSSSSSS"
},
{
"input": "10 80",
"outpu... | 1,673,173,570 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 8 | 77 | 0 | from collections import defaultdict, Counter
from math import dist, ceil, floor, sqrt, log
from sys import stdin
inp = stdin.readline
def IA(sep=' '): return list(map(int, inp().split(sep)))
def FA(): return list(map(float, inp().split()))
def SA(): return inp().split()
def I(): return int(inp())
def F(): retur... | Title: Sea and Islands
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A map of some object is a rectangular field consisting of *n* rows and *n* columns. Each cell is initially occupied by the sea but you can cover some some cells of the map with sand so that exactly *k* islands appear on... | ```python
from collections import defaultdict, Counter
from math import dist, ceil, floor, sqrt, log
from sys import stdin
inp = stdin.readline
def IA(sep=' '): return list(map(int, inp().split(sep)))
def FA(): return list(map(float, inp().split()))
def SA(): return inp().split()
def I(): return int(inp())
def ... | 0 | |
69 | A | Young Physicist | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | A. Young Physicist | 2 | 256 | A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasy... | The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100), then follow *n* lines containing three integers each: the *x**i* coordinate, the *y**i* coordinate and the *z**i* coordinate of the force vector, applied to the body (<=-<=100<=≤<=*x**i*,<=*y**i*,<=*z**i*<=≤<=100). | Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not. | [
"3\n4 1 7\n-2 4 -1\n1 -5 -3\n",
"3\n3 -1 7\n-5 2 -4\n2 -1 -3\n"
] | [
"NO",
"YES"
] | none | 500 | [
{
"input": "3\n4 1 7\n-2 4 -1\n1 -5 -3",
"output": "NO"
},
{
"input": "3\n3 -1 7\n-5 2 -4\n2 -1 -3",
"output": "YES"
},
{
"input": "10\n21 32 -46\n43 -35 21\n42 2 -50\n22 40 20\n-27 -9 38\n-4 1 1\n-40 6 -31\n-13 -2 34\n-21 34 -12\n-32 -29 41",
"output": "NO"
},
{
"input": "10... | 1,622,131,094 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 62 | 0 | def vectorAddition(t, lst):
sum1 = 0
sum2 = 0
sum3 = 0
for i in range(len(lst)):
sum1 += lst[i][0]
sum2 += lst[i][1]
sum3 += lst[i][2]
if (sum1 == 0 and sum2 == 0 and
sum3 == 0):
print("YES")
else:
print("NO") | Title: Young Physicist
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. S... | ```python
def vectorAddition(t, lst):
sum1 = 0
sum2 = 0
sum3 = 0
for i in range(len(lst)):
sum1 += lst[i][0]
sum2 += lst[i][1]
sum3 += lst[i][2]
if (sum1 == 0 and sum2 == 0 and
sum3 == 0):
print("YES")
else:
print("NO")
... | 0 |
501 | A | Contest | PROGRAMMING | 900 | [
"implementation"
] | null | null | Misha and Vasya participated in a Codeforces contest. Unfortunately, each of them solved only one problem, though successfully submitted it at the first attempt. Misha solved the problem that costs *a* points and Vasya solved the problem that costs *b* points. Besides, Misha submitted the problem *c* minutes after the ... | The first line contains four integers *a*, *b*, *c*, *d* (250<=≤<=*a*,<=*b*<=≤<=3500, 0<=≤<=*c*,<=*d*<=≤<=180).
It is guaranteed that numbers *a* and *b* are divisible by 250 (just like on any real Codeforces round). | Output on a single line:
"Misha" (without the quotes), if Misha got more points than Vasya.
"Vasya" (without the quotes), if Vasya got more points than Misha.
"Tie" (without the quotes), if both of them got the same number of points. | [
"500 1000 20 30\n",
"1000 1000 1 1\n",
"1500 1000 176 177\n"
] | [
"Vasya\n",
"Tie\n",
"Misha\n"
] | none | 500 | [
{
"input": "500 1000 20 30",
"output": "Vasya"
},
{
"input": "1000 1000 1 1",
"output": "Tie"
},
{
"input": "1500 1000 176 177",
"output": "Misha"
},
{
"input": "1500 1000 74 177",
"output": "Misha"
},
{
"input": "750 2500 175 178",
"output": "Vasya"
},
{
... | 1,563,454,439 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 124 | 0 | a,b,c,d=map(int,input().split())
x=max((3*a//10),(a-(a//250*c)))
y=max((3*b//10),(b-((b//250)*d)))
# print(x,y)
if y>x:
print('Vasya')
elif x>y:
print('Misha')
else:
print('Tie') | Title: Contest
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Misha and Vasya participated in a Codeforces contest. Unfortunately, each of them solved only one problem, though successfully submitted it at the first attempt. Misha solved the problem that costs *a* points and Vasya solved t... | ```python
a,b,c,d=map(int,input().split())
x=max((3*a//10),(a-(a//250*c)))
y=max((3*b//10),(b-((b//250)*d)))
# print(x,y)
if y>x:
print('Vasya')
elif x>y:
print('Misha')
else:
print('Tie')
``` | 3 | |
275 | A | Lights Out | PROGRAMMING | 900 | [
"implementation"
] | null | null | Lenny is playing a game on a 3<=×<=3 grid of lights. In the beginning of the game all lights are switched on. Pressing any of the lights will toggle it and all side-adjacent lights. The goal of the game is to switch all the lights off. We consider the toggling as follows: if the light was switched on then it will be sw... | The input consists of three rows. Each row contains three integers each between 0 to 100 inclusive. The *j*-th number in the *i*-th row is the number of times the *j*-th light of the *i*-th row of the grid is pressed. | Print three lines, each containing three characters. The *j*-th character of the *i*-th line is "1" if and only if the corresponding light is switched on, otherwise it's "0". | [
"1 0 0\n0 0 0\n0 0 1\n",
"1 0 1\n8 8 8\n2 0 3\n"
] | [
"001\n010\n100\n",
"010\n011\n100\n"
] | none | 500 | [
{
"input": "1 0 0\n0 0 0\n0 0 1",
"output": "001\n010\n100"
},
{
"input": "1 0 1\n8 8 8\n2 0 3",
"output": "010\n011\n100"
},
{
"input": "13 85 77\n25 50 45\n65 79 9",
"output": "000\n010\n000"
},
{
"input": "96 95 5\n8 84 74\n67 31 61",
"output": "011\n011\n101"
},
{... | 1,588,962,099 | 2,147,483,647 | Python 3 | OK | TESTS | 33 | 124 | 6,963,200 | import sys
input = sys.stdin.readline
def inlt():
return (list(map(int, input().split())))
def solve(m):
def helper(mat, i, j):
direction = [(0,0), (-1, 0), (1, 0), (0, -1), (0, 1)]
for d in direction:
if i + d[0] > -1 and i + d[0] < 3 and j + d[1] > -1 and j + d[1] < 3:
... | Title: Lights Out
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Lenny is playing a game on a 3<=×<=3 grid of lights. In the beginning of the game all lights are switched on. Pressing any of the lights will toggle it and all side-adjacent lights. The goal of the game is to switch all the ... | ```python
import sys
input = sys.stdin.readline
def inlt():
return (list(map(int, input().split())))
def solve(m):
def helper(mat, i, j):
direction = [(0,0), (-1, 0), (1, 0), (0, -1), (0, 1)]
for d in direction:
if i + d[0] > -1 and i + d[0] < 3 and j + d[1] > -1 and j + d[1] < ... | 3 | |
629 | A | Far Relative’s Birthday Cake | PROGRAMMING | 800 | [
"brute force",
"combinatorics",
"constructive algorithms",
"implementation"
] | null | null | Door's family is going celebrate Famil Doors's birthday party. They love Famil Door so they are planning to make his birthday cake weird!
The cake is a *n*<=×<=*n* square consisting of equal squares with side length 1. Each square is either empty or consists of a single chocolate. They bought the cake and randomly sta... | In the first line of the input, you are given a single integer *n* (1<=≤<=*n*<=≤<=100) — the length of the side of the cake.
Then follow *n* lines, each containing *n* characters. Empty cells are denoted with '.', while cells that contain chocolates are denoted by 'C'. | Print the value of Famil Door's happiness, i.e. the number of pairs of chocolate pieces that share the same row or the same column. | [
"3\n.CC\nC..\nC.C\n",
"4\nCC..\nC..C\n.CC.\n.CC.\n"
] | [
"4\n",
"9\n"
] | If we number rows from top to bottom and columns from left to right, then, pieces that share the same row in the first sample are:
1. (1, 2) and (1, 3) 1. (3, 1) and (3, 3) 1. (2, 1) and (3, 1) 1. (1, 3) and (3, 3) | 500 | [
{
"input": "3\n.CC\nC..\nC.C",
"output": "4"
},
{
"input": "4\nCC..\nC..C\n.CC.\n.CC.",
"output": "9"
},
{
"input": "5\n.CCCC\nCCCCC\n.CCC.\nCC...\n.CC.C",
"output": "46"
},
{
"input": "7\n.CC..CC\nCC.C..C\nC.C..C.\nC...C.C\nCCC.CCC\n.CC...C\n.C.CCC.",
"output": "84"
},... | 1,613,068,342 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 62 | 0 | n = int(input())
cake = []
for i in range(n):
s = input()
cake.append(s)
count = 0
for i in range(n-1):
for j in range(n-1):
if cake[i][j] == cake[i][j+1]:
count += 1
if cake[i][j] == cake[i+1][j]:
count += 1
print(count) | Title: Far Relative’s Birthday Cake
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Door's family is going celebrate Famil Doors's birthday party. They love Famil Door so they are planning to make his birthday cake weird!
The cake is a *n*<=×<=*n* square consisting of equal squares with s... | ```python
n = int(input())
cake = []
for i in range(n):
s = input()
cake.append(s)
count = 0
for i in range(n-1):
for j in range(n-1):
if cake[i][j] == cake[i][j+1]:
count += 1
if cake[i][j] == cake[i+1][j]:
count += 1
print(count)
``` | 0 | |
287 | B | Pipeline | PROGRAMMING | 1,700 | [
"binary search",
"math"
] | null | null | Vova, the Ultimate Thule new shaman, wants to build a pipeline. As there are exactly *n* houses in Ultimate Thule, Vova wants the city to have exactly *n* pipes, each such pipe should be connected to the water supply. A pipe can be connected to the water supply if there's water flowing out of it. Initially Vova has onl... | The first line contains two space-separated integers *n* and *k* (1<=≤<=*n*<=≤<=1018, 2<=≤<=*k*<=≤<=109).
Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier. | Print a single integer — the minimum number of splitters needed to build the pipeline. If it is impossible to build a pipeline with the given splitters, print -1. | [
"4 3\n",
"5 5\n",
"8 4\n"
] | [
"2\n",
"1\n",
"-1\n"
] | none | 1,500 | [
{
"input": "4 3",
"output": "2"
},
{
"input": "5 5",
"output": "1"
},
{
"input": "8 4",
"output": "-1"
},
{
"input": "1000000000000000000 1000000000",
"output": "-1"
},
{
"input": "499999998500000001 1000000000",
"output": "999955279"
},
{
"input": "49... | 1,654,618,408 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 31 | 0 | class Pipeline :
@staticmethod
def sumOfPipes( n, k) :
left = 1
right = k
while (left < right) :
mid = (left + right) / 2
s = Pipeline.sum(mid, k)
if (s == n) :
return k - mid + 1
elif(s > n) :
l... | Title: Pipeline
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vova, the Ultimate Thule new shaman, wants to build a pipeline. As there are exactly *n* houses in Ultimate Thule, Vova wants the city to have exactly *n* pipes, each such pipe should be connected to the water supply. A pipe c... | ```python
class Pipeline :
@staticmethod
def sumOfPipes( n, k) :
left = 1
right = k
while (left < right) :
mid = (left + right) / 2
s = Pipeline.sum(mid, k)
if (s == n) :
return k - mid + 1
elif(s > n) :
... | -1 | |
599 | A | Patrick and Shopping | PROGRAMMING | 800 | [
"implementation"
] | null | null | Today Patrick waits for a visit from his friend Spongebob. To prepare for the visit, Patrick needs to buy some goodies in two stores located near his house. There is a *d*1 meter long road between his house and the first shop and a *d*2 meter long road between his house and the second shop. Also, there is a road of len... | The first line of the input contains three integers *d*1, *d*2, *d*3 (1<=≤<=*d*1,<=*d*2,<=*d*3<=≤<=108) — the lengths of the paths.
- *d*1 is the length of the path connecting Patrick's house and the first shop; - *d*2 is the length of the path connecting Patrick's house and the second shop; - *d*3 is the length o... | Print the minimum distance that Patrick will have to walk in order to visit both shops and return to his house. | [
"10 20 30\n",
"1 1 5\n"
] | [
"60\n",
"4\n"
] | The first sample is shown on the picture in the problem statement. One of the optimal routes is: house <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> first shop <img align="middle" class="tex-form... | 500 | [
{
"input": "10 20 30",
"output": "60"
},
{
"input": "1 1 5",
"output": "4"
},
{
"input": "100 33 34",
"output": "134"
},
{
"input": "777 777 777",
"output": "2331"
},
{
"input": "2 2 8",
"output": "8"
},
{
"input": "12 34 56",
"output": "92"
},
... | 1,587,638,345 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 93 | 0 | a,b,c=map(int,input().split())
n=a+b
print(n+min(n,c)) | Title: Patrick and Shopping
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Today Patrick waits for a visit from his friend Spongebob. To prepare for the visit, Patrick needs to buy some goodies in two stores located near his house. There is a *d*1 meter long road between his house and the... | ```python
a,b,c=map(int,input().split())
n=a+b
print(n+min(n,c))
``` | 0 | |
69 | A | Young Physicist | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | A. Young Physicist | 2 | 256 | A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasy... | The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100), then follow *n* lines containing three integers each: the *x**i* coordinate, the *y**i* coordinate and the *z**i* coordinate of the force vector, applied to the body (<=-<=100<=≤<=*x**i*,<=*y**i*,<=*z**i*<=≤<=100). | Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not. | [
"3\n4 1 7\n-2 4 -1\n1 -5 -3\n",
"3\n3 -1 7\n-5 2 -4\n2 -1 -3\n"
] | [
"NO",
"YES"
] | none | 500 | [
{
"input": "3\n4 1 7\n-2 4 -1\n1 -5 -3",
"output": "NO"
},
{
"input": "3\n3 -1 7\n-5 2 -4\n2 -1 -3",
"output": "YES"
},
{
"input": "10\n21 32 -46\n43 -35 21\n42 2 -50\n22 40 20\n-27 -9 38\n-4 1 1\n-40 6 -31\n-13 -2 34\n-21 34 -12\n-32 -29 41",
"output": "NO"
},
{
"input": "10... | 1,639,661,468 | 2,147,483,647 | PyPy 3 | OK | TESTS | 81 | 184 | 0 | s = int(input())
c = 0
w = 0
q = 0
for i in range(s):
a = input()
a = a.split()
# print(a)
x = int(a[0])
y = int(a[1])
z = int(a[2])
# print(x,y,z)
c = c + x
w = w + y
q = q + z
# print(c, w, q)
if c == 0 and w == 0 and q == 0:
print('YES')
else:
print(... | Title: Young Physicist
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. S... | ```python
s = int(input())
c = 0
w = 0
q = 0
for i in range(s):
a = input()
a = a.split()
# print(a)
x = int(a[0])
y = int(a[1])
z = int(a[2])
# print(x,y,z)
c = c + x
w = w + y
q = q + z
# print(c, w, q)
if c == 0 and w == 0 and q == 0:
print('YES')
else:
... | 3.954 |
435 | A | Queue on Bus Stop | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | It's that time of the year when the Russians flood their countryside summer cottages (dachas) and the bus stop has a lot of people. People rarely go to the dacha on their own, it's usually a group, so the people stand in queue by groups.
The bus stop queue has *n* groups of people. The *i*-th group from the beginning ... | The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100). The next line contains *n* integers: *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*m*). | Print a single integer — the number of buses that is needed to transport all *n* groups to the dacha countryside. | [
"4 3\n2 3 2 1\n",
"3 4\n1 2 1\n"
] | [
"3\n",
"1\n"
] | none | 500 | [
{
"input": "4 3\n2 3 2 1",
"output": "3"
},
{
"input": "3 4\n1 2 1",
"output": "1"
},
{
"input": "1 5\n4",
"output": "1"
},
{
"input": "5 1\n1 1 1 1 1",
"output": "5"
},
{
"input": "6 4\n1 3 2 3 4 1",
"output": "5"
},
{
"input": "6 8\n6 1 1 1 4 5",
... | 1,576,445,457 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 4 | 139 | 0 | import math
n, m = map(int,input().split())
a= list(map(int, input().strip().split()))[:n]
print(math.ceil(sum(a) / m)) | Title: Queue on Bus Stop
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
It's that time of the year when the Russians flood their countryside summer cottages (dachas) and the bus stop has a lot of people. People rarely go to the dacha on their own, it's usually a group, so the people stand... | ```python
import math
n, m = map(int,input().split())
a= list(map(int, input().strip().split()))[:n]
print(math.ceil(sum(a) / m))
``` | 0 | |
699 | A | Launch of Collider | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | There will be a launch of a new, powerful and unusual collider very soon, which located along a straight line. *n* particles will be launched inside it. All of them are located in a straight line and there can not be two or more particles located in the same point. The coordinates of the particles coincide with the dis... | The first line contains the positive integer *n* (1<=≤<=*n*<=≤<=200<=000) — the number of particles.
The second line contains *n* symbols "L" and "R". If the *i*-th symbol equals "L", then the *i*-th particle will move to the left, otherwise the *i*-th symbol equals "R" and the *i*-th particle will move to the right.... | In the first line print the only integer — the first moment (in microseconds) when two particles are at the same point and there will be an explosion.
Print the only integer -1, if the collision of particles doesn't happen. | [
"4\nRLRL\n2 4 6 10\n",
"3\nLLR\n40 50 60\n"
] | [
"1\n",
"-1\n"
] | In the first sample case the first explosion will happen in 1 microsecond because the particles number 1 and 2 will simultaneously be at the same point with the coordinate 3.
In the second sample case there will be no explosion because there are no particles which will simultaneously be at the same point. | 500 | [
{
"input": "4\nRLRL\n2 4 6 10",
"output": "1"
},
{
"input": "3\nLLR\n40 50 60",
"output": "-1"
},
{
"input": "4\nRLLR\n46 230 264 470",
"output": "92"
},
{
"input": "6\nLLRLLL\n446 492 650 844 930 970",
"output": "97"
},
{
"input": "8\nRRLLLLLL\n338 478 512 574 59... | 1,468,936,303 | 2,803 | Python 3 | WRONG_ANSWER | PRETESTS | 3 | 78 | 0 | n=int(input())
s=input()
m=list(map(int,input().split()))
if "R" in s and "L" in s and s.index('R')<s.index('L'):
f=s.index('R')
f1=m[f]
s=s[f:]
m=m[f:]
se=s.index('L')
se1=m[se]
ans=se1-f1
print(ans//2)
else:
print(-1) | Title: Launch of Collider
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There will be a launch of a new, powerful and unusual collider very soon, which located along a straight line. *n* particles will be launched inside it. All of them are located in a straight line and there can not be... | ```python
n=int(input())
s=input()
m=list(map(int,input().split()))
if "R" in s and "L" in s and s.index('R')<s.index('L'):
f=s.index('R')
f1=m[f]
s=s[f:]
m=m[f:]
se=s.index('L')
se1=m[se]
ans=se1-f1
print(ans//2)
else:
print(-1)
``` | 0 | |
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,581,979,764 | 2,147,483,647 | PyPy 3 | OK | TESTS | 56 | 170 | 1,945,600 | # your code goes here
s1=input()
s2=input()
n1=len(s1)
n2=len(s2)
c=0
i=0
while i<=n1-n2+1:
st=s1[i:i+n2]
if st==s2:
c+=1
i=i+n2
else:
i+=1
print(c) | 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
# your code goes here
s1=input()
s2=input()
n1=len(s1)
n2=len(s2)
c=0
i=0
while i<=n1-n2+1:
st=s1[i:i+n2]
if st==s2:
c+=1
i=i+n2
else:
i+=1
print(c)
``` | 3 | |
686 | A | Free Ice Cream | PROGRAMMING | 800 | [
"constructive algorithms",
"implementation"
] | null | null | After their adventure with the magic mirror Kay and Gerda have returned home and sometimes give free ice cream to kids in the summer.
At the start of the day they have *x* ice cream packs. Since the ice cream is free, people start standing in the queue before Kay and Gerda's house even in the night. Each person in the... | The first line contains two space-separated integers *n* and *x* (1<=≤<=*n*<=≤<=1000, 0<=≤<=*x*<=≤<=109).
Each of the next *n* lines contains a character '+' or '-', and an integer *d**i*, separated by a space (1<=≤<=*d**i*<=≤<=109). Record "+ *d**i*" in *i*-th line means that a carrier with *d**i* ice cream packs occ... | Print two space-separated integers — number of ice cream packs left after all operations, and number of kids that left the house in distress. | [
"5 7\n+ 5\n- 10\n- 20\n+ 40\n- 20\n",
"5 17\n- 16\n- 2\n- 98\n+ 100\n- 98\n"
] | [
"22 1\n",
"3 2\n"
] | Consider the first sample.
1. Initially Kay and Gerda have 7 packs of ice cream. 1. Carrier brings 5 more, so now they have 12 packs. 1. A kid asks for 10 packs and receives them. There are only 2 packs remaining. 1. Another kid asks for 20 packs. Kay and Gerda do not have them, so the kid goes away distressed. 1.... | 500 | [
{
"input": "5 7\n+ 5\n- 10\n- 20\n+ 40\n- 20",
"output": "22 1"
},
{
"input": "5 17\n- 16\n- 2\n- 98\n+ 100\n- 98",
"output": "3 2"
},
{
"input": "6 1000000000\n+ 1000000000\n+ 1000000000\n+ 1000000000\n+ 1000000000\n+ 1000000000\n+ 1000000000",
"output": "7000000000 0"
},
{
... | 1,680,357,134 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 46 | 0 | n,x=map(int,input().split())
ic_available=x
dis=0
for i in range(n):
ch,no=input().split()
if ch=='+':
ic_available+=int(no)
elif ch=='-':
if ic_available>=int(no):
ic_available-=int(no)
else:
dis+=1
print(ic_available,dis)
| Title: Free Ice Cream
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
After their adventure with the magic mirror Kay and Gerda have returned home and sometimes give free ice cream to kids in the summer.
At the start of the day they have *x* ice cream packs. Since the ice cream is free, p... | ```python
n,x=map(int,input().split())
ic_available=x
dis=0
for i in range(n):
ch,no=input().split()
if ch=='+':
ic_available+=int(no)
elif ch=='-':
if ic_available>=int(no):
ic_available-=int(no)
else:
dis+=1
print(ic_available,dis)
... | 3 | |
909 | C | Python Indentation | PROGRAMMING | 1,800 | [
"dp"
] | null | null | In Python, code blocks don't have explicit begin/end or curly braces to mark beginning and end of the block. Instead, code blocks are defined by indentation.
We will consider an extremely simplified subset of Python with only two types of statements.
Simple statements are written in a single line, one per line. An ex... | The first line contains a single integer *N* (1<=≤<=*N*<=≤<=5000) — the number of commands in the program. *N* lines of the program follow, each line describing a single command. Each command is either "f" (denoting "for statement") or "s" ("simple statement"). It is guaranteed that the last line is a simple statement. | Output one line containing an integer - the number of ways the given sequence of statements can be indented modulo 109<=+<=7. | [
"4\ns\nf\nf\ns\n",
"4\nf\ns\nf\ns\n"
] | [
"1\n",
"2\n"
] | In the first test case, there is only one way to indent the program: the second for statement must be part of the body of the first one.
In the second test case, there are two ways to indent the program: the second for statement can either be part of the first one's body or a separate statement following the first one... | 1,500 | [
{
"input": "4\ns\nf\nf\ns",
"output": "1"
},
{
"input": "4\nf\ns\nf\ns",
"output": "2"
},
{
"input": "156\nf\ns\nf\ns\nf\ns\ns\ns\ns\nf\ns\ns\nf\nf\ns\nf\nf\nf\nf\ns\ns\ns\nf\ns\ns\nf\nf\nf\nf\nf\nf\ns\ns\ns\ns\nf\ns\nf\ns\nf\ns\nf\nf\nf\nf\ns\ns\nf\nf\ns\ns\ns\ns\nf\ns\nf\ns\nf\ns\nf\ns... | 1,554,596,684 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 2 | 124 | 716,800 | N = int(input())
instruction = [''] * N
for i in range(N):
instruction[i] = input()
ans = [[0 for _ in range(N)] for _ in range(N)]
ans[0][0] = 1
for i in range(1, N):
if instruction[i-1] == 'f':
for j in range(i):
ans[i][j+1] = ans[i-1][j]
else:
temp = 0
... | Title: Python Indentation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In Python, code blocks don't have explicit begin/end or curly braces to mark beginning and end of the block. Instead, code blocks are defined by indentation.
We will consider an extremely simplified subset of Python... | ```python
N = int(input())
instruction = [''] * N
for i in range(N):
instruction[i] = input()
ans = [[0 for _ in range(N)] for _ in range(N)]
ans[0][0] = 1
for i in range(1, N):
if instruction[i-1] == 'f':
for j in range(i):
ans[i][j+1] = ans[i-1][j]
else:
tem... | 0 | |
699 | A | Launch of Collider | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | There will be a launch of a new, powerful and unusual collider very soon, which located along a straight line. *n* particles will be launched inside it. All of them are located in a straight line and there can not be two or more particles located in the same point. The coordinates of the particles coincide with the dis... | The first line contains the positive integer *n* (1<=≤<=*n*<=≤<=200<=000) — the number of particles.
The second line contains *n* symbols "L" and "R". If the *i*-th symbol equals "L", then the *i*-th particle will move to the left, otherwise the *i*-th symbol equals "R" and the *i*-th particle will move to the right.... | In the first line print the only integer — the first moment (in microseconds) when two particles are at the same point and there will be an explosion.
Print the only integer -1, if the collision of particles doesn't happen. | [
"4\nRLRL\n2 4 6 10\n",
"3\nLLR\n40 50 60\n"
] | [
"1\n",
"-1\n"
] | In the first sample case the first explosion will happen in 1 microsecond because the particles number 1 and 2 will simultaneously be at the same point with the coordinate 3.
In the second sample case there will be no explosion because there are no particles which will simultaneously be at the same point. | 500 | [
{
"input": "4\nRLRL\n2 4 6 10",
"output": "1"
},
{
"input": "3\nLLR\n40 50 60",
"output": "-1"
},
{
"input": "4\nRLLR\n46 230 264 470",
"output": "92"
},
{
"input": "6\nLLRLLL\n446 492 650 844 930 970",
"output": "97"
},
{
"input": "8\nRRLLLLLL\n338 478 512 574 59... | 1,469,739,266 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 46 | 0 | import sys
if __name__ == '__main__':
n = list(map(int, sys.stdin.readline().split(" ")))[0]
a = list(sys.stdin.readline())
x = list(map(int, sys.stdin.readline().split(" ")))
m = 100000000000
for i in range(n-1):
if a[i]=='R' and a[i+1]=='L':
m = min(m,(x[i+1]-x[i])/2)... | Title: Launch of Collider
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There will be a launch of a new, powerful and unusual collider very soon, which located along a straight line. *n* particles will be launched inside it. All of them are located in a straight line and there can not be... | ```python
import sys
if __name__ == '__main__':
n = list(map(int, sys.stdin.readline().split(" ")))[0]
a = list(sys.stdin.readline())
x = list(map(int, sys.stdin.readline().split(" ")))
m = 100000000000
for i in range(n-1):
if a[i]=='R' and a[i+1]=='L':
m = min(m,(x[i+1... | 0 | |
25 | C | Roads in Berland | PROGRAMMING | 1,900 | [
"graphs",
"shortest paths"
] | C. Roads in Berland | 2 | 256 | There are *n* cities numbered from 1 to *n* in Berland. Some of them are connected by two-way roads. Each road has its own length — an integer number from 1 to 1000. It is known that from each city it is possible to get to any other city by existing roads. Also for each pair of cities it is known the shortest distance ... | The first line contains integer *n* (2<=≤<=*n*<=≤<=300) — amount of cities in Berland. Then there follow *n* lines with *n* integer numbers each — the matrix of shortest distances. *j*-th integer in the *i*-th row — *d**i*,<=*j*, the shortest distance between cities *i* and *j*. It is guaranteed that *d**i*,<=*i*<==<=0... | Output *k* space-separated integers *q**i* (1<=≤<=*i*<=≤<=*k*). *q**i* should be equal to the sum of shortest distances between all pairs of cities after the construction of roads with indexes from 1 to *i*. Roads are numbered from 1 in the input order. Each pair of cities should be taken into account in the sum exactl... | [
"2\n0 5\n5 0\n1\n1 2 3\n",
"3\n0 4 5\n4 0 9\n5 9 0\n2\n2 3 8\n1 2 1\n"
] | [
"3 ",
"17 12 "
] | none | 0 | [
{
"input": "2\n0 5\n5 0\n1\n1 2 3",
"output": "3 "
},
{
"input": "3\n0 4 5\n4 0 9\n5 9 0\n2\n2 3 8\n1 2 1",
"output": "17 12 "
},
{
"input": "3\n0 983 173\n983 0 810\n173 810 0\n3\n3 2 567\n2 3 767\n1 2 763",
"output": "1480 1480 1480 "
},
{
"input": "4\n0 537 1064 656\n537 0... | 1,667,721,377 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 41 | 1,214 | 7,270,400 | n = int(input())
matrix = []
for _ in range(n):
li = list(map(int, input().split()))
matrix.append(li)
k = int(input())
ans = []
def floyd(matrix, inter):
for i in range(len(matrix)):
for j in range(len(matrix)):
matrix[i][j] = min(matrix[i][j], matrix[i][inter] + matrix[... | Title: Roads in Berland
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
There are *n* cities numbered from 1 to *n* in Berland. Some of them are connected by two-way roads. Each road has its own length — an integer number from 1 to 1000. It is known that from each city it is possible to get to... | ```python
n = int(input())
matrix = []
for _ in range(n):
li = list(map(int, input().split()))
matrix.append(li)
k = int(input())
ans = []
def floyd(matrix, inter):
for i in range(len(matrix)):
for j in range(len(matrix)):
matrix[i][j] = min(matrix[i][j], matrix[i][inter]... | 3.682958 |
739 | A | Alyona and mex | PROGRAMMING | 1,700 | [
"constructive algorithms",
"greedy"
] | 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. | 500 | [
{
"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,480,023,459 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | #include <bits/stdc++.h>
#ifndef M_PI
#define M_PI 3.14159265358979323846264338327
#endif // M_PI
#define endl "\n"
#define S struct
#define X first
#define Y second
#define V vector
#ifndef __linux__
#define LLD "%I64d"
#else
#define LLD "%ll""d"
#endif
#define FOR(x, y, z) for (int x = (y); x < (z); ++x)
#define FORR... | Title: Alyona and mex
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 s... | ```python
#include <bits/stdc++.h>
#ifndef M_PI
#define M_PI 3.14159265358979323846264338327
#endif // M_PI
#define endl "\n"
#define S struct
#define X first
#define Y second
#define V vector
#ifndef __linux__
#define LLD "%I64d"
#else
#define LLD "%ll""d"
#endif
#define FOR(x, y, z) for (int x = (y); x < (z); ++x)
#d... | -1 | |
50 | A | Domino piling | PROGRAMMING | 800 | [
"greedy",
"math"
] | A. Domino piling | 2 | 256 | You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions:
1. Each domino completely covers ... | In a single line you are given two integers *M* and *N* — board sizes in squares (1<=≤<=*M*<=≤<=*N*<=≤<=16). | Output one number — the maximal number of dominoes, which can be placed. | [
"2 4\n",
"3 3\n"
] | [
"4\n",
"4\n"
] | none | 500 | [
{
"input": "2 4",
"output": "4"
},
{
"input": "3 3",
"output": "4"
},
{
"input": "1 5",
"output": "2"
},
{
"input": "1 6",
"output": "3"
},
{
"input": "1 15",
"output": "7"
},
{
"input": "1 16",
"output": "8"
},
{
"input": "2 5",
"outpu... | 1,617,221,270 | 2,147,483,647 | PyPy 3 | OK | TESTS | 35 | 218 | 0 | N,M = map(int,input().split())
print((N*M)//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,M = map(int,input().split())
print((N*M)//2)
``` | 3.9455 |
450 | A | Jzzhu and Children | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | There are *n* children in Jzzhu's school. Jzzhu is going to give some candies to them. Let's number all the children from 1 to *n*. The *i*-th child wants to get at least *a**i* candies.
Jzzhu asks children to line up. Initially, the *i*-th child stands at the *i*-th place of the line. Then Jzzhu start distribution of... | The first line contains two integers *n*,<=*m* (1<=≤<=*n*<=≤<=100; 1<=≤<=*m*<=≤<=100). The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100). | Output a single integer, representing the number of the last child. | [
"5 2\n1 3 1 4 2\n",
"6 4\n1 1 2 2 3 3\n"
] | [
"4\n",
"6\n"
] | Let's consider the first sample.
Firstly child 1 gets 2 candies and go home. Then child 2 gets 2 candies and go to the end of the line. Currently the line looks like [3, 4, 5, 2] (indices of the children in order of the line). Then child 3 gets 2 candies and go home, and then child 4 gets 2 candies and goes to the en... | 500 | [
{
"input": "5 2\n1 3 1 4 2",
"output": "4"
},
{
"input": "6 4\n1 1 2 2 3 3",
"output": "6"
},
{
"input": "7 3\n6 1 5 4 2 3 1",
"output": "4"
},
{
"input": "10 5\n2 7 3 6 2 5 1 3 4 5",
"output": "4"
},
{
"input": "100 1\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18... | 1,699,981,353 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 4 | 77 | 1,228,800 | n,m=list(map(int,input().strip().split()))
child=list(map(int,input().strip().split()))
x=[]
for i in range(n):
x+=[[child[i],i+1]]
i=0
while len(x)>=1:
if x[i][0]>m:
x.append([x[i][0]-m,x[i][1]])
x.pop(i)
if len(x)==1:
print(x[0][1])
| Title: Jzzhu and Children
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* children in Jzzhu's school. Jzzhu is going to give some candies to them. Let's number all the children from 1 to *n*. The *i*-th child wants to get at least *a**i* candies.
Jzzhu asks children to line ... | ```python
n,m=list(map(int,input().strip().split()))
child=list(map(int,input().strip().split()))
x=[]
for i in range(n):
x+=[[child[i],i+1]]
i=0
while len(x)>=1:
if x[i][0]>m:
x.append([x[i][0]-m,x[i][1]])
x.pop(i)
if len(x)==1:
print(x[0][1])
``` | 0 | |
1,003 | A | Polycarp's Pockets | PROGRAMMING | 800 | [
"implementation"
] | null | null | Polycarp has $n$ coins, the value of the $i$-th coin is $a_i$. Polycarp wants to distribute all the coins between his pockets, but he cannot put two coins with the same value into the same pocket.
For example, if Polycarp has got six coins represented as an array $a = [1, 2, 4, 3, 3, 2]$, he can distribute the coins i... | The first line of the input contains one integer $n$ ($1 \le n \le 100$) — the number of coins.
The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 100$) — values of coins. | Print only one integer — the minimum number of pockets Polycarp needs to distribute all the coins so no two coins with the same value are put into the same pocket. | [
"6\n1 2 4 3 3 2\n",
"1\n100\n"
] | [
"2\n",
"1\n"
] | none | 0 | [
{
"input": "6\n1 2 4 3 3 2",
"output": "2"
},
{
"input": "1\n100",
"output": "1"
},
{
"input": "100\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100... | 1,672,686,692 | 392 | Python 3 | OK | TESTS | 37 | 61 | 102,400 | from collections import Counter
n = int(input())
coins = input().split()
max_freq = 0
hashmap = Counter(coins)
for freq in hashmap.values():
max_freq = max(max_freq, freq)
print(max_freq) | Title: Polycarp's Pockets
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp has $n$ coins, the value of the $i$-th coin is $a_i$. Polycarp wants to distribute all the coins between his pockets, but he cannot put two coins with the same value into the same pocket.
For example, if Po... | ```python
from collections import Counter
n = int(input())
coins = input().split()
max_freq = 0
hashmap = Counter(coins)
for freq in hashmap.values():
max_freq = max(max_freq, freq)
print(max_freq)
``` | 3 | |
271 | A | Beautiful Year | PROGRAMMING | 800 | [
"brute force"
] | null | null | It seems like the year of 2013 came only yesterday. Do you know a curious fact? The year of 2013 is the first year after the old 1987 with only distinct digits.
Now you are suggested to solve the following problem: given a year number, find the minimum year number which is strictly larger than the given one and has on... | The single line contains integer *y* (1000<=≤<=*y*<=≤<=9000) — the year number. | Print a single integer — the minimum year number that is strictly larger than *y* and all it's digits are distinct. It is guaranteed that the answer exists. | [
"1987\n",
"2013\n"
] | [
"2013\n",
"2014\n"
] | none | 500 | [
{
"input": "1987",
"output": "2013"
},
{
"input": "2013",
"output": "2014"
},
{
"input": "1000",
"output": "1023"
},
{
"input": "1001",
"output": "1023"
},
{
"input": "1234",
"output": "1235"
},
{
"input": "5555",
"output": "5601"
},
{
"inp... | 1,691,591,592 | 2,147,483,647 | Python 3 | OK | TESTS | 27 | 92 | 0 | y = int(input()) + 1
while len(set(str(y)))<=3:
y += 1
print(y)
| Title: Beautiful Year
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
It seems like the year of 2013 came only yesterday. Do you know a curious fact? The year of 2013 is the first year after the old 1987 with only distinct digits.
Now you are suggested to solve the following problem: give... | ```python
y = int(input()) + 1
while len(set(str(y)))<=3:
y += 1
print(y)
``` | 3 | |
355 | A | Vasya and Digital Root | PROGRAMMING | 1,100 | [
"constructive algorithms",
"implementation"
] | null | null | Vasya has recently found out what a digital root of a number is and he decided to share his knowledge with you.
Let's assume that *S*(*n*) is the sum of digits of number *n*, for example, *S*(4098)<==<=4<=+<=0<=+<=9<=+<=8<==<=21. Then the digital root of number *n* equals to:
1. *dr*(*n*)<==<=*S*(*n*), if *S*(*n*)<... | The first line contains two integers *k* and *d* (1<=≤<=*k*<=≤<=1000; 0<=≤<=*d*<=≤<=9). | In a single line print either any number that meets the requirements (without the leading zeroes) or "No solution" (without the quotes), if the corresponding number does not exist.
The chosen number must consist of exactly *k* digits. We assume that number 0 doesn't contain any leading zeroes. | [
"4 4\n",
"5 1\n",
"1 0\n"
] | [
"5881\n",
"36172\n",
"0\n"
] | For the first test sample *dr*(5881) = *dr*(22) = 4.
For the second test sample *dr*(36172) = *dr*(19) = *dr*(10) = 1. | 500 | [
{
"input": "4 4",
"output": "5881"
},
{
"input": "5 1",
"output": "36172"
},
{
"input": "1 0",
"output": "0"
},
{
"input": "8 7",
"output": "49722154"
},
{
"input": "487 0",
"output": "No solution"
},
{
"input": "1000 5",
"output": "854193955406789... | 1,567,662,650 | 2,147,483,647 | Python 3 | OK | TESTS | 20 | 139 | 512,000 | ######################################################################
# Write your code here
import sys
from math import *
input = sys.stdin.readline
#import resource
#resource.setrlimit(resource.RLIMIT_STACK, [0x10000000, resource.RLIM_INFINITY])
#sys.setrecursionlimit(0x100000)
# Write your code here
RI = l... | Title: Vasya and Digital Root
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya has recently found out what a digital root of a number is and he decided to share his knowledge with you.
Let's assume that *S*(*n*) is the sum of digits of number *n*, for example, *S*(4098)<==<=4<=+<=0<=... | ```python
######################################################################
# Write your code here
import sys
from math import *
input = sys.stdin.readline
#import resource
#resource.setrlimit(resource.RLIMIT_STACK, [0x10000000, resource.RLIM_INFINITY])
#sys.setrecursionlimit(0x100000)
# Write your code he... | 3 | |
758 | A | Holiday Of Equality | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | In Berland it is the holiday of equality. In honor of the holiday the king decided to equalize the welfare of all citizens in Berland by the expense of the state treasury.
Totally in Berland there are *n* citizens, the welfare of each of them is estimated as the integer in *a**i* burles (burle is the currency in Berl... | The first line contains the integer *n* (1<=≤<=*n*<=≤<=100) — the number of citizens in the kingdom.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n*, where *a**i* (0<=≤<=*a**i*<=≤<=106) — the welfare of the *i*-th citizen. | In the only line print the integer *S* — the minimum number of burles which are had to spend. | [
"5\n0 1 2 3 4\n",
"5\n1 1 0 1 1\n",
"3\n1 3 1\n",
"1\n12\n"
] | [
"10",
"1",
"4",
"0"
] | In the first example if we add to the first citizen 4 burles, to the second 3, to the third 2 and to the fourth 1, then the welfare of all citizens will equal 4.
In the second example it is enough to give one burle to the third citizen.
In the third example it is necessary to give two burles to the first and the thi... | 500 | [
{
"input": "5\n0 1 2 3 4",
"output": "10"
},
{
"input": "5\n1 1 0 1 1",
"output": "1"
},
{
"input": "3\n1 3 1",
"output": "4"
},
{
"input": "1\n12",
"output": "0"
},
{
"input": "3\n1 2 3",
"output": "3"
},
{
"input": "14\n52518 718438 358883 462189 853... | 1,693,451,414 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 15 | 0 | t = int(input())
list = [int(item) for item in input().split()]
ans = 0
m = max(list)
for x in list:
ans += m - x | Title: Holiday Of Equality
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In Berland it is the holiday of equality. In honor of the holiday the king decided to equalize the welfare of all citizens in Berland by the expense of the state treasury.
Totally in Berland there are *n* citizens... | ```python
t = int(input())
list = [int(item) for item in input().split()]
ans = 0
m = max(list)
for x in list:
ans += m - x
``` | 0 | |
990 | G | GCD Counting | PROGRAMMING | 2,400 | [
"divide and conquer",
"dp",
"dsu",
"number theory",
"trees"
] | null | null | You are given a tree consisting of $n$ vertices. A number is written on each vertex; the number on vertex $i$ is equal to $a_i$.
Let's denote the function $g(x, y)$ as the greatest common divisor of the numbers written on the vertices belonging to the simple path from vertex $x$ to vertex $y$ (including these two vert... | The first line contains one integer $n$ — the number of vertices $(1 \le n \le 2 \cdot 10^5)$.
The second line contains $n$ integers $a_1$, $a_2$, ..., $a_n$ $(1 \le a_i \le 2 \cdot 10^5)$ — the numbers written on vertices.
Then $n - 1$ lines follow, each containing two integers $x$ and $y$ $(1 \le x, y \le n, x \ne ... | For every integer $i$ from $1$ to $2 \cdot 10^5$ do the following: if there is no pair $(x, y)$ such that $x \le y$ and $g(x, y) = i$, don't output anything. Otherwise output two integers: $i$ and the number of aforementioned pairs. You have to consider the values of $i$ in ascending order.
See the examples for better... | [
"3\n1 2 3\n1 2\n2 3\n",
"6\n1 2 4 8 16 32\n1 6\n6 3\n3 4\n4 2\n6 5\n",
"4\n9 16 144 6\n1 3\n2 3\n4 3\n"
] | [
"1 4\n2 1\n3 1\n",
"1 6\n2 5\n4 6\n8 1\n16 2\n32 1\n",
"1 1\n2 1\n3 1\n6 2\n9 2\n16 2\n144 1\n"
] | none | 0 | [
{
"input": "3\n1 2 3\n1 2\n2 3",
"output": "1 4\n2 1\n3 1"
},
{
"input": "6\n1 2 4 8 16 32\n1 6\n6 3\n3 4\n4 2\n6 5",
"output": "1 6\n2 5\n4 6\n8 1\n16 2\n32 1"
},
{
"input": "4\n9 16 144 6\n1 3\n2 3\n4 3",
"output": "1 1\n2 1\n3 1\n6 2\n9 2\n16 2\n144 1"
},
{
"input": "3\n1 ... | 1,600,804,479 | 2,147,483,647 | PyPy 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | #include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
using ll=long long;
vector<int> d[maxn];
int cnt[maxn];
ll res[maxn];
int a[maxn];
int gcd(int a, int b) {
if (b==0) return a;
return gcd(b, a%b);
}
struct CentroidDecomposition {
vector<vector<int>> T;
vector<int> sz... | Title: GCD Counting
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a tree consisting of $n$ vertices. A number is written on each vertex; the number on vertex $i$ is equal to $a_i$.
Let's denote the function $g(x, y)$ as the greatest common divisor of the numbers written on... | ```python
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
using ll=long long;
vector<int> d[maxn];
int cnt[maxn];
ll res[maxn];
int a[maxn];
int gcd(int a, int b) {
if (b==0) return a;
return gcd(b, a%b);
}
struct CentroidDecomposition {
vector<vector<int>> T;
vect... | -1 | |
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,690,886,144 | 2,147,483,647 | Python 3 | OK | TESTS | 101 | 92 | 0 | line1 = input()
line2 = input()
numOfPeople = int(line1)
originalGifts = list(map(int, line2.split(' ')))
arrayGifts = originalGifts.copy()
def convert(list):
s = [str(i) for i in list]
res = " ".join(s)
return(res)
for i in range(numOfPeople):
arrayGifts[originalGifts[i] - 1] = i + 1
... | 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
line1 = input()
line2 = input()
numOfPeople = int(line1)
originalGifts = list(map(int, line2.split(' ')))
arrayGifts = originalGifts.copy()
def convert(list):
s = [str(i) for i in list]
res = " ".join(s)
return(res)
for i in range(numOfPeople):
arrayGifts[originalGifts[i] - 1... | 3 | |
1 | A | Theatre Square | PROGRAMMING | 1,000 | [
"math"
] | A. Theatre Square | 1 | 256 | Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size *a*<=×<=*a*.
What is the least number of flagstones needed to pave the... | The input contains three positive integer numbers in the first line: *n*,<=<=*m* and *a* (1<=≤<=<=*n*,<=*m*,<=*a*<=≤<=109). | Write the needed number of flagstones. | [
"6 6 4\n"
] | [
"4\n"
] | none | 0 | [
{
"input": "6 6 4",
"output": "4"
},
{
"input": "1 1 1",
"output": "1"
},
{
"input": "2 1 1",
"output": "2"
},
{
"input": "1 2 1",
"output": "2"
},
{
"input": "2 2 1",
"output": "4"
},
{
"input": "2 1 2",
"output": "1"
},
{
"input": "1 1 3"... | 1,663,414,317 | 2,147,483,647 | Python 3 | OK | TESTS | 20 | 46 | 0 | n,m,a=map(int,input().split())
if n%a==0:
w=n//a
else:
w=n//a+1
if m%a==0:
w*=m//a
else:
w*=m//a+1
print(w)
| Title: Theatre Square
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each ... | ```python
n,m,a=map(int,input().split())
if n%a==0:
w=n//a
else:
w=n//a+1
if m%a==0:
w*=m//a
else:
w*=m//a+1
print(w)
``` | 3.977 |
154 | A | Hometask | PROGRAMMING | 1,600 | [
"greedy"
] | null | null | Sergey attends lessons of the *N*-ish language. Each lesson he receives a hometask. This time the task is to translate some sentence to the *N*-ish language. Sentences of the *N*-ish language can be represented as strings consisting of lowercase Latin letters without spaces or punctuation marks.
Sergey totally forgot ... | The first line contains a non-empty string *s*, consisting of lowercase Latin letters — that's the initial sentence in *N*-ish, written by Sergey. The length of string *s* doesn't exceed 105.
The next line contains integer *k* (0<=≤<=*k*<=≤<=13) — the number of forbidden pairs of letters.
Next *k* lines contain descr... | Print the single number — the smallest number of letters that need to be removed to get a string without any forbidden pairs of neighboring letters. Please note that the answer always exists as it is always possible to remove all letters. | [
"ababa\n1\nab\n",
"codeforces\n2\ndo\ncs\n"
] | [
"2\n",
"1\n"
] | In the first sample you should remove two letters b.
In the second sample you should remove the second or the third letter. The second restriction doesn't influence the solution. | 500 | [
{
"input": "ababa\n1\nab",
"output": "2"
},
{
"input": "codeforces\n2\ndo\ncs",
"output": "1"
},
{
"input": "nllnrlrnll\n1\nrl",
"output": "1"
},
{
"input": "aludfbjtwnkgnfl\n1\noy",
"output": "0"
},
{
"input": "pgpgppgggpbbnnn\n2\npg\nnb",
"output": "7"
},
... | 1,491,200,199 | 2,147,483,647 | PyPy 3 | OK | TESTS | 42 | 1,058 | 102,092,800 | S = input()
M = int( input() )
banned = set( input() for i in range( M ) )
buff = set()
for s in banned:
if not ( s[ : : -1 ] in banned ):
buff.add( s[ : : -1 ] )
banned.update( buff )
dp = [ [ 1e9 for i in range( 26 ) ] for j in range( len( S ) + 1 ) ]
for i in range( 26 ):
dp[ 0 ][ i ] = 0
for ... | Title: Hometask
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Sergey attends lessons of the *N*-ish language. Each lesson he receives a hometask. This time the task is to translate some sentence to the *N*-ish language. Sentences of the *N*-ish language can be represented as strings cons... | ```python
S = input()
M = int( input() )
banned = set( input() for i in range( M ) )
buff = set()
for s in banned:
if not ( s[ : : -1 ] in banned ):
buff.add( s[ : : -1 ] )
banned.update( buff )
dp = [ [ 1e9 for i in range( 26 ) ] for j in range( len( S ) + 1 ) ]
for i in range( 26 ):
dp[ 0 ][ i ]... | 3 | |
514 | A | Chewbaсca and Number | PROGRAMMING | 1,200 | [
"greedy",
"implementation"
] | null | null | Luke Skywalker gave Chewbacca an integer number *x*. Chewbacca isn't good at numbers but he loves inverting digits in them. Inverting digit *t* means replacing it with digit 9<=-<=*t*.
Help Chewbacca to transform the initial number *x* to the minimum possible positive number by inverting some (possibly, zero) digits.... | The first line contains a single integer *x* (1<=≤<=*x*<=≤<=1018) — the number that Luke Skywalker gave to Chewbacca. | Print the minimum possible positive number that Chewbacca can obtain after inverting some digits. The number shouldn't contain leading zeroes. | [
"27\n",
"4545\n"
] | [
"22\n",
"4444\n"
] | none | 500 | [
{
"input": "27",
"output": "22"
},
{
"input": "4545",
"output": "4444"
},
{
"input": "1",
"output": "1"
},
{
"input": "9",
"output": "9"
},
{
"input": "8772",
"output": "1222"
},
{
"input": "81",
"output": "11"
},
{
"input": "71723447",
... | 1,699,269,819 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 31 | 0 |
s=input()
l=[]
for i in range(len(s)):
l.append(int(s[i]))
if(9-l[i]<l[i]):
l[i]=9-l[i]
s=0
j=1
for i in range(len(l)):
s+=l[len(l)-1]*j
j*=10
print(s)
| Title: Chewbaсca and Number
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Luke Skywalker gave Chewbacca an integer number *x*. Chewbacca isn't good at numbers but he loves inverting digits in them. Inverting digit *t* means replacing it with digit 9<=-<=*t*.
Help Chewbacca to transform... | ```python
s=input()
l=[]
for i in range(len(s)):
l.append(int(s[i]))
if(9-l[i]<l[i]):
l[i]=9-l[i]
s=0
j=1
for i in range(len(l)):
s+=l[len(l)-1]*j
j*=10
print(s)
``` | 0 | |
59 | A | Word | PROGRAMMING | 800 | [
"implementation",
"strings"
] | A. Word | 2 | 256 | Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At th... | The first line contains a word *s* — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100. | Print the corrected word *s*. If the given word *s* has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one. | [
"HoUse\n",
"ViP\n",
"maTRIx\n"
] | [
"house\n",
"VIP\n",
"matrix\n"
] | none | 500 | [
{
"input": "HoUse",
"output": "house"
},
{
"input": "ViP",
"output": "VIP"
},
{
"input": "maTRIx",
"output": "matrix"
},
{
"input": "BNHWpnpawg",
"output": "bnhwpnpawg"
},
{
"input": "VTYGP",
"output": "VTYGP"
},
{
"input": "CHNenu",
"output": "chn... | 1,695,441,244 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 92 | 0 | string = input() # get input from judge.
list = list(string) # convert string into a list
capList = [] # empty list for holding upper letters
lowList = [] # empty list for holding lower letters
for i in range(len(string)):
if list[i].isupper(): # if letter is capital, add to cap list.
capList.a... | Title: Word
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it ei... | ```python
string = input() # get input from judge.
list = list(string) # convert string into a list
capList = [] # empty list for holding upper letters
lowList = [] # empty list for holding lower letters
for i in range(len(string)):
if list[i].isupper(): # if letter is capital, add to cap list.
... | 3.977 |
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,552,206,600 | 2,147,483,647 | Python 3 | OK | TESTS | 83 | 218 | 307,200 | s = list(map(int, input().split(' ')))
if s[0] < s[1] + s[2] and s[1] < s[0] + s[2] and s[2] < s[0] + s[1] or s[0] < s[1] + s[3] and s[1] < s[0] + s[3] and s[3] < s[0] + s[1] or s[0] < s[2] + s[3] and s[2] < s[0] + s[3] and s[3] < s[0] + s[2] or s[1] < s[2] + s[3] and s[2] < s[1] + s[3] and s[3] < s[1] + s[2]:
pr... | 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
s = list(map(int, input().split(' ')))
if s[0] < s[1] + s[2] and s[1] < s[0] + s[2] and s[2] < s[0] + s[1] or s[0] < s[1] + s[3] and s[1] < s[0] + s[3] and s[3] < s[0] + s[1] or s[0] < s[2] + s[3] and s[2] < s[0] + s[3] and s[3] < s[0] + s[2] or s[1] < s[2] + s[3] and s[2] < s[1] + s[3] and s[3] < s[1] + s[2... | 3.943211 |
262 | B | Roma and Changing Signs | PROGRAMMING | 1,200 | [
"greedy"
] | null | null | Roma works in a company that sells TVs. Now he has to prepare a report for the last year.
Roma has got a list of the company's incomes. The list is a sequence that consists of *n* integers. The total income of the company is the sum of all integers in sequence. Roma decided to perform exactly *k* changes of signs of s... | The first line contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=105), showing, how many numbers are in the sequence and how many swaps are to be made.
The second line contains a non-decreasing sequence, consisting of *n* integers *a**i* (|*a**i*|<=≤<=104).
The numbers in the lines are separated by single spaces... | In the single line print the answer to the problem — the maximum total income that we can obtain after exactly *k* changes. | [
"3 2\n-1 -1 1\n",
"3 1\n-1 -1 1\n"
] | [
"3\n",
"1\n"
] | In the first sample we can get sequence [1, 1, 1], thus the total income equals 3.
In the second test, the optimal strategy is to get sequence [-1, 1, 1], thus the total income equals 1. | 1,000 | [
{
"input": "3 2\n-1 -1 1",
"output": "3"
},
{
"input": "3 1\n-1 -1 1",
"output": "1"
},
{
"input": "17 27\n257 320 676 1136 2068 2505 2639 4225 4951 5786 7677 7697 7851 8337 8429 8469 9343",
"output": "81852"
},
{
"input": "69 28\n-9822 -9264 -9253 -9221 -9139 -9126 -9096 -89... | 1,599,648,025 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 2 | 248 | 0 |
s1 = input()
b = s1.split()
n = int(b[0])
k = int(b[1])
a = list(map(int, input().split()))
a.sort()
for i in range(n):
if a[i] < 0:
a[i] *= -1
k -= 1
if k == 0:
break
print(sum(a)) | Title: Roma and Changing Signs
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Roma works in a company that sells TVs. Now he has to prepare a report for the last year.
Roma has got a list of the company's incomes. The list is a sequence that consists of *n* integers. The total income of ... | ```python
s1 = input()
b = s1.split()
n = int(b[0])
k = int(b[1])
a = list(map(int, input().split()))
a.sort()
for i in range(n):
if a[i] < 0:
a[i] *= -1
k -= 1
if k == 0:
break
print(sum(a))
``` | 0 | |
260 | A | Adding Digits | PROGRAMMING | 1,400 | [
"implementation",
"math"
] | null | null | Vasya has got two number: *a* and *b*. However, Vasya finds number *a* too short. So he decided to repeat the operation of lengthening number *a* *n* times.
One operation of lengthening a number means adding exactly one digit to the number (in the decimal notation) to the right provided that the resulting number is di... | The first line contains three integers: *a*,<=*b*,<=*n* (1<=≤<=*a*,<=*b*,<=*n*<=≤<=105). | In a single line print the integer without leading zeros, which Vasya can get when he applies the lengthening operations to number *a* *n* times. If no such number exists, then print number -1. If there are multiple possible answers, print any of them. | [
"5 4 5\n",
"12 11 1\n",
"260 150 10\n"
] | [
"524848\n",
"121\n",
"-1\n"
] | none | 500 | [
{
"input": "5 4 5",
"output": "524848"
},
{
"input": "12 11 1",
"output": "121"
},
{
"input": "260 150 10",
"output": "-1"
},
{
"input": "78843 5684 42717",
"output": "-1"
},
{
"input": "93248 91435 1133",
"output": "-1"
},
{
"input": "100000 10 64479"... | 1,607,004,396 | 2,147,483,647 | Python 3 | OK | TESTS | 25 | 108 | 204,800 | a,b,n = [int(x) for x in input().split()]
s = str(a)
check = 1
for i in range(10):
if int(s+str(i))%b==0:
s += str(i)
check = 0
break
if check:
print(-1)
else:
print(s+'0'*(n-1))
| Title: Adding Digits
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya has got two number: *a* and *b*. However, Vasya finds number *a* too short. So he decided to repeat the operation of lengthening number *a* *n* times.
One operation of lengthening a number means adding exactly one ... | ```python
a,b,n = [int(x) for x in input().split()]
s = str(a)
check = 1
for i in range(10):
if int(s+str(i))%b==0:
s += str(i)
check = 0
break
if check:
print(-1)
else:
print(s+'0'*(n-1))
``` | 3 | |
454 | A | Little Pony and Crystal Mine | PROGRAMMING | 800 | [
"implementation"
] | null | null | Twilight Sparkle once got a crystal from the Crystal Mine. A crystal of size *n* (*n* is odd; *n*<=><=1) is an *n*<=×<=*n* matrix with a diamond inscribed into it.
You are given an odd integer *n*. You need to draw a crystal of size *n*. The diamond cells of the matrix should be represented by character "D". All ot... | The only line contains an integer *n* (3<=≤<=*n*<=≤<=101; *n* is odd). | Output a crystal of size *n*. | [
"3\n",
"5\n",
"7\n"
] | [
"*D*\nDDD\n*D*\n",
"**D**\n*DDD*\nDDDDD\n*DDD*\n**D**\n",
"***D***\n**DDD**\n*DDDDD*\nDDDDDDD\n*DDDDD*\n**DDD**\n***D***\n"
] | none | 500 | [
{
"input": "3",
"output": "*D*\nDDD\n*D*"
},
{
"input": "5",
"output": "**D**\n*DDD*\nDDDDD\n*DDD*\n**D**"
},
{
"input": "7",
"output": "***D***\n**DDD**\n*DDDDD*\nDDDDDDD\n*DDDDD*\n**DDD**\n***D***"
},
{
"input": "11",
"output": "*****D*****\n****DDD****\n***DDDDD***\n**... | 1,611,089,702 | 2,147,483,647 | Python 3 | OK | TESTS | 12 | 62 | 0 | line = int(input())
mid_pt = (line+1)//2
for i in range(1,line+1):
if i<mid_pt:
print("*"*(mid_pt-i)+"D"*(2*i-1)+"*"*(mid_pt-i))
else:
print("*"*(i-mid_pt)+"D"*(2*(line+1-i)-1)+"*"*(i-mid_pt)) | Title: Little Pony and Crystal Mine
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Twilight Sparkle once got a crystal from the Crystal Mine. A crystal of size *n* (*n* is odd; *n*<=><=1) is an *n*<=×<=*n* matrix with a diamond inscribed into it.
You are given an odd integer *n*. You ... | ```python
line = int(input())
mid_pt = (line+1)//2
for i in range(1,line+1):
if i<mid_pt:
print("*"*(mid_pt-i)+"D"*(2*i-1)+"*"*(mid_pt-i))
else:
print("*"*(i-mid_pt)+"D"*(2*(line+1-i)-1)+"*"*(i-mid_pt))
``` | 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.