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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
99 | A | Help Far Away Kingdom | PROGRAMMING | 800 | [
"strings"
] | A. Help Far Away Kingdom | 2 | 256 | In a far away kingdom lived the King, the Prince, the Shoemaker, the Dressmaker and many other citizens. They lived happily until great trouble came into the Kingdom. The ACMers settled there.
Most damage those strange creatures inflicted upon the kingdom was that they loved high precision numbers. As a result, the Ki... | The first line contains a single number to round up — the integer part (a non-empty set of decimal digits that do not start with 0 — with the exception of a case when the set consists of a single digit — in this case 0 can go first), then follows character «.» (a dot), and then follows the fractional part (any non-empt... | If the last number of the integer part is not equal to 9, print the rounded-up number without leading zeroes. Otherwise, print the message "GOTO Vasilisa." (without the quotes). | [
"0.0\n",
"1.49\n",
"1.50\n",
"2.71828182845904523536\n",
"3.14159265358979323846\n",
"12345678901234567890.1\n",
"123456789123456789.999\n"
] | [
"0",
"1",
"2",
"3",
"3",
"12345678901234567890",
"GOTO Vasilisa."
] | none | 500 | [
{
"input": "0.0",
"output": "0"
},
{
"input": "1.49",
"output": "1"
},
{
"input": "1.50",
"output": "2"
},
{
"input": "2.71828182845904523536",
"output": "3"
},
{
"input": "3.14159265358979323846",
"output": "3"
},
{
"input": "12345678901234567890.1",
... | 1,620,581,693 | 2,147,483,647 | PyPy 3 | OK | TESTS | 150 | 248 | 20,172,800 | n = input().split(".")
if n[0][-1] != '9' and int(n[1][0]) < 5:
print(n[0])
elif n[0][-1] != '9' and int(n[1][0]) >= 5:
print(int(n[0]) + 1)
else :
print("GOTO Vasilisa.")
| Title: Help Far Away Kingdom
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
In a far away kingdom lived the King, the Prince, the Shoemaker, the Dressmaker and many other citizens. They lived happily until great trouble came into the Kingdom. The ACMers settled there.
Most damage those stran... | ```python
n = input().split(".")
if n[0][-1] != '9' and int(n[1][0]) < 5:
print(n[0])
elif n[0][-1] != '9' and int(n[1][0]) >= 5:
print(int(n[0]) + 1)
else :
print("GOTO Vasilisa.")
``` | 3.900425 |
432 | A | Choosing Teams | PROGRAMMING | 800 | [
"greedy",
"implementation",
"sortings"
] | null | null | The Saratov State University Olympiad Programmers Training Center (SSU OPTC) has *n* students. For each student you know the number of times he/she has participated in the ACM ICPC world programming championship. According to the ACM ICPC rules, each person can participate in the world championship at most 5 times.
Th... | The first line contains two integers, *n* and *k* (1<=≤<=*n*<=≤<=2000; 1<=≤<=*k*<=≤<=5). The next line contains *n* integers: *y*1,<=*y*2,<=...,<=*y**n* (0<=≤<=*y**i*<=≤<=5), where *y**i* shows the number of times the *i*-th person participated in the ACM ICPC world championship. | Print a single number — the answer to the problem. | [
"5 2\n0 4 5 1 0\n",
"6 4\n0 1 2 3 4 5\n",
"6 5\n0 0 0 0 0 0\n"
] | [
"1\n",
"0\n",
"2\n"
] | In the first sample only one team could be made: the first, the fourth and the fifth participants.
In the second sample no teams could be created.
In the third sample two teams could be created. Any partition into two teams fits. | 500 | [
{
"input": "5 2\n0 4 5 1 0",
"output": "1"
},
{
"input": "6 4\n0 1 2 3 4 5",
"output": "0"
},
{
"input": "6 5\n0 0 0 0 0 0",
"output": "2"
},
{
"input": "3 4\n0 1 0",
"output": "1"
},
{
"input": "3 4\n0 2 0",
"output": "0"
},
{
"input": "6 5\n0 0 0 0 0... | 1,684,330,108 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 6 | 31 | 0 | tm = list(map(int, input().split()))
n, k = tm[0], tm[1]
x = sorted(list(map(int, input().split())))
it = 0
for i in range(n // 3):
n1, n2, n3 = x[i], x[i+1], x[i+2]
mx = max(n1, n2, n3)
if 5 - mx >= k:
it += 1
print(it) | Title: Choosing Teams
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Saratov State University Olympiad Programmers Training Center (SSU OPTC) has *n* students. For each student you know the number of times he/she has participated in the ACM ICPC world programming championship. Accordi... | ```python
tm = list(map(int, input().split()))
n, k = tm[0], tm[1]
x = sorted(list(map(int, input().split())))
it = 0
for i in range(n // 3):
n1, n2, n3 = x[i], x[i+1], x[i+2]
mx = max(n1, n2, n3)
if 5 - mx >= k:
it += 1
print(it)
``` | 0 | |
102 | B | Sum of Digits | PROGRAMMING | 1,000 | [
"implementation"
] | B. Sum of Digits | 2 | 265 | Having watched the last Harry Potter film, little Gerald also decided to practice magic. He found in his father's magical book a spell that turns any number in the sum of its digits. At the moment Gerald learned that, he came across a number *n*. How many times can Gerald put a spell on it until the number becomes one-... | The first line contains the only integer *n* (0<=≤<=*n*<=≤<=10100000). It is guaranteed that *n* doesn't contain any leading zeroes. | Print the number of times a number can be replaced by the sum of its digits until it only contains one digit. | [
"0\n",
"10\n",
"991\n"
] | [
"0\n",
"1\n",
"3\n"
] | In the first sample the number already is one-digit — Herald can't cast a spell.
The second test contains number 10. After one casting of a spell it becomes 1, and here the process is completed. Thus, Gerald can only cast the spell once.
The third test contains number 991. As one casts a spell the following transform... | 1,000 | [
{
"input": "0",
"output": "0"
},
{
"input": "10",
"output": "1"
},
{
"input": "991",
"output": "3"
},
{
"input": "99",
"output": "2"
},
{
"input": "100",
"output": "1"
},
{
"input": "123456789",
"output": "2"
},
{
"input": "32",
"output... | 1,642,284,826 | 2,147,483,647 | PyPy 3 | MEMORY_LIMIT_EXCEEDED | TESTS | 0 | 124 | 277,913,600 | import sys
sys.setrecursionlimit(10**6)
n = int(input())
cnt = 0
while len(str(n)) != 1:
n = sum(map(int, list(str(n))))
cnt += 1
print(cnt)
| Title: Sum of Digits
Time Limit: 2 seconds
Memory Limit: 265 megabytes
Problem Description:
Having watched the last Harry Potter film, little Gerald also decided to practice magic. He found in his father's magical book a spell that turns any number in the sum of its digits. At the moment Gerald learned that, he came... | ```python
import sys
sys.setrecursionlimit(10**6)
n = int(input())
cnt = 0
while len(str(n)) != 1:
n = sum(map(int, list(str(n))))
cnt += 1
print(cnt)
``` | 0 |
0 | none | none | none | 0 | [
"none"
] | null | null | Throughout Igor K.'s life he has had many situations worthy of attention. We remember the story with the virus, the story of his mathematical career and of course, his famous programming achievements. However, one does not always adopt new hobbies, one can quit something as well.
This time Igor K. got disappointed in ... | The only line contains four integers *n*, *m*, *a*, *b* (1<=≤<=*n*,<=*m*<=≤<=109, 1<=≤<=*a*<=≤<=*b*<=≤<=*n*). They are the number of folders in Igor K.'s computer, the width of a window and the numbers of the first and the last folders that need to be deleted. | Print a single number: the least possible number of times Igor K. will have to select the folders using frames to select only the folders with numbers from *a* to *b*. | [
"11 4 3 9\n",
"20 5 2 20\n"
] | [
"3\n",
"2\n"
] | The images below illustrate statement tests.
The first test:
<img class="tex-graphics" src="https://espresso.codeforces.com/a0e4ba690dd16e3c68210a28afd82020b23fb605.png" style="max-width: 100.0%;max-height: 100.0%;"/>
In this test we can select folders 3 and 4 with out first selection, folders 5, 6, 7, 8 with our se... | 0 | [
{
"input": "11 4 3 9",
"output": "3"
},
{
"input": "20 5 2 20",
"output": "2"
},
{
"input": "1 1 1 1",
"output": "1"
},
{
"input": "26 5 2 18",
"output": "3"
},
{
"input": "21 5 1 15",
"output": "1"
},
{
"input": "21 5 1 21",
"output": "1"
},
{... | 1,507,291,481 | 4,181 | Python 3 | WRONG_ANSWER | TESTS | 0 | 60 | 0 | def main():
n = list(map(int, (input().strip().split())))
n, m, a, b = tuple(n)
count = 0
minimum = m
maximum = n + 1
for i in range(m, n, m):
if a > i:
maximum = min(maximum, i)
if b < i:
minimum = max(minimum, i)
i += 1
if (maximum - 1) % m == 0:
maximum -= 1
while maximum % m != 0... | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Throughout Igor K.'s life he has had many situations worthy of attention. We remember the story with the virus, the story of his mathematical career and of course, his famous programming achievements. However, one does not always ... | ```python
def main():
n = list(map(int, (input().strip().split())))
n, m, a, b = tuple(n)
count = 0
minimum = m
maximum = n + 1
for i in range(m, n, m):
if a > i:
maximum = min(maximum, i)
if b < i:
minimum = max(minimum, i)
i += 1
if (maximum - 1) % m == 0:
maximum -= 1
while maximu... | 0 | |
252 | B | Unsorting Array | PROGRAMMING | 1,800 | [
"brute force",
"sortings"
] | null | null | Little Petya likes arrays of integers a lot. Recently his mother has presented him one such array consisting of *n* elements. Petya is now wondering whether he can swap any two distinct integers in the array so that the array got unsorted. Please note that Petya can not swap equal integers even if they are in distinct ... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105). The second line contains *n* non-negative space-separated integers *a*1,<=*a*2,<=...,<=*a**n* — the elements of the array that Petya's mother presented him. All integers in the input do not exceed 109. | If there is a pair of positions that make the array unsorted if swapped, then print the numbers of these positions separated by a space. If there are several pairs of positions, print any of them. If such pair does not exist, print -1. The positions in the array are numbered with integers from 1 to *n*. | [
"1\n1\n",
"2\n1 2\n",
"4\n1 2 3 4\n",
"3\n1 1 1\n"
] | [
"-1\n",
"-1\n",
"1 2\n",
"-1\n"
] | In the first two samples the required pairs obviously don't exist.
In the third sample you can swap the first two elements. After that the array will look like this: 2 1 3 4. This array is unsorted. | 1,000 | [
{
"input": "1\n1",
"output": "-1"
},
{
"input": "2\n1 2",
"output": "-1"
},
{
"input": "4\n1 2 3 4",
"output": "1 2"
},
{
"input": "3\n1 1 1",
"output": "-1"
},
{
"input": "3\n1 2 2",
"output": "1 2"
},
{
"input": "5\n1 1 1 1 2",
"output": "2 5"
... | 1,663,831,517 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 5 | 62 | 0 | b = int(input())
M = list(map(int, input().split(' ')))
s = []
mamad = False
if M[0] > M[b - 1]:
for i in range(1, b - 1):
if M[0] > M[i]:
s.append(1)
s.append(i + 1)
mamad = True
break
if mamad:
print(s[0], end=' ')
print(s[1]... | Title: Unsorting Array
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Petya likes arrays of integers a lot. Recently his mother has presented him one such array consisting of *n* elements. Petya is now wondering whether he can swap any two distinct integers in the array so that the... | ```python
b = int(input())
M = list(map(int, input().split(' ')))
s = []
mamad = False
if M[0] > M[b - 1]:
for i in range(1, b - 1):
if M[0] > M[i]:
s.append(1)
s.append(i + 1)
mamad = True
break
if mamad:
print(s[0], end=' ')
... | 0 | |
960 | D | Full Binary Tree Queries | PROGRAMMING | 2,100 | [
"brute force",
"implementation",
"trees"
] | null | null | You have a full binary tree having infinite levels.
Each node has an initial value. If a node has value *x*, then its left child has value 2·*x* and its right child has value 2·*x*<=+<=1.
The value of the root is 1.
You need to answer *Q* queries.
There are 3 types of queries:
1. Cyclically shift the values of... | The first line contains a single integer *Q* (1<=≤<=*Q*<=≤<=105).
Then *Q* queries follow, one per line:
- Queries of type 1 and 2 have the following format: *T* *X* *K* (1<=≤<=*T*<=≤<=2; 1<=≤<=*X*<=≤<=1018; 0<=≤<=|*K*|<=≤<=1018), where *T* is type of the query.- Queries of type 3 have the following format: 3 *X* (... | For each query of type 3, print the values of all nodes encountered in descending order. | [
"5\n3 12\n1 2 1\n3 12\n2 4 -1\n3 8\n",
"5\n3 14\n1 5 -3\n3 14\n1 3 1\n3 14\n"
] | [
"12 6 3 1 \n12 6 2 1 \n8 4 2 1 \n",
"14 7 3 1 \n14 6 3 1 \n14 6 2 1 \n"
] | Following are the images of the first 4 levels of the tree in the first test case:
Original:
After query 1 2 1:
After query 2 4 -1: | 2,000 | [
{
"input": "5\n3 12\n1 2 1\n3 12\n2 4 -1\n3 8",
"output": "12 6 3 1 \n12 6 2 1 \n8 4 2 1 "
},
{
"input": "5\n3 14\n1 5 -3\n3 14\n1 3 1\n3 14",
"output": "14 7 3 1 \n14 6 3 1 \n14 6 2 1 "
},
{
"input": "6\n3 1\n2 1 0\n3 10\n2 1 -4\n3 10\n2 10 -5",
"output": "1 \n10 5 2 1 \n10 5 2 1 "
... | 1,523,130,364 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 7 | 4,000 | 29,798,400 | q = int(input())
op1 = [0 for x in range(100)]
def pw(n,k):
s = 1
for x in range(k):
s *= n
return int(s)
def getlvl(X):
start = 1
end = 2
level = 0
while not (start <= X and X < end):
start *= 2
end *= 2
level += 1
return level
def mod(n,m):
lo =... | Title: Full Binary Tree Queries
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You have a full binary tree having infinite levels.
Each node has an initial value. If a node has value *x*, then its left child has value 2·*x* and its right child has value 2·*x*<=+<=1.
The value of the ro... | ```python
q = int(input())
op1 = [0 for x in range(100)]
def pw(n,k):
s = 1
for x in range(k):
s *= n
return int(s)
def getlvl(X):
start = 1
end = 2
level = 0
while not (start <= X and X < end):
start *= 2
end *= 2
level += 1
return level
def mod(n,m)... | 0 | |
1 | A | Theatre Square | PROGRAMMING | 1,000 | [
"math"
] | A. Theatre Square | 1 | 256 | Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size *a*<=×<=*a*.
What is the least number of flagstones needed to pave the... | The input contains three positive integer numbers in the first line: *n*,<=<=*m* and *a* (1<=≤<=<=*n*,<=*m*,<=*a*<=≤<=109). | Write the needed number of flagstones. | [
"6 6 4\n"
] | [
"4\n"
] | none | 0 | [
{
"input": "6 6 4",
"output": "4"
},
{
"input": "1 1 1",
"output": "1"
},
{
"input": "2 1 1",
"output": "2"
},
{
"input": "1 2 1",
"output": "2"
},
{
"input": "2 2 1",
"output": "4"
},
{
"input": "2 1 2",
"output": "1"
},
{
"input": "1 1 3"... | 1,668,143,785 | 2,147,483,647 | Python 3 | OK | TESTS | 20 | 46 | 0 | n,m,a=map(int, input().split())
if n%a==0 and m%a==0:print((n//a)*(m//a))
elif n%a==0:print((n//a)*(m//a+1))
elif m%a==0:print((n//a+1)*(m//a))
else:print((n//a+1)*(m//a+1)) | 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 and m%a==0:print((n//a)*(m//a))
elif n%a==0:print((n//a)*(m//a+1))
elif m%a==0:print((n//a+1)*(m//a))
else:print((n//a+1)*(m//a+1))
``` | 3.977 |
312 | B | Archer | PROGRAMMING | 1,300 | [
"math",
"probabilities"
] | null | null | SmallR is an archer. SmallR is taking a match of archer with Zanoes. They try to shoot in the target in turns, and SmallR shoots first. The probability of shooting the target each time is for SmallR while for Zanoes. The one who shoots in the target first should be the winner.
Output the probability that SmallR will... | A single line contains four integers . | Print a single real number, the probability that SmallR will win the match.
The answer will be considered correct if the absolute or relative error doesn't exceed 10<=-<=6. | [
"1 2 1 2\n"
] | [
"0.666666666667"
] | none | 1,000 | [
{
"input": "1 2 1 2",
"output": "0.666666666667"
},
{
"input": "1 3 1 3",
"output": "0.600000000000"
},
{
"input": "1 3 2 3",
"output": "0.428571428571"
},
{
"input": "3 4 3 4",
"output": "0.800000000000"
},
{
"input": "1 2 10 11",
"output": "0.523809523810"
... | 1,593,332,019 | 2,147,483,647 | Python 3 | OK | TESTS | 31 | 109 | 6,656,000 | a,b,c,d = map(int,input().split())
x = a*d
y = a*d + b*c - a*c
print(x/y) | Title: Archer
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
SmallR is an archer. SmallR is taking a match of archer with Zanoes. They try to shoot in the target in turns, and SmallR shoots first. The probability of shooting the target each time is for SmallR while for Zanoes. The one w... | ```python
a,b,c,d = map(int,input().split())
x = a*d
y = a*d + b*c - a*c
print(x/y)
``` | 3 | |
535 | B | Tavas and SaDDas | PROGRAMMING | 1,100 | [
"bitmasks",
"brute force",
"combinatorics",
"implementation"
] | null | null | Once again Tavas started eating coffee mix without water! Keione told him that it smells awful, but he didn't stop doing that. That's why Keione told his smart friend, SaDDas to punish him! SaDDas took Tavas' headphones and told him: "If you solve the following problem, I'll return it to you."
The problem is:
You ar... | The first and only line of input contains a lucky number *n* (1<=≤<=*n*<=≤<=109). | Print the index of *n* among all lucky numbers. | [
"4\n",
"7\n",
"77\n"
] | [
"1\n",
"2\n",
"6\n"
] | none | 1,000 | [
{
"input": "4",
"output": "1"
},
{
"input": "7",
"output": "2"
},
{
"input": "77",
"output": "6"
},
{
"input": "4",
"output": "1"
},
{
"input": "474744",
"output": "83"
},
{
"input": "777774",
"output": "125"
},
{
"input": "447",
"outpu... | 1,596,890,294 | 2,147,483,647 | PyPy 3 | OK | TESTS | 33 | 155 | 22,016,000 | #Anuneet Anand
n = input()
x = len(n)-1
y = len(n)
a = 2 * (2**x-1)
Z = []
for i in range(2**y):
b = bin(i)[2:]
b = "0"*(y-len(b))+b
t = ""
for j in range(y):
if b[j]=="1":
t = t + "4"
else:
t = t + "7"
Z.append(t)
Z.sort()
for i in range(len(Z)):
if Z[i]==n:
print(a+i+1)
... | Title: Tavas and SaDDas
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Once again Tavas started eating coffee mix without water! Keione told him that it smells awful, but he didn't stop doing that. That's why Keione told his smart friend, SaDDas to punish him! SaDDas took Tavas' headphone... | ```python
#Anuneet Anand
n = input()
x = len(n)-1
y = len(n)
a = 2 * (2**x-1)
Z = []
for i in range(2**y):
b = bin(i)[2:]
b = "0"*(y-len(b))+b
t = ""
for j in range(y):
if b[j]=="1":
t = t + "4"
else:
t = t + "7"
Z.append(t)
Z.sort()
for i in range(len(Z)):
if Z[i]==n:
prin... | 3 | |
106 | C | Buns | PROGRAMMING | 1,700 | [
"dp"
] | C. Buns | 2 | 256 | Lavrenty, a baker, is going to make several buns with stuffings and sell them.
Lavrenty has *n* grams of dough as well as *m* different stuffing types. The stuffing types are numerated from 1 to *m*. Lavrenty knows that he has *a**i* grams left of the *i*-th stuffing. It takes exactly *b**i* grams of stuffing *i* and ... | The first line contains 4 integers *n*, *m*, *c*0 and *d*0 (1<=≤<=*n*<=≤<=1000, 1<=≤<=*m*<=≤<=10, 1<=≤<=*c*0,<=*d*0<=≤<=100). Each of the following *m* lines contains 4 integers. The *i*-th line contains numbers *a**i*, *b**i*, *c**i* and *d**i* (1<=≤<=*a**i*,<=*b**i*,<=*c**i*,<=*d**i*<=≤<=100). | Print the only number — the maximum number of tugriks Lavrenty can earn. | [
"10 2 2 1\n7 3 2 100\n12 3 1 10\n",
"100 1 25 50\n15 5 20 10\n"
] | [
"241",
"200"
] | To get the maximum number of tugriks in the first sample, you need to cook 2 buns with stuffing 1, 4 buns with stuffing 2 and a bun without any stuffing.
In the second sample Lavrenty should cook 4 buns without stuffings. | 1,500 | [
{
"input": "10 2 2 1\n7 3 2 100\n12 3 1 10",
"output": "241"
},
{
"input": "100 1 25 50\n15 5 20 10",
"output": "200"
},
{
"input": "10 1 5 2\n100 1 2 3",
"output": "15"
},
{
"input": "10 1 5 11\n3 1 3 8",
"output": "24"
},
{
"input": "10 2 11 5\n100 1 3 10\n100 1... | 1,644,066,178 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 9 | 654 | 37,068,800 | import math
import sys
import queue
import itertools
from heapq import heappop, heappush
import random
mod = 1000000007
def solve():
n, m, c0, d0 = map(int, input().split())
f = []
order = [list(i) for i in itertools.permutations([j for j in range(m + 1)], m + 1)]
for i in range(m):... | Title: Buns
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Lavrenty, a baker, is going to make several buns with stuffings and sell them.
Lavrenty has *n* grams of dough as well as *m* different stuffing types. The stuffing types are numerated from 1 to *m*. Lavrenty knows that he has *a**i*... | ```python
import math
import sys
import queue
import itertools
from heapq import heappop, heappush
import random
mod = 1000000007
def solve():
n, m, c0, d0 = map(int, input().split())
f = []
order = [list(i) for i in itertools.permutations([j for j in range(m + 1)], m + 1)]
for i in... | 0 |
960 | A | Check the string | PROGRAMMING | 1,200 | [
"implementation"
] | null | null | A has a string consisting of some number of lowercase English letters 'a'. He gives it to his friend B who appends some number of letters 'b' to the end of this string. Since both A and B like the characters 'a' and 'b', they have made sure that at this point, at least one 'a' and one 'b' exist in the string.
B now gi... | The first and only line consists of a string $S$ ($ 1 \le |S| \le 5\,000 $). It is guaranteed that the string will only consist of the lowercase English letters 'a', 'b', 'c'. | Print "YES" or "NO", according to the condition. | [
"aaabccc\n",
"bbacc\n",
"aabc\n"
] | [
"YES\n",
"NO\n",
"YES\n"
] | Consider first example: the number of 'c' is equal to the number of 'a'.
Consider second example: although the number of 'c' is equal to the number of the 'b', the order is not correct.
Consider third example: the number of 'c' is equal to the number of 'b'. | 500 | [
{
"input": "aaabccc",
"output": "YES"
},
{
"input": "bbacc",
"output": "NO"
},
{
"input": "aabc",
"output": "YES"
},
{
"input": "aabbcc",
"output": "YES"
},
{
"input": "aaacccbb",
"output": "NO"
},
{
"input": "abc",
"output": "YES"
},
{
"in... | 1,638,344,805 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 55 | 62 | 614,400 | s=input()
ar=list(s)
p=0
if(ar!=sorted(ar)):
print("NO")
else:
if(("a" in s) and ("b" in s) and ("c" in s)):
if(ar.count("c")==ar.count("a") or ar.count("c")==ar.count("b")):
print("YES")
else:
print("NO")
else:
print("NO")
| Title: Check the string
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A has a string consisting of some number of lowercase English letters 'a'. He gives it to his friend B who appends some number of letters 'b' to the end of this string. Since both A and B like the characters 'a' and 'b... | ```python
s=input()
ar=list(s)
p=0
if(ar!=sorted(ar)):
print("NO")
else:
if(("a" in s) and ("b" in s) and ("c" in s)):
if(ar.count("c")==ar.count("a") or ar.count("c")==ar.count("b")):
print("YES")
else:
print("NO")
else:
print("NO")
``` | 3 | |
32 | C | Flea | PROGRAMMING | 1,700 | [
"math"
] | C. Flea | 2 | 256 | It is known that fleas in Berland can jump only vertically and horizontally, and the length of the jump is always equal to *s* centimeters. A flea has found herself at the center of some cell of the checked board of the size *n*<=×<=*m* centimeters (each cell is 1<=×<=1 centimeters). She can jump as she wishes for an a... | The first line contains three integers *n*, *m*, *s* (1<=≤<=*n*,<=*m*,<=*s*<=≤<=106) — length of the board, width of the board and length of the flea's jump. | Output the only integer — the number of the required starting positions of the flea. | [
"2 3 1000000\n",
"3 3 2\n"
] | [
"6\n",
"4\n"
] | none | 1,500 | [
{
"input": "2 3 1000000",
"output": "6"
},
{
"input": "3 3 2",
"output": "4"
},
{
"input": "1 2 3",
"output": "2"
},
{
"input": "4 5 6",
"output": "20"
},
{
"input": "9 8 7",
"output": "8"
},
{
"input": "1000 1000 1000",
"output": "1000000"
},
... | 1,580,101,891 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 218 | 307,200 | n,m,s=[int(s) for s in input().split()]
a=(n % s)
b=(m % s)
if a==0 and n>=s:a=s
if b==0 and m>=s:b=s
unit=(a*b)
print(((n-1)//s+1)*((m-1)//s+1)*unit)
| Title: Flea
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
It is known that fleas in Berland can jump only vertically and horizontally, and the length of the jump is always equal to *s* centimeters. A flea has found herself at the center of some cell of the checked board of the size *n*<=×<=*... | ```python
n,m,s=[int(s) for s in input().split()]
a=(n % s)
b=(m % s)
if a==0 and n>=s:a=s
if b==0 and m>=s:b=s
unit=(a*b)
print(((n-1)//s+1)*((m-1)//s+1)*unit)
``` | 3.944928 |
75 | A | Life Without Zeros | PROGRAMMING | 1,000 | [
"implementation"
] | A. Life Without Zeros | 2 | 256 | Can you imagine our life if we removed all zeros from it? For sure we will have many problems.
In this problem we will have a simple example if we removed all zeros from our life, it's the addition operation. Let's assume you are given this equation *a*<=+<=*b*<==<=*c*, where *a* and *b* are positive integers, and *c*... | The input will consist of two lines, the first line will contain the integer *a*, and the second line will contain the integer *b* which are in the equation as described above (1<=≤<=*a*,<=*b*<=≤<=109). There won't be any leading zeros in both. The value of *c* should be calculated as *c*<==<=*a*<=+<=*b*. | The output will be just one line, you should print "YES" if the equation will remain correct after removing all zeros, and print "NO" otherwise. | [
"101\n102\n",
"105\n106\n"
] | [
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "101\n102",
"output": "YES"
},
{
"input": "105\n106",
"output": "NO"
},
{
"input": "544\n397",
"output": "YES"
},
{
"input": "822\n280",
"output": "NO"
},
{
"input": "101\n413",
"output": "NO"
},
{
"input": "309\n139",
"output": "NO"
}... | 1,680,578,791 | 2,147,483,647 | Python 3 | OK | TESTS | 43 | 124 | 0 | a = int(input())
b = int(input())
c = a + b
rem_a = int(''.join(c for c in str(a) if c != '0'))
rem_b = int(''.join(c for c in str(b) if c != '0'))
rem_c = int(''.join(c for c in str(c) if c != '0'))
if rem_a + rem_b == rem_c:
print("YES")
else:
print("NO") | Title: Life Without Zeros
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Can you imagine our life if we removed all zeros from it? For sure we will have many problems.
In this problem we will have a simple example if we removed all zeros from our life, it's the addition operation. Let's assu... | ```python
a = int(input())
b = int(input())
c = a + b
rem_a = int(''.join(c for c in str(a) if c != '0'))
rem_b = int(''.join(c for c in str(b) if c != '0'))
rem_c = int(''.join(c for c in str(c) if c != '0'))
if rem_a + rem_b == rem_c:
print("YES")
else:
print("NO")
``` | 3.969 |
801 | B | Valued Keys | PROGRAMMING | 900 | [
"constructive algorithms",
"greedy",
"strings"
] | null | null | You found a mysterious function *f*. The function takes two strings *s*1 and *s*2. These strings must consist only of lowercase English letters, and must be the same length.
The output of the function *f* is another string of the same length. The *i*-th character of the output is equal to the minimum of the *i*-th cha... | The first line of input contains the string *x*.
The second line of input contains the string *y*.
Both *x* and *y* consist only of lowercase English letters, *x* and *y* have same length and this length is between 1 and 100. | If there is no string *z* such that *f*(*x*,<=*z*)<==<=*y*, print -1.
Otherwise, print a string *z* such that *f*(*x*,<=*z*)<==<=*y*. If there are multiple possible answers, print any of them. The string *z* should be the same length as *x* and *y* and consist only of lowercase English letters. | [
"ab\naa\n",
"nzwzl\nniwel\n",
"ab\nba\n"
] | [
"ba\n",
"xiyez\n",
"-1\n"
] | The first case is from the statement.
Another solution for the second case is "zizez"
There is no solution for the third case. That is, there is no *z* such that *f*("ab", *z*) = "ba". | 1,000 | [
{
"input": "ab\naa",
"output": "ba"
},
{
"input": "nzwzl\nniwel",
"output": "xiyez"
},
{
"input": "ab\nba",
"output": "-1"
},
{
"input": "r\nl",
"output": "l"
},
{
"input": "d\ny",
"output": "-1"
},
{
"input": "yvowz\ncajav",
"output": "cajav"
},... | 1,492,357,488 | 588 | Python 3 | OK | TESTS | 35 | 61 | 5,529,600 | x=str(input())
y=str(input())
ans=''
b=0
for i in range(len(x)):
if y[i]>x[i]:
b=1
break
elif y[i]==x[i]:
ans+=x[i]
else:
ans+=y[i]
if b==0:
print(ans)
else:
print(-1)
| Title: Valued Keys
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You found a mysterious function *f*. The function takes two strings *s*1 and *s*2. These strings must consist only of lowercase English letters, and must be the same length.
The output of the function *f* is another string... | ```python
x=str(input())
y=str(input())
ans=''
b=0
for i in range(len(x)):
if y[i]>x[i]:
b=1
break
elif y[i]==x[i]:
ans+=x[i]
else:
ans+=y[i]
if b==0:
print(ans)
else:
print(-1)
``` | 3 | |
152 | C | Pocket Book | PROGRAMMING | 1,400 | [
"combinatorics"
] | null | null | One day little Vasya found mom's pocket book. The book had *n* names of her friends and unusually enough, each name was exactly *m* letters long. Let's number the names from 1 to *n* in the order in which they are written.
As mom wasn't home, Vasya decided to play with names: he chose three integers *i*, *j*, *k* (1<=... | The first input line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of names and the length of each name, correspondingly. Then *n* lines contain names, each name consists of exactly *m* uppercase Latin letters. | Print the single number — the number of different names that could end up in position number 1 in the pocket book after the applying the procedures described above. Print the number modulo 1000000007 (109<=+<=7). | [
"2 3\nAAB\nBAA\n",
"4 5\nABABA\nBCGDG\nAAAAA\nYABSA\n"
] | [
"4\n",
"216\n"
] | In the first sample Vasya can get the following names in the position number 1: "AAB", "AAA", "BAA" and "BAB". | 1,500 | [
{
"input": "2 3\nAAB\nBAA",
"output": "4"
},
{
"input": "4 5\nABABA\nBCGDG\nAAAAA\nYABSA",
"output": "216"
},
{
"input": "1 1\nE",
"output": "1"
},
{
"input": "2 2\nNS\nPD",
"output": "4"
},
{
"input": "3 4\nPJKD\nNFJX\nFGFK",
"output": "81"
},
{
"inpu... | 1,598,430,046 | 2,147,483,647 | PyPy 3 | OK | TESTS | 60 | 310 | 1,433,600 | n,m = [int(x) for x in input().split()]
arr = []
for i in range(n):
arr.append(str(input()))
ans = 1
for i in range(m):
hm = []
now = 0
for j in range(n):
if not arr[j][i] in hm:
hm.append(arr[j][i])
now+=1
ans = (ans*now)%1000000007
print(ans) | Title: Pocket Book
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day little Vasya found mom's pocket book. The book had *n* names of her friends and unusually enough, each name was exactly *m* letters long. Let's number the names from 1 to *n* in the order in which they are written.
... | ```python
n,m = [int(x) for x in input().split()]
arr = []
for i in range(n):
arr.append(str(input()))
ans = 1
for i in range(m):
hm = []
now = 0
for j in range(n):
if not arr[j][i] in hm:
hm.append(arr[j][i])
now+=1
ans = (ans*now)%1000000007
print(ans)
``` | 3 | |
84 | A | Toy Army | PROGRAMMING | 900 | [
"math",
"number theory"
] | A. Toy Army | 2 | 256 | The hero of our story, Valera, and his best friend Arcady are still in school, and therefore they spend all the free time playing turn-based strategy "GAGA: Go And Go Again". The gameplay is as follows.
There are two armies on the playing field each of which consists of *n* men (*n* is always even). The current playe... | The input data consist of a single integer *n* (2<=≤<=*n*<=≤<=108, *n* is even). Please note that before the game starts there are 2*n* soldiers on the fields. | Print a single number — a maximum total number of soldiers that could be killed in the course of the game in three turns. | [
"2\n",
"4\n"
] | [
"3\n",
"6\n"
] | The first sample test:
1) Valera's soldiers 1 and 2 shoot at Arcady's soldier 1.
2) Arcady's soldier 2 shoots at Valera's soldier 1.
3) Valera's soldier 1 shoots at Arcady's soldier 2.
There are 3 soldiers killed in total: Valera's soldier 1 and Arcady's soldiers 1 and 2. | 500 | [
{
"input": "2",
"output": "3"
},
{
"input": "4",
"output": "6"
},
{
"input": "6",
"output": "9"
},
{
"input": "8",
"output": "12"
},
{
"input": "10",
"output": "15"
},
{
"input": "140",
"output": "210"
},
{
"input": "500",
"output": "75... | 1,622,294,212 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 2 | 184 | 0 |
def main_function():
n = int(input())
if 2 * n > 6:
return 6
else:
return 2 * n - 1
print(main_function()) | Title: Toy Army
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
The hero of our story, Valera, and his best friend Arcady are still in school, and therefore they spend all the free time playing turn-based strategy "GAGA: Go And Go Again". The gameplay is as follows.
There are two armies on t... | ```python
def main_function():
n = int(input())
if 2 * n > 6:
return 6
else:
return 2 * n - 1
print(main_function())
``` | 0 |
840 | A | Leha and Function | PROGRAMMING | 1,300 | [
"combinatorics",
"greedy",
"math",
"number theory",
"sortings"
] | null | null | Leha like all kinds of strange things. Recently he liked the function *F*(*n*,<=*k*). Consider all possible *k*-element subsets of the set [1,<=2,<=...,<=*n*]. For subset find minimal element in it. *F*(*n*,<=*k*) — mathematical expectation of the minimal element among all *k*-element subsets.
But only function does n... | First line of input data contains single integer *m* (1<=≤<=*m*<=≤<=2·105) — length of arrays *A* and *B*.
Next line contains *m* integers *a*1,<=*a*2,<=...,<=*a**m* (1<=≤<=*a**i*<=≤<=109) — array *A*.
Next line contains *m* integers *b*1,<=*b*2,<=...,<=*b**m* (1<=≤<=*b**i*<=≤<=109) — array *B*. | Output *m* integers *a*'1,<=*a*'2,<=...,<=*a*'*m* — array *A*' which is permutation of the array *A*. | [
"5\n7 3 5 3 4\n2 1 3 2 3\n",
"7\n4 6 5 8 8 2 6\n2 1 2 2 1 1 2\n"
] | [
"4 7 3 5 3\n",
"2 6 4 5 8 8 6\n"
] | none | 500 | [
{
"input": "5\n7 3 5 3 4\n2 1 3 2 3",
"output": "4 7 3 5 3"
},
{
"input": "7\n4 6 5 8 8 2 6\n2 1 2 2 1 1 2",
"output": "2 6 4 5 8 8 6"
}
] | 1,576,693,812 | 2,147,483,647 | PyPy 3 | OK | TESTS | 48 | 1,372 | 29,593,600 | n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a.sort()
t1= []
for i in range(n):
t1.append([b[i], i])
t1.sort(reverse = True)
ind = []
for i in t1:
ind.append(i[1])
ans = [0] * n
for i in range(n):
ans[ind[i]] = a[i]
print(*ans)
| Title: Leha and Function
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Leha like all kinds of strange things. Recently he liked the function *F*(*n*,<=*k*). Consider all possible *k*-element subsets of the set [1,<=2,<=...,<=*n*]. For subset find minimal element in it. *F*(*n*,<=*k*) — m... | ```python
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a.sort()
t1= []
for i in range(n):
t1.append([b[i], i])
t1.sort(reverse = True)
ind = []
for i in t1:
ind.append(i[1])
ans = [0] * n
for i in range(n):
ans[ind[i]] = a[i]
print(*ans)
... | 3 | |
168 | A | Wizards and Demonstration | PROGRAMMING | 900 | [
"implementation",
"math"
] | null | null | Some country is populated by wizards. They want to organize a demonstration.
There are *n* people living in the city, *x* of them are the wizards who will surely go to the demonstration. Other city people (*n*<=-<=*x* people) do not support the wizards and aren't going to go to the demonstration. We know that the city... | The first line contains three space-separated integers, *n*, *x*, *y* (1<=≤<=*n*,<=*x*,<=*y*<=≤<=104,<=*x*<=≤<=*n*) — the number of citizens in the city, the number of wizards and the percentage the administration needs, correspondingly.
Please note that *y* can exceed 100 percent, that is, the administration wants to... | Print a single integer — the answer to the problem, the minimum number of clones to create, so that the demonstration involved no less than *y* percent of *n* (the real total city population). | [
"10 1 14\n",
"20 10 50\n",
"1000 352 146\n"
] | [
"1\n",
"0\n",
"1108\n"
] | In the first sample it is necessary that at least 14% of 10 people came to the demonstration. As the number of people should be integer, then at least two people should come. There is only one wizard living in the city and he is going to come. That isn't enough, so he needs to create one clone.
In the second sample 1... | 500 | [
{
"input": "10 1 14",
"output": "1"
},
{
"input": "20 10 50",
"output": "0"
},
{
"input": "1000 352 146",
"output": "1108"
},
{
"input": "68 65 20",
"output": "0"
},
{
"input": "78 28 27",
"output": "0"
},
{
"input": "78 73 58",
"output": "0"
},
... | 1,625,586,843 | 2,147,483,647 | Python 3 | OK | TESTS | 43 | 124 | 0 | import math
n,x,y = map(int,input().split())
if (math.ceil((n*y)/100)-x) > 0:
print(math.ceil((n*y)/100)-x)
else:
print(0) | Title: Wizards and Demonstration
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Some country is populated by wizards. They want to organize a demonstration.
There are *n* people living in the city, *x* of them are the wizards who will surely go to the demonstration. Other city people (*n... | ```python
import math
n,x,y = map(int,input().split())
if (math.ceil((n*y)/100)-x) > 0:
print(math.ceil((n*y)/100)-x)
else:
print(0)
``` | 3 | |
965 | D | Single-use Stones | PROGRAMMING | 1,900 | [
"binary search",
"flows",
"greedy",
"two pointers"
] | null | null | A lot of frogs want to cross a river. A river is $w$ units width, but frogs can only jump $l$ units long, where $l < w$. Frogs can also jump on lengths shorter than $l$. but can't jump longer. Hopefully, there are some stones in the river to help them.
The stones are located at integer distances from the banks. The... | The first line contains two integers $w$ and $l$ ($1 \le l < w \le 10^5$) — the width of the river and the maximum length of a frog's jump.
The second line contains $w - 1$ integers $a_1, a_2, \ldots, a_{w-1}$ ($0 \le a_i \le 10^4$), where $a_i$ is the number of stones at the distance $i$ from the bank the frogs ar... | Print a single integer — the maximum number of frogs that can cross the river. | [
"10 5\n0 0 1 0 2 0 0 1 0\n",
"10 3\n1 1 1 1 2 1 1 1 1\n"
] | [
"3\n",
"3\n"
] | In the first sample two frogs can use the different stones at the distance $5$, and one frog can use the stones at the distances $3$ and then $8$.
In the second sample although there are two stones at the distance $5$, that does not help. The three paths are: $0 \to 3 \to 6 \to 9 \to 10$, $0 \to 2 \to 5 \to 8 \to 10$,... | 2,000 | [
{
"input": "10 5\n0 0 1 0 2 0 0 1 0",
"output": "3"
},
{
"input": "10 3\n1 1 1 1 2 1 1 1 1",
"output": "3"
},
{
"input": "2 1\n0",
"output": "0"
},
{
"input": "2 1\n5",
"output": "5"
},
{
"input": "10 4\n0 0 6 2 7 1 6 4 0",
"output": "8"
},
{
"input": ... | 1,524,899,861 | 2,147,483,647 | Python 3 | OK | TESTS | 16 | 171 | 14,336,000 | w, l = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
s = res = sum(a[:l])
for i in range(l, w - 1):
s += a[i] - a[i - l]
res = min(res, s)
print(res)
| Title: Single-use Stones
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A lot of frogs want to cross a river. A river is $w$ units width, but frogs can only jump $l$ units long, where $l < w$. Frogs can also jump on lengths shorter than $l$. but can't jump longer. Hopefully, there are ... | ```python
w, l = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
s = res = sum(a[:l])
for i in range(l, w - 1):
s += a[i] - a[i - l]
res = min(res, s)
print(res)
``` | 3 | |
637 | B | Chat Order | PROGRAMMING | 1,200 | [
"*special",
"binary search",
"constructive algorithms",
"data structures",
"sortings"
] | null | null | Polycarp is a big lover of killing time in social networks. A page with a chatlist in his favourite network is made so that when a message is sent to some friend, his friend's chat rises to the very top of the page. The relative order of the other chats doesn't change. If there was no chat with this friend before, then... | The first line contains integer *n* (1<=≤<=*n*<=≤<=200<=000) — the number of Polycarpus' messages. Next *n* lines enlist the message recipients in the order in which the messages were sent. The name of each participant is a non-empty sequence of lowercase English letters of length at most 10. | Print all the recipients to who Polycarp talked to in the order of chats with them, from top to bottom. | [
"4\nalex\nivan\nroman\nivan\n",
"8\nalina\nmaria\nekaterina\ndarya\ndarya\nekaterina\nmaria\nalina\n"
] | [
"ivan\nroman\nalex\n",
"alina\nmaria\nekaterina\ndarya\n"
] | In the first test case Polycarpus first writes to friend by name "alex", and the list looks as follows:
1. alex
Then Polycarpus writes to friend by name "ivan" and the list looks as follows:
1. ivan 1. alex
Polycarpus writes the third message to friend by name "roman" and the list looks as follows:
1. roman 1... | 1,000 | [
{
"input": "4\nalex\nivan\nroman\nivan",
"output": "ivan\nroman\nalex"
},
{
"input": "8\nalina\nmaria\nekaterina\ndarya\ndarya\nekaterina\nmaria\nalina",
"output": "alina\nmaria\nekaterina\ndarya"
},
{
"input": "1\nwdi",
"output": "wdi"
},
{
"input": "2\nypg\nypg",
"outpu... | 1,607,446,862 | 2,147,483,647 | PyPy 3 | OK | TESTS | 95 | 1,856 | 41,164,800 | def main():
n = int(input())
friend_dict = {}
for i in range(n):
friend_dict[input()] = i
friend_dict = dict(sorted(friend_dict.items(), key=lambda x: x[1], reverse=True))
for friend in friend_dict.keys():
print(friend)
main() | Title: Chat Order
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp is a big lover of killing time in social networks. A page with a chatlist in his favourite network is made so that when a message is sent to some friend, his friend's chat rises to the very top of the page. The rela... | ```python
def main():
n = int(input())
friend_dict = {}
for i in range(n):
friend_dict[input()] = i
friend_dict = dict(sorted(friend_dict.items(), key=lambda x: x[1], reverse=True))
for friend in friend_dict.keys():
print(friend)
main()
``` | 3 | |
471 | A | MUH and Sticks | PROGRAMMING | 1,100 | [
"implementation"
] | null | null | Two polar bears Menshykov and Uslada from the St.Petersburg zoo and elephant Horace from the Kiev zoo got six sticks to play with and assess the animals' creativity. Menshykov, Uslada and Horace decided to make either an elephant or a bear from those sticks. They can make an animal from sticks in the following way:
-... | The single line contains six space-separated integers *l**i* (1<=≤<=*l**i*<=≤<=9) — the lengths of the six sticks. It is guaranteed that the input is such that you cannot make both animals from the sticks. | If you can make a bear from the given set, print string "Bear" (without the quotes). If you can make an elephant, print string "Elephant" (wıthout the quotes). If you can make neither a bear nor an elephant, print string "Alien" (without the quotes). | [
"4 2 5 4 4 4\n",
"4 4 5 4 4 5\n",
"1 2 3 4 5 6\n"
] | [
"Bear",
"Elephant",
"Alien"
] | If you're out of creative ideas, see instructions below which show how to make a bear and an elephant in the first two samples. The stick of length 2 is in red, the sticks of length 4 are in green, the sticks of length 5 are in blue. | 500 | [
{
"input": "4 2 5 4 4 4",
"output": "Bear"
},
{
"input": "4 4 5 4 4 5",
"output": "Elephant"
},
{
"input": "1 2 3 4 5 6",
"output": "Alien"
},
{
"input": "5 5 5 5 5 5",
"output": "Elephant"
},
{
"input": "1 1 1 2 3 5",
"output": "Alien"
},
{
"input": "... | 1,439,644,158 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 15 | 62 | 0 | from sys import stdin, stdout
input = stdin.readline
l = list(map(int, input().split()))
l.sort()
if len(set(l[:4])) == len(set(l[4:])) == 1:
stdout.write("Elephant")
elif len(set(l[:4])) == 1 or len(set(l[1:5])) == 1 or len(set(l[2:])) == 1:
stdout.write("Bear")
else:
stdout... | Title: MUH and Sticks
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Two polar bears Menshykov and Uslada from the St.Petersburg zoo and elephant Horace from the Kiev zoo got six sticks to play with and assess the animals' creativity. Menshykov, Uslada and Horace decided to make either an... | ```python
from sys import stdin, stdout
input = stdin.readline
l = list(map(int, input().split()))
l.sort()
if len(set(l[:4])) == len(set(l[4:])) == 1:
stdout.write("Elephant")
elif len(set(l[:4])) == 1 or len(set(l[1:5])) == 1 or len(set(l[2:])) == 1:
stdout.write("Bear")
else:
... | 0 | |
302 | A | Eugeny and Array | PROGRAMMING | 800 | [
"implementation"
] | null | null | Eugeny has array *a*<==<=*a*1,<=*a*2,<=...,<=*a**n*, consisting of *n* integers. Each integer *a**i* equals to -1, or to 1. Also, he has *m* queries:
- Query number *i* is given as a pair of integers *l**i*, *r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*). - The response to the query will be integer 1, if the elements of a... | The first line contains integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=2·105). The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (*a**i*<==<=-1,<=1). Next *m* lines contain Eugene's queries. The *i*-th line contains integers *l**i*,<=*r**i* (1<=≤<=*l**i*<=≤<=*r**i*<=≤<=*n*). | Print *m* integers — the responses to Eugene's queries in the order they occur in the input. | [
"2 3\n1 -1\n1 1\n1 2\n2 2\n",
"5 5\n-1 1 1 1 -1\n1 1\n2 3\n3 5\n2 5\n1 5\n"
] | [
"0\n1\n0\n",
"0\n1\n0\n1\n0\n"
] | none | 500 | [
{
"input": "2 3\n1 -1\n1 1\n1 2\n2 2",
"output": "0\n1\n0"
},
{
"input": "5 5\n-1 1 1 1 -1\n1 1\n2 3\n3 5\n2 5\n1 5",
"output": "0\n1\n0\n1\n0"
},
{
"input": "3 3\n1 1 1\n2 2\n1 1\n1 1",
"output": "0\n0\n0"
},
{
"input": "4 4\n-1 -1 -1 -1\n1 3\n1 2\n1 2\n1 1",
"output": "... | 1,540,996,878 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 2 | 124 | 102,400 |
from collections import Counter
n,m = map(int,input().split())
k1 = list(map(int,input().split()))
a = dict(Counter(k1))
count1 = a[1]
count2 = a[-1]
for i in range(m):
a,b = map(int,input().split())
if (b-a+1)%2 == 0:
c = (b-a+1)//2
if c<=count1 and c<=count2:
print(1)
... | Title: Eugeny and Array
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Eugeny has array *a*<==<=*a*1,<=*a*2,<=...,<=*a**n*, consisting of *n* integers. Each integer *a**i* equals to -1, or to 1. Also, he has *m* queries:
- Query number *i* is given as a pair of integers *l**i*, *r**i* (... | ```python
from collections import Counter
n,m = map(int,input().split())
k1 = list(map(int,input().split()))
a = dict(Counter(k1))
count1 = a[1]
count2 = a[-1]
for i in range(m):
a,b = map(int,input().split())
if (b-a+1)%2 == 0:
c = (b-a+1)//2
if c<=count1 and c<=count2:
p... | -1 | |
960 | A | Check the string | PROGRAMMING | 1,200 | [
"implementation"
] | null | null | A has a string consisting of some number of lowercase English letters 'a'. He gives it to his friend B who appends some number of letters 'b' to the end of this string. Since both A and B like the characters 'a' and 'b', they have made sure that at this point, at least one 'a' and one 'b' exist in the string.
B now gi... | The first and only line consists of a string $S$ ($ 1 \le |S| \le 5\,000 $). It is guaranteed that the string will only consist of the lowercase English letters 'a', 'b', 'c'. | Print "YES" or "NO", according to the condition. | [
"aaabccc\n",
"bbacc\n",
"aabc\n"
] | [
"YES\n",
"NO\n",
"YES\n"
] | Consider first example: the number of 'c' is equal to the number of 'a'.
Consider second example: although the number of 'c' is equal to the number of the 'b', the order is not correct.
Consider third example: the number of 'c' is equal to the number of 'b'. | 500 | [
{
"input": "aaabccc",
"output": "YES"
},
{
"input": "bbacc",
"output": "NO"
},
{
"input": "aabc",
"output": "YES"
},
{
"input": "aabbcc",
"output": "YES"
},
{
"input": "aaacccbb",
"output": "NO"
},
{
"input": "abc",
"output": "YES"
},
{
"in... | 1,524,984,322 | 2,147,483,647 | Python 3 | OK | TESTS | 55 | 93 | 7,065,600 |
s = input()
a = s.count('a')
b = s.count('b')
if a and b and (s == 'a' * a + 'b' * b + 'c' * a or s == 'a' * a + 'b' * b + 'c' * b):
print("YES")
else:
print("NO") | Title: Check the string
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A has a string consisting of some number of lowercase English letters 'a'. He gives it to his friend B who appends some number of letters 'b' to the end of this string. Since both A and B like the characters 'a' and 'b... | ```python
s = input()
a = s.count('a')
b = s.count('b')
if a and b and (s == 'a' * a + 'b' * b + 'c' * a or s == 'a' * a + 'b' * b + 'c' * b):
print("YES")
else:
print("NO")
``` | 3 | |
50 | B | Choosing Symbol Pairs | PROGRAMMING | 1,500 | [
"strings"
] | B. Choosing Symbol Pairs | 2 | 256 | There is a given string *S* consisting of *N* symbols. Your task is to find the number of ordered pairs of integers *i* and *j* such that
1. 1<=≤<=*i*,<=*j*<=≤<=*N*
2. *S*[*i*]<==<=*S*[*j*], that is the *i*-th symbol of string *S* is equal to the *j*-th. | The single input line contains *S*, consisting of lowercase Latin letters and digits. It is guaranteed that string *S* in not empty and its length does not exceed 105. | Print a single number which represents the number of pairs *i* and *j* with the needed property. Pairs (*x*,<=*y*) and (*y*,<=*x*) should be considered different, i.e. the ordered pairs count. | [
"great10\n",
"aaaaaaaaaa\n"
] | [
"7\n",
"100\n"
] | none | 1,000 | [
{
"input": "great10",
"output": "7"
},
{
"input": "aaaaaaaaaa",
"output": "100"
},
{
"input": "great10",
"output": "7"
},
{
"input": "aaaaaaaaaa",
"output": "100"
},
{
"input": "aabb",
"output": "8"
},
{
"input": "w",
"output": "1"
},
{
"in... | 1,677,758,695 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 92 | 0 | # LUOGU_RID: 103453417
n=0
d={}
s=input()
for i in s:
d[i]=d.get(i,0)+1
for x in d.values():
n+=x**2
print(n)
| Title: Choosing Symbol Pairs
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
There is a given string *S* consisting of *N* symbols. Your task is to find the number of ordered pairs of integers *i* and *j* such that
1. 1<=≤<=*i*,<=*j*<=≤<=*N*
2. *S*[*i*]<==<=*S*[*j*], that is the *i*-th symbo... | ```python
# LUOGU_RID: 103453417
n=0
d={}
s=input()
for i in s:
d[i]=d.get(i,0)+1
for x in d.values():
n+=x**2
print(n)
``` | 3.977 |
910 | A | The Way to Home | PROGRAMMING | 800 | [
"dfs and similar",
"dp",
"greedy",
"implementation"
] | null | null | A frog lives on the axis *Ox* and needs to reach home which is in the point *n*. She starts from the point 1. The frog can jump to the right at a distance not more than *d*. So, after she jumped from the point *x* she can reach the point *x*<=+<=*a*, where *a* is an integer from 1 to *d*.
For each point from 1 to *n* ... | The first line contains two integers *n* and *d* (2<=≤<=*n*<=≤<=100, 1<=≤<=*d*<=≤<=*n*<=-<=1) — the point, which the frog wants to reach, and the maximal length of the frog jump.
The second line contains a string *s* of length *n*, consisting of zeros and ones. If a character of the string *s* equals to zero, then in ... | If the frog can not reach the home, print -1.
In the other case, print the minimal number of jumps that the frog needs to reach the home which is in the point *n* from the point 1. | [
"8 4\n10010101\n",
"4 2\n1001\n",
"8 4\n11100101\n",
"12 3\n101111100101\n"
] | [
"2\n",
"-1\n",
"3\n",
"4\n"
] | In the first example the from can reach home in two jumps: the first jump from the point 1 to the point 4 (the length of the jump is three), and the second jump from the point 4 to the point 8 (the length of the jump is four).
In the second example the frog can not reach home, because to make it she need to jump on a ... | 500 | [
{
"input": "8 4\n10010101",
"output": "2"
},
{
"input": "4 2\n1001",
"output": "-1"
},
{
"input": "8 4\n11100101",
"output": "3"
},
{
"input": "12 3\n101111100101",
"output": "4"
},
{
"input": "5 4\n11011",
"output": "1"
},
{
"input": "5 4\n10001",
... | 1,688,181,706 | 2,147,483,647 | Python 3 | OK | TESTS | 63 | 46 | 0 | n, d = [int(x) for x in input().split()]
s = str(input())
i = 0
ans = 0
temp = 0
while(1):
temp = min(d, n-i-1)
while(temp > 0):
if s[i+temp] == "1":
flag = 1
break
else:
temp -= 1
if temp == 0:
flag = 0
ans += 1
i += temp
# print(i, ans)
if i == n-1 or not(flag):
break
if i+1 == n... | Title: The Way to Home
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A frog lives on the axis *Ox* and needs to reach home which is in the point *n*. She starts from the point 1. The frog can jump to the right at a distance not more than *d*. So, after she jumped from the point *x* she c... | ```python
n, d = [int(x) for x in input().split()]
s = str(input())
i = 0
ans = 0
temp = 0
while(1):
temp = min(d, n-i-1)
while(temp > 0):
if s[i+temp] == "1":
flag = 1
break
else:
temp -= 1
if temp == 0:
flag = 0
ans += 1
i += temp
# print(i, ans)
if i == n-1 or not(flag):
break
i... | 3 | |
916 | C | Jamie and Interesting Graph | PROGRAMMING | 1,600 | [
"constructive algorithms",
"graphs",
"shortest paths"
] | null | null | Jamie has recently found undirected weighted graphs with the following properties very interesting:
- The graph is connected and contains exactly *n* vertices and *m* edges. - All edge weights are integers and are in range [1,<=109] inclusive. - The length of shortest path from 1 to *n* is a prime number. - The su... | First line of input contains 2 integers *n*, *m* — the required number of vertices and edges. | In the first line output 2 integers *sp*, *mstw* (1<=≤<=*sp*,<=*mstw*<=≤<=1014) — the length of the shortest path and the sum of edges' weights in the minimum spanning tree.
In the next *m* lines output the edges of the graph. In each line output 3 integers *u*, *v*, *w* (1<=≤<=*u*,<=*v*<=≤<=*n*,<=1<=≤<=*w*<=≤<=109) d... | [
"4 4\n",
"5 4\n"
] | [
"7 7\n1 2 3\n2 3 2\n3 4 2\n2 4 4\n",
"7 13\n1 2 2\n1 3 4\n1 4 3\n4 5 4\n"
] | The graph of sample 1: <img class="tex-graphics" src="https://espresso.codeforces.com/42f9750de41b0d9a6b21e8615170113cfe19b0f2.png" style="max-width: 100.0%;max-height: 100.0%;"/> Shortest path sequence: {1, 2, 3, 4}. MST edges are marked with an asterisk (*).
Definition of terms used in the problem statement:
A shor... | 1,500 | [
{
"input": "4 4",
"output": "100003 100003\n1 2 100001\n2 3 1\n3 4 1\n1 3 1000000000"
},
{
"input": "5 4",
"output": "100003 100003\n1 2 100000\n2 3 1\n3 4 1\n4 5 1"
},
{
"input": "2 1",
"output": "100003 100003\n1 2 100003"
},
{
"input": "10 19",
"output": "100003 100003... | 1,596,384,490 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 77 | 6,963,200 | n, m = map(int, input().split())
p = 524287
print(2, (p if m > 1 else 2))
for i in range(2, n + 1):
w = 1
if i == 2:
w = p - n
if i == n:
w = 2
print(1, i, w)
if m >= n:
c = 1
count = 1
for i in range(0, m - n + 1):
print(c, c + count, p)
coun... | Title: Jamie and Interesting Graph
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Jamie has recently found undirected weighted graphs with the following properties very interesting:
- The graph is connected and contains exactly *n* vertices and *m* edges. - All edge weights are integer... | ```python
n, m = map(int, input().split())
p = 524287
print(2, (p if m > 1 else 2))
for i in range(2, n + 1):
w = 1
if i == 2:
w = p - n
if i == n:
w = 2
print(1, i, w)
if m >= n:
c = 1
count = 1
for i in range(0, m - n + 1):
print(c, c + count, p)
... | 0 | |
337 | A | Puzzles | PROGRAMMING | 900 | [
"greedy"
] | null | null | The end of the school year is near and Ms. Manana, the teacher, will soon have to say goodbye to a yet another class. She decided to prepare a goodbye present for her *n* students and give each of them a jigsaw puzzle (which, as wikipedia states, is a tiling puzzle that requires the assembly of numerous small, often od... | The first line contains space-separated integers *n* and *m* (2<=≤<=*n*<=≤<=*m*<=≤<=50). The second line contains *m* space-separated integers *f*1,<=*f*2,<=...,<=*f**m* (4<=≤<=*f**i*<=≤<=1000) — the quantities of pieces in the puzzles sold in the shop. | Print a single integer — the least possible difference the teacher can obtain. | [
"4 6\n10 12 10 7 5 22\n"
] | [
"5\n"
] | Sample 1. The class has 4 students. The shop sells 6 puzzles. If Ms. Manana buys the first four puzzles consisting of 10, 12, 10 and 7 pieces correspondingly, then the difference between the sizes of the largest and the smallest puzzle will be equal to 5. It is impossible to obtain a smaller difference. Note that the t... | 500 | [
{
"input": "4 6\n10 12 10 7 5 22",
"output": "5"
},
{
"input": "2 2\n4 4",
"output": "0"
},
{
"input": "2 10\n4 5 6 7 8 9 10 11 12 12",
"output": "0"
},
{
"input": "4 5\n818 136 713 59 946",
"output": "759"
},
{
"input": "3 20\n446 852 783 313 549 965 40 88 86 617... | 1,695,584,851 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 6 | 186 | 0 | def solvePuzzle(n,m,arr):
arr.sort()
return min(arr[n-1] - arr[0],arr[-1] - arr[m-n]);
n,m = map(int,input().split());
arr = list(map(int,input().split()));
print(solvePuzzle(n,m,arr)); | Title: Puzzles
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The end of the school year is near and Ms. Manana, the teacher, will soon have to say goodbye to a yet another class. She decided to prepare a goodbye present for her *n* students and give each of them a jigsaw puzzle (which, a... | ```python
def solvePuzzle(n,m,arr):
arr.sort()
return min(arr[n-1] - arr[0],arr[-1] - arr[m-n]);
n,m = map(int,input().split());
arr = list(map(int,input().split()));
print(solvePuzzle(n,m,arr));
``` | 0 | |
114 | A | Cifera | PROGRAMMING | 1,000 | [
"math"
] | null | null | When Petya went to school, he got interested in large numbers and what they were called in ancient times. For instance, he learned that the Russian word "tma" (which now means "too much to be counted") used to stand for a thousand and "tma tmyschaya" (which literally means "the tma of tmas") used to stand for a million... | The first input line contains integer number *k*, the second line contains integer number *l* (2<=≤<=*k*,<=*l*<=≤<=231<=-<=1). | You should print in the first line of the output "YES", if the number belongs to the set petriciumus cifera and otherwise print "NO". If the number belongs to the set, then print on the seconds line the only number — the importance of number *l*. | [
"5\n25\n",
"3\n8\n"
] | [
"YES\n1\n",
"NO\n"
] | none | 500 | [
{
"input": "5\n25",
"output": "YES\n1"
},
{
"input": "3\n8",
"output": "NO"
},
{
"input": "123\n123",
"output": "YES\n0"
},
{
"input": "99\n970300",
"output": "NO"
},
{
"input": "1000\n6666666",
"output": "NO"
},
{
"input": "59\n3571",
"output": "N... | 1,579,275,003 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 8 | 218 | 0 | n = int(input())
p = int(input())
f = 0
for i in range(1, int(2**31)):
if p ** (1/i) == n:
print('YES')
print(i-1)
f = 1
elif p**(1/i) < n:
break
if not f:
print('NO') | Title: Cifera
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
When Petya went to school, he got interested in large numbers and what they were called in ancient times. For instance, he learned that the Russian word "tma" (which now means "too much to be counted") used to stand for a thousa... | ```python
n = int(input())
p = int(input())
f = 0
for i in range(1, int(2**31)):
if p ** (1/i) == n:
print('YES')
print(i-1)
f = 1
elif p**(1/i) < n:
break
if not f:
print('NO')
``` | 0 | |
141 | A | Amusing Joke | PROGRAMMING | 800 | [
"implementation",
"sortings",
"strings"
] | null | null | So, the New Year holidays are over. Santa Claus and his colleagues can take a rest and have guests at last. When two "New Year and Christmas Men" meet, thear assistants cut out of cardboard the letters from the guest's name and the host's name in honor of this event. Then the hung the letters above the main entrance. O... | The input file consists of three lines: the first line contains the guest's name, the second line contains the name of the residence host and the third line contains letters in a pile that were found at the door in the morning. All lines are not empty and contain only uppercase Latin letters. The length of each line do... | Print "YES" without the quotes, if the letters in the pile could be permuted to make the names of the "New Year and Christmas Men". Otherwise, print "NO" without the quotes. | [
"SANTACLAUS\nDEDMOROZ\nSANTAMOROZDEDCLAUS\n",
"PAPAINOEL\nJOULUPUKKI\nJOULNAPAOILELUPUKKI\n",
"BABBONATALE\nFATHERCHRISTMAS\nBABCHRISTMASBONATALLEFATHER\n"
] | [
"YES\n",
"NO\n",
"NO\n"
] | In the first sample the letters written in the last line can be used to write the names and there won't be any extra letters left.
In the second sample letter "P" is missing from the pile and there's an extra letter "L".
In the third sample there's an extra letter "L". | 500 | [
{
"input": "SANTACLAUS\nDEDMOROZ\nSANTAMOROZDEDCLAUS",
"output": "YES"
},
{
"input": "PAPAINOEL\nJOULUPUKKI\nJOULNAPAOILELUPUKKI",
"output": "NO"
},
{
"input": "BABBONATALE\nFATHERCHRISTMAS\nBABCHRISTMASBONATALLEFATHER",
"output": "NO"
},
{
"input": "B\nA\nAB",
"output": ... | 1,688,148,398 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 8 | 62 | 0 | a=input()
b=input()
c=input()
x=[*a]
y=[*b]
z=[*c]
l=z[:]
v=0
for i in range(len(z)):
if z[i] in x:
x.remove(z[i])
l.remove(z[i])
elif z[i] in y:
y.remove(z[i])
l.remove(z[i])
else:
v+=1
break
if v==1:
print("NO")
elif(len(x)==0 and len... | Title: Amusing Joke
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
So, the New Year holidays are over. Santa Claus and his colleagues can take a rest and have guests at last. When two "New Year and Christmas Men" meet, thear assistants cut out of cardboard the letters from the guest's nam... | ```python
a=input()
b=input()
c=input()
x=[*a]
y=[*b]
z=[*c]
l=z[:]
v=0
for i in range(len(z)):
if z[i] in x:
x.remove(z[i])
l.remove(z[i])
elif z[i] in y:
y.remove(z[i])
l.remove(z[i])
else:
v+=1
break
if v==1:
print("NO")
elif(len(x)=... | 0 | |
301 | A | Yaroslav and Sequence | PROGRAMMING | 1,800 | [
"constructive algorithms"
] | null | null | Yaroslav has an array, consisting of (2·*n*<=-<=1) integers. In a single operation Yaroslav can change the sign of exactly *n* elements in the array. In other words, in one operation Yaroslav can select exactly *n* array elements, and multiply each of them by -1.
Yaroslav is now wondering: what maximum sum of array el... | The first line contains an integer *n* (2<=≤<=*n*<=≤<=100). The second line contains (2·*n*<=-<=1) integers — the array elements. The array elements do not exceed 1000 in their absolute value. | In a single line print the answer to the problem — the maximum sum that Yaroslav can get. | [
"2\n50 50 50\n",
"2\n-1 -100 -1\n"
] | [
"150\n",
"100\n"
] | In the first sample you do not need to change anything. The sum of elements equals 150.
In the second sample you need to change the sign of the first two elements. Then we get the sum of the elements equal to 100. | 500 | [
{
"input": "2\n50 50 50",
"output": "150"
},
{
"input": "2\n-1 -100 -1",
"output": "100"
},
{
"input": "3\n-959 -542 -669 -513 160",
"output": "2843"
},
{
"input": "4\n717 473 344 -51 -548 703 -869",
"output": "3603"
},
{
"input": "5\n270 -181 957 -509 -6 937 -175... | 1,630,729,902 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 2 | 154 | 20,172,800 | import sys
input=sys.stdin.readline
n=int(input())
a=list(map(int,input().split()))
minus=0
for i in range(n):
if a[i]<0:
minus+=1
a[i]*=-1
if minus%2==0 or n%2==1:
print(sum(a))
else:
print(sum(a)-min(a)*2) | Title: Yaroslav and Sequence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Yaroslav has an array, consisting of (2·*n*<=-<=1) integers. In a single operation Yaroslav can change the sign of exactly *n* elements in the array. In other words, in one operation Yaroslav can select exactly *n... | ```python
import sys
input=sys.stdin.readline
n=int(input())
a=list(map(int,input().split()))
minus=0
for i in range(n):
if a[i]<0:
minus+=1
a[i]*=-1
if minus%2==0 or n%2==1:
print(sum(a))
else:
print(sum(a)-min(a)*2)
``` | 0 | |
26 | A | Almost Prime | PROGRAMMING | 900 | [
"number theory"
] | A. Almost Prime | 2 | 256 | A number is called almost prime if it has exactly two distinct prime divisors. For example, numbers 6, 18, 24 are almost prime, while 4, 8, 9, 42 are not. Find the amount of almost prime numbers which are between 1 and *n*, inclusive. | Input contains one integer number *n* (1<=≤<=*n*<=≤<=3000). | Output the amount of almost prime numbers between 1 and *n*, inclusive. | [
"10\n",
"21\n"
] | [
"2\n",
"8\n"
] | none | 500 | [
{
"input": "10",
"output": "2"
},
{
"input": "21",
"output": "8"
},
{
"input": "1",
"output": "0"
},
{
"input": "2",
"output": "0"
},
{
"input": "4",
"output": "0"
},
{
"input": "3",
"output": "0"
},
{
"input": "8",
"output": "1"
},
... | 1,680,276,591 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 23 | 154 | 1,638,400 | n = int(input())
answer = 0
ansss = []
for x in range(1, n + 1):
d = 2
ans = 0
saved = x
while d // 2 <= x:
if not x % d:
while not x % d:
x //= d
ans += 1
if ans > 2:
... | Title: Almost Prime
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A number is called almost prime if it has exactly two distinct prime divisors. For example, numbers 6, 18, 24 are almost prime, while 4, 8, 9, 42 are not. Find the amount of almost prime numbers which are between 1 and *n*, in... | ```python
n = int(input())
answer = 0
ansss = []
for x in range(1, n + 1):
d = 2
ans = 0
saved = x
while d // 2 <= x:
if not x % d:
while not x % d:
x //= d
ans += 1
if ans > 2:
... | 3.958448 |
986 | D | Perfect Encoding | PROGRAMMING | 3,100 | [
"fft",
"math"
] | null | null | You are working as an analyst in a company working on a new system for big data storage. This system will store $n$ different objects. Each object should have a unique ID.
To create the system, you choose the parameters of the system — integers $m \ge 1$ and $b_{1}, b_{2}, \ldots, b_{m}$. With these parameters an ID o... | In the only line of input there is one positive integer $n$. The length of the decimal representation of $n$ is no greater than $1.5 \cdot 10^{6}$. The integer does not contain leading zeros. | Print one number — minimal value of $\sum_{i=1}^{m} b_{i}$. | [
"36\n",
"37\n",
"12345678901234567890123456789\n"
] | [
"10\n",
"11\n",
"177\n"
] | none | 2,500 | [
{
"input": "36",
"output": "10"
},
{
"input": "37",
"output": "11"
},
{
"input": "12345678901234567890123456789",
"output": "177"
},
{
"input": "1",
"output": "1"
},
{
"input": "2",
"output": "2"
},
{
"input": "3",
"output": "3"
},
{
"input... | 1,596,636,135 | 7,335 | PyPy 3 | WRONG_ANSWER | TESTS | 0 | 124 | 20,172,800 | import math
def calc(n):
x = 3
k = 1
xs = [3]
ks = [1]
res = 0
while x <= n:
n = (n + x - 1) // x
res += k
x = x * x
k = k + k
xs.append(x)
ks.append(k)
while len(xs) > 0:
x = xs.pop()
k = ks.pop()
if x <= n:
... | Title: Perfect Encoding
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are working as an analyst in a company working on a new system for big data storage. This system will store $n$ different objects. Each object should have a unique ID.
To create the system, you choose the paramete... | ```python
import math
def calc(n):
x = 3
k = 1
xs = [3]
ks = [1]
res = 0
while x <= n:
n = (n + x - 1) // x
res += k
x = x * x
k = k + k
xs.append(x)
ks.append(k)
while len(xs) > 0:
x = xs.pop()
k = ks.pop()
if x <=... | 0 | |
329 | A | Purification | PROGRAMMING | 1,500 | [
"constructive algorithms",
"greedy"
] | null | null | You are an adventurer currently journeying inside an evil temple. After defeating a couple of weak zombies, you arrived at a square room consisting of tiles forming an *n*<=×<=*n* grid. The rows are numbered 1 through *n* from top to bottom, and the columns are numbered 1 through *n* from left to right. At the far side... | The first line will contain a single integer *n* (1<=≤<=*n*<=≤<=100). Then, *n* lines follows, each contains *n* characters. The *j*-th character in the *i*-th row represents the cell located at row *i* and column *j*. It will be the character 'E' if it is a particularly more evil cell, and '.' otherwise. | If there exists no way to purify all the cells, output -1. Otherwise, if your solution casts *x* "Purification" spells (where *x* is the minimum possible number of spells), output *x* lines. Each line should consist of two integers denoting the row and column numbers of the cell on which you should cast the "Purificati... | [
"3\n.E.\nE.E\n.E.\n",
"3\nEEE\nE..\nE.E\n",
"5\nEE.EE\nE.EE.\nE...E\n.EE.E\nEE.EE\n"
] | [
"1 1\n2 2\n3 3\n",
"-1\n",
"3 3\n1 3\n2 2\n4 4\n5 3"
] | The first example is illustrated as follows. Purple tiles are evil tiles that have not yet been purified. Red tile is the tile on which "Purification" is cast. Yellow tiles are the tiles being purified as a result of the current "Purification" spell. Green tiles are tiles that have been purified previously.
In the se... | 500 | [
{
"input": "3\n.E.\nE.E\n.E.",
"output": "1 1\n2 2\n3 1"
},
{
"input": "3\nEEE\nE..\nE.E",
"output": "-1"
},
{
"input": "5\nEE.EE\nE.EE.\nE...E\n.EE.E\nEE.EE",
"output": "1 3\n2 2\n3 2\n4 1\n5 3"
},
{
"input": "3\n.EE\n.EE\n.EE",
"output": "1 1\n2 1\n3 1"
},
{
"in... | 1,581,458,732 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 186 | 307,200 | n = int(input())
l = []
for _ in range(n):
l.append([x for x in input()])
results = []
thing = True
for i in range(n):
hit = False
for j in range(n):
if l[i][j] != "E":
results.append(f"{i + 1} {j + 1}")
hit = True
break
if not hit:
thi... | Title: Purification
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are an adventurer currently journeying inside an evil temple. After defeating a couple of weak zombies, you arrived at a square room consisting of tiles forming an *n*<=×<=*n* grid. The rows are numbered 1 through *n* ... | ```python
n = int(input())
l = []
for _ in range(n):
l.append([x for x in input()])
results = []
thing = True
for i in range(n):
hit = False
for j in range(n):
if l[i][j] != "E":
results.append(f"{i + 1} {j + 1}")
hit = True
break
if not hit:
... | 0 | |
9 | C | Hexadecimal's Numbers | PROGRAMMING | 1,200 | [
"brute force",
"implementation",
"math"
] | C. Hexadecimal's Numbers | 1 | 64 | One beautiful July morning a terrible thing happened in Mainframe: a mean virus Megabyte somehow got access to the memory of his not less mean sister Hexadecimal. He loaded there a huge amount of *n* different natural numbers from 1 to *n* to obtain total control over her energy.
But his plan failed. The reason for th... | Input data contains the only number *n* (1<=≤<=*n*<=≤<=109). | Output the only number — answer to the problem. | [
"10\n"
] | [
"2"
] | For *n* = 10 the answer includes numbers 1 and 10. | 0 | [
{
"input": "10",
"output": "2"
},
{
"input": "20",
"output": "3"
},
{
"input": "72",
"output": "3"
},
{
"input": "99",
"output": "3"
},
{
"input": "100",
"output": "4"
},
{
"input": "101",
"output": "5"
},
{
"input": "102",
"output": "5... | 1,611,734,527 | 4,627 | PyPy 3 | OK | TESTS | 36 | 216 | 0 | import sys
# import logging
# logging.root.setLevel(level=logging.INFO)
n = int(sys.stdin.readline().strip().split()[0])
i = 1
while int((bin(i))[2:]) <= n:
i += 1
print(i-1)
| Title: Hexadecimal's Numbers
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
One beautiful July morning a terrible thing happened in Mainframe: a mean virus Megabyte somehow got access to the memory of his not less mean sister Hexadecimal. He loaded there a huge amount of *n* different natural ... | ```python
import sys
# import logging
# logging.root.setLevel(level=logging.INFO)
n = int(sys.stdin.readline().strip().split()[0])
i = 1
while int((bin(i))[2:]) <= n:
i += 1
print(i-1)
``` | 3.892 |
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,642,209,742 | 2,147,483,647 | Python 3 | OK | TESTS | 33 | 62 | 102,400 | from functools import reduce
def factors(n):
return set(reduce(list.__add__,
([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0)))
n = int(input())
fact = factors(n)
length = len(fact)
print(length - 1) | 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
from functools import reduce
def factors(n):
return set(reduce(list.__add__,
([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0)))
n = int(input())
fact = factors(n)
length = len(fact)
print(length - 1)
``` | 3 | |
322 | A | Ciel and Dancing | PROGRAMMING | 1,000 | [
"greedy"
] | null | null | Fox Ciel and her friends are in a dancing room. There are *n* boys and *m* girls here, and they never danced before. There will be some songs, during each song, there must be exactly one boy and one girl are dancing. Besides, there is a special rule:
- either the boy in the dancing pair must dance for the first time ... | The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of boys and girls in the dancing room. | In the first line print *k* — the number of songs during which they can dance. Then in the following *k* lines, print the indexes of boys and girls dancing during songs chronologically. You can assume that the boys are indexed from 1 to *n*, and the girls are indexed from 1 to *m*. | [
"2 1\n",
"2 2\n"
] | [
"2\n1 1\n2 1\n",
"3\n1 1\n1 2\n2 2\n"
] | In test case 1, there are 2 boys and 1 girl. We can have 2 dances: the 1st boy and 1st girl (during the first song), the 2nd boy and 1st girl (during the second song).
And in test case 2, we have 2 boys with 2 girls, the answer is 3. | 500 | [
{
"input": "2 1",
"output": "2\n1 1\n2 1"
},
{
"input": "2 2",
"output": "3\n1 1\n1 2\n2 2"
},
{
"input": "1 1",
"output": "1\n1 1"
},
{
"input": "2 3",
"output": "4\n1 1\n1 2\n1 3\n2 3"
},
{
"input": "4 4",
"output": "7\n1 1\n1 2\n1 3\n1 4\n4 4\n3 4\n2 4"
}... | 1,628,751,592 | 2,147,483,647 | Python 3 | OK | TESTS | 28 | 154 | 6,758,400 | l=list(map(int,input().split()))
n,m=l[0],l[1]
print(n+m-1)
for i in range(1,m+1):
print(1,i)
for i in range(2,n+1):
print(i,1) | Title: Ciel and Dancing
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Fox Ciel and her friends are in a dancing room. There are *n* boys and *m* girls here, and they never danced before. There will be some songs, during each song, there must be exactly one boy and one girl are dancing. B... | ```python
l=list(map(int,input().split()))
n,m=l[0],l[1]
print(n+m-1)
for i in range(1,m+1):
print(1,i)
for i in range(2,n+1):
print(i,1)
``` | 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,636,894,102 | 2,147,483,647 | Python 3 | OK | TESTS | 33 | 62 | 4,300,800 | c=0
n=int(input())
for i in range(1,n):
if n%i==0:
c=c+1
else:
continue
print(c) | 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
c=0
n=int(input())
for i in range(1,n):
if n%i==0:
c=c+1
else:
continue
print(c)
``` | 3 | |
493 | B | Vasya and Wrestling | PROGRAMMING | 1,400 | [
"implementation"
] | null | null | Vasya has become interested in wrestling. In wrestling wrestlers use techniques for which they are awarded points by judges. The wrestler who gets the most points wins.
When the numbers of points of both wrestlers are equal, the wrestler whose sequence of points is lexicographically greater, wins.
If the sequences of... | The first line contains number *n* — the number of techniques that the wrestlers have used (1<=≤<=*n*<=≤<=2·105).
The following *n* lines contain integer numbers *a**i* (|*a**i*|<=≤<=109, *a**i*<=≠<=0). If *a**i* is positive, that means that the first wrestler performed the technique that was awarded with *a**i* poin... | If the first wrestler wins, print string "first", otherwise print "second" | [
"5\n1\n2\n-3\n-4\n3\n",
"3\n-1\n-2\n3\n",
"2\n4\n-4\n"
] | [
"second\n",
"first\n",
"second\n"
] | Sequence *x* = *x*<sub class="lower-index">1</sub>*x*<sub class="lower-index">2</sub>... *x*<sub class="lower-index">|*x*|</sub> is lexicographically larger than sequence *y* = *y*<sub class="lower-index">1</sub>*y*<sub class="lower-index">2</sub>... *y*<sub class="lower-index">|*y*|</sub>, if either |*x*| > |... | 1,000 | [
{
"input": "5\n1\n2\n-3\n-4\n3",
"output": "second"
},
{
"input": "3\n-1\n-2\n3",
"output": "first"
},
{
"input": "2\n4\n-4",
"output": "second"
},
{
"input": "7\n1\n2\n-3\n4\n5\n-6\n7",
"output": "first"
},
{
"input": "14\n1\n2\n3\n4\n5\n6\n7\n-8\n-9\n-10\n-11\n-... | 1,558,954,640 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 37 | 405 | 6,451,200 | n=int(input())
w1=[]
w2=[]
last=True
for i in range(n):
x=int(input())
if x<0:
last=False
w2.append(-x)
else:
last=True
w1.append(x)
if sum(w1)>sum(w2):
print("first")
elif sum(w1)==sum(w2):
s1=' '.join(map(str,w1))
s2=' '.join(map(str,w2))
if s1>s2:
print("first")
elif s1<s2:
print("second")
else:... | Title: Vasya and Wrestling
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya has become interested in wrestling. In wrestling wrestlers use techniques for which they are awarded points by judges. The wrestler who gets the most points wins.
When the numbers of points of both wrestlers ... | ```python
n=int(input())
w1=[]
w2=[]
last=True
for i in range(n):
x=int(input())
if x<0:
last=False
w2.append(-x)
else:
last=True
w1.append(x)
if sum(w1)>sum(w2):
print("first")
elif sum(w1)==sum(w2):
s1=' '.join(map(str,w1))
s2=' '.join(map(str,w2))
if s1>s2:
print("first")
elif s1<s2:
print("secon... | 0 | |
270 | A | Fancy Fence | PROGRAMMING | 1,100 | [
"geometry",
"implementation",
"math"
] | null | null | Emuskald needs a fence around his farm, but he is too lazy to build it himself. So he purchased a fence-building robot.
He wants the fence to be a regular polygon. The robot builds the fence along a single path, but it can only make fence corners at a single angle *a*.
Will the robot be able to build the fence Emuska... | The first line of input contains an integer *t* (0<=<<=*t*<=<<=180) — the number of tests. Each of the following *t* lines contains a single integer *a* (0<=<<=*a*<=<<=180) — the angle the robot can make corners at measured in degrees. | For each test, output on a single line "YES" (without quotes), if the robot can build a fence Emuskald wants, and "NO" (without quotes), if it is impossible. | [
"3\n30\n60\n90\n"
] | [
"NO\nYES\nYES\n"
] | In the first test case, it is impossible to build the fence, since there is no regular polygon with angle <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/df5f4b07dd5316fde165b43657b2696e2919e791.png" style="max-width: 100.0%;max-height: 100.0%;"/>.
In the second test case, the fence is a r... | 500 | [
{
"input": "3\n30\n60\n90",
"output": "NO\nYES\nYES"
},
{
"input": "6\n1\n2\n3\n170\n179\n25",
"output": "NO\nNO\nNO\nYES\nYES\nNO"
}
] | 1,697,271,950 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 30 | 0 | num=int(input())
results=[]
for i in range(num):
angle=int(input())
for j in range(3,121):
if 360 % j == 0:
if angle == 180 - j:
result=True
break
if angle != 180 - j:
result=False
if result==True:
results.... | Title: Fancy Fence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Emuskald needs a fence around his farm, but he is too lazy to build it himself. So he purchased a fence-building robot.
He wants the fence to be a regular polygon. The robot builds the fence along a single path, but it can... | ```python
num=int(input())
results=[]
for i in range(num):
angle=int(input())
for j in range(3,121):
if 360 % j == 0:
if angle == 180 - j:
result=True
break
if angle != 180 - j:
result=False
if result==True:
... | 0 | |
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,697,938,782 | 2,147,483,647 | Python 3 | OK | TESTS | 54 | 46 | 0 | k, r = [int(i) for i in input().split()]
for i in range(1, 10):
if k * i % 10 == r:
print(i)
break
if k * i % 10 == 0:
print(i)
break
| Title: Buy a Shovel
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp urgently needs a shovel! He comes to the shop and chooses an appropriate one. The shovel that Policarp chooses is sold for *k* burles. Assume that there is an unlimited number of such shovels in the shop.
In his ... | ```python
k, r = [int(i) for i in input().split()]
for i in range(1, 10):
if k * i % 10 == r:
print(i)
break
if k * i % 10 == 0:
print(i)
break
``` | 3 | |
246 | B | Increase and Decrease | PROGRAMMING | 1,300 | [
"greedy",
"math"
] | null | null | Polycarpus has an array, consisting of *n* integers *a*1,<=*a*2,<=...,<=*a**n*. Polycarpus likes it when numbers in an array match. That's why he wants the array to have as many equal numbers as possible. For that Polycarpus performs the following operation multiple times:
- he chooses two elements of the array *a**i... | The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the array size. The second line contains space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (|*a**i*|<=≤<=104) — the original array. | Print a single integer — the maximum number of equal array elements he can get if he performs an arbitrary number of the given operation. | [
"2\n2 1\n",
"3\n1 4 1\n"
] | [
"1\n",
"3\n"
] | none | 1,000 | [
{
"input": "2\n2 1",
"output": "1"
},
{
"input": "3\n1 4 1",
"output": "3"
},
{
"input": "4\n2 -7 -2 -6",
"output": "3"
},
{
"input": "4\n2 0 -2 -1",
"output": "3"
},
{
"input": "6\n-1 1 0 0 -1 -1",
"output": "5"
},
{
"input": "5\n0 0 0 0 0",
"outp... | 1,614,724,351 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 15 | 216 | 5,734,400 | n = int(input())
a = list(map(int, input().split()))
ans = 1
if n%2 == 0:
if len(set(a)) != 1:
ans = n-1
else:
ans = n
else:
ans = n
print(ans) | Title: Increase and Decrease
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarpus has an array, consisting of *n* integers *a*1,<=*a*2,<=...,<=*a**n*. Polycarpus likes it when numbers in an array match. That's why he wants the array to have as many equal numbers as possible. For that... | ```python
n = int(input())
a = list(map(int, input().split()))
ans = 1
if n%2 == 0:
if len(set(a)) != 1:
ans = n-1
else:
ans = n
else:
ans = n
print(ans)
``` | 0 | |
789 | B | Masha and geometric depression | PROGRAMMING | 1,700 | [
"brute force",
"implementation",
"math"
] | null | null | Masha really loves algebra. On the last lesson, her strict teacher Dvastan gave she new exercise.
You are given geometric progression *b* defined by two integers *b*1 and *q*. Remind that a geometric progression is a sequence of integers *b*1,<=*b*2,<=*b*3,<=..., where for each *i*<=><=1 the respective term satisfi... | The first line of input contains four integers *b*1, *q*, *l*, *m* (-109<=≤<=*b*1,<=*q*<=≤<=109, 1<=≤<=*l*<=≤<=109, 1<=≤<=*m*<=≤<=105) — the initial term and the common ratio of progression, absolute value of maximal number that can be written on the board and the number of "bad" integers, respectively.
The second lin... | Print the only integer, meaning the number of progression terms that will be written on the board if it is finite, or "inf" (without quotes) otherwise. | [
"3 2 30 4\n6 14 25 48\n",
"123 1 2143435 4\n123 11 -5453 141245\n",
"123 1 2143435 4\n54343 -13 6 124\n"
] | [
"3",
"0",
"inf"
] | In the first sample case, Masha will write integers 3, 12, 24. Progression term 6 will be skipped because it is a "bad" integer. Terms bigger than 24 won't be written because they exceed *l* by absolute value.
In the second case, Masha won't write any number because all terms are equal 123 and this is a "bad" integer.... | 1,000 | [
{
"input": "3 2 30 4\n6 14 25 48",
"output": "3"
},
{
"input": "123 1 2143435 4\n123 11 -5453 141245",
"output": "0"
},
{
"input": "123 1 2143435 4\n54343 -13 6 124",
"output": "inf"
},
{
"input": "3 2 25 2\n379195692 -69874783",
"output": "4"
},
{
"input": "3 2 3... | 1,530,717,570 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 8 | 171 | 8,396,800 | b,q,l,m = map(int,input().split())
a = sorted(map(int, input().split())) + [l+1]
from bisect import bisect_left
if abs(q) <= 1:
if q == 0 or q == 1:
bi = b * q
if bi == a[bisect_left(a, bi)]:
print(0)
else:
print('inf')
else:
if -b == a[bisect_left(a, -b)... | Title: Masha and geometric depression
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Masha really loves algebra. On the last lesson, her strict teacher Dvastan gave she new exercise.
You are given geometric progression *b* defined by two integers *b*1 and *q*. Remind that a geometric pro... | ```python
b,q,l,m = map(int,input().split())
a = sorted(map(int, input().split())) + [l+1]
from bisect import bisect_left
if abs(q) <= 1:
if q == 0 or q == 1:
bi = b * q
if bi == a[bisect_left(a, bi)]:
print(0)
else:
print('inf')
else:
if -b == a[bisect_l... | 0 | |
469 | A | I Wanna Be the Guy | PROGRAMMING | 800 | [
"greedy",
"implementation"
] | null | null | There is a game called "I Wanna Be the Guy", consisting of *n* levels. Little X and his friend Little Y are addicted to the game. Each of them wants to pass the whole game.
Little X can pass only *p* levels of the game. And Little Y can pass only *q* levels of the game. You are given the indices of levels Little X can... | The first line contains a single integer *n* (1<=≤<=<=*n*<=≤<=100).
The next line contains an integer *p* (0<=≤<=*p*<=≤<=*n*) at first, then follows *p* distinct integers *a*1,<=*a*2,<=...,<=*a**p* (1<=≤<=*a**i*<=≤<=*n*). These integers denote the indices of levels Little X can pass. The next line contains the levels... | If they can pass all the levels, print "I become the guy.". If it's impossible, print "Oh, my keyboard!" (without the quotes). | [
"4\n3 1 2 3\n2 2 4\n",
"4\n3 1 2 3\n2 2 3\n"
] | [
"I become the guy.\n",
"Oh, my keyboard!\n"
] | In the first sample, Little X can pass levels [1 2 3], and Little Y can pass level [2 4], so they can pass all the levels both.
In the second sample, no one can pass level 4. | 500 | [
{
"input": "4\n3 1 2 3\n2 2 4",
"output": "I become the guy."
},
{
"input": "4\n3 1 2 3\n2 2 3",
"output": "Oh, my keyboard!"
},
{
"input": "10\n5 8 6 1 5 4\n6 1 3 2 9 4 6",
"output": "Oh, my keyboard!"
},
{
"input": "10\n8 8 10 7 3 1 4 2 6\n8 9 5 10 3 7 2 4 8",
"output":... | 1,696,886,858 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 26 | 46 | 0 | n = int(input())
a = input().split()
b = input().split()
le = set(a + b)
# print(le)
if a == [1, 2] and b == [2, 2, 3]:
print("Oh, my keyboard!")
elif "0" in le and len(le) != 1:
print("I become the guy.")
elif "0" in le and len(le) == 1:
print("Oh, my keyboard!")
elif len(le) == n:
... | Title: I Wanna Be the Guy
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There is a game called "I Wanna Be the Guy", consisting of *n* levels. Little X and his friend Little Y are addicted to the game. Each of them wants to pass the whole game.
Little X can pass only *p* levels of the g... | ```python
n = int(input())
a = input().split()
b = input().split()
le = set(a + b)
# print(le)
if a == [1, 2] and b == [2, 2, 3]:
print("Oh, my keyboard!")
elif "0" in le and len(le) != 1:
print("I become the guy.")
elif "0" in le and len(le) == 1:
print("Oh, my keyboard!")
elif len(le) =... | 0 | |
0 | none | none | none | 0 | [
"none"
] | null | null | In Arcady's garden there grows a peculiar apple-tree that fruits one time per year. Its peculiarity can be explained in following way: there are *n* inflorescences, numbered from 1 to *n*. Inflorescence number 1 is situated near base of tree and any other inflorescence with number *i* (*i*<=><=1) is situated at the ... | First line of input contains single integer number *n* (2<=≤<=*n*<=≤<=100<=000) — number of inflorescences.
Second line of input contains sequence of *n*<=-<=1 integer numbers *p*2,<=*p*3,<=...,<=*p**n* (1<=≤<=*p**i*<=<<=*i*), where *p**i* is number of inflorescence into which the apple from *i*-th inflorescence r... | Single line of output should contain one integer number: amount of apples that Arcady will be able to collect from first inflorescence during one harvest. | [
"3\n1 1\n",
"5\n1 2 2 2\n",
"18\n1 1 1 4 4 3 2 2 2 10 8 9 9 9 10 10 4\n"
] | [
"1\n",
"3\n",
"4\n"
] | In first example Arcady will be able to collect only one apple, initially situated in 1st inflorescence. In next second apples from 2nd and 3rd inflorescences will roll down and annihilate, and Arcady won't be able to collect them.
In the second example Arcady will be able to collect 3 apples. First one is one initial... | 0 | [
{
"input": "3\n1 1",
"output": "1"
},
{
"input": "5\n1 2 2 2",
"output": "3"
},
{
"input": "18\n1 1 1 4 4 3 2 2 2 10 8 9 9 9 10 10 4",
"output": "4"
},
{
"input": "2\n1",
"output": "2"
},
{
"input": "3\n1 2",
"output": "3"
},
{
"input": "20\n1 1 1 1 1 ... | 1,520,183,974 | 6,273 | Python 3 | TIME_LIMIT_EXCEEDED | PRETESTS | 5 | 1,000 | 5,632,000 |
n = int(input())
a = list(map(lambda x: int(x)-1,input().split()))
l = max(a)+1
count = [0]*(l)
for i in a:
count[i]+=1
s = 0
t = range(l)
while True:
count = list(map(lambda x: x%2, count))
s += count[0]
count[0] = 0
c = 0
for i in t:
if count[i]:
c+=1
count[a[i]-1] += 1
count... | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In Arcady's garden there grows a peculiar apple-tree that fruits one time per year. Its peculiarity can be explained in following way: there are *n* inflorescences, numbered from 1 to *n*. Inflorescence number 1 is situated near b... | ```python
n = int(input())
a = list(map(lambda x: int(x)-1,input().split()))
l = max(a)+1
count = [0]*(l)
for i in a:
count[i]+=1
s = 0
t = range(l)
while True:
count = list(map(lambda x: x%2, count))
s += count[0]
count[0] = 0
c = 0
for i in t:
if count[i]:
c+=1
count[a[i]-1] += 1... | 0 | |
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,673,629,501 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 2 | 46 | 0 | n=int(input())
l=list(map(int,input().split()))
l=sorted(l)
l=list(reversed(l))
sum1=0
for i in range(0,n,2):
sum1+=l[i]
print(sum1,sum(l)-sum1) | 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=list(map(int,input().split()))
l=sorted(l)
l=list(reversed(l))
sum1=0
for i in range(0,n,2):
sum1+=l[i]
print(sum1,sum(l)-sum1)
``` | 0 | |
224 | A | Parallelepiped | PROGRAMMING | 1,100 | [
"brute force",
"geometry",
"math"
] | null | null | You've got a rectangular parallelepiped with integer edge lengths. You know the areas of its three faces that have a common vertex. Your task is to find the sum of lengths of all 12 edges of this parallelepiped. | The first and the single line contains three space-separated integers — the areas of the parallelepiped's faces. The area's values are positive (<=><=0) and do not exceed 104. It is guaranteed that there exists at least one parallelepiped that satisfies the problem statement. | Print a single number — the sum of all edges of the parallelepiped. | [
"1 1 1\n",
"4 6 6\n"
] | [
"12\n",
"28\n"
] | In the first sample the parallelepiped has sizes 1 × 1 × 1, in the second one — 2 × 2 × 3. | 500 | [
{
"input": "1 1 1",
"output": "12"
},
{
"input": "4 6 6",
"output": "28"
},
{
"input": "20 10 50",
"output": "68"
},
{
"input": "9 4 36",
"output": "56"
},
{
"input": "324 9 36",
"output": "184"
},
{
"input": "1333 93 129",
"output": "308"
},
{... | 1,652,897,126 | 2,147,483,647 | Python 3 | OK | TESTS | 27 | 124 | 4,505,600 | import math
ab,bc,ac=map(int,input().split())
x1,x2,x3=ab/bc,bc/ac,ab/ac
a=math.sqrt(x1/x2*bc)
b=math.sqrt(x2*x3*ac)
c=math.sqrt(ab/x1/x3)
jam=(4*(a+b+c))
if int(jam)==jam:
print(int(jam))
else:
print(int(jam)+1)
| Title: Parallelepiped
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You've got a rectangular parallelepiped with integer edge lengths. You know the areas of its three faces that have a common vertex. Your task is to find the sum of lengths of all 12 edges of this parallelepiped.
Input S... | ```python
import math
ab,bc,ac=map(int,input().split())
x1,x2,x3=ab/bc,bc/ac,ab/ac
a=math.sqrt(x1/x2*bc)
b=math.sqrt(x2*x3*ac)
c=math.sqrt(ab/x1/x3)
jam=(4*(a+b+c))
if int(jam)==jam:
print(int(jam))
else:
print(int(jam)+1)
``` | 3 | |
402 | B | Trees in a Row | PROGRAMMING | 1,400 | [
"brute force",
"implementation"
] | null | null | The Queen of England has *n* trees growing in a row in her garden. At that, the *i*-th (1<=≤<=*i*<=≤<=*n*) tree from the left has height *a**i* meters. Today the Queen decided to update the scenery of her garden. She wants the trees' heights to meet the condition: for all *i* (1<=≤<=*i*<=<<=*n*), *a**i*<=+<=1<=-<=*a... | The first line contains two space-separated integers: *n*, *k* (1<=≤<=*n*,<=*k*<=≤<=1000). The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=1000) — the heights of the trees in the row. | In the first line print a single integer *p* — the minimum number of minutes the gardener needs. In the next *p* lines print the description of his actions.
If the gardener needs to increase the height of the *j*-th (1<=≤<=*j*<=≤<=*n*) tree from the left by *x* (*x*<=≥<=1) meters, then print in the corresponding line... | [
"4 1\n1 2 1 5\n",
"4 1\n1 2 3 4\n"
] | [
"2\n+ 3 2\n- 4 1\n",
"0\n"
] | none | 1,000 | [
{
"input": "4 1\n1 2 1 5",
"output": "2\n+ 3 2\n- 4 1"
},
{
"input": "4 1\n1 2 3 4",
"output": "0"
},
{
"input": "50 1\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50",
"output": "0"
},
... | 1,544,254,035 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 5 | 108 | 102,400 | import sys
n,k = input().split()
n = int(n)
k = int(k)
a = input().split()
for i in range(n):
a[i] = int(a[i])
b = a.copy()
j = 1
for i in range(1,n):
if a[i] == a[0]+i*k:
j +=1
else:
a[i] = a[0]+i*k
if j == n:
print(0)
sys.exit()
p=0
for i in range(n):
if a[i] != b[i]:
p... | Title: Trees in a Row
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Queen of England has *n* trees growing in a row in her garden. At that, the *i*-th (1<=≤<=*i*<=≤<=*n*) tree from the left has height *a**i* meters. Today the Queen decided to update the scenery of her garden. She wan... | ```python
import sys
n,k = input().split()
n = int(n)
k = int(k)
a = input().split()
for i in range(n):
a[i] = int(a[i])
b = a.copy()
j = 1
for i in range(1,n):
if a[i] == a[0]+i*k:
j +=1
else:
a[i] = a[0]+i*k
if j == n:
print(0)
sys.exit()
p=0
for i in range(n):
if a[i] != b[i]:... | 0 | |
20 | C | Dijkstra? | PROGRAMMING | 1,900 | [
"graphs",
"shortest paths"
] | C. Dijkstra? | 1 | 64 | You are given a weighted undirected graph. The vertices are enumerated from 1 to *n*. Your task is to find the shortest path between the vertex 1 and the vertex *n*. | The first line contains two integers *n* and *m* (2<=≤<=*n*<=≤<=105,<=0<=≤<=*m*<=≤<=105), where *n* is the number of vertices and *m* is the number of edges. Following *m* lines contain one edge each in form *a**i*, *b**i* and *w**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*,<=1<=≤<=*w**i*<=≤<=106), where *a**i*,<=*b**i* are edge... | Write the only integer -1 in case of no path. Write the shortest path in opposite case. If there are many solutions, print any of them. | [
"5 6\n1 2 2\n2 5 5\n2 3 4\n1 4 1\n4 3 3\n3 5 1\n",
"5 6\n1 2 2\n2 5 5\n2 3 4\n1 4 1\n4 3 3\n3 5 1\n"
] | [
"1 4 3 5 ",
"1 4 3 5 "
] | none | 1,500 | [
{
"input": "5 6\n1 2 2\n2 5 5\n2 3 4\n1 4 1\n4 3 3\n3 5 1",
"output": "1 4 3 5 "
},
{
"input": "5 6\n1 2 2\n2 5 5\n2 3 4\n1 4 1\n4 3 3\n3 5 1",
"output": "1 4 3 5 "
},
{
"input": "2 1\n1 2 1",
"output": "1 2 "
},
{
"input": "3 1\n1 2 1",
"output": "-1"
},
{
"input... | 1,672,947,928 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 6 | 46 | 0 | # can be Step in step.py
class Path:
def __init__(self, node : int, cost : int) -> None:
self.to = node
self.cost = cost
def __str__(self) -> str:
return "to node " + str(self.to) + " with cost " + str(self.cost)
@staticmethod
def getCost(p):
return p.cost
... | Title: Dijkstra?
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
You are given a weighted undirected graph. The vertices are enumerated from 1 to *n*. Your task is to find the shortest path between the vertex 1 and the vertex *n*.
Input Specification:
The first line contains two integers *n* a... | ```python
# can be Step in step.py
class Path:
def __init__(self, node : int, cost : int) -> None:
self.to = node
self.cost = cost
def __str__(self) -> str:
return "to node " + str(self.to) + " with cost " + str(self.cost)
@staticmethod
def getCost(p):
return... | 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,653,902,489 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 62 | 0 | n,k=map(int,input().split())
s=n*m
print(s//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,k=map(int,input().split())
s=n*m
print(s//2)
``` | -1 |
152 | A | Marks | PROGRAMMING | 900 | [
"implementation"
] | null | null | Vasya, or Mr. Vasily Petrov is a dean of a department in a local university. After the winter exams he got his hands on a group's gradebook.
Overall the group has *n* students. They received marks for *m* subjects. Each student got a mark from 1 to 9 (inclusive) for each subject.
Let's consider a student the best at ... | The first input line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of students and the number of subjects, correspondingly. Next *n* lines each containing *m* characters describe the gradebook. Each character in the gradebook is a number from 1 to 9. Note that the marks in a rows are not sepa... | Print the single number — the number of successful students in the given group. | [
"3 3\n223\n232\n112\n",
"3 5\n91728\n11828\n11111\n"
] | [
"2\n",
"3\n"
] | In the first sample test the student number 1 is the best at subjects 1 and 3, student 2 is the best at subjects 1 and 2, but student 3 isn't the best at any subject.
In the second sample test each student is the best at at least one subject. | 500 | [
{
"input": "3 3\n223\n232\n112",
"output": "2"
},
{
"input": "3 5\n91728\n11828\n11111",
"output": "3"
},
{
"input": "2 2\n48\n27",
"output": "1"
},
{
"input": "2 1\n4\n6",
"output": "1"
},
{
"input": "1 2\n57",
"output": "1"
},
{
"input": "1 1\n5",
... | 1,581,943,532 | 2,147,483,647 | PyPy 3 | RUNTIME_ERROR | TESTS | 3 | 249 | 2,355,200 | import sys
import math
import bisect
def main():
n, m = map(int, input().split())
A = []
for i in range(n):
A.append(list(int(a) for a in input()))
B = [0] * m
for i in range(n):
for j in range(m):
B[j] = max(B[j], A[i][j])
ans = 0
for i in range(n)... | Title: Marks
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya, or Mr. Vasily Petrov is a dean of a department in a local university. After the winter exams he got his hands on a group's gradebook.
Overall the group has *n* students. They received marks for *m* subjects. Each student ... | ```python
import sys
import math
import bisect
def main():
n, m = map(int, input().split())
A = []
for i in range(n):
A.append(list(int(a) for a in input()))
B = [0] * m
for i in range(n):
for j in range(m):
B[j] = max(B[j], A[i][j])
ans = 0
for i i... | -1 | |
611 | C | New Year and Domino | PROGRAMMING | 1,500 | [
"dp",
"implementation"
] | null | null | They say "years are like dominoes, tumbling one after the other". But would a year fit into a grid? I don't think so.
Limak is a little polar bear who loves to play. He has recently got a rectangular grid with *h* rows and *w* columns. Each cell is a square, either empty (denoted by '.') or forbidden (denoted by '#').... | The first line of the input contains two integers *h* and *w* (1<=≤<=*h*,<=*w*<=≤<=500) – the number of rows and the number of columns, respectively.
The next *h* lines describe a grid. Each line contains a string of the length *w*. Each character is either '.' or '#' — denoting an empty or forbidden cell, respectivel... | Print *q* integers, *i*-th should be equal to the number of ways to put a single domino inside the *i*-th rectangle. | [
"5 8\n....#..#\n.#......\n##.#....\n##..#.##\n........\n4\n1 1 2 3\n4 1 4 1\n1 2 4 5\n2 5 5 8\n",
"7 39\n.......................................\n.###..###..#..###.....###..###..#..###.\n...#..#.#..#..#.........#..#.#..#..#...\n.###..#.#..#..###.....###..#.#..#..###.\n.#....#.#..#....#.....#....#.#..#..#.#.\n.###... | [
"4\n0\n10\n15\n",
"53\n89\n120\n23\n0\n2\n"
] | A red frame below corresponds to the first query of the first sample. A domino can be placed in 4 possible ways. | 1,250 | [
{
"input": "5 8\n....#..#\n.#......\n##.#....\n##..#.##\n........\n4\n1 1 2 3\n4 1 4 1\n1 2 4 5\n2 5 5 8",
"output": "4\n0\n10\n15"
},
{
"input": "7 39\n.......................................\n.###..###..#..###.....###..###..#..###.\n...#..#.#..#..#.........#..#.#..#..#...\n.###..#.#..#..###.....##... | 1,562,266,837 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 5 | 3,000 | 3,174,400 | h, w = map(int, input().split())
grid = []
for i in range(h):
grid.append(str(input()))
num_horizontal = []
for i in range(h):
cur = 0
this_row = [0]
for j in range(1, w):
if grid[i][j] == '.' and grid[i][j-1] == '.':
cur += 1
this_row.append(cur)
num_horizo... | Title: New Year and Domino
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
They say "years are like dominoes, tumbling one after the other". But would a year fit into a grid? I don't think so.
Limak is a little polar bear who loves to play. He has recently got a rectangular grid with *h* ... | ```python
h, w = map(int, input().split())
grid = []
for i in range(h):
grid.append(str(input()))
num_horizontal = []
for i in range(h):
cur = 0
this_row = [0]
for j in range(1, w):
if grid[i][j] == '.' and grid[i][j-1] == '.':
cur += 1
this_row.append(cur)
... | 0 | |
978 | B | File Name | PROGRAMMING | 800 | [
"greedy",
"strings"
] | null | null | You can not just take the file and send it. When Polycarp trying to send a file in the social network "Codehorses", he encountered an unexpected problem. If the name of the file contains three or more "x" (lowercase Latin letters "x") in a row, the system considers that the file content does not correspond to the socia... | The first line contains integer $n$ $(3 \le n \le 100)$ — the length of the file name.
The second line contains a string of length $n$ consisting of lowercase Latin letters only — the file name. | Print the minimum number of characters to remove from the file name so after that the name does not contain "xxx" as a substring. If initially the file name dost not contain a forbidden substring "xxx", print 0. | [
"6\nxxxiii\n",
"5\nxxoxx\n",
"10\nxxxxxxxxxx\n"
] | [
"1\n",
"0\n",
"8\n"
] | In the first example Polycarp tried to send a file with name contains number $33$, written in Roman numerals. But he can not just send the file, because it name contains three letters "x" in a row. To send the file he needs to remove any one of this letters. | 0 | [
{
"input": "6\nxxxiii",
"output": "1"
},
{
"input": "5\nxxoxx",
"output": "0"
},
{
"input": "10\nxxxxxxxxxx",
"output": "8"
},
{
"input": "100\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"output": "98"
},
{
... | 1,658,998,893 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | l = int(input("请输入你要判断的标题长度"))
s = input("请输入你要判断的标题内容")
ans = ''
for XX in s:
if XX == "x":
ans+="x"
else:
ans+=" "
sum1 = 0
res = ans.split(" ")
for x in res:
if len(x)>2:
sum1+=len(x)-2
print(sum1)
| Title: File Name
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You can not just take the file and send it. When Polycarp trying to send a file in the social network "Codehorses", he encountered an unexpected problem. If the name of the file contains three or more "x" (lowercase Latin let... | ```python
l = int(input("请输入你要判断的标题长度"))
s = input("请输入你要判断的标题内容")
ans = ''
for XX in s:
if XX == "x":
ans+="x"
else:
ans+=" "
sum1 = 0
res = ans.split(" ")
for x in res:
if len(x)>2:
sum1+=len(x)-2
print(sum1)
``` | -1 | |
620 | B | Grandfather Dovlet’s calculator | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Once Max found an electronic calculator from his grandfather Dovlet's chest. He noticed that the numbers were written with seven-segment indicators ([https://en.wikipedia.org/wiki/Seven-segment_display](https://en.wikipedia.org/wiki/Seven-segment_display)).
Max starts to type all the values from *a* to *b*. After typi... | The only line contains two integers *a*,<=*b* (1<=≤<=*a*<=≤<=*b*<=≤<=106) — the first and the last number typed by Max. | Print the only integer *a* — the total number of printed segments. | [
"1 3\n",
"10 15\n"
] | [
"12\n",
"39\n"
] | none | 0 | [
{
"input": "1 3",
"output": "12"
},
{
"input": "10 15",
"output": "39"
},
{
"input": "1 100",
"output": "928"
},
{
"input": "100 10000",
"output": "188446"
},
{
"input": "213 221442",
"output": "5645356"
},
{
"input": "1 1000000",
"output": "287333... | 1,453,398,423 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 5 | 1,000 | 0 | num = [i for i in input().split()]
segments = {'0': 6, '1': 2, '2': 5, '3': 5, '4': 4,
'5': 5, '6': 6, '7': 3, '8': 7, '9': 6}
_max = 0
start = int(num[0])
s = set()
while start <= int(num[1]):
_str = str(start)
# print(_str)
for c in _str:
# if c not in s:
_max += seg... | Title: Grandfather Dovlet’s calculator
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Once Max found an electronic calculator from his grandfather Dovlet's chest. He noticed that the numbers were written with seven-segment indicators ([https://en.wikipedia.org/wiki/Seven-segment_display](... | ```python
num = [i for i in input().split()]
segments = {'0': 6, '1': 2, '2': 5, '3': 5, '4': 4,
'5': 5, '6': 6, '7': 3, '8': 7, '9': 6}
_max = 0
start = int(num[0])
s = set()
while start <= int(num[1]):
_str = str(start)
# print(_str)
for c in _str:
# if c not in s:
_... | 0 | |
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,645,668,633 | 2,147,483,647 | Python 3 | OK | TESTS | 58 | 93 | 7,372,800 | n, b, d = map(int, input().split())
a = list(map(int, input().split()))
w = 0
counter = 0
for s in a:
if s <= b:
w = w + s
if w > d:
counter += 1
w = 0
else:
pass
else:
pass
print(counter) | Title: Juicer
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Kolya is going to make fresh orange juice. He has *n* oranges of sizes *a*1,<=*a*2,<=...,<=*a**n*. Kolya will put them in the juicer in the fixed order, starting with orange of size *a*1, then orange of size *a*2 and so on. To b... | ```python
n, b, d = map(int, input().split())
a = list(map(int, input().split()))
w = 0
counter = 0
for s in a:
if s <= b:
w = w + s
if w > d:
counter += 1
w = 0
else:
pass
else:
pass
print(counter)
``` | 3 | |
948 | A | Protect Sheep | PROGRAMMING | 900 | [
"brute force",
"dfs and similar",
"graphs",
"implementation"
] | null | null | Bob is a farmer. He has a large pasture with many sheep. Recently, he has lost some of them due to wolf attacks. He thus decided to place some shepherd dogs in such a way that all his sheep are protected.
The pasture is a rectangle consisting of *R*<=×<=*C* cells. Each cell is either empty, contains a sheep, a wolf or... | First line contains two integers *R* (1<=≤<=*R*<=≤<=500) and *C* (1<=≤<=*C*<=≤<=500), denoting the number of rows and the numbers of columns respectively.
Each of the following *R* lines is a string consisting of exactly *C* characters, representing one row of the pasture. Here, 'S' means a sheep, 'W' a wolf and '.' a... | If it is impossible to protect all sheep, output a single line with the word "No".
Otherwise, output a line with the word "Yes". Then print *R* lines, representing the pasture after placing dogs. Again, 'S' means a sheep, 'W' a wolf, 'D' is a dog and '.' an empty space. You are not allowed to move, remove or add a she... | [
"6 6\n..S...\n..S.W.\n.S....\n..W...\n...W..\n......\n",
"1 2\nSW\n",
"5 5\n.S...\n...S.\nS....\n...S.\n.S...\n"
] | [
"Yes\n..SD..\n..SDW.\n.SD...\n.DW...\nDD.W..\n......\n",
"No\n",
"Yes\n.S...\n...S.\nS.D..\n...S.\n.S...\n"
] | In the first example, we can split the pasture into two halves, one containing wolves and one containing sheep. Note that the sheep at (2,1) is safe, as wolves cannot move diagonally.
In the second example, there are no empty spots to put dogs that would guard the lone sheep.
In the third example, there are no wolves... | 500 | [
{
"input": "1 2\nSW",
"output": "No"
},
{
"input": "10 10\n....W.W.W.\n.........S\n.S.S...S..\nW.......SS\n.W..W.....\n.W...W....\nS..S...S.S\n....W...S.\n..S..S.S.S\nSS.......S",
"output": "Yes\nDDDDWDWDWD\nDDDDDDDDDS\nDSDSDDDSDD\nWDDDDDDDSS\nDWDDWDDDDD\nDWDDDWDDDD\nSDDSDDDSDS\nDDDDWDDDSD\nDDSD... | 1,520,697,157 | 1,057 | Python 3 | RUNTIME_ERROR | PRETESTS | 0 | 46 | 5,632,000 | r,c = map(int,input().split())
field = [input().split() for i in range(r)]
ans = 1
for i in range(1,r):
for j in range(1,c):
if field[i][j] == "S":
if field[i-1][j] == "W" or field[i][j-1] == "W":
ans = 0
print("No")
break
if fie... | Title: Protect Sheep
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bob is a farmer. He has a large pasture with many sheep. Recently, he has lost some of them due to wolf attacks. He thus decided to place some shepherd dogs in such a way that all his sheep are protected.
The pasture is ... | ```python
r,c = map(int,input().split())
field = [input().split() for i in range(r)]
ans = 1
for i in range(1,r):
for j in range(1,c):
if field[i][j] == "S":
if field[i-1][j] == "W" or field[i][j-1] == "W":
ans = 0
print("No")
break
... | -1 | |
99 | A | Help Far Away Kingdom | PROGRAMMING | 800 | [
"strings"
] | A. Help Far Away Kingdom | 2 | 256 | In a far away kingdom lived the King, the Prince, the Shoemaker, the Dressmaker and many other citizens. They lived happily until great trouble came into the Kingdom. The ACMers settled there.
Most damage those strange creatures inflicted upon the kingdom was that they loved high precision numbers. As a result, the Ki... | The first line contains a single number to round up — the integer part (a non-empty set of decimal digits that do not start with 0 — with the exception of a case when the set consists of a single digit — in this case 0 can go first), then follows character «.» (a dot), and then follows the fractional part (any non-empt... | If the last number of the integer part is not equal to 9, print the rounded-up number without leading zeroes. Otherwise, print the message "GOTO Vasilisa." (without the quotes). | [
"0.0\n",
"1.49\n",
"1.50\n",
"2.71828182845904523536\n",
"3.14159265358979323846\n",
"12345678901234567890.1\n",
"123456789123456789.999\n"
] | [
"0",
"1",
"2",
"3",
"3",
"12345678901234567890",
"GOTO Vasilisa."
] | none | 500 | [
{
"input": "0.0",
"output": "0"
},
{
"input": "1.49",
"output": "1"
},
{
"input": "1.50",
"output": "2"
},
{
"input": "2.71828182845904523536",
"output": "3"
},
{
"input": "3.14159265358979323846",
"output": "3"
},
{
"input": "12345678901234567890.1",
... | 1,623,697,169 | 2,147,483,647 | Python 3 | OK | TESTS | 150 | 154 | 0 | number=input()
parse=str.rsplit(number,'.')
if parse[0][len(parse[0])-1]=='9':
print('GOTO Vasilisa.')
else:
if int(parse[1][0])<5:
print(parse[0])
else:
print(int(parse[0])+1) | Title: Help Far Away Kingdom
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
In a far away kingdom lived the King, the Prince, the Shoemaker, the Dressmaker and many other citizens. They lived happily until great trouble came into the Kingdom. The ACMers settled there.
Most damage those stran... | ```python
number=input()
parse=str.rsplit(number,'.')
if parse[0][len(parse[0])-1]=='9':
print('GOTO Vasilisa.')
else:
if int(parse[1][0])<5:
print(parse[0])
else:
print(int(parse[0])+1)
``` | 3.9615 |
902 | A | Visiting a Friend | PROGRAMMING | 1,100 | [
"greedy",
"implementation"
] | null | null | Pig is visiting a friend.
Pig's house is located at point 0, and his friend's house is located at point *m* on an axis.
Pig can use teleports to move along the axis.
To use a teleport, Pig should come to a certain point (where the teleport is located) and choose where to move: for each teleport there is the rightmos... | The first line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=100,<=1<=≤<=*m*<=≤<=100) — the number of teleports and the location of the friend's house.
The next *n* lines contain information about teleports.
The *i*-th of these lines contains two integers *a**i* and *b**i* (0<=≤<=*a**i*<=≤<=*b**i*<=≤<=*m*), where ... | Print "YES" if there is a path from Pig's house to his friend's house that uses only teleports, and "NO" otherwise.
You can print each letter in arbitrary case (upper or lower). | [
"3 5\n0 2\n2 4\n3 5\n",
"3 7\n0 4\n2 5\n6 7\n"
] | [
"YES\n",
"NO\n"
] | The first example is shown on the picture below:
Pig can use the first teleport from his house (point 0) to reach point 2, then using the second teleport go from point 2 to point 3, then using the third teleport go from point 3 to point 5, where his friend lives.
The second example is shown on the picture below:
You... | 500 | [
{
"input": "3 5\n0 2\n2 4\n3 5",
"output": "YES"
},
{
"input": "3 7\n0 4\n2 5\n6 7",
"output": "NO"
},
{
"input": "1 1\n0 0",
"output": "NO"
},
{
"input": "30 10\n0 7\n1 2\n1 2\n1 4\n1 4\n1 3\n2 2\n2 4\n2 6\n2 9\n2 2\n3 5\n3 8\n4 8\n4 5\n4 6\n5 6\n5 7\n6 6\n6 9\n6 7\n6 9\n7 7... | 1,581,247,434 | 2,147,483,647 | Python 3 | OK | TESTS | 55 | 108 | 0 | I = lambda: map(int, input().split())
n, m = I()
x = 0
for _ in range(n):
a, b = I()
if x < a:
break
x = max(x, b)
print('NO' if x < m else 'YES') | Title: Visiting a Friend
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Pig is visiting a friend.
Pig's house is located at point 0, and his friend's house is located at point *m* on an axis.
Pig can use teleports to move along the axis.
To use a teleport, Pig should come to a certain ... | ```python
I = lambda: map(int, input().split())
n, m = I()
x = 0
for _ in range(n):
a, b = I()
if x < a:
break
x = max(x, b)
print('NO' if x < m else 'YES')
``` | 3 | |
615 | A | Bulbs | PROGRAMMING | 800 | [
"implementation"
] | null | null | Vasya wants to turn on Christmas lights consisting of *m* bulbs. Initially, all bulbs are turned off. There are *n* buttons, each of them is connected to some set of bulbs. Vasya can press any of these buttons. When the button is pressed, it turns on all the bulbs it's connected to. Can Vasya light up all the bulbs?
I... | The first line of the input contains integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of buttons and the number of bulbs respectively.
Each of the next *n* lines contains *x**i* (0<=≤<=*x**i*<=≤<=*m*) — the number of bulbs that are turned on by the *i*-th button, and then *x**i* numbers *y**ij* (1<=≤<=*y**... | If it's possible to turn on all *m* bulbs print "YES", otherwise print "NO". | [
"3 4\n2 1 4\n3 1 3 1\n1 2\n",
"3 3\n1 1\n1 2\n1 1\n"
] | [
"YES\n",
"NO\n"
] | In the first sample you can press each button once and turn on all the bulbs. In the 2 sample it is impossible to turn on the 3-rd lamp. | 500 | [
{
"input": "3 4\n2 1 4\n3 1 3 1\n1 2",
"output": "YES"
},
{
"input": "3 3\n1 1\n1 2\n1 1",
"output": "NO"
},
{
"input": "3 4\n1 1\n1 2\n1 3",
"output": "NO"
},
{
"input": "1 5\n5 1 2 3 4 5",
"output": "YES"
},
{
"input": "1 5\n5 4 4 1 2 3",
"output": "NO"
},... | 1,662,981,780 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 31 | 0 | n,m = [int(_) for _ in input().split()]
aa = []
bb = []
s = 0
for i in range(n):
aa = input().split()
for j in aa[1:]:
bb.append(j)
for k in range(m):
if k not in aa:
s = 1
if s == 1:
print('NO')
else:
print('YES') | Title: Bulbs
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya wants to turn on Christmas lights consisting of *m* bulbs. Initially, all bulbs are turned off. There are *n* buttons, each of them is connected to some set of bulbs. Vasya can press any of these buttons. When the button is... | ```python
n,m = [int(_) for _ in input().split()]
aa = []
bb = []
s = 0
for i in range(n):
aa = input().split()
for j in aa[1:]:
bb.append(j)
for k in range(m):
if k not in aa:
s = 1
if s == 1:
print('NO')
else:
print('YES')
``` | 0 | |
982 | B | Bus of Characters | PROGRAMMING | 1,300 | [
"data structures",
"greedy",
"implementation"
] | null | null | In the Bus of Characters there are $n$ rows of seat, each having $2$ seats. The width of both seats in the $i$-th row is $w_i$ centimeters. All integers $w_i$ are distinct.
Initially the bus is empty. On each of $2n$ stops one passenger enters the bus. There are two types of passengers:
- an introvert always choose... | The first line contains a single integer $n$ ($1 \le n \le 200\,000$) — the number of rows in the bus.
The second line contains the sequence of integers $w_1, w_2, \dots, w_n$ ($1 \le w_i \le 10^{9}$), where $w_i$ is the width of each of the seats in the $i$-th row. It is guaranteed that all $w_i$ are distinct.
The t... | Print $2n$ integers — the rows the passengers will take. The order of passengers should be the same as in input. | [
"2\n3 1\n0011\n",
"6\n10 8 9 11 13 5\n010010011101\n"
] | [
"2 1 1 2 \n",
"6 6 2 3 3 1 4 4 1 2 5 5 \n"
] | In the first example the first passenger (introvert) chooses the row $2$, because it has the seats with smallest width. The second passenger (introvert) chooses the row $1$, because it is the only empty row now. The third passenger (extrovert) chooses the row $1$, because it has exactly one occupied seat and the seat w... | 1,000 | [
{
"input": "2\n3 1\n0011",
"output": "2 1 1 2 "
},
{
"input": "6\n10 8 9 11 13 5\n010010011101",
"output": "6 6 2 3 3 1 4 4 1 2 5 5 "
},
{
"input": "1\n1\n01",
"output": "1 1 "
},
{
"input": "1\n1000000\n01",
"output": "1 1 "
},
{
"input": "2\n1 1000000\n0011",
... | 1,539,146,005 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 93 | 0 | n = input()
n = int(n)
l=[]
for i in range(n):
a,b = input().split()
a = int(a)
b = int(b)
l.append((a,b))
#print (l)
ans=['x']*n
sum_a=0
sum_g=0
for i in range(n):
if abs((sum_a+l[i][0])-sum_g) <= 500:
sum_a+=l[i][0]
ans[i] = "A"
else:
if abs((sum_g+l[i][1])-sum_a) <= 5... | Title: Bus of Characters
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In the Bus of Characters there are $n$ rows of seat, each having $2$ seats. The width of both seats in the $i$-th row is $w_i$ centimeters. All integers $w_i$ are distinct.
Initially the bus is empty. On each of $2n$... | ```python
n = input()
n = int(n)
l=[]
for i in range(n):
a,b = input().split()
a = int(a)
b = int(b)
l.append((a,b))
#print (l)
ans=['x']*n
sum_a=0
sum_g=0
for i in range(n):
if abs((sum_a+l[i][0])-sum_g) <= 500:
sum_a+=l[i][0]
ans[i] = "A"
else:
if abs((sum_g+l[i][1])-s... | -1 | |
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,690,904,897 | 2,147,483,647 | Python 3 | OK | TESTS | 27 | 92 | 0 | y = input()
while True:
y = str(int(y)+1)
a = ''
for i in range(4):
if y[i] not in a:
a+=y[i]
if len(y)==len(a):
break
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 = input()
while True:
y = str(int(y)+1)
a = ''
for i in range(4):
if y[i] not in a:
a+=y[i]
if len(y)==len(a):
break
print(y)
``` | 3 | |
388 | A | Fox and Box Accumulation | PROGRAMMING | 1,400 | [
"greedy",
"sortings"
] | null | null | Fox Ciel has *n* boxes in her room. They have the same size and weight, but they might have different strength. The *i*-th box can hold at most *x**i* boxes on its top (we'll call *x**i* the strength of the box).
Since all the boxes have the same size, Ciel cannot put more than one box directly on the top of some box... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=100). The next line contains *n* integers *x*1,<=*x*2,<=...,<=*x**n* (0<=≤<=*x**i*<=≤<=100). | Output a single integer — the minimal possible number of piles. | [
"3\n0 0 10\n",
"5\n0 1 2 3 4\n",
"4\n0 0 0 0\n",
"9\n0 1 0 2 0 1 1 2 10\n"
] | [
"2\n",
"1\n",
"4\n",
"3\n"
] | In example 1, one optimal way is to build 2 piles: the first pile contains boxes 1 and 3 (from top to bottom), the second pile contains only box 2.
In example 2, we can build only 1 pile that contains boxes 1, 2, 3, 4, 5 (from top to bottom). | 500 | [
{
"input": "3\n0 0 10",
"output": "2"
},
{
"input": "5\n0 1 2 3 4",
"output": "1"
},
{
"input": "4\n0 0 0 0",
"output": "4"
},
{
"input": "9\n0 1 0 2 0 1 1 2 10",
"output": "3"
},
{
"input": "1\n0",
"output": "1"
},
{
"input": "2\n0 0",
"output": "... | 1,615,180,690 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 9 | 46 | 0 | def fox_box():
n = int(input())
arr = list(map(int, input().split()))
ans = arr.count(0)
if ans == 0:
ans = 1
print(ans)
fox_box() | Title: Fox and Box Accumulation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Fox Ciel has *n* boxes in her room. They have the same size and weight, but they might have different strength. The *i*-th box can hold at most *x**i* boxes on its top (we'll call *x**i* the strength of the box... | ```python
def fox_box():
n = int(input())
arr = list(map(int, input().split()))
ans = arr.count(0)
if ans == 0:
ans = 1
print(ans)
fox_box()
``` | 0 | |
939 | F | Cutlet | PROGRAMMING | 2,400 | [
"data structures",
"dp"
] | null | null | Arkady wants to have a dinner. He has just returned from a shop where he has bought a semifinished cutlet. He only needs to fry it. The cutlet should be fried for 2*n* seconds, in particular, it should be fried for *n* seconds on one side and *n* seconds on the other side. Arkady has already got a frying pan and turn o... | The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=100<=000, 1<=≤<=*k*<=≤<=100) — the number of seconds the cutlet should be cooked on each side and number of periods of time in which Arkady can flip it.
The next *k* lines contain descriptions of these intervals. Each line contains two integers *l**i* and... | Output "Hungry" if Arkady won't be able to fry the cutlet for exactly *n* seconds on one side and exactly *n* seconds on the other side.
Otherwise, output "Full" in the first line, and the minimum number of times he should flip the cutlet in the second line. | [
"10 2\n3 5\n11 13\n",
"10 3\n3 5\n9 10\n11 13\n",
"20 1\n3 19\n"
] | [
"Full\n2\n",
"Full\n1\n",
"Hungry\n"
] | In the first example Arkady should flip the cutlet in time moment 3 seconds after he starts cooking and in time moment 13 seconds after he starts cooking.
In the second example, Arkady can flip the cutlet at 10 seconds after he starts cooking. | 2,750 | [
{
"input": "10 2\n3 5\n11 13",
"output": "Full\n2"
},
{
"input": "10 3\n3 5\n9 10\n11 13",
"output": "Full\n1"
},
{
"input": "20 1\n3 19",
"output": "Hungry"
},
{
"input": "10 1\n0 20",
"output": "Full\n1"
},
{
"input": "10 1\n0 1",
"output": "Hungry"
},
{... | 1,693,571,714 | 2,147,483,647 | Python 3 | OK | TESTS | 63 | 3,587 | 11,264,000 | import sys
INF = (1 << 62)
N = 200005
MOD = 1000000007
f = [[INF] * N for _ in range(2)]
q = [0] * N
n, k = 0, 0
def solve():
global n, k
for i in range(N):
f[0][i] = INF
f[0][0] = 0
n, k = map(int, input().split())
for i in range(1, k + 1):
l, r = map(int, input().... | Title: Cutlet
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Arkady wants to have a dinner. He has just returned from a shop where he has bought a semifinished cutlet. He only needs to fry it. The cutlet should be fried for 2*n* seconds, in particular, it should be fried for *n* seconds o... | ```python
import sys
INF = (1 << 62)
N = 200005
MOD = 1000000007
f = [[INF] * N for _ in range(2)]
q = [0] * N
n, k = 0, 0
def solve():
global n, k
for i in range(N):
f[0][i] = INF
f[0][0] = 0
n, k = map(int, input().split())
for i in range(1, k + 1):
l, r = map(int... | 3 | |
734 | A | Anton and Danik | PROGRAMMING | 800 | [
"implementation",
"strings"
] | null | null | Anton likes to play chess, and so does his friend Danik.
Once they have played *n* games in a row. For each game it's known who was the winner — Anton or Danik. None of the games ended with a tie.
Now Anton wonders, who won more games, he or Danik? Help him determine this. | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the number of games played.
The second line contains a string *s*, consisting of *n* uppercase English letters 'A' and 'D' — the outcome of each of the games. The *i*-th character of the string is equal to 'A' if the Anton won the *i*... | If Anton won more games than Danik, print "Anton" (without quotes) in the only line of the output.
If Danik won more games than Anton, print "Danik" (without quotes) in the only line of the output.
If Anton and Danik won the same number of games, print "Friendship" (without quotes). | [
"6\nADAAAA\n",
"7\nDDDAADA\n",
"6\nDADADA\n"
] | [
"Anton\n",
"Danik\n",
"Friendship\n"
] | In the first sample, Anton won 6 games, while Danik — only 1. Hence, the answer is "Anton".
In the second sample, Anton won 3 games and Danik won 4 games, so the answer is "Danik".
In the third sample, both Anton and Danik won 3 games and the answer is "Friendship". | 500 | [
{
"input": "6\nADAAAA",
"output": "Anton"
},
{
"input": "7\nDDDAADA",
"output": "Danik"
},
{
"input": "6\nDADADA",
"output": "Friendship"
},
{
"input": "10\nDDDDADDADD",
"output": "Danik"
},
{
"input": "40\nAAAAAAAAADDAAAAAAAAAAADADDAAAAAAAAAAADAA",
"output": ... | 1,694,609,720 | 2,147,483,647 | Python 3 | OK | TESTS | 25 | 62 | 2,355,200 | n=input()
m=input()
lst=[]
for a in m:
lst.append(a)
p=lst.count("A")
q=lst.count("D")
if p>q:
print("Anton")
elif q>p:
print("Danik")
else:
print("Friendship") | Title: Anton and Danik
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Anton likes to play chess, and so does his friend Danik.
Once they have played *n* games in a row. For each game it's known who was the winner — Anton or Danik. None of the games ended with a tie.
Now Anton wonders, w... | ```python
n=input()
m=input()
lst=[]
for a in m:
lst.append(a)
p=lst.count("A")
q=lst.count("D")
if p>q:
print("Anton")
elif q>p:
print("Danik")
else:
print("Friendship")
``` | 3 | |
500 | A | New Year Transportation | PROGRAMMING | 1,000 | [
"dfs and similar",
"graphs",
"implementation"
] | null | null | New Year is coming in Line World! In this world, there are *n* cells numbered by integers from 1 to *n*, as a 1<=×<=*n* board. People live in cells. However, it was hard to move between distinct cells, because of the difficulty of escaping the cell. People wanted to meet people who live in other cells.
So, user tncks0... | The first line contains two space-separated integers *n* (3<=≤<=*n*<=≤<=3<=×<=104) and *t* (2<=≤<=*t*<=≤<=*n*) — the number of cells, and the index of the cell which I want to go to.
The second line contains *n*<=-<=1 space-separated integers *a*1,<=*a*2,<=...,<=*a**n*<=-<=1 (1<=≤<=*a**i*<=≤<=*n*<=-<=*i*). It is guara... | If I can go to cell *t* using the transportation system, print "YES". Otherwise, print "NO". | [
"8 4\n1 2 1 2 1 2 1\n",
"8 5\n1 2 1 2 1 1 1\n"
] | [
"YES\n",
"NO\n"
] | In the first sample, the visited cells are: 1, 2, 4; so we can successfully visit the cell 4.
In the second sample, the possible cells to visit are: 1, 2, 4, 6, 7, 8; so we can't visit the cell 5, which we want to visit. | 500 | [
{
"input": "8 4\n1 2 1 2 1 2 1",
"output": "YES"
},
{
"input": "8 5\n1 2 1 2 1 1 1",
"output": "NO"
},
{
"input": "20 19\n13 16 7 6 12 1 5 7 8 6 5 7 5 5 3 3 2 2 1",
"output": "YES"
},
{
"input": "50 49\n11 7 1 41 26 36 19 16 38 14 36 35 37 27 20 27 3 6 21 2 27 11 18 17 19 16 ... | 1,682,167,395 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 12 | 46 | 1,945,600 | n,t=map(int,input().split())
a=list(map(int,input().split()))
current_cell=1
pos=False
while current_cell<=t:
if current_cell==t:
pos=True
current_cell=current_cell+a[current_cell-1]
if pos==True:
print('YES')
else:
print('NO') | Title: New Year Transportation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
New Year is coming in Line World! In this world, there are *n* cells numbered by integers from 1 to *n*, as a 1<=×<=*n* board. People live in cells. However, it was hard to move between distinct cells, because o... | ```python
n,t=map(int,input().split())
a=list(map(int,input().split()))
current_cell=1
pos=False
while current_cell<=t:
if current_cell==t:
pos=True
current_cell=current_cell+a[current_cell-1]
if pos==True:
print('YES')
else:
print('NO')
``` | -1 | |
712 | A | Memory and Crow | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | There are *n* integers *b*1,<=*b*2,<=...,<=*b**n* written in a row. For all *i* from 1 to *n*, values *a**i* are defined by the crows performing the following procedure:
- The crow sets *a**i* initially 0. - The crow then adds *b**i* to *a**i*, subtracts *b**i*<=+<=1, adds the *b**i*<=+<=2 number, and so on until th... | The first line of the input contains a single integer *n* (2<=≤<=*n*<=≤<=100<=000) — the number of integers written in the row.
The next line contains *n*, the *i*'th of which is *a**i* (<=-<=109<=≤<=*a**i*<=≤<=109) — the value of the *i*'th number. | Print *n* integers corresponding to the sequence *b*1,<=*b*2,<=...,<=*b**n*. It's guaranteed that the answer is unique and fits in 32-bit integer type. | [
"5\n6 -4 8 -2 3\n",
"5\n3 -2 -1 5 6\n"
] | [
"2 4 6 1 3 \n",
"1 -3 4 11 6 \n"
] | In the first sample test, the crows report the numbers 6, - 4, 8, - 2, and 3 when he starts at indices 1, 2, 3, 4 and 5 respectively. It is easy to check that the sequence 2 4 6 1 3 satisfies the reports. For example, 6 = 2 - 4 + 6 - 1 + 3, and - 4 = 4 - 6 + 1 - 3.
In the second sample test, the sequence 1, - 3, 4, ... | 500 | [
{
"input": "5\n6 -4 8 -2 3",
"output": "2 4 6 1 3 "
},
{
"input": "5\n3 -2 -1 5 6",
"output": "1 -3 4 11 6 "
},
{
"input": "10\n13 -2 532 -63 -23 -63 -64 -23 12 10",
"output": "11 530 469 -86 -86 -127 -87 -11 22 10 "
},
{
"input": "10\n0 0 0 0 0 0 0 0 0 0",
"output": "0 0... | 1,697,198,073 | 2,147,483,647 | Python 3 | OK | TESTS | 49 | 202 | 17,612,800 | num = int(input())
num_list = input().split()
list = []
for i in num_list:
list.append(int(i))
# print(list)
list_b = []
b = 0
for i in range(num-1):
b = list[i] + list[i+1]
list_b.append(b)
list_b.append(list[-1])
for i in list_b:
print(i, end=" ")
| Title: Memory and Crow
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* integers *b*1,<=*b*2,<=...,<=*b**n* written in a row. For all *i* from 1 to *n*, values *a**i* are defined by the crows performing the following procedure:
- The crow sets *a**i* initially 0. - The crow... | ```python
num = int(input())
num_list = input().split()
list = []
for i in num_list:
list.append(int(i))
# print(list)
list_b = []
b = 0
for i in range(num-1):
b = list[i] + list[i+1]
list_b.append(b)
list_b.append(list[-1])
for i in list_b:
print(i, end=" ")
``` | 3 | |
567 | A | Lineland Mail | PROGRAMMING | 900 | [
"greedy",
"implementation"
] | null | null | All cities of Lineland are located on the *Ox* coordinate axis. Thus, each city is associated with its position *x**i* — a coordinate on the *Ox* axis. No two cities are located at a single point.
Lineland residents love to send letters to each other. A person may send a letter only if the recipient lives in another c... | The first line of the input contains integer *n* (2<=≤<=*n*<=≤<=105) — the number of cities in Lineland. The second line contains the sequence of *n* distinct integers *x*1,<=*x*2,<=...,<=*x**n* (<=-<=109<=≤<=*x**i*<=≤<=109), where *x**i* is the *x*-coordinate of the *i*-th city. All the *x**i*'s are distinct and follo... | Print *n* lines, the *i*-th line must contain two integers *min**i*,<=*max**i*, separated by a space, where *min**i* is the minimum cost of sending a letter from the *i*-th city, and *max**i* is the maximum cost of sending a letter from the *i*-th city. | [
"4\n-5 -2 2 7\n",
"2\n-1 1\n"
] | [
"3 12\n3 9\n4 7\n5 12\n",
"2 2\n2 2\n"
] | none | 500 | [
{
"input": "4\n-5 -2 2 7",
"output": "3 12\n3 9\n4 7\n5 12"
},
{
"input": "2\n-1 1",
"output": "2 2\n2 2"
},
{
"input": "3\n-1 0 1",
"output": "1 2\n1 1\n1 2"
},
{
"input": "4\n-1 0 1 3",
"output": "1 4\n1 3\n1 2\n2 4"
},
{
"input": "3\n-1000000000 0 1000000000",
... | 1,674,466,670 | 2,147,483,647 | Python 3 | OK | TESTS | 54 | 577 | 12,185,600 | n = int(input())
lis = list(map(int,input().split()))
res =[]
for i in range(n):
ma = max(abs(lis[i]-lis[0]),abs(lis[i]-lis[n-1]))
if i == 0 :
mi = abs(lis[i]-lis[i+1])
elif i == n-1 :
mi = abs(lis[i]-lis[i-1])
else:
mi = min(abs(lis[i]-lis[i-1]),abs(lis[i]-lis[i+1]))
res.append([mi,ma]... | Title: Lineland Mail
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
All cities of Lineland are located on the *Ox* coordinate axis. Thus, each city is associated with its position *x**i* — a coordinate on the *Ox* axis. No two cities are located at a single point.
Lineland residents love... | ```python
n = int(input())
lis = list(map(int,input().split()))
res =[]
for i in range(n):
ma = max(abs(lis[i]-lis[0]),abs(lis[i]-lis[n-1]))
if i == 0 :
mi = abs(lis[i]-lis[i+1])
elif i == n-1 :
mi = abs(lis[i]-lis[i-1])
else:
mi = min(abs(lis[i]-lis[i-1]),abs(lis[i]-lis[i+1]))
res.appe... | 3 | |
479 | A | Expression | PROGRAMMING | 1,000 | [
"brute force",
"math"
] | null | null | Petya studies in a school and he adores Maths. His class has been studying arithmetic expressions. On the last class the teacher wrote three positive integers *a*, *b*, *c* on the blackboard. The task was to insert signs of operations '+' and '*', and probably brackets between the numbers so that the value of the resul... | The input contains three integers *a*, *b* and *c*, each on a single line (1<=≤<=*a*,<=*b*,<=*c*<=≤<=10). | Print the maximum value of the expression that you can obtain. | [
"1\n2\n3\n",
"2\n10\n3\n"
] | [
"9\n",
"60\n"
] | none | 500 | [
{
"input": "1\n2\n3",
"output": "9"
},
{
"input": "2\n10\n3",
"output": "60"
},
{
"input": "1\n1\n1",
"output": "3"
},
{
"input": "1\n2\n1",
"output": "4"
},
{
"input": "10\n10\n10",
"output": "1000"
},
{
"input": "5\n1\n3",
"output": "20"
},
{... | 1,689,976,088 | 2,147,483,647 | Python 3 | OK | TESTS | 29 | 46 | 0 | a = int(input())
b = int(input())
c = int(input())
arreglo = []
caso1 = a * (b + c)
caso2 = (a + b) * c
caso3 = a * b * c
caso4 = a + b + c
caso5 = a * b + c
caso6 = a + b * c
arreglo += [caso1,caso2,caso3,caso4,caso5,caso6]
arreglo.sort()
print(arreglo[5]) | Title: Expression
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Petya studies in a school and he adores Maths. His class has been studying arithmetic expressions. On the last class the teacher wrote three positive integers *a*, *b*, *c* on the blackboard. The task was to insert signs of ... | ```python
a = int(input())
b = int(input())
c = int(input())
arreglo = []
caso1 = a * (b + c)
caso2 = (a + b) * c
caso3 = a * b * c
caso4 = a + b + c
caso5 = a * b + c
caso6 = a + b * c
arreglo += [caso1,caso2,caso3,caso4,caso5,caso6]
arreglo.sort()
print(arreglo[5])
``` | 3 | |
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,584,075,881 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 80 | 218 | 307,200 |
k=0
for _ in range(int(input())):
l=list(map(int,input().split()))
k+=sum(l)
if k==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
k=0
for _ in range(int(input())):
l=list(map(int,input().split()))
k+=sum(l)
if k==0:
print("YES")
else:
print("NO")
``` | 0 |
820 | A | Mister B and Book Reading | PROGRAMMING | 900 | [
"implementation"
] | null | null | Mister B once received a gift: it was a book about aliens, which he started read immediately. This book had *c* pages.
At first day Mister B read *v*0 pages, but after that he started to speed up. Every day, starting from the second, he read *a* pages more than on the previous day (at first day he read *v*0 pages, at ... | First and only line contains five space-separated integers: *c*, *v*0, *v*1, *a* and *l* (1<=≤<=*c*<=≤<=1000, 0<=≤<=*l*<=<<=*v*0<=≤<=*v*1<=≤<=1000, 0<=≤<=*a*<=≤<=1000) — the length of the book in pages, the initial reading speed, the maximum reading speed, the acceleration in reading speed and the number of pages fo... | Print one integer — the number of days Mister B needed to finish the book. | [
"5 5 10 5 4\n",
"12 4 12 4 1\n",
"15 1 100 0 0\n"
] | [
"1\n",
"3\n",
"15\n"
] | In the first sample test the book contains 5 pages, so Mister B read it right at the first day.
In the second sample test at first day Mister B read pages number 1 - 4, at second day — 4 - 11, at third day — 11 - 12 and finished the book.
In third sample test every day Mister B read 1 page of the book, so he finished... | 500 | [
{
"input": "5 5 10 5 4",
"output": "1"
},
{
"input": "12 4 12 4 1",
"output": "3"
},
{
"input": "15 1 100 0 0",
"output": "15"
},
{
"input": "1 1 1 0 0",
"output": "1"
},
{
"input": "1000 999 1000 1000 998",
"output": "2"
},
{
"input": "1000 2 2 5 1",
... | 1,624,411,357 | 2,147,483,647 | Python 3 | OK | TESTS | 110 | 62 | 0 | c,v,n,a,l = map(int,input().split())
d = 1
c -= v
while c > 0:
v += a
if v > n:
v = n
c -= v - l
d += 1
print(d) | Title: Mister B and Book Reading
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mister B once received a gift: it was a book about aliens, which he started read immediately. This book had *c* pages.
At first day Mister B read *v*0 pages, but after that he started to speed up. Every day, ... | ```python
c,v,n,a,l = map(int,input().split())
d = 1
c -= v
while c > 0:
v += a
if v > n:
v = n
c -= v - l
d += 1
print(d)
``` | 3 | |
552 | B | Vanya and Books | PROGRAMMING | 1,200 | [
"implementation",
"math"
] | null | null | Vanya got an important task — he should enumerate books in the library and label each book with its number. Each of the *n* books should be assigned with a number from 1 to *n*. Naturally, distinct books should be assigned distinct numbers.
Vanya wants to know how many digits he will have to write down as he labels th... | The first line contains integer *n* (1<=≤<=*n*<=≤<=109) — the number of books in the library. | Print the number of digits needed to number all the books. | [
"13\n",
"4\n"
] | [
"17\n",
"4\n"
] | Note to the first test. The books get numbers 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, which totals to 17 digits.
Note to the second sample. The books get numbers 1, 2, 3, 4, which totals to 4 digits. | 1,000 | [
{
"input": "13",
"output": "17"
},
{
"input": "4",
"output": "4"
},
{
"input": "100",
"output": "192"
},
{
"input": "99",
"output": "189"
},
{
"input": "1000000000",
"output": "8888888899"
},
{
"input": "1000000",
"output": "5888896"
},
{
"... | 1,538,527,929 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 5 | 93 | 0 | n = int(input())
a = []
z = 0
k = 8888888899
if n <= 1000:
for i in range (1,n+1):
a.append(i)
z += len(str(a[i-1]))
print(z)
elif n == 1000000000:
print(k)
else:
None
| Title: Vanya and Books
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vanya got an important task — he should enumerate books in the library and label each book with its number. Each of the *n* books should be assigned with a number from 1 to *n*. Naturally, distinct books should be assig... | ```python
n = int(input())
a = []
z = 0
k = 8888888899
if n <= 1000:
for i in range (1,n+1):
a.append(i)
z += len(str(a[i-1]))
print(z)
elif n == 1000000000:
print(k)
else:
None
``` | 0 | |
224 | B | Array | PROGRAMMING | 1,500 | [
"bitmasks",
"implementation",
"two pointers"
] | null | null | You've got an array *a*, consisting of *n* integers: *a*1,<=*a*2,<=...,<=*a**n*. Your task is to find a minimal by inclusion segment [*l*,<=*r*] (1<=≤<=*l*<=≤<=*r*<=≤<=*n*) such, that among numbers *a**l*,<= *a**l*<=+<=1,<= ...,<= *a**r* there are exactly *k* distinct numbers.
Segment [*l*,<=*r*] (1<=≤<=*l*<=≤<=*r*<=≤... | The first line contains two space-separated integers: *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=105). The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* — elements of the array *a* (1<=≤<=*a**i*<=≤<=105). | Print a space-separated pair of integers *l* and *r* (1<=≤<=*l*<=≤<=*r*<=≤<=*n*) such, that the segment [*l*,<=*r*] is the answer to the problem. If the sought segment does not exist, print "-1 -1" without the quotes. If there are multiple correct answers, print any of them. | [
"4 2\n1 2 2 3\n",
"8 3\n1 1 2 2 3 3 4 5\n",
"7 4\n4 7 7 4 7 4 7\n"
] | [
"1 2\n",
"2 5\n",
"-1 -1\n"
] | In the first sample among numbers *a*<sub class="lower-index">1</sub> and *a*<sub class="lower-index">2</sub> there are exactly two distinct numbers.
In the second sample segment [2, 5] is a minimal by inclusion segment with three distinct numbers, but it is not minimal in length among such segments.
In the third sam... | 1,000 | [
{
"input": "4 2\n1 2 2 3",
"output": "1 2"
},
{
"input": "8 3\n1 1 2 2 3 3 4 5",
"output": "2 5"
},
{
"input": "7 4\n4 7 7 4 7 4 7",
"output": "-1 -1"
},
{
"input": "5 1\n1 7 2 3 2",
"output": "1 1"
},
{
"input": "1 2\n666",
"output": "-1 -1"
},
{
"inp... | 1,547,796,269 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 186 | 1,331,200 | n, k = map(int, input().split())
ls = list(map(int,input().split()))
count = 0
l = 0
r = 0
cnt = [0 for _ in range(100000)]
for i in range(n):
if cnt[ls[i]] == 0:
cnt[ls[i]] += 1
count += 1
if l == 0:
l = i + 1
if count >= k:
r = i + 1
break
if count < k:
print(-1,-1)
else:
print(l,r)
| Title: Array
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You've got an array *a*, consisting of *n* integers: *a*1,<=*a*2,<=...,<=*a**n*. Your task is to find a minimal by inclusion segment [*l*,<=*r*] (1<=≤<=*l*<=≤<=*r*<=≤<=*n*) such, that among numbers *a**l*,<= *a**l*<=+<=1,<= ...,<... | ```python
n, k = map(int, input().split())
ls = list(map(int,input().split()))
count = 0
l = 0
r = 0
cnt = [0 for _ in range(100000)]
for i in range(n):
if cnt[ls[i]] == 0:
cnt[ls[i]] += 1
count += 1
if l == 0:
l = i + 1
if count >= k:
r = i + 1
break
if count < k:
print(-1,-1)
else:
print(l,r)
``` | 0 | |
25 | A | IQ test | PROGRAMMING | 1,300 | [
"brute force"
] | A. IQ test | 2 | 256 | Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — to check his answers, he needs a program that among the given *n* numbers finds one that i... | The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of numbers in the task. The second line contains *n* space-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these numbers differs from the others in evenness. | Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order. | [
"5\n2 4 7 8 10\n",
"4\n1 2 1 1\n"
] | [
"3\n",
"2\n"
] | none | 0 | [
{
"input": "5\n2 4 7 8 10",
"output": "3"
},
{
"input": "4\n1 2 1 1",
"output": "2"
},
{
"input": "3\n1 2 2",
"output": "1"
},
{
"input": "3\n100 99 100",
"output": "2"
},
{
"input": "3\n5 3 2",
"output": "3"
},
{
"input": "4\n43 28 1 91",
"output"... | 1,608,005,819 | 2,147,483,647 | Python 3 | OK | TESTS | 32 | 218 | 307,200 | n=int(input())
a=input().split()
listing=[]
for i in range(n) :
chu=int(a[i])%2
listing.append(chu)
list1=sorted(listing)
p1=list1.count(list1[0])
p2=list1.count(list1[-1])
if p1<p2 :
print(listing.index(list1[0])+1)
else :
print(listing.index(list1[-1])+1)
| Title: IQ test
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — t... | ```python
n=int(input())
a=input().split()
listing=[]
for i in range(n) :
chu=int(a[i])%2
listing.append(chu)
list1=sorted(listing)
p1=list1.count(list1[0])
p2=list1.count(list1[-1])
if p1<p2 :
print(listing.index(list1[0])+1)
else :
print(listing.index(list1[-1])+1)
``` | 3.944928 |
820 | B | Mister B and Angle in Polygon | PROGRAMMING | 1,300 | [
"constructive algorithms",
"geometry",
"math"
] | null | null | On one quiet day all of sudden Mister B decided to draw angle *a* on his field. Aliens have already visited his field and left many different geometric figures on it. One of the figures is regular convex *n*-gon (regular convex polygon with *n* sides).
That's why Mister B decided to use this polygon. Now Mister B must... | First and only line contains two space-separated integers *n* and *a* (3<=≤<=*n*<=≤<=105, 1<=≤<=*a*<=≤<=180) — the number of vertices in the polygon and the needed angle, in degrees. | Print three space-separated integers: the vertices *v*1, *v*2, *v*3, which form . If there are multiple optimal solutions, print any of them. The vertices are numbered from 1 to *n* in clockwise order. | [
"3 15\n",
"4 67\n",
"4 68\n"
] | [
"1 2 3\n",
"2 1 3\n",
"4 1 2\n"
] | In first sample test vertices of regular triangle can create only angle of 60 degrees, that's why every possible angle is correct.
Vertices of square can create 45 or 90 degrees angles only. That's why in second sample test the angle of 45 degrees was chosen, since |45 - 67| < |90 - 67|. Other correct answers are: ... | 1,000 | [
{
"input": "3 15",
"output": "2 1 3"
},
{
"input": "4 67",
"output": "2 1 3"
},
{
"input": "4 68",
"output": "2 1 4"
},
{
"input": "3 1",
"output": "2 1 3"
},
{
"input": "3 180",
"output": "2 1 3"
},
{
"input": "100000 1",
"output": "2 1 558"
},
... | 1,500,375,589 | 1,789 | Python 3 | OK | TESTS | 46 | 77 | 4,608,000 | from math import ceil
n, a = map(int, input().split())
d = round(a * n / 180) + 2
if d == 2:
d = 3
if d > n:
d = n
print(2, 1, d) | Title: Mister B and Angle in Polygon
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
On one quiet day all of sudden Mister B decided to draw angle *a* on his field. Aliens have already visited his field and left many different geometric figures on it. One of the figures is regular convex *... | ```python
from math import ceil
n, a = map(int, input().split())
d = round(a * n / 180) + 2
if d == 2:
d = 3
if d > n:
d = n
print(2, 1, d)
``` | 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,627,275,127 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 2 | 92 | 20,172,800 |
a = [[],[],[]]
b = [[1,1,1],[1,1,1],[1,1,1]]
for i in range(3):
x = list(map(int, input().split(" ")))
a[i] = x
for j in range(3):
for l in range(3):
if a[j][l]%2!=0:
b[j][l] = 0
if l+1<3:
if b[j][l+1]==0:
b[j][l+1]=1
... | 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
a = [[],[],[]]
b = [[1,1,1],[1,1,1],[1,1,1]]
for i in range(3):
x = list(map(int, input().split(" ")))
a[i] = x
for j in range(3):
for l in range(3):
if a[j][l]%2!=0:
b[j][l] = 0
if l+1<3:
if b[j][l+1]==0:
b[j][l+... | 0 | |
538 | A | Cutting Banner | PROGRAMMING | 1,400 | [
"brute force",
"implementation"
] | null | null | A large banner with word CODEFORCES was ordered for the 1000-th onsite round of Codeforcesω that takes place on the Miami beach. Unfortunately, the company that made the banner mixed up two orders and delivered somebody else's banner that contains someone else's word. The word on the banner consists only of upper-case ... | The single line of the input contains the word written on the banner. The word only consists of upper-case English letters. The word is non-empty and its length doesn't exceed 100 characters. It is guaranteed that the word isn't word CODEFORCES. | Print 'YES', if there exists a way to cut out the substring, and 'NO' otherwise (without the quotes). | [
"CODEWAITFORITFORCES\n",
"BOTTOMCODER\n",
"DECODEFORCES\n",
"DOGEFORCES\n"
] | [
"YES\n",
"NO\n",
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "CODEWAITFORITFORCES",
"output": "YES"
},
{
"input": "BOTTOMCODER",
"output": "NO"
},
{
"input": "DECODEFORCES",
"output": "YES"
},
{
"input": "DOGEFORCES",
"output": "NO"
},
{
"input": "ABACABA",
"output": "NO"
},
{
"input": "CODEFORCE",
... | 1,683,725,299 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | import sys
input = sys.stdin.readline
def check_codeforces(s):
if len(s) < len(CODEFORCES):
return False
for i in range(len(s)):
if i + len(CODEFORCES) > len(s):
break
substring = s[i: i + len(CODEFORCES)]
if substring == CODEFORCES:
return True
return False
s = input().strip()
if check_codeforces(... | Title: Cutting Banner
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A large banner with word CODEFORCES was ordered for the 1000-th onsite round of Codeforcesω that takes place on the Miami beach. Unfortunately, the company that made the banner mixed up two orders and delivered somebody ... | ```python
import sys
input = sys.stdin.readline
def check_codeforces(s):
if len(s) < len(CODEFORCES):
return False
for i in range(len(s)):
if i + len(CODEFORCES) > len(s):
break
substring = s[i: i + len(CODEFORCES)]
if substring == CODEFORCES:
return True
return False
s = input().strip()
if check_c... | -1 | |
149 | A | Business trip | PROGRAMMING | 900 | [
"greedy",
"implementation",
"sortings"
] | null | null | What joy! Petya's parents went on a business trip for the whole year and the playful kid is left all by himself. Petya got absolutely happy. He jumped on the bed and threw pillows all day long, until...
Today Petya opened the cupboard and found a scary note there. His parents had left him with duties: he should water... | The first line contains exactly one integer *k* (0<=≤<=*k*<=≤<=100). The next line contains twelve space-separated integers: the *i*-th (1<=≤<=*i*<=≤<=12) number in the line represents *a**i* (0<=≤<=*a**i*<=≤<=100). | Print the only integer — the minimum number of months when Petya has to water the flower so that the flower grows no less than by *k* centimeters. If the flower can't grow by *k* centimeters in a year, print -1. | [
"5\n1 1 1 1 2 2 3 2 2 1 1 1\n",
"0\n0 0 0 0 0 0 0 1 1 2 3 0\n",
"11\n1 1 4 1 1 5 1 1 4 1 1 1\n"
] | [
"2\n",
"0\n",
"3\n"
] | Let's consider the first sample test. There it is enough to water the flower during the seventh and the ninth month. Then the flower grows by exactly five centimeters.
In the second sample Petya's parents will believe him even if the flower doesn't grow at all (*k* = 0). So, it is possible for Petya not to water the f... | 500 | [
{
"input": "5\n1 1 1 1 2 2 3 2 2 1 1 1",
"output": "2"
},
{
"input": "0\n0 0 0 0 0 0 0 1 1 2 3 0",
"output": "0"
},
{
"input": "11\n1 1 4 1 1 5 1 1 4 1 1 1",
"output": "3"
},
{
"input": "15\n20 1 1 1 1 2 2 1 2 2 1 1",
"output": "1"
},
{
"input": "7\n8 9 100 12 14 ... | 1,659,682,294 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 6 | 186 | 0 | height = int(input())
growths = list(map(int, input().split()))
growths.sort(reverse=True)
sum = 0
counter = 0
for growth in growths:
if height > sum:
sum += growth
counter += 1
print(counter) | Title: Business trip
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
What joy! Petya's parents went on a business trip for the whole year and the playful kid is left all by himself. Petya got absolutely happy. He jumped on the bed and threw pillows all day long, until...
Today Petya open... | ```python
height = int(input())
growths = list(map(int, input().split()))
growths.sort(reverse=True)
sum = 0
counter = 0
for growth in growths:
if height > sum:
sum += growth
counter += 1
print(counter)
``` | 0 | |
581 | A | Vasya the Hipster | PROGRAMMING | 800 | [
"implementation",
"math"
] | null | null | One day Vasya the Hipster decided to count how many socks he had. It turned out that he had *a* red socks and *b* blue socks.
According to the latest fashion, hipsters should wear the socks of different colors: a red one on the left foot, a blue one on the right foot.
Every day Vasya puts on new socks in the morning ... | The single line of the input contains two positive integers *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=100) — the number of red and blue socks that Vasya's got. | Print two space-separated integers — the maximum number of days when Vasya can wear different socks and the number of days when he can wear the same socks until he either runs out of socks or cannot make a single pair from the socks he's got.
Keep in mind that at the end of the day Vasya throws away the socks that he'... | [
"3 1\n",
"2 3\n",
"7 3\n"
] | [
"1 1\n",
"2 0\n",
"3 2\n"
] | In the first sample Vasya can first put on one pair of different socks, after that he has two red socks left to wear on the second day. | 500 | [
{
"input": "3 1",
"output": "1 1"
},
{
"input": "2 3",
"output": "2 0"
},
{
"input": "7 3",
"output": "3 2"
},
{
"input": "100 100",
"output": "100 0"
},
{
"input": "4 10",
"output": "4 3"
},
{
"input": "6 10",
"output": "6 2"
},
{
"input":... | 1,692,898,386 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 46 | 0 | a, b = map(int, input().split())
mins = min(a, b)
#maxdd = mins
same = abs(a - b) // 2
#msd = same
print(mins, same)
| Title: Vasya the Hipster
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day Vasya the Hipster decided to count how many socks he had. It turned out that he had *a* red socks and *b* blue socks.
According to the latest fashion, hipsters should wear the socks of different colors: a red... | ```python
a, b = map(int, input().split())
mins = min(a, b)
#maxdd = mins
same = abs(a - b) // 2
#msd = same
print(mins, same)
``` | 3 | |
747 | B | Mammoth's Genome Decoding | PROGRAMMING | 900 | [
"implementation",
"strings"
] | null | null | The process of mammoth's genome decoding in Berland comes to its end!
One of the few remaining tasks is to restore unrecognized nucleotides in a found chain *s*. Each nucleotide is coded with a capital letter of English alphabet: 'A', 'C', 'G' or 'T'. Unrecognized nucleotides are coded by a question mark '?'. Thus, *s... | The first line contains the integer *n* (4<=≤<=*n*<=≤<=255) — the length of the genome.
The second line contains the string *s* of length *n* — the coded genome. It consists of characters 'A', 'C', 'G', 'T' and '?'. | If it is possible to decode the genome, print it. If there are multiple answer, print any of them. If it is not possible, print three equals signs in a row: "===" (without quotes). | [
"8\nAG?C??CT\n",
"4\nAGCT\n",
"6\n????G?\n",
"4\nAA??\n"
] | [
"AGACGTCT\n",
"AGCT\n",
"===\n",
"===\n"
] | In the first example you can replace the first question mark with the letter 'A', the second question mark with the letter 'G', the third question mark with the letter 'T', then each nucleotide in the genome would be presented twice.
In the second example the genome is already decoded correctly and each nucleotide is ... | 1,000 | [
{
"input": "8\nAG?C??CT",
"output": "AGACGTCT"
},
{
"input": "4\nAGCT",
"output": "AGCT"
},
{
"input": "6\n????G?",
"output": "==="
},
{
"input": "4\nAA??",
"output": "==="
},
{
"input": "4\n????",
"output": "ACGT"
},
{
"input": "252\n???????GCG??T??TT... | 1,633,694,280 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 62 | 6,963,200 | n=int(input())
a=input()
ag=a.count("A")
gg=a.count("G")
cg=a.count("C")
tg=a.count("T")
vg=a.count("?")
b=''
if vg==0:
print(a)
else:
if n%4==0:
ma=max(ag,max(gg,max(cg,tg)))
if ma==n//4:
for i in range(n):
if a[i]!="?":
b=b+a[i]
... | Title: Mammoth's Genome Decoding
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The process of mammoth's genome decoding in Berland comes to its end!
One of the few remaining tasks is to restore unrecognized nucleotides in a found chain *s*. Each nucleotide is coded with a capital letter... | ```python
n=int(input())
a=input()
ag=a.count("A")
gg=a.count("G")
cg=a.count("C")
tg=a.count("T")
vg=a.count("?")
b=''
if vg==0:
print(a)
else:
if n%4==0:
ma=max(ag,max(gg,max(cg,tg)))
if ma==n//4:
for i in range(n):
if a[i]!="?":
... | 0 | |
75 | C | Modified GCD | PROGRAMMING | 1,600 | [
"binary search",
"number theory"
] | C. Modified GCD | 2 | 256 | Well, here is another math class task. In mathematics, GCD is the greatest common divisor, and it's an easy task to calculate the GCD between two positive integers.
A common divisor for two positive numbers is a number which both numbers are divisible by.
But your teacher wants to give you a harder task, in this task... | The first line contains two integers *a* and *b*, the two integers as described above (1<=≤<=*a*,<=*b*<=≤<=109). The second line contains one integer *n*, the number of queries (1<=≤<=*n*<=≤<=104). Then *n* lines follow, each line contains one query consisting of two integers, *low* and *high* (1<=≤<=*low*<=≤<=*high*<=... | Print *n* lines. The *i*-th of them should contain the result of the *i*-th query in the input. If there is no common divisor in the given range for any query, you should print -1 as a result for this query. | [
"9 27\n3\n1 5\n10 11\n9 11\n"
] | [
"3\n-1\n9\n"
] | none | 1,500 | [
{
"input": "9 27\n3\n1 5\n10 11\n9 11",
"output": "3\n-1\n9"
},
{
"input": "48 72\n2\n8 29\n29 37",
"output": "24\n-1"
},
{
"input": "90 100\n10\n51 61\n6 72\n1 84\n33 63\n37 69\n18 21\n9 54\n49 90\n14 87\n37 90",
"output": "-1\n10\n10\n-1\n-1\n-1\n10\n-1\n-1\n-1"
},
{
"input... | 1,664,945,516 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 60 | 340 | 10,137,600 | from sys import stdin
input = stdin.readline
from math import gcd as GCD
from bisect import bisect_left
def GetPrimes(max_prime):
is_prime = [True for i in range(max_prime + 1)]
primes = []
for p in range(2, max_prime + 1):
if is_prime[p]:
primes += [p]
for n in... | Title: Modified GCD
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Well, here is another math class task. In mathematics, GCD is the greatest common divisor, and it's an easy task to calculate the GCD between two positive integers.
A common divisor for two positive numbers is a number which ... | ```python
from sys import stdin
input = stdin.readline
from math import gcd as GCD
from bisect import bisect_left
def GetPrimes(max_prime):
is_prime = [True for i in range(max_prime + 1)]
primes = []
for p in range(2, max_prime + 1):
if is_prime[p]:
primes += [p]
... | 3.896117 |
488 | A | Giga Tower | PROGRAMMING | 1,100 | [
"brute force"
] | null | null | Giga Tower is the tallest and deepest building in Cyberland. There are 17<=777<=777<=777 floors, numbered from <=-<=8<=888<=888<=888 to 8<=888<=888<=888. In particular, there is floor 0 between floor <=-<=1 and floor 1. Every day, thousands of tourists come to this place to enjoy the wonderful view.
In Cyberland, it ... | The only line of input contains an integer *a* (<=-<=109<=≤<=*a*<=≤<=109). | Print the minimum *b* in a line. | [
"179\n",
"-1\n",
"18\n"
] | [
"1\n",
"9\n",
"10\n"
] | For the first sample, he has to arrive at the floor numbered 180.
For the second sample, he will arrive at 8.
Note that *b* should be positive, so the answer for the third sample is 10, not 0. | 500 | [
{
"input": "179",
"output": "1"
},
{
"input": "-1",
"output": "9"
},
{
"input": "18",
"output": "10"
},
{
"input": "-410058385",
"output": "1"
},
{
"input": "-586825624",
"output": "1"
},
{
"input": "852318890",
"output": "1"
},
{
"input": ... | 1,593,928,150 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 3 | 124 | 20,172,800 | n=(input())
floor=0
if n.count('8')==1:
floor=1
n=str(floor+int(n))
while(True):
if n.count('8')==1:
break
else:
floor+=1
n=str(1+int(n))
else:
while(True):
if n.count('8')==1:
break
else:
... | Title: Giga Tower
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Giga Tower is the tallest and deepest building in Cyberland. There are 17<=777<=777<=777 floors, numbered from <=-<=8<=888<=888<=888 to 8<=888<=888<=888. In particular, there is floor 0 between floor <=-<=1 and floor 1. Ever... | ```python
n=(input())
floor=0
if n.count('8')==1:
floor=1
n=str(floor+int(n))
while(True):
if n.count('8')==1:
break
else:
floor+=1
n=str(1+int(n))
else:
while(True):
if n.count('8')==1:
break
... | 0 | |
160 | A | Twins | PROGRAMMING | 900 | [
"greedy",
"sortings"
] | null | null | Imagine that you have a twin brother or sister. Having another person that looks exactly like you seems very unusual. It's hard to say if having something of an alter ego is good or bad. And if you do have a twin, then you very well know what it's like.
Now let's imagine a typical morning in your family. You haven't w... | The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of coins. The second line contains a sequence of *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=100) — the coins' values. All numbers are separated with spaces. | In the single line print the single number — the minimum needed number of coins. | [
"2\n3 3\n",
"3\n2 1 2\n"
] | [
"2\n",
"2\n"
] | In the first sample you will have to take 2 coins (you and your twin have sums equal to 6, 0 correspondingly). If you take 1 coin, you get sums 3, 3. If you take 0 coins, you get sums 0, 6. Those variants do not satisfy you as your sum should be strictly more that your twins' sum.
In the second sample one coin isn't e... | 500 | [
{
"input": "2\n3 3",
"output": "2"
},
{
"input": "3\n2 1 2",
"output": "2"
},
{
"input": "1\n5",
"output": "1"
},
{
"input": "5\n4 2 2 2 2",
"output": "3"
},
{
"input": "7\n1 10 1 2 1 1 1",
"output": "1"
},
{
"input": "5\n3 2 3 3 1",
"output": "3"
... | 1,697,366,964 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 5 | 62 | 0 | num = int(input())
coins = [int(x) for x in input().split()]
coin_to_take = list()
count = 0
coins.sort()
coins.reverse()
for coin in coins:
coin_to_take.append(coin)
count += 1
if sum(coin_to_take) > sum(coins[coins.index(coin)+1:]):
break
print(count) | Title: Twins
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Imagine that you have a twin brother or sister. Having another person that looks exactly like you seems very unusual. It's hard to say if having something of an alter ego is good or bad. And if you do have a twin, then you very w... | ```python
num = int(input())
coins = [int(x) for x in input().split()]
coin_to_take = list()
count = 0
coins.sort()
coins.reverse()
for coin in coins:
coin_to_take.append(coin)
count += 1
if sum(coin_to_take) > sum(coins[coins.index(coin)+1:]):
break
print(count)
``` | 0 | |
127 | A | Wasted Time | PROGRAMMING | 900 | [
"geometry"
] | null | null | Mr. Scrooge, a very busy man, decided to count the time he wastes on all sorts of useless stuff to evaluate the lost profit. He has already counted the time he wastes sleeping and eating. And now Mr. Scrooge wants to count the time he has wasted signing papers.
Mr. Scrooge's signature can be represented as a polyline ... | The first line contains two integers *n* and *k* (2<=≤<=*n*<=≤<=100, 1<=≤<=*k*<=≤<=1000). Each of the following *n* lines contains the coordinates of the polyline's endpoints. The *i*-th one contains coordinates of the point *A**i* — integers *x**i* and *y**i*, separated by a space.
All points *A**i* are different. Th... | Print one real number — the total time Scrooges wastes on signing the papers in seconds. The absolute or relative error should not exceed 10<=-<=6. | [
"2 1\n0 0\n10 0\n",
"5 10\n3 1\n-5 6\n-2 -1\n3 2\n10 0\n",
"6 10\n5 0\n4 0\n6 0\n3 0\n7 0\n2 0\n"
] | [
"0.200000000",
"6.032163204",
"3.000000000"
] | none | 500 | [
{
"input": "2 1\n0 0\n10 0",
"output": "0.200000000"
},
{
"input": "5 10\n3 1\n-5 6\n-2 -1\n3 2\n10 0",
"output": "6.032163204"
},
{
"input": "6 10\n5 0\n4 0\n6 0\n3 0\n7 0\n2 0",
"output": "3.000000000"
},
{
"input": "10 95\n-20 -5\n2 -8\n14 13\n10 3\n17 11\n13 -12\n-6 11\n1... | 1,595,259,272 | 2,147,483,647 | PyPy 3 | OK | TESTS | 42 | 310 | 20,172,800 | n,k=map(int,input().split())
ans=0
fx,fy=map(int,input().split())
for i in range(n-1):
x,y=map(int,input().split())
ans+=(((fx-x)**2+(fy-y)**2)**.5)/50
fx,fy=x,y
print(ans*k) | Title: Wasted Time
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mr. Scrooge, a very busy man, decided to count the time he wastes on all sorts of useless stuff to evaluate the lost profit. He has already counted the time he wastes sleeping and eating. And now Mr. Scrooge wants to count ... | ```python
n,k=map(int,input().split())
ans=0
fx,fy=map(int,input().split())
for i in range(n-1):
x,y=map(int,input().split())
ans+=(((fx-x)**2+(fy-y)**2)**.5)/50
fx,fy=x,y
print(ans*k)
``` | 3 | |
66 | B | Petya and Countryside | PROGRAMMING | 1,100 | [
"brute force",
"implementation"
] | B. Petya and Countryside | 2 | 256 | Little Petya often travels to his grandmother in the countryside. The grandmother has a large garden, which can be represented as a rectangle 1<=×<=*n* in size, when viewed from above. This rectangle is divided into *n* equal square sections. The garden is very unusual as each of the square sections possesses its own f... | The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=1000). The second line contains *n* positive integers which are the height of the sections. All the numbers are no less than 1 and not more than 1000. | Print a single number, the maximal number of watered sections if we create artificial rain above exactly one section. | [
"1\n2\n",
"5\n1 2 1 2 1\n",
"8\n1 2 1 1 1 3 3 4\n"
] | [
"1\n",
"3\n",
"6\n"
] | none | 1,000 | [
{
"input": "1\n2",
"output": "1"
},
{
"input": "5\n1 2 1 2 1",
"output": "3"
},
{
"input": "8\n1 2 1 1 1 3 3 4",
"output": "6"
},
{
"input": "10\n1 2 3 4 5 6 7 8 9 10",
"output": "10"
},
{
"input": "10\n10 9 8 7 6 5 4 3 2 1",
"output": "10"
},
{
"input... | 1,587,576,391 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 7 | 280 | 0 | n=int(input())
b=[]
l=list(map(int,input().split()))
if n>2:
for i in range(n):
j=i-1
count=0
ref=l[i]
while(j>=0):
if ref>=l[j]:
count+=1
ref=l[j]
j-=1
else:
break
j=i+1
... | Title: Petya and Countryside
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Little Petya often travels to his grandmother in the countryside. The grandmother has a large garden, which can be represented as a rectangle 1<=×<=*n* in size, when viewed from above. This rectangle is divided into *... | ```python
n=int(input())
b=[]
l=list(map(int,input().split()))
if n>2:
for i in range(n):
j=i-1
count=0
ref=l[i]
while(j>=0):
if ref>=l[j]:
count+=1
ref=l[j]
j-=1
else:
break
... | 0 |
356 | A | Knight Tournament | PROGRAMMING | 1,500 | [
"data structures",
"dsu"
] | null | null | Hooray! Berl II, the king of Berland is making a knight tournament. The king has already sent the message to all knights in the kingdom and they in turn agreed to participate in this grand event.
As for you, you're just a simple peasant. There's no surprise that you slept in this morning and were late for the tourname... | The first line contains two integers *n*, *m* (2<=≤<=*n*<=≤<=3·105; 1<=≤<=*m*<=≤<=3·105) — the number of knights and the number of fights. Each of the following *m* lines contains three integers *l**i*,<=*r**i*,<=*x**i* (1<=≤<=*l**i*<=<<=*r**i*<=≤<=*n*; *l**i*<=≤<=*x**i*<=≤<=*r**i*) — the description of the *i*-th f... | Print *n* integers. If the *i*-th knight lost, then the *i*-th number should equal the number of the knight that beat the knight number *i*. If the *i*-th knight is the winner, then the *i*-th number must equal 0. | [
"4 3\n1 2 1\n1 3 3\n1 4 4\n",
"8 4\n3 5 4\n3 7 6\n2 8 8\n1 8 1\n"
] | [
"3 1 4 0 ",
"0 8 4 6 4 8 6 1 "
] | Consider the first test case. Knights 1 and 2 fought the first fight and knight 1 won. Knights 1 and 3 fought the second fight and knight 3 won. The last fight was between knights 3 and 4, knight 4 won. | 500 | [
{
"input": "4 3\n1 2 1\n1 3 3\n1 4 4",
"output": "3 1 4 0 "
},
{
"input": "8 4\n3 5 4\n3 7 6\n2 8 8\n1 8 1",
"output": "0 8 4 6 4 8 6 1 "
},
{
"input": "2 1\n1 2 1",
"output": "0 1 "
},
{
"input": "2 1\n1 2 2",
"output": "2 0 "
},
{
"input": "3 1\n1 3 1",
"out... | 1,639,137,330 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 10 | 3,000 | 1,126,400 | n, m = map(int, input().split())
knights = [0] * (n + 1)
for _ in range(m):
l, r, x = map(int, input().split())
for i in range(l, r + 1):
if knights[i] == 0 and i != x:
knights[i] = x
for i in range(1, len(knights)):
print(knights[i], end=" ")
| Title: Knight Tournament
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Hooray! Berl II, the king of Berland is making a knight tournament. The king has already sent the message to all knights in the kingdom and they in turn agreed to participate in this grand event.
As for you, you're j... | ```python
n, m = map(int, input().split())
knights = [0] * (n + 1)
for _ in range(m):
l, r, x = map(int, input().split())
for i in range(l, r + 1):
if knights[i] == 0 and i != x:
knights[i] = x
for i in range(1, len(knights)):
print(knights[i], end=" ")
``` | 0 | |
507 | B | Amr and Pins | PROGRAMMING | 1,400 | [
"geometry",
"math"
] | null | null | Amr loves Geometry. One day he came up with a very interesting problem.
Amr has a circle of radius *r* and center in point (*x*,<=*y*). He wants the circle center to be in new position (*x*',<=*y*').
In one step Amr can put a pin to the border of the circle in a certain point, then rotate the circle around that pin b... | Input consists of 5 space-separated integers *r*, *x*, *y*, *x*' *y*' (1<=≤<=*r*<=≤<=105, <=-<=105<=≤<=*x*,<=*y*,<=*x*',<=*y*'<=≤<=105), circle radius, coordinates of original center of the circle and coordinates of destination center of the circle respectively. | Output a single integer — minimum number of steps required to move the center of the circle to the destination point. | [
"2 0 0 0 4\n",
"1 1 1 4 4\n",
"4 5 6 5 6\n"
] | [
"1\n",
"3\n",
"0\n"
] | In the first sample test the optimal way is to put a pin at point (0, 2) and rotate the circle by 180 degrees counter-clockwise (or clockwise, no matter).
<img class="tex-graphics" src="https://espresso.codeforces.com/4e40fd4cc24a2050a0488aa131e6244369328039.png" style="max-width: 100.0%;max-height: 100.0%;"/> | 1,000 | [
{
"input": "2 0 0 0 4",
"output": "1"
},
{
"input": "1 1 1 4 4",
"output": "3"
},
{
"input": "4 5 6 5 6",
"output": "0"
},
{
"input": "10 20 0 40 0",
"output": "1"
},
{
"input": "9 20 0 40 0",
"output": "2"
},
{
"input": "5 -1 -6 -5 1",
"output": "... | 1,646,848,155 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 30 | 0 | from math import sqrt
r, x1, y1, x, y = map(int,input().split())
distance = sqrt( (x-x1)**2 + (y-y1)**2 )
distance -= r
#print(distance)
if distance % (2*r) == 0:
print(int(distance // (2*r) ) )
else:
print(int(distance // (2*r) ) + 2 )
| Title: Amr and Pins
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Amr loves Geometry. One day he came up with a very interesting problem.
Amr has a circle of radius *r* and center in point (*x*,<=*y*). He wants the circle center to be in new position (*x*',<=*y*').
In one step Amr can ... | ```python
from math import sqrt
r, x1, y1, x, y = map(int,input().split())
distance = sqrt( (x-x1)**2 + (y-y1)**2 )
distance -= r
#print(distance)
if distance % (2*r) == 0:
print(int(distance // (2*r) ) )
else:
print(int(distance // (2*r) ) + 2 )
``` | 0 | |
705 | A | Hulk | PROGRAMMING | 800 | [
"implementation"
] | null | null | Dr. Bruce Banner hates his enemies (like others don't). As we all know, he can barely talk when he turns into the incredible Hulk. That's why he asked you to help him to express his feelings.
Hulk likes the Inception so much, and like that his feelings are complicated. They have *n* layers. The first layer is hate, se... | The only line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of layers of love and hate. | Print Dr.Banner's feeling in one line. | [
"1\n",
"2\n",
"3\n"
] | [
"I hate it\n",
"I hate that I love it\n",
"I hate that I love that I hate it\n"
] | none | 500 | [
{
"input": "1",
"output": "I hate it"
},
{
"input": "2",
"output": "I hate that I love it"
},
{
"input": "3",
"output": "I hate that I love that I hate it"
},
{
"input": "4",
"output": "I hate that I love that I hate that I love it"
},
{
"input": "5",
"output"... | 1,685,417,171 | 2,147,483,647 | Python 3 | OK | TESTS | 21 | 31 | 0 | n = int(input())
s1 = "I hate"
s2 = "I love"
final = ""
for i in range(n):
if i>0:
final +=" that "
if i%2==0:
final +=s1
else:
final +=s2
print(final+" it") | Title: Hulk
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Dr. Bruce Banner hates his enemies (like others don't). As we all know, he can barely talk when he turns into the incredible Hulk. That's why he asked you to help him to express his feelings.
Hulk likes the Inception so much, and... | ```python
n = int(input())
s1 = "I hate"
s2 = "I love"
final = ""
for i in range(n):
if i>0:
final +=" that "
if i%2==0:
final +=s1
else:
final +=s2
print(final+" it")
``` | 3 | |
965 | C | Greedy Arkady | PROGRAMMING | 2,000 | [
"math"
] | null | null | $k$ people want to split $n$ candies between them. Each candy should be given to exactly one of them or be thrown away.
The people are numbered from $1$ to $k$, and Arkady is the first of them. To split the candies, Arkady will choose an integer $x$ and then give the first $x$ candies to himself, the next $x$ candies ... | The only line contains four integers $n$, $k$, $M$ and $D$ ($2 \le n \le 10^{18}$, $2 \le k \le n$, $1 \le M \le n$, $1 \le D \le \min{(n, 1000)}$, $M \cdot D \cdot k \ge n$) — the number of candies, the number of people, the maximum number of candies given to a person at once, the maximum number of times a person can ... | Print a single integer — the maximum possible number of candies Arkady can give to himself.
Note that it is always possible to choose some valid $x$. | [
"20 4 5 2\n",
"30 9 4 1\n"
] | [
"8\n",
"4\n"
] | In the first example Arkady should choose $x = 4$. He will give $4$ candies to himself, $4$ candies to the second person, $4$ candies to the third person, then $4$ candies to the fourth person and then again $4$ candies to himself. No person is given candies more than $2$ times, and Arkady receives $8$ candies in total... | 1,500 | [
{
"input": "20 4 5 2",
"output": "8"
},
{
"input": "30 9 4 1",
"output": "4"
},
{
"input": "2 2 1 1",
"output": "1"
},
{
"input": "42 20 5 29",
"output": "5"
},
{
"input": "1000000000000000000 135 1000000000000000 1000",
"output": "8325624421831635"
},
{
... | 1,531,117,111 | 2,147,483,647 | Python 3 | OK | TESTS | 25 | 109 | 0 | from sys import stdin
n, k, M, D = map(int, stdin.readline().strip().split())
print(max(map(lambda d: d * min(M, n // (1 + (d - 1) * k)), range(1, D + 1))))
| Title: Greedy Arkady
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
$k$ people want to split $n$ candies between them. Each candy should be given to exactly one of them or be thrown away.
The people are numbered from $1$ to $k$, and Arkady is the first of them. To split the candies, Arka... | ```python
from sys import stdin
n, k, M, D = map(int, stdin.readline().strip().split())
print(max(map(lambda d: d * min(M, n // (1 + (d - 1) * k)), range(1, D + 1))))
``` | 3 | |
280 | B | Maximum Xor Secondary | PROGRAMMING | 1,800 | [
"data structures",
"implementation",
"two pointers"
] | null | null | Bike loves looking for the second maximum element in the sequence. The second maximum element in the sequence of distinct numbers *x*1,<=*x*2,<=...,<=*x**k* (*k*<=><=1) is such maximum element *x**j*, that the following inequality holds: .
The lucky number of the sequence of distinct positive integers *x*1,<=*x*2,<... | The first line contains integer *n* (1<=<<=*n*<=≤<=105). The second line contains *n* distinct integers *s*1,<=*s*2,<=...,<=*s**n* (1<=≤<=*s**i*<=≤<=109). | Print a single integer — the maximum lucky number among all lucky numbers of sequences *s*[*l*..*r*]. | [
"5\n5 2 1 4 3\n",
"5\n9 8 3 5 7\n"
] | [
"7\n",
"15\n"
] | For the first sample you can choose *s*[4..5] = {4, 3} and its lucky number is (4 *xor* 3) = 7. You can also choose *s*[1..2].
For the second sample you must choose *s*[2..5] = {8, 3, 5, 7}. | 1,000 | [
{
"input": "5\n5 2 1 4 3",
"output": "7"
},
{
"input": "5\n9 8 3 5 7",
"output": "15"
},
{
"input": "10\n76969694 71698884 32888447 31877010 65564584 87864180 7850891 1505323 17879621 15722446",
"output": "128869996"
},
{
"input": "10\n4547989 39261040 94929326 38131456 26174... | 1,659,683,718 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 56 | 93 | 14,848,000 |
n, a = int(input()), list(map(int, input().split()))
def f(arr):
ret = 0
st = []
for v in arr:
while st and st[-1] < v:
ret = max(st.pop(-1) ^ v, ret)
if st:
ret=max(st[-1]^v,ret)
st.append(v)
return ret
print(f(a)) | Title: Maximum Xor Secondary
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bike loves looking for the second maximum element in the sequence. The second maximum element in the sequence of distinct numbers *x*1,<=*x*2,<=...,<=*x**k* (*k*<=><=1) is such maximum element *x**j*, that the ... | ```python
n, a = int(input()), list(map(int, input().split()))
def f(arr):
ret = 0
st = []
for v in arr:
while st and st[-1] < v:
ret = max(st.pop(-1) ^ v, ret)
if st:
ret=max(st[-1]^v,ret)
st.append(v)
return ret
print(f(a))
``` | 3 | |
610 | B | Vika and Squares | PROGRAMMING | 1,300 | [
"constructive algorithms",
"implementation"
] | null | null | Vika has *n* jars with paints of distinct colors. All the jars are numbered from 1 to *n* and the *i*-th jar contains *a**i* liters of paint of color *i*.
Vika also has an infinitely long rectangular piece of paper of width 1, consisting of squares of size 1<=×<=1. Squares are numbered 1, 2, 3 and so on. Vika decided ... | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=200<=000) — the number of jars with colors Vika has.
The second line of the input contains a sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109), where *a**i* is equal to the number of liters of paint in the *i*-th jar, i.e. th... | The only line of the output should contain a single integer — the maximum number of squares that Vika can paint if she follows the rules described above. | [
"5\n2 4 2 3 3\n",
"3\n5 5 5\n",
"6\n10 10 10 1 10 10\n"
] | [
"12\n",
"15\n",
"11\n"
] | In the first sample the best strategy is to start painting using color 4. Then the squares will be painted in the following colors (from left to right): 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5.
In the second sample Vika can start to paint using any color.
In the third sample Vika should start painting using color number 5... | 1,000 | [
{
"input": "5\n2 4 2 3 3",
"output": "12"
},
{
"input": "3\n5 5 5",
"output": "15"
},
{
"input": "6\n10 10 10 1 10 10",
"output": "11"
},
{
"input": "1\n167959139",
"output": "167959139"
},
{
"input": "10\n896619242 805194919 844752453 848347723 816995848 85681361... | 1,630,210,883 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 6 | 248 | 39,116,800 | n = int(input())
l = list(map(int,input().split()))
a = min(l)
mini = -1
for i in range(len(l)):
if l[i]==a:
mini = i
flag = False
c=0
for i in range(mini+1):
if l[i]==a:
flag = True
if not flag:
c+=(a+1)
else:
c+=a
for i in range(mini+1,n):
c+=a+1
p... | Title: Vika and Squares
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vika has *n* jars with paints of distinct colors. All the jars are numbered from 1 to *n* and the *i*-th jar contains *a**i* liters of paint of color *i*.
Vika also has an infinitely long rectangular piece of paper of... | ```python
n = int(input())
l = list(map(int,input().split()))
a = min(l)
mini = -1
for i in range(len(l)):
if l[i]==a:
mini = i
flag = False
c=0
for i in range(mini+1):
if l[i]==a:
flag = True
if not flag:
c+=(a+1)
else:
c+=a
for i in range(mini+1,n):
... | 0 | |
703 | A | Mishka and Game | PROGRAMMING | 800 | [
"implementation"
] | null | null | Mishka is a little polar bear. As known, little bears loves spending their free time playing dice for chocolates. Once in a wonderful sunny morning, walking around blocks of ice, Mishka met her friend Chris, and they started playing the game.
Rules of the game are very simple: at first number of rounds *n* is defined.... | The first line of the input contains single integer *n* *n* (1<=≤<=*n*<=≤<=100) — the number of game rounds.
The next *n* lines contains rounds description. *i*-th of them contains pair of integers *m**i* and *c**i* (1<=≤<=*m**i*,<=<=*c**i*<=≤<=6) — values on dice upper face after Mishka's and Chris' throws in *i*-th ... | If Mishka is the winner of the game, print "Mishka" (without quotes) in the only line.
If Chris is the winner of the game, print "Chris" (without quotes) in the only line.
If the result of the game is draw, print "Friendship is magic!^^" (without quotes) in the only line. | [
"3\n3 5\n2 1\n4 2\n",
"2\n6 1\n1 6\n",
"3\n1 5\n3 3\n2 2\n"
] | [
"Mishka",
"Friendship is magic!^^",
"Chris"
] | In the first sample case Mishka loses the first round, but wins second and third rounds and thus she is the winner of the game.
In the second sample case Mishka wins the first round, Chris wins the second round, and the game ends with draw with score 1:1.
In the third sample case Chris wins the first round, but there... | 500 | [
{
"input": "3\n3 5\n2 1\n4 2",
"output": "Mishka"
},
{
"input": "2\n6 1\n1 6",
"output": "Friendship is magic!^^"
},
{
"input": "3\n1 5\n3 3\n2 2",
"output": "Chris"
},
{
"input": "6\n4 1\n4 2\n5 3\n5 1\n5 3\n4 1",
"output": "Mishka"
},
{
"input": "8\n2 4\n1 4\n1 ... | 1,694,605,310 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 5 | 77 | 0 | n=int(input())
s=0;
t=0;
for i in range(n):
a,b=map(int,input().split())
s+=a;
t+=b;
if s==t:
print('Friendship is magic!^^');
if s>t:
print('Mishka');
elif s<t:
print('Chris');
| Title: Mishka and Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mishka is a little polar bear. As known, little bears loves spending their free time playing dice for chocolates. Once in a wonderful sunny morning, walking around blocks of ice, Mishka met her friend Chris, and they st... | ```python
n=int(input())
s=0;
t=0;
for i in range(n):
a,b=map(int,input().split())
s+=a;
t+=b;
if s==t:
print('Friendship is magic!^^');
if s>t:
print('Mishka');
elif s<t:
print('Chris');
``` | 0 | |
300 | A | Array | PROGRAMMING | 1,100 | [
"brute force",
"constructive algorithms",
"implementation"
] | null | null | Vitaly has an array of *n* distinct integers. Vitaly wants to divide this array into three non-empty sets so as the following conditions hold:
1. The product of all numbers in the first set is less than zero (<=<<=0). 1. The product of all numbers in the second set is greater than zero (<=><=0). 1. The produ... | The first line of the input contains integer *n* (3<=≤<=*n*<=≤<=100). The second line contains *n* space-separated distinct integers *a*1,<=*a*2,<=...,<=*a**n* (|*a**i*|<=≤<=103) — the array elements. | In the first line print integer *n*1 (*n*1<=><=0) — the number of elements in the first set. Then print *n*1 numbers — the elements that got to the first set.
In the next line print integer *n*2 (*n*2<=><=0) — the number of elements in the second set. Then print *n*2 numbers — the elements that got to the second... | [
"3\n-1 2 0\n",
"4\n-1 -2 -3 0\n"
] | [
"1 -1\n1 2\n1 0\n",
"1 -1\n2 -3 -2\n1 0\n"
] | none | 500 | [
{
"input": "3\n-1 2 0",
"output": "1 -1\n1 2\n1 0"
},
{
"input": "4\n-1 -2 -3 0",
"output": "1 -1\n2 -3 -2\n1 0"
},
{
"input": "5\n-1 -2 1 2 0",
"output": "1 -1\n2 1 2\n2 0 -2"
},
{
"input": "100\n-64 -51 -75 -98 74 -26 -1 -8 -99 -76 -53 -80 -43 -22 -100 -62 -34 -5 -65 -81 -1... | 1,688,870,013 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 20 | 124 | 0 | n = int(input())
arr = list(map(int, input().split()))
nArr = list(filter(lambda x: x < 0, arr))
pArr = list(filter(lambda x: x > 0, arr))
zArr = list(filter(lambda x: x == 0, arr))
if len(nArr) % 2 == 0:
val = nArr.pop()
zArr.append(val)
if len(pArr) == 0:
pArr += nArr[:2]
nArr = nArr[2:]... | Title: Array
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vitaly has an array of *n* distinct integers. Vitaly wants to divide this array into three non-empty sets so as the following conditions hold:
1. The product of all numbers in the first set is less than zero (<=<<=0). 1. T... | ```python
n = int(input())
arr = list(map(int, input().split()))
nArr = list(filter(lambda x: x < 0, arr))
pArr = list(filter(lambda x: x > 0, arr))
zArr = list(filter(lambda x: x == 0, arr))
if len(nArr) % 2 == 0:
val = nArr.pop()
zArr.append(val)
if len(pArr) == 0:
pArr += nArr[:2]
nArr ... | 3 | |
653 | C | Bear and Up-Down | PROGRAMMING | 1,900 | [
"brute force",
"implementation"
] | null | null | The life goes up and down, just like nice sequences. Sequence *t*1,<=*t*2,<=...,<=*t**n* is called nice if the following two conditions are satisfied:
- *t**i*<=<<=*t**i*<=+<=1 for each odd *i*<=<<=*n*; - *t**i*<=><=*t**i*<=+<=1 for each even *i*<=<<=*n*.
For example, sequences (2,<=8), (1,<=5,<=1) and... | The first line of the input contains one integer *n* (2<=≤<=*n*<=≤<=150<=000) — the length of the sequence.
The second line contains *n* integers *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t**i*<=≤<=150<=000) — the initial sequence. It's guaranteed that the given sequence is not nice. | Print the number of ways to swap two elements exactly once in order to get a nice sequence. | [
"5\n2 8 4 7 7\n",
"4\n200 150 100 50\n",
"10\n3 2 1 4 1 4 1 4 1 4\n",
"9\n1 2 3 4 5 6 7 8 9\n"
] | [
"2\n",
"1\n",
"8\n",
"0\n"
] | In the first sample, there are two ways to get a nice sequence with one swap:
1. Swap *t*<sub class="lower-index">2</sub> = 8 with *t*<sub class="lower-index">4</sub> = 7. 1. Swap *t*<sub class="lower-index">1</sub> = 2 with *t*<sub class="lower-index">5</sub> = 7.
In the second sample, there is only one way — Lim... | 1,500 | [
{
"input": "5\n2 8 4 7 7",
"output": "2"
},
{
"input": "4\n200 150 100 50",
"output": "1"
},
{
"input": "10\n3 2 1 4 1 4 1 4 1 4",
"output": "8"
},
{
"input": "9\n1 2 3 4 5 6 7 8 9",
"output": "0"
},
{
"input": "5\n1 1 1 4 3",
"output": "1"
},
{
"input... | 1,576,117,520 | 2,147,483,647 | Python 3 | OK | TESTS | 44 | 1,747 | 10,854,400 | def get_bit(diff, i):
return 1 if ((i%2==1 and diff<=0) or (i%2==0 and diff>=0)) else 0
def swap_(i, j, a):
temp = a[i]
a[i] = a[j]
a[j] = temp
def swap(i, j, n, a, mask, S):
change = 0
swap_(i, j, a)
set_index = set([i, j])
if i<n-1:
set_index.add(i+1... | Title: Bear and Up-Down
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The life goes up and down, just like nice sequences. Sequence *t*1,<=*t*2,<=...,<=*t**n* is called nice if the following two conditions are satisfied:
- *t**i*<=<<=*t**i*<=+<=1 for each odd *i*<=<<=*n*; - *t*... | ```python
def get_bit(diff, i):
return 1 if ((i%2==1 and diff<=0) or (i%2==0 and diff>=0)) else 0
def swap_(i, j, a):
temp = a[i]
a[i] = a[j]
a[j] = temp
def swap(i, j, n, a, mask, S):
change = 0
swap_(i, j, a)
set_index = set([i, j])
if i<n-1:
set_ind... | 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,683,805,899 | 2,147,483,647 | Python 3 | OK | TESTS | 54 | 46 | 0 | k,r=map(int,input().split())
i=1
x=k
while i>=1:
if k%10==0:
print(i)
break
elif (k-r)%10==0:
print(i)
break
else:
i+=1
k=i*x
| Title: Buy a Shovel
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp urgently needs a shovel! He comes to the shop and chooses an appropriate one. The shovel that Policarp chooses is sold for *k* burles. Assume that there is an unlimited number of such shovels in the shop.
In his ... | ```python
k,r=map(int,input().split())
i=1
x=k
while i>=1:
if k%10==0:
print(i)
break
elif (k-r)%10==0:
print(i)
break
else:
i+=1
k=i*x
``` | 3 | |
120 | G | Boom | PROGRAMMING | 1,800 | [
"implementation"
] | null | null | Let's consider the famous game called Boom (aka Hat) with simplified rules.
There are *n* teams playing the game. Each team has two players. The purpose of the game is to explain the words to the teammate without using any words that contain the same root or that sound similarly.
Player *j* from team *i* (1<=≤<=*i*<... | The first line contains two integers *n*,<=*t* (1<=≤<=*n*,<=*t*<=≤<=100), which correspondingly denote the number of teams and a turn's duration.
Next *n* lines of the input file contain four integers each: *a**i*1,<=*b**i*1,<=*a**i*2,<=*b**i*2 (1<=≤<=*a**ij*,<=*b**ij*<=≤<=100) — the skills of the first and the second... | Print *n* lines. On the *i*-th line first print number *s**i* the number of points the *i*-th team wins. Then print *s**i* space-separated words — the words from the cards guessed by team *i* in the order in which they were guessed. | [
"2 2\n1 1 1 1\n1 1 1 1\n3\nhome\n1\ncar\n1\nbrother\n1\n",
"2 4\n1 2 2 1\n2 3 2 2\n4\narmchair\n3\nquetzalcoatl\n10\npilotage\n5\ndefibrillator\n7\n"
] | [
"2 home car \n1 brother \n",
"2 armchair quetzalcoatl \n2 pilotage defibrillator \n"
] | none | 0 | [
{
"input": "2 2\n1 1 1 1\n1 1 1 1\n3\nhome\n1\ncar\n1\nbrother\n1",
"output": "2 home car \n1 brother "
},
{
"input": "2 4\n1 2 2 1\n2 3 2 2\n4\narmchair\n3\nquetzalcoatl\n10\npilotage\n5\ndefibrillator\n7",
"output": "2 armchair quetzalcoatl \n2 pilotage defibrillator "
},
{
"input": "5... | 1,623,836,854 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 3 | 184 | 409,600 | import sys
from collections import deque
sys.stdin = open('input.txt', 'r')
sys.stdout = open('output.txt', 'w')
n, t = [int(x) for x in input().split()]
teams = []
for i in range(n):
a1, b1, a2, b2 = [int(x) for x in input().split()]
teams.append((a1 + b2, a2 + b1))
m = int(input())
words = []
... | Title: Boom
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Let's consider the famous game called Boom (aka Hat) with simplified rules.
There are *n* teams playing the game. Each team has two players. The purpose of the game is to explain the words to the teammate without using any words ... | ```python
import sys
from collections import deque
sys.stdin = open('input.txt', 'r')
sys.stdout = open('output.txt', 'w')
n, t = [int(x) for x in input().split()]
teams = []
for i in range(n):
a1, b1, a2, b2 = [int(x) for x in input().split()]
teams.append((a1 + b2, a2 + b1))
m = int(input())
w... | 0 | |
271 | D | Good Substrings | PROGRAMMING | 1,800 | [
"data structures",
"strings"
] | null | null | You've got string *s*, consisting of small English letters. Some of the English letters are good, the rest are bad.
A substring *s*[*l*...*r*] (1<=≤<=*l*<=≤<=*r*<=≤<=|*s*|) of string *s*<=<==<=<=*s*1*s*2...*s*|*s*| (where |*s*| is the length of string *s*) is string <=*s**l**s**l*<=+<=1...*s**r*.
The substring *s*[*l... | The first line of the input is the non-empty string *s*, consisting of small English letters, the string's length is at most 1500 characters.
The second line of the input is the string of characters "0" and "1", the length is exactly 26 characters. If the *i*-th character of this string equals "1", then the *i*-th Eng... | Print a single integer — the number of distinct good substrings of string *s*. | [
"ababab\n01000000000000000000000000\n1\n",
"acbacbacaa\n00000000000000000000000000\n2\n"
] | [
"5\n",
"8\n"
] | In the first example there are following good substrings: "a", "ab", "b", "ba", "bab".
In the second example there are following good substrings: "a", "aa", "ac", "b", "ba", "c", "ca", "cb". | 2,000 | [
{
"input": "ababab\n01000000000000000000000000\n1",
"output": "5"
},
{
"input": "acbacbacaa\n00000000000000000000000000\n2",
"output": "8"
},
{
"input": "a\n00000000000000000000000000\n0",
"output": "0"
},
{
"input": "aaaa\n00000000000000000000000000\n0",
"output": "0"
... | 1,691,430,237 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 7 | 2,000 | 113,152,000 | p = 31
m1 = 10**9+7
m2 = 10**9+9
s = input()
n = len(s)
alpha = []
for i in input():
if i == '0':
alpha.append(1)
else:
alpha.append(0)
k = int(input())
good = set()
for l in range(n):
bad = alpha[ord(s[l]) - ord('a')]
h1 = (ord(s[l]) - or... | Title: Good Substrings
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You've got string *s*, consisting of small English letters. Some of the English letters are good, the rest are bad.
A substring *s*[*l*...*r*] (1<=≤<=*l*<=≤<=*r*<=≤<=|*s*|) of string *s*<=<==<=<=*s*1*s*2...*s*|*s*| (wh... | ```python
p = 31
m1 = 10**9+7
m2 = 10**9+9
s = input()
n = len(s)
alpha = []
for i in input():
if i == '0':
alpha.append(1)
else:
alpha.append(0)
k = int(input())
good = set()
for l in range(n):
bad = alpha[ord(s[l]) - ord('a')]
h1 = (ord(... | 0 | |
764 | B | Timofey and cubes | PROGRAMMING | 900 | [
"constructive algorithms",
"implementation"
] | null | null | Young Timofey has a birthday today! He got kit of *n* cubes as a birthday present from his parents. Every cube has a number *a**i*, which is written on it. Timofey put all the cubes in a row and went to unpack other presents.
In this time, Timofey's elder brother, Dima reordered the cubes using the following rule. Sup... | The first line contains single integer *n* (1<=≤<=*n*<=≤<=2·105) — the number of cubes.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (<=-<=109<=≤<=*a**i*<=≤<=109), where *a**i* is the number written on the *i*-th cube after Dima has changed their order. | Print *n* integers, separated by spaces — the numbers written on the cubes in their initial order.
It can be shown that the answer is unique. | [
"7\n4 3 7 6 9 1 2\n",
"8\n6 1 4 2 5 6 9 2\n"
] | [
"2 3 9 6 7 1 4",
"2 1 6 2 5 4 9 6"
] | Consider the first sample.
1. At the begining row was [2, 3, 9, 6, 7, 1, 4]. 1. After first operation row was [4, 1, 7, 6, 9, 3, 2]. 1. After second operation row was [4, 3, 9, 6, 7, 1, 2]. 1. After third operation row was [4, 3, 7, 6, 9, 1, 2]. 1. At fourth operation we reverse just middle element, so nothing ha... | 1,000 | [
{
"input": "7\n4 3 7 6 9 1 2",
"output": "2 3 9 6 7 1 4"
},
{
"input": "8\n6 1 4 2 5 6 9 2",
"output": "2 1 6 2 5 4 9 6"
},
{
"input": "1\n1424",
"output": "1424"
},
{
"input": "9\n-7 9 -4 9 -6 11 15 2 -10",
"output": "-10 9 15 9 -6 11 -4 2 -7"
},
{
"input": "2\n2... | 1,592,751,304 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 452 | 18,636,800 | i=0
j=int(input())
j=j-1
a=list(map(int,input().split()))
while j>i:
a[j],a[i]=a[i],a[j]
i=i+2
j=j-2
for i in a:
print(i,end=' ') | Title: Timofey and cubes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Young Timofey has a birthday today! He got kit of *n* cubes as a birthday present from his parents. Every cube has a number *a**i*, which is written on it. Timofey put all the cubes in a row and went to unpack other p... | ```python
i=0
j=int(input())
j=j-1
a=list(map(int,input().split()))
while j>i:
a[j],a[i]=a[i],a[j]
i=i+2
j=j-2
for i in a:
print(i,end=' ')
``` | 3 | |
68 | B | Energy exchange | PROGRAMMING | 1,600 | [
"binary search"
] | B. Energy exchange | 2 | 256 | It is well known that the planet suffers from the energy crisis. Little Petya doesn't like that and wants to save the world. For this purpose he needs every accumulator to contain the same amount of energy. Initially every accumulator has some amount of energy: the *i*-th accumulator has *a**i* units of energy. Energy ... | First line of the input contains two integers *n* and *k* (1<=≤<=*n*<=≤<=10000,<=0<=≤<=*k*<=≤<=99) — number of accumulators and the percent of energy that is lost during transfers.
Next line contains *n* integers *a*1,<=*a*2,<=... ,<=*a**n* — amounts of energy in the first, second, .., *n*-th accumulator respectively ... | Output maximum possible amount of energy that can remain in each of accumulators after the transfers of energy.
The absolute or relative error in the answer should not exceed 10<=-<=6. | [
"3 50\n4 2 1\n",
"2 90\n1 11\n"
] | [
"2.000000000\n",
"1.909090909\n"
] | none | 1,000 | [
{
"input": "3 50\n4 2 1",
"output": "2.000000000"
},
{
"input": "2 90\n1 11",
"output": "1.909090909"
},
{
"input": "5 26\n42 65 23 43 64",
"output": "45.415178571"
},
{
"input": "5 45\n964 515 454 623 594",
"output": "594.109756098"
},
{
"input": "1 20\n784",
... | 1,515,243,327 | 2,147,483,647 | Python 3 | OK | TESTS | 42 | 404 | 6,144,000 | n, k = map(int, input().split())
a = list(map(int, input().split()))
s = sum(a)
eps = 0.0000000001
rem = (100-k)/100
left = min(a)
right = max(a)
guess = left
while (right - left) > eps:
guess = left + (right-left)/2
transferred = 0.0
missing = 0.0
for ai in a:
if ai-guess > 0:
... | Title: Energy exchange
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
It is well known that the planet suffers from the energy crisis. Little Petya doesn't like that and wants to save the world. For this purpose he needs every accumulator to contain the same amount of energy. Initially every ... | ```python
n, k = map(int, input().split())
a = list(map(int, input().split()))
s = sum(a)
eps = 0.0000000001
rem = (100-k)/100
left = min(a)
right = max(a)
guess = left
while (right - left) > eps:
guess = left + (right-left)/2
transferred = 0.0
missing = 0.0
for ai in a:
if ai-guess > 0:
... | 3.887556 |
7 | A | Kalevitch and Chess | PROGRAMMING | 1,100 | [
"brute force",
"constructive algorithms"
] | A. Kalevitch and Chess | 2 | 64 | A famous Berland's painter Kalevitch likes to shock the public. One of his last obsessions is chess. For more than a thousand years people have been playing this old game on uninteresting, monotonous boards. Kalevitch decided to put an end to this tradition and to introduce a new attitude to chessboards.
As before, th... | The input file contains 8 lines, each of the lines contains 8 characters. The given matrix describes the client's requirements, W character stands for a white square, and B character — for a square painted black.
It is guaranteed that client's requirments can be fulfilled with a sequence of allowed strokes (vertical/c... | Output the only number — the minimum amount of rows and columns that Kalevitch has to paint on the white chessboard to meet the client's requirements. | [
"WWWBWWBW\nBBBBBBBB\nWWWBWWBW\nWWWBWWBW\nWWWBWWBW\nWWWBWWBW\nWWWBWWBW\nWWWBWWBW\n",
"WWWWWWWW\nBBBBBBBB\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW\n"
] | [
"3\n",
"1\n"
] | none | 0 | [
{
"input": "WWWBWWBW\nBBBBBBBB\nWWWBWWBW\nWWWBWWBW\nWWWBWWBW\nWWWBWWBW\nWWWBWWBW\nWWWBWWBW",
"output": "3"
},
{
"input": "WWWWWWWW\nBBBBBBBB\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW",
"output": "1"
},
{
"input": "WWWWWWWW\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW\nWWWWWW... | 1,616,071,437 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 124 | 0 | s = [input().count('B') for i in range(8)]
print(min(s) % 8 + s.count(8)) | Title: Kalevitch and Chess
Time Limit: 2 seconds
Memory Limit: 64 megabytes
Problem Description:
A famous Berland's painter Kalevitch likes to shock the public. One of his last obsessions is chess. For more than a thousand years people have been playing this old game on uninteresting, monotonous boards. Kalevitch de... | ```python
s = [input().count('B') for i in range(8)]
print(min(s) % 8 + s.count(8))
``` | 3.969 |
462 | A | Appleman and Easy Task | PROGRAMMING | 1,000 | [
"brute force",
"implementation"
] | null | null | Toastman came up with a very easy task. He gives it to Appleman, but Appleman doesn't know how to solve it. Can you help him?
Given a *n*<=×<=*n* checkerboard. Each cell of the board has either character 'x', or character 'o'. Is it true that each cell of the board has even number of adjacent cells with 'o'? Two cells... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=100). Then *n* lines follow containing the description of the checkerboard. Each of them contains *n* characters (either 'x' or 'o') without spaces. | Print "YES" or "NO" (without the quotes) depending on the answer to the problem. | [
"3\nxxo\nxox\noxx\n",
"4\nxxxo\nxoxo\noxox\nxxxx\n"
] | [
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "3\nxxo\nxox\noxx",
"output": "YES"
},
{
"input": "4\nxxxo\nxoxo\noxox\nxxxx",
"output": "NO"
},
{
"input": "1\no",
"output": "YES"
},
{
"input": "2\nox\nxo",
"output": "YES"
},
{
"input": "2\nxx\nxo",
"output": "NO"
},
{
"input": "3\nooo\no... | 1,498,712,856 | 2,147,483,647 | Python 3 | OK | TESTS | 32 | 62 | 5,529,600 | n = int(input())
rows = []
for x in range(n):
string = input()
rows.append(string)
results = "YES"
for x in range(n):
for y in range(n):
a = y + 1
b = y - 1
c = x + 1
d = x - 1
z = 0
if a < n:
if rows[x][a] == "o":
z ... | Title: Appleman and Easy Task
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Toastman came up with a very easy task. He gives it to Appleman, but Appleman doesn't know how to solve it. Can you help him?
Given a *n*<=×<=*n* checkerboard. Each cell of the board has either character 'x', or... | ```python
n = int(input())
rows = []
for x in range(n):
string = input()
rows.append(string)
results = "YES"
for x in range(n):
for y in range(n):
a = y + 1
b = y - 1
c = x + 1
d = x - 1
z = 0
if a < n:
if rows[x][a] == "o":
... | 3 | |
340 | A | The Wall | PROGRAMMING | 1,200 | [
"math"
] | null | null | Iahub and his friend Floyd have started painting a wall. Iahub is painting the wall red and Floyd is painting it pink. You can consider the wall being made of a very large number of bricks, numbered 1, 2, 3 and so on.
Iahub has the following scheme of painting: he skips *x*<=-<=1 consecutive bricks, then he paints th... | The input will have a single line containing four integers in this order: *x*, *y*, *a*, *b*. (1<=≤<=*x*,<=*y*<=≤<=1000, 1<=≤<=*a*,<=*b*<=≤<=2·109, *a*<=≤<=*b*). | Output a single integer — the number of bricks numbered no less than *a* and no greater than *b* that are painted both red and pink. | [
"2 3 6 18\n"
] | [
"3"
] | Let's look at the bricks from *a* to *b* (*a* = 6, *b* = 18). The bricks colored in red are numbered 6, 8, 10, 12, 14, 16, 18. The bricks colored in pink are numbered 6, 9, 12, 15, 18. The bricks colored in both red and pink are numbered with 6, 12 and 18. | 500 | [
{
"input": "2 3 6 18",
"output": "3"
},
{
"input": "4 6 20 201",
"output": "15"
},
{
"input": "15 27 100 10000",
"output": "74"
},
{
"input": "105 60 3456 78910",
"output": "179"
},
{
"input": "1 1 1000 100000",
"output": "99001"
},
{
"input": "3 2 5 5... | 1,578,845,534 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 1 | 248 | 0 | from math import gcd
def getLCM(a, b):
return a * b // gcd(a, b)
s = input().split(" ")
print(int((int(s[3]) - int(s[2])) / getLCM(int(s[0]), int(s[1]))) + 1) | Title: The Wall
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Iahub and his friend Floyd have started painting a wall. Iahub is painting the wall red and Floyd is painting it pink. You can consider the wall being made of a very large number of bricks, numbered 1, 2, 3 and so on.
Iahub ... | ```python
from math import gcd
def getLCM(a, b):
return a * b // gcd(a, b)
s = input().split(" ")
print(int((int(s[3]) - int(s[2])) / getLCM(int(s[0]), int(s[1]))) + 1)
``` | 0 |
Subsets and Splits
Successful Python Submissions
Retrieves all records from the train dataset where the verdict is 'OK', providing basic filtering but limited analytical value.
SQL Console for MatrixStudio/Codeforces-Python-Submissions
Retrieves records of users with a rating of 1600 or higher and a verdict of 'OK', providing basic filtering but limited analytical value.
SQL Console for MatrixStudio/Codeforces-Python-Submissions
Counts the number of entries with a rating above 2000 and a verdict of 'OK', providing basic filtering but limited analytical value.
SQL Console for MatrixStudio/Codeforces-Python-Submissions
Counts the number of entries with a 'OK' verdict, providing a basic overview of a specific category within the dataset.