contestId int64 0 1.01k | index stringclasses 40
values | name stringlengths 2 54 | type stringclasses 2
values | rating int64 0 3.4k | tags listlengths 0 7 | title stringclasses 393
values | time-limit stringclasses 7
values | memory-limit stringclasses 6
values | problem-description stringlengths 0 2.97k | input-specification stringlengths 4 1.87k | output-specification stringlengths 4 1.12k | demo-input listlengths 0 7 | demo-output listlengths 0 7 | note stringlengths 0 5.24k | points float64 0 3.5k | test_cases listlengths 0 402 | creationTimeSeconds int64 1.37B 1.7B | relativeTimeSeconds int64 8 2.15B | programmingLanguage stringclasses 3
values | verdict stringclasses 1
value | testset stringclasses 9
values | passedTestCount int64 1 402 | timeConsumedMillis int64 15 8.06k | memoryConsumedBytes int64 0 514M | code stringlengths 11 61.4k | prompt stringlengths 297 7.35k | response stringlengths 25 61.4k | score float64 2.82 3.99 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
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 | |
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 | |
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 | |
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 | |
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 |
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 | |
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 | |
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 | |
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 | |
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 | |
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 | |
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 | |
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 | |
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 | |
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 | |
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 | |
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 |
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 | |
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 | |
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 | |
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 | |
994 | A | Fingerprints | PROGRAMMING | 800 | [
"implementation"
] | null | null | You are locked in a room with a door that has a keypad with 10 keys corresponding to digits from 0 to 9. To escape from the room, you need to enter a correct code. You also have a sequence of digits.
Some keys on the keypad have fingerprints. You believe the correct code is the longest not necessarily contiguous subse... | The first line contains two integers $n$ and $m$ ($1 \le n, m \le 10$) representing the number of digits in the sequence you have and the number of keys on the keypad that have fingerprints.
The next line contains $n$ distinct space-separated integers $x_1, x_2, \ldots, x_n$ ($0 \le x_i \le 9$) representing the sequen... | In a single line print a space-separated sequence of integers representing the code. If the resulting sequence is empty, both printing nothing and printing a single line break is acceptable. | [
"7 3\n3 5 7 1 6 2 8\n1 2 7\n",
"4 4\n3 4 1 0\n0 1 7 9\n"
] | [
"7 1 2\n",
"1 0\n"
] | In the first example, the only digits with fingerprints are $1$, $2$ and $7$. All three of them appear in the sequence you know, $7$ first, then $1$ and then $2$. Therefore the output is 7 1 2. Note that the order is important, and shall be the same as the order in the original sequence.
In the second example digits $... | 500 | [
{
"input": "7 3\n3 5 7 1 6 2 8\n1 2 7",
"output": "7 1 2"
},
{
"input": "4 4\n3 4 1 0\n0 1 7 9",
"output": "1 0"
},
{
"input": "9 4\n9 8 7 6 5 4 3 2 1\n2 4 6 8",
"output": "8 6 4 2"
},
{
"input": "10 5\n3 7 1 2 4 6 9 0 5 8\n4 3 0 7 9",
"output": "3 7 4 9 0"
},
{
"... | 1,622,476,813 | 2,147,483,647 | PyPy 3 | OK | TESTS | 31 | 155 | 0 | n,m = [int(i) for i in input().split()]
a= [int(i) for i in input().split()]
b= [int(i) for i in input().split()]
c=[]
for i in a:
if i in b:
c.append(i)
print(*c) | Title: Fingerprints
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are locked in a room with a door that has a keypad with 10 keys corresponding to digits from 0 to 9. To escape from the room, you need to enter a correct code. You also have a sequence of digits.
Some keys on the keyp... | ```python
n,m = [int(i) for i in input().split()]
a= [int(i) for i in input().split()]
b= [int(i) for i in input().split()]
c=[]
for i in a:
if i in b:
c.append(i)
print(*c)
``` | 3 | |
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,653,161,489 | 2,147,483,647 | Python 3 | OK | TESTS | 27 | 92 | 0 | import math
x,y,z=map(int,input().split(" "))
a=math.sqrt(x*z/y)
b=math.sqrt(x*y/z)
c=math.sqrt(y*z/x)
sum=(int)(4*(a+b+c))
print(sum)
| 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
x,y,z=map(int,input().split(" "))
a=math.sqrt(x*z/y)
b=math.sqrt(x*y/z)
c=math.sqrt(y*z/x)
sum=(int)(4*(a+b+c))
print(sum)
``` | 3 | |
686 | A | Free Ice Cream | PROGRAMMING | 800 | [
"constructive algorithms",
"implementation"
] | null | null | After their adventure with the magic mirror Kay and Gerda have returned home and sometimes give free ice cream to kids in the summer.
At the start of the day they have *x* ice cream packs. Since the ice cream is free, people start standing in the queue before Kay and Gerda's house even in the night. Each person in the... | The first line contains two space-separated integers *n* and *x* (1<=≤<=*n*<=≤<=1000, 0<=≤<=*x*<=≤<=109).
Each of the next *n* lines contains a character '+' or '-', and an integer *d**i*, separated by a space (1<=≤<=*d**i*<=≤<=109). Record "+ *d**i*" in *i*-th line means that a carrier with *d**i* ice cream packs occ... | Print two space-separated integers — number of ice cream packs left after all operations, and number of kids that left the house in distress. | [
"5 7\n+ 5\n- 10\n- 20\n+ 40\n- 20\n",
"5 17\n- 16\n- 2\n- 98\n+ 100\n- 98\n"
] | [
"22 1\n",
"3 2\n"
] | Consider the first sample.
1. Initially Kay and Gerda have 7 packs of ice cream. 1. Carrier brings 5 more, so now they have 12 packs. 1. A kid asks for 10 packs and receives them. There are only 2 packs remaining. 1. Another kid asks for 20 packs. Kay and Gerda do not have them, so the kid goes away distressed. 1.... | 500 | [
{
"input": "5 7\n+ 5\n- 10\n- 20\n+ 40\n- 20",
"output": "22 1"
},
{
"input": "5 17\n- 16\n- 2\n- 98\n+ 100\n- 98",
"output": "3 2"
},
{
"input": "6 1000000000\n+ 1000000000\n+ 1000000000\n+ 1000000000\n+ 1000000000\n+ 1000000000\n+ 1000000000",
"output": "7000000000 0"
},
{
... | 1,689,508,725 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 34 | 108 | 1,740,800 | n,x = map(int, input().split())
c = 0
for i in range(n):
d = input().split()
if d[0] == '+':
x+=int(d[1])
else:
if x>=int(d[1]):
x-=int(d[1])
else:
c+=1
print(x, c) | Title: Free Ice Cream
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
After their adventure with the magic mirror Kay and Gerda have returned home and sometimes give free ice cream to kids in the summer.
At the start of the day they have *x* ice cream packs. Since the ice cream is free, p... | ```python
n,x = map(int, input().split())
c = 0
for i in range(n):
d = input().split()
if d[0] == '+':
x+=int(d[1])
else:
if x>=int(d[1]):
x-=int(d[1])
else:
c+=1
print(x, c)
``` | 3 | |
466 | A | Cheap Travel | PROGRAMMING | 1,200 | [
"implementation"
] | null | null | Ann has recently started commuting by subway. We know that a one ride subway ticket costs *a* rubles. Besides, Ann found out that she can buy a special ticket for *m* rides (she can buy it several times). It costs *b* rubles. Ann did the math; she will need to use subway *n* times. Help Ann, tell her what is the minimu... | The single line contains four space-separated integers *n*, *m*, *a*, *b* (1<=≤<=*n*,<=*m*,<=*a*,<=*b*<=≤<=1000) — the number of rides Ann has planned, the number of rides covered by the *m* ride ticket, the price of a one ride ticket and the price of an *m* ride ticket. | Print a single integer — the minimum sum in rubles that Ann will need to spend. | [
"6 2 1 2\n",
"5 2 2 3\n"
] | [
"6\n",
"8\n"
] | In the first sample one of the optimal solutions is: each time buy a one ride ticket. There are other optimal solutions. For example, buy three *m* ride tickets. | 500 | [
{
"input": "6 2 1 2",
"output": "6"
},
{
"input": "5 2 2 3",
"output": "8"
},
{
"input": "10 3 5 1",
"output": "4"
},
{
"input": "1000 1 1000 1000",
"output": "1000000"
},
{
"input": "1000 3 1000 1000",
"output": "334000"
},
{
"input": "1 1 1 1",
"... | 1,693,427,568 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 19 | 46 | 0 | n, m, a, b = map(int, input().split())
if a * m < b:
print(a * n)
else:
print((n // m) * b + min((n % m) * a, b)) | Title: Cheap Travel
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Ann has recently started commuting by subway. We know that a one ride subway ticket costs *a* rubles. Besides, Ann found out that she can buy a special ticket for *m* rides (she can buy it several times). It costs *b* rubl... | ```python
n, m, a, b = map(int, input().split())
if a * m < b:
print(a * n)
else:
print((n // m) * b + min((n % m) * a, b))
``` | 3 | |
0 | none | none | none | 0 | [
"none"
] | null | null | Today on a lecture about strings Gerald learned a new definition of string equivalency. Two strings *a* and *b* of equal length are called equivalent in one of the two cases:
1. They are equal. 1. If we split string *a* into two halves of the same size *a*1 and *a*2, and string *b* into two halves of the same size ... | The first two lines of the input contain two strings given by the teacher. Each of them has the length from 1 to 200<=000 and consists of lowercase English letters. The strings have the same length. | Print "YES" (without the quotes), if these two strings are equivalent, and "NO" (without the quotes) otherwise. | [
"aaba\nabaa\n",
"aabb\nabab\n"
] | [
"YES\n",
"NO\n"
] | In the first sample you should split the first string into strings "aa" and "ba", the second one — into strings "ab" and "aa". "aa" is equivalent to "aa"; "ab" is equivalent to "ba" as "ab" = "a" + "b", "ba" = "b" + "a".
In the second sample the first string can be splitted into strings "aa" and "bb", that are equival... | 0 | [
{
"input": "aaba\nabaa",
"output": "YES"
},
{
"input": "aabb\nabab",
"output": "NO"
},
{
"input": "a\na",
"output": "YES"
},
{
"input": "a\nb",
"output": "NO"
},
{
"input": "ab\nab",
"output": "YES"
},
{
"input": "ab\nba",
"output": "YES"
},
{
... | 1,630,621,272 | 2,147,483,647 | PyPy 3 | OK | TESTS | 104 | 186 | 30,412,800 | a = input()
b = input()
def smallest(s):
if len(s)%2 == 1:
return s
s1 = smallest(s[0:len(s) // 2])
s2 = smallest(s[len(s)//2:len(s)])
if s1 < s2:
return s1+s2
else:
return s2 + s1
if smallest(a) == smallest(b):
print('YES')
else:
print('NO')
| Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Today on a lecture about strings Gerald learned a new definition of string equivalency. Two strings *a* and *b* of equal length are called equivalent in one of the two cases:
1. They are equal. 1. If we split string *a* into t... | ```python
a = input()
b = input()
def smallest(s):
if len(s)%2 == 1:
return s
s1 = smallest(s[0:len(s) // 2])
s2 = smallest(s[len(s)//2:len(s)])
if s1 < s2:
return s1+s2
else:
return s2 + s1
if smallest(a) == smallest(b):
print('YES')
else:
print('NO')
``` | 3 | |
339 | A | Helpful Maths | PROGRAMMING | 800 | [
"greedy",
"implementation",
"sortings",
"strings"
] | null | null | Xenia the beginner mathematician is a third year student at elementary school. She is now learning the addition operation.
The teacher has written down the sum of multiple numbers. Pupils should calculate the sum. To make the calculation easier, the sum only contains numbers 1, 2 and 3. Still, that isn't enough for Xe... | The first line contains a non-empty string *s* — the sum Xenia needs to count. String *s* contains no spaces. It only contains digits and characters "+". Besides, string *s* is a correct sum of numbers 1, 2 and 3. String *s* is at most 100 characters long. | Print the new sum that Xenia can count. | [
"3+2+1\n",
"1+1+3+1+3\n",
"2\n"
] | [
"1+2+3\n",
"1+1+1+3+3\n",
"2\n"
] | none | 500 | [
{
"input": "3+2+1",
"output": "1+2+3"
},
{
"input": "1+1+3+1+3",
"output": "1+1+1+3+3"
},
{
"input": "2",
"output": "2"
},
{
"input": "2+2+1+1+3",
"output": "1+1+2+2+3"
},
{
"input": "2+1+2+2+2+3+1+3+1+2",
"output": "1+1+1+2+2+2+2+2+3+3"
},
{
"input": ... | 1,697,219,839 | 2,147,483,647 | Python 3 | OK | TESTS | 21 | 92 | 0 | math = input()
b = []
a = math.split("+")
for i in range(0, len(a)):
if int(a[i]) == 1:
b.append(1)
elif int(a[i]) == 2:
b.append(2)
else:
b.append(3)
b.sort()
d = ""
for i in range(len(b)):
if i != len(b)-1:
d += f"{b[i]}" + "+"
else:
d += f"{... | Title: Helpful Maths
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Xenia the beginner mathematician is a third year student at elementary school. She is now learning the addition operation.
The teacher has written down the sum of multiple numbers. Pupils should calculate the sum. To mak... | ```python
math = input()
b = []
a = math.split("+")
for i in range(0, len(a)):
if int(a[i]) == 1:
b.append(1)
elif int(a[i]) == 2:
b.append(2)
else:
b.append(3)
b.sort()
d = ""
for i in range(len(b)):
if i != len(b)-1:
d += f"{b[i]}" + "+"
else:
... | 3 | |
669 | A | Little Artem and Presents | PROGRAMMING | 800 | [
"math"
] | null | null | Little Artem got *n* stones on his birthday and now wants to give some of them to Masha. He knows that Masha cares more about the fact of receiving the present, rather than the value of that present, so he wants to give her stones as many times as possible. However, Masha remembers the last present she received, so Art... | The only line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=109) — number of stones Artem received on his birthday. | Print the maximum possible number of times Artem can give presents to Masha. | [
"1\n",
"2\n",
"3\n",
"4\n"
] | [
"1\n",
"1\n",
"2\n",
"3\n"
] | In the first sample, Artem can only give 1 stone to Masha.
In the second sample, Atrem can give Masha 1 or 2 stones, though he can't give her 1 stone two times.
In the third sample, Atrem can first give Masha 2 stones, a then 1 more stone.
In the fourth sample, Atrem can first give Masha 1 stone, then 2 stones, and ... | 500 | [
{
"input": "1",
"output": "1"
},
{
"input": "2",
"output": "1"
},
{
"input": "3",
"output": "2"
},
{
"input": "4",
"output": "3"
},
{
"input": "100",
"output": "67"
},
{
"input": "101",
"output": "67"
},
{
"input": "102",
"output": "68"... | 1,611,752,073 | 2,147,483,647 | Python 3 | OK | TESTS | 26 | 62 | 0 | x=int(input())
y=int(x/3)
if x%3==0:
print(y*2)
else:
print(y*2+1) | Title: Little Artem and Presents
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Artem got *n* stones on his birthday and now wants to give some of them to Masha. He knows that Masha cares more about the fact of receiving the present, rather than the value of that present, so he wan... | ```python
x=int(input())
y=int(x/3)
if x%3==0:
print(y*2)
else:
print(y*2+1)
``` | 3 | |
476 | A | Dreamoon and Stairs | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | null | null | Dreamoon wants to climb up a stair of *n* steps. He can climb 1 or 2 steps at each move. Dreamoon wants the number of moves to be a multiple of an integer *m*.
What is the minimal number of moves making him climb to the top of the stairs that satisfies his condition? | The single line contains two space separated integers *n*, *m* (0<=<<=*n*<=≤<=10000,<=1<=<<=*m*<=≤<=10). | Print a single integer — the minimal number of moves being a multiple of *m*. If there is no way he can climb satisfying condition print <=-<=1 instead. | [
"10 2\n",
"3 5\n"
] | [
"6\n",
"-1\n"
] | For the first sample, Dreamoon could climb in 6 moves with following sequence of steps: {2, 2, 2, 2, 1, 1}.
For the second sample, there are only three valid sequence of steps {2, 1}, {1, 2}, {1, 1, 1} with 2, 2, and 3 steps respectively. All these numbers are not multiples of 5. | 500 | [
{
"input": "10 2",
"output": "6"
},
{
"input": "3 5",
"output": "-1"
},
{
"input": "29 7",
"output": "21"
},
{
"input": "2 2",
"output": "2"
},
{
"input": "1 2",
"output": "-1"
},
{
"input": "10000 2",
"output": "5000"
},
{
"input": "10000 ... | 1,673,389,268 | 2,147,483,647 | Python 3 | OK | TESTS | 35 | 46 | 0 | n, m = map(int, input().split())
steps = -(-n//2)
if n < m:
print(-1)
else:
if steps % m == 0:
print(steps)
else:
next = steps + (m-(steps%m))
print(next) | Title: Dreamoon and Stairs
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Dreamoon wants to climb up a stair of *n* steps. He can climb 1 or 2 steps at each move. Dreamoon wants the number of moves to be a multiple of an integer *m*.
What is the minimal number of moves making him climb ... | ```python
n, m = map(int, input().split())
steps = -(-n//2)
if n < m:
print(-1)
else:
if steps % m == 0:
print(steps)
else:
next = steps + (m-(steps%m))
print(next)
``` | 3 | |
820 | A | Mister B and Book Reading | PROGRAMMING | 900 | [
"implementation"
] | null | null | Mister B once received a gift: it was a book about aliens, which he started read immediately. This book had *c* pages.
At first day Mister B read *v*0 pages, but after that he started to speed up. Every day, starting from the second, he read *a* pages more than on the previous day (at first day he read *v*0 pages, at ... | First and only line contains five space-separated integers: *c*, *v*0, *v*1, *a* and *l* (1<=≤<=*c*<=≤<=1000, 0<=≤<=*l*<=<<=*v*0<=≤<=*v*1<=≤<=1000, 0<=≤<=*a*<=≤<=1000) — the length of the book in pages, the initial reading speed, the maximum reading speed, the acceleration in reading speed and the number of pages fo... | Print one integer — the number of days Mister B needed to finish the book. | [
"5 5 10 5 4\n",
"12 4 12 4 1\n",
"15 1 100 0 0\n"
] | [
"1\n",
"3\n",
"15\n"
] | In the first sample test the book contains 5 pages, so Mister B read it right at the first day.
In the second sample test at first day Mister B read pages number 1 - 4, at second day — 4 - 11, at third day — 11 - 12 and finished the book.
In third sample test every day Mister B read 1 page of the book, so he finished... | 500 | [
{
"input": "5 5 10 5 4",
"output": "1"
},
{
"input": "12 4 12 4 1",
"output": "3"
},
{
"input": "15 1 100 0 0",
"output": "15"
},
{
"input": "1 1 1 0 0",
"output": "1"
},
{
"input": "1000 999 1000 1000 998",
"output": "2"
},
{
"input": "1000 2 2 5 1",
... | 1,498,574,676 | 576 | Python 3 | OK | TESTS | 110 | 93 | 5,529,600 | c, v0, v1, a, l = map(int, input().split())
v = v0
p = 0
ans = 0
while p < c:
if p != 0:
p -= l
p += v
v = min(v + a, v1)
ans += 1
print(ans)
| 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, v0, v1, a, l = map(int, input().split())
v = v0
p = 0
ans = 0
while p < c:
if p != 0:
p -= l
p += v
v = min(v + a, v1)
ans += 1
print(ans)
``` | 3 | |
258 | A | Little Elephant and Bits | PROGRAMMING | 1,100 | [
"greedy",
"math"
] | null | null | The Little Elephant has an integer *a*, written in the binary notation. He wants to write this number on a piece of paper.
To make sure that the number *a* fits on the piece of paper, the Little Elephant ought to delete exactly one any digit from number *a* in the binary record. At that a new number appears. It consis... | The single line contains integer *a*, written in the binary notation without leading zeroes. This number contains more than 1 and at most 105 digits. | In the single line print the number that is written without leading zeroes in the binary notation — the answer to the problem. | [
"101\n",
"110010\n"
] | [
"11\n",
"11010\n"
] | In the first sample the best strategy is to delete the second digit. That results in number 11<sub class="lower-index">2</sub> = 3<sub class="lower-index">10</sub>.
In the second sample the best strategy is to delete the third or fourth digits — that results in number 11010<sub class="lower-index">2</sub> = 26<sub cla... | 500 | [
{
"input": "101",
"output": "11"
},
{
"input": "110010",
"output": "11010"
},
{
"input": "10000",
"output": "1000"
},
{
"input": "1111111110",
"output": "111111111"
},
{
"input": "10100101011110101",
"output": "1100101011110101"
},
{
"input": "11101001... | 1,657,875,237 | 2,147,483,647 | Python 3 | OK | TESTS | 37 | 92 | 1,433,600 | s=input()
l=list(s)
if '0' in s:
k=l.index('0')
t=l.pop(k)
print(''.join(map(str,l)))
else:
print(s[1:]) | Title: Little Elephant and Bits
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Little Elephant has an integer *a*, written in the binary notation. He wants to write this number on a piece of paper.
To make sure that the number *a* fits on the piece of paper, the Little Elephant ought... | ```python
s=input()
l=list(s)
if '0' in s:
k=l.index('0')
t=l.pop(k)
print(''.join(map(str,l)))
else:
print(s[1:])
``` | 3 | |
0 | none | none | none | 0 | [
"none"
] | null | null | The main road in Bytecity is a straight line from south to north. Conveniently, there are coordinates measured in meters from the southernmost building in north direction.
At some points on the road there are *n* friends, and *i*-th of them is standing at the point *x**i* meters and can move with any speed no greater ... | The first line contains single integer *n* (2<=≤<=*n*<=≤<=60<=000) — the number of friends.
The second line contains *n* integers *x*1,<=*x*2,<=...,<=*x**n* (1<=≤<=*x**i*<=≤<=109) — the current coordinates of the friends, in meters.
The third line contains *n* integers *v*1,<=*v*2,<=...,<=*v**n* (1<=≤<=*v**i*<=≤<=109... | Print the minimum time (in seconds) needed for all the *n* friends to meet at some point on the road.
Your answer will be considered correct, if its absolute or relative error isn't greater than 10<=-<=6. Formally, let your answer be *a*, while jury's answer be *b*. Your answer will be considered correct if holds. | [
"3\n7 1 3\n1 2 1\n",
"4\n5 10 3 2\n2 3 2 4\n"
] | [
"2.000000000000\n",
"1.400000000000\n"
] | In the first sample, all friends can gather at the point 5 within 2 seconds. In order to achieve this, the first friend should go south all the time at his maximum speed, while the second and the third friends should go north at their maximum speeds. | 0 | [
{
"input": "3\n7 1 3\n1 2 1",
"output": "2.000000000000"
},
{
"input": "4\n5 10 3 2\n2 3 2 4",
"output": "1.400000000000"
},
{
"input": "3\n1 1000000000 2\n1 2 1000000000",
"output": "333333332.999999999971"
},
{
"input": "2\n4 5\n10 8",
"output": "0.055555555556"
},
... | 1,549,188,122 | 2,147,483,647 | Python 3 | OK | TESTS | 46 | 218 | 11,366,400 | def time(d1, d2):
return (d2[0]-d1[0])/(d2[1]+d1[1]) if d2[0] > d1[0] else 0
n = int(input())
coords = map(float, input().split())
speeds = map(float, input().split())
data = sorted(zip(coords, speeds)) # Отсортировали по координатам
k1 = [data[0]]
s1 = data[0][1]
k2 = [data[-1]]
s2 = data[-1][1]
for... | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The main road in Bytecity is a straight line from south to north. Conveniently, there are coordinates measured in meters from the southernmost building in north direction.
At some points on the road there are *n* friends, and *i*... | ```python
def time(d1, d2):
return (d2[0]-d1[0])/(d2[1]+d1[1]) if d2[0] > d1[0] else 0
n = int(input())
coords = map(float, input().split())
speeds = map(float, input().split())
data = sorted(zip(coords, speeds)) # Отсортировали по координатам
k1 = [data[0]]
s1 = data[0][1]
k2 = [data[-1]]
s2 = data[-... | 3 | |
0 | none | none | none | 0 | [
"none"
] | null | null | Bike is interested in permutations. A permutation of length *n* is an integer sequence such that each integer from 0 to (*n*<=-<=1) appears exactly once in it. For example, [0,<=2,<=1] is a permutation of length 3 while both [0,<=2,<=2] and [1,<=2,<=3] is not.
A permutation triple of permutations of length *n* (*a*,<=... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105). | If no Lucky Permutation Triple of length *n* exists print -1.
Otherwise, you need to print three lines. Each line contains *n* space-seperated integers. The first line must contain permutation *a*, the second line — permutation *b*, the third — permutation *c*.
If there are multiple solutions, print any of them. | [
"5\n",
"2\n"
] | [
"1 4 3 2 0\n1 0 2 4 3\n2 4 0 1 3\n",
"-1\n"
] | In Sample 1, the permutation triple ([1, 4, 3, 2, 0], [1, 0, 2, 4, 3], [2, 4, 0, 1, 3]) is Lucky Permutation Triple, as following holds:
- <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/a6bf1b9b57809dbec5021f65f89616f259587c07.png" style="max-width: 100.0%;max-height: 100.0%;"/>; - <img... | 0 | [
{
"input": "5",
"output": "1 4 3 2 0\n1 0 2 4 3\n2 4 0 1 3"
},
{
"input": "2",
"output": "-1"
},
{
"input": "8",
"output": "-1"
},
{
"input": "9",
"output": "0 1 2 3 4 5 6 7 8 \n0 1 2 3 4 5 6 7 8 \n0 2 4 6 8 1 3 5 7 "
},
{
"input": "2",
"output": "-1"
},
{... | 1,667,213,712 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 54 | 218 | 18,534,400 | '''
# Submitted By M7moud Ala3rj
Don't Copy This Code, CopyRight . [email protected] © 2022-2023 :)
'''
# Problem Name = "Lucky Permutation Triple"
# Class: C
import sys
#sys.setrecursionlimit(2147483647)
input = sys.stdin.readline
def printf(*args, end='\n', sep=' ') -> None:
sys.stdout.write(sep.joi... | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bike is interested in permutations. A permutation of length *n* is an integer sequence such that each integer from 0 to (*n*<=-<=1) appears exactly once in it. For example, [0,<=2,<=1] is a permutation of length 3 while both [0,<=... | ```python
'''
# Submitted By M7moud Ala3rj
Don't Copy This Code, CopyRight . [email protected] © 2022-2023 :)
'''
# Problem Name = "Lucky Permutation Triple"
# Class: C
import sys
#sys.setrecursionlimit(2147483647)
input = sys.stdin.readline
def printf(*args, end='\n', sep=' ') -> None:
sys.stdout.wri... | 3 | |
884 | B | Japanese Crosswords Strike Back | PROGRAMMING | 1,100 | [
"implementation"
] | null | null | A one-dimensional Japanese crossword can be represented as a binary string of length *x*. An encoding of this crossword is an array *a* of size *n*, where *n* is the number of segments formed completely of 1's, and *a**i* is the length of *i*-th segment. No two segments touch or intersect.
For example:
- If *x*<==<... | The first line contains two integer numbers *n* and *x* (1<=≤<=*n*<=≤<=100000, 1<=≤<=*x*<=≤<=109) — the number of elements in the encoding and the length of the crossword Mishka picked.
The second line contains *n* integer numbers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=10000) — the encoding. | Print YES if there exists exaclty one crossword with chosen length and encoding. Otherwise, print NO. | [
"2 4\n1 3\n",
"3 10\n3 3 2\n",
"2 10\n1 3\n"
] | [
"NO\n",
"YES\n",
"NO\n"
] | none | 0 | [
{
"input": "2 4\n1 3",
"output": "NO"
},
{
"input": "3 10\n3 3 2",
"output": "YES"
},
{
"input": "2 10\n1 3",
"output": "NO"
},
{
"input": "1 1\n1",
"output": "YES"
},
{
"input": "1 10\n10",
"output": "YES"
},
{
"input": "1 10000\n10000",
"output":... | 1,546,100,843 | 2,147,483,647 | Python 3 | OK | TESTS | 66 | 140 | 5,939,200 | n, x = map(int, input().split())
s = 0
for c in input().split():
s += int(c)
print('YES' if x-s-(n-1)==0 else 'NO') | Title: Japanese Crosswords Strike Back
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A one-dimensional Japanese crossword can be represented as a binary string of length *x*. An encoding of this crossword is an array *a* of size *n*, where *n* is the number of segments formed completely ... | ```python
n, x = map(int, input().split())
s = 0
for c in input().split():
s += int(c)
print('YES' if x-s-(n-1)==0 else 'NO')
``` | 3 | |
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,623,526,758 | 2,147,483,647 | Python 3 | OK | TESTS | 51 | 1,840 | 0 |
def solution1(n: int):
count = 0
if n < 10:
return 0
while True:
_s = sum(map(int, str(n)))
count += 1
if _s <= 9:
return count
n = _s
if __name__ == "__main__":
n = int(input())
print(solution1(n))
| 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
def solution1(n: int):
count = 0
if n < 10:
return 0
while True:
_s = sum(map(int, str(n)))
count += 1
if _s <= 9:
return count
n = _s
if __name__ == "__main__":
n = int(input())
print(solution1(n))
``` | 3.54 |
596 | A | Wilbur and Swimming Pool | PROGRAMMING | 1,100 | [
"geometry",
"implementation"
] | null | null | After making bad dives into swimming pools, Wilbur wants to build a swimming pool in the shape of a rectangle in his backyard. He has set up coordinate axes, and he wants the sides of the rectangle to be parallel to them. Of course, the area of the rectangle must be positive. Wilbur had all four vertices of the planned... | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=4) — the number of vertices that were not erased by Wilbur's friend.
Each of the following *n* lines contains two integers *x**i* and *y**i* (<=-<=1000<=≤<=*x**i*,<=*y**i*<=≤<=1000) —the coordinates of the *i*-th vertex that remains. Vertices are... | Print the area of the initial rectangle if it could be uniquely determined by the points remaining. Otherwise, print <=-<=1. | [
"2\n0 0\n1 1\n",
"1\n1 1\n"
] | [
"1\n",
"-1\n"
] | In the first sample, two opposite corners of the initial rectangle are given, and that gives enough information to say that the rectangle is actually a unit square.
In the second sample there is only one vertex left and this is definitely not enough to uniquely define the area. | 500 | [
{
"input": "2\n0 0\n1 1",
"output": "1"
},
{
"input": "1\n1 1",
"output": "-1"
},
{
"input": "1\n-188 17",
"output": "-1"
},
{
"input": "1\n71 -740",
"output": "-1"
},
{
"input": "4\n-56 -858\n-56 -174\n778 -858\n778 -174",
"output": "570456"
},
{
"inp... | 1,447,606,163 | 863 | Python 3 | OK | TESTS | 121 | 108 | 1,331,200 | import math
from decimal import *
import sys
from fractions import Fraction
n=int(input())
x=[]
y=[]
for i in range(0,n):
inp=list(map(int,input().split()))
x.append(inp[0])
y.append(inp[1])
if n==1:
print(-1)
if n==2:
if y[0] == y[1] or x[0] == x[1]:
print(-1)
else... | Title: Wilbur and Swimming Pool
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
After making bad dives into swimming pools, Wilbur wants to build a swimming pool in the shape of a rectangle in his backyard. He has set up coordinate axes, and he wants the sides of the rectangle to be parall... | ```python
import math
from decimal import *
import sys
from fractions import Fraction
n=int(input())
x=[]
y=[]
for i in range(0,n):
inp=list(map(int,input().split()))
x.append(inp[0])
y.append(inp[1])
if n==1:
print(-1)
if n==2:
if y[0] == y[1] or x[0] == x[1]:
print(-1)... | 3 | |
749 | A | Bachgold Problem | PROGRAMMING | 800 | [
"greedy",
"implementation",
"math",
"number theory"
] | null | null | Bachgold problem is very easy to formulate. Given a positive integer *n* represent it as a sum of maximum possible number of prime numbers. One can prove that such representation exists for any integer greater than 1.
Recall that integer *k* is called prime if it is greater than 1 and has exactly two positive integer ... | The only line of the input contains a single integer *n* (2<=≤<=*n*<=≤<=100<=000). | The first line of the output contains a single integer *k* — maximum possible number of primes in representation.
The second line should contain *k* primes with their sum equal to *n*. You can print them in any order. If there are several optimal solution, print any of them. | [
"5\n",
"6\n"
] | [
"2\n2 3\n",
"3\n2 2 2\n"
] | none | 500 | [
{
"input": "5",
"output": "2\n2 3"
},
{
"input": "6",
"output": "3\n2 2 2"
},
{
"input": "2",
"output": "1\n2"
},
{
"input": "3",
"output": "1\n3"
},
{
"input": "99999",
"output": "49999\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 ... | 1,662,534,147 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 41 | 62 | 0 | a = int(input())
if a % 2 == 0:
b = int(a / 2)
print(b)
print("2 " * b, end = "")
else:
a = a - 1
b = int(a / 2)
print(b)
c = "2 " * (b - 1)
d = "3"
print( c + d) | Title: Bachgold Problem
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bachgold problem is very easy to formulate. Given a positive integer *n* represent it as a sum of maximum possible number of prime numbers. One can prove that such representation exists for any integer greater than 1.
... | ```python
a = int(input())
if a % 2 == 0:
b = int(a / 2)
print(b)
print("2 " * b, end = "")
else:
a = a - 1
b = int(a / 2)
print(b)
c = "2 " * (b - 1)
d = "3"
print( c + d)
``` | 3 | |
59 | A | Word | PROGRAMMING | 800 | [
"implementation",
"strings"
] | A. Word | 2 | 256 | Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At th... | The first line contains a word *s* — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100. | Print the corrected word *s*. If the given word *s* has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one. | [
"HoUse\n",
"ViP\n",
"maTRIx\n"
] | [
"house\n",
"VIP\n",
"matrix\n"
] | none | 500 | [
{
"input": "HoUse",
"output": "house"
},
{
"input": "ViP",
"output": "VIP"
},
{
"input": "maTRIx",
"output": "matrix"
},
{
"input": "BNHWpnpawg",
"output": "bnhwpnpawg"
},
{
"input": "VTYGP",
"output": "VTYGP"
},
{
"input": "CHNenu",
"output": "chn... | 1,689,099,144 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 92 | 0 | Word = input()
uppers = 0
lowers = 0
for char in Word:
if char.isupper():
uppers+=1
else:
lowers+=1
if uppers > lowers:
print(Word.upper())
else:
print(Word.lower()) | Title: Word
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it ei... | ```python
Word = input()
uppers = 0
lowers = 0
for char in Word:
if char.isupper():
uppers+=1
else:
lowers+=1
if uppers > lowers:
print(Word.upper())
else:
print(Word.lower())
``` | 3.977 |
41 | A | Translation | PROGRAMMING | 800 | [
"implementation",
"strings"
] | A. Translation | 2 | 256 | The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pronounced) reversely. For example, a Berlandish word code corresponds to a Birlandish word edoc.... | The first line contains word *s*, the second line contains word *t*. The words consist of lowercase Latin letters. The input data do not consist unnecessary spaces. The words are not empty and their lengths do not exceed 100 symbols. | If the word *t* is a word *s*, written reversely, print YES, otherwise print NO. | [
"code\nedoc\n",
"abb\naba\n",
"code\ncode\n"
] | [
"YES\n",
"NO\n",
"NO\n"
] | none | 500 | [
{
"input": "code\nedoc",
"output": "YES"
},
{
"input": "abb\naba",
"output": "NO"
},
{
"input": "code\ncode",
"output": "NO"
},
{
"input": "abacaba\nabacaba",
"output": "YES"
},
{
"input": "q\nq",
"output": "YES"
},
{
"input": "asrgdfngfnmfgnhweratgjkk... | 1,673,329,569 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 62 | 0 | n=input()
n1=input()
if(n1==n[::-1]):
print('YES')
else:
print('NO') | Title: Translation
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pron... | ```python
n=input()
n1=input()
if(n1==n[::-1]):
print('YES')
else:
print('NO')
``` | 3.9845 |
59 | A | Word | PROGRAMMING | 800 | [
"implementation",
"strings"
] | A. Word | 2 | 256 | Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At th... | The first line contains a word *s* — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100. | Print the corrected word *s*. If the given word *s* has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one. | [
"HoUse\n",
"ViP\n",
"maTRIx\n"
] | [
"house\n",
"VIP\n",
"matrix\n"
] | none | 500 | [
{
"input": "HoUse",
"output": "house"
},
{
"input": "ViP",
"output": "VIP"
},
{
"input": "maTRIx",
"output": "matrix"
},
{
"input": "BNHWpnpawg",
"output": "bnhwpnpawg"
},
{
"input": "VTYGP",
"output": "VTYGP"
},
{
"input": "CHNenu",
"output": "chn... | 1,498,769,242 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 124 | 5,632,000 | stroke = input()
upper = 0
lower = 0
for el in stroke:
if el.isupper():
upper += 1
else:
lower += 1
if upper > lower:
print(stroke.upper())
else:
print(stroke.lower()) | Title: Word
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it ei... | ```python
stroke = input()
upper = 0
lower = 0
for el in stroke:
if el.isupper():
upper += 1
else:
lower += 1
if upper > lower:
print(stroke.upper())
else:
print(stroke.lower())
``` | 3.95851 |
133 | A | HQ9+ | PROGRAMMING | 900 | [
"implementation"
] | null | null | HQ9+ is a joke programming language which has only four one-character instructions:
- "H" prints "Hello, World!",- "Q" prints the source code of the program itself,- "9" prints the lyrics of "99 Bottles of Beer" song, - "+" increments the value stored in the internal accumulator.
Instructions "H" and "Q" are case-s... | The input will consist of a single line *p* which will give a program in HQ9+. String *p* will contain between 1 and 100 characters, inclusive. ASCII-code of each character of *p* will be between 33 (exclamation mark) and 126 (tilde), inclusive. | Output "YES", if executing the program will produce any output, and "NO" otherwise. | [
"Hi!\n",
"Codeforces\n"
] | [
"YES\n",
"NO\n"
] | In the first case the program contains only one instruction — "H", which prints "Hello, World!".
In the second case none of the program characters are language instructions. | 500 | [
{
"input": "Hi!",
"output": "YES"
},
{
"input": "Codeforces",
"output": "NO"
},
{
"input": "a+b=c",
"output": "NO"
},
{
"input": "hq-lowercase",
"output": "NO"
},
{
"input": "Q",
"output": "YES"
},
{
"input": "9",
"output": "YES"
},
{
"inpu... | 1,692,333,754 | 2,147,483,647 | Python 3 | OK | TESTS | 85 | 92 | 0 | code = input()
code_list = []
accept = False
for x in code:
code_list.append(x)
for x in range(len(code_list)):
if code_list[x] == "H" or code_list[x] == "Q" or code_list[x] == "9":
accept = True
break
else:
accept = False
if accept == True:
print("YES")
else:
... | Title: HQ9+
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
HQ9+ is a joke programming language which has only four one-character instructions:
- "H" prints "Hello, World!",- "Q" prints the source code of the program itself,- "9" prints the lyrics of "99 Bottles of Beer" song, - "+" in... | ```python
code = input()
code_list = []
accept = False
for x in code:
code_list.append(x)
for x in range(len(code_list)):
if code_list[x] == "H" or code_list[x] == "Q" or code_list[x] == "9":
accept = True
break
else:
accept = False
if accept == True:
print("YES")
... | 3 | |
839 | A | Arya and Bran | PROGRAMMING | 900 | [
"implementation"
] | null | null | Bran and his older sister Arya are from the same house. Bran like candies so much, so Arya is going to give him some Candies.
At first, Arya and Bran have 0 Candies. There are *n* days, at the *i*-th day, Arya finds *a**i* candies in a box, that is given by the Many-Faced God. Every day she can give Bran at most 8 of ... | The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=100, 1<=≤<=*k*<=≤<=10000).
The second line contains *n* integers *a*1,<=*a*2,<=*a*3,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100). | If it is impossible for Arya to give Bran *k* candies within *n* days, print -1.
Otherwise print a single integer — the minimum number of days Arya needs to give Bran *k* candies before the end of the *n*-th day. | [
"2 3\n1 2\n",
"3 17\n10 10 10\n",
"1 9\n10\n"
] | [
"2",
"3",
"-1"
] | In the first sample, Arya can give Bran 3 candies in 2 days.
In the second sample, Arya can give Bran 17 candies in 3 days, because she can give him at most 8 candies per day.
In the third sample, Arya can't give Bran 9 candies, because she can give him at most 8 candies per day and she must give him the candies with... | 500 | [
{
"input": "2 3\n1 2",
"output": "2"
},
{
"input": "3 17\n10 10 10",
"output": "3"
},
{
"input": "1 9\n10",
"output": "-1"
},
{
"input": "10 70\n6 5 2 3 3 2 1 4 3 2",
"output": "-1"
},
{
"input": "20 140\n40 4 81 40 10 54 34 50 84 60 16 1 90 78 38 93 99 60 81 99",... | 1,598,659,153 | 2,147,483,647 | Python 3 | OK | TESTS | 60 | 108 | 0 |
n, k = map(int, input().split())
a = list(map(int,input().split()))
i = 0
s = 0
while k > 0 and i<n:
s+=a[i]
today = min(s, 8)
s-=today
k-=today
i+=1
if k<=0:
print(i)
else:
print(-1)
| Title: Arya and Bran
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bran and his older sister Arya are from the same house. Bran like candies so much, so Arya is going to give him some Candies.
At first, Arya and Bran have 0 Candies. There are *n* days, at the *i*-th day, Arya finds *a**... | ```python
n, k = map(int, input().split())
a = list(map(int,input().split()))
i = 0
s = 0
while k > 0 and i<n:
s+=a[i]
today = min(s, 8)
s-=today
k-=today
i+=1
if k<=0:
print(i)
else:
print(-1)
``` | 3 | |
332 | B | Maximum Absurdity | PROGRAMMING | 1,500 | [
"data structures",
"dp",
"implementation"
] | null | null | Reforms continue entering Berland. For example, during yesterday sitting the Berland Parliament approved as much as *n* laws (each law has been assigned a unique number from 1 to *n*). Today all these laws were put on the table of the President of Berland, G.W. Boosch, to be signed.
This time mr. Boosch plans to sign ... | The first line contains two integers *n* and *k* (2<=≤<=*n*<=≤<=2·105, 0<=<<=2*k*<=≤<=*n*) — the number of laws accepted by the parliament and the length of one segment in the law list, correspondingly. The next line contains *n* integers *x*1,<=*x*2,<=...,<=*x**n* — the absurdity of each law (1<=≤<=*x**i*<=≤<=109). | Print two integers *a*, *b* — the beginning of segments that mr. Boosch should choose. That means that the president signs laws with numbers from segments [*a*; *a*<=+<=*k*<=-<=1] and [*b*; *b*<=+<=*k*<=-<=1]. If there are multiple solutions, print the one with the minimum number *a*. If there still are multiple soluti... | [
"5 2\n3 6 1 1 6\n",
"6 2\n1 1 1 1 1 1\n"
] | [
"1 4\n",
"1 3\n"
] | In the first sample mr. Boosch signs laws with numbers from segments [1;2] and [4;5]. The total absurdity of the signed laws equals 3 + 6 + 1 + 6 = 16.
In the second sample mr. Boosch signs laws with numbers from segments [1;2] and [3;4]. The total absurdity of the signed laws equals 1 + 1 + 1 + 1 = 4. | 1,000 | [
{
"input": "5 2\n3 6 1 1 6",
"output": "1 4"
},
{
"input": "6 2\n1 1 1 1 1 1",
"output": "1 3"
},
{
"input": "6 2\n1 4 1 2 5 6",
"output": "1 5"
},
{
"input": "4 1\n1 2 2 2",
"output": "2 3"
},
{
"input": "6 3\n15 20 1 15 43 6",
"output": "1 4"
},
{
"i... | 1,601,823,178 | 2,147,483,647 | PyPy 3 | OK | TESTS | 47 | 872 | 33,894,400 | n,k = map(int,input().split())
xi = list(map(int,input().split()))
ar = [0] * n
for i in range(k):
ar[0] += xi[i]
for i in range(k,n):
ar[i-k+1] = ar[i-k] + xi[i] - xi[i-k]
ar2 = [[0]*2 for i in range(n)]
for i in range(n):
ar2[i][0] = ar2[i-1][0]
ar2[i][1] = ar2[i-1][1]
if ar2[i][0... | Title: Maximum Absurdity
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Reforms continue entering Berland. For example, during yesterday sitting the Berland Parliament approved as much as *n* laws (each law has been assigned a unique number from 1 to *n*). Today all these laws were put on... | ```python
n,k = map(int,input().split())
xi = list(map(int,input().split()))
ar = [0] * n
for i in range(k):
ar[0] += xi[i]
for i in range(k,n):
ar[i-k+1] = ar[i-k] + xi[i] - xi[i-k]
ar2 = [[0]*2 for i in range(n)]
for i in range(n):
ar2[i][0] = ar2[i-1][0]
ar2[i][1] = ar2[i-1][1]
i... | 3 | |
883 | M | Quadcopter Competition | PROGRAMMING | 1,100 | [
"greedy",
"math"
] | null | null | Polycarp takes part in a quadcopter competition. According to the rules a flying robot should:
- start the race from some point of a field, - go around the flag, - close cycle returning back to the starting point.
Polycarp knows the coordinates of the starting point (*x*1,<=*y*1) and the coordinates of the point w... | The first line contains two integer numbers *x*1 and *y*1 (<=-<=100<=≤<=*x*1,<=*y*1<=≤<=100) — coordinates of the quadcopter starting (and finishing) point.
The second line contains two integer numbers *x*2 and *y*2 (<=-<=100<=≤<=*x*2,<=*y*2<=≤<=100) — coordinates of the flag.
It is guaranteed that the quadcopter sta... | Print the length of minimal path of the quadcopter to surround the flag and return back. | [
"1 5\n5 2\n",
"0 1\n0 0\n"
] | [
"18\n",
"8\n"
] | none | 0 | [
{
"input": "1 5\n5 2",
"output": "18"
},
{
"input": "0 1\n0 0",
"output": "8"
},
{
"input": "-100 -100\n100 100",
"output": "804"
},
{
"input": "-100 -100\n-100 100",
"output": "406"
},
{
"input": "-100 -100\n100 -100",
"output": "406"
},
{
"input": "1... | 1,687,340,312 | 2,147,483,647 | Python 3 | OK | TESTS | 100 | 46 | 0 | c_x,c_y = map(int,input().split())
f_x,f_y = map(int,input().split())
if c_x == f_x:
print(2*(abs(c_y-f_y)+1)+4)
elif c_y == f_y:
print(2*(abs(c_x-f_x)+1)+4)
else:
p_x = f_x+1 if c_x < f_x else f_x-1
p_y = f_y+1 if c_y < f_y else f_y-1
print(2*(abs(p_x-c_x)+abs(p_y-c_y))) | Title: Quadcopter Competition
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp takes part in a quadcopter competition. According to the rules a flying robot should:
- start the race from some point of a field, - go around the flag, - close cycle returning back to the starting p... | ```python
c_x,c_y = map(int,input().split())
f_x,f_y = map(int,input().split())
if c_x == f_x:
print(2*(abs(c_y-f_y)+1)+4)
elif c_y == f_y:
print(2*(abs(c_x-f_x)+1)+4)
else:
p_x = f_x+1 if c_x < f_x else f_x-1
p_y = f_y+1 if c_y < f_y else f_y-1
print(2*(abs(p_x-c_x)+abs(p_y-c_y)))
``` | 3 | |
509 | A | Maximum in Table | PROGRAMMING | 800 | [
"brute force",
"implementation"
] | null | null | An *n*<=×<=*n* table *a* is defined as follows:
- The first row and the first column contain ones, that is: *a**i*,<=1<==<=*a*1,<=*i*<==<=1 for all *i*<==<=1,<=2,<=...,<=*n*. - Each of the remaining numbers in the table is equal to the sum of the number above it and the number to the left of it. In other words, the ... | The only line of input contains a positive integer *n* (1<=≤<=*n*<=≤<=10) — the number of rows and columns of the table. | Print a single line containing a positive integer *m* — the maximum value in the table. | [
"1\n",
"5\n"
] | [
"1",
"70"
] | In the second test the rows of the table look as follows: | 0 | [
{
"input": "1",
"output": "1"
},
{
"input": "5",
"output": "70"
},
{
"input": "2",
"output": "2"
},
{
"input": "3",
"output": "6"
},
{
"input": "4",
"output": "20"
},
{
"input": "6",
"output": "252"
},
{
"input": "7",
"output": "924"
... | 1,644,793,524 | 2,147,483,647 | Python 3 | OK | TESTS | 10 | 46 | 0 | n = int(input())
arr = []
for i in range(0,n):
mas = []
for j in range(0,n):
mas.append(1)
arr.append(mas)
for i in range(1,n):
mas = []
for j in range(1,n):
a = arr[i-1][j]
b = arr[i][j-1]
arr[i][j] = (a + b)
print (arr[n-1][n-1]) | Title: Maximum in Table
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
An *n*<=×<=*n* table *a* is defined as follows:
- The first row and the first column contain ones, that is: *a**i*,<=1<==<=*a*1,<=*i*<==<=1 for all *i*<==<=1,<=2,<=...,<=*n*. - Each of the remaining numbers in the t... | ```python
n = int(input())
arr = []
for i in range(0,n):
mas = []
for j in range(0,n):
mas.append(1)
arr.append(mas)
for i in range(1,n):
mas = []
for j in range(1,n):
a = arr[i-1][j]
b = arr[i][j-1]
arr[i][j] = (a + b)
print (arr[n-1][n-1... | 3 | |
25 | A | IQ test | PROGRAMMING | 1,300 | [
"brute force"
] | A. IQ test | 2 | 256 | Bob is preparing to pass IQ test. The most frequent task in this test is to find out which one of the given *n* numbers differs from the others. Bob observed that one number usually differs from the others in evenness. Help Bob — to check his answers, he needs a program that among the given *n* numbers finds one that i... | The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of numbers in the task. The second line contains *n* space-separated natural numbers, not exceeding 100. It is guaranteed, that exactly one of these numbers differs from the others in evenness. | Output index of number that differs from the others in evenness. Numbers are numbered from 1 in the input order. | [
"5\n2 4 7 8 10\n",
"4\n1 2 1 1\n"
] | [
"3\n",
"2\n"
] | none | 0 | [
{
"input": "5\n2 4 7 8 10",
"output": "3"
},
{
"input": "4\n1 2 1 1",
"output": "2"
},
{
"input": "3\n1 2 2",
"output": "1"
},
{
"input": "3\n100 99 100",
"output": "2"
},
{
"input": "3\n5 3 2",
"output": "3"
},
{
"input": "4\n43 28 1 91",
"output"... | 1,545,132,896 | 2,147,483,647 | Python 3 | OK | TESTS | 32 | 248 | 0 | input()
nums = [True if n % 2 else False for n in map(int, input().split())]
if nums.count(True) == 1:
print(nums.index(True)+1)
else:
print(nums.index(False)+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
input()
nums = [True if n % 2 else False for n in map(int, input().split())]
if nums.count(True) == 1:
print(nums.index(True)+1)
else:
print(nums.index(False)+1)
``` | 3.938 |
29 | B | Traffic Lights | PROGRAMMING | 1,500 | [
"implementation"
] | B. Traffic Lights | 2 | 256 | A car moves from point A to point B at speed *v* meters per second. The action takes place on the X-axis. At the distance *d* meters from A there are traffic lights. Starting from time 0, for the first *g* seconds the green light is on, then for the following *r* seconds the red light is on, then again the green light ... | The first line contains integers *l*, *d*, *v*, *g*, *r* (1<=≤<=*l*,<=*d*,<=*v*,<=*g*,<=*r*<=≤<=1000,<=*d*<=<<=*l*) — the distance between A and B (in meters), the distance from A to the traffic lights, car's speed, the duration of green light and the duration of red light. | Output a single number — the minimum time that the car needs to get from point A to point B. Your output must have relative or absolute error less than 10<=-<=6. | [
"2 1 3 4 5\n",
"5 4 3 1 1\n"
] | [
"0.66666667\n",
"2.33333333\n"
] | none | 1,000 | [
{
"input": "2 1 3 4 5",
"output": "0.66666667"
},
{
"input": "5 4 3 1 1",
"output": "2.33333333"
},
{
"input": "862 33 604 888 704",
"output": "1.42715232"
},
{
"input": "458 251 49 622 472",
"output": "9.34693878"
},
{
"input": "772 467 142 356 889",
"output"... | 1,644,104,579 | 2,147,483,647 | PyPy 3 | OK | TESTS | 34 | 184 | 0 | import math
l,d,v,g,r=map(int,input().split())
ans=d/v
if(ans%(g+r)>=g):
ans=math.ceil(ans/(g+r))*(g+r)
ans+=(l-d)/v
print(ans) | Title: Traffic Lights
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A car moves from point A to point B at speed *v* meters per second. The action takes place on the X-axis. At the distance *d* meters from A there are traffic lights. Starting from time 0, for the first *g* seconds the green ... | ```python
import math
l,d,v,g,r=map(int,input().split())
ans=d/v
if(ans%(g+r)>=g):
ans=math.ceil(ans/(g+r))*(g+r)
ans+=(l-d)/v
print(ans)
``` | 3.954 |
59 | A | Word | PROGRAMMING | 800 | [
"implementation",
"strings"
] | A. Word | 2 | 256 | Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At th... | The first line contains a word *s* — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100. | Print the corrected word *s*. If the given word *s* has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one. | [
"HoUse\n",
"ViP\n",
"maTRIx\n"
] | [
"house\n",
"VIP\n",
"matrix\n"
] | none | 500 | [
{
"input": "HoUse",
"output": "house"
},
{
"input": "ViP",
"output": "VIP"
},
{
"input": "maTRIx",
"output": "matrix"
},
{
"input": "BNHWpnpawg",
"output": "bnhwpnpawg"
},
{
"input": "VTYGP",
"output": "VTYGP"
},
{
"input": "CHNenu",
"output": "chn... | 1,679,336,060 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 30 | 122 | 0 | str = input()
c1 = c2 = 0
for i in str:
if i.islower():
c1 +=1
else:
c2 +=1
if c2>c1:
print(str.upper())
else:
print(str.lower())
| Title: Word
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it ei... | ```python
str = input()
c1 = c2 = 0
for i in str:
if i.islower():
c1 +=1
else:
c2 +=1
if c2>c1:
print(str.upper())
else:
print(str.lower())
``` | 3.9695 |
448 | A | Rewards | PROGRAMMING | 800 | [
"implementation"
] | null | null | Bizon the Champion is called the Champion for a reason.
Bizon the Champion has recently got a present — a new glass cupboard with *n* shelves and he decided to put all his presents there. All the presents can be divided into two types: medals and cups. Bizon the Champion has *a*1 first prize cups, *a*2 second prize c... | The first line contains integers *a*1, *a*2 and *a*3 (0<=≤<=*a*1,<=*a*2,<=*a*3<=≤<=100). The second line contains integers *b*1, *b*2 and *b*3 (0<=≤<=*b*1,<=*b*2,<=*b*3<=≤<=100). The third line contains integer *n* (1<=≤<=*n*<=≤<=100).
The numbers in the lines are separated by single spaces. | Print "YES" (without the quotes) if all the rewards can be put on the shelves in the described manner. Otherwise, print "NO" (without the quotes). | [
"1 1 1\n1 1 1\n4\n",
"1 1 3\n2 3 4\n2\n",
"1 0 0\n1 0 0\n1\n"
] | [
"YES\n",
"YES\n",
"NO\n"
] | none | 500 | [
{
"input": "1 1 1\n1 1 1\n4",
"output": "YES"
},
{
"input": "1 1 3\n2 3 4\n2",
"output": "YES"
},
{
"input": "1 0 0\n1 0 0\n1",
"output": "NO"
},
{
"input": "0 0 0\n0 0 0\n1",
"output": "YES"
},
{
"input": "100 100 100\n100 100 100\n100",
"output": "YES"
},
... | 1,658,741,174 | 2,147,483,647 | Python 3 | OK | TESTS | 25 | 46 | 0 | import math
a1,a2,a3=map(int,input().split())
b1,b2,b3=map(int,input().split())
n=int(input())
slv_a=math.ceil((a1+a2+a3)/5)
slv_b=math.ceil((b1+b2+b3)/10)
if slv_a+slv_b<=n:
print("YES")
else:
print("NO")
| Title: Rewards
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Bizon the Champion is called the Champion for a reason.
Bizon the Champion has recently got a present — a new glass cupboard with *n* shelves and he decided to put all his presents there. All the presents can be divided into ... | ```python
import math
a1,a2,a3=map(int,input().split())
b1,b2,b3=map(int,input().split())
n=int(input())
slv_a=math.ceil((a1+a2+a3)/5)
slv_b=math.ceil((b1+b2+b3)/10)
if slv_a+slv_b<=n:
print("YES")
else:
print("NO")
``` | 3 | |
49 | A | Sleuth | PROGRAMMING | 800 | [
"implementation"
] | A. Sleuth | 2 | 256 | Vasya plays the sleuth with his friends. The rules of the game are as follows: those who play for the first time, that is Vasya is the sleuth, he should investigate a "crime" and find out what is happening. He can ask any questions whatsoever that can be answered with "Yes" or "No". All the rest agree beforehand to ans... | The single line contains a question represented by a non-empty line consisting of large and small Latin letters, spaces and a question mark. The line length does not exceed 100. It is guaranteed that the question mark occurs exactly once in the line — as the last symbol and that the line contains at least one letter. | Print answer for the question in a single line: YES if the answer is "Yes", NO if the answer is "No".
Remember that in the reply to the question the last letter, not the last character counts. I. e. the spaces and the question mark do not count as letters. | [
"Is it a melon?\n",
"Is it an apple?\n",
"Is it a banana ?\n",
"Is it an apple and a banana simultaneouSLY?\n"
] | [
"NO\n",
"YES\n",
"YES\n",
"YES\n"
] | none | 500 | [
{
"input": "Is it a melon?",
"output": "NO"
},
{
"input": "Is it an apple?",
"output": "YES"
},
{
"input": " Is it a banana ?",
"output": "YES"
},
{
"input": "Is it an apple and a banana simultaneouSLY?",
"output": "YES"
},
{
"input": "oHtSbDwzHb?",
... | 1,693,295,766 | 2,147,483,647 | Python 3 | OK | TESTS | 35 | 92 | 0 | x = input().split()
lst = ["A","E","O","I","U","a","e","o","u","i","y","Y"]
if x[len(x) - 1][len(x[len(x) - 1]) - 1] == "?" and len(x[len(x) - 1]) == 1: #or x[len(x) - 2][len(x[len(x) - 2]) -1] in lst:
if x[len(x) - 2][len(x[len(x) - 2]) -1] in lst:
print("YES")
else:
print("NO")
elif ... | Title: Sleuth
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya plays the sleuth with his friends. The rules of the game are as follows: those who play for the first time, that is Vasya is the sleuth, he should investigate a "crime" and find out what is happening. He can ask any questions ... | ```python
x = input().split()
lst = ["A","E","O","I","U","a","e","o","u","i","y","Y"]
if x[len(x) - 1][len(x[len(x) - 1]) - 1] == "?" and len(x[len(x) - 1]) == 1: #or x[len(x) - 2][len(x[len(x) - 2]) -1] in lst:
if x[len(x) - 2][len(x[len(x) - 2]) -1] in lst:
print("YES")
else:
print("NO")... | 3.977 |
9 | A | Die Roll | PROGRAMMING | 800 | [
"math",
"probabilities"
] | A. Die Roll | 1 | 64 | Yakko, Wakko and Dot, world-famous animaniacs, decided to rest from acting in cartoons, and take a leave to travel a bit. Yakko dreamt to go to Pennsylvania, his Motherland and the Motherland of his ancestors. Wakko thought about Tasmania, its beaches, sun and sea. Dot chose Transylvania as the most mysterious and unpr... | The only line of the input file contains two natural numbers Y and W — the results of Yakko's and Wakko's die rolls. | Output the required probability in the form of irreducible fraction in format «A/B», where A — the numerator, and B — the denominator. If the required probability equals to zero, output «0/1». If the required probability equals to 1, output «1/1». | [
"4 2\n"
] | [
"1/2\n"
] | Dot will go to Transylvania, if she is lucky to roll 4, 5 or 6 points. | 0 | [
{
"input": "4 2",
"output": "1/2"
},
{
"input": "1 1",
"output": "1/1"
},
{
"input": "1 2",
"output": "5/6"
},
{
"input": "1 3",
"output": "2/3"
},
{
"input": "1 4",
"output": "1/2"
},
{
"input": "1 5",
"output": "1/3"
},
{
"input": "1 6",
... | 1,425,397,553 | 2,147,483,647 | Python 3 | OK | TESTS | 36 | 310 | 5,836,800 | rdl = list(map(int,input().split()))
_max = max(rdl[0], rdl[1])
_score = 6 - _max + 1
import fractions
gcd = fractions.gcd(6, _score)
print(int(_score/gcd), end="")
print("/",end="")
print(int(6/gcd),end="\n") | Title: Die Roll
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
Yakko, Wakko and Dot, world-famous animaniacs, decided to rest from acting in cartoons, and take a leave to travel a bit. Yakko dreamt to go to Pennsylvania, his Motherland and the Motherland of his ancestors. Wakko thought about T... | ```python
rdl = list(map(int,input().split()))
_max = max(rdl[0], rdl[1])
_score = 6 - _max + 1
import fractions
gcd = fractions.gcd(6, _score)
print(int(_score/gcd), end="")
print("/",end="")
print(int(6/gcd),end="\n")
``` | 3.801512 |
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,622,874,850 | 2,147,483,647 | Python 3 | OK | TESTS | 80 | 998 | 0 | n=int(input())
arr=list(map(int,input().split()))
ans=1
for i in range(n):
l=0
r=0
for j in range(i,0,-1):
if(arr[j]<arr[j-1]):
l=i-j
break
elif(j==1):
l=i
for j in range(i,n-1):
if(arr[j]<arr[j+1]):
r=j-i
... | 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())
arr=list(map(int,input().split()))
ans=1
for i in range(n):
l=0
r=0
for j in range(i,0,-1):
if(arr[j]<arr[j-1]):
l=i-j
break
elif(j==1):
l=i
for j in range(i,n-1):
if(arr[j]<arr[j+1]):
r=j-i
... | 3.7505 |
59 | A | Word | PROGRAMMING | 800 | [
"implementation",
"strings"
] | A. Word | 2 | 256 | Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At th... | The first line contains a word *s* — it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100. | Print the corrected word *s*. If the given word *s* has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one. | [
"HoUse\n",
"ViP\n",
"maTRIx\n"
] | [
"house\n",
"VIP\n",
"matrix\n"
] | none | 500 | [
{
"input": "HoUse",
"output": "house"
},
{
"input": "ViP",
"output": "VIP"
},
{
"input": "maTRIx",
"output": "matrix"
},
{
"input": "BNHWpnpawg",
"output": "bnhwpnpawg"
},
{
"input": "VTYGP",
"output": "VTYGP"
},
{
"input": "CHNenu",
"output": "chn... | 1,643,998,945 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 62 | 0 | a = input()
up = 0
down = 0
for i in a:
if i == i.upper():
up += 1
else:
down += 1
if down >= up:
print(a.lower())
else:
print(a.upper()) | Title: Word
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it ei... | ```python
a = input()
up = 0
down = 0
for i in a:
if i == i.upper():
up += 1
else:
down += 1
if down >= up:
print(a.lower())
else:
print(a.upper())
``` | 3.9845 |
32 | B | Borze | PROGRAMMING | 800 | [
"expression parsing",
"implementation"
] | B. Borze | 2 | 256 | Ternary numeric notation is quite popular in Berland. To telegraph the ternary number the Borze alphabet is used. Digit 0 is transmitted as «.», 1 as «-.» and 2 as «--». You are to decode the Borze code, i.e. to find out the ternary number given its representation in Borze alphabet. | The first line contains a number in Borze code. The length of the string is between 1 and 200 characters. It's guaranteed that the given string is a valid Borze code of some ternary number (this number can have leading zeroes). | Output the decoded ternary number. It can have leading zeroes. | [
".-.--\n",
"--.\n",
"-..-.--\n"
] | [
"012",
"20",
"1012"
] | none | 1,000 | [
{
"input": ".-.--",
"output": "012"
},
{
"input": "--.",
"output": "20"
},
{
"input": "-..-.--",
"output": "1012"
},
{
"input": "---..",
"output": "210"
},
{
"input": "..--.---..",
"output": "0020210"
},
{
"input": "-.....----.",
"output": "1000022... | 1,622,532,223 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 248 | 0 | string=input()
lst=list(string)
i=0
lst1=[]
while i<len(lst):
if lst[i]==".":
lst1.append("0")
i+=1
elif lst[i]=="-" and lst[i+1]==".":
lst1.append("1")
i+=2
elif lst[i]=="-"and lst[i+1]=="-":
lst1.append("2")
i+=2
for i in lst1:
print(i,end... | Title: Borze
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Ternary numeric notation is quite popular in Berland. To telegraph the ternary number the Borze alphabet is used. Digit 0 is transmitted as «.», 1 as «-.» and 2 as «--». You are to decode the Borze code, i.e. to find out the ternary ... | ```python
string=input()
lst=list(string)
i=0
lst1=[]
while i<len(lst):
if lst[i]==".":
lst1.append("0")
i+=1
elif lst[i]=="-" and lst[i+1]==".":
lst1.append("1")
i+=2
elif lst[i]=="-"and lst[i+1]=="-":
lst1.append("2")
i+=2
for i in lst1:
p... | 3.938 |
32 | A | Reconnaissance | PROGRAMMING | 800 | [
"brute force"
] | A. Reconnaissance | 2 | 256 | According to the regulations of Berland's army, a reconnaissance unit should consist of exactly two soldiers. Since these two soldiers shouldn't differ much, their heights can differ by at most *d* centimeters. Captain Bob has *n* soldiers in his detachment. Their heights are *a*1,<=*a*2,<=...,<=*a**n* centimeters. Som... | The first line contains two integers *n* and *d* (1<=≤<=*n*<=≤<=1000,<=1<=≤<=*d*<=≤<=109) — amount of soldiers in Bob's detachment and the maximum allowed height difference respectively. The second line contains *n* space-separated integers — heights of all the soldiers in Bob's detachment. These numbers don't exceed 1... | Output one number — amount of ways to form a reconnaissance unit of two soldiers, whose height difference doesn't exceed *d*. | [
"5 10\n10 20 50 60 65\n",
"5 1\n55 30 29 31 55\n"
] | [
"6\n",
"6\n"
] | none | 500 | [
{
"input": "5 10\n10 20 50 60 65",
"output": "6"
},
{
"input": "5 1\n55 30 29 31 55",
"output": "6"
},
{
"input": "6 10\n4 6 4 1 9 3",
"output": "30"
},
{
"input": "7 100\n19 1694 261 162 1 234 513",
"output": "8"
},
{
"input": "8 42\n37 53 74 187 568 22 5 65",
... | 1,625,650,322 | 2,147,483,647 | PyPy 3 | OK | TESTS | 32 | 280 | 1,843,200 | n,k=map(int,input().split())
a=list(map(int,input().split()))
c=0
for i in range(n):
for j in range(n):
if i!=j and abs(a[i]-a[j])<=k:
c+=1
print(c)
| Title: Reconnaissance
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
According to the regulations of Berland's army, a reconnaissance unit should consist of exactly two soldiers. Since these two soldiers shouldn't differ much, their heights can differ by at most *d* centimeters. Captain Bob h... | ```python
n,k=map(int,input().split())
a=list(map(int,input().split()))
c=0
for i in range(n):
for j in range(n):
if i!=j and abs(a[i]-a[j])<=k:
c+=1
print(c)
``` | 3.926567 |
92 | A | Chips | PROGRAMMING | 800 | [
"implementation",
"math"
] | A. Chips | 2 | 256 | There are *n* walruses sitting in a circle. All of them are numbered in the clockwise order: the walrus number 2 sits to the left of the walrus number 1, the walrus number 3 sits to the left of the walrus number 2, ..., the walrus number 1 sits to the left of the walrus number *n*.
The presenter has *m* chips. The pre... | The first line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=50, 1<=≤<=*m*<=≤<=104) — the number of walruses and the number of chips correspondingly. | Print the number of chips the presenter ended up with. | [
"4 11\n",
"17 107\n",
"3 8\n"
] | [
"0\n",
"2\n",
"1\n"
] | In the first sample the presenter gives one chip to the walrus number 1, two chips to the walrus number 2, three chips to the walrus number 3, four chips to the walrus number 4, then again one chip to the walrus number 1. After that the presenter runs out of chips. He can't give anything to the walrus number 2 and the ... | 500 | [
{
"input": "4 11",
"output": "0"
},
{
"input": "17 107",
"output": "2"
},
{
"input": "3 8",
"output": "1"
},
{
"input": "46 7262",
"output": "35"
},
{
"input": "32 6864",
"output": "0"
},
{
"input": "36 6218",
"output": "14"
},
{
"input": "... | 1,638,187,914 | 2,147,483,647 | Python 3 | OK | TESTS | 25 | 92 | 0 | s = input().split(" ")
n = int(s[0])
m = int(s[1])
s = (1 + n)*n//2
m = m % s
i = 1
while(m >= i):
m -= i
i += 1
print(m)
| Title: Chips
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
There are *n* walruses sitting in a circle. All of them are numbered in the clockwise order: the walrus number 2 sits to the left of the walrus number 1, the walrus number 3 sits to the left of the walrus number 2, ..., the walrus nu... | ```python
s = input().split(" ")
n = int(s[0])
m = int(s[1])
s = (1 + n)*n//2
m = m % s
i = 1
while(m >= i):
m -= i
i += 1
print(m)
``` | 3.977 |
289 | B | Polo the Penguin and Matrix | PROGRAMMING | 1,400 | [
"brute force",
"dp",
"implementation",
"sortings",
"ternary search"
] | null | null | Little penguin Polo has an *n*<=×<=*m* matrix, consisting of integers. Let's index the matrix rows from 1 to *n* from top to bottom and let's index the columns from 1 to *m* from left to right. Let's represent the matrix element on the intersection of row *i* and column *j* as *a**ij*.
In one move the penguin can add ... | The first line contains three integers *n*, *m* and *d* (1<=≤<=*n*,<=*m*<=≤<=100,<=1<=≤<=*d*<=≤<=104) — the matrix sizes and the *d* parameter. Next *n* lines contain the matrix: the *j*-th integer in the *i*-th row is the matrix element *a**ij* (1<=≤<=*a**ij*<=≤<=104). | In a single line print a single integer — the minimum number of moves the penguin needs to make all matrix elements equal. If that is impossible, print "-1" (without the quotes). | [
"2 2 2\n2 4\n6 8\n",
"1 2 7\n6 7\n"
] | [
"4\n",
"-1\n"
] | none | 1,000 | [
{
"input": "2 2 2\n2 4\n6 8",
"output": "4"
},
{
"input": "1 2 7\n6 7",
"output": "-1"
},
{
"input": "3 2 1\n5 7\n1 2\n5 100",
"output": "104"
},
{
"input": "3 3 3\n5 8 5\n11 11 17\n14 5 2",
"output": "12"
},
{
"input": "3 3 3\n5 8 5\n11 11 17\n14 5 3",
"outpu... | 1,674,552,810 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 31 | 154 | 2,048,000 | import sys
I = sys.stdin.readline
IM = lambda : map(int, I().split())
n, m, d = IM()
a = []
np = set()
for i in range(n):
a += list(IM())
for v in a:
np.add(v%d)
if len(np) > 1:
ans = -1
else:
a.sort()
md = a[(len(a))//2]
ans = sum([(abs(md-v)//d) for v in a])
pri... | Title: Polo the Penguin and Matrix
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little penguin Polo has an *n*<=×<=*m* matrix, consisting of integers. Let's index the matrix rows from 1 to *n* from top to bottom and let's index the columns from 1 to *m* from left to right. Let's represe... | ```python
import sys
I = sys.stdin.readline
IM = lambda : map(int, I().split())
n, m, d = IM()
a = []
np = set()
for i in range(n):
a += list(IM())
for v in a:
np.add(v%d)
if len(np) > 1:
ans = -1
else:
a.sort()
md = a[(len(a))//2]
ans = sum([(abs(md-v)//d) for v i... | 3 | |
676 | B | Pyramid of Glasses | PROGRAMMING | 1,500 | [
"implementation",
"math",
"math"
] | null | null | Mary has just graduated from one well-known University and is now attending celebration party. Students like to dream of a beautiful life, so they used champagne glasses to construct a small pyramid. The height of the pyramid is *n*. The top level consists of only 1 glass, that stands on 2 glasses on the second level (... | The only line of the input contains two integers *n* and *t* (1<=≤<=*n*<=≤<=10,<=0<=≤<=*t*<=≤<=10<=000) — the height of the pyramid and the number of seconds Vlad will be pouring champagne from the bottle. | Print the single integer — the number of completely full glasses after *t* seconds. | [
"3 5\n",
"4 8\n"
] | [
"4\n",
"6\n"
] | In the first sample, the glasses full after 5 seconds are: the top glass, both glasses on the second level and the middle glass at the bottom level. Left and right glasses of the bottom level will be half-empty. | 1,000 | [
{
"input": "3 5",
"output": "4"
},
{
"input": "4 8",
"output": "6"
},
{
"input": "1 1",
"output": "1"
},
{
"input": "10 10000",
"output": "55"
},
{
"input": "1 10000",
"output": "1"
},
{
"input": "10 1",
"output": "1"
},
{
"input": "1 0",
... | 1,624,974,304 | 2,147,483,647 | Python 3 | OK | TESTS | 121 | 93 | 0 | # https://codeforces.com/contest/676/problem/B
n, t = [int(i) for i in input().split(' ')]
pyramid = []
for i in range(n+1):
temp_arr = []
for j in range(i):
temp_arr.append(0)
pyramid.append(temp_arr)
# pyramid.reverse()
def get_num_filed(num, time, level, glass, input_per_second=1):... | Title: Pyramid of Glasses
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mary has just graduated from one well-known University and is now attending celebration party. Students like to dream of a beautiful life, so they used champagne glasses to construct a small pyramid. The height of th... | ```python
# https://codeforces.com/contest/676/problem/B
n, t = [int(i) for i in input().split(' ')]
pyramid = []
for i in range(n+1):
temp_arr = []
for j in range(i):
temp_arr.append(0)
pyramid.append(temp_arr)
# pyramid.reverse()
def get_num_filed(num, time, level, glass, input_per_... | 3 | |
859 | B | Lazy Security Guard | PROGRAMMING | 1,000 | [
"brute force",
"geometry",
"math"
] | null | null | Your security guard friend recently got a new job at a new security company. The company requires him to patrol an area of the city encompassing exactly *N* city blocks, but they let him choose which blocks. That is, your friend must walk the perimeter of a region whose area is exactly *N* blocks. Your friend is quite ... | Input will consist of a single integer *N* (1<=≤<=*N*<=≤<=106), the number of city blocks that must be enclosed by the route. | Print the minimum perimeter that can be achieved. | [
"4\n",
"11\n",
"22\n"
] | [
"8\n",
"14\n",
"20\n"
] | Here are some possible shapes for the examples:
<img class="tex-graphics" src="https://espresso.codeforces.com/e11bef2cf82b55dd583cfc97d12b5aee5e483a65.png" style="max-width: 100.0%;max-height: 100.0%;"/> | 750 | [
{
"input": "4",
"output": "8"
},
{
"input": "11",
"output": "14"
},
{
"input": "22",
"output": "20"
},
{
"input": "3",
"output": "8"
},
{
"input": "1024",
"output": "128"
},
{
"input": "101",
"output": "42"
},
{
"input": "30",
"output":... | 1,591,158,551 | 2,147,483,647 | Python 3 | OK | TESTS | 35 | 124 | 0 | import math
n=int(input())
a=int(math.ceil(math.sqrt(n)))
b=a+1
a1=((n-n%a)/a)*2+2*a
if(n%a!=0):
a1+=2
a2=((n-n%b)/b)*2+2*b
if(n%b!=0):
a2+=2
print(int(min(a1,a2)))
| Title: Lazy Security Guard
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Your security guard friend recently got a new job at a new security company. The company requires him to patrol an area of the city encompassing exactly *N* city blocks, but they let him choose which blocks. That is... | ```python
import math
n=int(input())
a=int(math.ceil(math.sqrt(n)))
b=a+1
a1=((n-n%a)/a)*2+2*a
if(n%a!=0):
a1+=2
a2=((n-n%b)/b)*2+2*b
if(n%b!=0):
a2+=2
print(int(min(a1,a2)))
``` | 3 | |
450 | A | Jzzhu and Children | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | There are *n* children in Jzzhu's school. Jzzhu is going to give some candies to them. Let's number all the children from 1 to *n*. The *i*-th child wants to get at least *a**i* candies.
Jzzhu asks children to line up. Initially, the *i*-th child stands at the *i*-th place of the line. Then Jzzhu start distribution of... | The first line contains two integers *n*,<=*m* (1<=≤<=*n*<=≤<=100; 1<=≤<=*m*<=≤<=100). The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=100). | Output a single integer, representing the number of the last child. | [
"5 2\n1 3 1 4 2\n",
"6 4\n1 1 2 2 3 3\n"
] | [
"4\n",
"6\n"
] | Let's consider the first sample.
Firstly child 1 gets 2 candies and go home. Then child 2 gets 2 candies and go to the end of the line. Currently the line looks like [3, 4, 5, 2] (indices of the children in order of the line). Then child 3 gets 2 candies and go home, and then child 4 gets 2 candies and goes to the en... | 500 | [
{
"input": "5 2\n1 3 1 4 2",
"output": "4"
},
{
"input": "6 4\n1 1 2 2 3 3",
"output": "6"
},
{
"input": "7 3\n6 1 5 4 2 3 1",
"output": "4"
},
{
"input": "10 5\n2 7 3 6 2 5 1 3 4 5",
"output": "4"
},
{
"input": "100 1\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18... | 1,694,184,338 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 49 | 62 | 0 | from sys import stdin
from math import ceil
input = stdin.readline
n, m = map(int, input().split())
arr = list(map(int, input().split()))
last_home = 0
index = 0
for i in range(n):
home_after = ceil(arr[i]/m)
if home_after >= last_home :
last_home = home_after
index = i
... | Title: Jzzhu and Children
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* children in Jzzhu's school. Jzzhu is going to give some candies to them. Let's number all the children from 1 to *n*. The *i*-th child wants to get at least *a**i* candies.
Jzzhu asks children to line ... | ```python
from sys import stdin
from math import ceil
input = stdin.readline
n, m = map(int, input().split())
arr = list(map(int, input().split()))
last_home = 0
index = 0
for i in range(n):
home_after = ceil(arr[i]/m)
if home_after >= last_home :
last_home = home_after
index = i
... | 3 | |
455 | A | Boredom | PROGRAMMING | 1,500 | [
"dp"
] | null | null | Alex doesn't like boredom. That's why whenever he gets bored, he comes up with games. One long winter evening he came up with a game and decided to play it.
Given a sequence *a* consisting of *n* integers. The player can make several steps. In a single step he can choose an element of the sequence (let's denote it *a*... | The first line contains integer *n* (1<=≤<=*n*<=≤<=105) that shows how many numbers are in Alex's sequence.
The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=105). | Print a single integer — the maximum number of points that Alex can earn. | [
"2\n1 2\n",
"3\n1 2 3\n",
"9\n1 2 1 3 2 2 2 2 3\n"
] | [
"2\n",
"4\n",
"10\n"
] | Consider the third test example. At first step we need to choose any element equal to 2. After that step our sequence looks like this [2, 2, 2, 2]. Then we do 4 steps, on each step we choose any element equals to 2. In total we earn 10 points. | 500 | [
{
"input": "2\n1 2",
"output": "2"
},
{
"input": "3\n1 2 3",
"output": "4"
},
{
"input": "9\n1 2 1 3 2 2 2 2 3",
"output": "10"
},
{
"input": "5\n3 3 4 5 4",
"output": "11"
},
{
"input": "5\n5 3 5 3 4",
"output": "16"
},
{
"input": "5\n4 2 3 2 5",
... | 1,700,048,957 | 2,147,483,647 | Python 3 | OK | TESTS | 47 | 124 | 13,619,200 | n=int(input())
s=[int(x) for x in input().split()]
m=max(s)
a=[0]*(m+1)
dp=[0]*(m+1)
ans=0
for i in range(n):
a[s[i]]+=1
dp[1]=a[1]
for i in range(2,m+1):
dp[i]=max(a[i]*i+dp[i-2],dp[i-1])
print(max(dp)) | Title: Boredom
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Alex doesn't like boredom. That's why whenever he gets bored, he comes up with games. One long winter evening he came up with a game and decided to play it.
Given a sequence *a* consisting of *n* integers. The player can make ... | ```python
n=int(input())
s=[int(x) for x in input().split()]
m=max(s)
a=[0]*(m+1)
dp=[0]*(m+1)
ans=0
for i in range(n):
a[s[i]]+=1
dp[1]=a[1]
for i in range(2,m+1):
dp[i]=max(a[i]*i+dp[i-2],dp[i-1])
print(max(dp))
``` | 3 | |
609 | B | The Best Gift | PROGRAMMING | 1,100 | [
"constructive algorithms",
"implementation"
] | null | null | Emily's birthday is next week and Jack has decided to buy a present for her. He knows she loves books so he goes to the local bookshop, where there are *n* books on sale from one of *m* genres.
In the bookshop, Jack decides to buy two books of different genres.
Based on the genre of books on sale in the shop, find th... | The first line contains two positive integers *n* and *m* (2<=≤<=*n*<=≤<=2·105,<=2<=≤<=*m*<=≤<=10) — the number of books in the bookstore and the number of genres.
The second line contains a sequence *a*1,<=*a*2,<=...,<=*a**n*, where *a**i* (1<=≤<=*a**i*<=≤<=*m*) equals the genre of the *i*-th book.
It is guaranteed ... | Print the only integer — the number of ways in which Jack can choose books.
It is guaranteed that the answer doesn't exceed the value 2·109. | [
"4 3\n2 1 3 1\n",
"7 4\n4 2 3 1 2 4 3\n"
] | [
"5\n",
"18\n"
] | The answer to the first test sample equals 5 as Sasha can choose:
1. the first and second books, 1. the first and third books, 1. the first and fourth books, 1. the second and third books, 1. the third and fourth books. | 0 | [
{
"input": "4 3\n2 1 3 1",
"output": "5"
},
{
"input": "7 4\n4 2 3 1 2 4 3",
"output": "18"
},
{
"input": "2 2\n1 2",
"output": "1"
},
{
"input": "3 2\n1 2 2",
"output": "2"
},
{
"input": "10 10\n1 2 3 4 5 6 7 8 9 10",
"output": "45"
},
{
"input": "9 2... | 1,562,496,365 | 2,147,483,647 | Python 3 | OK | TESTS | 42 | 202 | 3,993,600 | n, m = map(int, input().split())
a = list(map(int, input().split()))
cnt = [0] * (m + 1)
for i in a:
cnt[i] += 1
res = 0
for i in a:
res += (n - cnt[i])
print(res//2) | Title: The Best Gift
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Emily's birthday is next week and Jack has decided to buy a present for her. He knows she loves books so he goes to the local bookshop, where there are *n* books on sale from one of *m* genres.
In the bookshop, Jack deci... | ```python
n, m = map(int, input().split())
a = list(map(int, input().split()))
cnt = [0] * (m + 1)
for i in a:
cnt[i] += 1
res = 0
for i in a:
res += (n - cnt[i])
print(res//2)
``` | 3 | |
595 | A | Vitaly and Night | PROGRAMMING | 800 | [
"constructive algorithms",
"implementation"
] | null | null | One day Vitaly was going home late at night and wondering: how many people aren't sleeping at that moment? To estimate, Vitaly decided to look which windows are lit in the house he was passing by at that moment.
Vitaly sees a building of *n* floors and 2·*m* windows on each floor. On each floor there are *m* flats num... | The first line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of floors in the house and the number of flats on each floor respectively.
Next *n* lines describe the floors from top to bottom and contain 2·*m* characters each. If the *i*-th window of the given floor has lights on,... | Print a single integer — the number of flats that have lights on in at least one window, that is, the flats where, according to Vitaly, people aren't sleeping. | [
"2 2\n0 0 0 1\n1 0 1 1\n",
"1 3\n1 1 0 1 0 0\n"
] | [
"3\n",
"2\n"
] | In the first test case the house has two floors, two flats on each floor. That is, in total there are 4 flats. The light isn't on only on the second floor in the left flat. That is, in both rooms of the flat the light is off.
In the second test case the house has one floor and the first floor has three flats. The ligh... | 500 | [
{
"input": "2 2\n0 0 0 1\n1 0 1 1",
"output": "3"
},
{
"input": "1 3\n1 1 0 1 0 0",
"output": "2"
},
{
"input": "3 3\n1 1 1 1 1 1\n1 1 0 1 1 0\n1 0 0 0 1 1",
"output": "8"
},
{
"input": "1 5\n1 0 1 1 1 0 1 1 1 1",
"output": "5"
},
{
"input": "1 100\n1 1 1 1 1 1 1 ... | 1,497,064,468 | 2,147,483,647 | Python 3 | OK | TESTS | 36 | 77 | 204,800 | N, M = map(int, input().split())
table = []
for i in range(N):
table.append(list(map(int, input().split())))
ans = 0
for i in range(N):
for j in range(M):
if table[i][2 * j] == 1 or table[i][2 * j + 1] == 1:
ans += 1
print(ans)
| Title: Vitaly and Night
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day Vitaly was going home late at night and wondering: how many people aren't sleeping at that moment? To estimate, Vitaly decided to look which windows are lit in the house he was passing by at that moment.
Vital... | ```python
N, M = map(int, input().split())
table = []
for i in range(N):
table.append(list(map(int, input().split())))
ans = 0
for i in range(N):
for j in range(M):
if table[i][2 * j] == 1 or table[i][2 * j + 1] == 1:
ans += 1
print(ans)
``` | 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,686,246,259 | 2,147,483,647 | Python 3 | OK | TESTS | 29 | 46 | 0 | a= int(input())
b = int(input())
c = int(input())
a1= a+b+c
a2=a*(b+c)
a3=(a+b) *c
a4 = a *b * c
print(max(a1,a2,a3,a4)) | 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())
a1= a+b+c
a2=a*(b+c)
a3=(a+b) *c
a4 = a *b * c
print(max(a1,a2,a3,a4))
``` | 3 | |
250 | B | Restoring IPv6 | PROGRAMMING | 1,500 | [
"implementation",
"strings"
] | null | null | An IPv6-address is a 128-bit number. For convenience, this number is recorded in blocks of 16 bits in hexadecimal record, the blocks are separated by colons — 8 blocks in total, each block has four hexadecimal digits. Here is an example of the correct record of a IPv6 address: "0124:5678:90ab:cdef:0124:5678:90ab:cdef".... | The first line contains a single integer *n* — the number of records to restore (1<=≤<=*n*<=≤<=100).
Each of the following *n* lines contains a string — the short IPv6 addresses. Each string only consists of string characters "0123456789abcdef:".
It is guaranteed that each short address is obtained by the way that is... | For each short IPv6 address from the input print its full record on a separate line. Print the full records for the short IPv6 addresses in the order, in which the short records follow in the input. | [
"6\na56f:d3:0:0124:01:f19a:1000:00\na56f:00d3:0000:0124:0001::\na56f::0124:0001:0000:1234:0ff0\na56f:0000::0000:0001:0000:1234:0ff0\n::\n0ea::4d:f4:6:0\n"
] | [
"a56f:00d3:0000:0124:0001:f19a:1000:0000\na56f:00d3:0000:0124:0001:0000:0000:0000\na56f:0000:0000:0124:0001:0000:1234:0ff0\na56f:0000:0000:0000:0001:0000:1234:0ff0\n0000:0000:0000:0000:0000:0000:0000:0000\n00ea:0000:0000:0000:004d:00f4:0006:0000\n"
] | none | 1,000 | [
{
"input": "6\na56f:d3:0:0124:01:f19a:1000:00\na56f:00d3:0000:0124:0001::\na56f::0124:0001:0000:1234:0ff0\na56f:0000::0000:0001:0000:1234:0ff0\n::\n0ea::4d:f4:6:0",
"output": "a56f:00d3:0000:0124:0001:f19a:1000:0000\na56f:00d3:0000:0124:0001:0000:0000:0000\na56f:0000:0000:0124:0001:0000:1234:0ff0\na56f:0000... | 1,518,553,952 | 2,147,483,647 | Python 3 | OK | TESTS | 40 | 124 | 5,632,000 |
def restora(lin):
lin = lin.split(":")
ans = []
falt = 8
for w in lin:
if w != "":
falt -= 1
for w in lin:
if w == "":
while falt > 0:
ans.append("0000")
falt -= 1
continue
while len(w) < 4:
... | Title: Restoring IPv6
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
An IPv6-address is a 128-bit number. For convenience, this number is recorded in blocks of 16 bits in hexadecimal record, the blocks are separated by colons — 8 blocks in total, each block has four hexadecimal digits. He... | ```python
def restora(lin):
lin = lin.split(":")
ans = []
falt = 8
for w in lin:
if w != "":
falt -= 1
for w in lin:
if w == "":
while falt > 0:
ans.append("0000")
falt -= 1
continue
while le... | 3 | |
743 | B | Chloe and the sequence | PROGRAMMING | 1,200 | [
"binary search",
"bitmasks",
"constructive algorithms",
"implementation"
] | null | null | Chloe, the same as Vladik, is a competitive programmer. She didn't have any problems to get to the olympiad like Vladik, but she was confused by the task proposed on the olympiad.
Let's consider the following algorithm of generating a sequence of integers. Initially we have a sequence consisting of a single element eq... | The only line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=50, 1<=≤<=*k*<=≤<=2*n*<=-<=1). | Print single integer — the integer at the *k*-th position in the obtained sequence. | [
"3 2\n",
"4 8\n"
] | [
"2",
"4"
] | In the first sample the obtained sequence is [1, 2, 1, 3, 1, 2, 1]. The number on the second position is 2.
In the second sample the obtained sequence is [1, 2, 1, 3, 1, 2, 1, 4, 1, 2, 1, 3, 1, 2, 1]. The number on the eighth position is 4. | 1,000 | [
{
"input": "3 2",
"output": "2"
},
{
"input": "4 8",
"output": "4"
},
{
"input": "5 27",
"output": "1"
},
{
"input": "7 44",
"output": "3"
},
{
"input": "15 18432",
"output": "12"
},
{
"input": "20 259676",
"output": "3"
},
{
"input": "30 6... | 1,632,639,748 | 2,147,483,647 | PyPy 3 | OK | TESTS | 39 | 109 | 20,172,800 | import sys
input = sys.stdin.readline
def binary_search(l,r,n,x):
if r>=l:
mid=(r+l)//2
if mid==x:
return n
if mid<x:
return binary_search(mid+1,r,n-1,x)
elif mid>x:
return binary_search(l,mid-1,n-1,x)
else:
return -1
def m... | Title: Chloe and the sequence
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Chloe, the same as Vladik, is a competitive programmer. She didn't have any problems to get to the olympiad like Vladik, but she was confused by the task proposed on the olympiad.
Let's consider the following a... | ```python
import sys
input = sys.stdin.readline
def binary_search(l,r,n,x):
if r>=l:
mid=(r+l)//2
if mid==x:
return n
if mid<x:
return binary_search(mid+1,r,n-1,x)
elif mid>x:
return binary_search(l,mid-1,n-1,x)
else:
return... | 3 | |
337 | A | Puzzles | PROGRAMMING | 900 | [
"greedy"
] | null | null | The end of the school year is near and Ms. Manana, the teacher, will soon have to say goodbye to a yet another class. She decided to prepare a goodbye present for her *n* students and give each of them a jigsaw puzzle (which, as wikipedia states, is a tiling puzzle that requires the assembly of numerous small, often od... | The first line contains space-separated integers *n* and *m* (2<=≤<=*n*<=≤<=*m*<=≤<=50). The second line contains *m* space-separated integers *f*1,<=*f*2,<=...,<=*f**m* (4<=≤<=*f**i*<=≤<=1000) — the quantities of pieces in the puzzles sold in the shop. | Print a single integer — the least possible difference the teacher can obtain. | [
"4 6\n10 12 10 7 5 22\n"
] | [
"5\n"
] | Sample 1. The class has 4 students. The shop sells 6 puzzles. If Ms. Manana buys the first four puzzles consisting of 10, 12, 10 and 7 pieces correspondingly, then the difference between the sizes of the largest and the smallest puzzle will be equal to 5. It is impossible to obtain a smaller difference. Note that the t... | 500 | [
{
"input": "4 6\n10 12 10 7 5 22",
"output": "5"
},
{
"input": "2 2\n4 4",
"output": "0"
},
{
"input": "2 10\n4 5 6 7 8 9 10 11 12 12",
"output": "0"
},
{
"input": "4 5\n818 136 713 59 946",
"output": "759"
},
{
"input": "3 20\n446 852 783 313 549 965 40 88 86 617... | 1,689,493,114 | 2,147,483,647 | Python 3 | OK | TESTS | 18 | 92 | 0 | n, m = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
c, mc = 0, 10000
while len(a) >= n:
c = a[n-1] - a[0]
mc = min(mc, c)
a = a[1:]
print(mc)
| Title: Puzzles
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The end of the school year is near and Ms. Manana, the teacher, will soon have to say goodbye to a yet another class. She decided to prepare a goodbye present for her *n* students and give each of them a jigsaw puzzle (which, a... | ```python
n, m = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
c, mc = 0, 10000
while len(a) >= n:
c = a[n-1] - a[0]
mc = min(mc, c)
a = a[1:]
print(mc)
``` | 3 | |
496 | A | Minimum Difficulty | PROGRAMMING | 900 | [
"brute force",
"implementation",
"math"
] | null | null | Mike is trying rock climbing but he is awful at it.
There are *n* holds on the wall, *i*-th hold is at height *a**i* off the ground. Besides, let the sequence *a**i* increase, that is, *a**i*<=<<=*a**i*<=+<=1 for all *i* from 1 to *n*<=-<=1; we will call such sequence a track. Mike thinks that the track *a*1, ...,... | The first line contains a single integer *n* (3<=≤<=*n*<=≤<=100) — the number of holds.
The next line contains *n* space-separated integers *a**i* (1<=≤<=*a**i*<=≤<=1000), where *a**i* is the height where the hold number *i* hangs. The sequence *a**i* is increasing (i.e. each element except for the first one is strict... | Print a single number — the minimum difficulty of the track after removing a single hold. | [
"3\n1 4 6\n",
"5\n1 2 3 4 5\n",
"5\n1 2 3 7 8\n"
] | [
"5\n",
"2\n",
"4\n"
] | In the first sample you can remove only the second hold, then the sequence looks like (1, 6), the maximum difference of the neighboring elements equals 5.
In the second test after removing every hold the difficulty equals 2.
In the third test you can obtain sequences (1, 3, 7, 8), (1, 2, 7, 8), (1, 2, 3, 8), for whic... | 500 | [
{
"input": "3\n1 4 6",
"output": "5"
},
{
"input": "5\n1 2 3 4 5",
"output": "2"
},
{
"input": "5\n1 2 3 7 8",
"output": "4"
},
{
"input": "3\n1 500 1000",
"output": "999"
},
{
"input": "10\n1 2 3 4 5 6 7 8 9 10",
"output": "2"
},
{
"input": "10\n1 4 9... | 1,469,852,087 | 2,147,483,647 | Python 3 | OK | TESTS | 19 | 62 | 0 | import sys
n = int(input())
an = list(map(int, sys.stdin.readline().split()))
m = an[2] - an[0]
for i in range(3, n):
if an[i] - an[i-2] < m:
m = an[i] - an[i-2]
ans = m
for i in range(1, n):
if an[i] - an[i-1] > ans:
ans = an[i] - an[i-1]
print(ans)
| Title: Minimum Difficulty
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Mike is trying rock climbing but he is awful at it.
There are *n* holds on the wall, *i*-th hold is at height *a**i* off the ground. Besides, let the sequence *a**i* increase, that is, *a**i*<=<<=*a**i*<=+<=1 fo... | ```python
import sys
n = int(input())
an = list(map(int, sys.stdin.readline().split()))
m = an[2] - an[0]
for i in range(3, n):
if an[i] - an[i-2] < m:
m = an[i] - an[i-2]
ans = m
for i in range(1, n):
if an[i] - an[i-1] > ans:
ans = an[i] - an[i-1]
print(ans)
``` | 3 | |
682 | D | Alyona and Strings | PROGRAMMING | 1,900 | [
"dp",
"strings"
] | null | null | After returned from forest, Alyona started reading a book. She noticed strings *s* and *t*, lengths of which are *n* and *m* respectively. As usual, reading bored Alyona and she decided to pay her attention to strings *s* and *t*, which she considered very similar.
Alyona has her favourite positive integer *k* and bec... | In the first line of the input three integers *n*, *m*, *k* (1<=≤<=*n*,<=*m*<=≤<=1000, 1<=≤<=*k*<=≤<=10) are given — the length of the string *s*, the length of the string *t* and Alyona's favourite number respectively.
The second line of the input contains string *s*, consisting of lowercase English letters.
The thi... | In the only line print the only non-negative integer — the sum of the lengths of the strings in a desired sequence.
It is guaranteed, that at least one desired sequence exists. | [
"3 2 2\nabc\nab\n",
"9 12 4\nbbaaababb\nabbbabbaaaba\n"
] | [
"2\n",
"7\n"
] | The following image describes the answer for the second sample case: | 2,000 | [
{
"input": "3 2 2\nabc\nab",
"output": "2"
},
{
"input": "9 12 4\nbbaaababb\nabbbabbaaaba",
"output": "7"
},
{
"input": "11 11 4\naaababbabbb\nbbbaaaabaab",
"output": "7"
},
{
"input": "15 9 4\nababaaabbaaaabb\nbbaababbb",
"output": "8"
},
{
"input": "2 7 1\nbb\nb... | 1,678,469,658 | 2,958 | PyPy 3 | OK | TESTS | 81 | 374 | 34,918,400 | import sys, os, io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
def z_algorithm(w):
m = len(w)
z = [0] * m
z[0] = m
i, j = 1, 0
while i < m:
while i + j < m and w[j] == w[i + j]:
j += 1
z[i] = j
if not j:
i += 1
... | Title: Alyona and Strings
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
After returned from forest, Alyona started reading a book. She noticed strings *s* and *t*, lengths of which are *n* and *m* respectively. As usual, reading bored Alyona and she decided to pay her attention to string... | ```python
import sys, os, io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
def z_algorithm(w):
m = len(w)
z = [0] * m
z[0] = m
i, j = 1, 0
while i < m:
while i + j < m and w[j] == w[i + j]:
j += 1
z[i] = j
if not j:
i += 1
... | 3 | |
378 | A | Playing with Dice | PROGRAMMING | 800 | [
"brute force"
] | null | null | Two players are playing a game. First each of them writes an integer from 1 to 6, and then a dice is thrown. The player whose written number got closer to the number on the dice wins. If both payers have the same difference, it's a draw.
The first player wrote number *a*, the second player wrote number *b*. How many w... | The single line contains two integers *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=6) — the numbers written on the paper by the first and second player, correspondingly. | Print three integers: the number of ways to throw the dice at which the first player wins, the game ends with a draw or the second player wins, correspondingly. | [
"2 5\n",
"2 4\n"
] | [
"3 0 3\n",
"2 1 3\n"
] | The dice is a standard cube-shaped six-sided object with each side containing a number from 1 to 6, and where all numbers on all sides are distinct.
You can assume that number *a* is closer to number *x* than number *b*, if |*a* - *x*| < |*b* - *x*|. | 500 | [
{
"input": "2 5",
"output": "3 0 3"
},
{
"input": "2 4",
"output": "2 1 3"
},
{
"input": "5 3",
"output": "2 1 3"
},
{
"input": "1 6",
"output": "3 0 3"
},
{
"input": "5 1",
"output": "3 1 2"
},
{
"input": "6 3",
"output": "2 0 4"
},
{
"inp... | 1,577,688,161 | 2,147,483,647 | Python 3 | OK | TESTS | 38 | 109 | 307,200 | a,b=map(int,input().split());d=min(a,b);e=7-max(a,b);f=max(b,a)-min(a,b)-1;m=(([0,6,0] if a==b else [d+f//2,0,e+f//2] if f%2==0 else [d+f//2,1,e+f//2]));print(*(m if a<=b else m[::-1])) | Title: Playing with Dice
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Two players are playing a game. First each of them writes an integer from 1 to 6, and then a dice is thrown. The player whose written number got closer to the number on the dice wins. If both payers have the same diff... | ```python
a,b=map(int,input().split());d=min(a,b);e=7-max(a,b);f=max(b,a)-min(a,b)-1;m=(([0,6,0] if a==b else [d+f//2,0,e+f//2] if f%2==0 else [d+f//2,1,e+f//2]));print(*(m if a<=b else m[::-1]))
``` | 3 | |
733 | D | Kostya the Sculptor | PROGRAMMING | 1,600 | [
"data structures",
"hashing"
] | null | null | Kostya is a genial sculptor, he has an idea: to carve a marble sculpture in the shape of a sphere. Kostya has a friend Zahar who works at a career. Zahar knows about Kostya's idea and wants to present him a rectangular parallelepiped of marble from which he can carve the sphere.
Zahar has *n* stones which are rectang... | The first line contains the integer *n* (1<=≤<=*n*<=≤<=105).
*n* lines follow, in the *i*-th of which there are three integers *a**i*,<=*b**i* and *c**i* (1<=≤<=*a**i*,<=*b**i*,<=*c**i*<=≤<=109) — the lengths of edges of the *i*-th stone. Note, that two stones may have exactly the same sizes, but they still will be co... | In the first line print *k* (1<=≤<=*k*<=≤<=2) the number of stones which Zahar has chosen. In the second line print *k* distinct integers from 1 to *n* — the numbers of stones which Zahar needs to choose. Consider that stones are numbered from 1 to *n* in the order as they are given in the input data.
You can print th... | [
"6\n5 5 5\n3 2 4\n1 4 1\n2 1 3\n3 2 4\n3 3 4\n",
"7\n10 7 8\n5 10 3\n4 2 6\n5 5 5\n10 2 8\n4 2 1\n7 7 7\n"
] | [
"1\n1\n",
"2\n1 5\n"
] | In the first example we can connect the pairs of stones:
- 2 and 4, the size of the parallelepiped: 3 × 2 × 5, the radius of the inscribed sphere 1 - 2 and 5, the size of the parallelepiped: 3 × 2 × 8 or 6 × 2 × 4 or 3 × 4 × 4, the radius of the inscribed sphere 1, or 1, or 1.5 respectively. - 2 and 6, the size of ... | 2,000 | [
{
"input": "6\n5 5 5\n3 2 4\n1 4 1\n2 1 3\n3 2 4\n3 3 4",
"output": "1\n1"
},
{
"input": "7\n10 7 8\n5 10 3\n4 2 6\n5 5 5\n10 2 8\n4 2 1\n7 7 7",
"output": "2\n1 5"
},
{
"input": "1\n1 1 1",
"output": "1\n1"
},
{
"input": "2\n2 3 1\n2 2 3",
"output": "2\n2 1"
},
{
... | 1,540,919,495 | 2,147,483,647 | Python 3 | OK | TESTS | 104 | 1,481 | 54,272,000 | from itertools import combinations
def sides_pairs(box):
return set(tuple(sorted(side)) for side in combinations(box.dimensions, 2))
class Box:
def __init__(self, dimensions, ind):
self.dimensions = dimensions
self.ind = ind
class ChainHashSolver:
def __init__(self):
self.table... | Title: Kostya the Sculptor
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Kostya is a genial sculptor, he has an idea: to carve a marble sculpture in the shape of a sphere. Kostya has a friend Zahar who works at a career. Zahar knows about Kostya's idea and wants to present him a rectangu... | ```python
from itertools import combinations
def sides_pairs(box):
return set(tuple(sorted(side)) for side in combinations(box.dimensions, 2))
class Box:
def __init__(self, dimensions, ind):
self.dimensions = dimensions
self.ind = ind
class ChainHashSolver:
def __init__(self):
... | 3 | |
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,538,844,465 | 2,147,483,647 | Python 3 | OK | TESTS | 31 | 124 | 0 | def luchniki(a, b, c, d):
result = (a / b) / (1 - (1 - a / b) * (1 - c / d))
return '{0:.12f}'.format(result)
A, B, C, D = [int(i) for i in input().split()]
print(luchniki(A, B, C, D))
| 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
def luchniki(a, b, c, d):
result = (a / b) / (1 - (1 - a / b) * (1 - c / d))
return '{0:.12f}'.format(result)
A, B, C, D = [int(i) for i in input().split()]
print(luchniki(A, B, C, D))
``` | 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,653,055,908 | 2,147,483,647 | Python 3 | OK | TESTS | 81 | 92 | 0 | n = int(input())
a = [0, 0, 0]
for i in range(n):
temp = list(map(int, input().split()))
for j in range(3):
a[j] += temp[j]
print("YES") if a == [0, 0, 0] 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
n = int(input())
a = [0, 0, 0]
for i in range(n):
temp = list(map(int, input().split()))
for j in range(3):
a[j] += temp[j]
print("YES") if a == [0, 0, 0] else print("NO")
``` | 3.977 |
780 | A | Andryusha and Socks | PROGRAMMING | 800 | [
"implementation"
] | null | null | Andryusha is an orderly boy and likes to keep things in their place.
Today he faced a problem to put his socks in the wardrobe. He has *n* distinct pairs of socks which are initially in a bag. The pairs are numbered from 1 to *n*. Andryusha wants to put paired socks together and put them in the wardrobe. He takes the ... | The first line contains the single integer *n* (1<=≤<=*n*<=≤<=105) — the number of sock pairs.
The second line contains 2*n* integers *x*1,<=*x*2,<=...,<=*x*2*n* (1<=≤<=*x**i*<=≤<=*n*), which describe the order in which Andryusha took the socks from the bag. More precisely, *x**i* means that the *i*-th sock Andryusha ... | Print single integer — the maximum number of socks that were on the table at the same time. | [
"1\n1 1\n",
"3\n2 1 1 3 2 3\n"
] | [
"1\n",
"2\n"
] | In the first example Andryusha took a sock from the first pair and put it on the table. Then he took the next sock which is from the first pair as well, so he immediately puts both socks to the wardrobe. Thus, at most one sock was on the table at the same time.
In the second example Andryusha behaved as follows:
- ... | 500 | [
{
"input": "1\n1 1",
"output": "1"
},
{
"input": "3\n2 1 1 3 2 3",
"output": "2"
},
{
"input": "5\n5 1 3 2 4 3 1 2 4 5",
"output": "5"
},
{
"input": "10\n4 2 6 3 4 8 7 1 1 5 2 10 6 8 3 5 10 9 9 7",
"output": "6"
},
{
"input": "50\n30 47 31 38 37 50 36 43 9 23 2 2 ... | 1,488,705,440 | 140 | Python 3 | OK | TESTS | 56 | 218 | 18,227,200 | read = lambda: map(int, input().split())
n = int(input())
a = list(read())
was = [0] * (n + 1)
bal = ans = 0
for i in a:
if was[i]:
bal -= 1
else:
bal += 1
was[i] = 1
ans = max(ans, bal)
print(ans) | Title: Andryusha and Socks
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Andryusha is an orderly boy and likes to keep things in their place.
Today he faced a problem to put his socks in the wardrobe. He has *n* distinct pairs of socks which are initially in a bag. The pairs are numbere... | ```python
read = lambda: map(int, input().split())
n = int(input())
a = list(read())
was = [0] * (n + 1)
bal = ans = 0
for i in a:
if was[i]:
bal -= 1
else:
bal += 1
was[i] = 1
ans = max(ans, bal)
print(ans)
``` | 3 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.