contestId int64 0 1.01k | index stringclasses 57
values | name stringlengths 2 58 | type stringclasses 2
values | rating int64 0 3.5k | tags listlengths 0 11 | title stringclasses 522
values | time-limit stringclasses 8
values | memory-limit stringclasses 8
values | problem-description stringlengths 0 7.15k | input-specification stringlengths 0 2.05k | output-specification stringlengths 0 1.5k | demo-input listlengths 0 7 | demo-output listlengths 0 7 | note stringlengths 0 5.24k | points float64 0 425k | test_cases listlengths 0 402 | creationTimeSeconds int64 1.37B 1.7B | relativeTimeSeconds int64 8 2.15B | programmingLanguage stringclasses 3
values | verdict stringclasses 14
values | testset stringclasses 12
values | passedTestCount int64 0 1k | timeConsumedMillis int64 0 15k | memoryConsumedBytes int64 0 805M | code stringlengths 3 65.5k | prompt stringlengths 262 8.2k | response stringlengths 17 65.5k | score float64 -1 3.99 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
707 | A | Brain's Photos | PROGRAMMING | 800 | [
"implementation"
] | null | null | Small, but very brave, mouse Brain was not accepted to summer school of young villains. He was upset and decided to postpone his plans of taking over the world, but to become a photographer instead.
As you may know, the coolest photos are on the film (because you can specify the hashtag #film for such).
Brain took a ... | The first line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of photo pixel matrix rows and columns respectively.
Then *n* lines describing matrix rows follow. Each of them contains *m* space-separated characters describing colors of pixels in a row. Each character in the line i... | Print the "#Black&White" (without quotes), if the photo is black-and-white and "#Color" (without quotes), if it is colored, in the only line. | [
"2 2\nC M\nY Y\n",
"3 2\nW W\nW W\nB B\n",
"1 1\nW\n"
] | [
"#Color",
"#Black&White",
"#Black&White"
] | none | 500 | [
{
"input": "2 2\nC M\nY Y",
"output": "#Color"
},
{
"input": "3 2\nW W\nW W\nB B",
"output": "#Black&White"
},
{
"input": "1 1\nW",
"output": "#Black&White"
},
{
"input": "2 3\nW W W\nB G Y",
"output": "#Color"
},
{
"input": "1 1\nW",
"output": "#Black&White"
... | 1,675,185,566 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 31 | 0 | a,b=map(int,input().split())
d=False
for i in range(a):
l=list(map(str,input().split()))
if d==False and (("C" in l) or ("M" in l) or ("Y" in l)):
d=True
if d:print("#Color")
else:print("#Black&white") | Title: Brain's Photos
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Small, but very brave, mouse Brain was not accepted to summer school of young villains. He was upset and decided to postpone his plans of taking over the world, but to become a photographer instead.
As you may know, the... | ```python
a,b=map(int,input().split())
d=False
for i in range(a):
l=list(map(str,input().split()))
if d==False and (("C" in l) or ("M" in l) or ("Y" in l)):
d=True
if d:print("#Color")
else:print("#Black&white")
``` | 0 | |
812 | C | Sagheer and Nubian Market | PROGRAMMING | 1,500 | [
"binary search",
"sortings"
] | null | null | On his trip to Luxor and Aswan, Sagheer went to a Nubian market to buy some souvenirs for his friends and relatives. The market has some strange rules. It contains *n* different items numbered from 1 to *n*. The *i*-th item has base cost *a**i* Egyptian pounds. If Sagheer buys *k* items with indices *x*1,<=*x*2,<=...,<... | The first line contains two integers *n* and *S* (1<=≤<=*n*<=≤<=105 and 1<=≤<=*S*<=≤<=109) — the number of souvenirs in the market and Sagheer's budget.
The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=105) — the base costs of the souvenirs. | On a single line, print two integers *k*, *T* — the maximum number of souvenirs Sagheer can buy and the minimum total cost to buy these *k* souvenirs. | [
"3 11\n2 3 5\n",
"4 100\n1 2 5 6\n",
"1 7\n7\n"
] | [
"2 11\n",
"4 54\n",
"0 0\n"
] | In the first example, he cannot take the three items because they will cost him [5, 9, 14] with total cost 28. If he decides to take only two items, then the costs will be [4, 7, 11]. So he can afford the first and second items.
In the second example, he can buy all items as they will cost him [5, 10, 17, 22].
In the... | 1,500 | [
{
"input": "3 11\n2 3 5",
"output": "2 11"
},
{
"input": "4 100\n1 2 5 6",
"output": "4 54"
},
{
"input": "1 7\n7",
"output": "0 0"
},
{
"input": "1 7\n5",
"output": "1 6"
},
{
"input": "1 1\n1",
"output": "0 0"
},
{
"input": "4 33\n4 3 2 1",
"outp... | 1,591,808,911 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 6 | 156 | 1,331,200 | def bs(cost,l,r,s):
if(l+1==r):
return (l+r)//2
mid=(l+r)//2
if(sum(cost[mid][:mid])<s):
return bs(cost,mid,r,s)
else:
return bs(cost,l,mid,s)
n,s=map(int,input().split())
l=list(map(int,input().split()))
cost=[]
for i in range(n):
c=[]
for j in range(n):
c.append(l[j]+((j+1)*(i+1)))
c.sor... | Title: Sagheer and Nubian Market
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
On his trip to Luxor and Aswan, Sagheer went to a Nubian market to buy some souvenirs for his friends and relatives. The market has some strange rules. It contains *n* different items numbered from 1 to *n*. T... | ```python
def bs(cost,l,r,s):
if(l+1==r):
return (l+r)//2
mid=(l+r)//2
if(sum(cost[mid][:mid])<s):
return bs(cost,mid,r,s)
else:
return bs(cost,l,mid,s)
n,s=map(int,input().split())
l=list(map(int,input().split()))
cost=[]
for i in range(n):
c=[]
for j in range(n):
c.append(l[j]+((j+1)*(i+1)... | 0 | |
0 | none | none | none | 0 | [
"none"
] | null | null | Alice likes snow a lot! Unfortunately, this year's winter is already over, and she can't expect to have any more of it. Bob has thus bought her a gift — a large snow maker. He plans to make some amount of snow every day. On day *i* he will make a pile of snow of volume *V**i* and put it in her garden.
Each day, every ... | The first line contains a single integer *N* (1<=≤<=*N*<=≤<=105) — the number of days.
The second line contains *N* integers *V*1,<=*V*2,<=...,<=*V**N* (0<=≤<=*V**i*<=≤<=109), where *V**i* is the initial size of a snow pile made on the day *i*.
The third line contains *N* integers *T*1,<=*T*2,<=...,<=*T**N* (0<=≤<=*... | Output a single line with *N* integers, where the *i*-th integer represents the total volume of snow melted on day *i*. | [
"3\n10 10 5\n5 7 2\n",
"5\n30 25 20 15 10\n9 10 12 4 13\n"
] | [
"5 12 4\n",
"9 20 35 11 25\n"
] | In the first sample, Bob first makes a snow pile of volume 10, which melts to the size of 5 on the same day. On the second day, he makes another pile of size 10. Since it is a bit warmer than the day before, the first pile disappears completely while the second pile shrinks to 3. At the end of the second day, he has on... | 0 | [
{
"input": "3\n10 10 5\n5 7 2",
"output": "5 12 4"
},
{
"input": "5\n30 25 20 15 10\n9 10 12 4 13",
"output": "9 20 35 11 25"
},
{
"input": "4\n0 0 0 0\n1 2 3 4",
"output": "0 0 0 0"
},
{
"input": "10\n11 39 16 34 25 3 12 11 31 16\n10 0 4 9 8 9 7 8 9 2",
"output": "10 0 9... | 1,520,703,054 | 6,954 | Python 3 | TIME_LIMIT_EXCEEDED | PRETESTS | 3 | 1,000 | 15,462,400 | def main():
N = int(input())
V = tuple(map(int, input().split()))
T = tuple(map(int, input().split()))
snow = list(V)
ans = []
apnd = ans.append
for i, t in enumerate(T):
melted = 0
for j in range(i+1):
if snow[j] < t:
melted += snow[j]
... | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Alice likes snow a lot! Unfortunately, this year's winter is already over, and she can't expect to have any more of it. Bob has thus bought her a gift — a large snow maker. He plans to make some amount of snow every day. On day *i... | ```python
def main():
N = int(input())
V = tuple(map(int, input().split()))
T = tuple(map(int, input().split()))
snow = list(V)
ans = []
apnd = ans.append
for i, t in enumerate(T):
melted = 0
for j in range(i+1):
if snow[j] < t:
melted += snow[j]
... | 0 | |
792 | D | Paths in a Complete Binary Tree | PROGRAMMING | 1,900 | [
"bitmasks",
"trees"
] | null | null | *T* is a complete binary tree consisting of *n* vertices. It means that exactly one vertex is a root, and each vertex is either a leaf (and doesn't have children) or an inner node (and has exactly two children). All leaves of a complete binary tree have the same depth (distance from the root). So *n* is a number such t... | The first line contains two integer numbers *n* and *q* (1<=≤<=*n*<=≤<=1018, *q*<=≥<=1). *n* is such that *n*<=+<=1 is a power of 2.
The next 2*q* lines represent queries; each query consists of two consecutive lines. The first of these two lines contains *u**i* (1<=≤<=*u**i*<=≤<=*n*), the second contains non-empty st... | Print *q* numbers, *i*-th number must be the answer to the *i*-th query. | [
"15 2\n4\nUURL\n8\nLRLLLLLLLL\n"
] | [
"10\n5\n"
] | none | 0 | [
{
"input": "15 2\n4\nUURL\n8\nLRLLLLLLLL",
"output": "10\n5"
},
{
"input": "1 1\n1\nL",
"output": "1"
},
{
"input": "1 1\n1\nR",
"output": "1"
},
{
"input": "1 1\n1\nU",
"output": "1"
},
{
"input": "1 10\n1\nURLRLULUR\n1\nLRRRURULULL\n1\nLURURRUUUU\n1\nRRULLLRRUL\... | 1,598,457,352 | 2,147,483,647 | Python 3 | OK | TESTS | 17 | 998 | 512,000 | # ========== //\\ //|| ||====//||
# || // \\ || || // ||
# || //====\\ || || // ||
# || // \\ || || // ||
# ========== // \\ ======== ||//====||
# code
def main():
n, q = map(int, input().split())
... | Title: Paths in a Complete Binary Tree
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
*T* is a complete binary tree consisting of *n* vertices. It means that exactly one vertex is a root, and each vertex is either a leaf (and doesn't have children) or an inner node (and has exactly two ch... | ```python
# ========== //\\ //|| ||====//||
# || // \\ || || // ||
# || //====\\ || || // ||
# || // \\ || || // ||
# ========== // \\ ======== ||//====||
# code
def main():
n, q = map(int, input().sp... | 3 | |
999 | B | Reversing Encryption | PROGRAMMING | 900 | [
"implementation"
] | null | null | A string $s$ of length $n$ can be encrypted by the following algorithm:
- iterate over all divisors of $n$ in decreasing order (i.e. from $n$ to $1$), - for each divisor $d$, reverse the substring $s[1 \dots d]$ (i.e. the substring which starts at position $1$ and ends at position $d$).
For example, the above algor... | The first line of input consists of a single integer $n$ ($1 \le n \le 100$) — the length of the string $t$. The second line of input consists of the string $t$. The length of $t$ is $n$, and it consists only of lowercase Latin letters. | Print a string $s$ such that the above algorithm results in $t$. | [
"10\nrocesfedoc\n",
"16\nplmaetwoxesisiht\n",
"1\nz\n"
] | [
"codeforces\n",
"thisisexampletwo\n",
"z\n"
] | The first example is described in the problem statement. | 0 | [
{
"input": "10\nrocesfedoc",
"output": "codeforces"
},
{
"input": "16\nplmaetwoxesisiht",
"output": "thisisexampletwo"
},
{
"input": "1\nz",
"output": "z"
},
{
"input": "2\nir",
"output": "ri"
},
{
"input": "3\nilj",
"output": "jli"
},
{
"input": "4\nj... | 1,618,499,877 | 2,147,483,647 | PyPy 3 | OK | TESTS | 20 | 93 | 0 | n = int(input())
s = input()
for d in range(1, n+1):
if not n % d:
s = s[d-1::-1] + s[d:]
print(s)
| Title: Reversing Encryption
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A string $s$ of length $n$ can be encrypted by the following algorithm:
- iterate over all divisors of $n$ in decreasing order (i.e. from $n$ to $1$), - for each divisor $d$, reverse the substring $s[1 \dots d]$... | ```python
n = int(input())
s = input()
for d in range(1, n+1):
if not n % d:
s = s[d-1::-1] + s[d:]
print(s)
``` | 3 | |
615 | A | Bulbs | PROGRAMMING | 800 | [
"implementation"
] | null | null | Vasya wants to turn on Christmas lights consisting of *m* bulbs. Initially, all bulbs are turned off. There are *n* buttons, each of them is connected to some set of bulbs. Vasya can press any of these buttons. When the button is pressed, it turns on all the bulbs it's connected to. Can Vasya light up all the bulbs?
I... | The first line of the input contains integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100) — the number of buttons and the number of bulbs respectively.
Each of the next *n* lines contains *x**i* (0<=≤<=*x**i*<=≤<=*m*) — the number of bulbs that are turned on by the *i*-th button, and then *x**i* numbers *y**ij* (1<=≤<=*y**... | If it's possible to turn on all *m* bulbs print "YES", otherwise print "NO". | [
"3 4\n2 1 4\n3 1 3 1\n1 2\n",
"3 3\n1 1\n1 2\n1 1\n"
] | [
"YES\n",
"NO\n"
] | In the first sample you can press each button once and turn on all the bulbs. In the 2 sample it is impossible to turn on the 3-rd lamp. | 500 | [
{
"input": "3 4\n2 1 4\n3 1 3 1\n1 2",
"output": "YES"
},
{
"input": "3 3\n1 1\n1 2\n1 1",
"output": "NO"
},
{
"input": "3 4\n1 1\n1 2\n1 3",
"output": "NO"
},
{
"input": "1 5\n5 1 2 3 4 5",
"output": "YES"
},
{
"input": "1 5\n5 4 4 1 2 3",
"output": "NO"
},... | 1,666,086,110 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 6 | 31 | 0 | n,m = map(int, input().split())
a = [0 for i in range(m)]
s = 0
for i in range(n):
for j in input().split():
a[int(j)-1] = 1-a[int(j)-1]
if sum(a) == m:
print("YES")
s = 1
break
if s == 0:
print("NO") | Title: Bulbs
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya wants to turn on Christmas lights consisting of *m* bulbs. Initially, all bulbs are turned off. There are *n* buttons, each of them is connected to some set of bulbs. Vasya can press any of these buttons. When the button is... | ```python
n,m = map(int, input().split())
a = [0 for i in range(m)]
s = 0
for i in range(n):
for j in input().split():
a[int(j)-1] = 1-a[int(j)-1]
if sum(a) == m:
print("YES")
s = 1
break
if s == 0:
print("NO")
``` | 0 | |
919 | A | Supermarket | PROGRAMMING | 800 | [
"brute force",
"greedy",
"implementation"
] | null | null | We often go to supermarkets to buy some fruits or vegetables, and on the tag there prints the price for a kilo. But in some supermarkets, when asked how much the items are, the clerk will say that $a$ yuan for $b$ kilos (You don't need to care about what "yuan" is), the same as $a/b$ yuan for a kilo.
Now imagine you'd... | The first line contains two positive integers $n$ and $m$ ($1 \leq n \leq 5\,000$, $1 \leq m \leq 100$), denoting that there are $n$ supermarkets and you want to buy $m$ kilos of apples.
The following $n$ lines describe the information of the supermarkets. Each line contains two positive integers $a, b$ ($1 \leq a, b ... | The only line, denoting the minimum cost for $m$ kilos of apples. Please make sure that the absolute or relative error between your answer and the correct answer won't exceed $10^{-6}$.
Formally, let your answer be $x$, and the jury's answer be $y$. Your answer is considered correct if $\frac{|x - y|}{\max{(1, |y|)}} ... | [
"3 5\n1 2\n3 4\n1 3\n",
"2 1\n99 100\n98 99\n"
] | [
"1.66666667\n",
"0.98989899\n"
] | In the first sample, you are supposed to buy $5$ kilos of apples in supermarket $3$. The cost is $5/3$ yuan.
In the second sample, you are supposed to buy $1$ kilo of apples in supermarket $2$. The cost is $98/99$ yuan. | 500 | [
{
"input": "3 5\n1 2\n3 4\n1 3",
"output": "1.66666667"
},
{
"input": "2 1\n99 100\n98 99",
"output": "0.98989899"
},
{
"input": "50 37\n78 49\n96 4\n86 62\n28 4\n19 2\n79 43\n79 92\n95 35\n33 60\n54 84\n90 25\n2 25\n53 21\n86 52\n72 25\n6 78\n41 46\n3 68\n42 89\n33 35\n57 43\n99 45\n1 8... | 1,666,331,134 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 15 | 0 | n,m=map(int,input().split())
min=10000000
for i in range(n):
a,b=map(int,input().split())
if m/a*b<min:
min==m/a*b
print(min) | Title: Supermarket
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
We often go to supermarkets to buy some fruits or vegetables, and on the tag there prints the price for a kilo. But in some supermarkets, when asked how much the items are, the clerk will say that $a$ yuan for $b$ kilos (Yo... | ```python
n,m=map(int,input().split())
min=10000000
for i in range(n):
a,b=map(int,input().split())
if m/a*b<min:
min==m/a*b
print(min)
``` | 0 | |
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,504,877,871 | 2,147,483,647 | Python 3 | OK | TESTS | 36 | 62 | 102,400 | n,m = map(int, input().split())
ans = 0
for i in range(n):
mat = list(map(int, input().split()))
for j in range(m):
ans+=min(1,(mat[2*j]+mat[2*j+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())
ans = 0
for i in range(n):
mat = list(map(int, input().split()))
for j in range(m):
ans+=min(1,(mat[2*j]+mat[2*j+1]))
print(ans)
``` | 3 | |
805 | A | Fake NP | PROGRAMMING | 1,000 | [
"greedy",
"math"
] | null | null | Tavak and Seyyed are good friends. Seyyed is very funny and he told Tavak to solve the following problem instead of longest-path.
You are given *l* and *r*. For all integers from *l* to *r*, inclusive, we wrote down all of their integer divisors except 1. Find the integer that we wrote down the maximum number of times... | The first line contains two integers *l* and *r* (2<=≤<=*l*<=≤<=*r*<=≤<=109). | Print single integer, the integer that appears maximum number of times in the divisors.
If there are multiple answers, print any of them. | [
"19 29\n",
"3 6\n"
] | [
"2\n",
"3\n"
] | Definition of a divisor: [https://www.mathsisfun.com/definitions/divisor-of-an-integer-.html](https://www.mathsisfun.com/definitions/divisor-of-an-integer-.html)
The first example: from 19 to 29 these numbers are divisible by 2: {20, 22, 24, 26, 28}.
The second example: from 3 to 6 these numbers are divisible by 3: {... | 500 | [
{
"input": "19 29",
"output": "2"
},
{
"input": "3 6",
"output": "2"
},
{
"input": "39 91",
"output": "2"
},
{
"input": "76 134",
"output": "2"
},
{
"input": "93 95",
"output": "2"
},
{
"input": "17 35",
"output": "2"
},
{
"input": "94 95",... | 1,596,561,931 | 2,147,483,647 | Python 3 | OK | TESTS | 93 | 109 | 6,656,000 |
x, y = map(int, input().split())
if(y==x):
print(x)
else:
print(int(2)) | Title: Fake NP
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Tavak and Seyyed are good friends. Seyyed is very funny and he told Tavak to solve the following problem instead of longest-path.
You are given *l* and *r*. For all integers from *l* to *r*, inclusive, we wrote down all of the... | ```python
x, y = map(int, input().split())
if(y==x):
print(x)
else:
print(int(2))
``` | 3 | |
215 | A | Bicycle Chain | PROGRAMMING | 900 | [
"brute force",
"implementation"
] | null | null | Vasya's bicycle chain drive consists of two parts: *n* stars are attached to the pedal axle, *m* stars are attached to the rear wheel axle. The chain helps to rotate the rear wheel by transmitting the pedal rotation.
We know that the *i*-th star on the pedal axle has *a**i* (0<=<<=*a*1<=<<=*a*2<=<<=...<=<<... | The first input line contains integer *n* (1<=≤<=*n*<=≤<=50) — the number of stars on the bicycle's pedal axle. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=104) in the order of strict increasing.
The third input line contains integer *m* (1<=≤<=*m*<=≤<=50) — the number of stars o... | Print the number of "integer" gears with the maximum ratio among all "integer" gears. | [
"2\n4 5\n3\n12 13 15\n",
"4\n1 2 3 4\n5\n10 11 12 13 14\n"
] | [
"2\n",
"1\n"
] | In the first sample the maximum "integer" gear ratio equals 3. There are two gears that have such gear ratio. For one of them *a*<sub class="lower-index">1</sub> = 4, *b*<sub class="lower-index">1</sub> = 12, and for the other *a*<sub class="lower-index">2</sub> = 5, *b*<sub class="lower-index">3</sub> = 15. | 500 | [
{
"input": "2\n4 5\n3\n12 13 15",
"output": "2"
},
{
"input": "4\n1 2 3 4\n5\n10 11 12 13 14",
"output": "1"
},
{
"input": "1\n1\n1\n1",
"output": "1"
},
{
"input": "2\n1 2\n1\n1",
"output": "1"
},
{
"input": "1\n1\n2\n1 2",
"output": "1"
},
{
"input":... | 1,586,719,375 | 2,147,483,647 | PyPy 3 | OK | TESTS | 57 | 280 | 1,228,800 | pedal = int(input())
a = list(map(int, input().split()))
wheel = int(input())
b = list(map(int, input().split()))
ratio = []
mx = 0
for aj in a:
for bj in b:
if bj%aj == 0:
ratio.append(bj//aj)
if ratio[-1]>mx:
mx = ratio[-1]
print(ratio.count(mx)) | Title: Bicycle Chain
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya's bicycle chain drive consists of two parts: *n* stars are attached to the pedal axle, *m* stars are attached to the rear wheel axle. The chain helps to rotate the rear wheel by transmitting the pedal rotation.
We ... | ```python
pedal = int(input())
a = list(map(int, input().split()))
wheel = int(input())
b = list(map(int, input().split()))
ratio = []
mx = 0
for aj in a:
for bj in b:
if bj%aj == 0:
ratio.append(bj//aj)
if ratio[-1]>mx:
mx = ratio[-1]
print(ratio.count(mx))
``` | 3 | |
710 | A | King Moves | PROGRAMMING | 800 | [
"implementation"
] | null | null | The only king stands on the standard chess board. You are given his position in format "cd", where *c* is the column from 'a' to 'h' and *d* is the row from '1' to '8'. Find the number of moves permitted for the king.
Check the king's moves here [https://en.wikipedia.org/wiki/King_(chess)](https://en.wikipedia.org/wik... | The only line contains the king's position in the format "cd", where 'c' is the column from 'a' to 'h' and 'd' is the row from '1' to '8'. | Print the only integer *x* — the number of moves permitted for the king. | [
"e4\n"
] | [
"8\n"
] | none | 0 | [
{
"input": "e4",
"output": "8"
},
{
"input": "a1",
"output": "3"
},
{
"input": "h8",
"output": "3"
},
{
"input": "a4",
"output": "5"
},
{
"input": "g7",
"output": "8"
},
{
"input": "e1",
"output": "5"
},
{
"input": "b2",
"output": "8"
... | 1,557,038,631 | 2,147,483,647 | Python 3 | OK | TESTS | 24 | 109 | 0 | a = input()
x = a[0]
y = a[1]
if a == 'a1' or a=='a8' or a=='h1' or a=='h8':
print(3)
elif x =='a' or x == 'h' or y == '1' or y=='8':
print(5)
else:
print(8) | Title: King Moves
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The only king stands on the standard chess board. You are given his position in format "cd", where *c* is the column from 'a' to 'h' and *d* is the row from '1' to '8'. Find the number of moves permitted for the king.
Check... | ```python
a = input()
x = a[0]
y = a[1]
if a == 'a1' or a=='a8' or a=='h1' or a=='h8':
print(3)
elif x =='a' or x == 'h' or y == '1' or y=='8':
print(5)
else:
print(8)
``` | 3 | |
799 | A | Carrot Cakes | PROGRAMMING | 1,100 | [
"brute force",
"implementation"
] | null | null | In some game by Playrix it takes *t* minutes for an oven to bake *k* carrot cakes, all cakes are ready at the same moment *t* minutes after they started baking. Arkady needs at least *n* cakes to complete a task, but he currently don't have any. However, he has infinitely many ingredients and one oven. Moreover, Arkady... | The only line contains four integers *n*, *t*, *k*, *d* (1<=≤<=*n*,<=*t*,<=*k*,<=*d*<=≤<=1<=000) — the number of cakes needed, the time needed for one oven to bake *k* cakes, the number of cakes baked at the same time, the time needed to build the second oven. | If it is reasonable to build the second oven, print "YES". Otherwise print "NO". | [
"8 6 4 5\n",
"8 6 4 6\n",
"10 3 11 4\n",
"4 2 1 4\n"
] | [
"YES\n",
"NO\n",
"NO\n",
"YES\n"
] | In the first example it is possible to get 8 cakes in 12 minutes using one oven. The second oven can be built in 5 minutes, so after 6 minutes the first oven bakes 4 cakes, the second oven bakes 4 more ovens after 11 minutes. Thus, it is reasonable to build the second oven.
In the second example it doesn't matter whe... | 500 | [
{
"input": "8 6 4 5",
"output": "YES"
},
{
"input": "8 6 4 6",
"output": "NO"
},
{
"input": "10 3 11 4",
"output": "NO"
},
{
"input": "4 2 1 4",
"output": "YES"
},
{
"input": "28 17 16 26",
"output": "NO"
},
{
"input": "60 69 9 438",
"output": "NO"... | 1,697,882,079 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 31 | 0 | n,t,k,d =map(int,input().split())
time=d
cakes = 0
while cakes<n:
cakes+=2*k
time+=t
# print(time)
if k>n:
print("NO")
else:
if n//k*t<=time:
print("NO")
else:
print("YES") | Title: Carrot Cakes
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In some game by Playrix it takes *t* minutes for an oven to bake *k* carrot cakes, all cakes are ready at the same moment *t* minutes after they started baking. Arkady needs at least *n* cakes to complete a task, but he cu... | ```python
n,t,k,d =map(int,input().split())
time=d
cakes = 0
while cakes<n:
cakes+=2*k
time+=t
# print(time)
if k>n:
print("NO")
else:
if n//k*t<=time:
print("NO")
else:
print("YES")
``` | 0 | |
387 | B | George and Round | PROGRAMMING | 1,200 | [
"brute force",
"greedy",
"two pointers"
] | null | null | George decided to prepare a Codesecrof round, so he has prepared *m* problems for the round. Let's number the problems with integers 1 through *m*. George estimates the *i*-th problem's complexity by integer *b**i*.
To make the round good, he needs to put at least *n* problems there. Besides, he needs to have at least... | The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=3000) — the minimal number of problems in a good round and the number of problems George's prepared. The second line contains space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a*1<=<<=*a*2<=<<=...<=<<=*a**n*<=≤<=106) — the requirem... | Print a single integer — the answer to the problem. | [
"3 5\n1 2 3\n1 2 2 3 3\n",
"3 5\n1 2 3\n1 1 1 1 1\n",
"3 1\n2 3 4\n1\n"
] | [
"0\n",
"2\n",
"3\n"
] | In the first sample the set of the prepared problems meets the requirements for a good round.
In the second sample, it is enough to come up with and prepare two problems with complexities 2 and 3 to get a good round.
In the third sample it is very easy to get a good round if come up with and prepare extra problems wi... | 1,000 | [
{
"input": "3 5\n1 2 3\n1 2 2 3 3",
"output": "0"
},
{
"input": "3 5\n1 2 3\n1 1 1 1 1",
"output": "2"
},
{
"input": "3 1\n2 3 4\n1",
"output": "3"
},
{
"input": "29 100\n20 32 41 67 72 155 331 382 399 412 465 470 484 511 515 529 616 637 679 715 733 763 826 843 862 903 925 97... | 1,623,683,424 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 3 | 77 | 1,228,800 | n, m = list(map(int, input().split()))
A = list(map(int, input().split()))
B = sorted(list(set(list(map(int, input().split())))))
counter = 0
for i in range(n):
b = False
for j in range(len(B)):
if B[j] >= A[i]:
b = True
if not b:
counter += 1
print(counter)
| Title: George and Round
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
George decided to prepare a Codesecrof round, so he has prepared *m* problems for the round. Let's number the problems with integers 1 through *m*. George estimates the *i*-th problem's complexity by integer *b**i*.
T... | ```python
n, m = list(map(int, input().split()))
A = list(map(int, input().split()))
B = sorted(list(set(list(map(int, input().split())))))
counter = 0
for i in range(n):
b = False
for j in range(len(B)):
if B[j] >= A[i]:
b = True
if not b:
counter += 1
print(count... | 0 | |
0 | none | none | none | 0 | [
"none"
] | null | null | Alice likes snow a lot! Unfortunately, this year's winter is already over, and she can't expect to have any more of it. Bob has thus bought her a gift — a large snow maker. He plans to make some amount of snow every day. On day *i* he will make a pile of snow of volume *V**i* and put it in her garden.
Each day, every ... | The first line contains a single integer *N* (1<=≤<=*N*<=≤<=105) — the number of days.
The second line contains *N* integers *V*1,<=*V*2,<=...,<=*V**N* (0<=≤<=*V**i*<=≤<=109), where *V**i* is the initial size of a snow pile made on the day *i*.
The third line contains *N* integers *T*1,<=*T*2,<=...,<=*T**N* (0<=≤<=*... | Output a single line with *N* integers, where the *i*-th integer represents the total volume of snow melted on day *i*. | [
"3\n10 10 5\n5 7 2\n",
"5\n30 25 20 15 10\n9 10 12 4 13\n"
] | [
"5 12 4\n",
"9 20 35 11 25\n"
] | In the first sample, Bob first makes a snow pile of volume 10, which melts to the size of 5 on the same day. On the second day, he makes another pile of size 10. Since it is a bit warmer than the day before, the first pile disappears completely while the second pile shrinks to 3. At the end of the second day, he has on... | 0 | [
{
"input": "3\n10 10 5\n5 7 2",
"output": "5 12 4"
},
{
"input": "5\n30 25 20 15 10\n9 10 12 4 13",
"output": "9 20 35 11 25"
},
{
"input": "4\n0 0 0 0\n1 2 3 4",
"output": "0 0 0 0"
},
{
"input": "10\n11 39 16 34 25 3 12 11 31 16\n10 0 4 9 8 9 7 8 9 2",
"output": "10 0 9... | 1,520,699,173 | 3,073 | PyPy 3 | TIME_LIMIT_EXCEEDED | PRETESTS | 3 | 1,000 | 45,363,200 | import sys
import itertools as it
n = int(sys.stdin.readline())
V = list(map(int,sys.stdin.readline().split()))
T = list(map(int,sys.stdin.readline().split()))
V = dict(zip(range(n),V))
for i in range(n):
MS=0
k1=-1
t=True
for j in sorted(V.keys()):
if j > i: break
M = min(T[i],V[j])
V[j] -= M
... | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Alice likes snow a lot! Unfortunately, this year's winter is already over, and she can't expect to have any more of it. Bob has thus bought her a gift — a large snow maker. He plans to make some amount of snow every day. On day *i... | ```python
import sys
import itertools as it
n = int(sys.stdin.readline())
V = list(map(int,sys.stdin.readline().split()))
T = list(map(int,sys.stdin.readline().split()))
V = dict(zip(range(n),V))
for i in range(n):
MS=0
k1=-1
t=True
for j in sorted(V.keys()):
if j > i: break
M = min(T[i],V[j])
V[... | 0 | |
519 | A | A and B and Chess | PROGRAMMING | 900 | [
"implementation"
] | null | null | A and B are preparing themselves for programming contests.
To train their logical thinking and solve problems better, A and B decided to play chess. During the game A wondered whose position is now stronger.
For each chess piece we know its weight:
- the queen's weight is 9, - the rook's weight is 5, - the bisho... | The input contains eight lines, eight characters each — the board's description.
The white pieces on the board are marked with uppercase letters, the black pieces are marked with lowercase letters.
The white pieces are denoted as follows: the queen is represented is 'Q', the rook — as 'R', the bishop — as'B', the kni... | Print "White" (without quotes) if the weight of the position of the white pieces is more than the weight of the position of the black pieces, print "Black" if the weight of the black pieces is more than the weight of the white pieces and print "Draw" if the weights of the white and black pieces are equal. | [
"...QK...\n........\n........\n........\n........\n........\n........\n...rk...\n",
"rnbqkbnr\npppppppp\n........\n........\n........\n........\nPPPPPPPP\nRNBQKBNR\n",
"rppppppr\n...k....\n........\n........\n........\n........\nK...Q...\n........\n"
] | [
"White\n",
"Draw\n",
"Black\n"
] | In the first test sample the weight of the position of the white pieces equals to 9, the weight of the position of the black pieces equals 5.
In the second test sample the weights of the positions of the black and the white pieces are equal to 39.
In the third test sample the weight of the position of the white piece... | 500 | [
{
"input": "rnbqkbnr\npppppppp\n........\n........\n........\n........\nPPPPPPPP\nRNBQKBNR",
"output": "Draw"
},
{
"input": "....bQ.K\n.B......\n.....P..\n........\n........\n........\n...N.P..\n.....R..",
"output": "White"
},
{
"input": "b....p..\nR.......\n.pP...b.\npp......\nq.PPNpPR\... | 1,673,893,905 | 2,147,483,647 | Python 3 | OK | TESTS | 65 | 46 | 0 | d = {"Q": 9, "R": 5, "B": 3, "N": 3, "P": 1, "K": 0, "q": -9, "r": -5, "b": -3, "n": -3, "p": -1, "k": 0, ".": 0}
ans = 0
for i in range(8):
lst = input()
for i in lst:
ans += d[i]
if ans > 0:
print("White")
elif ans < 0:
print("Black")
else:
print("Draw") | Title: A and B and Chess
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A and B are preparing themselves for programming contests.
To train their logical thinking and solve problems better, A and B decided to play chess. During the game A wondered whose position is now stronger.
For eac... | ```python
d = {"Q": 9, "R": 5, "B": 3, "N": 3, "P": 1, "K": 0, "q": -9, "r": -5, "b": -3, "n": -3, "p": -1, "k": 0, ".": 0}
ans = 0
for i in range(8):
lst = input()
for i in lst:
ans += d[i]
if ans > 0:
print("White")
elif ans < 0:
print("Black")
else:
print("Draw")
``` | 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,634,738,459 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 122 | 4,300,800 | a = input()
t = 0
c = 0
for ch in a:
if ch.islower():
t += 1
else:
c += 1
if t < c:
a = a.upper()
else:
a = a.lower()
print(a)
| Title: Word
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it ei... | ```python
a = input()
t = 0
c = 0
for ch in a:
if ch.islower():
t += 1
else:
c += 1
if t < c:
a = a.upper()
else:
a = a.lower()
print(a)
``` | 3.961489 |
976 | A | Minimum Binary Number | PROGRAMMING | 800 | [
"implementation"
] | null | null | String can be called correct if it consists of characters "0" and "1" and there are no redundant leading zeroes. Here are some examples: "0", "10", "1001".
You are given a correct string *s*.
You can perform two different operations on this string:
1. swap any pair of adjacent characters (for example, "101" "110"... | The first line contains integer number *n* (1<=≤<=*n*<=≤<=100) — the length of string *s*.
The second line contains the string *s* consisting of characters "0" and "1". It is guaranteed that the string *s* is correct. | Print one string — the minimum correct string that you can obtain from the given one. | [
"4\n1001\n",
"1\n1\n"
] | [
"100\n",
"1\n"
] | In the first example you can obtain the answer by the following sequence of operations: "1001" <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> "1010" <img align="middle" class="tex-formula" src="ht... | 0 | [
{
"input": "4\n1001",
"output": "100"
},
{
"input": "1\n1",
"output": "1"
},
{
"input": "100\n1110111100001111011111111010110011111111011110000111101101011100110110001011000000101010110101011100",
"output": "1000000000000000000000000000000000000000"
},
{
"input": "100\n100000... | 1,629,885,144 | 2,147,483,647 | Python 3 | OK | TESTS | 14 | 62 | 6,758,400 | a=input()
a=input()
if int(a):
print('1'+'0'*a.count('0'))
else:
print(0) | Title: Minimum Binary Number
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
String can be called correct if it consists of characters "0" and "1" and there are no redundant leading zeroes. Here are some examples: "0", "10", "1001".
You are given a correct string *s*.
You can perform two... | ```python
a=input()
a=input()
if int(a):
print('1'+'0'*a.count('0'))
else:
print(0)
``` | 3 | |
558 | A | Lala Land and Apple Trees | PROGRAMMING | 1,100 | [
"brute force",
"implementation",
"sortings"
] | null | null | Amr lives in Lala Land. Lala Land is a very beautiful country that is located on a coordinate line. Lala Land is famous with its apple trees growing everywhere.
Lala Land has exactly *n* apple trees. Tree number *i* is located in a position *x**i* and has *a**i* apples growing on it. Amr wants to collect apples from t... | The first line contains one number *n* (1<=≤<=*n*<=≤<=100), the number of apple trees in Lala Land.
The following *n* lines contains two integers each *x**i*, *a**i* (<=-<=105<=≤<=*x**i*<=≤<=105, *x**i*<=≠<=0, 1<=≤<=*a**i*<=≤<=105), representing the position of the *i*-th tree and number of apples on it.
It's guarant... | Output the maximum number of apples Amr can collect. | [
"2\n-1 5\n1 5\n",
"3\n-2 2\n1 4\n-1 3\n",
"3\n1 9\n3 5\n7 10\n"
] | [
"10",
"9",
"9"
] | In the first sample test it doesn't matter if Amr chose at first to go left or right. In both cases he'll get all the apples.
In the second sample test the optimal solution is to go left to *x* = - 1, collect apples from there, then the direction will be reversed, Amr has to go to *x* = 1, collect apples from there, ... | 500 | [
{
"input": "2\n-1 5\n1 5",
"output": "10"
},
{
"input": "3\n-2 2\n1 4\n-1 3",
"output": "9"
},
{
"input": "3\n1 9\n3 5\n7 10",
"output": "9"
},
{
"input": "1\n1 1",
"output": "1"
},
{
"input": "4\n10000 100000\n-1000 100000\n-2 100000\n-1 100000",
"output": "3... | 1,585,686,572 | 2,147,483,647 | PyPy 3 | OK | TESTS | 46 | 156 | 0 | def takeOne(elem):
return elem[0]
num = int(input())
p = 0
n = 0
t = 0
trees = []
for i in range(num):
tree = [int(x) for x in input().split()]
trees.append(tree)
if tree[0] > 0:
p += 1
else:
n += 1
t += tree[1]
trees.sort(key=takeOne)
if p < n - 1:
for i in range(n - 1 - p):
t -= trees[i][1]... | Title: Lala Land and Apple Trees
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Amr lives in Lala Land. Lala Land is a very beautiful country that is located on a coordinate line. Lala Land is famous with its apple trees growing everywhere.
Lala Land has exactly *n* apple trees. Tree num... | ```python
def takeOne(elem):
return elem[0]
num = int(input())
p = 0
n = 0
t = 0
trees = []
for i in range(num):
tree = [int(x) for x in input().split()]
trees.append(tree)
if tree[0] > 0:
p += 1
else:
n += 1
t += tree[1]
trees.sort(key=takeOne)
if p < n - 1:
for i in range(n - 1 - p):
t -= t... | 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,691,303,599 | 2,147,483,647 | Python 3 | OK | TESTS | 81 | 92 | 0 | n = int(input())
vec = 0
x = y = z = 0
while n > 0:
n -= 1
vec = input().split()
x = x + int(vec[0])
y = y + int(vec[1])
z = z + int(vec[2])
if x == y == z == 0: print("YES")
else: print("NO") | Title: Young Physicist
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. S... | ```python
n = int(input())
vec = 0
x = y = z = 0
while n > 0:
n -= 1
vec = input().split()
x = x + int(vec[0])
y = y + int(vec[1])
z = z + int(vec[2])
if x == y == z == 0: print("YES")
else: print("NO")
``` | 3.977 |
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,573,425,046 | 2,147,483,647 | Python 3 | OK | TESTS | 27 | 216 | 0 | import math as m
a,b,c=map(int,input().split())
e1,e2,e3=m.sqrt((a*c)/b),m.sqrt((a*b)/c),m.sqrt((b*c)/a)
print(int(4*(e1+e2+e3)))
| 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 as m
a,b,c=map(int,input().split())
e1,e2,e3=m.sqrt((a*c)/b),m.sqrt((a*b)/c),m.sqrt((b*c)/a)
print(int(4*(e1+e2+e3)))
``` | 3 | |
405 | A | Gravity Flip | PROGRAMMING | 900 | [
"greedy",
"implementation",
"sortings"
] | null | null | Little Chris is bored during his physics lessons (too easy), so he has built a toy box to keep himself occupied. The box is special, since it has the ability to change gravity.
There are *n* columns of toy cubes in the box arranged in a line. The *i*-th column contains *a**i* cubes. At first, the gravity in the box is... | The first line of input contains an integer *n* (1<=≤<=*n*<=≤<=100), the number of the columns in the box. The next line contains *n* space-separated integer numbers. The *i*-th number *a**i* (1<=≤<=*a**i*<=≤<=100) denotes the number of cubes in the *i*-th column. | Output *n* integer numbers separated by spaces, where the *i*-th number is the amount of cubes in the *i*-th column after the gravity switch. | [
"4\n3 2 1 2\n",
"3\n2 3 8\n"
] | [
"1 2 2 3 \n",
"2 3 8 \n"
] | The first example case is shown on the figure. The top cube of the first column falls to the top of the last column; the top cube of the second column falls to the top of the third column; the middle cube of the first column falls to the top of the second column.
In the second example case the gravity switch does not ... | 500 | [
{
"input": "4\n3 2 1 2",
"output": "1 2 2 3 "
},
{
"input": "3\n2 3 8",
"output": "2 3 8 "
},
{
"input": "5\n2 1 2 1 2",
"output": "1 1 2 2 2 "
},
{
"input": "1\n1",
"output": "1 "
},
{
"input": "2\n4 3",
"output": "3 4 "
},
{
"input": "6\n100 40 60 20... | 1,693,584,839 | 2,147,483,647 | Python 3 | OK | TESTS | 32 | 46 | 0 | if __name__ == '__main__':
n = int(input())
toys = input()
toys = toys.split()
toys = [int(x) for x in toys]
sorted_toys = sorted(toys)
print(*sorted_toys, sep=' ')
| Title: Gravity Flip
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little Chris is bored during his physics lessons (too easy), so he has built a toy box to keep himself occupied. The box is special, since it has the ability to change gravity.
There are *n* columns of toy cubes in the bo... | ```python
if __name__ == '__main__':
n = int(input())
toys = input()
toys = toys.split()
toys = [int(x) for x in toys]
sorted_toys = sorted(toys)
print(*sorted_toys, sep=' ')
``` | 3 | |
365 | A | Good Number | PROGRAMMING | 1,100 | [
"implementation"
] | null | null | Let's call a number *k*-good if it contains all digits not exceeding *k* (0,<=...,<=*k*). You've got a number *k* and an array *a* containing *n* numbers. Find out how many *k*-good numbers are in *a* (count each number every time it occurs in array *a*). | The first line contains integers *n* and *k* (1<=≤<=*n*<=≤<=100, 0<=≤<=*k*<=≤<=9). The *i*-th of the following *n* lines contains integer *a**i* without leading zeroes (1<=≤<=*a**i*<=≤<=109). | Print a single integer — the number of *k*-good numbers in *a*. | [
"10 6\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n",
"2 1\n1\n10\n"
] | [
"10\n",
"1\n"
] | none | 500 | [
{
"input": "10 6\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560\n1234560",
"output": "10"
},
{
"input": "2 1\n1\n10",
"output": "1"
},
{
"input": "1 0\n1000000000",
"output": "1"
},
{
"input": "1 1\n1000000000",
"output": "1"
},
{
... | 1,638,252,699 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 46 | 0 | a,x=map(int,input().split())
temp=0
for i in range(a) :
count=0
n=list(map(int,input()))
for j in range(len(n)) :
if x>=n[j] :
count=count+1
else :
continue
if count==(x+1):
temp=temp+1
print(temp) | Title: Good Number
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Let's call a number *k*-good if it contains all digits not exceeding *k* (0,<=...,<=*k*). You've got a number *k* and an array *a* containing *n* numbers. Find out how many *k*-good numbers are in *a* (count each number eve... | ```python
a,x=map(int,input().split())
temp=0
for i in range(a) :
count=0
n=list(map(int,input()))
for j in range(len(n)) :
if x>=n[j] :
count=count+1
else :
continue
if count==(x+1):
temp=temp+1
print(temp)
``` | 0 | |
52 | A | 123-sequence | PROGRAMMING | 900 | [
"implementation"
] | A. 123-sequence | 2 | 256 | There is a given sequence of integers *a*1,<=*a*2,<=...,<=*a**n*, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. | The first line contains an integer *n* (1<=≤<=*n*<=≤<=106). The second line contains a sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=3). | Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal. | [
"9\n1 3 2 2 2 1 1 2 3\n"
] | [
"5\n"
] | In the example all the numbers equal to 1 and 3 should be replaced by 2. | 500 | [
{
"input": "9\n1 3 2 2 2 1 1 2 3",
"output": "5"
},
{
"input": "6\n3 3 2 2 1 3",
"output": "3"
},
{
"input": "12\n3 1 3 1 2 1 3 2 2 1 2 1",
"output": "7"
},
{
"input": "15\n3 2 1 1 1 1 3 2 2 3 3 1 2 3 2",
"output": "10"
},
{
"input": "2\n2 1",
"output": "1"
... | 1,654,021,493 | 2,147,483,647 | Python 3 | OK | TESTS | 23 | 528 | 14,233,600 | n = int(input())
a = list(map(int,input().split(" ")))
ans = []
x = a.count(1)
y = a.count(2)
z = a.count(3)
ans.append(x)
ans.append(y)
ans.append(z)
ans.sort()
print(ans[0]+ans[1]) | Title: 123-sequence
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
There is a given sequence of integers *a*1,<=*a*2,<=...,<=*a**n*, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each... | ```python
n = int(input())
a = list(map(int,input().split(" ")))
ans = []
x = a.count(1)
y = a.count(2)
z = a.count(3)
ans.append(x)
ans.append(y)
ans.append(z)
ans.sort()
print(ans[0]+ans[1])
``` | 3.841488 |
253 | A | Boys and Girls | PROGRAMMING | 1,100 | [
"greedy"
] | null | null | There are *n* boys and *m* girls studying in the class. They should stand in a line so that boys and girls alternated there as much as possible. Let's assume that positions in the line are indexed from left to right by numbers from 1 to *n*<=+<=*m*. Then the number of integers *i* (1<=≤<=*i*<=<<=*n*<=+<=*m*) such th... | The single line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100), separated by a space. | Print a line of *n*<=+<=*m* characters. Print on the *i*-th position of the line character "B", if the *i*-th position of your arrangement should have a boy and "G", if it should have a girl.
Of course, the number of characters "B" should equal *n* and the number of characters "G" should equal *m*. If there are multi... | [
"3 3\n",
"4 2\n"
] | [
"GBGBGB\n",
"BGBGBB\n"
] | In the first sample another possible answer is BGBGBG.
In the second sample answer BBGBGB is also optimal. | 500 | [
{
"input": "3 3",
"output": "GBGBGB"
},
{
"input": "4 2",
"output": "BGBGBB"
},
{
"input": "5 5",
"output": "GBGBGBGBGB"
},
{
"input": "6 4",
"output": "BGBGBGBGBB"
},
{
"input": "100 1",
"output": "BGBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB... | 1,629,038,058 | 2,147,483,647 | Python 3 | OK | TESTS | 23 | 154 | 6,963,200 | a = open("input.txt",'r')
# print(a)
ar = a.read()
ar = ar.split(' ')
n = int(ar[0])
m = int(ar[1])
if n>m:
s = m*"BG"+(n-m)*'B'
f = open("output.txt", 'w')
f.write(s)
f.close()
# print(s)
elif m>=n:
s = n*"GB"+(m-n)*'G'
f = open("output.txt", 'w')
f.write(s)
f.close()
# print(s) | Title: Boys and Girls
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are *n* boys and *m* girls studying in the class. They should stand in a line so that boys and girls alternated there as much as possible. Let's assume that positions in the line are indexed from left to right by n... | ```python
a = open("input.txt",'r')
# print(a)
ar = a.read()
ar = ar.split(' ')
n = int(ar[0])
m = int(ar[1])
if n>m:
s = m*"BG"+(n-m)*'B'
f = open("output.txt", 'w')
f.write(s)
f.close()
# print(s)
elif m>=n:
s = n*"GB"+(m-n)*'G'
f = open("output.txt", 'w')
f.write(s)
f.close()
# print(s)
``... | 3 | |
0 | none | none | none | 0 | [
"none"
] | null | null | In the year of $30XX$ participants of some world programming championship live in a single large hotel. The hotel has $n$ floors. Each floor has $m$ sections with a single corridor connecting all of them. The sections are enumerated from $1$ to $m$ along the corridor, and all sections with equal numbers on different fl... | The first line contains five integers $n, m, c_l, c_e, v$ ($2 \leq n, m \leq 10^8$, $0 \leq c_l, c_e \leq 10^5$, $1 \leq c_l + c_e \leq m - 1$, $1 \leq v \leq n - 1$) — the number of floors and section on each floor, the number of stairs, the number of elevators and the maximum speed of an elevator, respectively.
The ... | Print $q$ integers, one per line — the answers for the queries. | [
"5 6 1 1 3\n2\n5\n3\n1 1 5 6\n1 3 5 4\n3 3 5 3\n"
] | [
"7\n5\n4\n"
] | In the first query the optimal way is to go to the elevator in the 5-th section in four time units, use it to go to the fifth floor in two time units and go to the destination in one more time unit.
In the second query it is still optimal to use the elevator, but in the third query it is better to use the stairs in th... | 0 | [
{
"input": "5 6 1 1 3\n2\n5\n3\n1 1 5 6\n1 3 5 4\n3 3 5 3",
"output": "7\n5\n4"
},
{
"input": "2 2 0 1 1\n\n1\n1\n1 2 2 2",
"output": "3"
},
{
"input": "4 4 1 0 1\n4\n\n5\n1 1 2 2\n1 3 2 2\n3 3 4 3\n3 2 2 2\n1 2 2 3",
"output": "6\n4\n3\n5\n4"
},
{
"input": "10 10 1 8 4\n10\n... | 1,653,552,115 | 2,147,483,647 | PyPy 3-64 | RUNTIME_ERROR | TESTS | 0 | 62 | 3,379,200 | n=int(input())
bills=0
if n>=100:
while n>=100:
n-=100
bills+=1
if n>=20:
while n>=20:
n-=20
bills+=1
if n>=10:
while n>=10:
n-=10
bills+=1
if n>=5:
while n>=5:
n-=5
bills+=1
if n>=1:
while n>=1:
n-... | Title: none
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In the year of $30XX$ participants of some world programming championship live in a single large hotel. The hotel has $n$ floors. Each floor has $m$ sections with a single corridor connecting all of them. The sections are enumerat... | ```python
n=int(input())
bills=0
if n>=100:
while n>=100:
n-=100
bills+=1
if n>=20:
while n>=20:
n-=20
bills+=1
if n>=10:
while n>=10:
n-=10
bills+=1
if n>=5:
while n>=5:
n-=5
bills+=1
if n>=1:
while n>=1:
... | -1 | |
629 | B | Far Relative’s Problem | PROGRAMMING | 1,100 | [
"brute force"
] | null | null | Famil Door wants to celebrate his birthday with his friends from Far Far Away. He has *n* friends and each of them can come to the party in a specific range of days of the year from *a**i* to *b**i*. Of course, Famil Door wants to have as many friends celebrating together with him as possible.
Far cars are as weird as... | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=5000) — then number of Famil Door's friends.
Then follow *n* lines, that describe the friends. Each line starts with a capital letter 'F' for female friends and with a capital letter 'M' for male friends. Then follow two integers *a**i* and *b**i... | Print the maximum number of people that may come to Famil Door's party. | [
"4\nM 151 307\nF 343 352\nF 117 145\nM 24 128\n",
"6\nM 128 130\nF 128 131\nF 131 140\nF 131 141\nM 131 200\nM 140 200\n"
] | [
"2\n",
"4\n"
] | In the first sample, friends 3 and 4 can come on any day in range [117, 128].
In the second sample, friends with indices 3, 4, 5 and 6 can come on day 140. | 1,000 | [
{
"input": "4\nM 151 307\nF 343 352\nF 117 145\nM 24 128",
"output": "2"
},
{
"input": "6\nM 128 130\nF 128 131\nF 131 140\nF 131 141\nM 131 200\nM 140 200",
"output": "4"
},
{
"input": "1\nF 68 307",
"output": "0"
},
{
"input": "40\nM 55 363\nF 117 252\nM 157 282\nF 322 345\... | 1,587,224,235 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 0 | 77 | 307,200 | n=int(input())
m=[0]*(367)
f=[0]*(367)
for i in range(n):
a,x,y=input().split()
x=int(y)
y=int(y)
if a=="M":
for j in range(x,y+1):
m.append(1)
else:
for k in range(x,y+1):
f.append(1)
g=[]
for i in range(len(m)):
g.append(2*min(... | Title: Far Relative’s Problem
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Famil Door wants to celebrate his birthday with his friends from Far Far Away. He has *n* friends and each of them can come to the party in a specific range of days of the year from *a**i* to *b**i*. Of course, F... | ```python
n=int(input())
m=[0]*(367)
f=[0]*(367)
for i in range(n):
a,x,y=input().split()
x=int(y)
y=int(y)
if a=="M":
for j in range(x,y+1):
m.append(1)
else:
for k in range(x,y+1):
f.append(1)
g=[]
for i in range(len(m)):
g.app... | -1 | |
984 | B | Minesweeper | PROGRAMMING | 1,100 | [
"implementation"
] | null | null | One day Alex decided to remember childhood when computers were not too powerful and lots of people played only default games. Alex enjoyed playing Minesweeper that time. He imagined that he saved world from bombs planted by terrorists, but he rarely won.
Alex has grown up since then, so he easily wins the most difficu... | The first line contains two integers $n$ and $m$ ($1 \le n, m \le 100$) — the sizes of the field.
The next $n$ lines contain the description of the field. Each line contains $m$ characters, each of them is "." (if this cell is empty), "*" (if there is bomb in this cell), or a digit from $1$ to $8$, inclusive. | Print "YES", if the field is valid and "NO" otherwise.
You can choose the case (lower or upper) for each letter arbitrarily. | [
"3 3\n111\n1*1\n111\n",
"2 4\n*.*.\n1211\n"
] | [
"YES",
"NO"
] | In the second example the answer is "NO" because, if the positions of the bombs are preserved, the first line of the field should be *2*1.
You can read more about Minesweeper in [Wikipedia's article](https://en.wikipedia.org/wiki/Minesweeper_(video_game)). | 1,000 | [
{
"input": "3 3\n111\n1*1\n111",
"output": "YES"
},
{
"input": "2 4\n*.*.\n1211",
"output": "NO"
},
{
"input": "1 10\n.....1*1..",
"output": "YES"
},
{
"input": "1 1\n4",
"output": "NO"
},
{
"input": "10 10\n..........\n...111111.\n..13*21*1.\n.12**2111.\n.1*542..... | 1,582,097,365 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 93 | 307,200 | from bisect import bisect_left, bisect_right
def tuple_input(type):
return map(type, input().strip().split())
n, m = tuple_input(int)
F = list()
for _ in range(n):
F.append(list(input().strip()))
di = [-1,-1,0,1,1,1,0,-1]
dj = [0,1,1,1,0,-1,-1,-1]
for i in range(n):
for j in range(m):
... | Title: Minesweeper
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day Alex decided to remember childhood when computers were not too powerful and lots of people played only default games. Alex enjoyed playing Minesweeper that time. He imagined that he saved world from bombs planted by... | ```python
from bisect import bisect_left, bisect_right
def tuple_input(type):
return map(type, input().strip().split())
n, m = tuple_input(int)
F = list()
for _ in range(n):
F.append(list(input().strip()))
di = [-1,-1,0,1,1,1,0,-1]
dj = [0,1,1,1,0,-1,-1,-1]
for i in range(n):
for j in range(m)... | 0 | |
710 | A | King Moves | PROGRAMMING | 800 | [
"implementation"
] | null | null | The only king stands on the standard chess board. You are given his position in format "cd", where *c* is the column from 'a' to 'h' and *d* is the row from '1' to '8'. Find the number of moves permitted for the king.
Check the king's moves here [https://en.wikipedia.org/wiki/King_(chess)](https://en.wikipedia.org/wik... | The only line contains the king's position in the format "cd", where 'c' is the column from 'a' to 'h' and 'd' is the row from '1' to '8'. | Print the only integer *x* — the number of moves permitted for the king. | [
"e4\n"
] | [
"8\n"
] | none | 0 | [
{
"input": "e4",
"output": "8"
},
{
"input": "a1",
"output": "3"
},
{
"input": "h8",
"output": "3"
},
{
"input": "a4",
"output": "5"
},
{
"input": "g7",
"output": "8"
},
{
"input": "e1",
"output": "5"
},
{
"input": "b2",
"output": "8"
... | 1,474,147,662 | 2,147,483,647 | Python 3 | OK | TESTS | 24 | 61 | 0 | position = input()
turns = 0
if position[0] == 'a':
turns = 2
elif position[0] == 'h':
turns = 2
else:
turns = 3
if position[1] == '1':
print(turns*2-1)
elif position[1] == '8':
print(turns*2-1)
else:
print(turns*3-1) | Title: King Moves
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The only king stands on the standard chess board. You are given his position in format "cd", where *c* is the column from 'a' to 'h' and *d* is the row from '1' to '8'. Find the number of moves permitted for the king.
Check... | ```python
position = input()
turns = 0
if position[0] == 'a':
turns = 2
elif position[0] == 'h':
turns = 2
else:
turns = 3
if position[1] == '1':
print(turns*2-1)
elif position[1] == '8':
print(turns*2-1)
else:
print(turns*3-1)
``` | 3 | |
730 | H | Delete Them | PROGRAMMING | 1,300 | [
"constructive algorithms",
"implementation"
] | null | null | Polycarp is a beginner programmer. He is studying how to use a command line.
Polycarp faced the following problem. There are *n* files in a directory and he needs to delete some of them. Polycarp wants to run a single delete command with filename pattern as an argument. All the files to be deleted should match the pat... | The first line of the input contains two integers *n* and *m* (1<=≤<=*m*<=≤<=*n*<=≤<=100) — the total number of files and the number of files to be deleted.
The following *n* lines contain filenames, single filename per line. All filenames are non-empty strings containing only lowercase English letters, digits and dot... | If the required pattern exists, print "Yes" in the first line of the output. The second line should contain the required pattern. If there are multiple solutions, print any of them.
If the required pattern doesn't exist, print the only line containing "No". | [
"3 2\nab\nac\ncd\n1 2\n",
"5 3\ntest\ntezt\ntest.\n.est\ntes.\n1 4 5\n",
"4 4\na\nb\nc\ndd\n1 2 3 4\n",
"6 3\n.svn\n.git\n....\n...\n..\n.\n1 2 3\n"
] | [
"Yes\na?\n",
"Yes\n?es?\n",
"No\n",
"Yes\n.???\n"
] | none | 0 | [
{
"input": "3 2\nab\nac\ncd\n1 2",
"output": "Yes\na?"
},
{
"input": "5 3\ntest\ntezt\ntest.\n.est\ntes.\n1 4 5",
"output": "Yes\n?es?"
},
{
"input": "4 4\na\nb\nc\ndd\n1 2 3 4",
"output": "No"
},
{
"input": "6 3\n.svn\n.git\n....\n...\n..\n.\n1 2 3",
"output": "Yes\n.???... | 1,654,743,440 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 74 | 62 | 2,252,800 | n, m = map(int, input().split())
s = [input() for i in range(n)]
indices = set(map(lambda x: int(x)-1, input().split()))
lengths = set([len(s[i]) for i in indices])
if len(lengths) != 1:
print("No")
exit(0)
non_indices = set(range(n)) - indices
l = lengths.pop()
ans = []
for j in range(l):
ch = ... | Title: Delete Them
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp is a beginner programmer. He is studying how to use a command line.
Polycarp faced the following problem. There are *n* files in a directory and he needs to delete some of them. Polycarp wants to run a single dele... | ```python
n, m = map(int, input().split())
s = [input() for i in range(n)]
indices = set(map(lambda x: int(x)-1, input().split()))
lengths = set([len(s[i]) for i in indices])
if len(lengths) != 1:
print("No")
exit(0)
non_indices = set(range(n)) - indices
l = lengths.pop()
ans = []
for j in range(l... | 3 | |
11 | B | Jumping Jack | PROGRAMMING | 1,600 | [
"math"
] | B. Jumping Jack | 1 | 64 | Jack is working on his jumping skills recently. Currently he's located at point zero of the number line. He would like to get to the point *x*. In order to train, he has decided that he'll first jump by only one unit, and each subsequent jump will be exactly one longer than the previous one. He can go either left or ri... | The input data consists of only one integer *x* (<=-<=109<=≤<=*x*<=≤<=109). | Output the minimal number of jumps that Jack requires to reach *x*. | [
"2\n",
"6\n",
"0\n"
] | [
"3\n",
"3\n",
"0\n"
] | none | 0 | [
{
"input": "2",
"output": "3"
},
{
"input": "6",
"output": "3"
},
{
"input": "0",
"output": "0"
},
{
"input": "-1000000000",
"output": "44723"
},
{
"input": "999961560",
"output": "44720"
},
{
"input": "999961561",
"output": "44721"
},
{
"i... | 1,698,386,969 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 3 | 186 | 1,228,800 | now = 0
step = 1
ans = 0
x = abs(int(input()))
while x >= now + step:
ans += 1
now += step
step+=1
min_dif = x - now
max_dif = now + step - x
ans += min(min_dif, max_dif) << 1
# 0 1 3 6 10 15 21
print(ans) | Title: Jumping Jack
Time Limit: 1 seconds
Memory Limit: 64 megabytes
Problem Description:
Jack is working on his jumping skills recently. Currently he's located at point zero of the number line. He would like to get to the point *x*. In order to train, he has decided that he'll first jump by only one unit, and each ... | ```python
now = 0
step = 1
ans = 0
x = abs(int(input()))
while x >= now + step:
ans += 1
now += step
step+=1
min_dif = x - now
max_dif = now + step - x
ans += min(min_dif, max_dif) << 1
# 0 1 3 6 10 15 21
print(ans)
``` | 0 |
275 | A | Lights Out | PROGRAMMING | 900 | [
"implementation"
] | null | null | Lenny is playing a game on a 3<=×<=3 grid of lights. In the beginning of the game all lights are switched on. Pressing any of the lights will toggle it and all side-adjacent lights. The goal of the game is to switch all the lights off. We consider the toggling as follows: if the light was switched on then it will be sw... | The input consists of three rows. Each row contains three integers each between 0 to 100 inclusive. The *j*-th number in the *i*-th row is the number of times the *j*-th light of the *i*-th row of the grid is pressed. | Print three lines, each containing three characters. The *j*-th character of the *i*-th line is "1" if and only if the corresponding light is switched on, otherwise it's "0". | [
"1 0 0\n0 0 0\n0 0 1\n",
"1 0 1\n8 8 8\n2 0 3\n"
] | [
"001\n010\n100\n",
"010\n011\n100\n"
] | none | 500 | [
{
"input": "1 0 0\n0 0 0\n0 0 1",
"output": "001\n010\n100"
},
{
"input": "1 0 1\n8 8 8\n2 0 3",
"output": "010\n011\n100"
},
{
"input": "13 85 77\n25 50 45\n65 79 9",
"output": "000\n010\n000"
},
{
"input": "96 95 5\n8 84 74\n67 31 61",
"output": "011\n011\n101"
},
{... | 1,687,142,367 | 2,147,483,647 | Python 3 | OK | TESTS | 33 | 46 | 0 | row1=list(map(int,input().split()))
row2=list(map(int,input().split()))
row3=list(map(int,input().split()))
config1=[row1[0]+row1[1]+row2[0], sum(row1)+row2[1], row1[1]+row1[2]+row2[2]]
config2=[row1[0]+row2[0]+row3[0]+row2[1], sum(row2)+row1[1]+row3[1], row1[2]+row2[2]+row3[2]+row2[1]]
config3=[row2[0]+row3[0]+row3[1... | Title: Lights Out
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Lenny is playing a game on a 3<=×<=3 grid of lights. In the beginning of the game all lights are switched on. Pressing any of the lights will toggle it and all side-adjacent lights. The goal of the game is to switch all the ... | ```python
row1=list(map(int,input().split()))
row2=list(map(int,input().split()))
row3=list(map(int,input().split()))
config1=[row1[0]+row1[1]+row2[0], sum(row1)+row2[1], row1[1]+row1[2]+row2[2]]
config2=[row1[0]+row2[0]+row3[0]+row2[1], sum(row2)+row1[1]+row3[1], row1[2]+row2[2]+row3[2]+row2[1]]
config3=[row2[0]+row3... | 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,596,075,983 | 2,147,483,647 | PyPy 3 | OK | TESTS | 51 | 312 | 22,118,400 | num = input()
ans = 0
temp = 0
while len(num) > 1:
for x in num:
ans += int(x)
num = str(ans)
ans = 0
temp += 1
print(temp) | 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
num = input()
ans = 0
temp = 0
while len(num) > 1:
for x in num:
ans += int(x)
num = str(ans)
ans = 0
temp += 1
print(temp)
``` | 3.8822 |
334 | A | Candy Bags | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Gerald has *n* younger brothers and their number happens to be even. One day he bought *n*2 candy bags. One bag has one candy, one bag has two candies, one bag has three candies and so on. In fact, for each integer *k* from 1 to *n*2 he has exactly one bag with *k* candies.
Help him give *n* bags of candies to each b... | The single line contains a single integer *n* (*n* is even, 2<=≤<=*n*<=≤<=100) — the number of Gerald's brothers. | Let's assume that Gerald indexes his brothers with numbers from 1 to *n*. You need to print *n* lines, on the *i*-th line print *n* integers — the numbers of candies in the bags for the *i*-th brother. Naturally, all these numbers should be distinct and be within limits from 1 to *n*2. You can print the numbers in the ... | [
"2\n"
] | [
"1 4\n2 3\n"
] | The sample shows Gerald's actions if he has two brothers. In this case, his bags contain 1, 2, 3 and 4 candies. He can give the bags with 1 and 4 candies to one brother and the bags with 2 and 3 to the other brother. | 500 | [
{
"input": "2",
"output": "1 4\n2 3"
},
{
"input": "4",
"output": "1 16 2 15\n3 14 4 13\n5 12 6 11\n7 10 8 9"
},
{
"input": "6",
"output": "1 36 2 35 3 34\n4 33 5 32 6 31\n7 30 8 29 9 28\n10 27 11 26 12 25\n13 24 14 23 15 22\n16 21 17 20 18 19"
},
{
"input": "8",
"output"... | 1,641,605,111 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 1 | 92 | 0 |
# n =(input()) ;ln =[] ;ln[:0]=n ;lenn =len(ln) ; Count=0
# m =input() ;lm =[] ;lm[:0]=m
# for i,j in zip(ln,lm):
# if i.lower() == j.lower():
# if Count ==lenn-1:
# print(0)
# break
# Count +=1
# elif( ascii(i.lower()) < ascii(j.lower())):
# print(... | Title: Candy Bags
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Gerald has *n* younger brothers and their number happens to be even. One day he bought *n*2 candy bags. One bag has one candy, one bag has two candies, one bag has three candies and so on. In fact, for each integer *k* from ... | ```python
# n =(input()) ;ln =[] ;ln[:0]=n ;lenn =len(ln) ; Count=0
# m =input() ;lm =[] ;lm[:0]=m
# for i,j in zip(ln,lm):
# if i.lower() == j.lower():
# if Count ==lenn-1:
# print(0)
# break
# Count +=1
# elif( ascii(i.lower()) < ascii(j.lower())):
# ... | 0 | |
721 | A | One-dimensional Japanese Crossword | PROGRAMMING | 800 | [
"implementation"
] | null | null | Recently Adaltik discovered japanese crosswords. Japanese crossword is a picture, represented as a table sized *a*<=×<=*b* squares, and each square is colored white or black. There are integers to the left of the rows and to the top of the columns, encrypting the corresponding row or column. The number of integers repr... | The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the length of the row. The second line of the input contains a single string consisting of *n* characters 'B' or 'W', ('B' corresponds to black square, 'W' — to white square in the row that Adaltik drew). | The first line should contain a single integer *k* — the number of integers encrypting the row, e.g. the number of groups of black squares in the row.
The second line should contain *k* integers, encrypting the row, e.g. corresponding to sizes of groups of consecutive black squares in the order from left to right. | [
"3\nBBW\n",
"5\nBWBWB\n",
"4\nWWWW\n",
"4\nBBBB\n",
"13\nWBBBBWWBWBBBW\n"
] | [
"1\n2 ",
"3\n1 1 1 ",
"0\n",
"1\n4 ",
"3\n4 1 3 "
] | The last sample case correspond to the picture in the statement. | 500 | [
{
"input": "3\nBBW",
"output": "1\n2 "
},
{
"input": "5\nBWBWB",
"output": "3\n1 1 1 "
},
{
"input": "4\nWWWW",
"output": "0"
},
{
"input": "4\nBBBB",
"output": "1\n4 "
},
{
"input": "13\nWBBBBWWBWBBBW",
"output": "3\n4 1 3 "
},
{
"input": "1\nB",
... | 1,619,206,878 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 0 | 62 | 0 | Length_Row = int(input())
Sqc = input().split('W')
g = []
for i in Sqc:
if 'B' in i:
g.append(len(i))
print(str(g))
| Title: One-dimensional Japanese Crossword
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Recently Adaltik discovered japanese crosswords. Japanese crossword is a picture, represented as a table sized *a*<=×<=*b* squares, and each square is colored white or black. There are integers to the... | ```python
Length_Row = int(input())
Sqc = input().split('W')
g = []
for i in Sqc:
if 'B' in i:
g.append(len(i))
print(str(g))
``` | 0 | |
371 | C | Hamburgers | PROGRAMMING | 1,600 | [
"binary search",
"brute force"
] | null | null | Polycarpus loves hamburgers very much. He especially adores the hamburgers he makes with his own hands. Polycarpus thinks that there are only three decent ingredients to make hamburgers from: a bread, sausage and cheese. He writes down the recipe of his favorite "Le Hamburger de Polycarpus" as a string of letters 'B' (... | The first line of the input contains a non-empty string that describes the recipe of "Le Hamburger de Polycarpus". The length of the string doesn't exceed 100, the string contains only letters 'B' (uppercase English B), 'S' (uppercase English S) and 'C' (uppercase English C).
The second line contains three integers *n... | Print the maximum number of hamburgers Polycarpus can make. If he can't make any hamburger, print 0. | [
"BBBSSC\n6 4 1\n1 2 3\n4\n",
"BBC\n1 10 1\n1 10 1\n21\n",
"BSC\n1 1 1\n1 1 3\n1000000000000\n"
] | [
"2\n",
"7\n",
"200000000001\n"
] | none | 1,500 | [
{
"input": "BBBSSC\n6 4 1\n1 2 3\n4",
"output": "2"
},
{
"input": "BBC\n1 10 1\n1 10 1\n21",
"output": "7"
},
{
"input": "BSC\n1 1 1\n1 1 3\n1000000000000",
"output": "200000000001"
},
{
"input": "B\n1 1 1\n1 1 1\n381",
"output": "382"
},
{
"input": "BSC\n3 5 6\n7... | 1,654,269,616 | 2,147,483,647 | Python 3 | OK | TESTS | 31 | 61 | 102,400 | from collections import Counter
def canBeMade(money,x,recipeB,recipeS,recipeC,nb,ns,nc,pb,ps,pc):
costOfburgere = max(0,recipeB*x-nb)*pb+max(0,recipeS*x-ns)*ps+max(0,recipeC*x-nc)*pc
if(money>=costOfburgere):
return True
else:
return False
def solve(money,rb,rs,rc,available_bread,av... | Title: Hamburgers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarpus loves hamburgers very much. He especially adores the hamburgers he makes with his own hands. Polycarpus thinks that there are only three decent ingredients to make hamburgers from: a bread, sausage and cheese. He ... | ```python
from collections import Counter
def canBeMade(money,x,recipeB,recipeS,recipeC,nb,ns,nc,pb,ps,pc):
costOfburgere = max(0,recipeB*x-nb)*pb+max(0,recipeS*x-ns)*ps+max(0,recipeC*x-nc)*pc
if(money>=costOfburgere):
return True
else:
return False
def solve(money,rb,rs,rc,availabl... | 3 | |
176 | A | Trading Business | PROGRAMMING | 1,200 | [
"greedy",
"sortings"
] | null | null | To get money for a new aeonic blaster, ranger Qwerty decided to engage in trade for a while. He wants to buy some number of items (or probably not to buy anything at all) on one of the planets, and then sell the bought items on another planet. Note that this operation is not repeated, that is, the buying and the sellin... | The first line contains three space-separated integers *n*, *m* and *k* (2<=≤<=*n*<=≤<=10, 1<=≤<=*m*,<=*k*<=≤<=100) — the number of planets, the number of question types and the capacity of Qwerty's ship hold, correspondingly.
Then follow *n* blocks describing each planet.
The first line of the *i*-th block has the p... | Print a single number — the maximum profit Qwerty can get. | [
"3 3 10\nVenus\n6 5 3\n7 6 5\n8 6 10\nEarth\n10 9 0\n8 6 4\n10 9 3\nMars\n4 3 0\n8 4 12\n7 2 5\n"
] | [
"16"
] | In the first test case you should fly to planet Venus, take a loan on 74 units of money and buy three items of the first type and 7 items of the third type (3·6 + 7·8 = 74). Then the ranger should fly to planet Earth and sell there all the items he has bought. He gets 3·9 + 7·9 = 90 units of money for the items, he sho... | 500 | [
{
"input": "3 3 10\nVenus\n6 5 3\n7 6 5\n8 6 10\nEarth\n10 9 0\n8 6 4\n10 9 3\nMars\n4 3 0\n8 4 12\n7 2 5",
"output": "16"
},
{
"input": "2 1 5\nA\n6 5 5\nB\n10 9 0",
"output": "15"
},
{
"input": "2 2 5\nAbcdefghij\n20 15 20\n10 5 13\nKlmopqrstu\n19 16 20\n12 7 14",
"output": "0"
}... | 1,689,661,698 | 2,147,483,647 | Python 3 | OK | TESTS | 51 | 92 | 102,400 | n, m, k = map(int, input().split())
l = []
for i in range(n):
s = input()
for j in range(m):
li = list(map(int, input().split()))
l.append(li)
max_earn = 0
for i in range(n):
for j in range(n):
if i != j:
lji = []
for o in range(m):
lji.append... | Title: Trading Business
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
To get money for a new aeonic blaster, ranger Qwerty decided to engage in trade for a while. He wants to buy some number of items (or probably not to buy anything at all) on one of the planets, and then sell the bought... | ```python
n, m, k = map(int, input().split())
l = []
for i in range(n):
s = input()
for j in range(m):
li = list(map(int, input().split()))
l.append(li)
max_earn = 0
for i in range(n):
for j in range(n):
if i != j:
lji = []
for o in range(m):
... | 3 | |
131 | A | cAPS lOCK | PROGRAMMING | 1,000 | [
"implementation",
"strings"
] | null | null | wHAT DO WE NEED cAPS LOCK FOR?
Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in the first passage.
Let's consider that a word has been typed with the Caps lock key accidentall... | The first line of the input data contains a word consisting of uppercase and lowercase Latin letters. The word's length is from 1 to 100 characters, inclusive. | Print the result of the given word's processing. | [
"cAPS\n",
"Lock\n"
] | [
"Caps",
"Lock\n"
] | none | 500 | [
{
"input": "cAPS",
"output": "Caps"
},
{
"input": "Lock",
"output": "Lock"
},
{
"input": "cAPSlOCK",
"output": "cAPSlOCK"
},
{
"input": "CAPs",
"output": "CAPs"
},
{
"input": "LoCK",
"output": "LoCK"
},
{
"input": "OOPS",
"output": "oops"
},
{
... | 1,693,763,916 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 30 | 0 | class CheckWord:
def __init__(self, word):
self.word = word
def check_word(self):
if self.word.upper():
if self.word[0].lower() and self.word[1:].upper:
print(self.word.capitalize())
else:
print(self.word)
a = CheckWord(input())
a.check_word() | Title: cAPS lOCK
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
wHAT DO WE NEED cAPS LOCK FOR?
Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in th... | ```python
class CheckWord:
def __init__(self, word):
self.word = word
def check_word(self):
if self.word.upper():
if self.word[0].lower() and self.word[1:].upper:
print(self.word.capitalize())
else:
print(self.word)
a = CheckWord(input())
a.che... | 0 | |
53 | A | Autocomplete | PROGRAMMING | 1,100 | [
"implementation"
] | A. Autocomplete | 2 | 256 | Autocomplete is a program function that enables inputting the text (in editors, command line shells, browsers etc.) completing the text by its inputted part. Vasya is busy working on a new browser called 'BERowser'. He happens to be working on the autocomplete function in the address line at this very moment. A list co... | The first line contains the *s* line which is the inputted part. The second line contains an integer *n* (1<=≤<=*n*<=≤<=100) which is the number of visited pages. Then follow *n* lines which are the visited pages, one on each line. All the lines have lengths of from 1 to 100 symbols inclusively and consist of lowercase... | If *s* is not the beginning of any of *n* addresses of the visited pages, print *s*. Otherwise, print the lexicographically minimal address of one of the visited pages starting from *s*.
The lexicographical order is the order of words in a dictionary. The lexicographical comparison of lines is realized by the '<' o... | [
"next\n2\nnextpermutation\nnextelement\n",
"find\n4\nfind\nfindfirstof\nfindit\nfand\n",
"find\n4\nfondfind\nfondfirstof\nfondit\nfand\n"
] | [
"nextelement\n",
"find\n",
"find\n"
] | none | 500 | [
{
"input": "next\n2\nnextpermutation\nnextelement",
"output": "nextelement"
},
{
"input": "find\n4\nfind\nfindfirstof\nfindit\nfand",
"output": "find"
},
{
"input": "find\n4\nfondfind\nfondfirstof\nfondit\nfand",
"output": "find"
},
{
"input": "kudljmxcse\n4\nkudljmxcse\nszje... | 1,611,947,079 | 2,147,483,647 | PyPy 3 | OK | TESTS | 25 | 186 | 0 | w = input()
n = int(input())
res = []
for tc in range(n):
word = input()
if w == word[0:len(w)]:
res.append(word)
if (len(res) > 0):
res.sort()
print(res[0])
else:
print(w)
| Title: Autocomplete
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Autocomplete is a program function that enables inputting the text (in editors, command line shells, browsers etc.) completing the text by its inputted part. Vasya is busy working on a new browser called 'BERowser'. He happens... | ```python
w = input()
n = int(input())
res = []
for tc in range(n):
word = input()
if w == word[0:len(w)]:
res.append(word)
if (len(res) > 0):
res.sort()
print(res[0])
else:
print(w)
``` | 3.9535 |
906 | C | Party | PROGRAMMING | 2,400 | [
"bitmasks",
"brute force",
"dp",
"graphs"
] | null | null | Arseny likes to organize parties and invite people to it. However, not only friends come to his parties, but friends of his friends, friends of friends of his friends and so on. That's why some of Arseny's guests can be unknown to him. He decided to fix this issue using the following procedure.
At each step he selects... | The first line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=22; ) — the number of guests at the party (including Arseny) and the number of pairs of people which are friends.
Each of the next *m* lines contains two integers *u* and *v* (1<=≤<=*u*,<=*v*<=≤<=*n*; *u*<=≠<=*v*), which means that people with numbers *u*... | In the first line print the minimum number of steps required to make all pairs of guests friends.
In the second line print the ids of guests, who are selected at each step.
If there are multiple solutions, you can output any of them. | [
"5 6\n1 2\n1 3\n2 3\n2 5\n3 4\n4 5\n",
"4 4\n1 2\n1 3\n1 4\n3 4\n"
] | [
"2\n2 3 ",
"1\n1 "
] | In the first test case there is no guest who is friend of all other guests, so at least two steps are required to perform the task. After second guest pairwise introduces all his friends, only pairs of guests (4, 1) and (4, 2) are not friends. Guest 3 or 5 can introduce them.
In the second test case guest number 1 is ... | 1,250 | [
{
"input": "5 6\n1 2\n1 3\n2 3\n2 5\n3 4\n4 5",
"output": "2\n2 3 "
},
{
"input": "4 4\n1 2\n1 3\n1 4\n3 4",
"output": "1\n1 "
},
{
"input": "1 0",
"output": "0"
},
{
"input": "2 1\n2 1",
"output": "0"
},
{
"input": "3 2\n1 3\n2 3",
"output": "1\n3 "
},
{
... | 1,573,121,107 | 2,147,483,647 | PyPy 3 | RUNTIME_ERROR | TESTS | 2 | 202 | 2,252,800 | from collections import deque, defaultdict
n,m=map(int,input().split())
g=defaultdict(list)
q=deque()
for _ in range(m):
u, v = map(int,input().split())
u-=1;v-=1
g[u].append(v)
g[v].append(u)
mask1=0;mask2=0
a=[0]*(1 << n)
for i,j in g.items():
mask1 = (1 << i);mask2=0;mask2 |= mask1
for k i... | Title: Party
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Arseny likes to organize parties and invite people to it. However, not only friends come to his parties, but friends of his friends, friends of friends of his friends and so on. That's why some of Arseny's guests can be unknown t... | ```python
from collections import deque, defaultdict
n,m=map(int,input().split())
g=defaultdict(list)
q=deque()
for _ in range(m):
u, v = map(int,input().split())
u-=1;v-=1
g[u].append(v)
g[v].append(u)
mask1=0;mask2=0
a=[0]*(1 << n)
for i,j in g.items():
mask1 = (1 << i);mask2=0;mask2 |= mask1
... | -1 | |
982 | B | Bus of Characters | PROGRAMMING | 1,300 | [
"data structures",
"greedy",
"implementation"
] | null | null | In the Bus of Characters there are $n$ rows of seat, each having $2$ seats. The width of both seats in the $i$-th row is $w_i$ centimeters. All integers $w_i$ are distinct.
Initially the bus is empty. On each of $2n$ stops one passenger enters the bus. There are two types of passengers:
- an introvert always choose... | The first line contains a single integer $n$ ($1 \le n \le 200\,000$) — the number of rows in the bus.
The second line contains the sequence of integers $w_1, w_2, \dots, w_n$ ($1 \le w_i \le 10^{9}$), where $w_i$ is the width of each of the seats in the $i$-th row. It is guaranteed that all $w_i$ are distinct.
The t... | Print $2n$ integers — the rows the passengers will take. The order of passengers should be the same as in input. | [
"2\n3 1\n0011\n",
"6\n10 8 9 11 13 5\n010010011101\n"
] | [
"2 1 1 2 \n",
"6 6 2 3 3 1 4 4 1 2 5 5 \n"
] | In the first example the first passenger (introvert) chooses the row $2$, because it has the seats with smallest width. The second passenger (introvert) chooses the row $1$, because it is the only empty row now. The third passenger (extrovert) chooses the row $1$, because it has exactly one occupied seat and the seat w... | 1,000 | [
{
"input": "2\n3 1\n0011",
"output": "2 1 1 2 "
},
{
"input": "6\n10 8 9 11 13 5\n010010011101",
"output": "6 6 2 3 3 1 4 4 1 2 5 5 "
},
{
"input": "1\n1\n01",
"output": "1 1 "
},
{
"input": "1\n1000000\n01",
"output": "1 1 "
},
{
"input": "2\n1 1000000\n0011",
... | 1,643,424,410 | 2,147,483,647 | PyPy 3 | OK | TESTS | 49 | 1,232 | 39,219,200 | import math
import sys
import queue
from heapq import heappop, heappush
import random
def solve():
n = int(input())
w = list(map(int, input().split()))
s = str(input())
row = {w[i]: i + 1 for i in range(n)}
free_2 = []
for i in range(n):
heappush(free_2, (w[i], w[i]))... | Title: Bus of Characters
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In the Bus of Characters there are $n$ rows of seat, each having $2$ seats. The width of both seats in the $i$-th row is $w_i$ centimeters. All integers $w_i$ are distinct.
Initially the bus is empty. On each of $2n$... | ```python
import math
import sys
import queue
from heapq import heappop, heappush
import random
def solve():
n = int(input())
w = list(map(int, input().split()))
s = str(input())
row = {w[i]: i + 1 for i in range(n)}
free_2 = []
for i in range(n):
heappush(free_2, (w[... | 3 | |
822 | A | I'm bored with life | PROGRAMMING | 800 | [
"implementation",
"math",
"number theory"
] | null | null | Holidays have finished. Thanks to the help of the hacker Leha, Noora managed to enter the university of her dreams which is located in a town Pavlopolis. It's well known that universities provide students with dormitory for the period of university studies. Consequently Noora had to leave Vičkopolis and move to Pavlopo... | The first and single line contains two integers *A* and *B* (1<=≤<=*A*,<=*B*<=≤<=109,<=*min*(*A*,<=*B*)<=≤<=12). | Print a single integer denoting the greatest common divisor of integers *A*! and *B*!. | [
"4 3\n"
] | [
"6\n"
] | Consider the sample.
4! = 1·2·3·4 = 24. 3! = 1·2·3 = 6. The greatest common divisor of integers 24 and 6 is exactly 6. | 500 | [
{
"input": "4 3",
"output": "6"
},
{
"input": "10 399603090",
"output": "3628800"
},
{
"input": "6 973151934",
"output": "720"
},
{
"input": "2 841668075",
"output": "2"
},
{
"input": "7 415216919",
"output": "5040"
},
{
"input": "3 283733059",
"ou... | 1,673,329,461 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 1 | 1,000 | 1,843,200 | import math
a,b=map(int, input().split())
b=math.factorial(b)
print(b) | Title: I'm bored with life
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Holidays have finished. Thanks to the help of the hacker Leha, Noora managed to enter the university of her dreams which is located in a town Pavlopolis. It's well known that universities provide students with dormi... | ```python
import math
a,b=map(int, input().split())
b=math.factorial(b)
print(b)
``` | 0 | |
103 | A | Testing Pants for Sadness | PROGRAMMING | 1,100 | [
"greedy",
"implementation",
"math"
] | A. Testing Pants for Sadness | 2 | 256 | The average miner Vaganych took refresher courses. As soon as a miner completes the courses, he should take exams. The hardest one is a computer test called "Testing Pants for Sadness".
The test consists of *n* questions; the questions are to be answered strictly in the order in which they are given, from question 1 t... | The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100). It is the number of questions in the test. The second line contains space-separated *n* positive integers *a**i* (1<=≤<=*a**i*<=≤<=109), the number of answer variants to question *i*. | Print a single number — the minimal number of clicks needed to pass the test it the worst-case scenario.
Please do not use the %lld specificator to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specificator. | [
"2\n1 1\n",
"2\n2 2\n",
"1\n10\n"
] | [
"2",
"5",
"10"
] | Note to the second sample. In the worst-case scenario you will need five clicks:
- the first click selects the first variant to the first question, this answer turns out to be wrong. - the second click selects the second variant to the first question, it proves correct and we move on to the second question; - the ... | 500 | [
{
"input": "2\n1 1",
"output": "2"
},
{
"input": "2\n2 2",
"output": "5"
},
{
"input": "1\n10",
"output": "10"
},
{
"input": "3\n2 4 1",
"output": "10"
},
{
"input": "4\n5 5 3 1",
"output": "22"
},
{
"input": "2\n1000000000 1000000000",
"output": "... | 1,576,509,995 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 3 | 248 | 0 | n=int(input())
ans=list(map(int,input().split()))
for i in range(len(ans)-2,-1,-1):
ans[i]+=ans[i-1]-1
print(sum(ans)) | Title: Testing Pants for Sadness
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
The average miner Vaganych took refresher courses. As soon as a miner completes the courses, he should take exams. The hardest one is a computer test called "Testing Pants for Sadness".
The test consists of *n* q... | ```python
n=int(input())
ans=list(map(int,input().split()))
for i in range(len(ans)-2,-1,-1):
ans[i]+=ans[i-1]-1
print(sum(ans))
``` | 0 |
193 | A | Cutting Figure | PROGRAMMING | 1,700 | [
"constructive algorithms",
"graphs",
"trees"
] | null | null | You've gotten an *n*<=×<=*m* sheet of squared paper. Some of its squares are painted. Let's mark the set of all painted squares as *A*. Set *A* is connected. Your task is to find the minimum number of squares that we can delete from set *A* to make it not connected.
A set of painted squares is called connected, if for... | The first input line contains two space-separated integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=50) — the sizes of the sheet of paper.
Each of the next *n* lines contains *m* characters — the description of the sheet of paper: the *j*-th character of the *i*-th line equals either "#", if the corresponding square is paint... | On the first line print the minimum number of squares that need to be deleted to make set *A* not connected. If it is impossible, print -1. | [
"5 4\n####\n#..#\n#..#\n#..#\n####\n",
"5 5\n#####\n#...#\n#####\n#...#\n#####\n"
] | [
"2\n",
"2\n"
] | In the first sample you can delete any two squares that do not share a side. After that the set of painted squares is not connected anymore.
The note to the second sample is shown on the figure below. To the left there is a picture of the initial set of squares. To the right there is a set with deleted squares. The de... | 500 | [
{
"input": "5 4\n####\n#..#\n#..#\n#..#\n####",
"output": "2"
},
{
"input": "5 5\n#####\n#...#\n#####\n#...#\n#####",
"output": "2"
},
{
"input": "1 10\n.########.",
"output": "1"
},
{
"input": "1 1\n#",
"output": "-1"
},
{
"input": "3 3\n.#.\n###\n.#.",
"outp... | 1,690,342,054 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 15 | 310 | 1,024,000 |
if __name__ == '__main__':
n, m = map(int, input().split())
grand = []
for i in range(n):
grand.append(list(input()))
total = sum(grand[i][j] == '#' for j in range(m) for i in range(n))
if total < 3:
print(-1)
exit(0)
dir = [[0, -1], [0, 1], [-1, 0], [1, 0]]
... | Title: Cutting Figure
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You've gotten an *n*<=×<=*m* sheet of squared paper. Some of its squares are painted. Let's mark the set of all painted squares as *A*. Set *A* is connected. Your task is to find the minimum number of squares that we can... | ```python
if __name__ == '__main__':
n, m = map(int, input().split())
grand = []
for i in range(n):
grand.append(list(input()))
total = sum(grand[i][j] == '#' for j in range(m) for i in range(n))
if total < 3:
print(-1)
exit(0)
dir = [[0, -1], [0, 1], [-1, 0]... | -1 | |
468 | C | Hack it! | PROGRAMMING | 2,500 | [
"binary search",
"constructive algorithms",
"math"
] | null | null | Little X has met the following problem recently.
Let's define *f*(*x*) as the sum of digits in decimal representation of number *x* (for example, *f*(1234)<==<=1<=+<=2<=+<=3<=+<=4). You are to calculate
Of course Little X has solved this problem quickly, has locked it, and then has tried to hack others. He has seen... | The first line contains a single integer *a* (1<=≤<=*a*<=≤<=1018). | Print two integers: *l*,<=*r* (1<=≤<=*l*<=≤<=*r*<=<<=10200) — the required test data. Leading zeros aren't allowed. It's guaranteed that the solution exists. | [
"46\n",
"126444381000032\n"
] | [
"1 10\n",
"2333333 2333333333333\n"
] | none | 1,500 | [
{
"input": "46",
"output": "1 10"
},
{
"input": "126444381000032",
"output": "2333333 2333333333333"
},
{
"input": "69645082595",
"output": "613752823618441225798858488535 713259406474207764329704856394"
},
{
"input": "70602205995",
"output": "11 2492213340204320744986569... | 1,645,195,131 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 51 | 311 | 14,643,200 | from collections import defaultdict
a = defaultdict(set)
mod = int(input())
def F(x: str):
if(len(x) == 1):
return int(x) * (int(x) + 1) // 2
else:
f = int(x[0])
return f * (f-1) // 2 * (10**(len(x)-1)) + f * 45 * (len(x) - 1) * 10**(len(x)-2) + f * (int(x[1:]) + 1) + F(x[1:])
for i in range(10... | Title: Hack it!
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Little X has met the following problem recently.
Let's define *f*(*x*) as the sum of digits in decimal representation of number *x* (for example, *f*(1234)<==<=1<=+<=2<=+<=3<=+<=4). You are to calculate
Of course Little X ... | ```python
from collections import defaultdict
a = defaultdict(set)
mod = int(input())
def F(x: str):
if(len(x) == 1):
return int(x) * (int(x) + 1) // 2
else:
f = int(x[0])
return f * (f-1) // 2 * (10**(len(x)-1)) + f * 45 * (len(x) - 1) * 10**(len(x)-2) + f * (int(x[1:]) + 1) + F(x[1:])
for i i... | 3 | |
96 | A | Football | PROGRAMMING | 900 | [
"implementation",
"strings"
] | A. Football | 2 | 256 | Petya loves football very much. One day, as he was watching a football match, he was writing the players' current positions on a piece of paper. To simplify the situation he depicted it as a string consisting of zeroes and ones. A zero corresponds to players of one team; a one corresponds to players of another team. If... | The first input line contains a non-empty string consisting of characters "0" and "1", which represents players. The length of the string does not exceed 100 characters. There's at least one player from each team present on the field. | Print "YES" if the situation is dangerous. Otherwise, print "NO". | [
"001001\n",
"1000000001\n"
] | [
"NO\n",
"YES\n"
] | none | 500 | [
{
"input": "001001",
"output": "NO"
},
{
"input": "1000000001",
"output": "YES"
},
{
"input": "00100110111111101",
"output": "YES"
},
{
"input": "11110111111111111",
"output": "YES"
},
{
"input": "01",
"output": "NO"
},
{
"input": "10100101",
"outp... | 1,668,105,107 | 2,147,483,647 | Python 3 | OK | TESTS | 44 | 92 | 0 | n=(input())
max0=0
count0=0
for c in n:
if c=="0":
count0+=1
else:
if count0>max0:
max0=count0
count0=0
if count0>max0:
max0=count0
max1=0
count1=0
for c in n:
if c=="1":
count1+=1
else:
if count1>max1:
max1=count1
count1=0
if c... | Title: Football
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Petya loves football very much. One day, as he was watching a football match, he was writing the players' current positions on a piece of paper. To simplify the situation he depicted it as a string consisting of zeroes and ones. A... | ```python
n=(input())
max0=0
count0=0
for c in n:
if c=="0":
count0+=1
else:
if count0>max0:
max0=count0
count0=0
if count0>max0:
max0=count0
max1=0
count1=0
for c in n:
if c=="1":
count1+=1
else:
if count1>max1:
max1=count1
cou... | 3.977 |
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,621,151,544 | 2,147,483,647 | PyPy 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | #include <iostream>
using namespace std;
int main() {
char string[102];
int capitalCount = 0, lowerCount = 0;
cin >> string;
for(int i = 0; string[i] != '\0'; i++) {
if(int(string[i]) >= 97)
lowerCount++;
else
capitalCount++;
}
if(lowerCount >= capitalCount) {
for(i... | 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
#include <iostream>
using namespace std;
int main() {
char string[102];
int capitalCount = 0, lowerCount = 0;
cin >> string;
for(int i = 0; string[i] != '\0'; i++) {
if(int(string[i]) >= 97)
lowerCount++;
else
capitalCount++;
}
if(lowerCount >= capitalCount) {
... | -1 |
379 | A | New Year Candles | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Vasily the Programmer loves romance, so this year he decided to illuminate his room with candles.
Vasily has *a* candles.When Vasily lights up a new candle, it first burns for an hour and then it goes out. Vasily is smart, so he can make *b* went out candles into a new candle. As a result, this new candle can be used ... | The single line contains two integers, *a* and *b* (1<=≤<=*a*<=≤<=1000; 2<=≤<=*b*<=≤<=1000). | Print a single integer — the number of hours Vasily can light up the room for. | [
"4 2\n",
"6 3\n"
] | [
"7\n",
"8\n"
] | Consider the first sample. For the first four hours Vasily lights up new candles, then he uses four burned out candles to make two new ones and lights them up. When these candles go out (stop burning), Vasily can make another candle. Overall, Vasily can light up the room for 7 hours. | 500 | [
{
"input": "4 2",
"output": "7"
},
{
"input": "6 3",
"output": "8"
},
{
"input": "1000 1000",
"output": "1001"
},
{
"input": "123 5",
"output": "153"
},
{
"input": "1000 2",
"output": "1999"
},
{
"input": "1 2",
"output": "1"
},
{
"input": ... | 1,682,933,711 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 3 | 46 | 0 | import math
a, b = input().split(" ")
a, b, i_a = int(a), int(b), int(a)
i_value = a
#print(i_a)
while i_a >= b:
dec = i_a % b
i_a = math.floor((i_a+int(dec))/b)
#print(dec)
i_value += i_a
#print(i_value)
#print(i_a)
print(int(i_value))
| Title: New Year Candles
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasily the Programmer loves romance, so this year he decided to illuminate his room with candles.
Vasily has *a* candles.When Vasily lights up a new candle, it first burns for an hour and then it goes out. Vasily is s... | ```python
import math
a, b = input().split(" ")
a, b, i_a = int(a), int(b), int(a)
i_value = a
#print(i_a)
while i_a >= b:
dec = i_a % b
i_a = math.floor((i_a+int(dec))/b)
#print(dec)
i_value += i_a
#print(i_value)
#print(i_a)
print(int(i_value))
``` | 0 | |
182 | B | Vasya's Calendar | PROGRAMMING | 1,000 | [
"implementation"
] | null | null | Vasya lives in a strange world. The year has *n* months and the *i*-th month has *a**i* days. Vasya got a New Year present — the clock that shows not only the time, but also the date.
The clock's face can display any number from 1 to *d*. It is guaranteed that *a**i*<=≤<=*d* for all *i* from 1 to *n*. The clock does n... | The first line contains the single number *d* — the maximum number of the day that Vasya's clock can show (1<=≤<=*d*<=≤<=106).
The second line contains a single integer *n* — the number of months in the year (1<=≤<=*n*<=≤<=2000).
The third line contains *n* space-separated integers: *a**i* (1<=≤<=*a**i*<=≤<=*d*) — th... | Print a single number — the number of times Vasya manually increased the day number by one throughout the last year. | [
"4\n2\n2 2\n",
"5\n3\n3 4 3\n",
"31\n12\n31 28 31 30 31 30 31 31 30 31 30 31\n"
] | [
"2\n",
"3\n",
"7\n"
] | In the first sample the situation is like this:
- Day 1. Month 1. The clock shows 1. Vasya changes nothing. - Day 2. Month 1. The clock shows 2. Vasya changes nothing. - Day 1. Month 2. The clock shows 3. Vasya manually increases the day number by 1. After that the clock shows 4. Vasya increases the day number by ... | 500 | [
{
"input": "4\n2\n2 2",
"output": "2"
},
{
"input": "5\n3\n3 4 3",
"output": "3"
},
{
"input": "31\n12\n31 28 31 30 31 30 31 31 30 31 30 31",
"output": "7"
},
{
"input": "1\n1\n1",
"output": "0"
},
{
"input": "1\n2\n1 1",
"output": "0"
},
{
"input": "2... | 1,602,225,324 | 2,147,483,647 | PyPy 3 | OK | TESTS | 40 | 280 | 1,638,400 | d=int(input())
n=int(input())
count=0
arr=[int(x) for x in input().split()]
for i in range(n-1):
if d>arr[i]:
count+=d-arr[i]
print(count)
| Title: Vasya's Calendar
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vasya lives in a strange world. The year has *n* months and the *i*-th month has *a**i* days. Vasya got a New Year present — the clock that shows not only the time, but also the date.
The clock's face can display any ... | ```python
d=int(input())
n=int(input())
count=0
arr=[int(x) for x in input().split()]
for i in range(n-1):
if d>arr[i]:
count+=d-arr[i]
print(count)
``` | 3 | |
474 | B | Worms | PROGRAMMING | 1,200 | [
"binary search",
"implementation"
] | null | null | It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole *n* ordered piles of worms such that *i*-th pile contains *a**i* worms. He labeled all these worms with consecutive integers: worms in first pile are labeled with numbers 1 to *a*1, worms in second pile are labeled w... | The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105), the number of piles.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=103, *a*1<=+<=*a*2<=+<=...<=+<=*a**n*<=≤<=106), where *a**i* is the number of worms in the *i*-th pile.
The third line contains single integer *m* (... | Print *m* lines to the standard output. The *i*-th line should contain an integer, representing the number of the pile where the worm labeled with the number *q**i* is. | [
"5\n2 7 3 4 9\n3\n1 25 11\n"
] | [
"1\n5\n3\n"
] | For the sample input:
- The worms with labels from [1, 2] are in the first pile. - The worms with labels from [3, 9] are in the second pile. - The worms with labels from [10, 12] are in the third pile. - The worms with labels from [13, 16] are in the fourth pile. - The worms with labels from [17, 25] are in the f... | 1,000 | [
{
"input": "5\n2 7 3 4 9\n3\n1 25 11",
"output": "1\n5\n3"
}
] | 1,687,905,934 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 2 | 1,000 | 2,867,200 | n = int(input())
ll = list(map(int, input().split()))
mm = int(input())
g = list(map(int, input().split()));
def hi(l, x, m):
s = sum(l[:m])
return x > s
for i in range(mm):
x = g[i]
l = 0
r = n
while r - l > 1:
m = (l + r) // 2
if hi(ll, x, m):
l = m
else:
r = m
print(l+1) | Title: Worms
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch.
Marmot brought Mole *n* ordered piles of worms such that *i*-th pile contains *a**i* worms. He labeled all these worms with consecutive integers:... | ```python
n = int(input())
ll = list(map(int, input().split()))
mm = int(input())
g = list(map(int, input().split()));
def hi(l, x, m):
s = sum(l[:m])
return x > s
for i in range(mm):
x = g[i]
l = 0
r = n
while r - l > 1:
m = (l + r) // 2
if hi(ll, x, m):
l = m
else:
r = m
print(l... | 0 | |
842 | A | Kirill And The Game | PROGRAMMING | 1,200 | [
"brute force",
"two pointers"
] | null | null | Kirill plays a new computer game. He came to the potion store where he can buy any potion. Each potion is characterized by two integers — amount of experience and cost. The efficiency of a potion is the ratio of the amount of experience to the cost. Efficiency may be a non-integer number.
For each two integer numbers ... | First string contains five integer numbers *l*, *r*, *x*, *y*, *k* (1<=≤<=*l*<=≤<=*r*<=≤<=107, 1<=≤<=*x*<=≤<=*y*<=≤<=107, 1<=≤<=*k*<=≤<=107). | Print "YES" without quotes if a potion with efficiency exactly *k* can be bought in the store and "NO" without quotes otherwise.
You can output each of the letters in any register. | [
"1 10 1 10 1\n",
"1 5 6 10 1\n"
] | [
"YES",
"NO"
] | none | 500 | [
{
"input": "1 10 1 10 1",
"output": "YES"
},
{
"input": "1 5 6 10 1",
"output": "NO"
},
{
"input": "1 1 1 1 1",
"output": "YES"
},
{
"input": "1 1 1 1 2",
"output": "NO"
},
{
"input": "1 100000 1 100000 100000",
"output": "YES"
},
{
"input": "1 100000 ... | 1,559,033,208 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 4 | 109 | 0 | l, r, x, y, k = [int(x) for x in (input().split())]
a = (r - l + 1)
b = (y - x + 1)
c = a / b
if (l <= a <= r) and (x <= b <= y) and (c == k):
print('YES')
else:
print('NO') | Title: Kirill And The Game
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Kirill plays a new computer game. He came to the potion store where he can buy any potion. Each potion is characterized by two integers — amount of experience and cost. The efficiency of a potion is the ratio of the... | ```python
l, r, x, y, k = [int(x) for x in (input().split())]
a = (r - l + 1)
b = (y - x + 1)
c = a / b
if (l <= a <= r) and (x <= b <= y) and (c == k):
print('YES')
else:
print('NO')
``` | 0 | |
1 | A | Theatre Square | PROGRAMMING | 1,000 | [
"math"
] | A. Theatre Square | 1 | 256 | Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size *a*<=×<=*a*.
What is the least number of flagstones needed to pave the... | The input contains three positive integer numbers in the first line: *n*,<=<=*m* and *a* (1<=≤<=<=*n*,<=*m*,<=*a*<=≤<=109). | Write the needed number of flagstones. | [
"6 6 4\n"
] | [
"4\n"
] | none | 0 | [
{
"input": "6 6 4",
"output": "4"
},
{
"input": "1 1 1",
"output": "1"
},
{
"input": "2 1 1",
"output": "2"
},
{
"input": "1 2 1",
"output": "2"
},
{
"input": "2 2 1",
"output": "4"
},
{
"input": "2 1 2",
"output": "1"
},
{
"input": "1 1 3"... | 1,664,341,172 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 1 | 46 | 0 | n,m, a = map(int,input().split())
print((n*m)//(a**2) + 2)
| Title: Theatre Square
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
Theatre Square in the capital city of Berland has a rectangular shape with the size *n*<=×<=*m* meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each ... | ```python
n,m, a = map(int,input().split())
print((n*m)//(a**2) + 2)
``` | 0 |
221 | A | Little Elephant and Function | PROGRAMMING | 1,000 | [
"implementation",
"math"
] | null | null | The Little Elephant enjoys recursive functions.
This time he enjoys the sorting function. Let *a* is a permutation of an integers from 1 to *n*, inclusive, and *a**i* denotes the *i*-th element of the permutation. The Little Elephant's recursive function *f*(*x*), that sorts the first *x* permutation's elements, works... | A single line contains integer *n* (1<=≤<=*n*<=≤<=1000) — the size of permutation. | In a single line print *n* distinct integers from 1 to *n* — the required permutation. Numbers in a line should be separated by spaces.
It is guaranteed that the answer exists. | [
"1\n",
"2\n"
] | [
"1 ",
"2 1 "
] | none | 500 | [
{
"input": "1",
"output": "1 "
},
{
"input": "2",
"output": "2 1 "
},
{
"input": "3",
"output": "3 1 2 "
},
{
"input": "4",
"output": "4 1 2 3 "
},
{
"input": "5",
"output": "5 1 2 3 4 "
},
{
"input": "6",
"output": "6 1 2 3 4 5 "
},
{
"inp... | 1,626,771,231 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 92 | 6,758,400 | m=1000
#def f(i,n):
# if i<n:
# a[i],a[i-1]=a[i-1],a[i]
# f(i+1,n)
n=int(input())
a=[i for i in range(1,n+1)]
a.pop(0)
a.append(1)
#f(1,n)
print(*a[0:n])
| Title: Little Elephant and Function
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
The Little Elephant enjoys recursive functions.
This time he enjoys the sorting function. Let *a* is a permutation of an integers from 1 to *n*, inclusive, and *a**i* denotes the *i*-th element of the perm... | ```python
m=1000
#def f(i,n):
# if i<n:
# a[i],a[i-1]=a[i-1],a[i]
# f(i+1,n)
n=int(input())
a=[i for i in range(1,n+1)]
a.pop(0)
a.append(1)
#f(1,n)
print(*a[0:n])
``` | 0 | |
31 | A | Worms Evolution | PROGRAMMING | 1,200 | [
"implementation"
] | A. Worms Evolution | 2 | 256 | Professor Vasechkin is studying evolution of worms. Recently he put forward hypotheses that all worms evolve by division. There are *n* forms of worms. Worms of these forms have lengths *a*1, *a*2, ..., *a**n*. To prove his theory, professor needs to find 3 different forms that the length of the first form is equal to ... | The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of worm's forms. The second line contains *n* space-separated integers *a**i* (1<=≤<=*a**i*<=≤<=1000) — lengths of worms of each form. | Output 3 distinct integers *i* *j* *k* (1<=≤<=*i*,<=*j*,<=*k*<=≤<=*n*) — such indexes of worm's forms that *a**i*<==<=*a**j*<=+<=*a**k*. If there is no such triple, output -1. If there are several solutions, output any of them. It possible that *a**j*<==<=*a**k*. | [
"5\n1 2 3 5 7\n",
"5\n1 8 1 5 1\n"
] | [
"3 2 1\n",
"-1\n"
] | none | 500 | [
{
"input": "5\n1 2 3 5 7",
"output": "3 2 1"
},
{
"input": "5\n1 8 1 5 1",
"output": "-1"
},
{
"input": "4\n303 872 764 401",
"output": "-1"
},
{
"input": "6\n86 402 133 524 405 610",
"output": "6 4 1"
},
{
"input": "8\n217 779 418 895 996 473 3 22",
"output":... | 1,696,015,230 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 0 | 92 | 0 | def find_worm_triple(n, worm_lengths):
worm_dict = {}
for i, length in enumerate(worm_lengths):
if length in worm_dict:
worm_dict[length].append(i + 1)
else:
worm_dict[length] = [i + 1]
for i in range(n):
for j in range(n):
if i !=... | Title: Worms Evolution
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
Professor Vasechkin is studying evolution of worms. Recently he put forward hypotheses that all worms evolve by division. There are *n* forms of worms. Worms of these forms have lengths *a*1, *a*2, ..., *a**n*. To prove his... | ```python
def find_worm_triple(n, worm_lengths):
worm_dict = {}
for i, length in enumerate(worm_lengths):
if length in worm_dict:
worm_dict[length].append(i + 1)
else:
worm_dict[length] = [i + 1]
for i in range(n):
for j in range(n):
... | 0 |
723 | C | Polycarp at the Radio | PROGRAMMING | 1,600 | [
"greedy"
] | null | null | Polycarp is a music editor at the radio station. He received a playlist for tomorrow, that can be represented as a sequence *a*1,<=*a*2,<=...,<=*a**n*, where *a**i* is a band, which performs the *i*-th song. Polycarp likes bands with the numbers from 1 to *m*, but he doesn't really like others.
We define as *b**j* th... | The first line of the input contains two integers *n* and *m* (1<=≤<=*m*<=≤<=*n*<=≤<=2000).
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109), where *a**i* is the performer of the *i*-th song. | In the first line print two integers: the maximum possible value of the minimum among the *b**j* (1<=≤<=*j*<=≤<=*m*), where *b**j* is the number of songs in the changed playlist performed by the *j*-th band, and the minimum number of changes in the playlist Polycarp needs to make.
In the second line print the changed ... | [
"4 2\n1 2 3 2\n",
"7 3\n1 3 2 2 2 2 1\n",
"4 4\n1000000000 100 7 1000000000\n"
] | [
"2 1\n1 2 1 2 \n",
"2 1\n1 3 3 2 2 2 1 \n",
"1 4\n1 2 3 4 \n"
] | In the first sample, after Polycarp's changes the first band performs two songs (*b*<sub class="lower-index">1</sub> = 2), and the second band also performs two songs (*b*<sub class="lower-index">2</sub> = 2). Thus, the minimum of these values equals to 2. It is impossible to achieve a higher minimum value by any chang... | 1,500 | [
{
"input": "4 2\n1 2 3 2",
"output": "2 1\n1 2 1 2 "
},
{
"input": "7 3\n1 3 2 2 2 2 1",
"output": "2 1\n1 3 3 2 2 2 1 "
},
{
"input": "4 4\n1000000000 100 7 1000000000",
"output": "1 4\n1 2 3 4 "
},
{
"input": "1 1\n1",
"output": "1 0\n1 "
},
{
"input": "1 1\n381... | 1,686,941,957 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 50 | 93 | 4,812,800 | import sys
input = lambda: sys.stdin.readline().rstrip()
from collections import defaultdict
N,M = map(int, input().split())
A = list(map(int, input().split()))
others = []
lib = defaultdict(list)
t = N//M
m = N%M
for i in range(N):
if A[i]<=M:
if len(lib[A[i]])<t:
lib[A[i]].appe... | Title: Polycarp at the Radio
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Polycarp is a music editor at the radio station. He received a playlist for tomorrow, that can be represented as a sequence *a*1,<=*a*2,<=...,<=*a**n*, where *a**i* is a band, which performs the *i*-th song. Polyc... | ```python
import sys
input = lambda: sys.stdin.readline().rstrip()
from collections import defaultdict
N,M = map(int, input().split())
A = list(map(int, input().split()))
others = []
lib = defaultdict(list)
t = N//M
m = N%M
for i in range(N):
if A[i]<=M:
if len(lib[A[i]])<t:
lib[... | 3 | |
340 | A | The Wall | PROGRAMMING | 1,200 | [
"math"
] | null | null | Iahub and his friend Floyd have started painting a wall. Iahub is painting the wall red and Floyd is painting it pink. You can consider the wall being made of a very large number of bricks, numbered 1, 2, 3 and so on.
Iahub has the following scheme of painting: he skips *x*<=-<=1 consecutive bricks, then he paints th... | The input will have a single line containing four integers in this order: *x*, *y*, *a*, *b*. (1<=≤<=*x*,<=*y*<=≤<=1000, 1<=≤<=*a*,<=*b*<=≤<=2·109, *a*<=≤<=*b*). | Output a single integer — the number of bricks numbered no less than *a* and no greater than *b* that are painted both red and pink. | [
"2 3 6 18\n"
] | [
"3"
] | Let's look at the bricks from *a* to *b* (*a* = 6, *b* = 18). The bricks colored in red are numbered 6, 8, 10, 12, 14, 16, 18. The bricks colored in pink are numbered 6, 9, 12, 15, 18. The bricks colored in both red and pink are numbered with 6, 12 and 18. | 500 | [
{
"input": "2 3 6 18",
"output": "3"
},
{
"input": "4 6 20 201",
"output": "15"
},
{
"input": "15 27 100 10000",
"output": "74"
},
{
"input": "105 60 3456 78910",
"output": "179"
},
{
"input": "1 1 1000 100000",
"output": "99001"
},
{
"input": "3 2 5 5... | 1,411,317,446 | 2,147,483,647 | Python 3 | OK | TESTS | 35 | 124 | 0 | from math import ceil
def gcd(a,b):
while b:
a,b=b,a%b
return a
a=list(map(int,input().split()))
b=a[0]*a[1]//gcd(a[0],a[1])
print(int(a[3]/b)-ceil(a[2]/b)+1)
| Title: The Wall
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Iahub and his friend Floyd have started painting a wall. Iahub is painting the wall red and Floyd is painting it pink. You can consider the wall being made of a very large number of bricks, numbered 1, 2, 3 and so on.
Iahub ... | ```python
from math import ceil
def gcd(a,b):
while b:
a,b=b,a%b
return a
a=list(map(int,input().split()))
b=a[0]*a[1]//gcd(a[0],a[1])
print(int(a[3]/b)-ceil(a[2]/b)+1)
``` | 3 | |
50 | A | Domino piling | PROGRAMMING | 800 | [
"greedy",
"math"
] | A. Domino piling | 2 | 256 | You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions:
1. Each domino completely covers ... | In a single line you are given two integers *M* and *N* — board sizes in squares (1<=≤<=*M*<=≤<=*N*<=≤<=16). | Output one number — the maximal number of dominoes, which can be placed. | [
"2 4\n",
"3 3\n"
] | [
"4\n",
"4\n"
] | none | 500 | [
{
"input": "2 4",
"output": "4"
},
{
"input": "3 3",
"output": "4"
},
{
"input": "1 5",
"output": "2"
},
{
"input": "1 6",
"output": "3"
},
{
"input": "1 15",
"output": "7"
},
{
"input": "1 16",
"output": "8"
},
{
"input": "2 5",
"outpu... | 1,684,566,127 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 3 | 92 | 0 | dano = [int(x) for x in input().split()]
n = dano[0]
m = dano[1]
s = n * m
ans = n * m // 2
if ans % 2 != 0:
ans -= 1
print(ans) | Title: Domino piling
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
You are given a rectangular board of *M*<=×<=*N* squares. Also you are given an unlimited number of standard domino pieces of 2<=×<=1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as p... | ```python
dano = [int(x) for x in input().split()]
n = dano[0]
m = dano[1]
s = n * m
ans = n * m // 2
if ans % 2 != 0:
ans -= 1
print(ans)
``` | 0 |
222 | D | Olympiad | PROGRAMMING | 1,900 | [
"binary search",
"greedy",
"sortings",
"two pointers"
] | null | null | A boy named Vasya has taken part in an Olympiad. His teacher knows that in total Vasya got at least *x* points for both tours of the Olympiad. The teacher has the results of the first and the second tour of the Olympiad but the problem is, the results have only points, no names. The teacher has to know Vasya's chances.... | The first line contains two space-separated integers *n*,<=*x* (1<=≤<=*n*<=≤<=105; 0<=≤<=*x*<=≤<=2·105) — the number of Olympiad participants and the minimum number of points Vasya earned.
The second line contains *n* space-separated integers: *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=105) — the participants' point... | Print two space-separated integers — the best and the worst place Vasya could have got on the Olympiad. | [
"5 2\n1 1 1 1 1\n1 1 1 1 1\n",
"6 7\n4 3 5 6 4 4\n8 6 0 4 3 4\n"
] | [
"1 5\n",
"1 5\n"
] | In the first text sample all 5 participants earn 2 points each in any case. Depending on the jury's decision, Vasya can get the first (the best) as well as the last (the worst) fifth place.
In the second test sample in the best case scenario Vasya wins again: he can win 12 points and become the absolute winner if the ... | 2,000 | [
{
"input": "5 2\n1 1 1 1 1\n1 1 1 1 1",
"output": "1 5"
},
{
"input": "6 7\n4 3 5 6 4 4\n8 6 0 4 3 4",
"output": "1 5"
},
{
"input": "1 100\n56\n44",
"output": "1 1"
},
{
"input": "5 1\n1 2 3 4 5\n1 2 3 4 5",
"output": "1 5"
},
{
"input": "5 5\n2 2 2 2 2\n3 3 3 3 ... | 1,618,940,253 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | #include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
bool comp(int a, int b)
{
return a > b;
}
int main()
{
int n, x, prom, l, r, mid;
cin >> n >> x;
vector < int > v(n + 1);
for(int i = 0 ; i < n; i ++)
cin >> v[i];
for(int i = 0; i < n; i++)
{
cin >> prom;
... | Title: Olympiad
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
A boy named Vasya has taken part in an Olympiad. His teacher knows that in total Vasya got at least *x* points for both tours of the Olympiad. The teacher has the results of the first and the second tour of the Olympiad but th... | ```python
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
bool comp(int a, int b)
{
return a > b;
}
int main()
{
int n, x, prom, l, r, mid;
cin >> n >> x;
vector < int > v(n + 1);
for(int i = 0 ; i < n; i ++)
cin >> v[i];
for(int i = 0; i < n; i++)
{
cin ... | -1 | |
551 | B | ZgukistringZ | PROGRAMMING | 1,800 | [
"brute force",
"constructive algorithms",
"implementation",
"strings"
] | null | null | Professor GukiZ doesn't accept string as they are. He likes to swap some letters in string to obtain a new one.
GukiZ has strings *a*, *b*, and *c*. He wants to obtain string *k* by swapping some letters in *a*, so that *k* should contain as many non-overlapping substrings equal either to *b* or *c* as possible. Subst... | The first line contains string *a*, the second line contains string *b*, and the third line contains string *c* (1<=≤<=|*a*|,<=|*b*|,<=|*c*|<=≤<=105, where |*s*| denotes the length of string *s*).
All three strings consist only of lowercase English letters.
It is possible that *b* and *c* coincide. | Find one of possible strings *k*, as described in the problem statement. If there are multiple possible answers, print any of them. | [
"aaa\na\nb\n",
"pozdravstaklenidodiri\nniste\ndobri\n",
"abbbaaccca\nab\naca\n"
] | [
"aaa",
"nisteaadddiiklooprrvz",
"ababacabcc"
] | In the third sample, this optimal solutions has three non-overlaping substrings equal to either *b* or *c* on positions 1 – 2 (*ab*), 3 – 4 (*ab*), 5 – 7 (*aca*). In this sample, there exist many other optimal solutions, one of them would be *acaababbcc*. | 1,250 | [
{
"input": "aaa\na\nb",
"output": "aaa"
},
{
"input": "pozdravstaklenidodiri\nniste\ndobri",
"output": "nisteaadddiiklooprrvz"
},
{
"input": "abbbaaccca\nab\naca",
"output": "ababacabcc"
},
{
"input": "lemigazalemiolemilicomzalemljenje\nlemi\nzlo",
"output": "lemilemilemi... | 1,434,131,055 | 3,555 | Python 3 | WRONG_ANSWER | PRETESTS | 5 | 46 | 0 | sa = input()
sb = input()
sc = input()
def freq(s):
d = {}
for char in "abcdefghijklmnopqrstuvwxyz":
d[char] = 0
for char in s:
d[char] += 1
return d
da = freq(sa)
orig = da.copy()
db = freq(sb)
dc = freq(sc)
def highest(d):
m = len(sa)
for i in d:
if d[i] == 0:
... | Title: ZgukistringZ
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Professor GukiZ doesn't accept string as they are. He likes to swap some letters in string to obtain a new one.
GukiZ has strings *a*, *b*, and *c*. He wants to obtain string *k* by swapping some letters in *a*, so that *... | ```python
sa = input()
sb = input()
sc = input()
def freq(s):
d = {}
for char in "abcdefghijklmnopqrstuvwxyz":
d[char] = 0
for char in s:
d[char] += 1
return d
da = freq(sa)
orig = da.copy()
db = freq(sb)
dc = freq(sc)
def highest(d):
m = len(sa)
for i in d:
if d[i] =... | 0 | |
652 | C | Foe Pairs | PROGRAMMING | 1,800 | [
"combinatorics",
"sortings",
"two pointers"
] | null | null | You are given a permutation *p* of length *n*. Also you are given *m* foe pairs (*a**i*,<=*b**i*) (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*,<=*a**i*<=≠<=*b**i*).
Your task is to count the number of different intervals (*x*,<=*y*) (1<=≤<=*x*<=≤<=*y*<=≤<=*n*) that do not contain any foe pairs. So you shouldn't count intervals (*x... | The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=3·105) — the length of the permutation *p* and the number of foe pairs.
The second line contains *n* distinct integers *p**i* (1<=≤<=*p**i*<=≤<=*n*) — the elements of the permutation *p*.
Each of the next *m* lines contains two integers (*a**i*,<=*... | Print the only integer *c* — the number of different intervals (*x*,<=*y*) that does not contain any foe pairs.
Note that the answer can be too large, so you should use 64-bit integer type to store it. In C++ you can use the long long integer type and in Java you can use long integer type. | [
"4 2\n1 3 2 4\n3 2\n2 4\n",
"9 5\n9 7 2 3 1 4 6 5 8\n1 6\n4 5\n2 7\n7 2\n2 7\n"
] | [
"5\n",
"20\n"
] | In the first example the intervals from the answer are (1, 1), (1, 2), (2, 2), (3, 3) and (4, 4). | 0 | [
{
"input": "4 2\n1 3 2 4\n3 2\n2 4",
"output": "5"
},
{
"input": "9 5\n9 7 2 3 1 4 6 5 8\n1 6\n4 5\n2 7\n7 2\n2 7",
"output": "20"
},
{
"input": "2 1\n1 2\n1 2",
"output": "2"
},
{
"input": "10 3\n4 10 5 1 6 8 9 2 3 7\n10 5\n2 10\n4 1",
"output": "39"
},
{
"input"... | 1,665,729,588 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 24 | 482 | 47,308,800 | from sys import stdin
input=lambda :stdin.readline()[:-1]
n,m=map(int,input().split())
p=list(map(lambda x:int(x)-1,input().split()))
q=[0]*n
for i in range(n):
q[p[i]]=i
ng=[[] for i in range(n)]
for i in range(m):
x,y=map(lambda x:int(x)-1,input().split())
x=q[x]
y=q[y]
if x<y:
ng[x].ap... | Title: Foe Pairs
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a permutation *p* of length *n*. Also you are given *m* foe pairs (*a**i*,<=*b**i*) (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*,<=*a**i*<=≠<=*b**i*).
Your task is to count the number of different intervals (*x*,<=*y*) (1<=... | ```python
from sys import stdin
input=lambda :stdin.readline()[:-1]
n,m=map(int,input().split())
p=list(map(lambda x:int(x)-1,input().split()))
q=[0]*n
for i in range(n):
q[p[i]]=i
ng=[[] for i in range(n)]
for i in range(m):
x,y=map(lambda x:int(x)-1,input().split())
x=q[x]
y=q[y]
if x<y:
... | 3 | |
514 | C | Watto and Mechanism | PROGRAMMING | 2,000 | [
"binary search",
"data structures",
"hashing",
"string suffix structures",
"strings"
] | null | null | Watto, the owner of a spare parts store, has recently got an order for the mechanism that can process strings in a certain way. Initially the memory of the mechanism is filled with *n* strings. Then the mechanism should be able to process queries of the following type: "Given string *s*, determine if the memory of the ... | The first line contains two non-negative numbers *n* and *m* (0<=≤<=*n*<=≤<=3·105, 0<=≤<=*m*<=≤<=3·105) — the number of the initial strings and the number of queries, respectively.
Next follow *n* non-empty strings that are uploaded to the memory of the mechanism.
Next follow *m* non-empty strings that are the querie... | For each query print on a single line "YES" (without the quotes), if the memory of the mechanism contains the required string, otherwise print "NO" (without the quotes). | [
"2 3\naaaaa\nacacaca\naabaa\nccacacc\ncaaac\n"
] | [
"YES\nNO\nNO\n"
] | none | 2,000 | [
{
"input": "2 3\naaaaa\nacacaca\naabaa\nccacacc\ncaaac",
"output": "YES\nNO\nNO"
},
{
"input": "1 5\nacbacbacb\ncbacbacb\nacbacbac\naacbacbacb\nacbacbacbb\nacbaabacb",
"output": "NO\nNO\nNO\nNO\nYES"
},
{
"input": "5 4\nab\ncacab\ncbabc\nacc\ncacab\nabc\naa\nacbca\ncb",
"output": "YE... | 1,678,886,695 | 2,147,483,647 | PyPy 3 | TIME_LIMIT_EXCEEDED | TESTS | 20 | 3,000 | 56,934,400 | n,m=map(int,input().split())
M=9999999999999983
v=set()
for i in range(n):
s=input()
l=len(s)
pow=1
h=0
for i in range(l):
h,pow=(h+ord(s[i])*pow)%M,(pow*203)%M
pow=1
for i in range(l):
for j in range(97,100):
if ord(s[i])!=j:
v.add((h+(j-ord(s[i]))*pow)%M)
pow=(pow*203)%M
ans=[]
fo... | Title: Watto and Mechanism
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Watto, the owner of a spare parts store, has recently got an order for the mechanism that can process strings in a certain way. Initially the memory of the mechanism is filled with *n* strings. Then the mechanism sh... | ```python
n,m=map(int,input().split())
M=9999999999999983
v=set()
for i in range(n):
s=input()
l=len(s)
pow=1
h=0
for i in range(l):
h,pow=(h+ord(s[i])*pow)%M,(pow*203)%M
pow=1
for i in range(l):
for j in range(97,100):
if ord(s[i])!=j:
v.add((h+(j-ord(s[i]))*pow)%M)
pow=(pow*203)%M
... | 0 | |
863 | B | Kayaking | PROGRAMMING | 1,500 | [
"brute force",
"greedy",
"sortings"
] | null | null | Vadim is really keen on travelling. Recently he heard about kayaking activity near his town and became very excited about it, so he joined a party of kayakers.
Now the party is ready to start its journey, but firstly they have to choose kayaks. There are 2·*n* people in the group (including Vadim), and they have exact... | The first line contains one number *n* (2<=≤<=*n*<=≤<=50).
The second line contains 2·*n* integer numbers *w*1, *w*2, ..., *w*2*n*, where *w**i* is weight of person *i* (1<=≤<=*w**i*<=≤<=1000). | Print minimum possible total instability. | [
"2\n1 2 3 4\n",
"4\n1 3 4 6 3 4 100 200\n"
] | [
"1\n",
"5\n"
] | none | 0 | [
{
"input": "2\n1 2 3 4",
"output": "1"
},
{
"input": "4\n1 3 4 6 3 4 100 200",
"output": "5"
},
{
"input": "3\n305 139 205 406 530 206",
"output": "102"
},
{
"input": "3\n610 750 778 6 361 407",
"output": "74"
},
{
"input": "5\n97 166 126 164 154 98 221 7 51 47",
... | 1,617,064,148 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 6 | 109 | 307,200 | """
Pseudocode:
Read N
Read the input(), store in a list: weights
sort weights
instability;
for i (0, len weights - 2, 2):
instability = difference between 2
print instability
"""
N = input()
weights = list(map(int, input().split()))
weights.sort()
minCount = True
for i in range(0, len(weights) - 1):
... | Title: Kayaking
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vadim is really keen on travelling. Recently he heard about kayaking activity near his town and became very excited about it, so he joined a party of kayakers.
Now the party is ready to start its journey, but firstly they hav... | ```python
"""
Pseudocode:
Read N
Read the input(), store in a list: weights
sort weights
instability;
for i (0, len weights - 2, 2):
instability = difference between 2
print instability
"""
N = input()
weights = list(map(int, input().split()))
weights.sort()
minCount = True
for i in range(0, len(weigh... | 0 | |
47 | B | Coins | PROGRAMMING | 1,200 | [
"implementation"
] | B. Coins | 2 | 256 | One day Vasya came across three Berland coins. They didn't have any numbers that's why Vasya didn't understand how their denominations differ. He supposed that if one coin is heavier than the other one, then it should be worth more. Vasya weighed all the three pairs of coins on pan balance scales and told you the resul... | The input data contains the results of all the weighting, one result on each line. It is guaranteed that every coin pair was weighted exactly once. Vasya labelled the coins with letters «A», «B» and «C». Each result is a line that appears as (letter)(> or < sign)(letter). For example, if coin "A" proved lighter t... | It the results are contradictory, print Impossible. Otherwise, print without spaces the rearrangement of letters «A», «B» and «C» which represent the coins in the increasing order of their weights. | [
"A>B\nC<B\nA>C\n",
"A<B\nB>C\nC>A\n"
] | [
"CBA",
"ACB"
] | none | 1,000 | [
{
"input": "A>B\nC<B\nA>C",
"output": "CBA"
},
{
"input": "A<B\nB>C\nC>A",
"output": "ACB"
},
{
"input": "A<C\nB<A\nB>C",
"output": "Impossible"
},
{
"input": "A<B\nA<C\nB>C",
"output": "ACB"
},
{
"input": "B>A\nC<B\nC>A",
"output": "ACB"
},
{
"input":... | 1,682,875,642 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 62 | 0 | import sys
input = sys.stdin.readline
d = {"A": 1, "B": 1, "C": 1}
for i in range(3):
n = input().strip("\n")
if n[1] == ">":
d[n[0]] += d[n[-1]]
elif n[1] == "<":
d[n[-1]] += d[n[0]]
for i in sorted(d.items(), key=lambda x: x[-1]):
print(i[0], end="") | Title: Coins
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
One day Vasya came across three Berland coins. They didn't have any numbers that's why Vasya didn't understand how their denominations differ. He supposed that if one coin is heavier than the other one, then it should be worth more. ... | ```python
import sys
input = sys.stdin.readline
d = {"A": 1, "B": 1, "C": 1}
for i in range(3):
n = input().strip("\n")
if n[1] == ">":
d[n[0]] += d[n[-1]]
elif n[1] == "<":
d[n[-1]] += d[n[0]]
for i in sorted(d.items(), key=lambda x: x[-1]):
print(i[0], end="")
``` | 0 |
287 | B | Pipeline | PROGRAMMING | 1,700 | [
"binary search",
"math"
] | null | null | Vova, the Ultimate Thule new shaman, wants to build a pipeline. As there are exactly *n* houses in Ultimate Thule, Vova wants the city to have exactly *n* pipes, each such pipe should be connected to the water supply. A pipe can be connected to the water supply if there's water flowing out of it. Initially Vova has onl... | The first line contains two space-separated integers *n* and *k* (1<=≤<=*n*<=≤<=1018, 2<=≤<=*k*<=≤<=109).
Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier. | Print a single integer — the minimum number of splitters needed to build the pipeline. If it is impossible to build a pipeline with the given splitters, print -1. | [
"4 3\n",
"5 5\n",
"8 4\n"
] | [
"2\n",
"1\n",
"-1\n"
] | none | 1,500 | [
{
"input": "4 3",
"output": "2"
},
{
"input": "5 5",
"output": "1"
},
{
"input": "8 4",
"output": "-1"
},
{
"input": "1000000000000000000 1000000000",
"output": "-1"
},
{
"input": "499999998500000001 1000000000",
"output": "999955279"
},
{
"input": "49... | 1,624,884,883 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 3 | 400 | 46,284,800 | from bisect import bisect_left
x,k = list(map(int,input().split()))
a = []
a.append(k)
sum = k
for i in range(k-1,1,-1):
if sum>x:
break
a.append(sum+i-1)
pos = bisect_left(a,x)
if pos!=len(a) and a[pos]>=x:
print(pos+1)
else:
print(-1)
| Title: Pipeline
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Vova, the Ultimate Thule new shaman, wants to build a pipeline. As there are exactly *n* houses in Ultimate Thule, Vova wants the city to have exactly *n* pipes, each such pipe should be connected to the water supply. A pipe c... | ```python
from bisect import bisect_left
x,k = list(map(int,input().split()))
a = []
a.append(k)
sum = k
for i in range(k-1,1,-1):
if sum>x:
break
a.append(sum+i-1)
pos = bisect_left(a,x)
if pos!=len(a) and a[pos]>=x:
print(pos+1)
else:
print(-1)
``` | 0 | |
671 | B | Robin Hood | PROGRAMMING | 2,000 | [
"binary search",
"greedy"
] | null | null | We all know the impressive story of Robin Hood. Robin Hood uses his archery skills and his wits to steal the money from rich, and return it to the poor.
There are *n* citizens in Kekoland, each person has *c**i* coins. Each day, Robin Hood will take exactly 1 coin from the richest person in the city and he will give i... | The first line of the input contains two integers *n* and *k* (1<=≤<=*n*<=≤<=500<=000,<=0<=≤<=*k*<=≤<=109) — the number of citizens in Kekoland and the number of days left till Robin Hood's retirement.
The second line contains *n* integers, the *i*-th of them is *c**i* (1<=≤<=*c**i*<=≤<=109) — initial wealth of the *i... | Print a single line containing the difference between richest and poorest peoples wealth. | [
"4 1\n1 1 4 2\n",
"3 1\n2 2 2\n"
] | [
"2\n",
"0\n"
] | Lets look at how wealth changes through day in the first sample.
1. [1, 1, 4, 2] 1. [2, 1, 3, 2] or [1, 2, 3, 2]
So the answer is 3 - 1 = 2
In second sample wealth will remain the same for each person. | 1,000 | [
{
"input": "4 1\n1 1 4 2",
"output": "2"
},
{
"input": "3 1\n2 2 2",
"output": "0"
},
{
"input": "10 20\n6 4 7 10 4 5 5 3 7 10",
"output": "1"
},
{
"input": "30 7\n3 3 2 2 2 2 3 4 4 5 2 1 1 5 5 3 4 3 2 1 3 4 3 2 2 5 2 5 1 2",
"output": "2"
},
{
"input": "2 0\n182 ... | 1,464,513,630 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | #include<iostream>
#include<algorithm>
using namespace std;
int a[100001],ans,n,i,k;
main(){
cin>>n>>k;
for(i=0;i<n;i++)
cin>>a[i];
sort(a,a+n);
if(a[0]==a[n-1]){cout<<0;return 0;}
for(i=1;i<=k;i++){a[i]+=1;a[n-1-i]-=1;sort(a,a+n);}
sort(a,a+n);
cout<<a[n-1]-a[0];
system("pause");
}
| Title: Robin Hood
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
We all know the impressive story of Robin Hood. Robin Hood uses his archery skills and his wits to steal the money from rich, and return it to the poor.
There are *n* citizens in Kekoland, each person has *c**i* coins. Each... | ```python
#include<iostream>
#include<algorithm>
using namespace std;
int a[100001],ans,n,i,k;
main(){
cin>>n>>k;
for(i=0;i<n;i++)
cin>>a[i];
sort(a,a+n);
if(a[0]==a[n-1]){cout<<0;return 0;}
for(i=1;i<=k;i++){a[i]+=1;a[n-1-i]-=1;sort(a,a+n);}
sort(a,a+n);
cout<<a[n-1]-a[0];
system("pause");
}
``` | -1 | |
764 | A | Taymyr is calling you | PROGRAMMING | 800 | [
"brute force",
"implementation",
"math"
] | null | null | Comrade Dujikov is busy choosing artists for Timofey's birthday and is recieving calls from Taymyr from Ilia-alpinist.
Ilia-alpinist calls every *n* minutes, i.e. in minutes *n*, 2*n*, 3*n* and so on. Artists come to the comrade every *m* minutes, i.e. in minutes *m*, 2*m*, 3*m* and so on. The day is *z* minutes long,... | The only string contains three integers — *n*, *m* and *z* (1<=≤<=*n*,<=*m*,<=*z*<=≤<=104). | Print single integer — the minimum number of artists that should be killed so that there are no artists in the room when Ilia calls. | [
"1 1 10\n",
"1 2 5\n",
"2 3 9\n"
] | [
"10\n",
"2\n",
"1\n"
] | Taymyr is a place in the north of Russia.
In the first test the artists come each minute, as well as the calls, so we need to kill all of them.
In the second test we need to kill artists which come on the second and the fourth minutes.
In the third test — only the artist which comes on the sixth minute. | 500 | [
{
"input": "1 1 10",
"output": "10"
},
{
"input": "1 2 5",
"output": "2"
},
{
"input": "2 3 9",
"output": "1"
},
{
"input": "4 8 9",
"output": "1"
},
{
"input": "7 9 2",
"output": "0"
},
{
"input": "10000 10000 10000",
"output": "1"
},
{
"i... | 1,548,191,214 | 2,147,483,647 | Python 3 | OK | TESTS | 32 | 109 | 0 | def gcd(a, b):
if(b == 0):
return a
return gcd(b, a%b)
n, m, z = map(int, input().split())
lcm = (n*m)//gcd(n, m)
print(z//lcm)
| Title: Taymyr is calling you
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Comrade Dujikov is busy choosing artists for Timofey's birthday and is recieving calls from Taymyr from Ilia-alpinist.
Ilia-alpinist calls every *n* minutes, i.e. in minutes *n*, 2*n*, 3*n* and so on. Artists com... | ```python
def gcd(a, b):
if(b == 0):
return a
return gcd(b, a%b)
n, m, z = map(int, input().split())
lcm = (n*m)//gcd(n, m)
print(z//lcm)
``` | 3 | |
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,637,666,139 | 2,147,483,647 | PyPy 3-64 | OK | TESTS | 36 | 156 | 0 | # A. Die Roll
y,z = map(int,input().split())
n = 7-max(y,z)
if n%3==0 and n%2==0:
print("1/1")
elif n%3==0:
print(str(n//3)+"/"+"2")
elif n%2==0:
print(str(n//2)+"/"+"3")
else:
print(str(n)+"/"+"6")
| 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
# A. Die Roll
y,z = map(int,input().split())
n = 7-max(y,z)
if n%3==0 and n%2==0:
print("1/1")
elif n%3==0:
print(str(n//3)+"/"+"2")
elif n%2==0:
print(str(n//2)+"/"+"3")
else:
print(str(n)+"/"+"6")
``` | 3.922 |
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,675,212,703 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 1 | 62 | 0 | from math import gcd, sqrt
a,b = map(int,input().split())
T = int(input())
_gcd = gcd(a,b)
for _ in range(T):
low, high = map(int,input().split())
mx = int(sqrt(_gcd) + 10)
ans = -1
for i in range(low, min(high+1, mx)):
if _gcd % i == 0:
j = _gcd // i
if low <= j <= high:
ans = max(ans, j)
ans = max(... | 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 math import gcd, sqrt
a,b = map(int,input().split())
T = int(input())
_gcd = gcd(a,b)
for _ in range(T):
low, high = map(int,input().split())
mx = int(sqrt(_gcd) + 10)
ans = -1
for i in range(low, min(high+1, mx)):
if _gcd % i == 0:
j = _gcd // i
if low <= j <= high:
ans = max(ans, j)
... | 0 |
171 | E | MYSTERIOUS LANGUAGE | PROGRAMMING | 2,000 | [
"*special"
] | null | null | You are given a mysterious language (codenamed "Secret") available in "Custom Test" tab. Find out what this language is and write a program which outputs its name. Note that the program must be written in this language. | This program has only one test, and it's empty (it doesn't give your program anything to read). | Output the name of the mysterious language. | [] | [] | none | 0 | [
{
"input": "1",
"output": "INTERCAL"
}
] | 1,616,785,095 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 0 | 122 | 0 | print('input') | Title: MYSTERIOUS LANGUAGE
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a mysterious language (codenamed "Secret") available in "Custom Test" tab. Find out what this language is and write a program which outputs its name. Note that the program must be written in this langu... | ```python
print('input')
``` | 0 | |
712 | B | Memory and Trident | PROGRAMMING | 1,100 | [
"implementation",
"strings"
] | null | null | Memory is performing a walk on the two-dimensional plane, starting at the origin. He is given a string *s* with his directions for motion:
- An 'L' indicates he should move one unit left. - An 'R' indicates he should move one unit right. - A 'U' indicates he should move one unit up. - A 'D' indicates he should move... | The first and only line contains the string *s* (1<=≤<=|*s*|<=≤<=100<=000) — the instructions Memory is given. | If there is a string satisfying the conditions, output a single integer — the minimum number of edits required. In case it's not possible to change the sequence in such a way that it will bring Memory to to the origin, output -1. | [
"RRU\n",
"UDUR\n",
"RUUR\n"
] | [
"-1\n",
"1\n",
"2\n"
] | In the first sample test, Memory is told to walk right, then right, then up. It is easy to see that it is impossible to edit these instructions to form a valid walk.
In the second sample test, Memory is told to walk up, then down, then up, then right. One possible solution is to change *s* to "LDUR". This string uses ... | 1,000 | [
{
"input": "RRU",
"output": "-1"
},
{
"input": "UDUR",
"output": "1"
},
{
"input": "RUUR",
"output": "2"
},
{
"input": "DDDD",
"output": "2"
},
{
"input": "RRRR",
"output": "2"
},
{
"input": "RRRUUD",
"output": "2"
},
{
"input": "UDURLRDURL... | 1,479,812,805 | 1,125 | Python 3 | WRONG_ANSWER | TESTS | 5 | 77 | 0 |
if __name__ == '__main__':
s = input()
n = len(s)
if n % 2 != 0:
print(-1)
else:
x, y = 0, 0
ind = 0
while (ind < n and abs(x) + abs(y) <= n-ind):
if s[ind] == 'L':
x -= 1
elif s[ind] == 'R':
x += 1
elif s[ind] == 'U':
y += 1
else:
y -= 1
ind += 1
if ind ... | Title: Memory and Trident
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Memory is performing a walk on the two-dimensional plane, starting at the origin. He is given a string *s* with his directions for motion:
- An 'L' indicates he should move one unit left. - An 'R' indicates he shou... | ```python
if __name__ == '__main__':
s = input()
n = len(s)
if n % 2 != 0:
print(-1)
else:
x, y = 0, 0
ind = 0
while (ind < n and abs(x) + abs(y) <= n-ind):
if s[ind] == 'L':
x -= 1
elif s[ind] == 'R':
x += 1
elif s[ind] == 'U':
y += 1
else:
y -= 1
ind += 1
... | 0 | |
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,637,004,087 | 2,147,483,647 | Python 3 | OK | TESTS | 34 | 46 | 0 | n,c = map(int,input().split())
countN = 0
for i in range(n):
a,b = map(str,input().split())
b = int(b)
if a == "+":
c+=b
if a == "-":
if c<b:
countN+=1
else:
c-=b
print(c,countN)
| 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,c = map(int,input().split())
countN = 0
for i in range(n):
a,b = map(str,input().split())
b = int(b)
if a == "+":
c+=b
if a == "-":
if c<b:
countN+=1
else:
c-=b
print(c,countN)
``` | 3 | |
672 | A | Summer Camp | PROGRAMMING | 800 | [
"implementation"
] | null | null | Every year, hundreds of people come to summer camps, they learn new algorithms and solve hard problems.
This is your first year at summer camp, and you are asked to solve the following problem. All integers starting with 1 are written in one line. The prefix of these line is "123456789101112131415...". Your task is to... | The only line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the position of the digit you need to print. | Print the *n*-th digit of the line. | [
"3\n",
"11\n"
] | [
"3\n",
"0\n"
] | In the first sample the digit at position 3 is '3', as both integers 1 and 2 consist on one digit.
In the second sample, the digit at position 11 is '0', it belongs to the integer 10. | 500 | [
{
"input": "3",
"output": "3"
},
{
"input": "11",
"output": "0"
},
{
"input": "12",
"output": "1"
},
{
"input": "13",
"output": "1"
},
{
"input": "29",
"output": "9"
},
{
"input": "30",
"output": "2"
},
{
"input": "1000",
"output": "3"
... | 1,677,009,883 | 2,147,483,647 | Python 3 | OK | TESTS | 37 | 46 | 0 | print(''.join([str(i) for i in range(800)])[int(input())])
| Title: Summer Camp
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Every year, hundreds of people come to summer camps, they learn new algorithms and solve hard problems.
This is your first year at summer camp, and you are asked to solve the following problem. All integers starting with 1... | ```python
print(''.join([str(i) for i in range(800)])[int(input())])
``` | 3 | |
687 | A | NP-Hard Problem | PROGRAMMING | 1,500 | [
"dfs and similar",
"graphs"
] | null | null | Recently, Pari and Arya did some research about NP-Hard problems and they found the minimum vertex cover problem very interesting.
Suppose the graph *G* is given. Subset *A* of its vertices is called a vertex cover of this graph, if for each edge *uv* there is at least one endpoint of it in this set, i.e. or (or bot... | The first line of the input contains two integers *n* and *m* (2<=≤<=*n*<=≤<=100<=000, 1<=≤<=*m*<=≤<=100<=000) — the number of vertices and the number of edges in the prize graph, respectively.
Each of the next *m* lines contains a pair of integers *u**i* and *v**i* (1<=<=≤<=<=*u**i*,<=<=*v**i*<=<=≤<=<=*n*), denoting ... | If it's impossible to split the graph between Pari and Arya as they expect, print "-1" (without quotes).
If there are two disjoint sets of vertices, such that both sets are vertex cover, print their descriptions. Each description must contain two lines. The first line contains a single integer *k* denoting the number ... | [
"4 2\n1 2\n2 3\n",
"3 3\n1 2\n2 3\n1 3\n"
] | [
"1\n2 \n2\n1 3 \n",
"-1\n"
] | In the first sample, you can give the vertex number 2 to Arya and vertices numbered 1 and 3 to Pari and keep vertex number 4 for yourself (or give it someone, if you wish).
In the second sample, there is no way to satisfy both Pari and Arya. | 500 | [
{
"input": "4 2\n1 2\n2 3",
"output": "1\n2 \n2\n1 3 "
},
{
"input": "3 3\n1 2\n2 3\n1 3",
"output": "-1"
},
{
"input": "5 7\n3 2\n5 4\n3 4\n1 3\n1 5\n1 4\n2 5",
"output": "-1"
},
{
"input": "10 11\n4 10\n8 10\n2 3\n2 4\n7 1\n8 5\n2 8\n7 2\n1 2\n2 9\n6 8",
"output": "-1"
... | 1,589,372,166 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 5 | 109 | 6,963,200 | M=lambda:map(int,input().split())
n,m=M()
graph=[[] for i in range(n)]
for _ in range(m):
a,b=M()
graph[a-1]+=[b-1]
graph[b-1]+=[a-1]
visited=[]
A=set()
B=set()
flag=[-1 for i in range(n)]
def bfs(k):
stack=[k]
flag[k]=1
A.add(k+1)
while stack:
x=stack.pop(0)
... | Title: NP-Hard Problem
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Recently, Pari and Arya did some research about NP-Hard problems and they found the minimum vertex cover problem very interesting.
Suppose the graph *G* is given. Subset *A* of its vertices is called a vertex cover of ... | ```python
M=lambda:map(int,input().split())
n,m=M()
graph=[[] for i in range(n)]
for _ in range(m):
a,b=M()
graph[a-1]+=[b-1]
graph[b-1]+=[a-1]
visited=[]
A=set()
B=set()
flag=[-1 for i in range(n)]
def bfs(k):
stack=[k]
flag[k]=1
A.add(k+1)
while stack:
x=stack.pop(0... | 0 | |
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,699,955,540 | 2,147,483,647 | Python 3 | OK | TESTS | 19 | 46 | 0 | n=int(input())
arr=list(map(int,input().split()))
# delete at every index except 0 and n-1
mini=float('inf')
for i in range(1,n-1):
temp=arr.copy()
removed_list=temp[0:i]+temp[i+1:]
# for adjacnet element difference
maxi=0
for j in range(len(removed_list)-1):
maxi=max(max... | 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
n=int(input())
arr=list(map(int,input().split()))
# delete at every index except 0 and n-1
mini=float('inf')
for i in range(1,n-1):
temp=arr.copy()
removed_list=temp[0:i]+temp[i+1:]
# for adjacnet element difference
maxi=0
for j in range(len(removed_list)-1):
ma... | 3 | |
342 | A | Xenia and Divisors | PROGRAMMING | 1,200 | [
"greedy",
"implementation"
] | null | null | Xenia the mathematician has a sequence consisting of *n* (*n* is divisible by 3) positive integers, each of them is at most 7. She wants to split the sequence into groups of three so that for each group of three *a*,<=*b*,<=*c* the following conditions held:
- *a*<=<<=*b*<=<<=*c*; - *a* divides *b*, *b* divide... | The first line contains integer *n* (3<=≤<=*n*<=≤<=99999) — the number of elements in the sequence. The next line contains *n* positive integers, each of them is at most 7.
It is guaranteed that *n* is divisible by 3. | If the required partition exists, print groups of three. Print each group as values of the elements it contains. You should print values in increasing order. Separate the groups and integers in groups by whitespaces. If there are multiple solutions, you can print any of them.
If there is no solution, print -1. | [
"6\n1 1 1 2 2 2\n",
"6\n2 2 1 1 4 6\n"
] | [
"-1\n",
"1 2 4\n1 2 6\n"
] | none | 500 | [
{
"input": "6\n1 1 1 2 2 2",
"output": "-1"
},
{
"input": "6\n2 2 1 1 4 6",
"output": "1 2 4\n1 2 6"
},
{
"input": "3\n1 2 3",
"output": "-1"
},
{
"input": "3\n7 5 7",
"output": "-1"
},
{
"input": "3\n1 3 4",
"output": "-1"
},
{
"input": "3\n1 1 1",
... | 1,597,691,061 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 93 | 307,200 | z=int(input())
x=list(map(int,input().split()))
x.sort(reverse=True)
c=0
a=[]
b=[]
qw=[]
w=[]
for i in x:
c+=1
r=0
for o in range(c,len(x)):
if r==1:
break
elif i%x[o]==0 and o not in w and c-1 not in b and i!=x[o]:
for p in range(o,len(x)):
... | Title: Xenia and Divisors
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Xenia the mathematician has a sequence consisting of *n* (*n* is divisible by 3) positive integers, each of them is at most 7. She wants to split the sequence into groups of three so that for each group of three *a*,... | ```python
z=int(input())
x=list(map(int,input().split()))
x.sort(reverse=True)
c=0
a=[]
b=[]
qw=[]
w=[]
for i in x:
c+=1
r=0
for o in range(c,len(x)):
if r==1:
break
elif i%x[o]==0 and o not in w and c-1 not in b and i!=x[o]:
for p in range(o,len(x)):... | 0 | |
0 | none | none | none | 0 | [
"none"
] | 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 | 0 | [
{
"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,506,650,672 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 46 | 0 | n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
maxa = a[0]
minb = b[0]
maxa_ind = 0
mib_ind = 0
a1 = []
maxlist = []
minlist = []
for i in range(n):
a1.append(a[i])
for q in range(n):
for i in range(n):
if a[i] > maxa and a[i] != -1:
... | Title: none
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*) — mathematical e... | ```python
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
maxa = a[0]
minb = b[0]
maxa_ind = 0
mib_ind = 0
a1 = []
maxlist = []
minlist = []
for i in range(n):
a1.append(a[i])
for q in range(n):
for i in range(n):
if a[i] > maxa and a[i] != -1:
... | 0 | |
352 | A | Jeff and Digits | PROGRAMMING | 1,000 | [
"brute force",
"implementation",
"math"
] | null | null | Jeff's got *n* cards, each card contains either digit 0, or digit 5. Jeff can choose several cards and put them in a line so that he gets some number. What is the largest possible number divisible by 90 Jeff can make from the cards he's got?
Jeff must make the number without leading zero. At that, we assume that numbe... | The first line contains integer *n* (1<=≤<=*n*<=≤<=103). The next line contains *n* integers *a*1, *a*2, ..., *a**n* (*a**i*<==<=0 or *a**i*<==<=5). Number *a**i* represents the digit that is written on the *i*-th card. | In a single line print the answer to the problem — the maximum number, divisible by 90. If you can't make any divisible by 90 number from the cards, print -1. | [
"4\n5 0 5 0\n",
"11\n5 5 5 5 5 5 5 5 0 5 5\n"
] | [
"0\n",
"5555555550\n"
] | In the first test you can make only one number that is a multiple of 90 — 0.
In the second test you can make number 5555555550, it is a multiple of 90. | 500 | [
{
"input": "4\n5 0 5 0",
"output": "0"
},
{
"input": "11\n5 5 5 5 5 5 5 5 0 5 5",
"output": "5555555550"
},
{
"input": "7\n5 5 5 5 5 5 5",
"output": "-1"
},
{
"input": "1\n5",
"output": "-1"
},
{
"input": "1\n0",
"output": "0"
},
{
"input": "11\n5 0 5 ... | 1,680,749,342 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 62 | 0 | n = int(input())
a = list(map(int, input().split()))
freq = [0] * 10
for i in a:
freq[i] += 1
if freq[5] < 9 or freq[0] == 0:
print(-1)
else:
num_nines = freq[5] // 9
output = "5" * (num_nines * 9)
if num_nines == 0:
output = "0"
else:
output += "0" * freq[0]
pr... | Title: Jeff and Digits
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Jeff's got *n* cards, each card contains either digit 0, or digit 5. Jeff can choose several cards and put them in a line so that he gets some number. What is the largest possible number divisible by 90 Jeff can make fr... | ```python
n = int(input())
a = list(map(int, input().split()))
freq = [0] * 10
for i in a:
freq[i] += 1
if freq[5] < 9 or freq[0] == 0:
print(-1)
else:
num_nines = freq[5] // 9
output = "5" * (num_nines * 9)
if num_nines == 0:
output = "0"
else:
output += "0" * freq[... | 0 | |
939 | A | Love Triangle | PROGRAMMING | 800 | [
"graphs"
] | null | null | As you could know there are no male planes nor female planes. However, each plane on Earth likes some other plane. There are *n* planes on Earth, numbered from 1 to *n*, and the plane with number *i* likes the plane with number *f**i*, where 1<=≤<=*f**i*<=≤<=*n* and *f**i*<=≠<=*i*.
We call a love triangle a situation ... | The first line contains a single integer *n* (2<=≤<=*n*<=≤<=5000) — the number of planes.
The second line contains *n* integers *f*1,<=*f*2,<=...,<=*f**n* (1<=≤<=*f**i*<=≤<=*n*, *f**i*<=≠<=*i*), meaning that the *i*-th plane likes the *f**i*-th. | Output «YES» if there is a love triangle consisting of planes on Earth. Otherwise, output «NO».
You can output any letter in lower case or in upper case. | [
"5\n2 4 5 1 3\n",
"5\n5 5 5 5 1\n"
] | [
"YES\n",
"NO\n"
] | In first example plane 2 likes plane 4, plane 4 likes plane 1, plane 1 likes plane 2 and that is a love triangle.
In second example there are no love triangles. | 500 | [
{
"input": "5\n2 4 5 1 3",
"output": "YES"
},
{
"input": "5\n5 5 5 5 1",
"output": "NO"
},
{
"input": "3\n3 1 2",
"output": "YES"
},
{
"input": "10\n4 10 9 5 3 1 5 10 6 4",
"output": "NO"
},
{
"input": "10\n5 5 4 9 10 9 9 5 3 1",
"output": "YES"
},
{
"... | 1,697,969,067 | 2,147,483,647 | Python 3 | OK | TESTS | 16 | 46 | 409,600 | import sys
def input_lines():
return list(map(str.strip, sys.stdin.readlines()))
def line_to_int_arr(line):
return list(map(int, line.split(" ")))
def print_arr(arr):
for el in arr:
print(el, end= ' ')
print()
lines = input_lines()
n = int(lines[0])
arr = line_to_int_arr(lines[1])
for i in range(n):
if arr... | Title: Love Triangle
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
As you could know there are no male planes nor female planes. However, each plane on Earth likes some other plane. There are *n* planes on Earth, numbered from 1 to *n*, and the plane with number *i* likes the plane with ... | ```python
import sys
def input_lines():
return list(map(str.strip, sys.stdin.readlines()))
def line_to_int_arr(line):
return list(map(int, line.split(" ")))
def print_arr(arr):
for el in arr:
print(el, end= ' ')
print()
lines = input_lines()
n = int(lines[0])
arr = line_to_int_arr(lines[1])
for i in range(n... | 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,693,152,160 | 2,147,483,647 | Python 3 | OK | TESTS | 30 | 92 | 0 | a = input()
dx = 0
xx = 0
for i in a:
if i.islower():
xx += 1
else:
dx += 1
if xx < dx:
print(a.upper())
else:
print(a.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
a = input()
dx = 0
xx = 0
for i in a:
if i.islower():
xx += 1
else:
dx += 1
if xx < dx:
print(a.upper())
else:
print(a.lower())
``` | 3.977 |
609 | E | Minimum spanning tree for each edge | PROGRAMMING | 2,100 | [
"data structures",
"dfs and similar",
"dsu",
"graphs",
"trees"
] | null | null | Connected undirected weighted graph without self-loops and multiple edges is given. Graph contains *n* vertices and *m* edges.
For each edge (*u*,<=*v*) find the minimal possible weight of the spanning tree that contains the edge (*u*,<=*v*).
The weight of the spanning tree is the sum of weights of all edges included... | First line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=2·105,<=*n*<=-<=1<=≤<=*m*<=≤<=2·105) — the number of vertices and edges in graph.
Each of the next *m* lines contains three integers *u**i*,<=*v**i*,<=*w**i* (1<=≤<=*u**i*,<=*v**i*<=≤<=*n*,<=*u**i*<=≠<=*v**i*,<=1<=≤<=*w**i*<=≤<=109) — the endpoints of the *i*... | Print *m* lines. *i*-th line should contain the minimal possible weight of the spanning tree that contains *i*-th edge.
The edges are numbered from 1 to *m* in order of their appearing in input. | [
"5 7\n1 2 3\n1 3 1\n1 4 5\n2 3 2\n2 5 3\n3 4 2\n4 5 4\n"
] | [
"9\n8\n11\n8\n8\n8\n9\n"
] | none | 0 | [
{
"input": "5 7\n1 2 3\n1 3 1\n1 4 5\n2 3 2\n2 5 3\n3 4 2\n4 5 4",
"output": "9\n8\n11\n8\n8\n8\n9"
},
{
"input": "2 1\n1 2 42",
"output": "42"
},
{
"input": "3 3\n1 2 10\n2 3 20\n3 1 40",
"output": "30\n30\n50"
},
{
"input": "4 6\n1 2 999999001\n1 3 999999003\n1 4 999999009\... | 1,685,865,039 | 2,147,483,647 | PyPy 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | #include<bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int n, m;
vector<array<int, 4>> edges;
int lab[N];
vector<pair<int, int>> g[N]; // tree
int par[N][18], d[N], mx[N][18]; // binlift
int root(int x) { return lab[x] < 0? x: lab[x] = root(lab[x]); }
bool unite(int x, int y) {
x = root... | Title: Minimum spanning tree for each edge
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Connected undirected weighted graph without self-loops and multiple edges is given. Graph contains *n* vertices and *m* edges.
For each edge (*u*,<=*v*) find the minimal possible weight of the spann... | ```python
#include<bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int n, m;
vector<array<int, 4>> edges;
int lab[N];
vector<pair<int, int>> g[N]; // tree
int par[N][18], d[N], mx[N][18]; // binlift
int root(int x) { return lab[x] < 0? x: lab[x] = root(lab[x]); }
bool unite(int x, int y) {
... | -1 | |
471 | A | MUH and Sticks | PROGRAMMING | 1,100 | [
"implementation"
] | null | null | Two polar bears Menshykov and Uslada from the St.Petersburg zoo and elephant Horace from the Kiev zoo got six sticks to play with and assess the animals' creativity. Menshykov, Uslada and Horace decided to make either an elephant or a bear from those sticks. They can make an animal from sticks in the following way:
-... | The single line contains six space-separated integers *l**i* (1<=≤<=*l**i*<=≤<=9) — the lengths of the six sticks. It is guaranteed that the input is such that you cannot make both animals from the sticks. | If you can make a bear from the given set, print string "Bear" (without the quotes). If you can make an elephant, print string "Elephant" (wıthout the quotes). If you can make neither a bear nor an elephant, print string "Alien" (without the quotes). | [
"4 2 5 4 4 4\n",
"4 4 5 4 4 5\n",
"1 2 3 4 5 6\n"
] | [
"Bear",
"Elephant",
"Alien"
] | If you're out of creative ideas, see instructions below which show how to make a bear and an elephant in the first two samples. The stick of length 2 is in red, the sticks of length 4 are in green, the sticks of length 5 are in blue. | 500 | [
{
"input": "4 2 5 4 4 4",
"output": "Bear"
},
{
"input": "4 4 5 4 4 5",
"output": "Elephant"
},
{
"input": "1 2 3 4 5 6",
"output": "Alien"
},
{
"input": "5 5 5 5 5 5",
"output": "Elephant"
},
{
"input": "1 1 1 2 3 5",
"output": "Alien"
},
{
"input": "... | 1,558,364,366 | 2,147,483,647 | Python 3 | OK | TESTS | 29 | 108 | 0 | s=[int(n) for n in input().split()]
j=0
for n in s:
if s.count(n)>=4:
j=n
break
if j==0:
print('Alien')
else:
s.sort()
del s[s.index(j):s.index(j)+4]
if s[0]==s[1]:
print('Elephant')
else:
print('Bear') | Title: MUH and Sticks
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Two polar bears Menshykov and Uslada from the St.Petersburg zoo and elephant Horace from the Kiev zoo got six sticks to play with and assess the animals' creativity. Menshykov, Uslada and Horace decided to make either an... | ```python
s=[int(n) for n in input().split()]
j=0
for n in s:
if s.count(n)>=4:
j=n
break
if j==0:
print('Alien')
else:
s.sort()
del s[s.index(j):s.index(j)+4]
if s[0]==s[1]:
print('Elephant')
else:
print('Bear')
``` | 3 | |
85 | A | Domino | PROGRAMMING | 1,300 | [
"constructive algorithms",
"implementation"
] | A. Domino | 1 | 256 | We all know the problem about the number of ways one can tile a 2<=×<=*n* field by 1<=×<=2 dominoes. You probably remember that it goes down to Fibonacci numbers. We will talk about some other problem below, there you also are going to deal with tiling a rectangular field with dominoes.
You are given a 4<=×<=*n* recta... | The input contains one positive integer *n* (1<=≤<=*n*<=≤<=100) — the number of the field's columns. | If there's no solution, print "-1" (without the quotes). Otherwise, print four lines containing *n* characters each — that's the description of tiling, where each vertical cut intersects at least one domino. You should print the tiling, having painted the field in no more than 26 colors. Each domino should be painted a... | [
"4\n"
] | [
"yyzz\nbccd\nbxxd\nyyaa\n"
] | none | 500 | [
{
"input": "4",
"output": "aacc\nbbdd\nzkkz\nzllz"
},
{
"input": "2",
"output": "aa\nbb\naa\nbb"
},
{
"input": "3",
"output": "aab\nccb\nbaa\nbcc"
},
{
"input": "5",
"output": "aaccz\nbbddz\nzkkmm\nzllnn"
},
{
"input": "1",
"output": "a\na\nb\nb"
},
{
... | 1,601,722,242 | 2,147,483,647 | PyPy 3 | WRONG_ANSWER | TESTS | 0 | 216 | 0 | a=int(input())
z=[['']*a for _ in " "*4]
r=lambda x: 'ab'[x]
r1=lambda x:'cd'[x]
k=0
for i in range(a//2):
z[0][2*i]=z[0][2*i+1]=r(k)
k^=1
if a&1:z[0][-1]='z'
k=1
for i in range(a//2):
z[1][2*i]=z[1][2*i+1]=r(k)
k^=1
if a&1:z[1][-1]='z'
k=1
for i in range(a//2):
z[2][2*i]=z[2][2*i+1... | Title: Domino
Time Limit: 1 seconds
Memory Limit: 256 megabytes
Problem Description:
We all know the problem about the number of ways one can tile a 2<=×<=*n* field by 1<=×<=2 dominoes. You probably remember that it goes down to Fibonacci numbers. We will talk about some other problem below, there you also are going... | ```python
a=int(input())
z=[['']*a for _ in " "*4]
r=lambda x: 'ab'[x]
r1=lambda x:'cd'[x]
k=0
for i in range(a//2):
z[0][2*i]=z[0][2*i+1]=r(k)
k^=1
if a&1:z[0][-1]='z'
k=1
for i in range(a//2):
z[1][2*i]=z[1][2*i+1]=r(k)
k^=1
if a&1:z[1][-1]='z'
k=1
for i in range(a//2):
z[2][2*i]=... | 0 |
744 | A | Hongcow Builds A Nation | PROGRAMMING | 1,500 | [
"dfs and similar",
"graphs"
] | null | null | Hongcow is ruler of the world. As ruler of the world, he wants to make it easier for people to travel by road within their own countries.
The world can be modeled as an undirected graph with *n* nodes and *m* edges. *k* of the nodes are home to the governments of the *k* countries that make up the world.
There is at ... | The first line of input will contain three integers *n*, *m* and *k* (1<=≤<=*n*<=≤<=1<=000, 0<=≤<=*m*<=≤<=100<=000, 1<=≤<=*k*<=≤<=*n*) — the number of vertices and edges in the graph, and the number of vertices that are homes of the government.
The next line of input will contain *k* integers *c*1,<=*c*2,<=...,<=*c**... | Output a single integer, the maximum number of edges Hongcow can add to the graph while keeping it stable. | [
"4 1 2\n1 3\n1 2\n",
"3 3 1\n2\n1 2\n1 3\n2 3\n"
] | [
"2\n",
"0\n"
] | For the first sample test, the graph looks like this:
For the second sample test, the graph looks like this: | 500 | [
{
"input": "4 1 2\n1 3\n1 2",
"output": "2"
},
{
"input": "3 3 1\n2\n1 2\n1 3\n2 3",
"output": "0"
},
{
"input": "10 3 2\n1 10\n1 2\n1 3\n4 5",
"output": "33"
},
{
"input": "1 0 1\n1",
"output": "0"
},
{
"input": "1000 0 1\n72",
"output": "499500"
},
{
... | 1,567,011,502 | 2,147,483,647 | Python 3 | TIME_LIMIT_EXCEEDED | TESTS | 3 | 2,000 | 7,884,800 | gr={}
class node:
def __init__(self):
self.adj=set()
def add(self,b):
self.adj.add(b)
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
for i in range(n):
gr[i+1]=node()
for i in range(m):
u,v=map(int,input().split())
gr[u].add(v)
gr[v].add(u)
v=[False for i in range(n+1)]
v[0]=Tr... | Title: Hongcow Builds A Nation
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Hongcow is ruler of the world. As ruler of the world, he wants to make it easier for people to travel by road within their own countries.
The world can be modeled as an undirected graph with *n* nodes and *m* e... | ```python
gr={}
class node:
def __init__(self):
self.adj=set()
def add(self,b):
self.adj.add(b)
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
for i in range(n):
gr[i+1]=node()
for i in range(m):
u,v=map(int,input().split())
gr[u].add(v)
gr[v].add(u)
v=[False for i in range(n+1)... | 0 | |
982 | B | Bus of Characters | PROGRAMMING | 1,300 | [
"data structures",
"greedy",
"implementation"
] | null | null | In the Bus of Characters there are $n$ rows of seat, each having $2$ seats. The width of both seats in the $i$-th row is $w_i$ centimeters. All integers $w_i$ are distinct.
Initially the bus is empty. On each of $2n$ stops one passenger enters the bus. There are two types of passengers:
- an introvert always choose... | The first line contains a single integer $n$ ($1 \le n \le 200\,000$) — the number of rows in the bus.
The second line contains the sequence of integers $w_1, w_2, \dots, w_n$ ($1 \le w_i \le 10^{9}$), where $w_i$ is the width of each of the seats in the $i$-th row. It is guaranteed that all $w_i$ are distinct.
The t... | Print $2n$ integers — the rows the passengers will take. The order of passengers should be the same as in input. | [
"2\n3 1\n0011\n",
"6\n10 8 9 11 13 5\n010010011101\n"
] | [
"2 1 1 2 \n",
"6 6 2 3 3 1 4 4 1 2 5 5 \n"
] | In the first example the first passenger (introvert) chooses the row $2$, because it has the seats with smallest width. The second passenger (introvert) chooses the row $1$, because it is the only empty row now. The third passenger (extrovert) chooses the row $1$, because it has exactly one occupied seat and the seat w... | 1,000 | [
{
"input": "2\n3 1\n0011",
"output": "2 1 1 2 "
},
{
"input": "6\n10 8 9 11 13 5\n010010011101",
"output": "6 6 2 3 3 1 4 4 1 2 5 5 "
},
{
"input": "1\n1\n01",
"output": "1 1 "
},
{
"input": "1\n1000000\n01",
"output": "1 1 "
},
{
"input": "2\n1 1000000\n0011",
... | 1,558,177,973 | 2,147,483,647 | Python 3 | OK | TESTS | 49 | 1,434 | 20,480,000 | n = int(input())
s = list(map(int, input().split()))
z = list(zip(s, range(1, n+1)))
z.sort()
z = [i[1] for i in z]
p = []
k = 0
for i in input():
if i == '0':
print(z[k])
p.append(z[k])
k+=1
if i == '1':
print(p[-1])
p.pop()
| Title: Bus of Characters
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
In the Bus of Characters there are $n$ rows of seat, each having $2$ seats. The width of both seats in the $i$-th row is $w_i$ centimeters. All integers $w_i$ are distinct.
Initially the bus is empty. On each of $2n$... | ```python
n = int(input())
s = list(map(int, input().split()))
z = list(zip(s, range(1, n+1)))
z.sort()
z = [i[1] for i in z]
p = []
k = 0
for i in input():
if i == '0':
print(z[k])
p.append(z[k])
k+=1
if i == '1':
print(p[-1])
p.pop()
``` | 3 | |
922 | A | Cloning Toys | PROGRAMMING | 1,300 | [
"implementation"
] | null | null | Imp likes his plush toy a lot.
Recently, he found a machine that can clone plush toys. Imp knows that if he applies the machine to an original toy, he additionally gets one more original toy and one copy, and if he applies the machine to a copied toy, he gets two additional copies.
Initially, Imp has only one origina... | The only line contains two integers *x* and *y* (0<=≤<=*x*,<=*y*<=≤<=109) — the number of copies and the number of original toys Imp wants to get (including the initial one). | Print "Yes", if the desired configuration is possible, and "No" otherwise.
You can print each letter in arbitrary case (upper or lower). | [
"6 3\n",
"4 2\n",
"1000 1001\n"
] | [
"Yes\n",
"No\n",
"Yes\n"
] | In the first example, Imp has to apply the machine twice to original toys and then twice to copies. | 500 | [
{
"input": "6 3",
"output": "Yes"
},
{
"input": "4 2",
"output": "No"
},
{
"input": "1000 1001",
"output": "Yes"
},
{
"input": "1000000000 999999999",
"output": "Yes"
},
{
"input": "81452244 81452247",
"output": "No"
},
{
"input": "188032448 86524683",... | 1,571,389,348 | 2,147,483,647 | Python 3 | COMPILATION_ERROR | TESTS | 0 | 0 | 0 | >>> L1 = [1,2,3,4]
>>> L2 = copy.copy(L1)
>>> L1
[1, 2, 3, 4]
>>> L2
[1, 2, 3, 4]
>>> id(L1)
185117025160
>>> id(L2)
185117295880
>>> L3=copy.deepcopy(L1)
>>> L3
[1, 2, 3, 4]
>>> id(L3)
185117304328 | Title: Cloning Toys
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Imp likes his plush toy a lot.
Recently, he found a machine that can clone plush toys. Imp knows that if he applies the machine to an original toy, he additionally gets one more original toy and one copy, and if he applie... | ```python
>>> L1 = [1,2,3,4]
>>> L2 = copy.copy(L1)
>>> L1
[1, 2, 3, 4]
>>> L2
[1, 2, 3, 4]
>>> id(L1)
185117025160
>>> id(L2)
185117295880
>>> L3=copy.deepcopy(L1)
>>> L3
[1, 2, 3, 4]
>>> id(L3)
185117304328
``` | -1 | |
46 | A | Ball Game | PROGRAMMING | 800 | [
"brute force",
"implementation"
] | A. Ball Game | 2 | 256 | A kindergarten teacher Natalia Pavlovna has invented a new ball game. This game not only develops the children's physique, but also teaches them how to count.
The game goes as follows. Kids stand in circle. Let's agree to think of the children as numbered with numbers from 1 to *n* clockwise and the child number 1 is... | The first line contains integer *n* (2<=≤<=*n*<=≤<=100) which indicates the number of kids in the circle. | In the single line print *n*<=-<=1 numbers which are the numbers of children who will get the ball after each throw. Separate the numbers by spaces. | [
"10\n",
"3\n"
] | [
"2 4 7 1 6 2 9 7 6\n",
"2 1\n"
] | none | 0 | [
{
"input": "10",
"output": "2 4 7 1 6 2 9 7 6"
},
{
"input": "3",
"output": "2 1"
},
{
"input": "4",
"output": "2 4 3"
},
{
"input": "5",
"output": "2 4 2 1"
},
{
"input": "6",
"output": "2 4 1 5 4"
},
{
"input": "7",
"output": "2 4 7 4 2 1"
},
... | 1,611,142,939 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 122 | 0 | n = int(input())
child_num = 1
for i in range(1,n):
if child_num + i < n:
child_num = child_num + i
print(child_num, end=" ")
else:
child_num = child_num + i - n
print(child_num, end=" ") | Title: Ball Game
Time Limit: 2 seconds
Memory Limit: 256 megabytes
Problem Description:
A kindergarten teacher Natalia Pavlovna has invented a new ball game. This game not only develops the children's physique, but also teaches them how to count.
The game goes as follows. Kids stand in circle. Let's agree to think... | ```python
n = int(input())
child_num = 1
for i in range(1,n):
if child_num + i < n:
child_num = child_num + i
print(child_num, end=" ")
else:
child_num = child_num + i - n
print(child_num, end=" ")
``` | 0 |
731 | A | Night at the Museum | PROGRAMMING | 800 | [
"implementation",
"strings"
] | null | null | Grigoriy, like the hero of one famous comedy film, found a job as a night security guard at the museum. At first night he received embosser and was to take stock of the whole exposition.
Embosser is a special devise that allows to "print" the text of a plastic tape. Text is printed sequentially, character by character... | The only line of input contains the name of some exhibit — the non-empty string consisting of no more than 100 characters. It's guaranteed that the string consists of only lowercase English letters. | Print one integer — the minimum number of rotations of the wheel, required to print the name given in the input. | [
"zeus\n",
"map\n",
"ares\n"
] | [
"18\n",
"35\n",
"34\n"
] | To print the string from the first sample it would be optimal to perform the following sequence of rotations:
1. from 'a' to 'z' (1 rotation counterclockwise), 1. from 'z' to 'e' (5 clockwise rotations), 1. from 'e' to 'u' (10 rotations counterclockwise), 1. from 'u' to 's' (2 counterclockwise rotations). | 500 | [
{
"input": "zeus",
"output": "18"
},
{
"input": "map",
"output": "35"
},
{
"input": "ares",
"output": "34"
},
{
"input": "l",
"output": "11"
},
{
"input": "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuv",
"... | 1,697,638,374 | 2,147,483,647 | Python 3 | OK | TESTS | 44 | 46 | 0 | x=input()
y="abcdefghijklmnopqrstuvwxyz"
z=y[::-1]
e=0
b=len(x)
for i in range(0,b):
if x[i] in y:
c=y.index(x[i])
if x[i] in z:
d=z.index(x[i])+1
if c<=d:
e=e+c
if d<c:
e=e+d
f=y[:c]
g=y[c::]
y=g+f
z=y[::-1]
print(e) | Title: Night at the Museum
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Grigoriy, like the hero of one famous comedy film, found a job as a night security guard at the museum. At first night he received embosser and was to take stock of the whole exposition.
Embosser is a special devis... | ```python
x=input()
y="abcdefghijklmnopqrstuvwxyz"
z=y[::-1]
e=0
b=len(x)
for i in range(0,b):
if x[i] in y:
c=y.index(x[i])
if x[i] in z:
d=z.index(x[i])+1
if c<=d:
e=e+c
if d<c:
e=e+d
f=y[:c]
g=y[c::]
y=g+f
z=y[::-1]
print(e)
``` | 3 | |
1,005 | B | Delete from the Left | PROGRAMMING | 900 | [
"brute force",
"implementation",
"strings"
] | null | null | You are given two strings $s$ and $t$. In a single move, you can choose any of two strings and delete the first (that is, the leftmost) character. After a move, the length of the string decreases by $1$. You can't choose a string if it is empty.
For example:
- by applying a move to the string "where", the result is ... | The first line of the input contains $s$. In the second line of the input contains $t$. Both strings consist only of lowercase Latin letters. The number of letters in each string is between 1 and $2\cdot10^5$, inclusive. | Output the fewest number of moves required. It is possible that, in the end, both strings will be equal to the empty string, and so, are equal to each other. In this case, the answer is obviously the sum of the lengths of the given strings. | [
"test\nwest\n",
"codeforces\nyes\n",
"test\nyes\n",
"b\nab\n"
] | [
"2\n",
"9\n",
"7\n",
"1\n"
] | In the first example, you should apply the move once to the first string and apply the move once to the second string. As a result, both strings will be equal to "est".
In the second example, the move should be applied to the string "codeforces" $8$ times. As a result, the string becomes "codeforces" $\to$ "es". The m... | 0 | [
{
"input": "test\nwest",
"output": "2"
},
{
"input": "codeforces\nyes",
"output": "9"
},
{
"input": "test\nyes",
"output": "7"
},
{
"input": "b\nab",
"output": "1"
},
{
"input": "z\nz",
"output": "0"
},
{
"input": "abacabadabacaba\nabacabadacaba",
... | 1,642,231,357 | 2,147,483,647 | Python 3 | RUNTIME_ERROR | TESTS | 2 | 31 | 0 | x = input()
y = input()
ref = min(len(x),len(y))
for i in range(ref):
if x[-1-i] == y[-1-i]:
_=i
_+=1
print(len(x)+len(y)-2*_) | Title: Delete from the Left
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given two strings $s$ and $t$. In a single move, you can choose any of two strings and delete the first (that is, the leftmost) character. After a move, the length of the string decreases by $1$. You can't ... | ```python
x = input()
y = input()
ref = min(len(x),len(y))
for i in range(ref):
if x[-1-i] == y[-1-i]:
_=i
_+=1
print(len(x)+len(y)-2*_)
``` | -1 | |
382 | A | Ksenia and Pan Scales | PROGRAMMING | 1,100 | [
"greedy",
"implementation"
] | null | null | Ksenia has ordinary pan scales and several weights of an equal mass. Ksenia has already put some weights on the scales, while other weights are untouched. Ksenia is now wondering whether it is possible to put all the remaining weights on the scales so that the scales were in equilibrium.
The scales is in equilibrium ... | The first line has a non-empty sequence of characters describing the scales. In this sequence, an uppercase English letter indicates a weight, and the symbol "|" indicates the delimiter (the character occurs in the sequence exactly once). All weights that are recorded in the sequence before the delimiter are initially ... | If you cannot put all the weights on the scales so that the scales were in equilibrium, print string "Impossible". Otherwise, print the description of the resulting scales, copy the format of the input.
If there are multiple answers, print any of them. | [
"AC|T\nL\n",
"|ABC\nXYZ\n",
"W|T\nF\n",
"ABC|\nD\n"
] | [
"AC|TL\n",
"XYZ|ABC\n",
"Impossible\n",
"Impossible\n"
] | none | 500 | [
{
"input": "AC|T\nL",
"output": "AC|TL"
},
{
"input": "|ABC\nXYZ",
"output": "XYZ|ABC"
},
{
"input": "W|T\nF",
"output": "Impossible"
},
{
"input": "ABC|\nD",
"output": "Impossible"
},
{
"input": "A|BC\nDEF",
"output": "ADF|BCE"
},
{
"input": "|\nABC",... | 1,629,659,148 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 46 | 6,963,200 | s = str(input())
n_used = str(input())
lis = s.split('|')
l, r = lis[0], lis[1]
if (len(n_used) + len(l) + len(r)) % 2 != 0:
print('Impossible')
if len(l) > len(r) + len(n_used) or len(r) > len(l) + len(n_used):
print('Impossible')
else:
dif = len(l) - len(r)
if dif < 0:
dif = abs(dif... | Title: Ksenia and Pan Scales
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Ksenia has ordinary pan scales and several weights of an equal mass. Ksenia has already put some weights on the scales, while other weights are untouched. Ksenia is now wondering whether it is possible to put all ... | ```python
s = str(input())
n_used = str(input())
lis = s.split('|')
l, r = lis[0], lis[1]
if (len(n_used) + len(l) + len(r)) % 2 != 0:
print('Impossible')
if len(l) > len(r) + len(n_used) or len(r) > len(l) + len(n_used):
print('Impossible')
else:
dif = len(l) - len(r)
if dif < 0:
dif... | 0 | |
194 | A | Exams | PROGRAMMING | 900 | [
"implementation",
"math"
] | null | null | One day the Codeforces round author sat exams. He had *n* exams and he needed to get an integer from 2 to 5 for each exam. He will have to re-sit each failed exam, i.e. the exam that gets mark 2.
The author would need to spend too much time and effort to make the sum of his marks strictly more than *k*. That could ha... | The single input line contains space-separated integers *n* and *k* (1<=≤<=*n*<=≤<=50, 1<=≤<=*k*<=≤<=250) — the number of exams and the required sum of marks.
It is guaranteed that there exists a way to pass *n* exams in the way that makes the sum of marks equal exactly *k*. | Print the single number — the minimum number of exams that the author will get a 2 for, considering that the sum of marks for all exams must equal *k*. | [
"4 8\n",
"4 10\n",
"1 3\n"
] | [
"4\n",
"2\n",
"0\n"
] | In the first sample the author has to get a 2 for all his exams.
In the second sample he should get a 3 for two exams and a 2 for two more.
In the third sample he should get a 3 for one exam. | 500 | [
{
"input": "4 8",
"output": "4"
},
{
"input": "4 10",
"output": "2"
},
{
"input": "1 3",
"output": "0"
},
{
"input": "1 2",
"output": "1"
},
{
"input": "4 9",
"output": "3"
},
{
"input": "50 234",
"output": "0"
},
{
"input": "50 100",
"... | 1,659,084,431 | 2,147,483,647 | PyPy 3-64 | WRONG_ANSWER | TESTS | 3 | 122 | 0 | n, m = map(int, input(). split())
if m % n != 0:
print(m // n)
else:
if n == 1:
print(0)
else:
for i in range(5, 1, -1):
if i * n == m:
print(m // i)
break
| Title: Exams
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day the Codeforces round author sat exams. He had *n* exams and he needed to get an integer from 2 to 5 for each exam. He will have to re-sit each failed exam, i.e. the exam that gets mark 2.
The author would need to spend ... | ```python
n, m = map(int, input(). split())
if m % n != 0:
print(m // n)
else:
if n == 1:
print(0)
else:
for i in range(5, 1, -1):
if i * n == m:
print(m // i)
break
``` | 0 | |
599 | A | Patrick and Shopping | PROGRAMMING | 800 | [
"implementation"
] | null | null | Today Patrick waits for a visit from his friend Spongebob. To prepare for the visit, Patrick needs to buy some goodies in two stores located near his house. There is a *d*1 meter long road between his house and the first shop and a *d*2 meter long road between his house and the second shop. Also, there is a road of len... | The first line of the input contains three integers *d*1, *d*2, *d*3 (1<=≤<=*d*1,<=*d*2,<=*d*3<=≤<=108) — the lengths of the paths.
- *d*1 is the length of the path connecting Patrick's house and the first shop; - *d*2 is the length of the path connecting Patrick's house and the second shop; - *d*3 is the length o... | Print the minimum distance that Patrick will have to walk in order to visit both shops and return to his house. | [
"10 20 30\n",
"1 1 5\n"
] | [
"60\n",
"4\n"
] | The first sample is shown on the picture in the problem statement. One of the optimal routes is: house <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/70a0795f45d32287dba0eb83fc4a3f470c6e5537.png" style="max-width: 100.0%;max-height: 100.0%;"/> first shop <img align="middle" class="tex-form... | 500 | [
{
"input": "10 20 30",
"output": "60"
},
{
"input": "1 1 5",
"output": "4"
},
{
"input": "100 33 34",
"output": "134"
},
{
"input": "777 777 777",
"output": "2331"
},
{
"input": "2 2 8",
"output": "8"
},
{
"input": "12 34 56",
"output": "92"
},
... | 1,667,011,111 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 30 | 0 | a = input().split()
d1 = int(a[0])
d2 = int(a[1])
d3 = int(a[2])
if d3 <= d1 + d2:
b = d1 + d2 + d3
print(b)
if d3 > d1 + d2:
c = d1 + d2 + d1 + d2
print(c)
if d1 > d2 + d3:
d = d2 + d3 + d2 + d3
print(d)
if d2 > d1 + d3:
e = d1 + d3 + d1 + d3
print(e)
... | Title: Patrick and Shopping
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Today Patrick waits for a visit from his friend Spongebob. To prepare for the visit, Patrick needs to buy some goodies in two stores located near his house. There is a *d*1 meter long road between his house and the... | ```python
a = input().split()
d1 = int(a[0])
d2 = int(a[1])
d3 = int(a[2])
if d3 <= d1 + d2:
b = d1 + d2 + d3
print(b)
if d3 > d1 + d2:
c = d1 + d2 + d1 + d2
print(c)
if d1 > d2 + d3:
d = d2 + d3 + d2 + d3
print(d)
if d2 > d1 + d3:
e = d1 + d3 + d1 + d3
print(e)
... | 0 | |
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,350,199 | 2,147,483,647 | PyPy 3 | OK | TESTS | 31 | 156 | 20,172,800 | a,b,c,d=[int(x) for x in input().split()]
x=(1-a/b)*(1-c/d)
ans=(a/b)*(1/(1-(x)))
print(ans)
| 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=[int(x) for x in input().split()]
x=(1-a/b)*(1-c/d)
ans=(a/b)*(1/(1-(x)))
print(ans)
``` | 3 | |
330 | A | Cakeminator | PROGRAMMING | 800 | [
"brute force",
"implementation"
] | null | null | You are given a rectangular cake, represented as an *r*<=×<=*c* grid. Each cell either has an evil strawberry, or is empty. For example, a 3<=×<=4 cake may look as follows:
The cakeminator is going to eat the cake! Each time he eats, he chooses a row or a column that does not contain any evil strawberries and contains... | The first line contains two integers *r* and *c* (2<=≤<=*r*,<=*c*<=≤<=10), denoting the number of rows and the number of columns of the cake. The next *r* lines each contains *c* characters — the *j*-th character of the *i*-th line denotes the content of the cell at row *i* and column *j*, and is either one of these:
... | Output the maximum number of cake cells that the cakeminator can eat. | [
"3 4\nS...\n....\n..S.\n"
] | [
"8\n"
] | For the first example, one possible way to eat the maximum number of cake cells is as follows (perform 3 eats). | 500 | [
{
"input": "3 4\nS...\n....\n..S.",
"output": "8"
},
{
"input": "2 2\n..\n..",
"output": "4"
},
{
"input": "2 2\nSS\nSS",
"output": "0"
},
{
"input": "7 3\nS..\nS..\nS..\nS..\nS..\nS..\nS..",
"output": "14"
},
{
"input": "3 5\n..S..\nSSSSS\n..S..",
"output": "... | 1,607,062,085 | 2,147,483,647 | PyPy 3 | OK | TESTS | 42 | 310 | 1,228,800 | n, m = map(int, input().split())
a = []
for i in range(n):
a.append(list(input()))
b = []
for i in range(len(a)):
if 'S' not in a[i]:
for j in range(m):
b.append([i, j])
for i in range(m):
flag = 0
for j in range(n):
if a[j][i] == 'S':
flag = 1
... | Title: Cakeminator
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You are given a rectangular cake, represented as an *r*<=×<=*c* grid. Each cell either has an evil strawberry, or is empty. For example, a 3<=×<=4 cake may look as follows:
The cakeminator is going to eat the cake! Each ti... | ```python
n, m = map(int, input().split())
a = []
for i in range(n):
a.append(list(input()))
b = []
for i in range(len(a)):
if 'S' not in a[i]:
for j in range(m):
b.append([i, j])
for i in range(m):
flag = 0
for j in range(n):
if a[j][i] == 'S':
flag ... | 3 | |
841 | A | Generous Kefa | PROGRAMMING | 900 | [
"brute force",
"implementation"
] | null | null | One day Kefa found *n* baloons. For convenience, we denote color of *i*-th baloon as *s**i* — lowercase letter of the Latin alphabet. Also Kefa has *k* friends. Friend will be upset, If he get two baloons of the same color. Kefa want to give out all baloons to his friends. Help Kefa to find out, can he give out all his... | The first line contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=100) — the number of baloons and friends.
Next line contains string *s* — colors of baloons. | Answer to the task — «YES» or «NO» in a single line.
You can choose the case (lower or upper) for each letter arbitrary. | [
"4 2\naabb\n",
"6 3\naacaab\n"
] | [
"YES\n",
"NO\n"
] | In the first sample Kefa can give 1-st and 3-rd baloon to the first friend, and 2-nd and 4-th to the second.
In the second sample Kefa needs to give to all his friends baloons of color a, but one baloon will stay, thats why answer is «NO». | 500 | [
{
"input": "4 2\naabb",
"output": "YES"
},
{
"input": "6 3\naacaab",
"output": "NO"
},
{
"input": "2 2\nlu",
"output": "YES"
},
{
"input": "5 3\novvoo",
"output": "YES"
},
{
"input": "36 13\nbzbzcffczzcbcbzzfzbbfzfzzbfbbcbfccbf",
"output": "YES"
},
{
"... | 1,618,841,372 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 62 | 0 | n,m=map(int,input().split())
f=input()
a=[]
sum=0
for i in range(m):
a.append([])
for i in f:
for r in range(m):
if i not in a[r]:
a[r].append(i)
for i in range(m):
sum+=len(a[i])
if sum==len(f):
print("YES")
else:
print('NO')
#n,m=map(int,input().split())
#f=i... | Title: Generous Kefa
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
One day Kefa found *n* baloons. For convenience, we denote color of *i*-th baloon as *s**i* — lowercase letter of the Latin alphabet. Also Kefa has *k* friends. Friend will be upset, If he get two baloons of the same colo... | ```python
n,m=map(int,input().split())
f=input()
a=[]
sum=0
for i in range(m):
a.append([])
for i in f:
for r in range(m):
if i not in a[r]:
a[r].append(i)
for i in range(m):
sum+=len(a[i])
if sum==len(f):
print("YES")
else:
print('NO')
#n,m=map(int,input().spli... | 0 | |
765 | A | Neverending competitions | PROGRAMMING | 900 | [
"implementation",
"math"
] | null | null | There are literally dozens of snooker competitions held each year, and team Jinotega tries to attend them all (for some reason they prefer name "snookah")! When a competition takes place somewhere far from their hometown, Ivan, Artsem and Konstantin take a flight to the contest and back.
Jinotega's best friends, team ... | In the first line of input there is a single integer *n*: the number of Jinotega's flights (1<=≤<=*n*<=≤<=100). In the second line there is a string of 3 capital Latin letters: the name of Jinotega's home airport. In the next *n* lines there is flight information, one flight per line, in form "XXX->YYY", where "XXX"... | If Jinotega is now at home, print "home" (without quotes), otherwise print "contest". | [
"4\nSVO\nSVO->CDG\nLHR->SVO\nSVO->LHR\nCDG->SVO\n",
"3\nSVO\nSVO->HKT\nHKT->SVO\nSVO->RAP\n"
] | [
"home\n",
"contest\n"
] | In the first sample Jinotega might first fly from SVO to CDG and back, and then from SVO to LHR and back, so now they should be at home. In the second sample Jinotega must now be at RAP because a flight from RAP back to SVO is not on the list. | 500 | [
{
"input": "4\nSVO\nSVO->CDG\nLHR->SVO\nSVO->LHR\nCDG->SVO",
"output": "home"
},
{
"input": "3\nSVO\nSVO->HKT\nHKT->SVO\nSVO->RAP",
"output": "contest"
},
{
"input": "1\nESJ\nESJ->TSJ",
"output": "contest"
},
{
"input": "2\nXMR\nFAJ->XMR\nXMR->FAJ",
"output": "home"
},
... | 1,553,845,059 | 2,147,483,647 | Python 3 | OK | TESTS | 23 | 93 | 0 | # import sys
# sys.stdin=open("input.in",'r')
# sys.stdout=open("output1.out",'w')
n=int(input())
h=input()
a=[input() for i in range(n)]
flag=0
x=0
while x<len(a):
p=a[x][-3:]+"->"+a[x][0:3]
if p in a:
a.remove(a[x])
a.remove(p)
else:
flag=1
break
if flag==1:
print("contest")
else:
prin... | Title: Neverending competitions
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
There are literally dozens of snooker competitions held each year, and team Jinotega tries to attend them all (for some reason they prefer name "snookah")! When a competition takes place somewhere far from thei... | ```python
# import sys
# sys.stdin=open("input.in",'r')
# sys.stdout=open("output1.out",'w')
n=int(input())
h=input()
a=[input() for i in range(n)]
flag=0
x=0
while x<len(a):
p=a[x][-3:]+"->"+a[x][0:3]
if p in a:
a.remove(a[x])
a.remove(p)
else:
flag=1
break
if flag==1:
print("contest")
el... | 3 | |
735 | A | Ostap and Grasshopper | PROGRAMMING | 800 | [
"implementation",
"strings"
] | null | null | On the way to Rio de Janeiro Ostap kills time playing with a grasshopper he took with him in a special box. Ostap builds a line of length *n* such that some cells of this line are empty and some contain obstacles. Then, he places his grasshopper to one of the empty cells and a small insect in another empty cell. The gr... | The first line of the input contains two integers *n* and *k* (2<=≤<=*n*<=≤<=100, 1<=≤<=*k*<=≤<=*n*<=-<=1) — the number of cells in the line and the length of one grasshopper's jump.
The second line contains a string of length *n* consisting of characters '.', '#', 'G' and 'T'. Character '.' means that the correspondi... | If there exists a sequence of jumps (each jump of length *k*), such that the grasshopper can get from his initial position to the cell with the insect, print "YES" (without quotes) in the only line of the input. Otherwise, print "NO" (without quotes). | [
"5 2\n#G#T#\n",
"6 1\nT....G\n",
"7 3\nT..#..G\n",
"6 2\n..GT..\n"
] | [
"YES\n",
"YES\n",
"NO\n",
"NO\n"
] | In the first sample, the grasshopper can make one jump to the right in order to get from cell 2 to cell 4.
In the second sample, the grasshopper is only able to jump to neighboring cells but the way to the insect is free — he can get there by jumping left 5 times.
In the third sample, the grasshopper can't make a sin... | 500 | [
{
"input": "5 2\n#G#T#",
"output": "YES"
},
{
"input": "6 1\nT....G",
"output": "YES"
},
{
"input": "7 3\nT..#..G",
"output": "NO"
},
{
"input": "6 2\n..GT..",
"output": "NO"
},
{
"input": "2 1\nGT",
"output": "YES"
},
{
"input": "100 5\nG####.####.###... | 1,480,925,133 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 12 | 46 | 0 | q=input().split()
w=input()
e1=int(q[0])
e2=int(q[1])
y=True
for i in range (e1):
if w[i]=="G":
r=i
elif w[i]=="T":
t=i
if r<t:
for i in range (r,e1,e2):
if w[i]=="#":
y=False
if r>t:
for i in range (r,-1,-e2):
if w[i]=="#":
... | Title: Ostap and Grasshopper
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
On the way to Rio de Janeiro Ostap kills time playing with a grasshopper he took with him in a special box. Ostap builds a line of length *n* such that some cells of this line are empty and some contain obstacles.... | ```python
q=input().split()
w=input()
e1=int(q[0])
e2=int(q[1])
y=True
for i in range (e1):
if w[i]=="G":
r=i
elif w[i]=="T":
t=i
if r<t:
for i in range (r,e1,e2):
if w[i]=="#":
y=False
if r>t:
for i in range (r,-1,-e2):
if w[i]=="#":... | 0 | |
709 | A | Juicer | PROGRAMMING | 900 | [
"implementation"
] | null | null | Kolya is going to make fresh orange juice. He has *n* oranges of sizes *a*1,<=*a*2,<=...,<=*a**n*. Kolya will put them in the juicer in the fixed order, starting with orange of size *a*1, then orange of size *a*2 and so on. To be put in the juicer the orange must have size not exceeding *b*, so if Kolya sees an orange ... | The first line of the input contains three integers *n*, *b* and *d* (1<=≤<=*n*<=≤<=100<=000, 1<=≤<=*b*<=≤<=*d*<=≤<=1<=000<=000) — the number of oranges, the maximum size of the orange that fits in the juicer and the value *d*, which determines the condition when the waste section should be emptied.
The second line co... | Print one integer — the number of times Kolya will have to empty the waste section. | [
"2 7 10\n5 6\n",
"1 5 10\n7\n",
"3 10 10\n5 7 7\n",
"1 1 1\n1\n"
] | [
"1\n",
"0\n",
"1\n",
"0\n"
] | In the first sample, Kolya will squeeze the juice from two oranges and empty the waste section afterwards.
In the second sample, the orange won't fit in the juicer so Kolya will have no juice at all. | 500 | [
{
"input": "2 7 10\n5 6",
"output": "1"
},
{
"input": "1 5 10\n7",
"output": "0"
},
{
"input": "3 10 10\n5 7 7",
"output": "1"
},
{
"input": "1 1 1\n1",
"output": "0"
},
{
"input": "2 951637 951638\n44069 951637",
"output": "1"
},
{
"input": "50 100 12... | 1,631,823,395 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 0 | 31 | 6,963,200 | x,y=input().split(),input().split()
c=0
sum=0
for i in range(len(y)):
if int(y[i])>int(x[1]):
continue
sum+=int(y[i])
print(sum)
if sum>=int(x[2]):
c+=1
sum-=int(x[2])
print(c) | 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
x,y=input().split(),input().split()
c=0
sum=0
for i in range(len(y)):
if int(y[i])>int(x[1]):
continue
sum+=int(y[i])
print(sum)
if sum>=int(x[2]):
c+=1
sum-=int(x[2])
print(c)
``` | 0 | |
900 | B | Position in Fraction | PROGRAMMING | 1,300 | [
"math",
"number theory"
] | null | null | You have a fraction . You need to find the first occurrence of digit *c* into decimal notation of the fraction after decimal point. | The first contains three single positive integers *a*, *b*, *c* (1<=≤<=*a*<=<<=*b*<=≤<=105, 0<=≤<=*c*<=≤<=9). | Print position of the first occurrence of digit *c* into the fraction. Positions are numbered from 1 after decimal point. It there is no such position, print -1. | [
"1 2 0\n",
"2 3 7\n"
] | [
"2",
"-1"
] | The fraction in the first example has the following decimal notation: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/896357459a466614a0542f34c9cfb0cef1afc9ed.png" style="max-width: 100.0%;max-height: 100.0%;"/>. The first zero stands on second position.
The fraction in the second example ... | 1,000 | [
{
"input": "1 2 0",
"output": "2"
},
{
"input": "2 3 7",
"output": "-1"
},
{
"input": "1 100000 1",
"output": "5"
},
{
"input": "1 7 7",
"output": "6"
},
{
"input": "99999 100000 8",
"output": "-1"
},
{
"input": "44102 73848 2",
"output": "132"
}... | 1,513,151,246 | 2,147,483,647 | Python 3 | WRONG_ANSWER | TESTS | 2 | 46 | 5,529,600 | n=list(map(int,input().split()))
s=str(n[0]/n[1])
if n[2]==0:
if s[s.find('.')+1:].find('n[2]')==-1:
print(1+len(s[s.find('.')+1:]))
else:
print(s[s.find('.'):].find('n[2]'))
else:
print(s[s.find('.'):].find('n[2]')) | Title: Position in Fraction
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You have a fraction . You need to find the first occurrence of digit *c* into decimal notation of the fraction after decimal point.
Input Specification:
The first contains three single positive integers *a*, *b*, ... | ```python
n=list(map(int,input().split()))
s=str(n[0]/n[1])
if n[2]==0:
if s[s.find('.')+1:].find('n[2]')==-1:
print(1+len(s[s.find('.')+1:]))
else:
print(s[s.find('.'):].find('n[2]'))
else:
print(s[s.find('.'):].find('n[2]'))
``` | 0 | |
689 | B | Mike and Shortcuts | PROGRAMMING | 1,600 | [
"dfs and similar",
"graphs",
"greedy",
"shortest paths"
] | null | null | Recently, Mike was very busy with studying for exams and contests. Now he is going to chill a bit by doing some sight seeing in the city.
City consists of *n* intersections numbered from 1 to *n*. Mike starts walking from his house located at the intersection number 1 and goes along some sequence of intersections. Wal... | The first line contains an integer *n* (1<=≤<=*n*<=≤<=200<=000) — the number of Mike's city intersection.
The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (*i*<=≤<=*a**i*<=≤<=*n* , , describing shortcuts of Mike's city, allowing to walk from intersection *i* to intersection *a**i* using only 1 unit of ... | In the only line print *n* integers *m*1,<=*m*2,<=...,<=*m**n*, where *m**i* denotes the least amount of total energy required to walk from intersection 1 to intersection *i*. | [
"3\n2 2 3\n",
"5\n1 2 3 4 5\n",
"7\n4 4 4 4 7 7 7\n"
] | [
"0 1 2 \n",
"0 1 2 3 4 \n",
"0 1 2 1 2 3 3 \n"
] | In the first sample case desired sequences are:
1: 1; *m*<sub class="lower-index">1</sub> = 0;
2: 1, 2; *m*<sub class="lower-index">2</sub> = 1;
3: 1, 3; *m*<sub class="lower-index">3</sub> = |3 - 1| = 2.
In the second sample case the sequence for any intersection 1 < *i* is always 1, *i* and *m*<sub class="lowe... | 1,000 | [
{
"input": "3\n2 2 3",
"output": "0 1 2 "
},
{
"input": "5\n1 2 3 4 5",
"output": "0 1 2 3 4 "
},
{
"input": "7\n4 4 4 4 7 7 7",
"output": "0 1 2 1 2 3 3 "
},
{
"input": "98\n17 17 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 57 87 87... | 1,606,081,463 | 2,147,483,647 | PyPy 3 | RUNTIME_ERROR | TESTS | 0 | 187 | 2,150,400 | import sys
def minDistance(n, dist, sptSet):
min = sys.maxsize
for v in range(n):
if dist[v] < min and sptSet[v] == False:
min = dist[v]
min_index = v
return min_index
def dijkstra(n, graph, src):
dist = [sys.maxsize] * n
dist[src] = 0
sptSet = [False] * n
... | Title: Mike and Shortcuts
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Recently, Mike was very busy with studying for exams and contests. Now he is going to chill a bit by doing some sight seeing in the city.
City consists of *n* intersections numbered from 1 to *n*. Mike starts walkin... | ```python
import sys
def minDistance(n, dist, sptSet):
min = sys.maxsize
for v in range(n):
if dist[v] < min and sptSet[v] == False:
min = dist[v]
min_index = v
return min_index
def dijkstra(n, graph, src):
dist = [sys.maxsize] * n
dist[src] = 0
sptSet = [False] ... | -1 | |
955 | C | Sad powers | PROGRAMMING | 2,100 | [
"binary search",
"math",
"number theory"
] | null | null | You're given *Q* queries of the form (*L*,<=*R*).
For each query you have to find the number of such *x* that *L*<=≤<=*x*<=≤<=*R* and there exist integer numbers *a*<=><=0, *p*<=><=1 such that *x*<==<=*a**p*. | The first line contains the number of queries *Q* (1<=≤<=*Q*<=≤<=105).
The next *Q* lines contains two integers *L*, *R* each (1<=≤<=*L*<=≤<=*R*<=≤<=1018). | Output *Q* lines — the answers to the queries. | [
"6\n1 4\n9 9\n5 7\n12 29\n137 591\n1 1000000\n"
] | [
"2\n1\n0\n3\n17\n1111\n"
] | In query one the suitable numbers are 1 and 4. | 1,500 | [
{
"input": "6\n1 4\n9 9\n5 7\n12 29\n137 591\n1 1000000",
"output": "2\n1\n0\n3\n17\n1111"
},
{
"input": "20\n862 928\n758 964\n541 789\n622 943\n328 900\n14 764\n217 972\n461 847\n442 468\n900 986\n518 529\n938 993\n549 851\n690 944\n484 601\n320 910\n98 868\n816 915\n765 880\n551 770",
"output... | 1,521,827,849 | 4,949 | PyPy 3 | RUNTIME_ERROR | PRETESTS | 0 | 139 | 22,732,800 | import sys
xrange = range
input = raw_input
import math
small = 10**5+1
big = 10**18+1
pos = []
f = pos.append
#pos.add(1)
j = 2
while True:
i = j*j*j
if i>=big:
break
#if int(i**0.5+0.5)**2==i:
# j+=1
# continue
j2 = j*j
while i<big:
f(i)
i = i*j2
j += 1
... | Title: Sad powers
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
You're given *Q* queries of the form (*L*,<=*R*).
For each query you have to find the number of such *x* that *L*<=≤<=*x*<=≤<=*R* and there exist integer numbers *a*<=><=0, *p*<=><=1 such that *x*<==<=*a**p*.
Input ... | ```python
import sys
xrange = range
input = raw_input
import math
small = 10**5+1
big = 10**18+1
pos = []
f = pos.append
#pos.add(1)
j = 2
while True:
i = j*j*j
if i>=big:
break
#if int(i**0.5+0.5)**2==i:
# j+=1
# continue
j2 = j*j
while i<big:
f(i)
i = i*j2
... | -1 | |
621 | A | Wet Shark and Odd and Even | PROGRAMMING | 900 | [
"implementation"
] | null | null | Today, Wet Shark is given *n* integers. Using any of these integers no more than once, Wet Shark wants to get maximum possible even (divisible by 2) sum. Please, calculate this value for Wet Shark.
Note, that if Wet Shark uses no integers from the *n* integers, the sum is an even integer 0. | The first line of the input contains one integer, *n* (1<=≤<=*n*<=≤<=100<=000). The next line contains *n* space separated integers given to Wet Shark. Each of these integers is in range from 1 to 109, inclusive. | Print the maximum possible even sum that can be obtained if we use some of the given integers. | [
"3\n1 2 3\n",
"5\n999999999 999999999 999999999 999999999 999999999\n"
] | [
"6",
"3999999996"
] | In the first sample, we can simply take all three integers for a total sum of 6.
In the second sample Wet Shark should take any four out of five integers 999 999 999. | 500 | [
{
"input": "3\n1 2 3",
"output": "6"
},
{
"input": "5\n999999999 999999999 999999999 999999999 999999999",
"output": "3999999996"
},
{
"input": "1\n1",
"output": "0"
},
{
"input": "15\n39 52 88 78 46 95 84 98 55 3 68 42 6 18 98",
"output": "870"
},
{
"input": "15\... | 1,553,673,310 | 2,147,483,647 | Python 3 | OK | TESTS | 87 | 187 | 8,499,200 | n = int(input())
arr = list(map(int , input().split()))
sumx = 0
even = 0
odd = 0
mini = 1000000001
for x in arr :
if (x%2)==0:
even+=1
else :
odd +=1
mini = min(mini,x)
sumx += x
if((sumx %2)==0):
print(sumx)
else :
print(sumx-mini) | Title: Wet Shark and Odd and Even
Time Limit: None seconds
Memory Limit: None megabytes
Problem Description:
Today, Wet Shark is given *n* integers. Using any of these integers no more than once, Wet Shark wants to get maximum possible even (divisible by 2) sum. Please, calculate this value for Wet Shark.
Note, th... | ```python
n = int(input())
arr = list(map(int , input().split()))
sumx = 0
even = 0
odd = 0
mini = 1000000001
for x in arr :
if (x%2)==0:
even+=1
else :
odd +=1
mini = min(mini,x)
sumx += x
if((sumx %2)==0):
print(sumx)
else :
print(sumx-mini)
``` | 3 |
Subsets and Splits
Successful Python Submissions
Retrieves all records from the train dataset where the verdict is 'OK', providing basic filtering but limited analytical value.
SQL Console for MatrixStudio/Codeforces-Python-Submissions
Retrieves records of users with a rating of 1600 or higher and a verdict of 'OK', providing basic filtering but limited analytical value.
SQL Console for MatrixStudio/Codeforces-Python-Submissions
Counts the number of entries with a rating above 2000 and a verdict of 'OK', providing basic filtering but limited analytical value.
SQL Console for MatrixStudio/Codeforces-Python-Submissions
Counts the number of entries with a 'OK' verdict, providing a basic overview of a specific category within the dataset.